// Auteur : Mathieu Fay

// Adaptation perso pour bug Safari

// ------------------------------------------------------

var swctobj     = null ;

var swcttabtitl = new Array() ;

var swcttabhref = new Array() ;

function setActiveStyleSheet(title) 

{  ecritCookie(title);

   var i, a, href;

   var swcti = -1 ; 

   if (swctobj == null)

   {  for(i=0; (a = document.getElementsByTagName("link")[i]); i++)

      {  if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))

         {  a.disabled = true ;

            swcti++ ;

            swcttabtitl[swcti]  = a.title ;

            swcttabhref[swcti] = a.href ;     

            if(a.title == title)

            {  href = a.href ;

      }  }  } 

      var parent = document.getElementsByTagName("head")[0]

      swctobj = document.createElement("link") ;

      swctobj.setAttribute("type", "text/css") ; 

      swctobj.setAttribute("rel", "stylesheet") ; 

      swctobj.href = href ;

      parent.appendChild(swctobj)

   }

   else

   {  for(i in swcttabtitl)

      {  if (swcttabtitl[i] == title)

         {  swctobj.href = swcttabhref[i] ; 

}  }  }  }


// Ecriture du COOKIE pour 1 an

// -----------------------------

function ecritCookie(NomStyle) 

{  var expires = new Date();

   expires.setTime(expires.getTime()+(1*365*24*3600*1000));

   document.cookie = 'FeuilleStyle=' + NomStyle + '; expires=' + expires.toGMTString();

}

// Recuperation du COOKIE, est appele en premier dans la page

// ----------------------------------------------------------

function recupCookie()

{  if(document.cookie != '')

   {  var cookies = document.cookie.split(/; */);

      for(var i=0; i < cookies.length; i++)

      {  cookies[i] = cookies[i].split(/=/);

         if(cookies[i][0] == 'FeuilleStyle')

         {  setActiveStyleSheet(cookies[i][1]) ;

}  }  }  }

recupCookie();
