//gestion de l'agrandissemente de la police de caracteres (outil) 
var tailleTexte = 11;
//taille initial du text
var tailleInit = 11;
//taille maximum autorise 
var tailleMax = 17;
//nom de la div ou ce trouve les texte a agrandir
var divPrincipal = 'conteneur';
// -- menu -->	
function open_ext_link()
{
	var liens = document.getElementsByTagName('a');
	for( var i = 0 ; i < liens.length ; i++)
	{
		if(liens[i].className == 'lien_ext')
		{
			liens[i].onclick = function()
			{
				window.open(this.href);
				return false;
			}
		}
	}
}

function mesure(_MesurePro, _page)
{
	scr_w = screen.width;
	scr_h = screen.height;
	color = screen.colorDepth;
	ref = escape(window.document.referrer);
	
	document.write("<IMG src='http://noeinteractive.stats-pro.com/stats/satvac/marqueur.pl/"+ "?page="+ _page+ "&n="+ Math.round (Math.random () * 1000000000000000)+ "&reso_w="+ scr_w+ "&reso_h="+ scr_h+ "&color="+ color+ "&referer="+ ref+"' border=0>");
}

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

//
window.onload = function(e) {

	  var cookie = readCookie("style");
	  var title = cookie ? cookie : getPreferredStyleSheet();
	  setActiveStyleSheet(title);
	  open_ext_link();
	  
	   if(document.getElementById('agendadet'))
       { 
            var i=0;
            while(document.getElementById("section"+i))
            {
            	afficherCritere('section'+i);
            	i++;
            }
        }
        
       if(document.getElementById('actualite'))
       { 
            var i=0;
            while(document.getElementById("section"+i))
            {
            	afficherCritere('section'+i);
            	i++;
            }
        }
        
        if(document.getElementById('publication'))
       { 
            var i=0;
            while(document.getElementById("section"+i))
            {
            	afficherCritere('section'+i);
            	i++;
            }
        }
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

function PopUp2(URL,WIDTH,HEIGHT) {
	options="toolbar=no,location=no,directories=no,status=no,menubar=no,top=20,left=30, scrollbars=no,resizable=no,width=1,height=1"
	Box = window.open (URL,"Windows",options)
	Box.close()
	options="toolbar=no,location=no,directories=no,status=no,menubar=no,top=20,left=30, scrollbars=no,resizable=no,width="+WIDTH+",height="+HEIGHT
	Box = window.open (URL,"Windows",options)
	Box.focus();
}



function afficherCritere(obj,link){

       var affCrit = document.getElementById(obj);
       //var affTR = document.getElementById('tr'+obj);
       if (affCrit.style.display == "none")
       {
            //affTR.style.background = "#111210";
            var i=0;
            /*while(document.getElementById("section"+i))
            {
                if('section'+i != obj)
                {
                    document.getElementById('trsection'+i).style.background = "inherit";
                }

            	i++;
            }*/
       		affCrit.style.display = "block";  
       		if (link!=undefined)
       		{
       		    // link.style.background='url(../images/puce_moins.gif) 0px 2px no-repeat';
       		     if(document.getElementById("sectionaffiche"))
       		     {
       		       //alert(obj);
                      document.getElementById("sectionaffiche").value= affCrit.name;     
                 }
       		}       		
       	}else{
       	  if (link!=undefined)
       	  {
       	      //link.style.background='url(../images/puce_plus.gif) 0px 2px no-repeat';
       	  }       	
       		affCrit.style.display = "none";
       		affCrit.Offset = window.pageYOffset;
       	}

}



/*GESTION DU ZOOM */

/*@
    Fonction : changeTaille 
    Description : change la taille de la police d'un page
    Variable : pas (int) -> Valeur indiquant de combien de pixel la taille doit etre diminue ou
                        augmenter (souvent -1 ->diminution ou 1 -> augmentation) 
    
@*/
function changeTaille(pas)
{
  
  //determine si on veut changer de la taille de la poilce ou non (en rapport au taille max et initial defini)     
  var changeSize = true;
  
  tailleTexte = tailleTexte + pas;
    
  //on va verifier si la taille du texte n'est pas inferieur a la taille minimum
  if (tailleTexte < tailleInit)
  {
        //si la taille minumm a ete atteinte, on remet notre tailleTexte a la taille minumum, et
        //on considereque ce n'est pas la peine de changer la taille des element
        tailleTexte = tailleInit;
        changeSize = false;
   
  }        
  else
  {
        //cette fois ci on verifier que la taille maximum n'a ete atteinte
        if (tailleTexte > tailleMax)
        {
            tailleTexte = tailleMax;
            changeSize = false;
        }
  }
  
  //si changesize est true, c partie on change la taille de la police !!
  if (changeSize)
  {
      var text = document.getElementById(divPrincipal);
      
      //ici on va changer la taille de tout les p de la page
      //ICI ON MET TOUT LES TAGS QUI N'AUGMENTE PAS CA TAILLE AVEC LA SIMPLE INSTRUCTION 
      // text.style.fontSize = tailleTexte + 'px';
      
      updateTaille(text,'p',tailleTexte)
      updateTaille(text,'h6',tailleTexte)
      
      //on rajoute quand meme cette ligne pour augmenter d'autre element
      text.style.fontSize = tailleTexte + 'px';

  }
 
}

/*@
    Fonction  : updateTaille 
    Description : Change la taille des bloc d'une page(fonction appele dans changeTaille)
    Variables : - > divParent(object) : div de notre page pour laquel on veux changer la taille du texte
                - > tag (text) -> : tag html de l'element qui fera l'objet d'un changement de taille 
                              (ex : p, si l'on veut changer la taille de tout les p)
                - > tailleText : taille du texte
    
@*/
function updateTaille(divParent,tag,tailleTexte)
{

        //determine si on veut changer de la taille de la poilce ou non (en rapport au taille max et initial defini)  
        var changeSize = true;
        
        //on va augmenter la taille de tout ce qui ce trouve dans p
        var textPart = divParent.getElementsByTagName(tag);
        for (var i = 0; i < textPart.length; i++) 
        {
            textPart[i].style.fontSize = tailleTexte + 'px';
        }  
}
