/**
 *	Menu Action for the HTC college site.
 *
 *	This script implements the expanding and contracting menu
 *	action used for the left navigation on the HTC site.
 *
 *	This file depends on utility.js also being included in
 *	the html page.
 *
 *	@author Russell Francis < rfrancis at ev.net >
 *	@date 2005-12-12
 */
/**
 *	This function will open a menu item and close all
 *	others within the list.
 *
 *	This function will set the style.display property
 *	to 'block' for the element which has the same id
 *	as the id parameter.  All other elements which match
 *	the 'submenu1', 'submenu2' ... 'submenun' sequence
 *	will have their style.display property set to 'none'.
 *
 *	@param id The id of the menu element to open.
 */	
function openMenuById(id)
{
	var element = getById( id );
	if( element == null )
	{
		return;
	}

	var prefix = getPrefix( id );
	if( prefix == null )
	{
		return;
	}

	var keep_going = true;
	for( var i = 1; keep_going; ++i )
	{
		keep_going = false;
		var menu_element = getById( prefix + i );
		if( menu_element )
		{
			menu_element.style.display='none';
			keep_going = true;
		}
	}

	element.style.display='block';
}

/**
 *	This method will grab the prefix from a name
 *	It looks for a trailing series of digits and
 *	strips them off, returning what is in front
 *	of the trailing digits.
 *
 *	@param tag A string with a number at the end.
 *	@return The prefix, with the number stripped off.
 */
function getPrefix( tag )
{
	for( i = tag.length - 1; i >= 0; --i )
	{
		var c = tag.charAt(i);
		if( !isDigit( c ) )
		{
			break;
		}
	}

	if( ( i == tag.length - 1 ) || ( i < 0 ) )
	{
		return( null );
	}

	return( tag.substring( 0, i + 1 ) )
}
