Number.prototype.formata_moeda=function(c,d,t){var n=this,c=isNaN(c=Math.abs(c))?2:c,d=d==undefined?",":d,t=t==undefined?".":t,i=parseInt(n=(+n||0).toFixed(c))+"",j=(j=i.length)>3?j%3:0;return(j?i.substr(0,j)+t:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+t)+(c?d+(n-i).toFixed(c).slice(2):"");};
function isset(){return(typeof(arguments[0])=='undefined'||arguments[0]===null)?false:true;}
function trim(str){return str.replace(/^\s+|\s+$/g,"");}
function limpa_campo(obj){obj.value="";return;}
function funcaoredireciona(pagina){document.location.href=pagina;return;}
function formata_cep(obj){switch(obj.value.length){case 2:obj.value=obj.value+".";break;case 6:obj.value=obj.value+"-";break;}}
function formata_cep2(obj){switch(obj.value.length){case 5:obj.value=obj.value+"-";break;}}
function formata_cpf(obj){switch(obj.value.length){case 3:obj.value=obj.value+".";break;case 7:obj.value=obj.value+".";break;case 11:obj.value=obj.value+"-";break;}}
function valida_cpf(s){s=s.replace(".","");s=s.replace(".","");s=s.replace("-","");var i;var c=s.substr(0,9);var d1=0;var dv=s.substr(9,2);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 formata_cnpj(obj){switch(obj.value.length){case 2:obj.value=obj.value+".";break;case 6:obj.value=obj.value+".";break;case 10:obj.value=obj.value+"/";break;case 15:obj.value=obj.value+"-";break;}}
function valida_cnpj(a){var b,digitos,soma,i,resultado,pos,tamanho,digitos_iguais;a=a.replace("/","");a=a.replace("-","");a=a.replace(".","");a=a.replace(".","");digitos_iguais=1;if(a.length<14&&a.length<15)return false;for(i=0;i<a.length-1;i++)if(a.charAt(i)!=a.charAt(i+1)){digitos_iguais=0;break}if(!digitos_iguais){tamanho=a.length-2;b=a.substring(0,tamanho);digitos=a.substring(tamanho);soma=0;pos=tamanho-7;for(i=tamanho;i>=1;i--){soma+=b.charAt(tamanho-i)*pos--;if(pos<2)pos=9}resultado=soma%11<2?0:11-soma%11;if(resultado!=digitos.charAt(0))return false;tamanho=tamanho+1;b=a.substring(0,tamanho);soma=0;pos=tamanho-7;for(i=tamanho;i>=1;i--){soma+=b.charAt(tamanho-i)*pos--;if(pos<2)pos=9}resultado=soma%11<2?0:11-soma%11;if(resultado!=digitos.charAt(1))return false;return true}else return false}
function valida_email(mail){var er=new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);if(typeof(mail)=="string"){if(er.test(mail)){return true;}}else if(typeof(mail)=="object"){if(er.test(mail.value)){return true;}}else{return false;}}
function mascara_moeda(obj,sepMi,sepDe,e){var sep=0;var key='';var i=j=0;var len=len2=0;var strCheck='0123456789';var aux=aux2='';if(window.event)whichCode=e.keyCode;else if(e.which)whichCode=e.which;else whichCode=e.keyCode;if((whichCode==8)||(whichCode==0))return;if(whichCode==13)return true;key=String.fromCharCode(whichCode);if(strCheck.indexOf(key)==-1)return false;len=obj.value.length;for(i=0;i<len;i++)if((obj.value.charAt(i)!='0')&&(obj.value.charAt(i)!=sepDe))break;aux='';for(;i<len;i++)if(strCheck.indexOf(obj.value.charAt(i))!=-1)aux+=obj.value.charAt(i);aux+=key;len=aux.length;if(len==0)obj.value='';if(len==1)obj.value='0'+ sepDe+'0'+aux;if(len==2)obj.value='0'+sepDe+aux;if(len>2){aux2='';for(j=0,i=len-3;i>=0;i--){if(j==3){aux2+=sepMi;j=0;}aux2+=aux.charAt(i);j++;}obj.value='';len2=aux2.length;for(i=len2-1;i>=0;i--)obj.value+=aux2.charAt(i);obj.value+=sepDe+aux.substr(len-2,len);}return false;}
function campo_valor(a,b){if(b=='e'){if(a.value=='0,00')a.value=''}else if(b='s'){if((a.value=='')||(a.value==',00')||(a.value=='0')||(a.value=='0,0')||(a.value=='0,')||(a.value==',0')||(a.value==','))a.value='0,00'}}
function moeda2float(moeda){moeda=moeda.replace(".","");moeda=moeda.replace(".","");moeda=moeda.replace(",",".");return parseFloat(moeda);}
function somente_numero(e){var strCheck='0123456789';if(window.event)whichCode=e.keyCode;else if(e.which)whichCode=e.which;else whichCode=e.keyCode;if((whichCode==46)||(whichCode==8)||(whichCode==9)||(whichCode==0)||((whichCode>=96)&&(whichCode<=105))||((whichCode>=37)&&(whichCode<=40)))return true;if(whichCode==13)return false;key=String.fromCharCode(whichCode);if(strCheck.indexOf(key)==-1)return false;}
function formata_data(obj){switch(obj.value.length){case 2:obj.value=obj.value+"/";break;case 5:obj.value=obj.value+"/";break;}}
function formata_hora(obj){switch(obj.value.length){case 2:obj.value=obj.value+":";break;}}
function recupera_endereco(o,r,b,c,e,n){if(document.getElementById(r).value==""){document.getElementById(r).value=". . . Aguarde . . .";var vcep=document.getElementById(o).value;vcep=vcep.replace(".","");vcep=vcep.replace(".","");vcep=vcep.replace("-","");vcep=vcep.replace("-","");vcep=vcep.replace(",","");try{xmlhttp=new XMLHttpRequest();}catch(ee){try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(E){xmlhttp=false;}}}xmlhttp.open("GET","spark/includes/recupera_endereco.php?cep="+vcep,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){var response=xmlhttp.responseText;eval("var arr="+response);document.getElementById(r).value=trim(arr.rua);document.getElementById(b).value=trim(arr.bairro);document.getElementById(c).value=trim(arr.cidade);document.getElementById(e).value=trim(arr.uf);document.getElementById(n).focus();}};xmlhttp.send(null);}}
