﻿/* Style Switcher. fonte http://www.stichpunkt.de/css/switch.html
 rispetto allo script originale, sono stati solo cambiati i nomi delle variabili
 che erano in tedesco, e aggiunta una istruzione fondamentale per il corretto
 funzionamento. */

var style = "default";       // title del css di default
var cookiename = "Layout";   // nome del cookie
var days = 30;               // durata in giorni del cookie

function switchStyle(s) {
  if (!document.getElementsByTagName) return;
  var el = document.getElementsByTagName("link");
  for (var i = 0; i < el.length; i++ ) {
    if (el[i].getAttribute("rel").indexOf("style") != -1 && el[i].getAttribute("title")) {
      el[i].disabled = true;
      if (el[i].getAttribute("title") == s) el[i].disabled = false;
    }
  }
}

function loadStyle() {
  var c = getStyleCookie();
  if (c && c != style) {
    switchStyle(c);
    style = c;
  }
}

function setStyle(s) {
  if (s != style) {
    switchStyle(s);
    style = s;
    setStyleCookie();       // questa istruzione mancava nel sorgente originale
    
  }
}

window.onload = loadStyle;   // carica lo style swichter all' onload


// Funzioni di manipolazione dei cookie

function setCookie(name, value, expdays) {
  var now = new Date();
  var exp = new Date(now.getTime() + (1000*60*60*24*expdays));
  document.cookie = name + "=" + escape(value) + ";" +
                    "expires=" + exp.toGMTString() + ";" +
                    "path=/";
}

function delCookie(name) {   // fa scadere il cookie
  var now = new Date();
  var exp = new Date(now.getTime() - 1);
  document.cookie = name + "=;" +
                    "expires=" + exp.toGMTString() + ";" + 
                    "path=/";
}

function getCookie(name) {   // restituisce il valore del cookie
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    var start = dc.indexOf(cname);
    if (start != -1) {
      start += cname.length;
      var stop = dc.indexOf(";", start);
      if (stop == -1) stop = dc.length;
      return unescape(dc.substring(start,stop));
    }
  }
  return null;
}

function setStyleCookie() {
  setCookie(cookiename, style, days);
}

function getStyleCookie() {
  return getCookie(cookiename);
}

function delStyleCookie() {
  delCookie(cookiename);
}


// Stylesheet per Netscape 4
// necessita di un css a parte
if(document.layers)
  document.writeln("<link rel='stylesheet' type='text/css' href='/nn4.css' />");

/*---------------------------------------------------------------------
                        dimensionetesto
---------------------------------------------------------------------*/

window.onerror = HandleError;function HandleError() {return true}

function dimensionetesto(misura) {
if (!document.getElementsByTagName) {return}
var standard = "xs";
var misure_ = {
  "xs": "0.9em",
  "s": "1.1em",
  "m": "1.3em"
};
if (!misura) {
  var cookie = getCookie("dimensionetesto");
  misura = cookie ? cookie : standard;
}
document.getElementsByTagName('html')[0].style.fontSize = misure_[misura];
setCookie("dimensionetesto", misura, 365);
  for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
    if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title')) {
      if(a.getAttribute('title') == "default") a.disabled = true;
        if(a.getAttribute('title') == "default") a.disabled = false;
    }
  } 
}

window.onload = function(e) {
  dimensionetesto();
  loadStyle()
}
dimensionetesto();
loadStyle()
