// Fa la validazione dell'indirizzo di E-Mail
function ckEmailAddr(eAddr){
// Ritorna true se ok, false se non ok
	var DomainValidChars="1234567890abcdefghijklmnopqrstuvwxyz-.",UserValidChars=DomainValidChars+"_";
	var eInvalid=0,atPos,strCk;
	var msgEmpt="L'indirizzo di E-Mail è vuoto.",msgInva="L'indirizzo di E-Mail non è valido o contiene caratteri illegali.";
	if(eAddr==""){
		alert(msgEmpt);
		return false;
	}
	eAddr = eAddr.toLowerCase();
	atPos=eAddr.indexOf("@");
	atPos!=eAddr.lastIndexOf("@") || atPos<1 || atPos>(eAddr.length-5)?eInvalid+=1:null;
	strCk=eAddr.substring(0,atPos);
	for(i=0;i<strCk.length;i++){
		UserValidChars.indexOf(strCk.charAt(i))<0?eInvalid+= 1:null;
	}
	strCk=eAddr.slice(atPos+1);
	for(i=0;i<strCk.length;i++){
		DomainValidChars.indexOf(strCk.charAt(i))<0?eInvalid+=1:null;
	}
	strCk.indexOf(".")<0?eInvalid+=1:null;
	strCk=strCk.charAt(strCk.length-1);
	strCk=="." || strCk=="-"?eInvalid+=1:null;
	if(eInvalid!=0){
		alert(msgInva);
		return false;
	}
	return true;
}

// Verifica formale e gestion form di login
function frmLoginCk(which) {
	if (!ckEmailAddr(which.email.value)) {
		return false;
	}
	
	if (which.passw.value.length < 5) {
		alert ("La password deve essere lunga almeno 5 caratteri.");
		return false;
	}
	
	// Inizio algoritmo challange/response
	which.ok.disabled = true;
	str = MD5(which.passw.value) + ":" + which.response.value;
  which.response.value = MD5(str);
  which.passw.value = "";
	return true;
}
