function createAjaxObject() { 
   var req; 
   if (typeof XMLHttpRequest!='undefined'){ 
      // Firefox, Safari, Opera, IE7+... 
      req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { 
      // Internet Explorer 5, 6 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
//   } else { 
//      alert('Problem creating the XMLHttpRequest object'); 
   } 
   return req;
}

function statusLoading() {
	var status = document.getElementById("ajaxstatus");
	status.innerHTML = '<img src="'+siteRoot+'Images/ajax-loader.gif" alt="Laden..." />';
	if (document.defaultView) statusBackground = document.defaultView.getComputedStyle(status,null);
	if (statusBackground) statusBackground = statusBackground.getPropertyValue('background-color');
	status.style.backgroundColor = "transparent";	
	status.style.visibility = "visible";
}

function statusText(text) {
	var status = document.getElementById("ajaxstatus");
	status.innerHTML = text;
	if (statusBackground != '') status.style.backgroundColor  = statusBackground;
	status.style.visibility = "visible";
}

function statusHide() {
	var status = document.getElementById("ajaxstatus");
	status.innerHTML = '';
	status.style.visibility = "hidden";
}

function getViaAjax(url, callback) {
// Create a new object each time, to prevent conflicting requests
	var http = createAjaxObject(); 
	statusLoading();
	if (http) {
		var ran_no=(Math.round((Math.random()*9999))); 
		http.open('get', url+'&ran='+ran_no);
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
				var httpstatus = http.status;
			  	if (httpstatus == 200) { 
	      				var response = http.responseText;
	      				if(response) { 
						statusText('OK');
						callback(http.responseText); 
						statusHide();
   					} else {
						statusText('<div class="error">Fout: geen data</div>');
					}	 
 				} else {
					statusText('<div class="error">Fout: serverfout ('+httpstatus+')</div>');
				}
			}
		} 
   		http.send(null); 
	} else {
		statusText('<div class="error">Fout: geen connectie</div>');
	}
}

// Make the XMLHttpRequest object 
// var http = createAjaxObject(); 
var statusBackground = '';
