function encodeUrlString(str){
var tmp = "", hebrew = "all hebrew chars", encodeHEX = "0123456789ABCDEF";
for(i=0; i<str.length ; i++){
    character = str.charAt(i);
	ascii = character.charCodeAt(0);
	if(hebrew.indexOf(character)>=0) ascii = character.charCodeAt(0)-1264;
	tmp += "%"+encodeHEX.charAt(parseInt(ascii/16))+encodeHEX.charAt(ascii%16);
}
return (tmp);
}


function activateLoadingDiv(){ 
document.getElementById("ajax_loading").style.top =  document.body.scrollTop + 5;
document.getElementById("ajax_loading").style.display = "block";
}

function removeLoadingDiv() { document.getElementById("ajax_loading").style.display = "none"; }

function showFlash(divID, data){
var d = document.getElementById(divID);
d.innerHTML=data; 
}

function showBan(divID, width, height, src){
var d = document.getElementById(divID);
d.innerHTML='<OBJECT classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0  WIDTH='+width+' HEIGHT='+height+'><PARAM NAME=wmode VALUE=transparent><param name=allowScriptAccess value=sameDomain><param name=allowFullScreen value=true><PARAM NAME=movie VALUE="'+src+'"><PARAM NAME=quality VALUE=high><param name=allowScriptAccess value=allowScriptAccess><param name=bgcolor value=""><EMBED src="'+src+'" quality="high" wmode="transparent" WIDTH='+width+' HEIGHT='+height+' bgcolor="" TYPE=application/x-shockwave-flash PLUGINSPAGE=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash></EMBED></OBJECT>';
}

var siteCache=new Array();
var scriptStr="";

function checkBrowser(){
var navFamily = navigator.userAgent.toLowerCase();
	if (navFamily.indexOf('msie')!=-1) {
		var ver = parseFloat( navFamily.substring(navFamily.indexOf('msie')+5,navFamily.length) );
		scriptStr='SCRIPT';
		navFamily = 'IE6';
	} else if (navFamily.indexOf('gecko')!=-1) {
		var ver = parseFloat( navFamily.substring(navFamily.indexOf('gecko')+6,	navFamily.length) );
		scriptStr='script';
		navFamily = 'Gecko';
	} else {
		scriptStr='script'; navFamily = 'Gecko';
	}
return navFamily;
}
var myBrowser = checkBrowser();


function ajaxUrl(url, aid,cashe_stat,showLoading){
var siteHTTP;
if(showLoading==1) activateLoadingDiv();
if (siteCache[url]!=null) {
                    document.getElementById(aid).style.display="block"; 
					document.getElementById(aid).innerHTML = siteCache[url]; 
					removeLoadingDiv();  
					return;
}

if (window.XMLHttpRequest){
siteHTTP=new XMLHttpRequest();
siteHTTP.onreadystatechange=state_Change;
siteHTTP.open("POST",url,true);
siteHTTP.send(null);
} else if (window.ActiveXObject){
siteHTTP=new ActiveXObject("Microsoft.XMLHTTP");
if (siteHTTP){
siteHTTP.onreadystatechange=state_Change;
siteHTTP.open("POST",url,true);
siteHTTP.send();
}
}

function state_Change(){
if (siteHTTP.readyState==4){ 
		if (siteHTTP.status==200){
		document.getElementById(aid).style.display="block"; 
		document.getElementById(aid).innerHTML = siteHTTP.responseText; 
		if(cashe_stat==1) siteCache[url]=siteHTTP.responseText; 
		removeLoadingDiv();
		evalObjJavascript(aid); 
		}
}
}
}

function MyexecScript(txt){
if (myBrowser == 'IE6'){
try{execScript(txt,"JavaScript");}
catch(err){}
} else {			
var head = document.getElementsByTagName('head').item(0);
script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML=txt;
head.appendChild(script);
}
return false;
}


function evalObjJavascript(oname){
tobj=document.getElementById(oname);
if(typeof tobj == 'object'){
	var TmpHtml=tobj.innerHTML;
	var oEval=TmpHtml.search('<'+scriptStr+'>');
	var Max=5;
		for(i=0; i<Max && oEval>=0 ;i++){
		var tmp=TmpHtml.substring(oEval,TmpHtml.length).search('</'+scriptStr+'>');
		sEval=TmpHtml.substring(oEval+8,oEval+tmp);
		MyexecScript(sEval);
		TmpHtml=TmpHtml.substring(oEval+tmp+9,TmpHtml.length);
		oEval=TmpHtml.search('<'+scriptStr+'>');
		}
	}
return false;
}

// forum functions //
function open_forumAdmin(faid){
window.open("/pop/forumAdmin.php?id="+faid,"adminPop","top=10,left=10,width=435,height=420,toolbar=no,location=no");
}

function forumPages(fid,p){
location.href = "/forum.php?fid="+fid+"&p="+p;
}

function addForumM(fid,faid){
pop = window.open("/pop/addForumM.php?fid="+fid+"&faid="+faid,"messagePop","top=10,left=10,width=520,height=600,toolbar=no,location=no");
pop.focus();
}

function forumBody(id,isRoot){
if(document.getElementById("fm_"+id).style.display=="block"){ document.getElementById("fm_"+id).style.display="none"; document.getElementById("fRow_"+id).className="forum-"+isRoot; }
else { res = ajaxUrl("/ajax/forumBody.php?id="+id,"fm_"+id,1,1); document.getElementById("fRow_"+id).className="forum-open"; }
}

// sheelon functions //
var sheelonWindow = null;
function openSheelon(sheelonId){
sheelonWindow = window.open("/pop/sheelon.php?id="+sheelonId,"sheelonPop","top=10,left=10,width=485,height=400,toolbar=no,location=no");
}

// clinic functions
// right side clinic search
function search_clinic_buxa(){
//if(document.getElementById("search_clinic_area_id").value==""){ document.getElementById("search_clinic_area_id").focus(); return;}
if(document.getElementById("search_clinic_category_id").value==""){ alert("נא לבחור תחום"); document.getElementById("search_clinic_category_id").focus(); return;}
location.href="/clinics.php?cid="+document.getElementById("search_clinic_category_id").value+"&area="+document.getElementById("search_clinic_area_id").value+"&ref=from_search_box";
}

function clinic_contact_focus(){
//document.getElementById("contact_us_btn").style.display="none"; 
document.getElementById("clinicWorld").innerHTML="";
if(clinic_tab_selected>=0) document.getElementById("clinic_tab_"+clinic_tab_selected).className="clinic_tab_off"; 
clinic_tab_selected=-1;
document.getElementById("fullname").focus(); 
}

function open_clinic_hours(clinic_id){
window.open("/pop/clinicHours.php?id="+clinic_id,"hoursPop","top=10,left=10,width=435,height=420,toolbar=no,location=no");
}

function show_clinic_phone(clinic_id, click_type){
ajaxUrl("/ajax/clinic_phone.php?clinic_id="+clinic_id+"&click_type="+click_type,"clinic_phone_world",1,1);
}


function openCoupon(clinic_id){
window.open("/pop/coupon.php?id="+clinic_id,"couponPop","top=10,left=10,width=495,height=380,toolbar=no,location=no");
}

function clinicSuggest(clinic_id){
window.open("/pop/clinicSuggest.php?id="+clinic_id,"suggestPop","top=10,left=10,width=435,height=420,toolbar=no,location=no");
}

function openHavayaPop(){
window.open("/pop/sendHavaya.php","havayaPop","top=10,left=10,width=435,height=620,toolbar=no,location=no");
}

function openTipPop(){
window.open("/pop/sendTip.php","tipPop","top=10,left=10,width=435,height=420,toolbar=no,location=no");
}

var send_friend_win = null;

function openSend2friend(){
send_friend_window = window.open("/pop/send2friend.php?pageURL="+encodeURIComponent(top.document.location),"sendPop","top=10,left=10,width=435,height=420,toolbar=no,location=no");
send_friend_window.focus();
}

function openSend2friend_url(url){
send_friend_window = window.open("/pop/send2friend.php?pageURL="+encodeURIComponent(url),"sendPop","top=10,left=10,width=435,height=420,toolbar=no,location=no");
send_friend_window.focus();
}

function clinicEsteticaDetails(clinic_id){
var iframe_div = document.getElementById('ciframe_'+clinic_id);
var image_details = document.getElementById('img_details_'+clinic_id);
if(iframe_div.style.display == 'none' || iframe_div.style.display == ''){
image_details.src="http://www.estetica.co.il/u/icons/g/details_down.gif";
if(iframe_div.innerHTML=="")iframe_div.innerHTML="<iframe width=595 height=480 scrolling=No src='/inc/clinic_details.php?id="+clinic_id+"' frameborder=0 style='margin:0px; border:1px solid #f0f0f0;'></iframe>";
$(iframe_div).slideDown(1000);
//iframe_div.style.display = 'block';
}
else{
image_details.src="http://www.estetica.co.il/u/icons/g/details.gif";   
//iframe_div.style.display = 'none';
$(iframe_div).slideUp(500);
}
}

function clinicDetails(clinic_id){
var iframe_div = document.getElementById('ciframe_'+clinic_id);
var image_details = document.getElementById('img_details_'+clinic_id);
if(iframe_div.style.display == 'none'){
image_details.src="http://www.estetica.co.il/u/icons/g/details_down.gif";
if(iframe_div.innerHTML=="")iframe_div.innerHTML="<iframe width=736 height=480 scrolling=No src='/minisite/details.php?id="+clinic_id+"' frameborder=0 style='margin:0px; border:1px solid #D84492;'></iframe>";
$(iframe_div).slideDown(1000);
//iframe_div.style.display = 'block';
}
else{
image_details.src="http://www.estetica.co.il/u/icons/g/details.gif";   
//iframe_div.style.display = 'none';
$(iframe_div).slideUp(500);
}
}

// before after galleries
function switch_ba_gallery(object_type, object_id, gallery_id){
ajaxUrl("/ajax/ba_gallery.php?object_type="+object_type+"&object_id="+object_id+"&gallery_id="+gallery_id,"before_after_world",0,1);
}

// pink menus

function showMenu(menu_id){ 
   document.getElementById("menu_"+menu_id).style.display="block"; 
   //$("#menu_"+menu_id).slideDown("slow");
}
function hideMenu(menu_id){ 
   document.getElementById("menu_"+menu_id).style.display="none";
   //$("#menu_"+menu_id).slideUp("slow"); 
}

function email_validate(email_address) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(reg.test(email_address) == false) return 0; else return 1; 
}

var HPscrollTimeout=null;
var HPscrollDirection;
var HPscrollPos;
var HPscrollDivName;

function HPscrollDiv(){
HPscrollPos=document.getElementById(HPscrollDivName).scrollTop;
document.getElementById(HPscrollDivName).scrollTop=HPscrollPos+(HPscrollDirection*2);
HPscrollTimeout=setTimeout(HPscrollDiv,10);
}

function HPstartScrollDiv(d,scroll_div){
HPscrollDivName = scroll_div;
HPscrollDirection=d;
if (HPscrollTimeout!=null) clearTimeout(HPscrollTimeout);
HPscrollTimeout=setTimeout(HPscrollDiv,0);
}

function HPendScrollDiv(){ if (HPscrollTimeout!=null) clearTimeout(HPscrollTimeout); }


// product function 
function openProductCoupon(product_id){
window.open("/pop/coupon_product.php?id="+product_id,"couponPop","top=10,left=10,width=495,height=380,toolbar=no,location=no");
}


// blogs functions //
function open_blog_admin(aid){
window.open("/pop/blog-admin.php?id="+aid,"adminPop","top=10,left=10,width=435,height=420,toolbar=no,location=no");
}

// resize div functions 
var ResizeObject, ResizeObjectHeight, ResizeHeight, ResizeSpeed=5;

function closeDiv(){
ResizeHeight-=parseInt(ResizeHeight/ResizeObjectHeight*10)+5;
if(ResizeHeight>=0)ResizeObject.style.height=ResizeHeight+1;
if(ResizeHeight>0)setTimeout("closeDiv();",ResizeSpeed);
else ResizeObject.style.display="none";
}

function openDiv(){
ResizeHeight+=parseInt(ResizeHeight/ResizeObjectHeight*10)+5;
ResizeObject.style.height=ResizeHeight+1;
if(ResizeHeight<=ResizeObjectHeight)setTimeout("openDiv();",ResizeSpeed);
}

function ToggleResize(divID,h){
ResizeObject=document.getElementById(divID); 
ResizeObject.style.overflow="hidden";
ResizeObjectHeight=h;
if(ResizeObject.style.display=="none"){ ResizeObject.style.display="block";  ResizeHeight=0;   openDiv(); }
else { ResizeHeight=h; closeDiv(); }
}


function Check_Boxs_Comma(form_name, checkbox_name){
var checkboxObj, c, formObj = document.getElementById(form_name), clinics_ids;
clinics_ids="0";
for(c=0 ; c<formObj.elements.length ;c++){
checkboxObj=formObj.elements[c];
if(checkboxObj.checked && checkboxObj.id==checkbox_name){ clinics_ids+=","+checkboxObj.value; }
}
return(clinics_ids);
}



function clinics_multiple_sent(){
var iframe_object = document.getElementById("ciframe_multiple");
if(iframe_object.style.display=="block") return;
document.getElementById("multiple_empty").style.display="none"; 

checkboxes_str = Check_Boxs_Comma("multipleForm","clinic_check_box[]");
if(checkboxes_str=="0"){ document.getElementById("multiple_empty").style.display="block";  return; } 
  //              document.getElementById("multiple_close").style.display="none"; 
//                iframe_object.style.display="none"; iframe_object.src="/minisite/loading.html"; return; 

iframe_object.style.display="block";
document.getElementById("multiple_close").style.display="block"; 
document.getElementById("multipleForm").method="POST";
document.getElementById("multipleForm").action="/inc/clinic_multiple_send.php";
document.getElementById("multipleForm").submit();

}

function closeMultiple(){
document.getElementById("multiple_empty").style.display="none"; 
document.getElementById("multiple_close").style.display="none";
document.getElementById("ciframe_multiple").style.display="none";
}



var winWidth,winHeight;
function detectBrowserWH(){ 
if (parseInt(navigator.appVersion)>3) {
	if (navigator.appName=="Netscape") { winWidth = window.innerWidth; winHeight = window.innerHeight; }
	if (navigator.appName.indexOf("Microsoft")!=-1) { winWidth = document.body.offsetWidth-20; winHeight = document.body.offsetHeight-20; }
}	
}


function callme(clinic_id){
Open_Over_Layer_Shade();  
var x = "<iframe allowTransparency=true width=300 height=400 id='Callme_Iframe' name='Callme_Iframe' src='/pop/callme.php?clinic_id="+clinic_id+"'  frameborder=0 scrolling=No></iframe>";
x = wrap_shade_screen_data(x);
document.getElementById('shade_screen_data').innerHTML = x; 
$("#shade_screen_data").fadeIn("slow"); 
Over_Layer_Shade_Close_Button(); 
}


$(document).ready(function() {
  $('#shade_screen').click(function() {
        Close_Over_Layer_Shade();
  });
});



function Over_Layer_Shade_Close_Button(){
    $("#shade_screen_data").append("<div style='position:absolute; top:0; right:0; z-index:101;'><img src='/u/icons/g/close_btn.gif' class='hand' onclick='Close_Over_Layer_Shade();'></div>"); 
}

function Close_Over_Layer_Shade(){
$("#shade_screen_data").fadeOut("slow", function(){
       document.getElementById("shade_screen_data").innerHTML = "";
	   document.getElementById("shade_screen").style.display = "none";
});
}


function Open_Over_Layer_Shade(){ 
document.getElementById("shade_screen").style.display = "block"; 
}

function wrap_shade_screen_data(data){
  return ("<table cellpadding=0 cellspacing=0 width='100%' height='"+$(window).height()+"'><tr><td><div align=center>"+data+"</div></td></tr></table>"); 
}


function topShade(url,w,h){
alert(topShade); 
ToggleShade(1); 
detectBrowserWH(); 
var x = "<div align=right><img src='http://www.estetica.co.il/u/icons/g/close_btn.gif' class=hand onclick='ToggleShade(0);'></div><iframe id='Inner_shade_screen_data' name='Inner_shade_screen_data' src='"+url+"' style='width:"+w+"px; height:"+h+"px; margin:0px;' frameborder=0 scrolling=No></iframe>";
document.getElementById('shade_screen_data').innerHTML=x; 
}


function ToggleShade(ac){
if(ac==0) { document.getElementById('shade_screen').style.display='none'; document.getElementById('shade_screen_data').style.display='none';}
if(ac==1) { document.getElementById('shade_screen').style.display='block'; document.getElementById('shade_screen_data').style.display='block';}
}


function isNumeric(str){
var numbers = "0123456789-";
if(str.length==0) return false;
for (var i=0; i < str.length; i++){
        var ch = str.substring(i, i+1);
		if(numbers.indexOf(ch)<0) return false;
	}
return true;
}


function isValidPhone(str) {
if(isNumeric(str)==true && str.length>=9) return true; 
else return false; 
}

var tooltip_ajax_cache = new Array(); 

$(document).ready(function() {
$(".tooltip_treatments").mouseover(function(e){
          var ttclid = this.getAttribute("rel");
		  var ajax_url = "/ajax/info-treatments.php?id="+ttclid; 
		  $('body').append("<div id='clinic_treatments_list_"+ttclid+"' style='left:"+(e.pageX-190)+"px; top:"+(e.pageY+20)+"px; position:absolute;'></div>"); 
		  if (tooltip_ajax_cache[ajax_url]!=null) $("#clinic_treatments_list_"+ttclid).html(tooltip_ajax_cache[ajax_url]); 
		  else $("#clinic_treatments_list_"+ttclid).load(ajax_url, function(data) { tooltip_ajax_cache[ajax_url] = data; });
}).mouseout(function(){
          $("#clinic_treatments_list_"+this.getAttribute("rel")).slideUp(300, function(){ $(this).remove(); });
});
});

var TopOpenPopup=null;

function TopHidePopup(){
	if (TopOpenPopup!=null){
		//TopOpenPopup.style.display="none";
		$(TopOpenPopup).hide(300);
		TopOpenPopup=null;
	}
	document.onclick=null;
}

function TopShowPopup(objname,e){
	var obj=document.getElementById(objname);
	if (obj==null)return;
	if (TopOpenPopup!=null){
		if (TopOpenPopup==obj){	TopHidePopup();return; }
		TopHidePopup();
	}
	TopOpenPopup=obj; 
	//obj.style.display="block";
	$(TopOpenPopup).show(300);
	if (!e) var e = window.event; 
	e.cancelBubble= true;
	if(e.stopPropagation)e.stopPropagation();
	document.onclick=TopHidePopup;
}



$(document).ready(function() {
$(".select_box_option").mouseover(function(e){
          $(this).removeClass('select_box_option').addClass('select_box_option_over'); 
		  
}).mouseout(function(){
          $(this).removeClass('select_box_option_over').addClass('select_box_option'); 
});
});



function redirect_after_send(){
setTimeout ("document.location.href='http://www.estetica.co.il'", 1000*10); 
}


function Open_Facebook_Sahre(u){
window.open("http://www.facebook.com/sharer.php?u="+u+"&t=","sendPop","top=10,left=10,width=680,height=450,toolbar=no,location=no");
}


function load_ruller(){
$.ajax({
  url: "/ajax/ruller.php",
  cache: false,
  success: function(html){
       $("body").append(html); 
	   $("#ruller_warraper_show").slideToggle("slow");
  }
});
}


function load_right_float(cid){
$.ajax({
  url: "/ajax/right_float.php?cid="+cid,
  cache: false,
  success: function(html){
       $("body").append(html); 
	  // $("#right_float_warraper").animate("slow");
	   $("#right_float_warraper").animate( {width: "120px", opacity: 1.0} , 1000);
  }
});
}


function load_corner_banner(cid){
$.ajax({
  url: "/ajax/corner_banner.php?cid="+cid,
  cache: false,
  success: function(html){
	   $("body").append(html);
  }
});
}


function forum_tool_search(){
var forum_id = document.getElementById('forum_tool_search_id').value;
var phrase = document.getElementById('forum_tool_search_phrase').value;
if(forum_id==0){ alert("חובה לבחור פורום לחיפוש"); document.getElementById('forum_tool_search_id').focus(); return; }
if(phrase==""){ alert("חובה למלא את צירוף החיפוש"); document.getElementById('forum_tool_search_phrase').focus(); return; }
location.href = "/forum.php?fid="+forum_id+"&fq="+encodeURIComponent(document.getElementById("forum_tool_search_phrase").value);
}


function forum_tool_search_key(e){ if(e.keyCode==13) forum_tool_search(); }
function handle_search(e){ if(e.keyCode==13) submit_serach_form(); }

function submit_serach_form(){ 
	location.href = "/search.php?searchWord="+encodeURIComponent(document.getElementById("search_form_phrase").value);
}


$(document).ready(function() {
$(".clinic_row-0").mouseover(function(e){
		$(this).attr('class', 'clinic_mouseOver');
}).mouseout(function(){
		$(this).attr('class', 'clinic_row-0');
});
});

$(document).ready(function() {
$(".clinic_row-1").mouseover(function(e){
		$(this).attr('class', 'clinic_mouseOver');
}).mouseout(function(){
		$(this).attr('class', 'clinic_row-1');
});
});
