document.observe('dom:loaded', function()
{
	new InitDatePicker();

	if ($('booking_form'))
	{	
		$('booking_form').select('input[type=text]').each(function(el)
		{
			if (el.value.empty()) el.value = el.title;
			el.observe('focus', function(event)
			{
				this.activate();
			});
		});
	}
});

//Inicializar los inputs de fechas
var InitDatePicker = Class.create();
InitDatePicker.prototype =
{
	initialize : function()
	{
		$$("input.datepicker").each(function(elemento,indx)
		{
			options =
			{
				clickCallback		: function()
				{
					var calendar = this;

					if (elemento.id == 'departure' && !$F(elemento).isDate() && $F('arrival').isDate())
					{
						elemento.value = $F('arrival').toDate().addDays(7).toStrDate();
					}

					document.observe('click', function(event)
					{
						if (event.target != elemento && !$(event.target).descendantOf($("datepicker-" + elemento.id)))
						{
							calendar.close();
						}
					});

				},
				cellCallback		: function()
				{
					switch(elemento.id)
					{
						case 'arrival':
							//setNewArrival();
							break;

						case 'departure':
							//setNewDeparture();
							break;
					}
					document.stopObserving('click');
				},
				relative			: elemento.id,
				language			: elemento.lang,
				keepFieldEmpty		: true,
				enableShowEffect	: false,
				enableCloseEffect	: false,
				topOffset			: 25,
				disableFutureDate	: false,
				disablePastDate		: true,
				topOffset			: elemento.offsetHeight + 1
			}

			var obj = new DatePicker(options);

		}.bind(this))
	}
}

function initializeMap()
{
	if (GBrowserIsCompatible())
	{
		var latitude = 38.9099744;
		var longitude = 1.4345924;
		var zoom = 16;
		
		var map = new GMap2($("map"));
		map.setCenter(new GLatLng(latitude, longitude), zoom);
		map.setMapType(G_HYBRID_MAP);
		map.setUIToDefault();

		function createMarker(point) {
		  // Create a lettered icon for this point using our icon class
		  //var icon = new GIcon(baseIcon);

		  // Set up our GMarkerOptions object
		  //markerOptions = {icon: icon};
		  //var marker = new GMarker(point, markerOptions);
		  var marker = new GMarker(point);

		  GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml("Hotel Montesol");
		  });
		  return marker;
		}

		var point = new GLatLng(latitude, longitude);
		map.addOverlay(createMarker(point));
  	}
}
