
document.write("<script src='coremetrics/v40/eluminate.js' type='text/javascript'></script>");
document.write("<script src='coremetrics/v40/cm_datatagutils.js' type='text/javascript'></script>");

function showEmailElements(showElement) 
{
	if (document.getElementById) 
	{		
		this.emailShowFields = document.getElementById('emailShowFields');
		this.EmailConfirmation = document.getElementById('EmailConfirmation');
		this.EmailDetails = document.getElementById('EmailDetails');
		this.EmailSample = document.getElementById('EmailSample');
		this.EmailPrivacy = document.getElementById('EmailPrivacy');
		//this.EmailSubmit = document.getElementById('EmailSubmit');
		
		if (showElement != 'EmailConfirmation') 
		{
			this.emailShowFields.style.display = 'none';
			this.EmailConfirmation.style.display = 'none';
			this.EmailDetails.style.display = 'none';
			this.EmailSample.style.display = 'none';
			this.EmailPrivacy.style.display = 'none';
		}
		
		if (showElement == 'EmailPrivacyPrev' )
		{
			var emailConfirm = document.getElementById("EmailconfirmedFlag").value;
			if ( emailConfirm == 'true' )
				showElement = 'EmailConfirmation'
			else
				showElement = 'emailShowFields'
		}
		
		if (showElement == 'emailShowFields') 
		{
			this.emailShowFields.style.display = 'block';
			setTimeout("document.getElementById('emailShowFields').focus()",200); 
			throwConversionEventTag("1", "1");
		} 
		else if (showElement == 'EmailConfirmation') 
		{
			if( !handleEmailFormSubmit() )
			{
				this.emailShowFields.focus();	
				setTimeout("document.getElementById('emailShowFields').focus()",100);
			}
		}
		else if (showElement == 'EmailDetails') 
		{
			this.EmailDetails.style.display = 'block';
		} 
		else if (showElement == 'EmailSample') 
		{
			this.EmailSample.style.display = 'block';
		} 
		else if (showElement == 'EmailPrivacy') 
		{
			this.EmailPrivacy.style.display = 'block';
		}   

	}
}

function showEmailConfirmation() 
{		
	this.emailShowFields = document.getElementById('emailShowFields');
	this.EmailConfirmation = document.getElementById('EmailConfirmation'); 
	//this.EmailSubmit = document.getElementById('EmailSubmit');
	this.EmailDetails = document.getElementById('EmailDetails');
	this.EmailSample = document.getElementById('EmailSample');
	this.EmailPrivacy = document.getElementById('EmailPrivacy');
		
	if(this.emailShowFields!=null)
		this.emailShowFields.style.display = 'none';

	if(this.EmailConfirmation!=null)
	this.EmailConfirmation.style.display = 'block';
	
	if(this.EmailDetails!=null)
	this.EmailDetails.style.display = 'none';
	
	if(this.EmailSample!=null)
	this.EmailSample.style.display = 'none';
	
	if(this.EmailPrivacy!=null)
	{
		this.EmailPrivacy.style.display = 'none';
		throwRegistrationTag();
	}

	if(document.confirmform!=null&&document.confirmform.EmailconfirmedFlag!=null)
	{
		document.confirmform.EmailconfirmedFlag.value = 'true';
		throwConversionEventTag("2", "10");
	}
}

function processGetPost() {
	var myajax = hdiAjax.ajaxObject;
	var myfiletype = hdiAjax.filetype;
	
	if (myajax.readyState == 4) 
	{
		if (myajax.status == 200)
		{
			showEmailConfirmation();
		}
		else
		{	
			alert('Email-Signup request failed.\nCode:ESF1');
		}
	}
}


function handleEmailFormSubmit() 
{
	try 
	{
		if (!handleEmailValidation()) {
			alert('There was a problem validating the information on this page.');
			return false;
		}		
		if (!handleEmailFormSignup()) {
			alert('There was a problem while processing email signup.');
			return false;
		}
		
	} 
	catch(e) {
		alert('There was a problem while processing the information on this page.');
		return false;
	}
	return true
}


function handleEmailValidation() {
	try {
		if (checkEmailFields() == true)
			return true;
		else
			return false;
	}
	catch(e) {
		return false;
	}
}


function handleEmailFormSignup() {
	try {
		var postUrl = getFTREmailSignupPostUrl();
		var postParameters = getFTRSignupPostParameters();
		hdiAjax.postAjaxRequest(postUrl, postParameters, processGetPost, 'txt');
		return true;
	}
	catch(e) {
		return false;
	}
}


function getFTRSignupPostParameters() {
	try {
		var emailValue = document.getElementById("FTREmailAddressText").value;
		var firstNameValue = document.getElementById("FTRFirstNameText").value;
		var lastNameValue = document.getElementById("FTRLastNameText").value;
		var sourceValue = document.getElementById("FTREmailSignupSource").value;
		var ipAddressValue = document.getElementById("FTRLocalIPAddress").value;
		var divCodeValue = document.getElementById("FTREmailDivisionCode").value;
		var dateTimeValue = createDateTimeStamp();
		var postStr = "EMAIL_ADDRESS=" + encodeURI(emailValue) + "&" +
						"FIRST_NAME=" + encodeURI(firstNameValue) + "&" +
						"LAST_NAME=" + encodeURI(lastNameValue) + "&" +
						"SOURCE=" + encodeURI(sourceValue) + "&" +
						"IP_ADDRESS=" + encodeURI(ipAddressValue) + "&" +
						"DIV_CODE=" + encodeURI(divCodeValue) + "&" +
						"DATE_TIME=" + encodeURI(dateTimeValue);
		return postStr;
	}
	catch(e) {
		return 'Error building email signup post parameters.';
	}
}

function throwRegistrationTag() {
	try
	{
		var emailValue = document.getElementById("FTREmailAddressText").value;
		var sourceValue = ""; //document.getElementById("FTREmailSignupSource").value;	
		cmCreateRegistrationTag(emailValue, emailValue, '','', '', 'Email Signup', 'Y', '', '', '', '', sourceValue, '')

	}
	catch(e) 
	{
		//alert('An error occurred while throwing the coremetrics registration tag.');
	}
}

function throwConversionEventTag(pAction, pPoints) 
{	
	var paramEventID	= 'Opt In';
	var paramEventCat	= 'Email Signup';
	try
	{				
		cmCreateConversionEventTag(paramEventID, pAction, paramEventCat , pPoints);
	}
	catch(e)
	{
		alert('An error occurred while throwing the coremetrics ConversionEvent tag.');
		alert(e.message);
	}
}

function checkEmailFields() {

	var elmEmailAddressText = document.getElementById("FTREmailAddressText");
	var elmConfirmEmailAddressText = document.getElementById("FTRConfirmEmailAddressText");
	var elmFirstName = document.getElementById("FTRFirstNameText");
	var elmLastName = document.getElementById("FTRLastNameText");

	if (elmEmailAddressText.value == "") {
		alert("Please enter your email address");
		elmEmailAddressText.focus();
		return false;
	}
	else if (elmConfirmEmailAddressText.value == "") {
		alert("Please confirm your email address");
		elmConfirmEmailAddressText.focus();
		return false;
	}
	else if (elmFirstName.value == "") {
		alert("Please enter your first name");
		elmFirstName.focus();
		return false;
	}
	else if (elmLastName.value == "") {
		alert("Please enter your last name");
		elmLastName.focus();
		return false;
	}
	else if (elmEmailAddressText.value.indexOf('@', 0) == -1 || 
		elmEmailAddressText.value.indexOf('.', 0) == -1) {
		alert("Please enter a valid email address.");
		elmEmailAddressText.focus();
		return false;
	}
	else if (elmEmailAddressText.value != 
		elmConfirmEmailAddressText.value) {
		alert("Your email confirmation does not match your email. Please verify your email.");
		elmConfirmEmailAddressText.focus();
		return false;
	}
	// Everything is ok so return true.
	return true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_initTimelines() { //v4.0
    //MM_initTimelines() Copyright 1997 Macromedia, Inc. All rights reserved.
    var ns = navigator.appName == "Netscape";
    var ns4 = (ns && parseInt(navigator.appVersion) == 4);
    var ns5 = (ns && parseInt(navigator.appVersion) > 4);
    var macIE5 = (navigator.platform ? (navigator.platform == "MacPPC") : false) && (navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4);
    document.MM_Time = new Array(1);
    document.MM_Time[0] = new Array(0);
    document.MM_Time["TimelineEMAILTOP"] = document.MM_Time[0];
    document.MM_Time[0].MM_Name = "TimelineEMAILTOP";
    document.MM_Time[0].fps = 24;
    document.MM_Time[0].lastFrame = 0;
    for (i=0; i<document.MM_Time.length; i++) {
        document.MM_Time[i].ID = null;
        document.MM_Time[i].curFrame = 0;
        document.MM_Time[i].delay = 1000/document.MM_Time[i].fps;
    }
}