// JavaScript Document
function Validatequickcontact(thisform)
{ 

	
	with (thisform)
	{
	
		 	if (emptyvalidation(fname,"Please fill in your Name.")==false) 
			{
				fname.select();
				fname.focus();
				return false;
			}
			
			
			if (emptyvalidation(email,"Please fill in your Email Address.")==false) 
			{
				email.select();
				email.focus();
				return false;
			}
			 if(emailvalidation(email)==false)
			{
				alert("Sorry, you have entered an invalid Email Address.");
				email.select();
				email.focus();
				return false;			
			}
			/*
			if (emptyvalidation(phone,"Please fill in your Phone Number.")==false) 
			{
				phone.select();
				phone.focus();
				return false;
			}
			*/
	/*	if(phonevalidation()==false)
		{
		       phoneno.select();
				phoneno.focus();
				return false;
		}*/
		if (emptyvalidation(comments,"Please fill in your Questions or Comments.")==false) 
			{
				
				comments.focus();
				return false;
			}
		 
		
	if (userdigit.value==userdigit.defaultValue || userdigit.value=="Invalid Verification Code")
			{
			userdigit.value="";	
			}
			if(emptyvalidation(userdigit,"Please fill Verification code.")==false)
			{
			userdigit.focus();
			return false;
			}
			document.getElementById("search").innerHTML='<br><img  src="images/ajax-loader.gif" alt="" align="right"  />';

			runAjax('check_captcha','process_mail.php',thisform.userdigit.value);
			
			return false;

			
			
		
	} 
	document.getElementById("search").innerHTML='<img  src="images/ajax-loader.gif" alt="" align="right"  />';
		
	runAjax('check_captcha','process_mail.php',document.contact_us.userdigit.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 captcha_refresh()
{ 
var code = Math.floor(Math.random()*90000);
document.getElementById("button_div").src='button1.php?code='+code;
document.contact_us.match.value=code;
return false;
}

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

var xmlHttp
function runAjax(field,argurl,argVal)
{
var match_code = document.contact_us.match.value;
//alert(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+"?userdigit="+argVal
url=url+"&code="+match_code
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")
	{ 
	//alert(xmlHttp.responseText);
			if(xmlHttp.responseText=="yes")
			{
	//alert("hello");
		//document.getElementById("loadimagenew").innerHTML='<img  src="http://www.wysework.com/projects/thomas/oharatech/development/images/ajax-loader.gif" alt=""  />';
			
		//	alert("submitted");	
			document.contact_us.submit();
		//	return true;
			
			}
			else
			{			
		//	alert("not submitted");	

				 document.getElementById("loadimagenew").innerHTML=' <div  style="margin:0px;" id=""><span id="search"><a href="#" title="Submit" class="learnmore" onclick="return Validatequickcontact(document.contact_us);return false;">SUBMIT</a></span><div class="clear"></div>';
				captcha_refresh();
				
			 	document.contact_us.userdigit.value="Invalid Verification Code";
					  document.contact_us.userdigit.blur();
			   //document.quickcontact.phoneno.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
}

