// JavaScript Document

var globalErrorMessageVar = false;

function submitVipEmail(emailAddress){

	if(emailAddress.search(/^\w+([-.]\w+)*\@\w+([-.]\w+)*\.\w+$/) == -1){
		
		showVipEmailErrorMessage("The email address that you entered is invalid.");
		
		return false;
	}
	
	
	dateObj = new Date();
	var NoCache = dateObj.getTime();
	var postURL = "api_dot.php?api_version=1.1&command=submit_email_for_newsletter&emailAddress=" + escape(emailAddress);

	//Load the XML doc from the server... this will save information in the background
	var xmlDoc = getXmlHttpObj();
	xmlDoc.open('GET', postURL, true);

	// Micosoft does not like you setting the Ready State before calling "open".
	xmlDoc.onreadystatechange = function() 
	{
		if(xmlDoc.readyState != 4 )
			return;
				
		if(xmlDoc.status == "200")
		{
			displayVipEmailSuccessMessage();
		}
		else
		{
			showVipEmailErrorMessage("There was an error with your request. Please try submitting your email again.");
			globalErrorMessageVar = true;
		}
	}
	xmlDoc.send(null);
	
	if(!globalErrorMessageVar)
		displayVipEmailSuccessMessage();
	
	return false;
}

function showVipEmailErrorMessage(errMsg){

	document.getElementById('vipEmailMessageWindow').innerHTML = "<font class='ErrorText'>ERROR</font><br><br>" + escapeHtmlOuput(errMsg);
	displayVipEmailWindow();
	setTimeout("fadeOutVipEmailWindow()", 1500);
}

function displayVipEmailSuccessMessage(){
	document.getElementById('vipEmailMessageWindow').innerHTML = "<div align='center'><font style='color:#009900; font-size:14px; font-weight:bold;'>Thank You!</font><br><br>We got your request.</div>";
	displayVipEmailWindow();
	setTimeout("fadeOutVipEmailWindow()", 1500);
}

function displayVipEmailWindow(){
	document.getElementById('vipEmailMessageWindow').style.visibility = 'visible';
}

function fadeOutVipEmailWindow(){
	document.getElementById('vipEmailMessageWindow').style.visibility = 'hidden';
}

function escapeHtmlOuput(str)
{
        str = str.replace(/\&/g,"&amp;");
        str = str.replace(/\</g,"&lt;");
        str = str.replace(/\>/g,"&gt;");
        str = str.replace(/\"/g,"&quot;");
        return str;
}


