


/* ------------------------------------------------------------------------------- +

	File:		core.js
	Author:		Ben Nadel
	Desc:		These are base system functions.

+ ------------------------------------------------------------------------------- */


// This takes a variable, checks to see if it null or undefined
// and if so, then sets the default value
function ParamArgument(objArgument, objDefaultValue){
	// Check to see if the argument is defined
	if (objArgument && (typeof(objArgument).toString() != "undefined")){
		return(objArgument);
	} else {
		// The value has not been set so return the default value
		return(objDefaultValue);
	}
}
/* ------------------------------------------------------------------------------- +

	File:		validation.js
	Author:		Ben Nadel
	Date:		January 20, 2005
	Desc:		This has functions for validating objects.

+ ------------------------------------------------------------------------------- */


// Checks to see if an object is a button input
function IsButton(objButton){
	return(IsObjectOfTagNameAndType(objButton, "input", "button"));
}


// Checks to see if an object is a checkbox
function IsCheckBox(objCheckBox){
	return(IsObjectOfTagNameAndType(objCheckBox, "input", "checkbox"));
}


// Check to see if an input text box is empty
function IsInputEmpty(objInput){
	return(Trim(objInput.value).length == 0);
}


// Checks to see if the argument passed is a float
function IsFloat(objNumber){
	// Check to see if it is even a number and that it has a decimal
	if (objNumber && IsNumeric(objNumber) && (objNumber.toString().indexOf(".") >= 0)){
		return(true);
	} else {
		// It is not a number and therefore not a float
		return(false);
	}
}


// Checks to see if an object is a image input
function IsImageInput(objInput){
	return(IsObjectOfTagNameAndType(objInput, "input", "image"));
}


// Check to see if the argument passed is an integer
function IsInt(objNumber){
	// Check to see if it is even a number 
	if (objNumber && IsNumeric(objNumber)){
		// Check to see if the rounded version is same as non-rounded version
		return(objNumber == Math.round(objNumber));
	} else {
		return(false);
	}
}


// Checks to see if argument passed is a number
function IsNumeric(objNumber){
	if (objNumber){
		try {
			return(!isNaN(objNumber * 1));
		} catch(e) {
			return(false);
		}
	} else {
		return(false);
	}
}


// Checks to see if the given object is of type tag name
function IsObjectOfTagName(objNode, strTagName){
	if (
		objNode &&
		(typeof(objNode) == "object") &&
		(objNode.nodeType == 1) &&
		(objNode.tagName.toLowerCase() == strTagName.toLowerCase())
		){
		return(true);	
	} else {
		return(false);
	}
}


// Checks to see if the given object is of type tag name
// and has the given type attribute
function IsObjectOfTagNameAndType(objNode, strTagName, strType){
	if (
		IsObjectOfTagName(objNode, strTagName) &&
		(objNode.getAttribute("type").toLowerCase() == strType.toLowerCase())
		){
		return(true);
	} else {
		return(false);
	}
}


// Checks to see if an object is a radio box
function IsRadioBox(objRadio){
	return(IsObjectOfTagNameAndType(objRadio, "input", "radio"));
}


// Checks to see if an object is a reset button input
function IsResetButton(objButton){
	return(IsObjectOfTagNameAndType(objButton, "input", "reset"));
}


// Checks to see if an object is a select box
function IsSelectBox(objSelect){
	return(IsObjectOfTagName(objSelect, "select"));
}


// Checks to see if an object is a submit button input
function IsSubmitButton(objButton){
	return(IsObjectOfTagNameAndType(objButton, "input", "submit"));
}


// Checks to see if an object is a textarea
function IsTextArea(objTextArea){
	return(IsObjectOfTagName(objTextArea, "textarea"));
}


// Check to see if an email is of valid format
function IsValidEmail(strEmail){
	return(
		(strEmail.match(new RegExp("^[0-9a-z_]+[0-9a-z_\\.\\-]*@[0-9a-z_]+[0-9a-z_\\.\\-]*\\.[a-z]{2,5}$", "gi")) != null) &&
		(strEmail.match(new RegExp("(\\.{2,})|(-{2,})|(\\.-)|(-\\.)|((\\.|-)@)|(@(\\.|-))", "gi")) == null)
		);
}

/* ------------------------------------------------------------------------------- +

	File:		forms.js
	Author:		Ben Nadel
	Date:		February 02, 2005
	Desc:		This has functions for form-related actions.

+ ------------------------------------------------------------------------------- */

// This adds the given option to the given select object and then selects
// the new option
function AddAndSelectNewOption(objSelect, strText, strValue){
	objSelect.options[objSelect.options.length] = new Option(strText, strValue);
	
	// Select the last option
	objSelect.selectedIndex = (objSelect.options.length - 1);
}


// Forwards browser window to the given location string. If the form
// object was passed as a second argument, then the form will be disabled
function Cancel(strUrl, objForm){
	// If no form was passed, param it to be the data form
	objForm = ParamArgument(objForm, document.forms["data_form"]);

	// Check to see if the form was passed
	if (objForm){
		DisableForm(objForm);
	}
	
	// Redirect browser
	window.location.href = strUrl;
}


// This checkes all the checkboxes with the given name in the given form
function CheckAllCheckBoxesWithName(objForm, strName){
	var objBoxes = objForm[strName];
	
	// Check to make sure we have a valid checkbox element(s)
	if (objBoxes){
		// We have a valid checkbox. The tricky thing here is that the 
		// checkbox may be single, or it may be acting as an array of
		// checkbox objects.
		
		// Check for length
		if (objBoxes.length){
			// We have an array of checkboxes
			
			// Loop over the checkboxes 
			for (var i = 0 ; i < objBoxes.length ; i++){
				objBoxes[i].checked = true;
			}
			
		} else {
			// We have a single checkbox, so check it
			objBoxes.checked = true;
		}	
	}
	
	return;
}


// This confirms that the user wants to navigate away from a form
// that may or may not have dirty information that needs to be saved
/*
function ConfirmDirtyFormSubmission(){
	try {
		event.returnValue = "You are about to leave a page that may have unsaved information.";
	} catch (error){
		// This browser cannot handle this
	}
}
*/

// Deletes the options with the given value 
function DeleteSelectOptionsByValue(objSelect, strValue){
	var arrOptions = objSelect.options;
	
	// Loop over options and convert selected to null
	for (var i = (arrOptions.length - 1) ; i >= 0 ; i--){
		// Check to see if the option has the deletable value
		if (arrOptions[i].value == strValue){
			// Make this option null 
			arrOptions[i] = null;
		}
	}
}


// Deletes the selected options from the select box
function DeleteSelectedOptions(objSelect){
	var arrOptions = objSelect.options;
	
	// First, move all the selected options to the bottom
	MoveSelectedOptionsToBottom(objSelect);
	
	// Now, loop over options and convert selected to null
	for (var i = (arrOptions.length - 1) ; i >= 0 ; i--){
		// Check to see if the option is selected
		if (arrOptions[i].selected){
			// Make this option null 
			arrOptions[i] = null;
		}
	}
}


// This is called when submitting a form. It will go through the 
// form elements and disable all the buttons, submits and otherwise.
function DisableForm(objForm){
	for (var i = 0 ; i < objForm.elements.length ; i++){
		if (objForm.elements[i].tagName.toLowerCase() == "input"){
			if ((objForm.elements[i].type.toLowerCase() == "button") ||
				(objForm.elements[i].type.toLowerCase() == "submit") ||
				(objForm.elements[i].type.toLowerCase() == "image")
				){
				// Disable the input
				objForm.elements[i].disabled = true;
				
				// Only change the class if it's not an image
				if (objForm.elements[i].type.toLowerCase() != "image"){
					//objForm.elements[i].className = "button-disabled";
				}
			}		
		}
		
		// Disable any events that might trigger a form-submit
		objForm.elements[i].onclick = null;
		objForm.elements[i].onchange = null;
		objForm.elements[i].onfocus = null;
		objForm.elements[i].onblur = null;
		objForm.elements[i].onkeydown = null;
		objForm.elements[i].onkeyup = null;
	}
	
	// Also, since the form has already been submitted, let's have it return false
	// if it tries to submit again. I am worried though that this might stop the
	//previous form submission.
	objForm.onsubmit = new function(){
		return(false);
	}
}


// This formats the phone number input
function FormatPhoneNumberInput(objInput){
	var strValue = objInput.value;
	var strPreValue = strValue;
	
	// Strip out the non-integer values
	strValue = StripNonInteger(strValue);
	
	// Strip out leading and training spaced
	strValue = strValue.replace(new RegExp("(^[ ]{1,})|([ ]{1,}$)", "gi"), "");
	
	// Check to see if the first digit is one. If so, then we have to delete it
	strValue = strValue.replace(new RegExp("(^[1]{1})", "gi"), "");
	
	// Check to see what length we have
	if (strValue.length <= 7){
		// Format the number to be 999-9999
		objInput.value = NumberMask(strValue, "999-9999");
	} else if (strValue.length <= 10){
		// Forma the number to be (999) 999-9999
		objInput.value = NumberMask(strValue, "(999) 999-9999");
	} else {
		// This is an invalid length, so just put old value back in
		objInput.value = strPreValue;
	}
}


// THis formats the Url input field. It makes user that the URL starts with
// "http://" if it doesn, then it is prepended to the url
function FormatUrlInput(objInput){
	var strValue = Trim(objInput.value);
	
	// Only check input IF we have a length
	if (strValue.trim().length > 0){	
		// Check to see if the http is found (will also pass if https)
		if (!strValue.match(new RegExp("(^https?://)"))){
			// The Url is not formatted properly. Set it.
			objInput.value = ("http://" + strValue);
		}
	}
	
	return;
}


// This creates a deliniated list of values of all the options
// in the given select box. It uses both the selected and the 
// non-selected options when building the list.
function GetSelectOptionsValueList(objSelect, strDelimiter){
	var arrOptions = objSelect.options;
	var strValueList = "";
	strDelimiter = ParamArgument(strDelimiter, ",");
	
	// Loop over the options and get the values
	for (var i = 0 ; i < arrOptions.length ; i++){
		// Check to see if we need to append the delimiter
		if (i > 0){
			strValueList += strDelimiter;
		}
		
		// Append the next value
		strValueList += arrOptions[i].value;
	}
	
	// Return the value list
	return(strValueList);
}


// This creates a deliniated list of values of only the options
// in the given select box that are currently selected.
function GetSelectedOptionsValueList(objSelect, strDelimiter){
	var arrOptions = objSelect.options;
	var strValueList = "";
	strDelimiter = ParamArgument(strDelimiter, ",");
	
	// Loop over the options and get the values
	for (var i = 0 ; i < arrOptions.length ; i++){
		// Check to see if the option is selected
		if (arrOptions[i].selected){
			// Check to see if we need to append the delimiter
			if (strValueList.length > 0){
				strValueList += strDelimiter;
			}
			
			// Append the next value
			strValueList += arrOptions[i].value;
		}
	}
	
	// Return the value list
	return(strValueList);
}


// This moves the selected options in the specified direction, and then
// updates the input that holds the value list of ALL the options.
function MoveSelectedOptionsAndUpdateValueList(objSelect, strDirection, objInput, strDelimiter){
	strDelimiter = ParamArgument(strDelimiter, ",");

	// Check to see which direction
	switch (strDirection){
		case "TOP":
			MoveSelectedOptionsToTop(objSelect);
			break;
		case "UP":
			MoveSelectedOptionsUp(objSelect);
			break;
		case "DOWN":
			MoveSelectedOptionsDown(objSelect);
			break;
		case "BOTTOM":
			MoveSelectedOptionsToBottom(objSelect);
			break;
	}
	
	// Now, update the value list
	objInput.value = GetSelectOptionsValueList(objSelect, strDelimiter);
}


// Moves the selected options in a select box down
function MoveSelectedOptionsDown(objSelect){
	var arrOptions = objSelect.options;
	
	// Check to make sure the select has more than one size
	if (objSelect.size > 1){
	
		// Loop over the options and swap out
		for (var i = (arrOptions.length - 2) ; i >= 0 ; i--){
			// Check to see that the current option is highlighted and
			// that the one above it is NOT highlighted
			if (arrOptions[i].selected && !arrOptions[i+1].selected){
				// Swap options
				SwapSelectOptions(arrOptions[i], arrOptions[i+1]);
			}
		}
		
	}
}


// Moves the selected options to the bottom of the select box
function MoveSelectedOptionsToBottom(objSelect){
	var arrOptions = objSelect.options;
	
	// Check to make sure the select has more than one size
	if (objSelect.size > 1){
	
		// Loop over the array and swap options
		for (var i = 0 ; i <= (arrOptions.length - 2) ; i++){
			// Do a double loop to make sure the selected one always moves as low
			// as it can possibly go
			for (var j = (arrOptions.length - 2) ; j >= i ; j--){
				// Check to see if the current option is selected and 
				// that the next option is NOT selected
				if (arrOptions[j].selected && !arrOptions[j+1].selected){
					// Swap these two options
					SwapSelectOptions(arrOptions[j], arrOptions[j+1]);
				}
			}
		}
		
	}
}


// Moves the selected options to the top of the select box
function MoveSelectedOptionsToTop(objSelect){
	var arrOptions = objSelect.options;
	
	// Check to make sure the select has more than one size
	if (objSelect.size > 1){
		
		// Loop over the array and swap options
		for (var i = arrOptions.length ; i >= 0 ; i--){
			// Do a double loop to make sure the selected one always moves as high
			// as it can possibly go
			for (var j = 1 ; j < i ; j++){
				// Check to see if the current option is selected and 
				// that the previous option is NOT selected
				if (arrOptions[j].selected && !arrOptions[j-1].selected){
					// Swap these two options
					SwapSelectOptions(arrOptions[j], arrOptions[j-1]);
				}
			}
		}
		
	}
}


// Moves the selected options in a select box up
function MoveSelectedOptionsUp(objSelect){
	var arrOptions = objSelect.options;
	
	// Check to make sure the select has more than one size
	if (objSelect.size > 1){
	
		// Loop over the options and swap out
		for (var i = 1 ; i < arrOptions.length ; i++){
			// Check to see that the current option is highlighted and
			// that the one above it is NOT highlighted
			if (arrOptions[i].selected && !arrOptions[i-1].selected){
				// Swap options
				SwapSelectOptions(arrOptions[i], arrOptions[i-1]);
			}
		}
		
	}
}


// This assumes that there is an attribute in an input box called "defaultvalue". 
// This removes the value of a text field if it is equal to the default value.
function RemoveInputDefaultValue(objInput){
	var strDefaultValue = ParamArgument(objInput.getAttribute("defaultvalue"), "");
	
	// Check to see if the current value is the default value
	if (objInput.value == strDefaultValue){
		// It is the default value, so remove it
		objInput.value = "";
	} 
}


// This sets the focus to the default element of the form, but only if the 
// form is not dirty, otherwise we may be interupting the user experience
function SetFormDefaultElementFocus(strElementName){
	var objForm = document.forms["data_form"];
	var objDefaultElement = objForm.elements[strElementName];
	var objDirtyBit = objForm.elements["form_dirty_bit"];
	var blnIsDirty = (objDirtyBit.value == "1");
	
	
	// Check to see if the default element exists and that the form is 
	// not dirty (ie. it has not been accessed by the user.
	if (objDefaultElement && !blnIsDirty){
		// The form should be good to throw focus
		objDefaultElement.focus();
	}
}


// This assumes that there is an attribute in an input box called "defaultvalue". 
// This puts the default value into the text field on blur if the text field is empty.
function SetInputDefaultValue(objInput){
	var strDefaultValue = ParamArgument(objInput.getAttribute("defaultvalue"), "");
	
	// Check to see if the current value is empty
	if (objInput.value == ""){
		// It is empty, so put the default value back in
		objInput.value = strDefaultValue;
	} 
}


// This sorts the options of the given select box in an Ascending 
// alphabetical manner based on the option text values.
function SortOptionsAlphabetically(objSelect){
	var arrOptions = objSelect.options;
	
	// Check to make sure the select has more than one size
	if (objSelect.size > 1){
	
		// When doing a bubble sort, we want to start out going to the
		// end of the options list. However, since the heaviest value
		// will always fall to the bottom on each iteration, we don't
		// need to keep going to the end of the list. Therefore, subtract
		// one from the end each time.
		for (var intEnd = (arrOptions.length - 1) ; intEnd > 0 ; intEnd--){
			// On the inner loop, we want to start at the top of the list
			// and keep going till be meet the end of where we need to be.
			// Since we don't want to do extra work, just go to intEnd 
			// and not to the physical end of the list.
			for (var i = 0 ; i < intEnd ; i++){
				// Check to see if the current option text is great than
				// the next one. 
				if (arrOptions[i].text > arrOptions[i+1].text){
					// The text is great and therefore we need to swap the
					// two options.
					SwapSelectOptions(arrOptions[i], arrOptions[i+1]);
				}			
			}		
		}
	
	}
}


// This sorts the given select box alphabetically based on the text
// and then updates the given input value list with the values of 
// the newly sorted select box.
function SortOptionsAlphabeticallyAndUpdateValueList(objSelect, objInput, strDelimiter){
	// Sort the options alphabetically 
	SortOptionsAlphabetically(objSelect);

	// Now, update the value list
	objInput.value = GetSelectOptionsValueList(objSelect, strDelimiter);
}


// This merely submits the data form and then disables it.
function SubmitForm(objForm){
	objForm = ParamArgument(objForm, document.forms["data_form"]);
	
	// Submit the form
	objForm.submit();
	
	// Disable the current form to remove duplicate submissions
	DisableForm(objForm);
}


// This submits the form directly to a new action page, no going back 
// to the same page to process form information first. This should be
// used when going from a list page to detail action page. Especially
// useful when you are passing around "wizzard" type data.
function SubmitFormWithAction(strAction, strActionID){
	var objForm = document.forms["data_form"];
	var objAction = objForm.elements["action"];
	var objUniqueID = objForm.elements["unique_id"];
	var objSubmitted = objForm.elements["submitted"];
	var objDataBaseID = null;
	strActionID = ParamArgument(strActionID, "0");
	
	// The value of the unique id field should hold the name of the 
	// unique id value that we are using from the database. 
	objDataBaseID = objForm.elements[objUniqueID.value];
	
	// Make sure that submitted is zero since we are going to a new page
	objSubmitted.value = "0";
	
	// Set the action for the new page
	objAction.value = strAction;
	
	// Set the unique id for the new page if we have a unique id
	if (objDataBaseID){
		objDataBaseID.value = strActionID;
	}
	
	// Submit the form 
	SubmitForm(objForm);
}


// This is used with the data_form form pages. It submits the form back 
// to the same page after setting the new_action input value. Of course, we
// don't want to submit back to the page if we have not made any changes. So, 
// we are attempting to find out if the form has been changed... if it is dirty.
// However, this is only true if we have a unique id value - if we don't there might
// be required info on this page.
function SubmitFormWithNewAction(strNewAction){
	var objForm = document.forms["data_form"];
	var objActionURL = objForm.elements["action_url"];
	var objNewAction = objForm.elements["new_action"];
	var objUniqueID = objForm.elements["unique_id"];
	var objDataBaseID = objForm.elements[objUniqueID.value];
	var blnDirty = (objForm.elements["form_dirty_bit"].value == "1") ? true : false ;
	
	// Set the new action
	objNewAction.value = strNewAction;
	
	// Submit the form
	SubmitForm(objForm);
	
	
	/*
	// Check to see if the form is dirty
	if (blnDirty || (parseInt(objDataBaseID.value) == 0)){
		// The form is dirty, so we DO want to submit the form back to itself
		
		// Set the new action
		objNewAction.value = strNewAction;
		
		// Submit the form
		SubmitForm(objForm);
		
	} else {
		// The form is NOT dirty, so don't waste time submitting it back to itself. Just
		// set the location based on the actions and ids 
		
		// Set the url in format:
		// URL...?action=NEW_ACTION&UNIQUE_ID=ID
		location.href = (
			objActionURL.value + "?action=" + 
			strNewAction + "&" + 
			objUniqueID.value + "=" + 
			objDataBaseID.value
			);
			
	}
	*/
}


// This is used with the data_form form pages. It submits the form back 
// to the same page after setting the new_action_gorup input value. Of course, 
// we don't want to submit back to the page if we have not made any changes. So, 
// we are attempting to find out if the form has been changed... if it is dirty.
// However, this is only true if we have a unique id value - if we don't there might
// be required info on this page.
function SubmitFormWithNewActionGroup(strNewActionGroup){
	var objForm = document.forms["data_form"];
	var objActionURL = objForm.elements["action_url"];
	var objNewActionGroup = objForm.elements["new_action_group"];
	var objUniqueID = objForm.elements["unique_id"];
	var objDataBaseID = objForm.elements[objUniqueID.value];
	var blnDirty = (objForm.elements["form_dirty_bit"].value == "1") ? true : false ;
	
	// Set the new action
	objNewActionGroup.value = strNewActionGroup;
	
	// Submit the form
	SubmitForm(objForm);
	
	/*
	// Check to see if the form is dirty
	if (blnDirty || (parseInt(objDataBaseID.value) == 0)){
		// The form is dirty, so we DO want to submit the form back to itself
		
		// Set the new action
		objNewActionGroup.value = strNewActionGroup;
		
		// Submit the form
		SubmitForm(objForm);
		
	} else {
		// The form is NOT dirty, so don't waste time submitting it back to itself. Just
		// set the location based on the actions and ids 
		
		// Set the url in format:
		// URL...?action=NEW_ACTION&UNIQUE_ID=ID
		location.href = (
			objActionURL.value + "?action_group=" + 
			strNewActionGroup + "&" + 
			objUniqueID.value + "=" + 
			objDataBaseID.value
			);
	}
	*/
}


// This is used to submit a form after changing the column you want to 
// sort on. If you change the current sort column to itself, it will 
// merely change the sort direction. Otherwise, it will change the 
// sort and the direction will default to ASC
function SubmitFormWithNewSort(strSortName){
	var objForm = document.forms["data_form"];
	var objSortBy = objForm.elements["search_sort_by"];
	var objSortByDirection = objForm.elements["search_sort_by_direction"];
	
	// Check to see if we have valid sort elements
	if (objSortBy && objSortByDirection){
		// The elements exist, so now check to see if we are picking a
		// new column, or just changing direction
		if (objSortBy.value == strSortName){
			// We are just changing direction on the same column
			
			// Change the current sort direction
			objSortByDirection.value = (objSortByDirection.value == "ASC") ? "DESC" : "ASC" ;
			
		} else {
			// We are sorting on a new column
			
			// Chance column and set direction to asc
			objSortBy.value = strSortName;
			objSortByDirection.value = "ASC";
		}		
	}	
	
	// Submit the form
	SubmitForm(objForm);
}


// This is used to submit a form after changing one value in the form. This
// is meant to stay in the same type of page, but change a property of it.
// For example, for paging through a list, this might change the offset value
// then resubmit the form. This method can take multiples of two arguments.
function SubmitFormWithNewValue(strElementName, strValue){
	var objForm = document.forms["data_form"];
	var objElement = objForm.elements[strElementName];
	
	// Loop over the arguments in two to set values
	for (var i = 0 ; i < arguments.length ; i+=2){
		// Get the element
		objElement = objForm.elements[arguments[i]];
		
		// Check to see if we have a valid argument 
		if (objElement){
			// The element exists, so set the value
			objElement.value = arguments[i + 1];
		}
	}
	
	/*
	// Check to see if we have a valid element
	if (objElement){
		// The element exists, so set the value
		objElement.value = strValue;
	}	
	*/
	
	// Submit the form
	SubmitForm(objForm);
}


// This is meant to submit the form, process the data, and then refresh
// the page with no values. This is used to add multiple items in a row
// without having to leave the page.
function SubmitFormWithPageRefresh(){
	var objForm = document.forms["data_form"];
	var objRefresh = objForm.elements["page_refresh"];
	
	// Set the page refresh
	objRefresh.value = "1";
	
	// Submit the form
	SubmitForm(objForm);
}


// This is used with the data_form form pages. It submits the form back
// to the same page after it sets up the sub action and the sub action
// id input values.
function SubmitFormWithSubAction(strSubAction, strSubActionID){
	var objForm = document.forms["data_form"];
	var objSubAction = objForm.elements["sub_action"];
	var objSubActionID = objForm.elements["sub_action_id"];
	
	// Set the sub action and action id
	objSubAction.value = strSubAction;
	objSubActionID.value = strSubActionID;
	
	// Submit the form
	SubmitForm(objForm);
}


// This basically submits the form with a sub action but no sub action ID.
// It is a bit of a hack, but it basically gets the form to submit back 
// to itself for "Update Data" type links.
function SubmitFormWithUpdate(){
	// Submit the form with sub action
	SubmitFormWithSubAction("update", "0");
}


// This swaps two options in a select box
function SwapSelectOptions(objOption1, objOption2){
	var objTempOption = new Option("", "");
	var arrProperties = new Array("text","value","className","selected");
	
	// Move all the properties of option 2 into the temp option
	for (var i = 0 ; i < arrProperties.length ; i++){
		objTempOption[ arrProperties[i] ] = objOption2[ arrProperties[i] ];
	}
	
	// Move all the properties of option 1 into option 2
	for (var i = 0 ; i < arrProperties.length ; i++){
		objOption2[ arrProperties[i] ] = objOption1[ arrProperties[i] ];
	}
	
	// Move all the properties of the temp option back to option 1
	for (var i = 0 ; i < arrProperties.length ; i++){
		objOption1[ arrProperties[i] ] = objTempOption[ arrProperties[i] ];
	}
}


// This transfers the selected options of the source select box to the
// options list of the destination select box.
function TransferSelectedOptions(objSourceSelect, objDestinationSelect){
	var arrSourceOptions = objSourceSelect.options;
	var arrDestinationOptions = objDestinationSelect.options;
	
	// Loop over the source options to find the selected ones
	for (var i = 0 ; i < arrSourceOptions.length ; i++){
		// Check to see if this one is selected
		if (arrSourceOptions[i].selected){
			// This option is selected, so transfer it
			
			// Add the option the destination list
			arrDestinationOptions[arrDestinationOptions.length] = new Option(
				arrSourceOptions[i].text,
				arrSourceOptions[i].value
				);
		
			// Select the newly transfered option
			// arrDestinationOptions[arrDestinationOptions.length - 1].selected = true;
		}
	}	
	
	// Loop over the source select backwards and remove the selected items
	// so that we don't keep duplicate records.
	for (var i = (arrSourceOptions.length - 1) ; i >= 0 ; i--){
		// Check to see if this one is selected
		if (arrSourceOptions[i].selected){
			// This option is selected, so nullify it
			arrSourceOptions[i] = null;
		}
	}
}


// This transfers options from one select to another and then updates
// the given value list with the options of the destination select box.
function TransferSelectedOptionsAndUpdateValueList(objSourceSelect, objDestinationSelect, objValueListSelect, objInput, strDelimiter){
	// Transfer the selected options
	TransferSelectedOptions(objSourceSelect, objDestinationSelect);
	
	// Now, update the value list
	objInput.value = GetSelectOptionsValueList(objValueListSelect, strDelimiter);
}


// This uncheckes all the checkboxes with the given name in the given form
function UncheckAllCheckBoxesWithName(objForm, strName){
	var objBoxes = objForm[strName];
	
	// Check to make sure we have a valid checkbox element(s)
	if (objBoxes){
		// We have a valid checkbox. The tricky thing here is that the 
		// checkbox may be single, or it may be acting as an array of
		// checkbox objects.
		
		// Check for length
		if (objBoxes.length){
			// We have an array of checkboxes
			
			// Loop over the checkboxes 
			for (var i = 0 ; i < objBoxes.length ; i++){
				objBoxes[i].checked = false;
			}
			
		} else {
			// We have a single checkbox, so check it
			objBoxes.checked = false;
		}	
	}
	
	return;
}
/* ------------------------------------------------------------------------------- +

	File:		dom.js
	Author:		Ben Nadel
	Date:		January 20, 2005
	Desc:		This has functions for accessing the document object model.

+ ------------------------------------------------------------------------------- */


// Gets the first child of this node with the given class name
function GetChildWithClassName(objNode, strClassName){
	var objChildNode = null;
	
	// Check to see if we are working with a valid node
	if (objNode && (objNode.childNodes.length > 0)){
		// Loop through the children and check for tag name
		for (var i = 0 ; i < objNode.childNodes.length ; i++){
			// Check to see if this child is the one we are looking for
			if (
				objNode.childNodes[i] && 
				(objNode.childNodes[i].nodeType == 1) &&
				(objNode.childNodes[i].className.toLowerCase() == strClassName.toLowerCase())
				){
				// We found the correct child, so return it
				return(objNode.childNodes[i]);
			} else {
				// We didn't find the correct node, so run through its children
				objChildNode = GetChildWithClassName(objNode.childNodes[i], strClassName);
				
				// Check to see if we found the child
				if (objChildNode){
					return(objChildNode);
				}
			}
		}	
		
		// We have not found it at this point, so return null
		return(null);
	} else {
		return(null);
	}
}


// Gets the first child of this node with the given tag name
function GetChildWithTagName(objNode, strTagName){
	var objChildNode = null;
	
	// Check to see if we are working with a valid node
	if (objNode && (objNode.childNodes.length > 0)){
		// Loop through the children and check for tag name
		for (var i = 0 ; i < objNode.childNodes.length ; i++){
			// Check to see if this child is the one we are looking for
			if (
				objNode.childNodes[i] && 
				(objNode.childNodes[i].nodeType == 1) &&
				(objNode.childNodes[i].tagName.toLowerCase() == strTagName.toLowerCase())
				){
				// We found the correct child, so return it
				return(objNode.childNodes[i]);
			} else {
				// We didn't find the correct node, so run through its children
				objChildNode = GetChildWithTagName(objNode.childNodes[i], strTagName);
				
				// Check to see if we found the child
				if (objChildNode){
					return(objChildNode);
				}
			}
		}	
		
		// We have not found it at this point, so return null
		return(null);
	} else {
		return(null);
	}
}


// Gets the next sibling with the given class name
function GetNextSiblingWithClassName(objNode, strClassName){
	var objSibling = objNode.nextSibling;
	strClassName = strClassName.toLowerCase();
	 
	// Loop over siblings until you get null or the correct node
	while (objSibling){
		if (
			(objSibling.nodeType == 1) &&
			(objSibling.className.toLowerCase() == strClassName)
			){
			return(objSibling);
		} else {
			objSibling = objSibling.nextSibling;
		}
	}	
	 
	return(objSibling);
}


// Gets the next sibling with the given tag name
function GetNextSiblingWithTagName(objNode, strTagName){
	var objSibling = objNode.nextSibling;
	strTagName = strTagName.toLowerCase();
	 
	// Loop over siblings until you get null or the correct node
	while (objSibling){
		if (
			(objSibling.nodeType == 1) &&
			(objSibling.tagName.toLowerCase() == strTagName)
			){
			return(objSibling);
		} else {
			objSibling = objSibling.nextSibling;
		}
	}	
	 
	return(objSibling);
}


// Gets the first parent of this node with the given class name
function GetParentWithClassName(objNode, strClassName){
	// Check to see if we are working with a valid node
	if (objNode && objNode.parentNode){
		// Get the parent node
		objNode = objNode.parentNode;
		
		// Check to see if the node is the one we are looking for
		if (
			(objNode.nodeType == 1) &&
			(objNode.className.toLowerCase() == strClassName.toLowerCase())
			){
			// We found the correct node, so return it
			return(objNode);
		} else {
			// We didn't find it, so search higher
			return(GetParentWithClassName(objNode, strClassName));
		}
	} else {
		return(null);
	}
}


// Gets the first parent of this node with the given tag name
function GetParentWithTagName(objNode, strTagName){
	// Check to see if we are working with a valid node
	if (objNode && objNode.parentNode){
		// Get the parent node
		objNode = objNode.parentNode;
		
		// Check to see if the node is the one we are looking for
		if (
			(objNode.nodeType == 1) &&
			(objNode.tagName.toLowerCase() == strTagName.toLowerCase())
			){
			// We found the correct node, so return it
			return(objNode);
		} else {
			// We didn't find it, so search higher
			return(GetParentWithTagName(objNode, strTagName));
		}
	} else {
		return(null);
	}
}


// Gets the previous sibling with the given class name
function GetPreviousSiblingWithClassName(objNode, strClassName){
	var objSibling = objNode.previousSibling;
	strClassName = strClassName.toLowerCase();
	 
	// Loop over siblings until you get null or the correct node
	while (objSibling){
		if (
			(objSibling.nodeType == 1) &&
			(objSibling.className.toLowerCase() == strClassName)
			){
			return(objSibling);
		} else {
			objSibling = objSibling.previousSibling;
		}
	}	
	 
	return(objSibling);
}
/* ------------------------------------------------------------------------------- +

	File:		text.js
	Author:		Ben Nadel
	Date:		January 21, 2005
	Desc:		This has functions for manipulating text strings.

+ ------------------------------------------------------------------------------- */


// This is a trim function that will now be part of the basic 
// String core class for javascript.
String.prototype.trim = function() {
	return(
		this.replace(
			new RegExp("(^[\\s]+)|([\\s]+$)", "gim"),
			""
			)
		);
}


// Gets a substring from the left of count length
function Left(strText, intCount){
	return(strText.substring(0, intCount));
}


// Deletes the left characters of length count
function LeftDelete(strText, intCount){
	return(strText.substring(intCount));
}


// Trims white space from left of a string
function LeftTrim(strText){
	return(
		strText.replace(new RegExp("(^\\s*)", "gim"), "")
		);
}


// This gets a substring from within a string starting at the index, of length count
function Mid(strText, intIndex, intCount){
	return(strText.substring(intIndex, (intIndex + intCount)));
}


// This function deletes the given subsection of a string starting 
// at the index of length count
function MidDelete(strText, intIndex, intCount){
	return(
		strText.substring(0, intIndex) +
		strText.substring((intIndex + intCount), strText.length)
		);
}


// This wraps text around a substring of the given string
function MidSurround(strText, intIndex, intCount, strStart, strEnd){
	return(
		Left(strText, intIndex) +
		strStart + 
		Mid(strText, intIndex, intCount) +
		strEnd + 
		strText.substring((intIndex + intCount), strText.length)
		);
}


// This taks a number and formats it using the given mask. The mask
// is composed of any characters, but the character "9" is used as a 
// place holder for the digits in the number passed. For example, 
// you can pass this as a phone number mask: (999) 999-9999
function NumberMask(strNumber, strMask){
	var strOutput = "";
	var intIndex = 0;
	var intNumIndex = 0;
	
	// Make sure that the number is a string
	strNumber = strNumber.toString();
	
	// Loop through the mask characters
	for (intIndex = 0 ; intIndex < strMask.length ; intIndex++){
		// Check to see if the current character is a place holder 
		// "9" or just another character. If we have a place holder, then
		// we also have to check to make sure we have a digit available.
		// If the digit is not available (ie. we have used up all of our number)
		// then let's break out of the loop.
		if (intNumIndex < strNumber.length){
			// We have a number, so check the mask
			
			if (strMask.charAt(intIndex) == "9"){
				// We have a place holder and an avilable digit, so grab another 
				// character from the number and add it to the output.
				
				strOutput = (strOutput + strNumber.charAt(intNumIndex++));
			} else {
				// We don't have a place holder, so just take the number from 
				// the mask and add it to the output.
				
				strOutput = (strOutput + strMask.charAt(intIndex));
			}
			
		} else {
			// We have run out of numbers, so just break out of the loop
			
			break;
		}
	}
	
	// The mask has been applied, so return the output
	return(strOutput);
}


// Gets a substring from the right of count length
function Right(strText, intCount){
	return(strText.substring((strText.length - intCount), strText.length));
}


// Deletes the right characters of length count
function RightDelete(strText, intCount){
	return(strText.substring(0, (strText.length - intCount)));
}


// Trims white space from the right of a string
function RightTrim(strText){
	return(
		strText.replace(new RegExp("([\\s]{1,}$)", "gim"), "")
		);
}


// This strips non-integer characters from the string. It 
// allows only digits 0-9.
function StripNonInteger(strText){
	return(
		strText.replace(new RegExp("[^0-9]{1,}", "gi"), "")
		);
}


// Trims the outlier spaces in a string
function Trim(strText){
	return(
		LeftTrim(
			RightTrim(strText)
			)
		);
}
/* ------------------------------------------------------------------------------- +

	File:		math.js
	Author:		Ben Nadel
	Desc:		This has functions for manipulating numbers.

+ ------------------------------------------------------------------------------- */


// This gets an integer between the two given integers (outliers included)
function RandRange(intStart, intEnd){
	// Make sure we have integers
	intStart = Math.floor(intStart);
	intEnd = Math.floor(intEnd);
	
	// Return the random number
	return(
		intStart + 
		(Math.floor(Math.random() * (new Date()).getMilliseconds() * intEnd) % (intEnd - intStart + 1))	
		);
}

/* ------------------------------------------------------------------------------- +

	File:		images.js
	Author:		Ben Nadel
	Date:		January 19, 2005
	Desc:		This has functions for manipulating images.

+ ------------------------------------------------------------------------------- */


// Swaps images in the document with javascript images
function SwapImages(){
	var Args = arguments;
	
	for (var i = 0 ; i < Args.length ; i+=2){
		document.images[ Args[i] ].src = Args[i+1].src;
	}
}
/* ------------------------------------------------------------------------------- +

	File:		preload.js
	Author:		Ben Nadel
	Date:		February 08, 2005
	Desc:		This preloads any images that are needed by the current page. 
				Page can be determined through ENV.PP and ENV.SP values.

+ ------------------------------------------------------------------------------- */




/* ------------------------------------------------------------------------------- +

	File:		custom.js
	Author:		Ben Nadel
	Desc:		These are functions that are custom to this application and no
				where else.

+ ------------------------------------------------------------------------------- */

// This adds the given value/text combination to the given sort box
function AddOptionToSortBox(objForm, strSelectBoxName, strText, strValue){
	var objSelectBox = objForm.elements[strSelectBoxName + "_select_box"];
	var objSelectBoxValueList = objForm.elements[strSelectBoxName];
	var blnExists = false;
	
	// Before we add the option, we want to make sure it doesn't already exist 
	for (var i = 0 ; i < objSelectBox.options.length ; i++){
		if (objSelectBox.options[i].value == strValue){
			blnExists = true;
		}
	} 
	
	// Check to see if the value already existed 
	if (!blnExists){
		// Add the option to the select box
		objSelectBox.options[objSelectBox.options.length] = new Option(strText, strValue);
		
		// Upate the value list
		objSelectBoxValueList.value = GetSelectOptionsValueList(objSelectBox);
	}
}


// This pops up the window used to browser for Urls
function PopBrowser(strTargetField){
	var intWidth = 700;
	var intHeight = 550;
	var intWindowWidth = (window.innerWidth) ? (window.innerWidth) : ( (document.body.clientWidth) ? document.body.clientWidth : 0 );
	var intWindowHeight = (window.innerHeight) ? (window.innerHeight) : ( (document.body.clientHeight) ? document.body.clientHeight : 0 );
	var intTop = Math.floor((intWindowHeight / 2) - (intHeight / 2));
	var intLeft = Math.floor((intWindowWidth / 2) - (intWidth / 2));
	var strProperties = "";
	
	// set top and left to zero
	intTop = 50;
	intLeft = 50;
	
	// Set up properties
	strProperties = (strProperties + "width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft + ",status=yes");
	
	objWindow = window.open(
		(ENV.WebRoot + "pop/url_browser.cfm?target_field=" + strTargetField + "&base_url=" + escape(document.forms["data_form"].elements[strTargetField].value)), 
		"", 
		strProperties
		);
		
	// Move the window to the center if it didn't center when openening
	objWindow.moveTo(intLeft, intTop);
		
	objWindow.focus();
}


// This pops up the pop-up calendar window
function PopDateSelectCalendar(strURL){
	var intWidth = 250;
	var intHeight = 202;
	var objWindow = null;
	var intWindowWidth = (window.innerWidth) ? (window.innerWidth) : ( (document.body.clientWidth) ? document.body.clientWidth : 0 );
	var intWindowHeight = (window.innerHeight) ? (window.innerHeight) : ( (document.body.clientHeight) ? document.body.clientHeight : 0 );
	var intTop = Math.floor((intWindowHeight / 2) - (intHeight / 2));
	var intLeft = Math.floor((intWindowWidth / 2) - (intWidth / 2));
	var strProperties = "";
	
	// set top and left to zero
	intTop = 50;
	intLeft = 50;
	
	// Set up properties
	strProperties = (strProperties + "width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft);
	
	// Open window 
	objWindow = window.open(strURL, "", strProperties);
	
	// Move the window to the center if it didn't center when openening
	objWindow.moveTo(intLeft, intTop);
		
	objWindow.focus();
		
	// Return reference to the window
	return(objWindow);	
}


// This opens up a mini editing wizard
function PopMiniWizard(strType, strWindowName){
	var objWindow = null;
	var intWidth = 100;
	var intHeight = 100;
	var strProperties = "";
	var intWindowWidth = (window.innerWidth) ? (window.innerWidth) : ( (document.body.clientWidth) ? document.body.clientWidth : 0 );
	var intWindowHeight = (window.innerHeight) ? (window.innerHeight) : ( (document.body.clientHeight) ? document.body.clientHeight : 0 );
	var intTop = 0;
	var intLeft = 0;
	
	// set top and left to zero
	intTop = 50;
	intLeft = 50;
	
	// Check to see which type so we can set the properties
	switch (strType){
		case "COMPANY":
			intWidth = 650;
			intHeight = 535;
			break;
		case "POSITIONS":
			intWidth = 450;
			intHeight = 200;
			break;
		case "SCHOOLS":
			intWidth = 450;
			intHeight = 200;
			break;
		case "CONTACTS":
			intWidth = 450;
			intHeight = 250;
			break;
		case "NEWSLETTERS":
			intWidth = 450;
			intHeight = 250;
			break;
		case "NEWSLETTER.ISSUES":
			intWidth = 450;
			intHeight = 250;
			break;
		case "DEGREES":
			intWidth = 450;
			intHeight = 200;
			break;
		case "MAJORS":
			intWidth = 450;
			intHeight = 200;
			break;
		case "LANGUAGES":
			intWidth = 450;
			intHeight = 200;
			break;
		case "REP.MATTER.CATEGORIES":
			intWidth = 450;
			intHeight = 200;
			break;
		case "CONTACT.ACTIVITY.CATEGORIES":
			intWidth = 450;
			intHeight = 200;
			break;
		case "CONTACT.HONOR.CATEGORIES":
			intWidth = 450;
			intHeight = 200;
			break;
	}
	
	// Set top and left of the pop-up window
	intTop = Math.floor((intWindowHeight / 2) - (intHeight / 2));
	intLeft = Math.floor((intWindowWidth / 2) - (intWidth / 2));
	
	// Set up properties
	strProperties = (strProperties + "width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft);
	
	// Pop open the window
	objWindow = window.open("", strWindowName, strProperties);

	// Move the window to the center if it didn't center when opening
	objWindow.moveTo(intLeft, intTop);
		
	objWindow.focus();
		
	// Return reference to the window
	return(objWindow);
}


// This pops up the rich editor
function PopRichEditor(strTargetField, strTitleField, strTitle){
	var objForm = document.forms["data_form"];
	var intWidth = 720;
	var intHeight = 480;
	var intWindowWidth = (window.innerWidth) ? (window.innerWidth) : ( (document.body.clientWidth) ? document.body.clientWidth : 0 );
	var intWindowHeight = (window.innerHeight) ? (window.innerHeight) : ( (document.body.clientHeight) ? document.body.clientHeight : 0 );
	var intTop = Math.floor((intWindowHeight / 2) - (intHeight / 2));
	var intLeft = Math.floor((intWindowWidth / 2) - (intWidth / 2));
	var strProperties = "";
	
	// set top and left to zero
	intTop = 50;
	intLeft = 50;
	
	// Check to see if the title field exists 
	if ((strTitleField.length > 0) && (objForm.elements[strTitleField]) && (strTitle.length == 0)){
		strTitle = objForm.elements[strTitleField].value;
	}
	
	// Set up properties
	strProperties = (strProperties + "width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft + ",status=yes");
	
	
	objWindow = window.open(
		(ENV.WebRoot + "pop/xstandard.cfm?target_field=" + strTargetField + "&title=" + escape(strTitle)), 
		"", 
		strProperties
		);
}


// This pops up a window to view the url in a given url input url field 
function PopUrlField(strFieldName){
	var objWindow = null;
	var objForm = document.forms["data_form"];
	var objInput = objForm.elements[strFieldName];
	var intWidth = 640;
	var intHeight = 480;
	var strProperties = "";
	var intWindowWidth = (window.innerWidth) ? (window.innerWidth) : ( (document.body.clientWidth) ? document.body.clientWidth : 0 );
	var intWindowHeight = (window.innerHeight) ? (window.innerHeight) : ( (document.body.clientHeight) ? document.body.clientHeight : 0 );
	var intTop = 0;
	var intLeft = 0;
	
	// set top and left to zero
	intTop = 50;
	intLeft = 50;
	
	// Check to see if we have a url
	if (objInput.value.length > 0){
	
		// Set top and left of the pop-up window
		intTop = Math.floor((intWindowHeight / 2) - (intHeight / 2));
		intLeft = Math.floor((intWindowWidth / 2) - (intWidth / 2));
		
		// Set up properties
		strProperties = (strProperties + "width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft);
		strProperties = (strProperties + ",location=yes,status=yes,resizable=yes,menubar=yes,scrollbars=yes,titlebar=yes,toolbar=yes");
		
		// Pop open the window
		objWindow = window.open(objInput.value, "", strProperties);
	
		// Move the window to the center if it didn't center when opening
		objWindow.moveTo(intLeft, intTop);
			
		objWindow.focus();
		
	}
		
	// Return reference to the window
	return(objWindow);
}


// Pops up a generic window
function PopWindow(strWindowName){
	var objForm = document.forms["data_form"];
	var intWidth = 640;
	var intHeight = 480;
	var intWindowWidth = (window.innerWidth) ? (window.innerWidth) : ( (document.body.clientWidth) ? document.body.clientWidth : 0 );
	var intWindowHeight = (window.innerHeight) ? (window.innerHeight) : ( (document.body.clientHeight) ? document.body.clientHeight : 0 );
	var intTop = Math.floor((intWindowHeight / 2) - (intHeight / 2));
	var intLeft = Math.floor((intWindowWidth / 2) - (intWidth / 2));
	var strProperties = "";
	
	// set top and left to zero
	intTop = 50;
	intLeft = 50;
	
	// Set up properties
	strProperties = (strProperties + "width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft + ",status=yes");
	
	
	objWindow = window.open(
		"", 
		strWindowName, 
		strProperties
		);
		
	// Move the window to the center if it didn't center when openening
	objWindow.moveTo(intLeft, intTop);
		
	objWindow.focus();
}


// This previews the selected items of a double select box 
function PreviewDoubleSelectBoxSelections(objSelect1, objSelect2, objPreviewDiv){
	var arrOptions1 = objSelect1.options;
	var arrOptions2 = objSelect2.options;
	var objTextNode = null;
	var objSpanNode = null;
	var objBRNode = null;
	
	// Loop over the preview div to remove all of the children 
	for (var intNode = (objPreviewDiv.childNodes.length - 1) ; intNode >= 0 ;intNode --){
		objPreviewDiv.removeChild(
			objPreviewDiv.childNodes[intNode]
			);		
	}
	
	// Now, loop over the select boxes and add the option previews. 
	// Loop over the second one first since that is probably the more 
	// important one to preview
	for (var intIndex = 0 ; intIndex < arrOptions2.length ; intIndex++){
		// Check to see if the option is selected
		if (arrOptions2[intIndex].selected){
			// This option is selected, so preview it
			objSpanNode = document.createElement("span");
			objSpanNode.className = "move-left";
			objSpanNode.appendChild(document.createTextNode("<<- " + arrOptions2[intIndex].text));
			objBRNode = document.createElement("br");
			
			// Add the preview nodes to the preview div
			objPreviewDiv.appendChild(objSpanNode);
			objPreviewDiv.appendChild(objBRNode);
		}
	}
	
	
	// Loop over the first select box
	for (var intIndex = 0 ; intIndex < arrOptions1.length ; intIndex++){
		// Check to see if the option is selected
		if (arrOptions1[intIndex].selected){
			// This option is selected, so preview it
			objSpanNode = document.createElement("span");
			objSpanNode.className = "move-right";
			objSpanNode.appendChild(document.createTextNode(arrOptions1[intIndex].text + " ->>"));
			objBRNode = document.createElement("br");
			
			// Add the preview nodes to the preview div
			objPreviewDiv.appendChild(objSpanNode);
			objPreviewDiv.appendChild(objBRNode);
		}
	}
	
	
	// Check to see if there are any children
	if (objPreviewDiv.childNodes.length == 0){
		// There are no children so add a "no selected" span
		objSpanNode = document.createElement("span");
		objSpanNode.className = "no-selections";
		objSpanNode.appendChild(document.createTextNode("No items have been selected"));
		objBRNode = document.createElement("br");
		
		// Add the preview nodes to the preview div
		objPreviewDiv.appendChild(objSpanNode);
		objPreviewDiv.appendChild(objBRNode);
	}
}


// Removes the given option from a sort box
function RemoveOptionFromSortBox(objForm, strSelectBoxName, strValue){
	var objSelectBox = objForm.elements[strSelectBoxName + "_select_box"];
	var objSelectBoxValueList = objForm.elements[strSelectBoxName];
	
	// Remove the option from the select box
	DeleteSelectOptionsByValue(objSelectBox, strValue);
	
	// Upate the value list
	objSelectBoxValueList.value = GetSelectOptionsValueList(objSelectBox);
}


// This removes the default value for the quick search and changes the 
// class of the criteria box.
function RemoveQuickSearchDefaultValue(objInput){
	var strDefaultValue = objInput.getAttribute("defaultvalue");
	
	// Check to see if we have the default value
	if (strDefaultValue){
		// We do, so check to see if the current value is the default value
		if (objInput.value == strDefaultValue){
			// We can remove the default value. 
			objInput.value = "";
			
			// Also, change the class so that the typing is easier
			objInput.className = "criteria-focus";
		}
	}
}


// This sets the default value for the quick search assuming that it 
// can and then changes the class of the criteria box
function SetQuickSearchDefaultValue(objInput){
	var strDefaultValue = objInput.getAttribute("defaultvalue");
	
	// Check to see if we have the default value
	if (strDefaultValue){
		// We do, so check to see if the current value is empty
		if (Trim(objInput.value).length == 0){
			// We can set the default value. 
			objInput.value = strDefaultValue;
			
			// Also, change the class
			objInput.className = "criteria";
		}
	}
}


// This toggles the hidden search options with the given ID
function ToggleHiddenSearchOptions(strID){
	var objTable = document.getElementById(strID);
	
	// Check to see if we have a proper node
	if (objTable){
		// We have a node, so toggle the display
		objTable.style.display = (objTable.style.display == "") ? "none" : "" ;
	}
	
	return;
}


// This toggles the items sub area for the left hand navigation
function ToggleLeftNavItems(objNode){
	var objItems = GetNextSiblingWithClassName(objNode, "items");
	
	// Check to see if the items div was found
	if (objItems){
		// Check to see which way we are going to toggle
		if (objItems.style.display == "block"){
			// Hide it
			objItems.style.display = "none";
		} else {
			// Show it
			objItems.style.display = "block";
		}
	}
	
	// Take the focus off of the link
	objNode.blur();
}


// This toggles the properties sub area for the left hand navigation
function ToggleLeftNavProperties(objNode){
	var objProperties = GetNextSiblingWithClassName(objNode, "properties");
	var objPropertyNote = GetNextSiblingWithClassName(objNode, "property-note");
	
	// Check to see if the property div was found
	if (objProperties){
		// Check to see which way we are going to toggle
		if (objProperties.style.display == "block"){
			// Hide it
			objProperties.style.display = "none";
			objPropertyNote.replaceChild(document.createTextNode("+"), objPropertyNote.childNodes[0]);
		} else {
			// Show it
			objProperties.style.display = "block";
			objPropertyNote.replaceChild(document.createTextNode("-"), objPropertyNote.childNodes[0]);
		}
	}
	
	// Take the focus off of the link
	objNode.blur();
}

