
document.test={
	'field_0':/^\w{2,}$/,'field_1':/^\w{2,}$/,'field_2':/^[\w\s]+$/,'field_3':/^\w{2,}$/,'field_5':/^\d+$/,'field_7':/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/,'field_8':/^.+$/
};

checkForm=function(){
	for(field in document.test){
		if( !document.test[field].test($F(field)) ){
			this.field=$(field);
			this.field.focus();
			alert('Il campo "'+this.field.name+'" non contiene i valori aspettati, controllare.');
			return false;
		}
	}
	return true;
};

checkField=function(){
	this.regexp=this.regexp || new RegExp(document.test[this.id]);
	if(!this.value.match(this.regexp)){
		this.addClassName('wrong');
	}else{
		this.removeClassName('wrong');
	}
};

window.onload=function(){ 
	$('contatti').onsubmit=checkForm;
	for(field in document.test){
		Event.observe(field,'keyup',checkField.bindAsEventListener($(field)));
	}
};

