//
// Change the below variable to control when the cookie expires
//

var g_CookieLife = 90; // Days - Cookie will expire after this many days

// This can be probably moved to WebUtils.asp but it
// is typically required on the client side
function FZGetValueFromURL(a_URL, a_Field)
{
	if("" == a_URL)
		return "";
			
	var TempArray			= a_URL.split("?");
	if(2 != TempArray.length)
		return "";
			
	var NameValueArray	= TempArray[1].split("&");
		
	for(var i = 0; i < NameValueArray.length; i++)
	{
		var NameValuePair = NameValueArray[i].split("=");
		if(NameValuePair[0] == a_Field)
			return NameValuePair[1];
	}
	return "";
}

function FZSetCookie(a_Name, a_Value, a_Expiry)
{
	document.cookie = a_Name + "=" + escape(a_Value)
			+ " ;path=/"
			+ ((a_Expiry == null) ? "" : (" ;expires=" + a_Expiry.toGMTString()));
}

var g_URL = top.document.location.href;

// The page should be called as http://www.frontzone.com/?lead=WhatEver
// or http://www.frontzone.com/?source=WhatEver

var LeadSource = FZGetValueFromURL(g_URL, "lead");
if("" == LeadSource)
{
	LeadSource = FZGetValueFromURL(g_URL, "source");
}

if("" == LeadSource)
{
// ecruos is the reverse of source. We use this to make the url less apparent to the user
	LeadSource = FZGetValueFromURL(g_URL, "ecruos");
}

if("" != LeadSource)
{
	var ExpiryDate = new Date();
	ExpiryDate.setTime(ExpiryDate.getTime() + (g_CookieLife*24*60*60*1000));
	FZSetCookie("lead_source", LeadSource, ExpiryDate);
}
// document.write("Lead: " + LeadSource);
// document.write("<BR><BR>Cookie string: " + document.cookie);

