﻿$(document).ready(function() {

    $("li", ".star-rating").live("click", function() {
        var rating = $(this).text();
        var contentID = $("#ContentID").text();

        if (!isNaN(rating) && !isNaN(contentID)) {
            RateContent(contentID, rating);           
        }
    });


});

/* 1 - 5 */
function RateContent(contentID, articleRating) {
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "/Content/Content/RateArticleAjax/",
        data: {
            "Rating": articleRating,
            "ContentID": contentID
        },
        success: function(data) {

            if (data.NotAMember) {
                NotAMember();
            }
            else {

                if (data.NotAMember == false && data.MemberHadAlreadyVoted) {
                    AlreadyVoted();
                }
                else {
                    $(".articleRating").html(data.RatingHtml);
                }
            }
        }
    });

}


function NotAMember() {
    $("#rating-result").hide().html("<b>You need to be a member to vote</b> <a href='/login/'>Click here to login.</a>").fadeIn(1000);  
}

function AlreadyVoted() {
    $("#rating-result").hide().html("<b>You have already voted on this content.</b>").fadeIn(1000);
}




