﻿function RefreshPage(url)
{
    var nav = navigator.appName; 
    
    if(nav == "Netscape")
    {
        window.location.reload();
        window.location.href=url;
     }
}

function getPageCoords(element)
{
    var coords = {x: 0, y: 0}; 
    while (element)
    { 
        coords.x += element.offsetLeft; 
        coords.y += element.offsetTop; 
        element = element.offsetParent; 
    } 
    return coords; 
} 

//mostra il pannello per impedire l'accesso all'area di ricerca nella pagina ArchivioProdoti
function displayMask(mask, bottomPanel)
{
    var nav = navigator.appName;
//    if(nav != "Netscape")
    {
        var x = document.getElementById(mask);
        var y = document.getElementById(bottomPanel);
        
        p = getPageCoords(y);
        
        x.style.top  = p.y + "px";
        x.style.left   = p.x + "px";
        
        x.style.height = y.offsetHeight + "px";
        x.style.width = y.offsetWidth + "px";
    }
}

var resizeTimer = null;
function displayMaskOnResize(mask, bottomPanel)
{
    var nav = navigator.appName;
    if(nav != "Netscape")
    {
       var x = document.getElementById(mask);
       var y = document.getElementById(bottomPanel);
       if (x && y)
       {
           if (resizeTimer)
              clearTimeout(resizeTimer);
           resizeTimer = setTimeout(displayMask(mask, bottomPanel), 500);
       }
    }
}

//non utilizzata al momento
function NoCancel()
{
    var iCode = window.event.keyCode;
    if (iCode == 8 || iCode == 46)
        return false;
}

function ResizeImageProdotto(objImage, maxWidth, maxHeight)
{
    iWidth = objImage.offsetWidth;
    iHeight = objImage.offsetHeight;
//    iMaxWidth = 120;
//    iMaxHeight = 100;

        iMaxWidth = maxWidth;
        iMaxHeight = maxHeight;
    
    if (iWidth > iMaxWidth)
    {
        iHeight =  Math.floor((iMaxWidth * iHeight) / iWidth);
        iWidth = iMaxWidth;
        if (iHeight > iMaxHeight)
        {
            iWidth = Math.floor((iMaxHeight * iWidth) / iHeight);
            iHeight = iMaxHeight;
        }
    }
    else if (iHeight > iMaxHeight)
    {
        iWidth = Math.floor((iMaxHeight * iWidth) / iHeight);
        iHeight = iMaxHeight;
        if (iWidth > iMaxWidth)
        {
            iHeight =  Math.floor((iMaxWidth * iHeight) / iWidth);
            iWidth = iMaxHeight;
        }
    }
    
    
    objImage.style.height = iHeight + "px";
    objImage.style.width = iWidth + "px";    
    objImage.style.paddingTop = Math.floor((maxHeight-iHeight)/2)+"px";
}
