﻿var ofr;

function likeOffer(ofrId, usrId, canLike, usrIp) {
    var dvid = $.cookie("SavoryApp_Like1");
    if (!dvid) {
        var d = new Date();
        dvid = d.getTime();
        $.cookie("SavoryApp_Like1", dvid, { expires: 1000 });
    }

    ofr = ofrId;
    if (canLike > 0) { alert("Thank you!"); }
    else {
        ret = ws_offer.offerLike(ofrId, usrId, dvid, usrIp, 1, OnComplete, OnTimeOut, OnError);
    }
    //return true;
}

function OnComplete(arg) {
    var myId = "#like" + ofr;
    $(document).ready(function () {
        $(myId).html("Like | " + arg);
        $(myId).attr("href", "#myId");
    });
}
function OnTimeOut(arg) {
    alert("timeout: " + arg);
}
function OnError(arg) {
    alert("error: " + arg);
}

function favRest(uId, custId, CustName, ofrId) {
    if (uId == 0) { alert("You have to login or register to add restaurants to your Favorites"); }
    else {
        ret = ws_offer.restFav(custId, CustName, ofrId, 1, uId, OnCompleteFav, OnTimeOut, OnError);
    }
}

function OnCompleteFav(arg) {
    
    $(document).ready(function () {
        if ($("#FavResult").length > 0) { $("#FavResult").html("<h3 class=\"rsltOK\">" + arg + "</h3>"); }
    });
}
