﻿// 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;
     this.PageValidation = PageValidation;
// Public Property Declarations ////////////////////////
// Property Getters
//GetAjaxStatus - Flag that indicates if we have a reference to the Ajax object.
 this.GetAjaxStatus = GetAjaxStatus; 
 function GetAjaxStatus()
    {
         if(IsAjaxStatus())
           {           
                return true;
           }
           else
           {               
                return false;
           }
         
    }
this.GetSessionStatus = GetSessionStatus; 
 function GetSessionStatus()
    {
        if(IsSession())
        {
            return true;
        }
        else
        {
            return false;
        }
    } 
this.GetPageValidStatus = GetPageValidStatus; 
 function GetPageValidStatus()
    {
        if(_PageValidStatus)
        {
            return true;
        }
        else
        {
            return false;
        }
    }        
       
// Property Setters
       
    
                                                       
// Private Variable Declarations ////////////////////////
   
    var _DOMUtil;              //Browser specific Services Utility. 
    var _DOMobjFact; 
    var _AjaxProxy; 
    var _AjaxStatus;  
    var _SessionStatus; 
    var _PageValidStatus;   
////////////////////////////////////////////////////////
// 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(IsAjaxStatus())
           {           
                _AjaxProxy = AjaxProxy
           }
           else
           {
                _AjaxProxy = null;
                _AjaxStatus = false;
                 AjaxStatErr();
           }
           
            
          
        }   
/* *********************************************************************************** 
-  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(isObservations)
             {           
                  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;
               
               } 
           }
       
        }
/* *********************************************************************************** 
-  Function: PageValidation  
-  Purpose:  See if the page validation has failed.  This is sensitive to BOTH the 
-            asp.net validator controls and the BMS validator flag.   
-  Parameters: None.  
-  Date:  01/31/2008
-  Mods:
-     
************************************************************************************ */
    function PageValidation()
        { 
            //Check the BMS flag first
                if(BMSIs_PageValid != null)
                  {
                    _PageValidStatus = BMSIs_PageValid;
                  }
                else
                  {
                     //No BMS flag check the asp.net validator
                     if(typeof(Page_IsValid) != "undefined")
                        {
                            _PageValidStatus = Page_IsValid;
                        
                        }
                      else
                      { 
                        //No flag set page is good. 
                        _PageValidStatus = true;
                      }  
                  }    
                       
       
        }        
 
// Private Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: IsAjaxStatus 
-  Purpose:  See if ajax object is available.  Return true if it is else false.
-  Parameters: None
-  Date:  11/19/2007
-  Mods:
-     
************************************************************************************ */
    function IsAjaxStatus()
        { 
            try
              {
                if(AjaxProxy != null)
                {
                   
                    return true;
                } 
                else
                {                    
                    return false;
                }
              }
             catch(e)
            {               
                return false;
            }    
           
        }
/* *********************************************************************************** 
-  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 = false;
           //Can we get to the server via AJAX??
           if(IsAjaxStatus())
           {           
              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(); 
                _DOMobjFact = CommonUtil.GetDomUtilRef();        
               //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);

        }   
/* *********************************************************************************** 
-  Function: AjaxStatErr   
-  Purpose:  Client Error message that is environment dependent.  In dev/test
-            put out an alert.  In Production put out message to screen. 
-  Parameters: None.
-  Date:  11/15/2007
-  Mods:
-     
************************************************************************************ */        
     function AjaxStatErr()
        {
            var ErrMsg = "Client AjaxProxy object is null.  Please define in Webconfig or Master Page.";
            switch(thisEnv)
            {
                case "Unknown":
                    HandelClientSideErr("Localhost - Error - " + ErrMsg);
                    break;    
                case "Development":
                   HandelClientSideErr("Development - Error - " + ErrMsg)
                    break;
                case "Test":
                    HandelClientSideErr("UAT - Error - " + ErrMsg);
                    break;
                 case "Production":
                    
                    break;         
                default:
                    break;
            }

        }                                
        
} 


/*End Error Utility Classes **********************************************************/

