
function rollOnVote(points) {
    for (var i=0; i<5; i++) {
        if (i+1<=points)
            $("#star_"+i).attr('src', './buttons/star_on.gif');
        else
            $("#star_"+i).attr('src', './buttons/star_off.gif');
    }
}
function rollOffVote(points) {
    for (var i=0; i<5; i++) {
        $("#star_"+i).attr('src', './buttons/star_off.gif');
    }
}

function vote(itemid, points) {
    // envoi des données à la DB
    $.ajax({
       type: "GET",
       url: "./exec.vote.xhr.php",
       async: true,
       data: "id="+itemid+"&points="+points,
       success: function(msg){
         $("#votes_"+itemid).after("&nbsp;<em class=\"congrats\">Merci d'avoir voté !</em>");
       }
    });
    
    // affichage définitif
    $(".star").attr("onmouseover", "").attr("onmouseout", "").attr("onclick", "");
    rollOnVote(points);
}



function comment() {
    // envoi des données au handler
    $.ajax({
       type: "POST",
       url: "./exec.comment.xhr.php",
       async: true,
       data: $("#commenting").serialize(),
       success: function(msg) {
         $("#commentingDiv #result").html(msg);
         updateComments($("#commenting").serialize());
         if (msg.indexOf("congrats") == -1) {
            $("#commentingCaptcha").attr('src', '../captcha_bis.jpg');
            $("#security_code").val("");
         } else {
            $("#commentingDiv form#commenting").remove();
         }
       }
    });
}

function updateComments(serid) {
    // update
    $.ajax({
       type: "GET",
       url: "./body.displaycomments.xhr.php",
       async: true,
       data: serid,
       success: function(msg) {
         $("#comments").html(msg);
       }
    });
}
