﻿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;
}

function GestisciOverBordo(oCtr) {
    var cNormal = " BorderNormal";
    var cOver = " BorderOver";
    //alert(oCtr.className);
    //alert(oCtr.className.indexOf(cOver))
    if (oCtr.className.indexOf(cOver) == -1) 
    {   
        if (oCtr.className.indexOf(cNormal) >=0)
            oCtr.className = oCtr.className.replace(cNormal, cOver)
        else
            oCtr.className += cOver
    }
    else 
    {
        if (oCtr.className.indexOf(cOver) >= 0)
            oCtr.className = oCtr.className.replace(cOver, cNormal)
        else
            oCtr.className += cNormal;
    }
    //alert(oCtr.className);
}

function GetsisciMessaggi(id1, id2) 
{

    var oDiv1 = document.getElementById(id1);
    var oDiv2 = document.getElementById(id2);

    //avviso
    var count = 0;
    if (oDiv1 && oDiv1.style.display != "none") {

        var intervalId = setInterval(function() {
            count++;
            if (count == 1)
                return;
            if (oDiv1.style.color.toUpperCase() != "WHITE")
                oDiv1.style.color = "white";
            else
                oDiv1.style.color = "green";
            if (count >= 5) {
                clearInterval(intervalId);
                count = 0;
            }
        }
            , 300)
    }

    //errore
    count = 0;
    if (oDiv2 && oDiv2.style.display != "none") {

        var intervalId = setInterval(function() {
        count++;
        if (count == 1)
            return;
            if (oDiv2.style.color.toUpperCase() != "WHITE")
                oDiv2.style.color = "white";
            else
                oDiv2.style.color = "red";
            if (count >= 5) {
                clearInterval(intervalId);
                count = 0;
            }
        }
            , 300)
    }
    
}

function preLoadImmagini()
{   
    document.ImgPreload = new Array();
    if(document.images)
    {
        for(var i=0; i<arguments.length; i++)
        {
            document.ImgPreload[i] = new Image()
            document.ImgPreload[i].src = arguments[i];
        }
    }
}

function pulisciForm()
{
    var oCtr;
    var oNewCtr
    var oCtrParent
    for(var i=0; i < arguments.length; i++)
    {
        oCtr = document.getElementById(arguments[i]);
        if(oCtr)
        {
            switch (oCtr.tagName.toLowerCase())
            {
                case "input":
                    if(oCtr.type.toLowerCase() == "file")
                    {
                        oCtrParent = oCtr.parentNode;                        
                        oCtrParent.removeChild(oCtr);
                        oNewCtr = document.createElement("input");
                        oNewCtr.id = oCtr.id;
                        oNewCtr.name = oCtr.name;
                        oNewCtr.type = oCtr.type;   
                        oNewCtr.style.width = oCtr.style.width; 
                        oCtrParent.appendChild(oNewCtr);
                    }
                    else
                        oCtr.value = "";
                    break;
                case "textarea":
                    oCtr.value = ""
                    break;
                case "select":
                    oCtr.value = "-1";
                    break;
                default:
                    alert("Tipo di controllo non noto: " + oCtr.tagName.toLowerCase());
                    break;
            }       
        }
    }
}


function simulaClick(evt, target) 
 {
    var oOrigine = evt.srcElement || evt.target;
    
    if (evt.keyCode == 13 && !(oOrigine && oOrigine.tagName.toLowerCase() == "textarea"))
    {
        var defaultButton;
        defaultButton = document.getElementById(target);
        
        if (defaultButton && defaultButton.href) 
        {
            eval(defaultButton.href);
                                
            evt.cancelBubble = true;
            if (evt.stopPropagation) 
                evt.stopPropagation();
            return false;
        }
     }
    return true;
}


function MaxLength(oTextArea, max)
{ 
    if (oTextArea.value.length>max)  
        oTextArea.value = oTextArea.value.substring(0,max); 
}


function keepAlive(where)
{    
    oIframe = document.getElementById("ifKeepAlive");
    oIframe.src = where;    
    setTimeout(function(){ keepAlive(where) }, 5000);    
}


