// JavaScript Document
$(document).ready(function()
{  
	
	$("input[name='ciudad']").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});

	$("#btn_enviar").click(
		   function()
		   {	
			   $("form[name='frm_buscador']").submit();
		   });
	
	

	// Autocompletar ciudades	
	$("input[name='ciudad_origen']").autocomplete("/nucleo/booking/frontoffice/ajax/ciudad_autocompletar.asp", {
		minChars: 3,
		width: 310,
		delay:100,
		mustMatch: false, // true, the autocompleter will only allow results that are presented by the backend. Note that illegal values result in an empty input box.
		formatItem: function(row) {
			return row[0] + ", " + row[2] + ", " + row[3];
		},
		formatResult: function(row) {
			return row[0].replace(/(<.+?>)/gi, '');
		}
	});	
	
	$("input[name='ciudad_origen']").result(function(event, data, formatted) {
	if (data)
		 $("input[name='idciudad_origen']").attr('value',data[4]);
		 $("input[name='ciudad_origen_aeropuerto']").attr('value',data[1]);
	});	
	
	
	$("input[name='ciudad']").autocomplete("/nucleo/booking/frontoffice/ajax/ciudad_autocompletar.asp", {
		minChars: 3,
		width: 310,
		delay:100,
		mustMatch: false, // true, the autocompleter will only allow results that are presented by the backend. Note that illegal values result in an empty input box.
		formatItem: function(row) {
			return row[0] + ", " + row[2] + ", " + row[3];
		},
		formatResult: function(row) {
			return row[0].replace(/(<.+?>)/gi, '');
		}
	});	
	
	$("input[name='ciudad']").result(function(event, data, formatted) {
	if (data)
		 $("input[name='idciudad']").attr('value',data[4]);
		 $("input[name='ciudad_aeropuerto']").attr('value',data[1]);
	});	
	// ************ fin autocompleta ciudades 
	
	
	// Autocompletar ciudades GDS	
	$("input[name='city']").autocomplete("/nucleo/booking/frontoffice/ajax/ciudad_autocompletar.asp", {
		minChars: 3,
		width: 310,
		delay:100,
		mustMatch: false, // true, the autocompleter will only allow results that are presented by the backend. Note that illegal values result in an empty input box.
		formatItem: function(row) {
			return row[0] + ", " + row[2] + ", " + row[3];
		},
		formatResult: function(row) {
			return row[0].replace(/(<.+?>)/gi, '');
		}
	});	
	
	$("input[name='city']").result(function(event, data, formatted) {
	if (data)
		 $("input[name='idciudad']").attr('value',data[4]);
	});	
	// ************ fin autocompleta ciudades 
	
	
	//Valido el formulario
	$("form[name='frm_buscador']").validate();

	
});
