/*
* ANP - Agencia Nacional do Petroleo, Gas Natural e Biocombustiveis
* NIN / Equipe WEB
*
* Biblioteca com as funcoes especificas do site
*/

/******************************************************************
* FUNCAO: 		menu
* OBJETIVO:		Mostrar o menu do site
* PARAMETROS:	Sequencial da area (NUMBER)
* SAIDA:
*******************************************************************/
function menu( id ) {
	
	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						menu( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------		
					showLoading ();
					pesquisa_avancada_fechar ();
					rss_fechar ();

					var obj = document.getElementById("menu_interno");
					obj.innerHTML = "";
					obj.style.display = "none";

					var obj = document.getElementById("menu_conteudo");
					html_temp = obj.innerHTML;
				
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/menu/principal/?id=" + id + "&cachebust=" + new Date().getTime()

					objHTTP.open("get", strUrl, true );

					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");

								if ( resultado.indexOf("REDIRECIONAR:") !== -1 ) {
									location.href = "/";
									return;
								}
								else if ( resultado.indexOf("ERRO:") == -1 ) {
									if ( resultado == "<ul></ul>" ) obj.innerHTML = html_temp
									else obj.innerHTML = resultado;
									submenu( id );
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);	
}

/******************************************************************
* FUNCAO: 		submenu
* OBJETIVO:		Mostrar o menu da subpagina (index2) do site
* PARAMETROS:	Sequencial da area (NUMBER)
*				Borleano para ler a pagina ou nao
* SAIDA:
*******************************************************************/
function submenu( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;

				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						submenu( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------	
					showLoading ();
					var obj = document.getElementById("menu_interno");
					
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/menu/secundario/?id=" + id + "&cachebust=" + new Date().getTime();

					objHTTP.open("GET", strUrl, true );

					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");

								// se na string resultado não conter "ERRO:"...
								if ( resultado.indexOf("ERRO:") == -1 ) {

									// a string resultado contém o o menu mais "|0" ou "|1"
									// transforma-se o resultado em um array para poder
									// pegar o menu e inserir no canto esquerdo da página
									// e aciona a função guia passando o respectivo id recebido
									// na string da URL.

									if ( resultado == "|0" || resultado == "|1" ) 
									{
										subpagina ( id );
									}
									else {
										var conteudo = resultado.split("|");
										
										// chamando a função para exibir o menu pai do submenu
										if ( conteudo[1] == "0" ) guia ( id );
										
										// pegando a primeira parte da string resultado, que é o menu, e
										// inserindo na página.
										
										obj.innerHTML = conteudo[0];										
										obj.style.display = "block";
										estaaqui( id, "" );
										subpagina ( id );
									}
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);	
}

/******************************************************************
* FUNCAO: 		guia
* OBJETIVO:		Mostrar o menu pai do submenu
* PARAMETROS:	Sequencial da area (NUMBER)
* SAIDA:
*******************************************************************/
function guia ( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						submenupai ( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------	
					showLoading ();
					var obj = document.getElementById("menu_conteudo");
				
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/menu/guia/area/?id=" + id + "&cachebust=" + new Date().getTime()

					objHTTP.open("GET", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;

								resultado = resultado.replace(/\n/g,"");
								if ( resultado.indexOf("ERRO:") == -1 ) {
									if ( resultado !== "" ) obj.innerHTML = resultado
									else obj.innerHTML = "";
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);	
}

/******************************************************************
* FUNCAO: 		guiapagina
* OBJETIVO:		Mostrar o menu pai do submenu
* PARAMETROS:	Sequencial da pagina (NUMBER)
* SAIDA:
*******************************************************************/
function guiapagina ( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						guiapagina ( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------	
					showLoading ();
					var obj = document.getElementById("menu_conteudo");
				
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/menu/guia/pagina/?id=" + id + "&cachebust=" + new Date().getTime()
					
					objHTTP.open("get", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");

								if ( resultado.indexOf("ERRO:") == -1 ) {
									if ( resultado !== "" ) obj.innerHTML = resultado
									else obj.innerHTML = "";
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);	
}

/******************************************************************
* FUNCAO: 		submenupagina
* OBJETIVO:		Mostrar o submenu da pagina
* PARAMETROS:	Sequencial da pagina (NUMBER)
* SAIDA:
*******************************************************************/
function submenupagina( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						submenupagina( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------
					showLoading ();
					var obj = document.getElementById("menu_interno");
					
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/menu/pagina/secundario/?id=" + id + "&cachebust=" + new Date().getTime();
					
					objHTTP.open("get", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");
				
								if ( resultado.indexOf("ERRO:") == -1 ) {
									if ( resultado == "" ) obj.innerHTML = ""
									else {
										guiapagina ( id );
										obj.innerHTML = resultado;
										obj.style.display = "block";
									}
									caixa ( id );
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);	
}

/******************************************************************
* FUNCAO: 		menupagina
* OBJETIVO:		Mostrar o menu relacionado a pagina clicada
* PARAMETROS:	Sequencial da pagina (NUMBER)
* SAIDA:
*******************************************************************/
function menupagina ( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;

				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						menupagina ( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------	
					showLoading ();
					var obj = document.getElementById("menu_interno");
					obj.innerHTML = "";
					obj.style.display = "none";
				
					var obj = document.getElementById("menu_conteudo");

					var objHTTP = openAjax();
					strUrl = "/SITE/acao/menu/pagina/principal/?id=" + id + "&cachebust=" + new Date().getTime()
					
					objHTTP.open("GET", strUrl, true );

					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 

								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");
								if ( resultado.indexOf("ERRO:") == -1 ) {
									obj.innerHTML = resultado;
									submenupagina( id );
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);
}

/******************************************************************
* FUNCAO: 		estaaqui
* OBJETIVO:		Retorna o caminho ate o ponto em que o usuario esta
* PARAMETROS:	sequencial da area
*				texto no caso de busca, lista, etc.
* SAIDA:		
*******************************************************************/
function estaaqui ( id, texto ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("POST", strUrl, false)
	else objSESSAO.open("POST", strUrl, true);

	objSESSAO.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    objSESSAO.setRequestHeader("Content-length", strUrl.length);
    objSESSAO.setRequestHeader("Connection", "close");

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;

				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						estaaqui ( id, encodeURI(texto) );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------
					showLoading ();
					var caminho = document.getElementById("estaaqui");
										
					var objHTTP = openAjax();

					strUrl   = "/SITE/acao/estaaqui/index.asp" + "?cachebust=" + new Date().getTime();
					var prmLocal = "id=" + id + "&s1=" + texto;

					objHTTP.open("POST", strUrl, true );

					objHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    objHTTP.setRequestHeader("Content-length", prmLocal.length);
                    objHTTP.setRequestHeader("Connection", "close");
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) {
								
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");
				
								if ( resultado.indexOf("ERRO:") == -1 ) {
									caminho.innerHTML = resultado;
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(prmLocal);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(strUrl);					
}

/******************************************************************
* FUNCAO: 		subestaaqui
* OBJETIVO:		Retorna o caminho ate o ponto em que o usuario esta
* PARAMETROS:	sequencial da pagina
* SAIDA:		
*******************************************************************/
function subestaaqui ( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						subestaaqui ( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------
					showLoading ();
					var caminho = document.getElementById("estaaqui");
				
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/estaaqui/subindex/?id=" + id + "&cachebust=" + new Date().getTime();
					objHTTP.open("get", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) {
								
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");
				
								if ( resultado.indexOf("ERRO:") == -1 ) {
									caminho.innerHTML = resultado;
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);					
}

/******************************************************************
* FUNCAO: 		estaaquipagina
* OBJETIVO:		Retorna o caminho ate o ponto em que o usuario esta
* PARAMETROS:	sequencial da pagina
* SAIDA:		
*******************************************************************/
function estaaquipagina ( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						estaaquipagina ( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------
					showLoading ();
					var caminho = document.getElementById("estaaqui");
				
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/estaaqui/pagina/?id=" + id + "&cachebust=" + new Date().getTime();
					objHTTP.open("get", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) {
								
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");
				
								if ( resultado.indexOf("ERRO:") == -1 && resultado !== "" ) caminho.innerHTML = resultado
								else if ( resultado == "" ) subestaaqui ( id )
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);						
}

/******************************************************************
* FUNCAO: 		caixa
* OBJETIVO:		Mostrar as caixas da pagina
* PARAMETROS:	sequencial da pagina
* SAIDA:		as caixas
*******************************************************************/
function caixa ( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						caixa ( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------
					showLoading ();
				
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/caixa/pagina/?id=" + id + "&cachebust=" + new Date().getTime();
					
					objHTTP.open("GET", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");
								if ( resultado.indexOf("ERRO:") == -1 ) {
									
									var obj = document.getElementById("centro");
									html = obj.innerHTML;
									obj.innerHTML = "<div id='centrodireita'></div>" + html;
									var obj = document.getElementById("centrodireita");
									
									if ( resultado !== "" ) {
										
										try { 
																						
											obj.innerHTML = "";
											obj.style.width = "191px";
											if ( BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6") obj.style.margin = "0px";
											
											if (BrowserDetect.browser == "Explorer") obj.style.paddingTop = document.getElementById("inicio").offsetTop + "px"
											else obj.style.paddingTop = (document.getElementById("inicio").offsetTop-100) + "px"
										
											var obj1 = document.createElement("DIV")
											obj1.setAttribute('id','linhaDireita');
											obj1.style.display = "block";
											obj1.style.borderLeftColor = "#CCCCCC";
											obj1.style.borderLeftWidth = "1px";
											obj1.style.borderLeftStyle = "solid";
											obj1.style.width = "191px";
											obj1.style.paddingLeft = "10px";
											obj1.innerHTML = resultado;
											obj.insertBefore(obj1, obj.firstChild);
											
										} catch (e) {};

										obj.style.marginLeft = "10px";
										document.getElementById("linhaDireita").style.height = ( document.getElementById("centro").offsetHeight ) + 'px';
										document.getElementById("linhaDireita").style.height = ( document.getElementById("centro").offsetHeight ) + 'px';
										
										try { 
											var obj = document.getElementById("ultimas");
											obj.style.width = "580px";
										} catch (e) {};

									}
									else {
										
										try { 
											var obj = document.getElementById("centrodireita");
											obj.innerHTML = "";
											obj.style.width = "1px";
										} catch (e) {};
									}
									
									tamanho = ( document.getElementById("menu").offsetHeight + document.getElementById("menu_interno").offsetHeight + 138 );
											
									if ( document.getElementById("centro").offsetHeight > tamanho ) {
										var obj = document.getElementById("esquerda");
										obj.style.height = ( document.getElementById("centro").offsetHeight + 103 ) + 'px';
									}
									else {
										var obj = document.getElementById("esquerda");
										obj.style.height = ( tamanho + 103 ) + 'px';
									}
									
								}	
								else {
									mensagem_sistema ();
									return;				
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);					
}

/******************************************************************
* FUNCAO: 		pagina
* OBJETIVO:		Mostrar o pagina full
* PARAMETROS:	Sequencial da pagina (NUMBER)
* SAIDA:
*******************************************************************/
function pagina ( id, marcador, texto1, texto2, texto3, texto4, area, posicao ) {

	if ( typeof(marcador) 	== "undefined" ) marcador 	= "";
	if ( typeof(texto1) 	== "undefined" ) texto1 	= "";
	if ( typeof(texto2) 	== "undefined" ) texto2 	= "";
	if ( typeof(texto3) 	== "undefined" ) texto3 	= "";
	if ( typeof(texto4) 	== "undefined" ) texto4 	= "";
	if ( typeof(area) 		== "undefined" ) area		= "";
	if ( typeof(posicao)	== "undefined" ) posicao	= "";

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						pagina ( id, marcador, posicao );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------	

					showLoading ();
					if ( typeof(marcador) == "undefined" ) marcador = "";
					var obj = document.getElementById("centro");
				
					var objHTTP = openAjax();

					strUrl = 	"/SITE/acao/pagina/unica/?id=" + id + 
								"&v=" + getValueFromQueryString("v") + 
								"&q1=" + encodeURI(texto1) + 
								"&q2=" + encodeURI(texto2) + 
								"&q3=" + encodeURI(texto3) + 
								"&q4=" + encodeURI(texto4) + 
								"&q5=" + area + 
								"&p=" + posicao + "&cachebust=" + new Date().getTime();
								
					objHTTP.open("GET", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");
								
								if ( resultado.indexOf("/GCI/login") !== -1 ) {
									parent.location.href = encodeURI(resultado);
									return;
								}
									
								if ( resultado.indexOf("REDIRECIONAR:") !== -1 ) {
									location.href = "/";
									return;
								}
								else if ( resultado.indexOf("ERRO:") == -1 ) {
									
									estaaquipagina ( id );
									menupagina ( id );
									obj.innerHTML = resultado; 
									document.getElementById("esquerda").style.height = ( document.getElementById("centro").offsetHeight + 105 ) + 'px';
									
									if ( marcador !== "" ) {
										if ( marcador.indexOf("|") == -1 ) {
											obj.innerHTML = marcadorTexto ( obj.innerHTML, marcador );
										} 
										else {
											texto_marcador = marcador.split("|");
											for (i=0;i<texto_marcador.length;i++ ) {
												obj.innerHTML = marcadorTexto ( obj.innerHTML, texto_marcador[i] );
											}
										}
									}
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);						
}

/******************************************************************
* FUNCAO: 		subpagina
* OBJETIVO:		Mostrar a subpagina (index2)
* PARAMETROS:	Sequencial da area (NUMBER)
* SAIDA:
*******************************************************************/
function subpagina( id ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						subpagina( id );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------	

					showLoading ();
					var obj = document.getElementById("centro");
				
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/pagina/subindex/?id=" + id + "&cachebust=" + new Date().getTime();

					objHTTP.open("GET", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");

								if ( resultado.indexOf("ERRO:") == -1 ) 
								{

									if ( resultado !== "" ) 
									{ 

										estaaqui( id, "" );
										obj.innerHTML = resultado;
										
										if (resultado.indexOf("ferramentas") !== -1 ) 
										{
											var div = document.getElementById("texto_pagina");	
											sequencial = div.getAttribute("seq");
											caixa ( sequencial );
										}
										else 
										{
											subcaixa( id );
										}
									
									}
									else 
									{


										var objHTTPLINK = openAjax();
										strUrl = "/SITE/acao/link/menu/?id=" + id + "&cachebust=" + new Date().getTime();
										objHTTPLINK.open("GET", strUrl, true );
									
										objHTTPLINK.onreadystatechange = function() { 
											if (objHTTPLINK.readyState == 4) {
												if (objHTTPLINK.status == 200) { 
													var resultado = objHTTPLINK.responseText;
													resultado = resultado.replace(/\n/g,"");
													
													if ( resultado.indexOf("ERRO:") == -1 ) {
														if ( resultado !== "" ) {
															try {
																var menuobj = document.getElementById("li_" + id);
																if ( typeof(menuobj) == "object" ) menuobj.className = "menu_off"; 
															}
															catch (e) {}
															link ( resultado, '', '', '' );
														}
														else {
															
															var objHTTPARQUIVO = openAjax();
															strUrl = "/SITE/acao/download/menu/?id=" + id + "&cachebust=" + new Date().getTime();
															objHTTPARQUIVO.open("GET", strUrl, true );
														
															objHTTPARQUIVO.onreadystatechange = function() { 
																if (objHTTPARQUIVO.readyState == 4) {
																	if (objHTTPARQUIVO.status == 200) { 
																		var resultado = objHTTPARQUIVO.responseText;
																		resultado = resultado.replace(/\n/g,"");
																		
																		if ( resultado.indexOf("ERRO:") == -1 ) {
																			if ( resultado !== "" ) {
																				try {
																					var menuobj = document.getElementById("li_" + id);
																					if ( typeof(menuobj) == "object" ) menuobj.className = "menu_off"; 
																				}
																				catch (e) {}
																				download ( resultado );
																			}
																			else {
																				estaaqui( id, "" );
																				var obj = document.getElementById("centro");
																				obj.innerHTML = "<div id='centrodireita'></div>";
																				var obj = document.getElementById("centrodireita");
																				obj.style.width = "1px";
																				tamanho = ( document.getElementById("menu").offsetHeight + document.getElementById("menu_interno").offsetHeight + 138 );
																				obj.style.height = tamanho + 'px';
																				var obj = document.getElementById("esquerda");
																				obj.style.height = ( tamanho + 113 ) + 'px';
																			}
																		}
																		else {
																			alert( "INTERNET\n\nMENSAGEM:\n" + resultado);
																			return;
																		}
																	}
																}
															}
															objHTTPARQUIVO.send(null);
															
														}
													}
													else {
														alert( "INTERNET\n\nMENSAGEM:\n" + resultado);
														return;
													}
												}
											}
										}
										objHTTPLINK.send(null);
										
									}
								}
								else {
									mensagem_sistema ();
									return;
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);	
}

/******************************************************************
* FUNCAO: 		subcaixa
* OBJETIVO:		Mostrar as caixas do subindex
* PARAMETROS:	sequencial da area
* SAIDA:		as caixas
*******************************************************************/
function subcaixa( id ) {
	
	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						subcaixa( id ) ;
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------
					showLoading ();

					var objHTTP = openAjax();
					strUrl = "/SITE/acao/caixa/subindex/?id=" + id + "&cachebust=" + new Date().getTime();
					objHTTP.open("GET", strUrl, true );
				
					objHTTP.onreadystatechange = function() { 
						if (objHTTP.readyState == 4) {
							if (objHTTP.status == 200) { 
								var resultado = objHTTP.responseText;
								resultado = resultado.replace(/\n/g,"");
								if ( resultado.indexOf("ERRO:") == -1 ) {

									if ( resultado !== "" ) {
																	
										if ( id == '1' ) {
											var obj = document.getElementById("centro");
											html = obj.innerHTML;
											obj.innerHTML = "<div id='centrodireita'><div id='menu_secundario'>" + resultado + "</div></div>" + html;
											var obj = document.getElementById("centrodireita");
											tamanho = ( document.getElementById("menu").offsetHeight + document.getElementById("menu_interno").offsetHeight + 138 );
											obj.style.height = tamanho + 'px';
											if ( BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6") {
												var obj = document.getElementById("esquerda");
												obj.style.height = ( tamanho + 203 ) + 'px';
											}
											else {
												var obj = document.getElementById("esquerda");
												obj.style.height = ( tamanho + 203 ) + 'px';
											}
										}
										else {
											
											try { 
											
												var obj = document.getElementById("centro");
												html = obj.innerHTML;
												obj.innerHTML = "<div id='centrodireita'></div>" + html;
												var obj = document.getElementById("centrodireita");
											
											    
												obj.innerHTML = "";
												obj.style.width = "191px";
												obj.style.paddingTop = '0px';
																						
												if ( BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6") obj.style.margin = "0px";
												
												var obj1 = document.createElement("DIV")
												obj1.setAttribute('id','linhaDireita');
												obj1.style.display = "block";
												obj1.style.borderLeftColor = "#CCCCCC";
												obj1.style.borderLeftWidth = "1px";
												obj1.style.borderLeftStyle = "solid";
												obj1.style.width = "191px";
												obj1.style.paddingLeft = "10px";
												obj1.innerHTML = resultado;
												obj.insertBefore(obj1, obj.firstChild);
												
											} catch (e) {};
											obj.style.marginLeft = "10px";
											
											try {


												if ( BrowserDetect.browser == "Explorer" && BrowserDetect.version == "6") {
													document.getElementById("esquerda_bloco").style.width = '273px';
													document.getElementById("direita_bloco").style.width = '273px';
													changeCSS ("#bloco", "width", "265px");
													changeCSS ("#bloco_cabecalho", "width", "265px");
													changeCSS ("#bloco_corpo", "width", "265px");
													changeCSS ("#bloco p.vejamais", "width", "265px");
												}
												else {
													document.getElementById("esquerda_bloco").style.width = '283px';
													document.getElementById("direita_bloco").style.width = '283px';
												}

												document.getElementById("direita_bloco").style.marginRight = '0px';

												tamanho = ( document.getElementById("menu").offsetHeight + document.getElementById("menu_interno").offsetHeight + 138 );
												
												if ( document.getElementById("centro").offsetHeight > tamanho ) {
													document.getElementById("linhaDireita").style.height = ( document.getElementById("centro").offsetHeight - 50 ) + 'px';
													var obj = document.getElementById("esquerda");
													obj.style.height = ( document.getElementById("centro").offsetHeight ) + 'px';
												}
												else {
													document.getElementById("linhaDireita").style.height = tamanho + 'px';
													var obj = document.getElementById("esquerda");
													obj.style.height = ( tamanho + 203 ) + 'px';
												}
												
												tamanho = ( document.getElementById("menu").offsetHeight + document.getElementById("menu_interno").offsetHeight + 138 );
												if ( document.getElementById("centro").offsetHeight > tamanho ) {
													var obj = document.getElementById("esquerda");
													obj.style.height = ( document.getElementById("centro").offsetHeight + 103 ) + 'px';
												}
												
											}
											catch (e) {}
											
										}
									}
									else {
										var obj = document.getElementById("centro");
										html = obj.innerHTML;
										obj.innerHTML = "<div id='centrodireita'></div>" + html;
										var obj = document.getElementById("centrodireita");
										obj.style.width = "1px";
										
										tamanho = ( document.getElementById("menu").offsetHeight + document.getElementById("menu_interno").offsetHeight + 138 );
										if ( document.getElementById("centro").offsetHeight > tamanho ) {
											var obj = document.getElementById("esquerda");
											obj.style.height = ( document.getElementById("centro").offsetHeight + 103 ) + 'px';
										}
									}
								}
								else {
									mensagem_sistema ();
									return;				
								}
								hideBlock ();
							}
						} 
					} 
					objHTTP.send(null);
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);					
}

/******************************************************************
* FUNCAO: 		download
* OBJETIVO:		Fazer download do arquivo
* PARAMETROS:	sequencial
* SAIDA:
*******************************************************************/
function download ( sequencial ) {
	
	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						download ( sequencial );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------		
					location.href = "/SITE/acao/download/?id=" + sequencial + "&cachebust=" + new Date().getTime();
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);						
}

/******************************************************************
* FUNCAO: 		link
* OBJETIVO:		Abrir um link
* PARAMETROS:	id - sequecial do link
*				url - link http
*				texto - texto para o estaaqui
*				alvo - 1 (interno) 0 (externo)
* SAIDA:
*******************************************************************/
function link ( id, url, texto, alvo ) {

	var objSESSAO = openAjax();
	strUrl = "/comum/biblioteca/geral/f_checar_sessao_intra.asp?cachebust=" + new Date().getTime();

	if (BrowserDetect.browser == "Explorer") objSESSAO.open("GET", strUrl, false)
	else objSESSAO.open("GET", strUrl, true);

	objSESSAO.onreadystatechange = function() { 
		if (objSESSAO.readyState == 4) {
			if (objSESSAO.status == 200) { 
				var resultado = objSESSAO.responseText;
				
				if ( resultado == "FALSE" ) {
					if ( loopSessao == 0 ) {
						link ( id, url, texto, alvo );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------
					if ( id !== null ) {
						
						showLoading ();
						
						var objHTTP = openAjax();
						strUrl = "/SITE/acao/link/?id=" + id + "&cachebust=" + new Date().getTime();
						objHTTP.open("GET", strUrl, true );
					
						objHTTP.onreadystatechange = function() { 
							if (objHTTP.readyState == 4) {
								if (objHTTP.status == 200) { 
									var resultado = objHTTP.responseText;
									resultado = resultado.replace(/\n/g,"");
									
									if ( resultado.indexOf("ERRO:") == -1 ) {
										
										conteudo = resultado.split(";");
										
										if ( conteudo[1] == 'S' ) {
											var obj = document.getElementById("centro");
											estaaqui(0, encodeURI(conteudo[2]));
											obj.innerHTML = "<iframe id='framelink' frameborder='0' class='framelink' src='" + conteudo[0] + "' ></iframe><div id='centrodireita'></div>"; 
											caixa( id );
											document.getElementById("esquerda").style.height = ( document.getElementById("centro").offsetHeight + 105 ) + 'px';
										}
										else window.open ( conteudo[0] );
										
										hideBlock ();
										
									}
									else {
										mensagem_sistema ();
										return;
									}
									hideBlock ();
								}
							} 
						} 
						objHTTP.send(null);
					}
					else if ( alvo == 0 ) window.open ( url )
					else if ( alvo == 1 ) location.href = url;
					else {
					
						showLoading ();
						var obj = document.getElementById("centro");
						
						estaaqui(0, encodeURI(texto));
						var objmenu = document.getElementById("menu_interno");
						objmenu.innerHTML = "";
						var objmenu = document.getElementById("menu_conteudo");
						objmenu.innerHTML = "";
						obj.innerHTML = "<iframe id='framelink' class='framelink' frameborder='0' src='" + url + "' ></iframe><div id='centrodireita'></div>"; 
						document.getElementById("esquerda").style.height = ( document.getElementById("centro").offsetHeight + 105 ) + 'px';
						hideBlock ();
					}
					// -----------------------------------------
				}
			}
		} 
	} 
	objSESSAO.send(null);					
}

/******************************************************************
* FUNCAO: 		marcadorTexto
* OBJETIVO:		Marcar o texto com o estilo "caneta marcador"
* PARAMETROS:	texto 			(string)
* SAIDA:		texto marcado 	(string)
*******************************************************************/
function marcadorTexto ( texto, alvo ) {
	
	var i;
	var y;
	var textoResultado  = '';
	var alvoCaixaBaixa 	= alvo.toLowerCase();
	var textoCaixaAlta 	= texto.toUpperCase();
	var tamanho 		= alvo.length;
	
	for ( i=0; i<texto.length; i++ ) {
	
		if ( 	textoCaixaAlta.substr(i,4) == '<IMG' 	|| 
				textoCaixaAlta.substr(i,2) == "<A" 		|| 
				textoCaixaAlta.substr(i,7) == "<OBJECT" ) {

					for ( y=i; y<texto.length; y++ ) {
						if ( texto.substr(y,1) == ">" ) {
							textoResultado = textoResultado + texto.substr(i,(y-i));
							i=y;
							break;
						}
					}
		}
		
		if ( texto.substr(i,tamanho).toLowerCase() == alvoCaixaBaixa ) {
			textoResultado 	= textoResultado + "<span class='marcador'>" + texto.substr(i,tamanho) + "</span>";
			i				= i+tamanho-1;
		}
		else textoResultado = textoResultado + texto.substr(i,1);
	
	}
	
	return textoResultado;
}
