//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//	WebTop Tree View
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------------
//	Plus/minus images for tree
//---------------------------------------------------------------------------------------------------------
expand0					= new Image();
expand0.src				= "/images/nav-plus.gif";
expand1					= new Image();
expand1.src				= "/images/nav-minus.gif";

//---------------------------------------------------------------------------------------------------------
//	Change state of tree divs
//---------------------------------------------------------------------------------------------------------
function treeview_changestate( what )
{
	var open_values_string = find_cookie( treeview_name );

	if ( open_values_string == null )
	{
		open_values_string = '';
	}

	button = 'button' + what;
	
	obj	   = document.getElementById( what );
	
	if( !obj )
	{
		return;
	}

	//	Save the tree settings for a year
	var expdate = new Date ();
	expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 365));

	if( obj.style.display == 'none' )
	{
		obj.style.display	 = 'block';
		document[button].src = expand1.src;
		
		//	Save the change in da cookie
		open_values_string = open_values_string + what + ",";
		make_cookie(treeview_name, open_values_string, expdate);
	}
	else
	{
		obj.style.display	 = 'none';
		document[button].src = expand0.src;
		
		//	Delete the id from da cookie
		id		= what + ',';
		pos		= open_values_string.indexOf( id );
		end_pos	= pos + id.length;

		if ( pos != -1 )
		{
			first_part	= open_values_string.substring(0, pos);
			end_part	= open_values_string.substring(end_pos, open_values_string.length )
			open_values_string = first_part + end_part;
			make_cookie(treeview_name, open_values_string, expdate);
		}
	}
}

//---------------------------------------------------------------------------------------------------------
//	Use cookies to setup tree status
//---------------------------------------------------------------------------------------------------------
function treeview_setup() 
{
	var open_values_string = find_cookie( treeview_name );

	if ( !open_values_string )
	{
		//	Hide the loading message
		loadingmsg_obj = document.getElementById('loadingmsg');
		if ( loadingmsg_obj )
		{
			loadingmsg_obj.style.display  = 'none';
		}
		
		//	All done, now show the tree
		document.getElementById('treeview').style.visibility  = 'visible';
		return;
	}

	document.getElementById('treeview').style.visibility  = 'visible';
}


//	Show treeview actions bar
actionbar_timeout_id = 0;
actionbar_id		 = '';

function showActionsBar(what)
{
	if ( actionbar_timeout_id )
	{
		hideActionsBar( actionbar_id );
		clearTimeout( actionbar_timeout_id );
		actionbar_timeout_id = 0;
	}

	setObjectStyle( "prm" + what, 'visibility', 'visible');
}

//	Hide treeview actions bar
function hideActionsBar(what,timeout)
{
	if ( timeout )
	{
		actionbar_timeout_id	= setTimeout("hideActionsBar('" + what + "');",timeout);
		actionbar_id			= what;
		return;
	}
	setObjectStyle( "prm" + what, 'visibility', 'hidden');
}


function resetActionsBarTimer( what )
{
	if ( !actionbar_timeout_id )
	{
		return;
	}

	clearTimeout( actionbar_timeout_id );
	actionbar_timeout_id = 0;

	actionbar_timeout_id	= setTimeout("hideActionsBar('" + what + "');", 3000);
	actionbar_id			= what;
}