
function EmailRegCheck()
{
	// Check Name
	if(document.EmailReg.Name.value.length < 3 || document.EmailReg.Name.value == "Name")
	{
		alert('That name appears to be too short. Please enter your full name.');
		document.EmailReg.Name.focus();
		return false;
	}
	
	else if (	document.EmailReg.Email.value.indexOf("@",0) == -1 || 
				document.EmailReg.Email.value.indexOf(".",0) == -1 || 
				document.EmailReg.Email.value.indexOf(" ",0) != -1)
	{
		alert("That email address appears to be invalid.");
		document.EmailReg.Email.focus();
		return false;
	}
	
	else
	{
		EmailRegAJ();
	}
	
return false;
}


function EmailRegAJ()
{
try{AJ = new XMLHttpRequest();}
catch (MSIE){try{AJ = new ActiveXObject("Msxml2.XMLHTTP");}
catch (MSIE2){try{AJ = new ActiveXObject("Microsoft.XMLHTTP");}
catch (failed){AJ = false;}}}
	
	EmailRegURL='/_content/ajax/AJAX-EmailReg.php?Source='+escape(document.EmailReg.Source.value)
	+'&Name='+escape(document.EmailReg.Name.value)
	+'&Email='+escape(document.EmailReg.Email.value);
	AJ.open("GET", EmailRegURL, true);
	AJ.onreadystatechange = EmailRegAJParse;
	AJ.send(null);
}


function EmailRegAJParse()
{
	if (AJ.readyState == 4 && AJ.status == 200)
	{
		var EmailRegAJResponse=AJ.responseText.split("|");
		CODE=EmailRegAJResponse[0];
		ERROR=EmailRegAJResponse[1];

		if(CODE != 7){if(!ERROR){ERROR="An unknown error occurred.";}alert("Error: "+ERROR);document.EmailReg.Name.focus();return false;}
		else
		{
			document.getElementById("EmailRegElement").innerHTML="Subscription Successful. Thank You.";
		}
	}
}
