var map=null;function doReplaceExp(d,a,b){var c=new RegExp(d,"g");return b.replace(c,a)}function crearBotonReset(c,e,f,b){var d=document.getElementById("btnsT");var a=document.createElement("a");a.setAttribute("href","javascript:recenterMap("+c+", "+e+", "+f+")");a.setAttribute("id","btnReset");if(b=="esp"){a.innerHTML="Restaurar Mapa"}else{a.innerHTML="Reset Map"}d.appendChild(a)}function crearMapa(a,b,e,c){map=new GMap2(document.getElementById(c));map.setCenter(new GLatLng(a,b),e);map.addControl(new GLargeMapControl());map.addControl(new PanoMapTypeControl());map.addMapType(G_PHYSICAL_MAP);map.setMapType(G_HYBRID_MAP);map.disableDoubleClickZoom();map.clearOverlays()}function crearLoadingDest(b){var a=document.getElementById(b);var c=document.createElement("div");c.setAttribute("id","loading");a.appendChild(c)}function crearLoadingHotel(c){var b=document.getElementById(c);var a=document.createElement("div");a.setAttribute("id","loading_h");b.appendChild(a)}function crearLoadingTour(c){var b=document.getElementById(c);var a=document.createElement("div");a.setAttribute("id","loading_t");b.appendChild(a)}function moveendBounds(l,o,e,c,h,g,f,j){var a=map.getBounds();var b=a.getSouthWest();var d=a.getNorthEast();var k=d.lat();var n=b.lat();var i=d.lng();var m=b.lng();if(c){obtener_destinos_bound(n,m,k,i,f,e,j)}if(o){obtener_hoteles_bound(n,m,k,i,f,l,j)}if(g){obtener_tours_bound(n,m,k,i,f,h,j)}}function recenterMap(a,b,c){if(a!=0){map.setMapType(G_HYBRID_MAP);map.setCenter(new GLatLng(a,b),c)}}function obtenerZoomBound(b,e,a,c){var d=new GLatLngBounds();d.extend(new GLatLng(b,e));d.extend(new GLatLng(a,c));return map.getBoundsZoomLevel(d)}function mostrar_hoteles(d,b,c){var a=location.pathname.split("/");base_url="http://"+location.host+"/"+a[1]+"/"+a[2];var e=a[1];if(GBrowserIsCompatible()){new Ajax("/mapas/obtener_hoteles.php?hoteles="+d+"&id_pais="+c,{method:"get",encoding:"ISO-8859-1",onSuccess:function(){var f=Json.evaluate(this.response.text);extend=f.extend;crearMapa(extend.x,extend.y,15,b);var g=obtenerZoomBound(extend.xmin,extend.ymin,extend.xmax,extend.ymax);if(g>15){g=15}crearBotonReset(extend.x,extend.y,g,e);recenterMap(extend.x,extend.y,g);f.hoteles.each(function(h){if(h.x!=0){dibujarHotelNumber(h.n,h.x,h.y,h.tt,h.il,e)}});crearLoadingDest(b);crearLoadingHotel(b);crearLoadingTour(b);moveendBounds(d,true,"",true,"",true,e,c);GEvent.bind(map,"moveend",this,function(){moveendBounds(d,true,"",true,"",true,e,c)})}}).request()}else{$(b).setStyle("display","none")}}function infoMarker(b,e,d,c){var a=(d=="esp")?"M&aacute;s Informaci&oacute;n":"More Information";new Ajax("/mapas/obtener_info_hotel.php?id_hotel="+e+"&lang="+d,{method:"get",onSuccess:function(){var f=Json.evaluate(this.response.text);link_=(!c)?'<a class="info_tt" href="'+f.r+'" target="_self">'+a+"</a>":"";if(f.imagen==""){b.openInfoWindowHtml('<div style="margin-right:10px;width:350px;"><span class="nombre_hotel">'+f.n+'</span><br /><hr /><span class="direccion_hotel">'+f.d+'</span><br /><img class="img_tt" src="/images/vc-hot-'+f.e+'star.gif"/><br /><span class="tarifa_tt">&nbsp;</span><br /><span class="hab_tt">&nbsp;</span>'+link_+"</div>")}else{b.openInfoWindowHtml('<div style="margin-right:10px;width:350px;"><img class="img_hotel" height="100" align="left" src="'+f.i+'" /><span class="nombre_hotel">'+f.n+'</span><br /><hr /><span class="direccion_hotel">'+f.d+'</span><br /><img class="img_tt" src="/images/vc-hot-'+f.e+'star.gif"/><br /><span class="tarifa_tt">&nbsp;</span><br /><span class="hab_tt">&nbsp;</span>'+link_+"</div>")}}}).request()}function dibujarHotelNumber(c,b,d,e,g,f){b=Number(b);d=Number(d);var a=new GMarker(new GLatLng(b,d),{icon:getIconNumberHotel(c),draggable:false,title:e});GEvent.addListener(a,"click",function(){infoMarker(a,g,f,false)});map.addOverlay(a)}function getIconNumberHotel(a){var b=new GIcon();b.image="/images/mapas/numbers/darkblue/darkblue"+a+".png";b.shadow="/images/mapas/numbers/s.png";b.iconSize=new GSize(17,19);b.iconAnchor=new GPoint(0,19);b.infoWindowAnchor=new GPoint(8,9);return b}function mostrar_hotel(c,b,d){var a=location.pathname.split("/");base_url="http://"+location.host+"/"+a[1]+"/"+a[2];var e=a[1];if(GBrowserIsCompatible()){new Ajax("/mapas/obtener_hotel.php?hotel="+c+"&lang="+e+"&id_pais="+d,{method:"get",encoding:"ISO-8859-1",onSuccess:function(){var f=Json.evaluate(this.response.text);if(f.x!=0){crearBotonReset(f.x,f.y,14,e);crearMapa(f.x,f.y,14,b);dibujarHotelBound(f.ig,f.x,f.y,c,f.t,true,e);crearLoadingDest(b);crearLoadingHotel(b);crearLoadingTour(b);moveendBounds(c,true,"",true,"",true,e,d);GEvent.bind(map,"moveend",this,function(){moveendBounds(c,true,"",true,"",true,e,d)})}}}).request()}else{$(b).setStyle("display","none")}}var time2=null;var AjaxToursBound=null;var tours_dibujados=new Array();var tours_dibujados_id=new Array();function loadingT(a){$("loading_t").setStyles({visibility:"visible"});if(a=="esp"){$("loading_t").innerHTML='<p style="color:#fff;padding:1px 2px;margin:0"><img src="/images/mapas/loading_t.gif" style="border:0" align="absmiddle" /> Obteniendo Paquetes de Ski</p>'}else{$("loading_t").innerHTML='<p style="color:#fff;padding:1px 2px;margin:0"><img src="/images/mapas/loading_t.gif" align="absmiddle" style="border:0" /> Retrieving Ski Packages</p>'}}function obtener_tours_bound(g,c,b,a,h,f,e){if(AjaxToursBound!=null){AjaxToursBound.cancel()}var d=tours_dibujados_id.join(",");d=doReplaceExp(",+",",",d);d=doReplaceExp("^,","",d);d=doReplaceExp(",$","",d);AjaxToursBound=new Ajax("/mapas/obtener_tours_bound.php?xmin="+g+"&ymin="+c+"&xmax="+b+"&ymax="+a+"&not="+d+"&id_tour="+f+"&id_pais="+e,{method:"get",encoding:"ISO-8859-1",onRequest:function(){time2=setTimeout("loadingT('"+h+"')",500)},onSuccess:function(){clearTimeout(time2);var i=Json.evaluate(this.response.text);var k=i.tours.length;var j=1;i.tours.each(function(l){if(!tours_dibujados[l.ig]){if(l.x!=0){if(l.il!="-1"){if(h=="esp"){$("loading_t").innerHTML="Loading Tours ("+j+"/"+k+")";dibujarDestinoBound(l.ig,l.x,l.y,l.t,l.te,l.il,h,false,l.tp,l.c);j++}else{$("loading_t").innerHTML="Cargando Tours ("+j+"/"+k+")";dibujarDestinoBound(l.ig,l.x,l.y,l.t,l.ti,l.il,h,false,l.tp,l.c);j++}}}}});$("loading_t").setStyles({visibility:"hidden"})}}).request()}var timeO=null;var AjaxDestinosBound=null;var destinos_dibujados=new Array();var destinos_dibujados_id=new Array();var geoms_dibujadas=new Array();var geoms_borrar=new Array();var ajaxDestinoBound=new Array();var destinos_markers=new Array();var ajaxDestinoBoundPoligono=new Array();var ajaxDBound=null;function loadingD(a){$("loading").setStyles({visibility:"visible"});if(a=="esp"){$("loading").innerHTML='<p style="color:#fff;padding:1px 2px;margin:0"><img src="/images/mapas/loading.gif" style="border:0" align="absmiddle" /> Obteniendo Centros de Ski</p>'}else{$("loading").innerHTML='<p style="color:#fff;padding:1px 2px;margin:0"><img src="/images/mapas/loading.gif" align="absmiddle" style="border:0" /> Retrieving Ski Resorts</p>'}}function obtener_destinos_bound(f,c,b,a,h,g,e){if(AjaxDestinosBound!=null){AjaxDestinosBound.cancel()}var d=destinos_dibujados_id.join(",");d=doReplaceExp(",+",",",d);d=doReplaceExp("^,","",d);d=doReplaceExp(",$","",d);AjaxDestinosBound=new Ajax("/mapas/obtener_destinos_bound.php?xmin="+f+"&ymin="+c+"&xmax="+b+"&ymax="+a+"&not="+d+"&id_destino="+g+"&id_pais="+e,{method:"get",encoding:"ISO-8859-1",onRequest:function(){timeO=setTimeout("loadingD('"+h+"')",500)},onSuccess:function(){clearTimeout(timeO);var i=Json.evaluate(this.response.text);var k=i.destinos.length;var j=1;i.destinos.each(function(l){if(!destinos_dibujados[l.ig]){if(l.x!=0){if(l.il!="-1"){if(h=="esp"){$("loading").innerHTML="Loading Destinations ("+j+"/"+k+")";dibujarDestinoBound(l.ig,l.x,l.y,l.t,l.te,l.il,h,true,"P",0);j++}else{$("loading").innerHTML="Cargando Destinos ("+j+"/"+k+")";dibujarDestinoBound(l.ig,l.x,l.y,l.t,l.ti,l.il,h,true,"P",0);j++}}}}});$("loading").setStyles({visibility:"hidden"})}}).request()}function dibujarDestinoBound(l,a,k,i,o,d,b,m,h,j){geoms_borrar[l]=true;if(!m){if(b=="esp"){pre_tt="Paquete de SKI: "}else{pre_tt="SKI Package: "}}else{pre_tt=""}o=pre_tt+o;var f=new GMarker(new GLatLng(a,k),{icon:getIconDestinoBound(m,h,j),draggable:false,title:o});if(i==3||i==2){var e=GEvent.bind(f,"mouseover",this,function(){if(ajaxDestinoBound[l]){geoms_dibujadas[l].show();if(ajaxDestinoBoundPoligono[l]){if(m){geoms_dibujadas[l].setFillStyle({color:"#FF0000",opacity:0.2})}else{switch(h){case"P":geoms_dibujadas[l].setFillStyle({color:"#8800FF",opacity:0.2});break;case"C":geoms_dibujadas[l].setFillStyle({color:"#83C4DF",opacity:0.2});break}}}}else{dibujarPoligonoBound(l,i,m,h)}});var g=GEvent.bind(f,"mouseout",this,function(){if(geoms_borrar[l]){if(ajaxDBound!=null){ajaxDBound.cancel()}try{geoms_dibujadas[l].hide()}catch(p){}}});var n=GEvent.bind(f,"infowindowclose",this,function(){geoms_borrar[l]=true;geoms_dibujadas[l].hide()})}var c=GEvent.bind(f,"click",this,function(){geoms_borrar[l]=false;if(m){link_="destino"}else{link_="tour"}new Ajax("/mapas/obtener_info_"+link_+".php?id_lugar="+d+"&lang="+b+"&circuito="+j,{method:"get",onSuccess:function(){if(b=="esp"){desc_ruta="M&aacute;s Informaci&oacute;n"}else{desc_ruta="More Information"}var p=Json.evaluate(this.response.text);if(m){txtTar=""}else{txtTar='<br /><span class="tarifa_tt">'+p.t+'</span><br /><span class="hab_tt">'+p.h+"</span>"}if(p.foto==""){f.openInfoWindowHtml('<div style="margin-right:10px;width:350px;"><span class="nombre_hotel">'+p.nombre+'</span><br><hr><span class="direccion_hotel">'+p.descripcion+"</span>"+txtTar+'<p align="left" style="margin:2px 0 0 0;" ><a class="info_tt_destino" href="'+p.ruta+'" target="_self">'+desc_ruta+"</a></p></div>")}else{f.openInfoWindowHtml('<div style="margin-right:10px;width:350px;"><img class="img_hotel" height="100" align="left" src="'+p.foto+'" /><span class="nombre_hotel">'+p.nombre+'</span><br><hr><span class="direccion_hotel">'+p.descripcion+"</span>"+txtTar+'<p style="margin:2px 0 0 0;" align="left"><a class="info_tt_destino" href="'+p.ruta+'" target="_self">'+desc_ruta+"</a></p></div>")}}}).request()});map.addOverlay(f);if(m){destinos_dibujados[l]=true;destinos_markers[l]=f;destinos_dibujados_id[l]=l}else{tours_dibujados[l]=true;tours_dibujados_id[l]=l}}function getIconDestinoBound(b,d,a){var c=new GIcon();if(b){c.image="/images/mapas/mini_icon_red.png"}else{switch(d){case"P":switch(a){case 2:c.image="/images/mapas/mini_icon_lblue.png";break;case 3:c.image="/images/mapas/mini_icon_purple.png";break;default:c.image="/images/mapas/mini_icon_purple.png"}break;case"C":c.image="/images/mapas/mini_icon_lblue.png";break}}c.shadow="/images/mapas/shadow.png";c.iconSize=new GSize(12,20);c.shadowSize=new GSize(19,20);c.iconAnchor=new GPoint(6,20);c.infoWindowAnchor=new GPoint(6,20);return c}function destinos_hide(){destinos_markers.each(function(a){a.show()})}function destinos_show(){destinos_markers.each(function(a){a.hide()})}function dibujarPoligonoBound(c,b,a,d){ajaxDBound=new Ajax("/mapas/obtener_geom.php?id_g="+c,{method:"get",encoding:"ISO-8859-1",onRequest:function(){},onSuccess:function(){var k=this.response.text;var e=k.split(",");var j=new Array();var g=0;e.each(function(l){var i=l.split(" ");j[g++]=new GLatLng(i[0],i[1])});if(a){color="#FF0000"}else{switch(d){case"P":color="#8800FF";break;case"C":color="#83C4DF";break;default:color="#FF0000"}}switch(b){case 2:var f=new GPolyline(j,color,5,0.7);var h=false;break;case 3:var f=new GPolygon(j,color,2,0.7,color,0.2);var h=true;break}geoms_dibujadas[c]=f;map.addOverlay(f);ajaxDestinoBound[c]=true;ajaxDestinoBoundPoligono[c]=h;$("loading").setStyles({visibility:"hidden"})}}).request()}var hoteles_dibujados=new Array();var hoteles_dibujados_id=new Array();var AjaxHotelesBound=null;var time1=null;function loadingH(a){$("loading_h").setStyles({visibility:"visible"});if(a=="esp"){$("loading_h").innerHTML='<p style="color:#fff;padding:1px 2px;margin:0"><img src="/images/mapas/loading_h.gif" style="border:0" align="absmiddle" /> Obteniendo Holetes</p>'}else{$("loading_h").innerHTML='<p style="color:#fff;padding:1px 2px;margin:0"><img src="/images/mapas/loading_h.gif" align="absmiddle" style="border:0" /> Retrieving Hotels</p>'}}function obtener_hoteles_bound(g,d,c,a,h,b,f){if(AjaxHotelesBound!=null){AjaxHotelesBound.cancel()}var e=hoteles_dibujados_id.join(",");e=doReplaceExp(",+",",",e);e=doReplaceExp("^,","",e);e=doReplaceExp(",$","",e);new Ajax("/mapas/obtener_hoteles_bound.php?xmin="+g+"&ymin="+d+"&xmax="+c+"&ymax="+a+"&not="+e+"&id_hotel="+b+"&lang="+h+"&id_pais="+f,{method:"get",encoding:"ISO-8859-1",onRequest:function(){time1=setTimeout("loadingH('"+h+"')",500)},onSuccess:function(){clearTimeout(time1);var i=Json.evaluate(this.response.text);var k=i.hoteles.length;var j=1;i.hoteles.each(function(l){if(!hoteles_dibujados[l.ig]){if(l.x!=0){dibujarHotelBound(l.ig,l.x,l.y,l.il,l.tt,false,h);j++}}});$("loading_h").setStyles({visibility:"hidden"})}}).request()}function dibujarHotelBound(c,b,d,h,e,f,g){if(f){var a=new GMarker(new GLatLng(b,d),{icon:getIconHotel(),draggable:false,title:e})}else{var a=new GMarker(new GLatLng(b,d),{icon:getIconHotelBound(),draggable:false,title:e})}GEvent.addListener(a,"click",function(){infoMarker(a,h,g,f)});map.addOverlay(a);hoteles_dibujados_id[c]=c}function getIconHotelBound(){var a=new GIcon();a.image="/images/mapas/numbers/darkblue/h.png";a.shadow="/images/mapas/numbers/s.png";a.iconSize=new GSize(17,19);a.iconAnchor=new GPoint(1,19);a.infoWindowAnchor=new GPoint(1,19);return a}function getIconHotel(){var a=new GIcon();a.image="/images/mapas/pin1.png";a.iconSize=new GSize(32,32);a.iconAnchor=new GPoint(16,31);a.infoWindowAnchor=new GPoint(16,31);return a}function dibujarDestinoFijo(c,k,l,h,a,m,g){if(h!=1){var b=a.split(",");var d=new Array();var f=0;b.each(function(n){var i=n.split(" ");d[f++]=new GLatLng(i[0],i[1])});switch(h){case 2:var j=new GPolyline(d,"#00E13C",6,0.6,{title:m});break;case 3:var j=new GPolygon(d,"#00E13C",2,0.7,"#00E13C",0.2,{title:m});break}map.addOverlay(j)}else{var e=new GMarker(new GLatLng(c,k),{icon:getIconHotel(),draggable:false,title:m});map.addOverlay(e)}}function mostrar_tour(f,b,d,c,e,a){mostrar_destino(f,b,false,d,c,true,a)}function mostrar_circuito(c,a,b){mostrar_destino(c,a,false,b)}function mostrar_destino(c,a,g,e,i,f,d){var h=location.pathname.split("/");base_url="http://"+location.host+"/"+h[1]+"/"+h[2];var b=h[1];if(GBrowserIsCompatible()){if(g){link_="destino"}else{link_="tour"}new Ajax("/mapas/obtener_"+link_+".php?"+link_+"="+c+"&lang="+b+"&id_pais="+e,{method:"get",encoding:"ISO-8859-1",onSuccess:function(){var j=Json.evaluate(this.response.text);if(j.x!=0){crearMapa(j.x,j.y,15,a);if(j.tipo_geom!=1){var k=obtenerZoomBound(Number(j.xmin),Number(j.ymin),Number(j.xmax),Number(j.ymax));$("img_destino").setProperty("src","/images/mapas/destino.gif")}else{var k=15;$("img_destino").setProperty("src","/images/mapas/pin1.gif")}recenterMap(j.x,j.y,k);crearBotonReset(j.x,j.y,k,b);if(b=="eng"){dibujarDestinoFijo(j.x,j.y,j.nombre_esp,j.tipo_geom,j.the_geom,j.nombre_esp_tt,j)}else{dibujarDestinoFijo(j.x,j.y,j.nombre_ing,j.tipo_geom,j.the_geom,j.nombre_ing_tt,j)}crearLoadingDest(a);crearLoadingHotel(a);crearLoadingTour(a);moveendBounds("",d,c,i,c,f,b,e);GEvent.bind(map,"moveend",this,function(){moveendBounds("",d,c,i,c,f,b,e)})}}}).request()}else{$(a).setStyle("display","none")}}function mostrar_circuitos(c,a,b){mostrar_tours(c,a,b)}function mostrar_tours(c,b,d){var a=location.pathname.split("/");var e=a[1];if(GBrowserIsCompatible()){new Ajax("/mapas/obtener_tours.php?tours="+c+"&lang="+e+"&id_pais="+d,{method:"get",encoding:"ISO-8859-1",onSuccess:function(){var f=Json.evaluate(this.response.text);extend=f.extend;crearMapa(extend.x,extend.y,15,b);var g=obtenerZoomBound(extend.xmin,extend.ymin,extend.xmax,extend.ymax);if(g>15){g=15}crearBotonReset(extend.x,extend.y,g,e);recenterMap(extend.x,extend.y,g);f.tours.each(function(h){if(h.x!=0){if(e=="eng"){dibujarTourBound(h.ig,h.x,h.y,h.t,h.ti,h.il,e,false,h.n)}else{dibujarTourBound(h.ig,h.x,h.y,h.t,h.te,h.il,e,false,h.n)}}});crearLoadingDest(b);crearLoadingHotel(b);crearLoadingTour(b);moveendBounds("",false,"",true,"",false,e,d);GEvent.bind(map,"moveend",this,function(){moveendBounds("",false,"",true,"",false,e,d)})}}).request()}else{$(b).setStyle("display","none")}}function getIconNumberTour(a){var b=new GIcon();b.image="/images/mapas/numbers/"+a+".png";b.shadow="/images/mapas/numbers/s.png";b.iconSize=new GSize(17,19);b.iconAnchor=new GPoint(0,19);b.infoWindowAnchor=new GPoint(8,9);return b}function dibujarTourBound(i,a,h,g,k,d,b,j,f){geoms_borrar[i]=true;if(b=="esp"){pre_tt="Paquete de SKI: "}else{pre_tt="SKI Package: "}k=pre_tt+k;var e=new GMarker(new GLatLng(a,h),{icon:getIconNumberTour(f),draggable:false,title:k});var c=GEvent.bind(e,"click",this,function(){geoms_borrar[i]=false;new Ajax("/mapas/obtener_info_tour.php?id_lugar="+d+"&lang="+b,{method:"get",onSuccess:function(){if(b=="esp"){desc_ruta="M&aacute;s Informaci&oacute;n"}else{desc_ruta="More Information"}var l=Json.evaluate(this.response.text);txtTar='<br /><span class="tarifa_tt">'+l.t+'</span><br /><span class="hab_tt">'+l.h+"</span>";if(l.foto==""){e.openInfoWindowHtml('<div style="margin-right:10px;width:350px;"><span class="nombre_hotel">'+l.nombre+'</span><br><hr><span class="direccion_hotel">'+l.descripcion+"</span>"+txtTar+'<p align="left" style="margin:2px 0 0 0;" ><a class="info_tt_destino" href="'+l.ruta+'" target="_self">'+desc_ruta+"</a></p></div>")}else{e.openInfoWindowHtml('<div style="margin-right:10px;width:350px;"><img class="img_hotel" height="100" align="left" src="'+l.foto+'" /><span class="nombre_hotel">'+l.nombre+'</span><br><hr><span class="direccion_hotel">'+l.descripcion+"</span>"+txtTar+'<p style="margin:2px 0 0 0;" align="left"><a class="info_tt_destino" href="'+l.ruta+'" target="_self">'+desc_ruta+"</a></p></div>")}}}).request()});map.addOverlay(e);tours_dibujados[i]=true;tours_dibujados_id[i]=i};