﻿//params prepared in surrounding inc file:
//var jsviewstate 
//var jslocationcookiename
//var jslancookiename


function gobasket() {
    var url = '/basket.aspx?' + parseInt(Math.random() * 1000)
    if  (navigator.userAgent.indexOf('MSIE') == -1) {
        document.location.href = url;  // sends referrer in FF, not in IE
    }
    else {
        //i IE sættes request.referer IKKE ved document.location.href  - > i stedet .click
        var fakeLink = document.createElement("a");
        fakeLink.href = url;
        document.body.appendChild(fakeLink);
        fakeLink.click();   // click() method defined in IE only
    }
}

var refreshonfocus = 'N'
window.onfocus = function()  {if (refreshonfocus!='N') {dorefresh();} }
function dorefresh() {document.location.reload();refreshonfocus = 'N';}

function makeMailLink (p1, p2, p3)
{
    var url = 'ma'
    url += 'il'
    url += 'to:'
    url += p1 + '@'
    url += p2 + '.'
    url += p3
    document.location.href= url
}

function setcookielan(val)
{
    var expires_date = new Date( new Date().getTime() + (365 * 60 * 60 * 24 * 1000) );
    setCookie (jslancookiename, val, expires_date.toGMTString(), '', '', '')
}

var stdpopwindow
function openstdpopup(url, w, h) {
    common_openstdpopup(url, w, h, 'status=yes,resizable=yes,scrollbars=yes')

}

function opensimplepopup(url, w, h) {
    common_openstdpopup(url, w, h, 'menubar=no,scrollbars=no,toolbar=no,status=no,resizable=no') //
}

function common_openstdpopup(url, w, h, params) {

    var winX = (document.all) ? window.screenLeft : window.screenX;
    var winY = (document.all) ? window.screenTop : window.screenY;
    var screenw = (window.screen) ? window.screen.width : 1024;
    var screenh = (window.screen) ? window.screen.height : 768;

    var winW = -1, winH = -1;

    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        winW = window.innerWidth;
        winH = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        winW = document.documentElement.clientWidth;
        winH = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        winW = document.body.clientWidth;
        winH = document.body.clientHeight;
    }

    var l = parseInt((winW / 2) - (w / 2) + winX);
    var t = parseInt((winH / 2) - (h / 2) + winY);

    if (w > screenw) { w = screenw - 60; l = 30; }
    if (t > screenh) { h = screenh - 60; t = 30; }

    if (l + w > screenw) { l = parseInt((screenw - w) / 2) }
    if (t + h > screenh) { l = parseInt((screenh - h) / 2) }

    //Window.focus hack for chrome: Close window first - else no focus
    //if (navigator.userAgent.indexOf('Chrome/') > 0) {
    if (stdpopwindow) {
        stdpopwindow.close();
        stdpopwindow = null;
    }
    //}
    stdpopwindow = window.open(url, 'xxzzxx', 'left=' + l + ',top=' + t + ',width=' + w + ',height=' + h + ',' + params) //
    stdpopwindow.focus();
}

