﻿function openVariant2(param) {
    //     $('#variant').load(location.protocol + "//" + location.host + '/variantform.aspx?' + param, function() { $('#variant').dialog().open(); });
    //     var new_window = window.showModalDialog(location.protocol + "//" + location.host + '/variantform.aspx?'+param,'Varianter','menubar=no;statusbar=no;dialogWidth=1024px;dialogHeight=700px;resize=true;');
    var w = (screen.width - 1024 - 32) / 2;
    var h = (screen.height - 700 - 64) / 2
    window.new_window = window.open(location.protocol + "//" + location.host + '/variantform.aspx?' + param, 'Varianter', 'menubar=no,statusbar=no,Width=1024,Height=700,resizeable=true,location=no,scrollbars=yes,toolbar=no');
    window.new_window.moveTo(w, h);
    window.interval = setInterval(IsClosed, 1000); //sjekke en gang i sekundet om variantformen lukkes

}
function openVariant(param) {
    //     $('#variant').load(location.protocol + "//" + location.host + '/variantform.aspx?' + param, function() { $('#variant').dialog().open(); });
    //     var new_window = window.showModalDialog(location.protocol + "//" + location.host + '/variantform.aspx?'+param,'Varianter','menubar=no;statusbar=no;dialogWidth=1024px;dialogHeight=700px;resize=true;');
    var w = (screen.width - 1024 - 32) / 2;
    var h = (screen.height - 700 - 64) / 2
    window.new_window = window.open(location.protocol + "//" + location.host + '/variantvare/Edit?' + param, 'Varianter', 'menubar=no,statusbar=no,Width=1024,Height=700,resizeable=true,location=no,scrollbars=yes,toolbar=no');
     
    window.new_window.moveTo(w, h);
    window.interval = setInterval(IsClosed, 1000); //sjekke en gang i sekundet om variantformen lukkes

}

function IsClosed() {
    if (window.new_window.closed) {
        LoadUserInfo();
        clearInterval(window.interval);

    }
    return false;
}

//openProduct funker kun med en div med id=dialog
function openProduct(param) {
     $.ajax({ url: location.protocol + '//' + location.host + '/Product/Details/' + param
            , cache: false
            , success: function(html) {
                $('#dialog').html(html);
                $('#dialog').dialog({ modal: true
                                        , width: 750
                                        , height: 500
                                        , buttons: { "Lukk": function () { $(this).dialog('close'); },
                                                     "Skriv ut":function(){printSelection("#dialog");}
                                         }
                })
            }
    });
}
function openByggetVariant(param,param2) {
    $.ajax({ url: location.protocol + '//' + location.host + '/Variantvare/Details?itemcode=' + param +"&orgvarenummer="+param2
            , cache: false
            , success: function(html) {
                $('#dialog').html(html);
                $('#dialog').dialog({ modal: true
                                        , width: 750
                                        , height: 500
                                        , buttons: { "Lukk": function() { $(this).dialog('close') },
                                                   "Skriv ut": function () { printSelection("#dialog"); }
                                        }
                })
            }
    });
}
function openVariant3(param) {
    $.ajax({ url: location.protocol + '//' + location.host + '/Variantvare/Edit?' + param 
            , cache: false
            , success: function(html) {
                $('#variantdialog').html(html);
                $('#variantdialog').dialog('open');
                }
    });
}
function printSelection(node) {

    var content = $(node).html();
    var w = $(node).width();
    var h = $(node).height();
    var pwin = window.open('', 'print_content', 'width=' + w + ',height=' + h);

    pwin.document.open();
    pwin.document.write('<html>' +
                        '<head>' +
                        '<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />' +
                        '<link href="../../Content/variant.css"  type="text/css" rel="Stylesheet"/>' +
                        '<link href="../../Content/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />' +
                        '</head>' +
                        '<body onload="window.print();window.close();">' + content + '</body></html>');
    pwin.document.close();

 //   setTimeout(function () { pwin.print();pwin.close(); }, 3000);

} 
function LoadUserInfo() {
    var id = document.getElementById('footer');
    if (id == null) {
        return;
       }
       $.ajax({
           url: '/Account/UserInfo'
        , cache: false
     , success: function(html) { $(id).html(html); $('.button').button(); }
       });
}
function LockConditions(param) {
    if (param == true) {
        $('#aktivmatrise').attr('disabled', 'disabled');
        $('#FreightPct').attr('disabled', 'disabled');
        $('#resetfreight').hide();
    }
    else {
        $('#aktivmatrise').removeAttr('disabled', '');
        $('#FreightPct').removeAttr('disabled', '');
        $('#resetfreight').show();


    }
}
//brukes i webgroupscontrol1 for å loade en browse
function resetproductlist() {
    $('#vare_browse').scrollable({ vertical: true, mousewheel: true, prev: '#vare_prev', next: '#vare_next' });
    $('#vare_prev').addClass('disabled');
    $('#vare_next').addClass('disabled');
}
function getQuery(what) {
    var params = document.location.search;
    if (params == null || params == '') {

        return null;
    }

    params = params.substr(1); //rest of string

    var paramlist = params.split("&");
    var i = 0;
    for (i = 0; i < paramlist.length; i++) {
        var s = paramlist[i].split("=");
        if (s[0].toLowerCase() == what.toLowerCase()) {
            return s[1];
        }
    }
    return null;

}


