﻿	var ie5 = document.all && document.getElementById;
	var hasXPath = document.implementation.hasFeature("XPath", "3.0");
	var mil = 0;
	
	function ajaxReadWithCallBack(file, callbackFunction, arg)
	{
		var xmlObj = null;
		if (window.XMLHttpRequest)
		{
			xmlObj = new XMLHttpRequest();
		} 
		else if(window.ActiveXObject)
		{
			xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		else {
			return;
		}

		xmlObj.onreadystatechange = function()
		{
			if(xmlObj.readyState == 4) 
			{
				//document.getElementById("loadingInfo").innerHTML += "<br/>" + (new Date().valueOf() - mil)+ "<br/>";
				callbackFunction(xmlObj.responseXML, arg);
			}
		}
		
		xmlObj.open ('GET', file, true);
		mil= new Date().valueOf();
		xmlObj.send ('');
		
	}
	
	function ajaxWriteWithCallBack(file, data, callbackFunction)
	{
		var xmlObj = null;
		if (window.XMLHttpRequest)
		{
			xmlObj = new XMLHttpRequest();
		} 
		else if(window.ActiveXObject)
		{
			xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		else 
		{
			return;
		}

		xmlObj.onreadystatechange = function()
		{
			if(xmlObj.readyState == 4) 
			{
				callbackFunction(xmlObj.responseXML);
			}
		}
		
		var seed = Math.round(Math.random() * 1000000);
		file += (file.indexOf("?") != -1) ? "&seed=" + seed : "?seed=" + seed;
			
		xmlObj.open ('POST', file, true);
		xmlObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlObj.setRequestHeader("Content-length", data.length);
		xmlObj.setRequestHeader("Connection", "close");

		xmlObj.send(data);
		
	}
	
	function ajaxRead(file)
	{
	
		var xmlObj = null;
		if (window.XMLHttpRequest){
			xmlObj = new XMLHttpRequest();
		} else if(window.ActiveXObject){
			xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			return;
		}

		xmlObj.open ('GET', file, true);
		xmlObj.send ('');
	}

	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;
		}
		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;
			}
		}

		Element.prototype.selectNodes = function(cXPathString)
		{
			if(this.ownerDocument.selectNodes)
			{
				return this.ownerDocument.selectNodes(cXPathString, this);
			}
			else{throw "For XML Elements Only";}
		}

		Element.prototype.selectSingleNode = function(cXPathString)
		{	
			if(this.ownerDocument.selectSingleNode)
			{
				return this.ownerDocument.selectSingleNode(cXPathString, this);
			}
			else{throw "For XML Elements Only";}
		}

	}
	
	
	