/* ========================================================================== */
/* x-browser getElementById
/* ========================================================================== */
function getObject(id)
{
  if (document.getElementById)
  {
    return document.getElementById(id);
  }
  else if (document.all)
  {
    return document.all[id];
  }
  else if (document.layers)
  {
    return getObjNN4(document,id);
  }
}
function getObjNN4(obj,id)
{
  var x = obj.layers;
  var foundLayer;
  for (var i=0;i<x.length;i++)
  {
    if (x[i].id == id)
      foundLayer = x[i];
    else if (x[i].layers.length)
      var tmp = getObjNN4(x[i],id);
    if (tmp) foundLayer = tmp;
  }
  return foundLayer;
}

/* ========================================================================== */
/* show/hide layers
/* ========================================================================== */
function show(id) {
  var o = getObject(id);
  if(o) o.style.display = "block";
}
function hide(id) {
  var o = getObject(id);
  if(o) o.style.display = "none";
}

  /// <summary>
  /// Show processing animation
  /// </summary>
  var isProcessing = false;
  function showProcessing() {
    showPopup("processing");
    isProcessing=true;
  }
  /// <summary>
  /// Hide processing animation
  /// </summary>
  function hideProcessing() {
    hidePopup("processing");
    isProcessing=false;
  }

  /// <summary>
  /// Show popup window
  /// </summary>
  function showPopup() {
    show("popup");
    show("popupBg");
  }
  /// <summary>
  /// Show popup window
  /// </summary>
  function hidePopup() {
    hide("popup");
    hide("popupBg");
  }


/**
 * X-browser event handler attachment and detachment
 * TH: Switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
  if (window.innerHeight!=window.undefined) return window.innerHeight;
  if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
  if (document.body) return document.body.clientHeight; 

  return window.undefined; 
}
function getViewportWidth() {
  var offset = 17;
  var width = null;
  if (window.innerWidth!=window.undefined) return window.innerWidth; 
  if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
  if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
  if (self.pageYOffset) // all except Explorer
  {
    return self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
    // Explorer 6 Strict
  {
    return document.documentElement.scrollTop;
  }
  else if (document.body) // all other Explorers
  {
    return document.body.scrollTop;
  }
}
function getScrollLeft() {
  if (self.pageXOffset) // all except Explorer
  {
    return self.pageXOffset;
  }
  else if (document.documentElement && document.documentElement.scrollLeft)
    // Explorer 6 Strict
  {
    return document.documentElement.scrollLeft;
  }
  else if (document.body) // all other Explorers
  {
    return document.body.scrollLeft;
  }
}
