var MenuDelay = 50;
var timerShowMenu;
var timerHideMenu;
var ActiveMenu = null;
var ActiveEl = null;

function ImgOn(el, i, pageid) {
	if (menudropdowns.innerText == '') return;
	if (el.className != "m_active")
		el.className = "m_over";

	if (ActiveEl != null)
		if (ActiveEl.className != "m_active")
			ActiveEl.className = "m_off";
	
	if (ActiveMenu != null)
		ShowMenu(pageid, i);
	else 
		timerShowMenu = window.setTimeout("ShowMenu(" + pageid + ", " + i + ")", MenuDelay);

	ActiveEl = el;
	CancelCloseMenuTimer();

}

function ImgOff(el, i) {
	if (menudropdowns.innerText == '') return;

	if (ActiveEl == null)
	{
		if (el.className != "m_active");
		{
			el.className = "m_off";
		}
	}
	
	// cancel menu activation
	if (timerShowMenu)
		window.clearTimeout(timerShowMenu); 
	
	SetCloseMenuTimer();
}

function SetCloseMenuTimer() {
	CancelCloseMenuTimer();
	timerHideMenu = window.setTimeout("HideMenu()", MenuDelay);
}

function CancelCloseMenuTimer() {
	// cancel menu deactivation
	if (timerHideMenu)
		window.clearTimeout(timerHideMenu); 
}

function ShowMenu(pageid, i) {
	HideMenu();
	hideElement();							
	var m = new Menu(pageid);
	m.ParentMenu = null;
	var parentTD = document.all("menuTD" + i);
	var t = 220;
	if (typeof i != "undefined")
		t = parentTD.offsetTop - 1;
	var l = cxmenu.offsetLeft + cxmenu.offsetWidth;
	m.Show(t,l);
}

function ShowSubMenu(pageid, el) {
	if (ActiveMenu.ParentMenu != null)
		ActiveMenu.Hide();
	ActiveMenu.ShowMenu(pageid, el);
}

function HideMenu() {
	if (ActiveMenu != null)
	{
		ActiveMenu.Hide();
		if (ActiveMenu != null)
			HideMenu(); // call it recursively to Hide any other open menus in the hierarchy
		if (ActiveEl != null)
		{
			if (ActiveEl.className != "m_active")
				ActiveEl.className = "m_off";
			ActiveEl = null;
		}
	}
	showElement();
}


function Menu(id) {

	this.id = id;
	this.div = document.all("divCM_" + id);
	this.Hide = _Hide;
	this.Show = _Show;
	this.ShowMenu = _ShowMenu;
	this.ChildMenu = null;
	this.ParentMenu = null;

	return (this);
	
	function _Hide() {
		this.div.style.visibility = "hidden";
		ActiveMenu = this.ParentMenu;
		if (ActiveMenu!=null)
			SetCloseMenuTimer();
		if ((document.all.sidebar) && (IsLessThanIE55()))
		{
			document.all.sidebar.style.visibility = 'visible';
		}
	}
	
	function _Show(t,l) {
		if (this.ChildMenu != null) {
			this.ChildMenu.Hide();
			this.ChildMenu = null;
		}

		var clientHeight = document.body.clientHeight;
		if ((t + this.div.offsetHeight) > clientHeight)
			t = clientHeight - this.div.offsetHeight;

		this.div.style.top = t;
		this.div.style.left = l;
		this.div.style.visibility = "visible";
		this.div.onmouseover = CancelCloseMenuTimer;
		this.div.onmouseout = SetCloseMenuTimer;
		
		ActiveMenu = this;
	}
	
	function _ShowMenu(pageid, el) {
		if (ActiveMenu.id != pageid)
		{
			this.ChildMenu = new Menu(pageid);
			this.ChildMenu.ParentMenu = this;
			var t = el.offsetTop - 1;
			var clientHeight = document.body.clientHeight;
			var menuBottom = this.div.offsetTop + t + this.ChildMenu.div.offsetHeight;
			if (menuBottom > clientHeight)
			{
				t = el.offsetTop - (menuBottom - clientHeight);
			}
			var l = this.div.offsetWidth;
			this.ChildMenu.Show(t,l);			
			if ((document.all.sidebar) && (IsLessThanIE55()))
			{
				document.all.sidebar.style.visibility = 'hidden';
			}
		}
	}	
}

function g(l) {
	HideMenu();
	window.location.href = l;
}

function h(l) {
	HideMenu();
	NewWindow(l+'&amp;openerurl='+escape(location.href),'01','750','550','no');
}

function HighlightView(id)
{
	var ViewId = AV[id];
	if (ViewId != null)
	{
		ViewId = ViewId - 1;
		var el = cxmenu.all("menuF" + (ViewId + 1).toString());
		el.className = "m_active";
	}
		
	return;
}
function hideElement() 
{
	for (i = 0; i < document.all.tags('SELECT').length; i++){obj = document.all.tags('SELECT')[i]; if (! obj || ! obj.offsetParent) continue; obj.style.visibility = "hidden";}
	for (i = 0; i < document.all.tags('OBJECT').length; i++){obj = document.all.tags('OBJECT')[i]; if (! obj || ! obj.offsetParent) continue; obj.style.visibility = "hidden";}
	for (i = 0; i < document.all.tags('APPLET').length; i++){obj = document.all.tags('APPLET')[i]; if (! obj || ! obj.offsetParent) continue; obj.style.visibility = "hidden";}
}

function showElement() 
{
	for (i = 0; i < document.all.tags('SELECT').length; i++){obj = document.all.tags('SELECT')[i]; if (! obj || ! obj.offsetParent) continue; obj.style.visibility = "";}
	for (i = 0; i < document.all.tags('OBJECT').length; i++){obj = document.all.tags('OBJECT')[i]; if (! obj || ! obj.offsetParent) continue; obj.style.visibility = "";}
	for (i = 0; i < document.all.tags('APPLET').length; i++){obj = document.all.tags('APPLET')[i]; if (! obj || ! obj.offsetParent) continue; obj.style.visibility = "";}
}

function IsLessThanIE55()
{
	var version = window.navigator.appVersion;
	var pos = version.indexOf("MSIE");
	if (pos != -1)
	{
		var numberVersion = Number(version.substr(pos+5,3));
		if (numberVersion < 5.5)
			return true;
		else
			return false;
	}
	else
		return false;
}
