/* Saemtliche Rechte: Aktion Mensch - Einfach fuer Alle */
/* Lizenzbedingungen zur freien Nutzung: http://www.einfachfueralle.de/lizenz/ */

function setActiveStyleSheet(title) {
   if(title=="1"){
   	index=document.styleswitch.style_auswahl.selectedIndex;
   	title = document.styleswitch.style_auswahl.options[document.styleswitch.style_auswahl.selectedIndex].value;
   }
   else{
   	if(title=="style-0") index=0;
   	else if(title=="style-1") index=1;
   	else if(title=="style-2") index=2;
   	title = title;
   }
   status = title;
   var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) {
				a.disabled = false;
				if(cookiesEnabled()==1) setCookie("style", title, 365);
      }
    }
  }
  return false;
}

function init(){
	setActiveStyleSheet(title);
	document.styleswitch.style_auswahl.value = title;
}

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 cookiesEnabled() {
 var result=3;  // undefined, if the browser does not know the property
 if (navigator.cookieEnabled!=null) {
  if (navigator.cookieEnabled) result=1;
  else result=2;
 }
 return result;
}

function setCookie(a_name, a_value, a_lifetime) {  // a_lifetime in Tagen
 var now = new Date();
 var expiry = new Date(now.getTime() + a_lifetime*24*60*60*1000);
 if ((a_value != null) && (a_value != ""))
  document.cookie=a_name + "=" + escape(a_value) + "; expires=" + expiry.toGMTString();
 return getCookie(a_name) != null; // Test, ob es geklappt hat
}

function getCookie(a_name) {
 var a_start, an_end;
 if (document.cookie) {
  a_start = document.cookie.indexOf(a_name+"=");
  if (a_start < 0) return null;
  a_start = document.cookie.indexOf("=", a_start) + 1;
  an_end = document.cookie.indexOf(";", a_start);
  if (an_end < 0) an_end = document.cookie.length;
  return unescape(document.cookie.substring(a_start, an_end));
 }
 else return null;
}

function deleteCookie(a_name) {
 var now = new Date();
 var expired = new Date(now.getTime() - 2*24*60*60*1000);  // 2 Tage zurueck
 document.cookie=a_name + "=null; expires=" + expired.toGMTString();
}


if(cookiesEnabled()==1) var cookie = getCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
var index=0;

setActiveStyleSheet(title);