

var validator = new Object();


 /**
  * fade the Formular Message
  */
validator.fadeFormMessage = function(msg, box){
	
	if(!this.messageVisible){
		Spry.Effect.AppearFade(box, {duration:1000,from:0,to:100,toggle:true});
		this.messageVisible = true;
	}
	
	var el = document.getElementById(box);
	if(el){
		el.innerHTML = msg;
	}
	else{
  	  alert(msg);
	}
}


 /**
  * validate requestAccess Form
  */
validator.chkRequestFormular = function(formName) {
  
  var form = document[formName];
  var box = 'formMessage';
  if (form.nome.value == "") {
  
  	validator.fadeFormMessage("Per favore inserisci il nome.", box);
	
    document.Formular.nome.focus();
    return false;
  }
  
   if (form.cognome.value == "") {
   	validator.fadeFormMessage("Per favore inserisci il cognome.", box);
    document.Formular.cognome.focus();
    return false;
  	}
  
   if (form.email.value == "") {
   	validator.fadeFormMessage("Per favore inserisci la email.", box);
    document.Formular.email.focus();
    return false;
  }
  
  if (!this.checkEmail(form.email.value)) {
 	validator.fadeFormMessage("Per favore inserisci un indirizzo email valido.", box);
    document.Formular.email.focus();
    return false;
  }
  
  if (form.email.value != document.Formular.emailw.value) {
    validator.fadeFormMessage("Per favore controlla la email in entrambi i campi.", box);
    document.Formular.emailw.focus();
    return false;
  }
  
  if (form.telefono.value == "") {
   	validator.fadeFormMessage("Per favore inserisci il numero di telefono.", box);
    document.Formular.telefono.focus();
    return false;
  }
  
  if (form.ente.value == "") {
   	validator.fadeFormMessage("Per favore inserisci  l'ente di appartenenza.", box);
    document.Formular.ente.focus();
    return false;
  }
  
  if (form.motivo.value == "") {
   	validator.fadeFormMessage("Per favore inserisci il motivo della richiesta.", box);
    document.Formular.motivo.focus();
    return false;
  }
  
  
  }
  
  
  
  validator.chkUtentiExtraFormular = function(formName){
	  
  }
  
  validator.chkLoginFormular = function(formName){
	  
	 	var form = document[formName];
  	var box = 'formMessage';
 	 if (form.email.value == "") {
  
  		validator.fadeFormMessage("email o password non sono validi.", box);
	
   	 document.Formular.email.focus();
    return false;
  }
  
  if (!this.checkEmail(form.email.value)) {
 	validator.fadeFormMessage("email o password non sono validi.", box);
    document.Formular.email.focus();
    return false;
  }
  
   if (form.passwd.value == "") {
  
  		validator.fadeFormMessage("email o password non sono validi.", box);
	
   	 document.Formular.passwd.focus();
    return false;
  }
  
  }
  
  /**
  * validate remindPassword Form
  */
  validator.chkRemindFormular = function(formName) {
  
	  var form = document[formName];
	  var box = 'formMessage';
		
	  if (form.email.value == "") {
	  
	  	validator.fadeFormMessage("Per favore inserisci il indirizzo email.", box);
		
	    document.Formular.email.focus();
	    return false;
	  }
	  
	   if (!this.checkEmail(form.email.value)) {
 			validator.fadeFormMessage("Per favore inserisci un indirizzo email valido.", box);
    		document.Formular.email.focus();
    		return false;
  		}
  
  }
  
  /**
  * validate email using regular expresssion
  */
  validator.checkEmail = function(email){
  	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(email))
			return true;
		else return false;
  }

