// JavaScript Document

function obbligatori_registrazione(){
	var c = 0;
	$("input[id*='---']").each(function(){
		if ($(this).attr("obbligatory") == "yes" && $(this).val() == ""){
			$(this).css("border","1px solid #FF0000");
			c++;
		}
	  });
	if (c == 0) {
		
		var str = $("#registrazione").serialize();
		$.ajax({
		  url: '/include/rpc.php',
		  dataType: 'json',
		  data: str,
		  success: function(ris) {
				if (ris[0].is_error) {
					alert(ris[0].message);
					return false;
				}
				else {
					document.getElementById("registrazione").submit();
					return false;
				}
		  }
		});
	}
	else {
		 alert('Campi obbligatori assenti');
		return false;
	}
	
}
function valida_username(){
	var str = $("#registrazione").serialize();
	$.ajax({
	  url: '/include/rpc.php',
	  dataType: 'json',
	  data: str,
	  success: function(ris) {
			if (ris[0].is_error) {
				alert(ris[0].message);
				return false;
			}
			else {
				//alert("OK");
				return true;
			}
	  }
	});
	return false;
}
function obbligatori_fase(){
	var c = 0;
	$("input[id*='---']").each(function(){
		if ($(this).attr("obbligatory") == "yes" && $(this).val() == ""){
			$(this).css("border","1px solid #FF0000");
			c++;
		}
	  });
	
	if (c == 0) return true;
	else {
		 alert('Campi obbligatori assenti');
		return false;
	}
}

