
var coll = "";
var isNav4, isNav6, isIE, isIE4, isIE5, isIE55, isIE6, isMac;
if (parseInt(navigator.appVersion) >= 4)
{
	
	if (navigator.platform.indexOf("Mac")!=-1)
		isMac = true;
	
	if (navigator.appName == "Netscape")
	{
		if (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"))
			isNav6 = true;
		else
			isNav4 = true;
	}
	else
	{
		isIE = true;
		coll = "all.";
                if (navigator.appVersion.indexOf("MSIE 6")!=-1) 
                	isIE6 = true;
                else if (navigator.appVersion.indexOf("MSIE 5.5")!=-1) 
                	isIE55 = true;
		else if (navigator.appVersion.indexOf("MSIE 5")!=-1)
			isIE5 = true;
		else
			isIE4 = true;
	}
}


var canResize = false;
function handleResize()
{
	if(canResize) location.reload();
	return false;
}
if (isNav4)
{
	window.captureEvents(Event.RESIZE);
	window.onresize = handleResize;
}


function getObject(obj)
{
	var theObj;
	if (typeof obj == "string")
	{
		if (isNav6) 
			return document.getElementById(obj);
			
		theObj = eval("document." + coll + obj);
	}
	else
		theObj = obj;
	return theObj;
}


function getFormObject(divO, formO)
{
	if (isNav6) 
		return document.getElementById(formO);
	else if (isNav4)
		return eval("document." + divO + ".document." + formO);
	else
		return eval("document." + coll + formO);

}


function shiftTo(obj, x, y)
{
	if (isNav4)
		obj.moveTo(x,y);
	else if(isNav6)
	{
		obj.style.left = x;
		obj.style.top = y;
	}
	else
	{
		obj.style.pixelLeft = x;
		obj.style.pixelTop = y;
	}
}

function shiftBy(obj, dX, dY) 
{
	if (isNav4)
		obj.moveBy(dX, dY);
	else if (isNav6)
	{
		
	}
	else 
	{
		obj.pixelLeft += dX;
		obj.pixelTop += dY;
	}
}


function getWindowHeight()
{
	if(isNav4 || isNav6)
		return window.innerHeight;
	else
		return document.body.clientHeight;
}


function getWindowWidth()
{
	if(isNav4 || isNav6)
		return window.innerWidth;
	else
		return document.body.clientWidth;
}


function getObjWidth(obj)
{
	if(isNav4)
		return obj.clip.width;
	else if(isNav6)
		return obj.offsetWidth;
	else
		return obj.clientWidth;
}


function getObjHeight(obj)
{
	if(isNav4)
		return obj.clip.height;
	else if(isNav6)
		return obj.offsetHeight;
	else
		return obj.clientHeight;
}


function getObjLeft(obj)
{
	if(isNav4)
		return obj.left;
	else if(isNav6)
		return obj.offsetLeft;
	else
		return obj.style.pixelLeft;
}


function getObjTop(obj)
{
	if(isNav4)
		return obj.top;
	else if(isNav6)
		return obj.offsetTop;
	else
		return obj.style.pixelTop;
}


function getScrollY()
{
	if(isNav4 || isNav6)
		return window.pageYOffset;
	else
		return document.body.scrollTop;
}


function setZIndex(obj, z)
{
	if(isNav4)
		obj.zIndex = z;
	else
		obj.style.zIndex = z;
}


function show(obj)
{
	if(isNav4)
		obj.visibility = "visible";
	else
		obj.style.visibility = "visible";
}


function hide(obj)
{
	if(isNav4)
		obj.visibility = "hidden";
	else
		obj.style.visibility = "hidden";
}



// **************** MENU SPECIFIC FUNCTIONS ****************************




function buildItemHTML(itm)
{
	var tW;
	
	if (itm.lvl == 1)
		tW = 102;
	else
		tW = 120;
		
	var s = "";
	
	if(itm.lvl == 1)
	{
		
		
	
		
		//s += "<DIV id='" + itm.name + "' class='menuItems0'><SPAN class='whitetext'>|&nbsp;&nbsp;&nbsp;" + itm.displayName + "&nbsp;&nbsp;&nbsp;</SPAN></DIV>\n";
		s += "<DIV id='" + itm.name + "' class='menuItems0'><table width='165' border='0' cellspacing='0' cellpadding='0'><tr><td width='146' align='right'><SPAN class='greymenutext'>" + itm.displayName + "</SPAN></td><td><img src='images/trans.gif' width='9' height='1'><img src='images/trans.gif' width='5' height='19'><img src='images/trans.gif' width='5' height='1'></td></tr></table></DIV>\n";		
		s += "<DIV id='" + itm.nameOn + "' class='menuItems0'><table width='165' border='0' cellspacing='0' cellpadding='0'><tr><td width='146' align='right'><SPAN class='lightgreymenutext'>" + itm.displayName + "</SPAN></td><td><img src='images/trans.gif' width='9' height='1'><img src='images/";
		if (itm.hasChildren)
			s += "menuarrow";
		else
			s += "trans";
		s += ".gif' width='5' height='19'><img src='images/trans.gif' width='5' height='1'></td></tr></table></DIV>\n";
        	s += "<DIV id='" + itm.nameTrans + "' class='menuItems0'></DIV>\n";
	}
	else
	{
		s += "<DIV id='" + itm.name + "' class='menuItems'><TABLE border='0' cellspacing='0' cellpadding='1' width='*'><TR><TD bgcolor='#ffffff'><TABLE border='0' cellspacing='0' cellpadding='3' width='" + tW + "'><TR>";

		s += "<TD class='greymenutext' bgcolor='#ffffff'>" + itm.displayName + "</TD>";

		s += "</TR></TABLE></TD></TR></TABLE></DIV>\n";
		s += "<DIV id='" + itm.nameOn + "' class='menuItems'><TABLE border='0' cellspacing='0' cellpadding='1' width='*'><TR><TD bgcolor='#ffffff'><TABLE border='0' cellspacing='0' cellpadding='3' width='" + tW + "'><TR>";


		s += "<TD class='whitemenutext' bgcolor='#ffffff'>" + itm.displayName + "</TD>";

		s += "</TR></TABLE></TD></TR></TABLE></DIV>\n";
       		s += "<DIV id='" + itm.nameTrans + "' class='transItems'></DIV>\n";
	}
	return s;
}


function buildMenuHTML()
{
	var s = "";
	for (var i = 0; i < this.menuItems.length; i++)
		s += buildItemHTML(this.menuItems[i]);
	return s;
}


function getStackHeight(itemStack)
{
	var h = 0;
	for (var i = 0; i < itemStack.length; i++)
		h += itemStack[i].height;
	return h;
}


function liteTree()
{
	show(this.onRef);
	
	if (this.hasChildren)
	{
		if (!this.childrenSized)
			this.sizeItems();
		
		var h = getStackHeight(this.children);
		
		/*if (this.lvl == 1)
		{
			this.cX = this.left + 7;
			this.cY = this.top + this.yO + 21;
		}
		else
		{*/
			this.cX = this.left + this.xO;
			this.cY = this.top + this.yO;
		//}
		
		if (this.cY < getScrollY() + 4)
			this.cY = getScrollY() + 4;
			
		if (this.cY + h > getScrollY() + getWindowHeight() - 4)
			this.cY = getScrollY() + getWindowHeight() - h - 4;
			
		this.positionChildren();
		this.showChildren();
	}
}


function hideTree(newItm)
{
	if (newItm.parent != this)
	{
		if (newItm.parent == this.parent)
		{
			hide(this.onRef);
			
			if (this.hasChildren)
				this.hideChildren();
		}
		else
		{
			hide(this.onRef);
			
			if (this.hasChildren)
				this.hideChildren();
			
			this.parent.hideTree(newItm);
		}
	}
}


function positionChildren()
{
	var L = this.cX;
	var T = this.cY;
	
	if (this.lvl == 0)
	{
		for (var i = 0; i < this.children.length; i++)
		{
			var itm = this.children[i];
			itm.left = L;
			itm.top = T;
			itm.right = itm.left + itm.width;
			itm.bottom = itm.top + itm.height;
			shiftTo(itm.ref, L, T);
			shiftTo(itm.onRef, L, T);
			shiftTo(itm.tRef, L, T);
			T += itm.height;
			
		}
	}
	else
	{
		for (var i = 0; i < this.children.length; i++)
		{
			var itm = this.children[i];
			itm.left = L;
			itm.top = T;
			itm.right = itm.left + itm.width;
			itm.bottom = itm.top + itm.height;
			shiftTo(itm.ref, L, T);
			shiftTo(itm.onRef, L, T);
			shiftTo(itm.tRef, L, T);
			T += itm.height;
			
		}
	}
}


function hideChildren()
{
	for (var i = 0; i < this.children.length; i++)
	{
		hide(this.children[i].tRef);
		hide(this.children[i].ref);
	}
}


function showChildren()
{
	for (var i = 0; i < this.children.length; i++)
	{
		show(this.children[i].tRef);
		show(this.children[i].ref);
	}
}


function menuItem(name, displayName, dest, parentName, menuName)
{
	this.displayName = displayName;
	this.name = name;
        this.nameOn = name + "On";
        this.nameTrans = name + "Trans";
	this.dest = dest;
	this.ref;
	this.onRef;
	this.tRef;
	this.cX;
	this.cY;
	this.xO = 165;
	this.yO = 0;
	this.parent = eval(parentName);
	this.lvl = this.parent.lvl+1;
	this.parent.hasChildren = true;
	this.menu = eval(menuName);
	this.hasChildren = false;
	this.children = null;
	this.childrenSized = false;
	this.isOpen = false;
	this.top;
	this.bottom;
	this.left;
	this.right;
	this.width;
	this.height;
	this.menu.menuItems[this.menu.menuItems.length] = this;
	this.sizeItems = sizeItems;
	this.liteTree = liteTree;
	this.hideTree = hideTree;
	this.positionChildren = positionChildren;
	this.showChildren = showChildren;
	this.hideChildren = hideChildren;
}


function getDOMRefs()
{				
	for (var i = 0; i < this.menuItems.length; i++)
	{
		this.menuItems[i].ref = getObject(this.menuItems[i].name);
		this.menuItems[i].onRef = getObject(this.menuItems[i].nameOn);
		this.menuItems[i].tRef = getObject(this.menuItems[i].nameTrans);
	}
}


function makeHierachy()
{
	for (var i = 0; i < this.menuItems.length; i++)
	{
		var item = this.menuItems[i];
		var myLevel = item.parent.children;
		myLevel[myLevel.length] = item;
		if(item.hasChildren) item.children = new Array();
	}
}


function setEventCapture() {
	for (var i = 0; i < this.menuItems.length; i++) {
		if (isNav4) 
		{
			this.menuItems[i].tRef.captureEvents(Event.MOUSEOVER);
			this.menuItems[i].tRef.captureEvents(Event.MOUSEOUT);
			this.menuItems[i].tRef.captureEvents(Event.CLICK);
		}
		if (!isIE55 && !isIE6 && !isNav6)
		{
			this.menuItems[i].tRef.onmouseover = handleOver;
			this.menuItems[i].tRef.onmouseout = handleOut;
			this.menuItems[i].tRef.onclick = handleMenuClick;
		}
	}
}


function sizeItems()
{

	for (var i = 0; i < this.children.length; i++)
	{
		var itm = this.children[i];
		itm.width = getObjWidth(itm.ref);
		itm.height = getObjHeight(itm.ref)-1;

		if (isIE55 || isIE6 || isNav6)
			itm.tRef.innerHTML = "<IMG id='" + itm.name + "Image' src='images/trans.gif' width='" + itm.width + "' height='" + (itm.height) + "' border='0' onMouseOver='handleOver(event)' onMouseOut='handleOut(event)' onClick='handleMenuClick(event)'>";
		else if (isIE)
		{
		        itm.tRef.style.pixelWidth = itm.width;
		        itm.tRef.style.pixelHeight = itm.height;
		}
		else
		{
			itm.tRef.clip.width = itm.width;
			itm.tRef.clip.height = itm.height;
		}
		
		setZIndex(itm.ref, 5 * itm.lvl);
		setZIndex(itm.onRef, 6 * itm.lvl);
		setZIndex(itm.tRef, 7 * itm.lvl);
		
	}

	this.childrenSized = true;
}


function reset()
{
	this.currItem = null;
	
	for (var i = 0; i < this.menuItems.length; i++)
	{
			hide(this.menuItems[i].onRef);
		
		if (this.menuItems[i].lvl > 1)
		{
			hide(this.menuItems[i].tRef);
			hide(this.menuItems[i].ref);
		}
	}
}


function initMenu()
{
	this.getDOMRefs();
	this.makeHierachy();
	this.sizeItems();
	this.setEventCapture();
	this.positionChildren();
	this.showChildren();

}


function writeMenuHTML()
{
	document.write(theMenu.buildMenuHTML());
}


function menu(name)
{
	this.name = name;
	this.cX = 0;
	this.cY = 167;
	this.lvl = 0;
	this.lag = 300;
	this.timer;
	this.sTimer;
	this.searchOpen = false;
	this.loadSearchExp = false;
	this.hasChildren = true;
	this.childrenSized = false;
	this.isOpen = true;
	this.menuItems = new Array();
	this.children = new Array();
	this.buildMenuHTML = buildMenuHTML;
	this.initMenu = initMenu;
	this.getDOMRefs = getDOMRefs;
	this.makeHierachy = makeHierachy;
	this.sizeItems = sizeItems;
	this.setEventCapture = setEventCapture;
	this.positionChildren = positionChildren;
	this.reset = reset;
	this.hideTree = hideTree;
	this.showChildren = showChildren;
	this.hideChildren = hideChildren;
}


function handleOver(e) 
{

	clearTimeout(theMenu.timer);
	
	var nm;
	
	if (isIE)
	{
		event.srcElement.style.cursor = "hand";
		nm = event.srcElement.id.slice(0,-5);
	}
	else
	{
		if (isNav6)
			e.target.style.cursor = "pointer";
		nm = e.target.id.slice(0,-5);
	}

	var itm = eval(nm);
		
	if (theMenu.currItem)
			theMenu.currItem.hideTree(itm);
	
	theMenu.currItem = itm;
	
	theMenu.currItem.liteTree();
	
	return;
}


function handleOut(e) 
{
	
        theMenu.timer = setTimeout("theMenu.reset();", theMenu.lag);
	return;
}


function handleMenuClick(e) 
{
	window.location.href = theMenu.currItem.dest;
	return;
}


function init()
{
	if(isNav4)
		theMenu.initMenu();
	canResize = true;
}


// **************** GLENS ADDED FUNCTIONS ****************************

function popWindow(file) {
	var popup = window.open(file,"AAP","width=316,height=461,scrollbars=yes,resizable=no");
	popup.focus();
}


function getSelectValue(selectObj)
{
	for (i = 0; i < selectObj.options.length; i++)
		if (selectObj.options[i].selected) 
			return selectObj.options[i].value;

	return false;
}


function popWindowFromPopup(loc) {
	var popup = window.open(loc,"FILEWIN");
	popup.focus();
}

//function getFile(o)
//{
//	if (getSelectValue(o) != "")
//		popWindowFromPopup(getSelectValue(o));
//}

//function swapLoc(o)
//{

//}






