// JavaScript Document
jQuery(document).ready(function(){

	$('#middle_img').cycle();
	$('#banners_mini').cycle({
	 delay:  2000,
     speed:  500
	});
	$(".rollover").hover(
		 function()
		 {
		  this.src = this.src.replace("_off","_on");
			$("#boton_boletin").hide();

		 },
		 function()
		 {
		  this.src = this.src.replace("_on","_off");
		 }
	);

	$(".weddings_menu").click( function(){
		var referencia= $(this).attr("id");
		$("#cat_"+referencia).toggle("slow");
		return false;
	});

	$(".chat_online").click(function(){
		$.post("/php/control_sitio_chat.php","",function(){});
	});

	/*CODIGO PARA EL MOTOR*/

			$('#txtFechaIn').datepicker({
					inline:false,
					showOn:'button',
					buttonImage:'/images/calendario/calendar.gif',
					buttonImageOnly:true,
					minDate:'+2d',  //d m w y
					defaultDate:'+2d',
					'dateFormat': 'dd/mm/yy',
					onClose: function(input) {
						         $.post("/php/recorreFecha.php",{txtFechaIni:input,dias:1,op:"sum"},function(data){
						         	sucess:
						         		$('#txtFechaOut').val(data);
						         });
					}
			});

			$('#txtFechaOut').datepicker({
					inline:false,
					showOn:'button',
					buttonImage:'/images/calendario/calendar.gif',
					buttonImageOnly:true,
					minDate:'+3d',  //d m w y
					defaultDate:'+3d',
					'dateFormat': 'dd/mm/yy'
			});

			$(".ui-datepicker-trigger").click(function(e){
				e.preventDefault();
			});

			verificaSiAceptaNinios();

			$("#cboHotel").change(function(){
				verificaSiAceptaNinios();
			});

			function verificaSiAceptaNinios(){

				var cboHotel = $("#cboHotel").val();
				$("#contenedor-edades").empty();
				$("#cboNinio").show();
				$("#cboNinio").val(0);

				if (cboHotel=="Select")
					return false;

				$.post("/templates/verificarSiAceptaNinios.php",{cboHotel:cboHotel},function(data){
		         	sucess:
		         		$("#txtEdadMinima").val(data);
		         		if (parseInt(data)>=18){
							$("#cboNinio").hide();
		         		}
		         });
			}

			$("#cboNinio").change(function(){

				var numNinos = parseInt($("#cboNinio").val());
				var EdadMinima = parseInt($("#txtEdadMinima").val());
				var listaEdades = "";

				var cboHotel = $("#cboHotel").val();

				if (cboHotel=="Select")
					return false;

				if (numNinos>0){
					for (var i=1;i<=numNinos;i++){
						listaEdades += '<label>Age '+i+':</label>';
						listaEdades += '<select class="cbo_pax" id="cboEdad'+i+'" name="cboEdad'+i+'">';

						for (var j=EdadMinima;j<=17;j++)
						if (j<10)
							listaEdades += '<option value="0'+j+'">'+j+'</option>';
						else
							listaEdades += '<option value="'+j+'">'+j+'</option>';

						listaEdades += "</select>";
					}

					listaEdades = "<span>Please provide Children's ages:</span>" + listaEdades;
				}

				$("#contenedor-edades").empty().append(listaEdades);

			});

			$(".more_rooms").click(function(e){
				e.preventDefault();
				$(".fila_tarifas:gt(1)").toggle();
			});

			$("#deselect_traslado").click(function(event){
				event.preventDefault();
				$(".opciontraslado").attr("checked","");
			});

			/*Aqui se procesa el detalle de compra para los Hoteles*/
			$(".cssBtnCompraHotel").click( function(){

				var estado = false;
				var valores = "";
				var listaValores = "";

				//Con esto envio la habitacion selecionada
		      	$(".opcionhotel").each(function(i) {
						estado = $(this).attr("checked");
		      			if(estado) {
		      				valores = $(this).attr("value");
		      				listaValores = valores.split(",");
		      			}
		      	});

				$("#frmHotelReservation").find("input").each(function(indice,id){
		      		$(id).attr("value",listaValores[indice]);
		      	});

		      	//Con esto envio el traslado seleccionado
		      	$(".opciontraslado").each(function(i) {
						estado = $(this).attr("checked");
		      			if(estado) {
		      				valores = $(this).attr("value");
		      				$("#txtTraslado").val(valores);
		      			}
		      	});

				$("#frmHotelReservation").submit();
			});
	/*FIN DEL CODIGO MOTOR*/

	$("#EnviarForma").click( function(){

		if( $("#nombre_persona").val() == "" )
		{
			alert("Please insert your Name");
			return false;
		}

		if( $("#telefono_persona").val() == "" )
		{
			alert("Please insert your Phone Number");
			return false;
		}

		if( $("#c_email").val() == "" )
		{
			alert("Please insert your Email");
			return false;
		}

		if( $("#sel_topic").val() == "none" )
		{
			alert("Please select a topic");
			return false;
		}

		if( $("#sel_hotel").val() == "none" )
		{
			alert("Please select an Hotel");
			return false;
		}

		if( $("#c_comentario").val() == "" )
		{
			alert("Please insert a comment");
			return false;
		}

		var datos_frm = $("#form1").serialize();
		$.post("enviarcomentario.php",datos_frm, function(data){
			success:
				alert(data);
				$('#form1')[0].reset();

		});

		return false;

	});

});