// se usar o require_once, então colocar as tag neste arquivo // a.substr(índice_inicial,tamanho_string) // a.substring(índice_inicial,pare_antes_do_n_caractere) function goto(event,wedit,wedit0) { if(event==null) event=window.event; switch(event.keyCode) { case 13: document.getElementById(wedit).focus(); break; case 38: //down key if(document.getElementById(wedit0)==null) return; document.getElementById(wedit0).focus(); break; default: return; break; } } function left(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else return String(str).substring(0,n); } function right(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } function strzero(variavel, ncasas) { wzeros=strrepeat('0',ncasas); cvariavel = wzeros + String(variavel); cvariavel = right(cvariavel,ncasas); return cvariavel; } function strrepeat(s, n) { var a = []; while(a.length < n){ a.push(s); } return a.join(''); } //****************************************************************************** function isnumeric(sText) { var ValidChars = "0123456789."; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } if (isNaN(sText)) IsNumber=false; if (sText=="") IsNumber=false; return IsNumber; } //****************************************************************************** function elementoativo(evt) { var e = evt ? evt : window.event; if (!e) return; if (e.target) activeElement = e.target; else if(e.srcElement) activeElement = e.srcElement; return activeElement; } function jsGet(type) { if(location.href.match(type)){ return location.href.split(type+'=')[1].split('&')[0]; // .split igual ao explode } } //****************************************************************************** function getVar(name) { get_string = document.location.search; return_value = ''; do { //This loop is made to catch all instances of any get variable. name_index = get_string.indexOf(name + '='); if(name_index != -1) { get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index); end_of_value = get_string.indexOf('&'); if(end_of_value != -1) value = get_string.substr(0, end_of_value); else value = get_string; if(return_value == '' || value == '') return_value += value; else return_value += ', ' + value; } } while(name_index != -1) //Restores all the blank spaces. space = return_value.indexOf('+'); while(space != -1) { return_value = return_value.substr(0, space) + ' ' + return_value.substr(space + 1, return_value.length); space = return_value.indexOf('+'); } return(return_value); } function datahora() { var now = new Date(); var ano = now.getYear(); var mes = now.getMonth() + 1; var mes = ((mes < 10) ? "0" : "")+ mes; var dia = now.getDay() + 1; var dia = ((now.getDate()<10) ? "0" : "")+ now.getDate(); var hora = now.getHours(); var min = ((now.getMinutes() < 10) ? "0" : "") + now.getMinutes(); var seg = ((now.getSeconds() < 10) ? "0" : "") + now.getSeconds(); wretorno=ano.toString()+mes.toString()+dia.toString()+hora.toString()+min.toString()+seg.toString(); return (wretorno); } function datahoje() { var now = new Date(); //var ano = now.getYear(); var ano = now.getFullYear(); var mes = now.getMonth() + 1; var mes = ((mes < 10) ? "0" : "")+ mes; var dia = now.getDay() + 1; var dia = ((now.getDate()<10) ? "0" : "")+ now.getDate(); wretorno=dia.toString()+'/'+mes.toString()+'/'+ano.toString(); return (wretorno); } function diamesano(wparam) { wp=wparam.toString().toUpperCase(); now=new Date(); if (wp=='A') return now.getFullYear(); if (wp=='M') return now.getMonth(); if (wp=='D') return now.getDay(); } //****************************************************************************** function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } //***************************************************************************************** //para chamar = onKeyDown="enterAsTab(this.form.name,this.name);" enterAsTab = function(wform,wcampo) { //v1.0 function next(e) { var l, i, f, j, o = e.target; if(e.key == 13 && !/textarea|select/i.test(o.type)) { for(i = l = (f = o.form.elements).length; f[--i] != o;); for(j = i; (j = (j + 1) % l) != i && (!f[j].type || f[j].disabled || f[j].readOnly || f[j].type.toLowerCase() == "hidden");); e.preventDefault(), j != i && f[j].focus(); } } var wprox="addEvent(document.forms."+wform+"."+wcampo+",\"keypress\", next);"; eval(wprox); }; addEvent = function(o, e, f, s){ var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d; r[r.length] = [f, s || o], o[e] = function(e){ try{ (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;}); e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;}); e.target || (e.target = e.srcElement || null); e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0; }catch(f){} for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false)); return e = null, !!d; } }; removeEvent = function(o, e, f, s){ for(var i = (e = o["_on" + e] || []).length; i;) if(e[--i] && e[i][0] == f && (s || o) == e[i][1]) return delete e[i]; return false; }; var isNN = (navigator.appName.indexOf("Netscape")!=-1); function autoTab(input,len, e) { var keyCode = (isNN) ? e.which : e.keyCode; var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; if(input.value.length >= len && !containsElement(filter,keyCode)) { input.value = input.value.slice(0, len); input.form[(getIndex(input)+1) % input.form.length].focus(); } function containsElement(arr, ele) { var found = false, index = 0; while(!found && index < arr.length) if(arr[index] == ele) found = true; else index++; return found; } function getIndex(input) { var index = -1, i = 0, found = false; while (i < input.form.length && index == -1) if (input.form[i] == input)index = i; else i++; return index; } return true; } //****************************************************************************** function setElementVisibility(elementToSet, showItSwitch, keepPlacementSwitch){ if (showItSwitch) { elementToSet.style.display = "inline"; elementToSet.style.visibility = "visible"; } else{ if (keepPlacementSwitch) { elementToSet.style.display = "inline"; elementToSet.style.visibility = "hidden"; } else{ elementToSet.style.display = "none"; } } } function esconde_objeto(objeto){ setElementVisibility(objeto, false, true); } function remove_objeto(objeto){ setElementVisibility(objeto, false, false); } function mostra_objeto(objeto){ setElementVisibility(objeto, true); } //****************************************************************************** function validaEmail(campo) { var str = campo.value; var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if(filter.test(str)) valido = true; else{ alert('Email inválido'); valido = false; campo.focus(); campo.select(); } return valido; } function navegador(e) { // For IE4+ ie=(document.all)?true:false; // For Mozilla dom=((document.getElementById) && (!ie))?true:false; if (/*@cc_on!@*/false) ie=true; if (ie) { return "ie";} else { return "netscape";} } function checkNumber(e) { if (navegador=="ie"){ tecla = event.keyCode; }else{ tecla = e.which; } if((tecla > 47 && tecla < 58) || (tecla == 0) || (tecla == 8)){ return true; }else{ return false; } } function valida_cpf(cpf) { var ninja = /^[0-9]{11,11}$/ if ( !ninja.test(cpf) ) { return false; } var numeros, digitos, soma, i, resultado, digitos_iguais; digitos_iguais = 1; if (cpf.length < 11) return false; for (i = 0; i < cpf.length - 1; i++) { if (cpf.charAt(i) != cpf.charAt(i + 1)) { digitos_iguais = 0; break; } } if (!digitos_iguais) { numeros = cpf.substring(0,9); digitos = cpf.substring(9); soma = 0; for (i = 10; i > 1; i--) soma += numeros.charAt(10 - i) * i; resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; if (resultado != digitos.charAt(0)) return false; numeros = cpf.substring(0,10); soma = 0; for (i = 11; i > 1; i--) soma += numeros.charAt(11 - i) * i; resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; if (resultado != digitos.charAt(1)) return false; return true; } else { return false; } } function sonumeros(e) { if (window.event) //IE { tecla = e.keyCode; } else if (e.which) //FF { tecla = e.which; } //techa==8 é para permitir o backspace funcionar para apagar if ( (tecla >= 48 && tecla <= 57)||(tecla == 8 ) ) { return true; } else { return false; } } //****************************************************************************** function formatar(mascara, campo, event) { var t = document.forms[0][campo].value; var i = t.length; //document.forms[0].comentario.value=document.forms[0].comentario.value+'\n i='+i+'-mascara.charAt(i)'+mascara.charAt(i)+' t:'+t; if(document.all) { // Internet Explorer tecla = event.keyCode; } else { if(document.layers) { // Nestcape tecla = event.which; } else { tecla = event.which; } } if (tecla==9) { // tab return true; } if (tecla==46) { //del return true; } if (tecla==8) { //backspace return true; } if (tecla==37) { return true;} // seta p/esq if (tecla==39) { return true;} // seta p/dir if (mascara.charAt(i) == '9') { if ( String.fromCharCode(tecla)!='0' && String.fromCharCode(tecla)!='1' && String.fromCharCode(tecla)!='2' && String.fromCharCode(tecla)!='3' && String.fromCharCode(tecla)!='4' && String.fromCharCode(tecla)!='5' && String.fromCharCode(tecla)!='6' && String.fromCharCode(tecla)!='7' && String.fromCharCode(tecla)!='8' && String.fromCharCode(tecla)!='9' && tecla != 8 ) { return false; } } //if ( // foi anulado por causa do teclado numérico // !( // (tecla > 47 && tecla < 58) // || (tecla = 8) // || (tecla > 95 && tecla < 106) // ) // ) return false; if (mascara.charAt(i) != '#' && mascara.charAt(i) != '9') { document.forms[0][campo].value=t+mascara.charAt(i);//+String.fromCharCode(tecla); i++; } var t = document.forms[0][campo].value; //t=t.replace(/[^0123456789/]/g,""); document.forms[0][campo].value=t.substring(0, mascara.length); return true; } //****************************************************************************** // colocar no evento onkeydown, aceita tab, enter, etc. function formatardown(mascara, campo, event) { var t = document.forms[0][campo].value; var i = t.length; if(document.all) { // Internet Explorer tecla = event.keyCode; } else { if(document.layers) { // Nestcape tecla = event.which; } else { tecla = event.which; } } //alert(String.fromCharCode(tecla)+"="+tecla); if (tecla==9) { return true; } if (tecla==8) { return true; } if (tecla==13) { return true;} if (tecla==46) { return true;} // del if (tecla==37) { return true;} // seta p/esq if (tecla==39) { return true;} // seta p/dir if (t.length >= mascara.length) return false; // para limitar no tamanho da máscara if (mascara.charAt(i) == '9') { if ( String.fromCharCode(tecla)!='0' && String.fromCharCode(tecla)!='1' && String.fromCharCode(tecla)!='2' && String.fromCharCode(tecla)!='3' && String.fromCharCode(tecla)!='4' && String.fromCharCode(tecla)!='5' && String.fromCharCode(tecla)!='6' && String.fromCharCode(tecla)!='7' && String.fromCharCode(tecla)!='8' && String.fromCharCode(tecla)!='9' && (tecla < 96 || tecla > 105) && tecla != 8 ) return false; } if (mascara.charAt(i) != '#' && mascara.charAt(i) != '9') { document.forms[0][campo].value=t+mascara.charAt(i);//+String.fromCharCode(tecla); i++; } var t = document.forms[0][campo].value; document.forms[0][campo].value=t.substring(0, mascara.length); return true; } //****************************************************************************** function formatar_enter(mascara, campo,event) { formatar(mascara,campo,event); return teclou_enter(event); } function maiuscula(elemento) { el=document.getElementById(elemento); el.value=el.value.toString().toUpperCase(); } function minuscula(elemento) { el=document.getElementById(elemento); el.value=el.value.toString().toLowerCase(); } //****************************************************************************** //****************************************************************************** var podePost=true; //Variável que cancela o post no firefox // teclou_enter Função principal function teclou_enter(evt) { evt = getEvent(evt); if (getKeyCode(evt) != 13) return true; var elementAtivo = getTarget(evt); if (!elementAtivo) return true; // Se não tiver nenhum elemento ativo if (!elementAtivo.type) return true; // Se não tiver nenhum elemento ativo if (elementAtivo.type.toLowerCase() == "submit" || elementAtivo.type.toLowerCase() == "button") { podePost = true; elementAtivo.click(); return cancelaPost(evt); } var nextElement = null; if (elementAtivo.tabIndex == 0) nextElement = getNextElementByName(elementAtivo); else nextElement=getNextElementByTabIndex(elementAtivo); if(nextElement) { var theForm = document.forms[0]; if(theForm.addEventListener) theForm.addEventListener('submit', enviaForm, false); // Evento submit no form para FireFox if (nextElement.type.toLowerCase() == "submit" || nextElement.type.toLowerCase() == "button") { if (elementAtivo.tabIndex == 0) return true; podePost = true; nextElement.click(); return cancelaPost(evt); } podePost = false; nextElement.focus(); return cancelaPost(evt); } else { podePost=false; return cancelaPost(evt); } } // Função para cancelar o envio do form para o FireFox function enviaForm(evt) { if (!podePost) { evt.cancelBubble = true; evt.returnValue = false; if (evt.preventDefault) evt.preventDefault(); if (evt.stopPropagation) evt.stopPropagation(); podePost = true; return false; } else return true; } function cancelaPost(evt) { evt.cancelBubble = true; evt.returnValue = false; if (evt.preventDefault) evt.preventDefault(); if (evt.stopPropagation) evt.stopPropagation(); return false; } // Recupera o evento do form function getEvent(evt) { if( !evt ) evt = window.event; //Internet Explorer return evt; } // Recupera o elemento que está com o foco function getTarget(evt) { var target; if (evt.srcElement) target = evt.srcElement; else if (evt.target) target = evt.target; return target; } // Recupera o código da tecla que foi pressionado function getKeyCode(evt) { var code; if(typeof(evt.keyCode) == 'number') code = evt.keyCode; else if(typeof(evt.which) == 'number') code = evt.which; else if(typeof(evt.charCode) == 'number') code = evt.charCode; else return 0; return code; } // Recupera o elemento de acordo com o TabIndex function getElementByTabIndex(tabIndex) { var form = document.forms[0]; for( var i=0; i < form.elements.length; i++ ) { var el = form.elements[i]; if( el.tabIndex && el.tabIndex == tabIndex ) return el; } return null; } // Recupera o próximo elemento de acordo com o nome function getNextElementByTabIndex(elementAtivo) { var targetTabIndex = elementAtivo.tabIndex; var nextTabIndex = targetTabIndex+1; var nextElement = getElementByTabIndex(nextTabIndex); // Margem de erro var i=0; for(i=0; i < 45; i++) // Tolerância de tabIndex { if (nextElement!=null && !nextElement.disabled) break; nextTabIndex = nextTabIndex+1; nextElement = getElementByTabIndex(nextTabIndex); } return nextElement; } // Recupera o próximo elemento de acordo com o nome function getNextElementByName(elementAtivo) { var passou=false; var form = document.forms[0]; for(var i=0; i < form.elements.length; i++) { var el = form.elements[i]; if( el && el.id == elementAtivo.id || passou) { passou=true; // Encontrou o elemento atual var x=i+1; var elnx = form.elements[x]; if(elnx) { switch (elnx.type) { case "text": case "submit": case "button": case "reset": case "select-one": case "checkbox": case "image": case "password": case "radio": case "reset": case "submit": case "textarea": if (elnx.disabled) continue; break; default: continue; break; } return elnx; } } } return null; } //****************************************************************************** // troca ponto decimal e tira os separadores de milhar function pre_val(num) // desformata valor 1.234,56 p/ 1234.56 { if (num=="") num="0"; num = num.toString().replace(/\,/g,"*"); num = num.toString().replace(/\./g,""); num = num.toString().replace(/\*/g,"."); if (!isnumeric(num)) num="0"; return num; } //****************************************************************************** //****************************************************************************** // prepara valor formatado como moeda, retira ponto e vírgula function prepara_currency(num) { num = num.toString().replace(/\,/g,""); num = num.toString().replace(/\./g,""); return num; } // formata moeda ao sair function formata_currency(num) { num = num.toString().replace(/\,/g,""); num = num.toString().replace(/\./g,""); //num = num.toString().replace(/\$|.,/g,""); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); //num = Math.floor(num * 100 + 0.50000000001); num = Math.floor(num + 0.50000000001); cents = num % 100; num = Math.floor(num / 100).toString(); if (cents < 10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+'.'+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + ',' + cents); } //****************************************************************************** function formatFloat(num,casasDec,sepDecimal,sepMilhar) { if (num < 0) { num = -num; sinal = -1; } else sinal = 1; var resposta = ""; var part = ""; //if (num != Math.floor(num)) // decimal values present //{ part = Math.round((num-Math.floor(num))*Math.pow(10,casasDec)).toString(); // transforms decimal part into integer (rounded) while (part.length < casasDec) part = '0'+part; if (casasDec > 0) { resposta = sepDecimal+part; num = Math.floor(num); } else num = Math.round(num); //} // end of decimal part while (num > 0) // integer part { part = (num - Math.floor(num/1000)*1000).toString(); // part = three less significant digits num = Math.floor(num/1000); if (num > 0) while (part.length < 3) // 123.023.123 if sepMilhar = '.' part = '0'+part; // 023 resposta = part+resposta; if (num > 0) resposta = sepMilhar+resposta; if (num==0) resposta = "0"+resposta; } resp2 = resposta; while (resp2.substring(0,1)=="0") resp2 = resposta.substring(1,resposta.length); resposta = resp2; if (resposta.substring(0,1)==sepDecimal) resposta="0"+resposta; if (sinal < 0) resposta = '-'+resposta; return resposta; } //****************************************************************************** function replaceString(oldS, newS, fullS) { // Replaces oldS with newS in the string fullS for (var i = 0; i < fullS.length; i++) { if (fullS.substring(i, i + oldS.length) == oldS) { fullS = fullS.substring(0, i) + newS + fullS.substring(i + oldS.length, fullS.length); } } return fullS; } //replaceString("World", "Web", "Brave New World"); //****************************************************************************** function idade(data,dataHoje) { //document.write(idade('03/06/1965','08/11/2007')); x = data.split("/"); h = dataHoje.split("/"); anosProvisorio = h[2] - x[2]; if(h[1] < x[1]) { anosProvisorio -= 1; } else if(h[1] == x[1]) { if(h[0] < x[0]) { anosProvisorio -= 1; } } return anosProvisorio; } //****************************************************************************** function repeat(repeatString, repeatNum, returnNum) { var newString = ""; returnNum += ""; if (returnNum == "undefined" || returnNum == "0") { return ""; } for (var x=1; x<=parseInt(repeatNum, 10); x++) { newString = newString + repeatString; } if (newString == "") { return (newString); } else { return (newString.substring(0, parseInt(returnNum, 10))); } } String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); } String.prototype.ltrim = function() { return this.replace(/^\s+/,""); } String.prototype.rtrim = function() { return this.replace(/\s+$/,""); } function strcarac(numero,wdig,wcarac) { var cx=numero.trim(); if (cx.length > wdig) {cx=cx.substring(0,wdig);} while (cx.length < wdig) { cx=cx+wcarac; } return cx; } //****************************************************************************** function formatareais(fld, milSep, decSep,numdec, 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; a=document.getElementById(fld); if (whichCode == 13) return true; if (whichCode == 8) return true; if (whichCode == 0) return true; key = String.fromCharCode(whichCode); // Valor para o código da Chave if (strCheck.indexOf(key) == -1) return false; // Chave inválida len = a.value.length; for(i = 0; i < len; i++) if ((a.value.charAt(i) != '0') && (a.value.charAt(i) != decSep)) break; aux = ''; for(; i < len; i++) if (strCheck.indexOf(a.value.charAt(i))!=-1) aux += a.value.charAt(i); aux += key; len = aux.length; if (len == 0) a.value = ''; if (len < numdec) a.value = '0'+ decSep + repeat('0',numdec,numdec-len) + aux; if (len == numdec) a.value = '0'+ decSep + aux; if (len > numdec) { aux2 = ''; for (j = 0, i = len - numdec-1; i >= 0; i--) { if (j == 3) { aux2 += milSep; j = 0; } aux2 += aux.charAt(i); j++; } a.value = ''; len2 = aux2.length; for (i = len2 - 1; i >= 0; i--) a.value += aux2.charAt(i); a.value += decSep + aux.substr(len - numdec, len); } return false; } //****************************************************************************** // para o campo memo ou textarea // pega o caractere position doGetCaretPosition (ctrl) // ajusta o caractere position doSetCaretPosition (ctrl) // informa o número de linhas countLines(obj,0) // devolve a linha em que está o cursor memolinha(obj) // * * * não deu certo com internet-explorer function doGetCaretPosition (ctrl) { var CaretPos = 0; // IE Support if (document.selection) { ctrl.focus (); var Sel = document.selection.createRange (); Sel.moveStart ('character', -ctrl.value.length); CaretPos = Sel.text.length; } // Firefox support else if (ctrl.selectionStart || ctrl.selectionStart == '0') CaretPos = ctrl.selectionStart; return (CaretPos); } function setCaretPosition(ctrl, pos){ if(ctrl.setSelectionRange) { ctrl.focus(); ctrl.setSelectionRange(pos,pos); } else if (ctrl.createTextRange) { var range = ctrl.createTextRange(); range.collapse(true); range.moveEnd('character', pos); range.moveStart('character', pos); range.select(); } } function countLines(strtocount, cols) { var hard_lines = 1; var last = 0; while ( true ) { last = strtocount.indexOf("\n", last+1); hard_lines ++; if ( last == -1 ) break; } var soft_lines = Math.round(strtocount.length / (cols-1)); var hard = eval("hard_lines " + unescape("%3e") + "soft_lines;"); if ( hard ) soft_lines = hard_lines; return soft_lines; } function memolinha_ff(obj) { var xmemo=obj; var nc=doGetCaretPosition(xmemo); var rt=xmemo.value; rt=rt.substring(0,nc-1); la=countLines(rt,0)-1; var lp=xmemo.value.split("\n"); if (window.event) //IE { return lp[la-1]; } else return lp[la-1]; } function memolinha_ie(obj) { var a=updatePosition(obj); a=a.split(';'); a=a[2]; return a; } //****************************************************************************** function initPosition(textBox) { var storedValue = textBox.value; textBox.value = ""; textBox.select(); var caretPos = document.selection.createRange(); textBox.__boundingTop = caretPos.boundingTop; textBox.__boundingLeft = caretPos.boundingLeft; textBox.value = " "; textBox.select(); caretPos = document.selection.createRange(); textBox.__boundingWidth = caretPos.boundingWidth; textBox.__boundingHeight = caretPos.boundingHeight; textBox.value = storedValue; } function storePosition(textBox) { var caretPos = document.selection.createRange(); var boundingTop = (caretPos.offsetTop + textBox.scrollTop) - textBox.__boundingTop; var boundingLeft = (caretPos.offsetLeft + textBox.scrollLeft) - textBox.__boundingLeft; textBox.__Line = (boundingTop / textBox.__boundingHeight) + 1; textBox.__Column = (boundingLeft / textBox.__boundingWidth) + 1; } function updatePosition(textBox) { storePosition(textBox); var lp=textBox.value.split("\n"); return textBox.__Line+';'+ textBox.__Column+';'+lp[textBox.__Line-1]; } //****************************************************************************** var TimeToFade = 1000.0; function fade(eid,fun) // fade(nome_da_div,-2) -2=mostra, 2=esconde { var element = document.getElementById(eid); if(element == null) return; if(element.FadeState == null) { if(element.style.opacity == null || element.style.opacity == "" || element.style.opacity == '1') { element.FadeState = 2; } else { element.FadeState = -2; } } element.FadeState = fun; if(element.FadeState == 1 || element.FadeState == -1) { element.FadeState = element.FadeState == 1 ? -1 : 1; element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft; } else { element.FadeState = element.FadeState == 2 ? -1 : 1; element.FadeTimeLeft = TimeToFade; setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33); } } function animateFade(lastTick, eid) { var curTick = new Date().getTime(); var elapsedTicks = curTick - lastTick; var element = document.getElementById(eid); if(element.FadeTimeLeft <= elapsedTicks) { element.style.opacity = element.FadeState == 1 ? '1' : '0'; element.style.filter = 'alpha(opacity = ' + (element.FadeState == 1 ? '100' : '0') + ')'; element.FadeState = element.FadeState == 1 ? 2 : -2; return; } element.FadeTimeLeft -= elapsedTicks; var newOpVal = element.FadeTimeLeft/TimeToFade; if(element.FadeState == 1) newOpVal = 1 - newOpVal; element.style.opacity = newOpVal; element.style.filter ='alpha(opacity = ' + (newOpVal*100) + ')'; setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33); } function delay(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < millis); } //****************************************************************************** function zeronull(valor) { if ((valor=="0") || (isNaN(parseInt(valor))) ) return true; return false; } //****************************************************************************** function null2zero(valor) { if (!isnumeric(valor)) valor=0; return valor; } function partestring(wstring,wparte,wseparador) { var wvar1=wstring.toString(); var wvar2=wvar1.split(wseparador); return wvar2[wparte - 1]; } function somadia(wdata,wdias){ // no formato dd/mm/aaaa wdia=parseInt(wdata.substr(0,2)); wmes=parseInt(wdata.substr(3,2)); wano=parseInt(wdata.substr(6,4)); wmilisegundos=Date.UTC(wano,wmes-1,wdia); // UTC transforma a data na diferença em milisegundos a partir de 01/01/1970 //data_utc = new Date(Date.UTC(wano,wmes-1,wdia)); wmilisegundos+=86400000; // soma mais um dia, porque a data UTC já é a diferença de datas, então vem com menos 1 dia. (24h * 60m * 60s * 1000miliseg) data2= new Date(); data2.setTime(wmilisegundos+=(86400000 * wdias)); return strzero(data2.getDate(),2)+'/'+strzero(data2.getMonth()+1,2)+'/'+data2.getFullYear(); } function calcmin1(hora1,hora2) { // recebe duas horas e calcula a diferença em minutos, exemplo calcmin('10:00','12:00'); var d1 = new Date(); var d2 = new Date(); var b=hora1.split(":"); d1.setHours(b[0],b[1],0); var b=hora2.split(":"); d2.setHours(b[0],b[1]); return ((d2.getHours() * 60) + d2.getMinutes()) - ((d1.getHours() * 60) + d1.getMinutes()); } function calculajornada(entrada1,saida1,entrada2,saida2) { m1=calcmin1(entrada1,saida1); m2=calcmin1(entrada2,saida2); if (isNaN(m1)) m1=0; //NaN = não numérico valor if (isNaN(m2)) m2=0; return m1 + m2; // retorna a soma em minutos das duas jornadas de trabalho } //***************listbox function lb_desmarcatudo(CONTROL){ for(var i = 0;i < CONTROL.length;i++){ CONTROL.options[i].selected = false; } } function lb_selectall(CONTROL){ for(var i = 0;i < CONTROL.length;i++){ CONTROL.options[i].selected = true; } } function lb_deselectall(CONTROL){ for(var i = 0;i < CONTROL.length;i++){ CONTROL.options[i].selected = false; } } //***************