
<!-- var bandeau_cache = 0; -->
var barre_verr = 0;

function newAJAXRequest(){
 var xhr = false;
 try{
     xhr = new XMLHttpRequest(); //IE 7+, FF
 } 
 catch(e){
     try{
       xhr = new ActiveXObject("Msxml2.XMLHTTP"); //IE6
     } 
     catch(e){
         try{
           xhr = new ActiveXObject("Microsoft.XMLHTTP"); //IE5
         } 
         catch(e){
           xhr = false;
         }
     }
 }
 
return xhr ;
}
/* SXParser - Sherbrow XML Parser */

/*
##
## Copyrights Sherbrow - 2009
##
*/

function parseXML (root) {

	//TODELETE//var i = new Array; // un tableau de compteurs pour pas embrouiller les boucles for (à cause de la récursivité) va savoir si je raconte pas de la merde là
	var deep_cur = 0, deep_max = 15; //Profondeur maximum à parcourir ( 0 = renvoi la racine )
	
	function build_tree (elt) { // Fonction appellée en récursivité : elle construit le noeud passé en paramètre (attributs en elt.nom_attribut et noeuds n°x en elt[x] (supprime les noeuds "blancs" pris en comptes par FF)
		var i;
		var XML_elt = new Array;
		
		if (deep_cur < deep_max) { // Si on est pas "trop profond" (= pas encore trop de générations à traiter)
			deep_cur ++;; // On "s'enfonce"
			if (elt.hasChildNodes()) {
				XML_elt.__SXP_child_length = 0; // pour ne pas laisser de "blancs" si des noeuds sont ignorés
				for (i=0;i<elt.childNodes.length;i++) { 
					if (!/^\s*$/.test(elt.childNodes[i].nodeValue)) { // On vire les noeuds tels que les noeuds texte VIDES (espace, tab, RC, LF, etc) que détecte FF
						XML_elt[XML_elt.__SXP_child_length++]=build_tree(elt.childNodes[i]); // On construit l'arbre de ce fils là
						deep_cur --; // On a fini de construire "un" enfant, on remonte, si il y en a un autre on "s'enfoncera" encore
					}
					if (elt.nodeValue != null) {
						XML_elt.nodeValue = elt.nodeValue;
					}
				}
			}
			else if (elt.nodeValue != null) {
				XML_elt[0] = elt.nodeValue;
				XML_elt.nodeValue = elt.nodeValue;
				return XML_elt;
			}
			
		}
		else { //Sinon on renvoie les fils tels quels (seulement réorganisés si FF)
			if (elt.hasChildNodes()) {
				XML_elt.__SXP_child_length = 0; // pour ne pas laisser de "blancs" si des noeuds sont ignorés
				for (i=0;i<elt.childNodes.length;i++) {
					if (!/^\s*$/.test(elt.childNodes[i].nodeValue)) { // On vire les noeuds tels que les noeuds texte VIDES (espace, tab, RC, LF, etc) que détecte FF
						XML_elt[XML_elt.__SXP_child_length++]=elt.childNodes[i]; // On assigne le noeud à la bonne place
					}
				}
			}
		}
		
		
		if (elt.attributes) { // Si c'est pas un noeud de texte, les attributs sont définis donc ..
			if (elt.attributes.length > 0) { // Si il y a des attributs on contruit les attributs
				for (i=0;i<elt.attributes.length;i++) {
					eval("XML_elt."+elt.attributes[i].name+" = elt.attributes[i].value;");
				}
			}
		}
		return XML_elt;
	}
	
	return build_tree (root);
}/* Gestion des fonctions à appeller au chargement de la page */

/*
##
## Copyrights Sherbrow - 2009
##
*/

function addOnload (event) {
	
	if (window.document.getElementsByTagName('body')[0]) {
		/*var body_elt = window.document.getElementsByTagName('body')[0];
		
		if (body_elt.getAttribute('onload') == null) {
			body_elt.setAttribute('onload',event);
		}
		else {
			body_elt.setAttribute('onload',body_elt.getAttribute('onload')+event);
		}*/
		if (window.document.getElementsByTagName('body')[0].getAttribute('_loaded')) { eval(event); }
		else { window.document.getElementsByTagName('body')[0].setAttribute('onload',window.document.getElementsByTagName('body')[0].getAttribute('onload')+event); }
	}
	else {
		setTimeout("addOnload('"+event+"')",200);
	}
}/* Gestion du pseudo ajax */

/*
##
## Copyrights Sherbrow - 2009
##
##Last Updated: 09/10/02 17:25
*/

function bajax_getXMLanswer (id) {

	if ('id' in this) { id = this.id; }
	
	if (document.all) { return document.getElementById(id).contentWindow.document.XMLDocument; }
	else { return document.getElementById(id).contentWindow.document; }
}

function chaine_aleatoire(nombre) {
	var chaine = "",i,temp;
	for (i=0;i<nombre;i++) {
		temp = Math.floor(61*Math.random());
		
		if (temp <= 9) {chaine+=temp;}
		else if (temp <= 35) {chaine+=String.fromCharCode(temp+55);}
		else if (temp <= 61) {chaine+=String.fromCharCode(temp+61);}
	}
	return chaine;
}

function bajax_query (method, page, names, values) {
	
	this.method = method.toLowerCase();
	this.names = names;
	this.values = values;
	this.loaded = 1;
	this.id = chaine_aleatoire(30);
	this.action = '';
	
	this.set_action = bajax_set_action;
	this.send = bajax_send;
	this.display = bajax_display;
	this.submit = bajax_submit;
	this.erase = bajax_erase;
	
	this.iframe = document.createElement('iframe');
	
	this.iframe.setAttributeNode(document.createAttribute('src'));
	this.iframe.setAttribute('src','php/vide.php');
	
	this.iframe.setAttributeNode(document.createAttribute('onload'));
	this.iframe.setAttributeNode(document.createAttribute('_loaded'));
	
	this.iframe.setAttributeNode(document.createAttribute('style'));
	this.iframe.setAttribute('style','display: none;');
	this.iframe.setAttributeNode(document.createAttribute('id'));
	this.iframe.setAttribute('id',this.id);
	
	document.getElementsByTagName('html')[0].appendChild(this.iframe);
	
	this.iframe.appendChild(this.iframe.contentDocument.createTextNode(""));
	
	
	
	if (this.method == "get") {
		if (typeof names == "object" && typeof values == "object" && names.length == values.length) {
			var i;
			this.src = page+"?"+names[0]+"="+values[0];
			for (i=1;i<names.length;i++) {
				this.src += "&"+names[i]+"="+values[i];
			}
		}
		else if (typeof names == "string" && typeof values == "string") {
			this.src = page+"?"+names+"="+values;
		}
		else {
			return "ERROR : Incorrect names & values parameters";
		}
		this.src+="&time="+chaine_aleatoire(20);
	}
	else if (this.method == "post") {
	
		this.form = this.iframe.contentWindow.document.createElement('form');
		
		this.form.setAttributeNode(this.iframe.contentWindow.document.createAttribute('method'));
		this.form.setAttribute('method','post');
		
		this.form.setAttributeNode(this.iframe.contentWindow.document.createAttribute('action'));
		this.form.setAttribute('action',page);
		
		if (typeof names == "object" && typeof values == "object" && names.length == values.length) {
			var i,temp;
			for (i=0;i<names.length;i++) {
				temp = this.iframe.contentWindow.document.createElement('input');
				temp.setAttributeNode(this.iframe.contentWindow.document.createAttribute('type'));temp.setAttribute('type','hidden');
				temp.setAttributeNode(this.iframe.contentWindow.document.createAttribute('name'));temp.setAttribute('name',names[i]);
				temp.setAttributeNode(this.iframe.contentWindow.document.createAttribute('value'));temp.setAttribute('value',values[i]);
				this.form.appendChild(temp);
			}
		}
		else if (typeof names == "string" && typeof values == "string") {
				var temp;
				temp = this.iframe.contentWindow.document.createElement('input');
				temp.setAttributeNode(this.iframe.contentWindow.document.createAttribute('type'));temp.setAttribute('type','hidden');
				temp.setAttributeNode(this.iframe.contentWindow.document.createAttribute('name'));temp.setAttribute('name',names);
				temp.setAttributeNode(this.iframe.contentWindow.document.createAttribute('value'));temp.setAttribute('value',values);
				this.form.appendChild(temp);
		}
		else {
			return "ERROR : Incorrect names & values parameters";
		}
		this.iframe.contentWindow.document.getElementsByTagName('body')[0].appendChild(this.form);
	}
	else {
		return "ERROR : Unknown method";
	}
}

function bajax_set_action (action) {
	
	if (action != null) {
		if (typeof action == "function" || typeof action == "string") {
			//var temp = /^\s*function\s*\(\s*\)\s*\{(.*)\}\s*$/i;
			this.iframe._action = action;
			return 1;
		}
		else {
			return -1;
		}
		
		this.iframe._action=action;
		return 1;
	}
	else {
		this.iframe._action=action;
		return this.action;
	}

}

function bajax_send () {
	
	this.iframe.setAttribute('_loaded','0');
	
	this.iframe.setAttribute('onload','this.setAttribute("_loaded","1")');
	
	if (this.method == "get") { this.iframe.setAttribute('src',this.src); }
	else if(this.method == "post") {
		this.form.submit();
	}
	
}

function bajax_display (id) {
	
	if ('id' in this) { id = this.id; }
	
	if (document.getElementById(id).getAttribute('_loaded') == '1') {
	
		alert(bajax_getXMLanswer(id).getElementsByTagName('reponse')[0].getAttribute('statut'));
	}
	else {
		setTimeout('bajax_display("'+id+'")',500);
	}
}

function bajax_erase (id) {
	
	if ('id' in this) { id = this.id; }
	
	document.getElementById(id).parentNode.removeChild(document.getElementById(id));
	
}

function bajax_submit (id) {
	
	if ('id' in this) { id = this.id;this.send(); }
	
	if (document.getElementById(id).getAttribute('_loaded') == '1') {
	
		if(bajax_getXMLanswer(id).getElementsByTagName('bajax_root')[0]) {
		
			original_root = bajax_getXMLanswer(id).getElementsByTagName('bajax_root')[0];
			xml_root = parseXML(bajax_getXMLanswer(id).getElementsByTagName('bajax_root')[0]);

			if( typeof document.getElementById(id)._action == "function") {
				document.getElementById(id)._action();
			} else {
				eval(document.getElementById(id)._action);
			}
		}
		else { /*bajax_erase(id);*/return -1; }
		
		bajax_erase(id);
		return 1;
	}
	else {
		setTimeout('bajax_submit("'+id+'")',500);
		return 2;
	}
	
}

/* // Exemples
	//var requete = new bajax_query ('get', 'test.php', ['test','re'], ['marche','mdr']);
	// xml_root et original_root
	
	//requete.set_action("alert(xml_root[0].lol)");
	//requete.set_action("alert(xml_root[0][0])");
	//requete.set_action("alert(xml_root[0].nodeValue)");
	//requete.set_action("alert(xml_root[0][0].nodeValue)");
	//requete.set_action("alert(xml_root[0][0]);alert(xml_root[1][0]);alert(xml_root[2][0])");
	//requete.set_action("alert(xml_root[0].lol);alert(xml_root[0][1]);eval(xml_root[2][0])");
	//requete.set_action("eval(''+xml_root[2][0])");
	
	//requete.set_action("alert(original_root.childNodes[0].childNodes[0].hasChildNodes())");
	
	//requete.set_action("alert(original_root.childNodes.length)");
	//requete.set_action("alert(original_root.childNodes[0].nodeValue)");
	//requete.set_action("alert(original_root.childNodes[0].nodeValue);alert(/^\\s*$/i.test(original_root.childNodes[0].nodeValue))");
	//requete.set_action("alert(original_root.childNodes[0].childNodes[0].nodeValue)");
	//requete.set_action("alert(original_root.attributes[0].value)");
	//requete.set_action("alert(original_root.childNodes[1].attributes.length)");
	//requete.set_action("alert(original_root.childNodes[1].childNodes[0].nodeValue)");
	//requete.set_action("original_root[1]=original_root.childNodes[1];alert(original_root[1])");
*/
/* Gestion de l'horloge */

/*
##
## Copyrights Sherbrow - 2009
##
*/

function horloge_load () {
	//var horloge = document.createElement('span');
	var horloge = document.getElementById('horloge');
	horloge.setAttributeNode(document.createAttribute('id'));
	horloge.setAttribute('id','horloge');
	
	horloge.appendChild(document.createTextNode(""));
	
	//window.document.getElementById('barre').appendChild(horloge);
	
	maj_time();
}

function maj_time () {
	
	var date = new Date();
	var j;
	var M;
	var h;
	var m;
	/*
	if (date.getMonth()<9) { M = "0"+(date.getMonth()+1); } else { M = date.getMonth()+1; }
	if (date.getDate()<10) { j = "0"+date.getDate(); } else { j = date.getDate(); }
	*/
	if (date.getHours()<10) { h = "0"+date.getHours(); } else { h = date.getHours(); }
	if (date.getMinutes()<10) { m = "0"+date.getMinutes(); } else { m = date.getMinutes(); }
	
	// window.document.getElementById('horloge').childNodes[0].nodeValue = j+"/"+M+" - "+h+":"+m;
	window.document.getElementById('horloge').childNodes[0].nodeValue = h+":"+m;
	
	setTimeout("maj_time()",10000)
	
}

addOnload('horloge_load();');/* Gestion du bandeau */

/*
##
## Copyrights Sherbrow - 2009
##
*/

function bandeau_load () {
	var entete = document.getElementById('bandeau_entete');
	
	entete.appendChild(document.createTextNode("cacher ↑"));
	
	entete.setAttributeNode(document.createAttribute('onclick'));
	entete.setAttribute('onclick','cacher_bandeau(1)');
	
	window.document.getElementById('bandeau').insertBefore(entete,window.document.getElementsByTagName('h1')[0]);
	
	var onglet = document.createElement('small');
	
	onglet.setAttributeNode(document.createAttribute('id'));
	onglet.setAttribute('id','bandeau_onglet');
	
	onglet.appendChild(document.createTextNode("afficher ↓"));
	
	onglet.setAttributeNode(document.createAttribute('onclick'));
	onglet.setAttribute('onclick','afficher_bandeau(1)');
	
	window.document.getElementsByTagName('body')[0].appendChild(onglet);
	
	//if (bandeau_cache) { cacher_bandeau (); } //obsolète depuis css.php
	
	
}
	
function cacher_bandeau (save) {
	
	window.document.getElementById('bandeau').style.height='0px';
	window.document.getElementById('bandeau_onglet').style.display='block';
	
	if (save) {
	/* var requete = new bajax_query ('get', '/save_pref.php', 'bandeau_cache', '1');
	requete.set_action();
	requete.submit(); */
	var requete = newAJAXRequest();
	requete.open("GET", "/save_pref.php?bandeau_cache=1"); 
	requete.send(null);
	}
}
	
function afficher_bandeau (save) {
	
	window.document.getElementById('bandeau_onglet').style.display='none';
	window.document.getElementById('bandeau').style.height='150px';
	
	if (save) {
		/* var requete = new bajax_query ('get', '/save_pref.php', 'bandeau_cache', '0');
		requete.set_action("");
		requete.submit(); */
	var requete = newAJAXRequest();
	requete.open("GET", "/save_pref.php?bandeau_cache=0"); 
	requete.send(null);
	}
}

addOnload('bandeau_load();');/* Gestion du verrou de la barre*/

/*
##
## Copyrights Sherbrow - 2009
##
*/

function verrou_load () {
	var verrou_libre = document.createElement('img');
	var verrou_verr = document.createElement('img');
	
	verrou_libre.setAttributeNode(document.createAttribute('id'));
	verrou_libre.setAttribute('id','barre_verrou_libre');
	verrou_libre.setAttributeNode(document.createAttribute('onclick'));
	verrou_libre.setAttribute('onclick','lib_barre(1)');
	verrou_libre.setAttributeNode(document.createAttribute('src'));
	verrou_libre.setAttribute('src','img/libre.gif');
	verrou_libre.setAttributeNode(document.createAttribute('alt'));
	verrou_libre.setAttribute('alt','Dév.');
	verrou_libre.setAttributeNode(document.createAttribute('title'));
	verrou_libre.setAttribute('title','Détacher');
	verrou_libre.setAttributeNode(document.createAttribute('style'));
	verrou_libre.setAttribute('style','display: none;');
	
	window.document.getElementById('verrou').appendChild(verrou_libre);
	
	verrou_verr.setAttributeNode(document.createAttribute('id'));
	verrou_verr.setAttribute('id','barre_verrou_verr');
	verrou_verr.setAttributeNode(document.createAttribute('onclick'));
	verrou_verr.setAttribute('onclick','verr_barre(1)');
	verrou_verr.setAttributeNode(document.createAttribute('src'));
	verrou_verr.setAttribute('src','img/verr.gif');
	verrou_verr.setAttributeNode(document.createAttribute('alt'));
	verrou_verr.setAttribute('alt','Verr.');
	verrou_verr.setAttributeNode(document.createAttribute('title'));
	verrou_verr.setAttribute('title','Attacher');
	
	window.document.getElementById('verrou').appendChild(verrou_verr);
	
	if (barre_verr) { verr_barre(); }
}
	
function verr_barre (save) {
	
	window.document.getElementById('bandeau_onglet').style.position='absolute';
	window.document.getElementById('barre').style.position='absolute';
	window.document.getElementById('barre_verrou_libre').style.display='block';
	window.document.getElementById('barre_verrou_verr').style.display='none';
	
	if (save) {
	/* var requete = new bajax_query ('get', '/save_pref.php', 'barre_verr', '1');
	requete.set_action("");
	requete.submit(); */
	var requete = newAJAXRequest();
	requete.open("GET", "/save_pref.php?barre_verr=1"); 
	requete.send(null);
	}

}
	
function lib_barre (save) {
	
	window.document.getElementById('bandeau_onglet').style.position='fixed';
	window.document.getElementById('barre').style.position='fixed';
	window.document.getElementById('barre_verrou_verr').style.display='block';
	window.document.getElementById('barre_verrou_libre').style.display='none';
	
	if (save) {
	/* var requete = new bajax_query ('get', '/save_pref.php', 'barre_verr', '0');
	requete.set_action("");
	requete.submit(); */
	var requete = newAJAXRequest();
	requete.open("GET", "/save_pref.php?barre_verr=0"); 
	requete.send(null);
	}
	
}

addOnload('verrou_load();');
