var companyHttp;
var companyXML;

function getXmlHttpObject()
{
    var _http=null;
    try
    {
      // Firefox, Opera 8.0+, Safari
      _http=new XMLHttpRequest();
    }
    catch (e)
    {
      // Internet Explorer
      try
      {
		 _http=new ActiveXObject("Microsoft.XMLHTTP");
         
      }
      catch (e)
      {
        _http=new ActiveXObject("Msxml2.XMLHTTP");
      }
    }
    if(_http==null){
        alert("Ajax is Not Supported");
    }
    return _http;
}

function sendEnquiry(){
	var isValid = $('#ContactForm').validate().form();
	//var isValid = true;
	if(!isValid){
		//validation triggered
	}else{
	    pageTracker._trackPageview("/email-confirmation/");
		var url="/processEnquiry.aspx";
		var params = "firstName="+document.getElementById("first_name").value;
		params+="&lastName="+document.getElementById("last_name").value;
		params+="&phone="+document.getElementById("phone").value;
		params+="&email="+document.getElementById("email").value;
		params+="&contactMsg="+document.getElementById("message").value;
		params += "&address=" + document.getElementById("address").value;
		var branch = document.getElementById("branch");
		index = branch.selectedIndex;
		params += "&location=" + branch[index].text;
		
		var contactMethod = document.getElementById("contact_method");
		index = contactMethod.selectedIndex;
		params += "&contactMethod=" + contactMethod[index].text;
		
		companyHttp=getXmlHttpObject();
		try{	
			companyHttp.open("POST",url);
			companyHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			companyHttp.setRequestHeader("Content-length", params.length);
			companyHttp.setRequestHeader("Connection", "close");
			companyHttp.onreadystatechange=confirmation;
		 }
		 catch(e){
			 alert("HTTP Init error:"+e);
		 }
	 
		// alert("Send");
		if( window.ActiveXObject && /Win/.test(navigator.userAgent) ) { 
		  try{
			companyHttp.send(params);
			document.getElementById("ContactForm").innerHTML="<div class=\"contact_msg\"><p>Thank you, your enquiry has been submitted</p></div>";
			}
			catch(e){
				alert("SEND ERROR");
			}
		}else{
			companyHttp.async=true;
			companyHttp.send(params);
			document.getElementById("ContactForm").innerHTML="<div class=\"contact_msg\"><p>Thank you, your enquiry has been submitted</p></div>";
	//		companyHttp.send(document.location.href+"?name=1");
		}
		return false;
	}
}

function confirmation(){
	
}