// JavaScript Document

function pasarVariables(pagina, nombres) {
	pagina +="?";
	nomVec = nombres.split(",");
	for (i=0; i<nomVec.length; i++)
	pagina += nomVec[i] + "=" + escape(eval(nomVec[i]))+"&";
	pagina = pagina.substring(0,pagina.length-1);
	location.href=pagina;
	
	//<a href="javascript:pasarVariables('destino.html', 'var1,var2')">Pulseaquí</a> 
}

function getParameter(parameter){
	// Obtiene la cadena completa de URL
	var url = location.href;
	/* Obtiene la posicion donde se encuentra el signo ?,
	ahi es donde empiezan los parametros */
	var index = url.indexOf("?");
	/* Obtiene la posicion donde termina el nombre del parametro
	e inicia el signo = */
	if (index != null && index != "") {
		index = url.indexOf(parameter,index) + parameter.length;
		/* Verifica que efectivamente el valor en la posicion actual
		es el signo = */
		if (url.charAt(index) == "="){
			// Obtiene el valor del parametro
			var result = url.indexOf("&",index);
			if (result == -1){result=url.length;};
			// Despliega el valor del parametro
			//alert(url.substring(index + 1,result));
	
			return url.substring(index + 1,result);
		}
	}
	
	return null;
}

function mostrarCapa(capa) {
	ocultaItems();
	var obj = document.getElementById(capa);
    if(obj.style.display == 'block') obj.style.display = 'none';
    else obj.style.display = 'block';
}

function ocultaItems(){
	var listado = document.getElementById('menuheader');
    contenedores = listado.getElementsByTagName('div')
    numContenedores = contenedores.length
    for(m=0; m < numContenedores; m++){
    	if(contenedores[m].id.indexOf('menuheaderIdioma') == 0)
        	contenedores[m].style.display = 'none'
    }
}



// Usar estos métodos!!
function mostrarDiv(capa, padre, token) {
	ocultaCapas(padre, token);
	var obj = document.getElementById(capa);
    if(obj.style.display == 'block') obj.style.display = 'none';
    else obj.style.display = 'block';
}

function ocultaCapas(padre, token){
	var listado = document.getElementById(padre);
    contenedores = listado.getElementsByTagName('div')
    numContenedores = contenedores.length
    for(m=0; m < numContenedores; m++){
    	if(contenedores[m].id.indexOf(token) == 0)
        	contenedores[m].style.display = 'none'
    }
}

function mostrarCapaSimple(capa) {
	var obj = document.getElementById(capa);
    if(obj.style.display == 'block') obj.style.display = 'none';
    else obj.style.display = 'block';
}


function inicializarPagina(lang_menu) {
	// MENU IDIOMAS
	var idioma = lang_menu;
	var anchorActual = "castellano";
	
	if ((idioma == null) || (idioma == 'menuheaderIdiomaCastellano')) {
			mostrarCapa('menuheaderIdiomaCastellano');
	} else if (idioma == 'menuheaderIdiomaGalego') {
			mostrarCapa('menuheaderIdiomaGalego');
			anchorActual = "galego";
	} else if (idioma == 'menuheaderIdiomaIngles') {
			mostrarCapa('menuheaderIdiomaIngles');
			anchorActual = "ingles";
	} else if (idioma == 'menuheaderIdiomaFrances') {
			mostrarCapa('menuheaderIdiomaFrances');
			anchorActual = "frances";
	} else if (idioma == 'menuheaderIdiomaAleman') {
			mostrarCapa('menuheaderIdiomaAleman');
			anchorActual = "aleman";
	}
	
	// MENU FUNCIONAL
	var enlace = getParameter('func');
	var i;
	for (i=0;i<document.anchors.length;i++)
	{
		if ( (document.anchors[i].name == enlace) || (document.anchors[i].name == anchorActual)) {
			document.anchors[i].style.color = "#B5B5B5";
		}
	}
}


function marcarAnchor(anchor, color) {
	var i;
	for (i=0;i<document.anchors.length;i++)
	{
		if (document.anchors[i].name == anchor) {
			document.anchors[i].style.color = color;
			break;
		}
	}
}