// JavaScript Document
function xhr_init () {
	var xhr = null; 
	
	if(window.XMLHttpRequest) {
		xhr = new XMLHttpRequest(); 
	} else if(window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xhr;	
}

function aj_post (aj_script, aj_data, aj_callback) {
	xhr = xhr_init();
	if (!xhr) {
		alert("Votre navigateur ne supporte pas certaines fonctionnalités nécessaires pour cette application ..."); 
		return false;
	}
	
	show_ajpopup ('Veuillez patienter ...');
	
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			show_ajpopup ("Résultat", xhr.responseText);
			if (aj_callback) {
				eval (aj_callback);
			}
		}
	}	
	xhr.open("POST", aj_script, true);
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr.send(aj_data);
}

function aj_get (aj_script, aj_callback) {
	xhr = xhr_init();
	if (!xhr) {
		alert("Votre navigateur ne supporte pas certaines fonctionnalités nécessaires pour cette application ..."); 
		return false;
	}

	show_ajpopup ('Traitement en cours', 'Veuillez patienter ...');
	
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			show_ajpopup (xhr.responseText);
			if (aj_callback) {
				eval(aj_callback);
			}
		}
	}
	xhr.open("GET", aj_script, true);
	xhr.send(null);
}
