
 function mysubmit()

  {  
  
var valid = 1;
var nome = $("#tr1").val();
var cognome = $("#tr2").val();
var email = $("#tr3").val();
var commento = $("#tr4").val();
var value = $("#tr5").val();

var datastr ="&nome=" + nome + " " + cognome + "&email=" + email + "&commento=" + commento;



if (nome.length<4) {
//alert(nome);
$("#contattierrorenome").css({"background-image" : "url(/Immagini/foglio1/errorecontatti.png)", "display" : "block"});

valid = 0;
//alert(valid);
}
else {

$("#contattierrorenome").css({"display" : "none"});
valid = 1;
//alert(valid + 'nome');
}



if (cognome.length<4) {
//alert("ok.");
$("#contattierrorecognome").css({"background-image" : "url(/Immagini/foglio1/errorecontatti.png)", "display" : "block"});

valid = 0;
}
else {
//alert("ok.");
$("#contattierrorecognome").css({"display" : "none"});
valid = 1;

}

if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
//alert("ok.");
$("#contattierroreemail").css({"background-image" : "url(/Immagini/foglio1/errorecontatti.png)", "display" : "block"});

valid = 0;
}
else {
//alert("ok.");
$("#contattierroreemail").css({"display" : "none"});
valid = 1;

}


if ((commento.length<10)  & (valid == 1)) {
	if (value==1){
	alert("Inserire Il commento!");
	//alert(value);
	}else{
	alert("Insert comment!");
	}
valid = 0;
}





//alert(datastr);

if (valid == 1) {
//alert(datastr);
send(datastr, value);
}

	
	   
	   
	   
	   
	}
	/*  
  }//*/

  function send(datastr, value){



$.ajax({
  type: "POST",
  url: "/Php_Script/mail.php",
  data: datastr,
    error: function(html){ // Sull'errore invoco una funzione
        alert("Si è verificato un errore. Riprovare più tardi, se il problema persiste contattare il webmaster alla seguente email");
	$("#home1").load("/Php_Script/home.php");
    },

  success: function(html){
	if (value==1){
	 alert("Messaggio inviato correttamente, la risponderemo al più presto.");
	$("#home1").load("/Php_Script/home.php");
	//alert(value);
	}else{
	 alert("Message sent successfully, the answer as soon as.");
	$("#home1").load("/English/Php_Script/home.php");
	}
   
  }
});

}

