$(document).ready(function() {
	$(".booking input.date").datepicker({
		minDate: $("#min_checkin_date").val(),
		dateFormat: 'yy-mm-dd'
	});

	$(".booking form").submit(function(){
		var checkinDate = $(".booking #check_in").val();
		var checkoutDate = $(".booking #check_out").val();
		if(checkinDate == ""){
			openAlertDialog("Please specify a checkin date.");
		}else if(checkoutDate == ""){
			openAlertDialog("Please specify a checkout date.");
		}else if(checkinDate < checkoutDate){
			return true;
		}else{
			openAlertDialog("Checkout date must be greater than checkin date.")
		}
		return false;
	});
	
	var dialogBox;
	function openAlertDialog(msg){
		var content = '<p>' +
		'<span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-alert"></span>' +
		'<strong>Alert</strong><br/><br/>' + msg +
		'</p>';
		if(dialogBox){
			dialogBox.remove();
		}
		dialogBox = $(content).dialog({
			modal: true,
			draggable: true
		});
	}
});
