
	//when the document is ready.
  $(document).ready(function() { 
	
				
	 var options = { 
	        target:        '#response',   // target element(s) to be updated with server response 
	        beforeSubmit:  showRequest,  // pre-submit callback 
	        success:       showResponse  // post-submit callback 

	    }; 
		
		// //get todays date.
		// var today = new Date();
		// var year = today.getYear();
		// var day = today.getDate();
		// var month = today.getMonth()+1;
		// 
		// // Leading  zero
		// if(day<10) day = "0" + day
		// 	    if(month<10) month= "0" + month
		// if(year<1000) year+=1900
		// 
		// $('#dateinput').val(year+"-"+month+"-"+day);
		
	    // bind form using 'ajaxForm' 
	    $('#myForm').ajaxForm(options);
	
		// pre-submit callback 
		function showRequest(formData, jqForm, options) { 
		    // formData is an array; here we use $.param to convert it to a string to display it 
		    // but the form plugin does this for you automatically when it submits the data 
		    var queryString = $.param(formData); 

		    return true; 
		} 

		// post-submit callback 
		function showResponse(responseText, statusText)  { 

		}
		
		
	$(".calendar").datepicker({minDate: 'd', dateFormat: 'dd-mm-yy', onSelect:
	function(dateText){
		$('#dateinput').val(dateText);
		$('#myForm').ajaxSubmit(options);
	}
	});//minimum date today.
	
	
	// $("#dateinput").datepicker({minDate: 'd', dateFormat: 'yy-mm-dd', inline:true});//minimum date today.

	$('#myForm').ajaxSubmit(options);
});


function next(){

	$date = $('#dateinput').val();
	
	
	$.post("libs/functions/submit/check_availability_submit.php", {go: "next", date: $date},
		function(data){
			// alert("Data Loaded: " + $data);
			$('#response').html(data);
			
			$('#dateinput').val($('#ddid_d',data).html());
			//$('#dateinput').val($date);
		});
	
}

function goto(url){
	window.location =url;
	// $(window).load(url);
}

function previous(){
		$date = $('#dateinput').val();


		$.post("libs/functions/submit/check_availability_submit.php", {go: "previous", date: $date},
			function(data){
				// alert("Data Loaded: " + $data);
				$('#response').html(data);
				$('#dateinput').val($('date',data).html());
				//$('#dateinput').val($date);
			});
}

function booking(datein, suiteNumberin){
	// alert($date);
	// alert($suiteNumber);
	//http://hkbh.dev/index.php?target=check
	// $.post("http://hkbh.dev/index.php?target=booking",{date: $date, suite_id: $suiteNumber});
	// $.post("libs/functions/book.php",{date: $date, suite_id: $suiteNumber});
	//var url = "libs/functions/book.php?date="+date+"&suite_id="+suiteNumber;
	
	var url = "/index.php?target=booking";
	
	$("html").load(url,{date: datein, suite_id: suiteNumberin});
	
	//$.get("libs/functions/book.php?date="+date+"&"+suiteNumber);
}

