//Ajax process

function getXMLHttp()
{
	var xmlHttp; try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				return false;
			}
		}
	}
	return xmlHttp;
}

//Open booking

function open_booking_response(response)
{
	$('#book').html(response);
}

function open_booking(booking_type)
{
	var xmlHttp = getXMLHttp(); xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			open_booking_response(xmlHttp.responseText);
		}
	}
	$('#black_overlay').css('display', 'block'); $('#book').fadeIn('slow', function()
	{
		xmlHttp.open('get', 'web/code/open_booking.php?preset='+booking_type, true); xmlHttp.send();
	});
}

//Open calendar

function calendar_response(response)
{
	$('#calendar').fadeOut('fast', function()
	{
		var offset = $('#calender_icon').position(); $('#calendar').html(response).css('left', (offset.left+25)+'px').css('top', (offset.top)+'px').fadeIn('fast');
	});
}

function calendar(ym)
{
	var xmlHttp = getXMLHttp(); xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			calendar_response(xmlHttp.responseText);
		}
	}
	xmlHttp.open('get', 'web/code/calendar.php?ym='+ym, true); xmlHttp.send();
}

function pickdate(ymd)
{
	var dateinput = ymd.substring(4,6)+'-'+ymd.substring(2,4)+'-20'+ymd.substring(0,2); $('#reserv_date').val(dateinput); $('#calendar').fadeOut('fast');
}

//Do booking

function book_response(response)
{
	$('#load').css('visibility', 'hidden'); $('#book').html(response);
}

function book()
{
	var xmlHttp = getXMLHttp(); xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			book_response(xmlHttp.responseText);
		}
	}
	$('#load').css('visibility', 'visible'); xmlHttp.open('post', 'web/code/do_booking.php', true); xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp.send('type='+$("input[name=res_type]").val()+'&date='+$('#reserv_date').val()+'&time='+$('#reserv_time').val()+'&for_no='+$('#reserv_for_no').val()+'&uid_name='+$('#reserv_uid_name').val()+'&uid_mail='+$('#reserv_uid_mail').val()+'&uid_phone='+$('#reserv_uid_phone').val()+'&call='+$('#reserv_callme').is(':checked')+'&text='+$('#reserv_text').val());
}

//Unlist

function unlist_response(response)
{
	$('#load').css('visibility', 'hidden'); $('#unlisting').html(response);
}

function unlist()
{
	var xmlHttp = getXMLHttp(); xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			unlist_response(xmlHttp.responseText);
		}
	}
	$('#load').css('visibility', 'visible'); xmlHttp.open('post', 'web/code/do_unlist.php', true); xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp.send('uid_mail='+$('#unlist_mail').val());
}
