function patientValidate(thisform)
{ 
	with (thisform)
	{
					
		if(emptyvalidation(surname,"Please enter your surname")==false) 
		{
			surname.focus();
			return false;
		}
		if(emptyvalidation(gNames,"Please enter your given names")==false) 
		{
			gNames.focus();
			return false;
		}
		if(emptyvalidation(address,"Please enter your address")==false) 
		{
			address.focus();
			return false;
		}
		if(emptyvalidation(city,"Please enter your city")==false) 
		{
			city.focus();
			return false;
		}
		if(emptyvalidation(postalCode,"Please enter your postal code")==false) 
		{
			postalCode.focus();
			return false;
		}
		
		if(emptyvalidation(homeTel,"Please enter phone number")==false) 
		{
			homeTel.focus();
			return false;
		}
		if(homeTel.value.length<10)
		{
		alert('Invalid Phone Number');
		homeTel.select();
		homeTel.focus();
		return false;
		}
		if(emptyvalidation(email,"Please enter email")==false) 
		{
			email.focus();
			return false;
		}
		if(email.value!="")
		{
			if(emailCheck(email)==false)
			{
				alert("Invalid email ID");
				email.select();
				email.focus();
				return false;
			}
		}
		if(emptyvalidation(age,"Please enter your age")==false) 
		{
			age.focus();
			return false;
		}
		if(emptyvalidation(height_ft,"Please enter height in feet")==false) 
		{
			height_ft.focus();
			return false;
		}
		
		if(checkNum(height_ft.value)==false)
		{
		alert('Enter valid feet');
		height_ft.select();
		height_ft.focus();
		return false;
		}
		if(emptyvalidation(height_in,"Please enter height in inches")==false) 
		{
			height_in.focus();
			return false;
		}
		
		if(checkNum(height_in.value)==false)
		{
		alert('Enter valid inches');
		height_in.select();
		height_in.focus();
		return false;
		}
		if(emptyvalidation(weight,"Please enter weight")==false) 
		{
			weight.focus();
			return false;
		}
		
		if(checkNum(weight.value)==false)
		{
		alert('Enter a valid weight');
		weight.select();
		weight.focus();
		return false;
		}
		
		if (userdigit4.value==userdigit4.defaultValue)
			{
    		userdigit4.value="";	
    		}

			if(emptyvalidation(userdigit4,"Woops! You forgot to fill Verification code")==false)
    		{
			userdigit4.focus();
			return false;
			}
			runAjax4('check_captcha4','http://www.obesitysurgery.ca/process_mail_contact.php',document.patientQuestionnaire.userdigit4.value);
			
		
		 //$("#submit_btn6").hide();
		 //$('#wait6').show();
		//thisform.submit();
	}
	return false;
}
function captcha_refresh4()

{

document.getElementById("button_div4").src='http://www.obesitysurgery.ca/button-contact.php?'+Math.random();

return false;

}


var xmlHttp

function runAjax4(field,argurl,argVal)

{

//document.getElementById("check_captcha").innerHTML=" Loading...";

xmlHttp2=GetXmlHttpObject()

if (xmlHttp2==null)

{

alert ("Browser does not support HTTP Request")

return

} 

var url=argurl

url=url+"?userdigit="+argVal

url=url+"&sid="+Math.random()

if(field=='check_captcha4')

xmlHttp2.onreadystatechange=check_captcha4;

xmlHttp2.open("GET",url,true)

xmlHttp2.send(null)

}

function check_captcha4() 

{ 

	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")

	{ 

			if(xmlHttp2.responseText=="yes")

			{
		  $("#submit_btn6").hide();
		  $('#wait6').show();
		  $('#wait6').html('<img  src="http://www.obesitysurgery.ca/images/send.gif" alt=""  /><font color=#000> Please Wait...</font>'); 
		  
		  //thisform.submit();
		  document.patientQuestionnaire.submit();
			}

			else

			{

				captcha_refresh4();

				alert("Verification code mismatch");

				document.patientQuestionnaire.userdigit4.focus();

				document.patientQuestionnaire.userdigit4.select();

				return false;

			}

			

	} 

} 

function GetXmlHttpObject()

{ 

	var objXMLHttp=null

if (window.XMLHttpRequest)

{

	objXMLHttp=new XMLHttpRequest()

}

else if (window.ActiveXObject)

{

	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

}

	return objXMLHttp

}














function checkNum(strString)
{
 if(document.patientQuestionnaire.height_ft.value!="")
  { 
		 for(var i=0;i<document.patientQuestionnaire.height_ft.value.length;i++)
		 {
		   if(!isDigit(document.patientQuestionnaire.height_ft.value.charAt(i)))
			  {
				alert("Value should be number");
				document.patientQuestionnaire.height_in.disabled="disabled";
				document.patientQuestionnaire.weight.disabled="disabled";
				document.patientQuestionnaire.height_ft.focus();
				document.patientQuestionnaire.height_ft.select();
				return false;				
			  }
			  else
			  {
			    document.patientQuestionnaire.height_in.disabled=false;
				document.patientQuestionnaire.weight.disabled=false;
			  }
			
		 }	
   }
    if(document.patientQuestionnaire.height_in.value!="")
  {
		 for(var i=0;i<document.patientQuestionnaire.height_in.value.length;i++)
		 {
		   if(!isDigit(document.patientQuestionnaire.height_in.value.charAt(i)))
			  {				
				document.patientQuestionnaire.weight.disabled="disabled";
				document.patientQuestionnaire.height_ft.disabled="disabled";
				document.patientQuestionnaire.height_in.focus();
				document.patientQuestionnaire.height_in.select();
				return false;
			  }
			  else
			  {
			   document.patientQuestionnaire.weight.disabled=false;
			   document.patientQuestionnaire.height_ft.disabled=false;
			  }
		 }	
   }	
   
    if(document.patientQuestionnaire.weight.value!="")
  {
		 for(var i=0;i<document.patientQuestionnaire.weight.value.length;i++)
		 {
		   if(!isDigit(document.patientQuestionnaire.weight.value.charAt(i)))
			  {
				alert("Value should be number");
				document.patientQuestionnaire.height_ft.disabled="disabled";
				document.patientQuestionnaire.height_in.disabled="disabled";
				document.patientQuestionnaire.weight.focus();
				document.patientQuestionnaire.weight.select();
				return false;
			  }
			  else
			  {
			   document.patientQuestionnaire.height_ft.disabled=false;
			   document.patientQuestionnaire.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.patientQuestionnaire.height_ft.value!="")&&(document.patientQuestionnaire.weight.value!="")&&(document.patientQuestionnaire.height_in.value=="")){document.patientQuestionnaire.height_in.value=0;}
 var ht=0;
 var hi=0;
 var w=0;
   if(document.patientQuestionnaire.height_in.value!="")
  {
		 for(var i=0;i<document.patientQuestionnaire.height_in.value.length;i++)
		 {
		   if(!isDigit(document.patientQuestionnaire.height_in.value.charAt(i)))
			  {
				alert("Value should be number");
				document.patientQuestionnaire.weight.disabled="disabled";
				document.patientQuestionnaire.height_ft.disabled="disabled";
				document.patientQuestionnaire.height_in.focus();
				document.patientQuestionnaire.height_in.select();
				return false;
			  }
			  else
			  {
			   document.patientQuestionnaire.weight.disabled=false;
			   document.patientQuestionnaire.height_ft.disabled=false;
			  }
		 }	
   }	
 
    for(var i=0;i<document.patientQuestionnaire.height_ft.value.length;i++)
		 {
		   if(isDigit(document.patientQuestionnaire.height_ft.value.charAt(i)))
			  {
				ht=1;			
			  }			
		  }
	for(var i=0;i<document.patientQuestionnaire.height_in.value.length;i++)
		 {
		   if(isDigit(document.patientQuestionnaire.height_in.value.charAt(i)))
			  {
				hi=1;			
			  }			
		  }	
	for(var i=0;i<document.patientQuestionnaire.weight.value.length;i++)
		 {
		   if(isDigit(document.patientQuestionnaire.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.patientQuestionnaire.height_ft.value!="") && (document.patientQuestionnaire.height_in.value!="") && (document.patientQuestionnaire.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);
}		