﻿var DOM;
function DOMInit() {
  DOM = new DOMInterface();
  if (typeof DOMReady == 'function') 
    DOMReady();
}
function DOMInterface() {
  if (document.documentElement) 
    this.document = document.documentElement;
  else if (document.document)
    this.document = document.body;
  else
    return;

  var IsFF2 = !!window.Iterator;
  var IsS3 = (!!window.getComputedStyle && !!window.devicePixelRatio);
  var IsO9 = (!!window.getComputedStyle && !!document.all && !!window.opera);
  var IsIE5x = (!!document.all && !document.compatMode && !window.pageXOffset);
  var IsIE6up = (!!document.all && !!document.compatMode && !window.getComputedStyle);
  var IsIE7 = ((document.documentElement) && (typeof document.documentElement.style.maxHeight != "undefined"));
  var IsIE8 = (!!document.documentMode && (document.documentMode == 8));
  var ScrollDoc = (IsIE5x || IsO9 || IsS3) ? document.body : (IsIE6up || IsFF2) ? document.documentElement : null;
  var BoundsDoc = (IsIE5x || IsO9) ? document.body : (IsS3 || IsIE6up || IsFF2) ? document.documentElement : null;
  this.IsFF2 = IsFF2;
  this.IsFF2up = IsFF2;
  this.IsS3 = IsS3;
  this.IsO9 = IsO9;
  this.IsIE5x = IsIE5x;
  this.IsIE6 = IsIE6up && !IsIE7;
  this.IsIE6up = IsIE6up;
  this.IsIE7 = IsIE7 && !IsFF2;
  this.IsIE8 = IsIE8 && !IsFF2;
  this.IsIE = (this.IsIE5x || this.IsIE6up || this.IsIE7 || this.IsIE8);
  var Me = this;

  if (!!ScrollDoc && !!BoundsDoc) {
    this.scrollLeft = 0;
    this.scrollTop = 0;
    this.clientWidth = 0;
    this.clientHeight = 0;
  }
  function UpdateProperties() {
    if (!!ScrollDoc && !!BoundsDoc) {
      Me.scrollLeft = ScrollDoc.scrollLeft;
      Me.scrollTop = ScrollDoc.scrollTop;
      Me.clientWidth = BoundsDoc.clientWidth;
      Me.clientHeight = BoundsDoc.clientHeight;
    }
  }
  UpdateProperties();
  this.addHandler(window, "resize", UpdateProperties, false);
  this.addHandler(window, "scroll", UpdateProperties, false);
  this.addHandler(window, "unload", Dispose, false);
  function Dispose() {
    Me.document = null;
    Me.removeHandler(window, "resize", UpdateProperties, false);
    Me.removeHandler(window, "scroll", UpdateProperties, false);
    Me.removeHandler(window, "unload", Dispose, false);
    Me = null;
  }  
}
DOMInterface.prototype.getObjectInterface = function(node) {
  var obj = new Object;

  if (node && !node.ownerDocument) 
    obj.target = document.getElementById(node);
  else
    obj.target = node;
  
  if (!obj.target) {
    obj = null;
    return null;
  }
  if (obj.target && obj.target.style) {
    obj.style = obj.target.style;
    if (document.defaultView) {
      if (document.defaultView.getComputedStyle)
        obj.computedStyle = document.defaultView.getComputedStyle(obj.target,null);
      if (document.defaultView.getOverrideStyle)
        obj.overrideStyle = document.defaultView.getOverrideStyle(obj.target,null);
    }
    if (!obj.computedStyle && obj.target.currentStyle)
      obj.computedStyle = obj.target.currentStyle;
    if (!obj.overrideStyle && obj.target.runtimeStyle)
      obj.overrideStyle = obj.target.runtimeStyle;
    
    if (!obj.computedStyle)
      obj.computedStyle = obj.target.style;
    if (!obj.overrideStyle)
      obj.overrideStyle = obj.target.style;
    
    obj.UpdateBounds = function() {
      if (!!obj.computedStyle) {
        obj.x = parseInt(obj.computedStyle.left);
        obj.y = parseInt(obj.computedStyle.top);
        obj.width = parseInt(obj.computedStyle.width);
        obj.height = parseInt(obj.computedStyle.height);
      } 
    };
    obj.UpdateBounds();
    obj.MoveBy = function(x, y) {
      if (document.documentElement) {
        obj.x = parseInt(obj.computedStyle.left) + parseInt(x);
        obj.y = parseInt(obj.computedStyle.top) + parseInt(y);
        obj.overrideStyle.left = obj.x + "px";
        obj.overrideStyle.top = obj.y + "px";
        obj.UpdateBounds();
      } else
        return;
    };
    obj.MoveTo = function(left, top) {
      if (document.documentElement) {
        obj.x = parseInt(left);
        obj.y = parseInt(top);
        obj.overrideStyle.left = obj.x + "px";
        obj.overrideStyle.top = obj.y + "px";
        obj.UpdateBounds();
      } else
        return;
    };
    obj.Move = function(left, top, width, height) {
      if (document.documentElement) {
        obj.x = parseInt(left);
        obj.y = parseInt(top);
        obj.width = parseInt(width);
        obj.height = parseInt(height);
        obj.overrideStyle.left = obj.x + "px";
        obj.overrideStyle.top = obj.y + "px";
        obj.overrideStyle.width = obj.width + "px";
        obj.overrideStyle.height = obj.height + "px";
        obj.UpdateBounds();
      } else
        return;
    };
  }
  return obj;
}
DOMInterface.prototype.getEventInterface = function(e) {
  var obj = new Object;
  if (!e) 
    e = window.event;
  obj.event = e;
  obj.target = (e.target) ? e.target : (e.srcElement) ? e.srcElement : null;
  obj.relatedTarget = (!!e.relatedTarget) ? e.relatedTarget : (!!e.toElement) ? e.toElement : null;
  obj.offsetX = (e.offsetX) ? e.offsetX : (e.layerX) ? e.layerX : null;
  obj.offsetY = (e.offsetY) ? e.offsetY : (e.layerY) ? e.layerY : null;
  obj.clientX = e.clientX - ((e.offsetX) ? 2 : 0);
  obj.clientY = e.clientY - ((e.offsetY) ? 2 : 0);
  return obj;
}
DOMInterface.prototype.normalize = function(node) {
  if (typeof node != 'undefined')
    if (!!node.childNodes && (node.childNodes.length > 0)) {
      var index = node.childNodes.length - 1;
      var ELEMENT_NODE = 1;
      var TEXT_NODE = 3;
      while (index >= 0) {
        var childNode = node.childNodes[index];
        if (typeof childNode != 'undefined')
          switch (childNode.nodeType) {
            case TEXT_NODE:
              if (childNode.nodeValue.replace(/^\s+|\s+$/g,"").length == 0) 
                node.removeChild(childNode);
              break;
            case ELEMENT_NODE:
              this.normalize(childNode);
              break;
            default:
          }
        index--;
      }
    }
}
DOMInterface.prototype.GetPreviousSibling = function(element) {
  var TEXT_NODE = 3;
  var sibling = element.previousSibling;
  if (typeof sibling != 'undefined')
    while (!!sibling && (sibling.nodeType == TEXT_NODE))
      sibling = sibling.previousSibling;
  return sibling;
};
DOMInterface.prototype.GetNextSibling = function(element) {
  var TEXT_NODE = 3;
  var sibling = element.nextSibling;
  if (typeof sibling != 'undefined')
    while (!!sibling && (sibling.nodeType == TEXT_NODE))
      sibling = sibling.nextSibling;
  return sibling;
};
DOMInterface.prototype.DisableTextSelect = function(obj) {
  if (typeof obj.onselectstart != "undefined")  {
    obj.onselectstart = function() { return false; };
    obj.ondrag = function() { return false; };
  } else if (typeof obj.style.MozUserSelect != "undefined") 
    obj.style.MozUserSelect = "none";
  else if (obj == document.body)
    document.onmousedown = function() { return false; };
  else
    obj.onmousedown = function() { return false; };
};
DOMInterface.prototype.EnableTextSelect = function(obj) {
  if (typeof obj.onselectstart != "undefined") {
    obj.onselectstart = null;
    obj.ondrag = null;
  } else if (typeof obj.style.MozUserSelect != "undefined") 
    obj.style.MozUserSelect = "";
  else if (obj == document.body)
    document.onmousedown = null;
  else
    obj.onmousedown = null;
};
DOMInterface.prototype.addHandler = function(oElement, tEvent, pFunction, bCapture) {
  if (!bCapture) 
    bCapture = false;
  if (!!oElement.addEventListener) {
    oElement.addEventListener(tEvent, pFunction, bCapture);
    return true;
  } else if (!!oElement.attachEvent)
    return oElement.attachEvent("on" + tEvent, pFunction);
  else
    return false;
};
DOMInterface.prototype.removeHandler = function(oElement, tEvent, pFunction, bCapture) {
  if (!!oElement.removeEventListener) {
    oElement.removeEventListener(tEvent, pFunction, bCapture);
    return true;
  } else if (!!oElement.detachEvent)
    return oElement.detachEvent("on" + tEvent, pFunction);
  else
    return false;
};
var alreadyrunflag=0;
if (/Safari/i.test(navigator.userAgent)) { 
  var _timer = setInterval(function(){
  if(/loaded|complete/.test(document.readyState)){
    clearInterval(_timer)
    if (!alreadyrunflag) {
      alreadyrunflag = 1;
      DOMInit();
    }
  }}, 1);
} else if (document.addEventListener) 
  document.addEventListener("DOMContentLoaded", function(){ if (!alreadyrunflag) { alreadyrunflag=1; DOMInit();}}, false)
else if (document.all && !window.opera) {
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
  var contentloadtag = document.getElementById("contentloadtag");
  if (contentloadtag.onreadystatechange) 
    contentloadtag.onreadystatechange = function() {
      if ((this.readyState=="complete") && (!alreadyrunflag)) {
        alreadyrunflag=1;
        DOMInit();
      }
    }
} 
function IfNotRan() {
  setTimeout("if (!alreadyrunflag) DOMInit();", 0);
}
if (!!window.addEventListener) 
  window.addEventListener('load', IfNotRan, false);
else if (!!window.attachEvent) 
  window.attachEvent('onload', IfNotRan);
