// AJAXLib v. 1.0
// author: Jacek Karaszewski, http://www.karaszewski.com/tools/ajaxlib/
// licenced under Creative Commons Attribution 2.5 License
// This script has been rebuild into an object by P. Dudink on februari 27th, 2009

// public

// function loadXMLDoc(xml_url, function_name, ignore_white)
function loadXMLDoc() {
	this.loadXMLDoc = function(url, callFunc, ignoreWhite) {
		self.functionToCall = callFunc;
		self.stripWS = ignoreWhite;
		self.xmlRequestObj = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")
		self.xmlRequestObj.onreadystatechange = this.processXML;
		self.xmlRequestObj.open("GET", url, true);
		self.xmlRequestObj.send(null);
	}
	
	
	// private
	
	self.is_ws = function(nod) {
		return !(/[^\t\n\r ]/.test(nod.data));
	}
	
	self.findWhiteSpace = function(node, nodeNo) {
		for (i=0; i<node.childNodes.length; i++) {
			if (node.childNodes[i].nodeType == 3 && is_ws(node.childNodes[i])) {
				nodesToDelete[nodesToDelete.length] = node.childNodes[i]
			}
			if (node.childNodes[i].hasChildNodes()) {
				self.findWhiteSpace(node.childNodes[i], i);
			}
		}
		node = node.parentNode;
		i = nodeNo;
	}
	
	self.stripWhiteSpace = function(node) {
		nodesToDelete = Array();
		self.findWhiteSpace(node, 0);
		for(i=nodesToDelete.length-1;i>=0;i--) {
			nodeRef = nodesToDelete[i];
			nodeRef.parentNode.removeChild(nodeRef)
		}
	}
	
	this.processXML = function() {
		if (self.xmlRequestObj.readyState == 4 && (self.xmlRequestObj.status == 200 || self.xmlRequestObj.status == 304)) {
			if(self.stripWS) {
				self.stripWhiteSpace(self.xmlRequestObj.responseXML);
			}
			functionToCall(self.xmlRequestObj.responseXML);
		}
	}
}
