﻿var timeoutid = 0, curcat = 0, lastidx = 0;

function testNumericField(field) {
    var regExpr = new RegExp("^[0-9]+$");
    if (!regExpr.test(field.value)) {
        // Case of error
        field.value = "0";
    }
    if (field.value > 44640) {
        // Case of error
        field.value = "44640";
    }
}

$(function() {

    $('.servicecategory').click(function() { changeServiceValues(true); });
    $('.serviceusage').click(function() { changeServiceValues(true); });
    $('#popup').dialog({ autoOpen: false, position: ['center', 40], width: 810, height: 740 });
    $('#disclaimer').dialog({ autoOpen: false, position: ['center', 400], resizable: false, width: 500 });
    $('#terms').dialog({ autoOpen: false, width: 800, resizable: false });
    //$('#sliderpop').dialog({ autoOpen: false, resizable: false }).parent().addClass('sliderpop');
    $('#acceptTerms').dialog({ autoOpen: false, position: [400, 400], 'min-height': 50, height: 50, width: 225, resizable: false });
    $('#assumptions').dialog({ autoOpen: false, position: ['center', 400], width: 500, resizable: false });
    $('.popupdirections').click(function() {
        $('#popup').dialog('open');
        return false;
    });

    $('.popupdirections').click(function() {
        $('#popup').dialog('open');
        return false;
    });
    $('a.disclaimer').click(function() {
        var pos = $('a.disclaimer').offset();
        $('#disclaimer').dialog('option', 'position', [Math.min(pos.left - 120), Math.ceil(pos.top - $('html').scrollTop() - 430)]);
        $('#disclaimer').dialog('open');
        return false;
    });
    $('a.terms').click(function() {
        var pos = $('a.terms').offset();
        $('#terms').dialog('option', 'position', ['center', pos.top - 400]);
        $('#terms').dialog('open');
        return false;
    });
    $('a.assumptions').click(function() {
        $('#assumptions').dialog('option', 'position', ['center', 'center']);
        $('#assumptions').dialog('open');
        return false;
    });

    $('.validatedetail').add('.PhoneProportion').change(function() { $('#PhonePrices_MyChoice').val('true') });

    $('#slider .main').slider({
        value: 50,
        start: function(event, ui) {
            changeServiceValues(true);
            redrawSliderPop();
            $('#sliderpop').show(); //('open');
        },
        slide: function(event, ui) { changeServiceValues(true); redrawSliderPop(); },
        change: function(event, ui) { changeServiceValues(true); redrawSliderPop(); $('#PhonePrices_sliderval').val($('#slider .main').slider('option', 'value')); },
        stop: function(event, ui) { setTimeout("$('#sliderpop').hide();//('close');", 500); }
    });

    $("#slider a.ui-slider-handle").html($("#slider a.ui-slider-handle").html() + "<div id='sliderpop'>. </div>");

    $('#resetmarketshare').click(function() {
        $('#PhonePrices_iVodafoneProportion').val($('#PhonePrices_iVodafoneProportionHidden').val());
        $('#PhonePrices_iNovaProportion').val($('#PhonePrices_iNovaProportionHidden').val());
        $('#PhonePrices_iTalProportion').val($('#PhonePrices_iTalProportionHidden').val());
        $('#PhonePrices_iAlternaProportion').val($('#PhonePrices_iAlternaProportionHidden').val());
        $('#PhonePrices_iSiminnProportion').val($('#PhonePrices_iSiminnProportionHidden').val());
        $('#PhonePrices_iSiminnProportionReal').val($('#PhonePrices_iSiminnProportionHidden').val());
    });

    $('#PhonePrices_iVodafoneProportion').keypress(function(e) { if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { return false; } });
    $('#PhonePrices_iNovaProportion').keypress(function(e) { if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { return false; } });
    $('#PhonePrices_iTalProportion').keypress(function(e) { if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { return false; } });
    $('#PhonePrices_iAlternaProportion').keypress(function(e) { if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { return false; } });

    $('.PhoneProportion').keyup(function(e) {
        if (e.keyCode == '9' || e.keyCode == '16') { return false; }
        if (parseFloat($(this).val()) > 100) { $(this).val('100'); }
        CalculateProsent(this);
    });

    var disabledClick = function() {
        /* Skilmálar pop up*/
        $('#popupDisclaimerApproved').attr('checked', false);
        $('#popupDisclaimerApproved').click(EnableCalc);

        var pos = $('a.terms').offset();
        $('#acceptTerms').dialog('option', 'position', [Math.ceil(pos.left - 120), Math.ceil(pos.top - $('html').scrollTop() - 160)]);
        $('#acceptTerms').dialog('open');

        return false;
    }
    var enabledClick = function() { return true; }

    var EnableCalc = function() {
        $('#PhonePrices_Calculate').removeClass('disabled');
        $('#PhonePrices_Calculate').unbind('click');
        $('#PhonePrices_Calculate').click(enabledClick);
        $('#PhonePrices_Calculate').removeAttr('disabled');
        $('#acceptTerms').dialog('close');
        $('#PhonePrices_DisclaimerApproved').attr('checked', true);
    }

    var DisableCalc = function() {
        $('#PhonePrices_Calculate').addClass('disabled');
        $('#PhonePrices_Calculate').unbind('click');
        $('#PhonePrices_Calculate').click(disabledClick);
    }

    $('#PopUp_PhonePrices_DisclaimerApproved').click(function() {
        TermsTrueFalse();
    });

    var EnableOrDisableCalc = function() { $('#PhonePrices_DisclaimerApproved').attr('checked') ? EnableCalc() : DisableCalc(); };

    $('#PhonePrices_DisclaimerApproved').click(function() {
        EnableOrDisableCalc();
    });

    //Festa við default hegðun
    //EnableOrDisableCalc();
    /* Tekið út 16.6.2010 */

    if ($('#PhonePrices_DisclaimerApproved').attr('checked')) {
        $('#PhonePrices_Calculate').removeAttr('disabled');
    }

    /*if (location.hash != '') {
    window.setTimeout("location.href = location.href", 1000); // delay vegna animationa
    }*/
    $(".choiceholder .servicecategory input").each(function() {
        $(this).click(function() { changeServiceValues(true); });
    });

    //post-postBack stealth check
    if ($('#PhonePrices_SCInternet').attr('checked') || $('#PhonePrices_SC3GNet').attr('checked') || $('#PhonePrices_SC3GNetISimann').attr('checked')) {
        $("p.sliderbuff").hide(300);
        $("#PhonePrices_WrapInner").hide(300);
    }

    setChecked();

    //$('#fonts a.smalltext').click(function() { $.fontSize(-1); return false; });
    //$('#fonts a.largetext').click(function() { $.fontSize(); return false; });

    // Reset Font Size
    //    var originalFontSize = $('html').css('font-size');
    //    $(".resetFont").click(function() {
    //        $('html').css('font-size', originalFontSize);
    //    });
    // Increase Font Size
    var iFontSize = 0;
    $("#fonts a.largetext").click(function() {
        if (iFontSize < 2) {
            var currentFontSize = $('html').css('font-size');
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 1.2;
            $('html').css('font-size', newFontSize);
            iFontSize = iFontSize + 1;
            return false;
        }
        else { return false; }
    });
    // Decrease Font Size
    $("#fonts a.smalltext").click(function() {
        if (iFontSize > 0) {
            var currentFontSize = $('html').css('font-size');
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum / 1.2;
            $('html').css('font-size', newFontSize);
            iFontSize = iFontSize - 1;
            return false;
        }
        else { return false; }
    });

    $("#slider .left, #slider .right").click(function() { $("#PhonePrices_sliderval").val($("#slider .main").slider('option', 'value')); });

    //changeServiceValues(true);
    //redrawSliderPop();
});

function redrawSliderPop() {

    var sliderpopoffset = 140;
    var bottomPadding = 60;
    var background = "";
    if (typeof (svDefVal) !== "undefined") {
        switch (curcat) {
            case 0:
                sliderpopoffset = 124;
                bottomPadding = 60;
                background = "url(/images/sliderpop_gsm_back.png) no-repeat scroll 0 0 transparent";
                $('#sliderpop').html('<table><tr><td>' + (Math.round(svDefVal.Mobile[lastidx].CallsToHome) + Math.round(svDefVal.Mobile[lastidx].CallsToMobile)) + '</td><td>Símtöl</td>'
                                   + '<tr><td>' + (Math.round(svDefVal.Mobile[lastidx].MinutesToHome) + Math.round(svDefVal.Mobile[lastidx].MinutesToMobile)) + '</td><td>M&iacute;n</td><tr>'
                                   + '<td>' + svDefVal.Mobile[lastidx].SMS + '</td><td>SMS</td></tr><tr><td>' + svDefVal.Mobile[lastidx].MMS + '</td><td>MMS</td></tr></table>');
                break;
            case 1:
                sliderpopoffset = 88;
                bottomPadding = 53;
                background = "url(/images/sliderpop_home_back.png) no-repeat scroll 0 0 transparent";
                $('#sliderpop').html('<table><tr><td>' + Math.round(svDefVal.Home[lastidx].CallsToHome + svDefVal.Home[lastidx].CallsToMobile) + '</td><td>Símtöl</td>'
                               + '<tr><td>' + Math.round(svDefVal.Home[lastidx].MinutesToHome + svDefVal.Home[lastidx].MinutesToMobile) + '</td><td>M&iacute;n</td><tr></table> ');
                break;
            case 2:
                sliderpopoffset = 68;
                bottomPadding = 40;
                background =  "url(/images/sliderpop_net_back.png) no-repeat scroll 0 0 transparent";
                $('#sliderpop').html('<table><tr><td>Allt a&eth; ' + Math.round(svDefVal.Internet[lastidx].Data) + ' GB</td></tr></table>');
                break;
            case 3:
                sliderpopoffset = 68;
                bottomPadding = 40;
                background = "url(/images/sliderpop_net_back.png) no-repeat scroll 0 0 transparent";
                $('#sliderpop').html('<table><tr><td>Allt a&eth; ' + Math.round(svDefVal['3GNet'][lastidx].Data) + ' GB</td></tr></table>');
                break;
            case 4:
                sliderpopoffset = 68;
                bottomPadding = 40;
                background = "url(/images/sliderpop_net_back.png) no-repeat scroll 0 0 transparent";
                $('#sliderpop').html('<table><tr><td>Allt a&eth; ' + Math.round(svDefVal['3GNetISimann'][lastidx].Data) + ' MB</td></tr></table>');
                break;
            default: break;
        }

        $("#sliderpop").css({ "top": "-" + sliderpopoffset + "px", "padding-bottom": bottomPadding + "px", "background" : background });
    }
}

function CheckPrice() {
    var sum = 0;
    sum += parseFloat((($('#PhonePrices_iVodafoneProportion').val() == '') ? '0' : $('#PhonePrices_iVodafoneProportion').val()));
    sum += parseFloat((($('#PhonePrices_iNovaProportion').val() == '') ? '0' : $('#PhonePrices_iNovaProportion').val()));
    sum += parseFloat((($('#PhonePrices_iTalProportion').val() == '') ? '0' : $('#PhonePrices_iTalProportion').val()));
    sum += parseFloat((($('#PhonePrices_iAlternaProportion').val() == '') ? '0' : $('#PhonePrices_iAlternaProportion').val()));
    sum += parseFloat((($('#PhonePrices_iSiminnProportion').val() == '') ? '0' : $('#PhonePrices_iSiminnProportion').val()));
    if (sum <= 100) {
        return true;
    }
    else {
        alert("Ekki er hægt að reikna því prósenta \"Hringt er í viðtakendur hjá\" er meiri en 100%");
        return false;
    }
}

function CalculateProsent(el) {
    var sum = 0;
    sum += parseFloat((($('#PhonePrices_iVodafoneProportion').val() == '') ? '0' : $('#PhonePrices_iVodafoneProportion').val()));
    sum += parseFloat((($('#PhonePrices_iNovaProportion').val() == '') ? '0' : $('#PhonePrices_iNovaProportion').val()));
    sum += parseFloat((($('#PhonePrices_iTalProportion').val() == '') ? '0' : $('#PhonePrices_iTalProportion').val()));
    sum += parseFloat((($('#PhonePrices_iAlternaProportion').val() == '') ? '0' : $('#PhonePrices_iAlternaProportion').val()));

    if (sum > 100) {
        $(el).addClass('red');
        $('#PhonePrices_iSiminnProportion').val('0');
        $('#PhonePrices_iSiminnProportionReal').val('0');
    }
    else {
        $("#PhonePrices_Proportion table tbody tr td > input").removeClass('red');
        $('#PhonePrices_iSiminnProportion').val(100 - sum);
        $('#PhonePrices_iSiminnProportionReal').val(100 - sum);
    }
}

function toggleResults() {
    $('.hiddenresult').toggleClass('stream');

    if ($('.hiddenresult').attr('class').indexOf('stream') > -1) {
        $('.results').attr('value', 'Fleiri niðurstöður');
    }
    else {
        $('.results').attr('value', 'Færri niðurstöður');
    }
}

function changeServiceValues(enable) {
    //if (enable) {
    //    $('#PhonePrices_Calculate').removeClass('calcbutton_disabled');
    //}
    //else {
    if(!enable)
    {
        $(function() {
            $('#slider .main').slider('option', 'value', $('#PhonePrices_sliderval').val());
        });
    }

    var intervals = 100, catidx = 1;
    $('#PhonePrices_MyChoice').val('false');

    /* Farsími er valinn */
    if ($('#PhonePrices_SCMobile').attr('checked')) {
        if ($("p.sliderbuff").css("display") != "block")
            $("p.sliderbuff").show(300);
        if ($("#PhonePrices_WrapInner").hasClass("open") && $("#PhonePrices_WrapInner").css("display") == "none")
            $("#PhonePrices_WrapInner").show(300);
        catidx = Math.max(Math.ceil(svDefVal.Interval.Mobile * $('#slider .main').slider('option', 'value') / 100), 1);

        if (curcat != 0) {
            $('.personalchoice').show();
            $('.verticalholder label').removeClass('thin');
            $('.proportionholder').show();
            $('.internetinfo').add('.netshow').hide();
            $('.internetinfo').add('.gshow').hide();
            $('#sliderpop').removeClass('SCNet').removeClass('SCHome');
            $('#choiceheader').html('Fj&ouml;ldi');
            $('#detailheader1').html('Fj&ouml;ldi s&iacute;mtala');
            $('#detailheader2').html('Fj&ouml;ldi m&iacute;n&uacute;tna');
            $('.phonerow').show();
            $('.mobilerow').show();
            $('.internetrow').hide();
            $('.buttonholder .smalltext').hide();
        }

        if (catidx != lastidx || curcat != 0) {
            if (typeof (svDefVal) !== 'undefined') {
                $('#PhonePrices_iNrCallsToHome').attr('value', Math.round(svDefVal.Mobile[catidx].CallsToHome));
                $('#PhonePrices_iLengthCallsToHome').attr('value', Math.round(svDefVal.Mobile[catidx].MinutesToHome));
                $('#PhonePrices_iNrCallsToMobile').attr('value', Math.round(svDefVal.Mobile[catidx].CallsToMobile));
                $('#PhonePrices_iLengthCallsToMobile').attr('value', Math.round(svDefVal.Mobile[catidx].MinutesToMobile));
                $('#PhonePrices_iNrSMS').attr('value', svDefVal.Mobile[catidx].SMS);
                $('#PhonePrices_iNrMMS').attr('value', svDefVal.Mobile[catidx].MMS);
                lastidx = catidx;
                curcat = 0;
                redrawSliderPop();
            }
        }
    }

    /* Heimasími er valinn */
    else if ($('#PhonePrices_SCHome').attr('checked')) {

        catidx = Math.max(Math.ceil(svDefVal.Interval.Home * $('#slider .main').slider('option', 'value') / 100), 1);
        //sliderpopoffset = 104;
        if ($("p.sliderbuff").css("display") != "block")
            $("p.sliderbuff").show(300);
        if ($("#PhonePrices_WrapInner").hasClass("open") && $("#PhonePrices_WrapInner").css("display") == "none")
            $("#PhonePrices_WrapInner").parent().parent().find(".wrapinner").show(300);
        if (curcat != 1) {
            $('.personalchoice').show();
            $('.verticalholder label').removeClass('thin');
            $('.proportionholder').show();
            $('.internetinfo').add('.netshow').hide();
            $('.internetinfo').add('.gshow').hide();
            $('#sliderpop').removeClass('SCNet').addClass('SCHome');
            $('#choiceheader').html('Fj&ouml;ldi');
            $('#detailheader1').html('Fj&ouml;ldi s&iacute;mtala');
            $('#detailheader2').html('Fj&ouml;ldi m&iacute;n&uacute;tna');
            $('.phonerow').show();
            $('.mobilerow').hide();
            $('.internetrow').hide();
            $('.buttonholder .smalltext').hide();
        }
        if (catidx != lastidx || curcat != 1) {
            if (typeof (svDefVal) !== 'undefined') {
                $('#PhonePrices_iNrCallsToHome').val(Math.round(svDefVal.Home[catidx].CallsToHome));
                $('#PhonePrices_iLengthCallsToHome').attr('value', Math.round(svDefVal.Home[catidx].MinutesToHome));
                $('#PhonePrices_iNrCallsToMobile').attr('value', Math.round(svDefVal.Home[catidx].CallsToMobile));
                $('#PhonePrices_iLengthCallsToMobile').attr('value', Math.round(svDefVal.Home[catidx].MinutesToMobile));
                lastidx = catidx;
                curcat = 1;
                redrawSliderPop();
            }
        }
    }

    /* Nettenging er valin */
    else if ($('#PhonePrices_SCInternet').attr('checked')) {

        //þarf neðar
        catidx = Math.max(Math.ceil(svDefVal.Interval.Net * $('#slider .main').slider('option', 'value') / 100), 1);
        sliderpopoffset = 83;
        $("p.sliderbuff").hide(300);
        $("#PhonePrices_WrapInner").parent().parent().find(".wrapinner").hide(300);
        $('.internetinfo').add('.netshow').show();
        $('.internetinfo').add('.gshow').hide(); 
        if (curcat != 2 && curcat != 3 && curcat != 4) {
            //ef net var checked fyrir, þá er þetta óþarft.
            $('.personalchoice').hide();
            $('.verticalholder label').addClass('thin');
            $('.proportionholder').hide();          
            $('#sliderpop').removeClass('SCHome').addClass('SCNet');
            $('#choiceheader').html('Magn');
            $('#detailheader1').html('');
            $('#detailheader2').html('');
            $('.phonerow').hide();
            $('.mobilerow').hide();
            $('.internetrow').show();
        }
        if (catidx != lastidx || curcat != 2) {
            if (typeof (svDefVal) !== 'undefined') {
                $('#PhonePrices_iInternetData').attr('value', Math.round(svDefVal.Internet[catidx].Data));
                $('#PhonePrices_iInternetDataReal').attr('value', Math.round(svDefVal.Internet[catidx].Data));
                lastidx = catidx;
                curcat = 2;
                redrawSliderPop();
            }
        }
        //$('.buttonholder .smalltext').show();
    }

    /* 3G Netlyklar er valið */
    else if ($('#PhonePrices_SC3GNet').attr('checked')) {

        //þarf neðar
        catidx = Math.max(Math.ceil(svDefVal.Interval['3GNet'] * $('#slider .main').slider('option', 'value') / 100), 1);
        sliderpopoffset = 83;
        $("p.sliderbuff").hide(300);
        $("#PhonePrices_WrapInner").parent().parent().find(".wrapinner").hide(300);
        $('.internetinfo').add('.gshow').show();
        $('.internetinfo').add('.netshow').hide();
        if (curcat != 2 && curcat != 3 && curcat != 4) {
            //ef net var checked fyrir, þá er þetta óþarft.
            $('.personalchoice').hide();
            $('.verticalholder label').addClass('thin');
            $('.proportionholder').hide();                
            $('#sliderpop').removeClass('SCHome').addClass('SCNet');
            $('#choiceheader').html('Magn');
            $('#detailheader1').html('');
            $('#detailheader2').html('');
            $('.phonerow').hide();
            $('.mobilerow').hide();
            $('.internetrow').show();
        }
        if (catidx != lastidx || curcat != 3) {
            if (typeof (svDefVal) !== 'undefined') {
                $('#PhonePrices_iInternetData').attr('value', Math.round(svDefVal['3GNet'][catidx].Data));
                $('#PhonePrices_iInternetDataReal').attr('value', Math.round(svDefVal['3GNet'][catidx].Data));
                lastidx = catidx;
                curcat = 3;
                redrawSliderPop();
            }
        }
        //$('.buttonholder .smalltext').show();
    }

    /* 3G Netlyklar í Símann er valið */
    else if ($('#PhonePrices_SC3GNetISimann').attr('checked')) {

        //þarf neðar
        catidx = Math.max(Math.ceil(svDefVal.Interval.Net * $('#slider .main').slider('option', 'value') / 100), 1);
        sliderpopoffset = 83;
        $("p.sliderbuff").hide(300);
        $("#PhonePrices_WrapInner").parent().parent().find(".wrapinner").hide(300);
        $('.internetinfo').add('.gshow').show();
        $('.internetinfo').add('.netshow').hide();
        if (curcat != 2 && curcat != 3 && curcat != 4) {
            //ef net var checked fyrir, þá er þetta óþarft.
            $('.personalchoice').hide();
            $('.verticalholder label').addClass('thin');
            $('.proportionholder').hide();
            $('#sliderpop').removeClass('SCHome').addClass('SCNet');
            $('#choiceheader').html('Magn');
            $('#detailheader1').html('');
            $('#detailheader2').html('');
            $('.phonerow').hide();
            $('.mobilerow').hide();
            $('.internetrow').show();
        }
        if (catidx != lastidx || curcat != 4) {
            if (typeof (svDefVal) !== 'undefined') {
                $('#PhonePrices_iInternetData').attr('value', Math.round(svDefVal['3GNetISimann'][catidx].Data));
                $('#PhonePrices_iInternetDataReal').attr('value', Math.round(svDefVal['3GNetISimann'][catidx].Data));
                lastidx = catidx;
                curcat = 4;
                redrawSliderPop();
            }
        }
        //$('.buttonholder .smalltext').show();
    }
}

function setChecked() {

    if ($('#PhonePrices_SCMobile').attr('checked')) {
        curcat = 0;
    }
    else if ($('#PhonePrices_SCHome').attr('checked')) {
        curcat = 1;
    }
    else if ($('#PhonePrices_SCInternet').attr('checked')) {
        curcat = 2;
    }
    else if ($('#PhonePrices_SC3GNet').attr('checked')) {
        curcat = 3;
    }
    else if ($('#PhonePrices_SC3GNetISimann').attr('checked')) {
        curcat = 4;
    }
}

function moveSlider(direction) {
    setChecked();
    if (timeoutid) { clearTimeout(timeoutid); }
    var cat = null;
    switch (curcat) {
        case 0: cat = svDefVal.Mobile; break;
        case 1: cat = svDefVal.Home; break;
        case 2: cat = svDefVal.Internet; break;
        case 3: cat = svDefVal['3GNet']; break;
        case 4: cat = svDefVal['3GNetISimann']; break;
        default: break;
    }

    if (cat != null) {
        var inc = 0;
        var interval = Math.ceil(100 / (cat.length-2)); //percentage
        if (direction > 0 && lastidx < cat.length-1) {
            inc = interval;
        }
        else if (direction < 0 && lastidx > 0) {
            inc = -interval;
        }
        else {
            return;  
        }
        $('#slider .main').slider('option', 'value', Math.max(Math.min(Number($('#slider .main').slider('option', 'value')) + inc, 100), 0));
        changeServiceValues(true);
       
        $('#sliderpop').show();
        timeoutid = setTimeout("$('#sliderpop').hide();", 500);
        $('#PhonePrices_sliderval').val($('#slider .main').slider('option', 'value'));  
    }
}

function slideToEnd(end) {
    $('#slider .main').slider('option', 'value', end);
    changeServiceValues(true);
    $('#sliderpop').show();
    setTimeout("$('#sliderpop').hide();", 500);
}

function toggleInnerWrap(el) {
    $(el).parent().parent().find('.wrapinner').toggle(300, function() {
        if ($('#PhonePrices_WrapInner').css("display") == "block") {
            $('#PhonePrices_WrapInner').addClass("open");
        }
        else {
            $('#PhonePrices_WrapInner').removeClass('open');
        }
    });
}

function printPopup(elem) {
    var toPrint = document.getElementById(elem);
    var w = null;
    if (toPrint != null) {
        w = window.open("about:blank", "Prenta", "width=50,height=50");
        var sHtml = '<html><head><link rel="stylesheet" href="/css/print.css" type="text/css" media="print"/><title>Prentun</title>'
        + '<script type="text/javascript" src="/js/misc.js"></script></head><body>' + toPrint.innerHTML + '</body></html>';
        w.document.write(sHtml);
        w.document.close();
        if (/opera/.test(navigator.userAgent.toLowerCase())) {  //sér case fyrir e-ð annað en IE, ekki oft sem maður sér þetta
            w.window.onload = function() {
                w.window.focus();
                w.window.print();
                w.setTimeout(function() { w.close() }, 100);
                return;
            }
        }

        w.focus();
        w.print();
        w.setTimeout(function() { w.close(); }, 100);
    }
}

