// JavaScript Document



function submitContactForm() {
	//this function queues a bill to be sent again
	firstName=document.getElementById('firstName').value
	lastName=document.getElementById('lastName').value
	phone=document.getElementById('phone').value
	email=document.getElementById('email').value
	comment=document.getElementById('comment').value
	//first, just make sure
	
		
	if (!firstName || !lastName || !email) {
		alert('You must at least enter your first name, last name and e-mail address.');
		
	} else {
		
		document.getElementById('contactSubmitButton').disabled=true;
		
		xmlHttpSubmitContactForm=GetXmlHttpObject()
			 if (xmlHttpSubmitContactForm==null)
			  {
			  alert ("Browser does not support HTTP Request")
			  return
			  } 
			  
		
		var params='firstName='+escape(firstName);
			params+='&lastName='+escape(lastName);
			params+='&phone='+escape(phone);
			params+='&email='+escape(email);
			params+='&comment='+escape(comment);
		
		
		var url='submitContactForm.php'
		
		xmlHttpSubmitContactForm.open("POST", url, true);
		xmlHttpSubmitContactForm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttpSubmitContactForm.setRequestHeader("Content-length", params.length);
		xmlHttpSubmitContactForm.setRequestHeader("Connection", "close");
		xmlHttpSubmitContactForm.send(params);
		xmlHttpSubmitContactForm.onreadystatechange=stateChangedSubmitContactForm
	
	}
	

}



function stateChangedSubmitContactForm() 
{ 
if (xmlHttpSubmitContactForm.readyState==4 || xmlHttpSubmitContactForm.readyState=="complete")
{
	
	 xmlDoc=xmlHttpSubmitContactForm.responseXML;
	
	var haveInfo=xmlDoc.getElementsByTagName("haveInfo")[0].childNodes[0].nodeValue;
	
	if (haveInfo==1) {
		document.getElementById('contactResponse').innerHTML='Thank you for contacting us. We will be in touch soon.';
		
		document.getElementById('firstName').value='';
		document.getElementById('lastName').value='';
		document.getElementById('phone').value='';
		document.getElementById('email').value='';
		document.getElementById('comment').value='';
		
		
		document.getElementById('contactSubmitButton').disabled=false;
		
	}
	
	
	
	
}
}


function GetXmlHttpObject()
 { 
 var objXMLHttp=null
 if (window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest()
  }
 else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
 return objXMLHttp
 }
 
