var Checker={
	checks:{
		'richiesta':/.+/,
		'nome':/[a-zA-Z\' ]+/,
		'cognome':/[a-zA-Z\' ]+/,
		'indirizzo':/.+/,
		'citta':/.+/,
		/*'cap':/\d{5}/,*/
		'provincia':/[a-zA-z]{2}/,
		'telefono':/[\d\- \/\\]+/,
		'email':/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/,
		'captcha':/.+/
	},



	// controllo tutti i campi del form
	check_form:function(){
		for(i in this.checks){
			el=$(i);
			if(!this.checks[i].test(el.value)){
				el.style.backgroundColor='#ead5cc'; // background errore campi input
				elemento=i;
				

				if (el.name=='captcha'){
					switch (Common.lang()){
						case 'it': Common.errore('Il campo <b>"Verifica visiva"</b> non sembra corretto.', elemento); break;
						case 'en': Common.errore('The field <b>"Visual Verification"</b> doesn&#39;t seem correct.', elemento); break;
						case 'de': Common.errore('Der abgelegte <b>"Visual verification"</b> Name scheint korrekt nicht.', elemento); break;
						case 'fr': Common.errore('Le class&eacute; <b>"V&eacute;rification visuelle"</b> ne semble pas correct.', elemento); break;
						case 'es': Common.errore('El archivado <b>"Verificaci&oacute;n visual"</b> no parece correcto.', elemento); break;
					};
				} else {
					switch (Common.lang()){
						case 'it': Common.errore('Il campo <b>"'+el.name.replace(/_/g,' ')+'"</b> non sembra corretto.', elemento); break;
						case 'en': Common.errore('The field <b>"'+el.name.replace(/_/g,' ')+'"</b> doesn&#39;t seem correct.', elemento); break;
						case 'de': Common.errore('Der abgelegte <b>"'+el.name.replace(/_/g,' ')+'"</b> Name scheint korrekt nicht.', elemento); break;
						case 'fr': Common.errore('Le class&eacute; <b>"'+el.name.replace(/_/g,' ')+'"</b> ne semble pas correct.', elemento); break;
						case 'es': Common.errore('El archivado <b>"'+el.name.replace(/_/g,' ')+'"</b> no parece correcto.', elemento); break;
					};
				}
				return false;
			}
			else el.style.backgroundColor='#ffffff'; // bacgkground originale
		}
		return true;
	},


	
	// controllo il checkbox per la privacy
	checkbox:function(){
		if ($('accetto').checked==false){
			$('accetto').style.backgroundColor='#ead5cc'; // background errore checkbox
			switch (Common.lang()){
				case 'it': Common.errore('Non hai accettato la <b>normativa sulla privacy</b>', 'accetto'); break;
				case 'en': Common.errore('You have not accepted the <b>privacy terms</b>', 'accetto'); break;
				case 'de': Common.errore('Sie haben die <b>Privatleben-Bezeichnungen</b> nicht akzeptiert', 'accetto'); break;
				case 'fr': Common.errore('Vous n&#39;avez pas accept&eacute; les <b>termes de vie priv&eacute;e</b>', 'accetto'); break;
				case 'es': Common.errore('Usted no ha aceptado los <b>t&eacute;rminos de intimidad</b>', 'accetto'); break;
			};
			return false;
		}
		return true;
	}
};




// pulsanti form
Pulsanti = {
	spedisci: function(){
		modulo=$('contact_form');
		if (Checker.check_form(modulo) && Checker.checkbox())
			modulo.submit();
	},

	resetta: function(){
		$('contact_form').reset();
		for(i in Checker.checks){
			el=document.getElementById(i);
			el.style.backgroundColor='#fff'; // riporto tutti i campi al colore originale
		}
		$('accetto').style.backgroundColor='#fff'; 
	},
	
	rollover:function(div_id){
		$(div_id).style.background='#444444';
	},
	
	rollout:function(div_id){
		$(div_id).style.background='#a6a194';
	}
}


// eventi al caricamento della pagina
Event.observe(window, 'load', function(){

	Event.observe('send', 'click', function(){Pulsanti.spedisci();});
	Event.observe('cancel', 'click', function(){Pulsanti.resetta();});

	Event.observe('send', 'mouseover', function(){Pulsanti.rollover('send');});
	Event.observe('cancel', 'mouseover', function(){Pulsanti.rollover('cancel');});

	Event.observe('send', 'mouseout', function(){Pulsanti.rollout('send');});
	Event.observe('cancel', 'mouseout', function(){Pulsanti.rollout('cancel');});
	
})
