var NS4_MT = (document.layers) ? true : false;
var IE4_MT = (document.getElementById) ? true : false;

var style_MT = true; //((NS4_MT && document.test) || IE4_MT) ? 1 : 0;
var padding_MT = 0; // < 4 recommended
var borWid_MT = null; // for no border, assign null
var borCol_MT = "white";
var borSty_MT = "solid";
var nTimout_MT = 0; // seconds

var str = "<style TYPE='text/css'>";
str += ".menutip {";
str += "position: absolute;";
str += "visibility: hidden;";
str += "left: 0; top: 0;";
if (borWid_MT > 0)
{ // if a border is specified
	str += "border-width: " + borWid_MT + ";";
	str += "border-color: " + borCol_MT + ";";
	str += "border-style: " + borSty_MT + ";";
}
if (NS4_MT)
{
	if (borWid_MT > 0 && padding_MT <= 3)
	{
		str += "padding: 0;";
	}
	else if (borWid_MT > 0 && padding_MT > 3)
	{
		str += "padding: " + (padding_MT - 3) + ";";
	}
	else if (borWid_MT == 0)
	{
		str += "padding: " + padding_MT + ";";
	}
}
else
{
	str += "padding: " + padding_MT + ";";
}
str += "}";
str += "</style>";

if (style_MT)
{
	document.write(str);
	if (NS4_MT)
		window.onload = init_MT;
}

function init_MT()
{
	setTimeout("window.onresize = redo_MT", 1000);
}

function redo_MT()
{
	window.location.reload();
}

function oMenu(strID, nX, nY, bPersistent)
{
	this.strID = strID; // id of menu
	this.nX = nX; // x location (0 uses mouse position)
	this.nY = nY; // y location (0 uses mouse position)
	this.bPersistent = bPersistent; // keep it up or have it go away
	this.bActive = false; // active ?
	this.nTimeout = 0; // timeout delay
}
var aMenus = new Array();

function SetTimeout(id, nTimeoutVal)
{
	var oTimoutObj = FindMenuObject(id);
	if (oTimoutObj)
		oTimoutObj.nTimeout = nTimeoutVal;
}

function SetPersistent(id, bPersistentVal)
{
	var oPersistentObj = FindMenuObject(id);
	if (oPersistentObj)
		oPersistentObj.bPersistent = bPersistentVal;
}

function FindMenuObject(strID)
{
	for (var iMenu = 0; iMenu < aMenus.length; ++iMenu)
		if (aMenus[iMenu].strID == strID)
			return aMenus[iMenu];
	return null;
}

function makeMenu(id, code, x, y, bPersistent)
{
	if (!style_MT)
		return;
		
	// force it to boolean
	bPersistent = bPersistent ? true : false;
		
	aMenus[aMenus.length] = new oMenu(id, x, y, bPersistent);
		
	var str = "<style TYPE='text/css'>";
	str += "#" + id + " {";
	str += "}";
	str += "</style>";
	str += "<DIV CLASS='menutip' ID='" + id + "' align='left' valign='bottom'>" +
		code + "</DIV>";
	document.write(str);
}

function activateMenu(id) 
{
	var oActiveMenu = FindMenuObject(id);

	// Clear any existing...
//	clearMenu();

	if (!oActiveMenu)
		return;
	if (!(NS4_MT || IE4_MT))
		return;
	if (!style_MT)
		return;
	if (!((NS4_MT) ? document[oActiveMenu.strID] : document.getElementById(oActiveMenu.strID)))
		return;

	if (!oActiveMenu.bActive)
	{
		oActiveMenu.bActive = true;
		oActiveMenu.nTimeout = nTimout_MT;
	
		var whichMenu = (NS4_MT) ? document[oActiveMenu.strID] : document.getElementById(oActiveMenu.strID).style;
		if (!oActiveMenu.nX || (oActiveMenu.nX == 0)) // cursor location
			whichMenu.left = (NS4_MT) ? event.pageX : event.clientX + document.body.scrollLeft;
		else
			whichMenu.left = oActiveMenu.nX;
		if (!oActiveMenu.nY || (oActiveMenu.nY == 0)) // cursor location
			whichMenu.top = (NS4_MT) ? event.pageY : event.clientY + document.body.scrollTop;
		else
			whichMenu.top = oActiveMenu.nY;
		whichMenu.visibility = (NS4_MT) ? "show" : "visible";
	}
}

function clearMenu(idToClear) 
{
	var oClearMenu = idToClear ? FindMenuObject(idToClear) : null;

	if (!style_MT) // ???
		return;

	// can't be null
//	if (oClearMenu != null)
//		return;
	// todo: check for null 'not clears'
		
	// ID valid on page?	
	if (oClearMenu && !((NS4_MT) ? document[oClearMenu.strID] : document.getElementById(oClearMenu.strID)))
		return;
	// todo: check for valid 'not clears'

	// ignore if a menu was stated and it is not active
	if (oClearMenu && !oClearMenu.bActive)
		return;

	if (oClearMenu && oClearMenu.bActive)
	{
			var whichMenu = (NS4_MT) ? document[oClearMenu.strID] : document.getElementById(oClearMenu.strID).style;
			whichMenu.visibility = (NS4_MT) ? "hide" : "hidden";
			oClearMenu.bActive = false;
	}

	if (!oClearMenu)
	{
		// Go through all menu items and adjust based on properties.
		for (var iMenu = 0; iMenu < aMenus.length; ++iMenu)
		{
			// skip menu(s) set not to clear
			var bFound = false;
			for (var iItem = 0; iItem < aoNotClearMenus.length; ++iItem)
			{
//alert(aMenus[iMenu].strID + "==" + aoNotClearMenus[iItem].strID)
				if(aMenus[iMenu].strID == aoNotClearMenus[iItem].strID)
				{
			 		bFound = true;
					break;
				}
			}
			if (bFound)
				continue;
				
			// clear the menu
			aMenus[iMenu].bActive = false;
			var whichMenu = (NS4_MT) ? document[aMenus[iMenu].strID] : document.getElementById(aMenus[iMenu].strID).style;
			whichMenu.visibility = (NS4_MT) ? "hide" : "hidden";
		}
	}
}

function CheckToClear()
{
	for (var iMenu = 0; iMenu < aMenus.length; ++iMenu)
	{
		if (aMenus[iMenu].bActive && !aMenus[iMenu].bPersistent)
		{
			if (aMenus[iMenu].nTimeout > 0)
				--aMenus[iMenu].nTimeout;
			else
				clearMenu(aMenus[iMenu].strID);
		}
	}
}
setInterval("CheckToClear()", 1000);