var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
	var xmlHttp;

	// IE
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlHttp = false;
		}

	} else {
		// other
		try
		{
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			xmlHttp = false;
		}
	}

	if(!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		return xmlHttp;
}

function handleServerResponse()
{
  if(xmlHttp.readyState == 4)
  {	

  }
}	

function AjaxSend(){
  xmlHttp.open("POST", "/mailer.php", true);


  var VALlast_name = document.getElementById('contact_name').value;
  var VALcompany = document.getElementById('contact_company').value;
  var VALstreet = document.getElementById('contact_street').value;
  var VALzip = document.getElementById('contact_zip').value;
  var VALcity = document.getElementById('contact_city').value;
  var VALcountry = document.getElementById('contact_country').value;
  var VALphone = document.getElementById('contact_phone').value;
  var VALfax = document.getElementById('contact_fax').value;
  var VALemail = document.getElementById('contact_email').value;
  var VALcomments = document.getElementById('contact_comments').value;

  var params="last_name="+VALlast_name+"&company="+VALcompany+"&street="+VALstreet+"&zip="+VALzip+"&city="+VALcity+"&country="+VALcountry+"&phone="+VALphone+"&fax="+VALfax+"&email="+VALemail+"&comments="+VALcomments;


  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("Connection", "close");



  xmlHttp.onreadystatechange = handleServerResponse;
  xmlHttp.send(params);

  return true;
}		



function valiName()
{
	if(document.getElementById('contact_name').value != '')
		return true;
		
	alert('"Name" is a required field. Please enter your name!');
	return false;
}

function valiEmail()
{
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('contact_email').value))
		return true;
	
	alert('"Email" is a required field. Please enter a valid E-mail Address!');
	return false;
}


function go()
{
	if(valiName() && valiEmail())
	{
		document.getElementById('jon').onclick = '';
		AjaxSend();
		window.setTimeout('document.contactform.submit()', 1000);
	}
}

