//***** FUNZIONI DI CONVALIDA DEI DATI INSERITI NEL FORM DI CONTATTO *****

function IsEmailValid(){
	var EmailOk  = true
	var Temp     = document.frmModulo.txtEmail.value;
	var AtSym    = Temp.indexOf('@')
	var Period   = Temp.lastIndexOf('.')
	var Space    = Temp.indexOf(' ')
	var Length   = Temp.length - 1   
	// Array is from 0 to length-1
	if (Temp == "") { 
	return true; }
	if ((AtSym < 1) ||                     
	    (Period <= AtSym+1) ||             
	    (Period == Length ) ||             
	    (Space  != -1))
		{                 
	      alert("Inserire un indirizzo E-mail valido.");
			document.frmModulo.txtEmail.focus();
	      EmailOk = false
	   }

	return EmailOk
}

function Convalida(){ 
    if (document.frmModulo.txtRagioneSociale.value==""){
		alert("Inserire il cognome o la ragione sociale");
		document.frmModulo.txtRagioneSociale.focus();
		return false;
	}
	if (document.frmModulo.txtNome.value==""){
		alert("Inserire il nome");
		document.frmModulo.txtNome.focus();
		return false;
	}
	if (document.frmModulo.txtIndirizzo.value==""){
		alert("Inserire l'indirizzo");
		document.frmModulo.txtIndirizzo.focus();
		return false;
	}
	
	if (document.frmModulo.txtCAP.value==""){
		alert("Inserire il CAP");
		document.frmModulo.txtCAP.focus();
		return false;
	}
	
	if (document.frmModulo.txtCitta.value==""){
		alert("Inserire la Cittą");
		document.frmModulo.txtCitta.focus();
		return false;
	}
	
	if (document.frmModulo.cmbProvincia.value==""){
		alert("Inserire la provincia");
		document.frmModulo.cmbProvincia.focus();
		return false;
	}
	
	if ((document.frmModulo.txtEmail.value=="")&&(document.frmModulo.txtTelefono.value=="")){
		alert("Inserire almeno o l' E-Mail o il telefono");
		document.frmModulo.txtEmail.focus();
		return false;
	}
	
	if (IsEmailValid()==false){
		return false;
	}
	
	if (document.frmModulo.txtInfo.value==""){
		alert("Inserire le richieste");
		document.frmModulo.txtInfo.focus();
		return false;
	}
	if ((document.frmModulo.chkDatiPersonali.checked)==false){
		alert("E' necessario inserire la spunta su 'Autorizzo' per consentire il trattamento dei dati personali.");
		document.frmModulo.chkDatiPersonali.focus();
		return false;
	}
	
	return true;

}

function ConvalidaRegistrazione(){ 
    if (document.frmModulo.txtRagioneSociale.value==""){
		alert("Inserire il cognome o la ragione sociale");
		document.frmModulo.txtRagioneSociale.focus();
		return false;
	}
	if (document.frmModulo.txtNome.value==""){
		alert("Inserire il nome");
		document.frmModulo.txtNome.focus();
		return false;
	}
	
	if (document.frmModulo.txtComune.value==""){
		alert("Inserire la Cittą");
		document.frmModulo.txtComune.focus();
		return false;
	}
	
	if (document.frmModulo.cmbProvincia.value==""){
		alert("Inserire la provincia");
		document.frmModulo.cmbProvincia.focus();
		return false;
	}
	
	if (document.frmModulo.txtEmail.value==""){
		alert("Inserire  l' E-Mail ");
		document.frmModulo.txtEmail.focus();
		return false;
	}
	
	if (IsEmailValid()==false){
		return false;
	}
	
	if (document.frmModulo.txtUserID.value==""){
		alert("Inserire il nome utente per il login");
		document.frmModulo.txtUserID.focus();
		return false;
	}
	if (document.frmModulo.txtPassword.value==""){
		alert("Inserire la Password");
		document.frmModulo.txtPassword.focus();
		return false;
	}
	if (document.frmModulo.txtPassword2.value==""){
		alert("Ripeti l'inserimento della Password");
		document.frmModulo.txtPassword2.focus();
		return false;
	}
	if (document.frmModulo.txtPassword2.value!=document.frmModulo.txtPassword.value){
		alert("Le Password non corrispondono. Ripeti l'inserimento");
		document.frmModulo.txtPassword.value=""
		document.frmModulo.txtPassword2.value=""
		document.frmModulo.txtPassword.focus();
		return false;
	}
	
	if ((document.frmModulo.chkDatiPersonali.checked)==false){
		alert("E' necessario inserire la spunta su 'Autorizzo' per consentire il trattamento dei dati personali.");
		document.frmModulo.chkDatiPersonali.focus();
		return false;
	}
	
	return true;

}

function ConvalidaModificaDatiUtente(){ 
    if (document.frmModulo.txtRagioneSociale.value==""){
		alert("Inserire il cognome o la ragione sociale");
		document.frmModulo.txtRagioneSociale.focus();
		return false;
	}
	if (document.frmModulo.txtNome.value==""){
		alert("Inserire il nome");
		document.frmModulo.txtNome.focus();
		return false;
	}
	
	if (document.frmModulo.txtComune.value==""){
		alert("Inserire la Cittą");
		document.frmModulo.txtComune.focus();
		return false;
	}
	
	if (document.frmModulo.cmbProvincia.value==""){
		alert("Inserire la provincia");
		document.frmModulo.cmbProvincia.focus();
		return false;
	}
	
	if (document.frmModulo.txtEmail.value==""){
		alert("Inserire  l' E-Mail ");
		document.frmModulo.txtEmail.focus();
		return false;
	}
	
	if (IsEmailValid()==false){
		return false;
	}
	
	if (document.frmModulo.txtUserID.value==""){
		alert("Inserire il nome utente per il login");
		document.frmModulo.txtUserID.focus();
		return false;
	}
	if (document.frmModulo.txtPassword.value==""){
		alert("Inserire la Password");
		document.frmModulo.txtPassword.focus();
		return false;
	}
	
	return true;

}

function ConvalidaLogin(){ 
    if (document.frmLogin.txtUserID.value==""){
		alert("Inserire il nome Utente");
		document.frmLogin.txtUserID.focus();
		return false;
	}
	if (document.frmLogin.txtPassword.value==""){
		alert("Inserire la password");
		document.frmLogin.txtPassword.focus();
		return false;
	}
	return true;

}

//***** FINE FUNZIONI DI CONVALIDA DEI DATI INSERITI NEL FORM DI CONTATTO ****** 

