/*****************************************************************************************
          Script to import XML data files and make them available to JavaScript
                     v2.0.3 written by Mark Wilton-Jones, 13/04/2004
Updated 02/07/2004 to provide native Safari 1.2 and Opera 7.6 support using XMLHttpRequest
                   Updated 24/07/2004 to prevent a Safari caching bug
      Updated 02/10/2004 to include support for older Internet Explorer XML objects
 Updated 09/11/2004 to allow a delay for better response in browsers that use the iframe
*******************************************************************************************/
//CS added URL to pass to Funct
var ldD = [];

function importXML( URL, Funct, NoRand, Delay ) {
	//note: in XML importing event handlers, 'this' refers to window
	if( !NoRand ) { URL += ( ( URL.indexOf('?') + 1 ) ? '&' : '?' ) + ( new Date() ).getTime(); } //prevent cache
	if( window.XMLHttpRequest ) {
		//alternate XMLHTTP request - Gecko, Safari 1.2+ and Opera 7.6+
		ldD[ldD.length] = new XMLHttpRequest();
		ldD[ldD.length-1].onreadystatechange = new Function( 'if( ldD['+(ldD.length-1)+'].readyState == 4 && ldD['+(ldD.length-1)+'].status < 300 ) { '+Funct+'(ldD['+(ldD.length-1)+'].responseXML, "'+URL+'"); }' );
		//Added CS, need to send URL to new function
		ldD[ldD.length-1].open("GET", URL, true);
		ldD[ldD.length-1].send(null);
		return true;
	}
	if( !navigator.__ice_version && window.ActiveXObject ) {
		//the Microsoft way - IE 5+/Win (ICE produces errors and fails to use try-catch correctly)
		try { //IE Mac has the property window.ActiveXObject but produces errors if you try and use it
			try { var tho = new ActiveXObject( 'Microsoft.XMLDOM' ); //newer
			} catch(e) { var tho = new ActiveXObject( 'Msxml2.XMLHTTP' ); } //older
			ldD[ldD.length] = tho;
			ldD[ldD.length-1].onreadystatechange = new Function( 'if( ldD['+(ldD.length-1)+'].readyState == 4 ) { '+Funct+'(ldD['+(ldD.length-1)+'], "'+URL+'"); }' );
			ldD[ldD.length-1].load(URL);
			return true;
		} catch(e) {}
	}
	if( document.createElement && document.childNodes ) {
		//load the XML in an iframe
		var ifr = document.createElement('DIV');
		ifr.style.visibility = 'hidden'; ifr.style.position = 'absolute'; ifr.style.top = '0px'; ifr.style.left = '0px';
		//onload only fires in Opera so I use a timer for all
		if( !window.XML_timer ) { window.XML_timer = window.setInterval('checkXMLLoad();',100); }
		ifr.innerHTML = '<iframe src="'+URL+'" name="XML_loader_'+ldD.length+'" height="0" width="0"><\/iframe>';
		ldD[ldD.length] = Funct+'SPLIT'+(Delay?Delay:1), "'+URL+'"+'';
		document.body.appendChild(ifr);
		return true;
	}
	return false;
}
function checkXMLLoad() {
	//check if each imported file is available (huge files may not have loaded completely - nothing I can do - use the delay to help)
	for( var x = 0; x < ldD.length; x++ ) { if( ldD[x] && window.frames['XML_loader_'+x] ) {
		setTimeout( ldD[x].split('SPLIT')[0] + '(window.frames.XML_loader_'+x+'.window.document);', parseInt(ldD[x].split('SPLIT')[1]) );
		ldD[x] = false;
	} }
}

