
// Função para retirar o loading do Topo somente ao finalizar uma conclusão
function pauseLoadingTop() {
  $(".father_line_loading").css({
    "opacity": "0",
    "pointer-events": "none",
    "transition-duration": "0.1s"
  })
  $(".filter_loading").css({
    "opacity": "0",
    "pointer-events": "none"
  })
}
// Função de chamada e encerramento de um loading
function loadingPush() {
  // SE FOR O FIM DO LOADING EXECUTAR AS SAIDAS
  $(".father_line_loading").css({
    "opacity": "1",
    "pointer-events": "all",
    "transition-duration": "0s"
  })
  $(".filter_loading").css({
    "opacity": "0.4",
    "pointer-events": "all"
  })
}
window.addEventListener("load", function() {
  $(".phone").mask("(00) 0 0000-0000");
  $(".cpf").mask("000.000.000-00");
});
document.getElementById("first_form").addEventListener("submit", function() {
  var elementForm = this;
  boxAlertUser = document.getElementById("alert_user");
  textBoxAlertUser = document.getElementById("text_alert");
  textBoxAlertUser.innerHTML = '';
  boxAlertUser.style.display = "none";
  loadingPush();
  setTimeout(function () {
    if (validForm(elementForm)) {
      var formLoginClient = new FormData(elementForm);
      if (typeof formLoginClient == 'object') {
        $.ajax({
          url: absolute_url_js + "scripts/script_entrar.php",
          type: 'POST',
          data: formLoginClient,
          success: function (dataResponse) {
            if (dataResponse.status_response == 'erro') {
              textBoxAlertUser.innerHTML = dataResponse.message_response;
              boxAlertUser.style.display = "flex";
            }else{
              if(typeof dataResponse.header_login != "undefined"){
                location.href = absolute_url_js+dataResponse.header_login;
              }else{
                location.href = absolute_url_js;
              }
            }
          },
          contentType: false,
          processData: false
        });
        delete window.formLoginClient;
      } else {
        textBoxAlertUser.innerHTML = 'Ocorreu um erro ao enviar seus dados.';
        boxAlertUser.style.display = "flex";
      }
    }
    pauseLoadingTop();
  }, 1000);
});
$('input[required=true], input[data-inputType]').on('change', function() {
  firstInputWrong = false;
  validInput(this);
});

document.querySelector(".toggle_view").addEventListener("click", function(){
  var fatherElement = this.parentNode;
  var inputElement = fatherElement.querySelector("input");
  var currentType = inputElement.type;
  var newType = (currentType == "password") ? "text" : "password";

  inputElement.type = newType;
});