$(document).ready(function(){
	
	$(".simpleValidator").submit(function() 
	{
		var errors = "";
		
		// Miramos Campos marcados con no-empty --> No pueden estar vacios
		var noEmpty = $(".simpleValidator .no-empty");
		for(i=0;noEmpty[i];i++)
		{
			var input = $(noEmpty[i]);
			if ( input.val() == "" )
			{
				if ( !input.attr("rel") )
				{
					errors += " - El campo" + input.attr("name") + " es obligatorio y debe rellenarlo.\n";
				}
				else
				{
					errors += " - " + input.attr("rel") + ".\n";
				}
			}
		}
		
		
		// Miramos bloques marcados con one-of-this --> Dentro, los checkbox y radios que haya
		// deberán tener al menos uno seleccionado.
		var oneOfThis = $(".simpleValidator .one-of-this");
		for(i=0;oneOfThis[i];i++)
		{
			var checks = $(oneOfThis[i]);
			if ( checks.find("input:checked").length < 1)
			{
				if ( !checks.attr("rel") )
				{
					errors += " - Debe elegir una de las opciones.\n";
				}
				else
				{
					errors += " - " + checks.attr("rel") + ".\n";
				}
			}
		}

		
		// Printamos errores y bloqueamos o permitimos el envio
		if ( errors != "" )
		{
			alert( "Se encontraron los siguientes errores en el formulario:\n\n"+errors );
			return false;
		}
		else
		{
			return true;
		}
		
		
	});
	
	
	
	
})
