//be careful of the global variables
var xmlDoc =null;
var XMLtimeout=false;
var XMLtimeExpriation=5000; //set expire time to abort. 5 seconds.
var XMLDocLoaded=false;
var XMLID="";
var XMLcount=0;

function loadXML(XMLfile)
{
	if (window.ActiveXObject)
	{
	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	}

	else if (document.implementation!='undefined' && document.implementation.createDocument!='undefined')
	{
	xmlDoc= document.implementation.createDocument("", "", null);
	}

	if (typeof xmlDoc!="undefined")
	xmlDoc.load(XMLfile);

	XMLloadcontrol();
}


function getTree(tagset)
{
//Cache elements of xml file

var nodeSet=xmlDoc.getElementsByTagName(tagset);
nodeSet=XMLRemWhtspc(nodeSet);
return nodeSet;
}

function XMLRemWhtspc(Rootnode)
{
var notWhitespace = /\S/;
//REMOVE white spaces in XML file. Intended mainly for NS6/Mozilla

	for (i=0;i<Rootnode.length;i++)
	{
		if((Rootnode[i].nodeType == 3)&&(!notWhitespace.test(Rootnode[i].nodeValue))) 
		{
		Rootnode[i].removeChild(Rootnode[i]); i--;
		}
	}
return Rootnode;
}


function isXMLLoaded()
{
	if((window.ActiveXObject)&&(xmlDoc.readyState==4))
	{
	XMLDocLoaded=true;
	clearTimeout(XMLID);
	return true;
	}

	else if ((typeof document.implementation!='undefined') && (typeof document.implementation.createDocument!='undefined'))
	{
	XMLDocLoaded=true;
	clearTimeout(XMLID);
	return true;
	}
return false;  
}

function XMLloadcontrol()
{
var ITMAX=3;
	if(XMLDocLoaded)return;
	else
	{
	XMLID = setTimeout("isXMLLoaded()",XMLtimeExpriation); //set abort download time (5 sec).
	XMLID = setTimeout("XMLtimeout=isXMLLoaded()",2000);
	XMLcount++
	}

	if ((!XMLtimeout)&&(XMLcount>ITMAX)){ //if designated time frame has expired
	alert("XML file loading aborted");
	return;
	}
}