var xmlHttp = createXmlHttpRequestObject();
var HOST_DOMAIN = 'http://www.dub-mafia.com';
function createXmlHttpRequestObject()	{
	var xmlHttp;
	
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)	{
			try {
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {}
		}
	}
	
	if (!xmlHttp)	{
		alert("Error creating XMLHttpRequest object.");
	} else {
		return xmlHttp;
	}
}

function process_newsletter()	{
	if (xmlHttp)	{
		try {
			var email = document.getElementById("txtEmail").value;
			xmlHttp.open("GET", HOST_DOMAIN + "/newsletter_signup.php?email=" + email, true);
			xmlHttp.onreadystatechange = nl_handleRequestStateChange;
			xmlHttp.send(null);
		} catch (e) {
			alert("Can't connect to server:\n" + e.toString());
		}
	}
}

function nl_handleRequestStateChange()	{
	if (xmlHttp.readyState == 4)	{
		if (xmlHttp.status == 200)	{
			try {
				nl_handleServerResponse();
			} catch (e) {
				alert("Error reading the response:\n" + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function nl_handleServerResponse()	{
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parseerror")	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	
	if (rootNodeName != "response" || !xmlRoot.firstChild)	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	
	responseText = xmlRoot.firstChild.data;
	myDiv = document.getElementById("newsletter");
	myDiv.innerHTML = responseText;
}

function try_again()	{
	formShow = '<span style="float:left;padding:4px 4px 0 0; color: white;">If you would like to be kept up to date with news and special offers enter your email:</span>' +
				'<div style="float:left; padding:0px 3px 0 0;"><input class="input" id="txtEmail" name="txtEmail" size="25" maxlength="30" value="" /></div>' +
				'<div style="float:left; padding:0px 3px 0 0;"><input type="submit" value="Sign up" title="Sign up to our newsletter" alt="Sign up to our newsletter" name="submit" onclick="process_newsletter();" /></div>';
	
	myDiv = document.getElementById("newsletter");
	myDiv.innerHTML = formShow;
}