//
// (c) Dmitry Koteroff, http://www.dklab.ru
//

// Multiple onload callback support.
(function() {
  var onloads = [];
  window.attachOnload = function(func) {
    onloads[onloads.length] = func;
  }
  window.executeOnloads = function() {
    for (var i=0; i<onloads.length; i++) onloads[i]();
  }
})();

// Cross-browser addEventListener()/attachEvent() replacement.
function addEvent(elt, name, handler, dependant, atEnd) {
  name = name.replace(/^(on)?/, 'on');
  var prev = elt[name];
  var tmp = '__tmp';
  if (dependant) elt['dep'] = dependant;
  elt[name] = function(e) {
    if (!e) e = window.event;
    var result;
    if (!atEnd) {
      elt[tmp] = handler; result = elt[tmp](e); elt[tmp] = null; // delete() does not work in IE 5.0 (???!!!)
      if (result === false) return result;
    }
    if (prev) {
      elt[tmp] = prev; result = elt[tmp](e); elt[tmp] = null;
    }
    if (atEnd && result !== false) {
      elt[tmp] = handler; result = elt[tmp](e); elt[tmp] = null;
    }
    return result;
  }
  return handler;
}

// Emulation of innerText for Mozilla.
if (window.HTMLElement && window.HTMLElement.prototype.__defineSetter__) {
  HTMLElement.prototype.__defineSetter__("innerText", function (sText) {
     this.innerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  });
  HTMLElement.prototype.__defineGetter__("innerText", function () {
     var r = this.ownerDocument.createRange();
     r.selectNodeContents(this);
     return r.toString();
  });
}

attachOnload(function() {
    return false;
});

attachOnload(function() {
    var T = document.getElementsByTagName("TABLE");
    for(var i=0;i<T.length;i++) {
	if (T[i].summary) { addEvent(T[i], 'onclick', clickMe, T[i]); }
    }
    function clickMe() {
	window.location.href = this.summary;
    }
});

