//
// Contains validation required fields.
//
  // Validates that a single object containing a selection or value - a reference should
  // be sent to the function, not the value of the object. This will only work for known types -
  // DO NOT CALL this directly, call valReq() instead.
  //
  // @param obj the object to examine to see if it has a value or selection.
  // @param type the type of object to test.
  //
  // @return true if the object has a value or selection, else false.
  function valReqKnownObj(obj, type)
  {
    var result = false;
    if (obj != null)
    {
      // First test to see if it is a select list.
      if (type == "select-multiple" || type == "select-one")
      {
        result = (obj.selectedIndex > -1 && obj.options[obj.selectedIndex].value != null && trim(obj.options[obj.selectedIndex].value) != "");
      }
      // Next test for radio buttons and check boxes.
      else if (type == "radio" || type == "checkbox")
      {
        result = obj.checked;
      } 
      else 
      {
        result = (obj.value != null && trim(obj.value) != "");
      }
    }
    return result;
  }

  // Validates that a single object contains a selection or value - a reference should
  // be sent to the function, not the value of the object. Call this function instead if
  // valReqKnownObj() as it can deal with like named objects.
  //
  // @param obj the object to examine to see if it has a value or selection.
  //
  // @return true if the object has a value or selection, else false.
  function valReq(obj)
  {
    var result = false;
    if (obj != null)
    {
      var type = null; 
      type = obj.type;
      // If the type is undefined, this will guess that it is an array of like named objects.
      // Since they have the same name, only one of them is required to be valid.
      if (type == null)
      {
         for (var i=0; i < obj.length; i++)
         {
           result = valReqKnownObj(obj[i], obj[i].type);
           if (result)
           {
             break;
           }
         }
      }
      else 
      {
        result = valReqKnownObj(obj, type);
      }
    }
    return result;
  }

  // Verifies that all objects passed in have a value selected or filled in. This
  // function is able to tell what data control type is being used, so references to
  // the controls (not their values) should be sent in the Array() parameter.
  //
  // @param reqFieldArr an Array object containing the objects to examine to see if
  //   they have a value. The array is made up of references to the fields, not the
  //   values of the fields.
  // @param labelArr an Array object containing the labels to be used for each field 
  //   should it not have a value. The value from this array will be sent in the return
  //   array if the field does not have a value. These labels should be at the same array
  //   position as their associated field reference.
  //
  // @return an Array of strings containing the labels for the objects that have not been
  //   given a value.
  function valReqGroupAnd(reqFieldArr, labelArr)
  {
    // In JavaScript, you do not have to set the size of the array, just reference elements
    //  and it will expand.
    var result = new Array();
    if (reqFieldArr != null && labelArr != null)
    {
      var arrIdx = 0;
      for (var i = 0; i < reqFieldArr.length; i++)
      { 
        if (!valReq(reqFieldArr[i]))
        {
          result[arrIdx++] = labelArr[i];
        }
      }
    }
    return result;
  }

  // Verifies that at least one of the objects passed in has a value selected or filled in. This
  // function is able to tell what data control type is being used, so references to
  // the controls (not their values) should be sent in the Array() parameter.
  //
  // @param reqFieldArr an Array object containing the objects to examine to see if
  //   they have a value. The array is made up of references to the fields, not the
  //   values of the fields.
  // @param msg the message to return if none of the objects were selected.
  //
  // @return the message passed in if none are found, else null;
  function valReqGroupOr(reqFieldArr, msg)
  {
    var result = null;
    if (reqFieldArr != null && reqFieldArr.length > 0)
    {
      result = msg;
      for (var i = 0; i < reqFieldArr.length; i++)
      { 
        if (valReq(reqFieldArr[i]))
        {
          result = null;
          break;
        }
      }
    }
    return result;
  }
