// Global variables
var isCSS, isW3C, isIE4, isNN4, isImages, objArray;

objArray = new Array();

// tm == top menu
// mi == menu item
// tp == this page

tp_tm_bgColorOn = "#F8BB00";
tp_tm_bgColorOff = "#F8BB00";

tm_bgColorOn = "#0073ae";
tm_bgColorOff = "transparent";

mi_bgColorOn = "#000000";
mi_bgColorOff = "#0073ae";

tm_fgColorOn = "#085d99";
tm_fgColorOff = "#085d99";

// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
	if (document.images) {
		isImages = true;
		isCSS = (document.body && document.body.style) ? true : false;
		isW3C = (isCSS && document.getElementById) ? true : false;
		isIE4 = (isCSS && document.all) ? true : false;
		isNN4 = (document.layers) ? true : false;
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	} else {
		isImages = false;
	}
}

// Set the background color of an object
function setBGColor(obj, color) {
	var theObj = getObject(obj);
	if (theObj) { 
		if (isNN4) {
			theObj.bgColor = color;
		} else if (isCSS) {
			theObj.backgroundColor = color;
		}
	}   
}       

// Set the background color of an object
function setFGColor(obj, color) {
	var theObj = getObject(obj);
	if (theObj) { 
		theObj.color = color;
	}   
}       

function setBorders(a_obj, span_obj, color, leftPad, rightPad) {
return;
	var aObj = getObject(a_obj);
	var spanObj = getObject(span_obj);
	var propVal;

	if (color == "none") {
		propVal = "0 none";
	} else {
		propVal = "1px solid " + color;
	}
	
	if (aObj) { 
		aObj.borderRight = propVal;
		aObj.borderLeft = propVal;
		spanObj.paddingLeft = leftPad + "px";
		spanObj.paddingRight = rightPad + "px";
	}   
	
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
	var theObj;
	if (typeof obj == "string") {
		if (isW3C) {
			theObj = document.getElementById(obj);
		} else if (isIE4) {
			theObj = document.all(obj);
		} else if (isNN4) {
			theObj = seekLayer(document, obj);
		}
	} else {
		// pass through object reference
		theObj = obj;
	}
	return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
	var theObj = getRawObject(obj);
	if (theObj && isCSS) {
		theObj = theObj.style;
	}
	objArray[obj] = theObj;  // associative array cache
	return theObj;
}

// Set the visibility of an object to visible
function show(obj) {
	var theObj;
	if (objArray[obj]) {
		theObj = objArray[obj];
	} else {
		theObj = getObject(obj);
	}
	
	if (theObj) {
		theObj.display = "block";
	}
}

// Set the visibility of an object to hidden
function hide(obj) {
	var theObj;
	if (objArray[obj]) {
		theObj = objArray[obj];
	} else {
		theObj = getObject(obj);
	}

	if (theObj) {
		theObj.display = "none";
	}
}

var menuStack = new Array();
var menuItemStack = new Array();
var clearBorders = true;

function showMenu(lyrname, menuitem, level) {

	// the following if statement addresses a weird corner case who's effects are 
	// visible only in Gecko based browsers.  It does not appear to affect other
	// browsers.
	//
	// What was happening was that if you move your cursor up (and only up) from a
	// dropdown menu to the the highlighted top menu item, the menu would blink 
	// off then on again.
	//
	// the original code was merely a call to hideMenus(level); with no if logic.
	// Based on inspection though, I think that this logic should slightly improve
	// menu performance.
	
	if ( menuStack[level] != lyrname ) {
		hideMenus(level);
	} else {
		hideMenus(level+1);
	}
	
	show(lyrname);
	setBGColor("topmenu_"+lyrname, tm_bgColorOn);
	setFGColor("topmenu_"+lyrname, tm_fgColorOn);
	if (arguments.length == 3) {
		setBorders("topmenu_"+lyrname, "topmenu_"+lyrname+"_span", "#ffffff", 5, 10);
		clearBorders = true;
	} else {
		clearBorders = false;
	}
	
	if ( menuitem != '' ) {
		setBGColor(menuitem, mi_bgColorOn);
	}
	show("invisibleLyr");
	menuStack[level] = lyrname;
	menuItemStack[level] = menuitem;
}

function hideMenus(level) {
	if(level == 1) {
		hide("invisibleLyr");
		setBGColor("topmenu_"+menuStack[1], tm_bgColorOff);
		setFGColor("topmenu_"+menuStack[1], tm_fgColorOff);
		if (clearBorders) {
			setBorders("topmenu_"+menuStack[1], "topmenu_"+menuStack[1]+"_span", "none", 6, 11);
		} else {
			clearBorders = true;
		}
	}

	for ( var i = (menuStack.length -1); i >= level; i-- ) {
		setBGColor(menuItemStack[i], mi_bgColorOff);
		hide(menuStack[i]);
	}
	
}

window.onload = function () {
	initDHTMLAPI(); 
}

var last_shown_contact = "";

function show_contact_info(list) {
 	list_item_value = list.options[list.selectedIndex].value;
	if (last_shown_contact != "") {
	 	hide(last_shown_contact);
	}
	last_shown_contact = list_item_value;
	show(list_item_value);
}


/* the following function accepts a reference to a select list, extracts the 
		selected value, then loads the value as a URL */

function url(selection) {
	u = selection.options[selection.selectedIndex].value;
	if ( u != "") {
		document.location.href = u;
	}
}
