﻿/*************************************************************************
* A static class to handle browser incompatibilities (most Microsoft IE).
*************************************************************************/
var CrossBrowser =
{
  /******************************************************************
  * Determines whether or not the browser is supported.  The browser
  * must support the DOM (Document Object Model) standard.
  ******************************************************************/
  isSupportedBrowser: function()
  {
    return (document.getElementById ? true : false);
  },

  /************************************************
  * Retrieves the element that triggered an event.
  ************************************************/
  getEventSource: function(e)
  {
    e = e || window.event;
    return e.target || e.srcElement;
  },

  /********************************
  * Gets the key that was pressed.
  ********************************/
  getKeyCode: function(e)
  {
    e = e || window.event;
    return e.keyCode || e.which;
  },

  /**************************************************************************
  * Gets the mouse x/y coordinates relative to one of the specified options:
  * Element, Page, Screen, and Window.
  **************************************************************************/
  getMouseXY: function(e, sRelativeTo)
  {
    e = e || window.event;
    
    var pointMouse = {x: -1, y: -1};
    
    if (sRelativeTo == "Element")
    {
      if (e.offsetX)
      {
        pointMouse.x = e.offsetX;
        pointMouse.y = e.offsetY;
      }
      else
      {
        var targetElement = CrossBrowser.getEventSource(e);
        pointMouse.x = 0;
        pointMouse.y = 0;
        
        while (targetElement.offsetParent)
        {
          pointMouse.x += targetElement.offsetLeft;     
          pointMouse.y += targetElement.offsetTop;
          targetElement = targetElement.offsetParent;
        }
        
        pointMouse.x = e.pageX - pointMouse.x;
        pointMouse.y = e.pageY - pointMouse.y;
      }
    }
    else if (sRelativeTo == "Page")
    {
      pointMouse.x = e.pageX;
      pointMouse.y = e.pageY;
    }
    else if (sRelativeTo == "Screen")
    {
      pointMouse.x = e.screenX;
      pointMouse.y = e.screenY;
    }
    else if (sRelativeTo == "Window")
    {
      pointMouse.x = e.clientX;
      pointMouse.y = e.clientY;
    }
    
    return pointMouse;
  },

  /***************************************
  * Gets the height/width of the element.
  ***************************************/
  getElementSize: function(targetElement)
  {
    var rectElement = {width: 0, height: 0};
    rectElement.height = targetElement.offsetHeight;
    rectElement.width = targetElement.offsetWidth;
    return rectElement;
  },

  /**********************************************
  * Gets the height/width of the browser window.
  **********************************************/
  getWindowSize: function()
  {
    var rectWindow = {width: 0, height: 0};
    rectWindow.height = document.documentElement.clientHeight || window.innerHeight || document.body.clientHeight;
    rectWindow.width = document.documentElement.clientWidth || window.innerWidth || document.body.clientWidth;
    return rectWindow;
  },

  /*******************************
  * Gets the text of the element.
  *******************************/
  getElementText: function(targetElement)
  {
    if (targetElement.childNodes[0] != null)
      return targetElement.childNodes[0].nodeValue
    else
      targetElement.innerText;
  },

  /*******************************
  * Sets the text of the element.
  *******************************/
  setElementText: function(targetElement, sValue)
  {
    if (targetElement.innerText)
      targetElement.innerText = sValue;
    else if (oElement.childNodes[0] == null)
      targetElement.appendChild(document.createTextNode(sValue));
    else
      targetElement.childNodes[0].nodeValue = sValue;
  }
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();