function check_login(form){
	errors="";
	if (form.User.length<2 || form.User.value==form.User.defaultValue){
		errors="- Nome Utente mancante";
	}
	if (form.Pwd.value.length<2 || form.Pwd.value==form.Pwd.defaultValue){
		if (errors!=""){
			errors = errors + "\n";
		}
		errors=errors + "- Password mancante";
	}
	if(errors!=""){
		errors="Attenzione!	\nSono stati riscontrati i seguenti errori nella compilazione del modulo:\n\n" + errors + "\n\nRicorreggi igli errori prima di inviare il modulo.";
		alert(errors);
		return false;
	}  
}


function duplica_directory2(){
	//alert(document.getElementById('directory').length/2-1);
    var x=document.getElementById('myTable').insertRow(document.getElementById('myTable').rows.length);
    x.insertCell(0).innerHTML=document.getElementById('myTable').rows[0].cells[0].innerHTML;	
    var y=document.getElementById('myTable').insertRow(document.getElementById('myTable').rows.length);
    y.insertCell(0).innerHTML=document.getElementById('myTable').rows[1].cells[0].innerHTML;
	//x.insertCell(0).innerHTML="<select name=\"directory" + (document.getElementById('myTable').rows.length/2-1) + "\" id=\"directory" + (document.getElementById('myTable').rows.length/2-1) + "\" style=\"font-family:arial,verdana,serif; font-size:9pt; border-width:1px; border-style:groove; border-color:#7189AB; background-color:#ffffff; color:black;\"></select>";
	document.getElementById('myTable').rows[document.getElementById('myTable').rows.length-2].cells[0].align="right";
	document.getElementById('num_directory').value=parseInt(document.getElementById('num_directory').value)+1;
	/*i=0;
	dir=document.getElementById('directory');
	for (i==0;i<dir.length;i++){
	  var y=document.createElement('option');
      y.text=dir[i].text;
      var x=document.getElementById("directory" + (document.getElementById('myTable').rows.length/2-1));
      try {
        x.add(y,null); // standards compliant
      }
      catch(ex) {
        x.add(y); // IE only
      }
	}*/
	//alert(i);
}

function duplica_directory(){
    var x=document.getElementById('myTable').insertRow(document.getElementById('myTable').rows.length);
    var cella = x.insertCell(0);	
    var y=document.getElementById('myTable').insertRow(document.getElementById('myTable').rows.length);
    y.insertCell(0).innerHTML=document.getElementById('myTable').rows[1].cells[0].innerHTML;
	document.getElementById('myTable').rows[document.getElementById('myTable').rows.length-2].cells[0].align="right";	
	var pinco=document.createElement("select");
	
	/*var y=document.createElement('option');
    y.text='Kiwi'
    var x=document.getElementById("select");
    try {
      x.add(y,null); // standards compliant
    }
    catch(ex) {
      x.add(y); // IE only
    }*/
  
	pinco.name="directory" + document.getElementById('num_directory').value;
	pinco.id="directory" + document.getElementById('num_directory').value;
	var oOption = document.createElement("option");
	var t = document.createTextNode("Seleziona");
	//oOption.text="Seleziona";
	//oOption.value=0;
    oOption.setAttribute("value", 0);
    oOption.appendChild(t);
	pinco.appendChild(oOption);
	document.getElementById('num_directory').value=parseInt(document.getElementById('num_directory').value)+1;
	list=document.getElementById('directory');
	var optGrps = list.getElementsByTagName("OPTGROUP")
	for (var ii = 0; ii < optGrps.length; ii++) {
	  var oGroup = document.createElement("optgroup");
	  oGroup.label=optGrps[ii].label;	 
	  var option = optGrps[ii].getElementsByTagName("option")
	  //var option = xf.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "option");
	  //alert(optGrps[ii].getElementsByTagNameNS(document.all, "option").length);
	  for (var k = 0; k < option.length; k++) {
	    var oOption = document.createElement("option");
		//alert(option[k].text);
		var t = document.createTextNode(option[k].text);
        //oOption.setAttribute("text", );
        oOption.setAttribute("value", option[k].value);
		oOption.setAttribute("label", option[k].text);
        oOption.appendChild(t);
		try {
		  oGroup.appendChild(oOption,null); // standards compliant
		}
		catch(ex) {
		  oGroup.appendChild(oOption); // IE only
		}
	  }
	   pinco.appendChild(oGroup);
	  
	}
	cella.appendChild(pinco);
	document.getElementById(pinco.name).style.fontFamily="arial,verdana,serif";
	document.getElementById(pinco.name).style.fontSize="x-small";
	document.getElementById(pinco.name).style.borderWidth="1px";
	document.getElementById(pinco.name).style.borderStyle="groove";
	document.getElementById(pinco.name).style.borderWidth="1px";
	document.getElementById(pinco.name).style.borderColor="#7189AB";
	document.getElementById(pinco.name).style.backgroundColor="#ffffff";
	document.getElementById(pinco.name).style.color="black";
	
	/*i=0;
	dir=document.getElementById('directory');
	for (i==0;i<dir.length;i++){
	  var y=document.createElement('option');
      y.text=dir[i].text;
      var x=document.getElementById("directory" + (document.getElementById('myTable').rows.length/2-1));
      try {
        x.add(y,null); // standards compliant
      }
      catch(ex) {
        x.add(y); // IE only
      }
	}*/
	//alert(i);
}

function abilita_disabilita_date(check_box){
	if (check_box.checked==true){
		document.forms['modulo_documenti']['data_ref'][0].disabled=false;
		document.forms['modulo_documenti']['data_ref'][1].disabled=false;
		document.forms['modulo_documenti']['Periodo'].disabled=false;
		document.forms['modulo_documenti']['Mese'].disabled=false;
		document.forms['modulo_documenti']['anno'].disabled=false;		
	} else {		
		document.forms['modulo_documenti']['data_ref'][0].disabled=true;
		document.forms['modulo_documenti']['data_ref'][1].disabled=true;
		document.forms['modulo_documenti']['Periodo'].disabled=true;
		document.forms['modulo_documenti']['Mese'].disabled=true;
		document.forms['modulo_documenti']['anno'].disabled=true;		
	}
}

function abilita_disabilita_legislazione(check_box){
	if (check_box.checked==true){
		document.forms['modulo_documenti']['IDInfo_Legislazioni_Padre'].disabled=false;
		document.forms['modulo_documenti']['IDInfo_Legislazioni'].disabled=false;
	} else {		
		document.forms['modulo_documenti']['IDInfo_Legislazioni_Padre'].disabled=true;
		document.forms['modulo_documenti']['IDInfo_Legislazioni'].disabled=true;
	}
}

function check_search_advanced(form){
	
	    if (parseInt(form.num_directory.value)>1){
	      //alert("Ciclo directory" + i + " " + (parseInt(form.num_directory.value)-1));
		  nascosto="";
	      for (i=0;i<=parseInt(form.num_directory.value)-1;i++){
			  if (i==0){
				  valore="";
			  } else {
				  valore=i;
			  }
			  aaa=document.getElementById("directory" + valore)
			  if (i>0){
			    nascosto=nascosto + "-";
			  }
			  nascosto=nascosto + aaa.value;
		  }/*	
		  for (var aaa in form.directory){
			  alert(aaa);
		  }*/
		  document.getElementById("val_directory").value=nascosto;
		  //alert(document.getElementById("val_directory").value)
		}
	    parole="no";
		date="no";
		Directory="no";
		Legislazione="no";
		errors="";
		form.content_search_ESCAPE.value=escape(form.content_search.value);
		form.phrase_ESCAPE.value=escape(form.phrase.value);
		//form.content_search_at_least_ESCAPE.value=escape(form.content_search_at_least.value);
		//form.no_content_search_ESCAPE.value=escape(form.no_content_search.value);
		if (form.content_search.value.length>1 || form.phrase.value.length>1 || form.solo_titolo.value.length>1){
			parole="si";
		}
		if (form.Doc_Riferiti.checked==true){
			date="si";
		}
		
		//if(form.directory.value>0){
			for (i=1; i<=form.num_directory.value; i++){
				if (i==1 ){
					controllo="directory"
				} else {
					controllo="directory" + String(parseInt(i -1))
				}
				//alert(document.getElementById(controllo).value)
			    if (document.getElementById(controllo).value!=0){
					Directory="si";
					break;
				}
			}
			
		//}
		
		if (form.Legislation.checked==true){
			Legislazione="si";
		}
		if (date=="si"){
			if (form.data_ref[0].checked==true){
				//alert(form.Periodo.value);
				if (parseInt(form.Periodo.value)==0){
					errors="- Seleziona un periodo";
				}
			} else {
				if (form.anno.value.length<1){
					errors="- Seleziona un anno";
				}
			}
		}
		if (Legislazione=="si"){
			if (form.Legislation.checked==true){
				if (form.IDInfo_Legislazioni_Padre.value==-1){
					if (errors!=""){
						errors=errors + "\n";
					}
					errors= errors + "- Seleziona una tipologia di legislazione";
				}
			} 
		}
		if (parole=="no" && date=="no" && Directory=="no" && Legislazione=="no"){
			errors="Seleziona almeno un campo per la ricerca.";
		}
		
		if(errors!=""){
			errors="Attenzione!\n" + errors;
			alert(errors);
			return false;
		}
}

function check_search(form){
	
		errors="";
		if (form.content_search.value.length<1){
			errors="Inserisci una stringa di ricerca prima!";
		}
		if(errors!=""){
			errors="Attenzione!\n" + errors;
			alert(errors);
			return false;
		} else {
			try{
				if (form.dir_filter.checked==false){
					form.idcat.value=0;
					form.selected.value=0;
				}
			} catch(e) {
				form.idcat.value=0;
				form.selected.value=0;
			}
			form.content_search_escape.value=escape(form.content_search.value);
		}
}

function openFolderInTree(linkID) {
	var folderObj;
	folderObj = findObj(linkID);
	folderObj.forceOpeningOfAncestorFolders();
	if (!folderObj.isOpen){
		clickOnNodeObj(folderObj);
	} 
}

function valuta_e_spedisci(azione){
	switch (azione){
		case "insert":
			document.forms[0].action="gestione_utenti.asp?action=detail&iduser=0";
			document.forms[0].submit();
			break;
		case "modify":
			switch (document.forms[0].rec.value){
				case "0":
					alert("Nessun Utente Disponibile!");
					break;
				case "1":
					if (document.forms[0].iduser.checked==false){
						alert("Seleziona l'utente prima.");
					} else {
						document.forms[0].action="gestione_utenti.asp?action=detail";
						document.forms[0].submit();
					}
					break;
				default:
					selezionato="no";
					for ( i = 0 ; i < document.forms[0].rec.value; i++ ) {					
						if (document.forms[0].iduser[i].checked==true){
							selezionato="si";
						} 
					}
					if (selezionato=="si"){
						document.forms[0].action="gestione_utenti.asp?action=detail";
						document.forms[0].submit();
					} else {
						alert("Seleziona un utente prima.");
					}
					break;
			}
			break;
		case "delete":
			switch (document.forms[0].rec.value){
				case "0":
					alert("Nessun Utente Disponibile!");
					break;
				case "1":
					if (document.forms[0].iduser.checked==false){
						alert("Seleziona l'utente prima.");
					} else {
						if(confirm("ATTENZIONE!\nStai per cancellare PERMANENTEMENTE l'utente selezionato.\n\nProcedere?")){
							document.forms[0].action="gestione_utenti.asp?action=" + azione;
							document.forms[0].submit();
						}
					}
					break;
				default:
					selezionato="no";
					for ( i = 0 ; i < document.forms[0].rec.value; i++ ) {
						if (document.forms[0].iduser[i].checked==true){
							selezionato="si";
						} 
					}
					if (selezionato=="si"){
						if(confirm("ATTENZIONE!\nStai per cancellare PERMANENTEMENTE l'utente selezionato.\n\nProcedere?")){
							document.forms[0].action="gestione_utenti.asp?action=" + azione;
							document.forms[0].submit();
						}
					} else {
						alert("Seleziona un utente prima.");
					}
					break;
			}
			break;
		case "cerca":
			if (prendiElementoDaId("User").value=="cerca" || prendiElementoDaId("User").value.length<2){
				alert("Inserisci un testo valido per la ricerca.");
			} else {
				document.forms[0].action="gestione_utenti.asp?action=" + azione;
				document.forms[0].submit();
			}
			break;
		case "mostra_tutti":
			prendiElementoDaId("User").value="%";
			document.forms[0].action="gestione_utenti.asp?action=cerca";
			document.forms[0].submit();
			break;
	}
}

function valuta_e_spedisci_dir(azione){
	switch (azione){
		case "modify":
		  switch (document.forms[0].rec.value){
			  case "0":
			    alert("Nessuna Directory Disponibile!");
			    break;
			  case "1":
			    if (document.forms[0].idcategoria.checked==false){
					alert("Seleziona la directory prima.");
				} else {
			        document.forms[0].action="gestione_directory.asp?action=detail";
			        document.forms[0].submit();
				}
			    break;
			  default:
			    selezionato="no";
				for ( i = 0 ; i < document.forms[0].rec.value; i++ ) {
					
					//if (document.forms[0].idcategoria[i].value==1){
					  //alert(document.forms[0].idcategoria[i].value + " " + document.forms[0].idcategoria[i].checked==true)
					//}
			      if (document.forms[0].idcategoria[i].checked==true){
					selezionato="si";
				  } 
				}
				if (selezionato=="si"){
			      document.forms[0].action="gestione_directory.asp?action=detail";
			      document.forms[0].submit();
				} else {
				  alert("Seleziona la directory prima.");
				}
			    break;
		  }
		  break;
		case "delete":
		  switch (document.forms[0].rec.value){
			  case "0":
			    alert("Nessuna Directory Disponibile!");
			    break;
			  case "1":
			    if (document.forms[0].idcategoria.checked==false){
					alert("Seleziona la directory prima.");
				} else {
					if(confirm("ATTENZIONE!\nStai per cancellare PERMANENTEMENTE la directory selezionata\nL'operazione sarà consentita solo se la directory non ha altre sottodirectory\n\nL'OPERAZIONE CANCELLERÀ ANCHE TUTTI I DOCUMENTI CONTENUTI.\n\nProcedere?")){
			          document.forms[0].action="gestione_directory.asp?action=" + azione;
			          document.forms[0].submit();
					}
				}
			    break;
			  default:
			    selezionato="no";
				for ( i = 0 ; i < document.forms[0].rec.value; i++ ) {					
			      if (document.forms[0].idcategoria[i].checked==true){
					selezionato="si";
				  } 
				}
				if (selezionato=="si"){
				  if(confirm("ATTENZIONE!\nStai per cancellare PERMANENTEMENTE la directory selezionata\nL'operazione sarà consentita solo se la directory non ha altre sottodirectory\n\nL'OPERAZIONE CANCELLERÀ ANCHE TUTTI I DOCUMENTI CONTENUTI.\n\nProcedere?")){
			        document.forms[0].action="gestione_directory.asp?action=" + azione;
			        document.forms[0].submit();
				  }
				} else {
					alert("Seleziona la directory prima.");
				}
			    break;
		  }
		  break;
	}
}


function valuta_e_spedisci_News(azione){
	switch (azione){
		case "modify":
			switch (document.forms[0].rec.value){
				case "0":
			    	alert("Nessuna News Disponibile!");
			    	break;
			  	case "1":
			    	if (document.forms[0].IDInfo_News.checked==false){
						alert("Seleziona la News prima.");
					} else {
			        	document.forms[0].action="news_assalzoo.asp?action=detail";
			        	document.forms[0].submit();
					}
			    	break;
			  	default:
			    	selezionato="no";
					for ( i = 0 ; i < document.forms[0].rec.value; i++ ) {
						if (document.forms[0].IDInfo_News[i].checked==true){
							selezionato="si";
					  	} 
					}
					if (selezionato=="si"){
			      		document.forms[0].action="news_assalzoo.asp?action=detail";
			      		document.forms[0].submit();
					} else {
				  		alert("Seleziona la news prima.");
					}
			    	break;
		  		}
		  	break;
		case "delete":
			switch (document.forms[0].rec.value){
				case "0":
			    	alert("Nessuna News Disponibile!");
			    	break;
			  	case "1":
			    	if (document.forms[0].IDInfo_News.checked==false){
						alert("Seleziona la News prima.");
					} else {
						if(confirm("ATTENZIONE!\nStai per cancellare PERMANENTEMENTE la news selezionata\nL'OPERAZIONE CANCELLERÀ ANCHE TUTTI GLI ALLEGATI.\n\nProcedere?")){
			          		document.forms[0].action="news_assalzoo.asp?action=" + azione;
					        document.forms[0].submit();
						}
					}
			    	break;
			  default:
			  	selezionato="no";
				for ( i = 0 ; i < document.forms[0].rec.value; i++ ) {					
			    	if (document.forms[0].IDInfo_News[i].checked==true){
						selezionato="si";
				  	} 
				}
				if (selezionato=="si"){
					if(confirm("ATTENZIONE!\nStai per cancellare PERMANENTEMENTE la news selezionata\nL'OPERAZIONE CANCELLERÀ ANCHE TUTTI GLI ALLEGATI.\n\nProcedere?")){
						document.forms[0].action="news_assalzoo.asp?action=" + azione;
						document.forms[0].submit();
					}
				} else {
					alert("Seleziona la News prima.");
				}
			    break;
		  }
		  break;
		case "cerca":
			if (prendiElementoDaId("Doc").value=="cerca" || prendiElementoDaId("Doc").value.length<2){
		    	alert("Inserisci un testo valido per la ricerca.");
		  	} else {
			  	document.forms[0].action="news_assalzoo.asp?action=" + azione;
			  	document.forms[0].submit();
		  	}
		  break;
	}
}

function ApriPopUp(pagina,target,history,resizable,status,scrollbars,menubar,larghezza,altezza){
	var w = larghezza; 
	var h = altezza; 
	var pw = Math.floor((screen.width-w)/2); 
	var ph = Math.floor((screen.height-h)/2); 
	pop=window.open(pagina, target, "history=" + history +",resizable=" + resizable + ",status=" + status + ",scrollbars=" + scrollbars + ",menubar=" + menubar + ",width=" + larghezza + ",height=" + altezza + ",top=" + ph + ",left=" + pw);
    pop.focus();
    void(0);
}

function spedisci_documento(id){
	alert("Invio Modifica!");
}

function valuta_e_spedisci_documenti(azione){
	switch (azione){
		case "modify":
		  switch (document.forms[0].rec.value){
			  case "0":
			    alert("Nessuna Directory Disponibile!");
			    break;
			  case "1":
			    if (document.forms[0].iddocumento.checked==false){
					alert("Seleziona il documento prima.");
				} else {
			        document.forms[0].action="gestione_documenti.asp?action=detail";
			        document.forms[0].submit();
				}
			    break;
			  default:
			    selezionato="no";
				for ( i = 0 ; i < document.forms[0].rec.value; i++ ) {
					
					//if (document.forms[0].idcategoria[i].value==1){
					  //alert(document.forms[0].idcategoria[i].value + " " + document.forms[0].idcategoria[i].checked==true)
					//}
			      if (document.forms[0].iddocumento[i].checked==true){
					selezionato="si";
				  } 
				}
				if (selezionato=="si"){
			      document.forms[0].action="gestione_documenti.asp?action=detail";
			      document.forms[0].submit();
				} else {
				  alert("Seleziona il documento prima.");
				}
			    break;
		  }
		  break;
		case "delete":
		  switch (document.forms[0].rec.value){
			  case "0":
			    alert("Nessuna Directory Disponibile!");
			    break;
			  case "1":
			    if (document.forms[0].iddocumento.checked==false){
					alert("Seleziona il documento prima.");
				} else {
					if(confirm("ATTENZIONE!\nStai per cancellare PERMANENTEMENTE la directory selezionata\nL'operazione sarà consentita solo se la directory non ha altre sottodirectory\n\nL'OPERAZIONE CANCELLERÀ ANCHE TUTTI I DOCUMENTI CONTENUTI.\n\nProcedere?")){
			          document.forms[0].action="gestione_documenti.asp?action=" + azione;
			          document.forms[0].submit();
					}
				}
			    break;
			  default:
			    selezionato="no";
				for ( i = 0 ; i < document.forms[0].rec.value; i++ ) {					
			      if (document.forms[0].iddocumento[i].checked==true){
					selezionato="si";
				  } 
				}
				if (selezionato=="si"){
				  if(confirm("ATTENZIONE!\nStai per cancellare PERMANENTEMENTE il documento selezionato\nL'OPERAZIONE È IRREVERSIBILE!\n\nProcedere?")){
			        document.forms[0].action="gestione_documenti.asp?action=" + azione;
			        document.forms[0].submit();
				  }
				} else {
					alert("Seleziona il documento prima.");
				}
			    break;
		  }
		  break;
		case "cerca":
		  if (prendiElementoDaId("Doc").value=="cerca" || prendiElementoDaId("Doc").value.length<2){
		    alert("Inserisci un testo valido per la ricerca.");
		  } else {
			  document.forms[0].action="gestione_documenti.asp?action=" + azione;
			  document.forms[0].submit();
		  }
		  break;

	}
}

function cambia_sottocat(idcat,nome,ordine){
	document.forms[1].idreplica.value=idcat;
	prendiElementoDaId('Sottocategoria').innerHTML=nome;
	document.forms[1].Ordine.value=ordine;
}
function valida_modulo_utenti(form){
	errori="";
	if (form.Nome.value.length<2 && form.Cognome.value.length<2){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Devi compilare almeno uno dei seguenti campi: Nome,Cognome";
	}
	
	
	if (form.DittaEnte.value.length<1){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Ditta/Ente non inserito";
	}

	if (form.DittaEnte_Provincia.value.length<1){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Ditta/Ente provincia non inserita";
	}
	
	if (!CheckEmail(form.Mail.value)){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + '\n- Mail inserita non corretta';
	}
	
	if (form.User.value.length<6){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Il nome utente deve avere almeno 6 caratteri";
	}
	if (form.Pwd.value.length<6){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- La password deve avere almeno 6 caratteri";
	}
	if (errori!=""){
		alert("ATTENZIONE!\nSono stati riscontrati i seguenti errori nel modulo inserimento/modifica utenti\n\n" + errori +"\n\nRicontrolla tutti i campi e riprova.");
		return false;
	} else {
		/*alert(form.Mail.value!=form.Mail.defaultValue);
		alert(form.User.value!=form.User.defaultValue);
		alert(form.Pwd.value!=form.Pwd.defaultValue);*/
		if (form.Mail.value!=form.Mail.defaultValue || form.User.value!=form.User.defaultValue || form.Pwd.value!=form.Pwd.defaultValue){			
			if (confirm('Inviare i dati di accesso alla banca dati al cliente?')){
				form.SendMail.value='1';
			} else {
				form.SendMail.value='0';
			}
		} else {
			form.SendMail.value='0';
		}		
	  	return true;
	}
}

/*
function valida_modulo_utenti(form){
	errori="";
	if (form.Nome.value.length<2 && form.Cognome.value.length<2){
		errori = "- Devi compilare almeno uno dei seguenti campi: Nome,Cognome";
	}
	
	if (form.DittaEnte.value.length<1){
		errori = "- Ditta/Ente non inserito";
	}

	if (form.DittaEnte_Provincia.value.length<1){
		errori = "- Ditta/Ente provincia non inserita";
	}
	
	if (form.Telefono.value.length<1){
		errori = "- Telefono provincia non inserito";
	}

	if (form.User.value.length<6){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Il nome utente deve avere almeno 6 caratteri";
	}
	if (form.Pwd.value.length<6){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- La password deve avere almeno 6 caratteri";
	}
	
	
	if (errori!=""){
	  alert("ATTENZIONE!\nSono stati riscontrati i seguenti errori nel modulo inserimento/modifica utenti\n\n" + errori +"\n\nRicontrolla tutti i campi e riprova.");
	  return false;
	} else {
	  return true;
	}
}*/

function valida_modulo_documenti(form){	
	//alert(form.nomefile.value + " " +form.iddocumento.value)
	errori="";
	if (form.titolo.value.length<1){
		errori = errori + "- Inserisci un titolo al documento";
	}
	if (form.iddocumento.value>0 && form.nomefile.value.length<1){
		//form.nomefile.value="none";
	} else {
	  if (form.nomefile.value.length<1){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Seleziona un file dal tuo computer prima";
	  }
	}
	if (form.iddirectory.value==0){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Seleziona la directory in cui vuoi collocare il documento.";
	}
	if (errori!=""){
	  alert("ATTENZIONE!\nSono stati riscontrati i seguenti errori nel modulo inserimento/modifica utenti\n\n" + errori +"\n\nRicontrolla tutti i campi e riprova.");
	  return false;
	} else {
	  form.action="file.asp";	
	  return true;
	}
}

function valida_modulo_News(form){	
	errori="";
	if (form.titolo.value.length<1){
		errori = errori + "- Inserisci un titolo alla news";
	}
	if (form.Descrizione.value.length<1){
		errori = errori + "- Inserisci un testo alla news";
	}
	
	if (errori!=""){
		alert("ATTENZIONE!\nSono stati riscontrati i seguenti errori nel modulo inserimento/modifica utenti\n\n" + errori +"\n\nRicontrolla tutti i campi e riprova.");
		return false;
	} else {
		form.action="file_News.asp";	
		return true;
	}
}


function valida_modulo_directory(form){
	errori="";
	if (form.Nome.value.length<2){
		errori = "- Inserisci un Nome per la sottodirectory.";
	}
	if (form.idreplica.value==-1){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Seleziona una sottocategoria di appartenenza nella colonna di sinistra.\nAlcune sottocategorie potrebbero essere disabilitate perchè figlie della categoria che si vuole modificare.";
	}
	if (form.Ordine.value==0){
		if (errori!=""){
		  errori = errori + "\n";
		}
		errori = errori + "- Inserisci un valore di ordinamento";
	}
	if (errori!=""){
	  alert("ATTENZIONE!\nSono stati riscontrati i seguenti errori nel modulo inserimento/modifica sottodirectory\n\n" + errori +"\n\nRicontrolla tutti i campi e riprova.");
	  return false;
	} else {
	  return true;
	}
}

function prendiElementoDaId(id_elemento) {
	if (document.getElementById){
		elemento = document.getElementById(id_elemento);
	} else {
		elemento = document.all[id_elemento];
	}
	return elemento;
}

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_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_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_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];}
}


/********************************* Inizio Navigatore pagine *********************************/
var MaxPageVisible_on_Navigator=11;

function CalcolaTotalePagine(TR,TRFP){
	var TotalPage=1;
	//alert('mod=' + (TR % TRFP));
	
	if ((TR % TRFP )!=0 ) {
		TotalPage = parseInt(TR / TRFP) + 1
	} else {
		TotalPage = parseInt(TR / TRFP) 		
	}
	return TotalPage;
}

function CreaNavigatore(TotalRecord,TotalRowForPage,Didascalia){	
	var strInnerHTML="";
	
		var TR=TotalRecord;
	var TRFP=TotalRowForPage;

	var TotalPage=CalcolaTotalePagine(TR,TRFP);
var strStyle;
(TotalPage>1) ? strStyle="visible" : strStyle="hidden"

	//if (TotalPage>1) {
		strInnerHTML+='<table width="100%"  border="0" cellspacing="0" cellpadding="0" style="visibility:' +  strStyle +'">';
		strInnerHTML+='<tr>';
		strInnerHTML+='<td width="105" class="TD"><span class="' + prendiElementoDaId('ClassNavigatore_Riepilogo').value + '">Pagina dei risultati:</span></td>';
		strInnerHTML+='<td align="Left">';
		strInnerHTML+='<table width="100%"  border="0" cellspacing="0" cellpadding="0" align="left">';
		strInnerHTML+='<tr>';
		strInnerHTML+='<td id="Navigatore_Contenitore_Pagine" width="100%">';
		strInnerHTML+='</td>';
		strInnerHTML+='</tr>';
		strInnerHTML+='</table>';
		strInnerHTML+='</td>';				
		strInnerHTML+='<td><img src="Images/dot.gif" width="1" height="1"></td>';	
		strInnerHTML+='</tr>';
		strInnerHTML+='<tr>';
		strInnerHTML+='<td >';
		strInnerHTML+='<input type="hidden" id="FirstRecord_visible" name="FirstRecord_visible" value="">';
		strInnerHTML+='<input type="hidden" id="LastRecord_visible" name="LastRecord_visible" value="">';
		strInnerHTML+='<input type="hidden" id="CurrentPage_visible" name="CurrentPage_visible" value="">';
		strInnerHTML+='<input type="hidden" id="TotalPage" name="TotalPage" value="' + TotalPage +'">';
		strInnerHTML+='</td>';
		strInnerHTML+='</tr>';
		strInnerHTML+='</table>';
//	}
	return strInnerHTML;	
}

function CreaListaPagine(PaginaIniziale,PaginaFinale,PaginaCorrente,TotalRowForPage,TotalRecord,TotalPage,StringaRicerca){
	var strInnerHTML="";
	var lngI;
	var TRFP=TotalRowForPage;
	
	strInnerHTML+='<table  width="100%"  border="0" cellspacing="0" cellpadding="0" align="left">';

	strInnerHTML+='<td  class="TD" width="100" align="Center">';
	
	if(PaginaCorrente>1) {					

		strInnerHTML+='<a href="#" onclick="Paginazione(' + (PaginaCorrente-1) + ',' + parseInt((TRFP*((PaginaCorrente-1)-1)) +1) + ',' + TotalRowForPage + ',' + TotalRecord + ',\'' + StringaRicerca + '\')" class="' + prendiElementoDaId('ClassNavigatore_Numeri_Pagina').value + '"> < Precedenti</a>';
	} else {
		strInnerHTML+='<img src="Images/dot.gif" width="1" height="1">';
	}
	
	strInnerHTML+='</td>';	
	
	if (PaginaFinale>TotalPage)  PaginaFinale=TotalPage;
	
	var visible_Link="";
	var visible_Normale="";
		
	for (lngI=PaginaIniziale; lngI<=PaginaFinale; lngI++){
		
		if (PaginaCorrente==lngI){
			visible_Link="hidden";
			visible_Normale="visible";			
		}else{
			visible_Link="visible";
			visible_Normale="hidden";
		}
		
			strInnerHTML+='<td id="Navigatore_Pagina_' + lngI + '"  class="TD" width="20" align="Center">';
			
			if (PaginaCorrente!=lngI){
	//			strInnerHTML+='<div id="Navigatore_Pagina_' + lngI + '_Link" style="visibility:' + visible_Link + '; float:left; align:center">';			
//			strInnerHTML+='<div id="Navigatore_Pagina_' + lngI + '_Link" style="visibility:' + visible_Link + '; left=-5000; top=-5000; position=absolute;">';			
			strInnerHTML+='<a href="#"  onclick="Paginazione(' + lngI + ',' + parseInt((TRFP*(lngI-1)) +1) + ',' + TotalRowForPage + ',' + TotalRecord + ',\'' + StringaRicerca + '\')"  class="' + prendiElementoDaId('ClassNavigatore_Numeri_Pagina').value + '">' + lngI + '</a>';
			
		
		//	strInnerHTML+='</div>';
			}else{
//			strInnerHTML+='<div id="Navigatore_Pagina_' + lngI + '_Normale" style="visibility:' + visible_Normale + '; float:left; align:center" class="Navigatore_PaginaAttuale">';
			//strInnerHTML+='<div id="Navigatore_Pagina_' + lngI + '_Normale" style="visibility:' + visible_Normale + '; left=-5000; top=-5000; position=absolute;">';			
			strInnerHTML+='<span class="' + prendiElementoDaId('ClassNavigatore_PaginaAttuale').value + '">' + lngI + '</span>';
			//strInnerHTML+='</div>';
			}
			strInnerHTML+='</td>';
		}
			
		strInnerHTML+='<td  class="TD" width="100" align="Center">';		
		if (PaginaCorrente <TotalPage) {
			strInnerHTML+='<a href="#" onclick="Paginazione(' + (PaginaCorrente+1) + ',' + parseInt((TRFP*((PaginaCorrente+1)-1)) +1) + ',' + TotalRowForPage + ',' + TotalRecord + ',\'' + StringaRicerca + '\')" class="' + prendiElementoDaId('ClassNavigatore_Numeri_Pagina').value + '">Successive ></a>';
			
		} else {
			strInnerHTML+='<img src="Images/dot.gif" width="1" height="1">';
		}
		strInnerHTML+='</td>';	
		strInnerHTML+='<td><img src="Images/dot.gif" width="1" height="1"></td>';
		
		strInnerHTML+='</table>';
	
		return strInnerHTML;
}

function Paginazione(PaginaCorrente , Record_Partenza, TotalRowForPage, TotalRecord, StringaRicerca){
	//try{		
		/*Carica pagine navigatore*/
		var PaginaIniziale=1;		
		if (PaginaCorrente>parseInt((MaxPageVisible_on_Navigator/2)+1)) {
			PaginaIniziale=PaginaCorrente-(parseInt((MaxPageVisible_on_Navigator/2)+1)-1)
		}		
		var TotalPage=CalcolaTotalePagine(TotalRecord,TotalRowForPage);
		var PaginaFinale=(PaginaIniziale+MaxPageVisible_on_Navigator);
		if (PaginaFinale>TotalPage){
			PaginaIniziale=(TotalPage - MaxPageVisible_on_Navigator)
			if (PaginaIniziale<1) PaginaIniziale=1;
			PaginaFinale=TotalPage;			
		}		
		prendiElementoDaId('Navigatore_Contenitore_Pagine').innerHTML=CreaListaPagine(PaginaIniziale,PaginaFinale,PaginaCorrente,TotalRowForPage,TotalRecord,TotalPage,StringaRicerca);
		/**************************************************************************/

		/* Nasconde i risultati della pagina predecentemente visualizzata */
/*		if (isNumeric(prendiElementoDaId('FirstRecord_visible').value) && isNumeric(prendiElementoDaId('LastRecord_visible').value)){
			var J;
			for (J=parseInt(prendiElementoDaId('FirstRecord_visible').value); J<=parseInt(prendiElementoDaId('LastRecord_visible').value);J++){
				try{
					prendiElementoDaId('Risultato_Riga_' + J).style.position='absolute';
				} catch(e){
					alert	('Paginazione=' + e.message);
				}
			}
		}*/	
		 while (prendiElementoDaId('Tabella_Visione_Risultati').rows.length>0){
			prendiElementoDaId('Tabella_Visione_Risultati').deleteRow(0);
		}
		/**************************************************************************/
		
		//Imposto l'ulitmo elemento da visualizzare per la pagina corrente
		var MaxVisible=parseInt(Record_Partenza)+parseInt(TotalRowForPage)-1;	

		if (MaxVisible>parseInt(TotalRecord)) {
			//Se il numero massimo supera il numero totale di record ricercati dal sistema, imposto il  nuovo tetto massimo con il numero totale di record ricercati
			MaxVisible=TotalRecord;
		}

		var i=Record_Partenza;
		
		//alert(Record_Partenza);
		var x;
		var y;
		while (parseInt(i)<=parseInt(MaxVisible) ){			
//			prendiElementoDaId('Risultato_Riga_' + i).style.position='static';
			x=prendiElementoDaId('Tabella_Visione_Risultati').insertRow(prendiElementoDaId('Tabella_Visione_Risultati').rows.length);
			y=x.insertCell(0)
			y.innerHTML = prendiElementoDaId('Risultato_Riga_' + i).innerHTML;
			i+=1;
		}		
		
		prendiElementoDaId('CurrentPage_visible').value=PaginaCorrente;
		prendiElementoDaId('FirstRecord_visible').value=Record_Partenza;
		prendiElementoDaId('LastRecord_visible').value=(i-1);
		
		prendiElementoDaId('Navigatore_TOP').innerHTML='Risultati <strong>' + prendiElementoDaId('FirstRecord_visible').value + '</strong> di <strong>' + prendiElementoDaId('LastRecord_visible').value + '</strong> su circa <strong>' + TotalRecord + '</strong> per <strong>' + StringaRicerca + '</strong>';
		if ((i-1)==0){
			prendiElementoDaId('Navigatore_TOP_Risultati').style.visibility="hidden"
			prendiElementoDaId('Navigatore_TOP').style.visibility="hidden" 
		}else{
			prendiElementoDaId('Navigatore_TOP_Risultati').style.visibility="visible"
			prendiElementoDaId('Navigatore_TOP').style.visibility="visible"
		}
		
		
		//Nascondo i risulatati della pagina precedentemente visualizzata
		if (!isNumeric(prendiElementoDaId('CurrentPage_visible').value)) prendiElementoDaId('CurrentPage_visible').value="1";		
		var CPS=parseInt(prendiElementoDaId('CurrentPage_visible').value);		
	/*} catch(e) {
		alert('Paginazione:\n' + e.message);
	}*/
}

function isNumeric(vTestValue){
	// put the TEST value into a string object variable
	var sField = new String(Trim(vTestValue));
	
	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}
	
	// made it through the loop - we have a number
	return true;
}

function Trim(Valore) {
	return Valore.replace(/\s+$|^\s+/g,"");
}

function LTrim(Valore) {
	return Valore.replace(/^\s+/,"");
}

function RTrim(Valore) {
	return Valore.replace(/\s+$/,"");
}


/********************************* Fine Navigatore pagine *********************************/	


function Impostacontenuto(Campo){
	if(Trim(Campo.value)=="")
		Campo.value=Campo.defaultValue;
}

function CheckEmail(email) {
	AtPos = email.indexOf("@");
	StopPos = email.lastIndexOf(".");
	Len = email.length;

	Message = "";
	
	if (email="" || AtPos == -1 || StopPos == -1 ) {
		/*1)La mail è vuota
		  2)Non è stato trovata la chiocciola
		  3)Non è stato trovato il punto prima dell'estensione del dominio*/					  
		Message = "Not a valid email address"
	} else {				
		if (AtPos < 1) {
			//non esiste nessun carattere prima della chiocciola
			Message = "Not a valid Email address"
		}
	}
	
	if (StopPos==(Len-1)){
		//il punto non può stare come ultimo carattere
		Message = "Not a valid Email address"
	} else {
		if ((Len-1)-StopPos<2){
			//meno di 2 caratteri dopo Punto ultimo'
			Message = "Not a valid Email address"
		}
	}
	
	if (StopPos < AtPos) {
		//L'ulitmo punto della stringa non può stare prima della chiocciola
		Message = "Not a valid email address"
	} else {
		if ((StopPos-AtPos)==1){
			//la chioccila è attaccata al punto @.
			Message = "Not a valid email address"
		}
	}				
	
	return (Message=='');
}				