﻿// JScript File  JScriptUtilities 
/************************************************************************************* 
-  JScriptUtilities  This file contains JavaScript functions and objects that 
-       are common in nature AND NOT BROWSER SPECIFIC.
**************************************************************************************/
/************************************************************************************* 
-  Related Jscript files   
- 
/* *********************************************************************************** 
-  Class: CommonFunct   
-  Purpose: This object will provide common page functionality.  In addition it will 
-           provide global references to common objects that will be needed for error, Dom
-           compatibility and other functions.  In this manner only ONE instance of 
-           common utility objects will exist.  
-  Date:  10/17/2007
-  Mods:
-     
************************************************************************************ */ 
function CommonFunct()
{
     // Constructor
   this.Init = Init();
  //Public Methods 
 
  // Private Variable Declarations ////////////////////////
  
 
  // Property Getters
  //GetErrRef - Reference to the common error handler.
  this.GetErrRef = GetErrRef; 
  function GetErrRef()
    {
        return _ErrHandler;
    }
  //GetDomUtilRef - Reference to the common DOM compatibility object.
  this.GetDomUtilRef = GetDomUtilRef; 
  function GetDomUtilRef()
    {
        return _DomUtil;
    }  
 //GetObsDomUtilRef - Reference to the common observation DOM compatibility object.
  this.GetObsDomUtilRef = GetObsDomUtilRef; 
  function GetObsDomUtilRef()
    {
        return _ObsDomUtil;
    }     
  
  //Objects
  var _ErrHandler;
  var _DomUtil; 
  var _ObsDomUtil;    
////////////////////////////////////////////////////////
// Public Functions ////////////////////////////////////

/* *********************************************************************************** 
-  Function: Init  
-  Purpose: Constructor sets up any references to common objects.  
-             
-  Parameters: None. 
-  Date:  10/17/2007
-  Mods:
-     
************************************************************************************ */  
  function Init()
    {
      //Instantiate error handler, common Dom compat objects
       _ErrHandler = new CommonErrorHandler();
       _DomUtil = new DOMObjFactory(_ErrHandler);
       _ObsDomUtil  = new BrObjFactory(_ErrHandler);
    }

}    
/*End Init Classes *************************************************************/ 

       
/**************************************************************************************/
/*Commom Page Functions *************************************************************/ 
/* *********************************************************************************** 
-  Commom Page Functions - Function: ChangeLanguage   
-  Purpose:  Change Language Indicator via an AJAX call.
-  Parameters: langType - The numeric representation of the language.  
-  Date: 10/17/2007
-  Mods:
-     
************************************************************************************ */
function ChangeLanguage(langType)
{     
    AjaxProxy.ClientSetLanguage(langType);
}

function CheckAjaxProxy()
{
    
    try
      {
        if(AjaxProxy != null)
        {
            return true;
        } 
      }
     catch(e)
        {
            return false;
        }    

}
/*Image Swap Classes *****************************************************************/
/* *********************************************************************************** 
/* ImgSwap Class                                                                     */
/* *********************************************************************************** 
-  Class: ImgSwap
-  Purpose: Detects and swaps images for navigation.
-  Date:  6/12/2006
-  Mods:
-    
************************************************************************************ */
function ImgSwap(thisForm)
{
// Constructor /////////////////////////////////////////
    this.curForm = thisForm;
////////////////////////////////////////////////////////


// Public Function Declarations ////////////////////////
    this.replaceImage = replaceImage;
////////////////////////////////////////////////////////

// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Public  Functions:  replaceImage()
-  Parameters: String of pagename,target element Id,replacement image. 
-  Purpose: Iterate thru a list of pages and associated images and replace the image
-           if it is found.  The imageList is in the form:
-           pagename,target element Id,replacement image|pagename,target element Id,replacement image......  
-  Date:  6/12/2006
-  Mods:
-     
************************************************************************************ */    
    function replaceImage(imageList)
        {  
            //Find the page, split the page/id/image tag string on the pipe delimiter
            var splitImage = imageList.split("|");
            var imgEle;
            var imgEleArr;
            
            //Go thru the array and pick out all entries for this page, then 
            //substitute the image.
            for(var i = 0; i < splitImage.length; i++)
            {
                //Go locate the page
                if(locatePage(this.curForm,splitImage[i]))
                    {
                        imgEleArr = splitImage[i].split(",");
                        imgEle = document.getElementById(imgEleArr[1]);
                        if(imgEle)
                            {   
                                //This is a bit kludgy we do this because the < and > tags
                                //can't be in the web config entry where the imageList currently
                                //resides.  We can remove this when the data lives in a database.  
                                imgEleArr[2] = imgEleArr[2].replace("@","<");
                                imgEleArr[2] = imgEleArr[2].replace("*",">");
                                imgEle.innerHTML = imgEleArr[2];
                            }
                    
                    }
            
            }
          
        }  
// Private Functions        ////////////////////////        
/* *********************************************************************************** 
-  Private  Functions:  locatePage()
-  Parameters: pageName - Name of the current page
-              imageRow - Current row in imageList in the form pagename,target element Id,replacement image   
-  Purpose: Find a match in the string passed to the current page name. 
-  Date:  6/12/2006
-  Mods:
-     
************************************************************************************ */          
    function locatePage(pageName, imageRow)
        { 
            //Find out if images on this page should be swapped 

            var imgRSplit = imageRow.split(",");   
                        
            if(pageName == imgRSplit[0])
                {
                    return true; 
                
                }
            else
                {
                    return false;
                }    
                
        }        


} 
/*End Image Swap Classes *************************************************************/ 
