var fscmessages = Array();

function fscStart(url) {
	$('.fscform').hide();
	$('.fscinfo').show();
	fscUpdate('Calling...'); // initial message to show
	$.getJSON(
		url + 'setCallMeNow.php',
		{ restaurant: $('#irestaurant').val(), customer: $('#iuserphone').val() },
		function(data){
			fscUpdate(fscmessages[data.s]);
			if (data.e == 0) {
				setTimeout('fscGetUpdate(\'' + url + '\', \'' + data.s + '\')', 100);
			}
		}
	);
	$('.popupbuttoncontainerright').hide();
}

function fscForm() {
	$('.fscform').show();
}

function fscUpdate(status) {
	$('.fscstatus').html(status);
}

function fscGetUpdate(url, laststatus) {
	$.ajax({
		type: 'GET',
		dataType: 'json',
		url: url + 'getCallMeNowStatus.php',
		data: { last: laststatus },
		async: true, 
		cache: false,
		timeout: 300000,
		
		success: function(data){ 
			if (data.s != 'NO_STATUS') {
				fscUpdate(fscmessages[data.s]);
			}
			if (data.e == 1) {
				$('.popupbuttoncontainerright').show();
			} else {
				if (data.s == 'HANGUP') {
					setTimeout('closeActivePopUp()', 1000);
				} else {
					setTimeout('fscGetUpdate(\'' + url + '\', \'' + data.s + '\')', 1000);
				}
			}
		},
		error: function(data){
			setTimeout('fscGetUpdate(\'' + url + '\', \'' + data.s + '\')', 1000);
		}
	});
}

