
var quickBookRooms;
var quickBookExperiences;

$(document).ready(function() {
	
	var ShowDestinations = true;
	if (GBPChannel == GBPCHANNELS.CountryClubTasmania || GBPChannel == GBPCHANNELS.WrestPoint) {
		ShowDestinations = false;
	}
	
	quickBookRooms = new SearchBook({
	    API: "gbp/ajaxHandler.ashx?p={channelID}/quicksearch/rooms",
		Level1API: "gbp/ajaxHandler.ashx?p={channelID}/destinations",
		Level2API: "gbp/ajaxHandler.ashx?p={channelID}/destination/{locationID}/products",
	    Template: "gbp/templates/gbp_searchbook.html",
	    ItemTemplate: "gbp/templates/gbp_searchbook_item.html",
		ShowDestinations: ShowDestinations
	});
	
	
	quickBookExperiences = new SearchBook({
		ElementID: "searchBookExp",
		Selector: "#searchBookExp",
	    API: "gbp/ajaxHandler.ashx?p={channelID}/quicksearch/tours",
		Level1API: "gbp/ajaxHandler.ashx?p={channelID}/destinations",
		Level2API: "gbp/ajaxHandler.ashx?p={channelID}/destination/{locationID}/products",
	    Template: "gbp/templates/gbp_searchbook.html",
	    ItemTemplate: "gbp/templates/gbp_searchbook_item.html",
		ShowDestinations: ShowDestinations
	});
	quickBookExperiences.Load("#quickbook-experiences");
	quickBookRooms.Load("#quickbook-rooms");
	
	jQuery("#searchBook, #searchBookExp").undelegate("#btnConfirmBookNow", "click");
	
	jQuery("#searchBook, #searchBookExp").delegate("#btnConfirmBookNow", "click", function() {
	    //Check that product is selected
	    //productSelector.Open(object.SelectedProductData());
	
	    //loader.Show("<img src='images/gbp/loading.gif' /><br/>Loading");
	    //loader.Show();
		var datepickerData = jQuery(this).parent().parent().parent().find("div.datepicker .datepopup").data().datepicker;
		
		var selectedDay = datepickerData.selectedDay.toString().length == 1 ? '0' + datepickerData.selectedDay : datepickerData.selectedDay;
		var selectedMonth = datepickerData.selectedMonth.toString().length == 1 ? '0' + (parseInt(datepickerData.selectedMonth) + 1).toString() : (parseInt(datepickerData.selectedMonth) + 1).toString();
		var selectedYear = datepickerData.selectedYear.toString().length == 1 ? '0' + datepickerData.selectedYear : datepickerData.selectedYear;
		
		// dd/MM/yyyy
		//var selectedDate = selectedDay + '/' + selectedMonth + '/' + selectedYear;
		
		// yyyy/MM/dd
		var selectedDate = selectedYear + '/' + selectedMonth + '/' + selectedDay;
		
		window.location = GetContent($(this).parent().parent().find("#products .level2.item").data().product.Content, "Website").Media[0].Url + "&date=" + selectedDate;
		return false;
	});		
	
	
	jQuery("#quickbook-room-toggle").click(function(){
		jQuery("#quickbook-experience-toggle").removeAttr("checked");
		jQuery("#quickbook-room-toggle").attr("checked", "true");
		
		jQuery("#quickbook-experiences").hide();
		jQuery("#quickbook-rooms").show();
	});
	
	jQuery("#quickbook-experience-toggle").click(function(){
		jQuery("#quickbook-room-toggle").removeAttr("checked");
		jQuery("#quickbook-experience-toggle").attr("checked", "true");
		
		jQuery("#quickbook-rooms").hide();
		jQuery("#quickbook-experiences").show();
	});
	
	jQuery("#quickbook-room-toggle").attr("checked", "true");
	jQuery("#quickbook-experience-toggle").removeAttr("checked");
});



function OnPageShow_QuickBook() {
	$(document).ready(function() {
		jQuery("#quickbook-room-toggle").attr("checked", "true");
		jQuery("#quickbook-experience-toggle").removeAttr("checked");
	});
}

