function vuota(elem,valore){
	if(elem.value==valore)	
		elem.value="";
}	
function riempi(elem,valore){
	if(elem.value=="")	
		elem.value=valore;
}
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		return false;
	}	
}
function validaForm(){
	var valido=true;
	if(document.richiesta.nome.value=="" || document.richiesta.nome.value=="nome"){
		valido=false;
		alert("Non hai inserito Nome e Cognome!");		
	}		
else if(!emailValidator(document.richiesta.email)){
		valido=false;
		alert("Non hai inserito un email valida!");
	}
	else if(!document.richiesta.privacypre.checked){
		valido=false;
		alert("L'accettazione della Privacy è obbligatoria. In sua mancanza il messaggio non potrà essere inviato.");		
	}
	if(valido){
		document.richiesta.submit();
	}
}



//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = '00impianto/privacy1.png';
var imgTrue = '00impianto/privacy2.png';

//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
	replaceChecks();
}

function replaceChecks() {
	
	//get all the input fields on the page
	inputs = document.getElementsByTagName('input');

	//cycle trough the input fields
	for(var i=0; i < inputs.length; i++) {

		//check if the input is a checkbox
		if(inputs[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputs[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImage'+i;
			//set image 
			img.onclick = new Function('checkChange('+i+')');
			//place image in front of the checkbox
			inputs[i].parentNode.insertBefore(img, inputs[i]);
			
			//hide the checkbox
			inputs[i].style.display='none';
		}
	}
}

//change the checkbox status and the replacement image
function checkChange(i) {

	if(inputs[i].checked) {
		inputs[i].checked = '';
		document.getElementById('checkImage'+i).src=imgFalse;
	} else {
		inputs[i].checked = 'checked';
		document.getElementById('checkImage'+i).src=imgTrue;
	}
}

window.onload = init;
