var http = createRequestObject();
var areal = Math.random() + "";
var real = areal.substring(2,6);

function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}
function isEmail(a) {
   return (a.indexOf(".") > 0) && (a.indexOf("@") > 0);
}


function sendRequest() {
	var rnd = Math.random();
	var name = escape(document.getElementById("name").value);
	var email = escape(document.getElementById("email").value);
	var type = escape(document.getElementById("type").value);
	var message = escape(document.getElementById("message").value);
	if (trim(name)=="" || trim(email)=="" || trim(message)==""){
		alert ("Please complete all the fields")
		return false;
	}
	if (!isEmail(email)){
		alert("Email appears to be invalid\nPlease check and try again");
		document.getElementById("email").focus();
		document.getElementById("email").select();
		return false;
	}

	try{
    http.open('POST',  'request_emailer.php');
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.onreadystatechange = handleResponse;
		http.send('name='+name+'&email='+email+'&type='+type+'&message='+message+'&rnd='+rnd);
	}
	catch(e){}
	finally{}
	return false;
}

function handleResponse() {
	try{
    if((http.readyState == 4)&&(http.status == 200)){
    	var response = http.responseText;
      document.getElementById("confirmation").innerHTML = response;
      document.getElementById("confirmation").style.display ="";
		}
  }
	catch(e){}
	finally{}
}

