// JavaScript Document
function validate_contact(thisform)
{
	with (thisform)
	{
	//	if(fname.value=="Name")fname.value="";	
	if (emptyvalidation(fname,"Woops! You forgot to fill in your Name")==false) 
		{
		fname.focus();
		return false;	
		}
		
	/*if(email.value=="Email")email.value=""; */	
	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 in your Verification code")==false) 
		{
			userdigit.focus();
			return false;
		}	
		
		
	}
	document.getElementById("load_button1").innerHTML='<img src="http://www.southportdata.com/images/ajax-loader1.gif" width=100 height=19 border=0 alt="" />';
  
	//thisform.submit();
	 runAjaxcontact('check_captcha','process_mail.php',document.contact.userdigit.value);
	return false;	
}	



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_refresh_contact()
{ 
document.getElementById("button_condiv").src='button.php?'+Math.random();
return false;
}

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

var xmlHttp
function runAjaxcontact(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_captcha1;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function check_captcha1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	
	
			if(xmlHttp.responseText=="yes")
			{
		
		    document.getElementById("load_button1").innerHTML='<img src="images/loader2.gif" alt="" />';
			document.contact.submit();
		//	return true;
			
			}
			else
			{			
				
				 document.getElementById("load_button1").innerHTML='<a href="#" onclick="return validate_contact(document.contact)" ><img src="images/submit_red.jpg" alt="" width="71" height="26"  style="margin:0;padding:0;border:0;float:none"; /></a>';
				captcha_refresh_contact();
				
				document.contact.userdigit.value="Invalid Verification Code";
				document.contact.userdigit.focus();
				document.contact.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
}
