function CreateXMLHTTPRequestObject() {
	this.xhr_object    = null;
	this.response      = null;
	this.ready         = true;
	this.asynchronous  = true;
	if(window.XMLHttpRequest) // Firefox
		this.xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		this.xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas cette application...");
	this.indicatorFunction = null;
	this.setIndicatorFunction = function(func) {if(typeof(func) == "function") this.indicatorFunction = func;}
	this.setSynchronous = function() {this.asynchronous = false;}
	this.setAsynchronous = function() {this.asynchronous = true;}
	this.getFileGet = function(url, data) {return this.doRequest(url, "GET", data);}
	this.getFile = this.getFileGet;
	this.getFilePost = function(url, data) {return this.doRequest(url, "POST", data);}
	this.getFileHeader = function(url, header) {return this.doRequest(url, "HEAD", header);}
	this.doRequest = function(url, method, data) {
		if(!this.ready || !this.xhr_object) return false;
		function _getResponseHeader(headers, header_name) {
			var tmp = headers.split("\n");
			for(var i=0, n=tmp.length, t=[]; i<n-1; ++i) {
				t = tmp[i].split(": ");
				if(t[0].toLowerCase() == header_name.toLowerCase()) return t[1];
			}
			return "Header inconnu...";
		}

		if(this.indicatorFunction) this.indicatorFunction(true);
		this.ready = false;
		var obj = this;
		function onreadystatechangeFunction() {
			if(obj.xhr_object.readyState != 4) return;
			
			if(obj.indicatorFunction) obj.indicatorFunction(false);

			var all_headers = obj.xhr_object.getAllResponseHeaders();
			if(method == "HEAD") {
				obj.response = data ? _getResponseHeader(all_headers, data) : all_headers;
			}
			else {
				var content_type = _getResponseHeader(all_headers, "Content-Type");
				if (content_type != "Header inconnu..." && (new RegExp("^text/xml.*$", "gi")).test(content_type))
					obj.response = obj.xhr_object.responseXML;
				else
					obj.response = obj.xhr_object.responseText;
			}
		}

		if(method == "GET" && typeof(data) != "undefined" && data != "") url += "?"+data;
		this.xhr_object.open(method, url, this.asynchronous);

		if(this.asynchronous)
			this.xhr_object.onreadystatechange = onreadystatechangeFunction;
		
		if(data) this.xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		else     data = null;
		this.xhr_object.send(data);

		if(!this.asynchronous)
			onreadystatechangeFunction();

		return true;
	}
	this.hasResponse = function() {return this.response != null;}
	this.getResponse = function() {return this.response;}
	this.validateRequest = function() {this.ready = true; this.response = null;}

	var browser   = navigator.userAgent;
	var isOpera   = (browser.indexOf("Opera") != -1);
	var isIE      = (!isOpera && browser.indexOf("MSIE") != -1);
	var isMozilla = (!isOpera && !isIE && browser.indexOf("Mozilla") != -1);
	function giveFocus(theId) {document.getElementById(theId).focus();}
	var saved_colors = new Array;
	function saveColor(itemId, color) {saved_colors[itemId] = color;}
	function restoreColor(itemId) {
		if(typeof(saved_colors[itemId]) == "undefined") return "#000000";
		if(saved_colors[itemId] == "") return "#000000";
		return saved_colors[itemId];
	}
	function disableItem() {
		var items = disableItem.arguments;
		if(items.length == 0) return;
		for(var d=0; d<items.length; ++d) {
			if(document.getElementById(items[d]).disabled) continue;
			document.getElementById(items[d]).disabled = true;
			if(isOpera) {
				var el = document.getElementById(items[d])
				if(el.type == "button" || el.type == "reset" || el.type == "submit" || el.type == "file")
					saveColor(el.id, el.style.color);
				el.style.color = "#808080";
			}
		}
	}
	function enableItem() {
		var items = enableItem.arguments;
		if(items.length == 0) return;
		for(var d=0; d<items.length; ++d) {
			if(!document.getElementById(items[d]).disabled) continue;
			document.getElementById(items[d]).disabled = false;
			if(isOpera) {
				var el = document.getElementById(items[d])
				if(el.type == "button" || el.type == "reset" || el.type == "submit" || el.type == "file")
					el.style.color = restoreColor(el.id);
			}
		}
	}
	function myPopup(imgFile, imgWidth, imgHeight) {
		var imgLeft = (screen.width-imgWidth)/2;
		var imgTop  = (screen.height-imgHeight)/2;
		var wPopup  = window.open("", "_blank", "width="+imgWidth+", height="+imgHeight+", left="+imgLeft+", top="+imgTop);
		wPopup.document.write('<html><head><title>Cliquez dans cette fenêtre pour la fermer</title></head><body style="margin: 0px; padding: 0px;" onclick="window.close();"><img src="'+imgFile+'" alt="" title="Cliquez dans cette fenêtre pour la fermer" style="width: '+imgWidth+'; height: '+imgHeight+';" /></body></html>');
		wPopup.document.close();
		wPopup.focus();
	}

	this.cancelRequest = function() {
		this.xhr_object.abort();
		if(this.indicatorFunction) this.indicatorFunction(false);
		this.validateRequest();
	}
}

/*######### DEBUT SPECIFIQUE 2D AJAX - F.MARTINEZ ###############*/
var check_delay = 200;
var tab_req     = new Array();
var max_req     = 1;
var file				= "aide.php";
function toggleIndicator(flag) {
	if (document.getElementById){document.getElementById("dIndicator").style.display = flag ? "block" : "none";}
	else if (document.all){document.all["dIndicator"].style.display = flag ? "block" : "none";}
}

function toggleSelects(flag) {
	if (document.getElementById){
		document.getElementById("select1Div").style.display = flag ? "block" : "none";
	}
	else if (document.all){
		document.all["select1Div"].style.display = flag ? "block" : "none";
	}
}

//function doRequest(typeaction,actiondata) {
function doRequest() {
	if(tab_req.length > 0) return;
	for(var i=0; i< max_req; ++i) {
		tab_req[i] = new CreateXMLHTTPRequestObject();
		tab_req[i].setIndicatorFunction(toggleIndicator);
		// Mode asynchrone
		tab_req[i].setAsynchronous();
		// Transmission des données
		data = '';
		// Avec la méthode GET
		if(!tab_req[i].getFileGet(file, data)) return;
		setTimeout("checkResponse()", check_delay);
	}
}

//function générique pour écrire dans un layer quelque soit le navigateru ie ou firefox
function writeToLayer(text,id){
	var cntnt = '<div class="info">' + text + '</div>';
	if (document.getElementById){
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = cntnt;
	}else if (document.all){
		x = document.all[id];
		x.innerHTML = cntnt;
	}
}

function checkResponse() {
	var _yourplaces = 0;
	for(var i=0; i< max_req; ++i) {
		if(tab_req[i] && tab_req[i].hasResponse()) {
			var rep = tab_req[i].getResponse();
    	//eval("chaines = rep.split(';');")
			tab_req[i].validateRequest();
			tab_req.splice(i, 1);
			//alert(rep);
			writeToLayer(rep,'contentHelpDiv');
			showBox();
		}
	}
	if(tab_req.length > 0) 
		setTimeout("checkResponse()", check_delay);
}


