$(document).ready(function(){
	$(".contact-input").click(function(){
		$(this).val("");
	});

	$(".link").click(function(){
		var id = $(this).attr("id").replace("link_","");
		$("#text_"+id).fadeIn("fast");
	});
	$(".chiudi").click(function(){
		var id = $(this).attr("id").replace("chiudi_","");
		$("#text_"+id).fadeOut("fast");
	});
	
	
	$("#send").click(function(){
		var nome = $("#nome").val();
		var mail = $("#mail").val();
		var oggetto = $("#oggetto").val();
		var messaggio = $("#messaggio").val();
		
		var check = true;
		if(nome == "" || nome == "NOME E COGNOME"){
			$("#nome").val("Campo obbligatorio");
			$("#nome").css("color","red");
			check = false;
		}
		if(mail == "" || mail == "MAIL"){
			$("#mail").val("Campo obbligatorio");
			$("#mail").css("color","red");
			check = false;
		}
		if(oggetto == "" || oggetto == "OGGETTO"){
			$("#oggetto").val("Campo obbligatorio");
			$("#oggetto").css("color","red");
			check = false;
		}
		if(messaggio == ""){
			$("#messaggio").val("Campo obbligatorio");
			$("#messaggio").css("color","red");
			check = false;
		}
		if(check){
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			if(!emailReg.test(mail)){
				alert("Inserire un'email valida!");
				return false;
			}
			else{
				return true;
			}
		}
		else{
			alert("Compilare i campi obbligatori");
			return false;
		}
	});
	
});

