//var baseURLQ = location.href.substring(0,location.href.indexOf(".com")) + ".com";
function  formvalidation(thisform)
{ 
	var phone1element =  document.getElementById("phone1");
	var phone2element =  document.getElementById("phone2");
	with (thisform)
	{ 
			if(fname.value=="name*")fname.value="";		
			if (emptyvalidation(fname,"Woops! You forgot to fill in your name")==false) 
			{
				fname.select();
				fname.focus();
				return false;
			}
			
			if(email.value=="email*")email.value="";		
			if (emptyvalidation(email,"Woops! You forgot to fill in your email address")==false) 
			{
				email.select();
				email.focus();
				return false;
			}
			
			if(emailvalidation(email)==false)
			{
				alert("Woops! You have entered an invalid email address");
				email.select();
				email.focus();
				return false;
			}
						
			if (emptyvalidation(phone,"Woops! You forgot to fill in your phone number")==false) 
			{
				phone.select();
				phone.focus();
				return false;
			}
			else
		 {
		    		  if(isNaN(phone.value))
					   {
						alert("Woops! Phone number cannot contain characters");
						phone.select();
						return false;
					  }
						
		 }	
		 if(phone.value.length<3)
		 {
		   alert("Please enter your area code and full phone number (xxx xxx xxxx) in order to submit your form. Thank you!");	
		   phone.focus();
		   return false;
		 }
		if(phone1element.value == "" )
			{
				alert("Please enter your area code and full phone number (xxx xxx xxxx) in order to submit your form. Thank you!");
				phone1element.focus();
				return false;
			}
		else
		 {
		      	  if(isNaN(phone1element.value))
					  {
						alert("Woops! Phone number cannot contain characters");
						phone1element.select();
						return false;
					  }
								
		 }		
         if(phone1element.value.length<3)
		 {
		   alert("Please enter your area code and full phone number (xxx xxx xxxx) in order to submit your form. Thank you!");	
		   phone1element.focus();
		   return false;
		 }
		if(phone2element.value == "" )
			{
				alert("Please enter your area code and full phone number (xxx xxx xxxx) in order to submit your form. Thank you!");
				phone2element.focus();
				return false;
			}

         else
		 {
		     		  if(isNaN(phone2element.value))
					  {
						alert("Woops! Phone number cannot contain characters");
						phone2element.select();
						return false;
					  }
						
		 }	
		 if(phone2element.value.length<4)
		 {
		   alert("Please enter your area code and full phone number (xxx xxx xxxx) in order to submit your form. Thank you!");	
		   phone2element.focus();
		   return false;
		 }
        
			if(comments.value=="comments*")comments.value="";
			if (emptyvalidation(comments,"Woops! You forgot to fill in your comments")==false) 
			{
				comments.select();
				comments.focus();
				return false;
			}
				if(userdigit.value=="verification code")userdigit.value="";
		if(emptyvalidation(userdigit,"Please fill in Verification Code.")==false) 
		{
		userdigit.focus();
		return false;
		}	
		 $("#submit_btn").hide();
		  $('#wait').show();
		  $('#wait').html('<img  src="http://www.ocps.com/images/loader.gif" alt=""  /><font color=#f9efe5> Please Wait...</font>'); 
			//alert('document.getElementById("button_show_hide")');
			//document.getElementById("button_show_hide").innerHTML='<img src="images/loader.gif" alt="" />';
			//var pasurlq=baseURLQ+'/email_validate.php';
			var pasurlq='http://www.ocps.com/email_validate.php';
				checkemaildomain('check_cemail',document.form1.email.value,pasurlq);
	
		//
	}

}
function checkemaildomain(field,argVal,argurl)
{

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url=argurl 
url=url+"?email="+argVal
url=url+"&sid="+Math.random()
if(field=='check_cemail')
xmlHttp.onreadystatechange=check_email;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function check_email() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	//alert(xmlHttp.responseText);
			
			if(xmlHttp.responseText==0) 
			{
			 $("#submit_btn").show();
			 $('#wait').hide();
			 alert("Woops! Invalid email address");
			 document.form1.email.focus();
			 document.form1.email.select();
			 return false;
			}
			else
			{
				runAjax('check_captcha','http://www.ocps.com/process_mail.php',document.form1.userdigit.value);
				//document.getElementById("button_show_hide").innerHTML='<img src="images/loader.gif" alt="" />';
				//document.form1.submit();
			}
		 
	} 
} 
function captcha_refresh()
{	
document.getElementById("button").src='http://www.ocps.com/button.php?'+Math.random();
return false;
}

<!--Ajax for checking the captcha code ends here -->

		var xmlHttp
		function runAjax(field,argurl,argVal)
		{
				xmlHttp=GetXmlHttpObject()
					if (xmlHttp==null)
					{
					alert ("Browser does not support HTTP Request")
					return
					} 
		var url=argurl
		url=url+"?userdigit="+argVal
		url=url+"&sid="+Math.random()
		if(field=='check_captcha')
		xmlHttp.onreadystatechange=check_captcha;
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
		}

	function check_captcha() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			
				if(xmlHttp.responseText=="yes")
				{
					document.form1.submit();
				}
				else
				{
					captcha_refresh();
					
					alert("Verification code mismatch");
					$("#submit_btn").show();
					$('#wait').hide();
					document.form1.userdigit.focus();
					document.form1.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
}

function nextbox(fldobj,nbox)
{
	if(fldobj.value.length>2) 
	{
	document.forms[0].elements[nbox].focus()
	}
}

 

