
	 
	var reg=new RegExp('(\\+)', 'g');

	function xJAX()
	{
		this.sParams ='';
		this.sTarget='';

		$.ajaxSetup({
			  global: false,
			  type: "POST",
			  datatype: 'xml',
			  success:function (xml, text)
			  {
				xJAX.prototype.success(xml);
			  }
		});
	}

	xJAX.prototype.setTarget	= function(psTarget) 	{ this.sTarget = psTarget;	};
	xJAX.prototype.setParam		= function(psParam)		{ this.sParams = psParam;	};

	xJAX.prototype.send	= function(pbAsync, psMethod) {

		// Vire les tooltips en cours
		$("#tooltip").hide();

		$.ajax({
			  type: psMethod,
			  url: 'xjax.php?'+this.sTarget,
			  data: this.sParams,
			  async: pbAsync
		});

	}

		
		
	xJAX.prototype.success = function(xmlDocument)
	{

		if (xmlDocument != null)
		{
			
			// Traitement des divisions à mettre à jour
	    	var updateDivs = xmlDocument.getElementsByTagName('update');
			
	    	for (var i=0; i<updateDivs.length; i++) {
	    		var sTargetDiv	= updateDivs[i].getAttribute('target');
	    		var sValue		= updateDivs[i].firstChild.nodeValue;
	    		var bSlide		= updateDivs[i].getAttribute('slide');

				if (bSlide>0)
	    		{
		    		if ($("#"+sTargetDiv).html()!="")
		    		{
			    		xJAX.prototype.slideComplet(sTargetDiv, sValue);
		    		}
		    		else
		    		{
						xJAX.prototype.slideDemi(sTargetDiv, sValue);
		    		}
	    		}
	    		else {
	    			$("#"+sTargetDiv).html(sValue);
	    		}
	    	}

	    	// Erreurs eventuelles
	    	var aErrors = xmlDocument.getElementsByTagName('error');
	    	for (var i=0; i<aErrors.length; i++) {
	    		alert(aErrors[i].firstChild.nodeValue);
	    	}

	    	// Style
	    	var aStyle = xmlDocument.getElementsByTagName('style');
	    	for (var i=0; i<aStyle.length; i++) {

	    		// Initialisations
	    		var sTargetDiv	= aStyle[i].getAttribute('target');
	    		var sCSSType	= aStyle[i].getAttribute('type');
	    		var sValue		= aStyle[i].firstChild.nodeValue;

	    		// Modifications du style
	    		if (sCSSType == 'width')	{ document.getElementById(sTargetDiv).style.width	= sValue; 	continue; }
	    		if (sCSSType == 'display')	{ document.getElementById(sTargetDiv).style.display	= sValue;	continue; }
	    	}

	    	// Redirection
	    	var aRedirections = xmlDocument.getElementsByTagName('redirect');
	    	if (aRedirections.length > 0) {
	    		location.href = aRedirections[0].getAttribute('target');
	    	}

	    	// Popup
	    	var aPopup	=	xmlDocument.getElementsByTagName('message');
	    	for (var i=0; i<aPopup.length; i++){

	    		// Init
	    		var message = aPopup[i].firstChild.nodeValue;
	    		var titre =	aPopup[i].getAttribute('titre');
	    		var image = aPopup[i].getAttribute('image');
	    		var sticky = aPopup[i].getAttribute('sticky');
	    		var temps =aPopup[i].getAttribute('temps');

	    		afficher_message(message, titre, image, sticky, temps);
	    	}

			// Big popup dhtml
			var aBigPopup = xmlDocument.getElementsByTagName('bigPopup');
			for (var i=0; i<aBigPopup.length; i++)
			{
				var nb_alea = Math.floor(Math.random() * 9999999);
				var html = aBigPopup[i].firstChild.nodeValue;
				var width = aBigPopup[i].getAttribute('width');
				var height = aBigPopup[i].getAttribute('height');

				$("body").append("<div id='popup_"+nb_alea+"' style='display:none'>"+html+"</div>");
				$.modal($("#popup_"+nb_alea), { containerCss : {width: width+"px", height: height+"px" }, overlayClose :true });
			}

	    	// Callback
	    	var aCallback = xmlDocument.getElementsByTagName('callback');
	    	for (var i=0; i<aCallback.length; i++){

	    		// Init
	    		var fonction = aCallback[i].getAttribute('fonction');
	    		var message =  aCallback[i].firstChild.nodeValue;
	    		eval(fonction+'('+message+');');

	    	}
		}
	}

	xJAX.prototype.slideComplet = function(sTargetDiv, sValue)
	{
		$("#"+sTargetDiv).slideFadeToggle(1000, "", function() {
			$("#"+sTargetDiv).html(sValue);
			$("#"+sTargetDiv).slideFadeToggle(1000);
		});
	}


	xJAX.prototype.slideDemi = function(sTargetDiv, sValue)
	{
		$("#"+sTargetDiv).hide(0, function() {
			$("#"+sTargetDiv).html(sValue);
			$("#"+sTargetDiv).slideFadeToggle(1000);
		});
	}