function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}

function submitEmail(subscriber){
	var atindex = (subscriber.email.value).indexOf("@");
	if(atindex == -1) {
		//document.getElementById('email').style.background = "#FFCCCC";
		//alert('Please enter a valid email address.');
		return false;
	} else {
		createXMLHttpRequest();	
		xmlHttp.open("POST", "signup.php", true);
		xmlHttp.onreadystatechange = handleSearchStateChange;
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
		xmlHttp.send("email=" + subscriber.email.value);
		return false;
	}
}


function handleSearchStateChange() {
	if(xmlHttp.readyState == 4) {
			
		if(xmlHttp.status == 200) {	
			alert("Thanks. You have been added to our mailing list.");
		} else if (xmlHttp.status == 204){
			alert("There was an error. Sorry. Please try again.");
		}
	}
}
