// ==========================================
// Basic Utility Functions
	function util_GetItem( object_id )
	{
		var item;
		
		if(document.getElementById && document.getElementById( object_id ) )
			item = document.getElementById( object_id );
		else if (document.all && document.all( object_id ) )
			item = document.all( object_id );
		else if( document.layers && document.layers[object_id] )
			item = document.layers[object_id];
		
		return item;
	}

// ==========================================


// ==========================================
// AJAX Functions
	function ShowUpdating( LayerId )
	{
		//util_SetInnerHtml( LayerId, "Updating..." );
		//return true;
	}

// ==========================================
// Html Input Functions

	function GrowTextBox( ItemId )
	{
		TransformTextBox( ItemId, 1 );
	}
	function ShrinkTextBox( ItemId )
	{
		TransformTextBox( ItemId, -1 );
	}
	
	function TransformTextBox( ItemId, Direction )
	{
		var textBox;
		if( document.getElementById && (textBox = document.getElementById(ItemId) ) )
		{
			if( !textBox.rows )
				textBox.rows = 2;
			else if( (textBox.rows > 2 && Direction < 0 ) || (textBox.rows < 40 && Direction > 0 ) )
				textBox.rows += (2*Direction); 
		}	
	}
	function util_DisableButton( button_id, text )
	{
		var button;
		
		if( (button = util_GetItem( button_id )) != null )
		{
			button.disabled		= true;
			
			if( text )
				button.innerHTML	= text;
		}
	}
	function util_EnableButton( ButtonId, Text )
	{
		var button;
		
		if( (button = util_GetItem( ButtonId )) != null )
		{
			button.disabled	= false;
			
			if( Text )
				button.innerHTML = Text;
		}
	}	
	function util_ToggleButton( ButtonId )
	{
		var button;
		if( (button = util_GetItem( ButtonId )) != null )
			button.disabled = !button.disabled;
	}
// ==========================================


// ==========================================
// Display Functions

function util_SetVisibility( item_id, new_vis )
{
	var item;
	if( item = util_GetItem( item_id ) )
		util_SetObjectVisibility( item, new_vis )
	else
		alert("error: object '" + item_id + "' not found.");
}

// @param item : the object we want to set
// @param new_vis : Either hidden or visible
// @param new_display : Used to set the display mode; default is 'block'
function util_SetObjectVisibility(
	item,
	new_vis,
	new_display
)
{
	item.style.visibility	= new_vis;
	
	if( new_vis == "hidden" )
		item.style.display = "none";
	else
		item.style.display = (new_display ? new_display : "block");
}

// @param item_id : the Id of the object we want to hide.
// @param new_display : the new display mode; default is block.
function util_Show(
	item_id,
	new_display
)
{
	if( !new_display )
		util_SetVisibility( item_id, "visible" );
	else
	{
		var item = util_GetItem( item_id );
			item.style.visibility	= "visible";
			item.style.display	= new_display;
	}
}
// @param item_id : the Id of the object we want to hide.
function util_Hide( item_id )
{
	util_SetVisibility( item_id, "hidden" );
}


/// -- toggles the given item between hidden and visible
// @param item_id : the Id of the object to toggle
// @param display : the display mode for viewing; default is "block";
function util_Toggle(
	item_id,
	display
)
{
	var item = util_GetItem( item_id );
	if( item.style.visibility == "hidden" )
		util_SetObjectVisibility( item, "visible", display );
	else
		util_SetObjectVisibility( item, "hidden", display );
}

function util_SetClass( item_id, class_name )
{ 
	var item;
	
	if( item = util_GetItem( item_id ) )
		item.className	= class_name;
}


function util_SetInnerHtml( item_id, text, append )
{
	var item;
	
	if( item = util_GetItem( item_id ) )
		item.innerHTML = (append ? item.innerHTML + text : text);
}



