// returns the decoded value of a cookie function getCookieVal(offset) { var endstr = document.cookie.indexOf(";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } // returns the value of the specified cookie, or null function getCookie(name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal(j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return ""; } // creates or updates a cookie function setCookie(name, value) { var argv = setCookie.arguments; var argc = setCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = '/'; //(argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } // deletes a cookie function deleteCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); } //chama o agente que adiciona um produto no carrinho function adiciona(codproduto){ var id = ''; if(document.forms[0].CodigoProjeto.value == 'LOJA'){ id = document.forms[0].IDUsuario.value; } else { id = document.forms[0].IDAgente.value; } window.open('AdicionarProdutoCarrinho?OpenAgent&Produto=' + codproduto + '&IDUsuario=' + id + '&DirDB=' + document.forms[0].Dir.value.replace('/', ',') + '&Depto=' + window.document.forms[0].Departamento.value + '&Inicio=' + window.document.forms[0].Inicio.value + '&UsernameAgente=' + document.forms[0].UsernameAgente.value, '_self'); } function CartaoValido(st) { // Encoding only works on cards with less than 19 digits if (st.length > 19) { alert("Número de Cartão de Crédito inválido!"); return false; } sum = 0; mul = 1; l = st.length; for (i = 0; i < l; i++) { digit = st.substring(l-i-1,l-i); tproduct = parseInt(digit ,10)*mul; if (tproduct >= 10) sum += (tproduct % 10) + 1; else sum += tproduct; if (mul == 1) mul++; else mul--; } if ((sum % 10) != 0){ alert("Número de Cartão de Crédito inválido!"); return false; } return true; } function setColor(el, bg) { if (el.style) el.style.backgroundColor = bg; } function validaEmail(email){ /* em_val = /^\w+@\w+(\.\w+?)/; if(em_val.test(email)){ return true; } else { return false; }*/ return true; } function checaCPF (CPF) { CPF = CPF.replace('.', ''); CPF = CPF.replace('.', '');CPF = CPF.replace('.', ''); CPF = CPF.replace('-', '');CPF = CPF.replace('-', '');CPF = CPF.replace('-', ''); CPF = CPF.replace('/', '');CPF = CPF.replace('/', '');CPF = CPF.replace('/', ''); if(CPF.length == 14){ return validaCNPJ(CPF); } if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" || CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" || CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" || CPF == "88888888888" || CPF == "99999999999") return false; soma = 0; for (i=0; i < 9; i ++) soma += parseInt(CPF.charAt(i)) * (10 - i); resto = 11 - (soma % 11); if (resto == 10 || resto == 11) resto = 0; if (resto != parseInt(CPF.charAt(9))) return false; soma = 0; for (i = 0; i < 10; i ++) soma += parseInt(CPF.charAt(i)) * (11 - i); resto = 11 - (soma % 11); if (resto == 10 || resto == 11) resto = 0; if (resto != parseInt(CPF.charAt(10))) return false; return true; } function checaCEP(CEP){ if(CEP.length==9){ if(CEP.charAt(5) != '-'){ return false; } } else { if(CEP.length != 8){ return false; } else { if(CEP.indexOf('-') != -1){ return false; } } } return true; } function validaCNPJ(pcgc){ pcgc = pcgc.replace('.', ''); pcgc = pcgc.replace('.', ''); pcgc = pcgc.replace('.', ''); pcgc = pcgc.replace('.', ''); pcgc = pcgc.replace('.', ''); pcgc = pcgc.replace('-', ''); pcgc = pcgc.replace('-', ''); pcgc = pcgc.replace('-', ''); pcgc = pcgc.replace('/', ''); pcgc = pcgc.replace('/', ''); pcgc = pcgc.replace('/', ''); if(pcgc.length != 14){ sim=false; } else { sim=true; } if(sim){ for (i=0; ((i<=(pcgc.length-1)) && sim); i++){ val = pcgc.charAt(i); if((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") && (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")){ sim=false; } } if(sim){ m2 = 2; soma1 = 0; soma2 = 0; for(i=11; i>=0; i--){ val = eval(pcgc.charAt(i)); m1 = m2; if(m2 < 9){ m2 = m2+1; } else { m2 = 2; } soma1 = soma1 + (val * m1); soma2 = soma2 + (val * m2); } soma1 = soma1 % 11; if(soma1 < 2){ d1 = 0; } else { d1 = 11 - soma1; } soma2 = (soma2 + (2 * d1)) % 11; if(soma2 < 2){ d2 = 0; } else { d2 = 11- soma2; } if ((d1==pcgc.charAt(12)) && (d2==pcgc.charAt(13))){ return true; } else { return false; } } } } function preencherFormularioConfirmacaoCadastro(){ /* Obtem o cookie */ var sDados = getCookie('PERTO-LojaVirtual-DadosConfirmaCadastro'); /* Se achou, percorre os dados do cookie e preenche o form */ if (sDados != '') { /* Cria um vettor com os itens que salvou */ var vDados = sDados.split(';'); /* Percorre os itens */ for( var i = 0; i < vDados.length; i++){ /* Obtem os dados do item */ vItem = vDados[i].split('|'); var sTipo = vItem[0]; var sNome = vItem[1]; var sValor = vItem[2]; /* Obtem o objeto */ var obj = document.getElementsByName(sNome); for (var j = 0; j < obj.length; j++) { if (obj[j].type == sTipo) { if (sTipo == 'select-one') { obj[j].selectedIndex = sValor; } else { obj[j].value = sValor; } break; } } } } } function preencherCidades(pEstados, pCidades){ var sUF = pEstados.value; /* * Remove todas as opções da combo */ var j = pCidades.options.length; for (var i = 0; i < j; i++) { pCidades.remove(0); } /* * Adiciona as cidades do estado selecionado */ var vCidades = document.forms[0].TodasCidades.value.split(';'); for (var i = 0; i < vCidades.length; i++) { var vOpcao = vCidades[i].split('|'); if (vOpcao[0] == sUF) { pCidades.options[pCidades.options.length] = new Option(vOpcao[1], vOpcao[1]); } } } /* * Seleciona a opção pValor da combo pCombo */ function selecionar(pValor, pCombo){ for (var i = 0; i < pCombo.options.length; i++) { if (pCombo.options[i].value == pValor) { pCombo.selectedIndex = i; return; } } } function validarCarrinho(){ var i = 0; var vExcluir = new Array(); var vQuantidades = new Array(); var vPrecos = new Array(); if (document.forms[0].UID.value == ''){ alert('Não há produtos no carrinho!'); return false; } // Excluir var checks = document.getElementsByName('Excl'); for (var i = 0; i < checks.length; i++) { if (!checks[i].checked) { vExcluir.push(checks[i].value); } } document.forms[0].Excluir.value = vExcluir.join(';'); // Quantidades if(isNaN(document.forms[0].Qte.length)){ if(isNaN(document.forms[0].Qte.value)){ alert('Quantidade inválida!'); document.forms[0].Qte.select(); document.forms[0].Qte.focus(); return false; } else { document.forms[0].Quantidades.value = document.forms[0].Qte.value; } } else { for(i=0; i < document.forms[0].Qte.length; i++){ if(isNaN(document.forms[0].Qte[i].value)){ alert('Quantidade inválida!'); document.forms[0].Qte[i].select(); document.forms[0].Qte[i].focus(); return false; } else { vQuantidades.push(document.forms[0].Qte[i].value) } } document.forms[0].Quantidades.value = vQuantidades.join(';'); } // Precos if(isNaN(document.forms[0].Preco.length)){ if(isNaN(document.forms[0].Preco.value.replace(',', '.'))){ alert('Preco inválido (1)!'); document.forms[0].Preco.select(); document.forms[0].Preco.focus(); return false; } else { document.forms[0].Precos.value = document.forms[0].Preco.value.replace('.', ','); } } else { for(i=0; i < document.forms[0].Preco.length; i++){ if(isNaN(document.forms[0].Preco[i].value.replace(',', '.'))){ alert('Preco inválido (2)!'); document.forms[0].Preco[i].select(); document.forms[0].Preco[i].focus(); return false; } else { vPrecos.push(document.forms[0].Preco[i].value.replace('.', ',')); } } document.forms[0].Precos.value = vPrecos.join(';'); } computarInstalacaoEGarantia(); return true; } function computarInstalacaoEGarantia(){ if (document.forms[0].Instalacao) { if (document.forms[0].Instalacao.checked) { document.forms[0].AuxTemInstalacao.value = 'S'; } else { document.forms[0].AuxTemInstalacao.value = ''; } } if (document.forms[0].Garantia) { if (document.forms[0].Garantia.checked) { document.forms[0].AuxTemGarantia.value = 'S'; } else { document.forms[0].AuxTemGarantia.value = ''; } } }