$(document).ready(function(){

	//Configuracion de las fechas
	$("input.date-picker-alterno").datepicker({minDate:2,onClose:function(input){moverDia($(this).attr("id"));},numberOfMonths: 2});

	$(".datepicker-alterno").click(function(){
		var abuelo = $(this).parent().parent();
		$("li#" + abuelo.attr("id") + " input.date-picker-alterno").focus();
	});

		function moverDia(id){
			var startDate = $("#"+id).datepicker('getDate');
			if (startDate != null) {
				startDate.setDate(startDate.getDate()+1);
				if(id=="txtFeIni_1" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFeFin_1").datepicker('option', 'minDate',startDate);
					$("#txtFeFin_1").datepicker('setDate',startDate);
				}
				if(id=="txtFeIni_2" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFeFin_2").datepicker('option', 'minDate',startDate);
					$("#txtFeFin_2").datepicker('setDate',startDate);
				}
				if(id=="txtFeIni_3" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFeFin_3").datepicker('option', 'minDate',startDate);
					$("#txtFeFin_3").datepicker('setDate',startDate);
				}
				if(id=="txtFeIni_4" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFeFin_4").datepicker('option', 'minDate',startDate);
					$("#txtFeFin_4").datepicker('setDate',startDate);
				}
				if(id=="txtFeIni_5" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFeFin_5").datepicker('option', 'minDate',startDate);
					$("#txtFeFin_5").datepicker('setDate',startDate);
				}
				if(id=="txtFeIni_6" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFeFin_6").datepicker('option', 'minDate',startDate);
					$("#txtFeFin_6").datepicker('setDate',startDate);
				}
				if(id=="txtFeIni_7" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFeFin_7").datepicker('option', 'minDate',startDate);
					$("#txtFeFin_7").datepicker('setDate',startDate);
				}
				if(id=="txtFeIni_8" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFeFin_8").datepicker('option', 'minDate',startDate);
					$("#txtFeFin_8").datepicker('setDate',startDate);
				}
			}
		}

	$("#txtHotel_1").autocomplete("/includes/cargarHoteles.php", {
		width: 260,
		selectFirst: false
	});

	$("#txtHotel_1").result(function(event, data, formatted) {
		if (data){
			$("#cboHotel_1").val(data[1]);
		}
	});

	$("#txtHotel_2").autocomplete("/includes/cargarHoteles.php", {
		width: 260,
		selectFirst: false
	});

	$("#txtHotel_2").result(function(event, data, formatted) {
		if (data){
			$("#cboHotel_2").val(data[1]);
		}
	});

	$("#txtHotel_3").autocomplete("/includes/cargarHoteles.php", {
		width: 260,
		selectFirst: false
	});

	$("#txtHotel_3").result(function(event, data, formatted) {
		if (data){
			$("#cboHotel_3").val(data[1]);
		}
	});

	$("#txtHotel_4").autocomplete("/includes/cargarHoteles.php", {
		width: 260,
		selectFirst: false
	});

	$("#txtHotel_4").result(function(event, data, formatted) {
		if (data){
			$("#cboHotel_4").val(data[1]);
		}
	});

	$("#txtHotel_5").autocomplete("/includes/cargarHoteles.php", {
		width: 260,
		selectFirst: false
	});

	$("#txtHotel_5").result(function(event, data, formatted) {
		if (data){
			$("#cboHotel_5").val(data[1]);
		}
	});

	$("#txtHotel_6").autocomplete("/includes/cargarHotelesShare.php", {
		width: 260,
		selectFirst: false
	});

	$("#txtHotel_6").result(function(event, data, formatted) {
		if (data){
			$("#cboHotel_6").val(data[1]);
		}
	});

	$("#txtHotel_7").autocomplete("/includes/cargarHotelesShare.php", {
		width: 260,
		selectFirst: false
	});

	$("#txtHotel_7").result(function(event, data, formatted) {
		if (data){
			$("#cboHotel_7").val(data[1]);
		}
	});

	$("#txtHotel_8").autocomplete("/includes/cargarHotelesShare.php", {
		width: 260,
		selectFirst: false
	});

	$("#txtHotel_8").result(function(event, data, formatted) {
		if (data){
			$("#cboHotel_8").val(data[1]);
		}
	});

	$("#txtHotel_1").keypress(function(e){
		if(e.keyCode==8){
			$("#cboHotel_1").val("select");
		}

	});

	$("#txtHotel_2").keypress(function(e){
		if(e.keyCode==8){
			$("#cboHotel_2").val("select");
		}

	});

	$("#txtHotel_3").keypress(function(e){
		if(e.keyCode==8){
			$("#cboHotel_3").val("select");
		}

	});

	$("#txtHotel_4").keypress(function(e){
		if(e.keyCode==8){
			$("#cboHotel_4").val("select");
		}

	});

	$("#txtHotel_5").keypress(function(e){
		if(e.keyCode==8){
			$("#cboHotel_5").val("select");
		}

	});

	$("#txtHotel_6").keypress(function(e){
		if(e.keyCode==8){
			$("#cboHotel_6").val("select");
		}

	});

	$("#txtHotel_7").keypress(function(e){
		if(e.keyCode==8){
			$("#cboHotel_7").val("select");
		}

	});

	$("#txtHotel_8").keypress(function(e){
		if(e.keyCode==8){
			$("#cboHotel_8").val("select");
		}

	});

    //Para reservar desde el listado de autos
	$(".seleccionar_auto").click(function(){
		var vehiculo = $(this).val();
		$('.info_listado').find('.fila_vehiculo:visible').fadeOut(0);

		if($(this).attr("checked"))
			$("#fila_vehiculo_" + vehiculo).show();
	});

	$(".reservar_transfers").click(function(e){
		e.preventDefault();
		var vehiculo = $(this).attr("name");

		var valores = vehiculo.split("_");

		$("#txtFolio").val(valores[1]);
		$("#frmQuickAlternativo").submit();
	});

	//Para validar el formulario de traslados
	$("#frmQuickAlternativo").submit(function(){
		var id = $("#txtFolio").val();

		var txtTo = $("#txtHotel_"+id).val();
		var to = $("#cboHotel_"+id).val();
		var fe_1 = $("#txtFeIni_"+id).val();
		var fe_2 = $("#txtFeFin_"+id).val();

		if(txtTo==""){
			$("#cboHotel_"+id).val("select");
			to="select";
		}

		if(to=="select"){
			alert("Por favor proporcione su hotel de llegada");
			$("#txtHotel_"+id).focus();
			return false;
		}

		if(fe_1=="dd/mm/yyyy"||fe_1==""){
			alert("Por favor proporcione la fecha de salida");
        	$("#txtFeIni_"+id).focus();
			return false;
		}

		if(fe_2=="dd/mm/yyyy"||fe_1==""){
			alert("Por favor proporcione la fecha de regreso");
			$("#txtFeFin_"+id).focus();
			return false;
		}


		return true;
	});

});