function setActiveStyleSheet()
{
    var i, a, main;
    var title = '';
    
    if (document.getElementById("style")) {
        title = document.getElementById("style").value;
    }
    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;
	            setCookie("screencms_wai_style", title, 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 checkKey()
{
	if (window.event && window.event.keyCode == 13) {
		setActiveStyleSheet();
	}
}
function showStyleswitcher()
{
    var cookie = getCookie("screencms_wai_style");
    var selected = false;
    document.write('<form action="#" style="margin:0; padding:0;">');
    document.write('<label style="vertical-align:middle;" for="style" title="Hier k&ouml;nnen Sie das Aussehen dieser Seiten ver&auml;ndern" style="margin:0; padding:0.3em 0em 0em 0em; float:left;">Stil:&nbsp;</label>');
	if (navigator.appName == "Microsoft Internet Explorer") {
    document.write('<select style="vertical-align:middle;" id="style" size="1" onkeypress="checkKey()" onclick="setActiveStyleSheet()">');
	}
	else {
    	document.write('<select style="vertical-align:middle;" id="style" size="1" onchange="setActiveStyleSheet()" onclick="setActiveStyleSheet()">');
	}
    if (!cookie || (cookie != "bg" && cookie != "sw" && cookie != "ws")) {
        document.write('<option selected="selected" value="Standard" title="Standard">Standardversion&nbsp;</option>');
        selected = true;
    } else {
	   document.write('<option value="Standard" title="Standard">Standardversion&nbsp;</option>');
    }
    if (cookie == "bg" && selected == false) {
	   document.write('<option value="bg" title="bg" selected="selected">Blau Gelb</option>');
	   selected = true;
    } else {
        document.write('<option value="bg" title="bg">Blau Gelb</option>');
    }
    if (cookie == "sw" && selected == false) {
	   document.write('<option value="sw" title="sw" selected="selected">Schwarz Wei&szlig;</option>');
	   selected = true;
    } else {
        document.write('<option value="sw" title="sw">Schwarz Wei&szlig;</option>');
    }
    if (cookie == "ws" && selected == false) {
        document.write('<option value="ws" title="ws" selected="selected">Wei&szlig; Schwarz</option>');
        selected = true;
    } else {
        document.write('<option value="ws" title="ws">Wei&szlig; Schwarz</option>');
    }
	document.write('</select></form>');
}
var cookie = getCookie("screencms_wai_style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
