var g_objXMLHttp ;
var g_strEventName ;
// strUrl: "myPage.asp?ID=1"
// strMethod: "GET" or "POST"
// strData: use [null] as Data for "GET", otherwise FORM data :"name=marc&gender=male"
// strEventName: "MyFunction(...,RESPONSETEXT)"
function AjaxCallURL( strUrl, strMethod, strData, strEventName ) {
	try	{
		// Moz supports XMLHttpRequest. IE uses ActiveX. Browser detection is bad. object detection works for any browser
		g_objXMLHttp = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e) {
		return 0 ;
	}
 	g_strEventName = strEventName ;
	g_objXMLHttp.onreadystatechange = AjaxReqChange;
	g_objXMLHttp.open(strMethod, strUrl);
	if ( strMethod == "POST" ) g_objXMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	g_objXMLHttp.send(strData);
	return 1 ;
}

function AjaxReqChange() {
	// if the readyState code is 4 (Completed)
	// and http status is 200 (OK) we go ahead and get the responseText
	// other readyState codes: 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
	if ((g_objXMLHttp.readyState == 4) && (g_objXMLHttp.status == 200)) {
		// g_objXMLHttp.responseText object contains the response.
		//eval(g_strEventName+"(g_objXMLHttp.responseText)");
		eval(g_strEventName.replace(/RESPONSETEXT/gi, "g_objXMLHttp.responseText"));
	}
}

function AjaxCallURLSync( strUrl, strMethod, strData ) {
	var objXMLHttp ;
	try	{
		// Moz supports XMLHttpRequest. IE uses ActiveX. Browser detection is bad. object detection works for any browser
		objXMLHttp = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e) {
		return "" ;
	}
	objXMLHttp.open(strMethod, strUrl, false);
	if ( strMethod == "POST" ) objXMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	objXMLHttp.send(strData);
	return objXMLHttp.responseText ;
}
