var layerOuterDiv="layerOuterDiv";
var layerRootEl="layerRootEl";

function closePopup() {
    document.getElementById(layerOuterDiv).style.display="none";
}

/*
Requires that PopupLayerCtrl is added to the page.
*/
function showPopup(htmlFragment) {
    document.getElementById(layerRootEl).innerHTML=htmlFragment;
    document.getElementById(layerOuterDiv).style.display="block";
    
}

function openPopupWindow(url, title) {
    var options='toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=yes,dependent=yes,width=700,height=600';
    window.open(url, title, options);
}

function showZoomUtil(url,urlPrefix, minimumWidth) {
        if (urlPrefix) url = urlPrefix+url;
        if (minimumWidth) url = url+"&width="+minimumWidth;
        HTTP.getText(url, showPopup );

}

function showProductLineZoom(pdLineId, urlPrefix, minimumWidth) {
        showZoomUtil("ZoomView.aspx?productLineId="+pdLineId, urlPrefix, minimumWidth);
}

function showProductZoom(pdId, urlPrefix, minimumWidth) {
        showZoomUtil("ZoomView.aspx?productId="+pdId, urlPrefix, minimumWidth);
}

function showVariantZoom(variantId, urlPrefix, minimumWidth) {

        showZoomUtil("ZoomView.aspx?variantId="+variantId, urlPrefix, minimumWidth);
}

var currentTdEl;
function setZoomImg(url,tdEl) {
    if (currentTdEl!=null) currentTdEl.style.border="1px solid #B2CCCB";
    tdEl.style.border="1px solid black";
    currentTdEl=tdEl;
    document.getElementById("zoomImg").src=url;
}

function popupWindow(href) {
    var refWin=window.open(href,"_blank","toolbar=no,titlebar=no,menubar=no,dependent=yes,alwaysRaised=yes,left=50,top=50,width=800,height=800");
    //var newEl=refWin.document.createElement("div");
    //newEl.innerHTML="<a href='javascript:closeWindowUtil()'>[Luk vindue]</a>";
}

function closeWindowUtil() {
    window.opener='';
    window.close();
}

function notifyOpenerAndClose(clientSideCallBack) {
    if (clientSideCallBack!=null) {
        if (window.opener!=null) {
            if (window.opener[clientSideCallBack]!=null) {
                //We expect it to be a method, call it now.
                window.opener[clientSideCallBack]();
            }
        }
    }
    closeWindowUtil();
}