function Split(string, delimiter) {
var elements = new Array();
var numElements = 0;
var token;
var index = 0;
var nextIndex = -1;
index = string.indexOf(delimiter);
while (string != "") {
if (string.charAt(0) == delimiter) {
elements[numElements++] = "";
string = string.substring(1);
} else {
nextIndex = string.indexOf(delimiter);
if (nextIndex == -1) {
elements[numElements++] = string;
string = "";
} else {
elements[numElements++] = string.substring(0, nextIndex)
string = string.substring(nextIndex + 1)
}
}
}
return elements;
}
function GetCookie(key) {
var i;
var cookies = Split(document.cookie, ";");
for (i = 0; i < cookies.length; i++) {
if (cookies[i].substring(0, 1) == " ") cookies[i] = cookies[i].substring(1, cookies[i].length);
// Make the cookies case insensitive, like ASP
if (unescape(cookies[i].substring(0, key.length + 1).toUpperCase()) == key.toUpperCase() + "=") {
return unescape(cookies[i].substring(cookies[i].indexOf("=") + 1, cookies[i].length));
}
}
if (key == "BASEUSERSURL") {
return "/";
}
return null;
}
function SetCookie(key, value) {
SetCookieFull( key.toString().toUpperCase(), value, '', '/');
}
function ClearCookie(key) {
ClearCookieFull(key.toString().toUpperCase(), '/');
}
// this deletes the cookie when called
function ClearCookieFull(key, path, domain) 
{
document.cookie = key + "=0" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
// Sets the cookie with the given expiration date (in days).
// If the bOverRide flag is true, override the existing cookie (if the cookie already exists).
// If it is false, and the cookie already exists, don't ovverride the existing cookie.
// If the cookie doesn't exist in either case, set a new one.
function SetExpiresCookie(key, value, daysTillExpiration, bOverRide, domain)
{
//if don't override and the cookie exists - don't do anything
if(!bOverRide && GetCookie(key)) {
return;
} else {
//if the cookies doesn't exist - want to set regardless of bOverRide
SetCookieFull(key.toString().toUpperCase(), value, daysTillExpiration, '/', domain, false);
}
}
// only the first 2 parameters are required, the cookie key, the cookie
// value. Cookie time is in milliseconds, so the below daysTillExpiration will make the 
// number you pass in the setCookie function call the number of days the cookie
// lasts, if you want it to be hours or minutes, just get rid of 24 and 60.
// Generally you don't need to worry about domain, path or secure for most applications
// so unless you need that, leave those parameters blank in the function call.
function SetCookieFull(key, value, daysTillExpiration, path, domain, secure) 
{
if (daysTillExpiration && !isNaN(daysTillExpiration))
{
// Get the current date
var currentDate = new Date();
// Add the number of days
var expireTime = currentDate.getTime() + ( 1000 * 60 * 60 * 24 * daysTillExpiration);
var expireDate = new Date(expireTime);	
}
else
{
daysTillExpiration = false;
}
document.cookie = key + "=" + escape(value) +
((daysTillExpiration) ? ";expires=" + expireDate.toGMTString() : "") + 
((path) ? ";path=" + path : "") + 
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}
// Get and Set Cookie
// This function tests to see if the cookie is there, and if it is not, it sets it
// has an expiration date (in days)
function GetAndSetCookie(key, value, daysTillExpiration)
{
SetExpiresCookie(key, value, daysTillExpiration, false);
}
// A port of CEarCodeUtils::GetDomainForCookie
// Utility function to determine the domain for the cookie given a server
// context. If there are more than 3 portions between the periods in
// the server name, we just use the last 2 (ex. for 'www.blah.homestead.com'
// we set the cookie for domain='.homestead.com').
// Example: GetDomainForCookie(document.domain)
function GetDomainForCookie(domain) {
var domainTokens = domain.split('.');
var size = domainTokens.length;
if (size > 2) {
return "." + domainTokens[size-2] + "." + domainTokens[size-1];
}
return "";
}
// A function to add an ABTest Name-Value pair to the ABTestValues cookie.
// If there is already a value for a particular test name, it will knock out the old value and replace it with the new.
// Upon signup, we will record these ABTest values.
//
// The format for this cookie is "TESTNAME1;TESTVALUE1|TESTNAME2;TESTVALUE2|TESTNAME3;TESTVALUE3" etc.
function SetABTestValue(testName, testValue)
{
// Make sure we have a valid testName and testValue before we do anything.
if (!testName || testName.length == 0 || !testValue || testValue.length == 0)
{
return;
}
// Some constants
var ABTestCookieName = "ABTESTVALUES";
var betweenTestsDelimiter = "|";
var betweenNameAndValueDelimiter = ";";
// The array from which we will construct our new cookie.
var resultingABTestValuesArray = new Array();
var ABTestValuesString = GetCookie(ABTestCookieName);
if (ABTestValuesString && ABTestValuesString.length != 0)
{
var ABTestValuesArray = Split(ABTestValuesString, betweenTestsDelimiter);
// we'll just pull them off the old array one by one, adding them to the new array if the testName doesn't match the testName that we are adding.
while (ABTestValuesArray.length > 0)
{
var ABTestNameValuesString = ABTestValuesArray.shift();
var delimiterPosition = ABTestNameValuesString.search(betweenNameAndValueDelimiter);
if (delimiterPosition > 0 && ABTestNameValuesString.substr(0, delimiterPosition) != testName)
{
resultingABTestValuesArray.push(ABTestNameValuesString);
}
}
}
// Now push on the new test name and value.
resultingABTestValuesArray.push(testName + betweenNameAndValueDelimiter + testValue);
SetExpiresCookie(ABTestCookieName, resultingABTestValuesArray.join(betweenTestsDelimiter), 90, true);
}

var bShowInterceptor = true;
window.onunload = showInterceptor;
function initializeClicks()
{
if (document.all)
{
xAssignLinks(document.all);
}
else if (document.getElementsByTagName)
{
xAssignLinks(document.getElementsByTagName('a'));
xAssignLinks(document.getElementsByTagName('td'))
xAssignLinks(document.getElementsByTagName('div'));
}
if (document.forms)
{
xAssignSubmits(document.forms);
}
else if (document.getElementsByTagName)
{
xAssignSubmits(document.getElementsByTagName('form'));
}
}
function xAssignLinks(itemsToAssign)
{
if (!itemsToAssign)
return;
var undefined;
for (var i = 0; i < itemsToAssign.length; i++)
{
if ((itemsToAssign[i].onclick != null) || (itemsToAssign[i].href != undefined))
{
itemsToAssign[i].oldClick = (itemsToAssign[i].onclick) ? itemsToAssign[i].onclick: function() {};
itemsToAssign[i].onclick = function() { cancelInterceptor(); return this.oldClick(); };
}
}
}
function xAssignSubmits(itemsToAssign)
{
if (!itemsToAssign)
return;
for (var i = 0; i < itemsToAssign.length; i++)
{
itemsToAssign[i].oldOnSubmit = (itemsToAssign[i].onsubmit) ? itemsToAssign[i].onsubmit: function() {};
itemsToAssign[i].onsubmit = function() { cancelInterceptor(); return this.oldOnSubmit(); };
}
}
function cancelInterceptor()
{
bShowInterceptor = false;
if (this != this.parent)
{
this.parent.bShowInterceptor = false;
}
}
function enableInterceptor()
{
bShowInterceptor = true;
}
function showInterceptor()
{
}
