///////////////////////////////////////////////////////////
//  PopupMenu Object
///////////////////////////////////////////////////////////
var g_oPopup;
if (navigator.OS == "mac" || navigator.org != "microsoft")
{
	g_oPopup = null;
}
else
{
	g_oPopup = window.createPopup();
}
var g_oCurrentMenu;
function PopupMenu(name)
{
	this.name = name;
	this._oPO = g_oPopup;
	this.items = new Array();
	this.addItem = h_PopupMenu_AddItem;
	this.draw = h_draw;
	h_PopupMenu_InitGlobal();
	return this;
}
function h_PopupMenu_AddItem(text, func)
{
	this.items[this.items.length] = new _PopupItem(text, func, this.name);
}
function h_draw(e)
{
	g_oCurrentMenu = this;
	if (this.items.length > 0)
	{
		var x, y, width, height;
		var oContainerDiv = document.getElementById(this.name);
		if (oContainerDiv == null)
		{
			oContainerDiv = document.createElement("DIV");
			document.appendChild(oContainerDiv);
			oContainerDiv.id = this.name;
			oDiv = document.createElement("DIV");
			oDiv.id = oContainerDiv.id + "_div";
			oContainerDiv.appendChild(oDiv);
			oDiv.className = "popup_border";
			for (var x = 0; x < this.items.length; x++)
			{
				this.items[x].draw(oDiv);
			}
		}
		x = event.offsetX + 15;
		y = event.offsetY;
		width = 100;
		height = (this.items.length * 17) + 4;
		if (this._oPO != null)
		{
			this._oPO.document.body.innerHTML = oContainerDiv.innerHTML;
			var oTarget;
			if (navigator.org == "microsoft")
				oTarget = e.srcElement;
			else
				oTarget = e.target;
			this._oPO.show(x, y, width, height, oTarget);
		}
	}
	return false;
}
function h_PopupMenu_InitGlobal()
{
	if (g_oPopup != null && g_oPopup.document.styleSheets.length < 1)
	{
		var oNewCSS;
		var x;
		var y;
		var selectorText;
		for(x=0; x<document.styleSheets.length; x++)
		{
			oNewCSS = g_oPopup.document.createStyleSheet();
			for (y=0; y<document.styleSheets[x].rules.length; y++)
			{
				if (document.styleSheets[x].rules[y].selectorText.length < 1)
				{
					continue;
					selectorText = "*";  // i'm not copying this rule
				}
				else
				{
					selectorText = document.styleSheets[x].rules[y].selectorText;
				}
				oNewCSS.addRule(selectorText,document.styleSheets[x].rules[y].style.cssText);
			}
		}
		g_oPopup.document.attachEvent("onmouseover", e_PopupHiLite);
		g_oPopup.document.attachEvent("onmouseout", e_PopupNoHiLite);
		g_oPopup.document.attachEvent("onclick", e_onclick);
	}
}
///////////////////////////////////////////////////////////
//  _PopupItem Object - should only be used within this file
///////////////////////////////////////////////////////////
function _PopupItem(text, func, owner)
{
	this.text = text;
	this.func = func;
	this.name = owner.name + "_" + this.text;
	this.draw = h_drawItem;
	return this;
}
function h_drawItem(oDiv)
{
	oItem = document.createElement("DIV");
	oItem.id = this.name;
	oItem.className = "popup_nohighlite";
	oItem.innerText = this.text;
	oDiv.appendChild(oItem);
}
function e_PopupHiLite(e)
{
	var strName = new String();
	var oTarget;
	if (navigator.org == "microsoft")
		oTarget = e.srcElement;
	else
		oTarget = e.target;
	strName = oTarget.id
	if (strName.substr(strName.length - 4, strName.length) != "_div")
		oTarget.className = "popup_highlite";
}
function e_PopupNoHiLite(e)
{
	var strName = new String();
	var oTarget;
	if (navigator.org == "microsoft")
		oTarget = e.srcElement;
	else
		oTarget = e.target;
	strName = oTarget.id
	if (strName.substr(strName.length - 4, strName.length) != "_div")
		oTarget.className = "popup_nohighlite";
}
function e_onclick(e)
{
	var x;
	var oTarget;
	if (navigator.org == "microsoft")
		oTarget = e.srcElement;
	else
		oTarget = e.target;
	for (x = 0; x < g_oCurrentMenu.items.length; x++)
	{
		if (g_oCurrentMenu.items[x].name == oTarget.id)
		{
			g_oCurrentMenu.items[x].func(e);
			break;
		}
	}
	return false;
}
