

/**********************************************************************
 chkMandatory: check mandatory fields on the form objForm
 parameters: objForm - form reference

 pre-requisites: aMandatory - array of fields for which mandatory evaluation
        should be done
    aMandatory should be defined on each HTML page
 format of aMandatory:
    aMandatory[<field-name-string>] = new Array(<message-string>, <input-type-string>, <focus-on-string>);

 <message-string>: message to be displayed on mandatory check failure
    (NOTE: system dispalyes "<message-string> is mandatory")
 <input-type-string>: "TEXT", "RADIO"
 <focus-on-string>: name of the field where focus should be placed on mandatory check failure.
        if this is "" then focus is place on <field-name-string>
**********************************************************************/
var aMandatory = new Array();
function chkMandatory(objForm)
{
  for (var iLoop in aMandatory)
  {
    var strVal;
    strVal = "";
    if (aMandatory[iLoop][1] == "Text")
      strVal = eval("objForm." + iLoop + ".value");
    else if (aMandatory[iLoop][1] == "Radio")
    {
      var oEle = eval("objForm." + iLoop);
      var iLen = oEle.length;
      for (var iEle = 0; iEle < iLen; iEle++)
        if (oEle[iEle].checked)
        {
          strVal = oEle[iEle].value;
          break;
        }
    }
    else if (aMandatory[iLoop][1] == "Select")
    {
      var iIdx = eval("objForm." + iLoop + ".selectedIndex");
      if (iIdx > -1)
        strVal = eval("objForm." + iLoop + "[" + iIdx + "].value");
      else
        strVal = "";
    }
    if (strVal == "")
    {
      alert("Please enter a value for " + aMandatory[iLoop][0] + ".");
      if (aMandatory[iLoop][2] != "")
        eval("objForm." + aMandatory[iLoop][2] + ".focus()");
      else
      {
        if (aMandatory[iLoop][1] == "Radio")
          eval("objForm." + iLoop + "[0].focus()");
        else
          eval("objForm." + iLoop + ".focus()");
      }
      return false;
    }
  }
  return true;
}

function disableButtons(objForm) {
  var i
  for(i=0; i<objForm.elements.length; i++) {
    if(objForm.elements[i].type == "submit" || objForm.elements[i].type == "button") {
      objForm.elements[i].disabled = true;
    }
  }
}

function setFormFocus (objForm) {
  //Call this function from the body onLoad and it will set focus to first field in objForm
  if(objForm) {
    aForm = objForm;
    if(aForm.elements[0]!=null) {
      var i;
      var max = aForm.length;
      for( i = 0; i < max; i++ ) {
        if( aForm.elements[i].type != "hidden" &&
          aForm.elements[i].type != "button" &&
          !aForm.elements[i].disabled &&
          !aForm.elements[i].readOnly ) {
          aForm.elements[i].focus();
          break;
        }
      }
    }
  }
}
