
function reloadCAPTCHA() {
	document.getElementById('CAPTCHA').src='http://www.dandkimports.com/CAPTCHA/CAPTCHA_image.asp?'+Date();
}






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 validateContactForm(thisform)
{ 
	with (thisform)
	{
		
		 	if (emptyvalidation(fname,"Please fill in your Name.")==false) 
			{			
				fname.focus();
				return false;
			}
			
			
			if (emptyvalidation(email,"Please fill in your Email Address.")==false) 
			{
				email.select();
				email.focus();
				return false;
			}
		else
			{
				
   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("Sorry you have entered an invalid Email Address.");
	  email.focus();
	  email.select();
      return false;
   }	
				 		
			}	

			
			if (emptyvalidation(phone,"Please fill in your Phone.")==false) 
			{			
				phone.focus();
				return false;
			}
			if (emptyvalidation(comments,"Please fill in your Message.")==false) 
			{			
				comments.focus();
				return false;
			}
			
			if (emptyvalidation(securityCode,"Please fill in your Verification Code.")==false) 
			{			
				securityCode.focus();
				return false;
			}	
				
	
	}
	runAjax('check_captcha','http://www.dandkimports.com/process-mail.asp',thisform.securityCode.value);
	//thisform.submit();
return false;
}
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+"?securityCode="+argVal
//alert(url);
url=url+"&sid="+Math.random()
if(field=='check_captcha')
xmlHttp.onreadystatechange=check_captcha;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function check_captcha() 
{ 
//alert(xmlHttp.readyState);
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
//	alert(xmlHttp.responseText);
			if(xmlHttp.responseText=="yes")
			{
		
			
			document.frmaskaQuestion.submit();
		//	return true;
			
			}
			else
			{			

				 //document.getElementById("loadimagenew").innerHTML='<a href="#" onclick="return validate_contactus(document.contactform);"><img src="grafx/submit.jpg" border="0"  /></a>';
				reloadCAPTCHA();
				//document.getElementById("img_loader").innerHTML='<div id="submit-contact"> <a href="#" class="view"  onClick="return Validatequickcontact(document.quickcontact);" ><span>Submit</span></a> <br clear="all" /></div>';
			 	document.frmaskaQuestion.securityCode.value="Invalid Verification Code";
		     //	document.frmaskaQuestion.securityCode.focus();
			//	document.frmaskaQuestion.securityCode.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
}
//----------------------------------------------------------------------
