// FONDAZIONE ICONA
// JavaScript library utility
// (c) Aprile 2008 by Gianluca De Grandis

///////////////////////////////////////////////////////////////////////////////////////////////
// Controlli sul form di login
var ERR_LOGIN_NO_USERNAME = "Nome utente non valido!";
var ERR_LOGIN_PASSWORD = "Password non valida!";

function chkLoginData(){
	var myform = document.getElementById("loginForm");
	if ((!myform.userName.value)||(myform.userName.value.length > 121 )) {
		alert(ERR_LOGIN_NO_USERNAME);
		myform.userName.focus(); 
		return; 
	}
	if ((!myform.password.value)||(myform.password.value.length > 10 )||(myform.password.value.length < 3 )) {
		alert(ERR_LOGIN_PASSWORD);
		myform.password.focus(); 
		return; 
	}
	myform.submit();

}

///////////////////////////////////////////////////////////////////////////////////////////////
// Mostra/nasconde un oggetto
function showHideObject(objectId){
	if (document.getElementById(objectId).style.display == "none" )
		document.getElementById(objectId).style.display = "";
	else document.getElementById(objectId).style.display = "none" 
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Controlli sul form password dimenticata
var ERR_NO_EMAIL = "Inserire l'indirizzo email!";
var ERR_WRONG_EMAIL = "Indirizzo email NON valido!";
var ERR_EMAIL_TOO_LONG = "Indirizzo email troppo lungo!";

function chkPasswordForgotForm(){
	var myform = document.getElementById("passwordForgotForm");
	if (!myform.emailPasswordForgot.value){
		alert(ERR_NO_EMAIL);
		return;
	}
	if (!isEmail(myform.emailPasswordForgot.value)){
		alert(ERR_WRONG_EMAIL);
		return;
	}
	if (myform.emailPasswordForgot.value.length > 60 ) { 
		alert(ERR_EMAIL_TOO_LONG);
		return;
	}
	myform.submit();
}

function isEmail(string){
	if(string!=""){
		if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
			return 1;
		else
			return 0;
	}
	return 1;
}


