﻿// JScript File  JScriptObservationUtilities 
/************************************************************************************* 
-  JScriptObservationUtilities  This file contains JavaScript functions and objects that 
-       are common in nature.
**************************************************************************************/
/************************************************************************************* 
-  Related Jscript files   
-       JScriptObsevations. 
**************************************************************************************/
/* *********************************************************************************** 
/* Factory Classes                                                                   */
/* *********************************************************************************** 
-  Class: BrObjFactory
-  Purpose: Creates browser specific support classes depending upon browser.
-  Date:  6/01/2006
-  Mods:
-    
************************************************************************************ */
function BrObjFactory(errObj)
{
// Constructor /////////////////////////////////////////
    this.Init = Init(errObj);     
////////////////////////////////////////////////////////
// Public Variables ////////////////////////////////////
    this.UtilObj;

// Public Function Declarations ////////////////////////
    this.CreateUtilObject = CreateUtilObject;
////////////////////////////////////////////////////////
    
// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: Init  
-  Purpose: Constructor sets up any metadata for this observation.  If this request
-           is from a Flash site, we already have the data in the ParmNames/ParmValues
-           list.  We initialize the metadata objects differently      
-  Parameters: None
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function Init(errObj
    )
        {
           
        }   
/* *********************************************************************************** 
-  Public  Functions:  CreateUtilObject()
-  Parameters: None. 
-  Purpose: Create a Utility object that is Browser specific.  This object is created 
-           depending upon the present browser.  Return the object.
-  Date:  5/19/2006
-  Mods:
-     
************************************************************************************ */    
    function CreateUtilObject()
    {
        var _BrowserType;
        
        //Sniff the browser
        if(document.all)
            {
                _BrowserType = "IE4+"
            }
        else
            {
                _BrowserType = "Other"
            }  
        
        switch(_BrowserType)
            {
                case "IE4+":
                    UtilObj = new IEUtility();
                    return UtilObj;
                    break    
                case "Other":
                    UtilObj = new NonIEUtility();
                    return UtilObj;
                    break
                default:
                    UtilObj = new IEUtility();
                    return UtilObj;
            }

    }


}

/*End Factory Classes                                                                */ 

/*Utility Classes ********************************************************************/ 
/*IEIEIEIEIEIEIEIEIEIEIEIEIEIEIEIEIE**************************************************/
/* IE Classes                                                                        */ 
/* *********************************************************************************** 
-  Class: IEUtility
-  Purpose: Performs Utility Functions for IE browser.
-  Date:  6/01/2006
-  Mods:
-     
************************************************************************************ */
function IEUtility()
{
//Constructors
    this.Init = Init();
// Public Function Declarations ////////////////////////
     this.GetEevent = GetEevent;
     this.MetaObjectFactory = MetaObjectFactory;
     this.GitObservationID = GitObservationID; 
     this.FlashObsNoMetadata = FlashObsNoMetadata;
     this.FlashObsMetadata = FlashObsMetadata;
     this.FlashMetaObjectFactory = FlashMetaObjectFactory;
     this.FindID = FindID;
////////////////////////////////////////////////////////
      var _ErrHandler;
      var _AjaxProxy;            //Pointer to Server Ajax Object
/* *********************************************************************************** 
-  Function: Init  
-  Purpose: Constructor sets up any metadata for this observation.  If this request
-           is from a Flash site, we already have the data in the ParmNames/ParmValues
-           list.  We initialize the metadata objects differently      
-  Parameters: ObsCode - Observation Code that represents this observation. 
-              CurEvent - The client event ID that triggered this action.  
-              ParmNames - A list of data value names.  
-              ParmValues - A list of data values associated with ParmNames.  
-              isFlash - Is this a request from a Flash site.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function Init()
        { 
         //Declare error handler
           _ErrHandler = CommonUtil.GetErrRef();
            //Declare Ajax Proxy pointer
           _AjaxProxy = AjaxProxy;

        }
// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: GetEevent  IE
-  Purpose: Returns an event ID.  ONLY Anchor Tags.  If we have an IMG tag, look to see
-           id the parent is an anchor. 
-  Parameters: The event fired. 
-  Date:  5/30/2006
-  Mods:
-     
************************************************************************************ */
    function GetEevent(thisEvent)
        { 
            var eleID = null; 
            //Get Element tag name.
            var thisEle = thisEvent.srcElement.tagName 
            
            switch(thisEle)
            {
            //If this is an Anchor, get the element.
                case "A":
                       eleID = thisEvent.srcElement.id; 
                       //Set the page validation flag for this tag
                         _ErrHandler.PageValidation();
                    break;
            //If this is an IMG see if the parent is an anchor.     
                case "IMG":
                        var imgParent = thisEvent.srcElement.parentElement.tagName;
                        if (imgParent == "A")
                        {                           
                            eleID = thisEvent.srcElement.parentElement.id; 
                        }
                        //No id in the parent anchor see if it is in the image...
                        if(eleID == null)
                        {
                             eleID = thisEvent.srcElement.id; 
                        
                        }
                        //Set the page validation flag for this tag
                         _ErrHandler.PageValidation();
                    break;
             //If this is an INPUT get the ID.      
                case "INPUT":
                       //Set the page validation flag for this tag
                       _ErrHandler.PageValidation();
                        eleID = thisEvent.srcElement.id; 
                    break;
             //If this is a BUTTON get the ID.      
                case "BUTTON":
                         //Set the page validation flag for this tag 
                         _ErrHandler.PageValidation(); 
                        eleID = thisEvent.srcElement.id; 
                    break;
            //If this is an AREA get the ID.          
                case "AREA":
                       eleID = thisEvent.srcElement.id; 
                    break;    
                default:
                        eleID = null;
                    break;                         
             }
        
            return eleID;
        
        }

/* *********************************************************************************** 
-  Function: MetaObjectFactory  IE
-  Purpose: Returns a DYNObsMetaData object with all metadata. 
-  Parameters: ObsCode - The Observation Code for this Observation. 
-              ObjName - The ID of the Client Object tag. 
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function MetaObjectFactory(ObsCode, ObjName)
        { 
            var ObjectArray = new Array();
            var MetaArray = new Array();
            var DataObjList = _AjaxProxy.GitObservationData(ObsCode).value;
            var DataObj;
            var MetaDataObj;
            var Pos = 0;
            
            try
            {   
                    ObjectArray = DataObjList
                    if(ObjectArray.length == 0)
                    {
                        return MetaArray;    
                    }
                    for (i in ObjectArray)
                        {        
                            var DataObj = ObjectArray[i];
                 
                            if(isType("ObsMetaData", DataObj.__type))
                                {
                                    MetaDataObj = new DYNObsMetaData(); 
                                    MetaDataObj.SetCollDescVarName(DataObj.CollDescVarName);
                                    MetaDataObj.SetCollDescAttrName(DataObj.CollDescAttrName);
                                    MetaDataObj.SetObjectID(ObjName);
                                    MetaDataObj.SetObsrCode(ObsCode);
                                    MetaDataObj.SetthisURL(exit_method);
                                    MetaDataObj.SetisFlash(false);
                                    MetaArray[Pos] = MetaDataObj;
                                     
                                    Pos ++;
                                }

                        }
                }
                catch(e)
                {
                    //alert("No Data MetaObjectFactory " + e);
                    _ErrHandler.HandelSessionErr(null);
                    
                }
                
                return MetaArray;
        
        } 
/* *********************************************************************************** 
-  Function: FlashMetaObjectFactory  IE
-  Purpose: Returns a DYNObsMetaData object with all metadata. This is for requests 
-           from a Flash site.  We alresdy have the data.
-  Parameters: ObsCode - The Observation Code for this Observation. 
-              ParmNames - A list of data value names.  
-              ParmValues - A list of data values associated with ParmNames.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function FlashMetaObjectFactory(ObsCode, ParmNames, ParmValues)
        {             
            var MetaArray = new Array();
            var MetaDataObj;
            var Pos = 0;
            
            for(i = 0; i < ParmNames.length; i++)
           { 
               MetaDataObj = new DYNObsMetaData(); 
               //We already have the data put it in here....
               MetaDataObj.SetCollDescVarName(ParmNames[i]);
               MetaDataObj.SetObjectID(ParmNames[i]);
               MetaDataObj.SetObsData(ParmValues[i]);
               MetaDataObj.SetObsrCode(ObsCode);
               MetaDataObj.SetisFlash(true);
               MetaDataObj.SetthisURL(exit_method);
               MetaArray[Pos] = MetaDataObj;
               
                Pos ++;
           } 
           
                
            return MetaArray;
        
        }               
/* *********************************************************************************** 
-  Function: GitObservationID  IE
-  Purpose: Returns an Observation Code.   
-  Parameters: ObjName - The ID of the Client Object tag in the form xxxx_yyy where 
-              xxxx is some descriptive name and yyy is the observation code.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function GitObservationID(ObjName)
        { 
           var splitName = ObjName.split("_");
           var ArrLth = splitName.length - 1;
           var Obscde; 
                   
           //See if we have any data. 
           if(splitName[ArrLth] == null || splitName[ArrLth] == "")
             {
                //No data No Problem!! 
                return null;
             }
           Obscde = parseInt(splitName[ArrLth]);
            //See if the last node is a number  
           if(isNaN(Obscde))
            {
                 //No observation code imbedded
                 return null;   
            }
          //TEMPORARY HACK account for asp net controls in the form 
          //"ctl00_ContentPlaceHolderMaster_field_3_0"
           if(splitName[ArrLth] < 100)
            {
                 //No observation code imbedded
                 return null;   
            }
             
           
           return  splitName[ArrLth];
        } 
/* *********************************************************************************** 
-  Function: FlashObsNoMetadata  IE
-  Purpose: Hook for Flash sites to enable observations.  NB, No metadata is associated
-           with this observation.      
-  Parameters: ObsCode - The numeric representation of an observation. 
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function FlashObsNoMetadata(ObsCode)
        { 
          DynObs = new DYNObservation(ObsCode, null, exit_method, null, null, true);
           //Record the observation
          DynObs.PutObservation();
        } 
/* *********************************************************************************** 
-  Function: FlashObsMetadata  IE
-  Purpose: Hook for Flash sites to enable observations.  NB, Metadata is associated
-           with this observation.      
-  Parameters: ObsCode - The numeric representation of an observation. 
-              ParmNames - A list of data value names.  
-              ParmValues - A list of data values associated with ParmNames.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function FlashObsMetadata(ObsCode, parmlistnames, parmvalues)
        { 
          DynObs = new DYNObservation(ObsCode, null, exit_method, parmlistnames, parmvalues, true);
           //Record the observation
          DynObs.PutObservation();
        }                                                           
 
/* *********************************************************************************** 
-  Function: FindID IE
-  Purpose: Finds the value of an ID imbedded in the ASP.Net munged ID.
-  Parameters: inIDName - The value of the ID that we want.
-              inRawID -  The actual value of the ID. 
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */        
        function FindID(inIDName, inRawID)
        {   
           var regxx = eval("/" + inIDName + "/gi");
           var resArray; 
           if(inRawID != null)
            {
                resArray = inRawID.match(regxx);
                if(resArray)
                { 
                    return true;
                }
                else
                {    
                    return false;
                }
           }  
       }                    
        
/////////////////////// Private Methods ///////////////////////////////////        
/* *********************************************************************************** 
-  Function: isType  IE
-  Purpose: Determines the type of an object 
-  Parameters: inTypeName - the value of the type that we are looking for.
-              inType -  The string passed from AjaxPro with the type imbedded.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */        
        function isType(inTypeName, inType)
        {   
           var regxx = eval("/" + inTypeName + "/gi");
           var resArray; 
           if(inType != null)
            {
                resArray = inType.match(regxx);
                if(resArray)
                { 
                    return true;
                }
                else
                {    
                    return false;
                }
           }  
       }            
     
}   

/*End IE Utility Classes *************************************************************/ 
/*End IE Classes *********************************************************************/
/************************************************************************************/ 
/**** NS Moz Classes ****************************************************************/ 
/* *********************************************************************************** 
-  Class: NonIEUtility
-  Purpose: Performs Utility Functions for NON IE browser.
-  Date:  6/01/2006
-  Mods:
-     
************************************************************************************ */
function NonIEUtility()
{
//Constructors
    this.Init = Init();
// Public Function Declarations ////////////////////////
     this.GetEevent = GetEevent;
     this.MetaObjectFactory = MetaObjectFactory;
     this.GitObservationID = GitObservationID;
     this.FlashObsNoMetadata = FlashObsNoMetadata;
     this.FlashObsMetadata = FlashObsMetadata;
     this.FlashMetaObjectFactory = FlashMetaObjectFactory;
     this.FindID = FindID;    
     
////////////////////////////////////////////////////////
     var _ErrHandler;
     var _AjaxProxy;            //Pointer to Server Ajax Object
// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: Init  
-  Purpose: Constructor sets up any metadata for this observation.  If this request
-           is from a Flash site, we already have the data in the ParmNames/ParmValues
-           list.  We initialize the metadata objects differently      
-  Parameters: ObsCode - Observation Code that represents this observation. 
-              CurEvent - The client event ID that triggered this action.  
-              ParmNames - A list of data value names.  
-              ParmValues - A list of data values associated with ParmNames.  
-              isFlash - Is this a request from a Flash site.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function Init()
        { 
             //Declare error handler
           _ErrHandler = CommonUtil.GetErrRef();
           _AjaxProxy = AjaxProxy;      
         
          
        }

/* *********************************************************************************** 
-  Function: MetaObjectFactory Non IE
-  Purpose: Returns a DYNObsMetaData object with all metadata. 
-  Parameters: ObsCode - The Observation Code for this Observation. 
-              ObjName - The ID of the Client Object tag. 
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function MetaObjectFactory(ObsCode, ObjName)
        { 
            var ObjectArray = new Array();
            var MetaArray = new Array();
            var DataObjList = _AjaxProxy.GitObservationData(ObsCode).value;
      
            var DataObj;
            var MetaDataObj;
            var Pos = 0;
  
            ObjectArray = DataObjList
            for (i in ObjectArray)
                {        
                    var DataObj = ObjectArray[i];
         
                    if(isType("ObsMetaData", DataObj.__type))
                        {                         
                            MetaDataObj = new DYNObsMetaData(); 
                            MetaDataObj.SetCollDescVarName(DataObj.CollDescVarName);
                            MetaDataObj.SetCollDescAttrName(DataObj.CollDescAttrName);
                            MetaDataObj.SetObjectID(ObjName);
                            MetaDataObj.SetObsrCode(ObsCode);
                            MetaDataObj.SetthisURL(exit_method);
                            MetaArray[Pos] = MetaDataObj;
                             
                            Pos ++;
                        }

                }
                
                return MetaArray;
        
        } 
/* *********************************************************************************** 
-  Function: FlashMetaObjectFactory Non IE
-  Purpose: Returns a DYNObsMetaData object with all metadata. This is for requests 
-           from a Flash site.  We alresdy have the data.
-  Parameters: ObsCode - The Observation Code for this Observation. 
-              ParmNames - A list of data value names.  
-              ParmValues - A list of data values associated with ParmNames.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function FlashMetaObjectFactory(ObsCode, ParmNames, ParmValues)
        {             
            var MetaArray = new Array();
            var MetaDataObj;
            var Pos = 0;
            
            for(i = 0; i < ParmNames.length; i++)
           { 
               MetaDataObj = new DYNObsMetaData(); 
               //We already have the data put it in here....
               MetaDataObj.SetCollDescVarName(ParmNames[i]);
               MetaDataObj.SetObjectID(ParmNames[i]);
               MetaDataObj.SetObsData(ParmValues[i]);
               MetaDataObj.SetObsrCode(ObsCode);
               MetaDataObj.SetisFlash(true);
               MetaDataObj.SetthisURL(exit_method);
               MetaArray[Pos] = MetaDataObj;
               
                Pos ++;
           } 
           
                
            return MetaArray;
        
        }                          
/* *********************************************************************************** 
-  Function: GitObservationID  Non IE
-  Purpose: Returns an Observation Code.   
-  Parameters: ObjName - The ID of the Client Object tag in the form xxxx_yyy where 
-              xxxx is some descriptive name and yyy is the observation code.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function GitObservationID(ObjName)
        { 
           if(ObjName == null)
           {
                return null;
           }
           var splitName = ObjName.split("_");
           var ArrLth = splitName.length - 1;
                   
           //See if we have any data. 
           if(splitName[ArrLth] == null || splitName[ArrLth] == "")
             {
                //No data No Problem!! 
                return null;
             }
            //See if the last node is a number  
           if(isNaN(splitName[ArrLth]))
            {
                 //No observation code imbedded
                 return null;   
            } 
            
             //TEMPORARY HACK account for asp net controls in the form 
          //"ctl00_ContentPlaceHolderMaster_field_3_0"
           if(splitName[ArrLth] < 100)
            {
           
                 //No observation code imbedded
                 return null;   
            }
             
           
           return  splitName[ArrLth];
        }
         
/* *********************************************************************************** 
-  Function: FlashObsNoMetadata Non IE
-  Purpose: Hook for Flash sites to enable observations.  NB, No metadata is associated
-           with this observastion.      
-  Parameters: ObsCode - The numeric representation of an observation. 
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function FlashObsNoMetadata(ObsCode)
        { 
          DynObs = new DYNObservation(ObsCode, null, exit_method, null, null, true);
           //Record the observation
          DynObs.PutObservation();
        } 
/* *********************************************************************************** 
-  Function: FlashObsMetadata Non IE
-  Purpose: Hook for Flash sites to enable observations.  NB, Metadata is associated
-           with this observastion.      
-  Parameters: ObsCode - The numeric representation of an observation. 
-              ParmNames - A list of data value names.  
-              ParmValues - A list of data values associated with ParmNames.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */
    function FlashObsMetadata(ObsCode, parmlistnames, parmvalues)
        { 
          DynObs = new DYNObservation(ObsCode, null, exit_method, parmlistnames, parmvalues, true);
           //Record the observation
          DynObs.PutObservation();
        }                                                           
                        
/* *********************************************************************************** 
-  Function: FindID Non IE
-  Purpose: Finds the value of an ID imbedded in the ASP.Net munged ID.
-  Parameters: inIDName - The value of the ID that we want.
-              inRawID -  The actual value of the ID. 
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */        
        function FindID(inIDName, inRawID)
        {   
           var regxx = eval("/" + inIDName + "/gi");
           var resArray; 
           if(inRawID != null)
            {
                resArray = inRawID.match(regxx);
                if(resArray)
                { 
                    return true;
                }
                else
                {    
                    return false;
                }
           }  
       }                    
        
/////////////////////// Private Methods ///////////////////////////////////           
          
/* *********************************************************************************** 
-  Function: isType Non IE
-  Purpose: Determines the type of an object 
-  Parameters: inTypeName - the value of the type that we are looking for.
-              inType -  The string passed from AjaxPro with the type imbedded.  
-  Date:  10/04/2006
-  Mods:
-     
************************************************************************************ */             
        function isType(inTypeName, inType)
        {   
           var regxx = eval("/" + inTypeName + "/gi");
           var resArray; 
           if(inType != null)
            {
                resArray = inType.match(regxx);
                if(resArray)
                { 
                    return true;
                }
                else
                {    
                    return false;
                }
           }  
       }            
                        
/* *********************************************************************************** 
-  Function: GetEevent Non IE
-  Purpose: Returns an event ID.  ONLY Anchor Tags.  If we have an IMG tag, look to see
-           id the parent is an anchor. 
-  Parameters: The event fired. 
-  Date:  5/30/2006
-  Mods:
-     
************************************************************************************ */
    function GetEevent(thisEvent)
        {       
            var eleID; 
            //Get Element tag name.
            var thisEle = thisEvent.target.tagName 
           
            switch(thisEle)
            {
            //If this is an Anchor, get the element.
                case "A":
                       eleID = thisEvent.target.id;
                        //Set the page validation flag for this tag
                         _ErrHandler.PageValidation();
                    break;
            //If this is an IMG see if the parent is an anchor.     
                case "IMG":
                      
                        var imgObject = document.getElementById(thisEvent.target.id);
                        
                        var imgParent = imgObject.parentNode;
                        var imgParentName = imgParent.nodeName;
                         
                        if (imgParentName == "A")
                        {
                            var imgParentAttr = imgParent.attributes["id"];
                            //If no anchor id take image id
                            if(typeof(imgParentAttr) == "undefined")
                            {
                                eleID = imgObject.id;
                            }
                            else
                            { 
                                var imgParentId =  imgParentAttr.nodeValue;                          
                                eleID = imgParentId;
                            } 
                            //Set the page validation flag for this tag
                            _ErrHandler.PageValidation();
                        }
                        //It's an image
                        if(typeof(eleID) == "undefined")
                        {
                            eleID = thisEvent.target.id; 
                            //Set the page validation flag for this tag
                            _ErrHandler.PageValidation();
                        } 
                    break;
             //If this is an INPUT get the ID.     
                case "INPUT":
                        eleID = thisEvent.target.id; 
                        //Set the page validation flag for this tag
                         _ErrHandler.PageValidation(); 
                    break;    
              //If this is a BUTTON get the ID.     
                case "BUTTON":
                        eleID = thisEvent.target.id; 
                        //Set the page validation flag for this tag
                         _ErrHandler.PageValidation(); 
                    break;
              //If this is an AREA get the ID.      
                 case "AREA":
                       eleID = thisEvent.target.id; 
                     break;         
                 default:
                       eleID = null;
                    break;                             
             }
        
            return eleID;
        
        }
        
       
                
     
}       
/*End* NS Moz Classes *************************************************************/     
  
    
 


