/*** common functions ***/

function trim(x) {
    x = x.replace(/^\s*(.*)/, "$1");
    x = x.replace(/(.*?)\s*$/, "$1");
    return x;
}


/*** cookie functions ***/

function writeCookie(name, value) {
    var expDate = new Date();
    expDate = new Date(expDate.getTime() + (1000*60*60*24*365));
    document.cookie = name + '=' + escape(value) + '; expires=' + expDate.toGMTString() + '; path=/';
}

function readCookie(name) {
    localCookie = document.cookie;
    var cookieEntries = localCookie.split(";");
    for(var i=0; i<cookieEntries.length; i++) {
        splittedCookieEntry = cookieEntries[i].split("=");
        if(trim(splittedCookieEntry[0]) == trim(name)) {
            return unescape(splittedCookieEntry[1]);
        }
    }
    return "";
}

function deleteCookie(name) {
    document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}


/*** other ***/

function minimizeHeader() {
    var headerBody = $("headerbody");
    var headerTopButtonLink = $("headertopbuttonlink");
    headerBody.style.display = "none";
    headerTopButtonLink.style.backgroundImage = 'url(fileadmin/_img/btn-maximize.png)';
    headerTopButtonLink.innerHTML = "Bereich vergr&ouml;&szlig;ern";
    writeCookie("headerTransformValue", '1');
}

function maximizeHeader() {
    var headerBody = $("headerbody");
    var headerTopButtonLink = $("headertopbuttonlink");
    headerBody.style.display = "block";
    headerTopButtonLink.style.backgroundImage = 'url(fileadmin/_img/btn-minimize.png)';
    headerTopButtonLink.innerHTML = "Bereich verkleinern";
    writeCookie("headerTransformValue", '0');
    //deleteCookie("headerTransformValue");
}

function transformHeader(effect) {
    if(readCookie("headerTransformValue") == "" || readCookie("headerTransformValue") == "0") {
        minimizeHeader();
    }
    else {
        maximizeHeader();
    }
}

function updateHeader() {
    if(readCookie("headerTransformValue") == '1') {
        minimizeHeader();
    }
}

function printSite() {
    window.print();
}

function switchClipClap(object, type) {
    var parentChildNodes = object.parentNode.parentNode.childNodes;
    var objectChildNodes = object.childNodes;
    var innerText = 'Vergr&ouml;&szlig;ern';
    var backgroundImagePostfix;
    for(var i=0; i<parentChildNodes.length; i++) {
        var object = parentChildNodes[i];
        if(object.className) {
            if(object.className == 'contentdiv_clipclapbody') {
                if(!object.style.display || object.style.display == 'none') {
                    object.style.display = 'block';
                    backgroundImagePostfix = 'close';
                    innerText = 'Verkleinern';
                }
                else {
                    object.style.display = 'none';
                    backgroundImagePostfix = 'open';
                    innerText = 'Vergr&ouml;&szlig;ern';
                }
            }
        }
    }
    for(var i=0; i<objectChildNodes.length; i++) {
        var object = objectChildNodes[i];
        if(object.className) {
            if(object.className == 'contentdiv_clipclapheadright') {
                if(type == 0) {
                    object.style.backgroundImage = 'url(/fileadmin/_img/btn-clipclap-right-' + backgroundImagePostfix + '.png)';
                }
                if(type == 1) {
                    object.style.backgroundImage = 'url(/fileadmin/_img/btn-clipclapwithtitle-right-' + backgroundImagePostfix + '.png)';
                }
            }
            if(object.className == 'contentdiv_clipclapheadmiddle') {
                object.innerHTML = innerText;
            }
        }
    }
}


/*** font size ***/

function decreaseFontsize() {
    changeFontsize(-1);
}

function increaseFontsize() {
    changeFontsize(1);
}

function changeFontsize(value) {
    if(document.body.style.fontSize == "")
        document.body.style.fontSize = "12px";
    var currentFontsize = parseInt(document.body.style.fontSize);
    currentFontsize += parseInt(value);
    if(currentFontsize > 8 && currentFontsize < 20)
    document.body.style.fontSize = currentFontsize + "px";
}

function resetFontsize() {
    document.body.style.fontSize = "12px";
}


/*** tooltip ***/

function showTooltip(title, text, object) {
    Tip(text, TITLE, title, TITLEPADDING, 7, DELAY, 0, FONTFACE, 'helvetica, arial, verdana', TITLEFONTSIZE, '12px', EXCLUSIVE, true, FIX, [object, -260, 5], FOLLOWMOUSE, false, CLOSEBTNCOLORS, ['#666', '#fff', '#666', '#fff'], STICKY, true, CLOSEBTN, true, PADDING, 10, WIDTH, 300, BGCOLOR, '#fff', BORDERWIDTH, 0, TITLEBGCOLOR, '#fff', FONTCOLOR, '#000', TITLEFONTCOLOR, '#000', SHADOW, false);
}

function hideTooltip() {
    UnTip();
}
