 $(document).ready(function(){
	$("#sendmail").click(function(){
								  
		var valid = '';
		var isr = ' richiesto.';
		var name = $("#name").val();
		var mail = $("#mail").val();
		var azienda = $("#azienda").val();
		var subject = $("#subject").val();
		var professione = $("#professione").val();
		var telefono = $("#telefono").val();
		var text = $("#text").val();
		var chk = $('input[name=check]:checked').val(); 
		
		if (name.length<1) {
			valid += '<br />&bull; &nbsp;Il tuo Nome o Cognome &egrave;'+isr;
			$("#name").css();
		}
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<br />&bull; &nbsp;Un Indirizzo email valido &egrave;'+isr;
		}
		
		if (chk == null) {
			valid += '<br />&bull; &nbsp;Serve il consenso per il trattamento dei dati.';
		}
		
		if (valid!='') {
			$("#response").fadeIn("slow");
			$("#response").html("Errore compilazione modulo:"+valid);
		}
		
		else {
			var datastr ='name=' + name + '&mail=' + mail + '&azienda=' + azienda + '&professione=' + professione + '&telefono=' + telefono + '&text=' + text + '&subject=' + subject;
			$("#response").css("display", "block");
			$("#response").html("Invio richiesta in corso.. ");
			$("#response").fadeIn("slow");
			setTimeout("send('"+datastr+"')",2000);
		}
		return false;
	});
});
function send(datastr){
	$.ajax({	
		type: "POST",
		url: "mail.php",
		data: datastr,
		cache: false,
		success: function(html){
		$("#response").fadeIn("slow");
		$("#response").html(html);
		setTimeout('$("#response").fadeOut("slow")',2000);
	}
	});
}

