
// ----------------------------------
// cross-browser functions

var IE_all_cache = new Object();
function IE_getElementById(id) {
  if (IE_all_cache[id] == null) {
    IE_all_cache[id] = document.all[id];
  }
  return IE_all_cache[id];
}

if (document.all) {
  document.getElementById = IE_getElementById;
  IS_IE = 1;
  var isIE = 1;
} else {
  IS_IE = 0;
  var isMozilla = 1;
  enableEmu();
}


function enableEmu() {

  // document.all[xx]

  var allGetter = function () {
    var a = this.getElementsByTagName("*");
    var node = this;
    a.tags = function (sTagName) {
      return node.getElementsByTagName(sTagName);
    };
    return a;
  };
  HTMLDocument.prototype.__defineGetter__("all", allGetter);
  HTMLElement.prototype.__defineGetter__("all", allGetter);

  // attach/detach event
  // http://www.webfx.nu/dhtml/ieemu/eventlisteners.html

  HTMLElement.prototype.attachEvent = function (sType, fHandler) {
   var shortTypeName = sType.replace(/on/, "");
   fHandler._ieEmuEventHandler = function (e) {
      window.event = e;
      return fHandler();
   };
   this.addEventListener(shortTypeName, fHandler._ieEmuEventHandler, true);
  };
  HTMLDocument.prototype.attachEvent = HTMLElement.prototype.attachEvent;

  HTMLElement.prototype.detachEvent = function (sType, fHandler) {
   var shortTypeName = sType.replace(/on/, "");
   if (typeof fHandler._ieEmuEventHandler == "function")
      this.removeEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
   else   // we can always try :-)
      this.removeEventListener(shortTypeName, fHandler, true);
  };
  HTMLDocument.prototype.detachEvent = HTMLElement.prototype.detachElement;


  // document.body.focus

  HTMLElement.prototype.focus = function () {
  }

}
