if(!window.event)
{
	window.__defineGetter__("event", function __getEvent__()
	{
		
		var callFunc = __getEvent__.caller;
		while(callFunc)
		{
			var e = callFunc.arguments[0];
			if(e instanceof Event)
				return e;
			
			callFunc = callFunc.caller;			
		}
		return null;
	});
}

if(!Event.srcElement)
Event.prototype.__defineGetter__("srcElement", function() {
	if(this.target.tagName.toLowerCase() == "html")return document.body;
	else return (this.target.nodeType == 3) ? this.target.parentNode : this.target;
});

if(!HTMLElement.innerText)
{
	HTMLElement.prototype.__defineGetter__("innerText", function()
	{
		return this.textContent;	
	});
	HTMLElement.prototype.__defineSetter__("innerText", function(value)
	{
		this.textContent = value;
	});
}


HTMLTableElement.prototype.moveRow = function(iSrc, iTar)
{
	if(iSrc < 0 || iTar < 0 || this.rows[iSrc] == null || this.rows[iTar] ==null)
		throw new Error("Index out of the range at HTMLTableElement.moveRow");

	var parentNode = this.rows[iSrc].parentNode;
	var srcTR = parentNode.removeChild(this.rows[iSrc]);
	if(this.rows[iTar] != null)
	{
		parentNode.insertBefore(srcTR, this.rows[iTar]);
	}
	else
	{
		parentNode.appendChild(srcTR);
	}
};

HTMLElement.prototype.attachEvent = function(funcName, func)
{
	funcName = funcName.replace(/^on/i, "");
	if(typeof func == "function")
	{
		this.addEventListener(funcName, func, false);
	}
}

	XMLDocument.prototype.setProperty  = function(x,y){};
	// Emulate IE's selectNodes
	XMLDocument.prototype.selectNodes = function(sExpr, contextNode)
	{
		var oResult = this.evaluate(sExpr, (contextNode?contextNode:this), 
							this.createNSResolver(this.documentElement),
							XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		var nodeList = new Array(oResult.snapshotLength);
		nodeList.expr = sExpr;
		for(i=0;i<nodeList.length;i++)
			nodeList[i] = oResult.snapshotItem(i);
		return nodeList;
	};
	Element.prototype.selectNodes = function(sExpr)
	{
		var doc = this.ownerDocument;
		if(doc.selectNodes)
			return doc.selectNodes(sExpr, this);
		else
			throw "Method selectNodes is only supported by XML Nodes";
	};

	XMLDocument.prototype.selectSingleNode = function(sExpr, contextNode)
	{
		var ctx = contextNode?contextNode:null;
		sExpr += "[1]";
		var nodeList = this.selectNodes(sExpr, ctx);
		if(nodeList.length > 0)
			return nodeList[0];
		else 
			return null;
	};
	Element.prototype.selectSingleNode = function(sExpr)
	{
		var doc = this.ownerDocument;
		if(doc.selectSingleNode)
			return doc.selectSingleNode(sExpr, this);
		else
			throw new Error("Method selectSingleNode is only supported by XML Nodes. ");
	};

	Element.prototype.__defineGetter__("text", function () {
		return this.textContent;
	});



Document.prototype.transformNode = function(xslDoc)
{
	try
	{
		var xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(xslDoc);
		var xmlDoc = xsltProcessor.transformToFragment(this, document);
		return new XMLSerializer().serializeToString(xmlDoc);
	}
	catch(err)
	{
		throw err;
	}
}