﻿function equalHeight(divs) {
    if (!divs)
        divs = jQuery(".equalHeight");
    var maxHeight = 0;
    divs.height("");

    divs.each(function() {
        if (jQuery(this).height() > maxHeight)
            maxHeight = jQuery(this).height();
    })
    divs.height(maxHeight);
}

function stripHtml(text) {
    var newElement = document.createElement('DIV');
    newElement.innerHTML = text;
    return newElement.textContent || newElement.innerText;
}

function JustText(element) {
    return element.clone().children().remove().end().text();
}

function EmailPage(link) {
    if (!link)
        link = document.referrer;

    var subject = escape(document.title);
    var body = escape('Her er en side som jeg tror du vil finde interessant ' + link);
    var mailtolink = 'mailto:?subject=' + subject + '&body=' + body;
    mailWindow = window.open(mailtolink,'mailWindow');
    if (mailWindow && mailWindow.open && !mailWindow.closed) mailWindow.close();
}

Number.prototype.toDanishFormat = function () {
    var roundedNo = new String(Math.round(this * 100) / 100);
    var decimaler = new String();
    var helTal = new String();

    if (roundedNo.indexOf(".") != -1) {
        decimaler = roundedNo.substr(roundedNo.indexOf("."));
        helTal = roundedNo.substr(0, roundedNo.indexOf("."));
        decimaler = "," + decimaler.slice(1);
        if (decimaler.length == 2)
            decimaler += "0";
    }
    else
        helTal = roundedNo.toString();

    var regex = new RegExp('(-?[0-9]+)([0-9]{3})');
    while (regex.test(helTal)) {
        helTal = helTal.replace(regex, '$1.$2');
    }
    return helTal + decimaler;
}

function initDst() {
    
    jQuery(".NavTabs > ul > li").click(function () {
        var subMenu = jQuery(this).children();
        if (subMenu.css('display') == 'none') {
            jQuery(this).siblings().children("ul").slideUp('fast');
            jQuery(".menuOpen").removeClass("menuOpen");
            subMenu.slideDown('fast');
            if (!jQuery(this).hasClass("ActiveTab"))
                jQuery(this).addClass('menuOpen');
            return false;
        }
    });

    jQuery(document).click(function () {
        jQuery(".NavTabs > ul > li").children("ul").slideUp('fast');
        jQuery(".menuOpen").removeClass("menuOpen");
    });

    jQuery(".foldud .section > a:first-child").click(function () {
        foldudToggle($(this).parent());
    });

    if (window.location.hash) {
        $("div > a:first-child[name=" + window.location.hash.substr(1) +"]").parent().addClass("open");
    }

    $(".xmlstb_fodnoteclick").click(function () { equalHeight(); });
}

function foldudToggle(section) {
    $(section).toggleClass("open");
    equalHeight();
}
