/*

USE:

var checkForm = new Check([
	{ $('champ1'), 'filled' },
	{ $('champ2'), 'mail' },
	{ $('champ3'), 'number' }
]);



*/
var FormCheck = new Class({
	eFields: [],
	
	initialize: function(testFields) {
		var _this = this;
		
		testFields.each(function(e) {
			switch(e.type) {
				case 'mail':
					if(! _this.isMail(e.field))
						_this.eFields.push(e.field);	
					break;
					
				case 'number':
					if(! _this.isNumber(e.field)) 
						_this.eFields.push(e.field);
					break;
					
				case 'filled':
					if(_this.isEmpty(e.field))
						_this.eFields.push(e.field);
					break;
			}
		});
		
		this.valid = this.eFields.length == 0;
	},
	
	
	isMail: function(field) {
		exp = new RegExp("[A-Za-z0-9\.\-_]+@[A-Za-z0-9\.\-_]","g");
		return exp.test(field.value);
    },
	
	
	isEmpty: function(field) {
		return field.value.length == 0;
	},
	
	
	isNumber: function(field) {
		if(this.isEmpty(field))
			return false;
		else
			return !isNaN(field.value);
	}
});