//***********************************************************************
//Javascript popup menu																									*
//Author: Huy Tran																											*
//Date: 01/20/2006																											*
//***********************************************************************
//
//=======================================================================
var __timerId = -1;
var __mover = true;
var __Zindex = 1000;
var __timeCloseMenu = 1000; //millisections
var __lastRM = null;
function Menu(elId){
	this.parent = null;
	this.iframe = null;
	this.subdivTb = null;
	this.subdiv = null;
	this.children = new Array();
	this.subX = 0;
	this.subY = 0;
	this.horVer = 2; //default to vertical menu
	this.x = -1;
	this.y = -1;
	this.height = 0;
	this.bg_color = "white";
	//this.border_color = "#666666";
	this.loadAll = false;
	this.onMenuClose = null;  //callBackFunc
	this.onMenuCloseArgs = null;
	this.onMenuOpen = null;
	this.onMenuOpenArgs = null;
	this.onRootMenuOver = null;
	this.onRootMenuOverArgs = null;
	this.onRootMenuOut = null;
	this.onRootMenuOutArgs = null;
	
	this.rootEl = Menu.FindObj(elId);
	if(this.rootEl == null){
		alert("Can't find object " + elId + " to create menu");
		return;
	}
	
	this.rootEl.menu = this;
	Menu.AddEvent(this.rootEl, "mouseover", Menu.DoRootMenuOver);
	Menu.AddEvent(this.rootEl, "mouseout", Menu.DoRootMenuOut);
	
	//privilege methods====================================
	this.BuildMenu = function(isInherit){
		this.loadAll = isInherit;
		var zi = Menu.GetZIndex();
		var tb = Menu.CreateElement("table");
		tb.id = "mtb_" + zi;
		tb.border = 0;
		tb.cellPadding = 0;
		tb.cellSpacing = 0;
		tb.style.borderCollapse = "collapse";
		tb.style.borderWidth = "1px";
		tb.style.borderStyle = "solid";
		tb.style.borderColor = this.children[0].border_color;
		//tb.style.borderColor = this.border_color;
		
		var tbody = Menu.CreateElement("tbody", tb);

		for(var i=0; i<this.children.length; i++){
			if(this.children[i].text == "" && this.children[i].url == ""){	//separator
				var row = Menu.CreateElement("tr", tbody);
				var cell1 = Menu.CreateElement("td", row);
				cell1.colSpan = 3;
				var sep = "<hr width='95%' align=center";
				if(this.children[i].css != ""){
					cell1.className = this.children[i].css;
					cell1.innerHTML = sep + " class='" + this.children[i].css + "'>";
				}
				else{
					cell1.innerHTML = sep + ">";
				}
			}
			else{
				var row = Menu.CreateElement("tr", tbody);
				row.vAlign = "center";
				var cell0 = Menu.CreateElement("td", row);
				cell0.menu = this.children[i];
				cell0.id = "mTD0_" + i + "_" + zi;
				if(this.children[i].icon != ""){
					cell0.innerHTML = "<img src='" + this.children[i].icon + "' border=0>";
				}
				else{
					cell0.innerHTML = "";
				}
				if(this.children[i].css != "") cell0.className = this.children[i].css;
				Menu.AddEvent(cell0, "mouseover", Menu.DoMenuOver);
				Menu.AddEvent(cell0, "mouseout", Menu.DoMenuOut);
				if(this.children[i].url != ""){
					Menu.AddEvent(cell0, "click", Menu.DoMenuClick);
				}

				var cell1 = Menu.CreateElement("td", row);
				cell1.menu = this.children[i];
				cell1.id = "mTD1_" + i + "_" + zi;
				cell1.noWrap = true;
				if(this.children[i].css != "") cell1.className = this.children[i].css;
				cell1.innerHTML = this.children[i].text;
				Menu.AddEvent(cell1, "mouseover", Menu.DoMenuOver);
				Menu.AddEvent(cell1, "mouseout", Menu.DoMenuOut);
				if(this.children[i].url != ""){
					Menu.AddEvent(cell1, "click", Menu.DoMenuClick);
				}
				var cell2 = Menu.CreateElement("td", row);
				cell2.menu = this.children[i];
				cell2.id = "mTD2_" + i + "_" + zi;
				cell2.noWrap = true;
				cell2.align = "right";
				if(this.children[i].css != "") cell2.className = this.children[i].css;
				if(this.children[i].HasChildren()){
					cell2.innerHTML = this.children[i].submenuText;
				}
				else{
					cell2.innerHTML = "";
				}
				Menu.AddEvent(cell2, "mouseover", Menu.DoMenuOver);
				Menu.AddEvent(cell2, "mouseout", Menu.DoMenuOut);
				if(this.children[i].url != ""){
					Menu.AddEvent(cell2, "click", Menu.DoMenuClick);
				}
			}
		}

		this.subdivTb = tb;
		this.subdiv = Menu.CreateDiv("mDiv_" + zi);
		this.subdiv.style.backgroundColor = this.children[0].bg_color;
		this.subdiv.appendChild(tb);
		
		this.iframe = Menu.CreateIFrame();
		this.subdiv.style.display = "block";
		this.iframe.style.width = tb.offsetWidth + "px";
		this.iframe.style.height = tb.offsetHeight + "px";
		
		var rows = null;
		if(tb.childNodes[0].tagName.toUpperCase() == "TR"){
			rows = tb.childNodes;
		}
		else{
			rows = tb.childNodes[0].childNodes;
		}
		var h = 0;
		for(var i=0; i<rows.length; i++){
			this.children[i].height = h;
			h += rows[i].offsetHeight;
		}
		this.subdiv.style.display = "none";

		//cal display position
		if(this.horVer == 2){	//vertical
			this.x = Menu.FindOffsetLeft(this.rootEl) + this.subX;
			this.y = Menu.FindOffsetTop(this.rootEl) + this.rootEl.clientHeight + this.subY;
		}
		else{	//horizontal
			this.x = Menu.FindOffsetLeft(this.rootEl) + this.rootEl.clientWidth + this.subX;
			this.y = Menu.FindOffsetTop(this.rootEl) + this.subY;
		}
		this.subdiv.style.left = this.x + "px";
		this.iframe.style.left = this.x + "px";
		this.subdiv.style.top = this.y + "px";
		this.iframe.style.top = this.y + "px";

		if(isInherit){
			for(var i=0; i<this.children.length; i++){
				if(this.children[i].HasChildren()){
					this.children[i].BuildMenu(isInherit);
				}
			}
		}

	};
};//end function Menu

Menu.prototype.SetOnMenuClose = function(callBackFunc, callBackFuncArgs){
	this.onMenuClose = callBackFunc;
	this.onMenuCloseArgs = callBackFuncArgs;
};
Menu.prototype.SetOnMenuOpen = function(callBackFunc, callBackFuncArgs){
	this.onMenuOpen = callBackFunc;
	this.onMenuOpenArgs = callBackFuncArgs;
};
Menu.prototype.SetOnRootMenuOver = function(callBackFunc, callBackFuncArgs){
	this.onRootMenuOver = callBackFunc;
	this.onRootMenuOverArgs = callBackFuncArgs;
};
Menu.prototype.SetOnRootMenuOut = function(callBackFunc, callBackFuncArgs){
	this.onRootMenuOut = callBackFunc;
	this.onRootMenuOutArgs = callBackFuncArgs;
};
Menu.prototype.Close = function(){
	Menu.Close(this, true);
};
Menu.prototype.SetGroupBgColor = function(color){
	for(var i=0; i<this.children.length; i++){
		this.children[i].SetGroupBgColor(color, true);
	}
};
Menu.prototype.SetGroupBorderColor = function(color){
	for(var i=0; i<this.children.length; i++){
		this.children[i].SetGroupBorderColor(color, true);
	}
};
Menu.prototype.SetDirectionFromRoot = function(num){
	if(typeof(num) == "number" && (num == 1 || num == 2)){
		this.horVer = num;
	}
	else{
		alert("Invalid param for SetDirectionFromRoot");
	}
};
Menu.prototype.SetCss = function(css){
	for(var i=0; i<this.children.length; i++){
		this.children[i].SetCss(css, true);
	}
};
Menu.prototype.SetOverCss = function(css){
	for(var i=0; i<this.children.length; i++){
		this.children[i].SetOverCss(css, true);
	}
};
Menu.prototype.AddChildren = function(){
	for(var i=0; i<arguments.length; i++){
		this.children.push(arguments[i]);
		arguments[i].parent = this;
	}
};
Menu.prototype.Display = function(){
	if(this.subdiv == null) this.BuildMenu(this.loadAll);
	if(Menu.IEBrowser()) this.iframe.style.display = "block";
	this.subdiv.style.display = "block";
	if(__lastRM != null) __lastRM.ResetCss();
	return false;
};
Menu.prototype.SetCloseMenuTime = function(msec){
	if(typeof(msec) == "number")
	  __timeCloseMenu = msec;
};
Menu.prototype.IsOpen = function(){
  if(this.children == null) return false;
  for(var i=0; i<this.children.length; i++){
	  if(this.children[i].IsOpen()){
	    return true;
	  }
	}
	return false;
};
//=======================================================

//=======================================================
//MenuItem(txt, url)
//MenuItem(txt, url, newWD)
//MenuItem(txt, url, newWD, parent)
function MenuItem(){
	this.children = null;
	this.parent = null;
	this.subdiv = null;
	this.iframe = null;
	this.subdivTb = null;
	this.x = -1;
	this.y = -1;
	this.height = 0; 
	////////////////////////
	this.subX = 0;
	this.subY = 0;
	this.text = "";
	this.url = "";
	this.newWD = false;
	this.newWdOptions = "";
	this.submenuText = "&#x00bb;";
	this.css = "";
	this.overCss = "";
	this.bg_color = "white";
	this.icon = "";
	this.border_color = "#666666";
	
	if(arguments[0] != null) this.text = arguments[0];
	if(arguments[1] != null) this.url = arguments[1];
	if(arguments[2] != null) this.newWD = arguments[2];
	if(arguments[3] != null){
		this.parent = arguments[3];
		arguments[3].AddChildren(this);
	}

	//privilege methods====================================
	this.BuildMenu = function(isInherit){
		
		var zi = Menu.GetZIndex();
		var tb = Menu.CreateElement("table");
		tb.id = "mtb_" + zi;
		tb.border = 0;
		tb.cellPadding = 0;
		tb.cellSpacing = 0;
		
		tb.style.borderColor = this.children[0].border_color;
		tb.style.borderCollapse = "collapse";
		tb.style.borderWidth = "1px";
		tb.style.borderStyle = "solid";
		
		var tbody = Menu.CreateElement("tbody", tb);

		for(var i=0; i<this.children.length; i++){
			if(this.children[i].text == "" && this.children[i].url == ""){	//separator
				var row = Menu.CreateElement("tr", tbody);
				var cell1 = Menu.CreateElement("td", row);
				cell1.colSpan = 3;
				
				var sep = "<hr width='95%' size=1 align=center";
				if(this.children[i].css != ""){
					cell1.className = this.children[i].css;
					cell1.innerHTML = sep + " class='" + this.children[i].css + "'>";
				}
				else{
					cell1.innerHTML = sep + ">";
				}
			}
			else{
				var row = Menu.CreateElement("tr", tbody);
				row.vAlign = "center";
				var cell0 = Menu.CreateElement("td", row);
				cell0.menu = this.children[i];
				cell0.id = "mTD0_" + i + "_" + zi;
				if(this.children[i].icon != ""){
					cell0.innerHTML = "<img src='" + this.children[i].icon + "' border=0>";
				}
				else{
					cell0.innerHTML = "";
				}
				if(this.children[i].css != "") cell0.className = this.children[i].css;
				Menu.AddEvent(cell0, "mouseover", Menu.DoMenuOver);
				Menu.AddEvent(cell0, "mouseout", Menu.DoMenuOut);
				if(this.children[i].url != ""){
					Menu.AddEvent(cell0, "click", Menu.DoMenuClick);
				}
				var cell1 = Menu.CreateElement("td", row);
				cell1.menu = this.children[i];
				cell1.id = "mTD1_" + i + "_" + zi;
				cell1.noWrap = true;
				if(this.children[i].css != "") cell1.className = this.children[i].css;
				cell1.innerHTML = this.children[i].text;
				Menu.AddEvent(cell1, "mouseover", Menu.DoMenuOver);
				Menu.AddEvent(cell1, "mouseout", Menu.DoMenuOut);
				if(this.children[i].url != ""){
					Menu.AddEvent(cell1, "click", Menu.DoMenuClick);
				}
				var cell2 = Menu.CreateElement("td", row);
				cell2.menu = this.children[i];
				cell2.id = "mTD2_" + i + "_" + zi;
				cell2.noWrap = true;
				cell2.align = "right";
				if(this.children[i].css != "") cell2.className = this.children[i].css;
				if(this.children[i].HasChildren()){
					cell2.innerHTML = this.children[i].submenuText;
				}
				else{
					cell2.innerHTML = "";
				}
				Menu.AddEvent(cell2, "mouseover", Menu.DoMenuOver);
				Menu.AddEvent(cell2, "mouseout", Menu.DoMenuOut);
				if(this.children[i].url != ""){
					Menu.AddEvent(cell2, "click", Menu.DoMenuClick);
				}
			}
		}

		this.subdivTb = tb;
		this.subdiv = Menu.CreateDiv("mDiv_" + zi);
		this.subdiv.style.backgroundColor = this.children[0].bg_color;
		this.subdiv.appendChild(tb);
		
		this.iframe = Menu.CreateIFrame();
		this.subdiv.style.display = "block";
		this.iframe.style.width = tb.offsetWidth + "px";
		this.iframe.style.height = tb.offsetHeight + "px";
		
		var rows = null;
		if(tb.childNodes[0].tagName.toUpperCase() == "TR"){
			rows = tb.childNodes;
		}
		else{
			rows = tb.childNodes[0].childNodes;
		}
			
		var h = 0;
		for(var i=0; i<rows.length; i++){
			this.children[i].height = h;
			h += rows[i].offsetHeight;
		}
		h += this.parent.y;
		this.subdiv.style.display = "none";
		
		//cal display position
		this.x = this.parent.x + parseInt(this.parent.iframe.style.width.replace(/px/i, "")) + this.subX;
		this.y = this.parent.y + this.height + this.subY;
		this.subdiv.style.left = this.x + "px";
		this.iframe.style.left = this.x + "px";
		this.subdiv.style.top = this.y + "px";
		this.iframe.style.top = this.y + "px";
		
		if(isInherit)
		{
			for(var i=0; i<this.children.length; i++){
				if(this.children[i].HasChildren())
					this.children[i].BuildMenu(isInherit);
			}
		}
		
	};
	
};//end MenuItem

//===============
MenuItem.prototype.IsOpen = function(){
  
  if(this.subdiv != null && !this.subdiv.style.display.match(/none/i)) return true;
  
  if(this.children != null){
    for(var i=0; i<this.children.length; i++){
	    if(this.children[i].IsOpen()){
	      return true;
	    }
	  }
	}
	return false;
}
MenuItem.prototype.AddChildren = function(){
	if(this.children == null){
		this.children = new Array();
	}
	
	for(var i=0; i<arguments.length; i++){
		this.children.push(arguments[i]);
		arguments[i].SetParent(this);
	}
};
MenuItem.prototype.HasChildren = function(){
	if(this.children != null)
		return true;
	else
		return false;
};
MenuItem.prototype.SetGroupBgColor = function(color, isInherit){
	for(var i=0; i<this.parent.children.length; i++){
		this.parent.children[i].bg_color = color;
		if(isInherit && this.parent.children[i].children != null){
			for(var k=0; k<this.parent.children[i].children.length; k++){
				this.parent.children[i].children[k].SetGroupBgColor(color, isInherit);
			}
		}
	}
};
MenuItem.prototype.SetGroupBorderColor = function(color, isInherit){
	for(var i=0; i<this.parent.children.length; i++){
		this.parent.children[i].border_color = color;
		if(isInherit && this.parent.children[i].children != null){
			for(var k=0; k<this.parent.children[i].children.length; k++){
				this.parent.children[i].children[k].SetGroupBorderColor(color, isInherit);
			}
		}
	}
};
MenuItem.prototype.SetGroupSubX = function(x, isInherit){
	if(this.parent.parent == null){
		this.parent.subX = x;
	}
	else{
		for(var i=0; i<this.parent.parent.children.length; i++){
			this.parent.parent.children[i].subX = x;
		}
	}

	if(isInherit && this.HasChildren())
		this.children[0].SetGroupSubX(x, isInherit);
};
MenuItem.prototype.SetGroupSubY = function(y, isInherit){
	if(this.parent.parent == null){
		this.parent.subY = y;
	}
	else{
		for(var i=0; i<this.parent.parent.children.length; i++){
			this.parent.parent.children[i].subY = y;
		}
	}
	
	if(isInherit && this.HasChildren())
		this.children[0].SetGroupSubY(y, isInherit);
};
MenuItem.prototype.SetSubmenuText = function(smTxt, isInherit){
	this.submenuText = smTxt;
	if(isInherit && this.children != null){
		for(var i=0; i<this.children.length; i++){
			this.children[i].SetSubmenuText(smTxt, isInherit);
		}
	}
};
MenuItem.prototype.SetCss = function(css, isInherit){
	this.css = css;
	if(isInherit && this.children != null){
		for(var i=0; i<this.children.length; i++){
			this.children[i].SetCss(css, isInherit);
		}
	}
};
MenuItem.prototype.SetOverCss = function(css, isInherit){
	this.overCss = css;
	if(isInherit && this.children != null){
		for(var i=0; i<this.children.length; i++){
			this.children[i].SetOverCss(css, isInherit);
		}
	}
};
MenuItem.prototype.SetNewWindow = function(bool){
	this.newWD = bool;
};
MenuItem.prototype.SetParent = function(parent){
	this.parent = parent;
};
MenuItem.prototype.SetText = function(txt){
	this.text = txt;
};
MenuItem.prototype.SetURL = function(url){
	this.url = url;
};
MenuItem.prototype.SetNewWdOptions = function(options){
	this.newWdOptions = options;
};
MenuItem.prototype.SetIcon = function(iconPath){
	this.icon = iconPath;
};
MenuItem.prototype.Display = function(){
	if(this.parent != null) 
		this.parent.Display();
};
MenuItem.prototype.ResetCss = function(){
	var rows = null;
	if(__lastRM.parent.subdivTb.childNodes[0].tagName.toUpperCase() == "TR")
		rows = __lastRM.parent.subdivTb.childNodes;
	else
		rows = __lastRM.parent.subdivTb.childNodes[0].childNodes;
	
	for(var i=0; i<rows.length; i++){
		var _m = rows[i].childNodes[0].menu;
		if(typeof(_m) != "undefined" && _m.css != ""){
			rows[i].childNodes[0].className = _m.css;
			rows[i].childNodes[1].className = _m.css;
			rows[i].childNodes[2].className = _m.css;
		}
	}
};
MenuItem.prototype.SetCloseMenuTime = function(msec){
	if(typeof(msec) == "number")
	  __timeCloseMenu = msec;
};

//====================
Menu.IEBrowser = function(){
	if(navigator.userAgent.indexOf("MSIE") >= 0){
		return true;
	}
	else{
		return false;
	}
};
Menu.GetZIndex = function(){
	var ret = __Zindex;
	__Zindex++;
	return ret;
};
Menu.CreateDiv = function(divId){
	var div = Menu.CreateElement("DIV");
	div.id = divId;
	div.style.zIndex = __Zindex;	//Menu.GetZIndex;
	div.style.display = "none";
	div.style.position = "absolute";
	
	if(typeof(document.forms) != "undefined"){
		return document.forms[0].appendChild(div);
	}
	else{
		return document.body.appendChild(div);
	}
};
Menu.CreateIFrame = function(){
	var iframeEl = Menu.CreateElement("IFRAME");
	//iframeEl.id = elId + "_mFrame";
	iframeEl.frameBorder = 0;
	iframeEl.src = "javascript:;";
	iframeEl.style.display = "none";
	iframeEl.style.position = "absolute";
	//iframeEl.allowTransparency = false;
	iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
	return document.body.appendChild(iframeEl);
};
Menu.AddEvent = function(el, evname, func){
	if (el.attachEvent){
		el.attachEvent("on" + evname, func);
	}
	else if (el.addEventListener){
		el.addEventListener(evname, func, true);
	}
	else{
		el["on" + evname] = func;
	}
};
Menu.CreateElement = function(elementType, parent){
	var el = null;
	el = document.createElement(elementType);
	if (typeof(parent) != "undefined"){
		parent.appendChild(el);
	}
	return el;
};
Menu.GetEventSrc = function(ev){
	var evSrc = null;
	if(navigator.userAgent.indexOf("MSIE") >= 0){
		evSrc = window.event.srcElement;
	}
	else{
		evSrc = ev.currentTarget;
	}
		
	return evSrc;
};
Menu.FindObj = function(id){
	if(document.all){
		return document.all[id];
	}
	else{
		return document.getElementById(id);
	}
};
Menu.FindOffsetLeft = function(obj, toObjId){
	var offsetLeft = 0;
	while(obj != null){
		if(arguments.length > 1 && obj.id == toObjId) break;
		
		//if(obj.id == toObjId) break;

		//skip DIV objects
		if(!obj.tagName.match(/div/i)){
			offsetLeft += obj.offsetLeft;
		}

		if(document.all){
			obj = obj.parentElement;
		}
		else{
			obj = obj.parentNode;
		}
			
		if(obj.tagName.match(/(form)|(body)|(html)/i) && !obj.tagName.match(/tbody/i)) break;
	}
	
	return offsetLeft;
};
Menu.FindOffsetTop = function(obj, toObjId){
	var offsetTop = 0;
	while(obj != null){
		if(arguments.length > 1 && obj.id == toObjId) break;

		//if(obj.id == toObjId) break;
		
		//skip DIV and TR objects
		if(!obj.tagName.match(/div/i) && !obj.tagName.match(/tr/i)){
			offsetTop += obj.offsetTop;
		}

		if(document.all){
			obj = obj.parentElement;
		}
		else{
			obj = obj.parentNode;
		}

		if(obj.tagName.match(/(form)|(body)|(html)/i) && !obj.tagName.match(/tbody/i)) break;
	}
	
	return offsetTop;
};
Menu.FindRoot = function(menu){
	if(menu == null || typeof(menu) != "object") return null;
	while(menu.parent != null){
		menu = menu.parent;
	}
	return menu;
};
Menu.GetMenuEvSrc = function(evSrc){
	var ret = null;
	if(typeof(evSrc.menu) != "undefined"){
		ret = evSrc;
	}
	else{
		while(evSrc.parentNode != null){
			evSrc = evSrc.parentNode;
			if(typeof(evSrc.menu) != "undefined"){
				ret = evSrc;
				break;
			}
		}
	}
	return ret;
};
Menu.Close = function(menu, isInherit){
	if(menu.subdiv != null){
		menu.subdiv.style.display = "none";
		if(menu.iframe != null) menu.iframe.style.display = "none";
	}
	
	if(isInherit){
		for(var i=0; i<menu.children.length; i++){
			if(menu.children[i].HasChildren()){
				Menu.Close(menu.children[i], isInherit);
			}
		}
	}
};
Menu.Open = function(menu){
	if(Menu.IEBrowser() && menu.iframe != null) menu.iframe.style.display = "block";
	menu.subdiv.style.display = "block";
	if(menu.parent != null) Menu.Open(menu.parent);
	
	var root = Menu.FindRoot(__lastRM);
	if(root != null && root.onMenuOpen != null){
	  root.onMenuOpen.apply(this, root.onMenuOpenArgs);
	}
};
Menu.Navigate = function(url, isNewWd, options){
	if(isNewWd){
	  if(options.length > 0){
		  window.open(url, "_newWd", options);
		 }
		else
		  window.open(url, "_newWd");
	}
	else{
		window.location.href = url;
	}
};

//handle event==================
Menu.DoRootMenuOver = function(ev){
	var evSrc = Menu.GetEventSrc(ev);
	evSrc.style.cursor = "pointer";

	__mover = true;
	evSrc = Menu.GetMenuEvSrc(evSrc);
	var m = evSrc.menu;	
	if(m != null){
		Menu.HideAllExcept(m);
		m.Display();
  	clearTimeout(__timerId);

	  if(m.onRootMenuOver != null){
	    m.onRootMenuOver.apply(this, m.onRootMenuOverArgs);
	  }
	}
	//window.status = "DoRootMenuOver";
};
Menu.DoRootMenuOut = function(ev){  
	__mover = false;
 	__timerId = setTimeout("Menu.HideAll()", __timeCloseMenu);

	var evSrc = Menu.GetEventSrc(ev);
	evSrc = Menu.GetMenuEvSrc(evSrc);
	var m = evSrc.menu;	
	if(m.onRootMenuOut != null){
	  m.onRootMenuOut.apply(this, m.onRootMenuOutArgs);
	}
	//window.status = "DoRootMenuOut";
};

Menu.DoMenuOut = function(ev){
	var evSrc = Menu.GetEventSrc(ev);
	evSrc = Menu.GetMenuEvSrc(evSrc);
	if(evSrc.menu != null){
		__mover = false;
		
		//close menu after __timeCloseMenu msec inactive mouse-out
  	__timerId = setTimeout("Menu.HideAll()", __timeCloseMenu);
	}
};
Menu.DoMenuOver = function(ev){
	__mover = true;
	clearTimeout(__timerId);
	
	var evSrc = Menu.GetEventSrc(ev);
	evSrc.style.cursor = "pointer";
	
	evSrc = Menu.GetMenuEvSrc(evSrc);
	var m = evSrc.menu;
	
	if(m.parent.parent == null) __lastRM = m;
	
	//build & open submenu for this menu if necessary
	if(m.HasChildren() && m.subdiv == null){
		m.BuildMenu(false);
		m.subdiv.style.display = "block";
		if(Menu.IEBrowser() && m.iframe != null) m.iframe.style.display = "block";
	}
	
	//change css for other menus in this menu group
	var currRow = evSrc.parentNode;
	var tb = currRow.parentNode;
	for(var i=0; i<tb.childNodes.length; i++){
		if(tb.childNodes[i] == currRow){
			continue;
		}
		else{
			if(m.parent.children[i].subdiv != null && m.parent.children[i].subdiv.style.display == "block"){
				Menu.Close(m.parent.children[i], true);
			}
			if(m.parent.children[i].css != ""){
				if(tb.childNodes[i].childNodes.length == 3){
					tb.childNodes[i].childNodes[0].className = m.parent.children[i].css;
					tb.childNodes[i].childNodes[1].className = m.parent.children[i].css;
					tb.childNodes[i].childNodes[2].className = m.parent.children[i].css;
				}
			}
		}
	}
	
	if(m.overCss != ""){
		evSrc.className = m.overCss;
		if(evSrc.nextSibling != null) evSrc.nextSibling.className = m.overCss;
		if(evSrc.previousSibling != null) evSrc.previousSibling.className = m.overCss;
	}
		
	if(m.subdiv != null){
		//change css of previously displayed submenu before display current one
		var rows = null;
		if(m.subdivTb.childNodes[0].tagName.toUpperCase() == "TR"){
			rows = m.subdivTb.childNodes;
		}
		else{
			rows = m.subdivTb.childNodes[0].childNodes;
		}
		
		for(var i=0; i<rows.length; i++){
			var _m = rows[i].childNodes[0].menu;
			if(typeof(_m) != "undefined" && _m.css != ""){
				rows[i].childNodes[0].className = _m.css;
				rows[i].childNodes[1].className = _m.css;
				rows[i].childNodes[2].className = _m.css;
			}
		}

		//display submenu		
		if(Menu.IEBrowser()) m.iframe.style.display = "block";
		m.subdiv.style.display = "block";
	}
	
	var root = Menu.FindRoot(m);
	if(root != null && root.onMenuOpen != null){
	  root.onMenuOpen.apply(this, root.onMenuOpenArgs);
	}
	
	//window.status = "DoMenuOver";
};
Menu.DoMenuClick = function(ev){
	var evSrc = Menu.GetEventSrc(ev);
	evSrc = Menu.GetMenuEvSrc(evSrc);
	var m = evSrc.menu;
	if(m.url != ""){
		var root = Menu.FindRoot(m);
		Menu.Close(root, true);
		Menu.Navigate(m.url, m.newWD, m.newWdOptions);
	}
	return false;
};

////////////////////////////////////////////////////

var __menuArr = new Array();	//global array
Menu.HideAll = function(){
	if(!__mover){
    var root = Menu.FindRoot(__lastRM);
	
		for(var n=0; n<__menuArr.length; n++){
			if(__menuArr[n].subdiv != null && __menuArr[n].subdiv.style.display == "block"){
				__menuArr[n].Close();
			}
		}

	  if(__timerId != null) clearTimeout(__timerId);
	  if(root != null && root.onMenuClose != null){
	    root.onMenuClose.apply(this, root.onMenuCloseArgs);
	  }
	}
};
Menu.HideAllExcept = function(menu){
	for(var n=0; n<__menuArr.length; n++){
		if(__menuArr[n] != menu){
			if(__menuArr[n].subdiv != null && __menuArr[n].subdiv.style.display == "block"){
				__menuArr[n].Close();
			}
			
	    var m = Menu.FindRoot(__menuArr[n]);	
	    if(m.onRootMenuOut != null){
	      m.onRootMenuOut.apply(this, m.onRootMenuOutArgs);
	    }
			
		}
	}
};
Menu.AddEvent(document, "click", Menu.HideAll);

Menu.IsOpen = function(){
	for(var n=0; n<__menuArr.length; n++){
		if(__menuArr[n].IsOpen()) return true;
	}
	return false;
}
////////////////////////////////////////////////////

function FE(){};
FE.CreateMenuRoot = function(elName){
	for(var n=0; n<__menuArr.length; n++){
		if(__menuArr[n].rootEl.id == elName){
			return __menuArr[n];
		}
	}
	__menuArr.push(new Menu(elName));
	return __menuArr[__menuArr.length-1];
};
FE.CreateMenuItem = function(){
	var mi = null;
	if(arguments.length == 2){
		mi = new MenuItem(arguments[0], arguments[1]);
	}
	else if(arguments.length == 3){
		mi = new MenuItem(arguments[0], arguments[1], arguments[2]);
	}
	else if(arguments.length == 4){
		mi = new MenuItem(arguments[0], arguments[1], arguments[2], arguments[3]);
	}
		
	return mi;
};
FE.OpenMenu = function(m){
	__mover = true;
	Menu.Open(m);
};
FE.SetOnRootMenuOut = function(callbackFunc, args){
	for(var n=0; n<__menuArr.length; n++){
	  var root = Menu.FindRoot(__menuArr[n]);
		if(root != null){
			root.SetOnRootMenuOut(callbackFunc, args);
		}
	}
};
FE.SetOnRootMenuOver = function(callbackFunc, args){
	for(var n=0; n<__menuArr.length; n++){
	  var root = Menu.FindRoot(__menuArr[n]);
		if(root != null){
			root.SetOnRootMenuOver(callbackFunc, args);
		}
	}
};
FE.SetOnMenuClose = function(callbackFunc, args){
	for(var n=0; n<__menuArr.length; n++){
	  var root = Menu.FindRoot(__menuArr[n]);
		if(root != null){
			root.SetOnMenuClose(callbackFunc, args);
		}
	}
};
FE.SetOnMenuOpen = function(callbackFunc, args){
	for(var n=0; n<__menuArr.length; n++){
	  var root = Menu.FindRoot(__menuArr[n]);
		if(root != null){
			root.SetOnMenuOpen(callbackFunc, args);
		}
	}
};
