if( document.implementation.hasFeature("XPath", "3.0") ) // in case of Gecko/Mozillas family
{ 
	XMLDocument.prototype.selectNodes = function(senderXPath, senderNode)
	{
		if( !senderNode ) 
		{
			senderNode = this;
		}
    
		var defaultNS = this.defaultNS;

		var possibleResultants = this.evaluate(senderXPath, senderNode,
		{
		normalResolver:
			this.createNSResolver((document ? document : this).documentElement),
				lookupNamespaceURI : function (prefix) 
				{
					switch (prefix) {
						case "dflt":	return defaultNS;
						default:		return this.normalResolver.lookupNamespaceURI(prefix);
					}
				}
			},XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);

		var resultantNodes = [];
		
		for( var i = 0; i < possibleResultants.snapshotLength; i++)
			resultantNodes[i] =  possibleResultants.snapshotItem(i);
		
		return resultantNodes;
	}

	XMLDocument.prototype.selectSingleNodeWWE = XMLDocument.prototype.selectSingleNode = function(senderXPath, senderNode)
	{
		if( !senderNode ) 
  			senderNode = this;
		    
		var defaultNS = this.defaultNS;

		var possibleResultants = this.evaluate(senderXPath, senderNode,
		{
		normalResolver:
			this.createNSResolver(document.documentElement),
				lookupNamespaceURI : function (prefix) 
				{
					switch (prefix) 
					{
						case "dflt":
							return defaultNS;
						default:
							return this.normalResolver.lookupNamespaceURI(prefix);
					}
				}
			},XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);

		return possibleResultants.snapshotItem(0);;
	}

	Element.prototype.selectNodes = function(senderXPath)
	{
		if(this.ownerDocument.selectNodes)
			return this.ownerDocument.selectNodes(senderXPath, this);
		else
			throw "AdCenterXPathException in selectNodes for expression "+senderXPath;
	}

    Element.prototype.selectSingleNode = function (xpath)
    {
        if (this.ownerDocument.selectSingleNode)
        {
            return this.ownerDocument.selectSingleNode(xpath, this);
        }
        else
        {
            var r = this.ownerDocument.createNSResolver(this.ownerDocument.documentElement);
            var nodes = this.ownerDocument.evaluate(xpath, this, r, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
            if (nodes && nodes.snapshotLength > 0)
            {
                return nodes.snapshotItem(0);
            }
        }
        return null;
    }
    
    XMLDocument.prototype.transformNodeToHtml = function (XslDocumentPath)
    {
        var HtmlText  = null;	
	    if (XslDocumentPath != null)
		{
			try{
				HtmlText = XslTransform(this, XslDocumentPath);			
			}
			catch(Err){
				alert(Err);
			}
	    }
		return HtmlText;
    }    
    
    
    Element.prototype.transformNodeToHtml = function (XslDocumentPath)
    {
       var HtmlText  = null;	
	    if (XslDocumentPath != null)
		{
			try{
				HtmlText = XslTransform(this, XslDocumentPath);			
			}
			catch(Err){
				alert(Err);
			}
	    }
		return HtmlText;
    }
    
    
    XMLDocument.prototype.setProperty = function(p,v)
	{
		if(p=="SelectionNamespaces" && v.indexOf("xmlns:dflt")==0)
		{
			this.defaultNS = v.replace(/^.*=\'(.+)\'/,"$1");
		}
	}

	XMLDocument.prototype.defaultNS;

	XMLDocument.prototype.__defineGetter__("xml", function () {
		return new XMLSerializer().serializeToString(this);		
	}); 
	
	Element.prototype.__defineGetter__("xml", function () {
		return new XMLSerializer().serializeToString(this);		
	}); 

	
	//Method to get the expanded attributes (one which is specified with a .) of an element. If 
	//an expanded attrbute is not found, it will check in the attributes collection
	Element.prototype.getXpAttribute = function(AttrName)
	{
		var AttrValue = null;
		if(AttrName){
			AttrValue = eval('this.' + AttrName);
			if(!AttrValue){
				AttrValue = this.getAttribute(AttrName);
			}
			
			if(AttrValue){
				AttrValue = AttrValue.toString();
			}	
		}			
		return AttrValue;
	}
	
	//Function to load an XmlDocument from xml text
	function loadXmlDocumentFromText(XmlText)
    {
		var NewXmlDocument;
		try{
			var parser		= new DOMParser(); 
			NewXmlDocument	= parser.parseFromString(XmlText, "text/xml"); 
		}
		catch(Err){
			alert(Err);
		}		
		return NewXmlDocument;
    }    
	
	
	//Function to transform an xml object using the given xsl sheet
	function XslTransform(XmlDocumentObject, XslDocumentPath){
		var TransHTML  = null;
		
		if ((XmlDocumentObject != null) && (XslDocumentPath != null) && (document.implementation) && (document.implementation.createDocument))
		{
			var xsl = document.implementation.createDocument("", "", null);
			xsl.async = false;
			xsl.load(XslDocumentPath);
	        
			var GridXSL = new XSLTProcessor();
			GridXSL.importStylesheet(xsl);
	        
			GridXSL.apply_to = function (x)
			{
				var s = new XMLSerializer();
				return s.serializeToString(this.transformToDocument(x));
			}
	        
			TransHTML = GridXSL.apply_to(XmlDocumentObject);
			return TransHTML;
		}
	}
}