<?xml version="1.0"?>

<bindings
   xmlns="http://www.mozilla.org/xbl"
   xmlns:html="http://www.w3.org/1999/xhtml"
>

<binding id="head">
  <implementation>
    <constructor>
        <![CDATA[
			var listeners = ['dblclick','click','mousedown','mouseup','mousemove','mouseover','mouseout','keypress','keydown','keyup','focus','DOMFocusIn','DOMFocusOut','DOMActivate','blur','change','scroll','select','cut','copy','paste','drop','contextmenu','drag','dragenter','dragleave','dragover'];

			function cleanup(){
				window.removeEventListener("beforeunload", arguments.callee, true); 
				for(var i = 0; i < listeners.length; i++) 
					window.removeEventListener(listeners[i], stopEvent ,true);
				//alert('cleanup done listeners='+listeners.length);
			}

			function stopEvent(event){
				if(document.getElementById('stopEvents')) 
					event.stopPropagation();
			}


			var doc = this.ownerDocument;
			try{ 
				var isDoc = ( (doc instanceof HTMLDocument || doc instanceof HTMLIFrameElement) 
							&& !String(doc.location.href).toLowerCase().indexOf("http") ) 
			}catch(e){}
			if(!isDoc)
				return;
			var head_tag = doc.getElementsByTagName('head')[0];
			if(!head_tag)
				return; 

 			var script_tag = doc.createElement('script');  
			script_tag.setAttribute('type', 'text/javascript');  
			script_tag.setAttribute('id', 'domscr'); 
			var text = "document.docevents = []; var oldDAEL = document.addEventListener; document.addEventListener = function (oldDAEL) {return function (evt, func, bCapture) {oldDAEL.call (this, evt, func, bCapture); document.docevents.push( [evt, func, bCapture] ); } }(oldDAEL); ";
			text += "  document.winevents = []; var oldWAEL = window.addEventListener; window.addEventListener = function (oldWAEL) {return function (evt, func, bCapture) {oldWAEL.call (this, evt, func, bCapture); document.winevents.push( [evt, func, bCapture] ); } }(oldWAEL); "; 
			text += " var domscript = document.getElementById('domscr'); domscript.parentNode.removeChild(domscript); ";
			script_tag.text = text;
			head_tag.appendChild(script_tag);
			
			//disarm event-listeners: 
			for(var i = 0; i < listeners.length; i++) 
				window.addEventListener(listeners[i], stopEvent ,true);
			window.addEventListener('beforeunload', cleanup ,true);

        ]]>
    </constructor>
  </implementation>
</binding>




</bindings>