﻿
/**************** TOP MENU ********************************/

function imgHover(image, menuID) {
    if (document.body) 
    {
        var element = document.getElementById(menuID);
        element.src = image;
    }
}

//changes the text size on page
function ChangeSize(classname) {
    document.getElementById("page").className = classname;
    setTextSizeCookie('textSize', classname, 365);
    /*setInfoBlockHeights();*/
}
//set text size cookie
function setTextSizeCookie(name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    var cookie_string = name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
    document.cookie = cookie_string;
}
//get text size cookie
function getTextSizeCookie(cookie_name) {
    if (document.cookie.length > 0) {
        var c_start = document.cookie.indexOf(cookie_name + "=");
        if (c_start != -1) {
            c_start = c_start + cookie_name.length + 1;
            var 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 "";
}
//check if text size cookie exsits, if so changes text size on page
function checkCookies() {
    var textSizeCookie = getTextSizeCookie('textSize');
    if (textSizeCookie != null && textSizeCookie != "") {
        document.getElementById("page").className = textSizeCookie;
    }
    setInfoBlockHeights();
}

//sets heights for info blocks
function setInfoBlockHeights() {
    //Children block
    var innerTextChildrenHeight = calculateDivHeights("innerTextChildren");
    var infoBlockChildren = document.getElementById("infoBlockChilden");
    if (infoBlockChildren != null) {
        infoBlockChildren.style.height = innerTextChildrenHeight + 'px';
    }


    //Youth block
    var innerTextYouthHeight = calculateDivHeights("innerTextYouth");
    var infoBlockYouth = document.getElementById("infoBlockYouth");
    if (infoBlockYouth != null) {
        infoBlockYouth.style.height = innerTextYouthHeight + 'px';
    }


    //Family block
    var innerTextFamilyHeight = calculateDivHeights("innerTextFamily");
    var infoBlockFamily = document.getElementById("infoBlockFamily");
    if (infoBlockFamily != null) {
        infoBlockFamily.style.height = innerTextFamilyHeight + 'px';
    }

    //Experts block
    var innerTextExpertsHeight = calculateDivHeights("innerTextExperts");
    var infoBlockExperts = document.getElementById("infoBlockExperts");
    if (infoBlockExperts != null) {
        infoBlockExperts.style.height = innerTextExpertsHeight + 'px';
    }
}

//returns hight of a div
function calculateDivHeights(divId) {
    if (document.getElementById(divId)) {
        var height = document.getElementById(divId).clientHeight;
        return height;
    }
    return null;
}
function getElementsByClass(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
    var i;
    var j;
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function curveConersInfoBox() {
    var InfoBox = RUZEE.ShadedBorder.create({ corner: 5, edges: "blr", border: 1 });
    var boks = getElementsByClass("boksTekst", null, "div");
    if (boks.length > 0) {
        for (var i = 0; i < boks.length; i++) {
            InfoBox.render(boks[i]);
        }
    }
    var relatertBoks = getElementsByClass("relatertboksTekst", null, "div");
    if (relatertBoks.length > 0) {
        for (var i = 0; i < relatertBoks.length; i++) {
            InfoBox.render(relatertBoks[i]);
        }
    }
}

/* Show or hide all images */
function hideImage() {
    for (var i = 0; i < document.images.length; i++) {
        var image = document.images[i];
        if (image.style.display == "none") {
            image.style.display = "inline";
        }
        else {
            image.style.display = "none";
        }
    }
}

function addDocTracking() {
    $('a[href*="/Documents/"]').each(function(i, e) {
        $(this).click(function() {
            var file = $(this).attr("href");
            var index = file.indexOf('.');
            if (index > -1) {
                _gaq.push(['_trackPageview', file]);
            }

        });
    });
}

function emptyField(clientID, defaultText) {
    var txtField = document.getElementById(clientID);
    if (txtField.value == defaultText)
        txtField.value = '';
}
