function toggleDialog(dialogId)
{
	var dialog = document.getElementById(dialogId);
	var shade = document.getElementById("dialogShade");
	if (dialog && shade)
	{
		var showDialog = (dialog.style.display != "block");
		dialog.style.display = (showDialog) ? "block" : "none";
		shade.style.display = (showDialog) ? "block" : "none";
	}
}
//sets the selection of a select object to a given value.
//returns true if successful, or false if object was not in the select options.
function setSelection(selectObj, value)
{
	var inSelect = false;
	for(i=0; i<selectObj.options.length; i++)
	{
		if (selectObj.options[i].value == value)
		{
			selectObj.selectedIndex = i;
			inSelect = true;
		}
	}
	return inSelect;
}

//A big-ol' regex-based js date validation function.  Claims to be leap-year-aware.
//Pass in dom object input field to be validated.
//Modified from http://www.rodsdot.com/ee/dateValidate.asp
function validateDate(fld) {
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    return (fld.value.match(RegExPattern)) && (fld.value!='');
}

/**
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
Without the second parameter, it will trim these characters:
    * " " (ASCII 32 (0x20)), an ordinary space.
    * "\t" (ASCII 9 (0x09)), a tab.
    * "\n" (ASCII 10 (0x0A)), a new line (line feed).
    * "\r" (ASCII 13 (0x0D)), a carriage return.
    * "\0" (ASCII 0 (0x00)), the NUL-byte.
    * "\x0B" (ASCII 11 (0x0B)), a vertical tab.
**/
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"), "");
}
