function ResetProcessForm(frmObj) {
  elms = frmObj.elements;
  for (i = 0; i < elms.length; i++) {
    elm = elms[i];
    if (elm.name.substr(0,4) == "pbm_" && elm.name.indexOf("_modified") > 0) {
      elm.value = "false";
    }
  }
}

// For Compatibilty
function NodeChanged(blockId) {
  elm = document.getElementById(blockId + "_modified");
  elm.value = "true";
}

function RecordChanged(recordId) {
  elm = document.getElementById(recordId + "_modified");
  elm.value = "true";
}

function CheckSelectedModified(CheckedResultArray, fObj, rpp, seq) {

  onlyOneSelectedCheck = rpp.indexOf("_selected:OnlyOne") > -1;
  atLeastOneSelectedCheck = rpp.indexOf("_selected:AtLeastOne") > -1;
  atLeastOneModifiedCheck = rpp.indexOf("_modified:AtLeastOne") > -1;

  if (onlyOneSelectedCheck || atLeastOneSelectedCheck) {

    selectionCheckResult = CheckedResultArray["SelectionCheck_" + seq];

    if (!selectionCheckResult) {

      selectionCount = 0;

      selections = fObj.elements["pbs_" + seq + "_selected"];

      if (selections) {
        if (selections.length) {
          for (var i = 0; i < selections.length; i++ ) {
            elm = selections[i];
            if (elm.checked) {
              selectionCount++;
              if (selectionCount > 1) {
                break;
              }
            }
          }
        } else {
          if (selections.checked) {
            selectionCount++;
          }
        }
      }
      CheckedResultArray["SelectionCheck_" + seq] = selectionCount;
    }

    if (onlyOneSelectedCheck && selectionCount == 0) {
      alert(processform_resource("NO_RECORD_SELECTED"));
      return false;
    }

    if (onlyOneSelectedCheck && selectionCount > 1) {
      alert(processform_resource("ONLY_ONE_CAN_BE_SELECTED"));
      return false;
    }

    if (atLeastOneSelectedCheck && selectionCount == 0) {
      alert(processform_resource("NO_RECORD_SELECTED"));
      return false;
    }

  }

  if (atLeastOneModifiedCheck) {

    modifiedCheckResult = CheckedResultArray["ModifiedCheck_" + seq];

    if (!modifiedCheckResult) {

      modifiedCount = 0;

      modifieds = fObj.elements["pbm_" + seq + "_modified"];

      if (modifieds) {
        if (modifieds.length) {
          for (var i = 0; i < modifieds.length; i++ ) {
            elm = modifieds[i];
            if (elm.value == "true") {
              modifiedCount++;
              break;
            }
          }
        } else {
          if (modifieds.value == "true") {
            modifiedCount++;
          }
        }
      }
      CheckedResultArray["ModifiedCheck_" + seq] = modifiedCount;
    }

    if (modifiedCount == 0) {
      alert(processform_resource("NO_RECORD_MODIFIED"));
      return false;
    }

  }

  return true;

}


function FocusTab(elm) {

  s = elm.id;
  i = s.indexOf(".");
  if (i == -1) return;
  j = s.indexOf(".",i+1);
  k = s.indexOf(".",j+1);
  tcid = s.substring(i+1,j);
  tab = s.substring(j+1,k);
  SwitchTab(tcid,tab,true);

}

function ValueAvailable(elm) {
  if (elm.value == "") {
    FocusTab(elm);
    elm.focus();
    alert( processform_resource('CANNOT_BE_BLANK') );
    return false;
  }
}

function ValueIsNumber(elm) {
  if (isNaN(elm.value)) {
    FocusTab(elm);
    elm.focus();
    elm.select();
    alert( processform_resource('MUST_BE_NUMBER') );
    return false;
  }
}

function ValidValues(elm,vvalsStr)
{
  if (elm.value == '')
    return true;

  validated = 'false';
  vvals = vvalsStr.split(';');

  for ( i = 0; i < vvals.length; i++ )
  {
    val = vvals[i];
    if (val.indexOf(':') > -1)
    {
      ft = val.split(':');
      if (ft.length > 1)
      {

        if ( (parseInt(elm.value,10) >= parseInt(ft[0],10)) && (parseInt(elm.value,10) <= parseInt(ft[1],10)) )
        {
          validated = 'true';
        }
      }
    }
    else
    {
      if (val == elm.value)
      {
        validated = 'true';
      }
    }
  }

  if (validated == 'false') {
    FocusTab(elm);
    elm.focus();
    elm.select();
    alert (processform_resource('INVALID_VALUE', vvals) );
    return false;
  }
}

function ValidCurrencyValues(elm,vvalsStr)
{
  if (elm.value == '')
    return true;
  elmValue = GetPureCurrencyValue(elm) * 1;

  validated = 'false';
  vvals = vvalsStr.split(';');

  for ( i = 0; i < vvals.length; i++ )
  {
    val = vvals[i];
    if (val.indexOf(':') > -1)
    {
      ft = val.split(':');
      if (ft.length > 1)
      {
        if ( elmValue >= (ft[0] * 1) && elmValue <= (ft[1] * 1) )
        {
          validated = 'true';
        }
      }
    }
  }

  if (validated == 'false') {
    FocusTab(elm);
    elm.focus();
    elm.select();
    alert (processform_resource('INVALID_VALUE', vvals) );
    return false;
  }
}

function ValidCurrencyDialogValues(elm,vvalsStr)
{

  elmid = elm.id.substring(0,elm.id.length-2) + "_S";
  elm_S = document.getElementById(elmid);

  if (elm_S.value == '')
    return true;

  elmValue = elm_S.value * 1;

  validated = 'false';
  vvals = vvalsStr.split(';');

  for ( i = 0; i < vvals.length; i++ )
  {
    val = vvals[i];
    if (val.indexOf(':') > -1)
    {
      ft = val.split(':');
      if (ft.length > 1)
      {
        if ( elmValue >= (ft[0] * 1) && elmValue <= (ft[1] * 1) )
        {
          validated = 'true';
        }
      }
    }
  }

  if (validated == 'false') {
    FocusTab(elm);
    elm.focus();
    elm.select();
    alert (processform_resource('INVALID_VALUE', vvals) );
    return false;
  }
}



function ValidateDateEditBox(elm,displayformat,fromdate,todate)
{
  if (elm.value == '')
    return true;

  cDate = ParseDate(elm.value,displayformat);
  if (cDate == "NaN")
  {
    FocusTab(elm);
    elm.focus();
    elm.select();
    alert( Resource("INVALID_DATE") );
    return false;
  }

  if (fromdate == "today") fromdate = FormatDate( new Date(), "yyyy.mm.dd");
  if (todate == "today") todate = FormatDate( new Date(), "yyyy.mm.dd");

  fDate = ParseDate(fromdate,displayformat);
  tDate = ParseDate(todate,displayformat);

  if (cDate < fDate || cDate > tDate)
  {
    FocusTab(elm);
    elm.focus();
    elm.select();
    alert( Resource("DATE_OUT_OF_RANGE",fromdate,todate) );
    return false;
  }
  // selm = document.getElementById(selmid);
  // selm.value = ConvertDate(elm.value,displayformat,submitformat);
}

