function _BindArguments(fn) {//{{{
  var args = [];
  for (var n = 1; n < arguments.length; n++)
    args.push(arguments[n]);
  return function () { return fn.apply(this, args); };
}
Function.prototype.bind = function() {
	args = new Array();
	args[0] = this;
	for(i=0 ; i<arguments.length ; i++)
		args.push(arguments[i]);
	return _BindArguments.apply(this, args);
}//}}}

function addListener(elem, name, func) {//{{{
	if(elem.addEventListener)
		elem.addEventListener(name, func, false);
	else
		elem.attachEvent('on'+name, func);
}//}}}

function removeListener(elem, name, func) {//{{{
	if(elem.removeEventListener)
		elem.removeEventListener(name, func, false);
	else
		elem.detachEvent('on'+name, func);
}//}}}


function AjaxObject() {//{{{

	this.xhr = null;

	if(window.XMLHttpRequest) // Firefox
		this.xhr = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		this.xhr = new ActiveXObject("Microsoft.XMLHTTP");

	if(this.xhr == null)
		throw "Votre navigateur doit supporter l'AJAX pour utiliser cette fonction.";

	this.methode = "post";
	
	
	this.envoi = function(fichier, donnees, fonction) {

		this.xhr.open(this.methode, fichier, true);
		
		this.xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");

		var args = arguments;
		
		this.xhr.onreadystatechange = function() {
			if(this.readyState == 4) {
				if(args.length == 3)
					fonction(this.responseText);
				else if(args[3] == false)
					fonction(this.responseText);
				else
					fonction(this.responseXML);
			}
		}
		
		this.xhr.send(donnees);

	}
	
	this.envoiSync = function(fichier, donnees) {
	
		this.xhr.open(this.methode, fichier, false);
		
		this.xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		
		this.xhr.send(donnees);
		
		return this.xhr.responseText;

	}

}//}}}

var ajax = {//{{{
	obj: new AjaxObject(),
};
ajax.sync = function(fichier, donnees) {ajax.obj.envoiSync(fichier, donnees);};
ajax.async = function(fichier, donnees, fonction) {
	if(arguments.length == 3)
		ajax.obj.envoi(fichier, donnees, fonction);
	else
		ajax.obj.envoi(fichier, donnees, fonction, arguments[3]);
};//}}}

