// ********************************************************************************************* // chega combo function ck_Combo(pMsg,pCampo) { var vCampo=""; vSelIndex=0; vSelIndex= eval("document.pagina." + pCampo + ".selectedIndex"); if (vSelIndex==0) { alert(pMsg); vCampo=eval("document.pagina." + pCampo + ".focus()"); return false; } return true; } // *********************************************************************************************************************** function ck_TamSenha(pMsg,pCampo,pTamanho) { var QtdChar=0; vCampo=""; QtdChar=eval("document.pagina." + pCampo + ".value.length"); if (QtdChar="0") && (var_caracter<="9")) { return true; } else { return false; } } // ********************************************************************************************* // checa se é email function ck_email(pMsg,pCampo) { var vemail=""; vemailok=0; vCampo=""; vemail= eval("document.pagina." + pCampo + ".value"); // localiza o . e @ dentro do campo email if (vemail.indexOf(".")>=0) {vemailok=vemailok+1}; if (vemail.indexOf("@")>=0) {vemailok=vemailok+1}; if (vemailok<2) { alert(pMsg); vCampo=eval("document.pagina." + pCampo + ".select()"); vCampo=eval("document.pagina." + pCampo + ".focus()"); return false; } else { return true; } } // *********************************************************************************************************************** // valida se o campo foi preenchido function ck_Tam(pMsg,pCampo) { var QtdChar=0; vCampo=""; QtdChar=eval("document.pagina." + pCampo + ".value.length"); if (QtdChar==0) { alert(pMsg); vCampo=eval("document.pagina." + pCampo + ".select()"); vCampo=eval("document.pagina." + pCampo + ".focus()"); return false; } else return true; } // ********************************************************************************************* // checa cpf function CPFOK(vCampo) { var vRetorno=1; if (vCampo.length==11) { vRetorno=0; var i; s = vCampo; var c = s.substr(0,9); var dv = s.substr(9,2); var d1 = 0; for (i = 0; i < 9; i++) { d1 += c.charAt(i)*(10-i); } if (d1 == 0) {vRetorno=1} if (vRetorno==0) { d1 = 11 - (d1 % 11); if (d1 > 9) d1 = 0; if (dv.charAt(0) != d1) {vRetorno=1} if (vRetorno==0) { d1 *= 2; for (i = 0; i < 9; i++) { d1 += c.charAt(i)*(11-i); } d1 = 11 - (d1 % 11); if (d1 > 9) d1 = 0; if (dv.charAt(1) != d1) { vRetorno=1; } } } } return(vRetorno); } // ********************************************************************************************* // valida CNPJ function isNUMB(c) { if((cx=c.indexOf(","))!=-1) { c = c.substring(0,cx)+"."+c.substring(cx+1); } if((parseFloat(c) / c != 1)) { if(parseFloat(c) * c == 0) { return(1); } else { return(0); } } else { return(1); } } // ********************************************************************************************* function LIMP(c) { while((cx=c.indexOf("-"))!=-1) { c = c.substring(0,cx)+c.substring(cx+1); } while((cx=c.indexOf("/"))!=-1) { c = c.substring(0,cx)+c.substring(cx+1); } while((cx=c.indexOf(","))!=-1) { c = c.substring(0,cx)+c.substring(cx+1); } while((cx=c.indexOf("."))!=-1) { c = c.substring(0,cx)+c.substring(cx+1); } while((cx=c.indexOf("("))!=-1) { c = c.substring(0,cx)+c.substring(cx+1); } while((cx=c.indexOf(")"))!=-1) { c = c.substring(0,cx)+c.substring(cx+1); } while((cx=c.indexOf(" "))!=-1) { c = c.substring(0,cx)+c.substring(cx+1); } return(c); } // ********************************************************************************************* function VerifyCNPJ(CNPJ) { CNPJ = LIMP(CNPJ); if(isNUMB(CNPJ) != 1) { return(0); } else { if(CNPJ == 0) { return(0); } else { g=CNPJ.length-2; if(RealTestaCNPJ(CNPJ,g) == 1) { g=CNPJ.length-1; if(RealTestaCNPJ(CNPJ,g) == 1) { return(1); } else { return(0); } } else { return(0); } } } } // ********************************************************************************************* function RealTestaCNPJ(CNPJ,g) { var VerCNPJ=0; var ind=2; var tam; for(f=g;f>0;f--) { VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind; if(ind>8) { ind=2; } else { ind++; } } VerCNPJ%=11; if(VerCNPJ==0 || VerCNPJ==1) { VerCNPJ=0; } else { VerCNPJ=11-VerCNPJ; } if(VerCNPJ!=parseInt(CNPJ.charAt(g))) { return(0); } else { return(1); } } // ********************************************************************************************* function CNPJOK(vCampo) { var vRetorno=2; if (vCampo.length==14) if (VerifyCNPJ(vCampo)==1) {vRetorno=0;} return(vRetorno); } // ********************************************************************************************* function CPFCNPJOK(pCampo) { var vRetorno=0; vcCampo=""; vpCampo=eval("document.pagina." + pCampo + ".value"); vRetorno=CPFOK(vpCampo); if (vRetorno>0) { vRetorno=CNPJOK(vpCampo); } if (vRetorno==0) { return true; } else { alert("CPF/CNPJ inválido"); vcCampo=eval("document.pagina." + pCampo + ".select()"); vcCampo=eval("document.pagina." + pCampo + ".focus()"); return false; } } // exemplo do uso //