$(document).ready(function(){
    $("a[href='AddToFavourites']").click(function() {
        var escortId = $(this).attr('id');
        var thisLink = $(this);
        $.post("ajax",
               {
                   'func': "saveToFavourites",
                   'escort_id': escortId
               },
               function(data){
                   if (data['result']) {
                       if (!data['is_logged_in']) {
                           $("#addToFavouritesDialog").dialog('open');
                       }

                       //thisLink.parent().remove();
                       thisLink.replaceWith("Saved");
                   }
               },
               "json"
        );
        return false;
    });

    $("#addToFavouritesDialog").dialog({
        bgiframe: true,
        autoOpen: false,
        width: 350,
        height: 200,
        modal: true,
        draggable: false,
        resizable: false,
        buttons: {
            'No': function() {
                $(this).dialog('close');
            },
            'Yes': function() {
                window.location.replace("EscortReviewerRegistration");
            }
        }
    });

    $("a[href='RemoveFromFavourites']").click(function() {
        var escortId = $(this).attr('id');
        var thisLink = $(this);
        $.post("ajax",
               {
                   'func': "removeFromFavourites",
                   'escort_id': escortId
               },
               function(data) {
                   thisLink.parent().html("");
               },
               "json"
        );
        return false;
    });
});
