// 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 = getXmlCommunicationObj();
	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){

	$('vipEmailMessageWindow').innerHTML = "<font class='ErrorText'>ERROR</font><br><br>" + escapeHtmlOuput(errMsg);
	displayVipEmailWindow();
	setTimeout("fadeOutVipEmailWindow()", 1500);
}

function displayVipEmailSuccessMessage(){
	$('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(){
	$('vipEmailMessageWindow').visibility = 'visible';
	$('vipEmailMessageWindow').set('tween', {duration: '0'});
	$('vipEmailMessageWindow').fade(1);
}

function fadeOutVipEmailWindow(){
	$('vipEmailMessageWindow').set('tween', {duration: 'long'});
	$('vipEmailMessageWindow').fade(0);
}

