function preload() {
				 var args = preload.arguments;
				 document.imageArray = new Array(args.length);
				 for(var i=0; i<args.length; i++) {
				 				 document.imageArray[i] = new Image;
								 document.imageArray[i].src = args[i];
				 }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //customized by N.Boccardi
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) {
	 nm=val.name;
       //my adding
	 if (test.charAt(0) == 'M'){
	   if (val.selectedIndex < 1) errors+='- la prima opzione del campo '+nm+' non è valida.\n';
	 }
	 if (test.charAt(0) == 'C'){
	   if (!val.checked) errors+='- Il campo '+nm+' va spuntato.\n';
	 }
       //end
	 if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) {
	    p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- il campo '+nm+' deve contenere un indirizzo e-mail valido.\n';
      } 
  else if ((test!='R') && (test!='M') && (test!='C')){//another adding
        if (isNaN(val)) errors+='- il campo '+nm+' deve contenere un numero.\n';
        if (test.indexOf('inRange') != -1) {
		  p=test.indexOf(':');
          min=test.substring(8,p);
		  max=test.substring(p+1);
          if (val<min || max<val) errors+='- il campo '+nm+' deve contenere un numero fra '+min+' e '+max+'.\n';
        }
	  }
	 }
	 else if (test.charAt(0) == 'R') errors += '- il campo '+nm+' e\' necessario.\n';
    }

  }
   
  if (errors) alert('Si sono verificati i seguenti errori:\n'+errors);
  document.MM_returnValue = (errors == '');
  
}

function checkDisplayMenu(obj) {
	document.getElementById(obj).style.display = document.getElementById(obj).style.display == "none" ? "block" : "none";	
}

var altContenuto;

function tmpContenuto() {
   altContenuto = document.getElementById('contenuti').offsetHeight;
}

function aggiustaHeight() {
  var dmenu,div,div1;
  dmenu = document.getElementById('coldestra');
  div = document.getElementById('corpo2');
  div1 = document.getElementById('contenuti');
										
  if(dmenu.offsetHeight){
	 altColDx = dmenu.offsetHeight;
     if (altColDx > div.offsetHeight) {
        div.style.height = altColDx + "px";
	    div1.style.height = altColDx + "px"; 
	 } else if (altColDx < altContenuto) {
	    div.style.height = altContenuto + "px";
		div1.style.height = altContenuto + "px";
	 }
  }
  /*else if(dmenu.style.pixelHeight){
     div.style.height = dmenu.style.pixelHeight;
  }*/
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var popUpWin = 0;
function p_win(name,larg,alt){
	var args = arguments;
	if (args.length < 3) {
		larg = 800;
		alt = 600;
	}
	x = (screen.width/2)-(larg/2);
	y = (screen.height/2)-(alt/2);
	popUpWin=window.open(name,"popUpWin","width=" + larg + ", height=" + alt + ", left="+x+", top="+y+", scrollbars=yes");
}


function chiudi_pop() {
	if(popUpWin){
    	if(!popUpWin.closed) popUpWin.close();
  	}
}


//apre una finestra pop-up e crea un documento html
//code by Nicola Boccardi © 2003 Walkstudio
function crea_pop(titolo, base, testo){
    var titoloPop = "foto";
    var descrizione = "";
    //var base = "";
	base.replace(/\\/g, "/");
	if (base.charAt(base.length-1) != "/") base += "/";
	var larg = 150;
	var alt = 100;
	var x_pop = 0;
	var y_pop = 0;
	if (testo!=null) {
	    descrizione = testo;
	}
    pop_creata = window.open("",titoloPop,"toolbar=no,resizable=yes,location=no,menubar=no,scrollbars=yes,width="+larg+",height="+alt+",top=" + y_pop + ",left=" + x_pop);
	
	//formattazione pagina html
	codice = "<html>\n";
	codice += "<head>\n<title>"+descrizione+"</title>\n";
	codice += "</head>\n";
	codice += "<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>\n";
	codice += "<img src='"+base+titolo+"' alt='"+descrizione+"' border=0 id='foto' name='foto'>\n";
        codice += "</body>\n";
        codice += "<script language='Javascript' type='text/JavaScript'>\n";
	codice += "function ridimensiona(){\n";
    codice += "if(document.foto.complete){\n";
	codice += "if(document.foto.width<screen.width){\n";
    codice += "larg=(document.foto.width)+30;\n";
	codice += "}else {\n";
	codice += "larg=screen.width-15;\n";
	codice += "}\n";
	codice += "if(document.foto.height<screen.height){\n";
    codice += "alt=(document.foto.height)+50;\n";
	codice += "}else {\n";
	codice += "alt=screen.height-50;\n";
	codice += "}\n";
    codice += "window.resizeTo(larg,alt);\n";
    codice += "}\nelse{\n";
    codice += "setTimeout('ridimensiona()',1000);\n}\n}\n";
    codice += "ridimensiona();\n</script>\n";
	
        codice += "</html>";
	
	pop_creata.document.write(codice);
	pop_creata.document.close();
	pop_creata.focus();
}


