var isIE;

// AJAXLib v. 1.0
// author: Jacek Karaszewski, http://www.karaszewski.com/tools/ajaxlib/
// licenced under Creative Commons Attribution 2.5 License

// public

// function loadXMLDoc(xml_url, function_name, ignore_white)


function loadXMLDoc(url,ignoreWhite) {	
	//functionToCall = callFunc;
	stripWS = ignoreWhite;
	
	//xmlRequestObj = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Msxml2.XMLHTTP")//Microsoft.XMLHTTP
	
	if (window.XMLHttpRequest)
		{
			xmlRequestObj = new XMLHttpRequest();
		}
	else{
			xmlRequestObj = new ActiveXObject("Msxml2.XMLHTTP");//Microsoft.XMLHTTP
			isIE = true;
		}
	
	xmlRequestObj.onreadystatechange = proccessXML;
	xmlRequestObj.open("GET", url, true);
	xmlRequestObj.send(null);
/*xmlhttp=null
stripWS = ignoreWhite;
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=proccessXML
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }*/
}


// private

function is_ws(nod) {
	return !(/[^\t\n\r ]/.test(nod.data));
}

function findWhiteSpace(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()) {
			findWhiteSpace(node.childNodes[i], i);
		}
	}
	node = node.parentNode;
	i = nodeNo;
}

function stripWhiteSpace(node) {
	nodesToDelete = Array();
	findWhiteSpace(node, 0);
	for(i=nodesToDelete.length-1;i>=0;i--) {
		nodeRef = nodesToDelete[i];
		nodeRef.parentNode.removeChild(nodeRef);
	}
}

function proccessXML() {
	//xmlRequestObj.responseXML.load(xmlRequestObj.responseStream);
	//if (xmlRequestObj.readyState == 4 && (xmlRequestObj.status == 200 || xmlRequestObj.status == 304)) {
	if (xmlRequestObj.readyState == 4) {
		if(stripWS) {
			stripWhiteSpace(xmlRequestObj.responseXML);
		}		
		resultXML = xmlRequestObj.responseXML;		
		return resultXML;//functionToCall();		
	}
}
