function showhide(a, b)
{
	var id = document.getElementById(a);
	
	if (undefined != b)
	{
		var img = document.getElementById(b);
	}
	if (id.style.display == 'none') {	
		id.style.display = 'block';
		if (undefined != img)
		{
			img.className = 'img_toggle_down';
		}
	}
	else
	{
	    id.style.display = 'none';
	    if (undefined != img)
	    {
	    	img.className = 'img_toggle_up';
	    }
	}
}

function toggle(a) {
	var id = document.getElementById(a);
	if (id.style.display == 'none')
	{ 
		id.style.display = 'block';
	}
	else
	{ 
		id.style.display = 'none';
	}
}

function collapse(a,b) {
	var id = document.getElementById(a);
	var img = document.getElementById(b);
	id.style.display = 'none';
	img.className = 'img_toggle_up'; 
}

function checkAll(src, dest)
{
	var chkAll = document.getElementById(src);
	var checks = document.getElementsByName(dest);
	var boxLength = checks.length;
	for (i = 0; i < boxLength; i++)
	{
		checks[i].checked = chkAll.checked;
	}
}

/*
 * Set all checkboxes with checkboxName to have value
 * @param checkboxName string Name of the set of checkboxes to affect
 * @param value boolean Whether to set the checkboxes to checked (true) or unchecked (false)
 */
function setAllCheckboxes(checkboxName, value)
{
	var checkboxes = document.getElementsByName(checkboxName);
	for (i = 0; i < checkboxes.length; i++)
	{
		checkboxes[i].checked = value;
	}
}

/*
 * Invert the checkbox selection for checkboxName
 * @param checkboxName string Name of the set of checkboxes to affect
 */
function invertCheckboxes(checkboxName)
{
	var checkboxes = document.getElementsByName(checkboxName);
	for (i = 0; i < checkboxes.length; i++)
	{
		checkboxes[i].checked = !checkboxes[i].checked;
	}
}

////////////////////////////////////////////////////////////////// 
// functions moved from various templates to a cnetral place
//////////////////////////////////////////////////////////////////

/*  
* refresh the main window
* @parameter: none	
*/
function refresh()
{
	var sURL = unescape(window.location.pathname);
	window.location.replace( sURL );
}
/*  
* remove the thickbox and then refresh the main window, generally, it will be called after an edit operation
* @parameter: none	
*/
function cleanAndRefresh()
{
	window.parent.tb_remove();
	var sURL = unescape(window.location.pathname);
	window.location.replace( sURL );
}



//////////////// utility function . originally from tp-ajax-js.js
function isModernBrowser() {
    return (typeof document.getElementById!='undefined');
}

function dom(id) {
	if (isModernBrowser())
	{
    	return document.getElementById(id);
	}
	else if (typeof document.all!='undefined')
	{
		return document.all[id];
	}
	else
	{
		return false;
	}
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
