var inputColor = '#C0D5E9';
function validaTecla(campo, event)
{
var BACKSPACE=8;
var VIRGULA = 44;
var MENOS = 45;
var key;
var tecla;
CheckTAB=true;
if(navigator.appName.indexOf("Netscape")!= -1) {
tecla= event.which;
} else {
tecla= event.keyCode;
}
key = String.fromCharCode(tecla);
if ( tecla == 13) {
return false;
}
if (tecla == BACKSPACE || tecla == 0 || (tecla == VIRGULA &&
campo.value.indexOf(',') == -1 && campo.value.length > 0) || (tecla ==
MENOS && campo.value.length == 0))
return true;
if (isNum(key))
return true;
return false;
}
function isNum(caractere){
var strValidos = "0123456789";
if (strValidos.indexOf(caractere) == -1)
return false;
return true;
}
function mascaraPercentual(obj,teclapres){
var strValidos = "0123456789,.";
var ultCarac = ''+obj.value;
var tecla = teclapres.keyCode;
ultCarac = ultCarac.substring(((ultCarac.length)-1),ultCarac.length);
if(strValidos.indexOf(ultCarac) > -1 ){
valor = obj.value;
valor = valor.replace(",",".");
valor = parseFloat(valor);
if(valor > 100){
tot = obj.value.length;
tot = parseInt(tot) - 1;
texto = ''+valor;
texto = texto.substring(0,tot);
texto = texto.replace(".","");
obj.value = texto;
for(x=0;x<obj.value.length;x++){
if(parseInt(obj.value) > 100){
tot = obj.value.length;
tot = parseInt(tot) - 1;
texto = ''+valor;
texto = texto.substring(0,tot);
texto = texto.replace(".","");
obj.value = texto;
}
}
}else{
for(x=0;x<obj.value.length;x++){
texto = obj.value;
texto = texto.replace(".",",");
obj.value = texto;
}
}
virgulas = new Array();
for(x=0;x<obj.value.length;x++){
virgulas = texto.split(",");
if(parseInt(virgulas.length-1) > 1){
tot = obj.value.length;
tot = parseInt(tot) - 1;
texto = texto.substring(0,tot);
obj.value = texto;
}
}
if(parseInt(virgulas.length-1) > 1){
tot = obj.value.length;
tot = parseInt(tot) - 1;
texto = texto.substring(0,tot);
obj.value = texto;
}
}else{
excluiUltCaracter(obj);
}
str = obj.value;
tam = str.length;
str = str.substr(0,3);
if(str == "100" && tam == 5 && tecla != 8){
obj.value = obj.value + "0";
}
str = obj.value;
if(str.charAt(1) == "," && tam == 5){
obj.value = str.substr(0,tam-1);
}
}
function excluiUltCaracter(obj){
valor = ''+obj.value;
obj.value = valor.substring(0,((valor.length)-1));
}
function formataValor(campo,tammax,teclapres) {
var tecla = teclapres.keyCode;
vr = campo.value;
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(tam < tammax && tecla != 8){
tam = vr.length;
}
if(tecla == 8 ){
tam = tam - 1 ;
}
if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
if( tam <= 2 ){
campo.value = vr;
}
if( (tam > 2) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam );
}
if( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
}
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
}
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
}
}
}
function criaMascara(_RefObjeto, _Modelo){
var valorAtual = _RefObjeto.value;
var valorNumerico = '';
var nIndexModelo = 0;
var nIndexString = 0;
var valorFinal = '';
var adicionarValor = true;
for (i=0;i<_Modelo.length;i++){
if (_Modelo.substr(i,1) != '#'){
valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
}
}
for (i=0;i<valorAtual.length;i++){
if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
valorNumerico = valorNumerico + valorAtual.substr(i,1);
}
}
for (i=0;i<_Modelo.length;i++){
if (_Modelo.substr(i,1) == '#'){
if (valorNumerico.substr(nIndexModelo,1) != ''){
valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
nIndexModelo++;nIndexString++;
} else {
adicionarValor = false;
}
} else {
if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
nIndexString++;
}
}
}
_RefObjeto.value = valorFinal;
}
function formatoMonetario(oque,tipo){
if(oque.value == "-" || oque.value == "") {
oque.value = ""
return;
}
retorno = '';
for (contador=0;contador < oque.value.length;contador++) {
if( (oque.value.charAt(contador) != ".")) {retorno += oque.value.charAt(contador);}
}
procurado = /,/;
retorno = retorno.replace(procurado, ".");
retorno = retornaFormatoMonetario(retorno-0,tipo);
oque.value = retorno;
}
function retornaFormatoMonetario(valor,tipo) {
if((valor-0) != 0 || (tipo == 1 && (valor-0) == 0) ) {
return parteInteira(Math.floor(valor-0) + '') + parteFracao(valor-0);
}
else return '';
}
function parteFracao(resto) {
resto = Math.round( ( (resto) - Math.floor(resto) ) *100);
return (resto < 10 ? ',0' + resto : ',' + resto)};
function parteInteira(valor) {
if(valor.length <= 3)
return (valor == '' ? '0' : valor);
else {
vezes = valor.length % 3;
retorno = (vezes == 0 ? '' : (valor.substring(0,vezes)));
for (i=0 ; i < Math.floor(valor.length/3) ; i++) {
if( (vezes ==0) && (i ==0) )
retorno += valor.substring(vezes + 3 * i,vezes + 3 * i + 3);
else
retorno += '.' + valor.substring(vezes + 3 * i,vezes + 3 * i + 3);
}
retorno = retorno.replace(/-\./,"-");
return (retorno);
}
}
function retornaFormatoMonetarioInteiro(valor) {
if((valor-0) != 0) {
return parteInteira(Math.floor(valor-0) + '');
}
else return '';
}
function mascara(oque,tipo,tamanho1,tamanho2,sinal)
{
if( (event.keyCode == 8) || (event.keyCode == 13) || (event.keyCode == 37) || (event.keyCode == 39) || (event.keyCode == 46) || (event.keyCode == 16))
{
return;
}
if(tamanho1 != null) {tamanho1 = parseInt(tamanho1);}
if(tamanho2 != null) {tamanho2 = parseInt(tamanho2);}
retorno = '';
switch (tipo) {
case 'cep':
{
oque.maxLength=9;
retorno = limpaParaMascara(oque.value,'numeros');
retorno = retorno.substr(0,9);
if(retorno.length >= 8 && (retorno-0 == 0) )  {
alert(retorno.substr(0,5)+"-"+retorno.substr(5,7)+"\n"+"CEP inválido.");
oque.value="";
oque.focus();
return;
}
if(retorno.length >= 5) { retorno = retorno.substr(0,5)+"-"+retorno.substr(5,7); }
oque.value = retorno.substr(0,9);
break;
}
case 'cpf':
{
oque.maxLength=14;
retorno = limpaParaMascara(oque.value,'numeros');
if(retorno.length >= 3)  { retorno = retorno.substr(0,3) +"."+retorno.substr(3) ;}
if(retorno.length >= 7)  { retorno = retorno.substr(0,7) +"."+retorno.substr(7) ;}
if(retorno.length >= 11) { retorno = retorno.substr(0,11)+"-"+retorno.substr(11);}
oque.value = retorno.substr(0,14);
if(retorno.length >= 14) {
if(!validaCPF(retorno))
{
alert(oque.value+"\n"+"CPF inválido.");
oque.value="";
oque.focus();
return;
}
}
break;
}
case 'cgc':
{
oque.maxLength=18;
retorno = limpaParaMascara(oque.value,'numeros');
if(retorno.length >= 2)  { retorno = retorno.substr(0,2)+"."+retorno.substr(2); }
if(retorno.length >= 6)  { retorno = retorno.substr(0,6)+"."+retorno.substr(6); }
if(retorno.length >= 10) { retorno = retorno.substr(0,10)+"/"+retorno.substr(10); }
if(retorno.length >= 15) { retorno = retorno.substr(0,15)+"-"+retorno.substr(15); }
oque.value = retorno.substr(0,18);
if(retorno.length >= 18)
{
if(!validaCGC(retorno))
{
alert(oque.value+"\n"+"CNPJ inválido.");
oque.focus();
return;
}
}
break;
}
case 'cnpj10':
{
oque.maxLength=10;
retorno = limpaParaMascara(oque.value,'numeros');
if(retorno.length >= 2)  { retorno = retorno.substr(0,2)+"."+retorno.substr(2); }
if(retorno.length >= 6)  { retorno = retorno.substr(0,6)+"."+retorno.substr(6); }
oque.value = retorno.substr(0,10);
break;
}
case 'ddd': {
oque.maxLength=4;
retorno = limpaParaMascara(oque.value,'numeros');
retorno = retorno.substr(0,4);
if(retorno.length >= 4 && (retorno-0 == 0) )  {
alert("O DDD não pode ser "+retorno+".");
oque.value="";
oque.focus();
return;
}
oque.value = retorno.substr(0,4);
break;	}
case 'ramal': {
oque.maxLength=4;
retorno = limpaParaMascara(oque.value,'numeros');
oque.value = retorno.substr(0,4);
break;	}
case 'fone': {
oque.maxLength=10;
retorno = limpaParaMascara(oque.value,'numeros');
oque.value = retorno.substr(0,10);
break;	}
case 'celular': {
oque.maxLength=10;
retorno = limpaParaMascara(oque.value,'numeros');
oque.value = retorno.substr(0,10);
break;	}
case 'DD/MM/AA':
{
oque.maxLength=8;
retorno = limpaParaMascara(oque.value,'numeros');
if(retorno.length >= 2) { retorno = retorno.substr(0,2)+"/"+retorno.substr(2); }
if(retorno.length >= 5) { retorno = retorno.substr(0,5)+"/"+retorno.substr(5); }
oque.value = retorno.substr(0,8);
if(retorno.length >= 8)
{
dataEmTeste = retorno.substr(0,6)+'20'+retorno.substr(6,2) ;
if(!retornaValidaData(dataEmTeste))
{
oque.value="";
oque.focus();
return;
}
}
break;
}
case 'DD/MM/AAAA':
{
oque.maxLength=10;
retorno = limpaParaMascara(oque.value,'numeros');
if(retorno.length >= 2)
{
retorno = retorno.substr(0,2)+"/"+retorno.substr(2);
}
if(retorno.length >= 5)
{
retorno = retorno.substr(0,5)+"/"+retorno.substr(5);
}
oque.value = retorno.substr(0,10);
if(retorno.length >= 10)
{
if(!retornaValidaData(oque.value))
{
oque.focus();
return;
}
}
break;
}
case 'MM/AAAA': {
oque.maxLength=7;
retorno = limpaParaMascara(oque.value,'numeros');
if(retorno.length >= 2) { retorno = retorno.substr(0,2)+"/"+retorno.substr(2); }
oque.value = retorno.substr(0,7);
if(retorno.length >= 7) {
dataEmTeste = '01/'+retorno
if(!retornaValidaData(dataEmTeste)) {
oque.value="";
oque.focus();
return;
}
}
break;	}
case 'IE':
{
oque.maxLength=14;
break;
}
case 'caracter':
{
break;
}
case 'numero':
{
if(tamanho1 != null)
oque.maxLength = tamanho1;
retorno = limpaParaMascara(oque.value,'numeros');
oque.value = retorno.substr(0,oque.maxLength);
break;
}
case 'valor':
{
if( (tamanho1 != null) && (tamanho2 != null) )
{
if(tamanho2 == 0)
{
oque.maxLength = tamanho1;
}
else
{
oque.maxLength = tamanho1+1+tamanho2;
}
}
retorno = limpaParaMascara(oque.value,'valores',sinal);
retorno = limpaZerosAEsquerda(retorno,sinal);
posicaoPrimeiraVirgula = retorno.indexOf(",");
retorno = limpaParaMascara(retorno,'numeros',sinal);
if(posicaoPrimeiraVirgula > -1)
{
retorno = retorno.substr(0,posicaoPrimeiraVirgula)+","+retorno.substr(posicaoPrimeiraVirgula,2);
};
oque.value = retorno.substr(0,oque.maxLength);
break;
}
case 'valorDolar':
{
if( (tamanho1 != null) && (tamanho2 != null) )
{
if(tamanho2 == 0)
{
oque.maxLength = tamanho1;
}
else
{
oque.maxLength = tamanho1+1+tamanho2;
}
}
retorno = limpaParaMascara(oque.value,'valores',sinal);
retorno = limpaZerosAEsquerda(retorno,sinal);
posicaoPrimeiraVirgula = retorno.indexOf(",");
retorno = limpaParaMascara(retorno,'numeros',sinal);
if(posicaoPrimeiraVirgula > -1)
{
retorno = retorno.substr(0,posicaoPrimeiraVirgula)+","+retorno.substr(posicaoPrimeiraVirgula,tamanho2);
};
oque.value = retorno.substr(0,oque.maxLength);
break;
}
case 'percentual': {
oque.maxLength=3;
retorno = limpaParaMascara(oque.value,'numeros');
oque.value = retorno.substr(0,3);
break;	}
case 'cartao': {
oque.maxLength=19;
retorno = limpaParaMascara(oque.value,'numeros');
if(retorno.length >= 4) { retorno = retorno.substr(0,4)+" "+retorno.substr(4); }
if(retorno.length >= 9) { retorno = retorno.substr(0,9)+" "+retorno.substr(9); }
if(retorno.length >= 14) { retorno = retorno.substr(0,14)+" "+retorno.substr(14); }
oque.value = retorno.substr(0,19);
break;	}
case 'cc': {
oque.maxLength=13;
retorno = limpaParaMascara(oque.value,"numeros");
if(retorno.length >= 4) { retorno = retorno.substr(0,4) + "-" + retorno.substr(4); }
if(retorno.length >= 10) { retorno = retorno.substr(0,10) + "-" + retorno.substr(10); }
oque.value = retorno.substr(0,13);
break;	}
case 'poupanca': {
oque.maxLength=13;
retorno = limpaParaMascara(oque.value,"numeros");
if(retorno.length >= 4) { retorno = retorno.substr(0,4) + "-" + retorno.substr(4); }
if(retorno.length >= 11) { retorno = retorno.substr(0,11) + "-" + retorno.substr(11); }
oque.value = retorno.substr(0,13);
break;	}
case 'unidade': {
oque.maxLength=8;
retorno = limpaParaMascara(oque.value,"numeros");
if(retorno.length >= 5) { retorno = retorno.substr(0,5) + "-" + retorno.substr(5); }
oque.value = retorno.substr(0,8);
break; }
}
}
function limpaCampo(field) {
t_field='';
for (i=0;i<field.length;i++) {
if( (field.charAt(i) != ".") && (field.charAt(i) != "-") && (field.charAt(i) != "/") && (field.charAt(i) != ",")) {
t_field = t_field + field.charAt(i);
}
}
return t_field;
}
function formataCPF(paramCpf) {
cpfSemMascara = limpaParaMascara(paramCpf,'numeros');
if(cpfSemMascara.length == 11) {
cpfRetorno = '';
cpfRetorno += cpfSemMascara.substr(0,3);
cpfRetorno += ".";
cpfRetorno += cpfSemMascara.substr(3,3);
cpfRetorno += ".";
cpfRetorno += cpfSemMascara.substr(6,3);
cpfRetorno += "-";
cpfRetorno += cpfSemMascara.substr(9,2);
return cpfRetorno;
} else {
return paramCpf;
}
}
function formataCGC(paramCgc) {
cgcSemMascara = limpaParaMascara(paramCgc,'numeros');
if(cgcSemMascara.length == 14) {
cgcRetorno = '';
cgcRetorno = cgcSemMascara.substr(0,2);
cgcRetorno += '.';
cgcRetorno += cgcSemMascara.substr(2,3);
cgcRetorno += '.';
cgcRetorno += cgcSemMascara.substr(5,3);
cgcRetorno += '/';
cgcRetorno += cgcSemMascara.substr(8,4);
cgcRetorno += '-';
cgcRetorno += cgcSemMascara.substr(12,2);
return cgcRetorno;
}
else {
return paramCgc;
}
}
function formataCpfECnpj(campo){
str = campo.value;
if(str.length == 11){
campo.value = formataCPF(campo.value);
}
if(str.length == 14){
campo.value = formataCGC(campo.value);
}
}
function formataCEP(paramCep) {
cepSemMascara = limpaParaMascara(paramCep,'numeros');
if(cepSemMascara.length == 8) {
cepRetorno = '';
cepRetorno = cepSemMascara.substr(0,5);
cepRetorno += '-';
cepRetorno += cepSemMascara.substr(5,8);
return cepRetorno;
}
else {
return paramCep;
}
}
function desabilitaCampo(str) {
arrDesabilita = new Array();
arrDesabilita = str.split(",")
for (i=0; i<arrDesabilita.length; i++) {
obj = eval("document.form."+arrDesabilita[i])
if(obj != null) {
obj.disabled = true;
}
}
}
function limpaParaMascara(sujeira,filtro,tipo){
numeros = "0123456789";
valores = "0123456789,";
letras  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÂÊÎÔÛÃÕáéíóúàèìòùäëïöüâêîôûãõçÇ&ªº'\"\|@_<>!#$%&*()={[}]?:+-.,;/\\0123456789 ";
retorno2 = '';
if(tipo == 1) {
if(sujeira.substring(0,1) == "-") ind = 1;
else ind = 0;
}
else ind = 0;
switch (filtro){
case 'numeros': {
for ( i=ind; i < sujeira.length; i++ ) {
if( numeros.indexOf(sujeira.charAt(i))>-1 ) {
retorno2 += sujeira.charAt(i);
}
}
break;	}
case 'valores': {
for ( i=ind; i < sujeira.length; i++ ) {
if( valores.indexOf(sujeira.charAt(i))>-1 ) {
retorno2 += sujeira.charAt(i);
}
}
if(sujeira.charAt && sujeira.charAt(0)=='-') {
retorno2 = "-"+retorno2;
}
break;	}
case 'letras': {
for ( i=0; i < sujeira.length; i++ ) {
if( letras.indexOf(sujeira.charAt(i))>-1 ) {
retorno2 += sujeira.charAt(i);
}
}
break;	}
}
if(tipo == 1) {
if(sujeira.substring(0,1) == "-") retorno2 = "-" + retorno2;
}
return retorno2;
}
function strToDate(str){
var dia, mes, ano, ret;
dia = str.substr(0,2);
mes = str.substr(3,2) - 1;
ano = str.substr(6,4);
ret = new Date(ano, mes, dia, 0, 0, 0, 0);
return ret;
}
function dateToStr(data){
if(data == null){
data = new Date();
}
d = data.getDate();
d = (d<10?'0'+d:d);
m = (data.getMonth()+1);
m = (m<10?'0'+m:m);
a = data.getFullYear()
return (d+"/"+m+"/"+a)
}
function emFoco(obj, bg){
obj.style.backgroundColor = bg;
}
function colocaFoco(campo){
if(campo.disabled != true){
campo.focus();
}
}
function retornaValorFormatado(valor, d){
var deci;
var inteiro;
var retorno = '-';
deci = '';
if(!isNaN(valor))	{
if(valor.indexOf('.') >= 0) {
inteiro = valor.substr(0, valor.indexOf('.'));
deci = valor.substr(valor.indexOf('.')+1);
} else {
inteiro = valor;
}
inteiro = retornaFormatoMonetarioInteiro(inteiro);
if(typeof(d)=='undefined'){
d = 2;
}
while(deci.length < d) {
deci = deci + '0';
}
if (deci=='') {
retorno = inteiro;
} else {
retorno = (inteiro+','+deci);
}
}
return retorno;
}
function limpaCampos(idForm) {
var searchStr = new RegExp('\x160', 'g');
for(i=0;i<idForm.length;i++)
{
if (idForm.elements[i].type != 'button'){
idForm.elements[i].value = '';
}
}
}
function strToNum(str) {
num = "-0123456789";
ret = "";
if ((str == '') || (str.charCodeAt(0) == 160)) {
ret = '0';
}
else{
if (str.indexOf(',') > -1){
for (i=0; i<str.length; i++){
if (num.indexOf(str.charAt(i)) > -1){
ret += str.charAt(i);
}
else if ((str.charAt(i) == ',')){
ret += '.';
}
}
}
else{
return parseFloat(str);
}
}
return parseFloat(ret);
}
function desabilitaLinks(){
for(x=0;x<document.links.length;x++){
document.links[x].href = "#";
}
}
function desabilitaCampos(){
for(i=0;i<document.forms.length;i++){
for(x=0;x<document.forms[i].length;x++){
if(document.forms[i].elements[x].type){
if(document.forms[i].elements[x].type.toUpperCase() == "TEXT"){
document.forms[i].elements[x].readOnly = true;
}else{
document.forms[i].elements[x].disabled = true;
}
}
}
}
}
function habilitaCampos(){
for(i=0;i<document.forms.length;i++){
for(x=0;x<document.forms[i].length;x++){
document.forms[i].elements[x].disabled = false;
}
}
}
function limitaTextArea(obj, max, event){
if(max != ''){
max = parseInt(max);
valor = ''+obj.value;
if(valor.length >= max){
event.returnValue = false;
}
}
}
function mascaraCpfCNPJ(obj){
if(obj.value.length <  15){
criaMascara(obj,"###.###.###-##");
}else{
criaMascara(obj,"##.###.###/####-##");
}
}
function zerosdireita(campo,valor) {
tamanho = valor.length;
valor_num = strToNum(valor);
if(tamanho <= 3 && valor.indexOf(',')<0){
valor = valor + ",00";
}
if(valor.substring(tamanho - 1,tamanho) == ",") {
valor = valor + "00";
}
if(valor.substring(tamanho - 2,tamanho - 1) == ",") {
valor = valor + "0";
}
if(valor.substring(tamanho - 4,tamanho - 3) == ".") {
valor = valor + ",00";
}
if(valor.substring(tamanho - 5,tamanho - 4) == ".") {
valor = valor.replace( "/", "" );
valor = valor.replace( "/", "" );
valor = valor.replace( ",", "" );
valor = valor.replace( ".", "" );
valor = valor.replace( ".", "" );
valor = valor.replace( ".", "" );
valor = valor.replace( ".", "" );
tam = valor.length;
if( tam <= 3 ){
valor = vr;
}
if( (tam > 3) && (tam <= 6) ){
valor = valor.substr( 0, tam - 3 ) + '.' + valor.substr( tam - 3, tam );
}
if( (tam >= 7) && (tam <= 9) ){
valor = valor.substr( 0, tam - 6 ) + '.' + valor.substr( tam - 6, 3 ) + '.' + valor.substr( tam - 3, tam );
}
if ( (tam >= 10) && (tam <= 12) ){
valor = valor.substr( 0, tam - 9 ) + '.' + valor.substr( tam - 9, 3 ) + '.' + valor.substr( tam - 6, 3 ) + '.' + valor.substr( tam - 3, tam );
}
if ( (tam >= 13) && (tam <= 15) ){
valor = valor.substr( 0, tam - 12 ) + '.' + valor.substr( tam - 12, 3 ) + '.' + valor.substr( tam - 9, 3 ) + '.' + valor.substr( tam - 6, 3 ) + '.' + valor.substr( tam - 3, tam );
}
if ( (tam >= 16) && (tam <= 18) ){
valor = valor.substr( 0, tam - 15 ) + '.' + valor.substr( tam - 15, 3 ) + '.' + valor.substr( tam - 12, 3 ) + '.' + valor.substr( tam - 9, 3 ) + '.' + valor.substr( tam - 6, 3 ) + '.' + valor.substr( tam - 3, tam );
}
valor = valor + ",00";
}
campo.value = valor;
formataValor2(campo);
if(valor_num == 0) {
valor = "0,00";
campo.value = valor;
}
}
function limpaZerosAEsquerda(inputString,tipo) {
outputString  = '';
espacosAntes  = 0;
if(tipo == 1) {
re = /^0*$/;
res = inputString.match(re);
if(inputString.substr(0,1) != "-" && res == null) inic = 0;
else  inic = 1;
}
else inic = 0;
for(i = inic ; i < inputString.length ; i++){
if(inputString.charAt(i) == '0'){ espacosAntes++; }
else {	break;	}
}
outputString =  inputString.substr(espacosAntes);
return outputString;
}
function formataValor2(campo) {
vr = campo.value;
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( tam <= 2 ){
campo.value = vr;
}
if( (tam > 2) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam );
}
if( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
}
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
}
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
}
}
function formataValor3(campo,tammax,teclapres) {
var tecla = teclapres.keyCode;
vr = campo.value;
tamanho = vr.length;
if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 || tecla == 110 ){
if((vr.substring(tamanho - 4,tamanho - 3) == ",") ||
(vr.substring(tamanho - 3,tamanho - 2) == ",") ||
(vr.substring(tamanho - 2,tamanho - 1) == ",")) {
if(tecla == 110){
campo.value = vr.substring(0,tamanho - 1);
}
}
else {
if(vr.substring(tamanho - 1,tamanho) == "," ||
vr.substring(tamanho - 2,tamanho - 1) == "," ||
vr.substring(tamanho - 3,tamanho - 2) == "," ) {
if(tecla == 44){
return false;
}
}
else {
vr = campo.value;
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(tam < tammax && tecla != 8){
tam = vr.length;
}
if(tecla == 8 ){
tam = tam - 1 ;
}
if( tam <= 3 ){
campo.value = vr;
}
if( (tam > 3) && (tam <= 6) ){
campo.value = vr.substr( 0, tam - 3 ) + '.' + vr.substr( tam - 3, tam );
}
if( (tam >= 7) && (tam <= 9) ){
campo.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam );
}
if ( (tam >= 10) && (tam <= 12) ){
campo.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam );
}
if ( (tam >= 13) && (tam <= 15) ){
campo.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam );
}
if ( (tam >= 16) && (tam <= 18) ){
campo.value = vr.substr( 0, tam - 15 ) + '.' + vr.substr( tam - 15, 3 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam );
}
}
}
}
}
function formataValorMonetario(campo,tammax,teclapres,decimais,inteiros,isPonto) {
var tecla = teclapres.keyCode;
str = campo.value;
if(tecla >= 37 && tecla <=40 && tecla == 8)
return;
if(tecla == 32){
event.returnValue = false;
}
str = limpaParaMascara(str,'valores');
str = trim(str);
if((typeof(decimais) == 'undefined' || decimais == "") && decimais != '0'){
decimais = 2;
}
else{
decimais = parseInt(decimais);
}
if(typeof(inteiros) == 'undefined' || inteiros == "" && typeof(inteiros) != 'number'){
inteiros = 13;
}
else{
inteiros = parseInt(inteiros);
}
virgula = str.indexOf(',');
if(tecla != 110 && tecla != 188 && tecla != 8 && tecla != 9){
if(virgula == -1){
strpt = str;
strpt = strpt.replace( ".", "" );
strpt = strpt.replace( ".", "" );
strpt = strpt.replace( ".", "" );
strpt = strpt.replace( ".", "" );
if(strpt.length >= inteiros){
event.returnValue = false;
}
}
}
if(tecla == 110 || tecla == 188){
virgula = 0;
for(i=0;i<str.length;i++){
if(str.charAt(i) == ','){
virgula+=1;
}
}
if((virgula > 0) || (decimais == 0)){
event.returnValue = false;
}
}
virgula = str.indexOf(',');
if(virgula != -1){
strpt = str.substring(0,virgula-1);
strvg = str.substring(virgula-1,str.length);
}
else{
strpt = str;
strvg = '';
}
var sinal = strpt.charAt(0);
if (sinal == '-') {
strpt = strpt.replace('-','');
} else {
sinal = '';
}
for(i=0;i<=str.length;i++){
str = str.replace(/[\s]/,"");
}
for(i=0;i<=strpt.length;i++){
strpt = strpt.replace('.','');
strpt = strpt.replace(' ','');
}
if(inteiros != strpt.length) tam = strpt.length + 1;
else tam = strpt.length;
isPonto ? ponto = "." : ponto = "";
if(strvg.length <= 3 && ((96 <= tecla && tecla <= 105) || (48 <= tecla && tecla <= 57) && tecla != 110 && tecla != 188 && tecla != 8)){
if( tam <= 3 ){
strpt = strpt;
}
if( (tam > 3) && (tam <= 6) ){
strpt = strpt.substr( 0, tam - 3 ) + ponto + strpt.substr( tam - 3, tam );
}
if( (tam >= 7) && (tam <= 9) ){
strpt = strpt.substr( 0, tam - 6 ) + ponto + strpt.substr( tam - 6, 3 ) + ponto + strpt.substr( tam - 3, tam );
}
if ( (tam >= 10) && (tam <= 12) ){
strpt = strpt.substr( 0, tam - 9 ) + ponto + strpt.substr( tam - 9, 3 ) + ponto + strpt.substr( tam - 6, 3 ) + ponto + strpt.substr( tam - 3, tam );
}
if ( (tam >= 13) && (tam <= 15) ){
strpt = strpt.substr( 0, tam - 12 ) + ponto + strpt.substr( tam - 12, 3 ) + ponto + strpt.substr( tam - 9, 3 ) + ponto + strpt.substr( tam - 6, 3 ) + ponto + strpt.substr( tam - 3, tam );
}
if ( (tam >= 16) && (tam <= 18) ){
strpt = strpt.substr( 0, tam - 15 ) + ponto + strpt.substr( tam - 15, 3 ) + ponto + strpt.substr( tam - 12, 3 ) + ponto + strpt.substr( tam - 9, 3 ) + ponto + strpt.substr( tam - 6, 3 ) + ponto + strpt.substr( tam - 3, tam );
}
campo.value = sinal + strpt + strvg;
}
}
function verificaDecimais(campo,tammax,teclapres,decimais,inteiros){
var tecla = teclapres.keyCode;
if(typeof(decimais) == 'undefined' || decimais == ""){
decimais = 2;
}
else{
decimais = parseInt(decimais);
}
str = campo.value;
str = limpaParaMascara(str,'valores');
str = trim(str);
virgula = str.indexOf(',');
if(virgula != -1){
virgula+= 1;
if((96 <= tecla && tecla <= 105) || (48 <= tecla && tecla <= 57) && tecla != 110 && tecla != 188 && tecla != 8){
tam = str.length;
if(tam - virgula>decimais){
campo.value = str.substring(0,tam - 1);
}
}
}
}
function fmtaMonetario(campo,decimais,isPonto,inteiros){
str = campo.value;
if(str != ""){
var resultado = '';
var strpt;
var virgula;
isPonto ? ponto = "." : ponto = "";
if((typeof(decimais) == 'undefined' || decimais == "") && decimais != '0'){
decimais = 2;
}
else{
decimais = parseInt(decimais);
}
str = limpaParaMascara(str,'valores');
str = trim(str);
limpo = false;
tam = str.length;
strLimpa = "";
for(i=0;i<=tam;i++){
str.charAt(i) == '0' && limpo == false ? strLimpa = str.substring(i+1,str.length) : limpo = true;
}
if((typeof(strLimpa) != 'undefined' && strLimpa != "") || str == 0){
str = strLimpa;
}
virgula = str.indexOf(',');
strpt = str.substring(0,virgula);
virgulaCont = 0;
for(i=0;i<str.length;i++){
if(str.charAt(i) == ","){
virgulaCont++;
}
}
if(strpt.length > inteiros || virgulaCont > 1){
alert("Campo inválido. Digite novamente.");
campo.value = "";
}
else{
if(virgula != -1){
if(virgula == 0){
str = "0" + str;
virgula = str.indexOf(',');
}
tam = str.length;
decimaisCampo = tam - virgula;
if(decimaisCampo > decimais){
resultado+= str.substring(virgula,virgula + decimais + 1);
}
else{
strvg = str.substring(virgula+1,tam);
if(decimais > strvg.length){
resultado+= "," + strvg;
completa = decimais - strvg.length;
for(i=0;i<completa;i++){
resultado+= '0';
}
}
}
}
else{
if(decimais != 0){
if(str == ""){
resultado+= "0";
}
resultado+= ",";
for(i=0;i<decimais;i++){
resultado+= '0';
}
}
}
if(virgula == -1){
virgula = str.length;
}
sep = 0;
for (pos=virgula-1;pos >= 0;pos--){
sep ++;
if (sep > 3){
resultado = ponto + resultado;
sep = 1;
}
resultado = str.charAt(pos) + resultado;
}
campo.value = resultado;
}
}
}
function mudaFormatoData(data){
ano = data.substr(6,4);
mes = data.substr(3,2);
dia = data.substr(0,2);
data_nova = ano+""+mes+""+dia;
return data_nova;
}
function mudaFormatoDataDiaMes(data){
mes = data.substr(3,2);
dia = data.substr(0,2);
data_nova = mes+""+dia;
return data_nova;
}
function mudaFormatoDataMesAno(data){
mes = data.substr(0,2);
ano = data.substr(3,4);
data_nova = ano+""+mes;
return data_nova;
}
function Calcula_Dias(data1_DDMMYYYY,data2_DDMMYYYY){
Var_Dia1=Dia(data1_DDMMYYYY);
Var_Mes1=Mes(data1_DDMMYYYY);
Var_Mes1=Math.floor(Var_Mes1)-1;
Var_Ano1=Ano(data1_DDMMYYYY);
var data1 = new Date(Var_Ano1,Var_Mes1,Var_Dia1);
Var_Dia2=Dia(data2_DDMMYYYY);
Var_Mes2=Mes(data2_DDMMYYYY);
Var_Mes2=Math.floor(Var_Mes2)-1;
Var_Ano2=Ano(data2_DDMMYYYY);
var data2 = new Date(Var_Ano2,Var_Mes2,Var_Dia2);
var diferenca = data1.getTime() - data2.getTime();
var diferenca = Math.floor(diferenca / (1000 * 60 * 60 * 24));
return diferenca;
}
function Dia(Data_DDMMYYYY){
string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
if (posicao_barra!= -1){
dia = string_data.substring(0,posicao_barra);
return dia;
}else{
return false;
}
}
function Mes(Data_DDMMYYYY){
string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
if (posicao_barra!= -1){
dia = string_data.substring(0,posicao_barra);
string_mes = string_data.substring(posicao_barra+1,string_data.length);
posicao_barra = string_mes.indexOf("/");
if (posicao_barra!= -1){
mes = string_mes.substring(0,posicao_barra);
mes = Math.floor(mes);
return mes;
}else{
return false;
}
}else{
return false;
}
}
function Ano(Data_DDMMYYYY){
string_data = Data_DDMMYYYY.toString();
posicao_barra = string_data.indexOf("/");
if (posicao_barra!= -1){
dia = string_data.substring(0,posicao_barra);
string_mes = string_data.substring(posicao_barra+1,string_data.length);
posicao_barra = string_mes.indexOf("/");
if (posicao_barra!= -1){
mes = string_mes.substring(0,posicao_barra);
mes = Math.floor(mes);
ano = string_mes.substring(posicao_barra+1,string_mes.length);
return ano;
}else{
return false;
}
}else{
return false;
}
}
function trimWhiteSpaces(sString)
{
sTrimmedString = "";
if (sString != ""){
var iStart = 0;
var iEnd = sString.length  - 1;
var sWhitespace = " \t\f\n\r\v";
while (sWhitespace.indexOf(sString.charAt(iStart)) != -1){
iStart++;
if (iStart > iEnd)
break;
}
if (iStart <= iEnd){
while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
iEnd--;
sTrimmedString = sString.substring(iStart,++iEnd);
}
}
return sTrimmedString;
}
function converteMaiuscula(campo,teclapres){
tecla = teclapres.keyCode;
if(tecla >= 65 && tecla <= 90 || tecla == 186){
campo.value = campo.value.toUpperCase();
}
}
function completaString(varia, carac, cont, orient) {
var indice = cont - varia.length;
if (varia.length > 0) {
if(orient == 'D' || orient == 'd') {
for(x = 0; x < indice; x++) {
varia = varia + carac;
}
} else {
for(x = 0; x < indice; x++) {
varia = carac + varia;
}
}
}
return varia;
}
var MSIE = (document.all);
var NSN4 = (document.layers);
function showHideSelect(isOn){
var iForm;
var iElement;
var sTipo;
if(MSIE) {
for(iForm=0; iForm < document.forms.length; iForm++){
for(iElement=0; iElement < document.forms[iForm].elements.length; iElement++){
sTipo = document.forms[iForm].elements[iElement].type;
if( sTipo== "select-one" || sTipo == "select-multiple"){
document.forms[iForm].elements[iElement].style.visibility = isOn ? "visible" : "hidden";
}
}
}
} else if(NSN4) {
if(window.document.estapagina)
window.document.estapagina.visibility = isOn ? "show" : "hide";
}
}
function trocaMensagemAlerta(exibir, nivel, mensagem) {
if (exibir && document.getElementById("msgAlerta_msg1")) {
document.getElementById("msgAlerta_img1").src = contexto + "_image/CONTEUDO_" + nivel + "_topo_esquerda.gif";
document.getElementById("msgAlerta_msg1").background = contexto + "_image/CONTEUDO_" + nivel + "_fundo.gif";
document.getElementById("msgAlerta_msg2").background = contexto + "_image/CONTEUDO_" + nivel + "_fundo.gif";
document.getElementById("msgAlerta_msg2").innerHTML = nivel.charAt(0).toUpperCase() + nivel.substring(1, nivel.length);
document.getElementById("msgAlerta_img3").src = contexto + "_image/CONTEUDO_" + nivel + "_topo_direita.gif";
document.getElementById("msgAlerta_msg3").background = contexto + "_image/CONTEUDO_" + nivel + "_fundo.gif";
document.getElementById("msgAlerta_msg4").background = contexto + "_image/CONTEUDO_" + nivel + "_fundo.gif";
document.getElementById("msgAlerta_msg5").background = contexto + "_image/CONTEUDO_" + nivel + "_fundo.gif";
document.getElementById("msgAlerta_msg6").background = contexto + "_image/CONTEUDO_" + nivel + "_fundo.gif";
document.getElementById("msgAlerta_img7").src = contexto + "_image/CONTEUDO_" + nivel + "_baixo_esquerda.gif";
document.getElementById("msgAlerta_msg8").background = contexto + "_image/CONTEUDO_" + nivel + "_fundo.gif";
document.getElementById("msgAlerta_img9").src = contexto + "_image/CONTEUDO_" + nivel + "_baixo_direita.gif";
document.getElementById("msgAlerta_msg5").innerHTML = mensagem;
nivelUp = nivel.charAt(0).toUpperCase() + nivel.substr(1);
document.getElementById("msgAlerta_msg2").className = "errorTextBold_"+nivelUp;
document.getElementById("msgAlerta_msg5").className = "lightTextBold_"+nivelUp;
document.getElementById("msgAlerta_table").style.display = "block";
}else if (!exibir){
document.getElementById("msgAlerta_table").style.display = "none";
document.getElementById("msgAlerta_msg2").innerHTML = "";
document.getElementById("msgAlerta_msg5").innerHTML = "";
}
}
function selecionaTodos(acao,total,chk){
if(acao == "seleciona"){
for(i=0;i<total+1;i++){
campo = chk + i;
document.getElementById(campo).checked = true;
}
}
else if(acao == "nseleciona"){
for(i=0;i<total+1;i++){
campo = chk + i;
document.getElementById(campo).checked = false;
}
}
else if(acao == "inverte"){
for(i=0;i<total+1;i++){
campo = chk + i;
marcado = document.getElementById(campo).checked;
if(marcado){
document.getElementById(campo).checked = false;
}
else{
document.getElementById(campo).checked = true;
}
}
}
else{
if(typeof(total) == 'undefined' || total == ''){
i = 0;
campo = chk + i;
continua = false;
while(!continua){
campo = chk + i;
i++;
if(document.getElementById(campo)){
if(acao == true){
document.getElementById(campo).checked = true;
}
else{
document.getElementById(campo).checked = false;
}
}
else{
continua = true;
}
}
}
else{
for(i=0;i<total+1;i++){
campo = chk + i;
if(acao == true){
document.getElementById(campo).checked = true;
}
else{
document.getElementById(campo).checked = false;
}
}
}
}
}
function trocaObrigatorio (nome, troca){
for(x=0;x<obrigatorios.length;x++){
if (obrigatorios[x] == nome){
isObrigatorios[x] = troca;
if(document.getElementById('asterisco_'+nome)){
if (troca == 'sim'){
document.getElementById('asterisco_'+nome).innerHTML = '&nbsp;*';
} else {
document.getElementById('asterisco_'+nome).innerHTML = '';
}
}
break;
}
}
}
function mascaraDia(obj){
mascara(obj,'numero');
if(obj.value > 31 || obj.value < 1){
if(obj.value.length > 1){
auxValor = ''+obj.value;
obj.value = auxValor.substring(0,1);
}else{
obj.value = "";
}
}
}
function mascaraDia(obj){
mascara(obj,'numero');
if(obj.value > 31 || obj.value < 1){
if(obj.value.length > 1){
auxValor = ''+obj.value;
obj.value = auxValor.substring(0,1);
}else{
obj.value = "";
}
}
}
function identificaCampoAlterado (original, alterado){
if (original){
if (original.value != alterado.value){
return true;
}
else{
return false;
}
}
}
function trocaDescricao (nome, novoNome){
for(x=0;x<obrigatorios.length;x++){
if (obrigatorios[x] == nome){
nomesObrigatorios[x] = novoNome;
break;
}
}
}
function ajustaAlturaIframe(pai, campo, distanciaInferior, largura) {
try {
var distanciaTopo = 0;
distanciaTopo = findPosY(campo, pai);
aumentaIframe(distanciaTopo + distanciaInferior, largura, pai);
} catch (excecao){}
}
function aumentaIframe(altura, largura, pai) {
try {
pai.document.getElementById("tela_transacao").height = altura;
pai.document.getElementById("tela_transacao").width = largura;
} catch (excecao){}
}
function findPosX(obj, pai) {
try {
var curleft = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
}
return curleft;
} catch (excecao) {}
}
function findPosY(obj, pai) {
try {
var curtop = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
}
return (parseInt(curtop)+20);
} catch (excecao) {}
}
function retornaParametroUrl(nomeParametro){
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i = 0; i< parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
if(key == nomeParametro){
return parms[i].substring(pos+1);
}
}
}
return "";
}
