$(document).ready(function() {
	//centraContenido('#content');
	botonContinuar();
	$('.galeria').mndGallery({
        	ancho: 312,
        	height: 358,
        	flechas:true,
        	numeros:false
    });
    $('.ancha').mndGallery({
        	ancho: 600,
        	height: 345,
        	flechas:true,
        	numeros:false
    });
	$('#continuar').click(function() {
		var fechaInicio = $('#entrada').val();
		var fechaFin = $('#salida').val();
		var selectedRooms = new Array();
		$("input[@name='alojamiento[]']:checked").each(function() {
			selectedRooms.push($(this).val());
		});
		var reservas = new Array();
		$(".paxes").each(function() {
			var idSel = $(this).attr('id').split('pax_');
			var idRoom = idSel[1];
			if ($.inArray(idRoom, selectedRooms) >= 0) { // Returns index of value in array. Returns -1 if array does not contain value.
				reservas.push(idRoom + '#' + $(this).val());
			}
		});
		$.ajax({
	        type: "post",
	        url: "inc/calls/get-prices.php",
	        cache: false,
	        context: document.body,
	        data: "fechaInicio=" + fechaInicio + "&fechaFin=" + fechaFin + "&reservas=" + reservas,
	        success: function(param) {
				$('#presupuesto').html(param);
				var f1 = fechaInicio.split('/');
				var f2 = fechaFin.split('/');
				$('.mEntrada').html(f1[1] + '/' + f1[0] + '/' + f1[2]);
				$('.mSalida').html(f2[1] + '/' + f2[0] + '/' + f2[2]);
				// Datos para enviar el correo.
				$('#fechaEntrada').val(f1[1] + '/' + f1[0] + '/' + f1[2]);
				$('#fechaSalida').val(f2[1] + '/' + f2[0] + '/' + f2[2]);
				$('#datosReserva').val(param);
			}
		});
	});
	
	$('form').submit(function() {
		var eMust = $(this).find('.must');
		eMust.removeClass('error').each(function() {
			if ($(this).val() == '' || ($(this).attr('name') == 'email' && !checkEmail($(this).val()))) {
				var thisValue = $(this).attr('name');
				$(this).parent().parent().children().each(function () {
					if ($(this).attr('id') == thisValue) {
						thisValue = $(this).html();
					}
				});
				alert(errtxt[0] + ': ' + thisValue);
				$(this).addClass('error');
			}
		});
		if (eMust.hasClass('error')) {
			return false; 
		}
		return true;
	});
	
});

