
//********************************************************************************
// fonction qui créer un effet de clignotement pour les actus de la page d'accueil
//********************************************************************************

function couleur(i)
{
  tabBord = new Array ("#fff","#00A7EA");
  tabAffich = new Array ("hidden","visible");
  tabFond = new Array ("#fff","#ECF8FE");
  
  if (i+1 == tabBord.length) i=0;
  else i++;
  if (document.all)
    {
    document.getElementById("blocactu_top").style.setAttribute("cssText","visibility:"+tabAffich[i]+";");
    document.getElementById("blocactu_bottom").style.setAttribute("cssText","visibility:"+tabAffich[i]+";");
    document.getElementById("blocactu").style.setAttribute("cssText","border-left:1px solid "+tabBord[i]+";border-right:1px solid "+tabBord[i]+";border-top:"+tabFond[i]+";border-bottom:"+tabFond[i]+";background-color:"+tabFond[i]+";");
    }
  else
    {
    document.getElementById("blocactu_top").setAttribute("style","visibility:"+tabAffich[i]+";");
    document.getElementById("blocactu_bottom").setAttribute("style","visibility:"+tabAffich[i]+";");
    document.getElementById("blocactu").setAttribute("style","border-left:1px solid "+tabBord[i]+";border-right:1px solid "+tabBord[i]+";border-top:"+tabFond[i]+";border-bottom:"+tabFond[i]+";background-color:"+tabFond[i]+";");
    }
  timer=setTimeout("couleur("+i+")",1000);
  return timer;
}

function start ()
{
    
    couleur(0);
}

function stop ()
{
    clearTimeout(timer);
}


//--------------------------------------------------------
//findObj : encapsulation de la fonction de Dreamweaver
//--------------------------------------------------------
function findObj(n, d)
{
  var p,i,x;
  if(!d)
    d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length)
  {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all)
    x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++)
    x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
    x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById)
    x=d.getElementById(n);
  return x;
}

//------------------------------------------------------
// menu() : affiche ou cache le bloc de
// sous-menu
//------------------------------------------------------
function menu(lien_menu_parent)
{
  // On vérifie le type d'argument
  if(typeof(lien_menu_parent)!='object')
    lien_menu_parent=findObj(lien_menu_parent);

  nb_child = lien_menu_parent.parentNode.childNodes.length;
  for(var i=0; i < nb_child; i++)
  {
    var tag = (new String(lien_menu_parent.parentNode.childNodes.item(i).tagName)).toLowerCase()
    if(tag=='ul')
      cache_ou_affiche(lien_menu_parent.parentNode.childNodes.item(i),lien_menu_parent.id);
  }
  return false;
}

function cache_ou_affiche(objet,id)
{
  var nb=id.split('_')[1];
  if(objet.style)
    style = objet.style;
  else
    style = objet;
  if(style.display=='block')
    style.display='none';
  else
    style.display='block';
}

//------------------------------------------------------
// blank(obj) : ouvre le lien dans une nouvelle fenêtre
//------------------------------------------------------
function blank(lien)
{
  window.open(lien.href);
  return false;
}

//------------------------------------------------------
// goTo(obj) : redirection depuis un select
//------------------------------------------------------
function goTo(obj)
{
  window.location=obj.options[obj.selectedIndex].value;
}

//------------------------------------------------------
// userAcces(obj) : Gestion du menu déroulant de région
//------------------------------------------------------
function userAcces(obj,elem)
{
  if(obj.options[obj.selectedIndex].value=='contributeur regional')
    document.getElementById(elem).disabled=false;
  else
    document.getElementById(elem).disabled=true;
}

//------------------------------------------------------
// supprimer_rubrique() : supprime une rubrique
// après confirmation
//------------------------------------------------------
function supprimer_rubrique(nom_rubrique,id_rubrique)
{
  if(confirm('Etes-vous sûr de vouloir supprimer la rubrique \''+nom_rubrique+'\' ainsi que son contenu ?\nAttention : cette action est irréversible !'))
    window.location='edit.php?action=delete&id_rubrique='+id_rubrique;
}

//-----------------------------------------------------
// fonctions pour mise en page des actus 
// sur page d'accueil index.php
//-----------------------------------------------------

function expand(it)
{
  var elt = document.getElementById(it)
  if (elt.style.display == "block") elt.style.display="none";
  else elt.style.display = "block";
}

//-----------------------------------------------------
// gestion checkbox mise en avant 
//et switchage de modules FCKeditor<->textarea
//-----------------------------------------------------

// switch en utilisant display:block/table-row/none
function Switchsimple (it1, it2, it3, it4, it5, box)
{
try
{
  var vis = (box.checked) ? "table-row" : "none";
  document.getElementById(it1).style.display = vis;
  document.getElementById(it2).style.display = vis;
  document.getElementById(it3).style.display = vis;
  document.getElementById(it4).style.display = vis;
  document.getElementById(it5).style.display = vis;
  }
catch (e)
{
  var vis = (box.checked) ? "block" : "none";
  document.getElementById(it1).style.display = vis;
  document.getElementById(it2).style.display = vis;
  document.getElementById(it3).style.display = vis;
  document.getElementById(it4).style.display = vis;
  document.getElementById(it5).style.display = vis;
}
}


// switch en utilisant display:block/table-row/none
function Switchsimple2 (it1, it2, box)
{
try
{
  var vis = (box.checked) ? "table-row" : "none";
  document.getElementById(it1).style.display = vis;
  document.getElementById(it2).style.display = vis;
  }
catch (e)
{
  var vis = (box.checked) ? "block" : "none";
  document.getElementById(it1).style.display = vis;
  document.getElementById(it2).style.display = vis;
}
}

// fonction qui lance la destruction et la création des éléments
// dad est l'objet parent et child l'objet qui nous interesse
// et valeur est le contenu à afficher à l'init du module
function Switch (dad, child, box, valeur)
{
  if (box.checked)
  {
  removeElement(dad, child);
  addFCKeditor(dad, child, valeur, "contenu");
  }
  else
  {
  removeElement(dad, child);
  addtextarea(dad, child, valeur, "contenutext");
  }
}

function removeElement(dad, child)
{
  var papa = document.getElementById(dad);
  var elt = document.getElementById(child);
  papa.removeChild(elt);
}

function creer_FCK (valeur, id)
{
  var oFCKeditor = new FCKeditor(id);
  oFCKeditor.BasePath = "/include/FCKeditor/";
  oFCKeditor.Width="295" ;
  oFCKeditor.Height="175" ;
  oFCKeditor.ToolbarSet="Basic";
  oFCKeditor.Config['SkinPath']= "/include/FCKeditor/editor/skins/silver/" ;
  oFCKeditor.Config['EditorAreaCSS']="/css/interface.css" ;
// Contenu de l'éditeur
  oFCKeditor.Value=valeur;
  return oFCKeditor.CreateHtml();
}

function addFCKeditor(dad, child, valeur, id)
{
  var papa = document.getElementById(dad);
  var newtd = document.createElement('td');
  var tdIdName = child;
  newtd.setAttribute('id',tdIdName);
//   newtd.innerHTML = "<td id='bloc'>" + creer_FCK (valeur, id) + "</td>";
  newtd.innerHTML = creer_FCK (valeur, id);
  papa.appendChild(newtd);
}

function creer_textarea (valeur, id)
{
return "<textarea id='" + id + "' name='contenutext' cols='20' rows='3'>" + valeur + "</textarea>";
}

function addtextarea(dad, child, valeur, id)
{
  var papa = document.getElementById(dad);
  var newtd = document.createElement('td');
  var tdIdName = child;
  newtd.setAttribute('id',tdIdName);
//   newtd.innerHTML = "<td id='bloc'>" + creer_textarea (valeur, id) + "</td>";
  newtd.innerHTML = creer_textarea (valeur, id);
  papa.appendChild(newtd);
}

function checkEmail(email)
{
  var filter=/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/i;
  if (filter.test(email))
    return true;
  else
    return false;
}
