// what is switchable via the style switcher ?
// bigFontsNormColor
// normFontsContrColor
// normal
// what further combinations should be possible ?
// bigFontsContrColor 


var Stil = "Standard";
var Keks = "Layout";
var Tage = 30;

var fontSizeStyle;
var colorStyle;
var fontSizeStyleCookie = "fontSizeLayout";
var colorStyleCookie = "colorLayout";

function setActiveStyleSheet(title, switchMode) {

	var i;
	var a;
	var main;

	if (title != Stil) {

		/*
		 * look up for styles set during the last switch action and 
		 * look up, what should be switched; 
		 */
		if (title.indexOf("bigFonts") > -1) {

			if (getCookie(colorStyleCookie) == "contrColor")
				 title = "bigFontsContrColor";
		}
		if (title.indexOf("ContrColor") > -1) {

			if (getCookie(fontSizeStyleCookie) == "bigFonts")
				 title = "bigFontsContrColor";
		}
		if (title.indexOf("normal") > -1) {

			if (switchMode == "fontSizeSwitch") {

				if (getCookie(colorStyleCookie) == "contrColor")
					title = "normFontsContrColor";
				// delete the old font size style cookie ... 
				delCookie(fontSizeStyleCookie);
			} else if (switchMode == "colorSwitch") {

				if (getCookie(fontSizeStyleCookie) == "bigFonts")
					title = "bigFontsNormColor";
				// delete the old color style cookie ... 
				delCookie(colorStyleCookie);
			}
		}

		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.getAttribute("title") == "normal")
					a.disabled = false;
			}
			
		}

		Stil = title;

		setCookie(Keks, Stil, Tage);
		if (title.indexOf("bigFonts") > -1)
			setCookie(fontSizeStyleCookie, "bigFonts", Tage);
		if (title.indexOf("normFonts") > -1)
			setCookie(fontSizeStyleCookie, "normFonts", Tage);
		if (title.indexOf("ContrColor") > -1)
			setCookie(colorStyleCookie, "contrColor", Tage);
		if (title.indexOf("NormColor") > -1)
			setCookie(colorStyleCookie, "normColor", Tage);
	}
	
}

function loadStyle() {
  var c = getCookie(Keks);
  if (c && c != Stil) {
    setActiveStyleSheet(c);
    Stil = c;
  }
}

window.onload = loadStyle;


// 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 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 delCookie(name) {   // expires ist abgelaufen
  var now = new Date();
  var exp = new Date(now.getTime() - 1);
  document.cookie = name + "=;" +
                    "expires=" + exp.toGMTString() + ";" + 
                    "path=/";
}

function delStyleCookie() {
  delCookie(Keks);
}


