
/* =================================================
	Common AJAX javascript functions
	include this file on AJAX caller pages
================================================== */

// Makes XML Instance  
function AjaxInstance(){  
  var A=null;  
  try{A=new ActiveXObject("Msxml2.XMLHTTP")  
  }catch(e){ try{ A=new ActiveXObject("Microsoft.XMLHTTP")  
    } catch(oc){ A=null  // No XML Available  
	 }  }  
  if(!A && typeof XMLHttpRequest != "undefined") { A=new XMLHttpRequest() }  
  return A  
}  
  
/* ---------------------------------------------------------------------
	Calls AJAX 
	
	Url = the URL to be called (incl. request data)
	the iFrame escape is not implemented here
	
	iProcessType = type of processing to take place
	iProcessType = 1 : tries eval of response.Text
	iProcessType = 2: sets innerHTML of element with certain ID to response.Text
	sId : Id of element of which innerHTML is set with iProcessType = 2
	iProcessType = 3: variable xmlResult is filled with responseXML.documentElement
------------------------------------------------------------------------------ */
function AjaxCall(Url, iProcessType, sId){  
	instXML = AjaxInstance()  
	if (instXML) {  
	 	Url = Url + '&XML=1'; // Mark this as an XML call  
	 	instXML.open("GET", Url,true); 
		instXML.onreadystatechange = function () {  
			if (instXML.readyState==4) {   
				if (iProcessType == 1) { // eval output
					try {
						eval(instXML.responseText);
					} catch(e) {
						alert('AJaxXML Failed (eval of reponse.Text)');
						//alert is vaak niet genoeg om te ontdekken wat het probleem is!
						alert(instXML.responseText);
						AjaxError = window.open('', 'ajaxerror', '');
						AjaxError.document.write(instXML.responseText);
					}  
				} else if (iProcessType == 2) { // filldiv with output
					if (document.getElementById(sId)) {
						try {
							document.getElementById(sId).innerHTML = instXML.responseText;
						} catch(e) {
							alert('AJaxXML Failed (fill some elements innerHTML with reponse.Text)');
							//alert is vaak niet genoeg om te ontdekken wat het probleem is!
							alert(instXML.responseText);
							AjaxError = window.open('', 'ajaxerror', '');
							AjaxError.document.write(instXML.responseText);
						}
					} else {
						alert('no element found with ID = ' + sId);
					}
				} else if (iProcessType == 3) {//xmlResult filled with xmldataset
					//try {
						processXML();
					//} catch (e) {
					//	alert('AJaxXML Failed (returning xmldataset)');
					//	alert("Er is een fout opgetreden bij het ontvangen van de XML data:\n" + instXML.statusText);
					//}
				} // end if iProcessType
			}  // end if readyState
		}  // end inline function
		instXML.send(null);  
		return true;
		
	 }  else  {   
		//iFrame escape is not implemented
		alert('AJaxXML Failed: no XMLHttpRequest object could be created');
		
	 }  // end if instXML
  
}  


  

