var http = createRequestObject2();
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 sendRequest2() {
	var rnd = Math.random();
	var name = escape(document.getElementById("name").value);
	var address = escape(document.getElementById("address").value);
	var postalcode = escape(document.getElementById("postalcode").value);
	var city = escape(document.getElementById("city").value);
	var country = escape(document.getElementById("country").value);
	var phone = escape(document.getElementById("phone").value);
	var email = escape(document.getElementById("email").value);
	var information = escape(document.getElementById("information").value);

	try{
    http.open('POST', 'includes/pform.php');
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.onreadystatechange = handleResponse;
		http.send('&name='+name+'&email='+email+'&information='+information+'&address='+address+'&postalcode='+postalcode+'&city='+city+'&country='+country+'&phone='+phone);
	}
	catch(e){}
	finally{}
}

function check_values2() {
	var valid = '';
	
	var email = document.getElementById("email").value;
	if(trim(email) == "") {
			alert("Please complete all required fields...");
			//alert("Please complete all required fields");
	} else {
		if(isEmail(email)) {
			document.getElementById("submit").disabled=true;
			document.getElementById("submit").value='Please Wait..';
			sendRequest2();
		} else {
			alert("Email appears to be invalid.nPlease check.");
			document.getElementById("email").focus();
			document.getElementById("email").select();
		}
	}
}

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{}
}

function isUndefined(a) {
   return typeof a == 'undefined';
}

function trim(a) {
	return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

function isEmail(a) {
   return (a.indexOf(".") > 0) && (a.indexOf("@") > 0);
}

