// JavaScript Document
jQuery(document).ready(function(){
    
	/*$("#ubicacion_hoteles").hover(function(){
                   $("#mapa").trigger("click");
	});
    
	$(".group1").hover(function(){
                   $("#mapa1").trigger("click");
	});*/ 
	
	$(".ajax").colorbox();
	$(".group1").colorbox();
	$(".group2").colorbox();
	$(".grupo1").colorbox();
	$(".grupo2").colorbox();	
        
	
	
	
	//Configuracion de las fechas
	$("input.input").datepicker({minDate:2,onClose:function(input){moverDia($(this).attr("id"));},numberOfMonths: 1});
	
	
	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);
			}
		}
	}
	
	
	$(".search").css("height","220px");
	$(".cboRooms").val(1);
	
	$(".cboRooms").change(function(){
	    var valor = $(this).val();
	    
	    if(valor==1){
		$("#room_two").hide();
		$("#room_tree").hide();
		$(".search").css("height","220px");
	    }
	    
	    if(valor==2){
		$("#room_two").show();
		$("#room_tree").hide();
		$(".search").css("height","243px");
	    }
	    
	    if(valor==3){
		$("#room_two").show();
		$("#room_tree").show();
		$(".search").css("height","270px");
	    }
	    
	    
	});
	
	
	
	
	
	
	
	
	
	
	
	//Con esto ocultamos la barra del FB
	$("#iconoCerrarFB a").click(function(e){
		e.preventDefault();
		
		$("#ShareSidebar").remove();
	});
	
	   $("#ver").click(function(eventoo){
		      if ($("#ver").attr("checked")){
		         $(".coin-slider").css("display", "block");
		      }else{
		         $(".coin-slider").css("display", "none");
		      }
		   });
								
	$("#nyroModalImg").click(function(){
									  
	});							

	if($('#middle_img').length)
		$('#middle_img').cycle();
	
	/*$('#banners_mini').cycle({
	 delay:  2000,
     speed:  100
	});*/
	$(".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*/
	
	     
			
			

            
			
			
			

			

/*
			verificaSiAceptaNinios();

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

			function verificaSiAceptaNinios(){

				var cboHotel = $("#cboHotel").val();
				$("#contenedor-edades").empty();
				$("#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();
							$("#lbKids").hide();
		         		}else{
		         			$("#cboNinio").show();
							$("#lbKids").show();
		         		}
		         });
			}
			
			*/

			$("#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;

	});



/*DECLARACION DE EVENTOS POR EL PROGRAMADOR */


/* Fin evento agregado para que al retroceder me compruebe la fecha elegida y asi poner una fecha posterior */

/*EL CUAL FUNCIONA ATRAVEZ DEL IDENTIFICAR SELECT Y QUE ADEMAS ESTE SE ENCUENTRA EN EL ARCHIVO SEARCH.PHP,  UNA VEZ IDENTIFICADO EL VALOR DEL SELECT CREAMOS YA SEA 1, 2, 3 OPCIONES CON SUS RESPECTIVOS NOMBRES (cboadult1, cboadult2, cboadult3) */

$("#select").ready( function(){
	
var total =	$("#select").val()
if (total == 1){
	$("#room_one").fadeIn();
	$("#room_two").fadeOut();
	$("#room_tree").fadeOut();
	
}
if (total == 2){	
    $("#room_one").fadeIn();
    $("#room_two").fadeIn();
	$("#room_tree").fadeOut();
	
	
}
if (total == 3){
	$("#room_one").fadeIn();
	$("#room_two").fadeIn();
	$("#room_tree").fadeIn();	
}
		
});







$("#enviar").click( function(){
// Prevent the default event.
$(".opciontraslado").each(function(i) {
estado = $(this).attr("checked");
if(estado) {
valores = $(this).attr("value");
$("#txtTraslado").val(valores);
}
});


valor= "";
$("[id^='abrir_tour_']").each(function() { 
  var id = parseInt(this.id.replace("abrir_tour_", "")); 
  var cboPaquete = $("#abrir_tour_" + id); 
  var tours= new Array(30) 


cboPaquete.each(function(i) {
				 
estado = $(this).attr("checked");
if(estado) {
	
valores = $(this).attr("value");


var Option = $("#sgOption_" + valores); 
var Paquete= $("#cboPaquete_" + valores);
var FecServ= $("#txtFechaServicio_" + valores);
var Adulto= $("#cboAdulto_" + valores);
var Opt = Option.val(); 
var Paq = Paquete.val(); 
var FeS= FecServ.val(); 
var Adult= Adulto.val();

valor += valores + "#" + Opt + "#" + Paq + "#" + FeS + "#" + Adult + "|";


}


});
});
$("#txtTours").val(valor);


$("#frmHotelReservation").submit();
});




var container = $("#gourmet_1");
var container2 = $("#gourmet_2");

$("#gourmet_abrir1").click( function( event ){
// Prevent the default event.
event.preventDefault();

// Toggle the slide based on its current
// visibility.
if (container.is( ":visible" )){ 

// Hide - slide up.
container.slideUp();
 
} else { 

// Show - slide down.
container.slideDown();
 
}
}
);


$("#gourmet_abrir2").click( function( event ){
// Prevent the default event.
event.preventDefault();

// Toggle the slide based on its current
// visibility.
if (container2.is( ":visible" )){ 

// Hide - slide up.
container2.slideUp();
 
} else { 

// Show - slide down.
container2.slideDown();
 
}
}
);


$("a#show-panel").click(function(){
// $("#lightbox, #lightbox-panel").fadeIn(2000);
 $("#lightbox, #lightbox-panel").slideDown(800);

 });
 $("a#close-panel").click(function(){
 $("#lightbox, #lightbox-panel").fadeOut(800);

 });



$("a[id^='gourmet_abrir_']").each(function() { 
  var id = parseInt(this.id.replace("gourmet_abrir_", "")); 
  var airline = $("#gourmet_abrir_" + id); 
  var container = $("#gourmet_" + id);

airline.click( function( event ){
// Prevent the default event.
event.preventDefault();

if (container.is( ":visible" )){ 

// Hide - slide up.
container.slideUp();
 
} else { 

// Show - slide down.
container.slideDown();
 
}

});

}); 



$("[id^='opcionhabitacion_']").each(function() { 
  var id = parseInt(this.id.replace("opcionhabitacion_", "")); 
  var oprimir_habitacion = $("#opcionhabitacion_" + id);
  var container = $("#numero_" + id);
  var valor = container.val();
  oprimir_habitacion.click( function(){						
			
			document.form2.cboHabitacion.value = valor;
 					
  });
}); 


$("#mover_carrito_booking").click(function(){
								   
$(".form-habitacion_booking").submit();		

});







$("#mover_carrito").click(function(){
								   
$(".form-habitacion").submit();		

		   
/*							   
$numero_habitacion = $("#cboHabitacion").val();								   
								   
var container = $("#opcionhotel_" + $numero_habitacion);

valores = container.val()
listaValores = valores.split(",");

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

});

$("#frmHotelReservation").submit();
*/


});


$("a[id^='cssBtnCompraHotel_']").each(function() { 
  var id = parseInt(this.id.replace("cssBtnCompraHotel_", "")); 
  var airline = $("#cssBtnCompraHotel_" + id); 
  var container = $("#opcionhotel_" + id);

airline.click( function( event ){
// Prevent the default event.
event.preventDefault();

valores = container.val()
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();


});

}); 



$("[id^='txtFechaServicio_']").each(function() { 
  var id = parseInt(this.id.replace("txtFechaServicio_", "")); 
  var airline = $("#txtFechaServicio_" + id); 
  var airline2 = $("#abrir_tour_" + id); 
  var container = $("#div_c_recom_" + id); 
 
 airline.datepicker({
					inline:false,
					showOn:'button',
					buttonImage:'/images/calendario/calendar.jpg',
					buttonImageOnly:true,
					minDate:'+0d',  //d m w y
					defaultDate:'+2d',
					'dateFormat': 'mm/dd/yy',
					onClose:function(input){moverDia($(this).attr("id"));}    
					
					
			});	
 
  

 airline2.click( function( event ){
// Prevent the default event.


if (container.is( ":visible" )){ 

// Hide - slide up.
container.slideUp();

 
} else { 

// Show - slide down.
container.slideDown();

}

});


  
});




 $().ajaxStart(function() {
        $('#loading').show();
        $('#result').hide();
    }).ajaxStop(function() {
        $('#loading').hide();
        $('#result').fadeIn('slow');
		
    });
 
 
    $('#fo3').submit(function() {
    	
    	var nombre = $("#nombre").val();		
		var tel = $("#tel").val();
		var email = $("#email").val();
		var cboHotel = $("#cboHotelC").val();
		var coments = $("#coments").val();

		if(nombre==""){
			alert("Please enter your Name");
			$("#nombre").focus();
			return false;
		}

		if(tel==""){
			alert("Please enter your Telephone");
			$("#tel").focus();
			return false;
		}
		
		if(email==""){
			alert("Please enter your Email");
			$("#email").focus();
			return false;
		}
		
		if(cboHotel=="select"){
			alert("Please select your Hotel");
			$("#cboHotelC").focus();
			return false;
		}
		
		if(coments==""){
			alert("Please enter your Comments");
			$("#coments").focus();
			return false;
		}
    	
    	
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function(data) {
                //$('#result').html(data);
				if(data == 1){
					alert("Thank you for using our services.");
					$('.rowElem').val("");	
					$("#coments").val('');
					
					}else if(data == 3){
					alert("Thank you for contacting us, but the text image is incorrect.");
					//alert(data);
					}else {
					alert("Thank you for contacting us, but there is an error while sending your email.. Please Try again.");	
					//alert(data);
					}

            }
        })
        
        return false;
    });
	
	
   $('#fo6').submit(function() {
	   
	   var nombre = $("#nombre").val();		
		var tel = $("#tel").val();
		var email = $("#email").val();
		var cboHotel = $("#cboHotelC").val();
		var coments = $("#coments").val();

		if(nombre==""){
			alert("Por favor, ingrese su Nombre");
			$("#nombre").focus();
			return false;
		}

		if(tel==""){
			alert("Por favor, ingrese su Teléfono");
			$("#tel").focus();
			return false;
		}
		
		if(email==""){
			alert("Por favor, ingrese su Email");
			$("#email").focus();
			return false;
		}
		
		if(cboHotel=="select"){
			alert("Por favor, seleccione su Hotel");
			$("#cboHotelC").focus();
			return false;
		}
		
		if(coments==""){
			alert("Por favor, ingrese sus Comentarios");
			$("#coments").focus();
			return false;
		}
	   
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function(data) {
                //$('#result').html(data);
				if(data == 1){
					alert("Gracias por usar nuestros servicios.");
					$('.rowElem').val("");	
					$("#coments").val('');
					
					}else if(data == 3){
					alert("Gracias por contactar con nosotros, pero la imagen de texto es incorrecto.");
					//alert(data);
					}else {
					alert("Gracias por contactar con nosotros, pero hay un error al enviar su correo electronico. Int�ntalo de nuevo.");	
					//alert(data);
					}

            }
        })
        
        return false;
    });
	
	

    $().ajaxStart(function() {
        $('#loading').show();
        $('#result2').hide();
    }).ajaxStop(function() {
        $('#loading').hide();
        $('#result2').fadeIn('slow');
    });
    $('#fo1').submit(function() {
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function(data) {
                $('#result2').html(data);

            }
        })
        
        return false;
    });
    
    $('#enviar_correo').click(function() {
      $('#fo1').submit();
    });    
    
    
    $('#fox').submit(function() {
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function(data) {
		$("#correo").val("- - - - - - - - Ingresa tu correo electronico - - - - - - - -");
                //$('#result2').html(data);
		if(data == "Thanks For Register Your Email! "){
		alert("Gracias por Registre su correo electronico");
		}else{
		alert("Por favor ingrese un email valido");	
		}

            }
        })
        
        return false;
    });



if ($("#block").length) {
$('#block').nyroModal({
			'blocker': '#block'
});
}




/*FIN DEL EVENTO AGREGADO POR EL PROGRAMADOR*/




/*PROMOCIONES SOBRE EL SLIDER PRINCIPAL*/
/*
$('#coin-slider').coinslider({ 
	width: 230, // width of slider panel
	height: 290, // height of slider panel
	spw: 7, // squares per width
	sph: 5, // squares per height
	delay: 5000, // delay between images in ms
	sDelay: 30, // delay beetwen squares in ms
	opacity: 0.7, // opacity of title and navigation
	titleSpeed: 500, // speed of title appereance in ms
	effect: '', // random, swirl, rain, straight
	navigation: true, // prev next and buttons
	links : true, // show images as links
	hoverPause: true // pause on hover			

});*/

});



function abrir_ventana(cambio){
    if (cambio == 1){
	$("#room_one").fadeIn();
	$("#room_two").fadeOut();
	$("#room_tree").fadeOut();
	}
    if (cambio == 2){	
	$("#room_one").fadeIn();
    $("#room_two").fadeIn();
	$("#room_tree").fadeOut();
	}
    if (cambio == 3){
	$("#room_one").fadeIn();
	$("#room_two").fadeIn();
	$("#room_tree").fadeIn();
	}
}
function abrir_ventana_habitacion(cambio){
    if (cambio == 1){
	$("#room_one_habitacion").fadeIn();
	$("#room_two_habitacion").fadeOut();
	$("#room_tree_habitacion").fadeOut();
	}
    if (cambio == 2){	
	$("#room_one_habitacion").fadeIn();
    $("#room_two_habitacion").fadeIn();
	$("#room_tree_habitacion").fadeOut();
	}
    if (cambio == 3){
	$("#room_one_habitacion").fadeIn();
	$("#room_two_habitacion").fadeIn();
	$("#room_tree_habitacion").fadeIn();
	}
}


function closeModal(){
        // removemos divs creados
        $('#bgmodal').remove();
        $('#bgtransparent').remove();
}

 



function preloadImg(image) {
			var img = new Image();
			img.src = image;
}
		
preloadImg('/img/ajaxLoader.gif');
preloadImg('/img/prev.gif');
preloadImg('/img/next.gif');
preloadImg('/images/calendario/calendar.jpg');
		

function cambiaFoto(destino, imagen)
{
var foto=document.getElementById(destino);
foto.src=imagen;
//foto.width='500';
}

function popUp(URL) {
day = new Date();
id = day.getTime();
//window.showModalDialog(URL, "dialogHeight: 280px; dialogWidth: 280px; dialogTop: 100px; dialogLeft: 100px; center: no; resizable: no; status: no;");
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0, width=600,height=490,resizable=no');");
}

function features(contenido,titulo){

document.getElementById('contenid').innerHTML = "";

r = 0;	
	
var elem = contenido.split('|');

var cadena = "";
cadena += "<center><h5 style='color:#D17E08;font-family:'Times New Roman', Times, serif;font-size:18px;font-style:oblique;'>"+titulo+"</h5></center>";
cadena += "<center><h5>Room features</h5></center><br>";
cadena += "<ul>";
for(i = 0; i < elem.length - 1; i++){
	
	if(r == i){
    cadena +=  "<li style='background-color:#f7f7f7; padding-top:5px'><img src='/../images/bullet_required.png' ></img>&nbsp;&nbsp;&nbsp;"+elem[i]+"</li>";
    r = r + 2;
    }else {
    cadena +=  "<li style=' padding-top:5px'><img src='/../images/bullet_required.png' ></img>&nbsp;&nbsp;&nbsp;"+elem[i]+"</li>";
    }
	
}
cadena	+= "</ul><br><br>";

document.getElementById('contenid').innerHTML = cadena;
	
}



	
function carga_habitacion($numero_habitacion){
var container = $("#opcionhotel_" + $numero_habitacion);

valores = container.val()
listaValores = valores.split(",");

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

});

tot = $("#txtPrecioTotal").val();

if(tot > 0){
$("#frmHotelReservation").submit();
}else{
alert("This room is not available in the dates you have chosen. Please try other dates");
}
}

function obtenerHotel(valor){
$('#cboHotel_book').val(valor);
}

function nav(value){ 
if (value != "") { location.href = value; } 
} 



