function chkemail(emval)
{
        var posi = 0;
        var posj = 0;
        var iflg = "false";
        var jflg = "false";
        for(i=0;i<=emval.length;i++)
        {
                if(emval.substr(i, 1) == "\@")
                {
                        posi = i+1;
                        iflg = "true";
                }
                if(emval.substr(i, 1) == ".")
                {
                        posj = i+1;
                        jflg = "true";
                }
        }
        if(posi == "1" || (posi+1) == posj || posj == emval.length || iflg == "false" || jflg == "false")
        {
                return false;
        }
        else
        {
                return true;
        }
}
function IsEmpty(aTextField) {
	act_val = stringTrim(aTextField.value);
	if ((act_val.length==0) ||
   (act_val==null)) {
      return true;
   }
   else { return false; }
}
function changeCapthaImage()
{
	
	regContentPasteAt = "imgcap_div";
	document.getElementById(regContentPasteAt).innerHTML = "Please wait";
	var url = "ajax_img_captha_change.php";
	loadXMLDocChangeCaptha(url);
}
<!-- Begin
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
//alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
//alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}
//  End -->
function validImageCatha(captha_val) {

  	if(captha_val == document.getElementById('img_cap_val').value)
  	{
  		return true;
  	}
  	else
  	{
  		return false;
  	}
}		

function stringTrim(strToTrim) {
	return(strToTrim.replace(/^\s+|\s+$/g, ''));
}
function checkContactValidation()
{
	if(IsEmpty(document.getElementById('contact_name')))
	{
		alert("Please enter your name.");
		document.getElementById('contact_name').focus();
		return false;
		
	}

	if(IsEmpty(document.getElementById('contact_email')))
	{
		
		alert("Please enter your email address.");
		document.getElementById('contact_email').focus();
		return false;
	}
	else
	{
		if(!chkemail(document.getElementById('contact_email').value))
		{
			alert("Oops! You have entered invalid email address.");
			document.getElementById('contact_email').focus();
			return false;
		}
	}
	if(document.getElementById('month').selectedIndex == 0)
	{
		alert("Please select month.");
		document.getElementById('month').focus();
		return false;
	}

	if(document.getElementById('day').selectedIndex == 0)
	{
		alert("Please select day.");
		document.getElementById('day').focus();
		return false;
	}

	if(document.getElementById('year').selectedIndex == 0)
	{
		alert("Please select year.");
		document.getElementById('year').focus();
		return false;
	}
	if(document.getElementById('month').selectedIndex != 0 && document.getElementById('day').selectedIndex != 0 && document.getElementById('year').selectedIndex != 0)
	{
		var dateStr = document.getElementById('month').value + "/" + document.getElementById('day').value + "/" + document.getElementById('year').value;
		if(!isValidDate(dateStr))
		{
			alert("Oops! You have entered invalid date.");
			document.getElementById('month').focus();
			return false;
		}
	}
	if(IsEmpty(document.getElementById('contact_query')))
	{
		
		alert("Please enter your question.");
		document.getElementById('contact_query').focus();
		return false;
	}
	if(!validImageCatha(document.getElementById("imgverify").value))
	{
		alert("Sorry! Entered text did not matched with image text.");
		document.getElementById('imgverify').focus();
		return false;
	}
	
}
function loadXMLDocChangeCaptha(url)
{
	// branch for native XMLHttpRequest object
	//alert(1);
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChangeCaptha;
		req.open("GET", url, true);
		req.send(null);
		// branch for IE/Windows ActiveX version
	}
	else if (window.ActiveXObject)
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req)
		{
			req.onreadystatechange = processReqChangeCaptha;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processReqChangeCaptha()
{
	// only if req shows "complete"
	if (req.readyState == 4)
	{
		
		// only if "OK"
		if (req.status == 200)
		{
			response = req.responseXML.documentElement;
			var urlpath='';
			////alert(response.getElementsByTagName('testingnode')[0].childNodes[x].data); inside for loop
			for(var x = 0; response.getElementsByTagName('urlpath')[0].childNodes[x]; x++ )
				 urlpath = urlpath.concat(response.getElementsByTagName('urlpath')[0].childNodes[x].data);			
			document.getElementById(regContentPasteAt).innerHTML = urlpath;
			
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}
