﻿if (document.implementation.hasFeature("XPath", "3.0")) {
    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;
    };
    Element.prototype.selectNodes = function(cXPathString) {
        if(this.ownerDocument.selectNodes)
            return this.ownerDocument.selectNodes(cXPathString, this);
        else
            throw "For XML Elements Only";
    };
    HTMLElement.prototype.click = function() {
        var evt = this.ownerDocument.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
        this.dispatchEvent(evt);
    }
    HTMLElement.prototype.insertAdjacentElement = function(where, parsedNode) {
        switch (where){
            case "beforeBegin":
                this.parentNode.insertBefore(parsedNode,this);
                break;
            case "afterBegin":
                this.insertBefore(parsedNode,this.firstChild);
                break;
            case "beforeEnd":
                this.appendChild(parsedNode);
                break;
            case "afterEnd":
                if(this.nextSibling) 
                    this.parentNode.insertBefore(parsedNode,this.nextSibling);
            else
                this.parentNode.appendChild(parsedNode);
                break;
        }
    };
};

