//===========================================================================================
//                         Copyright © 2001, 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
//===========================================================================================

  // Declare page scope variables
  var strAction ="";                    // Form Action being taken
  var strKeyCode = "";		              // Key Code of last key pressed

  //==========================================================================================
  //                         Copyright © 2000, Agate Software, Inc.
  //===========================================================================================
  // Procedure: FormFunctions_Java.ResetKeyCode()
  //						FormFunctions_Java.SetKeyCode()
  //						FormFunctions_Java.GetKeyCode()
  //
  // Description: Reset, Set, and Get strKeyCode
  //
  //----------------------------------------------------------------------------------------------
  // History                                                   By                    Date
  //----------------------------------------------------------------------------------------------
  // Created                                                   A. Brzycki					 02/12/2002
  //============================================================================================	  
  function ResetKeyCode() {
    strKeyCode = "";
  }
  
  function SetKeyCode() {
    strKeyCode = window.event.keyCode;
  }
	
	function GetKeyCode() {
	  return strKeyCode;
	}
	
  //============================================================================================
  //                         Copyright © 2000, 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)?");
    if (Delete)
      // continue to delete record...
      return true;
    else
      // we'll need a redirect here...
      return false;
  }

  //==========================================================================================
  //                         Copyright © 2000, 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 © 2000, 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
    if(GetKeyCode() == 13)
    {
      ResetKeyCode();
      return false;
    }
    
    // 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 © 2000, 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
    if(GetKeyCode() == 13)
    {
      ResetKeyCode();
      return false;
    }
    
    // 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;
    
  }