var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
	xmlHttp = new XMLHttpRequest();
}
function load_table(day, roomIDs)
{
	var table_div = document.getElementById('reservation-table');

	//	Blur table.
	new Effect.Appear(table_div, {duration: 0.25, from: 1.0, to: 0.25});

	var url = '/reservation_table.php?day=' + day + '&roomIDs=' + roomIDs;
	xmlHttp.open('GET', url, true);
	xmlHttp.onreadystatechange = load_table_response;
	xmlHttp.send(null);
}
function load_table_response()
{
	var table_div = document.getElementById('reservation-table');

	if (xmlHttp.readyState == 4)
	{
		var response = xmlHttp.responseText;
		table_div.innerHTML = response;

		//	Remove table blur.
		new Effect.Appear(table_div, {duration: 0.25});
	}
}
function select_cell(begin, end, roomID, cellID, price)
{
	var summary_div = document.getElementById('selection-summary');
	if (xmlHttp.readyState == 0 || xmlHttp.readyState == 1 || xmlHttp.readyState == 4)
	{
		//	Blur summary.
		new Effect.Appear(summary_div, {duration: 0.25, from: 1.0, to: 0.25});

		var url = '/reservation_ajax.php?begin=' + begin + '&end=' + end + '&roomID=' + roomID + '&cellID=' + cellID + '&price=' + price;
		xmlHttp.open('GET', url, true);
		xmlHttp.onreadystatechange = selection_summary_response;
		xmlHttp.send(null);
	}
}
function selection_summary_response()
{
	var summary_div = document.getElementById('selection-summary');

	if (xmlHttp.readyState == 4)
	{
		var response_raw = xmlHttp.responseText;
		var response_components = response_raw.split('---||---', 2);

		//	Check JavaScript trimmed source length before eval.
		if (0 < response_components[0].replace(/^\s+|\s+$/g, '').length)
		{
			//	Run JavaScript.
			eval(response_components[0]);
		}
		//	Load HTML.
		summary_div.innerHTML = response_components[1];

		//	Remove table blur.
		new Effect.Appear(summary_div, {duration: 0.25});
	}
}

function delete_cart_row(roomID, begin, end)
{
	if (xmlHttp.readyState == 0 || xmlHttp.readyState == 1 || xmlHttp.readyState == 4)
	{
		var url = '/reservation_ajax.php?delete_cart_row&roomID=' + roomID + '&begin=' + begin + '&end= ' + end;
		xmlHttp.open('GET', url, true);
		xmlHttp.onreadystatechange = load_summary_delete;
		xmlHttp.send(null);
	}
}
function get_summary()
{
	if (xmlHttp.readyState == 0 || xmlHttp.readyState == 1 || xmlHttp.readyState == 4)
	{
		var url = '/reservation_ajax.php?summary';
		xmlHttp.open('GET', url, true);
		xmlHttp.onreadystatechange = load_summary;
		xmlHttp.send(null);
	}
}
function load_summary()
{
	var summary_div = document.getElementById('selection-summary');

	if (xmlHttp.readyState == 4)
	{
		summary_div.innerHTML = xmlHttp.responseText;
	}
}
function load_summary_delete()
{
	var summary_div = document.getElementById('selection-summary');

	if (xmlHttp.readyState == 4)
	{
		summary_div.innerHTML = xmlHttp.responseText;
		if (null !== document.getElementById('date-picker-container'))
		{
			date_selected_actions();
		}
	}
}
