function toggleContrast() {
    var styleCookie  = readCookie('style');

    // Extract font part of active cookie, this is added to
    // contrast setting allowing for multiple font sizes with
    // and without high contrast setting.
    
    if(styleCookie.indexOf('font') >= 0) {
        var postfix = styleCookie.substring(styleCookie.indexOf('font'));
    } else {
        postfix = 'font-normal';
    }
    
    contrastSelectorText = document.getElementById('contrast-selector');
    
    // If contrast stylesheet is not set
    if(styleCookie.indexOf('contrast-high') < 0) {
        setActiveStyleSheet('contrast-high-'+postfix);
        
        if(contrastSelectorText != null) {
            contrastSelectorText.innerHTML = 'normalkontrast';
        }
    }
    // If contrast is set, remove it
    else {
        setActiveStyleSheet(postfix);
        
        if(contrastSelectorText != null) {
            contrastSelectorText.innerHTML = 'h&oslash;ykontrast';
        }
    }
}

function toggleFontsize() {
    var styleCookie = readCookie('style');
    
    var prefix = '';
    if(styleCookie.indexOf('contrast') != -1) {
        var prefix = 'contrast-high-';
    }
    
    var fontStyle = 'font-normal';
    if(styleCookie.indexOf('font') != -1) {
        var fontStyle = styleCookie.substring(styleCookie.indexOf('font'));
    }
    
    switch(fontStyle) {
        case 'font-normal':
        setActiveStyleSheet(prefix+'font-medium');
        break;
        case 'font-medium':
        setActiveStyleSheet(prefix+'font-large');
        break;
        case 'font-large':
        setActiveStyleSheet(prefix+'font-normal');
        break;
    }
}

function setActiveStyleSheet(title) {
    var i, a, main;
    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.disabled) {
                a.disabled = false;
            } else {
                a.disabled = true;
            }
        }
    }

	// Set new logo image if using contrast stylesheet
	if (title.search("contrast") == 0) {
		document.getElementById('logo-image').src = "/images/logo_designforalle_contrast.gif";
	} else {
		document.getElementById('logo-image').src = "/images/logo_designforalle.gif";
	}
	
    createCookie("style", title, 365);
}

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;
    
    return "font-normal";
}

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;
}

