
		var ie = document.all != null;
		var mozilla = !ie && document.getElementById != null && document.layers == null;

		// for mozilla only
		if (mozilla)
		{
		    EmulateEvent(["load"]);
		    EmulateEvent(["keypress"]);
		    EmulateEvent(["click"]);
		    NodeEmulation();
		}
		
		function EmulateEvent(events)
		{
		    for (var i = 0; i < events.length; i++) 
		    {
		        document.addEventListener(events[i], 
		            function (e) 
		            {
		                window.event = e
		            }, true);   // using capture
		    }

		    Event.prototype.__defineGetter__("srcElement", 
		        function () 
		        {
		            var node = this.target
		            while (node.nodeType != 1) node = node.parentNode
		            return node
		        }
		    )
		}
		
		function RemoveOnSequence(str)
		{
		    return str.replace(/on/, "");
		}

		// adds to all elements IE attachEvent/detachEvent functions
		function AttachDetachEvent() 
		{
		    // sType contains event string name, e.g. "onclick"
		    HTMLDocument.prototype.attachEvent = 
		        HTMLElement.prototype.attachEvent = function (sType, fHandler) 
		        {
		            fHandler._EmuHandler = function(e) 
		            {
		                window.event = e;
		                return fHandler();
		            };
		            
		            this.addEventListener(RemoveOnSequence(sType), fHandler._EmuHandler, false);
		        };
		
		    HTMLDocument.prototype.detachEvent = 
		        HTMLElement.prototype.detachEvent = function (sType, fHandler) 
		        {
		            if (typeof fHandler._EmuHandler == "function")
		                this.removeEventListener(RemoveOnSequence(sType), fHandler._EmuHandler, false);
		        };
		}

		function NodeEmulation()
		{
			Node.prototype.swapNode = function(node) 
			{
				var nextSibling = this.nextSibling
				var parentNode = this.parentNode
				node.parentNode.replaceChild(this, node)
				parentNode.insertBefore(node, nextSibling)
			}
		}

