//=====================================
// javascript functions for DR levy
//=====================================

//function  calculateBMI() {
//  var weight = eval(document.BmiForm.weight.value)
//  var height = eval(document.BmiForm.height.value)
 // var height2 = height / 100
//  var BMI = weight  / (height2 * height2)
//  document.BmiForm.BodyMassIndex.value=custRound(BMI,1);
//}

var site_url = "http://www.drlevy.co.il/";

function  calculateBMI() {
  var weight = eval(document.BmiForm.weight.value)
  var height = eval(document.BmiForm.height.value)
  var height2 = height / 100
  var BMI = weight  / (height2 * height2)
 
  var result = custRound(BMI,1);
  document.BmiForm.BodyMassIndex.value=result;
 
  var bmi_span_status = document.getElementById('bmi_status');
  bmi_span_status.style.display = '';
  
 if (result < 19) bmi_span_status.innerHTML = '<font color="red">תת משקל</font>';
	else if ( (result >= 19) && (result < 25) ) bmi_span_status.innerHTML = '<font color="green">משקל תקין';
	else if ( (result >= 25) && (result < 30) ) bmi_span_status.innerHTML = '<font color="red">עודף משקל';
	else if ( (result >= 30) && (result < 40) ) bmi_span_status.innerHTML = '<font color="darkred">השמנת יתר';
	else bmi_span_status.innerHTML = 'השמנת יתר בדרגה חמורה';

}

function custRound(x,places) {
  return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}

function validateForm() {
		
	if (document.BmiForm.weight.value == '' || isNaN(document.BmiForm.weight.value)){
   	alert ('נא למלא משקל בק"ג');
	document.BmiForm.weight.focus();
	return false;}			
   	if (!IsNumeric(document.BmiForm.height.value) || document.BmiForm.height.value=='' ){
   	alert ('נא למלא גובה בס"מ');
	document.BmiForm.height.focus();
	return false;}
	calculateBMI();
}

function IsNumeric(sText) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

 function INM_RollOver(obj,dir){
  obj.className = (dir) ? 'main-menu-active' : 'main-menu-item';
 }
 
 function INM_LinkOver(obj,dir,classtype,url){
 if (classtype == 1) {classtype='link';}
 if (classtype == 2) {classtype='cat';}
 if (classtype == 3) {classtype='first-cat';}
 if (classtype == 4) {classtype='nocursor';}
//alert(classtype)
	obj.className = (dir) ? classtype+'-box-over' : classtype+'-box';
	this.window.status = url;
 }
 
 function INM_Jump(url,tar){
  if(tar){
   window.open(url);
  }else{
   document.location.href=url;
  }
 }
// [ url, width, height, resize, scroll]
function openWin(u,w,h,r,s){
 r=(r?'yes':'no');
 s=(s?'yes':'no');
 var l = (screen.width-w)/2;
 var t = (screen.height-h)/2-50;
 window.open(u,"","width="+w+",height="+h+",top="+t+",left="+l+",menubar=no,toolbar=no,status=no,resizable="+r+",scrollbars="+s);
}
 
function showHide(objid){
 obj = document.getElementById(objid);
 obj.style.display = obj.style.display=='none' ? 'block' : 'none';
 
}

function nav_MOver(navID){
	document.getElementById('btn'+navID).className='navText_Over';
}

function nav_MOut(navID){
	document.getElementById('btn'+navID).className='navText';
}
	
function BuildSEOLink(mdl,str,id){
	if (typeof mdl == 'undefined') mdl='';
	if (typeof str == 'undefined') str='';
	if (typeof id == 'undefined')   id='';
	return (_html_base+(mdl==''?'index':mdl)+(str!=''?'/'+str:'')+(id!=''?'/'+id:''));
}

function displayPost(icons){
	if(icons == 'flash_Contact'){
		document.location.href = BuildSEOLink("contact");
	}else if(icons=='flash_Home'){
		document.location.href = BuildSEOLink("");
		}
}

function printIt(title, id) {
	MyWindow1=window.open (site_url+'print/'+title+'/'+id, 'MyWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=550'); 
	return false;
}

function printItRecipe(title, id) {
	MyWindow1=window.open (site_url+'printr/'+title+'/'+id, 'MyWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=550'); 
	return false;
}

function sendIt(page, id) {
	subject = "Article from Dr Levy Site";
	link = site_url+page+'//'+id; 	
	document.location.href='mailto:?SUBJECT='+subject+'&BODY='+escape(link);
}

function changeDislplay(id){
	if (document.getElementById('answer'+id).style.display == 'none') document.getElementById('answer'+id).style.display = 'block';
	else document.getElementById('answer'+id).style.display = 'none';
}

function pngFix(){
	if (document.all && document.body.filters){
		tofix = document.getElementById('centerText').getElementsByTagName('img');
		for(var i=0; i<tofix.length; i++){
			var img = tofix[i];
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : "";
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText ;
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				var imgClick = (img.onclick != null) ? "onclick=\"" + img.onclick + "; anonymous();\"" : "";
				if (img.parentElement.href) imgStyle = "cursor:pointer;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + imgClick 
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				i = i-1;
			};
		};
	};
};