$(function() {

	// Date picker
	Date.firstDayOfWeek = 7;
	Date.format = "dd-mm-yyyy";
	
	// From Date
	$("input#period_from_top")
		.datePicker(
			{clickInput:true}
		)
		.bind("click",
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		);
	
	$("#period_from_top").dpSetPosition($.dpConst.POS_TOP, $.dpConst.POS_RIGHT);
	
	$("input#period_from_top").bind("dpClosed", function (e, selectedDates) {
	
		// Get first
		var d = selectedDates[0];
		
		// Check for date
		if (d) {
			
			// Build date
			var d = new Date (d);
			$("input#period_till_top").dpSetStartDate(d.addDays(1).asString());
		}
	});	
	
	// Till date
	$("input#period_till_top")
		.datePicker(
			{clickInput:true}
		)
		.bind("click",
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		);
	
	$("#period_till_top").dpSetPosition($.dpConst.POS_TOP, $.dpConst.POS_RIGHT);
	
	$("input#period_till_top").bind("dpClosed", function (e, selectedDates) {
	
		// Get last
		var d = selectedDates[0];
				
		// Check for date
		if (d) {
			
			// Build date
			var d = new Date (d);
			$("input#period_from_top").dpSetEndDate(d.addDays(-1).asString());
		}
	});
});

// Set top search bookable function
function set_top_seach_bookable_function () {
	
	var display_book_date_title = document.getElementById("book_date_title").style.display;
	var display_book_date_top = document.getElementById("book_date_top").style.display;

	if (display_book_date_title == 'block') {
		
		document.getElementById("book_date_title").style.display = "none";
		
	} else {
		
		document.getElementById("book_date_title").style.display = "block";
	}
	
	if (display_book_date_top == 'block') {
		
		document.getElementById("book_date_top").style.display = "none";
		
	} else {
		
		document.getElementById("book_date_top").style.display = "block";
	}
}