// Opens or closes a node
function oc(node, tree_name)
{
	var theDiv = get_element(tree_name + "Group" + node),
		theJoin	= get_element(tree_name + "Join" + node),
		theIcon = get_element(tree_name + "Icon" + node);

	if (! theDiv) return;

	if (theDiv.style.display == 'none')
	{
		theJoin.src = (theJoin.src.indexOf(icons[0].src) >= 0 ? icons[2].src : icons[3].src);
		theIcon.src = icons[5].src;
		theDiv.style.display = '';
	}
	else
	{
		theJoin.src = (theJoin.src.indexOf(icons[2].src) >= 0 ? icons[0].src : icons[1].src);
		theIcon.src = icons[4].src;
		theDiv.style.display = 'none';
	}
}

// updates status bar with message for current node
// "Abrir" to open group "Fechar" to hide group
function node_upstatus(node_id, node_mode, tree_name)
{
	var windowstatus = get_element(tree_name + "Group" + node_id).style.display == 'none' ? (node_mode == 1 ? 'Abrir' : 'Fechar') : (node_mode == 1 ? 'Fechar' : 'Abrir');

	window.setTimeout('window.status="' + windowstatus + '"', 5);
}

// emphasize current item when clicked
// and sets status bar
function item_upstatus(node_id, emphazise, statusbar, tree_name)
{
	if (emphazise)
	{
		emphasizeLink(node_id, tree_name);
	}

	window.setTimeout('window.status="' + (statusbar ? statusbar : '') + '"', 5);
}

// removes bold from previous item and adds bold to current
function emphasizeLink(node_id, tree_name)
{
	if (eval("lastNodeSelected" + tree_name) > -1)
	{
		get_element(tree_name + "Link" + eval("lastNodeSelected" + tree_name)).style.fontWeight = 'normal';
	}
	get_element(tree_name + "Link" + node_id).style.fontWeight = 'bold';
	eval("lastNodeSelected" + tree_name + "=" + node_id);
}

// opens or closes a list of nodes
function showhide(e, array_values, tree_name)
{
	var theDiv, theJoin, theIcon;

	mode = (e.altKey ? 'hide' : 'show');	// if ALT is pressed, hides all sub-folders, else, shows them

	window.status = "Por favor, espere...";

	for (var node in array_values)
	{
		theDiv = get_element(tree_name + "Group" + array_values[node]);
		theJoin	= get_element(tree_name + "Join" + array_values[node]);
		theIcon = get_element(tree_name + "Icon" + array_values[node]);

		if (mode == 'show' && theDiv.style.display == 'none')
		{
			theJoin.src = (theJoin.src.indexOf(icons[0].src) >= 0 ? icons[2].src : icons[3].src);
			theIcon.src = icons[5].src;
			theDiv.style.display = '';
		}
		else if (mode == 'hide' && theDiv.style.display != 'none')
		{
			theJoin.src = (theJoin.src.indexOf(icons[2].src) >= 0 ? icons[0].src : icons[1].src);
			theIcon.src = icons[4].src;
			theDiv.style.display = 'none';
		}
	}
	window.status = "Clique para expandir/ALT + clique para contrair";
}

var icons = new Array(6);

icons[0] = new Image();
icons[0].src = "/javascript/images/plus.gif";
icons[1] = new Image();
icons[1].src = "/javascript/images/plusbottom.gif";
icons[2] = new Image();
icons[2].src = "/javascript/images/minus.gif";
icons[3] = new Image();
icons[3].src = "/javascript/images/minusbottom.gif";
icons[4] = new Image();
icons[4].src = "/javascript/images/treestyles/" + tree_style + "/" + "folder.gif";
icons[5] = new Image();
icons[5].src = "/javascript/images/treestyles/" + tree_style + "/" + "folderopen.gif";

get_element = document.all ? function (s_id) { return document.all[s_id] } : function (s_id) { return document.getElementById(s_id) };
