function controlloCambioPassword(){
    with(document.cambiaPassword) {
	    if(pass.value=="") {
	        alert("Errore: compilare il campo Password");
	        pass.focus();
	        return false;
	    }
	    
	    if(pass.value!=pass1.value) {
	        alert("Errore: La Password di conferma deve essere uguale a quella scelta");
	        pass1.focus();
	        return false;
	    }
	    
	    if(pass1.value=="") {
	        alert("Errore: compilare il campo Nuova Password");
	        pass1.focus();
	        return false;
	    }
	    
	    if(pass.value.length<5) {
	        alert("Errore: la password deve contenere almeno 5 caratteri<textarea></textarea>");
	        pass.focus();
	        return false;
	    }
    }

    return true;
} 

function controlloCreaEditor(){
    with(document.creaEditor) {

	    if(nome.value=="") {
	        alert("Errore: compilare il campo Nome");
	        nome.focus();
	        return false;
	    }
	    
	    if(cognome.value=="") {
	        alert("Errore: compilare il campo Cognome");
	        cognome.focus();
	        return false;
	    }
	    
	    if(user.value=="") {
	        alert("Errore: compilare il campo user");
	        user.focus();
	        return false;
	    }
	    
	    if(pass.value!=pass1.value) {
	        alert("Errore: La Password di conferma deve essere uguale a quella scelta");
	        pass.focus();
	        return false;
	    }
	    
	    if(pass1.value=="") {
	        alert("Errore: compilare il campo Nuova Password");
	        pass1.focus();
	        return false;
	    }
	    
	    if(pass.value.length<5) {
	        alert("Errore: la password deve contenere almeno 5 caratteri");
	        pass.focus();
	        return false;
	    }
	    
	    return controlloEmail('0', '9')
    }

    return true;
} 

function controlloPrimoPiano(){
    with(document.creaPrimoPiano) {

	    if(categoria.value=="") {
	        alert("Errore: compilare il campo Categoria");
	        categoria.focus();
	        return false;
	    }
	    
	    if(titolo.value=="") {
	        alert("Errore: compilare il campo Titolo");
	        titolo.focus();
	        return false;
	    }
	    
	    if(testo.value=="") {
	        alert("Errore: compilare il campo Testo");
	        testo.focus();
	        return false;
	    }
    }

    return true;
} 

function controlloEmail(f,e) {

    var ok=true;

    var a=document.forms[f].elements[e];

    var pe=a.value.indexOf('.');
    var ss=a.value.indexOf(' ');
    var lch=a.value.length-1;
    var atr=a.value.indexOf('@');
    var att=atr+1;

    var sq=a.value.substring(0,atr); 
    var sw=a.value.substring(atr,pe); 
    var se=a.value.substring(pe,lch);

    if((atr<1) || (pe<=att) || (pe==lch) || (pe<1)  || (ss != -1) || (sq.length<=2) || (sw.length<=3) || (se.length<=1)) {

	    alert("Errore: email non valida");
        return false;
    }
    
    return true;
}

function controlloNews() {
    with(document.creaNews) {
	
	    if(titolo.value=="") {
	        alert("Errore: compilare il campo Titolo");
	        titolo.focus();
	        return false;
	    }
	    
	    if(testo.value=="") {
	        alert("Errore: compilare il campo Contenuto");
	        testo.focus();
	        return false;
	    }
    }

    return true;
} 

function MaxCaratteri(Object, MaxLen) {
    return (Object.value.length <= MaxLen);
}

function controlloCreaMaster(){
    with(document.creaMaster) {
	    if(titoloMaster.value=="") {
	        alert("Errore: compilare il campo Titolo Master");
	        titoloMaster.focus();
        	return false;
	    }
	
	    if(cittaSvolgimento.value=="") {
	        alert("Errore: compilare il campo 'Città Svolgimento' ");
	        cittaSvolgimento.focus();
	        return false;
	    }
	    
	    if(provaAmmissione.value=="") {
	        alert("Errore: compilare il campo 'Data Prova Ammissione' ");
	        provaAmmissione.focus();
	        return false;
	    }
	
	    if(luogoSelezioni.value=="") {
	        alert("Errore: compilare il campo 'Luogo Selezioni' ");
	        luogoSelezioni.focus();
	        return false;
	    }
	
	    if(luogoMaster.value=="") {
	        alert("Errore: compilare il campo 'Luogo Master' ");
	        luogoMaster.focus();
	        return false;
	    }
    	
	    if(testoBreve.value=="") {
	        alert("Errore: compilare il campo 'Descrizione Breve' ");
	        testoBreve.focus();
	        return false;
	    }
	    
	    if(testoCompleto.value=="") {
	        alert("Errore: compilare il campo 'Descrizione Completa' ");
	        testoCompleto.focus();
	        return false;
	    }
    }

    return true;
}

function controlloCreaCorso(){
    with(document.creaCorso) {
	    if(titoloCorso.value=="") {
	        alert("Errore: compilare il campo Titolo Corso");
	        titoloCorso.focus();
	        return false;
	    }
	
	    if(testoBreve.value=="") {
	        alert("Errore: compilare il campo 'Descrizione Breve' ");
	        testoBreve.focus();
	        return false;
	    }
	    
	    if(testoCompleto.value=="") {
	        alert("Errore: compilare il campo 'Descrizione Completa' ");
	        testoCompleto.focus();
	        return false;
	    }
    }

    return true;
}

function controlloCategoria() {
    with(document.creaCategoria) {
    	if(descrCateg.value=="") {
	        alert("Errore: compilare il campo 'Categoria'");
	        descrCateg.focus();
	        return false;
	    }
    }

    return true;
}

function controlloCreaGalleria() {
    with(document.creaGalleria) {
	    if(nomePagina.value=="") {
	        alert("Errore: compilare il campo Titolo");
	        nomePagina.focus();
	        return false;
	    }
	
	    if(fileImmagineVideo.value!=""){
		    if(document.getElementById('tipologiaFile').selectedIndex==0){
			    alert("Attenzione: Selezionare il tipo di file")
			    return false;
		    }
        }
    }

    return true;
}

function controlloCreaContatti(){

    with(document.creaContatti) {
        if(nomePagina.value=="") {
	        alert("Errore: compilare il campo Nome Pagina");
	        nomePagina.focus();
	        return false;
	    }
    	
	    if(testo.value=="") {
	        alert("Errore: compilare il campo Contenuto");
	        testo.focus();
        	return false;
	    }
    }

    return true;
}

function controlloModuloAziende(){

    with(document.moduloAziende) {
        if(RagSociale.value=="") {
	        alert("Attenzione: il campo Ragione sociale è obbligatorio");
	        RagSociale.focus();
	        return false;
	    }
	
	    if(PIVA.value=="") {
	        alert("Attenzione: il campo Partita IVA è obbligatorio");
	        PIVA.focus();
        	return false;
	    }
	
	    if(Indirizzo.value=="") {
	        alert("Attenzione: il  campo Indirizzo è obbligatorio");
        	Indirizzo.focus();
	        return false;
	    }
	
	    if(citta.value=="") {
	        alert("Attenzione: il campo Città è obbligatorio");
	        citta.focus();
	        return false;
	    }
	
	    if(nome.value=="") {
	        alert("Attenzione: il campo Nome è obbligatorio");
	        nome.focus();
        	return false;
	    }
	
	    if(cognome.value=="") {
	        alert("Attenzione: il campo Cognome è obbligatorio");
	        cognome.focus();
	        return false;
	    }
	
	    if(telefono.value=="") {
	        alert("Attenzione: il campo Telefono è obbligatorio");
	        telefono.focus();
	        return false;
	    }
	    
	    if(telefono.value!="") {
	        if(telefono.value.length<3 || telefono.value.isNaN){
		        alert("Il numero di telefono non è corretto:");
		        telefono.focus();
		        return false;
	        }
        }
	
	    if(email.value=="") {
	        alert("Attenzione: il campo Email è obbligatorio");
	        email.focus();
        	return false;
	    }
	
        var PIvaOk=partitaIVA(PIVA.value);
        if (PIvaOk==false) {
            alert("Partita IVA errata");
            return false;
        }

    	return controlloEmail('0', '10')
    }
    
    return true;
}

function controlloLavoraConNoi(){

    with(document.moduloLavoraConNoi) {
    
        if(lcnNome.value=="") {
	        alert("Attenzione: il campo Nome è obbligatorio");
	        lcnNome.focus();
	        return false;
	    }
	
	    if(lcnCognome.value=="") {
	        alert("Attenzione: il campo Cognome è obbligatorio");
	        lcnCognome.focus();
        	return false;
	    }
	
	    if(lcnIndirizzo.value=="") {
	        alert("Attenzione: il  campo Indirizzo è obbligatorio");
        	lcnIndirizzo.focus();
	        return false;
	    }
	
	    if(lcnCitta.value=="") {
	        alert("Attenzione: il campo Città è obbligatorio");
	        lcnCitta.focus();
	        return false;
	    }
	
	    if(lcnTelefono.value=="") {
	        alert("Attenzione: il campo Telefono è obbligatorio");
	        lcnTelefono.focus();
        	return false;
	    }
	
	    if(lcnEMail.value=="") {
	        alert("Attenzione: il campo E-Mail è obbligatorio");
	        lcnEMail.focus();
	        return false;
	    }
	
    	return controlloEmail('1', '6')
    }
    
    return true;
}

function controlloModulo1(){
    with(document.moduloAziende) {
	
	    if(nome.value=="") {
	        alert("Attenzione: il campo Nome è obbligatorio");
	        nome.focus();
	        return false;
	    }
	
	    if(cognome.value=="") {
	        alert("Attenzione: il campo Cognome è obbligatorio");
	        cognome.focus();
	        return false;
	    }
	
	    if(telefono.value=="") {
	        alert("Attenzione: il campo Telefono è obbligatorio");
	        telefono.focus();
	        return false;
	    }
	    
	    if(telefono.value!="") {
	        if(telefono.value.length<3 || telefono.value.isNaN){
		        alert("Il numero di telefono non è corretto:");
		        telefono.focus();
		        return false;
	        }
	    }
	  
	    if(fax.value!="") {
	        if(fax.value.length<3 || fax.value.isNaN){
		        alert("Il numero di fax non è corretto:");
		        fax.focus();
		        return false;
	        }
        }
	
	    if(email.value=="") {
	        alert("Attenzione: il campo Email è obbligatorio");
	        email.focus();
	        return false;
        }
	
        var PIvaOk=partitaIVA(PIVA.value); 
        if (PIvaOk==false) {
            alert("Partita IVA errata");
            return false;
        }

	    return controlloEmail('0', '10')
	}
	
	return true;
}

function partitaIVA(sz_Codice) {
    var n_Val,n_Som1=0,n_Som2=0,lcv;
    if (sz_Codice.length!=11 || isNaN(parseFloat(sz_Codice)) || parseFloat(sz_Codice)<parseFloat(0))
        return false;
   
    for (lcv=0;lcv<9;lcv+=2) {
        n_Val=parseInt(sz_Codice.charAt(lcv));
        n_Som1+=n_Val;
        n_Val=parseInt(sz_Codice.charAt(lcv+1));
        n_Som1+=Math.floor(n_Val/5) + (n_Val<<1) % 10;
    }
   
    n_Som2 = 10 - (n_Som1 % 10);
    n_Val=parseInt(sz_Codice.charAt(10));
    if (n_Som2==n_Val)
        return true;
    
    return false;
}

function controlloM1(){
    with(document.m1) {
    	
	    if(nome.value=="") {
	        alert("Errore: compilare il campo Nome");
	        nome.focus();
	        return false;
	    }
    	
	    if(cognome.value=="") {
	        alert("Errore: compilare il campo Cognome");
	        cognome.focus();
	        return false;
	    }
    	
	    if(telefono.value!="") {
	        if(telefono.value.length<3 || telefono.value.isNaN){
		        alert("Il numero di telefono non è corretto:")
		        telefono.focus()
		        return false;
	        }
	    }
    	  
        if(fax.value!="") {
	        if(fax.value.length<3 || fax.value.isNaN){
		        alert("Il numero di fax non è corretto:")
		        fax.focus()
		        return false;
	        }
	    }
    	
	    if(email.value=="") {
	        alert("Attenzione: il campo Email è obbligatorio");
	        email.focus();
	        return false;
	    }
    }

    return true;
} 

function controlloM3NewsLetter(){
    with(document.m3NewsLetter) {
	
	    if(nome.value=="") {
	        alert("Errore: compilare il campo Nome");
	        nome.focus();
	        return false;
	    }
	
	    if(cognome.value=="") {
	        alert("Errore: compilare il campo Cognome");
	        cognome.focus();
	        return false;
	    }
	
    	if(email.value=="") {
	        alert("Attenzione: il campo Email è obbligatorio");
	        email.focus();
	        return false;
	    }
	    
        if (!indirizzoEmailValido(email.value)) {
		    alert("Attenzione: email  non è valida");
	        email.focus();
        	return false;
	    }
    }

    return true;
} 

function indirizzoEmailValido(indirizzo) {
    if (window.RegExp) {
        var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
        var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
        var regnv = new RegExp(nonvalido);
        var regv = new RegExp(valido);
        if (!regnv.test(indirizzo) && regv.test(indirizzo))
            return true;
        return false;
	} else {
        if(indirizzo.indexOf("@") >= 0)
            return true;
        return false;
  	}
}