// FUNCIONES COMUNES
function replace(string, text, by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}
function corrigeUrl(url) {
// Incorpora el target a la URL
	if (target == "b") {
		nameurl = url + '" target=_blank';
	} else {
		nameurl = url + '"';
	}
	return nameurl;
}
function escriuMenus(seccion, area, tema){
var lstSecciones = "S¬El Club¬Club.html¬Club¬0¬logo_MASTBAL.jpg#+#A¬Salutación¬ClubSaludo.html¬Club&&&Saludo¬0#+#A¬Palmarés¬documentos/Palmares.pdf¬Club&&&Palmarés¬0#+#A¬Equipo Directivo¬ClubJunta.html¬Club&&&Junta¬0#+#A¬Nadadores¬ClubNadadores.html¬Club&&&Nadadores¬0#+#T¬Top 10¬ClubTop10.html¬Club&&&Nadadores&&&TopTen¬1#+#A¬Reglamento¬ClubReglamento.html¬Club&&&Reglamento¬0#+#A¬Memorias¬ClubMemorias.html¬Club&&&Memorias¬0#+#A¬Filosofía Master¬ClubFilosofia.html¬Club&&&Filosofia¬0#+#T¬Decálogo Máster¬ClubFilosofiaDecalogo.html¬Club&&&Filosofia&&&Decalogo¬0#+#S¬Noticias¬Noticias.php¬Noticias¬0¬ico_noticias.jpg#+#A¬Club¬NoticiasClub.php¬Noticias&&&Club¬0#+#A¬Autonomicas¬NoticiasAutonomicas.php¬Noticias&&&Autonomicas¬0#+#A¬Nacionales¬NoticiasNacionales.php¬Noticias&&&Nacionales¬0#+#A¬Internacionales¬NoticiasInternacionales.php¬Noticias&&&Internacionales¬0#+#S¬Competiciones¬Competiciones.html¬Competiciones¬0¬ico_compet.jpg#+#A¬Calendarios¬CompeticionesCalendarios.html¬Competiciones&&&Calendarios¬0#+#T¬Autonómico¬CompeticionesCalendariosAut.html¬Competiciones&&&Calendarios&&&Autonomico¬0#+#T¬Nacional¬CompeticionesCalendariosNac.html¬Competiciones&&&Calendarios&&&Nacional¬0#+#T¬Internacional¬CompeticionesCalendariosInt.html¬Competiciones&&&Calendarios&&&Internacional¬0#+#A¬Listados de Inscritos¬CompeticionesInscritos.html¬Competiciones&&&Inscritos¬0#+#A¬Resultados¬CompeticionesResultados.html¬Competiciones&&&Resultados¬0#+#A¬Normativas¬CompeticionesNormativas.html¬Competiciones&&&Normativas¬0#+#A¬Récords¬Records.html¬Competiciones&&&Records¬0¬ico_records.gif#+#A¬Rankings¬Rankings.html¬Competiciones&&&Rankings¬0¬ico_rankings.jpg#+#T¬Club¬RankingsClub.html¬Competiciones&&&Rankings&&&Club¬0#+#T¬Autonómico¬RankingsAuton.html¬Competiciones&&&Rankings&&&Autonomico¬0#+#T¬Top Ten España¬TopTenEspanya.html¬Competiciones&&&Rankings&&&TopTenEspanya¬0#+#T¬Top Ten Mundial¬TopTenMundial.html¬Competiciones&&&Rankings&&&TopTenMundial¬0#+#S¬Entrenamientos¬Entrenador.html¬Entrenador¬0¬ico_entrenador.gif#+#A¬Planificación temporada¬EntrenadorPlanif.html¬Entrenador&&&Planif¬0#+#A¬Entrenamientos planificados¬EntrenadorEntrenos.php¬Entrenador&&&Entrenos¬0#+#A¬Consejos de cara a la competición¬EntrenadorConsejos.html¬Entrenador&&&Consejos¬0#+#A¬Documentacion¬EntrenadorDocum.html¬Entrenador&&&Docum¬0#+#T¬Artículos técnicos¬EntrenadorArticulos.html¬Entrenador&&&Docum&&&Articulos¬1#+#S¬Enlaces¬Links.html¬Enlaces¬0¬ico_enlaces.jpg#+#A¬Federaciones¬LinksFederaciones.html¬Enlaces&&&Federaciones¬0#+#A¬Clubes¬LinksClubes.html¬Enlaces&&&Clubes¬0#+#A¬Foros y Comunidades¬LinksForos.html¬Enlaces&&&Foros¬0#+#A¬Otros¬LinksOtros.html¬Enlaces&&&Otros¬0#+#S¬Zona de Ocio¬Ocio.html¬Ocio¬0¬ico_ocio.jpg#+#A¬Agenda¬OcioAgenda.php¬Ocio&&&Agenda¬0#+#A¬Comunidad MSN¬http://groups.msn.com/mastbal¬Ocio&&&Comunidad¬0¬¬b#+#A¬Revista MASTBALMANIA¬http://www.geocities.com/mastbalmania/index.html¬Ocio&&&Revista¬0¬¬b#+#A¬Es Racó d'en Gomila¬OcioRacoGomila.html¬Ocio&&&RacoGomila¬0#+#T¬Gloses¬OcioRacoGloses.html¬Ocio&&&RacoGomila&&&Gloses¬0#+#T¬Dites¬OcioRacoDites.html¬Ocio&&&RacoGomila&&&Dites¬0#+#A¬Deu anys en Acció¬OcioDeuAnys.html¬Ocio&&&DeuAnys¬0#+#A¬Liga Mastbolera¬OcioLigaMastbolera.html¬Ocio&&&LigaMastbolera¬0#+#S¬Extras¬Extras.html¬Extras¬0¬ico_extra.jpg#+#A¬Descargas¬Descargas.html¬Extras&&&Descargas¬0¬ico_descargas.jpg#+#A¬Utilidades¬Utilidades.html¬Extras&&&Utilidades¬1¬ico_utils.jpg#+#A¬Administración Web¬http://www.mallorcaweb.net/mastbal/admin/index.php¬Extras&&&Admin¬0¬¬b";
	var escribePunts = false;
	var categEncontradaSec = false;
	var categEncontradaArea = false;
	var categEncontradoTema = false;
	var seccionActual = "";
	var areaActual = "";
	var esMenuPrincipal = (seccion=="");
	var numArea = 0;
	document.writeln('<table border="0" align="left" cellpadding="0" cellspacing="0" style="">')
	if (lstSecciones=="") {
		document.writeln('</table>')
		return;
	}
	nSecciones =lstSecciones.split ( "#+#" );
	for ( i = 0 ; i < nSecciones.length ; i++ ) {
		nSeccion 				= nSecciones[i].split('¬');
		tipoSeccion 			= nSeccion[0];		// Puede ser S o S+ (sección); A (area); T (tema)
		nameSeccion 			= nSeccion[1];		// El nombre que se muestra
		urlSeccion				= nSeccion[2];		// La url por defecto del elemento
		nomCategoriaComp 	= nSeccion[3].split("&&&");
		// El identificador del elemento seccion&&&area&&&tema (en catalán)
		nomSeccion 	= nomCategoriaComp[0];
		nomArea 			= nomCategoriaComp[1];
		nomTema 			= nomCategoriaComp[2];
		esNuevo 			= nSeccion[4];
		target                          = nSeccion[6];
		// categoria => 1; otras => 0
		if ((tipoSeccion == "S") || (tipoSeccion == "S+")) {
			if (escribePunts){
				if (! esMenuPrincipal) {
					document.writeln('<tr><td align="left"></td>')
					document.writeln('<td colspan="2" align="left" nowrap>')
					document.writeln('<font size="1">···</font></td></tr>')
				} else {
					if ( numArea>0 ) {
						document.writeln(', ...')
					} else {
						document.writeln('...')
					}
				}
			}
			if (i != 0){
				if (esMenuPrincipal) {
					document.writeln('</font></td></tr>')
				} 
				document.writeln('<tr><td colspan="3" height="3"></td></tr>') 	// Espacio entre secciones
			}
			numArea = 0;
			categEncontradaSec =  (nomSeccion == seccion);
			seccionActual = nomSeccion;
			if(categEncontradaSec && area==""){
				document.writeln('<tr><td><img src="archivos/ico.gif" width="22" height="16"></td>')
				document.write('<td colspan="2" nowrap class="menu_selec"><strong><a href="')
			} else {
				document.writeln('<tr><td><img src="archivos/ico.gif" width="22" height="16"></td>')
				document.write('<td colspan="2" nowrap class="menu_opcion"><strong><a href="')
			}			
			document.write(corrigeUrl(urlSeccion))
			document.write( ' class="menu_opcion">')
			document.writeln(nameSeccion + '</a></strong></td></tr>')
			if (esMenuPrincipal) {
				document.writeln('<tr><td></td>')
				document.write('<td colspan="2"><font size="1">')
			}
			escribePunts = (tipoSeccion == "S+");
		}
		else if (tipoSeccion == "A"){
			categEncontradaArea = ((area !="") && (area == nomArea));
			areaActual = nomArea;
			
			numArea++;
			if (((seccion =="") || (categEncontradaSec)) && (nomSeccion==seccionActual) ){
				if (! esMenuPrincipal) {
					document.write('<tr><td align="right">')
					if ( esNuevo == '1' ) {
						document.write('<img src="archivos/nuevo.gif">')
					}
					document.writeln('</td>')
					document.write('<td colspan="2"  nowrap>')
					document.writeln('<font size="2">')
				} else {
					if ( numArea > 1 ) {
						document.writeln(', ')
					}
				}
				document.write('<a href="')
				document.write(corrigeUrl(urlSeccion))
				if ((categEncontradaArea) && (tema=="")) {
					if ( esNuevo == '1' ) {
						document.write(' class="menu_opcion_selec_new">')
					} else if ( esNuevo == 'B' ) {
						document.write(' class="menu_opcion_selec_beta">');
						nameSeccion = nameSeccion + " (BETA)";
					} else {
						document.write(' class="menu_opcion_selec">')
					}
				} else {
					if ( esNuevo == '1' ) {
						document.write(' class="menu_opcion_new">')
					} else if ( esNuevo == 'B' ) {
						document.write(' class="menu_opcion_beta">');
						nameSeccion = nameSeccion + " (BETA)";
					} else {
						document.write(' class="menu_opcion">')
					}
				}
				document.write(replace(nameSeccion, ' ', '&nbsp;') + '</a>')
				if (! esMenuPrincipal ) {
					document.writeln('</font></td></tr>')
				}
			}
		}
		else if (tipoSeccion == "T") {
			if (((seccion != "") && (categEncontradaSec ))&& (nomSeccion==seccionActual) && (nomArea==areaActual)) {
				categEncontradoTema = ((tema !="") && (categEncontradaArea) && (tema == nomTema));
				document.write('<tr><td align="right">')
				if ( esNuevo == '1' ) {
					document.write('<img src="archivos/nuevo.gif"" />')
				}
				document.writeln('</td>')
				document.writeln('<td width="10%"><img src="/images.nsf/codo.gif" width="14" height="6" alt="codo" /></td>')
				document.write('<td align="left" nowrap>')
				document.writeln('<font size="1">')
				document.write('<a href="')
				document.write(corrigeUrl(urlSeccion))
				if (categEncontradoTema)
					if ( esNuevo == '1' ) {
						document.write(' class="menu_opcion_selec_new">')
					} else if ( esNuevo == 'B' ) {
						document.write(' class="menu_opcion_selec_beta">');
						nameSeccion = nameSeccion + " (BETA)";
					} else {
						document.write(' class="menu_opcion_selec">')
					}
				else
					if ( categEncontradaArea && tema=="" ) {
						document.write(' class="menu_opcion">')
					} else if ( esNuevo == '1' ) {
						document.write(' class="menu_opcion_new">')
					} else if ( esNuevo == 'B' ) {
						document.write(' class="menu_opcion_beta">');
						nameSeccion = nameSeccion + " (BETA)";
					} else {
						document.write(' class="menu_opcion_sub">')
					}
				document.writeln(nameSeccion + '</a></font></td></tr>')
			}
		}
	}
	if (escribePunts) {
		if (! esMenuPrincipal ) {
		    	document.writeln(' <tr><td></td>');
		    	document.writeln(' <td colspan="2"   align="left" nowrap><font size="1">···</font></td></tr>');
		} else {
			if ( numArea>0 ) {
				document.writeln(', ...')
			} else {
				document.writeln('...')
			}
		}
	}
	document.writeln('<TR><td colspan=3 align=center><br><a href="LibroVisitas.php"><img src="archivos/librovisitas.jpg" alt="Déjanos constancia de tu paso" width="90" height="42" border="0"></a></td></TR>');
	document.writeln('<TR><td colspan=3 height=5></td>')
	document.writeln('<TR><TD colspan=3 align=center><a href=javascript:window.external.AddFavorite("http://www.mastbal.com","Asociación Masters de Baleares")><IMG height=13 src="archivos/favoritos.gif" width=15 border=0></a><FONT face=Verdana color=#666666 size=1>&nbsp;Agregar a favoritos</font></td></TR>');
	document.writeln('<TR><td colspan=3 height=5></td>')
	document.writeln('<tr><td colspan=3 align=center><TABLE cellSpacing=0 cellPadding=2 width="200" border=0 background=archivos/contacto.jpg>')
	document.writeln('<TBODY>')
	document.writeln('<TR><td width=14>&nbsp;</td>')
	document.writeln('<TD height=350 valign=bottom><FONT color=white size=2>')
	document.writeln('Asociación Masters de Natación de Baleares<br><br>')
	document.writeln('Piscinas Son Hugo<br>')
	document.writeln('C/Tte. Oyaga s/n<br>')
	document.writeln('C.P. 07004<br>')
	document.writeln('Palma de Mallorca<br><br>') 
	document.writeln('Tlf. 649 391 420<br><br>')
	document.writeln('</FONT>')
	document.writeln('</TD></TR>')
    document.writeln('<tr><td colspan=2 align=center><a href=mailto:mastbal@hotmail.com><font color=white size=2>mastbal@hotmail.com</font></a></td></tr>')
	document.writeln('</TBODY></TABLE></td></tr>');
	document.writeln('<TR><TD colspan="3" align="center"><br><font size=1 color=teal>Web alojada en:</font><br><a href="http://mallorcaweb.net" target="_blank"><img src="archivos/mallorcaweb.gif" alt="www.mallorcaweb.net" width="110" height="30" border="0"></a></TD></TR>');	 
	document.writeln('</table>');
};
