
var UIthemes = ['aucoeur','pepper-grinder','zen-custom','humanity','eggplant', 'black-tie'];
function zenStr(s) { return s.toLowerCase().replace(/[éèêë]/g,"e").replace(/[àâä]/g,"a").replace(/[îï]/g,"i").replace(/[ôö]/g,"o").replace(/œ/g,"oe").replace(/[ùûü]/g,"u").replace(/[ç]/g,"c").replace(/[ñ]/g,"n");}

function ZEN(id) { // for old time sakes.. :)
   if (document.getElementById(id))
      return document.getElementById(id);
   else return false;
}
function SelectValeur(obj,val) {
  for (i = 0; i < obj.options.length; i++)
     if (obj.options[i].value == val) {
        obj.selectedIndex = i;
        return true;
     }
  return false;
}


// Internet Explorer 6
 var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
// exactly Internet Explorer 7
 var IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;
// at least Internet Explorer 7
 var gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/;
// any Internet Explorer (thanks to Dean)
 var isMSIE = /*@cc_on!@*/false;
 var gteIE9 = false;
var IEV = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
 var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
 if (re.exec(navigator.userAgent) != null) {
  IEV = parseFloat( RegExp.$1 );
  if (parseInt(IEV) >= 9) gteIE9 = true;
 }
}
/* ------------------  Fonctions de fenêtres "génériques"..  ------ */
function Ouvrir(id) {
  if (!isMSIE || gteIE9)
    $('#'+id).fadeIn();
  else $('#'+id).slideDown();
}

function Fermer(id) {
  if (!isMSIE || gteIE9)
    $('#'+id).fadeOut();
  else $('#'+id).slideUp();
}


function trans(element,op) {
   if (isMSIE)
        element.style.filter = "alpha(opacity="+op+")";
      else {
        element.style.opacity = (op / 100);
        element.style.MozOpacity = (op / 100);
      }
}

function Deconnecter() {
  if (CheckEdition()) {
      window.location.href = "zen_login.php?logout";
  }
}

function GetToTop() {
    $('html,body').animate({scrollTop: 0}, {duration: 'fast', easing: 'swing', queue:false});
    //Chrome à besoin du body...
}
/* *******************************************************
 *    Fonctions pour navigation
 *
 * ******************************************************* */
var edition_active = false;
var animation_active = false;
var efface_msg_admin = true;

function CheckEdition() {
   if (ZEN("msg_admin") && efface_msg_admin)
     ZEN("msg_admin").innerHTML = "&nbsp;";
   efface_msg_admin = true;
   if (edition_active || animation_active) {
      if (est_admin) 
         msg = '<div id="zen_edition_active"><div class="avertissement">Vous devriez finir ce que vous avez commencé !<br />Enregistrez ou annulez vos modifications puis ré-essayez.</div><br />Si vous êtes déjà en train de changer de page, veuillez patienter un moment...</div>';
      else
         msg = '<div id="zen_edition_active"><div class="note_opaque">Vous êtes déjà en train de changer de page, veuillez patienter un moment...</div></div>';

      $(msg).dialog({
          autoOpen : true, modal : true, resizable : false, draggable : false,
          title : 'Le site est déjà occupé . . .',
          width: 550,
          closeOnEscape : true,
          position : ['center',150],
          close : function() {$(this).remove();}
      });
      /*,
          buttons : {'Continuer' :  function() {$(this).dialog('close');}}
      $('#zen_edition_active').next().find('button').focus();
      */
      return false;
   }
   else {
      edition_active = true;
      return true;
   }
}

function Highlight(obj,rexp) {
  //ZEN('check_highlight').checked && 
  if (obj && obj.className != "zen_light" && !ZEN('cachette_admin_aj_elem')
      && !(obj.id && obj.id.substring(0,5) == "album")) {
   nb = 0;
   for (i in obj.childNodes) {
      nb++;
      Highlight(obj.childNodes[i],rexp);
   }
   if (!isMSIE) {
     if (nb == 0 && obj.nodeValue && rexp.test(obj.nodeValue)) { // fonctionne pour firefox, sans boucles inutiles ou infinies...
      if (obj.parentNode && obj.parentNode.className != "zen_light" && obj.parentNode.innerHTML.indexOf('zen_light') == -1) {
        temp = obj.parentNode.innerHTML.replace(rexp,'<u class="zen_light">$&</u>');
        obj.parentNode.innerHTML = temp;
      }
     }
   }
   else {
     if (nb == 1 && obj.nodeValue && rexp.test(obj.nodeValue)) {// fonctionne pour IE ???...
      if (obj.parentNode && obj.parentNode.className != "zen_light" && obj.parentNode.innerHTML.indexOf('zen_light') == -1) {
        temp = obj.parentNode.innerHTML.replace(rexp,'<u class="zen_light">$&</u>');
        obj.parentNode.innerHTML = temp;
      }
     }
   }
  }
}


function ZenConfirm(txt,ok,annuler) { // escape : annule, enter : accepte !
    $('<div id="zen_confirm">'+txt+'</div>').dialog({
        autoOpen : true, modal : true, closeOnEscape : true, open : 'fade',
        close : function () {
            annuler();
            $(this).dialog('destroy');
            $(this).remove();
        },
        draggable : false, resizable : false, position : ['center',100],
        width : 600,
        title : "Veuillez confirmer cette action",
        buttons : { 'Ok' : function () {
                            ok();
                            $(this).dialog('destroy');
                            $(this).remove();
                        },
                     'Annuler' : function () {
                            $(this).dialog('close');
                        }
                    
        }
    });
    // donner le focus au premier bouton, action par défaut...
    direction = $('#zen_confirm').next().find('button:first').css('float');

    $('#zen_confirm').next().find('button:first').focus();
    if (direction == "right")
        $('#zen_confirm').next().find('button').keypress(function(e) { // à l'enver car float right :)
          if (e.keyCode == 37) {if ($(this).next().length != 0) {$(this).blur(); $(this).next().focus();}}
          if (e.keyCode == 39) {if ($(this).prev().length != 0) {$(this).blur(); $(this).prev().focus();}}
        });
    else
        $('#zen_confirm').next().find('button').keypress(function(e) { // à l'enver car float right :)
          if (e.keyCode == 39) {if ($(this).next().length != 0) {$(this).blur(); $(this).next().focus();}}
          if (e.keyCode == 37) {if ($(this).prev().length != 0) {$(this).blur(); $(this).prev().focus();}}
        });
}

function NettoieContenu() { //effectué après chaque page loadé
   // nouveau traitement jQuery !!   

   $('.accordeon').accordion({'header':'h3.h3_acc',collapsible:true,autoHeight:false,active:false});//
   $('.onglets').tabs();
   $("button, input:submit, input:button").button().css('padding','3px');

   if (!isMSIE || gteIE9) {
    /*   $('.accordeon h3.h3_acc, .accordeon > div')
            .css('-moz-box-shadow','4px 2px 9px #999')
                 .css('box-shadow','4px 2px 9px #999');*/
       $('.accordeon h3.h3_acc, .accordeon > div, .onglets, .menu_vonglets p')
            .css('-moz-box-shadow','4px 4px 4px #999')
            .css('-webkit-box-shadow','4px 4px 4px #999')
            .css('box-shadow','4px 4px 4px #999');
       $('.ui-accordion .ui-accordion-header').css('margin-top','6px');
//filter: progid:DXImageTransform.Microsoft.dropShadow(color=#818181, offX=5, offY=5, positive=true);
    }

   //$('.note, .avertissement, .question').addClass('ui-corner-all');
   // oui mais l'admin ne la verra pas au premier coup d'oeil en le mettant..

    if (est_admin) {
        //  PlaceAdminGenerale();
          SwapAdminOptions();
          if (ZEN('cachette_admin_aj_elem')) {
              $('.admin_options, .admin_options_abso').fadeTo('fast',0.6);
              $('.admin_options, .admin_options_abso').hover(function(){$(this).stop().fadeTo('fast',1);},function(){$(this).stop().fadeTo('fast',0.6);});
              $('#contenu_pages .admin_options,#contenu_pages .admin_options_abso').addClass('ui-corner-all');
          }
          ChangeAdminSections(cat_active);
      //ChangeAdminPages(section_active); // inclus dans ChangeAdminSections ?
      }


   $('.menu_vonglets p').addClass('ui-state-default ui-corner-all');
   $('.menu_vonglets p').hover(
        function() {if (!$(this).hasClass('ui-state-active')) $(this).addClass('ui-state-hover');},
        function() {$(this).removeClass('ui-state-hover');});


   // ancien traitement
/*
   var cp = ZEN("contenu_pages");
   for (i in cp.childNodes) {
     var child = cp.childNodes[i];
     if (child && child.tagName == 'DIV') {
        vide = true;
        if (child.className == "colonnes") {
          for (j in child.childNodes) {
             col = child.childNodes[j];
             if (col.tagName == 'DIV') {
               if (col.innerHTML.replace(' ','').length > 0)
                vide = false;
               else
                col.style.display = 'none';
             }
            /* if (!IE6 && col.className == 'colonne_droite_petite' && !vide)
                col.innerHTML = '<div class="ombre_div_bg"><div class="ombre_bg ombre_n"></div><div class="ombre_bg ombre_ne"></div><div class="ombre_bg ombre_e"></div><div class="ombre_bg ombre_se"></div>         <div class="ombre_bg ombre_s"></div><div class="ombre_bg ombre_sw"></div><div class="ombre_bg ombre_w"></div><div class="ombre_bg ombre_nw"></div></div><div class="dessus_ombre">'
                                +col.innerHTML+'</div>';*/
        /*  }
        }
        else if (child.innerHTML.replace(' ','').length > 0) vide = false;

        if (vide) {
          child.style.display = 'none';
        }
     }
   }
   // -- fin ancien traitement...
*/
  if (ZEN('album_premiere_page')) {
      $('#album_table_matieres').addClass('ombre').addClass('ui-widget-content').addClass('ui-corner-all');
      setTimeout("AfficheAlbumThumbs(ZEN('album_premiere_page').innerHTML);",250);
  }
  if (ZEN('grille_cal_ev')) {
        mois = mois_cal_ev;
        max_mois = mois.getDaysInMonth();

        mois_nom = mois.getMonthName() ;

        mois_nom = mois_nom.substr(0,1).toUpperCase() + mois_nom.substr(1); // première lettre majuscule...


        mois_num = mois.getMonth();

        annee = mois.toString('yyyy'); //annee = mois.getYear(); // donne 109 au lieu de 2009
        $('cal_ev_mois').innerHTML = ''+mois_nom+' '+annee;

        GetCalEv(0);
   }

}
var requete_visiteur = "";
var showContenu = function(str) {
  GetToTop();
  $("#cherche_contenu").css('display','none');
  //FermeBarreDroite();

  $("#contenu_pages").html(str);
  if (ZEN('time_up')) window.location.href="zen_login.php";

  edition_active = false;
  if ($('#zen_edition_active').dialog('isOpen')) $('#zen_edition_active').dialog('close');

  if (requete_visiteur != "" && ZEN('form_plainte')) {
      ZEN('form_plainte').objet.value=requete_visiteur;
      requete_visiteur = "";
  }

  q = '';
  if (!q_cc_vide)
   q = ZEN('q_cc').value;

  if (ZEN('q_art') && q == "")
   q = ZEN('q_art').value;

  if (page_active == art_p && q.replace(/\s{1,}/g,'').length > 2) {
      question = PrepareQ(q);
      Highlight(ZEN("contenu_pages"),question);
  }

  if (!isMSIE || gteIE9) $('#contenu_pages').stop(true,true).fadeTo('slow',1);


  p = page_active;
  titre = "";
  if (section_active != 1)  //retire le mot "Accueil"
      titre = liste_sect[section_active];
 // ZEN('option_URL').value = url_base+liste_fp[p]+'.php';
  t2 = liste_ts[p][1];
  if (t2 == "") t2 = liste_ts[p][0];

  if (art_p != p && entr_p != p && annonce_p != p) {     
     if (titre == "") titre += t2;
     else if (titre != t2) titre += " - "+t2;
     annonce_actif = 0;
     article_actif = 0;
     entr_actif = 0;
     if (!est_admin && !cache_pages[page_active])
        cache_pages[page_active] = str;
  }
  else {
   if (art_p == p) {
    getArchivesArticles();
    if (article_actif > 0) {
       //titre += (titre!=""?" - ":"")+ZEN('titre_article').innerHTML;
       titre = ZEN('titre_article').innerHTML;
       ZEN('option_URL').value += '?art='+article_actif;
       if (!cache_art[article_actif])
        cache_art[article_actif] = str;
    }
    else {
       titre += t2;
       if (!cache_pages[page_active])
        cache_pages[page_active] = str;
    }
   }
  }

  document.title = (est_admin?'ADMIN':titre_site)+" - "+titre;

  effacer_photo = false;
  NettoieContenu();

  if (!est_admin)
    try { _gaq.push(['_trackPageview', liste_fp[p]+'.php'+(article_actif>0?"?art="+article_actif:"")]);  } catch(err) {}


}

function getContenuPatch(p) { /* Patch pour l'historique (retour du iframe..) */
   //GetToTop();
   if (!isMSIE || gteIE9) $('#contenu_pages').stop(true,true).fadeOut();
   //FermeBarreDroite(); // ici ou dans showContenu ?.. les deux par safety ?

   c = liste_ts[p][2];
   s =  liste_ts[p][3];
  ChangeSection(s,p);

   cat_active = c;
   section_active = s;
   page_active = p;



   album_page_active = "";
   album_photo_active = "";
   art = ""
   if (article_actif != "") art = "&art="+article_actif;
   if (p == art_p) {
      if (art == "") art = "&art=0";
   }
   else {
       article_actif = "";
       ZEN('archives_articles').style.display = "none";
   }
   entr = ""
   annonce = ""; 
   bp = "";
   if (est_admin) {
      bp = adbp; adbp = "";
      $.get('zen_contenu_pages.php?p='+p+art+entr+annonce+bp, showContenu);
   }
   else {
      if ((p != art_p || art == "&art=0") && cache_pages[p]) {
         showContenu(cache_pages[p]);
         $.get('zen_historique.php?session=1&p='+p+art+entr);
      }
      else if (p == art_p && article_actif > 0 && cache_art[article_actif]){
         showContenu(cache_art[article_actif]);
         $.get('zen_historique.php?session=1&p='+p+art);
      }
      
      else
        $.get('zen_contenu_pages.php?p='+p+art, showContenu);

   }

   
/*
   if (!isMSIE) {
      fade_out("contenu_pages",90,20);
   }
*/
   //ZEN('sommaire_cal_ev').style.display = "none";

}

var alterne_img = 0;
var histo_iframe = true;
var capture_lien = false;

function getContenu(p) {

 if (est_admin || page_active != p || (art_p && p == art_p) || (entr_p && p == entr_p) || (annonce_p && p == annonce_p)) {
  if (capture_lien) {CaptureLien(p);}
  else if (CheckEdition()){
   histo_iframe = false;

   ZEN('iframe_historique').src='zen_historique.php?p='+p;
   if (p == art_p) article_actif = 0;
   if (p == entr_p) entr_actif = 0;
   if (p == annonce_p) annonce_actif = 0;
   getContenuPatch(p);
  }
 }
}

var dernier_q_cc = "_rien_";
function PrepareQ(q) {
    /*expérimental...*/
   /*q = q.replace(/[^a-z]d[eu]s* /gi," ");
   q = q.replace(/[^a-z]l[ea]s* /gi," ");
   q = q.replace(/[^a-z][cç]a /gi," ");*/

   q = q.replace(/[eéèêë]/gi,"[eéèêë]");
   q = q.replace(/[aàâä]/gi,"[aàâä]");
   q = q.replace(/[iîï]/gi,"[iîï]");
   q = q.replace(/[oôö]/gi,"[oôö]");
   q = q.replace(/[uùûü]/gi,"[uùûü]");
   q = q.replace(/[cç]/gi,"[cç]");
   q = q.replace(/^[\s,;:!\.?+]+/g,'').replace(/[\s,;:!\.?+]+$/g,'');
   return new RegExp("("+q.replace(/[\s,;:!\.?+]+/g,")|(")+")","ig");
}



var showChercheContenu = function(str) {
   ZEN('cherche_contenu').innerHTML = str;
   if (ZEN('cherche_contenu').style.display != "block")
      Ouvrir('cherche_contenu');

      question = "";
      result = new Array();

      nb_res = 0;
      if (ZEN('rcpt')) {
         for (p in liste_ts)
            if (ZEN('rcc'+p)) {
               result[nb_res] = new Array(liste_sect[liste_ts[p][3]],liste_ts[p][0],p,0);
               nb_res++;
            }
      }
      else {
         question = PrepareQ(dernier_q_cc);
         for (p in liste_ts) {
            s_test = liste_sect[liste_ts[p][3]]+" "+liste_ts[p][0]+" "+liste_ts[p][1];
            if (ZEN('rcc'+p) || s_test.search(question) > -1) { // checker noms fichier aussi ? || question.test(liste_fp[c][i][j])
               result[nb_res] = new Array(liste_sect[liste_ts[p][3]],liste_ts[p][0],p,0);
               nb_res++;
            }
         }

         for (p in liste_le) {
            s_test = liste_le[p][0]+" "+liste_sect[liste_le[p][3]];
            if (s_test.search(question) > -1) {
               result[nb_res] = new Array(liste_sect[liste_le[p][3]],liste_le[p][0],p,1,liste_le[p][1]);
               nb_res++;
            }
         }



      }

      lst = "<ul>";

      result.sort(function(a,b) {return zenStr(a[0])>zenStr(b[0]);});
      last_titre = "";
      for (p in result) {
        if (last_titre != result[p][0]) {
           last_titre = result[p][0];
           nb_res++;
        }
      }


      nb_div = Math.ceil(nb_res / 3);
      if (nb_div<3) nb_div=3;
      i = 0;
      last_titre = "";
      cols = 1;
      next = nb_div;
      for (p in result) {
         if (i>0 && (i > next) && (cols < 3)) {
            lst += "</ul><ul>";
            cols++;
            next += nb_div;
            // RÉPÉTER LE TITRE SI ON CHANGE DE COLONNE...
            if (last_titre == result[p][0]) {
               lst += "<p>"+last_titre+"</p>";
            }
         }
         if (last_titre != result[p][0]) {
            last_titre = result[p][0];
            lst += "<p>"+last_titre+"</p>";
            i++
         }
         i++;
         if (result[p][3] == 0)
            lst += '<li class="cmr_int" onmouseover="this.className=\'cmr_int_over\';" onmouseout="this.className=\'cmr_int\';" onclick="getContenu('+result[p][2]+');">'+result[p][1]+'</li>';
         else
            lst += '<li class="cmr_ext" onmouseover="this.className=\'cmr_ext_over\';" onmouseout="this.className=\'cmr_ext\';" onclick="window.open(\''+result[p][4]+'\',\'_BLANK\')">'+result[p][1]+'</li>';

      }

      lst += "</ul>";
      if (nb_res == 0) lst = "<h4 style='text-align:center;'>Aucun résultats</h4>";

      ZEN('cherche_contenu_resultats').innerHTML += lst;
      if (question != "") Highlight(ZEN('cherche_contenu_resultats'),question);

}

var pa_cc = -1;
function ChercheContenu(q) {
 if (!q_cc_vide && !edition_active) {

  if (q.replace(/\s{1,}/g,'').length > 2) {
   if (q == dernier_q_cc) {
    if (ZEN('cherche_contenu').style.display != "block")
      Ouvrir('cherche_contenu');
   }
   else {
      q_ajax = encodeURIComponent(q);
      $.get('zen_cherche_contenu.php?q='+q_ajax, showChercheContenu);      
   }
   getArchivesArticles(q);
   //getListeEntreprises(q);
   //getListeAnnonces(q);
   pa_cc = page_active;
   page_active = -1;
   article_actif = -1;
   entr_actif = -1;
   ZEN("contenu_pages").innerHTML = "";
   ZEN("sommaire_cal_ev").style.display='none';
  }
  else {
       ZEN('cherche_contenu').innerHTML = '<div style="padding: 4px; position:relative;">'+
'<img style="cursor : pointer; position:absolute; top: 2px; right: 2px; width:24px; z-index : 10;" onclick="FermerChercheContenu();" src="images/fermer.png" title="Fermer la recherche" />'+
'<h4>Entrez au moins trois lettres pour chercher dans tout le site</h4></div><div class="cherche_contenu_resultats"></div>';
       if (ZEN('cherche_contenu').style.display != "block")
         Ouvrir('cherche_contenu');
   }
 }
 
 dernier_q_cc = q;



}
function FermerChercheContenu() {
   ZEN('cherche_contenu').style.display='none';
   if (page_active == -1) getContenu(pa_cc);
}

var q_cc_vide = true;
function cc_blur(obj) {   
   if (obj.value == "") {
      obj.style.color = "#999999";
      obj.style.fontStyle = "italic";
      obj.value = "Chercher dans le contenu";
      q_cc_vide = true;
   }
}
function cc_click(obj) {
   if (q_cc_vide) {
      obj.style.color = "#000000";
      obj.style.fontStyle = "normal";
      obj.value = "";
      q_cc_vide = false;
   } else obj.select();
}

var dernier_q_art = "_toutes_";
//var aa_temp = "";

var showArchivesArticles = function(str) {
   ZEN('archives_articles').innerHTML = str;
   //aa_temp = str;
   ZEN('archives_articles').style.display = "block";
   q = dernier_q_art;

   if (q.replace(/\s{1,}/g,'').length > 2 && q != '_toutes_') {
      question = PrepareQ(q);
      Highlight(ZEN('archives_articles'),question);
   }
   // Répété pour rien de NettoieContenu....
   $('.menu_vonglets p').addClass('ui-state-default ui-corner-all');
   $('.menu_vonglets p').hover(
        function() {if (!$(this).hasClass('ui-state-active')) $(this).addClass('ui-state-hover');},
        function() {$(this).removeClass('ui-state-hover');});
   $('.accordeon').accordion({'header':'h3.h3_acc',collapsible:true,autoHeight:false});
   
    $('.accordeon h3.h3_acc, .accordeon > div, .onglets, .menu_vonglets p')
            .css('-moz-box-shadow','4px 4px 4px #999')
            .css('-webkit-box-shadow','4px 4px 4px #999')
            .css('box-shadow','4px 4px 4px #999');
    $('.ui-accordion .ui-accordion-header').css('margin-top','6px');
    $("button, input:submit, input:button").button().css('padding','3px');

}
function getArchivesArticles(q){

   if (q === undefined) {
      q = "_tous_";
      if (ZEN('q_art')) {
       test = ZEN('q_art').value;
       if (test != "") q = test;
      }
   }

   if (dernier_q_art != q || ZEN('archives_articles').innerHTML == "") {

      if (ZEN('bouton_q_art')) {
         ZEN('bouton_q_art').value='recherche...';
         ZEN('bouton_q_art').disabled=true;
      }
      q_ajax = encodeURIComponent(q);
      // n'est chargé que lorsqu'on en a besoin...
      $.get('zen_archives_articles.php?q='+q_ajax, showArchivesArticles);
   }
   
   if (ZEN('archives_articles').style.display != "block")
      Ouvrir('archives_articles');

   dernier_q_art = q;
}

function getArticle(art){
 if (est_admin || art == 0 || art != article_actif) {
  if (capture_lien) {CaptureLien(art_p,art);}
  else if (CheckEdition()){
   histo_iframe = false;
   ZEN('iframe_historique').src='zen_historique.php?p='+art_p+'&art='+art;
   article_actif = art;
   if (art==0 && ZEN('q_art')) ZEN('q_art').value = ""; //enleve la recherche si on fait "tout voir"
   getContenuPatch(art_p);
  }
 }
}

function ChangeVOnglet(id, prefix) {
 if (prefix === undefined) prefix = "";
 if (!edition_active) {
   if (ZEN(prefix+'vonglet_actif')) {
      ferme = ZEN(prefix+'vonglet_actif').innerHTML;
      ZEN(prefix+'vonglet_actif').innerHTML = id;
      if (ferme != id) {

         ZEN(prefix+'vonglet_'+ferme).style.display = "none";
         $('#'+prefix+'menu_vonglet_'+ferme).parent().removeClass('ui-state-active');
         $('#'+prefix+'menu_vonglet_'+id).parent().addClass('ui-state-active');
         $('#'+prefix+'menu_vonglet_'+id).parent().removeClass('ui-state-hover');
         Ouvrir(prefix+'vonglet_'+id);
      }
   }
 }
}


var menu_q_vide = true;
function cm_blur(obj) {
   if (obj.value == "") {
      obj.style.color = "#999999";
      obj.style.fontStyle = "italic";
      obj.value = "Chercher dans le menu";
      menu_q_vide = true;
   }
}
function cm_click(obj) {
   if (menu_q_vide) {
      obj.style.color = "#000000";
      obj.style.fontStyle = "normal";
      obj.value = "";
      menu_q_vide = false;
   } else obj.select();
}


/* ********************************** COMMENTAIRES ET SUGGESTIONS **************************************** */
var backPlainte = function(str) {
   if (ZEN('msg_plainte')) {
      if (str=="OK") {
         ZEN('form_plainte').style.display = 'none';
         ZEN('msg_plainte').innerHTML = "<div class='note'>Un courriel a été envoyé à un responsable. Merci d'avoir utilisé ce service.</div>";
      }
      else {
         ZEN('msg_plainte').innerHTML = str;
         ZEN('form_plainte').code.value="";
         ZEN('img_captcha_plainte').src='securimage_show.php?sid='+(Math.random()*1000000000);
      }
   }
}


    function ValidePlainte() {
      if (f = ZEN('form_plainte')) {
        message = "";

        if (f.nom.value == "") message += "Vous devez entrer un nom.<br />";

        testc = f.courriel.value;
        testl = testc.length;
        at_pos = testc.indexOf("@");
        dot_pos = testc.lastIndexOf(".");

        if ((testl < 8) || at_pos == null || dot_pos == null || (at_pos < 1) || (dot_pos < (at_pos+2)))
            message += "Vous devez entrer un courriel valide.<br />";
/*
        tel = f.telephone.value;
        len = tel.replace(/[^0-9]/gi,'').length;
        if (len != 10)
           message += "Vous devez entrer un numéros de téléphone valide, à 10 chiffres,<br />par exemple (819) 555-5555 ou encore 8195555555.<br />";
*/
        if (f.objet.value == "") message += "Vous devez entrer un sujet.<br />";

        if (f.description.value == "") message += "Vous devez écrire un commentaire.<br />";


        if (message == "") {/*
           code = encodeURIComponent(f.code.value);
           //type =  encodeURIComponent(f.type.value);
           nom = encodeURIComponent(f.nom.value);
           courriel = encodeURIComponent(f.courriel.value);
           //adresse = encodeURIComponent(f.adresse.value);
           telephone = encodeURIComponent(f.telephone.value);
           objet = encodeURIComponent(f.objet.value);
           description = encodeURIComponent(f.description.value);*/

           $.post('zen_traite_commentaires.php',$('#form_plainte').serialize()
               /*'plainte_go=1&code='+code+
               '&nom='+nom+
               '&courriel='+courriel+
               '&telephone='+telephone+
               '&objet='+objet+
               '&description='+description
                */  ,backPlainte);
        }
        else {
         message = '<div class="avertissement">'+message+'</div>';
         ZEN('msg_plainte').innerHTML = message;
        }
      }
    }

function fs(s) {
    //$('#'+s+'>.msmenu').slideUp({duration:'fast',easing:'swing',queue:false});
    $('#'+s+'>.msmenu').hide();
    $('#'+s+'>.msbouton').slideDown({duration:'slow',easing:'swing',queue:false});
}
function os(s) {
    //$('#'+s+'>.msbouton').slideUp({duration:'fast',easing:'swing',queue:false});
    $('#'+s+'>.msbouton').hide();
    $('#'+s+'>.msmenu').slideDown({duration:'slow',easing:'swing',queue:false});
}

function ChangeSection(s,p) {
  $('.msbox').css('z-index',1);
  // sinon, on les ouvre tous pour la page 1
  if (p == 1) {
      $('#overlay_accueil').fadeIn('slow');
      $('.element_menu, .msmenu>ul').hide();
      $('#elem_menu_accueil').fadeIn('fast');
      $('.msbouton').fadeOut('fast');
      $('.msmenu').slideDown('slow');
     $('#fs0').fadeTo('slow',0.55);
     $('#fs1').fadeTo('slow',0);
  }
  else {
   
   $('#overlay_accueil').fadeOut('slow');
   $('.element_menu, .msmenu>ul').fadeIn('slow');
   $('#elem_menu_accueil').stop().hide();
   if (s > 1 && s < 5) {
     $('#fs0').fadeTo('slow',0);

     $('#fs1').attr('src','images/Fond_'+s+'.jpg').fadeTo('slow',1);
    // si la section est dans la boite
    anim = true;
    if (parseInt($('#ms'+s).css('left')) == 0) anim = false;

    $('.msbox').each(function() {
       id = $(this).attr('id');      
       if (id == 'ms'+s) {
           os(id);
           if (anim) {
               animation_active = true;
               $(this).css('z-index',10).animate({
                  left :  [0, 'swing']
               },'slow',function () {
                   animation_active = false;
                   if ($('#zen_edition_active').dialog('isOpen')) $('#zen_edition_active').dialog('close');
               });
           }
       }
       else {
           fs(id);
           if (anim && parseInt($(this).css('left')) < 500) $(this).animate({
               left : ['+=250', 'swing']
           },'slow');
      }
    });

   }
   else {
      $('#fs0').fadeTo('slow',0.4);
      $('#fs1').fadeTo('slow',0);
      $('.msbouton').slideDown('slow');
      //$('.msmenu').slideUp('fast');
      $('.msmenu').fadeOut('fast');
   }
  }
}



$(document).ready(function() {

    // ****
    //  /* French initialisation for the jQuery UI date picker plugin. */
        /* Written by Keith Wood (kbwood@virginbroadband.com.au) and Stéphane Nahmani (sholby@sholby.net). */
	$.datepicker.regional['fr'] = {clearText: 'Effacer', clearStatus: '',closeText: 'Fermer', closeStatus: 'Fermer sans modifier',
		prevText: '<Préc', prevStatus: 'Voir le mois précédent',nextText: 'Suiv>', nextStatus: 'Voir le mois suivant',
		currentText: 'Courant', currentStatus: 'Voir le mois courant',
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun','Jul','Aoû','Sep','Oct','Nov','Déc'],
		monthStatus: 'Voir un autre mois', yearStatus: 'Voir un autre année',
		weekHeader: 'Sm', weekStatus: '',
		dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
		dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
		dayNamesMin: ['D','L','M','M','J','V','S'],
		dayStatus: 'Utiliser DD comme premier jour de la semaine', dateStatus: 'Choisir le DD, MM d',
		dateFormat: 'dd/mm/yy', firstDay: 0,
		initStatus: 'Choisir la date', isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['fr']);
        /* Fin de la régionalisation en français */
   

   // ******* Trucs d'admin si c'est le cas...

   if (est_admin) AdminReady();


   // ******* Autocomplete pour chercher dans le menu
/*
   source_ac = new Array();
   i = 0;
   for (j in liste_ts) {
       l = liste_ts[j][0];
       if (liste_ts[j][3] != 1) l = liste_sect[liste_ts[j][3]]+' - '+l;
       source_ac[i++] = {label:l,p:j,ext:false};//,s:liste_sect[liste_ts[j][3]]
   }
   for (j in liste_le) {
       l = liste_le[j][0];
       if (liste_le[j][3] != 1) l = liste_sect[liste_le[j][3]]+' - '+l;
       source_ac[i++] = {label:l,p:j,ext:true};
   }
   //ajouter les liens externes
   $('#cherche_menu_q').autocomplete({source:source_ac, select:function(e,ui){
           if (ui.item.ext)
              window.open(liste_le[ui.item.p][1],'_BLANK');
           else getContenu(ui.item.p);
       }});
   $('.ui-autocomplete').addClass('ombre');
*/

   //$('#section_gauche, #entete, #cherche_contenu').addClass('ui-widget-content ui-corner-all');
   
   // ******* Menu de thème et ThemeRoller pour Firefox
   if (false) {
       tr = "";
       if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
        tr = '<br /><br /><b style="cursor:pointer" onclick="ZEN(\'theme_sel\').disabled=true; if(window.jquitr){ jquitr.addThemeRoller(); } else{ jquitr = {}; jquitr.s = document.createElement(\'script\'); jquitr.s.src = \'http://jqueryui.com/themeroller/developertool/developertool.js.php\'; document.getElementsByTagName(\'head\')[0].appendChild(jquitr.s);}">'+
                '-> ThemeRoller!! <-</b><div class="petit">(désactive le sélecteur)</div>';
       menuthemes = "<br /><br /><center class=\"note\" style=\"position:relative; margin:10px;\">Thème jQuery UI actif :<br /> "+
                "<select id='theme_sel' style=\"width:130px;\" onchange=\"$('#ui-theme-link').attr('href','themes/'+$(this).val()+'/jquery-ui-.custom.css');\">"
       for (i in UIthemes) {
           menuthemes += '<option value="'+UIthemes[i]+'">'+UIthemes[i]+'</option>';
       }
       menuthemes += '</select>'+tr+'</center>';
       $('.element_menu').after($(menuthemes));
   }

   // ******* Comportement du menu

   
   $('.admin_options').addClass('ui-corner-all'); // pour celles hors du contenu de la page, une seule fois.

   if (!isMSIE || gteIE9) {
       // éventuellement détecter le browser et mettre le bon (moz peut-être pu nécessaire bientôt, opéra le prend sans moz déjà, etc)
    /*    $('#entete, #section_gauche, .bd_sous_menu')
            .css('-moz-box-shadow','6px 6px 9px #777')
            .css('-webkit-box-shadow','6px 6px 9px #777')
            .css('box-shadow','6px 6px 9px #777');*/
        $('.div_form_dialog').parent()
            .css('-moz-box-shadow','12px 12px 25px #555')
            .css('-webkit-box-shadow','12px 12px 25px #555')
            .css('box-shadow','12px 12px 25px #555');
        $('.admin_options_generales')
            .css('-moz-box-shadow','4px 4px 6px #333')
            .css('-webkit-box-shadow','4px 4px 6px #333')
            .css('box-shadow','4px 4px 6px #333');
   }


  // ******* Comportement du menu
  $('#menu li ul').addClass('ui-widget-content');
  $('#menu li ul').css({
    display: "none"
  });
  $('#menu li').hoverIntent(function() {
      $(this).addClass('menu_hover')
      .find('ul')
      .stop(true, true)
      .slideDown({duration: 'fast', easing: 'swing', queue:false}).fadeIn();
     
  }, function() {    
     $(this).removeClass('menu_hover')
      .find('ul')
      .stop(true,true)
      .hide();    
  });
 // ******* Comportement du menu
  $('.msmenu li').hoverIntent(function() {
      $(this).css('background-color','#ffffff');

  }, function() {
     $(this).css('background-color','transparent');
  });
  // Tri du menu !
  // algo de tri par insertion, jQuery style :)
  // rapide sur une liste presque déjà triée.. !!
   function recule(a){
     while ($(a).prev().length >0 && ($(a).attr('rel') - $(a).prev().attr('rel') < 0)) {
       pr = $(a).prev();
       pr.before(a);
       a = pr.prev();
     }     
   }
   $('#menu>ul>li').each(function(){recule(this);});

       
   // ******* Historique et autres traitements particuliers au premier chargement

   histo_iframe = false;

   if (article_actif > 0) {
      cache_art[article_actif] = ZEN('contenu_pages').innerHTML;
      ZEN('iframe_historique').src='zen_historique.php?p='+page_active+'&art='+article_actif;
      if (!est_admin)
        try { _gaq.push(['_trackPageview', liste_fp[page_active]+'.php?art='+article_actif]);  } catch(err) {}
     }  
   else {
      cache_pages[page_active] = ZEN('contenu_pages').innerHTML;
      ZEN('iframe_historique').src='zen_historique.php?p='+page_active;
      if (!est_admin)
        try { _gaq.push(['_trackPageview', liste_fp[page_active]+'.php']);  } catch(err) {}
   }



    $('#nom_utilisateur a').click(function(){$('#nom_utilisateur').effect('explode');});

    NettoieContenu(); //effectué pour chaque pages...
    ChangeSection(section_active,page_active);
    //$(this).toggleClass('msover');
    if (!isMSIE || gteIE9) $('.msmenu>div').hover(function(){$(this).parent().fadeTo('fast',0.8);},function(){$(this).parent().fadeTo('fast',1);})
    if (isMSIE && !gteIE9) $('.msmenu>div').hover(function(){$(this).toggleClass('msover');})
    if (!isMSIE || gteIE9) $('.msbouton').hover(function(){$(this).css('opacity',0.8);},function(){$(this).css('opacity',1);})
    if (isMSIE && !gteIE9) $('.msbouton').hover(function(){$(this).toggleClass('msover');})
    
    $('<img src="images/Fond_3.jpg" />'); //pre-load
    $('<img src="images/Fond_4.jpg" />');
});


