/**
 * Set the display of an element to '' or 'none'
 *
 * @param string The id of the element to show or hide
 * @param boolean If this is true, show the element. Otherwise, hide the element
 */
function setElementDisplay(id, show)
{
	document.getElementById(id).style.display = (show) ? '' : 'none';
}	


/**
 * Select all checkboxes for a given model
 * @param string The list name to select all of
 * @param string The id of the checkbox which dispatched the request
 */
function selectAll(list, sourceCheckbox)
{	
	if (document.selectAllLists[list] != null)
	{	
		var checking = document.getElementById(sourceCheckbox).checked;	
		
		for(var i=0; i<document.selectAllLists[list].length; i++)
		{
			document.selectAllLists[list][i].checked = checking;
		}
	}
}


/**
 * Register a checkbox to be included in a select all list
 *
 * @param string The id of the checkbox to register
 * @param string The list name to register with
 */
function registerSelectAll(id, list)
{
	if (document.selectAllLists == null)
	{
		document.selectAllLists = new Array();
	}
	
	if (document.selectAllLists[list] == null)
	{
		document.selectAllLists[list] = new Array();
	}
	
	document.selectAllLists[list].push(document.getElementById(id));
}



/**
 * Display a popup containing the layout guide for a given section
 *
 * @param string The section to display the layout guide for
 */
function displayLayoutGuide(section)
{
	window.open( '/img/layout-guide-' + section + '.jpg','layout_' + section, 'width=800,height=486');
}



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"), "");
}