var xmlHttp;
function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
		xmlHttp = new XMLHttpRequest;
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function addToList() {

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url = '/ajaxDo.php';

	var postVals = 'sid=' + Math.random();
	postVals = postVals + '&action=addToList';
	postVals = postVals + '&name=' + escape(document.getElementById('listName').value);
	postVals = postVals + '&email=' + escape(document.getElementById('listEmail').value);
	xmlHttp.onreadystatechange = stateChangedAddToList;
	xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length', postVals.length);
	xmlHttp.setRequestHeader('Connection', 'close');
	xmlHttp.send(postVals);
} 

function stateChangedAddToList() {
	if (xmlHttp.readyState == 4) {


		var myKey = /Error:/;
		var myStringVar = xmlHttp.responseText;
		var myMatch = myStringVar.search(myKey);
		if(myMatch == -1) {
			document.getElementById('listName').value = '';
			document.getElementById('listEmail').value = '';
		}
		alert(xmlHttp.responseText);
	}
}