/* Génération d'un objet Ajax */
function ajaxGetXMLHttpRequest() {
	var xhr = null;
	
	if (window.XMLHttpRequest || window.ActiveXObject) {	//Objet Ajax supporté
		if (window.ActiveXObject) {	//Internet explorer
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		else {				//Autres navigateurs
			xhr = new XMLHttpRequest(); 
		}
	}
	else {						//Objet Ajax non supporté
		alert("Votre navigateur ne supporte pas la technologie ajax, veuilez mettez le mettre à jour ou le changer.");

		return null;
	}
	
	return xhr;
}

/* Protection des variables dans les url */
function ajaxProtect(v) {
	return encodeURIComponent(v);
}

/* Requete avec retour texte */
function ajaxRequestText(callback, url, data, method, async) {
	var xhr = ajaxGetXMLHttpRequest();
	
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
			callback(xhr.responseText);
		}
	};
	
	if(method == "POST") {
		xhr.open(method, url, async);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(data);
	}
	else if(method == "GET"){
		xhr.open(method, url + "?" + data, async);
		xhr.send(null);
	}
	else {
		xhr.open("GET", url, async);
		xhr.send(null);	
	}
}

/* Requete avec retour XML */
function ajaxRequestXml(callback, url, data, method, async) {
	//ajaxRequestText(callback, url, data, method, async);
	//return;

	var xhr = ajaxGetXMLHttpRequest();
	
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
			callback(xhr.responseXML);
		}
	};
	
	if(method == "POST") {
		xhr.open(method, url, async);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(data);
	}
	else if(method == "GET"){
		xhr.open(method, url + "?" + data, async);
		xhr.send(null);
	}
	else {
		xhr.open("GET", url, async);
		xhr.send(null);	
	}
}


