/*	Generic AJAX reader implementation
	2005-09-12, Johan Weitner at Mogul 
	Usage: Call ajaxRead(file,callback,dialog), where: 
	"file" is the file that should provide the needed data, 
	"callback" is the name of the method that should handle the retrieved data, 
	"target" is the target element for the data, and 
	"dialog" (optional) is the id of the dialog element
*/
  
function ajaxRead(file,callback,target,dialog) {
// XMLHttpRequest constructor
var xmlObj;
if(window.XMLHttpRequest) { 
	xmlObj = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
} else {
	return;
}

if(dialog) document.getElementById(dialog).style.visibility = "visible";

// Callback handler
xmlObj.onreadystatechange = function() {
	if(xmlObj.readyState == 4) {
		if (xmlObj.status == 200) eval(callback+"(xmlObj,target,dialog)");
		else {
			if(document.getElementById(dialog)) document.getElementById("loading").style.visibility = "hidden";
			alert("Data could not be retrieved. Error code: " + xmlObj.status);
		}
	}
}

// Request
try {
	xmlObj.open ('GET', file, true);
	xmlObj.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
	xmlObj.send (null); // Method call needed to trig the onreadystatechange handler above
	} 
catch(e) { 
	if(dialog) document.getElementById(dialog).style.visibility = "hidden"; 
	alert("Request could not be made... \nMalformed URL?"); 
	}
}



