// JavaScript Document

joursFR = new Array('dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'); 
joursFRabrege = new Array('dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.');

moisFR = new Array();
moisFR[1]='janvier';
moisFR[2]='février';
moisFR[3]='mars';
moisFR[4]='avril';
moisFR[5]='mai';
moisFR[6]='juin';
moisFR[7]='juillet';
moisFR[8]='août';
moisFR[9]='septembre';
moisFR[10]='octobre';
moisFR[11]='novembre';
moisFR[12]='décembre';

moisFRabrege  = new Array();
moisFRabrege[1]='jan.';
moisFRabrege[2]='fév.';
moisFRabrege[3]='mars';
moisFRabrege[4]='avr.';
moisFRabrege[5]='mai';
moisFRabrege[6]='juin';
moisFRabrege[7]='juil.';
moisFRabrege[8]='août';
moisFRabrege[9]='sept.';
moisFRabrege[10]='oct.';
moisFRabrege[11]='nov.';
moisFRabrege[12]='déc.';



function moveTo(container, element){
  Position.prepare();
  container_y = Position.cumulativeOffset($(container))[1]
  element_y = Position.cumulativeOffset($(element))[1]
  new Effect.Scroll(container, {x:0, y:(element_y-container_y)});
  return false;
}


/* Affiche les menus sous IE (non support du div:hover) VALIDE XHTML Transitional et Strict*/
menuHover = function() {
	var menuEls = document.getElementById("navMenu").getElementsByTagName("div");
	for (var i=0; i<menuEls.length; i++) {
		menuEls[i].onmouseover=function() { this.className="MenuON "+this.className; }
		menuEls[i].onmouseout=function()  { this.className=this.className.replace("MenuON ", ""); }
	}
}

function unlock(e) {
	if (!e) var e = window.event;
	var touche = window.event ? e.keyCode : e.which;
	buffer = buffer + String.fromCharCode(touche);
	
		if (buffer.indexOf("!!g") != -1) {
			document.location.href='/?p=gestion';
			buffer="";
		}

		/*if (buffer.indexOf("+++") != -1) {
			alert(document.location.href);
			buffer="";
		}*/


		if (buffer.indexOf("!!a!!") != -1 ) {
			document.location.href='/?p=annuaire';
			buffer="";
		}

		if (buffer.indexOf("!!d!!") != -1 ) {
			document.location.href='/agenda/';
			buffer="";
		}


		if (buffer.indexOf("!!w!!") != -1) {
			document.location.href='/?p=webcam';
			buffer="";
		}

		if (buffer.indexOf("!!p!!") != -1) {
			document.location.href='/?p=_pratique/petites_annonces';
			buffer="";
		}

		if (buffer.indexOf("!!cq!!") != -1) {
			document.location.href='/democratie_locale/comites_de_quartier/';
			buffer="";
		}	
	
		if (buffer.indexOf("elfronto!") != -1) {
			document.location.href='http://elfronto.info';
			buffer="";
		}
}
	
	buffer = new String("");
	window.document.onkeypress=unlock;
	
	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	// Example:
	// alert( readCookie("myCookie") );
	function readCookie(name)
	{
	  var cookieValue = "";
	  var search = name + "=";
	  if(document.cookie.length > 0)
	  { 
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{ 
		  offset += search.length;
		  end = document.cookie.indexOf(";", offset);
		  if (end == -1) end = document.cookie.length;
		  cookieValue = unescape(document.cookie.substring(offset, end))
		}
	  }
	  return cookieValue;
	}
	
// ###############################################################################################################
// ######### Gestion du menu #####################################################################################
// ###############################################################################################################

	
	function afficheMenu(objet) {

		// on récupère l'id de l'objet
		nomMenu = objet.id;
		// si la fonction est appelée d'une rubrique principale, on récupère l'id du cadre des liens
		if(nomMenu.substr(0,1) == "L") { nomMenu=nomMenu.substr(1); }

		// on interrompt l'effacement du menu (délais)
		if(typeof(timerCacheMenu) == "number") { clearTimeout(timerCacheMenu); }

		// si ce n'est pas le même menu, on efface l'ancien de suite
		if(typeof(oldMenuId) == "string" && oldMenuId != nomMenu) { document.getElementById(oldMenuId).style.display='none'; }

		// on affiche le menu, si il existe
		if(document.getElementById(nomMenu)) { 
			if(typeof(timerAfficheMenu) == "number") {	clearTimeout(timerAfficheMenu); }
			document.getElementById(nomMenu).style.display='block';
			// Corrige le bug de bordures sous IE
			timerAfficheMenu=setTimeout("document.getElementById('"+nomMenu+"').style.borderColor=document.getElementById('"+nomMenu+"').style.borderColor;", 5);
		}
		//oldMenuId = nomMenu;
			
	}

	function cacheMenu(objet, delai) {
		// délais par défaut : 800 ms
		if(!delai) { delai = 800; }

		// on récupère l'id de l'objet
		nomMenu = objet.id;
		// si la fonction est appelée d'une rubrique principale, on récupère l'id du cadre des liens
		if(nomMenu.substr(0,1) == "L") { nomMenu=nomMenu.substr(1); }

		// On enregistre ce menu comme ancien menu
		oldMenuId = nomMenu;

		// on cache le menu avec un délais, si il existe
		if(document.getElementById(nomMenu)) {
			timerCacheMenu=setTimeout("document.getElementById(nomMenu).style.display='none';", delai);
		}
	}


// ###############################################################################################################
// ######### Webcam ##############################################################################################
// ###############################################################################################################

/*function refreshWebcam() { // actualisation de la webcam 
	$j.('#wchaut').css('backgroundImage','url(/webcam/webcam.jpg'+ (Math.random()*1000) +')');
	stopwebcam = setTimeout("webcam();", 2000);
}*/

// ###############################################################################################################
// ######### Fonctions transversales #############################################################################
// ###############################################################################################################

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function getLinkText (link) {
  return link.text ? link.text :
         link.innerText ? link.innerText :
         link.firstChild.nodeType == 3 ? link.firstChild.nodeValue :
		 link.textContent ? textContent : '';
}

function stripHTML(oldString) {

  return oldString.replace(/<&#91;^>&#93;*>/g, "");
  
}


function filtrerUL(objet, recherche) {
	// Fonction de tri sur une liste <UL>
	// ATTENTION ! 'recherche' doit pointer vers un objet et non pas des valeurs

	//if(typeof(objet)=='undefined') return false;
	//alert(typeof(objet));

	objetListe=document.getElementById(objet.id).getElementsByTagName("LI");

	recherche = recherche.value.toLowerCase();

	var regReplace = new RegExp("[^a-zA-Z0-9âàäÂÀÄéèêëÉÈÊËîïÎÏôöÔÖùûüÙÛÜçÇ\\-' ]", "ig");
	recherche = recherche.replace(regReplace, " ");

	var regReplace = new RegExp("[ ]+", "ig");
	recherche = recherche.replace(regReplace, " ");

	var regReplace = new RegExp("[aâàä]", "ig");
	recherche = recherche.replace(regReplace, "[aâàä]");

	var regReplace = new RegExp("[éeèêë]", "ig");
	recherche = recherche.replace(regReplace, "[éeèêë]");

	var regReplace = new RegExp("[iîï]", "ig");
	recherche = recherche.replace(regReplace, "[iîï]");

	var regReplace = new RegExp("[oôö]", "ig");
	recherche = recherche.replace(regReplace, "[oôö]");

	var regReplace = new RegExp("[uùûü]", "ig");
	recherche = recherche.replace(regReplace, "[uùûü]");

	var regReplace = new RegExp("[cç]", "ig");
	recherche = recherche.replace(regReplace, "[cç]");

	var regReplace = new RegExp(" ", "ig");
	recherche = recherche.replace(regReplace, "(.+)?[ '-]+");

	if(recherche!='') recherche = "(^|[ '-])"+recherche;
	
	//alert(recherche);

	for(i=0 ; i<objetListe.length; i++) {

		texte = getLinkText(objetListe[i].getElementsByTagName("A")[0]);
		texte = stripHTML(texte);

		/*var regReplace = new RegExp("[(),\\.\\[\\]]", "ig");
		texte = texte.replace(regReplace, " ");*/

		var regReplace = new RegExp("[^a-zA-Z0-9âàäÂÀÄéèêëÉÈÊËîïÎÏôöÔÖùûüÙÛÜçÇ\\-' ]", "ig");
		texte = texte.replace(regReplace, " ");

		var regReplace = new RegExp("[ ]+", "ig");
		texte = texte.replace(regReplace, " ");

		/*var regReplace = new RegExp("^ | $", "ig");
		texte = texte.replace(regReplace, "");*/

		var reg = new RegExp(recherche, "ig");
		present = reg.test(texte);
		
		o = objetListe[i]; 
		display = o.style.display;

		if(!present) {
			$j(o).slideUp('fast');
			//o.style.display = "none"; 
		} else if(present) {
			//alert(display+" / "+recherche+" / "+texte);
			$j(o).slideDown('fast');
			//o.style.display = ""; 
		}

	}

}

function filtrerSelectTEST(objet, recherche) {
//
// Fonction de tri sur une liste
// 
// ATTENTION ! 'recherche' doit pointer vers des objets et non pas des valeurs

/*	for(zzz=0 ; zzz < objet.options.length; zzz++) {
		objet.options[zzz].style.display='none';
		objet.options[zzz].style.color='red';
		//objet.options[zzz].style.cssText="display:none;";
		//objet.options[zzz].text = "none";
	}*/
	
	//alert(objet.id);
	//$j('#'+objet.id+' option').attr('disabled','disabled');
	$j('#'+objet.id+' option').attr('style','color:red;');
	//$j('#'+objet.id+' option').attr('style','display:none');
	//$j('#'+objet.id+' option').hide();
	
/*	$j(objet.id + " option").each(function(this) { 
	
	});*/

	recherche = recherche.value.toLowerCase();
	  
	var regReplace = new RegExp("[éeèê]", "ig");
		recherche = recherche.replace(regReplace, "[éeèê]");
	var regReplace = new RegExp("[aâà]", "ig");
		recherche = recherche.replace(regReplace, "[aâà]");
	var regReplace = new RegExp("[cç]", "ig");
		recherche = recherche.replace(regReplace, "[cç]");
	var regReplace = new RegExp("[iîï]", "ig");
		recherche = recherche.replace(regReplace, "[iîï]");
	var regReplace = new RegExp("[oôö]", "ig");
		recherche = recherche.replace(regReplace, "[oôö]");
	var regReplace = new RegExp("[uùûü]", "ig");
		recherche = recherche.replace(regReplace, "[uùûü]");
	
	// on recopie dans la liste les options ou l'ont trouve le texte recherché
	// (recherche non sensible à la casse)
	for(zzz=0 ; zzz < objet.options.length ; zzz++) {

		txt = objet.options[zzz].text;
		var reg = new RegExp(recherche, "ig");

		if(reg.test(txt)) {
			objet.options[zzz].style.display = "";
		}
	}
	
	//alert("fin boucle recherche");
	
}


function filtrerSelectOKOKOKMAISLENT(objet, recherche) {
//
// Fonction de tri sur une liste
// 
// ATTENTION ! 'recherche' doit pointer vers des objets et non pas des valeurs

	// si les tableaux principaux de réplication n'ont pas déjà été créés, on les crée
	if(typeof(index) == "undefined") {
		index = new Array;	
		texte = new Array;
	}

	// si le tableau de réplication de CETTE liste n'a pas encore été créé, on le crée
	// L'index du tableau est le nom de la liste
	if(typeof(index[objet.name]) == "undefined") {
		index[objet.name] = new Array;
		texte[objet.name] = new Array;

		for(zzz=0 ; zzz < objet.options.length ; zzz++) {
			index[objet.name][zzz] = objet.options[zzz].value;
			texte[objet.name][zzz] = objet.options[zzz].text;
		}
	}
	
	// On efface le contenu de la balise select
	objet.options.length = 0;
	
	// On récupère la chaine à rechercher en majuscule
	recherche = recherche.value.toLowerCase();
	
	var regReplace = new RegExp("[éeèê]", "ig");
		recherche = recherche.replace(regReplace, "[éeèê]");
	var regReplace = new RegExp("[aâà]", "ig");
		recherche = recherche.replace(regReplace, "[aâà]");
	var regReplace = new RegExp("[cç]", "ig");
		recherche = recherche.replace(regReplace, "[cç]");
	var regReplace = new RegExp("[iîï]", "ig");
		recherche = recherche.replace(regReplace, "[iîï]");
	var regReplace = new RegExp("[oôö]", "ig");
		recherche = recherche.replace(regReplace, "[oôö]");
	var regReplace = new RegExp("[uùûü]", "ig");
		recherche = recherche.replace(regReplace, "[uùûü]");
	
	var regRecherche = new RegExp(recherche, "i");	

	// on recopie dans la liste les options ou l'ont trouve le texte recherché
	// (recherche non sensible à la casse)
	for(zzz=0 ; zzz < index[objet.name].length; zzz++) {

		if(regRecherche.test(texte[objet.name][zzz])) {
			var nouvelElement = document.createElement("OPTION");
			nouvelElement.value = index[objet.name][zzz];
			nouvelElement.text = texte[objet.name][zzz];
			objet.add(nouvelElement);
		}

	}

}

function filtrerSelect(objet, recherche) {

	// Fonction de tri sur une liste
	// ATTENTION ! 'recherche' doit pointer vers des objets et non pas des valeurs

	// si les tableaux principaux de réplication n'ont pas déjà été créés, on les crée
	if(typeof(a_selects) == "undefined") {
		a_selects = new Array;	
	}

	// si le tableau de réplication de CETTE liste n'a pas encore été créé, on le crée
	// L'index du tableau est le nom de la liste
	if(typeof(a_selects[objet.name]) == "undefined") {
		a_selects[objet.name] = new Array();

		for(zzz=0 ; zzz < objet.options.length ; zzz++) {
			a_selects[objet.name][zzz] = objet.options[zzz];
		}
	}

	// On efface le contenu de la balise select
	objet.options.length = 0;
	
	// On récupère la chaine à rechercher en minuscules
	recherche = recherche.value.toLowerCase();
	
		var regReplace = new RegExp("[^a-zA-Z0-9âàäÂÀÄéèêëÉÈÊËîïÎÏôöÔÖùûüÙÛÜçÇ\\-' ]", "ig");
		recherche = recherche.replace(regReplace, " ");

		var regReplace = new RegExp("[ ]+", "ig");
		recherche = recherche.replace(regReplace, " ");
		
		// trim
		recherche = recherche .replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	
	// On règle les problèmes d'accents
	var regReplace = new RegExp("[éeèê]", "ig");
		recherche = recherche.replace(regReplace, "[éeèê]");
	var regReplace = new RegExp("[aâà]", "ig");
		recherche = recherche.replace(regReplace, "[aâà]");
	var regReplace = new RegExp("[cç]", "ig");
		recherche = recherche.replace(regReplace, "[cç]");
	var regReplace = new RegExp("[iîï]", "ig");
		recherche = recherche.replace(regReplace, "[iîï]");
	var regReplace = new RegExp("[oôö]", "ig");
		recherche = recherche.replace(regReplace, "[oôö]");
	var regReplace = new RegExp("[uùûü]", "ig");
		recherche = recherche.replace(regReplace, "[uùûü]");

		var regReplace = new RegExp(" ", "ig");
		recherche = recherche.replace(regReplace, "(.+)?[ '-]+");
	
		if(recherche!='') recherche = "(^|[ '-])"+recherche;
	
	var regRecherche = new RegExp(recherche, "i");	

	// on recopie dans la liste les options ou l'ont trouve le texte recherché
	// (recherche non sensible à la casse)
	for(zzz=0 ; zzz < a_selects[objet.name].length; zzz++) {

		texte = a_selects[objet.name][zzz].text;

		var regReplace = new RegExp("[^a-zA-Z0-9âàäÂÀÄéèêëÉÈÊËîïÎÏôöÔÖùûüÙÛÜçÇ\\-' ]", "ig");
		texte = texte.replace(regReplace, " ");
		var regReplace = new RegExp("[ ]+", "ig");
		texte = texte.replace(regReplace, " ");

		if(regRecherche.test(texte)) { 	// Occurence trouvée
			objet.add(a_selects[objet.name][zzz]);					// On l'ajoute à la liste de destination
		}

	}

}

// ###############################################################################################################
// ######### Fonctions de formulaires ############################################################################
// ###############################################################################################################


function selectionneToutDansLaListe(listeCible) {
	elmt = document.getElementById(listeCible);
	taille=elmt.length;
	if(taille>0) {
	for (i=0; i<taille; i++) {
		elmt.options[i].selected = true;
	}
	}
}

	function selectionneToutDansLaListeOptGroup(listeCible, prefixOptGrps) {
		if(prefixOptGrps=='' || prefixOptGrps==null) { prefixOptGrps='optGrp'; }
		elmt = document.getElementById(listeCible);
		taille=elmt.length;
		if(taille>0) {
			for (i=0; i<taille; i++) {
				optGroupParentID = elmt.options[i].parentNode.id;
				elmt.options[i].value = optGroupParentID.replace(prefixOptGrps,'') +"=" + elmt.options[i].value;
				elmt.options[i].selected = true;
				//alert( elmt.options[i].value );
			}
		}
	}

function deselectionneToutDansLaListe(listeCible) {
	elmt = document.getElementById(listeCible);
	taille=elmt.length;
	if(taille>0) {
	for (i=0; i<taille; i++) {
		if(elmt.options[i].selected==true) { elmt.options[i].selected = false; }
	}
	}
}


function supprimerDeLaListe(listeDestination) {
	listeDestination = document.getElementById(listeDestination);
	// Si une ligne est sélectionnée, on la retire de la liste
	if(listeDestination.selectedIndex > -1) {
		listeDestination.remove(listeDestination.selectedIndex);
	} else {
		//alert("Sélectionnez l'élément de la liste à supprimer");
	}
}

	function supprimerDeLaListeOptGroup(listeDestination) {
		listeDestination = document.getElementById(listeDestination);
		// Si une ligne est sélectionnée, on la retire de la liste
		if(listeDestination.selectedIndex > -1) {
			if(listeDestination[listeDestination.selectedIndex].value != '-') { listeDestination.remove(listeDestination.selectedIndex); }
		} else {
			//alert("Sélectionnez l'élément de la liste à supprimer");
		}
	}

function ajouterAlaListe(listeSource,listeDestination) {

	existeDansListe = false;

	listeSource = document.getElementById(listeSource);
	listeDestination = document.getElementById(listeDestination);

	// Si une option a été sélectionnée dans la liste source, on exécute le code
	if(listeSource.selectedIndex != -1){

			// Est-ce que l'élément est déjà dans la liste ?
			for (i = 0; i<listeDestination.length; i++) {
				if(listeDestination.options[i].value == listeSource.options[listeSource.selectedIndex].value) {
					alert("« "+listeDestination.options[i].text+" » est déjà dans la liste !");
					existeDansListe = true;
					break;
				} 
			}
			
			// On ajoute l'option
			if(existeDansListe == false) {
				var nouvelElementListe = document.createElement("OPTION");
				nouvelElementListe.value = listeSource.options[listeSource.selectedIndex].value;
				nouvelElementListe.text = listeSource.options[listeSource.selectedIndex].text;
				listeDestination.options.add(nouvelElementListe);
			}
			
	} else {
		//alert("Merci de sélectionner l'élément à ajouter.");
	}

}

	function ajouterAlaListeOptGroup(listeSource,listeDestination) {
	
		existeDansListe = false;
	
		listeSource = document.getElementById(listeSource);
		listeDestination = document.getElementById(listeDestination);
	
		// Si une option a été sélectionnée dans la liste source, on exécute le code
		if(listeSource.selectedIndex != -1){
	
				// Est-ce que l'élément est déjà dans la liste ?
				for (i = 0; i<listeDestination.length; i++) {
					if(listeDestination.options[i].value == listeSource.options[listeSource.selectedIndex].value) {
						alert("« "+listeDestination.options[i].text+" » est déjà dans la liste !");
						existeDansListe = true;
						break;
					} 
				}
				
				// On ajoute l'option
				if(existeDansListe == false) {
					var nouvelElementListe = document.createElement("option");
					nouvelElementListe.value = listeSource.options[listeSource.selectedIndex].value;
					nouvelElementListe.text = listeSource.options[listeSource.selectedIndex].text;
	
					var optGrps = listeDestination.getElementsByTagName("optgroup")
	
					if(optGrps.length==0) { // Si pas de optgroup
	
						listeDestination.options.add(nouvelElementListe);
	
					} else { // Si présence de optgroups
	
						if(listeDestination.selectedIndex != -1) { // Si un élément est sélectionné, on insert avant celui-ci
							optGroupParent = listeDestination.options[listeDestination.selectedIndex].parentNode;
							optGroupParent.insertBefore(nouvelElementListe, listeDestination.options[listeDestination.selectedIndex]);
						} else { // sinon, on insert l'élément comme dernier enfant du dernier optgroup
							optGrps[optGrps.length-1].appendChild(nouvelElementListe);
							//listeDestination.insertBefore(nouvelElementListe, optGroupParent.options[optGroupParent.options.lastChild]);
							//alert(optGrps[optGrps.length-1].options);
							//optGrps.lastChild.insertBefore(nouvelElementListe, optGrps[2].options);
						}
	
					}
				}
				
		} else {
			//alert("Merci de sélectionner l'élément à ajouter.");
		}
	
	}

function descendreDansLaListe(listeCibleID) {
	listeCible = document.getElementById(listeCibleID);
	if(listeCible.selectedIndex > -1) {

	if(listeCible.selectedIndex < listeCible.length-1) {
	listeCibleValue = listeCible.options[listeCible.selectedIndex].value;
	listeCibleText = listeCible.options[listeCible.selectedIndex].text;

	listeCibleN1Value = listeCible.options[listeCible.selectedIndex+1].value;
	listeCibleN1Text = listeCible.options[listeCible.selectedIndex+1].text;

	listeCible.options[listeCible.selectedIndex].value = listeCibleN1Value;
	listeCible.options[listeCible.selectedIndex].text = listeCibleN1Text;
	
	listeCible.options[listeCible.selectedIndex+1].value = listeCibleValue;
	listeCible.options[listeCible.selectedIndex+1].text = listeCibleText;

	listeCible.options[listeCible.selectedIndex+1].selected=true;
	listeCible.options[listeCible.selectedIndex].selected=false;
	}

} else {
	//alert("Merci de sélectionner un élément dans la liste.");
}
}

	function descendreDansLaListeOptGroup(listeCibleID) {
	
		listeCible = document.getElementById(listeCibleID);
		listeCibleSelectedIndex = listeCible.selectedIndex;
	
		if(listeCible[listeCibleSelectedIndex].value=='-') { return false; }
	
		// les optgroups
		var optGrps = listeCible.getElementsByTagName("optgroup");
	
		optGroupParent = listeCible.options[listeCibleSelectedIndex].parentNode;
		if(listeCibleSelectedIndex < listeCible.options.length-1) {
			if(listeCible.options[listeCibleSelectedIndex+1].value != '-') {
				offset = 1;
			} else {
				offset = 2;
			}
	
			try { optGroupParentN1 = listeCible.options[listeCibleSelectedIndex + offset].parentNode; }
				catch(err) { return false; }
		}
	
		if(listeCible.selectedIndex < listeCible.options.length-1) {
	
			// si changement de optGroup
			if(optGrps.length>0 && optGroupParentN1.label != optGroupParent.label) {
				
				var nouvelElementListe = document.createElement("option");
				nouvelElementListe.value = listeCible.options[listeCibleSelectedIndex].value;
				nouvelElementListe.text = listeCible.options[listeCibleSelectedIndex].text;
				nouvelElementListe.className = listeCible.options[listeCibleSelectedIndex].className;
				nouvelElementListe.setAttribute('style', listeCible.options[listeCibleSelectedIndex].getAttribute('style'));
	
				optGroupParentN1.insertBefore(nouvelElementListe, optGroupParentN1.firstChild);
				listeCible.options[listeCibleSelectedIndex].remove();
	
				optGroupParentN1.firstChild.selected=true;
	
			} else {
		
				// On stock les valeurs de n
				listeCibleValue = listeCible.options[listeCibleSelectedIndex].value;
				listeCibleText = listeCible.options[listeCibleSelectedIndex].text;
				listeCibleClassName = listeCible.options[listeCibleSelectedIndex].className;
				listeCibleStyle = listeCible.options[listeCibleSelectedIndex].getAttribute('style');
	
				if(listeCible.options[listeCibleSelectedIndex+1].value != '-') {
					offset = 1;
				} else {
					offset = 2;
				}

				// On stock les valeurs de n + offset
				listeCibleN1Value = listeCible.options[listeCibleSelectedIndex + offset].value;
				listeCibleN1Text = listeCible.options[listeCibleSelectedIndex + offset].text;
				listeCibleN1ClassName = listeCible.options[listeCibleSelectedIndex + offset].className;
				listeCibleN1Style = listeCible.options[listeCibleSelectedIndex + offset].getAttribute('style');
			
				// Attributs de n = n+1
				listeCible.options[listeCibleSelectedIndex].value = listeCibleN1Value;
				listeCible.options[listeCibleSelectedIndex].text = listeCibleN1Text;
				listeCible.options[listeCibleSelectedIndex].className = listeCibleN1ClassName;
				listeCible.options[listeCibleSelectedIndex].setAttribute('style', listeCibleN1Style);
				// Attributs de n+1 = n
				listeCible.options[listeCibleSelectedIndex + offset].value = listeCibleValue;
				listeCible.options[listeCibleSelectedIndex + offset].text = listeCibleText;
				listeCible.options[listeCibleSelectedIndex + offset].className = listeCibleClassName;
				listeCible.options[listeCibleSelectedIndex + offset].setAttribute('style', listeCibleStyle) ;
			
				// on sélectionne le nouvel élément
				listeCible.options[listeCibleSelectedIndex + offset].selected=true;
				// on dé-sélectionne l'ancien élément
				listeCible.options[listeCibleSelectedIndex].selected=false;
	
			}
		}
	}

function monterDansLaListe(listeCibleID) {
	listeCible = document.getElementById(listeCibleID);
	if(listeCible.selectedIndex > -1) {

		if(listeCible.selectedIndex !=0) {
	
		listeCibleSelectedIndex = listeCible.selectedIndex;
	
		listeCibleValue = listeCible.options[listeCible.selectedIndex].value;
		listeCibleText = listeCible.options[listeCible.selectedIndex].text;
	
		listeCibleN1Value = listeCible.options[listeCible.selectedIndex-1].value;
		listeCibleN1Text = listeCible.options[listeCible.selectedIndex-1].text;
	
		listeCible.options[listeCible.selectedIndex].value = listeCibleN1Value;
		listeCible.options[listeCible.selectedIndex].text = listeCibleN1Text;
		
		listeCible.options[listeCible.selectedIndex-1].value = listeCibleValue;
		listeCible.options[listeCible.selectedIndex-1].text = listeCibleText;
	
		listeCible.options[listeCibleSelectedIndex-1].selected=true;
		listeCible.options[listeCibleSelectedIndex].selected=false;
		}

	} 
}

	function monterDansLaListeOptGroup(listeCibleID) {
		listeCible = document.getElementById(listeCibleID);
		listeCibleSelectedIndex = listeCible.selectedIndex;
	
		if(listeCible[listeCibleSelectedIndex].value=='-') { return false; }
	
		// les optgroups
		var optGrps = listeCible.getElementsByTagName("optgroup");
	
		optGroupParent = listeCible.options[listeCibleSelectedIndex].parentNode;
		if(listeCibleSelectedIndex>0) optGroupParentN1 = listeCible.options[listeCibleSelectedIndex-1].parentNode;
	
		// Si un élément est sélectionné
		if(listeCibleSelectedIndex > -1 && listeCibleSelectedIndex !=0) {
			
			// si changement de optGroup
			if(optGrps.length>0 && optGroupParentN1.label != optGroupParent.label) {
				
				var nouvelElementListe = document.createElement("option");
				nouvelElementListe.value = listeCible.options[listeCibleSelectedIndex].value;
				nouvelElementListe.text = listeCible.options[listeCibleSelectedIndex].text;
				nouvelElementListe.className = listeCible.options[listeCibleSelectedIndex].className;
				nouvelElementListe.setAttribute('style', listeCible.options[listeCibleSelectedIndex].getAttribute('style'));
	
				// si la valeur du dernier élément de l'optgroup précédent != '-'
				if(listeCible.options[listeCibleSelectedIndex-1].value != '-') {
					listeCible.options[listeCibleSelectedIndex].remove();
					optGroupParentN1.appendChild(nouvelElementListe);
					optGroupParentN1.lastChild.selected=true;
				} else {
					listeCible.options[listeCibleSelectedIndex].remove();
					optGroupParentN1.insertBefore(nouvelElementListe, listeCible.options[listeCibleSelectedIndex-1]);
					listeCible.options[listeCibleSelectedIndex-1].selected=true;
				}
	
			} else {
		
				// On stock les valeurs de n
				listeCibleValue = listeCible.options[listeCibleSelectedIndex].value;
				listeCibleText = listeCible.options[listeCibleSelectedIndex].text;
				listeCibleClassName = listeCible.options[listeCibleSelectedIndex].className;
				listeCibleStyle = listeCible.options[listeCibleSelectedIndex].getAttribute('style');
	
				if(listeCible.options[listeCibleSelectedIndex-1].value != '-') {
					offset = 1;
				} else {
					offset = 2;
				}
	
				// On stock les valeurs de n - offset
				listeCibleN1Value = listeCible.options[listeCibleSelectedIndex - offset].value;
				listeCibleN1Text = listeCible.options[listeCibleSelectedIndex - offset].text;
				listeCibleN1ClassName = listeCible.options[listeCibleSelectedIndex - offset].className;
				listeCibleN1Style = listeCible.options[listeCibleSelectedIndex - offset].getAttribute('style');
			
				// Attributs de n = n-1
				listeCible.options[listeCibleSelectedIndex].value = listeCibleN1Value;
				listeCible.options[listeCibleSelectedIndex].text = listeCibleN1Text;
				listeCible.options[listeCibleSelectedIndex].className = listeCibleN1ClassName;
				listeCible.options[listeCibleSelectedIndex].setAttribute('style', listeCibleN1Style);
				// Attributs de n-1 = n
				listeCible.options[listeCibleSelectedIndex - offset].value = listeCibleValue;
				listeCible.options[listeCibleSelectedIndex - offset].text = listeCibleText;
				listeCible.options[listeCibleSelectedIndex - offset].className = listeCibleClassName;
				listeCible.options[listeCibleSelectedIndex - offset].setAttribute('style', listeCibleStyle) ;
			
				// on sélectionne le nouvel élément
				listeCible.options[listeCibleSelectedIndex - offset].selected=true;
				// on dé-sélectionne l'ancien élément
				listeCible.options[listeCibleSelectedIndex].selected=false;
	
			}
	
		}
	}

/*
function filtrer(objet, recherche) {
//
// Fonction de tri sur une liste
// 
// ATTENTION ! 'recherche' doit pointer vers des objets et non pas des valeurs

	// si les tableaux principaux de réplication n'ont pas déjà été créés, on les crée
	if(typeof(index) == "undefined") {
		index = new Array;	
		texte = new Array;
	}

	// si le tableau de réplication de CETTE liste n'a pas encore été créé, on le crée
	// L'index du tableau est le nom de la liste
	if(typeof(index[objet.name]) == "undefined") {
		index[objet.name] = new Array;
		texte[objet.name] = new Array;

		for(zzz=0 ; zzz < objet.options.length ; zzz++) {
			index[objet.name][zzz] = objet.options[zzz].value;
			texte[objet.name][zzz] = objet.options[zzz].text;
		}
	}
	
	// on efface le contenue de la liste
	while(objet.options.length = 0) {
		objet.options.remove(0);
	}
	
	// on recopie dans la liste les options ou l'ont trouve le texte recherché
	// (recherche non sensible à la casse)
	for(zzz=0 ; zzz < index[objet.name].length; zzz++) {

		if(texte[objet.name][zzz].toLowerCase().indexOf(recherche.value.toLowerCase()) > -1) {
			var nouvelElement = document.createElement("OPTION");
			nouvelElement.value = index[objet.name][zzz];
			nouvelElement.text = texte[objet.name][zzz];
			objet.options.add(nouvelElement);
		}
	}
}
*/

/* ------------- Groupe de champs date et heure -------------------------------------*/ 

function formateDate(source) { 
	// Version modifiée (27/09/2007)
	// Le formulaire doit comporter 5 champs :
	// jourECRANdateDebut, moisECRANdateDebut, anneeECRANdateDebut, dateDebut, nomJourdateDebut
	// Ce qui apparait après ECRAN doit être el nom du champs de destination
	// Exemple : destination = jourECRANdateDebut -> dateDebut
	destination = source.id.substr(source.id.indexOf('ECRAN')+5); 
	srcAnnee=document.getElementById('anneeECRAN'+destination);
	srcMois=document.getElementById('moisECRAN'+destination);
	srcJour=document.getElementById('jourECRAN'+destination);

	if(srcAnnee.value!='' && srcMois.value!='' && srcJour.value!='' && srcAnnee.value.length==4) {

		// Corrige les saisies courtes (sans les 0)  Jour ou mois : 4 -> 04 ou année : 06 -> 2006
		//annee=(srcAnnee.value.length != 4)? "2000".substr(0, 4-srcAnnee.value.length)+srcAnnee.value : srcAnnee.value;
		annee=srcAnnee.value;
		mois=(srcMois.value.length == 1) ? "0"+srcMois.value : srcMois.value;
		jour=(srcJour.value.length == 1)? "0"+srcJour.value : srcJour.value;
		// on affiche aaaammjj
		document.getElementById(destination).value = annee+mois+jour; 
		// on affiche le nom du jour
		if(document.getElementById('nomJour'+destination)) {
			document.getElementById('nomJour'+destination).value = nomDuJour(jour, mois, annee);
		}
	
	} else {

		document.getElementById(destination).value = ''; 
		if(document.getElementById('nomJour'+destination)) {
			document.getElementById('nomJour'+destination).value = '';
		}

	}
}

function formateDateHeure(source) { 
	// Version modifiée (28/03/2006)
	// Le formulaire doit comporter 5 champs :
	// jourECRANdateDebut, moisECRANdateDebut, anneeECRANdateDebut, dateDebut, nomJourdateDebut
	// Ce qui apparait après ECRAN doit être le nom du champs de destination
	// Exemple : destination = jourECRANdateDebut -> dateDebut
	destination = source.id.substr(source.id.indexOf('ECRAN')+5); 
	srcAnnee=document.getElementById('anneeECRAN'+destination);
	srcMois=document.getElementById('moisECRAN'+destination);
	srcJour=document.getElementById('jourECRAN'+destination);
	
	if(srcAnnee.value!='' && srcMois.value!='' && srcJour.value!='' && srcAnnee.value.length == 4) {

		if(document.getElementById('heureECRAN'+destination)) srcHeure=document.getElementById('heureECRAN'+destination);
		// Corrige les saisies courtes (sans les 0)  Jour ou mois : 4 -> 04 ou année : 06 -> 2006
		annee=(srcAnnee.value.length != 4)? "2000".substr(0, 4-srcAnnee.value.length)+srcAnnee.value : srcAnnee.value;
		//annee=srcAnnee.value;
		mois=(srcMois.value.length == 1) ? "0"+srcMois.value : srcMois.value;
		jour=(srcJour.value.length == 1)? "0"+srcJour.value : srcJour.value;
		if(srcHeure) heure=(srcHeure.value == '')? "000000" : srcHeure.value.replace(':','').replace('h','').replace('H','').replace(' ','').replace('-','')+"00"; 
		// on affiche aaaammjjhhss00
		document.getElementById(destination).value = annee+mois+jour+heure; 
		// on affiche le nom du jour si le champs existe
		if(document.getElementById('nomJour'+destination)) document.getElementById('nomJour'+destination).value = nomDuJour(jour, mois, annee);
	
	} else {
	
		document.getElementById(destination).value = ''; 
	
	}
}


function nomDuJour(INjour, INmois, INannee) {
	var nomJour = new Array('dimanche','lundi','mardi','mercredi','jeudi','vendredi','samedi')
	var jour = new Date(INannee, INmois-1, INjour);
	//alert(jour);
	return nomJour[jour.getDay()];
}


function maintenant(groupechamps) {
	var dateDebut=new Date(); 
	document.getElementById('jourECRAN'+groupechamps).value=str_pad(dateDebut.getDate(), 2, '0', 'STR_PAD_LEFT');
	document.getElementById('moisECRAN'+groupechamps).value=str_pad(dateDebut.getMonth()+1, 2, '0', 'STR_PAD_LEFT'); 
	document.getElementById('anneeECRAN'+groupechamps).value=dateDebut.getFullYear(); 
	document.getElementById('heureECRAN'+groupechamps).value=str_pad(dateDebut.getHours(), 2, '0', 'STR_PAD_LEFT')
																+':'+str_pad(dateDebut.getMinutes(), 2, '0', 'STR_PAD_LEFT');
	formateDateHeure(document.getElementById('jourECRAN'+groupechamps));
}

function diffdate(d1,d2){
	// Retourne la différence en jours entre deux dates
	// A utiliser comme ceci :
	// var Date1 = new Date(2010,9,31);
	// var Date2 = new Date(2010,10,1);
 	// alert(diffdate(Date1,Date2) + ' jours');

	// Nombre de millisecondes dans un jour
    var ONE_DAY = 1000 * 60 * 60 * 24;

    // Conversion des dates en millisecondes
    var date1_ms = d1.getTime();
    var date2_ms = d2.getTime();

    // Différence en millisecondes
    var difference_ms = date1_ms - date2_ms;
    
    // On retourne le tout converti en jours
    return Math.round(difference_ms/ONE_DAY);
}

/* ----------------------------------- */


// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}


// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire+ "; path=/";
}


// ###############################################################################################################
// ######### Page de garde #######################################################################################
// ###############################################################################################################

 
	function toggleAgenda() { // déroulement de l'agenda : prochainement <-> aujourd'hui
		/*if(typeof(document.getElementById('agendaProchainement')) == "object") {

			if(document.getElementById('agendaAujourdhui').style.display=='block') {
				document.getElementById('agendaAujourdhui').style.display='none';
				document.getElementById('agendaProchainement').style.display='block';
			} else if(document.getElementById('agendaAujourdhui').style.display=='none') {
				document.getElementById('agendaAujourdhui').style.display='block';
				document.getElementById('agendaProchainement').style.display='none';	
			}
			
			if(typeof(timerToggleAgenda) != "undefined") { clearTimeout(timerToggleAgenda); }
			timerToggleAgenda = setTimeout("toggleAgenda();", 15000);

		}*/
		document.getElementById('agendaAujourdhui').style.display='block';
		document.getElementById('agendaProchainement').style.display='block';

	}




function urlhttp(element) {
	element.value = ltrim(element.value)
	if(element.value.substring(0, 7) == "http://"){
		element.value = element.value.substr(7, element.value.length)
	}

}


function ltrim(argvalue) {

  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }

  return argvalue;
}



function majuscule(element) {
//alert(element.value.charCodeAt(0));
	if( element.value.charCodeAt(0)<65 || element.value.charCodeAt(0)>90 ) {
		element.value = element.value.substr(0,1).toUpperCase() +
						element.value.substr(1);
	}

	if( element.value.length==1 
	|| element.value.charAt(element.value.length-2)=='-' 
	|| element.value.charAt(element.value.length-2)==' ' 
	|| element.value.charAt(element.value.length-2)=="'"
	|| element.value.charAt(element.value.length-2)=='.' ) 
	{
	element.value= element.value.substring(0, element.value.length-1)
				 + element.value.substring(element.value.length-1, element.value.length).toUpperCase()
	}

}

function showHide(block) {
	if(document.getElementById(block).style.display=='none' || document.getElementById(block).style.display=='') {
		document.getElementById(block).style.display='block'
	}else{
		document.getElementById(block).style.display='none'
	}
}


// -----------------------------------------------------------------------------
// Défilement 4 directions multiple

function Defilant(id, pos_init, pos_min, pos_max, delta, direction) {
   this.id          = id;
   this.element     = document.getElementById(id);
   this.pos_init    = pos_init;
   this.pos_min     = pos_min;
   this.pos_max     = pos_max;
   this.pos_current = pos_init;
   this.delta       = delta;
   this.direction   = direction;
}

Defilant.prototype.defile = function() {
   if (!this.element) {
	  this.element = document.getElementById(this.id);
   }

   if (this.element) {
	  if(this.direction == 'vertical'){

		 if(this.pos_current < (this.pos_min - this.element.offsetHeight) ){
			this.pos_current = this.pos_init;
		 } else if (this.pos_current > this.pos_max ) {
			this.pos_current = this.pos_init - this.element.offsetHeight;
		 } else {
			this.pos_current += this.delta;
		 }

		 this.element.style.top = this.pos_current+"px";

	  } else if(this.direction == 'horizontal') {

		 if(this.pos_current < (this.pos_min - this.element.offsetWidth) ){
			this.pos_current = this.pos_init;
		 } else if (this.pos_current > this.pos_max ) {
			this.pos_current = this.pos_init - this.element.offsetWidth;
		 } else {
			this.pos_current += this.delta;
		 }

		 this.element.style.left = this.pos_current+"px";

	  }

   }

}



/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid, action, callback){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid, action, callback)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid, action, callback){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		if(action=='update') {
			document.getElementById(containerid).innerHTML=page_request.responseText;
		} else if(action=='add') {
			objectToAppend = document.createElement("div");
			objectToAppend.innerHTML = page_request.responseText;
			document.getElementById(containerid).appendChild(objectToAppend);
		//document.getElementById(containerid).innerHTML=page_request.responseText;
		//document.getElementById(containerid).innerHTML=page_request.responseText;
		}
		if(callback!='') callback.call();
	}
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}





function actualise_tchatBox() {

	ajaxpage('http://www.mairie-athis-mons.fr/webcam/v4_tchat.php', 'tchatBox');

/*	var objDiv = document.getElementById("tchatBox");
	if(objDiv.scrollHeight) { 
		objDiv.scrollTop = objDiv.scrollHeight;
	} else { 
		objDiv.scrollTop = objDiv.offsetHeight;
	}
*/
	tchatRefresh=window.setTimeout("actualise_tchatBox();", 5000);
	//objDiv.scrollTop = objDiv.scrollHeight;
}

function actualise_listePresents() {
	ajaxpage('http://www.mairie-athis-mons.fr/webcam/v4_presents.php', 'listePresents');
	tchatRefresh=window.setTimeout("actualise_listePresents();", 5000);
}

function str_pad (input, pad_length, pad_string, pad_type)
{
  input = String (input);
  pad_string = pad_string != null ? pad_string : " ";
  if (pad_string.length > 0)
  {
    var padi = 0;
    pad_type = pad_type != null ? pad_type : "STR_PAD_RIGHT";
    pad_length = parseInt (pad_length);
    switch (pad_type)
    {
      case "STR_PAD_BOTH":
        input = str_pad (input
                       , input.length + Math.ceil ((pad_length - input.length) / 2.0)
                       , pad_string, "STR_PAD_RIGHT");
     // break;  // kein break!
      case "STR_PAD_LEFT":
        var buffer = "";
        for (var i = 0, z = pad_length - input.length; i < z; ++i)
        {
          buffer += pad_string.charAt(padi); // [padi] IE 6.x bug
          if (++padi == pad_string.length)
            padi = 0;
        }
        input = buffer + input;
        break;
      default:
        for (var i = 0, z = pad_length - input.length; i < z; ++i)
        {
          input += pad_string.charAt(padi);
          if (++padi == pad_string.length)
            padi = 0;
        }
        break;
    }
  }
  return input;
}




/* ------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------- */


if(window.attachEvent) { window.attachEvent("onload", menuHover); } 

if (!readCookie("UID")) {
	var	valeur = Math.round(Math.random()*1000000000000000000);
	writeCookie("UID", valeur, 24*31*12*10);
}



