<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>src/cruft/dom.js</filename>
    </added>
    <added>
      <filename>src/cruft/element.js</filename>
    </added>
    <added>
      <filename>src/cruft/parser.js</filename>
    </added>
    <added>
      <filename>test/index - Copy.html</filename>
    </added>
    <added>
      <filename>test/test-results.txt</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,11 +1,11 @@
-
-ENV = dist/env.rhino.js
-TEST = test/test.js
-
-JAR = java -jar rhino/js.jar
-
-test-rhino:
-	@@${JAR} ${TEST}
-
-run-rhino:
-	echo &quot;load('dist/env.rhino.js');window.location='test/index.html';&quot; | ${JAR}
+
+ENV = dist/env.rhino.js
+TEST = test/test.js
+
+JAR = java -jar rhino/js.jar
+
+test-rhino:
+	@@${JAR} ${TEST}
+
+run-rhino:
+	echo &quot;load('dist/env.rhino.js');window.location='test/index.html';&quot; | ${JAR}</diff>
      <filename>Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,7155 +1,7162 @@
-/*
- * Pure JavaScript Browser Environment
- *   By John Resig &lt;http://ejohn.org/&gt;
- * Copyright 2008 John Resig, under the MIT License
- */
- 
-
-// The Window Object
-var __this__ = this;
-this.__defineGetter__('window', function(){
-  return __this__;
-});
-try{
-(function($w, $env){
-        /*
-*	window.js
-*   - this file will be wrapped in a closure providing the window object as $w
-*/
-// a logger or empty function available to all modules.
-var $log = $env.log,
-    $error = $env.error,
-    $debug = $env.debug;
-//The version of this application
-var $version = &quot;0.1&quot;;
-//This should be hooked to git or svn or whatever
-var $revision = &quot;0.0.0.0&quot;;
-
-//These descriptions of window properties are taken loosely David Flanagan's
-//'JavaScript - The Definitive Guide' (O'Reilly)
-
-/**&gt; $cookies - see cookie.js &lt;*/
-// read only boolean specifies whether the window has been closed
-var $closed = false;
-
-// a read/write string that specifies the default message that appears in the status line 
-var $defaultStatus = &quot;Done&quot;;
-
-// a read-only reference to the Document object belonging to this window
-/**&gt; $document - See document.js &lt;*/
-
-//IE only, refers to the most recent event object - this maybe be removed after review
-var $event = null;
-
-//A read-only array of window objects
-var $frames = [];
-
-// a read-only reference to the History object
-/**&gt;  $history - see location.js &lt;**/
-
-// read-only properties that specify the height and width, in pixels
-var $innerHeight = 600, $innerWidth = 800;
-
-// a read-only reference to the Location object.  the location object does expose read/write properties
-/**&gt; $location - see location.js &lt;**/
-
-// a read only property specifying the name of the window.  Can be set when using open()
-// and may be used when specifying the target attribute of links
-var $name = 'Resig Env Browser';
-
-// a read-only reference to the Navigator object
-/**&gt; $navigator - see navigator.js &lt;**/
-
-// a read/write reference to the Window object that contained the script that called open() to 
-//open this browser window.  This property is valid only for top-level window objects.
-var $opener;
-
-// Read-only properties that specify the total height and width, in pixels, of the browser window.
-// These dimensions include the height and width of the menu bar, toolbars, scrollbars, window
-// borders and so on.  These properties are not supported by IE and IE offers no alternative 
-// properties;
-var $outerHeight = $innerHeight, $outerWidth = $innerWidth;
-
-// Read-only properties that specify the number of pixels that the current document has been scrolled
-//to the right and down.  These are not supported by IE.
-var $pageXOffset = 0, $pageYOffest = 0;
-
-//A read-only reference to the Window object that contains this window or frame.  If the window is
-// a top-level window, parent refers to the window itself.  If this window is a frame, this property
-// refers to the window or frame that conatins it.
-var $parent;
-
-// a read-only refernce to the Screen object that specifies information about the screen: 
-// the number of available pixels and the number of available colors.
-/**&gt; $screen - see screen.js &lt;**/
-
-// read only properties that specify the coordinates of the upper-left corner of the screen.
-var $screenX = 0, $screenY = 0;
-var $screenLeft = $screenX, $screenTop = $screenY;
-
-// a read-only refernce to this window itself.
-var $self;
-
-// a read/write string that specifies the current contents of the status line.
-var $status = '';
-
-// a read-only reference to the top-level window that contains this window.  If this
-// window is a top-level window it is simply a refernce to itself.  If this window 
-// is a frame, the top property refers to the top-level window that contains the frame.
-var $top;
-
-// the window property is identical to the self property.
-var $window = $w;
-
-$log(&quot;Initializing Window.&quot;);
-__extend__($w,{
-  get closed(){return $closed;},
-  get defaultStatus(){return $defaultStatus;},
-  set defaultStatus(_defaultStatus){$defaultStatus = _defaultStatus;},
-  //get document(){return $document;}, - see document.js
-  get event(){return $event;},
-  get frames(){return $frames;},
-  //get history(){return $history;}, - see location.js
-  get innerHeight(){return $innerHeight;},
-  get innerWidth(){return $innerWidth;},
-  get clientHeight(){return $innerHeight;},
-  get clientWidth(){return $innerWidth;},
-  //get location(){return $location;}, see location.js
-  get name(){return $name;},
-  //get navigator(){return $navigator;}, see navigator.js
-  get opener(){return $opener;},
-  get outerHeight(){return $outerHeight;},
-  get outerWidth(){return $outerWidth;},
-  get pageXOffest(){return $pageXOffset;},
-  get pageYOffset(){return $pageYOffset;},
-  get parent(){return $parent;},
-  //get screen(){return $screen;}, see screen.js
-  get screenLeft(){return $screenLeft;},
-  get screenTop(){return $screenTop;},
-  get screenX(){return $screenX;},
-  get screenY(){return $screenY;},
-  get self(){return $self;},
-  get status(){return $status;},
-  set status(_status){$status = _status;},
-  get top(){return $top;},
-  get window(){return $window;}
-});
-
-$w.open = function(url, name, features, replace){
-  //TODO
-};
-
-$w.close = function(){
-  //TODO
-};     
-  
-/* Time related functions - see timer.js
-*   - clearTimeout
-*   - clearInterval
-*   - setTimeout
-*   - setInterval
-*/
-
-/*
-* Events related functions - see event.js
-*   - addEventListener
-*   - attachEvent
-*   - detachEvent
-*   - removeEventListener
-*   
-* These functions are identical to the Element equivalents.
-*/
-
-/*
-* UIEvents related functions - see uievent.js
-*   - blur
-*   - focus
-*
-* These functions are identical to the Element equivalents.
-*/
-
-/* Dialog related functions - see dialog.js
-*   - alert
-*   - confirm
-*   - prompt
-*/
-
-/* Screen related functions - see screen.js
-*   - moveBy
-*   - moveTo
-*   - print
-*   - resizeBy
-*   - resizeTo
-*   - scrollBy
-*   - scrollTo
-*/
-
-/* CSS related functions - see css.js
-*   - getComputedStyle
-*/
-
-/*
-* Shared utility methods
-*/
-// Helper method for extending one object with another.  
-function __extend__(a,b) {
-	for ( var i in b ) {
-		var g = b.__lookupGetter__(i), s = b.__lookupSetter__(i);
-		if ( g || s ) {
-			if ( g ) a.__defineGetter__(i, g);
-			if ( s ) a.__defineSetter__(i, s);
-		} else
-			a[i] = b[i];
-	} return a;
-};
-	
-
-// from ariel flesler http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html
-// this might be a good utility function to provide in the env.core
-// as in might be useful to the parser and other areas as well
-function trim( str ){
-    var start = -1,
-    end = str.length;
-    /*jsl:ignore*/
-    while( str.charCodeAt(--end) &lt; 33 );
-    while( str.charCodeAt(++start) &lt; 33 );
-    /*jsl:end*/
-    return str.slice( start, end + 1 );
-};
-
-//from jQuery
-function __setArray__( target, array ) {
-	// Resetting the length to 0, then using the native Array push
-	// is a super-fast way to populate an object with array-like properties
-	target.length = 0;
-	Array.prototype.push.apply( target, array );
-};
-$log(&quot;Defining NodeList&quot;);
-/*
-* NodeList - DOM Level 2
-*/
-$w.__defineGetter__('NodeList', function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-/**
- * @class  DOMNodeList - provides the abstraction of an ordered collection of nodes
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- *
- * @param  ownerDocument : DOMDocument - the ownerDocument
- * @param  parentNode    : DOMNode - the node that the DOMNodeList is attached to (or null)
- */
-var DOMNodeList = function(ownerDocument, parentNode) {
-    //$log(&quot;\t\tcreating dom nodelist&quot;);
-    var nodes = new Array();
-    
-    this.length = 0;
-    this.parentNode = parentNode;
-    this.ownerDocument = ownerDocument;
-    
-    this._readonly = false;
-    
-    __setArray__(this, nodes);
-    //$log(&quot;\t\tfinished creating dom nodelist&quot;);
-};
-__extend__(DOMNodeList.prototype, {
-    item : function(index) {
-        var ret = null;
-        //$log(&quot;NodeList item(&quot;+index+&quot;) = &quot; + this[index]);
-        if ((index &gt;= 0) &amp;&amp; (index &lt; this.length)) { // bounds check
-            ret = this[index];                    // return selected Node
-        }
-        
-        return ret;                                    // if the index is out of bounds, default value null is returned
-    },
-    get xml() {
-        var ret = &quot;&quot;;
-        
-        // create string containing the concatenation of the string values of each child
-        for (var i=0; i &lt; this.length; i++) {
-            if(this[i].nodeType == DOMNode.TEXT_NODE &amp;&amp; i&gt;0 &amp;&amp; this[i-1].nodeType == DOMNode.TEXT_NODE){
-                //add a single space between adjacent text nodes
-                ret += &quot; &quot;+this[i].xml;
-            }else{
-                ret += this[i].xml;
-            }
-        }
-        
-        return ret;
-    },
-    toString: function(){
-      return &quot;[ &quot;+(this.length &gt; 0?Array.prototype.join.apply(this, [&quot;, &quot;]):&quot;Empty NodeList&quot;)+&quot; ]&quot;;
-    }
-});
-
-
-/**
- * @method DOMNodeList._findItemIndex - find the item index of the node with the specified internal id
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  id : int - unique internal id
- * @return : int
- */
-var __findItemIndex__ = function (nodelist, id) {
-  var ret = -1;
-
-  // test that id is valid
-  if (id &gt; -1) {
-    for (var i=0; i&lt;nodelist.length; i++) {
-      // compare id to each node's _id
-      if (nodelist[i]._id == id) {            // found it!
-        ret = i;
-        break;
-      }
-    }
-  }
-
-  return ret;                                    // if node is not found, default value -1 is returned
-};
-
-/**
- * @method DOMNodeList._insertBefore - insert the specified Node into the NodeList before the specified index
- *   Used by DOMNode.insertBefore(). Note: DOMNode.insertBefore() is responsible for Node Pointer surgery
- *   DOMNodeList._insertBefore() simply modifies the internal data structure (Array).
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  newChild      : DOMNode - the Node to be inserted
- * @param  refChildIndex : int     - the array index to insert the Node before
- */
-var __insertBefore__ = function(nodelist, newChild, refChildIndex) {
-    if ((refChildIndex &gt;= 0) &amp;&amp; (refChildIndex &lt; nodelist.length)) { // bounds check
-        
-        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
-            // append the children of DocumentFragment
-            Array.prototype.splice.apply(nodelist,[refChildIndex, 0].concat(newChild.childNodes));
-        }
-        else {
-            // append the newChild
-            Array.prototype.splice.apply(nodelist,[refChildIndex, 0, newChild]);
-        }
-    }
-    //$log(&quot;__insertBefore__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
-};
-
-/**
- * @method DOMNodeList._replaceChild - replace the specified Node in the NodeList at the specified index
- *   Used by DOMNode.replaceChild(). Note: DOMNode.replaceChild() is responsible for Node Pointer surgery
- *   DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  newChild      : DOMNode - the Node to be inserted
- * @param  refChildIndex : int     - the array index to hold the Node
- */
-var __replaceChild__ = function(nodelist, newChild, refChildIndex) {
-    var ret = null;
-    
-    if ((refChildIndex &gt;= 0) &amp;&amp; (refChildIndex &lt; nodelist.length)) { // bounds check
-        ret = nodelist[refChildIndex];            // preserve old child for return
-    
-        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
-            // get array containing children prior to refChild
-            Array.prototype.splice.apply(nodelist,[refChildIndex, 1].concat(newChild.childNodes));
-        }
-        else {
-            // simply replace node in array (links between Nodes are made at higher level)
-            nodelist[refChildIndex] = newChild;
-        }
-    }
-    
-    //$log(&quot;__replaceChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
-    return ret;                                   // return replaced node
-};
-
-/**
- * @method DOMNodeList._removeChild - remove the specified Node in the NodeList at the specified index
- *   Used by DOMNode.removeChild(). Note: DOMNode.removeChild() is responsible for Node Pointer surgery
- *   DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  refChildIndex : int - the array index holding the Node to be removed
- */
-var __removeChild__ = function(nodelist, refChildIndex) {
-    var ret = null;
-    
-    if (refChildIndex &gt; -1) {                              // found it!
-        ret = nodelist[refChildIndex];                    // return removed node
-        
-        // rebuild array without removed child
-        Array.prototype.splice.apply(nodelist,[refChildIndex, 1]);
-    }
-    
-    //$log(&quot;__removeChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
-    return ret;                                   // return removed node
-};
-
-/**
- * @method DOMNodeList._appendChild - append the specified Node to the NodeList
- *   Used by DOMNode.appendChild(). Note: DOMNode.appendChild() is responsible for Node Pointer surgery
- *   DOMNodeList._appendChild() simply modifies the internal data structure (Array).
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  newChild      : DOMNode - the Node to be inserted
- */
-var __appendChild__ = function(nodelist, newChild) {
-    if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
-        // append the children of DocumentFragment
-        Array.prototype.push.apply(nodelist, newChild.childNodes);
-    } else {
-        // simply add node to array (links between Nodes are made at higher level)
-        Array.prototype.push.apply(nodelist, [newChild]);
-    }
-    
-    //$log(&quot;__appendChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
-};
-
-/**
- * @method DOMNodeList._cloneNodes - Returns a NodeList containing clones of the Nodes in this NodeList
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  deep : boolean - If true, recursively clone the subtree under each of the nodes;
- *   if false, clone only the nodes themselves (and their attributes, if it is an Element).
- * @param  parentNode : DOMNode - the new parent of the cloned NodeList
- * @return : DOMNodeList - NodeList containing clones of the Nodes in this NodeList
- */
-var __cloneNodes__ = function(nodelist, deep, parentNode) {
-    var cloneNodeList = new DOMNodeList(nodelist.ownerDocument, parentNode);
-    
-    // create list containing clones of each child
-    for (var i=0; i &lt; nodelist.length; i++) {
-        __appendChild__(cloneNodeList, nodelist[i].cloneNode(deep));
-    }
-    
-    return cloneNodeList;
-};
-
-
-/**
- * @class  DOMNamedNodeMap - used to represent collections of nodes that can be accessed by name
- *  typically a set of Element attributes
- *
- * @extends DOMNodeList - note W3C spec says that this is not the case,
- *   but we need an item() method identicle to DOMNodeList's, so why not?
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - the ownerDocument
- * @param  parentNode    : DOMNode - the node that the DOMNamedNodeMap is attached to (or null)
- */
-var DOMNamedNodeMap = function(ownerDocument, parentNode) {
-    //$log(&quot;\t\tcreating dom namednodemap&quot;);
-    this.DOMNodeList = DOMNodeList;
-    this.DOMNodeList(ownerDocument, parentNode);
-    __setArray__(this, []);
-};
-DOMNamedNodeMap.prototype = new DOMNodeList;
-__extend__(DOMNamedNodeMap.prototype, {
-    getNamedItem : function(name) {
-        var ret = null;
-        
-        // test that Named Node exists
-        var itemIndex = __findNamedItemIndex__(this, name);
-        
-        if (itemIndex &gt; -1) {                          // found it!
-            ret = this[itemIndex];                // return NamedNode
-        }
-        
-        return ret;                                    // if node is not found, default value null is returned
-    },
-    setNamedItem : function(arg) {
-      // test for exceptions
-      if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if arg was not created by this Document
-            if (this.ownerDocument != arg.ownerDocument) {
-              throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-            }
-        
-            // throw Exception if DOMNamedNodeMap is readonly
-            if (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly)) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-        
-            // throw Exception if arg is already an attribute of another Element object
-            if (arg.ownerElement &amp;&amp; (arg.ownerElement != this.parentNode)) {
-              throw(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR));
-            }
-      }
-    
-      // get item index
-      var itemIndex = __findNamedItemIndex__(this, arg.name);
-      var ret = null;
-    
-      if (itemIndex &gt; -1) {                          // found it!
-            ret = this[itemIndex];                // use existing Attribute
-        
-            // throw Exception if DOMAttr is readonly
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ret._readonly) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            } else {
-              this[itemIndex] = arg;                // over-write existing NamedNode
-            }
-      } else {
-            // add new NamedNode
-            Array.prototype.push.apply(this, [arg]);
-      }
-    
-      arg.ownerElement = this.parentNode;            // update ownerElement
-    
-      return ret;                                    // return old node or null
-    },
-    removeNamedItem : function(name) {
-          var ret = null;
-          // test for exceptions
-          // throw Exception if DOMNamedNodeMap is readonly
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly))) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-          }
-        
-          // get item index
-          var itemIndex = __findNamedItemIndex__(this, name);
-        
-          // throw Exception if there is no node named name in this map
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-            throw(new DOMException(DOMException.NOT_FOUND_ERR));
-          }
-        
-          // get Node
-          var oldNode = this[itemIndex];
-        
-          // throw Exception if Node is readonly
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldNode._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-          }
-        
-          // return removed node
-          return __removeChild__(this, itemIndex);
-    },
-    getNamedItemNS : function(namespaceURI, localName) {
-          var ret = null;
-        
-          // test that Named Node exists
-          var itemIndex = __findNamedItemNSIndex__(this, namespaceURI, localName);
-        
-          if (itemIndex &gt; -1) {                          // found it!
-            ret = this[itemIndex];                // return NamedNode
-          }
-        
-          return ret;                                    // if node is not found, default value null is returned
-    },
-    setNamedItemNS : function(arg) {
-          // test for exceptions
-          if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if DOMNamedNodeMap is readonly
-            if (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly)) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-        
-            // throw Exception if arg was not created by this Document
-            if (this.ownerDocument != arg.ownerDocument) {
-              throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-            }
-        
-            // throw Exception if arg is already an attribute of another Element object
-            if (arg.ownerElement &amp;&amp; (arg.ownerElement != this.parentNode)) {
-              throw(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR));
-            }
-          }
-        
-          // get item index
-          var itemIndex = __findNamedItemNSIndex__(this, arg.namespaceURI, arg.localName);
-          var ret = null;
-        
-          if (itemIndex &gt; -1) {                          // found it!
-            ret = this[itemIndex];                // use existing Attribute
-            // throw Exception if DOMAttr is readonly
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ret._readonly) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            } else {
-              this[itemIndex] = arg;                // over-write existing NamedNode
-            }
-          }else {
-            // add new NamedNode
-            Array.prototype.push.apply(this, [arg]);
-          }
-          arg.ownerElement = this.parentNode;
-        
-        
-          return ret;                                    // return old node or null
-    },
-    removeNamedItemNS : function(namespaceURI, localName) {
-          var ret = null;
-        
-          // test for exceptions
-          // throw Exception if DOMNamedNodeMap is readonly
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly))) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-          }
-        
-          // get item index
-          var itemIndex = __findNamedItemNSIndex__(this, namespaceURI, localName);
-        
-          // throw Exception if there is no matching node in this map
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-            throw(new DOMException(DOMException.NOT_FOUND_ERR));
-          }
-        
-          // get Node
-          var oldNode = this[itemIndex];
-        
-          // throw Exception if Node is readonly
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldNode._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-          }
-        
-          return __removeChild__(this, itemIndex);             // return removed node
-    },
-    get xml() {
-          var ret = &quot;&quot;;
-        
-          // create string containing concatenation of all (but last) Attribute string values (separated by spaces)
-          for (var i=0; i &lt; this.length -1; i++) {
-            ret += this[i].xml +&quot; &quot;;
-          }
-        
-          // add last Attribute to string (without trailing space)
-          if (this.length &gt; 0) {
-            ret += this[this.length -1].xml;
-          }
-        
-          return ret;
-    }
-
-});
-
-/**
- * @method DOMNamedNodeMap._findNamedItemIndex - find the item index of the node with the specified name
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  name : string - the name of the required node
- * @param  isnsmap : if its a DOMNamespaceNodeMap
- * @return : int
- */
-var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) {
-  var ret = -1;
-
-  // loop through all nodes
-  for (var i=0; i&lt;namednodemap.length; i++) {
-    // compare name to each node's nodeName
-    if(isnsmap){
-        if (namednodemap[i].localName == localName) {         // found it!
-          ret = i;
-          break;
-        }
-    }else{
-        if (namednodemap[i].name == name) {         // found it!
-          ret = i;
-          break;
-        }
-    }
-  }
-
-  return ret;                                    // if node is not found, default value -1 is returned
-};
-
-/**
- * @method DOMNamedNodeMap._findNamedItemNSIndex - find the item index of the node with the specified namespaceURI and localName
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  namespaceURI : string - the namespace URI of the required node
- * @param  localName    : string - the local name of the required node
- * @return : int
- */
-var __findNamedItemNSIndex__ = function(namednodemap, namespaceURI, localName) {
-  var ret = -1;
-
-  // test that localName is not null
-  if (localName) {
-    // loop through all nodes
-    for (var i=0; i&lt;namednodemap.length; i++) {
-      // compare name to each node's namespaceURI and localName
-      if ((namednodemap[i].namespaceURI == namespaceURI) &amp;&amp; (namednodemap[i].localName == localName)) {
-        ret = i;                                 // found it!
-        break;
-      }
-    }
-  }
-
-  return ret;                                    // if node is not found, default value -1 is returned
-};
-
-/**
- * @method DOMNamedNodeMap._hasAttribute - Returns true if specified node exists
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  name : string - the name of the required node
- * @return : boolean
- */
-var __hasAttribute__ = function(namednodemap, name) {
-  var ret = false;
-
-  // test that Named Node exists
-  var itemIndex = __findNamedItemIndex__(namednodemap, name);
-
-  if (itemIndex &gt; -1) {                          // found it!
-    ret = true;                                  // return true
-  }
-
-  return ret;                                    // if node is not found, default value false is returned
-}
-
-/**
- * @method DOMNamedNodeMap._hasAttributeNS - Returns true if specified node exists
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  namespaceURI : string - the namespace URI of the required node
- * @param  localName    : string - the local name of the required node
- * @return : boolean
- */
-var __hasAttributeNS__ = function(namednodemap, namespaceURI, localName) {
-  var ret = false;
-
-  // test that Named Node exists
-  var itemIndex = __findNamedItemNSIndex__(namednodemap, namespaceURI, localName);
-
-  if (itemIndex &gt; -1) {                          // found it!
-    ret = true;                                  // return true
-  }
-
-  return ret;                                    // if node is not found, default value false is returned
-}
-
-/**
- * @method DOMNamedNodeMap._cloneNodes - Returns a NamedNodeMap containing clones of the Nodes in this NamedNodeMap
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  parentNode : DOMNode - the new parent of the cloned NodeList
- * @param  isnsmap : bool - is this a DOMNamespaceNodeMap
- * @return : DOMNamedNodeMap - NamedNodeMap containing clones of the Nodes in this DOMNamedNodeMap
- */
-var __cloneNamedNodes__ = function(namednodemap, parentNode, isnsmap) {
-  var cloneNamedNodeMap = isnsmap?
-    new DOMNamespaceNodeMap(namednodemap.ownerDocument, parentNode):
-    new DOMNamedNodeMap(namednodemap.ownerDocument, parentNode);
-
-  // create list containing clones of all children
-  for (var i=0; i &lt; namednodemap.length; i++) {
-      $log(&quot;cloning node in named node map :&quot; + namednodemap[i]);
-    __appendChild__(cloneNamedNodeMap, namednodemap[i].cloneNode(false));
-  }
-
-  return cloneNamedNodeMap;
-};
-
-
-/**
- * @class  DOMNamespaceNodeMap - used to represent collections of namespace nodes that can be accessed by name
- *  typically a set of Element attributes
- *
- * @extends DOMNamedNodeMap
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- *
- * @param  ownerDocument : DOMDocument - the ownerDocument
- * @param  parentNode    : DOMNode - the node that the DOMNamespaceNodeMap is attached to (or null)
- */
-var DOMNamespaceNodeMap = function(ownerDocument, parentNode) {
-    //$log(&quot;\t\t\tcreating dom namespacednodemap&quot;);
-    this.DOMNamedNodeMap = DOMNamedNodeMap;
-    this.DOMNamedNodeMap(ownerDocument, parentNode);
-    __setArray__(this, []);
-};
-DOMNamespaceNodeMap.prototype = new DOMNamedNodeMap;
-__extend__(DOMNamespaceNodeMap.prototype, {
-    get xml() {
-          var ret = &quot;&quot;;
-        
-          // identify namespaces declared local to this Element (ie, not inherited)
-          for (var ind = 0; ind &lt; this.length; ind++) {
-            // if namespace declaration does not exist in the containing node's, parentNode's namespaces
-            var ns = null;
-            try {
-                var ns = this.parentNode.parentNode._namespaces.getNamedItem(this[ind].localName);
-            }
-            catch (e) {
-                //breaking to prevent default namespace being inserted into return value
-                break;
-            }
-            if (!(ns &amp;&amp; (&quot;&quot;+ ns.nodeValue == &quot;&quot;+ this[ind].nodeValue))) {
-              // display the namespace declaration
-              ret += this[ind].xml +&quot; &quot;;
-            }
-          }
-        
-          return ret;
-    }
-});
-$log(&quot;Defining Node&quot;);
-/*
-* Node - DOM Level 2
-*/	
-$w.__defineGetter__('Node', function(){
-  return __extend__(function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-      } , {
-  		ELEMENT_NODE    :1,
-  		ATTRIBUTE_NODE  :2,
-  		TEXT_NODE       :3,
-  		CDATA_SECTION_NODE: 4,
-  		PROCESSING_INSTRUCTION_NODE: 7,
-  		COMMENT_NODE: 8,
-  		DOCUMENT_NODE: 9,
-  		DOCUMENT_TYPE_NODE: 10,
-  		DOCUMENT_FRAGMENT_NODE: 11
-	});
-});
-
-/**
- * @class  DOMNode - The Node interface is the primary datatype for the entire Document Object Model.
- *   It represents a single node in the document tree.
- * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMNode = function(ownerDocument) {
-  //$log(&quot;\tcreating dom node&quot;);
-  if (ownerDocument) {
-    this._id = ownerDocument._genId();           // generate unique internal id
-  }
-
-  this.namespaceURI = &quot;&quot;;                        // The namespace URI of this node (Level 2)
-  this.prefix       = &quot;&quot;;                        // The namespace prefix of this node (Level 2)
-  this.localName    = &quot;&quot;;                        // The localName of this node (Level 2)
-
-  this.nodeName = &quot;&quot;;                            // The name of this node
-  this.nodeValue = &quot;&quot;;                           // The value of this node
-  this.nodeType = 0;                             // A code representing the type of the underlying object
-
-  // The parent of this node. All nodes, except Document, DocumentFragment, and Attr may have a parent.
-  // However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null
-  this.parentNode      = null;
-
-  // A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.
-  // The content of the returned NodeList is &quot;live&quot; in the sense that, for instance, changes to the children of the node object
-  // that it was created from are immediately reflected in the nodes returned by the NodeList accessors;
-  // it is not a static snapshot of the content of the node. This is true for every NodeList, including the ones returned by the getElementsByTagName method.
-  this.childNodes      = new DOMNodeList(ownerDocument, this);
-
-  this.firstChild      = null;                   // The first child of this node. If there is no such node, this is null
-  this.lastChild       = null;                   // The last child of this node. If there is no such node, this is null.
-  this.previousSibling = null;                   // The node immediately preceding this node. If there is no such node, this is null.
-  this.nextSibling     = null;                   // The node immediately following this node. If there is no such node, this is null.
-
-  this.attributes = new DOMNamedNodeMap(ownerDocument, this);   // A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
-  this.ownerDocument   = ownerDocument;          // The Document object associated with this node
-  this._namespaces = new DOMNamespaceNodeMap(ownerDocument, this);  // The namespaces in scope for this node
-
-  this._readonly = false;
-  //$log(&quot;\tfinished creating dom node&quot;);
-};
-
-// nodeType constants
-DOMNode.ELEMENT_NODE                = 1;
-DOMNode.ATTRIBUTE_NODE              = 2;
-DOMNode.TEXT_NODE                   = 3;
-DOMNode.CDATA_SECTION_NODE          = 4;
-DOMNode.ENTITY_REFERENCE_NODE       = 5;
-DOMNode.ENTITY_NODE                 = 6;
-DOMNode.PROCESSING_INSTRUCTION_NODE = 7;
-DOMNode.COMMENT_NODE                = 8;
-DOMNode.DOCUMENT_NODE               = 9;
-DOMNode.DOCUMENT_TYPE_NODE          = 10;
-DOMNode.DOCUMENT_FRAGMENT_NODE      = 11;
-DOMNode.NOTATION_NODE               = 12;
-DOMNode.NAMESPACE_NODE              = 13;
-
-__extend__(DOMNode.prototype, {
-    hasAttributes : function() {
-        if (this.attributes.length == 0) {
-            return false;
-        }else{
-            return true;
-        }
-    },
-    insertBefore : function(newChild, refChild) {
-        var prevNode;
-        
-        // test for exceptions
-        if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if DOMNode is readonly
-            if (this._readonly) {
-                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-            
-            // throw Exception if newChild was not created by this Document
-            if (this.ownerDocument != newChild.ownerDocument) {
-                throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-            }
-            
-            // throw Exception if the node is an ancestor
-            if (__isAncestor__(this, newChild)) {
-                throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
-            }
-        }
-        
-        if (refChild) {                                // if refChild is specified, insert before it
-            // find index of refChild
-            var itemIndex = __findItemIndex__(this.childNodes, refChild._id);
-            
-            // throw Exception if there is no child node with this id
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-              throw(new DOMException(DOMException.NOT_FOUND_ERR));
-            }
-            
-            // if the newChild is already in the tree,
-            var newChildParent = newChild.parentNode;
-            if (newChildParent) {
-              // remove it
-              newChildParent.removeChild(newChild);
-            }
-            
-            // insert newChild into childNodes
-            __insertBefore__(this.childNodes, newChild, __findItemIndex__(this.childNodes, refChild._id));
-            
-            // do node pointer surgery
-            prevNode = refChild.previousSibling;
-            
-            // handle DocumentFragment
-            if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
-              if (newChild.childNodes.length &gt; 0) {
-                // set the parentNode of DocumentFragment's children
-                for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
-                  newChild.childNodes[ind].parentNode = this;
-                }
-            
-                // link refChild to last child of DocumentFragment
-                refChild.previousSibling = newChild.childNodes[newChild.childNodes.length-1];
-              }
-            }else {
-                newChild.parentNode = this;                // set the parentNode of the newChild
-                refChild.previousSibling = newChild;       // link refChild to newChild
-            }
-        }else {                                         // otherwise, append to end
-            prevNode = this.lastChild;
-            this.appendChild(newChild);
-        }
-        
-        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
-            // do node pointer surgery for DocumentFragment
-            if (newChild.childNodes.length &gt; 0) {
-                if (prevNode) {  
-                    prevNode.nextSibling = newChild.childNodes[0];
-                }else {                                         // this is the first child in the list
-                    this.firstChild = newChild.childNodes[0];
-                }
-            
-                newChild.childNodes[0].previousSibling = prevNode;
-                newChild.childNodes[newChild.childNodes.length-1].nextSibling = refChild;
-            }
-        }else {
-            // do node pointer surgery for newChild
-            if (prevNode) {
-              prevNode.nextSibling = newChild;
-            }else {                                         // this is the first child in the list
-              this.firstChild = newChild;
-            }
-            
-            newChild.previousSibling = prevNode;
-            newChild.nextSibling     = refChild;
-        }
-        
-        return newChild;
-    },
-    replaceChild : function(newChild, oldChild) {
-        var ret = null;
-        
-        // test for exceptions
-        if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if DOMNode is readonly
-            if (this._readonly) {
-                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-        
-            // throw Exception if newChild was not created by this Document
-            if (this.ownerDocument != newChild.ownerDocument) {
-                throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-            }
-        
-            // throw Exception if the node is an ancestor
-            if (__isAncestor__(this, newChild)) {
-                throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
-            }
-        }
-        
-        // get index of oldChild
-        var index = __findItemIndex__(this.childNodes, oldChild._id);
-        
-        // throw Exception if there is no child node with this id
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (index &lt; 0)) {
-            throw(new DOMException(DOMException.NOT_FOUND_ERR));
-        }
-        
-        // if the newChild is already in the tree,
-        var newChildParent = newChild.parentNode;
-        if (newChildParent) {
-            // remove it
-            newChildParent.removeChild(newChild);
-        }
-        
-        // add newChild to childNodes
-        ret = __replaceChild__(this.childNodes,newChild, index);
-        
-        
-        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
-            // do node pointer surgery for Document Fragment
-            if (newChild.childNodes.length &gt; 0) {
-                for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
-                    newChild.childNodes[ind].parentNode = this;
-                }
-                
-                if (oldChild.previousSibling) {
-                    oldChild.previousSibling.nextSibling = newChild.childNodes[0];
-                } else {
-                    this.firstChild = newChild.childNodes[0];
-                }
-                
-                if (oldChild.nextSibling) {
-                    oldChild.nextSibling.previousSibling = newChild;
-                } else {
-                    this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
-                }
-                
-                newChild.childNodes[0].previousSibling = oldChild.previousSibling;
-                newChild.childNodes[newChild.childNodes.length-1].nextSibling = oldChild.nextSibling;
-            }
-        } else {
-            // do node pointer surgery for newChild
-            newChild.parentNode = this;
-            
-            if (oldChild.previousSibling) {
-                oldChild.previousSibling.nextSibling = newChild;
-            }else{
-                this.firstChild = newChild;
-            }
-            if (oldChild.nextSibling) {
-                oldChild.nextSibling.previousSibling = newChild;
-            }else{
-                this.lastChild = newChild;
-            }
-            newChild.previousSibling = oldChild.previousSibling;
-            newChild.nextSibling = oldChild.nextSibling;
-        }
-        //this.removeChild(oldChild);
-        return ret;
-    },
-    removeChild : function(oldChild) {
-        // throw Exception if DOMNamedNodeMap is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || oldChild._readonly)) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        
-        // get index of oldChild
-        var itemIndex = __findItemIndex__(this.childNodes, oldChild._id);
-        
-        // throw Exception if there is no child node with this id
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-            throw(new DOMException(DOMException.NOT_FOUND_ERR));
-        }
-        
-        // remove oldChild from childNodes
-        __removeChild__(this.childNodes, itemIndex);
-        
-        // do node pointer surgery
-        oldChild.parentNode = null;
-        
-        if (oldChild.previousSibling) {
-            oldChild.previousSibling.nextSibling = oldChild.nextSibling;
-        }else {
-            this.firstChild = oldChild.nextSibling;
-        }
-        if (oldChild.nextSibling) {
-            oldChild.nextSibling.previousSibling = oldChild.previousSibling;
-        }else {
-            this.lastChild = oldChild.previousSibling;
-        }
-        
-        oldChild.previousSibling = null;
-        oldChild.nextSibling = null;
-        
-        /*if(oldChild.ownerDocument == document){
-            $log(&quot;removeChild :  all -&gt; &quot; + document.all.length);
-        }*/
-        return oldChild;
-    },
-    appendChild : function(newChild) {
-      // test for exceptions
-      if (this.ownerDocument.implementation.errorChecking) {
-        // throw Exception if Node is readonly
-        if (this._readonly) {
-          throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-    
-        // throw Exception if arg was not created by this Document
-        if (this.ownerDocument != newChild.ownerDocument) {
-          throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-        }
-    
-        // throw Exception if the node is an ancestor
-        if (__isAncestor__(this, newChild)) {
-          throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
-        }
-      }
-    
-      // if the newChild is already in the tree,
-      var newChildParent = newChild.parentNode;
-      if (newChildParent) {
-        // remove it
-        newChildParent.removeChild(newChild);
-      }
-    
-      // add newChild to childNodes
-      __appendChild__(this.childNodes, newChild);
-    
-      if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
-        // do node pointer surgery for DocumentFragment
-        if (newChild.childNodes.length &gt; 0) {
-          for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
-            newChild.childNodes[ind].parentNode = this;
-          }
-    
-          if (this.lastChild) {
-            this.lastChild.nextSibling = newChild.childNodes[0];
-            newChild.childNodes[0].previousSibling = this.lastChild;
-            this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
-          }
-          else {
-            this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
-            this.firstChild = newChild.childNodes[0];
-          }
-        }
-      }
-      else {
-        // do node pointer surgery for newChild
-        newChild.parentNode = this;
-        if (this.lastChild) {
-          this.lastChild.nextSibling = newChild;
-          newChild.previousSibling = this.lastChild;
-          this.lastChild = newChild;
-        }
-        else {
-          this.lastChild = newChild;
-          this.firstChild = newChild;
-        }
-      }
-    
-      return newChild;
-    },
-    hasChildNodes : function() {
-        return (this.childNodes.length &gt; 0);
-    },
-    cloneNode: function(deep) {
-        // use importNode to clone this Node
-        //do not throw any exceptions
-        //$log(&quot;cloning node&quot;);
-        try {
-            return this.ownerDocument.importNode(this, deep);
-        } catch (e) {
-            //there shouldn't be any exceptions, but if there are, return null
-            return null;
-        }
-    },
-    normalize : function() {
-        var inode;
-        var nodesToRemove = new DOMNodeList();
-        
-        if (this.nodeType == DOMNode.ELEMENT_NODE || this.nodeType == DOMNode.DOCUMENT_NODE) {
-            var adjacentTextNode = null;
-        
-            // loop through all childNodes
-            for(var i = 0; i &lt; this.childNodes.length; i++) {
-                inode = this.childNodes.item(i);
-            
-                if (inode.nodeType == DOMNode.TEXT_NODE) { // this node is a text node
-                    if (inode.length &lt; 1) {                  // this text node is empty
-                        __appendChild__(nodesToRemove, inode);      // add this node to the list of nodes to be remove
-                    }else {
-                        if (adjacentTextNode) {                // if previous node was also text
-                            adjacentTextNode.appendData(inode.data);     // merge the data in adjacent text nodes
-                            __appendChild__(nodesToRemove, inode);    // add this node to the list of nodes to be removed
-                        }else {
-                            adjacentTextNode = inode;              // remember this node for next cycle
-                        }
-                    }
-                } else {
-                    adjacentTextNode = null;                 // (soon to be) previous node is not a text node
-                    inode.normalize();                       // normalise non Text childNodes
-                }
-            }
-                
-            // remove redundant Text Nodes
-            for(var i = 0; i &lt; nodesToRemove.length; i++) {
-                inode = nodesToRemove.item(i);
-                inode.parentNode.removeChild(inode);
-            }
-        }
-    },
-    isSupported : function(feature, version) {
-        // use Implementation.hasFeature to determin if this feature is supported
-        return this.ownerDocument.implementation.hasFeature(feature, version);
-    },
-    getElementsByTagName : function(tagname) {
-        // delegate to _getElementsByTagNameRecursive
-        //$log(&quot;getElementsByTagName(&quot;+tagname+&quot;)&quot;);
-        return __getElementsByTagNameRecursive__(this, tagname, new DOMNodeList(this.ownerDocument));
-    },
-    getElementsByTagNameNS : function(namespaceURI, localName) {
-        // delegate to _getElementsByTagNameNSRecursive
-        return __getElementsByTagNameNSRecursive__(this, namespaceURI, localName, new DOMNodeList(this.ownerDocument));
-    },
-    importNode : function(importedNode, deep) {
-        var importNode;
-        //$log(&quot;importing node &quot; + importedNode + &quot;(?deep = &quot;+deep+&quot;)&quot;);
-        //there is no need to perform namespace checks since everything has already gone through them
-        //in order to have gotten into the DOM in the first place. The following line
-        //turns namespace checking off in ._isValidNamespace
-        this.ownerDocument._performingImportNodeOperation = true;
-        
-        try {
-            if (importedNode.nodeType == DOMNode.ELEMENT_NODE) {
-                if (!this.ownerDocument.implementation.namespaceAware) {
-                    // create a local Element (with the name of the importedNode)
-                    importNode = this.ownerDocument.createElement(importedNode.tagName);
-                
-                    // create attributes matching those of the importedNode
-                    for(var i = 0; i &lt; importedNode.attributes.length; i++) {
-                        importNode.setAttribute(importedNode.attributes.item(i).name, importedNode.attributes.item(i).value);
-                    }
-                }else {
-                    // create a local Element (with the name &amp; namespaceURI of the importedNode)
-                    importNode = this.ownerDocument.createElementNS(importedNode.namespaceURI, importedNode.nodeName);
-                
-                    // create attributes matching those of the importedNode
-                    for(var i = 0; i &lt; importedNode.attributes.length; i++) {
-                        importNode.setAttributeNS(importedNode.attributes.item(i).namespaceURI, 
-                            importedNode.attributes.item(i).name, importedNode.attributes.item(i).value);
-                    }
-                
-                    // create namespace definitions matching those of the importedNode
-                    for(var i = 0; i &lt; importedNode._namespaces.length; i++) {
-                        importNode._namespaces[i] = this.ownerDocument.createNamespace(importedNode._namespaces.item(i).localName);
-                        importNode._namespaces[i].value = importedNode._namespaces.item(i).value;
-                    }
-                }
-            } else if (importedNode.nodeType == DOMNode.ATTRIBUTE_NODE) {
-                if (!this.ownerDocument.implementation.namespaceAware) {
-                    // create a local Attribute (with the name of the importedAttribute)
-                    importNode = this.ownerDocument.createAttribute(importedNode.name);
-                } else {
-                    // create a local Attribute (with the name &amp; namespaceURI of the importedAttribute)
-                    importNode = this.ownerDocument.createAttributeNS(importedNode.namespaceURI, importedNode.nodeName);
-                
-                    // create namespace definitions matching those of the importedAttribute
-                    for(var i = 0; i &lt; importedNode._namespaces.length; i++) {
-                        importNode._namespaces[i] = this.ownerDocument.createNamespace(importedNode._namespaces.item(i).localName);
-                        importNode._namespaces[i].value = importedNode._namespaces.item(i).value;
-                    }
-                }
-            
-                // set the value of the local Attribute to match that of the importedAttribute
-                importNode.value = importedNode.value;
-                
-            } else if (importedNode.nodeType == DOMNode.DOCUMENT_FRAGMENT) {
-                // create a local DocumentFragment
-                importNode = this.ownerDocument.createDocumentFragment();
-            } else if (importedNode.nodeType == DOMNode.NAMESPACE_NODE) {
-                // create a local NamespaceNode (with the same name &amp; value as the importedNode)
-                importNode = this.ownerDocument.createNamespace(importedNode.nodeName);
-                importNode.value = importedNode.value;
-            } else if (importedNode.nodeType == DOMNode.TEXT_NODE) {
-                // create a local TextNode (with the same data as the importedNode)
-                importNode = this.ownerDocument.createTextNode(importedNode.data);
-            } else if (importedNode.nodeType == DOMNode.CDATA_SECTION_NODE) {
-                // create a local CDATANode (with the same data as the importedNode)
-                importNode = this.ownerDocument.createCDATASection(importedNode.data);
-            } else if (importedNode.nodeType == DOMNode.PROCESSING_INSTRUCTION_NODE) {
-                // create a local ProcessingInstruction (with the same target &amp; data as the importedNode)
-                importNode = this.ownerDocument.createProcessingInstruction(importedNode.target, importedNode.data);
-            } else if (importedNode.nodeType == DOMNode.COMMENT_NODE) {
-                // create a local Comment (with the same data as the importedNode)
-                importNode = this.ownerDocument.createComment(importedNode.data);
-            } else {  // throw Exception if nodeType is not supported
-                throw(new DOMException(DOMException.NOT_SUPPORTED_ERR));
-            }
-            
-            if (deep) {                                    // recurse childNodes
-                for(var i = 0; i &lt; importedNode.childNodes.length; i++) {
-                    importNode.appendChild(this.ownerDocument.importNode(importedNode.childNodes.item(i), true));
-                }
-            }
-            
-            //reset _performingImportNodeOperation
-            this.ownerDocument._performingImportNodeOperation = false;
-            return importNode;
-        } catch (eAny) {
-            //reset _performingImportNodeOperation
-            this.ownerDocument._performingImportNodeOperation = false;
-            
-            //re-throw the exception
-            throw eAny;
-        }//djotemp
-    },
-    contains : function(node){
-            while(node &amp;&amp; node != this ){
-                node = node.parentNode;
-            }
-            return !!node;
-    },
-    compareDocumentPosition : function(b){
-        var a = this;
-        var number = (a != b &amp;&amp; a.contains(b) &amp;&amp; 16) + (a != b &amp;&amp; b.contains(a) &amp;&amp; 8);
-        //find position of both
-        var all = document.getElementsByTagName(&quot;*&quot;);
-        var my_location = 0, node_location = 0;
-        for(var i=0; i &lt; all.length; i++){
-            if(all[i] == a) my_location = i;
-            if(all[i] == b) node_location = i;
-            if(my_location &amp;&amp; node_location) break;
-        }
-        number += (my_location &lt; node_location &amp;&amp; 4)
-        number += (my_location &gt; node_location &amp;&amp; 2)
-        return number;
-    } 
-
-});
-
-/**
- * @method DOMNode._getElementsByTagNameRecursive - implements getElementsByTagName()
- * @param  elem     : DOMElement  - The element which are checking and then recursing into
- * @param  tagname  : string      - The name of the tag to match on. The special value &quot;*&quot; matches all tags
- * @param  nodeList : DOMNodeList - The accumulating list of matching nodes
- *
- * @return : DOMNodeList
- */
-var __getElementsByTagNameRecursive__ = function (elem, tagname, nodeList) {
-    //$log(&quot;__getElementsByTagNameRecursive__(&quot;+elem._id+&quot;)&quot;);
-    if (elem.nodeType == DOMNode.ELEMENT_NODE || elem.nodeType == DOMNode.DOCUMENT_NODE) {
-    
-        if((elem.nodeName.toUpperCase() == tagname.toUpperCase()) || (tagname == &quot;*&quot;)) {
-            //$log(&quot;found node by name &quot; + tagname);
-            __appendChild__(nodeList, elem);               // add matching node to nodeList
-        }
-    
-        // recurse childNodes
-        for(var i = 0; i &lt; elem.childNodes.length; i++) {
-            nodeList = __getElementsByTagNameRecursive__(elem.childNodes.item(i), tagname, nodeList);
-        }
-    }
-    
-    return nodeList;
-};
-
-
-/**
- * @method DOMNode._getElementsByTagNameNSRecursive - implements getElementsByTagName()
- *
- * @param  elem     : DOMElement  - The element which are checking and then recursing into
- * @param  namespaceURI : string - the namespace URI of the required node
- * @param  localName    : string - the local name of the required node
- * @param  nodeList     : DOMNodeList - The accumulating list of matching nodes
- *
- * @return : DOMNodeList
- */
-var __getElementsByTagNameNSRecursive__ = function(elem, namespaceURI, localName, nodeList) {
-  if (elem.nodeType == DOMNode.ELEMENT_NODE || elem.nodeType == DOMNode.DOCUMENT_NODE) {
-
-    if (((elem.namespaceURI == namespaceURI) || (namespaceURI == &quot;*&quot;)) &amp;&amp; ((elem.localName == localName) || (localName == &quot;*&quot;))) {
-      __appendChild__(nodeList, elem);               // add matching node to nodeList
-    }
-
-    // recurse childNodes
-    for(var i = 0; i &lt; elem.childNodes.length; i++) {
-      nodeList = __getElementsByTagNameNSRecursive__(elem.childNodes.item(i), namespaceURI, localName, nodeList);
-    }
-  }
-
-  return nodeList;
-};
-
-/**
- * @method DOMNode._isAncestor - returns true if node is ancestor of target
- * @param  target         : DOMNode - The node we are using as context
- * @param  node         : DOMNode - The candidate ancestor node
- * @return : boolean
- */
-var __isAncestor__ = function(target, node) {
-  // if this node matches, return true,
-  // otherwise recurse up (if there is a parentNode)
-  return ((target == node) || ((target.parentNode) &amp;&amp; (__isAncestor__(target.parentNode, node))));
-}
-
-
-/**
- * @class  DOMNamespace - The Namespace interface represents an namespace in an Element object
- *
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMNamespace = function(ownerDocument) {
-  this.DOMNode = DOMNode;
-  this.DOMNode(ownerDocument);
-
-  this.name      = &quot;&quot;;                           // the name of this attribute
-
-  // If this attribute was explicitly given a value in the original document, this is true; otherwise, it is false.
-  // Note that the implementation is in charge of this attribute, not the user.
-  // If the user changes the value of the attribute (even if it ends up having the same value as the default value)
-  // then the specified flag is automatically flipped to true
-  this.specified = false;
-
-  this.value     = &quot;&quot;;                           // the value of the attribute is returned as a string
-
-  this.nodeType  = DOMNode.NAMESPACE_NODE;
-};
-DOMNamespace.prototype = new DOMNode;
-__extend__(DOMNamespace.prototype, {
-    get value(){
-        return this.nodeValue;
-    },
-    set value(value){
-        this.nodeValue = String(value);
-    },
-    get xml(){
-        var ret = &quot;&quot;;
-
-          // serialize Namespace Declaration
-          if (this.nodeName != &quot;&quot;) {
-            ret += this.nodeName +&quot;=\&quot;&quot;+ __escapeXML__(this.nodeValue) +&quot;\&quot;&quot;;
-          }
-          else {  // handle default namespace
-            ret += &quot;xmlns=\&quot;&quot;+ __escapeXML__(this.nodeValue) +&quot;\&quot;&quot;;
-          }
-        
-          return ret;
-    },
-    toString: function(){
-        return &quot;Namespace #&quot; + this.id;
-    }
-});
-
-$debug(&quot;Defining CharacterData&quot;);
-/*
-* CharacterData - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CharacterData&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMCharacterData - parent abstract class for DOMText and DOMComment
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMCharacterData = function(ownerDocument) {
-  this.DOMNode  = DOMNode;
-  this.DOMNode(ownerDocument);
-  this.data   = &quot;&quot;;
-  this.length = 0;
-};
-DOMCharacterData.prototype = new DOMNode;
-__extend__(DOMCharacterData.prototype,{
-    get data(){
-        return String(this.nodeValue);
-    },
-    set data(data){
-        this.nodeValue = String(data);
-    },
-    get length(){return this.nodeValue.length;},
-    appendData: function(arg){
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        // append data
-        this.data = &quot;&quot; + this.data + arg;
-    },
-    deleteData: function(offset, count){ 
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
-              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // delete data
-            if(!count || (offset + count) &gt; this.data.length) {
-              this.data = this.data.substring(0, offset);
-            }else {
-              this.data = this.data.substring(0, offset).concat(this.data.substring(offset + count));
-            }
-        }
-    },
-    insertData: function(offset, arg){
-        // throw Exception if DOMCharacterData is readonly
-        if(this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly){
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        
-        if(this.data){
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // insert data
-            this.data =  this.data.substring(0, offset).concat(arg, this.data.substring(offset));
-        }else {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (offset != 0)) {
-               throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // set data
-            this.data = arg;
-        }
-    },
-    replaceData: function(offset, count, arg){
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // replace data
-            this.data = this.data.substring(0, offset).concat(arg, this.data.substring(offset + count));
-        }else {
-            // set data
-            this.data = arg;
-        }
-    },
-    substringData: function(offset, count){
-        var ret = null;
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            // or the count is negative
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt; this.data.length) || (count &lt; 0))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            // if count is not specified
-            if (!count) {
-                ret = this.data.substring(offset); // default to 'end of string'
-            }else{
-                ret = this.data.substring(offset, offset + count);
-            }
-        }
-        return ret;
-    }
-});
-$log(&quot;Defining Text&quot;);
-/*
-* Text - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Text&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-/**
- * @class  DOMText - The Text interface represents the textual content (termed character data in XML) of an Element or Attr.
- *   If there is no markup inside an element's content, the text is contained in a single object implementing the Text interface
- *   that is the only child of the element. If there is markup, it is parsed into a list of elements and Text nodes that form the
- *   list of children of the element.
- * @extends DOMCharacterData
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-DOMText = function(ownerDocument) {
-  this.DOMCharacterData  = DOMCharacterData;
-  this.DOMCharacterData(ownerDocument);
-
-  this.nodeName  = &quot;#text&quot;;
-  this.nodeType  = DOMNode.TEXT_NODE;
-};
-DOMText.prototype = new DOMCharacterData;
-__extend__(DOMText.prototype,{
-    //Breaks this Text node into two Text nodes at the specified offset,
-    // keeping both in the tree as siblings. This node then only contains all the content up to the offset point.
-    // And a new Text node, which is inserted as the next sibling of this node, contains all the content at and after the offset point.
-    splitText : function(offset) {
-        var data, inode;
-        
-        // test for exceptions
-        if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if Node is readonly
-            if (this._readonly) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-            
-            // throw Exception if offset is negative or greater than the data length,
-            if ((offset &lt; 0) || (offset &gt; this.data.length)) {
-              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-        }
-        
-        if (this.parentNode) {
-            // get remaining string (after offset)
-            data  = this.substringData(offset);
-            
-            // create new TextNode with remaining string
-            inode = this.ownerDocument.createTextNode(data);
-            
-            // attach new TextNode
-            if (this.nextSibling) {
-              this.parentNode.insertBefore(inode, this.nextSibling);
-            }
-            else {
-              this.parentNode.appendChild(inode);
-            }
-            
-            // remove remaining string from original TextNode
-            this.deleteData(offset);
-        }
-        
-        return inode;
-    },
-    get xml(){
-        return __escapeXML__(&quot;&quot;+ this.nodeValue);
-    },
-    toString: function(){
-        return &quot;Text #&quot; + this._id;    
-    }
-});
-
-$log(&quot;Defining CDATASection&quot;);
-/*
-* CDATASection - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CDATASection&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMCDATASection - CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup.
- *   The only delimiter that is recognized in a CDATA section is the &quot;\]\]\&gt;&quot; string that ends the CDATA section
- * @extends DOMCharacterData
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMCDATASection = function(ownerDocument) {
-  this.DOMText  = DOMText;
-  this.DOMText(ownerDocument);
-
-  this.nodeName  = &quot;#cdata-section&quot;;
-  this.nodeType  = DOMNode.CDATA_SECTION_NODE;
-};
-DOMCDATASection.prototype = new DOMText;
-__extend__(DOMCDATASection.prototype,{
-    get xml(){
-        return &quot;&lt;![CDATA[&quot; + this.nodeValue + &quot;]]&gt;&quot;;
-    },
-    toString : function(){
-        return &quot;CDATA #&quot;+this._id;
-    }
-});$log(&quot;Defining Comment&quot;);
-/* 
-* Comment - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Comment&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMComment - This represents the content of a comment, i.e., all the characters between the starting '&lt;!--' and ending '--&gt;'
- * @extends DOMCharacterData
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMComment = function(ownerDocument) {
-  this.DOMCharacterData  = DOMCharacterData;
-  this.DOMCharacterData(ownerDocument);
-
-  this.nodeName  = &quot;#comment&quot;;
-  this.nodeType  = DOMNode.COMMENT_NODE;
-};
-DOMComment.prototype = new DOMCharacterData;
-__extend__(DOMComment.prototype, {
-    get xml(){
-        return &quot;&lt;!-- &quot; + this.nodeValue + &quot; --&gt;&quot;;
-    },
-    toString : function(){
-        return &quot;Comment #&quot;+this._id;
-    }
-});
-$log(&quot;Defining DocumentType&quot;);
-;/*
-* DocumentType - DOM Level 2
-*/
-$w.__defineGetter__('DocumentType', function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var DOMDocumentType    = function() { $error(&quot;DOMDocumentType.constructor(): Not Implemented&quot;   ); };$log(&quot;Defining Attr&quot;);
-/*
-* Attr - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Attr&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-
-/**
- * @class  DOMAttr - The Attr interface represents an attribute in an Element object
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMAttr = function(ownerDocument) {
-    //$log(&quot;\tcreating dom attribute&quot;);
-    this.DOMNode = DOMNode;
-    this.DOMNode(ownerDocument);
-    
-    this.name      = &quot;&quot;;                    // the name of this attribute
-    this.specified = false;
-    this.value     = &quot;&quot;;                    // the value of the attribute is returned as a string
-    this.nodeType  = DOMNode.ATTRIBUTE_NODE;
-    this.ownerElement = null;               // set when Attr is added to NamedNodeMap
-    
-    //$log(&quot;\tfincished creating dom attribute &quot; + this);
-};
-DOMAttr.prototype = new DOMNode; 
-__extend__(DOMAttr.prototype, {
-    get name(){
-        return this.nodeName;
-    },
-    get value(){
-        return this.nodeValue;
-    },
-    set value(value){
-        // throw Exception if Attribute is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        // delegate to node
-        this.specified = (this.value.length &gt; 0);
-        this.nodeValue = value;
-    },
-    get xml(){
-        return this.nodeName + &quot;='&quot; + this.nodeValue + &quot;' &quot;;
-    },
-    toString : function(){
-        return &quot;Attr #&quot; + this._id + &quot; &quot; + this.name;
-    }
-});    
-
-$log(&quot;Defining Element&quot;);
-/*
-* Element - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Element&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-	
-/**
- * @class  DOMElement - By far the vast majority of objects (apart from text) that authors encounter
- *   when traversing a document are Element nodes.
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMElement = function(ownerDocument) {
-    //$log(&quot;\tcreating dom element&quot;);
-    this.DOMNode  = DOMNode;
-    this.DOMNode(ownerDocument);
-    this.tagName = &quot;&quot;;                             // The name of the element.
-    this.id = &quot;&quot;;                                  // the ID of the element
-    this.nodeType = DOMNode.ELEMENT_NODE;
-    //$log(&quot;\nfinished creating dom element &quot; + this);
-};
-DOMElement.prototype = new DOMNode;
-__extend__(DOMElement.prototype, {
-  	addEventListener:     window.addEventListener,
-  	removeEventListener:  window.removeEventListener,
-  	dispatchEvent:        window.dispatchEvent,
-    getAttribute: function(name) {
-        var ret = null;
-        // if attribute exists, use it
-        var attr = this.attributes.getNamedItem(name);
-        if (attr) {
-            ret = attr.value;
-        }
-        return ret; // if Attribute exists, return its value, otherwise, return &quot;&quot;
-    },
-    setAttribute : function (name, value) {
-        // if attribute exists, use it
-        var attr = this.attributes.getNamedItem(name);
-        var value = new String(value);
-        //I had to add this check becuase as the script initializes
-        //the id may be set in the constructor, and the html element
-        //overrides the id property with a getter/setter.
-        if(this.ownerDocument){
-            if (!attr) {
-                attr = this.ownerDocument.createAttribute(name);  // otherwise create it
-            }
-            
-            
-            // test for exceptions
-            if (this.ownerDocument.implementation.errorChecking) {
-                // throw Exception if Attribute is readonly
-                if (attr._readonly) {
-                    throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-                }
-                
-                // throw Exception if the value string contains an illegal character
-                if (!__isValidString__(value)) {
-                    throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-                }
-            }
-            
-            if (__isIdDeclaration__(name)) {
-                this.id = value;  // cache ID for getElementById()
-            }
-            
-            // assign values to properties (and aliases)
-            attr.value     = value;
-            
-            // update .specified
-            if (value.length &gt; 0) {
-                attr.specified = true;
-            }else {
-                attr.specified = false;
-            }
-            
-            // add/replace Attribute in NamedNodeMap
-            this.attributes.setNamedItem(attr);
-        }
-    },
-    removeAttribute : function removeAttribute(name) {
-        // delegate to DOMNamedNodeMap.removeNamedItem
-        return this.attributes.removeNamedItem(name);
-    },
-    getAttributeNode : function getAttributeNode(name) {
-        // delegate to DOMNamedNodeMap.getNamedItem
-        return this.attributes.getNamedItem(name);
-    },
-    setAttributeNode: function(newAttr) {
-        // if this Attribute is an ID
-        if (__isIdDeclaration__(newAttr.name)) {
-            this.id = newAttr.value;  // cache ID for getElementById()
-        }
-        // delegate to DOMNamedNodeMap.setNamedItem
-        return this.attributes.setNamedItem(newAttr);
-    },
-    removeAttributeNode: function(oldAttr) {
-      // throw Exception if Attribute is readonly
-      if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldAttr._readonly) {
-        throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-      }
-    
-      // get item index
-      var itemIndex = this.attributes._findItemIndex(oldAttr._id);
-    
-      // throw Exception if node does not exist in this map
-      if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-        throw(new DOMException(DOMException.NOT_FOUND_ERR));
-      }
-    
-      return this.attributes._removeChild(itemIndex);
-    },
-    getAttributeNS : function(namespaceURI, localName) {
-        var ret = &quot;&quot;;
-        // delegate to DOMNAmedNodeMap.getNamedItemNS
-        var attr = this.attributes.getNamedItemNS(namespaceURI, localName);
-        if (attr) {
-            ret = attr.value;
-        }
-        return ret;  // if Attribute exists, return its value, otherwise return &quot;&quot;
-    },
-    setAttributeNS : function(namespaceURI, qualifiedName, value) {
-        // call DOMNamedNodeMap.getNamedItem
-        var attr = this.attributes.getNamedItem(namespaceURI, qualifiedName);
-        
-        if (!attr) {  // if Attribute exists, use it
-            // otherwise create it
-            attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
-        }
-        
-        var value = String(value);
-        
-        // test for exceptions
-        if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if Attribute is readonly
-            if (attr._readonly) {
-                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-            
-            // throw Exception if the Namespace is invalid
-            if (!__isValidNamespace__(namespaceURI, qualifiedName)) {
-                throw(new DOMException(DOMException.NAMESPACE_ERR));
-            }
-            
-            // throw Exception if the value string contains an illegal character
-            if (!__isValidString__(value)) {
-                throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-            }
-        }
-        
-        // if this Attribute is an ID
-        if (__isIdDeclaration__(name)) {
-            this.id = value;  // cache ID for getElementById()
-        }
-        
-        // assign values to properties (and aliases)
-        attr.value     = value;
-        attr.nodeValue = value;
-        
-        // update .specified
-        if (value.length &gt; 0) {
-            attr.specified = true;
-        }else {
-            attr.specified = false;
-        }
-        
-        // delegate to DOMNamedNodeMap.setNamedItem
-        this.attributes.setNamedItemNS(attr);
-    },
-    removeAttributeNS : function(namespaceURI, localName) {
-        // delegate to DOMNamedNodeMap.removeNamedItemNS
-        return this.attributes.removeNamedItemNS(namespaceURI, localName);
-    },
-    getAttributeNodeNS : function(namespaceURI, localName) {
-        // delegate to DOMNamedNodeMap.getNamedItemNS
-        return this.attributes.getNamedItemNS(namespaceURI, localName);
-    },
-    setAttributeNodeNS : function(newAttr) {
-        // if this Attribute is an ID
-        if ((newAttr.prefix == &quot;&quot;) &amp;&amp;  __isIdDeclaration__(newAttr.name)) {
-            this.id = String(newAttr.value);  // cache ID for getElementById()
-        }
-        
-        // delegate to DOMNamedNodeMap.setNamedItemNS
-        return this.attributes.setNamedItemNS(newAttr);
-    },
-    hasAttribute : function(name) {
-        // delegate to DOMNamedNodeMap._hasAttribute
-        return __hasAttribute__(this.attributes,name);
-    },
-    hasAttributeNS : function(namespaceURI, localName) {
-        // delegate to DOMNamedNodeMap._hasAttributeNS
-        return __hasAttributeNS__(this.attributes, namespaceURI, localName);
-    },
-    get xml() {
-        var ret = &quot;&quot;;
-        
-        // serialize namespace declarations
-        var ns = this._namespaces.xml;
-        if (ns.length &gt; 0) ns = &quot; &quot;+ ns;
-        
-        // serialize Attribute declarations
-        var attrs = this.attributes.xml;
-        if (attrs.length &gt; 0) attrs = &quot; &quot;+ attrs;
-        
-        // serialize this Element
-        ret += &quot;&lt;&quot; + this.nodeName.toLowerCase() + ns + attrs +&quot;&gt;&quot;;
-        ret += this.childNodes.xml;
-        ret += &quot;&lt;/&quot; + this.nodeName.toLowerCase()+&quot;&gt;&quot;;
-        
-        return ret;
-    },
-    toString : function(){
-        return &quot;Element #&quot;+this._id + &quot; &quot;+ this.tagName + (this.id?&quot; =&gt; &quot;+this.id:'');
-    }
-});
-
-/**
- * @class  DOMException - raised when an operation is impossible to perform
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  code : int - the exception code (one of the DOMException constants)
- */
-var DOMException = function(code) {
-  this.code = code;
-};
-
-// DOMException constants
-// Introduced in DOM Level 1:
-DOMException.INDEX_SIZE_ERR                 = 1;
-DOMException.DOMSTRING_SIZE_ERR             = 2;
-DOMException.HIERARCHY_REQUEST_ERR          = 3;
-DOMException.WRONG_DOCUMENT_ERR             = 4;
-DOMException.INVALID_CHARACTER_ERR          = 5;
-DOMException.NO_DATA_ALLOWED_ERR            = 6;
-DOMException.NO_MODIFICATION_ALLOWED_ERR    = 7;
-DOMException.NOT_FOUND_ERR                  = 8;
-DOMException.NOT_SUPPORTED_ERR              = 9;
-DOMException.INUSE_ATTRIBUTE_ERR            = 10;
-
-// Introduced in DOM Level 2:
-DOMException.INVALID_STATE_ERR              = 11;
-DOMException.SYNTAX_ERR                     = 12;
-DOMException.INVALID_MODIFICATION_ERR       = 13;
-DOMException.NAMESPACE_ERR                  = 14;
-DOMException.INVALID_ACCESS_ERR             = 15;
-$log(&quot;Defining DocumentFragment&quot;);
-/* 
-* DocumentFragment - DOM Level 2
-*/
-$w.__defineGetter__(&quot;DocumentFragment&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-/**
- * @class  DOMDocumentFragment - DocumentFragment is a &quot;lightweight&quot; or &quot;minimal&quot; Document object.
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMDocumentFragment = function(ownerDocument) {
-  this.DOMNode = DOMNode;
-  this.DOMNode(ownerDocument);
-  this.nodeName  = &quot;#document-fragment&quot;;
-  this.nodeType = DOMNode.DOCUMENT_FRAGMENT_NODE;
-};
-DOMDocumentFragment.prototype = new DOMNode;
-__extend__(DOMDocumentFragment.prototype,{
-    get xml(){
-        var xml = &quot;&quot;,
-            count = this.childNodes.length;
-        
-        // create string concatenating the serialized ChildNodes
-        for (var i = 0; i &lt; count; i++) {
-            xml += this.childNodes.item(i).xml;
-        }
-        
-        return xml;
-    },
-    toString : function(){
-        return &quot;DocumentFragment #&quot;+this._id;
-    }
-});
-$log(&quot;Defining ProcessingInstruction&quot;);
-/*
-* ProcessingInstruction - DOM Level 2
-*/
-$w.__defineGetter__('ProcessingInstruction', function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-/**
- * @class  DOMProcessingInstruction - The ProcessingInstruction interface represents a &quot;processing instruction&quot;,
- *   used in XML as a way to keep processor-specific information in the text of the document
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMProcessingInstruction = function(ownerDocument) {
-  this.DOMNode  = DOMNode;
-  this.DOMNode(ownerDocument);
-  // The target of this processing instruction.
-  // XML defines this as being the first token following the markup that begins the processing instruction.
-  this.target = &quot;&quot;;
-  // The content of this processing instruction.
-  // This is from the first non white space character after the target to the character immediately preceding the ?&gt;
-  this.data   = &quot;&quot;;
-  this.nodeType  = DOMNode.PROCESSING_INSTRUCTION_NODE;
-};
-DOMProcessingInstruction.prototype = new DOMNode;
-__extend__(DOMProcessingInstruction.prototype, {
-    get data(){
-        return this.nodeValue;
-    },
-    set data(data){
-        // throw Exception if DOMNode is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        this.nodeValue = data;
-    },
-    get target(){
-        return this.nodeName;
-    },
-    get xml(){
-        return &quot;&lt;?&quot; + this.nodeName +&quot; &quot;+ this.nodeValue + &quot; ?&gt;&quot;;
-    },
-    toString : function(){
-        return &quot;ProcessingInstruction #&quot;+this._id;
-    }
-});
-$log(&quot;Defining DOMParser&quot;);
-/*
-* DOMParser
-*/
-$w.__defineGetter__('DOMParser', function(){
-  return function(){
-    return __extend__(this, {
-      parseFromString: function(xmlString){
-        //$log(&quot;Parsing XML String: &quot; +xmlString);
-        return document.implementation.createDocument().loadXML(xmlString);
-      }
-    });
-  };
-});
-
-$log(&quot;Initializing Internal DOMParser.&quot;);
-//keep one around for internal use
-$domparser = new DOMParser();
-
-// =========================================================================
-//
-// xmlsax.js - an XML SAX parser in JavaScript.
-//
-// version 3.1
-//
-// =========================================================================
-//
-// Copyright (C) 2001 - 2002 David Joham (djoham@yahoo.com) and Scott Severtson
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-//
-//
-// Visit the XML for &lt;SCRIPT&gt; home page at http://xmljs.sourceforge.net
-//
-
-// CONSTANTS
-var whitespace = &quot;\n\r\t &quot;;
-
-
-/**
-*   function:   this is the constructor to the XMLP Object
-*   Author:   Scott Severtson
-*   Description:XMLP is a pull-based parser. The calling application passes in a XML string
-*   to the constructor, then repeatedly calls .next() to parse the next segment.
-*   .next() returns a flag indicating what type of segment was found, and stores
-*   data temporarily in couple member variables (name, content, array of
-*   attributes), which can be accessed by several .get____() methods.
-*
-*   Basically, XMLP is the lowest common denominator parser - an very simple
-*   API which other wrappers can be built against.
-**/
-
-
-var XMLP = function(strXML) {
-    // Normalize line breaks
-    strXML = SAXStrings.replace(strXML, null, null, &quot;\r\n&quot;, &quot;\n&quot;);
-    strXML = SAXStrings.replace(strXML, null, null, &quot;\r&quot;, &quot;\n&quot;);
-
-    this.m_xml = strXML;
-    this.m_iP = 0;
-    this.m_iState = XMLP._STATE_PROLOG;
-    this.m_stack = new Stack();
-    this._clearAttributes();
-
-};
-
-
-// CONSTANTS    (these must be below the constructor)
-
-
-XMLP._NONE    = 0;
-XMLP._ELM_B   = 1;
-XMLP._ELM_E   = 2;
-XMLP._ELM_EMP = 3;
-XMLP._ATT     = 4;
-XMLP._TEXT    = 5;
-XMLP._ENTITY  = 6;
-XMLP._PI      = 7;
-XMLP._CDATA   = 8;
-XMLP._COMMENT = 9;
-XMLP._DTD     = 10;
-XMLP._ERROR   = 11;
-
-XMLP._CONT_XML = 0;
-XMLP._CONT_ALT = 1;
-
-XMLP._ATT_NAME = 0;
-XMLP._ATT_VAL  = 1;
-
-XMLP._STATE_PROLOG = 1;
-XMLP._STATE_DOCUMENT = 2;
-XMLP._STATE_MISC = 3;
-
-XMLP._errs = new Array();
-XMLP._errs[XMLP.ERR_CLOSE_PI       = 0 ] = &quot;PI: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_DTD      = 1 ] = &quot;DTD: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_COMMENT  = 2 ] = &quot;Comment: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_CDATA    = 3 ] = &quot;CDATA: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_ELM      = 4 ] = &quot;Element: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_ENTITY   = 5 ] = &quot;Entity: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_PI_TARGET      = 6 ] = &quot;PI: target is required&quot;;
-XMLP._errs[XMLP.ERR_ELM_EMPTY      = 7 ] = &quot;Element: cannot be both empty and closing&quot;;
-XMLP._errs[XMLP.ERR_ELM_NAME       = 8 ] = &quot;Element: name must immediatly follow \&quot;&lt;\&quot;&quot;;
-XMLP._errs[XMLP.ERR_ELM_LT_NAME    = 9 ] = &quot;Element: \&quot;&lt;\&quot; not allowed in element names&quot;;
-XMLP._errs[XMLP.ERR_ATT_VALUES     = 10] = &quot;Attribute: values are required and must be in quotes&quot;;
-XMLP._errs[XMLP.ERR_ATT_LT_NAME    = 11] = &quot;Element: \&quot;&lt;\&quot; not allowed in attribute names&quot;;
-XMLP._errs[XMLP.ERR_ATT_LT_VALUE   = 12] = &quot;Attribute: \&quot;&lt;\&quot; not allowed in attribute values&quot;;
-XMLP._errs[XMLP.ERR_ATT_DUP        = 13] = &quot;Attribute: duplicate attributes not allowed&quot;;
-XMLP._errs[XMLP.ERR_ENTITY_UNKNOWN = 14] = &quot;Entity: unknown entity&quot;;
-XMLP._errs[XMLP.ERR_INFINITELOOP   = 15] = &quot;Infininte loop&quot;;
-XMLP._errs[XMLP.ERR_DOC_STRUCTURE  = 16] = &quot;Document: only comments, processing instructions, or whitespace allowed outside of document element&quot;;
-XMLP._errs[XMLP.ERR_ELM_NESTING    = 17] = &quot;Element: must be nested correctly&quot;;
-
-
-
-XMLP.prototype._addAttribute = function(name, value) {
-    this.m_atts[this.m_atts.length] = new Array(name, value);
-}  
-
-
-XMLP.prototype._checkStructure = function(iEvent) {
-  
-	if(XMLP._STATE_PROLOG == this.m_iState) {
-		if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
-            if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
-				return this._setErr(XMLP.ERR_DOC_STRUCTURE);
-            }
-        }
-
-        if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
-            this.m_iState = XMLP._STATE_DOCUMENT;
-            // Don't return - fall through to next state
-        }
-    }
-    if(XMLP._STATE_DOCUMENT == this.m_iState) {
-        if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
-            this.m_stack.push(this.getName());
-        }
-
-        if((XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent)) {
-            var strTop = this.m_stack.pop();
-            if((strTop == null) || (strTop != this.getName())) {
-                return this._setErr(XMLP.ERR_ELM_NESTING);
-            }
-        }
-
-        if(this.m_stack.count() == 0) {
-            this.m_iState = XMLP._STATE_MISC;
-            return iEvent;
-        }
-    }
-    if(XMLP._STATE_MISC == this.m_iState) {
-		if((XMLP._ELM_B == iEvent) || (XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent) || (XMLP.EVT_DTD == iEvent)) {
-			return this._setErr(XMLP.ERR_DOC_STRUCTURE);
-        }
-
-        if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
-			if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
-				return this._setErr(XMLP.ERR_DOC_STRUCTURE);
-            }
-        }
-    }
-
-    return iEvent;
-
-}  
-
-
-XMLP.prototype._clearAttributes = function() {
-    this.m_atts = new Array();
-}  
-
-
-XMLP.prototype._findAttributeIndex = function(name) {
-    for(var i = 0; i &lt; this.m_atts.length; i++) {
-        if(this.m_atts[i][XMLP._ATT_NAME] == name) {
-            return i;
-        }
-    }
-    return -1;
-
-}  
-
-
-XMLP.prototype.getAttributeCount = function() {
-
-    return this.m_atts ? this.m_atts.length : 0;
-
-}  
-
-
-XMLP.prototype.getAttributeName = function(index) {
-
-    return ((index &lt; 0) || (index &gt;= this.m_atts.length)) ? null : this.m_atts[index][XMLP._ATT_NAME];
-
-}  
-
-
-XMLP.prototype.getAttributeValue = function(index) {
-
-    return ((index &lt; 0) || (index &gt;= this.m_atts.length)) ? null : __unescapeXML__(this.m_atts[index][XMLP._ATT_VAL]);
-
-} 
-
-
-XMLP.prototype.getAttributeValueByName = function(name) {
-
-    return this.getAttributeValue(this._findAttributeIndex(name));
-
-}  
-
-
-XMLP.prototype.getColumnNumber = function() {
-
-    return SAXStrings.getColumnNumber(this.m_xml, this.m_iP);
-
-}  
-
-
-XMLP.prototype.getContent = function() {
-
-    return (this.m_cSrc == XMLP._CONT_XML) ? this.m_xml : this.m_cAlt;
-
-}  
-
-
-XMLP.prototype.getContentBegin = function() {
-
-    return this.m_cB;
-
-}  
-
-
-XMLP.prototype.getContentEnd = function() {
-
-    return this.m_cE;
-
-}  
-
-
-XMLP.prototype.getLineNumber = function() {
-
-    return SAXStrings.getLineNumber(this.m_xml, this.m_iP);
-
-}  
-
-
-XMLP.prototype.getName = function() {
-
-    return this.m_name;
-
-}  
-
-
-XMLP.prototype.next = function() {
-
-    return this._checkStructure(this._parse());
-
-} 
-
-
-XMLP.prototype._parse = function() {
-
-	if(this.m_iP == this.m_xml.length) {
-        return XMLP._NONE;
-    }
-
-    if(this.m_iP == this.m_xml.indexOf(&quot;&lt;?&quot;,        this.m_iP)) {
-        return this._parsePI     (this.m_iP + 2);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;!DOCTYPE&quot;, this.m_iP)) {
-        return this._parseDTD    (this.m_iP + 9);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;!--&quot;,      this.m_iP)) {
-        return this._parseComment(this.m_iP + 4);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;![CDATA[&quot;, this.m_iP)) {
-        return this._parseCDATA  (this.m_iP + 9);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;&quot;,         this.m_iP)) {
-        return this._parseElement(this.m_iP + 1);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&amp;&quot;,         this.m_iP)) {
-        return this._parseEntity (this.m_iP + 1);
-    }
-    else{
-        return this._parseText   (this.m_iP);
-    }
-	
-
-} 
-
-
-XMLP.prototype._parseAttribute = function(iB, iE) {
-    var iNB, iNE, iEq, iVB, iVE;
-    var cQuote, strN, strV;
-
-	this.m_cAlt = &quot;&quot;; //resets the value so we don't use an old one by accident (see testAttribute7 in the test suite)
-    
-	iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
-    if((iNB == -1) ||(iNB &gt;= iE)) {
-        return iNB;
-    }
-
-    iEq = this.m_xml.indexOf(&quot;=&quot;, iNB);
-    if((iEq == -1) || (iEq &gt; iE)) {
-        return this._setErr(XMLP.ERR_ATT_VALUES);
-    }
-
-    iNE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iNB, iEq);
-
-    iVB = SAXStrings.indexOfNonWhitespace(this.m_xml, iEq + 1, iE);
-    if((iVB == -1) ||(iVB &gt; iE)) {
-        return this._setErr(XMLP.ERR_ATT_VALUES);
-    }
-
-    cQuote = this.m_xml.charAt(iVB);
-    if(SAXStrings.QUOTES.indexOf(cQuote) == -1) {
-        return this._setErr(XMLP.ERR_ATT_VALUES);
-    }
-
-    iVE = this.m_xml.indexOf(cQuote, iVB + 1);
-    if((iVE == -1) ||(iVE &gt; iE)) {
-        return this._setErr(XMLP.ERR_ATT_VALUES);
-    }
-
-    strN = this.m_xml.substring(iNB, iNE + 1);
-    strV = this.m_xml.substring(iVB + 1, iVE);
-
-    if(strN.indexOf(&quot;&lt;&quot;) != -1) {
-        return this._setErr(XMLP.ERR_ATT_LT_NAME);
-    }
-
-    if(strV.indexOf(&quot;&lt;&quot;) != -1) {
-        return this._setErr(XMLP.ERR_ATT_LT_VALUE);
-    }
-
-    strV = SAXStrings.replace(strV, null, null, &quot;\n&quot;, &quot; &quot;);
-    strV = SAXStrings.replace(strV, null, null, &quot;\t&quot;, &quot; &quot;);
-	iRet = this._replaceEntities(strV);
-    if(iRet == XMLP._ERROR) {
-        return iRet;
-    }
-
-    strV = this.m_cAlt;
-
-    if(this._findAttributeIndex(strN) == -1) {
-        this._addAttribute(strN, strV);
-    }
-    else {
-        return this._setErr(XMLP.ERR_ATT_DUP);
-    }
-
-    this.m_iP = iVE + 2;
-
-    return XMLP._ATT;
-
-}  
-
-
-XMLP.prototype._parseCDATA = function(iB) {
-    var iE = this.m_xml.indexOf(&quot;]]&gt;&quot;, iB);
-    if (iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_CDATA);
-    }
-
-    this._setContent(XMLP._CONT_XML, iB, iE);
-
-    this.m_iP = iE + 3;
-
-    return XMLP._CDATA;
-
-}  
-
-
-XMLP.prototype._parseComment = function(iB) {
-    var iE = this.m_xml.indexOf(&quot;-&quot; + &quot;-&gt;&quot;, iB);
-    if (iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_COMMENT);
-    }
-
-    this._setContent(XMLP._CONT_XML, iB, iE);
-
-    this.m_iP = iE + 3;
-
-    return XMLP._COMMENT;
-
-}  
-
-
-XMLP.prototype._parseDTD = function(iB) {
-
-    // Eat DTD
-
-    var iE, strClose, iInt, iLast;
-
-    iE = this.m_xml.indexOf(&quot;&gt;&quot;, iB);
-    if(iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_DTD);
-    }
-
-    iInt = this.m_xml.indexOf(&quot;[&quot;, iB);
-    strClose = ((iInt != -1) &amp;&amp; (iInt &lt; iE)) ? &quot;]&gt;&quot; : &quot;&gt;&quot;;
-
-    while(true) {
-        // DEBUG: Remove
-        if(iE == iLast) {
-            return this._setErr(XMLP.ERR_INFINITELOOP);
-        }
-
-        iLast = iE;
-        // DEBUG: Remove End
-
-        iE = this.m_xml.indexOf(strClose, iB);
-        if(iE == -1) {
-            return this._setErr(XMLP.ERR_CLOSE_DTD);
-        }
-
-        // Make sure it is not the end of a CDATA section
-        if (this.m_xml.substring(iE - 1, iE + 2) != &quot;]]&gt;&quot;) {
-            break;
-        }
-    }
-
-    this.m_iP = iE + strClose.length;
-
-    return XMLP._DTD;
-
-}  
-
-
-XMLP.prototype._parseElement = function(iB) {
-    var iE, iDE, iNE, iRet;
-    var iType, strN, iLast;
-
-    iDE = iE = this.m_xml.indexOf(&quot;&gt;&quot;, iB);
-    if(iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_ELM);
-    }
-
-    if(this.m_xml.charAt(iB) == &quot;/&quot;) {
-        iType = XMLP._ELM_E;
-        iB++;
-    } else {
-        iType = XMLP._ELM_B;
-    }
-
-    if(this.m_xml.charAt(iE - 1) == &quot;/&quot;) {
-        if(iType == XMLP._ELM_E) {
-            return this._setErr(XMLP.ERR_ELM_EMPTY);
-        }
-        iType = XMLP._ELM_EMP;
-        iDE--;
-    }
-
-    iDE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iB, iDE);
-
-    //djohack
-    //hack to allow for elements with single character names to be recognized
-
-    if (iE - iB != 1 ) {
-        if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB) {
-            return this._setErr(XMLP.ERR_ELM_NAME);
-        }
-    }
-    // end hack -- original code below
-
-    /*
-    if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB)
-        return this._setErr(XMLP.ERR_ELM_NAME);
-    */
-    this._clearAttributes();
-
-    iNE = SAXStrings.indexOfWhitespace(this.m_xml, iB, iDE);
-    if(iNE == -1) {
-        iNE = iDE + 1;
-    }
-    else {
-        this.m_iP = iNE;
-        while(this.m_iP &lt; iDE) {
-            // DEBUG: Remove
-            if(this.m_iP == iLast) return this._setErr(XMLP.ERR_INFINITELOOP);
-            iLast = this.m_iP;
-            // DEBUG: Remove End
-
-
-            iRet = this._parseAttribute(this.m_iP, iDE);
-            if(iRet == XMLP._ERROR) return iRet;
-        }
-    }
-
-    strN = this.m_xml.substring(iB, iNE);
-
-    if(strN.indexOf(&quot;&lt;&quot;) != -1) {
-        return this._setErr(XMLP.ERR_ELM_LT_NAME);
-    }
-
-    this.m_name = strN;
-    this.m_iP = iE + 1;
-
-    return iType;
-
-}  
-
-
-XMLP.prototype._parseEntity = function(iB) {
-    var iE = this.m_xml.indexOf(&quot;;&quot;, iB);
-    if(iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_ENTITY);
-    }
-
-    this.m_iP = iE + 1;
-
-    return this._replaceEntity(this.m_xml, iB, iE);
-
-} 
-
-
-XMLP.prototype._parsePI = function(iB) {
-
-    var iE, iTB, iTE, iCB, iCE;
-
-    iE = this.m_xml.indexOf(&quot;?&gt;&quot;, iB);
-    if(iE   == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_PI);
-    }
-
-    iTB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
-    if(iTB == -1) {
-        return this._setErr(XMLP.ERR_PI_TARGET);
-    }
-
-    iTE = SAXStrings.indexOfWhitespace(this.m_xml, iTB, iE);
-    if(iTE  == -1) {
-        iTE = iE;
-    }
-
-    iCB = SAXStrings.indexOfNonWhitespace(this.m_xml, iTE, iE);
-    if(iCB == -1) {
-        iCB = iE;
-    }
-
-    iCE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iCB, iE);
-    if(iCE  == -1) {
-        iCE = iE - 1;
-    }
-
-    this.m_name = this.m_xml.substring(iTB, iTE);
-    this._setContent(XMLP._CONT_XML, iCB, iCE + 1);
-    this.m_iP = iE + 2;
-
-    return XMLP._PI;
-
-}  
-
-
-XMLP.prototype._parseText = function(iB) {
-    var iE, iEE;
-
-    iE = this.m_xml.indexOf(&quot;&lt;&quot;, iB);
-    if(iE == -1) {
-        iE = this.m_xml.length;
-    }
-
-    iEE = this.m_xml.indexOf(&quot;&amp;&quot;, iB);
-    if((iEE != -1) &amp;&amp; (iEE &lt;= iE)) {
-        iE = iEE;
-    }
-
-    this._setContent(XMLP._CONT_XML, iB, iE);
-
-    this.m_iP = iE;
-
-    return XMLP._TEXT;
-
-} 
-
-
-XMLP.prototype._replaceEntities = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) return &quot;&quot;;
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-
-    var iEB, iEE, strRet = &quot;&quot;;
-
-    iEB = strD.indexOf(&quot;&amp;&quot;, iB);
-    iEE = iB;
-
-    while((iEB &gt; 0) &amp;&amp; (iEB &lt; iE)) {
-        strRet += strD.substring(iEE, iEB);
-
-        iEE = strD.indexOf(&quot;;&quot;, iEB) + 1;
-
-        if((iEE == 0) || (iEE &gt; iE)) {
-            return this._setErr(XMLP.ERR_CLOSE_ENTITY);
-        }
-
-        iRet = this._replaceEntity(strD, iEB + 1, iEE - 1);
-        if(iRet == XMLP._ERROR) {
-            return iRet;
-        }
-
-        strRet += this.m_cAlt;
-
-        iEB = strD.indexOf(&quot;&amp;&quot;, iEE);
-    }
-
-    if(iEE != iE) {
-        strRet += strD.substring(iEE, iE);
-    }
-
-    this._setContent(XMLP._CONT_ALT, strRet);
-
-    return XMLP._ENTITY;
-
-}  
-
-
-XMLP.prototype._replaceEntity = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) return -1;
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    switch(strD.substring(iB, iE)) {
-        case &quot;amp&quot;:  strEnt = &quot;&amp;&quot;;  break;
-        case &quot;lt&quot;:   strEnt = &quot;&lt;&quot;;  break;
-        case &quot;gt&quot;:   strEnt = &quot;&gt;&quot;;  break;
-        case &quot;apos&quot;: strEnt = &quot;'&quot;;  break;
-        case &quot;quot&quot;: strEnt = &quot;\&quot;&quot;; break;
-        default:
-            if(strD.charAt(iB) == &quot;#&quot;) {
-                strEnt = String.fromCharCode(parseInt(strD.substring(iB + 1, iE)));
-            } else {
-                return this._setErr(XMLP.ERR_ENTITY_UNKNOWN);
-            }
-        break;
-    }
-    this._setContent(XMLP._CONT_ALT, strEnt);
-
-    return XMLP._ENTITY;
-}  
-
-
-XMLP.prototype._setContent = function(iSrc) {
-    var args = arguments;
-
-    if(XMLP._CONT_XML == iSrc) {
-        this.m_cAlt = null;
-        this.m_cB = args[1];
-        this.m_cE = args[2];
-    } else {
-        this.m_cAlt = args[1];
-        this.m_cB = 0;
-        this.m_cE = args[1].length;
-    }
-    this.m_cSrc = iSrc;
-
-}  
-
-
-XMLP.prototype._setErr = function(iErr) {
-    var strErr = XMLP._errs[iErr];
-
-    this.m_cAlt = strErr;
-    this.m_cB = 0;
-    this.m_cE = strErr.length;
-    this.m_cSrc = XMLP._CONT_ALT;
-
-    return XMLP._ERROR;
-
-}  
-
-
-/**
-* function:   SAXDriver
-* Author:   Scott Severtson
-* Description:
-*    SAXDriver is an object that basically wraps an XMLP instance, and provides an
-*   event-based interface for parsing. This is the object users interact with when coding
-*   with XML for &lt;SCRIPT&gt;
-**/
-
-var SAXDriver = function() {
-    this.m_hndDoc = null;
-    this.m_hndErr = null;
-    this.m_hndLex = null;
-}
-
-
-// CONSTANTS
-SAXDriver.DOC_B = 1;
-SAXDriver.DOC_E = 2;
-SAXDriver.ELM_B = 3;
-SAXDriver.ELM_E = 4;
-SAXDriver.CHARS = 5;
-SAXDriver.PI    = 6;
-SAXDriver.CD_B  = 7;
-SAXDriver.CD_E  = 8;
-SAXDriver.CMNT  = 9;
-SAXDriver.DTD_B = 10;
-SAXDriver.DTD_E = 11;
-
-
-
-SAXDriver.prototype.parse = function(strD) {
-    var parser = new XMLP(strD);
-
-    if(this.m_hndDoc &amp;&amp; this.m_hndDoc.setDocumentLocator) {
-        this.m_hndDoc.setDocumentLocator(this);
-    }
-
-    this.m_parser = parser;
-    this.m_bErr = false;
-
-    if(!this.m_bErr) {
-        this._fireEvent(SAXDriver.DOC_B);
-    }
-    this._parseLoop();
-    if(!this.m_bErr) {
-        this._fireEvent(SAXDriver.DOC_E);
-    }
-
-    this.m_xml = null;
-    this.m_iP = 0;
-
-}  
-
-
-SAXDriver.prototype.setDocumentHandler = function(hnd) {
-
-    this.m_hndDoc = hnd;
-
-}   
-
-
-SAXDriver.prototype.setErrorHandler = function(hnd) {
-
-    this.m_hndErr = hnd;
-
-}  
-
-
-SAXDriver.prototype.setLexicalHandler = function(hnd) {
-
-    this.m_hndLex = hnd;
-
-}  
-
-
-    /**
-    * LOCATOR/PARSE EXCEPTION INTERFACE
-    ***/
-
-SAXDriver.prototype.getColumnNumber = function() {
-
-    return this.m_parser.getColumnNumber();
-
-}
-
-
-SAXDriver.prototype.getLineNumber = function() {
-
-    return this.m_parser.getLineNumber();
-
-}
-
-
-SAXDriver.prototype.getMessage = function() {
-
-    return this.m_strErrMsg;
-
-}
-
-
-SAXDriver.prototype.getPublicId = function() {
-
-    return null;
-
-}  
-
-
-SAXDriver.prototype.getSystemId = function() {
-
-    return null;
-
-}  
-
-
-    /***
-    * Attribute List Interface
-    **/
-
-SAXDriver.prototype.getLength = function() {
-
-    return this.m_parser.getAttributeCount();
-
-}  
-
-
-SAXDriver.prototype.getName = function(index) {
-
-    return this.m_parser.getAttributeName(index);
-
-} 
-
-
-SAXDriver.prototype.getValue = function(index) {
-
-    return this.m_parser.getAttributeValue(index);
-
-}  
-
-
-SAXDriver.prototype.getValueByName = function(name) {
-
-    return this.m_parser.getAttributeValueByName(name);
-
-} 
-
-
-    /***
-    *    Private functions
-    **/
-
-SAXDriver.prototype._fireError = function(strMsg) {
-    this.m_strErrMsg = strMsg;
-    this.m_bErr = true;
-
-    if(this.m_hndErr &amp;&amp; this.m_hndErr.fatalError) {
-        this.m_hndErr.fatalError(this);
-    }
-
-}   // end function _fireError
-
-
-SAXDriver.prototype._fireEvent = function(iEvt) {
-    var hnd, func, args = arguments, iLen = args.length - 1;
-
-    if(this.m_bErr) return;
-
-    if(SAXDriver.DOC_B == iEvt) {
-        func = &quot;startDocument&quot;;         hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.DOC_E == iEvt) {
-        func = &quot;endDocument&quot;;           hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.ELM_B == iEvt) {
-        func = &quot;startElement&quot;;          hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.ELM_E == iEvt) {
-        func = &quot;endElement&quot;;            hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.CHARS == iEvt) {
-        func = &quot;characters&quot;;            hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.PI    == iEvt) {
-        func = &quot;processingInstruction&quot;; hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.CD_B  == iEvt) {
-        func = &quot;startCDATA&quot;;            hnd = this.m_hndLex;
-    }
-    else if (SAXDriver.CD_E  == iEvt) {
-        func = &quot;endCDATA&quot;;              hnd = this.m_hndLex;
-    }
-    else if (SAXDriver.CMNT  == iEvt) {
-        func = &quot;comment&quot;;               hnd = this.m_hndLex;
-    }
-
-    if(hnd &amp;&amp; hnd[func]) {
-        if(0 == iLen) {
-            hnd[func]();
-        }
-        else if (1 == iLen) {
-            hnd[func](args[1]);
-        }
-        else if (2 == iLen) {
-            hnd[func](args[1], args[2]);
-        }
-        else if (3 == iLen) {
-            hnd[func](args[1], args[2], args[3]);
-        }
-    }
-
-}  // end function _fireEvent
-
-
-SAXDriver.prototype._parseLoop = function(parser) {
-    var iEvent, parser;
-
-    parser = this.m_parser;
-    while(!this.m_bErr) {
-        iEvent = parser.next();
-
-        if(iEvent == XMLP._ELM_B) {
-            this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
-        }
-        else if(iEvent == XMLP._ELM_E) {
-            this._fireEvent(SAXDriver.ELM_E, parser.getName());
-        }
-        else if(iEvent == XMLP._ELM_EMP) {
-            this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
-            this._fireEvent(SAXDriver.ELM_E, parser.getName());
-        }
-        else if(iEvent == XMLP._TEXT) {
-            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
-        }
-        else if(iEvent == XMLP._ENTITY) {
-            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
-        }
-        else if(iEvent == XMLP._PI) {
-            this._fireEvent(SAXDriver.PI, parser.getName(), parser.getContent().substring(parser.getContentBegin(), parser.getContentEnd()));
-        }
-        else if(iEvent == XMLP._CDATA) {
-            this._fireEvent(SAXDriver.CD_B);
-            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
-            this._fireEvent(SAXDriver.CD_E);
-        }
-        else if(iEvent == XMLP._COMMENT) {
-            this._fireEvent(SAXDriver.CMNT, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
-        }
-        else if(iEvent == XMLP._DTD) {
-        }
-        else if(iEvent == XMLP._ERROR) {
-            this._fireError(parser.getContent());
-        }
-        else if(iEvent == XMLP._NONE) {
-            return;
-        }
-    }
-
-}  // end function _parseLoop
-
-/**
-*   function:   SAXStrings
-*   Author:   Scott Severtson
-*   Description: a useful object containing string manipulation functions
-**/
-
-var SAXStrings = function() {};
-
-
-SAXStrings.WHITESPACE = &quot; \t\n\r&quot;;
-SAXStrings.QUOTES = &quot;\&quot;'&quot;;
-
-
-SAXStrings.getColumnNumber = function(strD, iP) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iP = iP || strD.length;
-
-    var arrD = strD.substring(0, iP).split(&quot;\n&quot;);
-    var strLine = arrD[arrD.length - 1];
-    arrD.length--;
-    var iLinePos = arrD.join(&quot;\n&quot;).length;
-
-    return iP - iLinePos;
-
-}  // end function getColumnNumber
-
-
-SAXStrings.getLineNumber = function(strD, iP) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iP = iP || strD.length;
-
-    return strD.substring(0, iP).split(&quot;\n&quot;).length
-}  // end function getLineNumber
-
-
-SAXStrings.indexOfNonWhitespace = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    for(var i = iB; i &lt; iE; i++){
-        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1) {
-            return i;
-        }
-    }
-    return -1;
-
-}  // end function indexOfNonWhitespace
-
-
-SAXStrings.indexOfWhitespace = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    for(var i = iB; i &lt; iE; i++) {
-        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) != -1) {
-            return i;
-        }
-    }
-    return -1;
-}  // end function indexOfWhitespace
-
-
-SAXStrings.isEmpty = function(strD) {
-
-    return (strD == null) || (strD.length == 0);
-
-}
-
-
-SAXStrings.lastIndexOfNonWhitespace = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    for(var i = iE - 1; i &gt;= iB; i--){
-        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1){
-            return i;
-        }
-    }
-    return -1;
-}
-
-
-SAXStrings.replace = function(strD, iB, iE, strF, strR) {
-    if(SAXStrings.isEmpty(strD)) {
-        return &quot;&quot;;
-    }
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    return strD.substring(iB, iE).split(strF).join(strR);
-
-}
-
-
-
-/***************************************************************************************************************
-Stack: A simple stack class, used for verifying document structure.
-
-    Author:   Scott Severtson
-*****************************************************************************************************************/
-
-var Stack = function() {
-    this.m_arr = new Array();
-}; 
-__extend__(Stack.prototype, {
-    clear : function() {
-        this.m_arr = new Array();
-    },
-    count : function() {
-        return this.m_arr.length;
-    },
-    destroy : function() {
-        this.m_arr = null;
-    },
-    peek : function() {
-        if(this.m_arr.length == 0) {
-            return null;
-        }
-        return this.m_arr[this.m_arr.length - 1];
-    },
-    pop : function() {
-        if(this.m_arr.length == 0) {
-            return null;
-        }
-        var o = this.m_arr[this.m_arr.length - 1];
-        this.m_arr.length--;
-        return o;
-    },
-    push : function(o) {
-        this.m_arr[this.m_arr.length] = o;
-    }
-});    
-
-
-/**
-* function: isEmpty
-* Author: mike@idle.org
-* Description:  convenience function to identify an empty string
-**/
-function isEmpty(str) {
-    return (str==null) || (str.length==0);
-};
-
-
-/**
- * function __escapeXML__
- * author: David Joham djoham@yahoo.com
- * @param  str : string - The string to be escaped
- * @return : string - The escaped string
- */
-var escAmpRegEx = /&amp;/g;
-var escLtRegEx = /&lt;/g;
-var escGtRegEx = /&gt;/g;
-var quotRegEx = /&quot;/g;
-var aposRegEx = /'/g;
-function __escapeXML__(str) {
-    str = str.replace(escAmpRegEx, &quot;&amp;amp;&quot;).
-            replace(escLtRegEx, &quot;&amp;lt;&quot;).
-            replace(escGtRegEx, &quot;&amp;gt;&quot;).
-            replace(quotRegEx, &quot;&amp;quot;&quot;).
-            replace(aposRegEx, &quot;&amp;apos;&quot;);
-
-    return str;
-};
-
-/**
- * function __unescapeXML__ 
- * author: David Joham djoham@yahoo.com
- * @param  str : string - The string to be unescaped
- * @return : string - The unescaped string
- */
-var unescAmpRegEx = /&amp;amp;/g;
-var unescLtRegEx = /&amp;lt;/g;
-var unescGtRegEx = /&amp;gt;/g;
-var unquotRegEx = /&amp;quot;/g;
-var unaposRegEx = /&amp;apos;/g;
-function __unescapeXML__(str) {
-    str = str.replace(unescAmpRegEx, &quot;&amp;&quot;).
-            replace(unescLtRegEx, &quot;&lt;&quot;).
-            replace(unescGtRegEx, &quot;&gt;&quot;).
-            replace(unquotRegEx, &quot;\&quot;&quot;).
-            replace(unaposRegEx, &quot;'&quot;);
-
-    return str;
-};
-
-//DOMImplementation
-$log(&quot;Defining DOMImplementation&quot;);
-$w.__defineGetter__(&quot;DOMImplementation&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMImplementation - provides a number of methods for performing operations
- *   that are independent of any particular instance of the document object model.
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- */
-var DOMImplementation = function() {
-    this.preserveWhiteSpace = false;  // by default, ignore whitespace
-    this.namespaceAware = true;       // by default, handle namespaces
-    this.errorChecking  = true;       // by default, test for exceptions
-};
-__extend__(DOMImplementation.prototype,{
-    // @param  feature : string - The package name of the feature to test. 
-    //      the legal only values are &quot;XML&quot; and &quot;CORE&quot; (case-insensitive).
-    // @param  version : string - This is the version number of the package
-    //       name to test. In Level 1, this is the string &quot;1.0&quot;.*
-    // @return : boolean
-    hasFeature : function(feature, version) {
-        var ret = false;
-        if (feature.toLowerCase() == &quot;xml&quot;) {
-            ret = (!version || (version == &quot;1.0&quot;) || (version == &quot;2.0&quot;));
-        }
-        else if (feature.toLowerCase() == &quot;core&quot;) {
-            ret = (!version || (version == &quot;2.0&quot;));
-        }
-        return ret;
-    },
-	createDocumentType : function(qname, publicid, systemid){
-		return new DOMDocumentType();
-	},
-	createDocument : function(nsuri, qname, doctype){
-	  //TODO - this currently returns an empty doc
-	  //but needs to handle the args
-		return new HTMLDocument($implementation);
-	},
-    translateErrCode : function(code) {
-        //convert DOMException Code to human readable error message;
-      var msg = &quot;&quot;;
-    
-      switch (code) {
-        case DOMException.INDEX_SIZE_ERR :                // 1
-           msg = &quot;INDEX_SIZE_ERR: Index out of bounds&quot;;
-           break;
-    
-        case DOMException.DOMSTRING_SIZE_ERR :            // 2
-           msg = &quot;DOMSTRING_SIZE_ERR: The resulting string is too long to fit in a DOMString&quot;;
-           break;
-    
-        case DOMException.HIERARCHY_REQUEST_ERR :         // 3
-           msg = &quot;HIERARCHY_REQUEST_ERR: The Node can not be inserted at this location&quot;;
-           break;
-    
-        case DOMException.WRONG_DOCUMENT_ERR :            // 4
-           msg = &quot;WRONG_DOCUMENT_ERR: The source and the destination Documents are not the same&quot;;
-           break;
-    
-        case DOMException.INVALID_CHARACTER_ERR :         // 5
-           msg = &quot;INVALID_CHARACTER_ERR: The string contains an invalid character&quot;;
-           break;
-    
-        case DOMException.NO_DATA_ALLOWED_ERR :           // 6
-           msg = &quot;NO_DATA_ALLOWED_ERR: This Node / NodeList does not support data&quot;;
-           break;
-    
-        case DOMException.NO_MODIFICATION_ALLOWED_ERR :   // 7
-           msg = &quot;NO_MODIFICATION_ALLOWED_ERR: This object cannot be modified&quot;;
-           break;
-    
-        case DOMException.NOT_FOUND_ERR :                 // 8
-           msg = &quot;NOT_FOUND_ERR: The item cannot be found&quot;;
-           break;
-    
-        case DOMException.NOT_SUPPORTED_ERR :             // 9
-           msg = &quot;NOT_SUPPORTED_ERR: This implementation does not support function&quot;;
-           break;
-    
-        case DOMException.INUSE_ATTRIBUTE_ERR :           // 10
-           msg = &quot;INUSE_ATTRIBUTE_ERR: The Attribute has already been assigned to another Element&quot;;
-           break;
-    
-        // Introduced in DOM Level 2:
-        case DOMException.INVALID_STATE_ERR :             // 11
-           msg = &quot;INVALID_STATE_ERR: The object is no longer usable&quot;;
-           break;
-    
-        case DOMException.SYNTAX_ERR :                    // 12
-           msg = &quot;SYNTAX_ERR: Syntax error&quot;;
-           break;
-    
-        case DOMException.INVALID_MODIFICATION_ERR :      // 13
-           msg = &quot;INVALID_MODIFICATION_ERR: Cannot change the type of the object&quot;;
-           break;
-    
-        case DOMException.NAMESPACE_ERR :                 // 14
-           msg = &quot;NAMESPACE_ERR: The namespace declaration is incorrect&quot;;
-           break;
-    
-        case DOMException.INVALID_ACCESS_ERR :            // 15
-           msg = &quot;INVALID_ACCESS_ERR: The object does not support this function&quot;;
-           break;
-    
-        default :
-           msg = &quot;UNKNOWN: Unknown Exception Code (&quot;+ code +&quot;)&quot;;
-      }
-    
-      return msg;
-    }
-});
-  
-
-/**
-* Defined 'globally' to this scope.  Remember everything is wrapped in a closure so this doesnt show up 
-* in the outer most global scope.
-*/
-  
-/**
- *  process SAX events
- *
- * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
- *
- * @param  impl : DOMImplementation
- * @param  doc : DOMDocument - the Document to contain the parsed XML string
- * @param  p   : XMLP        - the SAX Parser
- *
- * @return : DOMDocument
- */
-function __parseLoop__(impl, doc, p) {
-  var iEvt, iNode, iAttr, strName;
-  iNodeParent = doc;
-
-  var el_close_count = 0;
-
-  var entitiesList = new Array();
-  var textNodesList = new Array();
-
-  // if namespaceAware, add default namespace
-  if (impl.namespaceAware) {
-    var iNS = doc.createNamespace(&quot;&quot;); // add the default-default namespace
-    iNS.value = &quot;http://www.w3.org/2000/xmlns/&quot;;
-    doc._namespaces.setNamedItem(iNS);
-  }
-
-  // loop until SAX parser stops emitting events
-  while(true) {
-    // get next event
-    iEvt = p.next();
-
-    if (iEvt == XMLP._ELM_B) {                      // Begin-Element Event
-      var pName = p.getName();                      // get the Element name
-      pName = trim(pName, true, true);              // strip spaces from Element name
-
-      if (!impl.namespaceAware) {
-        iNode = doc.createElement(p.getName());     // create the Element
-
-        // add attributes to Element
-        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
-          strName = p.getAttributeName(i);          // get Attribute name
-          iAttr = iNode.getAttributeNode(strName);  // if Attribute exists, use it
-
-          if(!iAttr) {
-            iAttr = doc.createAttribute(strName);   // otherwise create it
-          }
-
-          iAttr.value = p.getAttributeValue(i);   // set Attribute value
-          iNode.setAttributeNode(iAttr);            // attach Attribute to Element
-        }
-      }
-      else {  // Namespace Aware
-        // create element (with empty namespaceURI,
-        //  resolve after namespace 'attributes' have been parsed)
-        iNode = doc.createElementNS(&quot;&quot;, p.getName());
-
-        // duplicate ParentNode's Namespace definitions
-        iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
-
-        // add attributes to Element
-        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
-          strName = p.getAttributeName(i);          // get Attribute name
-
-          // if attribute is a namespace declaration
-          if (__isNamespaceDeclaration__(strName)) {
-            // parse Namespace Declaration
-            var namespaceDec = __parseNSName__(strName);
-
-            if (strName != &quot;xmlns&quot;) {
-              iNS = doc.createNamespace(strName);   // define namespace
-            }
-            else {
-              iNS = doc.createNamespace(&quot;&quot;);        // redefine default namespace
-            }
-            iNS.value = p.getAttributeValue(i);   // set value = namespaceURI
-
-            iNode._namespaces.setNamedItem(iNS);    // attach namespace to namespace collection
-          }
-          else {  // otherwise, it is a normal attribute
-            iAttr = iNode.getAttributeNode(strName);        // if Attribute exists, use it
-
-            if(!iAttr) {
-              iAttr = doc.createAttributeNS(&quot;&quot;, strName);   // otherwise create it
-            }
-
-            iAttr.value = p.getAttributeValue(i);         // set Attribute value
-            iNode.setAttributeNodeNS(iAttr);                // attach Attribute to Element
-
-            if (__isIdDeclaration__(strName)) {
-              iNode.id = p.getAttributeValue(i);    // cache ID for getElementById()
-            }
-          }
-        }
-
-        // resolve namespaceURIs for this Element
-        if (iNode._namespaces.getNamedItem(iNode.prefix)) {
-          iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
-        }
-
-        //  for this Element's attributes
-        for (var i = 0; i &lt; iNode.attributes.length; i++) {
-          if (iNode.attributes.item(i).prefix != &quot;&quot;) {  // attributes do not have a default namespace
-            if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
-              iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
-            }
-          }
-        }
-      }
-
-      // if this is the Root Element
-      if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
-        iNodeParent.documentElement = iNode;        // register this Element as the Document.documentElement
-      }
-
-      iNodeParent.appendChild(iNode);               // attach Element to parentNode
-      iNodeParent = iNode;                          // descend one level of the DOM Tree
-    }
-
-    else if(iEvt == XMLP._ELM_E) {                  // End-Element Event
-      iNodeParent = iNodeParent.parentNode;         // ascend one level of the DOM Tree
-    }
-
-    else if(iEvt == XMLP._ELM_EMP) {                // Empty Element Event
-      pName = p.getName();                          // get the Element name
-      pName = trim(pName, true, true);              // strip spaces from Element name
-
-      if (!impl.namespaceAware) {
-        iNode = doc.createElement(pName);           // create the Element
-
-        // add attributes to Element
-        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
-          strName = p.getAttributeName(i);          // get Attribute name
-          iAttr = iNode.getAttributeNode(strName);  // if Attribute exists, use it
-
-          if(!iAttr) {
-            iAttr = doc.createAttribute(strName);   // otherwise create it
-          }
-
-          iAttr.value = p.getAttributeValue(i);   // set Attribute value
-          iNode.setAttributeNode(iAttr);            // attach Attribute to Element
-        }
-      }
-      else {  // Namespace Aware
-        // create element (with empty namespaceURI,
-        //  resolve after namespace 'attributes' have been parsed)
-        iNode = doc.createElementNS(&quot;&quot;, p.getName());
-
-        // duplicate ParentNode's Namespace definitions
-        iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
-
-        // add attributes to Element
-        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
-          strName = p.getAttributeName(i);          // get Attribute name
-
-          // if attribute is a namespace declaration
-          if (__isNamespaceDeclaration__(strName)) {
-            // parse Namespace Declaration
-            var namespaceDec = __parseNSName__(strName);
-
-            if (strName != &quot;xmlns&quot;) {
-              iNS = doc.createNamespace(strName);   // define namespace
-            }
-            else {
-              iNS = doc.createNamespace(&quot;&quot;);        // redefine default namespace
-            }
-            iNS.value = p.getAttributeValue(i);   // set value = namespaceURI
-
-            iNode._namespaces.setNamedItem(iNS);    // attach namespace to namespace collection
-          }
-          else {  // otherwise, it is a normal attribute
-            iAttr = iNode.getAttributeNode(strName);        // if Attribute exists, use it
-
-            if(!iAttr) {
-              iAttr = doc.createAttributeNS(&quot;&quot;, strName);   // otherwise create it
-            }
-
-            iAttr.value = p.getAttributeValue(i);         // set Attribute value
-            iNode.setAttributeNodeNS(iAttr);                // attach Attribute to Element
-
-            if (__isIdDeclaration__(strName)) {
-              iNode.id = p.getAttributeValue(i);    // cache ID for getElementById()
-            }
-          }
-        }
-
-        // resolve namespaceURIs for this Element
-        if (iNode._namespaces.getNamedItem(iNode.prefix)) {
-          iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
-        }
-
-        //  for this Element's attributes
-        for (var i = 0; i &lt; iNode.attributes.length; i++) {
-          if (iNode.attributes.item(i).prefix != &quot;&quot;) {  // attributes do not have a default namespace
-            if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
-              iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
-            }
-          }
-        }
-      }
-
-      // if this is the Root Element
-      if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
-        iNodeParent.documentElement = iNode;        // register this Element as the Document.documentElement
-      }
-
-      iNodeParent.appendChild(iNode);               // attach Element to parentNode
-    }
-    else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) {                   // TextNode and entity Events
-      // get Text content
-      var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
-      
-	  if (!impl.preserveWhiteSpace ) {
-		if (trim(pContent, true, true) == &quot;&quot;) {
-			pContent = &quot;&quot;; //this will cause us not to create the text node below
-		}
-	  }
-	  
-      if (pContent.length &gt; 0) {                    // ignore empty TextNodes
-        var textNode = doc.createTextNode(pContent);
-        iNodeParent.appendChild(textNode); // attach TextNode to parentNode
-
-        //the sax parser breaks up text nodes when it finds an entity. For
-        //example hello&amp;lt;there will fire a text, an entity and another text
-        //this sucks for the dom parser because it looks to us in this logic
-        //as three text nodes. I fix this by keeping track of the entity nodes
-        //and when we're done parsing, calling normalize on their parent to
-        //turn the multiple text nodes into one, which is what DOM users expect
-        //the code to do this is at the bottom of this function
-        if (iEvt == XMLP._ENTITY) {
-            entitiesList[entitiesList.length] = textNode;
-        }
-		else {
-			//I can't properly decide how to handle preserve whitespace
-			//until the siblings of the text node are built due to 
-			//the entitiy handling described above. I don't know that this
-			//will be all of the text node or not, so trimming is not appropriate
-			//at this time. Keep a list of all the text nodes for now
-			//and we'll process the preserve whitespace stuff at a later time.
-			textNodesList[textNodesList.length] = textNode;
-		}
-      }
-    }
-    else if(iEvt == XMLP._PI) {                     // ProcessingInstruction Event
-      // attach ProcessingInstruction to parentNode
-      iNodeParent.appendChild(doc.createProcessingInstruction(p.getName(), p.getContent().substring(p.getContentBegin(), p.getContentEnd())));
-    }
-    else if(iEvt == XMLP._CDATA) {                  // CDATA Event
-      // get CDATA data
-      pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
-
-      if (!impl.preserveWhiteSpace) {
-        pContent = trim(pContent, true, true);      // trim whitespace
-        pContent.replace(/ +/g, ' ');               // collapse multiple spaces to 1 space
-      }
-
-      if (pContent.length &gt; 0) {                    // ignore empty CDATANodes
-        iNodeParent.appendChild(doc.createCDATASection(pContent)); // attach CDATA to parentNode
-      }
-    }
-    else if(iEvt == XMLP._COMMENT) {                // Comment Event
-      // get COMMENT data
-      var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
-
-      if (!impl.preserveWhiteSpace) {
-        pContent = trim(pContent, true, true);      // trim whitespace
-        pContent.replace(/ +/g, ' ');               // collapse multiple spaces to 1 space
-      }
-
-      if (pContent.length &gt; 0) {                    // ignore empty CommentNodes
-        iNodeParent.appendChild(doc.createComment(pContent));  // attach Comment to parentNode
-      }
-    }
-    else if(iEvt == XMLP._DTD) {                    // ignore DTD events
-    }
-    else if(iEvt == XMLP._ERROR) {
-      throw(new DOMException(DOMException.SYNTAX_ERR));
-      // alert(&quot;Fatal Error: &quot; + p.getContent() + &quot;\nLine: &quot; + p.getLineNumber() + &quot;\nColumn: &quot; + p.getColumnNumber() + &quot;\n&quot;);
-      // break;
-    }
-    else if(iEvt == XMLP._NONE) {                   // no more events
-      if (iNodeParent == doc) {                     // confirm that we have recursed back up to root
-        break;
-      }
-      else {
-        throw(new DOMException(DOMException.SYNTAX_ERR));  // one or more Tags were not closed properly
-      }
-    }
-  }
-
-  //normalize any entities in the DOM to a single textNode
-  for (var i = 0; i &lt; entitiesList.length; i++) {
-      var entity = entitiesList[i];
-      //its possible (if for example two entities were in the
-      //same domnode, that the normalize on the first entitiy
-      //will remove the parent for the second. Only do normalize
-      //if I can find a parent node
-      var parentNode = entity.parentNode;
-      if (parentNode) {
-          parentNode.normalize();
-		  
-		  //now do whitespace (if necessary)
-		  //it was not done for text nodes that have entities
-		  if(!impl.preserveWhiteSpace) {
-		  		var children = parentNode.childNodes;
-				for ( var j = 0; j &lt; children.length; j++) {
-					var child = children.item(j);
-					if (child.nodeType == DOMNode.TEXT_NODE) {
-						var childData = child.data;
-						childData.replace(/\s/g, ' ');
-						child.data = childData;
-					}
-				}
-		  }
-      }
-  }
-  
-  //do the preserve whitespace processing on the rest of the text nodes
-  //It's possible (due to the processing above) that the node will have been
-  //removed from the tree. Only do whitespace checking if parentNode is not null.
-  //This may duplicate the whitespace processing for some nodes that had entities in them
-  //but there's no way around that
-  if (!impl.preserveWhiteSpace) {
-	for (var i = 0; i &lt; textNodesList.length; i++) {
-		var node = textNodesList[i];
-		if (node.parentNode != null) {
-			var nodeData = node.data;
-			nodeData.replace(/\s/g, ' ');
-			node.data = nodeData;
-		}
-	}
-  
-  }
-};
-
-/**
- * @method DOMImplementation._isNamespaceDeclaration - Return true, if attributeName is a namespace declaration
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  attributeName : string - the attribute name
- * @return : boolean
- */
-function __isNamespaceDeclaration__(attributeName) {
-  // test if attributeName is 'xmlns'
-  return (attributeName.indexOf('xmlns') &gt; -1);
-};
-
-/**
- * @method DOMImplementation._isIdDeclaration - Return true, if attributeName is an id declaration
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  attributeName : string - the attribute name
- * @return : boolean
- */
-function __isIdDeclaration__(attributeName) {
-  // test if attributeName is 'id' (case insensitive)
-  return (attributeName.toLowerCase() == 'id');
-};
-
-/**
- * @method DOMImplementation._isValidName - Return true,
- *   if name contains no invalid characters
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  name : string - the candidate name
- * @return : boolean
- */
-function __isValidName__(name) {
-  // test if name contains only valid characters
-  return name.match(re_validName);
-};
-var re_validName = /^[a-zA-Z_:][a-zA-Z0-9\.\-_:]*$/;
-
-/**
- * @method DOMImplementation._isValidString - Return true, if string does not contain any illegal chars
- *  All of the characters 0 through 31 and character 127 are nonprinting control characters.
- *  With the exception of characters 09, 10, and 13, (Ox09, Ox0A, and Ox0D)
- *  Note: different from _isValidName in that ValidStrings may contain spaces
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  name : string - the candidate string
- * @return : boolean
- */
-function __isValidString__(name) {
-  // test that string does not contains invalid characters
-  return (name.search(re_invalidStringChars) &lt; 0);
-};
-var re_invalidStringChars = /\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0B|\x0C|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E|\x1F|\x7F/;
-
-/**
- * @method DOMImplementation._parseNSName - parse the namespace name.
- *  if there is no colon, the
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  qualifiedName : string - The qualified name
- * @return : NSName - [
-         .prefix        : string - The prefix part of the qname
-         .namespaceName : string - The namespaceURI part of the qname
-    ]
- */
-function __parseNSName__(qualifiedName) {
-  var resultNSName = new Object();
-
-  resultNSName.prefix          = qualifiedName;  // unless the qname has a namespaceName, the prefix is the entire String
-  resultNSName.namespaceName   = &quot;&quot;;
-
-  // split on ':'
-  var delimPos = qualifiedName.indexOf(':');
-  if (delimPos &gt; -1) {
-    // get prefix
-    resultNSName.prefix        = qualifiedName.substring(0, delimPos);
-    // get namespaceName
-    resultNSName.namespaceName = qualifiedName.substring(delimPos +1, qualifiedName.length);
-  }
-  return resultNSName;
-};
-
-/**
- * @method DOMImplementation._parseQName - parse the qualified name
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  qualifiedName : string - The qualified name
- * @return : QName
- */
-function __parseQName__(qualifiedName) {
-  var resultQName = new Object();
-
-  resultQName.localName = qualifiedName;  // unless the qname has a prefix, the local name is the entire String
-  resultQName.prefix    = &quot;&quot;;
-
-  // split on ':'
-  var delimPos = qualifiedName.indexOf(':');
-
-  if (delimPos &gt; -1) {
-    // get prefix
-    resultQName.prefix    = qualifiedName.substring(0, delimPos);
-
-    // get localName
-    resultQName.localName = qualifiedName.substring(delimPos +1, qualifiedName.length);
-  }
-
-  return resultQName;
-};
-
-$log(&quot;Initializing document.implementation&quot;);
-var $implementation =  new DOMImplementation();
-$implementation.namespaceAware = false;
-$implementation.errorChecking = true;$log(&quot;Defining Document&quot;);
-/*
-* Document - DOM Level 2
-*  The Document object is not directly 
-*/
-$w.__defineGetter__('Document', function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-/**
- * @class  DOMDocument - The Document interface represents the entire HTML or XML document.
- *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
- *
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  implementation : DOMImplementation - the creator Implementation
- */
-var DOMDocument = function(implementation) {
-    //$log(&quot;\tcreating dom document&quot;);
-    this.DOMNode = DOMNode;
-    this.DOMNode(this);
-    
-    this.doctype = null;                  // The Document Type Declaration (see DocumentType) associated with this document
-    this.implementation = implementation; // The DOMImplementation object that handles this document.
-    this.documentElement = null;          // This is a convenience attribute that allows direct access to the child node that is the root element of the document
-    //this.all  = new Array();                       // The list of all Elements
-    
-    this.nodeName  = &quot;#document&quot;;
-    this.nodeType = DOMNode.DOCUMENT_NODE;
-    this._id = 0;
-    this._lastId = 0;
-    this._parseComplete = false;                   // initially false, set to true by parser
-    this._url = &quot;&quot;;
-    
-    this.ownerDocument = this;
-    
-    this._performingImportNodeOperation = false;
-    //$log(&quot;\tfinished creating dom document &quot; + this);
-};
-DOMDocument.prototype = new DOMNode;
-__extend__(DOMDocument.prototype, {
-	addEventListener        : window.addEventListener,
-	removeEventListener     : window.removeEventListener,
-    attachEvent             : window.addEventListener,/*IE only subject to deprecation*/
-    detachEvent             : window.detachEvent,/*IE only subject to  deprecation*/
-	dispatchEvent           : window.dispatchEvent,
-    get styleSheets(){ 
-        return [];/*TODO*/ 
-    },
-    get all(){
-        return this.getElementsByTagName(&quot;*&quot;);
-    },
-    loadXML : function(xmlStr) {
-        // create SAX Parser
-        var parser;
-        
-        try {
-            parser = new XMLP(String(xmlStr));
-        }catch (e) {
-            $error(&quot;Error Creating the SAX Parser. \n\n\t&quot;+e+&quot;\n\n\t Did you include xmlsax.js or tinyxmlsax.js\
-                     in your web page?\nThe SAX parser is needed to populate XML for &lt;SCRIPT&gt;'s \
-                     W3C DOM Parser with data.&quot;);
-        }
-        // create DOM Document
-        var doc = new HTMLDocument(this.implementation);
-        // populate Document with Parsed Nodes
-        __parseLoop__(this.implementation, doc, parser);
-        // set parseComplete flag, (Some validation Rules are relaxed if this is false)
-        doc._parseComplete = true;
-        if(this === $document){
-            $log(&quot;Setting internal window.document&quot;);
-            $document = doc;
-        }
-        return doc;
-    },
-    load: function(url){
-		$log(&quot;Loading url into DOM Document: &quot;+ url + &quot; - (Asynch? &quot;+$w.document.async+&quot;)&quot;);
-        var _this = this;
-        var xhr = new XMLHttpRequest();
-        xhr.open(&quot;GET&quot;, url, $w.document.async);
-        xhr.onreadystatechange = function(){
-            try{
-        	    _this.loadXML(xhr.responseText);
-            }catch(e){
-                $error(&quot;Error Parsing XML - &quot;,e);
-                _this.loadXML(
-                &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&quot;+
-                  &quot;&lt;h1&gt;Parse Error&lt;/h1&gt;&quot;+
-                  &quot;&lt;p&gt;&quot;+e.toString()+&quot;&lt;/p&gt;&quot;+  
-                &quot;&lt;/body&gt;&lt;/html&gt;&quot;);
-            }
-            _this._url = url;
-        	$log(&quot;Sucessfully loaded document.&quot;);
-        	var event = document.createEvent();
-        	event.initEvent(&quot;load&quot;);
-        	$w.dispatchEvent( event );
-        };
-        xhr.send();
-    },
-	createEvent             : function(eventType){ 
-        var event;
-        if(eventType === &quot;UIEvents&quot;){ event = new UIEvent();}
-        else if(eventType === &quot;MouseEvents&quot;){ event = new MouseEvent();}
-        else{ event = new Event(); } 
-        return event;
-    },
-    createExpression        : function(xpath, nsuriMap){ 
-        return null;/*TODO*/
-    },
-    createElement : function(tagName) {
-        //$log(&quot;DOMDocument.createElement( &quot;+tagName+&quot; )&quot;);
-          // throw Exception if the tagName string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMElement specifying 'this' as ownerDocument
-          var node = new DOMElement(this);
-        
-          // assign values to properties (and aliases)
-          node.tagName  = tagName;
-          node.nodeName = tagName;
-        
-          // add Element to 'all' collection
-          //this.all[this.all.length] = node;
-          //$log(&quot;Document.all.length &quot; + this.all.length);
-        
-          return node;
-    },
-    createDocumentFragment : function() {
-          // create DOMDocumentFragment specifying 'this' as ownerDocument
-          var node = new DOMDocumentFragment(this);
-        
-          return node;
-    },
-    createTextNode: function(data) {
-          // create DOMText specifying 'this' as ownerDocument
-          var node = new DOMText(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createComment : function(data) {
-          // create DOMComment specifying 'this' as ownerDocument
-          var node = new DOMComment(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createCDATASection : function(data) {
-          // create DOMCDATASection specifying 'this' as ownerDocument
-          var node = new DOMCDATASection(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createProcessingInstruction : function(target, data) {
-          // throw Exception if the target string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(target))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMProcessingInstruction specifying 'this' as ownerDocument
-          var node = new DOMProcessingInstruction(this);
-        
-          // assign values to properties (and aliases)
-          node.target    = target;
-          node.nodeName  = target;
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createAttribute : function(name) {
-          // throw Exception if the name string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(name))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMAttr specifying 'this' as ownerDocument
-          var node = new DOMAttr(this);
-        
-          // assign values to properties (and aliases)
-          node.name     = name;
-          node.nodeName = name;
-        
-          return node;
-    },
-    createElementNS : function(namespaceURI, qualifiedName) {
-        //$log(&quot;DOMDocument.createElement( &quot;+namespaceURI+&quot;, &quot;+qualifiedName+&quot; )&quot;);
-          // test for exceptions
-          if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if the Namespace is invalid
-            if (!__isValidNamespace__(this, namespaceURI, qualifiedName)) {
-              throw(new DOMException(DOMException.NAMESPACE_ERR));
-            }
-        
-            // throw Exception if the qualifiedName string contains an illegal character
-            if (!__isValidName__(qualifiedName)) {
-              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-            }
-          }
-        
-          // create DOMElement specifying 'this' as ownerDocument
-          var node  = new DOMElement(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.namespaceURI = namespaceURI;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.tagName      = qualifiedName;
-        
-          // add Element to 'all' collection
-          //this.all[this.all.length] = node;
-        
-          return node;
-    },
-    createAttributeNS : function(namespaceURI, qualifiedName) {
-          // test for exceptions
-          if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if the Namespace is invalid
-            if (!__isValidNamespace__(this, namespaceURI, qualifiedName, true)) {
-              throw(new DOMException(DOMException.NAMESPACE_ERR));
-            }
-        
-            // throw Exception if the qualifiedName string contains an illegal character
-            if (!__isValidName__(qualifiedName)) {
-              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-            }
-          }
-        
-          // create DOMAttr specifying 'this' as ownerDocument
-          var node  = new DOMAttr(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.namespaceURI = namespaceURI;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.name         = qualifiedName;
-          node.nodeValue    = &quot;&quot;;
-        
-          return node;
-    },
-    createNamespace : function(qualifiedName) {
-          // create DOMNamespace specifying 'this' as ownerDocument
-          var node  = new DOMNamespace(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.name         = qualifiedName;
-          node.nodeValue    = &quot;&quot;;
-        
-          return node;
-    },
-    getElementById : function(elementId) {
-          var retNode = null,
-              node;
-          // loop through all Elements in the 'all' collection
-          var all = this.all;
-          for (var i=0; i &lt; all.length; i++) {
-            node = all[i];
-            // if id matches &amp; node is alive (ie, connected (in)directly to the documentElement)
-            if (node.id == elementId) {
-                if((node.ownerDocument.documentElement._id == this.documentElement._id)){
-                    retNode = node;
-                    //$log(&quot;Found node with id = &quot; + node.id);
-                    break;
-                }
-            }
-          }
-          
-          if(retNode == null){$log(&quot;Couldn't find id &quot; + elementId);}
-          return retNode;
-    },
-    normalizeDocument: function(){
-	    this.documentElement.normalize();
-    },
-    get xml(){
-        return this.documentElement.xml;
-    },
-	toString: function(){ 
-	    return &quot;Document&quot; +  (typeof this._url == &quot;string&quot; ? &quot;: &quot; + this._url : &quot;&quot;); 
-    },
-	get defaultView(){ //TODO: why isnt this just 'return $w;'?
-		return { getComputedStyle: function(elem){
-			return { getPropertyValue: function(prop){
-				prop = prop.replace(/\-(\w)/g,function(m,c){ return c.toUpperCase(); });
-				var val = elem.style[prop];
-				if ( prop == &quot;opacity&quot; &amp;&amp; val == &quot;&quot; ){ val = &quot;1&quot;; }return val;
-			}};
-		}};
-	},
-    _genId : function() {
-          this._lastId += 1;                             // increment lastId (to generate unique id)
-          return this._lastId;
-    }
-});
-
-
-var __isValidNamespace__ = function(doc, namespaceURI, qualifiedName, isAttribute) {
-
-      if (doc._performingImportNodeOperation == true) {
-        //we're doing an importNode operation (or a cloneNode) - in both cases, there
-        //is no need to perform any namespace checking since the nodes have to have been valid
-        //to have gotten into the DOM in the first place
-        return true;
-      }
-    
-      var valid = true;
-      // parse QName
-      var qName = __parseQName__(qualifiedName);
-    
-    
-      //only check for namespaces if we're finished parsing
-      if (this._parseComplete == true) {
-    
-        // if the qualifiedName is malformed
-        if (qName.localName.indexOf(&quot;:&quot;) &gt; -1 ){
-            valid = false;
-        }
-    
-        if ((valid) &amp;&amp; (!isAttribute)) {
-            // if the namespaceURI is not null
-            if (!namespaceURI) {
-            valid = false;
-            }
-        }
-    
-        // if the qualifiedName has a prefix
-        if ((valid) &amp;&amp; (qName.prefix == &quot;&quot;)) {
-            valid = false;
-        }
-    
-      }
-    
-      // if the qualifiedName has a prefix that is &quot;xml&quot; and the namespaceURI is
-      //  different from &quot;http://www.w3.org/XML/1998/namespace&quot; [Namespaces].
-      if ((valid) &amp;&amp; (qName.prefix == &quot;xml&quot;) &amp;&amp; (namespaceURI != &quot;http://www.w3.org/XML/1998/namespace&quot;)) {
-        valid = false;
-      }
-    
-      return valid;
-};
-$log(&quot;Defining HTMLDocument&quot;);
-/*
-* HTMLDocument - DOM Level 2
-*  The Document object is not directly 
-*/
-$w.__defineGetter__(&quot;HTMLDocument&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-/**
- * @class  HTMLDocument - The Document interface represents the entire HTML or XML document.
- *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
- *
- * @extends DOMDocument
- */
-var HTMLDocument = function(implementation) {
-  this.DOMDocument = DOMDocument;
-  this.DOMDocument(implementation);
-
-  this.title = &quot;&quot;;
-  this._refferer = &quot;&quot;;
-  this._domain;
-  this._open = false;
-};
-HTMLDocument.prototype = new DOMDocument;
-__extend__(HTMLDocument.prototype, {
-    createElement: function(tagName){
-        //$log(&quot;HTMLDocument.createElement( &quot;+tagName+&quot; )&quot;);
-        // throw Exception if the tagName string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-          tagName = tagName.toUpperCase();
-          //$log(&quot;HTMLDocument.createElement( &quot;+tagName+&quot; )&quot;);
-          // create DOMElement specifying 'this' as ownerDocument
-          //This is an html document so we need to use explicit interfaces per the 
-          if(     tagName.match(/^A$/))                 {node = new HTMLAnchorElement(this);}
-          else if(tagName.match(/AREA/))                {node = new HTMLAreaElement(this);}
-          else if(tagName.match(/BASE/))                {node = new HTMLBaseElement(this);}
-          else if(tagName.match(/BLOCKQUOTE|Q/))        {node = new HTMLQuoteElement(this);}
-          else if(tagName.match(/BODY/))                {node = new HTMLElement(this);}
-          else if(tagName.match(/BR/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/BUTTON/))              {node = new HTMLButtonElement(this);}
-          else if(tagName.match(/CAPTION/))             {node = new HTMLElement(this);}
-          else if(tagName.match(/COL|COLGROUP/))        {node = new HTMLTableColElement(this);}
-          else if(tagName.match(/DEL|INS/))             {node = new HTMLModElement(this);}
-          else if(tagName.match(/DIV/))                 {node = new HTMLElement(this);}
-          else if(tagName.match(/DL/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/FIELDSET/))            {node = new HTMLFieldSetElement(this);}
-          else if(tagName.match(/FORM/))                {node = new HTMLFormElement(this);}
-          else if(tagName.match(/^FRAME$/))             {node = new HTMLFrameElement(this);}
-          else if(tagName.match(/FRAMESET/))            {node = new HTMLFrameSetElement(this);}
-          else if(tagName.match(/H1|H2|H3|H4|H5|H6/))   {node = new HTMLElement(this);}
-          else if(tagName.match(/HEAD/))                {node = new HTMLHeadElement(this);}
-          else if(tagName.match(/HR/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/HTML/))                {node = new HTMLElement(this);}
-          else if(tagName.match(/IFRAME/))              {node = new HTMLIFrameElement(this);}
-          else if(tagName.match(/IMG/))                 {node = new HTMLImageElement(this);}
-          else if(tagName.match(/INPUT/))               {node = new HTMLInputElement(this);}
-          else if(tagName.match(/LABEL/))               {node = new HTMLLabelElement(this);}
-          else if(tagName.match(/LEGEND/))              {node = new HTMLLegendElement(this);}
-          else if(tagName.match(/^LI$/))                {node = new HTMLElement(this);}
-          else if(tagName.match(/LINK/))                {node = new HTMLLinkElement(this);}
-          else if(tagName.match(/MAP/))                 {node = new HTMLMapElement(this);}
-          else if(tagName.match(/META/))                {node = new HTMLMetaElement(this);}
-          else if(tagName.match(/OBJECT/))              {node = new HTMLObjectElement(this);}
-          else if(tagName.match(/OL/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/OPTGROUP/))            {node = new HTMLOptGroupElement(this);}
-          else if(tagName.match(/OPTION/))              {node = new HTMLOptionElement(this);;}
-          else if(tagName.match(/^P$/))                 {node = new HTMLElement(this);}
-          else if(tagName.match(/PARAM/))               {node = new HTMLParamElement(this);}
-          else if(tagName.match(/PRE/))                 {node = new HTMLElement(this);}
-          else if(tagName.match(/SCRIPT/))              {node = new HTMLScriptElement(this);}
-          else if(tagName.match(/SELECT/))              {node = new HTMLSelectElement(this);}
-          else if(tagName.match(/STYLE/))               {node = new HTMLStyleElement(this);}
-          else if(tagName.match(/TABLE/))               {node = new HTMLElement(this);}
-          else if(tagName.match(/TBODY|TFOOT|THEAD/))   {node = new HTMLElement(this);}
-          else if(tagName.match(/TD|TH/))               {node = new HTMLElement(this);}
-          else if(tagName.match(/TEXTAREA/))            {node = new HTMLElement(this);}
-          else if(tagName.match(/TITLE/))               {node = new HTMLElement(this);}
-          else if(tagName.match(/TR/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/UL/))                  {node = new HTMLElement(this);}
-          else{
-            node = new HTMLElement(this);
-          }
-        
-          // assign values to properties (and aliases)
-          node.tagName  = tagName;
-          node.nodeName = tagName;
-        
-          // add Element to 'all' collection
-          //this.all[this.all.length] = node;
-          //$log(&quot;Document.all.length &quot; + this.all.length);
-          return node;
-    },
-    get anchors(){
-        return new HTMLCollection(this.getElementsByTagName('a'), 'Anchor');
-        
-    },
-    get applets(){
-        return new HTMLCollection(this.getElementsByTagName('applet'), 'Applet');
-        
-    },
-    get body(){ 
-        var nodelist = this.getElementsByTagName('body');
-        return nodelist.item(0);
-        
-    },
-    set body(html){
-        return this.replaceNode(this.body,html);
-        
-    },
-    //set/get cookie see cookie.js
-    get domain(){
-        return this._domain||window.location.domain;
-        
-    },
-    set domain(){
-        /* TODO - requires a bit of thought to enforce domain restrictions */ 
-        return; 
-        
-    },
-    get forms(){
-      $log(&quot;document.forms&quot;);
-      return new HTMLCollection(this.getElementsByTagName('form'), 'Form');
-    },
-    get images(){
-        return new HTMLCollection(this.getElementsByTagName('img'), 'Image');
-        
-    },
-    get lastModified(){ 
-        /* TODO */
-        return this._lastModified; 
-    
-    },
-    get links(){
-        return new HTMLCollection(this.getElementsByTagName('a'), 'Link');
-        
-    },
-    get referrer(){
-        /* TODO */
-        return this._refferer; 
-        
-    },
-    get URL(){
-        /* TODO*/
-        return this._url; 
-        
-    },
-	close : function(){ 
-	    /* TODO */ 
-	    this._open = false;
-    },
-	getElementsByName : function(name){
-        //$debug(&quot;document.getElementsByName ( &quot;+name+&quot; )&quot;);
-        //returns a real Array + the DOMNodeList
-        var retNodes = __extend__([],new DOMNodeList(this, this.documentElement)),
-          node;
-        // loop through all Elements in the 'all' collection
-        var all = this.all;
-        for (var i=0; i &lt; all.length; i++) {
-            node = all[i];
-            if (node.nodeType == DOMNode.ELEMENT_NODE &amp;&amp; node.getAttribute('name') == name) {
-                //$log(&quot;Found node by name &quot; + name);
-                retNodes.push(node);
-            }
-        }
-        return retNodes;
-	},
-	open : function(){ 
-	    /* TODO */
-	    this._open = true;  
-    },
-	write: function(htmlstring){ 
-	    /* TODO */
-	    return; 
-	
-    },
-	writeln: function(htmlstring){ 
-	    this.write(htmlstring+'\n'); 
-    },
-	toString: function(){ 
-	    return &quot;Document&quot; +  (typeof this._url == &quot;string&quot; ? &quot;: &quot; + this._url : &quot;&quot;); 
-    },
-	get innerHTML(){ 
-	    return this.documentElement.outerHTML; 
-	    
-    },
-	get __html__(){
-	    return true;
-	    
-    }
-});
-
-//This is useful as html elements that modify the dom must also run through the new 
-//nodes and determine if they are javascript tags and load it.  This is really the fun 
-//parts! ;)
-function __execScripts__( node ) {
-	if ( node.nodeName == &quot;SCRIPT&quot; ) {
-		if ( !node.getAttribute(&quot;src&quot;) ) {
-			eval.call( window, node.textContent );
-		}
-	} else {
-		var scripts = node.getElementsByTagName(&quot;script&quot;);
-		for ( var i = 0; i &lt; scripts.length; i++ ) {
-			__execScripts__( node );
-		}
-	}
-};$log(&quot;Defining HTMLElement&quot;);
-/*
-* HTMLElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-var HTMLElement = function(ownerDocument) {
-    //$log(&quot;\tcreating html element&quot;);
-    this.DOMElement = DOMElement;
-    this.DOMElement(ownerDocument);
-    //$log(&quot;\nfinished creating html element&quot;);
-    
-    this.$css2props = null;
-};
-HTMLElement.prototype = new DOMElement;
-__extend__(HTMLElement.prototype, {
-		get className() { 
-		    return this.getAttribute(&quot;class&quot;)||&quot;&quot;; 
-		    
-	    },
-		set className(val) { 
-		    return this.setAttribute(&quot;class&quot;,trim(val)); 
-		    
-	    },
-		get dir() { 
-		    return this.getAttribute(&quot;dir&quot;)||&quot;ltr&quot;; 
-		    
-	    },
-		set dir(val) { 
-		    return this.setAttribute(&quot;dir&quot;,val); 
-		    
-	    },
-		get innerHTML(){  
-		    return this.childNodes.xml; 
-		    
-	    },
-		set innerHTML(html){
-		    //$debug(&quot;htmlElement.innerHTML(&quot;+html+&quot;)&quot;);
-		    //Should be replaced with HTMLPARSER usage
-			html = (html?html:&quot;&quot;).replace(/&lt;\/?([A-Z]+)/g, function(m){
-				return m.toLowerCase();
-			}).replace(/&amp;nbsp;/g, &quot; &quot;);
-			var doc = new DOMParser().
-			  parseFromString('&lt;div&gt;'+html+'&lt;/div&gt;');
-            var parent = this.ownerDocument.importNode(doc.documentElement, true);
-            
-			//$log(&quot;\n\nIMPORTED HTML:\n\n&quot;+nodes.xml);
-			while(this.firstChild != null){
-			    //$log('innerHTML - removing child '+ this.firstChild.xml);
-			    this.removeChild( this.firstChild );
-			}
-			while(parent.firstChild != null){
-			    //$log('innerHTML - appending child '+ parent.firstChild.xml);
-			    this.appendChild( parent.removeChild( parent.firstChild ) );
-		    }
-		    //Mark for garbage collection
-		    doc = null;
-		},
-		get lang() { 
-		    return this.getAttribute(&quot;lang&quot;)||&quot;&quot;; 
-		    
-	    },
-		set lang(val) { 
-		    return this.setAttribute(&quot;lang&quot;,val); 
-		    
-	    },
-		get offsetHeight(){
-		    return Number(this.style[&quot;height&quot;].replace(&quot;px&quot;,&quot;&quot;));
-		},
-		get offsetWidth(){
-		    return Number(this.style[&quot;width&quot;].replace(&quot;px&quot;,&quot;&quot;));
-		},
-		offsetLeft: 0,
-		offsetRight: 0,
-		get offsetParent(){
-		    /* TODO */
-		    return;
-	    },
-		set offsetParent(element){
-		    /* TODO */
-		    return;
-	    },
-		scrollHeight: 0,
-		scrollWidth: 0,
-		scrollLeft: 0, 
-		scrollRight: 0,
-		get style(){
-		    if(this.$css2props === null){
-		        $log(&quot;Initializing new css2props for html element : &quot; + this.getAttribute(&quot;style&quot;));
-		        this.$css2props = new CSS2Properties({
-    		        cssText:this.getAttribute(&quot;style&quot;)
-    	        });
-	        }
-	        return this.$css2props
-		},
-		get title() { 
-		    return this.getAttribute(&quot;title&quot;)||&quot;&quot;; 
-		    
-	    },
-		set title(val) { 
-		    return this.setAttribute(&quot;title&quot;,val); 
-		    
-	    },
-		//Not in the specs but I'll leave it here for now.
-		get outerHTML(){ 
-		    return this.xml; 
-		    
-	    },
-	    scrollIntoView: function(){
-	        /*TODO*/
-	        return;
-	    
-        },
-		onclick: function(event){
-		    try{
-		        eval(this.getAttribute('onclick'));
-		    }catch(e){
-		        $error(e);
-	        }
-	    },
-		ondblclick: function(event){
-		    try{
-		        eval(this.getAttribute('ondblclick'));
-		    }catch(e){
-		        $error(e)
-		    }
-	    },
-		onkeydown: function(event){
-		    try{
-		        eval(this.getAttribute('onkeydown'));
-		    }catch(e){
-		        $error(e);
-		    }
-	    },
-		onkeypress: function(event){
-		    try{
-		        eval(this.getAttribute('onkeypress'));
-		    }catch(e){
-		        $error(e);}},
-		onkeyup: function(event){
-		    try{
-		        eval(this.getAttribute('onkeyup'));
-		    }catch(e){
-		        $error(e);}},
-		onmousedown: function(event){
-		    try{
-		        eval(this.getAttribute('onmousedown'));
-		    }catch(e){
-		        $error(e);}},
-		onmousemove: function(event){
-		    try{
-		        eval(this.getAttribute('onmousemove'));
-		    }catch(e){
-		        $error(e);}},
-		onmouseout: function(event){
-		    try{
-		        eval(this.getAttribute('onmouseout'));
-		    }catch(e){
-		        $error(e);}},
-		onmouseover: function(event){
-		    try{
-		        eval(this.getAttribute('onmouseover'));
-		    }catch(e){
-		        $error(e);}},
-		onmouseup: function(event){
-		    try{
-		        eval(this.getAttribute('onmouseup'));
-		    }catch(e){
-		        $error(e);}}
-});
-
-var __registerEventAttrs__ = function(elm){
-    if(elm.hasAttribute('onclick')){ 
-        elm.addEventListener('click', elm.onclick ); 
-    }
-    if(elm.hasAttribute('ondblclick')){ 
-        elm.addEventListener('dblclick', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onkeydown')){ 
-        elm.addEventListener('keydown', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onkeypress')){ 
-        elm.addEventListener('keypress', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onkeyup')){ 
-        elm.addEventListener('keyup', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmousedown')){ 
-        elm.addEventListener('mousedown', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmousemove')){ 
-        elm.addEventListener('mousemove', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmouseout')){ 
-        elm.addEventListener('mouseout', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmouseover')){ 
-        elm.addEventListener('mouseover', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmouseup')){ 
-        elm.addEventListener('mouseup', elm.onclick ); 
-    }
-    return elm;
-};
-	
-var __click__ = function(element){
-	var event = new Event({
-	  target:element,
-	  currentTarget:element
-	});
-	event.initEvent(&quot;click&quot;);
-	element.dispatchEvent(event);
-};
-var __submit__ = function(element){
-	var event = new Event({
-	  target:element,
-	  currentTarget:element
-	});
-	event.initEvent(&quot;submit&quot;);
-	element.dispatchEvent(event);
-};
-var __focus__ = function(element){
-	var event = new Event({
-	  target:element,
-	  currentTarget:element
-	});
-	event.initEvent(&quot;focus&quot;);
-	element.dispatchEvent(event);
-};
-var __blur__ = function(element){
-	var event = new Event({
-	  target:element,
-	  currentTarget:element
-	});
-	event.initEvent(&quot;blur&quot;);
-	element.dispatchEvent(event);
-};
-$log(&quot;Defining HTMLCollection&quot;);
-/*
-* HTMLCollection - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLCollection&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/*var HTMLCollection = function(nodelist, type){
-  var $items = [], 
-      $item, i;
-  if(type === &quot;Anchor&quot; ){
-    for(i=0;i&lt;nodelist.length;i++){ 
-      //The name property is required to be add to the collection
-      if(nodelist.item(i).name){
-        item = new nodelist.item(i);
-        $items.push(item);
-        this[nodelist.item(i).name] = item;
-      }
-    }
-  }else if(type === &quot;Link&quot;){
-    for(i=0;i&lt;nodelist.length;i++){ 
-      //The name property is required to be add to the collection
-      if(nodelist.item(i).href){
-        item = new nodelist.item(i);
-        $items.push(item);
-        this[nodelist.item(i).name] = item;
-      }
-    }
-  }else if(type === &quot;Form&quot;){
-    for(i=0;i&lt;nodelist.length;i++){ 
-      //The name property is required to be add to the collection
-      if(nodelist.item(i).href){
-        item = new nodelist.item(i);
-        $items.push(item);
-        this[nodelist.item(i).name] = item;
-      }
-    }
-  }
-  setArray(this, $items);
-  return __extend__(this, {
-    item : function(i){return this[i];},
-    namedItem : function(name){return this[name];}
-  });
-};*/
-
-	$log(&quot;Defining HTMLAnchorElement&quot;);
-/* 
-* HTMLAnchorElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLAnchorElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLAnchorElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLAnchorElement.prototype = new HTMLElement;
-__extend__(HTMLAnchorElement.prototype, {
-	get accessKey() { 
-	    return this.getAttribute(&quot;accesskey&quot;) || &quot;&quot;; 
-	    
-    },
-	set accessKey(val) { 
-	    return this.setAttribute(&quot;accesskey&quot;,val); 
-	    
-    },
-	get charset() { 
-	    return this.getAttribute(&quot;charset&quot;) || &quot;&quot;; 
-	    
-    },
-	set charset(val) { 
-	    return this.setAttribute(&quot;charset&quot;,val); 
-	    
-    },
-	get coords() { 
-	    return this.getAttribute(&quot;coords&quot;) || &quot;&quot;; 
-	    
-    },
-	set coords(val) { 
-	    return this.setAttribute(&quot;coords&quot;,val); 
-	    
-    },
-	get href() { 
-	    return this.getAttribute(&quot;href&quot;) || &quot;&quot;; 
-	    
-    },
-	set href(val) { 
-	    return this.setAttribute(&quot;href&quot;,val); 
-	    
-    },
-	get hreflang() { 
-	    return this.getAttribute(&quot;hreflang&quot;) || &quot;&quot;; 
-	    
-    },
-	set hreflang(val) { 
-	    return this.setAttribute(&quot;hreflang&quot;,val); 
-	    
-    },
-	get name() { 
-	    return this.getAttribute(&quot;name&quot;) || &quot;&quot;; 
-	    
-    },
-	set name(val) { 
-	    return this.setAttribute(&quot;name&quot;,val); 
-	    
-    },
-	get rel() { 
-	    return this.getAttribute(&quot;rel&quot;) || &quot;&quot;; 
-	    
-    },
-	set rel(val) { 
-	    return this.setAttribute(&quot;rel&quot;,val); 
-	    
-    },
-	get rev() { 
-	    return this.getAttribute(&quot;rev&quot;) || &quot;&quot;; 
-	    
-    },
-	set rev(val) { 
-	    return this.setAttribute(&quot;rev&quot;,val); 
-	    
-    },
-	get shape() { 
-	    return this.getAttribute(&quot;shape&quot;) || &quot;&quot;; 
-	    
-    },
-	set shape(val) { 
-	    return this.setAttribute(&quot;shape&quot;,val); 
-	    
-    },
-	get tabIndex() { 
-	    return this.getAttribute(&quot;tabindex&quot;) || &quot;&quot;; 
-	    
-    },
-	set tabIndex(val) { 
-	    return this.setAttribute(&quot;tabindex&quot;,val); 
-	    
-    },
-	get target() { 
-	    return this.getAttribute(&quot;target&quot;) || &quot;&quot;; 
-	    
-    },
-	set target(val) { 
-	    return this.setAttribute(&quot;target&quot;,val); 
-	    
-    },
-	get type() { 
-	    return this.getAttribute(&quot;type&quot;) || &quot;&quot;; 
-	    
-    },
-	set type(val) { 
-	    return this.setAttribute(&quot;type&quot;,val); 
-	    
-    },
-	blur:function(){
-	    __blur__(this);
-	    
-    },
-	focus:function(){
-	    __focus__(this);
-	    
-    }
-});
-
-			$log(&quot;Defining Anchor&quot;);
-/* 
-* Anchor - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Anchor&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var Anchor = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLAnchorElement = HTMLAnchorElement;
-    this.HTMLAnchorElement(ownerDocument);
-};
-Anchor.prototype = new Anchor;
-
-(function(){
-    //static regular expressions
-	var hash 	 = new RegExp('(\\#.*)'),
-        hostname = new RegExp('\/\/([^\:\/]+)'),
-        pathname = new RegExp('(\/[^\\?\\#]*)'),
-        port 	 = new RegExp('\:(\\d+)\/'),
-        protocol = new RegExp('(^\\w*\:)'),
-        search 	 = new RegExp('(\\?[^\\#]*)');
-			
-    __extend__(Anchor.prototype, {
-		get hash(){
-			var m = hash.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set hash(_hash){
-			//setting the hash is the only property of the location object
-			//that doesn't cause the window to reload
-			_hash = _hash.indexOf('#')===0?_hash:&quot;#&quot;+_hash;	
-			this.href = this.protocol + this.host + this.pathname + this.search + _hash;
-		},
-		get host(){
-			return this.hostname + (this.port !== &quot;&quot;)?&quot;:&quot;+this.port:&quot;&quot;;
-		},
-		set host(_host){
-			this.href = this.protocol + _host + this.pathname + this.search + this.hash;
-		},
-		get hostname(){
-			var m = hostname.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set hostname(_hostname){
-			this.href = this.protocol + _hostname + ((this.port===&quot;&quot;)?&quot;&quot;:(&quot;:&quot;+this.port)) +
-			 	 this.pathname + this.search + this.hash;
-		},
-		get pathname(){
-			var m = this.href;
-			m = pathname.exec(m.substring(m.indexOf(this.hostname)));
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;/&quot;;
-		},
-		set pathname(_pathname){
-			this.href = this.protocol + this.host + _pathname + 
-				this.search + this.hash;
-		},
-		get port(){
-			var m = port.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set port(_port){
-			this.href = this.protocol + this.hostname + &quot;:&quot;+_port + this.pathname + 
-				this.search + this.hash;
-		},
-		get protocol(){
-			return protocol.exec(this.href)[0];
-		},
-		set protocol(_protocol){
-			this.href = _protocol + this.host + this.pathname + 
-				this.search + this.hash;
-		},
-		get search(){
-			var m = search.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set search(_search){
-			this.href = this.protocol + this.host + this.pathname + 
-				_search + this.hash;
-		}
-  });
-
-})();
-			$log(&quot;Defining HTMLAreaElement&quot;);
-/* 
-* HTMLAreaElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLAreaElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLAreaElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLAreaElement.prototype = new HTMLElement;
-__extend__(HTMLAreaElement.prototype, {
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    },
-    get alt(){
-        return this.getAttribute('alt');
-    },
-    set alt(value){
-        this.setAttribute('alt',value);
-    },
-    get coords(){
-        return this.getAttribute('coords');
-    },
-    set coords(value){
-        this.setAttribute('coords',value);
-    },
-    get href(){
-        return this.getAttribute('href');
-    },
-    set href(value){
-        this.setAttribute('href',value);
-    },
-    get noHref(){
-        return this.hasAttribute('href');
-    },
-    get shape(){
-        //TODO
-        return 0;
-    },
-    get tabIndex(){
-        return this.getAttribute('tabindex');
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',value);
-    },
-    get target(){
-        return this.getAttribute('target');
-    },
-    set target(value){
-        this.setAttribute('target',value);
-    }
-});
-
-			$log(&quot;Defining HTMLBaseElement&quot;);
-/* 
-* HTMLBaseElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLBaseElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLBaseElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLBaseElement.prototype = new HTMLElement;
-__extend__(HTMLBaseElement.prototype, {
-    get href(){
-        return this.getAttribute('href');
-    },
-    set href(value){
-        this.setAttribute('href',value);
-    },
-    get target(){
-        return this.getAttribute('target');
-    },
-    set target(value){
-        this.setAttribute('target',value);
-    }
-});
-
-			$log(&quot;Defining HTMLQuoteElement&quot;);
-/* 
-* HTMLQuoteElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLQuoteElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLQuoteElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLQuoteElement.prototype = new HTMLElement;
-__extend__(HTMLQuoteElement.prototype, {
-    get cite(){
-        return this.getAttribute('cite');
-    },
-    set cite(value){
-        this.setAttribute('cite',value);
-    }
-});
-
-			$log(&quot;Defining HTMLButtonElement&quot;);
-/* 
-* HTMLButtonElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLButtonElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLButtonElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLButtonElement.prototype = new HTMLElement;
-__extend__(HTMLButtonElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    },
-    get tabIndex(){
-        return Number(this.getAttribute('tabindex'));
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',Number(value));
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-    get value(){
-        return this.getAttribute('value');
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    }
-});
-
-			$log(&quot;Defining HTMLTableColElement&quot;);
-/* 
-* HTMLTableColElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLTableColElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLTableColElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLTableColElement.prototype = new HTMLElement;
-__extend__(HTMLTableColElement.prototype, {
-    get align(){
-        return this.getAttribute('align');
-    },
-    set align(value){
-        this.setAttribute('align', value);
-    },
-    get ch(){
-        return this.getAttribute('ch');
-    },
-    set ch(value){
-        this.setAttribute('ch', value);
-    },
-    get chOff(){
-        return this.getAttribute('ch');
-    },
-    set chOff(value){
-        this.setAttribute('ch', value);
-    },
-    get span(){
-        return this.getAttribute('span');
-    },
-    set span(value){
-        this.setAttribute('span', value);
-    },
-    get vAlign(){
-        return this.getAttribute('valign');
-    },
-    set vAlign(value){
-        this.setAttribute('valign', value);
-    },
-    get width(){
-        return this.getAttribute('width');
-    },
-    set width(value){
-        this.setAttribute('width', value);
-    }
-});
-
-			$log(&quot;Defining HTMLModElement&quot;);
-/* 
-* HTMLModElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLModElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLModElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLModElement.prototype = new HTMLElement;
-__extend__(HTMLModElement.prototype, {
-    get cite(){
-        return this.getAttribute('cite');
-    },
-    set cite(value){
-        this.setAttribute('cite', value);
-    },
-    get dateTime(){
-        return this.getAttribute('datetime');
-    },
-    set dateTime(value){
-        this.setAttribute('datetime', value);
-    }
-});
-
-			$log(&quot;Defining HTMLFieldSetElement&quot;);
-/* 
-* HTMLFieldSetElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLFieldSetElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLFieldSetElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLFieldSetElement.prototype = new HTMLElement;
-__extend__(HTMLFieldSetElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    }
-});
-
-			$log(&quot;Defining HTMLFormElement&quot;);
-/* 
-* HTMLAnchorElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Form&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-$w.__defineGetter__(&quot;HTMLFormElement&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var HTMLFormElement = function(ownerDocument){
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLFormElement.prototype = new HTMLElement;
-__extend__(HTMLFormElement.prototype,{
-    get acceptCharset(){ 
-        return this.getAttribute('accept-charset');
-        
-    },
-    set acceptCharset(acceptCharset){
-        this.setAttribute('accept-charset', acceptCharset);
-        
-    },
-    get action(){
-        return this.getAttribute('action');
-        
-    },
-    set action(action){
-        this.setAttribute('action', action);
-        
-    },
-    get elements() {
-        return this.getElementsByTagName(&quot;*&quot;);
-        
-    },
-    get enctype(){
-        return this.getAttribute('enctype');
-        
-    },
-    set enctype(enctype){
-        this.setAttribute('enctype', enctype);
-        
-    },
-    get length() {
-        return this.elements.length;
-        
-    },
-    get method(){
-        return this.getAttribute('method');
-        
-    },
-    set method(action){
-        this.setAttribute('method', method);
-        
-    },
-	get name() {
-	    return this.getAttribute(&quot;name&quot;) || &quot;&quot;; 
-	    
-    },
-	set name(val) { 
-	    return this.setAttribute(&quot;name&quot;,val); 
-	    
-    },
-	get target() { 
-	    return this.getAttribute(&quot;target&quot;) || &quot;&quot;; 
-	    
-    },
-	set target(val) { 
-	    return this.setAttribute(&quot;target&quot;,val); 
-	    
-    },
-	submit:function(){
-	    __submit__(this);
-	    
-    },
-	reset:function(){
-	    __reset__(this);
-	    
-    }
-});
-
-			$log(&quot;Defining HTMLFrameElement&quot;);
-/* 
-* HTMLFrameElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLFrameElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLFrameElement = function(ownerDocument) {
-    //$log(&quot;creating frame element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLFrameElement.prototype = new HTMLElement;
-__extend__(HTMLFrameElement.prototype, {
-    get frameBorder(){
-        return this.getAttribute('border')||&quot;&quot;;
-    },
-    set frameBorder(value){
-        this.setAttribute('border', value);
-    },
-    get longDesc(){
-        return this.getAttribute('longdesc')||&quot;&quot;;
-    },
-    set longDesc(value){
-        this.setAttribute('longdesc', value);
-    },
-    get marginHeight(){
-        return this.getAttribute('marginheight')||&quot;&quot;;
-    },
-    set marginHeight(value){
-        this.setAttribute('marginheight', value);
-    },
-    get marginWidth(){
-        return this.getAttribute('marginwidth')||&quot;&quot;;
-    },
-    set marginWidth(value){
-        this.setAttribute('marginwidth', value);
-    },
-    get name(){
-        return this.getAttribute('name')||&quot;&quot;;
-    },
-    set name(value){
-        this.setAttribute('name', value);
-    },
-    get noResize(){
-        return this.getAttribute('noresize')||&quot;&quot;;
-    },
-    set noResize(value){
-        this.setAttribute('noresize', value);
-    },
-    get scrolling(){
-        return this.getAttribute('scrolling')||&quot;&quot;;
-    },
-    set scrolling(value){
-        this.setAttribute('scrolling', value);
-    },
-    get src(){
-        return this.getAttribute('src')||&quot;&quot;;
-    },
-    set src(value){
-        this.setAttribute('src', value);
-    },
-    get contentDocument(){
-        $log(&quot;getting content document for (i)frame&quot;);
-        if(!this._content){
-            this._content = new HTMLDocument($implementation);
-            if(this.src.length &gt; 0){
-                $log(&quot;Loading frame content from &quot; + this.src);
-                try{
-                    this._content.load(this.src);
-                }catch(e){
-                    $error(&quot;failed to load &quot; + this.src);
-                }
-            }
-        }
-        return true;
-    }
-});
-
-			$log(&quot;Defining HTMLFrameSetElement&quot;);
-/* 
-* HTMLFrameSetElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLFrameSetElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLFrameSetElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLFrameSetElement.prototype = new HTMLElement;
-__extend__(HTMLFrameSetElement.prototype, {
-    get cols(){
-        return this.getAttribute('cols');
-    },
-    set cols(value){
-        this.setAttribute('cols', value);
-    },
-    get rows(){
-        return this.getAttribute('rows');
-    },
-    set rows(value){
-        this.setAttribute('rows', value);
-    }
-});
-
-			$log(&quot;Defining HTMLHeadElement&quot;);
-/* 
-* HTMLHeadElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLHeadElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLHeadElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLHeadElement.prototype = new HTMLElement;
-__extend__(HTMLHeadElement.prototype, {
-    get profile(){
-        return this.getAttribute('profile');
-    },
-    set profile(value){
-        this.setAttribute('profile', value);
-    },
-});
-
-			$log(&quot;Defining HTMLIFrameElement&quot;);
-/* 
-* HTMLIFrameElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLIFrameElement&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var HTMLIFrameElement = function(ownerDocument) {
-    //$log(&quot;creating iframe element&quot;);
-    this.HTMLFrameElement = HTMLFrameElement;
-    this.HTMLFrameElement(ownerDocument);
-};
-HTMLIFrameElement.prototype = new HTMLFrameElement;
-__extend__(HTMLIFrameElement.prototype, {
-	get height() { 
-	    return this.getAttribute(&quot;height&quot;) || &quot;&quot;; 
-    },
-	set height(val) { 
-	    return this.setAttribute(&quot;height&quot;,val); 
-    },
-	get width() { 
-	    return this.getAttribute(&quot;width&quot;) || &quot;&quot;; 
-    },
-	set width(val) { 
-	    return this.setAttribute(&quot;width&quot;,val); 
-    }
-});
-
-
-			$log(&quot;Defining HTMLImageElement&quot;);
-/* 
-* HTMLImageElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLImageElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLImageElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLImageElement.prototype = new HTMLElement;
-__extend__(HTMLImageElement.prototype, {
-    get alt(){
-        return this.getAttribute('alt');
-    },
-    set alt(value){
-        this.setAttribute('alt', value);
-    },
-    get height(){
-        return this.getAttribute('height');
-    },
-    set height(value){
-        this.setAttribute('height', value);
-    },
-    get isMap(){
-        return this.hasAttribute('map');
-    },
-    set useMap(value){
-        this.setAttribute('map', value);
-    },
-    get longDesc(){
-        return this.getAttribute('longdesc');
-    },
-    set longDesc(value){
-        this.setAttribute('longdesc', value);
-    },
-    get name(){
-        return this.getAttribute('name');
-    },
-    set name(value){
-        this.setAttribute('name', value);
-    },
-    get src(){
-        return this.getAttribute('src');
-    },
-    set src(value){
-        this.setAttribute('src', value);
-    },
-    get width(){
-        return this.getAttribute('width');
-    },
-    set width(value){
-        this.setAttribute('width', value);
-    }
-});
-
-			$log(&quot;Defining HTMLInputElement&quot;);
-/* 
-* HTMLInputElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLInputElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLInputElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLInputElement.prototype = new HTMLElement;
-__extend__(HTMLInputElement.prototype, {
-    get defaultValue(){
-        return this.getAttribute('defaultValue');
-    },
-    set defaultValue(value){
-        this.setAttribute('defaultValue', value);
-    },
-    get defaultChecked(){
-        return this.getAttribute('defaultChecked');
-    },
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    },
-    get access(){
-        return this.getAttribute('access');
-    },
-    set access(value){
-        this.setAttribute('access', value);
-    },
-    get alt(){
-        return this.getAttribute('alt');
-    },
-    set alt(value){
-        this.setAttribute('alt', value);
-    },
-    get checked(){
-        return (this.getAttribute('checked')==='checked');
-    },
-    set checked(){
-        this.setAttribute('checked', 'checked');
-    },
-    get disabled(){
-        return (this.getAttribute('disabled')==='disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled', 'disabled');
-    },
-    get maxLength(){
-        return Number(this.getAttribute('maxlength')||'0');
-    },
-    set maxLength(value){
-        this.setAttribute('maxlength', value);
-    },
-    get name(){
-        return this.getAttribute('name')||'';
-    },
-    set name(value){
-        this.setAttribute('name', value);
-    },
-    get readOnly(){
-        return (this.getAttribute('readonly')==='readonly');
-    },
-    set readOnly(value){
-        this.setAttribute('readonly', 'readonly');
-    },
-    get size(){
-        return this.getAttribute('size');
-    },
-    set size(value){
-        this.setAttribute('size', value);
-    },
-    get src(){
-        return this.getAttribute('src');
-    },
-    set src(value){
-        this.setAttribute('src', value);
-    },
-    get tabIndex(){
-        return Number(this.getAttribute('tabindex'));
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',Number(value));
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-    get useMap(){
-        return this.getAttribute('map');
-    },
-    get value(){
-        return this.getAttribute('value');
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    },
-	blur:function(){
-	    __blur__(this);
-	    
-    },
-	focus:function(){
-	    __focus__(this);
-	    
-    },
-	select:function(){
-	    __select__(this);
-	    
-    },
-	click:function(){
-	    __click__(this);
-	    
-    }
-});
-
-			$log(&quot;Defining HTMLLabelElement&quot;);
-/* 
-* HTMLLabelElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLLabelElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLLabelElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLLabelElement.prototype = new HTMLElement;
-__extend__(HTMLLabelElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    },
-    get htmlFor(){
-        return this.getAttribute('for');
-    },
-    set htmlFor(value){
-        this.setAttribute('for',value);
-    },
-});
-
-			$log(&quot;Defining HTMLLegendElement&quot;);
-/* 
-* HTMLLegendElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLLegendElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLLegendElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLLegendElement.prototype = new HTMLElement;
-__extend__(HTMLLegendElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    }
-});
-
-			/**
-* Link - HTMLElement 
-*/
-$w.__defineGetter__(&quot;Link&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-$log(&quot;Defining HTMLLinkElement&quot;);
-/* 
-* HTMLLinkElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLLinkElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLLinkElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLLinkElement.prototype = new HTMLElement;
-__extend__(HTMLLinkElement.prototype, {
-    get disabled(){
-        return this.getAttribute('disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled',value);
-    },
-    get charset(){
-        return this.getAttribute('charset');
-    },
-    set charset(value){
-        this.setAttribute('charset',value);
-    },
-    get href(){
-        return this.getAttribute('href');
-    },
-    set href(value){
-        this.setAttribute('href',value);
-    },
-    get hreflang(){
-        return this.getAttribute('hreflang');
-    },
-    set hreflang(value){
-        this.setAttribute('hreflang',value);
-    },
-    get media(){
-        return this.getAttribute('media');
-    },
-    set media(value){
-        this.setAttribute('media',value);
-    },
-    get rel(){
-        return this.getAttribute('rel');
-    },
-    set rel(value){
-        this.setAttribute('rel',value);
-    },
-    get rev(){
-        return this.getAttribute('rev');
-    },
-    set rev(value){
-        this.setAttribute('rev',value);
-    },
-    get target(){
-        return this.getAttribute('target');
-    },
-    set target(value){
-        this.setAttribute('target',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    }
-});
-
-			
-
-			$log(&quot;Defining HTMLMapElement&quot;);
-/* 
-* HTMLMapElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLMapElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLMapElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLMapElement.prototype = new HTMLElement;
-__extend__(HTMLMapElement.prototype, {
-    get areas(){
-        return this.getElementsByTagName('area');
-    },
-    get name(){
-        return this.getAttribute('name');
-    },
-    set name(value){
-        this.setAttribute('name',value);
-    }
-});
-
-			$log(&quot;Defining HTMLMetaElement&quot;);
-/* 
-* HTMLMetaElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLMetaElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLMetaElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLMetaElement.prototype = new HTMLElement;
-__extend__(HTMLMetaElement.prototype, {
-    get content(){
-        return this.getAttribute('content');
-    },
-    set content(value){
-        this.setAttribute('content',value);
-    },
-    get httpEquiv(){
-        return this.getAttribute('http-equiv');
-    },
-    set httpEquiv(value){
-        this.setAttribute('http-equiv',value);
-    },
-    get name(){
-        return this.getAttribute('name');
-    },
-    set name(value){
-        this.setAttribute('name',value);
-    },
-    get scheme(){
-        return this.getAttribute('scheme');
-    },
-    set scheme(value){
-        this.setAttribute('scheme',value);
-    }
-});
-
-			$log(&quot;Defining HTMLObjectElement&quot;);
-/* 
-* HTMLObjectElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLObjectElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLObjectElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLObjectElement.prototype = new HTMLElement;
-__extend__(HTMLObjectElement.prototype, {
-    get code(){
-        return this.getAttribute('code');
-    },
-    set code(value){
-        this.setAttribute('code',value);
-    },
-    get archive(){
-        return this.getAttribute('archive');
-    },
-    set archive(value){
-        this.setAttribute('archive',value);
-    },
-    get codeBase(){
-        return this.getAttribute('codebase');
-    },
-    set codeBase(value){
-        this.setAttribute('codebase',value);
-    },
-    get codeType(){
-        return this.getAttribute('codetype');
-    },
-    set codeType(value){
-        this.setAttribute('codetype',value);
-    },
-    get data(){
-        return this.getAttribute('data');
-    },
-    set data(value){
-        this.setAttribute('data',value);
-    },
-    get declare(){
-        return this.getAttribute('declare');
-    },
-    set declare(value){
-        this.setAttribute('declare',value);
-    },
-    get height(){
-        return this.getAttribute('height');
-    },
-    set height(value){
-        this.setAttribute('height',value);
-    },
-    get standby(){
-        return this.getAttribute('standby');
-    },
-    set standby(value){
-        this.setAttribute('standby',value);
-    },
-    get tabIndex(){
-        return this.getAttribute('tabindex');
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-    get useMap(){
-        return this.getAttribute('usemap');
-    },
-    set useMap(value){
-        this.setAttribute('usemap',value);
-    },
-    get width(){
-        return this.getAttribute('width');
-    },
-    set width(value){
-        this.setAttribute('width',value);
-    },
-    get contentDocument(){
-        return this.ownerDocument;
-    }
-});
-
-			$log(&quot;Defining HTMLOptGroupElement&quot;);
-/* 
-* HTMLOptGroupElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLOptGroupElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLOptGroupElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLOptGroupElement.prototype = new HTMLElement;
-__extend__(HTMLOptGroupElement.prototype, {
-    get disabled(){
-        return this.getAttribute('disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled',value);
-    },
-    get label(){
-        return this.getAttribute('label');
-    },
-    set label(value){
-        this.setAttribute('label',value);
-    },
-});
-
-			$log(&quot;Defining HTMLOptionElement&quot;);
-/* 
-* HTMLOptionElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLOptionElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLOptionElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLOptionElement.prototype = new HTMLElement;
-__extend__(HTMLOptionElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get defaultSelected(){
-        return this.getAttribute('defaultSelected');
-    },
-    set defaultSelected(value){
-        this.setAttribute('defaultSelected',value);
-    },
-    get text(){
-        return this.nodeValue;
-    },
-    get index(){
-        var options = this.parent.childNodes;
-        for(var i; i&lt;options.length;i++){
-            if(this == options[i])
-                return i;
-        }
-        return -1;
-    },
-    get disabled(){
-        return this.getAttribute('disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled',value);
-    },
-    get label(){
-        return this.getAttribute('label');
-    },
-    set label(value){
-        this.setAttribute('label',value);
-    },
-    get selected(){
-        return (this.getAttribute('selected')==='selected');
-    },
-    set selected(){
-        this.setAttribute('selected','selected');
-    },
-    get value(){
-        return this.getAttribute('value');
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    }
-});
-
-			$log(&quot;Defining HTMLParamElement&quot;);
-/* 
-* HTMLParamElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLParamElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLParamElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLParamElement.prototype = new HTMLElement;
-__extend__(HTMLParamElement.prototype, {
-    get name(){
-        return this.getAttribute('name');
-    },
-    set name(value){
-        this.setAttribute('name',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-    get value(){
-        return this.getAttribute('value');
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    },
-    get valueType(){
-        return this.getAttribute('valuetype');
-    },
-    set valueType(value){
-        this.setAttribute('valuetype',value);
-    },
-});
-
-			$log(&quot;Defining HTMLScriptElement&quot;);
-/* 
-* HTMLScriptElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLScriptElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLScriptElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLScriptElement.prototype = new HTMLElement;
-__extend__(HTMLScriptElement.prototype, {
-    get text(){
-        return this.nodeValue;
-    },
-    get htmlFor(){
-        return this.getAttribute('for');
-    },
-    set htmlFor(value){
-        this.setAttribute('for',value);
-    },
-    get event(){
-        return this.getAttribute('event');
-    },
-    set event(value){
-        this.setAttribute('event',value);
-    },
-    get charset(){
-        return this.getAttribute('charset');
-    },
-    set charset(value){
-        this.setAttribute('charset',value);
-    },
-    get defer(){
-        return this.getAttribute('defer');
-    },
-    set defer(value){
-        this.setAttribute('defer',value);
-    },
-    get src(){
-        return this.getAttribute('src');
-    },
-    set src(value){
-        this.setAttribute('src',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    }
-});
-
-			$log(&quot;Defining HTMLSelectElement&quot;);
-/* 
-* HTMLSelectElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLSelectElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLSelectElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLSelectElement.prototype = new HTMLElement;
-__extend__(HTMLSelectElement.prototype, {
-    get type(){
-        return this.getAttribute('type');
-    },
-    get selectedIndex(){
-        var options = this.options;
-        for(var i=0;i&lt;options.length;i++){
-            if(options[i].selected){
-                return i;
-            }
-        };
-        return -1;
-    },
-    set selectedIndex(value){
-        this.options[Number(value)].selected = 'selected';
-    },
-    get value(){
-        return this.getAttribute('value')||'';
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    },
-    get length(){
-        return this.options.length;
-    },
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get options(){
-        return this.getElementsByTagName('option');
-    },
-    get disabled(){
-        return (this.getAttribute('disabled')==='disabled');
-    },
-    set disabled(){
-        this.setAttribute('disabled','disabled');
-    },
-    get multiple(){
-        return this.getAttribute('multiple');
-    },
-    set multiple(value){
-        this.setAttribute('multiple',value);
-    },
-    get name(){
-        return this.getAttribute('name')||'';
-    },
-    set name(value){
-        this.setAttribute('name',value);
-    },
-    get size(){
-        return Number(this.getAttribute('size'));
-    },
-    set size(value){
-        this.setAttribute('size',value);
-    },
-    get tabIndex(){
-        return Number(this.getAttribute('tabindex'));
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',value);
-    },
-    add : function(){
-        __add__(this);
-    },
-    remove : function(){
-        __remove__(this);
-    },
-    blur: function(){
-        __blur__(this);
-    },
-    focus: function(){
-        __focus__(this);
-    }
-});
-
-			$log(&quot;Defining HTMLStyleElement&quot;);
-/* 
-* HTMLStyleElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLStyleElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLStyleElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLStyleElement.prototype = new HTMLElement;
-__extend__(HTMLStyleElement.prototype, {
-    get disabled(){
-        return this.getAttribute('disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled',value);
-    },
-    get media(){
-        return this.getAttribute('media');
-    },
-    set media(value){
-        this.setAttribute('media',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-});
-
-			$log(&quot;Defining Event&quot;);
-/*
-* event.js
-*/
-$w.__defineGetter__(&quot;Event&quot;, function(){
-  __extend__(this,{
-    CAPTURING_PHASE : 1,
-    AT_TARGET       : 2,
-    BUBBLING_PHASE  : 3
-  });
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var Event = function(options){
-  if(options === undefined){options={target:window,currentTarget:window};}
-  __extend__(this,{
-    CAPTURING_PHASE : 1,
-    AT_TARGET       : 2,
-    BUBBLING_PHASE  : 3
-  });
-  $log(&quot;Creating new Event&quot;);
-  var $bubbles = options.bubbles?options.bubbles:true,
-      $cancelable = options.cancelable?options.cancelable:true,
-      $currentTarget = options.currentTarget?options.currentTarget:null,
-      $eventPhase = options.eventPhase?options.eventPhase:Event.CAPTURING_PHASE,
-      $target = options.eventPhase?options.eventPhase:document,
-      $timestamp = options.timestamp?options.timestamp:new Date().getTime().toString(),
-      $type = options.type?options.type:&quot;&quot;;
-  return __extend__(this,{
-    get bubbles(){return $bubbles;},
-    get cancelable(){return $cancelable;},
-    get currentTarget(){return $currentTarget;},
-    get eventPhase(){return $eventPhase;},
-    get target(){return $target;},
-    get timestamp(){return $timestamp;},
-    get type(){return $type;},
-    initEvent: function(type,bubbles,cancelable){
-      $type=type?type:$type;
-      $bubbles=bubbles?bubbles:$bubbles;
-      $cancelable=cancelable?cancelable:$cancelable;
-    },
-    preventDefault: function(){return;/* TODO */},
-    stopPropagation: function(){return;/* TODO */}
-  });
-};
-
-$log(&quot;Defining MouseEvent&quot;);
-/*
-*	mouseevent.js
-*/
-$log(&quot;Defining MouseEvent&quot;);
-/*
-*	uievent.js
-*/
-
-var $onblur,
-    $onfocus,
-    $onresize;/*
-* CSS2Properties - DOM Level 2 CSS
-*/
-$w.__defineGetter__(&quot;CSS2Properties&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-var CSS2Properties = function(options){
-    __extend__(this, __supportedStyles__);
-    __cssTextToStyles__(this, options.cssText?options.cssText:&quot;&quot;);
-};
-//__extend__(CSS2Properties.prototype, __supportedStyles__);
-__extend__(CSS2Properties.prototype, {
-    get cssText(){
-        return Array.prototype.apply.join(this,[';\n']);
-    },
-    set cssText(cssText){ 
-        __cssTextToStyles__(this, cssText); 
-    },
-    getPropertyCSSValue : function(){
-        
-    },
-    getPropertyPriority : function(){
-        
-    },
-    getPropertyValue : function(name){
-		var camelCase = name.replace(/\-(\w)/g, function(all, letter){
-			return letter.toUpperCase();
-		});
-        var i, value = this[camelCase];
-        if(value === undefined){
-            for(i=0;i&lt;this.length;i++){
-                if(this[i]===name){
-                    return this[i];
-                }
-            }
-        }
-        return value;
-    },
-    item : function(index){
-        return this[index];
-    },
-    removeProperty: function(){
-        
-    },
-    setProperty: function(){
-        
-    },
-    toString:function(){
-        if (this.length &gt;0){
-            return &quot;{\n\t&quot;+Array.prototype.join.apply(this,[';\n\t'])+&quot;}\n&quot;;
-        }else{
-            return '';
-        }
-    }
-});
-
-var __cssTextToStyles__ = function(css2props, cssText){
-    var styleArray=[];
-    var style, name, value, camelCaseName, w3cName, styles = cssText.split(';');
-    for ( var i = 0; i &lt; styles.length; i++ ) {
-        //$log(&quot;Adding style property &quot; + styles[i]);
-    	style = styles[i].split(':');
-    	if ( style.length == 2 ){
-    	    //keep a reference to the original name of the style which was set
-    	    //this is the w3c style setting method.
-    	    styleArray[styleArray.length] = w3cName = styles[i];
-            //camel case for dash case
-    	    value = trim(style[1]);
-            camelCaseName = trim(style[0].replace(/\-(\w)/g, function(all, letter){
-				return letter.toUpperCase();
-			}));
-            //$log('CSS Style Name:  ' + camelCaseName);
-            if(css2props[camelCaseName]!==undefined){
-                //set the value internally with camelcase name 
-                //$log('Setting css ' + camelCaseName + ' to ' + value);
-                css2props[camelCaseName] = value;
-            };
-    	}
-    }
-    __setArray__(css2props, styleArray);
-};
-//Obviously these arent all supported but by commenting out various sections
-//this provides a single location to configure what is exposed as supported.
-//These will likely need to be functional getters/setters in the future to deal with
-//the variation on input formulations
-var __supportedStyles__ = {
-    azimuth: &quot;&quot;,
-    background:	&quot;&quot;,
-    backgroundAttachment:	&quot;&quot;,
-    backgroundColor:	&quot;&quot;,
-    backgroundImage:	&quot;&quot;,
-    backgroundPosition:	&quot;&quot;,
-    backgroundRepeat:	&quot;&quot;,
-    border:	&quot;&quot;,
-    borderBottom:	&quot;&quot;,
-    borderBottomColor:	&quot;&quot;,
-    borderBottomStyle:	&quot;&quot;,
-    borderBottomWidth:	&quot;&quot;,
-    borderCollapse:	&quot;&quot;,
-    borderColor:	&quot;&quot;,
-    borderLeft:	&quot;&quot;,
-    borderLeftColor:	&quot;&quot;,
-    borderLeftStyle:	&quot;&quot;,
-    borderLeftWidth:	&quot;&quot;,
-    borderRight:	&quot;&quot;,
-    borderRightColor:	&quot;&quot;,
-    borderRightStyle:	&quot;&quot;,
-    borderRightWidth:	&quot;&quot;,
-    borderSpacing:	&quot;&quot;,
-    borderStyle:	&quot;&quot;,
-    borderTop:	&quot;&quot;,
-    borderTopColor:	&quot;&quot;,
-    borderTopStyle:	&quot;&quot;,
-    borderTopWidth:	&quot;&quot;,
-    borderWidth:	&quot;&quot;,
-    bottom:	&quot;&quot;,
-    captionSide:	&quot;&quot;,
-    clear:	&quot;&quot;,
-    clip:	&quot;&quot;,
-    color:	&quot;&quot;,
-    content:	&quot;&quot;,
-    counterIncrement:	&quot;&quot;,
-    counterReset:	&quot;&quot;,
-    cssFloat:	&quot;&quot;,
-    cue:	&quot;&quot;,
-    cueAfter:	&quot;&quot;,
-    cueBefore:	&quot;&quot;,
-    cursor:	&quot;&quot;,
-    direction:	&quot;&quot;,
-    display:	&quot;&quot;,
-    elevation:	&quot;&quot;,
-    emptyCells:	&quot;&quot;,
-    font:	&quot;&quot;,
-    fontFamily:	&quot;&quot;,
-    fontSize:	&quot;&quot;,
-    fontSizeAdjust:	&quot;&quot;,
-    fontStretch:	&quot;&quot;,
-    fontStyle:	&quot;&quot;,
-    fontVariant:	&quot;&quot;,
-    fontWeight:	&quot;&quot;,
-    height:	&quot;&quot;,
-    left:	&quot;&quot;,
-    letterSpacing:	&quot;&quot;,
-    lineHeight:	&quot;&quot;,
-    listStyle:	&quot;&quot;,
-    listStyleImage:	&quot;&quot;,
-    listStylePosition:	&quot;&quot;,
-    listStyleType:	&quot;&quot;,
-    margin:	&quot;&quot;,
-    marginBottom:	&quot;&quot;,
-    marginLeft:	&quot;&quot;,
-    marginRight:	&quot;&quot;,
-    marginTop:	&quot;&quot;,
-    markerOffset:	&quot;&quot;,
-    marks:	&quot;&quot;,
-    maxHeight:	&quot;&quot;,
-    maxWidth:	&quot;&quot;,
-    minHeight:	&quot;&quot;,
-    minWidth:	&quot;&quot;,
-    opacity:	1,
-    orphans:	&quot;&quot;,
-    outline:	&quot;&quot;,
-    outlineColor:	&quot;&quot;,
-    outlineOffset:	&quot;&quot;,
-    outlineStyle:	&quot;&quot;,
-    outlineWidth:	&quot;&quot;,
-    overflow:	&quot;&quot;,
-    overflowX:	&quot;&quot;,
-    overflowY:	&quot;&quot;,
-    padding:	&quot;&quot;,
-    paddingBottom:	&quot;&quot;,
-    paddingLeft:	&quot;&quot;,
-    paddingRight:	&quot;&quot;,
-    paddingTop:	&quot;&quot;,
-    page:	&quot;&quot;,
-    pageBreakAfter:	&quot;&quot;,
-    pageBreakBefore:	&quot;&quot;,
-    pageBreakInside:	&quot;&quot;,
-    pause:	&quot;&quot;,
-    pauseAfter:	&quot;&quot;,
-    pauseBefore:	&quot;&quot;,
-    pitch:	&quot;&quot;,
-    pitchRange:	&quot;&quot;,
-    position:	&quot;&quot;,
-    quotes:	&quot;&quot;,
-    richness:	&quot;&quot;,
-    right:	&quot;&quot;,
-    size:	&quot;&quot;,
-    speak:	&quot;&quot;,
-    speakHeader:	&quot;&quot;,
-    speakNumeral:	&quot;&quot;,
-    speakPunctuation:	&quot;&quot;,
-    speechRate:	&quot;&quot;,
-    stress:	&quot;&quot;,
-    tableLayout:	&quot;&quot;,
-    textAlign:	&quot;&quot;,
-    textDecoration:	&quot;&quot;,
-    textIndent:	&quot;&quot;,
-    textShadow:	&quot;&quot;,
-    textTransform:	&quot;&quot;,
-    top:	&quot;&quot;,
-    unicodeBidi:	&quot;&quot;,
-    verticalAlign:	&quot;&quot;,
-    visibility:	&quot;&quot;,
-    voiceFamily:	&quot;&quot;,
-    volume:	&quot;&quot;,
-    whiteSpace:	&quot;&quot;,
-    widows:	&quot;&quot;,
-    width:	&quot;&quot;,
-    wordSpacing:	&quot;&quot;,
-    zIndex:	&quot;&quot;
-};/* 
-* CSSRule - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CSSRule&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var CSSRule = function(options){
-  var $style, 
-      $selectorText = options.selectorText?options.selectorText:&quot;&quot;;
-      $style = new CSS2Properties({cssText:options.cssText?options.cssText:null});
-    return __extend__(this, {
-      get style(){return $style;},
-      get selectorText(){return $selectorText;},
-      set selectorText(selectorText){$selectorText = selectorText;}
-    });
-};
-/* 
-* CSSStyleSheet - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CSSStyleSheet&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var CSSStyleSheet = function(options){
-    var $cssRules, 
-        $disabled = options.disabled?options.disabled:false,
-        $href = options.href?options.href:null,
-        $parentStyleSheet = options.parentStyleSheet?options.parentStyleSheet:null,
-        $title = options.title?options.title:&quot;&quot;,
-        $type = &quot;text/css&quot;;
-        
-    function parseStyleSheet(text){
-      //this is pretty ugly, but text is the entire text of a stylesheet
-      var cssRules = [];
-    	if (!text) text = &quot;&quot;;
-    	text = trim(text.replace(/\/\*(\r|\n|.)*\*\//g,&quot;&quot;));
-    	// TODO: @import ?
-    	var blocks = text.split(&quot;}&quot;);
-    	blocks.pop();
-    	var i, len = blocks.length;
-    	var definition_block, properties, selectors;
-    	for (i=0; i&lt;len; i++){
-    		definition_block = blocks[i].split(&quot;{&quot;);
-    		if(definition_block.length === 2){
-      		selectors = definition_block[0].split(&quot;,&quot;);
-      		for(var j=0;j&lt;selectors.length;j++){
-      		  cssRules.push(new CSSRule({
-      		    selectorText:selectors[j],
-      		    cssText:definition_block[1]
-      		  }));
-      		}
-      		__setArray__($cssRules, cssRules);
-    		}
-    	}
-    };
-    parseStyleSheet(options.text);
-    return __extend__(this, {
-      get cssRules(){return $cssRules;},
-      get rule(){return $cssRules;},//IE - may be deprecated
-      get href(){return $href;},
-      get parentStyleSheet(){return $parentStyleSheet;},
-      get title(){return $title;},
-      get type(){return $type;},
-      addRule: function(selector, style, index){/*TODO*/},
-      deleteRule: function(index){/*TODO*/},
-      insertRule: function(rule, index){/*TODO*/},
-      removeRule: function(index){this.deleteRule(index);}//IE - may be deprecated
-    });
-};
-/*
-*	location.js
-*   - requires env
-*/
-$log(&quot;Initializing Window Location.&quot;);
-//the current location
-var $location = $env.location('./');
-
-$w.__defineSetter__(&quot;location&quot;, function(url){
-  //$w.onunload();
-	$w.document.load(url);
-	$location = url;
-	setHistory($location);
-});
-
-$w.__defineGetter__(&quot;location&quot;, function(url){
-	var hash 	 = new RegExp('(\\#.*)'),
-		hostname = new RegExp('\/\/([^\:\/]+)'),
-		pathname = new RegExp('(\/[^\\?\\#]*)'),
-		port 	 = new RegExp('\:(\\d+)\/'),
-		protocol = new RegExp('(^\\w*\:)'),
-		search 	 = new RegExp('(\\?[^\\#]*)');
-	return {
-		get hash(){
-			var m = hash.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set hash(_hash){
-			//setting the hash is the only property of the location object
-			//that doesn't cause the window to reload
-			_hash = _hash.indexOf('#')===0?_hash:&quot;#&quot;+_hash;	
-			$location = this.protocol + this.host + this.pathname + 
-				this.search + _hash;
-			setHistory(_hash, &quot;hash&quot;);
-		},
-		get host(){
-			return this.hostname + (this.port !== &quot;&quot;)?&quot;:&quot;+this.port:&quot;&quot;;
-		},
-		set host(_host){
-			$w.location = this.protocol + _host + this.pathname + 
-				this.search + this.hash;
-		},
-		get hostname(){
-			var m = hostname.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set hostname(_hostname){
-			$w.location = this.protocol + _hostname + ((this.port===&quot;&quot;)?&quot;&quot;:(&quot;:&quot;+this.port)) +
-			 	 this.pathname + this.search + this.hash;
-		},
-		get href(){
-			//This is the only env specific function
-			return $location;
-		},
-		set href(url){
-			$w.location = url;	
-		},
-		get pathname(){
-			var m = this.href;
-			m = pathname.exec(m.substring(m.indexOf(this.hostname)));
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;/&quot;;
-		},
-		set pathname(_pathname){
-			$w.location = this.protocol + this.host + _pathname + 
-				this.search + this.hash;
-		},
-		get port(){
-			var m = port.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set port(_port){
-			$w.location = this.protocol + this.hostname + &quot;:&quot;+_port + this.pathname + 
-				this.search + this.hash;
-		},
-		get protocol(){
-			return protocol.exec(this.href)[0];
-		},
-		set protocol(_protocol){
-			$w.location = _protocol + this.host + this.pathname + 
-				this.search + this.hash;
-		},
-		get search(){
-			var m = search.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set search(_search){
-			$w.location = this.protocol + this.host + this.pathname + 
-				_search + this.hash;
-		},
-		toString: function(){
-			return this.href;
-		},
-		reload: function(force){
-			//TODO
-		},
-		replace: function(url){
-			//TODO
-		}
-	};
-});
-
-/*
-*	history.js
-*/
-
-  $log(&quot;Initializing Window History.&quot;);
-	$currentHistoryIndex = 0;
-	$history = [];
-	
-	// Browser History
-	$w.__defineGetter__(&quot;history&quot;, function(){	
-		return {
-			get length(){ return $history.length; },
-			back : function(count){
-				if(count){
-					go(-count);
-				}else{go(-1);}
-			},
-			forward : function(count){
-				if(count){
-					go(count);
-				}else{go(1);}
-			},
-			go : function(target){
-				if(typeof target == &quot;number&quot;){
-					target = $currentHistoryIndex+target;
-					if(target &gt; -1 &amp;&amp; target &lt; $history.length){
-						if($history[target].location == &quot;hash&quot;){
-							$w.location.hash = $history[target].value;
-						}else{
-							$w.location = $history[target].value;
-						}
-						$currentHistoryIndex = target;
-						//remove the last item added to the history
-						//since we are moving inside the history
-						$history.pop();
-					}
-				}else{
-					//TODO: walk throu the history and find the 'best match'
-				}
-			}
-		};
-	});
-
-	//Here locationPart is the particutlar method/attribute 
-	// of the location object that was modified.  This allows us
-	// to modify the correct portion of the location object
-	// when we navigate the history
-	var setHistory = function( value, locationPart){
-	  $log(&quot;adding value to history: &quot; +value);
-		$currentHistoryIndex++;
-		$history.push({
-			location: locationPart||&quot;href&quot;,
-			value: value
-		});
-	};
-	/*
-*	navigator.js
-*   - requires env
-*/
-$log(&quot;Initializing Window Navigator.&quot;);
-
-var $appCodeName  = &quot;EnvJS&quot;;//eg &quot;Mozilla&quot;
-var $appName      = &quot;Resig/20070309 BirdDog/0.0.0.1&quot;;//eg &quot;Gecko/20070309 Firefox/2.0.0.3&quot;
-
-// Browser Navigator
-$w.__defineGetter__(&quot;navigator&quot;, function(){	
-	return {
-		get appCodeName(){
-			return $appCodeName;
-		},
-		get appName(){
-			return $appName;
-		},
-		get appVersion(){
-			return $version +&quot; (&quot;+ 
-			    $w.navigator.platform +&quot;; &quot;+
-			    &quot;U; &quot;+//?
-			    $env.os_name+&quot; &quot;+$env.os_arch+&quot; &quot;+$env.os_version+&quot;; &quot;+
-			    $env.lang+&quot;; &quot;+
-			    &quot;rv:&quot;+$revision+
-			  &quot;)&quot;;
-		},
-		get cookieEnabled(){
-			return true;
-		},
-		get mimeTypes(){
-			return [];
-		},
-		get platform(){
-			return $env.platform;
-		},
-		get plugins(){
-			return [];
-		},
-		get userAgent(){
-			return $w.navigator.appCodeName + &quot;/&quot; + $w.navigator.appVersion + &quot; &quot; + $w.navigator.appName;
-		},
-		javaEnabled : function(){
-			return $env.javaEnabled;	
-		}
-	};
-});
-
-/*
-*	timer.js
-*/
-	
-
-$log(&quot;Initializing Window Timer.&quot;);
-
-//private
-var $timers = [];
-
-$w.setTimeout = function(fn, time){
-	var num;
-	return num = window.setInterval(function(){
-		fn();
-		window.clearInterval(num);
-	}, time);
-};
-
-window.setInterval = function(fn, time){
-	var num = $timers.length;
-	if(time===0){
-	    fn();
-	}else{
-    	$timers[num] = $env.timer(fn, time);
-    	$timers[num].start();
-	}
-	return num;
-};
-
-window.clearInterval = window.clearTimeout = function(num){
-	if ( $timers[num] ) {
-		$timers[num].stop();
-		delete $timers[num];
-	}
-};	
-	/*
-* event.js
-*/
-// Window Events
-$log(&quot;Initializing Window Event.&quot;);
-var $events = [{}],
-    $onerror,
-    $onload,
-    $onunload;
-
-$w.addEventListener = function(type, fn){
-  $log(&quot;adding event listener &quot; + type);
-	if ( !this.uuid || this == window ) {
-		this.uuid = $events.length;
-		$events[this.uuid] = {};
-	}
-	if ( !$events[this.uuid][type] ){
-		$events[this.uuid][type] = [];
-	}
-	if ( $events[this.uuid][type].indexOf( fn ) &lt; 0 ){
-		$events[this.uuid][type].push( fn );
-	}
-};
-
-$w.removeEventListener = function(type, fn){
-  if ( !this.uuid || this == window ) {
-    this.uuid = $events.length;
-    $events[this.uuid] = {};
-  }
-  if ( !$events[this.uuid][type] ){
-		$events[this.uuid][type] = [];
-	}	
-  $events[this.uuid][type] =
-    $events[this.uuid][type].filter(function(f){
-			return f != fn;
-		});
-};
-$w.dispatchEvent = function(event){
-  if(!event.target)
-    event.target = this;
-  if ( event.type ) {
-    if ( this.uuid &amp;&amp; events[this.uuid][event.type] ) {
-      var self = this;
-      events[this.uuid][event.type].forEach(function(fn){
-        fn.call( self, event );
-    });
-  }
-    
-  if ( this[&quot;on&quot; + event.type] )
-    this[&quot;on&quot; + event.type].call( self, event );
-  }
-  if(this.parentNode){
-    this.parentNode.dispatchEvent.call(this.parentNode,event);
-  }
-};
-$w.dispatchEvent = function(event){
-    $log(&quot;dispatching event &quot; + event.type);
-    //the window scope defines the $event object, for IE(^^^) compatibility;
-    $event = event;
-    if(!event.target)
-        event.target = this;
-    if ( event.type ) {
-        if ( this.uuid &amp;&amp; events[this.uuid][event.type] ) {
-            var _this = this;
-            events[this.uuid][event.type].forEach(function(fn){
-                fn.call( _this, event );
-            });
-        }
-    
-        if ( this[&quot;on&quot; + event.type] )
-            this[&quot;on&quot; + event.type].call( _this, event );
-    }
-    if(this.parentNode){
-        this.parentNode.dispatchEvent.call(this.parentNode,event);
-    }
-};
-	
-$w.__defineGetter__('onerror', function(){
-  return function(){
-   //$w.dispatchEvent('error');
-  };
-});
-
-$w.__defineSetter__('onerror', function(fn){
-  //$w.addEventListener('error', fn);
-});
-
-/*$w.__defineGetter__('onload', function(){
-  return function(){
-		//var event = document.createEvent();
-		//event.initEvent(&quot;load&quot;);
-   //$w.dispatchEvent(event);
-  };
-});
-
-$w.__defineSetter__('onload', function(fn){
-  //$w.addEventListener('load', fn);
-});
-
-$w.__defineGetter__('onunload', function(){
-  return function(){
-   //$w.dispatchEvent('unload');
-  };
-});
-
-$w.__defineSetter__('onunload', function(fn){
-  //$w.addEventListener('unload', fn);
-});*//*
-*	xhr.js
-*/
-$log(&quot;Initializing Window XMLHttpRequest.&quot;);
-// XMLHttpRequest
-// Originally implemented by Yehuda Katz
-$w.XMLHttpRequest = function(){
-	this.headers = {};
-	this.responseHeaders = {};
-};
-
-XMLHttpRequest.prototype = {
-	open: function(method, url, async, user, password){ 
-		this.readyState = 1;
-		if (async === false ){
-			this.async = false;
-		}else{ this.async = true; }
-		this.method = method || &quot;GET&quot;;
-		this.url = $env.location(url);
-		this.onreadystatechange();
-	},
-	setRequestHeader: function(header, value){
-		this.headers[header] = value;
-	},
-	getResponseHeader: function(header){ },
-	send: function(data){
-		var self = this;
-		
-		function makeRequest(){
-			$env.connection(self, function(){
-			  var responseXML = null;
-				self.__defineGetter__(&quot;responseXML&quot;, function(){
-  				if ( self.responseText.match(/^\s*&lt;/) ) {
-  				  if(responseXML){return responseXML;}
-  				  else{
-    					try {
-    					  $log(&quot;parsing response text into xml document&quot;);
-    						responseXML = $domparser.parseFromString(self.responseText);
-  					    return responseXML;
-    					} catch(e) { return null;/*TODO: need to flag an error here*/}
-  					}
-  				}else{return null;}
-  			});
-			});
-			self.onreadystatechange();
-		}
-		if (this.async){
-		  $log(&quot;XHR sending asynch;&quot;);
-			$env.runAsync(makeRequest);
-		}else{
-		  $log(&quot;XHR sending synch;&quot;);
-			makeRequest();
-		}
-	},
-	abort: function(){
-		//TODO
-	},
-	onreadystatechange: function(){
-		//TODO
-	},
-	getResponseHeader: function(header){
-	  var rHeader, returnedHeaders;
-		if (this.readyState &lt; 3){
-			throw new Error(&quot;INVALID_STATE_ERR&quot;);
-		} else {
-			returnedHeaders = [];
-			for (rHeader in this.responseHeaders) {
-				if (rHeader.match(new RegExp(header, &quot;i&quot;)))
-					returnedHeaders.push(this.responseHeaders[rHeader]);
-			}
-			if (returnedHeaders.length){ return returnedHeaders.join(&quot;, &quot;); }
-		}return null;
-	},
-	getAllResponseHeaders: function(){
-	  var header, returnedHeaders = [];
-		if (this.readyState &lt; 3){
-			throw new Error(&quot;INVALID_STATE_ERR&quot;);
-		} else {
-			for (header in this.responseHeaders){
-				returnedHeaders.push( header + &quot;: &quot; + this.responseHeaders[header] );
-			}
-		}return returnedHeaders.join(&quot;\r\n&quot;);
-	},
-	async: true,
-	readyState: 0,
-	responseText: &quot;&quot;,
-	status: 0
-};/*
-*	css.js
-*/
-$log(&quot;Initializing Window CSS&quot;);
-// returns a CSS2Properties object that represents the style
-// attributes and values used to render the specified element in this
-// window.  Any length values are always expressed in pixel, or
-// absolute values.
-$w.getComputedStyle = function(elt, pseudo_elt){
-  //TODO
-  //this is a naive implementation
-  $log(&quot;Getting computed style&quot;);
-  return elt?elt.style:new CSS2Properties({cssText:&quot;&quot;});
-};/*
-*	screen.js
-*/
-$log(&quot;Initializing Window Screen.&quot;);
-
-var $availHeight  = 600,
-    $availWidth   = 800,
-    $colorDepth    = 16,
-    $height       = 600,
-    $width        = 800;
-    
-$w.__defineGetter__(&quot;screen&quot;, function(){
-  return {
-    get availHeight(){return $availHeight;},
-    get availWidth(){return $availWidth;},
-    get colorDepth(){return $colorDepth;},
-    get height(){return $height;},
-    get width(){return $width;}
-  };
-});
-
-
-$w.moveBy = function(dx,dy){
-  //TODO
-};
-
-$w.moveTo = function(x,y) {
-  //TODO
-};
-
-/*$w.print = function(){
-  //TODO
-};*/
-
-$w.resizeBy = function(dw, dh){
-  $w.resizeTo($width+dw,$height+dh);
-};
-
-$w.resizeTo = function(width, height){
-  $width = (width &lt;= $availWidth) ? width : $availWidth;
-  $height = (height &lt;= $availHeight) ? height : $availHeight;
-};
-
-$w.scrollBy = function(dx, dy){
-  //TODO
-};
-$w.scrollTo = function(x,y){
-  //TODO
-};/*
-*	dialog.js
-*/
-$log(&quot;Initializing Window Dialogs.&quot;);
-$w.alert = function(message){
- //TODO 
-};
-
-$w.confirm = function(question){
-  //TODO
-};
-
-$w.prompt = function(message, defaultMsg){
-  //TODO
-};/*
-*	document.js
-*
-*	DOM Level 2 /DOM level 3 (partial)
-*	
-*	This file adds the document object to the window and allows you
-*	you to set the window.document using an html string or dom object.
-*
-*/
-
-// read only reference to the Document object
-
-$log(&quot;Initializing window.document.&quot;);
-var $async = false;
-__extend__(HTMLDocument.prototype, {
-	get async(){ return $async;},
-	set async(async){ $async = async; },
-	get baseURI(){ return $env.location('./'); },
-	get URL(){ return $w.location.href;  }
-});
-	
-
-var $document =  new HTMLDocument($implementation);
-$w.__defineGetter__(&quot;document&quot;, function(){
-	return $document;
-});
-/*
-*	outro.js
-*/
-
-})(window, __env__); 
-
-}catch(e){
-    __env__.error(&quot;ERROR LOADING ENV : &quot; + e + &quot;\nLINE SOURCE:\n&quot; +e.rhinoException.lineSource());
-}
+/*
+ * Pure JavaScript Browser Environment
+ *   By John Resig &lt;http://ejohn.org/&gt;
+ * Copyright 2008 John Resig, under the MIT License
+ */
+ 
+
+// The Window Object
+var __this__ = this;
+this.__defineGetter__('window', function(){
+  return __this__;
+});
+try{
+(function($w, $env){
+        /*
+*	window.js
+*   - this file will be wrapped in a closure providing the window object as $w
+*/
+// a logger or empty function available to all modules.
+var $log = $env.log,
+    $error = $env.error,
+    $debug = $env.debug;
+//The version of this application
+var $version = &quot;0.1&quot;;
+//This should be hooked to git or svn or whatever
+var $revision = &quot;0.0.0.0&quot;;
+
+//These descriptions of window properties are taken loosely David Flanagan's
+//'JavaScript - The Definitive Guide' (O'Reilly)
+
+/**&gt; $cookies - see cookie.js &lt;*/
+// read only boolean specifies whether the window has been closed
+var $closed = false;
+
+// a read/write string that specifies the default message that appears in the status line 
+var $defaultStatus = &quot;Done&quot;;
+
+// a read-only reference to the Document object belonging to this window
+/**&gt; $document - See document.js &lt;*/
+
+//IE only, refers to the most recent event object - this maybe be removed after review
+var $event = null;
+
+//A read-only array of window objects
+var $frames = [];
+
+// a read-only reference to the History object
+/**&gt;  $history - see location.js &lt;**/
+
+// read-only properties that specify the height and width, in pixels
+var $innerHeight = 600, $innerWidth = 800;
+
+// a read-only reference to the Location object.  the location object does expose read/write properties
+/**&gt; $location - see location.js &lt;**/
+
+// a read only property specifying the name of the window.  Can be set when using open()
+// and may be used when specifying the target attribute of links
+var $name = 'Resig Env Browser';
+
+// a read-only reference to the Navigator object
+/**&gt; $navigator - see navigator.js &lt;**/
+
+// a read/write reference to the Window object that contained the script that called open() to 
+//open this browser window.  This property is valid only for top-level window objects.
+var $opener;
+
+// Read-only properties that specify the total height and width, in pixels, of the browser window.
+// These dimensions include the height and width of the menu bar, toolbars, scrollbars, window
+// borders and so on.  These properties are not supported by IE and IE offers no alternative 
+// properties;
+var $outerHeight = $innerHeight, $outerWidth = $innerWidth;
+
+// Read-only properties that specify the number of pixels that the current document has been scrolled
+//to the right and down.  These are not supported by IE.
+var $pageXOffset = 0, $pageYOffest = 0;
+
+//A read-only reference to the Window object that contains this window or frame.  If the window is
+// a top-level window, parent refers to the window itself.  If this window is a frame, this property
+// refers to the window or frame that conatins it.
+var $parent;
+
+// a read-only refernce to the Screen object that specifies information about the screen: 
+// the number of available pixels and the number of available colors.
+/**&gt; $screen - see screen.js &lt;**/
+
+// read only properties that specify the coordinates of the upper-left corner of the screen.
+var $screenX = 0, $screenY = 0;
+var $screenLeft = $screenX, $screenTop = $screenY;
+
+// a read-only refernce to this window itself.
+var $self;
+
+// a read/write string that specifies the current contents of the status line.
+var $status = '';
+
+// a read-only reference to the top-level window that contains this window.  If this
+// window is a top-level window it is simply a refernce to itself.  If this window 
+// is a frame, the top property refers to the top-level window that contains the frame.
+var $top;
+
+// the window property is identical to the self property.
+var $window = $w;
+
+$log(&quot;Initializing Window.&quot;);
+__extend__($w,{
+  get closed(){return $closed;},
+  get defaultStatus(){return $defaultStatus;},
+  set defaultStatus(_defaultStatus){$defaultStatus = _defaultStatus;},
+  //get document(){return $document;}, - see document.js
+  get event(){return $event;},
+  get frames(){return $frames;},
+  //get history(){return $history;}, - see location.js
+  get innerHeight(){return $innerHeight;},
+  get innerWidth(){return $innerWidth;},
+  get clientHeight(){return $innerHeight;},
+  get clientWidth(){return $innerWidth;},
+  //get location(){return $location;}, see location.js
+  get name(){return $name;},
+  //get navigator(){return $navigator;}, see navigator.js
+  get opener(){return $opener;},
+  get outerHeight(){return $outerHeight;},
+  get outerWidth(){return $outerWidth;},
+  get pageXOffest(){return $pageXOffset;},
+  get pageYOffset(){return $pageYOffset;},
+  get parent(){return $parent;},
+  //get screen(){return $screen;}, see screen.js
+  get screenLeft(){return $screenLeft;},
+  get screenTop(){return $screenTop;},
+  get screenX(){return $screenX;},
+  get screenY(){return $screenY;},
+  get self(){return $self;},
+  get status(){return $status;},
+  set status(_status){$status = _status;},
+  get top(){return $top;},
+  get window(){return $window;}
+});
+
+$w.open = function(url, name, features, replace){
+  //TODO
+};
+
+$w.close = function(){
+  //TODO
+};     
+  
+/* Time related functions - see timer.js
+*   - clearTimeout
+*   - clearInterval
+*   - setTimeout
+*   - setInterval
+*/
+
+/*
+* Events related functions - see event.js
+*   - addEventListener
+*   - attachEvent
+*   - detachEvent
+*   - removeEventListener
+*   
+* These functions are identical to the Element equivalents.
+*/
+
+/*
+* UIEvents related functions - see uievent.js
+*   - blur
+*   - focus
+*
+* These functions are identical to the Element equivalents.
+*/
+
+/* Dialog related functions - see dialog.js
+*   - alert
+*   - confirm
+*   - prompt
+*/
+
+/* Screen related functions - see screen.js
+*   - moveBy
+*   - moveTo
+*   - print
+*   - resizeBy
+*   - resizeTo
+*   - scrollBy
+*   - scrollTo
+*/
+
+/* CSS related functions - see css.js
+*   - getComputedStyle
+*/
+
+/*
+* Shared utility methods
+*/
+// Helper method for extending one object with another.  
+function __extend__(a,b) {
+	for ( var i in b ) {
+		var g = b.__lookupGetter__(i), s = b.__lookupSetter__(i);
+		if ( g || s ) {
+			if ( g ) a.__defineGetter__(i, g);
+			if ( s ) a.__defineSetter__(i, s);
+		} else
+			a[i] = b[i];
+	} return a;
+};
+	
+
+// from ariel flesler http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html
+// this might be a good utility function to provide in the env.core
+// as in might be useful to the parser and other areas as well
+function trim( str ){
+    var start = -1,
+    end = str.length;
+    /*jsl:ignore*/
+    while( str.charCodeAt(--end) &lt; 33 );
+    while( str.charCodeAt(++start) &lt; 33 );
+    /*jsl:end*/
+    return str.slice( start, end + 1 );
+};
+
+//from jQuery
+function __setArray__( target, array ) {
+	// Resetting the length to 0, then using the native Array push
+	// is a super-fast way to populate an object with array-like properties
+	target.length = 0;
+	Array.prototype.push.apply( target, array );
+};
+$log(&quot;Defining NodeList&quot;);
+/*
+* NodeList - DOM Level 2
+*/
+$w.__defineGetter__('NodeList', function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+/**
+ * @class  DOMNodeList - provides the abstraction of an ordered collection of nodes
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ *
+ * @param  ownerDocument : DOMDocument - the ownerDocument
+ * @param  parentNode    : DOMNode - the node that the DOMNodeList is attached to (or null)
+ */
+var DOMNodeList = function(ownerDocument, parentNode) {
+    //$log(&quot;\t\tcreating dom nodelist&quot;);
+    var nodes = new Array();
+    
+    this.length = 0;
+    this.parentNode = parentNode;
+    this.ownerDocument = ownerDocument;
+    
+    this._readonly = false;
+    
+    __setArray__(this, nodes);
+    //$log(&quot;\t\tfinished creating dom nodelist&quot;);
+};
+__extend__(DOMNodeList.prototype, {
+    item : function(index) {
+        var ret = null;
+        //$log(&quot;NodeList item(&quot;+index+&quot;) = &quot; + this[index]);
+        if ((index &gt;= 0) &amp;&amp; (index &lt; this.length)) { // bounds check
+            ret = this[index];                    // return selected Node
+        }
+        
+        return ret;                                    // if the index is out of bounds, default value null is returned
+    },
+    get xml() {
+        var ret = &quot;&quot;;
+        
+        // create string containing the concatenation of the string values of each child
+        for (var i=0; i &lt; this.length; i++) {
+            if(this[i].nodeType == DOMNode.TEXT_NODE &amp;&amp; i&gt;0 &amp;&amp; this[i-1].nodeType == DOMNode.TEXT_NODE){
+                //add a single space between adjacent text nodes
+                ret += &quot; &quot;+this[i].xml;
+            }else{
+                ret += this[i].xml;
+            }
+        }
+        
+        return ret;
+    },
+    toString: function(){
+      return &quot;[ &quot;+(this.length &gt; 0?Array.prototype.join.apply(this, [&quot;, &quot;]):&quot;Empty NodeList&quot;)+&quot; ]&quot;;
+    }
+});
+
+
+/**
+ * @method DOMNodeList._findItemIndex - find the item index of the node with the specified internal id
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  id : int - unique internal id
+ * @return : int
+ */
+var __findItemIndex__ = function (nodelist, id) {
+  var ret = -1;
+
+  // test that id is valid
+  if (id &gt; -1) {
+    for (var i=0; i&lt;nodelist.length; i++) {
+      // compare id to each node's _id
+      if (nodelist[i]._id == id) {            // found it!
+        ret = i;
+        break;
+      }
+    }
+  }
+
+  return ret;                                    // if node is not found, default value -1 is returned
+};
+
+/**
+ * @method DOMNodeList._insertBefore - insert the specified Node into the NodeList before the specified index
+ *   Used by DOMNode.insertBefore(). Note: DOMNode.insertBefore() is responsible for Node Pointer surgery
+ *   DOMNodeList._insertBefore() simply modifies the internal data structure (Array).
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  newChild      : DOMNode - the Node to be inserted
+ * @param  refChildIndex : int     - the array index to insert the Node before
+ */
+var __insertBefore__ = function(nodelist, newChild, refChildIndex) {
+    if ((refChildIndex &gt;= 0) &amp;&amp; (refChildIndex &lt; nodelist.length)) { // bounds check
+        
+        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
+            // append the children of DocumentFragment
+            Array.prototype.splice.apply(nodelist,[refChildIndex, 0].concat(newChild.childNodes));
+        }
+        else {
+            // append the newChild
+            Array.prototype.splice.apply(nodelist,[refChildIndex, 0, newChild]);
+        }
+    }
+    //$log(&quot;__insertBefore__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
+};
+
+/**
+ * @method DOMNodeList._replaceChild - replace the specified Node in the NodeList at the specified index
+ *   Used by DOMNode.replaceChild(). Note: DOMNode.replaceChild() is responsible for Node Pointer surgery
+ *   DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  newChild      : DOMNode - the Node to be inserted
+ * @param  refChildIndex : int     - the array index to hold the Node
+ */
+var __replaceChild__ = function(nodelist, newChild, refChildIndex) {
+    var ret = null;
+    
+    if ((refChildIndex &gt;= 0) &amp;&amp; (refChildIndex &lt; nodelist.length)) { // bounds check
+        ret = nodelist[refChildIndex];            // preserve old child for return
+    
+        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
+            // get array containing children prior to refChild
+            Array.prototype.splice.apply(nodelist,[refChildIndex, 1].concat(newChild.childNodes));
+        }
+        else {
+            // simply replace node in array (links between Nodes are made at higher level)
+            nodelist[refChildIndex] = newChild;
+        }
+    }
+    
+    //$log(&quot;__replaceChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
+    return ret;                                   // return replaced node
+};
+
+/**
+ * @method DOMNodeList._removeChild - remove the specified Node in the NodeList at the specified index
+ *   Used by DOMNode.removeChild(). Note: DOMNode.removeChild() is responsible for Node Pointer surgery
+ *   DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  refChildIndex : int - the array index holding the Node to be removed
+ */
+var __removeChild__ = function(nodelist, refChildIndex) {
+    var ret = null;
+    
+    if (refChildIndex &gt; -1) {                              // found it!
+        ret = nodelist[refChildIndex];                    // return removed node
+        
+        // rebuild array without removed child
+        Array.prototype.splice.apply(nodelist,[refChildIndex, 1]);
+    }
+    
+    //$log(&quot;__removeChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
+    return ret;                                   // return removed node
+};
+
+/**
+ * @method DOMNodeList._appendChild - append the specified Node to the NodeList
+ *   Used by DOMNode.appendChild(). Note: DOMNode.appendChild() is responsible for Node Pointer surgery
+ *   DOMNodeList._appendChild() simply modifies the internal data structure (Array).
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  newChild      : DOMNode - the Node to be inserted
+ */
+var __appendChild__ = function(nodelist, newChild) {
+    if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
+        // append the children of DocumentFragment
+        Array.prototype.push.apply(nodelist, newChild.childNodes);
+    } else {
+        // simply add node to array (links between Nodes are made at higher level)
+        Array.prototype.push.apply(nodelist, [newChild]);
+    }
+    
+    //$log(&quot;__appendChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
+};
+
+/**
+ * @method DOMNodeList._cloneNodes - Returns a NodeList containing clones of the Nodes in this NodeList
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  deep : boolean - If true, recursively clone the subtree under each of the nodes;
+ *   if false, clone only the nodes themselves (and their attributes, if it is an Element).
+ * @param  parentNode : DOMNode - the new parent of the cloned NodeList
+ * @return : DOMNodeList - NodeList containing clones of the Nodes in this NodeList
+ */
+var __cloneNodes__ = function(nodelist, deep, parentNode) {
+    var cloneNodeList = new DOMNodeList(nodelist.ownerDocument, parentNode);
+    
+    // create list containing clones of each child
+    for (var i=0; i &lt; nodelist.length; i++) {
+        __appendChild__(cloneNodeList, nodelist[i].cloneNode(deep));
+    }
+    
+    return cloneNodeList;
+};
+
+
+/**
+ * @class  DOMNamedNodeMap - used to represent collections of nodes that can be accessed by name
+ *  typically a set of Element attributes
+ *
+ * @extends DOMNodeList - note W3C spec says that this is not the case,
+ *   but we need an item() method identicle to DOMNodeList's, so why not?
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - the ownerDocument
+ * @param  parentNode    : DOMNode - the node that the DOMNamedNodeMap is attached to (or null)
+ */
+var DOMNamedNodeMap = function(ownerDocument, parentNode) {
+    //$log(&quot;\t\tcreating dom namednodemap&quot;);
+    this.DOMNodeList = DOMNodeList;
+    this.DOMNodeList(ownerDocument, parentNode);
+    __setArray__(this, []);
+};
+DOMNamedNodeMap.prototype = new DOMNodeList;
+__extend__(DOMNamedNodeMap.prototype, {
+    getNamedItem : function(name) {
+        var ret = null;
+        
+        // test that Named Node exists
+        var itemIndex = __findNamedItemIndex__(this, name);
+        
+        if (itemIndex &gt; -1) {                          // found it!
+            ret = this[itemIndex];                // return NamedNode
+        }
+        
+        return ret;                                    // if node is not found, default value null is returned
+    },
+    setNamedItem : function(arg) {
+      // test for exceptions
+      if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if arg was not created by this Document
+            if (this.ownerDocument != arg.ownerDocument) {
+              throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+            }
+        
+            // throw Exception if DOMNamedNodeMap is readonly
+            if (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly)) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+        
+            // throw Exception if arg is already an attribute of another Element object
+            if (arg.ownerElement &amp;&amp; (arg.ownerElement != this.parentNode)) {
+              throw(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR));
+            }
+      }
+    
+      // get item index
+      var itemIndex = __findNamedItemIndex__(this, arg.name);
+      var ret = null;
+    
+      if (itemIndex &gt; -1) {                          // found it!
+            ret = this[itemIndex];                // use existing Attribute
+        
+            // throw Exception if DOMAttr is readonly
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ret._readonly) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            } else {
+              this[itemIndex] = arg;                // over-write existing NamedNode
+            }
+      } else {
+            // add new NamedNode
+            Array.prototype.push.apply(this, [arg]);
+      }
+    
+      arg.ownerElement = this.parentNode;            // update ownerElement
+    
+      return ret;                                    // return old node or null
+    },
+    removeNamedItem : function(name) {
+          var ret = null;
+          // test for exceptions
+          // throw Exception if DOMNamedNodeMap is readonly
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly))) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+          }
+        
+          // get item index
+          var itemIndex = __findNamedItemIndex__(this, name);
+        
+          // throw Exception if there is no node named name in this map
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+            throw(new DOMException(DOMException.NOT_FOUND_ERR));
+          }
+        
+          // get Node
+          var oldNode = this[itemIndex];
+        
+          // throw Exception if Node is readonly
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldNode._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+          }
+        
+          // return removed node
+          return __removeChild__(this, itemIndex);
+    },
+    getNamedItemNS : function(namespaceURI, localName) {
+          var ret = null;
+        
+          // test that Named Node exists
+          var itemIndex = __findNamedItemNSIndex__(this, namespaceURI, localName);
+        
+          if (itemIndex &gt; -1) {                          // found it!
+            ret = this[itemIndex];                // return NamedNode
+          }
+        
+          return ret;                                    // if node is not found, default value null is returned
+    },
+    setNamedItemNS : function(arg) {
+          // test for exceptions
+          if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if DOMNamedNodeMap is readonly
+            if (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly)) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+        
+            // throw Exception if arg was not created by this Document
+            if (this.ownerDocument != arg.ownerDocument) {
+              throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+            }
+        
+            // throw Exception if arg is already an attribute of another Element object
+            if (arg.ownerElement &amp;&amp; (arg.ownerElement != this.parentNode)) {
+              throw(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR));
+            }
+          }
+        
+          // get item index
+          var itemIndex = __findNamedItemNSIndex__(this, arg.namespaceURI, arg.localName);
+          var ret = null;
+        
+          if (itemIndex &gt; -1) {                          // found it!
+            ret = this[itemIndex];                // use existing Attribute
+            // throw Exception if DOMAttr is readonly
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ret._readonly) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            } else {
+              this[itemIndex] = arg;                // over-write existing NamedNode
+            }
+          }else {
+            // add new NamedNode
+            Array.prototype.push.apply(this, [arg]);
+          }
+          arg.ownerElement = this.parentNode;
+        
+        
+          return ret;                                    // return old node or null
+    },
+    removeNamedItemNS : function(namespaceURI, localName) {
+          var ret = null;
+        
+          // test for exceptions
+          // throw Exception if DOMNamedNodeMap is readonly
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly))) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+          }
+        
+          // get item index
+          var itemIndex = __findNamedItemNSIndex__(this, namespaceURI, localName);
+        
+          // throw Exception if there is no matching node in this map
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+            throw(new DOMException(DOMException.NOT_FOUND_ERR));
+          }
+        
+          // get Node
+          var oldNode = this[itemIndex];
+        
+          // throw Exception if Node is readonly
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldNode._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+          }
+        
+          return __removeChild__(this, itemIndex);             // return removed node
+    },
+    get xml() {
+          var ret = &quot;&quot;;
+        
+          // create string containing concatenation of all (but last) Attribute string values (separated by spaces)
+          for (var i=0; i &lt; this.length -1; i++) {
+            ret += this[i].xml +&quot; &quot;;
+          }
+        
+          // add last Attribute to string (without trailing space)
+          if (this.length &gt; 0) {
+            ret += this[this.length -1].xml;
+          }
+        
+          return ret;
+    }
+
+});
+
+/**
+ * @method DOMNamedNodeMap._findNamedItemIndex - find the item index of the node with the specified name
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  name : string - the name of the required node
+ * @param  isnsmap : if its a DOMNamespaceNodeMap
+ * @return : int
+ */
+var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) {
+  var ret = -1;
+
+  // loop through all nodes
+  for (var i=0; i&lt;namednodemap.length; i++) {
+    // compare name to each node's nodeName
+    if(isnsmap){
+        if (namednodemap[i].localName == localName) {         // found it!
+          ret = i;
+          break;
+        }
+    }else{
+        if (namednodemap[i].name == name) {         // found it!
+          ret = i;
+          break;
+        }
+    }
+  }
+
+  return ret;                                    // if node is not found, default value -1 is returned
+};
+
+/**
+ * @method DOMNamedNodeMap._findNamedItemNSIndex - find the item index of the node with the specified namespaceURI and localName
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  namespaceURI : string - the namespace URI of the required node
+ * @param  localName    : string - the local name of the required node
+ * @return : int
+ */
+var __findNamedItemNSIndex__ = function(namednodemap, namespaceURI, localName) {
+  var ret = -1;
+
+  // test that localName is not null
+  if (localName) {
+    // loop through all nodes
+    for (var i=0; i&lt;namednodemap.length; i++) {
+      // compare name to each node's namespaceURI and localName
+      if ((namednodemap[i].namespaceURI == namespaceURI) &amp;&amp; (namednodemap[i].localName == localName)) {
+        ret = i;                                 // found it!
+        break;
+      }
+    }
+  }
+
+  return ret;                                    // if node is not found, default value -1 is returned
+};
+
+/**
+ * @method DOMNamedNodeMap._hasAttribute - Returns true if specified node exists
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  name : string - the name of the required node
+ * @return : boolean
+ */
+var __hasAttribute__ = function(namednodemap, name) {
+  var ret = false;
+
+  // test that Named Node exists
+  var itemIndex = __findNamedItemIndex__(namednodemap, name);
+
+  if (itemIndex &gt; -1) {                          // found it!
+    ret = true;                                  // return true
+  }
+
+  return ret;                                    // if node is not found, default value false is returned
+}
+
+/**
+ * @method DOMNamedNodeMap._hasAttributeNS - Returns true if specified node exists
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  namespaceURI : string - the namespace URI of the required node
+ * @param  localName    : string - the local name of the required node
+ * @return : boolean
+ */
+var __hasAttributeNS__ = function(namednodemap, namespaceURI, localName) {
+  var ret = false;
+
+  // test that Named Node exists
+  var itemIndex = __findNamedItemNSIndex__(namednodemap, namespaceURI, localName);
+
+  if (itemIndex &gt; -1) {                          // found it!
+    ret = true;                                  // return true
+  }
+
+  return ret;                                    // if node is not found, default value false is returned
+}
+
+/**
+ * @method DOMNamedNodeMap._cloneNodes - Returns a NamedNodeMap containing clones of the Nodes in this NamedNodeMap
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  parentNode : DOMNode - the new parent of the cloned NodeList
+ * @param  isnsmap : bool - is this a DOMNamespaceNodeMap
+ * @return : DOMNamedNodeMap - NamedNodeMap containing clones of the Nodes in this DOMNamedNodeMap
+ */
+var __cloneNamedNodes__ = function(namednodemap, parentNode, isnsmap) {
+  var cloneNamedNodeMap = isnsmap?
+    new DOMNamespaceNodeMap(namednodemap.ownerDocument, parentNode):
+    new DOMNamedNodeMap(namednodemap.ownerDocument, parentNode);
+
+  // create list containing clones of all children
+  for (var i=0; i &lt; namednodemap.length; i++) {
+      $log(&quot;cloning node in named node map :&quot; + namednodemap[i]);
+    __appendChild__(cloneNamedNodeMap, namednodemap[i].cloneNode(false));
+  }
+
+  return cloneNamedNodeMap;
+};
+
+
+/**
+ * @class  DOMNamespaceNodeMap - used to represent collections of namespace nodes that can be accessed by name
+ *  typically a set of Element attributes
+ *
+ * @extends DOMNamedNodeMap
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ *
+ * @param  ownerDocument : DOMDocument - the ownerDocument
+ * @param  parentNode    : DOMNode - the node that the DOMNamespaceNodeMap is attached to (or null)
+ */
+var DOMNamespaceNodeMap = function(ownerDocument, parentNode) {
+    //$log(&quot;\t\t\tcreating dom namespacednodemap&quot;);
+    this.DOMNamedNodeMap = DOMNamedNodeMap;
+    this.DOMNamedNodeMap(ownerDocument, parentNode);
+    __setArray__(this, []);
+};
+DOMNamespaceNodeMap.prototype = new DOMNamedNodeMap;
+__extend__(DOMNamespaceNodeMap.prototype, {
+    get xml() {
+          var ret = &quot;&quot;;
+        
+          // identify namespaces declared local to this Element (ie, not inherited)
+          for (var ind = 0; ind &lt; this.length; ind++) {
+            // if namespace declaration does not exist in the containing node's, parentNode's namespaces
+            var ns = null;
+            try {
+                var ns = this.parentNode.parentNode._namespaces.getNamedItem(this[ind].localName);
+            }
+            catch (e) {
+                //breaking to prevent default namespace being inserted into return value
+                break;
+            }
+            if (!(ns &amp;&amp; (&quot;&quot;+ ns.nodeValue == &quot;&quot;+ this[ind].nodeValue))) {
+              // display the namespace declaration
+              ret += this[ind].xml +&quot; &quot;;
+            }
+          }
+        
+          return ret;
+    }
+});
+$log(&quot;Defining Node&quot;);
+/*
+* Node - DOM Level 2
+*/	
+$w.__defineGetter__('Node', function(){
+  return __extend__(function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+      } , {
+  		ELEMENT_NODE    :1,
+  		ATTRIBUTE_NODE  :2,
+  		TEXT_NODE       :3,
+  		CDATA_SECTION_NODE: 4,
+  		PROCESSING_INSTRUCTION_NODE: 7,
+  		COMMENT_NODE: 8,
+  		DOCUMENT_NODE: 9,
+  		DOCUMENT_TYPE_NODE: 10,
+  		DOCUMENT_FRAGMENT_NODE: 11
+	});
+});
+
+/**
+ * @class  DOMNode - The Node interface is the primary datatype for the entire Document Object Model.
+ *   It represents a single node in the document tree.
+ * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMNode = function(ownerDocument) {
+  //$log(&quot;\tcreating dom node&quot;);
+  if (ownerDocument) {
+    this._id = ownerDocument._genId();           // generate unique internal id
+  }
+
+  this.namespaceURI = &quot;&quot;;                        // The namespace URI of this node (Level 2)
+  this.prefix       = &quot;&quot;;                        // The namespace prefix of this node (Level 2)
+  this.localName    = &quot;&quot;;                        // The localName of this node (Level 2)
+
+  this.nodeName = &quot;&quot;;                            // The name of this node
+  this.nodeValue = &quot;&quot;;                           // The value of this node
+  this.nodeType = 0;                             // A code representing the type of the underlying object
+
+  // The parent of this node. All nodes, except Document, DocumentFragment, and Attr may have a parent.
+  // However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null
+  this.parentNode      = null;
+
+  // A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.
+  // The content of the returned NodeList is &quot;live&quot; in the sense that, for instance, changes to the children of the node object
+  // that it was created from are immediately reflected in the nodes returned by the NodeList accessors;
+  // it is not a static snapshot of the content of the node. This is true for every NodeList, including the ones returned by the getElementsByTagName method.
+  this.childNodes      = new DOMNodeList(ownerDocument, this);
+
+  this.firstChild      = null;                   // The first child of this node. If there is no such node, this is null
+  this.lastChild       = null;                   // The last child of this node. If there is no such node, this is null.
+  this.previousSibling = null;                   // The node immediately preceding this node. If there is no such node, this is null.
+  this.nextSibling     = null;                   // The node immediately following this node. If there is no such node, this is null.
+
+  this.attributes = new DOMNamedNodeMap(ownerDocument, this);   // A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
+  this.ownerDocument   = ownerDocument;          // The Document object associated with this node
+  this._namespaces = new DOMNamespaceNodeMap(ownerDocument, this);  // The namespaces in scope for this node
+
+  this._readonly = false;
+  //$log(&quot;\tfinished creating dom node&quot;);
+};
+
+// nodeType constants
+DOMNode.ELEMENT_NODE                = 1;
+DOMNode.ATTRIBUTE_NODE              = 2;
+DOMNode.TEXT_NODE                   = 3;
+DOMNode.CDATA_SECTION_NODE          = 4;
+DOMNode.ENTITY_REFERENCE_NODE       = 5;
+DOMNode.ENTITY_NODE                 = 6;
+DOMNode.PROCESSING_INSTRUCTION_NODE = 7;
+DOMNode.COMMENT_NODE                = 8;
+DOMNode.DOCUMENT_NODE               = 9;
+DOMNode.DOCUMENT_TYPE_NODE          = 10;
+DOMNode.DOCUMENT_FRAGMENT_NODE      = 11;
+DOMNode.NOTATION_NODE               = 12;
+DOMNode.NAMESPACE_NODE              = 13;
+
+__extend__(DOMNode.prototype, {
+    hasAttributes : function() {
+        if (this.attributes.length == 0) {
+            return false;
+        }else{
+            return true;
+        }
+    },
+    insertBefore : function(newChild, refChild) {
+        var prevNode;
+        
+        // test for exceptions
+        if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if DOMNode is readonly
+            if (this._readonly) {
+                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+            
+            // throw Exception if newChild was not created by this Document
+            if (this.ownerDocument != newChild.ownerDocument) {
+                throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+            }
+            
+            // throw Exception if the node is an ancestor
+            if (__isAncestor__(this, newChild)) {
+                throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
+            }
+        }
+        
+        if (refChild) {                                // if refChild is specified, insert before it
+            // find index of refChild
+            var itemIndex = __findItemIndex__(this.childNodes, refChild._id);
+            
+            // throw Exception if there is no child node with this id
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+              throw(new DOMException(DOMException.NOT_FOUND_ERR));
+            }
+            
+            // if the newChild is already in the tree,
+            var newChildParent = newChild.parentNode;
+            if (newChildParent) {
+              // remove it
+              newChildParent.removeChild(newChild);
+            }
+            
+            // insert newChild into childNodes
+            __insertBefore__(this.childNodes, newChild, __findItemIndex__(this.childNodes, refChild._id));
+            
+            // do node pointer surgery
+            prevNode = refChild.previousSibling;
+            
+            // handle DocumentFragment
+            if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
+              if (newChild.childNodes.length &gt; 0) {
+                // set the parentNode of DocumentFragment's children
+                for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
+                  newChild.childNodes[ind].parentNode = this;
+                }
+            
+                // link refChild to last child of DocumentFragment
+                refChild.previousSibling = newChild.childNodes[newChild.childNodes.length-1];
+              }
+            }else {
+                newChild.parentNode = this;                // set the parentNode of the newChild
+                refChild.previousSibling = newChild;       // link refChild to newChild
+            }
+        }else {                                         // otherwise, append to end
+            prevNode = this.lastChild;
+            this.appendChild(newChild);
+        }
+        
+        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
+            // do node pointer surgery for DocumentFragment
+            if (newChild.childNodes.length &gt; 0) {
+                if (prevNode) {  
+                    prevNode.nextSibling = newChild.childNodes[0];
+                }else {                                         // this is the first child in the list
+                    this.firstChild = newChild.childNodes[0];
+                }
+            
+                newChild.childNodes[0].previousSibling = prevNode;
+                newChild.childNodes[newChild.childNodes.length-1].nextSibling = refChild;
+            }
+        }else {
+            // do node pointer surgery for newChild
+            if (prevNode) {
+              prevNode.nextSibling = newChild;
+            }else {                                         // this is the first child in the list
+              this.firstChild = newChild;
+            }
+            
+            newChild.previousSibling = prevNode;
+            newChild.nextSibling     = refChild;
+        }
+        
+        return newChild;
+    },
+    replaceChild : function(newChild, oldChild) {
+        var ret = null;
+        
+        // test for exceptions
+        if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if DOMNode is readonly
+            if (this._readonly) {
+                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+        
+            // throw Exception if newChild was not created by this Document
+            if (this.ownerDocument != newChild.ownerDocument) {
+                throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+            }
+        
+            // throw Exception if the node is an ancestor
+            if (__isAncestor__(this, newChild)) {
+                throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
+            }
+        }
+        
+        // get index of oldChild
+        var index = __findItemIndex__(this.childNodes, oldChild._id);
+        
+        // throw Exception if there is no child node with this id
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (index &lt; 0)) {
+            throw(new DOMException(DOMException.NOT_FOUND_ERR));
+        }
+        
+        // if the newChild is already in the tree,
+        var newChildParent = newChild.parentNode;
+        if (newChildParent) {
+            // remove it
+            newChildParent.removeChild(newChild);
+        }
+        
+        // add newChild to childNodes
+        ret = __replaceChild__(this.childNodes,newChild, index);
+        
+        
+        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
+            // do node pointer surgery for Document Fragment
+            if (newChild.childNodes.length &gt; 0) {
+                for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
+                    newChild.childNodes[ind].parentNode = this;
+                }
+                
+                if (oldChild.previousSibling) {
+                    oldChild.previousSibling.nextSibling = newChild.childNodes[0];
+                } else {
+                    this.firstChild = newChild.childNodes[0];
+                }
+                
+                if (oldChild.nextSibling) {
+                    oldChild.nextSibling.previousSibling = newChild;
+                } else {
+                    this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
+                }
+                
+                newChild.childNodes[0].previousSibling = oldChild.previousSibling;
+                newChild.childNodes[newChild.childNodes.length-1].nextSibling = oldChild.nextSibling;
+            }
+        } else {
+            // do node pointer surgery for newChild
+            newChild.parentNode = this;
+            
+            if (oldChild.previousSibling) {
+                oldChild.previousSibling.nextSibling = newChild;
+            }else{
+                this.firstChild = newChild;
+            }
+            if (oldChild.nextSibling) {
+                oldChild.nextSibling.previousSibling = newChild;
+            }else{
+                this.lastChild = newChild;
+            }
+            newChild.previousSibling = oldChild.previousSibling;
+            newChild.nextSibling = oldChild.nextSibling;
+        }
+        //this.removeChild(oldChild);
+        return ret;
+    },
+    removeChild : function(oldChild) {
+        // throw Exception if DOMNamedNodeMap is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || oldChild._readonly)) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        
+        // get index of oldChild
+        var itemIndex = __findItemIndex__(this.childNodes, oldChild._id);
+        
+        // throw Exception if there is no child node with this id
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+            throw(new DOMException(DOMException.NOT_FOUND_ERR));
+        }
+        
+        // remove oldChild from childNodes
+        __removeChild__(this.childNodes, itemIndex);
+        
+        // do node pointer surgery
+        oldChild.parentNode = null;
+        
+        if (oldChild.previousSibling) {
+            oldChild.previousSibling.nextSibling = oldChild.nextSibling;
+        }else {
+            this.firstChild = oldChild.nextSibling;
+        }
+        if (oldChild.nextSibling) {
+            oldChild.nextSibling.previousSibling = oldChild.previousSibling;
+        }else {
+            this.lastChild = oldChild.previousSibling;
+        }
+        
+        oldChild.previousSibling = null;
+        oldChild.nextSibling = null;
+        
+        /*if(oldChild.ownerDocument == document){
+            $log(&quot;removeChild :  all -&gt; &quot; + document.all.length);
+        }*/
+        return oldChild;
+    },
+    appendChild : function(newChild) {
+      // test for exceptions
+      if (this.ownerDocument.implementation.errorChecking) {
+        // throw Exception if Node is readonly
+        if (this._readonly) {
+          throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+    
+        // throw Exception if arg was not created by this Document
+        if (this.ownerDocument != newChild.ownerDocument) {
+          throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+        }
+    
+        // throw Exception if the node is an ancestor
+        if (__isAncestor__(this, newChild)) {
+          throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
+        }
+      }
+    
+      // if the newChild is already in the tree,
+      var newChildParent = newChild.parentNode;
+      if (newChildParent) {
+        // remove it
+        newChildParent.removeChild(newChild);
+      }
+    
+      // add newChild to childNodes
+      __appendChild__(this.childNodes, newChild);
+    
+      if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
+        // do node pointer surgery for DocumentFragment
+        if (newChild.childNodes.length &gt; 0) {
+          for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
+            newChild.childNodes[ind].parentNode = this;
+          }
+    
+          if (this.lastChild) {
+            this.lastChild.nextSibling = newChild.childNodes[0];
+            newChild.childNodes[0].previousSibling = this.lastChild;
+            this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
+          }
+          else {
+            this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
+            this.firstChild = newChild.childNodes[0];
+          }
+        }
+      }
+      else {
+        // do node pointer surgery for newChild
+        newChild.parentNode = this;
+        if (this.lastChild) {
+          this.lastChild.nextSibling = newChild;
+          newChild.previousSibling = this.lastChild;
+          this.lastChild = newChild;
+        }
+        else {
+          this.lastChild = newChild;
+          this.firstChild = newChild;
+        }
+      }
+    
+      return newChild;
+    },
+    hasChildNodes : function() {
+        return (this.childNodes.length &gt; 0);
+    },
+    cloneNode: function(deep) {
+        // use importNode to clone this Node
+        //do not throw any exceptions
+        //$log(&quot;cloning node&quot;);
+        try {
+            return this.ownerDocument.importNode(this, deep);
+        } catch (e) {
+            //there shouldn't be any exceptions, but if there are, return null
+            return null;
+        }
+    },
+    normalize : function() {
+        var inode;
+        var nodesToRemove = new DOMNodeList();
+        
+        if (this.nodeType == DOMNode.ELEMENT_NODE || this.nodeType == DOMNode.DOCUMENT_NODE) {
+            var adjacentTextNode = null;
+        
+            // loop through all childNodes
+            for(var i = 0; i &lt; this.childNodes.length; i++) {
+                inode = this.childNodes.item(i);
+            
+                if (inode.nodeType == DOMNode.TEXT_NODE) { // this node is a text node
+                    if (inode.length &lt; 1) {                  // this text node is empty
+                        __appendChild__(nodesToRemove, inode);      // add this node to the list of nodes to be remove
+                    }else {
+                        if (adjacentTextNode) {                // if previous node was also text
+                            adjacentTextNode.appendData(inode.data);     // merge the data in adjacent text nodes
+                            __appendChild__(nodesToRemove, inode);    // add this node to the list of nodes to be removed
+                        }else {
+                            adjacentTextNode = inode;              // remember this node for next cycle
+                        }
+                    }
+                } else {
+                    adjacentTextNode = null;                 // (soon to be) previous node is not a text node
+                    inode.normalize();                       // normalise non Text childNodes
+                }
+            }
+                
+            // remove redundant Text Nodes
+            for(var i = 0; i &lt; nodesToRemove.length; i++) {
+                inode = nodesToRemove.item(i);
+                inode.parentNode.removeChild(inode);
+            }
+        }
+    },
+    isSupported : function(feature, version) {
+        // use Implementation.hasFeature to determin if this feature is supported
+        return this.ownerDocument.implementation.hasFeature(feature, version);
+    },
+    getElementsByTagName : function(tagname) {
+        // delegate to _getElementsByTagNameRecursive
+        //$log(&quot;getElementsByTagName(&quot;+tagname+&quot;)&quot;);
+        return __getElementsByTagNameRecursive__(this, tagname, new DOMNodeList(this.ownerDocument));
+    },
+    getElementsByTagNameNS : function(namespaceURI, localName) {
+        // delegate to _getElementsByTagNameNSRecursive
+        return __getElementsByTagNameNSRecursive__(this, namespaceURI, localName, new DOMNodeList(this.ownerDocument));
+    },
+    importNode : function(importedNode, deep) {
+        var importNode;
+        //$log(&quot;importing node &quot; + importedNode + &quot;(?deep = &quot;+deep+&quot;)&quot;);
+        //there is no need to perform namespace checks since everything has already gone through them
+        //in order to have gotten into the DOM in the first place. The following line
+        //turns namespace checking off in ._isValidNamespace
+        this.ownerDocument._performingImportNodeOperation = true;
+        
+        try {
+            if (importedNode.nodeType == DOMNode.ELEMENT_NODE) {
+                if (!this.ownerDocument.implementation.namespaceAware) {
+                    // create a local Element (with the name of the importedNode)
+                    importNode = this.ownerDocument.createElement(importedNode.tagName);
+                
+                    // create attributes matching those of the importedNode
+                    for(var i = 0; i &lt; importedNode.attributes.length; i++) {
+                        importNode.setAttribute(importedNode.attributes.item(i).name, importedNode.attributes.item(i).value);
+                    }
+                }else {
+                    // create a local Element (with the name &amp; namespaceURI of the importedNode)
+                    importNode = this.ownerDocument.createElementNS(importedNode.namespaceURI, importedNode.nodeName);
+                
+                    // create attributes matching those of the importedNode
+                    for(var i = 0; i &lt; importedNode.attributes.length; i++) {
+                        importNode.setAttributeNS(importedNode.attributes.item(i).namespaceURI, 
+                            importedNode.attributes.item(i).name, importedNode.attributes.item(i).value);
+                    }
+                
+                    // create namespace definitions matching those of the importedNode
+                    for(var i = 0; i &lt; importedNode._namespaces.length; i++) {
+                        importNode._namespaces[i] = this.ownerDocument.createNamespace(importedNode._namespaces.item(i).localName);
+                        importNode._namespaces[i].value = importedNode._namespaces.item(i).value;
+                    }
+                }
+            } else if (importedNode.nodeType == DOMNode.ATTRIBUTE_NODE) {
+                if (!this.ownerDocument.implementation.namespaceAware) {
+                    // create a local Attribute (with the name of the importedAttribute)
+                    importNode = this.ownerDocument.createAttribute(importedNode.name);
+                } else {
+                    // create a local Attribute (with the name &amp; namespaceURI of the importedAttribute)
+                    importNode = this.ownerDocument.createAttributeNS(importedNode.namespaceURI, importedNode.nodeName);
+                
+                    // create namespace definitions matching those of the importedAttribute
+                    for(var i = 0; i &lt; importedNode._namespaces.length; i++) {
+                        importNode._namespaces[i] = this.ownerDocument.createNamespace(importedNode._namespaces.item(i).localName);
+                        importNode._namespaces[i].value = importedNode._namespaces.item(i).value;
+                    }
+                }
+            
+                // set the value of the local Attribute to match that of the importedAttribute
+                importNode.value = importedNode.value;
+                
+            } else if (importedNode.nodeType == DOMNode.DOCUMENT_FRAGMENT) {
+                // create a local DocumentFragment
+                importNode = this.ownerDocument.createDocumentFragment();
+            } else if (importedNode.nodeType == DOMNode.NAMESPACE_NODE) {
+                // create a local NamespaceNode (with the same name &amp; value as the importedNode)
+                importNode = this.ownerDocument.createNamespace(importedNode.nodeName);
+                importNode.value = importedNode.value;
+            } else if (importedNode.nodeType == DOMNode.TEXT_NODE) {
+                // create a local TextNode (with the same data as the importedNode)
+                importNode = this.ownerDocument.createTextNode(importedNode.data);
+            } else if (importedNode.nodeType == DOMNode.CDATA_SECTION_NODE) {
+                // create a local CDATANode (with the same data as the importedNode)
+                importNode = this.ownerDocument.createCDATASection(importedNode.data);
+            } else if (importedNode.nodeType == DOMNode.PROCESSING_INSTRUCTION_NODE) {
+                // create a local ProcessingInstruction (with the same target &amp; data as the importedNode)
+                importNode = this.ownerDocument.createProcessingInstruction(importedNode.target, importedNode.data);
+            } else if (importedNode.nodeType == DOMNode.COMMENT_NODE) {
+                // create a local Comment (with the same data as the importedNode)
+                importNode = this.ownerDocument.createComment(importedNode.data);
+            } else {  // throw Exception if nodeType is not supported
+                throw(new DOMException(DOMException.NOT_SUPPORTED_ERR));
+            }
+            
+            if (deep) {                                    // recurse childNodes
+                for(var i = 0; i &lt; importedNode.childNodes.length; i++) {
+                    importNode.appendChild(this.ownerDocument.importNode(importedNode.childNodes.item(i), true));
+                }
+            }
+            
+            //reset _performingImportNodeOperation
+            this.ownerDocument._performingImportNodeOperation = false;
+            return importNode;
+        } catch (eAny) {
+            //reset _performingImportNodeOperation
+            this.ownerDocument._performingImportNodeOperation = false;
+            
+            //re-throw the exception
+            throw eAny;
+        }//djotemp
+    },
+    contains : function(node){
+            while(node &amp;&amp; node != this ){
+                node = node.parentNode;
+            }
+            return !!node;
+    },
+    compareDocumentPosition : function(b){
+        var a = this;
+        var number = (a != b &amp;&amp; a.contains(b) &amp;&amp; 16) + (a != b &amp;&amp; b.contains(a) &amp;&amp; 8);
+        //find position of both
+        var all = document.getElementsByTagName(&quot;*&quot;);
+        var my_location = 0, node_location = 0;
+        for(var i=0; i &lt; all.length; i++){
+            if(all[i] == a) my_location = i;
+            if(all[i] == b) node_location = i;
+            if(my_location &amp;&amp; node_location) break;
+        }
+        number += (my_location &lt; node_location &amp;&amp; 4)
+        number += (my_location &gt; node_location &amp;&amp; 2)
+        return number;
+    } 
+
+});
+
+/**
+ * @method DOMNode._getElementsByTagNameRecursive - implements getElementsByTagName()
+ * @param  elem     : DOMElement  - The element which are checking and then recursing into
+ * @param  tagname  : string      - The name of the tag to match on. The special value &quot;*&quot; matches all tags
+ * @param  nodeList : DOMNodeList - The accumulating list of matching nodes
+ *
+ * @return : DOMNodeList
+ */
+var __getElementsByTagNameRecursive__ = function (elem, tagname, nodeList) {
+    //$log(&quot;__getElementsByTagNameRecursive__(&quot;+elem._id+&quot;)&quot;);
+    if (elem.nodeType == DOMNode.ELEMENT_NODE || elem.nodeType == DOMNode.DOCUMENT_NODE) {
+    
+        if((elem.nodeName.toUpperCase() == tagname.toUpperCase()) || (tagname == &quot;*&quot;)) {
+            //$log(&quot;found node by name &quot; + tagname);
+            __appendChild__(nodeList, elem);               // add matching node to nodeList
+        }
+    
+        // recurse childNodes
+        for(var i = 0; i &lt; elem.childNodes.length; i++) {
+            nodeList = __getElementsByTagNameRecursive__(elem.childNodes.item(i), tagname, nodeList);
+        }
+    }
+    
+    return nodeList;
+};
+
+
+/**
+ * @method DOMNode._getElementsByTagNameNSRecursive - implements getElementsByTagName()
+ *
+ * @param  elem     : DOMElement  - The element which are checking and then recursing into
+ * @param  namespaceURI : string - the namespace URI of the required node
+ * @param  localName    : string - the local name of the required node
+ * @param  nodeList     : DOMNodeList - The accumulating list of matching nodes
+ *
+ * @return : DOMNodeList
+ */
+var __getElementsByTagNameNSRecursive__ = function(elem, namespaceURI, localName, nodeList) {
+  if (elem.nodeType == DOMNode.ELEMENT_NODE || elem.nodeType == DOMNode.DOCUMENT_NODE) {
+
+    if (((elem.namespaceURI == namespaceURI) || (namespaceURI == &quot;*&quot;)) &amp;&amp; ((elem.localName == localName) || (localName == &quot;*&quot;))) {
+      __appendChild__(nodeList, elem);               // add matching node to nodeList
+    }
+
+    // recurse childNodes
+    for(var i = 0; i &lt; elem.childNodes.length; i++) {
+      nodeList = __getElementsByTagNameNSRecursive__(elem.childNodes.item(i), namespaceURI, localName, nodeList);
+    }
+  }
+
+  return nodeList;
+};
+
+/**
+ * @method DOMNode._isAncestor - returns true if node is ancestor of target
+ * @param  target         : DOMNode - The node we are using as context
+ * @param  node         : DOMNode - The candidate ancestor node
+ * @return : boolean
+ */
+var __isAncestor__ = function(target, node) {
+  // if this node matches, return true,
+  // otherwise recurse up (if there is a parentNode)
+  return ((target == node) || ((target.parentNode) &amp;&amp; (__isAncestor__(target.parentNode, node))));
+}
+
+
+/**
+ * @class  DOMNamespace - The Namespace interface represents an namespace in an Element object
+ *
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMNamespace = function(ownerDocument) {
+  this.DOMNode = DOMNode;
+  this.DOMNode(ownerDocument);
+
+  this.name      = &quot;&quot;;                           // the name of this attribute
+
+  // If this attribute was explicitly given a value in the original document, this is true; otherwise, it is false.
+  // Note that the implementation is in charge of this attribute, not the user.
+  // If the user changes the value of the attribute (even if it ends up having the same value as the default value)
+  // then the specified flag is automatically flipped to true
+  this.specified = false;
+
+  this.value     = &quot;&quot;;                           // the value of the attribute is returned as a string
+
+  this.nodeType  = DOMNode.NAMESPACE_NODE;
+};
+DOMNamespace.prototype = new DOMNode;
+__extend__(DOMNamespace.prototype, {
+    get value(){
+        return this.nodeValue;
+    },
+    set value(value){
+        this.nodeValue = String(value);
+    },
+    get xml(){
+        var ret = &quot;&quot;;
+
+          // serialize Namespace Declaration
+          if (this.nodeName != &quot;&quot;) {
+            ret += this.nodeName +&quot;=\&quot;&quot;+ __escapeXML__(this.nodeValue) +&quot;\&quot;&quot;;
+          }
+          else {  // handle default namespace
+            ret += &quot;xmlns=\&quot;&quot;+ __escapeXML__(this.nodeValue) +&quot;\&quot;&quot;;
+          }
+        
+          return ret;
+    },
+    toString: function(){
+        return &quot;Namespace #&quot; + this.id;
+    }
+});
+
+$debug(&quot;Defining CharacterData&quot;);
+/*
+* CharacterData - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CharacterData&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMCharacterData - parent abstract class for DOMText and DOMComment
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMCharacterData = function(ownerDocument) {
+  this.DOMNode  = DOMNode;
+  this.DOMNode(ownerDocument);
+  this.data   = &quot;&quot;;
+  this.length = 0;
+};
+DOMCharacterData.prototype = new DOMNode;
+__extend__(DOMCharacterData.prototype,{
+    get data(){
+        return String(this.nodeValue);
+    },
+    set data(data){
+        this.nodeValue = String(data);
+    },
+    get length(){return this.nodeValue.length;},
+    appendData: function(arg){
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        // append data
+        this.data = &quot;&quot; + this.data + arg;
+    },
+    deleteData: function(offset, count){ 
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
+              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // delete data
+            if(!count || (offset + count) &gt; this.data.length) {
+              this.data = this.data.substring(0, offset);
+            }else {
+              this.data = this.data.substring(0, offset).concat(this.data.substring(offset + count));
+            }
+        }
+    },
+    insertData: function(offset, arg){
+        // throw Exception if DOMCharacterData is readonly
+        if(this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly){
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        
+        if(this.data){
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // insert data
+            this.data =  this.data.substring(0, offset).concat(arg, this.data.substring(offset));
+        }else {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (offset != 0)) {
+               throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // set data
+            this.data = arg;
+        }
+    },
+    replaceData: function(offset, count, arg){
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // replace data
+            this.data = this.data.substring(0, offset).concat(arg, this.data.substring(offset + count));
+        }else {
+            // set data
+            this.data = arg;
+        }
+    },
+    substringData: function(offset, count){
+        var ret = null;
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            // or the count is negative
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt; this.data.length) || (count &lt; 0))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            // if count is not specified
+            if (!count) {
+                ret = this.data.substring(offset); // default to 'end of string'
+            }else{
+                ret = this.data.substring(offset, offset + count);
+            }
+        }
+        return ret;
+    }
+});
+$log(&quot;Defining Text&quot;);
+/*
+* Text - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Text&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+/**
+ * @class  DOMText - The Text interface represents the textual content (termed character data in XML) of an Element or Attr.
+ *   If there is no markup inside an element's content, the text is contained in a single object implementing the Text interface
+ *   that is the only child of the element. If there is markup, it is parsed into a list of elements and Text nodes that form the
+ *   list of children of the element.
+ * @extends DOMCharacterData
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+DOMText = function(ownerDocument) {
+  this.DOMCharacterData  = DOMCharacterData;
+  this.DOMCharacterData(ownerDocument);
+
+  this.nodeName  = &quot;#text&quot;;
+  this.nodeType  = DOMNode.TEXT_NODE;
+};
+DOMText.prototype = new DOMCharacterData;
+__extend__(DOMText.prototype,{
+    //Breaks this Text node into two Text nodes at the specified offset,
+    // keeping both in the tree as siblings. This node then only contains all the content up to the offset point.
+    // And a new Text node, which is inserted as the next sibling of this node, contains all the content at and after the offset point.
+    splitText : function(offset) {
+        var data, inode;
+        
+        // test for exceptions
+        if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if Node is readonly
+            if (this._readonly) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+            
+            // throw Exception if offset is negative or greater than the data length,
+            if ((offset &lt; 0) || (offset &gt; this.data.length)) {
+              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+        }
+        
+        if (this.parentNode) {
+            // get remaining string (after offset)
+            data  = this.substringData(offset);
+            
+            // create new TextNode with remaining string
+            inode = this.ownerDocument.createTextNode(data);
+            
+            // attach new TextNode
+            if (this.nextSibling) {
+              this.parentNode.insertBefore(inode, this.nextSibling);
+            }
+            else {
+              this.parentNode.appendChild(inode);
+            }
+            
+            // remove remaining string from original TextNode
+            this.deleteData(offset);
+        }
+        
+        return inode;
+    },
+    get xml(){
+        return __escapeXML__(&quot;&quot;+ this.nodeValue);
+    },
+    toString: function(){
+        return &quot;Text #&quot; + this._id;    
+    }
+});
+
+$log(&quot;Defining CDATASection&quot;);
+/*
+* CDATASection - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CDATASection&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMCDATASection - CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup.
+ *   The only delimiter that is recognized in a CDATA section is the &quot;\]\]\&gt;&quot; string that ends the CDATA section
+ * @extends DOMCharacterData
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMCDATASection = function(ownerDocument) {
+  this.DOMText  = DOMText;
+  this.DOMText(ownerDocument);
+
+  this.nodeName  = &quot;#cdata-section&quot;;
+  this.nodeType  = DOMNode.CDATA_SECTION_NODE;
+};
+DOMCDATASection.prototype = new DOMText;
+__extend__(DOMCDATASection.prototype,{
+    get xml(){
+        return &quot;&lt;![CDATA[&quot; + this.nodeValue + &quot;]]&gt;&quot;;
+    },
+    toString : function(){
+        return &quot;CDATA #&quot;+this._id;
+    }
+});$log(&quot;Defining Comment&quot;);
+/* 
+* Comment - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Comment&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMComment - This represents the content of a comment, i.e., all the characters between the starting '&lt;!--' and ending '--&gt;'
+ * @extends DOMCharacterData
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMComment = function(ownerDocument) {
+  this.DOMCharacterData  = DOMCharacterData;
+  this.DOMCharacterData(ownerDocument);
+
+  this.nodeName  = &quot;#comment&quot;;
+  this.nodeType  = DOMNode.COMMENT_NODE;
+};
+DOMComment.prototype = new DOMCharacterData;
+__extend__(DOMComment.prototype, {
+    get xml(){
+        return &quot;&lt;!-- &quot; + this.nodeValue + &quot; --&gt;&quot;;
+    },
+    toString : function(){
+        return &quot;Comment #&quot;+this._id;
+    }
+});
+$log(&quot;Defining DocumentType&quot;);
+;/*
+* DocumentType - DOM Level 2
+*/
+$w.__defineGetter__('DocumentType', function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var DOMDocumentType    = function() { $error(&quot;DOMDocumentType.constructor(): Not Implemented&quot;   ); };$log(&quot;Defining Attr&quot;);
+/*
+* Attr - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Attr&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+
+/**
+ * @class  DOMAttr - The Attr interface represents an attribute in an Element object
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMAttr = function(ownerDocument) {
+    //$log(&quot;\tcreating dom attribute&quot;);
+    this.DOMNode = DOMNode;
+    this.DOMNode(ownerDocument);
+    
+    this.name      = &quot;&quot;;                    // the name of this attribute
+    this.specified = false;
+    this.value     = &quot;&quot;;                    // the value of the attribute is returned as a string
+    this.nodeType  = DOMNode.ATTRIBUTE_NODE;
+    this.ownerElement = null;               // set when Attr is added to NamedNodeMap
+    
+    //$log(&quot;\tfincished creating dom attribute &quot; + this);
+};
+DOMAttr.prototype = new DOMNode; 
+__extend__(DOMAttr.prototype, {
+    get name(){
+        return this.nodeName;
+    },
+    get value(){
+        return this.nodeValue;
+    },
+    set value(value){
+        // throw Exception if Attribute is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        // delegate to node
+        this.specified = (this.value.length &gt; 0);
+        this.nodeValue = value;
+    },
+    get xml(){
+        return this.nodeName + &quot;='&quot; + this.nodeValue + &quot;' &quot;;
+    },
+    toString : function(){
+        return &quot;Attr #&quot; + this._id + &quot; &quot; + this.name;
+    }
+});    
+
+$log(&quot;Defining Element&quot;);
+/*
+* Element - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Element&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+	
+/**
+ * @class  DOMElement - By far the vast majority of objects (apart from text) that authors encounter
+ *   when traversing a document are Element nodes.
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMElement = function(ownerDocument) {
+    //$log(&quot;\tcreating dom element&quot;);
+    this.DOMNode  = DOMNode;
+    this.DOMNode(ownerDocument);
+    this.tagName = &quot;&quot;;                             // The name of the element.
+    this.id = &quot;&quot;;                                  // the ID of the element
+    this.nodeType = DOMNode.ELEMENT_NODE;
+    //$log(&quot;\nfinished creating dom element &quot; + this);
+};
+DOMElement.prototype = new DOMNode;
+__extend__(DOMElement.prototype, {
+  	addEventListener:     window.addEventListener,
+  	removeEventListener:  window.removeEventListener,
+  	dispatchEvent:        window.dispatchEvent,
+    getAttribute: function(name) {
+        var ret = null;
+        // if attribute exists, use it
+        var attr = this.attributes.getNamedItem(name);
+        if (attr) {
+            ret = attr.value;
+        }
+        return ret; // if Attribute exists, return its value, otherwise, return &quot;&quot;
+    },
+    setAttribute : function (name, value) {
+        // if attribute exists, use it
+        var attr = this.attributes.getNamedItem(name);
+        var value = new String(value);
+        //I had to add this check becuase as the script initializes
+        //the id may be set in the constructor, and the html element
+        //overrides the id property with a getter/setter.
+        if(this.ownerDocument){
+            if (!attr) {
+                attr = this.ownerDocument.createAttribute(name);  // otherwise create it
+            }
+            
+            
+            // test for exceptions
+            if (this.ownerDocument.implementation.errorChecking) {
+                // throw Exception if Attribute is readonly
+                if (attr._readonly) {
+                    throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+                }
+                
+                // throw Exception if the value string contains an illegal character
+                if (!__isValidString__(value)) {
+                    throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+                }
+            }
+            
+            if (__isIdDeclaration__(name)) {
+                this.id = value;  // cache ID for getElementById()
+            }
+            
+            // assign values to properties (and aliases)
+            attr.value     = value;
+            
+            // update .specified
+            if (value.length &gt; 0) {
+                attr.specified = true;
+            }else {
+                attr.specified = false;
+            }
+            
+            // add/replace Attribute in NamedNodeMap
+            this.attributes.setNamedItem(attr);
+        }
+    },
+    removeAttribute : function removeAttribute(name) {
+        // delegate to DOMNamedNodeMap.removeNamedItem
+        return this.attributes.removeNamedItem(name);
+    },
+    getAttributeNode : function getAttributeNode(name) {
+        // delegate to DOMNamedNodeMap.getNamedItem
+        return this.attributes.getNamedItem(name);
+    },
+    setAttributeNode: function(newAttr) {
+        // if this Attribute is an ID
+        if (__isIdDeclaration__(newAttr.name)) {
+            this.id = newAttr.value;  // cache ID for getElementById()
+        }
+        // delegate to DOMNamedNodeMap.setNamedItem
+        return this.attributes.setNamedItem(newAttr);
+    },
+    removeAttributeNode: function(oldAttr) {
+      // throw Exception if Attribute is readonly
+      if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldAttr._readonly) {
+        throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+      }
+    
+      // get item index
+      var itemIndex = this.attributes._findItemIndex(oldAttr._id);
+    
+      // throw Exception if node does not exist in this map
+      if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+        throw(new DOMException(DOMException.NOT_FOUND_ERR));
+      }
+    
+      return this.attributes._removeChild(itemIndex);
+    },
+    getAttributeNS : function(namespaceURI, localName) {
+        var ret = &quot;&quot;;
+        // delegate to DOMNAmedNodeMap.getNamedItemNS
+        var attr = this.attributes.getNamedItemNS(namespaceURI, localName);
+        if (attr) {
+            ret = attr.value;
+        }
+        return ret;  // if Attribute exists, return its value, otherwise return &quot;&quot;
+    },
+    setAttributeNS : function(namespaceURI, qualifiedName, value) {
+        // call DOMNamedNodeMap.getNamedItem
+        var attr = this.attributes.getNamedItem(namespaceURI, qualifiedName);
+        
+        if (!attr) {  // if Attribute exists, use it
+            // otherwise create it
+            attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
+        }
+        
+        var value = String(value);
+        
+        // test for exceptions
+        if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if Attribute is readonly
+            if (attr._readonly) {
+                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+            
+            // throw Exception if the Namespace is invalid
+            if (!__isValidNamespace__(namespaceURI, qualifiedName)) {
+                throw(new DOMException(DOMException.NAMESPACE_ERR));
+            }
+            
+            // throw Exception if the value string contains an illegal character
+            if (!__isValidString__(value)) {
+                throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+            }
+        }
+        
+        // if this Attribute is an ID
+        if (__isIdDeclaration__(name)) {
+            this.id = value;  // cache ID for getElementById()
+        }
+        
+        // assign values to properties (and aliases)
+        attr.value     = value;
+        attr.nodeValue = value;
+        
+        // update .specified
+        if (value.length &gt; 0) {
+            attr.specified = true;
+        }else {
+            attr.specified = false;
+        }
+        
+        // delegate to DOMNamedNodeMap.setNamedItem
+        this.attributes.setNamedItemNS(attr);
+    },
+    removeAttributeNS : function(namespaceURI, localName) {
+        // delegate to DOMNamedNodeMap.removeNamedItemNS
+        return this.attributes.removeNamedItemNS(namespaceURI, localName);
+    },
+    getAttributeNodeNS : function(namespaceURI, localName) {
+        // delegate to DOMNamedNodeMap.getNamedItemNS
+        return this.attributes.getNamedItemNS(namespaceURI, localName);
+    },
+    setAttributeNodeNS : function(newAttr) {
+        // if this Attribute is an ID
+        if ((newAttr.prefix == &quot;&quot;) &amp;&amp;  __isIdDeclaration__(newAttr.name)) {
+            this.id = String(newAttr.value);  // cache ID for getElementById()
+        }
+        
+        // delegate to DOMNamedNodeMap.setNamedItemNS
+        return this.attributes.setNamedItemNS(newAttr);
+    },
+    hasAttribute : function(name) {
+        // delegate to DOMNamedNodeMap._hasAttribute
+        return __hasAttribute__(this.attributes,name);
+    },
+    hasAttributeNS : function(namespaceURI, localName) {
+        // delegate to DOMNamedNodeMap._hasAttributeNS
+        return __hasAttributeNS__(this.attributes, namespaceURI, localName);
+    },
+    get xml() {
+        var ret = &quot;&quot;;
+        
+        // serialize namespace declarations
+        var ns = this._namespaces.xml;
+        if (ns.length &gt; 0) ns = &quot; &quot;+ ns;
+        
+        // serialize Attribute declarations
+        var attrs = this.attributes.xml;
+        if (attrs.length &gt; 0) attrs = &quot; &quot;+ attrs;
+        
+        // serialize this Element
+        ret += &quot;&lt;&quot; + this.nodeName.toLowerCase() + ns + attrs +&quot;&gt;&quot;;
+        ret += this.childNodes.xml;
+        ret += &quot;&lt;/&quot; + this.nodeName.toLowerCase()+&quot;&gt;&quot;;
+        
+        return ret;
+    },
+    toString : function(){
+        return &quot;Element #&quot;+this._id + &quot; &quot;+ this.tagName + (this.id?&quot; =&gt; &quot;+this.id:'');
+    }
+});
+
+/**
+ * @class  DOMException - raised when an operation is impossible to perform
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  code : int - the exception code (one of the DOMException constants)
+ */
+var DOMException = function(code) {
+  this.code = code;
+};
+
+// DOMException constants
+// Introduced in DOM Level 1:
+DOMException.INDEX_SIZE_ERR                 = 1;
+DOMException.DOMSTRING_SIZE_ERR             = 2;
+DOMException.HIERARCHY_REQUEST_ERR          = 3;
+DOMException.WRONG_DOCUMENT_ERR             = 4;
+DOMException.INVALID_CHARACTER_ERR          = 5;
+DOMException.NO_DATA_ALLOWED_ERR            = 6;
+DOMException.NO_MODIFICATION_ALLOWED_ERR    = 7;
+DOMException.NOT_FOUND_ERR                  = 8;
+DOMException.NOT_SUPPORTED_ERR              = 9;
+DOMException.INUSE_ATTRIBUTE_ERR            = 10;
+
+// Introduced in DOM Level 2:
+DOMException.INVALID_STATE_ERR              = 11;
+DOMException.SYNTAX_ERR                     = 12;
+DOMException.INVALID_MODIFICATION_ERR       = 13;
+DOMException.NAMESPACE_ERR                  = 14;
+DOMException.INVALID_ACCESS_ERR             = 15;
+$log(&quot;Defining DocumentFragment&quot;);
+/* 
+* DocumentFragment - DOM Level 2
+*/
+$w.__defineGetter__(&quot;DocumentFragment&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+/**
+ * @class  DOMDocumentFragment - DocumentFragment is a &quot;lightweight&quot; or &quot;minimal&quot; Document object.
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMDocumentFragment = function(ownerDocument) {
+  this.DOMNode = DOMNode;
+  this.DOMNode(ownerDocument);
+  this.nodeName  = &quot;#document-fragment&quot;;
+  this.nodeType = DOMNode.DOCUMENT_FRAGMENT_NODE;
+};
+DOMDocumentFragment.prototype = new DOMNode;
+__extend__(DOMDocumentFragment.prototype,{
+    get xml(){
+        var xml = &quot;&quot;,
+            count = this.childNodes.length;
+        
+        // create string concatenating the serialized ChildNodes
+        for (var i = 0; i &lt; count; i++) {
+            xml += this.childNodes.item(i).xml;
+        }
+        
+        return xml;
+    },
+    toString : function(){
+        return &quot;DocumentFragment #&quot;+this._id;
+    }
+});
+$log(&quot;Defining ProcessingInstruction&quot;);
+/*
+* ProcessingInstruction - DOM Level 2
+*/
+$w.__defineGetter__('ProcessingInstruction', function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+/**
+ * @class  DOMProcessingInstruction - The ProcessingInstruction interface represents a &quot;processing instruction&quot;,
+ *   used in XML as a way to keep processor-specific information in the text of the document
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMProcessingInstruction = function(ownerDocument) {
+  this.DOMNode  = DOMNode;
+  this.DOMNode(ownerDocument);
+  // The target of this processing instruction.
+  // XML defines this as being the first token following the markup that begins the processing instruction.
+  this.target = &quot;&quot;;
+  // The content of this processing instruction.
+  // This is from the first non white space character after the target to the character immediately preceding the ?&gt;
+  this.data   = &quot;&quot;;
+  this.nodeType  = DOMNode.PROCESSING_INSTRUCTION_NODE;
+};
+DOMProcessingInstruction.prototype = new DOMNode;
+__extend__(DOMProcessingInstruction.prototype, {
+    get data(){
+        return this.nodeValue;
+    },
+    set data(data){
+        // throw Exception if DOMNode is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        this.nodeValue = data;
+    },
+    get target(){
+        return this.nodeName;
+    },
+    get xml(){
+        return &quot;&lt;?&quot; + this.nodeName +&quot; &quot;+ this.nodeValue + &quot; ?&gt;&quot;;
+    },
+    toString : function(){
+        return &quot;ProcessingInstruction #&quot;+this._id;
+    }
+});
+$log(&quot;Defining DOMParser&quot;);
+/*
+* DOMParser
+*/
+$w.__defineGetter__('DOMParser', function(){
+  return function(){
+    return __extend__(this, {
+      parseFromString: function(xmlString){
+        //$log(&quot;Parsing XML String: &quot; +xmlString);
+        return document.implementation.createDocument().loadXML(xmlString);
+      }
+    });
+  };
+});
+
+$log(&quot;Initializing Internal DOMParser.&quot;);
+//keep one around for internal use
+$domparser = new DOMParser();
+
+// =========================================================================
+//
+// xmlsax.js - an XML SAX parser in JavaScript.
+//
+// version 3.1
+//
+// =========================================================================
+//
+// Copyright (C) 2001 - 2002 David Joham (djoham@yahoo.com) and Scott Severtson
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+// Visit the XML for &lt;SCRIPT&gt; home page at http://xmljs.sourceforge.net
+//
+
+// CONSTANTS
+var whitespace = &quot;\n\r\t &quot;;
+
+
+/**
+*   function:   this is the constructor to the XMLP Object
+*   Author:   Scott Severtson
+*   Description:XMLP is a pull-based parser. The calling application passes in a XML string
+*   to the constructor, then repeatedly calls .next() to parse the next segment.
+*   .next() returns a flag indicating what type of segment was found, and stores
+*   data temporarily in couple member variables (name, content, array of
+*   attributes), which can be accessed by several .get____() methods.
+*
+*   Basically, XMLP is the lowest common denominator parser - an very simple
+*   API which other wrappers can be built against.
+**/
+
+
+var XMLP = function(strXML) {
+    // Normalize line breaks
+    strXML = SAXStrings.replace(strXML, null, null, &quot;\r\n&quot;, &quot;\n&quot;);
+    strXML = SAXStrings.replace(strXML, null, null, &quot;\r&quot;, &quot;\n&quot;);
+
+    this.m_xml = strXML;
+    this.m_iP = 0;
+    this.m_iState = XMLP._STATE_PROLOG;
+    this.m_stack = new Stack();
+    this._clearAttributes();
+
+};
+
+
+// CONSTANTS    (these must be below the constructor)
+
+
+XMLP._NONE    = 0;
+XMLP._ELM_B   = 1;
+XMLP._ELM_E   = 2;
+XMLP._ELM_EMP = 3;
+XMLP._ATT     = 4;
+XMLP._TEXT    = 5;
+XMLP._ENTITY  = 6;
+XMLP._PI      = 7;
+XMLP._CDATA   = 8;
+XMLP._COMMENT = 9;
+XMLP._DTD     = 10;
+XMLP._ERROR   = 11;
+
+XMLP._CONT_XML = 0;
+XMLP._CONT_ALT = 1;
+
+XMLP._ATT_NAME = 0;
+XMLP._ATT_VAL  = 1;
+
+XMLP._STATE_PROLOG = 1;
+XMLP._STATE_DOCUMENT = 2;
+XMLP._STATE_MISC = 3;
+
+XMLP._errs = new Array();
+XMLP._errs[XMLP.ERR_CLOSE_PI       = 0 ] = &quot;PI: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_DTD      = 1 ] = &quot;DTD: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_COMMENT  = 2 ] = &quot;Comment: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_CDATA    = 3 ] = &quot;CDATA: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_ELM      = 4 ] = &quot;Element: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_ENTITY   = 5 ] = &quot;Entity: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_PI_TARGET      = 6 ] = &quot;PI: target is required&quot;;
+XMLP._errs[XMLP.ERR_ELM_EMPTY      = 7 ] = &quot;Element: cannot be both empty and closing&quot;;
+XMLP._errs[XMLP.ERR_ELM_NAME       = 8 ] = &quot;Element: name must immediatly follow \&quot;&lt;\&quot;&quot;;
+XMLP._errs[XMLP.ERR_ELM_LT_NAME    = 9 ] = &quot;Element: \&quot;&lt;\&quot; not allowed in element names&quot;;
+XMLP._errs[XMLP.ERR_ATT_VALUES     = 10] = &quot;Attribute: values are required and must be in quotes&quot;;
+XMLP._errs[XMLP.ERR_ATT_LT_NAME    = 11] = &quot;Element: \&quot;&lt;\&quot; not allowed in attribute names&quot;;
+XMLP._errs[XMLP.ERR_ATT_LT_VALUE   = 12] = &quot;Attribute: \&quot;&lt;\&quot; not allowed in attribute values&quot;;
+XMLP._errs[XMLP.ERR_ATT_DUP        = 13] = &quot;Attribute: duplicate attributes not allowed&quot;;
+XMLP._errs[XMLP.ERR_ENTITY_UNKNOWN = 14] = &quot;Entity: unknown entity&quot;;
+XMLP._errs[XMLP.ERR_INFINITELOOP   = 15] = &quot;Infininte loop&quot;;
+XMLP._errs[XMLP.ERR_DOC_STRUCTURE  = 16] = &quot;Document: only comments, processing instructions, or whitespace allowed outside of document element&quot;;
+XMLP._errs[XMLP.ERR_ELM_NESTING    = 17] = &quot;Element: must be nested correctly&quot;;
+
+
+
+XMLP.prototype._addAttribute = function(name, value) {
+    this.m_atts[this.m_atts.length] = new Array(name, value);
+}  
+
+
+XMLP.prototype._checkStructure = function(iEvent) {
+  
+	if(XMLP._STATE_PROLOG == this.m_iState) {
+		if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
+            if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
+				return this._setErr(XMLP.ERR_DOC_STRUCTURE);
+            }
+        }
+
+        if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
+            this.m_iState = XMLP._STATE_DOCUMENT;
+            // Don't return - fall through to next state
+        }
+    }
+    if(XMLP._STATE_DOCUMENT == this.m_iState) {
+        if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
+            this.m_stack.push(this.getName());
+        }
+
+        if((XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent)) {
+            var strTop = this.m_stack.pop();
+            if((strTop == null) || (strTop != this.getName())) {
+                return this._setErr(XMLP.ERR_ELM_NESTING);
+            }
+        }
+
+        if(this.m_stack.count() == 0) {
+            this.m_iState = XMLP._STATE_MISC;
+            return iEvent;
+        }
+    }
+    if(XMLP._STATE_MISC == this.m_iState) {
+		if((XMLP._ELM_B == iEvent) || (XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent) || (XMLP.EVT_DTD == iEvent)) {
+			return this._setErr(XMLP.ERR_DOC_STRUCTURE);
+        }
+
+        if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
+			if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
+				return this._setErr(XMLP.ERR_DOC_STRUCTURE);
+            }
+        }
+    }
+
+    return iEvent;
+
+}  
+
+
+XMLP.prototype._clearAttributes = function() {
+    this.m_atts = new Array();
+}  
+
+
+XMLP.prototype._findAttributeIndex = function(name) {
+    for(var i = 0; i &lt; this.m_atts.length; i++) {
+        if(this.m_atts[i][XMLP._ATT_NAME] == name) {
+            return i;
+        }
+    }
+    return -1;
+
+}  
+
+
+XMLP.prototype.getAttributeCount = function() {
+
+    return this.m_atts ? this.m_atts.length : 0;
+
+}  
+
+
+XMLP.prototype.getAttributeName = function(index) {
+
+    return ((index &lt; 0) || (index &gt;= this.m_atts.length)) ? null : this.m_atts[index][XMLP._ATT_NAME];
+
+}  
+
+
+XMLP.prototype.getAttributeValue = function(index) {
+
+    return ((index &lt; 0) || (index &gt;= this.m_atts.length)) ? null : __unescapeXML__(this.m_atts[index][XMLP._ATT_VAL]);
+
+} 
+
+
+XMLP.prototype.getAttributeValueByName = function(name) {
+
+    return this.getAttributeValue(this._findAttributeIndex(name));
+
+}  
+
+
+XMLP.prototype.getColumnNumber = function() {
+
+    return SAXStrings.getColumnNumber(this.m_xml, this.m_iP);
+
+}  
+
+
+XMLP.prototype.getContent = function() {
+
+    return (this.m_cSrc == XMLP._CONT_XML) ? this.m_xml : this.m_cAlt;
+
+}  
+
+
+XMLP.prototype.getContentBegin = function() {
+
+    return this.m_cB;
+
+}  
+
+
+XMLP.prototype.getContentEnd = function() {
+
+    return this.m_cE;
+
+}  
+
+
+XMLP.prototype.getLineNumber = function() {
+
+    return SAXStrings.getLineNumber(this.m_xml, this.m_iP);
+
+}  
+
+
+XMLP.prototype.getName = function() {
+
+    return this.m_name;
+
+}  
+
+
+XMLP.prototype.next = function() {
+
+    return this._checkStructure(this._parse());
+
+} 
+
+
+XMLP.prototype._parse = function() {
+
+	if(this.m_iP == this.m_xml.length) {
+        return XMLP._NONE;
+    }
+
+    if(this.m_iP == this.m_xml.indexOf(&quot;&lt;?&quot;,        this.m_iP)) {
+        return this._parsePI     (this.m_iP + 2);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;!DOCTYPE&quot;, this.m_iP)) {
+        return this._parseDTD    (this.m_iP + 9);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;!--&quot;,      this.m_iP)) {
+        return this._parseComment(this.m_iP + 4);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;![CDATA[&quot;, this.m_iP)) {
+        return this._parseCDATA  (this.m_iP + 9);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;&quot;,         this.m_iP)) {
+        return this._parseElement(this.m_iP + 1);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&amp;&quot;,         this.m_iP)) {
+        return this._parseEntity (this.m_iP + 1);
+    }
+    else{
+        return this._parseText   (this.m_iP);
+    }
+	
+
+} 
+
+
+XMLP.prototype._parseAttribute = function(iB, iE) {
+    var iNB, iNE, iEq, iVB, iVE;
+    var cQuote, strN, strV;
+
+	this.m_cAlt = &quot;&quot;; //resets the value so we don't use an old one by accident (see testAttribute7 in the test suite)
+    
+	iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
+    if((iNB == -1) ||(iNB &gt;= iE)) {
+        return iNB;
+    }
+
+    iEq = this.m_xml.indexOf(&quot;=&quot;, iNB);
+    if((iEq == -1) || (iEq &gt; iE)) {
+        return this._setErr(XMLP.ERR_ATT_VALUES);
+    }
+
+    iNE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iNB, iEq);
+
+    iVB = SAXStrings.indexOfNonWhitespace(this.m_xml, iEq + 1, iE);
+    if((iVB == -1) ||(iVB &gt; iE)) {
+        return this._setErr(XMLP.ERR_ATT_VALUES);
+    }
+
+    cQuote = this.m_xml.charAt(iVB);
+    if(SAXStrings.QUOTES.indexOf(cQuote) == -1) {
+        return this._setErr(XMLP.ERR_ATT_VALUES);
+    }
+
+    iVE = this.m_xml.indexOf(cQuote, iVB + 1);
+    if((iVE == -1) ||(iVE &gt; iE)) {
+        return this._setErr(XMLP.ERR_ATT_VALUES);
+    }
+
+    strN = this.m_xml.substring(iNB, iNE + 1);
+    strV = this.m_xml.substring(iVB + 1, iVE);
+
+    if(strN.indexOf(&quot;&lt;&quot;) != -1) {
+        return this._setErr(XMLP.ERR_ATT_LT_NAME);
+    }
+
+    if(strV.indexOf(&quot;&lt;&quot;) != -1) {
+        return this._setErr(XMLP.ERR_ATT_LT_VALUE);
+    }
+
+    strV = SAXStrings.replace(strV, null, null, &quot;\n&quot;, &quot; &quot;);
+    strV = SAXStrings.replace(strV, null, null, &quot;\t&quot;, &quot; &quot;);
+	iRet = this._replaceEntities(strV);
+    if(iRet == XMLP._ERROR) {
+        return iRet;
+    }
+
+    strV = this.m_cAlt;
+
+    if(this._findAttributeIndex(strN) == -1) {
+        this._addAttribute(strN, strV);
+    }
+    else {
+        return this._setErr(XMLP.ERR_ATT_DUP);
+    }
+
+    this.m_iP = iVE + 2;
+
+    return XMLP._ATT;
+
+}  
+
+
+XMLP.prototype._parseCDATA = function(iB) {
+    var iE = this.m_xml.indexOf(&quot;]]&gt;&quot;, iB);
+    if (iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_CDATA);
+    }
+
+    this._setContent(XMLP._CONT_XML, iB, iE);
+
+    this.m_iP = iE + 3;
+
+    return XMLP._CDATA;
+
+}  
+
+
+XMLP.prototype._parseComment = function(iB) {
+    var iE = this.m_xml.indexOf(&quot;-&quot; + &quot;-&gt;&quot;, iB);
+    if (iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_COMMENT);
+    }
+
+    this._setContent(XMLP._CONT_XML, iB, iE);
+
+    this.m_iP = iE + 3;
+
+    return XMLP._COMMENT;
+
+}  
+
+
+XMLP.prototype._parseDTD = function(iB) {
+
+    // Eat DTD
+
+    var iE, strClose, iInt, iLast;
+
+    iE = this.m_xml.indexOf(&quot;&gt;&quot;, iB);
+    if(iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_DTD);
+    }
+
+    iInt = this.m_xml.indexOf(&quot;[&quot;, iB);
+    strClose = ((iInt != -1) &amp;&amp; (iInt &lt; iE)) ? &quot;]&gt;&quot; : &quot;&gt;&quot;;
+
+    while(true) {
+        // DEBUG: Remove
+        if(iE == iLast) {
+            return this._setErr(XMLP.ERR_INFINITELOOP);
+        }
+
+        iLast = iE;
+        // DEBUG: Remove End
+
+        iE = this.m_xml.indexOf(strClose, iB);
+        if(iE == -1) {
+            return this._setErr(XMLP.ERR_CLOSE_DTD);
+        }
+
+        // Make sure it is not the end of a CDATA section
+        if (this.m_xml.substring(iE - 1, iE + 2) != &quot;]]&gt;&quot;) {
+            break;
+        }
+    }
+
+    this.m_iP = iE + strClose.length;
+
+    return XMLP._DTD;
+
+}  
+
+
+XMLP.prototype._parseElement = function(iB) {
+    var iE, iDE, iNE, iRet;
+    var iType, strN, iLast;
+
+    iDE = iE = this.m_xml.indexOf(&quot;&gt;&quot;, iB);
+    if(iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_ELM);
+    }
+
+    if(this.m_xml.charAt(iB) == &quot;/&quot;) {
+        iType = XMLP._ELM_E;
+        iB++;
+    } else {
+        iType = XMLP._ELM_B;
+    }
+
+    if(this.m_xml.charAt(iE - 1) == &quot;/&quot;) {
+        if(iType == XMLP._ELM_E) {
+            return this._setErr(XMLP.ERR_ELM_EMPTY);
+        }
+        iType = XMLP._ELM_EMP;
+        iDE--;
+    }
+
+    iDE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iB, iDE);
+
+    //djohack
+    //hack to allow for elements with single character names to be recognized
+
+    if (iE - iB != 1 ) {
+        if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB) {
+            return this._setErr(XMLP.ERR_ELM_NAME);
+        }
+    }
+    // end hack -- original code below
+
+    /*
+    if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB)
+        return this._setErr(XMLP.ERR_ELM_NAME);
+    */
+    this._clearAttributes();
+
+    iNE = SAXStrings.indexOfWhitespace(this.m_xml, iB, iDE);
+    if(iNE == -1) {
+        iNE = iDE + 1;
+    }
+    else {
+        this.m_iP = iNE;
+        while(this.m_iP &lt; iDE) {
+            // DEBUG: Remove
+            if(this.m_iP == iLast) return this._setErr(XMLP.ERR_INFINITELOOP);
+            iLast = this.m_iP;
+            // DEBUG: Remove End
+
+
+            iRet = this._parseAttribute(this.m_iP, iDE);
+            if(iRet == XMLP._ERROR) return iRet;
+        }
+    }
+
+    strN = this.m_xml.substring(iB, iNE);
+
+    if(strN.indexOf(&quot;&lt;&quot;) != -1) {
+        return this._setErr(XMLP.ERR_ELM_LT_NAME);
+    }
+
+    this.m_name = strN;
+    this.m_iP = iE + 1;
+
+    return iType;
+
+}  
+
+
+XMLP.prototype._parseEntity = function(iB) {
+    var iE = this.m_xml.indexOf(&quot;;&quot;, iB);
+    if(iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_ENTITY);
+    }
+
+    this.m_iP = iE + 1;
+
+    return this._replaceEntity(this.m_xml, iB, iE);
+
+} 
+
+
+XMLP.prototype._parsePI = function(iB) {
+
+    var iE, iTB, iTE, iCB, iCE;
+
+    iE = this.m_xml.indexOf(&quot;?&gt;&quot;, iB);
+    if(iE   == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_PI);
+    }
+
+    iTB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
+    if(iTB == -1) {
+        return this._setErr(XMLP.ERR_PI_TARGET);
+    }
+
+    iTE = SAXStrings.indexOfWhitespace(this.m_xml, iTB, iE);
+    if(iTE  == -1) {
+        iTE = iE;
+    }
+
+    iCB = SAXStrings.indexOfNonWhitespace(this.m_xml, iTE, iE);
+    if(iCB == -1) {
+        iCB = iE;
+    }
+
+    iCE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iCB, iE);
+    if(iCE  == -1) {
+        iCE = iE - 1;
+    }
+
+    this.m_name = this.m_xml.substring(iTB, iTE);
+    this._setContent(XMLP._CONT_XML, iCB, iCE + 1);
+    this.m_iP = iE + 2;
+
+    return XMLP._PI;
+
+}  
+
+
+XMLP.prototype._parseText = function(iB) {
+    var iE, iEE;
+
+    iE = this.m_xml.indexOf(&quot;&lt;&quot;, iB);
+    if(iE == -1) {
+        iE = this.m_xml.length;
+    }
+
+    iEE = this.m_xml.indexOf(&quot;&amp;&quot;, iB);
+    if((iEE != -1) &amp;&amp; (iEE &lt;= iE)) {
+        iE = iEE;
+    }
+
+    this._setContent(XMLP._CONT_XML, iB, iE);
+
+    this.m_iP = iE;
+
+    return XMLP._TEXT;
+
+} 
+
+
+XMLP.prototype._replaceEntities = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) return &quot;&quot;;
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+
+    var iEB, iEE, strRet = &quot;&quot;;
+
+    iEB = strD.indexOf(&quot;&amp;&quot;, iB);
+    iEE = iB;
+
+    while((iEB &gt; 0) &amp;&amp; (iEB &lt; iE)) {
+        strRet += strD.substring(iEE, iEB);
+
+        iEE = strD.indexOf(&quot;;&quot;, iEB) + 1;
+
+        if((iEE == 0) || (iEE &gt; iE)) {
+            return this._setErr(XMLP.ERR_CLOSE_ENTITY);
+        }
+
+        iRet = this._replaceEntity(strD, iEB + 1, iEE - 1);
+        if(iRet == XMLP._ERROR) {
+            return iRet;
+        }
+
+        strRet += this.m_cAlt;
+
+        iEB = strD.indexOf(&quot;&amp;&quot;, iEE);
+    }
+
+    if(iEE != iE) {
+        strRet += strD.substring(iEE, iE);
+    }
+
+    this._setContent(XMLP._CONT_ALT, strRet);
+
+    return XMLP._ENTITY;
+
+}  
+
+
+XMLP.prototype._replaceEntity = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) return -1;
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    switch(strD.substring(iB, iE)) {
+        case &quot;amp&quot;:  strEnt = &quot;&amp;&quot;;  break;
+        case &quot;lt&quot;:   strEnt = &quot;&lt;&quot;;  break;
+        case &quot;gt&quot;:   strEnt = &quot;&gt;&quot;;  break;
+        case &quot;apos&quot;: strEnt = &quot;'&quot;;  break;
+        case &quot;quot&quot;: strEnt = &quot;\&quot;&quot;; break;
+        default:
+            if(strD.charAt(iB) == &quot;#&quot;) {
+                strEnt = String.fromCharCode(parseInt(strD.substring(iB + 1, iE)));
+            } else {
+                return this._setErr(XMLP.ERR_ENTITY_UNKNOWN);
+            }
+        break;
+    }
+    this._setContent(XMLP._CONT_ALT, strEnt);
+
+    return XMLP._ENTITY;
+}  
+
+
+XMLP.prototype._setContent = function(iSrc) {
+    var args = arguments;
+
+    if(XMLP._CONT_XML == iSrc) {
+        this.m_cAlt = null;
+        this.m_cB = args[1];
+        this.m_cE = args[2];
+    } else {
+        this.m_cAlt = args[1];
+        this.m_cB = 0;
+        this.m_cE = args[1].length;
+    }
+    this.m_cSrc = iSrc;
+
+}  
+
+
+XMLP.prototype._setErr = function(iErr) {
+    var strErr = XMLP._errs[iErr];
+
+    this.m_cAlt = strErr;
+    this.m_cB = 0;
+    this.m_cE = strErr.length;
+    this.m_cSrc = XMLP._CONT_ALT;
+
+    return XMLP._ERROR;
+
+}  
+
+
+/**
+* function:   SAXDriver
+* Author:   Scott Severtson
+* Description:
+*    SAXDriver is an object that basically wraps an XMLP instance, and provides an
+*   event-based interface for parsing. This is the object users interact with when coding
+*   with XML for &lt;SCRIPT&gt;
+**/
+
+var SAXDriver = function() {
+    this.m_hndDoc = null;
+    this.m_hndErr = null;
+    this.m_hndLex = null;
+}
+
+
+// CONSTANTS
+SAXDriver.DOC_B = 1;
+SAXDriver.DOC_E = 2;
+SAXDriver.ELM_B = 3;
+SAXDriver.ELM_E = 4;
+SAXDriver.CHARS = 5;
+SAXDriver.PI    = 6;
+SAXDriver.CD_B  = 7;
+SAXDriver.CD_E  = 8;
+SAXDriver.CMNT  = 9;
+SAXDriver.DTD_B = 10;
+SAXDriver.DTD_E = 11;
+
+
+
+SAXDriver.prototype.parse = function(strD) {
+    var parser = new XMLP(strD);
+
+    if(this.m_hndDoc &amp;&amp; this.m_hndDoc.setDocumentLocator) {
+        this.m_hndDoc.setDocumentLocator(this);
+    }
+
+    this.m_parser = parser;
+    this.m_bErr = false;
+
+    if(!this.m_bErr) {
+        this._fireEvent(SAXDriver.DOC_B);
+    }
+    this._parseLoop();
+    if(!this.m_bErr) {
+        this._fireEvent(SAXDriver.DOC_E);
+    }
+
+    this.m_xml = null;
+    this.m_iP = 0;
+
+}  
+
+
+SAXDriver.prototype.setDocumentHandler = function(hnd) {
+
+    this.m_hndDoc = hnd;
+
+}   
+
+
+SAXDriver.prototype.setErrorHandler = function(hnd) {
+
+    this.m_hndErr = hnd;
+
+}  
+
+
+SAXDriver.prototype.setLexicalHandler = function(hnd) {
+
+    this.m_hndLex = hnd;
+
+}  
+
+
+    /**
+    * LOCATOR/PARSE EXCEPTION INTERFACE
+    ***/
+
+SAXDriver.prototype.getColumnNumber = function() {
+
+    return this.m_parser.getColumnNumber();
+
+}
+
+
+SAXDriver.prototype.getLineNumber = function() {
+
+    return this.m_parser.getLineNumber();
+
+}
+
+
+SAXDriver.prototype.getMessage = function() {
+
+    return this.m_strErrMsg;
+
+}
+
+
+SAXDriver.prototype.getPublicId = function() {
+
+    return null;
+
+}  
+
+
+SAXDriver.prototype.getSystemId = function() {
+
+    return null;
+
+}  
+
+
+    /***
+    * Attribute List Interface
+    **/
+
+SAXDriver.prototype.getLength = function() {
+
+    return this.m_parser.getAttributeCount();
+
+}  
+
+
+SAXDriver.prototype.getName = function(index) {
+
+    return this.m_parser.getAttributeName(index);
+
+} 
+
+
+SAXDriver.prototype.getValue = function(index) {
+
+    return this.m_parser.getAttributeValue(index);
+
+}  
+
+
+SAXDriver.prototype.getValueByName = function(name) {
+
+    return this.m_parser.getAttributeValueByName(name);
+
+} 
+
+
+    /***
+    *    Private functions
+    **/
+
+SAXDriver.prototype._fireError = function(strMsg) {
+    this.m_strErrMsg = strMsg;
+    this.m_bErr = true;
+
+    if(this.m_hndErr &amp;&amp; this.m_hndErr.fatalError) {
+        this.m_hndErr.fatalError(this);
+    }
+
+}   // end function _fireError
+
+
+SAXDriver.prototype._fireEvent = function(iEvt) {
+    var hnd, func, args = arguments, iLen = args.length - 1;
+
+    if(this.m_bErr) return;
+
+    if(SAXDriver.DOC_B == iEvt) {
+        func = &quot;startDocument&quot;;         hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.DOC_E == iEvt) {
+        func = &quot;endDocument&quot;;           hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.ELM_B == iEvt) {
+        func = &quot;startElement&quot;;          hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.ELM_E == iEvt) {
+        func = &quot;endElement&quot;;            hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.CHARS == iEvt) {
+        func = &quot;characters&quot;;            hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.PI    == iEvt) {
+        func = &quot;processingInstruction&quot;; hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.CD_B  == iEvt) {
+        func = &quot;startCDATA&quot;;            hnd = this.m_hndLex;
+    }
+    else if (SAXDriver.CD_E  == iEvt) {
+        func = &quot;endCDATA&quot;;              hnd = this.m_hndLex;
+    }
+    else if (SAXDriver.CMNT  == iEvt) {
+        func = &quot;comment&quot;;               hnd = this.m_hndLex;
+    }
+
+    if(hnd &amp;&amp; hnd[func]) {
+        if(0 == iLen) {
+            hnd[func]();
+        }
+        else if (1 == iLen) {
+            hnd[func](args[1]);
+        }
+        else if (2 == iLen) {
+            hnd[func](args[1], args[2]);
+        }
+        else if (3 == iLen) {
+            hnd[func](args[1], args[2], args[3]);
+        }
+    }
+
+}  // end function _fireEvent
+
+
+SAXDriver.prototype._parseLoop = function(parser) {
+    var iEvent, parser;
+
+    parser = this.m_parser;
+    while(!this.m_bErr) {
+        iEvent = parser.next();
+
+        if(iEvent == XMLP._ELM_B) {
+            this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
+        }
+        else if(iEvent == XMLP._ELM_E) {
+            this._fireEvent(SAXDriver.ELM_E, parser.getName());
+        }
+        else if(iEvent == XMLP._ELM_EMP) {
+            this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
+            this._fireEvent(SAXDriver.ELM_E, parser.getName());
+        }
+        else if(iEvent == XMLP._TEXT) {
+            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+        }
+        else if(iEvent == XMLP._ENTITY) {
+            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+        }
+        else if(iEvent == XMLP._PI) {
+            this._fireEvent(SAXDriver.PI, parser.getName(), parser.getContent().substring(parser.getContentBegin(), parser.getContentEnd()));
+        }
+        else if(iEvent == XMLP._CDATA) {
+            this._fireEvent(SAXDriver.CD_B);
+            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+            this._fireEvent(SAXDriver.CD_E);
+        }
+        else if(iEvent == XMLP._COMMENT) {
+            this._fireEvent(SAXDriver.CMNT, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+        }
+        else if(iEvent == XMLP._DTD) {
+        }
+        else if(iEvent == XMLP._ERROR) {
+            this._fireError(parser.getContent());
+        }
+        else if(iEvent == XMLP._NONE) {
+            return;
+        }
+    }
+
+}  // end function _parseLoop
+
+/**
+*   function:   SAXStrings
+*   Author:   Scott Severtson
+*   Description: a useful object containing string manipulation functions
+**/
+
+var SAXStrings = function() {};
+
+
+SAXStrings.WHITESPACE = &quot; \t\n\r&quot;;
+SAXStrings.QUOTES = &quot;\&quot;'&quot;;
+
+
+SAXStrings.getColumnNumber = function(strD, iP) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iP = iP || strD.length;
+
+    var arrD = strD.substring(0, iP).split(&quot;\n&quot;);
+    var strLine = arrD[arrD.length - 1];
+    arrD.length--;
+    var iLinePos = arrD.join(&quot;\n&quot;).length;
+
+    return iP - iLinePos;
+
+}  // end function getColumnNumber
+
+
+SAXStrings.getLineNumber = function(strD, iP) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iP = iP || strD.length;
+
+    return strD.substring(0, iP).split(&quot;\n&quot;).length
+}  // end function getLineNumber
+
+
+SAXStrings.indexOfNonWhitespace = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    for(var i = iB; i &lt; iE; i++){
+        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1) {
+            return i;
+        }
+    }
+    return -1;
+
+}  // end function indexOfNonWhitespace
+
+
+SAXStrings.indexOfWhitespace = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    for(var i = iB; i &lt; iE; i++) {
+        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) != -1) {
+            return i;
+        }
+    }
+    return -1;
+}  // end function indexOfWhitespace
+
+
+SAXStrings.isEmpty = function(strD) {
+
+    return (strD == null) || (strD.length == 0);
+
+}
+
+
+SAXStrings.lastIndexOfNonWhitespace = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    for(var i = iE - 1; i &gt;= iB; i--){
+        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1){
+            return i;
+        }
+    }
+    return -1;
+}
+
+
+SAXStrings.replace = function(strD, iB, iE, strF, strR) {
+    if(SAXStrings.isEmpty(strD)) {
+        return &quot;&quot;;
+    }
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    return strD.substring(iB, iE).split(strF).join(strR);
+
+}
+
+
+
+/***************************************************************************************************************
+Stack: A simple stack class, used for verifying document structure.
+
+    Author:   Scott Severtson
+*****************************************************************************************************************/
+
+var Stack = function() {
+    this.m_arr = new Array();
+}; 
+__extend__(Stack.prototype, {
+    clear : function() {
+        this.m_arr = new Array();
+    },
+    count : function() {
+        return this.m_arr.length;
+    },
+    destroy : function() {
+        this.m_arr = null;
+    },
+    peek : function() {
+        if(this.m_arr.length == 0) {
+            return null;
+        }
+        return this.m_arr[this.m_arr.length - 1];
+    },
+    pop : function() {
+        if(this.m_arr.length == 0) {
+            return null;
+        }
+        var o = this.m_arr[this.m_arr.length - 1];
+        this.m_arr.length--;
+        return o;
+    },
+    push : function(o) {
+        this.m_arr[this.m_arr.length] = o;
+    }
+});    
+
+
+/**
+* function: isEmpty
+* Author: mike@idle.org
+* Description:  convenience function to identify an empty string
+**/
+function isEmpty(str) {
+    return (str==null) || (str.length==0);
+};
+
+
+/**
+ * function __escapeXML__
+ * author: David Joham djoham@yahoo.com
+ * @param  str : string - The string to be escaped
+ * @return : string - The escaped string
+ */
+var escAmpRegEx = /&amp;/g;
+var escLtRegEx = /&lt;/g;
+var escGtRegEx = /&gt;/g;
+var quotRegEx = /&quot;/g;
+var aposRegEx = /'/g;
+function __escapeXML__(str) {
+    str = str.replace(escAmpRegEx, &quot;&amp;amp;&quot;).
+            replace(escLtRegEx, &quot;&amp;lt;&quot;).
+            replace(escGtRegEx, &quot;&amp;gt;&quot;).
+            replace(quotRegEx, &quot;&amp;quot;&quot;).
+            replace(aposRegEx, &quot;&amp;apos;&quot;);
+
+    return str;
+};
+
+/**
+ * function __unescapeXML__ 
+ * author: David Joham djoham@yahoo.com
+ * @param  str : string - The string to be unescaped
+ * @return : string - The unescaped string
+ */
+var unescAmpRegEx = /&amp;amp;/g;
+var unescLtRegEx = /&amp;lt;/g;
+var unescGtRegEx = /&amp;gt;/g;
+var unquotRegEx = /&amp;quot;/g;
+var unaposRegEx = /&amp;apos;/g;
+function __unescapeXML__(str) {
+    str = str.replace(unescAmpRegEx, &quot;&amp;&quot;).
+            replace(unescLtRegEx, &quot;&lt;&quot;).
+            replace(unescGtRegEx, &quot;&gt;&quot;).
+            replace(unquotRegEx, &quot;\&quot;&quot;).
+            replace(unaposRegEx, &quot;'&quot;);
+
+    return str;
+};
+
+//DOMImplementation
+$log(&quot;Defining DOMImplementation&quot;);
+$w.__defineGetter__(&quot;DOMImplementation&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMImplementation - provides a number of methods for performing operations
+ *   that are independent of any particular instance of the document object model.
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ */
+var DOMImplementation = function() {
+    this.preserveWhiteSpace = false;  // by default, ignore whitespace
+    this.namespaceAware = true;       // by default, handle namespaces
+    this.errorChecking  = true;       // by default, test for exceptions
+};
+__extend__(DOMImplementation.prototype,{
+    // @param  feature : string - The package name of the feature to test. 
+    //      the legal only values are &quot;XML&quot; and &quot;CORE&quot; (case-insensitive).
+    // @param  version : string - This is the version number of the package
+    //       name to test. In Level 1, this is the string &quot;1.0&quot;.*
+    // @return : boolean
+    hasFeature : function(feature, version) {
+        var ret = false;
+        if (feature.toLowerCase() == &quot;xml&quot;) {
+            ret = (!version || (version == &quot;1.0&quot;) || (version == &quot;2.0&quot;));
+        }
+        else if (feature.toLowerCase() == &quot;core&quot;) {
+            ret = (!version || (version == &quot;2.0&quot;));
+        }
+        return ret;
+    },
+	createDocumentType : function(qname, publicid, systemid){
+		return new DOMDocumentType();
+	},
+	createDocument : function(nsuri, qname, doctype){
+	  //TODO - this currently returns an empty doc
+	  //but needs to handle the args
+		return new HTMLDocument($implementation);
+	},
+    translateErrCode : function(code) {
+        //convert DOMException Code to human readable error message;
+      var msg = &quot;&quot;;
+    
+      switch (code) {
+        case DOMException.INDEX_SIZE_ERR :                // 1
+           msg = &quot;INDEX_SIZE_ERR: Index out of bounds&quot;;
+           break;
+    
+        case DOMException.DOMSTRING_SIZE_ERR :            // 2
+           msg = &quot;DOMSTRING_SIZE_ERR: The resulting string is too long to fit in a DOMString&quot;;
+           break;
+    
+        case DOMException.HIERARCHY_REQUEST_ERR :         // 3
+           msg = &quot;HIERARCHY_REQUEST_ERR: The Node can not be inserted at this location&quot;;
+           break;
+    
+        case DOMException.WRONG_DOCUMENT_ERR :            // 4
+           msg = &quot;WRONG_DOCUMENT_ERR: The source and the destination Documents are not the same&quot;;
+           break;
+    
+        case DOMException.INVALID_CHARACTER_ERR :         // 5
+           msg = &quot;INVALID_CHARACTER_ERR: The string contains an invalid character&quot;;
+           break;
+    
+        case DOMException.NO_DATA_ALLOWED_ERR :           // 6
+           msg = &quot;NO_DATA_ALLOWED_ERR: This Node / NodeList does not support data&quot;;
+           break;
+    
+        case DOMException.NO_MODIFICATION_ALLOWED_ERR :   // 7
+           msg = &quot;NO_MODIFICATION_ALLOWED_ERR: This object cannot be modified&quot;;
+           break;
+    
+        case DOMException.NOT_FOUND_ERR :                 // 8
+           msg = &quot;NOT_FOUND_ERR: The item cannot be found&quot;;
+           break;
+    
+        case DOMException.NOT_SUPPORTED_ERR :             // 9
+           msg = &quot;NOT_SUPPORTED_ERR: This implementation does not support function&quot;;
+           break;
+    
+        case DOMException.INUSE_ATTRIBUTE_ERR :           // 10
+           msg = &quot;INUSE_ATTRIBUTE_ERR: The Attribute has already been assigned to another Element&quot;;
+           break;
+    
+        // Introduced in DOM Level 2:
+        case DOMException.INVALID_STATE_ERR :             // 11
+           msg = &quot;INVALID_STATE_ERR: The object is no longer usable&quot;;
+           break;
+    
+        case DOMException.SYNTAX_ERR :                    // 12
+           msg = &quot;SYNTAX_ERR: Syntax error&quot;;
+           break;
+    
+        case DOMException.INVALID_MODIFICATION_ERR :      // 13
+           msg = &quot;INVALID_MODIFICATION_ERR: Cannot change the type of the object&quot;;
+           break;
+    
+        case DOMException.NAMESPACE_ERR :                 // 14
+           msg = &quot;NAMESPACE_ERR: The namespace declaration is incorrect&quot;;
+           break;
+    
+        case DOMException.INVALID_ACCESS_ERR :            // 15
+           msg = &quot;INVALID_ACCESS_ERR: The object does not support this function&quot;;
+           break;
+    
+        default :
+           msg = &quot;UNKNOWN: Unknown Exception Code (&quot;+ code +&quot;)&quot;;
+      }
+    
+      return msg;
+    }
+});
+  
+
+/**
+* Defined 'globally' to this scope.  Remember everything is wrapped in a closure so this doesnt show up 
+* in the outer most global scope.
+*/
+  
+/**
+ *  process SAX events
+ *
+ * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
+ *
+ * @param  impl : DOMImplementation
+ * @param  doc : DOMDocument - the Document to contain the parsed XML string
+ * @param  p   : XMLP        - the SAX Parser
+ *
+ * @return : DOMDocument
+ */
+function __parseLoop__(impl, doc, p) {
+  var iEvt, iNode, iAttr, strName;
+  iNodeParent = doc;
+
+  var el_close_count = 0;
+
+  var entitiesList = new Array();
+  var textNodesList = new Array();
+
+  // if namespaceAware, add default namespace
+  if (impl.namespaceAware) {
+    var iNS = doc.createNamespace(&quot;&quot;); // add the default-default namespace
+    iNS.value = &quot;http://www.w3.org/2000/xmlns/&quot;;
+    doc._namespaces.setNamedItem(iNS);
+  }
+
+  // loop until SAX parser stops emitting events
+  while(true) {
+    // get next event
+    iEvt = p.next();
+
+    if (iEvt == XMLP._ELM_B) {                      // Begin-Element Event
+      var pName = p.getName();                      // get the Element name
+      pName = trim(pName, true, true);              // strip spaces from Element name
+
+      if (!impl.namespaceAware) {
+        iNode = doc.createElement(p.getName());     // create the Element
+
+        // add attributes to Element
+        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
+          strName = p.getAttributeName(i);          // get Attribute name
+          iAttr = iNode.getAttributeNode(strName);  // if Attribute exists, use it
+
+          if(!iAttr) {
+            iAttr = doc.createAttribute(strName);   // otherwise create it
+          }
+
+          iAttr.value = p.getAttributeValue(i);   // set Attribute value
+          iNode.setAttributeNode(iAttr);            // attach Attribute to Element
+        }
+      }
+      else {  // Namespace Aware
+        // create element (with empty namespaceURI,
+        //  resolve after namespace 'attributes' have been parsed)
+        iNode = doc.createElementNS(&quot;&quot;, p.getName());
+
+        // duplicate ParentNode's Namespace definitions
+        iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
+
+        // add attributes to Element
+        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
+          strName = p.getAttributeName(i);          // get Attribute name
+
+          // if attribute is a namespace declaration
+          if (__isNamespaceDeclaration__(strName)) {
+            // parse Namespace Declaration
+            var namespaceDec = __parseNSName__(strName);
+
+            if (strName != &quot;xmlns&quot;) {
+              iNS = doc.createNamespace(strName);   // define namespace
+            }
+            else {
+              iNS = doc.createNamespace(&quot;&quot;);        // redefine default namespace
+            }
+            iNS.value = p.getAttributeValue(i);   // set value = namespaceURI
+
+            iNode._namespaces.setNamedItem(iNS);    // attach namespace to namespace collection
+          }
+          else {  // otherwise, it is a normal attribute
+            iAttr = iNode.getAttributeNode(strName);        // if Attribute exists, use it
+
+            if(!iAttr) {
+              iAttr = doc.createAttributeNS(&quot;&quot;, strName);   // otherwise create it
+            }
+
+            iAttr.value = p.getAttributeValue(i);         // set Attribute value
+            iNode.setAttributeNodeNS(iAttr);                // attach Attribute to Element
+
+            if (__isIdDeclaration__(strName)) {
+              iNode.id = p.getAttributeValue(i);    // cache ID for getElementById()
+            }
+          }
+        }
+
+        // resolve namespaceURIs for this Element
+        if (iNode._namespaces.getNamedItem(iNode.prefix)) {
+          iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
+        }
+
+        //  for this Element's attributes
+        for (var i = 0; i &lt; iNode.attributes.length; i++) {
+          if (iNode.attributes.item(i).prefix != &quot;&quot;) {  // attributes do not have a default namespace
+            if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
+              iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
+            }
+          }
+        }
+      }
+
+      // if this is the Root Element
+      if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
+        iNodeParent.documentElement = iNode;        // register this Element as the Document.documentElement
+      }
+
+      iNodeParent.appendChild(iNode);               // attach Element to parentNode
+      iNodeParent = iNode;                          // descend one level of the DOM Tree
+    }
+
+    else if(iEvt == XMLP._ELM_E) {                  // End-Element Event
+      iNodeParent = iNodeParent.parentNode;         // ascend one level of the DOM Tree
+    }
+
+    else if(iEvt == XMLP._ELM_EMP) {                // Empty Element Event
+      pName = p.getName();                          // get the Element name
+      pName = trim(pName, true, true);              // strip spaces from Element name
+
+      if (!impl.namespaceAware) {
+        iNode = doc.createElement(pName);           // create the Element
+
+        // add attributes to Element
+        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
+          strName = p.getAttributeName(i);          // get Attribute name
+          iAttr = iNode.getAttributeNode(strName);  // if Attribute exists, use it
+
+          if(!iAttr) {
+            iAttr = doc.createAttribute(strName);   // otherwise create it
+          }
+
+          iAttr.value = p.getAttributeValue(i);   // set Attribute value
+          iNode.setAttributeNode(iAttr);            // attach Attribute to Element
+        }
+      }
+      else {  // Namespace Aware
+        // create element (with empty namespaceURI,
+        //  resolve after namespace 'attributes' have been parsed)
+        iNode = doc.createElementNS(&quot;&quot;, p.getName());
+
+        // duplicate ParentNode's Namespace definitions
+        iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
+
+        // add attributes to Element
+        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
+          strName = p.getAttributeName(i);          // get Attribute name
+
+          // if attribute is a namespace declaration
+          if (__isNamespaceDeclaration__(strName)) {
+            // parse Namespace Declaration
+            var namespaceDec = __parseNSName__(strName);
+
+            if (strName != &quot;xmlns&quot;) {
+              iNS = doc.createNamespace(strName);   // define namespace
+            }
+            else {
+              iNS = doc.createNamespace(&quot;&quot;);        // redefine default namespace
+            }
+            iNS.value = p.getAttributeValue(i);   // set value = namespaceURI
+
+            iNode._namespaces.setNamedItem(iNS);    // attach namespace to namespace collection
+          }
+          else {  // otherwise, it is a normal attribute
+            iAttr = iNode.getAttributeNode(strName);        // if Attribute exists, use it
+
+            if(!iAttr) {
+              iAttr = doc.createAttributeNS(&quot;&quot;, strName);   // otherwise create it
+            }
+
+            iAttr.value = p.getAttributeValue(i);         // set Attribute value
+            iNode.setAttributeNodeNS(iAttr);                // attach Attribute to Element
+
+            if (__isIdDeclaration__(strName)) {
+              iNode.id = p.getAttributeValue(i);    // cache ID for getElementById()
+            }
+          }
+        }
+
+        // resolve namespaceURIs for this Element
+        if (iNode._namespaces.getNamedItem(iNode.prefix)) {
+          iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
+        }
+
+        //  for this Element's attributes
+        for (var i = 0; i &lt; iNode.attributes.length; i++) {
+          if (iNode.attributes.item(i).prefix != &quot;&quot;) {  // attributes do not have a default namespace
+            if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
+              iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
+            }
+          }
+        }
+      }
+
+      // if this is the Root Element
+      if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
+        iNodeParent.documentElement = iNode;        // register this Element as the Document.documentElement
+      }
+
+      iNodeParent.appendChild(iNode);               // attach Element to parentNode
+    }
+    else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) {                   // TextNode and entity Events
+      // get Text content
+      var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
+      
+	  if (!impl.preserveWhiteSpace ) {
+		if (trim(pContent, true, true) == &quot;&quot;) {
+			pContent = &quot;&quot;; //this will cause us not to create the text node below
+		}
+	  }
+	  
+      if (pContent.length &gt; 0) {                    // ignore empty TextNodes
+        var textNode = doc.createTextNode(pContent);
+        iNodeParent.appendChild(textNode); // attach TextNode to parentNode
+
+        //the sax parser breaks up text nodes when it finds an entity. For
+        //example hello&amp;lt;there will fire a text, an entity and another text
+        //this sucks for the dom parser because it looks to us in this logic
+        //as three text nodes. I fix this by keeping track of the entity nodes
+        //and when we're done parsing, calling normalize on their parent to
+        //turn the multiple text nodes into one, which is what DOM users expect
+        //the code to do this is at the bottom of this function
+        if (iEvt == XMLP._ENTITY) {
+            entitiesList[entitiesList.length] = textNode;
+        }
+		else {
+			//I can't properly decide how to handle preserve whitespace
+			//until the siblings of the text node are built due to 
+			//the entitiy handling described above. I don't know that this
+			//will be all of the text node or not, so trimming is not appropriate
+			//at this time. Keep a list of all the text nodes for now
+			//and we'll process the preserve whitespace stuff at a later time.
+			textNodesList[textNodesList.length] = textNode;
+		}
+      }
+    }
+    else if(iEvt == XMLP._PI) {                     // ProcessingInstruction Event
+      // attach ProcessingInstruction to parentNode
+      iNodeParent.appendChild(doc.createProcessingInstruction(p.getName(), p.getContent().substring(p.getContentBegin(), p.getContentEnd())));
+    }
+    else if(iEvt == XMLP._CDATA) {                  // CDATA Event
+      // get CDATA data
+      pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
+
+      if (!impl.preserveWhiteSpace) {
+        pContent = trim(pContent, true, true);      // trim whitespace
+        pContent.replace(/ +/g, ' ');               // collapse multiple spaces to 1 space
+      }
+
+      if (pContent.length &gt; 0) {                    // ignore empty CDATANodes
+        iNodeParent.appendChild(doc.createCDATASection(pContent)); // attach CDATA to parentNode
+      }
+    }
+    else if(iEvt == XMLP._COMMENT) {                // Comment Event
+      // get COMMENT data
+      var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
+
+      if (!impl.preserveWhiteSpace) {
+        pContent = trim(pContent, true, true);      // trim whitespace
+        pContent.replace(/ +/g, ' ');               // collapse multiple spaces to 1 space
+      }
+
+      if (pContent.length &gt; 0) {                    // ignore empty CommentNodes
+        iNodeParent.appendChild(doc.createComment(pContent));  // attach Comment to parentNode
+      }
+    }
+    else if(iEvt == XMLP._DTD) {                    // ignore DTD events
+    }
+    else if(iEvt == XMLP._ERROR) {
+        $error(&quot;Fatal Error: &quot; + p.getContent() + &quot;\nLine: &quot; + p.getLineNumber() + &quot;\nColumn: &quot; + p.getColumnNumber() + &quot;\n&quot;);
+        throw(new DOMException(DOMException.SYNTAX_ERR));
+      // alert(&quot;Fatal Error: &quot; + p.getContent() + &quot;\nLine: &quot; + p.getLineNumber() + &quot;\nColumn: &quot; + p.getColumnNumber() + &quot;\n&quot;);
+      // break;
+    }
+    else if(iEvt == XMLP._NONE) {                   // no more events
+      if (iNodeParent == doc) {                     // confirm that we have recursed back up to root
+        break;
+      }
+      else {
+        throw(new DOMException(DOMException.SYNTAX_ERR));  // one or more Tags were not closed properly
+      }
+    }
+  }
+
+  //normalize any entities in the DOM to a single textNode
+  for (var i = 0; i &lt; entitiesList.length; i++) {
+      var entity = entitiesList[i];
+      //its possible (if for example two entities were in the
+      //same domnode, that the normalize on the first entitiy
+      //will remove the parent for the second. Only do normalize
+      //if I can find a parent node
+      var parentNode = entity.parentNode;
+      if (parentNode) {
+          parentNode.normalize();
+		  
+		  //now do whitespace (if necessary)
+		  //it was not done for text nodes that have entities
+		  if(!impl.preserveWhiteSpace) {
+		  		var children = parentNode.childNodes;
+				for ( var j = 0; j &lt; children.length; j++) {
+					var child = children.item(j);
+					if (child.nodeType == DOMNode.TEXT_NODE) {
+						var childData = child.data;
+						childData.replace(/\s/g, ' ');
+						child.data = childData;
+					}
+				}
+		  }
+      }
+  }
+  
+  //do the preserve whitespace processing on the rest of the text nodes
+  //It's possible (due to the processing above) that the node will have been
+  //removed from the tree. Only do whitespace checking if parentNode is not null.
+  //This may duplicate the whitespace processing for some nodes that had entities in them
+  //but there's no way around that
+  if (!impl.preserveWhiteSpace) {
+	for (var i = 0; i &lt; textNodesList.length; i++) {
+		var node = textNodesList[i];
+		if (node.parentNode != null) {
+			var nodeData = node.data;
+			nodeData.replace(/\s/g, ' ');
+			node.data = nodeData;
+		}
+	}
+  
+  }
+};
+
+/**
+ * @method DOMImplementation._isNamespaceDeclaration - Return true, if attributeName is a namespace declaration
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  attributeName : string - the attribute name
+ * @return : boolean
+ */
+function __isNamespaceDeclaration__(attributeName) {
+  // test if attributeName is 'xmlns'
+  return (attributeName.indexOf('xmlns') &gt; -1);
+};
+
+/**
+ * @method DOMImplementation._isIdDeclaration - Return true, if attributeName is an id declaration
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  attributeName : string - the attribute name
+ * @return : boolean
+ */
+function __isIdDeclaration__(attributeName) {
+  // test if attributeName is 'id' (case insensitive)
+  return (attributeName.toLowerCase() == 'id');
+};
+
+/**
+ * @method DOMImplementation._isValidName - Return true,
+ *   if name contains no invalid characters
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  name : string - the candidate name
+ * @return : boolean
+ */
+function __isValidName__(name) {
+  // test if name contains only valid characters
+  return name.match(re_validName);
+};
+var re_validName = /^[a-zA-Z_:][a-zA-Z0-9\.\-_:]*$/;
+
+/**
+ * @method DOMImplementation._isValidString - Return true, if string does not contain any illegal chars
+ *  All of the characters 0 through 31 and character 127 are nonprinting control characters.
+ *  With the exception of characters 09, 10, and 13, (Ox09, Ox0A, and Ox0D)
+ *  Note: different from _isValidName in that ValidStrings may contain spaces
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  name : string - the candidate string
+ * @return : boolean
+ */
+function __isValidString__(name) {
+  // test that string does not contains invalid characters
+  return (name.search(re_invalidStringChars) &lt; 0);
+};
+var re_invalidStringChars = /\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0B|\x0C|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E|\x1F|\x7F/;
+
+/**
+ * @method DOMImplementation._parseNSName - parse the namespace name.
+ *  if there is no colon, the
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  qualifiedName : string - The qualified name
+ * @return : NSName - [
+         .prefix        : string - The prefix part of the qname
+         .namespaceName : string - The namespaceURI part of the qname
+    ]
+ */
+function __parseNSName__(qualifiedName) {
+  var resultNSName = new Object();
+
+  resultNSName.prefix          = qualifiedName;  // unless the qname has a namespaceName, the prefix is the entire String
+  resultNSName.namespaceName   = &quot;&quot;;
+
+  // split on ':'
+  var delimPos = qualifiedName.indexOf(':');
+  if (delimPos &gt; -1) {
+    // get prefix
+    resultNSName.prefix        = qualifiedName.substring(0, delimPos);
+    // get namespaceName
+    resultNSName.namespaceName = qualifiedName.substring(delimPos +1, qualifiedName.length);
+  }
+  return resultNSName;
+};
+
+/**
+ * @method DOMImplementation._parseQName - parse the qualified name
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  qualifiedName : string - The qualified name
+ * @return : QName
+ */
+function __parseQName__(qualifiedName) {
+  var resultQName = new Object();
+
+  resultQName.localName = qualifiedName;  // unless the qname has a prefix, the local name is the entire String
+  resultQName.prefix    = &quot;&quot;;
+
+  // split on ':'
+  var delimPos = qualifiedName.indexOf(':');
+
+  if (delimPos &gt; -1) {
+    // get prefix
+    resultQName.prefix    = qualifiedName.substring(0, delimPos);
+
+    // get localName
+    resultQName.localName = qualifiedName.substring(delimPos +1, qualifiedName.length);
+  }
+
+  return resultQName;
+};
+
+$log(&quot;Initializing document.implementation&quot;);
+var $implementation =  new DOMImplementation();
+$implementation.namespaceAware = false;
+$implementation.errorChecking = true;$log(&quot;Defining Document&quot;);
+/*
+* Document - DOM Level 2
+*  The Document object is not directly 
+*/
+$w.__defineGetter__('Document', function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+/**
+ * @class  DOMDocument - The Document interface represents the entire HTML or XML document.
+ *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
+ *
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  implementation : DOMImplementation - the creator Implementation
+ */
+var DOMDocument = function(implementation) {
+    //$log(&quot;\tcreating dom document&quot;);
+    this.DOMNode = DOMNode;
+    this.DOMNode(this);
+    
+    this.doctype = null;                  // The Document Type Declaration (see DocumentType) associated with this document
+    this.implementation = implementation; // The DOMImplementation object that handles this document.
+    this.documentElement = null;          // This is a convenience attribute that allows direct access to the child node that is the root element of the document
+    //this.all  = new Array();                       // The list of all Elements
+    
+    this.nodeName  = &quot;#document&quot;;
+    this.nodeType = DOMNode.DOCUMENT_NODE;
+    this._id = 0;
+    this._lastId = 0;
+    this._parseComplete = false;                   // initially false, set to true by parser
+    this._url = &quot;&quot;;
+    
+    this.ownerDocument = this;
+    
+    this._performingImportNodeOperation = false;
+    //$log(&quot;\tfinished creating dom document &quot; + this);
+};
+DOMDocument.prototype = new DOMNode;
+__extend__(DOMDocument.prototype, {
+	addEventListener        : window.addEventListener,
+	removeEventListener     : window.removeEventListener,
+    attachEvent             : window.addEventListener,/*IE only subject to deprecation*/
+    detachEvent             : window.detachEvent,/*IE only subject to  deprecation*/
+	dispatchEvent           : window.dispatchEvent,
+    get styleSheets(){ 
+        return [];/*TODO*/ 
+    },
+    get all(){
+        return this.getElementsByTagName(&quot;*&quot;);
+    },
+    loadXML : function(xmlStr) {
+        // create SAX Parser
+        var parser;
+        
+        try {
+            parser = new XMLP(String(xmlStr));
+        }catch (e) {
+            $error(&quot;Error Creating the SAX Parser. \n\n\t&quot;+e+&quot;\n\n\t Did you include xmlsax.js or tinyxmlsax.js\
+                     in your web page?\nThe SAX parser is needed to populate XML for &lt;SCRIPT&gt;'s \
+                     W3C DOM Parser with data.&quot;);
+        }
+        // create DOM Document
+        var doc = new HTMLDocument(this.implementation);
+        // populate Document with Parsed Nodes
+        try {
+            __parseLoop__(this.implementation, doc, parser);
+        } catch (e) {
+            $error(this.implementation.translateErrCode(e.code))
+        }
+
+        // set parseComplete flag, (Some validation Rules are relaxed if this is false)
+        doc._parseComplete = true;
+        if(this === $document){
+            $log(&quot;Setting internal window.document&quot;);
+            $document = doc;
+        }
+        return doc;
+    },
+    load: function(url){
+		$log(&quot;Loading url into DOM Document: &quot;+ url + &quot; - (Asynch? &quot;+$w.document.async+&quot;)&quot;);
+        var _this = this;
+        var xhr = new XMLHttpRequest();
+        xhr.open(&quot;GET&quot;, url, $w.document.async);
+        xhr.onreadystatechange = function(){
+            try{
+        	    _this.loadXML(xhr.responseText);
+            }catch(e){
+                $error(&quot;Error Parsing XML - &quot;,e);
+                _this.loadXML(
+                &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&quot;+
+                    &quot;&lt;h1&gt;Parse Error&lt;/h1&gt;&quot;+
+                    &quot;&lt;p&gt;&quot;+e.toString()+&quot;&lt;/p&gt;&quot;+  
+                &quot;&lt;/body&gt;&lt;/html&gt;&quot;);
+            }
+            $env.loadScripts();
+            _this._url = url;
+        	$log(&quot;Sucessfully loaded document.&quot;);
+        	var event = document.createEvent();
+        	event.initEvent(&quot;load&quot;);
+        	$w.dispatchEvent( event );
+        };
+        xhr.send();
+    },
+	createEvent             : function(eventType){ 
+        var event;
+        if(eventType === &quot;UIEvents&quot;){ event = new UIEvent();}
+        else if(eventType === &quot;MouseEvents&quot;){ event = new MouseEvent();}
+        else{ event = new Event(); } 
+        return event;
+    },
+    createExpression        : function(xpath, nsuriMap){ 
+        return null;/*TODO*/
+    },
+    createElement : function(tagName) {
+        //$log(&quot;DOMDocument.createElement( &quot;+tagName+&quot; )&quot;);
+          // throw Exception if the tagName string contains an illegal character
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
+            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+          }
+        
+          // create DOMElement specifying 'this' as ownerDocument
+          var node = new DOMElement(this);
+        
+          // assign values to properties (and aliases)
+          node.tagName  = tagName;
+          node.nodeName = tagName;
+        
+          // add Element to 'all' collection
+          //this.all[this.all.length] = node;
+          //$log(&quot;Document.all.length &quot; + this.all.length);
+        
+          return node;
+    },
+    createDocumentFragment : function() {
+          // create DOMDocumentFragment specifying 'this' as ownerDocument
+          var node = new DOMDocumentFragment(this);
+        
+          return node;
+    },
+    createTextNode: function(data) {
+          // create DOMText specifying 'this' as ownerDocument
+          var node = new DOMText(this);
+        
+          // assign values to properties (and aliases)
+          node.data      = data;
+          node.nodeValue = data;
+        
+          // set initial length
+          node.length    = data.length;
+        
+          return node;
+    },
+    createComment : function(data) {
+          // create DOMComment specifying 'this' as ownerDocument
+          var node = new DOMComment(this);
+        
+          // assign values to properties (and aliases)
+          node.data      = data;
+          node.nodeValue = data;
+        
+          // set initial length
+          node.length    = data.length;
+        
+          return node;
+    },
+    createCDATASection : function(data) {
+          // create DOMCDATASection specifying 'this' as ownerDocument
+          var node = new DOMCDATASection(this);
+        
+          // assign values to properties (and aliases)
+          node.data      = data;
+          node.nodeValue = data;
+        
+          // set initial length
+          node.length    = data.length;
+        
+          return node;
+    },
+    createProcessingInstruction : function(target, data) {
+          // throw Exception if the target string contains an illegal character
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(target))) {
+            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+          }
+        
+          // create DOMProcessingInstruction specifying 'this' as ownerDocument
+          var node = new DOMProcessingInstruction(this);
+        
+          // assign values to properties (and aliases)
+          node.target    = target;
+          node.nodeName  = target;
+          node.data      = data;
+          node.nodeValue = data;
+        
+          // set initial length
+          node.length    = data.length;
+        
+          return node;
+    },
+    createAttribute : function(name) {
+          // throw Exception if the name string contains an illegal character
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(name))) {
+            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+          }
+        
+          // create DOMAttr specifying 'this' as ownerDocument
+          var node = new DOMAttr(this);
+        
+          // assign values to properties (and aliases)
+          node.name     = name;
+          node.nodeName = name;
+        
+          return node;
+    },
+    createElementNS : function(namespaceURI, qualifiedName) {
+        //$log(&quot;DOMDocument.createElement( &quot;+namespaceURI+&quot;, &quot;+qualifiedName+&quot; )&quot;);
+          // test for exceptions
+          if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if the Namespace is invalid
+            if (!__isValidNamespace__(this, namespaceURI, qualifiedName)) {
+              throw(new DOMException(DOMException.NAMESPACE_ERR));
+            }
+        
+            // throw Exception if the qualifiedName string contains an illegal character
+            if (!__isValidName__(qualifiedName)) {
+              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+            }
+          }
+        
+          // create DOMElement specifying 'this' as ownerDocument
+          var node  = new DOMElement(this);
+          var qname = __parseQName__(qualifiedName);
+        
+          // assign values to properties (and aliases)
+          node.nodeName     = qualifiedName;
+          node.namespaceURI = namespaceURI;
+          node.prefix       = qname.prefix;
+          node.localName    = qname.localName;
+          node.tagName      = qualifiedName;
+        
+          // add Element to 'all' collection
+          //this.all[this.all.length] = node;
+        
+          return node;
+    },
+    createAttributeNS : function(namespaceURI, qualifiedName) {
+          // test for exceptions
+          if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if the Namespace is invalid
+            if (!__isValidNamespace__(this, namespaceURI, qualifiedName, true)) {
+              throw(new DOMException(DOMException.NAMESPACE_ERR));
+            }
+        
+            // throw Exception if the qualifiedName string contains an illegal character
+            if (!__isValidName__(qualifiedName)) {
+              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+            }
+          }
+        
+          // create DOMAttr specifying 'this' as ownerDocument
+          var node  = new DOMAttr(this);
+          var qname = __parseQName__(qualifiedName);
+        
+          // assign values to properties (and aliases)
+          node.nodeName     = qualifiedName;
+          node.namespaceURI = namespaceURI;
+          node.prefix       = qname.prefix;
+          node.localName    = qname.localName;
+          node.name         = qualifiedName;
+          node.nodeValue    = &quot;&quot;;
+        
+          return node;
+    },
+    createNamespace : function(qualifiedName) {
+          // create DOMNamespace specifying 'this' as ownerDocument
+          var node  = new DOMNamespace(this);
+          var qname = __parseQName__(qualifiedName);
+        
+          // assign values to properties (and aliases)
+          node.nodeName     = qualifiedName;
+          node.prefix       = qname.prefix;
+          node.localName    = qname.localName;
+          node.name         = qualifiedName;
+          node.nodeValue    = &quot;&quot;;
+        
+          return node;
+    },
+    getElementById : function(elementId) {
+          var retNode = null,
+              node;
+          // loop through all Elements in the 'all' collection
+          var all = this.all;
+          for (var i=0; i &lt; all.length; i++) {
+            node = all[i];
+            // if id matches &amp; node is alive (ie, connected (in)directly to the documentElement)
+            if (node.id == elementId) {
+                if((node.ownerDocument.documentElement._id == this.documentElement._id)){
+                    retNode = node;
+                    //$log(&quot;Found node with id = &quot; + node.id);
+                    break;
+                }
+            }
+          }
+          
+          if(retNode == null){$log(&quot;Couldn't find id &quot; + elementId);}
+          return retNode;
+    },
+    normalizeDocument: function(){
+	    this.documentElement.normalize();
+    },
+    get xml(){
+        return this.documentElement.xml;
+    },
+	toString: function(){ 
+	    return &quot;Document&quot; +  (typeof this._url == &quot;string&quot; ? &quot;: &quot; + this._url : &quot;&quot;); 
+    },
+	get defaultView(){ //TODO: why isnt this just 'return $w;'?
+		return { getComputedStyle: function(elem){
+			return { getPropertyValue: function(prop){
+				prop = prop.replace(/\-(\w)/g,function(m,c){ return c.toUpperCase(); });
+				var val = elem.style[prop];
+				if ( prop == &quot;opacity&quot; &amp;&amp; val == &quot;&quot; ){ val = &quot;1&quot;; }return val;
+			}};
+		}};
+	},
+    _genId : function() {
+          this._lastId += 1;                             // increment lastId (to generate unique id)
+          return this._lastId;
+    }
+});
+
+
+var __isValidNamespace__ = function(doc, namespaceURI, qualifiedName, isAttribute) {
+
+      if (doc._performingImportNodeOperation == true) {
+        //we're doing an importNode operation (or a cloneNode) - in both cases, there
+        //is no need to perform any namespace checking since the nodes have to have been valid
+        //to have gotten into the DOM in the first place
+        return true;
+      }
+    
+      var valid = true;
+      // parse QName
+      var qName = __parseQName__(qualifiedName);
+    
+    
+      //only check for namespaces if we're finished parsing
+      if (this._parseComplete == true) {
+    
+        // if the qualifiedName is malformed
+        if (qName.localName.indexOf(&quot;:&quot;) &gt; -1 ){
+            valid = false;
+        }
+    
+        if ((valid) &amp;&amp; (!isAttribute)) {
+            // if the namespaceURI is not null
+            if (!namespaceURI) {
+            valid = false;
+            }
+        }
+    
+        // if the qualifiedName has a prefix
+        if ((valid) &amp;&amp; (qName.prefix == &quot;&quot;)) {
+            valid = false;
+        }
+    
+      }
+    
+      // if the qualifiedName has a prefix that is &quot;xml&quot; and the namespaceURI is
+      //  different from &quot;http://www.w3.org/XML/1998/namespace&quot; [Namespaces].
+      if ((valid) &amp;&amp; (qName.prefix == &quot;xml&quot;) &amp;&amp; (namespaceURI != &quot;http://www.w3.org/XML/1998/namespace&quot;)) {
+        valid = false;
+      }
+    
+      return valid;
+};
+$log(&quot;Defining HTMLDocument&quot;);
+/*
+* HTMLDocument - DOM Level 2
+*  The Document object is not directly 
+*/
+$w.__defineGetter__(&quot;HTMLDocument&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+/**
+ * @class  HTMLDocument - The Document interface represents the entire HTML or XML document.
+ *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
+ *
+ * @extends DOMDocument
+ */
+var HTMLDocument = function(implementation) {
+  this.DOMDocument = DOMDocument;
+  this.DOMDocument(implementation);
+
+  this.title = &quot;&quot;;
+  this._refferer = &quot;&quot;;
+  this._domain;
+  this._open = false;
+};
+HTMLDocument.prototype = new DOMDocument;
+__extend__(HTMLDocument.prototype, {
+    createElement: function(tagName){
+        //$log(&quot;HTMLDocument.createElement( &quot;+tagName+&quot; )&quot;);
+        // throw Exception if the tagName string contains an illegal character
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
+            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+          }
+          tagName = tagName.toUpperCase();
+          //$log(&quot;HTMLDocument.createElement( &quot;+tagName+&quot; )&quot;);
+          // create DOMElement specifying 'this' as ownerDocument
+          //This is an html document so we need to use explicit interfaces per the 
+          if(     tagName.match(/^A$/))                 {node = new HTMLAnchorElement(this);}
+          else if(tagName.match(/AREA/))                {node = new HTMLAreaElement(this);}
+          else if(tagName.match(/BASE/))                {node = new HTMLBaseElement(this);}
+          else if(tagName.match(/BLOCKQUOTE|Q/))        {node = new HTMLQuoteElement(this);}
+          else if(tagName.match(/BODY/))                {node = new HTMLElement(this);}
+          else if(tagName.match(/BR/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/BUTTON/))              {node = new HTMLButtonElement(this);}
+          else if(tagName.match(/CAPTION/))             {node = new HTMLElement(this);}
+          else if(tagName.match(/COL|COLGROUP/))        {node = new HTMLTableColElement(this);}
+          else if(tagName.match(/DEL|INS/))             {node = new HTMLModElement(this);}
+          else if(tagName.match(/DIV/))                 {node = new HTMLElement(this);}
+          else if(tagName.match(/DL/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/FIELDSET/))            {node = new HTMLFieldSetElement(this);}
+          else if(tagName.match(/FORM/))                {node = new HTMLFormElement(this);}
+          else if(tagName.match(/^FRAME$/))             {node = new HTMLFrameElement(this);}
+          else if(tagName.match(/FRAMESET/))            {node = new HTMLFrameSetElement(this);}
+          else if(tagName.match(/H1|H2|H3|H4|H5|H6/))   {node = new HTMLElement(this);}
+          else if(tagName.match(/HEAD/))                {node = new HTMLHeadElement(this);}
+          else if(tagName.match(/HR/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/HTML/))                {node = new HTMLElement(this);}
+          else if(tagName.match(/IFRAME/))              {node = new HTMLIFrameElement(this);}
+          else if(tagName.match(/IMG/))                 {node = new HTMLImageElement(this);}
+          else if(tagName.match(/INPUT/))               {node = new HTMLInputElement(this);}
+          else if(tagName.match(/LABEL/))               {node = new HTMLLabelElement(this);}
+          else if(tagName.match(/LEGEND/))              {node = new HTMLLegendElement(this);}
+          else if(tagName.match(/^LI$/))                {node = new HTMLElement(this);}
+          else if(tagName.match(/LINK/))                {node = new HTMLLinkElement(this);}
+          else if(tagName.match(/MAP/))                 {node = new HTMLMapElement(this);}
+          else if(tagName.match(/META/))                {node = new HTMLMetaElement(this);}
+          else if(tagName.match(/OBJECT/))              {node = new HTMLObjectElement(this);}
+          else if(tagName.match(/OL/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/OPTGROUP/))            {node = new HTMLOptGroupElement(this);}
+          else if(tagName.match(/OPTION/))              {node = new HTMLOptionElement(this);;}
+          else if(tagName.match(/^P$/))                 {node = new HTMLElement(this);}
+          else if(tagName.match(/PARAM/))               {node = new HTMLParamElement(this);}
+          else if(tagName.match(/PRE/))                 {node = new HTMLElement(this);}
+          else if(tagName.match(/SCRIPT/))              {node = new HTMLScriptElement(this);}
+          else if(tagName.match(/SELECT/))              {node = new HTMLSelectElement(this);}
+          else if(tagName.match(/STYLE/))               {node = new HTMLStyleElement(this);}
+          else if(tagName.match(/TABLE/))               {node = new HTMLElement(this);}
+          else if(tagName.match(/TBODY|TFOOT|THEAD/))   {node = new HTMLElement(this);}
+          else if(tagName.match(/TD|TH/))               {node = new HTMLElement(this);}
+          else if(tagName.match(/TEXTAREA/))            {node = new HTMLElement(this);}
+          else if(tagName.match(/TITLE/))               {node = new HTMLElement(this);}
+          else if(tagName.match(/TR/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/UL/))                  {node = new HTMLElement(this);}
+          else{
+            node = new HTMLElement(this);
+          }
+        
+          // assign values to properties (and aliases)
+          node.tagName  = tagName;
+          node.nodeName = tagName;
+        
+          // add Element to 'all' collection
+          //this.all[this.all.length] = node;
+          //$log(&quot;Document.all.length &quot; + this.all.length);
+          return node;
+    },
+    get anchors(){
+        return new HTMLCollection(this.getElementsByTagName('a'), 'Anchor');
+        
+    },
+    get applets(){
+        return new HTMLCollection(this.getElementsByTagName('applet'), 'Applet');
+        
+    },
+    get body(){ 
+        var nodelist = this.getElementsByTagName('body');
+        return nodelist.item(0);
+        
+    },
+    set body(html){
+        return this.replaceNode(this.body,html);
+        
+    },
+    //set/get cookie see cookie.js
+    get domain(){
+        return this._domain||window.location.domain;
+        
+    },
+    set domain(){
+        /* TODO - requires a bit of thought to enforce domain restrictions */ 
+        return; 
+        
+    },
+    get forms(){
+      $log(&quot;document.forms&quot;);
+      return new HTMLCollection(this.getElementsByTagName('form'), 'Form');
+    },
+    get images(){
+        return new HTMLCollection(this.getElementsByTagName('img'), 'Image');
+        
+    },
+    get lastModified(){ 
+        /* TODO */
+        return this._lastModified; 
+    
+    },
+    get links(){
+        return new HTMLCollection(this.getElementsByTagName('a'), 'Link');
+        
+    },
+    get referrer(){
+        /* TODO */
+        return this._refferer; 
+        
+    },
+    get URL(){
+        /* TODO*/
+        return this._url; 
+        
+    },
+	close : function(){ 
+	    /* TODO */ 
+	    this._open = false;
+    },
+	getElementsByName : function(name){
+        //$debug(&quot;document.getElementsByName ( &quot;+name+&quot; )&quot;);
+        //returns a real Array + the DOMNodeList
+        var retNodes = __extend__([],new DOMNodeList(this, this.documentElement)),
+          node;
+        // loop through all Elements in the 'all' collection
+        var all = this.all;
+        for (var i=0; i &lt; all.length; i++) {
+            node = all[i];
+            if (node.nodeType == DOMNode.ELEMENT_NODE &amp;&amp; node.getAttribute('name') == name) {
+                //$log(&quot;Found node by name &quot; + name);
+                retNodes.push(node);
+            }
+        }
+        return retNodes;
+	},
+	open : function(){ 
+	    /* TODO */
+	    this._open = true;  
+    },
+	write: function(htmlstring){ 
+	    /* TODO */
+	    return; 
+	
+    },
+	writeln: function(htmlstring){ 
+	    this.write(htmlstring+'\n'); 
+    },
+	toString: function(){ 
+	    return &quot;Document&quot; +  (typeof this._url == &quot;string&quot; ? &quot;: &quot; + this._url : &quot;&quot;); 
+    },
+	get innerHTML(){ 
+	    return this.documentElement.outerHTML; 
+	    
+    },
+	get __html__(){
+	    return true;
+	    
+    }
+});
+
+//This is useful as html elements that modify the dom must also run through the new 
+//nodes and determine if they are javascript tags and load it.  This is really the fun 
+//parts! ;)
+function __execScripts__( node ) {
+	if ( node.nodeName == &quot;SCRIPT&quot; ) {
+		if ( !node.getAttribute(&quot;src&quot;) ) {
+			eval.call( window, node.textContent );
+		}
+	} else {
+		var scripts = node.getElementsByTagName(&quot;script&quot;);
+		for ( var i = 0; i &lt; scripts.length; i++ ) {
+			__execScripts__( node );
+		}
+	}
+};$log(&quot;Defining HTMLElement&quot;);
+/*
+* HTMLElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+var HTMLElement = function(ownerDocument) {
+    //$log(&quot;\tcreating html element&quot;);
+    this.DOMElement = DOMElement;
+    this.DOMElement(ownerDocument);
+    //$log(&quot;\nfinished creating html element&quot;);
+    
+    this.$css2props = null;
+};
+HTMLElement.prototype = new DOMElement;
+__extend__(HTMLElement.prototype, {
+		get className() { 
+		    return this.getAttribute(&quot;class&quot;)||&quot;&quot;; 
+		    
+	    },
+		set className(val) { 
+		    return this.setAttribute(&quot;class&quot;,trim(val)); 
+		    
+	    },
+		get dir() { 
+		    return this.getAttribute(&quot;dir&quot;)||&quot;ltr&quot;; 
+		    
+	    },
+		set dir(val) { 
+		    return this.setAttribute(&quot;dir&quot;,val); 
+		    
+	    },
+		get innerHTML(){  
+		    return this.childNodes.xml; 
+		    
+	    },
+		set innerHTML(html){
+		    //$debug(&quot;htmlElement.innerHTML(&quot;+html+&quot;)&quot;);
+		    //Should be replaced with HTMLPARSER usage
+			html = (html?html:&quot;&quot;).replace(/&lt;\/?([A-Z]+)/g, function(m){
+				return m.toLowerCase();
+			}).replace(/&amp;nbsp;/g, &quot; &quot;);
+			var doc = new DOMParser().
+			  parseFromString('&lt;div&gt;'+html+'&lt;/div&gt;');
+            var parent = this.ownerDocument.importNode(doc.documentElement, true);
+            
+			//$log(&quot;\n\nIMPORTED HTML:\n\n&quot;+nodes.xml);
+			while(this.firstChild != null){
+			    //$log('innerHTML - removing child '+ this.firstChild.xml);
+			    this.removeChild( this.firstChild );
+			}
+			while(parent.firstChild != null){
+			    //$log('innerHTML - appending child '+ parent.firstChild.xml);
+			    this.appendChild( parent.removeChild( parent.firstChild ) );
+		    }
+		    //Mark for garbage collection
+		    doc = null;
+		},
+		get lang() { 
+		    return this.getAttribute(&quot;lang&quot;)||&quot;&quot;; 
+		    
+	    },
+		set lang(val) { 
+		    return this.setAttribute(&quot;lang&quot;,val); 
+		    
+	    },
+		get offsetHeight(){
+		    return Number(this.style[&quot;height&quot;].replace(&quot;px&quot;,&quot;&quot;));
+		},
+		get offsetWidth(){
+		    return Number(this.style[&quot;width&quot;].replace(&quot;px&quot;,&quot;&quot;));
+		},
+		offsetLeft: 0,
+		offsetRight: 0,
+		get offsetParent(){
+		    /* TODO */
+		    return;
+	    },
+		set offsetParent(element){
+		    /* TODO */
+		    return;
+	    },
+		scrollHeight: 0,
+		scrollWidth: 0,
+		scrollLeft: 0, 
+		scrollRight: 0,
+		get style(){
+		    if(this.$css2props === null){
+		        $log(&quot;Initializing new css2props for html element : &quot; + this.getAttribute(&quot;style&quot;));
+		        this.$css2props = new CSS2Properties({
+    		        cssText:this.getAttribute(&quot;style&quot;)
+    	        });
+	        }
+	        return this.$css2props
+		},
+		get title() { 
+		    return this.getAttribute(&quot;title&quot;)||&quot;&quot;; 
+		    
+	    },
+		set title(val) { 
+		    return this.setAttribute(&quot;title&quot;,val); 
+		    
+	    },
+		//Not in the specs but I'll leave it here for now.
+		get outerHTML(){ 
+		    return this.xml; 
+		    
+	    },
+	    scrollIntoView: function(){
+	        /*TODO*/
+	        return;
+	    
+        },
+		onclick: function(event){
+		    try{
+		        eval(this.getAttribute('onclick'));
+		    }catch(e){
+		        $error(e);
+	        }
+	    },
+		ondblclick: function(event){
+		    try{
+		        eval(this.getAttribute('ondblclick'));
+		    }catch(e){
+		        $error(e)
+		    }
+	    },
+		onkeydown: function(event){
+		    try{
+		        eval(this.getAttribute('onkeydown'));
+		    }catch(e){
+		        $error(e);
+		    }
+	    },
+		onkeypress: function(event){
+		    try{
+		        eval(this.getAttribute('onkeypress'));
+		    }catch(e){
+		        $error(e);}},
+		onkeyup: function(event){
+		    try{
+		        eval(this.getAttribute('onkeyup'));
+		    }catch(e){
+		        $error(e);}},
+		onmousedown: function(event){
+		    try{
+		        eval(this.getAttribute('onmousedown'));
+		    }catch(e){
+		        $error(e);}},
+		onmousemove: function(event){
+		    try{
+		        eval(this.getAttribute('onmousemove'));
+		    }catch(e){
+		        $error(e);}},
+		onmouseout: function(event){
+		    try{
+		        eval(this.getAttribute('onmouseout'));
+		    }catch(e){
+		        $error(e);}},
+		onmouseover: function(event){
+		    try{
+		        eval(this.getAttribute('onmouseover'));
+		    }catch(e){
+		        $error(e);}},
+		onmouseup: function(event){
+		    try{
+		        eval(this.getAttribute('onmouseup'));
+		    }catch(e){
+		        $error(e);}}
+});
+
+var __registerEventAttrs__ = function(elm){
+    if(elm.hasAttribute('onclick')){ 
+        elm.addEventListener('click', elm.onclick ); 
+    }
+    if(elm.hasAttribute('ondblclick')){ 
+        elm.addEventListener('dblclick', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onkeydown')){ 
+        elm.addEventListener('keydown', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onkeypress')){ 
+        elm.addEventListener('keypress', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onkeyup')){ 
+        elm.addEventListener('keyup', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmousedown')){ 
+        elm.addEventListener('mousedown', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmousemove')){ 
+        elm.addEventListener('mousemove', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmouseout')){ 
+        elm.addEventListener('mouseout', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmouseover')){ 
+        elm.addEventListener('mouseover', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmouseup')){ 
+        elm.addEventListener('mouseup', elm.onclick ); 
+    }
+    return elm;
+};
+	
+var __click__ = function(element){
+	var event = new Event({
+	  target:element,
+	  currentTarget:element
+	});
+	event.initEvent(&quot;click&quot;);
+	element.dispatchEvent(event);
+};
+var __submit__ = function(element){
+	var event = new Event({
+	  target:element,
+	  currentTarget:element
+	});
+	event.initEvent(&quot;submit&quot;);
+	element.dispatchEvent(event);
+};
+var __focus__ = function(element){
+	var event = new Event({
+	  target:element,
+	  currentTarget:element
+	});
+	event.initEvent(&quot;focus&quot;);
+	element.dispatchEvent(event);
+};
+var __blur__ = function(element){
+	var event = new Event({
+	  target:element,
+	  currentTarget:element
+	});
+	event.initEvent(&quot;blur&quot;);
+	element.dispatchEvent(event);
+};
+$log(&quot;Defining HTMLCollection&quot;);
+/*
+* HTMLCollection - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLCollection&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/*var HTMLCollection = function(nodelist, type){
+  var $items = [], 
+      $item, i;
+  if(type === &quot;Anchor&quot; ){
+    for(i=0;i&lt;nodelist.length;i++){ 
+      //The name property is required to be add to the collection
+      if(nodelist.item(i).name){
+        item = new nodelist.item(i);
+        $items.push(item);
+        this[nodelist.item(i).name] = item;
+      }
+    }
+  }else if(type === &quot;Link&quot;){
+    for(i=0;i&lt;nodelist.length;i++){ 
+      //The name property is required to be add to the collection
+      if(nodelist.item(i).href){
+        item = new nodelist.item(i);
+        $items.push(item);
+        this[nodelist.item(i).name] = item;
+      }
+    }
+  }else if(type === &quot;Form&quot;){
+    for(i=0;i&lt;nodelist.length;i++){ 
+      //The name property is required to be add to the collection
+      if(nodelist.item(i).href){
+        item = new nodelist.item(i);
+        $items.push(item);
+        this[nodelist.item(i).name] = item;
+      }
+    }
+  }
+  setArray(this, $items);
+  return __extend__(this, {
+    item : function(i){return this[i];},
+    namedItem : function(name){return this[name];}
+  });
+};*/
+
+	$log(&quot;Defining HTMLAnchorElement&quot;);
+/* 
+* HTMLAnchorElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLAnchorElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLAnchorElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLAnchorElement.prototype = new HTMLElement;
+__extend__(HTMLAnchorElement.prototype, {
+	get accessKey() { 
+	    return this.getAttribute(&quot;accesskey&quot;) || &quot;&quot;; 
+	    
+    },
+	set accessKey(val) { 
+	    return this.setAttribute(&quot;accesskey&quot;,val); 
+	    
+    },
+	get charset() { 
+	    return this.getAttribute(&quot;charset&quot;) || &quot;&quot;; 
+	    
+    },
+	set charset(val) { 
+	    return this.setAttribute(&quot;charset&quot;,val); 
+	    
+    },
+	get coords() { 
+	    return this.getAttribute(&quot;coords&quot;) || &quot;&quot;; 
+	    
+    },
+	set coords(val) { 
+	    return this.setAttribute(&quot;coords&quot;,val); 
+	    
+    },
+	get href() { 
+	    return this.getAttribute(&quot;href&quot;) || &quot;&quot;; 
+	    
+    },
+	set href(val) { 
+	    return this.setAttribute(&quot;href&quot;,val); 
+	    
+    },
+	get hreflang() { 
+	    return this.getAttribute(&quot;hreflang&quot;) || &quot;&quot;; 
+	    
+    },
+	set hreflang(val) { 
+	    return this.setAttribute(&quot;hreflang&quot;,val); 
+	    
+    },
+	get name() { 
+	    return this.getAttribute(&quot;name&quot;) || &quot;&quot;; 
+	    
+    },
+	set name(val) { 
+	    return this.setAttribute(&quot;name&quot;,val); 
+	    
+    },
+	get rel() { 
+	    return this.getAttribute(&quot;rel&quot;) || &quot;&quot;; 
+	    
+    },
+	set rel(val) { 
+	    return this.setAttribute(&quot;rel&quot;,val); 
+	    
+    },
+	get rev() { 
+	    return this.getAttribute(&quot;rev&quot;) || &quot;&quot;; 
+	    
+    },
+	set rev(val) { 
+	    return this.setAttribute(&quot;rev&quot;,val); 
+	    
+    },
+	get shape() { 
+	    return this.getAttribute(&quot;shape&quot;) || &quot;&quot;; 
+	    
+    },
+	set shape(val) { 
+	    return this.setAttribute(&quot;shape&quot;,val); 
+	    
+    },
+	get tabIndex() { 
+	    return this.getAttribute(&quot;tabindex&quot;) || &quot;&quot;; 
+	    
+    },
+	set tabIndex(val) { 
+	    return this.setAttribute(&quot;tabindex&quot;,val); 
+	    
+    },
+	get target() { 
+	    return this.getAttribute(&quot;target&quot;) || &quot;&quot;; 
+	    
+    },
+	set target(val) { 
+	    return this.setAttribute(&quot;target&quot;,val); 
+	    
+    },
+	get type() { 
+	    return this.getAttribute(&quot;type&quot;) || &quot;&quot;; 
+	    
+    },
+	set type(val) { 
+	    return this.setAttribute(&quot;type&quot;,val); 
+	    
+    },
+	blur:function(){
+	    __blur__(this);
+	    
+    },
+	focus:function(){
+	    __focus__(this);
+	    
+    }
+});
+
+			$log(&quot;Defining Anchor&quot;);
+/* 
+* Anchor - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Anchor&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var Anchor = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLAnchorElement = HTMLAnchorElement;
+    this.HTMLAnchorElement(ownerDocument);
+};
+Anchor.prototype = new Anchor;
+
+(function(){
+    //static regular expressions
+	var hash 	 = new RegExp('(\\#.*)'),
+        hostname = new RegExp('\/\/([^\:\/]+)'),
+        pathname = new RegExp('(\/[^\\?\\#]*)'),
+        port 	 = new RegExp('\:(\\d+)\/'),
+        protocol = new RegExp('(^\\w*\:)'),
+        search 	 = new RegExp('(\\?[^\\#]*)');
+			
+    __extend__(Anchor.prototype, {
+		get hash(){
+			var m = hash.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set hash(_hash){
+			//setting the hash is the only property of the location object
+			//that doesn't cause the window to reload
+			_hash = _hash.indexOf('#')===0?_hash:&quot;#&quot;+_hash;	
+			this.href = this.protocol + this.host + this.pathname + this.search + _hash;
+		},
+		get host(){
+			return this.hostname + (this.port !== &quot;&quot;)?&quot;:&quot;+this.port:&quot;&quot;;
+		},
+		set host(_host){
+			this.href = this.protocol + _host + this.pathname + this.search + this.hash;
+		},
+		get hostname(){
+			var m = hostname.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set hostname(_hostname){
+			this.href = this.protocol + _hostname + ((this.port===&quot;&quot;)?&quot;&quot;:(&quot;:&quot;+this.port)) +
+			 	 this.pathname + this.search + this.hash;
+		},
+		get pathname(){
+			var m = this.href;
+			m = pathname.exec(m.substring(m.indexOf(this.hostname)));
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;/&quot;;
+		},
+		set pathname(_pathname){
+			this.href = this.protocol + this.host + _pathname + 
+				this.search + this.hash;
+		},
+		get port(){
+			var m = port.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set port(_port){
+			this.href = this.protocol + this.hostname + &quot;:&quot;+_port + this.pathname + 
+				this.search + this.hash;
+		},
+		get protocol(){
+			return protocol.exec(this.href)[0];
+		},
+		set protocol(_protocol){
+			this.href = _protocol + this.host + this.pathname + 
+				this.search + this.hash;
+		},
+		get search(){
+			var m = search.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set search(_search){
+			this.href = this.protocol + this.host + this.pathname + 
+				_search + this.hash;
+		}
+  });
+
+})();
+			$log(&quot;Defining HTMLAreaElement&quot;);
+/* 
+* HTMLAreaElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLAreaElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLAreaElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLAreaElement.prototype = new HTMLElement;
+__extend__(HTMLAreaElement.prototype, {
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    },
+    get alt(){
+        return this.getAttribute('alt');
+    },
+    set alt(value){
+        this.setAttribute('alt',value);
+    },
+    get coords(){
+        return this.getAttribute('coords');
+    },
+    set coords(value){
+        this.setAttribute('coords',value);
+    },
+    get href(){
+        return this.getAttribute('href');
+    },
+    set href(value){
+        this.setAttribute('href',value);
+    },
+    get noHref(){
+        return this.hasAttribute('href');
+    },
+    get shape(){
+        //TODO
+        return 0;
+    },
+    get tabIndex(){
+        return this.getAttribute('tabindex');
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',value);
+    },
+    get target(){
+        return this.getAttribute('target');
+    },
+    set target(value){
+        this.setAttribute('target',value);
+    }
+});
+
+			$log(&quot;Defining HTMLBaseElement&quot;);
+/* 
+* HTMLBaseElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLBaseElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLBaseElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLBaseElement.prototype = new HTMLElement;
+__extend__(HTMLBaseElement.prototype, {
+    get href(){
+        return this.getAttribute('href');
+    },
+    set href(value){
+        this.setAttribute('href',value);
+    },
+    get target(){
+        return this.getAttribute('target');
+    },
+    set target(value){
+        this.setAttribute('target',value);
+    }
+});
+
+			$log(&quot;Defining HTMLQuoteElement&quot;);
+/* 
+* HTMLQuoteElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLQuoteElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLQuoteElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLQuoteElement.prototype = new HTMLElement;
+__extend__(HTMLQuoteElement.prototype, {
+    get cite(){
+        return this.getAttribute('cite');
+    },
+    set cite(value){
+        this.setAttribute('cite',value);
+    }
+});
+
+			$log(&quot;Defining HTMLButtonElement&quot;);
+/* 
+* HTMLButtonElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLButtonElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLButtonElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLButtonElement.prototype = new HTMLElement;
+__extend__(HTMLButtonElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    },
+    get tabIndex(){
+        return Number(this.getAttribute('tabindex'));
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',Number(value));
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+    get value(){
+        return this.getAttribute('value');
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    }
+});
+
+			$log(&quot;Defining HTMLTableColElement&quot;);
+/* 
+* HTMLTableColElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLTableColElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLTableColElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLTableColElement.prototype = new HTMLElement;
+__extend__(HTMLTableColElement.prototype, {
+    get align(){
+        return this.getAttribute('align');
+    },
+    set align(value){
+        this.setAttribute('align', value);
+    },
+    get ch(){
+        return this.getAttribute('ch');
+    },
+    set ch(value){
+        this.setAttribute('ch', value);
+    },
+    get chOff(){
+        return this.getAttribute('ch');
+    },
+    set chOff(value){
+        this.setAttribute('ch', value);
+    },
+    get span(){
+        return this.getAttribute('span');
+    },
+    set span(value){
+        this.setAttribute('span', value);
+    },
+    get vAlign(){
+        return this.getAttribute('valign');
+    },
+    set vAlign(value){
+        this.setAttribute('valign', value);
+    },
+    get width(){
+        return this.getAttribute('width');
+    },
+    set width(value){
+        this.setAttribute('width', value);
+    }
+});
+
+			$log(&quot;Defining HTMLModElement&quot;);
+/* 
+* HTMLModElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLModElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLModElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLModElement.prototype = new HTMLElement;
+__extend__(HTMLModElement.prototype, {
+    get cite(){
+        return this.getAttribute('cite');
+    },
+    set cite(value){
+        this.setAttribute('cite', value);
+    },
+    get dateTime(){
+        return this.getAttribute('datetime');
+    },
+    set dateTime(value){
+        this.setAttribute('datetime', value);
+    }
+});
+
+			$log(&quot;Defining HTMLFieldSetElement&quot;);
+/* 
+* HTMLFieldSetElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLFieldSetElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLFieldSetElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLFieldSetElement.prototype = new HTMLElement;
+__extend__(HTMLFieldSetElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    }
+});
+
+			$log(&quot;Defining HTMLFormElement&quot;);
+/* 
+* HTMLAnchorElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Form&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+$w.__defineGetter__(&quot;HTMLFormElement&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var HTMLFormElement = function(ownerDocument){
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLFormElement.prototype = new HTMLElement;
+__extend__(HTMLFormElement.prototype,{
+    get acceptCharset(){ 
+        return this.getAttribute('accept-charset');
+        
+    },
+    set acceptCharset(acceptCharset){
+        this.setAttribute('accept-charset', acceptCharset);
+        
+    },
+    get action(){
+        return this.getAttribute('action');
+        
+    },
+    set action(action){
+        this.setAttribute('action', action);
+        
+    },
+    get elements() {
+        return this.getElementsByTagName(&quot;*&quot;);
+        
+    },
+    get enctype(){
+        return this.getAttribute('enctype');
+        
+    },
+    set enctype(enctype){
+        this.setAttribute('enctype', enctype);
+        
+    },
+    get length() {
+        return this.elements.length;
+        
+    },
+    get method(){
+        return this.getAttribute('method');
+        
+    },
+    set method(action){
+        this.setAttribute('method', method);
+        
+    },
+	get name() {
+	    return this.getAttribute(&quot;name&quot;) || &quot;&quot;; 
+	    
+    },
+	set name(val) { 
+	    return this.setAttribute(&quot;name&quot;,val); 
+	    
+    },
+	get target() { 
+	    return this.getAttribute(&quot;target&quot;) || &quot;&quot;; 
+	    
+    },
+	set target(val) { 
+	    return this.setAttribute(&quot;target&quot;,val); 
+	    
+    },
+	submit:function(){
+	    __submit__(this);
+	    
+    },
+	reset:function(){
+	    __reset__(this);
+	    
+    }
+});
+
+			$log(&quot;Defining HTMLFrameElement&quot;);
+/* 
+* HTMLFrameElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLFrameElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLFrameElement = function(ownerDocument) {
+    //$log(&quot;creating frame element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLFrameElement.prototype = new HTMLElement;
+__extend__(HTMLFrameElement.prototype, {
+    get frameBorder(){
+        return this.getAttribute('border')||&quot;&quot;;
+    },
+    set frameBorder(value){
+        this.setAttribute('border', value);
+    },
+    get longDesc(){
+        return this.getAttribute('longdesc')||&quot;&quot;;
+    },
+    set longDesc(value){
+        this.setAttribute('longdesc', value);
+    },
+    get marginHeight(){
+        return this.getAttribute('marginheight')||&quot;&quot;;
+    },
+    set marginHeight(value){
+        this.setAttribute('marginheight', value);
+    },
+    get marginWidth(){
+        return this.getAttribute('marginwidth')||&quot;&quot;;
+    },
+    set marginWidth(value){
+        this.setAttribute('marginwidth', value);
+    },
+    get name(){
+        return this.getAttribute('name')||&quot;&quot;;
+    },
+    set name(value){
+        this.setAttribute('name', value);
+    },
+    get noResize(){
+        return this.getAttribute('noresize')||&quot;&quot;;
+    },
+    set noResize(value){
+        this.setAttribute('noresize', value);
+    },
+    get scrolling(){
+        return this.getAttribute('scrolling')||&quot;&quot;;
+    },
+    set scrolling(value){
+        this.setAttribute('scrolling', value);
+    },
+    get src(){
+        return this.getAttribute('src')||&quot;&quot;;
+    },
+    set src(value){
+        this.setAttribute('src', value);
+    },
+    get contentDocument(){
+        $log(&quot;getting content document for (i)frame&quot;);
+        if(!this._content){
+            this._content = new HTMLDocument($implementation);
+            if(this.src.length &gt; 0){
+                $log(&quot;Loading frame content from &quot; + this.src);
+                try{
+                    this._content.load(this.src);
+                }catch(e){
+                    $error(&quot;failed to load &quot; + this.src);
+                }
+            }
+        }
+        return true;
+    }
+});
+
+			$log(&quot;Defining HTMLFrameSetElement&quot;);
+/* 
+* HTMLFrameSetElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLFrameSetElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLFrameSetElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLFrameSetElement.prototype = new HTMLElement;
+__extend__(HTMLFrameSetElement.prototype, {
+    get cols(){
+        return this.getAttribute('cols');
+    },
+    set cols(value){
+        this.setAttribute('cols', value);
+    },
+    get rows(){
+        return this.getAttribute('rows');
+    },
+    set rows(value){
+        this.setAttribute('rows', value);
+    }
+});
+
+			$log(&quot;Defining HTMLHeadElement&quot;);
+/* 
+* HTMLHeadElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLHeadElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLHeadElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLHeadElement.prototype = new HTMLElement;
+__extend__(HTMLHeadElement.prototype, {
+    get profile(){
+        return this.getAttribute('profile');
+    },
+    set profile(value){
+        this.setAttribute('profile', value);
+    },
+});
+
+			$log(&quot;Defining HTMLIFrameElement&quot;);
+/* 
+* HTMLIFrameElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLIFrameElement&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var HTMLIFrameElement = function(ownerDocument) {
+    //$log(&quot;creating iframe element&quot;);
+    this.HTMLFrameElement = HTMLFrameElement;
+    this.HTMLFrameElement(ownerDocument);
+};
+HTMLIFrameElement.prototype = new HTMLFrameElement;
+__extend__(HTMLIFrameElement.prototype, {
+	get height() { 
+	    return this.getAttribute(&quot;height&quot;) || &quot;&quot;; 
+    },
+	set height(val) { 
+	    return this.setAttribute(&quot;height&quot;,val); 
+    },
+	get width() { 
+	    return this.getAttribute(&quot;width&quot;) || &quot;&quot;; 
+    },
+	set width(val) { 
+	    return this.setAttribute(&quot;width&quot;,val); 
+    }
+});
+
+
+			$log(&quot;Defining HTMLImageElement&quot;);
+/* 
+* HTMLImageElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLImageElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLImageElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLImageElement.prototype = new HTMLElement;
+__extend__(HTMLImageElement.prototype, {
+    get alt(){
+        return this.getAttribute('alt');
+    },
+    set alt(value){
+        this.setAttribute('alt', value);
+    },
+    get height(){
+        return this.getAttribute('height');
+    },
+    set height(value){
+        this.setAttribute('height', value);
+    },
+    get isMap(){
+        return this.hasAttribute('map');
+    },
+    set useMap(value){
+        this.setAttribute('map', value);
+    },
+    get longDesc(){
+        return this.getAttribute('longdesc');
+    },
+    set longDesc(value){
+        this.setAttribute('longdesc', value);
+    },
+    get name(){
+        return this.getAttribute('name');
+    },
+    set name(value){
+        this.setAttribute('name', value);
+    },
+    get src(){
+        return this.getAttribute('src');
+    },
+    set src(value){
+        this.setAttribute('src', value);
+    },
+    get width(){
+        return this.getAttribute('width');
+    },
+    set width(value){
+        this.setAttribute('width', value);
+    }
+});
+
+			$log(&quot;Defining HTMLInputElement&quot;);
+/* 
+* HTMLInputElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLInputElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLInputElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLInputElement.prototype = new HTMLElement;
+__extend__(HTMLInputElement.prototype, {
+    get defaultValue(){
+        return this.getAttribute('defaultValue');
+    },
+    set defaultValue(value){
+        this.setAttribute('defaultValue', value);
+    },
+    get defaultChecked(){
+        return this.getAttribute('defaultChecked');
+    },
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    },
+    get access(){
+        return this.getAttribute('access');
+    },
+    set access(value){
+        this.setAttribute('access', value);
+    },
+    get alt(){
+        return this.getAttribute('alt');
+    },
+    set alt(value){
+        this.setAttribute('alt', value);
+    },
+    get checked(){
+        return (this.getAttribute('checked')==='checked');
+    },
+    set checked(){
+        this.setAttribute('checked', 'checked');
+    },
+    get disabled(){
+        return (this.getAttribute('disabled')==='disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled', 'disabled');
+    },
+    get maxLength(){
+        return Number(this.getAttribute('maxlength')||'0');
+    },
+    set maxLength(value){
+        this.setAttribute('maxlength', value);
+    },
+    get name(){
+        return this.getAttribute('name')||'';
+    },
+    set name(value){
+        this.setAttribute('name', value);
+    },
+    get readOnly(){
+        return (this.getAttribute('readonly')==='readonly');
+    },
+    set readOnly(value){
+        this.setAttribute('readonly', 'readonly');
+    },
+    get size(){
+        return this.getAttribute('size');
+    },
+    set size(value){
+        this.setAttribute('size', value);
+    },
+    get src(){
+        return this.getAttribute('src');
+    },
+    set src(value){
+        this.setAttribute('src', value);
+    },
+    get tabIndex(){
+        return Number(this.getAttribute('tabindex'));
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',Number(value));
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+    get useMap(){
+        return this.getAttribute('map');
+    },
+    get value(){
+        return this.getAttribute('value');
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    },
+	blur:function(){
+	    __blur__(this);
+	    
+    },
+	focus:function(){
+	    __focus__(this);
+	    
+    },
+	select:function(){
+	    __select__(this);
+	    
+    },
+	click:function(){
+	    __click__(this);
+	    
+    }
+});
+
+			$log(&quot;Defining HTMLLabelElement&quot;);
+/* 
+* HTMLLabelElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLLabelElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLLabelElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLLabelElement.prototype = new HTMLElement;
+__extend__(HTMLLabelElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    },
+    get htmlFor(){
+        return this.getAttribute('for');
+    },
+    set htmlFor(value){
+        this.setAttribute('for',value);
+    },
+});
+
+			$log(&quot;Defining HTMLLegendElement&quot;);
+/* 
+* HTMLLegendElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLLegendElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLLegendElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLLegendElement.prototype = new HTMLElement;
+__extend__(HTMLLegendElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    }
+});
+
+			/**
+* Link - HTMLElement 
+*/
+$w.__defineGetter__(&quot;Link&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+$log(&quot;Defining HTMLLinkElement&quot;);
+/* 
+* HTMLLinkElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLLinkElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLLinkElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLLinkElement.prototype = new HTMLElement;
+__extend__(HTMLLinkElement.prototype, {
+    get disabled(){
+        return this.getAttribute('disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled',value);
+    },
+    get charset(){
+        return this.getAttribute('charset');
+    },
+    set charset(value){
+        this.setAttribute('charset',value);
+    },
+    get href(){
+        return this.getAttribute('href');
+    },
+    set href(value){
+        this.setAttribute('href',value);
+    },
+    get hreflang(){
+        return this.getAttribute('hreflang');
+    },
+    set hreflang(value){
+        this.setAttribute('hreflang',value);
+    },
+    get media(){
+        return this.getAttribute('media');
+    },
+    set media(value){
+        this.setAttribute('media',value);
+    },
+    get rel(){
+        return this.getAttribute('rel');
+    },
+    set rel(value){
+        this.setAttribute('rel',value);
+    },
+    get rev(){
+        return this.getAttribute('rev');
+    },
+    set rev(value){
+        this.setAttribute('rev',value);
+    },
+    get target(){
+        return this.getAttribute('target');
+    },
+    set target(value){
+        this.setAttribute('target',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    }
+});
+
+			
+
+			$log(&quot;Defining HTMLMapElement&quot;);
+/* 
+* HTMLMapElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLMapElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLMapElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLMapElement.prototype = new HTMLElement;
+__extend__(HTMLMapElement.prototype, {
+    get areas(){
+        return this.getElementsByTagName('area');
+    },
+    get name(){
+        return this.getAttribute('name');
+    },
+    set name(value){
+        this.setAttribute('name',value);
+    }
+});
+
+			$log(&quot;Defining HTMLMetaElement&quot;);
+/* 
+* HTMLMetaElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLMetaElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLMetaElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLMetaElement.prototype = new HTMLElement;
+__extend__(HTMLMetaElement.prototype, {
+    get content(){
+        return this.getAttribute('content');
+    },
+    set content(value){
+        this.setAttribute('content',value);
+    },
+    get httpEquiv(){
+        return this.getAttribute('http-equiv');
+    },
+    set httpEquiv(value){
+        this.setAttribute('http-equiv',value);
+    },
+    get name(){
+        return this.getAttribute('name');
+    },
+    set name(value){
+        this.setAttribute('name',value);
+    },
+    get scheme(){
+        return this.getAttribute('scheme');
+    },
+    set scheme(value){
+        this.setAttribute('scheme',value);
+    }
+});
+
+			$log(&quot;Defining HTMLObjectElement&quot;);
+/* 
+* HTMLObjectElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLObjectElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLObjectElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLObjectElement.prototype = new HTMLElement;
+__extend__(HTMLObjectElement.prototype, {
+    get code(){
+        return this.getAttribute('code');
+    },
+    set code(value){
+        this.setAttribute('code',value);
+    },
+    get archive(){
+        return this.getAttribute('archive');
+    },
+    set archive(value){
+        this.setAttribute('archive',value);
+    },
+    get codeBase(){
+        return this.getAttribute('codebase');
+    },
+    set codeBase(value){
+        this.setAttribute('codebase',value);
+    },
+    get codeType(){
+        return this.getAttribute('codetype');
+    },
+    set codeType(value){
+        this.setAttribute('codetype',value);
+    },
+    get data(){
+        return this.getAttribute('data');
+    },
+    set data(value){
+        this.setAttribute('data',value);
+    },
+    get declare(){
+        return this.getAttribute('declare');
+    },
+    set declare(value){
+        this.setAttribute('declare',value);
+    },
+    get height(){
+        return this.getAttribute('height');
+    },
+    set height(value){
+        this.setAttribute('height',value);
+    },
+    get standby(){
+        return this.getAttribute('standby');
+    },
+    set standby(value){
+        this.setAttribute('standby',value);
+    },
+    get tabIndex(){
+        return this.getAttribute('tabindex');
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+    get useMap(){
+        return this.getAttribute('usemap');
+    },
+    set useMap(value){
+        this.setAttribute('usemap',value);
+    },
+    get width(){
+        return this.getAttribute('width');
+    },
+    set width(value){
+        this.setAttribute('width',value);
+    },
+    get contentDocument(){
+        return this.ownerDocument;
+    }
+});
+
+			$log(&quot;Defining HTMLOptGroupElement&quot;);
+/* 
+* HTMLOptGroupElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLOptGroupElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLOptGroupElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLOptGroupElement.prototype = new HTMLElement;
+__extend__(HTMLOptGroupElement.prototype, {
+    get disabled(){
+        return this.getAttribute('disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled',value);
+    },
+    get label(){
+        return this.getAttribute('label');
+    },
+    set label(value){
+        this.setAttribute('label',value);
+    },
+});
+
+			$log(&quot;Defining HTMLOptionElement&quot;);
+/* 
+* HTMLOptionElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLOptionElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLOptionElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLOptionElement.prototype = new HTMLElement;
+__extend__(HTMLOptionElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get defaultSelected(){
+        return this.getAttribute('defaultSelected');
+    },
+    set defaultSelected(value){
+        this.setAttribute('defaultSelected',value);
+    },
+    get text(){
+        return this.nodeValue;
+    },
+    get index(){
+        var options = this.parent.childNodes;
+        for(var i; i&lt;options.length;i++){
+            if(this == options[i])
+                return i;
+        }
+        return -1;
+    },
+    get disabled(){
+        return this.getAttribute('disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled',value);
+    },
+    get label(){
+        return this.getAttribute('label');
+    },
+    set label(value){
+        this.setAttribute('label',value);
+    },
+    get selected(){
+        return (this.getAttribute('selected')==='selected');
+    },
+    set selected(){
+        this.setAttribute('selected','selected');
+    },
+    get value(){
+        return this.getAttribute('value');
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    }
+});
+
+			$log(&quot;Defining HTMLParamElement&quot;);
+/* 
+* HTMLParamElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLParamElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLParamElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLParamElement.prototype = new HTMLElement;
+__extend__(HTMLParamElement.prototype, {
+    get name(){
+        return this.getAttribute('name');
+    },
+    set name(value){
+        this.setAttribute('name',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+    get value(){
+        return this.getAttribute('value');
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    },
+    get valueType(){
+        return this.getAttribute('valuetype');
+    },
+    set valueType(value){
+        this.setAttribute('valuetype',value);
+    },
+});
+
+			$log(&quot;Defining HTMLScriptElement&quot;);
+/* 
+* HTMLScriptElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLScriptElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLScriptElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLScriptElement.prototype = new HTMLElement;
+__extend__(HTMLScriptElement.prototype, {
+    get text(){
+        return this.nodeValue;
+    },
+    get htmlFor(){
+        return this.getAttribute('for');
+    },
+    set htmlFor(value){
+        this.setAttribute('for',value);
+    },
+    get event(){
+        return this.getAttribute('event');
+    },
+    set event(value){
+        this.setAttribute('event',value);
+    },
+    get charset(){
+        return this.getAttribute('charset');
+    },
+    set charset(value){
+        this.setAttribute('charset',value);
+    },
+    get defer(){
+        return this.getAttribute('defer');
+    },
+    set defer(value){
+        this.setAttribute('defer',value);
+    },
+    get src(){
+        return this.getAttribute('src');
+    },
+    set src(value){
+        this.setAttribute('src',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    }
+});
+
+			$log(&quot;Defining HTMLSelectElement&quot;);
+/* 
+* HTMLSelectElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLSelectElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLSelectElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLSelectElement.prototype = new HTMLElement;
+__extend__(HTMLSelectElement.prototype, {
+    get type(){
+        return this.getAttribute('type');
+    },
+    get selectedIndex(){
+        var options = this.options;
+        for(var i=0;i&lt;options.length;i++){
+            if(options[i].selected){
+                return i;
+            }
+        };
+        return -1;
+    },
+    set selectedIndex(value){
+        this.options[Number(value)].selected = 'selected';
+    },
+    get value(){
+        return this.getAttribute('value')||'';
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    },
+    get length(){
+        return this.options.length;
+    },
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get options(){
+        return this.getElementsByTagName('option');
+    },
+    get disabled(){
+        return (this.getAttribute('disabled')==='disabled');
+    },
+    set disabled(){
+        this.setAttribute('disabled','disabled');
+    },
+    get multiple(){
+        return this.getAttribute('multiple');
+    },
+    set multiple(value){
+        this.setAttribute('multiple',value);
+    },
+    get name(){
+        return this.getAttribute('name')||'';
+    },
+    set name(value){
+        this.setAttribute('name',value);
+    },
+    get size(){
+        return Number(this.getAttribute('size'));
+    },
+    set size(value){
+        this.setAttribute('size',value);
+    },
+    get tabIndex(){
+        return Number(this.getAttribute('tabindex'));
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',value);
+    },
+    add : function(){
+        __add__(this);
+    },
+    remove : function(){
+        __remove__(this);
+    },
+    blur: function(){
+        __blur__(this);
+    },
+    focus: function(){
+        __focus__(this);
+    }
+});
+
+			$log(&quot;Defining HTMLStyleElement&quot;);
+/* 
+* HTMLStyleElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLStyleElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLStyleElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLStyleElement.prototype = new HTMLElement;
+__extend__(HTMLStyleElement.prototype, {
+    get disabled(){
+        return this.getAttribute('disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled',value);
+    },
+    get media(){
+        return this.getAttribute('media');
+    },
+    set media(value){
+        this.setAttribute('media',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+});
+
+			$log(&quot;Defining Event&quot;);
+/*
+* event.js
+*/
+$w.__defineGetter__(&quot;Event&quot;, function(){
+  __extend__(this,{
+    CAPTURING_PHASE : 1,
+    AT_TARGET       : 2,
+    BUBBLING_PHASE  : 3
+  });
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var Event = function(options){
+  if(options === undefined){options={target:window,currentTarget:window};}
+  __extend__(this,{
+    CAPTURING_PHASE : 1,
+    AT_TARGET       : 2,
+    BUBBLING_PHASE  : 3
+  });
+  $log(&quot;Creating new Event&quot;);
+  var $bubbles = options.bubbles?options.bubbles:true,
+      $cancelable = options.cancelable?options.cancelable:true,
+      $currentTarget = options.currentTarget?options.currentTarget:null,
+      $eventPhase = options.eventPhase?options.eventPhase:Event.CAPTURING_PHASE,
+      $target = options.eventPhase?options.eventPhase:document,
+      $timestamp = options.timestamp?options.timestamp:new Date().getTime().toString(),
+      $type = options.type?options.type:&quot;&quot;;
+  return __extend__(this,{
+    get bubbles(){return $bubbles;},
+    get cancelable(){return $cancelable;},
+    get currentTarget(){return $currentTarget;},
+    get eventPhase(){return $eventPhase;},
+    get target(){return $target;},
+    get timestamp(){return $timestamp;},
+    get type(){return $type;},
+    initEvent: function(type,bubbles,cancelable){
+      $type=type?type:$type;
+      $bubbles=bubbles?bubbles:$bubbles;
+      $cancelable=cancelable?cancelable:$cancelable;
+    },
+    preventDefault: function(){return;/* TODO */},
+    stopPropagation: function(){return;/* TODO */}
+  });
+};
+
+$log(&quot;Defining MouseEvent&quot;);
+/*
+*	mouseevent.js
+*/
+$log(&quot;Defining MouseEvent&quot;);
+/*
+*	uievent.js
+*/
+
+var $onblur,
+    $onfocus,
+    $onresize;/*
+* CSS2Properties - DOM Level 2 CSS
+*/
+$w.__defineGetter__(&quot;CSS2Properties&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+var CSS2Properties = function(options){
+    __extend__(this, __supportedStyles__);
+    __cssTextToStyles__(this, options.cssText?options.cssText:&quot;&quot;);
+};
+//__extend__(CSS2Properties.prototype, __supportedStyles__);
+__extend__(CSS2Properties.prototype, {
+    get cssText(){
+        return Array.prototype.apply.join(this,[';\n']);
+    },
+    set cssText(cssText){ 
+        __cssTextToStyles__(this, cssText); 
+    },
+    getPropertyCSSValue : function(){
+        
+    },
+    getPropertyPriority : function(){
+        
+    },
+    getPropertyValue : function(name){
+		var camelCase = name.replace(/\-(\w)/g, function(all, letter){
+			return letter.toUpperCase();
+		});
+        var i, value = this[camelCase];
+        if(value === undefined){
+            for(i=0;i&lt;this.length;i++){
+                if(this[i]===name){
+                    return this[i];
+                }
+            }
+        }
+        return value;
+    },
+    item : function(index){
+        return this[index];
+    },
+    removeProperty: function(){
+        
+    },
+    setProperty: function(){
+        
+    },
+    toString:function(){
+        if (this.length &gt;0){
+            return &quot;{\n\t&quot;+Array.prototype.join.apply(this,[';\n\t'])+&quot;}\n&quot;;
+        }else{
+            return '';
+        }
+    }
+});
+
+var __cssTextToStyles__ = function(css2props, cssText){
+    var styleArray=[];
+    var style, name, value, camelCaseName, w3cName, styles = cssText.split(';');
+    for ( var i = 0; i &lt; styles.length; i++ ) {
+        //$log(&quot;Adding style property &quot; + styles[i]);
+    	style = styles[i].split(':');
+    	if ( style.length == 2 ){
+    	    //keep a reference to the original name of the style which was set
+    	    //this is the w3c style setting method.
+    	    styleArray[styleArray.length] = w3cName = styles[i];
+            //camel case for dash case
+    	    value = trim(style[1]);
+            camelCaseName = trim(style[0].replace(/\-(\w)/g, function(all, letter){
+				return letter.toUpperCase();
+			}));
+            //$log('CSS Style Name:  ' + camelCaseName);
+            if(css2props[camelCaseName]!==undefined){
+                //set the value internally with camelcase name 
+                //$log('Setting css ' + camelCaseName + ' to ' + value);
+                css2props[camelCaseName] = value;
+            };
+    	}
+    }
+    __setArray__(css2props, styleArray);
+};
+//Obviously these arent all supported but by commenting out various sections
+//this provides a single location to configure what is exposed as supported.
+//These will likely need to be functional getters/setters in the future to deal with
+//the variation on input formulations
+var __supportedStyles__ = {
+    azimuth: &quot;&quot;,
+    background:	&quot;&quot;,
+    backgroundAttachment:	&quot;&quot;,
+    backgroundColor:	&quot;&quot;,
+    backgroundImage:	&quot;&quot;,
+    backgroundPosition:	&quot;&quot;,
+    backgroundRepeat:	&quot;&quot;,
+    border:	&quot;&quot;,
+    borderBottom:	&quot;&quot;,
+    borderBottomColor:	&quot;&quot;,
+    borderBottomStyle:	&quot;&quot;,
+    borderBottomWidth:	&quot;&quot;,
+    borderCollapse:	&quot;&quot;,
+    borderColor:	&quot;&quot;,
+    borderLeft:	&quot;&quot;,
+    borderLeftColor:	&quot;&quot;,
+    borderLeftStyle:	&quot;&quot;,
+    borderLeftWidth:	&quot;&quot;,
+    borderRight:	&quot;&quot;,
+    borderRightColor:	&quot;&quot;,
+    borderRightStyle:	&quot;&quot;,
+    borderRightWidth:	&quot;&quot;,
+    borderSpacing:	&quot;&quot;,
+    borderStyle:	&quot;&quot;,
+    borderTop:	&quot;&quot;,
+    borderTopColor:	&quot;&quot;,
+    borderTopStyle:	&quot;&quot;,
+    borderTopWidth:	&quot;&quot;,
+    borderWidth:	&quot;&quot;,
+    bottom:	&quot;&quot;,
+    captionSide:	&quot;&quot;,
+    clear:	&quot;&quot;,
+    clip:	&quot;&quot;,
+    color:	&quot;&quot;,
+    content:	&quot;&quot;,
+    counterIncrement:	&quot;&quot;,
+    counterReset:	&quot;&quot;,
+    cssFloat:	&quot;&quot;,
+    cue:	&quot;&quot;,
+    cueAfter:	&quot;&quot;,
+    cueBefore:	&quot;&quot;,
+    cursor:	&quot;&quot;,
+    direction:	&quot;&quot;,
+    display:	&quot;&quot;,
+    elevation:	&quot;&quot;,
+    emptyCells:	&quot;&quot;,
+    font:	&quot;&quot;,
+    fontFamily:	&quot;&quot;,
+    fontSize:	&quot;&quot;,
+    fontSizeAdjust:	&quot;&quot;,
+    fontStretch:	&quot;&quot;,
+    fontStyle:	&quot;&quot;,
+    fontVariant:	&quot;&quot;,
+    fontWeight:	&quot;&quot;,
+    height:	&quot;&quot;,
+    left:	&quot;&quot;,
+    letterSpacing:	&quot;&quot;,
+    lineHeight:	&quot;&quot;,
+    listStyle:	&quot;&quot;,
+    listStyleImage:	&quot;&quot;,
+    listStylePosition:	&quot;&quot;,
+    listStyleType:	&quot;&quot;,
+    margin:	&quot;&quot;,
+    marginBottom:	&quot;&quot;,
+    marginLeft:	&quot;&quot;,
+    marginRight:	&quot;&quot;,
+    marginTop:	&quot;&quot;,
+    markerOffset:	&quot;&quot;,
+    marks:	&quot;&quot;,
+    maxHeight:	&quot;&quot;,
+    maxWidth:	&quot;&quot;,
+    minHeight:	&quot;&quot;,
+    minWidth:	&quot;&quot;,
+    opacity:	1,
+    orphans:	&quot;&quot;,
+    outline:	&quot;&quot;,
+    outlineColor:	&quot;&quot;,
+    outlineOffset:	&quot;&quot;,
+    outlineStyle:	&quot;&quot;,
+    outlineWidth:	&quot;&quot;,
+    overflow:	&quot;&quot;,
+    overflowX:	&quot;&quot;,
+    overflowY:	&quot;&quot;,
+    padding:	&quot;&quot;,
+    paddingBottom:	&quot;&quot;,
+    paddingLeft:	&quot;&quot;,
+    paddingRight:	&quot;&quot;,
+    paddingTop:	&quot;&quot;,
+    page:	&quot;&quot;,
+    pageBreakAfter:	&quot;&quot;,
+    pageBreakBefore:	&quot;&quot;,
+    pageBreakInside:	&quot;&quot;,
+    pause:	&quot;&quot;,
+    pauseAfter:	&quot;&quot;,
+    pauseBefore:	&quot;&quot;,
+    pitch:	&quot;&quot;,
+    pitchRange:	&quot;&quot;,
+    position:	&quot;&quot;,
+    quotes:	&quot;&quot;,
+    richness:	&quot;&quot;,
+    right:	&quot;&quot;,
+    size:	&quot;&quot;,
+    speak:	&quot;&quot;,
+    speakHeader:	&quot;&quot;,
+    speakNumeral:	&quot;&quot;,
+    speakPunctuation:	&quot;&quot;,
+    speechRate:	&quot;&quot;,
+    stress:	&quot;&quot;,
+    tableLayout:	&quot;&quot;,
+    textAlign:	&quot;&quot;,
+    textDecoration:	&quot;&quot;,
+    textIndent:	&quot;&quot;,
+    textShadow:	&quot;&quot;,
+    textTransform:	&quot;&quot;,
+    top:	&quot;&quot;,
+    unicodeBidi:	&quot;&quot;,
+    verticalAlign:	&quot;&quot;,
+    visibility:	&quot;&quot;,
+    voiceFamily:	&quot;&quot;,
+    volume:	&quot;&quot;,
+    whiteSpace:	&quot;&quot;,
+    widows:	&quot;&quot;,
+    width:	&quot;&quot;,
+    wordSpacing:	&quot;&quot;,
+    zIndex:	&quot;&quot;
+};/* 
+* CSSRule - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CSSRule&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var CSSRule = function(options){
+  var $style, 
+      $selectorText = options.selectorText?options.selectorText:&quot;&quot;;
+      $style = new CSS2Properties({cssText:options.cssText?options.cssText:null});
+    return __extend__(this, {
+      get style(){return $style;},
+      get selectorText(){return $selectorText;},
+      set selectorText(selectorText){$selectorText = selectorText;}
+    });
+};
+/* 
+* CSSStyleSheet - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CSSStyleSheet&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var CSSStyleSheet = function(options){
+    var $cssRules, 
+        $disabled = options.disabled?options.disabled:false,
+        $href = options.href?options.href:null,
+        $parentStyleSheet = options.parentStyleSheet?options.parentStyleSheet:null,
+        $title = options.title?options.title:&quot;&quot;,
+        $type = &quot;text/css&quot;;
+        
+    function parseStyleSheet(text){
+      //this is pretty ugly, but text is the entire text of a stylesheet
+      var cssRules = [];
+    	if (!text) text = &quot;&quot;;
+    	text = trim(text.replace(/\/\*(\r|\n|.)*\*\//g,&quot;&quot;));
+    	// TODO: @import ?
+    	var blocks = text.split(&quot;}&quot;);
+    	blocks.pop();
+    	var i, len = blocks.length;
+    	var definition_block, properties, selectors;
+    	for (i=0; i&lt;len; i++){
+    		definition_block = blocks[i].split(&quot;{&quot;);
+    		if(definition_block.length === 2){
+      		selectors = definition_block[0].split(&quot;,&quot;);
+      		for(var j=0;j&lt;selectors.length;j++){
+      		  cssRules.push(new CSSRule({
+      		    selectorText:selectors[j],
+      		    cssText:definition_block[1]
+      		  }));
+      		}
+      		__setArray__($cssRules, cssRules);
+    		}
+    	}
+    };
+    parseStyleSheet(options.text);
+    return __extend__(this, {
+      get cssRules(){return $cssRules;},
+      get rule(){return $cssRules;},//IE - may be deprecated
+      get href(){return $href;},
+      get parentStyleSheet(){return $parentStyleSheet;},
+      get title(){return $title;},
+      get type(){return $type;},
+      addRule: function(selector, style, index){/*TODO*/},
+      deleteRule: function(index){/*TODO*/},
+      insertRule: function(rule, index){/*TODO*/},
+      removeRule: function(index){this.deleteRule(index);}//IE - may be deprecated
+    });
+};
+/*
+*	location.js
+*   - requires env
+*/
+$log(&quot;Initializing Window Location.&quot;);
+//the current location
+var $location = $env.location('./');
+
+$w.__defineSetter__(&quot;location&quot;, function(url){
+  //$w.onunload();
+	$w.document.load(url);
+	$location = url;
+	setHistory($location);
+});
+
+$w.__defineGetter__(&quot;location&quot;, function(url){
+	var hash 	 = new RegExp('(\\#.*)'),
+		hostname = new RegExp('\/\/([^\:\/]+)'),
+		pathname = new RegExp('(\/[^\\?\\#]*)'),
+		port 	 = new RegExp('\:(\\d+)\/'),
+		protocol = new RegExp('(^\\w*\:)'),
+		search 	 = new RegExp('(\\?[^\\#]*)');
+	return {
+		get hash(){
+			var m = hash.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set hash(_hash){
+			//setting the hash is the only property of the location object
+			//that doesn't cause the window to reload
+			_hash = _hash.indexOf('#')===0?_hash:&quot;#&quot;+_hash;	
+			$location = this.protocol + this.host + this.pathname + 
+				this.search + _hash;
+			setHistory(_hash, &quot;hash&quot;);
+		},
+		get host(){
+			return this.hostname + (this.port !== &quot;&quot;)?&quot;:&quot;+this.port:&quot;&quot;;
+		},
+		set host(_host){
+			$w.location = this.protocol + _host + this.pathname + 
+				this.search + this.hash;
+		},
+		get hostname(){
+			var m = hostname.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set hostname(_hostname){
+			$w.location = this.protocol + _hostname + ((this.port===&quot;&quot;)?&quot;&quot;:(&quot;:&quot;+this.port)) +
+			 	 this.pathname + this.search + this.hash;
+		},
+		get href(){
+			//This is the only env specific function
+			return $location;
+		},
+		set href(url){
+			$w.location = url;	
+		},
+		get pathname(){
+			var m = this.href;
+			m = pathname.exec(m.substring(m.indexOf(this.hostname)));
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;/&quot;;
+		},
+		set pathname(_pathname){
+			$w.location = this.protocol + this.host + _pathname + 
+				this.search + this.hash;
+		},
+		get port(){
+			var m = port.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set port(_port){
+			$w.location = this.protocol + this.hostname + &quot;:&quot;+_port + this.pathname + 
+				this.search + this.hash;
+		},
+		get protocol(){
+			return protocol.exec(this.href)[0];
+		},
+		set protocol(_protocol){
+			$w.location = _protocol + this.host + this.pathname + 
+				this.search + this.hash;
+		},
+		get search(){
+			var m = search.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set search(_search){
+			$w.location = this.protocol + this.host + this.pathname + 
+				_search + this.hash;
+		},
+		toString: function(){
+			return this.href;
+		},
+		reload: function(force){
+			//TODO
+		},
+		replace: function(url){
+			//TODO
+		}
+	};
+});
+
+/*
+*	history.js
+*/
+
+  $log(&quot;Initializing Window History.&quot;);
+	$currentHistoryIndex = 0;
+	$history = [];
+	
+	// Browser History
+	$w.__defineGetter__(&quot;history&quot;, function(){	
+		return {
+			get length(){ return $history.length; },
+			back : function(count){
+				if(count){
+					go(-count);
+				}else{go(-1);}
+			},
+			forward : function(count){
+				if(count){
+					go(count);
+				}else{go(1);}
+			},
+			go : function(target){
+				if(typeof target == &quot;number&quot;){
+					target = $currentHistoryIndex+target;
+					if(target &gt; -1 &amp;&amp; target &lt; $history.length){
+						if($history[target].location == &quot;hash&quot;){
+							$w.location.hash = $history[target].value;
+						}else{
+							$w.location = $history[target].value;
+						}
+						$currentHistoryIndex = target;
+						//remove the last item added to the history
+						//since we are moving inside the history
+						$history.pop();
+					}
+				}else{
+					//TODO: walk throu the history and find the 'best match'
+				}
+			}
+		};
+	});
+
+	//Here locationPart is the particutlar method/attribute 
+	// of the location object that was modified.  This allows us
+	// to modify the correct portion of the location object
+	// when we navigate the history
+	var setHistory = function( value, locationPart){
+	  $log(&quot;adding value to history: &quot; +value);
+		$currentHistoryIndex++;
+		$history.push({
+			location: locationPart||&quot;href&quot;,
+			value: value
+		});
+	};
+	/*
+*	navigator.js
+*   - requires env
+*/
+$log(&quot;Initializing Window Navigator.&quot;);
+
+var $appCodeName  = &quot;EnvJS&quot;;//eg &quot;Mozilla&quot;
+var $appName      = &quot;Resig/20070309 BirdDog/0.0.0.1&quot;;//eg &quot;Gecko/20070309 Firefox/2.0.0.3&quot;
+
+// Browser Navigator
+$w.__defineGetter__(&quot;navigator&quot;, function(){	
+	return {
+		get appCodeName(){
+			return $appCodeName;
+		},
+		get appName(){
+			return $appName;
+		},
+		get appVersion(){
+			return $version +&quot; (&quot;+ 
+			    $w.navigator.platform +&quot;; &quot;+
+			    &quot;U; &quot;+//?
+			    $env.os_name+&quot; &quot;+$env.os_arch+&quot; &quot;+$env.os_version+&quot;; &quot;+
+			    $env.lang+&quot;; &quot;+
+			    &quot;rv:&quot;+$revision+
+			  &quot;)&quot;;
+		},
+		get cookieEnabled(){
+			return true;
+		},
+		get mimeTypes(){
+			return [];
+		},
+		get platform(){
+			return $env.platform;
+		},
+		get plugins(){
+			return [];
+		},
+		get userAgent(){
+			return $w.navigator.appCodeName + &quot;/&quot; + $w.navigator.appVersion + &quot; &quot; + $w.navigator.appName;
+		},
+		javaEnabled : function(){
+			return $env.javaEnabled;	
+		}
+	};
+});
+
+/*
+*	timer.js
+*/
+	
+
+$log(&quot;Initializing Window Timer.&quot;);
+
+//private
+var $timers = [];
+
+$w.setTimeout = function(fn, time){
+	var num;
+	return num = window.setInterval(function(){
+		fn();
+		window.clearInterval(num);
+	}, time);
+};
+
+window.setInterval = function(fn, time){
+	var num = $timers.length;
+	if(time===0){
+	    fn();
+	}else{
+    	$timers[num] = $env.timer(fn, time);
+    	$timers[num].start();
+	}
+	return num;
+};
+
+window.clearInterval = window.clearTimeout = function(num){
+	if ( $timers[num] ) {
+		$timers[num].stop();
+		delete $timers[num];
+	}
+};	
+	/*
+* event.js
+*/
+// Window Events
+$log(&quot;Initializing Window Event.&quot;);
+var $events = [{}],
+    $onerror,
+    $onload,
+    $onunload;
+
+$w.addEventListener = function(type, fn){
+  $log(&quot;adding event listener &quot; + type);
+	if ( !this.uuid || this == window ) {
+		this.uuid = $events.length;
+		$events[this.uuid] = {};
+	}
+	if ( !$events[this.uuid][type] ){
+		$events[this.uuid][type] = [];
+	}
+	if ( $events[this.uuid][type].indexOf( fn ) &lt; 0 ){
+		$events[this.uuid][type].push( fn );
+	}
+};
+
+$w.removeEventListener = function(type, fn){
+  if ( !this.uuid || this == window ) {
+    this.uuid = $events.length;
+    $events[this.uuid] = {};
+  }
+  if ( !$events[this.uuid][type] ){
+		$events[this.uuid][type] = [];
+	}	
+  $events[this.uuid][type] =
+    $events[this.uuid][type].filter(function(f){
+			return f != fn;
+		});
+};
+$w.dispatchEvent = function(event){
+  if(!event.target)
+    event.target = this;
+  if ( event.type ) {
+    if ( this.uuid &amp;&amp; events[this.uuid][event.type] ) {
+      var self = this;
+      events[this.uuid][event.type].forEach(function(fn){
+        fn.call( self, event );
+    });
+  }
+    
+  if ( this[&quot;on&quot; + event.type] )
+    this[&quot;on&quot; + event.type].call( self, event );
+  }
+  if(this.parentNode){
+    this.parentNode.dispatchEvent.call(this.parentNode,event);
+  }
+};
+$w.dispatchEvent = function(event){
+    $log(&quot;dispatching event &quot; + event.type);
+    //the window scope defines the $event object, for IE(^^^) compatibility;
+    $event = event;
+    if(!event.target)
+        event.target = this;
+    if ( event.type ) {
+        if ( this.uuid &amp;&amp; events[this.uuid][event.type] ) {
+            var _this = this;
+            events[this.uuid][event.type].forEach(function(fn){
+                fn.call( _this, event );
+            });
+        }
+    
+        if ( this[&quot;on&quot; + event.type] )
+            this[&quot;on&quot; + event.type].call( _this, event );
+    }
+    if(this.parentNode){
+        this.parentNode.dispatchEvent.call(this.parentNode,event);
+    }
+};
+	
+$w.__defineGetter__('onerror', function(){
+  return function(){
+   //$w.dispatchEvent('error');
+  };
+});
+
+$w.__defineSetter__('onerror', function(fn){
+  //$w.addEventListener('error', fn);
+});
+
+/*$w.__defineGetter__('onload', function(){
+  return function(){
+		//var event = document.createEvent();
+		//event.initEvent(&quot;load&quot;);
+   //$w.dispatchEvent(event);
+  };
+});
+
+$w.__defineSetter__('onload', function(fn){
+  //$w.addEventListener('load', fn);
+});
+
+$w.__defineGetter__('onunload', function(){
+  return function(){
+   //$w.dispatchEvent('unload');
+  };
+});
+
+$w.__defineSetter__('onunload', function(fn){
+  //$w.addEventListener('unload', fn);
+});*//*
+*	xhr.js
+*/
+$log(&quot;Initializing Window XMLHttpRequest.&quot;);
+// XMLHttpRequest
+// Originally implemented by Yehuda Katz
+$w.XMLHttpRequest = function(){
+	this.headers = {};
+	this.responseHeaders = {};
+};
+
+XMLHttpRequest.prototype = {
+	open: function(method, url, async, user, password){ 
+		this.readyState = 1;
+		if (async === false ){
+			this.async = false;
+		}else{ this.async = true; }
+		this.method = method || &quot;GET&quot;;
+		this.url = $env.location(url);
+		this.onreadystatechange();
+	},
+	setRequestHeader: function(header, value){
+		this.headers[header] = value;
+	},
+	getResponseHeader: function(header){ },
+	send: function(data){
+		var self = this;
+		
+		function makeRequest(){
+			$env.connection(self, function(){
+			  var responseXML = null;
+				self.__defineGetter__(&quot;responseXML&quot;, function(){
+  				if ( self.responseText.match(/^\s*&lt;/) ) {
+  				  if(responseXML){return responseXML;}
+  				  else{
+    					try {
+    					  $log(&quot;parsing response text into xml document&quot;);
+    						responseXML = $domparser.parseFromString(self.responseText);
+  					    return responseXML;
+    					} catch(e) { return null;/*TODO: need to flag an error here*/}
+  					}
+  				}else{return null;}
+  			});
+			});
+			self.onreadystatechange();
+		}
+		if (this.async){
+		  $log(&quot;XHR sending asynch;&quot;);
+			$env.runAsync(makeRequest);
+		}else{
+		  $log(&quot;XHR sending synch;&quot;);
+			makeRequest();
+		}
+	},
+	abort: function(){
+		//TODO
+	},
+	onreadystatechange: function(){
+		//TODO
+	},
+	getResponseHeader: function(header){
+	  var rHeader, returnedHeaders;
+		if (this.readyState &lt; 3){
+			throw new Error(&quot;INVALID_STATE_ERR&quot;);
+		} else {
+			returnedHeaders = [];
+			for (rHeader in this.responseHeaders) {
+				if (rHeader.match(new RegExp(header, &quot;i&quot;)))
+					returnedHeaders.push(this.responseHeaders[rHeader]);
+			}
+			if (returnedHeaders.length){ return returnedHeaders.join(&quot;, &quot;); }
+		}return null;
+	},
+	getAllResponseHeaders: function(){
+	  var header, returnedHeaders = [];
+		if (this.readyState &lt; 3){
+			throw new Error(&quot;INVALID_STATE_ERR&quot;);
+		} else {
+			for (header in this.responseHeaders){
+				returnedHeaders.push( header + &quot;: &quot; + this.responseHeaders[header] );
+			}
+		}return returnedHeaders.join(&quot;\r\n&quot;);
+	},
+	async: true,
+	readyState: 0,
+	responseText: &quot;&quot;,
+	status: 0
+};/*
+*	css.js
+*/
+$log(&quot;Initializing Window CSS&quot;);
+// returns a CSS2Properties object that represents the style
+// attributes and values used to render the specified element in this
+// window.  Any length values are always expressed in pixel, or
+// absolute values.
+$w.getComputedStyle = function(elt, pseudo_elt){
+  //TODO
+  //this is a naive implementation
+  $log(&quot;Getting computed style&quot;);
+  return elt?elt.style:new CSS2Properties({cssText:&quot;&quot;});
+};/*
+*	screen.js
+*/
+$log(&quot;Initializing Window Screen.&quot;);
+
+var $availHeight  = 600,
+    $availWidth   = 800,
+    $colorDepth    = 16,
+    $height       = 600,
+    $width        = 800;
+    
+$w.__defineGetter__(&quot;screen&quot;, function(){
+  return {
+    get availHeight(){return $availHeight;},
+    get availWidth(){return $availWidth;},
+    get colorDepth(){return $colorDepth;},
+    get height(){return $height;},
+    get width(){return $width;}
+  };
+});
+
+
+$w.moveBy = function(dx,dy){
+  //TODO
+};
+
+$w.moveTo = function(x,y) {
+  //TODO
+};
+
+/*$w.print = function(){
+  //TODO
+};*/
+
+$w.resizeBy = function(dw, dh){
+  $w.resizeTo($width+dw,$height+dh);
+};
+
+$w.resizeTo = function(width, height){
+  $width = (width &lt;= $availWidth) ? width : $availWidth;
+  $height = (height &lt;= $availHeight) ? height : $availHeight;
+};
+
+$w.scrollBy = function(dx, dy){
+  //TODO
+};
+$w.scrollTo = function(x,y){
+  //TODO
+};/*
+*	dialog.js
+*/
+$log(&quot;Initializing Window Dialogs.&quot;);
+$w.alert = function(message){
+ //TODO 
+};
+
+$w.confirm = function(question){
+  //TODO
+};
+
+$w.prompt = function(message, defaultMsg){
+  //TODO
+};/*
+*	document.js
+*
+*	DOM Level 2 /DOM level 3 (partial)
+*	
+*	This file adds the document object to the window and allows you
+*	you to set the window.document using an html string or dom object.
+*
+*/
+
+// read only reference to the Document object
+
+$log(&quot;Initializing window.document.&quot;);
+var $async = false;
+__extend__(HTMLDocument.prototype, {
+	get async(){ return $async;},
+	set async(async){ $async = async; },
+	get baseURI(){ return $env.location('./'); },
+	get URL(){ return $w.location.href;  }
+});
+	
+
+var $document =  new HTMLDocument($implementation);
+$w.__defineGetter__(&quot;document&quot;, function(){
+	return $document;
+});
+/*
+*	outro.js
+*/
+
+})(window, __env__); 
+
+}catch(e){
+    __env__.error(&quot;ERROR LOADING ENV : &quot; + e + &quot;\nLINE SOURCE:\n&quot; +e.rhinoException.lineSource());
+}</diff>
      <filename>dist/env.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,7327 +1,7353 @@
-/*
-*	env.rhino.js
-*/
-var __env__ = {};
-(function($env){
-	
-  $env.debug = function(){};
-  
-  $env.log = function(){};
-  //uncomment this if you want to get some internal log statementes
-  $env.log = print;
-  $env.log(&quot;Initializing Rhino Platform Env&quot;);
-  
-  $env.error = function(msg, e){
-    print(&quot;ERROR! : &quot; + msg);
-    print(e);
-  };
-  
-  $env.hashCode = function(obj){
-    return obj?obj.hashCode().toString():null;
-  };
-	//For Java the window.location object is a java.net.URL
-	$env.location = function(path, base){
-	  var protocol = new RegExp('(^\\w*\:)');
-		var m = protocol.exec(path);
-		if(m&amp;&amp;m.length&gt;1){
-			return new java.net.URL(path).toString();
-		}else if(base){
-		  return new java.net.URL(base + '/' + path).toString();
-		}else{
-			//return an absolute url from a relative to the file system
-			return new java.io.File(path).toURL().toString();
-		}
-	};
-	
-	//For Java the window.timer is created using the java.lang.Thread in combination
-	//with the java.lang.Runnable
-	$env.timer = function(fn, time){
-		return new java.lang.Thread(new java.lang.Runnable({
-			run: function(){
-				while (true){
-					java.lang.Thread.currentThread().sleep(time);
-					fn();
-				}
-			}
-		}));
-	};	
-	
-	//Since we're running in rhino I guess we can safely assume
-	//java is 'enabled'.  I'm sure this requires more thought
-	//than I've given it here
-	$env.javaEnabled = true;	
-	
-	
-	//Used in the XMLHttpRquest implementation to run a
-	// request in a seperate thread
-	$env.runAsync = function(fn){
-		(new java.lang.Thread(new java.lang.Runnable({
-			run: fn
-		}))).start();
-	};
-	
-	//Used to write to a local file
-	$env.writeToFile = function(text, url){
-		var out = new java.io.FileWriter( 
-			new java.io.File( 
-				new java.net.URI(url.toString())));				
-		out.write( text, 0, text.length );
-		out.flush();
-		out.close();
-	};
-	
-	//Used to delete a local file
-	$env.deleteFile = function(url){
-		var file = new java.io.File( new java.net.URI( url ) );
-        file[&quot;delete&quot;]();
-	};
-	
-	$env.connection = function(xhr, responseHandler){
-		var url = java.net.URL(xhr.url);//, $w.location);
-	  var connection;
-		if ( /^file\:/.test(url) ) {
-			if ( xhr.method == &quot;PUT&quot; ) {
-				var text =  data || &quot;&quot; ;
-				$env.writeToFile(text, url);
-			} else if ( xhr.method == &quot;DELETE&quot; ) {
-				$env.deleteFile(url);
-			} else {
-				connection = url.openConnection();
-				connection.connect();
-			}
-		} else { 
-			connection = url.openConnection();
-			connection.setRequestMethod( xhr.method );
-			
-			// Add headers to Java connection
-			for (var header in xhr.headers){
-				connection.addRequestProperty(header, xhr.headers[header]);
-		  }connection.connect();
-			
-			// Stick the response headers into responseHeaders
-			for (var i = 0; ; i++) { 
-				var headerName = connection.getHeaderFieldKey(i); 
-				var headerValue = connection.getHeaderField(i); 
-				if (!headerName &amp;&amp; !headerValue) break; 
-				if (headerName)
-					xhr.responseHeaders[headerName] = headerValue;
-			}
-		}
-		if(connection){
-				xhr.readyState = 4;
-				xhr.status = parseInt(connection.responseCode,10) || undefined;
-				xhr.statusText = connection.responseMessage || &quot;&quot;;
-				
-				var contentEncoding = connection.getContentEncoding() || &quot;utf-8&quot;,
-					stream = (contentEncoding.equalsIgnoreCase(&quot;gzip&quot;) || contentEncoding.equalsIgnoreCase(&quot;decompress&quot;) )?
-   							new java.util.zip.GZIPInputStream(connection.getInputStream()) :
-   							connection.getInputStream(),
-					baos = new java.io.ByteArrayOutputStream(),
-   				buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024),
-					length,
-					responseXML = null;
-
-				while ((length = stream.read(buffer)) != -1) {
-					baos.write(buffer, 0, length);
-				}
-
-				baos.close();
-				stream.close();
-
-				xhr.responseText = java.nio.charset.Charset.forName(contentEncoding).
-					decode(java.nio.ByteBuffer.wrap(baos.toByteArray())).toString();
-				
-		}
-		if(responseHandler){
-		  responseHandler();
-		}
-	};
-	
-	var htmlDocBuilder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
-	htmlDocBuilder.setNamespaceAware(false);
-	htmlDocBuilder.setValidating(false);
-	
-	$env.parseHTML = function(htmlstring){
-		return htmlDocBuilder.newDocumentBuilder().parse(
-				  new java.io.ByteArrayInputStream(
-						(new java.lang.String(htmlstring)).getBytes(&quot;UTF8&quot;)));
-	};
-	
-	var xmlDocBuilder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
-	xmlDocBuilder.setNamespaceAware(true);
-	xmlDocBuilder.setValidating(true);
-	
-	$env.parseXML = function(xmlstring){
-		return xmlDocBuilder.newDocumentBuilder().parse(
-				  new java.io.ByteArrayInputStream(
-						(new java.lang.String(xmlstring)).getBytes(&quot;UTF8&quot;)));
-	};
-	
-	
-  $env.xpath = function(expression, doc){
-    return Packages.javax.xml.xpath.
-      XPathFactory.newInstance().newXPath().
-        evaluate(expression, doc, javax.xml.xpath.XPathConstants.NODESET);
-  };
-	
-  $env.os_name        = java.lang.System.getProperty(&quot;os.name&quot;); 
-  $env.os_arch        = java.lang.System.getProperty(&quot;os.arch&quot;); 
-  $env.os_version     = java.lang.System.getProperty(&quot;os.version&quot;); 
-  $env.lang           = java.lang.System.getProperty(&quot;user.lang&quot;); 
-  $env.platform       = &quot;Rhino &quot;;//how do we get the version
-	
-})(__env__);/*
- * Pure JavaScript Browser Environment
- *   By John Resig &lt;http://ejohn.org/&gt;
- * Copyright 2008 John Resig, under the MIT License
- */
- 
-
-// The Window Object
-var __this__ = this;
-this.__defineGetter__('window', function(){
-  return __this__;
-});
-try{
-(function($w, $env){
-        /*
-*	window.js
-*   - this file will be wrapped in a closure providing the window object as $w
-*/
-// a logger or empty function available to all modules.
-var $log = $env.log,
-    $error = $env.error,
-    $debug = $env.debug;
-//The version of this application
-var $version = &quot;0.1&quot;;
-//This should be hooked to git or svn or whatever
-var $revision = &quot;0.0.0.0&quot;;
-
-//These descriptions of window properties are taken loosely David Flanagan's
-//'JavaScript - The Definitive Guide' (O'Reilly)
-
-/**&gt; $cookies - see cookie.js &lt;*/
-// read only boolean specifies whether the window has been closed
-var $closed = false;
-
-// a read/write string that specifies the default message that appears in the status line 
-var $defaultStatus = &quot;Done&quot;;
-
-// a read-only reference to the Document object belonging to this window
-/**&gt; $document - See document.js &lt;*/
-
-//IE only, refers to the most recent event object - this maybe be removed after review
-var $event = null;
-
-//A read-only array of window objects
-var $frames = [];
-
-// a read-only reference to the History object
-/**&gt;  $history - see location.js &lt;**/
-
-// read-only properties that specify the height and width, in pixels
-var $innerHeight = 600, $innerWidth = 800;
-
-// a read-only reference to the Location object.  the location object does expose read/write properties
-/**&gt; $location - see location.js &lt;**/
-
-// a read only property specifying the name of the window.  Can be set when using open()
-// and may be used when specifying the target attribute of links
-var $name = 'Resig Env Browser';
-
-// a read-only reference to the Navigator object
-/**&gt; $navigator - see navigator.js &lt;**/
-
-// a read/write reference to the Window object that contained the script that called open() to 
-//open this browser window.  This property is valid only for top-level window objects.
-var $opener;
-
-// Read-only properties that specify the total height and width, in pixels, of the browser window.
-// These dimensions include the height and width of the menu bar, toolbars, scrollbars, window
-// borders and so on.  These properties are not supported by IE and IE offers no alternative 
-// properties;
-var $outerHeight = $innerHeight, $outerWidth = $innerWidth;
-
-// Read-only properties that specify the number of pixels that the current document has been scrolled
-//to the right and down.  These are not supported by IE.
-var $pageXOffset = 0, $pageYOffest = 0;
-
-//A read-only reference to the Window object that contains this window or frame.  If the window is
-// a top-level window, parent refers to the window itself.  If this window is a frame, this property
-// refers to the window or frame that conatins it.
-var $parent;
-
-// a read-only refernce to the Screen object that specifies information about the screen: 
-// the number of available pixels and the number of available colors.
-/**&gt; $screen - see screen.js &lt;**/
-
-// read only properties that specify the coordinates of the upper-left corner of the screen.
-var $screenX = 0, $screenY = 0;
-var $screenLeft = $screenX, $screenTop = $screenY;
-
-// a read-only refernce to this window itself.
-var $self;
-
-// a read/write string that specifies the current contents of the status line.
-var $status = '';
-
-// a read-only reference to the top-level window that contains this window.  If this
-// window is a top-level window it is simply a refernce to itself.  If this window 
-// is a frame, the top property refers to the top-level window that contains the frame.
-var $top;
-
-// the window property is identical to the self property.
-var $window = $w;
-
-$log(&quot;Initializing Window.&quot;);
-__extend__($w,{
-  get closed(){return $closed;},
-  get defaultStatus(){return $defaultStatus;},
-  set defaultStatus(_defaultStatus){$defaultStatus = _defaultStatus;},
-  //get document(){return $document;}, - see document.js
-  get event(){return $event;},
-  get frames(){return $frames;},
-  //get history(){return $history;}, - see location.js
-  get innerHeight(){return $innerHeight;},
-  get innerWidth(){return $innerWidth;},
-  get clientHeight(){return $innerHeight;},
-  get clientWidth(){return $innerWidth;},
-  //get location(){return $location;}, see location.js
-  get name(){return $name;},
-  //get navigator(){return $navigator;}, see navigator.js
-  get opener(){return $opener;},
-  get outerHeight(){return $outerHeight;},
-  get outerWidth(){return $outerWidth;},
-  get pageXOffest(){return $pageXOffset;},
-  get pageYOffset(){return $pageYOffset;},
-  get parent(){return $parent;},
-  //get screen(){return $screen;}, see screen.js
-  get screenLeft(){return $screenLeft;},
-  get screenTop(){return $screenTop;},
-  get screenX(){return $screenX;},
-  get screenY(){return $screenY;},
-  get self(){return $self;},
-  get status(){return $status;},
-  set status(_status){$status = _status;},
-  get top(){return $top;},
-  get window(){return $window;}
-});
-
-$w.open = function(url, name, features, replace){
-  //TODO
-};
-
-$w.close = function(){
-  //TODO
-};     
-  
-/* Time related functions - see timer.js
-*   - clearTimeout
-*   - clearInterval
-*   - setTimeout
-*   - setInterval
-*/
-
-/*
-* Events related functions - see event.js
-*   - addEventListener
-*   - attachEvent
-*   - detachEvent
-*   - removeEventListener
-*   
-* These functions are identical to the Element equivalents.
-*/
-
-/*
-* UIEvents related functions - see uievent.js
-*   - blur
-*   - focus
-*
-* These functions are identical to the Element equivalents.
-*/
-
-/* Dialog related functions - see dialog.js
-*   - alert
-*   - confirm
-*   - prompt
-*/
-
-/* Screen related functions - see screen.js
-*   - moveBy
-*   - moveTo
-*   - print
-*   - resizeBy
-*   - resizeTo
-*   - scrollBy
-*   - scrollTo
-*/
-
-/* CSS related functions - see css.js
-*   - getComputedStyle
-*/
-
-/*
-* Shared utility methods
-*/
-// Helper method for extending one object with another.  
-function __extend__(a,b) {
-	for ( var i in b ) {
-		var g = b.__lookupGetter__(i), s = b.__lookupSetter__(i);
-		if ( g || s ) {
-			if ( g ) a.__defineGetter__(i, g);
-			if ( s ) a.__defineSetter__(i, s);
-		} else
-			a[i] = b[i];
-	} return a;
-};
-	
-
-// from ariel flesler http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html
-// this might be a good utility function to provide in the env.core
-// as in might be useful to the parser and other areas as well
-function trim( str ){
-    var start = -1,
-    end = str.length;
-    /*jsl:ignore*/
-    while( str.charCodeAt(--end) &lt; 33 );
-    while( str.charCodeAt(++start) &lt; 33 );
-    /*jsl:end*/
-    return str.slice( start, end + 1 );
-};
-
-//from jQuery
-function __setArray__( target, array ) {
-	// Resetting the length to 0, then using the native Array push
-	// is a super-fast way to populate an object with array-like properties
-	target.length = 0;
-	Array.prototype.push.apply( target, array );
-};
-$log(&quot;Defining NodeList&quot;);
-/*
-* NodeList - DOM Level 2
-*/
-$w.__defineGetter__('NodeList', function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-/**
- * @class  DOMNodeList - provides the abstraction of an ordered collection of nodes
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- *
- * @param  ownerDocument : DOMDocument - the ownerDocument
- * @param  parentNode    : DOMNode - the node that the DOMNodeList is attached to (or null)
- */
-var DOMNodeList = function(ownerDocument, parentNode) {
-    //$log(&quot;\t\tcreating dom nodelist&quot;);
-    var nodes = new Array();
-    
-    this.length = 0;
-    this.parentNode = parentNode;
-    this.ownerDocument = ownerDocument;
-    
-    this._readonly = false;
-    
-    __setArray__(this, nodes);
-    //$log(&quot;\t\tfinished creating dom nodelist&quot;);
-};
-__extend__(DOMNodeList.prototype, {
-    item : function(index) {
-        var ret = null;
-        //$log(&quot;NodeList item(&quot;+index+&quot;) = &quot; + this[index]);
-        if ((index &gt;= 0) &amp;&amp; (index &lt; this.length)) { // bounds check
-            ret = this[index];                    // return selected Node
-        }
-        
-        return ret;                                    // if the index is out of bounds, default value null is returned
-    },
-    get xml() {
-        var ret = &quot;&quot;;
-        
-        // create string containing the concatenation of the string values of each child
-        for (var i=0; i &lt; this.length; i++) {
-            if(this[i].nodeType == DOMNode.TEXT_NODE &amp;&amp; i&gt;0 &amp;&amp; this[i-1].nodeType == DOMNode.TEXT_NODE){
-                //add a single space between adjacent text nodes
-                ret += &quot; &quot;+this[i].xml;
-            }else{
-                ret += this[i].xml;
-            }
-        }
-        
-        return ret;
-    },
-    toString: function(){
-      return &quot;[ &quot;+(this.length &gt; 0?Array.prototype.join.apply(this, [&quot;, &quot;]):&quot;Empty NodeList&quot;)+&quot; ]&quot;;
-    }
-});
-
-
-/**
- * @method DOMNodeList._findItemIndex - find the item index of the node with the specified internal id
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  id : int - unique internal id
- * @return : int
- */
-var __findItemIndex__ = function (nodelist, id) {
-  var ret = -1;
-
-  // test that id is valid
-  if (id &gt; -1) {
-    for (var i=0; i&lt;nodelist.length; i++) {
-      // compare id to each node's _id
-      if (nodelist[i]._id == id) {            // found it!
-        ret = i;
-        break;
-      }
-    }
-  }
-
-  return ret;                                    // if node is not found, default value -1 is returned
-};
-
-/**
- * @method DOMNodeList._insertBefore - insert the specified Node into the NodeList before the specified index
- *   Used by DOMNode.insertBefore(). Note: DOMNode.insertBefore() is responsible for Node Pointer surgery
- *   DOMNodeList._insertBefore() simply modifies the internal data structure (Array).
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  newChild      : DOMNode - the Node to be inserted
- * @param  refChildIndex : int     - the array index to insert the Node before
- */
-var __insertBefore__ = function(nodelist, newChild, refChildIndex) {
-    if ((refChildIndex &gt;= 0) &amp;&amp; (refChildIndex &lt; nodelist.length)) { // bounds check
-        
-        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
-            // append the children of DocumentFragment
-            Array.prototype.splice.apply(nodelist,[refChildIndex, 0].concat(newChild.childNodes));
-        }
-        else {
-            // append the newChild
-            Array.prototype.splice.apply(nodelist,[refChildIndex, 0, newChild]);
-        }
-    }
-    //$log(&quot;__insertBefore__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
-};
-
-/**
- * @method DOMNodeList._replaceChild - replace the specified Node in the NodeList at the specified index
- *   Used by DOMNode.replaceChild(). Note: DOMNode.replaceChild() is responsible for Node Pointer surgery
- *   DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  newChild      : DOMNode - the Node to be inserted
- * @param  refChildIndex : int     - the array index to hold the Node
- */
-var __replaceChild__ = function(nodelist, newChild, refChildIndex) {
-    var ret = null;
-    
-    if ((refChildIndex &gt;= 0) &amp;&amp; (refChildIndex &lt; nodelist.length)) { // bounds check
-        ret = nodelist[refChildIndex];            // preserve old child for return
-    
-        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
-            // get array containing children prior to refChild
-            Array.prototype.splice.apply(nodelist,[refChildIndex, 1].concat(newChild.childNodes));
-        }
-        else {
-            // simply replace node in array (links between Nodes are made at higher level)
-            nodelist[refChildIndex] = newChild;
-        }
-    }
-    
-    //$log(&quot;__replaceChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
-    return ret;                                   // return replaced node
-};
-
-/**
- * @method DOMNodeList._removeChild - remove the specified Node in the NodeList at the specified index
- *   Used by DOMNode.removeChild(). Note: DOMNode.removeChild() is responsible for Node Pointer surgery
- *   DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  refChildIndex : int - the array index holding the Node to be removed
- */
-var __removeChild__ = function(nodelist, refChildIndex) {
-    var ret = null;
-    
-    if (refChildIndex &gt; -1) {                              // found it!
-        ret = nodelist[refChildIndex];                    // return removed node
-        
-        // rebuild array without removed child
-        Array.prototype.splice.apply(nodelist,[refChildIndex, 1]);
-    }
-    
-    //$log(&quot;__removeChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
-    return ret;                                   // return removed node
-};
-
-/**
- * @method DOMNodeList._appendChild - append the specified Node to the NodeList
- *   Used by DOMNode.appendChild(). Note: DOMNode.appendChild() is responsible for Node Pointer surgery
- *   DOMNodeList._appendChild() simply modifies the internal data structure (Array).
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  newChild      : DOMNode - the Node to be inserted
- */
-var __appendChild__ = function(nodelist, newChild) {
-    if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
-        // append the children of DocumentFragment
-        Array.prototype.push.apply(nodelist, newChild.childNodes);
-    } else {
-        // simply add node to array (links between Nodes are made at higher level)
-        Array.prototype.push.apply(nodelist, [newChild]);
-    }
-    
-    //$log(&quot;__appendChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
-};
-
-/**
- * @method DOMNodeList._cloneNodes - Returns a NodeList containing clones of the Nodes in this NodeList
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  deep : boolean - If true, recursively clone the subtree under each of the nodes;
- *   if false, clone only the nodes themselves (and their attributes, if it is an Element).
- * @param  parentNode : DOMNode - the new parent of the cloned NodeList
- * @return : DOMNodeList - NodeList containing clones of the Nodes in this NodeList
- */
-var __cloneNodes__ = function(nodelist, deep, parentNode) {
-    var cloneNodeList = new DOMNodeList(nodelist.ownerDocument, parentNode);
-    
-    // create list containing clones of each child
-    for (var i=0; i &lt; nodelist.length; i++) {
-        __appendChild__(cloneNodeList, nodelist[i].cloneNode(deep));
-    }
-    
-    return cloneNodeList;
-};
-
-
-/**
- * @class  DOMNamedNodeMap - used to represent collections of nodes that can be accessed by name
- *  typically a set of Element attributes
- *
- * @extends DOMNodeList - note W3C spec says that this is not the case,
- *   but we need an item() method identicle to DOMNodeList's, so why not?
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - the ownerDocument
- * @param  parentNode    : DOMNode - the node that the DOMNamedNodeMap is attached to (or null)
- */
-var DOMNamedNodeMap = function(ownerDocument, parentNode) {
-    //$log(&quot;\t\tcreating dom namednodemap&quot;);
-    this.DOMNodeList = DOMNodeList;
-    this.DOMNodeList(ownerDocument, parentNode);
-    __setArray__(this, []);
-};
-DOMNamedNodeMap.prototype = new DOMNodeList;
-__extend__(DOMNamedNodeMap.prototype, {
-    getNamedItem : function(name) {
-        var ret = null;
-        
-        // test that Named Node exists
-        var itemIndex = __findNamedItemIndex__(this, name);
-        
-        if (itemIndex &gt; -1) {                          // found it!
-            ret = this[itemIndex];                // return NamedNode
-        }
-        
-        return ret;                                    // if node is not found, default value null is returned
-    },
-    setNamedItem : function(arg) {
-      // test for exceptions
-      if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if arg was not created by this Document
-            if (this.ownerDocument != arg.ownerDocument) {
-              throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-            }
-        
-            // throw Exception if DOMNamedNodeMap is readonly
-            if (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly)) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-        
-            // throw Exception if arg is already an attribute of another Element object
-            if (arg.ownerElement &amp;&amp; (arg.ownerElement != this.parentNode)) {
-              throw(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR));
-            }
-      }
-    
-      // get item index
-      var itemIndex = __findNamedItemIndex__(this, arg.name);
-      var ret = null;
-    
-      if (itemIndex &gt; -1) {                          // found it!
-            ret = this[itemIndex];                // use existing Attribute
-        
-            // throw Exception if DOMAttr is readonly
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ret._readonly) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            } else {
-              this[itemIndex] = arg;                // over-write existing NamedNode
-            }
-      } else {
-            // add new NamedNode
-            Array.prototype.push.apply(this, [arg]);
-      }
-    
-      arg.ownerElement = this.parentNode;            // update ownerElement
-    
-      return ret;                                    // return old node or null
-    },
-    removeNamedItem : function(name) {
-          var ret = null;
-          // test for exceptions
-          // throw Exception if DOMNamedNodeMap is readonly
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly))) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-          }
-        
-          // get item index
-          var itemIndex = __findNamedItemIndex__(this, name);
-        
-          // throw Exception if there is no node named name in this map
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-            throw(new DOMException(DOMException.NOT_FOUND_ERR));
-          }
-        
-          // get Node
-          var oldNode = this[itemIndex];
-        
-          // throw Exception if Node is readonly
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldNode._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-          }
-        
-          // return removed node
-          return __removeChild__(this, itemIndex);
-    },
-    getNamedItemNS : function(namespaceURI, localName) {
-          var ret = null;
-        
-          // test that Named Node exists
-          var itemIndex = __findNamedItemNSIndex__(this, namespaceURI, localName);
-        
-          if (itemIndex &gt; -1) {                          // found it!
-            ret = this[itemIndex];                // return NamedNode
-          }
-        
-          return ret;                                    // if node is not found, default value null is returned
-    },
-    setNamedItemNS : function(arg) {
-          // test for exceptions
-          if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if DOMNamedNodeMap is readonly
-            if (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly)) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-        
-            // throw Exception if arg was not created by this Document
-            if (this.ownerDocument != arg.ownerDocument) {
-              throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-            }
-        
-            // throw Exception if arg is already an attribute of another Element object
-            if (arg.ownerElement &amp;&amp; (arg.ownerElement != this.parentNode)) {
-              throw(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR));
-            }
-          }
-        
-          // get item index
-          var itemIndex = __findNamedItemNSIndex__(this, arg.namespaceURI, arg.localName);
-          var ret = null;
-        
-          if (itemIndex &gt; -1) {                          // found it!
-            ret = this[itemIndex];                // use existing Attribute
-            // throw Exception if DOMAttr is readonly
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ret._readonly) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            } else {
-              this[itemIndex] = arg;                // over-write existing NamedNode
-            }
-          }else {
-            // add new NamedNode
-            Array.prototype.push.apply(this, [arg]);
-          }
-          arg.ownerElement = this.parentNode;
-        
-        
-          return ret;                                    // return old node or null
-    },
-    removeNamedItemNS : function(namespaceURI, localName) {
-          var ret = null;
-        
-          // test for exceptions
-          // throw Exception if DOMNamedNodeMap is readonly
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly))) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-          }
-        
-          // get item index
-          var itemIndex = __findNamedItemNSIndex__(this, namespaceURI, localName);
-        
-          // throw Exception if there is no matching node in this map
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-            throw(new DOMException(DOMException.NOT_FOUND_ERR));
-          }
-        
-          // get Node
-          var oldNode = this[itemIndex];
-        
-          // throw Exception if Node is readonly
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldNode._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-          }
-        
-          return __removeChild__(this, itemIndex);             // return removed node
-    },
-    get xml() {
-          var ret = &quot;&quot;;
-        
-          // create string containing concatenation of all (but last) Attribute string values (separated by spaces)
-          for (var i=0; i &lt; this.length -1; i++) {
-            ret += this[i].xml +&quot; &quot;;
-          }
-        
-          // add last Attribute to string (without trailing space)
-          if (this.length &gt; 0) {
-            ret += this[this.length -1].xml;
-          }
-        
-          return ret;
-    }
-
-});
-
-/**
- * @method DOMNamedNodeMap._findNamedItemIndex - find the item index of the node with the specified name
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  name : string - the name of the required node
- * @param  isnsmap : if its a DOMNamespaceNodeMap
- * @return : int
- */
-var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) {
-  var ret = -1;
-
-  // loop through all nodes
-  for (var i=0; i&lt;namednodemap.length; i++) {
-    // compare name to each node's nodeName
-    if(isnsmap){
-        if (namednodemap[i].localName == localName) {         // found it!
-          ret = i;
-          break;
-        }
-    }else{
-        if (namednodemap[i].name == name) {         // found it!
-          ret = i;
-          break;
-        }
-    }
-  }
-
-  return ret;                                    // if node is not found, default value -1 is returned
-};
-
-/**
- * @method DOMNamedNodeMap._findNamedItemNSIndex - find the item index of the node with the specified namespaceURI and localName
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  namespaceURI : string - the namespace URI of the required node
- * @param  localName    : string - the local name of the required node
- * @return : int
- */
-var __findNamedItemNSIndex__ = function(namednodemap, namespaceURI, localName) {
-  var ret = -1;
-
-  // test that localName is not null
-  if (localName) {
-    // loop through all nodes
-    for (var i=0; i&lt;namednodemap.length; i++) {
-      // compare name to each node's namespaceURI and localName
-      if ((namednodemap[i].namespaceURI == namespaceURI) &amp;&amp; (namednodemap[i].localName == localName)) {
-        ret = i;                                 // found it!
-        break;
-      }
-    }
-  }
-
-  return ret;                                    // if node is not found, default value -1 is returned
-};
-
-/**
- * @method DOMNamedNodeMap._hasAttribute - Returns true if specified node exists
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  name : string - the name of the required node
- * @return : boolean
- */
-var __hasAttribute__ = function(namednodemap, name) {
-  var ret = false;
-
-  // test that Named Node exists
-  var itemIndex = __findNamedItemIndex__(namednodemap, name);
-
-  if (itemIndex &gt; -1) {                          // found it!
-    ret = true;                                  // return true
-  }
-
-  return ret;                                    // if node is not found, default value false is returned
-}
-
-/**
- * @method DOMNamedNodeMap._hasAttributeNS - Returns true if specified node exists
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  namespaceURI : string - the namespace URI of the required node
- * @param  localName    : string - the local name of the required node
- * @return : boolean
- */
-var __hasAttributeNS__ = function(namednodemap, namespaceURI, localName) {
-  var ret = false;
-
-  // test that Named Node exists
-  var itemIndex = __findNamedItemNSIndex__(namednodemap, namespaceURI, localName);
-
-  if (itemIndex &gt; -1) {                          // found it!
-    ret = true;                                  // return true
-  }
-
-  return ret;                                    // if node is not found, default value false is returned
-}
-
-/**
- * @method DOMNamedNodeMap._cloneNodes - Returns a NamedNodeMap containing clones of the Nodes in this NamedNodeMap
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  parentNode : DOMNode - the new parent of the cloned NodeList
- * @param  isnsmap : bool - is this a DOMNamespaceNodeMap
- * @return : DOMNamedNodeMap - NamedNodeMap containing clones of the Nodes in this DOMNamedNodeMap
- */
-var __cloneNamedNodes__ = function(namednodemap, parentNode, isnsmap) {
-  var cloneNamedNodeMap = isnsmap?
-    new DOMNamespaceNodeMap(namednodemap.ownerDocument, parentNode):
-    new DOMNamedNodeMap(namednodemap.ownerDocument, parentNode);
-
-  // create list containing clones of all children
-  for (var i=0; i &lt; namednodemap.length; i++) {
-      $log(&quot;cloning node in named node map :&quot; + namednodemap[i]);
-    __appendChild__(cloneNamedNodeMap, namednodemap[i].cloneNode(false));
-  }
-
-  return cloneNamedNodeMap;
-};
-
-
-/**
- * @class  DOMNamespaceNodeMap - used to represent collections of namespace nodes that can be accessed by name
- *  typically a set of Element attributes
- *
- * @extends DOMNamedNodeMap
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- *
- * @param  ownerDocument : DOMDocument - the ownerDocument
- * @param  parentNode    : DOMNode - the node that the DOMNamespaceNodeMap is attached to (or null)
- */
-var DOMNamespaceNodeMap = function(ownerDocument, parentNode) {
-    //$log(&quot;\t\t\tcreating dom namespacednodemap&quot;);
-    this.DOMNamedNodeMap = DOMNamedNodeMap;
-    this.DOMNamedNodeMap(ownerDocument, parentNode);
-    __setArray__(this, []);
-};
-DOMNamespaceNodeMap.prototype = new DOMNamedNodeMap;
-__extend__(DOMNamespaceNodeMap.prototype, {
-    get xml() {
-          var ret = &quot;&quot;;
-        
-          // identify namespaces declared local to this Element (ie, not inherited)
-          for (var ind = 0; ind &lt; this.length; ind++) {
-            // if namespace declaration does not exist in the containing node's, parentNode's namespaces
-            var ns = null;
-            try {
-                var ns = this.parentNode.parentNode._namespaces.getNamedItem(this[ind].localName);
-            }
-            catch (e) {
-                //breaking to prevent default namespace being inserted into return value
-                break;
-            }
-            if (!(ns &amp;&amp; (&quot;&quot;+ ns.nodeValue == &quot;&quot;+ this[ind].nodeValue))) {
-              // display the namespace declaration
-              ret += this[ind].xml +&quot; &quot;;
-            }
-          }
-        
-          return ret;
-    }
-});
-$log(&quot;Defining Node&quot;);
-/*
-* Node - DOM Level 2
-*/	
-$w.__defineGetter__('Node', function(){
-  return __extend__(function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-      } , {
-  		ELEMENT_NODE    :1,
-  		ATTRIBUTE_NODE  :2,
-  		TEXT_NODE       :3,
-  		CDATA_SECTION_NODE: 4,
-  		PROCESSING_INSTRUCTION_NODE: 7,
-  		COMMENT_NODE: 8,
-  		DOCUMENT_NODE: 9,
-  		DOCUMENT_TYPE_NODE: 10,
-  		DOCUMENT_FRAGMENT_NODE: 11
-	});
-});
-
-/**
- * @class  DOMNode - The Node interface is the primary datatype for the entire Document Object Model.
- *   It represents a single node in the document tree.
- * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMNode = function(ownerDocument) {
-  //$log(&quot;\tcreating dom node&quot;);
-  if (ownerDocument) {
-    this._id = ownerDocument._genId();           // generate unique internal id
-  }
-
-  this.namespaceURI = &quot;&quot;;                        // The namespace URI of this node (Level 2)
-  this.prefix       = &quot;&quot;;                        // The namespace prefix of this node (Level 2)
-  this.localName    = &quot;&quot;;                        // The localName of this node (Level 2)
-
-  this.nodeName = &quot;&quot;;                            // The name of this node
-  this.nodeValue = &quot;&quot;;                           // The value of this node
-  this.nodeType = 0;                             // A code representing the type of the underlying object
-
-  // The parent of this node. All nodes, except Document, DocumentFragment, and Attr may have a parent.
-  // However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null
-  this.parentNode      = null;
-
-  // A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.
-  // The content of the returned NodeList is &quot;live&quot; in the sense that, for instance, changes to the children of the node object
-  // that it was created from are immediately reflected in the nodes returned by the NodeList accessors;
-  // it is not a static snapshot of the content of the node. This is true for every NodeList, including the ones returned by the getElementsByTagName method.
-  this.childNodes      = new DOMNodeList(ownerDocument, this);
-
-  this.firstChild      = null;                   // The first child of this node. If there is no such node, this is null
-  this.lastChild       = null;                   // The last child of this node. If there is no such node, this is null.
-  this.previousSibling = null;                   // The node immediately preceding this node. If there is no such node, this is null.
-  this.nextSibling     = null;                   // The node immediately following this node. If there is no such node, this is null.
-
-  this.attributes = new DOMNamedNodeMap(ownerDocument, this);   // A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
-  this.ownerDocument   = ownerDocument;          // The Document object associated with this node
-  this._namespaces = new DOMNamespaceNodeMap(ownerDocument, this);  // The namespaces in scope for this node
-
-  this._readonly = false;
-  //$log(&quot;\tfinished creating dom node&quot;);
-};
-
-// nodeType constants
-DOMNode.ELEMENT_NODE                = 1;
-DOMNode.ATTRIBUTE_NODE              = 2;
-DOMNode.TEXT_NODE                   = 3;
-DOMNode.CDATA_SECTION_NODE          = 4;
-DOMNode.ENTITY_REFERENCE_NODE       = 5;
-DOMNode.ENTITY_NODE                 = 6;
-DOMNode.PROCESSING_INSTRUCTION_NODE = 7;
-DOMNode.COMMENT_NODE                = 8;
-DOMNode.DOCUMENT_NODE               = 9;
-DOMNode.DOCUMENT_TYPE_NODE          = 10;
-DOMNode.DOCUMENT_FRAGMENT_NODE      = 11;
-DOMNode.NOTATION_NODE               = 12;
-DOMNode.NAMESPACE_NODE              = 13;
-
-__extend__(DOMNode.prototype, {
-    hasAttributes : function() {
-        if (this.attributes.length == 0) {
-            return false;
-        }else{
-            return true;
-        }
-    },
-    insertBefore : function(newChild, refChild) {
-        var prevNode;
-        
-        // test for exceptions
-        if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if DOMNode is readonly
-            if (this._readonly) {
-                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-            
-            // throw Exception if newChild was not created by this Document
-            if (this.ownerDocument != newChild.ownerDocument) {
-                throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-            }
-            
-            // throw Exception if the node is an ancestor
-            if (__isAncestor__(this, newChild)) {
-                throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
-            }
-        }
-        
-        if (refChild) {                                // if refChild is specified, insert before it
-            // find index of refChild
-            var itemIndex = __findItemIndex__(this.childNodes, refChild._id);
-            
-            // throw Exception if there is no child node with this id
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-              throw(new DOMException(DOMException.NOT_FOUND_ERR));
-            }
-            
-            // if the newChild is already in the tree,
-            var newChildParent = newChild.parentNode;
-            if (newChildParent) {
-              // remove it
-              newChildParent.removeChild(newChild);
-            }
-            
-            // insert newChild into childNodes
-            __insertBefore__(this.childNodes, newChild, __findItemIndex__(this.childNodes, refChild._id));
-            
-            // do node pointer surgery
-            prevNode = refChild.previousSibling;
-            
-            // handle DocumentFragment
-            if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
-              if (newChild.childNodes.length &gt; 0) {
-                // set the parentNode of DocumentFragment's children
-                for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
-                  newChild.childNodes[ind].parentNode = this;
-                }
-            
-                // link refChild to last child of DocumentFragment
-                refChild.previousSibling = newChild.childNodes[newChild.childNodes.length-1];
-              }
-            }else {
-                newChild.parentNode = this;                // set the parentNode of the newChild
-                refChild.previousSibling = newChild;       // link refChild to newChild
-            }
-        }else {                                         // otherwise, append to end
-            prevNode = this.lastChild;
-            this.appendChild(newChild);
-        }
-        
-        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
-            // do node pointer surgery for DocumentFragment
-            if (newChild.childNodes.length &gt; 0) {
-                if (prevNode) {  
-                    prevNode.nextSibling = newChild.childNodes[0];
-                }else {                                         // this is the first child in the list
-                    this.firstChild = newChild.childNodes[0];
-                }
-            
-                newChild.childNodes[0].previousSibling = prevNode;
-                newChild.childNodes[newChild.childNodes.length-1].nextSibling = refChild;
-            }
-        }else {
-            // do node pointer surgery for newChild
-            if (prevNode) {
-              prevNode.nextSibling = newChild;
-            }else {                                         // this is the first child in the list
-              this.firstChild = newChild;
-            }
-            
-            newChild.previousSibling = prevNode;
-            newChild.nextSibling     = refChild;
-        }
-        
-        return newChild;
-    },
-    replaceChild : function(newChild, oldChild) {
-        var ret = null;
-        
-        // test for exceptions
-        if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if DOMNode is readonly
-            if (this._readonly) {
-                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-        
-            // throw Exception if newChild was not created by this Document
-            if (this.ownerDocument != newChild.ownerDocument) {
-                throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-            }
-        
-            // throw Exception if the node is an ancestor
-            if (__isAncestor__(this, newChild)) {
-                throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
-            }
-        }
-        
-        // get index of oldChild
-        var index = __findItemIndex__(this.childNodes, oldChild._id);
-        
-        // throw Exception if there is no child node with this id
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (index &lt; 0)) {
-            throw(new DOMException(DOMException.NOT_FOUND_ERR));
-        }
-        
-        // if the newChild is already in the tree,
-        var newChildParent = newChild.parentNode;
-        if (newChildParent) {
-            // remove it
-            newChildParent.removeChild(newChild);
-        }
-        
-        // add newChild to childNodes
-        ret = __replaceChild__(this.childNodes,newChild, index);
-        
-        
-        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
-            // do node pointer surgery for Document Fragment
-            if (newChild.childNodes.length &gt; 0) {
-                for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
-                    newChild.childNodes[ind].parentNode = this;
-                }
-                
-                if (oldChild.previousSibling) {
-                    oldChild.previousSibling.nextSibling = newChild.childNodes[0];
-                } else {
-                    this.firstChild = newChild.childNodes[0];
-                }
-                
-                if (oldChild.nextSibling) {
-                    oldChild.nextSibling.previousSibling = newChild;
-                } else {
-                    this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
-                }
-                
-                newChild.childNodes[0].previousSibling = oldChild.previousSibling;
-                newChild.childNodes[newChild.childNodes.length-1].nextSibling = oldChild.nextSibling;
-            }
-        } else {
-            // do node pointer surgery for newChild
-            newChild.parentNode = this;
-            
-            if (oldChild.previousSibling) {
-                oldChild.previousSibling.nextSibling = newChild;
-            }else{
-                this.firstChild = newChild;
-            }
-            if (oldChild.nextSibling) {
-                oldChild.nextSibling.previousSibling = newChild;
-            }else{
-                this.lastChild = newChild;
-            }
-            newChild.previousSibling = oldChild.previousSibling;
-            newChild.nextSibling = oldChild.nextSibling;
-        }
-        //this.removeChild(oldChild);
-        return ret;
-    },
-    removeChild : function(oldChild) {
-        // throw Exception if DOMNamedNodeMap is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || oldChild._readonly)) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        
-        // get index of oldChild
-        var itemIndex = __findItemIndex__(this.childNodes, oldChild._id);
-        
-        // throw Exception if there is no child node with this id
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-            throw(new DOMException(DOMException.NOT_FOUND_ERR));
-        }
-        
-        // remove oldChild from childNodes
-        __removeChild__(this.childNodes, itemIndex);
-        
-        // do node pointer surgery
-        oldChild.parentNode = null;
-        
-        if (oldChild.previousSibling) {
-            oldChild.previousSibling.nextSibling = oldChild.nextSibling;
-        }else {
-            this.firstChild = oldChild.nextSibling;
-        }
-        if (oldChild.nextSibling) {
-            oldChild.nextSibling.previousSibling = oldChild.previousSibling;
-        }else {
-            this.lastChild = oldChild.previousSibling;
-        }
-        
-        oldChild.previousSibling = null;
-        oldChild.nextSibling = null;
-        
-        /*if(oldChild.ownerDocument == document){
-            $log(&quot;removeChild :  all -&gt; &quot; + document.all.length);
-        }*/
-        return oldChild;
-    },
-    appendChild : function(newChild) {
-      // test for exceptions
-      if (this.ownerDocument.implementation.errorChecking) {
-        // throw Exception if Node is readonly
-        if (this._readonly) {
-          throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-    
-        // throw Exception if arg was not created by this Document
-        if (this.ownerDocument != newChild.ownerDocument) {
-          throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
-        }
-    
-        // throw Exception if the node is an ancestor
-        if (__isAncestor__(this, newChild)) {
-          throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
-        }
-      }
-    
-      // if the newChild is already in the tree,
-      var newChildParent = newChild.parentNode;
-      if (newChildParent) {
-        // remove it
-        newChildParent.removeChild(newChild);
-      }
-    
-      // add newChild to childNodes
-      __appendChild__(this.childNodes, newChild);
-    
-      if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
-        // do node pointer surgery for DocumentFragment
-        if (newChild.childNodes.length &gt; 0) {
-          for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
-            newChild.childNodes[ind].parentNode = this;
-          }
-    
-          if (this.lastChild) {
-            this.lastChild.nextSibling = newChild.childNodes[0];
-            newChild.childNodes[0].previousSibling = this.lastChild;
-            this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
-          }
-          else {
-            this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
-            this.firstChild = newChild.childNodes[0];
-          }
-        }
-      }
-      else {
-        // do node pointer surgery for newChild
-        newChild.parentNode = this;
-        if (this.lastChild) {
-          this.lastChild.nextSibling = newChild;
-          newChild.previousSibling = this.lastChild;
-          this.lastChild = newChild;
-        }
-        else {
-          this.lastChild = newChild;
-          this.firstChild = newChild;
-        }
-      }
-    
-      return newChild;
-    },
-    hasChildNodes : function() {
-        return (this.childNodes.length &gt; 0);
-    },
-    cloneNode: function(deep) {
-        // use importNode to clone this Node
-        //do not throw any exceptions
-        //$log(&quot;cloning node&quot;);
-        try {
-            return this.ownerDocument.importNode(this, deep);
-        } catch (e) {
-            //there shouldn't be any exceptions, but if there are, return null
-            return null;
-        }
-    },
-    normalize : function() {
-        var inode;
-        var nodesToRemove = new DOMNodeList();
-        
-        if (this.nodeType == DOMNode.ELEMENT_NODE || this.nodeType == DOMNode.DOCUMENT_NODE) {
-            var adjacentTextNode = null;
-        
-            // loop through all childNodes
-            for(var i = 0; i &lt; this.childNodes.length; i++) {
-                inode = this.childNodes.item(i);
-            
-                if (inode.nodeType == DOMNode.TEXT_NODE) { // this node is a text node
-                    if (inode.length &lt; 1) {                  // this text node is empty
-                        __appendChild__(nodesToRemove, inode);      // add this node to the list of nodes to be remove
-                    }else {
-                        if (adjacentTextNode) {                // if previous node was also text
-                            adjacentTextNode.appendData(inode.data);     // merge the data in adjacent text nodes
-                            __appendChild__(nodesToRemove, inode);    // add this node to the list of nodes to be removed
-                        }else {
-                            adjacentTextNode = inode;              // remember this node for next cycle
-                        }
-                    }
-                } else {
-                    adjacentTextNode = null;                 // (soon to be) previous node is not a text node
-                    inode.normalize();                       // normalise non Text childNodes
-                }
-            }
-                
-            // remove redundant Text Nodes
-            for(var i = 0; i &lt; nodesToRemove.length; i++) {
-                inode = nodesToRemove.item(i);
-                inode.parentNode.removeChild(inode);
-            }
-        }
-    },
-    isSupported : function(feature, version) {
-        // use Implementation.hasFeature to determin if this feature is supported
-        return this.ownerDocument.implementation.hasFeature(feature, version);
-    },
-    getElementsByTagName : function(tagname) {
-        // delegate to _getElementsByTagNameRecursive
-        //$log(&quot;getElementsByTagName(&quot;+tagname+&quot;)&quot;);
-        return __getElementsByTagNameRecursive__(this, tagname, new DOMNodeList(this.ownerDocument));
-    },
-    getElementsByTagNameNS : function(namespaceURI, localName) {
-        // delegate to _getElementsByTagNameNSRecursive
-        return __getElementsByTagNameNSRecursive__(this, namespaceURI, localName, new DOMNodeList(this.ownerDocument));
-    },
-    importNode : function(importedNode, deep) {
-        var importNode;
-        //$log(&quot;importing node &quot; + importedNode + &quot;(?deep = &quot;+deep+&quot;)&quot;);
-        //there is no need to perform namespace checks since everything has already gone through them
-        //in order to have gotten into the DOM in the first place. The following line
-        //turns namespace checking off in ._isValidNamespace
-        this.ownerDocument._performingImportNodeOperation = true;
-        
-        try {
-            if (importedNode.nodeType == DOMNode.ELEMENT_NODE) {
-                if (!this.ownerDocument.implementation.namespaceAware) {
-                    // create a local Element (with the name of the importedNode)
-                    importNode = this.ownerDocument.createElement(importedNode.tagName);
-                
-                    // create attributes matching those of the importedNode
-                    for(var i = 0; i &lt; importedNode.attributes.length; i++) {
-                        importNode.setAttribute(importedNode.attributes.item(i).name, importedNode.attributes.item(i).value);
-                    }
-                }else {
-                    // create a local Element (with the name &amp; namespaceURI of the importedNode)
-                    importNode = this.ownerDocument.createElementNS(importedNode.namespaceURI, importedNode.nodeName);
-                
-                    // create attributes matching those of the importedNode
-                    for(var i = 0; i &lt; importedNode.attributes.length; i++) {
-                        importNode.setAttributeNS(importedNode.attributes.item(i).namespaceURI, 
-                            importedNode.attributes.item(i).name, importedNode.attributes.item(i).value);
-                    }
-                
-                    // create namespace definitions matching those of the importedNode
-                    for(var i = 0; i &lt; importedNode._namespaces.length; i++) {
-                        importNode._namespaces[i] = this.ownerDocument.createNamespace(importedNode._namespaces.item(i).localName);
-                        importNode._namespaces[i].value = importedNode._namespaces.item(i).value;
-                    }
-                }
-            } else if (importedNode.nodeType == DOMNode.ATTRIBUTE_NODE) {
-                if (!this.ownerDocument.implementation.namespaceAware) {
-                    // create a local Attribute (with the name of the importedAttribute)
-                    importNode = this.ownerDocument.createAttribute(importedNode.name);
-                } else {
-                    // create a local Attribute (with the name &amp; namespaceURI of the importedAttribute)
-                    importNode = this.ownerDocument.createAttributeNS(importedNode.namespaceURI, importedNode.nodeName);
-                
-                    // create namespace definitions matching those of the importedAttribute
-                    for(var i = 0; i &lt; importedNode._namespaces.length; i++) {
-                        importNode._namespaces[i] = this.ownerDocument.createNamespace(importedNode._namespaces.item(i).localName);
-                        importNode._namespaces[i].value = importedNode._namespaces.item(i).value;
-                    }
-                }
-            
-                // set the value of the local Attribute to match that of the importedAttribute
-                importNode.value = importedNode.value;
-                
-            } else if (importedNode.nodeType == DOMNode.DOCUMENT_FRAGMENT) {
-                // create a local DocumentFragment
-                importNode = this.ownerDocument.createDocumentFragment();
-            } else if (importedNode.nodeType == DOMNode.NAMESPACE_NODE) {
-                // create a local NamespaceNode (with the same name &amp; value as the importedNode)
-                importNode = this.ownerDocument.createNamespace(importedNode.nodeName);
-                importNode.value = importedNode.value;
-            } else if (importedNode.nodeType == DOMNode.TEXT_NODE) {
-                // create a local TextNode (with the same data as the importedNode)
-                importNode = this.ownerDocument.createTextNode(importedNode.data);
-            } else if (importedNode.nodeType == DOMNode.CDATA_SECTION_NODE) {
-                // create a local CDATANode (with the same data as the importedNode)
-                importNode = this.ownerDocument.createCDATASection(importedNode.data);
-            } else if (importedNode.nodeType == DOMNode.PROCESSING_INSTRUCTION_NODE) {
-                // create a local ProcessingInstruction (with the same target &amp; data as the importedNode)
-                importNode = this.ownerDocument.createProcessingInstruction(importedNode.target, importedNode.data);
-            } else if (importedNode.nodeType == DOMNode.COMMENT_NODE) {
-                // create a local Comment (with the same data as the importedNode)
-                importNode = this.ownerDocument.createComment(importedNode.data);
-            } else {  // throw Exception if nodeType is not supported
-                throw(new DOMException(DOMException.NOT_SUPPORTED_ERR));
-            }
-            
-            if (deep) {                                    // recurse childNodes
-                for(var i = 0; i &lt; importedNode.childNodes.length; i++) {
-                    importNode.appendChild(this.ownerDocument.importNode(importedNode.childNodes.item(i), true));
-                }
-            }
-            
-            //reset _performingImportNodeOperation
-            this.ownerDocument._performingImportNodeOperation = false;
-            return importNode;
-        } catch (eAny) {
-            //reset _performingImportNodeOperation
-            this.ownerDocument._performingImportNodeOperation = false;
-            
-            //re-throw the exception
-            throw eAny;
-        }//djotemp
-    },
-    contains : function(node){
-            while(node &amp;&amp; node != this ){
-                node = node.parentNode;
-            }
-            return !!node;
-    },
-    compareDocumentPosition : function(b){
-        var a = this;
-        var number = (a != b &amp;&amp; a.contains(b) &amp;&amp; 16) + (a != b &amp;&amp; b.contains(a) &amp;&amp; 8);
-        //find position of both
-        var all = document.getElementsByTagName(&quot;*&quot;);
-        var my_location = 0, node_location = 0;
-        for(var i=0; i &lt; all.length; i++){
-            if(all[i] == a) my_location = i;
-            if(all[i] == b) node_location = i;
-            if(my_location &amp;&amp; node_location) break;
-        }
-        number += (my_location &lt; node_location &amp;&amp; 4)
-        number += (my_location &gt; node_location &amp;&amp; 2)
-        return number;
-    } 
-
-});
-
-/**
- * @method DOMNode._getElementsByTagNameRecursive - implements getElementsByTagName()
- * @param  elem     : DOMElement  - The element which are checking and then recursing into
- * @param  tagname  : string      - The name of the tag to match on. The special value &quot;*&quot; matches all tags
- * @param  nodeList : DOMNodeList - The accumulating list of matching nodes
- *
- * @return : DOMNodeList
- */
-var __getElementsByTagNameRecursive__ = function (elem, tagname, nodeList) {
-    //$log(&quot;__getElementsByTagNameRecursive__(&quot;+elem._id+&quot;)&quot;);
-    if (elem.nodeType == DOMNode.ELEMENT_NODE || elem.nodeType == DOMNode.DOCUMENT_NODE) {
-    
-        if((elem.nodeName.toUpperCase() == tagname.toUpperCase()) || (tagname == &quot;*&quot;)) {
-            //$log(&quot;found node by name &quot; + tagname);
-            __appendChild__(nodeList, elem);               // add matching node to nodeList
-        }
-    
-        // recurse childNodes
-        for(var i = 0; i &lt; elem.childNodes.length; i++) {
-            nodeList = __getElementsByTagNameRecursive__(elem.childNodes.item(i), tagname, nodeList);
-        }
-    }
-    
-    return nodeList;
-};
-
-
-/**
- * @method DOMNode._getElementsByTagNameNSRecursive - implements getElementsByTagName()
- *
- * @param  elem     : DOMElement  - The element which are checking and then recursing into
- * @param  namespaceURI : string - the namespace URI of the required node
- * @param  localName    : string - the local name of the required node
- * @param  nodeList     : DOMNodeList - The accumulating list of matching nodes
- *
- * @return : DOMNodeList
- */
-var __getElementsByTagNameNSRecursive__ = function(elem, namespaceURI, localName, nodeList) {
-  if (elem.nodeType == DOMNode.ELEMENT_NODE || elem.nodeType == DOMNode.DOCUMENT_NODE) {
-
-    if (((elem.namespaceURI == namespaceURI) || (namespaceURI == &quot;*&quot;)) &amp;&amp; ((elem.localName == localName) || (localName == &quot;*&quot;))) {
-      __appendChild__(nodeList, elem);               // add matching node to nodeList
-    }
-
-    // recurse childNodes
-    for(var i = 0; i &lt; elem.childNodes.length; i++) {
-      nodeList = __getElementsByTagNameNSRecursive__(elem.childNodes.item(i), namespaceURI, localName, nodeList);
-    }
-  }
-
-  return nodeList;
-};
-
-/**
- * @method DOMNode._isAncestor - returns true if node is ancestor of target
- * @param  target         : DOMNode - The node we are using as context
- * @param  node         : DOMNode - The candidate ancestor node
- * @return : boolean
- */
-var __isAncestor__ = function(target, node) {
-  // if this node matches, return true,
-  // otherwise recurse up (if there is a parentNode)
-  return ((target == node) || ((target.parentNode) &amp;&amp; (__isAncestor__(target.parentNode, node))));
-}
-
-
-/**
- * @class  DOMNamespace - The Namespace interface represents an namespace in an Element object
- *
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMNamespace = function(ownerDocument) {
-  this.DOMNode = DOMNode;
-  this.DOMNode(ownerDocument);
-
-  this.name      = &quot;&quot;;                           // the name of this attribute
-
-  // If this attribute was explicitly given a value in the original document, this is true; otherwise, it is false.
-  // Note that the implementation is in charge of this attribute, not the user.
-  // If the user changes the value of the attribute (even if it ends up having the same value as the default value)
-  // then the specified flag is automatically flipped to true
-  this.specified = false;
-
-  this.value     = &quot;&quot;;                           // the value of the attribute is returned as a string
-
-  this.nodeType  = DOMNode.NAMESPACE_NODE;
-};
-DOMNamespace.prototype = new DOMNode;
-__extend__(DOMNamespace.prototype, {
-    get value(){
-        return this.nodeValue;
-    },
-    set value(value){
-        this.nodeValue = String(value);
-    },
-    get xml(){
-        var ret = &quot;&quot;;
-
-          // serialize Namespace Declaration
-          if (this.nodeName != &quot;&quot;) {
-            ret += this.nodeName +&quot;=\&quot;&quot;+ __escapeXML__(this.nodeValue) +&quot;\&quot;&quot;;
-          }
-          else {  // handle default namespace
-            ret += &quot;xmlns=\&quot;&quot;+ __escapeXML__(this.nodeValue) +&quot;\&quot;&quot;;
-          }
-        
-          return ret;
-    },
-    toString: function(){
-        return &quot;Namespace #&quot; + this.id;
-    }
-});
-
-$debug(&quot;Defining CharacterData&quot;);
-/*
-* CharacterData - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CharacterData&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMCharacterData - parent abstract class for DOMText and DOMComment
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMCharacterData = function(ownerDocument) {
-  this.DOMNode  = DOMNode;
-  this.DOMNode(ownerDocument);
-  this.data   = &quot;&quot;;
-  this.length = 0;
-};
-DOMCharacterData.prototype = new DOMNode;
-__extend__(DOMCharacterData.prototype,{
-    get data(){
-        return String(this.nodeValue);
-    },
-    set data(data){
-        this.nodeValue = String(data);
-    },
-    get length(){return this.nodeValue.length;},
-    appendData: function(arg){
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        // append data
-        this.data = &quot;&quot; + this.data + arg;
-    },
-    deleteData: function(offset, count){ 
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
-              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // delete data
-            if(!count || (offset + count) &gt; this.data.length) {
-              this.data = this.data.substring(0, offset);
-            }else {
-              this.data = this.data.substring(0, offset).concat(this.data.substring(offset + count));
-            }
-        }
-    },
-    insertData: function(offset, arg){
-        // throw Exception if DOMCharacterData is readonly
-        if(this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly){
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        
-        if(this.data){
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // insert data
-            this.data =  this.data.substring(0, offset).concat(arg, this.data.substring(offset));
-        }else {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (offset != 0)) {
-               throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // set data
-            this.data = arg;
-        }
-    },
-    replaceData: function(offset, count, arg){
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // replace data
-            this.data = this.data.substring(0, offset).concat(arg, this.data.substring(offset + count));
-        }else {
-            // set data
-            this.data = arg;
-        }
-    },
-    substringData: function(offset, count){
-        var ret = null;
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            // or the count is negative
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt; this.data.length) || (count &lt; 0))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            // if count is not specified
-            if (!count) {
-                ret = this.data.substring(offset); // default to 'end of string'
-            }else{
-                ret = this.data.substring(offset, offset + count);
-            }
-        }
-        return ret;
-    }
-});
-$log(&quot;Defining Text&quot;);
-/*
-* Text - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Text&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-/**
- * @class  DOMText - The Text interface represents the textual content (termed character data in XML) of an Element or Attr.
- *   If there is no markup inside an element's content, the text is contained in a single object implementing the Text interface
- *   that is the only child of the element. If there is markup, it is parsed into a list of elements and Text nodes that form the
- *   list of children of the element.
- * @extends DOMCharacterData
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-DOMText = function(ownerDocument) {
-  this.DOMCharacterData  = DOMCharacterData;
-  this.DOMCharacterData(ownerDocument);
-
-  this.nodeName  = &quot;#text&quot;;
-  this.nodeType  = DOMNode.TEXT_NODE;
-};
-DOMText.prototype = new DOMCharacterData;
-__extend__(DOMText.prototype,{
-    //Breaks this Text node into two Text nodes at the specified offset,
-    // keeping both in the tree as siblings. This node then only contains all the content up to the offset point.
-    // And a new Text node, which is inserted as the next sibling of this node, contains all the content at and after the offset point.
-    splitText : function(offset) {
-        var data, inode;
-        
-        // test for exceptions
-        if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if Node is readonly
-            if (this._readonly) {
-              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-            
-            // throw Exception if offset is negative or greater than the data length,
-            if ((offset &lt; 0) || (offset &gt; this.data.length)) {
-              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-        }
-        
-        if (this.parentNode) {
-            // get remaining string (after offset)
-            data  = this.substringData(offset);
-            
-            // create new TextNode with remaining string
-            inode = this.ownerDocument.createTextNode(data);
-            
-            // attach new TextNode
-            if (this.nextSibling) {
-              this.parentNode.insertBefore(inode, this.nextSibling);
-            }
-            else {
-              this.parentNode.appendChild(inode);
-            }
-            
-            // remove remaining string from original TextNode
-            this.deleteData(offset);
-        }
-        
-        return inode;
-    },
-    get xml(){
-        return __escapeXML__(&quot;&quot;+ this.nodeValue);
-    },
-    toString: function(){
-        return &quot;Text #&quot; + this._id;    
-    }
-});
-
-$log(&quot;Defining CDATASection&quot;);
-/*
-* CDATASection - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CDATASection&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMCDATASection - CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup.
- *   The only delimiter that is recognized in a CDATA section is the &quot;\]\]\&gt;&quot; string that ends the CDATA section
- * @extends DOMCharacterData
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMCDATASection = function(ownerDocument) {
-  this.DOMText  = DOMText;
-  this.DOMText(ownerDocument);
-
-  this.nodeName  = &quot;#cdata-section&quot;;
-  this.nodeType  = DOMNode.CDATA_SECTION_NODE;
-};
-DOMCDATASection.prototype = new DOMText;
-__extend__(DOMCDATASection.prototype,{
-    get xml(){
-        return &quot;&lt;![CDATA[&quot; + this.nodeValue + &quot;]]&gt;&quot;;
-    },
-    toString : function(){
-        return &quot;CDATA #&quot;+this._id;
-    }
-});$log(&quot;Defining Comment&quot;);
-/* 
-* Comment - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Comment&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMComment - This represents the content of a comment, i.e., all the characters between the starting '&lt;!--' and ending '--&gt;'
- * @extends DOMCharacterData
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMComment = function(ownerDocument) {
-  this.DOMCharacterData  = DOMCharacterData;
-  this.DOMCharacterData(ownerDocument);
-
-  this.nodeName  = &quot;#comment&quot;;
-  this.nodeType  = DOMNode.COMMENT_NODE;
-};
-DOMComment.prototype = new DOMCharacterData;
-__extend__(DOMComment.prototype, {
-    get xml(){
-        return &quot;&lt;!-- &quot; + this.nodeValue + &quot; --&gt;&quot;;
-    },
-    toString : function(){
-        return &quot;Comment #&quot;+this._id;
-    }
-});
-$log(&quot;Defining DocumentType&quot;);
-;/*
-* DocumentType - DOM Level 2
-*/
-$w.__defineGetter__('DocumentType', function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var DOMDocumentType    = function() { $error(&quot;DOMDocumentType.constructor(): Not Implemented&quot;   ); };$log(&quot;Defining Attr&quot;);
-/*
-* Attr - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Attr&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-
-/**
- * @class  DOMAttr - The Attr interface represents an attribute in an Element object
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMAttr = function(ownerDocument) {
-    //$log(&quot;\tcreating dom attribute&quot;);
-    this.DOMNode = DOMNode;
-    this.DOMNode(ownerDocument);
-    
-    this.name      = &quot;&quot;;                    // the name of this attribute
-    this.specified = false;
-    this.value     = &quot;&quot;;                    // the value of the attribute is returned as a string
-    this.nodeType  = DOMNode.ATTRIBUTE_NODE;
-    this.ownerElement = null;               // set when Attr is added to NamedNodeMap
-    
-    //$log(&quot;\tfincished creating dom attribute &quot; + this);
-};
-DOMAttr.prototype = new DOMNode; 
-__extend__(DOMAttr.prototype, {
-    get name(){
-        return this.nodeName;
-    },
-    get value(){
-        return this.nodeValue;
-    },
-    set value(value){
-        // throw Exception if Attribute is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        // delegate to node
-        this.specified = (this.value.length &gt; 0);
-        this.nodeValue = value;
-    },
-    get xml(){
-        return this.nodeName + &quot;='&quot; + this.nodeValue + &quot;' &quot;;
-    },
-    toString : function(){
-        return &quot;Attr #&quot; + this._id + &quot; &quot; + this.name;
-    }
-});    
-
-$log(&quot;Defining Element&quot;);
-/*
-* Element - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Element&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-	
-/**
- * @class  DOMElement - By far the vast majority of objects (apart from text) that authors encounter
- *   when traversing a document are Element nodes.
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMElement = function(ownerDocument) {
-    //$log(&quot;\tcreating dom element&quot;);
-    this.DOMNode  = DOMNode;
-    this.DOMNode(ownerDocument);
-    this.tagName = &quot;&quot;;                             // The name of the element.
-    this.id = &quot;&quot;;                                  // the ID of the element
-    this.nodeType = DOMNode.ELEMENT_NODE;
-    //$log(&quot;\nfinished creating dom element &quot; + this);
-};
-DOMElement.prototype = new DOMNode;
-__extend__(DOMElement.prototype, {
-  	addEventListener:     window.addEventListener,
-  	removeEventListener:  window.removeEventListener,
-  	dispatchEvent:        window.dispatchEvent,
-    getAttribute: function(name) {
-        var ret = null;
-        // if attribute exists, use it
-        var attr = this.attributes.getNamedItem(name);
-        if (attr) {
-            ret = attr.value;
-        }
-        return ret; // if Attribute exists, return its value, otherwise, return &quot;&quot;
-    },
-    setAttribute : function (name, value) {
-        // if attribute exists, use it
-        var attr = this.attributes.getNamedItem(name);
-        var value = new String(value);
-        //I had to add this check becuase as the script initializes
-        //the id may be set in the constructor, and the html element
-        //overrides the id property with a getter/setter.
-        if(this.ownerDocument){
-            if (!attr) {
-                attr = this.ownerDocument.createAttribute(name);  // otherwise create it
-            }
-            
-            
-            // test for exceptions
-            if (this.ownerDocument.implementation.errorChecking) {
-                // throw Exception if Attribute is readonly
-                if (attr._readonly) {
-                    throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-                }
-                
-                // throw Exception if the value string contains an illegal character
-                if (!__isValidString__(value)) {
-                    throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-                }
-            }
-            
-            if (__isIdDeclaration__(name)) {
-                this.id = value;  // cache ID for getElementById()
-            }
-            
-            // assign values to properties (and aliases)
-            attr.value     = value;
-            
-            // update .specified
-            if (value.length &gt; 0) {
-                attr.specified = true;
-            }else {
-                attr.specified = false;
-            }
-            
-            // add/replace Attribute in NamedNodeMap
-            this.attributes.setNamedItem(attr);
-        }
-    },
-    removeAttribute : function removeAttribute(name) {
-        // delegate to DOMNamedNodeMap.removeNamedItem
-        return this.attributes.removeNamedItem(name);
-    },
-    getAttributeNode : function getAttributeNode(name) {
-        // delegate to DOMNamedNodeMap.getNamedItem
-        return this.attributes.getNamedItem(name);
-    },
-    setAttributeNode: function(newAttr) {
-        // if this Attribute is an ID
-        if (__isIdDeclaration__(newAttr.name)) {
-            this.id = newAttr.value;  // cache ID for getElementById()
-        }
-        // delegate to DOMNamedNodeMap.setNamedItem
-        return this.attributes.setNamedItem(newAttr);
-    },
-    removeAttributeNode: function(oldAttr) {
-      // throw Exception if Attribute is readonly
-      if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldAttr._readonly) {
-        throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-      }
-    
-      // get item index
-      var itemIndex = this.attributes._findItemIndex(oldAttr._id);
-    
-      // throw Exception if node does not exist in this map
-      if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
-        throw(new DOMException(DOMException.NOT_FOUND_ERR));
-      }
-    
-      return this.attributes._removeChild(itemIndex);
-    },
-    getAttributeNS : function(namespaceURI, localName) {
-        var ret = &quot;&quot;;
-        // delegate to DOMNAmedNodeMap.getNamedItemNS
-        var attr = this.attributes.getNamedItemNS(namespaceURI, localName);
-        if (attr) {
-            ret = attr.value;
-        }
-        return ret;  // if Attribute exists, return its value, otherwise return &quot;&quot;
-    },
-    setAttributeNS : function(namespaceURI, qualifiedName, value) {
-        // call DOMNamedNodeMap.getNamedItem
-        var attr = this.attributes.getNamedItem(namespaceURI, qualifiedName);
-        
-        if (!attr) {  // if Attribute exists, use it
-            // otherwise create it
-            attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
-        }
-        
-        var value = String(value);
-        
-        // test for exceptions
-        if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if Attribute is readonly
-            if (attr._readonly) {
-                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-            }
-            
-            // throw Exception if the Namespace is invalid
-            if (!__isValidNamespace__(namespaceURI, qualifiedName)) {
-                throw(new DOMException(DOMException.NAMESPACE_ERR));
-            }
-            
-            // throw Exception if the value string contains an illegal character
-            if (!__isValidString__(value)) {
-                throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-            }
-        }
-        
-        // if this Attribute is an ID
-        if (__isIdDeclaration__(name)) {
-            this.id = value;  // cache ID for getElementById()
-        }
-        
-        // assign values to properties (and aliases)
-        attr.value     = value;
-        attr.nodeValue = value;
-        
-        // update .specified
-        if (value.length &gt; 0) {
-            attr.specified = true;
-        }else {
-            attr.specified = false;
-        }
-        
-        // delegate to DOMNamedNodeMap.setNamedItem
-        this.attributes.setNamedItemNS(attr);
-    },
-    removeAttributeNS : function(namespaceURI, localName) {
-        // delegate to DOMNamedNodeMap.removeNamedItemNS
-        return this.attributes.removeNamedItemNS(namespaceURI, localName);
-    },
-    getAttributeNodeNS : function(namespaceURI, localName) {
-        // delegate to DOMNamedNodeMap.getNamedItemNS
-        return this.attributes.getNamedItemNS(namespaceURI, localName);
-    },
-    setAttributeNodeNS : function(newAttr) {
-        // if this Attribute is an ID
-        if ((newAttr.prefix == &quot;&quot;) &amp;&amp;  __isIdDeclaration__(newAttr.name)) {
-            this.id = String(newAttr.value);  // cache ID for getElementById()
-        }
-        
-        // delegate to DOMNamedNodeMap.setNamedItemNS
-        return this.attributes.setNamedItemNS(newAttr);
-    },
-    hasAttribute : function(name) {
-        // delegate to DOMNamedNodeMap._hasAttribute
-        return __hasAttribute__(this.attributes,name);
-    },
-    hasAttributeNS : function(namespaceURI, localName) {
-        // delegate to DOMNamedNodeMap._hasAttributeNS
-        return __hasAttributeNS__(this.attributes, namespaceURI, localName);
-    },
-    get xml() {
-        var ret = &quot;&quot;;
-        
-        // serialize namespace declarations
-        var ns = this._namespaces.xml;
-        if (ns.length &gt; 0) ns = &quot; &quot;+ ns;
-        
-        // serialize Attribute declarations
-        var attrs = this.attributes.xml;
-        if (attrs.length &gt; 0) attrs = &quot; &quot;+ attrs;
-        
-        // serialize this Element
-        ret += &quot;&lt;&quot; + this.nodeName.toLowerCase() + ns + attrs +&quot;&gt;&quot;;
-        ret += this.childNodes.xml;
-        ret += &quot;&lt;/&quot; + this.nodeName.toLowerCase()+&quot;&gt;&quot;;
-        
-        return ret;
-    },
-    toString : function(){
-        return &quot;Element #&quot;+this._id + &quot; &quot;+ this.tagName + (this.id?&quot; =&gt; &quot;+this.id:'');
-    }
-});
-
-/**
- * @class  DOMException - raised when an operation is impossible to perform
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  code : int - the exception code (one of the DOMException constants)
- */
-var DOMException = function(code) {
-  this.code = code;
-};
-
-// DOMException constants
-// Introduced in DOM Level 1:
-DOMException.INDEX_SIZE_ERR                 = 1;
-DOMException.DOMSTRING_SIZE_ERR             = 2;
-DOMException.HIERARCHY_REQUEST_ERR          = 3;
-DOMException.WRONG_DOCUMENT_ERR             = 4;
-DOMException.INVALID_CHARACTER_ERR          = 5;
-DOMException.NO_DATA_ALLOWED_ERR            = 6;
-DOMException.NO_MODIFICATION_ALLOWED_ERR    = 7;
-DOMException.NOT_FOUND_ERR                  = 8;
-DOMException.NOT_SUPPORTED_ERR              = 9;
-DOMException.INUSE_ATTRIBUTE_ERR            = 10;
-
-// Introduced in DOM Level 2:
-DOMException.INVALID_STATE_ERR              = 11;
-DOMException.SYNTAX_ERR                     = 12;
-DOMException.INVALID_MODIFICATION_ERR       = 13;
-DOMException.NAMESPACE_ERR                  = 14;
-DOMException.INVALID_ACCESS_ERR             = 15;
-$log(&quot;Defining DocumentFragment&quot;);
-/* 
-* DocumentFragment - DOM Level 2
-*/
-$w.__defineGetter__(&quot;DocumentFragment&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-/**
- * @class  DOMDocumentFragment - DocumentFragment is a &quot;lightweight&quot; or &quot;minimal&quot; Document object.
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMDocumentFragment = function(ownerDocument) {
-  this.DOMNode = DOMNode;
-  this.DOMNode(ownerDocument);
-  this.nodeName  = &quot;#document-fragment&quot;;
-  this.nodeType = DOMNode.DOCUMENT_FRAGMENT_NODE;
-};
-DOMDocumentFragment.prototype = new DOMNode;
-__extend__(DOMDocumentFragment.prototype,{
-    get xml(){
-        var xml = &quot;&quot;,
-            count = this.childNodes.length;
-        
-        // create string concatenating the serialized ChildNodes
-        for (var i = 0; i &lt; count; i++) {
-            xml += this.childNodes.item(i).xml;
-        }
-        
-        return xml;
-    },
-    toString : function(){
-        return &quot;DocumentFragment #&quot;+this._id;
-    }
-});
-$log(&quot;Defining ProcessingInstruction&quot;);
-/*
-* ProcessingInstruction - DOM Level 2
-*/
-$w.__defineGetter__('ProcessingInstruction', function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-/**
- * @class  DOMProcessingInstruction - The ProcessingInstruction interface represents a &quot;processing instruction&quot;,
- *   used in XML as a way to keep processor-specific information in the text of the document
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMProcessingInstruction = function(ownerDocument) {
-  this.DOMNode  = DOMNode;
-  this.DOMNode(ownerDocument);
-  // The target of this processing instruction.
-  // XML defines this as being the first token following the markup that begins the processing instruction.
-  this.target = &quot;&quot;;
-  // The content of this processing instruction.
-  // This is from the first non white space character after the target to the character immediately preceding the ?&gt;
-  this.data   = &quot;&quot;;
-  this.nodeType  = DOMNode.PROCESSING_INSTRUCTION_NODE;
-};
-DOMProcessingInstruction.prototype = new DOMNode;
-__extend__(DOMProcessingInstruction.prototype, {
-    get data(){
-        return this.nodeValue;
-    },
-    set data(data){
-        // throw Exception if DOMNode is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        this.nodeValue = data;
-    },
-    get target(){
-        return this.nodeName;
-    },
-    get xml(){
-        return &quot;&lt;?&quot; + this.nodeName +&quot; &quot;+ this.nodeValue + &quot; ?&gt;&quot;;
-    },
-    toString : function(){
-        return &quot;ProcessingInstruction #&quot;+this._id;
-    }
-});
-$log(&quot;Defining DOMParser&quot;);
-/*
-* DOMParser
-*/
-$w.__defineGetter__('DOMParser', function(){
-  return function(){
-    return __extend__(this, {
-      parseFromString: function(xmlString){
-        //$log(&quot;Parsing XML String: &quot; +xmlString);
-        return document.implementation.createDocument().loadXML(xmlString);
-      }
-    });
-  };
-});
-
-$log(&quot;Initializing Internal DOMParser.&quot;);
-//keep one around for internal use
-$domparser = new DOMParser();
-
-// =========================================================================
-//
-// xmlsax.js - an XML SAX parser in JavaScript.
-//
-// version 3.1
-//
-// =========================================================================
-//
-// Copyright (C) 2001 - 2002 David Joham (djoham@yahoo.com) and Scott Severtson
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-//
-//
-// Visit the XML for &lt;SCRIPT&gt; home page at http://xmljs.sourceforge.net
-//
-
-// CONSTANTS
-var whitespace = &quot;\n\r\t &quot;;
-
-
-/**
-*   function:   this is the constructor to the XMLP Object
-*   Author:   Scott Severtson
-*   Description:XMLP is a pull-based parser. The calling application passes in a XML string
-*   to the constructor, then repeatedly calls .next() to parse the next segment.
-*   .next() returns a flag indicating what type of segment was found, and stores
-*   data temporarily in couple member variables (name, content, array of
-*   attributes), which can be accessed by several .get____() methods.
-*
-*   Basically, XMLP is the lowest common denominator parser - an very simple
-*   API which other wrappers can be built against.
-**/
-
-
-var XMLP = function(strXML) {
-    // Normalize line breaks
-    strXML = SAXStrings.replace(strXML, null, null, &quot;\r\n&quot;, &quot;\n&quot;);
-    strXML = SAXStrings.replace(strXML, null, null, &quot;\r&quot;, &quot;\n&quot;);
-
-    this.m_xml = strXML;
-    this.m_iP = 0;
-    this.m_iState = XMLP._STATE_PROLOG;
-    this.m_stack = new Stack();
-    this._clearAttributes();
-
-};
-
-
-// CONSTANTS    (these must be below the constructor)
-
-
-XMLP._NONE    = 0;
-XMLP._ELM_B   = 1;
-XMLP._ELM_E   = 2;
-XMLP._ELM_EMP = 3;
-XMLP._ATT     = 4;
-XMLP._TEXT    = 5;
-XMLP._ENTITY  = 6;
-XMLP._PI      = 7;
-XMLP._CDATA   = 8;
-XMLP._COMMENT = 9;
-XMLP._DTD     = 10;
-XMLP._ERROR   = 11;
-
-XMLP._CONT_XML = 0;
-XMLP._CONT_ALT = 1;
-
-XMLP._ATT_NAME = 0;
-XMLP._ATT_VAL  = 1;
-
-XMLP._STATE_PROLOG = 1;
-XMLP._STATE_DOCUMENT = 2;
-XMLP._STATE_MISC = 3;
-
-XMLP._errs = new Array();
-XMLP._errs[XMLP.ERR_CLOSE_PI       = 0 ] = &quot;PI: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_DTD      = 1 ] = &quot;DTD: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_COMMENT  = 2 ] = &quot;Comment: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_CDATA    = 3 ] = &quot;CDATA: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_ELM      = 4 ] = &quot;Element: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_CLOSE_ENTITY   = 5 ] = &quot;Entity: missing closing sequence&quot;;
-XMLP._errs[XMLP.ERR_PI_TARGET      = 6 ] = &quot;PI: target is required&quot;;
-XMLP._errs[XMLP.ERR_ELM_EMPTY      = 7 ] = &quot;Element: cannot be both empty and closing&quot;;
-XMLP._errs[XMLP.ERR_ELM_NAME       = 8 ] = &quot;Element: name must immediatly follow \&quot;&lt;\&quot;&quot;;
-XMLP._errs[XMLP.ERR_ELM_LT_NAME    = 9 ] = &quot;Element: \&quot;&lt;\&quot; not allowed in element names&quot;;
-XMLP._errs[XMLP.ERR_ATT_VALUES     = 10] = &quot;Attribute: values are required and must be in quotes&quot;;
-XMLP._errs[XMLP.ERR_ATT_LT_NAME    = 11] = &quot;Element: \&quot;&lt;\&quot; not allowed in attribute names&quot;;
-XMLP._errs[XMLP.ERR_ATT_LT_VALUE   = 12] = &quot;Attribute: \&quot;&lt;\&quot; not allowed in attribute values&quot;;
-XMLP._errs[XMLP.ERR_ATT_DUP        = 13] = &quot;Attribute: duplicate attributes not allowed&quot;;
-XMLP._errs[XMLP.ERR_ENTITY_UNKNOWN = 14] = &quot;Entity: unknown entity&quot;;
-XMLP._errs[XMLP.ERR_INFINITELOOP   = 15] = &quot;Infininte loop&quot;;
-XMLP._errs[XMLP.ERR_DOC_STRUCTURE  = 16] = &quot;Document: only comments, processing instructions, or whitespace allowed outside of document element&quot;;
-XMLP._errs[XMLP.ERR_ELM_NESTING    = 17] = &quot;Element: must be nested correctly&quot;;
-
-
-
-XMLP.prototype._addAttribute = function(name, value) {
-    this.m_atts[this.m_atts.length] = new Array(name, value);
-}  
-
-
-XMLP.prototype._checkStructure = function(iEvent) {
-  
-	if(XMLP._STATE_PROLOG == this.m_iState) {
-		if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
-            if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
-				return this._setErr(XMLP.ERR_DOC_STRUCTURE);
-            }
-        }
-
-        if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
-            this.m_iState = XMLP._STATE_DOCUMENT;
-            // Don't return - fall through to next state
-        }
-    }
-    if(XMLP._STATE_DOCUMENT == this.m_iState) {
-        if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
-            this.m_stack.push(this.getName());
-        }
-
-        if((XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent)) {
-            var strTop = this.m_stack.pop();
-            if((strTop == null) || (strTop != this.getName())) {
-                return this._setErr(XMLP.ERR_ELM_NESTING);
-            }
-        }
-
-        if(this.m_stack.count() == 0) {
-            this.m_iState = XMLP._STATE_MISC;
-            return iEvent;
-        }
-    }
-    if(XMLP._STATE_MISC == this.m_iState) {
-		if((XMLP._ELM_B == iEvent) || (XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent) || (XMLP.EVT_DTD == iEvent)) {
-			return this._setErr(XMLP.ERR_DOC_STRUCTURE);
-        }
-
-        if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
-			if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
-				return this._setErr(XMLP.ERR_DOC_STRUCTURE);
-            }
-        }
-    }
-
-    return iEvent;
-
-}  
-
-
-XMLP.prototype._clearAttributes = function() {
-    this.m_atts = new Array();
-}  
-
-
-XMLP.prototype._findAttributeIndex = function(name) {
-    for(var i = 0; i &lt; this.m_atts.length; i++) {
-        if(this.m_atts[i][XMLP._ATT_NAME] == name) {
-            return i;
-        }
-    }
-    return -1;
-
-}  
-
-
-XMLP.prototype.getAttributeCount = function() {
-
-    return this.m_atts ? this.m_atts.length : 0;
-
-}  
-
-
-XMLP.prototype.getAttributeName = function(index) {
-
-    return ((index &lt; 0) || (index &gt;= this.m_atts.length)) ? null : this.m_atts[index][XMLP._ATT_NAME];
-
-}  
-
-
-XMLP.prototype.getAttributeValue = function(index) {
-
-    return ((index &lt; 0) || (index &gt;= this.m_atts.length)) ? null : __unescapeXML__(this.m_atts[index][XMLP._ATT_VAL]);
-
-} 
-
-
-XMLP.prototype.getAttributeValueByName = function(name) {
-
-    return this.getAttributeValue(this._findAttributeIndex(name));
-
-}  
-
-
-XMLP.prototype.getColumnNumber = function() {
-
-    return SAXStrings.getColumnNumber(this.m_xml, this.m_iP);
-
-}  
-
-
-XMLP.prototype.getContent = function() {
-
-    return (this.m_cSrc == XMLP._CONT_XML) ? this.m_xml : this.m_cAlt;
-
-}  
-
-
-XMLP.prototype.getContentBegin = function() {
-
-    return this.m_cB;
-
-}  
-
-
-XMLP.prototype.getContentEnd = function() {
-
-    return this.m_cE;
-
-}  
-
-
-XMLP.prototype.getLineNumber = function() {
-
-    return SAXStrings.getLineNumber(this.m_xml, this.m_iP);
-
-}  
-
-
-XMLP.prototype.getName = function() {
-
-    return this.m_name;
-
-}  
-
-
-XMLP.prototype.next = function() {
-
-    return this._checkStructure(this._parse());
-
-} 
-
-
-XMLP.prototype._parse = function() {
-
-	if(this.m_iP == this.m_xml.length) {
-        return XMLP._NONE;
-    }
-
-    if(this.m_iP == this.m_xml.indexOf(&quot;&lt;?&quot;,        this.m_iP)) {
-        return this._parsePI     (this.m_iP + 2);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;!DOCTYPE&quot;, this.m_iP)) {
-        return this._parseDTD    (this.m_iP + 9);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;!--&quot;,      this.m_iP)) {
-        return this._parseComment(this.m_iP + 4);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;![CDATA[&quot;, this.m_iP)) {
-        return this._parseCDATA  (this.m_iP + 9);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;&quot;,         this.m_iP)) {
-        return this._parseElement(this.m_iP + 1);
-    }
-    else if(this.m_iP == this.m_xml.indexOf(&quot;&amp;&quot;,         this.m_iP)) {
-        return this._parseEntity (this.m_iP + 1);
-    }
-    else{
-        return this._parseText   (this.m_iP);
-    }
-	
-
-} 
-
-
-XMLP.prototype._parseAttribute = function(iB, iE) {
-    var iNB, iNE, iEq, iVB, iVE;
-    var cQuote, strN, strV;
-
-	this.m_cAlt = &quot;&quot;; //resets the value so we don't use an old one by accident (see testAttribute7 in the test suite)
-    
-	iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
-    if((iNB == -1) ||(iNB &gt;= iE)) {
-        return iNB;
-    }
-
-    iEq = this.m_xml.indexOf(&quot;=&quot;, iNB);
-    if((iEq == -1) || (iEq &gt; iE)) {
-        return this._setErr(XMLP.ERR_ATT_VALUES);
-    }
-
-    iNE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iNB, iEq);
-
-    iVB = SAXStrings.indexOfNonWhitespace(this.m_xml, iEq + 1, iE);
-    if((iVB == -1) ||(iVB &gt; iE)) {
-        return this._setErr(XMLP.ERR_ATT_VALUES);
-    }
-
-    cQuote = this.m_xml.charAt(iVB);
-    if(SAXStrings.QUOTES.indexOf(cQuote) == -1) {
-        return this._setErr(XMLP.ERR_ATT_VALUES);
-    }
-
-    iVE = this.m_xml.indexOf(cQuote, iVB + 1);
-    if((iVE == -1) ||(iVE &gt; iE)) {
-        return this._setErr(XMLP.ERR_ATT_VALUES);
-    }
-
-    strN = this.m_xml.substring(iNB, iNE + 1);
-    strV = this.m_xml.substring(iVB + 1, iVE);
-
-    if(strN.indexOf(&quot;&lt;&quot;) != -1) {
-        return this._setErr(XMLP.ERR_ATT_LT_NAME);
-    }
-
-    if(strV.indexOf(&quot;&lt;&quot;) != -1) {
-        return this._setErr(XMLP.ERR_ATT_LT_VALUE);
-    }
-
-    strV = SAXStrings.replace(strV, null, null, &quot;\n&quot;, &quot; &quot;);
-    strV = SAXStrings.replace(strV, null, null, &quot;\t&quot;, &quot; &quot;);
-	iRet = this._replaceEntities(strV);
-    if(iRet == XMLP._ERROR) {
-        return iRet;
-    }
-
-    strV = this.m_cAlt;
-
-    if(this._findAttributeIndex(strN) == -1) {
-        this._addAttribute(strN, strV);
-    }
-    else {
-        return this._setErr(XMLP.ERR_ATT_DUP);
-    }
-
-    this.m_iP = iVE + 2;
-
-    return XMLP._ATT;
-
-}  
-
-
-XMLP.prototype._parseCDATA = function(iB) {
-    var iE = this.m_xml.indexOf(&quot;]]&gt;&quot;, iB);
-    if (iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_CDATA);
-    }
-
-    this._setContent(XMLP._CONT_XML, iB, iE);
-
-    this.m_iP = iE + 3;
-
-    return XMLP._CDATA;
-
-}  
-
-
-XMLP.prototype._parseComment = function(iB) {
-    var iE = this.m_xml.indexOf(&quot;-&quot; + &quot;-&gt;&quot;, iB);
-    if (iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_COMMENT);
-    }
-
-    this._setContent(XMLP._CONT_XML, iB, iE);
-
-    this.m_iP = iE + 3;
-
-    return XMLP._COMMENT;
-
-}  
-
-
-XMLP.prototype._parseDTD = function(iB) {
-
-    // Eat DTD
-
-    var iE, strClose, iInt, iLast;
-
-    iE = this.m_xml.indexOf(&quot;&gt;&quot;, iB);
-    if(iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_DTD);
-    }
-
-    iInt = this.m_xml.indexOf(&quot;[&quot;, iB);
-    strClose = ((iInt != -1) &amp;&amp; (iInt &lt; iE)) ? &quot;]&gt;&quot; : &quot;&gt;&quot;;
-
-    while(true) {
-        // DEBUG: Remove
-        if(iE == iLast) {
-            return this._setErr(XMLP.ERR_INFINITELOOP);
-        }
-
-        iLast = iE;
-        // DEBUG: Remove End
-
-        iE = this.m_xml.indexOf(strClose, iB);
-        if(iE == -1) {
-            return this._setErr(XMLP.ERR_CLOSE_DTD);
-        }
-
-        // Make sure it is not the end of a CDATA section
-        if (this.m_xml.substring(iE - 1, iE + 2) != &quot;]]&gt;&quot;) {
-            break;
-        }
-    }
-
-    this.m_iP = iE + strClose.length;
-
-    return XMLP._DTD;
-
-}  
-
-
-XMLP.prototype._parseElement = function(iB) {
-    var iE, iDE, iNE, iRet;
-    var iType, strN, iLast;
-
-    iDE = iE = this.m_xml.indexOf(&quot;&gt;&quot;, iB);
-    if(iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_ELM);
-    }
-
-    if(this.m_xml.charAt(iB) == &quot;/&quot;) {
-        iType = XMLP._ELM_E;
-        iB++;
-    } else {
-        iType = XMLP._ELM_B;
-    }
-
-    if(this.m_xml.charAt(iE - 1) == &quot;/&quot;) {
-        if(iType == XMLP._ELM_E) {
-            return this._setErr(XMLP.ERR_ELM_EMPTY);
-        }
-        iType = XMLP._ELM_EMP;
-        iDE--;
-    }
-
-    iDE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iB, iDE);
-
-    //djohack
-    //hack to allow for elements with single character names to be recognized
-
-    if (iE - iB != 1 ) {
-        if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB) {
-            return this._setErr(XMLP.ERR_ELM_NAME);
-        }
-    }
-    // end hack -- original code below
-
-    /*
-    if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB)
-        return this._setErr(XMLP.ERR_ELM_NAME);
-    */
-    this._clearAttributes();
-
-    iNE = SAXStrings.indexOfWhitespace(this.m_xml, iB, iDE);
-    if(iNE == -1) {
-        iNE = iDE + 1;
-    }
-    else {
-        this.m_iP = iNE;
-        while(this.m_iP &lt; iDE) {
-            // DEBUG: Remove
-            if(this.m_iP == iLast) return this._setErr(XMLP.ERR_INFINITELOOP);
-            iLast = this.m_iP;
-            // DEBUG: Remove End
-
-
-            iRet = this._parseAttribute(this.m_iP, iDE);
-            if(iRet == XMLP._ERROR) return iRet;
-        }
-    }
-
-    strN = this.m_xml.substring(iB, iNE);
-
-    if(strN.indexOf(&quot;&lt;&quot;) != -1) {
-        return this._setErr(XMLP.ERR_ELM_LT_NAME);
-    }
-
-    this.m_name = strN;
-    this.m_iP = iE + 1;
-
-    return iType;
-
-}  
-
-
-XMLP.prototype._parseEntity = function(iB) {
-    var iE = this.m_xml.indexOf(&quot;;&quot;, iB);
-    if(iE == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_ENTITY);
-    }
-
-    this.m_iP = iE + 1;
-
-    return this._replaceEntity(this.m_xml, iB, iE);
-
-} 
-
-
-XMLP.prototype._parsePI = function(iB) {
-
-    var iE, iTB, iTE, iCB, iCE;
-
-    iE = this.m_xml.indexOf(&quot;?&gt;&quot;, iB);
-    if(iE   == -1) {
-        return this._setErr(XMLP.ERR_CLOSE_PI);
-    }
-
-    iTB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
-    if(iTB == -1) {
-        return this._setErr(XMLP.ERR_PI_TARGET);
-    }
-
-    iTE = SAXStrings.indexOfWhitespace(this.m_xml, iTB, iE);
-    if(iTE  == -1) {
-        iTE = iE;
-    }
-
-    iCB = SAXStrings.indexOfNonWhitespace(this.m_xml, iTE, iE);
-    if(iCB == -1) {
-        iCB = iE;
-    }
-
-    iCE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iCB, iE);
-    if(iCE  == -1) {
-        iCE = iE - 1;
-    }
-
-    this.m_name = this.m_xml.substring(iTB, iTE);
-    this._setContent(XMLP._CONT_XML, iCB, iCE + 1);
-    this.m_iP = iE + 2;
-
-    return XMLP._PI;
-
-}  
-
-
-XMLP.prototype._parseText = function(iB) {
-    var iE, iEE;
-
-    iE = this.m_xml.indexOf(&quot;&lt;&quot;, iB);
-    if(iE == -1) {
-        iE = this.m_xml.length;
-    }
-
-    iEE = this.m_xml.indexOf(&quot;&amp;&quot;, iB);
-    if((iEE != -1) &amp;&amp; (iEE &lt;= iE)) {
-        iE = iEE;
-    }
-
-    this._setContent(XMLP._CONT_XML, iB, iE);
-
-    this.m_iP = iE;
-
-    return XMLP._TEXT;
-
-} 
-
-
-XMLP.prototype._replaceEntities = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) return &quot;&quot;;
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-
-    var iEB, iEE, strRet = &quot;&quot;;
-
-    iEB = strD.indexOf(&quot;&amp;&quot;, iB);
-    iEE = iB;
-
-    while((iEB &gt; 0) &amp;&amp; (iEB &lt; iE)) {
-        strRet += strD.substring(iEE, iEB);
-
-        iEE = strD.indexOf(&quot;;&quot;, iEB) + 1;
-
-        if((iEE == 0) || (iEE &gt; iE)) {
-            return this._setErr(XMLP.ERR_CLOSE_ENTITY);
-        }
-
-        iRet = this._replaceEntity(strD, iEB + 1, iEE - 1);
-        if(iRet == XMLP._ERROR) {
-            return iRet;
-        }
-
-        strRet += this.m_cAlt;
-
-        iEB = strD.indexOf(&quot;&amp;&quot;, iEE);
-    }
-
-    if(iEE != iE) {
-        strRet += strD.substring(iEE, iE);
-    }
-
-    this._setContent(XMLP._CONT_ALT, strRet);
-
-    return XMLP._ENTITY;
-
-}  
-
-
-XMLP.prototype._replaceEntity = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) return -1;
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    switch(strD.substring(iB, iE)) {
-        case &quot;amp&quot;:  strEnt = &quot;&amp;&quot;;  break;
-        case &quot;lt&quot;:   strEnt = &quot;&lt;&quot;;  break;
-        case &quot;gt&quot;:   strEnt = &quot;&gt;&quot;;  break;
-        case &quot;apos&quot;: strEnt = &quot;'&quot;;  break;
-        case &quot;quot&quot;: strEnt = &quot;\&quot;&quot;; break;
-        default:
-            if(strD.charAt(iB) == &quot;#&quot;) {
-                strEnt = String.fromCharCode(parseInt(strD.substring(iB + 1, iE)));
-            } else {
-                return this._setErr(XMLP.ERR_ENTITY_UNKNOWN);
-            }
-        break;
-    }
-    this._setContent(XMLP._CONT_ALT, strEnt);
-
-    return XMLP._ENTITY;
-}  
-
-
-XMLP.prototype._setContent = function(iSrc) {
-    var args = arguments;
-
-    if(XMLP._CONT_XML == iSrc) {
-        this.m_cAlt = null;
-        this.m_cB = args[1];
-        this.m_cE = args[2];
-    } else {
-        this.m_cAlt = args[1];
-        this.m_cB = 0;
-        this.m_cE = args[1].length;
-    }
-    this.m_cSrc = iSrc;
-
-}  
-
-
-XMLP.prototype._setErr = function(iErr) {
-    var strErr = XMLP._errs[iErr];
-
-    this.m_cAlt = strErr;
-    this.m_cB = 0;
-    this.m_cE = strErr.length;
-    this.m_cSrc = XMLP._CONT_ALT;
-
-    return XMLP._ERROR;
-
-}  
-
-
-/**
-* function:   SAXDriver
-* Author:   Scott Severtson
-* Description:
-*    SAXDriver is an object that basically wraps an XMLP instance, and provides an
-*   event-based interface for parsing. This is the object users interact with when coding
-*   with XML for &lt;SCRIPT&gt;
-**/
-
-var SAXDriver = function() {
-    this.m_hndDoc = null;
-    this.m_hndErr = null;
-    this.m_hndLex = null;
-}
-
-
-// CONSTANTS
-SAXDriver.DOC_B = 1;
-SAXDriver.DOC_E = 2;
-SAXDriver.ELM_B = 3;
-SAXDriver.ELM_E = 4;
-SAXDriver.CHARS = 5;
-SAXDriver.PI    = 6;
-SAXDriver.CD_B  = 7;
-SAXDriver.CD_E  = 8;
-SAXDriver.CMNT  = 9;
-SAXDriver.DTD_B = 10;
-SAXDriver.DTD_E = 11;
-
-
-
-SAXDriver.prototype.parse = function(strD) {
-    var parser = new XMLP(strD);
-
-    if(this.m_hndDoc &amp;&amp; this.m_hndDoc.setDocumentLocator) {
-        this.m_hndDoc.setDocumentLocator(this);
-    }
-
-    this.m_parser = parser;
-    this.m_bErr = false;
-
-    if(!this.m_bErr) {
-        this._fireEvent(SAXDriver.DOC_B);
-    }
-    this._parseLoop();
-    if(!this.m_bErr) {
-        this._fireEvent(SAXDriver.DOC_E);
-    }
-
-    this.m_xml = null;
-    this.m_iP = 0;
-
-}  
-
-
-SAXDriver.prototype.setDocumentHandler = function(hnd) {
-
-    this.m_hndDoc = hnd;
-
-}   
-
-
-SAXDriver.prototype.setErrorHandler = function(hnd) {
-
-    this.m_hndErr = hnd;
-
-}  
-
-
-SAXDriver.prototype.setLexicalHandler = function(hnd) {
-
-    this.m_hndLex = hnd;
-
-}  
-
-
-    /**
-    * LOCATOR/PARSE EXCEPTION INTERFACE
-    ***/
-
-SAXDriver.prototype.getColumnNumber = function() {
-
-    return this.m_parser.getColumnNumber();
-
-}
-
-
-SAXDriver.prototype.getLineNumber = function() {
-
-    return this.m_parser.getLineNumber();
-
-}
-
-
-SAXDriver.prototype.getMessage = function() {
-
-    return this.m_strErrMsg;
-
-}
-
-
-SAXDriver.prototype.getPublicId = function() {
-
-    return null;
-
-}  
-
-
-SAXDriver.prototype.getSystemId = function() {
-
-    return null;
-
-}  
-
-
-    /***
-    * Attribute List Interface
-    **/
-
-SAXDriver.prototype.getLength = function() {
-
-    return this.m_parser.getAttributeCount();
-
-}  
-
-
-SAXDriver.prototype.getName = function(index) {
-
-    return this.m_parser.getAttributeName(index);
-
-} 
-
-
-SAXDriver.prototype.getValue = function(index) {
-
-    return this.m_parser.getAttributeValue(index);
-
-}  
-
-
-SAXDriver.prototype.getValueByName = function(name) {
-
-    return this.m_parser.getAttributeValueByName(name);
-
-} 
-
-
-    /***
-    *    Private functions
-    **/
-
-SAXDriver.prototype._fireError = function(strMsg) {
-    this.m_strErrMsg = strMsg;
-    this.m_bErr = true;
-
-    if(this.m_hndErr &amp;&amp; this.m_hndErr.fatalError) {
-        this.m_hndErr.fatalError(this);
-    }
-
-}   // end function _fireError
-
-
-SAXDriver.prototype._fireEvent = function(iEvt) {
-    var hnd, func, args = arguments, iLen = args.length - 1;
-
-    if(this.m_bErr) return;
-
-    if(SAXDriver.DOC_B == iEvt) {
-        func = &quot;startDocument&quot;;         hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.DOC_E == iEvt) {
-        func = &quot;endDocument&quot;;           hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.ELM_B == iEvt) {
-        func = &quot;startElement&quot;;          hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.ELM_E == iEvt) {
-        func = &quot;endElement&quot;;            hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.CHARS == iEvt) {
-        func = &quot;characters&quot;;            hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.PI    == iEvt) {
-        func = &quot;processingInstruction&quot;; hnd = this.m_hndDoc;
-    }
-    else if (SAXDriver.CD_B  == iEvt) {
-        func = &quot;startCDATA&quot;;            hnd = this.m_hndLex;
-    }
-    else if (SAXDriver.CD_E  == iEvt) {
-        func = &quot;endCDATA&quot;;              hnd = this.m_hndLex;
-    }
-    else if (SAXDriver.CMNT  == iEvt) {
-        func = &quot;comment&quot;;               hnd = this.m_hndLex;
-    }
-
-    if(hnd &amp;&amp; hnd[func]) {
-        if(0 == iLen) {
-            hnd[func]();
-        }
-        else if (1 == iLen) {
-            hnd[func](args[1]);
-        }
-        else if (2 == iLen) {
-            hnd[func](args[1], args[2]);
-        }
-        else if (3 == iLen) {
-            hnd[func](args[1], args[2], args[3]);
-        }
-    }
-
-}  // end function _fireEvent
-
-
-SAXDriver.prototype._parseLoop = function(parser) {
-    var iEvent, parser;
-
-    parser = this.m_parser;
-    while(!this.m_bErr) {
-        iEvent = parser.next();
-
-        if(iEvent == XMLP._ELM_B) {
-            this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
-        }
-        else if(iEvent == XMLP._ELM_E) {
-            this._fireEvent(SAXDriver.ELM_E, parser.getName());
-        }
-        else if(iEvent == XMLP._ELM_EMP) {
-            this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
-            this._fireEvent(SAXDriver.ELM_E, parser.getName());
-        }
-        else if(iEvent == XMLP._TEXT) {
-            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
-        }
-        else if(iEvent == XMLP._ENTITY) {
-            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
-        }
-        else if(iEvent == XMLP._PI) {
-            this._fireEvent(SAXDriver.PI, parser.getName(), parser.getContent().substring(parser.getContentBegin(), parser.getContentEnd()));
-        }
-        else if(iEvent == XMLP._CDATA) {
-            this._fireEvent(SAXDriver.CD_B);
-            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
-            this._fireEvent(SAXDriver.CD_E);
-        }
-        else if(iEvent == XMLP._COMMENT) {
-            this._fireEvent(SAXDriver.CMNT, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
-        }
-        else if(iEvent == XMLP._DTD) {
-        }
-        else if(iEvent == XMLP._ERROR) {
-            this._fireError(parser.getContent());
-        }
-        else if(iEvent == XMLP._NONE) {
-            return;
-        }
-    }
-
-}  // end function _parseLoop
-
-/**
-*   function:   SAXStrings
-*   Author:   Scott Severtson
-*   Description: a useful object containing string manipulation functions
-**/
-
-var SAXStrings = function() {};
-
-
-SAXStrings.WHITESPACE = &quot; \t\n\r&quot;;
-SAXStrings.QUOTES = &quot;\&quot;'&quot;;
-
-
-SAXStrings.getColumnNumber = function(strD, iP) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iP = iP || strD.length;
-
-    var arrD = strD.substring(0, iP).split(&quot;\n&quot;);
-    var strLine = arrD[arrD.length - 1];
-    arrD.length--;
-    var iLinePos = arrD.join(&quot;\n&quot;).length;
-
-    return iP - iLinePos;
-
-}  // end function getColumnNumber
-
-
-SAXStrings.getLineNumber = function(strD, iP) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iP = iP || strD.length;
-
-    return strD.substring(0, iP).split(&quot;\n&quot;).length
-}  // end function getLineNumber
-
-
-SAXStrings.indexOfNonWhitespace = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    for(var i = iB; i &lt; iE; i++){
-        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1) {
-            return i;
-        }
-    }
-    return -1;
-
-}  // end function indexOfNonWhitespace
-
-
-SAXStrings.indexOfWhitespace = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    for(var i = iB; i &lt; iE; i++) {
-        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) != -1) {
-            return i;
-        }
-    }
-    return -1;
-}  // end function indexOfWhitespace
-
-
-SAXStrings.isEmpty = function(strD) {
-
-    return (strD == null) || (strD.length == 0);
-
-}
-
-
-SAXStrings.lastIndexOfNonWhitespace = function(strD, iB, iE) {
-    if(SAXStrings.isEmpty(strD)) {
-        return -1;
-    }
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    for(var i = iE - 1; i &gt;= iB; i--){
-        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1){
-            return i;
-        }
-    }
-    return -1;
-}
-
-
-SAXStrings.replace = function(strD, iB, iE, strF, strR) {
-    if(SAXStrings.isEmpty(strD)) {
-        return &quot;&quot;;
-    }
-    iB = iB || 0;
-    iE = iE || strD.length;
-
-    return strD.substring(iB, iE).split(strF).join(strR);
-
-}
-
-
-
-/***************************************************************************************************************
-Stack: A simple stack class, used for verifying document structure.
-
-    Author:   Scott Severtson
-*****************************************************************************************************************/
-
-var Stack = function() {
-    this.m_arr = new Array();
-}; 
-__extend__(Stack.prototype, {
-    clear : function() {
-        this.m_arr = new Array();
-    },
-    count : function() {
-        return this.m_arr.length;
-    },
-    destroy : function() {
-        this.m_arr = null;
-    },
-    peek : function() {
-        if(this.m_arr.length == 0) {
-            return null;
-        }
-        return this.m_arr[this.m_arr.length - 1];
-    },
-    pop : function() {
-        if(this.m_arr.length == 0) {
-            return null;
-        }
-        var o = this.m_arr[this.m_arr.length - 1];
-        this.m_arr.length--;
-        return o;
-    },
-    push : function(o) {
-        this.m_arr[this.m_arr.length] = o;
-    }
-});    
-
-
-/**
-* function: isEmpty
-* Author: mike@idle.org
-* Description:  convenience function to identify an empty string
-**/
-function isEmpty(str) {
-    return (str==null) || (str.length==0);
-};
-
-
-/**
- * function __escapeXML__
- * author: David Joham djoham@yahoo.com
- * @param  str : string - The string to be escaped
- * @return : string - The escaped string
- */
-var escAmpRegEx = /&amp;/g;
-var escLtRegEx = /&lt;/g;
-var escGtRegEx = /&gt;/g;
-var quotRegEx = /&quot;/g;
-var aposRegEx = /'/g;
-function __escapeXML__(str) {
-    str = str.replace(escAmpRegEx, &quot;&amp;amp;&quot;).
-            replace(escLtRegEx, &quot;&amp;lt;&quot;).
-            replace(escGtRegEx, &quot;&amp;gt;&quot;).
-            replace(quotRegEx, &quot;&amp;quot;&quot;).
-            replace(aposRegEx, &quot;&amp;apos;&quot;);
-
-    return str;
-};
-
-/**
- * function __unescapeXML__ 
- * author: David Joham djoham@yahoo.com
- * @param  str : string - The string to be unescaped
- * @return : string - The unescaped string
- */
-var unescAmpRegEx = /&amp;amp;/g;
-var unescLtRegEx = /&amp;lt;/g;
-var unescGtRegEx = /&amp;gt;/g;
-var unquotRegEx = /&amp;quot;/g;
-var unaposRegEx = /&amp;apos;/g;
-function __unescapeXML__(str) {
-    str = str.replace(unescAmpRegEx, &quot;&amp;&quot;).
-            replace(unescLtRegEx, &quot;&lt;&quot;).
-            replace(unescGtRegEx, &quot;&gt;&quot;).
-            replace(unquotRegEx, &quot;\&quot;&quot;).
-            replace(unaposRegEx, &quot;'&quot;);
-
-    return str;
-};
-
-//DOMImplementation
-$log(&quot;Defining DOMImplementation&quot;);
-$w.__defineGetter__(&quot;DOMImplementation&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMImplementation - provides a number of methods for performing operations
- *   that are independent of any particular instance of the document object model.
- *
- * @author Jon van Noort (jon@webarcana.com.au)
- */
-var DOMImplementation = function() {
-    this.preserveWhiteSpace = false;  // by default, ignore whitespace
-    this.namespaceAware = true;       // by default, handle namespaces
-    this.errorChecking  = true;       // by default, test for exceptions
-};
-__extend__(DOMImplementation.prototype,{
-    // @param  feature : string - The package name of the feature to test. 
-    //      the legal only values are &quot;XML&quot; and &quot;CORE&quot; (case-insensitive).
-    // @param  version : string - This is the version number of the package
-    //       name to test. In Level 1, this is the string &quot;1.0&quot;.*
-    // @return : boolean
-    hasFeature : function(feature, version) {
-        var ret = false;
-        if (feature.toLowerCase() == &quot;xml&quot;) {
-            ret = (!version || (version == &quot;1.0&quot;) || (version == &quot;2.0&quot;));
-        }
-        else if (feature.toLowerCase() == &quot;core&quot;) {
-            ret = (!version || (version == &quot;2.0&quot;));
-        }
-        return ret;
-    },
-	createDocumentType : function(qname, publicid, systemid){
-		return new DOMDocumentType();
-	},
-	createDocument : function(nsuri, qname, doctype){
-	  //TODO - this currently returns an empty doc
-	  //but needs to handle the args
-		return new HTMLDocument($implementation);
-	},
-    translateErrCode : function(code) {
-        //convert DOMException Code to human readable error message;
-      var msg = &quot;&quot;;
-    
-      switch (code) {
-        case DOMException.INDEX_SIZE_ERR :                // 1
-           msg = &quot;INDEX_SIZE_ERR: Index out of bounds&quot;;
-           break;
-    
-        case DOMException.DOMSTRING_SIZE_ERR :            // 2
-           msg = &quot;DOMSTRING_SIZE_ERR: The resulting string is too long to fit in a DOMString&quot;;
-           break;
-    
-        case DOMException.HIERARCHY_REQUEST_ERR :         // 3
-           msg = &quot;HIERARCHY_REQUEST_ERR: The Node can not be inserted at this location&quot;;
-           break;
-    
-        case DOMException.WRONG_DOCUMENT_ERR :            // 4
-           msg = &quot;WRONG_DOCUMENT_ERR: The source and the destination Documents are not the same&quot;;
-           break;
-    
-        case DOMException.INVALID_CHARACTER_ERR :         // 5
-           msg = &quot;INVALID_CHARACTER_ERR: The string contains an invalid character&quot;;
-           break;
-    
-        case DOMException.NO_DATA_ALLOWED_ERR :           // 6
-           msg = &quot;NO_DATA_ALLOWED_ERR: This Node / NodeList does not support data&quot;;
-           break;
-    
-        case DOMException.NO_MODIFICATION_ALLOWED_ERR :   // 7
-           msg = &quot;NO_MODIFICATION_ALLOWED_ERR: This object cannot be modified&quot;;
-           break;
-    
-        case DOMException.NOT_FOUND_ERR :                 // 8
-           msg = &quot;NOT_FOUND_ERR: The item cannot be found&quot;;
-           break;
-    
-        case DOMException.NOT_SUPPORTED_ERR :             // 9
-           msg = &quot;NOT_SUPPORTED_ERR: This implementation does not support function&quot;;
-           break;
-    
-        case DOMException.INUSE_ATTRIBUTE_ERR :           // 10
-           msg = &quot;INUSE_ATTRIBUTE_ERR: The Attribute has already been assigned to another Element&quot;;
-           break;
-    
-        // Introduced in DOM Level 2:
-        case DOMException.INVALID_STATE_ERR :             // 11
-           msg = &quot;INVALID_STATE_ERR: The object is no longer usable&quot;;
-           break;
-    
-        case DOMException.SYNTAX_ERR :                    // 12
-           msg = &quot;SYNTAX_ERR: Syntax error&quot;;
-           break;
-    
-        case DOMException.INVALID_MODIFICATION_ERR :      // 13
-           msg = &quot;INVALID_MODIFICATION_ERR: Cannot change the type of the object&quot;;
-           break;
-    
-        case DOMException.NAMESPACE_ERR :                 // 14
-           msg = &quot;NAMESPACE_ERR: The namespace declaration is incorrect&quot;;
-           break;
-    
-        case DOMException.INVALID_ACCESS_ERR :            // 15
-           msg = &quot;INVALID_ACCESS_ERR: The object does not support this function&quot;;
-           break;
-    
-        default :
-           msg = &quot;UNKNOWN: Unknown Exception Code (&quot;+ code +&quot;)&quot;;
-      }
-    
-      return msg;
-    }
-});
-  
-
-/**
-* Defined 'globally' to this scope.  Remember everything is wrapped in a closure so this doesnt show up 
-* in the outer most global scope.
-*/
-  
-/**
- *  process SAX events
- *
- * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
- *
- * @param  impl : DOMImplementation
- * @param  doc : DOMDocument - the Document to contain the parsed XML string
- * @param  p   : XMLP        - the SAX Parser
- *
- * @return : DOMDocument
- */
-function __parseLoop__(impl, doc, p) {
-  var iEvt, iNode, iAttr, strName;
-  iNodeParent = doc;
-
-  var el_close_count = 0;
-
-  var entitiesList = new Array();
-  var textNodesList = new Array();
-
-  // if namespaceAware, add default namespace
-  if (impl.namespaceAware) {
-    var iNS = doc.createNamespace(&quot;&quot;); // add the default-default namespace
-    iNS.value = &quot;http://www.w3.org/2000/xmlns/&quot;;
-    doc._namespaces.setNamedItem(iNS);
-  }
-
-  // loop until SAX parser stops emitting events
-  while(true) {
-    // get next event
-    iEvt = p.next();
-
-    if (iEvt == XMLP._ELM_B) {                      // Begin-Element Event
-      var pName = p.getName();                      // get the Element name
-      pName = trim(pName, true, true);              // strip spaces from Element name
-
-      if (!impl.namespaceAware) {
-        iNode = doc.createElement(p.getName());     // create the Element
-
-        // add attributes to Element
-        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
-          strName = p.getAttributeName(i);          // get Attribute name
-          iAttr = iNode.getAttributeNode(strName);  // if Attribute exists, use it
-
-          if(!iAttr) {
-            iAttr = doc.createAttribute(strName);   // otherwise create it
-          }
-
-          iAttr.value = p.getAttributeValue(i);   // set Attribute value
-          iNode.setAttributeNode(iAttr);            // attach Attribute to Element
-        }
-      }
-      else {  // Namespace Aware
-        // create element (with empty namespaceURI,
-        //  resolve after namespace 'attributes' have been parsed)
-        iNode = doc.createElementNS(&quot;&quot;, p.getName());
-
-        // duplicate ParentNode's Namespace definitions
-        iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
-
-        // add attributes to Element
-        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
-          strName = p.getAttributeName(i);          // get Attribute name
-
-          // if attribute is a namespace declaration
-          if (__isNamespaceDeclaration__(strName)) {
-            // parse Namespace Declaration
-            var namespaceDec = __parseNSName__(strName);
-
-            if (strName != &quot;xmlns&quot;) {
-              iNS = doc.createNamespace(strName);   // define namespace
-            }
-            else {
-              iNS = doc.createNamespace(&quot;&quot;);        // redefine default namespace
-            }
-            iNS.value = p.getAttributeValue(i);   // set value = namespaceURI
-
-            iNode._namespaces.setNamedItem(iNS);    // attach namespace to namespace collection
-          }
-          else {  // otherwise, it is a normal attribute
-            iAttr = iNode.getAttributeNode(strName);        // if Attribute exists, use it
-
-            if(!iAttr) {
-              iAttr = doc.createAttributeNS(&quot;&quot;, strName);   // otherwise create it
-            }
-
-            iAttr.value = p.getAttributeValue(i);         // set Attribute value
-            iNode.setAttributeNodeNS(iAttr);                // attach Attribute to Element
-
-            if (__isIdDeclaration__(strName)) {
-              iNode.id = p.getAttributeValue(i);    // cache ID for getElementById()
-            }
-          }
-        }
-
-        // resolve namespaceURIs for this Element
-        if (iNode._namespaces.getNamedItem(iNode.prefix)) {
-          iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
-        }
-
-        //  for this Element's attributes
-        for (var i = 0; i &lt; iNode.attributes.length; i++) {
-          if (iNode.attributes.item(i).prefix != &quot;&quot;) {  // attributes do not have a default namespace
-            if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
-              iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
-            }
-          }
-        }
-      }
-
-      // if this is the Root Element
-      if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
-        iNodeParent.documentElement = iNode;        // register this Element as the Document.documentElement
-      }
-
-      iNodeParent.appendChild(iNode);               // attach Element to parentNode
-      iNodeParent = iNode;                          // descend one level of the DOM Tree
-    }
-
-    else if(iEvt == XMLP._ELM_E) {                  // End-Element Event
-      iNodeParent = iNodeParent.parentNode;         // ascend one level of the DOM Tree
-    }
-
-    else if(iEvt == XMLP._ELM_EMP) {                // Empty Element Event
-      pName = p.getName();                          // get the Element name
-      pName = trim(pName, true, true);              // strip spaces from Element name
-
-      if (!impl.namespaceAware) {
-        iNode = doc.createElement(pName);           // create the Element
-
-        // add attributes to Element
-        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
-          strName = p.getAttributeName(i);          // get Attribute name
-          iAttr = iNode.getAttributeNode(strName);  // if Attribute exists, use it
-
-          if(!iAttr) {
-            iAttr = doc.createAttribute(strName);   // otherwise create it
-          }
-
-          iAttr.value = p.getAttributeValue(i);   // set Attribute value
-          iNode.setAttributeNode(iAttr);            // attach Attribute to Element
-        }
-      }
-      else {  // Namespace Aware
-        // create element (with empty namespaceURI,
-        //  resolve after namespace 'attributes' have been parsed)
-        iNode = doc.createElementNS(&quot;&quot;, p.getName());
-
-        // duplicate ParentNode's Namespace definitions
-        iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
-
-        // add attributes to Element
-        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
-          strName = p.getAttributeName(i);          // get Attribute name
-
-          // if attribute is a namespace declaration
-          if (__isNamespaceDeclaration__(strName)) {
-            // parse Namespace Declaration
-            var namespaceDec = __parseNSName__(strName);
-
-            if (strName != &quot;xmlns&quot;) {
-              iNS = doc.createNamespace(strName);   // define namespace
-            }
-            else {
-              iNS = doc.createNamespace(&quot;&quot;);        // redefine default namespace
-            }
-            iNS.value = p.getAttributeValue(i);   // set value = namespaceURI
-
-            iNode._namespaces.setNamedItem(iNS);    // attach namespace to namespace collection
-          }
-          else {  // otherwise, it is a normal attribute
-            iAttr = iNode.getAttributeNode(strName);        // if Attribute exists, use it
-
-            if(!iAttr) {
-              iAttr = doc.createAttributeNS(&quot;&quot;, strName);   // otherwise create it
-            }
-
-            iAttr.value = p.getAttributeValue(i);         // set Attribute value
-            iNode.setAttributeNodeNS(iAttr);                // attach Attribute to Element
-
-            if (__isIdDeclaration__(strName)) {
-              iNode.id = p.getAttributeValue(i);    // cache ID for getElementById()
-            }
-          }
-        }
-
-        // resolve namespaceURIs for this Element
-        if (iNode._namespaces.getNamedItem(iNode.prefix)) {
-          iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
-        }
-
-        //  for this Element's attributes
-        for (var i = 0; i &lt; iNode.attributes.length; i++) {
-          if (iNode.attributes.item(i).prefix != &quot;&quot;) {  // attributes do not have a default namespace
-            if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
-              iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
-            }
-          }
-        }
-      }
-
-      // if this is the Root Element
-      if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
-        iNodeParent.documentElement = iNode;        // register this Element as the Document.documentElement
-      }
-
-      iNodeParent.appendChild(iNode);               // attach Element to parentNode
-    }
-    else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) {                   // TextNode and entity Events
-      // get Text content
-      var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
-      
-	  if (!impl.preserveWhiteSpace ) {
-		if (trim(pContent, true, true) == &quot;&quot;) {
-			pContent = &quot;&quot;; //this will cause us not to create the text node below
-		}
-	  }
-	  
-      if (pContent.length &gt; 0) {                    // ignore empty TextNodes
-        var textNode = doc.createTextNode(pContent);
-        iNodeParent.appendChild(textNode); // attach TextNode to parentNode
-
-        //the sax parser breaks up text nodes when it finds an entity. For
-        //example hello&amp;lt;there will fire a text, an entity and another text
-        //this sucks for the dom parser because it looks to us in this logic
-        //as three text nodes. I fix this by keeping track of the entity nodes
-        //and when we're done parsing, calling normalize on their parent to
-        //turn the multiple text nodes into one, which is what DOM users expect
-        //the code to do this is at the bottom of this function
-        if (iEvt == XMLP._ENTITY) {
-            entitiesList[entitiesList.length] = textNode;
-        }
-		else {
-			//I can't properly decide how to handle preserve whitespace
-			//until the siblings of the text node are built due to 
-			//the entitiy handling described above. I don't know that this
-			//will be all of the text node or not, so trimming is not appropriate
-			//at this time. Keep a list of all the text nodes for now
-			//and we'll process the preserve whitespace stuff at a later time.
-			textNodesList[textNodesList.length] = textNode;
-		}
-      }
-    }
-    else if(iEvt == XMLP._PI) {                     // ProcessingInstruction Event
-      // attach ProcessingInstruction to parentNode
-      iNodeParent.appendChild(doc.createProcessingInstruction(p.getName(), p.getContent().substring(p.getContentBegin(), p.getContentEnd())));
-    }
-    else if(iEvt == XMLP._CDATA) {                  // CDATA Event
-      // get CDATA data
-      pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
-
-      if (!impl.preserveWhiteSpace) {
-        pContent = trim(pContent, true, true);      // trim whitespace
-        pContent.replace(/ +/g, ' ');               // collapse multiple spaces to 1 space
-      }
-
-      if (pContent.length &gt; 0) {                    // ignore empty CDATANodes
-        iNodeParent.appendChild(doc.createCDATASection(pContent)); // attach CDATA to parentNode
-      }
-    }
-    else if(iEvt == XMLP._COMMENT) {                // Comment Event
-      // get COMMENT data
-      var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
-
-      if (!impl.preserveWhiteSpace) {
-        pContent = trim(pContent, true, true);      // trim whitespace
-        pContent.replace(/ +/g, ' ');               // collapse multiple spaces to 1 space
-      }
-
-      if (pContent.length &gt; 0) {                    // ignore empty CommentNodes
-        iNodeParent.appendChild(doc.createComment(pContent));  // attach Comment to parentNode
-      }
-    }
-    else if(iEvt == XMLP._DTD) {                    // ignore DTD events
-    }
-    else if(iEvt == XMLP._ERROR) {
-      throw(new DOMException(DOMException.SYNTAX_ERR));
-      // alert(&quot;Fatal Error: &quot; + p.getContent() + &quot;\nLine: &quot; + p.getLineNumber() + &quot;\nColumn: &quot; + p.getColumnNumber() + &quot;\n&quot;);
-      // break;
-    }
-    else if(iEvt == XMLP._NONE) {                   // no more events
-      if (iNodeParent == doc) {                     // confirm that we have recursed back up to root
-        break;
-      }
-      else {
-        throw(new DOMException(DOMException.SYNTAX_ERR));  // one or more Tags were not closed properly
-      }
-    }
-  }
-
-  //normalize any entities in the DOM to a single textNode
-  for (var i = 0; i &lt; entitiesList.length; i++) {
-      var entity = entitiesList[i];
-      //its possible (if for example two entities were in the
-      //same domnode, that the normalize on the first entitiy
-      //will remove the parent for the second. Only do normalize
-      //if I can find a parent node
-      var parentNode = entity.parentNode;
-      if (parentNode) {
-          parentNode.normalize();
-		  
-		  //now do whitespace (if necessary)
-		  //it was not done for text nodes that have entities
-		  if(!impl.preserveWhiteSpace) {
-		  		var children = parentNode.childNodes;
-				for ( var j = 0; j &lt; children.length; j++) {
-					var child = children.item(j);
-					if (child.nodeType == DOMNode.TEXT_NODE) {
-						var childData = child.data;
-						childData.replace(/\s/g, ' ');
-						child.data = childData;
-					}
-				}
-		  }
-      }
-  }
-  
-  //do the preserve whitespace processing on the rest of the text nodes
-  //It's possible (due to the processing above) that the node will have been
-  //removed from the tree. Only do whitespace checking if parentNode is not null.
-  //This may duplicate the whitespace processing for some nodes that had entities in them
-  //but there's no way around that
-  if (!impl.preserveWhiteSpace) {
-	for (var i = 0; i &lt; textNodesList.length; i++) {
-		var node = textNodesList[i];
-		if (node.parentNode != null) {
-			var nodeData = node.data;
-			nodeData.replace(/\s/g, ' ');
-			node.data = nodeData;
-		}
-	}
-  
-  }
-};
-
-/**
- * @method DOMImplementation._isNamespaceDeclaration - Return true, if attributeName is a namespace declaration
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  attributeName : string - the attribute name
- * @return : boolean
- */
-function __isNamespaceDeclaration__(attributeName) {
-  // test if attributeName is 'xmlns'
-  return (attributeName.indexOf('xmlns') &gt; -1);
-};
-
-/**
- * @method DOMImplementation._isIdDeclaration - Return true, if attributeName is an id declaration
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  attributeName : string - the attribute name
- * @return : boolean
- */
-function __isIdDeclaration__(attributeName) {
-  // test if attributeName is 'id' (case insensitive)
-  return (attributeName.toLowerCase() == 'id');
-};
-
-/**
- * @method DOMImplementation._isValidName - Return true,
- *   if name contains no invalid characters
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  name : string - the candidate name
- * @return : boolean
- */
-function __isValidName__(name) {
-  // test if name contains only valid characters
-  return name.match(re_validName);
-};
-var re_validName = /^[a-zA-Z_:][a-zA-Z0-9\.\-_:]*$/;
-
-/**
- * @method DOMImplementation._isValidString - Return true, if string does not contain any illegal chars
- *  All of the characters 0 through 31 and character 127 are nonprinting control characters.
- *  With the exception of characters 09, 10, and 13, (Ox09, Ox0A, and Ox0D)
- *  Note: different from _isValidName in that ValidStrings may contain spaces
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  name : string - the candidate string
- * @return : boolean
- */
-function __isValidString__(name) {
-  // test that string does not contains invalid characters
-  return (name.search(re_invalidStringChars) &lt; 0);
-};
-var re_invalidStringChars = /\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0B|\x0C|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E|\x1F|\x7F/;
-
-/**
- * @method DOMImplementation._parseNSName - parse the namespace name.
- *  if there is no colon, the
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  qualifiedName : string - The qualified name
- * @return : NSName - [
-         .prefix        : string - The prefix part of the qname
-         .namespaceName : string - The namespaceURI part of the qname
-    ]
- */
-function __parseNSName__(qualifiedName) {
-  var resultNSName = new Object();
-
-  resultNSName.prefix          = qualifiedName;  // unless the qname has a namespaceName, the prefix is the entire String
-  resultNSName.namespaceName   = &quot;&quot;;
-
-  // split on ':'
-  var delimPos = qualifiedName.indexOf(':');
-  if (delimPos &gt; -1) {
-    // get prefix
-    resultNSName.prefix        = qualifiedName.substring(0, delimPos);
-    // get namespaceName
-    resultNSName.namespaceName = qualifiedName.substring(delimPos +1, qualifiedName.length);
-  }
-  return resultNSName;
-};
-
-/**
- * @method DOMImplementation._parseQName - parse the qualified name
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  qualifiedName : string - The qualified name
- * @return : QName
- */
-function __parseQName__(qualifiedName) {
-  var resultQName = new Object();
-
-  resultQName.localName = qualifiedName;  // unless the qname has a prefix, the local name is the entire String
-  resultQName.prefix    = &quot;&quot;;
-
-  // split on ':'
-  var delimPos = qualifiedName.indexOf(':');
-
-  if (delimPos &gt; -1) {
-    // get prefix
-    resultQName.prefix    = qualifiedName.substring(0, delimPos);
-
-    // get localName
-    resultQName.localName = qualifiedName.substring(delimPos +1, qualifiedName.length);
-  }
-
-  return resultQName;
-};
-
-$log(&quot;Initializing document.implementation&quot;);
-var $implementation =  new DOMImplementation();
-$implementation.namespaceAware = false;
-$implementation.errorChecking = true;$log(&quot;Defining Document&quot;);
-/*
-* Document - DOM Level 2
-*  The Document object is not directly 
-*/
-$w.__defineGetter__('Document', function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-/**
- * @class  DOMDocument - The Document interface represents the entire HTML or XML document.
- *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
- *
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  implementation : DOMImplementation - the creator Implementation
- */
-var DOMDocument = function(implementation) {
-    //$log(&quot;\tcreating dom document&quot;);
-    this.DOMNode = DOMNode;
-    this.DOMNode(this);
-    
-    this.doctype = null;                  // The Document Type Declaration (see DocumentType) associated with this document
-    this.implementation = implementation; // The DOMImplementation object that handles this document.
-    this.documentElement = null;          // This is a convenience attribute that allows direct access to the child node that is the root element of the document
-    //this.all  = new Array();                       // The list of all Elements
-    
-    this.nodeName  = &quot;#document&quot;;
-    this.nodeType = DOMNode.DOCUMENT_NODE;
-    this._id = 0;
-    this._lastId = 0;
-    this._parseComplete = false;                   // initially false, set to true by parser
-    this._url = &quot;&quot;;
-    
-    this.ownerDocument = this;
-    
-    this._performingImportNodeOperation = false;
-    //$log(&quot;\tfinished creating dom document &quot; + this);
-};
-DOMDocument.prototype = new DOMNode;
-__extend__(DOMDocument.prototype, {
-	addEventListener        : window.addEventListener,
-	removeEventListener     : window.removeEventListener,
-    attachEvent             : window.addEventListener,/*IE only subject to deprecation*/
-    detachEvent             : window.detachEvent,/*IE only subject to  deprecation*/
-	dispatchEvent           : window.dispatchEvent,
-    get styleSheets(){ 
-        return [];/*TODO*/ 
-    },
-    get all(){
-        return this.getElementsByTagName(&quot;*&quot;);
-    },
-    loadXML : function(xmlStr) {
-        // create SAX Parser
-        var parser;
-        
-        try {
-            parser = new XMLP(String(xmlStr));
-        }catch (e) {
-            $error(&quot;Error Creating the SAX Parser. \n\n\t&quot;+e+&quot;\n\n\t Did you include xmlsax.js or tinyxmlsax.js\
-                     in your web page?\nThe SAX parser is needed to populate XML for &lt;SCRIPT&gt;'s \
-                     W3C DOM Parser with data.&quot;);
-        }
-        // create DOM Document
-        var doc = new HTMLDocument(this.implementation);
-        // populate Document with Parsed Nodes
-        __parseLoop__(this.implementation, doc, parser);
-        // set parseComplete flag, (Some validation Rules are relaxed if this is false)
-        doc._parseComplete = true;
-        if(this === $document){
-            $log(&quot;Setting internal window.document&quot;);
-            $document = doc;
-        }
-        return doc;
-    },
-    load: function(url){
-		$log(&quot;Loading url into DOM Document: &quot;+ url + &quot; - (Asynch? &quot;+$w.document.async+&quot;)&quot;);
-        var _this = this;
-        var xhr = new XMLHttpRequest();
-        xhr.open(&quot;GET&quot;, url, $w.document.async);
-        xhr.onreadystatechange = function(){
-            try{
-        	    _this.loadXML(xhr.responseText);
-            }catch(e){
-                $error(&quot;Error Parsing XML - &quot;,e);
-                _this.loadXML(
-                &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&quot;+
-                  &quot;&lt;h1&gt;Parse Error&lt;/h1&gt;&quot;+
-                  &quot;&lt;p&gt;&quot;+e.toString()+&quot;&lt;/p&gt;&quot;+  
-                &quot;&lt;/body&gt;&lt;/html&gt;&quot;);
-            }
-            _this._url = url;
-        	$log(&quot;Sucessfully loaded document.&quot;);
-        	var event = document.createEvent();
-        	event.initEvent(&quot;load&quot;);
-        	$w.dispatchEvent( event );
-        };
-        xhr.send();
-    },
-	createEvent             : function(eventType){ 
-        var event;
-        if(eventType === &quot;UIEvents&quot;){ event = new UIEvent();}
-        else if(eventType === &quot;MouseEvents&quot;){ event = new MouseEvent();}
-        else{ event = new Event(); } 
-        return event;
-    },
-    createExpression        : function(xpath, nsuriMap){ 
-        return null;/*TODO*/
-    },
-    createElement : function(tagName) {
-        //$log(&quot;DOMDocument.createElement( &quot;+tagName+&quot; )&quot;);
-          // throw Exception if the tagName string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMElement specifying 'this' as ownerDocument
-          var node = new DOMElement(this);
-        
-          // assign values to properties (and aliases)
-          node.tagName  = tagName;
-          node.nodeName = tagName;
-        
-          // add Element to 'all' collection
-          //this.all[this.all.length] = node;
-          //$log(&quot;Document.all.length &quot; + this.all.length);
-        
-          return node;
-    },
-    createDocumentFragment : function() {
-          // create DOMDocumentFragment specifying 'this' as ownerDocument
-          var node = new DOMDocumentFragment(this);
-        
-          return node;
-    },
-    createTextNode: function(data) {
-          // create DOMText specifying 'this' as ownerDocument
-          var node = new DOMText(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createComment : function(data) {
-          // create DOMComment specifying 'this' as ownerDocument
-          var node = new DOMComment(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createCDATASection : function(data) {
-          // create DOMCDATASection specifying 'this' as ownerDocument
-          var node = new DOMCDATASection(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createProcessingInstruction : function(target, data) {
-          // throw Exception if the target string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(target))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMProcessingInstruction specifying 'this' as ownerDocument
-          var node = new DOMProcessingInstruction(this);
-        
-          // assign values to properties (and aliases)
-          node.target    = target;
-          node.nodeName  = target;
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createAttribute : function(name) {
-          // throw Exception if the name string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(name))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMAttr specifying 'this' as ownerDocument
-          var node = new DOMAttr(this);
-        
-          // assign values to properties (and aliases)
-          node.name     = name;
-          node.nodeName = name;
-        
-          return node;
-    },
-    createElementNS : function(namespaceURI, qualifiedName) {
-        //$log(&quot;DOMDocument.createElement( &quot;+namespaceURI+&quot;, &quot;+qualifiedName+&quot; )&quot;);
-          // test for exceptions
-          if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if the Namespace is invalid
-            if (!__isValidNamespace__(this, namespaceURI, qualifiedName)) {
-              throw(new DOMException(DOMException.NAMESPACE_ERR));
-            }
-        
-            // throw Exception if the qualifiedName string contains an illegal character
-            if (!__isValidName__(qualifiedName)) {
-              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-            }
-          }
-        
-          // create DOMElement specifying 'this' as ownerDocument
-          var node  = new DOMElement(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.namespaceURI = namespaceURI;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.tagName      = qualifiedName;
-        
-          // add Element to 'all' collection
-          //this.all[this.all.length] = node;
-        
-          return node;
-    },
-    createAttributeNS : function(namespaceURI, qualifiedName) {
-          // test for exceptions
-          if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if the Namespace is invalid
-            if (!__isValidNamespace__(this, namespaceURI, qualifiedName, true)) {
-              throw(new DOMException(DOMException.NAMESPACE_ERR));
-            }
-        
-            // throw Exception if the qualifiedName string contains an illegal character
-            if (!__isValidName__(qualifiedName)) {
-              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-            }
-          }
-        
-          // create DOMAttr specifying 'this' as ownerDocument
-          var node  = new DOMAttr(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.namespaceURI = namespaceURI;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.name         = qualifiedName;
-          node.nodeValue    = &quot;&quot;;
-        
-          return node;
-    },
-    createNamespace : function(qualifiedName) {
-          // create DOMNamespace specifying 'this' as ownerDocument
-          var node  = new DOMNamespace(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.name         = qualifiedName;
-          node.nodeValue    = &quot;&quot;;
-        
-          return node;
-    },
-    getElementById : function(elementId) {
-          var retNode = null,
-              node;
-          // loop through all Elements in the 'all' collection
-          var all = this.all;
-          for (var i=0; i &lt; all.length; i++) {
-            node = all[i];
-            // if id matches &amp; node is alive (ie, connected (in)directly to the documentElement)
-            if (node.id == elementId) {
-                if((node.ownerDocument.documentElement._id == this.documentElement._id)){
-                    retNode = node;
-                    //$log(&quot;Found node with id = &quot; + node.id);
-                    break;
-                }
-            }
-          }
-          
-          if(retNode == null){$log(&quot;Couldn't find id &quot; + elementId);}
-          return retNode;
-    },
-    normalizeDocument: function(){
-	    this.documentElement.normalize();
-    },
-    get xml(){
-        return this.documentElement.xml;
-    },
-	toString: function(){ 
-	    return &quot;Document&quot; +  (typeof this._url == &quot;string&quot; ? &quot;: &quot; + this._url : &quot;&quot;); 
-    },
-	get defaultView(){ //TODO: why isnt this just 'return $w;'?
-		return { getComputedStyle: function(elem){
-			return { getPropertyValue: function(prop){
-				prop = prop.replace(/\-(\w)/g,function(m,c){ return c.toUpperCase(); });
-				var val = elem.style[prop];
-				if ( prop == &quot;opacity&quot; &amp;&amp; val == &quot;&quot; ){ val = &quot;1&quot;; }return val;
-			}};
-		}};
-	},
-    _genId : function() {
-          this._lastId += 1;                             // increment lastId (to generate unique id)
-          return this._lastId;
-    }
-});
-
-
-var __isValidNamespace__ = function(doc, namespaceURI, qualifiedName, isAttribute) {
-
-      if (doc._performingImportNodeOperation == true) {
-        //we're doing an importNode operation (or a cloneNode) - in both cases, there
-        //is no need to perform any namespace checking since the nodes have to have been valid
-        //to have gotten into the DOM in the first place
-        return true;
-      }
-    
-      var valid = true;
-      // parse QName
-      var qName = __parseQName__(qualifiedName);
-    
-    
-      //only check for namespaces if we're finished parsing
-      if (this._parseComplete == true) {
-    
-        // if the qualifiedName is malformed
-        if (qName.localName.indexOf(&quot;:&quot;) &gt; -1 ){
-            valid = false;
-        }
-    
-        if ((valid) &amp;&amp; (!isAttribute)) {
-            // if the namespaceURI is not null
-            if (!namespaceURI) {
-            valid = false;
-            }
-        }
-    
-        // if the qualifiedName has a prefix
-        if ((valid) &amp;&amp; (qName.prefix == &quot;&quot;)) {
-            valid = false;
-        }
-    
-      }
-    
-      // if the qualifiedName has a prefix that is &quot;xml&quot; and the namespaceURI is
-      //  different from &quot;http://www.w3.org/XML/1998/namespace&quot; [Namespaces].
-      if ((valid) &amp;&amp; (qName.prefix == &quot;xml&quot;) &amp;&amp; (namespaceURI != &quot;http://www.w3.org/XML/1998/namespace&quot;)) {
-        valid = false;
-      }
-    
-      return valid;
-};
-$log(&quot;Defining HTMLDocument&quot;);
-/*
-* HTMLDocument - DOM Level 2
-*  The Document object is not directly 
-*/
-$w.__defineGetter__(&quot;HTMLDocument&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-/**
- * @class  HTMLDocument - The Document interface represents the entire HTML or XML document.
- *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
- *
- * @extends DOMDocument
- */
-var HTMLDocument = function(implementation) {
-  this.DOMDocument = DOMDocument;
-  this.DOMDocument(implementation);
-
-  this.title = &quot;&quot;;
-  this._refferer = &quot;&quot;;
-  this._domain;
-  this._open = false;
-};
-HTMLDocument.prototype = new DOMDocument;
-__extend__(HTMLDocument.prototype, {
-    createElement: function(tagName){
-        //$log(&quot;HTMLDocument.createElement( &quot;+tagName+&quot; )&quot;);
-        // throw Exception if the tagName string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-          tagName = tagName.toUpperCase();
-          //$log(&quot;HTMLDocument.createElement( &quot;+tagName+&quot; )&quot;);
-          // create DOMElement specifying 'this' as ownerDocument
-          //This is an html document so we need to use explicit interfaces per the 
-          if(     tagName.match(/^A$/))                 {node = new HTMLAnchorElement(this);}
-          else if(tagName.match(/AREA/))                {node = new HTMLAreaElement(this);}
-          else if(tagName.match(/BASE/))                {node = new HTMLBaseElement(this);}
-          else if(tagName.match(/BLOCKQUOTE|Q/))        {node = new HTMLQuoteElement(this);}
-          else if(tagName.match(/BODY/))                {node = new HTMLElement(this);}
-          else if(tagName.match(/BR/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/BUTTON/))              {node = new HTMLButtonElement(this);}
-          else if(tagName.match(/CAPTION/))             {node = new HTMLElement(this);}
-          else if(tagName.match(/COL|COLGROUP/))        {node = new HTMLTableColElement(this);}
-          else if(tagName.match(/DEL|INS/))             {node = new HTMLModElement(this);}
-          else if(tagName.match(/DIV/))                 {node = new HTMLElement(this);}
-          else if(tagName.match(/DL/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/FIELDSET/))            {node = new HTMLFieldSetElement(this);}
-          else if(tagName.match(/FORM/))                {node = new HTMLFormElement(this);}
-          else if(tagName.match(/^FRAME$/))             {node = new HTMLFrameElement(this);}
-          else if(tagName.match(/FRAMESET/))            {node = new HTMLFrameSetElement(this);}
-          else if(tagName.match(/H1|H2|H3|H4|H5|H6/))   {node = new HTMLElement(this);}
-          else if(tagName.match(/HEAD/))                {node = new HTMLHeadElement(this);}
-          else if(tagName.match(/HR/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/HTML/))                {node = new HTMLElement(this);}
-          else if(tagName.match(/IFRAME/))              {node = new HTMLIFrameElement(this);}
-          else if(tagName.match(/IMG/))                 {node = new HTMLImageElement(this);}
-          else if(tagName.match(/INPUT/))               {node = new HTMLInputElement(this);}
-          else if(tagName.match(/LABEL/))               {node = new HTMLLabelElement(this);}
-          else if(tagName.match(/LEGEND/))              {node = new HTMLLegendElement(this);}
-          else if(tagName.match(/^LI$/))                {node = new HTMLElement(this);}
-          else if(tagName.match(/LINK/))                {node = new HTMLLinkElement(this);}
-          else if(tagName.match(/MAP/))                 {node = new HTMLMapElement(this);}
-          else if(tagName.match(/META/))                {node = new HTMLMetaElement(this);}
-          else if(tagName.match(/OBJECT/))              {node = new HTMLObjectElement(this);}
-          else if(tagName.match(/OL/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/OPTGROUP/))            {node = new HTMLOptGroupElement(this);}
-          else if(tagName.match(/OPTION/))              {node = new HTMLOptionElement(this);;}
-          else if(tagName.match(/^P$/))                 {node = new HTMLElement(this);}
-          else if(tagName.match(/PARAM/))               {node = new HTMLParamElement(this);}
-          else if(tagName.match(/PRE/))                 {node = new HTMLElement(this);}
-          else if(tagName.match(/SCRIPT/))              {node = new HTMLScriptElement(this);}
-          else if(tagName.match(/SELECT/))              {node = new HTMLSelectElement(this);}
-          else if(tagName.match(/STYLE/))               {node = new HTMLStyleElement(this);}
-          else if(tagName.match(/TABLE/))               {node = new HTMLElement(this);}
-          else if(tagName.match(/TBODY|TFOOT|THEAD/))   {node = new HTMLElement(this);}
-          else if(tagName.match(/TD|TH/))               {node = new HTMLElement(this);}
-          else if(tagName.match(/TEXTAREA/))            {node = new HTMLElement(this);}
-          else if(tagName.match(/TITLE/))               {node = new HTMLElement(this);}
-          else if(tagName.match(/TR/))                  {node = new HTMLElement(this);}
-          else if(tagName.match(/UL/))                  {node = new HTMLElement(this);}
-          else{
-            node = new HTMLElement(this);
-          }
-        
-          // assign values to properties (and aliases)
-          node.tagName  = tagName;
-          node.nodeName = tagName;
-        
-          // add Element to 'all' collection
-          //this.all[this.all.length] = node;
-          //$log(&quot;Document.all.length &quot; + this.all.length);
-          return node;
-    },
-    get anchors(){
-        return new HTMLCollection(this.getElementsByTagName('a'), 'Anchor');
-        
-    },
-    get applets(){
-        return new HTMLCollection(this.getElementsByTagName('applet'), 'Applet');
-        
-    },
-    get body(){ 
-        var nodelist = this.getElementsByTagName('body');
-        return nodelist.item(0);
-        
-    },
-    set body(html){
-        return this.replaceNode(this.body,html);
-        
-    },
-    //set/get cookie see cookie.js
-    get domain(){
-        return this._domain||window.location.domain;
-        
-    },
-    set domain(){
-        /* TODO - requires a bit of thought to enforce domain restrictions */ 
-        return; 
-        
-    },
-    get forms(){
-      $log(&quot;document.forms&quot;);
-      return new HTMLCollection(this.getElementsByTagName('form'), 'Form');
-    },
-    get images(){
-        return new HTMLCollection(this.getElementsByTagName('img'), 'Image');
-        
-    },
-    get lastModified(){ 
-        /* TODO */
-        return this._lastModified; 
-    
-    },
-    get links(){
-        return new HTMLCollection(this.getElementsByTagName('a'), 'Link');
-        
-    },
-    get referrer(){
-        /* TODO */
-        return this._refferer; 
-        
-    },
-    get URL(){
-        /* TODO*/
-        return this._url; 
-        
-    },
-	close : function(){ 
-	    /* TODO */ 
-	    this._open = false;
-    },
-	getElementsByName : function(name){
-        //$debug(&quot;document.getElementsByName ( &quot;+name+&quot; )&quot;);
-        //returns a real Array + the DOMNodeList
-        var retNodes = __extend__([],new DOMNodeList(this, this.documentElement)),
-          node;
-        // loop through all Elements in the 'all' collection
-        var all = this.all;
-        for (var i=0; i &lt; all.length; i++) {
-            node = all[i];
-            if (node.nodeType == DOMNode.ELEMENT_NODE &amp;&amp; node.getAttribute('name') == name) {
-                //$log(&quot;Found node by name &quot; + name);
-                retNodes.push(node);
-            }
-        }
-        return retNodes;
-	},
-	open : function(){ 
-	    /* TODO */
-	    this._open = true;  
-    },
-	write: function(htmlstring){ 
-	    /* TODO */
-	    return; 
-	
-    },
-	writeln: function(htmlstring){ 
-	    this.write(htmlstring+'\n'); 
-    },
-	toString: function(){ 
-	    return &quot;Document&quot; +  (typeof this._url == &quot;string&quot; ? &quot;: &quot; + this._url : &quot;&quot;); 
-    },
-	get innerHTML(){ 
-	    return this.documentElement.outerHTML; 
-	    
-    },
-	get __html__(){
-	    return true;
-	    
-    }
-});
-
-//This is useful as html elements that modify the dom must also run through the new 
-//nodes and determine if they are javascript tags and load it.  This is really the fun 
-//parts! ;)
-function __execScripts__( node ) {
-	if ( node.nodeName == &quot;SCRIPT&quot; ) {
-		if ( !node.getAttribute(&quot;src&quot;) ) {
-			eval.call( window, node.textContent );
-		}
-	} else {
-		var scripts = node.getElementsByTagName(&quot;script&quot;);
-		for ( var i = 0; i &lt; scripts.length; i++ ) {
-			__execScripts__( node );
-		}
-	}
-};$log(&quot;Defining HTMLElement&quot;);
-/*
-* HTMLElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-var HTMLElement = function(ownerDocument) {
-    //$log(&quot;\tcreating html element&quot;);
-    this.DOMElement = DOMElement;
-    this.DOMElement(ownerDocument);
-    //$log(&quot;\nfinished creating html element&quot;);
-    
-    this.$css2props = null;
-};
-HTMLElement.prototype = new DOMElement;
-__extend__(HTMLElement.prototype, {
-		get className() { 
-		    return this.getAttribute(&quot;class&quot;)||&quot;&quot;; 
-		    
-	    },
-		set className(val) { 
-		    return this.setAttribute(&quot;class&quot;,trim(val)); 
-		    
-	    },
-		get dir() { 
-		    return this.getAttribute(&quot;dir&quot;)||&quot;ltr&quot;; 
-		    
-	    },
-		set dir(val) { 
-		    return this.setAttribute(&quot;dir&quot;,val); 
-		    
-	    },
-		get innerHTML(){  
-		    return this.childNodes.xml; 
-		    
-	    },
-		set innerHTML(html){
-		    //$debug(&quot;htmlElement.innerHTML(&quot;+html+&quot;)&quot;);
-		    //Should be replaced with HTMLPARSER usage
-			html = (html?html:&quot;&quot;).replace(/&lt;\/?([A-Z]+)/g, function(m){
-				return m.toLowerCase();
-			}).replace(/&amp;nbsp;/g, &quot; &quot;);
-			var doc = new DOMParser().
-			  parseFromString('&lt;div&gt;'+html+'&lt;/div&gt;');
-            var parent = this.ownerDocument.importNode(doc.documentElement, true);
-            
-			//$log(&quot;\n\nIMPORTED HTML:\n\n&quot;+nodes.xml);
-			while(this.firstChild != null){
-			    //$log('innerHTML - removing child '+ this.firstChild.xml);
-			    this.removeChild( this.firstChild );
-			}
-			while(parent.firstChild != null){
-			    //$log('innerHTML - appending child '+ parent.firstChild.xml);
-			    this.appendChild( parent.removeChild( parent.firstChild ) );
-		    }
-		    //Mark for garbage collection
-		    doc = null;
-		},
-		get lang() { 
-		    return this.getAttribute(&quot;lang&quot;)||&quot;&quot;; 
-		    
-	    },
-		set lang(val) { 
-		    return this.setAttribute(&quot;lang&quot;,val); 
-		    
-	    },
-		get offsetHeight(){
-		    return Number(this.style[&quot;height&quot;].replace(&quot;px&quot;,&quot;&quot;));
-		},
-		get offsetWidth(){
-		    return Number(this.style[&quot;width&quot;].replace(&quot;px&quot;,&quot;&quot;));
-		},
-		offsetLeft: 0,
-		offsetRight: 0,
-		get offsetParent(){
-		    /* TODO */
-		    return;
-	    },
-		set offsetParent(element){
-		    /* TODO */
-		    return;
-	    },
-		scrollHeight: 0,
-		scrollWidth: 0,
-		scrollLeft: 0, 
-		scrollRight: 0,
-		get style(){
-		    if(this.$css2props === null){
-		        $log(&quot;Initializing new css2props for html element : &quot; + this.getAttribute(&quot;style&quot;));
-		        this.$css2props = new CSS2Properties({
-    		        cssText:this.getAttribute(&quot;style&quot;)
-    	        });
-	        }
-	        return this.$css2props
-		},
-		get title() { 
-		    return this.getAttribute(&quot;title&quot;)||&quot;&quot;; 
-		    
-	    },
-		set title(val) { 
-		    return this.setAttribute(&quot;title&quot;,val); 
-		    
-	    },
-		//Not in the specs but I'll leave it here for now.
-		get outerHTML(){ 
-		    return this.xml; 
-		    
-	    },
-	    scrollIntoView: function(){
-	        /*TODO*/
-	        return;
-	    
-        },
-		onclick: function(event){
-		    try{
-		        eval(this.getAttribute('onclick'));
-		    }catch(e){
-		        $error(e);
-	        }
-	    },
-		ondblclick: function(event){
-		    try{
-		        eval(this.getAttribute('ondblclick'));
-		    }catch(e){
-		        $error(e)
-		    }
-	    },
-		onkeydown: function(event){
-		    try{
-		        eval(this.getAttribute('onkeydown'));
-		    }catch(e){
-		        $error(e);
-		    }
-	    },
-		onkeypress: function(event){
-		    try{
-		        eval(this.getAttribute('onkeypress'));
-		    }catch(e){
-		        $error(e);}},
-		onkeyup: function(event){
-		    try{
-		        eval(this.getAttribute('onkeyup'));
-		    }catch(e){
-		        $error(e);}},
-		onmousedown: function(event){
-		    try{
-		        eval(this.getAttribute('onmousedown'));
-		    }catch(e){
-		        $error(e);}},
-		onmousemove: function(event){
-		    try{
-		        eval(this.getAttribute('onmousemove'));
-		    }catch(e){
-		        $error(e);}},
-		onmouseout: function(event){
-		    try{
-		        eval(this.getAttribute('onmouseout'));
-		    }catch(e){
-		        $error(e);}},
-		onmouseover: function(event){
-		    try{
-		        eval(this.getAttribute('onmouseover'));
-		    }catch(e){
-		        $error(e);}},
-		onmouseup: function(event){
-		    try{
-		        eval(this.getAttribute('onmouseup'));
-		    }catch(e){
-		        $error(e);}}
-});
-
-var __registerEventAttrs__ = function(elm){
-    if(elm.hasAttribute('onclick')){ 
-        elm.addEventListener('click', elm.onclick ); 
-    }
-    if(elm.hasAttribute('ondblclick')){ 
-        elm.addEventListener('dblclick', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onkeydown')){ 
-        elm.addEventListener('keydown', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onkeypress')){ 
-        elm.addEventListener('keypress', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onkeyup')){ 
-        elm.addEventListener('keyup', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmousedown')){ 
-        elm.addEventListener('mousedown', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmousemove')){ 
-        elm.addEventListener('mousemove', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmouseout')){ 
-        elm.addEventListener('mouseout', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmouseover')){ 
-        elm.addEventListener('mouseover', elm.onclick ); 
-    }
-    if(elm.hasAttribute('onmouseup')){ 
-        elm.addEventListener('mouseup', elm.onclick ); 
-    }
-    return elm;
-};
-	
-var __click__ = function(element){
-	var event = new Event({
-	  target:element,
-	  currentTarget:element
-	});
-	event.initEvent(&quot;click&quot;);
-	element.dispatchEvent(event);
-};
-var __submit__ = function(element){
-	var event = new Event({
-	  target:element,
-	  currentTarget:element
-	});
-	event.initEvent(&quot;submit&quot;);
-	element.dispatchEvent(event);
-};
-var __focus__ = function(element){
-	var event = new Event({
-	  target:element,
-	  currentTarget:element
-	});
-	event.initEvent(&quot;focus&quot;);
-	element.dispatchEvent(event);
-};
-var __blur__ = function(element){
-	var event = new Event({
-	  target:element,
-	  currentTarget:element
-	});
-	event.initEvent(&quot;blur&quot;);
-	element.dispatchEvent(event);
-};
-$log(&quot;Defining HTMLCollection&quot;);
-/*
-* HTMLCollection - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLCollection&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/*var HTMLCollection = function(nodelist, type){
-  var $items = [], 
-      $item, i;
-  if(type === &quot;Anchor&quot; ){
-    for(i=0;i&lt;nodelist.length;i++){ 
-      //The name property is required to be add to the collection
-      if(nodelist.item(i).name){
-        item = new nodelist.item(i);
-        $items.push(item);
-        this[nodelist.item(i).name] = item;
-      }
-    }
-  }else if(type === &quot;Link&quot;){
-    for(i=0;i&lt;nodelist.length;i++){ 
-      //The name property is required to be add to the collection
-      if(nodelist.item(i).href){
-        item = new nodelist.item(i);
-        $items.push(item);
-        this[nodelist.item(i).name] = item;
-      }
-    }
-  }else if(type === &quot;Form&quot;){
-    for(i=0;i&lt;nodelist.length;i++){ 
-      //The name property is required to be add to the collection
-      if(nodelist.item(i).href){
-        item = new nodelist.item(i);
-        $items.push(item);
-        this[nodelist.item(i).name] = item;
-      }
-    }
-  }
-  setArray(this, $items);
-  return __extend__(this, {
-    item : function(i){return this[i];},
-    namedItem : function(name){return this[name];}
-  });
-};*/
-
-	$log(&quot;Defining HTMLAnchorElement&quot;);
-/* 
-* HTMLAnchorElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLAnchorElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLAnchorElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLAnchorElement.prototype = new HTMLElement;
-__extend__(HTMLAnchorElement.prototype, {
-	get accessKey() { 
-	    return this.getAttribute(&quot;accesskey&quot;) || &quot;&quot;; 
-	    
-    },
-	set accessKey(val) { 
-	    return this.setAttribute(&quot;accesskey&quot;,val); 
-	    
-    },
-	get charset() { 
-	    return this.getAttribute(&quot;charset&quot;) || &quot;&quot;; 
-	    
-    },
-	set charset(val) { 
-	    return this.setAttribute(&quot;charset&quot;,val); 
-	    
-    },
-	get coords() { 
-	    return this.getAttribute(&quot;coords&quot;) || &quot;&quot;; 
-	    
-    },
-	set coords(val) { 
-	    return this.setAttribute(&quot;coords&quot;,val); 
-	    
-    },
-	get href() { 
-	    return this.getAttribute(&quot;href&quot;) || &quot;&quot;; 
-	    
-    },
-	set href(val) { 
-	    return this.setAttribute(&quot;href&quot;,val); 
-	    
-    },
-	get hreflang() { 
-	    return this.getAttribute(&quot;hreflang&quot;) || &quot;&quot;; 
-	    
-    },
-	set hreflang(val) { 
-	    return this.setAttribute(&quot;hreflang&quot;,val); 
-	    
-    },
-	get name() { 
-	    return this.getAttribute(&quot;name&quot;) || &quot;&quot;; 
-	    
-    },
-	set name(val) { 
-	    return this.setAttribute(&quot;name&quot;,val); 
-	    
-    },
-	get rel() { 
-	    return this.getAttribute(&quot;rel&quot;) || &quot;&quot;; 
-	    
-    },
-	set rel(val) { 
-	    return this.setAttribute(&quot;rel&quot;,val); 
-	    
-    },
-	get rev() { 
-	    return this.getAttribute(&quot;rev&quot;) || &quot;&quot;; 
-	    
-    },
-	set rev(val) { 
-	    return this.setAttribute(&quot;rev&quot;,val); 
-	    
-    },
-	get shape() { 
-	    return this.getAttribute(&quot;shape&quot;) || &quot;&quot;; 
-	    
-    },
-	set shape(val) { 
-	    return this.setAttribute(&quot;shape&quot;,val); 
-	    
-    },
-	get tabIndex() { 
-	    return this.getAttribute(&quot;tabindex&quot;) || &quot;&quot;; 
-	    
-    },
-	set tabIndex(val) { 
-	    return this.setAttribute(&quot;tabindex&quot;,val); 
-	    
-    },
-	get target() { 
-	    return this.getAttribute(&quot;target&quot;) || &quot;&quot;; 
-	    
-    },
-	set target(val) { 
-	    return this.setAttribute(&quot;target&quot;,val); 
-	    
-    },
-	get type() { 
-	    return this.getAttribute(&quot;type&quot;) || &quot;&quot;; 
-	    
-    },
-	set type(val) { 
-	    return this.setAttribute(&quot;type&quot;,val); 
-	    
-    },
-	blur:function(){
-	    __blur__(this);
-	    
-    },
-	focus:function(){
-	    __focus__(this);
-	    
-    }
-});
-
-			$log(&quot;Defining Anchor&quot;);
-/* 
-* Anchor - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Anchor&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var Anchor = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLAnchorElement = HTMLAnchorElement;
-    this.HTMLAnchorElement(ownerDocument);
-};
-Anchor.prototype = new Anchor;
-
-(function(){
-    //static regular expressions
-	var hash 	 = new RegExp('(\\#.*)'),
-        hostname = new RegExp('\/\/([^\:\/]+)'),
-        pathname = new RegExp('(\/[^\\?\\#]*)'),
-        port 	 = new RegExp('\:(\\d+)\/'),
-        protocol = new RegExp('(^\\w*\:)'),
-        search 	 = new RegExp('(\\?[^\\#]*)');
-			
-    __extend__(Anchor.prototype, {
-		get hash(){
-			var m = hash.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set hash(_hash){
-			//setting the hash is the only property of the location object
-			//that doesn't cause the window to reload
-			_hash = _hash.indexOf('#')===0?_hash:&quot;#&quot;+_hash;	
-			this.href = this.protocol + this.host + this.pathname + this.search + _hash;
-		},
-		get host(){
-			return this.hostname + (this.port !== &quot;&quot;)?&quot;:&quot;+this.port:&quot;&quot;;
-		},
-		set host(_host){
-			this.href = this.protocol + _host + this.pathname + this.search + this.hash;
-		},
-		get hostname(){
-			var m = hostname.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set hostname(_hostname){
-			this.href = this.protocol + _hostname + ((this.port===&quot;&quot;)?&quot;&quot;:(&quot;:&quot;+this.port)) +
-			 	 this.pathname + this.search + this.hash;
-		},
-		get pathname(){
-			var m = this.href;
-			m = pathname.exec(m.substring(m.indexOf(this.hostname)));
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;/&quot;;
-		},
-		set pathname(_pathname){
-			this.href = this.protocol + this.host + _pathname + 
-				this.search + this.hash;
-		},
-		get port(){
-			var m = port.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set port(_port){
-			this.href = this.protocol + this.hostname + &quot;:&quot;+_port + this.pathname + 
-				this.search + this.hash;
-		},
-		get protocol(){
-			return protocol.exec(this.href)[0];
-		},
-		set protocol(_protocol){
-			this.href = _protocol + this.host + this.pathname + 
-				this.search + this.hash;
-		},
-		get search(){
-			var m = search.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set search(_search){
-			this.href = this.protocol + this.host + this.pathname + 
-				_search + this.hash;
-		}
-  });
-
-})();
-			$log(&quot;Defining HTMLAreaElement&quot;);
-/* 
-* HTMLAreaElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLAreaElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLAreaElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLAreaElement.prototype = new HTMLElement;
-__extend__(HTMLAreaElement.prototype, {
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    },
-    get alt(){
-        return this.getAttribute('alt');
-    },
-    set alt(value){
-        this.setAttribute('alt',value);
-    },
-    get coords(){
-        return this.getAttribute('coords');
-    },
-    set coords(value){
-        this.setAttribute('coords',value);
-    },
-    get href(){
-        return this.getAttribute('href');
-    },
-    set href(value){
-        this.setAttribute('href',value);
-    },
-    get noHref(){
-        return this.hasAttribute('href');
-    },
-    get shape(){
-        //TODO
-        return 0;
-    },
-    get tabIndex(){
-        return this.getAttribute('tabindex');
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',value);
-    },
-    get target(){
-        return this.getAttribute('target');
-    },
-    set target(value){
-        this.setAttribute('target',value);
-    }
-});
-
-			$log(&quot;Defining HTMLBaseElement&quot;);
-/* 
-* HTMLBaseElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLBaseElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLBaseElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLBaseElement.prototype = new HTMLElement;
-__extend__(HTMLBaseElement.prototype, {
-    get href(){
-        return this.getAttribute('href');
-    },
-    set href(value){
-        this.setAttribute('href',value);
-    },
-    get target(){
-        return this.getAttribute('target');
-    },
-    set target(value){
-        this.setAttribute('target',value);
-    }
-});
-
-			$log(&quot;Defining HTMLQuoteElement&quot;);
-/* 
-* HTMLQuoteElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLQuoteElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLQuoteElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLQuoteElement.prototype = new HTMLElement;
-__extend__(HTMLQuoteElement.prototype, {
-    get cite(){
-        return this.getAttribute('cite');
-    },
-    set cite(value){
-        this.setAttribute('cite',value);
-    }
-});
-
-			$log(&quot;Defining HTMLButtonElement&quot;);
-/* 
-* HTMLButtonElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLButtonElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLButtonElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLButtonElement.prototype = new HTMLElement;
-__extend__(HTMLButtonElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    },
-    get tabIndex(){
-        return Number(this.getAttribute('tabindex'));
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',Number(value));
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-    get value(){
-        return this.getAttribute('value');
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    }
-});
-
-			$log(&quot;Defining HTMLTableColElement&quot;);
-/* 
-* HTMLTableColElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLTableColElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLTableColElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLTableColElement.prototype = new HTMLElement;
-__extend__(HTMLTableColElement.prototype, {
-    get align(){
-        return this.getAttribute('align');
-    },
-    set align(value){
-        this.setAttribute('align', value);
-    },
-    get ch(){
-        return this.getAttribute('ch');
-    },
-    set ch(value){
-        this.setAttribute('ch', value);
-    },
-    get chOff(){
-        return this.getAttribute('ch');
-    },
-    set chOff(value){
-        this.setAttribute('ch', value);
-    },
-    get span(){
-        return this.getAttribute('span');
-    },
-    set span(value){
-        this.setAttribute('span', value);
-    },
-    get vAlign(){
-        return this.getAttribute('valign');
-    },
-    set vAlign(value){
-        this.setAttribute('valign', value);
-    },
-    get width(){
-        return this.getAttribute('width');
-    },
-    set width(value){
-        this.setAttribute('width', value);
-    }
-});
-
-			$log(&quot;Defining HTMLModElement&quot;);
-/* 
-* HTMLModElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLModElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLModElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLModElement.prototype = new HTMLElement;
-__extend__(HTMLModElement.prototype, {
-    get cite(){
-        return this.getAttribute('cite');
-    },
-    set cite(value){
-        this.setAttribute('cite', value);
-    },
-    get dateTime(){
-        return this.getAttribute('datetime');
-    },
-    set dateTime(value){
-        this.setAttribute('datetime', value);
-    }
-});
-
-			$log(&quot;Defining HTMLFieldSetElement&quot;);
-/* 
-* HTMLFieldSetElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLFieldSetElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLFieldSetElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLFieldSetElement.prototype = new HTMLElement;
-__extend__(HTMLFieldSetElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    }
-});
-
-			$log(&quot;Defining HTMLFormElement&quot;);
-/* 
-* HTMLAnchorElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Form&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-$w.__defineGetter__(&quot;HTMLFormElement&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var HTMLFormElement = function(ownerDocument){
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLFormElement.prototype = new HTMLElement;
-__extend__(HTMLFormElement.prototype,{
-    get acceptCharset(){ 
-        return this.getAttribute('accept-charset');
-        
-    },
-    set acceptCharset(acceptCharset){
-        this.setAttribute('accept-charset', acceptCharset);
-        
-    },
-    get action(){
-        return this.getAttribute('action');
-        
-    },
-    set action(action){
-        this.setAttribute('action', action);
-        
-    },
-    get elements() {
-        return this.getElementsByTagName(&quot;*&quot;);
-        
-    },
-    get enctype(){
-        return this.getAttribute('enctype');
-        
-    },
-    set enctype(enctype){
-        this.setAttribute('enctype', enctype);
-        
-    },
-    get length() {
-        return this.elements.length;
-        
-    },
-    get method(){
-        return this.getAttribute('method');
-        
-    },
-    set method(action){
-        this.setAttribute('method', method);
-        
-    },
-	get name() {
-	    return this.getAttribute(&quot;name&quot;) || &quot;&quot;; 
-	    
-    },
-	set name(val) { 
-	    return this.setAttribute(&quot;name&quot;,val); 
-	    
-    },
-	get target() { 
-	    return this.getAttribute(&quot;target&quot;) || &quot;&quot;; 
-	    
-    },
-	set target(val) { 
-	    return this.setAttribute(&quot;target&quot;,val); 
-	    
-    },
-	submit:function(){
-	    __submit__(this);
-	    
-    },
-	reset:function(){
-	    __reset__(this);
-	    
-    }
-});
-
-			$log(&quot;Defining HTMLFrameElement&quot;);
-/* 
-* HTMLFrameElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLFrameElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLFrameElement = function(ownerDocument) {
-    //$log(&quot;creating frame element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLFrameElement.prototype = new HTMLElement;
-__extend__(HTMLFrameElement.prototype, {
-    get frameBorder(){
-        return this.getAttribute('border')||&quot;&quot;;
-    },
-    set frameBorder(value){
-        this.setAttribute('border', value);
-    },
-    get longDesc(){
-        return this.getAttribute('longdesc')||&quot;&quot;;
-    },
-    set longDesc(value){
-        this.setAttribute('longdesc', value);
-    },
-    get marginHeight(){
-        return this.getAttribute('marginheight')||&quot;&quot;;
-    },
-    set marginHeight(value){
-        this.setAttribute('marginheight', value);
-    },
-    get marginWidth(){
-        return this.getAttribute('marginwidth')||&quot;&quot;;
-    },
-    set marginWidth(value){
-        this.setAttribute('marginwidth', value);
-    },
-    get name(){
-        return this.getAttribute('name')||&quot;&quot;;
-    },
-    set name(value){
-        this.setAttribute('name', value);
-    },
-    get noResize(){
-        return this.getAttribute('noresize')||&quot;&quot;;
-    },
-    set noResize(value){
-        this.setAttribute('noresize', value);
-    },
-    get scrolling(){
-        return this.getAttribute('scrolling')||&quot;&quot;;
-    },
-    set scrolling(value){
-        this.setAttribute('scrolling', value);
-    },
-    get src(){
-        return this.getAttribute('src')||&quot;&quot;;
-    },
-    set src(value){
-        this.setAttribute('src', value);
-    },
-    get contentDocument(){
-        $log(&quot;getting content document for (i)frame&quot;);
-        if(!this._content){
-            this._content = new HTMLDocument($implementation);
-            if(this.src.length &gt; 0){
-                $log(&quot;Loading frame content from &quot; + this.src);
-                try{
-                    this._content.load(this.src);
-                }catch(e){
-                    $error(&quot;failed to load &quot; + this.src);
-                }
-            }
-        }
-        return true;
-    }
-});
-
-			$log(&quot;Defining HTMLFrameSetElement&quot;);
-/* 
-* HTMLFrameSetElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLFrameSetElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLFrameSetElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLFrameSetElement.prototype = new HTMLElement;
-__extend__(HTMLFrameSetElement.prototype, {
-    get cols(){
-        return this.getAttribute('cols');
-    },
-    set cols(value){
-        this.setAttribute('cols', value);
-    },
-    get rows(){
-        return this.getAttribute('rows');
-    },
-    set rows(value){
-        this.setAttribute('rows', value);
-    }
-});
-
-			$log(&quot;Defining HTMLHeadElement&quot;);
-/* 
-* HTMLHeadElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLHeadElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLHeadElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLHeadElement.prototype = new HTMLElement;
-__extend__(HTMLHeadElement.prototype, {
-    get profile(){
-        return this.getAttribute('profile');
-    },
-    set profile(value){
-        this.setAttribute('profile', value);
-    },
-});
-
-			$log(&quot;Defining HTMLIFrameElement&quot;);
-/* 
-* HTMLIFrameElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLIFrameElement&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var HTMLIFrameElement = function(ownerDocument) {
-    //$log(&quot;creating iframe element&quot;);
-    this.HTMLFrameElement = HTMLFrameElement;
-    this.HTMLFrameElement(ownerDocument);
-};
-HTMLIFrameElement.prototype = new HTMLFrameElement;
-__extend__(HTMLIFrameElement.prototype, {
-	get height() { 
-	    return this.getAttribute(&quot;height&quot;) || &quot;&quot;; 
-    },
-	set height(val) { 
-	    return this.setAttribute(&quot;height&quot;,val); 
-    },
-	get width() { 
-	    return this.getAttribute(&quot;width&quot;) || &quot;&quot;; 
-    },
-	set width(val) { 
-	    return this.setAttribute(&quot;width&quot;,val); 
-    }
-});
-
-
-			$log(&quot;Defining HTMLImageElement&quot;);
-/* 
-* HTMLImageElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLImageElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLImageElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLImageElement.prototype = new HTMLElement;
-__extend__(HTMLImageElement.prototype, {
-    get alt(){
-        return this.getAttribute('alt');
-    },
-    set alt(value){
-        this.setAttribute('alt', value);
-    },
-    get height(){
-        return this.getAttribute('height');
-    },
-    set height(value){
-        this.setAttribute('height', value);
-    },
-    get isMap(){
-        return this.hasAttribute('map');
-    },
-    set useMap(value){
-        this.setAttribute('map', value);
-    },
-    get longDesc(){
-        return this.getAttribute('longdesc');
-    },
-    set longDesc(value){
-        this.setAttribute('longdesc', value);
-    },
-    get name(){
-        return this.getAttribute('name');
-    },
-    set name(value){
-        this.setAttribute('name', value);
-    },
-    get src(){
-        return this.getAttribute('src');
-    },
-    set src(value){
-        this.setAttribute('src', value);
-    },
-    get width(){
-        return this.getAttribute('width');
-    },
-    set width(value){
-        this.setAttribute('width', value);
-    }
-});
-
-			$log(&quot;Defining HTMLInputElement&quot;);
-/* 
-* HTMLInputElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLInputElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLInputElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLInputElement.prototype = new HTMLElement;
-__extend__(HTMLInputElement.prototype, {
-    get defaultValue(){
-        return this.getAttribute('defaultValue');
-    },
-    set defaultValue(value){
-        this.setAttribute('defaultValue', value);
-    },
-    get defaultChecked(){
-        return this.getAttribute('defaultChecked');
-    },
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    },
-    get access(){
-        return this.getAttribute('access');
-    },
-    set access(value){
-        this.setAttribute('access', value);
-    },
-    get alt(){
-        return this.getAttribute('alt');
-    },
-    set alt(value){
-        this.setAttribute('alt', value);
-    },
-    get checked(){
-        return (this.getAttribute('checked')==='checked');
-    },
-    set checked(){
-        this.setAttribute('checked', 'checked');
-    },
-    get disabled(){
-        return (this.getAttribute('disabled')==='disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled', 'disabled');
-    },
-    get maxLength(){
-        return Number(this.getAttribute('maxlength')||'0');
-    },
-    set maxLength(value){
-        this.setAttribute('maxlength', value);
-    },
-    get name(){
-        return this.getAttribute('name')||'';
-    },
-    set name(value){
-        this.setAttribute('name', value);
-    },
-    get readOnly(){
-        return (this.getAttribute('readonly')==='readonly');
-    },
-    set readOnly(value){
-        this.setAttribute('readonly', 'readonly');
-    },
-    get size(){
-        return this.getAttribute('size');
-    },
-    set size(value){
-        this.setAttribute('size', value);
-    },
-    get src(){
-        return this.getAttribute('src');
-    },
-    set src(value){
-        this.setAttribute('src', value);
-    },
-    get tabIndex(){
-        return Number(this.getAttribute('tabindex'));
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',Number(value));
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-    get useMap(){
-        return this.getAttribute('map');
-    },
-    get value(){
-        return this.getAttribute('value');
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    },
-	blur:function(){
-	    __blur__(this);
-	    
-    },
-	focus:function(){
-	    __focus__(this);
-	    
-    },
-	select:function(){
-	    __select__(this);
-	    
-    },
-	click:function(){
-	    __click__(this);
-	    
-    }
-});
-
-			$log(&quot;Defining HTMLLabelElement&quot;);
-/* 
-* HTMLLabelElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLLabelElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLLabelElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLLabelElement.prototype = new HTMLElement;
-__extend__(HTMLLabelElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    },
-    get htmlFor(){
-        return this.getAttribute('for');
-    },
-    set htmlFor(value){
-        this.setAttribute('for',value);
-    },
-});
-
-			$log(&quot;Defining HTMLLegendElement&quot;);
-/* 
-* HTMLLegendElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLLegendElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLLegendElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLLegendElement.prototype = new HTMLElement;
-__extend__(HTMLLegendElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get accessKey(){
-        return this.getAttribute('accesskey');
-    },
-    set accessKey(value){
-        this.setAttribute('accesskey',value);
-    }
-});
-
-			/**
-* Link - HTMLElement 
-*/
-$w.__defineGetter__(&quot;Link&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-$log(&quot;Defining HTMLLinkElement&quot;);
-/* 
-* HTMLLinkElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLLinkElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLLinkElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLLinkElement.prototype = new HTMLElement;
-__extend__(HTMLLinkElement.prototype, {
-    get disabled(){
-        return this.getAttribute('disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled',value);
-    },
-    get charset(){
-        return this.getAttribute('charset');
-    },
-    set charset(value){
-        this.setAttribute('charset',value);
-    },
-    get href(){
-        return this.getAttribute('href');
-    },
-    set href(value){
-        this.setAttribute('href',value);
-    },
-    get hreflang(){
-        return this.getAttribute('hreflang');
-    },
-    set hreflang(value){
-        this.setAttribute('hreflang',value);
-    },
-    get media(){
-        return this.getAttribute('media');
-    },
-    set media(value){
-        this.setAttribute('media',value);
-    },
-    get rel(){
-        return this.getAttribute('rel');
-    },
-    set rel(value){
-        this.setAttribute('rel',value);
-    },
-    get rev(){
-        return this.getAttribute('rev');
-    },
-    set rev(value){
-        this.setAttribute('rev',value);
-    },
-    get target(){
-        return this.getAttribute('target');
-    },
-    set target(value){
-        this.setAttribute('target',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    }
-});
-
-			
-
-			$log(&quot;Defining HTMLMapElement&quot;);
-/* 
-* HTMLMapElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLMapElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLMapElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLMapElement.prototype = new HTMLElement;
-__extend__(HTMLMapElement.prototype, {
-    get areas(){
-        return this.getElementsByTagName('area');
-    },
-    get name(){
-        return this.getAttribute('name');
-    },
-    set name(value){
-        this.setAttribute('name',value);
-    }
-});
-
-			$log(&quot;Defining HTMLMetaElement&quot;);
-/* 
-* HTMLMetaElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLMetaElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLMetaElement = function(ownerDocument) {
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLMetaElement.prototype = new HTMLElement;
-__extend__(HTMLMetaElement.prototype, {
-    get content(){
-        return this.getAttribute('content');
-    },
-    set content(value){
-        this.setAttribute('content',value);
-    },
-    get httpEquiv(){
-        return this.getAttribute('http-equiv');
-    },
-    set httpEquiv(value){
-        this.setAttribute('http-equiv',value);
-    },
-    get name(){
-        return this.getAttribute('name');
-    },
-    set name(value){
-        this.setAttribute('name',value);
-    },
-    get scheme(){
-        return this.getAttribute('scheme');
-    },
-    set scheme(value){
-        this.setAttribute('scheme',value);
-    }
-});
-
-			$log(&quot;Defining HTMLObjectElement&quot;);
-/* 
-* HTMLObjectElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLObjectElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLObjectElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLObjectElement.prototype = new HTMLElement;
-__extend__(HTMLObjectElement.prototype, {
-    get code(){
-        return this.getAttribute('code');
-    },
-    set code(value){
-        this.setAttribute('code',value);
-    },
-    get archive(){
-        return this.getAttribute('archive');
-    },
-    set archive(value){
-        this.setAttribute('archive',value);
-    },
-    get codeBase(){
-        return this.getAttribute('codebase');
-    },
-    set codeBase(value){
-        this.setAttribute('codebase',value);
-    },
-    get codeType(){
-        return this.getAttribute('codetype');
-    },
-    set codeType(value){
-        this.setAttribute('codetype',value);
-    },
-    get data(){
-        return this.getAttribute('data');
-    },
-    set data(value){
-        this.setAttribute('data',value);
-    },
-    get declare(){
-        return this.getAttribute('declare');
-    },
-    set declare(value){
-        this.setAttribute('declare',value);
-    },
-    get height(){
-        return this.getAttribute('height');
-    },
-    set height(value){
-        this.setAttribute('height',value);
-    },
-    get standby(){
-        return this.getAttribute('standby');
-    },
-    set standby(value){
-        this.setAttribute('standby',value);
-    },
-    get tabIndex(){
-        return this.getAttribute('tabindex');
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-    get useMap(){
-        return this.getAttribute('usemap');
-    },
-    set useMap(value){
-        this.setAttribute('usemap',value);
-    },
-    get width(){
-        return this.getAttribute('width');
-    },
-    set width(value){
-        this.setAttribute('width',value);
-    },
-    get contentDocument(){
-        return this.ownerDocument;
-    }
-});
-
-			$log(&quot;Defining HTMLOptGroupElement&quot;);
-/* 
-* HTMLOptGroupElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLOptGroupElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLOptGroupElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLOptGroupElement.prototype = new HTMLElement;
-__extend__(HTMLOptGroupElement.prototype, {
-    get disabled(){
-        return this.getAttribute('disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled',value);
-    },
-    get label(){
-        return this.getAttribute('label');
-    },
-    set label(value){
-        this.setAttribute('label',value);
-    },
-});
-
-			$log(&quot;Defining HTMLOptionElement&quot;);
-/* 
-* HTMLOptionElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLOptionElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLOptionElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLOptionElement.prototype = new HTMLElement;
-__extend__(HTMLOptionElement.prototype, {
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get defaultSelected(){
-        return this.getAttribute('defaultSelected');
-    },
-    set defaultSelected(value){
-        this.setAttribute('defaultSelected',value);
-    },
-    get text(){
-        return this.nodeValue;
-    },
-    get index(){
-        var options = this.parent.childNodes;
-        for(var i; i&lt;options.length;i++){
-            if(this == options[i])
-                return i;
-        }
-        return -1;
-    },
-    get disabled(){
-        return this.getAttribute('disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled',value);
-    },
-    get label(){
-        return this.getAttribute('label');
-    },
-    set label(value){
-        this.setAttribute('label',value);
-    },
-    get selected(){
-        return (this.getAttribute('selected')==='selected');
-    },
-    set selected(){
-        this.setAttribute('selected','selected');
-    },
-    get value(){
-        return this.getAttribute('value');
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    }
-});
-
-			$log(&quot;Defining HTMLParamElement&quot;);
-/* 
-* HTMLParamElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLParamElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLParamElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLParamElement.prototype = new HTMLElement;
-__extend__(HTMLParamElement.prototype, {
-    get name(){
-        return this.getAttribute('name');
-    },
-    set name(value){
-        this.setAttribute('name',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-    get value(){
-        return this.getAttribute('value');
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    },
-    get valueType(){
-        return this.getAttribute('valuetype');
-    },
-    set valueType(value){
-        this.setAttribute('valuetype',value);
-    },
-});
-
-			$log(&quot;Defining HTMLScriptElement&quot;);
-/* 
-* HTMLScriptElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLScriptElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLScriptElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLScriptElement.prototype = new HTMLElement;
-__extend__(HTMLScriptElement.prototype, {
-    get text(){
-        return this.nodeValue;
-    },
-    get htmlFor(){
-        return this.getAttribute('for');
-    },
-    set htmlFor(value){
-        this.setAttribute('for',value);
-    },
-    get event(){
-        return this.getAttribute('event');
-    },
-    set event(value){
-        this.setAttribute('event',value);
-    },
-    get charset(){
-        return this.getAttribute('charset');
-    },
-    set charset(value){
-        this.setAttribute('charset',value);
-    },
-    get defer(){
-        return this.getAttribute('defer');
-    },
-    set defer(value){
-        this.setAttribute('defer',value);
-    },
-    get src(){
-        return this.getAttribute('src');
-    },
-    set src(value){
-        this.setAttribute('src',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    }
-});
-
-			$log(&quot;Defining HTMLSelectElement&quot;);
-/* 
-* HTMLSelectElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLSelectElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLSelectElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLSelectElement.prototype = new HTMLElement;
-__extend__(HTMLSelectElement.prototype, {
-    get type(){
-        return this.getAttribute('type');
-    },
-    get selectedIndex(){
-        var options = this.options;
-        for(var i=0;i&lt;options.length;i++){
-            if(options[i].selected){
-                return i;
-            }
-        };
-        return -1;
-    },
-    set selectedIndex(value){
-        this.options[Number(value)].selected = 'selected';
-    },
-    get value(){
-        return this.getAttribute('value')||'';
-    },
-    set value(value){
-        this.setAttribute('value',value);
-    },
-    get length(){
-        return this.options.length;
-    },
-    get form(){
-        var parent = this.parent;
-        while(parent.nodeName.toLowerCase() != 'form'){
-            parent = parent.parent;
-        }
-        return parent;
-    },
-    get options(){
-        return this.getElementsByTagName('option');
-    },
-    get disabled(){
-        return (this.getAttribute('disabled')==='disabled');
-    },
-    set disabled(){
-        this.setAttribute('disabled','disabled');
-    },
-    get multiple(){
-        return this.getAttribute('multiple');
-    },
-    set multiple(value){
-        this.setAttribute('multiple',value);
-    },
-    get name(){
-        return this.getAttribute('name')||'';
-    },
-    set name(value){
-        this.setAttribute('name',value);
-    },
-    get size(){
-        return Number(this.getAttribute('size'));
-    },
-    set size(value){
-        this.setAttribute('size',value);
-    },
-    get tabIndex(){
-        return Number(this.getAttribute('tabindex'));
-    },
-    set tabIndex(value){
-        this.setAttribute('tabindex',value);
-    },
-    add : function(){
-        __add__(this);
-    },
-    remove : function(){
-        __remove__(this);
-    },
-    blur: function(){
-        __blur__(this);
-    },
-    focus: function(){
-        __focus__(this);
-    }
-});
-
-			$log(&quot;Defining HTMLStyleElement&quot;);
-/* 
-* HTMLStyleElement - DOM Level 2
-*/
-$w.__defineGetter__(&quot;HTMLStyleElement&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-var HTMLStyleElement = function(ownerDocument) {
-    //$log(&quot;creating anchor element&quot;);
-    this.HTMLElement = HTMLElement;
-    this.HTMLElement(ownerDocument);
-};
-HTMLStyleElement.prototype = new HTMLElement;
-__extend__(HTMLStyleElement.prototype, {
-    get disabled(){
-        return this.getAttribute('disabled');
-    },
-    set disabled(value){
-        this.setAttribute('disabled',value);
-    },
-    get media(){
-        return this.getAttribute('media');
-    },
-    set media(value){
-        this.setAttribute('media',value);
-    },
-    get type(){
-        return this.getAttribute('type');
-    },
-    set type(value){
-        this.setAttribute('type',value);
-    },
-});
-
-			$log(&quot;Defining Event&quot;);
-/*
-* event.js
-*/
-$w.__defineGetter__(&quot;Event&quot;, function(){
-  __extend__(this,{
-    CAPTURING_PHASE : 1,
-    AT_TARGET       : 2,
-    BUBBLING_PHASE  : 3
-  });
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var Event = function(options){
-  if(options === undefined){options={target:window,currentTarget:window};}
-  __extend__(this,{
-    CAPTURING_PHASE : 1,
-    AT_TARGET       : 2,
-    BUBBLING_PHASE  : 3
-  });
-  $log(&quot;Creating new Event&quot;);
-  var $bubbles = options.bubbles?options.bubbles:true,
-      $cancelable = options.cancelable?options.cancelable:true,
-      $currentTarget = options.currentTarget?options.currentTarget:null,
-      $eventPhase = options.eventPhase?options.eventPhase:Event.CAPTURING_PHASE,
-      $target = options.eventPhase?options.eventPhase:document,
-      $timestamp = options.timestamp?options.timestamp:new Date().getTime().toString(),
-      $type = options.type?options.type:&quot;&quot;;
-  return __extend__(this,{
-    get bubbles(){return $bubbles;},
-    get cancelable(){return $cancelable;},
-    get currentTarget(){return $currentTarget;},
-    get eventPhase(){return $eventPhase;},
-    get target(){return $target;},
-    get timestamp(){return $timestamp;},
-    get type(){return $type;},
-    initEvent: function(type,bubbles,cancelable){
-      $type=type?type:$type;
-      $bubbles=bubbles?bubbles:$bubbles;
-      $cancelable=cancelable?cancelable:$cancelable;
-    },
-    preventDefault: function(){return;/* TODO */},
-    stopPropagation: function(){return;/* TODO */}
-  });
-};
-
-$log(&quot;Defining MouseEvent&quot;);
-/*
-*	mouseevent.js
-*/
-$log(&quot;Defining MouseEvent&quot;);
-/*
-*	uievent.js
-*/
-
-var $onblur,
-    $onfocus,
-    $onresize;/*
-* CSS2Properties - DOM Level 2 CSS
-*/
-$w.__defineGetter__(&quot;CSS2Properties&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-var CSS2Properties = function(options){
-    __extend__(this, __supportedStyles__);
-    __cssTextToStyles__(this, options.cssText?options.cssText:&quot;&quot;);
-};
-//__extend__(CSS2Properties.prototype, __supportedStyles__);
-__extend__(CSS2Properties.prototype, {
-    get cssText(){
-        return Array.prototype.apply.join(this,[';\n']);
-    },
-    set cssText(cssText){ 
-        __cssTextToStyles__(this, cssText); 
-    },
-    getPropertyCSSValue : function(){
-        
-    },
-    getPropertyPriority : function(){
-        
-    },
-    getPropertyValue : function(name){
-		var camelCase = name.replace(/\-(\w)/g, function(all, letter){
-			return letter.toUpperCase();
-		});
-        var i, value = this[camelCase];
-        if(value === undefined){
-            for(i=0;i&lt;this.length;i++){
-                if(this[i]===name){
-                    return this[i];
-                }
-            }
-        }
-        return value;
-    },
-    item : function(index){
-        return this[index];
-    },
-    removeProperty: function(){
-        
-    },
-    setProperty: function(){
-        
-    },
-    toString:function(){
-        if (this.length &gt;0){
-            return &quot;{\n\t&quot;+Array.prototype.join.apply(this,[';\n\t'])+&quot;}\n&quot;;
-        }else{
-            return '';
-        }
-    }
-});
-
-var __cssTextToStyles__ = function(css2props, cssText){
-    var styleArray=[];
-    var style, name, value, camelCaseName, w3cName, styles = cssText.split(';');
-    for ( var i = 0; i &lt; styles.length; i++ ) {
-        //$log(&quot;Adding style property &quot; + styles[i]);
-    	style = styles[i].split(':');
-    	if ( style.length == 2 ){
-    	    //keep a reference to the original name of the style which was set
-    	    //this is the w3c style setting method.
-    	    styleArray[styleArray.length] = w3cName = styles[i];
-            //camel case for dash case
-    	    value = trim(style[1]);
-            camelCaseName = trim(style[0].replace(/\-(\w)/g, function(all, letter){
-				return letter.toUpperCase();
-			}));
-            //$log('CSS Style Name:  ' + camelCaseName);
-            if(css2props[camelCaseName]!==undefined){
-                //set the value internally with camelcase name 
-                //$log('Setting css ' + camelCaseName + ' to ' + value);
-                css2props[camelCaseName] = value;
-            };
-    	}
-    }
-    __setArray__(css2props, styleArray);
-};
-//Obviously these arent all supported but by commenting out various sections
-//this provides a single location to configure what is exposed as supported.
-//These will likely need to be functional getters/setters in the future to deal with
-//the variation on input formulations
-var __supportedStyles__ = {
-    azimuth: &quot;&quot;,
-    background:	&quot;&quot;,
-    backgroundAttachment:	&quot;&quot;,
-    backgroundColor:	&quot;&quot;,
-    backgroundImage:	&quot;&quot;,
-    backgroundPosition:	&quot;&quot;,
-    backgroundRepeat:	&quot;&quot;,
-    border:	&quot;&quot;,
-    borderBottom:	&quot;&quot;,
-    borderBottomColor:	&quot;&quot;,
-    borderBottomStyle:	&quot;&quot;,
-    borderBottomWidth:	&quot;&quot;,
-    borderCollapse:	&quot;&quot;,
-    borderColor:	&quot;&quot;,
-    borderLeft:	&quot;&quot;,
-    borderLeftColor:	&quot;&quot;,
-    borderLeftStyle:	&quot;&quot;,
-    borderLeftWidth:	&quot;&quot;,
-    borderRight:	&quot;&quot;,
-    borderRightColor:	&quot;&quot;,
-    borderRightStyle:	&quot;&quot;,
-    borderRightWidth:	&quot;&quot;,
-    borderSpacing:	&quot;&quot;,
-    borderStyle:	&quot;&quot;,
-    borderTop:	&quot;&quot;,
-    borderTopColor:	&quot;&quot;,
-    borderTopStyle:	&quot;&quot;,
-    borderTopWidth:	&quot;&quot;,
-    borderWidth:	&quot;&quot;,
-    bottom:	&quot;&quot;,
-    captionSide:	&quot;&quot;,
-    clear:	&quot;&quot;,
-    clip:	&quot;&quot;,
-    color:	&quot;&quot;,
-    content:	&quot;&quot;,
-    counterIncrement:	&quot;&quot;,
-    counterReset:	&quot;&quot;,
-    cssFloat:	&quot;&quot;,
-    cue:	&quot;&quot;,
-    cueAfter:	&quot;&quot;,
-    cueBefore:	&quot;&quot;,
-    cursor:	&quot;&quot;,
-    direction:	&quot;&quot;,
-    display:	&quot;&quot;,
-    elevation:	&quot;&quot;,
-    emptyCells:	&quot;&quot;,
-    font:	&quot;&quot;,
-    fontFamily:	&quot;&quot;,
-    fontSize:	&quot;&quot;,
-    fontSizeAdjust:	&quot;&quot;,
-    fontStretch:	&quot;&quot;,
-    fontStyle:	&quot;&quot;,
-    fontVariant:	&quot;&quot;,
-    fontWeight:	&quot;&quot;,
-    height:	&quot;&quot;,
-    left:	&quot;&quot;,
-    letterSpacing:	&quot;&quot;,
-    lineHeight:	&quot;&quot;,
-    listStyle:	&quot;&quot;,
-    listStyleImage:	&quot;&quot;,
-    listStylePosition:	&quot;&quot;,
-    listStyleType:	&quot;&quot;,
-    margin:	&quot;&quot;,
-    marginBottom:	&quot;&quot;,
-    marginLeft:	&quot;&quot;,
-    marginRight:	&quot;&quot;,
-    marginTop:	&quot;&quot;,
-    markerOffset:	&quot;&quot;,
-    marks:	&quot;&quot;,
-    maxHeight:	&quot;&quot;,
-    maxWidth:	&quot;&quot;,
-    minHeight:	&quot;&quot;,
-    minWidth:	&quot;&quot;,
-    opacity:	1,
-    orphans:	&quot;&quot;,
-    outline:	&quot;&quot;,
-    outlineColor:	&quot;&quot;,
-    outlineOffset:	&quot;&quot;,
-    outlineStyle:	&quot;&quot;,
-    outlineWidth:	&quot;&quot;,
-    overflow:	&quot;&quot;,
-    overflowX:	&quot;&quot;,
-    overflowY:	&quot;&quot;,
-    padding:	&quot;&quot;,
-    paddingBottom:	&quot;&quot;,
-    paddingLeft:	&quot;&quot;,
-    paddingRight:	&quot;&quot;,
-    paddingTop:	&quot;&quot;,
-    page:	&quot;&quot;,
-    pageBreakAfter:	&quot;&quot;,
-    pageBreakBefore:	&quot;&quot;,
-    pageBreakInside:	&quot;&quot;,
-    pause:	&quot;&quot;,
-    pauseAfter:	&quot;&quot;,
-    pauseBefore:	&quot;&quot;,
-    pitch:	&quot;&quot;,
-    pitchRange:	&quot;&quot;,
-    position:	&quot;&quot;,
-    quotes:	&quot;&quot;,
-    richness:	&quot;&quot;,
-    right:	&quot;&quot;,
-    size:	&quot;&quot;,
-    speak:	&quot;&quot;,
-    speakHeader:	&quot;&quot;,
-    speakNumeral:	&quot;&quot;,
-    speakPunctuation:	&quot;&quot;,
-    speechRate:	&quot;&quot;,
-    stress:	&quot;&quot;,
-    tableLayout:	&quot;&quot;,
-    textAlign:	&quot;&quot;,
-    textDecoration:	&quot;&quot;,
-    textIndent:	&quot;&quot;,
-    textShadow:	&quot;&quot;,
-    textTransform:	&quot;&quot;,
-    top:	&quot;&quot;,
-    unicodeBidi:	&quot;&quot;,
-    verticalAlign:	&quot;&quot;,
-    visibility:	&quot;&quot;,
-    voiceFamily:	&quot;&quot;,
-    volume:	&quot;&quot;,
-    whiteSpace:	&quot;&quot;,
-    widows:	&quot;&quot;,
-    width:	&quot;&quot;,
-    wordSpacing:	&quot;&quot;,
-    zIndex:	&quot;&quot;
-};/* 
-* CSSRule - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CSSRule&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var CSSRule = function(options){
-  var $style, 
-      $selectorText = options.selectorText?options.selectorText:&quot;&quot;;
-      $style = new CSS2Properties({cssText:options.cssText?options.cssText:null});
-    return __extend__(this, {
-      get style(){return $style;},
-      get selectorText(){return $selectorText;},
-      set selectorText(selectorText){$selectorText = selectorText;}
-    });
-};
-/* 
-* CSSStyleSheet - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CSSStyleSheet&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var CSSStyleSheet = function(options){
-    var $cssRules, 
-        $disabled = options.disabled?options.disabled:false,
-        $href = options.href?options.href:null,
-        $parentStyleSheet = options.parentStyleSheet?options.parentStyleSheet:null,
-        $title = options.title?options.title:&quot;&quot;,
-        $type = &quot;text/css&quot;;
-        
-    function parseStyleSheet(text){
-      //this is pretty ugly, but text is the entire text of a stylesheet
-      var cssRules = [];
-    	if (!text) text = &quot;&quot;;
-    	text = trim(text.replace(/\/\*(\r|\n|.)*\*\//g,&quot;&quot;));
-    	// TODO: @import ?
-    	var blocks = text.split(&quot;}&quot;);
-    	blocks.pop();
-    	var i, len = blocks.length;
-    	var definition_block, properties, selectors;
-    	for (i=0; i&lt;len; i++){
-    		definition_block = blocks[i].split(&quot;{&quot;);
-    		if(definition_block.length === 2){
-      		selectors = definition_block[0].split(&quot;,&quot;);
-      		for(var j=0;j&lt;selectors.length;j++){
-      		  cssRules.push(new CSSRule({
-      		    selectorText:selectors[j],
-      		    cssText:definition_block[1]
-      		  }));
-      		}
-      		__setArray__($cssRules, cssRules);
-    		}
-    	}
-    };
-    parseStyleSheet(options.text);
-    return __extend__(this, {
-      get cssRules(){return $cssRules;},
-      get rule(){return $cssRules;},//IE - may be deprecated
-      get href(){return $href;},
-      get parentStyleSheet(){return $parentStyleSheet;},
-      get title(){return $title;},
-      get type(){return $type;},
-      addRule: function(selector, style, index){/*TODO*/},
-      deleteRule: function(index){/*TODO*/},
-      insertRule: function(rule, index){/*TODO*/},
-      removeRule: function(index){this.deleteRule(index);}//IE - may be deprecated
-    });
-};
-/*
-*	location.js
-*   - requires env
-*/
-$log(&quot;Initializing Window Location.&quot;);
-//the current location
-var $location = $env.location('./');
-
-$w.__defineSetter__(&quot;location&quot;, function(url){
-  //$w.onunload();
-	$w.document.load(url);
-	$location = url;
-	setHistory($location);
-});
-
-$w.__defineGetter__(&quot;location&quot;, function(url){
-	var hash 	 = new RegExp('(\\#.*)'),
-		hostname = new RegExp('\/\/([^\:\/]+)'),
-		pathname = new RegExp('(\/[^\\?\\#]*)'),
-		port 	 = new RegExp('\:(\\d+)\/'),
-		protocol = new RegExp('(^\\w*\:)'),
-		search 	 = new RegExp('(\\?[^\\#]*)');
-	return {
-		get hash(){
-			var m = hash.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set hash(_hash){
-			//setting the hash is the only property of the location object
-			//that doesn't cause the window to reload
-			_hash = _hash.indexOf('#')===0?_hash:&quot;#&quot;+_hash;	
-			$location = this.protocol + this.host + this.pathname + 
-				this.search + _hash;
-			setHistory(_hash, &quot;hash&quot;);
-		},
-		get host(){
-			return this.hostname + (this.port !== &quot;&quot;)?&quot;:&quot;+this.port:&quot;&quot;;
-		},
-		set host(_host){
-			$w.location = this.protocol + _host + this.pathname + 
-				this.search + this.hash;
-		},
-		get hostname(){
-			var m = hostname.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set hostname(_hostname){
-			$w.location = this.protocol + _hostname + ((this.port===&quot;&quot;)?&quot;&quot;:(&quot;:&quot;+this.port)) +
-			 	 this.pathname + this.search + this.hash;
-		},
-		get href(){
-			//This is the only env specific function
-			return $location;
-		},
-		set href(url){
-			$w.location = url;	
-		},
-		get pathname(){
-			var m = this.href;
-			m = pathname.exec(m.substring(m.indexOf(this.hostname)));
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;/&quot;;
-		},
-		set pathname(_pathname){
-			$w.location = this.protocol + this.host + _pathname + 
-				this.search + this.hash;
-		},
-		get port(){
-			var m = port.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set port(_port){
-			$w.location = this.protocol + this.hostname + &quot;:&quot;+_port + this.pathname + 
-				this.search + this.hash;
-		},
-		get protocol(){
-			return protocol.exec(this.href)[0];
-		},
-		set protocol(_protocol){
-			$w.location = _protocol + this.host + this.pathname + 
-				this.search + this.hash;
-		},
-		get search(){
-			var m = search.exec(this.href);
-			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
-		},
-		set search(_search){
-			$w.location = this.protocol + this.host + this.pathname + 
-				_search + this.hash;
-		},
-		toString: function(){
-			return this.href;
-		},
-		reload: function(force){
-			//TODO
-		},
-		replace: function(url){
-			//TODO
-		}
-	};
-});
-
-/*
-*	history.js
-*/
-
-  $log(&quot;Initializing Window History.&quot;);
-	$currentHistoryIndex = 0;
-	$history = [];
-	
-	// Browser History
-	$w.__defineGetter__(&quot;history&quot;, function(){	
-		return {
-			get length(){ return $history.length; },
-			back : function(count){
-				if(count){
-					go(-count);
-				}else{go(-1);}
-			},
-			forward : function(count){
-				if(count){
-					go(count);
-				}else{go(1);}
-			},
-			go : function(target){
-				if(typeof target == &quot;number&quot;){
-					target = $currentHistoryIndex+target;
-					if(target &gt; -1 &amp;&amp; target &lt; $history.length){
-						if($history[target].location == &quot;hash&quot;){
-							$w.location.hash = $history[target].value;
-						}else{
-							$w.location = $history[target].value;
-						}
-						$currentHistoryIndex = target;
-						//remove the last item added to the history
-						//since we are moving inside the history
-						$history.pop();
-					}
-				}else{
-					//TODO: walk throu the history and find the 'best match'
-				}
-			}
-		};
-	});
-
-	//Here locationPart is the particutlar method/attribute 
-	// of the location object that was modified.  This allows us
-	// to modify the correct portion of the location object
-	// when we navigate the history
-	var setHistory = function( value, locationPart){
-	  $log(&quot;adding value to history: &quot; +value);
-		$currentHistoryIndex++;
-		$history.push({
-			location: locationPart||&quot;href&quot;,
-			value: value
-		});
-	};
-	/*
-*	navigator.js
-*   - requires env
-*/
-$log(&quot;Initializing Window Navigator.&quot;);
-
-var $appCodeName  = &quot;EnvJS&quot;;//eg &quot;Mozilla&quot;
-var $appName      = &quot;Resig/20070309 BirdDog/0.0.0.1&quot;;//eg &quot;Gecko/20070309 Firefox/2.0.0.3&quot;
-
-// Browser Navigator
-$w.__defineGetter__(&quot;navigator&quot;, function(){	
-	return {
-		get appCodeName(){
-			return $appCodeName;
-		},
-		get appName(){
-			return $appName;
-		},
-		get appVersion(){
-			return $version +&quot; (&quot;+ 
-			    $w.navigator.platform +&quot;; &quot;+
-			    &quot;U; &quot;+//?
-			    $env.os_name+&quot; &quot;+$env.os_arch+&quot; &quot;+$env.os_version+&quot;; &quot;+
-			    $env.lang+&quot;; &quot;+
-			    &quot;rv:&quot;+$revision+
-			  &quot;)&quot;;
-		},
-		get cookieEnabled(){
-			return true;
-		},
-		get mimeTypes(){
-			return [];
-		},
-		get platform(){
-			return $env.platform;
-		},
-		get plugins(){
-			return [];
-		},
-		get userAgent(){
-			return $w.navigator.appCodeName + &quot;/&quot; + $w.navigator.appVersion + &quot; &quot; + $w.navigator.appName;
-		},
-		javaEnabled : function(){
-			return $env.javaEnabled;	
-		}
-	};
-});
-
-/*
-*	timer.js
-*/
-	
-
-$log(&quot;Initializing Window Timer.&quot;);
-
-//private
-var $timers = [];
-
-$w.setTimeout = function(fn, time){
-	var num;
-	return num = window.setInterval(function(){
-		fn();
-		window.clearInterval(num);
-	}, time);
-};
-
-window.setInterval = function(fn, time){
-	var num = $timers.length;
-	if(time===0){
-	    fn();
-	}else{
-    	$timers[num] = $env.timer(fn, time);
-    	$timers[num].start();
-	}
-	return num;
-};
-
-window.clearInterval = window.clearTimeout = function(num){
-	if ( $timers[num] ) {
-		$timers[num].stop();
-		delete $timers[num];
-	}
-};	
-	/*
-* event.js
-*/
-// Window Events
-$log(&quot;Initializing Window Event.&quot;);
-var $events = [{}],
-    $onerror,
-    $onload,
-    $onunload;
-
-$w.addEventListener = function(type, fn){
-  $log(&quot;adding event listener &quot; + type);
-	if ( !this.uuid || this == window ) {
-		this.uuid = $events.length;
-		$events[this.uuid] = {};
-	}
-	if ( !$events[this.uuid][type] ){
-		$events[this.uuid][type] = [];
-	}
-	if ( $events[this.uuid][type].indexOf( fn ) &lt; 0 ){
-		$events[this.uuid][type].push( fn );
-	}
-};
-
-$w.removeEventListener = function(type, fn){
-  if ( !this.uuid || this == window ) {
-    this.uuid = $events.length;
-    $events[this.uuid] = {};
-  }
-  if ( !$events[this.uuid][type] ){
-		$events[this.uuid][type] = [];
-	}	
-  $events[this.uuid][type] =
-    $events[this.uuid][type].filter(function(f){
-			return f != fn;
-		});
-};
-$w.dispatchEvent = function(event){
-  if(!event.target)
-    event.target = this;
-  if ( event.type ) {
-    if ( this.uuid &amp;&amp; events[this.uuid][event.type] ) {
-      var self = this;
-      events[this.uuid][event.type].forEach(function(fn){
-        fn.call( self, event );
-    });
-  }
-    
-  if ( this[&quot;on&quot; + event.type] )
-    this[&quot;on&quot; + event.type].call( self, event );
-  }
-  if(this.parentNode){
-    this.parentNode.dispatchEvent.call(this.parentNode,event);
-  }
-};
-$w.dispatchEvent = function(event){
-    $log(&quot;dispatching event &quot; + event.type);
-    //the window scope defines the $event object, for IE(^^^) compatibility;
-    $event = event;
-    if(!event.target)
-        event.target = this;
-    if ( event.type ) {
-        if ( this.uuid &amp;&amp; events[this.uuid][event.type] ) {
-            var _this = this;
-            events[this.uuid][event.type].forEach(function(fn){
-                fn.call( _this, event );
-            });
-        }
-    
-        if ( this[&quot;on&quot; + event.type] )
-            this[&quot;on&quot; + event.type].call( _this, event );
-    }
-    if(this.parentNode){
-        this.parentNode.dispatchEvent.call(this.parentNode,event);
-    }
-};
-	
-$w.__defineGetter__('onerror', function(){
-  return function(){
-   //$w.dispatchEvent('error');
-  };
-});
-
-$w.__defineSetter__('onerror', function(fn){
-  //$w.addEventListener('error', fn);
-});
-
-/*$w.__defineGetter__('onload', function(){
-  return function(){
-		//var event = document.createEvent();
-		//event.initEvent(&quot;load&quot;);
-   //$w.dispatchEvent(event);
-  };
-});
-
-$w.__defineSetter__('onload', function(fn){
-  //$w.addEventListener('load', fn);
-});
-
-$w.__defineGetter__('onunload', function(){
-  return function(){
-   //$w.dispatchEvent('unload');
-  };
-});
-
-$w.__defineSetter__('onunload', function(fn){
-  //$w.addEventListener('unload', fn);
-});*//*
-*	xhr.js
-*/
-$log(&quot;Initializing Window XMLHttpRequest.&quot;);
-// XMLHttpRequest
-// Originally implemented by Yehuda Katz
-$w.XMLHttpRequest = function(){
-	this.headers = {};
-	this.responseHeaders = {};
-};
-
-XMLHttpRequest.prototype = {
-	open: function(method, url, async, user, password){ 
-		this.readyState = 1;
-		if (async === false ){
-			this.async = false;
-		}else{ this.async = true; }
-		this.method = method || &quot;GET&quot;;
-		this.url = $env.location(url);
-		this.onreadystatechange();
-	},
-	setRequestHeader: function(header, value){
-		this.headers[header] = value;
-	},
-	getResponseHeader: function(header){ },
-	send: function(data){
-		var self = this;
-		
-		function makeRequest(){
-			$env.connection(self, function(){
-			  var responseXML = null;
-				self.__defineGetter__(&quot;responseXML&quot;, function(){
-  				if ( self.responseText.match(/^\s*&lt;/) ) {
-  				  if(responseXML){return responseXML;}
-  				  else{
-    					try {
-    					  $log(&quot;parsing response text into xml document&quot;);
-    						responseXML = $domparser.parseFromString(self.responseText);
-  					    return responseXML;
-    					} catch(e) { return null;/*TODO: need to flag an error here*/}
-  					}
-  				}else{return null;}
-  			});
-			});
-			self.onreadystatechange();
-		}
-		if (this.async){
-		  $log(&quot;XHR sending asynch;&quot;);
-			$env.runAsync(makeRequest);
-		}else{
-		  $log(&quot;XHR sending synch;&quot;);
-			makeRequest();
-		}
-	},
-	abort: function(){
-		//TODO
-	},
-	onreadystatechange: function(){
-		//TODO
-	},
-	getResponseHeader: function(header){
-	  var rHeader, returnedHeaders;
-		if (this.readyState &lt; 3){
-			throw new Error(&quot;INVALID_STATE_ERR&quot;);
-		} else {
-			returnedHeaders = [];
-			for (rHeader in this.responseHeaders) {
-				if (rHeader.match(new RegExp(header, &quot;i&quot;)))
-					returnedHeaders.push(this.responseHeaders[rHeader]);
-			}
-			if (returnedHeaders.length){ return returnedHeaders.join(&quot;, &quot;); }
-		}return null;
-	},
-	getAllResponseHeaders: function(){
-	  var header, returnedHeaders = [];
-		if (this.readyState &lt; 3){
-			throw new Error(&quot;INVALID_STATE_ERR&quot;);
-		} else {
-			for (header in this.responseHeaders){
-				returnedHeaders.push( header + &quot;: &quot; + this.responseHeaders[header] );
-			}
-		}return returnedHeaders.join(&quot;\r\n&quot;);
-	},
-	async: true,
-	readyState: 0,
-	responseText: &quot;&quot;,
-	status: 0
-};/*
-*	css.js
-*/
-$log(&quot;Initializing Window CSS&quot;);
-// returns a CSS2Properties object that represents the style
-// attributes and values used to render the specified element in this
-// window.  Any length values are always expressed in pixel, or
-// absolute values.
-$w.getComputedStyle = function(elt, pseudo_elt){
-  //TODO
-  //this is a naive implementation
-  $log(&quot;Getting computed style&quot;);
-  return elt?elt.style:new CSS2Properties({cssText:&quot;&quot;});
-};/*
-*	screen.js
-*/
-$log(&quot;Initializing Window Screen.&quot;);
-
-var $availHeight  = 600,
-    $availWidth   = 800,
-    $colorDepth    = 16,
-    $height       = 600,
-    $width        = 800;
-    
-$w.__defineGetter__(&quot;screen&quot;, function(){
-  return {
-    get availHeight(){return $availHeight;},
-    get availWidth(){return $availWidth;},
-    get colorDepth(){return $colorDepth;},
-    get height(){return $height;},
-    get width(){return $width;}
-  };
-});
-
-
-$w.moveBy = function(dx,dy){
-  //TODO
-};
-
-$w.moveTo = function(x,y) {
-  //TODO
-};
-
-/*$w.print = function(){
-  //TODO
-};*/
-
-$w.resizeBy = function(dw, dh){
-  $w.resizeTo($width+dw,$height+dh);
-};
-
-$w.resizeTo = function(width, height){
-  $width = (width &lt;= $availWidth) ? width : $availWidth;
-  $height = (height &lt;= $availHeight) ? height : $availHeight;
-};
-
-$w.scrollBy = function(dx, dy){
-  //TODO
-};
-$w.scrollTo = function(x,y){
-  //TODO
-};/*
-*	dialog.js
-*/
-$log(&quot;Initializing Window Dialogs.&quot;);
-$w.alert = function(message){
- //TODO 
-};
-
-$w.confirm = function(question){
-  //TODO
-};
-
-$w.prompt = function(message, defaultMsg){
-  //TODO
-};/*
-*	document.js
-*
-*	DOM Level 2 /DOM level 3 (partial)
-*	
-*	This file adds the document object to the window and allows you
-*	you to set the window.document using an html string or dom object.
-*
-*/
-
-// read only reference to the Document object
-
-$log(&quot;Initializing window.document.&quot;);
-var $async = false;
-__extend__(HTMLDocument.prototype, {
-	get async(){ return $async;},
-	set async(async){ $async = async; },
-	get baseURI(){ return $env.location('./'); },
-	get URL(){ return $w.location.href;  }
-});
-	
-
-var $document =  new HTMLDocument($implementation);
-$w.__defineGetter__(&quot;document&quot;, function(){
-	return $document;
-});
-/*
-*	outro.js
-*/
-
-})(window, __env__); 
-
-}catch(e){
-    __env__.error(&quot;ERROR LOADING ENV : &quot; + e + &quot;\nLINE SOURCE:\n&quot; +e.rhinoException.lineSource());
-}
+/*
+*	env.rhino.js
+*/
+var __env__ = {};
+(function($env){
+	
+  $env.debug = function(){};
+  
+  $env.log = function(){};
+  //uncomment this if you want to get some internal log statementes
+  $env.log = print;
+  $env.log(&quot;Initializing Rhino Platform Env&quot;);
+  
+  $env.error = function(msg, e){
+    print(&quot;ERROR! : &quot; + msg);
+    print(e);
+  };
+  
+  $env.hashCode = function(obj){
+    return obj?obj.hashCode().toString():null;
+  };
+	//For Java the window.location object is a java.net.URL
+	$env.location = function(path, base){
+	  var protocol = new RegExp('(^\\w*\:)');
+		var m = protocol.exec(path);
+		if(m&amp;&amp;m.length&gt;1){
+			return new java.net.URL(path).toString();
+		}else if(base){
+		  return new java.net.URL(base + '/' + path).toString();
+		}else{
+			//return an absolute url from a relative to the file system
+			return new java.io.File(path).toURL().toString();
+		}
+	};
+	
+	//For Java the window.timer is created using the java.lang.Thread in combination
+	//with the java.lang.Runnable
+	$env.timer = function(fn, time){
+		return new java.lang.Thread(new java.lang.Runnable({
+			run: function(){
+				while (true){
+					java.lang.Thread.currentThread().sleep(time);
+					fn();
+				}
+			}
+		}));
+	};	
+	
+	//Since we're running in rhino I guess we can safely assume
+	//java is 'enabled'.  I'm sure this requires more thought
+	//than I've given it here
+	$env.javaEnabled = true;	
+	
+	
+	//Used in the XMLHttpRquest implementation to run a
+	// request in a seperate thread
+	$env.runAsync = function(fn){
+		(new java.lang.Thread(new java.lang.Runnable({
+			run: fn
+		}))).start();
+	};
+	
+	//Used to write to a local file
+	$env.writeToFile = function(text, url){
+		var out = new java.io.FileWriter( 
+			new java.io.File( 
+				new java.net.URI(url.toString())));				
+		out.write( text, 0, text.length );
+		out.flush();
+		out.close();
+	};
+	
+	//Used to delete a local file
+	$env.deleteFile = function(url){
+		var file = new java.io.File( new java.net.URI( url ) );
+        file[&quot;delete&quot;]();
+	};
+	
+	$env.connection = function(xhr, responseHandler){
+		var url = java.net.URL(xhr.url);//, $w.location);
+	  var connection;
+		if ( /^file\:/.test(url) ) {
+			if ( xhr.method == &quot;PUT&quot; ) {
+				var text =  data || &quot;&quot; ;
+				$env.writeToFile(text, url);
+			} else if ( xhr.method == &quot;DELETE&quot; ) {
+				$env.deleteFile(url);
+			} else {
+				connection = url.openConnection();
+				connection.connect();
+			}
+		} else { 
+			connection = url.openConnection();
+			connection.setRequestMethod( xhr.method );
+			
+			// Add headers to Java connection
+			for (var header in xhr.headers){
+				connection.addRequestProperty(header, xhr.headers[header]);
+		  }connection.connect();
+			
+			// Stick the response headers into responseHeaders
+			for (var i = 0; ; i++) { 
+				var headerName = connection.getHeaderFieldKey(i); 
+				var headerValue = connection.getHeaderField(i); 
+				if (!headerName &amp;&amp; !headerValue) break; 
+				if (headerName)
+					xhr.responseHeaders[headerName] = headerValue;
+			}
+		}
+		if(connection){
+				xhr.readyState = 4;
+				xhr.status = parseInt(connection.responseCode,10) || undefined;
+				xhr.statusText = connection.responseMessage || &quot;&quot;;
+				
+				var contentEncoding = connection.getContentEncoding() || &quot;utf-8&quot;,
+					stream = (contentEncoding.equalsIgnoreCase(&quot;gzip&quot;) || contentEncoding.equalsIgnoreCase(&quot;decompress&quot;) )?
+   							new java.util.zip.GZIPInputStream(connection.getInputStream()) :
+   							connection.getInputStream(),
+					baos = new java.io.ByteArrayOutputStream(),
+   				buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024),
+					length,
+					responseXML = null;
+
+				while ((length = stream.read(buffer)) != -1) {
+					baos.write(buffer, 0, length);
+				}
+
+				baos.close();
+				stream.close();
+
+				xhr.responseText = java.nio.charset.Charset.forName(contentEncoding).
+					decode(java.nio.ByteBuffer.wrap(baos.toByteArray())).toString();
+				
+		}
+		if(responseHandler){
+		  responseHandler();
+		}
+	};
+	
+	var htmlDocBuilder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
+	htmlDocBuilder.setNamespaceAware(false);
+	htmlDocBuilder.setValidating(false);
+	
+	$env.parseHTML = function(htmlstring){
+		return htmlDocBuilder.newDocumentBuilder().parse(
+				  new java.io.ByteArrayInputStream(
+						(new java.lang.String(htmlstring)).getBytes(&quot;UTF8&quot;)));
+	};
+	
+	var xmlDocBuilder = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
+	xmlDocBuilder.setNamespaceAware(true);
+	xmlDocBuilder.setValidating(true);
+	
+	$env.parseXML = function(xmlstring){
+		return xmlDocBuilder.newDocumentBuilder().parse(
+				  new java.io.ByteArrayInputStream(
+						(new java.lang.String(xmlstring)).getBytes(&quot;UTF8&quot;)));
+	};
+	
+	
+    $env.xpath = function(expression, doc){
+    return Packages.javax.xml.xpath.
+      XPathFactory.newInstance().newXPath().
+        evaluate(expression, doc, javax.xml.xpath.XPathConstants.NODESET);
+    };
+    
+    $env.os_name        = java.lang.System.getProperty(&quot;os.name&quot;); 
+    $env.os_arch        = java.lang.System.getProperty(&quot;os.arch&quot;); 
+    $env.os_version     = java.lang.System.getProperty(&quot;os.version&quot;); 
+    $env.lang           = java.lang.System.getProperty(&quot;user.lang&quot;); 
+    $env.platform       = &quot;Rhino &quot;;//how do we get the version
+	
+    
+    $env.loadScripts = safeScript;
+    function safeScript(){
+      //do nothing  
+    };
+    
+    function localScripts(){
+        //try loading locally
+        var scripts = document.getElementsByTagName('script');
+        for(var i=0;i&lt;scipts.length;i++){
+            if(scripts[i].getAttribute('type') == 'text/javascript'){
+                try{
+                    load(scripts[i].src);
+                }catch(e){
+                    $error(&quot;Error loading script.&quot; , e);
+                }
+            }
+        }
+    };
+})(__env__);/*
+ * Pure JavaScript Browser Environment
+ *   By John Resig &lt;http://ejohn.org/&gt;
+ * Copyright 2008 John Resig, under the MIT License
+ */
+ 
+
+// The Window Object
+var __this__ = this;
+this.__defineGetter__('window', function(){
+  return __this__;
+});
+try{
+(function($w, $env){
+        /*
+*	window.js
+*   - this file will be wrapped in a closure providing the window object as $w
+*/
+// a logger or empty function available to all modules.
+var $log = $env.log,
+    $error = $env.error,
+    $debug = $env.debug;
+//The version of this application
+var $version = &quot;0.1&quot;;
+//This should be hooked to git or svn or whatever
+var $revision = &quot;0.0.0.0&quot;;
+
+//These descriptions of window properties are taken loosely David Flanagan's
+//'JavaScript - The Definitive Guide' (O'Reilly)
+
+/**&gt; $cookies - see cookie.js &lt;*/
+// read only boolean specifies whether the window has been closed
+var $closed = false;
+
+// a read/write string that specifies the default message that appears in the status line 
+var $defaultStatus = &quot;Done&quot;;
+
+// a read-only reference to the Document object belonging to this window
+/**&gt; $document - See document.js &lt;*/
+
+//IE only, refers to the most recent event object - this maybe be removed after review
+var $event = null;
+
+//A read-only array of window objects
+var $frames = [];
+
+// a read-only reference to the History object
+/**&gt;  $history - see location.js &lt;**/
+
+// read-only properties that specify the height and width, in pixels
+var $innerHeight = 600, $innerWidth = 800;
+
+// a read-only reference to the Location object.  the location object does expose read/write properties
+/**&gt; $location - see location.js &lt;**/
+
+// a read only property specifying the name of the window.  Can be set when using open()
+// and may be used when specifying the target attribute of links
+var $name = 'Resig Env Browser';
+
+// a read-only reference to the Navigator object
+/**&gt; $navigator - see navigator.js &lt;**/
+
+// a read/write reference to the Window object that contained the script that called open() to 
+//open this browser window.  This property is valid only for top-level window objects.
+var $opener;
+
+// Read-only properties that specify the total height and width, in pixels, of the browser window.
+// These dimensions include the height and width of the menu bar, toolbars, scrollbars, window
+// borders and so on.  These properties are not supported by IE and IE offers no alternative 
+// properties;
+var $outerHeight = $innerHeight, $outerWidth = $innerWidth;
+
+// Read-only properties that specify the number of pixels that the current document has been scrolled
+//to the right and down.  These are not supported by IE.
+var $pageXOffset = 0, $pageYOffest = 0;
+
+//A read-only reference to the Window object that contains this window or frame.  If the window is
+// a top-level window, parent refers to the window itself.  If this window is a frame, this property
+// refers to the window or frame that conatins it.
+var $parent;
+
+// a read-only refernce to the Screen object that specifies information about the screen: 
+// the number of available pixels and the number of available colors.
+/**&gt; $screen - see screen.js &lt;**/
+
+// read only properties that specify the coordinates of the upper-left corner of the screen.
+var $screenX = 0, $screenY = 0;
+var $screenLeft = $screenX, $screenTop = $screenY;
+
+// a read-only refernce to this window itself.
+var $self;
+
+// a read/write string that specifies the current contents of the status line.
+var $status = '';
+
+// a read-only reference to the top-level window that contains this window.  If this
+// window is a top-level window it is simply a refernce to itself.  If this window 
+// is a frame, the top property refers to the top-level window that contains the frame.
+var $top;
+
+// the window property is identical to the self property.
+var $window = $w;
+
+$log(&quot;Initializing Window.&quot;);
+__extend__($w,{
+  get closed(){return $closed;},
+  get defaultStatus(){return $defaultStatus;},
+  set defaultStatus(_defaultStatus){$defaultStatus = _defaultStatus;},
+  //get document(){return $document;}, - see document.js
+  get event(){return $event;},
+  get frames(){return $frames;},
+  //get history(){return $history;}, - see location.js
+  get innerHeight(){return $innerHeight;},
+  get innerWidth(){return $innerWidth;},
+  get clientHeight(){return $innerHeight;},
+  get clientWidth(){return $innerWidth;},
+  //get location(){return $location;}, see location.js
+  get name(){return $name;},
+  //get navigator(){return $navigator;}, see navigator.js
+  get opener(){return $opener;},
+  get outerHeight(){return $outerHeight;},
+  get outerWidth(){return $outerWidth;},
+  get pageXOffest(){return $pageXOffset;},
+  get pageYOffset(){return $pageYOffset;},
+  get parent(){return $parent;},
+  //get screen(){return $screen;}, see screen.js
+  get screenLeft(){return $screenLeft;},
+  get screenTop(){return $screenTop;},
+  get screenX(){return $screenX;},
+  get screenY(){return $screenY;},
+  get self(){return $self;},
+  get status(){return $status;},
+  set status(_status){$status = _status;},
+  get top(){return $top;},
+  get window(){return $window;}
+});
+
+$w.open = function(url, name, features, replace){
+  //TODO
+};
+
+$w.close = function(){
+  //TODO
+};     
+  
+/* Time related functions - see timer.js
+*   - clearTimeout
+*   - clearInterval
+*   - setTimeout
+*   - setInterval
+*/
+
+/*
+* Events related functions - see event.js
+*   - addEventListener
+*   - attachEvent
+*   - detachEvent
+*   - removeEventListener
+*   
+* These functions are identical to the Element equivalents.
+*/
+
+/*
+* UIEvents related functions - see uievent.js
+*   - blur
+*   - focus
+*
+* These functions are identical to the Element equivalents.
+*/
+
+/* Dialog related functions - see dialog.js
+*   - alert
+*   - confirm
+*   - prompt
+*/
+
+/* Screen related functions - see screen.js
+*   - moveBy
+*   - moveTo
+*   - print
+*   - resizeBy
+*   - resizeTo
+*   - scrollBy
+*   - scrollTo
+*/
+
+/* CSS related functions - see css.js
+*   - getComputedStyle
+*/
+
+/*
+* Shared utility methods
+*/
+// Helper method for extending one object with another.  
+function __extend__(a,b) {
+	for ( var i in b ) {
+		var g = b.__lookupGetter__(i), s = b.__lookupSetter__(i);
+		if ( g || s ) {
+			if ( g ) a.__defineGetter__(i, g);
+			if ( s ) a.__defineSetter__(i, s);
+		} else
+			a[i] = b[i];
+	} return a;
+};
+	
+
+// from ariel flesler http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html
+// this might be a good utility function to provide in the env.core
+// as in might be useful to the parser and other areas as well
+function trim( str ){
+    var start = -1,
+    end = str.length;
+    /*jsl:ignore*/
+    while( str.charCodeAt(--end) &lt; 33 );
+    while( str.charCodeAt(++start) &lt; 33 );
+    /*jsl:end*/
+    return str.slice( start, end + 1 );
+};
+
+//from jQuery
+function __setArray__( target, array ) {
+	// Resetting the length to 0, then using the native Array push
+	// is a super-fast way to populate an object with array-like properties
+	target.length = 0;
+	Array.prototype.push.apply( target, array );
+};
+$log(&quot;Defining NodeList&quot;);
+/*
+* NodeList - DOM Level 2
+*/
+$w.__defineGetter__('NodeList', function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+/**
+ * @class  DOMNodeList - provides the abstraction of an ordered collection of nodes
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ *
+ * @param  ownerDocument : DOMDocument - the ownerDocument
+ * @param  parentNode    : DOMNode - the node that the DOMNodeList is attached to (or null)
+ */
+var DOMNodeList = function(ownerDocument, parentNode) {
+    //$log(&quot;\t\tcreating dom nodelist&quot;);
+    var nodes = new Array();
+    
+    this.length = 0;
+    this.parentNode = parentNode;
+    this.ownerDocument = ownerDocument;
+    
+    this._readonly = false;
+    
+    __setArray__(this, nodes);
+    //$log(&quot;\t\tfinished creating dom nodelist&quot;);
+};
+__extend__(DOMNodeList.prototype, {
+    item : function(index) {
+        var ret = null;
+        //$log(&quot;NodeList item(&quot;+index+&quot;) = &quot; + this[index]);
+        if ((index &gt;= 0) &amp;&amp; (index &lt; this.length)) { // bounds check
+            ret = this[index];                    // return selected Node
+        }
+        
+        return ret;                                    // if the index is out of bounds, default value null is returned
+    },
+    get xml() {
+        var ret = &quot;&quot;;
+        
+        // create string containing the concatenation of the string values of each child
+        for (var i=0; i &lt; this.length; i++) {
+            if(this[i].nodeType == DOMNode.TEXT_NODE &amp;&amp; i&gt;0 &amp;&amp; this[i-1].nodeType == DOMNode.TEXT_NODE){
+                //add a single space between adjacent text nodes
+                ret += &quot; &quot;+this[i].xml;
+            }else{
+                ret += this[i].xml;
+            }
+        }
+        
+        return ret;
+    },
+    toString: function(){
+      return &quot;[ &quot;+(this.length &gt; 0?Array.prototype.join.apply(this, [&quot;, &quot;]):&quot;Empty NodeList&quot;)+&quot; ]&quot;;
+    }
+});
+
+
+/**
+ * @method DOMNodeList._findItemIndex - find the item index of the node with the specified internal id
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  id : int - unique internal id
+ * @return : int
+ */
+var __findItemIndex__ = function (nodelist, id) {
+  var ret = -1;
+
+  // test that id is valid
+  if (id &gt; -1) {
+    for (var i=0; i&lt;nodelist.length; i++) {
+      // compare id to each node's _id
+      if (nodelist[i]._id == id) {            // found it!
+        ret = i;
+        break;
+      }
+    }
+  }
+
+  return ret;                                    // if node is not found, default value -1 is returned
+};
+
+/**
+ * @method DOMNodeList._insertBefore - insert the specified Node into the NodeList before the specified index
+ *   Used by DOMNode.insertBefore(). Note: DOMNode.insertBefore() is responsible for Node Pointer surgery
+ *   DOMNodeList._insertBefore() simply modifies the internal data structure (Array).
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  newChild      : DOMNode - the Node to be inserted
+ * @param  refChildIndex : int     - the array index to insert the Node before
+ */
+var __insertBefore__ = function(nodelist, newChild, refChildIndex) {
+    if ((refChildIndex &gt;= 0) &amp;&amp; (refChildIndex &lt; nodelist.length)) { // bounds check
+        
+        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
+            // append the children of DocumentFragment
+            Array.prototype.splice.apply(nodelist,[refChildIndex, 0].concat(newChild.childNodes));
+        }
+        else {
+            // append the newChild
+            Array.prototype.splice.apply(nodelist,[refChildIndex, 0, newChild]);
+        }
+    }
+    //$log(&quot;__insertBefore__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
+};
+
+/**
+ * @method DOMNodeList._replaceChild - replace the specified Node in the NodeList at the specified index
+ *   Used by DOMNode.replaceChild(). Note: DOMNode.replaceChild() is responsible for Node Pointer surgery
+ *   DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  newChild      : DOMNode - the Node to be inserted
+ * @param  refChildIndex : int     - the array index to hold the Node
+ */
+var __replaceChild__ = function(nodelist, newChild, refChildIndex) {
+    var ret = null;
+    
+    if ((refChildIndex &gt;= 0) &amp;&amp; (refChildIndex &lt; nodelist.length)) { // bounds check
+        ret = nodelist[refChildIndex];            // preserve old child for return
+    
+        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
+            // get array containing children prior to refChild
+            Array.prototype.splice.apply(nodelist,[refChildIndex, 1].concat(newChild.childNodes));
+        }
+        else {
+            // simply replace node in array (links between Nodes are made at higher level)
+            nodelist[refChildIndex] = newChild;
+        }
+    }
+    
+    //$log(&quot;__replaceChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
+    return ret;                                   // return replaced node
+};
+
+/**
+ * @method DOMNodeList._removeChild - remove the specified Node in the NodeList at the specified index
+ *   Used by DOMNode.removeChild(). Note: DOMNode.removeChild() is responsible for Node Pointer surgery
+ *   DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  refChildIndex : int - the array index holding the Node to be removed
+ */
+var __removeChild__ = function(nodelist, refChildIndex) {
+    var ret = null;
+    
+    if (refChildIndex &gt; -1) {                              // found it!
+        ret = nodelist[refChildIndex];                    // return removed node
+        
+        // rebuild array without removed child
+        Array.prototype.splice.apply(nodelist,[refChildIndex, 1]);
+    }
+    
+    //$log(&quot;__removeChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
+    return ret;                                   // return removed node
+};
+
+/**
+ * @method DOMNodeList._appendChild - append the specified Node to the NodeList
+ *   Used by DOMNode.appendChild(). Note: DOMNode.appendChild() is responsible for Node Pointer surgery
+ *   DOMNodeList._appendChild() simply modifies the internal data structure (Array).
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  newChild      : DOMNode - the Node to be inserted
+ */
+var __appendChild__ = function(nodelist, newChild) {
+    if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {  // node is a DocumentFragment
+        // append the children of DocumentFragment
+        Array.prototype.push.apply(nodelist, newChild.childNodes);
+    } else {
+        // simply add node to array (links between Nodes are made at higher level)
+        Array.prototype.push.apply(nodelist, [newChild]);
+    }
+    
+    //$log(&quot;__appendChild__ : length &quot; + nodelist.length + &quot; all -&gt; &quot; + document.all.length);
+};
+
+/**
+ * @method DOMNodeList._cloneNodes - Returns a NodeList containing clones of the Nodes in this NodeList
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  deep : boolean - If true, recursively clone the subtree under each of the nodes;
+ *   if false, clone only the nodes themselves (and their attributes, if it is an Element).
+ * @param  parentNode : DOMNode - the new parent of the cloned NodeList
+ * @return : DOMNodeList - NodeList containing clones of the Nodes in this NodeList
+ */
+var __cloneNodes__ = function(nodelist, deep, parentNode) {
+    var cloneNodeList = new DOMNodeList(nodelist.ownerDocument, parentNode);
+    
+    // create list containing clones of each child
+    for (var i=0; i &lt; nodelist.length; i++) {
+        __appendChild__(cloneNodeList, nodelist[i].cloneNode(deep));
+    }
+    
+    return cloneNodeList;
+};
+
+
+/**
+ * @class  DOMNamedNodeMap - used to represent collections of nodes that can be accessed by name
+ *  typically a set of Element attributes
+ *
+ * @extends DOMNodeList - note W3C spec says that this is not the case,
+ *   but we need an item() method identicle to DOMNodeList's, so why not?
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - the ownerDocument
+ * @param  parentNode    : DOMNode - the node that the DOMNamedNodeMap is attached to (or null)
+ */
+var DOMNamedNodeMap = function(ownerDocument, parentNode) {
+    //$log(&quot;\t\tcreating dom namednodemap&quot;);
+    this.DOMNodeList = DOMNodeList;
+    this.DOMNodeList(ownerDocument, parentNode);
+    __setArray__(this, []);
+};
+DOMNamedNodeMap.prototype = new DOMNodeList;
+__extend__(DOMNamedNodeMap.prototype, {
+    getNamedItem : function(name) {
+        var ret = null;
+        
+        // test that Named Node exists
+        var itemIndex = __findNamedItemIndex__(this, name);
+        
+        if (itemIndex &gt; -1) {                          // found it!
+            ret = this[itemIndex];                // return NamedNode
+        }
+        
+        return ret;                                    // if node is not found, default value null is returned
+    },
+    setNamedItem : function(arg) {
+      // test for exceptions
+      if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if arg was not created by this Document
+            if (this.ownerDocument != arg.ownerDocument) {
+              throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+            }
+        
+            // throw Exception if DOMNamedNodeMap is readonly
+            if (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly)) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+        
+            // throw Exception if arg is already an attribute of another Element object
+            if (arg.ownerElement &amp;&amp; (arg.ownerElement != this.parentNode)) {
+              throw(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR));
+            }
+      }
+    
+      // get item index
+      var itemIndex = __findNamedItemIndex__(this, arg.name);
+      var ret = null;
+    
+      if (itemIndex &gt; -1) {                          // found it!
+            ret = this[itemIndex];                // use existing Attribute
+        
+            // throw Exception if DOMAttr is readonly
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ret._readonly) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            } else {
+              this[itemIndex] = arg;                // over-write existing NamedNode
+            }
+      } else {
+            // add new NamedNode
+            Array.prototype.push.apply(this, [arg]);
+      }
+    
+      arg.ownerElement = this.parentNode;            // update ownerElement
+    
+      return ret;                                    // return old node or null
+    },
+    removeNamedItem : function(name) {
+          var ret = null;
+          // test for exceptions
+          // throw Exception if DOMNamedNodeMap is readonly
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly))) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+          }
+        
+          // get item index
+          var itemIndex = __findNamedItemIndex__(this, name);
+        
+          // throw Exception if there is no node named name in this map
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+            throw(new DOMException(DOMException.NOT_FOUND_ERR));
+          }
+        
+          // get Node
+          var oldNode = this[itemIndex];
+        
+          // throw Exception if Node is readonly
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldNode._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+          }
+        
+          // return removed node
+          return __removeChild__(this, itemIndex);
+    },
+    getNamedItemNS : function(namespaceURI, localName) {
+          var ret = null;
+        
+          // test that Named Node exists
+          var itemIndex = __findNamedItemNSIndex__(this, namespaceURI, localName);
+        
+          if (itemIndex &gt; -1) {                          // found it!
+            ret = this[itemIndex];                // return NamedNode
+          }
+        
+          return ret;                                    // if node is not found, default value null is returned
+    },
+    setNamedItemNS : function(arg) {
+          // test for exceptions
+          if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if DOMNamedNodeMap is readonly
+            if (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly)) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+        
+            // throw Exception if arg was not created by this Document
+            if (this.ownerDocument != arg.ownerDocument) {
+              throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+            }
+        
+            // throw Exception if arg is already an attribute of another Element object
+            if (arg.ownerElement &amp;&amp; (arg.ownerElement != this.parentNode)) {
+              throw(new DOMException(DOMException.INUSE_ATTRIBUTE_ERR));
+            }
+          }
+        
+          // get item index
+          var itemIndex = __findNamedItemNSIndex__(this, arg.namespaceURI, arg.localName);
+          var ret = null;
+        
+          if (itemIndex &gt; -1) {                          // found it!
+            ret = this[itemIndex];                // use existing Attribute
+            // throw Exception if DOMAttr is readonly
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ret._readonly) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            } else {
+              this[itemIndex] = arg;                // over-write existing NamedNode
+            }
+          }else {
+            // add new NamedNode
+            Array.prototype.push.apply(this, [arg]);
+          }
+          arg.ownerElement = this.parentNode;
+        
+        
+          return ret;                                    // return old node or null
+    },
+    removeNamedItemNS : function(namespaceURI, localName) {
+          var ret = null;
+        
+          // test for exceptions
+          // throw Exception if DOMNamedNodeMap is readonly
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || (this.parentNode &amp;&amp; this.parentNode._readonly))) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+          }
+        
+          // get item index
+          var itemIndex = __findNamedItemNSIndex__(this, namespaceURI, localName);
+        
+          // throw Exception if there is no matching node in this map
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+            throw(new DOMException(DOMException.NOT_FOUND_ERR));
+          }
+        
+          // get Node
+          var oldNode = this[itemIndex];
+        
+          // throw Exception if Node is readonly
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldNode._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+          }
+        
+          return __removeChild__(this, itemIndex);             // return removed node
+    },
+    get xml() {
+          var ret = &quot;&quot;;
+        
+          // create string containing concatenation of all (but last) Attribute string values (separated by spaces)
+          for (var i=0; i &lt; this.length -1; i++) {
+            ret += this[i].xml +&quot; &quot;;
+          }
+        
+          // add last Attribute to string (without trailing space)
+          if (this.length &gt; 0) {
+            ret += this[this.length -1].xml;
+          }
+        
+          return ret;
+    }
+
+});
+
+/**
+ * @method DOMNamedNodeMap._findNamedItemIndex - find the item index of the node with the specified name
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  name : string - the name of the required node
+ * @param  isnsmap : if its a DOMNamespaceNodeMap
+ * @return : int
+ */
+var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) {
+  var ret = -1;
+
+  // loop through all nodes
+  for (var i=0; i&lt;namednodemap.length; i++) {
+    // compare name to each node's nodeName
+    if(isnsmap){
+        if (namednodemap[i].localName == localName) {         // found it!
+          ret = i;
+          break;
+        }
+    }else{
+        if (namednodemap[i].name == name) {         // found it!
+          ret = i;
+          break;
+        }
+    }
+  }
+
+  return ret;                                    // if node is not found, default value -1 is returned
+};
+
+/**
+ * @method DOMNamedNodeMap._findNamedItemNSIndex - find the item index of the node with the specified namespaceURI and localName
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  namespaceURI : string - the namespace URI of the required node
+ * @param  localName    : string - the local name of the required node
+ * @return : int
+ */
+var __findNamedItemNSIndex__ = function(namednodemap, namespaceURI, localName) {
+  var ret = -1;
+
+  // test that localName is not null
+  if (localName) {
+    // loop through all nodes
+    for (var i=0; i&lt;namednodemap.length; i++) {
+      // compare name to each node's namespaceURI and localName
+      if ((namednodemap[i].namespaceURI == namespaceURI) &amp;&amp; (namednodemap[i].localName == localName)) {
+        ret = i;                                 // found it!
+        break;
+      }
+    }
+  }
+
+  return ret;                                    // if node is not found, default value -1 is returned
+};
+
+/**
+ * @method DOMNamedNodeMap._hasAttribute - Returns true if specified node exists
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  name : string - the name of the required node
+ * @return : boolean
+ */
+var __hasAttribute__ = function(namednodemap, name) {
+  var ret = false;
+
+  // test that Named Node exists
+  var itemIndex = __findNamedItemIndex__(namednodemap, name);
+
+  if (itemIndex &gt; -1) {                          // found it!
+    ret = true;                                  // return true
+  }
+
+  return ret;                                    // if node is not found, default value false is returned
+}
+
+/**
+ * @method DOMNamedNodeMap._hasAttributeNS - Returns true if specified node exists
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  namespaceURI : string - the namespace URI of the required node
+ * @param  localName    : string - the local name of the required node
+ * @return : boolean
+ */
+var __hasAttributeNS__ = function(namednodemap, namespaceURI, localName) {
+  var ret = false;
+
+  // test that Named Node exists
+  var itemIndex = __findNamedItemNSIndex__(namednodemap, namespaceURI, localName);
+
+  if (itemIndex &gt; -1) {                          // found it!
+    ret = true;                                  // return true
+  }
+
+  return ret;                                    // if node is not found, default value false is returned
+}
+
+/**
+ * @method DOMNamedNodeMap._cloneNodes - Returns a NamedNodeMap containing clones of the Nodes in this NamedNodeMap
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  parentNode : DOMNode - the new parent of the cloned NodeList
+ * @param  isnsmap : bool - is this a DOMNamespaceNodeMap
+ * @return : DOMNamedNodeMap - NamedNodeMap containing clones of the Nodes in this DOMNamedNodeMap
+ */
+var __cloneNamedNodes__ = function(namednodemap, parentNode, isnsmap) {
+  var cloneNamedNodeMap = isnsmap?
+    new DOMNamespaceNodeMap(namednodemap.ownerDocument, parentNode):
+    new DOMNamedNodeMap(namednodemap.ownerDocument, parentNode);
+
+  // create list containing clones of all children
+  for (var i=0; i &lt; namednodemap.length; i++) {
+      $log(&quot;cloning node in named node map :&quot; + namednodemap[i]);
+    __appendChild__(cloneNamedNodeMap, namednodemap[i].cloneNode(false));
+  }
+
+  return cloneNamedNodeMap;
+};
+
+
+/**
+ * @class  DOMNamespaceNodeMap - used to represent collections of namespace nodes that can be accessed by name
+ *  typically a set of Element attributes
+ *
+ * @extends DOMNamedNodeMap
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ *
+ * @param  ownerDocument : DOMDocument - the ownerDocument
+ * @param  parentNode    : DOMNode - the node that the DOMNamespaceNodeMap is attached to (or null)
+ */
+var DOMNamespaceNodeMap = function(ownerDocument, parentNode) {
+    //$log(&quot;\t\t\tcreating dom namespacednodemap&quot;);
+    this.DOMNamedNodeMap = DOMNamedNodeMap;
+    this.DOMNamedNodeMap(ownerDocument, parentNode);
+    __setArray__(this, []);
+};
+DOMNamespaceNodeMap.prototype = new DOMNamedNodeMap;
+__extend__(DOMNamespaceNodeMap.prototype, {
+    get xml() {
+          var ret = &quot;&quot;;
+        
+          // identify namespaces declared local to this Element (ie, not inherited)
+          for (var ind = 0; ind &lt; this.length; ind++) {
+            // if namespace declaration does not exist in the containing node's, parentNode's namespaces
+            var ns = null;
+            try {
+                var ns = this.parentNode.parentNode._namespaces.getNamedItem(this[ind].localName);
+            }
+            catch (e) {
+                //breaking to prevent default namespace being inserted into return value
+                break;
+            }
+            if (!(ns &amp;&amp; (&quot;&quot;+ ns.nodeValue == &quot;&quot;+ this[ind].nodeValue))) {
+              // display the namespace declaration
+              ret += this[ind].xml +&quot; &quot;;
+            }
+          }
+        
+          return ret;
+    }
+});
+$log(&quot;Defining Node&quot;);
+/*
+* Node - DOM Level 2
+*/	
+$w.__defineGetter__('Node', function(){
+  return __extend__(function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+      } , {
+  		ELEMENT_NODE    :1,
+  		ATTRIBUTE_NODE  :2,
+  		TEXT_NODE       :3,
+  		CDATA_SECTION_NODE: 4,
+  		PROCESSING_INSTRUCTION_NODE: 7,
+  		COMMENT_NODE: 8,
+  		DOCUMENT_NODE: 9,
+  		DOCUMENT_TYPE_NODE: 10,
+  		DOCUMENT_FRAGMENT_NODE: 11
+	});
+});
+
+/**
+ * @class  DOMNode - The Node interface is the primary datatype for the entire Document Object Model.
+ *   It represents a single node in the document tree.
+ * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMNode = function(ownerDocument) {
+  //$log(&quot;\tcreating dom node&quot;);
+  if (ownerDocument) {
+    this._id = ownerDocument._genId();           // generate unique internal id
+  }
+
+  this.namespaceURI = &quot;&quot;;                        // The namespace URI of this node (Level 2)
+  this.prefix       = &quot;&quot;;                        // The namespace prefix of this node (Level 2)
+  this.localName    = &quot;&quot;;                        // The localName of this node (Level 2)
+
+  this.nodeName = &quot;&quot;;                            // The name of this node
+  this.nodeValue = &quot;&quot;;                           // The value of this node
+  this.nodeType = 0;                             // A code representing the type of the underlying object
+
+  // The parent of this node. All nodes, except Document, DocumentFragment, and Attr may have a parent.
+  // However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null
+  this.parentNode      = null;
+
+  // A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.
+  // The content of the returned NodeList is &quot;live&quot; in the sense that, for instance, changes to the children of the node object
+  // that it was created from are immediately reflected in the nodes returned by the NodeList accessors;
+  // it is not a static snapshot of the content of the node. This is true for every NodeList, including the ones returned by the getElementsByTagName method.
+  this.childNodes      = new DOMNodeList(ownerDocument, this);
+
+  this.firstChild      = null;                   // The first child of this node. If there is no such node, this is null
+  this.lastChild       = null;                   // The last child of this node. If there is no such node, this is null.
+  this.previousSibling = null;                   // The node immediately preceding this node. If there is no such node, this is null.
+  this.nextSibling     = null;                   // The node immediately following this node. If there is no such node, this is null.
+
+  this.attributes = new DOMNamedNodeMap(ownerDocument, this);   // A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
+  this.ownerDocument   = ownerDocument;          // The Document object associated with this node
+  this._namespaces = new DOMNamespaceNodeMap(ownerDocument, this);  // The namespaces in scope for this node
+
+  this._readonly = false;
+  //$log(&quot;\tfinished creating dom node&quot;);
+};
+
+// nodeType constants
+DOMNode.ELEMENT_NODE                = 1;
+DOMNode.ATTRIBUTE_NODE              = 2;
+DOMNode.TEXT_NODE                   = 3;
+DOMNode.CDATA_SECTION_NODE          = 4;
+DOMNode.ENTITY_REFERENCE_NODE       = 5;
+DOMNode.ENTITY_NODE                 = 6;
+DOMNode.PROCESSING_INSTRUCTION_NODE = 7;
+DOMNode.COMMENT_NODE                = 8;
+DOMNode.DOCUMENT_NODE               = 9;
+DOMNode.DOCUMENT_TYPE_NODE          = 10;
+DOMNode.DOCUMENT_FRAGMENT_NODE      = 11;
+DOMNode.NOTATION_NODE               = 12;
+DOMNode.NAMESPACE_NODE              = 13;
+
+__extend__(DOMNode.prototype, {
+    hasAttributes : function() {
+        if (this.attributes.length == 0) {
+            return false;
+        }else{
+            return true;
+        }
+    },
+    insertBefore : function(newChild, refChild) {
+        var prevNode;
+        
+        // test for exceptions
+        if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if DOMNode is readonly
+            if (this._readonly) {
+                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+            
+            // throw Exception if newChild was not created by this Document
+            if (this.ownerDocument != newChild.ownerDocument) {
+                throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+            }
+            
+            // throw Exception if the node is an ancestor
+            if (__isAncestor__(this, newChild)) {
+                throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
+            }
+        }
+        
+        if (refChild) {                                // if refChild is specified, insert before it
+            // find index of refChild
+            var itemIndex = __findItemIndex__(this.childNodes, refChild._id);
+            
+            // throw Exception if there is no child node with this id
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+              throw(new DOMException(DOMException.NOT_FOUND_ERR));
+            }
+            
+            // if the newChild is already in the tree,
+            var newChildParent = newChild.parentNode;
+            if (newChildParent) {
+              // remove it
+              newChildParent.removeChild(newChild);
+            }
+            
+            // insert newChild into childNodes
+            __insertBefore__(this.childNodes, newChild, __findItemIndex__(this.childNodes, refChild._id));
+            
+            // do node pointer surgery
+            prevNode = refChild.previousSibling;
+            
+            // handle DocumentFragment
+            if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
+              if (newChild.childNodes.length &gt; 0) {
+                // set the parentNode of DocumentFragment's children
+                for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
+                  newChild.childNodes[ind].parentNode = this;
+                }
+            
+                // link refChild to last child of DocumentFragment
+                refChild.previousSibling = newChild.childNodes[newChild.childNodes.length-1];
+              }
+            }else {
+                newChild.parentNode = this;                // set the parentNode of the newChild
+                refChild.previousSibling = newChild;       // link refChild to newChild
+            }
+        }else {                                         // otherwise, append to end
+            prevNode = this.lastChild;
+            this.appendChild(newChild);
+        }
+        
+        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
+            // do node pointer surgery for DocumentFragment
+            if (newChild.childNodes.length &gt; 0) {
+                if (prevNode) {  
+                    prevNode.nextSibling = newChild.childNodes[0];
+                }else {                                         // this is the first child in the list
+                    this.firstChild = newChild.childNodes[0];
+                }
+            
+                newChild.childNodes[0].previousSibling = prevNode;
+                newChild.childNodes[newChild.childNodes.length-1].nextSibling = refChild;
+            }
+        }else {
+            // do node pointer surgery for newChild
+            if (prevNode) {
+              prevNode.nextSibling = newChild;
+            }else {                                         // this is the first child in the list
+              this.firstChild = newChild;
+            }
+            
+            newChild.previousSibling = prevNode;
+            newChild.nextSibling     = refChild;
+        }
+        
+        return newChild;
+    },
+    replaceChild : function(newChild, oldChild) {
+        var ret = null;
+        
+        // test for exceptions
+        if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if DOMNode is readonly
+            if (this._readonly) {
+                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+        
+            // throw Exception if newChild was not created by this Document
+            if (this.ownerDocument != newChild.ownerDocument) {
+                throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+            }
+        
+            // throw Exception if the node is an ancestor
+            if (__isAncestor__(this, newChild)) {
+                throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
+            }
+        }
+        
+        // get index of oldChild
+        var index = __findItemIndex__(this.childNodes, oldChild._id);
+        
+        // throw Exception if there is no child node with this id
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (index &lt; 0)) {
+            throw(new DOMException(DOMException.NOT_FOUND_ERR));
+        }
+        
+        // if the newChild is already in the tree,
+        var newChildParent = newChild.parentNode;
+        if (newChildParent) {
+            // remove it
+            newChildParent.removeChild(newChild);
+        }
+        
+        // add newChild to childNodes
+        ret = __replaceChild__(this.childNodes,newChild, index);
+        
+        
+        if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
+            // do node pointer surgery for Document Fragment
+            if (newChild.childNodes.length &gt; 0) {
+                for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
+                    newChild.childNodes[ind].parentNode = this;
+                }
+                
+                if (oldChild.previousSibling) {
+                    oldChild.previousSibling.nextSibling = newChild.childNodes[0];
+                } else {
+                    this.firstChild = newChild.childNodes[0];
+                }
+                
+                if (oldChild.nextSibling) {
+                    oldChild.nextSibling.previousSibling = newChild;
+                } else {
+                    this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
+                }
+                
+                newChild.childNodes[0].previousSibling = oldChild.previousSibling;
+                newChild.childNodes[newChild.childNodes.length-1].nextSibling = oldChild.nextSibling;
+            }
+        } else {
+            // do node pointer surgery for newChild
+            newChild.parentNode = this;
+            
+            if (oldChild.previousSibling) {
+                oldChild.previousSibling.nextSibling = newChild;
+            }else{
+                this.firstChild = newChild;
+            }
+            if (oldChild.nextSibling) {
+                oldChild.nextSibling.previousSibling = newChild;
+            }else{
+                this.lastChild = newChild;
+            }
+            newChild.previousSibling = oldChild.previousSibling;
+            newChild.nextSibling = oldChild.nextSibling;
+        }
+        //this.removeChild(oldChild);
+        return ret;
+    },
+    removeChild : function(oldChild) {
+        // throw Exception if DOMNamedNodeMap is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (this._readonly || oldChild._readonly)) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        
+        // get index of oldChild
+        var itemIndex = __findItemIndex__(this.childNodes, oldChild._id);
+        
+        // throw Exception if there is no child node with this id
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+            throw(new DOMException(DOMException.NOT_FOUND_ERR));
+        }
+        
+        // remove oldChild from childNodes
+        __removeChild__(this.childNodes, itemIndex);
+        
+        // do node pointer surgery
+        oldChild.parentNode = null;
+        
+        if (oldChild.previousSibling) {
+            oldChild.previousSibling.nextSibling = oldChild.nextSibling;
+        }else {
+            this.firstChild = oldChild.nextSibling;
+        }
+        if (oldChild.nextSibling) {
+            oldChild.nextSibling.previousSibling = oldChild.previousSibling;
+        }else {
+            this.lastChild = oldChild.previousSibling;
+        }
+        
+        oldChild.previousSibling = null;
+        oldChild.nextSibling = null;
+        
+        /*if(oldChild.ownerDocument == document){
+            $log(&quot;removeChild :  all -&gt; &quot; + document.all.length);
+        }*/
+        return oldChild;
+    },
+    appendChild : function(newChild) {
+      // test for exceptions
+      if (this.ownerDocument.implementation.errorChecking) {
+        // throw Exception if Node is readonly
+        if (this._readonly) {
+          throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+    
+        // throw Exception if arg was not created by this Document
+        if (this.ownerDocument != newChild.ownerDocument) {
+          throw(new DOMException(DOMException.WRONG_DOCUMENT_ERR));
+        }
+    
+        // throw Exception if the node is an ancestor
+        if (__isAncestor__(this, newChild)) {
+          throw(new DOMException(DOMException.HIERARCHY_REQUEST_ERR));
+        }
+      }
+    
+      // if the newChild is already in the tree,
+      var newChildParent = newChild.parentNode;
+      if (newChildParent) {
+        // remove it
+        newChildParent.removeChild(newChild);
+      }
+    
+      // add newChild to childNodes
+      __appendChild__(this.childNodes, newChild);
+    
+      if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
+        // do node pointer surgery for DocumentFragment
+        if (newChild.childNodes.length &gt; 0) {
+          for (var ind = 0; ind &lt; newChild.childNodes.length; ind++) {
+            newChild.childNodes[ind].parentNode = this;
+          }
+    
+          if (this.lastChild) {
+            this.lastChild.nextSibling = newChild.childNodes[0];
+            newChild.childNodes[0].previousSibling = this.lastChild;
+            this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
+          }
+          else {
+            this.lastChild = newChild.childNodes[newChild.childNodes.length-1];
+            this.firstChild = newChild.childNodes[0];
+          }
+        }
+      }
+      else {
+        // do node pointer surgery for newChild
+        newChild.parentNode = this;
+        if (this.lastChild) {
+          this.lastChild.nextSibling = newChild;
+          newChild.previousSibling = this.lastChild;
+          this.lastChild = newChild;
+        }
+        else {
+          this.lastChild = newChild;
+          this.firstChild = newChild;
+        }
+      }
+    
+      return newChild;
+    },
+    hasChildNodes : function() {
+        return (this.childNodes.length &gt; 0);
+    },
+    cloneNode: function(deep) {
+        // use importNode to clone this Node
+        //do not throw any exceptions
+        //$log(&quot;cloning node&quot;);
+        try {
+            return this.ownerDocument.importNode(this, deep);
+        } catch (e) {
+            //there shouldn't be any exceptions, but if there are, return null
+            return null;
+        }
+    },
+    normalize : function() {
+        var inode;
+        var nodesToRemove = new DOMNodeList();
+        
+        if (this.nodeType == DOMNode.ELEMENT_NODE || this.nodeType == DOMNode.DOCUMENT_NODE) {
+            var adjacentTextNode = null;
+        
+            // loop through all childNodes
+            for(var i = 0; i &lt; this.childNodes.length; i++) {
+                inode = this.childNodes.item(i);
+            
+                if (inode.nodeType == DOMNode.TEXT_NODE) { // this node is a text node
+                    if (inode.length &lt; 1) {                  // this text node is empty
+                        __appendChild__(nodesToRemove, inode);      // add this node to the list of nodes to be remove
+                    }else {
+                        if (adjacentTextNode) {                // if previous node was also text
+                            adjacentTextNode.appendData(inode.data);     // merge the data in adjacent text nodes
+                            __appendChild__(nodesToRemove, inode);    // add this node to the list of nodes to be removed
+                        }else {
+                            adjacentTextNode = inode;              // remember this node for next cycle
+                        }
+                    }
+                } else {
+                    adjacentTextNode = null;                 // (soon to be) previous node is not a text node
+                    inode.normalize();                       // normalise non Text childNodes
+                }
+            }
+                
+            // remove redundant Text Nodes
+            for(var i = 0; i &lt; nodesToRemove.length; i++) {
+                inode = nodesToRemove.item(i);
+                inode.parentNode.removeChild(inode);
+            }
+        }
+    },
+    isSupported : function(feature, version) {
+        // use Implementation.hasFeature to determin if this feature is supported
+        return this.ownerDocument.implementation.hasFeature(feature, version);
+    },
+    getElementsByTagName : function(tagname) {
+        // delegate to _getElementsByTagNameRecursive
+        //$log(&quot;getElementsByTagName(&quot;+tagname+&quot;)&quot;);
+        return __getElementsByTagNameRecursive__(this, tagname, new DOMNodeList(this.ownerDocument));
+    },
+    getElementsByTagNameNS : function(namespaceURI, localName) {
+        // delegate to _getElementsByTagNameNSRecursive
+        return __getElementsByTagNameNSRecursive__(this, namespaceURI, localName, new DOMNodeList(this.ownerDocument));
+    },
+    importNode : function(importedNode, deep) {
+        var importNode;
+        //$log(&quot;importing node &quot; + importedNode + &quot;(?deep = &quot;+deep+&quot;)&quot;);
+        //there is no need to perform namespace checks since everything has already gone through them
+        //in order to have gotten into the DOM in the first place. The following line
+        //turns namespace checking off in ._isValidNamespace
+        this.ownerDocument._performingImportNodeOperation = true;
+        
+        try {
+            if (importedNode.nodeType == DOMNode.ELEMENT_NODE) {
+                if (!this.ownerDocument.implementation.namespaceAware) {
+                    // create a local Element (with the name of the importedNode)
+                    importNode = this.ownerDocument.createElement(importedNode.tagName);
+                
+                    // create attributes matching those of the importedNode
+                    for(var i = 0; i &lt; importedNode.attributes.length; i++) {
+                        importNode.setAttribute(importedNode.attributes.item(i).name, importedNode.attributes.item(i).value);
+                    }
+                }else {
+                    // create a local Element (with the name &amp; namespaceURI of the importedNode)
+                    importNode = this.ownerDocument.createElementNS(importedNode.namespaceURI, importedNode.nodeName);
+                
+                    // create attributes matching those of the importedNode
+                    for(var i = 0; i &lt; importedNode.attributes.length; i++) {
+                        importNode.setAttributeNS(importedNode.attributes.item(i).namespaceURI, 
+                            importedNode.attributes.item(i).name, importedNode.attributes.item(i).value);
+                    }
+                
+                    // create namespace definitions matching those of the importedNode
+                    for(var i = 0; i &lt; importedNode._namespaces.length; i++) {
+                        importNode._namespaces[i] = this.ownerDocument.createNamespace(importedNode._namespaces.item(i).localName);
+                        importNode._namespaces[i].value = importedNode._namespaces.item(i).value;
+                    }
+                }
+            } else if (importedNode.nodeType == DOMNode.ATTRIBUTE_NODE) {
+                if (!this.ownerDocument.implementation.namespaceAware) {
+                    // create a local Attribute (with the name of the importedAttribute)
+                    importNode = this.ownerDocument.createAttribute(importedNode.name);
+                } else {
+                    // create a local Attribute (with the name &amp; namespaceURI of the importedAttribute)
+                    importNode = this.ownerDocument.createAttributeNS(importedNode.namespaceURI, importedNode.nodeName);
+                
+                    // create namespace definitions matching those of the importedAttribute
+                    for(var i = 0; i &lt; importedNode._namespaces.length; i++) {
+                        importNode._namespaces[i] = this.ownerDocument.createNamespace(importedNode._namespaces.item(i).localName);
+                        importNode._namespaces[i].value = importedNode._namespaces.item(i).value;
+                    }
+                }
+            
+                // set the value of the local Attribute to match that of the importedAttribute
+                importNode.value = importedNode.value;
+                
+            } else if (importedNode.nodeType == DOMNode.DOCUMENT_FRAGMENT) {
+                // create a local DocumentFragment
+                importNode = this.ownerDocument.createDocumentFragment();
+            } else if (importedNode.nodeType == DOMNode.NAMESPACE_NODE) {
+                // create a local NamespaceNode (with the same name &amp; value as the importedNode)
+                importNode = this.ownerDocument.createNamespace(importedNode.nodeName);
+                importNode.value = importedNode.value;
+            } else if (importedNode.nodeType == DOMNode.TEXT_NODE) {
+                // create a local TextNode (with the same data as the importedNode)
+                importNode = this.ownerDocument.createTextNode(importedNode.data);
+            } else if (importedNode.nodeType == DOMNode.CDATA_SECTION_NODE) {
+                // create a local CDATANode (with the same data as the importedNode)
+                importNode = this.ownerDocument.createCDATASection(importedNode.data);
+            } else if (importedNode.nodeType == DOMNode.PROCESSING_INSTRUCTION_NODE) {
+                // create a local ProcessingInstruction (with the same target &amp; data as the importedNode)
+                importNode = this.ownerDocument.createProcessingInstruction(importedNode.target, importedNode.data);
+            } else if (importedNode.nodeType == DOMNode.COMMENT_NODE) {
+                // create a local Comment (with the same data as the importedNode)
+                importNode = this.ownerDocument.createComment(importedNode.data);
+            } else {  // throw Exception if nodeType is not supported
+                throw(new DOMException(DOMException.NOT_SUPPORTED_ERR));
+            }
+            
+            if (deep) {                                    // recurse childNodes
+                for(var i = 0; i &lt; importedNode.childNodes.length; i++) {
+                    importNode.appendChild(this.ownerDocument.importNode(importedNode.childNodes.item(i), true));
+                }
+            }
+            
+            //reset _performingImportNodeOperation
+            this.ownerDocument._performingImportNodeOperation = false;
+            return importNode;
+        } catch (eAny) {
+            //reset _performingImportNodeOperation
+            this.ownerDocument._performingImportNodeOperation = false;
+            
+            //re-throw the exception
+            throw eAny;
+        }//djotemp
+    },
+    contains : function(node){
+            while(node &amp;&amp; node != this ){
+                node = node.parentNode;
+            }
+            return !!node;
+    },
+    compareDocumentPosition : function(b){
+        var a = this;
+        var number = (a != b &amp;&amp; a.contains(b) &amp;&amp; 16) + (a != b &amp;&amp; b.contains(a) &amp;&amp; 8);
+        //find position of both
+        var all = document.getElementsByTagName(&quot;*&quot;);
+        var my_location = 0, node_location = 0;
+        for(var i=0; i &lt; all.length; i++){
+            if(all[i] == a) my_location = i;
+            if(all[i] == b) node_location = i;
+            if(my_location &amp;&amp; node_location) break;
+        }
+        number += (my_location &lt; node_location &amp;&amp; 4)
+        number += (my_location &gt; node_location &amp;&amp; 2)
+        return number;
+    } 
+
+});
+
+/**
+ * @method DOMNode._getElementsByTagNameRecursive - implements getElementsByTagName()
+ * @param  elem     : DOMElement  - The element which are checking and then recursing into
+ * @param  tagname  : string      - The name of the tag to match on. The special value &quot;*&quot; matches all tags
+ * @param  nodeList : DOMNodeList - The accumulating list of matching nodes
+ *
+ * @return : DOMNodeList
+ */
+var __getElementsByTagNameRecursive__ = function (elem, tagname, nodeList) {
+    //$log(&quot;__getElementsByTagNameRecursive__(&quot;+elem._id+&quot;)&quot;);
+    if (elem.nodeType == DOMNode.ELEMENT_NODE || elem.nodeType == DOMNode.DOCUMENT_NODE) {
+    
+        if((elem.nodeName.toUpperCase() == tagname.toUpperCase()) || (tagname == &quot;*&quot;)) {
+            //$log(&quot;found node by name &quot; + tagname);
+            __appendChild__(nodeList, elem);               // add matching node to nodeList
+        }
+    
+        // recurse childNodes
+        for(var i = 0; i &lt; elem.childNodes.length; i++) {
+            nodeList = __getElementsByTagNameRecursive__(elem.childNodes.item(i), tagname, nodeList);
+        }
+    }
+    
+    return nodeList;
+};
+
+
+/**
+ * @method DOMNode._getElementsByTagNameNSRecursive - implements getElementsByTagName()
+ *
+ * @param  elem     : DOMElement  - The element which are checking and then recursing into
+ * @param  namespaceURI : string - the namespace URI of the required node
+ * @param  localName    : string - the local name of the required node
+ * @param  nodeList     : DOMNodeList - The accumulating list of matching nodes
+ *
+ * @return : DOMNodeList
+ */
+var __getElementsByTagNameNSRecursive__ = function(elem, namespaceURI, localName, nodeList) {
+  if (elem.nodeType == DOMNode.ELEMENT_NODE || elem.nodeType == DOMNode.DOCUMENT_NODE) {
+
+    if (((elem.namespaceURI == namespaceURI) || (namespaceURI == &quot;*&quot;)) &amp;&amp; ((elem.localName == localName) || (localName == &quot;*&quot;))) {
+      __appendChild__(nodeList, elem);               // add matching node to nodeList
+    }
+
+    // recurse childNodes
+    for(var i = 0; i &lt; elem.childNodes.length; i++) {
+      nodeList = __getElementsByTagNameNSRecursive__(elem.childNodes.item(i), namespaceURI, localName, nodeList);
+    }
+  }
+
+  return nodeList;
+};
+
+/**
+ * @method DOMNode._isAncestor - returns true if node is ancestor of target
+ * @param  target         : DOMNode - The node we are using as context
+ * @param  node         : DOMNode - The candidate ancestor node
+ * @return : boolean
+ */
+var __isAncestor__ = function(target, node) {
+  // if this node matches, return true,
+  // otherwise recurse up (if there is a parentNode)
+  return ((target == node) || ((target.parentNode) &amp;&amp; (__isAncestor__(target.parentNode, node))));
+}
+
+
+/**
+ * @class  DOMNamespace - The Namespace interface represents an namespace in an Element object
+ *
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMNamespace = function(ownerDocument) {
+  this.DOMNode = DOMNode;
+  this.DOMNode(ownerDocument);
+
+  this.name      = &quot;&quot;;                           // the name of this attribute
+
+  // If this attribute was explicitly given a value in the original document, this is true; otherwise, it is false.
+  // Note that the implementation is in charge of this attribute, not the user.
+  // If the user changes the value of the attribute (even if it ends up having the same value as the default value)
+  // then the specified flag is automatically flipped to true
+  this.specified = false;
+
+  this.value     = &quot;&quot;;                           // the value of the attribute is returned as a string
+
+  this.nodeType  = DOMNode.NAMESPACE_NODE;
+};
+DOMNamespace.prototype = new DOMNode;
+__extend__(DOMNamespace.prototype, {
+    get value(){
+        return this.nodeValue;
+    },
+    set value(value){
+        this.nodeValue = String(value);
+    },
+    get xml(){
+        var ret = &quot;&quot;;
+
+          // serialize Namespace Declaration
+          if (this.nodeName != &quot;&quot;) {
+            ret += this.nodeName +&quot;=\&quot;&quot;+ __escapeXML__(this.nodeValue) +&quot;\&quot;&quot;;
+          }
+          else {  // handle default namespace
+            ret += &quot;xmlns=\&quot;&quot;+ __escapeXML__(this.nodeValue) +&quot;\&quot;&quot;;
+          }
+        
+          return ret;
+    },
+    toString: function(){
+        return &quot;Namespace #&quot; + this.id;
+    }
+});
+
+$debug(&quot;Defining CharacterData&quot;);
+/*
+* CharacterData - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CharacterData&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMCharacterData - parent abstract class for DOMText and DOMComment
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMCharacterData = function(ownerDocument) {
+  this.DOMNode  = DOMNode;
+  this.DOMNode(ownerDocument);
+  this.data   = &quot;&quot;;
+  this.length = 0;
+};
+DOMCharacterData.prototype = new DOMNode;
+__extend__(DOMCharacterData.prototype,{
+    get data(){
+        return String(this.nodeValue);
+    },
+    set data(data){
+        this.nodeValue = String(data);
+    },
+    get length(){return this.nodeValue.length;},
+    appendData: function(arg){
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        // append data
+        this.data = &quot;&quot; + this.data + arg;
+    },
+    deleteData: function(offset, count){ 
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
+              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // delete data
+            if(!count || (offset + count) &gt; this.data.length) {
+              this.data = this.data.substring(0, offset);
+            }else {
+              this.data = this.data.substring(0, offset).concat(this.data.substring(offset + count));
+            }
+        }
+    },
+    insertData: function(offset, arg){
+        // throw Exception if DOMCharacterData is readonly
+        if(this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly){
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        
+        if(this.data){
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // insert data
+            this.data =  this.data.substring(0, offset).concat(arg, this.data.substring(offset));
+        }else {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (offset != 0)) {
+               throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // set data
+            this.data = arg;
+        }
+    },
+    replaceData: function(offset, count, arg){
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // replace data
+            this.data = this.data.substring(0, offset).concat(arg, this.data.substring(offset + count));
+        }else {
+            // set data
+            this.data = arg;
+        }
+    },
+    substringData: function(offset, count){
+        var ret = null;
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            // or the count is negative
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt; this.data.length) || (count &lt; 0))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            // if count is not specified
+            if (!count) {
+                ret = this.data.substring(offset); // default to 'end of string'
+            }else{
+                ret = this.data.substring(offset, offset + count);
+            }
+        }
+        return ret;
+    }
+});
+$log(&quot;Defining Text&quot;);
+/*
+* Text - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Text&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+/**
+ * @class  DOMText - The Text interface represents the textual content (termed character data in XML) of an Element or Attr.
+ *   If there is no markup inside an element's content, the text is contained in a single object implementing the Text interface
+ *   that is the only child of the element. If there is markup, it is parsed into a list of elements and Text nodes that form the
+ *   list of children of the element.
+ * @extends DOMCharacterData
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+DOMText = function(ownerDocument) {
+  this.DOMCharacterData  = DOMCharacterData;
+  this.DOMCharacterData(ownerDocument);
+
+  this.nodeName  = &quot;#text&quot;;
+  this.nodeType  = DOMNode.TEXT_NODE;
+};
+DOMText.prototype = new DOMCharacterData;
+__extend__(DOMText.prototype,{
+    //Breaks this Text node into two Text nodes at the specified offset,
+    // keeping both in the tree as siblings. This node then only contains all the content up to the offset point.
+    // And a new Text node, which is inserted as the next sibling of this node, contains all the content at and after the offset point.
+    splitText : function(offset) {
+        var data, inode;
+        
+        // test for exceptions
+        if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if Node is readonly
+            if (this._readonly) {
+              throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+            
+            // throw Exception if offset is negative or greater than the data length,
+            if ((offset &lt; 0) || (offset &gt; this.data.length)) {
+              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+        }
+        
+        if (this.parentNode) {
+            // get remaining string (after offset)
+            data  = this.substringData(offset);
+            
+            // create new TextNode with remaining string
+            inode = this.ownerDocument.createTextNode(data);
+            
+            // attach new TextNode
+            if (this.nextSibling) {
+              this.parentNode.insertBefore(inode, this.nextSibling);
+            }
+            else {
+              this.parentNode.appendChild(inode);
+            }
+            
+            // remove remaining string from original TextNode
+            this.deleteData(offset);
+        }
+        
+        return inode;
+    },
+    get xml(){
+        return __escapeXML__(&quot;&quot;+ this.nodeValue);
+    },
+    toString: function(){
+        return &quot;Text #&quot; + this._id;    
+    }
+});
+
+$log(&quot;Defining CDATASection&quot;);
+/*
+* CDATASection - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CDATASection&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMCDATASection - CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup.
+ *   The only delimiter that is recognized in a CDATA section is the &quot;\]\]\&gt;&quot; string that ends the CDATA section
+ * @extends DOMCharacterData
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMCDATASection = function(ownerDocument) {
+  this.DOMText  = DOMText;
+  this.DOMText(ownerDocument);
+
+  this.nodeName  = &quot;#cdata-section&quot;;
+  this.nodeType  = DOMNode.CDATA_SECTION_NODE;
+};
+DOMCDATASection.prototype = new DOMText;
+__extend__(DOMCDATASection.prototype,{
+    get xml(){
+        return &quot;&lt;![CDATA[&quot; + this.nodeValue + &quot;]]&gt;&quot;;
+    },
+    toString : function(){
+        return &quot;CDATA #&quot;+this._id;
+    }
+});$log(&quot;Defining Comment&quot;);
+/* 
+* Comment - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Comment&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMComment - This represents the content of a comment, i.e., all the characters between the starting '&lt;!--' and ending '--&gt;'
+ * @extends DOMCharacterData
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMComment = function(ownerDocument) {
+  this.DOMCharacterData  = DOMCharacterData;
+  this.DOMCharacterData(ownerDocument);
+
+  this.nodeName  = &quot;#comment&quot;;
+  this.nodeType  = DOMNode.COMMENT_NODE;
+};
+DOMComment.prototype = new DOMCharacterData;
+__extend__(DOMComment.prototype, {
+    get xml(){
+        return &quot;&lt;!-- &quot; + this.nodeValue + &quot; --&gt;&quot;;
+    },
+    toString : function(){
+        return &quot;Comment #&quot;+this._id;
+    }
+});
+$log(&quot;Defining DocumentType&quot;);
+;/*
+* DocumentType - DOM Level 2
+*/
+$w.__defineGetter__('DocumentType', function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var DOMDocumentType    = function() { $error(&quot;DOMDocumentType.constructor(): Not Implemented&quot;   ); };$log(&quot;Defining Attr&quot;);
+/*
+* Attr - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Attr&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+
+/**
+ * @class  DOMAttr - The Attr interface represents an attribute in an Element object
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMAttr = function(ownerDocument) {
+    //$log(&quot;\tcreating dom attribute&quot;);
+    this.DOMNode = DOMNode;
+    this.DOMNode(ownerDocument);
+    
+    this.name      = &quot;&quot;;                    // the name of this attribute
+    this.specified = false;
+    this.value     = &quot;&quot;;                    // the value of the attribute is returned as a string
+    this.nodeType  = DOMNode.ATTRIBUTE_NODE;
+    this.ownerElement = null;               // set when Attr is added to NamedNodeMap
+    
+    //$log(&quot;\tfincished creating dom attribute &quot; + this);
+};
+DOMAttr.prototype = new DOMNode; 
+__extend__(DOMAttr.prototype, {
+    get name(){
+        return this.nodeName;
+    },
+    get value(){
+        return this.nodeValue;
+    },
+    set value(value){
+        // throw Exception if Attribute is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        // delegate to node
+        this.specified = (this.value.length &gt; 0);
+        this.nodeValue = value;
+    },
+    get xml(){
+        return this.nodeName + &quot;='&quot; + this.nodeValue + &quot;' &quot;;
+    },
+    toString : function(){
+        return &quot;Attr #&quot; + this._id + &quot; &quot; + this.name;
+    }
+});    
+
+$log(&quot;Defining Element&quot;);
+/*
+* Element - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Element&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+	
+/**
+ * @class  DOMElement - By far the vast majority of objects (apart from text) that authors encounter
+ *   when traversing a document are Element nodes.
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMElement = function(ownerDocument) {
+    //$log(&quot;\tcreating dom element&quot;);
+    this.DOMNode  = DOMNode;
+    this.DOMNode(ownerDocument);
+    this.tagName = &quot;&quot;;                             // The name of the element.
+    this.id = &quot;&quot;;                                  // the ID of the element
+    this.nodeType = DOMNode.ELEMENT_NODE;
+    //$log(&quot;\nfinished creating dom element &quot; + this);
+};
+DOMElement.prototype = new DOMNode;
+__extend__(DOMElement.prototype, {
+  	addEventListener:     window.addEventListener,
+  	removeEventListener:  window.removeEventListener,
+  	dispatchEvent:        window.dispatchEvent,
+    getAttribute: function(name) {
+        var ret = null;
+        // if attribute exists, use it
+        var attr = this.attributes.getNamedItem(name);
+        if (attr) {
+            ret = attr.value;
+        }
+        return ret; // if Attribute exists, return its value, otherwise, return &quot;&quot;
+    },
+    setAttribute : function (name, value) {
+        // if attribute exists, use it
+        var attr = this.attributes.getNamedItem(name);
+        var value = new String(value);
+        //I had to add this check becuase as the script initializes
+        //the id may be set in the constructor, and the html element
+        //overrides the id property with a getter/setter.
+        if(this.ownerDocument){
+            if (!attr) {
+                attr = this.ownerDocument.createAttribute(name);  // otherwise create it
+            }
+            
+            
+            // test for exceptions
+            if (this.ownerDocument.implementation.errorChecking) {
+                // throw Exception if Attribute is readonly
+                if (attr._readonly) {
+                    throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+                }
+                
+                // throw Exception if the value string contains an illegal character
+                if (!__isValidString__(value)) {
+                    throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+                }
+            }
+            
+            if (__isIdDeclaration__(name)) {
+                this.id = value;  // cache ID for getElementById()
+            }
+            
+            // assign values to properties (and aliases)
+            attr.value     = value;
+            
+            // update .specified
+            if (value.length &gt; 0) {
+                attr.specified = true;
+            }else {
+                attr.specified = false;
+            }
+            
+            // add/replace Attribute in NamedNodeMap
+            this.attributes.setNamedItem(attr);
+        }
+    },
+    removeAttribute : function removeAttribute(name) {
+        // delegate to DOMNamedNodeMap.removeNamedItem
+        return this.attributes.removeNamedItem(name);
+    },
+    getAttributeNode : function getAttributeNode(name) {
+        // delegate to DOMNamedNodeMap.getNamedItem
+        return this.attributes.getNamedItem(name);
+    },
+    setAttributeNode: function(newAttr) {
+        // if this Attribute is an ID
+        if (__isIdDeclaration__(newAttr.name)) {
+            this.id = newAttr.value;  // cache ID for getElementById()
+        }
+        // delegate to DOMNamedNodeMap.setNamedItem
+        return this.attributes.setNamedItem(newAttr);
+    },
+    removeAttributeNode: function(oldAttr) {
+      // throw Exception if Attribute is readonly
+      if (this.ownerDocument.implementation.errorChecking &amp;&amp; oldAttr._readonly) {
+        throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+      }
+    
+      // get item index
+      var itemIndex = this.attributes._findItemIndex(oldAttr._id);
+    
+      // throw Exception if node does not exist in this map
+      if (this.ownerDocument.implementation.errorChecking &amp;&amp; (itemIndex &lt; 0)) {
+        throw(new DOMException(DOMException.NOT_FOUND_ERR));
+      }
+    
+      return this.attributes._removeChild(itemIndex);
+    },
+    getAttributeNS : function(namespaceURI, localName) {
+        var ret = &quot;&quot;;
+        // delegate to DOMNAmedNodeMap.getNamedItemNS
+        var attr = this.attributes.getNamedItemNS(namespaceURI, localName);
+        if (attr) {
+            ret = attr.value;
+        }
+        return ret;  // if Attribute exists, return its value, otherwise return &quot;&quot;
+    },
+    setAttributeNS : function(namespaceURI, qualifiedName, value) {
+        // call DOMNamedNodeMap.getNamedItem
+        var attr = this.attributes.getNamedItem(namespaceURI, qualifiedName);
+        
+        if (!attr) {  // if Attribute exists, use it
+            // otherwise create it
+            attr = this.ownerDocument.createAttributeNS(namespaceURI, qualifiedName);
+        }
+        
+        var value = String(value);
+        
+        // test for exceptions
+        if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if Attribute is readonly
+            if (attr._readonly) {
+                throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+            }
+            
+            // throw Exception if the Namespace is invalid
+            if (!__isValidNamespace__(namespaceURI, qualifiedName)) {
+                throw(new DOMException(DOMException.NAMESPACE_ERR));
+            }
+            
+            // throw Exception if the value string contains an illegal character
+            if (!__isValidString__(value)) {
+                throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+            }
+        }
+        
+        // if this Attribute is an ID
+        if (__isIdDeclaration__(name)) {
+            this.id = value;  // cache ID for getElementById()
+        }
+        
+        // assign values to properties (and aliases)
+        attr.value     = value;
+        attr.nodeValue = value;
+        
+        // update .specified
+        if (value.length &gt; 0) {
+            attr.specified = true;
+        }else {
+            attr.specified = false;
+        }
+        
+        // delegate to DOMNamedNodeMap.setNamedItem
+        this.attributes.setNamedItemNS(attr);
+    },
+    removeAttributeNS : function(namespaceURI, localName) {
+        // delegate to DOMNamedNodeMap.removeNamedItemNS
+        return this.attributes.removeNamedItemNS(namespaceURI, localName);
+    },
+    getAttributeNodeNS : function(namespaceURI, localName) {
+        // delegate to DOMNamedNodeMap.getNamedItemNS
+        return this.attributes.getNamedItemNS(namespaceURI, localName);
+    },
+    setAttributeNodeNS : function(newAttr) {
+        // if this Attribute is an ID
+        if ((newAttr.prefix == &quot;&quot;) &amp;&amp;  __isIdDeclaration__(newAttr.name)) {
+            this.id = String(newAttr.value);  // cache ID for getElementById()
+        }
+        
+        // delegate to DOMNamedNodeMap.setNamedItemNS
+        return this.attributes.setNamedItemNS(newAttr);
+    },
+    hasAttribute : function(name) {
+        // delegate to DOMNamedNodeMap._hasAttribute
+        return __hasAttribute__(this.attributes,name);
+    },
+    hasAttributeNS : function(namespaceURI, localName) {
+        // delegate to DOMNamedNodeMap._hasAttributeNS
+        return __hasAttributeNS__(this.attributes, namespaceURI, localName);
+    },
+    get xml() {
+        var ret = &quot;&quot;;
+        
+        // serialize namespace declarations
+        var ns = this._namespaces.xml;
+        if (ns.length &gt; 0) ns = &quot; &quot;+ ns;
+        
+        // serialize Attribute declarations
+        var attrs = this.attributes.xml;
+        if (attrs.length &gt; 0) attrs = &quot; &quot;+ attrs;
+        
+        // serialize this Element
+        ret += &quot;&lt;&quot; + this.nodeName.toLowerCase() + ns + attrs +&quot;&gt;&quot;;
+        ret += this.childNodes.xml;
+        ret += &quot;&lt;/&quot; + this.nodeName.toLowerCase()+&quot;&gt;&quot;;
+        
+        return ret;
+    },
+    toString : function(){
+        return &quot;Element #&quot;+this._id + &quot; &quot;+ this.tagName + (this.id?&quot; =&gt; &quot;+this.id:'');
+    }
+});
+
+/**
+ * @class  DOMException - raised when an operation is impossible to perform
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  code : int - the exception code (one of the DOMException constants)
+ */
+var DOMException = function(code) {
+  this.code = code;
+};
+
+// DOMException constants
+// Introduced in DOM Level 1:
+DOMException.INDEX_SIZE_ERR                 = 1;
+DOMException.DOMSTRING_SIZE_ERR             = 2;
+DOMException.HIERARCHY_REQUEST_ERR          = 3;
+DOMException.WRONG_DOCUMENT_ERR             = 4;
+DOMException.INVALID_CHARACTER_ERR          = 5;
+DOMException.NO_DATA_ALLOWED_ERR            = 6;
+DOMException.NO_MODIFICATION_ALLOWED_ERR    = 7;
+DOMException.NOT_FOUND_ERR                  = 8;
+DOMException.NOT_SUPPORTED_ERR              = 9;
+DOMException.INUSE_ATTRIBUTE_ERR            = 10;
+
+// Introduced in DOM Level 2:
+DOMException.INVALID_STATE_ERR              = 11;
+DOMException.SYNTAX_ERR                     = 12;
+DOMException.INVALID_MODIFICATION_ERR       = 13;
+DOMException.NAMESPACE_ERR                  = 14;
+DOMException.INVALID_ACCESS_ERR             = 15;
+$log(&quot;Defining DocumentFragment&quot;);
+/* 
+* DocumentFragment - DOM Level 2
+*/
+$w.__defineGetter__(&quot;DocumentFragment&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+/**
+ * @class  DOMDocumentFragment - DocumentFragment is a &quot;lightweight&quot; or &quot;minimal&quot; Document object.
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMDocumentFragment = function(ownerDocument) {
+  this.DOMNode = DOMNode;
+  this.DOMNode(ownerDocument);
+  this.nodeName  = &quot;#document-fragment&quot;;
+  this.nodeType = DOMNode.DOCUMENT_FRAGMENT_NODE;
+};
+DOMDocumentFragment.prototype = new DOMNode;
+__extend__(DOMDocumentFragment.prototype,{
+    get xml(){
+        var xml = &quot;&quot;,
+            count = this.childNodes.length;
+        
+        // create string concatenating the serialized ChildNodes
+        for (var i = 0; i &lt; count; i++) {
+            xml += this.childNodes.item(i).xml;
+        }
+        
+        return xml;
+    },
+    toString : function(){
+        return &quot;DocumentFragment #&quot;+this._id;
+    }
+});
+$log(&quot;Defining ProcessingInstruction&quot;);
+/*
+* ProcessingInstruction - DOM Level 2
+*/
+$w.__defineGetter__('ProcessingInstruction', function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+/**
+ * @class  DOMProcessingInstruction - The ProcessingInstruction interface represents a &quot;processing instruction&quot;,
+ *   used in XML as a way to keep processor-specific information in the text of the document
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMProcessingInstruction = function(ownerDocument) {
+  this.DOMNode  = DOMNode;
+  this.DOMNode(ownerDocument);
+  // The target of this processing instruction.
+  // XML defines this as being the first token following the markup that begins the processing instruction.
+  this.target = &quot;&quot;;
+  // The content of this processing instruction.
+  // This is from the first non white space character after the target to the character immediately preceding the ?&gt;
+  this.data   = &quot;&quot;;
+  this.nodeType  = DOMNode.PROCESSING_INSTRUCTION_NODE;
+};
+DOMProcessingInstruction.prototype = new DOMNode;
+__extend__(DOMProcessingInstruction.prototype, {
+    get data(){
+        return this.nodeValue;
+    },
+    set data(data){
+        // throw Exception if DOMNode is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        this.nodeValue = data;
+    },
+    get target(){
+        return this.nodeName;
+    },
+    get xml(){
+        return &quot;&lt;?&quot; + this.nodeName +&quot; &quot;+ this.nodeValue + &quot; ?&gt;&quot;;
+    },
+    toString : function(){
+        return &quot;ProcessingInstruction #&quot;+this._id;
+    }
+});
+$log(&quot;Defining DOMParser&quot;);
+/*
+* DOMParser
+*/
+$w.__defineGetter__('DOMParser', function(){
+  return function(){
+    return __extend__(this, {
+      parseFromString: function(xmlString){
+        //$log(&quot;Parsing XML String: &quot; +xmlString);
+        return document.implementation.createDocument().loadXML(xmlString);
+      }
+    });
+  };
+});
+
+$log(&quot;Initializing Internal DOMParser.&quot;);
+//keep one around for internal use
+$domparser = new DOMParser();
+
+// =========================================================================
+//
+// xmlsax.js - an XML SAX parser in JavaScript.
+//
+// version 3.1
+//
+// =========================================================================
+//
+// Copyright (C) 2001 - 2002 David Joham (djoham@yahoo.com) and Scott Severtson
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+// Visit the XML for &lt;SCRIPT&gt; home page at http://xmljs.sourceforge.net
+//
+
+// CONSTANTS
+var whitespace = &quot;\n\r\t &quot;;
+
+
+/**
+*   function:   this is the constructor to the XMLP Object
+*   Author:   Scott Severtson
+*   Description:XMLP is a pull-based parser. The calling application passes in a XML string
+*   to the constructor, then repeatedly calls .next() to parse the next segment.
+*   .next() returns a flag indicating what type of segment was found, and stores
+*   data temporarily in couple member variables (name, content, array of
+*   attributes), which can be accessed by several .get____() methods.
+*
+*   Basically, XMLP is the lowest common denominator parser - an very simple
+*   API which other wrappers can be built against.
+**/
+
+
+var XMLP = function(strXML) {
+    // Normalize line breaks
+    strXML = SAXStrings.replace(strXML, null, null, &quot;\r\n&quot;, &quot;\n&quot;);
+    strXML = SAXStrings.replace(strXML, null, null, &quot;\r&quot;, &quot;\n&quot;);
+
+    this.m_xml = strXML;
+    this.m_iP = 0;
+    this.m_iState = XMLP._STATE_PROLOG;
+    this.m_stack = new Stack();
+    this._clearAttributes();
+
+};
+
+
+// CONSTANTS    (these must be below the constructor)
+
+
+XMLP._NONE    = 0;
+XMLP._ELM_B   = 1;
+XMLP._ELM_E   = 2;
+XMLP._ELM_EMP = 3;
+XMLP._ATT     = 4;
+XMLP._TEXT    = 5;
+XMLP._ENTITY  = 6;
+XMLP._PI      = 7;
+XMLP._CDATA   = 8;
+XMLP._COMMENT = 9;
+XMLP._DTD     = 10;
+XMLP._ERROR   = 11;
+
+XMLP._CONT_XML = 0;
+XMLP._CONT_ALT = 1;
+
+XMLP._ATT_NAME = 0;
+XMLP._ATT_VAL  = 1;
+
+XMLP._STATE_PROLOG = 1;
+XMLP._STATE_DOCUMENT = 2;
+XMLP._STATE_MISC = 3;
+
+XMLP._errs = new Array();
+XMLP._errs[XMLP.ERR_CLOSE_PI       = 0 ] = &quot;PI: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_DTD      = 1 ] = &quot;DTD: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_COMMENT  = 2 ] = &quot;Comment: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_CDATA    = 3 ] = &quot;CDATA: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_ELM      = 4 ] = &quot;Element: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_CLOSE_ENTITY   = 5 ] = &quot;Entity: missing closing sequence&quot;;
+XMLP._errs[XMLP.ERR_PI_TARGET      = 6 ] = &quot;PI: target is required&quot;;
+XMLP._errs[XMLP.ERR_ELM_EMPTY      = 7 ] = &quot;Element: cannot be both empty and closing&quot;;
+XMLP._errs[XMLP.ERR_ELM_NAME       = 8 ] = &quot;Element: name must immediatly follow \&quot;&lt;\&quot;&quot;;
+XMLP._errs[XMLP.ERR_ELM_LT_NAME    = 9 ] = &quot;Element: \&quot;&lt;\&quot; not allowed in element names&quot;;
+XMLP._errs[XMLP.ERR_ATT_VALUES     = 10] = &quot;Attribute: values are required and must be in quotes&quot;;
+XMLP._errs[XMLP.ERR_ATT_LT_NAME    = 11] = &quot;Element: \&quot;&lt;\&quot; not allowed in attribute names&quot;;
+XMLP._errs[XMLP.ERR_ATT_LT_VALUE   = 12] = &quot;Attribute: \&quot;&lt;\&quot; not allowed in attribute values&quot;;
+XMLP._errs[XMLP.ERR_ATT_DUP        = 13] = &quot;Attribute: duplicate attributes not allowed&quot;;
+XMLP._errs[XMLP.ERR_ENTITY_UNKNOWN = 14] = &quot;Entity: unknown entity&quot;;
+XMLP._errs[XMLP.ERR_INFINITELOOP   = 15] = &quot;Infininte loop&quot;;
+XMLP._errs[XMLP.ERR_DOC_STRUCTURE  = 16] = &quot;Document: only comments, processing instructions, or whitespace allowed outside of document element&quot;;
+XMLP._errs[XMLP.ERR_ELM_NESTING    = 17] = &quot;Element: must be nested correctly&quot;;
+
+
+
+XMLP.prototype._addAttribute = function(name, value) {
+    this.m_atts[this.m_atts.length] = new Array(name, value);
+}  
+
+
+XMLP.prototype._checkStructure = function(iEvent) {
+  
+	if(XMLP._STATE_PROLOG == this.m_iState) {
+		if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
+            if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
+				return this._setErr(XMLP.ERR_DOC_STRUCTURE);
+            }
+        }
+
+        if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
+            this.m_iState = XMLP._STATE_DOCUMENT;
+            // Don't return - fall through to next state
+        }
+    }
+    if(XMLP._STATE_DOCUMENT == this.m_iState) {
+        if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
+            this.m_stack.push(this.getName());
+        }
+
+        if((XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent)) {
+            var strTop = this.m_stack.pop();
+            if((strTop == null) || (strTop != this.getName())) {
+                return this._setErr(XMLP.ERR_ELM_NESTING);
+            }
+        }
+
+        if(this.m_stack.count() == 0) {
+            this.m_iState = XMLP._STATE_MISC;
+            return iEvent;
+        }
+    }
+    if(XMLP._STATE_MISC == this.m_iState) {
+		if((XMLP._ELM_B == iEvent) || (XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent) || (XMLP.EVT_DTD == iEvent)) {
+			return this._setErr(XMLP.ERR_DOC_STRUCTURE);
+        }
+
+        if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
+			if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
+				return this._setErr(XMLP.ERR_DOC_STRUCTURE);
+            }
+        }
+    }
+
+    return iEvent;
+
+}  
+
+
+XMLP.prototype._clearAttributes = function() {
+    this.m_atts = new Array();
+}  
+
+
+XMLP.prototype._findAttributeIndex = function(name) {
+    for(var i = 0; i &lt; this.m_atts.length; i++) {
+        if(this.m_atts[i][XMLP._ATT_NAME] == name) {
+            return i;
+        }
+    }
+    return -1;
+
+}  
+
+
+XMLP.prototype.getAttributeCount = function() {
+
+    return this.m_atts ? this.m_atts.length : 0;
+
+}  
+
+
+XMLP.prototype.getAttributeName = function(index) {
+
+    return ((index &lt; 0) || (index &gt;= this.m_atts.length)) ? null : this.m_atts[index][XMLP._ATT_NAME];
+
+}  
+
+
+XMLP.prototype.getAttributeValue = function(index) {
+
+    return ((index &lt; 0) || (index &gt;= this.m_atts.length)) ? null : __unescapeXML__(this.m_atts[index][XMLP._ATT_VAL]);
+
+} 
+
+
+XMLP.prototype.getAttributeValueByName = function(name) {
+
+    return this.getAttributeValue(this._findAttributeIndex(name));
+
+}  
+
+
+XMLP.prototype.getColumnNumber = function() {
+
+    return SAXStrings.getColumnNumber(this.m_xml, this.m_iP);
+
+}  
+
+
+XMLP.prototype.getContent = function() {
+
+    return (this.m_cSrc == XMLP._CONT_XML) ? this.m_xml : this.m_cAlt;
+
+}  
+
+
+XMLP.prototype.getContentBegin = function() {
+
+    return this.m_cB;
+
+}  
+
+
+XMLP.prototype.getContentEnd = function() {
+
+    return this.m_cE;
+
+}  
+
+
+XMLP.prototype.getLineNumber = function() {
+
+    return SAXStrings.getLineNumber(this.m_xml, this.m_iP);
+
+}  
+
+
+XMLP.prototype.getName = function() {
+
+    return this.m_name;
+
+}  
+
+
+XMLP.prototype.next = function() {
+
+    return this._checkStructure(this._parse());
+
+} 
+
+
+XMLP.prototype._parse = function() {
+
+	if(this.m_iP == this.m_xml.length) {
+        return XMLP._NONE;
+    }
+
+    if(this.m_iP == this.m_xml.indexOf(&quot;&lt;?&quot;,        this.m_iP)) {
+        return this._parsePI     (this.m_iP + 2);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;!DOCTYPE&quot;, this.m_iP)) {
+        return this._parseDTD    (this.m_iP + 9);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;!--&quot;,      this.m_iP)) {
+        return this._parseComment(this.m_iP + 4);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;![CDATA[&quot;, this.m_iP)) {
+        return this._parseCDATA  (this.m_iP + 9);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&lt;&quot;,         this.m_iP)) {
+        return this._parseElement(this.m_iP + 1);
+    }
+    else if(this.m_iP == this.m_xml.indexOf(&quot;&amp;&quot;,         this.m_iP)) {
+        return this._parseEntity (this.m_iP + 1);
+    }
+    else{
+        return this._parseText   (this.m_iP);
+    }
+	
+
+} 
+
+
+XMLP.prototype._parseAttribute = function(iB, iE) {
+    var iNB, iNE, iEq, iVB, iVE;
+    var cQuote, strN, strV;
+
+	this.m_cAlt = &quot;&quot;; //resets the value so we don't use an old one by accident (see testAttribute7 in the test suite)
+    
+	iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
+    if((iNB == -1) ||(iNB &gt;= iE)) {
+        return iNB;
+    }
+
+    iEq = this.m_xml.indexOf(&quot;=&quot;, iNB);
+    if((iEq == -1) || (iEq &gt; iE)) {
+        return this._setErr(XMLP.ERR_ATT_VALUES);
+    }
+
+    iNE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iNB, iEq);
+
+    iVB = SAXStrings.indexOfNonWhitespace(this.m_xml, iEq + 1, iE);
+    if((iVB == -1) ||(iVB &gt; iE)) {
+        return this._setErr(XMLP.ERR_ATT_VALUES);
+    }
+
+    cQuote = this.m_xml.charAt(iVB);
+    if(SAXStrings.QUOTES.indexOf(cQuote) == -1) {
+        return this._setErr(XMLP.ERR_ATT_VALUES);
+    }
+
+    iVE = this.m_xml.indexOf(cQuote, iVB + 1);
+    if((iVE == -1) ||(iVE &gt; iE)) {
+        return this._setErr(XMLP.ERR_ATT_VALUES);
+    }
+
+    strN = this.m_xml.substring(iNB, iNE + 1);
+    strV = this.m_xml.substring(iVB + 1, iVE);
+
+    if(strN.indexOf(&quot;&lt;&quot;) != -1) {
+        return this._setErr(XMLP.ERR_ATT_LT_NAME);
+    }
+
+    if(strV.indexOf(&quot;&lt;&quot;) != -1) {
+        return this._setErr(XMLP.ERR_ATT_LT_VALUE);
+    }
+
+    strV = SAXStrings.replace(strV, null, null, &quot;\n&quot;, &quot; &quot;);
+    strV = SAXStrings.replace(strV, null, null, &quot;\t&quot;, &quot; &quot;);
+	iRet = this._replaceEntities(strV);
+    if(iRet == XMLP._ERROR) {
+        return iRet;
+    }
+
+    strV = this.m_cAlt;
+
+    if(this._findAttributeIndex(strN) == -1) {
+        this._addAttribute(strN, strV);
+    }
+    else {
+        return this._setErr(XMLP.ERR_ATT_DUP);
+    }
+
+    this.m_iP = iVE + 2;
+
+    return XMLP._ATT;
+
+}  
+
+
+XMLP.prototype._parseCDATA = function(iB) {
+    var iE = this.m_xml.indexOf(&quot;]]&gt;&quot;, iB);
+    if (iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_CDATA);
+    }
+
+    this._setContent(XMLP._CONT_XML, iB, iE);
+
+    this.m_iP = iE + 3;
+
+    return XMLP._CDATA;
+
+}  
+
+
+XMLP.prototype._parseComment = function(iB) {
+    var iE = this.m_xml.indexOf(&quot;-&quot; + &quot;-&gt;&quot;, iB);
+    if (iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_COMMENT);
+    }
+
+    this._setContent(XMLP._CONT_XML, iB, iE);
+
+    this.m_iP = iE + 3;
+
+    return XMLP._COMMENT;
+
+}  
+
+
+XMLP.prototype._parseDTD = function(iB) {
+
+    // Eat DTD
+
+    var iE, strClose, iInt, iLast;
+
+    iE = this.m_xml.indexOf(&quot;&gt;&quot;, iB);
+    if(iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_DTD);
+    }
+
+    iInt = this.m_xml.indexOf(&quot;[&quot;, iB);
+    strClose = ((iInt != -1) &amp;&amp; (iInt &lt; iE)) ? &quot;]&gt;&quot; : &quot;&gt;&quot;;
+
+    while(true) {
+        // DEBUG: Remove
+        if(iE == iLast) {
+            return this._setErr(XMLP.ERR_INFINITELOOP);
+        }
+
+        iLast = iE;
+        // DEBUG: Remove End
+
+        iE = this.m_xml.indexOf(strClose, iB);
+        if(iE == -1) {
+            return this._setErr(XMLP.ERR_CLOSE_DTD);
+        }
+
+        // Make sure it is not the end of a CDATA section
+        if (this.m_xml.substring(iE - 1, iE + 2) != &quot;]]&gt;&quot;) {
+            break;
+        }
+    }
+
+    this.m_iP = iE + strClose.length;
+
+    return XMLP._DTD;
+
+}  
+
+
+XMLP.prototype._parseElement = function(iB) {
+    var iE, iDE, iNE, iRet;
+    var iType, strN, iLast;
+
+    iDE = iE = this.m_xml.indexOf(&quot;&gt;&quot;, iB);
+    if(iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_ELM);
+    }
+
+    if(this.m_xml.charAt(iB) == &quot;/&quot;) {
+        iType = XMLP._ELM_E;
+        iB++;
+    } else {
+        iType = XMLP._ELM_B;
+    }
+
+    if(this.m_xml.charAt(iE - 1) == &quot;/&quot;) {
+        if(iType == XMLP._ELM_E) {
+            return this._setErr(XMLP.ERR_ELM_EMPTY);
+        }
+        iType = XMLP._ELM_EMP;
+        iDE--;
+    }
+
+    iDE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iB, iDE);
+
+    //djohack
+    //hack to allow for elements with single character names to be recognized
+
+    if (iE - iB != 1 ) {
+        if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB) {
+            return this._setErr(XMLP.ERR_ELM_NAME);
+        }
+    }
+    // end hack -- original code below
+
+    /*
+    if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB)
+        return this._setErr(XMLP.ERR_ELM_NAME);
+    */
+    this._clearAttributes();
+
+    iNE = SAXStrings.indexOfWhitespace(this.m_xml, iB, iDE);
+    if(iNE == -1) {
+        iNE = iDE + 1;
+    }
+    else {
+        this.m_iP = iNE;
+        while(this.m_iP &lt; iDE) {
+            // DEBUG: Remove
+            if(this.m_iP == iLast) return this._setErr(XMLP.ERR_INFINITELOOP);
+            iLast = this.m_iP;
+            // DEBUG: Remove End
+
+
+            iRet = this._parseAttribute(this.m_iP, iDE);
+            if(iRet == XMLP._ERROR) return iRet;
+        }
+    }
+
+    strN = this.m_xml.substring(iB, iNE);
+
+    if(strN.indexOf(&quot;&lt;&quot;) != -1) {
+        return this._setErr(XMLP.ERR_ELM_LT_NAME);
+    }
+
+    this.m_name = strN;
+    this.m_iP = iE + 1;
+
+    return iType;
+
+}  
+
+
+XMLP.prototype._parseEntity = function(iB) {
+    var iE = this.m_xml.indexOf(&quot;;&quot;, iB);
+    if(iE == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_ENTITY);
+    }
+
+    this.m_iP = iE + 1;
+
+    return this._replaceEntity(this.m_xml, iB, iE);
+
+} 
+
+
+XMLP.prototype._parsePI = function(iB) {
+
+    var iE, iTB, iTE, iCB, iCE;
+
+    iE = this.m_xml.indexOf(&quot;?&gt;&quot;, iB);
+    if(iE   == -1) {
+        return this._setErr(XMLP.ERR_CLOSE_PI);
+    }
+
+    iTB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
+    if(iTB == -1) {
+        return this._setErr(XMLP.ERR_PI_TARGET);
+    }
+
+    iTE = SAXStrings.indexOfWhitespace(this.m_xml, iTB, iE);
+    if(iTE  == -1) {
+        iTE = iE;
+    }
+
+    iCB = SAXStrings.indexOfNonWhitespace(this.m_xml, iTE, iE);
+    if(iCB == -1) {
+        iCB = iE;
+    }
+
+    iCE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iCB, iE);
+    if(iCE  == -1) {
+        iCE = iE - 1;
+    }
+
+    this.m_name = this.m_xml.substring(iTB, iTE);
+    this._setContent(XMLP._CONT_XML, iCB, iCE + 1);
+    this.m_iP = iE + 2;
+
+    return XMLP._PI;
+
+}  
+
+
+XMLP.prototype._parseText = function(iB) {
+    var iE, iEE;
+
+    iE = this.m_xml.indexOf(&quot;&lt;&quot;, iB);
+    if(iE == -1) {
+        iE = this.m_xml.length;
+    }
+
+    iEE = this.m_xml.indexOf(&quot;&amp;&quot;, iB);
+    if((iEE != -1) &amp;&amp; (iEE &lt;= iE)) {
+        iE = iEE;
+    }
+
+    this._setContent(XMLP._CONT_XML, iB, iE);
+
+    this.m_iP = iE;
+
+    return XMLP._TEXT;
+
+} 
+
+
+XMLP.prototype._replaceEntities = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) return &quot;&quot;;
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+
+    var iEB, iEE, strRet = &quot;&quot;;
+
+    iEB = strD.indexOf(&quot;&amp;&quot;, iB);
+    iEE = iB;
+
+    while((iEB &gt; 0) &amp;&amp; (iEB &lt; iE)) {
+        strRet += strD.substring(iEE, iEB);
+
+        iEE = strD.indexOf(&quot;;&quot;, iEB) + 1;
+
+        if((iEE == 0) || (iEE &gt; iE)) {
+            return this._setErr(XMLP.ERR_CLOSE_ENTITY);
+        }
+
+        iRet = this._replaceEntity(strD, iEB + 1, iEE - 1);
+        if(iRet == XMLP._ERROR) {
+            return iRet;
+        }
+
+        strRet += this.m_cAlt;
+
+        iEB = strD.indexOf(&quot;&amp;&quot;, iEE);
+    }
+
+    if(iEE != iE) {
+        strRet += strD.substring(iEE, iE);
+    }
+
+    this._setContent(XMLP._CONT_ALT, strRet);
+
+    return XMLP._ENTITY;
+
+}  
+
+
+XMLP.prototype._replaceEntity = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) return -1;
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    switch(strD.substring(iB, iE)) {
+        case &quot;amp&quot;:  strEnt = &quot;&amp;&quot;;  break;
+        case &quot;lt&quot;:   strEnt = &quot;&lt;&quot;;  break;
+        case &quot;gt&quot;:   strEnt = &quot;&gt;&quot;;  break;
+        case &quot;apos&quot;: strEnt = &quot;'&quot;;  break;
+        case &quot;quot&quot;: strEnt = &quot;\&quot;&quot;; break;
+        default:
+            if(strD.charAt(iB) == &quot;#&quot;) {
+                strEnt = String.fromCharCode(parseInt(strD.substring(iB + 1, iE)));
+            } else {
+                return this._setErr(XMLP.ERR_ENTITY_UNKNOWN);
+            }
+        break;
+    }
+    this._setContent(XMLP._CONT_ALT, strEnt);
+
+    return XMLP._ENTITY;
+}  
+
+
+XMLP.prototype._setContent = function(iSrc) {
+    var args = arguments;
+
+    if(XMLP._CONT_XML == iSrc) {
+        this.m_cAlt = null;
+        this.m_cB = args[1];
+        this.m_cE = args[2];
+    } else {
+        this.m_cAlt = args[1];
+        this.m_cB = 0;
+        this.m_cE = args[1].length;
+    }
+    this.m_cSrc = iSrc;
+
+}  
+
+
+XMLP.prototype._setErr = function(iErr) {
+    var strErr = XMLP._errs[iErr];
+
+    this.m_cAlt = strErr;
+    this.m_cB = 0;
+    this.m_cE = strErr.length;
+    this.m_cSrc = XMLP._CONT_ALT;
+
+    return XMLP._ERROR;
+
+}  
+
+
+/**
+* function:   SAXDriver
+* Author:   Scott Severtson
+* Description:
+*    SAXDriver is an object that basically wraps an XMLP instance, and provides an
+*   event-based interface for parsing. This is the object users interact with when coding
+*   with XML for &lt;SCRIPT&gt;
+**/
+
+var SAXDriver = function() {
+    this.m_hndDoc = null;
+    this.m_hndErr = null;
+    this.m_hndLex = null;
+}
+
+
+// CONSTANTS
+SAXDriver.DOC_B = 1;
+SAXDriver.DOC_E = 2;
+SAXDriver.ELM_B = 3;
+SAXDriver.ELM_E = 4;
+SAXDriver.CHARS = 5;
+SAXDriver.PI    = 6;
+SAXDriver.CD_B  = 7;
+SAXDriver.CD_E  = 8;
+SAXDriver.CMNT  = 9;
+SAXDriver.DTD_B = 10;
+SAXDriver.DTD_E = 11;
+
+
+
+SAXDriver.prototype.parse = function(strD) {
+    var parser = new XMLP(strD);
+
+    if(this.m_hndDoc &amp;&amp; this.m_hndDoc.setDocumentLocator) {
+        this.m_hndDoc.setDocumentLocator(this);
+    }
+
+    this.m_parser = parser;
+    this.m_bErr = false;
+
+    if(!this.m_bErr) {
+        this._fireEvent(SAXDriver.DOC_B);
+    }
+    this._parseLoop();
+    if(!this.m_bErr) {
+        this._fireEvent(SAXDriver.DOC_E);
+    }
+
+    this.m_xml = null;
+    this.m_iP = 0;
+
+}  
+
+
+SAXDriver.prototype.setDocumentHandler = function(hnd) {
+
+    this.m_hndDoc = hnd;
+
+}   
+
+
+SAXDriver.prototype.setErrorHandler = function(hnd) {
+
+    this.m_hndErr = hnd;
+
+}  
+
+
+SAXDriver.prototype.setLexicalHandler = function(hnd) {
+
+    this.m_hndLex = hnd;
+
+}  
+
+
+    /**
+    * LOCATOR/PARSE EXCEPTION INTERFACE
+    ***/
+
+SAXDriver.prototype.getColumnNumber = function() {
+
+    return this.m_parser.getColumnNumber();
+
+}
+
+
+SAXDriver.prototype.getLineNumber = function() {
+
+    return this.m_parser.getLineNumber();
+
+}
+
+
+SAXDriver.prototype.getMessage = function() {
+
+    return this.m_strErrMsg;
+
+}
+
+
+SAXDriver.prototype.getPublicId = function() {
+
+    return null;
+
+}  
+
+
+SAXDriver.prototype.getSystemId = function() {
+
+    return null;
+
+}  
+
+
+    /***
+    * Attribute List Interface
+    **/
+
+SAXDriver.prototype.getLength = function() {
+
+    return this.m_parser.getAttributeCount();
+
+}  
+
+
+SAXDriver.prototype.getName = function(index) {
+
+    return this.m_parser.getAttributeName(index);
+
+} 
+
+
+SAXDriver.prototype.getValue = function(index) {
+
+    return this.m_parser.getAttributeValue(index);
+
+}  
+
+
+SAXDriver.prototype.getValueByName = function(name) {
+
+    return this.m_parser.getAttributeValueByName(name);
+
+} 
+
+
+    /***
+    *    Private functions
+    **/
+
+SAXDriver.prototype._fireError = function(strMsg) {
+    this.m_strErrMsg = strMsg;
+    this.m_bErr = true;
+
+    if(this.m_hndErr &amp;&amp; this.m_hndErr.fatalError) {
+        this.m_hndErr.fatalError(this);
+    }
+
+}   // end function _fireError
+
+
+SAXDriver.prototype._fireEvent = function(iEvt) {
+    var hnd, func, args = arguments, iLen = args.length - 1;
+
+    if(this.m_bErr) return;
+
+    if(SAXDriver.DOC_B == iEvt) {
+        func = &quot;startDocument&quot;;         hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.DOC_E == iEvt) {
+        func = &quot;endDocument&quot;;           hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.ELM_B == iEvt) {
+        func = &quot;startElement&quot;;          hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.ELM_E == iEvt) {
+        func = &quot;endElement&quot;;            hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.CHARS == iEvt) {
+        func = &quot;characters&quot;;            hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.PI    == iEvt) {
+        func = &quot;processingInstruction&quot;; hnd = this.m_hndDoc;
+    }
+    else if (SAXDriver.CD_B  == iEvt) {
+        func = &quot;startCDATA&quot;;            hnd = this.m_hndLex;
+    }
+    else if (SAXDriver.CD_E  == iEvt) {
+        func = &quot;endCDATA&quot;;              hnd = this.m_hndLex;
+    }
+    else if (SAXDriver.CMNT  == iEvt) {
+        func = &quot;comment&quot;;               hnd = this.m_hndLex;
+    }
+
+    if(hnd &amp;&amp; hnd[func]) {
+        if(0 == iLen) {
+            hnd[func]();
+        }
+        else if (1 == iLen) {
+            hnd[func](args[1]);
+        }
+        else if (2 == iLen) {
+            hnd[func](args[1], args[2]);
+        }
+        else if (3 == iLen) {
+            hnd[func](args[1], args[2], args[3]);
+        }
+    }
+
+}  // end function _fireEvent
+
+
+SAXDriver.prototype._parseLoop = function(parser) {
+    var iEvent, parser;
+
+    parser = this.m_parser;
+    while(!this.m_bErr) {
+        iEvent = parser.next();
+
+        if(iEvent == XMLP._ELM_B) {
+            this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
+        }
+        else if(iEvent == XMLP._ELM_E) {
+            this._fireEvent(SAXDriver.ELM_E, parser.getName());
+        }
+        else if(iEvent == XMLP._ELM_EMP) {
+            this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
+            this._fireEvent(SAXDriver.ELM_E, parser.getName());
+        }
+        else if(iEvent == XMLP._TEXT) {
+            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+        }
+        else if(iEvent == XMLP._ENTITY) {
+            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+        }
+        else if(iEvent == XMLP._PI) {
+            this._fireEvent(SAXDriver.PI, parser.getName(), parser.getContent().substring(parser.getContentBegin(), parser.getContentEnd()));
+        }
+        else if(iEvent == XMLP._CDATA) {
+            this._fireEvent(SAXDriver.CD_B);
+            this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+            this._fireEvent(SAXDriver.CD_E);
+        }
+        else if(iEvent == XMLP._COMMENT) {
+            this._fireEvent(SAXDriver.CMNT, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+        }
+        else if(iEvent == XMLP._DTD) {
+        }
+        else if(iEvent == XMLP._ERROR) {
+            this._fireError(parser.getContent());
+        }
+        else if(iEvent == XMLP._NONE) {
+            return;
+        }
+    }
+
+}  // end function _parseLoop
+
+/**
+*   function:   SAXStrings
+*   Author:   Scott Severtson
+*   Description: a useful object containing string manipulation functions
+**/
+
+var SAXStrings = function() {};
+
+
+SAXStrings.WHITESPACE = &quot; \t\n\r&quot;;
+SAXStrings.QUOTES = &quot;\&quot;'&quot;;
+
+
+SAXStrings.getColumnNumber = function(strD, iP) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iP = iP || strD.length;
+
+    var arrD = strD.substring(0, iP).split(&quot;\n&quot;);
+    var strLine = arrD[arrD.length - 1];
+    arrD.length--;
+    var iLinePos = arrD.join(&quot;\n&quot;).length;
+
+    return iP - iLinePos;
+
+}  // end function getColumnNumber
+
+
+SAXStrings.getLineNumber = function(strD, iP) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iP = iP || strD.length;
+
+    return strD.substring(0, iP).split(&quot;\n&quot;).length
+}  // end function getLineNumber
+
+
+SAXStrings.indexOfNonWhitespace = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    for(var i = iB; i &lt; iE; i++){
+        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1) {
+            return i;
+        }
+    }
+    return -1;
+
+}  // end function indexOfNonWhitespace
+
+
+SAXStrings.indexOfWhitespace = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    for(var i = iB; i &lt; iE; i++) {
+        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) != -1) {
+            return i;
+        }
+    }
+    return -1;
+}  // end function indexOfWhitespace
+
+
+SAXStrings.isEmpty = function(strD) {
+
+    return (strD == null) || (strD.length == 0);
+
+}
+
+
+SAXStrings.lastIndexOfNonWhitespace = function(strD, iB, iE) {
+    if(SAXStrings.isEmpty(strD)) {
+        return -1;
+    }
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    for(var i = iE - 1; i &gt;= iB; i--){
+        if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1){
+            return i;
+        }
+    }
+    return -1;
+}
+
+
+SAXStrings.replace = function(strD, iB, iE, strF, strR) {
+    if(SAXStrings.isEmpty(strD)) {
+        return &quot;&quot;;
+    }
+    iB = iB || 0;
+    iE = iE || strD.length;
+
+    return strD.substring(iB, iE).split(strF).join(strR);
+
+}
+
+
+
+/***************************************************************************************************************
+Stack: A simple stack class, used for verifying document structure.
+
+    Author:   Scott Severtson
+*****************************************************************************************************************/
+
+var Stack = function() {
+    this.m_arr = new Array();
+}; 
+__extend__(Stack.prototype, {
+    clear : function() {
+        this.m_arr = new Array();
+    },
+    count : function() {
+        return this.m_arr.length;
+    },
+    destroy : function() {
+        this.m_arr = null;
+    },
+    peek : function() {
+        if(this.m_arr.length == 0) {
+            return null;
+        }
+        return this.m_arr[this.m_arr.length - 1];
+    },
+    pop : function() {
+        if(this.m_arr.length == 0) {
+            return null;
+        }
+        var o = this.m_arr[this.m_arr.length - 1];
+        this.m_arr.length--;
+        return o;
+    },
+    push : function(o) {
+        this.m_arr[this.m_arr.length] = o;
+    }
+});    
+
+
+/**
+* function: isEmpty
+* Author: mike@idle.org
+* Description:  convenience function to identify an empty string
+**/
+function isEmpty(str) {
+    return (str==null) || (str.length==0);
+};
+
+
+/**
+ * function __escapeXML__
+ * author: David Joham djoham@yahoo.com
+ * @param  str : string - The string to be escaped
+ * @return : string - The escaped string
+ */
+var escAmpRegEx = /&amp;/g;
+var escLtRegEx = /&lt;/g;
+var escGtRegEx = /&gt;/g;
+var quotRegEx = /&quot;/g;
+var aposRegEx = /'/g;
+function __escapeXML__(str) {
+    str = str.replace(escAmpRegEx, &quot;&amp;amp;&quot;).
+            replace(escLtRegEx, &quot;&amp;lt;&quot;).
+            replace(escGtRegEx, &quot;&amp;gt;&quot;).
+            replace(quotRegEx, &quot;&amp;quot;&quot;).
+            replace(aposRegEx, &quot;&amp;apos;&quot;);
+
+    return str;
+};
+
+/**
+ * function __unescapeXML__ 
+ * author: David Joham djoham@yahoo.com
+ * @param  str : string - The string to be unescaped
+ * @return : string - The unescaped string
+ */
+var unescAmpRegEx = /&amp;amp;/g;
+var unescLtRegEx = /&amp;lt;/g;
+var unescGtRegEx = /&amp;gt;/g;
+var unquotRegEx = /&amp;quot;/g;
+var unaposRegEx = /&amp;apos;/g;
+function __unescapeXML__(str) {
+    str = str.replace(unescAmpRegEx, &quot;&amp;&quot;).
+            replace(unescLtRegEx, &quot;&lt;&quot;).
+            replace(unescGtRegEx, &quot;&gt;&quot;).
+            replace(unquotRegEx, &quot;\&quot;&quot;).
+            replace(unaposRegEx, &quot;'&quot;);
+
+    return str;
+};
+
+//DOMImplementation
+$log(&quot;Defining DOMImplementation&quot;);
+$w.__defineGetter__(&quot;DOMImplementation&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMImplementation - provides a number of methods for performing operations
+ *   that are independent of any particular instance of the document object model.
+ *
+ * @author Jon van Noort (jon@webarcana.com.au)
+ */
+var DOMImplementation = function() {
+    this.preserveWhiteSpace = false;  // by default, ignore whitespace
+    this.namespaceAware = true;       // by default, handle namespaces
+    this.errorChecking  = true;       // by default, test for exceptions
+};
+__extend__(DOMImplementation.prototype,{
+    // @param  feature : string - The package name of the feature to test. 
+    //      the legal only values are &quot;XML&quot; and &quot;CORE&quot; (case-insensitive).
+    // @param  version : string - This is the version number of the package
+    //       name to test. In Level 1, this is the string &quot;1.0&quot;.*
+    // @return : boolean
+    hasFeature : function(feature, version) {
+        var ret = false;
+        if (feature.toLowerCase() == &quot;xml&quot;) {
+            ret = (!version || (version == &quot;1.0&quot;) || (version == &quot;2.0&quot;));
+        }
+        else if (feature.toLowerCase() == &quot;core&quot;) {
+            ret = (!version || (version == &quot;2.0&quot;));
+        }
+        return ret;
+    },
+	createDocumentType : function(qname, publicid, systemid){
+		return new DOMDocumentType();
+	},
+	createDocument : function(nsuri, qname, doctype){
+	  //TODO - this currently returns an empty doc
+	  //but needs to handle the args
+		return new HTMLDocument($implementation);
+	},
+    translateErrCode : function(code) {
+        //convert DOMException Code to human readable error message;
+      var msg = &quot;&quot;;
+    
+      switch (code) {
+        case DOMException.INDEX_SIZE_ERR :                // 1
+           msg = &quot;INDEX_SIZE_ERR: Index out of bounds&quot;;
+           break;
+    
+        case DOMException.DOMSTRING_SIZE_ERR :            // 2
+           msg = &quot;DOMSTRING_SIZE_ERR: The resulting string is too long to fit in a DOMString&quot;;
+           break;
+    
+        case DOMException.HIERARCHY_REQUEST_ERR :         // 3
+           msg = &quot;HIERARCHY_REQUEST_ERR: The Node can not be inserted at this location&quot;;
+           break;
+    
+        case DOMException.WRONG_DOCUMENT_ERR :            // 4
+           msg = &quot;WRONG_DOCUMENT_ERR: The source and the destination Documents are not the same&quot;;
+           break;
+    
+        case DOMException.INVALID_CHARACTER_ERR :         // 5
+           msg = &quot;INVALID_CHARACTER_ERR: The string contains an invalid character&quot;;
+           break;
+    
+        case DOMException.NO_DATA_ALLOWED_ERR :           // 6
+           msg = &quot;NO_DATA_ALLOWED_ERR: This Node / NodeList does not support data&quot;;
+           break;
+    
+        case DOMException.NO_MODIFICATION_ALLOWED_ERR :   // 7
+           msg = &quot;NO_MODIFICATION_ALLOWED_ERR: This object cannot be modified&quot;;
+           break;
+    
+        case DOMException.NOT_FOUND_ERR :                 // 8
+           msg = &quot;NOT_FOUND_ERR: The item cannot be found&quot;;
+           break;
+    
+        case DOMException.NOT_SUPPORTED_ERR :             // 9
+           msg = &quot;NOT_SUPPORTED_ERR: This implementation does not support function&quot;;
+           break;
+    
+        case DOMException.INUSE_ATTRIBUTE_ERR :           // 10
+           msg = &quot;INUSE_ATTRIBUTE_ERR: The Attribute has already been assigned to another Element&quot;;
+           break;
+    
+        // Introduced in DOM Level 2:
+        case DOMException.INVALID_STATE_ERR :             // 11
+           msg = &quot;INVALID_STATE_ERR: The object is no longer usable&quot;;
+           break;
+    
+        case DOMException.SYNTAX_ERR :                    // 12
+           msg = &quot;SYNTAX_ERR: Syntax error&quot;;
+           break;
+    
+        case DOMException.INVALID_MODIFICATION_ERR :      // 13
+           msg = &quot;INVALID_MODIFICATION_ERR: Cannot change the type of the object&quot;;
+           break;
+    
+        case DOMException.NAMESPACE_ERR :                 // 14
+           msg = &quot;NAMESPACE_ERR: The namespace declaration is incorrect&quot;;
+           break;
+    
+        case DOMException.INVALID_ACCESS_ERR :            // 15
+           msg = &quot;INVALID_ACCESS_ERR: The object does not support this function&quot;;
+           break;
+    
+        default :
+           msg = &quot;UNKNOWN: Unknown Exception Code (&quot;+ code +&quot;)&quot;;
+      }
+    
+      return msg;
+    }
+});
+  
+
+/**
+* Defined 'globally' to this scope.  Remember everything is wrapped in a closure so this doesnt show up 
+* in the outer most global scope.
+*/
+  
+/**
+ *  process SAX events
+ *
+ * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
+ *
+ * @param  impl : DOMImplementation
+ * @param  doc : DOMDocument - the Document to contain the parsed XML string
+ * @param  p   : XMLP        - the SAX Parser
+ *
+ * @return : DOMDocument
+ */
+function __parseLoop__(impl, doc, p) {
+  var iEvt, iNode, iAttr, strName;
+  iNodeParent = doc;
+
+  var el_close_count = 0;
+
+  var entitiesList = new Array();
+  var textNodesList = new Array();
+
+  // if namespaceAware, add default namespace
+  if (impl.namespaceAware) {
+    var iNS = doc.createNamespace(&quot;&quot;); // add the default-default namespace
+    iNS.value = &quot;http://www.w3.org/2000/xmlns/&quot;;
+    doc._namespaces.setNamedItem(iNS);
+  }
+
+  // loop until SAX parser stops emitting events
+  while(true) {
+    // get next event
+    iEvt = p.next();
+
+    if (iEvt == XMLP._ELM_B) {                      // Begin-Element Event
+      var pName = p.getName();                      // get the Element name
+      pName = trim(pName, true, true);              // strip spaces from Element name
+
+      if (!impl.namespaceAware) {
+        iNode = doc.createElement(p.getName());     // create the Element
+
+        // add attributes to Element
+        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
+          strName = p.getAttributeName(i);          // get Attribute name
+          iAttr = iNode.getAttributeNode(strName);  // if Attribute exists, use it
+
+          if(!iAttr) {
+            iAttr = doc.createAttribute(strName);   // otherwise create it
+          }
+
+          iAttr.value = p.getAttributeValue(i);   // set Attribute value
+          iNode.setAttributeNode(iAttr);            // attach Attribute to Element
+        }
+      }
+      else {  // Namespace Aware
+        // create element (with empty namespaceURI,
+        //  resolve after namespace 'attributes' have been parsed)
+        iNode = doc.createElementNS(&quot;&quot;, p.getName());
+
+        // duplicate ParentNode's Namespace definitions
+        iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
+
+        // add attributes to Element
+        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
+          strName = p.getAttributeName(i);          // get Attribute name
+
+          // if attribute is a namespace declaration
+          if (__isNamespaceDeclaration__(strName)) {
+            // parse Namespace Declaration
+            var namespaceDec = __parseNSName__(strName);
+
+            if (strName != &quot;xmlns&quot;) {
+              iNS = doc.createNamespace(strName);   // define namespace
+            }
+            else {
+              iNS = doc.createNamespace(&quot;&quot;);        // redefine default namespace
+            }
+            iNS.value = p.getAttributeValue(i);   // set value = namespaceURI
+
+            iNode._namespaces.setNamedItem(iNS);    // attach namespace to namespace collection
+          }
+          else {  // otherwise, it is a normal attribute
+            iAttr = iNode.getAttributeNode(strName);        // if Attribute exists, use it
+
+            if(!iAttr) {
+              iAttr = doc.createAttributeNS(&quot;&quot;, strName);   // otherwise create it
+            }
+
+            iAttr.value = p.getAttributeValue(i);         // set Attribute value
+            iNode.setAttributeNodeNS(iAttr);                // attach Attribute to Element
+
+            if (__isIdDeclaration__(strName)) {
+              iNode.id = p.getAttributeValue(i);    // cache ID for getElementById()
+            }
+          }
+        }
+
+        // resolve namespaceURIs for this Element
+        if (iNode._namespaces.getNamedItem(iNode.prefix)) {
+          iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
+        }
+
+        //  for this Element's attributes
+        for (var i = 0; i &lt; iNode.attributes.length; i++) {
+          if (iNode.attributes.item(i).prefix != &quot;&quot;) {  // attributes do not have a default namespace
+            if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
+              iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
+            }
+          }
+        }
+      }
+
+      // if this is the Root Element
+      if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
+        iNodeParent.documentElement = iNode;        // register this Element as the Document.documentElement
+      }
+
+      iNodeParent.appendChild(iNode);               // attach Element to parentNode
+      iNodeParent = iNode;                          // descend one level of the DOM Tree
+    }
+
+    else if(iEvt == XMLP._ELM_E) {                  // End-Element Event
+      iNodeParent = iNodeParent.parentNode;         // ascend one level of the DOM Tree
+    }
+
+    else if(iEvt == XMLP._ELM_EMP) {                // Empty Element Event
+      pName = p.getName();                          // get the Element name
+      pName = trim(pName, true, true);              // strip spaces from Element name
+
+      if (!impl.namespaceAware) {
+        iNode = doc.createElement(pName);           // create the Element
+
+        // add attributes to Element
+        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
+          strName = p.getAttributeName(i);          // get Attribute name
+          iAttr = iNode.getAttributeNode(strName);  // if Attribute exists, use it
+
+          if(!iAttr) {
+            iAttr = doc.createAttribute(strName);   // otherwise create it
+          }
+
+          iAttr.value = p.getAttributeValue(i);   // set Attribute value
+          iNode.setAttributeNode(iAttr);            // attach Attribute to Element
+        }
+      }
+      else {  // Namespace Aware
+        // create element (with empty namespaceURI,
+        //  resolve after namespace 'attributes' have been parsed)
+        iNode = doc.createElementNS(&quot;&quot;, p.getName());
+
+        // duplicate ParentNode's Namespace definitions
+        iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
+
+        // add attributes to Element
+        for(var i = 0; i &lt; p.getAttributeCount(); i++) {
+          strName = p.getAttributeName(i);          // get Attribute name
+
+          // if attribute is a namespace declaration
+          if (__isNamespaceDeclaration__(strName)) {
+            // parse Namespace Declaration
+            var namespaceDec = __parseNSName__(strName);
+
+            if (strName != &quot;xmlns&quot;) {
+              iNS = doc.createNamespace(strName);   // define namespace
+            }
+            else {
+              iNS = doc.createNamespace(&quot;&quot;);        // redefine default namespace
+            }
+            iNS.value = p.getAttributeValue(i);   // set value = namespaceURI
+
+            iNode._namespaces.setNamedItem(iNS);    // attach namespace to namespace collection
+          }
+          else {  // otherwise, it is a normal attribute
+            iAttr = iNode.getAttributeNode(strName);        // if Attribute exists, use it
+
+            if(!iAttr) {
+              iAttr = doc.createAttributeNS(&quot;&quot;, strName);   // otherwise create it
+            }
+
+            iAttr.value = p.getAttributeValue(i);         // set Attribute value
+            iNode.setAttributeNodeNS(iAttr);                // attach Attribute to Element
+
+            if (__isIdDeclaration__(strName)) {
+              iNode.id = p.getAttributeValue(i);    // cache ID for getElementById()
+            }
+          }
+        }
+
+        // resolve namespaceURIs for this Element
+        if (iNode._namespaces.getNamedItem(iNode.prefix)) {
+          iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
+        }
+
+        //  for this Element's attributes
+        for (var i = 0; i &lt; iNode.attributes.length; i++) {
+          if (iNode.attributes.item(i).prefix != &quot;&quot;) {  // attributes do not have a default namespace
+            if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
+              iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
+            }
+          }
+        }
+      }
+
+      // if this is the Root Element
+      if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
+        iNodeParent.documentElement = iNode;        // register this Element as the Document.documentElement
+      }
+
+      iNodeParent.appendChild(iNode);               // attach Element to parentNode
+    }
+    else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) {                   // TextNode and entity Events
+      // get Text content
+      var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
+      
+	  if (!impl.preserveWhiteSpace ) {
+		if (trim(pContent, true, true) == &quot;&quot;) {
+			pContent = &quot;&quot;; //this will cause us not to create the text node below
+		}
+	  }
+	  
+      if (pContent.length &gt; 0) {                    // ignore empty TextNodes
+        var textNode = doc.createTextNode(pContent);
+        iNodeParent.appendChild(textNode); // attach TextNode to parentNode
+
+        //the sax parser breaks up text nodes when it finds an entity. For
+        //example hello&amp;lt;there will fire a text, an entity and another text
+        //this sucks for the dom parser because it looks to us in this logic
+        //as three text nodes. I fix this by keeping track of the entity nodes
+        //and when we're done parsing, calling normalize on their parent to
+        //turn the multiple text nodes into one, which is what DOM users expect
+        //the code to do this is at the bottom of this function
+        if (iEvt == XMLP._ENTITY) {
+            entitiesList[entitiesList.length] = textNode;
+        }
+		else {
+			//I can't properly decide how to handle preserve whitespace
+			//until the siblings of the text node are built due to 
+			//the entitiy handling described above. I don't know that this
+			//will be all of the text node or not, so trimming is not appropriate
+			//at this time. Keep a list of all the text nodes for now
+			//and we'll process the preserve whitespace stuff at a later time.
+			textNodesList[textNodesList.length] = textNode;
+		}
+      }
+    }
+    else if(iEvt == XMLP._PI) {                     // ProcessingInstruction Event
+      // attach ProcessingInstruction to parentNode
+      iNodeParent.appendChild(doc.createProcessingInstruction(p.getName(), p.getContent().substring(p.getContentBegin(), p.getContentEnd())));
+    }
+    else if(iEvt == XMLP._CDATA) {                  // CDATA Event
+      // get CDATA data
+      pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
+
+      if (!impl.preserveWhiteSpace) {
+        pContent = trim(pContent, true, true);      // trim whitespace
+        pContent.replace(/ +/g, ' ');               // collapse multiple spaces to 1 space
+      }
+
+      if (pContent.length &gt; 0) {                    // ignore empty CDATANodes
+        iNodeParent.appendChild(doc.createCDATASection(pContent)); // attach CDATA to parentNode
+      }
+    }
+    else if(iEvt == XMLP._COMMENT) {                // Comment Event
+      // get COMMENT data
+      var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
+
+      if (!impl.preserveWhiteSpace) {
+        pContent = trim(pContent, true, true);      // trim whitespace
+        pContent.replace(/ +/g, ' ');               // collapse multiple spaces to 1 space
+      }
+
+      if (pContent.length &gt; 0) {                    // ignore empty CommentNodes
+        iNodeParent.appendChild(doc.createComment(pContent));  // attach Comment to parentNode
+      }
+    }
+    else if(iEvt == XMLP._DTD) {                    // ignore DTD events
+    }
+    else if(iEvt == XMLP._ERROR) {
+        $error(&quot;Fatal Error: &quot; + p.getContent() + &quot;\nLine: &quot; + p.getLineNumber() + &quot;\nColumn: &quot; + p.getColumnNumber() + &quot;\n&quot;);
+        throw(new DOMException(DOMException.SYNTAX_ERR));
+      // alert(&quot;Fatal Error: &quot; + p.getContent() + &quot;\nLine: &quot; + p.getLineNumber() + &quot;\nColumn: &quot; + p.getColumnNumber() + &quot;\n&quot;);
+      // break;
+    }
+    else if(iEvt == XMLP._NONE) {                   // no more events
+      if (iNodeParent == doc) {                     // confirm that we have recursed back up to root
+        break;
+      }
+      else {
+        throw(new DOMException(DOMException.SYNTAX_ERR));  // one or more Tags were not closed properly
+      }
+    }
+  }
+
+  //normalize any entities in the DOM to a single textNode
+  for (var i = 0; i &lt; entitiesList.length; i++) {
+      var entity = entitiesList[i];
+      //its possible (if for example two entities were in the
+      //same domnode, that the normalize on the first entitiy
+      //will remove the parent for the second. Only do normalize
+      //if I can find a parent node
+      var parentNode = entity.parentNode;
+      if (parentNode) {
+          parentNode.normalize();
+		  
+		  //now do whitespace (if necessary)
+		  //it was not done for text nodes that have entities
+		  if(!impl.preserveWhiteSpace) {
+		  		var children = parentNode.childNodes;
+				for ( var j = 0; j &lt; children.length; j++) {
+					var child = children.item(j);
+					if (child.nodeType == DOMNode.TEXT_NODE) {
+						var childData = child.data;
+						childData.replace(/\s/g, ' ');
+						child.data = childData;
+					}
+				}
+		  }
+      }
+  }
+  
+  //do the preserve whitespace processing on the rest of the text nodes
+  //It's possible (due to the processing above) that the node will have been
+  //removed from the tree. Only do whitespace checking if parentNode is not null.
+  //This may duplicate the whitespace processing for some nodes that had entities in them
+  //but there's no way around that
+  if (!impl.preserveWhiteSpace) {
+	for (var i = 0; i &lt; textNodesList.length; i++) {
+		var node = textNodesList[i];
+		if (node.parentNode != null) {
+			var nodeData = node.data;
+			nodeData.replace(/\s/g, ' ');
+			node.data = nodeData;
+		}
+	}
+  
+  }
+};
+
+/**
+ * @method DOMImplementation._isNamespaceDeclaration - Return true, if attributeName is a namespace declaration
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  attributeName : string - the attribute name
+ * @return : boolean
+ */
+function __isNamespaceDeclaration__(attributeName) {
+  // test if attributeName is 'xmlns'
+  return (attributeName.indexOf('xmlns') &gt; -1);
+};
+
+/**
+ * @method DOMImplementation._isIdDeclaration - Return true, if attributeName is an id declaration
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  attributeName : string - the attribute name
+ * @return : boolean
+ */
+function __isIdDeclaration__(attributeName) {
+  // test if attributeName is 'id' (case insensitive)
+  return (attributeName.toLowerCase() == 'id');
+};
+
+/**
+ * @method DOMImplementation._isValidName - Return true,
+ *   if name contains no invalid characters
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  name : string - the candidate name
+ * @return : boolean
+ */
+function __isValidName__(name) {
+  // test if name contains only valid characters
+  return name.match(re_validName);
+};
+var re_validName = /^[a-zA-Z_:][a-zA-Z0-9\.\-_:]*$/;
+
+/**
+ * @method DOMImplementation._isValidString - Return true, if string does not contain any illegal chars
+ *  All of the characters 0 through 31 and character 127 are nonprinting control characters.
+ *  With the exception of characters 09, 10, and 13, (Ox09, Ox0A, and Ox0D)
+ *  Note: different from _isValidName in that ValidStrings may contain spaces
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  name : string - the candidate string
+ * @return : boolean
+ */
+function __isValidString__(name) {
+  // test that string does not contains invalid characters
+  return (name.search(re_invalidStringChars) &lt; 0);
+};
+var re_invalidStringChars = /\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0B|\x0C|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E|\x1F|\x7F/;
+
+/**
+ * @method DOMImplementation._parseNSName - parse the namespace name.
+ *  if there is no colon, the
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  qualifiedName : string - The qualified name
+ * @return : NSName - [
+         .prefix        : string - The prefix part of the qname
+         .namespaceName : string - The namespaceURI part of the qname
+    ]
+ */
+function __parseNSName__(qualifiedName) {
+  var resultNSName = new Object();
+
+  resultNSName.prefix          = qualifiedName;  // unless the qname has a namespaceName, the prefix is the entire String
+  resultNSName.namespaceName   = &quot;&quot;;
+
+  // split on ':'
+  var delimPos = qualifiedName.indexOf(':');
+  if (delimPos &gt; -1) {
+    // get prefix
+    resultNSName.prefix        = qualifiedName.substring(0, delimPos);
+    // get namespaceName
+    resultNSName.namespaceName = qualifiedName.substring(delimPos +1, qualifiedName.length);
+  }
+  return resultNSName;
+};
+
+/**
+ * @method DOMImplementation._parseQName - parse the qualified name
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  qualifiedName : string - The qualified name
+ * @return : QName
+ */
+function __parseQName__(qualifiedName) {
+  var resultQName = new Object();
+
+  resultQName.localName = qualifiedName;  // unless the qname has a prefix, the local name is the entire String
+  resultQName.prefix    = &quot;&quot;;
+
+  // split on ':'
+  var delimPos = qualifiedName.indexOf(':');
+
+  if (delimPos &gt; -1) {
+    // get prefix
+    resultQName.prefix    = qualifiedName.substring(0, delimPos);
+
+    // get localName
+    resultQName.localName = qualifiedName.substring(delimPos +1, qualifiedName.length);
+  }
+
+  return resultQName;
+};
+
+$log(&quot;Initializing document.implementation&quot;);
+var $implementation =  new DOMImplementation();
+$implementation.namespaceAware = false;
+$implementation.errorChecking = true;$log(&quot;Defining Document&quot;);
+/*
+* Document - DOM Level 2
+*  The Document object is not directly 
+*/
+$w.__defineGetter__('Document', function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+/**
+ * @class  DOMDocument - The Document interface represents the entire HTML or XML document.
+ *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
+ *
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  implementation : DOMImplementation - the creator Implementation
+ */
+var DOMDocument = function(implementation) {
+    //$log(&quot;\tcreating dom document&quot;);
+    this.DOMNode = DOMNode;
+    this.DOMNode(this);
+    
+    this.doctype = null;                  // The Document Type Declaration (see DocumentType) associated with this document
+    this.implementation = implementation; // The DOMImplementation object that handles this document.
+    this.documentElement = null;          // This is a convenience attribute that allows direct access to the child node that is the root element of the document
+    //this.all  = new Array();                       // The list of all Elements
+    
+    this.nodeName  = &quot;#document&quot;;
+    this.nodeType = DOMNode.DOCUMENT_NODE;
+    this._id = 0;
+    this._lastId = 0;
+    this._parseComplete = false;                   // initially false, set to true by parser
+    this._url = &quot;&quot;;
+    
+    this.ownerDocument = this;
+    
+    this._performingImportNodeOperation = false;
+    //$log(&quot;\tfinished creating dom document &quot; + this);
+};
+DOMDocument.prototype = new DOMNode;
+__extend__(DOMDocument.prototype, {
+	addEventListener        : window.addEventListener,
+	removeEventListener     : window.removeEventListener,
+    attachEvent             : window.addEventListener,/*IE only subject to deprecation*/
+    detachEvent             : window.detachEvent,/*IE only subject to  deprecation*/
+	dispatchEvent           : window.dispatchEvent,
+    get styleSheets(){ 
+        return [];/*TODO*/ 
+    },
+    get all(){
+        return this.getElementsByTagName(&quot;*&quot;);
+    },
+    loadXML : function(xmlStr) {
+        // create SAX Parser
+        var parser;
+        
+        try {
+            parser = new XMLP(String(xmlStr));
+        }catch (e) {
+            $error(&quot;Error Creating the SAX Parser. \n\n\t&quot;+e+&quot;\n\n\t Did you include xmlsax.js or tinyxmlsax.js\
+                     in your web page?\nThe SAX parser is needed to populate XML for &lt;SCRIPT&gt;'s \
+                     W3C DOM Parser with data.&quot;);
+        }
+        // create DOM Document
+        var doc = new HTMLDocument(this.implementation);
+        // populate Document with Parsed Nodes
+        try {
+            __parseLoop__(this.implementation, doc, parser);
+        } catch (e) {
+            $error(this.implementation.translateErrCode(e.code))
+        }
+
+        // set parseComplete flag, (Some validation Rules are relaxed if this is false)
+        doc._parseComplete = true;
+        if(this === $document){
+            $log(&quot;Setting internal window.document&quot;);
+            $document = doc;
+        }
+        return doc;
+    },
+    load: function(url){
+		$log(&quot;Loading url into DOM Document: &quot;+ url + &quot; - (Asynch? &quot;+$w.document.async+&quot;)&quot;);
+        var _this = this;
+        var xhr = new XMLHttpRequest();
+        xhr.open(&quot;GET&quot;, url, $w.document.async);
+        xhr.onreadystatechange = function(){
+            try{
+        	    _this.loadXML(xhr.responseText);
+            }catch(e){
+                $error(&quot;Error Parsing XML - &quot;,e);
+                _this.loadXML(
+                &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&quot;+
+                    &quot;&lt;h1&gt;Parse Error&lt;/h1&gt;&quot;+
+                    &quot;&lt;p&gt;&quot;+e.toString()+&quot;&lt;/p&gt;&quot;+  
+                &quot;&lt;/body&gt;&lt;/html&gt;&quot;);
+            }
+            $env.loadScripts();
+            _this._url = url;
+        	$log(&quot;Sucessfully loaded document.&quot;);
+        	var event = document.createEvent();
+        	event.initEvent(&quot;load&quot;);
+        	$w.dispatchEvent( event );
+        };
+        xhr.send();
+    },
+	createEvent             : function(eventType){ 
+        var event;
+        if(eventType === &quot;UIEvents&quot;){ event = new UIEvent();}
+        else if(eventType === &quot;MouseEvents&quot;){ event = new MouseEvent();}
+        else{ event = new Event(); } 
+        return event;
+    },
+    createExpression        : function(xpath, nsuriMap){ 
+        return null;/*TODO*/
+    },
+    createElement : function(tagName) {
+        //$log(&quot;DOMDocument.createElement( &quot;+tagName+&quot; )&quot;);
+          // throw Exception if the tagName string contains an illegal character
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
+            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+          }
+        
+          // create DOMElement specifying 'this' as ownerDocument
+          var node = new DOMElement(this);
+        
+          // assign values to properties (and aliases)
+          node.tagName  = tagName;
+          node.nodeName = tagName;
+        
+          // add Element to 'all' collection
+          //this.all[this.all.length] = node;
+          //$log(&quot;Document.all.length &quot; + this.all.length);
+        
+          return node;
+    },
+    createDocumentFragment : function() {
+          // create DOMDocumentFragment specifying 'this' as ownerDocument
+          var node = new DOMDocumentFragment(this);
+        
+          return node;
+    },
+    createTextNode: function(data) {
+          // create DOMText specifying 'this' as ownerDocument
+          var node = new DOMText(this);
+        
+          // assign values to properties (and aliases)
+          node.data      = data;
+          node.nodeValue = data;
+        
+          // set initial length
+          node.length    = data.length;
+        
+          return node;
+    },
+    createComment : function(data) {
+          // create DOMComment specifying 'this' as ownerDocument
+          var node = new DOMComment(this);
+        
+          // assign values to properties (and aliases)
+          node.data      = data;
+          node.nodeValue = data;
+        
+          // set initial length
+          node.length    = data.length;
+        
+          return node;
+    },
+    createCDATASection : function(data) {
+          // create DOMCDATASection specifying 'this' as ownerDocument
+          var node = new DOMCDATASection(this);
+        
+          // assign values to properties (and aliases)
+          node.data      = data;
+          node.nodeValue = data;
+        
+          // set initial length
+          node.length    = data.length;
+        
+          return node;
+    },
+    createProcessingInstruction : function(target, data) {
+          // throw Exception if the target string contains an illegal character
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(target))) {
+            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+          }
+        
+          // create DOMProcessingInstruction specifying 'this' as ownerDocument
+          var node = new DOMProcessingInstruction(this);
+        
+          // assign values to properties (and aliases)
+          node.target    = target;
+          node.nodeName  = target;
+          node.data      = data;
+          node.nodeValue = data;
+        
+          // set initial length
+          node.length    = data.length;
+        
+          return node;
+    },
+    createAttribute : function(name) {
+          // throw Exception if the name string contains an illegal character
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(name))) {
+            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+          }
+        
+          // create DOMAttr specifying 'this' as ownerDocument
+          var node = new DOMAttr(this);
+        
+          // assign values to properties (and aliases)
+          node.name     = name;
+          node.nodeName = name;
+        
+          return node;
+    },
+    createElementNS : function(namespaceURI, qualifiedName) {
+        //$log(&quot;DOMDocument.createElement( &quot;+namespaceURI+&quot;, &quot;+qualifiedName+&quot; )&quot;);
+          // test for exceptions
+          if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if the Namespace is invalid
+            if (!__isValidNamespace__(this, namespaceURI, qualifiedName)) {
+              throw(new DOMException(DOMException.NAMESPACE_ERR));
+            }
+        
+            // throw Exception if the qualifiedName string contains an illegal character
+            if (!__isValidName__(qualifiedName)) {
+              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+            }
+          }
+        
+          // create DOMElement specifying 'this' as ownerDocument
+          var node  = new DOMElement(this);
+          var qname = __parseQName__(qualifiedName);
+        
+          // assign values to properties (and aliases)
+          node.nodeName     = qualifiedName;
+          node.namespaceURI = namespaceURI;
+          node.prefix       = qname.prefix;
+          node.localName    = qname.localName;
+          node.tagName      = qualifiedName;
+        
+          // add Element to 'all' collection
+          //this.all[this.all.length] = node;
+        
+          return node;
+    },
+    createAttributeNS : function(namespaceURI, qualifiedName) {
+          // test for exceptions
+          if (this.ownerDocument.implementation.errorChecking) {
+            // throw Exception if the Namespace is invalid
+            if (!__isValidNamespace__(this, namespaceURI, qualifiedName, true)) {
+              throw(new DOMException(DOMException.NAMESPACE_ERR));
+            }
+        
+            // throw Exception if the qualifiedName string contains an illegal character
+            if (!__isValidName__(qualifiedName)) {
+              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+            }
+          }
+        
+          // create DOMAttr specifying 'this' as ownerDocument
+          var node  = new DOMAttr(this);
+          var qname = __parseQName__(qualifiedName);
+        
+          // assign values to properties (and aliases)
+          node.nodeName     = qualifiedName;
+          node.namespaceURI = namespaceURI;
+          node.prefix       = qname.prefix;
+          node.localName    = qname.localName;
+          node.name         = qualifiedName;
+          node.nodeValue    = &quot;&quot;;
+        
+          return node;
+    },
+    createNamespace : function(qualifiedName) {
+          // create DOMNamespace specifying 'this' as ownerDocument
+          var node  = new DOMNamespace(this);
+          var qname = __parseQName__(qualifiedName);
+        
+          // assign values to properties (and aliases)
+          node.nodeName     = qualifiedName;
+          node.prefix       = qname.prefix;
+          node.localName    = qname.localName;
+          node.name         = qualifiedName;
+          node.nodeValue    = &quot;&quot;;
+        
+          return node;
+    },
+    getElementById : function(elementId) {
+          var retNode = null,
+              node;
+          // loop through all Elements in the 'all' collection
+          var all = this.all;
+          for (var i=0; i &lt; all.length; i++) {
+            node = all[i];
+            // if id matches &amp; node is alive (ie, connected (in)directly to the documentElement)
+            if (node.id == elementId) {
+                if((node.ownerDocument.documentElement._id == this.documentElement._id)){
+                    retNode = node;
+                    //$log(&quot;Found node with id = &quot; + node.id);
+                    break;
+                }
+            }
+          }
+          
+          if(retNode == null){$log(&quot;Couldn't find id &quot; + elementId);}
+          return retNode;
+    },
+    normalizeDocument: function(){
+	    this.documentElement.normalize();
+    },
+    get xml(){
+        return this.documentElement.xml;
+    },
+	toString: function(){ 
+	    return &quot;Document&quot; +  (typeof this._url == &quot;string&quot; ? &quot;: &quot; + this._url : &quot;&quot;); 
+    },
+	get defaultView(){ //TODO: why isnt this just 'return $w;'?
+		return { getComputedStyle: function(elem){
+			return { getPropertyValue: function(prop){
+				prop = prop.replace(/\-(\w)/g,function(m,c){ return c.toUpperCase(); });
+				var val = elem.style[prop];
+				if ( prop == &quot;opacity&quot; &amp;&amp; val == &quot;&quot; ){ val = &quot;1&quot;; }return val;
+			}};
+		}};
+	},
+    _genId : function() {
+          this._lastId += 1;                             // increment lastId (to generate unique id)
+          return this._lastId;
+    }
+});
+
+
+var __isValidNamespace__ = function(doc, namespaceURI, qualifiedName, isAttribute) {
+
+      if (doc._performingImportNodeOperation == true) {
+        //we're doing an importNode operation (or a cloneNode) - in both cases, there
+        //is no need to perform any namespace checking since the nodes have to have been valid
+        //to have gotten into the DOM in the first place
+        return true;
+      }
+    
+      var valid = true;
+      // parse QName
+      var qName = __parseQName__(qualifiedName);
+    
+    
+      //only check for namespaces if we're finished parsing
+      if (this._parseComplete == true) {
+    
+        // if the qualifiedName is malformed
+        if (qName.localName.indexOf(&quot;:&quot;) &gt; -1 ){
+            valid = false;
+        }
+    
+        if ((valid) &amp;&amp; (!isAttribute)) {
+            // if the namespaceURI is not null
+            if (!namespaceURI) {
+            valid = false;
+            }
+        }
+    
+        // if the qualifiedName has a prefix
+        if ((valid) &amp;&amp; (qName.prefix == &quot;&quot;)) {
+            valid = false;
+        }
+    
+      }
+    
+      // if the qualifiedName has a prefix that is &quot;xml&quot; and the namespaceURI is
+      //  different from &quot;http://www.w3.org/XML/1998/namespace&quot; [Namespaces].
+      if ((valid) &amp;&amp; (qName.prefix == &quot;xml&quot;) &amp;&amp; (namespaceURI != &quot;http://www.w3.org/XML/1998/namespace&quot;)) {
+        valid = false;
+      }
+    
+      return valid;
+};
+$log(&quot;Defining HTMLDocument&quot;);
+/*
+* HTMLDocument - DOM Level 2
+*  The Document object is not directly 
+*/
+$w.__defineGetter__(&quot;HTMLDocument&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+/**
+ * @class  HTMLDocument - The Document interface represents the entire HTML or XML document.
+ *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
+ *
+ * @extends DOMDocument
+ */
+var HTMLDocument = function(implementation) {
+  this.DOMDocument = DOMDocument;
+  this.DOMDocument(implementation);
+
+  this.title = &quot;&quot;;
+  this._refferer = &quot;&quot;;
+  this._domain;
+  this._open = false;
+};
+HTMLDocument.prototype = new DOMDocument;
+__extend__(HTMLDocument.prototype, {
+    createElement: function(tagName){
+        //$log(&quot;HTMLDocument.createElement( &quot;+tagName+&quot; )&quot;);
+        // throw Exception if the tagName string contains an illegal character
+          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
+            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
+          }
+          tagName = tagName.toUpperCase();
+          //$log(&quot;HTMLDocument.createElement( &quot;+tagName+&quot; )&quot;);
+          // create DOMElement specifying 'this' as ownerDocument
+          //This is an html document so we need to use explicit interfaces per the 
+          if(     tagName.match(/^A$/))                 {node = new HTMLAnchorElement(this);}
+          else if(tagName.match(/AREA/))                {node = new HTMLAreaElement(this);}
+          else if(tagName.match(/BASE/))                {node = new HTMLBaseElement(this);}
+          else if(tagName.match(/BLOCKQUOTE|Q/))        {node = new HTMLQuoteElement(this);}
+          else if(tagName.match(/BODY/))                {node = new HTMLElement(this);}
+          else if(tagName.match(/BR/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/BUTTON/))              {node = new HTMLButtonElement(this);}
+          else if(tagName.match(/CAPTION/))             {node = new HTMLElement(this);}
+          else if(tagName.match(/COL|COLGROUP/))        {node = new HTMLTableColElement(this);}
+          else if(tagName.match(/DEL|INS/))             {node = new HTMLModElement(this);}
+          else if(tagName.match(/DIV/))                 {node = new HTMLElement(this);}
+          else if(tagName.match(/DL/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/FIELDSET/))            {node = new HTMLFieldSetElement(this);}
+          else if(tagName.match(/FORM/))                {node = new HTMLFormElement(this);}
+          else if(tagName.match(/^FRAME$/))             {node = new HTMLFrameElement(this);}
+          else if(tagName.match(/FRAMESET/))            {node = new HTMLFrameSetElement(this);}
+          else if(tagName.match(/H1|H2|H3|H4|H5|H6/))   {node = new HTMLElement(this);}
+          else if(tagName.match(/HEAD/))                {node = new HTMLHeadElement(this);}
+          else if(tagName.match(/HR/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/HTML/))                {node = new HTMLElement(this);}
+          else if(tagName.match(/IFRAME/))              {node = new HTMLIFrameElement(this);}
+          else if(tagName.match(/IMG/))                 {node = new HTMLImageElement(this);}
+          else if(tagName.match(/INPUT/))               {node = new HTMLInputElement(this);}
+          else if(tagName.match(/LABEL/))               {node = new HTMLLabelElement(this);}
+          else if(tagName.match(/LEGEND/))              {node = new HTMLLegendElement(this);}
+          else if(tagName.match(/^LI$/))                {node = new HTMLElement(this);}
+          else if(tagName.match(/LINK/))                {node = new HTMLLinkElement(this);}
+          else if(tagName.match(/MAP/))                 {node = new HTMLMapElement(this);}
+          else if(tagName.match(/META/))                {node = new HTMLMetaElement(this);}
+          else if(tagName.match(/OBJECT/))              {node = new HTMLObjectElement(this);}
+          else if(tagName.match(/OL/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/OPTGROUP/))            {node = new HTMLOptGroupElement(this);}
+          else if(tagName.match(/OPTION/))              {node = new HTMLOptionElement(this);;}
+          else if(tagName.match(/^P$/))                 {node = new HTMLElement(this);}
+          else if(tagName.match(/PARAM/))               {node = new HTMLParamElement(this);}
+          else if(tagName.match(/PRE/))                 {node = new HTMLElement(this);}
+          else if(tagName.match(/SCRIPT/))              {node = new HTMLScriptElement(this);}
+          else if(tagName.match(/SELECT/))              {node = new HTMLSelectElement(this);}
+          else if(tagName.match(/STYLE/))               {node = new HTMLStyleElement(this);}
+          else if(tagName.match(/TABLE/))               {node = new HTMLElement(this);}
+          else if(tagName.match(/TBODY|TFOOT|THEAD/))   {node = new HTMLElement(this);}
+          else if(tagName.match(/TD|TH/))               {node = new HTMLElement(this);}
+          else if(tagName.match(/TEXTAREA/))            {node = new HTMLElement(this);}
+          else if(tagName.match(/TITLE/))               {node = new HTMLElement(this);}
+          else if(tagName.match(/TR/))                  {node = new HTMLElement(this);}
+          else if(tagName.match(/UL/))                  {node = new HTMLElement(this);}
+          else{
+            node = new HTMLElement(this);
+          }
+        
+          // assign values to properties (and aliases)
+          node.tagName  = tagName;
+          node.nodeName = tagName;
+        
+          // add Element to 'all' collection
+          //this.all[this.all.length] = node;
+          //$log(&quot;Document.all.length &quot; + this.all.length);
+          return node;
+    },
+    get anchors(){
+        return new HTMLCollection(this.getElementsByTagName('a'), 'Anchor');
+        
+    },
+    get applets(){
+        return new HTMLCollection(this.getElementsByTagName('applet'), 'Applet');
+        
+    },
+    get body(){ 
+        var nodelist = this.getElementsByTagName('body');
+        return nodelist.item(0);
+        
+    },
+    set body(html){
+        return this.replaceNode(this.body,html);
+        
+    },
+    //set/get cookie see cookie.js
+    get domain(){
+        return this._domain||window.location.domain;
+        
+    },
+    set domain(){
+        /* TODO - requires a bit of thought to enforce domain restrictions */ 
+        return; 
+        
+    },
+    get forms(){
+      $log(&quot;document.forms&quot;);
+      return new HTMLCollection(this.getElementsByTagName('form'), 'Form');
+    },
+    get images(){
+        return new HTMLCollection(this.getElementsByTagName('img'), 'Image');
+        
+    },
+    get lastModified(){ 
+        /* TODO */
+        return this._lastModified; 
+    
+    },
+    get links(){
+        return new HTMLCollection(this.getElementsByTagName('a'), 'Link');
+        
+    },
+    get referrer(){
+        /* TODO */
+        return this._refferer; 
+        
+    },
+    get URL(){
+        /* TODO*/
+        return this._url; 
+        
+    },
+	close : function(){ 
+	    /* TODO */ 
+	    this._open = false;
+    },
+	getElementsByName : function(name){
+        //$debug(&quot;document.getElementsByName ( &quot;+name+&quot; )&quot;);
+        //returns a real Array + the DOMNodeList
+        var retNodes = __extend__([],new DOMNodeList(this, this.documentElement)),
+          node;
+        // loop through all Elements in the 'all' collection
+        var all = this.all;
+        for (var i=0; i &lt; all.length; i++) {
+            node = all[i];
+            if (node.nodeType == DOMNode.ELEMENT_NODE &amp;&amp; node.getAttribute('name') == name) {
+                //$log(&quot;Found node by name &quot; + name);
+                retNodes.push(node);
+            }
+        }
+        return retNodes;
+	},
+	open : function(){ 
+	    /* TODO */
+	    this._open = true;  
+    },
+	write: function(htmlstring){ 
+	    /* TODO */
+	    return; 
+	
+    },
+	writeln: function(htmlstring){ 
+	    this.write(htmlstring+'\n'); 
+    },
+	toString: function(){ 
+	    return &quot;Document&quot; +  (typeof this._url == &quot;string&quot; ? &quot;: &quot; + this._url : &quot;&quot;); 
+    },
+	get innerHTML(){ 
+	    return this.documentElement.outerHTML; 
+	    
+    },
+	get __html__(){
+	    return true;
+	    
+    }
+});
+
+//This is useful as html elements that modify the dom must also run through the new 
+//nodes and determine if they are javascript tags and load it.  This is really the fun 
+//parts! ;)
+function __execScripts__( node ) {
+	if ( node.nodeName == &quot;SCRIPT&quot; ) {
+		if ( !node.getAttribute(&quot;src&quot;) ) {
+			eval.call( window, node.textContent );
+		}
+	} else {
+		var scripts = node.getElementsByTagName(&quot;script&quot;);
+		for ( var i = 0; i &lt; scripts.length; i++ ) {
+			__execScripts__( node );
+		}
+	}
+};$log(&quot;Defining HTMLElement&quot;);
+/*
+* HTMLElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+var HTMLElement = function(ownerDocument) {
+    //$log(&quot;\tcreating html element&quot;);
+    this.DOMElement = DOMElement;
+    this.DOMElement(ownerDocument);
+    //$log(&quot;\nfinished creating html element&quot;);
+    
+    this.$css2props = null;
+};
+HTMLElement.prototype = new DOMElement;
+__extend__(HTMLElement.prototype, {
+		get className() { 
+		    return this.getAttribute(&quot;class&quot;)||&quot;&quot;; 
+		    
+	    },
+		set className(val) { 
+		    return this.setAttribute(&quot;class&quot;,trim(val)); 
+		    
+	    },
+		get dir() { 
+		    return this.getAttribute(&quot;dir&quot;)||&quot;ltr&quot;; 
+		    
+	    },
+		set dir(val) { 
+		    return this.setAttribute(&quot;dir&quot;,val); 
+		    
+	    },
+		get innerHTML(){  
+		    return this.childNodes.xml; 
+		    
+	    },
+		set innerHTML(html){
+		    //$debug(&quot;htmlElement.innerHTML(&quot;+html+&quot;)&quot;);
+		    //Should be replaced with HTMLPARSER usage
+			html = (html?html:&quot;&quot;).replace(/&lt;\/?([A-Z]+)/g, function(m){
+				return m.toLowerCase();
+			}).replace(/&amp;nbsp;/g, &quot; &quot;);
+			var doc = new DOMParser().
+			  parseFromString('&lt;div&gt;'+html+'&lt;/div&gt;');
+            var parent = this.ownerDocument.importNode(doc.documentElement, true);
+            
+			//$log(&quot;\n\nIMPORTED HTML:\n\n&quot;+nodes.xml);
+			while(this.firstChild != null){
+			    //$log('innerHTML - removing child '+ this.firstChild.xml);
+			    this.removeChild( this.firstChild );
+			}
+			while(parent.firstChild != null){
+			    //$log('innerHTML - appending child '+ parent.firstChild.xml);
+			    this.appendChild( parent.removeChild( parent.firstChild ) );
+		    }
+		    //Mark for garbage collection
+		    doc = null;
+		},
+		get lang() { 
+		    return this.getAttribute(&quot;lang&quot;)||&quot;&quot;; 
+		    
+	    },
+		set lang(val) { 
+		    return this.setAttribute(&quot;lang&quot;,val); 
+		    
+	    },
+		get offsetHeight(){
+		    return Number(this.style[&quot;height&quot;].replace(&quot;px&quot;,&quot;&quot;));
+		},
+		get offsetWidth(){
+		    return Number(this.style[&quot;width&quot;].replace(&quot;px&quot;,&quot;&quot;));
+		},
+		offsetLeft: 0,
+		offsetRight: 0,
+		get offsetParent(){
+		    /* TODO */
+		    return;
+	    },
+		set offsetParent(element){
+		    /* TODO */
+		    return;
+	    },
+		scrollHeight: 0,
+		scrollWidth: 0,
+		scrollLeft: 0, 
+		scrollRight: 0,
+		get style(){
+		    if(this.$css2props === null){
+		        $log(&quot;Initializing new css2props for html element : &quot; + this.getAttribute(&quot;style&quot;));
+		        this.$css2props = new CSS2Properties({
+    		        cssText:this.getAttribute(&quot;style&quot;)
+    	        });
+	        }
+	        return this.$css2props
+		},
+		get title() { 
+		    return this.getAttribute(&quot;title&quot;)||&quot;&quot;; 
+		    
+	    },
+		set title(val) { 
+		    return this.setAttribute(&quot;title&quot;,val); 
+		    
+	    },
+		//Not in the specs but I'll leave it here for now.
+		get outerHTML(){ 
+		    return this.xml; 
+		    
+	    },
+	    scrollIntoView: function(){
+	        /*TODO*/
+	        return;
+	    
+        },
+		onclick: function(event){
+		    try{
+		        eval(this.getAttribute('onclick'));
+		    }catch(e){
+		        $error(e);
+	        }
+	    },
+		ondblclick: function(event){
+		    try{
+		        eval(this.getAttribute('ondblclick'));
+		    }catch(e){
+		        $error(e)
+		    }
+	    },
+		onkeydown: function(event){
+		    try{
+		        eval(this.getAttribute('onkeydown'));
+		    }catch(e){
+		        $error(e);
+		    }
+	    },
+		onkeypress: function(event){
+		    try{
+		        eval(this.getAttribute('onkeypress'));
+		    }catch(e){
+		        $error(e);}},
+		onkeyup: function(event){
+		    try{
+		        eval(this.getAttribute('onkeyup'));
+		    }catch(e){
+		        $error(e);}},
+		onmousedown: function(event){
+		    try{
+		        eval(this.getAttribute('onmousedown'));
+		    }catch(e){
+		        $error(e);}},
+		onmousemove: function(event){
+		    try{
+		        eval(this.getAttribute('onmousemove'));
+		    }catch(e){
+		        $error(e);}},
+		onmouseout: function(event){
+		    try{
+		        eval(this.getAttribute('onmouseout'));
+		    }catch(e){
+		        $error(e);}},
+		onmouseover: function(event){
+		    try{
+		        eval(this.getAttribute('onmouseover'));
+		    }catch(e){
+		        $error(e);}},
+		onmouseup: function(event){
+		    try{
+		        eval(this.getAttribute('onmouseup'));
+		    }catch(e){
+		        $error(e);}}
+});
+
+var __registerEventAttrs__ = function(elm){
+    if(elm.hasAttribute('onclick')){ 
+        elm.addEventListener('click', elm.onclick ); 
+    }
+    if(elm.hasAttribute('ondblclick')){ 
+        elm.addEventListener('dblclick', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onkeydown')){ 
+        elm.addEventListener('keydown', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onkeypress')){ 
+        elm.addEventListener('keypress', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onkeyup')){ 
+        elm.addEventListener('keyup', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmousedown')){ 
+        elm.addEventListener('mousedown', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmousemove')){ 
+        elm.addEventListener('mousemove', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmouseout')){ 
+        elm.addEventListener('mouseout', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmouseover')){ 
+        elm.addEventListener('mouseover', elm.onclick ); 
+    }
+    if(elm.hasAttribute('onmouseup')){ 
+        elm.addEventListener('mouseup', elm.onclick ); 
+    }
+    return elm;
+};
+	
+var __click__ = function(element){
+	var event = new Event({
+	  target:element,
+	  currentTarget:element
+	});
+	event.initEvent(&quot;click&quot;);
+	element.dispatchEvent(event);
+};
+var __submit__ = function(element){
+	var event = new Event({
+	  target:element,
+	  currentTarget:element
+	});
+	event.initEvent(&quot;submit&quot;);
+	element.dispatchEvent(event);
+};
+var __focus__ = function(element){
+	var event = new Event({
+	  target:element,
+	  currentTarget:element
+	});
+	event.initEvent(&quot;focus&quot;);
+	element.dispatchEvent(event);
+};
+var __blur__ = function(element){
+	var event = new Event({
+	  target:element,
+	  currentTarget:element
+	});
+	event.initEvent(&quot;blur&quot;);
+	element.dispatchEvent(event);
+};
+$log(&quot;Defining HTMLCollection&quot;);
+/*
+* HTMLCollection - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLCollection&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/*var HTMLCollection = function(nodelist, type){
+  var $items = [], 
+      $item, i;
+  if(type === &quot;Anchor&quot; ){
+    for(i=0;i&lt;nodelist.length;i++){ 
+      //The name property is required to be add to the collection
+      if(nodelist.item(i).name){
+        item = new nodelist.item(i);
+        $items.push(item);
+        this[nodelist.item(i).name] = item;
+      }
+    }
+  }else if(type === &quot;Link&quot;){
+    for(i=0;i&lt;nodelist.length;i++){ 
+      //The name property is required to be add to the collection
+      if(nodelist.item(i).href){
+        item = new nodelist.item(i);
+        $items.push(item);
+        this[nodelist.item(i).name] = item;
+      }
+    }
+  }else if(type === &quot;Form&quot;){
+    for(i=0;i&lt;nodelist.length;i++){ 
+      //The name property is required to be add to the collection
+      if(nodelist.item(i).href){
+        item = new nodelist.item(i);
+        $items.push(item);
+        this[nodelist.item(i).name] = item;
+      }
+    }
+  }
+  setArray(this, $items);
+  return __extend__(this, {
+    item : function(i){return this[i];},
+    namedItem : function(name){return this[name];}
+  });
+};*/
+
+	$log(&quot;Defining HTMLAnchorElement&quot;);
+/* 
+* HTMLAnchorElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLAnchorElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLAnchorElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLAnchorElement.prototype = new HTMLElement;
+__extend__(HTMLAnchorElement.prototype, {
+	get accessKey() { 
+	    return this.getAttribute(&quot;accesskey&quot;) || &quot;&quot;; 
+	    
+    },
+	set accessKey(val) { 
+	    return this.setAttribute(&quot;accesskey&quot;,val); 
+	    
+    },
+	get charset() { 
+	    return this.getAttribute(&quot;charset&quot;) || &quot;&quot;; 
+	    
+    },
+	set charset(val) { 
+	    return this.setAttribute(&quot;charset&quot;,val); 
+	    
+    },
+	get coords() { 
+	    return this.getAttribute(&quot;coords&quot;) || &quot;&quot;; 
+	    
+    },
+	set coords(val) { 
+	    return this.setAttribute(&quot;coords&quot;,val); 
+	    
+    },
+	get href() { 
+	    return this.getAttribute(&quot;href&quot;) || &quot;&quot;; 
+	    
+    },
+	set href(val) { 
+	    return this.setAttribute(&quot;href&quot;,val); 
+	    
+    },
+	get hreflang() { 
+	    return this.getAttribute(&quot;hreflang&quot;) || &quot;&quot;; 
+	    
+    },
+	set hreflang(val) { 
+	    return this.setAttribute(&quot;hreflang&quot;,val); 
+	    
+    },
+	get name() { 
+	    return this.getAttribute(&quot;name&quot;) || &quot;&quot;; 
+	    
+    },
+	set name(val) { 
+	    return this.setAttribute(&quot;name&quot;,val); 
+	    
+    },
+	get rel() { 
+	    return this.getAttribute(&quot;rel&quot;) || &quot;&quot;; 
+	    
+    },
+	set rel(val) { 
+	    return this.setAttribute(&quot;rel&quot;,val); 
+	    
+    },
+	get rev() { 
+	    return this.getAttribute(&quot;rev&quot;) || &quot;&quot;; 
+	    
+    },
+	set rev(val) { 
+	    return this.setAttribute(&quot;rev&quot;,val); 
+	    
+    },
+	get shape() { 
+	    return this.getAttribute(&quot;shape&quot;) || &quot;&quot;; 
+	    
+    },
+	set shape(val) { 
+	    return this.setAttribute(&quot;shape&quot;,val); 
+	    
+    },
+	get tabIndex() { 
+	    return this.getAttribute(&quot;tabindex&quot;) || &quot;&quot;; 
+	    
+    },
+	set tabIndex(val) { 
+	    return this.setAttribute(&quot;tabindex&quot;,val); 
+	    
+    },
+	get target() { 
+	    return this.getAttribute(&quot;target&quot;) || &quot;&quot;; 
+	    
+    },
+	set target(val) { 
+	    return this.setAttribute(&quot;target&quot;,val); 
+	    
+    },
+	get type() { 
+	    return this.getAttribute(&quot;type&quot;) || &quot;&quot;; 
+	    
+    },
+	set type(val) { 
+	    return this.setAttribute(&quot;type&quot;,val); 
+	    
+    },
+	blur:function(){
+	    __blur__(this);
+	    
+    },
+	focus:function(){
+	    __focus__(this);
+	    
+    }
+});
+
+			$log(&quot;Defining Anchor&quot;);
+/* 
+* Anchor - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Anchor&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var Anchor = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLAnchorElement = HTMLAnchorElement;
+    this.HTMLAnchorElement(ownerDocument);
+};
+Anchor.prototype = new Anchor;
+
+(function(){
+    //static regular expressions
+	var hash 	 = new RegExp('(\\#.*)'),
+        hostname = new RegExp('\/\/([^\:\/]+)'),
+        pathname = new RegExp('(\/[^\\?\\#]*)'),
+        port 	 = new RegExp('\:(\\d+)\/'),
+        protocol = new RegExp('(^\\w*\:)'),
+        search 	 = new RegExp('(\\?[^\\#]*)');
+			
+    __extend__(Anchor.prototype, {
+		get hash(){
+			var m = hash.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set hash(_hash){
+			//setting the hash is the only property of the location object
+			//that doesn't cause the window to reload
+			_hash = _hash.indexOf('#')===0?_hash:&quot;#&quot;+_hash;	
+			this.href = this.protocol + this.host + this.pathname + this.search + _hash;
+		},
+		get host(){
+			return this.hostname + (this.port !== &quot;&quot;)?&quot;:&quot;+this.port:&quot;&quot;;
+		},
+		set host(_host){
+			this.href = this.protocol + _host + this.pathname + this.search + this.hash;
+		},
+		get hostname(){
+			var m = hostname.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set hostname(_hostname){
+			this.href = this.protocol + _hostname + ((this.port===&quot;&quot;)?&quot;&quot;:(&quot;:&quot;+this.port)) +
+			 	 this.pathname + this.search + this.hash;
+		},
+		get pathname(){
+			var m = this.href;
+			m = pathname.exec(m.substring(m.indexOf(this.hostname)));
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;/&quot;;
+		},
+		set pathname(_pathname){
+			this.href = this.protocol + this.host + _pathname + 
+				this.search + this.hash;
+		},
+		get port(){
+			var m = port.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set port(_port){
+			this.href = this.protocol + this.hostname + &quot;:&quot;+_port + this.pathname + 
+				this.search + this.hash;
+		},
+		get protocol(){
+			return protocol.exec(this.href)[0];
+		},
+		set protocol(_protocol){
+			this.href = _protocol + this.host + this.pathname + 
+				this.search + this.hash;
+		},
+		get search(){
+			var m = search.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set search(_search){
+			this.href = this.protocol + this.host + this.pathname + 
+				_search + this.hash;
+		}
+  });
+
+})();
+			$log(&quot;Defining HTMLAreaElement&quot;);
+/* 
+* HTMLAreaElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLAreaElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLAreaElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLAreaElement.prototype = new HTMLElement;
+__extend__(HTMLAreaElement.prototype, {
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    },
+    get alt(){
+        return this.getAttribute('alt');
+    },
+    set alt(value){
+        this.setAttribute('alt',value);
+    },
+    get coords(){
+        return this.getAttribute('coords');
+    },
+    set coords(value){
+        this.setAttribute('coords',value);
+    },
+    get href(){
+        return this.getAttribute('href');
+    },
+    set href(value){
+        this.setAttribute('href',value);
+    },
+    get noHref(){
+        return this.hasAttribute('href');
+    },
+    get shape(){
+        //TODO
+        return 0;
+    },
+    get tabIndex(){
+        return this.getAttribute('tabindex');
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',value);
+    },
+    get target(){
+        return this.getAttribute('target');
+    },
+    set target(value){
+        this.setAttribute('target',value);
+    }
+});
+
+			$log(&quot;Defining HTMLBaseElement&quot;);
+/* 
+* HTMLBaseElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLBaseElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLBaseElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLBaseElement.prototype = new HTMLElement;
+__extend__(HTMLBaseElement.prototype, {
+    get href(){
+        return this.getAttribute('href');
+    },
+    set href(value){
+        this.setAttribute('href',value);
+    },
+    get target(){
+        return this.getAttribute('target');
+    },
+    set target(value){
+        this.setAttribute('target',value);
+    }
+});
+
+			$log(&quot;Defining HTMLQuoteElement&quot;);
+/* 
+* HTMLQuoteElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLQuoteElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLQuoteElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLQuoteElement.prototype = new HTMLElement;
+__extend__(HTMLQuoteElement.prototype, {
+    get cite(){
+        return this.getAttribute('cite');
+    },
+    set cite(value){
+        this.setAttribute('cite',value);
+    }
+});
+
+			$log(&quot;Defining HTMLButtonElement&quot;);
+/* 
+* HTMLButtonElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLButtonElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLButtonElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLButtonElement.prototype = new HTMLElement;
+__extend__(HTMLButtonElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    },
+    get tabIndex(){
+        return Number(this.getAttribute('tabindex'));
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',Number(value));
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+    get value(){
+        return this.getAttribute('value');
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    }
+});
+
+			$log(&quot;Defining HTMLTableColElement&quot;);
+/* 
+* HTMLTableColElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLTableColElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLTableColElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLTableColElement.prototype = new HTMLElement;
+__extend__(HTMLTableColElement.prototype, {
+    get align(){
+        return this.getAttribute('align');
+    },
+    set align(value){
+        this.setAttribute('align', value);
+    },
+    get ch(){
+        return this.getAttribute('ch');
+    },
+    set ch(value){
+        this.setAttribute('ch', value);
+    },
+    get chOff(){
+        return this.getAttribute('ch');
+    },
+    set chOff(value){
+        this.setAttribute('ch', value);
+    },
+    get span(){
+        return this.getAttribute('span');
+    },
+    set span(value){
+        this.setAttribute('span', value);
+    },
+    get vAlign(){
+        return this.getAttribute('valign');
+    },
+    set vAlign(value){
+        this.setAttribute('valign', value);
+    },
+    get width(){
+        return this.getAttribute('width');
+    },
+    set width(value){
+        this.setAttribute('width', value);
+    }
+});
+
+			$log(&quot;Defining HTMLModElement&quot;);
+/* 
+* HTMLModElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLModElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLModElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLModElement.prototype = new HTMLElement;
+__extend__(HTMLModElement.prototype, {
+    get cite(){
+        return this.getAttribute('cite');
+    },
+    set cite(value){
+        this.setAttribute('cite', value);
+    },
+    get dateTime(){
+        return this.getAttribute('datetime');
+    },
+    set dateTime(value){
+        this.setAttribute('datetime', value);
+    }
+});
+
+			$log(&quot;Defining HTMLFieldSetElement&quot;);
+/* 
+* HTMLFieldSetElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLFieldSetElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLFieldSetElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLFieldSetElement.prototype = new HTMLElement;
+__extend__(HTMLFieldSetElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    }
+});
+
+			$log(&quot;Defining HTMLFormElement&quot;);
+/* 
+* HTMLAnchorElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Form&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+$w.__defineGetter__(&quot;HTMLFormElement&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var HTMLFormElement = function(ownerDocument){
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLFormElement.prototype = new HTMLElement;
+__extend__(HTMLFormElement.prototype,{
+    get acceptCharset(){ 
+        return this.getAttribute('accept-charset');
+        
+    },
+    set acceptCharset(acceptCharset){
+        this.setAttribute('accept-charset', acceptCharset);
+        
+    },
+    get action(){
+        return this.getAttribute('action');
+        
+    },
+    set action(action){
+        this.setAttribute('action', action);
+        
+    },
+    get elements() {
+        return this.getElementsByTagName(&quot;*&quot;);
+        
+    },
+    get enctype(){
+        return this.getAttribute('enctype');
+        
+    },
+    set enctype(enctype){
+        this.setAttribute('enctype', enctype);
+        
+    },
+    get length() {
+        return this.elements.length;
+        
+    },
+    get method(){
+        return this.getAttribute('method');
+        
+    },
+    set method(action){
+        this.setAttribute('method', method);
+        
+    },
+	get name() {
+	    return this.getAttribute(&quot;name&quot;) || &quot;&quot;; 
+	    
+    },
+	set name(val) { 
+	    return this.setAttribute(&quot;name&quot;,val); 
+	    
+    },
+	get target() { 
+	    return this.getAttribute(&quot;target&quot;) || &quot;&quot;; 
+	    
+    },
+	set target(val) { 
+	    return this.setAttribute(&quot;target&quot;,val); 
+	    
+    },
+	submit:function(){
+	    __submit__(this);
+	    
+    },
+	reset:function(){
+	    __reset__(this);
+	    
+    }
+});
+
+			$log(&quot;Defining HTMLFrameElement&quot;);
+/* 
+* HTMLFrameElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLFrameElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLFrameElement = function(ownerDocument) {
+    //$log(&quot;creating frame element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLFrameElement.prototype = new HTMLElement;
+__extend__(HTMLFrameElement.prototype, {
+    get frameBorder(){
+        return this.getAttribute('border')||&quot;&quot;;
+    },
+    set frameBorder(value){
+        this.setAttribute('border', value);
+    },
+    get longDesc(){
+        return this.getAttribute('longdesc')||&quot;&quot;;
+    },
+    set longDesc(value){
+        this.setAttribute('longdesc', value);
+    },
+    get marginHeight(){
+        return this.getAttribute('marginheight')||&quot;&quot;;
+    },
+    set marginHeight(value){
+        this.setAttribute('marginheight', value);
+    },
+    get marginWidth(){
+        return this.getAttribute('marginwidth')||&quot;&quot;;
+    },
+    set marginWidth(value){
+        this.setAttribute('marginwidth', value);
+    },
+    get name(){
+        return this.getAttribute('name')||&quot;&quot;;
+    },
+    set name(value){
+        this.setAttribute('name', value);
+    },
+    get noResize(){
+        return this.getAttribute('noresize')||&quot;&quot;;
+    },
+    set noResize(value){
+        this.setAttribute('noresize', value);
+    },
+    get scrolling(){
+        return this.getAttribute('scrolling')||&quot;&quot;;
+    },
+    set scrolling(value){
+        this.setAttribute('scrolling', value);
+    },
+    get src(){
+        return this.getAttribute('src')||&quot;&quot;;
+    },
+    set src(value){
+        this.setAttribute('src', value);
+    },
+    get contentDocument(){
+        $log(&quot;getting content document for (i)frame&quot;);
+        if(!this._content){
+            this._content = new HTMLDocument($implementation);
+            if(this.src.length &gt; 0){
+                $log(&quot;Loading frame content from &quot; + this.src);
+                try{
+                    this._content.load(this.src);
+                }catch(e){
+                    $error(&quot;failed to load &quot; + this.src);
+                }
+            }
+        }
+        return true;
+    }
+});
+
+			$log(&quot;Defining HTMLFrameSetElement&quot;);
+/* 
+* HTMLFrameSetElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLFrameSetElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLFrameSetElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLFrameSetElement.prototype = new HTMLElement;
+__extend__(HTMLFrameSetElement.prototype, {
+    get cols(){
+        return this.getAttribute('cols');
+    },
+    set cols(value){
+        this.setAttribute('cols', value);
+    },
+    get rows(){
+        return this.getAttribute('rows');
+    },
+    set rows(value){
+        this.setAttribute('rows', value);
+    }
+});
+
+			$log(&quot;Defining HTMLHeadElement&quot;);
+/* 
+* HTMLHeadElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLHeadElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLHeadElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLHeadElement.prototype = new HTMLElement;
+__extend__(HTMLHeadElement.prototype, {
+    get profile(){
+        return this.getAttribute('profile');
+    },
+    set profile(value){
+        this.setAttribute('profile', value);
+    },
+});
+
+			$log(&quot;Defining HTMLIFrameElement&quot;);
+/* 
+* HTMLIFrameElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLIFrameElement&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var HTMLIFrameElement = function(ownerDocument) {
+    //$log(&quot;creating iframe element&quot;);
+    this.HTMLFrameElement = HTMLFrameElement;
+    this.HTMLFrameElement(ownerDocument);
+};
+HTMLIFrameElement.prototype = new HTMLFrameElement;
+__extend__(HTMLIFrameElement.prototype, {
+	get height() { 
+	    return this.getAttribute(&quot;height&quot;) || &quot;&quot;; 
+    },
+	set height(val) { 
+	    return this.setAttribute(&quot;height&quot;,val); 
+    },
+	get width() { 
+	    return this.getAttribute(&quot;width&quot;) || &quot;&quot;; 
+    },
+	set width(val) { 
+	    return this.setAttribute(&quot;width&quot;,val); 
+    }
+});
+
+
+			$log(&quot;Defining HTMLImageElement&quot;);
+/* 
+* HTMLImageElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLImageElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLImageElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLImageElement.prototype = new HTMLElement;
+__extend__(HTMLImageElement.prototype, {
+    get alt(){
+        return this.getAttribute('alt');
+    },
+    set alt(value){
+        this.setAttribute('alt', value);
+    },
+    get height(){
+        return this.getAttribute('height');
+    },
+    set height(value){
+        this.setAttribute('height', value);
+    },
+    get isMap(){
+        return this.hasAttribute('map');
+    },
+    set useMap(value){
+        this.setAttribute('map', value);
+    },
+    get longDesc(){
+        return this.getAttribute('longdesc');
+    },
+    set longDesc(value){
+        this.setAttribute('longdesc', value);
+    },
+    get name(){
+        return this.getAttribute('name');
+    },
+    set name(value){
+        this.setAttribute('name', value);
+    },
+    get src(){
+        return this.getAttribute('src');
+    },
+    set src(value){
+        this.setAttribute('src', value);
+    },
+    get width(){
+        return this.getAttribute('width');
+    },
+    set width(value){
+        this.setAttribute('width', value);
+    }
+});
+
+			$log(&quot;Defining HTMLInputElement&quot;);
+/* 
+* HTMLInputElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLInputElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLInputElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLInputElement.prototype = new HTMLElement;
+__extend__(HTMLInputElement.prototype, {
+    get defaultValue(){
+        return this.getAttribute('defaultValue');
+    },
+    set defaultValue(value){
+        this.setAttribute('defaultValue', value);
+    },
+    get defaultChecked(){
+        return this.getAttribute('defaultChecked');
+    },
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    },
+    get access(){
+        return this.getAttribute('access');
+    },
+    set access(value){
+        this.setAttribute('access', value);
+    },
+    get alt(){
+        return this.getAttribute('alt');
+    },
+    set alt(value){
+        this.setAttribute('alt', value);
+    },
+    get checked(){
+        return (this.getAttribute('checked')==='checked');
+    },
+    set checked(){
+        this.setAttribute('checked', 'checked');
+    },
+    get disabled(){
+        return (this.getAttribute('disabled')==='disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled', 'disabled');
+    },
+    get maxLength(){
+        return Number(this.getAttribute('maxlength')||'0');
+    },
+    set maxLength(value){
+        this.setAttribute('maxlength', value);
+    },
+    get name(){
+        return this.getAttribute('name')||'';
+    },
+    set name(value){
+        this.setAttribute('name', value);
+    },
+    get readOnly(){
+        return (this.getAttribute('readonly')==='readonly');
+    },
+    set readOnly(value){
+        this.setAttribute('readonly', 'readonly');
+    },
+    get size(){
+        return this.getAttribute('size');
+    },
+    set size(value){
+        this.setAttribute('size', value);
+    },
+    get src(){
+        return this.getAttribute('src');
+    },
+    set src(value){
+        this.setAttribute('src', value);
+    },
+    get tabIndex(){
+        return Number(this.getAttribute('tabindex'));
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',Number(value));
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+    get useMap(){
+        return this.getAttribute('map');
+    },
+    get value(){
+        return this.getAttribute('value');
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    },
+	blur:function(){
+	    __blur__(this);
+	    
+    },
+	focus:function(){
+	    __focus__(this);
+	    
+    },
+	select:function(){
+	    __select__(this);
+	    
+    },
+	click:function(){
+	    __click__(this);
+	    
+    }
+});
+
+			$log(&quot;Defining HTMLLabelElement&quot;);
+/* 
+* HTMLLabelElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLLabelElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLLabelElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLLabelElement.prototype = new HTMLElement;
+__extend__(HTMLLabelElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    },
+    get htmlFor(){
+        return this.getAttribute('for');
+    },
+    set htmlFor(value){
+        this.setAttribute('for',value);
+    },
+});
+
+			$log(&quot;Defining HTMLLegendElement&quot;);
+/* 
+* HTMLLegendElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLLegendElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLLegendElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLLegendElement.prototype = new HTMLElement;
+__extend__(HTMLLegendElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get accessKey(){
+        return this.getAttribute('accesskey');
+    },
+    set accessKey(value){
+        this.setAttribute('accesskey',value);
+    }
+});
+
+			/**
+* Link - HTMLElement 
+*/
+$w.__defineGetter__(&quot;Link&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+$log(&quot;Defining HTMLLinkElement&quot;);
+/* 
+* HTMLLinkElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLLinkElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLLinkElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLLinkElement.prototype = new HTMLElement;
+__extend__(HTMLLinkElement.prototype, {
+    get disabled(){
+        return this.getAttribute('disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled',value);
+    },
+    get charset(){
+        return this.getAttribute('charset');
+    },
+    set charset(value){
+        this.setAttribute('charset',value);
+    },
+    get href(){
+        return this.getAttribute('href');
+    },
+    set href(value){
+        this.setAttribute('href',value);
+    },
+    get hreflang(){
+        return this.getAttribute('hreflang');
+    },
+    set hreflang(value){
+        this.setAttribute('hreflang',value);
+    },
+    get media(){
+        return this.getAttribute('media');
+    },
+    set media(value){
+        this.setAttribute('media',value);
+    },
+    get rel(){
+        return this.getAttribute('rel');
+    },
+    set rel(value){
+        this.setAttribute('rel',value);
+    },
+    get rev(){
+        return this.getAttribute('rev');
+    },
+    set rev(value){
+        this.setAttribute('rev',value);
+    },
+    get target(){
+        return this.getAttribute('target');
+    },
+    set target(value){
+        this.setAttribute('target',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    }
+});
+
+			
+
+			$log(&quot;Defining HTMLMapElement&quot;);
+/* 
+* HTMLMapElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLMapElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLMapElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLMapElement.prototype = new HTMLElement;
+__extend__(HTMLMapElement.prototype, {
+    get areas(){
+        return this.getElementsByTagName('area');
+    },
+    get name(){
+        return this.getAttribute('name');
+    },
+    set name(value){
+        this.setAttribute('name',value);
+    }
+});
+
+			$log(&quot;Defining HTMLMetaElement&quot;);
+/* 
+* HTMLMetaElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLMetaElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLMetaElement = function(ownerDocument) {
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLMetaElement.prototype = new HTMLElement;
+__extend__(HTMLMetaElement.prototype, {
+    get content(){
+        return this.getAttribute('content');
+    },
+    set content(value){
+        this.setAttribute('content',value);
+    },
+    get httpEquiv(){
+        return this.getAttribute('http-equiv');
+    },
+    set httpEquiv(value){
+        this.setAttribute('http-equiv',value);
+    },
+    get name(){
+        return this.getAttribute('name');
+    },
+    set name(value){
+        this.setAttribute('name',value);
+    },
+    get scheme(){
+        return this.getAttribute('scheme');
+    },
+    set scheme(value){
+        this.setAttribute('scheme',value);
+    }
+});
+
+			$log(&quot;Defining HTMLObjectElement&quot;);
+/* 
+* HTMLObjectElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLObjectElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLObjectElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLObjectElement.prototype = new HTMLElement;
+__extend__(HTMLObjectElement.prototype, {
+    get code(){
+        return this.getAttribute('code');
+    },
+    set code(value){
+        this.setAttribute('code',value);
+    },
+    get archive(){
+        return this.getAttribute('archive');
+    },
+    set archive(value){
+        this.setAttribute('archive',value);
+    },
+    get codeBase(){
+        return this.getAttribute('codebase');
+    },
+    set codeBase(value){
+        this.setAttribute('codebase',value);
+    },
+    get codeType(){
+        return this.getAttribute('codetype');
+    },
+    set codeType(value){
+        this.setAttribute('codetype',value);
+    },
+    get data(){
+        return this.getAttribute('data');
+    },
+    set data(value){
+        this.setAttribute('data',value);
+    },
+    get declare(){
+        return this.getAttribute('declare');
+    },
+    set declare(value){
+        this.setAttribute('declare',value);
+    },
+    get height(){
+        return this.getAttribute('height');
+    },
+    set height(value){
+        this.setAttribute('height',value);
+    },
+    get standby(){
+        return this.getAttribute('standby');
+    },
+    set standby(value){
+        this.setAttribute('standby',value);
+    },
+    get tabIndex(){
+        return this.getAttribute('tabindex');
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+    get useMap(){
+        return this.getAttribute('usemap');
+    },
+    set useMap(value){
+        this.setAttribute('usemap',value);
+    },
+    get width(){
+        return this.getAttribute('width');
+    },
+    set width(value){
+        this.setAttribute('width',value);
+    },
+    get contentDocument(){
+        return this.ownerDocument;
+    }
+});
+
+			$log(&quot;Defining HTMLOptGroupElement&quot;);
+/* 
+* HTMLOptGroupElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLOptGroupElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLOptGroupElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLOptGroupElement.prototype = new HTMLElement;
+__extend__(HTMLOptGroupElement.prototype, {
+    get disabled(){
+        return this.getAttribute('disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled',value);
+    },
+    get label(){
+        return this.getAttribute('label');
+    },
+    set label(value){
+        this.setAttribute('label',value);
+    },
+});
+
+			$log(&quot;Defining HTMLOptionElement&quot;);
+/* 
+* HTMLOptionElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLOptionElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLOptionElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLOptionElement.prototype = new HTMLElement;
+__extend__(HTMLOptionElement.prototype, {
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get defaultSelected(){
+        return this.getAttribute('defaultSelected');
+    },
+    set defaultSelected(value){
+        this.setAttribute('defaultSelected',value);
+    },
+    get text(){
+        return this.nodeValue;
+    },
+    get index(){
+        var options = this.parent.childNodes;
+        for(var i; i&lt;options.length;i++){
+            if(this == options[i])
+                return i;
+        }
+        return -1;
+    },
+    get disabled(){
+        return this.getAttribute('disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled',value);
+    },
+    get label(){
+        return this.getAttribute('label');
+    },
+    set label(value){
+        this.setAttribute('label',value);
+    },
+    get selected(){
+        return (this.getAttribute('selected')==='selected');
+    },
+    set selected(){
+        this.setAttribute('selected','selected');
+    },
+    get value(){
+        return this.getAttribute('value');
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    }
+});
+
+			$log(&quot;Defining HTMLParamElement&quot;);
+/* 
+* HTMLParamElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLParamElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLParamElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLParamElement.prototype = new HTMLElement;
+__extend__(HTMLParamElement.prototype, {
+    get name(){
+        return this.getAttribute('name');
+    },
+    set name(value){
+        this.setAttribute('name',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+    get value(){
+        return this.getAttribute('value');
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    },
+    get valueType(){
+        return this.getAttribute('valuetype');
+    },
+    set valueType(value){
+        this.setAttribute('valuetype',value);
+    },
+});
+
+			$log(&quot;Defining HTMLScriptElement&quot;);
+/* 
+* HTMLScriptElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLScriptElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLScriptElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLScriptElement.prototype = new HTMLElement;
+__extend__(HTMLScriptElement.prototype, {
+    get text(){
+        return this.nodeValue;
+    },
+    get htmlFor(){
+        return this.getAttribute('for');
+    },
+    set htmlFor(value){
+        this.setAttribute('for',value);
+    },
+    get event(){
+        return this.getAttribute('event');
+    },
+    set event(value){
+        this.setAttribute('event',value);
+    },
+    get charset(){
+        return this.getAttribute('charset');
+    },
+    set charset(value){
+        this.setAttribute('charset',value);
+    },
+    get defer(){
+        return this.getAttribute('defer');
+    },
+    set defer(value){
+        this.setAttribute('defer',value);
+    },
+    get src(){
+        return this.getAttribute('src');
+    },
+    set src(value){
+        this.setAttribute('src',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    }
+});
+
+			$log(&quot;Defining HTMLSelectElement&quot;);
+/* 
+* HTMLSelectElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLSelectElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLSelectElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLSelectElement.prototype = new HTMLElement;
+__extend__(HTMLSelectElement.prototype, {
+    get type(){
+        return this.getAttribute('type');
+    },
+    get selectedIndex(){
+        var options = this.options;
+        for(var i=0;i&lt;options.length;i++){
+            if(options[i].selected){
+                return i;
+            }
+        };
+        return -1;
+    },
+    set selectedIndex(value){
+        this.options[Number(value)].selected = 'selected';
+    },
+    get value(){
+        return this.getAttribute('value')||'';
+    },
+    set value(value){
+        this.setAttribute('value',value);
+    },
+    get length(){
+        return this.options.length;
+    },
+    get form(){
+        var parent = this.parent;
+        while(parent.nodeName.toLowerCase() != 'form'){
+            parent = parent.parent;
+        }
+        return parent;
+    },
+    get options(){
+        return this.getElementsByTagName('option');
+    },
+    get disabled(){
+        return (this.getAttribute('disabled')==='disabled');
+    },
+    set disabled(){
+        this.setAttribute('disabled','disabled');
+    },
+    get multiple(){
+        return this.getAttribute('multiple');
+    },
+    set multiple(value){
+        this.setAttribute('multiple',value);
+    },
+    get name(){
+        return this.getAttribute('name')||'';
+    },
+    set name(value){
+        this.setAttribute('name',value);
+    },
+    get size(){
+        return Number(this.getAttribute('size'));
+    },
+    set size(value){
+        this.setAttribute('size',value);
+    },
+    get tabIndex(){
+        return Number(this.getAttribute('tabindex'));
+    },
+    set tabIndex(value){
+        this.setAttribute('tabindex',value);
+    },
+    add : function(){
+        __add__(this);
+    },
+    remove : function(){
+        __remove__(this);
+    },
+    blur: function(){
+        __blur__(this);
+    },
+    focus: function(){
+        __focus__(this);
+    }
+});
+
+			$log(&quot;Defining HTMLStyleElement&quot;);
+/* 
+* HTMLStyleElement - DOM Level 2
+*/
+$w.__defineGetter__(&quot;HTMLStyleElement&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+var HTMLStyleElement = function(ownerDocument) {
+    //$log(&quot;creating anchor element&quot;);
+    this.HTMLElement = HTMLElement;
+    this.HTMLElement(ownerDocument);
+};
+HTMLStyleElement.prototype = new HTMLElement;
+__extend__(HTMLStyleElement.prototype, {
+    get disabled(){
+        return this.getAttribute('disabled');
+    },
+    set disabled(value){
+        this.setAttribute('disabled',value);
+    },
+    get media(){
+        return this.getAttribute('media');
+    },
+    set media(value){
+        this.setAttribute('media',value);
+    },
+    get type(){
+        return this.getAttribute('type');
+    },
+    set type(value){
+        this.setAttribute('type',value);
+    },
+});
+
+			$log(&quot;Defining Event&quot;);
+/*
+* event.js
+*/
+$w.__defineGetter__(&quot;Event&quot;, function(){
+  __extend__(this,{
+    CAPTURING_PHASE : 1,
+    AT_TARGET       : 2,
+    BUBBLING_PHASE  : 3
+  });
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var Event = function(options){
+  if(options === undefined){options={target:window,currentTarget:window};}
+  __extend__(this,{
+    CAPTURING_PHASE : 1,
+    AT_TARGET       : 2,
+    BUBBLING_PHASE  : 3
+  });
+  $log(&quot;Creating new Event&quot;);
+  var $bubbles = options.bubbles?options.bubbles:true,
+      $cancelable = options.cancelable?options.cancelable:true,
+      $currentTarget = options.currentTarget?options.currentTarget:null,
+      $eventPhase = options.eventPhase?options.eventPhase:Event.CAPTURING_PHASE,
+      $target = options.eventPhase?options.eventPhase:document,
+      $timestamp = options.timestamp?options.timestamp:new Date().getTime().toString(),
+      $type = options.type?options.type:&quot;&quot;;
+  return __extend__(this,{
+    get bubbles(){return $bubbles;},
+    get cancelable(){return $cancelable;},
+    get currentTarget(){return $currentTarget;},
+    get eventPhase(){return $eventPhase;},
+    get target(){return $target;},
+    get timestamp(){return $timestamp;},
+    get type(){return $type;},
+    initEvent: function(type,bubbles,cancelable){
+      $type=type?type:$type;
+      $bubbles=bubbles?bubbles:$bubbles;
+      $cancelable=cancelable?cancelable:$cancelable;
+    },
+    preventDefault: function(){return;/* TODO */},
+    stopPropagation: function(){return;/* TODO */}
+  });
+};
+
+$log(&quot;Defining MouseEvent&quot;);
+/*
+*	mouseevent.js
+*/
+$log(&quot;Defining MouseEvent&quot;);
+/*
+*	uievent.js
+*/
+
+var $onblur,
+    $onfocus,
+    $onresize;/*
+* CSS2Properties - DOM Level 2 CSS
+*/
+$w.__defineGetter__(&quot;CSS2Properties&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+var CSS2Properties = function(options){
+    __extend__(this, __supportedStyles__);
+    __cssTextToStyles__(this, options.cssText?options.cssText:&quot;&quot;);
+};
+//__extend__(CSS2Properties.prototype, __supportedStyles__);
+__extend__(CSS2Properties.prototype, {
+    get cssText(){
+        return Array.prototype.apply.join(this,[';\n']);
+    },
+    set cssText(cssText){ 
+        __cssTextToStyles__(this, cssText); 
+    },
+    getPropertyCSSValue : function(){
+        
+    },
+    getPropertyPriority : function(){
+        
+    },
+    getPropertyValue : function(name){
+		var camelCase = name.replace(/\-(\w)/g, function(all, letter){
+			return letter.toUpperCase();
+		});
+        var i, value = this[camelCase];
+        if(value === undefined){
+            for(i=0;i&lt;this.length;i++){
+                if(this[i]===name){
+                    return this[i];
+                }
+            }
+        }
+        return value;
+    },
+    item : function(index){
+        return this[index];
+    },
+    removeProperty: function(){
+        
+    },
+    setProperty: function(){
+        
+    },
+    toString:function(){
+        if (this.length &gt;0){
+            return &quot;{\n\t&quot;+Array.prototype.join.apply(this,[';\n\t'])+&quot;}\n&quot;;
+        }else{
+            return '';
+        }
+    }
+});
+
+var __cssTextToStyles__ = function(css2props, cssText){
+    var styleArray=[];
+    var style, name, value, camelCaseName, w3cName, styles = cssText.split(';');
+    for ( var i = 0; i &lt; styles.length; i++ ) {
+        //$log(&quot;Adding style property &quot; + styles[i]);
+    	style = styles[i].split(':');
+    	if ( style.length == 2 ){
+    	    //keep a reference to the original name of the style which was set
+    	    //this is the w3c style setting method.
+    	    styleArray[styleArray.length] = w3cName = styles[i];
+            //camel case for dash case
+    	    value = trim(style[1]);
+            camelCaseName = trim(style[0].replace(/\-(\w)/g, function(all, letter){
+				return letter.toUpperCase();
+			}));
+            //$log('CSS Style Name:  ' + camelCaseName);
+            if(css2props[camelCaseName]!==undefined){
+                //set the value internally with camelcase name 
+                //$log('Setting css ' + camelCaseName + ' to ' + value);
+                css2props[camelCaseName] = value;
+            };
+    	}
+    }
+    __setArray__(css2props, styleArray);
+};
+//Obviously these arent all supported but by commenting out various sections
+//this provides a single location to configure what is exposed as supported.
+//These will likely need to be functional getters/setters in the future to deal with
+//the variation on input formulations
+var __supportedStyles__ = {
+    azimuth: &quot;&quot;,
+    background:	&quot;&quot;,
+    backgroundAttachment:	&quot;&quot;,
+    backgroundColor:	&quot;&quot;,
+    backgroundImage:	&quot;&quot;,
+    backgroundPosition:	&quot;&quot;,
+    backgroundRepeat:	&quot;&quot;,
+    border:	&quot;&quot;,
+    borderBottom:	&quot;&quot;,
+    borderBottomColor:	&quot;&quot;,
+    borderBottomStyle:	&quot;&quot;,
+    borderBottomWidth:	&quot;&quot;,
+    borderCollapse:	&quot;&quot;,
+    borderColor:	&quot;&quot;,
+    borderLeft:	&quot;&quot;,
+    borderLeftColor:	&quot;&quot;,
+    borderLeftStyle:	&quot;&quot;,
+    borderLeftWidth:	&quot;&quot;,
+    borderRight:	&quot;&quot;,
+    borderRightColor:	&quot;&quot;,
+    borderRightStyle:	&quot;&quot;,
+    borderRightWidth:	&quot;&quot;,
+    borderSpacing:	&quot;&quot;,
+    borderStyle:	&quot;&quot;,
+    borderTop:	&quot;&quot;,
+    borderTopColor:	&quot;&quot;,
+    borderTopStyle:	&quot;&quot;,
+    borderTopWidth:	&quot;&quot;,
+    borderWidth:	&quot;&quot;,
+    bottom:	&quot;&quot;,
+    captionSide:	&quot;&quot;,
+    clear:	&quot;&quot;,
+    clip:	&quot;&quot;,
+    color:	&quot;&quot;,
+    content:	&quot;&quot;,
+    counterIncrement:	&quot;&quot;,
+    counterReset:	&quot;&quot;,
+    cssFloat:	&quot;&quot;,
+    cue:	&quot;&quot;,
+    cueAfter:	&quot;&quot;,
+    cueBefore:	&quot;&quot;,
+    cursor:	&quot;&quot;,
+    direction:	&quot;&quot;,
+    display:	&quot;&quot;,
+    elevation:	&quot;&quot;,
+    emptyCells:	&quot;&quot;,
+    font:	&quot;&quot;,
+    fontFamily:	&quot;&quot;,
+    fontSize:	&quot;&quot;,
+    fontSizeAdjust:	&quot;&quot;,
+    fontStretch:	&quot;&quot;,
+    fontStyle:	&quot;&quot;,
+    fontVariant:	&quot;&quot;,
+    fontWeight:	&quot;&quot;,
+    height:	&quot;&quot;,
+    left:	&quot;&quot;,
+    letterSpacing:	&quot;&quot;,
+    lineHeight:	&quot;&quot;,
+    listStyle:	&quot;&quot;,
+    listStyleImage:	&quot;&quot;,
+    listStylePosition:	&quot;&quot;,
+    listStyleType:	&quot;&quot;,
+    margin:	&quot;&quot;,
+    marginBottom:	&quot;&quot;,
+    marginLeft:	&quot;&quot;,
+    marginRight:	&quot;&quot;,
+    marginTop:	&quot;&quot;,
+    markerOffset:	&quot;&quot;,
+    marks:	&quot;&quot;,
+    maxHeight:	&quot;&quot;,
+    maxWidth:	&quot;&quot;,
+    minHeight:	&quot;&quot;,
+    minWidth:	&quot;&quot;,
+    opacity:	1,
+    orphans:	&quot;&quot;,
+    outline:	&quot;&quot;,
+    outlineColor:	&quot;&quot;,
+    outlineOffset:	&quot;&quot;,
+    outlineStyle:	&quot;&quot;,
+    outlineWidth:	&quot;&quot;,
+    overflow:	&quot;&quot;,
+    overflowX:	&quot;&quot;,
+    overflowY:	&quot;&quot;,
+    padding:	&quot;&quot;,
+    paddingBottom:	&quot;&quot;,
+    paddingLeft:	&quot;&quot;,
+    paddingRight:	&quot;&quot;,
+    paddingTop:	&quot;&quot;,
+    page:	&quot;&quot;,
+    pageBreakAfter:	&quot;&quot;,
+    pageBreakBefore:	&quot;&quot;,
+    pageBreakInside:	&quot;&quot;,
+    pause:	&quot;&quot;,
+    pauseAfter:	&quot;&quot;,
+    pauseBefore:	&quot;&quot;,
+    pitch:	&quot;&quot;,
+    pitchRange:	&quot;&quot;,
+    position:	&quot;&quot;,
+    quotes:	&quot;&quot;,
+    richness:	&quot;&quot;,
+    right:	&quot;&quot;,
+    size:	&quot;&quot;,
+    speak:	&quot;&quot;,
+    speakHeader:	&quot;&quot;,
+    speakNumeral:	&quot;&quot;,
+    speakPunctuation:	&quot;&quot;,
+    speechRate:	&quot;&quot;,
+    stress:	&quot;&quot;,
+    tableLayout:	&quot;&quot;,
+    textAlign:	&quot;&quot;,
+    textDecoration:	&quot;&quot;,
+    textIndent:	&quot;&quot;,
+    textShadow:	&quot;&quot;,
+    textTransform:	&quot;&quot;,
+    top:	&quot;&quot;,
+    unicodeBidi:	&quot;&quot;,
+    verticalAlign:	&quot;&quot;,
+    visibility:	&quot;&quot;,
+    voiceFamily:	&quot;&quot;,
+    volume:	&quot;&quot;,
+    whiteSpace:	&quot;&quot;,
+    widows:	&quot;&quot;,
+    width:	&quot;&quot;,
+    wordSpacing:	&quot;&quot;,
+    zIndex:	&quot;&quot;
+};/* 
+* CSSRule - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CSSRule&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var CSSRule = function(options){
+  var $style, 
+      $selectorText = options.selectorText?options.selectorText:&quot;&quot;;
+      $style = new CSS2Properties({cssText:options.cssText?options.cssText:null});
+    return __extend__(this, {
+      get style(){return $style;},
+      get selectorText(){return $selectorText;},
+      set selectorText(selectorText){$selectorText = selectorText;}
+    });
+};
+/* 
+* CSSStyleSheet - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CSSStyleSheet&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var CSSStyleSheet = function(options){
+    var $cssRules, 
+        $disabled = options.disabled?options.disabled:false,
+        $href = options.href?options.href:null,
+        $parentStyleSheet = options.parentStyleSheet?options.parentStyleSheet:null,
+        $title = options.title?options.title:&quot;&quot;,
+        $type = &quot;text/css&quot;;
+        
+    function parseStyleSheet(text){
+      //this is pretty ugly, but text is the entire text of a stylesheet
+      var cssRules = [];
+    	if (!text) text = &quot;&quot;;
+    	text = trim(text.replace(/\/\*(\r|\n|.)*\*\//g,&quot;&quot;));
+    	// TODO: @import ?
+    	var blocks = text.split(&quot;}&quot;);
+    	blocks.pop();
+    	var i, len = blocks.length;
+    	var definition_block, properties, selectors;
+    	for (i=0; i&lt;len; i++){
+    		definition_block = blocks[i].split(&quot;{&quot;);
+    		if(definition_block.length === 2){
+      		selectors = definition_block[0].split(&quot;,&quot;);
+      		for(var j=0;j&lt;selectors.length;j++){
+      		  cssRules.push(new CSSRule({
+      		    selectorText:selectors[j],
+      		    cssText:definition_block[1]
+      		  }));
+      		}
+      		__setArray__($cssRules, cssRules);
+    		}
+    	}
+    };
+    parseStyleSheet(options.text);
+    return __extend__(this, {
+      get cssRules(){return $cssRules;},
+      get rule(){return $cssRules;},//IE - may be deprecated
+      get href(){return $href;},
+      get parentStyleSheet(){return $parentStyleSheet;},
+      get title(){return $title;},
+      get type(){return $type;},
+      addRule: function(selector, style, index){/*TODO*/},
+      deleteRule: function(index){/*TODO*/},
+      insertRule: function(rule, index){/*TODO*/},
+      removeRule: function(index){this.deleteRule(index);}//IE - may be deprecated
+    });
+};
+/*
+*	location.js
+*   - requires env
+*/
+$log(&quot;Initializing Window Location.&quot;);
+//the current location
+var $location = $env.location('./');
+
+$w.__defineSetter__(&quot;location&quot;, function(url){
+  //$w.onunload();
+	$w.document.load(url);
+	$location = url;
+	setHistory($location);
+});
+
+$w.__defineGetter__(&quot;location&quot;, function(url){
+	var hash 	 = new RegExp('(\\#.*)'),
+		hostname = new RegExp('\/\/([^\:\/]+)'),
+		pathname = new RegExp('(\/[^\\?\\#]*)'),
+		port 	 = new RegExp('\:(\\d+)\/'),
+		protocol = new RegExp('(^\\w*\:)'),
+		search 	 = new RegExp('(\\?[^\\#]*)');
+	return {
+		get hash(){
+			var m = hash.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set hash(_hash){
+			//setting the hash is the only property of the location object
+			//that doesn't cause the window to reload
+			_hash = _hash.indexOf('#')===0?_hash:&quot;#&quot;+_hash;	
+			$location = this.protocol + this.host + this.pathname + 
+				this.search + _hash;
+			setHistory(_hash, &quot;hash&quot;);
+		},
+		get host(){
+			return this.hostname + (this.port !== &quot;&quot;)?&quot;:&quot;+this.port:&quot;&quot;;
+		},
+		set host(_host){
+			$w.location = this.protocol + _host + this.pathname + 
+				this.search + this.hash;
+		},
+		get hostname(){
+			var m = hostname.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set hostname(_hostname){
+			$w.location = this.protocol + _hostname + ((this.port===&quot;&quot;)?&quot;&quot;:(&quot;:&quot;+this.port)) +
+			 	 this.pathname + this.search + this.hash;
+		},
+		get href(){
+			//This is the only env specific function
+			return $location;
+		},
+		set href(url){
+			$w.location = url;	
+		},
+		get pathname(){
+			var m = this.href;
+			m = pathname.exec(m.substring(m.indexOf(this.hostname)));
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;/&quot;;
+		},
+		set pathname(_pathname){
+			$w.location = this.protocol + this.host + _pathname + 
+				this.search + this.hash;
+		},
+		get port(){
+			var m = port.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set port(_port){
+			$w.location = this.protocol + this.hostname + &quot;:&quot;+_port + this.pathname + 
+				this.search + this.hash;
+		},
+		get protocol(){
+			return protocol.exec(this.href)[0];
+		},
+		set protocol(_protocol){
+			$w.location = _protocol + this.host + this.pathname + 
+				this.search + this.hash;
+		},
+		get search(){
+			var m = search.exec(this.href);
+			return m&amp;&amp;m.length&gt;1?m[1]:&quot;&quot;;
+		},
+		set search(_search){
+			$w.location = this.protocol + this.host + this.pathname + 
+				_search + this.hash;
+		},
+		toString: function(){
+			return this.href;
+		},
+		reload: function(force){
+			//TODO
+		},
+		replace: function(url){
+			//TODO
+		}
+	};
+});
+
+/*
+*	history.js
+*/
+
+  $log(&quot;Initializing Window History.&quot;);
+	$currentHistoryIndex = 0;
+	$history = [];
+	
+	// Browser History
+	$w.__defineGetter__(&quot;history&quot;, function(){	
+		return {
+			get length(){ return $history.length; },
+			back : function(count){
+				if(count){
+					go(-count);
+				}else{go(-1);}
+			},
+			forward : function(count){
+				if(count){
+					go(count);
+				}else{go(1);}
+			},
+			go : function(target){
+				if(typeof target == &quot;number&quot;){
+					target = $currentHistoryIndex+target;
+					if(target &gt; -1 &amp;&amp; target &lt; $history.length){
+						if($history[target].location == &quot;hash&quot;){
+							$w.location.hash = $history[target].value;
+						}else{
+							$w.location = $history[target].value;
+						}
+						$currentHistoryIndex = target;
+						//remove the last item added to the history
+						//since we are moving inside the history
+						$history.pop();
+					}
+				}else{
+					//TODO: walk throu the history and find the 'best match'
+				}
+			}
+		};
+	});
+
+	//Here locationPart is the particutlar method/attribute 
+	// of the location object that was modified.  This allows us
+	// to modify the correct portion of the location object
+	// when we navigate the history
+	var setHistory = function( value, locationPart){
+	  $log(&quot;adding value to history: &quot; +value);
+		$currentHistoryIndex++;
+		$history.push({
+			location: locationPart||&quot;href&quot;,
+			value: value
+		});
+	};
+	/*
+*	navigator.js
+*   - requires env
+*/
+$log(&quot;Initializing Window Navigator.&quot;);
+
+var $appCodeName  = &quot;EnvJS&quot;;//eg &quot;Mozilla&quot;
+var $appName      = &quot;Resig/20070309 BirdDog/0.0.0.1&quot;;//eg &quot;Gecko/20070309 Firefox/2.0.0.3&quot;
+
+// Browser Navigator
+$w.__defineGetter__(&quot;navigator&quot;, function(){	
+	return {
+		get appCodeName(){
+			return $appCodeName;
+		},
+		get appName(){
+			return $appName;
+		},
+		get appVersion(){
+			return $version +&quot; (&quot;+ 
+			    $w.navigator.platform +&quot;; &quot;+
+			    &quot;U; &quot;+//?
+			    $env.os_name+&quot; &quot;+$env.os_arch+&quot; &quot;+$env.os_version+&quot;; &quot;+
+			    $env.lang+&quot;; &quot;+
+			    &quot;rv:&quot;+$revision+
+			  &quot;)&quot;;
+		},
+		get cookieEnabled(){
+			return true;
+		},
+		get mimeTypes(){
+			return [];
+		},
+		get platform(){
+			return $env.platform;
+		},
+		get plugins(){
+			return [];
+		},
+		get userAgent(){
+			return $w.navigator.appCodeName + &quot;/&quot; + $w.navigator.appVersion + &quot; &quot; + $w.navigator.appName;
+		},
+		javaEnabled : function(){
+			return $env.javaEnabled;	
+		}
+	};
+});
+
+/*
+*	timer.js
+*/
+	
+
+$log(&quot;Initializing Window Timer.&quot;);
+
+//private
+var $timers = [];
+
+$w.setTimeout = function(fn, time){
+	var num;
+	return num = window.setInterval(function(){
+		fn();
+		window.clearInterval(num);
+	}, time);
+};
+
+window.setInterval = function(fn, time){
+	var num = $timers.length;
+	if(time===0){
+	    fn();
+	}else{
+    	$timers[num] = $env.timer(fn, time);
+    	$timers[num].start();
+	}
+	return num;
+};
+
+window.clearInterval = window.clearTimeout = function(num){
+	if ( $timers[num] ) {
+		$timers[num].stop();
+		delete $timers[num];
+	}
+};	
+	/*
+* event.js
+*/
+// Window Events
+$log(&quot;Initializing Window Event.&quot;);
+var $events = [{}],
+    $onerror,
+    $onload,
+    $onunload;
+
+$w.addEventListener = function(type, fn){
+  $log(&quot;adding event listener &quot; + type);
+	if ( !this.uuid || this == window ) {
+		this.uuid = $events.length;
+		$events[this.uuid] = {};
+	}
+	if ( !$events[this.uuid][type] ){
+		$events[this.uuid][type] = [];
+	}
+	if ( $events[this.uuid][type].indexOf( fn ) &lt; 0 ){
+		$events[this.uuid][type].push( fn );
+	}
+};
+
+$w.removeEventListener = function(type, fn){
+  if ( !this.uuid || this == window ) {
+    this.uuid = $events.length;
+    $events[this.uuid] = {};
+  }
+  if ( !$events[this.uuid][type] ){
+		$events[this.uuid][type] = [];
+	}	
+  $events[this.uuid][type] =
+    $events[this.uuid][type].filter(function(f){
+			return f != fn;
+		});
+};
+$w.dispatchEvent = function(event){
+  if(!event.target)
+    event.target = this;
+  if ( event.type ) {
+    if ( this.uuid &amp;&amp; events[this.uuid][event.type] ) {
+      var self = this;
+      events[this.uuid][event.type].forEach(function(fn){
+        fn.call( self, event );
+    });
+  }
+    
+  if ( this[&quot;on&quot; + event.type] )
+    this[&quot;on&quot; + event.type].call( self, event );
+  }
+  if(this.parentNode){
+    this.parentNode.dispatchEvent.call(this.parentNode,event);
+  }
+};
+$w.dispatchEvent = function(event){
+    $log(&quot;dispatching event &quot; + event.type);
+    //the window scope defines the $event object, for IE(^^^) compatibility;
+    $event = event;
+    if(!event.target)
+        event.target = this;
+    if ( event.type ) {
+        if ( this.uuid &amp;&amp; events[this.uuid][event.type] ) {
+            var _this = this;
+            events[this.uuid][event.type].forEach(function(fn){
+                fn.call( _this, event );
+            });
+        }
+    
+        if ( this[&quot;on&quot; + event.type] )
+            this[&quot;on&quot; + event.type].call( _this, event );
+    }
+    if(this.parentNode){
+        this.parentNode.dispatchEvent.call(this.parentNode,event);
+    }
+};
+	
+$w.__defineGetter__('onerror', function(){
+  return function(){
+   //$w.dispatchEvent('error');
+  };
+});
+
+$w.__defineSetter__('onerror', function(fn){
+  //$w.addEventListener('error', fn);
+});
+
+/*$w.__defineGetter__('onload', function(){
+  return function(){
+		//var event = document.createEvent();
+		//event.initEvent(&quot;load&quot;);
+   //$w.dispatchEvent(event);
+  };
+});
+
+$w.__defineSetter__('onload', function(fn){
+  //$w.addEventListener('load', fn);
+});
+
+$w.__defineGetter__('onunload', function(){
+  return function(){
+   //$w.dispatchEvent('unload');
+  };
+});
+
+$w.__defineSetter__('onunload', function(fn){
+  //$w.addEventListener('unload', fn);
+});*//*
+*	xhr.js
+*/
+$log(&quot;Initializing Window XMLHttpRequest.&quot;);
+// XMLHttpRequest
+// Originally implemented by Yehuda Katz
+$w.XMLHttpRequest = function(){
+	this.headers = {};
+	this.responseHeaders = {};
+};
+
+XMLHttpRequest.prototype = {
+	open: function(method, url, async, user, password){ 
+		this.readyState = 1;
+		if (async === false ){
+			this.async = false;
+		}else{ this.async = true; }
+		this.method = method || &quot;GET&quot;;
+		this.url = $env.location(url);
+		this.onreadystatechange();
+	},
+	setRequestHeader: function(header, value){
+		this.headers[header] = value;
+	},
+	getResponseHeader: function(header){ },
+	send: function(data){
+		var self = this;
+		
+		function makeRequest(){
+			$env.connection(self, function(){
+			  var responseXML = null;
+				self.__defineGetter__(&quot;responseXML&quot;, function(){
+  				if ( self.responseText.match(/^\s*&lt;/) ) {
+  				  if(responseXML){return responseXML;}
+  				  else{
+    					try {
+    					  $log(&quot;parsing response text into xml document&quot;);
+    						responseXML = $domparser.parseFromString(self.responseText);
+  					    return responseXML;
+    					} catch(e) { return null;/*TODO: need to flag an error here*/}
+  					}
+  				}else{return null;}
+  			});
+			});
+			self.onreadystatechange();
+		}
+		if (this.async){
+		  $log(&quot;XHR sending asynch;&quot;);
+			$env.runAsync(makeRequest);
+		}else{
+		  $log(&quot;XHR sending synch;&quot;);
+			makeRequest();
+		}
+	},
+	abort: function(){
+		//TODO
+	},
+	onreadystatechange: function(){
+		//TODO
+	},
+	getResponseHeader: function(header){
+	  var rHeader, returnedHeaders;
+		if (this.readyState &lt; 3){
+			throw new Error(&quot;INVALID_STATE_ERR&quot;);
+		} else {
+			returnedHeaders = [];
+			for (rHeader in this.responseHeaders) {
+				if (rHeader.match(new RegExp(header, &quot;i&quot;)))
+					returnedHeaders.push(this.responseHeaders[rHeader]);
+			}
+			if (returnedHeaders.length){ return returnedHeaders.join(&quot;, &quot;); }
+		}return null;
+	},
+	getAllResponseHeaders: function(){
+	  var header, returnedHeaders = [];
+		if (this.readyState &lt; 3){
+			throw new Error(&quot;INVALID_STATE_ERR&quot;);
+		} else {
+			for (header in this.responseHeaders){
+				returnedHeaders.push( header + &quot;: &quot; + this.responseHeaders[header] );
+			}
+		}return returnedHeaders.join(&quot;\r\n&quot;);
+	},
+	async: true,
+	readyState: 0,
+	responseText: &quot;&quot;,
+	status: 0
+};/*
+*	css.js
+*/
+$log(&quot;Initializing Window CSS&quot;);
+// returns a CSS2Properties object that represents the style
+// attributes and values used to render the specified element in this
+// window.  Any length values are always expressed in pixel, or
+// absolute values.
+$w.getComputedStyle = function(elt, pseudo_elt){
+  //TODO
+  //this is a naive implementation
+  $log(&quot;Getting computed style&quot;);
+  return elt?elt.style:new CSS2Properties({cssText:&quot;&quot;});
+};/*
+*	screen.js
+*/
+$log(&quot;Initializing Window Screen.&quot;);
+
+var $availHeight  = 600,
+    $availWidth   = 800,
+    $colorDepth    = 16,
+    $height       = 600,
+    $width        = 800;
+    
+$w.__defineGetter__(&quot;screen&quot;, function(){
+  return {
+    get availHeight(){return $availHeight;},
+    get availWidth(){return $availWidth;},
+    get colorDepth(){return $colorDepth;},
+    get height(){return $height;},
+    get width(){return $width;}
+  };
+});
+
+
+$w.moveBy = function(dx,dy){
+  //TODO
+};
+
+$w.moveTo = function(x,y) {
+  //TODO
+};
+
+/*$w.print = function(){
+  //TODO
+};*/
+
+$w.resizeBy = function(dw, dh){
+  $w.resizeTo($width+dw,$height+dh);
+};
+
+$w.resizeTo = function(width, height){
+  $width = (width &lt;= $availWidth) ? width : $availWidth;
+  $height = (height &lt;= $availHeight) ? height : $availHeight;
+};
+
+$w.scrollBy = function(dx, dy){
+  //TODO
+};
+$w.scrollTo = function(x,y){
+  //TODO
+};/*
+*	dialog.js
+*/
+$log(&quot;Initializing Window Dialogs.&quot;);
+$w.alert = function(message){
+ //TODO 
+};
+
+$w.confirm = function(question){
+  //TODO
+};
+
+$w.prompt = function(message, defaultMsg){
+  //TODO
+};/*
+*	document.js
+*
+*	DOM Level 2 /DOM level 3 (partial)
+*	
+*	This file adds the document object to the window and allows you
+*	you to set the window.document using an html string or dom object.
+*
+*/
+
+// read only reference to the Document object
+
+$log(&quot;Initializing window.document.&quot;);
+var $async = false;
+__extend__(HTMLDocument.prototype, {
+	get async(){ return $async;},
+	set async(async){ $async = async; },
+	get baseURI(){ return $env.location('./'); },
+	get URL(){ return $w.location.href;  }
+});
+	
+
+var $document =  new HTMLDocument($implementation);
+$w.__defineGetter__(&quot;document&quot;, function(){
+	return $document;
+});
+/*
+*	outro.js
+*/
+
+})(window, __env__); 
+
+}catch(e){
+    __env__.error(&quot;ERROR LOADING ENV : &quot; + e + &quot;\nLINE SOURCE:\n&quot; +e.rhinoException.lineSource());
+}</diff>
      <filename>dist/env.rhino.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,129 +1,129 @@
-#
-# Configuration File for JavaScript Lint 0.3.0
-# Developed by Matthias Miller (http://www.JavaScriptLint.com)
-#
-# This configuration file can be used to lint a collection of scripts, or to enable
-# or disable warnings for scripts that are linted via the command line.
-#
-
-### Warnings
-# Enable or disable warnings based on requirements.
-# Use &quot;+WarningName&quot; to display or &quot;-WarningName&quot; to suppress.
-#
-+no_return_value              # function {0} does not always return a value
-+duplicate_formal             # duplicate formal argument {0}
-+equal_as_assign              # test for equality (==) mistyped as assignment (=)?{0}
-+var_hides_arg                # variable {0} hides argument
-+redeclared_var               # redeclaration of {0} {1}
-+anon_no_return_value         # anonymous function does not always return a value
-+missing_semicolon            # missing semicolon
-+meaningless_block            # meaningless block; curly braces have no impact
-+comma_separated_stmts        # multiple statements separated by commas (use semicolons?)
-+unreachable_code             # unreachable code
-+missing_break                # missing break statement
-+missing_break_for_last_case  # missing break statement for last case in switch
-+comparison_type_conv         # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==)
-+inc_dec_within_stmt          # increment (++) and decrement (--) operators used as part of greater statement
-+useless_void                 # use of the void type may be unnecessary (void is always undefined)
-+multiple_plus_minus          # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs
-+use_of_label                 # use of label
--block_without_braces         # block statement without curly braces
-+leading_decimal_point        # leading decimal point may indicate a number or an object member
-+trailing_decimal_point       # trailing decimal point may indicate a number or an object member
-+octal_number                 # leading zeros make an octal number
-+nested_comment               # nested comment
-+misplaced_regex              # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma
-+ambiguous_newline            # unexpected end of line; it is ambiguous whether these lines are part of the same statement
--empty_statement              # empty statement or extra semicolon
--missing_option_explicit      # the &quot;option explicit&quot; control comment is missing
-+partial_option_explicit      # the &quot;option explicit&quot; control comment, if used, must be in the first script tag
-+dup_option_explicit          # duplicate &quot;option explicit&quot; control comment
-+useless_assign               # useless assignment
-+ambiguous_nested_stmt        # block statements containing block statements should use curly braces to resolve ambiguity
-+ambiguous_else_stmt          # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent)
-+missing_default_case         # missing default case in switch statement
-+duplicate_case_in_switch     # duplicate case in switch statements
-+default_not_at_end           # the default case is not at the end of the switch statement
-+legacy_cc_not_understood     # couldn't understand control comment using /*@keyword@*/ syntax
-+jsl_cc_not_understood        # couldn't understand control comment using /*jsl:keyword*/ syntax
-+useless_comparison           # useless comparison; comparing identical expressions
-+with_statement               # with statement hides undeclared variables; use temporary variable instead
-+trailing_comma_in_array      # extra comma is not recommended in array initializers
-+assign_to_function_call      # assignment to a function call
-+parseint_missing_radix       # parseInt missing radix parameter
-
-
-### Output format
-# Customize the format of the error message.
-#    __FILE__ indicates current file path
-#    __FILENAME__ indicates current file name
-#    __LINE__ indicates current line
-#    __ERROR__ indicates error message
-#
-# Visual Studio syntax (default):
-+output-format __FILE__(__LINE__): __ERROR__
-# Alternative syntax:
-#+output-format __FILE__:__LINE__: __ERROR__
-
-
-### Context
-# Show the in-line position of the error.
-# Use &quot;+context&quot; to display or &quot;-context&quot; to suppress.
-#
-+context
-
-
-### Semicolons
-# By default, assignments of an anonymous function to a variable or
-# property (such as a function prototype) must be followed by a semicolon.
-#
-+lambda_assign_requires_semicolon
-
-
-### Control Comments
-# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for
-# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is
-# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason,
-# although legacy control comments are enabled by default for backward compatibility.
-#
-+legacy_control_comments
-
-
-### JScript Function Extensions
-# JScript allows member functions to be defined like this:
-#     function MyObj() { /*constructor*/ }
-#     function MyObj.prototype.go() { /*member function*/ }
-#
-# It also allows events to be attached like this:
-#     function window::onload() { /*init page*/ }
-#
-# This is a Microsoft-only JavaScript extension. Enable this setting to allow them.
-#
--jscript_function_extensions
-
-
-### Defining identifiers
-# By default, &quot;option explicit&quot; is enabled on a per-file basis.
-# To enable this for all files, use &quot;+always_use_option_explicit&quot;
--always_use_option_explicit
-
-# Define certain identifiers of which the lint is not aware.
-# (Use this in conjunction with the &quot;undeclared identifier&quot; warning.)
-#
-# Common uses for webpages might be:
-#+define window
-#+define document
-
-
-### Interactive
-# Prompt for a keystroke before exiting.
-#+pauseatend
-
-
-### Files
-# Specify which files to lint
-# Use &quot;+recurse&quot; to enable recursion (disabled by default).
-# To add a set of files, use &quot;+process FileName&quot;, &quot;+process Folder\Path\*.js&quot;,
-# or &quot;+process Folder\Path\*.htm&quot;.
-#
-+process jsl-test.js
+#
+# Configuration File for JavaScript Lint 0.3.0
+# Developed by Matthias Miller (http://www.JavaScriptLint.com)
+#
+# This configuration file can be used to lint a collection of scripts, or to enable
+# or disable warnings for scripts that are linted via the command line.
+#
+
+### Warnings
+# Enable or disable warnings based on requirements.
+# Use &quot;+WarningName&quot; to display or &quot;-WarningName&quot; to suppress.
+#
++no_return_value              # function {0} does not always return a value
++duplicate_formal             # duplicate formal argument {0}
++equal_as_assign              # test for equality (==) mistyped as assignment (=)?{0}
++var_hides_arg                # variable {0} hides argument
++redeclared_var               # redeclaration of {0} {1}
++anon_no_return_value         # anonymous function does not always return a value
++missing_semicolon            # missing semicolon
++meaningless_block            # meaningless block; curly braces have no impact
++comma_separated_stmts        # multiple statements separated by commas (use semicolons?)
++unreachable_code             # unreachable code
++missing_break                # missing break statement
++missing_break_for_last_case  # missing break statement for last case in switch
++comparison_type_conv         # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==)
++inc_dec_within_stmt          # increment (++) and decrement (--) operators used as part of greater statement
++useless_void                 # use of the void type may be unnecessary (void is always undefined)
++multiple_plus_minus          # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs
++use_of_label                 # use of label
+-block_without_braces         # block statement without curly braces
++leading_decimal_point        # leading decimal point may indicate a number or an object member
++trailing_decimal_point       # trailing decimal point may indicate a number or an object member
++octal_number                 # leading zeros make an octal number
++nested_comment               # nested comment
++misplaced_regex              # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma
++ambiguous_newline            # unexpected end of line; it is ambiguous whether these lines are part of the same statement
+-empty_statement              # empty statement or extra semicolon
+-missing_option_explicit      # the &quot;option explicit&quot; control comment is missing
++partial_option_explicit      # the &quot;option explicit&quot; control comment, if used, must be in the first script tag
++dup_option_explicit          # duplicate &quot;option explicit&quot; control comment
++useless_assign               # useless assignment
++ambiguous_nested_stmt        # block statements containing block statements should use curly braces to resolve ambiguity
++ambiguous_else_stmt          # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent)
++missing_default_case         # missing default case in switch statement
++duplicate_case_in_switch     # duplicate case in switch statements
++default_not_at_end           # the default case is not at the end of the switch statement
++legacy_cc_not_understood     # couldn't understand control comment using /*@keyword@*/ syntax
++jsl_cc_not_understood        # couldn't understand control comment using /*jsl:keyword*/ syntax
++useless_comparison           # useless comparison; comparing identical expressions
++with_statement               # with statement hides undeclared variables; use temporary variable instead
++trailing_comma_in_array      # extra comma is not recommended in array initializers
++assign_to_function_call      # assignment to a function call
++parseint_missing_radix       # parseInt missing radix parameter
+
+
+### Output format
+# Customize the format of the error message.
+#    __FILE__ indicates current file path
+#    __FILENAME__ indicates current file name
+#    __LINE__ indicates current line
+#    __ERROR__ indicates error message
+#
+# Visual Studio syntax (default):
++output-format __FILE__(__LINE__): __ERROR__
+# Alternative syntax:
+#+output-format __FILE__:__LINE__: __ERROR__
+
+
+### Context
+# Show the in-line position of the error.
+# Use &quot;+context&quot; to display or &quot;-context&quot; to suppress.
+#
++context
+
+
+### Semicolons
+# By default, assignments of an anonymous function to a variable or
+# property (such as a function prototype) must be followed by a semicolon.
+#
++lambda_assign_requires_semicolon
+
+
+### Control Comments
+# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for
+# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is
+# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason,
+# although legacy control comments are enabled by default for backward compatibility.
+#
++legacy_control_comments
+
+
+### JScript Function Extensions
+# JScript allows member functions to be defined like this:
+#     function MyObj() { /*constructor*/ }
+#     function MyObj.prototype.go() { /*member function*/ }
+#
+# It also allows events to be attached like this:
+#     function window::onload() { /*init page*/ }
+#
+# This is a Microsoft-only JavaScript extension. Enable this setting to allow them.
+#
+-jscript_function_extensions
+
+
+### Defining identifiers
+# By default, &quot;option explicit&quot; is enabled on a per-file basis.
+# To enable this for all files, use &quot;+always_use_option_explicit&quot;
+-always_use_option_explicit
+
+# Define certain identifiers of which the lint is not aware.
+# (Use this in conjunction with the &quot;undeclared identifier&quot; warning.)
+#
+# Common uses for webpages might be:
+#+define window
+#+define document
+
+
+### Interactive
+# Prompt for a keystroke before exiting.
+#+pauseatend
+
+
+### Files
+# Specify which files to lint
+# Use &quot;+recurse&quot; to enable recursion (disabled by default).
+# To add a set of files, use &quot;+process FileName&quot;, &quot;+process Folder\Path\*.js&quot;,
+# or &quot;+process Folder\Path\*.htm&quot;.
+#
++process jsl-test.js</diff>
      <filename>jsl/jsl.default.conf</filename>
    </modified>
    <modified>
      <diff>@@ -1,216 +1,216 @@
-/*
-* CSS2Properties - DOM Level 2 CSS
-*/
-$w.__defineGetter__(&quot;CSS2Properties&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-var CSS2Properties = function(options){
-    __extend__(this, __supportedStyles__);
-    __cssTextToStyles__(this, options.cssText?options.cssText:&quot;&quot;);
-};
-//__extend__(CSS2Properties.prototype, __supportedStyles__);
-__extend__(CSS2Properties.prototype, {
-    get cssText(){
-        return Array.prototype.apply.join(this,[';\n']);
-    },
-    set cssText(cssText){ 
-        __cssTextToStyles__(this, cssText); 
-    },
-    getPropertyCSSValue : function(){
-        
-    },
-    getPropertyPriority : function(){
-        
-    },
-    getPropertyValue : function(name){
-		var camelCase = name.replace(/\-(\w)/g, function(all, letter){
-			return letter.toUpperCase();
-		});
-        var i, value = this[camelCase];
-        if(value === undefined){
-            for(i=0;i&lt;this.length;i++){
-                if(this[i]===name){
-                    return this[i];
-                }
-            }
-        }
-        return value;
-    },
-    item : function(index){
-        return this[index];
-    },
-    removeProperty: function(){
-        
-    },
-    setProperty: function(){
-        
-    },
-    toString:function(){
-        if (this.length &gt;0){
-            return &quot;{\n\t&quot;+Array.prototype.join.apply(this,[';\n\t'])+&quot;}\n&quot;;
-        }else{
-            return '';
-        }
-    }
-});
-
-var __cssTextToStyles__ = function(css2props, cssText){
-    var styleArray=[];
-    var style, name, value, camelCaseName, w3cName, styles = cssText.split(';');
-    for ( var i = 0; i &lt; styles.length; i++ ) {
-        //$log(&quot;Adding style property &quot; + styles[i]);
-    	style = styles[i].split(':');
-    	if ( style.length == 2 ){
-    	    //keep a reference to the original name of the style which was set
-    	    //this is the w3c style setting method.
-    	    styleArray[styleArray.length] = w3cName = styles[i];
-            //camel case for dash case
-    	    value = trim(style[1]);
-            camelCaseName = trim(style[0].replace(/\-(\w)/g, function(all, letter){
-				return letter.toUpperCase();
-			}));
-            //$log('CSS Style Name:  ' + camelCaseName);
-            if(css2props[camelCaseName]!==undefined){
-                //set the value internally with camelcase name 
-                //$log('Setting css ' + camelCaseName + ' to ' + value);
-                css2props[camelCaseName] = value;
-            };
-    	}
-    }
-    __setArray__(css2props, styleArray);
-};
-//Obviously these arent all supported but by commenting out various sections
-//this provides a single location to configure what is exposed as supported.
-//These will likely need to be functional getters/setters in the future to deal with
-//the variation on input formulations
-var __supportedStyles__ = {
-    azimuth: &quot;&quot;,
-    background:	&quot;&quot;,
-    backgroundAttachment:	&quot;&quot;,
-    backgroundColor:	&quot;&quot;,
-    backgroundImage:	&quot;&quot;,
-    backgroundPosition:	&quot;&quot;,
-    backgroundRepeat:	&quot;&quot;,
-    border:	&quot;&quot;,
-    borderBottom:	&quot;&quot;,
-    borderBottomColor:	&quot;&quot;,
-    borderBottomStyle:	&quot;&quot;,
-    borderBottomWidth:	&quot;&quot;,
-    borderCollapse:	&quot;&quot;,
-    borderColor:	&quot;&quot;,
-    borderLeft:	&quot;&quot;,
-    borderLeftColor:	&quot;&quot;,
-    borderLeftStyle:	&quot;&quot;,
-    borderLeftWidth:	&quot;&quot;,
-    borderRight:	&quot;&quot;,
-    borderRightColor:	&quot;&quot;,
-    borderRightStyle:	&quot;&quot;,
-    borderRightWidth:	&quot;&quot;,
-    borderSpacing:	&quot;&quot;,
-    borderStyle:	&quot;&quot;,
-    borderTop:	&quot;&quot;,
-    borderTopColor:	&quot;&quot;,
-    borderTopStyle:	&quot;&quot;,
-    borderTopWidth:	&quot;&quot;,
-    borderWidth:	&quot;&quot;,
-    bottom:	&quot;&quot;,
-    captionSide:	&quot;&quot;,
-    clear:	&quot;&quot;,
-    clip:	&quot;&quot;,
-    color:	&quot;&quot;,
-    content:	&quot;&quot;,
-    counterIncrement:	&quot;&quot;,
-    counterReset:	&quot;&quot;,
-    cssFloat:	&quot;&quot;,
-    cue:	&quot;&quot;,
-    cueAfter:	&quot;&quot;,
-    cueBefore:	&quot;&quot;,
-    cursor:	&quot;&quot;,
-    direction:	&quot;&quot;,
-    display:	&quot;&quot;,
-    elevation:	&quot;&quot;,
-    emptyCells:	&quot;&quot;,
-    font:	&quot;&quot;,
-    fontFamily:	&quot;&quot;,
-    fontSize:	&quot;&quot;,
-    fontSizeAdjust:	&quot;&quot;,
-    fontStretch:	&quot;&quot;,
-    fontStyle:	&quot;&quot;,
-    fontVariant:	&quot;&quot;,
-    fontWeight:	&quot;&quot;,
-    height:	&quot;&quot;,
-    left:	&quot;&quot;,
-    letterSpacing:	&quot;&quot;,
-    lineHeight:	&quot;&quot;,
-    listStyle:	&quot;&quot;,
-    listStyleImage:	&quot;&quot;,
-    listStylePosition:	&quot;&quot;,
-    listStyleType:	&quot;&quot;,
-    margin:	&quot;&quot;,
-    marginBottom:	&quot;&quot;,
-    marginLeft:	&quot;&quot;,
-    marginRight:	&quot;&quot;,
-    marginTop:	&quot;&quot;,
-    markerOffset:	&quot;&quot;,
-    marks:	&quot;&quot;,
-    maxHeight:	&quot;&quot;,
-    maxWidth:	&quot;&quot;,
-    minHeight:	&quot;&quot;,
-    minWidth:	&quot;&quot;,
-    opacity:	1,
-    orphans:	&quot;&quot;,
-    outline:	&quot;&quot;,
-    outlineColor:	&quot;&quot;,
-    outlineOffset:	&quot;&quot;,
-    outlineStyle:	&quot;&quot;,
-    outlineWidth:	&quot;&quot;,
-    overflow:	&quot;&quot;,
-    overflowX:	&quot;&quot;,
-    overflowY:	&quot;&quot;,
-    padding:	&quot;&quot;,
-    paddingBottom:	&quot;&quot;,
-    paddingLeft:	&quot;&quot;,
-    paddingRight:	&quot;&quot;,
-    paddingTop:	&quot;&quot;,
-    page:	&quot;&quot;,
-    pageBreakAfter:	&quot;&quot;,
-    pageBreakBefore:	&quot;&quot;,
-    pageBreakInside:	&quot;&quot;,
-    pause:	&quot;&quot;,
-    pauseAfter:	&quot;&quot;,
-    pauseBefore:	&quot;&quot;,
-    pitch:	&quot;&quot;,
-    pitchRange:	&quot;&quot;,
-    position:	&quot;&quot;,
-    quotes:	&quot;&quot;,
-    richness:	&quot;&quot;,
-    right:	&quot;&quot;,
-    size:	&quot;&quot;,
-    speak:	&quot;&quot;,
-    speakHeader:	&quot;&quot;,
-    speakNumeral:	&quot;&quot;,
-    speakPunctuation:	&quot;&quot;,
-    speechRate:	&quot;&quot;,
-    stress:	&quot;&quot;,
-    tableLayout:	&quot;&quot;,
-    textAlign:	&quot;&quot;,
-    textDecoration:	&quot;&quot;,
-    textIndent:	&quot;&quot;,
-    textShadow:	&quot;&quot;,
-    textTransform:	&quot;&quot;,
-    top:	&quot;&quot;,
-    unicodeBidi:	&quot;&quot;,
-    verticalAlign:	&quot;&quot;,
-    visibility:	&quot;&quot;,
-    voiceFamily:	&quot;&quot;,
-    volume:	&quot;&quot;,
-    whiteSpace:	&quot;&quot;,
-    widows:	&quot;&quot;,
-    width:	&quot;&quot;,
-    wordSpacing:	&quot;&quot;,
-    zIndex:	&quot;&quot;
+/*
+* CSS2Properties - DOM Level 2 CSS
+*/
+$w.__defineGetter__(&quot;CSS2Properties&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+
+var CSS2Properties = function(options){
+    __extend__(this, __supportedStyles__);
+    __cssTextToStyles__(this, options.cssText?options.cssText:&quot;&quot;);
+};
+//__extend__(CSS2Properties.prototype, __supportedStyles__);
+__extend__(CSS2Properties.prototype, {
+    get cssText(){
+        return Array.prototype.apply.join(this,[';\n']);
+    },
+    set cssText(cssText){ 
+        __cssTextToStyles__(this, cssText); 
+    },
+    getPropertyCSSValue : function(){
+        
+    },
+    getPropertyPriority : function(){
+        
+    },
+    getPropertyValue : function(name){
+		var camelCase = name.replace(/\-(\w)/g, function(all, letter){
+			return letter.toUpperCase();
+		});
+        var i, value = this[camelCase];
+        if(value === undefined){
+            for(i=0;i&lt;this.length;i++){
+                if(this[i]===name){
+                    return this[i];
+                }
+            }
+        }
+        return value;
+    },
+    item : function(index){
+        return this[index];
+    },
+    removeProperty: function(){
+        
+    },
+    setProperty: function(){
+        
+    },
+    toString:function(){
+        if (this.length &gt;0){
+            return &quot;{\n\t&quot;+Array.prototype.join.apply(this,[';\n\t'])+&quot;}\n&quot;;
+        }else{
+            return '';
+        }
+    }
+});
+
+var __cssTextToStyles__ = function(css2props, cssText){
+    var styleArray=[];
+    var style, name, value, camelCaseName, w3cName, styles = cssText.split(';');
+    for ( var i = 0; i &lt; styles.length; i++ ) {
+        //$log(&quot;Adding style property &quot; + styles[i]);
+    	style = styles[i].split(':');
+    	if ( style.length == 2 ){
+    	    //keep a reference to the original name of the style which was set
+    	    //this is the w3c style setting method.
+    	    styleArray[styleArray.length] = w3cName = styles[i];
+            //camel case for dash case
+    	    value = trim(style[1]);
+            camelCaseName = trim(style[0].replace(/\-(\w)/g, function(all, letter){
+				return letter.toUpperCase();
+			}));
+            //$log('CSS Style Name:  ' + camelCaseName);
+            if(css2props[camelCaseName]!==undefined){
+                //set the value internally with camelcase name 
+                //$log('Setting css ' + camelCaseName + ' to ' + value);
+                css2props[camelCaseName] = value;
+            };
+    	}
+    }
+    __setArray__(css2props, styleArray);
+};
+//Obviously these arent all supported but by commenting out various sections
+//this provides a single location to configure what is exposed as supported.
+//These will likely need to be functional getters/setters in the future to deal with
+//the variation on input formulations
+var __supportedStyles__ = {
+    azimuth: &quot;&quot;,
+    background:	&quot;&quot;,
+    backgroundAttachment:	&quot;&quot;,
+    backgroundColor:	&quot;&quot;,
+    backgroundImage:	&quot;&quot;,
+    backgroundPosition:	&quot;&quot;,
+    backgroundRepeat:	&quot;&quot;,
+    border:	&quot;&quot;,
+    borderBottom:	&quot;&quot;,
+    borderBottomColor:	&quot;&quot;,
+    borderBottomStyle:	&quot;&quot;,
+    borderBottomWidth:	&quot;&quot;,
+    borderCollapse:	&quot;&quot;,
+    borderColor:	&quot;&quot;,
+    borderLeft:	&quot;&quot;,
+    borderLeftColor:	&quot;&quot;,
+    borderLeftStyle:	&quot;&quot;,
+    borderLeftWidth:	&quot;&quot;,
+    borderRight:	&quot;&quot;,
+    borderRightColor:	&quot;&quot;,
+    borderRightStyle:	&quot;&quot;,
+    borderRightWidth:	&quot;&quot;,
+    borderSpacing:	&quot;&quot;,
+    borderStyle:	&quot;&quot;,
+    borderTop:	&quot;&quot;,
+    borderTopColor:	&quot;&quot;,
+    borderTopStyle:	&quot;&quot;,
+    borderTopWidth:	&quot;&quot;,
+    borderWidth:	&quot;&quot;,
+    bottom:	&quot;&quot;,
+    captionSide:	&quot;&quot;,
+    clear:	&quot;&quot;,
+    clip:	&quot;&quot;,
+    color:	&quot;&quot;,
+    content:	&quot;&quot;,
+    counterIncrement:	&quot;&quot;,
+    counterReset:	&quot;&quot;,
+    cssFloat:	&quot;&quot;,
+    cue:	&quot;&quot;,
+    cueAfter:	&quot;&quot;,
+    cueBefore:	&quot;&quot;,
+    cursor:	&quot;&quot;,
+    direction:	&quot;&quot;,
+    display:	&quot;&quot;,
+    elevation:	&quot;&quot;,
+    emptyCells:	&quot;&quot;,
+    font:	&quot;&quot;,
+    fontFamily:	&quot;&quot;,
+    fontSize:	&quot;&quot;,
+    fontSizeAdjust:	&quot;&quot;,
+    fontStretch:	&quot;&quot;,
+    fontStyle:	&quot;&quot;,
+    fontVariant:	&quot;&quot;,
+    fontWeight:	&quot;&quot;,
+    height:	&quot;&quot;,
+    left:	&quot;&quot;,
+    letterSpacing:	&quot;&quot;,
+    lineHeight:	&quot;&quot;,
+    listStyle:	&quot;&quot;,
+    listStyleImage:	&quot;&quot;,
+    listStylePosition:	&quot;&quot;,
+    listStyleType:	&quot;&quot;,
+    margin:	&quot;&quot;,
+    marginBottom:	&quot;&quot;,
+    marginLeft:	&quot;&quot;,
+    marginRight:	&quot;&quot;,
+    marginTop:	&quot;&quot;,
+    markerOffset:	&quot;&quot;,
+    marks:	&quot;&quot;,
+    maxHeight:	&quot;&quot;,
+    maxWidth:	&quot;&quot;,
+    minHeight:	&quot;&quot;,
+    minWidth:	&quot;&quot;,
+    opacity:	1,
+    orphans:	&quot;&quot;,
+    outline:	&quot;&quot;,
+    outlineColor:	&quot;&quot;,
+    outlineOffset:	&quot;&quot;,
+    outlineStyle:	&quot;&quot;,
+    outlineWidth:	&quot;&quot;,
+    overflow:	&quot;&quot;,
+    overflowX:	&quot;&quot;,
+    overflowY:	&quot;&quot;,
+    padding:	&quot;&quot;,
+    paddingBottom:	&quot;&quot;,
+    paddingLeft:	&quot;&quot;,
+    paddingRight:	&quot;&quot;,
+    paddingTop:	&quot;&quot;,
+    page:	&quot;&quot;,
+    pageBreakAfter:	&quot;&quot;,
+    pageBreakBefore:	&quot;&quot;,
+    pageBreakInside:	&quot;&quot;,
+    pause:	&quot;&quot;,
+    pauseAfter:	&quot;&quot;,
+    pauseBefore:	&quot;&quot;,
+    pitch:	&quot;&quot;,
+    pitchRange:	&quot;&quot;,
+    position:	&quot;&quot;,
+    quotes:	&quot;&quot;,
+    richness:	&quot;&quot;,
+    right:	&quot;&quot;,
+    size:	&quot;&quot;,
+    speak:	&quot;&quot;,
+    speakHeader:	&quot;&quot;,
+    speakNumeral:	&quot;&quot;,
+    speakPunctuation:	&quot;&quot;,
+    speechRate:	&quot;&quot;,
+    stress:	&quot;&quot;,
+    tableLayout:	&quot;&quot;,
+    textAlign:	&quot;&quot;,
+    textDecoration:	&quot;&quot;,
+    textIndent:	&quot;&quot;,
+    textShadow:	&quot;&quot;,
+    textTransform:	&quot;&quot;,
+    top:	&quot;&quot;,
+    unicodeBidi:	&quot;&quot;,
+    verticalAlign:	&quot;&quot;,
+    visibility:	&quot;&quot;,
+    voiceFamily:	&quot;&quot;,
+    volume:	&quot;&quot;,
+    whiteSpace:	&quot;&quot;,
+    widows:	&quot;&quot;,
+    width:	&quot;&quot;,
+    wordSpacing:	&quot;&quot;,
+    zIndex:	&quot;&quot;
 };
\ No newline at end of file</diff>
      <filename>src/css/properties.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,19 +1,19 @@
-/* 
-* CSSRule - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CSSRule&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var CSSRule = function(options){
-  var $style, 
-      $selectorText = options.selectorText?options.selectorText:&quot;&quot;;
-      $style = new CSS2Properties({cssText:options.cssText?options.cssText:null});
-    return __extend__(this, {
-      get style(){return $style;},
-      get selectorText(){return $selectorText;},
-      set selectorText(selectorText){$selectorText = selectorText;}
-    });
-};
+/* 
+* CSSRule - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CSSRule&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var CSSRule = function(options){
+  var $style, 
+      $selectorText = options.selectorText?options.selectorText:&quot;&quot;;
+      $style = new CSS2Properties({cssText:options.cssText?options.cssText:null});
+    return __extend__(this, {
+      get style(){return $style;},
+      get selectorText(){return $selectorText;},
+      set selectorText(selectorText){$selectorText = selectorText;}
+    });
+};</diff>
      <filename>src/css/rule.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,55 +1,55 @@
-/* 
-* CSSStyleSheet - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CSSStyleSheet&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-var CSSStyleSheet = function(options){
-    var $cssRules, 
-        $disabled = options.disabled?options.disabled:false,
-        $href = options.href?options.href:null,
-        $parentStyleSheet = options.parentStyleSheet?options.parentStyleSheet:null,
-        $title = options.title?options.title:&quot;&quot;,
-        $type = &quot;text/css&quot;;
-        
-    function parseStyleSheet(text){
-      //this is pretty ugly, but text is the entire text of a stylesheet
-      var cssRules = [];
-    	if (!text) text = &quot;&quot;;
-    	text = trim(text.replace(/\/\*(\r|\n|.)*\*\//g,&quot;&quot;));
-    	// TODO: @import ?
-    	var blocks = text.split(&quot;}&quot;);
-    	blocks.pop();
-    	var i, len = blocks.length;
-    	var definition_block, properties, selectors;
-    	for (i=0; i&lt;len; i++){
-    		definition_block = blocks[i].split(&quot;{&quot;);
-    		if(definition_block.length === 2){
-      		selectors = definition_block[0].split(&quot;,&quot;);
-      		for(var j=0;j&lt;selectors.length;j++){
-      		  cssRules.push(new CSSRule({
-      		    selectorText:selectors[j],
-      		    cssText:definition_block[1]
-      		  }));
-      		}
-      		__setArray__($cssRules, cssRules);
-    		}
-    	}
-    };
-    parseStyleSheet(options.text);
-    return __extend__(this, {
-      get cssRules(){return $cssRules;},
-      get rule(){return $cssRules;},//IE - may be deprecated
-      get href(){return $href;},
-      get parentStyleSheet(){return $parentStyleSheet;},
-      get title(){return $title;},
-      get type(){return $type;},
-      addRule: function(selector, style, index){/*TODO*/},
-      deleteRule: function(index){/*TODO*/},
-      insertRule: function(rule, index){/*TODO*/},
-      removeRule: function(index){this.deleteRule(index);}//IE - may be deprecated
-    });
-};
+/* 
+* CSSStyleSheet - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CSSStyleSheet&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+var CSSStyleSheet = function(options){
+    var $cssRules, 
+        $disabled = options.disabled?options.disabled:false,
+        $href = options.href?options.href:null,
+        $parentStyleSheet = options.parentStyleSheet?options.parentStyleSheet:null,
+        $title = options.title?options.title:&quot;&quot;,
+        $type = &quot;text/css&quot;;
+        
+    function parseStyleSheet(text){
+      //this is pretty ugly, but text is the entire text of a stylesheet
+      var cssRules = [];
+    	if (!text) text = &quot;&quot;;
+    	text = trim(text.replace(/\/\*(\r|\n|.)*\*\//g,&quot;&quot;));
+    	// TODO: @import ?
+    	var blocks = text.split(&quot;}&quot;);
+    	blocks.pop();
+    	var i, len = blocks.length;
+    	var definition_block, properties, selectors;
+    	for (i=0; i&lt;len; i++){
+    		definition_block = blocks[i].split(&quot;{&quot;);
+    		if(definition_block.length === 2){
+      		selectors = definition_block[0].split(&quot;,&quot;);
+      		for(var j=0;j&lt;selectors.length;j++){
+      		  cssRules.push(new CSSRule({
+      		    selectorText:selectors[j],
+      		    cssText:definition_block[1]
+      		  }));
+      		}
+      		__setArray__($cssRules, cssRules);
+    		}
+    	}
+    };
+    parseStyleSheet(options.text);
+    return __extend__(this, {
+      get cssRules(){return $cssRules;},
+      get rule(){return $cssRules;},//IE - may be deprecated
+      get href(){return $href;},
+      get parentStyleSheet(){return $parentStyleSheet;},
+      get title(){return $title;},
+      get type(){return $type;},
+      addRule: function(selector, style, index){/*TODO*/},
+      deleteRule: function(index){/*TODO*/},
+      insertRule: function(rule, index){/*TODO*/},
+      removeRule: function(index){this.deleteRule(index);}//IE - may be deprecated
+    });
+};</diff>
      <filename>src/css/stylesheet.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,55 +1,55 @@
-$log(&quot;Defining Attr&quot;);
-/*
-* Attr - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Attr&quot;, function(){
-    return function(){
-        throw new Error(&quot;Object cannot be created in this context&quot;);
-    };
-});
-
-
-/**
- * @class  DOMAttr - The Attr interface represents an attribute in an Element object
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMAttr = function(ownerDocument) {
-    //$log(&quot;\tcreating dom attribute&quot;);
-    this.DOMNode = DOMNode;
-    this.DOMNode(ownerDocument);
-    
-    this.name      = &quot;&quot;;                    // the name of this attribute
-    this.specified = false;
-    this.value     = &quot;&quot;;                    // the value of the attribute is returned as a string
-    this.nodeType  = DOMNode.ATTRIBUTE_NODE;
-    this.ownerElement = null;               // set when Attr is added to NamedNodeMap
-    
-    //$log(&quot;\tfincished creating dom attribute &quot; + this);
-};
-DOMAttr.prototype = new DOMNode; 
-__extend__(DOMAttr.prototype, {
-    get name(){
-        return this.nodeName;
-    },
-    get value(){
-        return this.nodeValue;
-    },
-    set value(value){
-        // throw Exception if Attribute is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        // delegate to node
-        this.specified = (this.value.length &gt; 0);
-        this.nodeValue = value;
-    },
-    get xml(){
-        return this.nodeName + &quot;='&quot; + this.nodeValue + &quot;' &quot;;
-    },
-    toString : function(){
-        return &quot;Attr #&quot; + this._id + &quot; &quot; + this.name;
-    }
-});    
-
+$log(&quot;Defining Attr&quot;);
+/*
+* Attr - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Attr&quot;, function(){
+    return function(){
+        throw new Error(&quot;Object cannot be created in this context&quot;);
+    };
+});
+
+
+/**
+ * @class  DOMAttr - The Attr interface represents an attribute in an Element object
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMAttr = function(ownerDocument) {
+    //$log(&quot;\tcreating dom attribute&quot;);
+    this.DOMNode = DOMNode;
+    this.DOMNode(ownerDocument);
+    
+    this.name      = &quot;&quot;;                    // the name of this attribute
+    this.specified = false;
+    this.value     = &quot;&quot;;                    // the value of the attribute is returned as a string
+    this.nodeType  = DOMNode.ATTRIBUTE_NODE;
+    this.ownerElement = null;               // set when Attr is added to NamedNodeMap
+    
+    //$log(&quot;\tfincished creating dom attribute &quot; + this);
+};
+DOMAttr.prototype = new DOMNode; 
+__extend__(DOMAttr.prototype, {
+    get name(){
+        return this.nodeName;
+    },
+    get value(){
+        return this.nodeValue;
+    },
+    set value(value){
+        // throw Exception if Attribute is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        // delegate to node
+        this.specified = (this.value.length &gt; 0);
+        this.nodeValue = value;
+    },
+    get xml(){
+        return this.nodeName + &quot;='&quot; + this.nodeValue + &quot;' &quot;;
+    },
+    toString : function(){
+        return &quot;Attr #&quot; + this._id + &quot; &quot; + this.name;
+    }
+});    
+</diff>
      <filename>src/dom/attr.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,33 +1,33 @@
-$log(&quot;Defining CDATASection&quot;);
-/*
-* CDATASection - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CDATASection&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMCDATASection - CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup.
- *   The only delimiter that is recognized in a CDATA section is the &quot;\]\]\&gt;&quot; string that ends the CDATA section
- * @extends DOMCharacterData
- * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMCDATASection = function(ownerDocument) {
-  this.DOMText  = DOMText;
-  this.DOMText(ownerDocument);
-
-  this.nodeName  = &quot;#cdata-section&quot;;
-  this.nodeType  = DOMNode.CDATA_SECTION_NODE;
-};
-DOMCDATASection.prototype = new DOMText;
-__extend__(DOMCDATASection.prototype,{
-    get xml(){
-        return &quot;&lt;![CDATA[&quot; + this.nodeValue + &quot;]]&gt;&quot;;
-    },
-    toString : function(){
-        return &quot;CDATA #&quot;+this._id;
-    }
+$log(&quot;Defining CDATASection&quot;);
+/*
+* CDATASection - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CDATASection&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMCDATASection - CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup.
+ *   The only delimiter that is recognized in a CDATA section is the &quot;\]\]\&gt;&quot; string that ends the CDATA section
+ * @extends DOMCharacterData
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMCDATASection = function(ownerDocument) {
+  this.DOMText  = DOMText;
+  this.DOMText(ownerDocument);
+
+  this.nodeName  = &quot;#cdata-section&quot;;
+  this.nodeType  = DOMNode.CDATA_SECTION_NODE;
+};
+DOMCDATASection.prototype = new DOMText;
+__extend__(DOMCDATASection.prototype,{
+    get xml(){
+        return &quot;&lt;![CDATA[&quot; + this.nodeValue + &quot;]]&gt;&quot;;
+    },
+    toString : function(){
+        return &quot;CDATA #&quot;+this._id;
+    }
 });
\ No newline at end of file</diff>
      <filename>src/dom/cdatasection.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,119 +1,119 @@
-$debug(&quot;Defining CharacterData&quot;);
-/*
-* CharacterData - DOM Level 2
-*/
-$w.__defineGetter__(&quot;CharacterData&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMCharacterData - parent abstract class for DOMText and DOMComment
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMCharacterData = function(ownerDocument) {
-  this.DOMNode  = DOMNode;
-  this.DOMNode(ownerDocument);
-  this.data   = &quot;&quot;;
-  this.length = 0;
-};
-DOMCharacterData.prototype = new DOMNode;
-__extend__(DOMCharacterData.prototype,{
-    get data(){
-        return String(this.nodeValue);
-    },
-    set data(data){
-        this.nodeValue = String(data);
-    },
-    get length(){return this.nodeValue.length;},
-    appendData: function(arg){
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        // append data
-        this.data = &quot;&quot; + this.data + arg;
-    },
-    deleteData: function(offset, count){ 
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
-              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // delete data
-            if(!count || (offset + count) &gt; this.data.length) {
-              this.data = this.data.substring(0, offset);
-            }else {
-              this.data = this.data.substring(0, offset).concat(this.data.substring(offset + count));
-            }
-        }
-    },
-    insertData: function(offset, arg){
-        // throw Exception if DOMCharacterData is readonly
-        if(this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly){
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        
-        if(this.data){
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // insert data
-            this.data =  this.data.substring(0, offset).concat(arg, this.data.substring(offset));
-        }else {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (offset != 0)) {
-               throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // set data
-            this.data = arg;
-        }
-    },
-    replaceData: function(offset, count, arg){
-        // throw Exception if DOMCharacterData is readonly
-        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
-            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
-        }
-        
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            
-            // replace data
-            this.data = this.data.substring(0, offset).concat(arg, this.data.substring(offset + count));
-        }else {
-            // set data
-            this.data = arg;
-        }
-    },
-    substringData: function(offset, count){
-        var ret = null;
-        if (this.data) {
-            // throw Exception if offset is negative or greater than the data length,
-            // or the count is negative
-            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt; this.data.length) || (count &lt; 0))) {
-                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
-            }
-            // if count is not specified
-            if (!count) {
-                ret = this.data.substring(offset); // default to 'end of string'
-            }else{
-                ret = this.data.substring(offset, offset + count);
-            }
-        }
-        return ret;
-    }
-});
+$debug(&quot;Defining CharacterData&quot;);
+/*
+* CharacterData - DOM Level 2
+*/
+$w.__defineGetter__(&quot;CharacterData&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMCharacterData - parent abstract class for DOMText and DOMComment
+ * @extends DOMNode
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMCharacterData = function(ownerDocument) {
+  this.DOMNode  = DOMNode;
+  this.DOMNode(ownerDocument);
+  this.data   = &quot;&quot;;
+  this.length = 0;
+};
+DOMCharacterData.prototype = new DOMNode;
+__extend__(DOMCharacterData.prototype,{
+    get data(){
+        return String(this.nodeValue);
+    },
+    set data(data){
+        this.nodeValue = String(data);
+    },
+    get length(){return this.nodeValue.length;},
+    appendData: function(arg){
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        // append data
+        this.data = &quot;&quot; + this.data + arg;
+    },
+    deleteData: function(offset, count){ 
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
+              throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // delete data
+            if(!count || (offset + count) &gt; this.data.length) {
+              this.data = this.data.substring(0, offset);
+            }else {
+              this.data = this.data.substring(0, offset).concat(this.data.substring(offset + count));
+            }
+        }
+    },
+    insertData: function(offset, arg){
+        // throw Exception if DOMCharacterData is readonly
+        if(this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly){
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        
+        if(this.data){
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // insert data
+            this.data =  this.data.substring(0, offset).concat(arg, this.data.substring(offset));
+        }else {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; (offset != 0)) {
+               throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // set data
+            this.data = arg;
+        }
+    },
+    replaceData: function(offset, count, arg){
+        // throw Exception if DOMCharacterData is readonly
+        if (this.ownerDocument.implementation.errorChecking &amp;&amp; this._readonly) {
+            throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
+        }
+        
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt;  this.data.length) || (count &lt; 0))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            
+            // replace data
+            this.data = this.data.substring(0, offset).concat(arg, this.data.substring(offset + count));
+        }else {
+            // set data
+            this.data = arg;
+        }
+    },
+    substringData: function(offset, count){
+        var ret = null;
+        if (this.data) {
+            // throw Exception if offset is negative or greater than the data length,
+            // or the count is negative
+            if (this.ownerDocument.implementation.errorChecking &amp;&amp; ((offset &lt; 0) || (offset &gt; this.data.length) || (count &lt; 0))) {
+                throw(new DOMException(DOMException.INDEX_SIZE_ERR));
+            }
+            // if count is not specified
+            if (!count) {
+                ret = this.data.substring(offset); // default to 'end of string'
+            }else{
+                ret = this.data.substring(offset, offset + count);
+            }
+        }
+        return ret;
+    }
+});</diff>
      <filename>src/dom/characterdata.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,32 +1,32 @@
-$log(&quot;Defining Comment&quot;);
-/* 
-* Comment - DOM Level 2
-*/
-$w.__defineGetter__(&quot;Comment&quot;, function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-/**
- * @class  DOMComment - This represents the content of a comment, i.e., all the characters between the starting '&lt;!--' and ending '--&gt;'
- * @extends DOMCharacterData
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  ownerDocument : DOMDocument - The Document object associated with this node.
- */
-var DOMComment = function(ownerDocument) {
-  this.DOMCharacterData  = DOMCharacterData;
-  this.DOMCharacterData(ownerDocument);
-
-  this.nodeName  = &quot;#comment&quot;;
-  this.nodeType  = DOMNode.COMMENT_NODE;
-};
-DOMComment.prototype = new DOMCharacterData;
-__extend__(DOMComment.prototype, {
-    get xml(){
-        return &quot;&lt;!-- &quot; + this.nodeValue + &quot; --&gt;&quot;;
-    },
-    toString : function(){
-        return &quot;Comment #&quot;+this._id;
-    }
-});
+$log(&quot;Defining Comment&quot;);
+/* 
+* Comment - DOM Level 2
+*/
+$w.__defineGetter__(&quot;Comment&quot;, function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
+/**
+ * @class  DOMComment - This represents the content of a comment, i.e., all the characters between the starting '&lt;!--' and ending '--&gt;'
+ * @extends DOMCharacterData
+ * @author Jon van Noort (jon@webarcana.com.au)
+ * @param  ownerDocument : DOMDocument - The Document object associated with this node.
+ */
+var DOMComment = function(ownerDocument) {
+  this.DOMCharacterData  = DOMCharacterData;
+  this.DOMCharacterData(ownerDocument);
+
+  this.nodeName  = &quot;#comment&quot;;
+  this.nodeType  = DOMNode.COMMENT_NODE;
+};
+DOMComment.prototype = new DOMCharacterData;
+__extend__(DOMComment.prototype, {
+    get xml(){
+        return &quot;&lt;!-- &quot; + this.nodeValue + &quot; --&gt;&quot;;
+    },
+    toString : function(){
+        return &quot;Comment #&quot;+this._id;
+    }
+});</diff>
      <filename>src/dom/comment.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,11 @@
-$log(&quot;Defining DocumentType&quot;);
-;/*
-* DocumentType - DOM Level 2
-*/
-$w.__defineGetter__('DocumentType', function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
+$log(&quot;Defining DocumentType&quot;);
+;/*
+* DocumentType - DOM Level 2
+*/
+$w.__defineGetter__('DocumentType', function(){
+  return function(){
+    throw new Error(&quot;Object cannot be created in this context&quot;);
+  };
+});
+
 var DOMDocumentType    = function() { $error(&quot;DOMDocumentType.constructor(): Not Implemented&quot;   ); };
\ No newline at end of file</diff>
      <filename>src/dom/doctype.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,380 +1,380 @@
-$log(&quot;Defining Document&quot;);
-/*
-* Document - DOM Level 2
-*  The Document object is not directly 
-*/
-$w.__defineGetter__('Document', function(){
-  return function(){
-    throw new Error(&quot;Object cannot be created in this context&quot;);
-  };
-});
-
-
-/**
- * @class  DOMDocument - The Document interface represents the entire HTML or XML document.
- *   Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
- *
- * @extends DOMNode
- * @author Jon van Noort (jon@webarcana.com.au)
- * @param  implementation : DOMImplementation - the creator Implementation
- */
-var DOMDocument = function(implementation) {
-    //$log(&quot;\tcreating dom document&quot;);
-    this.DOMNode = DOMNode;
-    this.DOMNode(this);
-    
-    this.doctype = null;                  // The Document Type Declaration (see DocumentType) associated with this document
-    this.implementation = implementation; // The DOMImplementation object that handles this document.
-    this.documentElement = null;          // This is a convenience attribute that allows direct access to the child node that is the root element of the document
-    //this.all  = new Array();                       // The list of all Elements
-    
-    this.nodeName  = &quot;#document&quot;;
-    this.nodeType = DOMNode.DOCUMENT_NODE;
-    this._id = 0;
-    this._lastId = 0;
-    this._parseComplete = false;                   // initially false, set to true by parser
-    this._url = &quot;&quot;;
-    
-    this.ownerDocument = this;
-    
-    this._performingImportNodeOperation = false;
-    //$log(&quot;\tfinished creating dom document &quot; + this);
-};
-DOMDocument.prototype = new DOMNode;
-__extend__(DOMDocument.prototype, {
-	addEventListener        : window.addEventListener,
-	removeEventListener     : window.removeEventListener,
-    attachEvent             : window.addEventListener,/*IE only subject to deprecation*/
-    detachEvent             : window.detachEvent,/*IE only subject to  deprecation*/
-	dispatchEvent           : window.dispatchEvent,
-    get styleSheets(){ 
-        return [];/*TODO*/ 
-    },
-    get all(){
-        return this.getElementsByTagName(&quot;*&quot;);
-    },
-    loadXML : function(xmlStr) {
-        // create SAX Parser
-        var parser;
-        
-        try {
-            parser = new XMLP(String(xmlStr));
-        }catch (e) {
-            $error(&quot;Error Creating the SAX Parser. \n\n\t&quot;+e+&quot;\n\n\t Did you include xmlsax.js or tinyxmlsax.js\
-                     in your web page?\nThe SAX parser is needed to populate XML for &lt;SCRIPT&gt;'s \
-                     W3C DOM Parser with data.&quot;);
-        }
-        // create DOM Document
-        var doc = new HTMLDocument(this.implementation);
-        // populate Document with Parsed Nodes
-        try {
-            __parseLoop__(this.implementation, doc, parser);
-        } catch (e) {
-            $error(this.implementation.translateErrCode(e.code))
-        }
-
-        // set parseComplete flag, (Some validation Rules are relaxed if this is false)
-        doc._parseComplete = true;
-        if(this === $document){
-            $log(&quot;Setting internal window.document&quot;);
-            $document = doc;
-        }
-        return doc;
-    },
-    load: function(url){
-		$log(&quot;Loading url into DOM Document: &quot;+ url + &quot; - (Asynch? &quot;+$w.document.async+&quot;)&quot;);
-        var _this = this;
-        var xhr = new XMLHttpRequest();
-        xhr.open(&quot;GET&quot;, url, $w.document.async);
-        xhr.onreadystatechange = function(){
-            try{
-        	    _this.loadXML(xhr.responseText);
-            }catch(e){
-                $error(&quot;Error Parsing XML - &quot;,e);
-                _this.loadXML(
-                &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&quot;+
-                    &quot;&lt;h1&gt;Parse Error&lt;/h1&gt;&quot;+
-                    &quot;&lt;p&gt;&quot;+e.toString()+&quot;&lt;/p&gt;&quot;+  
-                &quot;&lt;/body&gt;&lt;/html&gt;&quot;);
-            }
-            $env.loadScripts();
-            _this._url = url;
-        	$log(&quot;Sucessfully loaded document.&quot;);
-        	var event = document.createEvent();
-        	event.initEvent(&quot;load&quot;);
-        	$w.dispatchEvent( event );
-        };
-        xhr.send();
-    },
-	createEvent             : function(eventType){ 
-        var event;
-        if(eventType === &quot;UIEvents&quot;){ event = new UIEvent();}
-        else if(eventType === &quot;MouseEvents&quot;){ event = new MouseEvent();}
-        else{ event = new Event(); } 
-        return event;
-    },
-    createExpression        : function(xpath, nsuriMap){ 
-        return null;/*TODO*/
-    },
-    createElement : function(tagName) {
-        //$log(&quot;DOMDocument.createElement( &quot;+tagName+&quot; )&quot;);
-          // throw Exception if the tagName string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(tagName))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMElement specifying 'this' as ownerDocument
-          var node = new DOMElement(this);
-        
-          // assign values to properties (and aliases)
-          node.tagName  = tagName;
-          node.nodeName = tagName;
-        
-          // add Element to 'all' collection
-          //this.all[this.all.length] = node;
-          //$log(&quot;Document.all.length &quot; + this.all.length);
-        
-          return node;
-    },
-    createDocumentFragment : function() {
-          // create DOMDocumentFragment specifying 'this' as ownerDocument
-          var node = new DOMDocumentFragment(this);
-        
-          return node;
-    },
-    createTextNode: function(data) {
-          // create DOMText specifying 'this' as ownerDocument
-          var node = new DOMText(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createComment : function(data) {
-          // create DOMComment specifying 'this' as ownerDocument
-          var node = new DOMComment(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createCDATASection : function(data) {
-          // create DOMCDATASection specifying 'this' as ownerDocument
-          var node = new DOMCDATASection(this);
-        
-          // assign values to properties (and aliases)
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createProcessingInstruction : function(target, data) {
-          // throw Exception if the target string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(target))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMProcessingInstruction specifying 'this' as ownerDocument
-          var node = new DOMProcessingInstruction(this);
-        
-          // assign values to properties (and aliases)
-          node.target    = target;
-          node.nodeName  = target;
-          node.data      = data;
-          node.nodeValue = data;
-        
-          // set initial length
-          node.length    = data.length;
-        
-          return node;
-    },
-    createAttribute : function(name) {
-          // throw Exception if the name string contains an illegal character
-          if (this.ownerDocument.implementation.errorChecking &amp;&amp; (!__isValidName__(name))) {
-            throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-          }
-        
-          // create DOMAttr specifying 'this' as ownerDocument
-          var node = new DOMAttr(this);
-        
-          // assign values to properties (and aliases)
-          node.name     = name;
-          node.nodeName = name;
-        
-          return node;
-    },
-    createElementNS : function(namespaceURI, qualifiedName) {
-        //$log(&quot;DOMDocument.createElement( &quot;+namespaceURI+&quot;, &quot;+qualifiedName+&quot; )&quot;);
-          // test for exceptions
-          if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if the Namespace is invalid
-            if (!__isValidNamespace__(this, namespaceURI, qualifiedName)) {
-              throw(new DOMException(DOMException.NAMESPACE_ERR));
-            }
-        
-            // throw Exception if the qualifiedName string contains an illegal character
-            if (!__isValidName__(qualifiedName)) {
-              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-            }
-          }
-        
-          // create DOMElement specifying 'this' as ownerDocument
-          var node  = new DOMElement(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.namespaceURI = namespaceURI;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.tagName      = qualifiedName;
-        
-          // add Element to 'all' collection
-          //this.all[this.all.length] = node;
-        
-          return node;
-    },
-    createAttributeNS : function(namespaceURI, qualifiedName) {
-          // test for exceptions
-          if (this.ownerDocument.implementation.errorChecking) {
-            // throw Exception if the Namespace is invalid
-            if (!__isValidNamespace__(this, namespaceURI, qualifiedName, true)) {
-              throw(new DOMException(DOMException.NAMESPACE_ERR));
-            }
-        
-            // throw Exception if the qualifiedName string contains an illegal character
-            if (!__isValidName__(qualifiedName)) {
-              throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
-            }
-          }
-        
-          // create DOMAttr specifying 'this' as ownerDocument
-          var node  = new DOMAttr(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.namespaceURI = namespaceURI;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.name         = qualifiedName;
-          node.nodeValue    = &quot;&quot;;
-        
-          return node;
-    },
-    createNamespace : function(qualifiedName) {
-          // create DOMNamespace specifying 'this' as ownerDocument
-          var node  = new DOMNamespace(this);
-          var qname = __parseQName__(qualifiedName);
-        
-          // assign values to properties (and aliases)
-          node.nodeName     = qualifiedName;
-          node.prefix       = qname.prefix;
-          node.localName    = qname.localName;
-          node.name         = qualifiedName;
-          node.nodeValue    = &quot;&quot;;
-        
-          return node;
-    },
-    getElementById : function(elementId) {
-          var retNode = null,
-              node;
-          // loop through all Elements in the 'all' collection
-          var all = this.all;
-          for (var i=0; i &lt; all.length; i++) {
-            node = all[i];
-            // if id matches &amp; node is alive (ie, connected (in)directly to the documentElement)
-            if (node.id == elementId) {
-                if((node.ownerDocument.documentElement._id == this.documentElement._id)){
-                    retNode = node;
-                    //$log(&quot;Found node with id = &quot; + node.id);
-                    break;
-                }
-            }
-          }
-          
-          if(retNode == null){$log(&quot;Couldn't find id &quot; + elementId);}
-          return retNode;
-    },
-    normalizeDocument: function(){
-	    this.