function ouvrirFenetre(url, nompage, largeur, hauteur, extra, withsession)
{
  window.open(url, nompage,
              extra + ' status=no, width=' + largeur + ', height=' + hauteur);
  return false;
}

//******************************************************************************
var scrOfX = 0, scrOfY = 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;
  }
}

//******************************************************************************
var mouse_x=0; var mouse_y=0;
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);

var agt = navigator.userAgent.toLowerCase();
var isMac = (agt.indexOf('mac') != -1);
var isOpera = (agt.indexOf("opera") != -1);
var isIE = ((agt.indexOf('msie')!=-1 && !isOpera && (agt.indexOf('webtv')==-1)) && !isMac);

//******************************************************************************
function showAide(nom, show)
{
  aide = document.getElementById(nom);
  if (mouse_x>450)
    aide.style.left = (mouse_x-405) + 'px';
  else
    aide.style.left = (mouse_x+5) + 'px';
  aide.style.top = (mouse_y+10) + 'px';
  aide.style.visibility = show?"visible":"hidden";
  SelectVisible(show?"hidden":"visible",document.getElementsByTagName('select'));
}

//******************************************************************************
function SelectVisible(v,elem)
{
	if (isIE)
		for (var i=0;i<elem.length;i++)
      elem[i].style.visibility=v;
}

//******************************************************************************
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;
}

var affevt = false;
//******************************************************************************
function affichetop()
{
  affevt = !affevt;
  var tab = document.getElementsByName('evt_top');
  for (idx = 0; idx < tab.length; idx++)
  {
    var obj = tab[idx];
    if (obj != null)
    {
      obj2 = document.getElementById('evt_'+obj.value);
      if (obj2 != null)
        obj2.style.display = affevt?"":"none";
    }
  }
  obj = document.getElementById('lientop');
  obj.innerHTML = affevt?'Cacher la suite':'Voir la suite';
  return false;
}

//******************************************************************************
// Fonctions de gestion du coupon
//******************************************************************************
var coupons = new Array();

function showCoupon()
{
  obj = document.getElementById('coupons');
  var s = '';
  var cook = '';
  for (id in coupons)
  {
    nom = coupons[id]['nom'];
    pays = coupons[id]['pays'];
    sport = coupons[id]['sport'];
    typecote = coupons[id]['typecote'];
    idmatch = coupons[id]['idmatch'];

    switch(parseInt(typecote)){
      case 1: tc = sport==2?'12':'1N2'; break;
      case 2: tc = 'U/O'; break;
      case 3: tc = 'Double'; break;
      case 4: tc = 'HT/FT'; break;
      default : tc = typecote; break;
    }

    s += '<tr><td><img src="images/' + imagesBallons[sport] + '" height="16" width="16" alt=""/></td>' +
         '<td><a href="cotes-' + convertiUrl(nom) + '-m' + idmatch + '.html">' + nom + '</a> '+
         //(' + tc + ')' +
         '</td>' +
         '<td><a href="#" onclick="return retireCoupon(\'' + id + '\')"><img src="images/efface.png" width="16" height="16" border="0"></a> </td></tr>';
    cook += idmatch + '#' + nom + '#' + pays + '#' + sport + '#' + typecote +'##';
  }

  if (s != '')
    obj.innerHTML = '<table>' + s + '</table>' +
                    '<a href="#" onclick="effaceCoupon()">Tout effacer</a>';
  else
    obj.innerHTML = 'Aucun match dans le coupon';

  //var expDate = new Date();
  //expDate.setTime(expDate.getTime() + (5 * 1000));
  //expDate.setTime(expDate.getTime());
  //document.cookie = 'favoris=' + cook + ";expires=" + expDate.toGMTString() + ';path=/';
  document.cookie = 'favoris=' + cook + ';path=/';
}

//******************************************************************************
function chargeCoupon()
{
  nom = 'favoris';
  debut = document.cookie.indexOf(nom + "=")
  if (debut >= 0)
  {
    debut += nom.length + 1;
    fin = document.cookie.indexOf(";",debut);
    if (fin < 0) fin = document.cookie.length;
    s = unescape(document.cookie.substring(debut,fin));

    var reg=new RegExp("##", "g");
    var tableau=s.split(reg);

    for (id in tableau)
    {
      s = tableau[id];
      if (s != '')
      {
        reg=new RegExp("#", "g");
        var elts = s.split(reg);

        coupon = new Array();
        coupon['nom'] = elts[1];
        coupon['pays'] = elts[2];
        coupon['sport'] = elts[3];
        coupon['typecote'] = elts[4];
        coupon['idmatch'] = elts[0];
        coupons.push(coupon);
      }
    }

    showCoupon();
  }
}

//******************************************************************************
function ajoutCoupon(nomMatch, idMatch, nomPays, sport, typecote)
{
  i = 0;
  for (id in coupons) i++;
  if (i < 10)
  {
    coupon = new Array();
    coupon['nom'] = nomMatch;
    coupon['pays'] = nomPays;
    coupon['sport'] = sport;
    coupon['typecote'] = typecote;
    coupon['idmatch'] = idMatch;
    coupons.push(coupon);
    showCoupon();
  }
  else
    alert('Vous ne pouvez pas jouer plus de 10 matchs à votre coupon');
  return false;
}

//******************************************************************************
function retireCoupon(id)
{
  delete(coupons[id]);

  showCoupon();

  return false;
}

//******************************************************************************
function effaceCoupon()
{
  for (id in coupons)
    delete(coupons[id]);

  showCoupon();

  return false;
}

