// ***************************************************************************************
// Copyright (C) Pentagate. All rights reserved.
// ***************************************************************************************
// j5config.js - Site configuration JS
//
//
//	Use this config file if you intend using the frame control environment used on the Pentagate site
// ***************************************************************************************
// Initialization
// ***************************************************************************************


function $ConfigSystem()
{
	// You can set TFunctionClass/TNavigatorClass properties here

	/*
		The site id allows you to run separate sub sites within a single site
			Specifically it serves as part of the key to keep cookies unique when
			saving & accessing cookies for this site and where multiple domain 
			aliases exist for the same site.
			If the menu configured in the menu config JS is configured differently
			dependent on the domain, then the site id must also be different for 
			each domain. eg.
				if (parent.document.domain.slice(8) == "mytest.co.za")
				{
					NavUI.siteId = ...
					... configuration for this domain
				}
				else ... configuration for another domain etc.
	*/


	NavUI.siteId="P070205";

	NavUI.rpcCmd="/j5rpcServer.php";	// JPenta server request url for this site or null if not used;
	NavUI.host="phpBB3";				// Name of the server host that controls logins
	NavUI.configFile="/j5config.js";	// This file
	

	NavUI.menuName="MainTree";				// The name of the controlling menu component
	NavUI.contentFrameName="contentFrame";	//	The frame that holds the site content pages
	NavUI.homeFramesURL="indexframes.html"; // Defines the default frames page used when frames are active
	NavUI.homeURL="index.html";				// The default site page (home page)

	// Divs where frameless/scriptless text is held that must
	// be hidden in when frames & scripts are active
	NavUI.noFramesStyle=".sNoFramesOrScripts";

	// A-sorted list of valid url query parameter names used by the system
	// to locate a url's node - Only way to do this.
	// If this line is removed, locating of url's will ignore the query 
	// parameters in a url when doing a locate
	NavUI.qryParams = new Array("f", "folder", "i", "mode", "perform", "action");

	// Query keys that, if present, clear other query keys
	NavUI.clearingKeys = {confirm_key:new Array("i", "mode")};

	// Disable internal compression
	NavUI.compression=false; // Enable this if your server does not compress JS.
	
	// Events
	NavUI.onDocumentChanged="documentChanged()";
//	NavUI.onDocumentLoaded="documentLoaded()"; Called after document body has completed loading
	NavUI.onLoginChanged = "loginChanged()";
	NavUI.onTitleChanged = "setTitle()";
	NavUI.onPageTitleChanged = "setPageTitle()";
	NavUI.onBannerChanged = "setBanner()";
	NavUI.onSidebarChanged="sidebarChanged()";
	NavUI.onRightPaneChanged="rightPaneChanged()";
};





// *****************************************************************************************
// The following section does not change and handles frame redirects and Safari bookmarking.
// *****************************************************************************************

function initializeDocument()
{
	var win = arguments.length>0?arguments[0]:window;
	if (window.top.NavUI)
	{
		if (win == window.top)
			$ConfigSystem();
		window.top.NavUI.bind(win);
		if (!(arguments[6] & 2))
		{
			NavUI.initializeDocument(win, arguments.length>1?arguments[1]:false,
					arguments.length>2?arguments[2]:false, arguments.length>3?arguments[3]:null,
					arguments.length>4?arguments[4]:null, arguments.length>5?arguments[5]:null,
					arguments.length>6?arguments[6]:0);
		}
		win = null;
		return;
	}
	
	this.getCookie = function(name)
	{
		var pos=0, end=0;
		
		if (!document.cookie)
			return null;
		name = escape(NavUI.siteId+String.fromCharCode(30)+name);
		pos = document.cookie.indexOf("; "+name+"=");
	
		if (pos == -1)
		{
			if (document.cookie.substr(0,name.length+1) == name+"=")
				pos = name.length+1;
			else
				return null;
		}
		else
		{
			pos += name.length+3;
		}
		end = document.cookie.indexOf(";", pos);
		if (end == -1)
			end = document.cookie.length;
		data = unescape(document.cookie.substring(pos, end));
		if (data.length == 1 && data.charCodeAt(0) == 29)
			return null;
		return data;
	};

	this.initializeBookmark = function(href)
	{
		if (!this.initializeBookmark.timer)
		{
			var dateVar = new Date();
			dateVar.setTime(dateVar.getTime()-86400000)
	
			document.cookie = escape(NavUI.siteId+String.fromCharCode(30)+"bookmarker") + "=" + escape(String.fromCharCode(29)) + "; path=/; expires=" + dateVar.toGMTString();

			if (href != document.location.href)
				return false;
		}
			
		if (!this.initializeBookmark.resized && top.resizeTo)
		{
			this.initializeBookmark.width = outerWidth;
			this.initializeBookmark.height = outerHeight;
			this.initializeBookmark.left = screenX;
			this.initializeBookmark.top = screenY;
			resizeTo(520,340);
			moveTo((screen.width-outerWidth)/2, (screen.height-outerHeight)/2);
			this.initializeBookmark.resized = true;
		};
		
		if (!document.body)
		{
			// We have to tight loop this
			if (!this.initializeBookmark.timer)
			{
				var self = this;
				this.initializeBookmark.timer = setInterval(function(){self.initializeBookmark()},10);
			}
			return true;
		}
		
		if (this.initializeBookmark.timer)
			clearInterval(this.initializeBookmark.timer);
	
		document.body.onLoad = "";
		document.documentElement.innerHTML = "<div style='font-size:11px;font-family:Verdana,Tahoma,Arial,Helvetica,Sans-serif;margin:10px'>You can now safely add this page as a bookmark using your browser's <b>Bookmarks</b> menu above.<br/><br/>We apologize for this inconvenience but your browser has no automated facility for bookmarking specific pages in a frames based site.<br/>Internet Explorer, Firefox and Opera do have a facility.<br/><b>Safari</b> and <b>Konqueror</b> unfortunately <b>require this procedure</b>.<br/><br/>Once you have completed adding the bookmark you can return to your previous page by closing this page. Ensure that you do <span style='color:#dd5500'>close this page before proceeding</span> otherwise new windows you open in your browser will be this size until you resize them. Should you forget to close this page you can easily reset your browser's size by opening a new browser window, setting the size you prefer and closing it again.<br/><br/><span style='color:#006600'>This is a completely safe procedure and will not harm your system in any way.</span></div>";
		var self = this;
		top.addEventListener("unload",function(){var f=self.initializeBookmark;resizeTo(f.width,f.height);moveTo(f.left,f.top);},false);
		return true;
	
	};

	if (window.frames && (arguments.length<7 || !(arguments[6] & 2)))
	{
		
		var href = null;
		win.NavUI = new Object;
		$ConfigSystem();

		if (!window.sidebar && !window.external &&!window.opera && (href=this.getCookie("bookmarker")))
		{
			// This is a bit of a hack to allow users to bookmark a specific frame page where no JS bookmarking
			// facility exists in the browser
			if (this.initializeBookmark(href))
			{
				win = null;
				return;
			}
		}

		// Save this page as the redirect uid
		document.cookie = escape(NavUI.siteId+String.fromCharCode(30)+"ruid") + "=" + escape(document.location.href) + "; path=/";
		// Call the frames page with a redirect to this page
		location.replace(location.protocol+"//"+location.hostname+"/"+NavUI.homeFramesURL);
		win = null;
		return;
	}

};


