﻿// JScript File  JScriptErrorUtilities
/************************************************************************************* 
-  JScriptErrorUtilities  This file contains JavaScript functions and objects that 
-       support client side error reporting.
**************************************************************************************/
/************************************************************************************* 
-  Related Jscript files   
-        
**************************************************************************************/
/*Error Utility Classes **************************************************************/
/* *********************************************************************************** 
-  Class: CommonErrorHandler   
-  Purpose: Records or processes client side errors.  
-  Date:  09/27/2007
-  Mods:
-     
************************************************************************************ */
function CommonErrorHandler()
{
// Constructor
     this.Init = Init();
// Public Function Declarations ////////////////////////
     this.HandelClientSideErr = HandelClientSideErr;
     this.HandelServerSideErr = HandelServerSideErr;
     this.HandelSessionErr = HandelSessionErr;
     this.HandelThrownErr = HandelThrownErr;
// Public Property Declarations ////////////////////////
// Property Getters
     //GetIsProceed - Flag that indicates if we should proceed with edits/submit.
     this.GetAjaxStatus = GetAjaxStatus; 
     function GetAjaxStatus()
        {
            return _AjaxStatus;
        }
// Property Setters
       
    
                                                       
// Private Variable Declarations ////////////////////////
   
    var _DOMUtil;              //Browser specific Services Utility. 
    var _DOMobjFact; 
    var _AjaxProxy; 
    var _AjaxStatus;      
////////////////////////////////////////////////////////
// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: Init  
-  Purpose: Constructor sets up any metadata for this question.  
-             
-  Parameters: thisEvnt - The event that initiated this class usually the submit button
-                         click.  We also could be processing a clear button.   
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */
    function Init()
        {
            //Declare Ajax Proxy pointer
           if(CheckAjaxProxy())
           {           
                _AjaxProxy = AjaxProxy
           }
           else
           {
                _AjaxProxy = null;
                _AjaxStatus = false;
           }
          
        }   
/* *********************************************************************************** 
-  Function: HandelClientSideErr   
-  Purpose:  Display an Alert with error message and supporting data.
-  Parameters: Msg - the position in the object array that this object occupies.  
-  Date:  09/27/2007
-  Mods:
-     
************************************************************************************ */
    function HandelClientSideErr(Msg)
        { 
           alert(Msg);
           
        }

/* *********************************************************************************** 
-  Function: HandelServerSideErr   
-  Purpose:  Call AJAX function that will record the error on the database.
-  Parameters: Msg - the position in the object array that this object occupies.  
-  Date:  09/27/2007
-  Mods:
-     
************************************************************************************ */
    function HandelServerSideErr(Msg,obj)
        {            
          if(_AjaxProxy != null)
          {
            _AjaxProxy.ClientError(Msg);
          }
           
        }

/* *********************************************************************************** 
-  Function: HandelSessionErr   
-  Purpose:  Call AJAX function that will record the error on the database.
-  Parameters: Msg - the position in the object array that this object occupies.  
-  Date:  09/27/2007
-  Mods:
-     
************************************************************************************ */
    function HandelSessionErr(_thisEvent)
        { 
                     
          if(!IsSession())
             {
              
                RedirAndCancel(_thisEvent);
             }
             else
             {
                 if(!CheckAjaxProxy())
                 {
                    RedirAndCancel(_thisEvent);
                 }
             }    
           
        }
/* *********************************************************************************** 
-  Function: HandelThrownErr  
-  Purpose:  Display an Alert with error message and supporting data.
-  Parameters: Msg - the position in the object array that this object occupies.  
-  Date:  09/27/2007
-  Mods:
-     
************************************************************************************ */
    function HandelThrownErr(errFlagObj)
        { 
           var IsApPgValid;
           var hdnT;
           
           IsApPgValid = errFlagObj.value;
           if(IsApPgValid == "false")
           {
               hdnT = document.getElementById("errTxt"); 
               if(hdnT != null)
               {
                  window.status = hdnT.value;
               
               } 
           }
       
        }

// Private Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: IsSession   
-  Purpose:  Call AJAX function that will determine if the session ID is available.
-  Parameters: None
-  Date:  09/27/2007
-  Mods:
-     
************************************************************************************ */
    function IsSession()
        { 
           var ChkSession;
           var _AjaxProxy;
           
           if(CheckAjaxProxy())
           {           
                _AjaxProxy = AjaxProxy
           }
           else
           {
             return false;
           }
           ChkSession = AjaxProxy.CheckSession();
           return ChkSession.value;
           
        }
/* *********************************************************************************** 
-  Function: OpenRedirectWin   
-  Purpose:  Client Side Redirect.
-  Parameters: rlocation - Redirect Target.
-  Date:  09/27/2007
-  Mods:
-     
************************************************************************************ */        
     function OpenRedirectWin(rlocation)
        {
            window.location.href = rlocation;

        }
        
/* *********************************************************************************** 
-  Function: OpenRedirectWin   
-  Purpose:  Client Side Redirect.
-  Parameters: rlocation - Redirect Target.
-  Date:  09/27/2007
-  Mods:
-     
************************************************************************************ */        
     function RedirAndCancel(thisEvent)
        {
              //Get browser specific Utility object... 
               _DOMobjFact = new DOMObjFactory();           
               //This object provides browser specific services.  
               _DOMUtil = _DOMobjFact.CreateDOMUtilObject();
               //Put out alert
               alert("This site has expired.  It will be refreshed by clicking OK.");
               //If this is an event cancel it
               if(thisEvent != null)
               {
                    _DOMUtil.CancelEvent(thisEvent);
               }
               OpenRedirectWin(homeURL + "?ID="+ sessionId);

        }                           
        
} 


/*End Error Utility Classes **********************************************************/

