// JavaScript Document

var siteUrl='http://www.thornhillskinclinic.com/';
function  Formvalidation(thisform)
{ 
	with (thisform)
	{ 		
			if (emptyvalidation(first_name,"Please fill in your First Name.")==false) 
			{
				first_name.select();
				first_name.focus();
				return false;
			}
			if (emptyvalidation(last_name,"Please fill in your Last Name.")==false) 
			{
				last_name.select();
				last_name.focus();
				return false;
			}
			if (emptyvalidation(age,"Please select your Age.")==false) 
			{
				
				age.focus();
				return false;
			}
			if (emptyvalidation(gender,"Please select your Gender.")==false) 
			{
				
				gender.focus();
				return false;
			}
			if (emptyvalidation(city,"Please fill in your City.")==false) 
			{
				city.select();
				city.focus();
				return false;
			}
			if (emptyvalidation(state,"Please fill in your State/Province.")==false) 
			{
				state.select();
				state.focus();
				return false;
			}
			if (emptyvalidation(zip_code,"Please fill in your Zip Code/Postal Code.")==false) 
			{
				zip_code.select();
				zip_code.focus();
				return false;
			}
			if (emptyvalidation(emailaddr,"Please fill in your Email Address.")==false) 
			{
				emailaddr.select();
				emailaddr.focus();
				return false;
			}
			if(emailvalidation(emailaddr)==false)
			{
				alert("Sorry, you have entered an invalid Email Address.");
				emailaddr.select();
				emailaddr.focus();
				return false;
			}
			
			if (emptyvalidation(interest,"Please fill What procedure or treatments are you interested in?")==false) 
			{
				interest.select();
				interest.focus();
				return false;
			}
			
 	if (userdigit1.value==userdigit1.defaultValue || userdigit1.value=="Invalid Verification Code")
			{
			userdigit1.value="";	
			}
			if(emptyvalidation(userdigit1,"Please fill Verification Code.")==false)
			{
			userdigit1.focus();
			return false;
			}
			document.getElementById("loadimagenew1").innerHTML='<img  src="'+siteUrl+'images/ajax-loader.gif" alt=""  />';

			runAjax1('check_captcha1',''+siteUrl+'process_mail1.php',thisform.userdigit1.value);
			
			return false;

			
			
		
	} 
	document.getElementById("loadimagenew1").innerHTML='<img  src="'+siteUrl+'images/ajax-loader.gif" alt=""  />';
		
	runAjax1('check_captcha1',''+siteUrl+'process_mail1.php',document.contact_us.userdigit1.value);
return false;	
//thisform.submit();			
	
}
// JavaScript Document

function emailvalidation(thisform) {

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = thisform.value;
   var email = address.split(',');
   
   for (var i = 0; i < email.length; i++) {
   if(reg.test(email[i]) == false) {
     // alert('Invalid Email Address');
      return false;
   }
   else
   {
    }
   }
}

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;
	}
}
//------------------------------------------------------

function captcha_refresh1()
{ 
document.getElementById("button_div1").src=''+siteUrl+'button1.php?'+Math.random();
return false;
}

<!--Ajax for checking the captcha code ends here -->

var xmlHttp
function runAjax1(field,argurl,argVal)
{
//document.getElementById("check_captcha1").innerHTML=" Loading...";
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url=argurl
url=url+"?userdigit1="+argVal
url=url+"&sid="+Math.random()
if(field=='check_captcha1')
xmlHttp.onreadystatechange=check_captcha1;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function check_captcha1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	//alert(xmlHttp.responseText);
			if(xmlHttp.responseText=="yes")
			{
		
		//document.getElementById("loadimagenew").innerHTML='<img  src="http://www.wysework.com/projects/thomas/oharatech/development/images/ajax-loader.gif" alt=""  />';
			
			
			document.contact_us.submit();
		//	return true;
			
			}
			else
			{			

				 document.getElementById("loadimagenew1").innerHTML=' <div id="submit" style="margin:0px;"><a href="#" title="Submit" onclick="return Formvalidation(document.contact_us);return false;">Submit</a></div>';
				captcha_refresh1();
				
			 	document.contact_us.userdigit1.value="Invalid Verification Code";
		      //  document.quickcontact.userdigit.focus();
				//document.quickcontact.userdigit.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
}

