/*************************************************
 * Created by Hedde Bosman aka Tex-nd            *
 * Free to copy under the GPL license            *
 * ( http://www.gnu.org/copyleft/gpl.html )      *
 *************************************************/

/******************
 * creating the xmlHttpRequest object
 * from w3schools.com
 *****/
function createXmlHttpReq() {
var xmlhttp = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

// some indication of activity...
var numRel = 0;
function pushRel() {
	numRel++;
//	if (numRel > 0)
//		setVisibility("loading", true);
}
function popRel() {
	numRel--;
	if (numRel <= 0) {
//		setVisibility("loading", false);
		numRel = 0;
	}
}

/******************
 * retrieve a given URL and set the handler;
 *****/
function getURL(url, fPtr, cls) {
	var xmlhttp = false;
	xmlhttp = createXmlHttpReq();
	
	if (xmlhttp) {
		pushRel();
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var mtxt = xmlhttp.responseText;
				var mxml = null;
				if (xmlhttp.status == 200) {
					if (xmlhttp.responseXML != undefined) {
						mxml = xmlhttp.responseXML.documentElement;
					}
				} else {
				    if (xmlhttp.status != 0) // tot nu toe alleen 0 wanneer request nog bezig is (geen response) terwijl je al een andere link aanklikt (of stop)
					alert("Error, or server unreachable.\nRequest: "+url+" \nstatus: "+xmlhttp.status+", text:\n"+xmlhttp.responseText);
					mtxt = null;
					mxml = null;
				}
				if (cls != undefined && cls != null) {
					fPtr.call(cls, mtxt, mxml);
				} else {
					fPtr(mtxt, mxml);
				}
				popRel();
			}
		}
		xmlhttp.send(null)
	} else {
		return false;
	}
	return true;
}


