if (typeof Class == 'undefined') {

	var Class = {
		create: function() {
			return function() { 
				this.initialize.apply(this, arguments); 
			}
		}
	};
	
	$ = function(id) { 
		return (document.getElementById(id.toString())) || null;
	};
	var Ajax = Class.create();
}

Ajax.prototype = {

	// Constructeur

	initialize: function(sUrl, scope) {

		if (scope == undefined) {
			this.scope = window;
		} else {
			this.scope = scope;
		} 

		this.sUrl = sUrl;
		this.oXmlHttp = false;
		this.sVariables = "";
		this.aArguments = [];

		/*@cc_on
		@if(@_jscript_version >= 5)
			try {
				this.oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					this.oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) {
					this.oXmlHttp = false;
				}
			}
		@else
			this.oXmlHttp = false;
		@end @*/
		if(!this.oXmlHttp && typeof XMLHttpRequest != 'undefined') {
			try {
				this.oXmlHttp = new XMLHttpRequest();
			} catch (e) {
				this.oXmlHttp = false;
			}
		}
		if (!this.oXmlHttp) {
			// XMLHttpRequest n'est pas supporte pas le client
		}
	},
	// Envoi
	envoie: function(fonctionRetour) {

		this.fonctionRetour = fonctionRetour;
		this.oXmlHttp.abort();
		this.oXmlHttp.open('POST', this.sUrl, true);
		this.oXmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

		for (var i = 0; i < this.aArguments.length; i++) {
			this.sVariables += "&"+this.aArguments[i].nom+"="+this.aArguments[i].valeur;
		}

		this.oXmlHttp.send(this.sVariables);
		var _this = this;

		this.oXmlHttp.onreadystatechange = function () {
			try {
				if (_this.oXmlHttp.status == 200 && _this.oXmlHttp.readyState == 4) {
					_this.fonctionRetour.apply(_this.scope, [_this.oXmlHttp.responseText]);
				}
			} catch (e) {
				// debug seulement
			}
		}
	},

	// Ajoute
	ajoute: function(nom, valeur) {
		var bExiste = false;
		for (var i = 0; i < this.aArguments.length; i++) {
			if (this.aArguments[i].nom == nom) {
				bExiste = true;
				this.aArguments[i].valeur = valeur;
				break;
			}
			if (i>100) {
				break;
			}
		}
		if (!bExiste) {
			this.aArguments.push( {nom: nom, valeur: valeur} );
		}
	}

};
