function toUpper(obj) { obj.value = obj.value.toUpperCase(); } function somarDias(txtData, diasAdd) { var d = new Date(); d.setTime(Date.parse(txtData.split("/").reverse().join("/"))+(86400000*(diasAdd))) var dataFinal; if(d.getDate() < 10) { dataFinal = "0"+d.getDate().toString(); } else { dataFinal = d.getDate().toString(); } if((d.getMonth()+1) < 10) { dataFinal += "/0"+(d.getMonth()+1).toString()+"/"+d.getFullYear().toString(); } else { dataFinal += "/"+((d.getMonth()+1).toString())+"/"+d.getFullYear().toString(); } return dataFinal; } function subtrairDias(txtData, diasAdd) { var d = new Date(); d.setTime(Date.parse(txtData.split("/").reverse().join("/"))-(86400000*(diasAdd))) var dataFinal; if(d.getDate() < 10) { dataFinal = "0"+d.getDate().toString(); } else { dataFinal = d.getDate().toString(); } if((d.getMonth()+1) < 10) { dataFinal += "/0"+(d.getMonth()+1).toString()+"/"+d.getFullYear().toString(); } else { dataFinal += "/"+((d.getMonth()+1).toString())+"/"+d.getFullYear().toString(); } return dataFinal; } function diasDecorridos(dt1, dt2){ // variíveis auxiliares var minuto = 60000; var dia = minuto * 60 * 24; var horarioVerao = 0; // ajusta o horario de cada objeto Date dt1.setHours(0); dt1.setMinutes(0); dt1.setSeconds(0); dt2.setHours(0); dt2.setMinutes(0); dt2.setSeconds(0); // determina o fuso horírio de cada objeto Date var fh1 = dt1.getTimezoneOffset(); var fh2 = dt2.getTimezoneOffset(); // retira a diferenía do horírio de verío if(dt2 > dt1){ horarioVerao = (fh2 - fh1) * minuto; } else{ horarioVerao = (fh1 - fh2) * minuto; } var dif = Math.abs(dt2.getTime() - dt1.getTime()) - horarioVerao; return Math.ceil(dif / dia); } /*Função para determinar um limite de dias para pesquisa entre duas datas parametros: objData1 = objeto do campo da data inicio objData2 = objeto do campo da data fim paramDias = o range de dias que deve ser validado entre as duas datas*/ function determinarRangeDuasData(objData1, objData2, paramDias){ var dataIni = objData1.value; var dataFim = objData2.value; var data1 = ""; var data2 = ""; if (dataIni != "" && dataFim == ""){ dataFim = somarDias(dataIni,paramDias); objData2.value = dataFim; }else if (dataIni == "" && dataFim != ""){ dataIni = subtrairDias(dataFim,paramDias); objData1.value = dataIni; }else if (dataIni != "" && dataFim != ""){ //data1 = new Date(dataIni.split( "/" )[2].toString(), dataIni.split( "/" )[1].toString(), dataIni.split( "/" )[0].toString()); //data2 = new Date(dataFim.split( "/" )[2].toString(), dataFim.split( "/" )[1].toString(), dataFim.split( "/" )[0].toString()); data1 = new Date( parseInt(dataIni.substring(6,10)), parseInt(dataIni.substring(3,5))-1, parseInt(dataIni.substring(0,2)) ); data2 = new Date( parseInt(dataFim.substring(6,10)), parseInt(dataFim.substring(3,5))-1, parseInt(dataFim.substring(0,2)) ); if (diasDecorridos(data1,data2)-1 >= paramDias){ alert( "O período para a pesquisa entre as datas não pode ser maior que " + paramDias + " dias." ); return false; } } return true; } function addOption(obj, value, text, sel) { var newOpcao = document.createElement("option"); newOpcao.setAttribute("value",value); newOpcao.appendChild(document.createTextNode(text)); //Adiciona o texto a OPTION. newOpcao.selected = sel; obj.appendChild(newOpcao); } function removerOptions(obj, last) { while(obj.options.length > last) { obj.options[obj.options.length-1] = null; } } function removerAllOptions(obj) { while(obj.options.length > 0) { obj.options[obj.options.length-1] = null; } } function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } // Verificar se esta vazio function campovazio(campo,nome_campo) { if (trim(campo.value) == "") { alert("O campo "+nome_campo+" está vazio"); campo.focus(); return false; } else if(campo == null){ alert("O campo "+nome_campo+" está vazio"); campo.focus(); return false; } else return true; } // Verifica limite mínimo de campo function limite_minimo(campo,nome_campo,valor_minimo) { if (campo.value.length < valor_minimo) { alert("O campo " +nome_campo+ " deve conter no mínimo "+valor_minimo+ " caracteres"); campo.focus(); return false; } else return true; } // Verifica limite do campo function limite(campo,nome_campo,valor_limite) { if (campo.value.length < valor_limite) { alert("O campo " +nome_campo+ " deve conter "+valor_limite+ " caracteres"); campo.focus(); return false; } else return true; } // Verifica a confirmação de senha function confirmasenha(confirma,nome_conforma,senha,nome_senha) { if (campo != senha) { alert("O campo "+nome_campo+" deve ser igual ao campo "+nome_senha); campo.focus(); return false; } } function corrigeCEP(cep) { var novoCep = ''; var numerico = /[0-9]/; var aux; for (i=0; i<=(cep.length-1); i++) { aux = cep.substring(i,i+1); if (numerico.test(aux)) { novoCep += aux; } } return novoCep; } // Verifica nímeros function numerico(campo,nome_campo) { var numerico = /[^0-9]/; if (numerico.test(campo.value)) { alert("O campo "+nome_campo+" só aceita campos numéricos"); campo.focus(); return false } else return true; } function validaCPFCNPJ(campo, nome_campo){ var cgcpf = campo.value; if (cgcpf.length == 11) { if(!CPFValido(cgcpf)){ alert("O campo "+nome_campo+ " está inválido"); return false; } } if (cgcpf.length == 14) { if (!check_cgc(cgcpf)) { alert("CNPJ informado é inválido."); return false; } } return true; } // Verifica se o login í CPF ou CNPJ function verificalogin(campo,nome_campo) { alert(campo.length); if (campo.length < 11 ) { alert("O campo "+nome_campo+ "está inválido"); campo.focus(); return false; } if (campo.length = 11) { checaCPF(campo.value); } if (campo.length = 14) { checaCGC(campo.value); } else { alert("O campo "+nome_campo+ "está inválido"); campo.focus(); return false; } } //função de validação de CPF function CPFValido(CPF) { var cpf = CPF; if(cpf == ""){ return false; } var digitsInCIC = 11; var digito = new Array(digitsInCIC); var dv = new Array(2); var aux = 0; var i = 0; switch(CPF) { case "11111111111": return false; case "22222222222": return false; case "33333333333": return false; case "44444444444": return false; case "55555555555": return false; case "66666666666": return false; case "77777777777": return false; case "88888888888": return false; case "99999999999": return false; case "00000000000": return false; default: // Se tiver menos de digitsInCIC posicoes, completa com zeros í frente if (CPF.length < digitsInCIC-1) { CPF = "0000000000" + CPF; CPF = CPF.substring(CPF.length - digitsInCIC, CPF.length); } } // Separa os dígitos (12 dígitos no míximo) for (i=0; i<=(CPF.length-1); i++) { digito[i]=CPF.substring(i,i+1); } // Calcula o primeiro dígito verificador for (i=0; i<=8; i++) { aux += (digito[i] * (10-i)); } if (((aux%digitsInCIC)==0) | ((aux%digitsInCIC)==1)) { dv[0] = 0; } else { dv[0] = digitsInCIC - (aux%digitsInCIC); } // Se o primeiro dígito não valer, píra por aqui if (dv[0] != digito[9]) { return false; } // Calcula o segundo dígito verificador aux = 0; for (i=0; i<=8; i++) { aux += (digito[i] * (digitsInCIC-i)); } aux += dv[0] * 2; if (((aux%digitsInCIC)==0) | ((aux%digitsInCIC)==1)) { dv[1] = 0; } else { dv[1] = digitsInCIC - (aux%digitsInCIC); } // Se o segundo dígito não valer, píra por aqui if (dv[1] != digito[10]) { return false; } // Se chegou atí aqui, não hí por que não dizer // que o CPF não í vílido return true; } // função de validação do email function verifyemail_check(str) { const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(str).toLowerCase()); // if(!str.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i)) // return false; // else // return true; } // Verifica se o e-mail í vílido function checaemail(campo,nome_campo) { if(campo.value == "") { alert("O campo "+nome_campo+ " está vazio."); return false; } if(!verifyemail_check(campo.value)) { alert("O campo "+nome_campo+ " está inválido."); // campo.focus(); return false; } else return true; } // Verifica o CPF caso tenha sido preenchido function checaCPFPreenchido(campo) { if(campo.value != ""){ if(!CPFValido(campo.value)) { alert("O CPF é inválido, digite um CPF válido."); campo.focus(); return false; } } } // Verifica o CPF function checaCPF(campo) { if(campo.value == ""){ alert("O CPF está vazio."); return false; } if(!CPFValido(campo.value)) { alert("O CPF é inválido, digite um CPF válido."); // campo.focus(); return false; } } function cgc(campo) { if (!check_cgc(campo.value)) { alert("CNPJ informado é inválido."); campo.focus(); } } // Verifica CNPJ function checaCGC(campo) { if (!check_cgc(campo.value)) alert("O campo CNPJ informado é inválido"); // campo.focus(); return false; } // Verifica cartío de Crídito function checacartao(campo,nome_campo) { if (campo.value.length == 16 || campo.value.length == 19){ if(!verifica_numerico(campo.value)){ alert("O número de "+nome_campo+ "digitado é inválido"); campo.select(); return false; } } else { alert("O número do "+nome_campo+ "seu cartão deve ter 16 ou 19 dígitos"); campo.select(); return false; } if (!(campo.value.substring(0,1) == 5 || campo.value.substring(0,1) == 6 || campo.value.substring(0,3) == 104)){ alert("O número do "+nome_campo+ "cartão digitado é inválido"); campo.select(); return false; } } //Recebe um valor e o retorna formatado como CPF function formataCPF(valor){ var vr = completar(11,valor,0); valor = vr.substring(0,3) + '.' + vr.substring(3,6) + '.' + vr.substring(6,9) + '-' + vr.substring(9,11); return valor; } //Recebe um valor e o retorna formatado como CNPJ function formataCNPJ(valor){ var vr = completar(14,valor,0); valor = vr.substring(0,2) + '.' + vr.substring(2,5) + '.' + vr.substring(5,8) + '/' + vr.substring(8,12)+ '-' + vr.substring(12,14); return valor; } // Completa uma string í esquerda com o caracter passado como parímetro function completar(max, str, caracter) { novoValor = str; restante = max - str.length; for(i = 0; i < restante; i++) { str = caracter + str; } novoValor = str; return novoValor; } function desformataCGCPF(valor) { valor = valor.replace(".", ""); valor = valor.replace(".", ""); valor = valor.replace("-", ""); valor = valor.replace("/", ""); /*for(i = 0; i < valor.length; i++) { if(valor.indexOf("0") == 0) valor = valor.substring(1, valor.length); else break; }*/ return valor; } function formataNumeroMilhar(num, milhar) { valorFormatado = ""; decimais = ""; if(num.indexOf(milhar) > -1) return num; if(num.indexOf(",") > -1) { decimais = num.substr(num.indexOf(","),num.length); num = num.substr(0, num.length - decimais.length); } if(num.length <= 3) return num + decimais; cont = 0; for(i = num.length-1; i >= 0; i--) { valorFormatado = num.charAt(i) + valorFormatado; cont ++; if(cont % 3 == 0 && cont != 0 && cont != num.length) valorFormatado = milhar + valorFormatado; } valorFormatado += decimais; return valorFormatado; } function float2moeda(num) { x = 0; if(num<0) { num = Math.abs(num); x = 1; } if(isNaN(num)) num = "0"; cents = Math.floor((num*100+0.5)%100); num = Math.floor((num*100+0.5)/100).toString(); if(cents < 10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0, num.length-(4*i+3)) + '.' + num.substring(num.length-(4*i+3)); ret = num + ',' + cents; if (x == 1) ret = ' - ' + ret; return ret; } function moeda2float(moeda){ moeda = moeda.replace(".",""); moeda = moeda.replace(",","."); return parseFloat(moeda); } function check_cgc(cgc_ver){ var recgc; var p="", x=""; var i = 0, m1=0, m2=0, num=0, soma1=0, soma2=0, digito1=0, digito2=0, dcalculo=0, digitos=0; recgc = /\d{14}/; if ((cgc_ver == "00000000000000") || (cgc_ver == "11111111111111") || (cgc_ver == "22222222222222") || (cgc_ver == "33333333333333") || (cgc_ver == "44444444444444") || (cgc_ver == "55555555555555") || (cgc_ver == "66666666666666") || (cgc_ver == "77777777777777") || (cgc_ver == "88888888888888") || (cgc_ver == "99999999999999")) { return false; } if (cgc_ver.length < 14) { return false; } if (! recgc.test) { return false; } p = cgc_ver.substring(0,12); for (i = 1; i <= 12 ; i++) { m1 = 6-i; if (i > 4) { m1=14-i; } m2 = 7-i; if (i > 5) { m2 = 15-i; } num = parseInt(p.charAt(i-1), 10); soma1 += num*m1; soma2 += num*m2; } m1 = ( soma1 - parseInt(soma1/11)*11); if ( m1 == 0 || m1 ==1) { digito1 = 0; } else { digito1 = 11-m1; } soma2 = soma2 + (digito1*2); m2 = ( soma2 - parseInt(soma2/11)*11); if ( m2 == 0 || m2 ==1) { digito2 = 0; } else { digito2 = 11-m2; } dcalculo = (digito1*10)+digito2; x = cgc_ver.substr(12,2); digitos = parseInt(x,10); if ( dcalculo == digitos) { return true; } else { return false; } } function validaCliente(campo){ if(document.getElementById(campo).value != "______________"){ if (!check_cgc(document.getElementById(campo).value)) { alert("CNPJ informado é inválido."); document.getElementById('finalizarEmabarcadorId').style.display = 'none'; return; } show_loading(); ValidacoesAJAX.validaCNPJCad(document.getElementById("embarcador_cnpj").value,function(data){ clienteExiste(data); }); } } function validaClienteTransp(){ if (campovazio(document.getElementById('transportador_cgcpf'),'CPF/CNPJ')){ return false; } ValidacoesAJAX.validaCPFCNPJTransp(document.getElementById("transportador_cgcpf").value, clienteTranspExiste); } function mod(dividendo,divisor) { return Math.round(dividendo - (Math.floor(dividendo/divisor)*divisor)); } function clienteExiste(retorno){ hide_loading(); if(retorno){ alert("CNPJ já cadastrado em nossa base"); document.getElementById("embarcador_cnpj").value=''; document.getElementById("embarcador_cnpj").focus(); document.getElementById('finalizarEmabarcadorId').style.display = 'none'; }else{ EmbarcadorAJAX.obterDadosEmbarcadorPedagio(document.getElementById("embarcador_cnpj").value, carregaDadosEmbarcador); } } function validaCep(retorno){ if(document.getElementById('cep').value == "_____-___"){ alert ('CEP informado é inválido.'); return; } ValidacoesAJAX.validaCEP(document.getElementById('cep').value, carregaDadosCep); } function clienteTranspExiste(retorno){ if(!retorno){ alert("CNPJ/CPF não cadastrado em nossa base. Adquira o Via Fácil!"); document.getElementById("transportador_cgcpf").value=''; document.getElementById("transportador_cgcpf").focus(); } } function loginExiste(retorno){ if(retorno){ alert("Usuário já cadastrado para este cliente"); document.getElementById('btFinalizarCadastroUsuario').style.display = 'none'; setTimeout(function() { document.getElementById("usuario_login").focus(); }, 10); }else{ document.getElementById('btFinalizarCadastroUsuario').style.display = ''; } } function replaceAll( str, from, to ) { var idx = str.indexOf( from ); while ( idx > -1 ) { str = str.replace( from, to ); idx = str.indexOf( from ); } return str; } function carregaDadosEmbarcador(obj){ if(obj != null){ document.getElementById("embarcador_nome").value = trim(obj.razaoSocial); document.getElementById("embarcador_nomeFantasia").value = trim(obj.nomeEmpresa); document.getElementById("embarcador_inscricaoEstadual").value = trim(obj.inscricaoEstadual); document.getElementById("embarcador_inscricaoMunicipal").value = trim(obj.inscricaoMunicipal); document.getElementById("embarcador_site").value = trim(obj.site); document.getElementById("endereco_logradouro").value = trim(obj.logradouro); document.getElementById("endereco_numero").value = trim(obj.numero); document.getElementById("endereco_complemento").value = trim(obj.complemento); document.getElementById("endereco_bairro").value = trim(obj.bairro); document.getElementById("cep").value = trim(obj.cep); document.getElementById("cep").value = replaceAll( document.getElementById("cep").value, ' ', '' ); document.getElementById("endereco_cidade").value = trim(obj.cidade); document.getElementById("endereco_estado").value = trim(obj.estado); document.getElementById("foneEmpresa").value = trim(obj.telefoneContato); document.getElementById("foneEmpresa").value = replaceAll( document.getElementById("foneEmpresa").value, ' ', '' ); document.getElementById("contatoComercial_nome").value = trim(obj.contato); document.getElementById("contatoComercial_cargo").value = trim(obj.cargoContato); document.getElementById("foneContatoComercial").value = trim(obj.telefoneContato); document.getElementById("foneContatoComercial").value = replaceAll( document.getElementById("foneContatoComercial").value, ' ', '' ); document.getElementById("contatoComercial_ramal").value = trim(obj.ramalContato); document.getElementById("contatoComercial_email").value = trim(obj.emailContato); if(obj.status != 1){ document.getElementById("embarcador_nome").disabled = true; document.getElementById("embarcador_nomeFantasia").disabled = true; ///* VP-23642 (esta alteração foi comentada pq está aguardando correção no CBILL) document.getElementById("embarcador_inscricaoEstadual").disabled = true; document.getElementById("embarcador_inscricaoMunicipal").disabled = true; document.getElementById("embarcador_site").disabled = true; document.getElementById("endereco_logradouro").disabled = true; document.getElementById("endereco_complemento").disabled = true; document.getElementById("endereco_numero").disabled = true; document.getElementById("endereco_bairro").disabled = true; document.getElementById("cep").disabled = true; document.getElementById("endereco_cidade").disabled = true; document.getElementById("endereco_estado").disabled = true; document.getElementById("foneEmpresa").disabled = true; //*/ } alert('Alguns campos foram carregados utilizando a nossa base de dados. \nFavor confirmar antes de finalizar o cadastro.') }else{ document.getElementById("embarcador_nome").value = ""; document.getElementById("embarcador_nomeFantasia").value = ""; document.getElementById("embarcador_inscricaoEstadual").value = ""; document.getElementById("embarcador_inscricaoMunicipal").value = ""; document.getElementById("embarcador_site").value = ""; document.getElementById("endereco_logradouro").value = ""; document.getElementById("endereco_numero").value = ""; document.getElementById("endereco_complemento").value = ""; document.getElementById("endereco_bairro").value = ""; document.getElementById("cep").value = ""; document.getElementById("cep").value = ""; document.getElementById("endereco_cidade").value = ""; document.getElementById("endereco_estado").value = ""; document.getElementById("foneEmpresa").value = ""; document.getElementById("foneEmpresa").value = ""; document.getElementById("contatoComercial_nome").value = ""; document.getElementById("contatoComercial_cargo").value = ""; document.getElementById("foneContatoComercial").value = ""; document.getElementById("foneContatoComercial").value = ""; document.getElementById("contatoComercial_ramal").value = ""; document.getElementById("contatoComercial_email").value = ""; document.getElementById("embarcador_nome").disabled = false; document.getElementById("embarcador_nomeFantasia").disabled = false; document.getElementById("embarcador_inscricaoEstadual").disabled = false; document.getElementById("embarcador_inscricaoMunicipal").disabled = false; document.getElementById("embarcador_site").disabled = false; document.getElementById("endereco_logradouro").disabled = false; document.getElementById("endereco_complemento").disabled = false; document.getElementById("endereco_numero").disabled = false; document.getElementById("endereco_bairro").disabled = false; document.getElementById("cep").disabled = false; document.getElementById("endereco_cidade").disabled = false; document.getElementById("endereco_estado").disabled = false; document.getElementById("foneEmpresa").disabled = false; } document.getElementById('finalizarEmabarcadorId').style.display = ''; } function carregaDadosCep(obj){ if(obj != null){ if (trim(obj.logradouro) == 'erro'){ alert('CEP informado é inválido. '); document.getElementById("endereco_logradouro").value = ''; document.getElementById("endereco_bairro").value = ''; document.getElementById("endereco_cidade").value = ''; document.getElementById("endereco_estado").value = ''; } else { document.getElementById("endereco_logradouro").value = trim(obj.logradouro); document.getElementById("endereco_bairro").value = trim(obj.bairro); document.getElementById("endereco_cidade").value = trim(obj.cidade); document.getElementById("endereco_estado").value = trim(obj.estado); } } else { alert('CEP informado é inválido. '); } } function trim(str){ if(str != null){ return str.replace(/^\s+|\s+$/g,""); } return ""; } function show_loading(){ var elem = document.getElementById("loading"); elem.classList.add("show_loading"); } function hide_loading(){ var elem = document.getElementById("loading"); elem.classList.remove("show_loading"); } // Valida Senha function validaSenha(campo,nome_campo){ var valorCampo = document.getElementById(campo).value; if(valorCampo){ /* if(!limite_minimo(document.getElementById(campo),nome_campo, 8)) return false; ValidacoesAJAX.validaSenha(document.getElementById(campo).value,function(data){ if(data != null && data != '' && data.length != 0){ //document.getElementById(campo).focus(); alert(data); //return false; } }); */ ValidacoesAJAX.validaSenha(document.getElementById(campo).value,validaRetornoSenha); } } function validaRetornoSenha(retornoSenha){ if(retornoSenha != null && retornoSenha != '' && retornoSenha.length != 0){ alert(retornoSenha); return false; }else return true; }