function expandTree()
{	
	if (!window.item_id || item_id == null || item_id.length <= 0) return;
	else
	{
		for (i=0;i<item_id.length;i++)
		{
			// expand the tree
			branch_id = document.getElementById(item_id[i]);
			if (branch_id == null) continue;
			
			// fix if range tree is only 1 level
			if (branch_id.parentNode.parentNode.nodeName == "LI")
			{
				branch_id.parentNode.parentNode.attributes['class'].nodeValue = 'liOpen';
			}

			branch_id.attributes['class'].nodeValue = 'liBulletsel';
		}
	}
}


function treeClick(rID)
{
	var displayTreeId = rID.attributes['id'].nodeValue;
	for (i=0;i<tree_list.length;i++)
	{
		// set all tabs to regular display 
		document.getElementById(tree_list[i]).attributes['class'].nodeValue = 'menu_option';	
	
		// hide all tree_ul in the best posible way to work with all br	
		iTreeUL = document.getElementById(tree_list[i] + "_ul");
		iTreeUL.attributes['class'].nodeValue = 'hidedisplay';
		iTreeUL.style.display = 'none';
		iTreeUL.style.height = 0;
	}
	createCookie('browseby', displayTreeId,100);
	rID.attributes['class'].nodeValue ='menu_option_sel';
	
	var displayTreeUL = document.getElementById(displayTreeId + "_ul");

	displayTreeUL.attributes['class'].nodeValue='tree_ul';
	displayTreeUL.style.display = 'block';
	
	// this line caused error in IE but somehow it is working with IE6, still a mystery.
	// IE will eventually hang after this line. 
	displayTreeUL.style.height = 'inherit';

}

/*
function treeClick(rID)
{
	var display_tree = rID.attributes['id'].nodeValue;
	
	for (i = 0; i < tree_list.length; i++)
	{
		// hide all nodes:
		document.getElementById(tree_list[i]).attributes['class'].nodeValue = 'menu_option';	
		document.getElementById(tree_list[i] + "_ul").style.display = 'none';
		document.getElementById(tree_list[i] + "_ul").style.height = 0;
	}
	createCookie('browseby', display_tree,100);
	rID.attributes['class'].nodeValue ='menu_option_sel';
	document.getElementById(display_tree + "_ul").style.display = 'block';
	
	// this line caused error in IE but somehow it is working with IE6, still a mystery.
	// IE will eventually hang after this line. 
	document.getElementById(display_tree + "_ul").style.height = 'inherit';
}
*/

function branchClick(bID)
{
	var bParentNode = bID.parentNode;
	var attrib = bParentNode.attributes['class'].nodeValue;
	if (attrib == "liClosed") 
	{
		bParentNode.attributes['class'].nodeValue = "liOpen";
	}
	else 
	{
		bParentNode.attributes['class'].nodeValue = "liClosed";
	}
}


/* cookies function */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function hightlightTopmenuItem(menuItemName)
{
	if (menuItemName == null || menuItemName.length == 0)
	{
		// set all top menu item to inactive
		//var allMenuItem = document.getElementById("top_menu").getElementsByTagName('a');
		//for (i=0;i<allMenuItem.length;i++)
		//{
		//	allMenuItem[i].attributes['class'].nodeValue="top_menu_link";
		//}
	}
	else
	{
		document.getElementById(menuItemName).attributes['class'].nodeValue="top_menu_sel";
	}
}
