// sending info to the server
function ajaxRate (value) {
    var url = document.location.href;
    var objectName = url.substring(url.indexOf("/masterclass") + 1, url.indexOf(".do"));
    RatingAJAX.rate(new Array(objectName, "None", value), rateCallbackFunction);
}

function ajaxVote (objectName) {
    VotingAjax.rate(new Array(objectName, "Image", 1), voteCallbackFunction);
}

// The callback functions
function rateCallbackFunction(data) {
    var output = "";
    if (data == 1) {
        output = "You have voted <span id='feedback_1'>not very useful</span>";
    } else if (data == 2) {
        output = "You have voted <span id='feedback_2'>useful</span>";
    } else if (data == 3) {
        output = "You have voted <span id='feedback_3'>very useful</span>";
    } else {
        // Invalid rating (tried to vote twice), should already be caught as the page loads
        output = "You have already voted for this video";
    }
    document.getElementById("feedback").innerHTML = "<span>Your feedback</span><p>"+output+"</p>";
}

function voteCallbackFunction(data) {
    var output = "";
    if (data == 1) {
        output = data;
    } else {
        // Invalid rating (tried to vote twice), should already be caught as the page loads
        output = "You have already voted for this video";
    }
    document.getElementById("vote").innerHTML = output;
}
