setTimeout(function () { addScript('https://igorescobar.github.io/jQuery-Mask-Plugin/js/jquery.mask.min.js'); }, 500); addScript('https://unpkg.com/axios/dist/axios.min.js'); setTimeout(function () { var htmlLoad = '' + '
' + '
' + '
' + '

' + ' ' + '
' + '
' + '

' + '

' + ' ' + '

' + '
' + '
' + '
' + '
' + ' ' + '
  • ' + '
    ' + ' ' + '
    ' + ' ' + ' ' + ' Residêncial' + ' ' + '
    ' + '
    ' + '
  • ' + '
  • ' + '
    ' + ' ' + '
    ' + ' ' + ' ' + ' Comercial' + ' ' + '
    ' + '
    ' + '
  • ' + '
  • ' + '
    ' + ' ' + '
    ' + ' ' + ' ' + ' Industrial' + ' ' + '
    ' + '
    ' + '
  • ' + '
  • ' + '
    ' + ' ' + '
    ' + ' ' + ' ' + ' Rural' + ' ' + '
    ' + '
    ' + '
  • ' + ' ' + '
    ' + '
    ' + '
    ' + ' ' + '
    ' + '
    ' + ' ' + '
    ' + '
    ' + ' ' + '
    ' + ' ' + '
    ' + '
    ' + ' ' + '
    ' + '
    ' + ' ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + ' '; if (!$) { $ = jQuery; } $('#form-safe').html(htmlLoad); var frm = $('#generation_1506220 #form'); $('#back').on('click', function (e) { $('#generation_1506220 .content-first').fadeIn(), $('#generation_1506220 .content-success').fadeOut(); $('#generation_1506220 input[name=nome]').val(""); $('#generation_1506220 input[name=celular]').val(""); $('#generation_1506220 input[name=email]').val(""); $('#generation_1506220 input[name=tipoLead]').val(""); $('#generation_1506220 input[name=kwh]').val(""); }) frm.submit(function (e) { e.preventDefault(); let obj = { nome: $('#generation_1506220 input[name=nome]').val(), celular: $('#generation_1506220 input[name=celular]').val(), email: $('#generation_1506220 input[name=email]').val(), tipoLead: $('#generation_1506220 input[name=tipoLead]:checked').val(), kwh: $('#generation_1506220 input[name=kwh]').val() }; axios.post('https://cordeiroenergia.api.safeleads.app/api/Simulador/Externo?configId=26', obj) .then(function (response) { $('#generation_1506220 .content-first').fadeOut(), $('#generation_1506220 .content-success').fadeIn(); setTimeout(() => { var urlRedirect = ''; if (urlRedirect) { window.location.replace(urlRedirect); } }, 3000); }) .catch(function (error) { console.log(error); }); }); let type = $('.type'); type.hover(function (e) { $(this).css({ 'border-color': 'rgba(32, 39, 97,1)' }); }, function (e) { $(this).css({ 'border-color': 'rgba(32, 39, 97,0)' }); }); type.on('click', function (e) { type.removeClass('active'); $(this).addClass('active'); }); //Mascaras $("#cep").mask("99.999-999"); $("#cep").on('blur', function () { // Remove tudo o que não é número para fazer a pesquisa var cep = this.value.replace(/[^0-9]/g, ""); // Validação do CEP; caso o CEP não possua 8 números, então cancela // a consulta if (cep.length !== 8) { return false; } // A url de pesquisa consiste no endereço do webservice + o cep que // o usuário informou + o tipo de retorno desejado (entre "json", // "jsonp", "xml", "piped" ou "querty") var url = "https://viacep.com.br/ws/" + cep + "/json/"; // Faz a pesquisa do CEP, tratando o retorno com try/catch para que // caso ocorra algum erro (o cep pode não existir, por exemplo) a // usabilidade não seja afetada, assim o usuário pode continuar// // preenchendo os campos normalmente $.getJSON(url, function (dadosRetorno) { try { // Preenche os campos de acordo com o retorno da pesquisa $("#logradouro").val(dadosRetorno.logradouro); $("#bairro").val(dadosRetorno.bairro); $("#cidade").val(dadosRetorno.localidade); $("#uf").val(dadosRetorno.uf); } catch (ex) { //Mensagem de Erro } }); }); }, 1000); function addScript(src) { if (!isLoadedScript(src)) { var s = document.createElement('script'); s.setAttribute('src', src); document.body.appendChild(s); } } function isLoadedScript(src) { return document.querySelectorAll('[src="' + src + '"]').length > 0; }