// eenvoudige ajax implementatie - zie verder simpleAjax.aspx
var aspx = 'simpleAjax.aspx?';
var resultSeparator = 'fd72s(a9hnrkwel;hiogp!54rewsrt';


var xmlHttp;
var customCallBack;

function simpleAjax(params, callBack)
{
		customCallBack = callBack;
		
		/* using "object sniffing" to detect major browsers:
	   true on window.XMLHttpRequest denotes a Gecko browser,
	   and true on window.ActiveXObject indicates MS Internet Explorer. */
		if (window.XMLHttpRequest)
		{
			xmlHttp = new XMLHttpRequest();
			/* Assign the onload event-handling function. This function is called
			   when the data has completely loaded into the xmlHttp object. */
			xmlHttp.onload = simpleAjax_callBack;
			xmlHttp.onreadystatechange = simpleAjax_callBack; // voor IE7

		}
		else if (window.ActiveXObject)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			xmlHttp.onreadystatechange = simpleAjax_callBack;
		}
		else
		{
			alert('Fout bij HttpRequest.');
			return '';
		}

		var timestamp = new Date();
		var url = aspx + "timestamp=" + escape(timestamp) + "&" + params;
		xmlHttp.open("GET", url, true);
		
		showLoading(true);
		xmlHttp.send(null);
}

function simpleAjax_callBack()
{
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		var result;
		
		showLoading(false);	
		result = xmlHttp.responseText;

		if (result.substring(0, 4) == 'FOUT')
		{
  			alert(result);
  			customCallBack('');
		}
		else {
			if (result.indexOf(resultSeparator) < 0)
				customCallBack(result);
			else
				customCallBack(result.split(resultSeparator));
		}
	}
}

function showLoading(show)
{
	var loadingElement = document.getElementById("simpleAjaxLoadingElement");
	if (!loadingElement)
	{
		createLoadingElement();
		loadingElement = document.getElementById("simpleAjaxLoadingElement");
	}
	
	if (loadingElement)
	{
		if (show) {
			loadingElement.style.top = document.body.scrollTop;
			loadingElement.style.left = document.body.scrollLeft;
			loadingElement.style.visibility = "visible";
		}
		else
			loadingElement.style.visibility = "hidden";
	}
}

function createLoadingElement()
{
	var e = document.createElement('div');
	e.id = "simpleAjaxLoadingElement";
	e.style.visibility = "hidden";
	e.style.position = "absolute";
	e.style.left = "0px";
	e.style.top = "0px";
	e.style.backgroundColor = "Red";
	e.style.color = "White";
	e.style.fontFamily = "Arial";
	e.style.fontWeight = "bold";
	e.style.padding = "5px";
	e.innerHTML = 'Bezig met laden...';
	document.body.appendChild(e);
}