
$(document).ready(function(){
	
	
	//Con esto cargamos los datos de las excepciones de traslados
	
	var excepciones = new Array();
	var idAfiliado = 0;
	var destino_vuelo = "select";
	
	$.post("/includes/cargarExcepciones.php",{idAfiliado:idAfiliado},function(data){
		sucess:
			excepciones = data;							
	},'json');
	
	//efecto del quick

	$("#ul_links_tab li a").click( function(){
		var tabactual = $(this);
		var idtab = $(this).attr("id");	
		
		if( idtab=='linktransfers' )
		{
			$(".booking-search").css({'background' : 'url(/recursos/img/quick_traslados.png)'});
			var padre = tabactual.parent();
			$("#ul_links_tab li").each( function(){
				$(this).removeClass("hover");
			});

			padre.addClass("hover");

			$("#frm_transfers").show();
			$("#frm_tours").hide();
			$("#frm_vuelos").hide();
			$("#frm_hotels").hide();
		}

		if( idtab=='linkstours' )
		{
			$(".booking-search").css({'background' : 'url(/recursos/img/quick_tours.png)'});
			var padre = tabactual.parent();
			$("#ul_links_tab li").each( function(){
				$(this).removeClass("hover");
			});

			padre.addClass("hover");

			$("#frm_tours").show();
			$("#frm_vuelos").hide();
			$("#frm_transfers").hide();
			$("#frm_hotels").hide();
		}

		if( idtab=='linksflights' )
		{
			$(".booking-search").css({'background' : 'url(/recursos/img/quick_paquetes.png)'});
			var padre = tabactual.parent();
			$("#ul_links_tab li").each( function(){
				$(this).removeClass("hover");
			});

			padre.addClass("hover");

			$("#frm_vuelos").show();
			$("#frm_hotels").hide();
			$("#frm_transfers").hide();
			$("#frm_tours").hide();
		}

		if( idtab=='linkshotels' )
		{
			$(".booking-search").css({'background' : 'url(/recursos/img/quick_hoteles.png)'});
			var padre = tabactual.parent();
			$("#ul_links_tab li").each( function(){
				$(this).removeClass("hover");
			});

			padre.addClass("hover");

			$("#frm_hotels").show();
			$("#frm_vuelos").hide();
			$("#frm_transfers").hide();
			$("#frm_tours").hide();
			
			cargarHotelesPaquetes("Paquetes","select");

		}

		return false;
	});

	//Configuracion de las fechas para tours y traslados
	$.datepicker.setDefaults($.datepicker.regional['es']);
	$("input.date-picker").datepicker({minDate:2,onClose:function(input){moverDia($(this).attr("id"));},numberOfMonths: 2});

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

	//Configuracion de las fechas para hoteles
	$("input.date-picker-hotel").datepicker({minDate:parseInt($("#diasBq").val()),onClose:function(input){moverDia($(this).attr("id"));},numberOfMonths: 2});

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

		function moverDia(id){
			var startDate = $("#"+id).datepicker('getDate');
			if (startDate != null) {
				startDate.setDate(startDate.getDate()+1);
				if(id=="txtFechaIn" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtFechaOut").datepicker('option', 'minDate',startDate);
					$("#txtFechaOut").datepicker('setDate',startDate);
				}
				if(id=="txtCheckIn" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtCheckOut").datepicker('option', 'minDate',startDate);
					$("#txtCheckOut").datepicker('setDate',startDate);
				}
				if(id=="txtCheckIn_2" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtCheckOut_2").datepicker('option', 'minDate',startDate);
					$("#txtCheckOut_2").datepicker('setDate',startDate);
				}
				if(id=="txtCheckInVuelo" && $("#"+id).val()!="dd/mm/yyyy"){
					$("#txtCheckOutVuelo").datepicker('option', 'minDate',startDate);
					$("#txtCheckOutVuelo").datepicker('setDate',startDate);
				}
			}
		}

		$("ul#menu_actividades li").click(function(){
			var url = $(this).find('a').attr("href");
			window.location = url;
		});

		$("#menu_actividades li img").hover(
		 function()
		 {
		  this.src = this.src.replace("_off","_on");
		  $(this).parent().find('a').css("color","#9ACA73");
		 },
		 function()
		 {
		  this.src = this.src.replace("_on","_off");
		  $(this).parent().find('a').css("color","#ccc");
		 }
		);

	$(".chkViaje").click(function(){
		var valor = $(this).val();

		if(valor=="One Way")
			$("#Out_t").hide();
		else
			$("#Out_t").show();
	});

	
	

	

	function validarSiSoloPrivado(){
		var valorComboUno = $("#cboFromTransfer").val();
		var valorComboDos = $("#cboToTransfer").val();
		var vectorComboUno = valorComboUno.split('*');
		var vectorComboDos = valorComboDos.split('*');
		
		$("#frmTraslado input[value='Private']").removeAttr("disabled");
		$("#frmTraslado input[value='Share']").removeAttr("disabled");
		$("#frmTraslado input[value='Non stop']").removeAttr("disabled");
		$("#frmTraslado input[value='Private']").attr("checked","checked");
		$(".caja_privado").show();
		$(".caja_compartido").show();
		$(".caja_directo").show();

		if (vectorComboUno[0]=="Hotel" && vectorComboDos[0]=="Hotel"){			
			$(".caja_compartido").hide();
			$(".caja_directo").hide();
			$("#frmTraslado input[value='Share']").attr("disabled","disabled");
			$("#frmTraslado input[value='Non stop']").attr("disabled","disabled");						
		}else{		
			
			if(excepciones.length>0){
				
				for (j=0;j<excepciones.length;j++){					
					if(vectorComboUno[1]==excepciones[j][0]||vectorComboDos[1]==excepciones[j][0]){						
						if(excepciones[j][1]==0){							
							$(".caja_privado").hide();
							$("#frmTraslado input[value='Private']").attr("disabled","disabled");
							$("#frmTraslado input[value='Share']").attr("checked","checked");
						}
						if(excepciones[j][2]==0){							
							$(".caja_compartido").hide();
							$("#frmTraslado input[value='Share']").attr("disabled","disabled");
							if(excepciones[j][1]==0)
								$("#frmTraslado input[value='Non stop']").attr("checked","checked");
						}
						if(excepciones[j][3]==0){							
							$(".caja_directo").hide();
							$("#frmTraslado input[value='Non stop']").attr("disabled","disabled");							
						}
						break;
					}
				}				
			}		
		}
	}

	$("#txtToTransfer").focus(function(){
		var texto = $(this).val();
		if(texto=="Nombre del Hotel | Cancún Aeropuerto"){
			$(this).val('');
			$("#cboToTransfer").val("select");
		}
	});

	$("#txtToTransfer").blur(function(){
		var texto = $(this).val();
		if(texto==""){
			$(this).val('Nombre del Hotel | Cancún Aeropuerto');
			$("#cboToTransfer").val("select");
		}
	});

	$("#txtHotel").focus(function(){
		var texto = $(this).val();
		if(texto=="Escriba el nombre del Hotel"){
			$(this).val('');
			$("#keyword_hotel").val("select");
		}
	});

	$("#txtHotel").blur(function(){
		var texto = $(this).val();
		if(texto==""){
			$(this).val('Escriba el nombre del Hotel');
			$("#keyword_hotel").val("select");
		}
	});

	$("#txtHotelVuelo").focus(function(){
		var texto = $(this).val();
		if(texto=="Escriba el nombre del Hotel"){
			$(this).val('');
			$("#vuelo_keyword_hotel").val("select");
		}
	});

	$("#txtHotelVuelo").blur(function(){
		var texto = $(this).val();
		if(texto==""){
			$(this).val('Escriba el nombre del Hotel');
			$("#vuelo_keyword_hotel").val("select");
		}
	});
	
	$("#txtOrigenVuelo").focus(function(){
		var texto = $(this).val();
		if(texto=="Ingrese una ciudad de origen"){
			$(this).val('');
		}
	});

	$("#txtOrigenVuelo").blur(function(){
		var texto = $(this).val();
		if(texto==""){
			$(this).val('Ingrese una ciudad de origen');
		}
	});
	
	$("#txtDestinoVuelo").focus(function(){
		var texto = $(this).val();
		if(texto=="Ingrese una ciudad de destino"){
			$(this).val('');
		}
	});

	$("#txtDestinoVuelo").blur(function(){
		var texto = $(this).val();
		if(texto==""){
			$(this).val('Ingrese una ciudad de destino');
		}
	});

	//Para validar el formulario de tours
	$("#frmTour").submit(function(){
		var cboCategoria = $("#cboCategoria").val();
		var saliendo = $("#cboSalidaDesde").val();
		var tour = $("#txtTour").val();
		var fe_2 = $("#txtFechaServicio").val();
		var keyword_tour = $("#keyword_tour").val();
		var numAdultos = $("#cboAdulto").val();
		var numNinos = $("#cboNino").val();

		if(saliendo=="select"&&keyword_tour==""&&cboCategoria=="select"){
			alert("Por favor selecione su destino");
			$("#txtHotelDestinoTour").focus();
			return false;
		}

		if(tour==""){
			$("#keyword_tour").val('');
		}
/*
		if(saliendo!="select"){
			if(fe_2=="dd/mm/yyyy"){
				alert("Por favor seleccione una fecha");

				var targetOffset = $("#txtFechaServicio").offset().top;

	        	$('html,body').animate({scrollTop: targetOffset-210}, 1000);
	        	$("#txtFechaServicio").focus();
	        	$("#ui-datepicker-div").css("top",targetOffset+20);

				return false;
			}
		}*/
/*
		if(parseInt(numAdultos)+parseInt(numNinos)>10){
			alert("For Groups over 10 participants please contact us");
			$("#cboAdulto").focus();
			return false;
		}*/

		/*if( parseInt(numNinos)>parseInt(numAdultos)){
			alert("El numero de menores no debe exceder el numero de adultos participantes");
			//alert("It is permitted one infant per paying adult");
			$("#cboNino").val(0);
			$("#cboNino").focus();
			return false;
		}*/


		return true;
	});

	$("#frmTourFicha").submit(function(){
		var op = $("#opcion").val();
		var minPax = $("#minPax").val();
		var maxPax = $("#maxPax").val();

		if(op!="opVehiculo"){
			var opcionFolio = $("#opcionFolio").val();
			var sgOption = $("#sgOption_"+opcionFolio).val();
			var txtFechaServicio = $("#txtFechaServicio_"+opcionFolio).val();
			var numAdultos = $("#cboAdulto_"+opcionFolio).val();
			var numNinos = 0;
			var paquete = "I";

			if($("#cboNino_"+opcionFolio).length>0)
				numNinos = $("#cboNino_"+opcionFolio).val();

			if($("#cboPaquete_"+opcionFolio).length>0)
				paquete = $("#cboPaquete_"+opcionFolio).val();

			var valores_fecha = txtFechaServicio.split("/");

			var dias = Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sabado");

			if(sgOption=="select"){
				alert("Seleccione una opcion");
				$("#sgOption_"+opcionFolio).focus();
				return false;
			}

			if(txtFechaServicio=="dd/mm/yyyy"){
				alert("Seleccione una fecha para su actividad");
				$("#txtFechaServicio_"+opcionFolio).focus();
				return false;
			}
			
			if((parseInt(numAdultos)+parseInt(numNinos))<parseInt(minPax)){
				alert("Este tour opera sólo con un mínimo de "+minPax+" personas.");
				$("#cboAdulto_"+opcionFolio).focus();
				return false;				
			}
			
			if((parseInt(numAdultos)+parseInt(numNinos))>parseInt(maxPax)){
				alert("Este tour opera sólo con un máximo de "+maxPax+" personas.");
				$("#cboAdulto_"+opcionFolio).focus();
				return false;				
			}

			var valores = sgOption.split('-');
			var valor_dias = valores[3];
			var disponibilidad = valor_dias.split(",");

			var thenx = new Date(valores_fecha[2],valores_fecha[1]-1,valores_fecha[0]);
			var num_dia = thenx.getDay();
			var txtMsj = "\n\nDisponible los días:\n";

			if(disponibilidad[num_dia]==0){

				for (var i=0;i<7;i++){
					if(disponibilidad[i]==1)
						txtMsj = txtMsj + dias[i] + "\n";
				}

				alert("No está disponible para las fechas seleccionadas."+txtMsj);
				return false;
			}

			/*if( parseInt(numNinos)>parseInt(numAdultos)){
				alert("El numero de menores no debe exceder el numero de adultos participantes");
				//alert("It is permitted one infant per paying adult");
				$("#cboNino_"+opcionFolio).val(0);
				$("#cboNino_"+opcionFolio).focus();
				return false;
			}*/

			if(paquete=="S"){
				if( (parseInt(numNinos)+parseInt(numAdultos))%2!=0 ) {
					alert("Para reservar un servicio compartido el numero de participantes debe ser par");
					//alert("Shared service is considered in pairs");
					$("#cboAdulto_"+opcionFolio).val(2);
					if (parseInt(numNinos)>0)
						$("#cboNino_"+opcionFolio).val(0);
					$("#cboAdulto_"+opcionFolio).focus();
					return false;
				}
			}

		}

		return true;
	});

	$(".paquete").change(function(){
		var op = $(this).val();

		if(op=="select"){
			alert("Por favor selecciona una opcion");
			return false;
		}

		var valores = op.split('-');
		$(".cboTourNino").val(0);
		if(valores[4]==0){
			$("#liAceptaNino").hide();
		}else{
			$("#liAceptaNino").show();
		}
	});


	//Para validar el formulario de traslados
	$("#frmTraslado").submit(function(){
		var from = $("#cboFromTransfer").val();
		var to = $("#cboToTransfer").val();
		var fe_1 = $("#txtFechaIn").val();
		var fe_2 = $("#txtFechaOut").val();
		var numAdultos = $("#cboPax").val();

		if(from=="select"){
			alert("Por favor seleccione su origen");
			$("#txtFromTransfer").focus();
			return false;
		}

		if(to=="select"){
			alert("Por favor escriba su hotel");
			$("#txtToTransfer").focus();
			return false;
		}

		if(from==to){
			alert("Por favor escriba su hotel");
			$("#txtToTransfer").val('');
			$("#txtToTransfer").focus();
			return false;
		}


		if(fe_1=="dd/mm/yyyy"){
			alert("Por favor seleccione una fecha");

			var targetOffset = $("#txtToTransfer").offset().top;

        	$('html,body').animate({scrollTop: targetOffset-160}, 1000);
        	$("#txtFechaIn").focus();
        	$("#ui-datepicker-div").css("top",targetOffset+60);
			return false;
		}

		if(fe_2=="dd/mm/yyyy"){
			alert("Por favor seleccione una fecha");
			$("#txtFechaOut").focus();
			return false;
		}

		/*if(parseInt(numAdultos)>10){
			alert("For Groups over 10 participants please contact us");
			$("#cboPax").focus();
			return false;
		}*/


		return true;
	});

	//Con esto agrego al carrito el tour de los listados
	$(".reservar_tour").click(function(e){
		e.preventDefault();
		var tour = $(this).attr("name");

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

		$("#opFolio").val(valores[1]);
		$("#frmSelectTour").submit();
	});

	//script para eliminar texto del buscador.

	$("#search-header").focus( function(){
		$("#search-header").val("");
		return false;
	});


	//Codigo de hoteles
	var orden_grl = 0;
	$("#r_ordenacion").change(function(){
		$("#frmBusqueda").attr("action","/hoteles/asignar_orden_grl.php");
		orden_grl = 1;
		$("#frmBusqueda").submit();
	});

	//Codigo de hoteles
	$("#r_ordenacion2").change(function(){
		orden_grl = 0;
		$("#frmBusqueda").submit();
	});

	//Codigo de hoteles
	$("#cboHab").change(function(){
		var cboHab = $("#cboHab").val();

		$(".filaHab").hide();

		for(var i=1;i<=cboHab;i++){
			$("#filaHab_"+i).show();
		}

	});

	$(".cboNinoHab").change(function(){
		var id_grl = $(this).attr("id");
		var valores = id_grl.split("_");
		var id = valores[1];
		var numNinos = $(this).val();

		$("#lbEdad_"+id).hide();
		$("#cboEdadUno_"+id).hide();
		$("#cboEdadDos_"+id).hide();
		$("#cboEdadTres_"+id).hide();

		if(numNinos==1){
			$("#lbEdad_"+id).css("display","block");
			$("#cboEdadUno_"+id).show();
		}

		if(numNinos==2){
			$("#lbEdad_"+id).css("display","block");
			$("#cboEdadUno_"+id).show();
			$("#cboEdadDos_"+id).show();
		}

		if(numNinos==3){
			$("#lbEdad_"+id).css("display","block");
			$("#cboEdadUno_"+id).show();
			$("#cboEdadDos_"+id).show();
			$("#cboEdadTres_"+id).show();
		}

	});

	$("#frmHoteles").submit(function(){
		var fe_1 = $("#txtCheckIn").val();
		var fe_2 = $("#txtCheckOut").val();
		var destino = $("#cboDestino").val();
		var keyword_hotel = $("#keyword_hotel").val();
		var txtHotel = $("#txtHotel").val();

		if(keyword_hotel=="select"){
			$("#txtHotel").val("");
			if(destino=="select"){
				alert("Por favor seleccione un destino");
				$("#cboDestino").focus();
				return false;
			}

			if(fe_1=="dd/mm/yyyy"){
				alert("Por favor seleccione su fecha de llegada");
				$("#txtCheckIn").focus();
				return false;
			}

			if(fe_2=="dd/mm/yyyy"){
				alert("Por favor seleccione su fecha de salida");
				$("#txtCheckOut").focus();
				return false;
			}

			desplegarInfoEspera();
		}

		return true;
	});

	$("#frmBusqueda").submit(function(){
		var fe_1 = $("#txtCheckIn_2").val();
		var fe_2 = $("#txtCheckOut_2").val();

		if(orden_grl==0){
			if(fe_1=="dd/mm/yyyy"){
				alert("Por favor seleccione una fecha");
				$("#txtCheckIn_2").focus();
				return false;
			}

			if(fe_2=="dd/mm/yyyy"){
				alert("Por favor seleccione una fecha");
				$("#txtCheckOut_2").focus();
				return false;
			}
		}

		desplegarInfoEspera();

		return true;
	});

	$("ul.cambiarPaginaBusqueda li a").click(function(e){
			e.preventDefault();
			var nombre = $(this).attr("name");
			var valores = nombre.split("_");
			$("#numPagina").val(valores[1]);
			$("#frmPaginacion").submit();
	});

	$(".ver_detalle_noche").click(function(e){
			e.preventDefault();
			var nombre = $(this).attr("name");
			//$(".contenido-ficha").hide();
			$("#ficha_"+nombre).toggle();
	});


	$(".cssBtnCompraHotel").click(function(){
			var datos = $(this).val();
			$("#datosHab").val(datos);
			desplegarInfoEspera();
			$("#frmSeleccionHab").submit();
	});

	

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

	});

	

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

	});

	$("#menu_actividades li").click( function(){
		//$(this).find("a").trigger("click");
		//return false;
	});

	//Con esto agrego al carrito el tour de los listados
	$("#menu_agency").click(function(e){
		e.preventDefault();
		//$("#contenedor_agency").toggle();
		$.post('/includes/formAgencias.php',{}, function(data) {
	 		sucess:	 			
	 			$.facebox(data);
	 			$("div#facebox div.content").css("width","auto");
	 	});		
	});

	$("#btnSignOut").live('click',function(){
		//$("#contenedor_agency").hide();		
		$.facebox.close();
	});
	
	$("#btnReenviarPW").live('click',function(e){
		e.preventDefault();
		var txtAgencyId = $("#txtAgencyId").val();

		if(txtAgencyId==""){
			alert("Por favor escriba su Id de Agencia");
			$("#txtAgencyId").focus();
			return false;
		}else{		
			$.post('/includes/reenviarPWAgencias.php',{txtAgencyId:txtAgencyId}, function(data) {
		 		sucess:
		 			if(data==1)
		 				alert("La información de su cuenta se ha enviado a su correo");
		 			else
		 				alert("Ocurrio un error, por favor intente de nuevo");
		 	});	
		}		

	});
	
	$("#btnSignIn").live('click',function(){
		var datos = $("#frmSignIn").serialize();
		var txtAgencyId = $("#txtAgencyId").val();
		var txtAgencyPw = $("#txtAgencyPw").val();

		if(txtAgencyId==""){
			alert("Por favor escriba su Id de Agencia");
			$("#txtAgencyId").focus();
			return false;
		}

		if(txtAgencyPw==""){
			alert("Por favor escriba su contraseña");
			$("#txtAgencyPw").focus();
			return false;
		}


		$.post("/includes/verificarDatosAgency.php",datos,function(data){
			sucess:
			if(data==0){
				alert("Informacion incorrecta, por favor intente de nuevo");
				return false;
			}else{
				window.location.href="/";
			}
		});

		return false;
	});	

	//Aqui empieza todo lo de los paquetes y vuelos
	cargarOrigenesDestinosPaquetes("Paquetes");
	cargarHotelesPaquetes("Paquetes","select");
	
	function cargarOrigenesDestinosPaquetes(opVuelo){		
	
		$.ajax({
			url: "/gets/cargarOrigenesPaquetes.php?op="+opVuelo,
			dataType: "xml",
			success: function( xmlResponse ) {
				var txtOrigenVuelo = $( "hotel", xmlResponse ).map(function() {
					return {
						value: $( "nombre", this ).text(),
						id: $( "keyword", this ).text()
					};
				}).get();
				$( "#txtOrigenVuelo" ).autocomplete({
					source: txtOrigenVuelo,
					minLength: 1,
					select: function( event, ui ) {
					       $("#cboOrigenVuelo").val(ui.item.id);
					}
				});
				
			}
		});
		
		$.ajax({
			url: "/gets/cargarOrigenesPaquetes.php?op="+opVuelo,
			dataType: "xml",
			success: function( xmlResponse ) {
				var txtDestinoVuelo = $( "hotel", xmlResponse ).map(function() {
					return {
						value: $( "nombre", this ).text(),
						id: $( "keyword", this ).text()
					};
				}).get();
				$( "#txtDestinoVuelo" ).autocomplete({
					source: txtDestinoVuelo,
					minLength: 1,
					select: function( event, ui ) {
					       $("#cboDestinoVuelo").val(ui.item.id);
					       cargarHotelesPaquetes(opVuelo,ui.item.id);
					}
				});
				
			}
		});
	
	}
	
	function cargarHotelesPaquetes(op,destino){
		$.ajax({
			url: "/gets/cargarHotelesVenta.php?op="+op+"&destino="+destino,
			dataType: "xml",
			success: function( xmlResponse ) {
				var txtOrigenVuelo = $( "hotel", xmlResponse ).map(function() {
					return {
						value: $( "nombre", this ).text(),
						id: $( "keyword", this ).text()
					};
				}).get();
				$( "#txtHotelVuelo" ).autocomplete({
					source: txtOrigenVuelo,
					minLength: 1,
					select: function( event, ui ) {
					       $("#vuelo_keyword_hotel").val(ui.item.id);
					}
				});
				$( "#txtHotel" ).autocomplete({
					source: txtOrigenVuelo,
					minLength: 1,
					select: function( event, ui ) {
					       $("#keyword_hotel").val(ui.item.id);
					}
				});
				
			}
		});
	}
	
	
	$.ajax({
		url: "/gets/cargarDestinosVenta.php",
		dataType: "xml",
		success: function( xmlResponse ) {
			var txtOrigenVuelo = $( "hotel", xmlResponse ).map(function() {
				return {
					value: $( "nombre", this ).text(),
					id: $( "keyword", this ).text()
				};
			}).get();
			$( "#txtFromTransfer" ).autocomplete({
				source: txtOrigenVuelo,
				minLength: 1,
				select: function( event, ui ) {
				       $("#cboFromTransfer").val(ui.item.id);
				       validarSiSoloPrivado();
				}
			});
			
		}
	});
	
	
	
	$.ajax({
		url: "/gets/cargarHoteles.php",
		dataType: "xml",
		success: function( xmlResponse ) {
			var txtOrigenVuelo = $( "hotel", xmlResponse ).map(function() {
				return {
					value: $( "nombre", this ).text(),
					id: $( "keyword", this ).text()
				};
			}).get();
			$( "#txtToTransfer" ).autocomplete({
				source: txtOrigenVuelo,
				minLength: 1,
				select: function( event, ui ) {
				       $("#cboToTransfer").val(ui.item.id);
				       validarSiSoloPrivado();
				}
			});
			
		}
	});
	
	$.ajax({
		url: "/gets/cargarDestinoHotelTours.php",
		dataType: "xml",
		success: function( xmlResponse ) {
			var txtOrigenVuelo = $( "hotel", xmlResponse ).map(function() {
				return {
					value: $( "nombre", this ).text(),
					id: $( "keyword", this ).text()
				};
			}).get();
			$( "#txtHotelDestinoTour" ).autocomplete({
				source: txtOrigenVuelo,
				minLength: 1,
				select: function( event, ui ) {
				       $("#cboSalidaDesde").val(ui.item.id);
				}
			});
			
		}
	});
	
	$.ajax({
		url: "/gets/cargarToursVenta.php",
		dataType: "xml",
		success: function( xmlResponse ) {
			var txtOrigenVuelo = $( "hotel", xmlResponse ).map(function() {
				return {
					value: $( "nombre", this ).text(),
					id: $( "keyword", this ).text()
				};
			}).get();
			$( "#txtTour" ).autocomplete({
				source: txtOrigenVuelo,
				minLength: 1,
				select: function( event, ui ) {
				       $("#keyword_tour").val(ui.item.id);
				}
			});
			
		}
	});
	
	
	

	$(".chkOpcionVuelo").click(function(){
		var opVuelo = $(this).val();
		$("#cboHabVuelo").val(1);

		if(opVuelo=="HotelVuelo"){
			$("#fila_num_hab").show();
			$(".fila_desc_hab").show();
			$("#filaOrigenVuelo").show();			
			$("#bookTipo").val("HotelVuelo");
		}else{
			$("#fila_num_hab").hide();
			$(".fila_desc_hab").hide();
			$("#filaOrigenVuelo").hide();	
			$("#bookTipo").val("Paquetes");
		}
		
		$("#cboOrigenVuelo").val("select");
		$("#cboDestinoVuelo").val("select");
		$("#txtOrigenVuelo").val("Ingrese una ciudad de origen");
		$("#txtDestinoVuelo").val("Ingrese una ciudad de destino");
		
		cargarOrigenesDestinosPaquetes(opVuelo);
	});

	/*$(".chkViajeVuelo").click(function(){
		var opViaje = $(this).val();

		if(opViaje=="R")
			$("#Out_vuelo").show();
		else
			$("#Out_vuelo").hide();
	});*/

	$("#cboHabVuelo").change(function(){
		var cboHab = $("#cboHabVuelo").val();

		$(".filaHabVuelo").hide();

		for(var i=1;i<=cboHab;i++){
			$("#filaHabVuelo_"+i).show();
		}

	});
	
	$("#cboDestino").change(function(){
		$("#txtHotelVuelo").val('Escriba el nombre del Hotel');		
		destino_vuelo = $("#cboDestino").val();
		$(".ac_results").remove();
		$("#txtHotel").autocomplete("/includes/cargarHotelesVentaXDestino.php?destino="+destino_vuelo, {
			width: 260,
			selectFirst: false
		});
	});
	
	$("#btnMostrarLista").click(function(){
		 
		 var destino = $("#cboDestino").val();
		 $(".ac_results").remove();
		 jQuery.facebox("<img src='/recursos/img/cargandoDatos.gif' height='32' width='32' />");				 
		 $("div#facebox div.content").css("width","auto");
		 
		 $.get("/includes/cargarHotelesVentaListado.php",{destino:destino},function(data){
			 sucess:			 		 
		 		jQuery.facebox("<div class='contListHoteles'>"+data+"<div>");
		 		$("div#facebox div.content").css("width","auto");
		 });						 
		 
		 $("#txtHotel").focus();
		 
	 });
	
	$(".opListado").live('click',function(){
		 var id = $(this).attr("id");				 
		 var texto = $(this).attr("title");
		 
		 $("#keyword_hotel").val(id);
		 $("#txtHotel").val(texto);
		 
		 $.facebox.close();
	 });

	$("#cboDestinoVuelo").change(function(){
		$("#txtHotelVuelo").val('Escriba el nombre del Hotel');
		$("#vuelo_keyword_hotel").val('select');
		destino_vuelo = $("#cboDestinoVuelo").val();
		$("#txtHotelVuelo").autocomplete("/includes/cargarHotelesVenta.php?destino="+destino_vuelo, {
			width: 260,
			selectFirst: false
		});
	});

	$(".cboNinoHabVuelo").change(function(){
		var id_grl = $(this).attr("id");
		var valores = id_grl.split("_");
		var id = valores[1];
		var numNinos = $(this).val();

		$("#lbEdadVuelo_"+id).hide();
		$("#cboEdadUnoVuelo_"+id).hide();
		$("#cboEdadDosVuelo_"+id).hide();
		$("#cboEdadTresVuelo_"+id).hide();

		if(numNinos==1){
			$("#lbEdadVuelo_"+id).css("display","block");
			$("#cboEdadUnoVuelo_"+id).show();
		}

		if(numNinos==2){
			$("#lbEdadVuelo_"+id).css("display","block");
			$("#cboEdadUnoVuelo_"+id).show();
			$("#cboEdadDosVuelo_"+id).show();
		}

		if(numNinos==3){
			$("#lbEdadVuelo_"+id).css("display","block");
			$("#cboEdadUnoVuelo_"+id).show();
			$("#cboEdadDosVuelo_"+id).show();
			$("#cboEdadTresVuelo_"+id).show();
		}

	});

	$("#frmVuelos").submit(function(){

		var cboOrigenVuelo = $("#cboOrigenVuelo").val();
		var cboDestinoVuelo = $("#cboDestinoVuelo").val();
		var bookTipo = $("#bookTipo").val();
		var fe_1 = $("#txtCheckInVuelo").val();
		var fe_2 = $("#txtCheckOutVuelo").val();

		if(bookTipo!="Paquetes")
			if(cboOrigenVuelo=="select"){
				alert("Por favor seleccione su origen");
				$("#cboOrigenVuelo").focus();
				return false;
			}

		if(cboDestinoVuelo=="select"){
			alert("Por favor seleccione su destino");
			$("#cboDestinoVuelo").focus();
			return false;
		}
		
		if(bookTipo!="Paquetes")
			if(cboOrigenVuelo==cboDestinoVuelo){
				alert("Por favor seleccione un destino diferente a su origen");
				$("#cboDestinoVuelo").val('select');
				$("#txtDestinoVuelo").val('');
				$("#cboDestinoVuelo").focus();
				return false;
			}

		if(fe_1=="dd/mm/yyyy"){
			alert("Por favor seleccione una fecha");
			$("#txtCheckInVuelo").focus();
			return false;
		}

		if(fe_2=="dd/mm/yyyy"){
			alert("Por favor seleccione una fecha");
			$("#txtCheckOutVuelo").focus();
			return false;
		}

	    desplegarInfoEspera();
	    
		if(bookTipo=="Paquetes")
			$(this).attr("action","/paquetes/procesa_parametros_busqueda.php");
		else
			$(this).attr("action","/vuelos/procesa_parametros_busqueda.php");
			
		return true;

	});

	$(".cboVuelos_ida").change(function(){
		var id = $(this).attr("id");
		var op = $(this).val();
		var op = op.split("#");
		var valor = id.split("-");
		var abuelo = $(this).parent().parent();

		$("tr#"+ abuelo.attr("id") + " td:eq(1) .contenedor_horarios").hide();
		$("#contenedor_horarios_"+valor[1]+"_"+op[0]).show();
	});

	$(".cboVuelos_regreso").change(function(){
		var id = $(this).attr("id");
		var op = $(this).val();
		var op = op.split("#");
		var valor = id.split("-");
		var abuelo = $(this).parent().parent();

		$("tr#"+ abuelo.attr("id") + " td:eq(1) .contenedor_horarios").hide();
		$("#contenedor_horarios_"+valor[1]+"_"+op[0]).show();
	});

	$(".cssBtnCompraHotelAvion").click(function(){
			var valores = $(this).attr("id");
			var id = valores.split("_");
			var datos = $(this).val();

			$("#datosHab").val(datos);
			$("#datosVueloIda").val($("#cboVuelos-ida_"+id[1]).val());
			$("#datosVueloRegreso").val($("#cboVuelos-regreso_"+id[1]).val());
			desplegarInfoEspera();
			$("#frmSeleccionHab").submit();
	});

	//Aqui termina lo de los paquetes

	function desplegarInfoEspera(){

		$('#overlay').show();

    	$('#overlay').fadeIn('fast',function(){
			$('#box').show();
			$('#box').animate({'top':'160px'},700);
	    });
    }

	//Esto es para mostrar los detalles de las tarifas y promos de los hoteles
	$("a.mostrarDetallePrecioHotel").click(function(e){
			e.preventDefault();
	});

    $('a.mostrarDetallePrecioHotel[href][title]').qtip({
      content: {
         text: false // Use each elements title attribute
      },
     style: {
      width: 600,
      name: 'green',
      background:'#f6f6f6',
      border:{color:'#009092',width:6},
      color:'#696969',
      tip: 'topRight'
   },
   position: { adjust: { x: -600, y: 0 } }
   });
    
    
    
    $("#frmNews").submit(function(){
		var datos = $("#frmNews").serialize();
		var txtNombreNews = $("#txtNombreNews").val();
		var txtEmailNews = $("#txtEmailNews").val();

		if(txtNombreNews==""){
			alert("Por favor escriba su Nombre");
			$("#txtNombreNews").focus();
			return false;
		}

		if(txtEmailNews==""){
			alert("Por favor escriba su Email");
			$("#txtEmailNews").focus();
			return false;
		}


		$.post("/newsletter/agregar_correo.php",datos,function(data){
			sucess:
			if(data==0){
				$("#txtNombreNews").val('');
				$("#txtEmailNews").val('');
				alert("Su registro se realizó correctamente, pronto recibirá grandes promociones.");
				return false;
			}else{
				alert("Ocurrió un error al registrarse, por favor intente de nuevo.");
				return false;
			}
		});

		return false;
	});	
    
    //$.each($.browser, function(i, val) {
      //  alert(i+":" +val);
      //});

    
    if($.browser.msie){
    	if($.browser.version>8)
    		$(".header .menu ul li h1 a").css("padding","0 15px");
    }
    
    if($.browser.safari){    	
    		$(".header .menu ul li h1 a").css("padding","0 5px");
    }
    
  //Con esto ocultamos la barra del FB
	$("#iconoCerrarFB a").click(function(e){
		e.preventDefault();
		
		$("#ShareSidebar").remove();
	});
	
	//Con esto abrimos el Chat de la nota de traslado
	$(".txtNotaTraslados a").click(function(e){
		e.preventDefault();
		
		$(".lpStaticButtonTR a").click();
	});

});
