jsLogger.logger("Library Loaded: Outros", jsLogger.DEBUG); function FormataControle(Campo, teclapres) { var tecla = teclapres.keyCode; var vr = new String(Campo.value); vr = vr.replace(".", ""); vr = vr.replace(".", ""); vr = vr.replace(".", ""); tam = vr.length + 1; if (tecla != 9 && tecla != 8) if (tam > 7) { if (tam > 4 && tam < 9) Campo.value = vr.substr(0, 4) + '.' + vr.substr(4, tam); if (tam >= 9 && tam < 13) Campo.value = vr.substr(0, 4) + '.' + vr.substr(4, 4) + '.' + vr.substr(8, tam - 8); if (tam >= 13 && tam < 17) Campo.value = vr.substr(0, 4) + '.' + vr.substr(4, 4) + '.' + vr.substr(8, 4) + '.' + vr.substr(12, tam - 12); } else { if (tam > 1 && tam < 5) Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, tam); if (tam >= 5 && tam < 8) Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, 3) + '.' + vr.substr(4, tam - 4); } } function FormataITR(Campo, teclapres) { var tecla = teclapres.keyCode; var vr = new String(Campo.value); vr = vr.replace(".", ""); vr = vr.replace(".", ""); vr = vr.replace("-", ""); tam = vr.length + 1; if (tecla != 9 && tecla != 8) { if (tam > 1 && tam < 5) Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, tam); if (tam >= 5 && tam < 8) Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, 3) + '.' + vr.substr(4, tam - 4); if (tam >= 8) Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, 3) + '.' + vr.substr(4, 3) + '-' + vr.substr(7, 1); } } function SaltaCampo(campo, prox, tammax, teclapres) { var tecla = teclapres.keyCode; vr = document.forms[0].elements[campo].value; if (tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108) { document.form[campo].value = vr.substr(0, vr.length - 1); } else { vr = vr.replace("-", ""); vr = vr.replace("/", ""); vr = vr.replace("/", ""); vr = vr.replace(",", ""); vr = vr.replace(".", ""); vr = vr.replace(".", ""); vr = vr.replace(".", ""); vr = vr.replace(".", ""); tam = vr.length; if (tecla != 0 && tecla != 9 && tecla != 16) if (tam == tammax) document.forms[0].elements[prox].focus(); } } function CalcularDV(sCampo, iPeso) { var iTamCampo; var iPosicao, iDigito; var iSoma1 = 0; var iSoma2 = 0; var iDV1, iDV2; iTamCampo = sCampo.length; for (iPosicao = 1; iPosicao <= iTamCampo; iPosicao++) { iDigito = sCampo.substr(iPosicao - 1, 1); iSoma1 = parseInt(iSoma1, 10) + parseInt((iDigito * Calcular_Peso(iTamCampo - iPosicao, iPeso)), 10); iSoma2 = parseInt(iSoma2, 10) + parseInt((iDigito * Calcular_Peso(iTamCampo - iPosicao + 1, iPeso)), 10); } iDV1 = 11 - (iSoma1 % 11); if (iDV1 > 9) iDV1 = 0; iSoma2 = iSoma2 + (iDV1 * 2); iDV2 = 11 - (iSoma2 % 11); if (iDV2 > 9) iDV2 = 0; Ret = (parseInt(iDV1 * 10, 10) + parseInt(iDV2)); Ret = "0" + Ret; Ret = Ret.substr(Ret.length - 2, Ret.length); return (Ret); } function Calcular_Peso(iPosicao, iPeso) { //Pesos //CPF 11 //CNPJ 9 return (iPosicao % (iPeso - 1)) + 2; } function LimpaCampo(sValor, iBase) { var tam = sValor.length; var saida = new String(); for (i = 0; i < tam; i++) if (!isNaN(parseInt(sValor.substr(i, 1), iBase))) saida = saida + String(sValor.substr(i, 1)); return (saida); } function TestaForm(theForm, iTipo) { if (!(TestaNI(theForm.NI, iTipo))) return (false); if (!(TestaControle(theForm.Controle))) return (false); var controle = LimpaCampo(theForm.Controle.value, 16); var tam = controle.length; if (tam == 16) { if (!(TestaData(theForm.Data))) return (false); if (!(TestaHora(theForm.Hora))) return (false); } else { if (theForm.Data.value != "") { alert('Só preencher data da emissão para certidão emitida pela Internet'); theForm.Data.value = ""; theForm.Data.focus(); return (false); } if (theForm.Hora.value != "") { alert('Só preencher hora da emissão para certidão emitida pela Internet '); theForm.Hora.value = ""; theForm.Hora.focus(); return (false); } } return (true); } function TestaFormItr(theForm, iTipo) { if (!(TestaNI(theForm.NI, iTipo))) return (false); if (!(TestaControle(theForm.Controle))) return (false); return (true); } function TestaNI(cNI, iTipo) { var NI = LimpaCampo(cNI.value, 10); switch (iTipo) { case 1 : if (NI.length != 14) { alert('O número do CNPJ informado está incorreto'); cNI.value = ""; cNI.focus(); return (false); } if (NI.substr(12, 2) != CalcularDV(NI.substr(0, 12), 9)) { alert('O número do CNPJ informado está incorreto'); cNI.value = ""; cNI.focus(); return (false); } break; case 2 : if (NI.length != 11) { alert('O número do CPF informado está incorreto'); cNI.value = ""; cNI.focus(); return (false); } if (NI.substr(9, 2) != CalcularDV(NI.substr(0, 9), 11)) { alert('O número do CPF informado está incorreto'); cNI.value = ""; cNI.focus(); return (false); } break; case 3 : if (NI.length != 8) { alert('O número do ITR informado está incorreto'); cNI.value = ""; cNI.focus(); return (false); } var dv = new String(); dv = CalcularDV(NI.substr(0, 7), 9); dv = dv.substr(0, 1); if (NI.substr(7, 1) != dv) { alert('O número do ITR informado está incorreto'); cNI.value = ""; cNI.focus(); return (false); } break; default : return (false); } return (true); } function TestaControle(cControle) { var controle; controle = LimpaCampo(cControle.value, 16); var tam = controle.length; if (tam != 7 && tam != 16) { alert('O número da Certidão / Controle informado está incorreto'); cControle.value = ""; cControle.focus(); return (false); } return (true); } function VerAlfaNumerico(pInd) { var pValor = document.forms[0].elements[pInd].value; var AuxTam = pValor.length; for (var j = 0; j < AuxTam; j++) if ((!IndAlfaNumerico(pValor.charAt(j))) || (pValor.charAt(j) == " ")) { document.forms[0].elements[pInd].focus(); document.forms[0].elements[pInd].value = pValor = pValor.substring(0, j); } } function IndAlfaNumerico(N) { for (var i = 0; i < 10; i++) if (N == i) return true; return false; }