// JavaScript Document
function validate_quickcontact(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;	
		}	
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = thisform.email.value;
  
	if(reg.test(address) == false) { 
      alert('Woops! You have entered an invalid Email Address');
	  email.focus();
	  email.select();
      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 Comments")==false) 
		{
		comments.focus();
		return false;	
		}
		if (emptyvalidation(userdigit,"Woops! You forgot to fill the Verification Code")==false) 
		{
		userdigit.focus();
		return false;	
		}	
		
	}
	
		runAjax('check_captcha','process_mail.php',document.quick_form.userdigit.value);		
		return false;
//   return false;	
//	thisform.submit();
}



function captcha_refresh()
{ 
document.getElementById("button_div").src='button_contactinfo.php?'+Math.random();
return false;
}
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+"?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.getElementById("load_button").innerHTML='<img src="images/ajax-loader2.gif" alt="" />';
			document.quick_form.submit();
			}
			else
			{
			
				 //document.getElementById("button_show_hide").innerHTML='<a href="#" onclick="return validateMainform(document.m_form);"><img  src="images/submit_button1.jpg" alt="" border="0" /></a>&nbsp;&nbsp;<a href="#" onclick="return clearMainTemplate(document.contactform);"><img  src="images/resetbutton.jpg" alt="" border="0" /></a>';
				captcha_refresh();
				document.quick_form.userdigit.value="Invalid Code";
				document.quick_form.userdigit.focus();
				document.quick_form.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
}

//aJax code ends here****************************************


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

