/*
* ANP - Agencia Nacional do Petroleo, Gas Natural e Biocombustiveis
* NIN / Equipe WEB
*
* Biblioteca com as funcoes especificas do site
*/

var objDelayMenu;
var objItemMenuAtual;

/******************************************************************
* FUNCAO: 		abrirSubMenu
* OBJETIVO:		Mostrar o submenu com seus niveis
* PARAMETROS:	Sequencial da area (NUMBER)
* SAIDA:
*******************************************************************/
function abrirSubMenu ( objetoLI ) {

	var area = objetoLI.id.substr( 3, objetoLI.id.length );
	var div = document.getElementsByTagName('DIV');

	for ( var i=0; i <= div.length-1; i++ ) {
		if ( div[i].id.substr(0,4) == "div_" ) div[i].style.display = "none";
	}
	
	try {
		
		objItemMenuAtual		= document.getElementById("div_" + area );
		var objTamanho 			= objItemMenuAtual.getAttribute("altura");
		var objAltura 			= findObjectPosY( document.getElementById("li_" + area ), "esquerda");

		if (BrowserDetect.browser == "Explorer") var tamanhoJanela = document.body.clientHeight
		else var tamanhoJanela = document.body.clientHeight;

		if ( ( parseInt(objTamanho) + parseInt(objAltura) + 100 ) > tamanhoJanela ) objItemMenuAtual.style.top = ( parseInt(objAltura) - parseInt(objTamanho) + 100 ) + "px";
		else objItemMenuAtual.style.top = ( objAltura + 30 ) + "px";

		objItemMenuAtual.style.left = ( findPosX( document.getElementById("li_" + area )) + 150 ) + "px";
		objItemMenuAtual.style.display = "block";
		
		clearInterval( objDelayMenu );
		objDelayMenu = setInterval( "fecharMenu()", 5000);
		
	}
	catch (e) {};
		
}

/******************************************************************
* FUNCAO: 		fecharMenu
* OBJETIVO:		funcao para fechar o submenu automaticamente
* PARAMETROS:	
* SAIDA:
*******************************************************************/
function fecharMenu () { 
	if ( objItemMenuAtual ) objItemMenuAtual.style.display = "none"; 
	clearInterval( objDelayMenu );
}

/******************************************************************
* FUNCAO: 		fecharTodosMenus
* OBJETIVO:		funcao para fechar todos os submenus
* PARAMETROS:	
* SAIDA:
*******************************************************************/
function fecharTodosMenus () {
	var div = document.getElementsByTagName('DIV');
	for ( var i=0; i <= div.length-1; i++ ) {
		if ( div[i].id.substr(0,4) == "div_" ) div[i].style.display = "none";
	}
}

/******************************************************************
* FUNCAO: 		montarItemMenuNivel1
* OBJETIVO:		Montar o submenu se existir
* PARAMETROS:	Sequencial da area (NUMBER)
* SAIDA:
*******************************************************************/
function montarItemMenuNivel1 ( itemMenu ) {

	var objHTTP1 = openAjax();
	strUrl = "/SITE/acao/menu/submenu/principal/?id=" + itemMenu[0] + "&cachebust=" + new Date().getTime()
	objHTTP1.open("GET", strUrl, true );

	objHTTP1.onreadystatechange = function() { 
		if (objHTTP1.readyState == 4) {
			if (objHTTP1.status == 200) { 
				var resultado = objHTTP1.responseText;
				resultado = resultado.replace(/\n/g,"");
			
				if ( resultado.indexOf("ERRO:") == -1 ) {
					if ( resultado !== "" ) {

						var li_link = document.createElement('A');  
						li_link_href = document.createAttribute('href');
						li_link_href.value = "javascript:void(0);";
						li_link.setAttributeNode( li_link_href );
						li_link_title = document.createAttribute('title');
						li_link_title.value = itemMenu[2];
						li_link.setAttributeNode( li_link_title );
						li_link.innerHTML = itemMenu[1];
						document.getElementById( "li_" + itemMenu[0] ).appendChild( li_link );
						
						var conteudoSub = resultado.split(";");
						var objBody = document.getElementsByTagName("body").item(0);
						var objDIV = document.createElement('DIV');
						objDIV.style.display="none";
						
						var objDIV_classe = document.createAttribute('class');
						objDIV_classe.value = "submenu";
						objDIV.setAttributeNode( objDIV_classe );
						
						var objDIV_id = document.createAttribute('id');
						objDIV_id.value = "div_" + itemMenu[0];
						objDIV.setAttributeNode( objDIV_id );
						
						var objDIV_altura = document.createAttribute('altura');
						objDIV_altura.value = ((conteudoSub.length-1) * 22 );
						objDIV.setAttributeNode( objDIV_altura );
						
						objBody.insertBefore(objDIV, objBody.firstChild);
						
						var ulSub = document.createElement('UL');
						objDIV.appendChild( ulSub );
						
						for ( var z=0; z < conteudoSub.length-1; z++ ) {

							var itemSubMenu = conteudoSub[z].split("|");
						
							var li = document.createElement('LI');
							ulSub.appendChild( li );
							
							var li_id = document.createAttribute('id');
							li_id.value = "li_" + itemSubMenu[0];
							li.setAttributeNode( li_id );
			
							var li_link = document.createElement('A');  
							li_link_href = document.createAttribute('href');
							li_link_href.value = 'javascript:abrirPagina(' + itemSubMenu[0] + ');';
							li_link.setAttributeNode( li_link_href );
							
							li_link.innerHTML = "<B>" + itemSubMenu[1] + "</B><BR /><FONT SIZE=1>" + itemSubMenu[2] + "</FONT>";
							li.appendChild( li_link );
					
						}
						
					}
					else {
						var li_link = document.createElement('A');  
						li_link_href = document.createAttribute('href');
						li_link_href.value = "javascript:abrirPagina(" + itemMenu[0] + ",true);";
						li_link.setAttributeNode( li_link_href );
						li_link_title = document.createAttribute('title');
						li_link_title.value = itemMenu[2];
						li_link.setAttributeNode( li_link_title );
						li_link.innerHTML = itemMenu[1];
						document.getElementById( "li_" + itemMenu[0] ).appendChild( li_link );
					}
				}
				else {
					mensagem_sistema ();
					return;
				}
			}
		}
	} 
	objHTTP1.send(null);

}

/******************************************************************
* FUNCAO: 		montarItemSubMenuNivel1
* OBJETIVO:		Montar o submenu se existir
* PARAMETROS:	Sequencial da area (NUMBER)
* SAIDA:
*******************************************************************/
function montarItemSubMenuNivel1 ( itemMenu ) {
	
	var objHTTP1 = openAjax();
	strUrl = "/SITE/acao/menu/submenu/secundario/?id=" + itemMenu[0] + "&cachebust=" + new Date().getTime()
	objHTTP1.open("GET", strUrl, true );

	objHTTP1.onreadystatechange = function() { 
		if (objHTTP1.readyState == 4) {
			if (objHTTP1.status == 200) { 
				var resultado = objHTTP1.responseText;
				resultado = resultado.replace(/\n/g,"");
				
				if ( resultado.indexOf("ERRO:") == -1 ) {
					
					if ( resultado !== "" ) {
		
						var li_link = document.createElement('A');  
						li_link_href = document.createAttribute('href');
						li_link_href.value = "javascript:void(0);";
						li_link.setAttributeNode( li_link_href );
						li_link_title = document.createAttribute('title');
						li_link_title.value = itemMenu[2];
						li_link.setAttributeNode( li_link_title );
						li_link.innerHTML = itemMenu[1];
						document.getElementById( "li_" + itemMenu[0] ).appendChild( li_link );
		
						var conteudoSub = resultado.split(";");
						var objBody = document.getElementsByTagName("body").item(0);
						var objDIV = document.createElement('DIV');
						objDIV.style.display="none";
						
						var objDIV_classe = document.createAttribute('class');
						objDIV_classe.value = "submenu";
						objDIV.setAttributeNode( objDIV_classe );
						
						var objDIV_id = document.createAttribute('id');
						objDIV_id.value = "div_" + itemMenu;
						objDIV.setAttributeNode( objDIV_id );
						
						var objDIV_altura = document.createAttribute('altura');
						objDIV_altura.value = ((conteudoSub.length-1) * 22 );
						objDIV.setAttributeNode( objDIV_altura );
						
						objBody.insertBefore(objDIV, objBody.firstChild);
						
						var ulSub = document.createElement('UL');
						objDIV.appendChild( ulSub );
						
						for ( var z=0; z < conteudoSub.length-1; z++ ) {

							var itemSubMenu = conteudoSub[z].split("|");
						
							var li = document.createElement('LI');
							ulSub.appendChild( li );
							
							var li_id = document.createAttribute('id');
							li_id.value = "li_" + itemSubMenu[0];
							li.setAttributeNode( li_id );
			
							var li_link = document.createElement('A');  
							li_link_href = document.createAttribute('href');
							li_link_href.value = 'javascript:abrirPagina(' + itemSubMenu[0] + ');';
							li_link.setAttributeNode( li_link_href );
							
							li_link.innerHTML = "<B>" + itemSubMenu[1] + "</B><BR /><FONT SIZE=1>" + itemSubMenu[2] + "</FONT>";
							li.appendChild( li_link );
					
						}
						
					}
					else {
						var li_link = document.createElement('A');  
						li_link_href = document.createAttribute('href');
						li_link_href.value = "javascript:abrirPagina(" + itemMenu[0] + ",true);";
						li_link.setAttributeNode( li_link_href );
						li_link_title = document.createAttribute('title');
						li_link_title.value = itemMenu[2];
						li_link.setAttributeNode( li_link_title );
						li_link.innerHTML = itemMenu[1];
						document.getElementById( "li_" + itemMenu[0] ).appendChild( li_link );
					}
				}
				else {
					mensagem_sistema ();
					return;
				}
			}
		}
	} 
	objHTTP1.send(null);
}

/******************************************************************
* 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 == "" ) obj.innerHTML = html_temp
									else {
										
										obj.innerHTML = "<ul></ul>";
																	
										var ul = obj.getElementsByTagName('UL');
										while (ul[0].childNodes[0]) {
											ul[0].removeChild(ul[0].childNodes[0]);
										}
										
										var conteudo = resultado.split(";");
										
										for ( var i=0; i < conteudo.length-1; i++ ) {

											var itemMenu = conteudo[i].split("|");
											var li = document.createElement('LI');
											ul[0].appendChild( li );
												
											if ( itemMenu[3] == "N" ) {
												var li_classe = document.createAttribute("class");
												li_classe.value = "menu_off";
												li.setAttributeNode( li_classe );
											}
											else {
												var li_classe = document.createAttribute("class");
												li_classe.value = "menu_selecionado";

												li.setAttributeNode( li_classe );
											}

											li.onmouseover = function() { abrirSubMenu( this ) };

											var li_id = document.createAttribute("id");
											li_id.value = "li_" + itemMenu[0];
											li.setAttributeNode( li_id );

											montarItemMenuNivel1 ( itemMenu );
											
										}
									}
									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,"");

								if ( resultado.indexOf("ERRO:") == -1 ) {
									if ( resultado == "@0" || resultado == "@1" ) subpagina ( id )
									else {
										
										var conteudo = resultado.split("@");
										if ( conteudo[1] == "0" ) guia ( id );
										
										var cabecalho = conteudo[0].split("||");
										obj.innerHTML = cabecalho[0] + "<ul></ul>";
										
										var ul = obj.getElementsByTagName('UL');
										while (ul[0].childNodes[0]) {
											ul[0].removeChild(ul[0].childNodes[0]);
										}
										
										var conteudo = cabecalho[1].split(";");
										
										for ( var i=0; i < conteudo.length-1; i++ ) {

											var itemMenu = conteudo[i].split("|");

											var li = document.createElement('LI');
											ul[0].appendChild( li );

											if ( itemMenu[3] == "N" ) {
												var li_classe = document.createAttribute("class");
												li_classe.value = "menu_off";
												li.setAttributeNode( li_classe );
											}
											else {
												var li_classe = document.createAttribute("class");
												li_classe.value = "menu_selecionado";
												li.setAttributeNode( li_classe );
											}

											li.onmouseover = function() { abrirSubMenu( this ) };

											var li_id = document.createAttribute("id");
											li_id.value = "li_" + itemMenu[0];
											li.setAttributeNode( li_id );

											montarItemSubMenuNivel1 ( itemMenu );

										}
										
										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 );
										var cabecalho = resultado.split("||");
										obj.innerHTML = cabecalho[0] + "<ul></ul>";
										
										var ul = obj.getElementsByTagName('UL');
										while (ul[0].childNodes[0]) {
											ul[0].removeChild(ul[0].childNodes[0]);
										}
										
										var conteudo = cabecalho[1].split(";");
										
										for ( var i=0; i < conteudo.length-1; i++ ) {
	
											var itemMenu = conteudo[i].split("|");
											var li = document.createElement('LI');
											ul[0].appendChild( li );
												
											if ( itemMenu[3] == "N" ) {
												var li_classe = document.createAttribute("class");
												li_classe.value = "menu_off";
												li.setAttributeNode( li_classe );
											}
											else {
												var li_classe = document.createAttribute("class");
												li_classe.value = "menu_selecionado";
												li.setAttributeNode( li_classe );
											}
	
											li.onmouseover = function() { abrirSubMenu( this ) };
	
											var li_id = document.createAttribute("id");
											li_id.value = "li_" + itemMenu[0];
											li.setAttributeNode( li_id );
	
											montarItemSubMenuNivel1 ( itemMenu )
										}
										
										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 ) {
									
									var ul = obj.getElementsByTagName('UL');
									while (ul[0].childNodes[0]) {
										ul[0].removeChild(ul[0].childNodes[0]);
									}
									
									var conteudo = resultado.split(";");
									
									for ( var i=0; i < conteudo.length-1; i++ ) {

										var itemMenu = conteudo[i].split("|");
										var li = document.createElement('LI');
										ul[0].appendChild( li );
											
										if ( itemMenu[3] == "N" ) {
											var li_classe = document.createAttribute("class");
											li_classe.value = "menu_off";
											li.setAttributeNode( li_classe );
										}
										else {
											var li_classe = document.createAttribute("class");
											li_classe.value = "menu_selecionado";
											li.setAttributeNode( li_classe );
										}

										li.onmouseover = function() { abrirSubMenu( this ) };

										var li_id = document.createAttribute("id");
										li_id.value = "li_" + itemMenu[0];
										li.setAttributeNode( li_id );

										montarItemMenuNivel1 ( itemMenu );
									}
									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("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 ) {
						estaaqui ( id, encodeURI(texto) );
						loopSessao = 1;
					}
				}
				else {
					
					loopSessao = 0;
					// -----------------------------------------
					showLoading ();
					var caminho = document.getElementById("estaaqui");
										
					var objHTTP = openAjax();
					strUrl = "/SITE/acao/estaaqui/?id=" + id + "&s1=" + texto + "&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: 		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-300) + "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';

									}
									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 + 188 );
											
									if ( document.getElementById("centro").offsetHeight > tamanho ) {
										var obj = document.getElementById("esquerda");
										obj.style.height = ( document.getElementById("centro").offsetHeight + 310 ) + 'px';
									}
									else {
										var obj = document.getElementById("esquerda");
										obj.style.height = ( tamanho + 310 ) + '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("REDIRECIONAR:") !== -1 ) {
									location.href = "/";
									return;
								}
								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 + 338 );
																				obj.style.height = tamanho + 'px';
																				var obj = document.getElementById("esquerda");
																				obj.style.height = ( tamanho + 338 ) + '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' ) {
											
											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";
											obj.style.marginBottom = "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 + 188 );
												
												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 + 310 ) + '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";
										obj.style.display = "none";
										
										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 + 310 ) + '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 + 310 ) + '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 + 310 ) + '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;
}
