//===========================================================================================
//                         Copyright © 2005, Agate Software, Inc.
//===========================================================================================
// File: ValidationFormLevelFunctions.js
//
// Description: Functions performed to validate data
//
//-------------------------------------------------------------------------------------------
// History                                                   By               Date
//-------------------------------------------------------------------------------------------
// Created                                                   Andy Giddings    02/20/2001
// Added code to check if 'Enter' was pressed                A. Frazier       03/31/2003
// Added function CheckPageSave                           Sarah Beth Tobias   07/14/2003
// Added additional warning text to the delete button        Joshua Tkaczyk   01/07/2005
//===========================================================================================

  // Declare page scope variables
  var strAction ="";                    // Form Action being taken

  //============================================================================================
  //                         Copyright © 2005, Agate Software, Inc.
  //============================================================================================
  // Procedure: ValidationFormLevelFunctions.ConfirmDelete
  //
  // Description: Double checks to make sure a record should be deleted
  //
  //--------------------------------------------------------------------------------------------
  // History                                                   By                    Date
  //--------------------------------------------------------------------------------------------
  // Created                                                   Christian Kaczmarek   02/29/2000
  //============================================================================================
  function ConfirmDelete()
  {
    var Delete = window.confirm("Are you sure you want to delete the selected record(s)?  Warning!  This may delete related records.");
    if (Delete)
      // continue to delete record...
      return true;
    else
      // we'll need a redirect here...
      return false;
  }

  //==========================================================================================
  //                         Copyright © 2005, Agate Software, Inc.
  //===========================================================================================
  // Procedure: FormFunctions_Java.ConfirmClear
  //
  // Description: Double checks to make sure a record should be deleted
  //
  //----------------------------------------------------------------------------------------------
  // History                                                   By                    Date
  //----------------------------------------------------------------------------------------------
  // Created                                                   A. Frazier           10/03/2002
  //============================================================================================
  function ConfirmClear()
  {
    var Clear = window.confirm("Are you sure you want to delete all the information on this page?");
    if (Clear)
      // continue to delete record...
      return true;
    else
      // we'll need a redirect here...
      return false;
  }

  //============================================================================================
  //                         Copyright © 2005, Agate Software, Inc.
  //============================================================================================
  // Procedure: ValidationFormLevelFunctions.FormSubmit
  //
  // Description: Does necessary checks before allow a form submit
  //
  //--------------------------------------------------------------------------------------------
  // History                                                   By                    Date
  //--------------------------------------------------------------------------------------------
  // Created                                                   Christian Kaczmarek   02/29/2000
  //============================================================================================
  function FormSubmit(objForm) {

    // Don't submit form if user hit the enter key
    // Default to allow submit
    var AllowSubmit = true;

    // Handle Update
    if(strAction=="Save")
    {
      AllowSubmit = ValidateDetailData(objForm);

      if(AllowSubmit==false)
        alert("Please enter all required data and proper data types!");
    }

    // Handle Delete
    if(strAction=="Delete")
    {
      AllowSubmit = ConfirmDelete();
    }

    // Return for execution continuance
    return AllowSubmit;

  }

  //============================================================================================
  //                         Copyright © 2005, Agate Software, Inc.
  //============================================================================================
  // Procedure: ValidationFormLevelFunctions.FormSubmit_Grid
  //
  // Description: Does necessary checks before allow a form submit
  //
  //--------------------------------------------------------------------------------------------
  // History                                                   By                    Date
  //--------------------------------------------------------------------------------------------
  // Created                                                   Christian Kaczmarek   02/29/2000
  // Added code to make sure that the user selected a record   A. Frazier            11/11/2002
  //  before allowing them to edit or delete
  //============================================================================================
  function FormSubmit_Grid(objForm) {

    // Don't submit form if user hit the enter key
    // Default to allow submit
    var AllowSubmit = true;
    var aryRecordIDs;
    var blnEditAllEnabled;

    // Handle Edit
    if(strAction=="Edit")
    {
      blnEditAllEnabled = eval('document.forms.' + objForm.name + '.EAE');
      if (blnEditAllEnabled.value == "TRUE") {
        // do nothing
      }
      else {
        // Make sure a record is selected
        AllowSubmit = false;
        var aryRecordIDs = eval('document.forms.' + objForm.name + '.RID');
        if (aryRecordIDs.length == null){
          if(aryRecordIDs.checked){
            AllowSubmit = true;
          }
        } else {
          var lngCtr;
          for (lngCtr = 0; lngCtr < aryRecordIDs.length; lngCtr++){
            if(aryRecordIDs[lngCtr].checked){
              AllowSubmit = true;
            }
          }
        }

        if(AllowSubmit==false)
          alert("Please select a record!");
      }
    }

    // Handle Update
    if(strAction=="Save")
    {
      AllowSubmit = ValidateGridData(objForm);

      if(AllowSubmit==false)
        alert("Please enter all required data and proper data types!");
    }

    // Handle Delete
    if(strAction=="Delete")
    {
      // Make sure a record is selected
      AllowSubmit = false;
      var aryRecordIDs = eval('document.forms.' + objForm.name + '.RID');
      if (aryRecordIDs.length == null){
        if(aryRecordIDs.checked){
          AllowSubmit = true;
        }
      } else {
        var lngCtr;
        for (lngCtr = 0; lngCtr < aryRecordIDs.length; lngCtr++){
          if(aryRecordIDs[lngCtr].checked){
            AllowSubmit = true;
          }
        }
      }

      if(AllowSubmit==false) {
        alert("Please select a record!");
      } else {
        AllowSubmit = ConfirmDelete();
      }
    }

    // Return for execution continuance
    return AllowSubmit;

  }

  //============================================================================================
  //                         Copyright © 2005, Agate Software, Inc.
  //============================================================================================
  // Procedure: ValidationFormLevelFunctions.CheckPageSave
  //
  // Description: Checks to see if the javascript variable PageChangesSaved is set to zero
  //              If it is, give the user a warning to save the page
  //
  //--------------------------------------------------------------------------------------------
  // History                                                   By                    Date
  //--------------------------------------------------------------------------------------------
  // Created                                                   Sarah Beth Tobias     07/14/2003
  //============================================================================================
  function CheckPageSave(objForm) {

    // Default to allow submit
    var AllowSubmit = true;

    // Handle Clear
    if(document.all.PageChangesSaved.value == 0)
    {
      AllowSubmit = window.confirm("Warnings!  You have made changes to this page.\n \n Select CANCEL to go BACK and SAVE.\n \n If you select OK your CHANGES will be LOST!");
    }

    // Return for execution continuance
    return AllowSubmit;
  }