function checkFreeRoom() {
	
	var startDate = $('select[name="ariveyear"]').val() + "-" + $('select[name="ariveday"]').val() + "-" + $('select[name="arivemonth"]').val();
	var endDate = $('select[name="departureyear"]').val() + "-" + $('select[name="departureday"]').val() + "-" + $('select[name="departuremonth"]').val();

/*
    $.ajax({
        cache: false,
        dataType: 'json',
        /*
        data : {
				"type" : "721",
				"tx_lioncastlefreeroom_pi1[roomType]" : $("#room").val(),
				"tx_lioncastlefreeroom_pi1[startDate]" : startDate,
				"tx_lioncastlefreeroom_pi1[endDate]" : endDate,
				"tx_lioncastlefreeroom_pi1[checkIn]" : $('select[name="checkin"]').val(),
				"tx_lioncastlefreeroom_pi1[checkOut]" : $('select[name="checkout"]').val()
        },
        */
        url: window.location,
        success: function (data) {
			if(!data.is_free) {
				$('.room_is_busy').show();
			}
			else {
				$('.room_is_busy').hide();
			}
        },
        error: function () {
        }
    });
*/


	$.getJSON(
			window.location,
			{
				"type" : "721",
				"tx_lioncastlefreeroom_pi1[roomType]" : $("#room").val(),
				"tx_lioncastlefreeroom_pi1[startDate]" : startDate,
				"tx_lioncastlefreeroom_pi1[endDate]" : endDate,
				"tx_lioncastlefreeroom_pi1[checkIn]" : $('select[name="checkin"]').val(),
				"tx_lioncastlefreeroom_pi1[checkOut]" : $('select[name="checkout"]').val()
			},
			function(data) {
				if(!data.is_free) {
					$('.room_is_busy').show();
				}
				else {
					$('.room_is_busy').hide();
				}
			}
	);


}

$(document).ready(function(){
	
	$('select[name="ariveyear"],select[name="arivemonth"],select[name="ariveday"],select[name="departureyear"],select[name="departuremonth"],select[name="departureday"],#room,select[name="checkin"],select[name="checkout"]').change(function(){
		checkFreeRoom();
	});
	
});
