// JavaScript Document

//just like the php isset function
function isset(variable_name)
{
	try
	{
		if (typeof(eval(variable_name)) != 'undefined')
			if (eval(variable_name) != null)
				return true;
	}
	catch(e)
	{ }

	return false;
}

//function found online at http://javascript.about.com/library/bldom08.htm
//return nodelist of all elements with passed class
document.getElementsByClassName = function(cl)
{
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
	var classes = elem[i].className;
	if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
};

//IE FIX for css hover classes
//changes the colors of implicit element just like the css th.thlink:hover 
changeMenuColor = function()
{
	this.style.backgroundColor = "#FFFFFF";
	this.style.color = "#000000";
	this.style.cursor = "pointer";
	var num = this.id;
	if (isset(document.getElementById("submenu"+num)))
		document.getElementById("submenu"+num).style.display = "block";
};
//changes them back
changeMenuBack = function()
{
	this.style.background = "none";
	this.style.color = "#FFFFFF";
	var num = this.id;
	if (isset(document.getElementById("submenu"+num)))
	{
		document.getElementById("submenu"+num).style.display = "none";
	}
};

//change the colors of implicit element just like the css th.thlink:hover, but for class submenu_item
/*
this function is rather stupid, basically it does the same thing as the previous function, but stores the parent menu's onclick event, then clears it. onmouseout, it restores it 
*/
var oldreturn = "";	//the menu's previous onclick function
changeSubmenuColor = function()
{
	this.style.backgroundColor = "#006699";
	this.style.color = "#FFFFFF";
	this.style.cursor = "pointer";
	
	//store the old onmouseclick for restoration later
	var num = this.id.charAt(this.id.length-1);
	oldreturn = document.getElementById(num).onclick;
	document.getElementById(num).onclick = null;
};
//changes them back
changeSubmenuBack = function()
{
	this.style.backgroundColor = "#003366";
	this.style.color = "#FFFFFF";
	
	//now restore the old onclick function
	var num = this.id.charAt(this.id.length-1);
	document.getElementById(num).onclick = oldreturn;
};

//store the nodelist of all elements that have the thlink class into AllTdButtons
var AllTdButtons = document.getElementsByClassName("thlink");

//run through the AllTdButtons nodelist and set the onmouseover and onmouseout functions to change colors appropriately.
for (var i=0; i<AllTdButtons.length; i++)
{
	AllTdButtons[i].onmouseover = changeMenuColor;
	AllTdButtons[i].onmouseout = changeMenuBack;
}

//store the nodelist of all elements that have the submenu_item class into AllSubmenuItems
var AllSubmenuItems = document.getElementsByClassName("submenu_item");

//run through the AllSubmenuItems nodelist and set the onmouseover and onmouseout functions to change colors appropriately.
for (var i=0; i<AllSubmenuItems.length; i++)
{
	AllSubmenuItems[i].onmouseover = changeSubmenuColor;
	AllSubmenuItems[i].onmouseout = changeSubmenuBack;
}


