function validarCnpj(pNmrCnpj)
{var i;var c=pNmrCnpj.substr(0,12);var dv=pNmrCnpj.substr(12,2);var d1=0;for(i=0;i<12;i++)
d1+=c.charAt(11-i)*(2+(i%8));if(d1==0)
return false;d1=11-(d1%11);if(d1>9)
d1=0;if(dv.charAt(0)!=d1)
return false;d1*=2;for(i=0;i<12;i++)
d1+=c.charAt(11-i)*(2+((i+1)%8));d1=11-(d1%11);if(d1>9)
d1=0;if(dv.charAt(1)!=d1)
return false;return true;}
function validarCpf(pNmrCpf){var i;var c=pNmrCpf.substr(0,9);var dv=pNmrCpf.substr(9,2);var d1=0;for(i=0;i<9;i++)
d1+=c.charAt(i)*(10-i);if(d1==0)
return false;d1=11-(d1%11);if(d1>9)
d1=0;if(dv.charAt(0)!=d1)
return false;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)
return false;return true;}
function validarCheque(cheque){soma=0;cheque=cheque.toString();ndc=cheque.length;c3=cheque.substr(ndc-1,1);cheque=cheque.substr(0,ndc-1);ndc=ndc-1;for(i=0;i<ndc;i++){soma=soma+(cheque.substr(i,1)*(ndc-i+1))}
digito=(soma%11)
if((digito==1)||(digito==0))
digito=0
else
digito=(11-digito)
if(digito.toString()==c3.toString())
return true
else
return false}
function completaZero(valor,qtd){valor=valor.toString();len=valor.length;for(i=0;i<(qtd-len);i++)
valor="0"+valor;return valor;}
function validateForm(pFormulario){var vMsg='';var vCheckedGroup=false;for(var i=0;i<pFormulario.elements.length;i++){if(pFormulario.elements[i].idDigito&&pFormulario.elements[i].idDigito.length>0)
vDigito=document.getElementById(pFormulario.elements[i].idDigito).value;vValue=pFormulario.elements[i].value;if(vValue==undefined)continue;vValue=vValue.trim();vValue=(vValue!=' ')?vValue:'';pFormulario.elements[i].setAttribute('value',vValue);if(pFormulario.elements[i].title!=''){if(pFormulario.elements[i].type=='text'){if(pFormulario.elements[i].value.length==0||pFormulario.elements[i].value.toLowerCase()=='carregando...'||(pFormulario.elements[i].getAttribute('named')=='true'&&!pFormulario.elements[i].valueBck)){vMsg+='* '+pFormulario.elements[i].title+"\n";}
else if(pFormulario.elements[i].getAttribute('minlength')&&pFormulario.elements[i].value.length<pFormulario.elements[i].getAttribute('minlength')){vMsg+='* '+pFormulario.elements[i].title+" deve ter no mínimo "+pFormulario.elements[i].getAttribute('minlength')+" dígitos\n";}
else{expEmail=/^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;valor=pFormulario.elements[i].value;valorSemPontos=pFormulario.elements[i].value.replace(/\./g,'').replace(/\-/g,'').replace(/\//g,'');if(pFormulario.elements[i].name=="nmrCpf"&&!validarCpf(completaZero(valorSemPontos,10)))
vMsg+='* Número de CPF inválido! '+"\n";if(pFormulario.elements[i].name=="nmrCnpj"&&(valorSemPontos.length<13||!validarCnpj(completaZero(valorSemPontos,14))))
vMsg+='* Número de CNPJ inválido! '+"\n";if(pFormulario.elements[i].name=="nmrDoc"){if(document.getElementById('tp_pessoa_fisica')&&document.getElementById('tp_pessoa_juridica')){if(document.getElementById('tp_pessoa_fisica').checked&&!validarCpf(completaZero(valorSemPontos,10))){vMsg+='* Número do CPF inválido! '+"\n";}
if(document.getElementById('tp_pessoa_juridica').checked&&!validarCnpj(completaZero(valorSemPontos,14))){vMsg+='* Número do CNPJ inválido! '+"\n";}}else{if((!validarCpf(completaZero(valorSemPontos,10)))&&(!validarCnpj(completaZero(valorSemPontos,14))))
vMsg+='* Número do documento inválido! '+"\n";}}
if(pFormulario.elements[i].name=="responsavel"&&valor.trim().split(" ").length<2)
vMsg+='* Favor colocar o nome completo do Responsável! '+"\n";if(pFormulario.elements[i].name=="nmrCheque"&&!validarCheque(completaZero(valorSemPontos+vDigito,7)))
vMsg+='* Número de Cheque inválido! '+"\n";if(pFormulario.elements[i].name=="email"&&!expEmail.test(valor))
vMsg+='* Email inválido! '+"\n";}
vCheckedGroup=false;}else if(pFormulario.elements[i].type=='file'){if(pFormulario.elements[i].value=='')
vMsg+='* '+pFormulario.elements[i].title+"\n";vCheckedGroup=false;}else if(pFormulario.elements[i].type=='password'){if(pFormulario.elements[i].value=='')
vMsg+='* '+pFormulario.elements[i].title+"\n";vCheckedGroup=false;}else if(pFormulario.elements[i].type=='hidden'){if(pFormulario.elements[i].value=='')
vMsg+='* '+pFormulario.elements[i].title+"\n";vCheckedGroup=false;}else if(pFormulario.elements[i].type=='textarea'){if(pFormulario.elements[i].value=='')
vMsg+='* '+pFormulario.elements[i].title+"\n";vCheckedGroup=false;}else if(pFormulario.elements[i].type=='select-one'){if(pFormulario.elements[i].selectedIndex==-1)
pFormulario.elements[i].selectedIndex=0;if((pFormulario.elements[i].options[pFormulario.elements[i].selectedIndex].text=='')||(pFormulario.elements[i].options[pFormulario.elements[i].selectedIndex].text.toLowerCase().indexOf('selecione')!=-1))
vMsg+='* '+pFormulario.elements[i].title+"\n";vCheckedGroup=false;}else if(pFormulario.elements[i].type=='radio'){nomeGrupo=pFormulario.elements[i].name;if(pFormulario.elements[i].title!=''){var j=(i-1);do{j++;if(j<pFormulario.elements.length){if(pFormulario.elements[j].checked)
vCheckedGroup=true;}else
break;}while((pFormulario.elements[j].type=='radio')&&(pFormulario.elements[j].name==nomeGrupo))
j--;if(vCheckedGroup==false)
vMsg+='* '+pFormulario.elements[i].title+"\n";else
vCheckedGroup=false;i=j;}}}}
if(vMsg!=''){alert("Os campos abaixo devem ser preenchidos corretamente: \n\n"+vMsg);return false}
return true;}
function aceitaNumero(pCampo,e){c=e.keyCode;if(navigator.appName=="Netscape"&&parseInt(navigator.appVersion)==4){var mString=(e.modifiers+32).toString(2).substring(3,6);ctrlPressed=(mString.charAt(1)=="1");}
else
ctrlPressed=e.ctrlKey;if((((c>=48&&c<=57)||(c>=96&&c<=105)||(c>=37&&c<=40)||c==46||c==35||c==36||c==27||c==116||c==8||c==9||c==13||c==144)&&!ctrlPressed)||ctrlPressed){return true;}else
return false;}
function aceitaNumeroLetra(pCampo,e){c=e.keyCode;if(navigator.appName=="Netscape"&&parseInt(navigator.appVersion)==4){var mString=(e.modifiers+32).toString(2).substring(3,6);ctrlPressed=(mString.charAt(1)=="1");}
else
ctrlPressed=e.ctrlKey;if(((c>=48&&c<=57)||(c>=96&&c<=105)||(c>=37&&c<=40)||(c>=65&&c<=90)||c==46||c==35||c==36||c==27||c==116||c==8||c==9||c==13||c==144)&&!ctrlPressed){return true;}else
return false;}
function formataCampoNumero(pValor,pMascara){var mascara=pMascara.toUpperCase();var valorI=pValor;valor=valorI.replace(/\./g,'').replace(/\-/g,'').replace(/\//g,'');var retorno='';var iv=valor.length-1;var posLast=mascara.length;var posPri=mascara.length-valorI.length;var mnew=mascara.substr(posPri,posLast);var qtdNaoNumero=mascara.substr(posPri,posLast).replace(/\X/g,'').length;posPri=(posPri-qtdNaoNumero>0)?posPri-qtdNaoNumero:0;mnew=mascara.substr(posPri,posLast);for(im=mnew.length;im>=0;im--){cm=mnew.charAt(im);cv=valor.charAt(iv);if(cm=='X'){retorno=cv+retorno;iv--;}else if(cm!=''){retorno=cm+retorno;}}
return retorno;}
function soNumero(pValor){var vReturn='';for(i=0;i<pValor.length;i++){ch=pValor.charAt(i);if(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||ch=='6'||ch=='7'||ch=='8'||ch=='9')
vReturn+=ch;}
return vReturn;}
function soDinheiro(pValor){var vReturn='';for(i=0;i<pValor.length;i++){ch=pValor.charAt(i);if(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch==',')
vReturn+=ch;}
return vReturn;}
function blockCtrlCV(e){if(!e)e=window.event;var code;if(e.keyCode)code=e.keyCode;else if(e.which)code=e.which;var pressedKey=String.fromCharCode(code).toLowerCase();if(e.ctrlKey&&(pressedKey=="c"||pressedKey=="v")){e.cancelBubble=true;e.returnValue=false;if(e.stopPropagation){e.stopPropagation();e.preventDefault();}}}
function blockBtnDir(e){if(!e)e=window.event;var code;if(e.keyCode)code=e.keyCode;if(e.button==2){alert('www.CONSULTANET.com.br');}}
function dinheiro(pDinheiro){if(pDinheiro==undefined||pDinheiro==null||pDinheiro=='0'){vDinheiro="0,00";}else{vDinheiro=unescape(Number(pDinheiro).toFixed(2));vDinheiro=vDinheiro.replace(/\./g,',');}
return vDinheiro;}