/**
 * Contains misc javascripts.
 * Using JQuery.
 */


function validation(varuser, varevent) {
    
    var valide = $.ajax({ 
        type: "GET", 
        url: "./includes/ajax.php", 
        data: {a: 'validation', user_id: varuser, event_id: varevent}, 
        dataType: "text", 
        async: false
    }).responseText;
    
    //valide now contains the new value (1 for a validation, 0 for a cancelation)
    var img = $("tr#"+varuser+" td.statut span");
    if (valide == 1) {
        img.fadeOut("fast", function() {
            img.removeClass("cancel");    //Remove class "cancel"
            img.addClass("check");        //Add class "check"
            img.fadeIn("fast");
            img.attr("title", "valide");
        });
    }
    else {
        img.fadeOut("fast", function() {
            img.removeClass("check");    //Remove class "check"
            img.addClass("cancel");      //Add class "cancel"
            img.fadeIn("fast");
            img.attr("title", "non valide");
        });
    }
}

function changelevel(varuser, varevent) {
    
    var level = $.ajax({ 
        type: "GET", 
        url: "./includes/ajax.php", 
        data: {a: 'changelevel', user_id: varuser}, 
        dataType: "text", 
        async: false
    }).responseText;
    
    //level contains the new value (1 for user, 5 for admin)
    var img = $("tr#"+varuser+" td.level span");
    if (level == 1) {
        img.fadeOut("fast", function() {
            img.removeClass("star");     //Remove class "star"
            img.addClass("user");        //Add class "user"
            img.fadeIn("fast");
            img.attr("title", "user");
        });
    }
    else {
        img.fadeOut("fast", function() {
            img.removeClass("user");    //Remove class "user"
            img.addClass("star");        //Add class "star"
            img.fadeIn("fast");
            img.attr("title", "admin");
        });
    }
}