function ratingCallback(sender, value, link)
{
    // Go up a couple of levels to fetch the forumPostId that we're setting the rating for
    // Note: If you move where the hidden field lives in the DOM you will break this!
    var forumPostId = $("input[name='" + sender.name + "']").parent().parent().children("input[type='hidden']").val();
    $.ajax({
      type: "POST",
      url: starRatingUrl,
      data: "{forumPostId:" + forumPostId + ",yourRating:" + value + ",senderName:'" + sender.name + "'}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {        
        ratingSuccess(msg);
      }
    });
}

function getVotesString(votes) {
	if (votes == 1) {
		return '(1 ' + (typeof (voteLabel) != 'undefined' ? voteLabel : '[vote]') + ')';
	} else {
		return '(' + votes + ' ' + (typeof (votesLabel) != 'undefined' ? votesLabel : '[votes]') + ')';
	}
}

function ratingSuccess(msg)
{
    var newRating = msg.d[0];
    var totalVotes = msg.d[1];
    var senderName = msg.d[2];
    // Update the text for the rating
    $("input[name='" + senderName + "']").parent().parent().find(".votes-box span").text(getVotesString(totalVotes));
    
    var el = $("input[name='" + senderName + "']").parent().parent().find("a[title='" + newRating + "']").parent()[0];
    
    $.rating.groups[senderName].current = el;
	// Set value
	$.rating.groups[senderName].valueElem.val(newRating);
	// Update display
	$.rating.event.drain(senderName, el, $.rating);
	$.rating.event.reset(senderName, el, $.rating);
	
	$("input[name='" + senderName + "']").parent().css("display", "none");
	$("input[name='" + senderName + "']").parent().parent().find(".forum-vote-thanks").css("display","inline");
	
	var forumPostId = $("input[name='" + senderName + "']").parent().parent().children("input[type='hidden']").val();
	
	//Write cookie
	$.cookie('rating_forumPost' + forumPostId, "true");
}

