/*
$Id: frameContext.js,v 1.1 2006/05/02 04:41:45 cvs Exp $

Description: If the loaded page is not in the frameset, load the index2 page, which contains the 
frameset and pass the filepath to it so that it can load the current page in the frameset.

Usage: This function should be called when the onload event is triggered in the body tag.

Copyright (c) Communicat
*/
function checkContext()
{
	var searchPattern = /((cfm|html)\/.*)/i;
	var searchPatternCFID = /cfid=[\d]+/i;
	var searchPatternCFTOKEN = /cftoken=[\d]+/i;
	var searchPatternMultipleAmpersand = /[&]+/;
	var searchPatternEndAmpersand = /[&]+/;
	var searchPatternEndQuestionMark = /\?$/;

	if (window == top)
		if (searchPattern.test(location.href))
		{
			var newLocation = RegExp.$1;

			// Remove the Coldfusion cfid and cftokens.			
			newLocation = newLocation.replace(searchPatternCFID, "");
			newLocation = newLocation.replace(searchPatternCFTOKEN, "");
			
			// Replace multiple ampersands with a single one.
			newLocation = newLocation.replace(searchPatternMultipleAmpersand, "&");
			
			// Remove ampersand at the end of the line if exists.
			//newLocation = newLocation.replace(searchPatternEndAmpersand, "");

			// Remove question mark at the end of the line if exists.
			newLocation = newLocation.replace(searchPatternEndQuestionMark, "");

			location.href = 'index.cfm?newLocation=' + escape(newLocation);
		}
}