﻿// JScript File  BrowserServicesFactory
/************************************************************************************* 
-  BrowserServicesFactory  This file contains JavaScript classes that handle DOM manipulation
-  for IE and NON-IE browsers.  
**************************************************************************************/
/* *********************************************************************************** 
/* Factory Class                                                                     */
/* *********************************************************************************** 
-  Class: BrowserServicesFactory
-  Purpose: Creates browser specific DOM support classes depending upon browser.
-  Date:  6/01/2006
-  Mods:
-    
************************************************************************************ */
function BrowserServicesFactory()
{
// Constructor /////////////////////////////////////////
  this.Init = Init(); 

// Public Function Declarations ////////////////////////
  this.CreateBrowserServices = CreateBrowserServices;

////////////////////////////////////////////////////////
// Public Functions ////////////////////////////////////
  function Init()
  {
  }   

  //create a utility object that is browser specific
  //this object is created depending upon the present browser
  function CreateBrowserServices()
  {
    var browserType;

    //sniff the browser
    if(document.all)
    {
      browserType = "IE4+"
    }
    else
    {
      browserType = "Other"
    }  

    var browserServices = null;
    
    switch(browserType)
    {
    case "IE4+":
      browserServices = new IEBrowserServices();
      break;
    case "Other":
      browserServices = new NonIEBrowserServices();
      break;
    default:
      browserServices = new IEBrowserServices();
      break;
    }
    
    return browserServices;
  }
}

/* End Factoy Class *******************************************************************/

/*BrowserServices Classes ********************************************************************/ 
/*IEIEIEIEIEIEIEIEIEIEIEIEIEIEIEIEIE**************************************************/
/* IE Classes                                                                        */ 
/* *********************************************************************************** 
-  Class: IEBrowserServices
-  Purpose: Performs DOM Utility Functions for IE browser.
-  Date:  6/01/2006
-  Mods:
-     
************************************************************************************ */
function IEBrowserServices()
{
// Public Function Declarations ////////////////////////
  this.GetSourceElementId = GetSourceElementId;
  this.CancelEvent = CancelEvent;  
  this.GetEventId = GetEventId;
      
////////////////////////////////////////////////////////
// Public Functions ////////////////////////////////////

  //This function returns the ID of the initiating HTML tag for the event
  function GetSourceElementId(currentEvent)
  {    
    return currentEvent.srcElement.id;
  }

  //this function Cancels the given event
  function CancelEvent(currentEvent)
  {    
    currentEvent.returnValue = false; 
  }

  function GetEventId(currentEvent)
  { 
    var elementId = null; 
    //Get Element tag name.
    var thisEle = currentEvent.srcElement.tagName 

    switch(thisEle)
    {
    case "A":
      elementId = currentEvent.srcElement.id; 
      break;
    case "IMG":
      var imgParent = currentEvent.srcElement.parentElement.tagName;
      //see if the parent is an anchor.
      if (imgParent == "A")
      {                           
        elementId = currentEvent.srcElement.parentElement.id; 
      }
      //no id in the parent anchor; see if it is in the image...
      if(elementId == null)
      {
        elementId = currentEvent.srcElement.id; 
      }
      break;
      
    case "INPUT":
      elementId = currentEvent.srcElement.id; 
      break;
    case "BUTTON":
      elementId = currentEvent.srcElement.id; 
      break;
    case "AREA":
      elementId = currentEvent.srcElement.id; 
      break;    
    default:
      elementId = null;
      break;                         
    }

    return elementId;
  }
}

/*End IE Classes *********************************************************************/
/************************************************************************************/ 
/**** NS Moz Classes ****************************************************************/ 
/* *********************************************************************************** 
-  Class: NonIEBrowserServices
-  Purpose: Performs Utility Functions for NON IE browser.
-  Date:  6/01/2006
-  Mods:
-     
************************************************************************************ */
function NonIEBrowserServices()
{
// Public Function Declarations ////////////////////////
  this.GetSourceElementId = GetSourceElementId;
  this.CancelEvent = CancelEvent;  
  this.GetEventId = GetEventId;
                        
////////////////////////////////////////////////////////
// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: GetSourceElementId NON IE  
-  Purpose:  This function returns the ID of the initiating HTML tag for the
-            event.      
-  Parameters: thisEvnt - The initiating event. 
-               
-  Date:  01/03/2007
-  Mods:
-     
************************************************************************************ */
  function GetSourceElementId(thisEvnt)
  {    
    return thisEvnt.target.id;
  }

/* *********************************************************************************** 
-  Function: CancelEvent NON IE  
-  Purpose:  This function Cancels the event. 
-  Parameters: thisEvnt - The initiating event. 
-               
-  Date:  01/03/2007
-  Mods:
-     
************************************************************************************ */
  function CancelEvent(currentEvent)
  {    
    //document.forms[0].onsubmit = function f(){return false;}
    currentEvent.preventDefault();
  }

  function GetEventId(currentEvent)
  {       
    var eleID; 
    var thisEle = currentEvent.target.tagName 

    switch(thisEle)
    {
    case "A":
      eleID = currentEvent.target.id;
      break;
    case "IMG":

      var imgObject = currentEvent.target;
      var imgParent = imgObject.parentNode;
      var imgParentName = imgParent.nodeName;

      //see if the parent is an anchor.     
      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;
        } 
      }
      //It's an image
      if(typeof(eleID) == "undefined")
      {
        eleID = currentEvent.target.id; 
      } 
      break;
    case "INPUT":
      eleID = currentEvent.target.id; 
      break;    
    case "BUTTON":
      eleID = currentEvent.target.id; 
      break;
    case "AREA":
      eleID = currentEvent.target.id; 
      break;         
    default:
      eleID = null;
      break;                             
    }

    return eleID;
  }
}

/*End* NS Moz Classes *************************************************************/ 
