// ###############################################
// NOTE: All Functions included in this file have a prefix of "ui_"
// ###############################################

NONE= "scrollbars,resizable,status,"
MENUONLY= "menubar,scrollbars,resizable,status,"
ALL = ""
var exp_Space_head  	= /^(\s+)(\S?.*)$/ ;
var exp_Space_tail    		= /^(.*\S+)(\s+)$/ ;
var exp_Space_mid     	= /^(\S+)(\s+)(\S?.*)$/ ;
var exp_has_wild_card  = /\*/;
var exp_has_space 		= /\s/;
var exp_no_space       	= /[^\s]/ ;
var exp_alphanumeric	= /[\s0-9a-z]+/i ;

var VAL_INVALID_MANDATORY_SELECT	= 'dummy';
var ERR_MSG_INVALID_SELECT = 'Please select a valid value from the list';

//
// FUNCTION ui_jumpTo: This function points the cursor to a certain location.href value
//
function ui_jumpTo (theLinkVal) {
  if ((theLinkVal != "")) {
    window.location.href = '#' + theLinkVal;
  }
}

function ui_w(astring) {
  document.writeln(astring);
}

function ui_getSelection (radio_button) {
  if(radio_button) {
    for (i=0; i<radio_button.length; i++) {
      if (radio_button[i].checked) {
        selection=radio_button[i].value
         return selection
      }
    }
    return ""
  }
  return ""
}

function ui_printPage() {
  if (navigator.appName =="Netscape" && navigator.appVersion.substring(0,1)=="4" ) {
    alert("This function is not supported yet.  However, you can still print the current window by pressing \"Ctrl + P\".")
  } else {  
    window.print() 
  }
}

function ui_getValue(astring) {
  var temp = "";
  for (var i = 0; i < astring.length; i++) {
    target = astring.charAt(i);
    if ((target == " ") || (target == "=")) target = "_";
    if ((target == "+") || (target == "-")) target = "_";
    if ((target == "*") || (target == "/")) target = "_";
    if ((target == "(") || (target == ")")) target = "_";
    if ((target == "{") || (target == "}")) target = "_";
    if ((target == "[") || (target == "]")) target = "_";
    if ((target == "<") || (target == ">")) target = "_";
    if ((target == ":") || (target == ";")) target = "_";
    if ((target == "~") || (target == "`")) target = "_";
    if ((target == "!") || (target == "@")) target = "_";
    if ((target == "#") || (target == "$")) target = "_";
    if ((target == "%") || (target == "^")) target = "_";
    if ((target == "&") || (target == "*")) target = "_";
    if ((target == "|") || (target == "\\")) target = "_";
    if ((target == ".") || (target == ",")) target = "_";
    if ((target == "?") || (target == "'")) target = "_";
    if (target == "\"") target = "_";
    temp += target;
  }
  return temp;
}

// **********************************************************************
// THE FOLLOWING ARE ALL FORM DATA RELATED FUNCTIONS
// **********************************************************************

//
// FUNCTION ui_setFocus: This function is currently used to set focus on a certain element on BODY load.
//
function ui_setFocus (theFormName, theEleName) {
  document.forms[theFormName].elements[theEleName].focus();
}

//
// FUNCTION ui_setButton:  This function sets the value of selected button, normally "btn_clicked" or "side_step_btn"
//
function ui_setButton (theFormName, theBtnName, theBtnVal) {
  document.forms[theFormName].elements[theBtnName].value = theBtnVal;
}

//
// FUNCTION ui_setJumpTo: This function sets the value of "jumpTo" tag and points the cursor to the location.href value
//
function ui_setJumpTo (theFormName, theLinkVal) {
  document.forms[theFormName].elements["jumpTo"].value = theLinkVal;
  window.location.href = '#' + theLinkVal;
}

//
// FUNCTION ui_isMaxNumOfRecordsReached: This function checks whether the allowed max of a certain item list from 
//   the datapacket is reached (an example of the item list is shipment coverage items list on cf_shpt_cov_edit page
//
  function ui_isMaxNumOfRecordsReached (theItemCount, theMaxAllowed, theErrMsg) {
    if (theItemCount >= theMaxAllowed) {
      alert( theErrMsg );
      return true;
    } else {
      return false;
    }
  }
  
//
// FUNCTION ui_checkSelectValue: This function checks all mandatory SELECT lists and make sure all valid options are selected
//
function ui_checkSelectValue(theForm) {
	var i=0;	
	var isValid = true;
	while ( (i<theForm.elements.length) && (isValid == true) ) {
		if (theForm.elements[i].value == VAL_INVALID_MANDATORY_SELECT) {
				alert(ERR_MSG_INVALID_SELECT);
				theForm.elements[i].focus();
				isValid = false;
			}
		i++;	
	}
	return isValid;
}

function ui_checkSingleSelectValue(theForm, theElement) {
	var isValid = true;
	if (document.forms[theForm].elements[theElement].value == VAL_INVALID_MANDATORY_SELECT || document.forms[theForm].elements[theElement].value == '') {
	    alert(ERR_MSG_INVALID_SELECT);
	    document.forms[theForm].elements[theElement].focus();
	    isValid = false;
	}
	return isValid;
}

// **************************************************************************
// THE FOLLOWING ARE TEXT INPUT BOX  RELATED FUNCTIONS
// **************************************************************************

//
// FUNCTION ui_isValEmpty: This function validates the empty value of a form element (i.e. input text box)
//
function ui_isValEmpty (theObj, theVal, theErrMsg) {
  theVal = theVal.replace(exp_Space_head, "$2");
  theVal = theVal.replace(exp_Space_tail, "$1");
  if (theVal == "") {
    alert(theErrMsg); theObj.focus(); return true;
  } else {
    return false;
  }
}

//
// FUNCTION ui_isValNumeric: This function validates the numeric value of a form element (i.e. input text box)
//
function ui_isValNumeric (theObj, theVal, theErrMsg) {
  if (isNaN(theVal)) {
    alert(theErrMsg); theObj.focus(); return false;
  } else {
    return true;
  }
}

//
// FUNCTION ui_doesValHaveSpecialChar: This function checks for the specified special char in the item value
// 	 (item could be checkbox, radio button, select list, input text box or textarea)
//
function ui_doesValHaveSpecialChar(theObj, theVal, theRegExp, theErrMsg) {
  if (theVal.match(theRegExp) != null) {

    alert(theErrMsg); theObj.focus(); return true;
  } else {
    return false;
  }
}

//
// FUNCTION ui_doesValHaveCorrectLength: 
//    This function validates any object value to see if it has incorrect length (either too long or too short)
//
function ui_doesValHaveCorrectLength (theObj, theLengthLimit, theErrMsg, checkMax) {
  if (((checkMax) && (theObj.value.length <= theLengthLimit)) || 
  	((!checkMax) && (theObj.value.length >= theLengthLimit))) {
  	return true;
 } else {
 	alert(theErrMsg); theObj.focus(); return false;
 }
}

// **************************************************************************
// THE FOLLOWING ARE SELECT CONTROL RELATED FUNCTIONS
// **************************************************************************

//
 // FUNCTION ui_getIndex:
 // This function returns a index of provided list name and selection text
//  used for - SI
//  last modified- 09/06/02
 function ui_getIndex(listname, listval)
 {
	i=0;
	found=false;
	optLen = theForm.elements[listname].options.length;
		while ((!found) && (i<optLen)) {
		  if (theForm.elements[listname].options[i].text==listval) {
		      found = true;
		      return i;
		  }
		  i++;
	}
	return 0;
 }

//
// FUNCTION ui_selectAllOptions:
// This function selects all options in a multiple SELECT list
//
function ui_selectAllOptions(theFormName, theEleName) {
  var obj = document.forms[theFormName].elements[theEleName];
  for (var i = 0; i < obj.options.length; i++) {
    obj.options[i].selected = true;
  }
}

//
// FUNCTION ui_deSelectAllOptions:
// This function deselects all options in a multiple SELECT list
//
function ui_deSelectAllOptions(theFormName, theEleName) {
  var obj = document.forms[theFormName].elements[theEleName];
  for (var i = 0; i < obj.options.length; i++) {
    obj.options[i].selected = false;
  }
}

//
// FUNCTION ui_isValidOptionSelected:
// This function checks whether a valid selection (non-empty) has been made in a drop-down SELECT list
//
function ui_isValidOptionSelected (theFormName, theEleName, theErrMsg) {
  var obj = document.forms[theFormName].elements[theEleName];
  var val = obj.options[obj.selectedIndex].value;
  if (val != "") { return true; }
  else { alert(theErrMsg); obj.focus(); return false; }
}

//
// FUNCTION ui_isAtLeastOneSelected:
// This function checks whether any valid selection (non-empty) has been made in a multiple SELECT list
//
function ui_isAtLeastOneSelected(theFormName, theEleName, theErrMsg) {
  var sourceObj = document.forms[theFormName].elements[theEleName];
  var sourceOptions = sourceObj.options;
  var selectedCount = 0;
  for (var i=0; i < sourceOptions.length; i++) {
    if (sourceOptions[i].selected) {
      selectedCount++;
  }}
  if (selectedCount <= 0) { alert(theErrMsg); sourceObj.focus(); return false; }
  else { return true; }
}

//
// FUNCTION ui_areAllOptionsNoDuplicate:
//   This function checks whether any new option to be added from the source SELECT list
//    has a duplicate value from the target SELECT list
//
  function ui_areAllOptionsNoDuplicate (theFormName, theFromEleName, theToEleName, theErrMsg) {
  	var obj = document.forms[theFormName].elements[theFromEleName];
    var theOptions = obj.options;
    var i=0;
    var noDupFound = true;
    while ((i<theOptions.length) && (noDupFound)) {
      if (theOptions[i].selected) {
        if (!ui_isOptionNoDuplicate(theFormName, theToEleName, theOptions[i].value, theErrMsg)) {
          noDupFound = false;
      }}
      i++;
    }
    return noDupFound;
  }

//
// FUNCTION ui_isOptionNoDuplicate:
// This function checks whether a single new option to be added has a duplicate value from the target SELECT list
//
  function ui_isOptionNoDuplicate (theFormName, theEleName, theNewVal, theErrMsg) {
  	var obj = document.forms[theFormName].elements[theEleName];
    var theOptions = obj.options;
    for (var i=0; i<theOptions.length; i++) {
      if (theOptions[i].value == theNewVal) {
        if (theErrMsg != "") {alert(theErrMsg);}
        obj.focus(); return false;
    }}
    return true;
  }

//
// FUNCTION ui_isMultiSelectionEmpty:
// This function checks whether any selection has been made from a multiple SELECT list
//
  function ui_isMultiSelectionEmpty(theObj, theErrMsg) {
    var selectedCount = 0;
    var theOptions = theObj.options;
    for (var i=0; i < theOptions.length; i++) {
      if (theOptions[i].selected) {
        selectedCount++;
    }}
    if (selectedCount <= 0) { alert(theErrMsg); theObj.focus(); return true; }
    else { return false; }
  }

//
// FUNCTION ui_deleteSelectedOptions:
// This function deletes all selected options from a multiple SELECT list
//
  function ui_deleteSelectedOptions(theFormName, theEleName, replaceDefault, theValToBeReplaced) {
	var theObj = document.forms[theFormName].elements[theEleName];
    var theOptions = theObj.options;
    var length = theOptions.length;
    for(i=0; i < length; i++) {
      if (theOptions[i].selected) {
        theOptions[i] = null;
        length--;
        i--;
    }}
  	if ((theOptions.length <= 0) && replaceDefault) { 
  	  var def_option = new Option(theValToBeReplaced, theValToBeReplaced, 0, false);
	  theObj.options[0] = def_option;
  	}
  }
  
// 
// FUNCTION ui_isDateRangeValid: This function validates the DATE RANGE selection control
// 
function ui_isDateRangeValid (theFormName, theDatePrefix, theStartDateStr, theEndDateStr, theErrMsg) {
    var obj = document.forms[theFormName].elements[theDatePrefix+'.'+theStartDateStr+'.month.value'];
    var val = obj.options[obj.selectedIndex].value;
    var d1MonSelected = !(val == "") ;
    obj = document.forms[theFormName].elements[theDatePrefix+"."+theStartDateStr+".date.value"];
    val = obj.options[obj.selectedIndex].value;
    var d1DaySelected = !(val == "");
    obj = document.forms[theFormName].elements[theDatePrefix+"."+theStartDateStr+".year.value"];
    val = obj.options[obj.selectedIndex].value;
    var d1YeaSelected = !(val == "");
    obj = document.forms[theFormName].elements[theDatePrefix+"."+theEndDateStr+".month.value"];
    val = obj.options[obj.selectedIndex].value;
    var d2Monelected = !(val == "");
    obj = document.forms[theFormName].elements[theDatePrefix+"."+theEndDateStr+".date.value"];
    val = obj.options[obj.selectedIndex].value;
    var d2DaySelected = !(val == "");
    obj = document.forms[theFormName].elements[theDatePrefix+"."+theEndDateStr+".year.value"];
    val = obj.options[obj.selectedIndex].value;
    var d2YeaSelected = !(val == "");

    if (d1MonSelected && d1DaySelected && d1YeaSelected && d2Monelected && d2DaySelected && d2YeaSelected) {
      return true;
    } else {
      alert(theErrMsg); 
      return false;
    }
  }

//
// FUNCTION ui_copyOrMoveMultiOption:
// This function copies (or moves) multiple selected options from one SELECT list to another
//
function ui_copyOrMoveMultiOption (theFormName, theSourceEleName, theTargetEleName, replaceDefault, theValToBeReplaced, isCopy) {
  var sourceObj  = document.forms[theFormName].elements[theSourceEleName];
  var sourceOptions = sourceObj.options;
  var targetObj = document.forms[theFormName].elements[theTargetEleName];
  if (targetObj.options.length > 0) {
    if ((targetObj.options[0].value == theValToBeReplaced) && (targetObj.options.length == 1) && replaceDefault) { 
      targetObj.options[0] = null;
  }}
  var length = sourceOptions.length;
  for (var i=0; i < length; i++) {
    if (sourceOptions[i].selected) {
      var topic_text = sourceOptions[i].text;
      var topic_value = sourceOptions[i].value;
	  ui_addSingleOption(theFormName, topic_text, topic_value, theTargetEleName, false);
      if (!isCopy) {
        sourceOptions[i] = null;
        length--;
        i--;
  }}}
}

// 
// FUNCTION ui_addSingleOption: This function addes a single option to a SELECT list
//   It will select the newly added option if single SELECT; or leave the newly added option unselected if multiple SELECT.
// 
function ui_addSingleOption(theFormName, theTopicText, theTopicVal, theTargetEleName, isSingle) {
  var selectNewOpt = 0;
  if (isSingle) { selectNewOpt = 1; }
  var selected_topic = new Option(theTopicText, theTopicVal, 0, selectNewOpt);
  var targetObj = document.forms[theFormName].elements[theTargetEleName];
  targetObj.options[targetObj.length] = selected_topic;
  if (isSingle) { targetObj.selectedIndex = targetObj.length - 1; }
}

// 
// FUNCTION ui_moveSingleOption:
// This function moves a single selected option from one SELECT list to another
//
function ui_moveSingleOption (theFormName, theTopicText, theTopicVal, theSourceEleName, theTargetEleName, isSingle, theIndex) {
  ui_addSingleOption(theFormName, theTopicText, theTopicVal, theTargetEleName, isSingle);
  var sourceObj = document.forms[theFormName].elements[theSourceEleName];
  sourceObj.options[theIndex] = null;
}

// **************************************************************************************
// THE FOLLOWING ARE CHECKBOX & RADIO BUTTON RELATED FUNCTIONS
// **************************************************************************************

//
// FUNCTION ui_isCkboxChecked: This function checks whether a specific checkbox is checked
//
function ui_isCkboxChecked (theFormName, theName, theVal) {
  var numOfFormEle = document.forms[theFormName].elements.length;
  var theElements = document.forms[theFormName].elements;
  for (var i=0; i < numOfFormEle; i++) {
    if (theElements[i].name == theName) {
      if (theElements[i].value == theVal) {
        if (theElements[i].checked) {
          return true;
  }}}}
  return false;
}

//
// FUNCTION ui_toggleCkbox: This function checks or unchecks a specific checkbox depending on the value of toBeChecked
//
function ui_toggleCkbox (theFormName, theName, theVal, toBeChecked) {
  var numOfFormEle = document.forms[theFormName].elements.length;
  var theElements = document.forms[theFormName].elements;
  var i = 0;
  var found = false;
  while ((i < numOfFormEle) && !(found)) {
    if (theElements[i].name == theName) {
      if (theElements[i].value == theVal) {
      	if (toBeChecked) {
          theElements[i].checked = true;          
        } else {
          theElements[i].checked = false;
        }
        found = true;
    }}
    i++;
  }
}

//
// FUNCTION ui_isRadioChecked:
// This function checks whether a selection has been made to a set of radio buttons
//
function ui_isRadioChecked (theFormName, theRbLabel, theErrMsg) {
  var theEle = document.forms[theFormName].elements;
  var numOfEle  = theEle.length;
  var isChecked = false;
  for (var i=0; i < numOfEle; i++) {
    if (theEle[i].type == 'radio') {
      if (theEle[i].name == theRbLabel) {
        if (theEle[i].checked) {
          isChecked = true;
  }}}}
  if (!isChecked) { alert(theErrMsg); return false; }
  else { return true; }
}

//
// FUNCTION ui_setCkboxAssocRadio: 
// This function is invoked when the user clicks on a single checkbox which has some associated radio buttons below. If the checkbox is checked, 
// set the default radio button to be checked; if the checkbox is unchecked, clear all related radio buttons -set all to be unchecked.
//
// INPUT PARAMETERS: 
//   1) theCkBoxObj: CheckBox Object; 
//   2) theFormName: Form name; 
//   3) theRbLabel: Name of related Radio Button set; 
//   4) theRbDefVal: Value of default Radio Button to be checked once the CheckBox is checked.
//
function ui_setCkboxAssocRadio (theCkBoxObj, theFormName, theRbLabel, theRbDefVal) {
  var theEle = document.forms[theFormName].elements;
  var numOfEle  = theEle.length;
  for (i=0; i<numOfEle; i++) {
    if (theEle[i].type == 'radio') {
      if (theEle[i].name == theRbLabel) {
        if (!theCkBoxObj.checked) {
          theEle[i].checked = false;
        } else {
          if (theEle[i].value == theRbDefVal) {
            theEle[i].checked = true;
          }
        }
  }}}
}

//
// FUNCTION ui_setSingleCheckBox: 
// This function is invoked when the user checks on one radio button after the controlling checkbox is unchecked.
//  If after uncheck the checkbox, user checks any of the associated radioboxes, reset the checkbox to be checked.
//
// INPUT PARAMETERS: 
//   1) theFormName: Form name; 2) theCkboxLabel: Name of the CheckBox to be checked.
//
function ui_setSingleCheckBox (theFormName, theCkboxLabel) {
  document.forms[theFormName].elements[theCkboxLabel].checked = true;
}

//
// FUNCTION ui_setSelectAssocRadio: 
// This function is invoked when the user clicks on any item in a selection list associated with a set of radio buttons. 
// Set the corresponding radio button to be checked.
//
// INPUT PARAMETERS: 
//   1) theFormName: Form name; 
//   2) theRbLabel: Name of related RadioBoxes; 
//   3) theRelVal: The value of the related Radio Button to be checked;
//
function ui_setSelectAssocRadio (theFormName, theRbLabel, theRelVal) {
  var anIndex = 0;
  var i = 0;
  var found = false;
  var theEle = document.forms[theFormName].elements;
  var numOfEle  = theEle.length;
  while ((!found) && (i < numOfEle)) {
    if (theEle[i].type == 'radio') {
      if (theEle[i].name == theRbLabel) {
        if (theEle[i].value == theRelVal) {
          anIndex = i;
          found = true;
    	}
      }
    }
    i++;
  }
  theEle[anIndex].checked = true;
}

/// The following functions were from control.js developed by Mang

function ui_getElementNamed(elementName) {
	var formElement = null;
	for (var p = 0; p< document.forms.length; ++p) {
		formElement = ui_getElementNamedIn(elementName, document.forms[p])
		if (formElement != null) {
			return formElement;
		}
	}
	return null;
}

function ui_getElementNamedIn(elementName, elementForm) {
	for (var y = 0; y< elementForm.elements.length; ++y) {
		if (elementForm.elements[y].name == elementName) {
			return elementForm.elements[y];
		}
	}
	return null
}
	
function ui_setSelectionInSelect(selection, menu) {
	for (var l = 0; l < menu.options.length; ++l) {
		if (menu.options[l].text == selection) {
			menu.options[l].selected = true;
		}
	}
}

function ui_setSelectionsInSelect(selections, menu) {
	for (var l = 0; l < menu.options.length; ++l) {
		for (var m = 0; m < selections.length; ++m) {
			if (menu.options[l].text == selections[m]) {
				menu.options[l].selected = true;
			}
		}
	}
}

function ui_setSelectionInNamedSelect(selection, menuName) {
	var menu = ui_getElementNamed(menuName);
	ui_setSelectionInSelect(selection, menu);
}

function ui_setSelectionInNamedSelectInForm(selection, menuName, menuForm) {
	var menu = ui_getElementNamedIn(menuName, menuForm);
	ui_setSelectionInSelect(selection, menu);
}

function ui_setSelectionsInNamedSelectInForm(selections, menuName, menuForm) {
	var menu = ui_getElementNamedIn(menuName, menuForm);
	ui_setSelectionsInSelect(selections, menu);
}

function ui_populateSelect(menuItems, menu) {
	var menuSize = menu.options.length;
	for (var j = 0; j < menuSize; ++j) {
		menu.options[0] = null;
	}
	ui_appendSelect(menuItems, menu);
}


function ui_appendSelect(menuItems, menu) {
	var j = menu.options.length;
	for (var k = 0; k < menuItems.length; ++k) {
		menu.options[j] = new Option(menuItems[k], menuItems[k]);
		j = j + 1;
	}
}

function ui_selectAndPopulateSelect(selection, menuItems, menu) {
	for (var j = 0; j < menu.options.length; ++j) {
		menu.options[0] = null;
	}
	for (var k = 0; k < menuItems.length; ++k) {
		menu.options[k] = new Option(menuItems[k], menuItems[k]);
		if (menu.options[k].text == selection) {
			menu.options[k].selected = true;
		}
	}
}

function ui_populateNamedSelect(menuItems, menuName) {
	ui_populateSelect(menuItems, ui_getElementNamed(menuName));
}

function ui_appendNamedSelect(menuItems, menuName) {
	ui_appendSelect(menuItems, ui_getElementNamed(menuName));
}

function ui_selectAndPopulateNamedSelect(selection, menuItems, menuName) {
	ui_selectAndPopulateSelect(selection, menuItems, ui_getElementNamed(menuName));
}

function ui_setNamedInput(value, inputName) {
	var inputField = ui_getElementNamed(inputName);
	inputField.value = value;
}

function ui_clearNamedInput(inputName) {
	var inputField = ui_getElementNamed(inputName);
	inputField.value = "";
}

function ui_safelyClearNamedInput(inputName) {
	var inputField = ui_getElementNamed(inputName);
	if (inputField != null) { 
		if (inputField.disable != true) {
			inputField.value = "";
		}
	}
}

function ui_clearNamedInputs(inputNames) {
	for (var j = 0; j < inputNames.length; ++j) {
		ui_clearNamedInput(inputNames[j]);
	}
}

function ui_safelyClearNamedInputs(inputNames) {
	for (var j = 0; j < inputNames.length; ++j) {
		ui_safelyClearNamedInput(inputNames[j]);
	}
}

function ui_changeLayerBackgroundColor(layerName, colorValue) {
	if (document.all)
	{
		document.all(layerName).style.backgroundColor=colorValue;
	} else if (document.layers) 
	{
		document.layers[layerName].bgColor=colorValue;
	}
}

function ui_disableNamedInput(inputName) {
	var inputField = ui_getElementNamed(inputName);
	inputField.disabled = true;
}

function ui_clickRadioButton(index, radioListSize, listName, elementName, setElementName) {
	for (var i=0; i<radioListSize; ++i) {
		var elementFieldName = listName+"["+i+"]." + elementName
		var element = ui_getElementNamed(elementFieldName);
		if (index == i) {
			if (setElementName != "") {
				var setElement = ui_getElementNamed(setElementName);
				setElement.value = index;
			}
		} else {
			if(element != null) { element.checked = false; }
		}
	}	
}

function ui_clickCheck(element, elementValueName, value) {
	var elementValue = ui_getElementNamed(elementValueName);
	if (element.checked) {
		elementValue.value = value;
	} else {
		elementValue.value = "";
	}	
}


function ui_clickRadio(element, setValue ) {
	element.value = setValue;
}

function ui_uncheckAllRadio(elementGroupName) {
	var formElement = null;
	for (var p = 0; p< document.forms.length; ++p) {
		formElement = document.forms[p];
		for (var y = 0; y< formElement.elements.length; ++y) {
			if (formElement.elements[y].name == elementGroupName) {
				formElement.elements[y].checked = false;
			}
		}
	}	
}

function ui_getRadioValue(elementGroupName) {
	var formElement = null;
	for (var p = 0; p< document.forms.length; ++p) {
		formElement = document.forms[p];
		for (var y = 0; y< formElement.elements.length; ++y) {
			if (formElement.elements[y].name == elementGroupName) {
				if (formElement.elements[y].checked) {
					return formElement.elements[y].value;
				}
			}
		}
	}
	return null;	
}

//
// The following function should be merged with function ui_selectAllOptions(theFormName, theEleName) later. 
//
function ui_selectAll(elementName) {
	var element = ui_getElementNamed(elementName);
	for (var i=0; i<element.options.length; i++) {
		element.options[i].selected = true;
	}
}
