var getTransferObject = function(){	return null;	};
if(window.ActiveXObject){
	// Check if the browser has support for ActiveXObject (IE Usually)  
	try{ 
		// Check for the new version of XMLHttp compoment  
		var x=  new ActiveXObject("MSXML2.XMLHTTP"); 
		getTransferObject = function(){ return new ActiveXObject("MSXML2.XMLHTTP"); }
	}catch(_ex){ 
		try{ // Check for late version of XMLHTTP compoment  
			var x = new ActiveXObject("Microsoft.XMLHTTP"); 
			getTransferObject = function(){ return new ActiveXObject("Microsoft.XMLHTTP"); }
		}catch(ex){
			// Otherwise the version of IE is too old  
		} 
	} 
}else if(window.XMLHttpRequest){
	// XMLHttpRequest object supported by Opera, Firefox and Safari - may too in IE 7.  
	getTransferObject = function(){ return new XMLHttpRequest(); }
}

/*
	* make an "Ajax Request".
	* @params: 
		- url : contains the target of the request.
		- params: Hash Table that contains a data that send with the request.
		- aOptions: Associative array that contains an optional property: method of sendinge, 
			2 optional function: 
				- onSuccess(param: RequestObject): will dispatch when the request get a "true" response (status-code=200)
				- onFailure(param: RequestObject): will dispatch when the request get a "false" response (status=code isn't 200)
			and an Hash Table of http headers named: httpHeaders
*/
function doAjaxRequest(url, params, aOptions){
	// get transfer object
	var oReq = getTransferObject();
	if(!oReq){
		// Check for XMLHttpRequest
		throw "Download the newer Firefox or upgrade your browser please.";
		return false;
	}

	// Add HTTP headers to the message
	for(var header in aOptions.httpHeaders){
		oReq.setRequestHeader(header,aOptions.httpHeaders[header]);
	}

	oReq.onreadystatechange = function(){
		if(oReq.readyState==4){
			if(oReq.status==200){
				if(aOptions.onSuccess) aOptions.onSuccess(oReq);
			}else{
				if(aOptions.onFailure) aOptions.onFailure(oReq);
			}
		}
	}

	// make parameters string
	var _params = [];
	for(var p in params){
		_params.push(p+"="+encodeURIComponent(params[p]));
	}
	_params = _params.join("&");

	// Default send method: GET
	var method = aOptions.method?aOptions.method:"GET",
		bodyPost= null;


	if(method=="POST"){
		oReq.open(method, url, true);
		oReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		bodyPost = _params; // POST data send into the request
	}else{
		oReq.open(method, url+"?"+_params, true); // GET data send as part of the url
	}
	//send request
	oReq.send(bodyPost);
}