$(document).ready(function() {
   
   $(".campo-calendario").calendar({
      autoPopUp: "button",
      speed: "fast",
      buttonImageOnly : true,
      buttonImage : "images/bt-calendario.gif"
   });
   
   /*$(".campo-calendario").mask("99/99/9999",{placeholder:" "});*/
   
   $(".link-modal").click(function () {
       parent.document.location.href = $(this).attr("href");
       return false;
   });
      
   $('.conteudo-aba').hide();
   $('.conteudo-aba:first').show();
   $('.aba').click(function(){
      $('.conteudo-aba').hide();
      $('.listagem-abas2').children('li').removeAttr('class');
      $('.listagem-abas1').children('li').removeAttr('class');
      $(this).parent('li').attr('class', 'ativo');
      $('#conteudo-'+$(this).attr('id')).show();
   });
   
   $("#formulario-cadastro-de-pessoa-fisica").RSV({
        errorFieldClass: "form-erro",
        rules:
        [
          "required,usuario,Usuário",
          "required,senha,Senha",
          "required,confirmar_senha,Confirmar Senha",
          "same_as,senha,confirmar_senha,Senha de confirmação esta diferente",
          "required,nome,Nome",
          "required,data_de_nascimento,Data de Nascimento",
          "required,sexo,Sexo",
          "required,cpf,CPF",
          "required,rg,RG",
          "required,email,E-mail",
          "required,prefixo,Telefone - Prefixo",
          "required,telefone,Telefone - Numero",
          "required,endereco,Endereço",
          "required,bairro,Bairro",
          "required,cidade,Cidade",
          "required,cep,CEP"
        ]
   });
   
   $(".itens-pag").change(function () {
      
      var link = document.location.href;
      var posItensPag = 0;
      
      if ((posItensPag = link.indexOf("&itens_pag")) > 0) {
         var txtRemover = link.substr(posItensPag, link.indexOf("&", posItensPag));
         link = link.replace(txtRemover, "");
      }
      
      document.location.href = link +"&itens_pag="+ $(this).val() +'&pag=1';
   });

   $(".clear-form").click(function () {
      $(this).parents("form").clearForm();
   });

});


/*
 *
 * FORMATAÇÃO DE NÚMEROS
 *
 */

function floatToMoeda(numero) {
   numero += '';
   numero  = numero.replace(".",",");
   
   if (numero.indexOf(",")<0) {
      numero += ",00";
   } else if (numero.indexOf(",") == numero.length-2) {
      numero += "0";
   }
   
   return numero;
}

function moedaToFloat(moeda){
   moeda += '';
   moeda  = moeda.replace("R$ ","");
   moeda  = moeda.replace(".","");
   return parseFloat(moeda.replace(",","."));
}

function arredonda(valor) {
   return (Math.round(parseFloat(valor) * 100))/100;
}



$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};