// runs immediately (in HEAD) before each content page loads

if(UA.dom1) Initialise();			// don't bother initialising script if browser doesn't have DOM level 1 support

function Initialise() {
	if(!Dbg.IsExtended()) CheckFrameset();						// load in frameset if accessed directly

	// if accessed site via "/" and support DOM1, redirect to 'index.asp' (otherwise leave with plain content)
	if(!Dbg.IsExtended() && PageName()=="") location.replace("index.asp");
	
	document.write("<style>.div"+"Page{display"+":none;}</style>"); 	// if multi "page" content, hide pages initially
}

// redirect to put content in frameset if accessed directly (unless ext debug or 'noFrame' param)
function CheckFrameset() {
	if(!Dbg.IsExtended() && (PageParam("noFrame")!="true")) {
		// if top page name isn't "index.asp" or blank, load content in frameset by passing as 'page' param to portal page
		if(!top.location || ((PageName(top)!="index.asp") && (PageName(top)!="")) )
			// redirect to frameset portal page, passing encoded relative content URL (+ extra param "redir=true")
			top.location = PortalURL()+ "?page="+ PageName() + encodeURIComponent(location.search +(location.search?"&":"?")+ "redir=true");
	}
}

function PortalURL() {
	var sPath = location.pathname;
	return ((sPath.indexOf("/") != -1)? sPath.substr(0, sPath.lastIndexOf("/")) : sPath) + "/index.asp";
}
// returns page name for specified window (defaults to current), without query string or path
function PageName(win) {
	var sPath = (win || window).location.pathname;
	return sPath.substr( sPath.lastIndexOf("/")+1 );
}

// returns specified page parameter or null if undefined
function PageParam(sName) { 
	var aMatch = (new RegExp("[^\\w]"+sName+"=(\\w*)")).exec(location.search);
	return aMatch? aMatch[1] : null;
}
