function checkNum(strString)
{
 if(strString.height_ft.value!="")
  { 
		 for(var i=0;i<strString.height_ft.value.length;i++)
		 {
		   if(!isDigit(strString.height_ft.value.charAt(i)))
			  {
				alert("Value should be number");
				strString.height_in.disabled="disabled";
				strString.weight.disabled="disabled";
				strString.height_ft.focus();
				strString.height_ft.select();
				return false;				
			  }
			  else
			  {
			    strString.height_in.disabled=false;
				strString.weight.disabled=false;
			  }
			
		 }	
   }
    if(document.formbmi.height_in.value!="")
  {
		 for(var i=0;i<document.formbmi.height_in.value.length;i++)
		 {
		   if(!isDigit(document.formbmi.height_in.value.charAt(i)))
			  {				
				document.formbmi.weight.disabled="disabled";
				document.formbmi.height_ft.disabled="disabled";
				document.formbmi.height_in.focus();
				document.formbmi.height_in.select();
				return false;
			  }
			  else
			  {
			   document.formbmi.weight.disabled=false;
			   document.formbmi.height_ft.disabled=false;
			  }
		 }	
   }	
   if(document.formbmi.height_in.value!="")
  {
		 for(var i=0;i<document.formbmi.height_in.value.length;i++)
		 {
		   if(!isDigit(document.formbmi.height_in.value.charAt(i)))
			  {				
				document.formbmi.weight.disabled="disabled";
				document.formbmi.height_ft.disabled="disabled";				
				return false;
			  }
			  else
			  {
			   document.formbmi.weight.disabled=false;
			   document.formbmi.height_ft.disabled=false;
			  }
		 }	
   }	
 
    if(strString.weight.value!="")
  {
		 for(var i=0;i<strString.weight.value.length;i++)
		 {
		   if(!isDigit(strString.weight.value.charAt(i)))
			  {
				alert("Value should be number");
				strString.height_ft.disabled="disabled";
				strString.height_in.disabled="disabled";
				strString.weight.focus();
				strString.weight.select();
				return false;
			  }
			  else
			  {
			   strString.height_ft.disabled=false;
			   strString.height_in.disabled=false;
			  }
		 }	
   }		
   	   
}
function checking1(arg)
{
 if( (arg.height_ft.value=="") )
 {
  alert("Please enter your height in feet");
  arg.height_ft.focus();
  arg.height_ft.select();
  return false;
 }
  
}	  
function checking2(arg)
{ 
 if( (arg.height_ft.value=="") )
 {
  alert("Please enter your height in feet");
  arg.height_ft.focus();
  arg.height_ft.select();
  return false;
 }
 /*if( (arg.height_in.value=="") )
 {
  alert("Please enter your height in inches");
  arg.height_in.focus();
  arg.height_in.select();
  return false;
 }*/
 
}
function isDigit(num)
{
	 if(num.length>1)
	   {
		return false;
	   }
    var string="1234567890-.";

	 if(string.indexOf(num)!=-1)
	  {
	   return true;
	  }
 return false;
} 
					  
function calcBmi(htF,htI,wt) 
{ if((document.formbmi.height_ft.value!="")&&(document.formbmi.weight.value!="")&&(document.formbmi.height_in.value=="")){document.formbmi.height_in.value=0;}
 var ht=0;
 var hi=0;
 var w=0;
 
   if(document.formbmi.height_in.value!="")
  {
		 for(var i=0;i<document.formbmi.height_in.value.length;i++)
		 {
		   if(!isDigit(document.formbmi.height_in.value.charAt(i)))
			  {
				alert("Value should be number");
				document.formbmi.weight.disabled="disabled";
				document.formbmi.height_ft.disabled="disabled";
				document.formbmi.height_in.focus();
				document.formbmi.height_in.select();
				return false;
			  }
			  else
			  {
			   document.formbmi.weight.disabled=false;
			   document.formbmi.height_ft.disabled=false;
			  }
		 }	
   }	
 
    for(var i=0;i<document.formbmi.height_ft.value.length;i++)
		 {
		   if(isDigit(document.formbmi.height_ft.value.charAt(i)))
			  {
				ht=1;			
			  }			
		  }
	for(var i=0;i<document.formbmi.height_in.value.length;i++)
		 {
		   if(isDigit(document.formbmi.height_in.value.charAt(i)))
			  {
				hi=1;			
			  }			
		  }	
	for(var i=0;i<document.formbmi.weight.value.length;i++)
		 {
		   if(isDigit(document.formbmi.weight.value.charAt(i)))
			  {
				w=1;			
			  }			
		  }	
if( (ht=1)&&(hi=1)&&(w=1))
 {		  	  	  	
	if(htF.lenght!=0&&htI.lenght!=0&&wt.lenght!=0)
	{
		inches=eval(htF*12)+eval(htI);
		sqrin=inches*inches;		
		var result= Math.round(wt/sqrin*70300)/100;	
		
		 //session ajax starts here
 if((document.formbmi.height_ft.value!="")&& (document.formbmi.height_in.value!="") && (document.formbmi.weight.value!=""))
 {
	var xmlHttp
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	var url='ajax_session.php';
	
	url=url+"?h_ft="+htF;
	url=url+"&h_in="+htI;	
	url=url+"&w="+wt;	
	url=url+"&bmi="+result;	
	url=url+"&sid="+Math.random()
	
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)	
	
	
 }
 
 //session ajax ends here
		var originalNum = result;
		var roundedNum = roundToPrecision(originalNum, 1);
		var roundedNumString = addZeroesToPrecision(roundedNum, 1);		
		return roundedNumString;		
	}
 } 
}
function GetXmlHttpObject()
	{ 
			var objXMLHttp=null
		if (window.XMLHttpRequest)
		{
			objXMLHttp=new XMLHttpRequest()
		}
		else if (window.ActiveXObject)
		{
			objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
		return objXMLHttp
	}	

//rounds the input number to the desired precision
//and returns the rounded number
function roundToPrecision(inputNum, desiredPrecision){
 var precisionGuide = Math.pow(10, desiredPrecision);
 return( Math.round(inputNum * precisionGuide) / precisionGuide );
}

//converts the input number into a string and adds zeroes
//until the desired precision is reached and then
//returns the new string
function addZeroesToPrecision(inputNum, desiredPrecision){
 var numString = inputNum + "";
 var afterDecimalString = numString.substring(numString.search(/\./) + 1);
 while (afterDecimalString.length < desiredPrecision) {
   afterDecimalString += "0";
   numString += "0";
 }
 return(numString);
}	

 function validatenews(thisform)
	{ 
	with (thisform)
	{
		 if (emptyvalidation(newsletter,"Please fill in your Email Address.")==false) 
			{
				newsletter.select();newsletter.focus();
				return false;
			}	
			var flag=checkDomain($.trim($('#newsletter').val()));
		   if(flag==0)
		   {
		       alert("Sorry, You have entered an Invalid Email Address.");
	 		    newsletter.select();newsletter.focus();
			   	return false;
		   }			
				
			 thisform.submit();
		}			
		return false;
}
function checkDomain(emailid)
{ var domain_status = $.ajax({url: 'email-validate.php?email='+emailid,async: false}).responseText;  return  domain_status;}

function emptyvalidation(entered, alertbox)
{
	with (entered)
	{
		while (value.charAt(0) == ' ')
			value = value.substring(1);
		while (value.charAt(value.length - 1) == ' ')
			value = value.substring(0, value.length - 1);
		if (value==null || value=="")
		{
			if (alertbox!="") alert(alertbox);
			return false;
		}
		else return true;
	}
}