//Funciones del mapa del buscador de cercanía
var mapa; 
var geoXmlLugaresInteres;
var geoXmlLineasMetro;
var iconoPDI;
var iconoRojo;
var iconoAzul;
var iconoVerde;
var iconoAmarillo;
var iconoPurple; 
var iconoNaranja;
var iconoGris;
var iconoSkyBlue;
var iconoMS;
var vectorHoteles;
var vectorPDIs;
var puntosGUIA;
var elementosXPagina = 10; 
var parametrosBusqueda = "";
var alerta="";

function loadMapaGuia(){
	clearTimeout(temporizador);
	if (GBrowserIsCompatible()) {				
        puntosGUIA = null;
        puntosGUIA = new Array();
        
		mapa = new GMap2(document.getElementById("map")); 
			
		mapa.enableScrollWheelZoom();
		mapa.setMapType(G_NORMAL_MAP);
		mapa.addControl(new GLargeMapControl()); 
		mapa.addControl(new GHierarchicalMapTypeControl());
		mapa.addMapType(G_PHYSICAL_MAP); 
    	mapa.addMapType(G_SATELLITE_3D_MAP); 
	
		mapa.enableContinuousZoom();
		mapa.enableScrollWheelZoom();
			
		mapa.setCenter(new GLatLng(41.652425,-0.881267), 7);	
		
		cargarPuntosGuia(true);														
	}			
}	

function loadMapaBuscadorInteractivo() 
{	
	addMapper(); 
			
	if (GBrowserIsCompatible()) 
	{					
		mapa = new GMap2(document.getElementById("mapaPuntosInteres")); 
		mapa.addControl(new GSmallMapControl());
			
		mapa.enableScrollWheelZoom();
		mapa.setMapType(G_PHYSICAL_MAP);
			
		mapa.setCenter(new GLatLng(41.651367,-0.883026), 12);		
		
		cargarPDIS(true);														
	}			
}	

function cargarPDIS(accion) 
{		
	iconoPDI = new GIcon();
	iconoPDI.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
	iconoPDI.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoPDI.iconSize = new GSize(12, 20);
	iconoPDI.shadowSize = new GSize(22, 20);
	iconoPDI.iconAnchor = new GPoint(6, 20);
	iconoPDI.infoWindowAnchor = new GPoint(5, 1);

	
	GDownloadUrl("devolverPDI.aspx?idArea=10", function (doc) 
	{ 
		var xmlDoc = GXml.parse(doc);			
		var pdi = xmlDoc.documentElement.getElementsByTagName("REGISTRO"); 
		
		vectorPDIs = new Array(); 
		
		for (var i = 0; i < pdi.length; i++) 
		{ 		
			incluirPDI(pdi[i], accion);									
		}
	});
}

function incluirPDI(nodoPDI, accion){
	
	var lat = parseFloat(nodoPDI.getAttribute("LAT")); 
    var lng = parseFloat(nodoPDI.getAttribute("LNG")); 
	var nombre = nodoPDI.getAttribute("NOMBRE"); 
	
	var punto = new GMarker(new GLatLng(lat,lng), iconoPDI);
	var tooltip = new Tooltip(punto,nombre,-50);
	punto.tooltip = tooltip;
			
	if (accion) {
			GEvent.addListener(punto, "click", function() {window.location='mapaHoteles.aspx?PASO1_GEOLATITUD=' + lat + '&PASO1_GEOLONGITUD=' + lng + '&PASO1_GEODISTANCIA=2'});
		}
	GEvent.addListener(punto, "mouseover",function() {this.tooltip.show();});
	GEvent.addListener(punto, "mouseout",function(){this.tooltip.hide();});
										
	mapa.addOverlay(punto);
	mapa.addOverlay(tooltip);
	
	vectorPDIs[vectorPDIs.length]=punto; 	
	
	}
	
function incluirPuntoGuia(nodoPDI, accion)
{						
    var lat = 0; 
    var lng = 0;
    var nombre = nodoPDI.getAttribute("NOMBRE");
    var codigo = nodoPDI.getAttribute("CODIGO");
    var texto = nodoPDI.getAttribute("TEXTO");
    var direccion = nodoPDI.getAttribute("DIRECCION");
    var fecha = String(nodoPDI.getAttribute("FECHA")).replace(" ","");
    var fecha2 = String(nodoPDI.getAttribute("FECHA2")).replace(" ","");
    var categoria = nodoPDI.getAttribute("CATEGORIA");
    var idCategoria = nodoPDI.getAttribute("IDCATEGORIA");
    var archivo = nodoPDI.getAttribute("ARCHIVO");
    var ocultarFecha = String(nodoPDI.getAttribute("OCULTARFECHA"));
    var ocultarAno = String(nodoPDI.getAttribute("OCULTARANO"));

    if (nodoPDI.getAttribute("LAT")) {
        if (nodoPDI.getAttribute("LAT") != "") lat = parseFloat(nodoPDI.getAttribute("LAT"));
    }
    if (nodoPDI.getAttribute("LNG")) {
        if (nodoPDI.getAttribute("LNG") != "") lng = parseFloat(nodoPDI.getAttribute("LNG"));
    }
    
    if (lat == "" || lng == "" || lat == 0 || lng == 0 || lat == NaN || lng == NaN || lat == "NaN" || lng == "NaN") {
        return;
    }
    
    if (archivo == 0) {
        archivo = archivoImagenDefecto;
    }
	
	var punto;
	var fechaI = fecha.substr(0,2) + " " + meses[fecha.substr(3,2)-1];	
	var fechaF = fecha2.substr(0,2) + " " + meses[fecha2.substr(3,2)-1];	
	
	/*switch (fecha.substr(3,2))
	{
		case '01': fechaF = fecha.substr(0,2) + ' Enero'; break;
		case '02': fechaF = fecha.substr(0,2) + ' Febrero'; break;
		case '03': fechaF = fecha.substr(0,2) + ' Marzo'; break;
		case '04': fechaF = fecha.substr(0,2) + ' Abril'; break;
		case '05': fechaF = fecha.substr(0,2) + ' Mayo'; break;
		case '06': fechaF = fecha.substr(0,2) + ' Junio'; break;
		case '07': fechaF = fecha.substr(0,2) + ' Julio'; break;
		case '08': fechaF = fecha.substr(0,2) + ' Agosto'; break;
		case '09': fechaF = fecha.substr(0,2) + ' Septiembre'; break;
		case '10': fechaF = fecha.substr(0,2) + ' Octubre'; break;
		case '11': fechaF = fecha.substr(0,2) + ' Noviembre'; break;
		case '12': fechaF = fecha.substr(0,2) + ' Diciembre'; break;
	}*/
	
	if(ocultarAno == "" || ocultarAno.toUpperCase() == "FALSE") fechaI += " " + fecha.substr(6,4);
	if(ocultarFecha.toUpperCase() == "TRUE") fechaI = "";
	if(ocultarAno == "" || ocultarAno.toUpperCase() == "FALSE") fechaF += " " + fecha2.substr(6,4);
	if(ocultarFecha.toUpperCase() == "TRUE") fechaF = "";
	
	var valorFecha = "";
	 
	if(fechaI == fechaF && fechaI != "") valorFecha = fechaI;
	if(fechaI != fechaF && fechaI != "") valorFecha = fechaI + " - " + fechaF;
	
	if(valorFecha != "") valorFecha = "<i>" + valorFecha + "</i><br/>";
    var icono = "iconoSkyBlue";

    switch (String(idCategoria)) {
        case "89": //"EVENTOS":
            icono = "iconoRojo";
            break;
        case "90": //"FERIAS Y CONGRESOS":
            icono = "iconoAzul";
            break;
        case "91": //"FIESTAS Y TRADICIONES":
            icono = "iconoVerde";
            break;
        case "92": //"MUSEOS":
            icono = "iconoAmarillo";
            break;
        case "111": //"ZONAS DE OCIO":
            icono = "iconoPurple";
            break;
        case "114": //"BODEGAS":
            icono = "iconoNaranja";
            break;
        case "118": //"OFICINAS DE TURISMO":
            icono = "iconoInfo";
            break;
        /*case "CONCIERTOS":
            icono = "iconoNaranja";
            break;*/
    }

	texto = reemplazaTodo(texto,"&quot;","\"");
	texto = reemplazaTodo(texto,"&lt;","<");
	texto = reemplazaTodo(texto,"&gt;",">");
	
	/*if (archivo==0){
		puntosGUIA[codigo] = ["<div class=\"tabGuia\" ><table><tr><td class=\"imagen\" valign=\"top\"><img src=\"images/noEncontrado.gif\" class=\"miniaturaHotel\" width=\"51\" height=\"38\"/><br/><a class=\"botonReservar1\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 17);\">Acercar</a><a class=\"botonReservar2\" style=\"margin-top: 5px\" href=\"mapaHoteles.aspx?PASO1_GEOLATITUD=" + lat + "&PASO1_GEOLONGITUD=" + lng + "&PASO1_GEODISTANCIA=20\">Buscar alojamiento</a></td><td><h5>" + nombre + "</h5>" + valorFecha + "<br/>Lugar: <b>" + direccion + "</b><br/><br/></td></tr></table></div>",
			"<div class=\"tabGuia\">" + texto + "</div>",
			icono,
			lat,
			lng,
			nombre,
			null
		];
	}else{*/
		puntosGUIA[codigo] = ["<div class=\"tabGuia\" ><table><tr><td class=\"imagen\" valign=\"top\"><img src=\"image.aspx?FIL_ID=" + archivo + "&tImg=D&iW=51&iH=38\" class=\"miniaturaHotel\" width=\"51\" height=\"38\"/><br/><a class=\"botonReservar1\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 17);\">Acercar</a><a class=\"botonReservar2\" style=\"margin-top: 5px\" href=\"mapaHoteles.aspx?PASO1_GEOLATITUD=" + lat + "&PASO1_GEOLONGITUD=" + lng + "&PASO1_GEODISTANCIA=20\">Buscar alojamiento</a></td><td><h5>" + nombre + "</h5>" + valorFecha + "<br/>Lugar: <b>" + direccion + "</b><br/><br/></td></tr></table></div>",
			"<div class=\"tabGuia\">" + texto + "</div>",
			icono,
			lat,
			lng,
			nombre,
			null
		];
	/*}*/

    if (accion == true) mostrarPuntoGuia(codigo,false);
	
	/*if (categoria == 'Eventos') 
	{		
		punto = new GMarker(new GLatLng(lat,lng), iconoRojo);
		fechaF = fecha.substring(0,10); //Sólo recogemos la fecha.
	} 
	else
	{
		if (categoria == 'Ferias y Congresos') 
		{			
			punto = new GMarker(new GLatLng(lat,lng), iconoAzul);
			fechaF = fecha;
		} 
		else
		{
			if (categoria == 'Fiestas y Tradiciones') 
			{			
				punto = new GMarker(new GLatLng(lat,lng), iconoVerde);
			}
			else
			{
				if (categoria == 'Zonas de Ocio') 
				{			
					punto = new GMarker(new GLatLng(lat,lng), iconoPurple);
					fechaF = "";
				} 
				else 
				{
					if (categoria == 'Museos')
					{
						punto = new GMarker(new GLatLng(lat,lng), iconoAmarillo);
						fechaF = "";
					}
					else
					{
						if (categoria == 'Conciertos') 
						{			
							punto = new GMarker(new GLatLng(lat,lng), iconoNaranja);
							fechaF = "";
						}
						else 
						{
							punto = new GMarker(new GLatLng(lat,lng), iconoSkyBlue);
							fechaF = "";
						}		
					}
				}
			}
		}
	}
			
	var tooltip = new Tooltip(punto,nombre,-50);
	punto.tooltip = tooltip;
	
	if (archivo==0)
	{
		var tabs = [
			new GInfoWindowTab("General", "<div class=\"tabGuia\" ><table><tr><td class=\"imagen\" valign=\"top\"><img src=\"images/noEncontrado.gif\" class=\"miniaturaHotel\" width=\"51\" height=\"38\"/><br/><a class=\"botonReservar1\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 17);\">Acercar</a><a class=\"botonReservar2\" style=\"margin-top: 5px\" href=\"mapaHoteles.aspx?PASO1_GEOLATITUD=" + lat + "&PASO1_GEOLONGITUD=" + lng + "&PASO1_GEODISTANCIA=20\">Buscar alojamiento</a></td><td><h5>" + nombre + "</h5><i>" + fechaF + "</i><br/><br/>Lugar: <b>" + direccion + "</b><br/><br/></td></tr></table></div>"),			
			new GInfoWindowTab("Detalles", "<div class=\"tabGuia\">" + texto + "</div>")
			];
	}
	else
	{
		var tabs = [
			new GInfoWindowTab("General", "<div class=\"tabGuia\" ><table><tr><td class=\"imagen\" valign=\"top\"><img src=\"image.aspx?FIL_ID=" + archivo + "&tImg=D&iW=51&iH=38\" class=\"miniaturaHotel\" width=\"51\" height=\"38\"/><br/><a class=\"botonReservar1\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 17);\">Acercar</a><a class=\"botonReservar2\" style=\"margin-top: 5px\" href=\"mapaHoteles.aspx?PASO1_GEOLATITUD=" + lat + "&PASO1_GEOLONGITUD=" + lng + "&PASO1_GEODISTANCIA=20\">Buscar alojamiento</a></td><td><h5>" + nombre + "</h5><i>" + fechaF + "</i><br/><br/>Lugar: <b>" + direccion + "</b><br/><br/></td></tr></table></div>"),			
			new GInfoWindowTab("Detalles", "<div class=\"tabGuia\">" + texto + "</div>")
			];
	}
					
	GEvent.addListener(punto, "click", function() {this.tooltip.hide(); punto.openInfoWindowTabsHtml(tabs);});
	GEvent.addListener(punto, "mouseover",function() {this.tooltip.show();});
	GEvent.addListener(punto, "mouseout",function(){this.tooltip.hide();});
										
	mapa.addOverlay(punto);
	mapa.addOverlay(tooltip);
	
	vectorPDIs[codigo] = punto;	*/
}

function mostrarPuntoGuia(codigo, showToolTip) {
    if(puntosGUIA[codigo][3] == "" || puntosGUIA[codigo][4] == "") return;
    
    if (puntosGUIA[codigo][6]) {
        GEvent.trigger(puntosGUIA[codigo][6], "click");
        return;
    }
    //Disparamos el evento Click del punto en cuestión
    //Pablo Pons: Añadimos el punto en el mapa y generamos el tooltip según las opciones
    //		del hotel
    var informacion;
    var tabGeneral;
    var tabDetalles;
    if (puntosGUIA[codigo][0] != "") tabGeneral = new GInfoWindowTab("General", puntosGUIA[codigo][0]);
    if (puntosGUIA[codigo][1] != "") tabDetalles = new GInfoWindowTab("Detalles", puntosGUIA[codigo][1]);
    if (tabGeneral && tabDetalles) {
        informacion = [
				tabGeneral,
				tabDetalles
			];
    } else if (tabGeneral) {
        informacion = [
				tabGeneral
			];
    }
    var punto;
    eval("punto = new GMarker(new GLatLng(" + puntosGUIA[codigo][3] + ", " + puntosGUIA[codigo][4] + "), " + puntosGUIA[codigo][2] + ");");
    
    punto.isInfoWindowOpen = false;
    var tooltip = new Tooltip(punto, reemplazaTodo(String(puntosGUIA[codigo][5]),"&quot;","\""), -50);
    punto.tooltip = tooltip;

    GEvent.clearListeners(punto);
    GEvent.addListener(punto, "click", function() { this.tooltip.hide(); punto.openInfoWindowTabsHtml(informacion); });
    GEvent.addListener(punto, 'mouseover', function() { if (!punto.isInfoWindowOpen) { this.tooltip.show(); } });
    GEvent.addListener(punto, 'mouseout', function() { this.tooltip.hide(); });
    GEvent.addListener(punto, 'infowindowopen', function() { punto.isInfoWindowOpen = true; });
    GEvent.addListener(punto, 'infowindowclose', function() { punto.isInfoWindowOpen = false; });

    puntosGUIA[codigo][6] = punto;

    //Pablo Pons: No cargamos el punto en el mapa hasta que no pinchen
    mapa.removeOverlay(punto);
    mapa.addOverlay(punto);
    mapa.addOverlay(tooltip);
    if(showToolTip == true) GEvent.trigger(punto, "click");
}

function cargarPuntosGuia(accion) 
{				
	iconoRojo = new GIcon();
	iconoRojo.image = URLImagesGuia + "rojoMapa.png"; //"http://labs.google.com/ridefinder/images/mm_20_red.png";
	iconoRojo.shadow = URLImagesGuia + "sombra.png"; //"http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoRojo.iconSize = new GSize(12, 20);
	iconoRojo.shadowSize = new GSize(22, 20);
	iconoRojo.iconAnchor = new GPoint(6, 20);
	iconoRojo.infoWindowAnchor = new GPoint(5, 1);
	
	iconoAzul = new GIcon();
	iconoAzul.image = URLImagesGuia + "azulMapa.png"; //"http://labs.google.com/ridefinder/images/mm_20_blue.png";
	iconoAzul.shadow = URLImagesGuia + "sombra.png"; //"http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoAzul.iconSize = new GSize(12, 20);
	iconoAzul.shadowSize = new GSize(22, 20);
	iconoAzul.iconAnchor = new GPoint(6, 20);
	iconoAzul.infoWindowAnchor = new GPoint(5, 1);
	
	iconoVerde = new GIcon();
	iconoVerde.image = URLImagesGuia + "verdeMapa.png"; //"http://labs.google.com/ridefinder/images/mm_20_green.png";
	iconoVerde.shadow = URLImagesGuia + "sombra.png"; //"http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoVerde.iconSize = new GSize(12, 20);
	iconoVerde.shadowSize = new GSize(22, 20);
	iconoVerde.iconAnchor = new GPoint(6, 20);
	iconoVerde.infoWindowAnchor = new GPoint(5, 1);
	
	iconoAmarillo = new GIcon();
	iconoAmarillo.image = URLImagesGuia + "amarilloMapa.png"; //"http://labs.google.com/ridefinder/images/mm_20_yellow.png";
	iconoAmarillo.shadow = URLImagesGuia + "sombra.png"; //"http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoAmarillo.iconSize = new GSize(12, 20);
	iconoAmarillo.shadowSize = new GSize(22, 20);
	iconoAmarillo.iconAnchor = new GPoint(6, 20);
	iconoAmarillo.infoWindowAnchor = new GPoint(5, 1);
	
	iconoPurple = new GIcon();
	iconoPurple.image = URLImagesGuia + "purpleMapa.png"; //"http://labs.google.com/ridefinder/images/mm_20_purple.png";
	iconoPurple.shadow = URLImagesGuia + "sombra.png"; //"http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoPurple.iconSize = new GSize(12, 20);
	iconoPurple.shadowSize = new GSize(22, 20);
	iconoPurple.iconAnchor = new GPoint(6, 20);
	iconoPurple.infoWindowAnchor = new GPoint(5, 1);
	
	iconoNaranja = new GIcon();
	iconoNaranja.image = URLImagesGuia + "naranjaMapa.png"; //"http://labs.google.com/ridefinder/images/mm_20_orange.png";
	iconoNaranja.shadow = URLImagesGuia + "sombra.png"; //"http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoNaranja.iconSize = new GSize(12, 20);
	iconoNaranja.shadowSize = new GSize(22, 20);
	iconoNaranja.iconAnchor = new GPoint(6, 20);
	iconoNaranja.infoWindowAnchor = new GPoint(5, 1);

	iconoInfo = new GIcon();
	iconoInfo.image = URLImagesGuia + "infoMapa.png";
	iconoInfo.shadow = URLImagesGuia + "sombra.png"; //"http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoInfo.iconSize = new GSize(16, 19);
	iconoInfo.shadowSize = new GSize(22, 20);
	iconoInfo.iconAnchor = new GPoint(6, 20);
	iconoInfo.infoWindowAnchor = new GPoint(5, 1);
			
	iconoSkyBlue = new GIcon();
	iconoSkyBlue.image = "http://labs.google.com/ridefinder/images/mm_20_BlueSky.png";
	iconoSkyBlue.shadow = URLImagesGuia + "sombra.png"; //"http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	iconoSkyBlue.iconSize = new GSize(12, 20);
	iconoSkyBlue.shadowSize = new GSize(22, 20);
	iconoSkyBlue.iconAnchor = new GPoint(6, 20);
	iconoSkyBlue.infoWindowAnchor = new GPoint(5, 1);

	GDownloadUrl("devolverPuntosGuia.aspx", function(doc) {
	    var xmlDoc = GXml.parse(doc);
	    var pdi = new Array();
	    var pdiTotal = new Array();
	    pdi = xmlDoc.documentElement.getElementsByTagName("REGISTRO");
	    pdiTotal = xmlDoc.documentElement.getElementsByTagName("REGISTROMATRIZ");

	    //vectorPDIs = new Array();
	    var pdiMostrar = new Array();
	    var strPDIMostrar = ",";
	    for (var j = 0; j < pdi.length; j++) {
	        pdiMostrar[j] = pdi[j].getAttribute("CODIGO");
	    }
	    strPDIMostrar += pdiMostrar.toString() + ",";
	    pdi = null;
	    pdiMostrar = null;

	    for (var i = 0; i < pdiTotal.length; i++) {
	        if (strPDIMostrar.indexOf("," + pdiTotal[i].getAttribute("CODIGO") + ",") >= 0) {
	            incluirPuntoGuia(pdiTotal[i], true);
	        } else {
	            incluirPuntoGuia(pdiTotal[i], false);
	        }
	        window.status = "Generado: " + i + " / " + pdiTotal.length + "";
	    }

	    window.status = "Listo";
	    document.getElementById("cargandoGuia").style.display = "none";
	});

	/*GDownloadUrl("devolverPuntosGuia.aspx", function (doc) { 
		var xmlDoc = GXml.parse(doc);			
		var pdi = xmlDoc.documentElement.getElementsByTagName("REGISTRO"); 
			
		vectorPDIs = new Array(); 
										
		for (var i = 0; i < pdi.length; i++) 
		{ 		
			incluirPuntoGuia(pdi[i], accion);									
		}
	});*/
}

//realizada por duru
function cargarPuntoGuiaNoMostradoEnMapa(idPuntoGuia, accion)
{
	GDownloadUrl("devolverPuntoGuiaNoMostradoEnMapa.aspx?idPuntoGuia=" + idPuntoGuia, function (doc) { 
		var xmlDoc = GXml.parse(doc);			
		var pdi = xmlDoc.documentElement.getElementsByTagName("REGISTRO");											
		incluirPuntoGuia(pdi[0], accion);			
	});
	
	setTimeout("abrirPunto(" + idPuntoGuia + ")", 10);		
} 
	
function inicializarMapa(){
	
	//Define los iconos y el tipo de mapa de arranque

	/*iconoMS = new GIcon();
	iconoMS.image = "http://zaragozahoteles.desarrollando.net/images/iconoZH.gif";
	iconoMS.shadow = "http://zaragozahoteles.desarrollando.net/images/iconoMSShadow.png";
	iconoMS.iconSize = new GSize(23.0, 27.0);
	iconoMS.shadowSize = new GSize(42.0, 24.0);
	iconoMS.iconAnchor = new GPoint(14.0, 12.0);
	iconoMS.infoWindowAnchor = new GPoint(14.0, 12.0);*/
	
	iconoHotel = new GIcon();
	iconoHotel.image = "images/hotel.png";
	iconoHotel.shadow = "images/shadowIconos.png";
	iconoHotel.iconSize = new GSize(32.0, 37.0);
	iconoHotel.shadowSize = new GSize(51.0, 37.0);
	iconoHotel.iconAnchor =  new GPoint(16.0, 18.0);
	iconoHotel.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoHostal = new GIcon();
	iconoHostal.image = "images/hostal.png";
	iconoHostal.shadow = "images/shadowIconos.png";
	iconoHostal.iconSize = new GSize(32.0, 37.0);
	iconoHostal.shadowSize = new GSize(51.0, 37.0);
	iconoHostal.iconAnchor =  new GPoint(16.0, 18.0);
	iconoHostal.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoHospederia = new GIcon();
	iconoHospederia.image = "images/iconoHostal.png";
	iconoHospederia.shadow = "images/shadowIconos.png";
	iconoHospederia.iconSize = new GSize(32.0, 37.0);
	iconoHospederia.shadowSize = new GSize(51.0, 37.0);
	iconoHospederia.iconAnchor =  new GPoint(16.0, 18.0);
	iconoHospederia.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoCRH = new GIcon();
	iconoCRH.image = "images/casaRural.png";
	iconoCRH.shadow = "images/shadowIconos.png";
	iconoCRH.iconSize = new GSize(32.0, 37.0);
	iconoCRH.shadowSize = new GSize(51.0, 37.0);
	iconoCRH.iconAnchor =  new GPoint(16.0, 18.0);
	iconoCRH.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoCRC = new GIcon();
	iconoCRC.image = "images/casaRural.png";
	iconoCRC.shadow = "images/shadowIconos.png";
	iconoCRC.iconSize = new GSize(32.0, 37.0);
	iconoCRC.shadowSize = new GSize(51.0, 37.0);
	iconoCRC.iconAnchor =  new GPoint(16.0, 18.0);
	iconoCRC.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoAlbergue = new GIcon();
	iconoAlbergue.image = "images/albergue.png";
	iconoAlbergue.shadow = "images/shadowIconos.png";
	iconoAlbergue.iconSize = new GSize(32.0, 37.0);
	iconoAlbergue.shadowSize = new GSize(51.0, 37.0);
	iconoAlbergue.iconAnchor =  new GPoint(16.0, 18.0);
	iconoAlbergue.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoApartamentoTuristico = new GIcon();
	iconoApartamentoTuristico.image = "images/apartamentoTuristico.png";
	iconoApartamentoTuristico.shadow = "images/shadowIconos.png";
	iconoApartamentoTuristico.iconSize = new GSize(32.0, 37.0);
	iconoApartamentoTuristico.shadowSize = new GSize(51.0, 37.0);
	iconoApartamentoTuristico.iconAnchor =  new GPoint(16.0, 18.0);
	iconoApartamentoTuristico.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoBalneario = new GIcon();
	iconoBalneario.image = "images/balneario.png";
	iconoBalneario.shadow = "images/shadowIconos.png";
	iconoBalneario.iconSize = new GSize(32.0, 37.0);
	iconoBalneario.shadowSize = new GSize(51.0, 37.0);
	iconoBalneario.iconAnchor =  new GPoint(16.0, 18.0);
	iconoBalneario.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoTurismoAventura = new GIcon();
	iconoTurismoAventura.image = "images/turismoAventura.png";
	iconoTurismoAventura.shadow = "images/shadowIconos.png";
	iconoTurismoAventura.iconSize = new GSize(32.0, 37.0);
	iconoTurismoAventura.shadowSize = new GSize(51.0, 37.0);
	iconoTurismoAventura.iconAnchor =  new GPoint(16.0, 18.0);
	iconoTurismoAventura.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoRestaurante = new GIcon();
	iconoRestaurante.image = "images/restaurante.png";
	iconoRestaurante.shadow = "images/shadowIconos.png";
	iconoRestaurante.iconSize = new GSize(32.0, 37.0);
	iconoRestaurante.shadowSize = new GSize(51.0, 37.0);
	iconoRestaurante.iconAnchor =  new GPoint(16.0, 18.0);
	iconoRestaurante.infoWindowAnchor = new GPoint(16.0, 18.0);
	
	iconoCamping = new GIcon();
	iconoCamping.image = "images/camping.png";
	iconoCamping.shadow = "images/shadowIconos.png";
	iconoCamping.iconSize = new GSize(32.0, 37.0);
	iconoCamping.shadowSize = new GSize(51.0, 37.0);
	iconoCamping.iconAnchor =  new GPoint(16.0, 18.0);
	iconoCamping.infoWindowAnchor = new GPoint(16.0, 18.0);
		    
	mapa = new GMap2(document.getElementById("map")); 
	mapa.addControl(new GLargeMapControl());
	mapa.addControl(new GHierarchicalMapTypeControl());
	mapa.addMapType(G_PHYSICAL_MAP); 
    mapa.addMapType(G_SATELLITE_3D_MAP); 
    
    mapa.clearOverlays();
	
	mapa.enableContinuousZoom();
	mapa.enableScrollWheelZoom();

}

function incluirHotel(nodoHotel){
	var precioFormateado;
	var demandaAux = parseInt(nodoHotel.getAttribute("DEMANDA"));
	var lat = "0"; 
    var lng = "0"; 
	var nombre = nodoHotel.getAttribute("HOTD_NOMBRE"); 
	var direccion = nodoHotel.getAttribute("HOTI_DIRECCION"); 
	var localidad = nodoHotel.getAttribute("LOCALIDAD");
	var provincia = nodoHotel.getAttribute("PROVINCIA");
	var categoria = parseInt(nodoHotel.getAttribute("HOTI_CATEGORIA")); 
	//Transpondemos la categoria para que aparezca un orden lógico
		/*if (categoria >= 10)  {
			categoria  = parseInt(categoria - 10); //Hostales se quedarán con 01 - 02 - 03 
		} else {
			categoria = parseInt(categoria + 10); //Hoteles tomarán 11 - 12 - 13 - 14 - 15
		}*/
	var precioMinimo = nodoHotel.getAttribute("PRECIODESDEIVA").replace(",", "."); 
	var descripcion = nodoHotel.getAttribute("HOTD_DESCRIPCION"); 
	var codigo = nodoHotel.getAttribute("HOTI_CODIGO"); 
	var videoYouTube = nodoHotel.getAttribute("HOTD_YOUTUBE"); 
	var videoYouTube2 = nodoHotel.getAttribute("HOTD_YOUTUBE2"); 
	var imagenMiniatura = "0";
	var edadMaxBebe = nodoHotel.getAttribute("HOTI_EDADMAXBEBE");
	var tipoEstablecimiento = nodoHotel.getAttribute("HOTI_TIPOESTABLECIMIENTO");
	var imagenCategoria = "";
	
	if(nodoHotel.getAttribute("ESTTIP_IMAGEN")) imagenCategoria = nodoHotel.getAttribute("ESTTIP_IMAGEN");
	
	if(nodoHotel.getAttribute("HOTI_LATITUD")) lat = parseFloat(nodoHotel.getAttribute("HOTI_LATITUD").replace(",", ".")); 
    if(nodoHotel.getAttribute("HOTI_LONGITUD")) lng = parseFloat(nodoHotel.getAttribute("HOTI_LONGITUD").replace(",", ".")); 

	if(nodoHotel.getAttribute("IMAGEN")) imagenMiniatura = nodoHotel.getAttribute("IMAGEN");
	if(nodoHotel.getAttribute("FOTO")) imagenMiniatura = nodoHotel.getAttribute("FOTO");
	if(nodoHotel.getAttribute("FIL_ID")) imagenMiniatura = nodoHotel.getAttribute("FIL_ID");

	if(videoYouTube == null) videoYouTube = "";
	if(videoYouTube2 == null) videoYouTube2 = "";
	
	if(!direccion) direccion = "";
	direccion += " - ";
	if(localidad) direccion += " " + localidad;
	if(provincia) direccion += " (" + provincia + ")";
	if(descripcion){
		if (descripcion.length > 130){
			descripcion = descripcion.substring(0,130) + "..."
		}
	}
		
	if (imagenMiniatura == "" || imagenMiniatura == "null") {
		imagenMiniatura = 0
	}
			
	
	var estrellas = generarEstrellas(categoria,imagenCategoria);
	
	var imagenes = nodoHotel.getElementsByTagName("IMAGEN"); 
	var galeriaImagenes = "<div id='empujador'>haga click sobre las miniaturas para ampliar</div>";
	var limiteImagenes;
	if(imagenes.length <= 9){
		limiteImagenes = imagenes.length;
	}else{
		limiteImagenes = 9;
	}
	for (var i = 0; i < limiteImagenes; i++) 
		{ 		
			var imagenActual = imagenes[i].getAttribute("FIL_ID");
			
			galeriaImagenes += "<div id='foto'><a href=\"http://reservas.siron.es/admin/File.aspx?FIL_ID=" + imagenActual + "\" class=\"highslide\" onclick=\"return hs.expand(this)\" ><img src=\"http://reservas.siron.es/admin/File.aspx?FIL_ID=" + imagenActual + "&tImg=D&iW=71&iH=53\" /></a></div>"	
		}
	if (imagenes.length == 0) {
		galeriaImagenes = "Galer&iacute;a de im&aacute;genes no disponible"
		}
				
	var tabs;

	if (demandaAux == 1) {
		precioFormateado = precioMinimo;
		precioMinimo = "Reserva bajo demanda";
	} else {
		precioFormateado = parseFloat(precioMinimo).toFixed(2);
		precioMinimo = "Desde<br/><b>" + String(precioFormateado).replace(".",",") + " &euro;</b>"
	}
	
//		precioMinimo = "Demanda (Incluir Hotel): " + demandaAux;

	var tabImg, tabHotel;
	//var objPrecio = new oNumero(precioMinimo);
	//objPrecio.formato(2, true)
	
	tabHotel = "<div class=\"tabMapa\"><table><tr><td class=\"imagen\"><img src=\"http://reservas.siron.es/admin/File.aspx?FIL_ID=" + imagenMiniatura + "&tImg=D&iW=71&iH=53\" class=\"miniaturaHotel\"/><p>" + precioMinimo + "</p></td><td><h5>" + nombre + "</h5>" + estrellas + "<br/><br/><b>" + direccion + "</b><br/>" + descripcion + "</td></tr><tr><td><a href='javascript:lanzarReserva(\"" + codigo + "\"," + edadMaxBebe + ")' class=\"botonReservar\">reservar</a></td><td><a href='javascript:verHotel(\"" + codigo + "\")' class=\"botonMasInfo\">m&aacute;s informaci&oacute;n</a><a class=\"zoomHotel\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 16);\">Zoom</a></td></tr></table></div>";
	tabImg = "<div class=\"tabMapa\" style=\"overflow:auto\">" + galeriaImagenes + "</div>";
	
	if(videoYouTube2 != ""){
		tabs = [
			tabHotel,
			tabImg,
			"<div class=\"tabMapa\"><object width=\"280\" height=\"180\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + videoYouTube2 + "&hl=es&fs=1\"/><param name=\"allowFullScreen\" value=\"true\"/><embed src=\"http://www.youtube.com/v/" + videoYouTube2 + "&hl=es&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"280\" height=\"180\"/></object></div>"
		];
	}else if(videoYouTube != ""){
		tabs = [
			tabHotel,
			tabImg,
			"<div class=\"tabMapa\"><object width=\"280\" height=\"180\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + videoYouTube + "&hl=es&fs=1\"/><param name=\"allowFullScreen\" value=\"true\"/><embed src=\"http://www.youtube.com/v/" + videoYouTube + "&hl=es&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"280\" height=\"180\"/></object></div>"
		];
	}else{
		tabs = [
			tabHotel,
			tabImg,
			""
		];
	}
	
	/*if (videoYouTube != "") {
		tabs = [
		new GInfoWindowTab("info", "<div class=\"tabMapa\"><table><tr><td class=\"imagen\"><img src=\"http://reservas.siron.es/admin/File.aspx?FIL_ID=" + imagenMiniatura + "&tImg=D&iW=71&iH=53\" class=\"miniaturaHotel\"/><p>" + precioMinimo + "</p></td><td><h5>" + nombre + "</h5>" + estrellas + "<br/><br/><b>" + direccion + "</b><br/>" + descripcion + "</td></tr><tr><td><a href='javascript:lanzarReserva(\"" + codigo + "\"," + edadMaxBebe + ")' class=\"botonReservar\">reservar</a></td><td><a href='javascript:verHotel(\"" + codigo + "\")' class=\"botonMasInfo\">más información</a><a class=\"zoomHotel\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 16);\">Zoom</a></td></tr></table></div>"),
		
		new GInfoWindowTab("fotos","<div class=\"tabMapa\" style=\"overflow:auto\">" + galeriaImagenes + "</div>"),
			new GInfoWindowTab("video","<div class=\"tabMapa\"><object width=\"280\" height=\"180\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + videoYouTube + "&hl=es&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/" + videoYouTube + "&hl=es&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"280\" height=\"180\"></embed></object></div>")
		];
	} else {
	tabs = [
		new GInfoWindowTab("info", "<div class=\"tabMapa\"><table><tr><td class=\"imagen\"><img src=\"http://reservas.siron.es/admin/File.aspx?FIL_ID=" + imagenMiniatura + "&tImg=D&iW=71&iH=53\" class=\"miniaturaHotel\"/><p>" + precioMinimo + "</p></td><td><h5>" + nombre + "</h5>" + estrellas + "<br/><br/><b>" + direccion + "</b><br/>" + descripcion + "</td></tr><tr><td><a href='javascript:lanzarReserva(\"" + codigo + "\"," + edadMaxBebe + ")' class=\"botonReservar\">reservar</a></td><td><a href='javascript:verHotel(\"" + codigo + "\")' class=\"botonMasInfo\">más información</a><a class=\"zoomHotel\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 16);\">Zoom</a></td></tr></table></div>"),
		
		new GInfoWindowTab("fotos","<div class=\"tabMapa\" style=\"overflow:auto\">" + galeriaImagenes + "</div>")];
	}
	if (videoYouTube2 != "") {
		tabs = [
		new GInfoWindowTab("info", "<div class=\"tabMapa\"><table><tr><td class=\"imagen\"><img src=\"http://reservas.siron.es/admin/File.aspx?FIL_ID=" + imagenMiniatura + "&tImg=D&iW=71&iH=53\" class=\"miniaturaHotel\"/><p>" + precioMinimo + "</p></td><td><h5>" + nombre + "</h5>" + estrellas + "<br/><br/><b>" + direccion + "</b><br/>" + descripcion + "</td></tr><tr><td><a href='javascript:lanzarReserva(\"" + codigo + "\"," + edadMaxBebe + ")' class=\"botonReservar\">reservar</a></td><td><a href='javascript:verHotel(\"" + codigo + "\")' class=\"botonMasInfo\">más información</a><a class=\"zoomHotel\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 16);\">Zoom</a></td></tr></table></div>"),
		
		new GInfoWindowTab("fotos","<div class=\"tabMapa\" style=\"overflow:auto\">" + galeriaImagenes + "</div>"),
			new GInfoWindowTab("video","<div class=\"tabMapa\"><object width=\"280\" height=\"180\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + videoYouTube + "&hl=es&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/" + videoYouTube2 + "&hl=es&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"280\" height=\"180\"></embed></object></div>")
		];
	} else {
	tabs = [
		new GInfoWindowTab("info", "<div class=\"tabMapa\"><table><tr><td class=\"imagen\"><img src=\"http://reservas.siron.es/admin/File.aspx?FIL_ID=" + imagenMiniatura + "&tImg=D&iW=71&iH=53\" class=\"miniaturaHotel\"/><p>" + precioMinimo + "</p></td><td><h5>" + nombre + "</h5>" + estrellas + "<br/><br/><b>" + direccion + "</b><br/>" + descripcion + "</td></tr><tr><td><a href='javascript:lanzarReserva(\"" + codigo + "\"," + edadMaxBebe + ")' class=\"botonReservar\">reservar</a></td><td><a href='javascript:verHotel(\"" + codigo + "\")' class=\"botonMasInfo\">más información</a><a class=\"zoomHotel\" href=\"javascript:mapa.setCenter(new GLatLng(" + lat + "," + lng + "), 16);\">Zoom</a></td></tr></table></div>"),
		
		new GInfoWindowTab("fotos","<div class=\"tabMapa\" style=\"overflow:auto\">" + galeriaImagenes + "</div>")];
	}*/
		var punto 
		//No ponemos ningún punto
		/*
		if (tipoEstablecimiento == 1) {
			punto = new GMarker(new GLatLng(lat,lng), iconoHotel);
		}
		if (tipoEstablecimiento == 2) {
			punto = new GMarker(new GLatLng(lat,lng), iconoHostal);
		}
		if (tipoEstablecimiento == 3) {
			punto = new GMarker(new GLatLng(lat,lng), iconoHospederia);
		}
		if (tipoEstablecimiento == 4) {
			punto = new GMarker(new GLatLng(lat,lng), iconoCRH);
		}
		if (tipoEstablecimiento == 5) {
			punto = new GMarker(new GLatLng(lat,lng), iconoCRC);
		}
		if (tipoEstablecimiento == 6) {
			punto = new GMarker(new GLatLng(lat,lng), iconoAlbergue);
		}
		if (tipoEstablecimiento == 7) {
			punto = new GMarker(new GLatLng(lat,lng), iconoApartamentoTuristico);
		}
		if (tipoEstablecimiento == 8) {
			punto = new GMarker(new GLatLng(lat,lng), iconoBalneario);
		}
		if (tipoEstablecimiento == 9) {
			punto = new GMarker(new GLatLng(lat,lng), iconoTurismoAventura);
		}
		if (tipoEstablecimiento == 10) {
			punto = new GMarker(new GLatLng(lat,lng), iconoRestaurante);
		}
		if (tipoEstablecimiento == 11) {
			punto = new GMarker(new GLatLng(lat,lng), iconoCamping);
		}
		
		
		punto.isInfoWindowOpen = false;
		var tooltip = new Tooltip(punto,nombre,-50);
		punto.tooltip = tooltip;
			
		GEvent.addListener(punto, "click", function() {this.tooltip.hide(); punto.openInfoWindowTabsHtml(tabs);});
		GEvent.addListener(punto,'mouseover',function(){if (!punto.isInfoWindowOpen) {this.tooltip.show();}});
		GEvent.addListener(punto,'mouseout',function(){this.tooltip.hide();});
		GEvent.addListener(punto,'infowindowopen',function() {punto.isInfoWindowOpen = true;});
		GEvent.addListener(punto,'infowindowclose',function() {punto.isInfoWindowOpen = false;});
		
		//Pablo Pons: No cargamos el punto en el mapa hasta que no pinchen en un hotel								
		//mapa.addOverlay(punto);
		mapa.addOverlay(tooltip);
		
		// Generamos la entrada en el vector de hoteles
		*/
		//precioMinimo = nodoHotel.getAttribute("PRECIODESDEIVA").replace(",", "."); 

		vectorHoteles.nuevoHotel(codigo,nombre,direccion,categoria,precioFormateado,punto,'',imagenMiniatura,demandaAux,tipoEstablecimiento,lat,lng,tabs,imagenCategoria);
	}

function seleccionarHotelMapa(indexHotel){

	if(vectorHoteles.hotel[indexHotel].punto){
		GEvent.trigger(vectorHoteles.hotel[indexHotel].punto, "click");
		return;
	}
	//Disparamos el evento Click del punto en cuestión
	//Pablo Pons: Añadimos el punto en el mapa y generamos el tooltip según las opciones
	//		del hotel
	var informacion;
	var tabInfo;
	var tabFotos;
	var tabVideo;
	if (vectorHoteles.hotel[indexHotel].tooltip[0] != "") tabInfo = new GInfoWindowTab("info", vectorHoteles.hotel[indexHotel].tooltip[0]);
	if (vectorHoteles.hotel[indexHotel].tooltip[1] != "") tabFotos = new GInfoWindowTab("fotos", vectorHoteles.hotel[indexHotel].tooltip[1]);
	if (vectorHoteles.hotel[indexHotel].tooltip[2] != "") tabVideo = new GInfoWindowTab("video", vectorHoteles.hotel[indexHotel].tooltip[2]);
	if(tabInfo && tabFotos && tabVideo){
		informacion = [
			tabInfo,
			tabFotos,
			tabVideo
		];
	}else if(tabInfo && tabFotos){
		informacion = [
			tabInfo,
			tabFotos
		];
	}else{
		informacion = [
			tabInfo
		];
	}
	var punto;
	var tipoEstablecimiento = vectorHoteles.hotel[indexHotel].tipoEstablecimiento;
	var lat = vectorHoteles.hotel[indexHotel].latitud;
	var lng = vectorHoteles.hotel[indexHotel].longitud;
			
	switch(tipoEstablecimiento){
		case "2":
			punto = new GMarker(new GLatLng(lat,lng), iconoHostal);
			break;
		case "3":
			punto = new GMarker(new GLatLng(lat,lng), iconoHospederia);
			break;
		case "4":
			punto = new GMarker(new GLatLng(lat,lng), iconoCRH);
			break;
		case "5":
			punto = new GMarker(new GLatLng(lat,lng), iconoCRC);
			break;
		case "6":
			punto = new GMarker(new GLatLng(lat,lng), iconoAlbergue);
			break;
		case "7":
			punto = new GMarker(new GLatLng(lat,lng), iconoApartamentoTuristico);
			break;
		case "8":
			punto = new GMarker(new GLatLng(lat,lng), iconoBalneario);
			break;
		case "9":
			punto = new GMarker(new GLatLng(lat,lng), iconoTurismoAventura);
			break;
		case "10":
			punto = new GMarker(new GLatLng(lat,lng), iconoRestaurante);
			break;
		case "11":
			punto = new GMarker(new GLatLng(lat,lng), iconoCamping);
			break;
		default:
			punto = new GMarker(new GLatLng(lat,lng), iconoHotel);
	}
	/*if (tipoEstablecimiento == 1) {
		punto = new GMarker(new GLatLng(lat,lng), iconoHotel);
	}
	if (tipoEstablecimiento == 2) {
		punto = new GMarker(new GLatLng(lat,lng), iconoHostal);
	}
	if (tipoEstablecimiento == 3) {
		punto = new GMarker(new GLatLng(lat,lng), iconoHospederia);
	}
	if (tipoEstablecimiento == 4) {
		punto = new GMarker(new GLatLng(lat,lng), iconoCRH);
	}
	if (tipoEstablecimiento == 5) {
		punto = new GMarker(new GLatLng(lat,lng), iconoCRC);
	}
	if (tipoEstablecimiento == 6) {
		punto = new GMarker(new GLatLng(lat,lng), iconoAlbergue);
	}
	if (tipoEstablecimiento == 7) {
		punto = new GMarker(new GLatLng(lat,lng), iconoApartamentoTuristico);
	}
	if (tipoEstablecimiento == 8) {
		punto = new GMarker(new GLatLng(lat,lng), iconoBalneario);
	}
	if (tipoEstablecimiento == 9) {
		punto = new GMarker(new GLatLng(lat,lng), iconoTurismoAventura);
	}
	if (tipoEstablecimiento == 10) {
		punto = new GMarker(new GLatLng(lat,lng), iconoRestaurante);
	}
	if (tipoEstablecimiento == 11) {
		punto = new GMarker(new GLatLng(lat,lng), iconoCamping);
	}*/
	
	
	punto.isInfoWindowOpen = false;
	var tooltip = new Tooltip(punto,vectorHoteles.hotel[indexHotel].nombre,-50);
	punto.tooltip = tooltip;
	
	GEvent.clearListeners(punto);
	GEvent.addListener(punto, "click", function() {this.tooltip.hide(); punto.openInfoWindowTabsHtml(informacion);});
	GEvent.addListener(punto,'mouseover',function(){if (!punto.isInfoWindowOpen) {this.tooltip.show();}});
	GEvent.addListener(punto,'mouseout',function(){this.tooltip.hide();});
	GEvent.addListener(punto,'infowindowopen',function() {punto.isInfoWindowOpen = true;});
	GEvent.addListener(punto,'infowindowclose',function() {punto.isInfoWindowOpen = false;});
	
	vectorHoteles.hotel[indexHotel].punto = punto;
	
	//Pablo Pons: No cargamos el punto en el mapa hasta que no pinchen en un hotel
	mapa.removeOverlay(punto);
	mapa.addOverlay(punto);
	mapa.addOverlay(tooltip);
	GEvent.trigger(punto, "click");

	//mapa.removeOverlay(vectorHoteles.hotel[indexHotel].marker);
	//mapa.addOverlay(vectorHoteles.hotel[indexHotel].marker);
	//GEvent.trigger(vectorHoteles.hotel[indexHotel].marker, "click");
}

function limpiarHotelesActuales(){
	mapa.clearOverlays();
		//Recorremos el vector de hoteles y eliminamos todos los puntos del mapa
		/*if (vectorHoteles){
			for (i=0; i< vectorHoteles.hotel.length; i++)
			{
				mapa.removeOverlay(vectorHoteles.hotel[i].marker);
			}
		}*/
}

function limpiarPDISActuales(){
	
		//Recorremos el vector de hoteles y eliminamos todos los puntos del mapa
		if (vectorPDIs != undefined)			
			for (i=0; i< vectorPDIs.length; i++)
			{
				mapa.removeOverlay(vectorPDIs[i]);
				
			}			
}

function cambiarZonaMapa(){
	
	hacerZoomAZona(document.getElementById('cmbZonasMapa').value);
	recargarConsulta();
	
	}


function hacerZoomAZona(numeroZona){
	
	//Cambiamos la posición y el zoom del mapa a la zona concreta seleccionada
	switch(numeroZona)
		{
		case 'Aranda':
			mapa.setCenter(new GLatLng(41.573334,-1.792145), 10);		
			break;  
		case 'Bajo Aragón-Caspe':
			mapa.setCenter(new GLatLng(41.235478,-0.041199), 10);		
			break;  
		case 'Bajo Cinca':
			mapa.setCenter(new GLatLng(41.512691,0.351563), 10);		
			break;  
		case 'Campo de Belchite':
			mapa.setCenter(new GLatLng(41.309986,-0.754023), 10);		
			break;  
		case 'Campo de Borja':
			mapa.setCenter(new GLatLng(41.808173,-1.51062), 10);		
			break;  
		case 'Campo de Cariñena':
			mapa.setCenter(new GLatLng(41.336349,-1.225319), 10);		
			break;  
		case 'Campo de Daroca':
			mapa.setCenter(new GLatLng(41.114021,-1.412086), 10);		
			break; 
		case 'Cinco Villas':
			mapa.setCenter(new GLatLng(42.115543,-1.149445), 10);		
			break;  
		case 'Comunidad de Calatayud':
			mapa.setCenter(new GLatLng(41.356196,-1.652756), 10);		
			break;  
		case 'Hoya de Huesca':
			mapa.setCenter(new GLatLng(42.309815,-0.55481), 10);		
			break;  
		case 'La Jacetania':
			mapa.setCenter(new GLatLng(42.730874,-0.758057), 10);		
			break;  
		case 'Los Monegros':
			mapa.setCenter(new GLatLng(41.750824,-0.148315), 10);		
			break;  
		case 'Ribera Alta del Ebro':
			mapa.setCenter(new GLatLng(41.983994,-0.834961), 10);		
			break;  
		case 'Ribera Baja del Ebro':
			mapa.setCenter(new GLatLng(41.512691,-0.527344), 10);		
			break; 
		case 'Tarazona y el Moncayo':
			mapa.setCenter(new GLatLng(41.8987,-1.722107), 10);		
			break;  
		case 'Valdejalón':
			mapa.setCenter(new GLatLng(41.611335,-1.257935), 10);		
			break;  
		case 'Zaragoza':
			mapa.setCenter(new GLatLng(41.651367,-0.883026), 12);		
			break; 
		default:
			//Zoom por defecto en mapa general
			mapa.setCenter(new GLatLng(41.651367,-0.883026), 7);		
		}		
	}

function cambiarEstadoLineasMetro(){		
		
	if (document.getElementById('chkLineasMetro').checked) 
	{
		//Carga asíncronamente la capa KML con las líneas del metro 		
		geoXmlLineasMetro = new GGeoXml("http://zaragozahoteles.desarrollando.net/lineasMetro.kml");
		mapa.addOverlay(geoXmlLineasMetro);
			
	} else {
		//Borra la capa KML con las líneas del metro 		
		mapa.removeOverlay(geoXmlLineasMetro);
	}
}

function cambiarEstadoLugaresInteres(){		
		
	if (document.getElementById('chkLugaresInteres').checked) 
	{
		//Carga asíncronamente la capa KML con los lugares de interés		
		cargarPDIS(false);
			
	} else {
		//Borra la capa KML con las líneas del metro 		
		limpiarPDISActuales();
	}
}

/*Funciones del elemento ToolTip*/

function Tooltip(marker, text, padding){
	this.marker_ = marker;
	this.text_ = text;
	this.padding_ = padding;
}

Tooltip.prototype = new GOverlay();

Tooltip.prototype.initialize = function(map){
	var div = document.createElement("div");
	div.appendChild(document.createTextNode(this.text_));
	div.className = 'tooltip';
	div.style.position = 'absolute';
	div.style.visibility = 'hidden';
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	this.map_ = map;
	this.div_ = div;
}

Tooltip.prototype.remove = function(){
	this.div_.parentNode.removeChild(this.div_);
}

Tooltip.prototype.copy = function(){
	return new Tooltip(this.marker_,this.text_,this.padding_);
}

Tooltip.prototype.redraw = function(force){
	if (!force) return;
	var markerPos = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
	var iconAnchor = this.marker_.getIcon().iconAnchor;
	var xPos = Math.round(markerPos.x - this.div_.clientWidth / 2);
	var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_;
	this.div_.style.top = yPos + 'px';
	this.div_.style.left = xPos + 'px';
}

Tooltip.prototype.show = function(){
	this.div_.style.visibility = 'visible';
}

Tooltip.prototype.hide = function(){
	this.div_.style.visibility = 'hidden';
}

/* Funciones del vector de hoteles */

function objetoHoteles() { 
	this.hotel=new Array(); 
}

function hotel(codigo,nombre,direccion,categoria,precio,marker,descripcion,imagen,demanda,tipoEstablecimiento,latitud,longitud,tooltip,imagenCategoria) { 
	this.codigo=codigo;
	this.nombre=nombre;
	this.direccion=direccion;
	this.categoria=categoria; 
	this.precio=precio;
	this.marker=marker;
	this.descripcion=descripcion;
	this.imagen=imagen;
	this.demanda=demanda;
	this.tipoEstablecimiento=tipoEstablecimiento;
	this.latitud = latitud;
	this.longitud = longitud;
	this.tooltip = tooltip;
	this.imagenCategoria = imagenCategoria;
}

objetoHoteles.prototype.nuevoHotel=function(codigo,nombre,direccion,categoria,precio,marker,descripcion,imagen,demanda,tipoEstablecimiento,latitud,longitud,tooltip,imagenCategoria) { 
	this.hotel[this.hotel.length]=new hotel(codigo,nombre,direccion,categoria,precio,marker,descripcion,imagen,demanda,tipoEstablecimiento,latitud,longitud,tooltip,imagenCategoria); 
} 

objetoHoteles.prototype.ordenar=function() { 
	var param = "return ", dato, orden;
	for (var i = 0; i < arguments.length; i += 2) { 
	dato = arguments[i];
	orden = (arguments[i+1] == "D")? 1 : -1;
	
	param += "(x." + dato + " < y." + dato + ")?" + orden + ":";
	param += "(x." + dato + " > y." + dato + ")?" + (0 - orden) + ":"; 
	}
	
	param += "0;";
	
	this.hotel.sort(new Function("x","y",param)); 
} 

/* Funciones de manejo de la tabla de hoteles bajo el mapa */

function actualizarTablaHoteles(paginaActual){
		
		//Limpiamos la tabla actual de hoteles
		var tablaHoteles = document.getElementById('tablaHoteles');	
		
		if (vectorHoteles.hotel.length > 0)
		{
			
			limpiarFilas(tablaHoteles);			
					
			//Ahora recorremos el vector de hoteles y hacemos la llamada a la funcion que pinta cada fila
			var posicionInicial = paginaActual * elementosXPagina;
			var posicionFinal = posicionInicial + elementosXPagina;
			
			if (posicionFinal > vectorHoteles.hotel.length) 
				posicionFinal = vectorHoteles.hotel.length;
			//Pintamos los elementos en la tabla

			for (i=posicionInicial; i< posicionFinal; i++)
			{
				
				nuevaFila(tablaHoteles,vectorHoteles.hotel[i], i);
			}			
			
			//Obtenemos el número de páginas total y pintamos el paginador
			if ((vectorHoteles.hotel.length % elementosXPagina ) == 0)
			{
				numeroTotalPaginas = (vectorHoteles.hotel.length / elementosXPagina) ;
			} else {
				numeroTotalPaginas = ((vectorHoteles.hotel.length - (vectorHoteles.hotel.length % elementosXPagina)) /elementosXPagina)  + 1;
			}
			
			incluirFilaPaginacion(tablaHoteles, numeroTotalPaginas, paginaActual);
		
		}				
}

function limpiarFilas (tabla){
	
	while(tabla.rows.length > 1)       
		tabla.deleteRow(tabla.rows.length-1); 			
}

function nuevaFila (tabla, nuevoHotel, indexHotel){
	
	var precio;
	var hotel = tabla.insertRow(-1);
	
	var celdaHoteles = hotel.insertCell(0)
	var celdaCategoria = hotel.insertCell(1)
	var celdaPrecio = hotel.insertCell(2)
	
	celdaHoteles.innerHTML = "<h4><a href='javascript:verHotel(\"" + nuevoHotel.codigo + "\")'>" + nuevoHotel.nombre + "</a></h4>" + nuevoHotel.direccion + " · <a href='javascript:seleccionarHotelMapa(" + indexHotel + ")'>Ver en Mapa</a>";
	
	var estrellas = generarEstrellas(nuevoHotel.categoria,nuevoHotel.imagenCategoria);
			
	celdaCategoria.innerHTML =  estrellas;
	
	//Para mostrar los precio de los hoteles bajo demanda, la condición ha de ser
	// if (nuevoHotel.demanda == 1 && !(nuevoHotel.precio > 0)) {
	if (nuevoHotel.demanda == 1) {
		celdaPrecio.innerHTML =  "Consultar";	
	} else {
		celdaPrecio.innerHTML =  String(nuevoHotel.precio).replace(".",",") + " &euro;";	
	}
//		celdaPrecio.innerHTML = " Demanda (Nueva Fila): " + nuevoHotel.demanda;
	
	
	celdaPrecio.className = "celdaPrecio"
}


function incluirFilaPaginacion (tabla, numeroPaginas, paginaActiva){
	
	var paginador = tabla.insertRow(-1);
	var celdaPaginacion = paginador.insertCell(0)
	celdaPaginacion.colSpan = 3;
	celdaPaginacion.className = "celdaPaginacion"
	
	for (i=0; i<numeroPaginas;i++)
	{
		if (i!=paginaActiva) {
			celdaPaginacion.innerHTML += "<a href='javascript:actualizarTablaHoteles(" + i + ")'>" + (i + 1) + "</a> "
		} else{
			celdaPaginacion.innerHTML += "<span class='numeroActual'>" + (i + 1) + "</span> "
		}
			
	}
		
}

function restablecerFlechas(){
	
	document.getElementById("nombreA").src = "images/flechaArribaG.gif"
	document.getElementById("categoriaA").src = "images/flechaArribaG.gif"
	document.getElementById("precioA").src = "images/flechaArribaG.gif"
	document.getElementById("nombreD").src = "images/flechaAbajoG.gif"
	document.getElementById("categoriaD").src = "images/flechaAbajoG.gif"
	document.getElementById("precioD").src = "images/flechaAbajoG.gif"
	
	}

function reordenarTabla(campo, tipo) {
	
	restablecerFlechas();
	
	if (tipo == 'A') {
			document.getElementById(campo + tipo).src = "images/flechaArriba.gif"
		} else {
			document.getElementById(campo + tipo).src = "images/flechaAbajo.gif"
		}
		
	vectorHoteles.ordenar(campo,tipo);
	actualizarTablaHoteles(0);
			
	}
	
function reordenarLista(campo, tipo) {
	vectorHoteles.ordenar(campo,tipo);
	actualizarListadoHoteles(0);
}

function generarEstrellas(categoria,nombreImagen) {
	var estrellas = "";
	var unidades;
	
	unidades = String(categoria).substr(String(categoria).length-1,1);
	
	if(parseInt(categoria) > 110 && parseInt(categoria) < 120){
		estrellas = "<div id=\"categoria\">" + unidades + " Cat.</div>";
	}else{
		if(nombreImagen == "") return estrellas;
		//var numeroEstrellas = categoria %10;
		for (var i = 0; i < unidades; i++) { 		
			estrellas += "<img src=\"images\/" + nombreImagen + "\" class=\"estrella\"/>"								
		}
	}
	return estrellas;
}

function lanzarBusqueda(){
		var hoteles;
		var precioMinimo = 50000;			
		var precioMaximo = 20;
	
		informarNumeroHotelesEncontrados(-1);
		
		//Limpiamos primero los posibles puntos que haya en el mapa
		limpiarHotelesActuales();		
		restablecerFlechas();
		
		//limpiarDivPaginacion(document.getElementById('paginador'))
		//Aqui lanzaríamos la búsqueda con los parámetros necesarios	
		var URLAjax = "ajaxHoteles.aspx"
		if (parametrosBusqueda != "") {
			URLAjax += "?"  + parametrosBusqueda;
			}	
		//prompt("",URLAjax);
		GDownloadUrl(URLAjax, function (doc) { 
										
		
        var xmlDoc = GXml.parse(doc);			
        if(xmlDoc.documentElement){
        	hoteles = xmlDoc.documentElement.getElementsByTagName("HOTEL"); 
			//var innerXML = "";
			//alert(hoteles.length + " Hoteles");
			//var atributo;
			vectorHoteles = new objetoHoteles();
			for (var i = 0; i < hoteles.length; i++) 
				{
					//innerXML += "<HOTEL ";
					//for(var j = 0;j < hoteles[i].attributes.length; j++){
						//atributo = hoteles[i].attributes[i];
						//innerXML += " " + atributo.name.toUpperCase() + "=\"" + atributo.value.toUpperCase() + "\"";
					//}
					//innerXML += "/>";
					window.status = " " + parseFloat((100*i)/hoteles.length).toFixed(0) + " %";
					incluirHotel(hoteles[i]);							
					var precioHotel = parseFloat(hoteles[i].getAttribute("PRECIODESDEIVA").replace(",", "."));
					if (precioHotel != 0) {
						if (precioHotel < precioMinimo) precioMinimo = precioHotel;
						if (precioHotel > precioMaximo) precioMaximo = precioHotel;
					}
				}
			//prompt("",innerXML);
			//En este punto debemos pintar el punto de interés seleccionado, si es que lo hay
			var comboPuntos = document.getElementById('selectPDI');
			if (comboPuntos.value != '0,0')
			{
				pintarPuntoInteres(comboPuntos.value) //Crear esta funcion
			}
		}else{
			hoteles = new Array();
		}
		informarNumeroHotelesEncontrados(hoteles.length);
		if (hoteles.length == 0){
			inicializarSlider(precioMinimoDefecto,precioMaximoDefecto);
		} else {
			precioMaximo = precioMaximo + (precioMaximo / 50);
			precioMinimo = precioMinimo - (precioMinimo / 50);
			actualizarTablaHoteles(0);
			inicializarSlider(precioMinimo,precioMaximo);
			
			hacerZoomAZona(0);
		}
		});
	}
	
	function pintarPuntoInteres(latLong){
	
	punto = new GMarker(new GLatLng(latLong.split(",")[0],latLong.split(",")[1]), iconoAmarillo);										
	mapa.addOverlay(punto);
	
	}
	
	function recargarConsulta(){

	sacarTiposAlojamiento();
	
	var categoria;	
	var servicios = "";	
	var latLng = document.getElementById("selectPDI").value;	
		
	var radioButtons = document.getElementsByName("categoria");
    for (var x = 0; x < radioButtons.length; x ++) {
		if (radioButtons[x].checked) 
			{
			categoria = radioButtons[x].value;
			}
		}
		
	var checkButtons = document.getElementsByName("servicios");		
    for (var x = 0; x < checkButtons.length; x ++) {
		if (checkButtons[x].checked) 
			{
			servicios += checkButtons[x].value + ',';
			}
		}	
	  		
	parametrosBusqueda = "";		
	parametrosBusqueda += "PASO1_CATEGORIA=" + categoria;	
	
	parametrosBusqueda += "&PASO1_PRECIOMINIMO=" + document.getElementById("precioMinimo").value;	
	parametrosBusqueda += "&PASO1_PRECIOMAXIMO=" + document.getElementById("precioMaximo").value;	
	
	parametrosBusqueda += "&PASO1_FECHADESDE=" + document.getElementById("PASO1_FECHADESDE").value;	
	parametrosBusqueda += "&PASO1_FECHAHASTA=" + document.getElementById("PASO1_FECHAHASTA").value;	
	parametrosBusqueda += "&PASO1_NUMHABITACIONES=" + document.getElementById("PASO1_NUMHABITACIONES").value;
	
	parametrosBusqueda += "&PASO1_numAdultos_1=" + document.getElementById("PASO1_numAdultos_1").value;
	parametrosBusqueda += "&PASO1_numAdultos_2=" + document.getElementById("PASO1_numAdultos_2").value;
	parametrosBusqueda += "&PASO1_numAdultos_3=" + document.getElementById("PASO1_numAdultos_3").value;
	parametrosBusqueda += "&PASO1_numAdultos_4=" + document.getElementById("PASO1_numAdultos_4").value;
	parametrosBusqueda += "&PASO1_numAdultos_5=" + document.getElementById("PASO1_numAdultos_5").value;	
	
	parametrosBusqueda += "&PASO1_numNinos_1=" + document.getElementById("PASO1_numNinos_1").value;
	parametrosBusqueda += "&PASO1_numNinos_2=" + document.getElementById("PASO1_numNinos_2").value;
	parametrosBusqueda += "&PASO1_numNinos_3=" + document.getElementById("PASO1_numNinos_3").value;
	parametrosBusqueda += "&PASO1_numNinos_4=" + document.getElementById("PASO1_numNinos_4").value;
	parametrosBusqueda += "&PASO1_numNinos_5=" + document.getElementById("PASO1_numNinos_5").value;
	
	
	parametrosBusqueda += "&PASO1_NOCHES=" + document.getElementById("PASO1_NOCHES").value;	
	
	parametrosBusqueda += "&PASO1_TAG=" + document.getElementById("PASO1_TAG").value;	

	if(document.getElementById("PASO1_TIPOESTABLECIMIENTO")) parametrosBusqueda += "&PASO1_TIPOESTABLECIMIENTO=" + document.getElementById("PASO1_TIPOESTABLECIMIENTO").value;	

	parametrosBusqueda += "&TIPOBUSQUEDA=" + document.getElementById("tipoBusqueda").value;	
	
	if (servicios != "")
	{
		servicios = servicios.substring(0, servicios.length - 1);
		parametrosBusqueda += "&PASO1_SERVICIOS=" + servicios;	
	}
	
	if (latLng != "0,0")
	{
		parametrosBusqueda += "&PASO1_GEOLATITUD=" + latLng.split(",")[0].replace(".",",");	
		parametrosBusqueda += "&PASO1_GEOLONGITUD=" + latLng.split(",")[1].replace(".",",");	
		parametrosBusqueda += "&PASO1_GEODISTANCIA=" + document.getElementById("distancia").value;	
		parametrosBusqueda += "&PASO1_GEOFACTORDISTANCIA=0,011";	
		
	}	

	lanzarBusqueda();		
	}
			
	function incluirHotelAVector(nodoHotel){
	
		var lat = parseFloat(nodoHotel.getAttribute("lat")); 
		var lng = parseFloat(nodoHotel.getAttribute("lng")); 
		var nombre = nodoHotel.getAttribute("nombre"); 
		var direccion = nodoHotel.getAttribute("direccion"); 
		var categoria = parseInt(nodoHotel.getAttribute("categoria")); 
		var precioMinimo = nodoHotel.getAttribute("precioMinimo"); 
		var descripcion = nodoHotel.getAttribute("descripcion"); 
		var codigo = nodoHotel.getAttribute("codigo"); 
		var videoYouTube = nodoHotel.getAttribute("videoYouTube"); 
		var videoYouTube2 = nodoHotel.getAttribute("videoYouTube2"); 
		var imagenMiniatura = nodoHotel.getAttribute("imagen"); 
		var demandaAux = nodoHotel.getAttribute("imagen"); 
		var tipoEstablecimiento = nodoHotel.getAttribute("tipoEstablecimiento");
		var tooltip="";
		
		vectorHoteles.nuevoHotel(codigo,nombre,direccion,categoria,precioMinimo,'',descripcion,imagenMiniatura,demandaAux,tipoEstablecimiento,lat,lng,tooltip);
	
	}

	function informarNumeroHotelesEncontrados (numero){
		var numeroHoteles = document.getElementById("numeroHotelesEncontrados");
		var capaHoteles = document.getElementById('capaSinResultados');
		var tablaHoteles = document.getElementById('tablaHoteles');	
		
		if (numero > 0 ){
				numeroHoteles.innerHTML = numero + ' ' + textoEncontrado;
				capaHoteles.style.display = "none";
				tablaHoteles.style.display = "";
			} else 				
			if (numero == -1){
				numeroHoteles.innerHTML = textoBuscando;
				capaHoteles.style.display = "";
				tablaHoteles.style.display = "none";
				capaHoteles.innerHTML = "<br/><br/><br/><br/><div align='center'><img src='images/loading.gif'/><p>&nbsp;</p><p>" + textoBusquedaAJAX + "</p></div>"
			} else 
			
			{
				numeroHoteles.innerHTML = textoNoEncontrado;
				capaHoteles.style.display = "";
				tablaHoteles.style.display = "none";
				capaHoteles.innerHTML = "<br/><br/><br/><br/><br/><br/><br/><div align='center'>" + textoNoEncontrado + "</div>"
				}	 	
		}
		
	function sacarTiposAlojamiento() {	
	var marcador = '';
	var checkboxes = document.getElementsByName('tipoEstablecimiento');     
	for (var i = 0; i < checkboxes.length; i++)    {     
		if (checkboxes[i].checked)
		{
			marcador += checkboxes[i].value;
			}		
	} 
	document.getElementById("PASO1_TIPOESTABLECIMIENTO").value = marcador;
	}
