$(function(){
	$('form').submit(function(){
		 err = 0;
		 if($("#nick", this).val().length == 0) {
		 	$("#nick", this).next().show();
			err++;
		 } else {
		 	$("#nick", this).next().hide();
		 }
		 if($("#email", this).val().length == 0 || !isEmail($("#email", this).val())) {
		 	$("#email", this).next().show();
			err++;
		 } else {
		 	$("#email", this).next().hide();
		 }
		 if(!$("#privacy", this).attr("checked")) {
		 	$("#privacy", this).parent().parent().next().show();
			err++;
		 } else {
		 	$("#privacy", this).parent().parent().next().hide();
		 }
		 if($("#testo", this).val().length == 0){
			$("#testo", this).next().show();
		 } else {
		 	$("#testo", this).next().hide();
		 }
		 if(err) return false;
	});
});
function isEmail (s){   
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")){ 
	i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")){ 
		i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

