﻿//params prepared in surrounding inc file:
//var jsviewstate 
//var jslocationcookiename 
//var jslancookiename

function gobasket() { goAndStoreLocation(basketurl)}

function goAndStoreLocation(url)
{
    setCookie(jslocationcookiename, escape(document.location.href), '', '/') //Mon, 01-Jan-2020 00:00:00 GMT
    document.location.href = url;
}

function goBackToStoredLocation() 
{
    var backcookie = getCookie(jslocationcookiename)
    if (backcookie != '') { document.location.href = unescape(backcookie) }
}

var refreshonfocus = 'N'
window.onfocus = function()  {if (refreshonfocus!='N') {dorefresh();} }
function dorefresh() {document.location.reload();refreshonfocus = 'N';}
 
function enlargeImage(id,w,h) {enlargeCommon('imageviewer.asp', id, w, h )}
function enlargeVideo(id,w,h) {enlargeCommon('videoviewer.asp', id, w, h )}

var largeimagewindow
function enlargeCommon(page, id, w, h )
{    
    largeimagewindow = window.open(page +'?id=' + id + '&w=' + w + '&h=' + h,'xxxx','titlebar=no,resizable=no,scrollbars=no,status=no,left=160,top=68,width=' + (w + 20) + ',height=' + (h + 40))
}

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();
}

