var AllTitles = new Array();
var MenuArray = new Array();
var AllMenus = new Array();
var AllSubMenus = new Array();
var MenuTitle = new Array();

AllTitles[0] = new Array('Noticias', 'nt_index.html', 1);
AllTitles[1] = new Array('Bioseguridad', 'bs_index.html', 2);

// AllMenus contiene Array (texto_menu, url, seccion, n_lineas)

AllMenus[0] = new Array('Índice de bioseguridad ','bs_index.html',2,1);
AllMenus[1] = new Array('Boletines','bt_index.html',2,1);
AllMenus[2] = new Array('Rotación de Desinfectantes','bt_032.html',2,1);
AllMenus[3] = new Array('10 hechos clave sobre la influenza aviar','ar_016.html',2,2);
AllMenus[4] = new Array('Influenza aviar: Recomendaciones para su  prevención y control','ar_007.html',2,2);
AllMenus[5] = new Array('Lengua Azul: prevención y control','ar_015.html',2,1);
AllMenus[6] = new Array('Virkon S en lucha contra la gripe aviar','ar_013.html',2,1);
AllMenus[7] = new Array('Virocid contra PMWS','ar_012.html',2,1);
AllMenus[8] = new Array('Bioseguridad en granjas de avestruces','ar_011.html',2,2);
AllMenus[9] = new Array('Control de salmonella explotacines avícolas','ar_010.html',2,2);
AllMenus[10] = new Array('Desinfección en piscifactorías y acuarios','ar_006.html',2,2);
AllMenus[11] = new Array('Contra la brucelosis en vacuno','ar_005.html',2,2);
AllMenus[12] = new Array('Bioseguridad en granjas de cerdos','ar_004.html',2,2);
AllMenus[13] = new Array('Frente a la peste porcina clásica','ar_003.html',2,2);
AllMenus[14] = new Array('Virkon S, recomendado en Australia para el control de enfermedades de declaración obligatoria','ar_002.html',2,2);
AllMenus[15] = new Array('Virkon S, contra el contra el virus de la Circovirosis Porcina','ar_008.html',2,2);
AllMenus[16] = new Array('10 apuntes sobre la Peste Porcina Clásica','ar_001.html',2,2);
AllMenus[17] = new Array('Bioseguridad frente a la fiebre aftosa','ar_009.html',2,2);
AllMenus[18] = new Array('Índice de noticias','nt_index.html',1,1);
AllMenus[19] = new Array('Nueva pistola aplicadora para sebacil pour-on','nt_061_01.html',1,3);
AllMenus[20] = new Array('Baytril 10% para el tratamiento de la mastitis coliforme','nt_060_01.html',1,3);
AllMenus[21] = new Array('Nueva Web de Bayer HealthCare www.promiau.com','nt_059.html',1,3);
AllMenus[22] = new Array('Virocid y Virkon S, desinfectantes recomendados por la FAO','nt_056.html',1,3);
AllMenus[23] = new Array('Curso de parasitología on-line para auxiliares veterinarios','nt_058.html',1,3);
AllMenus[24] = new Array('Actualidad y prespectivas de la Bioseguridad en granjas','nt_054.html',1,2);
AllMenus[25] = new Array('Vetriderm: nueva imagen','nt_046.html',1,1);
AllMenus[26] = new Array('Programa de terapia asistida con animales para Animalia Tarragona','nt_045.html',1,2);
AllMenus[27] = new Array('Bayer patrocina un programa de T.A.A. junto a Fundación Bocalán','nt_044.html',1,2);
AllMenus[28] = new Array('Declaración universal de derechos del Animal','nt_034.html',1,2);


// AllSubMenus contiene todas las páginas que figuran en un submenú pero no figuran en los lista

AllSubMenus[0] = new Array('bs_index.html',2);
AllSubMenus[1] = new Array('bt_index.html','bt_001.html','bt_002.html','bt_003.html','bt_004.html','bt_005.html','bt_006.html','bt_007.html','bt_008.html','bt_009.html','bt_010.html','bt_011.html','bt_012.html','bt_013.html','bt_014.html','bt_015.html','bt_016.html','bt_017.html','bt_018.html','bt_019.html','bt_020.html','bt_021.html','bt_022.html','bt_023.html','bt_024.html','bt_025.html','bt_026.html', 'bt_027.html', 'bt_028.html', 'bt_030.html', 'bt_031.html',2);
AllSubMenus[2] = new Array('ar_016.html',  2);
AllSubMenus[3] = new Array('ar_007.html','ar_007_02.html', 'ar_007_03.html', 'ar_007_04.html', 'ar_007_05.html',  2);
AllSubMenus[4] = new Array('ar_015.html',2);
AllSubMenus[5] = new Array('ar_013.html',2);
AllSubMenus[6] = new Array('ar_012.html',2);
AllSubMenus[7] = new Array('ar_011.html','ar_011_02.html','ar_011_03.html','ar_011_04.html','ar_011_05.html','ar_011_06.html',2);
AllSubMenus[8] = new Array('ar_010.html','ar_010_02.html','ar_010_03.html','ar_010_04.html','ar_010_05.html',2);
AllSubMenus[9] = new Array('ar_006.html','ar_006_02.html','ar_006_03.html',2);
AllSubMenus[10] = new Array('ar_005.html',2);
AllSubMenus[11] = new Array('ar_004.html','ar_004_02.html','ar_004_03.html',2);
AllSubMenus[12] = new Array('ar_003.html','ar_003_02.html','ar_003_03.html','ar_003_04.html','ar_003_05.html',2);
AllSubMenus[13] = new Array('ar_002.html',2);
AllSubMenus[14] = new Array('ar_008.html',2);
AllSubMenus[15] = new Array('ar_001.html',2);
AllSubMenus[16] = new Array('ar_009.html','ar_009_02.html','ar_009_03.html','ar_009_04.html',2);
AllSubMenus[17] = new Array('nt_index.html',1);
AllSubMenus[18] = new Array('nt_061.jsp','nt_061_01.html',1);
AllSubMenus[19] = new Array('nt_057.jsp','nt_060_01.html',1);
AllSubMenus[20] = new Array('nt_058.html',1);
AllSubMenus[21] = new Array('nt_055.html',1);
AllSubMenus[22] = new Array('nt_051.html',1);
AllSubMenus[23] = new Array('nt_050.html',1);
AllSubMenus[24] = new Array('nt_047.html', 'nt_047_01.html',1);
AllSubMenus[25] = new Array('nt_045.html',1);
AllSubMenus[26] = new Array('nt_044.html',1);
AllSubMenus[27] = new Array('nt_041.html',1);
AllSubMenus[28] = new Array('nt_034.html',1);


//	Pàgina per defecte
var defaultPage = 0;
var defaultSection = 0;

// 
var thisPage = document.location;
	thisPage = '' + thisPage;
	var cut1 = thisPage.lastIndexOf('/')+1;
	var cut2 = thisPage.length + thisPage.lastIndexOf('/')+1;
	thisPage = thisPage.substr(cut1, cut2);
	
var thisSection = defaultSection;
var isSectionSet = false;
//	


// Localiza una sección y rellena el array del menú y del título de sección 
// propio de la página cuyo nombre se pasa como parámetro
function populateMenuArray(aPage)
{
	var i0 = -1;
	
	i0 = findPageItemAndSectionInAllMenus(thisPage);
	
	if(i0 < 0) //It was not in the AllMenus list
	{
		i0 = findPageItemAndSectionInAllSubMenus(thisPage);
	}

	// First, take the title from the title list	
	for(var i=0; i < AllTitles.length; i++)
	{
		if(AllTitles[i][2] == thisSection)
			MenuTitle = AllTitles[i];
	}
	
	// If no title, then take the Default section and Default Title
	if (i0 < 0)
	{
		MenuTitle = AllTitles[defaultSection];
		thisSection = defaultSection;
	}
	
	var n=0;
	
	// Then, take the menu items from the menu list
	for(var i=0; i < AllMenus.length; i++)
	{
		if(AllMenus[i][2] == thisSection)
		{
			MenuArray[n] = new Array();
			MenuArray[n][0] = AllMenus[i];
			MenuArray[n][1] = AllSubMenus[i];
			n = n + 1;
		}
	}
}

// Localiza una página en el árbol general de menús. 
// Devuelve a qué ítem corresponde y coloca en la variable thisSection a qué sección corresponde
function findPageItemAndSectionInAllMenus(aPage)
{
	var i0 = -1;
	
	for(var i=0; i < AllMenus.length; i++)
	{
		if (aPage.toUpperCase() == AllMenus[i][1].toUpperCase())
			i0 = i;
	}
	
	if(i0 >= 0)
		{
		thisSection = AllMenus[i0][2];
		isSectionSet = true;
		}
	else
		{
		thisSection = defaultSection;
		isSectionSet = false;
		}
	return i0;
}

// Localiza una página en el listado de páginas que figuran en los submenús
// Devuelve a qué ítem corresponde y coloca en la variable thisSection a qué sección corresponde
function findPageItemAndSectionInAllSubMenus(aPage)
{
	var i0 = -1;
	
	var matchAPage = aPage.toUpperCase();
	
	for(var i=0; i < AllSubMenus.length; i++)
	{
		// Cycle only until lenght-1; length contains a number
		for(var j=0; j < AllSubMenus[i].length - 1; j++)
		{
			if (matchAPage == AllSubMenus[i][j].toUpperCase())
			{
				i0 = i;
			}
		}
	}
	
	if(i0 >= 0)
		{
		thisSection = AllSubMenus[i0][AllSubMenus[i0].length - 1];
		isSectionSet = true;
		}
	else
		{
		thisSection = defaultSection;
		isSectionSet = false;
		}

	return i0;
}

// Localiza una página en un menú
// Si la página no está en el menú lo busca en el submenú y siempre 
// devuelve el ítem de menú con el que está relacionada la página

function findPageItemInMenu(aPage)
{
	var i0 = -1;
	var matchAPage = aPage.toUpperCase();
	
	for(var i=0; i < MenuArray.length/* - 1*/; i++)
	{
		// En MenuArray[i][0] está la página directamente enlazada al menú
		if (matchAPage == MenuArray[i][0][1].toUpperCase())
			i0 = i;
			
		// Si no es ésa, busca en el submenú, que es el array copiado en MenuArray[i][1]
		// Se cuenta hasta length - 1 porque el último es el número de sección y no acepta UpperCase
		if (i0 < 0)
			for(var j=0; j < MenuArray[i][1].length - 1; j++)
				{
					if(matchAPage == MenuArray[i][1][j].toUpperCase())
						i0 = i;
				}
	}

	return i0;
}

// function lineHeight(nLines)
// Calcula la altura en píxels según el número de líneas, conforme a la guía de estilo vigente
function lineHeight(nLines)
{
	return 14 * nLines + 4;
}

// function createPageMenu(aPage)
// Crea las filas de la tabla lateral con los ítems de menú y los rollovers para la página aPage (url)
function createPageMenu(aPage)
{
	var thePageItem = findPageItemInMenu(aPage);
	
	if(!isSectionSet)
			populateMenuArray(defaultSection);
	
	if(thePageItem < 0)
		thePageItem = defaultPage;
		
	var BufferStr = "";
	var rowLineHeight = 18;
	
	BufferStr = BufferStr + "\
				<tr>\
					<td onClick=\"location.href='" + MenuTitle[1]  + "';\">\
						<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\
							<tr class=\"bgLeftMenuOn\">\
								<td width=\"14\" align=\"right\" valign=\"top\"><img src=\"images/common/empty.gif\" width=\"12\" height=\"11\" border=\"0\"></td>\
								<td width=\"148\" class=\"txtNegro01\"><a href=\""  + MenuTitle[1] + "\" class=\"txtNegro01\"><b>" + MenuTitle[0] + "</b></a></td>\
							</tr>\
						</table>\
					</td>\
				</tr>\
				";
	
	for (var i=0; i < MenuArray.length; i++)
	{
		rowLineHeight = lineHeight(MenuArray[i][3]);
		if(i == thePageItem) // then apply the "selected" format 
			{
			BufferStr = BufferStr + "\
				<tr class=\"bgBlanco01\">\
					<td height=\"1\"><img src=\"images/common/empty.gif\" width=\"170\" height=\"1\" border=\"0\"></td>\
				</tr>\
				<tr>\
					<td onClick=\"location.href='" + MenuArray[i][0][1] + "';\">\
						<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\
							<tr class=\"bgLeftMenuOff\">\
								<td width=\"14\" align=\"right\" valign=\"top\" height=\""+ rowLineHeight +"\"><img src=\"images/common/common_005.gif\" width=\"12\" height=\"11\" border=\"0\" name=\"flnm" + i + "\"></td>\
								<td width=\"148\" height=\""+ rowLineHeight +"\"><a href=\"" + MenuArray[i][0][1] + "\" class=\"txtNegro01\">" + MenuArray[i][0][0] + "</a></td>\
							</tr>\
						</table>\
					</td>\
				</tr>\
				";
			}
		else // apply the "unselected" format
			{
			BufferStr = BufferStr + "\
				<tr class=\"bgBlanco01\">\
					<td height=\"1\"><img src=\"images/common/empty.gif\" width=\"170\" height=\"1\" border=\"0\"></td>\
				</tr>\
				<tr>\
					<td onClick=\"location.href='" + MenuArray[i][0][1] + "';\" onMouseOver=\"CambiaImagen(null, 'flnm" + i + "', 'fl2')\" onMouseOut=\"CambiaImagen(null, 'flnm" + i + "', 'empty')\">\
						<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\
							<tr class=\"bgLeftMenuOff\">\
								<td width=\"14\" align=\"right\" valign=\"top\" height=\""+ rowLineHeight +"\"><img src=\"images/common/empty.gif\" width=\"12\" border=\"0\" name=\"flnm"+ i +"\"></td>\
								<td width=\"148\" height=\""+ rowLineHeight +"\"><a href=\"" + MenuArray[i][0][1] + "\" class=\"txtMenuLeft\" onMouseOver=\"CambiaImagen(null, 'flnm" + i + "', 'fl2')\" onMouseOut=\"CambiaImagen(null, 'flnm" + i + "', 'empty')\">" + MenuArray[i][0][0] + "</a></td>\
							</tr>\
						</table>\
					</td>\
				</tr>\
				";
			}
	}
	return (BufferStr);
}


// AT RUNTIME: Crea el MenuArray correspondiente a la página, crea el menú y escribe el menú en la página
populateMenuArray();
var menuText = createPageMenu(thisPage);
document.writeln(menuText);
