/**
 * Translated default messages for the jQuery validation plugin.
 * Language: PT_BR
 * Translator: Francisco Ernesto Teixeira <fco_ernesto@yahoo.com.br>
 */
jQuery.extend(jQuery.validator.messages, {
	required: "Campo obrigat&oacute;rio.",
	remote: "Por favor, corrija este campo.",
	email: "Por favor, forne&ccedil;a um endere&ccedil;o eletr&ocirc;nico v&aacute;lido.",
	url: "Por favor, forne&ccedil;a uma URL v&aacute;lida.",
	date: "Por favor, forne&ccedil;a uma data v&aacute;lida.",
	dateISO: "Por favor, forne&ccedil;a uma data v&aacute;lida (ISO).",
	dateDE: "Bitte geben Sie ein gültiges Datum ein.",
	number: "Somente informe números.",
	numberDE: "Bitte geben Sie eine Nummer ein.",
	digits: "Por favor, forne&ccedil;a somente d&iacute;gitos.",
	creditcard: "Por favor, forne&ccedil;a um cart&atilde;o de cr&eacute;dito v&aacute;lido.",
	equalTo: "Por favor, forne&ccedil;a o mesmo valor novamente.",
	accept: "Por favor, forne&ccedil;a um valor com uma extens&atilde;o v&aacute;lida.",
	maxlength: jQuery.format("Por favor, forne&ccedil;a n&atilde;o mais que {0} caracteres."),
	minlength: jQuery.format("Por favor, forne&ccedil;a ao menos {0} caracteres."),
	rangelength: jQuery.format("Por favor, forne&ccedil;a um valor entre {0} e {1} caracteres de comprimento."),
	rangeValue: jQuery.format("Por favor, forne&ccedil;a um valor entre {0} e {1}."),
	range: jQuery.format("Por favor, forne&ccedil;a um valor entre {0} e {1}."),
	maxValue: jQuery.format("Por favor, forne&ccedil;a um valor menor que ou igual a {0}."),
	max: jQuery.format("Por favor, forne&ccedil;a um valor menor ou igual a {0}."),
	minValue: jQuery.format("Por favor, forne&ccedil;a um valor maior ou igual a {0}."),
	min: jQuery.format("Por favor, forne&ccedil;a um valor maior ou igual a {0}.")
});

jQuery.validator.addMethod(
	"datePTBR", 
	function isDate(str) 
	{
		if (str.length != 10)
		{
			return false;
		}
		
		for (j=0; j<str.length; j++) 
		{
			if ((j == 2) || (j == 5)) 
			{
				if (str.charAt(j) != "/") 
				{ 
					return false;
				}
			}
			else 
			{
				if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) 
				{ 
					return false;
				}
			}
		}
		
		var day = str.charAt(0) == "0" ? parseInt(str.substring(1,2)) : parseInt(str.substring(0,2));
		var month = str.charAt(3) == "0" ? parseInt(str.substring(4,5)) : parseInt(str.substring(3,5));
		var begin = str.charAt(6) == "0" ? (str.charAt(7) == "0" ? (str.charAt(8) == "0" ? 9 : 8) : 7) : 6;
		var year = parseInt(str.substring(begin, 10));
		
		if (day == 0) 
		{ return false;}
		if (month == 0 || month > 12) 
		{ return false;}
		if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) 
		{
			if (day > 31) 
			{ 
				return false;
			}
		} 
		else 
		{
			if (month == 4 || month == 6 || month == 9 || month == 11) 
			{
				if (day > 30) 
				{ 
					return false;
				}
			} 
			else 
			{
				if (year%4 != 0) 
				{
					if (day > 28) 
					{ 
						return false;
					}
				} 
				else 
				{
					if (day > 29) 
					{
						return false;
					}
				}
			}
		}
		return true;
	}
	, "Por favor, forne&ccedil;a uma data v&aacute;lida.");

jQuery.validator.addMethod(
	"cpf", 
	function (s){
		var i;
		var c = s.substr(0,9);
		var dv = s.substr(9,2);
		var d1 = 0;
		for (i = 0; i < 9; i++){d1 += c.charAt(i)*(10-i);}
		if (d1 == 0){return false;}
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(0) != d1){ return false;}
		d1 *= 2;
		for (i = 0; i < 9; i++) {d1 += c.charAt(i)*(11-i);}
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(1) != d1){ return false;}
		return true;
	} , 
	"Cpf inv&aacute;lido."
);

jQuery.validator.addMethod(
	"numeric", 
	function sss (input){
	    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
	    return (RE.test(input));
	}, 
	"Digite um numero v&aacute;lido."
);

