function formValidation(thisform)
{ 

	with (thisform)
	{
				
		if(emptyvalidation(fname,"Woops! You forgot to fill in your Name")==false) 
		{
			fname.focus();
			return false;
		}
		if(emptyvalidation(email,"Woops! You forgot to fill in your Email Address")==false) 
		{
			email.focus();
			return false;
		}
		if(echeck(email.value)==false)
		{
		  email.select();
			//arg.email_to.value="";
			email.focus();
			return false;
		}
			if(emptyvalidation(phone,"Woops! You forgot to fill in your Phone Number")==false) 
		{
			phone.focus();
			return false;
		}
		if(emptyvalidation(comments,"Woops! You forgot to fill in your Questions or Comments")==false) 
		{
			comments.focus();
			return false;
		}		
		document.getElementById("button_show_hide").innerHTML='<img  src="images/loader.gif" alt="" width="160px"/>';			
			//thisform.submit();
			runAjax('check_captcha','process_mail.php','sendmail');
		     return false;		
		thisform.submit();
	}
}



function formValidationContact(thisform)
{
	var phone1element =  document.getElementById("phone1");
	var phone2element =  document.getElementById("phone2");
	with (thisform)
	{
	
			
		if(emptyvalidation(fname_contact,"Woops! You forgot to fill in your First Name")==false) 
		{
			fname_contact.focus();
			return false;
		}
		if(emptyvalidation(lname,"Woops! You forgot to fill in your Last Name")==false) 
		{
			lname.focus();
			return false;
		}
		if(emptyvalidation(phone,"Woops! You forgot to fill in your Phone Number")==false) 
		{
			phone.focus();
			return false;
		}
		if(phone1element.value == "" )
			{
				alert("Woops! You forgot to fill in your phone number");
				phone1element.focus();
				return false;
			}

		if(phone2element.value == "" )
			{
				alert("Woops! You forgot to fill in your phone number");
				phone2element.focus();
				return false;
			}
		 
		if(emptyvalidation(email,"Woops! You forgot to fill in your Email Address")==false) 
		{
			email.focus();
			return false;
		}
		if(echeck(email.value)==false)
		{
		  email.select();
			//arg.email_to.value="";
			email.focus();
			return false;
		}
		
		if(emptyvalidation(address,"Woops! You forgot to fill in your Street Address")==false) 
		{
			address.focus();
			return false;
		}
		if(emptyvalidation(city,"Woops! You forgot to fill in your City")==false) 
		{
			city.focus();
			return false;
		}
		if(emptyvalidation(province,"Woops! You forgot to select your Province/State")==false) 
		{
			province.focus();
			return false;
		}
		if(emptyvalidation(reachme,"Woops! You forgot to select When to Reach me")==false) 
		{
			reachme.focus();
			return false;
		}
		if(thisform.formsubmit.value=="Y")
		{
			alert("Woops! Wait a while for submitting form");
			return false;
		}
		else
		{
			thisform.formsubmit.value="Y";
			//thisform.submit();
			//document.getElementById("button_show").innerHTML='<img  src="images/loading.gif" alt="" />';	images/loader.gif	
			document.getElementById("button_show").innerHTML='<img  src="images/loader.gif" alt="" width="160px"/>';
			//thisform.submit();
			runAjax2('check_captcha2','process_mail.php','sendmail');
		     return false;
		}
		
	}
	return true;
}




function emptyvalidation(entered, alertbox)
{
		
	with (entered)
	{
		value = entered.value;
	
		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 echeck(str) 
	{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Woops! You have entered an invalid Email Address")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Woops! You have entered an invalid Email Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Woops! You have entered an invalid Email Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Woops! You have entered an invalid Email Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Woops! You have entered an invalid Email Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Woops! You have entered an invalid Email Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Woops! You have entered an invalid Email Address")
		    return false
		 }
		
	 return true					
	}

function emailvalidation(entered,alertbox)
{
	with (entered)
	{
		lastpos=value.length-1;//Total Letters
		apos=value.indexOf("@"); //Total letters before @
		dotpos=value.lastIndexOf(".");//Total letters before .
		beforeStr=value.substring(0,apos);
		afterStr=value.substring(apos);
		dotafatpos=afterStr.indexOf(".");
		udslpos=beforeStr.lastIndexOf("_");
		dotfpos=beforeStr.indexOf(".");
		dotlpos=beforeStr.lastIndexOf(".");
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2 || dotfpos!=dotlpos || apos-1==udslpos || dotafatpos==1) 
		{if (alertbox) {alert(alertbox);} return false; }
		else {return true;}
	}
}	
var xmlHttp

function runAjax(field,argurl,argVal)

{

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

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

} 

var url=argurl

url=url+"?verify_digit="+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.quick_contact.submit();
					return true;

				

			}
			else
			{
				
				
					//document.quick_contact.submit();
					document.quick_contact.submit();
					return true;
				
			
			}

			

			

	} 

} 

/*         sdgdfgdfgdfgdfgdf                    */

var xmlHttp

function runAjax2(field,argurl,argVal)

{

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

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

} 

var url=argurl

url=url+"?verify_digit="+argVal
url=url+"&sid="+Math.random()
if(field=='check_captcha2')
xmlHttp.onreadystatechange=check_captcha2;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}

function check_captcha2() 

{ 

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

	{ 

			

			if(xmlHttp.responseText=="yes")

			{
				
					document.contact_us.submit();
					return true;

				

			}
			else
			{
				
				
					//document.quick_contact.submit();
					document.contact_us.submit();
					return true;
				
			
			}

			

			

	} 

} 


/*         sdgdfgdfgdfgdfgdf                    */



function GetXmlHttpObject()

{ 

	var objXMLHttp=null

if (window.XMLHttpRequest)

{

	objXMLHttp=new XMLHttpRequest()

}

else if (window.ActiveXObject)

{

	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

}

	return objXMLHttp

}
