// Switches elements from one select list to another.
// The last argument is true/false flag that tells the function whether the
// newly moved items should be selected. (If the list items are not selected, then
// the data will not be passed back to the server when the form is submitted).
//
// ARGUMENTS:
// SourceListID						- The ElementID of the select list to remove the option from.
// DestinationListID			- The ElementID of the select list to add the option to.
// Selected								- Boolean: Whether the option should be selected or not.
function MoveOption(SourceListID, DestinationListID, Selected) {

	var MoveFromList = document.getElementById(SourceListID);
	var MoveToList = document.getElementById(DestinationListID);
	var HowMany = MoveFromList.options.length;
	
	for (var i = 0; i < HowMany; i++) {
		if (MoveFromList.options[i].selected == true) {
		// add option to destination list
			var NewElement = document.createElement("option");
			NewElement.text = MoveFromList.options[i].text;
			NewElement.value = MoveFromList.options[i].value;
			MoveToList.options.add(NewElement);
		// if flag is set, then we need to select new item
			if (Selected)
				UpdateSelectBox(MoveToList.id, NewElement.value);
				
		// remove option from source list
			RemoveSelectBoxElement(MoveFromList.id, NewElement.value)
		
		// decrement counters by 1, to keep instep with
		// total number of options in list, and current position in list
		// which otherwise are out of sync when an option is removed
			i--;
			HowMany--;
		}
	}

}

// Updates the select box to select the passed value.
// If the passed value does not exist, no value is selected.
//
// ARGUMENTS:
//	ElementID 					- Identifies which Select Box we're updating
// 	Value								- The value to be selected
function UpdateSelectBox(ElementID, Value) {

var i = 0;

	for (i = 0; i < document.getElementById(ElementID).length; i++)
		if (Value == document.getElementById(ElementID).options[i].value)
			 document.getElementById(ElementID).options[i].selected = true;
}

// Removes a single option from a select box.
//
// ARGUMENTS:
// ElementID						- The ElementID of the select list to remove the option from.
// Value								- The vlaue of the option to be removed.
function RemoveSelectBoxElement(ElementID, Value) {

var i = 0;
var SelectList = document.getElementById(ElementID);
var intTotalItems = SelectList.length;

	for (i = 0; i < intTotalItems; i++) {
		if (SelectList.options[i].value == Value) {
			if (navigator.appName == "Microsoft Internet Explorer")
				document.getElementById(ElementID).options.remove(i);
			else
				document.getElementById(ElementID).options[i] = null;
			break;
		}
	}
	
}

// function to make sure all items in multi-select list boxs are 
// selected before page is submitted
function SelectMultiLists(ListNames) {

	if (ListNames.length == 0)
		return false;
	
	var arr = ListNames.split(",");
	
	for (i=0;i<arr.length;i++) {
		var List = document.getElementById("arrData["+arr[i]+"][]");
		if (List != null)
			SelectEntireList("arrData["+arr[i]+"][]");
	}

	return false;

}

// Selects every option in a select list
//
// ARGUMENTS:
//	ElementID 					- Identifies which Select Box we're updating
function SelectEntireList(ElementID) {

	var i;
	var list = document.getElementById(ElementID);

	for (i = 0; i < list.length; i++)
		list.options[i].selected = true;

}

function IsBlank(s) {
	if (s == null)
		return true;
	else if (s == "")
		return true;
	else
		return false;
}
