// POUR LE MENU DU BACK-OFFICE ----------------------------------------------------------------------------- >>
function montre(id) {
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
			if (navigator.appName=="Microsoft Internet Explorer") swapmenuUp("select");
		}
	}
	if (d) {
		d.style.display='block';
		if (navigator.appName=="Microsoft Internet Explorer") swapmenuDown("select");
	}
}
function swapmenuDown(tag) {
	tab = document.getElementsByTagName(tag);
	for(var i=0;i<tab.length;i++) {
			tab[i].style.visibility = "hidden";
	}
}

function swapmenuUp(tag) {
	tab = document.getElementsByTagName(tag);
	for(var i=0;i<tab.length;i++) {
			tab[i].style.visibility = "visible";
	}
}

/* POUR LES ONGLETS */
function aff_onglet(id){
	for (var i = 0; i<=10; i++) {
		if (document.getElementById('onglet_'+i)) {
			document.getElementById('onglet_'+i).style.display = 'none';
			document.getElementById('btn_'+i).className = 'btn_off';
		}
	}
	document.getElementById('onglet_'+id).style.display = 'block';
	document.getElementById('btn_'+id).className = 'btn_selected';
}


// FERMER UN GREYBOX --------------------------------------------------------------------------------------- >>
function fermer_greybox(){
	parent.parent.GB_hide();
}

// SUPPRIMER LES IMAGES DANS LE GESTIONNAIRE D'IMAGES ET DE FICHIERS --------------------------------------- >>
function sup_asso(id) {
	document.getElementById("document_"+id).style.display = "none";
	document.forms.form1.ids_fich.value =  document.forms.form1.ids_fich.value.replace(id+",", "");
}

function sup_asso_img(id) {
	document.getElementById("image_"+id).style.display = "none";
	document.forms.form1.ids_img.value =  document.forms.form1.ids_img.value.replace(id+",", "");
}

// AFFICHER / MASQUER UNE DIV ------------------------------------------------------------------------------ >>
function swap(madiv){
	var etat = document.getElementById(madiv).style.display;
	if(etat == "none"){
		document.getElementById(madiv).style.display = "block";
	} else {
		document.getElementById(madiv).style.display = "none";
	}
}

// AFFICHER / MASQUER UNE DIV SELON ETAT ------------------------------------------------------------------- >>
function swapChoose(madiv,etat){
	if(etat == "none"){
		document.getElementById(madiv).style.display = "none";
	} else if (etat == "block") {
		document.getElementById(madiv).style.display = "block";
	} else if (etat == "inline") {
		document.getElementById(madiv).style.display = "inline";
	}
}

// TOUT DEPLIER / TOUT MASQUER ----------------------------------------------------------------------------- >>
function swapAllDown(){
	var tab = document.getElementsByTagName("div");
	for(i=0;i<tab.length; i++){
		if (tab[i].getAttribute("label") == "swapy") {
		tab[i].style.display = "none";
		}
	}
}
function swapAllUp(){
	var tab = document.getElementsByTagName("div");
	for(i=0;i<tab.length; i++){
		if (tab[i].getAttribute("label") == "swapy") {
		tab[i].style.display = "block";
		}
	}
}

// POP UN D'AIDE ------------------------------------------------------------------------------------------ >>
function helpop(hcheminh) {
	window.open(hcheminh+"aide.php","Aide","height=625, width=625 ,toolbar=no, scrollbars=yes");
}

function supprimer(quoi, urltraitement){
	if(confirm("Es-tu sûr de vouloir supprimer "+quoi+"?")){
		document.location.href = urltraitement;
	}
}

function reinitialiserInput(obj, defaut){
	if(obj.value=='')	obj.value = defaut;
}
function viderInput(obj, defaut){
	if(obj.value==defaut)	obj.value = '';
}



///////////////////////// ROBIN

////////////// GOTO ETAPE SUIVANTE ------------------------------------------------------>
function gotoEtape(nom, id){
	for (var i=0; i<=20; i++) {
		if (document.getElementById(nom+i)) {
				document.getElementById(nom+i).style.display = 'none';
				document.getElementById("btn_suivant_"+i).className = '';
		}
	}

	document.getElementById("form_etape_"+id).style.display = 'block';
	document.getElementById("btn_suivant_"+id).className = 'selected';

	return true;
}

function verif_email(email){
    var verif = /^[^@]+@(([\w\-]+\.){1,4}[a-zA-Z]{2,4}|(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5]))$/
    return ( verif.test(email) );
}

function ChercheValeurRadio(nb_radio, nom_form, nom_champ)
	{
	for(i=0;i<nb_radio;i++)
		eval("if(document.forms."+nom_form+"."+nom_champ+"[i].checked)	valeur = document.forms."+nom_form+"."+nom_champ+"[i].value");
	return valeur;
	}

//Fonction permettant de récupérer n'importe quel valeur d'un élément de formulaire
function getFormElementValue(e) {
	if (e.type == 'radio') {
		return getFormRadioValue(e);
	} else if (e.type == 'checkbox') {
		return getFormCheckValue(e);
	} else {
		return e.value;
	}
}

//renvoi la valeur d'un checkbox
function getFormCheckValue(e) {
	if (e.checked) {
		return e.value;
	}
	return null;
}
//renvoi la valeur dun bouton radio
function getFormRadioValue(e) {
	for (var i=0; i <e.length; i++) {
		if (e[i].checked) {
			return e[i].value;
		} else {
			return null;
		}
	}
}
/////


//vérifie le traitement d'une action définie
function verifierTraitement(nom_form, nom_champs, nb_champs, debut, id_champs_verif, lien){
	//nom du traitement à vérifier
	formulaire =  "document."+nom_form;
	nom_traitement = formulaire+"."+nom_champs;

	//
	if(compterNbCasesChochees(nom_form, id_champs_verif, nb_champs, debut)){
		//pour suppression
		if(eval(nom_traitement+".value") == 'supprimer'){
			if(confirm('Etes-vous sûr de vouloir supprimer tous les éléments sélectionnés ?')){
				eval(formulaire+".action = '"+lien+"'");
				eval(formulaire+".submit()");
			}
			else return false;
		}
	}
	else alert("Vous devez sélectionner au moins un élément dans la liste !");
}


function compterNbCasesChochees(nom_form, id_champs, nb_champs, debut)
	{
	//initialisation du compteur
	compteur = 0;

	//on recupère l'id du formulaire et de la case à cocher
	id_checkbox = "document."+nom_form+"."+id_champs;

	for(i=debut; i<nb_champs; i++)
		if (eval(id_checkbox+i+".checked == true")) compteur++;

	//
	if(compteur > 0) return true;
	else return false;
	}

function CocherCase(nom_form, id_champs, nb_champs, debut, action)
	{
	//on recupère l'id du formulaire et de la case à cocher
	id_checkbox = "document."+nom_form+"."+id_champs;

	if(action == 'cocher')
		{
		for(i=debut; i<nb_champs; i++)
			{
			if(eval(id_checkbox+i+".disabled == false")) eval(id_checkbox+i+".checked = true");
			}
		}
	else if(action == 'decocher')
		{
		for(i=debut; i<nb_champs; i++) eval(id_checkbox+i+".checked = false");
		}
	}
//-->


function popupcentree(page,largeur,hauteur,options){
	var top = (screen.height-hauteur)/2;
	var left = (screen.width-largeur)/2;
	window.open(page,"pop","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function confirmerSortirPage(){
	if(confirm("Etes-vous sûr de vouloir quitter la page en cours ?")) return true;
	else{
		return false;
		//document.location.href = '/mon_compte/messages/messages_composer.php?recup=1';
	}
}

// AJOUTER UN MSG DANS UNE DIV EN INNER HTML  -------------------------------------------------- >> # 07/05/2007
function affiche_inner(msg, div){
	document.getElementById(div).innerHTML = msg;
}

// SUPPRIMER UNE IMAGE EN AJAX ----------------------------------------------------------------- >> # 04/05/2007
function ajax_supprimer_photo(id,mode,fichier_traitement,id_inner){
	var xhr_object = null;
	var data=null;
	if(window.XMLHttpRequest) // Firefox
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	data = id;
	xhr_object.open("POST", fichier_traitement+"?mode="+mode+"&id="+id, true);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send(data);
	xhr_object.onreadystatechange = function(){
		if(xhr_object.readyState == 4){
			infos = xhr_object.responseText;
			document.getElementById(id_inner).innerHTML = infos;
		}
	}
}

// STYLE DIV VISIBLE -------------------------------------------------------------------------- >> # 07/05/2007
function visible(div){
	var etat = document.getElementById(div).style.display;
	if(etat == "block"){
		var retour = "none";
	} else {
		var retour = "block";
	}
	document.getElementById(div).style.display = retour;

}

// GENERER UNE CHAINE TYPE URL8REWRITING ------------------------------------------------------ >> # 15/05/2007
function generer_url(chaine, champs){
		var nurl = chaine.toLowerCase();
		var remplacer = Array("#¤-", "?¤-", "ù¤u", "ô¤o", "û¤u", "î¤i", ".¤-", "|¤-", "_¤-", ",¤-", "°¤-",
			"ü¤u", "ë¤e", "ö¤o", "ë¤e", "ê¤e", "%¤-", "(¤-", ")¤-", "ç¤c", "*¤-", "²¤2", '"¤-', "\\¤-",
			"¨¤-", "^¤-", "é¤e", "è¤e", "à¤a", "'¤-", "&¤et", "@¤a", "/¤-", " ¤-",
			"&¤et", "&amp;¤et", "â¤a", '"¤', "+¤-", "!¤-", "$¤", ":¤-", ";¤-", "§¤", "=¤", "}¤", "]¤",
			"`¤", "[¤", "{¤", "<¤-", ">¤-", "--¤-");
		for( var j=0; j < remplacer.length; j++){
			var chaine2 = remplacer[j].split("¤");
			while(nurl.indexOf(chaine2[0]) != -1){
				nurl = nurl.replace(chaine2[0], chaine2[1]);
			}
		}

		if(nurl.indexOf("-") == 0){ nurl = nurl.replace("-", ""); }
		if(nurl.lastIndexOf("-") == nurl.length-1){ nurl = nurl.substring(0, nurl.length-1);}
		var newurl = (nurl+".html").toLowerCase();
		document.getElementById(champs).value = newurl;
	}

// GENERER UNE CHAINE TYPE URL8REWRITING ------------------------------------------------------ >> # 22/08/2007
function alea(longeur) {
	var aleatoire;
	var chaine = '';
	var cars = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
	for(i=0; i<=longeur; i++){
		aleatoire = Math.round((Math.random()*35));
		chaine += cars[aleatoire];
	}
	return chaine;
}


// FONCTIONS AJAX ///////////////////////////////////////////////////////////////////////////////////////////////////////

////////////// SUPPRESSION GENERIQUE AJAX ------------------------------------------------------>
function ajax_supprimer(id, mode, fichier_traitement, id_inner){
	if(confirm("Etes-vous sûr de bien vouloir supprimer ?")){
		var xhr_object = null;
		var data=null;
		if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest(); // Firefox
		else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
		else { // XMLHttpRequest non supporté par le navigateur
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); return;
		}

		data = id;
		xhr_object.open("POST", fichier_traitement+"?mode="+mode+"&id="+id, true);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send(data);
		xhr_object.onreadystatechange = function(){
			if(xhr_object.readyState == 4){
				infos = xhr_object.responseText;
				document.getElementById(id_inner).innerHTML = infos;
				if(infos=="") alert("Suppression effectuée !");
				else alert("Erreur lors de la suppression !");
			}
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// TOUT COCHER / DECOCHER ------------------------------------------------------------------------ >> 16/06/2007
function tout_cocher(nom,action){
	if(action == "cocher") var coche = true;
	if(action == "decocher") var coche = false;

	var field = document.getElementsByName(nom+"[]");

	for(i=0; i<field.length; i++){
		field[i].checked = coche;
	}
}
