function AJAXrequest(url,pars,callback_function) {
	var http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if(http_request) {
		http_request.onreadystatechange=function()
		{
			if (http_request.readyState == 4) {
				if (http_request.status == 200) {
					var AJAXresp = http_request.responseText;
					eval(callback_function+"(AJAXresp)"); 
				} else {
					alert("Error");
				}
			}
		}
		http_request.open("POST", url, true);
		http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		http_request.send(pars);
	} else {
		alert("Error");
	}
}

function ajax(id) {
	this.verrou=false;
	this.id=id;
	this.action="";
	this.flag_enter = false; 
	this.compteurwaitint = 0;
	this.compteur_wait = ".";
	this.closeload = 0;
	this.reftime = "";
	document.write("<div id='dWaj' class='dW'></div><div id='dWwait' class='dW'></div>");
}

ajax.prototype.send = function(tableau,action) {
	this.verrou=false;
	this.action=action;
	if (this.flag_enter == false) {
		this.flag_enter = true;
		var url = "/_control/_ajax.php";
		var pars = "ajaxid="+this.id+"&action="+action+"&send="+escape(jsArray2Php(tableau));
		var callback_function = "ajax.prototype.receive";
		this.loading(this.id);
		AJAXrequest(url,pars,callback_function);
	}
}

ajax.prototype.wait = function() {
	//console.info("timer = "+this.compteurwaitint);
	if (parseInt(this.compteurwaitint) == 0) {
		if (this.closeload==1) {
			clearInterval(this.reftime);
			this.compteur_wait = ".";
			this.closeload = 0;
			this.flag_enter = false;
			this.compteurwaitint = -1;
		} else if (this.verrou=="false") {
			dW.display_window("dWwait","bloc=yes,template=load2,type=load,move=yes");
		}
	} else if ((parseInt(this.compteurwaitint) >= 41 && this.closeload==1) || parseInt(this.compteurwaitint) >= 300) {
		clearInterval(this.reftime);
		this.compteur_wait = ".";
		this.closeload = 0;
		this.flag_enter = false;
		this.compteurwaitint = -1;
		dW.close_window();
	}
	this.compteurwaitint=parseInt(this.compteurwaitint)+1;
}

ajax.prototype.loading = function(id) {
	eval(id+".compteurwaitint=0;");
	eval(id+".closeload=0;");
	eval(id+".reftime = setInterval('"+id+".wait()',100);");
}

ajax.prototype.receive = function(request) {
	eval(request);
	var tabletemp = new PhpArray2Js(receive);
	var phpajax=tabletemp.retour();
	ajaxid=phpajax["ajaxid"];
	eval(ajaxid+".closeload = 1;");
	eval(ajaxid+".flag_ajax = false;");
	eval(ajaxid+".flag_enter = false;");
	eval("clearInterval("+ajaxid+".reftime);");
	ajax_receive(phpajax,aj.action);
}


function PhpArray2Js(tabphp_serialise) {
   this.php = corrigerChainePHP(tabphp_serialise);
   var dim = this.extraireDimTab();
   this.tabjs = this.transformer(dim);
}

PhpArray2Js.prototype.retour = function() {
        // retourne le tableau JS
        return this.tabjs;
}

PhpArray2Js.prototype.transformer = function(dim) {
   // méthode principale qui transforme la chaîne sérialisée en un tableau Javascript
        // dim est la dimension du tableau PHP
   var tab = new Array();
   // extrait un groupe de dim données (indice - valeur)
   for (var i=0;i<dim;i++) {
       // extrait un indice : numérique ou littéral
       var indice = this.extraireIndice();
       if (indice == -1) return;
       // extrait une valeur : tableau, null, booléen, numérique ou littéral
       var valeur = this.extraireValeur();
       if (valeur == -1) tab[indice] = undefined;
       else {
           switch (valeur[0]) {
               case "N" : tab[indice] = null; break;
               case "b" : tab[indice] = valeur[1] ? true : false; break;
               case "i" : tab[indice] = parseInt(valeur[1]); break;
               case "d" : tab[indice] = parseFloat(valeur[1]); break;
               case "s" : tab[indice] = valeur[1]; break;
               case "a" : tab[indice] = this.transformer(valeur[1]); break;
               default  : tab[indice] = undefined;
           }
       }
   }
   // en fin de groupe de données, supprime le "}" final
   this.php = this.php.substring(1);
   return tab;
}

PhpArray2Js.prototype.extraireDimTab = function() {
   // extrait la dimension N du tableau de "a:N:{"
   var reg = this.php.match(/^a:(\d+):\{/);
   if (reg != -1) {
       // on coupe le texte de l'entité détectée
       this.php = this.php.substring(reg[0].length);
       return reg[1];
   }
   else return -1;
}

PhpArray2Js.prototype.extraireIndice = function() {
   // extrait l'indice d'un tableau
   // cet indice peut être de la forme "i:\d+" ou "s:\d+:\"\w+\""
   var retour;
   var reg = this.php.match(/^((i):(\d+);|(s):\d+:"([^"]+)";)/);
   if (reg != -1) {
       // on coupe le texte de la chaîne détectée
       this.php = this.php.substring(reg[0].length);
       if (reg[2] == "i") retour = reg[3];
       else if (reg[4] == "s") retour = reg[5];
       else retour = -1;
   }
   else retour = -1;
   return retour;
}

PhpArray2Js.prototype.extraireValeur = function() {
   // extrait une valeur au début de this.php
   // cette valeur est de type "a:\d+:{" ou "N" ou "b:[01]" ou "i:\d+" ou "i:[\d\.]+" ou "s:\d+:\"\w+\""
   // on tente de détecter une valeur en tête de texte
   var retour;
   var reg = this.php.match(/^((N);|(b):([01]);|(i):(\d+);|(d):([\d\.]+);|(s):\d+:"([^"]*)";|(a):(\d+):\{)/);
   if (reg != -1) {
       // on coupe le texte de la valeur détectée
       this.php = this.php.substring(reg[0].length);
       // retour est un tableau contenant le type et la valeur de la donnée détectée dans la chaîne
       if (reg[2] == "N") retour = new Array("N", null); // valeur nulle
       else if (reg[3] == "b") retour = new Array("b", reg[4]); // booléen (true/false)
       else if (reg[5] == "i")  retour = new Array("i", reg[6]); // entier
       else if (reg[7] == "d")  retour = new Array("d", reg[8]); // entier double ou flottant
       else if (reg[9] == "s") retour = new Array("s", remplacerQuotes(reg[10])); // chaîne de caractères
       else if (reg[11] == "a") retour = new Array("a", reg[12]); // sous-tableau
       else retour = -1;
   }
   else retour = -1;
   return retour;
}

function corrigerChainePHP(chaine) {
   // remplace les &quot; en " uniquement autour des chaînes de caractères
   chaine = chaine.replace(/:&quot;/g, ':"');
   chaine = chaine.replace(/&quot;;/g, '";');
   return chaine;
} 

function remplacerQuotes(chaine) {
   // remplace les &quot; à l'intérieur des chaînes de caractères
   return chaine.replace(/&quot;/g, '\"');
}

PhpArray2Js.prototype.var_dump = function() {
   // affiche le tableau
   return var_dump(this.tabjs);
}

function var_dump(tab) {
   // fonction analogue à var_dump en PHP, mais plus simple
   if (arguments.length == 2) var indent = arguments[1] + "\t";
   else var indent = "\t";
   var i = 0;
   var elements = "";
   for (var elt in tab) {
       elements += (i ? ",\n " : " ") + indent + "[" + elt + "]:";
       switch (typeof tab[elt]) {
           case "string" : 
               elements += "\"" + tab[elt] + "\""; break;
           case "number" :
               elements += tab[elt]; break;
           case "object" :
               if (tab[elt] == null) elements += "*null*";
               else if (tab[elt]) elements += var_dump(tab[elt], indent); break;
           case "undefined" :
               elements += "*undefined*"; break;
           default : elements += tab[elt];
       }
       i++;
   }
   return "tableau(" + i + "){\n" + elements + "\n" + (arguments[1] ? arguments[1] : "") + "}";
}

var _MAX_INT = 256*256*256*16-1;

function jsArray2Php(tab) {
   var jAi = 0;
   var chaine = "";
   var idx = 0;
   for (jAi in tab) {
       if (isNaN(jAi)) chaine += "s:" + jAi.length + ":\"" + jAi + "\";";
       else chaine += "i:" + i + ";";
       var valeur = tab[jAi];
       switch (typeof valeur) {
           case "string" : 
               valeur = formaterChaine(valeur);
               chaine += "s:" + valeur.length + ":\"" + valeur + "\";";
               break;
           case "number" :
               if (valeur > parseInt(valeur)) chaine += "d:" + valeur + ";";
               else if (valeur > _MAX_INT) chaine += "d:" + valeur + ";";
               else chaine += "i:" + valeur + ";";
               break;
           case "boolean" :
               chaine += "b:" + ((valeur === true) ? 1 : 0) + ";";
               break;
           case "object" :
               if (valeur === null) chaine += "N;"; 
               else chaine += jsArray2Php(valeur);
               break;
           default : 
               chaine += "N;";
       }
       idx++;
   }
   return "a:" + idx + ":{" + chaine + "}";
}

function formaterChaine(chaine) {
   return chaine.replace(/\"/g, "&quot;");
}





/*
functions to use display_window, close_window
///////////////////
display_window(
"dW4",
"
bloc=yes, // option
template=load2, // load1 or load2 or navigate or confirm 
move=yes, // move in option
type=load, // in option type=load if a load window
mess2='', // a message in html no put , and ' in option
actions='' // actions to do with the main page in option

");

to open (as exemples):
dW.display_window("dW4","bloc=yes,template=load2,move=yes,type=load,mess2='',actions=''");

to close:
dW.close_window();

*/

extend = function(subClass, baseClass) {
   function inheritance() {}
   inheritance.prototype = baseClass.prototype;
   subClass.prototype = new inheritance();
   subClass.prototype.constructor = subClass;
   subClass.baseConstructor = baseClass;
   subClass.superClass = baseClass.prototype;
}


function cWindow() {
}

cWindow.prototype.filterResults = function(n_win, n_docel, n_body) {
	/*
	maxval = Math.max(n_win,n_docel);
	maxval = Math.max(maxval,n_body);
	return maxval;
	*/
	
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

cWindow.prototype.clientTop = function() {
	if (document.documentElement && document.documentElement.scrollTop)
		theTop = document.documentElement.scrollTop;
	else if (document.body)
		theTop = document.body.scrollTop;
	else
		theTop = 0;
	return parseInt(theTop) ;
}

cWindow.prototype.clientLeft = function() {
	if (document.documentElement && document.documentElement.scrollLeft)
		theLeft = document.documentElement.scrollLeft;
	else if (document.body)
		theLeft = document.body.scrollLeft;
	else
		theLeft = 0;
	return parseInt(theLeft) ;
}

cWindow.prototype.clientWidth = function() {
	return this.filterResults(window.innerWidth ? window.innerWidth : 0,document.documentElement ? document.documentElement.clientWidth : 0,document.body ? document.body.clientWidth : 0);
}

cWindow.prototype.clientHeight = function() {
	return this.filterResults(window.innerHeight ? window.innerHeight : 0,document.documentElement ? document.documentElement.clientHeight : 0,document.body ? document.body.clientHeight : 0);

}

cWindow.prototype._Connect = function(oElem, sEvType, fn, bCapture) {
	return oElem.addEventListener?
	oElem.addEventListener(sEvType, fn, bCapture):
	oElem.attachEvent?
	oElem.attachEvent('on' + sEvType, fn):
	oElem['on' + sEvType] = fn;
}

function cDisplayWindow(id,pas,ecrire) {
	this.timeref= "";
	this.numero = "";
	this.confirm = false;
	this.actions = "";
	this.id = id;
	this.ido = "";
	this.compteur = 0;
	this.pas = pas;
	this.choice = "";
	this.ecrire = ecrire;
	this.move = false;
	this.style = "<style type='text/css'>#container_"+this.id+" {position:relative;display:none;padding:0px;margin:0px;z-index:10000;top:100px;left:100px;} ."+this.id+" {position:relative;display:none;} select,input,textarea {position:relative;visibility:visible;}</style>";       
}
extend(cDisplayWindow,cWindow);

cDisplayWindow.prototype.init = function() {
	document.write(this.style);
}

cDisplayWindow.prototype.display_bloc = function() {
	var pageWidth,pageHeight;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	if (test1 > test2) {
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
	} else {
		pageWidth = document.body.offsetWidth;
		pageHeight = document.body.offsetHeight;
	}
	var fsdiv = document.createElement("div");
	fsdiv.id = "fsdiv";
	fsdiv.style.backgroundColor = "#000000";
	fsdiv.style.padding = "0px";
	fsdiv.style.textAlign = "center";
	fsdiv.style.verticalAlign = "middle";
	fsdiv.style.color = "#ffffff";
	fsdiv.style.fontWeight = 'bold';
	fsdiv.style.width = pageWidth+"px";
	fsdiv.style.height = pageHeight+"px";
	fsdiv.style.position = "absolute";
	fsdiv.style.top = "0px";
	fsdiv.style.left = "0px";
	fsdiv.opacity = (0.7);
	fsdiv.style.MozOpacity = "0.7";
	fsdiv.style.filter = "alpha(opacity=70)";
	fsdiv.style.zIndex = "90";
	document.getElementById('begin').appendChild(fsdiv);
}

cDisplayWindow.prototype.display_window = function() {
		//this.timer();
		var args = cDisplayWindow.prototype.display_window.arguments; 
   		this.nombre_args = args.length - 1; // args.length est le nombre d'arguments
		numero = "dW1";
		bloc= "";
		template= "";
		type = "";
		mess2 = "";
		move= "";
		actions= "";
		hide="yes";
		
		numero = args[0];
		if (args.length>1) {
			resultat = args[1].split(",");
			mess="";
			for (i=0;i<resultat.length;i++) {
				var resultat2=resultat[i].split("=");
				mess+=resultat2[0]+":"+resultat2[1];
				switch(resultat2[0]) {
					case "hide":
					hide = resultat2[1];
					break;
					case "bloc":
					bloc = resultat2[1];
					break;
					case "template":
					template = resultat2[1];
					break;
					case "move":
					move = resultat2[1];
					break;
					case "type":
					type = resultat2[1];
					break;
					case "mess":
					mess2 = resultat2[1];
					if (mess2=="''") {mess2='';}
					else if (mess2=='""') {mess2='';}
					break;
					case "actions":
					actions = resultat2[1];
					if (actions=="''") {actions='';}
					else if (actions=='""') {actions='';}
					break;
					case "ido":
					ido = resultat2[1];
					if (ido=="''") {ido='';}
					else if (ido=='""') {ido='';}
					this.ido=ido;
					break;
				}
			}
		}
		
		if (document.getElementById("container_"+this.id).style.display=='block') {
			this.close_window();
			setTimeout(this.id+".display_window('"+numero+"','bloc="+bloc+",template="+template+",move="+move+",type="+type+",mess2=\""+mess2+"\",actions="+actions+",ido="+ido+",hide="+hide+"')",300);
		} else {
			
			// hide the elements of forms
			if (hide=="yes") {
				elems=document.getElementsByTagName("select");
				if (elems.length>0) {
					for (i=0;i<elems.length;i++) {
					elems[i].style.visibility='hidden';
					}
				}
				elems=document.getElementsByTagName("input");
				if (elems.length>0) {
					for (i=0;i<elems.length;i++) {
					elems[i].style.visibility='hidden';
					}
				}
			}
			document.getElementById('container_'+ this.id).style.position = "absolute";
			document.getElementById('container_'+ this.id).style.top = ((this.clientHeight()/2)-(400/2)+this.clientTop())+"px";
			document.getElementById('container_'+ this.id).style.left = ((this.clientWidth()/2)-(600/2))+"px";
			document.getElementById('container_'+ this.id).style.zIndex = "100";
			if ((type=='load')||(type=='load2')) {
				if ((mess2 == "")&&(type=='load2')) {
					mess2=document.getElementById(numero).innerHTML;
				}
				// timer display loading
				if (type == "load2") {
					if (bloc=='yes') {
						this.display_bloc();
					}
					if (this.choice != template) {
						this.ecrire = "";
						this.choice = template;
						this.template(template);
						document.getElementById('container_'+ this.id).innerHTML= this.ecrire;
					}
					if (document.getElementById(this.id+'_contenu')) {document.getElementById(this.id+'_contenu').innerHTML=mess2;}
					if (document.getElementById(this.id+'_l1')) {document.getElementById(this.id+'_l1').style.display='none';}
					if (document.getElementById(this.id+'_l2')) {document.getElementById(this.id+'_l2').style.display='none';}
					this.actions=actions;
					this.numero = numero;
					document.getElementById("container_"+this.id).style.display='block';
					if (move=="yes") {this.move= true;}
				}
				else {
					setTimeout(this.id+".display_window('"+numero+"','bloc="+bloc+",template="+template+",move="+move+",type=load2,mess2=\""+mess2+"\",actions="+actions+",ido="+ido+"')",300);
				}
				
			} else {
				if (document.getElementById(this.id+'_l1')) {document.getElementById(this.id+'_l1').style.display='inline';}
				if (document.getElementById(this.id+'_l2')) {document.getElementById(this.id+'_l2').style.display='inline';}
				if (document.getElementById("container_"+this.id).style.display=='block') {
					document.getElementById("container_"+this.id).style.display='none';
				}
				if (numero!='') {
					mess2=document.getElementById(numero).innerHTML.replace(/&amp;apos;/g,"'");
				}
				if (bloc=='yes') {
					this.display_bloc();
				}
				if (this.choice != template) {
					this.ecrire = "";
					this.choice = template;
					this.template(template);
					document.getElementById('container_'+ this.id).innerHTML= this.ecrire;
				}
				if (document.getElementById(this.id+'_contenu')) {document.getElementById(this.id+'_contenu').innerHTML=mess2.replace(/&amp;apos;/g,"'");}
				if (move=="yes") {this.move= true;}
				this.actions=actions;
				this.numero = numero;
				if (template == "navigate") {
					this.retirate(this.numero);
				}
				document.getElementById("container_"+this.id).style.display='block';
			}
			
		}
}

cDisplayWindow.prototype.close_window = function() {
	this.verrou=false;
	//clearInterval(this.timeref);
	this.move= false;
	document.getElementById("container_"+this.id).style.display='none';
	if (document.getElementById('fsdiv')) {
		document.getElementById('begin').removeChild(document.getElementById('fsdiv'));
	}
	elems=document.getElementsByTagName("select");
	if (elems.length>0) {
		for (i=0;i<elems.length;i++) {
			elems[i].style.visibility='visible';
		}
	}
	elems=document.getElementsByTagName("input");
	if (elems.length>0) {
		for (i=0;i<elems.length;i++) {
			elems[i].style.visibility='visible';
		}
	}
	return false;
}


cDisplayWindow.prototype.recalculateWindow = function() {
	if (this.confirm == true) {
		this.confirm = false;
		// on lance fonction confirm de la page courante
		confirmer(this.id,this.actions,this.ido);
	} else
	if ((this.move == true)&&(document.getElementById("container_"+this.id))) {
		if (document.getElementById("container_"+this.id).style.display=='block') {
			document.getElementById('container_'+ this.id).style.top = ((this.clientHeight()/2)-(400/2)+this.clientTop())+"px";
			document.getElementById('container_'+ this.id).style.left = ((this.clientWidth()/2)-(600/2))+"px";
		}
	}
	if (document.getElementById('fsdiv')) {
		var pageWidth,pageHeight;
		var test1 = document.body.scrollHeight;
		var test2 = document.body.offsetHeight
		if (test1 > test2) {
			pageWidth = document.body.scrollWidth;
			pageHeight = document.body.scrollHeight;
		} else {
			pageWidth = document.body.offsetWidth;
			pageHeight = document.body.offsetHeight;
		}
		document.getElementById('fsdiv').style.width = pageWidth+"px";
		document.getElementById('fsdiv').style.height = pageHeight+"px";
	}
}

cDisplayWindow.prototype.timer = function() {
	this.timeref = setInterval(this.id+".recalculateWindow()",200);
}

cDisplayWindow.prototype.retirate = function(id) {
	if (document.getElementById(id).getAttribute('pr')) {
		document.getElementById(this.id+'pr').style.display='inline';
	} else {
		document.getElementById(this.id+'pr').style.display='none';
	}
	if (document.getElementById(id).getAttribute('nx')) {
		document.getElementById(this.id+'nx').style.display='inline';
	} else {
		document.getElementById(this.id+'nx').style.display='none';
	}
}

cDisplayWindow.prototype.doprecedent = function() {
	var pr = document.getElementById(this.numero).getAttribute('pr');
	this.numero = pr;
	this.retirate(pr);
	document.getElementById(this.id+'_contenu').innerHTML=document.getElementById(pr).innerHTML;
}

cDisplayWindow.prototype.donext = function() {
	var nx = document.getElementById(this.numero).getAttribute('nx');
	this.numero = nx;
	this.retirate(nx);
	document.getElementById(this.id+'_contenu').innerHTML=document.getElementById(nx).innerHTML;
}



cDisplayWindow.prototype.template = function(choice) {
	if (this.ecrire == '') {
	// don't forget el id="+this.id+"
		var color="background-image:url(img/popdhtml1.gif);";
		if (choice == "t1") {
			color="background-image:url(img/popdhtml1.gif);";
		} else if (choice == "t2") {
			var color="background-image:url(img/popdhtml2.gif);";
		}  else if (choice == "t3") {
			var color="background-image:url(img/popdhtml3.gif);";
		} 
		if ((choice == "") || (choice == "t1") || (choice=="t2") || (choice=="t3")) {
			this.ecrire+='<table  id='+this.id+' width="600" height="400"  style="'+color+'" border="0" cellpadding="0" cellspacing="0">';
			this.ecrire+='<tr><td align="right" valign="top"><a id="'+this.id+'_l1" href="#" onClick="return '+this.id+'.close_window();" style="position:relative;left:-15px;top:15px;"><img src="img/close.gif" border="0"></a></td></tr>';
			this.ecrire+='<tr><td align="center"><div id="'+this.id+'_contenu" style="font-size:12px;color:#000000;"></div></td></tr>';
			this.ecrire+='</table>';
		}
	}
	if (!document.getElementById('container_'+ this.id)) {
		this.ecrire = "<div id='container_"+this.id+"'>" + this.ecrire + "</div>";
	}
}

dW=new cDisplayWindow('dW','20','');
dW.init();
dW.template('');
document.write("<div id='begin' style='margin:0px;padding:0px;'></div>"+dW.ecrire);
dW._Connect(window, "load",dW.timer(), false);