//This file exists so I only have to maintain code in one place.

function EnsurePageIsFramed()
{
	if (top.location == self.location)
	{
		//Store the current URL for index.html to load
		var strURL = self.location.href;
		SetCookie("ReferringURL", strURL, 0);

		//Note: Set window.location.href because it works in IE
		//and Netscape.  window.navigate() only worked in IE.
		top.location.href = "index.html";
	}
}

function LoadReferrerIfNecessary()
{
	var strReferringURL = GetCookie("ReferringURL");
	if (strReferringURL != null)
	{		
		DeleteCookie("ReferringURL");
		
		//Load the referring URL into the "main" frame.
		if (window.frames != null && window.frames.length > 0)
		{
			var MainFrameWindow = window.frames["main"];
			if (MainFrameWindow != null)
			{
				MainFrameWindow.location.href = strReferringURL;
			}
		}
	}
}

//Add a new cookie name/value pair.
function SetCookie(name, value, days)
{
	var expire = new Date ();
	if (days == 0)
	{
		document.cookie = name + "=" + escape(value);
	}
	else
	{
		expire.setTime (expire.getTime() + (24 * 60 * 60 * 1000) * days);
		document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString();
	}
}

//Get the value for a specific cookie name/value pair.
function GetCookie(name)
{
	var startIndex = document.cookie.indexOf(name);
	if (startIndex != -1)
	{
		var endIndex = document.cookie.indexOf(";", startIndex);
		if (endIndex == -1) endIndex = document.cookie.length;
		return unescape(document.cookie.substring(startIndex+name.length+1, endIndex));
	}
	else
	{
		return null;
	}
}

//Delete a cookie name/value pair.
function DeleteCookie(name)
{
	var expire = new Date ();
	expire.setTime (expire.getTime() - (24 * 60 * 60 * 1000));
	document.cookie = name + "=; expires=" + expire.toGMTString();
}