var mins;
var secs;
var begclo = 0;

function cd() {
    begclo = 0;
    mins = 1 * m("1");
    secs = 0 + s(":00");
}

function m(obj) {
    for (var i = 0; i < obj.length; i++) {
        if (obj.substring(i, i + 1) == ":") {
            break;
        }
    }
    return(obj.substring(0, i));
}

function s(obj) {
    for (var i = 0; i < obj.length; i++) {
        if (obj.substring(i, i + 1) == ":") {
            break;
        }
    }
    return(obj.substring(i + 1, obj.length));
}

function dis(mins,secs) {
    var disp;
    if (mins <= 9) {
        disp = " 0";
    }
    else {
        disp = " ";
    }
    disp+= mins + ":";
    if (secs <= 9) {
        disp+= "0" + secs;
    }
    else {
        disp+= secs;
    }
    return(disp);
}

function timeIsUp() {
    mins = 0;
    secs = 1;
}

function redo(id_quiz, max) {
    if (count == max) return;
    secs--;
    if (secs == -1) {
        secs = 59;
        mins--;
    }
    document.cd.disp.value = dis(mins,secs);
    if ((mins == 0) && (secs == 0)) {
        window.alert("Chrono écoulé ! Regardons votre résulat...");
        showMissed(id_quiz);
    }
    else {
        cd = setTimeout("redo(" + id_quiz + "," + max + ")", 1000);
    }
}

function init() {
    cd();
}
window.onload = init;

var count = 0;
var found = new Array();
var separateur = new RegExp("[ ]+", "g");

var mot_singulier = new Array();
var mot_pluriel   = new Array();
var hxcd          = new Array();
var soluce        = new Array();
var nb_hxcd       = new Array();


// Quiz 1
mot_singulier[1] = "joueur";
mot_pluriel[1]   = "joueurs";
hxcd[1]          = new Array("Llacer", "Fiorèse", "Pedretti", "Mendy", "Moussilou", "Piquionne");
soluce[1]        = new Array("Francis Llacer", "Fabrice Fiorèse", "Benoît Pedretti", "Bernard Mendy", "Matt Moussilou", "Frédéric Piquionne");
nb_hxcd[1]       = hxcd[1].length;

// Quiz 2
mot_singulier[2] = "gardien";
mot_pluriel[2]   = "gardiens";
hxcd[2]          = new Array("Coupet", "Landreau", "Barthez", "Ramé", "Warmuz", "Charbonnier", "Casagrande", "Lama", "Olmeta", "Huard");
soluce[2]        = new Array("Grégory Coupet (Lyon, 2002 à 2008)", "Mickaël Landreau (Nantes, 2001)", "Fabien Barthez (Monaco, 1997 et 2000)", "Ulrich Ramé (Bordeaux, 1999)", "Guillaume Warmuz (Lens, 1998)", "Lionel Charbonnier (Auxerre, 1996)", "Dominique Casagrande (Nantes, 1995)", "Bernard Lama (Paris SG, 1994)", "Pascal Olmeta (OM, 1991 et 1992)", "Gaëtan Huard (OM, 1989 et 1990)");
nb_hxcd[2]       = hxcd[2].length;

// Quiz 3
mot_singulier[3] = "buteur";
mot_pluriel[3]   = "buteurs";
hxcd[3]          = new Array("Niang", "Savidan", "Odemwingie", "Fred", "Pagis", "Drogba", "Frei", "Pauleta", "Trezeguet", "Caveglia");
soluce[3]        = new Array("Mamadou Niang (Marseille, 2008)", "Steve Savidan (Valenciennes, 2007)", "Peter Odemwingie (Lille, 2006)", "Fred (Lyon, 2006)", "Mickaël Pagis (Strasbourg, 2005)", "Didier Drogba (Marseille, 2004)", "Alexander Frei (Rennes, 2004)", "Pedro Miguel Pauleta (Bordeaux, 2001 et 2003)", "David Trezeguet (Monaco, 2000)", "Alain Caveglia (Lyon, 1999)");
nb_hxcd[3]       = hxcd[3].length;

// Quiz 4
mot_singulier[4] = "tacleur de genou";
mot_pluriel[4]   = "tacleurs de genou";
hxcd[4]          = new Array("Rool", "Jeunechamp", "Jurietti", "Batlles", "Jemmali", "Saveljic", "Meniri", "Meyrieu", "Violeau", "Leroy");
soluce[4]        = new Array("Cyril Rool (151 cartons)", "Cyril Jeunechamp (98 cartons)", "Franck Jurietti (94 cartons)", "Laurent Batlles (79 cartons)", "David Jemmali (74 cartons)", "Nisa Saveljic (71 cartons)", "Mehdi Meniri (68 cartons)", "Frédéric Meyrieu (66 cartons)", "Philippe Violeau (65 cartons)", "Jérôme Leroy (65 cartons)");
nb_hxcd[4]       = hxcd[4].length;

// Quiz 5
mot_singulier[5] = "joueur en Z";
mot_pluriel[5]   = "joueurs en Z";
hxcd[5]          = new Array("Zubar", "Zubar", "Zenden", "Ziani", "Zerka", "Zola", "Zelazny");
soluce[5]        = new Array("Stéphane Zubar (Caen)", "Ronald Zubar (OM)", "Boudewijn Zenden (OM)", "Karim Ziani (OM)", "Moncef Zerka (Nancy)", "Distel Zola (Monaco)", "Erwin Zelazny (Nantes)");
nb_hxcd[5]       = hxcd[5].length;

// Quiz 6
mot_singulier[6] = "marqueur de pénalty";
mot_pluriel[6]   = "marqueurs de pénalty";
hxcd[6]          = new Array("Monterrubio", "Pauleta", "Guivarc'h", "Darcheville", "Bertin", "Maurice", "Nonda", "Frau", "Niang", "Juninho", "Baticle", "Anderson", "N'Doram");
soluce[6]        = new Array("Olivier Monterrubio (26)", "Pedro-Miguel Pauleta (23)", "Stéphane Guivarc'h (13)", "Jean-Claude Darcheville (12)", "Teddy Bertin (11)", "Florian Maurice (10)", "Shabani Nonda (9)", "Pierre-Alain Frau (9)", "Mamadou Niang (9)", "Juninho (9)", "Gérald Baticle (9)", "Sonny Anderson (9)", "Japhet N'Doram (9)");
nb_hxcd[6]       = hxcd[6].length;

// Quiz 7
mot_singulier[7] = "passeur";
mot_pluriel[7]   = "passeurs";
hxcd[7]          = new Array("Gameiro", "Bastos", "Danic", "Hellebuyck", "Gourcuff", "Niang", "Kahlenberg", "Savidan", "Wendel");
soluce[7]        = new Array("Kévin Gameiro (Lorient, 6)", "Michel Bastos (Lille, 6)", "Gaël Danic (Valenciennes, 6)", "David Hellebuyck (Nice, 6)", "Yoann Gourcuff (Bordeaux, 6)", "Mamadou Niang (Marseille, 5)", "Thomas Kahlenberg (Auxerre, 5)", "Steve Savidan (Caen, 5)", "Wendel (Bordeaux, 5)");
nb_hxcd[7]       = hxcd[7].length;

// Quiz 8
mot_singulier[8] = "buteur";
mot_pluriel[8]   = "buteurs";
hxcd[8]          = new Array("Hoarau", "Lesage", "Traoré", "Savidan", "Koné", "Suarez", "Fauré", "Diallo", "Santos", "Traoré");
soluce[8]        = new Array("Guillaume Hoarau (Le Havre, 2008)", "Jean-Michel Lesage (Le Havre, 2006 et 2007)", "Kandia Traoré (Le Havre, 2007)", "Steve Savidan (Valenciennes, 2006)", "Bakary Koné (Lorient, 2005)", "David Suarez (Amiens, 2004)", "Cédric Fauré (Toulouse, 2003)", "Hamed Diallo (Amiens, 2002)", "Francileudo Santos (Sochaux, 2001)", "Amada Traoré (Gueugnon, 2000)");
nb_hxcd[8]       = hxcd[8].length;

// Quiz 9
mot_singulier[9] = "entraineur";
mot_pluriel[9]   = "entraineurs";
hxcd[9]          = new Array("Perrin", "Lacombe", "Roux", "Halilhodzic", "Pouliquen", "Denoueix", "Ricardo");
soluce[9]        = new Array("Alain Perrin (Sochaux en 2007, Lyon en 2008)", "Guy Lacombe (PSG en 2006)", "Guy Roux (Auxerre en 2003 et 2005)", "Vahid Halilhodzic (PSG en 2004)", "Yvon Pouliquen (Strasbourg en 2001, Lorient en 2002)", "Reynald Denoueix (Nantes en 1999 et 2000)", "Ricardo (PSG en 1998)");
nb_hxcd[9]       = hxcd[9].length;

// Quiz 10
mot_singulier[10] = "attaquant français géant";
mot_pluriel[10]   = "attaquants français géants";
hxcd[10]          = new Array("Hoarau", "Baseya", "Péricard", "Trezeguet", "Nimani", "N'Gog", "Fauvergue");
soluce[10]        = new Array("Guillaume Hoarau (PSG)", "Cédric Baseya (Lille)", "Vincent Péricard (Millwall)", "David Trezeguet (Juventus)", "Frédéric Nimani (Monaco)", "David N'Gog (Liverpool)", "Nicolas Fauvergue (Lille)");
nb_hxcd[10]       = hxcd[10].length;

// Quiz 11
mot_singulier[11] = "buteur inutile";
mot_pluriel[11]   = "buteurs inutiles";
hxcd[11]          = new Array("Bocanegra", "Cissé", "Maoulida", "Noro", "Leal", "Dutitre", "Smicer");
soluce[11]        = new Array("Carlos Bocanegra (Rennes, 2009)", "Djibril Cissé (Marseille, 2007 - 2x inutile)", "Toifilou Maoulida (Marseille, 2006)", "Stéphane Noro (Sedan, 2005)", "Hugo Leal (Paris SG, 2003)", "Jérôme Dutitre (Calais, 2000)", "Vladimir Smicer (Lens, 1998)");
nb_hxcd[11]       = hxcd[11].length;

// Quiz 12
mot_singulier[12] = "arbitre";
mot_pluriel[12]   = "arbitres";
hxcd[12]          = new Array("Layec", "Lannoy", "Duhamel", "Bré", "Gautier", "Ennjimi", "Chapron", "Fautrel", "Jaffredo", "Piccirillo");
soluce[12]        = new Array("Bertrand Layec (1)", "Stéphane Lannoy (2)", "Laurent Duhamel (3)", "Stéphane Bré (4)", "Antony Gautier (5)", "Saïd Ennjimi (6)", "Tony Chapron (7)", "Freddy Fautrel (8)", "Lionel Jaffredo (9)", "Hervé Piccirillo (10)");
nb_hxcd[12]       = hxcd[12].length;

// Quiz 13
mot_singulier[13] = "buteur";
mot_pluriel[13]   = "buteurs";
hxcd[13]          = new Array("Darcheville", "Goussé", "Bamogo", "N'Diaye", "Gueye", "Tum", "Keserü", "Diallo", "Payet", "Alassane");
soluce[13]        = new Array("Jean-Claude Darcheville (Lorient en 2001-2002, 19 buts)", "Nicolas Goussé (Troyes en 2002-2003, 6 buts)", "Habib Bamogo (Montpellier en 2003-2004, 16 buts)", "Moussa N'Diaye (Istres en 2004-2005, 6 buts)", "Babacar Gueye (Metz en 2005-2006, 3 buts et en 2007-2008, 6 buts)", "Hervé Tum (Metz en 2005-2006, 3 buts)", "Claudiu Keserü (Nantes en 2006-2007, 4 buts)", "Mamadou Diallo (Nantes en 2006-2007, 4 buts)", "Dimitri Payet (Nantes en 2006-2007, 4 buts)", "Amadou Alassane (Le Havre en 2008-2009, 10 buts)");
nb_hxcd[13]       = hxcd[13].length;

// Quiz 14
mot_singulier[14] = "équipe";
mot_pluriel[14]   = "équipes";
hxcd[14]          = new Array("Parme", "Dortmund", "Real Madrid", "Manchester United", "Celta Vigo", "Milan AC", "La Corogne", "Liverpool", "Arsenal", "Chelsea");
soluce[14]        = new Array("Parme (1994-1995, en finale)", "Dortmund (1996-1997, en finale)", "Real Madrid (1997-1998, en finale)", "Manchester United (1998-1999, en demi)", "Celta Vigo (1999-2000, en tour de qualif)", "Milan AC (2002-2003, en finale)", "La Corogne (2003-2004, en tour de qualif)", "Liverpool (2004-2005, en quart)", "Arsenal (2005-2006, en quart)", "Chelsea (2008-2009, en tour de qualif)");
nb_hxcd[14]       = hxcd[14].length;

// Quiz 15
mot_singulier[15] = "joueur";
mot_pluriel[15]   = "joueurs";
hxcd[15]          = new Array("Chalmé", "Valverde", "Dossevi", "Debuchy", "Bodmer", "Valbuena", "Dreyer", "Berson", "Coutadeur");
soluce[15]        = new Array("Matthieu Chalmé (Bordeaux)", "Matthieu Valverde (Boulogne)", "Mathieu Dossevi (Le Mans)", "Mathieu Debuchy (Lille)", "Mathieu Bodmer (Lyon)", "Mathieu Valbuena (OM)", "Matthieu Dreyer (Sochaux)", "Mathieu Berson (Toulouse)", "Mathieu Coutadeur (Monaco)");
nb_hxcd[15]       = hxcd[15].length;

// Quiz 16
mot_singulier[16] = "joueur";
mot_pluriel[16]   = "joueurs";
hxcd[16]          = new Array("Gourcuff", "Lachor", "Ramaré", "Demont", "Cabaye", "Hartock", "Thuram", "Mollo", "Carrasso", "Andreu", "Benalouane", "Hautcoeur", "Pelé", "Audel", "Lapeyre", "Gouffran");
soluce[16]        = new Array("Yoann Gourcuff (Bordeaux)", "Yoann Lachor (Boulogne)", "Johan Ramaré (Boulogne)", "Yohan Demont (Lens)", "Yohan Cabaye (Lille)", "Joan Hartock (Lyon)", "Yohann Thuram (Monaco)", "Yohan Mollo (Monaco)", "Johann Carrasso (Montpellier)", "Yoann Andreu (ASSE)", "Yohan Benalouane (ASSE)", "Yohan Hautcoeur (ASSE)", "Yohann Pelé (Toulouse)", "Johan Audel (Valenciennes)", "Johan Lapeyre (Nancy)", "Yoan Gouffran (Bordeaux)");
nb_hxcd[16]       = hxcd[16].length;

// Quiz 17
mot_singulier[17] = "équipe";
mot_pluriel[17]   = "équipes";
hxcd[17]          = new Array("Azerbaïdjan", "Arménie", "Andorre", "Malte", "Iles Feroë", "Chypre", "Autriche");
soluce[17]        = new Array("Azerbaïdjan (2 victoires)", "Arménie (1 victoire)", "Andorre (3 victoires)", "Malte (2 victoires)", "Iles Feroë (6 victoires)", "Chypre (2 victoires)", "Autriche (1 défaîte)");
nb_hxcd[17]       = hxcd[17].length;

// Quiz 18
mot_singulier[18] = "club";
mot_pluriel[18]   = "clubs";
hxcd[18]          = new Array("CSKA Moscou", "Dinamo Moscou", "FC Moscou", "Lokomotiv Moscou", "Presnya Moscou", "Spartak Moscou", "Torpedo Moscou");
soluce[18]        = new Array("CSKA Moscou", "Dinamo Moscou", "FC Moscou", "Lokomotiv Moscou", "Presnya Moscou", "Spartak Moscou", "Torpedo Moscou");
nb_hxcd[18]       = hxcd[18].length;

// Quiz 19
mot_singulier[19] = "stade";
mot_pluriel[19]   = "stades";
hxcd[19]          = new Array("Léon Bollée", "Félix Bollaert", "Yves Allainmat", "Marcel Picot", "Geoffroy Guichard", "Auguste Bonal", "Jacques Chaban-Delmas", "Léo Lagrange");
soluce[19]        = new Array("Léon Bollée (Le Mans)", "Félix Bollaert (Lens)", "Yves Allainmat (Lorient - nom officiel du stade du Moustoir)", "Marcel Picot (Nancy)", "Geoffroy Guichard (ASSE)", "Auguste Bonal (Sochaux)", "Jacques Chaban-Delmas (Bordeaux)", "Léo Lagrange (Nice - nom officiel du stade du Ray)");
nb_hxcd[19]       = hxcd[19].length;

// Quiz 20
mot_singulier[20] = "buteur";
mot_pluriel[20]   = "buteurs";
hxcd[20]          = new Array("Giuly", "Bergessio", "Jussié", "Le Tallec", "Berenguer", "Bakar", "Briand", "Oliech", "Ben Khalfallah", "Kazim-Richards");
soluce[20]        = new Array("Ludovic Giuly (PSG)", "Gonzalo Bergessio (ASSE)", "Jussié (Bordeaux)", "Anthony Le Tallec (Le Mans)", "Pascal Berenguer (Nancy)", "Djamel Bakar (Nancy)", "Jimmy Briand (Rennes)", "Dennis Oliech (Auxerre)", "Fahid Ben Khalfallah (Valenciennes)", "Colin Kazim-Richards (Toulouse)");
nb_hxcd[20]       = hxcd[20].length;

// Quiz 21
mot_singulier[21] = "joueur";
mot_pluriel[21]   = "joueurs";
hxcd[21]          = new Array("Bouazza", "Ghilas", "Kermorgant", "Coquelin", "Gudjohnsen", "Nimani", "Klasnic");
soluce[21]        = new Array("Hameur Bouazza (de Blackpool à Arles)", "Kamel Ghilas (de Hull City à Arles)", "Yann Kermorgant (de Leicester à Arles)", "Francis Coquelin (de Arsenal à Lorient)", "Eidur Gudjohnsen (de Tottenham à Monaco)", "Frédéric Nimani (de Burnley à Monaco)", "Ivan Klasnic (de Bolton à Nantes)");
nb_hxcd[21]       = hxcd[21].length;

function checkAnsrs(fld, id_quiz) {

    var tab_solution = new Array();

    nb_reponse = nb_hxcd[id_quiz];

    if (begclo == 0) {
        begclo = 1;
        document.getElementById("remain").innerHTML = "<b>Encore&nbsp;" + nb_reponse + "&nbsp;" + mot_pluriel[id_quiz] + "&nbsp;à trouver...</b>";
        redo(id_quiz, nb_reponse);
    }

    if (fld.value.length > 1) {

        for (var i = 0 ; i < hxcd[id_quiz].length ; i++) {

            reponse = fld.value.toLowerCase();
            solution = hxcd[id_quiz][i].toLowerCase();

            //tab_solution = solution.split(separateur);

            if (reponse == solution) {

                // Une réponse de trouvée
                found[found.length] = soluce[id_quiz][i];
                found.sort();
                hxcd[id_quiz].splice(i, 1);
								soluce[id_quiz].splice(i, 1);
                fld.value = "";
                count++;

                // Le message avec les bonnes réponses
                msg = "Pour l'instant vous avez trouvé : <span class='quiz_gras'>";
                for (var x = 0 ; x < found.length ; x++) {
                    msg += found[x];
                    if  (x < (found.length - 1)) msg += ", ";
                    if ((x + 1) % 4 == 0) msg += "<br/>";
                }
                msg += "</span>";
                document.getElementById("found").innerHTML = msg;

                // Le message avec le nombre de réponses restantes
                msg = "<b>Encore&nbsp;" + (nb_reponse - count) + "&nbsp;";
                if ((nb_reponse - count) == 1) {
                    msg += mot_singulier[id_quiz];
                } else {
                    msg += mot_pluriel[id_quiz];
                }
                msg += "&nbsp;à trouver...</b>";
                document.getElementById("remain").innerHTML = msg;

                if (count == nb_reponse) {
                    window.alert("Bravo !");
                    resultmessage(nb_reponse);
                }
            }
        }

    } else {
        if (fld.value == " ") fld.value = "";
    }
}

function showMissed(id_quiz) {

    msg = "Vous avez oublié :<br/><span class='quiz_gras'>";
    for (x = 0 ; x < soluce[id_quiz].length ; x++) {
        msg += soluce[id_quiz][x];
        if  (x < (soluce[id_quiz].length - 1)) msg += ", ";
        if ((x+1) % 3 == 0) msg += "<br/>";
    }
    msg += "</span><br/>";

    document.getElementById("missing").innerHTML = msg;
    resultmessage(x);
}

function resultmessage(nb) {

    if (count >= (0.7 * nb)) {
        msg = "Très beau score, vous êtes dans l'élite !";
    }
    else {
        msg = "Il y a encore du boulot...";
    }
    document.getElementById("rsltmsg").innerHTML=msg;
}
