var xhr_object = new Array(null, null, null, null, null);
var lastobj = null;

var scrOfX = 0, scrOfY = 0;
var mouse_x=0; var mouse_y=0;

function getScrollXY()
{
  if( typeof( window.pageYOffset ) == 'number' )
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
}

function mouseMove (evt)
{
  getScrollXY();

	if (document.all)
  {
    mouse_x=event.clientX + scrOfX;
    mouse_y=event.clientY + scrOfY;
	}
  else if (document.getElementById)
  {
		mouse_x=evt.clientX + scrOfX;
    mouse_y=evt.clientY + scrOfY;
	}
}
if (document.layers || document.all)
  document.onmousemove = mouseMove;
if (document.addEventListener)
  document.addEventListener('mousemove', mouseMove, true);

//******************************************************************************
function affiche_table(id_match)
{
  obj = document.getElementById('extra_' + id_match);
  obj.style.display = obj.style.display==''?'none':'';
  return false;
}

//******************************************************************************
function majLive(idSport, idChamp, idPays, date_debut, date_fin, limite_temps)
{
  var url = 'ajax_live.php?idSport='+idSport+'&idChamp='+idChamp+'&idPays='+idPays+
            '&date_debut='+date_debut+'&date_fin='+date_fin+'&limite_temps='+limite_temps;
  if (idSport == 1)
    appelAjax(null, url, true, callbackLiveFoot, 0);
  else if (idSport == 2)
    appelAjax(null, url, true, callbackLiveTennis, 0);

}

//******************************************************************************
var callbackLiveFoot = function getCallbackLiveFoot()
{
  if ((xhr_object[0].readyState == 4))
  {
    document.body.style.cursor = 'default';
    s = xhr_object[0].responseText;
    if (s != '')
    {
      var table = s.split('$$');
      datenow = table[0];
      var nouveauBut = false;

      d = table[1];
      var eltdate = d.split('#');
      var madate = new Date(eltdate[5], (eltdate[4]-1), eltdate[3], eltdate[2], eltdate[1], eltdate[0]);
      for (i=0; i<tabMatch.length;i++)
      {
        // On retire toutes les alertes changement de scores
        if ((tabAlerte[tabMatch[i]]) && (tabAlerte[tabMatch[i]]>0))
        {
          tabAlerte[tabMatch[i]]--;
          if (tabAlerte[tabMatch[i]]==0)
            document.getElementById('score_'+tabMatch[i]).className = 'normalScore';
        }

        // On met à jour la date
        if (tableTemps[tabMatch[i]])
        {
          if ((tableMiTemps[tabMatch[i]]==1) || (tableMiTemps[tabMatch[i]]==3) || (tableMiTemps[tabMatch[i]]==4))
          {
            var minute = Math.round((madate - tableTemps[tabMatch[i]])/60000);
            if ((tableMiTemps[tabMatch[i]]==1) && (minute>45))
              minute = 45;
            else if (tableMiTemps[tabMatch[i]]==3)
            {
              minute+= 45;
              if (minute>90)
                minute = 90;
            }
            else if (tableMiTemps[tabMatch[i]]==4)
            {
              minute+= 90;
              if (minute>120)
                minute = 120;
            }
            document.getElementById('date_'+tabMatch[i]).innerHTML = minute+"' <img src='images/live.gif' alt='live' align='absmiddle' />";
          }
        }
      }

      // Traitement des modifications de scores
      if (table[2] != '')
      {
        change_cache = false;
        var tableMatch = table[2].split('#$#');
        for (i=0; i < tableMatch.length; i++)
          if (tableMatch[i] != '')
          {
            var elt = tableMatch[i].split('#');
            id = elt[0];
            etat = elt[1];
            score = elt[2];
            score_mt = elt[10];
            penaltys = elt[11];
            mitemps = elt[3];
            if (tableMiTemps[id])
              monetat = tableMiTemps[id];
            else
              monetat = 0;

            var vainqueur = 0;
            score_complet = score + score_mt;
            if (etat == 5)
            {
              var p1 = (penaltys>>16);
              var p2 = (penaltys&0xff);
              score += '<br/>(' + score_pen + ' ' + p1 + '-' + $p2 + ')';
              vainqueur = p1>p2?1:2;
            }

            obj = document.getElementById('score_'+id);
            if (obj && (score_complet != obj.innerHTML))
            {
              if ((obj.innerHTML != '-') && (etat != 3) && (score != obj.innerHTML))
              {
                obj.className = 'alerteScore';
                tabAlerte[id] = 6;

                var ligne = document.getElementById('ligne_'+id);
                if ((ligne) && (ligne.style.display == ""))
                  nouveauBut = true;
              }
              obj.innerHTML = score_complet;
            }

            if ((etat>1) && (mitemps!=monetat))
            {
              if (monetat==0)
              {
                obj2 = document.getElementById('score2_'+id);
                obj2.innerHTML = '';
              }

              if (tableEtat[id] != etat)
              {
                tableEtat[id] = etat;

                if ((etat==2) || (etat==7))
                  ischeck = document.getElementById('aff_encours').checked;
                else if (etat>=3)
                {
                  if (etat==3)
                  {
                    if (vainqueur==0)
                    {
                      var sco = elt[2].split(' - ');
                      if (sco[0] > sco[1])
                        vainqueur = 1;
                      else if (sco[0] < sco[1])
                        vainqueur = 2;
                    }

                    obj = document.getElementById('joueur'+vainqueur+'_'+id);
                    if (obj)
                      obj.className = 'vainqueur';
                  }
                  ischeck = document.getElementById('aff_termine').checked;
                }

                var ligne = document.getElementById('ligne_'+id);
                if (ligne)
                {
                  var affiche = (ligne.style.display=='');
                  if ((affiche!=ischeck) && ((!ischeck) || (!(tabRetire[id] == 1))))
                  {
                    ligne.style.display = ischeck?"":"none";
                    var ligne = document.getElementById('ligne2_'+id);
                    if (ligne)
                      ligne.style.display = ischeck?"":"none";
                    change_cache = true;
                  }

                }
              }
              tableTemps[id] = new Date(elt[4], elt[5], elt[6], elt[7], elt[8], elt[9]);
              tableMiTemps[id] = mitemps;

              if ((tableMiTemps[id]==1) || (tableMiTemps[id]==3) || (tableMiTemps[id]==4))
              {
                minuteEx = '';
                var minute = Math.round((madate - tableTemps[id])/60000);
                if ((tableMiTemps[id]==1) && (minute>45))
                  minute = 45;
                else if (tableMiTemps[id]==3)
                {
                  minute+= 45;
                  if (minute>90)
                    minute = 90;
                }
                else if (tableMiTemps[id]==4)
                {
                  minute+= 80;
                  if (minute>120)
                    minute = 120;
                  else if (minute<90)
                    minute = 90;
                  minuteEx = ' (' + live_prolong + ')';
                }
                document.getElementById('date_'+id).innerHTML = minute+"' <img src='images/live.gif' alt='live' align='absmiddle' />"+minuteEx;
              }
              else if (tableMiTemps[id]==2)
                document.getElementById('date_'+id).innerHTML = live_mt;
              else if (tableMiTemps[id]==5)
                document.getElementById('date_'+id).innerHTML = live_penaltys;
              else if (etat==4)
                document.getElementById('date_'+id).innerHTML = live_reporte;
              else if (etat==7)
                document.getElementById('date_'+id).innerHTML = live_interrompu;
              else if (etat==8)
                document.getElementById('date_'+id).innerHTML = live_annule;
              else
                document.getElementById('date_'+id).innerHTML = live_termine;
            }
          }
        if (change_cache)
          changeAffMatchSimple();
      }

      // Traitement des modifications de buteurs
      if (table[3] != '')
      {
        var tableButeur = table[3].split('#$#');
        for (i=0; i < tableButeur.length; i++)
          if (tableButeur[i] != '')
          {
            var elt = tableButeur[i].split('#');
            id = elt[0];
            minute = elt[4];

            if (minute == -1)
            {
              obj = document.getElementById('buteur_'+id);
              if (obj)
              {
                obj.innerHTML = '';
                obj.style.display = 'none';
              }
            }
            else
            {
              id_match = elt[1];
              nom = elt[2];

              obj = document.getElementById('equipe1_'+id_match);
              if (obj)
              {
                var extra = '';
                inversion = false;

                switch(elt[5])
                {
                  case '1': extra = ' - '+live_pen; break;
                  case '2': extra = ' - '+live_csc; inversion = true; break;
                }

                eq1 = document.getElementById('equipe1_'+id_match).value;
                var is1 = (((eq1 == elt[3]) && (!inversion)) || ((eq1 != elt[3]) && (inversion)));

                if (is1)
                  obj = document.getElementById('buteur1_'+id_match);
                else
                  obj = document.getElementById('buteur2_'+id_match);

                if (obj)
                {
                  var t = '<div class="but' + (is1?'g':'d') + '" id="buteur_'+id+'">'+nom+' ('+minute+extra+')</div>';
                  obj.innerHTML += t;
                }
              }
            }
          }
      }

      // Traitement des modifications de cartons
      if (table[4] != '')
      {
        var tableCarton = table[4].split('#$#');
        for (i=0; i < tableCarton.length; i++)
          if (tableCarton[i] != '')
          {
            var elt = tableCarton[i].split('#');
            id = elt[0];
            minute = elt[4];

            if (minute == -1)
            {
              obj = document.getElementById('carton_'+id);
              if (obj)
              {
                obj.innerHTML = '';
                obj.style.display = 'none';
              }
            }
            else
            {
              id_match = elt[1];
              nom = elt[2];
              obj = document.getElementById('equipe1_'+id_match);
              if (obj)
              {
                eq1 = document.getElementById('equipe1_'+id_match).value;
                if (eq1 == elt[3])
                  obj = document.getElementById('carton1_'+id_match);
                else
                  obj = document.getElementById('carton2_'+id_match);

                if (obj)
                {
                  var extra = '';
                  switch(elt[5])
                  {
                    case '1': image = 'J'; break;
                    default: image = 'R'; break;
                  }
                  var t = '<div class="C' + image + (eq1 == elt[3]?'g':'d') + '"  id="carton_'+id+'">'+extra+nom+' ('+minute+')</div>';
                  obj.innerHTML += t;
                }
              }
            }
          }
      }
      if (avecson)
      {
        obj = document.getElementById('joueson');
        if (nouveauBut)
        {
          obj.innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"  WIDTH="0" HEIGHT="0" id="son">' +
                          '<PARAM NAME="movie" VALUE="son1.swf">' +
                          '<PARAM NAME="quality" VALUE="high">' +
                          '<PARAM NAME="bgcolor" VALUE="#FFFFFF">' +
                          '<EMBED src="son1.swf" quality="high" bgcolor="#FFFFFF"  WIDTH="0" HEIGHT="0" NAME="son" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>'+
                          '</OBJECT>';
        }
        else
          obj.innerHTML = '';
      }
    }
  }
}

//******************************************************************************
var callbackLiveTennis = function getCallbackLiveTennis()
{
  if ((xhr_object[0].readyState == 4))
  {
    document.body.style.cursor = 'default';
    s = xhr_object[0].responseText;
    if (s != '')
    {
      var table = s.split('$$');
      datenow = table[0];

      d = table[1];
      var eltdate = d.split('#');
      var madate = new Date(eltdate[5], (eltdate[4]-1), eltdate[3], eltdate[2], eltdate[1], eltdate[0]);
      for (i=0; i<tabMatch.length;i++)
      {
        // On retire toutes les alertes changement de scores
        if ((tabAlerte[tabMatch[i]]) && (tabAlerte[tabMatch[i]]>0))
        {
          tabAlerte[tabMatch[i]]--;
          if (tabAlerte[tabMatch[i]]==0)
          {
            document.getElementById('score1_'+tabMatch[i]).className = 'normalScore';
            document.getElementById('score2_'+tabMatch[i]).className = 'normalScore';
          }
        }
      }

      // Traitement des modifications de scores
      if (table[2] != '')
      {
        change_cache = false;
        var tableMatch = table[2].split('#$#');
        for (i=0; i < tableMatch.length; i++)
          if (tableMatch[i] != '')
          {
            var elt = tableMatch[i].split('#');
            id = elt[0];
            etat = elt[1];
            if (etat>1)
            {
              set = elt[2];
              sets = new Array(elt[3], elt[4], elt[5], elt[6], elt[7]);

              var score1 = score2 = '';
              var vainqueur = 0;
              for (iSet = 0; iSet < 5; iSet++)
                if (sets[iSet] != 0)
                {
                  var sc2 = sets[iSet] & 0xff;
                  var sc1 = sets[iSet] >> 16;
                  score1 += '<span style="margin-right:10px">' + sc1 + '</span>';
                  score2 += '<span style="margin-right:10px">' + sc2 + '</span>';
                  vainqueur = sc1>sc2?1:2;
                }

              obj = document.getElementById('score1_'+id);
              if (obj && (score1 != obj.innerHTML))
              {
                obj.innerHTML = score1;
                obj.className = 'alerteScore';
                tabAlerte[id] = 6;
              }
              obj2 = document.getElementById('score2_'+id);
              if (obj2 && (score2 != obj2.innerHTML))
              {
                obj2.innerHTML = score2;
                obj2.className = 'alerteScore';
                tabAlerte[id] = 6;
              }


              if (tableEtat[id] != etat)
              {
                tableEtat[id] = etat;

                if ((etat==2) || (etat==7))
                  ischeck = document.getElementById('aff_encours').checked;
                else if (etat>=3)
                  ischeck = document.getElementById('aff_termine').checked;

                var ligne = document.getElementById('ligne_'+id);
                if (ligne)
                {
                  var affiche = (ligne.style.display=='');
                  if ((affiche!=ischeck) && ((!ischeck) || (!(tabRetire[id] == 1))))
                  {
                    ligne.style.display = ischeck?"":"none";
                    var ligne = document.getElementById('ligne2_'+id);
                    if (ligne)
                      ligne.style.display = ischeck?"":"none";
                    change_cache = true;
                  }

                }
              }

              if (etat == 3)
              {
                document.getElementById('date_'+id).innerHTML = live_termine;
                obj = document.getElementById('joueur'+vainqueur+'_'+id);
                if (obj)
                  obj.className = 'vainqueur';
              }
              else if (etat==2)
                document.getElementById('date_'+id).innerHTML = live_set+' '+set+' <img src="images/live.gif" alt="live" align="absmiddle" />';
              else if (etat == 5)
                document.getElementById('date_'+id).innerHTML = live_abandon + ' 1';
              else if (etat == 6)
                document.getElementById('date_'+id).innerHTML = live_abandon + ' 2';
              else if (etat==4)
                document.getElementById('date_'+id).innerHTML = live_reporte;
              else if (etat==7)
                document.getElementById('date_'+id).innerHTML = live_interrompu;
              else if (etat==8)
                document.getElementById('date_'+id).innerHTML = live_annule;
            }
          }
        if (change_cache)
          changeAffMatchSimple();
      }
    }
  }
}

//******************************************************************************
function chargeClassement(champ, typeClassement, width, eq1, eq2, lg, nomgroupe, champex)
{
  url = 'ajax_classement.php?champ='+champ+'&champex='+champex+'&type='+typeClassement+'&width='+width+
        '&eq1='+eq1+'&eq2='+eq2+'&lg='+lg+'&nomgroupe='+nomgroupe;
  appelAjax(null, url, true, callbackClassement, 1);
  return false;
}

//******************************************************************************
var callbackClassement = function getCallbackClassement()
{
  if ((xhr_object[1].readyState == 4))
  {
    document.body.style.cursor = 'default';
    obj = document.getElementById('blocClassement');
    obj.innerHTML = xhr_object[1].responseText;
  }
}

//******************************************************************************
function chargeMatchSaison(champ, idsport, lieu, eq1, lg)
{
  url = 'ajax_matchsaison.php?champ='+champ+'&idsport='+idsport+'&type='+lieu+
        '&eq1='+eq1+'&lg='+lg;
  appelAjax(null, url, true, callbackMatchSaison, 1);
  return false;
}

//******************************************************************************
var callbackMatchSaison = function getCallbackMatchSaison()
{
  if ((xhr_object[1].readyState == 4))
  {
    document.body.style.cursor = 'default';
    obj = document.getElementById('blocMatchs');
    obj.innerHTML = xhr_object[1].responseText;
  }
}

//******************************************************************************
function changeStatSaison(option, lg, elt)
{
  return changeStatSaisonBase(option, lg, elt, 0, 0, 0)
}

function changeStatSaisonEx(option, lg, elt)
{
  obj = document.getElementById('statJoueur');
  obj2 = document.getElementById('statJoueur2');
  idx1 = obj.options[obj.options.selectedIndex].value;
  idx2 = obj2?obj2.options[obj2.options.selectedIndex].value:0;

  obj = document.getElementById('statPays2');
  idPays = obj.options[obj.options.selectedIndex].value;

  return changeStatSaisonBase(option, lg, elt, idPays, idx1, idx2)
}

function changeStatSaisonBase(option, lg, elt, pays, eq1, eq2)
{
  var saison = option[option.selectedIndex].value;
  appelAjax(null, 'ajax_stats.php?saison='+saison+'&lg='+lg+'&elt='+elt+'&pays='+pays+'&eq1='+eq1+'&eq2='+eq2, true, callbackStatSaison, 3);
  return false;
}

//******************************************************************************
var callbackStatSaison = function getCallbackStatSaison()
{
  if ((xhr_object[3].readyState == 4))
  {
    var table = xhr_object[3].responseText.split('##');
    type = table[1];

    document.body.style.cursor = 'default';
    if (type == 1)
      obj = document.getElementById('statPays');
    else
    {
      removeJoueurs(1);
      obj = document.getElementById('statPays2');
      tabOld = table[0].split('$');
      var idPays = tabOld[0];
    }

    while(obj.length>0)
      obj.options[0] = null;

    opt = new Option(texte_choixpays + ' ...', 0);
    obj.options[obj.length] = opt;

    select = 0;
    for (i=2; i < table.length; i++)
      if (table[i] != '')
      {
        elt = table[i].split('$');
        opt = new Option(elt[1], elt[0]);
        if (idPays == elt[0])
          select = obj.length;
        obj.options[obj.length] = opt;
      }
    if (select!=0)
    {
      obj.options[select].selected = true;
      if (tabOld[1] != 0)
      {
        if (type==2)
          envoi_joueur_Ex(document.form_detail, tabOld[1], tabOld[4]);
        else
          envoi_match_Ex(document.form_detail, tabOld[1], tabOld[4], tabOld[2], tabOld[5])
      }
      else
      {
        changeStatJoueurBase(obj.options, tabOld[1], tabOld[2]);
      }
    }
  }
}

//******************************************************************************
function changeStatPays(option, lg)
{
  var pays = option[option.selectedIndex].value;
  appelAjax(null, 'ajax_stats.php?pays='+pays+'&lg='+lg, true, callbackStatPays, 3);
  return false;
}

//******************************************************************************
var callbackStatPays = function getCallbackStatPays()
{
  if ((xhr_object[3].readyState == 4))
  {
    document.body.style.cursor = 'default';
    obj = document.getElementById('statChamp');

    while(obj.length>0)
      obj.options[0] = null;

    opt = new Option(texte_choixchamp + ' ...', 0);
    obj.options[obj.length] = opt;

    var table = xhr_object[3].responseText.split('##');
    for (i=0; i < table.length; i++)
      if (table[i] != '')
      {
        elt = table[i].split('$');
        opt = new Option(elt[1], elt[0]);
        obj.options[obj.length] = opt;
      }
  }
}

//******************************************************************************
function changeStatJoueur(option)
{
  return changeStatJoueurBase(option, 0, 0);
}

function changeStatJoueurEx(option)
{
  obj = document.getElementById('statJoueur');
  obj2 = document.getElementById('statJoueur2');
  idx1 = obj.options[obj.options.selectedIndex].value;
  idx2 = obj2?obj2.options[obj2.options.selectedIndex].value:0;

  return changeStatJoueurBase(option, idx1, idx2);
}

function changeStatJoueurBase(option, eq1, eq2)
{
  var pays = option[option.selectedIndex].value;
  appelAjax(null, 'ajax_stats.php?pays2='+pays+'&eq1='+eq1+'&eq2='+eq2, true, callbackStatJoueur, 4);
  return false;
}

//******************************************************************************
function removeJoueurs(type)
{
  var obj = document.getElementById('statJoueur');
  var obj2 = document.getElementById('statJoueur2');

  while(obj.length>0)
    obj.options[0] = null;

  opt = new Option((type==1?texte_choixtournoiabord:texte_choixjoueur) + ' ...', 0);
  obj.options[obj.length] = opt;

  if (obj2)
  {
    while(obj2.length>0)
      obj2.options[0] = null;

    opt = new Option((type==1?texte_choixtournoiabord:texte_choixjoueur) + ' ...', 0);
    obj2.options[obj2.length] = opt;
  }
}

//******************************************************************************
var callbackStatJoueur = function getCallbackStatJoueur()
{
  if ((xhr_object[4].readyState == 4))
  {
    document.body.style.cursor = 'default';
    obj = document.getElementById('statJoueur');
    obj2 = document.getElementById('statJoueur2');

    removeJoueurs(2);

    var table = xhr_object[4].responseText.split('##');

    tabOld = table[0].split('$');
    var eq1 = tabOld[0];
    var eq2 = tabOld[1];

    var select1 = select2 = 0;


    for (i=1; i < table.length; i++)
      if (table[i] != '')
      {
        elt = table[i].split('$');
        opt = new Option(elt[1], elt[0]);
        if (eq1 == elt[0])
          select1 = obj.length;
        obj.options[obj.length] = opt;

        if (obj2)
        {
          opt = new Option(elt[1], elt[0]);
          if (eq2 == elt[0])
            select2 = obj2.length;
          obj2.options[obj2.length] = opt;
        }
      }
    obj.options[select1].selected = true;
    if (obj2)
      obj2.options[select2].selected = true;
  }
}

//******************************************************************************
function changeMatch(elt)
{
  obj = document.getElementById('statJoueur');
  obj2 = document.getElementById('statJoueur2');

  idx1 = obj.options[obj.options.selectedIndex].value;
  idx2 = obj2.options[obj2.options.selectedIndex].value;

  if ((idx1>0) && (idx2>0))
    envoi_match(elt.form)
}

//******************************************************************************
function showScore(nom, show, libelle)
{
  score = document.getElementById(nom);
  if (mouse_x>150)
    score.style.left = (mouse_x-150) + 'px';
  else
    score.style.left = (mouse_x+5) + 'px';
  score.style.top = (mouse_y+10) + 'px';
  score.style.visibility = show?"visible":"hidden";
  score.value = libelle;
}

//******************************************************************************
function cache(idmatch, nb)
{
  var ligne = document.getElementById('ligne_'+idmatch);
  if (ligne)
  {
    ligne.style.display = "none";
    tabRetire[idmatch] = 1;
  }

  if (nb == 2)
  {
    var ligne = document.getElementById('ligne2_'+idmatch);
    if (ligne)
      ligne.style.display = "none";
  }
  changeAffMatchSimple();
  return false;
}

//******************************************************************************
function cache_champ(idchamp)
{
  var ligne = document.getElementById('table_'+idchamp);
  if (ligne)
    ligne.style.display = "none";
  for (i=0; i<tabChamp.length;i++)
    if (tabChamp[i]==idchamp)
    {
      idmatch = tabMatch[i];
      var ligne = document.getElementById('ligne_'+idmatch);
      if (ligne)
      {
        ligne.style.display = "none";
        tabRetire[idmatch] = 1;
      }
    }
  return false;
}

//******************************************************************************
function changeAffMatchSimple()
{
  tabTempVisible = new Array();
  tabTempCache = new Array();
  for (i=0; i<tabMatch.length;i++)
  {
    var ligne = document.getElementById('ligne_'+tabMatch[i]);
    if (ligne.style.display=='')
      tabTempVisible[tabChamp[i]]=1;
    else
      tabTempCache[tabChamp[i]]=1;
  }
  for (value in tabTempVisible)
  {
    var ligne = document.getElementById('table_'+value);
    if (ligne)
      ligne.style.display = "";
  }

  for (value in tabTempCache)
    if (tabTempVisible[value] != 1)
    {
      var ligne = document.getElementById('table_'+value);
      if (ligne)
        ligne.style.display = "none";
    }
}

//******************************************************************************
function changeAffMatch(nomcheck, idcheck)
{
  tabTempVisible = new Array();
  tabTempCache = new Array();
  ischeck = document.getElementById(nomcheck).checked;
  for (i=0; i<tabMatch.length;i++)
  {
    var ligne = document.getElementById('ligne_'+tabMatch[i]);
    if ((!ischeck) || (!(tabRetire[tabMatch[i]] == 1)))
    {

      if (tableEtat[tabMatch[i]] == idcheck)
      {
        if (ligne)
          ligne.style.display = ischeck?"":"none";
        var ligne = document.getElementById('ligne2_'+tabMatch[i]);
        if (ligne)
          ligne.style.display = ischeck?"":"none";
      }
    }
    if (ligne.style.display=='')
      tabTempVisible[tabChamp[i]]=1;
    else
      tabTempCache[tabChamp[i]]=1;
  }
  for (value in tabTempVisible)
  {
    var ligne = document.getElementById('table_'+value);
    if (ligne)
      ligne.style.display = "";
  }

  for (value in tabTempCache)
    if (tabTempVisible[value] != 1)
    {
      var ligne = document.getElementById('table_'+value);
      if (ligne)
        ligne.style.display = "none";
    }

}
//******************************************************************************
function chargeScore(match, eq1, lg, extra)
{
  obj = document.getElementById('extra_' + (extra!=0?extra:'') + match);
  affiche = obj.style.display!='';
  obj.style.display = affiche?'':'none';

  if (affiche)
  {
    obj = document.getElementById('charge_' + (extra!=0?extra:'') + match);
    if (obj.value==0)
    {
       appelAjax(null, 'ajax_score.php?match='+match+'&eq1='+eq1+'&lg='+lg+'&extra=' + extra, true, callbackScore, 1);
    }
  }
  return false;
}

//******************************************************************************
var callbackScore = function getCallbackScore()
{
  if ((xhr_object[1].readyState == 4))
  {
    document.body.style.cursor = 'default';
    var elts = xhr_object[1].responseText.split('##');
    idmatch = elts[0];

    obj = document.getElementById('buteur1_' + idmatch);
    if (obj)
      obj.innerHTML = elts[1];
    obj = document.getElementById('buteur2_' + idmatch);
    if (obj)
      obj.innerHTML = elts[3];
    obj = document.getElementById('carton1_' + idmatch);
    if (obj)
      obj.innerHTML = elts[2];
    obj = document.getElementById('carton2_' + idmatch);
    if (obj)
      obj.innerHTML = elts[4];

    obj = document.getElementById('charge_' + idmatch);
    if (obj)
      obj.value = 1;
  }
}

//******************************************************************************
function changeJournee(option, champ, journeemax, idsport, lg, champex, nomgroupe)
{
  var journee = option[option.selectedIndex].value;
  url = 'ajax_resultat.php?champ='+champ+'&champex='+champex+'&journee='+journee+
        '&journeemax='+journeemax+'&idsport='+idsport+'&lg='+lg+'&nomgroupe='+nomgroupe;
  appelAjax(null, url, true, callbackJournee, 2);
  return false;
}

//******************************************************************************
function changeJourneeNum(journee, champ, journeemax, idsport, lg, champex, nomgroupe)
{
  url = 'ajax_resultat.php?champ='+champ+'&champex='+champex+'&journee='+journee+
        '&journeemax='+journeemax+'&idsport='+idsport+'&lg='+lg+'&nomgroupe='+nomgroupe;
  appelAjax(null, url, true, callbackJournee, 2);
  return false;
}

//******************************************************************************
var callbackJournee = function getCallbackJournee()
{
  if ((xhr_object[2].readyState == 4))
  {
    document.body.style.cursor = 'default';
    obj = document.getElementById('blocResultat');
    obj.innerHTML = xhr_object[2].responseText;
  }
}

//******************************************************************************
function changeSport(option, formu)
{
  var sport = option[option.selectedIndex].value;
  formu.action = 'live' + (sport ==1?'':'2') + '.php';
  formu.submit();
}

//******************************************************************************
function changeSon(option)
{
  avecson = option[option.selectedIndex].value==1;
}

//******************************************************************************
function appelAjax(obj, url, retour, fn, type)
{
  if (xhr_object[type] == null)
  {
    if(window.XMLHttpRequest)
      xhr_object[type] = new XMLHttpRequest();
    else if(window.ActiveXObject)
      xhr_object[type] = new ActiveXObject("Microsoft.XMLHTTP");
    else
      return true;
  }

  xhr_object[type].open("GET", url, true);
  if (retour)
    xhr_object[type].onreadystatechange = fn;
  xhr_object[type].send(null);

  if (retour)
  {
    document.body.style.cursor = 'wait';
    /*if (obj != null)
      obj.style.cursor = 'wait';*/
    lastobj=obj;
  }

  return false;
}

function retireParenthese(nom)
{
  var posi = nom.indexOf('(');
  if (posi > -1)
    return nom.substring(0, posi-1);
  else
    return nom;
}

//******************************************************************************
function convertiUrl(chaine)
{
  var c1 = 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ';
  var c2 = 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy';

  chaine2 = '';
  for (i = 0; i < chaine.length; i++)
  {
    if ((posi = c1.indexOf(chaine.charAt(i)))>=0)
      chaine2 += c2.charAt(posi);
    else
      chaine2 += chaine.charAt(i);
  }

  var reg=new RegExp("[^a-zA-Z0-9]", "g");
  chaine2 = chaine2.replace(reg, '-');
  var reg=new RegExp("-{2,}", "g");
  chaine2 = chaine2.replace(reg, '-');
  var reg=new RegExp("^-", "g");
  chaine2 = chaine2.replace(reg, '');
  var reg=new RegExp("-$", "g");
  chaine2 = chaine2.replace(reg, '');

  chaine2 = chaine2.toLowerCase();

  return chaine2;
}

//******************************************************************************
function envoi_detail(formu)
{
  var objS = document.getElementById('statSaison');
  var annee = objS.options[objS.options.selectedIndex].text;

  var objP = document.getElementById('statPays');
  var pays = objP.options[objP.options.selectedIndex].text;

  var objC = document.getElementById('statChamp');
  var idchamp = objC.options[objC.options.selectedIndex].value;
  var nomchamp = objC.options[objC.options.selectedIndex].text;
  url = convertiUrl(nomchamp+'-'+annee+'-'+pays)+'-c'+idchamp;
  document.location.href=url;
  return false;
}

//******************************************************************************
function envoi_joueur_Ex(formu, idjoueur, nomjoueur)
{
  var objS = document.getElementById('statSaison2');
  var annee = objS.options[objS.options.selectedIndex].text;

  var objP = document.getElementById('statPays2');
  var pays = objP.options[objP.options.selectedIndex].text;
  var idpays = objP.options[objP.options.selectedIndex].value;

  var objC = document.getElementById('statJoueur');
  url = convertiUrl(retireParenthese(nomjoueur)+'-'+annee+'-'+pays)+'-p'+idpays+'-e'+idjoueur;
  document.location.href=url;
  return false;
}

function envoi_joueur(formu)
{
  var objC = document.getElementById('statJoueur');
  var idjoueur = objC.options[objC.options.selectedIndex].value;
  var nomjoueur = objC.options[objC.options.selectedIndex].text;

  return envoi_joueur_Ex(formu, idjoueur, nomjoueur);
}

//******************************************************************************
function envoi_match_Ex(formu, idjoueur1, nomjoueur1, idjoueur2, nomjoueur2)
{
  var objS = document.getElementById('statSaison2');
  var annee = objS.options[objS.options.selectedIndex].text;

  var objP = document.getElementById('statPays2');
  var pays = objP.options[objP.options.selectedIndex].text;
  var idpays = objP.options[objP.options.selectedIndex].value;

  var objC = document.getElementById('statJoueur');
  url = convertiUrl(retireParenthese(nomjoueur1)+'-'+retireParenthese(nomjoueur2)+'-'+annee+'-'+pays)+'-p'+idpays+'-e'+idjoueur1+'-e'+idjoueur2;
  document.location.href=url;
  return false;
}

function envoi_match(formu)
{
  var objC = document.getElementById('statJoueur');
  var idjoueur1 = objC.options[objC.options.selectedIndex].value;
  var nomjoueur1 = objC.options[objC.options.selectedIndex].text;

  var objC = document.getElementById('statJoueur2');
  var idjoueur2 = objC.options[objC.options.selectedIndex].value;
  var nomjoueur2 = objC.options[objC.options.selectedIndex].text;

  return envoi_match_Ex(formu, idjoueur1, nomjoueur1, idjoueur2, nomjoueur2);
}