var HelpHideTimer = 0;
var MenuKillTimer = 0;
var ActiveLayer = null;
document.onmouseover = new Function("if (ActiveLayer) StartMenuKillTimer();");
document.onClick = new Function("if (ActiveLayer) {HideLayer(ActiveLayer);StopMenuKillTimer();};");

function ChangeCSS(obj,Clas)
{
	obj.className = Clas;
};

function GetLayer(layername)
{
	if (document.getElementById)
	{
		x=document.getElementById(layername);		
	}
	else
	{
		x = document.all[layername];
	};
	return x;
};

function getPos(el,sProp) 
{
	var iPos = 0
	while (el != null) 
	{
		iPos+=el["offset" + sProp];
		el = el.offsetParent;
	}
	return iPos;
};

function getHeight(el) 
{
	var iPos = 0
	while ((el != null) && (iPos == 0)) 
	{
		iPos+=el["offsetBottom"];
		el = el.offsetParent;
	}
	return iPos;
};

function IsIE()
{
	if (document.all) return true;
	return false;
};

function ShowMenuLayer(layername,parentobj)
{
	var x = GetLayer(layername);		
	var wid;
	if (x == null)
	{
		alert("Layer Name Not Found");
	}
	else
	{
		if (ActiveLayer != null)
		{
			HideMenuLayer(ActiveLayer);
		};
		if (IsIE())
		{			
			wid = document.body.scrollWidth;
			x.style.pixelLeft = getPos(parentobj,"Left");
			x.style.pixelWidth = parentobj.offsetWidth;
			if (x.style.pixelWidth < 125) x.style.pixelWidth=125;
			x.style.pixelTop = getPos(parentobj,"Top") + 20;
			
			if ((x.style.pixelLeft + x.style.pixelWidth) > wid)
			{
				x.style.pixelLeft = wid - parentobj.offsetWidth;
				x.style.pixelWidth = parentobj.offsetWidth;
			};
			x.style.visibility='visible';
		}
		else
		{
			wid = parseInt(window.innerWidth);
			x.style.left = getPos(parentobj,"Left");
			x.style.width = parentobj.offsetWidth;
			if (x.style.width < 150) x.style.width=150;
			//if (x.style.height < 20) x.style.height=20;
			x.style.top = getPos(parentobj,"Top") + 20;
			
			if ((x.style.left + x.style.width) > wid)
			{
				x.style.left = wid - parseInt(parentobj.offsetWidth);
				x.style.width = parentobj.offsetWidth;
			};
			x.style.visibility='visible';
		};
		ActiveLayer = layername;
	};
};

function HideMenuLayer(layername)
{
	if (ActiveLayer == null) return;	
	HideLayer(layername);		
	ActiveLayer=null;	
};

function HelpHide()
{
	HideLayer("HELP");
};

function HideLayer(layername)
{
	var x = GetLayer(layername);	
	if (x != null)
	{
		x.style.visibility='hidden';
		if (IsIE())
		{
			var tmph = x.style.pixelHeight;
			var tmpw = x.style.pixelWidth;
			x.style.pixelTop = 1;
			x.style.pixelHeight = tmph;
			x.style.pixelLeft = 1;
			x.style.pixelWidth = tmpw;
		}
		else
		{
			var tmph = x.style.height;
			var tmpw = x.style.width;
			x.style.top = 1;
			//x.style.height = tmph;
			x.style.left = 1;
			x.style.width = tmpw;
		};
	};
};

function StartMenuKillTimer()
{
	StopMenuKillTimer();
	MenuKillTimer = setTimeout("HideMenuLayer(ActiveLayer)",2000);
};

function StopMenuKillTimer()
{
	if (MenuKillTimer != 0) clearTimeout(MenuKillTimer);
	MenuKillTimer = 0;
};

function StartHelpHideTimer()
{
	StopHelpHideTimer();
	HelpHideTimer = setTimeout("HelpHide()",2000);
};

function StopHelpHideTimer()
{
	if (HelpHideTimer != 0) clearTimeout(HelpHideTimer);
	HelpHideTimer = 0;
};

function SetHelp(mess)
{
	StopHelpHideTimer();
	var x = GetLayer("HELP");	
	if (x != null)
	{
		if (IsIE())
		{
			x.innerHTML = "<blockquote><br><br><center>" + mess + "</center></blockquote>";
		}
		else
		{
			x.innerHTML = "<blockquote><br><center>" + mess + "</center></blockquote>";
		};
		
		if (IsIE())
		{
			var tmp = x.style.pixelHeight;
			x.style.pixelTop = document.body.clientHeight - (x.style.pixelHeight + 25);
			x.style.pixelHeight = tmp;
		}
		else
		{
			var tmp = x.style.height;
			x.style.top = window.innerHeight - (parseInt(x.style.height) + 40);
			x.style.height = tmp;
		};
		
		x.style.visibility='visible';
	};
};
