function updateListeResultats(){
	var prenom = $("#filtrePersonnes input[name=prenom]").val();
	var nom = $("#filtrePersonnes input[name=nom]").val();
	var idClub = $("#filtrePersonnes select[name=idClub] option:selected").val();
	var idCategorie = $("#filtrePersonnes select[name=filtreCategorie] option:selected").val();
	var pays = $("#filtrePersonnes select[name=paysClub] option:selected").val();
	var idEvenement = $("#filtrePersonnes select[name=filtreEvenements] option:selected").val();
	dataString = "nom=" + nom + "&prenom=" + prenom + "&idClub=" + idClub + "&idCategorie=" + idCategorie + "&pays=" + pays + "&idEvenement=" + idEvenement;
	$.ajaxSetup({ 
	    beforeSend: function() { 
	        $("#ajax-loader").show(); 
	    }, 
	    complete: function() { 
	        $("#ajax-loader").hide(); 
	    } 
	});
	var html = $.ajax({
		type: "POST",
		url: "resultats.inc.php",
		data: dataString,
		async: false
	}).responseText;
    $("#listePersonnes").replaceWith(html);
}

// Inscriptions (modification des menus, affichage / masquage, ...)
function updateClub(pays, departement, idClub){
    var html = $.ajax({
        type: "POST",
        url: "./ajaxListeResultats.php",
        data: "action=choixClub&pays=" + pays + "&dpt=" + departement + "&idClub=" + idClub,
        async: false
    }).responseText;
    $("#choixClub").replaceWith(html);
    if ($("select[name=idClub]").attr("class") == "vide") {
        $("#choixClub").hide();
    }
    else {
        $("#choixClub").show("blind");
    }
}

function choixPaysClub(departement,idClub){
    var pays = $("select[name=paysClub] option:selected").val();
	$("select[name=paysClub] option.selected").removeAttr("class");
    if (pays == "FRA") {
		updateClub(pays,'','');
        $("#choixDepartementClub").show("blind");
        $("#choixClub").hide();
    }
    else {
		$("#choixDepartementClub").hide();
		updateClub(pays,'','');
		if(pays == '') {
			$("#choixClub").hide();
		}
    }
    $("select[name=paysClub] option:selected").attr("class", "selected");
	updateListeResultats();
}

function choixClub(){
    var club = $("#choixClub select option:selected").val();
    $("#choixClub select").removeAttr("class");
    $("#choixClub select option.selected").removeAttr("class");
	if(club != '' && club !='NC') {
		$("#choixClub select option[value="+club+"]").attr("class", "selected");
	}
}

function choixDptClub(departement,idClub){
	if (departement == "") {
		var departement = $("select[name=departementClub] option:selected").val();
	}
    $("select[name=departementClub] option.selected").removeAttr("class");
    updateClub('FRA', departement, idClub);
    if (departement == "") {
        $("#choixClub").hide();
    }
	$("select[name=departementClub] option[value="+departement+"]").attr("class", "selected");
}

$(function($){
	$.ajaxSetup({ 
	    beforeSend: function() { 
	        $("#ajax-loader").show(); 
	    }, 
	    complete: function() { 
	        $("#ajax-loader").hide(); 
	    } 
	});
    $('.ui-state-default').hover(
			function(){ $(this).addClass('ui-state-hover'); }, 
			function(){ $(this).removeClass('ui-state-hover'); }
	);
	$('button.ui-state-highlight').hover(
		function(){ $(this).removeClass('ui-state-highlight'); $(this).addClass('ui-state-default'); }, 
		function(){ $(this).removeClass('ui-state-default'); $(this).addClass('ui-state-highlight'); }
	);
	$('a.ui-state-highlight').hover(
		function(){ $(this).removeClass('ui-state-highlight'); $(this).addClass('ui-state-default'); }, 
		function(){ $(this).removeClass('ui-state-default'); $(this).addClass('ui-state-highlight'); }
	);
	$('button.ui-state-error').hover(
		function(){ $(this).removeClass('ui-state-error'); $(this).addClass('ui-state-hover'); }, 
		function(){ $(this).removeClass('ui-state-hover'); $(this).addClass('ui-state-error'); }
	);
	$('.tipsy-e').tipsy({gravity: 'e'});
	$('.tipsy-w').tipsy({gravity: 'w'});
	$('.tipsy-n').tipsy({gravity: 'n'});
	$('.tipsy-s').tipsy({gravity: 's'});
    // Boite de connexion
    $("#loginBox").hide();
    $("a[id=loginButton]").click(function(){
        $("#loginBox").toggle('slide', {
            direction: "up"
        }, 'normal');
        return false;
    });
    $("#loginBox #login_cancel").click(function(){
        $("#loginBox").toggle('slide', {
            direction: "up"
        }, 'normal');
        return false;
    });
    // Selecteur de langue
    $("#lang .off").mouseover(function(){
        s1 = $(this).children('img').attr("src").replace('_off', '');
        $(this).children('img').attr("src", s1);
        s2 = $("#lang .on img").attr("src").replace('.png', '_off.png');
        $("#lang .on img").attr("src", s2);
    });
    $("#lang .off").mouseout(function(){
        s1 = $(this).children('img').attr("src").replace('.png', '_off.png');
        $(this).children('img').attr("src", s1);
        s2 = $("#lang .on img").attr("src").replace('_off', '');
        $("#lang .on img").attr("src", s2);
    });
	
    $("img.rollover").hover(function(){
        this.src = this.src.replace("_off", "_on")
    }, function(){
        this.src = this.src.replace("_on", "_off");
    });
    $("#container form input").focus(function(){
        this.select();
    });
    $("#container form textarea").focus(function(){
        this.select();
    });
});