function _SendTopTableRequest(doing, url, failed)
{
	if(doing != '')
		$("#booking-block-content").html($("#order_form_wait").html() + doing + "...");
	
	$.ajax({
		type:		"get",
		url:		url,
		dataType:	"html",
		data:		'',
		success: function(data)
		{
			$("#booking-block-content").html(data);
			$("#booking-block").show();
		},
		error: function(xhr, ajaxOptions, thrownError)
		{
			$("#booking-block-content").html("Failed to " + failed);
		}
	});
}

function ShowTopTableRoomForm()
{
	_SendTopTableRequest('Checking availability',
						 place_url + "?order=toptable&step=roomlist",
						 'check availability');
}


function ProcessTopTableRoomForm()
{
	var num_p = parseInt($("#number-of-people").val());
	if(num_p == 0 || isNaN(num_p))
	{
		alert("Please enter number of people dining");
		return;
	}

	_SendTopTableRequest('Checking available times',
						 place_url + "?order=toptable&step=room&" + $('#book_form').serialize(),
						 'check available times');
}

function ProcessTopTableTimeForm()
{
	_SendTopTableRequest('',
						 place_url + "?order=toptable&step=form&" + $('#book_form').serialize(),
					     'continue booking process');
}

function ProcessTopTableFinalForm()
{
	if( $("#f_name").val() == "" ||
		$("#f_email").val() == "" ||
		$("#f_phone").val() == "" ||
		$("#f_party").val() == "")
	{
		alert("Please fill all required fields");
		return;
	}

	_SendTopTableRequest('Booking',
						 place_url + "?order=toptable&step=book&" + $('#book_form').serialize(),
						 'book');
}

function OpenCreditCardWindow(url)
{
	newwindow = window.open(url, 'name', 'height=450,width=800,toolbar=no,menubar=no');
	if (window.focus)
		newwindow.focus();
}