function validate_contactus()
{
  if(document.frm_contact.txtName.value=="")
  {
  alert("Please enter name!");
  document.frm_contact.txtName.focus();
  return false;
  }

  if(document.frm_contact.txtEmail.value=="")
  {
  alert("Please enter email address!");
  document.frm_contact.txtEmail.focus();
  return false;
  }
  
  if(validate_email(document.frm_contact.txtEmail,"Invalid email address! Please re-enter!")==false)
  {
  document.frm_contact.txtEmail.select();
  document.frm_contact.txtEmail.focus();
  return false;
  }
  
  if(document.frm_contact.txtAddress.value=="")
  {
  alert("Please enter address!");
  document.frm_contact.txtAddress.focus();
  return false;
  }
  
  if(document.frm_contact.txtTel.value=="" || document.frm_contact.txtTel.value=="Number")
  {
  alert("Please enter phone number!");
  document.frm_contact.txtTel.focus();
  return false;
  }
  
  if(IsNumeric(document.frm_contact.txtTel.value)==false)
  {
  alert("Invalid phone number! Please re-enter!");
  document.frm_contact.txtTel.select();
  document.frm_contact.txtTel.focus();
  return false;
  }
  
  if(document.frm_contact.txtFax.value!=""){
  
  if(IsNumeric(document.frm_contact.txtFax.value)==false)
  {
  alert("Invalid fax number! Please re-enter!");
  document.frm_contact.txtFax.select();
  document.frm_contact.txtFax.focus();
  return false;
  }
  }
  if(document.frm_contact.txtComments.value=="")
  {
  alert("Please enter comments!");
  document.frm_contact.txtComments.focus();
  return false;
  }
  if(document.frm_contact.txtCode.value=="")
  {
  alert("Please enter code!");
  document.frm_contact.txtCode.focus();
  return false;
  }
var name	= document.frm_contact.txtName.value;
var email	= document.frm_contact.txtEmail.value;
var address	= document.frm_contact.txtAddress.value;
var address = address.replace(/\n/g, "<br />");
var phone	= document.frm_contact.txtTel.value;
var fax		= document.frm_contact.txtFax.value;
var comment	= document.frm_contact.txtComments.value;
var comment = comment.replace(/\n/g, "<br />");
var code	= document.frm_contact.txtCode.value;
authenticate_contact(name,email,address,phone,fax,comment,code)
return true;
//document.frm_contact.submit();
}
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
function authenticate_contact(nameVal,emailVal,addressVal,phoneVal,faxVal,commentVal,codeVal) {	

	var strURL="http://www.merlonbuilders.com/mails/mailsend.php?name="+nameVal+"&email="+emailVal+"&address="+addressVal+"&phone="+phoneVal+"&fax="+faxVal+"&comment="+commentVal+"&code="+codeVal;
	//var strURL="http://localhost/works/merlon/mails/mailsend.php?name="+nameVal+"&email="+emailVal+"&address="+addressVal+"&phone="+phoneVal+"&fax="+faxVal+"&comment="+commentVal+"&code="+codeVal;
		var req = getXMLHTTP();
		//alert(thisVal1)
			if (req) {
				//document.getElementById('listClientDetails').style.display='block';
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						// only if "OK"
						if (req.status == 200) {	
						 	if(req.responseText.match(/^OK/) != null) {
        					// alert('Your message has been sent!');  
							
							//window.location="http://localhost/works/merlon/thanks.php";
							window.location="http://www.merlonbuilders.com/thanks.php";
         
        					} else {
          					alert(req.responseText);
							document.frm_contact.txtCode.select();
        					}
														
						} else {
							alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
					}				
				}			
				req.open("POST", strURL, true);
				//req.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
				req.send(null);
			}			
		
	}
