try { xmlhttp = new XMLHttpRequest(); } catch (ee) { try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(E) { xmlhttp = false; } } } function confirma(mensagem, comando) { if (confirm(mensagem)) { return eval(comando); } else { return false; } } function Imprimir(){ if (window.print) { window.print(); } else { var WebBrowser = ''; document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(6, 2); WebBrowser1.outerHTML = " "; } } var ajaxHistory = { 'items': [], 'captions': [], 'currentIndex': 0, 'go': function(ref) { if(this.items[this.currentIndex + ref] || false) this.currentIndex += ref; else return; if(this.activeHistory) this.setHash(); if(this.captions[this.currentIndex]) document.title = this.captions[this.currentIndex]; new Function(this.items[this.currentIndex])(); }, 'goTo': function(ind) { if(this.items[ind] || false) this.currentIndex = ind; else return; if(this.activeHistory) this.setHash(); if(this.captions[this.currentIndex]) document.title = this.captions[this.currentIndex]; new Function(this.items[this.currentIndex])(); }, 'add': function(str, cap) { if(str == this.items[this.currentIndex]) return false; this.currentIndex = this.items.length; this.items.push(str); this.captions.push(cap || false); if(this.activeHistory) this.setHash(); return true; }, 'hasBack': function() { return (this.items[this.currentIndex - 1] || false) ? true : false; }, 'hasForward': function() { return (this.items[this.currentIndex + 1] || false) ? true : false; }, 'activeHistory': false, 'activateBrowserHistory': function() { if(document.all) this.makeIframe(); else setInterval("ajaxHistory.checkHash()", 100); this.activeHistory = true; }, 'makeIframe': function() { this.iframe = document.createElement('iframe'); this.iframe.style.display = 'none'; this.iframe.src = 'historyframe.html'; document.getElementsByTagName('body')[0].appendChild(this.iframe); }, 'checkHash': function() { var curHash = location.hash.replace(/#/,''); if(this.currentIndex != curHash) this.goTo(curHash); }, 'setHash': function() { top.location.hash = this.currentIndex; if(document.all) this.iframe.contentWindow.location.href = 'historyframe.html?'+this.currentIndex; } }; function verifica_anula_ajax(elemento){ classes = carrega_em_array(elemento.className, ' '); for (var aux2 = 0; aux2 < classes.length; aux2++) { classe = classes[aux2]; if (classe == 'anula_ajax') { return true; } } return false; } function carrega_ajax(){ //Obt�m os links da pagina var conteudo=document.getElementById('conteudo'); var links=conteudo.getElementsByTagName("a"); //Atribui o evento for(var i=0; i < links.length ; i++) { if (links[i].href == "javascript://" || links[i].target == "ignora_ajax" || links[i].target == "anula_ajax" || links[i].target == "_BLANK" || links[i].target == "_TOP" || links[i].target == "_PARENT") { if (links[i].target == "anula_ajax") { links[i].target = ''; } } else { links[i].onclick = carregar; } } return true; } atual=0 function carrega(pagina){ carrega_para_destino(pagina, "conteudo"); } function copia_parametros(parametros) { parametros = parametros.getElementsByTagName("input"); for(var i=0;i < parametros.length;i++) { iddestino = parametros[i].id; iddestino = iddestino.substring(18); destino = document.getElementById(iddestino); if (destino != null) { destino.value = parametros[i].value; } } } function extraiScript(texto){ var ini = 0; // loop enquanto achar um script while (ini!=-1){ // procura uma tag de script ini = texto.indexOf('=0){ // define o inicio para depois do fechamento dessa tag ini = texto.indexOf('>', ini) + 1; // procura o final do script var fim = texto.indexOf('', ini); // extrai apenas o script codigo = texto.substring(ini,fim); novo = document.createElement("script") novo.text = codigo; document.body.appendChild(novo); } } } function carrega_para_destino_onoff_assinc(pagina, destino, onoff, assincrono, nao_salva_historico){ comando = 'carrega_para_destino_onoff_assinc(\''+pagina+'\', \''+destino+'\', \''+onoff+'\', \''+assincrono+'\')'; if (nao_salva_historico != true) { ajaxHistory.add(comando, document.caption); } //Exibe o texto carregando no div conte�do var conteudo_vazio = false; if (destino != null) { var conteudo=document.getElementById(destino); if (conteudo.innerHTML == '') { var conteudo_vazio = true; } } if (onoff === true && !conteudo_vazio) { if (destino != null) { conteudo.innerHTML = ''; } } else { if (destino != null) { conteudo.innerHTML = '
Cargando...
Cargando...'; } //Abre a url xmlhttp2 = new XMLHttpRequest(); timeout = setTimeout(function(){ xmlhttp2.abort(); }, 15000); xmlhttp2.open("GET", pagina+"&ajax=1", assincrono); xmlhttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"); xmlhttp2.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate"); xmlhttp2.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); xmlhttp2.setRequestHeader("Pragma", "no-cache"); //Executada quando o navegador obtiver o c�digo xmlhttp2.onreadystatechange=function() { if (xmlhttp2.readyState==4){ //Exibe o texto no div conte�do if (destino != null) { var conteudo = document.getElementById(destino); conteudo.innerHTML = xmlhttp2.responseText; extraiScript(xmlhttp2.responseText); } else { extraiScript(xmlhttp2.responseText); } conteudo2 = document.getElementById("recarrega_ajax"); if (conteudo2 != null) { carrega_ajax(); } conteudo2 = document.getElementById("validar"); if (conteudo2 != null) { inicia_validar(); } } clearTimeout(timeout); } xmlhttp2.send(null); } } function carrega_para_destino_onoff(pagina, destino, onoff){ carrega_para_destino_onoff_assinc(pagina, destino, false, true); } function carrega_para_destino(pagina, destino){ carrega_para_destino_onoff(pagina, destino, false); } function carregar(e){ //Correcao para eventos quebrados da Microsoft if(typeof(e)=='undefined') { var e=window.event; } source=e.target?e.target:e.srcElement; //Correcao para o bug do Konqueror/Safari if(source.nodeType==3 || source.type != '') source = source.parentNode; if(source.getAttribute("href") == null) { source = source.parentNode; } if(source.getAttribute("href") == null) { source = source.parentNode; } if(source.getAttribute("href") == null) { source = source.parentNode; } //Obtem o numero quebrando a url pagina=source.getAttribute("href"); destino = "conteudo"; alvo = source.getAttribute("target"); if (alvo != null) { if (alvo.substring(0, 1) == "_" && alvo != "_BLANK" && alvo != "_SELF" && alvo != "_PARENT" && alvo != "_TOP") { destino = alvo; } } //Chama o carrega carrega_para_destino(pagina, destino); //Cancela o click (evita a navegacao) return false; } function envia_campos(formdestino, idform, divretorno, campos, divloading) { if (campos == '') { if (formdestino.indexOf('controlador.php?pagina=') == -1) { formdestino = formdestino.substring(formdestino.lastIndexOf('/')+1); formdestino = 'controlador.php?pagina='+formdestino; } formulario = document.getElementById(idform); if (formulario.target != "") { divretorno = formulario.target; } var elementos = formulario.elements; Post = ''; for(i = 0; i < elementos.length; i++){ campo = elementos[i].name.replace(/\[\]/i, ""); Atual = "&"+campo+"="+url_encode(elementos[i].value); if (elementos[i].type == 'radio' || elementos[i].type == 'checkbox') { if (elementos[i].checked) { if (elementos[i].value == 'on') { Atual = "&"+campo+"=on"; } else { Atual = "&"+campo+"=off"; } } else { Atual = ""; } } if (elementos[i].type == 'submit') { Atual = ""; } Post += Atual; } Post += "&ajax=true"; comando = 'envia_campos(\''+formdestino+'\', \''+idform+'\', \''+divretorno+'\', \''+Post+'\')'; ajaxHistory.add(comando, document.caption); } else { Post = campos; } if (divretorno != null) { if(divloading !== undefined) { loading_element = document.getElementById(divloading); loading_element.innerHTML = '
Cargando...
Cargando...'; } else { retorno = document.getElementById(divretorno); retorno.innerHTML = '
Cargando...
Cargando...'; loading_element = undefined; } }; timeout = setTimeout(function(){ xmlhttp.abort(); }, 15000); xmlhttp.open("POST", formdestino ,true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1;"); xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate"); xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); xmlhttp.setRequestHeader("Pragma", "no-cache"); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4){ if (divretorno != null) { retorno = document.getElementById(divretorno); retorno.innerHTML = xmlhttp.responseText; if(loading_element !== undefined) { loading_element.innerHTML = ''; } } extraiScript(xmlhttp.responseText); conteudo2 = document.getElementById("recarrega_ajax"); if (conteudo2 != null) { carrega_ajax(); } conteudo2 = document.getElementById("validar"); if (conteudo2 != null) { inicia_validar(); } } clearTimeout(timeout); } /* Envia os dados contidos na variavel texto como se fosse uma parametros de um GET */ xmlhttp.send(Post); return false; } function envia(formdestino, idform, divretorno, divloading) { envia_campos(formdestino, idform, divretorno, '', divloading); return false; } // url_encode version 1.0 function url_encode(str) { var hex_chars = "0123456789ABCDEF"; var noEncode = /^([a-zA-Z0-9\_\-\.])$/; var n, strCode, hex1, hex2, strEncode = ""; for(n = 0; n < str.length; n++) { if (noEncode.test(str.charAt(n))) { strEncode += str.charAt(n); } else { strCode = str.charCodeAt(n); hex1 = hex_chars.charAt(Math.floor(strCode / 16)); hex2 = hex_chars.charAt(strCode % 16); strEncode += "%" + (hex1 + hex2); } } return strEncode; } // url_decode version 1.0 function url_decode(str) { var n, strCode, strDecode = ""; for (n = 0; n < str.length; n++) { if (str.charAt(n) == "%") { strCode = str.charAt(n + 1) + str.charAt(n + 2); strDecode += String.fromCharCode(parseInt(strCode, 16)); n += 2; } else { strDecode += str.charAt(n); } } return strDecode; } function inicia_ajax(){ //Obtem os links do menu var menu=document.getElementById('menu_princ'); if (menu != null) { var links=menu.getElementsByTagName("a"); //Atribui o evento for(var i=0; i < links.length; i++) { if (links[i].href == "javascript://" || links[i].target == "ignora_ajax" || links[i].target == "anula_ajax" || links[i].target == "_BLANK" || links[i].target == "_TOP" || links[i].target == "_PARENT") { if (links[i].target == "anula_ajax") { links[i].target = ''; } } else { links[i].onclick = carregar; } } } conteudo2 = document.getElementById("recarrega_ajax"); if (conteudo2 != null) { carrega_ajax(); } conteudo2 = document.getElementById("validar"); if (conteudo2 != null) { inicia_validar(); } ajaxHistory.activateBrowserHistory(); } function envia_form_post(formulario, divretorno) { if (formulario.action == undefined || divretorno == null) { return false; } let tmpurl = formulario.action.split('/'); if (tmpurl[tmpurl.length - 1].indexOf('controlador.php?pagina=') == -1) { tmpurl[tmpurl.length - 1] = 'controlador.php?pagina=' + tmpurl[tmpurl.length - 1]; } let formdestino = tmpurl[tmpurl.length - 1]; if (formulario.target != '') { divretorno = formulario.target; } inactiva_campos(formulario, 'off'); let Post = prepara_campos(formulario); Post += "&ajax=true"; comando = 'envia_form_post(\'' + formulario + '\', \'' + divretorno + '\')'; ajaxHistory.add(comando, document.caption); retorno = document.getElementById(divretorno); retorno.innerHTML = '
Cargando...
Carregando...'; timeout = setTimeout(function() { xmlhttp.abort(); }, 15000); xmlhttp.open("POST", formdestino, true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1;"); xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate"); xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0"); xmlhttp.setRequestHeader("Pragma", "no-cache"); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { inactiva_campos(formulario, 'on'); retorno = document.getElementById(divretorno); retorno.innerHTML = xmlhttp.responseText; extraiScript(xmlhttp.responseText); conteudo2 = document.getElementById("recarrega_ajax"); if (conteudo2 != null) { carrega_ajax(); } conteudo2 = document.getElementById("validar"); if (conteudo2 != null) { inicia_validar(); } } clearTimeout(timeout); } xmlhttp.send(Post); return false; } function inactiva_campos(form, status) { if (status == 'off') { status = true; } else { status = false; } if (form.elements != null && form.elements.length > 0) { for (let i = 0; i < form.elements.length; i++) { if (form.elements[i].type != 'hidden') { form.elements[i].disabled = status; } } } } function prepara_campos(form) { let cadena = ''; let campo = ''; let atual = ''; if (form.elements != null && form.elements.length > 0) { for (let i = 0; i < form.elements.length; i++) { campo = form.elements[i].name.replace(/\[\]/i, ""); atual = "&" + campo + "=" + url_encode(form.elements[i].value); if (form.elements[i].type == 'radio' || form.elements[i].type == 'checkbox') { if (form.elements[i].checked) { if (form.elements[i].value == 'on') { atual = "&" + campo + "=on"; } else { atual = "&" + campo + "=off"; } } else { atual = ""; } } if (form.elements[i].type == 'submit') { atual = ""; } cadena += atual; } } return cadena; } if(xmlhttp) { window.onload=inicia_ajax; }