$(document).scroll(function () { var y = $(this).scrollTop(); if (y > 169) { $('.navbar-fixed-top').fadeIn(); } else { $('.navbar-fixed-top').fadeOut(); } }); function toJSONString(form) { var obj = {}; var elements = form.querySelectorAll("input, select, textarea"); for (var i = 0; i < elements.length; ++i) { var element = elements[i]; var name = element.name; var value = element.value; if (name) { obj[ name ] = value; } } return JSON.stringify(obj); } $(document).ready(function () { $('#tipoMostra').change(function () { document.location.href = document.location.pathname + '/?ORDER=' + $(this).val(); }); $('.temFrete').hide(); $('.loadingPage').hide(); var pasta = document.location.pathname.split('/')[1]; var produto = document.location.pathname.split('/')[2]; $('.comboMarca').change(function () { var marca = $(this).find(":selected"); document.location = '/produto/' + marca.val() + '/' + convertToSlugUrl(marca.attr("data-nome")); }); $('.cep').mask("99999-999"); if (pasta === 'produto' || pasta === 'checkout' || pasta === 'cadastro' || pasta === 'minha-conta') { $('.cep').mask("99999-999"); if (localStorage.getItem("cepDestino") !== '') { $('.cepDestino').val(localStorage.getItem("cepDestino")); } $('.cnpj').mask("99.999.999/9999-99"); } if (pasta === 'paymentMethod') { $('.loadingPage').show(); window.onload = function () { $('.loadingPage').hide(); }; } $('.form-contato').on('submit', function (e) { e.preventDefault(); $('.help-block').html(""); // var nome = $('.nome'); var email = $('.email'); var telefone = $('.telefone'); var pedido = $('.pedido'); var mensagem = $('.mensagem'); if (nome.val() === '') { $('.help-nome').html("Informe o seu nome"); } else if (email.val() === '' || !ValidaEmail(email.val())) { $('.help-email').html("Verifique o seu e-mail"); } else if (mensagem.val() === '') { $('.help-mensagem').html("Escreva sua mensagem"); } else { $('.loading').show(); $.post('/util/Util.php', { nome: nome.val(), email: email.val(), telefone: telefone.val(), pedido: pedido.val(), mensagem: mensagem.val(), acao: 'email-contato' }, function (data) { console.log(data); if (data === 'ok') { $('.form-control').val(""); $('.loading').html("E-mail enviado com sucesso. Aguarde nosso retorno."); } }); } }); $('.addCarrinho').submit(function (e) { e.preventDefault(); var dados = { 'acao': 'addCarrinho', 'data': $.parseJSON(toJSONString(this)) }; $.post('/util/Util.php', dados, function (data) { console.log(data); $('.circulo_cart').text(data); }); }); if (pasta === 'shippingMethod') { var cep = $('.cepDestino').val(); getFrete(cep, '', 1); } if (produto === 'loginError' && pasta === 'login') { alert('Dados Incorretos'); $('.emailLogin').focus(); } $('#qtdCart').blur(function () { $('.loadingPage').show(); }); $('.cep').on('blur', function () { if ($(this).val() !== '') { getEndereco($(this).val()); } }); $('.tipoFisica').click(function () { $('.label-nome').text('Nome Completo*:'); $('.label-cpfcnpj').text('CPF*:'); $('.label-rg').text('RG:'); $('.cpfcnpj').removeClass('cnpj'); $('.cpfcnpj').addClass('cpf'); $('.cpfcnpj').mask("999.999.999-99"); $('.juridica').hide(); $('.fisica').show(); $('.tipoCadastro').val("F"); }); $('.tipoJuridica').click(function () { $('.label-nome').text('Razão Social*:'); $('.label-rg').text('Inscrição Estadual:'); $('.label-cpfcnpj').text('CNPJ*:'); $('.cpfcnpj').removeClass('cpf'); $('.cpfcnpj').addClass('cnpj'); $('.cpfcnpj').mask("99.999.999/9999-99"); $('.fisica').hide(); $('.juridica').show(); $('.tipoCadastro').val("J"); }); $('[data-toggle="popover"]').popover({ html: true, trigger: "hover" }); $('.senhaCadastro').on('blur', function () { $('.verificaSenha').html(""); if ($(this).val().length <= 5 || $(this).val().length >= 9) { $('.verificaSenha').html('Sua senha deve conter entre 6 e 8 dígitos'); } }); $('.nome-cliente').on('blur', function () { $('.help_nome_cliente').html(''); var nome = $(this).val(); if (nome.split(' ').length > 1) { } else { $('.help_nome_cliente').html(' Informe seu nome completo.'); } }); $('.senhaConfirma').on('blur', function () { if ($(this).val() !== $('.senhaCadastro').val()) { $('#confirmar').html(' Confira sua senha.').css('color', 'red'); $(this).css('border-color', 'red'); } else { $('#confirmar').html(' Senhas Conferem.').css('color', 'green'); $(this).css('border-color', 'green'); } }); $('.calculaFrete').click(function () { var carrinho = null; if (pasta === 'checkout') { carrinho = 1; } else { carrinho = 0; } getFrete($('.cepDestino').val(), produto, carrinho); }); if (localStorage.getItem('tipoLista') === '1') { $('#tipoLista').click(); } if (localStorage.getItem("tipolista") === 'C' && pasta !== 'produto' && pasta !== '') { $(this).css('font-weight', 'bold'); $('.tipoGrade').css('font-weight', 'normal'); $('.grid').removeClass('col-md-3'); $('.grid').removeClass('col-md-4'); $('.grid').addClass('col-md-12 lista'); $('.imagem').css('float', 'left'); $('.textos-grade-produtos p').css('font-size', '14px'); $('.img-grid').css('max-width', '230px'); $('.textos-grade-produtos').css('float', 'left').css('margin-left', '20px'); $('.aplicacao').css('font-size', '12px !important').css('font-weight', 'normal').css('line-height', '30px;'); localStorage.setItem("tipoLista", '1'); } else { $(this).css('font-weight', 'bold'); $('.tipoLista').css('font-weight', 'normal'); $('.grid').removeClass('col-md-12 lista'); $('.grid').addClass('col-md-3'); $('.imagem').css('float', 'none'); $('.textos-grade-produtos p').css('font-size', '12px'); //$('.img-grid').css('max-width', '210px'); $('.textos-grade-produtos').css('float', 'none').css('margin-left', '0px').css('width', '100%'); localStorage.setItem("tipoLista", '2'); } $('.tipoLista').click(function () { $(this).css('font-weight', 'bold'); $('.tipoGrade').css('font-weight', 'normal'); $('.grid').removeClass('col-md-3'); $('.grid').addClass('col-md-12 lista'); $('.imagem').css('float', 'left'); $('.textos-grade-produtos p').css('font-size', '14px'); $('.img-grid').css('max-width', '230px'); $('.textos-grade-produtos').css('float', 'left').css('margin-left', '20px').css('width', '200px'); $('.aplicacao').css('font-size', '12px !important').css('font-weight', 'normal').css('line-height', '30px;'); $('.codigos').hide(); localStorage.setItem("tipoLista", '1'); }); $('.tipoGrade').click(function () { $(this).css('font-weight', 'bold'); $('.tipoLista').css('font-weight', 'normal'); $('.grid').removeClass('col-md-12 lista'); $('.grid').addClass('col-md-3'); $('.imagem').css('float', 'none'); $('.textos-grade-produtos p').css('font-size', '12px'); //$('.img-grid').css('max-width', '210px'); $('.textos-grade-produtos').css('float', 'none').css('margin-left', '0px').css('width', '100%'); $('.codigos').show(); localStorage.setItem("tipoLista", '2'); }); $('.newPass').on('blur', function () { if ($(this).val().length < 6 || $(this).val().length > 8) { $('.help-newPass').html("Sua senha deve conter de 6 a 8 caracteres"); $(this).val(""); } else { $('.help-newPass').html(""); } }); $('.ConfirmNewPass').on('blur', function () { if ($(this).val() !== $('.newPass').val()) { $('.help-ConfirmNewPass').html("As senhas não conferem"); $(this).val(""); } else { $('.help-ConfirmNewPass').html(""); } }); $('.changePass').click(function () { if ($('.newPass').val() === '') { $('.help-newPass').html("Informe sua nova senha"); } else if ($('.ConfirmNewPass').val() === '') { $('.help-ConfirmNewPass').html("Confirme sua senha"); } else if ($('.newPass').val() !== $('.ConfirmNewPass').val()) { $('.loading').html("As senhas não conferem"); } else { $('.loading').html('
'); $('.form-troca-senha').submit(); } }); $('#radioBtn a').on('click', function () { var sel = $(this).data('title'); var tog = $(this).data('toggle'); $('#' + tog).prop('value', sel); $('a[data-toggle="' + tog + '"]').not('[data-title="' + sel + '"]').removeClass('active').addClass('notActive'); $('a[data-toggle="' + tog + '"][data-title="' + sel + '"]').removeClass('notActive').addClass('active'); if (sel === 'J') { $('.juridico').show(); $('.fisico').hide(); } else { $('.fisico').show(); $('.juridico').hide(); } }); $('.senhaCadastro').keyup(function () { var char = $(this).val().length; $('.digitos').html(char); }); $('.cpf').on('blur', function () { if ($(this).val().length === 11) { //000.000.000-00 if (!validarCPF($(this).val())) { $('.grupoCpf').addClass('has-error'); $('.erroCPF').html('Verifique o seu documento'); $(this).val(""); $(this).unmask(); } else { $('.grupoCpf').removeClass('has-error'); $('.erroCPF').html(''); } } else if ($(this).val().length === 14) { //00.000.000/0000-00 if (!validarCNPJ($(this).val())) { $('.grupoCpf').addClass('has-error'); $('.erroCPF').html('Verifique o seu documento'); $(this).val(""); $(this).unmask(); } else { $('.grupoCpf').removeClass('has-error'); $('.erroCPF').html(''); } } }); $('.data').on('blur', function () { if (!validaData($(this).val())) { $('.grupoData').addClass('has-error'); $('.erroDATA').html('Data incorreta'); } else { $('.grupoData').removeClass('has-error'); $('.erroDATA').html(''); } }); $('.telefone').on('blur', function () { if ($(this).val().length === 10) { $(this).mask("(99)9999-9999"); $('.erroTELEFONE').html(''); } else if ($(this).val().length === 11) { $(this).mask("(99)99999-9999"); $('.erroTELEFONE').html(''); } else { if ($(this).val() === '') { $(this).val(""); $(this).unmask(); } } }); $('.btn-pagseguro').click(function () { $('#gw_id').val(1); $('.finalizarPagamento').fadeIn(); }); $('.btn-mercadopago').click(function () { $('#gw_id').val(2); $('.finalizarPagamento').fadeIn(); }); $('.palavraBuscaInput').keydown(function (event) { if (event.keyCode === 13) { if ($(this).val() === '') { alert('Digite sua busca'); $(this).focus(); } else { redirecionaURL($(this).val()); } } }); $('.palavraBuscaBtn').click(function () { if ($('#pesquisaMobile').val() === '') { alert('Digite sua busca'); $('#palavra').focus(); } else { redirecionaURL($('#pesquisaMobile').val()); } }); $('.cpfcnpj').on('blur', function () { if ($('.cpfcnpj').val().length === 11) { if (validarCPF($(this).val())) { $(this).mask('999.999.999-99'); } else { $(this).unmask(); } } else if ($('.cpfcnpj').val().length === 14) { if (validarCNPJ($(this).val())) { $(this).mask('99.999.999/9999-99'); } else { $(this).unmask(); } } else { $(this).unmask(); } }); $('.cad_news').click(function () { if ($('.nomeNews').val() === '') { alert('Informe seu nome'); $('.nomeNews').focus(); } else if (!ValidaEmail($('.emailNews').val())) { alert('Confira seu e-mail'); $('.emailNews').focus(); } else { $('.loadingNews').html("Cadastrando dados. Aguarde ..."); $.post('/Util/Util.php', { acao: 'cadNews', nome: $('.nomeNews').val(), email: $('.emailNews').val() }, function (data) { if (data === 'ok') { $('.loadingNews').html("Dados cadastrados com sucesso!"); setTimeout(function () { $('.loadingNews').html(""); }, 2000); } else { $('.loadingNews').html("Erro ao cadastrar os dados ..."); } $('.nomeNews').val(""); $('.emailNews').val(""); }); } }); $('.continuar').hide(); $('.trocar-senha').submit(function (e) { $('.msg').hide(); mensagem("info", " Aguarde ..."); e.preventDefault(); var senha = $('.senha').val(); var senhac = $('.consenha').val(); var texto = ''; if (senha === '') { texto = 'Informe sua senha'; senha.focus(); } else if (senhac === '') { texto = 'confirme sua senha'; mensagem('danger', texto); senhac.focus(); } else if (senha !== senhac) { texto = 'confira suas senhas. Elas não são iguais'; mensagem('danger', texto); } else if (senhac.length < 6) { texto = 'confira sua senha, ela deve ter de 6 a 8 dígitos'; mensagem('danger', texto); } else { $.post('/util/Util.php', { acao: "troca-senha", senha: senhac, cliente: $('.cliente').val() }, function (data) { if (data) { texto = " Senha alterada com sucesso"; mensagem('success', texto); $('button').hide(); $('.continuar').show(); } else { texto = "Erro ao alterar a senha, tente novamente mais tarde."; mensagem('danger', texto); } }); } }); $('.sendPass').click(function () { }); $('.trocaEndereco').click(function () { if ($('.cep').val() === '') { $('.helpcep').html("Informe seu cep"); } else if ($('.rua').val() === '') { $('.help-rua').html("Informe seu endereço"); } else if ($('.numero').val() === '') { $('.help-numero').html("Informe o seu número"); } else if ($('.bairro').val() === '') { $('.help-bairro').html("Informe o seu bairro"); } else if ($('.cidade').val() === '') { $('.help-cidade').html("Informe sua cidade"); } else if ($('.estado').val() === '') { $('.help-estado').html("Informe Estado"); } else { $('.help-block').html(""); $('.loading').html('
'); $.post('/util/Util.php', { acao: 'atualizaEnderecoCliente', cep: $('.cep').val(), rua: $('.rua').val(), numero: $('.numero').val(), bairro: $('.bairro').val(), complemento: $('.complemento').val(), cidade: $('.cidade').val(), estado: $('.estado').val(), email: $('#email').val(), loja: localStorage.getItem("loja") }, function (data) { console.log(data); if (data === 'ok') { $('.cep').val(""); $('.rua').val(""); $('.numero').val(""); $('.bairro').val(""); $('.complemento').val(""); $('.cidade').val(""); $('.estado').val(""); $('.loading').html('
Endereço atualizado com sucesso!
'); setTimeout(function () { location.reload(); }, 2000); } }); } }); if (pasta === '') { $('.aplicacao').hide(); $('.codigos').hide(); } }); function getCarrinho() { var dados = { 'acao': 'getCarrinho' }; $.post('/util/Util.php', dados, function (data) { $('#prev-cart').html(data); }); } getCarrinho(); function mensagem(tipo, msg) { $('.msg').html('
' + msg + '
').show(); } function carregarDados() { var busca = $('#busca').val(); if (busca != "" && busca.length >= 2) { $.ajax({ url: "consulta.php", dataType: "json", data: { acao: 'consulta', parametro: $('#busca').val() }, success: function (data) { console.log(data); } }); } } function convertToSlugBusca(text) { console.log(text); return text.toString().toLowerCase() .replace(/\s+/g, '+') // Replace spaces with - .replace(/[^\w\-]+/g, '') // Remove all non-word chars .replace(/\-\-+/g, '+') // Replace multiple - with single - .replace(/^-+/, '') // Trim - from start of text .replace(/-+$/, ''); // Trim - from end of text } function convertToSlugUrl(Text) { return Text .toLowerCase() .replace(/ /g, '-') .replace(/[^\w-]+/g, '') ; } function adicionaItem(campo, multiplo) { $('.loadingPage').show(); var atual = $('#qtdCart' + campo).val(); var multiplo = multiplo; $('#qtdCart' + campo).val(""); $('#qtdCart' + campo).val(parseFloat(atual) + parseFloat(multiplo)); document.atualizaItem.submit(); } function autocomplete() { var dados = localStorage.getItem('prd'); $("#palavra").autocomplete({ source: dados }); console.log(dados); } function validaNome(str) { if (str.split(' ').length > 1) { return true; } else { return false; } } function removeItem(campo, multiplo) { $('.loadingPage').show(); var atual = $('#qtdCart' + campo).val(); var multiplo = multiplo; $('#qtdCart' + campo).val(""); $('#qtdCart' + campo).val(atual - multiplo); document.atualizaItem.submit(); } function redirecionaURL(palavra) { var str = palavra.split(" "); var wd = ""; for (i = 0; i < str.length; i++) { wd += str[i] + "+"; } document.location = "/busca/" + wd.substring(0, wd.length - 1); } function somaFrete(valor, tipo, prazo) { var totalNovo = parseFloat($('#valorTotal').val()) + parseFloat(valor); $('#totalCompra').html("R$ " + totalNovo.toFixed(2).replace(".", ",")); $('.tipoEntrega').html('' + tipo + ''); $('.valor_frete_final').html(valor.toFixed(2).replace(".", ",")); $('.prazoEntrega').html(prazo); $('.btn-pagar').removeAttr('disabled'); $('.freteValor').val(valor); $('.freteTipo').val(tipo); $('#prazoEntrega').val(prazo); } function getFrete(cep, produto, carrinho) { var pasta = document.location.pathname.split("/")[1]; var final = 'N'; if (pasta === 'shippingMethod') { final = 'S'; } if (cep !== '') { $('.temFrete').show(); $('.dadosFrete').html('
'); var url = 'https://viacep.com.br/ws/' + cep.replace('-', '') + '/json/'; $.get(url, function (data) { $.post('/util/Frete.php', { acao: 'getFrete', produto: produto, cep: data.cep, estado: data.uf, carrinho: carrinho, finalizacao: final }, function (data) { $('.dadosFrete').html(data); }); }); } } function ValidaEmail(email) { var txt = email; if ((txt.length !== 0) && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7))) { return false; } else { return true; } } function buscaEndereco() { if ($('.buscaRua').val() === '') { alert('Informe sua rua'); $('.buscaRua').focus(); } else if ($('.buscaCidade').val() === '') { alert('Informe sua Cidade'); $('.buscaCidade').focus(); } else if ($('.buscaEstado').val() === '') { alert('Informe seu Estado'); $('.buscaEstado').focus(); } else { $('.resultadoBuscaCep').html('
'); $.post('https://sistema.vipsystem.com.br/getcep/', { acao: 'getEndereco', rua: $('.buscaRua').val(), cidade: $('.buscaCidade').val(), estado: $('.buscaEstado').val() }, function (data) { $('.resultadoBuscaCep').html(data); }); } } function setCEP(cep) { $('.cepDestino').val(cep); $('#modalCep').modal('hide'); } function modalCEP() { $('.buscaRua').val(""); $('.buscaCidade').val(""); $('.buscaEstado').val(""); $('#modalCep').modal('show'); } function getEndereco(cep) { cep = cep.replace(/\D/g, ""); $('.helpcep').html(""); $.get('https://viacep.com.br/ws/' + cep + '/json/', function (valor) { $(".rua").val(valor.logradouro); $(".bairro").val(valor.bairro); $(".cidade").val(valor.localidade); $(".estado").val(valor.uf); }); }