Sunday, January 23, 2011

script aidant à gérer son zoo.


// ==UserScript==
// @name   Monzoo Help
// @author   Mahab, sur la base d'un script initial de Mikey, script pratiquement complètement réécrit : merci à lui quand même ;)
// @description  script aidant à gérer son zoo
// @version   1.4.07.6
// @source    http://userscripts.org/scripts/show/63727
// @identifier   http://userscripts.org/scripts/show/63727.user.js
// @include   http://www.monzoo.net/*
// @include   http://www.virtualgamessc.com/*

// ==/UserScript==

var this_version = "1.4.07.6";

function $(id) { return document.getElementById(id); }
function $c(classe) { return document.getElementsByClassName(classe); }
function $t(balise, doc)
{ var doc = doc ? doc : document;
 if (doc.getElementsByTagName(balise)[0]) return doc.getElementsByTagName(balise);
 else return false;
}

String.prototype.trim = function() { return this.replace(/(?:^\s+|\s+$)/g, ""); }

String.prototype.noAccent = function()
{
 var init = new Array('à|á|â|ã|ä', 'ç', 'è|é|ê|ë', 'ì|í|î|ï', 'ñ', 'ò|ó|ô|õ|ö', 'ù|ú|û|ü', 'ý|ÿ', 'À|Á|Â|Ã|Ä', 'Ç', 'È|É|Ê|Ë', 'Ì|Í|Î|Ï', 'Ñ', 'Ò|Ó|Ô|Õ|Ö', 'Ù|Ú|Û|Ü', 'Ý');
 var repl = new Array('a', 'c', 'e', 'i', 'n', 'o', 'u', 'y', 'A', 'C', 'E', 'I', 'N', 'O', 'U', 'Y');
 var str = this, i0, reg;
 for (i0=0; i0<init.length; i0++)
 { reg = new RegExp(init[i0], "g");
  str = str.replace(reg, repl[i0]);
 }
 return str;
}

function Animal(prix, enclos, bonus, nom, agroupe, stock)
{
 if (!bonus || bonus == '') bonus = false;
 if (!nom) nom = "";
 if (!agroupe) agroupe = false;
 if (!stock) stock = false;
 this.prix = prix;
 this.enclos = enclos;
 this.bonus = bonus;
 this.nom = nom;
 this.agroupe = agroupe;
 this.stock = stock;
}

function AnimBonus(image1, nom, image2)
{
 this.image1 = image1;
 this.nom = nom;
 if (!image2) this.image2 = image1;
 else this.image2 = image2;
}

function serialize(tab) // pour transformer un tableau en string pour pouvoir le stocker
{
 if (typeof(tab) != "undefined")
 { var string = "", i1;
  for (i1 in tab) { string += i1 + "," + tab[i1] + ";"; }
  return string;
 }
}

function unserialize(string) // retransforme une chaine en tableau, voire en double tableau
{
 var tab = new Array(), i2, i3;
 if (typeof(string) != "undefined")
 { while (string.length != 0)
  { i2 = string.substring(0, string.indexOf(","));
   sousstring = string.substring(string.indexOf(",") + 1, string.indexOf(";"));
   if (sousstring.indexOf(",") != -1)
   { tab[i2] = new Array(), i3 = 0;
    while(sousstring.indexOf(",") != -1)
    { tab[i2][i3] = sousstring.substring(0, sousstring.indexOf(","));
     i3++;
     sousstring = sousstring.substring(sousstring.indexOf(",") + 1);
    }
    tab[i2][i3] = sousstring;
   }
   else tab[i2] = sousstring;
   string = string.substring(string.indexOf(";") + 1);
  }
 }
 return tab;
}

function ajoute_br(elt) // ajoute un saut de ligne à un élément
{
 var bbr = document.createElement("br");
 elt.appendChild(bbr);
}

function position(elt, niveau) // récupère la position d'un élément (top et left)
{
 var x = 0, y = 0;
 if (!niveau) niveau = null;
 while (elt != niveau)
 { x += elt.offsetLeft-elt.scrollLeft;
  y += elt.offsetTop-elt.scrollTop;
  elt = elt.offsetParent;
 }
 return {x:x,y:y};
}

function image_options() // affichage de l'image pour les options
{
 var bimg = document.createElement("img");
 //bimg.src = "http://www.fotosearch.com/bthumb/CSP/CSP068/k0688841.jpg"; // panda
 bimg.src = "http://montdm.servhome.org/ScriptMonZoo/images/P1010909.jpg"; // bouquetin
 bimg.id = "img_options";
 bimg.style.top = "3px";
 bimg.style.left = "14px";
 bimg.style.width = "164px";
 bimg.style.height = "112px";
 bimg.style.border = "0px";
 bimg.style.position = "absolute";
 bimg.style.cursor = "pointer";
 bimg.alt = "jeune bouquetin";
 bimg.setAttribute("onmouseout", "UnTip()");
 bimg.setAttribute("onmouseover", "Tip(\"Cliquez ici pour accéder aux options :<br />- de l'affichage dans les enclos,<br />- de la gestion des stocks,<br />- de l'affichage sur le forum,<br />- de l'affichage des infos sur les adultes<br />- des graphiques.\", BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
 bimg.addEventListener("click", options, true);
 $c("menu")[0].appendChild(bimg);
}

function options()
{
 if (parseInt(GM_getValue("nbpoints", 5)) == 5) fenetre_options(false);
 else fenetre_options(true);
}

function fenetre_options(repartition) // affichage de la fenêtre des options
{
 var bdiv = $("options");
 if (!bdiv)
 { bdiv = document.createElement("div");
  bdiv.id = "options";
  bdiv.className = "info_bulle";

  bdiv.style.top = "5px";
  gauche = position($c("menu")[0])["x"] - 110;
  bdiv.style.left = gauche > 0 ? gauche + "px" : "0px";
  document.body.appendChild(bdiv);

  var text = document.createElement("h4");
  var i4, choix, nom;
  text.setAttribute("style", "margin-top:3px");
  text.innerHTML = "Type d'encadrement dans les enclos pour les naissances, les mourants et les vieux :";
  bdiv.appendChild(text);

  /* choix du type d'affichage
     p_affichage = 1 => tour de l'image + barre de vie, sinon tour de la barre de vie uniquement */
  var p_affichage = parseInt(GM_getValue("p_affichage", 1));
  GM_setValue("p_affichage", p_affichage); // si l'utilisateur oublie d'enregistrer son nouveau choix, on enregistre le choix 1 (1ère connexion) sinon le choix précédent
  var liste = document.createElement("select");
  liste.setAttribute("style", "background-color:#eac893;font-size:12px");
  liste.name = "choix_affichage";
  liste.id = "choix_affichage";
  for (i4=1;i4<=2;i4++)
  { choix = document.createElement("option");
   choix.value = i4;
   choix.innerHTML = i4 == 1?"Encadrement complet (image + barre)":"Encadrement uniquement de la barre de vie";
   liste.appendChild(choix);
  }
  liste.selectedIndex = p_affichage - 1;
  bdiv.appendChild(liste);
  ajoute_br(bdiv);

  text = document.createElement("h4");
  text.innerHTML = "Age maximum à prendre en compte pour les vieux :";
  bdiv.appendChild(text);

  /* case texte pour les vieux */
  var vieux = parseInt(GM_getValue("vieux", 10));
  GM_setValue("vieux", vieux); // si l'utilisateur oublie d'enregistrer son nouveau choix, on enregistre 10 pour la valeur des vieux sinon le choix précédent
  choix = document.createElement("input");
  choix.type = "text";
  choix.name = "choix_vieux";
  choix.setAttribute("style", "font-size:11px;padding:0px;text-align:center");
  choix.size = "3";
  choix.value = vieux;
  nom = document.createElement("label");
  nom.setAttribute("for", "choix_vieux");
  nom.innerHTML = " (minimum = 5; maximum = 92)";
  bdiv.appendChild(choix);
  bdiv.appendChild(nom);
  ajoute_br(bdiv);

  text = document.createElement("h4");
  text.innerHTML = "Contrer partiellement le bug de la double MAJ :";
  bdiv.appendChild(text);

  /* pour contrer ou non le bug de la double MAJ
     antibug = 1 => on contre */
  var antibug = parseInt(GM_getValue("antibug", 2));
  GM_setValue("antibug", antibug); // si l'utilisateur oublie d'enregistrer son nouveau choix, on enregistre le choix 2 (1ère connexion) sinon le choix précédent
  liste = document.createElement("select");
  liste.setAttribute("style", "background-color:#eac893;font-size:12px");
  liste.name = "choix_antibug";
  liste.id = "choix_antibug";
  for (i4=1;i4<=2;i4++)
  { choix = document.createElement("option");
   choix.value = i4;
   choix.innerHTML = i4 == 1?"Je double les stocks":"Je ne fais rien";
   liste.appendChild(choix);
  }
  liste.selectedIndex = antibug - 1;
  bdiv.appendChild(liste);
  ajoute_br(bdiv);

  text = document.createElement("h4");
  text.innerHTML = "Affichage sur le forum des achats et/ou des ventes :";
  bdiv.appendChild(text);

  // affichage des achats/ventes sur le forum
  var achatforum = parseInt(GM_getValue("achatforum", 2));
  GM_setValue("achatforum", achatforum); // si l'utilisateur oublie d'enregistrer son nouveau choix, on enregistre le choix 2 (1ère connexion) sinon le choix précédent
  liste = document.createElement("select");
  liste.setAttribute("style", "background-color:#eac893;font-size:12px");
  liste.name = "choix_achatforum";
  liste.id = "choix_achatforum";
  for (i4=1;i4<=4;i4++)
  { choix = document.createElement("option");
   choix.value = i4;
   switch(i4)
   { case 1 : choix.innerHTML = "Tout afficher"; break;
    case 2 : choix.innerHTML = "Ne rien afficher"; break;
    case 3 : choix.innerHTML = "N'afficher que les achats"; break;
    case 4 : choix.innerHTML = "N'afficher que les ventes"; break;
   }
   liste.appendChild(choix);
  }
  liste.selectedIndex = achatforum - 1;
  bdiv.appendChild(liste);
  ajoute_br(bdiv);

  text = document.createElement("h4");
  text.innerHTML = "Afficher les futurs adultes dans le tableau des animaux  :";
  bdiv.appendChild(text);

  /* afficher les futurs adultes
     afficheadulte = 1 => on affiche */
  var afficheadulte = parseInt(GM_getValue("afficheadulte", 1));
  GM_setValue("afficheadulte", afficheadulte); // si l'utilisateur oublie d'enregistrer son nouveau choix, on enregistre le choix 1 (1ère connexion) sinon le choix précédent
  liste = document.createElement("select");
  liste.setAttribute("style", "background-color:#eac893;font-size:12px");
  liste.name = "choix_afficheadulte";
  liste.id = "choix_afficheadulte";
  for (i4=1;i4<=2;i4++)
  { choix = document.createElement("option");
   choix.value = i4;
   choix.innerHTML = i4 == 1?"Oui":"Non";
   liste.appendChild(choix);
  }
  liste.selectedIndex = afficheadulte - 1;
  bdiv.appendChild(liste);
  ajoute_br(bdiv);

  text = document.createElement("h4");
  text.setAttribute("style", "margin-bottom:2px");
  text.innerHTML = "Graphiques du suivi :";
  bdiv.appendChild(text);

  var tableau = document.createElement("table");
  tableau.setAttribute("style", "border-collapse:collapse");
  var ligne = document.createElement("tr");
  var casetab = document.createElement("td");
  casetab.width = "7px";
  ligne.appendChild(casetab);
  casetab = document.createElement("td");
  casetab.width = "250px";
  text = document.createElement("h4");
  text.setAttribute("style", "margin-top:0px;color:#634425");
  text.innerHTML = "- nbr de points maxi :";
  casetab.appendChild(text);

  // boutons radio pour le choix du nbr de points des graphiques
  var nbpoints = parseInt(GM_getValue("nbpoints", 5));
  GM_setValue("nbpoints", nbpoints); // si l'utilisateur oublie d'enregistrer son nouveau choix, on enregistre le choix 1 (1ère connexion) sinon le choix précédent
  for (i4=1;i4<=5;i4++)
  { choix = document.createElement("input");
   choix.type = "radio";
   choix.name = "choix_nbpoints";
   choix.id = "choix_nbpoints"+i4;
   choix.value = i4;
   nom = document.createElement("label");
   nom.setAttribute("for", "choix_nbpoints"+i4);
   if (i4 == nbpoints) choix.checked = true;
   switch(i4)
   { case 1: nom.innerHTML = "50&nbsp;&nbsp;&nbsp;"; break;
    case 2: nom.innerHTML = "75&nbsp;&nbsp;&nbsp;"; break;
    case 3: nom.innerHTML = "100&nbsp;&nbsp;&nbsp;"; break;
    case 4: nom.innerHTML = "150&nbsp;&nbsp;&nbsp;"; break;
    case 5: nom.innerHTML = "Tous";
   }
   casetab.appendChild(choix);
   casetab.appendChild(nom);
  }
  ligne.appendChild(casetab);
  tableau.appendChild(ligne);

  ligne = document.createElement("tr");
  ligne.id = "répartitionpoints";
  casetab = document.createElement("td");
  ligne.appendChild(casetab);
  casetab = document.createElement("td");
  casetab.setAttribute("style", "padding-bottom:7px");
  text = document.createElement("h4");
  text.setAttribute("style", "margin-top:4px;color:#634425");
  text.innerHTML = "- choix dans la répartition des points :";
  casetab.appendChild(text);
  var typerepartition = parseInt(GM_getValue("typerepartition", 1));
  GM_setValue("typerepartition", typerepartition); // si l'utilisateur oublie d'enregistrer son nouveau choix, on enregistre le choix 1 (1ère connexion) sinon le choix précédent
  for (i4=1;i4<=2;i4++)
  { choix = document.createElement("input");
   choix.type = "radio";
   choix.name = "choix_répartition";
   choix.id = "choix_répartition"+i4;
   choix.value = i4;
   nom = document.createElement("label");
   nom.setAttribute("for", "choix_répartition"+i4);
   if (i4 == typerepartition) choix.checked = true;
   nom.innerHTML = i4 == 1?"Equilibré&nbsp;&nbsp;&nbsp;":"Les derniers";
   casetab.appendChild(choix);
   casetab.appendChild(nom);
  }
  casetab.title = "Equilibré = on affiche les points équitablement répartis depuis l'origine jusqu'aux dernières données / " +
   "Les derniers = on affiche que les dernières données.";
  ligne.appendChild(casetab);
  tableau.appendChild(ligne);
  bdiv.appendChild(tableau);

  // zone bouton
  tableau = document.createElement("table");
  ligne = document.createElement("tr");
  casetab = document.createElement("td");
  casetab.style.textAlign = "center";
  casetab.width = "165px";
  // bouton enregistrer
  var btn = document.createElement("input");
  btn.type = "button";
  btn.value = "Sauvegarder";
  btn.addEventListener("click", enregistre_choix, true);
  casetab.appendChild(btn);
  ligne.appendChild(casetab);
  casetab = document.createElement("td");
  casetab.innerHTML = "version : " + this_version;
  casetab.style.textAlign = "right";
  casetab.style.fontWeight = "bold";
  casetab.width = "130px";
  ligne.appendChild(casetab);
  tableau.appendChild(ligne);
  bdiv.appendChild(tableau);
 }
 if (repartition) $("répartitionpoints").style.display = "";
 else $("répartitionpoints").style.display = "none";
}

function enregistre_choix() // enregistre les options
{
 var i5;
 GM_setValue("p_affichage", 1 + $("choix_affichage").selectedIndex);
 GM_setValue("antibug", 1 + $("choix_antibug").selectedIndex);
 GM_setValue("achatforum", 1 + $("choix_achatforum").selectedIndex);
 GM_setValue("afficheadulte", 1 + $("choix_afficheadulte").selectedIndex);
 
 for (i5=1;i5<=5;i5++)
  if ($("choix_nbpoints"+i5).checked == true) GM_setValue("nbpoints", i5);
 if (parseInt(GM_getValue("nbpoints", 5)) != 5)
  for (i5=1;i5<=2;i5++)
   if ($("choix_répartition"+i5).checked == true) GM_setValue("typerepartition", i5);

 var choix = document.getElementsByName("choix_vieux");
 i5 = parseInt(choix[0].value);
 if (i5 > 4 && i5 < 93 && parseFloat(choix[0].value) - i5 == 0)
 { GM_setValue("vieux", i5);
  $("options").parentNode.removeChild($("options"));
 }
 else alert("valeur incorrecte pour l'âge maximum des vieux :\nmerci de saisir une valeur entière entre 5 et 92 compris");
}

function montre_zoos() // affiche et masque la liste des zoos sur le forum
{
 if ($("liste_zoo").style.display == "none") $("liste_zoo").style.display = "block";
 else $("liste_zoo").style.display = "none";
}

function insere_liste() // publie le rapport sur le forum
{
 if (liste_zoo != "")
 { var mes_naissances, mes_trouvailles, mes_vols, i6, MAJ, dateMAJ;

  for (i6 in tab_zoo) { if (this.id == tab_zoo[i6][0]) { id_zoo = i6; break; }}
  mes_naissances = listes("naissances", "forum");
  mes_trouvailles = listes("trouvailles", "forum");
  mes_vols = listes("vols", "forum");
  var achatforum = GM_getValue("achatforum", 1);
  mes_achats = achatforum == 1 || achatforum == 3 ? listes("achats", "forum"):"";
  mes_ventes = achatforum == 1 || achatforum == 4 ? listes("ventes", "forum"):"";
  MAJ = GM_getValue("dateConnexion_"+id_zoo, "");
  dateMAJ = MAJ.substring(0,MAJ.lastIndexOf("/"));
  MAJ = MAJ.substring(MAJ.lastIndexOf("/")+1);
  $("req_message").value += "\r\n[quote][u][b]Version :[/b][/u] " + this_version + "\r\n[u][b]Parc :[/b][/u] " + tab_zoo[id_zoo][0] + "\r\n[u][b]MAJ n°[/b][/u] " + MAJ + " [u][b]du[/b][/u] " + dateMAJ + "\r\n" + mes_naissances + mes_trouvailles + mes_vols + mes_achats + mes_ventes + "[/quote]";
 }
}

function affiche_rapport(scan_fait) // affiche le rapport
{
 var contenu_rapport = "<div class=\"bloc_rapport\"><h6>Enclos</h6>";
 if (!scan_fait)
 { contenu_rapport += "<span class=\"attention\">Attention,</span><br />";
  contenu_rapport += "<span>il y a peut-être un déséquilibre de PA pour un certain nombre de vos enclos</span><br />";
  contenu_rapport += "<span>et vos stocks sont peut-être insuffisants :</span><br />";
  contenu_rapport += "<span>vérifiez vos enclos un par un et contrôler vos stocks vous-même,</span><br />";
  contenu_rapport += "<span>ou mettez tout à jour en relançant ce rapport.</span><br />";
 }
 else contenu_rapport += "<span>Les PA de tous vos enclos et vos stocks sont à jour.</span><br />";

 contenu_rapport += "</div><hr class=\"separateur\" />";
 contenu_rapport += "<div class=\"bloc_rapport\">" + listes("naissances", "rapport") + "</div><hr class=\"separateur\" />";
 contenu_rapport += "<div class=\"bloc_rapport\">" + listes("trouvailles", "rapport") + "</div><hr class=\"separateur\" />";
 contenu_rapport += "<div class=\"bloc_rapport\">" + listes("vols", "rapport") + "</div><hr class=\"separateur\" />";
 contenu_rapport += "<div class=\"bloc_rapport\">" + listes("achats", "rapport") + "</div><hr class=\"separateur\" />";
 contenu_rapport += "<div class=\"bloc_rapport\">" + listes("ventes", "rapport") + "</div>";

 // on remplace le texte du tableau par le nouveau rapport
 var btd = $t("td");
 btd[4].innerHTML = contenu_rapport;
}

function listes(type_liste, publication) // crée les listes (vol, naissance ou trouvaille) pour le rapport et le forum
{
 var ma_liste = "", tableau = new Array(), id;
 if (type_liste == "vols")
 { if (GM_getValue("string_vols_" + id_zoo, "") != "")
  { tableau = unserialize(GM_getValue("string_vols_"+id_zoo, ""));
   if (publication == "rapport")
   { for (id in tableau) 
    { if (parseInt(id) > 10)
      ma_liste += "<span class=\"attention\">Echec : " + tableau[id] + " !</span><br />";
     else ma_liste += "<span class=\"bonus\">Réussi : " + tableau[id] + " !</span><br />";
    }
    ma_liste = "<h6>Vols</h6>" + ma_liste;
   }
   else
   { for (id in tableau) 
    { if (parseInt(id) > 10)
      ma_liste += "[b][color=#FA2104]Echec : " + tableau[id] + " ![/color][/b] ";
     else ma_liste += "[b][color=#4bb86c]Réussi : " + tableau[id] + " ![/color][/b] ";
    }
    ma_liste = ma_liste.substring(0, ma_liste.length-1);
    ma_liste = "[u][b]Vols :[/b][/u] " + ma_liste + "\r\n";;
   }
  }
  else if (publication == "rapport")
   ma_liste = "<h6>Vols</h6><span>Aucun vol réussi.</span>";
  else ma_liste = "[u][b]Aucun vol réussi[/b][/u].\r\n";
 }
 else
 { tableau = unserialize(GM_getValue("string_" + type_liste + "_"+id_zoo, ""));
  var enclos, i7, nb = 0, valeur = 0, moyenne;
  var tab_animaux = new Array(), animauxtries = new Array();
  for (enclos in tableau)
  { for (i7=0; i7<tableau[enclos].length; i7+=2)
   { animauxtries.push(tableau[enclos][i7]);
    tab_animaux[tableau[enclos][i7]] = tableau[enclos][i7+1];
   }
  }
  animauxtries.sort();
  for (i7 in animauxtries)
  { if (publication == "rapport")
   { if (/albinos/.test(animauxtries[i7])) ma_liste += "<span class=\"albinos\">" + animauxtries[i7] + " : " + tab_animaux[animauxtries[i7]] + "</span>";
    else if (ANIMAUX[animauxtries[i7]].bonus) ma_liste += "<span class=\"bonus\">" + animauxtries[i7] + " : " + tab_animaux[animauxtries[i7]] + "</span>";
    else if (ANIMAUX[animauxtries[i7]].prix >= 100000) ma_liste += "<span class=\"cher\">" + animauxtries[i7] + " : " + tab_animaux[animauxtries[i7]] + "</span>";
    else ma_liste += "<span>" + animauxtries[i7] + " : " + tab_animaux[animauxtries[i7]] + "</span>";
    ma_liste += "<br />";
   }
   else
   { if (/albinos/.test(animauxtries[i7])) ma_liste += "[b][color=#31b9E4]" + animauxtries[i7] + " : " + tab_animaux[animauxtries[i7]] + "[/color][/b]";
    else if (ANIMAUX[animauxtries[i7]].bonus) ma_liste += "[b][color=#1bb86c]" + animauxtries[i7] + " : " + tab_animaux[animauxtries[i7]] + "[/color][/b]";
    else if (ANIMAUX[animauxtries[i7]].prix >= 100000) ma_liste += "[b][color=#2732c7]" + animauxtries[i7] + " : " + tab_animaux[animauxtries[i7]] + "[/color][/b]";
    else ma_liste += animauxtries[i7] + " : " + tab_animaux[animauxtries[i7]];
    ma_liste += ", ";
   }
   nb += parseInt(tab_animaux[animauxtries[i7]]);
   valeur += parseInt(tab_animaux[animauxtries[i7]]) * ANIMAUX[animauxtries[i7]].prix;
  }
  if (nb > 1) { s="s"; moyenne = Math.round(valeur/nb); }
  else { s=""; moyenne = valeur; }
  if (type_liste == "naissances")
  { var valeur_th, moyenne_th, valeurT, nb_theorique, felins, males, femelles, s1 = "", s2 = "";
   valeur = millier(valeur);
   moyenne = millier(moyenne);
   valeur_th = parseFloat(GM_getValue("valeur_th_" + id_zoo, "0"));
   nb_theorique = parseFloat(GM_getValue("nb_th_"+id_zoo, "0"));
   moyenne_th = nb_theorique != 0 ? Math.round(valeur_th / nb_theorique):0;
   nb_theorique = Math.round(nb_theorique * 100) / 100;
   valeur_th = millier(Math.round(valeur_th));
   moyenne_th = millier(moyenne_th);
   valeurT = millier(parseInt(GM_getValue("valeurT_" + id_zoo, 0)));
   males = unserialize(GM_getValue("sexes_" +id_zoo, ""));
   femelles = parseInt(males[1]);
   males = parseInt(males[0]);
   couples = millier(parseInt(GM_getValue("couples_" + id_zoo, 0)));
   nbanim = GM_getValue("suivi_naissances_" + id_zoo, 0);
   nbanim = nbanim.substring(nbanim.lastIndexOf(":")+1);
   nbanim = nbanim.substring(nbanim.indexOf("/")+1);
   nbanim = nbanim.substring(nbanim.indexOf("/")+1);
   agemoyen = nbanim.substring(nbanim.indexOf("/")+1);
   agemoyen = parseFloat(agemoyen.substring(0,agemoyen.indexOf(",")));
   nbanim = millier(parseInt(nbanim.substring(0,nbanim.indexOf("/")).replace(" ","","g")));
   if (males > 1) s1 = "s";
   if (femelles > 1) s2 = "s";
   if (publication == "rapport")
   { felins = GM_getValue("felins_"+id_zoo, 0);
    if (nb == 0) ma_liste = "<span>Aucune naissance.</span>";
    ma_liste = "<h6>" + nb + " naissance" + s + " (" + males + " mâle" + s1 +"/" + femelles +" femelle" + s2 + ") pour " + nb_theorique +
     " naissances théoriques</h6><h5>Valeur des naissances : " + valeur + " Zoo'z</h5>" + "<h5>Valeur théorique : " + valeur_th +
     " Zoo'z</h5><h5>Valeur moyenne : " + moyenne + " Zoo'z</h5><h5>Moyenne théorique : " + moyenne_th + " Zoo'z</h5><h5>Nbr de couples adultes de félins : " +
     felins + "</h5>" + "<h5>Valeur réelle du parc : " + valeurT + "</h5>" + "<h5>Nombre de couples adultes : " + couples + "</h5>" +
     "<h5>Nombre d'animaux : " + nbanim + "</h5>" + "<h5>Age moyen des animaux : " + agemoyen + "</h5>" + ma_liste;
   }
   else
   { if (nb>0) ma_liste = ma_liste.substring(0, ma_liste.length-2) + ".\r\n";
    else ma_liste = "aucune naissance.\r\n";
    ma_liste = "[u][b]Valeur réelle du parc :[/b][/u] " + valeurT + " Zoo'z.\r\n[u][b]Nombre de couples adultes :[/b][/u] " + couples +
     ".\r\n[u][b]Nombre d'animaux :[/b][/u] " + nbanim + ".\r\n[u][b]Age moyen des animaux :[/b][/u] " + agemoyen + " jours restant à vivre.\r\n[u][b]" +
     nb + " naissance" + s + "[/b][/u] (" + males + " mâle" + s1 +"/" + femelles +" femelle" + s2 + ") pour " + nb_theorique +
     " naissances théoriques, [u][b]valeur:[/b][/u] " + valeur + " Zoo'z (théorie: " + valeur_th +
     "), [u][b]moyenne:[/b][/u] " + moyenne + " Zoo'z (théorie: " + moyenne_th + "), [u][b]détail:[/b][/u] " + ma_liste;
   }
  }
  else if (type_liste == "trouvailles")
  { if (publication == "rapport")
   { if (nb>0) ma_liste = "<h6>" + nb + " trouvaille" + s + "</h6>" + ma_liste;
    else ma_liste = "<h6>Trouvailles</h6><span>Aucune trouvaille.</span>";
   }
   else
   { if (nb>0) ma_liste = "[u][b]" + nb + " trouvaille" + s + " :[/b][/u] " + ma_liste.substring(0, ma_liste.length-2) + ".\r\n";
    else ma_liste = "[u][b]Aucune trouvaille[/b][/u].\r\n";
   }
  }
  else if (type_liste == "achats")
  { if (publication == "rapport")
   { if (nb>0) ma_liste = "<h6>" + nb + " achat" + s + "</h6>" + ma_liste;
    else ma_liste = "<h6>Achats</h6><span>Aucun achat.</span>";
   }
   else
   { if (nb>0) ma_liste = "[u][b]" + nb + " achat" + s + " :[/b][/u] " + ma_liste.substring(0, ma_liste.length-2) + ".\r\n";
    else ma_liste = "[u][b]Aucun achat[/b][/u].\r\n";
   }
  }
  else
  { if (publication == "rapport")
   { if (nb>0) ma_liste = "<h6>" + nb + " vente" + s + "</h6>" + ma_liste;
    else ma_liste = "<h6>Ventes</h6><span>Aucune vente.</span>";
   }
   else
   { if (nb>0) ma_liste = "[u][b]" + nb + " vente" + s + " :[/b][/u] " + ma_liste.substring(0, ma_liste.length-2) + ".\r\n";
    else ma_liste = "[u][b]Aucune vente[/b][/u].\r\n";
   }
  }
 }

 return ma_liste;
}

function lancerespions()
{
 GM_setValue("espions", true);
 binput[0].dispatchEvent(clickmouse);
}

function lancerscan()
{
 GM_deleteValue("oeuf_"+id_zoo);
 if (GM_getValue("ordre", "") != "")
 { var txt = urlSite + "enclosgestion1.php?t="
  var numenclos = unserialize(GM_getValue("ordre", ""));
  numenclos = parseInt(numenclos[0]);
  txt += Math.floor(numenclos/100) + "&v=";
  numenclos = numenclos - Math.floor(numenclos/100)*100;
  txt += numenclos;
  window.location.href = txt;
 }
 else window.location.href = urlSite + "enclosgestion1.php?t=0&v=0";
}

function achatcouple(e) // achat multiple de couples, mâles ou femelles en un seul clic
{
 var nom = e.target.id.substring(0, e.target.id.indexOf(";"));
 var type = nom.substring(nom.length-1);
 if (type == "1" || type == "2")
 { nom = nom.substring(0, nom.length-1);
  genre = type == "1" ? "mâle" : "femelle";
 }
 else
 { genre = "couple";
  type = "1";
 }
 var feminin = type == "2" ? "e" : "";
 var txt = document.getElementsByName(nom);
 var nbr = parseInt(txt[0].value);
 var maxachats = parseInt(e.target.id.substring(e.target.id.lastIndexOf(";")+1));
 if (nbr > 0 && nbr <= maxachats && parseFloat(txt[0].value) - nbr == 0)
 { var s = nbr > 1 ? "s":"";
  var prix = parseInt(e.target.id.substring(e.target.id.indexOf(";")+1, e.target.id.lastIndexOf(";")));
  var i8, argent;
  var bdiv = $t("div");
  for (i8=25; i8<bdiv.length;i8++) if (bdiv[i8].attributes[0].value.indexOf("width: 125px") != -1) break;
  if (bdiv[i8+1].innerHTML.indexOf("<span") != -1)
  { inn = bdiv[i8+1].innerHTML;
   inn = inn.substring(inn.indexOf(">")+1);
   bdiv[i8+1].innerHTML = inn.substring(0,inn.indexOf("<"));
  }
  argent = parseInt(bdiv[i8+1].innerHTML);
  if (confirm("Vous êtes sur le point d'acheter :\n- " + nbr + " " + genre + s + "\n- de l'espèce \"" + nom + "\"\n- pour un montant total de " + millier(nbr*prix) +
   " Zoo'z.\n\nArgent disponible : " + millier(argent) + " Zoo'z.\nIl vous restera donc : " + millier(argent-nbr*prix) +" Zoo'z après cet achat.\n\nConfirmez-vous votre choix ?"))
  { binput = $t("input");
   for (i8=0; i8<binput.length;i8++) if (binput[i8].value == nom + type) binput[i8].checked = true;
   GM_setValue("achatcouple", nbr + ";" + nom + type);
   GM_setValue("nbrcouples", nbr);
   if (genre == "mâle") GM_setValue("achatmale", true);
   else if (genre == "femelle") GM_setValue("achatfemelle", true);
   for (i8=binput.length-1; i8>=0;i8--) if (binput[i8].value == "Acheter l'animal") break;
   binput[i8].dispatchEvent(clickmouse);
  }
 }
 else if (maxachats > 1) alert("valeur incorrecte, merci de saisir :\n- un nombre entier strictement positif\n- inférieur ou égal à " + maxachats);
 else alert("valeur incorrecte :\nvous ne pouvez acheter qu'un" + feminin + " seul" + feminin + " " + genre);
}

function trouvebonus(e)
{
 var nombonus = e.target.id.substring(0, e.target.id.indexOf(";"));
 var prix = e.target.id.substring(e.target.id.indexOf(";")+1);
 nomachat = prix.substring(0, prix.indexOf(";"));
 var sexe = prix.substring(prix.indexOf(";")+1);
 prix = parseInt(sexe.substring(0, sexe.indexOf(";")));
 sexe = sexe.substring(sexe.indexOf(";")+1);
 var txt = "Vous êtes sur le point de lancer une recherche pour essayer de trouver :\n- un";
 if (sexe == "1") txt += " mâle\n";
 else txt +="e femelle\n";
 txt += "- de l'espèce \"" + nombonus + "\"\n\nen achetant le nombre de fois nécessaire :\n- l'espèce \"" + nomachat + "\"\n- au prix de " + millier(prix) +
  " Zoo'z.\n\nLa recherche s'arrêtera :\n- si vous trouvez l'animal bonus,\n- ou si vous n'avez plus assez d'argent,\n- ou si vous avez atteint la limite des 20 achats,\n- ou si vous décidez de l'arrêter (possible à chaque nouvelle tentative).\n\n" +
  "NB : l'animal acheté pour essayer de trouver un animal bonus est\nrevendu à chaque fois.\n\nConfirmez-vous votre choix ?";
 if (confirm(txt))
 { binput = $t("input");
  nomachat = nomachat.toLowerCase();
  for (i8=0; i8<binput.length;i8++) if(binput[i8].value == nomachat + sexe) binput[i8].checked = true;
  GM_setValue("cherchebonus", nomachat + sexe + ";1");
  for (i8=binput.length-1; i8>=0;i8--) if (binput[i8].value == "Acheter l'animal") break;
  binput[i8].dispatchEvent(clickmouse);
 }
}

function mise_a_jour() // vérification de nouvelles versions et téléchargement
{
 GM_xmlhttpRequest(
 { method:'POST', url:monSite+'?source',
  onload: function(result)
  { if (result.status != 200) return;
   if (!result.responseText.match(/@version\s+([\d.]+)/)) return;
   var VersionServer = RegExp.$1;
   var valVersion = VersionServer.replace(".","","g");
   var sousstring = VersionServer.substring(VersionServer.indexOf(".")+1);
   sousstring = sousstring.substring(sousstring.indexOf(".")+1);
   if (sousstring.indexOf(".") == -1) valVersion = valVersion + "0";
   valVersion = parseInt(valVersion);
   var valThis = this_version.replace(".","","g");
   sousstring = this_version.substring(this_version.indexOf(".")+1);
   sousstring = sousstring.substring(sousstring.indexOf(".")+1);
   if (sousstring.indexOf(".") == -1) valThis = valThis + "0";
   valThis = parseInt(valThis);
   if (valThis < valVersion)
   { if (valThis < 12203)
    { if (confirm("Attention ! Attention ! Attention ! Attention ! Attention ! Attention ! Attention !\n\nMise à jour IMPORTANTE de Monzoo Help !\n" +
     "Mise à jour IMPORTANTE de Monzoo Help !\nMise à jour IMPORTANTE de Monzoo Help !\n\nCette MAJ devrait être installée soit AVANT le scan initial de la journée,\n" +
     "soit APRES toutes vos actions de la journée sur votre zoo (y compris\nvos interventions sur le forum).\n\nSi vous n'êtes pas dans l'un de ces cas, " +
     "cliquez sur 'Annuler'.\n\nVous pourrez y revenir APRES votre gestion quotidienne de votre zoo,\nen cliquant alors " +
     "sur 'Deconnecion'.\n\nMettre à jour maintenant ?"))
      window.location.href = monSite;
    }
    else if (confirm("La version " + VersionServer + " de Monzoo Help est disponible.\r\nMettre à jour maintenant ?\r\n"))
     window.location.href = monSite;
   }
  }
 });
}

function est_connecte() // test de la connexion
{
 if(/www.monzoo.net/.test(window.location))
 { var bdiv = $t("div"), nom = "", i9;
  for (i9=20;i9<bdiv.length;i9++)
   { if (bdiv[i9].style.width == "125px") { nom = bdiv[i9].innerHTML; break; }}
  if (nom != "") return nom;
  else return false;
 }
 else return false;
}

function modification_menu() // ajout menu classement points, classement prestige, classement team
{
 // classement points
 var lien_menu = document.createElement("a");
 lien_menu.addEventListener("click", classement, true);
 lien_menu.setAttribute("style", "cursor:pointer");
 lien_menu.innerHTML = "Mon classement points";
 var classe_points = document.createElement("div");
 classe_points.setAttribute("class", "link");
 classe_points.appendChild(lien_menu);

 // classement prestige
 var lien_menu = document.createElement("a");
 lien_menu.addEventListener("click", classement, true);
 lien_menu.setAttribute("style", "cursor:pointer");
 lien_menu.textContent = "Mon classement prestige";
 var classe_prestige = document.createElement("div");
 classe_prestige.setAttribute("class", "link");
 classe_prestige.appendChild(lien_menu);

 // classement team
 var lien_menu = document.createElement("a");
 lien_menu.addEventListener("click", team, true);
 lien_menu.setAttribute("style", "cursor:pointer");
 lien_menu.textContent = "Notre classement team";
 var classe_team = document.createElement("div");
 classe_team.setAttribute("class", "link");
 classe_team.appendChild(lien_menu);

 var menu = $c("menu")[0];
 var liens = $c("un");
 var ref, ref2, i10 ;
 for (i10=0;i10<liens.length;i10++)
 { if (/event.php/.test(liens[i10].href))
   liens[i10].style.fontWeight = "bold";
  if (/classement.php/.test(liens[i10].href))
   ref = liens[i10];
  if (/team.php/.test(liens[i10].href))
  { ref2 = liens[i10];
   break;
  }
 }
 menu.insertBefore(classe_points, ref.parentNode.nextSibling);
 menu.insertBefore(classe_prestige, ref.parentNode.nextSibling.nextSibling);
 if (GM_getValue("team_"+id_zoo, false)) menu.insertBefore(classe_team, ref2.parentNode.nextSibling);
}

function team(e)
{
 GM_setValue("classement", "team");
 window.location.href = urlSite + "team.php"
}

function classement(e)
{
 if (e.target.textContent == "Mon classement points" || e.target.textContent == "Mon class. points") GM_setValue("classement", "points");
 else GM_setValue("classement", "prestige");
 window.location.href = urlSite + "classement.php"
}

function nom_enclos(t,v) // donne le nom de l'enclos tel que sur la carte
{
 var enclos = "", numero;
 if (t == 1)
 { if (v == 0) enclos = "Volière";
  else if (v == 1) enclos = "Aquarium";
  else if (v == 2) enclos = "Vivarium";
  else if (v == 3) enclos = "Noctarium";
  else if (v == 4) enclos = "Insectarium";
 }
 else
 { if (v < 10) { numero = v+1; enclos = "Savane n° " + numero; }
  else if (v < 16) { numero = v-9; enclos = "Bassin n° " + numero; }
  else if (v < 30) { numero = v-19; enclos = "Terre n° " + numero; }
  else if (v < 41) { numero = v-29; enclos = "Forêt n° " + numero; }
  else if (v < 46) { numero = v-30; enclos = "Savane n° " + numero; }
  else if (v < 51) { numero = v-39; enclos = "Bassin n° " + numero; }
  else if (v < 56) { numero = v-40; enclos = "Terre n° " + numero; }
  else if (v < 61) { numero = v-44; enclos = "Forêt n° " + numero; }
 }
 if (enclos == "") enclos = "bad";
 return enclos;
}

function millier(nb) // transforme un nombre quelconque en string avec espaces
{
 var mil, debu = "", entier = "", deci = "";
 nb = nb.toString();
 if (nb.indexOf(".") != -1) { entier = nb.substring(0,nb.indexOf(".")); deci = nb.substring(nb.indexOf(".")+1); }
 else entier = nb;
 maxi = Math.floor((entier.length-1)/3);
 for (mil=0;mil<maxi;mil++)
 { debu += entier.substring(0,entier.length-3*Math.floor((entier.length-1)/3)) + " ";
  entier = entier.substring(entier.length-3*Math.floor((entier.length-1)/3));
 }
 entier = debu + entier;
 if (deci != "")
 {
  debu = "";
  maxi = Math.floor((deci.length-1)/3);
  for (mil=0;mil<maxi;mil++)
  { debu += deci.substring(0,3) + " ";
   deci = deci.substring(3);
  }
  deci = debu + deci;
  return entier+"."+deci;
 }
 else return entier;
}

function recherche_param(url, param) // recupère la valeur d'un paramètre dans l'url
{
 valeur = url.substring(url.indexOf("?")); // on ne garde que les paramètres de l'url
 valeur = valeur.replace("?", "&");
 param = "&" + param + "=";
 valeur = valeur.substring(valeur.indexOf(param)+param.length);
 if (valeur.indexOf("&") != -1) valeur = valeur.substring(0, valeur.indexOf("&"));
 return valeur;
}

function tableau_animaux(enclos) // affiche le tableau des animaux
{
 if (!enclos) enclos = new Array();
 var espece;
 for (espece in enclos) break;
 if (espece)
 { var liste_enclos;
  pageenclos = /enclosgestion1.php/.test(window.location);
  var animaux_tries = new Array();
  for (espece in enclos) animaux_tries.push(espece);
  animaux_tries.sort();
  var bdiv = $("animaux_enclos");
  if (!bdiv)
  { var enclosavoir = unserialize(GM_getValue("enclosavoir_" + id_zoo, ""));
   var pendant = "";
   avant = "";
   apres = "";
   for (i in enclosavoir)
    if (pendant != "")
    { apres = enclosavoir[i];
     break;
    }
    else if (enclosavoir[i] == numenclos)
     pendant = enclosavoir[i];
    else avant = enclosavoir[i];
   var desequilibre, i11, i12, clique, colsave;
   var albinos = unserialize(GM_getValue("albinos_" + id_zoo, ""));
   var mourant = $c("mourant"), listemourant = new Array();
   if (mourant.length > 0)
   { for (i11=0;i11<mourant.length;i11++)
    { listemourant[i11] = new String(mourant[i11].className.substring(mourant[i11].className.indexOf("animal")+7));
     if (listemourant[i11].indexOf("mâle") != -1) listemourant[i11] = listemourant[i11].substring(0, listemourant[i11].indexOf(" mâle"));
     else listemourant[i11] = listemourant[i11].substring(0, listemourant[i11].indexOf(" femelle"));
     listemourant[i11] = listemourant[i11].replace("%20", " ", "g");
    }
   }

   liste_enclos = '<table width="100%"><tr style="text-align:center;margin:2px"><td><input type="checkbox" name="affichertabanimaux" id="affichertabanimaux"';
   if (GM_getValue("affichertabanimaux", false)) liste_enclos += ' checked="checked"';
   liste_enclos += '><label for="affichertabanimaux">Afficher</label></input></td></tr></table>' +
    '<div id="tabanimaux" style="width:100%;text-align:center;margin:2px"><table width="100%"><tr style="text-align:center"><td><input type="checkbox" name="etroit" id="etroit"';
   if (GM_getValue("etroit", true)) liste_enclos += ' checked="checked"';
   liste_enclos += "><label for=\"etroit\">Tableau étroit</label></input></td>";
   if (pageenclos) liste_enclos += "<td><input style='font-family:garamond arial sans serif;width:50px' type='button' value='Vendre'></input></td>";
   liste_enclos += "</tr></table><table width=\"100%\" id=\"liste_animaux\"><tr><th class=\"sel\" onmouseout=\"UnTip()\" " +
    "onmouseover=\"Tip('Liste des espèces présentes dans cet enclos";
   if (pageenclos) liste_enclos += "<br />Cliquez ici + sur une espèce pour sélectionner tous les animaux de cette espèce";
   liste_enclos += "', ";
   if (pageenclos) liste_enclos += "WIDTH, 553, ";
   liste_enclos += "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">Animal</th>" +
    "<th class=\"nsel\"><img src=\"images/icones/male.gif\" onmouseout=\"UnTip()\" onmouseover=\"Tip('Nombre de mâles-nombre de vieux mâles";
   if (pageenclos) liste_enclos += "<br />Cliquez ici + sur une espèce pour ne sélectionner que les mâles de cette espèce";
   liste_enclos += "', ";
   if (pageenclos) liste_enclos += "WIDTH, 553, ";
   liste_enclos += "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\"></th><th class=\"nsel\">" +
    "<img src=\"images/icones/female.gif\" onmouseout=\"UnTip()\" onmouseover=\"Tip('Nombre de femelles-nombre de vieilles femelles";
   if (pageenclos) liste_enclos += "<br />Cliquez ici + sur une espèce pour ne sélectionner que les femelles de cette espèce";
   liste_enclos += "', ";
   if (pageenclos) liste_enclos += "WIDTH, 574, ";
   liste_enclos += "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\"></th>";
   if (GM_getValue("afficheadulte", 1) == 1) liste_enclos += "<th style='font-size:10px' onmouseout=\"UnTip()\" onmouseover=\"Tip('Nombre " +
    "de mâles adultes à la prochaine MAJ-nombre de femelles adultes à la prochaine MAJ<br />nb : les espèces albinos sont complétées avec l&rsquo;espèce source', " +
    "WIDTH, 616, BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">Futurs<br />adultes</th>";
   liste_enclos += "</tr>";
   for (i11=0;i11<animaux_tries.length;i11++)
   { animourant = "";
    for (i12=0;i12<listemourant.length;i12++)
     if (listemourant[i12] == animaux_tries[i11]) { animourant = " animourant"; break; }
    if (enclos[animaux_tries[i11]][0] != enclos[animaux_tries[i11]][1] || enclos[animaux_tries[i11]][0] > 15) desequilibre = " class=\"desequilibre\"";
    else desequilibre = "";
    if (albinos[animaux_tries[i11]])
     trop = enclos[animaux_tries[i11]][0] > 15+parseInt(albinos[animaux_tries[i11]][0]) &&
      enclos[animaux_tries[i11]][1] > 15+parseInt(albinos[animaux_tries[i11]][1]) ? " trop":"";
    else trop = enclos[animaux_tries[i11]][0] > 15 && enclos[animaux_tries[i11]][1] > 15 ? " trop":""
    liste_enclos += "<tr"+desequilibre+"><td class=\"titre" + animourant + "\">" + animaux_tries[i11].replace(" ","&nbsp;","g") + "</td><td class=\"mâle actu" + trop + "\">" + 
     enclos[animaux_tries[i11]][0] + "<span>-" + enclos[animaux_tries[i11]][2] + "</span>" + "<td class=\"femelle actu" + trop + "\">" +
     enclos[animaux_tries[i11]][1] + "<span>-" + enclos[animaux_tries[i11]][3] + "</span>" + "</td>";
    if (GM_getValue("afficheadulte", 1) == 1)
    { maxi = parseInt(animauxmax[animaux_tries[i11].replace("&nbsp;"," ","g")]);
     trop = enclos[animaux_tries[i11]][4] > maxi || enclos[animaux_tries[i11]][5] > maxi ? " trop":"";
     liste_enclos += "<td class=\"futur" + trop + "\">" + "<span class=\"mâle\">" + enclos[animaux_tries[i11]][4] +
      "</span> / <span class=\"femelle\">" + enclos[animaux_tries[i11]][5] + "</span></td>";
    }
    liste_enclos += "</tr>";
   }
   liste_enclos += "</table>";
   if (pageenclos)
   { liste_enclos += '<table width="100%"><tr style="text-align:center;"><td style="padding:2px 2px 0px"><input type="checkbox" name="filtre" id="filtre"';
    if (GM_getValue("filtre", false)) liste_enclos += ' checked="checked"';
    liste_enclos += '><label for="filtre">Filtrer</label></input></td></tr>';
    liste_enclos += '<tr style="text-align:center;"><td style="padding:0px 2px"><input type="checkbox" name="triesp" id="triesp"';
    if (GM_getValue("triesp", false)) liste_enclos += ' checked="checked"';
    liste_enclos += '><label for="triesp">Tri par espèce</label></input></td></tr></table></div>';
   }
   else liste_enclos += "</div>";
   if (GM_getValue("etroit", false)) liste_enclos = liste_enclos.replace("&nbsp;", " <br>", "g");
   else liste_enclos = liste_enclos.replace(" <br>", "&nbsp;", "g");
   bdiv = document.createElement("div");
   bdiv.id = "animaux_enclos";
   bdiv.setAttribute("class", "info_bulle");
   bdiv.style.top = "0px";
   bdiv.style.right = "0px";
   bdiv.innerHTML = liste_enclos;
   document.body.appendChild(bdiv);
   $("tabanimaux").style.display = "";
   if (pageenclos)
   { var ctitre = $c("titre");
    for (i11=0;i11<ctitre.length;i11++) ctitre[i11].addEventListener("click", souligneclick, true);
    var csel = $c("sel");
    csel[0].addEventListener("click", typeselclick, true);
    var cnsel = $c("nsel");
    cnsel[0].addEventListener("click", typeselclick, true);
    cnsel[1].addEventListener("click", typeselclick, true);
    if (pendant != "" && (avant != "" || apres != ""))
    { var bdiv2 = document.createElement("div");
     bdiv2.id = "enclosavoir";
     bdiv2.className = "info_bulle";
     precedent = avant != "" ? "<input id=\"precedent\" style=\"font-size:9px;padding:0px\" type=\"button\" value=\"précédent\" onmouseout=\"UnTip()\" onmouseover=\"Tip('Pour revenir à l&rsquo;enclos avec des " +
      "naissances/mourants précédent', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', LEFT, 'true', OFFSETX, 3, " +
      "OFFSETY, -13, TEXTALIGN, 'center')\"></input>":"";
     suivant = apres != "" ? "<input id=\"suivant\" style=\"font-size:9px;padding:0px\" type=\"button\" value=\"suivant\" onmouseout=\"UnTip()\" onmouseover=\"Tip('Pour passer à l&rsquo;enclos avec des " +
      "naissances/mourants suivant', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', LEFT, 'true', OFFSETX, 3, " +
      "OFFSETY, -13, TEXTALIGN, 'center')\"></input>":"";
     bdiv2.innerHTML = "<table><tr><td width=\"70px\">" + precedent + "</td><td width=\"40px\">" + suivant + "</td></tr></table>";
     bdiv2.style.top = "0px";
     document.body.appendChild(bdiv2);
     if (avant != "")
     { encprecedent = $("precedent");
      encprecedent.addEventListener("click", enclosprecedent, true);
     }
     if (apres != "")
     { encsuivant = $("suivant");
      encsuivant.addEventListener("click", enclossuivant, true);
     }
    }
   }
  }
  else if (pageenclos)
  { futur = $c("futur");
   for (i=0;i<futur.length;i++)
   { maxi = parseInt(animauxmax[animaux_tries[i].replace("&nbsp;"," ","g")]);
    trop = enclos[animaux_tries[i]][4] > maxi || enclos[animaux_tries[i]][5] > maxi ? "futur trop":"futur";
    futur[i].className = trop;
   }
   actu = $c("actu trop");
   
   for (i=0;i<actu.length;i++) actu[0].className = actu[i].className.replace(" trop", "");
   actu = $c("actu");
   for (i=0;i<actu.length;i++)
   { lig = Math.floor(i/2);
    trop = enclos[animaux_tries[lig]][0] > 15 && enclos[animaux_tries[lig]][1] > 15 ? " trop":"";
    actu[i].className = actu[i].className + trop;
   }
  }
  if (GM_getValue("affichertabanimaux", true)) $("tabanimaux").style.display = "";
  else $("tabanimaux").style.display = "none";
  bdiv.style.width = "";
  if (bdiv2) bdiv2.style.right = bdiv.clientWidth + 10 + "px";
  if (pageenclos)
  { if (GM_getValue("clique", "") != "") typesel(GM_getValue("colonne", "tout"), true);
   else { GM_deleteValue("colonne"); typesel("tout", true); }
  }
  else
  { var csel = $c("sel");
   csel[0].setAttribute("class", "nsel2");
   var cnsel = $c("nsel");
   cnsel[0].setAttribute("class", "nsel2");
   cnsel[0].setAttribute("class", "nsel2");
   var ctitre = $c("titre");
   var nbtitre = ctitre.length;
   for (i11=0;i11<nbtitre;i11++) ctitre[0].setAttribute("class", "titre3");
   if (/vente_animaux.php/.test(window.location) || /achat_animauxconfirm.php/.test(window.location))
   { var espece = /vente_animaux.php/.test(window.location) ? GM_getValue("temp_vente") : GM_getValue("temp_achat", "");
    var espece1 = espece.replace(" ", " <br>", "g");
    var espece2 = espece.replace(" ", "&nbsp;", "g");
    var titre = $c("titre3");
    for (var i=0;i<titre.length;i++)
    { if (titre[i].innerHTML == espece1 || titre[i].innerHTML == espece2) titre[i].setAttribute("class", "titre2");
    }
   }
  }
 }
}

function souligneclick(e) // on a cliqué sur une espèce dans le tableau
{
 var txt = e.target.textContent, txt2 = "";
 for (i=0;i<txt.length;i++)
  if (txt.charCodeAt(i) == 160) txt2 += " ";
  else txt2 += txt.substring(i,i+1);
 GM_setValue("clique",txt2);
 souligne(txt2,false);
}

function typeselclick(e) // on a cliqué sur une colonne dans le tableau
{
 var clcol;
 if (e.target.textContent) clcol = "tout";
 else if (e.target.getAttribute("src").indexOf("female") != -1) clcol = "femelle";
 else clcol = "mâle";
 typesel(clcol, false);
}

function souligne(espece,temoin) // sélectionne/désélectionne une espèce (femelle, mâle ou les 2)
{
 var espece1 = espece.replace(" ", " <br>", "g");
 var espece2 = espece.replace(" ", "&nbsp;", "g");
 espece = espece.replace(" ", "%20", "g");
 var titre2 = $c("titre2");
 var deja = false; // si true, on a cliqué sur le même animal : on efface tout
 var colonne = GM_getValue("colonne", "tout");
 if (titre2.length != 0)
 { if ((titre2[0].innerHTML == espece1 || titre2[0].innerHTML == espece2) && !temoin) deja = true;
  titre2[0].className = titre2[0].className.replace("titre2", "titre");
 }
 if (!deja)
 { var titre = $c("titre");
  for (var i=0;i<titre.length;i++)
  { if (titre[i].innerHTML == espece1 || titre[i].innerHTML == espece2)
   { titre[i].className = titre[i].className.replace("titre", "titre2");
    break;
   }
  }
 }
 var td = $c("animal");
 for (i=0;i<td.length;i++)
  td[i].style.display = "block";
 var td = $c("filtre_mâle");
 if (td.length != 0)
 { lgtd = td.length;
  for (i=0;i<lgtd;i++)
   td[0].className = td[0].className.replace(" filtre_mâle", "", "g");
 }
 td = $c("filtre_femelle");
 if (td.length != 0)
 { lgtd = td.length;
  for (i=0;i<lgtd;i++)
   td[0].className = td[0].className.replace(" filtre_femelle", "", "g");
 }
 td = $c("filtre");
 if (td.length != 0)
 { lgtd = td.length;
  for (i=0;i<lgtd;i++)
   td[0].className = td[0].className.replace(" filtre", "", "g");
 }
 titre2 = $c("titre2");
 if (titre2.length != 0)
 { if (colonne == "tout") td = $c("animal " + espece);
  else td = $c("animal " + espece + " " + colonne);
  for (i=0;i<td.length;i++)
   if (td[i].className.indexOf("mâle") != -1) td[i].className = td[i].className + " filtre_mâle filtre";
   else td[i].className = td[i].className + " filtre_femelle filtre";
  if (GM_getValue("filtre", false))
  { td = $c("naissance");
   for (i=0;i<td.length;i++)
    td[i].className = td[i].className + " filtre";
   td = $c("mourant");
   for (i=0;i<td.length;i++)
    td[i].className = td[i].className + " filtre";
  }
  if (colonne != "tout")
  { td = $c("animal " + espece + " separation");
   for (i=0;i<td.length;i++)
    td[i].className = td[i].className + " filtre";
  }
  if (GM_getValue("filtre", false))
  { td = $c("animal");
   for (i=0;i<td.length;i++)
    td[i].style.display = "none";
   td = $c("filtre");
   for (i=0;i<td.length;i++)
    td[i].style.display = "block";
   td = $c("filtre_mâle");
   for (i=0;i<td.length;i++)
    td[i].style.display = "block";
   td = $c("filtre_femelle");
   for (i=0;i<td.length;i++)
    td[i].style.display = "block";
   td = $c("filtre");
   if (td[td.length-1].className.indexOf("separation") != -1) td[td.length-1].style.display = "none";
  }
 }
 else { GM_deleteValue("clique"); GM_deleteValue("colonne"); }
 if (GM_getValue("bebes", "") != "") // on a demandé l'ouverture de la page sur les plus jeunes
 { var bstrong = $t("strong");
  window.scroll(0, position(bstrong[bstrong.length - 17])["y"] - window.innerHeight);
  GM_deleteValue("bebes");
 }
 if (titre2.length == 0) typesel("tout", true);
 lien_enclos(true);
}

function typesel(col, temoin) // souligne la colonne 'col'
{
 var colonne = GM_getValue("colonne", "tout");
 var sel, nsel;
 if (col == "tout" && (colonne != "tout" || temoin))
 { sel = $c("sel");
  sel[0].setAttribute("class", "nsel");
  nsel = $c("nsel");
  nsel[0].setAttribute("class", "sel");
  GM_deleteValue("colonne");
 }
 else if (col == "femelle" && (colonne != "femelle" || temoin))
 { sel = $c("sel");
  sel[0].setAttribute("class", "nsel");
  nsel = $c("nsel");
  nsel[2].setAttribute("class", "sel");
  GM_setValue("colonne","femelle");
 }
 else if (col == "mâle" && (colonne != "mâle" || temoin))
 { sel = $c("sel");
  sel[0].setAttribute("class", "nsel");
  nsel = $c("nsel");
  nsel[1].setAttribute("class", "sel");
  GM_setValue("colonne","mâle");
 }
 if (GM_getValue("clique", "") != "") souligne(GM_getValue("clique"),true);
 lien_enclos(true);
}

function lien_enclos(surlignage) // affiche les tableaux de tous les enclos, des liens directs vers diverses pages et du déplacement haut/bas sur chaque page
{
 var t, nom =  "", separe;
 var div, exist, div2, div3;
 exist = $("lien_enclos");
 if (exist) old = exist.parentNode.removeChild(exist);
 var touslesenclos = unserialize(GM_getValue("touslesenclos_" + id_zoo, ""));
 var tab_naissances = unserialize(GM_getValue("string_naissances_" + id_zoo, ""));
 var mourants = unserialize(GM_getValue("mourants_" + id_zoo, ""));
 var couples15 = unserialize(GM_getValue("couples15_" + id_zoo, ""));
 var liste_enclos, v, v2, vmax, alterne = false, etroit2 = GM_getValue("etroit2", false);
 var tabespece = new Array();

 liste_enclos = '<table width="100%"><tr style="text-align:center;margin:2px;"><td><input type="checkbox" name="etroit2" id="etroit2"';
 if (etroit2) liste_enclos += 'checked="checked"';
 liste_enclos += '><label for="etroit2">Tableau étroit</label></input></td></tr></table>';
 liste_enclos += "<table id=\"liste_enclos\">"

 var totalesp = 0, numenclos, i12, enclos;
 for (espece in ANIMAUX)
 { totalesp++;
  tabespece[espece] = 0;
 }
 var enclosavoir = unserialize(GM_getValue("enclosavoir_" + id_zoo, ""));
 for (enclos in enclosavoir) break;
 if (enclos)
  var bulleavoir = unserialize(GM_getValue("bulleavoir_" + id_zoo, ""));
 var avoir, bulle;

 for (t = 0;t<2;t++)
 { if (t==0) vmax = 41;
  else vmax=5;
  for (v=0; v<vmax; v++)
  { if (v==0 || v==10 || v==20 || v==30) separe = " class=\"separe\"";
   else separe = "";
   avoir = "";
   bulle1 = touslesenclos[t*100+v];
   bulle2 = "";
   for (numenclos in enclosavoir)
   { if (enclosavoir[numenclos] == t*100+v)
    { avoir = " avoir";
     if (enclos)
     { bulle2 = new String(bulleavoir[enclosavoir[numenclos]]);
      bulle2 = bulle2.replace(" : ", "&nbsp;:&nbsp;", "g");
      bulle2 = "<br /><br />" + bulle2;
     }
    }
   }
   if (alterne) 
   { if (etroit2) liste_enclos += "<tr" + separe + ">";
    liste_enclos += "<td class=\"lenclos" + avoir + "\"><a href=\"" + urlSite + "enclosgestion1.php?t=" + t + "&v=" + v + "\" class=\"un\" " +
     onmouse(bulle1+bulle2, true) + ">" + nom_enclos(t,v) + "</a> / <a name=\"bebes\" href=\"" + urlSite + "enclosgestion1.php?t=" + t +
     "&v=" + v + "\" class=\"un\" " + onmouse(bulle1+bulle2, true) + ">BB</a></td></tr>";
   }
   else 
   { liste_enclos += "<tr" + separe + "><td class=\"lenclos" + avoir + "\"><a href=\"" + urlSite + "enclosgestion1.php?t=" + t + "&v=" + v + "\" class=\"un\" " +
     onmouse(bulle1+bulle2, true) + ">" + nom_enclos(t,v) + "</a> / <a name=\"bebes\" href=\"" + urlSite + "enclosgestion1.php?t=" + t + "&v=" + v +
     "\" class=\"un\" " + onmouse(bulle1+bulle2, true) + ">BB</a></td>";
    if (etroit2) liste_enclos += "</tr>";
   }
   liste = touslesenclos[t*100+v];
   if (liste == "Vide" || liste == "Enclos non construit") liste = "";
   else liste = liste.substring(liste.indexOf(":")+2);
   while (liste != "")
   { if (liste.indexOf(" /") != -1) { espece = liste.substring(0,liste.indexOf(" /")); liste = liste.substring(liste.indexOf(" /")+3); }
    else { espece = liste; liste = ""; }
    tabespece[espece] = 1;
   }
   alterne = !alterne;
   if (v==15) v=19;
   if (v==9 || v==19 || v==29 || v==40)
   { for (j=0;j<5;j++)
    { v2 = Math.floor((v-9)/2)+41+j;
     avoir = "";
     bulle1 = touslesenclos[t*100+v2];
     bulle2 = "";
     for (numenclos in enclosavoir)
     { if (enclosavoir[numenclos] == t*100+v2)
      { avoir = " avoir";
       if (enclos)
       { bulle2 = new String(bulleavoir[enclosavoir[numenclos]]);
        bulle2 = bulle2.replace(" : ", "&nbsp;:&nbsp;", "g");
        bulle2 = "<br /><br />" + bulle2;
       }
      }
     }
     if (alterne) 
     { if (etroit2) liste_enclos += "<tr" + separe + ">";
      liste_enclos += "<td class=\"lenclos" + avoir + "\"><a href=\"" + urlSite + "enclosgestion1.php?t=" + t + "&v=" + v2 + "\" class=\"un\" " +
       onmouse(bulle1+bulle2, true) + ">" + nom_enclos(t,v2) + "</a> / <a name=\"bebes\" href=\"" + urlSite + "enclosgestion1.php?t=" + t +
       "&v=" + v2 + "\" class=\"un\" " + onmouse(bulle1+bulle2, true) + ">BB</a></td></tr>";
     }
     else 
     { liste_enclos += "<tr" + separe + "><td class=\"lenclos" + avoir + "\"><a href=\"" + urlSite + "enclosgestion1.php?t=" + t + "&v=" + v2 + "\" class=\"un\" " +
       onmouse(bulle1+bulle2, true) + ">" + nom_enclos(t,v2) + "</a> / <a name=\"bebes\" href=\"" + urlSite + "enclosgestion1.php?t=" + t + "&v=" + v2 +
       "\" class=\"un\" " + onmouse(bulle1+bulle2, true) + ">BB</a></td>";
      if (etroit2) liste_enclos += "</tr>";
     }
     liste = touslesenclos[t*100+v2];
     if (liste == "Vide" || liste == "Enclos non construit") liste = "";
     else liste = liste.substring(liste.indexOf(":")+2);
     while (liste != "")
     { if (liste.indexOf(" /") != -1) { espece = liste.substring(0,liste.indexOf(" /")); liste = liste.substring(liste.indexOf(" /")+3); }
      else { espece = liste; liste = ""; }
      tabespece[espece] = 1;
     }
     alterne = !alterne;
    }
    if (!etroit2 && v != 40) liste_enclos += "<td></td></tr>";
    alterne = false;
   }
  }
  if (t==1)
  { if (!etroit2) liste_enclos += "<td></td></tr>";
   dispo = 0;
   dispo2 = new Array();
   manque2 = new Array();
   for (espece in tabespece) if (tabespece[espece] == 1) { dispo++; dispo2.push(espece);} else manque2.push(espece);
   manque = totalesp - dispo;
   dispo2.sort();
   manque2.sort();
   dispo3 = "";
   for (i=0;i<dispo2.length;i++) dispo3 += dispo2[i] + " / ";
   if (dispo3.length > 3) dispo3 = dispo3.substring(0, dispo3.length - 3);
   if (dispo == 0) dispo = "Vous n&rsquo;avez aucune espèce";
   else if (dispo > 1) dispo = "Vous avez " + dispo + " espèces :<br />" + dispo3;
   else dispo = "Vous avez " + dispo + " seule espèce :\n" + dispo3;
   manque3 = "";
   for (i=0;i<manque2.length;i++) manque3 += manque2[i] + " / ";
   if (manque3.length > 3) manque3 = manque3.substring(0, manque3.length - 3);
   if (manque == 0) manque = "Il ne vous manque aucune espèce";
   else if (manque > 1) manque = "Il vous manque " + manque + " espèces :<br />" + manque3;
   else manque = "Il vous manque " + manque + " seule espèce :\n" + manque3;
   liste_enclos += "<tr class=\"separe\"><td class=\"manque\" " + onmouse(dispo) + ">Espèces<br />présentes</td>";
   if (etroit2) liste_enclos += "</tr><tr>";
   liste_enclos += "<td class=\"manque\" " + onmouse(manque) + ">Espèces<br />manquantes</td></tr>";
  }
 }
 liste_enclos += "</table>";
 div = document.createElement("div");
 div.id = "lien_enclos";
 div.setAttribute("class", "info_bulle");
 div.style.top = "0px";
 div.style.left = "0px";
 div.innerHTML = liste_enclos;
 document.body.appendChild(div);
 if ((/enclosgestion1.php/.test(window.location) || /achat_animaux.php/.test(window.location) || /vente_animaux.php/.test(window.location) ||
  /achat_animauxconfirm.php/.test(window.location) || /bureau.php/.test(window.location) || /enclosconfirm.php/.test(window.location)) && surlignage)
 { if (/bureau.php/.test(window.location) && GM_getValue("nom_enclos", "") != "")
   nom = GM_getValue("nom_enclos");
  else if (!/achat_animauxconfirm.php/.test(window.location) && !/enclosconfirm.php/.test(window.location))
   nom = nom_enclos(parseInt(recherche_param(window.location.href, "t")), parseInt(recherche_param(window.location.href, "v")));
  else if (GM_getValue("nom_enclos", "") != "")
   nom = GM_getValue("nom_enclos");
  else
  { var binput = $t("input"); 
   if (binput[2])
   { if (/achat_animauxconfirm.php/.test(window.location)) nom = nom_enclos(parseInt(binput[0].value), parseInt(binput[2].value));
    else if (parseInt(binput[4].value) < 2) nom = nom_enclos(parseInt(binput[4].value), parseInt(binput[2].value));
   }
   else
   { ba = $t("a");
    for (i=25;i<35;i++)
     if (ba[i].innerHTML == "retour enclos") nom = nom_enclos(parseInt(recherche_param(ba[i].href, "t")), parseInt(recherche_param(ba[i].href, "v")));
   }
  }
  if (nom != "")
  { GM_setValue("nom_enclos", nom);
   lenclos = $c("lenclos");
   for (j=0;j<lenclos.length;j++)
   { if ($t("a", lenclos[j])[0].innerHTML == nom)
    { $t("a", lenclos[j])[0].className = "encours";
     $t("a", lenclos[j])[1].className = "encours";
     lenclos[j].className = "encours";
    }
   }
  }
 }
 else GM_deleteValue("nom_enclos");
 exist = $("lien_autres");
 if (!exist)
 { div2 = document.createElement("div");
  div2.id = "lien_autres";
  div2.setAttribute("class", "info_bulle");
  txt = '<table width="100%"><tr><td style="text-align:center;margin:2px;"><input type="checkbox" name="afficheautres" id="afficheautres"';
  if (GM_getValue("afficheautres", true)) txt += 'checked="checked"';
  txt += '><label for="afficheautres">Afficher les liens</label></input></td></tr></table>';
  txt += "<table id=\"autres\"><tr class=\"separe\"><td><a href=\"" + urlSite + "zonemembre.php\">Carte du zoo</a></td></tr>" +
   "<tr><td><a href=\"" + urlSite + "toutou.php\">Votre chien</a></td></tr><tr><td><a href=\"" + urlSite + "enclosgestion.php?t=5&v=0\">Musée</a></td></tr>" +
   "<tr><td><a href=\"" + urlSite + "botanica.php\">La Botanica</a></td></tr><tr><td><a href=\"" + urlSite + "parrainage.php\">Parrainage</a></td></tr>" +
   "<tr><td><a href=\"" + urlSite + "news.php\">News</a></td></tr><tr class=\"separe\"><td><a href=\"" + urlSite + "bureau.php\">Personnel</a></td></tr>" +
   "<tr><td><a href=\"" + urlSite + "bureau2.php\">Recettes</a></td></tr><tr><td><a href=\"" + urlSite + "bureau4.php\">Stock</a></td></tr>" + 
   "<tr><td><a href=\"" + urlSite + "espion.php\">Espions</a></td></tr><tr><td><a href=\"" + urlSite + "explorateur.php\">Explorateur</a></td></tr>" +
   "<tr><td><a class=\"rapport\" id=\"rapportsc\">Rapport</a></td></tr><tr><td><a name=\"suivi\" class=\"rapport\" id=\"suivisc\">Suivi</a></td></tr>" +
   "<tr class=\"separe\"><td><a href=\"" + urlSite + "enclosgestion.php?t=4&v=0\">Souvenirs</a></td></tr>" +
   "<tr><td><a href=\"" + urlSite + "enclosgestion.php?t=4&v=1\">Snack</a></td></tr><tr><td><a href=\"" + urlSite + "enclosgestion.php?t=4&v=2\">Boissons</a></td></tr>" +
   "<tr><td><a href=\"" + urlSite + "enclosgestion.php?t=4&v=3\">Glaces</a></td></tr><tr class=\"separe\"><td><a class=\"rapport\" href=\"" + urlSite + "animaux.php\">Intendance</a></td></tr>" +
   "<tr><td><a class=\"rapport\" href=\"" + urlSite + "bourse.php\">La bourse</a></td></tr><tr><td><a href=\"" + urlSite + "missions.php\">Vos missions</a></td></tr>" +
   "<tr><td><a class=\"rapport\" href=\"" + urlSite + "event.php\">Vos messages</a></td></tr><tr><td><a href=\"" + urlSite + "team.php\">Les teams</a></td></tr>" +
   "<tr><td><a href=\"" + urlSite + "index.php?deco\">Déconnexion</a></td></tr><tr class=\"separe\"><td><a id=\"mespoints\">Mon class. points</a></td></tr>" +
   "<tr><td><a id=\"prestige\">Mon class. prestige</a></td></tr>";
  if (GM_getValue("team_"+id_zoo, false)) txt += "<tr><td><a id=\"mateam\">Notre class. team</a></td></tr>";
  if (num_zoo != "NC") txt += "<tr class=\"separe\"><td><a class=\"rapport\" href=\"" + urlSite + "voirzoo.php?idparc=" + num_zoo + "\">Listes du zoo</a></td></tr>";
  txt += "</table>";
  div2.innerHTML = txt;
  document.body.appendChild(div2);
  var ba = $("mespoints");
  ba.addEventListener("click", classement, true);
  ba = $("prestige");
  ba.addEventListener("click", classement, true);
  if (GM_getValue("team_"+id_zoo, false))
  { ba = $("mateam");
   ba.addEventListener("click", team, true);
  }
  ba = $("rapportsc");
  ba.addEventListener("click", rapport, true);
  ba = $("suivisc");
  ba.addEventListener("click", suivi, true);
 }
 else div2 = exist;
 div2.style.height = "";
 div2.style.width = "";
 div.style.height = "";
 div.style.width = "";
 if (GM_getValue("afficheautres", true))
 { $("autres").style.display = "";
  div2.style.top = "0px";
  if (div2.clientHeight > window.innerHeight)
  { div2.style.height = window.innerHeight - 15 + "px";
   div2.style.width = div2.clientWidth + 26 + "px";
  }
  if (div.clientHeight > window.innerHeight)
  { div.style.height = window.innerHeight - 15 + "px";
   div.style.width = div.clientWidth + 26 + "px";
   div2.style.left = div.clientWidth + 28 + "px";
  }
  else div2.style.left = div.clientWidth + 10 + "px";
 }
 else
 { $("autres").style.display = "none";
  div2.style.left = "0px";
  if (div.clientHeight + div2.clientHeight + 10 > window.innerHeight)
  { div.style.height = window.innerHeight - div2.clientHeight - 25 + "px";
   div.style.width = div.clientWidth + 26 + "px";
  }
  div2.style.top = div.clientHeight + 10 + "px";
 }
 exist = $("lien_deplacement");
 if (exist) old = exist.parentNode.removeChild(exist);
 div3 = document.createElement("div");
 div3.id = "lien_deplacement";
 div3.setAttribute("class", "info_bulle");
 div3.style.right = "0px";
 div3.style.top = "0px";
 div2=$("animaux_enclos");
 if (div2 && /enclosgestion1.php/.test(window.location))
 { bstrong = $t("strong");
  deplaceHaut = position(bstrong[4])["y"];
  deplaceBB = position(bstrong[bstrong.length - 17])["y"] - window.innerHeight;
  div3.innerHTML = "<table id=\"deplacement\"><tr><td><a href=\"javascript:window.scroll(0,0)\">Haut de page</a></td></tr>" +
   "<tr><td><a href=\"javascript:window.scroll(0," + deplaceHaut + ")\">Haut animaux</a></td></tr>" +
   "<tr><td><a href=\"javascript:window.scroll(0," + deplaceBB + ")\">Bébés</a></td></tr>" +
   "<tr><td><a href=\"javascript:window.scroll(0,document.body.clientHeight)\">Bas de page</a></td></tr></table>";
 }
 else div3.innerHTML = "<table id=\"deplacement\"><tr><td><a href=\"javascript:window.scroll(0,0)\">Haut de page</a></td></tr>" +
  "<tr><td><a href=\"javascript:window.scroll(0,document.body.clientHeight)\">Bas de page</a></td></tr></table>";
 document.body.appendChild(div3);
 div3.style.height = "";
 div3.style.width = "";
 if (div2)
 { div2.style.height = "";
  div2.style.width = "";
  if (div2.clientHeight + 15 + div3.clientHeight > window.innerHeight)
  { div2.style.height = window.innerHeight - div3.clientHeight - 25 + "px";
   div2.style.width = div2.clientWidth + 22 + "px";
   var titre2 = $c("titre2");
   if (titre2.length != 0)
    titre2[0].scrollIntoView(false);
   if ($("enclosavoir")) $("enclosavoir").style.right = div2.clientWidth + 27 + "px";
  }
  else if ($("enclosavoir")) $("enclosavoir").style.right = div2.clientWidth + 10 + "px";
  div3.style.top = div2.clientHeight + 10 + "px";
 }
 else
 { div2=$("enclos_naissances");
  if (div2)
  { div2.style.height = "";
   div2.style.width = "";
   if (div2.clientHeight + 15 + div3.clientHeight > window.innerHeight)
   { div2.style.height = window.innerHeight - div3.clientHeight - 25 + "px";
    div2.style.width = div2.clientWidth + 26 + "px";
   }
   div3.style.top = div2.clientHeight + 10 + "px";
  }
  else
  { div2=$("tableau_vieux");
   if (div2)
   { div2.style.height = "";
    div2.style.width = "";
    div4=$("tableau_animaux");
    div4.style.height = "";
    div4.style.width = "";
    if (GM_getValue("affichertabanim", true))
    { if (div4.clientHeight + 15 + div3.clientHeight > window.innerHeight)
     { div4.style.height = window.innerHeight - div3.clientHeight - 25 + "px";
      div4.style.width = div4.clientWidth + 26 + "px";
      div2.style.right = div4.clientWidth + 28 + "px";
     }
     else div2.style.right = div4.clientWidth + 10 + "px";
    }
    else div2.style.right = div4.clientWidth + 10 + "px";
    if (GM_getValue("affichertabvieux", true))
    { if (div2.clientHeight + 15 + div3.clientHeight > window.innerHeight)
     { div2.style.height = window.innerHeight - div3.clientHeight - 25 + "px";
      div2.style.width = div2.clientWidth + 26 + "px";
     }
    }
    div3.style.top = div4.clientHeight + 10 + "px";
   }
  }
 }
}

function afficheautres(coche)
{
 GM_setValue("afficheautres", coche);
 if (GM_getValue("rapport", "") != "") lien_enclos(false);
 else lien_enclos(true);
}

function afficheenclosnaissance()
{
 GM_setValue("afficheenclosnaissance", !GM_getValue("afficheenclosnaissance", true));
 enclos_naissances();
}

function trienclosavoir()
{
 var index, index2, index3;
 var tab_naissances = unserialize(GM_getValue("string_naissances_" + id_zoo, ""));
 var mourants = unserialize(GM_getValue("mourants_" + id_zoo, ""));
 var couples15 = unserialize(GM_getValue("couples15_" + id_zoo, ""));
 var tabtrie = new Array(), numero;
 var naissmourant = false;
 for (index in tab_naissances) break;
 if (index)
 { naissmourant = true;
  for (index in tab_naissances)
  { index = parseInt(index);
   if (index < 10) numero = index+1;
   else if (index < 16) numero = index+10;
   else if (index < 30) numero = index+20;
   else if (index < 41) numero = index+30;
   else if (index < 46) numero = index-30;
   else if (index < 51) numero = index-20;
   else if (index < 56) numero = index-1;
   else if (index < 61) numero = index+15;
   else numero = index;
   tabtrie[numero] = index;
  }
 }
 for (index2 in mourants) break;
 if (index2)
 { naissmourant = true;
  for (index2 in mourants)
  { index2 = parseInt(index2);
   if (index2 < 10) numero = index2+1;
   else if (index2 < 16) numero = index2+10;
   else if (index2 < 30) numero = index2+20;
   else if (index2 < 41) numero = index2+30;
   else if (index2 < 46) numero = index2-30;
   else if (index2 < 51) numero = index2-20;
   else if (index2 < 56) numero = index2-1;
   else if (index2 < 61) numero = index2+15;
   else numero = index2;
   tabtrie[numero] = index2;
  }
 }
 GM_setValue("enclosavoir_" + id_zoo, serialize(tabtrie));
 for (enclos in tabtrie) break;
 if (enclos)
 { newtab_naissances = new Array();
  newmourants = new Array();
  newcouples15 = new Array();
  for (index in tabtrie)
  { if (tab_naissances[tabtrie[index]])
   { animtrie = new Array(); nbanim = new Array();
    for (i12=0; i12<tab_naissances[tabtrie[index]].length;i12+=2)
    { animtrie.push(tab_naissances[tabtrie[index]][i12]);
     nbanim[tab_naissances[tabtrie[index]][i12]] = tab_naissances[tabtrie[index]][i12+1];
    }
    animtrie.sort();
    newtab_naissances[tabtrie[index]] = new Array();
    for (j=0;j<animtrie.length;j++)
    { newtab_naissances[tabtrie[index]][2*j] = animtrie[j];
     newtab_naissances[tabtrie[index]][2*j+1] = nbanim[animtrie[j]];
    }
   }
   if (mourants[tabtrie[index]])
   { animtrie = new Array(); nbanim = new Array();
    for (i12=0; i12<mourants[tabtrie[index]].length;i12+=2)
    { animtrie.push(mourants[tabtrie[index]][i12]);
     nbanim[mourants[tabtrie[index]][i12]] = mourants[tabtrie[index]][i12+1];
    }
    animtrie.sort();
    newmourants[tabtrie[index]] = new Array();
    for (j=0;j<animtrie.length;j++)
    { newmourants[tabtrie[index]][2*j] = animtrie[j];
     newmourants[tabtrie[index]][2*j+1] = nbanim[animtrie[j]];
    }
   }
  }
  GM_setValue("string_naissances_" + id_zoo, serialize(newtab_naissances));
  GM_setValue("mourants_", serialize(newmourants));
  //GM_setValue("mourants_" + id_zoo, serialize(newmourants));
  GM_setValue("couples15_" + id_zoo, serialize(newcouples15));
  bulle = new Array();
  for (index in tabtrie)
  { bulle[tabtrie[index]] = "";
   if (tab_naissances[tabtrie[index]])
   { bulle[tabtrie[index]] += "Naissance(s) :<br />";
    for (i12=0; i12<tab_naissances[tabtrie[index]].length;i12+=2)
     bulle[tabtrie[index]] += tab_naissances[tabtrie[index]][i12] + " : " + tab_naissances[tabtrie[index]][i12+1] + ", ";
    bulle[tabtrie[index]] = bulle[tabtrie[index]].substring(0, bulle[tabtrie[index]].length -2);
   }
   if (mourants[tabtrie[index]])
   { animtrie = new Array(); nbanim = new Array();
    for (i12=0; i12<mourants[tabtrie[index]].length;i12+=2)
    { animtrie.push(mourants[tabtrie[index]][i12]);
     nbanim[mourants[tabtrie[index]][i12]] = mourants[tabtrie[index]][i12+1];
    }
    animtrie.sort();
    if (bulle[tabtrie[index]] != "") bulle[tabtrie[index]] += "<br /><br />";
    bulle[tabtrie[index]] += "Mourant(s) :<br />";
    for (j=0;j<animtrie.length;j++)
     bulle[tabtrie[index]] += animtrie[j] + " : " + nbanim[animtrie[j]] + ", ";
    bulle[tabtrie[index]] = bulle[tabtrie[index]].substring(0, bulle[tabtrie[index]].length -2);
   }
  }
  GM_setValue("bulleavoir_" + id_zoo, serialize(bulle));
 }
}

function enclos_naissances() // affiche le tableau des enclos avec naissances / mourants
{
 var liste_enclos = "", t, v, alterne = false, index, enclos, div, nbindex = 0;
 var trop = "<br />et mourant(s)";
 trienclosavoir();
 div = $("enclos_naissances");
 if (!div)
 { var enclosavoir = unserialize(GM_getValue("enclosavoir_" + id_zoo, ""));
  for (enclos in enclosavoir) break;
  if (enclos)
  { var bulleavoir = unserialize(GM_getValue("bulleavoir_" + id_zoo, ""));
   for (index in enclosavoir)
   { nbindex++;
    t = Math.floor(enclosavoir[index]/100);
    v = enclosavoir[index] - t*100;
    bulle = new String(bulleavoir[enclosavoir[index]]);
    bulle = bulle.replace(" : ", "&nbsp;:&nbsp;", "g");
    if (alterne) liste_enclos += "<td><a name=\"bebes\" href=\"enclosgestion1.php?t=" + t + "&v=" + v + "\" class=\"un\" " +
     onmouse(bulle, true) + ">" + nom_enclos(t,v) + "</a></td></tr>";
    else liste_enclos += "<tr><td><a name=\"bebes\" href=\"enclosgestion1.php?t=" + t + "&v=" + v + "\" class=\"un\" " +
     onmouse(bulle, true) + ">" + nom_enclos(t,v) + "</a></td>";
    alterne = !alterne;
   }
   if (alterne)
   { if (nbindex > 1) liste_enclos += "<td></td></tr>";
    else liste_enclos += "</tr>";
   }
  }
  else liste_enclos = "<tr><td>aucune naissance<br />aucun mourant</td></tr>";
  liste_enclos = "<div name=\'afficheenclosnaissance\' style=\'cursor:pointer;font-weight:bold;text-align:center\' onmouseout=\"UnTip()\" onmouseover=\"Tip('Cliquez ici pour réduire le tableau', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', LEFT, 'true', OFFSETX, 3, OFFSETY, -10, TEXTALIGN, 'center')\">Enclos avec naissance(s)" + trop + "</div><table id=\"table_enclos\">" + liste_enclos + "</table>";
  div = document.createElement("div");
  div.id = "enclos_naissances";
  div.setAttribute("class", "info_bulle");
  div.style.top = "0px";
  div.style.right = "0px";
  div.innerHTML = liste_enclos;
  document.body.appendChild(div);
 }
 if (GM_getValue("afficheenclosnaissance", true)) $("table_enclos").style.display = "";
 else $("table_enclos").style.display = "none";
 lien_enclos();
}

function tableau_vieux() // affiche le tableau des vieux
{
 var bdiv = $("tableau_vieux");
 if (!bdiv)
 { var synthvieux = unserialize(GM_getValue("synthvieux_" + id_zoo, ""));
  var albinos = unserialize(GM_getValue("albinos_" + id_zoo, ""));
  var i12, numenclos, numero, insuffisant, vieux = false, tabtrie = new Array();
  for (numenclos in synthvieux) break;
  if (numenclos)
  { vieux = true;
   for (numenclos in synthvieux)
   { numenclos = parseInt(numenclos);
    if (numenclos < 10) numero = numenclos+1;
    else if (numenclos < 16) numero = numenclos+10;
    else if (numenclos < 30) numero = numenclos+20;
    else if (numenclos < 41) numero = numenclos+30;
    else if (numenclos < 46) numero = numenclos-30;
    else if (numenclos < 51) numero = numenclos-20;
    else if (numenclos < 56) numero = numenclos-1;
    else if (numenclos < 61) numero = numenclos+15;
    else numero = numenclos;
    tabtrie[numero] = numenclos;
   }
  }
  var liste_enclos;
  liste_enclos = "<div name=\'affichertabvieux\' style=\'cursor:pointer;font-weight:bold;font-size:15px;text-align:center\' onmouseout=\"UnTip()\" " +
   "onmouseover=\"Tip('Cliquez ici pour afficher ou masquer la liste', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', LEFT, 'true', OFFSETX, 3, " +
   "OFFSETY, -10, TEXTALIGN, 'center')\">Liste des vieux</div>";
  liste_enclos += '<div id="tabvieux" style="width:100%;text-align:center;margin:2px"><table><tr><td></td></tr></table>';
  if (vieux)
  { liste_enclos += '<input type="checkbox" name="etroit3" id="etroit3"';
   if (GM_getValue("etroit3", false)) liste_enclos += 'checked="checked"';
   liste_enclos += '><label for="etroit3">Tableau étroit</label></input>';
   liste_enclos += '<input type="checkbox" name="filtre2" id="filtre2"';
   if (GM_getValue("filtre2", false)) liste_enclos += 'checked="checked"';
   liste_enclos += '><label for="filtre2">Filtre</label></input>';
   liste_enclos += "<table id=\"liste_vieux\"><tr><th>Enclos</th>" +
    "<th onmouseout=\"UnTip()\" onmouseover=\"Tip('Espèces avec des vieux', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">Animal</th><th " +
    "style=\"display:none\">Bad</th><th><img src=\"images/icones/male.gif\" onmouseout=\"UnTip()\" onmouseover=\"Tip('Nombre de " +
    "mâles-nombre de vieux mâles', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\"></th>" +
    "<th><img src=\"images/icones/female.gif\" onmouseout=\"UnTip()\" onmouseover=\"Tip('Nombre de femelles-nombre de vieilles femelles', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\"></th>";
   liste_enclos += "</tr>";
   for (numenclos in tabtrie)
   { animtrie = new Array(); nbanim = new Array();
    for (i12=0; i12<synthvieux[tabtrie[numenclos]].length;i12+=5)
    { animtrie.push(synthvieux[tabtrie[numenclos]][i12]);
     nbanim[synthvieux[tabtrie[numenclos]][i12]] = new Array();
     for (j=1;j<5;j++) nbanim[synthvieux[tabtrie[numenclos]][i12]][j] = parseInt(synthvieux[tabtrie[numenclos]][i12+j]);
    }
    animtrie.sort();
    t = Math.floor(tabtrie[numenclos]/100);
    v = tabtrie[numenclos] - t*100;
    couleur = nom_enclos(t, v);
    if (couleur.indexOf(" n") != -1) couleur = couleur.substring(0, couleur.indexOf(" n"));
    couleur = couleur.toLowerCase();
    un = couleur == "insectarium" ? "insectarium" : "un";
    insuffisant = new Array();
    for (i12=0;i12<animtrie.length;i12++)
    { insuffisant[i12] = "ok";
     if (nbanim[animtrie[i12]][1] >= parseInt(animauxmax[animtrie[i12]]) && nbanim[animtrie[i12]][2] >= parseInt(animauxmax[animtrie[i12]]) &&
      parseInt(animauxmax[animtrie[i12]]) > 1)
     { if (albinos[animtrie[i12]])
      { if (nbanim[animtrie[i12]][1]-nbanim[animtrie[i12]][3] < parseInt(animauxmax[animtrie[i12]])+parseInt(albinos[animtrie[i12]][2]) ||
        nbanim[animtrie[i12]][2]-nbanim[animtrie[i12]][4] < parseInt(animauxmax[animtrie[i12]])+parseInt(albinos[animtrie[i12]][3]))
         insuffisant[i12] = "insuffisant";
      }
      else if (nbanim[animtrie[i12]][1]-nbanim[animtrie[i12]][3] < parseInt(animauxmax[animtrie[i12]]) ||
       nbanim[animtrie[i12]][2]-nbanim[animtrie[i12]][4] < parseInt(animauxmax[animtrie[i12]]))
        insuffisant[i12] = "insuffisant";
     }
    }
    nextinsuffisant = 0;
    for (i12=0;i12<animtrie.length;i12++)
    { if (i12 == nextinsuffisant && insuffisant[i12] == "ok")
     { for (j=nextinsuffisant+1;j<animtrie.length;j++) if (insuffisant[j] != insuffisant[nextinsuffisant]) break;
      nbrow = j - nextinsuffisant;
      liste_enclos += "<tr class=\"" + couleur + "\"><td rowspan=\"" + nbrow + "\" class=\"enclos\"><a href=\"" + urlSite +
       "enclosgestion1.php?t=" + t + "&v=" + v + "\" class=\"" + un + "\">" + nom_enclos(t,v).replace(" ","&nbsp;") +
       "</a></td><td class=\"animvieux\">" + animtrie[i12].replace(" ","&nbsp;","g") + "</td><td style=\"display:none\"></td>" +
       "<td class=\"mâle " + insuffisant[nextinsuffisant] + "\">" + nbanim[animtrie[i12]][1] + "<span>-" + nbanim[animtrie[i12]][3] +
       "</span><td class=\"femelle " + insuffisant[nextinsuffisant] + "\">" + nbanim[animtrie[i12]][2] + "<span>-" +
       nbanim[animtrie[i12]][4] + "</span></td>";
      nextinsuffisant = j;
     }
     else if (i12 == nextinsuffisant && insuffisant[i12] == "insuffisant")
     { liste_enclos += "<tr class=\"" + couleur + "\"><td class=\"enclos\"><a href=\"" + urlSite +
       "enclosgestion1.php?t=" + t + "&v=" + v + "\" class=\"" + un + "\">" + nom_enclos(t,v).replace(" ","&nbsp;") +
       "</a></td><td class=\"animvieux\">" + animtrie[i12].replace(" ","&nbsp;","g") + "</td><td style=\"display:none\">*</td>" +
       "<td class=\"mâle " + insuffisant[nextinsuffisant] + "\">" + nbanim[animtrie[i12]][1] + "<span>-" + nbanim[animtrie[i12]][3] +
       "</span><td class=\"femelle " + insuffisant[nextinsuffisant] + "\">" + nbanim[animtrie[i12]][2] + "<span>-" +
       nbanim[animtrie[i12]][4] + "</span></td>";
      nextinsuffisant++;
     }
     else
     { liste_enclos += "<tr class=\"" + couleur + "\"><td class=\"animvieux\">" + animtrie[i12].replace(" ","&nbsp;","g") +
       "</td><td style=\"display:none\"></td><td class=\"mâle " + insuffisant[nextinsuffisant-1] + "\">" + nbanim[animtrie[i12]][1] +
       "<span>-" + nbanim[animtrie[i12]][3] + "</span><td class=\"femelle " + insuffisant[nextinsuffisant-1] + "\">" +
       nbanim[animtrie[i12]][2] + "<span>-" + nbanim[animtrie[i12]][4] + "</span></td>";
     }
     liste_enclos += "</tr>";
    }
   }
   liste_enclos += "</table></div>";
   if (GM_getValue("etroit3", false)) liste_enclos = liste_enclos.replace("&nbsp;", " <br>", "g");
   else liste_enclos = liste_enclos.replace(" <br>", "&nbsp;", "g");
  }
  else liste_enclos += "<div style=\"border:1px SOLID #000\">aucun vieux</div></div>";
  bdiv = document.createElement("div");
  bdiv.id = "tableau_vieux";
  bdiv.setAttribute("class", "info_bulle");
  bdiv.style.top = "0px";
  bdiv.style.right = "0px";
  bdiv.innerHTML = liste_enclos;
  document.body.appendChild(bdiv);
  if (GM_getValue("filtre2", false))
  { ok = $c("ok");
   if (ok) for (i12=0;i12<ok.length;i12++) ok[i12].parentNode.style.display = "none";
  }
 }
 var page = /bourse.php/.test(window.location) ? "b" : "i";
 var bdiv2 = $("tableau_animaux");
 if (!bdiv2)
 { var synthanimaux = unserialize(GM_getValue("synthanimaux_" + id_zoo, ""));
  var numenclos, animal = false;
  for (numenclos in synthanimaux) break;
  if (numenclos)
  { animal = true;
   var i12, numero, tabtrie = new Array(), liste = new Array();
   for (numenclos in synthanimaux)
   { numenclos = parseInt(numenclos);
    if (numenclos < 10) numero = numenclos+1;
    else if (numenclos < 16) numero = numenclos+10;
    else if (numenclos < 30) numero = numenclos+20;
    else if (numenclos < 41) numero = numenclos+30;
    else if (numenclos < 46) numero = numenclos-30;
    else if (numenclos < 51) numero = numenclos-20;
    else if (numenclos < 56) numero = numenclos-1;
    else if (numenclos < 61) numero = numenclos+15;
    else numero = numenclos;
    tabtrie[numero] = numenclos;
   }
  }
  var liste_enclos;
  liste_enclos = "<div name=\'affichertabanim\' style=\'cursor:pointer;font-weight:bold;font-size:15px;text-align:center\' onmouseout=\"UnTip()\" " +
   "onmouseover=\"Tip('Cliquez ici pour afficher ou masquer la liste', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', LEFT, 'true', OFFSETX, 3, " +
   "OFFSETY, -10, TEXTALIGN, 'center')\">Liste des animaux</div>";
  liste_enclos += '<div id="tabanim" style="width:100%;text-align:center;margin:2px"><table width="100%"><tr><td></td></tr>';
  if (animal)
  { if (/bourse.php/.test(window.location))
   { var prixbourse = new Array();
    prixbourse = unserialize(GM_getValue("prixbourse"));
   }
   liste_enclos += '<tr><td><input type="checkbox" name="etroit4" id="etroit4"';
   if (GM_getValue("etroit4", false)) liste_enclos += ' checked="checked"';
   liste_enclos += '><label for="etroit4">Tableau étroit</label></input></td></tr></table>';
   liste_enclos += '<table width="100%" style="border-top:1px solid #000;border-right:1px solid #000;border-left:1px solid #000"><tr style="font-weight:bold"><td><input type="radio" name="choixliste" id="choixliste1" value=1';
   if (GM_getValue("choixliste" + page, 1) == 1) liste_enclos += ' checked="checked"';
   liste_enclos += '><label for="choixliste1">Tri par enclos</label></input></td></tr>';
   liste_enclos += '<tr style="font-weight:bold"><td><input type="radio" name="choixliste" id="choixliste2" value=2';
   if (GM_getValue("choixliste" + page, 1) == 2) liste_enclos += ' checked="checked"';
   liste_enclos += '><label for="choixliste2">Tri par espèce</label></input></td></tr>';
   if (/bourse.php/.test(window.location))
   { liste_enclos += '<tr style="font-weight:bold"><td><input type="radio" name="choixliste" id="choixliste3" value=3';
    if (GM_getValue("choixliste" + page, 1) == 3) liste_enclos += ' checked="checked"';
    liste_enclos += '><label for="choixliste3">Tri par prix</label></input></td></tr>';
    liste_enclos += '<tr style="font-weight:bold"><td><input type="radio" name="choixliste" id="choixliste4" value=4';
    if (GM_getValue("choixliste" + page, 1) == 4) liste_enclos += ' checked="checked"';
    liste_enclos += '><label for="choixliste4">Tri par %</label></input></td></tr>';
   }
   liste_enclos += '</table>';
   liste_enclos += '<table width="100%" id="radioanim" style="font-size:9.3px;border-left:1px solid #000;border-right:1px solid #000;border-top:1px solid #000"><tr><td><input type="radio" name="choixaffanim" id="choixaffanim1" value=1';
   if (GM_getValue("choixaffanim", 1) == 1) liste_enclos += ' checked="checked"';
   liste_enclos += '><label for="choixaffanim1">Espèces présentes</label></input></td></tr>';
   liste_enclos += '<tr><td><input type="radio" name="choixaffanim" id="choixaffanim2" value=2';
   if (GM_getValue("choixaffanim", 1) == 2) liste_enclos += ' checked="checked"';
   liste_enclos += '><label for="choixaffanim2">Manquantes</label></input></td></tr>';
   liste_enclos += '<tr><td><input type="radio" name="choixaffanim" id="choixaffanim3" value=3';
   if (GM_getValue("choixaffanim", 1) == 3) liste_enclos += ' checked="checked"';
   liste_enclos += '><label for="choixaffanim3">Toutes</label></input></td></tr></table>';
   liste_enclos += "<table width=\"100%\" id=\"liste_anim1\"><tr><th>Enclos</th>" +
    "<th>Animal</th><th onmouseout=\"UnTip()\" onmouseover=\"Tip('Animaux vivant en groupe', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">Gr</th>" +
    "<th onmouseout=\"UnTip()\" onmouseover=\"Tip('Animaux nécessitant des stocks', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', " +
    "FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">St</th>" +
    "<th><img src=\"images/icones/male.gif\" onmouseout=\"UnTip()\" onmouseover=\"Tip('Nombre de mâles', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\"></th>" +
    "<th><img src=\"images/icones/female.gif\" onmouseout=\"UnTip()\" onmouseover=\"Tip('Nombre de femelles', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\"></th>";
   if (/bourse.php/.test(window.location)) liste_enclos += "<th onmouseout=\"UnTip()\" onmouseover=\"Tip('Prix bourse', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">Prix</th><th " +
    "onmouseout=\"UnTip()\" onmouseover=\"Tip('% par rapport au prix de base', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">%</th>";
   liste_enclos += "</tr>";
   for (numenclos in tabtrie)
   { animtrie = new Array(); nbanim = new Array();
    for (i12=0; i12<synthanimaux[tabtrie[numenclos]].length;i12+=3)
    { espece = synthanimaux[tabtrie[numenclos]][i12];
     animtrie.push(espece);
     nbanim[espece] = new Array();
     for (j=1;j<3;j++) nbanim[espece][j] = parseInt(synthanimaux[tabtrie[numenclos]][i12+j]);
     if (!liste[espece])
      liste[espece] = new Array();
     liste[espece][liste[espece].length] = tabtrie[numenclos];
     liste[espece][liste[espece].length] = parseInt(synthanimaux[tabtrie[numenclos]][i12+1]);
     liste[espece][liste[espece].length] = parseInt(synthanimaux[tabtrie[numenclos]][i12+2]);
    }
    animtrie.sort();
    t = Math.floor(tabtrie[numenclos]/100);
    v = tabtrie[numenclos] - t*100;
    couleur = nom_enclos(t, v);
    if (couleur.indexOf(" n") != -1) couleur = couleur.substring(0, couleur.indexOf(" n"));
    couleur = couleur.toLowerCase();
    un = couleur == "insectarium" ? "insectarium" : "un";
    for (i12=0;i12<animtrie.length;i12++)
    { if (i12 == 0)
      liste_enclos += "<tr class=\"" + couleur + "\"><td rowspan=\"" + animtrie.length + "\" class=\"enclos2\"><a href=\"" + urlSite + "enclosgestion1.php?t=" + t + "&v=" +
       v + "\"  class=\"" + un + "\">" + nom_enclos(t,v).replace(" ","&nbsp;") + "</a></td>";
     else liste_enclos += "<tr class=\"" + couleur + "\">";
     gr = ANIMAUX[animtrie[i12]].agroupe ? "N" : "O";
     st = ANIMAUX[animtrie[i12]].stock ? "O" : "N";
     liste_enclos += "<td class=\"espece\">" + animtrie[i12].replace(" ","&nbsp;","g") + "</td><td>" + gr + "</td><td>" + st + "</td><td class=\"mâle\">" + nbanim[animtrie[i12]][1] +
      "<td class=\"femelle\">" + nbanim[animtrie[i12]][2] + "</td>";
     if (/bourse.php/.test(window.location))
     { prixB = prixbourse[animtrie[i12]];
      pourcent = Math.round((parseInt(prixB)/ANIMAUX[animtrie[i12]].prix - 1) * 10000) / 100;
      if (pourcent >= 0) plus = "+";
      else { plus = "-"; pourcent = 0 - pourcent ; }
      liste_enclos += "<td>" + millier(prixB) + "</td>";
      liste_enclos += "<td>" + plus + "&nbsp;" + pourcent + "</td>";
     }
     liste_enclos += "</tr>";
    }
   }
   liste_enclos += "</table>";
   for (espece in ANIMAUX)
   { if (!liste[espece])
    { liste[espece] = new Array();
     liste[espece][0] = "aucun";
     liste[espece][1] = 0;
     liste[espece][2] = 0;
    }
   }
   liste_enclos += "<table width=\"100%\" id=\"liste_anim2\">";
   var entete = "<tr><th>Animal</th><th>Enclos</th><th onmouseout=\"UnTip()\" onmouseover=\"Tip('Animaux vivant en groupe', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">Gr</th>" +
    "<th onmouseout=\"UnTip()\" onmouseover=\"Tip('Animaux nécessitant des stocks', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', " +
    "FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">St</th><th><img src=\"images/icones/male.gif\" " +
    "onmouseout=\"UnTip()\" onmouseover=\"Tip('Nombre de mâles', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', " +
    "ABOVE, 'true', TEXTALIGN, 'center')\"></th><th><img src=\"images/icones/female.gif\" onmouseout=\"UnTip()\" " +
    "onmouseover=\"Tip('Nombre de femelles', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\"></th>";
   if (/bourse.php/.test(window.location)) entete += "<th onmouseout=\"UnTip()\" onmouseover=\"Tip('Prix bourse', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">Prix</th><th onmouseout=\"UnTip()\" onmouseover=\"Tip('% par rapport au prix de base', " +
    "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')\">%</th>";
   entete += "</tr>";
   liste_enclos += entete;
   var listetriee = new Array(), ligne = new Array();
   for (espece in liste)
   { listetriee.push(espece);
    enclostrie = new Array(); nbanim = new Array();
    for (i12=0; i12<liste[espece].length;i12+=3)
    { enclos = liste[espece][i12];
     enclostrie.push(enclos);
     nbanim[enclos] = new Array();
     for (j=1;j<3;j++) nbanim[enclos][j] = parseInt(liste[espece][i12+j]);
    }
    enclostrie.sort();
    for (i12=0;i12<enclostrie.length;i12++)
    { if (enclostrie[i12] != "aucun")
     { t = Math.floor(enclostrie[i12]/100);
      v = enclostrie[i12] - t*100;
      couleur = nom_enclos(t, v);
      if (couleur.indexOf(" n") != -1) couleur = couleur.substring(0, couleur.indexOf(" n"));
      couleur = couleur.toLowerCase();
      un = couleur == "insectarium" ? "insectarium" : "un";
      a = "<a href=\"" + urlSite + "enclosgestion1.php?t=" + t + "&v=" + v + "\" class=\"" + un + "\">" + nom_enclos(t,v).replace(" ","&nbsp;") + "</a>";
      cl = "présente ";
      b = "";
     }
     else { a = ANIMAUX[espece].enclos; b = " style='background-color:#f44;color:#fff'"; cl = "absente "; couleur = ANIMAUX[espece].enclos.toLowerCase(); }
     if (i12 == 0)
     { ligne[espece] = new Array();
      ligne[espece][i12] = "<tr class=\"" + cl + couleur + "\"><td rowspan=\"" + enclostrie.length + "\" class=\"espece\">" +
       espece.replace(" ","&nbsp;","g") + "</td>";
     }
     else ligne[espece][i12] = "<tr class=\"" + cl + couleur + "\">";
     gr = ANIMAUX[espece].agroupe ? "N" : "O";
     st = ANIMAUX[espece].stock ? "O" : "N";
     ligne[espece][i12] += "<td class=\"enclos2\"" + b + ">" + a + "</td><td>" + gr + "</td><td>" + st + "</td><td class=\"mâle\">" + 
      nbanim[enclostrie[i12]][1] + "<td class=\"femelle\">" + nbanim[enclostrie[i12]][2] + "</td>";
     if (/bourse.php/.test(window.location) && i12 == 0)
     { prixB = prixbourse[espece];
      pourcent = Math.round((parseInt(prixB)/ANIMAUX[espece].prix - 1) * 10000) / 100;
      if (pourcent >= 0) plus = "+";
      else { plus = "-"; pourcent = 0 - pourcent ; }
      ligne[espece][0] += "<td rowspan=\"" + enclostrie.length + "\">" + millier(prixB) + "</td>";
      ligne[espece][0] += "<td rowspan=\"" + enclostrie.length + "\">" + plus + "&nbsp;" + pourcent + "</td>";
     }
     ligne[espece][i12] += "</tr>";
    }
   }
   listetriee.sort();
   for (numespece in listetriee)
   { for (i12=0;i12<ligne[listetriee[numespece]].length;i12++)
     liste_enclos += ligne[listetriee[numespece]][i12];
   }
   liste_enclos += "</table>";
   liste_enclos += "<table width=\"100%\" id=\"liste_anim3\">" + entete;
   if (/bourse.php/.test(window.location))
   { listetriee.sort(function (a, b) { return parseInt(prixbourse[b]) - parseInt(prixbourse[a]) });
    for (numespece in listetriee)
    { for (i12=0;i12<ligne[listetriee[numespece]].length;i12++)
      liste_enclos += ligne[listetriee[numespece]][i12];
    }
   }
   liste_enclos += "</table>";
   liste_enclos += "<table width=\"100%\" id=\"liste_anim4\">" + entete;
   if (/bourse.php/.test(window.location))
   { listetriee.sort(function (a, b) { return parseInt(prixbourse[a])/ANIMAUX[a].prix - parseInt(prixbourse[b])/ANIMAUX[b].prix; });
    for (numespece in listetriee)
    { for (i12=0;i12<ligne[listetriee[numespece]].length;i12++)
      liste_enclos += ligne[listetriee[numespece]][i12];
    }
   }
   liste_enclos += "</table>";
   liste_enclos += "</div>";
  }
  else liste_enclos += "<div style=\"border:1px SOLID #000\">aucun animal</div></div>";
  bdiv2 = document.createElement("div");
  bdiv2.id = "tableau_animaux";
  bdiv2.setAttribute("class", "info_bulle");
  bdiv2.style.top = "0px";
  bdiv2.style.right = "0px";
  bdiv2.innerHTML = liste_enclos;
  document.body.appendChild(bdiv2);
 }
 if (GM_getValue("affichertabvieux", true))
  $("tabvieux").style.display = "";
 else $("tabvieux").style.display = "none";
 if (GM_getValue("affichertabanim", true))
  $("tabanim").style.display = "";
 else $("tabanim").style.display = "none";
 if (GM_getValue("choixliste" + page, 1) == 1)
 { $("liste_anim2").style.display = "none";
  $("radioanim").style.display = "none";
  $("liste_anim3").style.display = "none";
  $("liste_anim4").style.display = "none";
 }
 else if (GM_getValue("choixliste" + page, 1) == 2)
 { $("liste_anim1").style.display = "none";
  $("liste_anim3").style.display = "none";
  $("liste_anim4").style.display = "none";
 }
 else if (GM_getValue("choixliste" + page, 1) == 3)
 { $("liste_anim1").style.display = "none";
  $("liste_anim2").style.display = "none";
  $("liste_anim4").style.display = "none";
 }
 else
 { $("liste_anim1").style.display = "none";
  $("liste_anim2").style.display = "none";
  $("liste_anim3").style.display = "none";
 }
 if (GM_getValue("choixaffanim", 1) == 1)
 { pres = $c("présente");
  for(i12=0;i12<pres.length;i12++)
   pres[i12].style.display = "";
  abse = $c("absente");
  for(i12=0;i12<abse.length;i12++)
   abse[i12].style.display = "none";
 }
 else if (GM_getValue("choixaffanim", 1) == 2)
 { pres = $c("présente");
  for(i12=0;i12<pres.length;i12++)
   pres[i12].style.display = "none";
  abse = $c("absente");
  for(i12=0;i12<abse.length;i12++)
   abse[i12].style.display = "";
 }
 else
 { pres = $c("présente");
  for(i12=0;i12<pres.length;i12++)
   pres[i12].style.display = "";
  abse = $c("absente");
  for(i12=0;i12<abse.length;i12++)
   abse[i12].style.display = "";
 }
 if (GM_getValue("etroit4", false))
   { animvieux = $c("espece");
    for (j=0;j<animvieux.length;j++) animvieux[j].innerHTML = animvieux[j].innerHTML.replace("&nbsp;", " <br>", "g");
    enclos = $c("enclos2");
    for (j=0;j<enclos.length;j++) enclos[j].innerHTML = enclos[j].innerHTML.replace("&nbsp;", " <br>", "g");
   }
   else
   { animvieux = $c("espece");
    for (j=0;j<animvieux.length;j++) animvieux[j].innerHTML = animvieux[j].innerHTML.replace(" <br>", "&nbsp;", "g");
    enclos = $c("enclos2");
    for (j=0;j<enclos.length;j++) enclos[j].innerHTML = enclos[j].innerHTML.replace(" <br>", "&nbsp;", "g");
   }
 lien_enclos();
}

function hautbasforum() // affiche 2 liens haut et bas sur le forum
{
 var div = document.createElement("div");
 div.id = "lien_forum";
 div.setAttribute("class", "fenetre");
 div.style.top = "0px";
 div.style.right = "0px";
 div.innerHTML = "<table id=\"forum\"><tr><td><a href=\"javascript:window.scroll(0,0)\">Haut de page</a></td></tr>" +
  "<tr><td><a href=\"javascript:window.scroll(0,document.body.clientHeight)\">Bas de page</a></td></tr></table>"
 document.body.appendChild(div);
}

function reecriture_url() // réécriture des urls qui ne fonctionnent pas
{
 var url_voliere = "enclosgestion1.php?t=1&v=0";
 var url_aquarium = "enclosgestion1.php?t=1&v=1";
 var url_vivarium = "enclosgestion1.php?t=1&v=2";
 var url_noctarium = "enclosgestion1.php?t=1&v=3";
 var url_insectarium = "enclosgestion1.php?t=1&v=4";
 var les_liens = $t("a"), i13;
 for (i13=0;i13<les_liens.length;i13++)
 { if (/enclosgestion.php\?t=0&v=1000/.test(les_liens[i13].href) || /enclosgestion1.php\?t=0&v=1000/.test(les_liens[i13].href))
   les_liens[i13].href = url_voliere;
  else if (/enclosgestion.php\?t=0&v=1001/.test(les_liens[i13].href) || /enclosgestion1.php\?t=0&v=1001/.test(les_liens[i13].href))
   les_liens[i13].href = url_aquarium;
  else if (/enclosgestion.php\?t=0&v=1002/.test(les_liens[i13].href) || /enclosgestion1.php\?t=0&v=1002/.test(les_liens[i13].href))
   les_liens[i13].href = url_vivarium;
  else if (/enclosgestion.php\?t=0&v=1003/.test(les_liens[i13].href) || /enclosgestion1.php\?t=0&v=1003/.test(les_liens[i13].href))
   les_liens[i13].href = url_noctarium;
  else if (/enclosgestion.php\?t=0&v=1004/.test(les_liens[i13].href) || /enclosgestion1.php\?t=0&v=1004/.test(les_liens[i13].href))
   les_liens[i13].href = url_insectarium;
 }
}

function DrawLine(x1,y1,x2,y2,color)
{
 // on calcule la longueur du segment
 var lg = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
 // on détermine le nombre de points nécessaires
 var nbPoints = Math.floor(lg);
 // stepX, stepY = distance entre deux points;
 var stepX = (x2-x1)/lg;
 var stepY = (y2-y1)/lg;
 var Points='';
 for (var i14=0;i14<nbPoints+1;i14+=5)
  Points += '<div style="font-size:3px;cursor:default;width:3px;heigth:3px;background-color:' + color + ';position:absolute;top:' + Math.round(y1-1+i14*stepY) +
   'px;left:' + Math.round(x1+i14*stepX) + 'px">&nbsp;</div>';
 // on rajoute le point de départ
 Points += '<div style="font-size:3px;cursor:default;width:3px;heigth:3px;background-color:#000000;position:absolute;top:' + (y1-1) + 'px;left:' + x1 + 'px">&nbsp;</div>';
 // et le point d'arrivée
 Points += '<div style="font-size:3px;cursor:default;width:3px;heigth:3px;background-color:#000000;position:absolute;top:' + (y2-1) + 'px;left:' + x2 + 'px">&nbsp;</div>';
 return Points;
}

function decompose(extraitsuivi)
{
 var donnees = extraitsuivi, sousdonnees;
 this.date = donnees.substring(0, donnees.indexOf(":"));
 jour = this.date.substring(0,this.date.indexOf("/"));
 mois = this.date.substring(this.date.indexOf("/")+1);
 an = mois.substring(mois.indexOf("/")+1);
 mois = mois.substring(0,mois.indexOf("/"));
 if (an.indexOf("/") != -1) an = an.substring(0,an.indexOf("/"));
 val = parseInt(an) * 500 + parseInt(mois) * 40 + parseInt(jour);
 donnees = donnees.substring(donnees.indexOf(":")+1);
 sousdonnees = donnees.substring(0, donnees.indexOf(","));
 if (sousdonnees.indexOf("/") != -1)
 { this.couples = parseInt(sousdonnees.substring(0, sousdonnees.indexOf("/")).replace(" ","","g"));
  sousdonnees = sousdonnees.substring(sousdonnees.indexOf("/")+1);
  if (sousdonnees.indexOf("/") != -1)
  { this.valeurT = parseInt(sousdonnees.substring(0, sousdonnees.indexOf("/")).replace(" ","","g"));
   sousdonnees = sousdonnees.substring(sousdonnees.indexOf("/")+1);
   this.nbanim = parseInt(sousdonnees.substring(0, sousdonnees.indexOf("/")).replace(" ","","g"));
   this.agemoyen = parseFloat(sousdonnees.substring(sousdonnees.indexOf("/")+1).replace(" ","","g"));
  }
  else if (val >= 1005046)
  { this.valeurT = parseInt(sousdonnees.substring(sousdonnees.indexOf("/")+1).replace(" ","","g"));
   this.nbanim = -1;
   this.agemoyen = -1;
  }
  else
  { this.valeurT = -1; // on ne tient pas compte des valeurs anciennes, erronées
   this.nbanim = -1;
   this.agemoyen = -1;
  }
 }
 else
 { this.couples = parseInt(sousdonnees.replace(" ","","g"));
  this.valeurT = -1;
  this.nbanim = -1;
  this.agemoyen = -1;
 }
 donnees = donnees.substring(donnees.indexOf(",")+1);
 if (donnees.indexOf(",") != -1)
 { sousdonnees = donnees.substring(0, donnees.indexOf(","));
  this.nb = parseInt(sousdonnees.substring(0, sousdonnees.indexOf("/")));
  this.nb_th = parseFloat(sousdonnees.substring(sousdonnees.indexOf("/")+1));
  donnees = donnees.substring(donnees.indexOf(",")+1);
  if (donnees.indexOf(",") != -1)
  { sousdonnees = donnees.substring(0, donnees.indexOf(","));
   this.valeur = parseInt(sousdonnees.substring(0, sousdonnees.indexOf("/")).replace(" ","","g"));
   if (val >= 1005005) this.valeur_th = parseInt(sousdonnees.substring(sousdonnees.indexOf("/")+1).replace(" ","","g"));
   else this.valeur_th = -1; // on ne tient pas compte des valeurs anciennes, erronées
   donnees = donnees.substring(donnees.indexOf(",")+1);
   if (donnees.indexOf(",") != -1)
   { sousdonnees = donnees.substring(0, donnees.indexOf(","));
    this.moyenne = parseInt(sousdonnees.substring(0, sousdonnees.indexOf("/")).replace(" ","","g"));
    if (sousdonnees.substring(sousdonnees.indexOf("/")+1) == "NaN") this.moyenne_th = -1;
    else if (val >= 1005005) this.moyenne_th = parseInt(sousdonnees.substring(sousdonnees.indexOf("/")+1).replace(" ","","g"));
    else this.moyenne_th = -1;
    donnees = donnees.substring(donnees.indexOf(",")+1);
    this.males = parseInt(donnees.substring(0, donnees.indexOf("/")));
    this.femelles = parseInt(donnees.substring(donnees.indexOf("/")+1));
   }
   else
   { this.moyenne = parseInt(donnees.substring(0, donnees.indexOf("/")).replace(" ","","g"));
    if (donnees.substring(donnees.indexOf("/")+1) == "NaN") this.moyenne_th = -1;
    else if (val >= 1005005) this.moyenne_th = parseInt(donnees.substring(donnees.indexOf("/")+1).replace(" ","","g"));
    else this.moyenne_th = -1;
    this.males = -1;
    this.femelles = -1;
   }
  }
  else
  { this.valeur = parseInt(donnees.substring(0, donnees.indexOf("/")).replace(" ","","g"));
   this.valeur_th = -1;
   this.moyenne = parseInt(donnees.substring(donnees.indexOf("/")+1).replace(" ","","g"));
   this.moyenne_th = -1;
   this.males = -1;
   this.femelles = -1;
  }
 }
 else
 { this.nb = parseInt(donnees.substring(0, donnees.indexOf("/")));
  this.nb_th = parseFloat(donnees.substring(donnees.indexOf("/")+1));
  this.valeur = -1;
  this.valeur_th = -1;
  this.moyenne = -1;
  this.moyenne_th = -1;
  this.males = -1;
  this.femelles = -1;
 }
}

function analyse_suivi()
{
 var suivi = GM_getValue("suivi_naissances_" + id_zoo);
 var i15 = 0;
 while (suivi != "")
 { tab_suivi[i15] = new decompose(suivi.substring(0,suivi.indexOf(";")));
  i15++;
  suivi = suivi.substring(suivi.indexOf(";")+1)
 }
 imax = i15;
 /*for (i15=0;i15<imax;i15++)
 { suivi += tab_suivi[i15].date + ":" + tab_suivi[i15].couples + "/" + tab_suivi[i15].valeurT + "," + tab_suivi[i15].nb + "/" + tab_suivi[i15].nb_th + "," +
   tab_suivi[i15].valeur + "/" + tab_suivi[i15].valeur_th + "," + tab_suivi[i15].moyenne + "/" + tab_suivi[i15].moyenne_th + "," + tab_suivi[i15].males + "/" +
   tab_suivi[i15].femelles + "\n";
 } alert(suivi);*/
 for (i15=0;i15<imax;i15++)
 { if (min.couples == -1) min.couples = tab_suivi[i15].couples;
  else if (tab_suivi[i15].couples < min.couples && tab_suivi[i15].couples >= 0) min.couples = tab_suivi[i15].couples;
  if (min.valeurT == -1) min.valeurT = tab_suivi[i15].valeurT;
  else if (tab_suivi[i15].valeurT < min.valeurT && tab_suivi[i15].valeurT >= 0) min.valeurT = tab_suivi[i15].valeurT;
  if (min.nbanim == -1) min.nbanim = tab_suivi[i15].nbanim;
  else if (tab_suivi[i15].nbanim < min.nbanim && tab_suivi[i15].nbanim >= 0) min.nbanim = tab_suivi[i15].nbanim;
  if (min.agemoyen == -1) min.agemoyen = tab_suivi[i15].agemoyen;
  else if (tab_suivi[i15].agemoyen < min.agemoyen && tab_suivi[i15].agemoyen >= 0) min.agemoyen = tab_suivi[i15].agemoyen;
  if (min.nb == -1) min.nb = tab_suivi[i15].nb;
  else if (tab_suivi[i15].nb < min.nb && tab_suivi[i15].nb >= 0) min.nb = tab_suivi[i15].nb;
  if (min.nb_th == -1) min.nb_th = tab_suivi[i15].nb_th;
  else if (tab_suivi[i15].nb_th < min.nb_th && tab_suivi[i15].nb_th > 0) min.nb_th = tab_suivi[i15].nb_th;
  if (min.valeur == -1) min.valeur = tab_suivi[i15].valeur;
  else if (tab_suivi[i15].valeur < min.valeur && tab_suivi[i15].valeur >= 0) min.valeur = tab_suivi[i15].valeur;
  if (min.valeur_th == -1) min.valeur_th = tab_suivi[i15].valeur_th;
  else if (tab_suivi[i15].valeur_th < min.valeur_th && tab_suivi[i15].valeur_th > 0) min.valeur_th = tab_suivi[i15].valeur_th;
  if (min.moyenne == -1) min.moyenne = tab_suivi[i15].moyenne;
  else if (tab_suivi[i15].moyenne < min.moyenne && tab_suivi[i15].moyenne >= 0) min.moyenne = tab_suivi[i15].moyenne;
  if (min.moyenne_th == -1) min.moyenne_th = tab_suivi[i15].moyenne_th;
  else if (tab_suivi[i15].moyenne_th < min.moyenne_th && tab_suivi[i15].moyenne_th > 0) min.moyenne_th = tab_suivi[i15].moyenne_th;
  if (min.males == -1) min.males = tab_suivi[i15].males;
  else if (tab_suivi[i15].males < min.males && tab_suivi[i15].males >= 0) min.males = tab_suivi[i15].males;
  if (min.femelles == -1) min.femelles = tab_suivi[i15].femelles;
  else if (tab_suivi[i15].femelles < min.femelles && tab_suivi[i15].femelles >= 0) min.femelles = tab_suivi[i15].femelles;
 }
 for (i15=0;i15<imax;i15++)
 { if (max.couples == -1) max.couples = tab_suivi[i15].couples;
  else if (tab_suivi[i15].couples > max.couples) max.couples = tab_suivi[i15].couples;
  if (max.valeurT == -1) max.valeurT = tab_suivi[i15].valeurT;
  else if (tab_suivi[i15].valeurT > max.valeurT) max.valeurT = tab_suivi[i15].valeurT;
  if (max.nbanim == -1) max.nbanim = tab_suivi[i15].nbanim;
  else if (tab_suivi[i15].nbanim > max.nbanim) max.nbanim = tab_suivi[i15].nbanim;
  if (max.agemoyen == -1) max.agemoyen = tab_suivi[i15].agemoyen;
  else if (tab_suivi[i15].agemoyen > max.agemoyen) max.agemoyen = tab_suivi[i15].agemoyen;
  if (max.nb == -1) max.nb = tab_suivi[i15].nb;
  else if (tab_suivi[i15].nb > max.nb) max.nb = tab_suivi[i15].nb;
  if (max.nb_th == -1) max.nb_th = tab_suivi[i15].nb_th;
  else if (tab_suivi[i15].nb_th > max.nb_th) max.nb_th = tab_suivi[i15].nb_th;
  if (max.valeur == -1) max.valeur = tab_suivi[i15].valeur;
  else if (tab_suivi[i15].valeur > max.valeur) max.valeur = tab_suivi[i15].valeur;
  if (max.valeur_th == -1) max.valeur_th = tab_suivi[i15].valeur_th;
  else if (tab_suivi[i15].valeur_th > max.valeur_th) max.valeur_th = tab_suivi[i15].valeur_th;
  if (max.moyenne == -1) max.moyenne = tab_suivi[i15].moyenne;
  else if (tab_suivi[i15].moyenne > max.moyenne) max.moyenne = tab_suivi[i15].moyenne;
  if (max.moyenne_th == -1) max.moyenne_th = tab_suivi[i15].moyenne_th;
  else if (tab_suivi[i15].moyenne_th > max.moyenne_th) max.moyenne_th = tab_suivi[i15].moyenne_th;
  if (max.males == -1) max.males = tab_suivi[i15].males;
  else if (tab_suivi[i15].males > max.males) max.males = tab_suivi[i15].males;
  if (max.femelles == -1) max.femelles = tab_suivi[i15].femelles;
  else if (tab_suivi[i15].femelles > max.femelles) max.femelles = tab_suivi[i15].femelles;
 }
}

function graphique(btd)
{ var i16, j, jmax = 0, min2;
 var x1, y1, x2, y2, txt, date1 = "", date2 = "";
 var nbpoints, typerepartition;
 deb = 0;
 pas = 1;
 iclic = 1 + $("choix_trace").selectedIndex;
 var btable = $("suivi");
 if (!btable)
 { btable = document.createElement("table");
  btable.id = "suivi";
  btable.style.width = largeurgraphique + 10 + "px";
  btable.style.height = hauteurgraphique + 50 + "px";
  bligne1 = document.createElement("tr");
  bligne2 = document.createElement("tr");
  bligne3 = document.createElement("tr");
  bligne4 = document.createElement("tr");
  bcase1 = document.createElement("td");
  bcase2 = document.createElement("td");
  bcase2.setAttribute("style", "position:absolute;border:1px solid #000");
  bcase2.setAttribute("rowspan", "2");
  bcase2.setAttribute("colspan", "3");
  bcase2.id = "casegraphe";
  bcase3 = document.createElement("td");
  bcase4 = document.createElement("td");
  bcase5 = document.createElement("td");
  bcase6 = document.createElement("td");
  bcase7 = document.createElement("td");
  bcase8 = document.createElement("td");
  bcase9 = document.createElement("td");
  bcase10 = document.createElement("td");
  bcase11 = document.createElement("td");
  bcase1.setAttribute("height", hauteurgraphique);
  bcase1.setAttribute("valign", "top");
  bligne1.appendChild(bcase1);
  bligne1.appendChild(bcase2);
  bligne2.appendChild(bcase3);
  bcase5.style.textAlign= "left";
  bcase5.innerHTML = "&nbsp;|";
  bcase7.innerHTML = "|&nbsp;";
  bcase7.style.textAlign= "right";
  bligne3.appendChild(bcase4);
  bligne3.appendChild(bcase5);
  bligne3.appendChild(bcase6);
  bligne3.appendChild(bcase7);
  bcase10.setAttribute("style", "font-size:10px;font-weight:bold;text-align:center");
  bcase11.style.textAlign= "right";
  bligne4.appendChild(bcase8);
  bligne4.appendChild(bcase9);
  bligne4.appendChild(bcase10);
  bligne4.appendChild(bcase11);
  btable.appendChild(bligne1);
  btable.appendChild(bligne2);
  btable.appendChild(bligne3);
  btable.appendChild(bligne4);
  btd[4].appendChild(btable);
 }
 extrait = new Array();
 extrait2 = new Array();
 var moyenne = new Array();
 dategr = new Array();
 nbpoints = parseInt(GM_getValue("nbpoints", 5));
 if (nbpoints != 5)
 { typerepartition = parseInt(GM_getValue("typerepartition", 1));
  if (nbpoints == 1) nbpoints = 50;
  else if (nbpoints == 2) nbpoints = 75;
  else if (nbpoints == 3) nbpoints = 100;
  else nbpoints = 150;
 }
 else nbpoints = 0;
 switch (iclic)
 { case 1:
   for (i16=0;i16<imax;i16++)
    if (tab_suivi[i16].nbanim >= 0)
    { extrait[jmax] = tab_suivi[i16].nbanim;
     if (date1 == "") date1 = tab_suivi[i16].date;
     dategr[jmax] = tab_suivi[i16].date;
     date2 = dategr[jmax];
     jmax++;
    }
   if (jmax - 1 > nbpoints && nbpoints > 0)
   { if (typerepartition == 2)
    { deb = jmax - nbpoints;
     for (i16=deb;i16<=jmax;i16++)
     { if (i16 == deb) { min2 = extrait[i16]; max2 = extrait[i16]; date1 = dategr[i16]; }
      else
      { if (extrait[i16] < min2) min2 = extrait[i16];
       if (extrait[i16] > max2) max2 = extrait[i16];
      }
     }
    }
    else
    { pas = (jmax - 1)/ (nbpoints - 1);
     for (i16=0;i16<nbpoints;i16++)
     { if (i16 == 0) { min2 = extrait[i16]; max2 = extrait[i16]; }
      else
      { if (extrait[Math.ceil(i16*pas)] < min2) min2 = extrait[Math.ceil(i16*pas)];
       if (extrait[Math.ceil(i16*pas)] > max2) max2 = extrait[Math.ceil(i16*pas)];
      }
     }
     date2 = dategr[Math.ceil((nbpoints-1)*pas)];
    }
    jmax = nbpoints;
   }
   else
   { max2 = max.nbanim;
    min2 = min.nbanim;
   }
   break;
  case 2:
   for (i16=0;i16<imax;i16++)
    if (tab_suivi[i16].agemoyen >= 0)
    { extrait[jmax] = tab_suivi[i16].agemoyen;
     if (date1 == "") date1 = tab_suivi[i16].date;
     dategr[jmax] = tab_suivi[i16].date;
     date2 = dategr[jmax];
     jmax++;
    }
   if (jmax - 1 > nbpoints && nbpoints > 0)
   { if (typerepartition == 2)
    { deb = jmax - nbpoints;
     for (i16=deb;i16<=jmax;i16++)
     { if (i16 == deb) { min2 = extrait[i16]; max2 = extrait[i16]; date1 = dategr[i16]; }
      else
      { if (extrait[i16] < min2) min2 = extrait[i16];
       if (extrait[i16] > max2) max2 = extrait[i16];
      }
     }
    }
    else
    { pas = (jmax - 1)/ (nbpoints - 1);
     for (i16=0;i16<nbpoints;i16++)
     { if (i16 == 0) { min2 = extrait[i16]; max2 = extrait[i16]; }
      else
      { if (extrait[Math.ceil(i16*pas)] < min2) min2 = extrait[Math.ceil(i16*pas)];
       if (extrait[Math.ceil(i16*pas)] > max2) max2 = extrait[Math.ceil(i16*pas)];
      }
     }
     date2 = dategr[Math.ceil((nbpoints-1)*pas)];
    }
    jmax = nbpoints;
   }
   else
   { max2 = max.agemoyen;
    min2 = min.agemoyen;
   }
   break;
  case 3:
   for (i16=0;i16<imax;i16++)
    if (tab_suivi[i16].couples >= 0)
    { extrait[jmax] = tab_suivi[i16].couples;
     if (date1 == "") date1 = tab_suivi[i16].date;
     dategr[jmax] = tab_suivi[i16].date;
     date2 = dategr[jmax];
     jmax++;
    }
   if (jmax - 1 > nbpoints && nbpoints > 0)
   { if (typerepartition == 2)
    { deb = jmax - nbpoints;
     for (i16=deb;i16<=jmax;i16++)
     { if (i16 == deb) { min2 = extrait[i16]; max2 = extrait[i16]; date1 = dategr[i16]; }
      else
      { if (extrait[i16] < min2) min2 = extrait[i16];
       if (extrait[i16] > max2) max2 = extrait[i16];
      }
     }
    }
    else
    { pas = (jmax - 1)/ (nbpoints - 1);
     for (i16=0;i16<nbpoints;i16++)
     { if (i16 == 0) { min2 = extrait[i16]; max2 = extrait[i16]; }
      else
      { if (extrait[Math.ceil(i16*pas)] < min2) min2 = extrait[Math.ceil(i16*pas)];
       if (extrait[Math.ceil(i16*pas)] > max2) max2 = extrait[Math.ceil(i16*pas)];
      }
     }
     date2 = dategr[Math.ceil((nbpoints-1)*pas)];
    }
    jmax = nbpoints;
   }
   else
   { max2 = max.couples;
    min2 = min.couples;
   }
   break;
  case 4:
   for (i16=0;i16<imax;i16++)
    if (tab_suivi[i16].valeurT >= 0)
    { extrait[jmax] = tab_suivi[i16].valeurT;
     if (date1 == "") date1 = tab_suivi[i16].date;
     dategr[jmax] = tab_suivi[i16].date;
     date2 = dategr[jmax];
     jmax++;
    }
   if (jmax - 1 > nbpoints && nbpoints > 0)
   { if (typerepartition == 2)
    { deb = jmax - nbpoints;
     for (i16=deb;i16<=jmax;i16++)
     { if (i16 == deb) { min2 = extrait[i16]; max2 = extrait[i16]; date1 = dategr[i16]; }
      else
      { if (extrait[i16] < min2) min2 = extrait[i16];
       if (extrait[i16] > max2) max2 = extrait[i16];
      }
     }
    }
    else
    { pas = (jmax - 1)/ (nbpoints - 1);
     for (i16=0;i16<nbpoints;i16++)
     { if (i16 == 0) { min2 = extrait[i16]; max2 = extrait[i16]; }
      else
      { if (extrait[Math.ceil(i16*pas)] < min2) min2 = extrait[Math.ceil(i16*pas)];
       if (extrait[Math.ceil(i16*pas)] > max2) max2 = extrait[Math.ceil(i16*pas)];
      }
     }
     date2 = dategr[Math.ceil((nbpoints-1)*pas)];
    }
    jmax = nbpoints;
   }
   else
   { max2 = max.valeurT;
    min2 = min.valeurT;
   }
   break;
  case 5:
   for (i16=0;i16<imax;i16++)
    if (tab_suivi[i16].nb >= 0)
    { extrait[jmax] = tab_suivi[i16].nb;
     extrait2[jmax] = tab_suivi[i16].nb_th;
     if (date1 == "") date1 = tab_suivi[i16].date;
     dategr[jmax] = tab_suivi[i16].date;
     date2 = dategr[jmax];
     jmax++;
    }
   if (jmax - 1 > nbpoints && nbpoints > 0)
   { if (typerepartition == 2)
    { deb = jmax - nbpoints;
     for (i16=deb;i16<=jmax;i16++)
     { if (i16 == deb) { min2 = extrait[i16]; max2 = extrait[i16]; date1 = dategr[i16]; }
      else
      { if (extrait[i16] < min2) min2 = extrait[i16];
       if (extrait[i16] > max2) max2 = extrait[i16];
      }
      if (extrait2[i16] > 0 && extrait2[i16] < min2) min2 = extrait2[i16];
      if (extrait2[i16] > max2) max2 = extrait2[i16];
     }
    }
    else
    { pas = (jmax - 1)/ (nbpoints - 1);
     for (i16=0;i16<nbpoints;i16++)
     { if (i16 == 0) { min2 = extrait[i16]; max2 = extrait[i16]; }
      else
      { if (extrait[Math.ceil(i16*pas)] < min2) min2 = extrait[Math.ceil(i16*pas)];
       if (extrait[Math.ceil(i16*pas)] > max2) max2 = extrait[Math.ceil(i16*pas)];
      }
      if (extrait2[Math.ceil(i16*pas)] > 0 && extrait2[Math.ceil(i16*pas)] < min2) min2 = extrait2[Math.ceil(i16*pas)];
      if (extrait2[Math.ceil(i16*pas)] > max2) max2 = extrait2[Math.ceil(i16*pas)];
     }
     date2 = dategr[Math.ceil((nbpoints-1)*pas)];
    }
    jmax = nbpoints;
   }
   else
   { max2 = Math.max(max.nb, max.nb_th);
    min2 = Math.min(min.nb, min.nb_th);
   }
   break;
  case 6:
   for (i16=0;i16<imax;i16++)
    if (tab_suivi[i16].males >= 0)
    { extrait[jmax] = tab_suivi[i16].males;
     extrait2[jmax] = tab_suivi[i16].femelles;
     if (date1 == "") date1 = tab_suivi[i16].date;
     dategr[jmax] = tab_suivi[i16].date;
     date2 = dategr[jmax];
     jmax++;
    }
   if (jmax - 1 > nbpoints && nbpoints > 0)
   { if (typerepartition == 2)
    { deb = jmax - nbpoints;
     for (i16=deb;i16<=jmax;i16++)
     { if (i16 == deb) { min2 = extrait[i16]; max2 = extrait[i16]; date1 = dategr[i16]; }
      else
      { if (extrait[i16] < min2) min2 = extrait[i16];
       if (extrait[i16] > max2) max2 = extrait[i16];
      }
      if (extrait2[i16] < min2) min2 = extrait2[i16];
      if (extrait2[i16] > max2) max2 = extrait2[i16];
     }
    }
    else
    { pas = (jmax - 1)/ (nbpoints - 1);
     for (i16=0;i16<nbpoints;i16++)
     { if (i16 == 0) { min2 = extrait[i16]; max2 = extrait[i16]; }
      else
      { if (extrait[Math.ceil(i16*pas)] < min2) min2 = extrait[Math.ceil(i16*pas)];
       if (extrait[Math.ceil(i16*pas)] > max2) max2 = extrait[Math.ceil(i16*pas)];
      }
      if (extrait2[Math.ceil(i16*pas)] < min2) min2 = extrait2[Math.ceil(i16*pas)];
      if (extrait2[Math.ceil(i16*pas)] > max2) max2 = extrait2[Math.ceil(i16*pas)];
     }
     date2 = dategr[Math.ceil((nbpoints-1)*pas)];
    }
    jmax = nbpoints;
   }
   else
   { max2 = Math.max(max.males, max.femelles);
    min2 = Math.min(min.males, min.femelles);
   }
   break;
  case 7:
   for (i16=0;i16<imax;i16++)
    if (tab_suivi[i16].valeur >= 0)
    { extrait[jmax] = tab_suivi[i16].valeur;
     extrait2[jmax] = tab_suivi[i16].valeur_th;
     if (date1 == "") date1 = tab_suivi[i16].date;
     dategr[jmax] = tab_suivi[i16].date;
     date2 = dategr[jmax];
     jmax++;
    }
   if (jmax - 1 > nbpoints && nbpoints > 0)
   { if (typerepartition == 2)
    { deb = jmax - nbpoints;
     for (i16=deb;i16<=jmax;i16++)
     { if (i16 == deb) { min2 = extrait[i16]; max2 = extrait[i16]; date1 = dategr[i16]; }
      else
      { if (extrait[i16] < min2) min2 = extrait[i16];
       if (extrait[i16] > max2) max2 = extrait[i16];
      }
      if (extrait2[i16] > 0 && extrait2[i16] < min2) min2 = extrait2[i16];
      if (extrait2[i16] > max2) max2 = extrait2[i16];
     }
    }
    else
    { pas = (jmax - 1)/ (nbpoints - 1);
     for (i16=0;i16<nbpoints;i16++)
     { if (i16 == 0) { min2 = extrait[i16]; max2 = extrait[i16]; }
      else
      { if (extrait[Math.ceil(i16*pas)] < min2) min2 = extrait[Math.ceil(i16*pas)];
       if (extrait[Math.ceil(i16*pas)] > max2) max2 = extrait[Math.ceil(i16*pas)];
      }
      if (extrait2[Math.ceil(i16*pas)] > 0 && extrait2[Math.ceil(i16*pas)] < min2) min2 = extrait2[Math.ceil(i16*pas)];
      if (extrait2[Math.ceil(i16*pas)] > max2) max2 = extrait2[Math.ceil(i16*pas)];
     }
     date2 = dategr[Math.ceil((nbpoints-1)*pas)];
    }
    jmax = nbpoints;
   }
   else
   { max2 = Math.max(max.valeur, max.valeur_th);
    min2 = Math.min(min.valeur, min.valeur_th);
   }
   break;
  case 8:
   for (i16=0;i16<imax;i16++)
    if (tab_suivi[i16].moyenne >= 0)
    { extrait[jmax] = tab_suivi[i16].moyenne;
     extrait2[jmax] = tab_suivi[i16].moyenne_th;
     if (date1 == "") date1 = tab_suivi[i16].date;
     dategr[jmax] = tab_suivi[i16].date;
     date2 = dategr[jmax];
     jmax++;
    }
   if (jmax - 1 > nbpoints && nbpoints > 0)
   { if (typerepartition == 2)
    { deb = jmax - nbpoints;
     for (i16=deb;i16<=jmax;i16++)
     { if (i16 == deb) { min2 = extrait[i16]; max2 = extrait[i16]; date1 = dategr[i16]; }
      else
      { if (extrait[i16] < min2) min2 = extrait[i16];
       if (extrait[i16] > max2) max2 = extrait[i16];
      }
      if (extrait2[i16] > 0 && extrait2[i16] < min2) min2 = extrait2[i16];
      if (extrait2[i16] > max2) max2 = extrait2[i16];
     }
    }
    else
    { pas = (jmax - 1)/ (nbpoints - 1);
     for (i16=0;i16<nbpoints;i16++)
     { if (i16 == 0) { min2 = extrait[i16]; max2 = extrait[i16]; }
      else
      { if (extrait[Math.ceil(i16*pas)] < min2) min2 = extrait[Math.ceil(i16*pas)];
       if (extrait[Math.ceil(i16*pas)] > max2) max2 = extrait[Math.ceil(i16*pas)];
      }
      if (extrait2[Math.ceil(i16*pas)] > 0 && extrait2[Math.ceil(i16*pas)] < min2) min2 = extrait2[Math.ceil(i16*pas)];
      if (extrait2[Math.ceil(i16*pas)] > max2) max2 = extrait2[Math.ceil(i16*pas)];
     }
     date2 = dategr[Math.ceil((nbpoints-1)*pas)];
    }
    jmax = nbpoints;
   }
   else
   { max2 = Math.max(max.moyenne, max.moyenne_th);
    min2 = Math.min(min.moyenne, min.moyenne_th);
   }
   if (min2 == -1) min2 = 0;
   break;
 }
 if (min2 == max2) { min2 += -1; max2 += 1; }
 bcase1.innerHTML = millier(max2).replace(" ","&nbsp;","g") + "&nbsp;-";
 bcase1.style.width = 0 + "px";
 if (iclic < 5)
 { if (extrait[Math.ceil(deb)] > 0)
  { pourcent = 100 * (extrait[Math.ceil(deb+(jmax-1)*pas)] - extrait[Math.ceil(deb)]) / extrait[Math.ceil(deb)];
   pourcent = Math.round(10 * pourcent) / 10;
   if (pourcent >= 0) bcase10.innerHTML = "Progression entre 1er et dernier point : + " + pourcent + "&nbsp;%";
   else
   { pourcent = 0 - pourcent;
    bcase10.innerHTML = "Progression entre 1er et dernier point : - " + pourcent + "&nbsp;%";
   }
  }
  else bcase10.innerHTML = "";
 }
 else
 { var totreel = 0, totth = 0, type, debut;
  for (j=0;j<jmax;j++) { totreel += extrait[Math.ceil(deb+j*pas)]; totth += extrait2[Math.ceil(deb+j*pas)]; }
  var ecartmoy = (totreel - totth) / jmax;
  ecartmoy = iclic < 7 ? Math.round(100 * ecartmoy) / 100 : Math.round(ecartmoy);
  switch(iclic)
  { case 5 : type = " naissances"; break;
   case 6 : type = " naissances"; break;
   case 7 : type = " Zoo'z"; break;
   case 8 : type = " Zoo'z";
  }
  debut = iclic == 6 ? "Ecart moyen entre mâles et femelles : " : "Ecart moyen entre réalité et théorie : ";
  if (ecartmoy >= 0) bcase10.innerHTML = debut + "+ " + millier(ecartmoy) + type;
  else
  { ecartmoy = 0 - ecartmoy;
   bcase10.innerHTML = debut + "- " + millier(ecartmoy) + type;
  }
 }
 bcase9.innerHTML = date1;
 bcase11.innerHTML = date2;
 bcase9.style.width = 0 + "px";
 bcase11.style.width = 0 + "px";
 bcase10.style.width = largeurgraphique - bcase4.clientWidth - bcase5.clientWidth - bcase7.clientWidth;
 for (j=0;j<jmax;j++) moyenne[j] = 0;
 i16min = Math.ceil((0 - deb)/pas);
 for (j=0;j<jmax;j++)
 { for (i16=Math.max(i16min,j-14);i16<=j;i16++) moyenne[j] += extrait[Math.ceil(deb+i16*pas)];
  if (iclic == 2 || iclic == 5 || iclic == 6) moyenne[j] = Math.round(100 * moyenne[j] / (i16 - Math.max(i16min,j-14))) / 100;
  else moyenne[j] = Math.round(moyenne[j] / (i16 - Math.max(i16min,j-14)));
  if (moyenne[j] < min2) min2 = moyenne[j];
 }
 if (iclic == 6)
 { var moyenne2 = new Array();
  for (j=0;j<jmax;j++) moyenne2[j] = 0;
  for (j=0;j<jmax;j++)
  { for (i16=Math.max(i16min,j-14);i16<=j;i16++) moyenne2[j] += extrait2[Math.ceil(deb+i16*pas)];
   moyenne2[j] = Math.round(100 * moyenne2[j] / (i16 - Math.max(i16min,j-14))) / 100;
   if (moyenne2[j] < min2) min2 = moyenne2[j];
  }
 }
 bcase3.innerHTML = millier(min2).replace(" ","&nbsp;","g") + "&nbsp;-";
 hy = max2 - min2;
 if (jmax > 1) pasx = (largeurgraphique-bcase1.clientWidth-3)/(jmax-1);
 else pasx = largeurgraphique-bcase1.clientWidth-3;
 XX = 5;
 YY = 9;
 txt = "";
 if (jmax > 1)
  for (j=0;j<jmax-1;j++)
  { x1 = XX+j*pasx;
   y1 = YY + hauteurgraphique*(max2-extrait[Math.ceil(deb+j*pas)])/hy;
   x2 = XX+(j+1)*pasx;
   y2 = YY+hauteurgraphique*(max2-extrait[Math.ceil(deb+(j+1)*pas)])/hy;
   txt += DrawLine(x1,y1,x2,y2,"#B86242");
   x1 = XX+j*pasx;
   y1 = YY+hauteurgraphique*(max2-moyenne[j])/hy;
   x2 = XX+(j+1)*pasx;
   y2 = YY+hauteurgraphique*(max2-moyenne[j+1])/hy;
   txt += DrawLine(x1,y1,x2,y2,"#E2AD13");
   if (extrait2.length > 0)
   { if (iclic != 6)
    { if (extrait2[Math.ceil(deb+j*pas)] > 0 && extrait2[Math.ceil(deb+(j+1)*pas)] > 0)
     { x1 = XX+j*pasx;
      y1 = YY+hauteurgraphique*(max2-extrait2[Math.ceil(deb+j*pas)])/hy;
      x2 = XX+(j+1)*pasx;
      y2 = YY+hauteurgraphique*(max2-extrait2[Math.ceil(deb+(j+1)*pas)])/hy;
      txt += DrawLine(x1,y1,x2,y2,"#2732c7");
     }
    }
    else
    { if (extrait2[Math.ceil(deb+j*pas)] >= 0 && extrait2[Math.ceil(deb+(j+1)*pas)] >= 0)
     { x1 = XX+j*pasx;
      y1 = YY+hauteurgraphique*(max2-extrait2[Math.ceil(deb+j*pas)])/hy;
      x2 = XX+(j+1)*pasx;
      y2 = YY+hauteurgraphique*(max2-extrait2[Math.ceil(deb+(j+1)*pas)])/hy;
      txt += DrawLine(x1,y1,x2,y2,"#2732c7");
     }
     x1 = XX+j*pasx;
     y1 = YY+hauteurgraphique*(max2-moyenne2[j])/hy;
     x2 = XX+(j+1)*pasx;
     y2 = YY+hauteurgraphique*(max2-moyenne2[j+1])/hy;
     txt += DrawLine(x1,y1,x2,y2,"#19D5D4");
    }
   }
  }
 else if (jmax == 1)
 { x1 = XX;
  y1 = YY+hauteurgraphique*(max2-extrait[Math.ceil(deb)])/hy;
  x2 = XX+pasx;
  y2 = y1;
  txt += DrawLine(x1,y1,x2,y2,"#B86242");
  if (extrait2.length > 0)
  { if (extrait2[Math.ceil(deb)] > 0)
   { x1 = XX;
    y1 = YY+hauteurgraphique*(max2-extrait2[Math.ceil(deb)])/hy;
    x2 = XX+pasx;
    y2 = y1;
    txt += DrawLine(x1,y1,x2,y2,"#2732c7");
   }
  }
 }
 bcase2.innerHTML = txt;
 document.addEventListener("mousemove", suivisouris, true);
 bcase2.width = XX + largeurgraphique - bcase1.clientWidth + "px";
 bcase2.height = hauteurgraphique + 15 + "px";
 if (nbpoints != 0)
  if (typerepartition == 1) txt = jmax + " points équitablement répartis.";
  else txt = "Les " + jmax + " derniers points.";
 else txt = "Tous les points disponibles (" + jmax + ").";
 if (iclic != 6) txt += "<br />En orange, moyenne glissante des 15 derniers points."
 else txt += "<br />En orange (mâles) et en bleu ciel (femelles), moyenne glissante des 15 derniers points."
 $("titre_trace").innerHTML = txt;
}

function suivisouris(e)
{
 var sourisX1 = e.clientX - position($("casegraphe"))["x"];
 var sourisY = window.scrollY + e.clientY;
 var sourisY1 = sourisY - position($("casegraphe"))["y"];
 var sourisX2 = sourisX1 - $("casegraphe").clientWidth;
 var sourisY2 = sourisY1 - $("casegraphe").clientHeight;
 if (sourisX1 < 0 || sourisY1 < 0 || sourisX2 > 0 || sourisY2 > 0)
 { exist = $("bullegraphe");
  if (exist) exist.parentNode.removeChild(exist);
  exist = $("traitgraphe");
  if (exist) exist.parentNode.removeChild(exist);
 }
 else
 { var x = Math.max(0, Math.floor(0.5 + ((sourisX1 - 7) / pasx)));
  var type, qualif = "", type2;
  switch (iclic)
  { case 1 : type = "Nombre d'animaux"; break;
   case 2 : type = "Age moyen"; qualif = " jour"; break;
   case 3 : type = "Nombre de couples adultes"; break;
   case 4 : type = "Valeur réelle"; qualif = " Zoo'z"; break;
   case 5 : type = "Nombre de naissances"; type2 = "Théorie"; break;
   case 6 : type = "Nombre de naissances mâles"; type2 = "Nombre de naissances femelles"; break;
   case 7 : type = "Valeur des naissances"; qualif = " Zoo'z"; type2 = "Valeur théorique"; break;
   case 8 : type = "Valeur moyenne des naissances"; qualif = " Zoo'z"; type2 = "Valeur moyenne théorique"; 
  }
  var j = Math.ceil(deb+x*pas);
  if (iclic == 2 && parseFloat(extrait[j]) > 1) qualif += "s";
  var txt = "Date MAJ : " + dategr[j] + "<br />" + type + " : " + millier(extrait[j]) + qualif;
  if (iclic > 4) txt += "<br />" + type2 + " : " + millier(extrait2[j]) + qualif;
  var bdiv = $("bullegraphe");
  var bdiv2 = $("traitgraphe");
  if (!bdiv)
  { bdiv = document.createElement("div");
   bdiv.id = "bullegraphe";
   bdiv.setAttribute("style", "border:1px solid #000;z-index:999;display:block;position:absolute;background-color:#FFFFAA;" +
    "padding:3px;text-align:center;font-family:garamond arial sans serif;font-size:11px;color:#000044");
   document.body.appendChild(bdiv);
   bdiv2 = document.createElement("div");
   bdiv2.id = "traitgraphe";
   bdiv2.setAttribute("style", "border-left:1px solid #000;z-index:999;display:block;position:absolute;width:0px");
   document.body.appendChild(bdiv2);
  }
  bdiv.innerHTML = txt;
  bdiv.style.left = position($("casegraphe"))["x"] + 6 + x*pasx + "px";
  bdiv.style.top = sourisY - bdiv.clientHeight + "px";
  bdiv2.style.left = position($("casegraphe"))["x"] + 6 + x*pasx + "px";
  posgraphe = position($("casegraphe"))["y"] + YY + hauteurgraphique*(max2-extrait[j])/hy;
  if (iclic < 5)
  { if (sourisY <= posgraphe)
   { bdiv2.style.top = sourisY + "px";
    bdiv2.style.height = posgraphe - sourisY + "px";
   }
   else
   { bdiv2.style.top = posgraphe + "px";
    bdiv2.style.height = sourisY - posgraphe + "px";
   }
  }
  else
  { posgraphe2 = position($("casegraphe"))["y"] + YY + hauteurgraphique*(max2-extrait2[j])/hy;
   haut = Math.min(posgraphe, posgraphe2);
   bas = Math.max(posgraphe, posgraphe2);
   if (sourisY <= haut)
   { bdiv2.style.top = sourisY + "px";
    bdiv2.style.height = bas - sourisY + "px";
   }
   else if (sourisY >= bas)
   { bdiv2.style.top = haut + "px";
    bdiv2.style.height = sourisY - haut + "px";
   }
   else
   { bdiv2.style.top = haut + "px";
    bdiv2.style.height = bas - haut + "px";
   }
  }
 }
}

function filtre(coche)
{
 GM_setValue("filtre", coche);
 if (GM_getValue("clique", "") != "") souligne(GM_getValue("clique", ""), true);
}

function etroit(coche)
{
 var titre, titre2, j;
 GM_setValue("etroit", coche);
 if (GM_getValue("etroit", false))
 { titre = $c("titre");
  for (j=0;j<titre.length;j++) titre[j].innerHTML = titre[j].innerHTML.replace("&nbsp;", " <br>", "g");
  titre2 = $c("titre2");
  for (j=0;j<titre2.length;j++) titre2[j].innerHTML = titre2[j].innerHTML.replace("&nbsp;", " <br>", "g");
  titre3 = $c("titre3");
  for (j=0;j<titre3.length;j++) titre3[j].innerHTML = titre3[j].innerHTML.replace("&nbsp;", " <br>", "g");
 }
 else
 { titre = $c("titre");
  for (j=0;j<titre.length;j++) titre[j].innerHTML = titre[j].innerHTML.replace(" <br>", "&nbsp;", "g");
  titre2 = $c("titre2");
  for (j=0;j<titre2.length;j++) titre2[j].innerHTML = titre2[j].innerHTML.replace(" <br>", "&nbsp;", "g");
  titre3 = $c("titre3");
  for (j=0;j<titre3.length;j++) titre3[j].innerHTML = titre3[j].innerHTML.replace(" <br>", "&nbsp;", "g");
 }
 $("animaux_enclos").style.width = "";
 if ($("enclosavoir")) $("enclosavoir").style.right = $("animaux_enclos").clientWidth + 10 + "px";
 lien_enclos(true);
}

function affichertabanimaux(coche)
{
 GM_setValue("affichertabanimaux", coche);
 if (GM_getValue("affichertabanimaux", true)) $("tabanimaux").style.display = "";
 else $("tabanimaux").style.display = "none";
 $("animaux_enclos").style.width = "";
 if ($("enclosavoir")) $("enclosavoir").style.right = $("animaux_enclos").clientWidth + 10 + "px";
 lien_enclos(true);
}

function etroit2(coche)
{
 GM_setValue("etroit2", coche);
 lien_enclos(true);
}

function affichertabvieux()
{
 GM_setValue("affichertabvieux", !GM_getValue("affichertabvieux", true));
 if (GM_getValue("affichertabvieux", true))
  $("tabvieux").style.display = "";
 else $("tabvieux").style.display = "none";
 lien_enclos(true);
}

function affichertabanim()
{
 GM_setValue("affichertabanim", !GM_getValue("affichertabanim", true));
 if (GM_getValue("affichertabanim", true))
  $("tabanim").style.display = "";
 else $("tabanim").style.display = "none";
 lien_enclos(true);
}

function etroit3(coche)
{
 var animvieux, enclos, j;
 GM_setValue("etroit3", coche);
 if (GM_getValue("etroit3", false))
 { animvieux = $c("animvieux");
  for (j=0;j<animvieux.length;j++) animvieux[j].innerHTML = animvieux[j].innerHTML.replace("&nbsp;", " <br>", "g");
  enclos = $c("enclos");
  for (j=0;j<enclos.length;j++) enclos[j].innerHTML = enclos[j].innerHTML.replace("&nbsp;", " <br>", "g");
 }
 else
 { animvieux = $c("animvieux");
  for (j=0;j<animvieux.length;j++) animvieux[j].innerHTML = animvieux[j].innerHTML.replace(" <br>", "&nbsp;", "g");
  enclos = $c("enclos");
  for (j=0;j<enclos.length;j++) enclos[j].innerHTML = enclos[j].innerHTML.replace(" <br>", "&nbsp;", "g");
 }
 lien_enclos(true);
}

function filtre2(coche)
{
 GM_setValue("filtre2", coche);
 ok = $c("ok");
 if (ok)
 { if (GM_getValue("filtre2", false))
   for (i12=0;i12<ok.length;i12++) ok[i12].parentNode.style.display = "none";
  else
   for (i12=0;i12<ok.length;i12++) ok[i12].parentNode.style.display = "";
 }
 lien_enclos(true);
}

function etroit4(coche)
{
 var animvieux, enclos, j;
 GM_setValue("etroit4", coche);
 if (GM_getValue("etroit4", false))
 { animvieux = $c("espece");
  for (j=0;j<animvieux.length;j++) animvieux[j].innerHTML = animvieux[j].innerHTML.replace("&nbsp;", " <br>", "g");
  enclos = $c("enclos2");
  for (j=0;j<enclos.length;j++) enclos[j].innerHTML = enclos[j].innerHTML.replace("&nbsp;", " <br>", "g");
 }
 else
 { animvieux = $c("espece");
  for (j=0;j<animvieux.length;j++) animvieux[j].innerHTML = animvieux[j].innerHTML.replace(" <br>", "&nbsp;", "g");
  enclos = $c("enclos2");
  for (j=0;j<enclos.length;j++) enclos[j].innerHTML = enclos[j].innerHTML.replace(" <br>", "&nbsp;", "g");
 }
 lien_enclos(true);
}

function choixliste(numradio)
{
 page = /bourse.php/.test(window.location) ? "b" : "i";
 GM_setValue("choixliste" + page, numradio);
 if (GM_getValue("choixliste" + page, 1) == 1)
 { $("liste_anim1").style.display = "";
  $("liste_anim2").style.display = "none";
  $("radioanim").style.display = "none";
  $("liste_anim3").style.display = "none";
  $("liste_anim4").style.display = "none";
 }
 else if (GM_getValue("choixliste" + page, 1) == 2)
 { $("liste_anim1").style.display = "none";
  $("liste_anim2").style.display = "";
  $("radioanim").style.display = "";
  $("liste_anim3").style.display = "none";
  $("liste_anim4").style.display = "none";
 }
 else if (GM_getValue("choixliste" + page, 1) == 3)
 { $("liste_anim1").style.display = "none";
  $("liste_anim2").style.display = "none";
  $("radioanim").style.display = "";
  $("liste_anim3").style.display = "";
  $("liste_anim4").style.display = "none";
 }
 else
 { $("liste_anim1").style.display = "none";
  $("liste_anim2").style.display = "none";
  $("radioanim").style.display = "";
  $("liste_anim3").style.display = "none";
  $("liste_anim4").style.display = "";
 }
 lien_enclos();
}

function choixaffanim(numradio)
{
 GM_setValue("choixaffanim", numradio);
 if (GM_getValue("choixaffanim", 1) == 1)
 { pres = $c("présente");
  for(i12=0;i12<pres.length;i12++)
   pres[i12].style.display = "";
  abse = $c("absente");
  for(i12=0;i12<abse.length;i12++)
   abse[i12].style.display = "none";
 }
 else if (GM_getValue("choixaffanim", 1) == 2)
 { pres = $c("présente");
  for(i12=0;i12<pres.length;i12++)
   pres[i12].style.display = "none";
  abse = $c("absente");
  for(i12=0;i12<abse.length;i12++)
   abse[i12].style.display = "";
 }
 else
 { pres = $c("présente");
  for(i12=0;i12<pres.length;i12++)
   pres[i12].style.display = "";
  abse = $c("absente");
  for(i12=0;i12<abse.length;i12++)
   abse[i12].style.display = "";
 }
 lien_enclos();
}

function triesp(coche)
{
 GM_setValue("triesp", coche);
 if (coche)
 { if (!triespecesfait)
  { trier_espece();
   triespecesfait = true;
  }
  else papa.replaceChild(newdiv2, newdiv);
 }
 else
  papa.replaceChild(newdiv, newdiv2);
 clique = GM_getValue("clique", "");
 if (clique != "")
  typesel(GM_getValue("colonne", "tout"), true);
 else
 { GM_deleteValue("colonne");
  typesel("tout", true);
 }
 souligne(clique, true);
}

function trier_espece()
{
 for (i12=0;i12<especes_triees.length;i12++)
 { btd2 = $c("animal " + especes_triees[i12].replace(" ", "%20", "g"));
  for (j=0;j<btd2.length;j++)
  { clonetd = btd2[j].cloneNode(true);
   bimg = $t("img", clonetd);
   bimg[0].addEventListener("click", selvente, true);
   newdiv2.appendChild(clonetd);
  }
  nomclass = btd2[btd2.length-1].className;
  if (nomclass.indexOf("naissance") != -1) nomclass = "animal " + especes_triees[i12].replace(" ", "%20", "g") + " separation naissance";
  else if (nomclass.indexOf("mourant") != -1) nomclass = "animal " + especes_triees[i12].replace(" ", "%20", "g") + " separation mourant";
  else nomclass = "animal " + especes_triees[i12].replace(" ", "%20", "g") + " separation";
  if (i12 != especes_triees.length-1)
  { btd = document.createElement("td");
   btd.className = nomclass;
   btd.setAttribute("style","width:593px;margin:5px 0px;background-color:#FF8888;border:2px solid #B86242");
   newdiv2.appendChild(btd);
  }
 }
 papa.replaceChild(newdiv2, newdiv);
}

function onmouse(texte, naiss)
{
 if (!texte) texte = " ";
 if (!naiss) naiss = false;
 texte = new String(texte);
 var largeur;
 if (texte.indexOf("<br />") != -1) { texte2 = texte.substring(texte.indexOf("<br />")+6); ligne1 = 18; }
 else { texte2 = texte; ligne1 = 0; }
 if (texte2.indexOf("&nbsp;") != -1) texte2 = texte2.replace("&nbsp;"," ","g");
 mini = Math.max(450, 70 + texte2.length * Math.ceil(11800 / (window.innerHeight - ligne1)) / 100);
 taillecarac = '8pt';
 if (mini > window.innerWidth)
 { mini = Math.max(450, 70 + texte2.length * Math.ceil(8000 / (window.innerHeight - ligne1)) / 100);
  taillecarac = '7pt';
 }
 largeur = Math.min(mini, Math.ceil(texte2.length * 5.62));
 var mouse = "onmouseover=\"Tip('" + texte + "', ";
 if (!naiss) mouse += "WIDTH, " + largeur + ", ";
 mouse += "BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '" + taillecarac + "', ABOVE, 'true', TEXTALIGN, 'center')\" onmouseout=\"UnTip()\""
 return mouse;
}

function calculelargeur(texte)
{
 if (!texte) texte = " ";
 texte = new String(texte);
 var largeur;
 if (texte.indexOf("<br />") != -1) largeur = texte.substring(texte.indexOf("<br />")+6);
 else largeur = texte;
 if (largeur.indexOf("&nbsp;") != -1) largeur = largeur.replace("&nbsp;"," ","g");
 largeur = Math.min(450, Math.ceil(largeur.length * 7.0));
 return largeur;
}

function entete()
{
 var bdiv = $t("div"), i17;
 for (i17=20; i17<bdiv.length;i17++) if (bdiv[i17].attributes[0].value.indexOf("width: 125px") != -1) break;
 var nom = bdiv[i17].innerHTML;
 var zooz = bdiv[i17+1].innerHTML;
 var visiteurs = bdiv[i17+2].innerHTML;
 var barres = bdiv[i17+3].innerHTML;
 var barrerouge = barres.substring(barres.indexOf("width")+7,barres.indexOf("%"));
 barres = barres.substring(barres.indexOf("%")+1);
 var barrebleue = barres.substring(barres.indexOf("width")+7,barres.indexOf("%"));
 var points = bdiv[i17+6].innerHTML.trim();
 var rs="r";
 if (GM_getValue("suivi", "") != "") rs="s";
 return "nom="+nom+"&zooz="+zooz+"&visiteurs="+visiteurs+"&barrerouge="+barrerouge+"&barrebleue="+barrebleue+"&points="+points+"&rs="+rs;
}

function rapport()
{
 patience("");
 var data = entete();
 GM_xmlhttpRequest({
  method: "POST",
  url: "http://montdm.servhome.org/ScriptMonZoo/rapportnew.php",
  data: data,
  headers: {
   "Content-Type": "application/x-www-form-urlencoded"
  },
  onload: function(result) {
   if (result.status != 200) return;
   var contenupage = $c("content_site");
   contenupage[0].innerHTML = result.responseText;
   fenpat = $("patience");
   old = fenpat.parentNode.removeChild(fenpat);
   var btd=$t("td");
   btd[4].innerHTML="    ";
   if (!trouvaille) { GM_setValue("trouvaille", true); GM_setValue("string_trouvailles_"+id_zoo, ""); window.location.href = urlSite + "event.php"; }
   else 
   { if (!scan)
    { if (confirm("Souhaitez-vous vérifier et mettre à jour les PA de tous vos enclos ?"))
     { btd[4].innerHTML="Veuillez patienter, la vérification va démarrer.<br />Une fois terminée, le rapport s'affichera.";
      GM_setValue("scan", true);
      GM_deleteValue("enclos");
      var url = urlSite + "enclosgestion1.php?t=0&v=0";
      setTimeout('window.location.href = "' + url + '"',2000);
     }
     else { GM_deleteValue("trouvaille"); trouvaille = false; image_options(); modification_menu(); lien_enclos(false); affiche_rapport(false); }
    }
    else // le scan pour le rapport est terminé
    { GM_deleteValue("scan");
     scan = false;
     GM_deleteValue("trouvaille");
     trouvaille = false;
     image_options();
     modification_menu();
     lien_enclos(false);
     GM_setValue("rapport", "ok");
     affiche_rapport(true);
    }
   }
  }
 });
}

function suivi()
{
 patience("");
 var data = entete();
 var i18;
 GM_xmlhttpRequest({
  method: "POST",
  url: "http://montdm.servhome.org/ScriptMonZoo/rapportnew.php",
  //url: "http://scriptmonzoo.free.fr/rapport.php",
  data: data,
  headers: {
   "Content-Type": "application/x-www-form-urlencoded"
  },
  onload: function(result) {
   if (result.status != 200) return;
   var contenupage = $c("content_site");
   contenupage[0].innerHTML = result.responseText;
   GM_deleteValue("enclos");
   var exist = $("animaux_enclos");
   if (exist)
    old = exist.parentNode.removeChild(exist);
   exist = $("enclos_naissances");
   if (exist)
    old = exist.parentNode.removeChild(exist);
   exist = $("tableau_vieux");
   if (exist)
    old = exist.parentNode.removeChild(exist);
   exist = $("tableau_animaux");
   if (exist)
    old = exist.parentNode.removeChild(exist);
   fenpat = $("patience");
   old = fenpat.parentNode.removeChild(fenpat);
   if (GM_getValue("suivi", "") == "ok2") lien_enclos();
   analyse_suivi();
   var btd = $t("td");
   btd[4].innerHTML="";
   largeurgraphique = btd[4].clientWidth-10;
   hauteurgraphique = btd[4].clientWidth*0.82;
   var bdiv = document.createElement("div"), choix, txt;
   bdiv.id = "type_trace";
   bdiv.setAttribute("class", "bloc_graphe");
   liste = document.createElement("select");
   liste.setAttribute("style", "background-color:#F7E3C0");
   liste.name = "choix_trace";
   liste.id = "choix_trace";
   for (i18=1;i18<=8;i18++)
   { choix = document.createElement("option");
    choix.value = i18;
    switch (i18)
    { case 1:
      choix.innerHTML = "Suivi du nombre d'animaux";
      break;
     case 2:
      choix.innerHTML = "Suivi de l'âge moyen des animaux";
      break;
     case 3:
      choix.innerHTML = "Suivi du nombre de couples adultes";
      break;
     case 4:
      choix.innerHTML = "Suivi de la valeur réelle du zoo";
      break;
     case 5:
      choix.innerHTML = "Suivi des naissances (marron) et des naissances théoriques (bleu)";
      break;
     case 6:
      choix.innerHTML = "Suivi des naissances mâles (marron) et des naissances femelles (bleu)";
      break;
     case 7:
      choix.innerHTML = "Suivi de la valeur des naissances (marron) et de la théorie (bleu)";
      break;
     case 8:
      choix.innerHTML = "Suivi de la valeur moyenne des naissances (marron) et de la théorie (bleu)";
    }
    liste.appendChild(choix);
   }
   liste.addEventListener('change', graphique, true);
   bdiv.appendChild(liste);
   ajoute_br(bdiv);
   btd[4].appendChild(bdiv);
   var bhr = document.createElement("hr");
   bhr.setAttribute("class", "separateur");
   btd[4].appendChild(bhr);
   bdiv=document.createElement("div");
   bdiv.id = "titre_trace";
   bdiv.setAttribute("class", "bloc_rapport");
   bdiv.setAttribute("style", "color:#B86242;font-weight:bold;");
   btd[4].appendChild(bdiv);
   graphique(btd);
   var bimg = $t("img");
   window.scroll(0, position(bimg[bimg.length-1])["y"]);
   if (GM_getValue("suivi", "") == "ok") { GM_setValue("suivi", "ok2"); suivi(); }
   else GM_deleteValue("suivi");
  }
 });
}

function patience(typem) // fenêtre pour patienter
{
 var div = document.createElement("div");
 div.id = "patience";
 div.className = "info_bulle";
 if (typem == "PA")
 { var totalPA = GM_getValue("totalPA");
  var n = totalPA.substring(4,totalPA.indexOf("r"));
  var n1 = n.substring(1,n.indexOf(" su"));
  n1 = parseInt(n1)+1;
  n1 = "e " + n1 + " su";
  totalPA = totalPA.replace(n, n1);
  inner = "Suppression des PA en trop :</h2></span><span>" + totalPA;
  GM_setValue("totalPA", totalPA);
 }
 else if (typem == "enchere")
 { tentative = 6 - parseInt(GM_getValue("encherir_"+nom, 1));
  div.style.top = window.innerHeight / 3 + "px";
  inner = "Tentative n° " + tentative + " non nécessaire :<br />vous êtes déjà le meilleur enchérisseur.</h2>";
 }
 else inner = "Veuillez patienter, connection en cours...</h2>";
 div.innerHTML = "<span><h2 style=\"text-align:center;font-size:14px;;color:#B86242\">" + inner + "</span>";
 document.body.appendChild(div);
}

function enregistreachat()
{
 var listeachat = unserialize(GM_getValue("string_achats_"+id_zoo, ""));
 var nom_achat = GM_getValue("temp_achat", "");
 if (ANIMAUX[nom_achat])
 { GM_setValue("compteur_achats_"+id_zoo, GM_getValue("compteur_achats_"+id_zoo, 0) + 1);
  if (GM_getValue("constructionenclos", false))
   GM_setValue("maxachats_"+id_zoo, parseInt(GM_getValue("maxachats_"+id_zoo, 20)) + 1);
  if (!listeachat[0])
  { listeachat[0] = new Array();
   listeachat[0][0] = nom_achat;
   listeachat[0][1] = 1;
  }
  else
  { temoin = false;
   for (i=0; i<listeachat[0].length; i+=2)
    if (listeachat[0][i] == nom_achat) { temoin = true; listeachat[0][i+1] = parseInt(listeachat[0][i+1]) + 1; }
   if (!temoin)
   { listeachat[0][i] = nom_achat;
    listeachat[0][i+1] = 1;
   }
  }
  GM_setValue("string_achats_"+id_zoo, serialize(listeachat));
  GM_deleteValue("constructionenclos");
  if (GM_getValue("cherchebonus", "") == "") GM_setValue("testerbonus", true);
 }
 else
  alert("Il ne sert à rien de cliquer 2 fois sur un bouton : un bouton marche comme une touche de clavier ou une touche de votre télécommande, un seul clic suffit.\n2 clics provoquent une erreur de frappe, vous font arriver sur une mauvaise chaîne de TV, ou vous affichent un message qui ne vous plaît pas forcément !");
 GM_deleteValue("temp_achat");
}

function enregistrevente()
{
 var listevente = unserialize(GM_getValue("string_ventes_"+id_zoo, ""));
 var nom_vente = GM_getValue("temp_vente", "");
 if (ANIMAUX[nom_vente])
 { if (!listevente[0])
  { listevente[0] = new Array();
   listevente[0][0] = nom_vente;
   listevente[0][1] = 1;
  }
  else
  { temoin = false;
   for (i=0; i<listevente[0].length; i+=2)
    if (listevente[0][i] == nom_vente) { temoin = true; listevente[0][i+1] = parseInt(listevente[0][i+1]) + 1; }
   if (!temoin)
   { listevente[0][i] = nom_vente;
    listevente[0][i+1] = 1;
   }
  }
  GM_setValue("string_ventes_"+id_zoo, serialize(listevente));
 }
 else
  alert("Il ne sert à rien de cliquer 2 fois sur un bouton : un bouton marche comme une touche de clavier ou une touche de votre télécommande, un seul clic suffit.\n2 clics provoquent une erreur de frappe, vous font arriver sur une mauvaise chaîne de TV, ou vous affichent un message qui ne vous plaît pas forcément !");
 GM_deleteValue("temp_vente");
}

function encherenormale()
{
 if (encherisseur == nom_zoo)
 { alert("Vous êtes déjà le meilleur enchérisseur !");
  subm = document.getElementsByName("propose");
  subm[0].value = "";
 }
 else
 { valeur = document.getElementsByName("propose");
  valeur = valeur[0].value;
  enchere = unserialize(GM_getValue("enchere_"+id_zoo, ""));
  enchere[nom] = valeur;
  GM_setValue("enchere_"+id_zoo, serialize(enchere));
 }
}

function encherir()
{
 if (encherisseur == nom_zoo) alert("Vous êtes déjà le meilleur enchérisseur !");
 else
 { nvprix = prix + 1;
  binput = $t("input", btable);
  binput[1].value = nvprix;
  enchere = unserialize(GM_getValue("enchere_"+id_zoo, ""));
  enchere[nom] = nvprix;
  GM_setValue("enchere_"+id_zoo, serialize(enchere));
  binput[2].dispatchEvent(clickmouse);
 }
}

function encherir5()
{
 bstrong = $t("strong");
 message = bstrong[8].innerHTML;
 if (message.indexOf("Votre enchère n'a pas ") == -1)
 { binput = $t("input", btable);
  var enchere = new Array();
  if (GM_getValue("encherir_"+nom, "") == "")
  { GM_setValue("encherir_"+nom, 5);
   encheremaxi[nom] = binput[5].value;
   GM_setValue("encheremaxi_"+id_zoo, serialize(encheremaxi));
  }
  else GM_setValue("encherir_"+nom, parseInt(GM_getValue("encherir_"+nom))-1);
  if (parseInt(GM_getValue("encherir_"+nom)) == 1) GM_deleteValue("encherir_"+nom);
  var nvprix = prix + 1;
  enchere = unserialize(GM_getValue("enchere_"+id_zoo, ""));
  if (encheremaxi[nom] > 0)
  { if (nvprix <= encheremaxi[nom] && encherisseur != nom_zoo)
   { binput[1].value = nvprix;
    enchere[nom] = nvprix;
    GM_setValue("enchere_"+id_zoo, serialize(enchere));
    binput[2].dispatchEvent(clickmouse);
   }
   else if (nvprix > encheremaxi[nom])
   { alert("Enchère maxi atteinte : arrêt des enchères");
    GM_deleteValue("encherir_"+nom);
    window.location.href = window.location;
   }
   else
   { patience("enchere");
    window.location.href = window.location;
   }
  }
  else
  { if (encherisseur != nom_zoo)
   { binput[1].value = nvprix;
    enchere[nom] = nvprix;
    GM_setValue("enchere_"+id_zoo, serialize(enchere));
    binput[2].dispatchEvent(clickmouse);
   }
   else
   { patience("enchere");
    window.location.href = window.location;
   }
  }
 }
 else
 { message = message.substring(message.indexOf("Votre prop"));
  message = message.replace(", ", ",\n", "g");
  alert("L'enchère précédente a échoué pour la raison suivante :\n\"" + message +".\"\n\nArrêt des enchères.");
  GM_deleteValue("encherir_"+nom);
  window.location.href = window.location;
 }
}

function sauveencheremaxi()
{
 binput = $t("input", btable);
 encheremaxi = unserialize(GM_getValue("encheremaxi_"+id_zoo, ""));
 encheremaxi[nom] = binput[5].value;
 GM_setValue("encheremaxi_"+id_zoo, serialize(encheremaxi));
}

function liensmusee()
{
 GM_setValue("liensmusee", !GM_getValue("liensmusee", true));
 window.location.href = window.location;
}

function sauvemaxi()
{
 var maxi = $c("maxi");
 var couples15 = unserialize(GM_getValue("couples15_" + id_zoo, "")), newcouples15 = new Array;
 var numenclos = parseInt(recherche_param(window.location.href, "t")) * 100 + parseInt(recherche_param(window.location.href, "v"));
 for (i19 in couples15)
 { i19 = parseInt(i19);
  if (i19 != numenclos) newcouples15[i19] = couples15[i19];
 }
 for (i19=0;i19<maxi.length;i19++)
 { espece = maxi[i19].name;
  animmax = maxi[i19].value;
  animauxmax[espece] = animmax;
  if (enclos[espece][4] > animmax || enclos[espece][5] > animmax)
  { if (!newcouples15[numenclos])
    newcouples15[numenclos] = new Array();
   j = newcouples15[numenclos].length;
   newcouples15[numenclos][j] = espece;
   newcouples15[numenclos][j+1] = enclos[espece][4] > animmax ? enclos[espece][4] - animmax : 0;
   newcouples15[numenclos][j+1] += enclos[espece][5] > animmax ? enclos[espece][5] - animmax : 0;
  }
 }
 GM_setValue("animauxmax_"+id_zoo, serialize(animauxmax));
 GM_setValue("couples15_" + id_zoo, serialize(newcouples15));
 tableau_animaux(enclos);
 alert("Les valeurs maxi ont été sauvegardées.");
}

function selvente(e)
{
 e.target.parentNode.style.opacity = e.target.parentNode.style.opacity == "0.5" ? "1": "0.5";
 e.target.parentNode.className = e.target.parentNode.style.opacity == "0.5" ? "vente "+ e.target.parentNode.className : e.target.parentNode.className.replace("vente ", "");
}

function ventemulti()
{
 var bvente = $c("vente");
 GM_setValue("retour", window.scrollY);
 if (bvente.length > 0)
 { var listevente = new Array(), liste = unserialize(GM_getValue("liste"));
  if (bvente.length > 1)
  { var touslesenclos = unserialize(GM_getValue("touslesenclos_" + id_zoo, ""));
   for (i20 in touslesenclos)
   { if (touslesenclos[i20].indexOf("anima") != -1) touslesenclos[i20] = parseInt(touslesenclos[i20].substring(0, touslesenclos[i20].indexOf(" anima")));
    else if (touslesenclos[i20].indexOf("Vide") != -1) touslesenclos[i20] = 0;
    else touslesenclos[i20] = 1000;
   }
   var tableau1 = new Array(), tableau2 = new Array();
   for (i20 in touslesenclos) { tableau1.push(parseInt(touslesenclos[i20])); tableau2[touslesenclos[i20]] = i20; }

   tableau1.sort(function (a, b) { return a - b; });
   enclosmini = tableau2[tableau1[0]];
   var txt = urlSite + "vente_animaux.php?t=";
   txt += Math.floor(enclosmini/100) + "&v=";
   enclosmini = enclosmini - Math.floor(enclosmini/100)*100;
   txt += enclosmini + "&vtemp=";
   ba = $t("a", bvente[0]);
   txt += recherche_param(ba[0].href, "vtemp") + "&ids=";
   message = "Liste des animaux à vendre :\n";
  }
  else message = "Vous avez sélectionné un seul animal à vendre :\n";
  for (i20=0;i20<bvente.length;i20++)
  { ba = $t("a", bvente[i20]);
   if (i20 == bvente.length - 1) listevente.push(ba[0].href);
   else listevente.push(txt + recherche_param(ba[0].href, "ids"));
  }
  GM_setValue("listevente", serialize(listevente));
  for (i20=0;i20<listevente.length;i20++)
  { num = recherche_param(listevente[i20], "ids");
   message += "- " + liste[num] + "\n";
  }
  message += "\nConfimez-vous votre choix ?";
  if (confirm(message))
  { firstvente = listevente.shift();
   GM_setValue("listevente", serialize(listevente));
   GM_setValue("venteauto", true);
   window.location.href = firstvente;
  }
  else GM_deleteValue("listevente");
 }
 else alert("Vous n'avez sélectionné aucun animal :\ncliquez sur les animaux que vous souhaitez vendre\navant de recliquer sur ce bouton");
}

function enclosprecedent()
{
 var txt = urlSite + "enclosgestion1.php?t=";
 txt += Math.floor(avant/100) + "&v=";
 avant = avant - Math.floor(avant/100)*100;
 txt += avant;
 GM_setValue("bebes","ok");
 window.location.href = txt;
}

function enclossuivant()
{
 var txt = urlSite + "enclosgestion1.php?t=";
 txt += Math.floor(apres/100) + "&v=";
 apres = apres - Math.floor(apres/100)*100;
 txt += apres;
 GM_setValue("bebes","ok");
 window.location.href = txt;
}

function boutique()
{
 GM_setValue("boutique", true);
 window.location.href = urlSite + "enclosgestion.php?v=" + v + "&t=4&achat=100";
}

function MAJPA(e)
{
 var lienmaj = e.target; // lien pour mettre à jour tous les PA d'un coup
 var btable = $t("table"), last_tablebureau, i21;
 for (i21=btable.length-1;i21>=0;i21--)
  if (btable[i21].getAttribute("cellpadding") == 4) { last_tablebureau = btable[i21]; break; }
 var btd = $t("td", last_tablebureau);
 var PAdispo = new Array(), PAplus = new Array(), PA1 = new Array();
 for (i21=0;i21<5;i21++)
 { PAplus[i21] = 0;
  PAdispo[i21] = parseInt(btd[i21].innerHTML.substring(btd[i21].innerHTML.indexOf("PA dispo :")+11, btd[i21].innerHTML.indexOf("</strong")));
 }
 for (i21=8;i21<btd.length;i21+=8) // contrôle des PA
  PA1[i21/8-1] = parseInt(btd[i21].innerHTML.substring(0, btd[i21].innerHTML.indexOf("<br>")));
 for (i21=8;i21<btd.length;i21+=8) // contrôle des PA
 { if (btd[i21+3].innerHTML.indexOf("<br>") == -1) PA2=parseInt(btd[i21+3].innerHTML);
  else PA2=parseInt(btd[i21+3].innerHTML.substring(0, btd[i21+3].innerHTML.indexOf("<br>")));
  j = i21/8-1;
  if (j==0 && PA2 == 0)
  { if (PA1[1] != "0" || PA1[2] != "3" || PA1[3] != "0" || PA1[4] != "5")
   { btd[35].innerHTML = 4; GM_setValue("MAJPA2", true); GM_setValue("retour", window.scrollY); }
  }
  if (PA1[j] > PA2) bad = true;
  if (PA1[j] < PA2)
  { bad = true;
   PAplus[j] = Math.max(Math.ceil((PA2-PA1[j]-PAdispo[j])/10), 0);
  }
 }
 if (bad) // si les PA sont incorrects, on corrige en embauchant éventuellement
 { if (PAplus[0]+PAplus[1]+PAplus[2]+PAplus[3]+PAplus[4] == 0) // pas besoin d'embaucher
   e.target.href = lienmaj;
  else
  { var lienplus = urlSite + "bureau.php?achat=1&j="; // lien pour embaucher
   for (i21=0;i21<5;i21++)
   { if (PAplus[i21]>0)
    { lienplus += i21+1;
     PAplus[i21] += -1;
     GM_setValue("plus",serialize(PAplus));
     GM_setValue("enclos", t+"_"+v);
     GM_setValue("MAJPA", true);
     GM_setValue("retour", window.scrollY);
     e.target.href = lienplus;
     break;
    }
   }
  }
 }
 else
 { alert("il n'était pas nécessaire de cliquer ici : tous les PA sont déjà corrects");
  newtarget = urlSite + "enclosgestion1.php?t=" + t + "&v=" + v;
  GM_setValue("retour", window.scrollY);
  e.target.href = newtarget;
 }
}




// début du script
var monSite = 'http://userscripts.org/scripts/source/63727.user.js';
var urlSite = 'http://www.monzoo.net/';
var p_affichage = parseInt(GM_getValue("p_affichage", 1)); // préférences pour entourer les animaux
var largeur_ecran = window.innerWidth;
var nom_zoo, id_zoo, num_zoo;
var newdiv, newdiv2, avant, apres;
var deb, pas, pasx, iclic, extrait, extrait2, dategr, max2, hy;
if(/monzoo.net/.test(window.location))
{ var bdiv = $t("div");
 for(i=0;i<bdiv.length;i++)
  if (bdiv[i].innerHTML.indexOf("livecount.fr") != -1) lasti = i;
 bdiv[lasti].parentNode.removeChild(bdiv[lasti]);
}
var tab_suivi = new Array(), imax, largeurgraphique, hauteurgraphique;
var min = new decompose("1/1/2010:-1/-1/-1/-1,-1/-1,-1/-1,-1/-1;-1/-1;");
var max = new decompose("1/1/2010:-1/-1/-1/-1,-1/-1,-1/-1,-1/-1;-1/-1");
var aujourd_hui = GM_getValue("aujourd_hui", "");
var liste_zoo = GM_getValue("liste_zoo", ""); // liste des zoos sur ce PC
if (liste_zoo != "") tab_zoo = unserialize(liste_zoo);
else tab_zoo = new Array();
GM_deleteValue("rapport"); // si en cours de jeu la variable existe, c'est qu'on est sur la page rapport
GM_deleteValue("enclosconstruits_1");
GM_addStyle(".info_bulle {border:3px solid #000;-moz-border-radius:10px;z-index:999;display:block;position:absolute;background-color:#F7E3C0;" +
 "padding:3px;font-family:garamond arial sans serif;font-size:12px;}");
GM_addStyle("#options {width:300px;;z-index:9999;}" +
 "#options h4{color:#B86242;margin-top:8px;margin-bottom:2px;}");
GM_addStyle(".bloc_rapport {width:100%;margin:4px;text-align:center;}");
GM_addStyle(".bloc_rapport h6{font-size:16px;margin:4px;text-decoration:underline;color:#000}");
GM_addStyle(".bloc_rapport h5{font-size:13px;margin:4px;text-decoration:underline;color:#000}");
GM_addStyle(".bloc_rapport span{font-weight:bold;font-size:11px;padding:8px;}");
GM_addStyle(".bloc_rapport span a{font-size:11px;margin:8px;}");
GM_addStyle("#suivi {border-collapse:collapse}");
GM_addStyle(".separateur {width:50%;margin-top:20px;margin-bottom:20px;}");
GM_addStyle(".attention {color:#FA2104;}");
GM_addStyle(".bonus {color:#1bb86c;}" +
 ".cher {color:#2732c7;}" +
 ".albinos {color:#31b9E4;}" +
 ".attention {color:#FA2104;}");
GM_addStyle(".filtre {background-color:#B86242;}");
GM_addStyle(".filtre_mâle {background-color:#8888FF;}");
GM_addStyle(".filtre_femelle {background-color:#FF8888;}");
GM_addStyle(".animal {float:left;width:92px;align:center;border:2px solid #F7E3C0;}");
GM_addStyle("#animaux_enclos {padding:4px;font-size:11px;position:fixed;cursor:default;overflow-y:auto;}" +
 "#liste_animaux {border-collapse:collapse;text-align:center;border:1px solid #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#liste_animaux .sel{background-color:#B86242;color:#fff4d0;}" +
 "#liste_animaux .nsel{cursor:help;background-color:#F7E3C0;color:#000000;height:30px;}" +
 "#liste_animaux .nsel2{background-color:#F7E3C0;color:#000000;}" +
 "#liste_animaux td, #liste_animaux th{border:1px solid #000000;padding:2px;}" +
 "#liste_animaux .titre{cursor:help;text-align:center;font-size:11px;color:#000000;}" +
 "#liste_animaux .titre2{cursor:help;text-align:center;font-size:11px;background-color:#B86242;color:#fff4d0;}" +
 "#liste_animaux .titre3{text-align:center;font-size:11px;}" +
 "#liste_animaux .mâle{font-family:Arial;font-size:11px;color:#394AE2;text-align:center;width:24px}" +
 "#liste_animaux .femelle{font-family:Arial;font-size:11px;color:#A016ba;text-align:center;width:24px}" +
 "#liste_animaux .mâle span, #liste_animaux .femelle span{font-size:10px;font-weight:normal}" +
 "#liste_animaux .trop{background-color:#CCC}" +
 "#liste_animaux tr.desequilibre{background-color:#eac893;}" +
 "#liste_animaux td.animourant{background-color:#f00;}");
GM_addStyle("#enclosavoir {padding:4px;font-size:11px;position:fixed;cursor:default;overflow-y:auto;}");
GM_addStyle("#tableau_vieux {padding:4px;font-size:11px;position:fixed;cursor:default;overflow-y:auto;}" +
 "#liste_vieux {border-collapse:collapse;text-align:center;border:1px solid #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#liste_vieux td, #liste_vieux th{border:1px solid #000000;padding:2px;}" +
 "#liste_vieux th{background-color:#eac893;height:30px}" +
 "#liste_vieux tr.savane{background-color:#FEE58C}" +
 "#liste_vieux tr.bassin{background-color:#8AC3FF}" +
 "#liste_vieux tr.terre{background-color:#98E586}" +
 "#liste_vieux tr.forêt{background-color:#6BD949}" +
 "#liste_vieux tr.volière{background-color:#FAFFFE}" +
 "#liste_vieux tr.aquarium{background-color:#A1E9FF}" +
 "#liste_vieux tr.vivarium{background-color:#CBBE7C}" +
 "#liste_vieux tr.noctarium{background-color:#A4C0BD}" +
 "#liste_vieux tr.insectarium{background-color:#D47F3F}" +
 "#liste_vieux a.insectarium{color:#FFF}" +
 "#liste_vieux .mâle{font-family:Arial;font-size:11px;color:#394AE2;text-align:center;width:24px}" +
 "#liste_vieux .femelle{font-family:Arial;font-size:11px;color:#A016ba;text-align:center;width:24px}" +
 "#liste_vieux .mâle span, #liste_vieux .femelle span{font-size:10px;font-weight:normal}" +
 "#liste_vieux td.insuffisant{background-color:#f44;color:#fff}" +
 "#liste_vieux td.insuffisant span{background-color:#f44;color:#fff;font-size:11px}");
GM_addStyle("#tableau_animaux {padding:4px;font-size:11px;position:fixed;cursor:default;overflow-y:auto;}" +
 "#liste_anim1 {border-collapse:collapse;text-align:center;border:1px solid #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#liste_anim1 td, #liste_anim1 th{border:1px solid #000000;padding:2px;}" +
 "#liste_anim1 th{background-color:#eac893;height:30px}" +
 "#liste_anim1 tr.savane{background-color:#FEE58C}" +
 "#liste_anim1 tr.bassin{background-color:#8AC3FF}" +
 "#liste_anim1 tr.terre{background-color:#98E586}" +
 "#liste_anim1 tr.forêt{background-color:#6BD949}" +
 "#liste_anim1 tr.volière{background-color:#FAFFFE}" +
 "#liste_anim1 tr.aquarium{background-color:#A1E9FF}" +
 "#liste_anim1 tr.vivarium{background-color:#CBBE7C}" +
 "#liste_anim1 tr.noctarium{background-color:#A4C0BD}" +
 "#liste_anim1 tr.insectarium{background-color:#D47F3F}" +
 "#liste_anim1 a.insectarium{color:#FFF}" +
 "#liste_anim1 .mâle{font-family:Arial;font-size:11px;color:#394AE2;text-align:center;width:24px}" +
 "#liste_anim1 .femelle{font-family:Arial;font-size:11px;color:#A016ba;text-align:center;width:24px}" +
 "#liste_anim2 {border-collapse:collapse;text-align:center;border:1px solid #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#liste_anim2 td, #liste_anim2 th{border:1px solid #000000;padding:2px;}" +
 "#liste_anim2 th{background-color:#eac893;height:30px}" +
 "#liste_anim2 tr.savane{background-color:#FEE58C}" +
 "#liste_anim2 tr.bassin{background-color:#8AC3FF}" +
 "#liste_anim2 tr.terre{background-color:#98E586}" +
 "#liste_anim2 tr.forêt{background-color:#6BD949}" +
 "#liste_anim2 tr.volière{background-color:#FAFFFE}" +
 "#liste_anim2 tr.aquarium{background-color:#A1E9FF}" +
 "#liste_anim2 tr.vivarium{background-color:#CBBE7C}" +
 "#liste_anim2 tr.noctarium{background-color:#A4C0BD}" +
 "#liste_anim2 tr.insectarium{background-color:#D47F3F}" +
 "#liste_anim2 a.insectarium{color:#FFF}" +
 "#liste_anim2 .mâle{font-family:Arial;font-size:11px;color:#394AE2;text-align:center;width:24px}" +
 "#liste_anim2 .femelle{font-family:Arial;font-size:11px;color:#A016ba;text-align:center;width:24px}" +
 "#liste_anim3 {border-collapse:collapse;text-align:center;border:1px solid #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#liste_anim3 td, #liste_anim3 th{border:1px solid #000000;padding:2px;}" +
 "#liste_anim3 th{background-color:#eac893;height:30px}" +
 "#liste_anim3 tr.savane{background-color:#FEE58C}" +
 "#liste_anim3 tr.bassin{background-color:#8AC3FF}" +
 "#liste_anim3 tr.terre{background-color:#98E586}" +
 "#liste_anim3 tr.forêt{background-color:#6BD949}" +
 "#liste_anim3 tr.volière{background-color:#FAFFFE}" +
 "#liste_anim3 tr.aquarium{background-color:#A1E9FF}" +
 "#liste_anim3 tr.vivarium{background-color:#CBBE7C}" +
 "#liste_anim3 tr.noctarium{background-color:#A4C0BD}" +
 "#liste_anim3 tr.insectarium{background-color:#D47F3F}" +
 "#liste_anim3 a.insectarium{color:#FFF}" +
 "#liste_anim3 .mâle{font-family:Arial;font-size:11px;color:#394AE2;text-align:center;width:24px}" +
 "#liste_anim3 .femelle{font-family:Arial;font-size:11px;color:#A016ba;text-align:center;width:24px}" +
 "#liste_anim4 {border-collapse:collapse;text-align:center;border:1px solid #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#liste_anim4 td, #liste_anim4 th{border:1px solid #000000;padding:2px;}" +
 "#liste_anim4 th{background-color:#eac893;height:30px}" +
 "#liste_anim4 tr.savane{background-color:#FEE58C}" +
 "#liste_anim4 tr.bassin{background-color:#8AC3FF}" +
 "#liste_anim4 tr.terre{background-color:#98E586}" +
 "#liste_anim4 tr.forêt{background-color:#6BD949}" +
 "#liste_anim4 tr.volière{background-color:#FAFFFE}" +
 "#liste_anim4 tr.aquarium{background-color:#A1E9FF}" +
 "#liste_anim4 tr.vivarium{background-color:#CBBE7C}" +
 "#liste_anim4 tr.noctarium{background-color:#A4C0BD}" +
 "#liste_anim4 tr.insectarium{background-color:#D47F3F}" +
 "#liste_anim4 a.insectarium{color:#FFF}" +
 "#liste_anim4 .mâle{font-family:Arial;font-size:11px;color:#394AE2;text-align:center;width:24px}" +
 "#liste_anim4 .femelle{font-family:Arial;font-size:11px;color:#A016ba;text-align:center;width:24px}");
GM_addStyle("#lien_enclos {padding:4px;font-size:10px;position:fixed;overflow-y:auto;;z-index:90;}" +
 "#liste_enclos {border-collapse:collapse;border:4px double #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#liste_enclos td{border:1px solid #000000;padding:2px;text-align:center;}" +
 "#liste_enclos td.manque{border:1px solid #000000;padding:2px;text-align:center;color:#B86242;cursor:help;}" +
 "#liste_enclos .avoir{background-color:#CCC;}" +
 "#liste_enclos .encours{background-color:#B86242;color:#FFF}" +
 "#liste_enclos a.encours{color:#FFF;}" +
 "#liste_enclos a.un{color:#B86242;}" +
 "#liste_enclos .separe{border-top:4px double;}");
GM_addStyle("#lien_autres {padding:4px;font-size:13px;position:fixed;overflow-y:auto;;z-index:90;}" +
 "#autres {border-collapse:collapse;border:4px double #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#autres td{border:1px solid #000000;padding:2px;text-align:center;}" +
 "#autres .rapport{color:#634425;}" +
 "#autres .separe{border-top:4px double;}" +
 "#mespoints {cursor:pointer;}" +
 "#prestige {cursor:pointer;}" +
 "#rapportsc {cursor:pointer;}" +
 "#suivisc {cursor:pointer;}" +
 "#intendance {cursor:pointer;}" +
 "#mateam {cursor:pointer;}");
GM_addStyle("#lien_deplacement {padding:4px;font-size:13px;position:fixed;}" +
 "#deplacement {border-collapse:collapse;border:4px double #000000;background-color:#F7E3C0;font-weight:bold;}" +
 "#deplacement td{border:1px solid #000000;padding:2px;text-align:center;}");
GM_addStyle("#enclos_naissances {padding:4px;font-size:13px;position:fixed;overflow-y:auto}" +
 "#table_enclos {border-collapse:collapse;border:4px double #000000;background-color:#F7E3C0;font-weight:bold;width:100%}" +
 "#table_enclos td{border:1px solid #000000;padding:4px;text-align:center;}");
GM_addStyle(".fenetre {border:3px solid #000;-moz-border-radius:10px;z-index:500000;display:block;position:absolute;background-color:#EEF1F1;" +
  "padding:5px;font-family:garamond arial sans serif;font-size:12px;}");
GM_addStyle("#lien_forum {padding:4px;font-size:14px;position:fixed;}" +
 "#forum {border-collapse:collapse;border:4px double #000000;background-color:#F2F6F6;font-weight:bold;}" +
 "#forum td{border:1px solid #000000;padding:2px;text-align:center;}");
_left = (largeur_ecran - 550) / 2;
_left2 = (largeur_ecran - 520) / 2;
_left3 = (largeur_ecran - 500) / 2;
_left4 = (largeur_ecran - 350) / 2;
GM_addStyle("#attraction {top:40px;left:" + _left + "px;width:550px;z-index:999;}");
GM_addStyle("#tornade {top:60px;left:" + _left2 + "px;width:520px;z-index:150;}");
GM_addStyle("#conseil {top:80px;left:" + _left3 + "px;width:500px;z-index:100;background-color:#F7E3C0}");
GM_addStyle("#news {top:100px;left:" + _left4 + "px;width:350px;z-index:50;background-color:#F7E3C0}");
GM_addStyle(".bloc_graphe{width:100%;margin:4px;text-align:center;position:relative;font-size:12px;}");
GM_addStyle(".naissance {border:2px solid #0f0;}");
GM_addStyle(".mourant {border:2px solid #f00;}");
GM_addStyle(".vieux {border:2px solid #00f;}");
_left = (largeur_ecran - 250) / 2;
GM_addStyle("#patience {top:40px;left:" + _left + "px;width:250px;position:fixed;text-align:center}");
GM_addStyle(".lien_naissances {cursor:pointer;float:left;margin-right:10px;font-size:10px;font-weight:bold;}" +
 ".lien_naissances a {color:navy;}" +
 ".lien_naissances a:hover {color:#3399CC;}" +
 "hr.spacer {clear:both;height:1px;visibility:hidden;}");

var ANIMAUX = new Array();ANIMAUX['dendrobate a ventre tachete'] = new Animal(2500000, 'Terre');ANIMAUX['colocolo'] = new Animal(1500000, 'Forêt', '', '', '', true);ANIMAUX['shagya criniere de feu'] = new Animal(1000000, 'Terre');
ANIMAUX['dugong'] = new Animal(750000, 'Bassin');ANIMAUX['tigre blanc'] = new Animal(500000, 'Forêt', '', '', true);ANIMAUX['hippocampe divin'] = new Animal(500000, 'Aquarium', true);ANIMAUX['gorfou a crete'] = new Animal(500000, 'Bassin');
ANIMAUX['phoque'] = new Animal(400000, 'Bassin');ANIMAUX['loup rouge'] = new Animal(400000, 'Forêt', '', '', true);ANIMAUX['douc a queue rayee'] = new Animal(400000, 'Forêt');ANIMAUX['panda'] = new Animal(350000, 'Forêt');
ANIMAUX['once'] = new Animal(350000, 'Terre', '', '', true, true);ANIMAUX['poisson clown divin'] = new Animal(350000, 'Aquarium');ANIMAUX['beluga'] = new Animal(300000, 'Bassin', '', '', true);ANIMAUX['tamandua'] = new Animal(300000, 'Forêt', '', '', '', true);
ANIMAUX['hyene'] = new Animal(300000, 'Savane', '', '', true);ANIMAUX['narval'] = new Animal(300000, 'Bassin', true);ANIMAUX['crabe percussionniste'] = new Animal(300000, 'Aquarium');ANIMAUX['fossa'] = new Animal(275000, 'Forêt', '', '', true);
ANIMAUX['koala'] = new Animal(250000, 'Forêt');ANIMAUX['dik dik zebre'] = new Animal(245000, 'Savane');ANIMAUX['unau'] = new Animal(230000, 'Forêt');ANIMAUX['dragon de komodo'] = new Animal(230000, 'Vivarium');
ANIMAUX['fugu'] = new Animal(225000, 'Aquarium');ANIMAUX['komondor'] = new Animal(215000, 'Terre', '', '', '', true);ANIMAUX['libellule deesse precieuse'] = new Animal(208335, 'Insectarium', true, '', '', true);ANIMAUX['guepard'] = new Animal(200000, 'Savane', '', '', true);
ANIMAUX['caracal'] = new Animal(200000, 'Savane', '', '', true);ANIMAUX['panda roux'] = new Animal(200000, 'Forêt');ANIMAUX['ours rastafarai'] = new Animal(200000, 'Bassin', true);ANIMAUX['dendrobate fraise'] = new Animal(185000, 'Terre');
ANIMAUX['espadon'] = new Animal(176000, 'Aquarium');ANIMAUX['ours polaire'] = new Animal(175000, 'Bassin', '', '', true);ANIMAUX['tuit tuit'] = new Animal(175000, 'Volière', '', '', '', true);ANIMAUX['mandrill'] = new Animal(170000, 'Forêt', '', '', true);
ANIMAUX['calao buffle'] = new Animal(170000, 'Volière');ANIMAUX['toucan bec sanglant'] = new Animal(150000, 'Terre');ANIMAUX['meduse des bermudes'] = new Animal(150000, 'Aquarium');ANIMAUX['grizzly'] = new Animal(150000, 'Forêt', '', '', true);
ANIMAUX['salamandre de feu'] = new Animal(145000, 'Noctarium');ANIMAUX['anaconda'] = new Animal(142000, 'Vivarium');ANIMAUX['paon bleu'] = new Animal(135000, 'Terre');ANIMAUX['marsouin argente'] = new Animal(133000, 'Bassin');
ANIMAUX['kakapo'] = new Animal(133000, 'Noctarium');ANIMAUX['tigre'] = new Animal(125000, 'Forêt', '', '', true);ANIMAUX['napoleon'] = new Animal(110000, 'Aquarium');ANIMAUX['tarsier'] = new Animal(110000, 'Noctarium');
ANIMAUX['requin nourrice'] = new Animal(105000, 'Bassin', '', '', true);ANIMAUX['dunnart castor'] = new Animal(104000, 'Noctarium');ANIMAUX['lion'] = new Animal(100000, 'Savane', '', '', true);ANIMAUX['lion albinos'] = new Animal(200000, 'Savane', true, '', true);
ANIMAUX['scorpion aiguille ecarlate'] = new Animal(100000, 'Vivarium');ANIMAUX['condor des andes'] = new Animal(95000, 'Volière');ANIMAUX['requin marteau'] = new Animal(95000, 'Bassin');ANIMAUX['hermine'] = new Animal(94000, 'Terre');
ANIMAUX['raton laveur'] = new Animal(90000, 'Forêt');ANIMAUX['pingouin'] = new Animal(90000, 'Terre');ANIMAUX['cameleon luminophore'] = new Animal(90000, 'Vivarium');ANIMAUX['criquet du mato grosso'] = new Animal(85000, 'Insectarium');
ANIMAUX['phalanger renard'] = new Animal(85000, 'Noctarium');ANIMAUX['python royal'] = new Animal(83000, 'Vivarium');ANIMAUX['loup blanc'] = new Animal(80000, 'Forêt', '', '', true);ANIMAUX['caribou de noel'] = new Animal(79000, 'Forêt', true);
ANIMAUX['mygale geante asiatique'] = new Animal(75000, 'Vivarium');ANIMAUX['calamar geant'] = new Animal(75000, 'Aquarium');ANIMAUX['alpaga'] = new Animal(75000, 'Terre', '', '', '', true);ANIMAUX['muscardin'] = new Animal(74000, 'Noctarium');
ANIMAUX['muscardin albinos'] = new Animal(148000, 'Noctarium', true);ANIMAUX['perlinsky'] = new Animal(73000, 'Terre');ANIMAUX['axolotl'] = new Animal(72000, 'Aquarium', '', '', '', true);ANIMAUX['fennec'] = new Animal(70000, 'Savane');
ANIMAUX['orque'] = new Animal(70000, 'Bassin', '', '', true);ANIMAUX['ouistiti'] = new Animal(70000, 'Forêt');ANIMAUX['ibis rouge'] = new Animal(70000, 'Volière');ANIMAUX['messager sagittaire'] = new Animal(70000, 'Volière');
ANIMAUX['mamba noir'] = new Animal(68000, 'Vivarium');ANIMAUX['scorpion coton du mexique'] = new Animal(65000, 'Vivarium');ANIMAUX['chouette leptogramme'] = new Animal(63000, 'Noctarium', '', '', '', true);
ANIMAUX['raie lunaire'] = new Animal(62500, 'Aquarium');ANIMAUX['paul le poulpe'] = new Animal(62000, 'Aquarium', true);ANIMAUX['dauphin'] = new Animal(60000, 'Bassin');ANIMAUX['jaseur boreal'] = new Animal(60000, 'Volière', '', '', '', true);
ANIMAUX['dauphin albinos'] = new Animal(120000, 'Bassin', true);ANIMAUX['massasauga argente'] = new Animal(60000, 'Vivarium');ANIMAUX['orang outan'] = new Animal(57000, 'Forêt', '', '', true);ANIMAUX['puma'] = new Animal(57000, 'Forêt', '', '', true);
ANIMAUX['caribou'] = new Animal(55000, 'Forêt');ANIMAUX['tortue geante'] = new Animal(55000, 'Terre');ANIMAUX['elaphe noir'] = new Animal(55000, 'Vivarium');ANIMAUX['papillon du crepuscule'] = new Animal(55000, 'Volière');
ANIMAUX['chimpanze zombie'] = new Animal(55000, 'Forêt', true);ANIMAUX['musaraigne elephant'] = new Animal(54000, 'Noctarium');ANIMAUX['heron agami'] = new Animal(53000, 'Terre');ANIMAUX['mamba rouge'] = new Animal(52000, 'Vivarium');
ANIMAUX['tapir'] = new Animal(50000, 'Forêt');ANIMAUX['kangourou'] = new Animal(50000, 'Savane');ANIMAUX['kangourou albinos'] = new Animal(100000, 'Savane', true);ANIMAUX['husky'] = new Animal(49000, 'Forêt', '', '', true);
ANIMAUX['hippocampe lumineux'] = new Animal(49000, 'Aquarium');ANIMAUX['renard polaire'] = new Animal(48000, 'Terre', '', '', true);ANIMAUX['effraie des clochers'] = new Animal(48000, 'Noctarium');ANIMAUX['copris lunaire'] = new Animal(47000, 'Insectarium');
ANIMAUX['tatou'] = new Animal(45000, 'Terre');ANIMAUX['requin bleu'] = new Animal(45000, 'Bassin', '', '', true);ANIMAUX['raie des sables'] = new Animal(45000, 'Aquarium');ANIMAUX['ara pyrodactile'] = new Animal(45000, 'Volière');
ANIMAUX['tortue caouanne'] = new Animal(42000, 'Bassin');ANIMAUX['cameleon allumette'] = new Animal(41000, 'Vivarium');ANIMAUX['cervicapre'] = new Animal(40000, 'Savane');ANIMAUX['panthere noire'] = new Animal(40000, 'Forêt', '', '', true);
ANIMAUX['iguane vert'] = new Animal(39000, 'Vivarium');ANIMAUX['iguane vert albinos'] = new Animal(78000, 'Vivarium', true);ANIMAUX['poulpe a anneaux bleus'] = new Animal(36000, 'Aquarium');
ANIMAUX['mante religieuse'] = new Animal(35500, 'Insectarium');ANIMAUX['lynx'] = new Animal(35000, 'Forêt', '', '', true);ANIMAUX['kiwi'] = new Animal(35000, 'Noctarium');ANIMAUX['coq patriote'] = new Animal(35000, 'Volière', true);
ANIMAUX['quetzal'] = new Animal(35000, 'Volière', '', '', '', true);ANIMAUX['tarentule rosea'] = new Animal(35000, 'Vivarium');ANIMAUX['hibou grand duc'] = new Animal(34000, 'Noctarium');ANIMAUX['panthere'] = new Animal(32500, 'Forêt', '', '', true);
ANIMAUX['morse'] = new Animal(32000, 'Bassin');ANIMAUX['poisson clown sable'] = new Animal(32000, 'Aquarium');ANIMAUX['dendrobate bleu'] = new Animal(30000, 'Terre');ANIMAUX['elephant'] = new Animal(30000, 'Savane');
ANIMAUX['raie furtive'] = new Animal(30000, 'Aquarium');ANIMAUX['ara ararauna'] = new Animal(30000, 'Volière');ANIMAUX['gerenuk'] = new Animal(29000, 'Savane', true);ANIMAUX['murene commune'] = new Animal(28000, 'Aquarium');
ANIMAUX['loup gris'] = new Animal(27500, 'Forêt', '', '', true);ANIMAUX['vipere des dunes'] = new Animal(27000, 'Vivarium');ANIMAUX['luciole'] = new Animal(26500, 'Insectarium');ANIMAUX['elan'] = new Animal(26000, 'Forêt');
ANIMAUX['gavial'] = new Animal(26000, 'Terre', true, '', true);ANIMAUX['vigogne a bosses'] = new Animal(26000, 'Terre');ANIMAUX['girafe'] = new Animal(25000, 'Savane');ANIMAUX['girafe albinos'] = new Animal(50000, 'Savane', true);
ANIMAUX['hippocampe roux'] = new Animal(25000, 'Aquarium');ANIMAUX['perroquet gris du gabon'] = new Animal(25000, 'Volière', true, '', '', true);ANIMAUX['leopard de mer'] = new Animal(25000, 'Bassin');
ANIMAUX['western pipistrelle'] = new Animal(24000, 'Noctarium');ANIMAUX['cobra royal'] = new Animal(23500, 'Vivarium');ANIMAUX['gorille'] = new Animal(23000, 'Forêt', '', '', true);ANIMAUX['gorille albinos'] = new Animal(46000, 'Forêt', true, '', true);
ANIMAUX['papillon joyeux'] = new Animal(22500, 'Volière');ANIMAUX['dingo'] = new Animal(22164, 'Savane', true, '', '', '', true);ANIMAUX['buffle du cap'] = new Animal(22000, 'Savane');ANIMAUX['bison'] = new Animal(21000, 'Terre');
ANIMAUX['chimpanze'] = new Animal(20000, 'Forêt');ANIMAUX['tarentule infernale'] = new Animal(20000, 'Vivarium');ANIMAUX['sternocera aequisignata'] = new Animal(19500, 'Insectarium', true, '', '', true);ANIMAUX['crocodile'] = new Animal(19500, 'Terre', '', '', true);
ANIMAUX['crocodile albinos'] = new Animal(39000, 'Terre', true);ANIMAUX['manchot empereur'] = new Animal(19000, 'Bassin');ANIMAUX['lemming des toundras'] = new Animal(19000, 'Noctarium');ANIMAUX['lama'] = new Animal(19000, 'Terre');
ANIMAUX['lemurien'] = new Animal(18500, 'Forêt');ANIMAUX['hippopotame'] = new Animal(18500, 'Terre');ANIMAUX['ornithorynque'] = new Animal(18000, 'Terre');ANIMAUX['cameleon sanguin'] = new Animal(18000, 'Vivarium');
ANIMAUX['grand tetra'] = new Animal(18000, 'Volière');ANIMAUX['poisson clown'] = new Animal(17500, 'Aquarium');ANIMAUX['boa constrictor'] = new Animal(17500, 'Vivarium');ANIMAUX['boa constrictor albinos'] = new Animal(35000, 'Vivarium', true);
ANIMAUX['zebre'] = new Animal(17000, 'Savane');ANIMAUX['castor'] = new Animal(17000, 'Terre');ANIMAUX['rhinoceros'] = new Animal(16000, 'Savane');ANIMAUX['scorpion amazone'] = new Animal(16000, 'Vivarium');
ANIMAUX['renard veloce'] = new Animal(15000, 'Terre', '', '', true);ANIMAUX['aigle royal'] = new Animal(15000, 'Volière');ANIMAUX['chamois'] = new Animal(15000, 'Forêt');ANIMAUX['phasme baton du diable'] = new Animal(14500, 'Insectarium');
ANIMAUX['otarie'] = new Animal(14000, 'Bassin');ANIMAUX['raie ventouse'] = new Animal(14000, 'Aquarium');ANIMAUX['sanglier'] = new Animal(13000, 'Forêt');ANIMAUX['phacochere'] = new Animal(13000, 'Savane');
ANIMAUX['autruche'] = new Animal(12000, 'Savane');ANIMAUX['marmotte'] = new Animal(11856, 'Terre', true, '', '', true);ANIMAUX['dromadaire'] = new Animal(11000, 'Savane');ANIMAUX['loutre'] = new Animal(10000, 'Bassin');
ANIMAUX['poisson clown cuivre'] = new Animal(10000, 'Aquarium');ANIMAUX['aigle noir'] = new Animal(10000, 'Volière');ANIMAUX['pelican'] = new Animal(9500, 'Terre');ANIMAUX['gypaete barbu'] = new Animal(9100, 'Volière');
ANIMAUX['cygne'] = new Animal(9000, 'Terre');ANIMAUX['crotale diamantin'] = new Animal(9000, 'Vivarium');ANIMAUX['chevre naine'] = new Animal(8000, 'Terre');ANIMAUX['barbotte nicoise'] = new Animal(7500, 'Aquarium');
ANIMAUX['nautile'] = new Animal(7200, 'Aquarium');ANIMAUX['flamant rose'] = new Animal(7000, 'Terre');ANIMAUX['ara fantome'] = new Animal(7000, 'Volière');ANIMAUX['grabote de paques'] = new Animal(7000, 'Aquarium', true, "Grabote de Pâques");
ANIMAUX['couleuvre agile'] = new Animal(6500, 'Vivarium');ANIMAUX['gazelle'] = new Animal(6000, 'Savane');ANIMAUX['cameleon des roches'] = new Animal(6000, 'Vivarium');ANIMAUX['cigogne blanche'] = new Animal(6000, 'Volière', true);
ANIMAUX['fourmi rousse'] = new Animal(5600, 'Insectarium');ANIMAUX['saumon rouge gorge'] = new Animal(5500, 'Aquarium');ANIMAUX['scorpion africain'] = new Animal(5400, 'Vivarium');ANIMAUX['carpe ancestrale'] = new Animal(5000, 'Aquarium');
ANIMAUX['mygale moderatum'] = new Animal(5000, 'Vivarium');ANIMAUX['vautour imperial'] = new Animal(5000, 'Volière');ANIMAUX['colibri thalassin'] = new Animal(5000, 'Volière', true, "Colibri thalassin");
ANIMAUX['papillon du soleil'] = new Animal(4500, 'Volière');ANIMAUX['barbotte du mistral'] = new Animal(4000, 'Aquarium');ANIMAUX['cobra perce roches'] = new Animal(3500, 'Vivarium');ANIMAUX['vautour cendre'] = new Animal(3500, 'Volière');
ANIMAUX['aigle antique'] = new Animal(3240, 'Volière');ANIMAUX['gecko poudre d or'] = new Animal(3000, 'Vivarium', true, "Gecko poudre d'or");ANIMAUX['saumon banni'] = new Animal(3000, 'Aquarium');
ANIMAUX['suricate'] = new Animal(3000, 'Savane', true, "Suricate");ANIMAUX['carpe venimeuse'] = new Animal(3000, 'Aquarium');ANIMAUX['saumon ardent'] = new Animal(2500, 'Aquarium');ANIMAUX['vautour des marais'] = new Animal(2500, 'Volière');
ANIMAUX['coccinelle a 7 points'] = new Animal(2500, 'Insectarium', true, "Coccinelle à 7 points");ANIMAUX['etoile de mer'] = new Animal(2500, 'Bassin', true, "Etoile de mer");ANIMAUX['barbotte de berlin'] = new Animal(2000, 'Aquarium');
ANIMAUX['herisson'] = new Animal(2000, 'Noctarium', true, "Hérisson");ANIMAUX['bernard l ermite'] = new Animal(2000, 'Aquarium', true, "Bernard l'ermite");ANIMAUX['ecureuil'] = new Animal(1000, 'Forêt', true, "Ecureuil");
ANIMAUX['rainette verte'] = new Animal(500, 'Terre', true, "Rainette verte");
var ANIMBONUS = new Array;
ANIMBONUS['Savane'] = new AnimBonus('savane_suricate', 'Suricate'); ANIMBONUS['Bassin'] = new AnimBonus('bassin_etoile%20de%20mer', 'Etoile de mer'); ANIMBONUS['Terre'] = new AnimBonus('terre_rainette%20verte', 'Rainette verte'); ANIMBONUS['Forêt'] = new AnimBonus('foret_ecureuil', 'Ecureuil');
ANIMBONUS['Volière'] = new AnimBonus('voliere_colibri%20thalassin', 'Colibri thalassin'); ANIMBONUS['Aquarium'] = new AnimBonus('aquarium_grabote%20de%20paques', 'Grabote de Pâques ou Bernard l\'ermite', 'aquarium_bernard%20l%20ermite'); ANIMBONUS['Vivarium'] = new AnimBonus('vivarium_gecko%20poudre%20d%20or', 'Gecko poudre d\'or');
ANIMBONUS['Noctarium'] = new AnimBonus('noctarium_herisson', 'Hérisson'); ANIMBONUS['Insectarium'] = new AnimBonus('insectarium_coccinelle%20a%207%20points', 'Coccinelle à 7 points');
var animauxmax = new Array();
var scan = GM_getValue("scan", false); // si true, on est entrain de scanner tous les enclos
var trouvaille = GM_getValue("trouvaille", false); // si true, on cherche les trouvailles
var clickmouse = document.createEvent("MouseEvents"); // pour simuler le click de la souris
clickmouse.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var i;
var debug = unserialize(GM_getValue("debug", ""));
if (debug.length == 0) debug[debug.length] = window.location;
else debug[debug.length] = window.location.href.substring(window.location.href.lastIndexOf("/")+1);
GM_setValue("debug", serialize(debug));
document.addEventListener('click', function(e)
 { if (e.target.name == "bebes") GM_setValue("bebes","ok");
  if (e.target.name == "suivi") GM_setValue("suivi","ok");
  if (e.target.src == "http://www.monzoo.net/images/icones/icone_achat.png") GM_setValue("retour", window.scrollY);
  if (e.target.innerHTML == "cliquez ici" || e.target.innerHTML == "cliquez ici.") GM_setValue("retour", window.scrollY);
  if (e.target.value == "Adultes\nmaxi") sauvemaxi();
  if (e.target.value == "Vendre") ventemulti();
  if (e.target.value == "Ok" && (/items.php/.test(window.location)  || /items_botanica.php/.test(window.location))) encherenormale();
  if (e.target.value == "Oui je souhaite vendre") enregistrevente();
  if (e.target.value == "Validez votre achat" || (e.target.value == "Validez la construction" && GM_getValue("constructionenclos", false)))
   enregistreachat();
  if (e.target.value == "Cliquez ici pour continuer")
  { if (GM_getValue("ordre", "") != "")
   { var txt = urlSite + "enclosgestion1.php?t="
    var numenclos = unserialize(GM_getValue("ordre", ""));
    numenclos = parseInt(numenclos[0]);
    txt += Math.floor(numenclos/100) + "&v=";
    numenclos = numenclos - Math.floor(numenclos/100)*100;
    txt += numenclos;
    window.location.href = txt;
   }
   else window.location.href = urlSite + "enclosgestion1.php?t=0&v=0";
  }
  if (e.target.name == "filtre") filtre(e.target.checked);
  if (e.target.name == "etroit") etroit(e.target.checked);
  if (e.target.name == "affichertabanimaux") affichertabanimaux(e.target.checked);
  if (e.target.name == "etroit2") etroit2(e.target.checked);
  if (e.target.innerHTML == "Liste des vieux") affichertabvieux();
  if (e.target.name == "etroit3") etroit3(e.target.checked);
  if (e.target.name == "filtre2") filtre2(e.target.checked);
  if (e.target.innerHTML == "Liste des animaux") affichertabanim();
  if (e.target.name == "etroit4") etroit4(e.target.checked);
  if (e.target.name == "choixliste") choixliste(e.target.value);
  if (e.target.name == "choixaffanim") choixaffanim(e.target.value);
  if (e.target.name == "triesp") triesp(e.target.checked);
  if (e.target.name == "afficheautres") afficheautres(e.target.checked);
  if (e.target.innerHTML == "Enclos avec naissance(s)<br>et mourant(s)") afficheenclosnaissance();
  if (e.target.innerHTML == "Enclos avec naissance(s),<br>mourants et<br>adulte(s) en trop") afficheenclosnaissance();
  if (e.target.id == "choix_nbpoints5") fenetre_options(false);
  else if (e.target.name == "choix_nbpoints") fenetre_options(true);
  if (e.target.textContent == "Déconnexion")
   if (!confirm("Vous allez vous déconnecter.\n\nPour éviter tout problème, il est conseillé de vérifier son stock\n" +
    "et ses PA (avec le rapport) avant de sortir : cliquez sur Annuler\nsi vous voulez rester connecté.\n\n" +
    "Cliquez sur OK si vous voulez confirmer votre déconnexion.")) e.target.href = window.location;
  if (e.target.href.indexOf("enclosgestion1.php?bot=1") != -1) MAJPA(e);
 }, true);


if (nom_zoo = est_connecte()) // on vérifie que ce parc est connecté
{ var exist = false, bad = false;
 for (i in tab_zoo)
 { if (nom_zoo == tab_zoo[i]) { id_zoo = i; bad = true; break; }
  if (nom_zoo == tab_zoo[i][0])
   { id_zoo = i; num_zoo = tab_zoo[i][1]; exist = true; break; }
 }

 if (GM_getValue("creacompte", "") != "") // on est entrain de créer un nouveau compte
 { if (GM_getValue("classement", "") != "" && !/classement.php/.test(window.location))
   window.location.href = urlSite + "classement.php";
  else if (GM_getValue("scrollcl", "") != "" && !/classement.php/.test(window.location))
  { GM_setValue("classement", "prestige");
   window.location.href = urlSite + "classement.php";
  }
  else if (/classement.php/.test(window.location) && GM_getValue("classement", "") != "")
  { var bstrong = $t("strong"), cl;
   if (bstrong[8].innerHTML.indexOf("Prestige") != -1)
   { cl = bstrong[2].innerHTML;
    cl = parseInt(cl) - 1;
    GM_deleteValue("classement");
    GM_setValue("scrollcl", 230);
    window.location.href = urlSite + "classement.php?deb=" + cl;
   }
   else 
    window.location.href = urlSite + "classement.php?change=1";
  }
  else if (/classement.php/.test(window.location) && GM_getValue("scrollcl", "") != "")
  { GM_deleteValue("scrollcl");
   var ba = $t("a");
   for (i=20;i<40;i++)
    if (ba[i].innerHTML == nom_zoo)
    { num_zoo = recherche_param(ba[i].href, "idparc");
     break;
    }
   if (!bad) id_zoo = tab_zoo.length;
   tab_zoo[id_zoo] = new Array();
   tab_zoo[id_zoo][0] = nom_zoo;
   tab_zoo[id_zoo][1] = num_zoo ? num_zoo : "NC";
   GM_setValue("liste_zoo", serialize(tab_zoo));
   GM_deleteValue("creacompte");
   window.location.href = urlSite + "zonemembre.php";
  }
 }
 else if (!exist)
 { GM_setValue("creacompte", "oui");
  GM_setValue("classement", "prestige");
  window.location.href = urlSite + "classement.php";
 }
 else
 { if (GM_getValue("version","") != this_version)
  { GM_setValue("version", this_version);
   alert("Bienvenue dans la version " + this_version + " de mon script.\n\n" +
    "Cette version prend en compte :\n" +
    "- dans les graphiques, la moyenne glissante est maintenant calculée\n  systématiquement sur les 15 derniers points même si ces points sont\n  hors graphique (cas en début des graphiques),\n" +
    "- lorsqu'on déplace la souris sur les graphiques, on récupère les infos\n  sur les différentes MAJ,\n" +
    "- lors du scan pour le rapport et le scan initial, les enclos non cons-\n  truits sont sautés,\n" +
    "- lors du scan initial, les enclos vides sont sautés,\n" +
    "- prise en compte de la nouvelle version de Greasemonkey qui faisait\n  planter le script.\n\n" +
    "Mon site montdm.servhome.org (sans www. devant) est mis à jour\nrégulièrement, n'hésitez pas à le visiter de temps en temps.\n\n" +
    "Si vous vous voulez me contacter par rapport à ce script, vous pouvez\nme laisser des messages directement sur :\n                        http://userscripts.org/scripts/show/63727\nou sur mon courriel privé sur le forum.");
  }

  if (scan && GM_getValue("messages_releves_"+id_zoo, "") == "" && !(/enclosgestion1.php/.test(window.location)) && !(/bureau.php/.test(window.location)) && !(/bureau4.php/.test(window.location)) && !(/espion.php/.test(window.location)) && GM_getValue("oeuf_"+id_zoo,"") == "") // on était en train de scanner et il y a eu un problème : on réinitialise tout
   GM_setValue("dateConnexion_"+id_zoo, "");
   
  var constructionenclos = false;
  if (/enclosgestion1.php/.test(window.location) && !scan)
  { var bstrong = $t("strong");
   if (bstrong[0].innerHTML.indexOf("construire") != -1)
    constructionenclos = true;
  }

 // si c'est la première connexion de la journée ou si c'est une MAJ bonus, on efface les données précédentes
  dateConnexion = GM_getValue("dateConnexion_"+id_zoo, "");
  monzoo = "voirzoo.php?idparc=" + num_zoo;
  if (dateConnexion != aujourd_hui || /zonemembre.php\?maj_bonus/.test(window.location))
  { GM_deleteValue("string_vols_"+id_zoo);  // vols
   GM_deleteValue("string_naissances_"+id_zoo); // naissances
   GM_deleteValue("mourants_"+id_zoo); // mourants
   GM_deleteValue("synthvieux_"+id_zoo); // synthèse des vieux
   GM_deleteValue("albinos_"+id_zoo); // pour équilibrer les espèces sources
   GM_deleteValue("synthanimaux_"+id_zoo); // synthèse des animaux
   GM_deleteValue("couples15_"+id_zoo); // animaux en trop
   GM_deleteValue("string_trouvailles_"+id_zoo); // trouvailles
   GM_deleteValue("string_achats_"+id_zoo); // achats
   GM_deleteValue("string_ventes_"+id_zoo); // ventes
   GM_deleteValue("messages_releves_"+id_zoo); // messages
   GM_deleteValue("valeurC_"+id_zoo); // variable qui n'est plus utilisée
   GM_deleteValue("initialisation");  // variable qui n'est plus utilisée
   GM_deleteValue("nobulles");  // variable qui n'est plus utilisée
   GM_deleteValue("team");  // variable qui n'est plus utilisée
   GM_deleteValue("posY");  // variable qui n'est plus utilisée
   GM_deleteValue("choixliste");  // variable qui n'est plus utilisée
   GM_deleteValue("scan");
   GM_deleteValue("trouvaille");
   GM_deleteValue("pas un animal bonus");
   GM_deleteValue("cherchebonus");
   GM_setValue("compteur_achats_"+id_zoo, 0);
   GM_setValue("maxachats_"+id_zoo, 20);
   GM_deleteValue("debug");
   GM_deleteValue("plus");
   GM_deleteValue("oeuf_"+id_zoo);
   GM_deleteValue("moins");
   if (num_zoo == "NC")
   { tab_zoo[id_zoo] = nom_zoo;
    GM_setValue("liste_zoo", serialize(tab_zoo));
    GM_setValue("creacompte", "oui");
    GM_setValue("classement", "prestige");
    window.location.href = urlSite + "classement.php";
   }
   scan = false;
   trouvaille = false;
   if (GM_getValue("animauxmax_"+id_zoo, "") == "")
   { for (espece in ANIMAUX) animauxmax[espece] = 15;
    GM_setValue("animauxmax_"+id_zoo, serialize(animauxmax));
   }
   else
   { animauxmax = unserialize(GM_getValue("animauxmax_"+id_zoo));
    for (espece in ANIMAUX) if (!animauxmax[espece]) animauxmax[espece] = 15;
    GM_setValue("animauxmax_"+id_zoo, serialize(animauxmax));
   }
   if (GM_getValue("touslesenclos_" + id_zoo, "") == "")
   { var touslesenclos = new Array();
    for (i=0;i<16;i++) touslesenclos[i] = "Initialisation";
    for (i=20;i<61;i++) touslesenclos[i] = "Initialisation";
    for (i=100;i<105;i++) touslesenclos[i] = "Initialisation";
    GM_setValue("touslesenclos_" + id_zoo, serialize(touslesenclos));
   }
   GM_setValue("dateConnexion_"+id_zoo, aujourd_hui);
   window.location.href = urlSite + "event.php";
  }
  else animauxmax = unserialize(GM_getValue("animauxmax_"+id_zoo));

  if (!scan && !trouvaille && GM_getValue("encherir", "") == "" && GM_getValue("messages_releves_"+id_zoo, "") != "" && GM_getValue("achatcouple","") == "" &&
   GM_getValue("cherchebonus","") == "" && !GM_getValue("espions", false) && !GM_getValue("boutique", false) && !GM_getValue("venteauto", false)) // si on n'est pas en train de scanner, on affiche l'icone des préférences et le menu modifié
  { image_options();
   modification_menu();
  }

  if (GM_getValue("affnews", false) && GM_getValue("messages_releves_"+id_zoo, "") != "" && !/news.php/.test(window.location) && !/toutou.php/.test(window.location))
  { var bdiv3 = document.createElement("div");
   bdiv3.id = "news";
   bdiv3.className = "info_bulle";
   bdiv3.innerHTML = "<div style=\"width:350px;text-align:center;font-size:14px;font-weight:bold;color:#B86242;\">Une news vient d'être publiée</div>" +
    "<br /><div style=\"text-align:center\"><a style=\"cursor:pointer;\" onClick=\"window.location.href='news.php'\">Cliquez ici</a> pour y accéder" +
    "<br /><br /><a style=\"cursor:pointer;\" onClick=\"document.getElementById('news').style.display = 'none'\">Fermer</a></div>";
   document.body.appendChild(bdiv3);
  }

  if (GM_getValue("oeuf_"+id_zoo,"") == "oeuf3" && !(/oeuf.php/.test(window.location)) && scan) // on a lu le message sur l'oeuf, mais on n'a pas cliqué sur le bouton : pas grave, on continue !
  { alert("Vous n'avez peut-être pas vu, mais il y avait un bouton sur la page de l'oeuf pour continuer et lancer le scan initial :\npas grave, mais la prochaine fois, cliquez plutôt sur ce bouton que dans les menus !\n\nCliquez maintenant sur OK pour continuer le jeu.");
   lancerscan();
  }
  else if (GM_getValue("oeuf_"+id_zoo,"") == "oeuf2" && (/zonemembre.php/.test(window.location)) && scan) // le message de l'oeuf est toujours là mais la page oeuf a disparu : pas grave, on continue !
   lancerscan();
  else if (/enclosconfirm.php/.test(window.location))
  { var binput = $t("input");
   if (binput)
   { if (parseInt(binput[4].value) < 2)
    { GM_setValue("constructionenclos", true);
     GM_setValue("temp_achat", binput[1].value);
    }
   }
  }
  else if (/achat_animaux.php/.test(window.location) && GM_getValue("achatcouple","") != "") // achat de couples
  { var binput = $t("input");
   if (binput)
   { var espece = GM_getValue("achatcouple");
    espece = espece.substring(espece.indexOf(";")+1);
    for (i=0; i<binput.length;i++) if (binput[i].value == espece) binput[i].checked = true;
    binput[binput.length-1].dispatchEvent(clickmouse);
   }
   else // max de 20 achats atteint
   { alert("Vous ne pouvez pas terminer la procédure automatique d'achat de couples :\nvous avez atteint le maximum d'achats possibles pour aujourd'hui.");
    GM_deleteValue("achatcouple");
    var t = recherche_param(window.location.href, "t");
    var v = recherche_param(window.location.href, "v");
    window.location.href = urlSite + "enclosgestion1.php?t=" + t + "&v=" + v;
   }
  }
  else if (/achat_animaux.php/.test(window.location) && GM_getValue("cherchebonus", "") != "") // on fait un autre essai pour trouver un animal bonus
  { var binput = $t("input");
   var cherche = GM_getValue("cherchebonus");
   var nbr = parseInt(cherche.substring(cherche.indexOf(";")+1));
   if (binput)
   { nbr++;
    if (confirm("La tentative précédente a échoué.\n\nSouhaitez-vous faire un nouvel essai (n° " + nbr + ")\npour trouver un animal bonus ?"))
    { cherche = cherche.substring(0, cherche.indexOf(";"));
     GM_setValue("cherchebonus", cherche+";"+nbr);
     for (i=0; i<binput.length;i++) if (binput[i].value == cherche) binput[i].checked = true;
     binput[binput.length-1].dispatchEvent(clickmouse);
    }
    else
    { GM_deleteValue("cherchebonus");
     var t = recherche_param(window.location.href, "t");
     var v = recherche_param(window.location.href, "v");
     window.location.href = urlSite + "enclosgestion1.php?t=" + t + "&v=" + v;
    }
   }
   else // max de 20 achats atteint
   { var s = nbr>1?"s":"";
    alert("Après " + nbr + " essai" + s + ", vous avez atteint le maximum des 20 achats : fin de la recherche d'un animal bonus.");
    GM_deleteValue("cherchebonus");
    var t = recherche_param(window.location.href, "t");
    var v = recherche_param(window.location.href, "v");
    window.location.href = urlSite + "enclosgestion1.php?t=" + t + "&v=" + v;
   }
  }
  else if (/achat_animaux.php/.test(window.location) || constructionenclos) // on corrige l'orthographe de Gabarit et on rajoute prix de base, rapport prix sur prix de base, achat de couple et trouver un animal bonus
  { var bstrong = $t("strong");
   for (i=0;i<bstrong.length;i++)
    { if (bstrong[i].innerHTML == "Gabari :") bstrong[i].innerHTML = "Gabarit :"; }
   var btd = $t("td");
   var txt, newtd, newa, nom, prix, pourcent, achatexiste = false;
   var maxsingles = GM_getValue("maxachats_"+id_zoo, 20) - GM_getValue("compteur_achats_"+id_zoo, 0);
   var maxcouples = Math.floor(maxsingles / 2);
   var enclos = unserialize(GM_getValue("enclos"), "");
   for (espece in enclos) break;
   var argent, bdiv = $t("div");
   for (i=25; i<bdiv.length;i++) if (bdiv[i].attributes[0].value.indexOf("width: 125px") != -1) break;
   if (bdiv[i+1].innerHTML.indexOf("<span") != -1)
   { inn = bdiv[i+1].innerHTML;
    inn = inn.substring(inn.indexOf(">")+1);
    bdiv[i+1].innerHTML = inn.substring(0,inn.indexOf("<"));
   }
   argent = parseInt(bdiv[i+1].innerHTML);
   for (i=0;i<btd.length;i++)
   { if (btd[i].width == 150 || btd[i].width == 140)
    { achatexiste = true;
     nom = btd[i+1].innerHTML;
     nom = nom.substring(nom.indexOf("value")+7);
     nom = nom.trim();
     if (nom == "")
     { nom = btd[i-1].innerHTML;
      nom = nom.substring(nom.indexOf("images/animaux/"));
      nom = nom.substring(nom.indexOf("_")+1, nom.indexOf(".jpg"));
      nom = nom.replace("%20", " ", "g");
      if (nom.indexOf("1") == -1  && (nom.indexOf("2") == -1)) nom = nom + "1";
     }
     else nom = nom.substring(0, nom.indexOf("\""));
     txt = "Zoo\'z<br>";
     if (nom.indexOf("1") != -1)
     { nom = nom.substring(0, nom.indexOf("1"));
      if (!ANIMAUX[nom]) alert("L'espèce "+ nom + " est inconnue dans le script.\nAchat multiple imposssible pour l'instant.");
      else
      { txt = txt + "<strong>Base :</strong> " + ANIMAUX[nom].prix + " Zoo\'z<br>";
       btd[i].innerHTML = btd[i].innerHTML.replace("Zoo\'z<br>", txt);
      }
      if (!constructionenclos)
      { btd[i].parentNode.parentNode.parentNode.width = 274;
       bbr = $t("br", btd[i].parentNode.parentNode.parentNode.parentNode);
       supbr = btd[i].parentNode.parentNode.parentNode.parentNode.removeChild(bbr[bbr.length-1]);
       btd[i].parentNode.parentNode.parentNode.parentNode.width = 274;
      }
     }
     else
     { nom = nom.substring(0, nom.indexOf("2"));
      maxanim = 50;
      if (espece)
      { for (j in enclos)
        if (j == nom) { maxanim = Math.max(0, 50 - parseInt(enclos[j][0]) - parseInt(enclos[j][1])); break; }
      }
      if (!constructionenclos)
      { btd[i].parentNode.parentNode.parentNode.width = 275;
       bbr = $t("br", btd[i].parentNode.parentNode.parentNode.parentNode);
       supbr = btd[i].parentNode.parentNode.parentNode.parentNode.removeChild(bbr[bbr.length-1]);
       btd[i].parentNode.parentNode.parentNode.parentNode.width = 275;
      }
      if (ANIMAUX[nom])
      { prix = btd[i].innerHTML.substring(btd[i].innerHTML.indexOf("Prix")+16);
       prix = parseInt(prix.substring(0, prix.indexOf(" Zoo")));
       pourcent = Math.round((prix/ANIMAUX[nom].prix - 1) * 10000) / 100;
       if (pourcent >= 0) plus = "+";
       else { plus = "-"; pourcent = 0 - pourcent ; }
       txt = txt + "<strong>Prix/Base :</strong> " + plus + "&nbsp;" + pourcent + "&nbsp;%<br>";
       btd[i].innerHTML = btd[i].innerHTML.replace("Zoo\'z<br>", txt);
       if (!constructionenclos)
       { if (btd[i].innerHTML.indexOf("Stock") != -1)
        { stock = btd[i].innerHTML.substring(btd[i].innerHTML.indexOf("Stock")+8);
         stock = parseInt(stock.substring(0, stock.indexOf("</div>")));
        }
        else stock = 100;
        if (stock > 0)
        { valmax = Math.min(stock, maxsingles, maxanim, Math.floor(argent / prix));
         coumax = Math.min(Math.floor(stock / 2), maxcouples, Math.floor(maxanim / 2), Math.floor(argent / (2 *prix)));
         newtd = document.createElement("td");
         newtd.width = 55;
         newtd.setAttribute("align", "center");
         newtd.setAttribute("style", "font-size:10px;margin:0px;padding:0px;background-color:#FCF0DB;border:1px solid #E9CA94");
         if (valmax > 0)
         { txt = document.createElement("input");
          txt.type = "text";
          txt.setAttribute("style", "font-size:10px;padding:0px;text-align:center");
         }
         else txt = newtd;
         txt.setAttribute("onmouseout", "UnTip()");
         lim1 = Math.min(stock, maxsingles, maxanim);
         lim2 = Math.min(Math.floor(stock / 2), maxcouples, Math.floor(maxanim / 2));
         nextcouple = coumax + 1 <= lim2 ? (coumax + 1) * 2 * prix - argent : 0;
         nextsingle = valmax + 1 <= lim1 ? (valmax + 1) * prix - argent : 0;
         txt.setAttribute("onmouseover", "Tip('nb max d&rsquo;achats de couple = " + coumax + "<br />argent nécessaire pour un couple supplémentaire = " +
          millier(nextcouple) + " Zoo&rsquo;z<br />nb max d&rsquo;achats de mâle ou femelle = " + valmax + "<br />argent nécessaire pour un individu supplémentaire = " +
          millier(nextsingle) + " Zoo&rsquo;z', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
         if (valmax > 0)
         { txt.size = "1";
          txt.name = nom;
          txt.value = "1";
          newtd.appendChild(txt);
          txt = document.createElement("p");
          txt.setAttribute("style", "margin:0px");
          txt.innerHTML = "achat(s) de";
          newtd.appendChild(txt);
          newa = document.createElement("a");
          newa.addEventListener("click", achatcouple, true);
          newa.innerHTML = "- mâle<br /><br />";
          newa.setAttribute("style", "cursor:pointer");
          newa.id = nom +"1;"+prix+";"+valmax;
          newtd.appendChild(newa);
          newa = document.createElement("a");
          newa.addEventListener("click", achatcouple, true);
          newa.innerHTML = "- femelle<br /><br />";
          newa.style.cursor = "pointer";
          newa.id = nom +"2;"+prix+";"+valmax;
          newtd.appendChild(newa);
         }
         if (coumax > 0)
         { newa = document.createElement("a");
          newa.addEventListener("click", achatcouple, true);
          newa.innerHTML = "- couple";
          newa.style.cursor = "pointer";
          prix = prix * 2;
          newa.id = nom +";"+prix+";"+coumax;
          newtd.appendChild(newa);
         }
         btd[i].parentNode.parentNode.parentNode.parentNode.parentNode.insertBefore(newtd, btd[i].parentNode.parentNode.parentNode.parentNode.nextSibling);
        }
       }
      }
      if (!constructionenclos)
      { newtr = document.createElement("tr");
       newtd = document.createElement("td");
       newtd.height = 10;
       newtr.appendChild(newtd);
       btd[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.insertBefore(newtr, btd[i].parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling);
      }
     }
    }
   }
   if (achatexiste && !constructionenclos)
   { nomenclos = nom_enclos(parseInt(recherche_param(window.location.href, "t")), parseInt(recherche_param(window.location.href, "v")));
    if (nomenclos.indexOf(" ") != -1) nomenclos = nomenclos.substring(0, nomenclos.indexOf(" "));
    for (i=btd.length-1;i>0;i--)
    { if ((btd[i].width == 150 || btd[i].width == 140) && btd[i].innerHTML.indexOf("Stock") == -1)
      break;
    }
    newanim = btd[i].parentNode.parentNode.parentNode.parentNode.parentNode.cloneNode(true);
    bimg = $t("img", newanim);
    bimg[0].setAttribute("src", "images/animaux/" + ANIMBONUS[nomenclos].image1 + ".jpg");
    bimg[1].setAttribute("src", "images/animaux/" + ANIMBONUS[nomenclos].image2 + ".jpg");
    btd2 = $t('td', newanim);
    btd22 = btd2[2].innerHTML;
    oldnom = btd22.substring(btd22.indexOf("Nom"),btd22.indexOf("<br"));
    oldnom = oldnom.substring(oldnom.indexOf("> ")+2);
    newnom = ANIMBONUS[nomenclos].nom;
    prix = btd22.substring(btd22.indexOf("Prix"));
    prix = prix.substring(prix.indexOf("> ")+2, prix.indexOf(" Zoo"));
    btd2[2].innerHTML = "<strong>Nom :</strong> " + newnom + "<br><strong>Gabarit :</strong> 1<br><strong>Sexe :</strong> Mâle<br><strong>Groupe :</strong> oui<br>";
    newa = document.createElement("a");
    newa.addEventListener("click", trouvebonus, true);
    newa.innerHTML = "Trouver cet animal bonus";
    newa.style.cursor = "pointer";
    newa.id = newnom + ";" + oldnom + ";" + prix + ";1";
    btd2[2].appendChild(newa);
    btd2[7].innerHTML = "<strong>Nom :</strong> " + newnom + "<br><strong>Gabarit :</strong> 1<br><strong>Sexe :</strong> Femelle<br><strong>Groupe :</strong> oui<br>";
    newa = document.createElement("a");
    newa.addEventListener("click", trouvebonus, true);
    newa.innerHTML = "Trouver cet animal bonus";
    newa.style.cursor = "pointer";
    newa.id = newnom + ";" + oldnom + ";" + prix + ";2";
    btd2[7].appendChild(newa);
    if (btd2.length == 10)
    { btd22 = btd2[9];
     newanim.removeChild(btd22);
    }
    btd2[8].innerHTML = " ";
    btd2[3].innerHTML = " ";
    btd[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(newanim);
   }
   if (!constructionenclos) tableau_animaux(enclos);
  }
  else if (/achat_animauxconfirm.php/.test(window.location)) // on rajoute nom, sexe et enclos de l'animal acheté
  { var binput = $t("input"), bstrong = $t("strong");
   if (binput) { var espece = binput[1].value; GM_setValue("temp_achat", espece); }
   if (GM_getValue("achatcouple", "") != "") // on fait des achats multiples
   { if (binput)
    { achat = GM_getValue("achatcouple");
     numero = parseInt(GM_getValue("nbrcouples")) - parseInt(achat.substring(0, achat.indexOf(";"))) + 1;
     sexe = achat.substring(achat.length-1) == "1" ? "u mâle" : "e la femelle";
     couple = GM_getValue("achatmale", false) || GM_getValue("achatfemelle", false) ? "":" du couple";
     if (sexe == "u mâle")
     { if (GM_getValue("achatmale", false))
      { nbr = parseInt(achat.substring(0,achat.indexOf(";"))) - 1;
       if (nbr > 0) GM_setValue("achatcouple", nbr + achat.substring(achat.indexOf(";"),achat.length-1) + "1");
       else GM_setValue("achatcouple", "fin");
      }
      else GM_setValue("achatcouple", achat.substring(0,achat.length-1) + "2");
     }
     else
     { nbr = parseInt(achat.substring(0,achat.indexOf(";"))) - 1;
      if (nbr > 0)
      { if (GM_getValue("achatfemelle", false)) GM_setValue("achatcouple", nbr + achat.substring(achat.indexOf(";"),achat.length-1) + "2");
       else GM_setValue("achatcouple", nbr + achat.substring(achat.indexOf(";"),achat.length-1) + "1");
      }
      else GM_setValue("achatcouple", "fin");
     }
     binput[4].style.visibility = "hidden";
     bstrong[1].innerHTML = "Ne touchez à rien, achat automatique d" + sexe + couple + " n° " + numero + " en cours...";
     binput[4].dispatchEvent(clickmouse);
    }
    else // on ne peut plus continuer
    { alert("Vous ne pouvez pas terminer la procédure automatique d'achat d'animaux.");
     GM_deleteValue("achatcouple");
    }
   }
   else if (GM_getValue("cherchebonus", "") != "") // on cherche un animal bonus
   { if (binput) // on a assez d'argent
    { binput[4].style.visibility = "hidden";
     bstrong[1].innerHTML = "Ne touchez à rien, recherche d'un animal bonus en cours...";
     binput[4].dispatchEvent(clickmouse);
    }
    else // on n'a plus d'argent
    { nbr = GM_getValue("cherchebonus");
     nbr = parseInt(nbr.substring(nbr.indexOf(";")+1));
     nbr--;
     s = nbr>1?"s":"";
     if (nbr>0) alert("Après " + nbr + " essai" + s + ", vous n'avez plus assez d'argent pour faire une nouvelle tentative : fin de la recherche d'un animal bonus.");
     else alert("Vous n'avez pas assez d'argent pour faire une tentative dans cet enclos : fin de la recherche d'un animal bonus.");
     GM_deleteValue("cherchebonus");
     var ba = $t("a");
     for(i=0;i<ba.length;i++) if (ba[i].innerHTML == "retour enclos") break;
     window.location.href = ba[i].href;
    }
   }
   else
   { if (binput)
    { var t = parseInt(binput[0].value);
     var v = parseInt(binput[2].value);
     var sexe = (binput[3].value == 1 ? "mâle" : "femelle");
     var bdiv = $t("div");
     var enclos = nom_enclos(t,v);
     for (i=0;i<bdiv.length;i++)
     { if (bdiv[i].getAttribute("align") == "justify")
      { if (espece == "coq patriote")
       { if (sexe == "mâle" ) { espece = "coq"; sexe = "patriote"; }
        else { espece = "poule"; sexe = "patriote"; }
       }
       var txt = "cet animal (<strong>" + espece + " " + sexe + "</strong>) pour l'enclos <strong>" + enclos + "</strong>";
       bdiv[i].innerHTML = bdiv[i].innerHTML.replace("cet animal", txt);
       bdiv[i].innerHTML = bdiv[i].innerHTML.replace("zoo", "Zoo");
      }
     }
    }
    tableau_animaux(unserialize(GM_getValue("enclos")));
   }
  }
  else if (/bureau4.php/.test(window.location) && scan) // correction automatique des stocks à la fin des scans
  { var bstrong = $t("strong");
   var decalage = bstrong[0].innerHTML.indexOf("Vous n'avez pas assez de") != -1 ? 2 : 0;
   var actuel = parseInt(bstrong[decalage+0].innerHTML);
   var besoins = parseInt(bstrong[decalage+4].innerHTML.replace(" ","","g"));
   if (parseInt(GM_getValue("antibug", 2)) == 1) besoins = 2 * (besoins - 1.5*Math.ceil(parseFloat(GM_getValue("nb_th_"+id_zoo, "0"))));
   bstrong[decalage+4].innerHTML = "- " + (0-besoins);
   var total = actuel + besoins;
   if (total >= 0) { txtotal = "+ " + total; bstrong[decalage+6].parentNode.parentNode.setAttribute("style", "font-size:20px;color:#6BBF36;"); }
   else { txtotal = "- " + (0 - total); bstrong[decalage+6].parentNode.parentNode.setAttribute("style", "font-size:20px;color:#DE422C;"); }
   bstrong[decalage+5].innerHTML = "TOTAL (cf. vos options)";
   bstrong[decalage+6].innerHTML = txtotal;
   if (decalage == 2)
    alert("Vous n'avez pas assez de Zoo'z pour acheter suffisamment de stocks !");
   else if (total < 0)
   { var ba =$t("a");
    for (i=ba.length-1; i>0; i--) if (ba[i].href == "http://www.monzoo.net/bureau4.php?achat=1") break;
    if (total + 900 > 0) window.location.href = ba[i].href;
    else if (total + 9000 > 0) window.location.href = ba[i+1].href;
    else window.location.href = ba[i+2].href;
   }
   if (decalage == 2 || total >= 0)
   { if (GM_getValue("messages_releves_"+id_zoo, "") == "")
    { GM_deleteValue("scan");
     window.location.href = urlSite + "enclosgestion.php?t=4&v=0";
    }
    else rapport();
   }
  }
  else if (/bureau4.php/.test(window.location)) // correction du total des stocks
  { var bstrong = $t("strong");
   var decalage = bstrong[0].innerHTML.indexOf("Vous n'avez pas assez de") != -1 ? 2 : 0;
   var actuel = parseInt(bstrong[decalage].innerHTML);
   var besoins = parseInt(bstrong[decalage+4].innerHTML.replace(" ","","g"));
   if (parseInt(GM_getValue("antibug", 2)) == 1) besoins = 2 * (besoins - 1.5*Math.ceil(parseFloat(GM_getValue("nb_th_"+id_zoo, "0"))));
   bstrong[decalage+4].innerHTML = "- " + (0-besoins);
   var total = actuel + besoins;
   if (total >= 0) { total = "+ " + total; bstrong[decalage+6].parentNode.parentNode.setAttribute("style", "font-size:20px;color:#6BBF36;"); }
   else { total = 0 - total; total = "- " + total; bstrong[decalage+6].parentNode.parentNode.setAttribute("style", "font-size:20px;color:#DE422C;"); }
   bstrong[decalage+5].innerHTML = "TOTAL (cf. vos options)";
   bstrong[decalage+6].innerHTML = total;
  } // première connexion de la journée, on démarre par une consultation de la liste des messages
  else if (/zonemembre.php/.test(window.location) && GM_getValue("messages_releves_"+id_zoo, "") == "")
  { var ba = $t("a");
   for (i=0;i<ba.length;i++) if (ba[i].href.indexOf("news.php") != -1) break;
   if (GM_getValue("news", "Caribou de Noel et Hippocampe Divin") != ba[i].innerHTML)
   { GM_setValue("news", ba[i].innerHTML);
    GM_setValue("affnews", true);
   }
   GM_setValue("dateConnexion_"+id_zoo, aujourd_hui);
   window.location.href = urlSite + "event.php";
  }
  else if (/classement.php/.test(window.location) && GM_getValue("classement", "") != "") // mon classement point ou prestige, 1ère partie
  { var bstrong = $t("strong"), cl;
   if (bstrong[8].innerHTML.indexOf("Prestige") != -1)
   { if (GM_getValue("classement", "") == "prestige")
    { cl = bstrong[2].innerHTML;
     cl = Math.max(0, parseInt(cl) - 6);
     GM_deleteValue("classement");
     GM_setValue("scrollcl", 230);
     window.location.href = urlSite + "classement.php?deb=" + cl;
    }
    else window.location.href = urlSite + "classement.php?change=1"
   }
   else 
   { if (GM_getValue("classement", "") == "points")
    { cl = bstrong[6].innerHTML.substring(0, bstrong[6].innerHTML.indexOf("/")-1);
     cl = Math.max(0, parseInt(cl) - 6);
     GM_deleteValue("classement");
     GM_setValue("scrollcl", 230);
     window.location.href = urlSite + "classement.php?deb=" + cl;
    }
    else window.location.href = urlSite + "classement.php?change=1"
   }
  }
  else if (/classement.php/.test(window.location) && GM_getValue("scrollcl", "") != "") // mon classement point ou prestige, 2ème partie
  { window.scroll(0, parseInt(GM_getValue("scrollcl")));
   GM_deleteValue("scrollcl");
   var ba = $t("a");
   for (i=25;i<45;i++)
    if (ba[i].innerHTML == nom_zoo)
    { ba[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.setAttribute("bgcolor", "#eac893");
     break;
    }
  }
  else if (/classement_team.php/.test(window.location)  && GM_getValue("scrollcl", "") != "") // page classement des teams
  { window.scroll(0, parseInt(GM_getValue("scrollcl")));
   GM_deleteValue("scrollcl");
   var bstrong = $t("strong"), cl = GM_getValue("team_" + id_zoo, cl) + "-";
   for (i=0;i<bstrong.length;i++)
    if (bstrong[i].innerHTML == cl)
    { bstrong[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.setAttribute("bgcolor", "#eac893");
     break;
    }
  }
  else if (/team.php/.test(window.location) && GM_getValue("classement", "") != "") // page des teams, pour le classement
  { var bspan = $t("span"), cl;
   GM_deleteValue("classement");
   if (bspan)
   { cl = bspan[0].innerHTML.trim();
    cl = cl.substring(0,cl.length - 15);
    GM_setValue("team_" + id_zoo, cl);
    cl = Math.max(0, parseInt(cl) - 13);
    GM_setValue("scrollcl", 200);
    window.location.href = urlSite + "classement_team.php?deb=" + cl;
   }
  }
  else if (/team.php/.test(window.location) && !GM_getValue("team_" + id_zoo, false)) // page des teams, vérification d'appartenance
  { var bspan = $t("span");
   if (bspan)
   { GM_setValue("team_"+id_zoo, true);
    window.location.href = urlSite + "team.php";
   }
  }
  else if (/voirzoo.php/.test(window.location)) // page des listes, mise en alerte sur l'image
  { var bp = $t("p"), txt;
   txt = "</p><p>Vous êtes sur la page des listes, cette carte est inactive.<br />Pour accéder à la carte avec les liens, cliquez sur \'Carte du zoo\' dans le menu à côté.</p><p a";
   bp[0].parentNode.innerHTML = bp[0].parentNode.innerHTML.replace("</p><p a", txt);
   var bimg = $t("img");
   for (i=0;i<bimg.length;i++)
   { if (bimg[i].src.indexOf("musee") != -1)
    { nom = bimg[i].src;
     nom = nom.substring(nom.indexOf("mages")+6, nom.indexOf(".jpg"));
     nom = nom[0] + nom.substring(nom.indexOf("/")+1);
     bimg[i].setAttribute("onmouseout", "UnTip()");
     var enchere = unserialize(GM_getValue("enchere_" + id_zoo, ""));
     if (!enchere[nom]) enchere = "???";
     else enchere = enchere[nom];
     numero = nom.substring(1);
     bimg[i].setAttribute("onmouseover", "Tip('Item " + numero + ", prix d&rsquo;achat : " + enchere + " Zoo&rsquo;z', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
    }
   }
   if (window.location.href.indexOf(monzoo) != -1)
    tableau_vieux();
  }
  else if (/missions.php/.test(window.location)) // page des missions, mise en évidence de la mission en cours
  { var btr = $t("tr");
   for (i=5;i<btr.length;i++)
    if (btr[i].innerHTML.indexOf("En cours") != -1)
     break;
   if (i<btr.length) // il reste au moins une mission en cours
   { btr[i].setAttribute("bgcolor", "#eac893");
    btd = $t("td", btr[i]);
    for (j=0;j<btd.length;j++) btd[j].setAttribute("bgcolor", "");
    window.scroll(0, position(btr[i])["y"] - window.innerHeight/2);
   }
   else window.scroll(0, document.body.clientHeight); // toutes les missions ont été faites
   for (i=5;i<btr.length;i++)
    if (btr[i].innerHTML.indexOf("Mission 30") != -1)
    { txt = btr[i].innerHTML;
     nbr = 0;
     while (txt.indexOf(" : ") != -1)
     { nbr += parseInt(txt.substring(txt.indexOf(" : ")+3, txt.indexOf(" / ")));
      txt = txt.substring(txt.indexOf(" / ")+3);
     }
     nbr = "<br /><br />" + parseInt(10000 * nbr / 155) / 100 + "&nbsp;% réalisé";
     bfont = $t("font", btr[i]);
     bfont[0].innerHTML = bfont[0].innerHTML + nbr;
    }
  }
  else if (/vente_animaux.php/.test(window.location) && GM_getValue("pas un animal bonus", "") != "") // on vend l'animal pas bonus
  { var binput = $t("input"), bstrong = $t("strong");
   bstrong[1].innerHTML = "Veuillez patienter, vente automatique en cours...";
   espece = GM_getValue("cherchebonus");
   GM_setValue("temp_vente", espece.substring(0, espece.indexOf(";")-1));
   binput[5].style.visibility = "hidden";
   binput[5].dispatchEvent(clickmouse);
  }
  else if (/vente_animaux.php/.test(window.location) && GM_getValue("venteauto", false))
  { var binput = $t("input"), bstrong = $t("strong");
   bstrong[1].innerHTML = "Veuillez patienter, vente automatique en cours...";
   var bimg = $t("img");
   var nom = bimg[bimg.length-1].src;
   nom = nom.substring(nom.indexOf("_")+1, nom.indexOf(".jpg"));
   nom = nom.replace("%20", " ", "g");
   nom = nom.replace("2", "");
   GM_setValue("temp_vente", nom);
   binput[5].style.visibility = "hidden";
   binput[5].dispatchEvent(clickmouse);
  }
  else if (/vente_animaux.php/.test(window.location)) // si on vend un animal, on ajoute ses caractéristiques
  { var btd = $t("td");
   var liste = new Array();
   var libelle, numero, txt;
   for (i=0;i<btd.length;i++)
   { if (btd[i].width == "100")
    { libelle = btd[i+2].innerHTML;
     numero = recherche_param(window.location.href, "ids");
     liste = unserialize(GM_getValue("liste", ""));
     txt = new String(liste[numero]);
     var bimg = $t("img");
     var nom = bimg[bimg.length-1].src;
     nom = nom.substring(nom.indexOf("_")+1, nom.indexOf(".jpg"));
     nom = nom.replace("%20", " ", "g");
     nom = nom.replace("2", "");
     GM_setValue("temp_vente", nom);
     libelle = libelle.substring(0,12) + "(<strong>" + txt + "</strong>)" + libelle.substring(11,libelle.length-1) + ".";
     btd[i+2].innerHTML = libelle;
     if (btd[i+2].innerHTML.indexOf("cervicapre femelle") != -1)
     { txt = btd[i].innerHTML;
      txt = txt.replace("capre.jpg", "capre2.jpg");
      btd[i].innerHTML = txt;
     }
     break;
    }
   }
   
   tableau_animaux(unserialize(GM_getValue("enclos")));
  }
  else if (/enclosgestion.php/.test(window.location)) // boutique
  { t = parseInt(recherche_param(window.location.href, "t"));
   if (t == 4)
   { var v = parseInt(recherche_param(window.location.href, "v"));
    var finscan = GM_getValue("messages_releves_"+id_zoo, "") == "", bad = false;
    var miniprov = 150 * (v + 1);
    var bstrong = $t("strong");
    if (bstrong.length > 2) // la boutique a été construite
    { var actu = parseInt(bstrong[2].innerHTML);
     var MAJ = "";
     if (GM_getValue("boutique", false) || finscan)
     { if (actu < miniprov)
       { bad = true; window.location.href = urlSite + "enclosgestion.php?v=" + v + "&t=4&achat=100"; }
      else if (!finscan)
      { GM_deleteValue("boutique");
       image_options();
       modification_menu();
       MAJ = "maintenant ";
      }
     }
     if (!GM_getValue("boutique", false) && !finscan)
     { window.scroll(0, position($c("minibarre")[0])["y"]);
      var bdiv = $t("div");
      if (actu < miniprov)
      { if (v == 0) txt = "Il est conseillé d'avoir un minimum de 150 provisions dans cette boutique";
       else if (v == 1) txt = "Il est conseillé d'avoir un minimum de 300 provisions dans cette boutique";
       else if (v == 2) txt = "Il est conseillé d'avoir un minimum de 450 provisions dans cette boutique";
       else txt = "Il est conseillé d'avoir un minimum de 600 provisions dans cette boutique";
      }
      else txt = "Vous avez " + MAJ + "des provisions suffisantes";
      var lastdiv = -1;
      for (i=0;i<bdiv.length;i++)
       if (bdiv[i].innerHTML.indexOf("provisions dans cette boutique") != -1) lastdiv = i;
      if (lastdiv >= 0)
      { bdiv[lastdiv].innerHTML = bdiv[lastdiv].innerHTML.substring(0,bdiv[lastdiv].innerHTML.length-1) + ".<br /><b>" + txt + "</b>.";
       bdiv[lastdiv].setAttribute("style", "text-align:justify");
      }
      if (actu < miniprov)
      { var btd = bdiv[lastdiv].parentNode;
       btd.setAttribute("align", "center");
       var btn = document.createElement("input");
       btn.type = "button";
       btn.setAttribute("onmouseout", "UnTip()");
       btn.setAttribute("onmouseover", "Tip('Cliquez ici pour atteindre les " + miniprov + " provisions', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
       btn.value = "Mettre à niveau les provisions";
       btn.addEventListener("click", boutique, true);
       btd.appendChild(btn);
      }
     }
    }
    if (finscan && !bad)
    { if (v<3) { v++; window.location.href = urlSite + "enclosgestion.php?t=4&v=" + v; }
     else window.location.href = urlSite + "espion.php";
    }
   }
  }
  else if (/items.php/.test(window.location) || /items_botanica.php/.test(window.location)) // items
  { var btr = $t("tr");
   for (i=0;i<btr.length;i++) if (btr[i].getAttribute("bgcolor") == "#fcf0db") break;
   var bimg = $t("img");
   var nom = bimg[bimg.length-1].src;
   nom = nom.substring(nom.indexOf("mages")+6, nom.indexOf(".jpg"));
   nom = nom[0] + nom.substring(nom.indexOf("/")+1);
   var btd = $t("td", btr[i+1]);
   if (btd[0].innerHTML.indexOf("Vous avez d") == -1)
   { window.scroll(0, position($c("minibarre")[0])["y"]);
    btd = $t("td", btr[i]);
    var encherisseur = $t("strong", btr[i])[0].innerHTML;
    var prix = btd[1].innerHTML;
    prix = prix.substring(0, prix.indexOf(" Zo"));
    if (prix == "") prix = 9999;
    else prix = parseInt(prix);
    btable = btr[i].parentNode;
    var encheremaxi = new Array();
    encheremaxi = unserialize(GM_getValue("encheremaxi_"+id_zoo, ""));
    if (!encheremaxi[nom]) encheremaxi[nom] = 0;
    else encheremaxi[nom] = parseInt(encheremaxi[nom]);
    if (GM_getValue("encherir_"+nom, "") == "")
    { ligne = document.createElement("tr");
     ligne.setAttribute("align", "center");
     ligne.setAttribute("bgcolor", "#eac893");
     tabcase = document.createElement("td");
     tabcase.setAttribute("colspan", 2);
     btn = document.createElement("input");
     btn.type = "button";
     btn.value = "Enchérir 1 seule fois";
     btn.setAttribute("style", "margin-right:10px");
     btn.addEventListener("click", encherir, true);
     tabcase.appendChild(btn);
     ligne.appendChild(tabcase);
     btable.appendChild(ligne);
     ligne = document.createElement("tr");
     ligne.setAttribute("align", "center");
     ligne.setAttribute("bgcolor", "#eac893");
     tabcase = document.createElement("td");
     tabcase.setAttribute("colspan", 2);
     btn = document.createElement("input");
     btn.type = "button";
     btn.value = "Enchérir 5 fois";
     btn.setAttribute("style", "margin-right:10px");
     btn.addEventListener("click", encherir5, true);
     tabcase.appendChild(btn);
     txt = document.createElement("strong");
     txt.innerHTML = "Enchère maxi : ";
     txt.style.cursor = "default";
     txt.setAttribute("onmouseout", "UnTip()");
     txt.setAttribute("onmouseover", "Tip('Saisir l&rsquo;enchère que vous ne voulez pas dépasser.<br />NB1 : la case est préremplie avec 0 ou votre ancienne saisie pour cet item.<br />NB2 : mettre &rsquo;0&rsquo; si vous ne souhaitez aucune limitation.', WIDTH, 420, BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
     tabcase.appendChild(txt);
     txt = document.createElement("input");
     txt.type = "text";
     txt.size = "10";
     txt.name = "MaxiEnch"+nom;
     if (encheremaxi[nom] > 0) txt.value = encheremaxi[nom];
     else txt.value = 0;
     tabcase.appendChild(txt);
     btn = document.createElement("input");
     btn.type = "button";
     btn.value = "Sauver";
     btn.addEventListener("click", sauveencheremaxi, true);
     tabcase.appendChild(btn);
     ligne.appendChild(tabcase);
     btable.appendChild(ligne);
    }
    else encherir5();
   }
   else GM_deleteValue("encherir_"+nom);
  }
  else if (/musee.php/.test(window.location))
  { var btable = $t("table");
   btable = btable[btable.length-1];
   var ligne = document.createElement("tr");
   ligne.setAttribute("align", "center");
   var tabcase = document.createElement("td");
   tabcase.setAttribute("colspan", 4);
   var txt;
   if (GM_getValue("liensmusee", true)) txt = "Vous avez choisi d&rsquo;afficher tous les liens.<br />Cliquer ici pour masquer les liens des items que vous possédez déjà.";
   else txt = "Vous avez choisi de masquer tous les liens inutiles.<br />Cliquer ici pour les afficher à nouveau.";
   var btn = document.createElement("input");
   btn.type = "button";
   if (GM_getValue("liensmusee", true)) btn.value = "Masquer les liens inutiles";
   else btn.value = "Afficher tous les liens";
   btn.addEventListener("click", liensmusee, true);
   btn.setAttribute("onmouseout", "UnTip()");
   btn.setAttribute("onmouseover", "Tip('" + txt + "', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
   tabcase.appendChild(btn);
   ligne.appendChild(tabcase);
   btable.appendChild(ligne);
   window.scroll(0,document.body.clientHeight);
   if (!GM_getValue("liensmusee", true))
   { var btd = $t("td", btable);
    var bimg = $t("img");
    for (i=0;i<bimg.length;i++)
    { if (bimg[i].src.indexOf("images/musee") != -1)
     { nom = bimg[i].src;
      numero = parseInt(nom.substring(nom.indexOf("musee")+6,nom.indexOf(".png")));
      if (numero != 0)
      { nom = nom.substring(nom.indexOf("mages")+6, nom.indexOf(".png"));
       nom = nom[0] + nom.substring(nom.indexOf("/")+1);
       bimg[i].setAttribute("onmouseout", "UnTip()");
       var enchere = unserialize(GM_getValue("enchere_" + id_zoo, ""));
       if (!enchere[nom]) enchere = "???";
       else enchere = enchere[nom];
       bimg[i].setAttribute("onmouseover", "Tip('Item " + numero + ", prix d&rsquo;achat : " + enchere + " Zoo&rsquo;z', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
       btd[numero-1].innerHTML = $t("a",btd[numero-1])[0].innerHTML;
       btd[numero-1].setAttribute("onmouseout", "UnTip()");
       btd[numero-1].setAttribute("onmouseover", "Tip('Vous avez déjà cet item, acheté au prix de " + enchere + " Zoo&rsquo;z', BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
       btd[numero-1].style.cursor = "default";
      }
     }
    }
   }
  }
  else if (/toutou.php/.test(window.location))
  { var bdiv = $t("div"), arret = false;
   for (i=bdiv.length-1;i>=0;i--) if (bdiv[i].align == "left") break;
   maction = bdiv[i].innerHTML;
   maction = maction.substring(maction.indexOf(":")+2);
   if (maction.indexOf("<a ") != -1)
   { var ba = $t("a", bdiv[i]);
    arret = true;
    window.location = ba[0];
   }
   else if (maction.indexOf("  poin") != -1)
    bdiv[i].innerHTML = bdiv[i].innerHTML.replace(maction, "Action déjà réalisée pour aujourd'hui");
   if (!arret)
   { if (GM_getValue("attraction_"+id_zoo, "") != "") // si on a une attraction exceptionnelle, on l'affiche
    { var bdiv = document.createElement("div");
     bdiv.id = "attraction";
     bdiv.className = "info_bulle";
     var txt = GM_getValue("attraction_"+id_zoo, "");
     txt = txt.substring(45);
     txt = txt.replace("achat ju", "achat<br />ju");

     // ajout de l'image de l'attraction exceptionnelle
     var img_attraction;
     if (txt.indexOf("Fennec") != -1) img_attraction = "savane_fennec.jpg";
     else if (txt.indexOf("Calamar géant") != -1) img_attraction = "aquarium_calamar geant.jpg";
     else if (txt.indexOf("Tatou") != -1) img_attraction = "terre_tatou.jpg";
     else if (txt.indexOf("Tapir") != -1) img_attraction = "foret_tapir.jpg";
     else if (txt.indexOf("Requin marteau") != -1) img_attraction = "bassin_requin marteau.jpg";
     else if (txt.indexOf("chamois") != -1) img_attraction = "foret_chamois.jpg";
     else if (txt.indexOf("gavial") != -1) img_attraction = "terre_gavial.jpg";
     else if (txt.indexOf("Cigogne") != -1) img_attraction = "voliere_cigogne blanche.jpg";
     else if (txt.indexOf("gérénuk") != -1) img_attraction = "savane_gerenuk.jpg";
     else if (txt.indexOf("Narval") != -1) img_attraction = "bassin_narval.jpg";

     if (img_attraction != "") img_attraction = "<img src=\'images/animaux/" + img_attraction + "\' height=\"80\" width=\"80\" hspace=\"6\" />";
     bdiv.innerHTML = "<div style=\"width:550px;text-align:center;font-size:14px;font-weight:bold;color:#B86242;\">Attraction exceptionnelle dans votre parc !" +
      "</div><br /><div style=\"text-align:center\">L" + txt + "</div><div align=\"center\" style=\"margin-top:20px;\">" + img_attraction +
      "<br /><br /><a style=\"cursor:pointer;\" onClick=\"document.getElementById('attraction').style.display = 'none'\">Fermer</a></div>";
     document.body.appendChild(bdiv);
     GM_deleteValue("attraction_"+id_zoo);
    }
    if (GM_getValue("tornade_"+id_zoo, "") != "")
    { var bdiv2 = document.createElement("div");
     bdiv2.id = "tornade";
     bdiv2.className = "info_bulle";
     bdiv2.innerHTML = "<br /><div style=\"width:520px;text-align:center;font-size:14px;font-weight:bold;color:#B86242;\">Alerte !!! Tornade !!!</div>" +
      "<br /><br /><div style=\"text-align:center\">Les animaux font grise mine et les visiteurs fuient...<br />Le syndicat des zoos ravagés par une " +
      "tornade vous offre<br />une prime de catastrophe climatique de 10.000 Zoo'z.<br /><br /><br /><a style=\"cursor:pointer;\" " +
      "onClick=\"document.getElementById('tornade').style.display = 'none'\">Fermer</a></div>";
     document.body.appendChild(bdiv2);
     GM_deleteValue("tornade_"+id_zoo);
    }
    if (GM_getValue("messagesauvegarde", false))
    { var bdiv3 = document.createElement("div");
     bdiv3.id = "conseil";
     bdiv3.className = "info_bulle";
     bdiv3.innerHTML = "<div style=\"width:500px;text-align:center;font-size:14px;font-weight:bold;color:#B86242;\">Vous venez de terminer le scan initial" +
      "</div><br /><div style=\"text-align:center\">Beaucoup de données ont été calculées et mises à jour.<br />Il est conseillé de fermer " +
      "Firefox maintenant (sans forcément vous déconnecter)<br />afin d'enregistrer ces données sur votre ordinateur.<br />Vous pourrez " +
      "ensuite réouvrir immédiatement votre navigateur préféré pour poursuivre normalement.<br /><br /><a style=\"cursor:pointer;\" " +
      "onClick=\"document.getElementById('conseil').style.display = 'none'\">Fermer</a></div>";
     document.body.appendChild(bdiv3);
     GM_deleteValue("messagesauvegarde");
    }
    if (GM_getValue("affnews", false))
    { var bdiv4 = document.createElement("div");
     bdiv4.id = "news";
     bdiv4.className = "info_bulle";
     bdiv4.innerHTML = "<div style=\"width:350px;text-align:center;font-size:14px;font-weight:bold;color:#B86242;\">Une news vient d'être publiée</div>" +
      "<br /><div style=\"text-align:center\"><a style=\"cursor:pointer;\" onClick=\"window.location.href='news.php'\">Cliquez ici</a> pour y accéder" +
      "<br /><br /><a style=\"cursor:pointer;\" onClick=\"document.getElementById('news').style.display = 'none'\">Fermer</a></div>";
     document.body.appendChild(bdiv4);
    }
   }
  }
  else if (/news.php/.test(window.location))
   GM_deleteValue("affnews");
  else if (/animaux.php/.test(window.location))
   tableau_vieux();
  else if (/bourse.php/.test(window.location))
  { var btd = $t("td"), espece, prixbourse = new Array();
   for (i=btd.length-1;i>=0;i--) if (btd[i].width == "239") break;
   var debi = i;
   for (i=debi;i>=0;i-=6)
   { if (btd[i].width != "239") break;
    else
    { espece = $t("b", btd[i+2])[0].innerHTML.toLowerCase();
     prixbourse[espece] = btd[i+4].innerHTML;
    }
   }
   debi = i - 1;
   for (i=debi;i>=0;i-=6)
   { if (btd[i].width != "239") break;
    else
    { espece = $t("b", btd[i+2])[0].innerHTML.toLowerCase();
     prixbourse[espece] = btd[i+4].innerHTML;
    }
   }
   GM_setValue("prixbourse", serialize(prixbourse));
   tableau_vieux();
  }
  else if ((/enclosgestion1.php/.test(window.location)) && GM_getValue("achatcouple", "") != "" && GM_getValue("achatcouple", "") != "fin") // achat de couples
  { var bimg = $t("img"), derimg;
   for (i=bimg.length-1;i>=0;i--) if (bimg[i].getAttribute("src") == "images/icones/baby.png") { derimg = i; break; }
   var ids = 0;
   for (i=derimg;i>=0;i-=4)
   { if (bimg[i].getAttribute("src") == "images/icones/baby.png")
    { ba = $t("a", bimg[i].parentNode);
     ids2 = parseInt(recherche_param(ba[0].href, "ids"));
     if (ids2 > ids) { ids = ids2; animalbonus = i-2; }
    }
    else break;
   }
   animal = bimg[animalbonus].getAttribute("src");
   animal = animal.substring(animal.indexOf("_")+1,animal.indexOf(".jpg"));
   animal = animal.replace("2", "", "g");
   achat = GM_getValue("achatcouple");
   achat = achat.substring(achat.indexOf(";")+1);
   sexe = achat.substring(achat.length-1);
   sexe = sexe == "1" ? " mâle" : "e femelle";
   achat = achat.substring(0, achat.length-1);
   if (animal != achat) // on a trouvé un animal bonus !
    alert("Bravo : en achetant un" + sexe + ", vous avez\n trouvé un animal bonus de l'espèce :\n" + animal + ".\n\nCliquez sur 'OK' pour continuer.");
   var ba = $t("a"), iloc;
   for (i=0;i<ba.length;i++) if (ba[i].innerHTML == "cliquez ici.") { iloc = i; break; }
   window.location.href = ba[iloc];
  }
  else if ((/enclosgestion1.php/.test(window.location)) && GM_getValue("cherchebonus", "") != "") // recherche d'un animal bonus
  { if (GM_getValue("pas un animal bonus", "") == "oui") // on revient de la vente de l'animal qui n'a rien donné
   { GM_deleteValue("pas un animal bonus");
    var ba = $t("a"), iloc;
    for (i=0;i<ba.length;i++) if (ba[i].innerHTML == "cliquez ici." || ba[i].innerHTML == "cliquez ici") { iloc = i; break; }
    window.location.href = ba[iloc];
   }
   else if (GM_getValue("pas un animal bonus", "") == "non") // on revient de la vente de l'animal qui a trouvé l'animal bonus
   { GM_deleteValue("pas un animal bonus");
    nbr = GM_getValue("cherchebonus");
    nbr = parseInt(nbr.substring(nbr.indexOf(";")+1));
    s = nbr>1?"s":"";
    GM_deleteValue("cherchebonus");
    var bimg = $t("img"), derimg;
    for (i=bimg.length-1;i>=0;i--) if (bimg[i].getAttribute("src") == "images/icones/baby.png") { derimg = i; break; }
    var ids = 0;
    for (i=derimg;i>=0;i-=4)
    { if (bimg[i].getAttribute("src") == "images/icones/baby.png")
     { ba = $t("a", bimg[i].parentNode);
      ids2 = parseInt(recherche_param(ba[0].href, "ids"));
      if (ids2 > ids) { ids = ids2; animalbonus = i-2; }
     }
     else break;
    }
    animal = bimg[animalbonus].getAttribute("src");
    animal = animal.substring(animal.indexOf("_")+1,animal.indexOf(".jpg"));
    sexe = animal.substring(animal.length - 1);
    if (sexe == "2") sexe = "femelle";
    else sexe = "mâle";
    animal = animal.replace("2", "", "g");
    animal = ANIMAUX[animal].nom;
    alert("Après " + nbr + " essai" + s + ", vous avez trouvé un animal bonus :\n- " + sexe + "\n- de l'espèce \"" + animal + "\"\n\nFélicitations !");
    window.location.href = window.location;
   }
   else // on vient d'acheter un animal
   { var bimg = $t("img"), derimg;
    for (i=bimg.length-1;i>=0;i--) if (bimg[i].getAttribute("src") == "images/icones/baby.png") { derimg = i; break; }
    var ids = 0;
    for (i=derimg;i>=0;i-=4)
    { if (bimg[i].getAttribute("src") == "images/icones/baby.png")
     { ba = $t("a", bimg[i].parentNode);
      ids2 = parseInt(recherche_param(ba[0].href, "ids"));
      if (ids2 > ids) { ids = ids2; animalbonus = i-2; }
     }
     else break;
    }
    animal = bimg[animalbonus].getAttribute("src");
    animal = animal.substring(animal.indexOf("_")+1,animal.indexOf(".jpg"));
    if (animal[animal.length-1] != "2") animal += "1";
    cherche = GM_getValue("cherchebonus");
    cherche = cherche.substring(0, cherche.indexOf(";"));
    if (animal == cherche) // on n'a rien trouvé, on supprime
    { GM_setValue("pas un animal bonus", "oui");
     var ba = $t("a", bimg[derimg].parentNode);
     window.location.href = ba[0];
    }
    else // c'est un animal bonus ! on supprime l'animal qu'on a acheté et on arrête
    { GM_setValue("pas un animal bonus", "non");
     var ba = $t("a", bimg[derimg].parentNode);
     numero = parseInt(recherche_param(ba[0].href, "ids")) - 1; // on recherche l'animal acheté
     for (i=derimg-4;i>=0;i-=4)
      if (bimg[i].getAttribute("src") == "images/icones/baby.png")
      { ba = $t("a", bimg[i].parentNode);
       numero2 = parseInt(recherche_param(ba[0].href, "ids"));
       if (numero2 == numero) break; // on l'a trouvé !
      }
      else { alert("il y a un pb dans le script : l'animal acheté pour trouver l'animal bonus ne semble pas exister !"); break; }
     if (numero2 == numero) window.location.href = ba[0];
     else { GM_deleteValue("pas un animal bonus"); GM_deleteValue("cherchebonus"); } // bug, on arrête tout
    }
   }
  }
  else if ((/enclosgestion1.php/.test(window.location)) && GM_getValue("venteauto", false) && GM_getValue("listevente", "") != "") // retour d'une vente auto
  { var listevente = unserialize(GM_getValue("listevente", ""));
   nextvente = listevente.shift();
   GM_setValue("listevente", serialize(listevente));
   window.location.href = nextvente;
  }
  else if (/enclosgestion1.php/.test(window.location) && GM_getValue("MAJPA", false)) // on revient de l'embauche d'employés pour la MAJ des PA
  { var btable = $t("table"), last_tablelien;
   for (i=btable.length-1;i>=0;i--)
    if (btable[i].getAttribute("bgcolor") == "#faefdb") { last_tablelien = btable[i]; break ; }
   var lienmaj = $t("a", last_tablelien); // lien pour mettre à jour tous les PA d'un coup
   lienmaj = lienmaj[0].getAttribute("href");
   GM_deleteValue("MAJPA");
   window.location.href = urlSite + lienmaj;
  }
  else if (/enclosgestion1.php/.test(window.location) && !scan && !GM_getValue("MAJPA2", false)) // enclos
  { var btd, btd2, last_tablebureau, t, v, numenclos, construit = true, enclosbulle = "", ba;
   var nom, age, tableau, s, btable, txt, old_txt, bdiv, debi;
   var mourant = false, vieux = GM_getValue("vieux", 10);
   var enclos = new Array(), liste = new Array(), numero;

   GM_deleteValue("achatcouple");
   GM_deleteValue("nbrcouples");
   GM_deleteValue("achatmale");
   GM_deleteValue("achatfemelle");
   if (GM_getValue("venteauto", false)) { GM_deleteValue("venteauto"); image_options(); modification_menu(); }

   // correction du nom de l'enclos 
   t = parseInt(recherche_param(window.location.href, "t"));
   v = parseInt(recherche_param(window.location.href, "v"));
   numenclos = t * 100 + v;
   btable = $t("table");
   if (btable[2].innerHTML.indexOf("constu") != -1) // si l'enclos a été construit
   { txt = "construit :</strong> Enclos " + nom_enclos(t, v);
    old_txt = btable[2].innerHTML.substring(btable[2].innerHTML.indexOf("constu"));
   }
   else
   { txt = "construire :</strong> Enclos " + nom_enclos(t, v);
    old_txt = btable[2].innerHTML.substring(btable[2].innerHTML.indexOf("constr"));
    construit = false;
    enclosbulle = "Enclos non construit";
   }
   old_txt = old_txt.substring(0, old_txt.indexOf("<br>"));
   btable[2].innerHTML = btable[2].innerHTML.replace(old_txt, txt);
   btable[3].setAttribute("cellspacing","2");

   if (GM_getValue("testerbonus", false)) // on vient d'acheter un animal, on teste si on a trouvé un animal bonus
   { var bimg = $t("img"), derimg;
    for (i=bimg.length-1;i>=0;i--) if (bimg[i].getAttribute("src") == "images/icones/baby.png") { derimg = i; break; }
    var ids = 0;
    for (i=derimg;i>=0;i-=4)
    { if (bimg[i].getAttribute("src") == "images/icones/baby.png")
     { ba = $t("a", bimg[i].parentNode);
      ids2 = parseInt(recherche_param(ba[0].href, "ids"));
      if (ids2 > ids) { ids = ids2; animalbonus = i-2; }
     }
     else break;
    }
    animal = bimg[animalbonus].getAttribute("src");
    animal = animal.substring(animal.indexOf("_")+1,animal.indexOf(".jpg"));
    animal = animal.replace("2", "", "g");
    if (ANIMAUX[animal].nom != "") // on a trouvé un animal bonus !
     alert("Bravo : vous venez de trouver un animal bonus de l'espèce :\n" + animal + ".\n\nCliquez sur 'OK' pour continuer.");
   }
   GM_deleteValue("testerbonus");
   if (construit) // si l'enclos est construit
   { ba = $t("a");
    for (i=0;i<ba.length;i++)
     if (ba[i].innerHTML.indexOf("cliquez ici") != -1)
     { divbis = ba[i].parentNode.innerHTML;
      nbachats = parseInt(GM_getValue("compteur_achats_" + id_zoo, 0));
      s = nbachats>1?"ux":"l";
      maxachats = parseInt(GM_getValue("maxachats_" + id_zoo, 20));
      if (nbachats < maxachats) txt = "NB : vous avez pour l'instant acheté " + nbachats + " anima" + s + " sur les " + maxachats + " possibles.";
      else txt = "NB : vous avez déjà acheté " + nbachats + " anima" + s + " sur les " + maxachats + " possibles.";
      if (divbis.indexOf("en acheter") != -1)
      { txt = "acheter.<br /><br />" + txt;
       ba[i].parentNode.innerHTML = ba[i].parentNode.innerHTML.replace("acheter.", txt);
      }
      else
      { txt = "</a><br /><br />" + txt;
       ba[i].parentNode.innerHTML = ba[i].parentNode.innerHTML.replace("</a>", txt);
      }
     }

    var oldsynthvieux = unserialize(GM_getValue("synthvieux_" + id_zoo, ""));
    var synthvieux = new Array();
    for (i in oldsynthvieux) if (parseInt(i) != numenclos) synthvieux[i] = oldsynthvieux[i];
    var oldsynthanimaux = unserialize(GM_getValue("synthanimaux_" + id_zoo, ""));
    var synthanimaux = new Array();
    for (i in oldsynthanimaux) if (parseInt(i) != numenclos) synthanimaux[i] = oldsynthanimaux[i];

    for (i=0;i<btable.length;i++) { if (btable[i].innerHTML.indexOf("bureau.php") != -1) last_tablebureau = i; }
    last_tablebureau = btable[last_tablebureau];
    btd2 = $t("td", last_tablebureau);
    if (btd2[11].innerHTML == "0" ) // si enclos vide
    { btd2[35].innerHTML = 0;
     btd2[32].id = 'grand2';
     btd2[0].innerHTML = btd2[0].innerHTML.replace("Employé simple", "Balayeur");
     enclosbulle = "Vide";
    }
    else
    { var albinos = unserialize(GM_getValue("albinos_" + id_zoo, ""));
     btable3 = $t("table")[3].innerHTML;
     debut = "";
     for (i=0;i<2;i++)
     { debut += btable3.substring(0,btable3.indexOf("</div>")+6);
      btable3 = btable3.substring(btable3.indexOf("</div>")+6);
     }
     debut = debut.substring(debut.indexOf("<div"));
     tabcase = document.createElement("td");
     tabcase.innerHTML = debut;
     tabcase.setAttribute("colspan","6");
     tabcase.setAttribute("style","width:600px");
     ligne = document.createElement("tr");
     ligne.appendChild(tabcase);
     newdiv = document.createElement("div");
     newdiv.setAttribute("style","align:center");
     newdiv.appendChild(ligne);
     newdiv2 = document.createElement("div");
     newdiv2.setAttribute("style","align:center");
     lignebis = ligne.cloneNode(true);
     newdiv2.appendChild(lignebis);

     // entourage, comptage et bulle d'info des mourants
     var nb = 0;
     btd = $t("td");
     for (debi=0;debi<btd.length;debi++)
     { bdiv = $t("div", btd[debi]);
      if (bdiv[0])
      { if (bdiv[0].innerHTML == "<strong>Les mourants</strong>")
       { mourant = true; 
        tabcase = btd[debi].parentNode.parentNode.parentNode.parentNode.parentNode.cloneNode(true);
        newdiv.appendChild(tabcase);
        ajoute_br(newdiv);
        break;
       }
      }
     }
     if (mourant)
     { debi++;
      for (i=debi;i<btd.length;i+=2)
      { if (btd[i].align == "center")
       { btd[i].setAttribute("style", "padding-top:5px;margin:1px");
        tabcase = btd[i].cloneNode(true);
        bbr = $t("br", tabcase);
        supbr = tabcase.removeChild(bbr[0]);
        nb++;
        nom = btd[i].innerHTML.substring(25);
        nom = nom.substring(nom.indexOf("_") + 1, nom.indexOf(".jpg"));
        nom = nom.replace("%20", " ", "g");
        nom = nom.replace(2, ""); // animaux à une image par sexe
        if (btd[i+1].innerHTML.indexOf("female.png") != -1) { sexe = "femelle"; nsexe = 1; }
        else { sexe = "mâle"; nsexe = 0; }
        if (!enclos[nom])
        { enclos[nom] = new Array()
         for (j=0;j<6;j++) enclos[nom][j] = 0; //01=total;23=vieux;45=futurs adultes
        }
        enclos[nom][nsexe] += 1;
        bdiv = $t("div", btd[i]);
        if (p_affichage == 1) tableau = btd[i];
        else tableau = bdiv[0];
        tableau.className = " mourant";
        enclos[nom][nsexe+2] += 1;
        if (!synthvieux[numenclos])
        { synthvieux[numenclos] = new Array();
         synthvieux[numenclos][0] = nom;
         for (j=1;j<5;j++) synthvieux[numenclos][j] = 0; //0510=especes;12=tous;34=vieux
         synthvieux[numenclos][nsexe+3] = 1;
        }
         else
         { temoin = false;
          for (j=0; j<synthvieux[numenclos].length; j+=5)
           if (synthvieux[numenclos][j] == nom) { temoin = true; synthvieux[numenclos][j+nsexe+3] = parseInt(synthvieux[numenclos][j+nsexe+3]) + 1; }
          if (!temoin)
          { synthvieux[numenclos][j] = nom;
           for (k=1;k<5;k++) synthvieux[numenclos][j+k] = 0; //0510=especes;12=tous;34=vieux
           synthvieux[numenclos][j+nsexe+3] = 1;
          }
         }
        tabcase.className = "animal " + nom.replace(" ", "%20", "g") + " " + sexe + btd[i].className;
        if (nom == "coq patriote")
        { if (sexe == "femelle") { nom = "poule"; sexe = "patriote"; }
         else { nom = "coq"; sexe = "patriote"; }
        }
        numero = btd[i+1].innerHTML.substring(btd[i+1].innerHTML.indexOf("ids")+4);
        numero = numero.substring(0, numero.indexOf("\""));
        liste[numero] = nom + " " + sexe + ", reste à vivre : 0 jour";
        tabcase.setAttribute("onmouseout", "UnTip()");
        largeur = calculelargeur(liste[numero]);
        tabcase.setAttribute("onmouseover", "Tip('" + liste[numero] +"', WIDTH, " + largeur + ", BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
        bimg = $t("img", tabcase);
        bimg[0].addEventListener("click", selvente, true);
        newdiv.appendChild(tabcase);
       }
       else break;
      }
     }
     // comptage des mâles et femelles, bulle d'info et affichage du tableau
     for (debi=0;debi<btd.length;debi++)
     { bdiv = $t("div", btd[debi]);
      if (bdiv[0])
       { if (bdiv[0].innerHTML == "<strong>Vos animaux</strong>")
        { tabcase = btd[debi].parentNode.parentNode.parentNode.parentNode.parentNode.cloneNode(true);
         newdiv.appendChild(tabcase);
         tabcase2 = tabcase.cloneNode(true);
         newdiv2.appendChild(tabcase2);
         break;
        }
       }
     }
     debi++;
     for (i=debi;i<btd.length;i+=2)
     { btd[i].setAttribute("style", "padding-top:5px;margin:1px");
      bdiv = $t("div", btd[i]);
      if (bdiv[0])
      { age = parseInt(parseFloat(bdiv[1].style.width.substring(0,bdiv[1].style.width.length - 2))/.71);
       if (age < vieux+2 || age == 99)
       { if (p_affichage == 1) tableau = btd[i];
        else tableau = bdiv[0];
        if (age < vieux+2) { tableau.className = " vieux"; btd[i].setAttribute("style", "height:123px;margin:1px;padding-top:5px;"); }
        else tableau.className = " naissance";
       }
      }
      else break;
     }
     for (i=debi;i<btd.length;i+=2)
     { if (btd[i].align == "center")
      { tabcase = btd[i].cloneNode(true);
       nb++;
       nom = btd[i].innerHTML.substring(25);
       nom = nom.substring(nom.indexOf("_") + 1, nom.indexOf(".jpg"));
       nom = nom.replace("%20", " ", "g");
       nom = nom.replace(2, ""); // animaux à une image par sexe
       if (btd[i+1].innerHTML.indexOf("female.png") != -1) { sexe = "femelle"; nsexe = 1; }
       else { sexe = "mâle"; nsexe = 0; }
       if (!enclos[nom])
       { enclos[nom] = new Array()
        for (j=0;j<6;j++) enclos[nom][j] = 0; //01=total;23=vieux;45=futurs adultes
       }
       enclos[nom][nsexe] += 1;
       bdiv = $t("div", btd[i]);
       age = parseInt(parseFloat(bdiv[1].style.width.substring(0,bdiv[1].style.width.length - 2))/.71);
       if (age < vieux+2)
       { enclos[nom][nsexe+2] += 1;
        if (!synthvieux[numenclos])
        { synthvieux[numenclos] = new Array();
         synthvieux[numenclos][0] = nom;
         for (j=1;j<5;j++) synthvieux[numenclos][j] = 0; //0510=especes;12=tous;34=vieux
         synthvieux[numenclos][nsexe+3] = 1;
        }
        else
        { temoin = false;
         for (j=0; j<synthvieux[numenclos].length; j+=5)
          if (synthvieux[numenclos][j] == nom) { temoin = true; synthvieux[numenclos][j+nsexe+3] = parseInt(synthvieux[numenclos][j+nsexe+3]) + 1; }
         if (!temoin)
         { synthvieux[numenclos][j] = nom;
          for (k=1;k<5;k++) synthvieux[numenclos][j+k] = 0; //0510=especes;12=tous;34=vieux
          synthvieux[numenclos][j+nsexe+3] = 1;
         }
        }
       }
       if (age < 95)
       { if (sexe == "mâle") enclos[nom][4] += 1;
        else enclos[nom][5] += 1;
       }
       age += -1;
       s=age > 1 ?"s":"";
       tabcase.className = "animal " + nom.replace(" ", "%20", "g") + " " + sexe + btd[i].className;
       if (nom == "coq patriote") {
        if (sexe == "femelle") { nom = "poule"; sexe = "patriote"; }
        else { nom = "coq"; sexe = "patriote"; }
       }
       numero = btd[i+1].innerHTML.substring(btd[i+1].innerHTML.indexOf("ids")+4);
       numero = numero.substring(0, numero.indexOf("\""));
       liste[numero] = nom + " " + sexe + ", reste à vivre : " + age + " jour" + s;
       tabcase.setAttribute("onmouseout", "UnTip()");
       largeur = calculelargeur(liste[numero]);
       tabcase.setAttribute("onmouseover", "Tip('" + liste[numero] +"', WIDTH, " + largeur + ", BGCOLOR, '#FFFFAA', FONTFACE, 'Courier New', FONTSIZE, '8pt', ABOVE, 'true', TEXTALIGN, 'center')");
       bimg = $t("img", tabcase);
       bimg[0].addEventListener("click", selvente, true);
       newdiv.appendChild(tabcase);
      }
      else // changer balayeur
      { btd[i+9].innerHTML = btd[i+9].innerHTML.replace("Employé simple", "Balayeur");
       break;
      }
     }
     if (synthvieux[numenclos])
     { for (i=0;i<synthvieux[numenclos].length;i+=5) // on récupère le nombre d'animaux de chaque espèce ayant des vieux
      { synthvieux[numenclos][i+1] = enclos[synthvieux[numenclos][i]][0];
       synthvieux[numenclos][i+2] = enclos[synthvieux[numenclos][i]][1];
      }
     }
     var espece;
     var especes_triees = new Array();
     for (espece in enclos)
     { especes_triees.push(espece);
      if (espece.indexOf("albinos") != -1)
      { espece_source = espece.replace(" albinos", "");
       couples_albi = Math.min(enclos[espece][0], enclos[espece][1]);
       albinos[espece_source] = new Array();
       albinos[espece_source][0] = enclos[espece][1] - couples_albi;
       albinos[espece_source][1] = enclos[espece][0] - couples_albi;
       albinos[espece_source][2] = enclos[espece][1] - enclos[espece][3] - couples_albi;
       albinos[espece_source][3] = enclos[espece][0] - enclos[espece][2] - couples_albi;
       couples_albi = Math.min(enclos[espece][4], enclos[espece][5]);
       transfertmale = Math.min(enclos[espece_source][4], enclos[espece][5] - couples_albi);
       transfertfemelle = Math.min(enclos[espece_source][5], enclos[espece][4] - couples_albi);
       enclos[espece_source][4] -= transfertmale;
       enclos[espece_source][5] -= transfertfemelle;
       enclos[espece][4] += transfertmale;
       enclos[espece][5] += transfertfemelle;
      }
     }
     GM_setValue("albinos_" + id_zoo, serialize(albinos));
     especes_triees.sort();
     for (i=0;i<especes_triees.length;i++)
      enclosbulle += especes_triees[i] +" / ";
     anim = nb>1?" animaux":" animal";
     s = especes_triees.length>1?"s":"";
     var papa = $t("table")[3].parentNode;
     papa.replaceChild(newdiv,$t("table")[3]);
     var triespecesfait = false;
     if (GM_getValue("triesp", false)) // si on trie par espèce
     { trier_espece();
      triespecesfait = true;
     }
     enclosbulle = enclosbulle.substring(0, enclosbulle.length - 3);
     enclosbulle = nb + anim + ".<br />" + especes_triees.length + " espèce" + s + " : " + enclosbulle;
     synthanimaux[numenclos] = new Array();
     i=-3;
     for (espece in enclos)
     { i+=3;
      synthanimaux[numenclos][i] = espece;
      synthanimaux[numenclos][i+1] = enclos[espece][0];
      synthanimaux[numenclos][i+2] = enclos[espece][1];
     }
    }
    GM_setValue("liste", serialize(liste));
    GM_setValue("synthvieux_" + id_zoo, serialize(synthvieux));
    GM_setValue("synthanimaux_"+id_zoo, serialize(synthanimaux));
   }

   GM_setValue("enclos", serialize(enclos));
   var touslesenclos = unserialize(GM_getValue("touslesenclos_" + id_zoo, ""));
   touslesenclos[numenclos] = enclosbulle;
   GM_setValue("touslesenclos_" + id_zoo, serialize(touslesenclos));
   if (GM_getValue("bebes", "") != "" && !(GM_getValue("filtre", false) && GM_getValue("clique", "") != "")) // on a demandé l'ouverture de la page sur les plus jeunes
   { var bstrong = $t("strong");
    window.scroll(0, position(bstrong[bstrong.length - 17])["y"] - window.innerHeight);
    GM_deleteValue("bebes");
   }
   else if (GM_getValue("retour", "") != "") // on revient d'une vente
   { window.scroll(0, parseInt(GM_getValue("retour")));
    GM_deleteValue("retour");
   }
   tableau_animaux(enclos);
  }
  else if (/enclosgestion1.php/.test(window.location) && (scan || GM_getValue("MAJPA2", false))) // on scanne tous les enclos pour le rapport ou pour les naissances théoriques
  { var param_enclos = recherche_param(window.location.href, "t") + "_" + recherche_param(window.location.href, "v");
   var touslesenclos = unserialize(GM_getValue("touslesenclos_" + id_zoo, ""));
   var bad = false, j, tot, btd, vide = false, connexion1;
   var couples, sexes, nb_th, valeur_th, felins;
   var btable = $t("table"), last_tablebureau, last_tablelien, tab_param_enclos = param_enclos.split("_");
   var numenclos = parseInt(tab_param_enclos[0]) * 100 + parseInt(tab_param_enclos[1]);
   for (i=btable.length-1;i>=0;i--)
    if (btable[i].getAttribute("cellpadding") == 4) { last_tablebureau = btable[i]; break; }
   for (i=btable.length-1;i>=0;i--)
    if (btable[i].getAttribute("bgcolor") == "#faefdb") { last_tablelien = btable[i]; break ; }
   connexion1 = GM_getValue("messages_releves_"+id_zoo, "") == ""; // si true, on scanne pour la 1ère connexion de la journée, sinon pour le rapport
   if (last_tablebureau && last_tablelien) // si l'enclos a été construit
   { btd = $t("td", last_tablebureau);
    if (!connexion1 && !GM_getValue("MAJPA2", false)) // on scanne pour le rapport
     if (GM_getValue("construit", "") != "MAJ") GM_setValue("construit", param_enclos);
    var lienmaj = $t("a", last_tablelien); // lien pour mettre à jour tous les PA d'un coup
    lienmaj = lienmaj[0].getAttribute("href");
    var PAdispo = new Array(), PAplus = new Array(), PAmoins = new Array();
    for (i=0;i<5;i++)
    { PAplus[i] = 0; PAmoins[i] = 0;
     PAdispo[i] = parseInt(btd[i].innerHTML.substring(btd[i].innerHTML.indexOf("PA dispo :")+11, btd[i].innerHTML.indexOf("</strong")));
    }
    for (i=8;i<btd.length;i+=8) // contrôle des PA
    { if (btd[i].getAttribute("id") == "grand1" || btd[i].getAttribute("id") == "grand2")
     { PA1 = parseInt(btd[i].innerHTML.substring(0, btd[i].innerHTML.indexOf("<br>")));
      if (btd[i+3].innerHTML.indexOf("<br>") == -1) PA2=parseInt(btd[i+3].innerHTML);
      else PA2=parseInt(btd[i+3].innerHTML.substring(0, btd[i+3].innerHTML.indexOf("<br>")));
      j = i/8-1;
      if (j==0 && PA2 == 0) vide = true;
      if (j==2 && vide && 
       (PA1 != PA2 || parseInt(btd[40].innerHTML.substring(0, btd[40].innerHTML.indexOf("<br>"))) != parseInt(btd[43].innerHTML.substring(0, btd[43].innerHTML.indexOf("<br>")))))
        vide = false; // si enclos vide mais réparateur ou paysagiste pas bon, on ajuste les PA avant de mettre le PA gardien à 0
      if (j==3 && vide) PA2 = 0;
      if (PA1 > PA2 && !(j==3 && vide)) bad = true;
      if (PA1 < PA2)
      { bad = true;
       PAplus[j] = Math.max(Math.ceil((PA2-PA1-PAdispo[j])/10), 0);
      }
     }
    }
    if (bad) // si les PA sont incorrects, on corrige en embauchant éventuellement
    { if (PAplus[0]+PAplus[1]+PAplus[2]+PAplus[3]+PAplus[4] == 0) // pas besoin d'embaucher
      window.location.href = urlSite + lienmaj;
     else
     { var lienplus = urlSite + "bureau.php?achat=1&j="; // lien pour embaucher
      for (i=0;i<5;i++)
      { if (PAplus[i]>0)
       { lienplus += i+1;
        PAplus[i] += -1;
        GM_setValue("plus",serialize(PAplus));
        GM_setValue("enclos", param_enclos);
        window.location.href = lienplus;
        break;
       }
      }
     }
    }  // si enclos vide mais il y a des PA gardiens, on met les PA gardien à 0
    if (!connexion1 && !bad) // on scanne pour le rapport
    { if (vide && parseInt(btd[32].innerHTML.substring(0, btd[32].innerHTML.indexOf("<br>"))) > 0)
     { var lien = $t("a", btd[31]);
      lien = urlSite + lien[0].getAttribute("href");
      bad = true;
      window.location.href = lien;
     }  // si c'est le dernier enclos, on contrôle une dernière fois les PA pour licencier éventuellement les employés en trop
     else if ((param_enclos=="1_4" || GM_getValue("construit", "") == "MAJ") && !GM_getValue("MAJPA2", false))
     { for (i=0;i<5;i++) PAmoins[i]=Math.floor(PAdispo[i]/10);
      if (PAmoins[0]+PAmoins[1]+PAmoins[2]+PAmoins[3]+PAmoins[4] != 0)
      { tot = PAmoins[0]+PAmoins[1]+PAmoins[2]+PAmoins[3]+PAmoins[4];
       GM_setValue("totalPA", "étape 0 sur " + tot);
       bad = true;
       var lienmoins = urlSite + "bureau.php?achat=1&l="; // lien pour diminuer de 10 les PA
       for (i=0;i<5;i++)
       { if (PAmoins[i]>0)
        { lienmoins += i+1;
         PAmoins[i] += -1;
         GM_setValue("moins",serialize(PAmoins));
         GM_setValue("enclos", param_enclos);
         window.location.href = lienmoins;
         break;
        }
       }
      }
     }
    }
    if (connexion1 && !bad) // si c'est la 1ère connexion de la journée
    { var mourants = unserialize(GM_getValue("mourants_" + id_zoo, "")), mourant = false, vieux = GM_getValue("vieux", 10);
     var couples15 = unserialize(GM_getValue("couples15_" + id_zoo, ""));
     var synthvieux = unserialize(GM_getValue("synthvieux_" + id_zoo, ""));
     var albinos = unserialize(GM_getValue("albinos_" + id_zoo, ""));
     var synthanimaux = unserialize(GM_getValue("synthanimaux_" + id_zoo, ""));
     var agemoyen = parseInt(GM_getValue("agemoyen_" + id_zoo, 0));
     var enclosbulle = "";
     if (parseInt(btd[11].innerHTML) > 0) // enclos non vide
     { btd = $t("td"); // on compte les couples pour en déduire les naissances théoriques
      var reg = new RegExp("(%20)", "g"), enclos = new Array(), enclosbis = new Array(), especes_triees = new Array();
      var sexe, espece, debi, bdiv, nb = 0;
      var valeurT = parseInt(GM_getValue("valeurT_" + id_zoo, 0));

      for (debi=0;debi<btd.length;debi++)
      { bdiv = $t("div", btd[debi]);
       if (bdiv[0])
        { if (bdiv[0].innerHTML == "<strong>Les mourants</strong>") { mourant = true; break; } }
      }
      if (mourant)
      { debi++;
       for (i=debi;i<btd.length;i+=2)
       { if (btd[i].align == "center")
        { nb++;
         espece = btd[i].innerHTML.substring(25);
         espece = espece.substring(espece.indexOf("_") + 1, espece.indexOf(".jpg"));
         espece = espece.replace(reg, " ");
         espece = espece.replace(2, ""); // animaux à une image par sexe
         enclosbis[espece] = "ok";
         bdiv = $t("div", btd[i]);
         valeurT += Math.round(parseInt(ANIMAUX[espece].prix) * 6 / 1000);
         agemoyen += 1;
         if (!mourants[numenclos])
         { mourants[numenclos] = new Array();
          mourants[numenclos][0] = espece;
          mourants[numenclos][1] = 1;
         }
         else
         { temoin = false;
          for (j=0; j<mourants[numenclos].length; j+=2)
           if (mourants[numenclos][j] == espece) { temoin = true; mourants[numenclos][j+1] = parseInt(mourants[numenclos][j+1]) + 1; }
          if (!temoin)
          { mourants[numenclos][j] = espece;
           mourants[numenclos][j+1] = 1;
          }
         }
         if (btd[i+1].innerHTML.indexOf("female.png") != -1) sexe = 1;
         else sexe = 0;
         if (!enclos[espece])
         { enclos[espece] = new Array()
          for (j=0;j<8;j++) enclos[espece][j] = 0; //01=adultes;23=naissances;45=adultes à la prochaine MAJ;67=tous
         }
         enclos[espece][sexe] += 1;
         enclos[espece][sexe+6] += 1;
         if (!synthvieux[numenclos])
         { synthvieux[numenclos] = new Array();
          synthvieux[numenclos][0] = espece;
          for (j=1;j<5;j++) synthvieux[numenclos][j] = 0; //0510=especes;12=tous;34=vieux
          synthvieux[numenclos][sexe+3] = 1;
         }
         else
         { temoin = false;
          for (j=0; j<synthvieux[numenclos].length; j+=5)
           if (synthvieux[numenclos][j] == espece) { temoin = true; synthvieux[numenclos][j+sexe+3] = parseInt(synthvieux[numenclos][j+sexe+3]) + 1; }
          if (!temoin)
          { synthvieux[numenclos][j] = espece;
           for (k=1;k<5;k++) synthvieux[numenclos][j+k] = 0; //0510=especes;12=tous;34=vieux
           synthvieux[numenclos][j+sexe+3] = 1;
          }
         }
        }
        else break;
       }
      }
      for (debi=0;debi<btd.length;debi++)
      { bdiv = $t("div", btd[debi]);
       if (bdiv[0])
        { if (bdiv[0].innerHTML == "<strong>Vos animaux</strong>") break; }
      }
      debi++;
      for (i=debi;i<btd.length;i+=2)
      { if (btd[i].align == "center")
       { nb++;
        espece = btd[i].innerHTML.substring(25);
        espece = espece.substring(espece.indexOf("_") + 1, espece.indexOf(".jpg"));
        espece = espece.replace(reg, " ");
        espece = espece.replace(2, ""); // animaux à une image par sexe
        enclosbis[espece] = "ok";
        bdiv = $t("div", btd[i]);
        age = parseInt(parseFloat(bdiv[1].style.width.substring(0,bdiv[1].style.width.length - 2))/.71);
        agemoyen += age;
        valeurT += Math.round(parseInt(ANIMAUX[espece].prix) * age * 6 / 1000);
        if (btd[i+1].innerHTML.indexOf("female.png") != -1) sexe = 1;
        else sexe = 0;
        if (!enclos[espece])
        { enclos[espece] = new Array()
         for (j=0;j<8;j++) enclos[espece][j] = 0; //01=adultes;23=naissances;45=adultes à la prochaine MAJ;67=tous
        }
        enclos[espece][sexe+6] += 1;
        if (age < 94)
         enclos[espece][sexe] += 1;
        if (age < 95)
         enclos[espece][sexe+4] += 1;
        if (age == 99)
         enclos[espece][sexe+2] += 1;
        if (age < vieux+2)
        { if (!synthvieux[numenclos])
         { synthvieux[numenclos] = new Array();
          synthvieux[numenclos][0] = espece;
          for (j=1;j<5;j++) synthvieux[numenclos][j] = 0; //0510=especes;12=tous;34=vieux
          synthvieux[numenclos][sexe+3] = 1;
         }
         else
         { temoin = false;
          for (j=0; j<synthvieux[numenclos].length; j+=5)
           if (synthvieux[numenclos][j] == espece) { temoin = true; synthvieux[numenclos][j+sexe+3] = parseInt(synthvieux[numenclos][j+sexe+3]) + 1; }
          if (!temoin)
          { synthvieux[numenclos][j] = espece;
           for (k=1;k<5;k++) synthvieux[numenclos][j+k] = 0; //0510=especes;12=tous;34=vieux
           synthvieux[numenclos][j+sexe+3] = 1;
          }
         }
        }
       }
       else break;
      }
      if (synthvieux[numenclos])
      { for (i=0;i<synthvieux[numenclos].length;i+=5) // on récupère le nombre d'animaux de chaque espèce ayant des vieux
       { synthvieux[numenclos][i+1] = enclos[synthvieux[numenclos][i]][6];
        synthvieux[numenclos][i+2] = enclos[synthvieux[numenclos][i]][7];
       }
      }
      couples = parseInt(GM_getValue("couples_" + id_zoo, 0));
      nb_th = parseFloat(GM_getValue("nb_th_" + id_zoo, "0"));
      sexes = unserialize(GM_getValue("sexes_" + id_zoo, "0,0;1,0;"));
      sexes[0] = parseInt(sexes[0]);
      sexes[1] = parseInt(sexes[1]);
      valeur_th = parseFloat(GM_getValue("valeur_th_" + id_zoo, "0"));
      felins = parseInt(GM_getValue("felins_" + id_zoo, 0));
      for (espece in enclos)
      { if (espece.indexOf("albinos") != -1)
       { couples_albi = Math.min(enclos[espece][6], enclos[espece][7]);
        espece_source = espece.replace(" albinos", "");
        albinos[espece_source] = new Array();
        albinos[espece_source][0] = enclos[espece][7] - couples_albi;
        albinos[espece_source][1] = enclos[espece][6] - couples_albi;
        albinos[espece_source][2] = enclos[espece][7] - couples_albi;
        albinos[espece_source][3] = enclos[espece][6] - couples_albi;
        if (synthvieux[numenclos])
        { for (i=0;i<synthvieux[numenclos].length;i+=5) // on ne tient pas compte des vieux albinos
         { if (synthvieux[numenclos][i] == espece)
          { albinos[espece_source][2] -= synthvieux[numenclos][i+4];
           albinos[espece_source][3] -= synthvieux[numenclos][i+3];
          }
         }
        }
        couples_albi = Math.min(enclos[espece][0], enclos[espece][1]);
        enclos[espece_source][0] += enclos[espece][0] - couples_albi;
        enclos[espece_source][1] += enclos[espece][1] - couples_albi;
        enclos[espece][0] = couples_albi;
        enclos[espece][1] = couples_albi;
        couples_albi = Math.min(enclos[espece][4], enclos[espece][5]);
        transfertmale = Math.min(enclos[espece_source][4], enclos[espece][5] - couples_albi);
        transfertfemelle = Math.min(enclos[espece_source][5], enclos[espece][4] - couples_albi);
        enclos[espece_source][4] -= transfertmale;
        enclos[espece_source][5] -= transfertfemelle;
        enclos[espece][4] += transfertmale;
        enclos[espece][5] += transfertfemelle;
       }
      }
      for (espece in enclos)
      { if (espece == "lion" || espece == "lion albinos" ||espece == "tigre" || espece == "panthere" || espece == "panthere noire" || espece == "lynx" ||
        espece == "tigre blanc" || espece == "guepard" || espece == "puma" || espece == "caracal")
         felins += Math.min(enclos[espece][0], enclos[espece][1]);
       couples += Math.min(enclos[espece][0], enclos[espece][1]);
       maxi = parseInt(animauxmax[espece]);
       if (enclos[espece][4] > maxi || enclos[espece][5] > maxi)
       { if (!couples15[numenclos])
         couples15[numenclos] = new Array();
        j = couples15[numenclos].length;
        couples15[numenclos][j] = espece;
        couples15[numenclos][j+1] = enclos[espece][4] > maxi ? enclos[espece][4] - maxi : 0;
        couples15[numenclos][j+1] += enclos[espece][5] > maxi ? enclos[espece][5] - maxi : 0;
       }
       if (parseInt(ANIMAUX[espece].prix) <= 100000)
       { nb_th += Math.min(enclos[espece][0], enclos[espece][1]) * 0.03;
        valeur_th += Math.min(enclos[espece][0], enclos[espece][1]) * parseInt(ANIMAUX[espece].prix) * 0.03;
       }
       else if (parseInt(ANIMAUX[espece].prix) <= 250000)
       { nb_th += Math.min(enclos[espece][0], enclos[espece][1]) * 0.0252;
        valeur_th += Math.min(enclos[espece][0], enclos[espece][1]) * parseInt(ANIMAUX[espece].prix) * 0.0252;
       }
       else if (parseInt(ANIMAUX[espece].prix) <= 500000)
       { nb_th += Math.min(enclos[espece][0], enclos[espece][1]) * 0.0242;
        valeur_th += Math.min(enclos[espece][0], enclos[espece][1]) * parseInt(ANIMAUX[espece].prix) * 0.0242;
       }
       else
       { nb_th += Math.min(enclos[espece][0], enclos[espece][1]) * 0.0227;
        valeur_th += Math.min(enclos[espece][0], enclos[espece][1]) * parseInt(ANIMAUX[espece].prix) * 0.0227;
       }
       sexes[0] += enclos[espece][2];
       sexes[1] += enclos[espece][3];
      }
      for (espece in enclosbis) especes_triees.push(espece);
      especes_triees.sort();
      for (i=0;i<especes_triees.length;i++)
       enclosbulle += especes_triees[i] +" / ";
      if (nb > 1) anim = " animaux";
      else anim = " animal";
      if (especes_triees.length > 1) s="s";
      else s="";
      enclosbulle = enclosbulle.substring(0, enclosbulle.length - 3);
      enclosbulle = nb + anim + ".<br />" + especes_triees.length + " espèce" + s + " : " + enclosbulle;
      touslesenclos[numenclos] = enclosbulle;
      synthanimaux[numenclos] = new Array();
      i=-3;
      for (espece in enclos)
      { i+=3;
       synthanimaux[numenclos][i] = espece;
       synthanimaux[numenclos][i+1] = enclos[espece][6];
       synthanimaux[numenclos][i+2] = enclos[espece][7];
      }
      GM_setValue("couples_" + id_zoo, couples);
      GM_setValue("agemoyen_" + id_zoo, agemoyen);
      GM_setValue("nb_th_" + id_zoo, (Math.round(nb_th*10000)/10000).toString());
      GM_setValue("sexes_" + id_zoo, serialize(sexes));
      GM_setValue("valeur_th_" + id_zoo, valeur_th.toString());
      GM_setValue("valeurT_" + id_zoo, valeurT);
      GM_setValue("felins_" + id_zoo, felins);
      GM_setValue("mourants_" + id_zoo, serialize(mourants));
      GM_setValue("couples15_" + id_zoo, serialize(couples15));
      GM_setValue("synthvieux_" + id_zoo, serialize(synthvieux));
      GM_setValue("albinos_" + id_zoo, serialize(albinos));
      GM_setValue("synthanimaux_" + id_zoo, serialize(synthanimaux));
      GM_setValue("touslesenclos_" + id_zoo, serialize(touslesenclos));
     }
     else
     { enclosbulle = "Vide";
      touslesenclos[numenclos] = enclosbulle;
      GM_setValue("touslesenclos_" + id_zoo, serialize(touslesenclos));
      if (GM_getValue("ordre", "") == "") derenclos = "1_4";
      else
      { numenclos = unserialize(GM_getValue("ordre", ""));
       j = 61;
       while (touslesenclos[numenclos[j]] == "Enclos non construit") j--;
       numenclos = parseInt(numenclos[j]);
       derenclos = Math.floor(numenclos/100) + "_";
       numenclos = numenclos - Math.floor(numenclos/100)*100;
       derenclos += numenclos;
      }
      if (param_enclos == derenclos)
      { couples = parseInt(GM_getValue("couples_" + id_zoo, 0));
       agemoyen = parseInt(GM_getValue("agemoyen_" + id_zoo, 0));
       nb_th = parseFloat(GM_getValue("nb_th_" + id_zoo, "0"));
       valeur_th = parseFloat(GM_getValue("valeur_th_" + id_zoo, "0"));
       valeurT = parseInt(GM_getValue("valeurT_" + id_zoo, 0));
       sexes = unserialize(GM_getValue("sexes_" + id_zoo, "0,0;1,0;"));
       sexes[0] = parseInt(sexes[0]);
       sexes[1] = parseInt(sexes[1]);
      }
     }
    }
   } // enclos insectarium pas construit et scan pour le rapport
   else if (param_enclos=="1_4" && GM_getValue("construit", "") != "" && GM_getValue("construit", "") != "MAJ" && !GM_getValue("MAJPA2", false))
   { bad = true;
    param_enclos = GM_getValue("construit");
    tab_param_enclos = param_enclos.split("_");
    GM_setValue("construit", "MAJ");
    window.location.href = urlSite + "enclosgestion1.php?t=" + tab_param_enclos[0] + "&v=" + tab_param_enclos[1];
   } // scan pour le rapport et aucun enclos construit, on affiche le rapport
   else if (param_enclos=="1_4" && GM_getValue("construit", "") == "" && !GM_getValue("MAJPA2", false))
   { bad = true;
    rapport();
   }

   if (!bad && !GM_getValue("MAJPA2", false)) // on passe à l'enclos suivant
   { var next_enclos = "";
    if (GM_getValue("construit", "") != "MAJ")
    { if (GM_getValue("ordre", "") == "")
     { numenclos = new Array();
      for (i=0;i<16;i++) numenclos[i] = i;
      for (i=20;i<61;i++) numenclos[i-4] = i;
      for (i=100;i<105;i++) numenclos[i-43] = i;
      GM_setValue("ordre", serialize(numenclos));
     }
     else numenclos = unserialize(GM_getValue("ordre", ""));
     i = parseInt(tab_param_enclos[0]) * 100 + parseInt(tab_param_enclos[1]);
     j = 0;
     while (parseInt(numenclos[j]) != i) j++;
     j++;
     if (!connexion1) while (touslesenclos[numenclos[j]] == "Enclos non construit" && j < 62) j++;
     else while ((touslesenclos[numenclos[j]] == "Enclos non construit" || touslesenclos[numenclos[j]] == "Vide") && j < 62) j++;
     if (j < 62)
     { numenclos = parseInt(numenclos[j]);
      next_enclos = Math.floor(numenclos/100) + "_";
      numenclos = numenclos - Math.floor(numenclos/100)*100;
      next_enclos += numenclos;
     }
    }
    if (next_enclos != "")
     window.location.href = urlSite + "enclosgestion1.php?t=" + next_enclos.substring(0, next_enclos.indexOf("_")) +
      "&v=" + next_enclos.substring(next_enclos.indexOf("_")+1);
    else
    { GM_deleteValue("ordre");
     if (connexion1) // on a fini le scan pour les naissances théoriques
     { trienclosavoir();
      var tableau = unserialize(GM_getValue("string_naissances_"+id_zoo, ""));
      var nb = 0, valeur = 0, moyenne = 0, nbanim = 0;
      for (numenclos in tableau)
      { for (i=0;i<tableau[numenclos].length;i+=2)
       { nb += parseInt(tableau[numenclos][i+1]);
        valeur += parseInt(ANIMAUX[tableau[numenclos][i]].prix * parseInt(tableau[numenclos][i+1]));
       }
      }
      if (nb > 0) moyenne = Math.round(valeur/nb);
      touslesenclos = unserialize(GM_getValue("touslesenclos_" + id_zoo, ""));
      for (i in touslesenclos)
      { if (touslesenclos[i] != "Vide" && touslesenclos[i] != "Enclos non construit")
        nbanim += parseInt(touslesenclos[i].substring(0, touslesenclos[i].indexOf(" ")));
      }
      if (nbanim > 0) agemoyen = Math.round(100 * agemoyen / nbanim) / 100;
      else agemoyen = 0;
      moy_th = nb_th > 0 ? Math.round(valeur_th/nb_th) : 0;
      var suivi = aujourd_hui + ":" + millier(couples) + "/" + millier(valeurT)+ "/" + millier(nbanim)+ "/" + agemoyen  + "," + nb + "/" + Math.round(100*nb_th)/100 + "," +
       millier(valeur) + "/" + millier(Math.round(valeur_th)) + "," + millier(moyenne) + "/" + millier(moy_th) +
       "," + sexes[0] + "/" + sexes[1] + ";"; // a/c du 5/1/10, valeurT à la place de valeurC
      suivi = GM_getValue("suivi_naissances_"+id_zoo, "") + suivi;
      GM_setValue("suivi_naissances_"+id_zoo, suivi);
      GM_setValue("messagesauvegarde", true);
      window.location.href = urlSite + "bureau4.php";
     }
     else // on a fini le scan pour le rapport, on vérifie les stocks
     { GM_deleteValue("construit");
      window.location.href = urlSite + "bureau4.php";
     }
    }
   }
   else if (!bad && GM_getValue("MAJPA2", false))
   { GM_deleteValue("MAJPA2");
    window.location.href = urlSite + "enclosgestion1.php?t=" + tab_param_enclos[0] + "&v=" + tab_param_enclos[1];
   }
  }
  else if (/oeuf.php/.test(window.location) && GM_getValue("messages_releves_"+id_zoo, "") == "" && scan)
  { var btable = $t("table");
   var btn = document.createElement("input");
   btn.type = "button";
   btn.value = "Cliquez ici pour continuer";
   btn.addEventListener("click", lancerscan, true);
   var bligne = document.createElement("tr");
   var bcase = document.createElement("td");
   bcase.setAttribute("align", "center");
   bcase.appendChild(btn);
   bligne.appendChild(bcase);
   btable[0].appendChild(bligne);
   GM_setValue("oeuf_"+id_zoo, "oeuf3");
  }
  else if (/bureau.php/.test(window.location))
  { if (scan || GM_getValue("MAJPA", false)) // si on est entrain de scanner, on embauche ou licencie ce qui va bien
   { var PAplus = unserialize(GM_getValue("plus","0,0;1,0;2,0;3,0;4,0;"));
    var PAmoins = unserialize(GM_getValue("moins","0,0;1,0;2,0;3,0;4,0;"));
    for (i=0;i<5;i++) { PAplus[i] = parseInt(PAplus[i]); PAmoins[i] = parseInt(PAmoins[i]); }
    var enclos = GM_getValue("enclos");
    var url = urlSite + "enclosgestion1.php?t=" + enclos.substring(0, enclos.indexOf("_")) + "&v=" + enclos.substring(enclos.indexOf("_")+1);
    if (PAplus[0]+PAplus[1]+PAplus[2]+PAplus[3]+PAplus[4] == 0)
    { if (PAmoins[0]+PAmoins[1]+PAmoins[2]+PAmoins[3]+PAmoins[4] == 0)
     { if (GM_getValue("totalPA", "") != "")
      { patience("PA");
       GM_deleteValue("totalPA");
      }
      GM_deleteValue("enclos");
      window.location.href = url;
     }
     else
     { var lienmoins = urlSite + "bureau.php?achat=1&l=";
      patience("PA");
      for (i=0;i<5;i++)
      { if (PAmoins[i]>0)
       { lienmoins += i+1;
        PAmoins[i] += -1;
        GM_setValue("moins",serialize(PAmoins));
        window.location.href = lienmoins;
        break;
       }
      }
     }
    }
    else
    { var lienplus = urlSite + "bureau.php?achat=1&j=";
     for (i=0;i<5;i++)
     { if (PAplus[i]>0)
      { lienplus += i+1;
       PAplus[i] += -1;
       GM_setValue("plus",serialize(PAplus));
       window.location.href = lienplus;
       break;
      }
     }
    }
   }
   else // on corrige l'employé simple en balayeur
   { var bspan = $t("span");
    var txt = bspan[0].innerHTML;
    txt = txt.replace("employé(s) simple(s)","balayeur(s)");
    bspan[0].innerHTML = txt;
    var ba = $t("a");
    txt = ba[41].innerHTML;
    txt = txt.replace("employé simple","balayeur");
    ba[41].innerHTML = txt;
   }
  }
  else if (/event.php/.test(window.location) && GM_getValue("messages_releves_"+id_zoo, "") == "") // relevé des messages lors de la 1ère connexion du jour
  { reecriture_url();
   var tab_naissances = new Array();
   tab_naissances = unserialize(GM_getValue("string_naissances_"+id_zoo, ""));

   var messages = $t("div"), bug = false;
   var contenu_div = "", nom_naissance = "", txt ="", enclos, t, v;
   for (i=0;i<messages.length;i++)
   { if (messages[i].style.width == "560px") // c'est un message
    { if (messages[i].innerHTML.indexOf("Grand moment dans votre parc") != -1) // c'est une naissance
     { contenu_div = messages[i].innerHTML;
      contenu_div = contenu_div.substring(contenu_div.indexOf("eventid=")+8);
      nom_naissance = contenu_div.substring(contenu_div.indexOf("Grand moment dans votre parc, un")+38, contenu_div.indexOf(" vient de voir le jour"));
      enclos = contenu_div.substring(contenu_div.indexOf("href")+6,contenu_div.indexOf("\">Cl"));
      enclos = enclos.replace("amp;","");
      t = parseInt(recherche_param(enclos,"t"));
      v = parseInt(recherche_param(enclos,"v"));
      if (nom_enclos(t, v) != "bad")
      {
       enclos = t*100 + v;
       if (!tab_naissances[enclos])
       { tab_naissances[enclos] = new Array();
        tab_naissances[enclos][0] = nom_naissance;
        tab_naissances[enclos][1] = 1;
       }
       else
       { temoin = false;
        for (i=0; i<tab_naissances[enclos].length; i+=2)
         if (tab_naissances[enclos][i] == nom_naissance) { temoin = true; tab_naissances[enclos][i+1] = parseInt(tab_naissances[enclos][i+1]) + 1; }
        if (!temoin)
        { tab_naissances[enclos][i] = nom_naissance;
         tab_naissances[enclos][i+1] = 1;
        }
       }
      }
      else
      { alert("BUG ! BUG ! BUG ! de monzoo.net !!!\n\nUn animal est né dans un enclos qui n'existe pas !\nNom de l'animal : " +
        nom_naissance + "\nEnclos : " + enclos + "\n\nMerci de me transmettre ces éléments sur :\n                 " +
        "http://userscripts.org/scripts/show/63727\npour une prise en compte dans une prochaine version du script.\n\n" +
        "En attendant, arrêt du scan ! Désolé !");
       GM_setValue("messages_releves_"+id_zoo, "ok");
       GM_deleteValue("scan");
       scan = false;
       GM_deleteValue("ordre");
       GM_deleteValue("trouvaille");
       trouvaille = false;
       image_options();
       modification_menu();
       bug = true;
       break;
      }
     }
     else if (messages[i].innerHTML.indexOf("Attraction exceptionnelle") != -1) // c'est une attraction exceptionnelle
     { txt = messages[i].innerHTML.substring(messages[i].innerHTML.indexOf("Attraction exceptionnelle"));
      GM_setValue("attraction_"+id_zoo, txt);
     }
     else if (messages[i].innerHTML.indexOf("Alerte") != -1) // c'est une tornade
     { txt = messages[i].innerHTML;
      GM_setValue("tornade_"+id_zoo, "ok");
     }
     else if (messages[i].innerHTML.indexOf("oeuf") != -1) // un mystérieux oeuf est apparu
      GM_setValue("oeuf_"+id_zoo, "oeuf1");
    }
   }
   if (!bug)
   { GM_setValue("string_naissances_"+id_zoo, serialize(tab_naissances));
    // si on a plus de 20 messages, on passe à la page suivante
    var tous_liens = $t("a"), suivant = false;
    for (i=0;i<tous_liens.length;i++)
    { if (tous_liens[i].innerHTML == "[ Les 20 suivants ]")
     { suivant = true;
      window.location.href = tous_liens[i].href;
      break;
     }
    }
    if (!suivant)
    { GM_setValue("couples_" + id_zoo, 0);
     GM_setValue("agemoyen_" + id_zoo, 0);
     GM_setValue("nb_th_" + id_zoo, "0");
     GM_setValue("sexes_" + id_zoo, "0,0;1,0;");
     GM_setValue("valeur_th_" + id_zoo, "0");
     GM_setValue("valeurT_" + id_zoo, 0);
     GM_setValue("felins_" + id_zoo, 0);
     var prix = new Array(), numenclos = new Array(), j, temp;
     for (i=0;i<16;i++) prix[i] = 0;
     for (i=20;i<61;i++) prix[i] = 0;
     for (i=100;i<105;i++) prix[i] = 0;
     for (enclos in tab_naissances)
     { for (i=0;i<tab_naissances[enclos].length;i+=2)
      { if (i == 0) prix[enclos] = ANIMAUX[tab_naissances[enclos][i]].prix;
       else if (prix[enclos] < ANIMAUX[tab_naissances[enclos][i]].prix) prix[enclos] = ANIMAUX[tab_naissances[enclos][i]].prix;
      }
     }
     for (i in prix) numenclos.push(i);
     for (i=0;i<numenclos.length;i++)
      for (j=i+1;j<numenclos.length;j++)
      { if (prix[numenclos[j]] > prix[numenclos[i]])
       { enclos = numenclos[j];
        numenclos[j] = numenclos[i];
        numenclos[i] = enclos;
       }
      }
     enclos = 0;
     while (prix[numenclos[enclos]] > 0 && enclos < 61) enclos++;
     for (i=enclos;i<numenclos.length;i++)
      for (j=i+1;j<numenclos.length;j++)
      { if (parseInt(numenclos[j]) < parseInt(numenclos[i]))
       { temp = numenclos[j];
        numenclos[j] = numenclos[i];
        numenclos[i] = temp;
       }
      }
     GM_setValue("ordre", serialize(numenclos));
     GM_setValue("scan", true); // on démarre le scan pour les naissances théoriques
     if (GM_getValue("oeuf_"+id_zoo, "") == "oeuf1") // si on a une oeuf mystérieux, on l'affiche
     { GM_setValue("oeuf_"+id_zoo, "oeuf2");
      window.location.href = urlSite + "oeuf.php";
     }
     else
     { txt = urlSite + "enclosgestion1.php?t=";
      j = 0;
      var touslesenclos = unserialize(GM_getValue("touslesenclos_" + id_zoo, ""));
      while ((touslesenclos[numenclos[j]] == "Enclos non construit" || touslesenclos[numenclos[j]] == "Vide") && j < 62) j++;
      if (j < 62)
      { var num = parseInt(numenclos[j]);
       txt += Math.floor(num/100) + "&v=";
       num = num - Math.floor(num/100)*100;
       txt += num;
       window.location.href = txt;
      }
      else // on n'a construit aucun enclos ou ils sont tous vides
      { GM_deleteValue("ordre");
       var suivi = aujourd_hui + ":0/0/0/0,0/0,0/0,0/0,0/0;";
       suivi = GM_getValue("suivi_naissances_"+id_zoo, "") + suivi;
       GM_setValue("suivi_naissances_"+id_zoo, suivi);
       GM_setValue("messagesauvegarde", true);
       window.location.href = urlSite + "bureau4.php";
      }
     }
    }
   }
  }
  else if (/event.php/.test(window.location)) // page des messages en cours de jeu
  { reecriture_url();
   var messages = $t("div");
   if (!trouvaille) // on est en consultation simple
   { for (i=0;i<messages.length;i++)
    { if (messages[i].style.width == "560px")
     { if (messages[i].innerHTML.indexOf("en clos") != -1)
       messages[i].innerHTML = messages[i].innerHTML.replace("en clos","enclos","g");
      if (messages[i].innerHTML.indexOf("Cette dernière a été ajouté ") != -1)
       messages[i].innerHTML = messages[i].innerHTML.replace("Cette dernière a été ajouté ", "Cette dernière a été ajoutée ","g");
     }
    }
    enclos_naissances();
   }
   if (trouvaille) // on est en train de vérifier les messages
   { var tab_trouvailles = unserialize(GM_getValue("string_trouvailles_"+id_zoo, ""));
    var tab_vols = unserialize(GM_getValue("string_vols_"+id_zoo, ""));
    var contenu_div = "", nom_trouvaille = "", temoin;
    for (i=0;i<messages.length;i++)
    { if (messages[i].style.width == "560px")
     { if (messages[i].innerHTML.indexOf("Vous venez de trouver u") != -1  && messages[i].innerHTML.indexOf("oeuf") == -1) // c'est une trouvaille
      { contenu_div = messages[i].innerHTML;
       nom_trouvaille = contenu_div.substring(contenu_div.indexOf("Vous venez de trouver u")+23);
       nom_trouvaille = nom_trouvaille.substring(nom_trouvaille.indexOf(" ")+1, nom_trouvaille.indexOf(".")).noAccent();
       if (nom_trouvaille.indexOf("bonus") != -1) nom_trouvaille = nom_trouvaille.substring(0,nom_trouvaille.indexOf(" bonus"));
       if (nom_trouvaille == "rainette") nom_trouvaille = "rainette verte";
       if (!tab_trouvailles[0])
       { tab_trouvailles[0] = new Array();
        tab_trouvailles[0][0] = nom_trouvaille;
        tab_trouvailles[0][1] = 1;
       }
       else
       { temoin = false;
        for (i=0; i<tab_trouvailles[0].length; i+=2)
         if (tab_trouvailles[0][i] == nom_trouvaille) { temoin = true; tab_trouvailles[0][i+1] = parseInt(tab_trouvailles[0][i+1]) + 1; }
        if (!temoin)
        { tab_trouvailles[0][i] = nom_trouvaille;
         tab_trouvailles[0][i+1] = 1;
        }
       }
      }
      if (messages[i].innerHTML.indexOf("Catastrophe, un espion") != -1) // on s'est fait voler quelque chose
      { contenu_div = messages[i].innerHTML;
       contenu_div = contenu_div.substring(contenu_div.indexOf("eventid=")+8);
       id = contenu_div.substring(0, contenu_div.indexOf("\""));
       if (!tab_vols[id])
       { contenu_div = contenu_div.substring(contenu_div.indexOf("vous voler")+17);
        tab_vols[id] = "on vous a volé un animal de l'espèce " + contenu_div;
        alert("Catastrophe, " + tab_vols[id] + " !\n\nCliquez sur 'OK' pour continuer.");
       }
      }
     }
    }
    GM_setValue("string_trouvailles_"+id_zoo, serialize(tab_trouvailles));
    GM_setValue("string_vols_"+id_zoo, serialize(tab_vols));
    // si on a plus de 20 messages, on passe à la page suivante
    var tous_liens = $t("a"), suivant = false;
    for (var i=0;i<tous_liens.length;i++)
    { if (tous_liens[i].innerHTML == "[ Les 20 suivants ]")
     { suivant = true;
      window.location.href = tous_liens[i].href;
      break;
     }
    }
    if (!suivant) rapport();
   }
  }
  else if (/espion.php/.test(window.location)) // page des espions
  { var binput = $t("input");
   var restant = binput[0].parentNode.innerHTML;
   restant = parseInt(restant.substring(restant.indexOf("il vous") + 22, restant.indexOf(" espion")));
   var finscan = GM_getValue("messages_releves_"+id_zoo, "") == "";
   if (restant > 0)
   { if (!GM_getValue("espions", false) && !finscan)
    { var bdiv = binput[0].parentNode.parentNode;
     var btn = document.createElement("input");
     btn.type = "button";
     btn.value = "Envoyer tous les espions restants";
     btn.addEventListener("click", lancerespions, true);
     ajoute_br(bdiv);
     bdiv.appendChild(btn);
    }
    else binput[0].style.visibility = "hidden";
   }
   else
   { if (GM_getValue("espions", false))
    { GM_deleteValue("espions");
     image_options();
     modification_menu();
    }
    binput[0].style.visibility = "hidden";
   }
   bdiv = $t("div");
   for (i=0;i<bdiv.length;i++)
   { if (bdiv[i].style.width == "570px")
    { if (bdiv[i].innerHTML.indexOf("Votre espion a r") != -1) // s'il y a un vol, enregistrement pour l'intégrer au rapport
     { var nom_vol = bdiv[i].innerHTML.substring(bdiv[i].innerHTML.indexOf("Votre espion a r") + 67,
       bdiv[i].innerHTML.indexOf("Ce dernier a ")).replace(/<br>|<br \/>/g, "");
      var prix_vol = bdiv[i].innerHTML.substring(bdiv[i].innerHTML.indexOf("Ce dernier a ") + 70);
      var tab_vols = unserialize(GM_getValue("string_vols_"+id_zoo, "")), id_vol = tab_vols.length;
      tab_vols[id_vol] = nom_vol + " pour " + prix_vol;
      GM_setValue("string_vols_"+id_zoo, serialize(tab_vols));
      txt = "Un de vos espions a réussi à voler un animal :\n- de l'espèce " + nom_vol + "\n- pour un montant de " + prix_vol;
      if (restant > 0) txt += "\n\nCliquez sur 'OK' pour envoyer les espions restants.";
      alert(txt);
     }
    break;
    }
   }
   if (GM_getValue("espions", false) || (finscan && restant > 0)) binput[0].dispatchEvent(clickmouse);
   else if (finscan)
   { GM_setValue("messages_releves_"+id_zoo, "ok");
    window.location.href = urlSite + "toutou.php";
   }
  }
  else if (GM_getValue("messages_releves_"+id_zoo, "") == "") // première connexion de la journée, on démarre par une consultation de la liste des messages
  { GM_setValue("dateConnexion_"+id_zoo, aujourd_hui);
   window.location.href = urlSite + "event.php";
  }

  if (!scan && !trouvaille && GM_getValue("encherir", "") == "" && GM_getValue("messages_releves_"+id_zoo, "") != "" && GM_getValue("achatcouple","") == "" && GM_getValue("cherchebonus","") == "" && !GM_getValue("espions", false) && !GM_getValue("boutique", false) && !GM_getValue("venteauto", false)) // si on n'est pas en train de scanner, on affiche les liens
   lien_enclos(true);
 }
}
else if(/virtualgamessc.com/.test(window.location)) // on est sur le forum
{ if ($("toolbar"))
 { var bspan;
  // on supprime les espaces blancs en fin de toolbar
  while ($("toolbar").lastChild.nodeName == "span" || $("toolbar").lastChild.nodeName == "SPAN")
  { bspan = $("toolbar").lastChild;
   $("toolbar").removeChild(bspan);
  }
  bspan = document.createElement("span");
  bspan.style.padding = "0px 2px 0px 0px";
  $("toolbar").appendChild(bspan);

  var img_naissances = document.createElement("img");
  img_naissances.src = "http://img16.imageshack.us/img16/4205/trombones004.gif";
  img_naissances.title = "Naissances de mes zoos";
  img_naissances.alt = "Mes naissances";
  if (tab_zoo.length > 1)
  { img_naissances.addEventListener("click", montre_zoos, true);
   $("toolbar").appendChild(img_naissances);

   var bdiv = document.createElement("div");
   bdiv.id = "liste_zoo";
   bdiv.style.padding = "5px";
   bdiv.style.display = "none";

   for (i=0;i<tab_zoo.length;i++)
   { bspan = document.createElement("span");
    bspan.setAttribute("class","lien_naissances");

    var ba = document.createElement("a");
    ba.innerHTML = tab_zoo[i][0];
    ba.id = tab_zoo[i][0];
    ba.addEventListener("click", insere_liste, true);

    bspan.appendChild(ba)
    bdiv.appendChild(bspan);
   }
   ajoute_br(bdiv);
   $("smilies").parentNode.insertBefore(bdiv, $("smilies"));
  }
  else
  { img_naissances.addEventListener("click", insere_liste, true);
   img_naissances.id = tab_zoo[0][0];
   $("toolbar").appendChild(img_naissances);
  }
 }
 hautbasforum();
}
else
{ aujourd_hui = new Date();
 var numconnect = 2;
 if (aujourd_hui.getHours()<14) numconnect = 1;
 aujourd_hui = aujourd_hui.getDate()+"/"+(aujourd_hui.getMonth()+1)+"/"+aujourd_hui.getFullYear()+"/"+numconnect;
 GM_setValue("aujourd_hui", aujourd_hui);
 mise_a_jour();
}

0 comments:

Post a Comment