function validaCampo(campo, valor) { if (campo.value == "") { alert("Por favor preencha o campo "+valor) campo.focus(); return false; } else return true; } // Verifica se a Data digitada é válida function isValidData(vfield, vfieldName) { var diaStr, mesStr, anoStr var diaInt, mesInt, anoInt var tam, sep1, sep2, verAno tam = vfield.value.length; sep1 = parseInt(vfield.value.indexOf("/", 0)); if (sep1<0) { alert("A Data digitada deve ter o seguinte formato: DD/MM/AAAA !"); return false; } sep2 = parseInt(vfield.value.indexOf("/", sep1+1)) if (sep2<5) { alert("A Data digitada deve ter o seguinte formato: DD/MM/AAAA !"); return false; } verAno = tam-sep2; if(verAno < 5 ) { alert("As datas devem ser preenchidas utilizando 4 dígitos para informar o Ano (ex.: DD/MM/AAAA)!"); return false; } diaStr = vfield.value.substring(0, sep1); if(diaStr.substring(0, 1) == "0") diaStr = diaStr.substring(1, 2); if (isValidNumberValue(diaStr, vfieldName)) { mesStr = vfield.value.substring(sep1+1, sep2); if(mesStr.substring(0, 1) == "0") mesStr = mesStr.substring(1, 2); if (isValidNumberValue(mesStr, vfieldName)) { anoStr = vfield.value.substring(sep2+1, tam); if (isValidNumberValue(anoStr, vfieldName)) { diaInt = parseInt(diaStr); mesInt = parseInt(mesStr); anoInt = parseInt(anoStr); if ((diaInt <= 0) || (diaInt > 31)) { alert("O dia informado não é válido!"); return false; } if ((mesInt <= 0) || (mesInt > 12)) { alert("O mês informado não é válido!"); return false; } if ((mesInt == 4) || (mesInt == 6) || (mesInt == 9) || (mesInt == 11)) { if( diaInt > 30) { alert("O mês informado não possui mais de 30 dias!"); return false; } } if (mesInt == 2) { if ((anoInt % 4 == 0) && ( (anoInt % 100 != 0) || (anoInt % 400 == 0))) { if (diaInt > 29) { alert("O mês informado não possui mais de 29 dias!"); return false; } } else { if(diaInt > 28) { alert("O mês informado não possui mais de 28 dias!"); return false; } } return true; } return true; } else return false; } else return false; } else return false; } // Verifica se somente números foram digitados no campo; function isValidNumberValue (objTextControl, strFieldName) { var strValidNumber = "1234567890"; for (nCount=0; nCount < objTextControl.length; nCount++) { strTempChar=objTextControl.substring(nCount,nCount+1); if ( strValidNumber.indexOf(strTempChar,0)==-1) { alert("O campo " + strFieldName + " deve conter somente números!"); return false; } } return true; } MAIOR_VALOR=9999999999.99; function myFormataCampo(campo,tp,par1,par2,par3){ var ie=(nave().eIntenetExplorer()&&!nave().eApple()),v=nave().pegaVersao(); var b=parent.buttons; if(ie&&(v>=5 && v<5.2)&&b&&b.myBarra&&b.myBarra.clicked==true){ parent.buttons.myBarra.clicked=false; eval("try{campo.focus();}catch(e){}"); return false; } var nArg=myFormataCampo.arguments.length; ERRO=false; var vr=myTiraEspaco(campo.value); if(!campo|| !vr ||vr.length==0){ if(/^(neg_)?(money|money2)$/.test(tp))campo.value="0,00"; return false; } if(nArg==2)par1=""; if(tp=="interval" || tp=="percent_interval"){ if(nArg<=4)par3=""; return myFormataTipo(campo,tp,par3,par1,par2); }else return myFormataTipo(campo,tp,par1); } function nave(){ if(typeof objnave!="object")objnave=new Navegador(); return objnave; } function Navegador(){ this.pegaVersao=function(){return parseFloat(this.version,10)}; this.eIntenetExplorer=function(){return(this.name=="IE")}; this.eNetscape=function(){return(this.name=="Netscape")}; this.eMozilla=function(){return this.mozilla}; this.eApple=function(){return _has(this.platform,["Mac","PPC"]);}; } function myTiraEspaco(s){ return String(s).replace(/^\s+/,"").replace(/\s+$/,""); } function myFormataTipo(f,tp,msgErr,adarg1,adarg2){ if(tp=="none"){f.value=myExcluiCaraSpecial(f.value);return true;} var vr=myCampoFormatado(f.value,tp,f.type); LAST_FIELD=f; var ret=EValidaValor(vr,tp,adarg1,adarg2); if(!ret){showError(tp,msgErr);return false;} else if(!myEReal(tp))f.value=myPegaValor((typeof ret=="boolean")?vr:ret,tp); ERRO=false; return true; } function myCampoFormatado(valor,tipo,inputType){ var t=(arguments.length<1)?"default":String(tipo), vr=myTiraEspaco(myExcluiCaraSpecial((typeof valor=="object"?valor.value:valor),(inputType?inputType:valor.type))); if(!vr||vr.length==0)return ""; if(/^(date|month_year|time|ag_account|ag_cc_cp|ag_savings|branch|account|cep|(neg_)?numeric|interval)$/.test(t)) vr=(/^neg_/.test(t)&&vr.indexOf("-")==0?"-":"")+justNumbersStr(vr); else if(/^(percent|percent_interval|(neg_)?(float(\d{0,1})|money(\d{0,1})))$/.test(t))vr=myParaPontoFlutuante(vr,myPegaNestDeca(t)); else{ if(/^(cpf|cnpj|cpf_cnpj)$/.test(t)){ vr=justNumbersStr(vr); var isCPF=tipo=="cpf"||(tipo=="cpf_cnpj" && vr.length<=SZ_CPF); vr=repeatStr(vr,"0",isCPF?SZ_CPF:SZ_CNPJ); if(parseInt(vr,10)==0)vr=""; }else if(t=="email")vr=myTiraEspaco(vr) } if(typeof valor=="object")valor.value=vr; return vr; } function myExcluiCaraSpecial(vr,type){ var ret="",re=/197|198|208|215|216|222|223|229|230|240|247|248/,c=0,s=String(vr); for(var i=0;i31&&c<253&&(c<127||c>191)&&!re.test(c))||(type=="textarea"&& (c==9||c==13||c==10)))ret+=s.charAt(i); } return ret; } function myParaPontoFlutuante(src,ndec){ src=myTiraEspaco(src); if(!/^\-?([0-9]|\.)*\,{0,1}[0-9]*$/.test(src)||src.charAt(0)==".")return src; var tam=src.length,pDec=src.indexOf(","); if(src.length==0)src="0"; if(pDec==-1){ var p=src.indexOf("."); if(p!=-1&&p==(tam-ndec-1))src=src.replace(/\.(\d*)$/,",$1"); else return myRemoveString(src,".")+","+myRepeteNestString("0",ndec); pDec=src.indexOf(","); } src=myRemoveString(src,"."); if(pDec==0)return "0"+src+myRepeteNestString("0",ndec+1-src.length); else{ if(pDec>(tam-ndec-1))src+=myRepeteNestString("0",pDec-(tam-ndec-1)); pDec=src.indexOf(","); return parseInt(src.slice(0,pDec),10)+src.slice(pDec,pDec+ndec+1); } } function myPegaNestDeca(t){ var arr=t.match(/(\d+)\s*$/); return arr?parseInt(arr[1],10):2; } function myRemoveString(src,arg){ var v=(typeof arg=="string")?[arg]:arg; var r=""; for(var i=0;i=adarg1 && vr<=adarg2; case "percent_interval": if(!myENumeroPontoFlutuante(vr))return false; vr=parseFloat(String(vr).replace(/,/g,"."),10); return vr>=adarg1 && vr<=adarg2; case "default":return !/'|"/.test(vr); default:return true; } } } function myENumero(v){ return /^[0-9]+$/.test(v); } function myEReal(re){ return typeof re=="object" && typeof re.test=="function"; } function myENumeroPontoFlutuante(n){ return /^\-?\d+(,\d+|\d*)$/.test(n); } function myPegaValor(vr,tp){ if(tp=="cpf_cnpj")tp=(vr.length <=SZ_CPF)?"cpf":"cnpj"; if(/^(neg_)?money/.test(tp))return myDinheiro(vr,myPegaNestDeca(tp)); else{ switch(tp){ case "time":return vr.slice(0,2)+":"+vr.slice(2,4); case "date":return vr.getDateValue(); case "month_year":return vr.getMonthDateValue(); case "ag_account":return vr.slice(0,4)+"-"+vr.slice(4,9)+"-"+vr.slice(9,11); case "ag_cc_cp":return vr.slice(0,4)+"-"+vr.slice(4,11); case "ag_savings":return vr.slice(0,4)+"-"+vr.slice(4,10)+"-"+vr.slice(10,11); case "account":return vr.slice(0,5)+"-"+vr.slice(5,7); case "cep":return vr.slice(0,5)+"-"+vr.slice(5,8); case "uppercase":case "full_name": return vr.toUpperCase(); case "cpf":return vr.slice(0,3)+"."+vr.slice(3,6)+"."+ vr.slice(6,9)+ "-"+vr.slice(9,11); case "cnpj":return vr.slice(0,2)+"."+vr.slice(2,5)+"."+vr.slice(5,8)+"/"+vr.slice(8,12)+"-"+vr.slice(12,14); default:return vr; } } } function myDinheiro(vr,ndec){ var neg=vr.indexOf("-")==0; if(myVerificaValorAlto(vr)){ERRO=true;return "0,00";} vr=myParaPontoFlutuante(vr,ndec); var vraux="",p,pDec=vr.indexOf(","),vrDec=vr.slice(pDec+1); for(var i=pDec;i>(neg?1:0);i--){ p=i-pDec; if(i!=pDec&&(p%3==0))vraux+="."; vraux+=vr.charAt(i-1); } return (neg?"-":"")+myInverteString(vraux)+","+vrDec; } function myVerificaValorAlto(vr){ return vr.length>0 &&(parseFloat(vr)>MAIOR_VALOR); } function myInverteString(s){ var t="",i; for(i=0;i