
function reloadCart () {
    new Ajax.Request('/ajax', {
	method: 'post',
	postBody: 'id=3',
	onSuccess: function (tp) { $('tehcart').innerHTML = tp.responseText || ''; },
	onFailure: function () { alert("Hiba a feldolgozás közben!"); }
    });
}

function remFood (food) {
    doFood ('id=1&food=' + food);
}

function addFood (food, amount) {
    doFood ('id=2&food=' + food + '&amount=' + amount);
}


function doFood (pBody) {
    new Ajax.Request('/ajax', {
	method: 'post',
	postBody: pBody,
	onSuccess: function (tp) {
	    var resp = tp.responseText || 'error: no response';
	    if (resp != "OK") {
		alert(resp);
	    } else {
		reloadCart();
	    }
	},
	onFailure: function () { alert("Hiba a feldolgozás közben!"); }
    });
}

function fbLogin(sr) {
    new Ajax.Request('/ajax', {
	method: 'post',
	parameters: {'id':4, 'signed_request':sr},
	onSuccess: function (tp) {
	    $('formc').innerHTML = tp.responseText || 'error: no response';
	},
	onFailure: function () { alert("Hiba a feldolgozás közben!"); }
    });
}

function fbAutoLogin() {
    FB.getLoginStatus(function(response) {
	if (response.authResponse) {
	    fbLogin(response.authResponse.signedRequest);
	}
    });
}

