//------------------------------------------------------------------
//	implements xpath...
//------------------------------------------------------------------
if (document.all == null)
{
	 function _normalizeText(sIn) 
	 { 
	  var _WSMULT = new RegExp("^\\s*|\\s*$", "g"); 
	  var _WSENDS = new RegExp("\\s\\s+", "g"); 
	  return sIn.replace(_WSENDS, " ").replace(_WSMULT, " "); 
	 } 

	 // Emulates IE's xml property. Gives an XML serialization of the DOM Object 
	 XMLDocument.prototype.__defineGetter__("xml", function () 
	 { 
	  return (new XMLSerializer()).serializeToString(this); 
	 }); 
	 // Emulates IE's xml property. Gives an XML serialization of the DOM Object 
	 Node.prototype.__defineGetter__("xml", function () 
	 { 
	  return (new XMLSerializer()).serializeToString(this); 
	 }); 
	 // Ensures and informs the xml property is read only 
	 XMLDocument.prototype.__defineSetter__("xml", function () 
	 { 
	  throw "Invalid assignment on read-only property 'xml'. Hint: Use the 'loadXML(String xml)' method instead. (original exception: "+e+")"; 
	 }); 
	 // Emulates IE's innerText (write). Note that this removes all childNodes of // an Element and just replaces it with a textNode 
	 HTMLElement.prototype.__defineSetter__("innerText", function (sText) 
	 { 
	  var s = "" + sText; 
	  this.innerHTML = s.replace(/\&/g, "&amp;").replace(/</g, 
	"&lt;").replace(/>/g, "&gt;"); 
	 }); 
	 // Emulate IE's innerText (read). Gives the concatenation of all text nodes under the Element 
	 HTMLElement.prototype.__defineGetter__("innerText", function () 
	 { 
	  return _normalizeText(this.innerHTML.replace(/<[^>]+>/g,"")); 
	 }); 
	 // Emulates IE's xml property. Gives an XML serialization of the DOM Object 
	 Node.prototype.__defineGetter__("text", function() 
	 { 
	  return _normalizeText( this.xml.replace(/<[^>]+>/g,"") ); 
	 }); 


	 // Extend the Array to behave as a NodeList 
	 Array.prototype.item = function(i) 
	 { 
	  return this[i]; 
	 }; 
	 // add IE's expr property 
	 Array.prototype.expr = ""; 
	 // dummy, used to accept IE's stuff without throwing errors 
	 XMLDocument.prototype.setProperty = function(x,y){}; 

	// check for XPath implementation
	if( document.implementation.hasFeature("XPath", "3.0") )
	{
	   // prototying the XMLDocument
	   XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	   {
		  if( !xNode ) { xNode = this; } 

		  var oNSResolver = this.createNSResolver(this.documentElement);
		  var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
					   XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		  var aResult = [];
		  for( var i = 0; i < aItems.snapshotLength; i++)
		  {
			 aResult[i] =  aItems.snapshotItem(i);
		  }
		  return aResult;
	   }

	   // prototying the Element
	   Element.prototype.selectNodes = function(cXPathString)
	   {
		  if(this.ownerDocument.selectNodes)
		  {
			 return this.ownerDocument.selectNodes(cXPathString, this);
		  }
		  else{throw "For XML Elements Only";}
	   }

	   // prototying the XMLDocument
	   XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	   {

		  if( !xNode ) { xNode = this; } 
		  var xItems = this.selectNodes(cXPathString, xNode);
		  if( xItems.length > 0 )
		  {
			 return xItems[0];
		  }
		  else
		  {
			 return null;
		  }
	   }
	   
	   // prototying the Element
	   Element.prototype.selectSingleNode = function(cXPathString)
	   {	
		  if(this.ownerDocument.selectSingleNode)
		  {
			 return this.ownerDocument.selectSingleNode(cXPathString, this);
		  }
		  else{throw "For XML Elements Only";}
	   }
	}		
}

