/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function init() {

    // Schriftgröße
    var fontSize = getCookieValue("fontSize");

    if(fontSize == null)
        document.cookie = "fontSize=10; path=/";
    else {
        changeFontSize(fontSize);
    }

    document.getElementById("btn_decreaseFontSize").onclick = decreaseFontSize;
    document.getElementById("btn_resetFontSize").onclick = resetFontSize;
    document.getElementById("btn_increaseFontSize").onclick = increaseFontSize;

    document.getElementById("GwnSearchForm_SearchForm_Search").onfocus = document.getElementById("GwnSearchForm_SearchForm_Search").select;

    // Kontrast
    var contrast = getCookieValue("contrast");

    if(contrast == "darkBackground")
        switchToDarkBackground();
     
    document.getElementById("btn_contrastBright").onclick = switchToBrightBackground;
    document.getElementById("btn_contrastDark").onclick = switchToDarkBackground;


    // Fokus von Textfeldern
    changeSSFormFieldBackgroundColorOnFocus("input", "EditableTextField");
    changeSSFormFieldBackgroundColorOnFocus("input", "EditableEmailField");
    changeSSFormFieldBackgroundColorOnFocus("textarea", "EditableTextField");




}

function changeSSFormFieldBackgroundColorOnFocus(tag, name) {
    var inputFields = document.getElementsByTagName(tag);

    for (i = 0; i < inputFields.length; i++) {
        var currentField = inputFields[i];
        var currentName = currentField.getAttribute("name");

        if (currentName.substr(0, name.length) == name) {

            currentField.onfocus = changeTextFieldBackgroundToDarkBlue;
            currentField.onblur = changeTextFieldBackgroundToGray;

        }
    }
}


function changeTextFieldBackgroundToDarkBlue() {
    this.parentNode.style.backgroundColor = "#002D69";
}

function changeTextFieldBackgroundToGray() {
    this.parentNode.style.backgroundColor = "#E9E9E9";
}


function getCookieValue(id) {
    var cookieString = document.cookie;
    var cookieArray = cookieString.split("; ");

    for (var i = 0; i < cookieArray.length; i++) {
        var entrySet = cookieArray[i].split("=");
        var key = entrySet[0];
        var value = entrySet[1];
        if (key == id) {
            return value;
        }
    }

    return null;
}


function decreaseFontSize() {
    var fontSize = getCookieValue("fontSize");
    var newSize = parseInt(fontSize) - 1;

    changeFontSize(newSize);
}

function increaseFontSize() {
    var fontSize = getCookieValue("fontSize");
    var newSize = parseInt(fontSize) + 1;

    changeFontSize(newSize);
}

function resetFontSize() {
    changeFontSize(10);
}


function changeFontSize(size) {
    document.cookie = "fontSize=" + size + "; path=/";
    
    document.getElementById("body").style.fontSize = size + "px";
    document.getElementById("inhaltsbereich").style.fontSize = size + "px";
}


function switchContrast() {
    

//    var contrast = getCookieValue("contrast");
//
//    if (contrast == null)
//    if (contrast == "darkBackground") {
//
//    }

//    if (addLinkElement) {
//
//    } else {
//        if (document.getElementById("kontrastCSS"))
//            document.getElementById("head").removeChild(document.getElementById("kontrastCSS"));
//    }
    
    //contrastCSS[cssFile] = cssFile;
}

function switchToDarkBackground() {
    var cssFile = '/themes/gwnneu/css/kontrast_dunkel.css';
    var linkElement = document.createElement('link');


    linkElement.rel = 'stylesheet';
    linkElement.type = 'text/css';
    linkElement.id = 'kontrastCSS';
    linkElement.href = cssFile;

    document.getElementById('head').appendChild(linkElement);

    document.cookie = "contrast=darkBackground; path=/";
}

function switchToBrightBackground() {
    document.getElementById("head").removeChild(document.getElementById("kontrastCSS"));

    document.cookie = "contrast=brightBackground; path=/";
}

function showContactDetails(id) {

    var display = document.getElementById("AnsprechpartnerInfos" + id).style.display;

    document.getElementById("AnsprechpartnerInfos" + id).style.display = (display == "none" || display == "") ? "block" : "none";

    return false;
}

function closeSubmenu(id) {
    var display = document.getElementById("unternavigation" + id).style.display;
    
    document.getElementById("unternavigation" + id).style.display = (display == "none") ? "block" : "none";

    return true;
}


function showClientDetails(id) {

    var display = document.getElementById("Referenz" + id).style.display;

    document.getElementById("Referenz" + id).style.display = (display == "none" || display == "") ? "block" : "none";

    return false;
}
