 $(document).ready(function(){	
							
	$('.tonus').tooltip({
		delay: 0,
		showURL: false,
		showBody: " - ",
		extraClass: "right fonte_menor"
	});
	
	
});

function customRange(input) {
	return {minDate: (input.id == "dataFinal" ? $("#dataInicial").datepicker("getDate") : null),
		maxDate: (input.id == "dataInicial" ? $("#dataFinal").datepicker("getDate") : null)};
} 
 
function carregaFuncao(idarea,idfuncao) {
	if(idarea) {
		$('select[@name=idarea_interesse_opcao]').html('<option value="sda">Buscando funções, aguarde ... </option>');
                $.post('passo_2_obj_profissionais_funcao.php', 
			{idarea : idarea, idfuncao : idfuncao}, 
			function(resposta){
				$('select[@name=idarea_interesse_opcao]').html(resposta);
			}
			
		);
	}
}
 
function validaFormulario(form) {
	$.metadata.setType("attr", "validate");
							 
	$("input.data").keypress(function() {return false});
    $("#dataInicial").datepicker({yearRange: "-100:+0", beforeShow: customRange,dateFormat: "dd/mm/yy"});
	$("#dataFinal").datepicker({yearRange: "-50:+50", beforeShow: customRange,dateFormat: "dd/mm/yy"});
    $(".data").datepicker({yearRange: "-100:+0", dateFormat: "dd/mm/yy"});
	
 	
	jQuery.validator.addMethod("password", function( value, element ) {
		var result = this.optional(element) || value.length >= 4;
		if (!result) {
			element.value = "";
			var validator = this;
			setTimeout(function() {
				validator.blockFocusCleanup = true;
				element.focus();
				validator.blockFocusCleanup = false;
			}, 1);
		}
		return result;
	}, "Sua senha deve conter pelo menos 6 caracteres, sendo obrigatório pelo menos 1 letra e 1 número.");
	
	jQuery.validator.addMethod("cpf", function( value, element ) {
		var result = isCpf(element.value)
		if(!result) {
			element.value = "";
			var validator = this;
			setTimeout(function() {
				validator.blockFocusCleanup = true;
				//element.focus();
				validator.blockFocusCleanup = false;
			}, 1);
		}
		return result;
	}, "CPF Incorreto. Digite Novamente");	

	jQuery.validator.addMethod("data", function( value, element ) {
		if(element.value.length > 5 && element.value != '__/__/____') {
			var result = validaData(element)
			if(!result) {
				element.value = "";
				var validator = this;
				setTimeout(function() {
					validator.blockFocusCleanup = true;
					//element.focus();
					validator.blockFocusCleanup = false;
				}, 1);
			}
		}
		else
			return true;
		return result;
	}, "Data Inv&aacute;lida. Digite Novamente.");	
	
	// a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
	jQuery.validator.addMethod("defaultInvalid", function(value, element) {
		return value != element.defaultValue;
	}, "");
	
	jQuery.validator.messages.required = "";
	
	
		$('form').bind("invalid-form.validate", function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'Foi encontrado 1 campo n&atilde;o preenchido. Verifique a marca&ccedil;&atilde;o em Vermelho'
					: 'Foram encontrados ' + errors + ' campos n&atilde;o  preenchidos. Verifique a marca&ccedil;&atilde;o em Vermelho';
				alert('Foram Encontrados Campos Obrigatórios não preenchidos. Verifique antes de continuar.')
				$("form div.error span").html(message);
				$("form div.error").show();
			} else {
				$("form div.error").hide();
			}
		}).validate({
			//focusInvalid: false,
			//focusCleanup: true,
			onkeyup: false,
			messages: {
				password2: {
					required: " ",
					equalTo: "Digite a senha conforme o campo SENHA"	
				},
				email: {
					required: " ",
					email: "Digite um e-mail v&aacute;lido: Por exemplo: nome@seudominio.com",
					remote: jQuery.format("{0} este e-mail j&aacute; existe em nosso banco de dados, digite um diferente.")	
				}
			},
			debug:false
		});

	
  $(".resize").vjustify();
  $("div.buttonSubmit").hoverClass("buttonSubmitHover");
  $("div.buttonCancel").hoverClass("buttonCancelHover");

  if ($.browser.safari) {
    $("body").addClass("safari");
  }
  
  $("input.telefone").mask("(99) 9999-9999");
  $("input.cep").mask("99.999-999");
  $("input.cpf").mask("999.999.999-99");
  //$("input.data").mask("99/99/9999");
  //$("input.data_hora").mask("99/99/9999 99:99:99");
  $("input.cnpj").mask("99.999.999/9999-99");

	$("input.moeda").keyup(
		function() {
			var strSemMascara;
			var numContador;
			var numero;
		
			strSemMascara = this.value
			TamDig = strSemMascara.length
			numContador = 0;
			numero = "";
			for (i = TamDig; (i >= 0); i--){
				if ((parseInt(strSemMascara.substr(i,1))>=0) && (parseInt(strSemMascara.substr(i, 1))<=9)){
					numContador++;
					if ((numContador == 3) && ((TamDig -i) < 5)){
						numero = ","+numero;numContador = 0;
					}
					else 
						if (numContador == 3){
							numero = "."+numero;numContador = 0;
					}
					numero = strSemMascara.substr(i, 1)+numero;
				}
			}
			
			TamDig = numero.length;
			//remove os zeros a esquerda
			for (i=TamDig-1;(i>=0);i--){
				if (((numero.substr(0,1) == "0")||(numero.substr(0,1) == "."))&&(numero.length!=4)){
					numero= numero.substr(1,numero.length-1);
				}
				else{
					break
				}
			}			
				
			this.value = numero
		}
	);


}; 
 

$.fn.vjustify = function() {
    var maxHeight=0;
    $(".resize").css("height","auto");
    this.each(function(){
        if (this.offsetHeight > maxHeight) {
          maxHeight = this.offsetHeight;
        }
    });
    this.each(function(){
        $(this).height(maxHeight);
        if (this.offsetHeight > maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight)));
        }
    });
};

$.fn.hoverClass = function(classname) {
	return this.hover(function() {
		$(this).addClass(classname);
	}, function() {
		$(this).removeClass(classname);
	});

};
