//==================================================================
function GetPageToken(pString)
{
var theBackslashIndex;
var theSlashIndex;
var theToken;

// This function will return the last token of a URL

	//theToken = pString;		// Can't just do the assignment, the "slice" method is needed.
	theToken = new String(pString);

	// Look for both kinds of separators just in case you're running locally on a PC.
	
	theSlashIndex = StringReverseSearch(theToken, '/');
	theBackslashIndex = StringReverseSearch(theToken, '\\\\');
	
	if (theSlashIndex < theBackslashIndex)
		theSlashIndex = theBackslashIndex;

	theToken = theToken.slice(-(theToken.length - theSlashIndex));

	return theToken;	
}

//==================================================================
function GetRedirectToken(pString)
{
var theIndex;
var theToken;

// This function will return the last token of a URL

	theToken = new String(pString);
	theIndex = StringReverseSearch(theToken, '=');
	
	if (theIndex > 0)
	{
		theToken = theToken.slice(-(theToken.length - theIndex));
	}
	else
	{
		theToken = '';
	}

	return theToken;	
}

//==================================================================
function StringReverseSearch(pString, pSearch)
{
var theIndex;
var theRegArray;
var theRegExp;

	theIndex = 0;

	theRegExp = new RegExp(pSearch, 'g');
	theRegArray = theRegExp.exec(pString);

	while (theRegArray != null)
	{
		theIndex = theRegExp.lastIndex;
		theRegArray = theRegExp.exec(pString);
	}
	return theIndex;
}

//==================================================================
function onloadCheckIfWeNeedARedirect()
{
var hasFrames = false;
var thePage;
var theMainPage;

var browserVersion	= parseInt(navigator.appVersion);
var isNetscape		= navigator.appName.indexOf("Netscape") != -1;
var isExplorer		= navigator.appName.indexOf("Microsoft") != -1;
var agent			= navigator.userAgent.toLowerCase();
var isWindows		= agent.indexOf("win") != -1;
var isMac			= agent.indexOf("mac") != -1;
var isUnix			= agent.indexOf("X11") != -1;

	hasFrames = (window.top.frames.length > 1);
	
	if (isMac)
	{
		if (! hasFrames)
		{
		//	alert("Welcome Mac user...\n\n"
		//		+ "The frames have not been setup.\n"
		//		+ "Please enter the site through the main page for full functionality.\n"
		//		+ "\n"
		//		+ "I'm having a few problems with the redirect\n"
		//		+ "code which I hope to have fixed soon.");
		}
		return;
	}

	theMainPage = GetPageToken(window.location);

	if (! hasFrames)
	{
		theMainPage = GetPageToken(window.location);

		//window.navigate('index3.htm');		// Not supported by Netscape.

		// Any redirect should be the last thing that you do.
		window.location = 'index3.htm?redirect=' + theMainPage;
	}
	else // We have frames...
	{
		thePage	= GetRedirectToken(window.top.location);
		
		// We don't need to redirect if the page is the same page.
		// This also helps fight the nasty recursion.

		if (thePage != ''
		 && thePage != theMainPage
		 && window.top.header.header_form.visited_field.value != "true")
		{
			window.parent.main.location = thePage;
		}

		window.top.header.header_form.visited_field.value = "true";
	}
}

//==================================================================
function WriteModifiedDate(pDateString)
{
var hasFrames = false;

	hasFrames = (window.top.frames.length > 1);
	
	if (hasFrames)
	{
		window.top.header.header_form.date_field.value = pDateString;
	}
}