/**
 * 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");
        });
    }
}

$(document).ready(function() {
    //Clear login/pw boxes when clicking it
    $('.login_box input[name="login"]').focus(function() {
        if ($('.login_box input[name="login"]').val() == 'login')
            $('.login_box input[name="login"]').val('');
    });
    
    $('.login_box input[name="password"]').focus(function() {
        if ($('.login_box input[name="password"]').val() == 'password')
            $('.login_box input[name="password"]').val('');
    });
    
    //Render buttons-links
    $('a.button').appendTo(
        $('<button type="button" class="link"></button>').appendTo($('a.button').parent())
    );
    $('button.link').click(function() {
        var url = $('button.link a').attr('href');
        //$(location).attr('href',url);
		window.location.href = url;
    });
});
