﻿function MaxLength(oTextArea, max)
{ 
    if (oTextArea.value.length>max)  
        oTextArea.value = oTextArea.value.substring(0,max); 
}

function GestisciRollOverBG(oCtr, shiftX, shiftY)
{
    shiftX = (shiftX == 0 ? "0" : "-" + shiftX + "px");
    shiftY = (shiftY == 0 ? "0" : "-" + shiftY + "px");
    //oCtr.parentNode.style.backgroundPosition = shiftX + " " + shiftY;
    oCtr.style.backgroundPosition = shiftX + " " + shiftY;
}

var oIFCorrente;
function MostraPopUpModale(idIf)
{
    var oForm = document.getElementsByTagName("FORM")[0];
    oForm.target = idIf;
    
    var oDivMod = document.getElementById("divModale");
    oDivMod.style.display = "block";
        
    var oIF = document.getElementById(idIf);    
    var oDivIF = oIF.parentNode;
    
    oDivIF.style.display = "block";     
    oIFCorrente = oIF;
    resizePopUp();
    
    window.onresize = function (){ resizePopUp(); }
}


function getHWin()
{
    var theHeight;        
    if (window.innerHeight) 
        theHeight = window.innerHeight;
    else 
        if (document.documentElement && document.documentElement.clientHeight) 
            theHeight = document.documentElement.clientHeight;
        else if (document.body) 
            theHeight = document.body.clientHeight;
    return theHeight;   
}

function resizePopUp()
{
    if(oIFCorrente)
    {
        var oDivPopUpCorrente = oIFCorrente.parentNode;
        
        var oDivMod = document.getElementById("divModale");
        var hContainer = document.getElementById("divContainer").offsetHeight;
        oDivMod.style.height = hContainer + "px"; 
        
        var hBodyScroll = document.getElementsByTagName("BODY")[0].scrollTop;
        var hHTMLScroll = document.getElementsByTagName("HTML")[0].scrollTop;
        
        var hScroll = Math.max(hBodyScroll, hHTMLScroll);
        var hWin = getHWin();
        var hExtra = Math.floor(hWin * 0.05);        
        var hTop = hScroll + hExtra;
        var hDiv = Math.floor(hWin * 0.90);
        
        if((hDiv + hTop + hExtra) >= hContainer)
            hTop = Math.floor((hContainer - hDiv) /2);
        
        oDivPopUpCorrente.style.top = hTop + "px"; 
        oDivPopUpCorrente.style.height = hDiv + "px";
        oIFCorrente.style.height = hDiv + "px";
    }
}



function chiudiPopUp(idIf, btnUniquId, action)
{
    oIFCorrente = null;
    var oForm = document.getElementsByTagName("FORM")[0];
    oForm.target = "_self";
    //oForm.action = "Contributo.aspx";
    oForm.action = action;
    
    var oDivMod = document.getElementById("divModale");
    oDivMod.style.display = "none";
    
    var oIF = document.getElementById(idIf);    
    var oDivIF = oIF.parentNode;
    
    oDivIF.style.display = "none"; 
    
    if(btnUniquId)
        __doPostBack(btnUniquId, "");
    
}

function chiudiPopUpRedirect(url)
{
    var oIF = document.getElementById(url);    
    top.location.href = url;
}



