
$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});
$(document).ready(function() {
  $("#buscar_zona").change(function(){
	$("#buscar_destino").empty();
	$("#buscar_servicio").empty();
	$("#buscar_servicio_tipo").empty();

	if ( $(this).val() > 0 ) {
		$("#buscar_destino").hide();
		$('<img src="theme/img/ajax-loader.gif" width="16" height="11" alt="Espere..." id="ajax_loader" style="margin-bottom:8px;" />').insertAfter('#buscar_destino');
		
		$.getJSON("ajax_destinos.php",{id: $(this).val()}, function(j){
			var options = '';
			
			options += '<option value="0">Seleccione un Destino</option>';

			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}

			$("#buscar_destino").html(options);
			$('#ajax_loader').remove();
			$("#buscar_destino").show();
		});
	}
  })


  $("#buscar_destino").change(function(){
	$("#buscar_servicio").empty();
	$("#buscar_servicio_tipo").empty();

	if ( $(this).val() > 0 ) {
		$("#buscar_servicio").hide();
		$('<img src="theme/img/ajax-loader.gif" width="16" height="11" alt="Espere..." id="ajax_loader" style="margin-bottom:8px;" />').insertAfter('#buscar_servicio');
		$.getJSON("ajax_servicios.php",{id: $(this).val()}, function(j){
			var options = '';
			options += '<option value="0">Servicios - Alojamientos</option>';
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			$("#buscar_servicio").html(options);
			$('#ajax_loader').remove();
			$("#buscar_servicio").show();
		});
	}
  })

  $("#buscar_servicio").change(function(){
	$("#buscar_servicio_tipo").empty();

	if ( $(this).val() > 0 ) {
		$("#buscar_servicio_tipo").hide();
		$('<img src="theme/img/ajax-loader.gif" width="16" height="11" alt="Espere..." id="ajax_loader" style="margin-bottom:8px;" />').insertAfter('#buscar_servicio');
		$.getJSON("ajax_servicios_tipos.php",{id: $(this).val(), buscar_zona: $("#buscar_zona").val(), buscar_destino: $("#buscar_destino").val()}, function(j){
			var options = '';
			options += '<option value="0">Todos</option>';
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			$("#buscar_servicio_tipo").html(options);
			$('#ajax_loader').remove();
			$("#buscar_servicio_tipo").show();
		});
	}
  })


	if ($("div#mapa_destinos").length){
		var so = new SWFObject("ammap/ammap.swf", "ammap", "450", "420", "8", "#FFFFFF");
		so.addVariable("path", "ammap/");
		so.addVariable("data_file", escape("ammap/ammap_data.xml"));
		so.addVariable("settings_file", escape("ammap/ammap_settings.xml"));		
		so.addVariable("preloader_color", "#999999");
		so.write("mapa_destinos");
	}

})



