/*------------------------------------------------------------------- 
Author's Statement:
This script is based on ideas of the author.
You may copy, modify and use it for any purpose. The only condition is that if you publish web pages that use this script you point to its author at a suitable place and don't remove this Statement from it.
It's your responsibility to handle possible bugs even if you didn't modify anything. I cannot promise any support.
Dieter Bungers
GMD (www.gmd.de) and infovation (www.infovation.de)

Alterado por Miguel NunesA (SNIRH)
.Agora, a página gerada é uma página web mais simples
.Ligação a vários ficheiros de configuração
.toc é o nome da frame a actualizar
.Adicionado suporte para target frame
.Adicionada possibilidade de adicionar imagens no topo da página (para destaques)
--------------------------------------------------------------------*/
if (navigator.appName.toLowerCase().indexOf("explorer") > -1) {
	var mdi=textSizes[1], sml=textSizes[2];
} else {
	var mdi=textSizes[3], sml=textSizes[4];
}

function reDisplay(currentNumber,currentIsExpanded,objlinkbool) {

	main_leg.document.open();
	main_leg.document.write("<html>\n<head>\n<title>SNIRH - Navegação Principal");
	main_leg.document.write("</title>\n"); 
	main_leg.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
	main_leg.document.write("<link href=\"/snirh/scripts/nav2005/menu.css\" rel=\"stylesheet\" type=\"text/css\" />");
	/*main_leg.document.write("<script language=\"JavaScript\" src=\"/snirh/scripts/funcoes.js\"></script>");*/

	// Escreve na página o ID do item activo
	main_leg.document.write("<script>");
	main_leg.document.write("		var pagina_item ='" + currentNumber + "'; ");
	main_leg.document.write("		var pagina_main_id ='" + snirh_gid + "'; ");
	main_leg.document.write("</script>");

	main_leg.document.write("<script>\n");		
	main_leg.document.write("		function AbreContacto() { ");
	main_leg.document.write("		    window.open('http://intranet.snirh.pt/snirh/mailservice/contacto.php','contacto','width=615,height=515,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0');");
	main_leg.document.write("		};\n");
	
	main_leg.document.write("	function AbreMapa(lang) { ");
	main_leg.document.write("	if (lang == 'portugues') { ");
	main_leg.document.write("		caminho =  '/snirh/_navegacao/site_map/mapa_pt.php'; ");
	main_leg.document.write("	} else { ");
	main_leg.document.write("		caminho =  '/snirh/_navegacao/site_map/mapa_eng.php'; ");
	main_leg.document.write("	} ");
	main_leg.document.write("	window.open(caminho, '001122', 'width=740,height=500,scrollbars=1'); ");
	main_leg.document.write("}; ");
	
	main_leg.document.write("	function menuSNIRH(oque) { ");		
	main_leg.document.write("		if (navigator.appName == \"Microsoft Internet Explorer\") {");		
	main_leg.document.write("	        document.all.menu.style.visibility = oque; ");		
	main_leg.document.write("	    } else { ");		
	main_leg.document.write("			document.getElementById(\"menu\").style.visibility = oque;");		
	main_leg.document.write("    	}");		
	main_leg.document.write("	};\n");		

	main_leg.document.write("	function navegacao(lang,arg) { ");
	main_leg.document.write("		top.location='/snirh.php?main_id='+arg+'&idioma='+lang ");
	main_leg.document.write(" } ; \n");

	main_leg.document.write("	function MudaIdioma(lang) { ");
	main_leg.document.write("		top.location = '/snirh.php?main_id=' + this.pagina_main_id +'&item=' + this.pagina_item + '&idioma=' +  lang;");
	main_leg.document.write(" };\n ");

	main_leg.document.write("	function AdicionaMySNIRH() { ");
	main_leg.document.write("		var app_url = escape(top.main_apr.location);");
	//main_leg.document.write("		alert(top.main_apr.document.title);");
	main_leg.document.write("		var app_url_title = escape(top.main_apr.document.title);");
	main_leg.document.write("		var item = this.pagina_item; ");
	main_leg.document.write("		var main_id = this.pagina_main_id; ");
	main_leg.document.write("		var snirhURL_id = '0.' + main_id + '.' + item; ");

	main_leg.document.write("	adicionar_txt = new String('Pretende adicionar esta página ao SNIRH-me?\\n\\nO SNIRH-me permite-lhe guardar até 10 páginas do SNIRH.'); ");	
	main_leg.document.write("	adicionar = confirm(adicionar_txt,''); ");
	main_leg.document.write("	var adicionar_ = 0; ");
	main_leg.document.write("	if (adicionar == true) { var adicionar_ = 1; }; ");
	main_leg.document.write("		window.open('/popup_gestaoMySNIRH.php?appurl='+app_url+'&app_url_title='+app_url_title+'&snirhURL_id='+snirhURL_id+'&adicionar_='+adicionar_,'SNIRHmeGestao','width=500,height=300,toolbar=0,menubar=0,status=1,scrollbars=0,resizable=0') ");
	main_leg.document.write(" };\n ");

//



	main_leg.document.write("</script>\n");		

	main_leg.document.write("</head>\n<body leftmargin=\"0\" topmargin=\"0\"  background=\"/snirh/navegacao/imagens/bg_" + tema + ".gif\" bgcolor=" + backColor + ">\n<table border=0 cellspacing=1 cellpadding=0>\n<tr>");
	main_leg.document.write("<img src=\"/snirh/_level0/imagens/bt_snirh_toolbox" + str_snirhtool_img + ".png\" border=\"0\" usemap=\"#ligacoes\">");	
	main_leg.document.write("<a href=\"javascript:parent.reDisplay('0',true);\" target=\"main_apr\"><img border=\"0\" src=\"/snirh/_navegacao/seccoes/bt_" + tema + "_topo.png\" style=\"cursor:hand\" alt=\"voltar ao início\"></a>");
	//main_leg.document.write("<a href=\""+tocTab[0][2]+"\" target=\"main_apr\"><img border=\"0\" src=\"/snirh/navegacao/seccoes/bt_" + tema + "2.png\" style=\"cursor:hand\" alt=\"voltar ao início\"></a>");
	main_leg.document.write("<br>");
	
	// Apresenta os destaques no topo do BARMENU
	for (i=0; i<tocDestaques.length; i++) {
		main_leg.document.write("<center>");
		main_leg.document.write("<a href=\""+ tocDestaques[i][1] +"\" target=\""+ tocDestaques[i][2] +"\"><img src=\""+ tocDestaques[i][0] +"\" border=\"0\" alt=\""+ tocDestaques[i][3] +"\"></a></center>");		
	}

	var currentNumArray = currentNumber.split(".");
	var currentLevel = currentNumArray.length-1;
	var scrollY=0, addScroll=true, theHref="";

	for (i=0; i<tocTab.length; i++) { // Alterei i=0 para ignorar o titulo do ToC
		
		thisNumber = tocTab[i][0];
		
		if(!thisNumber) {
			//alert(thisNumber);
			continue;
		}
		
		var isCurrentNumber = (thisNumber == currentNumber);
		if (isCurrentNumber) theHref=tocTab[i][2];
		if (isCurrentNumber) target=tocTab[i][3]; //Adicionado suporte para target frame
		var thisNumArray = thisNumber.split(".");
		var thisLevel = thisNumArray.length-1;
		var toDisplay = true;
		
		if (thisLevel > 0) {
			for (j=0; j<thisLevel; j++) {
				toDisplay = (j>currentLevel)?false:toDisplay && (thisNumArray[j] == currentNumArray[j]);
			}
		}
		thisIsExpanded = toDisplay && (thisNumArray[thisLevel] == currentNumArray[thisLevel])
		if (currentIsExpanded) {
			toDisplay = toDisplay && (thisLevel<=currentLevel);
			if (isCurrentNumber) thisIsExpanded = false;
		}
		
		if (toDisplay) {
			//if (i==0) {
			//theHref = ""; //Impede de refazer a página ao iniciar
			/*
				main_leg.document.writeln("\n<td colspan=" + (nCols+1) + "><a href=\"javaScript:parent.reDisplay('" + thisNumber + "'," + thisIsExpanded + ")\" style=\"font-family: " + fontTitle + "; font-weight:bold; font-size:" + textSizes[0] + "em; color: " + titleColor + "; text-decoration:none\">" + tocTab[i][1] + "</a></td></tr>");
				for (k=0; k<nCols; k++) {
					main_leg.document.write("<td>&nbsp;</td>");
				}
				main_leg.document.write("<td width=240>&nbsp;</td></tr>");
			*/
			//} else if((thisNumber % 1) == 0) {
			//} else {
				//main_leg.document.writeln(thisNumber);
				if (addScroll) scrollY+=((thisLevel<2)?mdi:sml)*25;
				if (isCurrentNumber) addScroll=false;
				var isLeaf = (i==tocTab.length-1) || (thisLevel >= tocTab[i+1][0].split(".").length-1);
				img = (isLeaf)?"leaf":(thisIsExpanded)?"minus":"plus";
				main_leg.document.writeln("<tr>");
				for (k=1; k<=thisLevel; k++) {
					main_leg.document.writeln("<td>&nbsp;</td>");
				}
				
				//if(thisNumber.indexOf(".") == -1) {
				//	main_leg.document.writeln("<td valign=top><a href=\"javaScript:parent.reDisplay('" + thisNumber + "'," + thisIsExpanded + ");\"><img src=\"/snirh/scripts/nav/images/" + img + ".gif\" width=13 height=12 border=0></a></td> <td colspan=" + (nCols-thisLevel) + " bgcolor='#ffffff'><a href=\"javaScript:parent.reDisplay('" + thisNumber + "'," + thisIsExpanded + ")\" style=\"font-family: " + fontLines + ";" + ((thisLevel<=mLevel)?"font-weight:bold":"") +  "; font-size:" + ((thisLevel<=mLevel)?mdi:sml) + "em; color: " + ((isCurrentNumber)?currentColor:normalColor) + "; text-decoration:none\" title=\""+ tocTab[i][1] +"\">" + ((showNumbers)?(thisNumber+" "):"") + tocTab[i][1] + "</a></td></tr>");
				//} else {
				if (i > 0) {
					main_leg.document.writeln("<td valign=top><a href=\"javaScript:parent.reDisplay('" + thisNumber + "'," + thisIsExpanded + ");\"><img src=\"/snirh/scripts/nav/images/" + img + ".gif\" width=13 height=12 border=0></a></td> <td colspan=" + (nCols-thisLevel) + "><a href=\"javaScript:parent.reDisplay('" + thisNumber + "'," + thisIsExpanded + ")\" style=\"font-family: " + fontLines + ";" + ((thisLevel<=mLevel)?"font-weight:bold":"") +  "; font-size:" + ((thisLevel<=mLevel)?mdi:sml) + "em; color: " + ((isCurrentNumber)?currentColor:normalColor) + "\";  title=\""+ tocTab[i][1] +"\" class=\"menuSNIRH\">" + tocTab[i][1] + "</a></td></tr>\n");
				}
				//}
				
			//}
		}
	}
	
	if (tema == "base") { //Pesquisa de estações
		main_leg.document.write("<tr><td height=20></td></tr>");
		main_leg.document.write("<form name=goProcurar action=\"/snirh/dados_base/pesquisa_estacoes/pesquisador.php?accao=go\" method=\"post\" target=\"main_apr\">");
		main_leg.document.write("<tr><td colspan="+ (nCols+1) +" valign=center background=/snirh/dados_base/pesquisa_estacoes/img/bck.gif height=10>");
		main_leg.document.write("<font color=#ffffff face=Verdana, Arial, Helvetica, sans-serif size=2><strong>&nbsp;&nbsp;Procurar Estações<br></strong></font>");		
		main_leg.document.write("<input name=\"form_estacaomenu\" type=\"text\" style=\"border:1px solid #3faaff; background-color:#ffffff; width=9.4em; height=0,5em;\">");
		main_leg.document.write("<input type=\"submit\" name=\"Submit\" value=\"OK\" onClick=\"document.goProcurar.submit()\" style=\"border:0px solid #3faaff; color:#ffffff; background-color:#3faaff; height=0,5em; cursor:hand\"><br>");		
		main_leg.document.write("<input type=\"hidden\" name=\"tipo_entrada\" value=\"0\">");
		//main_leg.document.write("<font color=#071D8D face=Arial, Helvetica, sans-serif size=1>");
		//main_leg.document.write("<input type=\"radio\" name=\"tipo_entrada\" value=\"1\">Nome");
		//main_leg.document.write("<input type=\"radio\" name=\"tipo_entrada\" value=\"2\">Código");
		//main_leg.document.write("<input type=\"radio\" name=\"tipo_entrada\" value=\"0\" checked>Geral");
		///main_leg.document.write("</font>");				
		main_leg.document.write("</td></tr>");
		main_leg.document.write("<tr><td colspan=10 align=right>");
		//main_leg.document.write("<a href=\"/snirh/dados_base/pesquisa_estacoes/pesquisa_estacoes_v2.php\" target=\"main_apr\" style=\"text-decoration: underline;\"><font color=#9CCFFF face=Verdana, Arial, Helvetica, sans-serif size=1><strong>Configurar opções de pesquisa<strong></font></a>");
		main_leg.document.write("<a href=\"/snirh/dados_base/pesquisa_estacoes/pesquisador.php\" target=\"main_apr\" style=\"text-decoration: underline;\"><font color=#9CCFFF face=Verdana, Arial, Helvetica, sans-serif size=1><strong>Configurar opções de pesquisa<strong></font></a>");
		main_leg.document.write("</td></tr>");				
		main_leg.document.write("</form>");
	};
	
	main_leg.document.writeln("</table>\n");

	main_leg.document.write("<map name=\"ligacoes\">");
	
	main_leg.document.write("<area shape=\"rect\" coords=\"0,1,74,30\" href=\"/index.php?idioma="+str_lang+"\" target=\"_top\" alt=\""+ str_home_language +"\">");
	main_leg.document.write("<area shape=\"rect\" coords=\"77,0,102,15\" href=\"javascript:MudaIdioma('" +  str_old_language + "')\" alt=\""+ str_chng_language +"\">");
	main_leg.document.write("<area shape=\"rect\" coords=\"120,0,150,35\" href=\"javascript:AbreContacto('" +  str_actual_language + "')\" target=\"_self\" alt=\""+ str_mail_language +"\">");
	main_leg.document.write("<area shape=\"rect\" coords=\"103,0,120,15\" href=\"javascript:AbreMapa('" +  str_actual_language + "')\" target=\"_self\" alt=\""+ str_help_language +"\">");
	main_leg.document.write("<area shape=\"rect\" coords=\"77,15,120,30\" href=\"javascript:AdicionaMySNIRH()\" alt=\"Adicionar esta página ao SNIRH-me\">");
	main_leg.document.write("</map>");
	
	// LINKS PARA OUTRAS SECÇÕES
	if (tema != "sintese") {
		main_leg.document.write("<a href='/snirh.php?main_id=1' target='_top'><img style='margin-top:2px' border='0' src=/snirh/_navegacao/seccoes/bt_sintese2.png></a>");
	}
	if (tema != "base") {
		main_leg.document.write("<a href='/snirh.php?main_id=2' target='_top'><img style='margin-top:2px' border='0' src=/snirh/_navegacao/seccoes/bt_base2.png></a>");
	}
	if (tema != "estudosproj") {
		main_leg.document.write("<a href='/snirh.php?main_id=3' target='_top'><img style='margin-top:2px' border='0' src=/snirh/_navegacao/seccoes/bt_estudosproj2.png></a>");
	}
	if (tema != "atlasagua") {
		main_leg.document.write("<a href='/snirh.php?main_id=4' target='_top'><img style='margin-top:2px' border='0' src=/snirh/_navegacao/seccoes/bt_atlasagua2.png></a>");
	}
	if (tema != "divulgacao") {
		main_leg.document.write("<a href='/snirh.php?main_id=5' target='_top'><img style='margin-top:2px' border='0' src=/snirh/_navegacao/seccoes/bt_divulgacao2.png></a>");
	}
	if (tema != "relacoesinternacionais") {
		main_leg.document.write("<a href='/snirh.php?main_id=6' target='_top'><img style='margin-top:2px' border='0' src=/snirh/_navegacao/seccoes/bt_relacoesinternacionais2.png></a>");
	}
	
	// \LINKS PARA OUTRAS SECÇÕES
	/*
	if (tema == "base") { //Pesquisa de estações
		main_leg.document.write("<br /> ");
		main_leg.document.write("<br /> ");
		main_leg.document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='150' height='300'> ");
		main_leg.document.write("  <param name='movie' value='/snirh/dados_base/site/flash/oqueachadositebase.swf'> ");
		main_leg.document.write("  <param name='quality' value='high'> ");
		main_leg.document.write("  <param name='wmode' value='transparent'> ");
		main_leg.document.write("  <param name='menu' value='false'> ");
		main_leg.document.write("  <embed src='/snirh/dados_base/site/flash/oqueachadositebase.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='150' height='300'></embed> ");
		main_leg.document.write("</object> ");
	}
	*/
		main_leg.document.writeln("</body>");
		main_leg.document.close();
		main_leg.scroll(0,scrollY);
		
	if ((theHref != "") && (target != "_blank") && (target != "tudo") && (!objlinkbool)) {
		parent.main_apr.location.href = theHref;
	} else	if ((theHref != "") && (target == "_blank")) {
		window.open(theHref);
	} else	if ((theHref != "") && (target == "tudo")) {
		top.location=theHref;
	}
}