var Checker={
	checks:{'nome':/.+/,'cognome':/.+/,'indirizzo':/.+/,'citta':/.+/,'provincia':/.+/,'cap':/^[\d]{5}$/,'telefono':/[\d\- \/\\]+/,'email':/^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/},
	check_form:function(){
		for(i in this.checks){
			el=document.getElementById(i);
			if(!this.checks[i].test(el.value)){
				el.focus();
				alert('Il campo "'+el.name+'" non sembra corretto.');
				el.style.backgroundColor='#ddd';		
				return false;
			}
		}
		if (!document.getElementById('accetto').checked)
		{
			alert('per proseguire devi accettare la normativa sulla privacy');
			return false;
		}
		return true;
	}
};




input_focus=function(){
	//this.style.backgroundColor='#fff';
};
input_blur=function(){
	//this.style.backgroundColor='#fff';
};


window.onload=function(){
		inputs=document.getElementById('contatti').getElementsByTagName('input');
		inputs[inputs.length]=document.getElementById('contatti').getElementsByTagName('textarea')[0];
		for(i=0; i<inputs.length+1;i++){	
			inputs[i].onfocus=input_focus;
			inputs[i].onblur=input_blur;
		}
		inputs[0].focus();
		
		document.getElementById('send').onclick=function(){
			if(Checker.check_form())document.getElementById('contatti').submit();
		};
		document.getElementById('reset').onclick=function(){
			document.getElementById('contatti').reset();
		};

	
};