﻿function openProductDetailWindow(productId)
{
    productRefresh(productId);
    
    showPopupMask();
    setTimeout(finishDetailLoad, 10);
}

function finishDetailLoad()
{    
    showDetailsWindow();   
}

function getDetailDiv()
{
    return document.getElementById('productDetails');
}

function hideDetailWindow()
{
    var detailDiv = getDetailDiv();
    
    if (detailDiv != null)
    {
        detailDiv.style.display = 'none';
        hidePopupMask();
    }
}

function showDetailsWindowSimple() {
    var detailDiv = getDetailDiv();

    if (detailDiv != null) {
        detailDiv.style.position = 'relative';
        detailDiv.style.display = 'block'; 
    }
}

function showDetailsWindow()
{
    var detailDiv = getDetailDiv();
    
    if (detailDiv != null)
    {
        var viewportHeight = getViewportHeight();
    
        var xPos = ((getViewportWidth() / 2) - (stripPXFromString(detailDiv.style.width) / 2));
        var yPos = ((viewportHeight / 2) - ((stripPXFromString(detailDiv.style.height) / 2)) - 65);
        
        var scrollTop = f_scrollTop();
        
        if (scrollTop != 0)
        {
            yPos += scrollTop; //((viewportHeight - scrollTop) - 100);
        }
        
        detailDiv.style.left = xPos + 'px';
        detailDiv.style.top = yPos + 'px';
        detailDiv.style.display = 'block';       
    }
}

function stripPXFromString(originalString) {
    return originalString.replace(/px/i, "");
}