// Browser detection
var ie5 = (document.all && document.getElementById) ? 1 : 0;
var ns6 = (document.getElementById && !document.all) ? 1 : 0;
var is_fx = ((navigator.vendor=="Firefox"));
if (is_fx) ns6 = 1;

var leftX = 0, rightX = 0, topX = 0, bottomX = 0;
var leftY = 0, rightY = 0, topY = 0, bottomY = 0;
var lastMenu = null;
var windowstatus;

window.onerror = new Function("return true")

function showSubMenu(objMainMenuItem) {
	var objSubMenu;
	objSubMenu = document.getElementById(objMainMenuItem.id + "_submenu");

    if (lastMenu != null && lastMenu != objSubMenu) hideAll();
    leftX = calculateSumOffset(objMainMenuItem, 'offsetLeft');
    topX = calculateSumOffset(objMainMenuItem, 'offsetTop');
    rightX = leftX + objMainMenuItem.offsetWidth;
    bottomX = topX + objMainMenuItem.offsetHeight;

    objSubMenu.style.left = rightX;
    objSubMenu.style.top  = topX;
    objSubMenu.style.visibility = "visible";
    
	leftY = rightX;
	topY = topX;
	rightY = leftY + objSubMenu.offsetWidth;
    bottomY = topY + objSubMenu.offsetHeight;

	lastMenu = objSubMenu;
}

function calculateSumOffset(objItem, offsetName) {
	var totalOffset = 0;
	var item = objItem;
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

function hideAll() {
	if (lastMenu != null) {
		lastMenu.style.visibility = "hidden";
		lastMenu.style.left = 0;
	}
}

function init() {
	if (ie5) {
		document.body.onscroll=hideAll;
		document.body.onmousemove=updateIt;
	}
	if (ns6) {
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove=updateIt;
	}
}

function updateIt(e) {
	if (ie5) {
		var x = document.body.scrollLeft + window.event.clientX;
		var y = document.body.scrollTop + window.event.clientY;
		if (( x > rightX || x < leftX || y > bottomX || y < topX ) && (x > rightY || x < leftY || y > bottomY || y < topY )) hideAll();
	}
	if (ns6) {
		var x = e.pageX;
		var y = e.pageY;
		if (( x > rightX || x < leftX || y > bottomX || y < topX ) && (x > rightY || x < leftY || y > bottomY || y < topY )) hideAll();
	}
}

function createSubMenu(name, menuItems) {
	var menuStr = '<div id="' + name + '" class="level2menu">\n';
	if (ie5) {
		menuStr += '<table border="0" width="100%" cellspacing="0" cellpadding="5">\n';
		for (var i = 0; i < menuItems.length; i++) {
			menuStr += '<tr><td class="level2menu" onmouseover="moverc(this,\'' + menuItems[i].statusline + '\');"  onmouseout="moutc(this);" onclick="gotoUrl(\'' + menuItems[i].hyperlink + '\');">' + menuItems[i].text + '</td></tr>\n'
		}
		menuStr += '</table>\n';
	} else {
		menuStr += '<ul id="nav">\n';
		for (var i=0; i < menuItems.length; i++) {
			menuStr += '<li><a href="' + menuItems[i].hyperlink + '" >' + menuItems[i].text + '</a></li>\n';
		}
		menuStr += '</ul>\n';
	}
	menuStr += '</div>\n';
	document.write(menuStr); 
}

// Define a menuItem object.
function menuItem(strText, strStatusLine, strHyperlink) {
	this.text = strText;
	this.statusline = strStatusLine;
	this.hyperlink = strHyperlink;
}

function moverc(cellobj,sStatusText) { 
	cellobj.className = 'level2menu_on';
	window.status = sStatusText;
	return true;	
}
function moutc(cellobj) { 
	cellobj.className = 'level2menu';
	window.status = '';
	return true;
}

function gotoUrl(strURL){
	document.location = strURL;
	return true;
}

function showCode(sCode) {
	var sHTML;
	sHTML = "<div style='position:absolute; top:0; left: 0; width: 400'>\n";
	sHTML += "<textarea rows='39' name='jscode' cols='88'>" + sCode + "</textarea>\n</div>";
	document.write(sHTML);
}
