/*Version: $Id: presentationadmin.js 1570 2006-01-09 18:36:23Z ray $*/

/*******************************************/
/* tab stuff                               */
/*******************************************/

var contentStore;

//tab object

function initTab(objName) {
	this.obj = objName;
	this.aNodes = [];
};


//Node definition

function tabNode(id, name, url, title) {
	this.id = id;
	this.name = name;
	this.url = url;
	this.title = title;
};

//Add node

initTab.prototype.add = function(id, name, url, title) {
	
	this.aNodes[this.aNodes.length] = new tabNode(id, name, url, title);
};

//Function to dump tabs as linked list

initTab.prototype.dumpTabs = function () {
	
	var outputStr = "";
	
	for (n = 0; n < this.aNodes.length; n++) {
		outputStr = outputStr + '<li id=\"tab' + this.aNodes[n].id + 'l\"><a href=\"#\" id=\"tab' + this.aNodes[n].id + 'r\" onclick=\"' + this.aNodes[n].url + '\">' + this.aNodes[n].title + '</a></li>\n'
	}
	
	return outputStr;
}

//Function to write tabs to div

initTab.prototype.doTabs = function(myDiv) {

	outputStr = '<ul id="mb1" style="margin:0px;padding:0px;top:0px;left:0px;vertical-align:top;">' + initialTab.dumpTabs() + '</ul>';
	
	myDiv.innerHTML = outputStr;

	return;
}

function changePage(doc_name, page_name, tabclass) {
	
	var myPageIndex = -1;
	
	var dataPages = doc_name.getElementsByClass(tabclass);
	
	for (i = 0; i < dataPages.length; i++) {
		dataPages[i].style.display="none";
		if (dataPages[i].id == page_name) myPageIndex = i;
	}
	
	if (doc_name.getElementById("tab" + myPageIndex + "l")) {
		doc_name.getElementsByTagName("body").item(0).id = "body_tab" + myPageIndex;
	}
	
	doc_name.getElementById(page_name).style.display = "block";
	
	return true;
	
}

/*---------------------------------*/
/*Code for arranging three columns of CSS text---
/*swiped from http://www.quirksmode.org/dom/3column.html */
/*---------------------------------*/

function arrangePage(doc_id) {

	return;
	var x=-1;
	
	if (doc_id.getElementById('documentWholePage')) return 0;

	doc_id.getElementById('documentHolder').style.height = 'auto';
	x = doc_id.getElementById('documentContent').offsetHeight;
	
	if (doc_id.getElementById('documentLeftMenu1')) {
	
		doc_id.getElementById('documentLeftMenu1').style.height = 'auto';
		var y = doc_id.getElementById('documentLeftMenu1').offsetHeight;
	
		if (doc_id.all) {
			if (x > y) doc_id.getElementById('documentLeftMenu1').style.height = x + "px";
		} else {
			if (x > y) doc_id.getElementById('documentLeftMenu1').style.height = (x - 22) + "px";
		}
	}
	
	return x;
}

/*---------------------------------*/
/*Code for making a form in a new pop up window
/*swiped from http://www.faqs.org/docs/htmltut/linking/linking_famsupp_73.html */
/*---------------------------------*/

function popupform(myform, windowname)
{
if (! window.focus)return true;
window.open('', windowname, 'top=20px, left=20px, width=600px, height=545px, scrollbars=no, resizable=yes');
myform.target=windowname;
return true;
}


/*---------------------------------*/
/*Code for adding the menu system---
/*list menu script by Brothercake (http://www.brothercake.com/)
/*you may use the code providing this message remains intact 
/*---------------------------------*/

//trigger initialiser
function menuInitTrigger(menuTrigger)
{
	//null menu object
	var menuMenu = null;

	//moz needs this         //mac/ie5 needs this
	if(menuTrigger.firstChild && menuTrigger.firstChild.nextSibling)
	{
		//get menu object
		menuMenu = menuTrigger.childNodes[2];
	}

	//bind menu mouse-opener
	menuTrigger.onmouseover = function()
	{
		this.menuShowMenu();
	}

	//bind menu mouse-closer
	menuTrigger.onmouseout = function(e)
	{
		this.menuHideMenu(e);
	}

	//menu opening function
	menuTrigger.menuShowMenu = function()
	{
		//rollover
		menuTrigger.firstChild.style.backgroundColor = '#3333ff';
		menuTrigger.firstChild.style.color = '#fffff0';

		//if trigger has menu
		if(menuMenu != null)
		{
			//tweak top position
			menuMenu.style.marginTop = (0-menuTrigger.offsetHeight)+'px';

			//show menu
			menuMenu.style.visibility = 'visible';

		}

	}

	//menu mouse-closing function
	menuTrigger.menuHideMenu = function(e)
	{
		if(!e) { e = window.event; }

		//if event came from outside current trigger branch
		if(!menuTrigger.contains(e.relatedTarget || e.toElement))
		{
			//rollout
			menuTrigger.firstChild.style.backgroundColor = '#fffff0';
			menuTrigger.firstChild.style.color = '#000066';

			//if trigger has menu
			if(menuMenu != null)
			{
				//hide menu
				menuMenu.style.visibility = 'hidden';
			}
		}
	}

	//prototyped contains method
	//obviously not necessary for win/ie5, and errs in mac/ie5 anyway
	//not actually necessary for O7 either .. but I'm superstitious
	if(!(menu.macie||menu.winie))
	{
		//contains method by jkd (http://www.jasonkarldavis.com/)
		menuTrigger.contains = function(node)
		{
			if (node == null) { return false; }
			if (node == this) { return true; }
			else { return this.contains(node.parentNode); }
		}
	}


}

//navbar object
function menuNavbar(ulTree)
{
	//object
	menu.nav = this;

	//ul tree
	menu.tree = ulTree;

	//invalidate markup so it works in win/ie
	if(menu.winie)
	{
		//get inner HTML
		menu.html = menu.tree.innerHTML;

		//replace <li> with <div> to prevent excess margins
		//sorry - I know this invalidates the DOM
		//but invalid markup is the only language it understands ...
		menu.html = menu.html.replace(/<([\/]?)li/ig,'<$1div');

		//write back to tree
		menu.tree.innerHTML = menu.html;
	}

	//get trigger elements
 	(menu.xdom) ? menu.tagNames = 'li' : (menu.winie) ? menu.tagNames = 'DIV' : menu.tagNames = 'LI';
 	menu.listItems = menu.tree.getElementsByTagName(menu.tagNames);
 	menu.listLen = menu.listItems.length;

 	//initialise
 	for(i=0; i<menu.listLen; i++)
 	{
 		menuInitTrigger(menu.listItems[i]);
 	}
}

//menu tree
var tree = null;

//menu object
var menu = new Object;

//identify support level
menu.ua = navigator.userAgent.toLowerCase();
menu.op6 = (menu.ua.indexOf("opera 6")!=-1||menu.ua.indexOf("opera/6")!=-1)?true:false;
menu.dom = (typeof document.getElementById!="undefined"&&typeof document.createElement!="undefined"&&!menu.op6)?true:false;

//identify win and mac versions of ie
menu.winie = (menu.dom&&typeof document.all!="undefined"&&typeof window.opera=="undefined")?true:false;
menu.macie = (menu.winie&&menu.ua.indexOf("mac")!=-1)?true:false;if(menu.macie){menu.winie=false;}

//identify which DOM were in
//this test may not be 100% reliable ...
menu.xdom = (menu.dom&&typeof document.write=='undefined')?true:false;

//initiate
function makeMenu()
{
	//if browser is supported
	if(menu.dom)
	{
		//tree object
		tree = document.getElementById('menu');
		if(tree != null)
		{
			//create navbar object
			menu.nav = new menuNavbar(tree)
		}
	}
}

/*---------------------------------*/
/*Automatic execution*/
/*---------------------------------*/

window.onload = function() {
	makeMenu();
	arrangePage(document);
}

window.onresize = function() {
	arrangePage(document);
}

