function validate() {	
	if(document.contactUsForm.first_name.value == "") {
		 document.getElementById("ErrorContact").innerHTML = "Please enter your First Name.";		 
		 document.contactUsForm.first_name.focus();
		 return;
	} else if(document.contactUsForm.last_name.value == "") {		 
		 document.getElementById("ErrorContact").innerHTML = "Please enter your Last Name.";		 
		 document.contactUsForm.last_name.focus();
		 return;
	} else if(document.contactUsForm.email.value == "" || validateEmailv2(document.contactUsForm.email.value) == false) {		 
		 document.getElementById("ErrorContact").innerHTML = "Please enter your Email.";
		 document.contactUsForm.email.focus();
		 return;
	} else if(document.contactUsForm.enquiry_subject.value == "") {
		 document.getElementById("ErrorContact").innerHTML = "Please select a Tour Pakcages.";
		 return;
	}	
	checkCode();
	//document.contactUsForm.submit();
}
var xmlhttp;
xmlhttp=GetXmlHttpObject();
function checkCode() {
	var code = document.getElementById("codeInput").value;
	if(code == "") {
		document.getElementById("ErrorContact").innerHTML="Please enter the answer!"
		document.getElementById("codeInput").focus();
	} else {		
		var url="http://www.catcityholidays.com/html/checkcode.php";
		url=url+"?code="+code;		
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}

function stateChanged() {	
	if (xmlhttp.readyState==4) {		
		if(xmlhttp.responseText != 1) {
			document.getElementById("ErrorContact").innerHTML="Please enter the answer!"
			document.getElementById("codeInput").focus();
		} else {
			//document.getElementById("ErrorCode").innerHTML= "";
			document.contactUsForm.submit();
		}		
	}
}
function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
  		return new ActiveXObject("Microsoft.XMLHTTP");
  	}
	return null;
}
