/* script validation for patient change password starts here */

function changepass_validate(thisform)
{ 
	with(thisform)
	{
		
		if(emptyvalidation(uname,"You forgot to enter Username")==false)
		{
			thisform.uname.focus();
			return false;
		}
		
		if(emptyvalidation(cpass,"You forgot to enter Current Password")==false)
		{
			cpass.focus();
			return false;
		}
		if(emptyvalidation(npass,"You forgot to enter New Password")==false)
		{		
			npass.focus();
			return false;
		}			
	}
	thisform.submit();
}
/* script validation for  patient change password ends here */

/* script validation for patient forgot password starts here */
function forgotpass_validate(thisform)
{ 
	with(thisform)
	{
		
		if(emptyvalidation(forgot_username,"You forgot to enter Username")==false)
		{
			thisform.forgot_username.focus();
			return false;
		}
		/* if(email_validate(forgot_username)==false)
		{
			alert("You have entered an invalid Email");
			forgot_username.select();
			forgot_username.focus();
			return false;
		}*/
			
	}
	thisform.submit();
}

/* script validation for forgot registration starts here */

/* script validation for patient registration starts here */

function pregistraion_validate(thisform)
{ 
	with(thisform)
	{
		
		if(emptyvalidation(first_name,"You forgot to enter First Name")==false)
		{
			thisform.first_name.focus();
			return false;
		}
		
		if(emptyvalidation(last_name,"You forgot to enter Last Name")==false)
		{
			last_name.focus();
			return false;
		}
		if(emptyvalidation(email,"You forgot to enter Email")==false)
		{		
			email.focus();
			return false;
		}
		 if(email_validate(email)==false)
		{
			alert("You have entered an invalid Email");
			email.select();
			email.focus();
			return false;
		}
		
	}
	thisform.submit();
}
/* script validation for  patient registration ends here */

/* script validation for subscribers starts here */

function addsubscriber_validate(thisform)
{ 
	with(thisform)
	{
		
		if(emptyvalidation(email,"You forgot to enter Email")==false)
		{
			email.focus();
			return false;
		}
		if(emailvalidate_other(email)==false)
		{
		   window.alert("You have entered an invalid Email");
		   email.focus();
		   email.select();
		   return false;
		}		
		
	}
	thisform.submit();
}
/* script validation for subscibers ends here */

/* script validation for healthcare starts here */

function validateHealthcare(arg)
{
	var phone1element =  document.getElementById("phone1");
	var phone2element =  document.getElementById("phone2");
 with(arg)
 {
  if(emptyvalidation(title,"You forgot to enter Title")==false)
  {
   title.focus();
   return false;
  }
  if(emptyvalidation(first_name,"You forgot to enter First Name")==false)
  {
   first_name.focus();
   return false;
  }
  if(emptyvalidation(last_name,"You forgot to enter Last Name")==false)
  {
   last_name.focus();
   return false;
  }
  if(emptyvalidation(clinic_name,"You forgot to enter Clinic/Practice Name")==false)
  {
   clinic_name.focus();
   return false;
  }
  /*
  if(emptyvalidation(clinic_address,"You forgot to enter Clinic/Practice Address")==false)
  {
   clinic_address.focus();
   return false;
  }
  */
  /*
  if (emptyvalidation(phone,"You forgot to enter Phone")==false) 
				{
					phone.focus();
					return false;
				}
		else
		 {
		      
				 for(var i=0;i<phone.value.length;i++)
				  {
					  if(!isDigit(phone.value.charAt(i)))
					  {
						alert("Invalid Phone Number");
						phone.select();
						return false;
					  }
				  }
				
		 }	
		 if(phone.value.length<3)
		 {
		   alert("Invalid phone number format. The format should be (xxx-xxx-xxxx)");	
		   phone.focus();
		   return false;
		 }
		
        

		if(phone1element.value == "" )
			{
				alert("You forgot to enter Phone");
				phone1element.focus();
				return false;
			}
		else
		 {
		      
				 for(var i=0;i<phone1element.value.length;i++)
				  {
					  if(!isDigit(phone1element.value.charAt(i)))
					  {
						alert("Invalid Phone Number");
						phone1element.select();
						return false;
					  }
				  }
				
		 }		
        if(phone1element.value.length<3)
		 {
		   alert("Invalid phone number format. The format should be (xxx-xxx-xxxx)");	
		   phone1element.focus();
		   return false;
		 }
		if(phone2element.value == "" )
			{
				alert("You forgot to enter Phone");
				phone2element.focus();
				return false;
			}

         else
		 {
		      
				 for(var i=0;i<phone2element.value.length;i++)
				  {
					  if(!isDigit(phone2element.value.charAt(i)))
					  {
						alert("Invalid Phone Number");
						phone2element.select();
						return false;
					  }
				  }
				
		 }	
		 if(phone2element.value.length<4)
		 {
		   alert("Invalid phone number format. The format should be (xxx-xxx-xxxx)");	
		   phone2element.focus();
		   return false;
		 }
  */
   /*
  result=phoneValidation(arg.phone.value)
	
	if(result==0)
	{
		alert("Invalid phone number");
		arg.phone.focus();
		arg.phone.select();
		return false;
	}
 */
	
	
  if(emptyvalidation(email,"You forgot to enter Email")==false)
  {
   email.focus();
   return false;
  }
  if(emailvalidate_other(email)==false)
  {
	   alert("You have entered an invalid Email");
	   email.focus();
	   email.select();
	   return false;
  }
 
}
 arg.submit();
}
 
 function clearall(arg)
 {
  arg.title.value='';
  arg.first_name.value='';
  arg.last_name.value='';
  arg.clinic_name.value='';
  arg.clinic_address.value='';
  arg.phone.value='';
  arg.phone1.value='';
  arg.phone2.value='';
  arg.email.value='';
  //window.location.href = "healthcare-signup.php#health";
 }
/* script validation for healthcare ends here */

/* script validation for get informed starts here */
function subscriber_checkphone1(arg)
{ 
 var count=arg.length;
 if(count==3)
 {
 document.add_subscriber.phone_home.value=arg+"-";
 }
 if(count==7)
 {
 document.add_subscriber.phone_home.value=arg+"-";
 }
}
function subscriber_checkphone2(arg)
{ 
 var count=arg.length;
 if(count==3)
 {
 document.add_subscriber.phone_mobile.value=arg+"-";
 }
 if(count==7)
 {
 document.add_subscriber.phone_mobile.value=arg+"-";
 }
}
function subscriber_checkphone3(arg)
{ 
 var count=arg.length;
 if(count==3)
 {
 document.add_subscriber.phone_work.value=arg+"-";
 }
 if(count==7)
 {
 document.add_subscriber.phone_work.value=arg+"-";
 }
}
/* script validation for get informed ends here */

/* script validation for talk with us starts here */


function contactUs(arg)
{
 with(arg)
 {
	     if(emptyvalidation(first_name,"You forgot to fill First Name")==false)
		 {
		 first_name.focus();
		 return false;
	 	 }
		 if(phone_home.value!='')
		 {			
			   if(isNaN(phone_home.value))
			   {
				 alert("Invalid Phone Number");
				 phone_home.focus();
				 return false;
			   }
			   else if(phone_home.value.length<3)
			   {
			   alert("Invalid phone number format. The format should be (xxx-xxx-xxxx)");	
			   phone_home.focus();
			   return false;
			   }
		 	   if(emptyvalidation(phone_home2,"Invalid phone number format. The format should be (xxx-xxx-xxxx)")==false)
		 	   {
		 		phone_home2.focus();
		 		return false;
	 	 		}
		 } 
		 
		 if(phone_home2.value!='')
		 {
			 if(isNaN(phone_home2.value))
			 {
				 alert("Invalid Phone Number");
				 phone_home2.focus();
				 return false;
			 }
			 else if(phone_home2.value.length<3)
		     {
		      alert("Invalid phone number format. The format should be (xxx-xxx-xxxx)");	
		      phone_home2.focus();
		      return false;
		     } 
			 if(emptyvalidation(phone_home3,"Invalid phone number format. The format should be (xxx-xxx-xxxx)")==false)
			 {
			 phone_home3.focus();
			 return false;
			 }
		 }
		 
		 if(phone_home3.value!='')
		 {
			 if(isNaN(phone_home3.value))
			 {
				 alert("Invalid Phone Number");
				 phone_home3.focus();
				 return false;
			 }
		    else if(phone_home3.value.length<4)
		    {
		    alert("Invalid phone number format. The format should be (xxx-xxx-xxxx)");	
		    phone_home3.focus();
		    return false;
		    }
		 }

		 if(emptyvalidation(email,"You forgot to fill Email")==false)
		 {
		 email.focus();
		 return false;
		 }
		
		 if(emailvalidate_other(email)==false)
		 {
			   alert("You have entered an invalid Email");
			   email.focus();
			   email.select();
			   return false;
		 }
		 if(emptyvalidation(find_our_website,"You forgot to fill how you find our website")==false)
		 {
		 find_our_website.focus();
		 return false;
		 }	
	          $("#submit_btn4").hide();
		  $('#wait4').show();
		//  $('#wait4').html('<img  src="http://www.obesitysurgery.ca/images/send.gif" alt=""  /><font color=#000> Please Wait...</font>'); 
arg.submit();
 }
    return false;
}


function contact_checkphone(arg)
{
 var count=arg.length;
 if(count==3)
 {
 document.contact_us.phone.value=arg+"-";
 }
 if(count==7)
 {
 document.contact_us.phone.value=arg+"-";
 }
}
function checkphone(arg)
{
 var count=arg.length;
 if(count==3)
 {
 document.health_care.phone.value=arg+"-";
 }
 if(count==7)
 {
 document.health_care.phone.value=arg+"-";
 }
}


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(strString.height_in.value!="")
  {
		 for(var i=0;i<strString.height_in.value.length;i++)
		 {
		   if(!isDigit(strString.height_in.value.charAt(i)))
			  {				
				strString.weight.disabled="disabled";
				strString.height_ft.disabled="disabled";
				strString.height_in.focus();
				strString.height_in.select();
				return false;
			  }
			  else
			  {
			   strString.weight.disabled=false;
			   strString.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 contactus_checkphone1(arg)
{ 
 var count=arg.length;
 if(count==3)
 {
 document.contact_us.phone_home.value=arg+"-";
 }
 if(count==7)
 {
 document.contact_us.phone_home.value=arg+"-";
 }
}
function contactus_checkphone2(arg)
{ 
 var count=arg.length;
 if(count==3)
 {
 document.contact_us.phone_mobile.value=arg+"-";
 }
 if(count==7)
 {
 document.contact_us.phone_mobile.value=arg+"-";
 }
}
function contactus_checkphone3(arg)
{ 
 var count=arg.length;
 if(count==3)
 {
 document.contact_us.phone_work.value=arg+"-";
 }
 if(count==7)
 {
 document.contact_us.phone_work.value=arg+"-";
 }
}

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

function checkvalue(val)
{
 if(val=='Other')
 {
  document.getElementById("descbox").style.display='block';	 
 }
 else
 {
  document.getElementById("descbox").style.display='none';	 
 }
}
/* script validation for talk with us ends here */


function phoneValidation(strString)
{
   var dashcount=0;
   var strValidChars = "0123456789-+ ";
   var strChar;
   var blnResult = true;
   if ((strString.length == 0) || (strString.length < 12)|| (strString.length >12) ) return false;
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
		  if( strString.charAt(i)=='-')
		  {	   
		   dashcount=dashcount+1;  
		  }
        strChar = strString.charAt(i) ;
         if (strValidChars.indexOf(strChar) == -1)
          {
			return 0;
          }
	
      }
		  if(dashcount!='2')
			 {
			   return 0;
			 }
}

//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 email_validate(objForm) 
 {
	
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = objForm.value;
   if(reg.test(address) == false)
   {
      //alert('Invalid Email Address');
      return false;
   }
  }
  

