﻿/*
=======================================================================================
 HOTELES RH                                                     Site produced by KOALAB        
 Copyright 2007                                                   http://www.koalab.com
=======================================================================================
 Utilidad de enmvoltorio de la API cliente de Google Maps. La función recibe los parámetros:
 + containerId      : ID del objeto DOM contenedor del mapa.
 + mapLatitude      : Latitud de centrado del mapa.
 + mapLongitude     : Longitud de centrado del mapa.
 + mapFocus         : [Opcional] Nivel de zoom del mapa. Por defecto es 13.
 + coordsCollection : [Opcional] Objeto JSON conteniendo las coordenadas y nombres de 
                      picto a representar en el mapa. Además, se puede incluir una propiedad
                      adicional incluyendo contenido HTML contextual al hacer clic en el picto.
                      Para diferenciar cada picto en el mapa, el sistema buscará un PNG en la carpeta '/imgLib/gmaps/'
                      con el nombre del picto cuyas coordenadas se representan.
                      NO SE PUEDEN REPETIR PICTOS CON EL MISMO INDICE.
                      -----------------------------------------------------------------
                      Ejemplo: Este ejemplo representará dos pictos en el mapa, con dos
                      pares de coordenadas diferentes, representando el primero con el PNG
                      '/imgLib/gmaps/punto1.png' y el segundo con la ruta '/imgLib/gmaps/puntoB.png'.
                      Además, el picto 1 incluye contenido HTML al hacer clic en él, mediante una ventana
                      emergente.
                      
                      var markerLatLngArray = {
                           punto1:  { lng : 39.004578, lat: -0.162762, content: '<p>Hola mundo</p>' },
                           puntoB:  { lng : 39.005578, lat: -0.161762 }
                        }
---------------------------------------------------------------------------------------
*/
function mapload(containerId, mapLatitude, mapLongitude, mapFocus, coordsCollection) {
 if (GBrowserIsCompatible()) {
    if(mapFocus == null) mapFocus = 13;
    var map = new GMap2(document.getElementById(containerId));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(mapLatitude, mapLongitude), mapFocus);
	
	var icon;
	var point;
	var marker;
	
	icon = new GIcon();
	icon.iconAnchor = new GPoint(12, 29);
    icon.infoWindowAnchor = new GPoint(12, 29);
	
	if(coordsCollection != null)
	{
        
        jQuery.each(markerLatLngArray, function(i, val) {   
            icon.image = "/imgLib/gmaps/" + i + ".png";   
            icon.iconSize = new GSize(19, 30);
        
            var point = new GLatLng(val.lng, val.lat);
	        var marker = new GMarker(point, icon);

	        if(val.content)
	        {
	            GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml(val.content);
                });
	        }

	        map.addOverlay(marker);
        });
    }
    else
    {
            icon.image = "/imgLib/gmaps/puntorh.png";   
            icon.iconSize = new GSize(24, 30);
            icon.shadow = "/imgLib/hotels/map_icon_shadow.png";
            icon.shadowSize = new GSize(34, 25);   
            point = new GLatLng(mapLatitude, mapLongitude);
	        marker = new GMarker(point, icon);
	        map.addOverlay(marker);
    }
    	    
 }
	 // display a warning if the browser was not compatible
	else 
	{
	    alert("Désolés, l’API de Google Maps n’est pas compatible avec ce navigateur");
 }
}	

/*
---------------------------------------------------------------------------------------

Enlazar el formulario de trazado de rutas con Google. 
Para ello es preciso remitir también la ruta de destino, 
que deberá incorporarse en un campo oculto. 
El evento click dispara toda la ruta pasándole el origen y destino.

---------------------------------------------------------------------------------------
*/

$(document).ready(function(){
$("#saddr").click(function() { if ($(this).val() == 'Saisissez ici votre rue, adresse ou ville d’origine. Par ex: Murcie') $(this).val(''); });
$("#saddr").blur(function() { if ($(this).val() != '') return; $(this).val('Saisissez ici votre rue, adresse ou ville d’origine. Par ex: Murcie'); });
        
        $("#launchMapTrace").click(function(){
           var fromAddress = $("#saddr").val();
           var urlAddress = $("#directUrl").val();
           window.location.href= urlAddress + "&saddr=" + fromAddress; 
        });
});

