﻿function RefreshPage(bHome)
{
    //questo js era per safari...ma safari 5.0 ha risolto il bug!
   /* var nav = navigator.appName; 
    if(nav == "Netscape")
    {
        
        var returnVal;
        if(bHome =="false")
        {
            qString = window.location.href.substr(0,window.location.href.length).split("&"); 
            var sUrl = window.location.href.substr(0,window.location.href.length).split("&")[0];
            
            if(qString[2]!=null)
            {           
                var index = qString[2].indexOf("="); 
                if (index >= 0)
                { 
                    var strCurrentParamName = escape(unescape(qString[2].substr(0, index))); 
                    if (strCurrentParamName == "fromSite")
                    { 
                        returnVal = (qString[2].substr(index + 1)); 
                        if(returnVal == "1" && sUrl!=null)
                        {
                            window.location.reload();
                            window.location.href=sUrl;
                        } 
                    }
                }
            }
        }
        else
        {
            qString = window.location.href.substr(0,window.location.href.length).split("?"); 
            var sUrl = window.location.href.substr(0,window.location.href.length).split("?")[0];
            
             if(qString[1]!=null)
            {           
                var index = qString[1].indexOf("="); 
                if (index >= 0)
                { 
                    var strCurrentParamName = escape(unescape(qString[1].substr(0, index))); 
                    if (strCurrentParamName == "fromSite")
                    { 
                        returnVal = (qString[1].substr(index + 1)); 
                        if(returnVal == "1" && sUrl!=null)
                        {
                            window.location.reload();
                            window.location.href=sUrl;
                        } 
                    }
                }
            }
        
        }
    }*/
}

/** 
* @returns A string which specifies which is the current 
* browser in which we are running. 
* 
* Currently-supported browser detection and codes: 
* * 'opera' -- Opera 
* * 'msie' -- Internet Explorer 
* * 'safari' -- Safari 
* * 'firefox' -- FireFox 
* * 'mozilla' -- Mozilla 
* 
* If we are unable to property identify the browser, we 
* return an empty string. 
* 
* @type String 
*/ 
function getBrowserName() { 
    var browserName = ""; 

    var ua = navigator.userAgent.toLowerCase(); 
    if ( ua.indexOf( "opera" ) != -1 ) 
        browserName = "opera"; 
    else if ( ua.indexOf( "msie" ) != -1 ) 
        browserName = "msie"; 
    else if ( ua.indexOf( "safari" ) != -1 )
        browserName = "safari"; 
    else if ( ua.indexOf( "mozilla" ) != -1 ){
        if ( ua.indexOf( "firefox" ) != -1 )
            browserName = "firefox"; 
        else 
            browserName = "mozilla";} 

    return browserName; 
}


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";
}



/********************FOR PHOTO SLIDER*********************************/


   function change(hiddenInput,name,btn)
   {   
        if(typeof(hiddenInput) == "object")
            FindDiv(hiddenInput.id,name,btn.id); 
        else
            FindDiv(hiddenInput,name,btn);
        
        // per la gestione del back con il timer per lo slider immagini
        OnClickSetBack();
   }       
     
//   function changeDis(name)
//   {
//         if(typeof(hiddenInput) == "object")
//        FindDiv(hiddenInput.id,name,btn.id); 
//    else
//        FindDiv(hiddenInput,name,btn); 
//   }
//    
//    function changeDisVuoto(name)
//    {
//        if(typeof(hiddenInput) == "object")
//        FindDiv(hiddenInput.id,name,btn.id); 
//    else
//        FindDiv(hiddenInput,name,btn); 
//    }
     
    function FindDiv(hiddenInput,name, btn)
    {    
    
        $("div .li_over").each(function()
        {
            $(this).removeClass("li_over");
            $(this).addClass("li");
        });        
        $("div .li").each(function() {
            if($(this)[0].attributes["name"].value == name)
            {
                $("#"+hiddenInput).val(name);
                $(this).removeClass("li");
                $(this).addClass("li_over");
            }
        });
        var button = $("#"+btn)[0]
        if (button)
        {
            __doPostBack(button.name,"");
        }
        
    }
    

               
                


          

/*********************************************************************/

