/****************************************************************************************
*																						*
*	s11-global.js																		*
*																						*
*	Script que se incluye en todas las páginas del portal de turismo (s11).				*
*	Proporciona funcionalidad comun a páginas del portal:								*
*																						*
*	- Menus de nivel 3 desplegables.													*
*	- Paginación de buscadores.															*
*	- Visualizador de municipio sobre los mapas.										*
*																						*
*	Carlos Méndez (Bilbomática) 														*
*	Fecha Actualización: 20/07/2007														*
*																						*
****************************************************************************************/

/****************************************************************************************
*																						*
*	Permite añadir funciones de inicialización que se ejecutan con el evento onload de 	*
*	carga de la página del portal.														*
*																						*
*	Se emplea la propiedad r01gIsAdminPage para evitar inicializaciones durante la		*
*	administración de la página del portal.												*
*																						*
*	¡¡¡ OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO OJO !!!	*
*	Cuando se ejecuta esta parte del script, no tenemos ninguna garantia de que el/los	*
*	elementos afectados estén ya cargados en la página. En este script solo se podran	*
*	añadir las fucniones que queremos que se lancen con el evento onload de la página	*
*	y OBLIGATORIAMENTE estas funciones deberán comprobar si el/los elementos afectados	*
*	están presentes en la página para ejecutar el script o no hacer nada.
*																						*
****************************************************************************************/

if(r01gIsAdminPage.toUpperCase()=="FALSE")
{
	if (window.addEventListener) 
	{
	   	window.addEventListener("load", s11OcultaMenu, false);
	} 
	else if (window.attachEvent) 
	{
	   	window.attachEvent("onload", s11OcultaMenu);
	}
}

/****************************************************************************************
*																						*
*	Código de ocultación visualización de los Menus de nivel 3 para portales V2			*
*																						*
*	Carlos Méndez (Bilbomática) 														*
*	Fecha Actualización: 20/07/2007														*
*																						*
****************************************************************************************/

function s11OcultaMenu() 
{	
	if(document.getElementById("s11_ImageMenuDrop-Down"))
	{
		document.getElementById("s11_ImageMenuDrop-Down").style.visibility = "visible";
		document.getElementById("s11_VerticalMenuDrop-Down").style.visibility = "hidden";
		document.getElementById("s11_VerticalMenuDrop-Down").style.position = "absolute";
		document.getElementById("s11_VerticalMenuDrop-Down").style.zIndex = "1";
		document.getElementById("s11_VerticalMenuDrop-Down").style.width = "576px";
		document.getElementById("s11_ImageMenuDrop-Down").onclick = s11DespliegaMenu;
	}
}

function s11DespliegaMenu() 
{	
	if (document.getElementById("s11_VerticalMenuDrop-Down").style.visibility == "visible")	
	{
		document.getElementById("s11_VerticalMenuDrop-Down").style.visibility = "hidden";
	} 
	else 
	{
		document.getElementById("s11_VerticalMenuDrop-Down").style.visibility = "visible";
	}
}	
/****************************************************************************************
*																						*
*	Código para la visualización de los Mapas de Provincias			*
*																						*
*	Javier Robles y Kiko Gálvez (Bilbomática) 														*
*	Fecha Actualización: 20/07/2007														*
*																						*
****************************************************************************************/
/* Establece una función que se ejecutará cuando se cargue la página */

if (window.addEventListener)
{
 window.addEventListener('load', s11_JSIncludeMapaProv, false);

} else if (window.attachEvent)
{
 window.attachEvent('onload', s11_JSIncludeMapaProv);
} 

/*
 * Función que se ejecuta al cargarse la página.
 * Se encarga de obtener los datos del mapa y el punto a pintar
 */
 var s11_divMapaGoogle = null;
function s11_BuscarMapaProvincia() {
	
	
	if (s11_divMapaGoogle != null) {
		if (GBrowserIsCompatible()) {	
			GDownloadUrl(s11_divMapaGoogle.getAttribute('url'), function(data, responseCode) {
				if (responseCode != -1) { // Timeout
					s11_pintarMapaProvincia(s11_divMapaGoogle,data);
				}
			});
		}
	}
}

/*
 * Función que pinta un punto en el mapa e inicializa sus eventos
 */
function s11_createMarkerMapaProv(point,icon,html,url) {
    
    var Params = { icon: null, title: null};
    Params.icon=icon;
    Params.title=html;
    
    var marker = new GMarker(point, Params);
    /*GEvent.addListener(marker, "mouseover", function() {
    	marker.openInfoWindowHtml(html);	
    });
    
    GEvent.addListener(marker, "mouseout", function() {
        marker.closeInfoWindow();	
    });*/
    
    GEvent.addListener(marker, "click", function() {
        //window.open(url, "recurso");	
        window.location.href = url;
    });
    return marker;
}

/*
 * Función que pinta el mapa y posiciona el recurso
 */
function s11_pintarMapaProvincia(divMapa, data) {
	var datosMapa = eval("(" + data + ")");

	if (GBrowserIsCompatible()) {
		var gmap = new GMap2(divMapa);
		
		switch(datosMapa.provincia) {
			case 1: // Alava
				gmap.setCenter(new GLatLng(42.80797684287408, -2.63671875), 9, G_NORMAL_MAP);
				break;
			case 48: // Vizcaya
				gmap.setCenter(new GLatLng(43.25520534158046, -2.7740478515625), 9, G_NORMAL_MAP);
				break;
			case 20: // Guipuzcoa
				gmap.setCenter(new GLatLng(43.141078106345866, -2.24945068359375), 9, G_NORMAL_MAP);
				break
		}
		
		gmap.disableDragging();
		
		// Importante: para que funcionen bien los eventos de la marca el tamaño del icono debe corresponder
		// con el tamaño dado en GSize
		var icon = new GIcon();
		icon.image = "/contenidos/recurso_tecnico/s11_comun/es_s11/images/s11_PuntoRojo.gif";
    icon.iconSize = new GSize(6, 6);
    icon.iconAnchor = new GPoint(3, 3);
    icon.infoWindowAnchor = new GPoint(6, 0);
		
		for(var i = 0; i < datosMapa.puntos.length; i++) {
			var point = new GLatLng(datosMapa.puntos[i].gmLat, datosMapa.puntos[i].gmLng);     
			var marker = s11_createMarkerMapaProv(point, icon, datosMapa.puntos[i].municipio, datosMapa.puntos[i].url );
      gmap.addOverlay(marker);
		}
	}
}

function s11_JSIncludeMapaProv()
{
	
	s11_divMapaGoogle = document.getElementById("s11_mapaProvinciaGoogle");
	
	if (s11_divMapaGoogle != null)
	{
		var strNomFuncionAsinc;
		strNomFuncionAsinc = "s11_BuscarMapaProvincia";
		var INCLUDE_JS_MAPA_PROV;
		
		var strLocation = document.location.toString();
		
		//compruebo si estamos en el preview o producción
		if (strLocation.indexOf("ejiedes") != -1) //estoy en desarrollo
		{
			INCLUDE_JS_MAPA_PROV = "http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAALkquwgWUtlxv4hlSqufWJRTd0yWKyKZcx-aykoac11V_HNRzMBQ8lEh_j28YmCrj1_vMWxVCNLKBlw&async=2&callback=" + strNomFuncionAsinc;
			
		}else{ //estoy en produccion
			//compruebo si estamos en el preview o producción
			if (strLocation.indexOf("ejgvdns") != -1) //estoy en el preview
			{
				INCLUDE_JS_MAPA_PROV = "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAALkquwgWUtlxv4hlSqufWJRR5sh1EEaJ7NfRwfWcXzz0CDemhXRQwGeb5CHoeC-oWWT-Kb7LwPvq1ag&async=2&callback=" + strNomFuncionAsinc;		  																																				
			}else{ //estoy en produccion
				INCLUDE_JS_MAPA_PROV = "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAALkquwgWUtlxv4hlSqufWJRRc4v5-nswy3psr7eXYvRmFQAoxaRTG8V-RTpVd-NQK2dbrD4EciH7FkA&async=2&callback=" + strNomFuncionAsinc;   	
			} 
		}
		
	   	//INCLUDE_JS_MAPA_PROV = "http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAALkquwgWUtlxv4hlSqufWJRRc4v5-nswy3psr7eXYvRmFQAoxaRTG8V-RTpVd-NQK2dbrD4EciH7FkA&async=2&callback=s11_BuscarMapaProvincia";
	   	  																																				
	   	
		 var JS_Include = document.createElement("script");
		 JS_Include.setAttribute("charset", "UTF-8");
		 JS_Include.src = INCLUDE_JS_MAPA_PROV;
		 JS_Include.setAttribute("type","text/javascript");
		 
		 document.getElementsByTagName("head")[0].appendChild(JS_Include);	
	}
	 
}

//funcion para la ficha de ruta. La pongo aqui para que no falle, ya que el s11_General.js se carga en el onload de la página y a esta función se la llama antes.
function fncDibujarEnlaceCapaFicha(strIdCapaMostrar,strIdCapaOcultar)
{
	document.writeln("<a href=\"javascript:fncMostrarRutaDia('" + strIdCapaMostrar + "','" + strIdCapaOcultar + "')\">");
		document.writeln("<img src=\"/contenidos/recurso_tecnico/s11_comun/es_s11/images/fle_v.gif\"/>");
	document.writeln("</a>");
	
}