if (!window.ActiveXObject) {

Element.prototype.selectNodes = function(sXPath) {

var oEvaluator = new XPathEvaluator();

var oResult = oEvaluator.evaluate(sXPath, this, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);

var aNodes = new Array();

if (oResult != null) {

var oElement = oResult.iterateNext();

while (oElement) {

aNodes.push(oElement);

oElement = oResult.iterateNext();

}

}

return aNodes;

}

Element.prototype.selectSingleNode = function(sXPath) {

var oEvaluator = new XPathEvaluator();

// FIRST_ORDERED_NODE_TYPE returns the first match to the xpath.

var oResult = oEvaluator.evaluate(sXPath, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);

if (oResult != null) {

return oResult.singleNodeValue;

} else {

return null;

}

}

HTMLTableRowElement.prototype.insertCell=function()

{

var ret=document.createElement("td");

this.appendChild(ret);

return ret;

}

HTMLTableSectionElement.prototype.insertRow=function() {

var ret=document.createElement("tr");

this.appendChild(ret);

return ret;

}

HTMLElement.prototype.__defineGetter__("innerText",

function() {

return this.textContent.replace(/(^\s*)|(\s*$)/g, "");

}

);

HTMLElement.prototype.__defineSetter__("innerText",

function(sText) {

this.textContent = sText;

}

);

HTMLElement.prototype.__defineGetter__("name",

function() {

var name = this.getAttribute("name");

return (name == null ? "" : name);

}

);

// HTMLDocument

// ------------

// support microsoft's "all" property

HTMLDocument.prototype.__defineGetter__("all", function() {

return this.getElementsByTagName("*");

});

// mimic the "createEventObject" method for the document object

HTMLDocument.prototype.createEventObject = function() {

return document.createEvent("Events");

};

HTMLElement.prototype.__defineGetter__("all", function() {

return this.getElementsByTagName("*");

});

// support "parentElement"

HTMLElement.prototype.__defineGetter__("parentElement", function() {

return (this.parentNode == this.ownerDocument) ? null : this.parentNode;

});

// support the "contains" method

HTMLElement.prototype.contains = function($element) {

return Boolean($element == this || ($element && this.contains($element.parentElement)));

};

// Event

// -----

// support microsoft's proprietary event properties

Event.prototype.__defineGetter__("srcElement", function() {

return (this.target.nodeType == Node.ELEMENT_NODE) ? this.target : this.target.parentNode;

});

Event.prototype.__defineGetter__("fromElement", function() {

return (this.type == "mouseover") ? this.relatedTarget : (this.type == "mouseout") ? this.srcElement : null;

});

Event.prototype.__defineGetter__("toElement", function() {

return (this.type == "mouseout") ? this.relatedTarget : (this.type == "mouseover") ? this.srcElement : null;

});

// convert w3c button id's to microsoft's

Event.prototype.__defineGetter__("button", function() {

return (this.which == 1) ? 1 : (this.which == 2) ? 4 : 2;

});

// mimic "returnValue" (default is "true")

Event.prototype.__defineGetter__("returnValue", function() {

return true;

});

Event.prototype.__defineSetter__("returnValue", function($value) {

if (this.cancelable && !$value) {

// this can't be undone!

this.preventDefault();

this.__defineGetter__("returnValue", function() {

return false;

});

}

});

// mozilla already supports the read-only "cancelBubble"

// so we only need to define the setter

Event.prototype.__defineSetter__("cancelBubble", function($value) {

// this can't be undone!

if ($value) this.stopPropagation();

});

Event.prototype.__defineGetter__("offsetX", function() {

return this.layerX;

});

Event.prototype.__defineGetter__("offsetY", function() {

return this.layerY;

});

 

// 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);

// }

}

 

if (window.XPathEvaluator) {

(function() {

if (window.__defineGetter__) {

var stylesheet = CSSStyleSheet.prototype;

delete stylesheet.rules;

stylesheet.__proto__ = { __proto__: stylesheet.__proto__ };

stylesheet.__proto__.__defineGetter__("rules", function() {

return this.cssRules;

});

var text = Text.prototype;

text.__proto__ = { __proto__: text.__proto__ };

text.__proto__.__defineGetter__("text", function() {

return this.nodeValue;

});

var attr = Attr.prototype;

delete attr.text;

attr.__proto__ = { __proto__: attr.__proto__ };

attr.__proto__.__defineGetter__("text", function() {

return this.nodeValue;

});

var element = Element.prototype;

delete element.text;

element.__proto__ = { __proto__: element.__proto__ };

element.__proto__.__defineGetter__("text", function() {

var i, a = [], nodes = this.childNodes, length = nodes.length;

for (i = 0; i < length; i++) {

a[i] = nodes[i].text;

}

return a.join("");

});

}

})();

} 
