/**
 *  Show/Hide the form containing search parameters
 * 
 * @param formName string Name of the form
 * 
 * @return boolean Always false to prevent the default action
 * 		on the A element (to prevent following the href attribute)
 */
function toggleSearchParameters( formName )
{
	var tmpForm = document.forms[formName];

	if( tmpForm.style.display == "none" )
		new Effect.BlindDown( tmpForm, {duration:0.2} );
	else
		new Effect.BlindUp( tmpForm, {duration:0.2}  );

	/*  Don't follow the link  */
	return false;
}


/**
 *  Set the status of the item via an Ajax request 
 */
function toggleStatus(statusLink, updateURL)
{
	var ajax = new Ajax.Request(updateURL + "&rn=" + Math.random(),
					{method: 'get',
					onFailure:function(t) { alert('Error setting status: ' + t.status + ' -- ' + t.statusText); }});

	var statusImage = statusLink.getElementsByTagName('IMG').item(0);

	if( statusImage.src.search("[1]\.gif$") != -1 )
	{
		statusLink.title = "Offline. Click to make it online";
		new Effect.Fade( statusLink,
			{
			duration:0.2,
			afterFinish:function() {statusImage.src = statusImage.src.replace("1.gif", "0.gif");new Effect.Appear( statusLink )}
			});
	}
	else
	{
		statusLink.title = "Online. Click to make it offline";
		new Effect.Fade( statusLink,
			{
			duration:0.2,
			afterFinish:function() { statusImage.src = statusImage.src.replace("0.gif", "1.gif");new Effect.Appear( statusLink )}
			});
	}

	return false;
}


/*
 *  Given a tab number make that active (hiding any previusly shown tab)
 */
function tabMakeActive( tab_number )
{
	var newActiveTabElem = document.getElementById("tab" + tab_number);
	var i=1;

	/*  Hide all tabs  */
	do{
		if( document.getElementById("tab" + i) )
			document.getElementById("tab" + i).style.display = 'none';
		i++;
	}while( document.getElementById("tab" + i) );


	/*  Un-hide the tab that was clicked on  */
	newActiveTabElem.style.display = "block";


	/*  Make all tab headers inactive  */
	i=1;
	do{
		if( document.getElementById("ctab" + i) )
			document.getElementById("ctab" + i).className = 'inactive';
		i++;
	}while( document.getElementById("ctab" + i) );


	/*  Make the current tab active  */
	document.getElementById("ctab"+tab_number).className = "active";
}