function validateForm($form)
{
	$('.fieldnote .text').html("");
	$('.fieldnote').fadeOut();
	var err = {};
	
	$("INPUT,TEXTAREA", $form).each( function() {
		
		if ($(this).attr("validate"))
		{
			validate = $(this).attr("validate").split(",");
			for (i=0; i<validate.length; i++)
			{
				id = $(this).attr("id");
				errstr = "";
				
				if (validate[i].indexOf("[")>-1)
				{
					param = validate[i].substring(validate[i].indexOf("[")+1, validate[i].indexOf("]"));
					validate[i] = validate[i].substring(0, validate[i].indexOf("["));
				}
				
				if ($(this).attr("type").toLowerCase() == "text" || $(this).attr("type").toLowerCase() == "hidden" || $(this).attr("type").toLowerCase() == "textarea" || $(this).attr("type").toLowerCase() == "password")
					switch (validate[i])
					{
						case "required":
							if(!$(this).val().replace(/^\s+|\s+$/g,"").replace(/(\r\n|[\r\n])/g, "") || $(this).val().replace(/^\s+|\s+$/g,"").replace(/(\r\n|[\r\n])/g, "") == "")
							{
								errstr = 'Compila il campo';
							}
							break;
						case "numeric":
							var is_numeric = /^[0-9]+$/.test($(this).val());
							if(!is_numeric) errstr = 'Numero non valido';
							break;
						case "float":
							var is_float = /^[0-9|,]+$/.test($(this).val());
							if(!is_float) errstr = 'Numero non valido';
							break;
						case "email":
							var is_email = /^[_a-z0-9-]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/.test($(this).val().toLowerCase());
							if(!is_email) errstr = 'Email non valida';
							break;
						case "length":
							n = param.substring(2)*1;
							if (param.substring(0,2)=="gt" && $(this).val().length <= n)
							{
								errstr = 'Questo campo dev\'essere di almeno '+(n+1)+' caratteri';
							}
							else if (param.substring(0,2)=="lt" && $(this).val().length >= n)
							{
								errstr = 'Questo campo dev\'essere di non più di '+(n-1)+' caratteri';
							}
							else if (param.substring(0,2)=="eq" && $(this).val().length != n)
							{
								errstr = 'Questo campo dev\'essere di '+n+' caratteri';
							}
							break;
						case "c":
							if ($(this).val() != $("#"+$(this).attr("id").replace("_c", "")).val())
							{
								errstr = 'Campo non confermato';
							}
							break;
					}
				else if ($(this).attr("type").toLowerCase() == "checkbox")
				{
					switch (validate[i])
					{
						case "required":
							if(!$("#"+id+":checked").val() || $("#"+id+":checked").val() == "")
							{
								errstr = 'Accetta';
							}
							break;
					}
				}
				else if ($(this).attr("type").toLowerCase() == "radio")
					switch (validate[i])
					{
						case "required":
							if(!$("INPUT[@name='"+$(this).attr("name")+"']:checked").val() || $("INPUT[@name='"+$(this).attr("name")+"']:checked").val() == "")
							{
								errstr = 'Seleziona';
							}
							break;
					}
				if (errstr!="")
				{
					if ($(this).attr("err")!=undefined && $(this).attr("err")!="") errstr = $(this).attr("err");
					eval("err."+id+" = errstr;");
					break;
				}
			}
		}
	});

	returnval = true;
	$.each(err, function(i,o)
	{
		$parent = $('#'+i).parent();
		if ($parent.hasClass('custom-checkbox') || $parent.hasClass('custom-radio')) $parent = $parent.parent();
		$(".fieldnote .text", $parent).html(o);
		$(".fieldnote", $parent).fadeIn();
		returnval = false;
	})
	return returnval;
}
