
function getNextSibling(startBrother) {
    endBrother = startBrother.nextSibling;
    while (endBrother.nodeType != 1) {
        endBrother = endBrother.nextSibling;
    }
    return endBrother;
}

function getParameter(strParamName) {
    var strReturn = "";
    var strHref = window.location.href;
    var bFound = false;

    var cmpstring = strParamName + "=";
    var cmplen = cmpstring.length;

    if (strHref.indexOf("?") > -1) {
        var strQueryString = strHref.substr(strHref.indexOf("?") + 1);
        var aQueryString = strQueryString.split("&");
        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            if (aQueryString[iParam].substr(0, cmplen) == cmpstring) {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                bFound = true;
                break;
            }

        }
    }
    if (bFound == false) return null;
    return strReturn;
}

function resizeImages(jqueryPattern) {

    $(jqueryPattern).each(function() {

        var height = this.height; //$(this).height();
        var width = this.width; // $(this).width();

        if (height > 100 || width > 100) {

            $(this).width(100);
            var newheight = (100 / width) * height;
            $(this).height(newheight);

            if (newheight > 100) {
                $(this).height(100);
                $(this).width(((100 / height) * width));
            }

            var parentdiv = $(this).parent().parent(0).get(0);
            $(parentdiv).width($(this).width());
            $(parentdiv).height($(this).height());
        }
    });
}

function openWindow(url) {
    window.open(url);
}

function findFirstParentTag(element, tagname) {
    if (!element)
        return element;
    else if (element.tagName == tagname)
        return element;
    else
        return findFirstParentTag(element.parentNode, tagname);
}

// Toegangkelijkheid functies

function setLinkedStyleSheet(a_title) {
    if ($(a_title)) {
        $(".fontColor a").attr('class', 'fontColorNonActive');
        $(".fontColor a#" + a_title).attr('class', 'active');
    }
    var linkNodes = document.getElementsByTagName("link");
    var len = linkNodes.length;
    for (i = 0; i < len; i++) {
        linkNode = linkNodes[i];
        relAttr = linkNode.getAttribute('rel');
        if (relAttr && (relAttr.indexOf("style") != -1) && linkNode.getAttribute("title") && linkNode.getAttribute("title") != 'checkbox') {
            linkNode.disabled = true;
            if (linkNode.getAttribute("title") == a_title)
                linkNode.disabled = false;
        }
    }
    setCookie("setStyle", a_title, 5);

    $("iframe").each(function() {
        try {
            if (frames[$(this).attr("name")] && frames[$(this).attr("name")].setDefaults)
                frames[$(this).attr("name")].setDefaults();
        } catch (Error) { }
    });

    if (a_title == "greyscale") {
        $("img").each(function() {
            if ($(this).attr('src').indexOf('zwartwit') == -1) {
                $(this).attr('src', $(this).attr('src').replace('images/', 'images/zwartwit/'));
            }
        });

        if ($("input.styledcheckbox").length > 0)
            $("input.styledcheckbox").checkbox();
    }

    //window.reload();

    //    alert($('#frame_imagesrvclient').css('z-index'));
}

function changeFont(fontClass) {

    $('.fontbeinvloedbaar').removeClass("normal")
    $('.fontbeinvloedbaar').removeClass("greater")
    $('.fontbeinvloedbaar').removeClass("greatest")

    $('.fontbeinvloedbaar').addClass(fontClass);

    $(".fontSizer a").attr('class', 'nonActive');
    $(".fontSizer a#" + fontClass).attr('class', 'active');

    setCookie("fontSize", fontClass, 5); //REMOVE COMMENT SIGNS TO ENABLED FONT COOKIES

    $("iframe").each(function() {
        if (frames[$(this).attr("name")] && frames[$(this).attr("name")].setDefaults)
            frames[$(this).attr("name")].setDefaults();
    });

    var css_title = getCookie("setStyle");

    if (css_title) {
        setLinkedStyleSheet(css_title);
    } else {
        setLinkedStyleSheet('style');
    }
}

function setDefaults() {
    var _fontSize = getCookie("fontSize");

    if (_fontSize != "") {
        changeFont(_fontSize);
    }
    else { $(".fontSizer a#normal").attr('class', 'active'); }
    var css_title = getCookie("setStyle");

    if (css_title) {
        setLinkedStyleSheet(css_title);
    } else {
        setLinkedStyleSheet('style');
    }

}

function setDefaultsFromUrl() {
    var _fontSize = getURLParam("fontsize");

    if (_fontSize != "") {
        changeFont(_fontSize);
    }
    else { $(".fontSizer a#normal").attr('class', 'active'); }
    var css_title = getURLParam("style");

    if (css_title) {
        setLinkedStyleSheet(css_title);
    }
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setTime(exdate.getTime() + (expiredays * 24 * 60 * 60 * 1000));
    document.cookie = c_name + "=" + escape(value)
                             + ((expiredays == null) ? "" : "; expires=" + exdate.toGMTString());
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return false;
}

function getStyle() {
    return getCookie("setStyle");
}

function getFontSize() {
    return getCookie("fontSize");
}