/*
	Quick Booking js functions
*/

// Promotional code show/hide
function showHidePromoBox () {
	
	if($("div#page div.promocode .promo_entry").css("display") == "none"){
		$("div#page div.promocode .promo_entry").show();
		$("div#page div.promocode a#showpromo").hide();
	}else{
		$("div#page div.promocode .promo_entry").slideUp(100);
	}
	
}

// Open click to talk popup
function openClicktoTalk() {
  window.open("clicktotalk.html","win", "height=498, width=439, toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=no");
}

$(function() {
	
	// set current date to arrival and departure within quick booking
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	if(month < 10) month = "0" + month;
	var day = currentTime.getDate();
	if(day < 10) day = "0" + day;
	var year = currentTime.getFullYear();
	
	$("input#search_from_date").attr("value", day + "/" + month + "/" + year);
	
	var nextDate = new Date(currentTime.valueOf()+(24*60*60*1000)); // 24 hours ahead.
	var next_month = nextDate.getMonth() + 1;
	if(next_month < 10) next_month = "0" + next_month;
	var next_day = nextDate.getDate();
	if(next_day < 10) next_day = "0" + next_day;
	var next_year = nextDate.getFullYear();
	
	$("input#search_to_date").attr("value", next_day + "/" + next_month + "/" + next_year);
	
	// Show promotion code selector
	$("div#page div.promocode a").attr( "href", "javascript:showHidePromoBox()" );
	
	// Set promotional code type
	$("div#page select#promo_select").change(function() {
		$("div#page input#promo_input").attr( "name", $("div#page select#promo_select").attr("value") );
	});
	
	// Trigger click to talk popup
	$("div#page div#clicktotalk a").attr( "href", "javascript:openClicktoTalk()" );
	
	// Initialize loading animation
	$("input#check-availability").click(function() {
	  if (formHelpers.validate()) {
	    $("div.row", $("form#reservation")).hide();
  		$("div.loading-booking", $("form#reservation")).show(); 
  		setTimeout(function() { 
  		  $("div.loading-booking img").attr("src", $("div.loading-booking img").attr("src"));
  		}, 100);
  		return true;
	  } else {
	    return false;
	  }
	});
	
});
