// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/
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;
}
function init_2col()
{
// On récupère les listes du coeur de page (contenu) dans une variable (un array), ici ul.
// les li "impairs" sont forcés à gauche
var ul=document.getElementById("contenu").getElementsByTagName("ul")[0];
var enf = ul.childNodes; /* li et text */
var nb_enf = enf.length;
var gauche = true;
var larg_demi_ul = (ul.offsetWidth)/2;
var larg_tiers_ul = (ul.offsetWidth)/3;
var prec = 0;
for (var i = 0 ; i < nb_enf ; ++i) {
if (enf[i].nodeName == "LI")
{
// ne doit s'appliquer qu'aux listes sur 2 colonnes, donc dont les li sont entre le tiers et la moitie de la largeur du ul
if ((enf[i].offsetWidth < larg_demi_ul)&&(enf[i].offsetWidth > larg_tiers_ul)){
if (gauche == true)
{
//	document.write(" -- i " + i+ ", height " + enf[i].style.height);
enf[i].style.clear = "both";
gauche = false;
prec = i;
}
else {
gauche = true;
if ( (enf[i].offsetHeight < enf[prec].offsetHeight) )
{
enf[i].style.height = enf[prec].offsetHeight;
}
}
}
}
}
}
function getFloat(elId) {
var el = document.getElementById(elId),v = '';
if (typeof el.style.styleFloat === 'string') {
v += 'M$ mode = ' + el.style.styleFloat + '\n';
}
if (typeof el.style.cssFloat === 'string') {
v += 'W3C mode = ' + el.style.cssFloat;
}
alert(v);
}
//window.onload = function(e) {
// var cookie = readCookie("style");
// var title = cookie ? cookie : getPreferredStyleSheet();
// setActiveStyleSheet(title);
//}
//window.onload = init_2col;
window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Simon Willison | http://simon.incutio.com/ */
function addLoadEvent(maFonction) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = maFonction;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
maFonction();
}
}
}
addLoadEvent(init_2col);
addLoadEvent(function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}
);

