﻿function SetFollowSeries(series_id, panel, username) {
    //alert("Adding" + series_id + " into " + panel);
    $j.ajax({
        type: "POST",
        url: "/SaveDataService.asmx/SetFollowSeries",
        data: "{'series_id':'" + series_id + "','username':'" + username + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data) {

            $j("#" + panel).html("<img src='/images/redheart.gif' border='0' class='leafimage'>");



        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            // typically only one of textStatus or errorThrown 
            // will have info
            //this; // the options for this ajax request
            //alert(XMLHttpRequest.d + " " + errorThrown);
            //alert(XMLHttpRequest.d);
        }

    });
}

function RemoveFollowSeries(series_id, panel, username) {

    if (confirm("Are you sure you want to remove? This can not be undone. You will loose all book reads, and all related information.")) {
        $j.ajax({
            type: "POST",
            url: "SaveDataService.asmx/RemoveFollowSeries",
            data: "{'series_id':'" + series_id + "','username':'" + username + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(data) {

                
                window.location = "userhome.aspx";



            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                // typically only one of textStatus or errorThrown 
                // will have info
                //this; // the options for this ajax request
                //alert(XMLHttpRequest.d + " " + errorThrown);
                //alert(XMLHttpRequest.d);
            }

        });
    }
}


function SetUserReadBook( book_id,user_id, panel) {
   

    $j.ajax({
        type: "POST",
        url: "SaveDataService.asmx/InsertUserBook",
        data: "{'book_id':'" + book_id + "','user_id':'" + user_id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data) {

        $j("#" + panel).html("<img src='/images/greencheck.gif' border='0'> <a href='#' onclick=\"RemoveUserReadBook(" + book_id + "," + user_id + ",'" + panel  + "');$('rating_one').hide();\" style='color:red'>(x)</a>")
     

        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
           
            //alert(XMLHttpRequest.d + " ERROR" + errorThrown + " TEXT:" + textStatus);
         
        }

    });

   
}

function RemoveUserReadBook(book_id, user_id, panel) {

    //  alert("rempce" + book_id + " " + user_id);


    $j.ajax({
        type: "POST",
        url: "SaveDataService.asmx/RemoveUserBook",
        data: "{'book_id':'" + book_id + "','user_id':'" + user_id + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data) {

            $j("#" + panel).html("<a href='#' onclick=\"SetUserReadBook(" + book_id + "," + user_id + ",'" + panel + "');$('rating_one').show();\">Mark as Read</a>");
            // window.location = "userhome.aspx";




        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            // typically only one of textStatus or errorThrown 
            // will have info
            //this; // the options for this ajax request
            //alert(XMLHttpRequest.d + " ERROR" + errorThrown + " TEXT" + textStatus);
            //alert(XMLHttpRequest.d);
        }

    });

}

  function UpdateUserBookRating(book_id, user_id, rating_value) {

    //alert("rating " + book_id + " " + user_id + " " + rating_value);

    //alert("{'book_id':'" + book_id + "','user_id':'" + user_id + "','rating_value':'" + rating_value + "'}");
    
    $j.ajax({
        type: "POST",
        url: "SaveDataService.asmx/UpdateUserBookRating",
        data: "{'book_id':'" + book_id + "','user_id':'" + user_id + "','rating_value':'" + rating_value  + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data) {

            //$j("#" + panel).html(rating_value);
            // window.location = "userhome.aspx";

         //  alert("Saved Rating!");


        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            // typically only one of textStatus or errorThrown 
            // will have info
            //this; // the options for this ajax request
            //alert(XMLHttpRequest.d + " ERROR" + errorThrown + " TEXT" + textStatus);
            //alert(XMLHttpRequest.d);
        }

    });



}

