/********************************************************************************/ /* VARIAVEIS PARA IDENTIFICAÇÃO DO SO E BROWSERs /* Descrição: identifica os navegadores e sistemas operacionais /* /*---------------------------------------------------------------------------------- /* Autor: -- /* Criação: /* Histórico: 16/12/2006 - adaptação /***********************************************************************************/ var agt = navigator.userAgent.toLowerCase(); var isIE = (agt.indexOf('msie') != -1); var isIE5 = (agt.indexOf('msie 5') != -1); var isIE6 = (agt.indexOf('msie 6') != -1); var isNotFF1 = (agt.indexOf('firefox/1.0.') != -1); var isFF = (agt.indexOf('firefox') != -1); var isOP8 = (agt.indexOf('opera 8') != -1); var isOP = (agt.indexOf('opera') != -1); var isWin = (agt.indexOf('windows') != -1); var isLinux = (agt.indexOf('linux') != -1); var isFedora = (agt.indexOf('fedora/1.0') != -1); var isFedora15 = (agt.indexOf('fedora/1.5') != -1); var isKonqueror = (agt.indexOf('konqueror') != -1); var isGecko = (agt.indexOf('gecko') != -1); var isNN = (agt.indexOf('netscape') != -1); // EVITANDO OUTROS NAVEGADORES FORA O IE E O FF //if(!isIE || !isFF){ // window.location.href='/sistema/logout.html'; // alert('ATENÇÃO:\n\nO sistema bloqueou o seu acesso!\nEntre em contato com o administrador!\n\nQuality Entregas 2007.'); //} /********************************************************************************/ /* Função:jsvSomenteNumeros(evt) /* Descrição: Abre uma caixa de "Diálogo" para o usuário. /* /* Parâmetros: evt - event /*---------------------------------------------------------------------------------- /* Autor: Giovanni Donda /* Criação: 06/12/2006 /* Histórico: 06/12/2006 - Criação da Função /***********************************************************************************/ function jsvSomenteNumeros(evt){ var charCode = (evt.which) ? evt.which : event.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)){ return false; } return true; } /********************************************************************************/ /* Função:jsvFormataMoeda(objTextBox,e) /* Descrição: Formata o valor do campo para a moeda REAL (9.999,99) /* /* Parâmetros: objTextBox - usar a palavra reservada do JS this apra fazer referencia /* ao proprio campo /* e - event /* Orientação: usar o envento onKeyPress = "return(jsvFormataMoeda(this,event))" /*---------------------------------------------------------------------------------- /* Autor: Desconhecido /* Criação: /* Histórico: 15/12/2006 - Adaptação da Função para uso no sistema /* 30/08/2007 - nova função para funcionar com FF e IE /***********************************************************************************/ documentall = document.all; /* * função para formatação de valores monetários retirada de * http://jonasgalvez.com/br/blog/2003-08/egocentrismo */ function formatamoney(c) { var t = this; if(c == undefined) c = 2; var p, d = (t=t.split("."))[1].substr(0, c); for(p = (t=t[0]).length; (p-=3) >= 1;) { t = t.substr(0,p) + "." + t.substr(p); } return t+","+d+Array(c+1-d.length).join(0); } String.prototype.formatCurrency=formatamoney function demaskvalue(valor, currency){ /* * Se currency é false, retorna o valor sem apenas com os números. Se é true, os dois últimos caracteres são considerados as * casas decimais */ var val2 = ''; var strCheck = '0123456789'; var len = valor.length; if (len== 0){ return 0.00; } if (currency ==true){ /* Elimina os zeros à esquerda * a variável passa a ser a localização do primeiro caractere após os zeros e * val2 contém os caracteres (descontando os zeros à esquerda) */ for(var i = 0; i < len; i++) if ((valor.charAt(i) != '0') && (valor.charAt(i) != ',')) break; for(; i < len; i++){ if (strCheck.indexOf(valor.charAt(i))!=-1) val2+= valor.charAt(i); } if(val2.length==0) return "0.00"; if (val2.length==1)return "0.0" + val2; if (val2.length==2)return "0." + val2; var parte1 = val2.substring(0,val2.length-2); var parte2 = val2.substring(val2.length-2); var returnvalue = parte1 + "." + parte2; return returnvalue; } else{ /* currency é false: retornamos os valores COM os zeros à esquerda, * sem considerar os últimos 2 algarismos como casas decimais */ val3 =""; for(var k=0; k < len; k++){ if (strCheck.indexOf(valor.charAt(k))!=-1) val3+= valor.charAt(k); } return val3; } } function reais(obj,event){ var whichCode = (window.Event) ? event.which : event.keyCode; /* Executa a formatação após o backspace nos navegadores !document.all */ if (whichCode == 8 && !documentall) { /* Previne a ação padrão nos navegadores */ if (event.preventDefault){ //standart browsers event.preventDefault(); }else{ // internet explorer event.returnValue = false; } var valor = obj.value; var x = valor.substring(0,valor.length-1); obj.value= demaskvalue(x,true).formatCurrency(); return false; } /* Executa o Formata Reais e faz o format currency novamente após o backspace */ FormataReais(obj,'.',',',event); } // end reais function backspace(obj,event){ /* Essa função basicamente altera o backspace nos input com máscara reais para os navegadores IE e opera. O IE não detecta o keycode 8 no evento keypress, por isso, tratamos no keydown. Como o opera suporta o infame document.all, tratamos dele na mesma parte do código. */ var whichCode = (window.Event) ? event.which : event.keyCode; if (whichCode == 8 && documentall) { var valor = obj.value; var x = valor.substring(0,valor.length-1); var y = demaskvalue(x,true).formatCurrency(); obj.value =""; //necessário para o opera obj.value += y; if (event.preventDefault){ //standart browsers event.preventDefault(); }else{ // internet explorer event.returnValue = false; } return false; }// end if }// end backspace function FormataReais(fld, milSep, decSep, e) { var sep = 0; var key = ''; var i = j = 0; var len = len2 = 0; var strCheck = '0123456789'; var aux = aux2 = ''; var whichCode = (window.Event) ? e.which : e.keyCode; //if (whichCode == 8 ) return true; //backspace - estamos tratando disso em outra função no keydown if (whichCode == 0 ) return true; if (whichCode == 9 ) return true; //tecla tab if (whichCode == 13) return true; //tecla enter if (whichCode == 16) return true; //shift internet explorer if (whichCode == 17) return true; //control no internet explorer if (whichCode == 27 ) return true; //tecla esc if (whichCode == 34 ) return true; //tecla end if (whichCode == 35 ) return true;//tecla end if (whichCode == 36 ) return true; //tecla home /* O trecho abaixo previne a ação padrão nos navegadores. Não estamos inserindo o caractere normalmente, mas via script */ if (e.preventDefault){ //standart browsers e.preventDefault() }else{ // internet explorer e.returnValue = false } var key = String.fromCharCode(whichCode); // Valor para o código da Chave if (strCheck.indexOf(key) == -1) return false; // Chave inválida /* Concatenamos ao value o keycode de key, se esse for um número */ fld.value += key; var len = fld.value.length; var bodeaux = demaskvalue(fld.value,true).formatCurrency(); fld.value=bodeaux; /* Essa parte da função tão somente move o cursor para o final no opera. Atualmente não existe como movê-lo no konqueror. */ if (fld.createTextRange) { var range = fld.createTextRange(); range.collapse(false); range.select(); } else if (fld.setSelectionRange) { fld.focus(); var length = fld.value.length; fld.setSelectionRange(length, length); } return false; } function janela(www,h,w){ var height = window.screen.height - 160; var width = window.screen.width; var top = (height- h)/2; var left = (width - w)/2; window.open(www,"nova","top=" + top + ",left="+ left +",width="+w+",heigth="+h+",toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,scrolling=yes,resizable=yes") } /********************************************************************************/ /* Função:jsvFormataMoeda(objTextBox,e) /* Descrição: Formata o valor do campo para a moeda REAL (9.999,99) /* /* Parâmetros: objTextBox - usar a palavra reservada do JS this apra fazer referencia /* ao proprio campo /* e - event /* Orientação: usar o envento onKeyPress = "return(jsvFormataMoeda(this,event))" /*---------------------------------------------------------------------------------- /* Autor: Desconhecido /* Criação: /* Histórico: 15/12/2006 - Adaptação da Função para uso no sistema /***********************************************************************************/ function jsvFormatarMoeda(objTextBox,e){ var sep = 0; var key = ''; var i = j = 0; var len = len2 = 0; var strCheck = '0123456789'; var aux = aux2 = ''; var whichCode = (!window.Event) ? e.which : e.keyCode; //alert(whichCode); if (whichCode == 13) return false; //if (whichCode == 37) return true; //if (whichCode == 39) return true; key = String.fromCharCode(whichCode); // Valor para o código da Chave //alert(key); if (strCheck.indexOf(key) == -1) return false; // Chave inválida len = objTextBox.value.length; for(i = 0; i < len; i++) if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != ',')) break; aux = ''; for(;i < len; i++) if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i); aux += key; len = aux.length; if (len == 0) objTextBox.value = ''; if (len == 1) objTextBox.value = '0'+ ',' + '0' + aux; if (len == 2) objTextBox.value = '0'+ ',' + aux; if (len > 2) { aux2 = ''; for (j = 0, i = len - 3; i >= 0; i--) { if (j == 3) { aux2 += '.'; j = 0; } aux2 += aux.charAt(i); j++; } objTextBox.value = ''; len2 = aux2.length; for (i = len2 - 1; i >= 0; i--) objTextBox.value += aux2.charAt(i); objTextBox.value += ',' + aux.substr(len - 2, len); } return false; } /********************************************************************************/ /* Função:jsvFormatar(sCampo,sTipo) /* Descrição: formata o campo de acordo com o tipo solicitado! /* /* Parâmetros: sCampo - id do campo a ser formatado /* sTipo - pode ser CEP,CPF,CNPJ /* /* Orientação: ------------------ /*---------------------------------------------------------------------------------- /* Autor: Giovanni Donda /* Criação: 01/02/2007 /* Histórico: /***********************************************************************************/ function jsvFormatar(sCampo, sTipo){ if(typeof sTipo=="undefined") return false else sTipo = sTipo.toLowerCase(); var cep = "#####-###"; var cpf = "###.###.###-##"; var cnpj = "###.###.###/####-##"; var aFormatos = ['cep','cpf','cnpj']; if(aFormatos.indexOf(sTipo)==-1){ alert('Formato não configurado'); return false; } switch(sTipo){ case "cep": var sTipo=cep; break; case "cpf": var sTipo=cpf; break; case "cnpj": var sTipo=cnpj; break; } var i = sCampo.value.length; var texto = sTipo.substring(i) if (texto.substring(0,1) != '#'){ sCampo.value += texto.substring(0,1); } } /** * * @access public * @return void **/ function jsvFormatarCEP(e,src,mask){ if(window.event) { _TXT = e.keyCode; } else if(e.which) { _TXT = e.which; } if(_TXT > 47 && _TXT < 58) { var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i) if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); } return true; } else { if (_TXT != 8) { return false; } else { return true; } } }