// JavaScript Document

//variable declarations
var browserCheck = false;
var bufferID = '';
var holderID = '';
var allowClosing = true;
var menuOpen = '';
var lastMenuOpen = '';
var i=0;

//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,order) {
	strMenu	= '';
	strMenu += '<table class="" cellpadding="0" cellspacing="0" style="z-index: 100;">';
	strMenu += '<tr>';
	for (i=1; i<=order; i++) {
		strMenu += '<td valign="top" class="nav" style="height: 22px;">';
		strMenu += '<a class="nav" href="nothing">' + eval('menu'+i+'Text') + '</a>';
		strMenu += '</td>'
	}
	strMenu += '</tr>';	
	strMenu += '<tr>';
	if(order>1) {
		strMenu += '<td colspan="' + parseInt(order-1) + '">&nbsp;</td>';
	}	
	strMenu += '<td class="" valign="top">';	
	if (typeof(self['arr'+menuName])!='undefined') {	
		menuItems = eval('arr'+menuName);
		strMenu += '<table class="dropMenu" cellpadding="0" cellspacing="0" style="z-index: 50; visibility: visible;" onMouseOver="highlight(true)" onMouseOut="highlight(false)">';
		strMenu += '<tr><td style="padding: 2px;">';
		strMenu += '<table cellpadding="0" cellspacing="0" border="0" style="">';
		styleText = '';
		for (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="' + styleText + '">' +
				menuItems[i].text + ' <font style="font-weight: normal;">' + menuItems[i].subtext + '</font>'
				'</td></tr>';
		}
	strMenu += '</table></td></tr></table>';
	} else {		
		strMenu += '&nbsp;';
	}	
	strMenu += '</td>';
	strMenu += '</tr></table>';	
	return strMenu;
}

function showMenu(menuName) {
	insertMenuHTML(menuName);
	//setDropMenuVisibility('visible');
}

//The following function returns HTML code for the menu requested
function getHTML(menuName) {
	//window.status = 'creating menu ' + menuName;
	theOrder = getMenuOrder(menuName);
	return createDropMenu(menuName,theOrder);
}

function insertMenuHTML(menuName) {
	document.getElementById(getHolderID()).innerHTML = getHTML(menuName);
}

function clearMenuHTML() {
	document.getElementById(getHolderID()).innerHTML = '&nbsp;';
}

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;
}