function F_preloadImages() {
    var d = document;

    if (d.images) {

        if (!d.MM_p) d.MM_p = new Array();

        var i,j = d.MM_p.length,a = F_preloadImages.arguments;

        for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function getImageWidth(myImage) {
    var x, obj;
    if (document.layers) {
        var img = getImage(myImage);
        return img.width;
    } else {
        return getElementWidth(myImage);
    }
}

function getImageHeight(myImage) {
    var y, obj;
    if (document.layers) {
        var img = getImage(myImage);
        return img.height;
    } else {
        return getElementHeight(myImage);
    }
}

function resize(img, maxW, maxH) {
    var rapporto;
    if (img == undefined || img == null) return false;
    if (maxH == undefined) maxH = 100;
    if (maxW == undefined) maxW = 100;


    if ((img.width > maxW) && ((img.height > maxH))) {
        rapporto = img.width / img.height;


        if (img.width > img.height) {
            img.width = maxW;
            img.height = (img.width / rapporto);
        }
        else
            if (img.height > img.width) {
                img.height = maxH;
                img.width = (img.height * rapporto);
            }
            else {
                img.height = maxH;
                img.width = maxW;
            }
    }

    if (img.width > maxW) {
        rapporto = img.width / img.height;

        img.width = maxW;
        img.height = (img.width / rapporto);
    }
    else
        if (img.height > maxH) {
            rapporto = img.width / img.height;
            img.height = maxH;
            img.width = (img.height * rapporto);

        }

    img.style.visibility = 'visible';
    return true;
}

function textLimit(field, maxlen) {
    if (field.value.length > maxlen)
        field.value = field.value.substring(0, maxlen);
}






function disableButton() {
  
    var testo = "Grazie! La richiesta è stata inviata.";
    document.getElementById("upload").innerHTML = testo;


}


//hide selects on page - copy code below

function hideCombo(action, overDiv) {
    //possible values for action are 'hidden' and 'visible'
    
    elmID = 'SELECT';
    if (action!='visible'){action='hidden';}

    if ((navigator.appName.indexOf("Microsoft")>=0) && ((navigator.appVersion.indexOf("MSIE 6")>=0) ||(navigator.appVersion.indexOf("MSIE 5")>=0)) )
    {
        for( i = 0; i < document.all.tags( elmID ).length; i++ )
        {
          obj = document.all.tags( elmID )[i];
          if( !obj || !obj.offsetParent )
          {
            continue;
          }

          // Find the element's offsetTop and offsetLeft relative to the BODY tag.
          objLeft   = obj.offsetLeft;
          objTop    = obj.offsetTop;
          objParent = obj.offsetParent;

          while( objParent.tagName.toUpperCase() != "BODY" )
          {
            objLeft  += objParent.offsetLeft;
            objTop   += objParent.offsetTop;
            objParent = objParent.offsetParent;
          }

          objHeight = obj.offsetHeight;
          objWidth = obj.offsetWidth;

          if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
          else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
          else if( overDiv.offsetTop >= ( objTop + objHeight ));
          else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
          else
          {
            obj.style.visibility = action;
          }
        }

     }
}



// --------------------------------------------------------------
// Funzione per l'apertura di una finestra Popup per le immagini
// --------------------------------------------------------------
function openImage ( filename, titolo ) {

    image = new Image();
    image.src = filename;

    F_preloadImages(filename);

    larghezza = image.width;
    altezza = image.height;

    if (larghezza == 0) {
        larghezza = 850;
    }  else {
        larghezza = image.width + 50;
    }

    if (altezza == 0) {
        altezza = 670;
    }  else {
        altezza = image.height + 70;
    }

    mywindow=window.open("", "", "alwaysRaised, width=" + larghezza + ", height="+ altezza + ", status=no, scrollbars=yes, resizable=yes");
	mywindow.document.write("<HTML><HEAD>");
	mywindow.document.write("<TITLE>" + titolo + "</TITLE>");
	mywindow.document.write("<link rel='stylesheet' href='./stili/style.css'  type='text/css'>");
	mywindow.document.write("</HEAD><BODY>");
	mywindow.document.write("<div align=\"center\"><img src='" + filename + "'></div>");
	mywindow.document.write("<BR><BR><div align=\"center\"><a href='javascript:this.close()' class='LINK'> Chiudi </a></div>");
	mywindow.document.write("</BODY></HTML>");
}


/*
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder)
{
        if (window.event&&event.srcElement.value.length>=maxlength)
            return false
        else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength)
            {
                var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
                if (pressedkey.test(String.fromCharCode(e.which)))
                    e.stopPropagation()
            }
}

function countlimit(maxlength,e,placeholder)
{
    var theform=eval(placeholder)
    var lengthleft=maxlength-theform.value.length
    var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)

    if (window.event||e.target&&e.target==eval(placeholder))
    {
        if (lengthleft<0)
            theform.value=theform.value.substring(0,maxlength)

        placeholderobj.innerHTML=lengthleft
    }
}

function displaylimit(thename, theid, thelimit)
{
    var theform=theid!=""? document.getElementById(theid) : thename var limit_text='<strong>Puoi inserire ancora <span id="'+theform.toString()+'">'+thelimit+'</span>caratteri</strong>'

    if (document.all||ns6)
        document.write(limit_text)

        if (document.all)
        {
            eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
            eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
        }
    else if (ns6)
        {
            document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
            document.body.addEventListener('keyup'   , function(event) { countlimit(thelimit,event,theform) }   , true);
        }
}*/
//end code
