// Este codigo es propiedad de Media Bit SL y MuchoViaje.com
// No debe ser utilizado sin autorizacion
// En caso contrario los elementos seran invocados
// y las siete plagas de egipto retornaran para
// acabar con tu miserable existencia!
// version 2

//ktes
rutaImagenes = "http://www.hotelius.com/GeoXmlSrvcwww/imagenes/";
rutaWS = "http://reservations.hotelius.fr/GeoXmlSrvcwww/xml.aspx";

//mapa
var map;
var ZOOM; //valor dentro de cada metodo

//arrays de marcas y su html
var colMarcas = new Array();
var colMarcasHtml = new Array();
var idMarca;
var contLinks;
var maxLinks;



//tipos de iconos
var icoAeropuerto = new GIcon();
	icoAeropuerto.image = rutaImagenes + "gaero_peq.png";
	icoAeropuerto.shadow = rutaImagenes + "gsombra_peq.png";
	icoAeropuerto.iconSize = new GSize(24, 31);
	icoAeropuerto.shadowSize = new GSize(38, 31);
	icoAeropuerto.iconAnchor = new GPoint(1, 31);
	icoAeropuerto.infoWindowAnchor = new GPoint(22, 15);

var icoDistrito = new GIcon();
	icoDistrito.image = rutaImagenes + "gdistrito_peq.png";
	icoDistrito.shadow = rutaImagenes + "gsombra_peq.png";
	icoDistrito.iconSize = new GSize(24, 31);
	icoDistrito.shadowSize = new GSize(38, 31);
	icoDistrito.iconAnchor = new GPoint(1, 31);
	icoDistrito.infoWindowAnchor = new GPoint(22, 15);

var icoTrenBus = new GIcon();
	icoTrenBus.image = rutaImagenes + "gbustren_peq.png";
	icoTrenBus.shadow = rutaImagenes + "gsombra_peq.png";
	icoTrenBus.iconSize = new GSize(24, 31);
	icoTrenBus.shadowSize = new GSize(38, 31);
	icoTrenBus.iconAnchor = new GPoint(1, 31);
	icoTrenBus.infoWindowAnchor = new GPoint(22, 15);

var icoMuseo = new GIcon();
	icoMuseo.image = rutaImagenes + "gmuseo_peq.png";
	icoMuseo.shadow = rutaImagenes + "gsombra_peq.png";
	icoMuseo.iconSize = new GSize(24, 31);
	icoMuseo.shadowSize = new GSize(38, 31);
	icoMuseo.iconAnchor = new GPoint(1, 31);
	icoMuseo.infoWindowAnchor = new GPoint(22, 15);

var icoOtros = new GIcon();
	icoOtros.image = rutaImagenes + "gotra_peq.png";
	icoOtros.shadow = rutaImagenes + "gsombra_peq.png";
	icoOtros.iconSize = new GSize(24, 31);
	icoOtros.shadowSize = new GSize(38, 31);
	icoOtros.iconAnchor = new GPoint(1, 31);
	icoOtros.infoWindowAnchor = new GPoint(22, 15);

var icoPlaza = new GIcon();
	icoPlaza.image = rutaImagenes + "gcalle_peq.png";
	icoPlaza.shadow = rutaImagenes + "gsombra_peq.png";
	icoPlaza.iconSize = new GSize(24, 31);
	icoPlaza.shadowSize = new GSize(38, 31);
	icoPlaza.iconAnchor = new GPoint(1, 31);
	icoPlaza.infoWindowAnchor = new GPoint(22, 15);

var icoRecinto = new GIcon();
	icoRecinto.image = rutaImagenes + "grecinto_peq.png";
	icoRecinto.shadow = rutaImagenes + "gsombra_peq.png";
	icoRecinto.iconSize = new GSize(24, 31);
	icoRecinto.shadowSize = new GSize(38, 31);
	icoRecinto.iconAnchor = new GPoint(1, 31);
	icoRecinto.infoWindowAnchor = new GPoint(22, 15);
	
var icoSki = new GIcon();
	icoSki.image = rutaImagenes + "gski_peq.png";
	icoSki.shadow = rutaImagenes + "gsombra_peq.png";
	icoSki.iconSize = new GSize(24, 31);
	icoSki.shadowSize = new GSize(38, 31);
	icoSki.iconAnchor = new GPoint(1, 31);
	icoSki.infoWindowAnchor = new GPoint(22, 15);

var icoTeatro = new GIcon();
	icoTeatro.image = rutaImagenes + "gteatro_peq.png";
	icoTeatro.shadow = rutaImagenes + "gsombra_peq.png";
	icoTeatro.iconSize = new GSize(24, 31);
	icoTeatro.shadowSize = new GSize(38, 31);
	icoTeatro.iconAnchor = new GPoint(1, 31);
	icoTeatro.infoWindowAnchor = new GPoint(22, 15);

var icoTurismo = new GIcon();
	icoTurismo.image = rutaImagenes + "gturismo_peq.png";
	icoTurismo.shadow = rutaImagenes + "gsombra_peq.png";
	icoTurismo.iconSize = new GSize(24, 31);
	icoTurismo.shadowSize = new GSize(38, 31);
	icoTurismo.iconAnchor = new GPoint(1, 31);
	icoTurismo.infoWindowAnchor = new GPoint(22, 15);

var icoHotel = new GIcon();
	icoHotel.image = rutaImagenes + "ghotel_peq.png";
	icoHotel.shadow = rutaImagenes + "gsombra_peq.png";
	icoHotel.iconSize = new GSize(24, 31);
	icoHotel.shadowSize = new GSize(38, 31);
	icoHotel.iconAnchor = new GPoint(1, 31);
	icoHotel.infoWindowAnchor = new GPoint(22, 15);

var icoGeneral = new GIcon();
	icoGeneral.image = rutaImagenes + "gotra_peq.png";
	icoGeneral.shadow = rutaImagenes + "gsombra_peq.png";
	icoGeneral.iconSize = new GSize(24, 31);
	icoGeneral.shadowSize = new GSize(38, 31);
	icoGeneral.iconAnchor = new GPoint(1, 31);
	icoGeneral.infoWindowAnchor = new GPoint(22, 15);

//tipos de iconos resaltados
var icoAeropuertoRes = new GIcon();
	icoAeropuertoRes.image = rutaImagenes + "gaero_peq_res.png";
	icoAeropuertoRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoAeropuertoRes.iconSize = new GSize(24, 31);
	icoAeropuertoRes.shadowSize = new GSize(38, 31);
	icoAeropuertoRes.iconAnchor = new GPoint(1, 31);
	icoAeropuertoRes.infoWindowAnchor = new GPoint(22, 15);

var icoDistritoRes = new GIcon();
	icoDistritoRes.image = rutaImagenes + "gdistrito_peq_res.png";
	icoDistritoRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoDistritoRes.iconSize = new GSize(24, 31);
	icoDistritoRes.shadowSize = new GSize(38, 31);
	icoDistritoRes.iconAnchor = new GPoint(1, 31);
	icoDistritoRes.infoWindowAnchor = new GPoint(22, 15);

var icoTrenBusRes = new GIcon();
	icoTrenBusRes.image = rutaImagenes + "gbustren_peq_res.png";
	icoTrenBusRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoTrenBusRes.iconSize = new GSize(24, 31);
	icoTrenBusRes.shadowSize = new GSize(38, 31);
	icoTrenBusRes.iconAnchor = new GPoint(1, 31);
	icoTrenBusRes.infoWindowAnchor = new GPoint(22, 15);

var icoMuseoRes = new GIcon();
	icoMuseoRes.image = rutaImagenes + "gmuseo_peq_res.png";
	icoMuseoRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoMuseoRes.iconSize = new GSize(24, 31);
	icoMuseoRes.shadowSize = new GSize(38, 31);
	icoMuseoRes.iconAnchor = new GPoint(1, 31);
	icoMuseoRes.infoWindowAnchor = new GPoint(22, 15);

var icoOtrosRes = new GIcon();
	icoOtrosRes.image = rutaImagenes + "gotra_peq_res.png";
	icoOtrosRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoOtrosRes.iconSize = new GSize(24, 31);
	icoOtrosRes.shadowSize = new GSize(38, 31);
	icoOtrosRes.iconAnchor = new GPoint(1, 31);
	icoOtrosRes.infoWindowAnchor = new GPoint(22, 15);

var icoPlazaRes = new GIcon();
	icoPlazaRes.image = rutaImagenes + "gcalle_peq_res.png";
	icoPlazaRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoPlazaRes.iconSize = new GSize(24, 31);
	icoPlazaRes.shadowSize = new GSize(38, 31);
	icoPlazaRes.iconAnchor = new GPoint(1, 31);
	icoPlazaRes.infoWindowAnchor = new GPoint(22, 15);

var icoRecintoRes = new GIcon();
	icoRecintoRes.image = rutaImagenes + "grecinto_peq_res.png";
	icoRecintoRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoRecintoRes.iconSize = new GSize(24, 31);
	icoRecintoRes.shadowSize = new GSize(38, 31);
	icoRecintoRes.iconAnchor = new GPoint(1, 31);
	icoRecintoRes.infoWindowAnchor = new GPoint(22, 15);
	
var icoSkiRes = new GIcon();
	icoSkiRes.image = rutaImagenes + "gski_peq_res.png";
	icoSkiRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoSkiRes.iconSize = new GSize(24, 31);
	icoSkiRes.shadowSize = new GSize(38, 31);
	icoSkiRes.iconAnchor = new GPoint(1, 31);
	icoSkiRes.infoWindowAnchor = new GPoint(22, 15);

var icoTeatroRes = new GIcon();
	icoTeatroRes.image = rutaImagenes + "gteatro_peq_res.png";
	icoTeatroRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoTeatroRes.iconSize = new GSize(24, 31);
	icoTeatroRes.shadowSize = new GSize(38, 31);
	icoTeatroRes.iconAnchor = new GPoint(1, 31);
	icoTeatroRes.infoWindowAnchor = new GPoint(22, 15);

var icoTurismoRes = new GIcon();
	icoTurismoRes.image = rutaImagenes + "gturismo_peq_res.png";
	icoTurismoRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoTurismoRes.iconSize = new GSize(24, 31);
	icoTurismoRes.shadowSize = new GSize(38, 31);
	icoTurismoRes.iconAnchor = new GPoint(1, 31);
	icoTurismoRes.infoWindowAnchor = new GPoint(22, 15);

var icoHotelRes = new GIcon();
	icoHotelRes.image = rutaImagenes + "ghotel_peq_res.png";
	icoHotelRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoHotelRes.iconSize = new GSize(24, 31);
	icoHotelRes.shadowSize = new GSize(38, 31);
	icoHotelRes.iconAnchor = new GPoint(1, 31);
	icoHotelRes.infoWindowAnchor = new GPoint(22, 15);

var icoGeneralRes = new GIcon();
	icoGeneralRes.image = rutaImagenes + "gotra_peq_res.png";
	icoGeneralRes.shadow = rutaImagenes + "gsombra_peq.png";
	icoGeneralRes.iconSize = new GSize(24, 31);
	icoGeneralRes.shadowSize = new GSize(38, 31);
	icoGeneralRes.iconAnchor = new GPoint(1, 31);
	icoGeneralRes.infoWindowAnchor = new GPoint(22, 15);



function irMarca(id)
	{if (id!='') colMarcas[id].openInfoWindowHtml(colMarcasHtml[id])}
//irMarca



function crearMarca(point, html) 
{
	var marca = new GMarker(point);
	GEvent.addListener(marca, 
			   "click", 
			   function() {marca.openInfoWindowHtml(html)}
			  );
	return marca;
}//crearMarca()



function crearMarca(point, html, tipo) 
{
	var icono;
	switch(tipo){
		case "aeropuerto":
			icono = icoAeropuerto;
			break;
		case "aeropuertoRes":
			icono = icoAeropuertoRes;
			break;
		case "distrito":
			icono = icoDistrito;
			break;
		case "distritoRes":
			icono = icoDistritoRes;
			break;
		case "esttrenbus":
			icono = icoTrenBus;
			break;
		case "esttrenbusRes":
			icono = icoTrenBusRes;
			break;
		case "museo":
			icono = icoMuseo;
			break;
		case "museoRes":
			icono = icoMuseoRes;
			break;
		case "otros":
			icono = icoOtros;
			break;			
		case "otrosRes":
			icono = icoOtrosRes;
			break;			
		case "hotel":
			icono = icoHotel;
			break;
		case "hotelRes":
			icono = icoHotelRes;
			break;
		case "plaza":
			icono = icoPlaza;
			break;
		case "plazaRes":
			icono = icoPlazaRes;
			break;
		case "recinto":
			icono = icoRecinto;
			break;
		case "recintoRes":
			icono = icoRecintoRes;
			break;
		case "ski":
			icono = icoSki;
			break;
		case "skiRes":
			icono = icoSkiRes;
			break;
		case "teatro":
			icono = icoTeatro;
			break;
		case "teatroRes":
			icono = icoTeatroRes;
			break;
		case "turismo":
			icono = icoTurismo;
			break;
		case "turismoRes":
			icono = icoTurismoRes;
			break;
		default:
			icono = icoGeneral;
			break;
	}//switch

	var marca = new GMarker(point, icono);
	GEvent.addListener(marca, 
			   "click",
			   function(){marca.openInfoWindowHtml(html)}
			  );
	return marca;
}//crearMarca()



function _crearMapa(tipoMapa, urlXML, tipoPuntoRes, codPuntoRes){
	if (GBrowserIsCompatible()){
		ZOOM = 14;
		colMarcas = new Array();
		colMarcasHtml = new Array();
		contLinks = 0;
		maxLinks = 25;

		//tags xml		
		var lat, lng, tipo, cod, tit, cat, dir, dsc, foto, linkUrl, linkTxt;
		
		//html
		var html, titH, fotoH;
		var htmlLinks = "";
		var htmlLinks2 = "<select class='enlace' onChange='javascript:irMarca(this.value)'><option value=''>Seleccione...</option>";
		var htmlLinks3 = "<select class='enlace' onChange='javascript:irMarca(this.value)'><option value=''>Seleccione...</option>";
		var idMarcaMostrar = '0';

		//lectura del xml
      	var request = GXmlHttp.create();
      	request.open("GET", urlXML, true);
      	request.onreadystatechange = function(){
	        if (request.readyState == 4){
	          	var xmlDoc = request.responseXML;
	          	var marcas = xmlDoc.documentElement.getElementsByTagName("row");
	          	
				//mapa: crear y posicionar en la primera marca
	          	if (marcas.length>0){
	          		map = new GMap2(document.getElementById("mapa"));
					map.addControl(new GSmallMapControl());
					map.addControl(new GMapTypeControl());

	             	lat = parseFloat(marcas[0].getAttribute("lat"));
	            	lng = parseFloat(marcas[0].getAttribute("lng"));
	          		map.setCenter(new GLatLng(lat, lng), ZOOM);

					switch(tipoMapa){
						case 2:
							map.setMapType(G_SATELLITE_MAP);
						break;
						case 3:
							map.setMapType(G_HYBRID_MAP);
						break;
					}//switch
				}
				else{//no hay marcas, no hay mapa:
					document.getElementById("mapa").innerHTML = "<span class=descripcion>Mapa no disponible.</span>";
	          	}//if
						          	
	          	//marcas: recorrer marcas del xml y posicionarlas
	          	for (var i = 0; i < marcas.length; i++){
	            	lat = parseFloat(marcas[i].getAttribute("lat"));
	            	lng = parseFloat(marcas[i].getAttribute("lng"));
	            	tipo = marcas[i].getAttribute("tipo").toLowerCase();
	            	cod = marcas[i].getAttribute("cod");
	            	tit = marcas[i].getAttribute("tit");
	            	cat = marcas[i].getAttribute("cat");
	            	dir = marcas[i].getAttribute("dir");
	            	dsc = marcas[i].getAttribute("dsc");
	            	foto = marcas[i].getAttribute("foto");
	            	linkUrl = marcas[i].getAttribute("lnkUrl");
	            	linkTxt = marcas[i].getAttribute("lnkTxt");
	            	destacado = marcas[i].getAttribute("destacado");

					//montar ficha
					if (tit!="") titH = "<span class=titulo>" + tit + "</span>"
					if (cat!="") cat = "&nbsp;<img src='http://hoteles.hotelius.com/Hoteles/Images/comun/Star" + cat + ".gif'>";
					if (dir!="") dir = "<br><span class=descripcion>" + dir + "<br><br></span>";
					if (dsc!="") dsc = "<span class=descripcion>" + dsc + "<br><br></span>";
					if (foto!=""){	
						fotoH = foto.substr(0,foto.lastIndexOf("/"));
		            			fotoH += "/peq_" + foto.substr(foto.lastIndexOf("/")+1);
		            			fotoH = "<img height=75 src='" + fotoH + "'>";
		            }
					if (linkUrl!="") linkUrl = "<a href='" + linkUrl + "' class='enlace'>" + linkTxt + "</a>";

					if (foto!="") 
		            	html = 	titH + cat + dir +
		            		"<table width=400><tr><td valign=top align=center width=100px>" + fotoH + "</td>" + 
            				"<td valign=top width=300px>" + dsc + linkUrl + "</td></tr></table>";
					else
		            	html = 	"<table width=400><tr><td>" + titH + cat + dir + dsc + linkUrl + "</td></tr></table>";
					//montar ficha/fin
	            	
					//links
					if (contLinks < maxLinks && destacado=="1"){
	    				htmlLinks += "<a href=javascript:irMarca('" + i + "'); class='enlace'>" + tit + "</a><br>";
	    				contLinks++;
	    			}
					if (tipo=="hotel")
    					htmlLinks2 += "<option value='" + i +"'>" + tit + "</option>";
    				else
    					htmlLinks3 += "<option value='" + i +"'>" + tit + "</option>";
    				//links/fin
	            			
	            	//crear/resaltar/guardar marca
	            	if (tipoPuntoRes=="1ero" && i==0) tipo += "Res";
	            	else if (tipo==tipoPuntoRes) tipo += "Res";
	            	else if (codPuntoRes!="" && codPuntoRes==cod) {
	            		tipo += "Res";
	            		idMarcaMostrar = i;
	            	}
	            	var point = new GLatLng(lat,lng);
	            	var marca = crearMarca(point, html, tipo);
	            	map.addOverlay(marca);
	    			
    				colMarcasHtml[i] = html;
    				colMarcas[i] = marca;
    				//crear/resaltar/guardar marca/fin
	          	}//for
		        
	          	//terminar/pegar links
				htmlLinks2 += "</select>"
				htmlLinks3 += "</select>"
	          	if (document.getElementById("links")!= null) document.getElementById("links").innerHTML = htmlLinks;
		        if (document.getElementById("links2")!= null) document.getElementById("links2").innerHTML = htmlLinks2;
		        if (document.getElementById("links3")!= null) document.getElementById("links3").innerHTML = htmlLinks3;
		        //terminar/pegar links/fin

		        //mostrar marca
		        if (marcas.length>0) irMarca(idMarcaMostrar);
	        }//readyState
      	}//lectura xml
      	request.send(null);
	}//GBrowserIsCompatible
}//_crearMapa()



function mapaHotel(tipoMapa, codHotel)
	{_crearMapa(tipoMapa, rutaWS + "?map=hyp&cod=" + codHotel, "hotel", "");}

function mapaHotelyPOI(tipoMapa, codHotel, codPunto)
	{_crearMapa(tipoMapa, rutaWS + "?map=hyp&cod=" + codHotel, "hotel", codPunto);}

function mapaHotelesDestino(tipoMapa, codDestino)
	{_crearMapa(tipoMapa, rutaWS + "?map=dhyp&cod=" + codDestino, "hotel", "");}
	
function mapaPOIyHoteles(tipoMapa, codPoi)
	{_crearMapa(tipoMapa, rutaWS + "?map=pyh&cod=" + codPoi, "1ero", "");}

function mapaHotelIdioma(tipoMapa, codHotel, idioma)
	{_crearMapa(tipoMapa, rutaWS + "?map=hIyp&cod=" + codHotel + "&idi=" + idioma, "hotel", "");}
