var abriendo_mas = false;
var pagina = location.pathname;
var idioma;

// Redirección a la versión anterior si el browser no es compatible
if (!navigator.geolocation){
	window.location = "./anterior/perfil.php";
}

// Selección de la oción activa
if (pagina.lastIndexOf("inicio.php")!=-1){
	document.getElementById("opcion_inicio").className = "opcion_menu opcion_seleccionada";
}else if (pagina.lastIndexOf("perfil.php")!=-1){
	document.getElementById("opcion_perfil").className = "opcion_menu opcion_seleccionada";
}else if (pagina.lastIndexOf("viajes.php")!=-1 || pagina.lastIndexOf("ruta.php")!=-1){
	document.getElementById("opcion_viajes").className = "opcion_menu opcion_seleccionada";
}

// Se obtienen las variables de la URL 
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
}

//Variable de idioma
idioma = devuelve_idioma();


function abrir_mas(){
	var opcion_mas_DOM = document.getElementById("opcion_mas");
	var menu__DOM = document.getElementById("menu");
	document.getElementById("menu_mas").style.visibility="visible";
	document.getElementById("menu_mas").style.top = (opcion_mas_DOM.offsetHeight + opcion_mas_DOM.offsetTop + 5) + "px";
	document.getElementById("menu_mas").style.left = opcion_mas_DOM.offsetLeft + "px";
	document.getElementById("opcion_mas").className = "opcion_mas_seleccionada";
	abriendo_mas = true;
}

function cerrar_mas(){
	if (!abriendo_mas && document.getElementById("menu_mas").style.visibility == "visible"){
		document.getElementById("menu_mas").style.visibility="hidden";
		document.getElementById("opcion_mas").className = "opcion_menu";
	}
	abriendo_mas = false;
}

function cambiar_idioma(idioma){
	var current_url = location.href; 
	if (current_url.indexOf("lng=")!=-1){
		current_url = current_url.replace(new RegExp("lng=.."),"lng="+idioma);
	}else if (current_url.indexOf("?")!=-1){
		current_url = current_url.concat("&lng="+idioma);
	}else{
		if (current_url.indexOf("#")!=-1){
			current_url = current_url.replace("#","");
		}
		current_url = current_url.concat("?lng="+idioma);
	}
	window.location.href = current_url;
}

function devuelve_idioma()
{
    if (vars["lng"]){
    	return vars["lng"];
    }else{
    	return "es";
    }
}

function getUrlVars()
{

    return vars;
}
