// JavaScript Document

//variable declarations
var browserCheck = false;
var bufferID = '';
var holderID = '';
var bufferInitial = 0;
var menuCellHeight = 0;
var bufferDirection = 'vertical';
var allowClosing = true;
var menuOpen = '';
var lastMenuOpen = '';

//initial scripts;
if((getBrowserType()=="IE"&&parseInt(getBrowserVersion())>=4)||(getBrowserType()=="Netscape"&&parseInt(getBrowserVersion())>=5)||(getBrowserType()=="Firefox")) {
	browserCheck = true;
}

//The following function defines a menuItem object
function menuItem(itemText,itemSubText,linkURL,linkTarget) {
	if (linkTarget==null) {
		linkTarget = 'top';
	}
	this.text = itemText;
	this.subText = itemSubText;
	this.URL = linkURL;
	this.target = linkTarget;
}

//The following function provides a way to create a new menuItem object and set the necessary properties
function addMenuItem(menu,itemText,itemSubText,linkURL,linkTarget) {
	if(!(self['arr'+menu])) {		
		eval('arr'+menu+' = new Array()');
	}
	obj = eval('arr'+menu);
	obj[obj.length] = new menuItem(itemText,itemSubText,linkURL,linkTarget);
}

//The following function creates the HTML for a dropdown menu from the information passed to it
	//The function takes an indefinite number of parameters, each in the form of a two-member, one-dimensional array:
	//First member is the menu item's text, the second is the URL to which the item is linked

function createDropMenu(menuName) {
	if (hasItems(menuName)) {
		menuItems = eval('arr'+menuName);
		strMenu	= '';		
		strMenu += '<table class="dropMenu" cellpadding="0" cellspacing="0" style="z-index: 50;" onMouseOver="highlight('+"'on'"+')" onMouseOut="highlight('+"'off'"+')">';		
		for (var i=0; i<menuItems.length; i++) {
			strMenu += '<tr><td class="dropMenu" onMouseOver="changeDropMenu(this,false,' + "'" + menuItems[i].URL + "'" + ')" onMouseOut="changeDropMenu(this,true)"' +
			' onClick="cellClicked(' + "'" + menuItems[i].target + "','" + menuItems[i].URL + "'" + ')" style=""><span style="width: 100%;">' +
				menuItems[i].text;
			if(menuItems[i].subText!='') {
				strMenu += '<span style="font-size: 8pt;">' + ' ' + menuItems[i].subText + '</span>'
			}
			strMenu += '</span></td></tr>';
		}
		strMenu += '</table>';				
	} else {
		strMenu = '';
	}	
	return strMenu;
}

function showMenu(menuName) {
	setBufferHeight(menuName);
	insertMenuHTML(menuName);
	setDropMenuVisibility('visible');
}

//The following function returns HTML code for the menu requested
function getHTML(menuName) {
	//window.status = 'creating menu ' + menuName;
	return createDropMenu(menuName);
}

function insertMenuHTML(menuName) {
	document.getElementById(getHolderID()).innerHTML = getHTML(menuName);
}

function hasItems(menuName) {
	if(self['arr'+menuName]) {		
		theArray = eval('arr'+menuName);
		if(theArray.length>0) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function setDropMenuVisibility(setting) {
	//setting should be "visible" or "hidden"
	document.getElementById(getHolderID()).style.visibility = setting;
}

function getDropMenuVisibility() {
	return document.getElementById(getHolderID()).style.visibility;
}

//The following function returns a number representing the location of a menu relative to the other menus
function getMenuOrder(menuName) {
	i = 1;
	while(self['menu'+i]) {
		if(eval('menu'+i)==menuName) {
			return i;
		}
		i=i+1;
	}
	return 0;
}

function setBufferHeight(menuName) {
	switch(getBufferDirection()) {
		case "vertical":
			document.getElementById(getBufferID()).style.height = getBufferInitial() + (getMenuCellHeight()*getMenuOrder(menuName));
		break;
		case "horizontal":
			document.getElementById(getBufferID()).style.width = getBufferInitial() + (getMenuCellHeight()*getMenuOrder(menuName));
		break;
	}	
}

function cellClicked(target,URL) {
	okToClose(true);
	highlight('off');
	switch(target) {
		case 'blank':
			window.open(URL,'newWind');
			break;
		default:
			eval(target).location.href = URL;
	}	
}

function browserOk() {
	return browserCheck;
}

function okToClose() {
	//can pass one argument to set whether to allow closing of drop menus
	if(okToClose.arguments.length==1) {		
		allowClosing=okToClose.arguments[0];
		//window.status = allowClosing;
	} else {
		return allowClosing;
	}
}

function changeDropMenu(cell,canClose,URL) {
	okToClose(canClose);
	changeDropMenuStyle(cell,canClose);
	if(!canClose) {
		window.status = URL;
	}
}

function setMenuOpen(menuName) {
	menuOpen = menuName;
}

function getMenuOpen() {
	return menuOpen;
}

function setLastMenuOpen(menuName) {
	lastMenuOpen = menuName;
}

function getLastMenuOpen() {
	return lastMenuOpen;
}

function setBufferID(cellName) {
	bufferID = cellName;
}

function getBufferID() {
	return bufferID;
}

function setHolderID(cellName) {
	holderID = cellName;
}

function getHolderID() {
	return holderID;
}

function setBufferInitial(height) {
	bufferInitial = height;
}

function getBufferInitial() {
	return bufferInitial;
}

function setBufferDirection(direction) {
	if(direction!='horizontal') {
		direction = 'vertical';
	}
	bufferDirection = direction;
}

function getBufferDirection() {
	return bufferDirection;
}

function setMenuCellHeight(height) {
	menuCellHeight = height;
}

function getMenuCellHeight() {
	return menuCellHeight;
}