var xmlHttp;

function emailupdatesubmit() {
 document.getElementById("emailupdate_error").innerHTML = "";
 document.getElementById("emailupdate_pleasewait").innerHTML = "<p align=\"center\"><img src=\"http://www.influx.co.uk/wordpress/images/pleasewait.gif\" /></p>";
 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url="http://www.influx.co.uk/wordpress/wp-includes/pi-library.php";

 var params = "name="+document.getElementById("sub_name").value+"&email="+document.getElementById("sub_email").value;
 if (document.getElementById("sub_newsletter").checked == true) params=params+"&newsletter=1";
 if (document.getElementById("sub_updates").checked == true) params=params+"&updates=1";
 xmlHttp.open("POST", url, true);

 //Send the proper header information along with the request
 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 xmlHttp.setRequestHeader("Content-length", params.length);
 xmlHttp.setRequestHeader("Connection", "close");
 
 xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
 	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
 		var split = xmlHttp.responseText.split("<%data%>");
 		
 		if (split[0]=="error") {
 		 document.getElementById("emailupdate_pleasewait").innerHTML = "";
 		 document.getElementById("emailupdate_error").innerHTML = "<span class=\"emailupdate_errormsg\">"+split[1]+"</span>";
 		} else if (split[0]=="success") {
 		 var frmthanks;
 		 document.getElementById("emailupdate_pleasewait").innerHTML = "";
 		 frmthanks="<div class=\"recent menu\">\n";
    frmthanks=frmthanks+"<div id=\"emailupdate_error\"></div>\n";
	   frmthanks=frmthanks+"<p>"+split[1]+"</p>\n";
 		 
 		 document.getElementById("emailupdate_form").innerHTML = frmthanks;
 		}
 	}
 }
 xmlHttp.send(params);
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){
	// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}