/*
 * $Id: menu.js,v 1.1 2006-03-24 10:46:30 sgiles Exp $
 * Copyright (c) 2004 Orbis Technology Ltd. All rights reserved.
 */

// timer
var timeOn  = null;
var timeOn2 = null;

// maximum number of menus
var numMenus = 50;

// count the menus defined so far
var currentMenuNo = 0;

// menu state
var menuActive = new Array(numMenus);

// menu tier
var tier = new Array(numMenus);

// line-up menus
var borderMod = new Array(numMenus);

// off class of the corresponding (sub)menu label link
var offClass = new Array(numMenus);

// on class of the corresponding (sub)menu label link
var onClass = new Array(numMenus);

// off colour of the corresponding (sub)menu label background
var offColours = new Array(numMenus);

// on colour of the corresponding (sub)menu label background
var onColours = new Array(numMenus);

// name of the bullet object (if any) used by the corresponding (sub)menu label
var labelBulletName = new Array(numMenus);

// the type of (sub)menu label corresponding to this menu
var menuType = new Array(numMenus);

// hold the menu objects in the system
var menus = new Array(numMenus);

// location of shim.gif
var shimGIF = "shim.gif"


// sniff out problem browsers
var browser = new SniffBrowser();
function SniffBrowser() {

	var ns4 = document.layers;
	var op5 = navigator.userAgent.indexOf("Opera 5") !=-1 || navigator.userAgent.indexOf("Opera/5") != -1;
	var op6 = navigator.userAgent.indexOf("Opera 6") !=-1 || navigator.userAgent.indexOf("Opera/6") != -1;
	var agt = navigator.userAgent.toLowerCase();
	var mac = agt.indexOf("mac") != -1;
	var ie  = agt.indexOf("msie") != -1;
	var mac_ie = mac && ie;
}


// get the style object for the different types of browsers
function getStyleObject(objectId, doc) {

	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	}
	else if(document.all && document.all(objectId)) {
		return document.all(objectId).style;
	}
	else if(document.layers && document.layers[objectId]) {
		return getObjNN4(document, objectId);
	}

	return false;
}


// hide or show a page element
function changeObjectVisibility(objectId, newVisibility) {

	var styleObject = getStyleObject(objectId, document);
	if(styleObject) {
		styleObject.visibility = newVisibility;
		return true;
	}

	return false;
}


// find an image (NS4 only)
function findImage(name, doc) {

	var i, img;

	for(i = 0; i < doc.images.length; i++) {
		if(doc.images[i].name == name) {
			return doc.images[i];
		}
	}
	for(i = 0; i < doc.layers.length; i++) {
		if((img = findImage(name, doc.layers[i].document)) != null) {
			img.container = doc.layers[i];
			return img;
		}
	}

	return null;
}


// get an image (NS4 only)
function getImage(name) {

	if (document.layers) {
		return findImage(name, document);
	}
	return null;
}


// find an object (NS4 only)
function getObjNN4(obj, name)
{
	var x = obj.layers;
	var foundLayer;

	for(var i=0; i < x.length; i++) {
		if(x[i].id == name) {
		 	foundLayer = x[i];
		}
		else if(x[i].layers.length) {
			var tmp = getObjNN4(x[i], name);
		}
		if(tmp) {
			foundLayer = tmp;
		}
	}

	return foundLayer;
}


// get an element's height
function getElementHeight(Elem) {

	var elem, xPos;

	if(browser.ns4) {
		elem = getObjNN4(document, Elem);
		return elem.clip.height;
	}

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	} else if (document.all) {
		elem = document.all[Elem];
	}

	if(browser.op5) {
		xPos = elem.style.pixelHeight;
	} else {
		xPos = elem.offsetHeight;
	}

	return xPos;
}


// get an element's width
function getElementWidth(Elem) {

	var elem, xPos;

	if(browser.ns4) {
		elem = getObjNN4(document, Elem);
		return elem.clip.width;
	}

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	} else if(document.all) {
		elem = document.all[Elem];
	}

	if(browser.op5) {
		xPos = elem.style.pixelWidth;
	}
	else {
		xPos = elem.offsetWidth;
	}

	return xPos;
}


// get the X co-ordinate of an element
function getElementLeft(Elem) {

	var elem, xPos, tempEl;

	if(browser.ns4) {
		elem = getObjNN4(document, Elem);
		return elem.pageX;
	}

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	} else if (document.all){
		elem = document.all[Elem];
	}
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while(tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}

	return xPos;
}



// get the Y co-ordinate of an element
function getElementTop(Elem) {

	var elem, yPos, tempEl;

	if(browser.ns4) {
		elem = getObjNN4(document, Elem);
		return elem.pageY;
	}

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	} else if (document.all) {
		elem = document.all[Elem];
	}
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while(tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}


// get the X co-ordinate of an image
function getImageLeft(img) {

	if(document.layers) {
		var m = getImage(img);
		if(m.container != null) {
			return m.container.pageX + m.x;
		}
		return m.x;
	}

	return getElementLeft(img);
}


// get the Y co-ordinate of an image
function getImageTop(img) {

	if(document.layers) {
		var m = getImage(img);
		if(m.container != img) {
			return m.container.pageY + m.y;
		}
		return m.y;
	}

	return getElementTop(img);
}


// get image width
function getImageWidth(img) {

	if(document.layers) {
		var m = getImage(img);
		return m.width;
	}

	return getElementWidth(img);
}


// get image height
function getImageHeight(img) {

	if(document.layers) {
		var m = getImage(img);
		return m.height;
	}

	return getElementHeight(img);
}


// move an element to a new set of X + Y co-ordinates
function moveXY(Obj, x, y) {

	var obj = getStyleObject(Obj)

	if(browser.ns4) {
		obj.top = y;
		obj.left = x;
	}
	else if(browser.op5) {
		obj.pixelTop = y;
		obj.pixelLeft = x;
	}
	else {
		obj.top = y + 'px';
		obj.left = x + 'px';
	}
}


// change style class of an element
function changeClass(Elem, Class) {

	var elem;

	if(document.getElementById) {
		elem = document.getElementById(Elem);
	}
	else if(document.all){
		elem = document.all[Elem];
	}
	if(browser.op5 || browser.op6) {
		elem.style.className = Class;
	}
	else {
		elem.className = Class;
	}
}


// change the background of an element
function changeBGColour(Object, colour) {

	if(browser.ns4) {
		var obj = getObjNN4(document, Object);
		obj.bgColor=colour;
	} else {
		var obj = getStyleObject(Object);
		if(browser.op5) {
			obj.background = colour;
		} else {
			obj.backgroundColor = colour;
		}
	}
}


// changes the source the source of "target" to "source"
function changeImage(target, source) {

	var imageObj;

	if(browser.ns4) {
		imageObj = getImage(target);
		if(imageObj) {
			imageObj.src = eval(source).src;
		}
	} else {
		imageObj = eval('document.images.' + target);
		if (imageObj) {
			imageObj.src = eval(source).src;
		}
	}
}


// Writes a 1 pixel wide td element with a background colour "B".
function borderCell(B) {

	return '<td width="1" bgcolor="' + B + '">' +
	    '<img src="' + shimGIF + '" width="1" height="1" border="0"></td>';
}


/* Writes a table row 1 pixel high, containing a td element with background
 * colour "B" and a colspan of "C"
 */
function borderRow(B, C) {

	return '<tr><td height="1" colspan="' + C + '" bgcolor="' + B + '">' +
	   '<img src="' + shimGIF + '" width="1" height="1" border="0"></td></tr>';
}



// clear the timeout when a mouse enters a menu item or label, created on menuOut
function menuOver() {
	clearTimeout(timeOn);
}


// hide all the menus after 1 second, when a mouse leaves a menu item or label
function menuOut() {
	clearTimeout(timeOn2);
	timeOn = setTimeout("hideAllMenus()", 500);
}


// show a menu
function showMenu(m_No, eventObj) {

	// hide all the other menus
	hideAllMenusTier(tier[m_No] - 1);


	var borderModSize = borderMod[m_No];

	// change the bg colour + class
	if(browser.ns4) {
		changeBGColour('menuLabel' + m_No, onColours[m_No]);
	}
	else {
		changeBGColour('labelCell' + m_No, onColours[m_No]);
		changeClass('menuLink' + m_No, onClass[m_No]);
	}

	// if the Menu Label has a bullet point then change it
	if(labelBulletName[m_No] != null){
		changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.onImage');
	}

	// set the menu as "active"
	menuActive[m_No] = true;

	// if it's not a blank menu...
	if(menuType[m_No] != 'blank') {

		// ID of the Menus Label
		if(browser.ns4) {
			labelObj = 'menuLabel' + m_No;
		}
		else {
			labelObj = 'labelCell' + m_No;
		}

		// X + Y co-ordinates of the menu label
		var x = getElementLeft(labelObj) - borderModSize;
		var y = getElementTop(labelObj) + getElementHeight(labelObj);

		// for centered menus...
		if (menus[m_No].align == 'center') {
			x = x + ((getElementWidth(labelObj) - getElementWidth('menu' + m_No)) / 2);
		}

		// right aligned menus
		if (menus[m_No].align == 'right') {
			x = x + ((getElementWidth(labelObj) - getElementWidth('menu' + m_No))) + (borderModSize * 2);
		}

		// move the menu to it's rightful place
		moveXY('menu' + m_No, x, y);

		// and finally show the menu
		return changeObjectVisibility('menu' + m_No, 'visible');
	}
}


// displays side menus (with a slight delay)
function showMenuSide(m_No, eventObj, Tier) {

	timeOn2 = setTimeout('_showMenuSide("' + m_No + '","' + eventObj + '","' + Tier + '")', 150);
}


// displays side menus
function _showMenuSide(m_No, eventObj, Tier) {

	// hide all the other menus
	hideAllMenusTier(tier[m_No]-1);

	var borderModSize = borderMod[m_No];

	// bg colour + class
	if(browser.ns4) {
		changeBGColour('menuLabel' + m_No, onColours[m_No]);
	} else {
		changeBGColour('labelCell' + m_No, onColours[m_No]);
		changeClass('menuLink' + m_No, onClass[m_No]);
	}

	// if the Menu Label has a bullet point then change it
	if (labelBulletName[m_No] != null) {
		changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.onImage');
	}

	// active
	menuActive[m_No] = true;

	// if it's not a blank menu...
	if(menuType[m_No] != 'blank') {
		if(browser.ns4) {
			labelObj = 'menuLabel' + m_No;
		}
		else {
			labelObj = 'labelCell' + m_No;
			if(browser.mac_ie) {
				labelObj = 'labelRow' + m_No;
			}
		}

		/* X + Y
		 * - offset X by 3 pixels, so we can have overlapping menus
		 * - offset Y by half the height of the label, so we can overlap
		 */
		x = getElementLeft(labelObj) - 3;
		y = getElementTop(labelObj) - borderModSize + (getElementHeight(labelObj) / 2);

		// right aligned menus
		if(menus[m_No].align=='right') {
			x = x + getElementWidth(labelObj);
		}
		else {
			x = x - getElementWidth('menu' + m_No);
		}

		// move the menu to it's correct placement...
		moveXY('menu' + m_No, x, y);

		// display
		return changeObjectVisibility('menu' + m_No, 'visible');
	}
}



// hide all menus
function hideAllMenus() {

	for(var i = 1; i < (currentMenuNo + 1); i++) {
		if(menuActive[i]) {
			hideMenu(i);
		}
	}
}


// hide all menus on a tier
function hideAllMenusTier(Tier) {

	for(var i = 1; i < (currentMenuNo + 1); i++) {
		if(tier[i] > Tier && menuActive[i]) {
			hideMenu(i);
		}
	}
}


// hide a menu
function hideMenu(m_No) {

	if(browser.ns4) {
		changeBGColour('menuLabel' + m_No, offColours[m_No]);
	}
	else {
		changeBGColour('labelCell' + m_No, offColours[m_No]);
		changeClass('menuLink' + m_No, offClass[m_No]);
	}

	if(labelBulletName[m_No] != null){
		changeImage('menuBullet' + m_No, labelBulletName[m_No] + '.offImage');
	}
	menuActive[m_No] = false;

	return changeObjectVisibility('menu' + m_No, 'hidden');
}



/* menu-bar object
 *
 *   barName      - menu bar div id
 *   barWidth     - width of the menu-bar (pixels)
 *   orientation  - horizontal or vertical
 *   iBor         - inner border colour
 *   oBor         - outer border colour
 */
function MenuBar(barName, barWidth, orientation, iBor, oBor) {

	// count the number of labels in the menu bar
	this.numLabels = 0;

	// border colours + orientation
	this.iBor = iBor;
	this.oBor = oBor;
	this.orientation = orientation;

	// default height
	this.height = 15;

	// label text (menu HTML)
	this.labelText = new Array();

	// veritical menu bars
	this.rowText = new Array();

	// link classes
	this.offClass = 'JSMenuLabelLink';
	this.onClass = 'JSMenuLabelLinkOn';

	// bullet point alignment (left | right)
	this.bulletAlign = 'left';

	// target type (self | iframe | frame | new)
	this.targetType = 'self';

	// target frame ( _self | _blank | (i)frame name)
	this.targetFrame = '_self';


	/* add a lebel
	 *
	 *   bullet       - name of bullet, or null
	 *   labelText    - text to appear in the menu-label
	 *   menuNo       - menu number
	 *   labelWidth   - label width (pixels)
	 *   offColour    - background colour of the label's off state
	 *   onColour     - background colour of the label's on state
	 *   labelURL     - menu link URL
	 *   align        - text alignment
	 */
	this.add = function(bullet, labelText, menuNo, labelWidth, offColour, onColour, labelURL, align) {

		this.numLabels += 1;

		// set the tier for the menu hanging from this label
		tier[menuNo] = 0;

		// offset for placing the menu due to the outer border
		if(this.oBor != null) {
			borderMod[menuNo] = 1;
		}
		else {
			borderMod[menuNo] = 0;
		}

		// set the globals for the menu label
		if(menuNo != null) {
			onColours[menuNo]       = onColour;
			offColours[menuNo]      = offColour;
			onClass[menuNo]         = this.onClass;
			offClass[menuNo]        = this.offClass;
			labelBulletName[menuNo] = bullet;
		}

		// temporary string object to hold the html for the menu label
		var temp = new String('');

		// string object to hold the row tag for the label (if necessary)
		this.rowText[this.numLabels] = new String('');

		// td tag
		temp += '<td id="labelCell' + menuNo + '" width="' + labelWidth +
		    '" bgcolor="' + offColour + '" valign="middle" height="' + this.height + '" ';

		// non NS4
		if(!browser.ns4) {
			temp += ' onmouseout="menuOut(); "onmouseover="menuOver(); ';
			if(this.orientation == 'vertical') {
				temp += 'return !showMenuSide(' + menuNo + ', event, tier[' + menuNo + ']);" ';
			}
			else {
				temp += 'return !showMenu(' + menuNo + ', event);" ';
			}
		}
		temp +='>';

		// NS4
		if(browser.ns4) {
			temp +='<ilayer><layer onmouseout="menuOut();" onmouseover="menuOver(); ';
			if(this.orientation == 'vertical') {
				temp +='return !showMenuSide(' + menuNo + ', event, tier[' + menuNo + ']);" ';
			}
			else {
				temp +='return !showMenu(' + menuNo + ', event);" ';
			}

		// create the div on non NS4 browsers
		} else {
			temp +='<div ';
		}

		// give the layer/div an ID and start the link tag
		temp += ' class="JSMenuLabel' + align + '" width="' + labelWidth + '" id="menuLabel' + menuNo +'">' +
		    '<a href="' + labelURL + '" target="'+ this.targetFrame + '" class="' + this.offClass + '" id="menuLink' + menuNo +'">';

		// bullet point enabled
		if(bullet != null) {
			temp += '<img src="' + eval(bullet + ".URL") +
			    '" border="0" align="' + this.bulletAlign +
			    '" id="menuBullet' + menuNo + '" name="menuBullet' + menuNo +
			    '">';
		}

		// close the link tag
		temp += labelText + '</a>';

		// close the div or layer
		if(browser.ns4) {
			temp += '</layer></ilayer>';
		}
		else {
			temp += '</div>';
		}

		// close the td tag
		temp += '</td>';

		// store the HTML
		this.labelText[this.numLabels] = new String(temp);
	}


	// write the menu-bar
	this.write = function() {

		var oBor = this.oBor;
		var iBor = this.iBor;

		// a div tag for the menu bar so we can position it using CSS
		var menuBarStr = new String();
		menuBarStr += '<div id="' + barName + '"><table border="0" cellpadding="0" cellspacing="0">';

		// side menu
		if (this.orientation == 'vertical') {
			if(oBor != null) {
				menuBarStr += borderRow(oBor, 3);
			}
			for(var count = 0; count < this.numLabels; count++) {
				menuBarStr += this.rowText[count+1];
				if(oBor != null) {
					menuBarStr += borderCell(oBor);
				}
				menuBarStr += this.labelText[count+1];
				if(oBor != null) {
					menuBarStr += borderCell(oBor);
				}
				menuBarStr += '</tr>';
				if(iBor != null && count < (this.numLabels - 1)) {
					if(oBor != null) {
						menuBarStr += '<tr>' + borderCell(oBor) + borderCell(iBor) + borderCell(oBor) + '</tr>';
					}
					else {
						menuBarStr += borderRow(iBor, 1);
					}
				}
			}
			if (oBor != null) {
				menuBarStr += borderRow(oBor, 3);
			}

		// bar menu
		} else {
			if(oBor != null) {
				if(iBor != null) {
					menuBarStr += borderRow(oBor, ((this.numLabels * 2) + 1));
				}
				else {
					menuBarStr += borderRow(oBor, (this.numLabels + 2));
				}
			}
			menuBarStr += '<tr>';
			if(oBor != null) {
				menuBarStr += borderCell(oBor);
			}

			// add the labels
			for(var count = 0; count < this.numLabels; count++) {
				menuBarStr += this.rowText[count + 1];
				menuBarStr += this.labelText[count + 1];
				if(iBor != null && count < (this.numLabels - 1)) {
					menuBarStr += borderCell(iBor);
				}
			}
			if(oBor != null) {
				menuBarStr += borderCell(oBor);
				if (iBor != null) {
					menuBarStr += borderRow(oBor, ((this.numLabels * 2) + 1));
				}
				else {
					menuBarStr += borderRow(oBor, (this.numLabels + 2));
				}
			}
			menuBarStr += '</tr>';
		}

		menuBarStr += '</table></div>';
		document.write(menuBarStr);
	}
}


/* Menu
 *
 *  menuNo        - menu number
 *  menuWidth     - menu width
 *  orientation   - horizontal or vertical
 *  iBor          - inner border colour
 *  oBor          - outer border colour
 */
function Menu(menuNo, menuWidth, orientation, iBor, oBor) {

	// increment internal menu count
	currentMenuNo += 1;
	this.menuNo = menuNo;

	// menu item counter
	this.numItems = 0;

	// borders
	this.iBor = iBor;
	this.oBor = oBor;

	// default height
	this.height = 15;

	// html of the menu items
	this.itemText = new Array();
	this.rowText = new Array();

	// alignment
	this.align = 'left';

	// classes
	this.offClass = 'JSMenuItemLink';
	this.onClass = 'JSMenuItemLinkOn';

	// orientation
	this.orientation = orientation;

	// bullet point alignment (left | right)
	this.bulletAlign = 'left';

	// target type (self | iframe | frame | new)
	this.targetType = 'self';

	// target frame ( _self | _blank | (i)frame name)
	this.targetFrame = '_self';

	/* Add a menu item
	 *
	 *   bullet       - name of bullet, or null
	 *   labelText    - text to appear in the menu-label
	 *   menuNo       - menu number
	 *   labelWidth   - label width (pixels)
	 *   offColour    - background colour of the label's off state
	 *   onColour     - background colour of the label's on state
	 *   labelURL     - menu link URL
	 *   align        - text alignment
	 */
	this.add = function(bullet, itemText, menuNo, itemWidth, offColour, onColour, itemURL, align) {

		// increment internal counter
		this.numItems += 1;

		// create a unique ID for the menu item..
		var tempId = this.menuNo + '_' + this.numItems;

		// if the item pops up a menu
		if(menuNo != null) {
			tier[menuNo]            = tier[this.menuNo] + 1;
			onColours[menuNo]       = onColour;
			offColours[menuNo]      = offColour;
			onClass[menuNo]         = this.onClass;
			offClass[menuNo]        = this.offClass;
			labelBulletName[menuNo] = bullet;
			if(this.oBor != null) {
				borderMod[menuNo] = 1;
			}
			else {
				borderMod[menuNo] = 0;
			}
		}

		// create strings to hold the html for the menu item
		temp = new String('');
		this.rowText[this.numItems] = new String('');

		// if this is a submenu label...
		if(menuNo != null) {
			if(this.orientation =='vertical') {
				this.rowText[this.numItems] += '<tr id="labelRow'+ menuNo + '">';
			}
			temp += '<td id="labelCell'+ menuNo + '" width="'+ itemWidth +
			    '" bgcolor="' + offColour + '" valign="middle" ' +
			    'height="' + this.height + '" ';

		// no sub-menu
		} else {
			if(this.orientation =='vertical') {
				this.rowText[this.numItems] += '<tr>';
			}
			temp += '<td id="itemCell' + tempId + '" width="'+ itemWidth +
			    '" bgcolor="' + offColour + '" valign="middle" height="' +
			    this.height + '" class="JS' + align + 'Menu"';
		}

		// non NS
		if(!browser.ns4) {
			if(menuNo != null) {
				if(this.orientation =='vertical') {
					temp += ' onmouseover="menuOver(); return !showMenuSide(' + menuNo + ', event, tier[' + menuNo + ']); ' +
					    '" onmouseout=" menuOut(); "';
				}
				else {
					temp += ' onmouseover="menuOver(); return !showMenu(' + menuNo + ', event); '+
					'" onmouseout=" menuOut(); "';
				}
			} else {
				temp += ' onmouseover="changeClass(\'menuLink' + tempId + '\',\'' + this.onClass + '\');' +
				    'hideAllMenusTier(tier[' + this.menuNo + ']);' +
				    'menuOver();  ' +
				    'changeBGColour(\'itemCell' + tempId + '\', \'' + onColour + '\'); ' +
				    'changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.onImage\'); " ' +
				    'onmouseout="menuOut(); ' +
				    'changeClass(\'menuLink' + tempId + '\',\'' + this.offClass + '\'); '+
				    'changeBGColour(\'itemCell' + tempId + '\', \'' + offColour + '\'); ' +
				    'changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.offImage\'); "';
			}
		}
		temp += '>';

		// NS4
		if(browser.ns4) {
			temp += '<ilayer><layer ';
			if(menuNo != null) {
				if(this.orientation == 'vertical') {
					temp += 'onmouseover="menuOver(); return !showMenuSide(' + menuNo + ', event, ' +
					    'tier[' + menuNo + ']);" onmouseout="menuOut();"';
				}
				else {
					temp += 'onmouseover="menuOver(); return !showMenu(' + menuNo + ', event);' +
					    '" onmouseout="menuOut();"';
				}
			} else {
				temp += 'onmouseover="hideAllMenusTier(tier[' + this.menuNo + ']); menuOver(); ' +
				    'changeBGColour(\'menuItem' + tempId + '\', \'' + onColour + '\'); ' +
				    'changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.onImage\'); ' +
				    '"onmouseout="menuOut(); changeBGColour(\'menuItem' + tempId + '\', \'' + offColour + '\'); ' +
				    'changeImage(\'menuItemBullet' + tempId + '\', \'' + bullet + '.offImage\'); "';
			}
		} else {
			temp +='<div ';
		}

		// assign class and width
		temp += ' class="JSMenuItem' + align + '" width="' + itemWidth + '"';

		// id
		if(menuNo != null) {
			temp += ' id="menuLabel' + menuNo +'"';
		}
		else {
			temp += ' id="menuItem' + tempId +'"';
		}

		// URL
		temp += '><a href="' + itemURL +'" target="' + this.targetFrame + '" class="' + this.offClass + '"';
		if(menuNo != null) {
			temp += 'id="menuLink' + menuNo +'"';
		}
		else {
			temp += 'id="menuLink' + tempId +'"';
		}
		temp +='>';

		// if bullets are enabled...
		if (bullet != null) {
			if(menuNo != null) {
				temp += '<img src="' + eval(bullet + ".URL") + '" border="0" align="' + this.bulletAlign +
				    '" id="menuBullet' + menuNo + '" name="menuBullet' + menuNo + '">';
			}
			else {
				temp += '<img src="' + eval(bullet + ".URL") + '" border="0" align="' + this.bulletAlign +
				    '" id="menuItemBullet' + tempId + '" name="menuItemBullet' + tempId + '">';
			}
		}

		// close the link element
		temp += itemText + '</a>';

		if(browser.ns4) {
			temp += '</layer></ilayer>';
		}
		else {
			temp += '</div>';
		}

		temp += '</td>';
		this.itemText[this.numItems] = new String(temp);
	}


	// write the menu
	this.write = function() {

		var menuStr = new String();
		oBor = this.oBor;
		iBor = this.iBor;

		// any menu-items
		if(this.numItems == 0) {
			menuType[this.menuNo] = 'blank';
		}
		else {
			menuType[this.menuNo] = 'default';
		}

		// start a DIV element to hold the menu
		menuStr += '<div id="menu' + this.menuNo + '" name="menu' + this.menuNo + '" class="JSMenu" width="' + menuWidth + '"';

		// assign a width (NS4 can choke on "style" attributes)
		if(!browser.ns4) {
			menuStr += ' style="width:' + menuWidth + ';"';
		}

		// start the TABLE that hold the menu
		menuStr+= '><table border="0" cellpadding="0" cellspacing="0" width="' + menuWidth + '">';

		// if it's a vertical menu...
		if(this.orientation == 'vertical') {
			if(oBor != null) {
				menuStr += borderRow(this.oBor, 3);
			}

			// each label
			for(var count = 0; count < this.numItems; count++) {
				menuStr += this.rowText[count+1];
				if(oBor != null) {
					menuStr += borderCell(oBor);
				}
				menuStr += this.itemText[count+1];
				if(oBor != null) {
					menuStr += borderCell(oBor);
				}
				menuStr += '</tr>';
				if(iBor != null && count < (this.numItems - 1)) {
					if(oBor != null) {
						menuStr += '<tr>' + borderCell(oBor) + borderCell(iBor) + borderCell(oBor) + '</tr>';
					}
					else {
						menuStr += borderRow(iBor, 1);
					}
				}
			}
			if(oBor != null) {
				menuStr += borderRow(oBor, 3);
			}

		// horizontal
		} else {
			if(oBor != null) {
				if(iBor != null) {
					menuStr += borderRow(oBor, ((this.numItems * 2) + 1));
				}
				else {
					menuStr += borderRow(oBor, (this.numItems + 2));
				}
			}
			menuStr += '<tr>';
			if(oBor != null) {
				menuStr += borderCell(oBor);
			}
			for(var count = 0; count < this.numItems; count++) {
				menuStr += this.rowText[count+1];
				menuStr += this.itemText[count+1];
				if(iBor != null && count < (this.numItems-1)) {
					menuStr += borderCell(iBor);
				}
			}
			if(oBor != null) {
				menuStr += borderCell(oBor);
				if(iBor != null) {
					menuStr += borderRow(oBor, ((this.numItems * 2) + 1));
				}
				else {
					menuStr += borderRow(oBor, (this.numItems+2));
				}
			}
			menuStr +=  '</tr>';
		}

		// close the table and DIV elements
		menuStr += '</table></div>';

		// write it
		document.write(menuStr);
	}
}


// Bullet Point Object
function BulletPoint(offURL, onURL) {

	this.offImage     = new Image();
	this.offImage.src = offURL;
	this.onImage      = new Image();
	this.onImage.src  = onURL;
	this.URL          = String(offURL);
}



// expand a menu table
function expand_table(name) {

	alterElements('div', 'expanded_' + name, '');
	alterElements('div', 'collapsed_' + name, 'none');

	// set cookie so that the expanded table will be displayed
	set_cookie("expanded_" +name, "Y");
}


// collapse a menu table
function collapse_table(name) {

	alterElements("div", "expanded_" + name, 'none');
	alterElements("div", "collapsed_" + name, '');

	// set cookie so that the collapsed table will be displayed
	set_cookie("expanded_" +name, "N");
}



/*
* Loads up the customer menu preferences; determining whether or
* not particular menu tables specified by parameter 'name' should
* should be expanded/collapsed
*/
function loadCustMenuPrefs(name, default_value) {

	var displayExpandedTable = get_cookie("expanded_"+name);

	if (displayExpandedTable == null) {
		displayExpandedTable= default_value;
	}

	if (displayExpandedTable == "Y") {
		expand_table(name);
	} else {
		collapse_table(name);
	}
}



// Clear login fields
function clearLoginFields(name) {
	var form = document.forms[name];

	form.username.value = "";
	form.pwd.value = "";
}
