function loadingX(el) { el = typeof el !== 'undefined' ? el : false; if(el) { path = HTTP+'/xpainel/imagens/loading.gif'; eval('$(\''+el+'\').html(\' \');'); } else { $('#loadingX').fadeIn(); } } function loadedX(el) { $('#loadingX').fadeOut(); } function alertX(str) { return alert(str); } function confirmX($questao) { return confirm($questao); } function getCaracteristicasSecundarias(caracteristicaPrimaria, produto) { $('#produtoQuantidade').html(''); $( "#caracteristicaSecundaria").html(''); if(caracteristicaPrimaria == '') { return false; } $( "#caracteristicaSecundaria").html(''); $.get( "xpainel/lib/ajax.php?function=getCaracteristicasSecundarias&caracteristicaPrimaria="+caracteristicaPrimaria+"&produto="+produto, function( data ) { $( "#caracteristicaSecundaria").html( data ); }); } function limpaCarrinho() { if(confirm('Você realmente deseja excluir TODOS os itens do carrinho?')) { loadingX(); $('#xgetDados').attr('src',HTTP+'/xpainel/lib/ajax.php?function=limparCarrinho'); } return false; } function validaBusca() { digts = document.getElementsByName("busca")[0].value.length; if( digts > 3) { document.getElementById('xbusca').submit(); return true; } alertX('Informe pelomenos 4 caracteres para sua busca') return false; } function getEstoqueProduto(produto) { $( "#produtoDisponibilidade").html(''); $.get( "xpainel/lib/ajax.php?function=getEstoqueProduto&produto="+produto, function( data ) { $( "#produtoDisponibilidade").html( data ); }); } function getEstoqueDisponivel(estoque_grade_id) { $( "#produtoQuantidade").html(''); $.get( "xpainel/lib/ajax.php?function=getEstoqueDisponivel&estoque_grade_id="+estoque_grade_id, function( data ) { $( "#produtoQuantidade").html( data ); }); } function setPagSeguro(code) { isOpenLightbox = PagSeguroLightbox({ code: code }, { success : function(transactionCode) { location = 'meus-pedidos.php'; alert(transactionCode); }, abort : function() { } }); if (!isOpenLightbox){ location.href="https://pagseguro.uol.com.br/v2/checkout/payment.html?code="+code; } } function getTransportadoras() { cep = document.getElementById('cep').value; if(cep.length >= 8) { return returnFretes(cep); } return false; } function setQtd(acao,indice) { indice = typeof indice !== 'undefined' ? indice : ''; var inputQtd = $('#produto_quantidade'+indice); valorAtual = parseInt(inputQtd.val()); valorMaximo = parseInt(inputQtd.attr('max')); if(acao == 1) { if(valorMaximo == 0 || valorAtual < valorMaximo) { valorAtual++; } else { valorAtual = valorMaximo; alertX('Temos apenas '+ valorMaximo +' ítens no estoque'); return false; } } else { if(valorAtual > 1) { valorAtual--; } } inputQtd.val(valorAtual); if(indice != '') { loadingX(); $('#linhaCarrinho'+indice).submit(); } } function setQtdAjax(acao,indice) { indice = typeof indice !== 'undefined' ? indice : ''; var inputQtd = $('#produto_quantidade'+indice); valorAtual = parseInt(inputQtd.val()); valorMaximo = parseInt(inputQtd.attr('max')); if(acao == 1) { if(valorMaximo == 0 || valorAtual < valorMaximo) { valorAtual++; } else { valorAtual = valorMaximo; alertX('Temos apenas '+ valorMaximo +' ítens no estoque'); return false; } } else { if(valorAtual > 1) { valorAtual--; } } inputQtd.val(valorAtual); } function escondeBtsAjax(id) { loadingX(); $('.hidden'+id).fadeOut( "slow", function() { $('#cartajaxbtcart'+id).fadeIn( "slow", function() { }); }); return true; } function atualizaListaSuspensa(v) { console.log(v); $('#valorcarrinhosuspenso').html(v); loadedX(); } function Mascara(o, f) { v_obj = o v_fun = f setTimeout("execmascara()", 1) } /* Função que Executa os objetos */ function execmascara() { v_obj.value = v_fun(v_obj.value) } /* Função que Determina as expressões regulares dos objetos */ function leech(v) { v = v.replace(/o/gi, "0") v = v.replace(/i/gi, "1") v = v.replace(/z/gi, "2") v = v.replace(/e/gi, "3") v = v.replace(/a/gi, "4") v = v.replace(/s/gi, "5") v = v.replace(/t/gi, "7") return v } /* Função que permite apenas numeros */ function Integer(v) { return v.replace(/\D/g, "") } /* Função que padroniza telefone (11) 4184-1241 */ function Telefone(v) { v = v.replace(/\D/g, "") v = v.replace(/^(\d\d)(\d)/g, "($1) $2") v = v.replace(/(\d{4})(\d)/, "$1-$2") return v } /* Função que padroniza telefone (11) 41841241 */ function TelefoneCall(v) { v = v.replace(/\D/g, "") v = v.replace(/^(\d\d)(\d)/g, "($1) $2") return v } /* Função que padroniza CPF */ function Cpf(v) { v = v.replace(/\D/g, "") v = v.replace(/(\d{3})(\d)/, "$1.$2") v = v.replace(/(\d{3})(\d)/, "$1.$2") v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2") return v } /* Função que padroniza CEP */ function CepEnd(v) { v = v.replace(/D/g, "") v = v.replace(/^(\d{5})(\d)/, "$1-$2") return v; } function CepFrete(v) { v = v.replace(/D/g, ""); v = v.replace(/^(\d{5})(\d)/, "$1-$2") return v } /* Função que padroniza CNPJ */ function Cnpj(v) { v = v.replace(/\D/g, "") v = v.replace(/^(\d{2})(\d)/, "$1.$2") v = v.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3") v = v.replace(/\.(\d{3})(\d)/, ".$1/$2") v = v.replace(/(\d{4})(\d)/, "$1-$2") return v } /* Função que permite apenas numeros Romanos */ function Romanos(v) { v = v.toUpperCase() v = v.replace(/[^IVXLCDM]/g, "") while (v.replace( /^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/, "") != "") v = v.replace(/.$/, "") return v } /* Função que padroniza o Site */ function Site(v) { v = v.replace(/^http:\/\/?/, "") dominio = v caminho = "" if (v.indexOf("/") > -1) dominio = v.split("/")[0] caminho = v.replace(/[^\/]*/, "") dominio = dominio.replace(/[^\w\.\+-:@]/g, "") caminho = caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g, "") caminho = caminho.replace(/([\?&])=/, "$1") if (caminho != "") dominio = dominio.replace(/\.+$/, "") v = "http://" + dominio + caminho return v } /* Função que padroniza DATA */ function Data(v) { v = v.replace(/\D/g, "") v = v.replace(/(\d{2})(\d)/, "$1/$2") v = v.replace(/(\d{2})(\d)/, "$1/$2") return v } /* Função que padroniza DATA */ function Hora(v) { v = v.replace(/\D/g, "") v = v.replace(/(\d{2})(\d)/, "$1:$2") return v } /* Função que padroniza valor monétario */ function Valor(v) { v = v.replace(/\D/g, "") // Remove tudo o que não é dígito v = v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/, "$1.$2"); // v=v.replace(/(\d{3})(\d)/g,"$1,$2") v = v.replace(/(\d)(\d{2})$/, "$1.$2") // Coloca ponto antes dos 2 últimos // digitos return v } /* Função que padroniza Area */ function Area(v) { v = v.replace(/\D/g, "") v = v.replace(/(\d)(\d{2})$/, "$1.$2") return v } function carregaCidades(UF, cid_id) { if (cid_id == null) cid_id = "cidade"; var cid = document.getElementById(cid_id); cid.innerHTML = ""; var inner = ''; var res = request("lista_cidades.php", "UF=" + UF, "TEXT", "POST", false); res = res.split("\n"); for (x = 0; x < res.length; x++) { res[x] = unescape(res[x].replace(/\+/g, " ")); if (res[x] != "") inner += ''; } if (navigator.appName == 'Microsoft Internet Explorer') { cid.outerHTML = ""; } else { cid.innerHTML = inner; } } function returnFretes(cep) { loadingX('#fretes'); url = 'xpainel/lib/ajax.php?function=getFretes&cep='+cep+noCache(); console.log(url); var retorno = $.get(url, function() { loadingX('#fretes'); }) .done(function(data) { $('#fretes').html(data); }) .fail(function() { return false; }) .always(function() { }); } function getGateways() { loadingX('#gateways'); var retorno = $.get('xpainel/lib/ajax.php?function=getGateways'+noCache(), function() { }) .done(function(data) { $('#gateways').html(data); }) .fail(function() { return false; }) .always(function() { }); } function setSessionEndereco(elemento) { var url = "xpainel/lib/ajax.php?function=setSessionEndereco"; var validacao = ''; $.post( url, $(elemento).serialize()) .done(function( data ) { }); setTimeout(function(){ return window.location.href = 'revisar-pedido.php'; }, 2000); return false; } function submitAjax(formulario, url) { console.log(formulario+', '+url); $.post( url, $(formulario).serialize()) .done(function( data ) { console.log(data); $('#loadingX').html(data); }); } function setFrete(valor) { $("input[name=valor_frete]").val(valor); } function noCache() { n = new Date().getTime(); return '&nocache='+n; } function autoCep() { cep=document.getElementById('cep').value; if (cep.length <= 8) { return false; } $("#cep").val(cep); $('#cep').blur(); loadingX(); $.getJSON( 'xpainel/lib/ajax.php?function=getEndereco&cep='+cep+noCache(), function( data ) { console.log(data); if(data['endereco'] != undefined) { $('#endereco').val(data['endereco']); } if(data['clientes_complemento'] != undefined) { $('#complemento').val(data['clientes_complemento']); } if(data['bairro'] != undefined) { $('#bairro').val(data['bairro']); } if(data['clientes_destinatario'] != undefined) { $('#destinatario').val(data['clientes_destinatario']); } new dgCidadesEstados({ cidade : document.getElementById('clientes_cidade'), estado : document.getElementById('clientes_estado'), estadoVal : data['estado'] != undefined ? data['estado'] : '', cidadeVal : data['cidade'] != undefined ? data['cidade'] : '' }); if(data['clientes_numero'] != undefined) { $('#numero').val(data['clientes_numero']); } else { $('#numero').focus(); } loadedX(); returnFretes(cep); }); } /* Objeto dgCidadesEstados */ var dgCidadesEstados = function(data) { var defaultData = { estado: false, estadoVal: '', cidade: false, cidadeVal: '', change: false } for (name in defaultData) { if (!data[name]) { data[name] = defaultData[name]; } } var keys = ['estado', 'cidade']; if (data['change']) { //caso change: true, não se trata de um select a ser povoado var nome, length = keys.length; for (var a=0; a