/*
File: ajax.js
Purpose: Contains AJAX "Asynchronous JavaScript and XML" functions.  AJAX
         uses the XMLHttpRequest object.
--------------------------------------------------------------------- */
// Global settings
gbAjaxTimeout = -1; //Set to the number of seconds to timeout the request if it doesn't return (-1 don't timeout)
var gfAjaxUserHandler;
var objAjax;

function objGetAjaxHandle() {
  try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {};
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {};
	try { return new XMLHttpRequest(); } catch(e) {};
	try { return new window.createRequest(); } catch(e) {};
  return false;
}

function zAjaxHandler() {
	if (objAjax.readyState == 4) {
		gfAjaxUserHandler();
	}
	return true;
}

function iSendAjaxRequest(fHandler,sURL,sMethod,bASYNC,sUserName,sPassword) {
	objAjax = objGetAjaxHandle();

	if (typeof objAjax != 'object'){
		return false;
	} else {
		try {
		if (typeof sMethod != 'string') {
			sMethod = 'get';
		}
		if (typeof bASYNC != 'number') {
			bASYNC = true;
		}
		if (typeof sUserName != 'string') {
			sUserName = "";
		}
		if (typeof sPassword != 'string') {
			sPassword = "";
		}
		gfAjaxUserHandler = fHandler;
		objAjax.onreadystatechange = zAjaxHandler;
	  objAjax.open(sMethod, sURL, bASYNC, sUserName, sPassword);
	  objAjax.send(null);
	  return true;
	  }
	  catch (e) {
	  	alert('An error was generated trying Ajax : ' + e.description);
	  }
	}
}


