/** Dom onLoad event hanlder object. */ var DOMEvents = new Object(); /** Array storing the functions to call. */ DOMEvents.Entries = new Array(); /** State variables. */ DOMEvents.State = 0; DOMEvents.REGISTERED = 1; DOMEvents.LOADED = 2; /** * Register a function for the onDomLoaded event. */ DOMEvents.register = function (fCallback) { this.Entries[this.Entries.length] = fCallback; if (this.State >= this.LOADED) { this._run(); } } /** * Run the registered functions. */ DOMEvents._run = function () { // Call all the registered functions. for (var i = 0; i < this.Entries.length; i++) { this.Entries[i](); } // Reset array and set state to loaded. this.Entries = new Array(); this.State = this.LOADED; } /** * Register the events needed. */ DOMEvents._registerEvent = function () { if (this.State < this.REGISTERED) { // Case GECKO if (document.addEventListener) { document.addEventListener('DOMContentLoaded', function () { DOMEvents._run(); }, null); this.State = this.REGISTERED; } // Case IE /* var sAgent = navigator.userAgent.toLowerCase(); if (sAgent.indexOf('msie') != -1 && sAgent.indexOf('opera') == -1) { if (document.getElementsByTagName && (document.getElementsByTagName('body')[0] != null || document.body != null)) { var oHtml = document.getElementsByTagName('html')[0]; var oScript = document.createElement('script'); oScript.type = 'text/javascript'; oHtml.appendChild(oScript); oScript.text = 'DOMEvents._run();'; this.State = this.REGISTERED; } else { setTimeout(function () { DOMEvents._registerEvent(); }, 10); } } */ // Default if (this.State < this.REGISTERED) { if (document.body) { if (document.body._DOMLoaded) { DOMEvents._run(); } else { var fOldOnLoad = window.onload; window.onload = function () { DOMEvents._run(); if (fOldOnLoad) fOldOnLoad(); } } this.State = this.REGISTERED; } else { setTimeout(function () { DOMEvents._registerEvent(); }, 0); return false; } } return true; } return false; } /** Make sure we have registered the event. */ DOMEvents._registerEvent();