c_navegador = 'IE'; if(document.all) { c_navegador="IE"; } else if(document.layers) { c_navegador="Netscape"; } else if(navigator.appName.indexOf("Mozilla") != -1) { c_navegador="Mozilla"; } else if(navigator.appName.indexOf("Opera") != -1) { c_navegador="Opera"; } else { c_navegador="desconhecido"; } var ns4 = document.layers; var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) ||(navigator.userAgent.indexOf("Opera/5")!=-1); var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) ||(navigator.userAgent.indexOf("Opera/6")!=-1); var agt=navigator.userAgent.toLowerCase(); var mac = (agt.indexOf("mac")!=-1); var ie = (agt.indexOf("msie") != -1); var mac_ie = mac && ie; function addEvent(obj, evType, fn) { if (typeof obj == "string") { if (null == (obj = getElement(obj))) { throw new Error("Elemento HTML não encontrado. Não foi possível adicionar o evento."); } } if (obj.attachEvent) { return obj.attachEvent(("on" + evType), fn); } else if (obj.addEventListener) { return obj.addEventListener(evType, fn, true); } else { throw new Error("Seu browser não suporta adição de eventos."); } } function removeElement(ele) { return ele.parentNode.removeChild(ele); } function elDisplay(element_id, display) { el = getElement(element_id); //alert(el); if (el) { try { el.style.display = display; //alert(el.style.display); return true; } catch (err) { try { el[0].style.display = display; //alert('2 '+ el[0].style.display); return true; } catch (err) { } } } return false; } // nao testado function windowTextSelection_disable() { //if the browser is IE4+ document.onselectstart=new Function ("return false"); //if the browser is NS6 if (window.sidebar) { document.onmousedown=disabletext; document.onclick=reEnable; } } function mouseX(evt) { return evt.clientX ? evt.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) : evt.pageX;} function mousePosicao(e) { if (!e) { if (window.event) e=window.event; else if (window.Event) e=window.Event; } var cursor = {x:0, y:0}; if (e.pageX || e.pageY) { cursor.x = e.pageX; cursor.y = e.pageY; } else { cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft; cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop; } return cursor; } function classAdd(elem, classe) { if (!elem) return; cn = elem.className; if (cn) { var i = cn.indexOf( classe, 0 ); // se ja tem a classe no elemento if (i > 0) return; } // inseri novamente try { elem.className = elem.className +' '+ classe; //alert(elem.className); } catch (err) { } } function classDel(elem, classe) { if (!elem) return; try { //getElement('log').innerHTML = 'classDel atual: '+ elem.className +'
Retirar '+ classe; elem.className = elem.className.replace(' '+ classe,''); elem.className = elem.className.replace(' '+ classe,''); elem.className = elem.className.replace(' '+ classe,''); elem.className = elem.className.replace(' '+ classe,''); //getElement('log').innerHTML = getElement('log').innerHTML +'
Ficou '+ elem.className; } catch (err) { } } function classInv(elem, classe1, classe2) { classDel(elem, classe1); classAdd(elem, classe2); } function elementoPosicao(elemID){ var offsetTrail = getElement(elemID); var offsetLeft = 0; var offsetTop = 0; while (offsetTrail) { offsetLeft += offsetTrail.offsetLeft; offsetTop += offsetTrail.offsetTop; offsetTrail = offsetTrail.offsetParent; } if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") { offsetLeft += document.body.leftMargin; offsetTop += document.body.topMargin; } return {left:offsetLeft, top:offsetTop}; } function ctrlPressionado() { try { if (window.event) e=window.event; else if (window.Event) e=window.Event; if (typeof(e.ctrlKey)!='undefined' && e.ctrlKey) { return true; } if (Event) if (e.modifiers & Event.CONTROL_MASK) return true; } catch(err) { } return false; } function wWidth() { myWidth=0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; } else { myWidth = window.screen.width; } return myWidth; } function wHeight() { myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myHeight = document.body.clientHeight; } else { myHeight = window.screen.height; } return myHeight; } function getObjNN4(obj,name) { var x = obj.layers; var foundLayer; for (var i=0;i < x.length;i++) { if (x[i].id == name) foundLayer = x[i]; else if (x[i].layers.length) var tmp = getObjNN4(x[i],name); if (tmp) foundLayer = tmp; } return foundLayer; } function eHeight(Elem) { if (ns4) { var elem = getObjNN4(document, Elem); return elem.clip.height; } else { var elem = getElement(Elem); if (op5) { xPos = elem.style.pixelHeight; } else { xPos = elem.offsetHeight; } return xPos; } } function eWidth(Elem) { if (ns4) { var elem = getObjNN4(document, Elem); return elem.clip.width; } else { var elem = getElement(Elem); if (op5) { xPos = elem.style.pixelWidth; } else { xPos = elem.offsetWidth; } return xPos; } } function formata_moeda(num) { x = 0; if(num < 0) { num = Math.abs(num); x = 1; } if(isNaN(num)) num = "0"; cents = Math.floor((num*100+0.5)%100); num = Math.floor((num*100+0.5)/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)); ret = num + ',' + cents; if (x == 1) ret = ' - ' + ret; return ret; } // onkeyDown='fmoeda();' ESTE VI FUNCIONANDO onkeypress=\"return fmoeda();\ function fmoeda() { var tecla; tecla = keyCode(); // 44 e 188 = , // 8 e 9 = Backspace // 46 = Del // 29 = Esc // 37 = seta <- // 39 = seta -> if ((tecla < 48 || tecla > 57) && tecla != 188 && tecla != 44 && tecla != 9 && tecla != 13 && tecla != 29 && tecla != 8 && tecla != 46 && tecla != 37 && tecla != 39) event.returnValue = false; } function finteiro() { var tecla; tecla = keyCode(); if ((tecla < 48 || tecla > 57) && tecla != 9 && tecla != 13 && tecla != 29 && tecla != 8 && tecla != 46 && tecla != 37 && tecla != 39) event.returnValue = false; } var spBuff = new Array(); //declaração do array Buffer var spBuff = new Array(50); var spPonteiro = new Array(50); var spCadeia = new Array(50); var spBuffI = 0; var spDigitos = 20; // EXEMPLO: onKeypress='spPress(this,PROXIMOCAMPO);' onfocus='spApaga(this)' onblur='spApaga(this)' onclick='spApaga(this)'; function spPress(obj, objfoco) { var letra = String.fromCharCode(keyCode()); var digitos = 10; //alert('Letra '+ letra); try { eval("pId = spIds"+ obj.id +";"); } catch (err) { pId = false; } //alert('pId '+ pId); if (!pId) { pId = spBuffI; spBuffI++; eval("spIds"+ obj.id +" = pId;"); spBuff[pId] = new Array(spDigitos); spPonteiro[pId] = 0; spCadeia[pId] = ""; } //alert('Pon '+ spPonteiro[pId]); if(spPonteiro[pId] >= spDigitos) { spCadeia[pId]=""; spPonteiro[pId]=0; ret = ret +' Cad Zerada'; } //alert(keyCode()); // se pressiona a tecla ENTER, apago o array de teclas pressionadas e salto a outro objeto... if (keyCode() == 13) { spApaga(obj); if(objfoco!=0) objfoco.focus(); //evita foco a outro objeto se objfoco=0 } //senao busco a cadeia teclada dentro do combo... else { spBuff[pId][spPonteiro[pId]]=letra; //salvo na posicao ponteiro a letra teclada spCadeia[pId]=spCadeia[pId]+spBuff[pId][spPonteiro[pId]]; //armo uma cadeia com os dados que vao ingressando ao array spPonteiro[pId]++; ret = ret +' Buscando c: '+ spCadeia[pId]; //barro todas as opcoes que contem o combo e comparo a cadeia... for (var opcombo=0;opcombo < obj.length;opcombo++) { if(obj[opcombo].text.substr(0,spPonteiro[pId]).toLowerCase()==spCadeia[pId].toLowerCase()) { obj.selectedIndex=opcombo; } } } //document.getElememtById('log').innerHTML = document.getElememtById('log').innerHTML +'
'+ ret; if (c_navegador == 'IE') event.returnValue = false; else { try { e.preventDefault(); } catch(err) { keyCodeSet(0); } } //invalida a acao de clique de tecla para evitar busca do primeiro caractere } // onKeyDown='somenteNum();' function somenteNum() { kcode = keyCode(); if ((kcode < 48 && kcode > 31) || kcode > 57) { alert('SomenteNum '+ kcode); keyCodeSet(0); } } function somenteMoeda() { kcode = keyCode(); //alert('SomenteNum '+ kcode); if ((kcode < 48 && kcode > 31 && kcode != 44) || kcode > 57) { keyCodeSet(0); } } function window_maximize() { try { window.moveTo(0,0); if (document.all) { top.window.resizeTo(screen.availWidth,screen.availHeight); } else if (document.layers||document.getElementById) { if (top.window.outerHeight 0) return ret; } catch(err) { } try { ret = e.charCode; if (ret > 0) return ret; } catch(err) { } try { ret = e.keyCode; if (ret > 0) return ret; } catch(err) { } try { ret = e.which; if (ret > 0) return ret; } catch(err) { } try { ret = event.charCode; if (ret > 0) return ret; } catch(err) { } try { ret = event.keyCode; if (ret > 0) return ret; } catch(err) { } try { ret = event.which; if (ret > 0) return ret; } catch(err) { } /* try { ret = window.event.keyCode; } catch (err) { ret = e.which; } return ret; */ } function keyCodeSet(v,e) { ret = false; try { window.event.keyCode = v; return true; } catch(err) { } try { e.keyCode=v; return true; } catch(err) { } try { e.which=v; return true; } catch(err) { } try { e.charCode=v; return true; } catch(err) { } try { event.keyCode=v; return true; } catch(err) { } try { event.which=v; return true; } catch(err) { } try { event.charCode=v; return true; } catch(err) { } } // TROCA ENTER POR TAB NO ONKEYDOWN // onKeyDown='enter_tab();' function enter_tab() { kcode = keyCode(); if (kcode == 13) { keyCodeSet(9); } } // onKeyPress="slenter_tab('prx_campo');" // para campos select // o select nao pega o keydown com code 13 function slenter_tab(prx) { //alert('Prx '+ prx); kcode = keyCode(); if (kcode == 13) { try { campo = getElement(prx); //alert(campo); if (campo) campo.focus(); } catch (err) { } } } // EXECUTA EVENTO SE ENTER PRESSIONADO // onKeyDown='enter_exec('alert(\'Enter pressionado\');');' function enter_exec(funcao) { kcode = keyCode(); if (kcode == 13) eval(funcao); } function dia_valido(valor) { inteiro = intval(valor); if (inteiro>0 && inteiro < 32) return true; return false; } function mes_valido(valor) { inteiro = intval(valor); if (inteiro>0 && inteiro < 13) return true; return false; } function ano_valido(valor) { inteiro = intval(valor); if (inteiro>1950 && inteiro < 2100) return true; return false; } // FUNCOES DE VALIDACAO PARA CAMPOS DE DATA SEPARADA function cdia_validar(code, campo, id, campo_proximo, proximo) { eval(id +'dia_pressionado = true;'); eval(id +'mes_pressionado = false;'); eval(id +'ano_pressionado = false;'); if (code == 13) { if (dia_valido(campo.value)) { mes = getElement(id +'_mes'); if (mes.value != '') if (campo_proximo != '') getElement(campo_proximo).focus(); else keyCodeSet(9); if (proximo!="") { cdata_aplicar(proximo,getElement(id +'_dia').value,getElement(id +'_mes').value,getElement(id +'_ano').value); } else keyCodeSet(9); } } } function cdia_up(campo, id) { try { eval('press = '+ id +'dia_pressionado;'); } catch (err) { press = false; } if (strlen(campo.value)>=2 && press) { if (dia_valido(campo.value)) getElement(id +'_mes').focus(); else campo.select(); } eval(id +'dia_pressionado = false;'); } function cmes_validar(code, campo, id, campo_proximo, proximo) { eval(id +'dia_pressionado = false;'); eval(id +'mes_pressionado = true;'); eval(id +'ano_pressionado = false;'); if (code == 13) { if (mes_valido(campo.value)) { ano = getElement(id +'_ano'); if (ano.value != '') if (campo_proximo != '') getElement(campo_proximo).focus(); else keyCodeSet(9); if (proximo!="") { cdata_aplicar(proximo,getElement(id +'_dia').value,getElement(id +'_mes').value,getElement(id +'_ano').value); } else window.event.keyCode = 9; } } if (code == 27) { keyCodeSet(1); getElement(id +'_dia').focus(); } } function cmes_up(campo, id) { try { eval('press = '+ id +'mes_pressionado;'); } catch (err) { press = false; } if (strlen(campo.value)>=2 && press) { if (mes_valido(campo.value)) getElement(id +'_ano').focus(); else campo.select(); } eval(id +'mes_pressionado = false;'); } function cano_validar(code, campo, id, campo_proximo, proximo) { eval(id +'dia_pressionado = false;'); eval(id +'mes_pressionado = false;'); eval(id +'ano_pressionado = true;'); if (code == 13) { if (ano_valido(campo.value)) { if (campo_proximo != '') getElement(campo_proximo).focus(); else keyCodeSet(9); if (proximo!="") { cdata_aplicar(proximo,getElement(id +'_dia').value,getElement(id +'_mes').value,getElement(id +'_ano').value); } } } if (code == 27) { keyCodeSet(1); getElement(id +'_mes').focus(); } } function cano_up(campo, id, campo_proximo, proximo) { try { eval('press = '+ id +'ano_pressionado;'); } catch (err) { press = false; } if (strlen(campo.value)>=4 && press) { //alert('Pr '+ press); if (ano_valido(campo.value)) { //getElement(id +'_ano').focus(); // deveria emular o pressionamento de um tab para que avance o campo if (campo_proximo!='') { getElement(campo_proximo).focus(); } if (proximo!="") { cdata_aplicar(proximo,getElement(id +'_dia').value,getElement(id +'_mes').value,getElement(id +'_ano').value); } } else campo.select(); } } function cdata_aplicar(campo,dia, mes, ano) { getElement(campo +'_dia').value = dia; getElement(campo +'_mes').value = mes; getElement(campo +'_ano').value = ano; } //onkeypress="formatar(this,'##/##/####')" // este formatar funciona para letras tbm function formatarAntigo(src, mask, type) { 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); } } // onkeypress="return formatar(this,'##/##/####',event)" // por padrao so permite numeros = regex = /\d/; // tipo = alfan // tipo = num function formatar(src, mask, evt, tipo) { var key = keyCode(evt); regex = /\d/; if (tipo == "num") regex = /\d/; if (tipo == "alfan") regex = /(\w|\s)/; if ( key >= 32 && key < 127 ) { var ch = String.fromCharCode(key); var str = src.value + ch; var pos = str.length; if ( regex.test(ch) && pos <= mask.length ) { //alert(' P2 '); if (mask.charAt(pos - 1) != ' ' && mask.charAt(pos - 1) != '#') { //alert(src.value +' + '+ mask.charAt(pos - 1) +' + '+ ch); str = src.value + mask.charAt(pos - 1) + ch; } src.value = str; } keyCodeSet(0,evt); return false; } } function getElement(id) { try { elem = document.getElementById( id ); return elem; } catch (err) { } try { if ( document.all ) { elem = document.all[id]; return elem; } } catch (err) { } try { if( document.layers ) { elem = document.layers[id]; return elem; } } catch (err) { alert('function getElement - Não foi possivel localizar o elemento '+ id); return false; } } // FUNCOES ABAIXO PARA VALIDACAO DO CNPJ E CPF // ******************************************* /** * @author Márcio d'Ávila * @version 1.01, 2004 * * PROTÓTIPOS: * método String.lpad(int pSize, char pCharPad) * método String.trim() * * String unformatNumber(String pNum) * String formatCpfCnpj(String pCpfCnpj, boolean pUseSepar, boolean pIsCnpj) * String dvCpfCnpj(String pEfetivo, boolean pIsCnpj) * boolean isCpf(String pCpf) * boolean isCnpj(String pCnpj) * boolean isCpfCnpj(String pCpfCnpj) */ var NUM_DIGITOS_CPF = 11; var NUM_DIGITOS_CNPJ = 14; var NUM_DGT_CNPJ_BASE = 8; /** * Adiciona método lpad() à classe String. * Preenche a String à esquerda com o caractere fornecido, * até que ela atinja o tamanho especificado. */ String.prototype.lpad = function(pSize, pCharPad) { var str = this; var dif = pSize - str.length; var ch = String(pCharPad).charAt(0); for (; dif>0; dif--) str = ch + str; return (str); } //String.lpad /** * Adiciona método trim() à classe String. * Elimina brancos no início e fim da String. */ String.prototype.trim = function() { return this.replace(/^\s*/, "").replace(/\s*$/, ""); } //String.trim /** * Elimina caracteres de formatação e zeros à esquerda da string * de número fornecida. * @param String pNum * String de número fornecida para ser desformatada. * @return String de número desformatada. */ function unformatNumber(pNum) { return String(pNum).replace(/\D/g, "").replace(/^0+/, ""); } //unformatNumber /** * Formata a string fornecida como CNPJ ou CPF, adicionando zeros * à esquerda se necessário e caracteres separadores, conforme solicitado. * @param String pCpfCnpj * String fornecida para ser formatada. * @param boolean pUseSepar * Indica se devem ser usados caracteres separadores (. - /). * @param boolean pIsCnpj * Indica se a string fornecida é um CNPJ. * Caso contrário, é CPF. Default = false (CPF). * @return String de CPF ou CNPJ devidamente formatada. */ function formatCpfCnpj(pCpfCnpj, pUseSepar, pIsCnpj) { if (pIsCnpj==null) pIsCnpj = false; if (pUseSepar==null) pUseSepar = true; var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF; var numero = unformatNumber(pCpfCnpj); numero = numero.lpad(maxDigitos, '0'); if (!pUseSepar) return numero; if (pIsCnpj) { reCnpj = /(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/; numero = numero.replace(reCnpj, "$1.$2.$3/$4-$5"); } else { reCpf = /(\d{3})(\d{3})(\d{3})(\d{2})$/; numero = numero.replace(reCpf, "$1.$2.$3-$4"); } return numero; } //formatCpfCnpj /** * Calcula os 2 dígitos verificadores para o número-efetivo pEfetivo de * CNPJ (12 dígitos) ou CPF (9 dígitos) fornecido. pIsCnpj é booleano e * informa se o número-efetivo fornecido é CNPJ (default = false). * @param String pEfetivo * String do número-efetivo (SEM dígitos verificadores) de CNPJ ou CPF. * @param boolean pIsCnpj * Indica se a string fornecida é de um CNPJ. * Caso contrário, é CPF. Default = false (CPF). * @return String com os dois dígitos verificadores. */ function dvCpfCnpj(pEfetivo, pIsCnpj) { if (pIsCnpj==null) pIsCnpj = false; var i, j, k, soma, dv; var cicloPeso = pIsCnpj? NUM_DGT_CNPJ_BASE: NUM_DIGITOS_CPF; var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF; var calculado = formatCpfCnpj(pEfetivo, false, pIsCnpj); calculado = calculado.substring(2, maxDigitos); var result = ""; for (j = 1; j <= 2; j++) { k = 2; soma = 0; for (i = calculado.length-1; i >= 0; i--) { soma += (calculado.charAt(i) - '0') * k; k = (k-1) % cicloPeso + 2; } dv = 11 - soma % 11; if (dv > 9) dv = 0; calculado += dv; result += dv } return result; } //dvCpfCnpj /** * Testa se a String pCpf fornecida é um CPF válido. * Qualquer formatação que não seja algarismos é desconsiderada. * @param String pCpf * String fornecida para ser testada. * @return true se a String fornecida for um CPF válido. */ function isCpf(pCpf) { var numero = formatCpfCnpj(pCpf, false, false); var base = numero.substring(0, numero.length - 2); var digitos = dvCpfCnpj(base, false); var algUnico, i; // Valida dígitos verificadores if (numero != base + digitos) return false; /* Não serão considerados válidos os seguintes CPF: * 000.000.000-00, 111.111.111-11, 222.222.222-22, 333.333.333-33, 444.444.444-44, * 555.555.555-55, 666.666.666-66, 777.777.777-77, 888.888.888-88, 999.999.999-99. */ algUnico = true; for (i=1; itrue se a String fornecida for um CNPJ válido. */ function isCnpj(pCnpj) { if (pCnpj.length < 14) return false; var numero = formatCpfCnpj(pCnpj, false, true); var base = numero.substring(0, NUM_DGT_CNPJ_BASE); var ordem = numero.substring(NUM_DGT_CNPJ_BASE, 12); var digitos = dvCpfCnpj(base + ordem, true); var algUnico; // Valida dígitos verificadores if (numero != base + ordem + digitos) return false; /* Não serão considerados válidos os CNPJ com os seguintes números BÁSICOS: * 11.111.111, 22.222.222, 33.333.333, 44.444.444, 55.555.555, * 66.666.666, 77.777.777, 88.888.888, 99.999.999. */ algUnico = numero.charAt(0) != '0'; for (i=1; itrue se a String fornecida for um CPF ou CNPJ válido. */ function isCpfCnpj(pCpfCnpj) { var numero = pCpfCnpj.replace(/\D/g, ""); if (numero.length > NUM_DIGITOS_CPF) return isCnpj(pCpfCnpj) else return isCpf(pCpfCnpj); } //isCpfCnpj // ******************************************************** // fim das funcoes de validacao de cpf e cnpj // ******************************************************** // funcao de abrir foto sobre a pagina com fundo preto // JavaScript Document /* Lightbox JS: Fullsize Image Overlays by Lokesh Dhakar - http://www.huddletogether.com For more information on this script, visit: http://huddletogether.com/projects/lightbox/ Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/ (basically, do anything you want, just leave my name and link) Table of Contents ----------------- Configuration Functions - getPageScroll() - getPageSize() - pause() - getKey() - listenKey() - showLightbox() - hideLightbox() - initLightbox() - addLoadEvent() Function Calls - addLoadEvent(initLightbox) */ // // Configuration // // If you would like to use a custom loading image or close button reference them in the next two lines. var loadingImage = '/layout/basico/images/lb_car.gif'; var closeButton = '/layout/basico/images/lb_clo.gif'; var imgOverlay = '/layout/basico/images/lb_overlay.png'; // // getPageScroll() // Returns array with x,y page scroll values. // Core code from - quirksmode.org // function getPageScroll(){ var yScroll; if (self.pageYOffset) { yScroll = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict yScroll = document.documentElement.scrollTop; } else if (document.body) {// all other Explorers yScroll = document.body.scrollTop; } arrayPageScroll = new Array('',yScroll) return arrayPageScroll; } // // getPageSize() // Returns array with page width, height and window width, height // Core code from - quirksmode.org // Edit for Firefox by pHaez // function getPageSize(){ var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { // all except Explorer windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } // for small pages with total width less then width of the viewport if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) return arrayPageSize; } // // pause(numberMillis) // Pauses code execution for specified time. Uses busy code, not good. // Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602 // function pause(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; while (true) { now = new Date(); if (now.getTime() > exitTime) return; } } // // getKey(key) // Gets keycode. If 'x' is pressed then it hides the lightbox. // function getKey(e){ if (e == null) { // ie keycode = event.keyCode; } else { // mozilla keycode = e.which; } key = String.fromCharCode(keycode).toLowerCase(); if(key == 'x'){ hideLightbox(); } } // // listenKey() // function listenKey () { document.onkeypress = getKey; } // // showLightbox() // Preloads images. Pleaces new image in lightbox then centers and displays. // function showLightbox(objLink) { // prep objects var objOverlay = document.getElementById('overlay'); var objLightbox = document.getElementById('lightbox'); var objCaption = document.getElementById('lightboxCaption'); var objImage = document.getElementById('lightboxImage'); var objLoadingImage = document.getElementById('loadingImage'); var objLightboxDetails = document.getElementById('lightboxDetails'); var arrayPageSize = getPageSize(); var arrayPageScroll = getPageScroll(); // center loadingImage if it exists if (objLoadingImage) { objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px'); objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px'); objLoadingImage.style.display = 'block'; } // set height of Overlay to take up whole page and show objOverlay.style.height = (arrayPageSize[1] + 'px'); objOverlay.style.display = 'block'; // preload image imgPreload = new Image(); imgPreload.onload=function(){ objImage.src = objLink.href; // center lightbox and make sure that the top and left values are not negative // and the image placed outside the viewport var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2); var lightboxLeft = ((arrayPageSize[0] - 20 - imgPreload.width) / 2); objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px"; objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px"; objLightboxDetails.style.width = imgPreload.width + 'px'; if(objLink.getAttribute('title')){ objCaption.style.display = 'block'; //objCaption.style.width = imgPreload.width + 'px'; objCaption.innerHTML = objLink.getAttribute('title'); } else { objCaption.style.display = 'none'; } // A small pause between the image loading and displaying is required with IE, // this prevents the previous image displaying for a short burst causing flicker. if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } if (objLoadingImage) { objLoadingImage.style.display = 'none'; } // Hide select boxes as they will 'peek' through the image in IE selects = document.getElementsByTagName("select"); for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "hidden"; } objLightbox.style.display = 'block'; // After image is loaded, update the overlay height as the new image might have // increased the overall page height. arrayPageSize = getPageSize(); objOverlay.style.height = (arrayPageSize[1] + 'px'); // Check for 'x' keypress listenKey(); return false; } imgPreload.src = objLink.href; } function flashLightbox(imgURL) { // prep objects var objOverlay = document.getElementById('overlay'); var objLightbox = document.getElementById('lightbox'); var objImage = document.getElementById('lightboxImage'); var objLoadingImage = document.getElementById('loadingImage'); var arrayPageSize = getPageSize(); var arrayPageScroll = getPageScroll(); // center loadingImage if it exists if (objLoadingImage) { objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px'); objLoadingImage.style.left = (((arrayPageSize[0] - 40 - objLoadingImage.width) / 2) + 'px'); objLoadingImage.border = 0; } // set height of Overlay to take up whole page and show objOverlay.style.height = (arrayPageSize[1] + 'px'); objOverlay.style.display = ''; objOverlay.border = 0; objOverlay.className = 'overlay'; objOverlay.innerHTML=''; // preload image imgPreload = new Image(); imgPreload.onload=function(){ objImage.src = imgURL; objImage.border = 0; // center lightbox objLightbox.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2) + 'px'); objLightbox.style.left = (((arrayPageSize[0] - 40 - imgPreload.width) / 2) + 'px'); // A small pause between the image loading and displaying is required with IE, // this prevents the previous image displaying for a short burst causing flicker. if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } objLightbox.style.display = 'block'; return false; } imgPreload.src = imgURL; } // // hideLightbox() // function hideLightbox() { // get objects objOverlay = document.getElementById('overlay'); objLightbox = document.getElementById('lightbox'); // hide lightbox and overlay objOverlay.style.display = 'none'; objLightbox.style.display = 'none'; // make select boxes visible selects = document.getElementsByTagName("select"); for (i = 0; i != selects.length; i++) { selects[i].style.visibility = "visible"; } // disable keypress listener document.onkeypress = ''; } // // initLightbox() // Function runs on window load, going through link tags looking for rel="lightbox". // These links receive onclick events that enable the lightbox display for their targets. // The function also inserts html markup at the top of the page which will be used as a // container for the overlay pattern and the inline image. // function initLightbox() { //alert('initlight'); if (!document.getElementsByTagName){ return; } var anchors = document.getElementsByTagName("a"); // loop through all anchor tags for (var i=0; i // // // var objBody = document.getElementsByTagName("body").item(0); // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file) var objOverlay = document.createElement("div"); objOverlay.setAttribute('id','overlay'); objOverlay.onclick = function () {hideLightbox(); return false;} objOverlay.style.display = 'none'; objOverlay.style.position = 'absolute'; objOverlay.style.top = '0'; objOverlay.style.left = '0'; objOverlay.style.zIndex = '90'; objOverlay.style.width = '100%'; //imgOO = 'http://www.projemoveis.ind.br'+ imgOverlay; //alert(imgOO); //objOverlay.style.backgroundColor = '#002500'; //objOverlay.style.backgroundImage.src = imgOverlay; objBody.insertBefore(objOverlay, objBody.firstChild); var arrayPageSize = getPageSize(); var arrayPageScroll = getPageScroll(); // preload and create loader image var imgPreloader = new Image(); // if loader image found, create link to hide lightbox and create loadingimage imgPreloader.onload=function(){ var objLoadingImageLink = document.createElement("a"); objLoadingImageLink.setAttribute('href','#'); objLoadingImageLink.onclick = function () {hideLightbox(); return false;} objOverlay.appendChild(objLoadingImageLink); var objLoadingImage = document.createElement("img"); objLoadingImage.src = loadingImage; objLoadingImage.setAttribute('id','loadingImage'); objLoadingImage.style.position = 'absolute'; objLoadingImage.style.zIndex = '150'; objLoadingImageLink.appendChild(objLoadingImage); imgPreloader.onload=function(){}; // clear onLoad, as IE will flip out w/animated gifs return false; } imgPreloader.src = loadingImage; // create lightbox div, same note about styles as above var objLightbox = document.createElement("div"); objLightbox.setAttribute('id','lightbox'); objLightbox.style.display = 'none'; objLightbox.style.position = 'absolute'; objLightbox.style.zIndex = '100'; objLightbox.style.backgroundImage.src = imgOverlay; objBody.insertBefore(objLightbox, objOverlay.nextSibling); // create link var objLink = document.createElement("a"); objLink.setAttribute('href','#'); objLink.setAttribute('title','Clique para fechar'); objLink.onclick = function () {hideLightbox(); return false;} objLightbox.appendChild(objLink); // preload and create close button image var imgPreloadCloseButton = new Image(); // if close button image found, imgPreloadCloseButton.onload=function(){ var objCloseButton = document.createElement("img"); objCloseButton.src = closeButton; objCloseButton.border = 0; objCloseButton.setAttribute('id','closeButton'); objCloseButton.style.position = 'absolute'; objCloseButton.style.zIndex = '200'; objLink.appendChild(objCloseButton); return false; } imgPreloadCloseButton.src = closeButton; // create image var objImage = document.createElement("img"); objImage.setAttribute('id','lightboxImage'); objLink.appendChild(objImage); // create details div, a container for the caption and keyboard message var objLightboxDetails = document.createElement("div"); objLightboxDetails.setAttribute('id','lightboxDetails'); objLightbox.appendChild(objLightboxDetails); // create caption var objCaption = document.createElement("div"); objCaption.setAttribute('id','lightboxCaption'); objCaption.style.display = 'none'; objLightboxDetails.appendChild(objCaption); /* // create keyboard message var objKeyboardMsg = document.createElement("div"); objKeyboardMsg.setAttribute('id','keyboardMsg'); objKeyboardMsg.innerHTML = 'Pressione x para fechar'; objLightboxDetails.appendChild(objKeyboardMsg); */ } // // addLoadEvent() // Adds event to window.onload without overwriting currently assigned onload functions. // Function found at Simon Willison's weblog - http://simon.incutio.com/ // function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function'){ window.onload = func; } else { window.onload = function(){ oldonload(); func(); } } } addLoadEvent(initLightbox); // run initLightbox onLoad // funcao de abrir foto sobre a pagina com fundo preto - fim // ********************************************************