﻿/********************************/
/* hotelListing.js				*/
/*	- Implements "abstract"		*/
/*		loadHotelListing() and	*/
/*		viewHotelDetails()		*/
/*	- Requires hotelResults.js	*/
/*	- Requires Planner.ascx		*/
/********************************/

/************/
/* On Ready */
/************/

$(document).ready(function() {
	updateDestination(false);
	getUpdateButton().hide();
	getNoResultsMessage().hide();

	$('#lnkCoupons').click(function() {
		openCouponDialog();
	});
});

/*****************/
/* Hotel Listing */
/*****************/

var resyncPlannerFunction = null;

function updateCalendarItems() {
	if (resyncPlannerFunction != null) {
		resyncPlannerFunction();
	}

	getUpdateButton().fadeIn('slow');
}

function updateDestination(showButton) {
	setTicketID("-1");

	if (showButton) {
		updateCalendarItems();
	}
}

function updateLocationContent() {
	var $destination = getDestination();
	var destinationText = $destination.html();
	var destinationBannerSrc = $destination.attr('HotelListing.Banner');

	if (!destinationBannerSrc) {
		destinationBannerSrc = '';
	}

	// Set page title, page heading, location heading, and package banner
	document.title = $('[ID*=hdnPageTitle]').val().replace(/{locationName}/g, destinationText);

	var $pageHeading = $('[ID*=hHeading]');
	$pageHeading.eq(0).html($pageHeading.attr('unformatted').replace(/{locationName}/g, destinationText));

	var $locationHeading = $('.bubble_heading_text');
	$locationHeading.eq(0).html($locationHeading.attr('unformatted').replace(/{locationName}/g, destinationText));

	$('[ID*=imgGatAd]img').attr('src', destinationBannerSrc);
}

function planVacationClicked() {
	var ages = planVacation_getChildAges();

	for (var index = 0; index < ages.length; index++) {
		if (ages[index] < 0) {
			planVacation_getActionButton().siblings('img').remove();
			delete ages;
			alert('Invalid child age(s) selected.');
			return false;
		}
	}
	
	delete ages;

	getMapsLink().hide();
	getNoResultsMessage().hide();
	hotelResults_refresh(hotelResults_getContainer(), 1, true);
	updateLocationContent();
}

/****************************/
/* Abstract Implementations */
/****************************/

function loadHotelListing(subsetIndex, reloadTickets) {
	hotelResults_refresh(hotelResults_getContainer(), subsetIndex, reloadTickets);

	getUpdateButton().fadeOut('slow');
	getMapsLink().hide();
	getNoResultsMessage().hide();
	updateLocationContent();
}

function viewHotelDetails(selectorText, itemText, hotelGroupID, hotelID, checkIn) {
	openHotelDialog(itemText, hotelGroupID, hotelID, checkIn, selectorText);
}

/******************************/
/* Accessor/Mutator Functions */
/******************************/

// Selected Destination
function getDestination() {
	return $('[ID*=ddlDestination]').children(':selected');
	
}

// Sort
function getSortOption() {
    return $('[ID*=rblSortOptions]:checked').val();
}

// Special
function getSpecialID() {
	debugger;
	return $('[ID*=hdnSpecialID]').val();
}
		
function setSpecialID(value) {
	$('[ID*=hdnSpecialID]').val(value);
}

// Ticket ID
function getTicketID() {
	var ticketID = $('[ID*=hdnTicketID]').val();

	if (ticketID)
		return ticketID;
	else
		return '0';
}

function setTicketID(value) {
	$('[ID*=hdnTicketID]').val(value);
}

// Banner
function getUpdateButton() {
	return $('[ID*=lnkImgUpdate]');
}

function getMapsLink() {
	return $('#maps');
}

// No Results Message
function getNoResultsMessage() {
	return $('#noResultsMessage');
}