var NS4								= (navigator.appName.indexOf("Netscape")>=0 && parseFloat(navigator.appVersion) >= 4 && parseFloat(navigator.appVersion) < 5)? true : false;
var IE4								= (document.all)? true : false;
var NS6								= (parseFloat(navigator.appVersion) >= 5 && navigator.appName.indexOf("Netscape")>=0 )? true: false;

// Envoyer une requete au serveur qui devra renvoyer du JavaScript
// method = POST / GET
// URL = adresse de la page à appeller
// Params = les paramètres à passez à la pge, du style parma1=x&parma2=Y
// msgErreur= message a afficher en cas d'erreur, dans la langue désirée
function AJAXsend(method,url,params,msgErreur) {
  	// Afficher l'image d'attente
  	if (!document.getElementById('ajaxProgress'))
  		create_div_dynamic();
  	showWaitingMessage();
  	
	if ((method.toUpperCase() != "POST") && (method.toUpperCase() != "GET"))
		method		=	"POST";
	if (msgErreur == "")
		msgErreur	=	"Votre navigateur ne supporte pas les objets XMLHTTPRequest...";
	var xhr_object	= null;
	if(window.XMLHttpRequest) // Firefox
		xhr_object	= new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		xhr_object	= new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert(msgErreur);
		return;
	}

	xhr_object.open(method.toUpperCase(), url, true);

	xhr_object.onreadystatechange = function anonymous() {
		if(xhr_object.readyState == 4){
			response = xhr_object.responseText;
			hideWaitingMessage();
			eval(response);
		}
	}

	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var data = params;
	xhr_object.send(data);
}

function AJAXupdate(divID,method,url,params,msgErreur) {
  	// Afficher l'image d'attente
  	if (!document.getElementById('ajaxProgress'))
  		create_div_dynamic();
  	showWaitingMessage();
  	
	if ((method.toUpperCase() != "POST") && (method.toUpperCase() != "GET"))
		method		=	"POST";
	if (msgErreur == "")
		msgErreur	=	"Votre navigateur ne supporte pas les objets XMLHTTPRequest...";
	var xhr_object	= null;
	if(window.XMLHttpRequest) // Firefox
		xhr_object	= new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		xhr_object	= new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert(msgErreur);
		return;
	}

	xhr_object.open(method.toUpperCase(), url, true);

	xhr_object.onreadystatechange = function anonymous() {
		if(xhr_object.readyState == 4){
			response = xhr_object.responseText;
			hideWaitingMessage();
			document.getElementById(divID).innerHTML=response;
		}
	}

	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var data = params;
	xhr_object.send(data);
}


// La première fois, créer le DIV pour l'animation d'attente
function create_div_dynamic() {
  	var width						= 50;
  	var height						= 50
  	var ww							= (IE4)? document.body.clientWidth : window.innerWidth;
	var x							= (ww-width)/2;
	var hh							= (IE4)? document.body.clientHeight : window.innerHeight;
	var yposition					= (hh-height)/2;
	
	dv = document.createElement('div');
	dv.setAttribute('id',"ajaxProgress");
	//set the inner styling of the div tag 
	dv.style.display="none";
	dv.style.position="absolute";
	dv.style.pixelWidth=50;
	dv.style.pixelHeight=50;	
	dv.style.pixelLeft=x;
	dv.style.pixelTop=yposition;
	dv.style.backgroundColor="white";
	dv.style.borderColor="black";
	dv.style.borderWidth="1px";
	dv.style.borderStyle="solid";
	document.body.appendChild(dv);
}

// Affiche un gif animé d'attente
function showWaitingMessage() { 
  	dv = document.getElementById('ajaxProgress');
	dv.innerHTML="<IMG SRC='images/ajax-loader.gif' BORDER='0' style='margin:10px;'>";
   	dv.style.display="";
}

// Cache l'annimation d'attente
function hideWaitingMessage() { 
	dv = document.getElementById('ajaxProgress');   
   dv.style.display="none";
}