function selectTab(idTab, parameters, ignore) {
	$('#hotel_tabs li').removeClass('selected').addClass('unselected');
	url = '?id=' + hotelId + '&ajax=1&subseccion=' + idTab;
	if (parameters) {
		url = url + '&' + parameters;
	}
	$('#hotel_tabs li.' + idTab).removeClass('unselected').addClass('selected');
	$('#tab_contents').html($('#tab_loader').html());
	$('#tab_contents').load(url);
}

function calculateReservationPrice() {
	var roomTypes = new Array();
	var roomTypeOffers = new Array();

	$('#room_types tr').each(function() {
		var matches = new Array();
		if (this.id && (matches = this.id.match(/^room\_type\_(\d+)$/))) {
			var idRoomType = parseInt(matches[1]);
			roomTypes.push({
				'id'     : idRoomType,
				'price' : parseFloat($('#room_price_' + idRoomType).html().replace('.', '').replace(',', '.')),
				'count'  : parseInt($('#room_count_' + idRoomType).val())
			});
		}
	});

	$('#room_type_offers tr').each(function() {
		var matches = new Array();
		if (this.id && (matches = this.id.match(/^room\_type\_offer\_(\d+)$/))) {
			var idRoomType = parseInt(matches[1]);
			roomTypeOffers.push({
				'id'	: idRoomType,
				'price'	: parseFloat($('#room_price_offer_' + idRoomType).html().replace('.', '').replace(',', '.')),
				'count'	: parseInt($('#room_count_offer_' + idRoomType).val())
			});
		}
	});


	var idRoomType, priceTotal = 0.0;
	for (var i = 0; i<roomTypes.length; i++) {
		priceTotal += (roomTypes[i].price * roomTypes[i].count);
	}

	for (var i = 0; i<roomTypeOffers.length; i++) {
		priceTotal += (roomTypeOffers[i].price * roomTypeOffers[i].count);
	}

	priceTotal = Math.round(priceTotal * 100);
	priceTotal += '';
	if (priceTotal == '0') {
		priceTotal = '000';
	}
	var rest = ',' + priceTotal.substr(priceTotal.length - 2);
	priceTotal = priceTotal.substr(0, priceTotal.length - 2);
	while (priceTotal.length > 3) {
		rest = '.' + priceTotal.substr(priceTotal.length - 3) + rest;
		priceTotal = priceTotal.substr(0, priceTotal.length - 3);
	}
	priceTotal += rest;

	$('#reservation_price').val(priceTotal);
}

function submitReservationRequest(frmReservation) {
	var reservationDetails = new Array();
	var go = false;
	var roomCountTest = /^room\_count\_\d+$/;
	var roomCountTestOffer = /^room\_count\_offer\_\d+$/;

	$('#frm_reservation :input').each(function() {
		if ((this.value == '') || (this.value == '0')) {
		 return;
		}
		if (roomCountTest.test(this.name) && this.value != 0) {
			go = true;
		}
		 if (roomCountTestOffer.test(this.name) && this.value != 0) {
			go = true;
		}
		reservationDetails.push(this.name + '=' + this.value);
	});
	if (go) {
		var queryString = reservationDetails.join('&');
		document.location.href = frmReservation.action + '?' + queryString;
	} else {
		window.alert('Por favor, seleccione algún tipo de habitación para realizar la reserva.');
	}
}

function viewRoomTypeDetails(idRoomType) {
	if ($('#room_type_' + idRoomType + '_details').is(':visible')) {
		$('#room_type_' + idRoomType + '_details').fadeOut();
	} else {
		$('#room_type_' + idRoomType + '_details').fadeIn();
	}
}