var Stil = "Standard";
var Keks = "Layout";
var Tage = 30;
var prefsLoaded = false;
var defaultFontSize = 80;
var currentFontSize = defaultFontSize;

// Style Switcher


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 != Stil) {
    switchStyle(c);
    Stil = c;
  }
}

function setStyle(s) {
  if (s != Stil) {
    switchStyle(s);
    Stil = s;
    // 10.08.2007 MOZ
    setStyleCookie();
  }
}

// Cookie-Funktionen

function setCookie(name, value, expdays) {   // gültig expdays Tage
  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) {   // expires ist abgelaufen
  var now = new Date();
  var exp = new Date(now.getTime() - 1);
  document.cookie = name + "=;" +
                    "expires=" + exp.toGMTString() + ";" + 
                    "path=/";
}

function getCookie(name) {
  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() {
  // 10.08.2007 MOZ
  // setCookie(Keks, Stil, Tage);
  // ersetzt durch
  createCookie(Keks, Stil, Tage);
}

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

function delStyleCookie() {
  delCookie(Keks);
}
// Stylesheet für Netscape 4
if(document.layers)
  document.writeln("<link rel='stylesheet' type='text/css' href='/nn4.css' />");

// my_styleswitcher.js

function revertStyles(){
        currentFontSize = defaultFontSize;
        changeFontSize(0);
}

function changeFontSize(sizeDifference){
        currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);
        if(currentFontSize > 220){
                currentFontSize = 220;
        }else if(currentFontSize < 60){
                currentFontSize = 60;
        }
        setFontSize(currentFontSize);
};

function setFontSize(fontSize){
        var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
        document.body.style.fontSize = fontSize + '%';

        //alert (document.body.style.fontSize);
};

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 setUserOptions(){
        loadStyle();
		if(!prefsLoaded){
                cookie = readCookie("fontSize");
                currentFontSize = cookie ? cookie : defaultFontSize;
                setFontSize(currentFontSize);
                prefsLoaded = true;
        }
}

function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
}

window.onload = setUserOptions;
//window.onload = loadStyle;
window.onunload = saveSettings;
