// * * * IEemul.js
// * * * Written and Copyright By David Blackledge, Summer 2000
// * * * added attachEvent, some other stuff January 2001
// * * * Simulate the "style" property used in IE as well as the "all" collection and a few other things like the window.event object.
// * * * Some other IE features supported as well (see documentation on below web-site)
// * * * You have permission to duplicate and make use of this file in your own web page if you do not modify it and you are not an employee of Microsoft Corp or any of its related companies.
// * * * If you want to use it outside of the conditions stated in the previous sentence, contact me.
// * * * It'd also be nice if you dropped me a line to let me know you're using it.
// * * * http://David.Blackledge.com
// * * * David @ Blackledge.com
/*
NO WARRANTIES. USE AT YOUR OWN RISK.
IF ANYTHING GOES WRONG BECAUSE OF YOUR USE OF THIS CODE,
 IT'S YOUR OWN FAULT FOR THINKING IT WAS RELIABLE WHEN YOU DIDN'T EVENT PAY FOR IT.
NETSCAPE HAS BEEN KNOWN TO *CRASH* UNDER CERTAIN CIRCUMSTANCES WITH REPEATED USE OF
 COMPLEX FUNCTIONS LIKE THOSE USED BY THIS LIBRARY. 
*/
/* stuff to do:
note: all elements in IE have .document (like layer has)

NS: window.screenX/Y, window.pageX/YOffset (scroll position)
document.width/height

IE:
window.screenLeft/Top = screenX/Y + border,etc ((outerWidth-innerWidth)/2)
window funcs: createPopup(),showModalDialog,showModelessDialog
document.frames = window.frames,
document...
activeElement,  documentElement=window.document , 
 , fileCreatedDate , fileModifiedDate=lastModified , fileSize , 
parentWindow , protocol , readyState , 
selection.createRange()TextRange[0].text=.getSelection()&type="text"|"none" 
, URLUnencoded 
*/
/*@cc_on @*/
// create a conditional compilation (IE-only feature) that is always false,
// thus IE never compiles anything in this file.

/*@if (@_jscript_version < 0) */
/*
function CollectionFunc(index) {
}
function Collection(array) {
 this = CollectionFunc;
 this.array = array;
 
}
*/

window.execScript = new Function("x","lang","return eval(x);");
window.navigate = new Function("x","return window.location.href = x");
Object.prototype.fireEvent = new Function("name","e",
"if(e!=null)window.event=e;"+
" window.event.srcElement = this;"+
" window.event.type = name.substring(2);"+
" if(this.constructor==Layer && typeof(this.handleEvent)!='function')"+
"  return this.document.handleEvent(name); // supposedly, Layer doesn't have handleEvent"+
" else"+
"  return this.handleEvent(name);");

// IE5.5 only.  allow multiple-dispatching of events
Object.prototype.attachEvent = new Function("sEvent","handler",
"if(this[sEvent] != attachedEventsHandler) {"+//first time setup
" this['reg'+sEvent] = this[sEvent];"+
" this[sEvent] = attachedEventsHandler;"+
" this[sEvent+'attachedEvents'] = new Array();"+
" this.watch(sEvent,window.watchEvent);"+ // make sure we're watching this thing.
"}"+
"this[sEvent+'attachedEvents'][this[sEvent+'attachedEvents'].length]=handler;"+
"return true;");

// IE5.5 only. remove events added with attachEvent
Object.prototype.detachEvent = new Function("sEvent","handler",
"if(this[sEvent] == attachedEventsHandler) {"+
" for(var i = 0 ; i < this[sEvent+'attachedEvents'].length ; ++i) {"+
"  if(this[sEvent+'attachedEvents'][i] == handler)"+
"   {this[sEvent+'attachedEvents'][i] = null;break;}"+
" }"+
"}");

// MS Docs don't say what happens regarding return values for attached Events (and the regular event)... so I'm guessing here.
// Actually, my guess would be: return whatever the non-attached version of event returns.
// But, for my own purposes, I'm going to return an "AND" of all returned values.
function attachedEventsHandler(e) {
	// should make sure window.event is set up, but for now, let document and all, etc., handle that
	var returnval = true;
	if(this['regon'+e.type]) // fire original event (if it is defined)
		returnval = this['regon'+e.type]();
	var aEvents = this['on'+e.type+'attachedEvents'];
    // fire all attached events "in random order"
	for(var i = (aEvents.length-1) ; i >= 0 ; --i) {//IE appears to fire them last-first
		if(aEvents[i])
			returnval = (aEvents[i]()===false?false:returnval);
	}
	return returnval;
}

function addRule(context,rules) {
	if(context==0) return window; // use this func for the styleSheets collection also.
	var rulesarray = rules.split(";"); // in case multiple rules are allowed.
	for(var r = 0; r < rulesarray.length ; ++r) {
	 var rule = rulesarray[r];
	 var ruleitem = rule.substring(0,rule.indexOf(":"));
	 // convert stuff like background-color to backgroundColor
	 for(
		var start=0, dash = ruleitem.indexOf("-") ;
		dash > -1 ;
		start = dash, dash = ruleitem.indexOf("-")
	 ) {
	  ruleitem = ruleitem.substring(start,dash) +
	   ruleitem.charAt(dash+1).toUpperCase() +
	   ruleitem.substring(dash+2);
	 }
	 var ruleval = rule.substring(rule.indexOf(":")+1);
	 var contextarray = context.split(" ");
	 var contexts = "";
	 for(var i = 0 ; i < contextarray.length ; ++i) {
	  if(contextarray[i].length == 0) continue; // 2 spaces in a row
	  var dot = contextarray[i].indexOf(".");
	  var pound = contextarray[i].indexOf("#");
	  if(pound > -1) {
	   contexts += "document.ids."+contextarray[i].substring(pound+1)+",";
	  } else if(dot > -1) {
	   var classtag = contextarray[i].substring(0,dot);
	   if(classtag == "") classtag = "all";
	   contexts += "document.classes."+contextarray[i].substring(dot+1)+"."+classtag+",";
	  } else {
	   contexts += "document.tags."+contextarray[i]+",";
	  }
	 }
	 if(contexts.length > 0) {
	  // remove last ","
	  contexts = contexts.substring(0,contexts.length-1);
	  eval("document.contextual("+contexts+")."+ruleitem+"=\""+ruleval+"\"");
	 }
	}// end for loop of rules
}
 window.document.styleSheets = addRule; // styleSheets(0).addRule will work
 window.document.styleSheets[0] = window; // syleSheets[0].addRule will work.
 window.document.styleSheets.length = 1;

function style(forObj) {
	this.objRef = forObj;
//	function objForStyle(styleobj,doc) {
//	   if(doc.style === styleobj) return doc;
//	   else {
//		for(var i = 0 ; i < doc.layers.length ; ++i) {
//		 if(doc.layers[i].style === stylobj) return doc.layers[i];
//		}
//		var retobj = null;
//		for(var i = 0 ; i < doc.layers.length ; ++i) {
//		 retobj = styleobj.objForStyle(styleobj, doc.layers[i].document);
//		 if(retobj != null) return retobj;
//		}
//		return null;
//	   }
//	}
//	this.objForStyle = objForStyle;

	function _watchStyle(prop,oldval,newval) {
//	 // try to set objRef if not set
//	 if(this.objRef == null) {
//	  this.objRef = objForStyle(this,window.document);
//	 }
     if(prop.indexOf("pixel") == 0)
      prop = prop.substring(5).toLowerCase();
	 if(prop == "backgroundColor")
	  this.objRef.bgColor = newval;
	 else if (prop == "clip") {
	  // parse the "rect" expression and assign values accordingly.
	  if(newval.indexOf("rect") != -1) {
	   var lookfor = " ";
	   if(newval.indexOf(", ") != -1) lookfor=", ";
	   else if(newval.indexOf(",") != -1) lookfor=",";
	   var currpos = newval.indexOf("(")+1;
	   while(newval.charAt(currpos) == lookfor)currpos++;
	   var top = newval.substring(currpos,newval.indexOf(lookfor,currpos));
	   currpos = newval.indexOf(lookfor,currpos)+lookfor.length;
	   while(newval.charAt(currpos) == lookfor)currpos++;
	   var right = newval.substring(currpos,newval.indexOf(lookfor,currpos));
	   currpos = newval.indexOf(lookfor,currpos)+lookfor.length;
	   while(newval.charAt(currpos) == lookfor)currpos++;
	   var bottom = newval.substring(currpos,newval.indexOf(lookfor,currpos));
	   currpos = newval.indexOf(lookfor,currpos)+lookfor.length;
	   while(newval.charAt(currpos) == lookfor)currpos++;
	   var end = newval.indexOf(lookfor,currpos);
	   if(end == -1)
		end = newval.indexOf(")",currpos);
	   var left = newval.substring(currpos,end);
	   if(top=="auto") top = "0";
	   if(right=="auto") right = ""+Math.max(this.objRef.document.width,this.objRef.clip.width);
	   if(bottom == "auto") bottom = ""+Math.max(this.objRef.document.width,this.objRef.clip.height);
	   if(left=="auto") left = "0";
	   this.objRef.clip.top = parseInt(top);
	   this.objRef.clip.right = parseInt(right);
	   this.objRef.clip.bottom = parseInt(bottom);
	   this.objRef.clip.left = parseInt(left);
	  } else if(newval == "auto") { // expose entire object
	   this.objRef.clip.left = 0;
	   this.objRef.clip.top = 0;
	   this.objRef.clip.right = this.objRef.clip.width;
	   this.objRef.clip.bottom = this.objRef.clip.height;
	  }
	 } else if (prop == "visibility") {
	  if(newval == "hidden")
	   this.objRef.visibility = "hide";
	  else if(newval == "visible")
	   this.objRef.visibility = "show";
	  else
	   this.objRef.visibility = newval;
	 } else if(this.objRef.constructor == Layer) {
      //documents do have height and width.. layer only has clip height and width
      if(prop == "height") {
       this.objRef.clip.height = newval;
       this.objRef.offsetHeight = newval; // document's offset is the window.. never change that.
      } else if (prop == "width") {
       this.objRef.clip.width = newval;
       this.objRef.offsetWidth = newval;
	  } else if (prop == "left") { // ignore left and top for documents (leave at 0)
	   this.objRef.pageX += (newval-oldval);
	   this.objRef.offsetLeft = this.objRef.pageX;
	   this.objRef.clientLeft = this.objRef.pageX;
	  } else if (prop == "top") {
	   this.objRef.pageY += (newval-oldval);
	   this.objRef.offsetTop = this.objRef.pageY;
	   this.objRef.clientTop = this.objRef.pageY;
      } else {
	   eval("this.objRef."+prop+"=\""+newval+"\";");
      }
	 } else {
	  eval("this.objRef."+prop+"=\""+newval+"\";");
     }

	 // Regardless of special case for REAL value setting,
	 // also set the "read-only" values
	 if(prop == "height") {
      this.objRef.clientHeight = newval;
	 } else if(prop == "width") {
      this.objRef.clientWidth = newval;
	 }
	 return newval;
	}
	this.watchStyle = _watchStyle;
	// making watchStyle an attr instead of a "temporary" function fixed the style
	// forgetting to watch things after an innerHTML set.
	// not as straightforward to do funcs in the IEAll function, though... figure that out.

    var isLayer = false;
    if(this.objRef.constructor == Layer)
     isLayer = true;

	this.backgroundColor = this.objRef.bgColor;
	this.watch("backgroundColor",this.watchStyle);
    if(isLayer) this.height = this.objRef.clip.height;
	else this.height = this.objRef.height;
	this.watch("height",this.watchStyle);
    if(isLayer) this.width = this.objRef.clip.width;
    else this.width = this.objRef.width;
	this.watch("width",this.watchStyle);
	if(isLayer) {
		this.clip = "rect("+this.objRef.clip.top+" "+this.objRef.clip.right+" "+this.objRef.clip.bottom+" "+this.objRef.clip.left+")";
		this.watch("clip",this.watchStyle);
		this.left = this.objRef.left;
		this.watch("left",this.watchStyle);
		this.top = this.objRef.top;
		this.watch("top",this.watchStyle);

		this.pixelLeft = this.left;
		this.watch("pixelLeft",this.watchStyle);
		this.pixelTop = this.top;
		this.watch("pixelTop",this.watchStyle);

		this.visibility = this.objRef.visibility;
		if(this.visibility == "show") this.visibility = "visible";
		else if(this.visibility == "hide") this.visibility == "hidden";
		this.watch("visibility",this.watchStyle);
		this.zIndex = this.objRef.zIndex;
		this.watch("zIndex",this.watchStyle);
	}
	this.pixelHeight = this.height;
	this.watch("pixelHeight",this.watchStyle);
	this.pixelWidth = this.width;
	this.watch("pixelWidth",this.watchStyle);
}

function watchEvent(p,o,n) {
  var evnt = eval("Event."+p.substring(2).toUpperCase()); 
  if(n==null || typeof(n)=="undefined") {
	  // some events for Layer should be handled by the layer's document.
	  // ... at least I thought so, but it's working for ALL events with just the layer, so leave it be.
	  if(this == window) { // if they'd overwrite our top-level capturing:
		  // clear the variable that our event capturer will call.
		  window["toplevelevent"+p.substring(2).toUpperCase()] = null;
		  n=o; // return the old value.
	  } else {
		  this.releaseEvents(evnt);
	  }
  } else {
	  if(this == window) { // if they'd overwrite our top-level capturing:
		  // set up a variable that our event capturer will call.
		  window["toplevelevent"+p.substring(2).toUpperCase()] = n;
		  n=o; // return the old value.
	  }
	  // some events for Layer should be handled by the layer's document.
	  // ... at least I thought so, but it's working for ALL events with just the layer, so leave it be.
	  // Note: mouseover and mouseout have the LAYER as their target,
	  //  but others have the DOCUMENT as their target.
	  // Note also: click is always a problem when you're over text, but dblclick works fine.
	  //  Use a separate layer on top of your text-filled layer to handle events.

	  this.captureEvents(evnt);
	  window.beSureToCapture(evnt);
  }
  // now see if we're handling attached Events, and make sure things work right.
  if(o == attachedEventsHandler) { // we've done event attachment, and forever on shall.
	  this['reg'+p] = n; // change the value for the non-attached event handler.
	  n = o; // maintain the attachedEventHandler thing
  }
  return n;
}
window.htmlWatch = new Function("p","o","n","this.document.open();this.document.write(n);this.document.close();return n");

// Simulate the IE "all" collection for documents and layer objects.
// Will return a reference to any property of the object with the given name.
// or, failing that, any layer (immediately-) below the object with the given name.
// Also implements the style object and an innerHTML property for the object.
// handles "body" as a special case and sets offset/clientWidth/Height appropriately.
function IEAll(idname) {
 var returnobj = this[idname];
 if(typeof(this[idname]) != "undefined")
  returnobj = this[idname];
 else if(typeof(this.layers[idname]) != "undefined")
  returnobj = this.layers[idname];
 else if(this.constructor != Layer && idname == "body") {
  returnobj = this; // assumably a document object.
 }
 // if we still don't have anything, do a recursive search through the layers
 for(var i = 0 ; (typeof(returnobj)=="undefined") && (i < this.layers.length) ; ++i) {
   returnobj = this.layers[i].all(idname);
 }
 // give up if it's still undefined.
 if(typeof(returnobj) == "undefined")
  return returnobj;

 // add a reference for obj.all.id type context (not to mention obj.all["id"])
 // (breaks if inner/outerHTML is set (when document is re-written))
 this.all[idname] = returnobj;

 if(typeof(returnobj.style) == "undefined")
  returnobj.style = new style(returnobj);

 if(typeof(returnobj.innerHTML) == "undefined") {
  returnobj.innerHTML = "document contents";
  returnobj.outerHTML = "<DIV>document contents</DIV>";
 }
  // for some reason we have to re-watch innerHTML though it SHOULD only require a single watching.
  // (a watch is supposed to persist even if the property is deleted)
  returnobj.watch("innerHTML",htmlWatch);
  returnobj.watch("outerHTML",htmlWatch);

// if(typeof(returnobj.offsetLeft) == "undefined") {
  // sadly, these are read-only, but they need to be used for accurate reading, so we can't make them truly read-only and still keep them up-to-date
// }
 if(returnobj == document) {
  if(typeof(returnobj.offsetWidth) == "undefined") {
  // sadly, these are read-only, but they need to be used for accurate reading, so we can't make them truly read-only and still keep them up-to-date
   returnobj.offsetLeft = 0;
   returnobj.offsetTop = 0;
   returnobj.offsetParent = document; // doc might not have offset/client stuff set yet, though
   returnobj.offsetWidth = window.innerWidth;
   returnobj.clientWidth = window.outerWidth;
   returnobj.offsetHeight = window.innerHeight;
   returnobj.clientHeight = window.outerHeight;
   // no attempt to watch them at the moment.
  }
 } else {
  if(typeof(returnobj.offsetWidth) == "undefined") {
   returnobj.offsetLeft = returnobj.pageX;
   returnobj.offsetTop = returnobj.pageY;
   returnobj.offsetParent = returnobj.parentLayer.document;
   returnobj.offsetWidth = returnobj.clip.width;
   returnobj.clientWidth = returnobj.clip.width;
   returnobj.offsetHeight = returnobj.clip.height;
   returnobj.clientHeight = returnobj.clip.height;
   // no attempt to watch them at the moment.
  }
 }
 returnobj.watch("onfocus",window.watchEvent);
 returnobj.watch("onblur",window.watchEvent);
 returnobj.watch("onmousedown",window.watchEvent);
 returnobj.watch("onmouseup",window.watchEvent);
 returnobj.watch("onclick",window.watchEvent);
 returnobj.watch("ondblclick",window.watchEvent);
 returnobj.watch("onmousemove",window.watchEvent);
 returnobj.watch("onmouseover",window.watchEvent);
 returnobj.watch("onmouseout",window.watchEvent);
 returnobj.watch("onkeydown",window.watchEvent);
 returnobj.watch("onkeyup",window.watchEvent);
 returnobj.watch("onkeypress",window.watchEvent);

 return returnobj;
}
Document.prototype.all = IEAll;
Document.prototype.all.item = IEAll;
//Document.prototype.body = window.document.all("body"); //hopefully make document.body work "always".
Layer.prototype.all = IEAll; //oddly enough layers technically have a "layers" array that is equiv of referring to the layer's document.layers array.
/* Attempt at doing Event stuff, too. */
var eventCount = new Array();
with(window) {
	function beSureToCapture(eventID) {
		if(eventCount[eventID] == null || eventCount[eventID] == 0) {
			this.captureEvents(eventID); // function should already be set.
			eventCount[eventID]=1;
		} else {
			eventCount[eventID]++;
		}
	}
}
/* capture all mouse and key events at the window level, set the window.event, then let the regular event handler do the rest, hopefully */
function topleveleventcapture(e) {
 window.event = new IEEvent(e); 
// var ret = routeEvent(e); // pass it on to the real target, and correctly perpetuate any possible cancellation when the real target returns.
// event bubbling will probably never work totally because of some basic differences in opinion on when events should fire and such.
// currently we can bubble a layer up through all enclosing documents, layers and window
// we bubble a document straight to the window.
// we bubble any other item (e.g. link) to the window's document, then the window.
 var ret = true;
 var item = e.target;
 while(typeof(item)=="object" && window.event.cancelBubble !== true
     && item != window) {
  if(item.handleEvent(e) === false)
	ret = false;
  if(item.constructor == Layer) {
	item = item.parentLayer;
	if(window.event.cancelBubble !== true) // include layer's document in the bubble
		if(item.document.handleEvent(e) === false)
			ret = false;
  } else if(item.constructor == Document) {
	// gotta be sure we really get all the requested stuff when we wimp out.
	if(window.event.cancelBubble !== true) // if we've not run enough stuff already.
		if(routeEvent(e)===false)  // wimp out.  SHOULD get item's enclosing layer
			ret = false;
	item = window;
  } else {
	// gotta be sure we really get all the requested stuff when we wimp out.
	if(window.event.cancelBubble !== true) // if we've not run enough stuff already.
		if(routeEvent(e)===false) // wimp out.  SHOULD get item's enclosing document.
			ret = false;
	item = window;
  }
 }
 var toplevelevent = window["toplevelevent"+e.type.toUpperCase()];
 if(typeof(toplevelevent) == "function"
 && window.event.cancelBubble !== true) {
	 if(toplevelevent(e)===false) // only truly returning false will abort it.
		 return false;
	 else
	     return ret;
 }
}
function IEEvent(NSEvent) {
 this.altKey = (NSEvent.modifiers&Event.ALT_MASK)>0;
 this.button = (NSEvent.which==1?1:(NSEvent.which==2?4:(NSEvent.which==3?2:0)));
 this.clientX = NSEvent.pageX; //? NSEvent.screenX-window.screenX
 this.clientY = NSEvent.pageY; //? NSEvent.screenY-window.screenY
 this.ctrlKey = (NSEvent.modifiers&Event.CONTROL_MASK)>0;
 //this.dataTransfer = NSEvent.data;
 this.keyCode = NSEvent.which;
 this.offsetX = NSEvent.layerX;
 this.offsetY = NSEvent.layerY;
 this.screenX = NSEvent.screenX;
 this.screenY = NSEvent.screenY;
 this.shiftKey = (NSEvent.modifiers&Event.SHIFT_MASK)>0;
 this.srcElement = NSEvent.target;
 this.type = NSEvent.type;
 this.x = this.clientX; // diff values for earlier than IE5, though!
 this.y = this.clientY;
 this.cancelBubble = false;
 
/* IE window.event properties:
   altKey , altLeft , behaviorCookie , behaviorPart ,button , cancelBubble , clientX , clientY , contentOverflow , ctrlKey , ctrlLeft ,   dataFld , dataTransfer , fromElement , keyCode , nextPage , offsetX , offsetY , propertyName , qualifier , reason , recordset ,repeat , returnValue , saveType , screenX , screenY , shiftKey , shiftLeft , srcElement , srcFilter , srcUrn , toElement , type ,
   x , y
Sets or retrieves the x-coordinate, in pixels, of the mouse pointer's position relative to the parent element.
In browser versions earlier than Internet Explorer 5, the x property retrieves a coordinate relative to the client.

       If the mouse is outside the window when the event is called, this property returns -1. If an element is absolutely
       positioned and fires a mouse event, or is not the child of an absolutely positioned element, the x property returns a
       coordinate relative to the body element.
 */
/* DOM2 Event:
CAPTURING_PHASE                = 1;
AT_TARGET                      = 2;
BUBBLING_PHASE                 = 3;

type;target;currentTarget;eventPhase;bubbles;cancelable;timeStamp;
void stopPropagation();
void preventDefault();
*/
/* DOM2 mouseevent: (note: no keyevents in DOM2)
screenX;screenY;clientX;clientY;ctrlKey;shiftKey;altKey;metaKey;button;relatedTarget;
		click
If multiple clicks occur at the same screen location, the sequence repeats with the detail attribute
              incrementing with each repetition. This event is valid for most elements.
Context Info: screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, button, detail 
         mousedown 
Context Info: screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, button, detail 
         mouseup 
Context Info: screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, button, detail 
         mouseover 
Context Info: screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, relatedTarget
                   indicates the EventTarget the pointing device is exiting. 
         mousemove 
                   Cancelable: No 
Context Info: screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey 
         mouseout 
Context Info: screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, relatedTarget                   indicates the EventTarget the pointing device is entering. 
*/
/* DOM2 mutationevent: (sort-of onpropertychange in IE5... watched attrs in NS)
relatedNode;prevValue;newValue;attrName;
*/
}
window.onmousedown=topleveleventcapture;
window.watch("onmousedown",window.watchEvent);
window.onmouseup=topleveleventcapture;
window.watch("onmouseup",window.watchEvent);
window.onclick=topleveleventcapture;
window.watch("onclick",window.watchEvent);
window.ondblclick=topleveleventcapture;
window.watch("ondblclick",window.watchEvent);
window.onmousemove=topleveleventcapture;
window.watch("onmousemove",window.watchEvent);
window.onmouseover=topleveleventcapture;
window.watch("onmouseover",window.watchEvent);
window.onmouseout=topleveleventcapture;
window.watch("onmouseout",window.watchEvent);
window.onkeydown=topleveleventcapture;
window.watch("onkeydown",window.watchEvent);
window.onkeyup=topleveleventcapture;
window.watch("onkeyup",window.watchEvent);
window.onkeypress=topleveleventcapture;
window.watch("onkeypress",window.watchEvent);
window.onchange=topleveleventcapture;
window.watch("onchange",window.watchEvent);
window.onselect=topleveleventcapture;
window.watch("onselect",window.watchEvent);
window.onresize=topleveleventcapture;
window.watch("onresize",window.watchEvent);
window.onmove=topleveleventcapture;
window.watch("onmove",window.watchEvent);
window.onfocus=topleveleventcapture;
window.watch("onfocus",window.watchEvent);
window.onblur=topleveleventcapture;
window.watch("onblur",window.watchEvent);
// capturing turned on when events are programmatically assigned.
//window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN|Event.CLICK|Event.MOUSEMOVE|Event.DBLCLICK|Event.MOUSEOUT|Event.MOUSEOVER|Event.KEYDOWN|Event.KEYUP|Event.KEYPRESS);
// this, of course, won't work for inline events, so, in fact, we'll capture some
// less "demanding" and/or more common inline events.
//window.captureEvents(Event.CLICK|Event.DBLCLICK|Event.MOUSEOUT|Event.MOUSEOVER|Event.MOUSEDOWN|Event.MOUSEUP);
window.captureEvents(Event.FOCUS|Event.BLUR|Event.CHANGE|Event.SELECT|Event.RESIZE|Event.MOVE|Event.CLICK|Event.DBLCLICK|Event.MOUSEOUT|Event.MOUSEOVER|Event.MOUSEDOWN|Event.MOUSEUP);

// make sure the document is initialized (watch events, etc)
document.body = document.all("body");

/* @*//*@end @*/

