var formValidator = {
    theForm: new Array(), 
       
     initialize: function(aForm) {
     	this.theForm = aForm ; 
     },
       
     add : function (triplet) {
     	// ajoute un triplet {valeur/type de test/msg d'erreur}.
     	this.theForm.push(triplet); 
     },  
     
     clear : function () {
     	this.theForm = new Array() ; 
     },  
     
     checkIt: function() {
     
     	var msgBack = "" ; 
		for ( var i = 0 ; i < this.theForm.length ; i++ ) {			
			
			if( !this.validateData( this.theForm[i].value, this.theForm[i].command)) 
				msgBack += ( this.theForm[i].msg == null ? "" : this.theForm[i].msg ) ; 
	    }
		return msgBack ; 
	},
    
    validateData: function(value, command) {
	    switch(command) { 
	        case "filled":  {      
	 			return this.isFilled( value ) ; 
				break;             
	         } 

	        case "email": { 
	 			return this.isEmail( value ) ; 
				break;    
	            }
	    }
    }, 
        
	isEmail : function(email) {
	   if(email == null || email.length == 0)return false;
	   
	   var splitted = email.match("^(.+)@(.+)$");
	   if(splitted == null) return false;
	   if(splitted[1] != null )   {
	      var regexp_user=/^\"?[\w-_\.]*\"?$/;
	      if(splitted[1].match(regexp_user) == null) return false;
	    }
	    if(splitted[2] != null) {
	      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
	      if(splitted[2].match(regexp_domain) == null){
		    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
		    if(splitted[2].match(regexp_ip) == null) return false;
	      }
	      return true;
	    }
		return false;    
	},
  
	isFilled: function(field) {
		if(field == null || field.length == 0)return false;
		else return true ; 
   }
};