//variable pour l'effacement du texte dans le moteur de recherche
var erased_annuaire = false;

//on enleve les erreurs eventuelles
function no_error()
{ return true; }
window.onerror = no_error;

function open_popup(page,hauteur,largeur)
//ouvre une popup
{ window.open(page,"Popup","status=no,scrollbars=yes,resizable=no,height="+hauteur+",width="+largeur+",top=0,left=0"); }

function confirm_delete(page, texte)
//demande une confirmation avant de supprimer un site ou une categorie
{
	confirmation = confirm('Etes vous sur de vouloir supprimer '+texte+' ? ');
	if(confirmation)
		window.location.replace(page);
}

function message_annu_status(message)
//affiche un texte dans la barre de statut du navigateur
{ window.status = message; }

function check_id_cat()
//verifie si on a bien selectionner une categorie dans la liste deroulante
{
	if (document.form2submit.id_cat.value == 0)
	{
		alert('Veuillez sélectionner une catégorie !');
		return false;
	}
	else
	{ return true; }
}

function clk(id)
{
(new Image()).src="goto.php?id="+id;
return true;
}

function visibilite(thingId)
{
var targetElement;
targetElement = document.getElementById(thingId) ;
if (targetElement.style.display == "none")
{
targetElement.style.display = "" ;
} else {
targetElement.style.display = "none" ;
}
}



function ShowDiv () {
       
                //tab_argumemts = tableau des arguments (=id des div) passés lors de l'appel de la fonction ShowDiv   
        var tab_argumemts = ShowDiv.arguments;
               
                // Si plus d'un id donné en argument on appelle la fonction AmtShowDiv en lui passant le tableau des arguments sinon l'id correspond au premier (et dernier) élément du tableau.
                if (tab_argumemts.length > 1) AmtShowDiv (tab_argumemts); else var id = tab_argumemts[0];
               
        var id_show;
       
        //Si l'id correspond à un id existant
        if (id_show = document.getElementById(id))
                {
                        // Inverse l'état du div : s'il est à "display : none", sa largeur id_show.offsetWidth = 0
                        var showHide = id_show.offsetWidth > 0 ? 'none' : 'block';
                        id_show.style.display = showHide;
                       
                       
                        var tab_cook_showDiv;
                       
                        // Cherche le cookie affecté à cette page et s'il existe le désérialise
                        tab_cook_showDiv = (tab_cook_showDiv = GetCookie(SetNomCookie())) ? Unserialize(tab_cook_showDiv) : null;                              

                        // Vérifie que le résultat tab_cook_showDiv est un tableau sinon initialise cette variable en tableau
                        tab_cook_showDiv = (typeof tab_cook_showDiv == 'object' && tab_cook_showDiv instanceof Array) ? tab_cook_showDiv : new Array();
                       
                        // Enregistre l'état de la div avec l'id comme index de l'élément dans le tableau (crée l'élément ou le remplace)
                        tab_cook_showDiv[id] = showHide;
                       
                        // Envoi le tableau sérialisé dans un cookie dont le nom est "SetNomCookie()"
                        SetCoockie (SetNomCookie(), Serialize(tab_cook_showDiv));      
                       
                }
}



function InitShowDiv () {
       
         
        var cookie_showDiv;
       
        // Cherche le cookie affecté à cette page (ayant pour nom SetNomCookie()) et s'il existe ...
        if (cookie_showDiv = GetCookie(SetNomCookie()))
       
                {              
                                        // Désérialise le tableau enregistré dans le cookie
                                        var tab_cook_showDiv = Unserialize(cookie_showDiv);
                                   
                                        // Si tab_cook_showDiv est un objet et un tableau
                                        if(typeof tab_cook_showDiv == 'object' && tab_cook_showDiv instanceof Array)
                   
                                                {
       
                                                        // Affiche les div suivant leur état "block" ou "none" enregistrés dans le tableau du cookie de la page)
                                                       
                                                        // Liste le tableau associatif
                                                        for (var id in tab_cook_showDiv)
                                                                 {
                                                                        var affich_id;
                                                                        // Si l'index de l'élément du tableau correspond à un id existant de la page en cours => affecte son affichage avec sa valeur enregistrée
                                                                        if (affich_id = document.getElementById(id))  affich_id.style.display = tab_cook_showDiv[id];
                                                                 }
                                               
       
                                                        // Renvoie le même cookie pour prolongation de sa durée de vie dès le chargement de la page
                                                        SetCoockie (SetNomCookie(), cookie_showDiv);
                                                }                      
                }
                 
}



function addLoadInitShowDiv(func) {
    //http://www.alsacreations.com/article/lire/565-JavaScript-organiser-son-code-en-modules.html
        if (window.addEventListener)
        {
      window.addEventListener("load", func, false);
    }
        else if (document.addEventListener)
        {
      document.addEventListener("load", func, false);
    }
        else if (window.attachEvent)
        {
      window.attachEvent("onload", func);
    }
}
 
addLoadInitShowDiv(InitShowDiv);



function AmtShowDiv (tab_argumemts) {
               
                //tab_argumemts = Tableau des arguments (=id des div) transmis par la fonction ShowDiv (si le nombre des arguments > 1)
               
               
                // Crée une variable composée de la concaténation des id des div passés en paramètre lors de l'appel de la fonction.
                //Cette variable permet d'identifier des appels à la fonction provenant de blocs différents                                                                                                                                                                                                                                                                                  
                var div_concat = '';
                for (var i=0; i < tab_argumemts.length; i++) {div_concat += tab_argumemts[i];}
               
               
                /* Création d'une propriété (avec le mot-clé this) se référent à elle-même, ce qui revient à créer une variable qui mémorisera sa dernière valeur définie lors d'appels succesifs.
                Cela permettra la mémorisation lors d'appels successifs dans une même session y compris sans les cookies activés dans le navigateur, mais dans ce cas la mémorisation de l'état sera perdue au rechargement de la page puisque c'est un cookie qui mémorise l'état d'une session à un autre. */
               
                this.EtatAmt = typeof this.EtatAmt != 'undefined' ? this.EtatAmt : new Array;
                this.EtatAmt[div_concat] = typeof this.EtatAmt[div_concat] != 'undefined' ? this.EtatAmt[div_concat] : 'none';
               
                               
               
                var tab_cook_showDiv;
           
                // Cherche le cookie affecté à cette page et s'il existe le désérialise
                tab_cook_showDiv = (tab_cook_showDiv = GetCookie(SetNomCookie())) ? Unserialize(tab_cook_showDiv) : null;                              

                // Vérifie que le résultat tab_cook_showDiv est un tableau sinon initialise cette variable en tableau
                tab_cook_showDiv = (typeof tab_cook_showDiv == 'object' && tab_cook_showDiv instanceof Array) ? tab_cook_showDiv : new Array;
               
                // Cherche l'élément 'div_concat' du tableau du cookie sinon le crée et lui affecte la valeur this.EtatAmt[div_concat]
                tab_cook_showDiv[div_concat] = (typeof tab_cook_showDiv[div_concat] != 'undefined')? tab_cook_showDiv[div_concat] :  this.EtatAmt[div_concat];                        
                       

                // Cherche si les div passés en argument dans la fonction AmtShowDiv ne sont pas tous déjà dans l'état inverse de la valeur de tab_cook_showDiv[div_concat] (si modifiés individuellement par la fonction ShowDiv ou par css)
               
                var affiche_id;
               
                // Valeur témoin
                var verif = false;
               
                // Liste les arguments passés en paramètres lors de l'appel de la fonction AmtShowDiv
                for (var i=0; i < tab_argumemts.length; i++)
                                                               
                                {
                                        // Si l'argument passé dans la fonction  correspond à un id existant de la page en cours
                        if (affiche_id = document.getElementById(tab_argumemts[i]))
                                                {
                                                        // Si cet élément est dans le même état que tab_cook_showDiv[div_concat], verif = true
                                                        //(si au moins un élément est dans le même état, alors tous ne sont pas dans l'état inverse)
                                                        if ((tab_cook_showDiv[div_concat] == 'block' && affiche_id.offsetWidth > 0) || (tab_cook_showDiv[div_concat] == 'none' && !(affiche_id.offsetWidth > 0))) verif = true;
                                                       
                                                }
                                       
                                }              
               
                // si vérif = true => redéfini tab_cook_showDiv[div_concat] pour inverser l'affichage
                if (verif === true) tab_cook_showDiv[div_concat] = tab_cook_showDiv[div_concat] == 'block' ? 'none' : 'block';
               
               
               
                // Défini l'affichage des blocs (en utilisant les id des div passés en paramètres lors de l'appel de la fonction)
               
        // Liste les arguments passés dans la fonction AmtShowDiv                                                    
                for (var i=0; i < tab_argumemts.length; i++)
                                                               
                                {
               
                 // Si l'argument passé en paramètre dans la fonction AmtShowDiv correspond à un id existant de la page en cours => affecte son affichage "style.display" avec la valeur de tab_cook_showDiv[div_concat]
                        if (affiche_id = document.getElementById(tab_argumemts[i]))
                                                {
                                                        affiche_id.style.display = tab_cook_showDiv[div_concat];
                                       
                                                        // Et enregistre son état dans le tableau
                                                        tab_cook_showDiv[tab_argumemts[i]] = tab_cook_showDiv[div_concat];
                                                }
                                }
               
               
                // Enregistre la valeur de tab_cook_showDiv[div_concat] dans this.EtatAmt[div_concat] (pour mémorisation de l'état dans une même session y compris sans les cookies activés)
                this.EtatAmt[div_concat] = tab_cook_showDiv[div_concat];


                // Envoi le tableau sérialisé dans un cookie dont le nom est "SetNomCookie()"

                SetCoockie (SetNomCookie(), Serialize(tab_cook_showDiv));  
               
}



function SetNomCookie() {
               
        var fich = window.location.pathname;  
       
        if (fich != '/')
                {      
                        //Enlève tout ce qu'il y a après de dernier point
                        fich = fich.substr(0,fich.lastIndexOf('.'));
                       
                        //Si fich = "/index" on est sur la page d'accueil et l'on renvoie le nom de domaine
                        var name = (fich == '/index')?  window.location.host : fich;  
                }
                else
                {
                        //si fich == '/' on est sur la page d'accueil et l'on renvoie le nom de domaine
                        var name = window.location.host;
                }

        return (name);
}



function SetCoockie (nom, valeur) {

        //http://fr.selfhtml.org/javascript/exemples/visites_pages.htm ... script légèrement modifié

         var peremption = 1000*60*60;//durée de validité : 1an
       
         var maintenant = new Date();
         var temps = new Date(maintenant.getTime() + peremption);
         
         document.cookie = nom+"="+escape(valeur)+"; expires="+temps.toGMTString()+";";
}



function GetCookie(nom) {

      //http://www.asp-php.net/tutorial/scripting/cookies.php ... script légèrement modifié

      var deb,fin;
         
      deb = document.cookie.indexOf(nom + "=");
         
      if (deb >= 0)
                  {
                         deb += nom.length + 1;
                         
                         fin = document.cookie.indexOf(";",deb);
                         if (fin < 0) fin = document.cookie.length;
                         
                         return unescape(document.cookie.substring(deb,fin));
                  }
      else return false;
}



function Serialize (txt) {
       
        /*auteur : XoraX
        info : <!-- m --><a class="postlink" href="http://www.xorax.info/blog/programmatio">http://www.xorax.info/blog/programmatio</a><!-- m --> ... e-php.html  ... script légèrement modifié*/

        switch(typeof(txt))
                {
                        case 'string':
                                return 's:'+txt.length+':"'+txt+'";';
                               
                        case 'number':
                                if(txt>=0 && String(txt).indexOf('.') == -1 && txt < 65536) return 'i:'+txt+';';
                                return 'd:'+txt+';';
                               
                        case 'boolean':
                                return 'b:'+( (txt)?'1':'0' )+';';
                               
                        case 'object':
                                var i=0,k,ret='';
                                for(k in txt)
                                        {
                                                //alert(isNaN(k));
                                                if(!isNaN(k)) k = Number(k);
                                                ret += Serialize(k)+Serialize(txt[k]);
                                                i++;
                                        }
                                return 'a:'+i+':{'+ret+'}';
                               
                        default:
                                return 'N;';
                                //alert('var undefined: '+typeof(txt));return undefined;
                }
}



function Unserialize(txt){
       
        /*auteur : XoraX
        info : <!-- m --><a class="postlink" href="http://www.xorax.info/blog/programmatio">http://www.xorax.info/blog/programmatio</a><!-- m --> ... e-php.html  ... script légèrement modifié*/

        var level=0,arrlen=new Array(),del=0,final=new Array(),key=new Array(),save=txt;
        while(1)
        {
                switch(txt.substr(0,1))
                {
                        case 'N':
                                del = 2;
                                ret = null;
                                break;
                       
                        case 'b':
                                del = txt.indexOf(';')+1;
                                ret = (txt.substring(2,del-1) == '1')?true:false;
                                break;
                       
                        case 'i':
                                del = txt.indexOf(';')+1;
                                ret = Number(txt.substring(2,del-1));
                                break;
                       
                        case 'd':
                                del = txt.indexOf(';')+1;
                                ret = Number(txt.substring(2,del-1));
                                break;
                       
                        case 's':
                                del = txt.substr(2,txt.substr(2).indexOf(':'));
                                ret = txt.substr( 1+txt.indexOf('"'),del);
                                del = txt.indexOf('"')+ 1 + ret.length + 2;
                                break;
                       
                        case 'a':
                                del = txt.indexOf(':{')+2;
                                ret = new Array();
                                arrlen[level+1] = Number(txt.substring(txt.indexOf(':')+1, del-2))*2;
                                break;
                               
                        case 'O':
                                txt = txt.substr(2);
                                var tmp = txt.indexOf(':"')+2;
                                var nlen = Number(txt.substring(0, txt.indexOf(':')));
                                name = txt.substring(tmp, tmp+nlen );
                                //alert(name);
                                txt = txt.substring(tmp+nlen+2);
                                del = txt.indexOf(':{')+2;
                                ret = new Object();
                                arrlen[level+1] = Number(txt.substring(0, del-2))*2;
                                break;
                               
                        case '}':
                                txt = txt.substr(1);
                                if(arrlen[level] != 0)
                                        {
                                                //alert('var missed : '+save);
                                                return undefined;
                                        }
                                //alert(arrlen[level]);
                                level--;
                                continue;
                               
                        default:
                                if(level==0) return final;
                                //alert('syntax invalid(1) : '+save+"\nat\n"+txt+"level is at "+level);
                                return undefined;
                }
               
                if(arrlen[level]%2 == 0)
                        {
                                if(typeof(ret) == 'object')
                                        {
                                                //alert('array index object no accepted : '+save);
                                                return undefined;
                                        }
                                if(ret == undefined)
                                        {
                                                //alert('syntax invalid(2) : '+save);
                                                return undefined;
                                        }
                                key[level] = ret;
                        }
                        else
                        {
                                var ev = '';
                                for(var i=1;i<=level;i++)
                                        {
                                                if(typeof(key[i]) == 'number')
                                                        {
                                                                ev += '['+key[i]+']';
                                                        }
                                                        else
                                                        {
                                                                ev += '["'+key[i]+'"]';
                                                        }
                                        }
                                eval('final'+ev+'= ret;');
                        }
                       
                arrlen[level]--;//alert(arrlen[level]-1);
                if(typeof(ret) == 'object') level++;
                txt = txt.substr(del);
                continue;
        }
}

function bascule(elem)
{
etat=document.getElementById(elem).style.display;
if(etat=="none"){document.getElementById(elem).style.display="block";}
else{document.getElementById(elem).style.display="none";}
} 

 
      maxKeys = 4000;
            var IE = (document.all) ? 1 : 0;
            var DOM = 0;
            if (parseInt(navigator.appVersion) >=5) {DOM=1};
 
        function txtshow( txt2show ) {
           
            // Detect Browser
 
            if (DOM) {
      var viewer = document.getElementById("detaildescref");
                viewer.innerHTML=txt2show;
            }
            else if(IE) {
                document.all["detaildescref"].innerHTML=txt2show;
            }
        }
 
function detailcheckref(what)
{
  var str = new String(what.value);
  var len = str.length;
  var showstr = len + " caractères utilisés sur un maximum de " + maxKeys + " ...";
  if (len > 0) var showstr = "<span class=\"comko\">Le texte fait " + len + " caractères : décrivez plus longuement votre commentaire.</span>";
  if (len < maxKeys && len > 149) var showstr = "<span class=\"comok\">Le texte fait " + len + " caractères : votre commentaire répond au minimum démandé.</span>";
  if (len > maxKeys) var showstr = "Le texte fait " + len + " caractères: essayez de faire plus court.";
  txtshow( showstr );
}


