/*
htmlTableau( jat, ie, it)
htmlFiche( jat, jou)
htmlPlanning( jat, jour)
htmlResultat( jat, ie, nc)
htmlListe( jat)
htmlNomJour( jat, jour)
htmlMenutab( jat, ie, it)
htmlMenujour( jat, jour)
htmlMenujour2( jat, jour)
*/

//=========Fonctions navigation

var curU;
var curE, curT, curJ, curD;

var unjour = (Date.UTC( 2002,1,2) - Date.UTC( 2002,1,1));

function Init()
{
	var i;
	var u = String( document.location).split( "#");
	var p = u[1];
	curU = u[0];

	if( p)
	{
		p = p.split( ";");

		for( i=0; p.length>i; i++)
		{
			switch( p[i].substring( 0, 1))
			{
			case 'e':	curE = p[i].substring( 1);	break;
			case 't':	curT = p[i].substring( 1);	break;
			case 'j':	curJ = p[i].substring( 1);	break;
			case 'd':	curD = p[i].substring( 1);	break;
			}
		}
	}
}
Init();

function gotoHash( h)
{
	gotoHRef( curU + "#" + h);
	return false;
}

function gotoHRef( h, noreload)
{
	if( document.location != h) {
		document.location = h;
		if( !noreload) document.location.reload();
	}
	return false;
}

//=========Fonction menus

function htmlMenutab( jat, ie, it)
{
	var h="";
	var e, t, oE, h;

	if( isNaN(ie) || isNaN(it)) {
		h+= "<select onchange='gotoHRef( \"tabl.htm#\" + this.options[this.selectedIndex].value,1)'>\n";
		h+= "<option selected>&lt;choisissez un tableau&gt;</option>\n";
	} else
		h+= "<select onchange='gotoHash( this.options[this.selectedIndex].value)'>\n";

	for( e=0; jat.E.length>e; e++)
	{
		oE = jat.E[ e];

		h+= "<option value='e"+ e +";t0'>=====&nbsp;"+ jat.E[ e].Nom +"&nbsp;=====</option>";

		for( t=0; oE.T.length>t; t++)
		{
			if( !oE.T[ t]) continue;
				
			h+= "<option value='e"+ e +";t"+ t +"'";
			if( e == ie && t == it)
				h+= " selected";
			h+= ">"+ jat.E[ e].Nom +" | "+ oE.T[ t].Nom +"</option>";
		}
	}

	h+= '</select>\n';

	return h;
}

function htmlMenujour( jat, jour)
{
	var h="";
	var i, njour, d;

	if( !jat.Deb || !jat.Fin || !jat.D.length)
		return h;

	njour = (jat.Fin - jat.Deb) / unjour +1;

	if( isNaN(jour)) {
		h+= "<select onchange='gotoHRef( \"plan.htm#\" + this.options[this.selectedIndex].value,1)'>\n";
		h+= "<option selected>&lt;choisissez une date&gt;</option>\n";
	} else
		h+= "<select onchange='gotoHash( this.options[this.selectedIndex].value)'>\n";

	d = new Date( jat.Deb);
	for( i=0; i< njour; i++) 
	{
		if( jat.D[i] && jat.D[i].M.length) 
		{
			h+= "<option value='d"+ i +"'";
			if( i == jour)
				h+= " selected";
			h+= ">"+ fmtDateL( d) +"</option>\n";
		}
		d.setDate( d.getDate() +1);
	}
	h+= "</select>\n";

	return h;
}

function htmlNomJour( jat, jour)
{
	var h="";

	if( jat.Deb && jat.D[ jour]) {
		var d = new Date( jat.Deb);
		d.setDate( d.getDate() + Number( jour));
		h+= fmtDateL( d);
	}

	return h;
}

function htmlMenujour2( jat, jour)
{
	var h="";
	var i, njour;
	var d, ip=-1, is=-1;

	if( !jat.Deb || !jat.Fin || !jat.D.length)
		return h;

	njour = (jat.Fin - jat.Deb) / unjour +1;
	jour = parseInt( jour);

	d = new Date( jat.Deb);
	for( i=0; i< njour; i++) 
	{
		if( jat.D[i] && jat.D[i].M.length) 
		{
			if( i == jour) {
				if( ip >= 0)
					h= "<a href='#d"+ ip + "' onclick='return gotoHRef( this.href)'>&lt;&lt;&lt;</a> "+ h;
				h+= " ["+ fmtDateS( d) +"] ";
			} else {
				h+= "<a href='#d"+ i + "' onclick='return gotoHRef( this.href)'>"+ fmtDateS( d) +"</a> ";
				if( i > jour && is==-1)
					is = i;
			}
			ip = i;
		}
		d.setDate( d.getDate() +1);
	}

	if( is >= 0)
		h+= "<a href='#d"+ is + "' onclick='return gotoHRef( this.href)'>&gt;&gt;&gt;</a>";

	return h;
}

//=========Fonction tableaux

function isCache( b) {
	return !b || ((b.Fla ) & 0x1); 
}

function	iCol( i) {
	var col = -1;
	for (i++; i; i >>= 1, col++);
	return col;
}
function	iHautCol( col) {
	return ( 1 << (col+1)) -2;
}
function	iBasCol( col) {
	return ( 1 << col) -1;
}
function	nInCol( col) {
	return (1 << col);
}
function	iColMaxQ( nCol, nQ) {
	return iCol( nQ -2) + nCol;
}
function	iColMinQ( nQ) {
	return iCol( nQ -2) + 1;
}
function	iBasColQ( col, nQ) {
	return ( iHautCol(col) - nInColQ(col, nQ) + 1);
}
function	nInColQ( col, nQ) {
	return nQ * nInCol( col - iColMinQ(nQ));
}
function	iBoiteMinQ( nQ) { 
	return iBasColQ( iColMinQ( nQ), nQ);
}
function	iBoiteMaxQ( nCol, nQ){ 
	return iHautCol( iColMaxQ( nCol, nQ));
}
function ADVERSAIRE1( i) { 
	return (i<<1)+2; 
}
function ADVERSAIRE2( i) { 
	return (i<<1)+1; 
}
function IMATCH( i) { 
	return (i-1)>>1; 
}
function IAUTRE( i) {
	return i&1 ? i+1 : i-1; 
}

function suitePrec( oE, oT, t, q) {
	for( t = (oT.Sui ? t-oT.Sui : t-1) ;t>0; t--) {	
		pT = oE.T[t];
		if( !pT)
			return -1;
		for( b=0; b<pT.B.length; b++)
			if( pT.B[b] && pT.B[b].QS==q)
				return t;

		if( !(pT.Sui >1)) break;
	}
	return t;
}
function suiteSuiv( oE, t, q) {
	for( t++; oE.T[t] && oE.T[t].Sui; t++);

	if( !oE.T[t])
		return -1;
	for( ;t<oE.T.length; t++) {	
		pT = oE.T[t];
		for( b=0; b<pT.B.length; b++)
			if( pT.B[b] && pT.B[b].QE==q)
				return t;
		if( !oE.T[t].Sui) break;
	}
	return t; 
}

function iColPoule( i, nCol) {
	return Math.floor( i / nCol);
}
function iRowPoule( i, nCol) {
	return i % nCol;
}

function POULE_ADVERSAIRE1( i, nCol) { 
	return (i % nCol) + (nCol * nCol); 
}
function POULE_ADVERSAIRE2( i, nCol) { 
	return Math.floor( i / nCol) + (nCol * nCol); 
}

function iJour( sDate, sRef) {
	return Math.floor((sDate - sRef) / (Date.UTC( 2002,1,2) - Date.UTC( 2002,1,1)));
}

function fmtDate( d, avecHeure) 
{
	var tjour = new Array( "dim", "lun", "mar", "mer", "jeu", "ven", "sam");
	var tmois = new Array( "jan", "fév", "mar", "avr", "mai", "jui", "jul", "aoû", "sep", "oct", "nov", "déc");

	return tjour[ d.getDay()] +" "+ d.getDate() +" "+ tmois[ d.getMonth()] + (avecHeure && d.getHours() ? ", "+ fmtHeure(d) : "");
}

function fmtDateS( d) 
{
	var tjour = new Array( "dim", "lun", "mar", "mer", "jeu", "ven", "sam");

	return tjour[ d.getDay()] +" "+ d.getDate();
}

function fmtDateL( d) 
{
	var tjour = new Array( "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi");
	var tmois = new Array( "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre");

	return tjour[ d.getDay()] +" "+ d.getDate() +" "+ tmois[ d.getMonth()] +" "+ d.getFullYear();
}

function fmtHeure( d) 
{
	if( !d) return "";
	return d.getHours() ? (d.getHours() + "h" + (d.getMinutes() ? d.getMinutes() :"") ) :"";
}

function v( s)
{
	return s ? s : "";
}

//=========Fonction exportées

function htmlTableau( jat, ie, it)
{
	var h="";
	var l, c, ib, iv, nLigne, bMax, bMin, cMax, cMin, oE, oT, oB, oJ, t;

	ie = Number( ie);
	it = Number( it);

	oE = jat.E[ ie];

	if( 0<=it && it<oE.T.length) {
		oT = oE.T[ it];
		//h+=( "<h3>Tableau:&nbsp;"+ oT.Nom +"</h3>\n");

		if( !oT.Typ || oT.Typ == 1) {

			nLigne = nInColQ( iColMaxQ( oT.Col, oT.Qua), oT.Qua) <<1;
			bMax = iBoiteMaxQ( oT.Col, oT.Qua);
			//bMin = iBoiteMinQ( oT.Qua); 
			cMax = iColMaxQ( oT.Col, oT.Qua);
			cMin = iColMinQ( oT.Qua);

			h+= "<table cellspacing='0' width='100%'>";

			for( l=0; l<nLigne; l++) {

				h+= "<tr>";

				ib = bMax - (l >>1);
				iv = ADVERSAIRE1( bMax) - l;

				for( c = cMax; c >= cMin; c--) {
						
					oB = oT.B[ ib];
					oJ = (oB && oB.Jou>=0) ? jat.J[ oB.Jou] : 0;

					if( l == 0) {
						i = Math.floor(100 / (cMax - cMin +1));
						h+= "<td width='"+ i +"%' class='J";
					} else
						h+= "<td class='J";

					if( oB) {
						if( c == cMin)
							h+= iv & 1 ? "B" : "H";
						else
							h+= !(ib & 1) ? "H" : "B";
					} else 
						h+= "C";

					if( iv & 1) 
						h+= "S";

					i = 1 << ( cMax - c);
					h+= "'"+ (i>1 ? " rowspan="+ i : "") +">";

					if( oB && !isCache( oB)) {
						if( !(iv & 1)) {
							h+= htmlJoueur( jat, oB, oJ, oT, oE, ie, it, ib) + "&nbsp;";

							if( oB.QS) {
								h+= "</td><td"+ (i>1 ? " rowspan="+ i : "") +" valign=bottom>";
								t = suiteSuiv( oE, it, oB.QS);
								if( it < (oE.T.length-1) && t>=0)
									h+= "<a href='#e"+ ie + ";t"+ t +"' onclick='return gotoHRef( this.href)'>Q"+ oB.QS +"</a>";
								else
									h+= "Q"+ oB.QS;
							}

						} else {
							if( oB.Jou>=0 && oB.Ord && oJ.Clu)
								h+= v( oJ.Clu);

							h+= htmlScore( jat, oB);
						}
					}

					h+= "</td>\n";

					if( iv & 1)
						break;

					iv = IMATCH( iv);
					ib = IMATCH( ib);
				}

				h+= "</tr>\n";
			}

			h+= "</table>";
		} else {
			//Poule
			h+= "<table border='1' cellspacing='0' cellpadding='5'>\n";

			bMax = oT.Col * (oT.Col +1) -1;
			cMax = oT.Col;
			cMin = 0;

			//Ligne des joueurs
			h+= "<tr><td class='PX'></td>";
			
			for( c = 0; c < oT.Col; c++) {
				ib = bMax - c;

				oB = oT.B[ ib];

				h+= "<td width='"+ Math.floor( 80 / oT.Col) +"%' align='center'>";

				if( oB && oB.Jou>=0) {
					oJ = jat.J[ oB.Jou];
					h+= oJ.Nom +"&nbsp;"+ v( oJ.Pre).substring( 0, 1) +"</td>";
				} else
					h+= "&nbsp;</td>";
			}
			h+= "</tr>\n";
			
			//La grille des matches
			for( l=oT.Col -1; l>=0; l--) {

				h+= "<tr><td>";

				//Colonne des joueurs
				ib = bMax + l - oT.Col +1;
				oB = oT.B[ ib];

				if( oB) {
					oJ = oB.Jou>=0 ? jat.J[ oB.Jou] : 0;
					h+= htmlJoueur( jat, oB, oJ, oT, oE, ie, it, ib);
				} else
					h+= "&nbsp;</td>";

				h+= "</td>\n";

				//Les matches
				for( c = cMax -1; c >= 0; c--) {

					ib = c * oT.Col + l;
					oB = oT.B[ ib];

					if( !oB || isCache( oB))
						h+= "\t<td class='PX'>&nbsp;</td>\n";
					else {
						h+= "\t<td align='center'>";

						oJ = oB.Jou>=0 ? jat.J[ oB.Jou] : 0;

						h+= htmlJoueur( jat, oB, oJ, oT, oE, ie, it, ib);
						
						h+= "<br>\n";

						h+= htmlScore( jat, oB);

						h+= "</td>\n";
					}
				}

				//Colonne des qualifiés
				ib = l * (oT.Col +1);
				oB = oT.B[ ib];

				if( oB && oB.QS) {
					t = suiteSuiv( oE, it, oB.QS);
					if( t>=0)
						h+= "<td><a href='#e"+ ie +";t"+ t +"' onclick='return gotoHRef( this.href)'>Q"+ oB.QS +"</a></td>";
					else
						h+= "<td>Q"+ oB.QS +"</td>";
				}

				h+= "</tr>\n";
			}
			h+= "</table>\n";
		}
	}
	return h;

	function htmlJoueur( jat, oB, oJ, oT, oE, ie, it, ib)
	{
		var h="";
		var t;

		if( oB.Ord)
			h+= "<i><small>"+ oB.Ord +"</small></i> ";
		else if( oB.QE) {
			t = suitePrec( oE, oT, it, oB.QE);
			if( t>=0)
				h+= "<a href='#e"+ ie +";t"+ t +"' onclick='return gotoHRef( this.href)'>Q"+ (oB.QE!=-1?oB.QE:"") +"</a> ";
			else
				h+= "Q"+ (oB.QE!=-1?oB.QE:"") +" ";
		}

		if( oB.Jou>=0) {
			h+= "<a href='fich.htm#j" + oB.Jou +"'>";
			if( oB.Ord || ib==0)
				h+= "<b>"+ oJ.Nom +" "+ v( oJ.Pre) +"</b></a> "+ v( oJ.Cls);
			else
				h+= oJ.Nom +"&nbsp;"+ v( oJ.Pre).substring( 0, 1) +"</a>";
		}

		if( oB.TS)							
			h+= " ("+ oB.TS +")";

		if( oB.Jou>=0 && String( oB.Sco).indexOf( 'VD') != -1) {
			h+= " requalifié<br>";

			breq = oT.B[ ADVERSAIRE1( ib)];
			if( breq && breq.Jou == oB.Jou)
				breq = oT.B[ ADVERSAIRE2( ib)];
			if( breq && breq.Jou>=0) {
				jreq = jat.J[ breq.Jou];

				h+= "<a href='fich.htm#j"+ breq.Jou +"'>";
				h+= jreq.Nom +"&nbsp;"+ v( jreq.Pre).substring( 0, 1) +"</a>";
				h+= " se retire";
			}
		}

		return h;
	}

	function htmlScore( jat, oB)
	{
		var h="";

		if( oB.Dat) {
			if( jat.Deb && jat.Deb <= oB.Dat && oB.Dat < (jat.Fin.valueOf() + unjour))
				h+= "<a href='plan.htm#d"+ iJour( oB.Dat, jat.Deb) +"'>" + fmtDate( oB.Dat,1) +"</a><br>";
			else
				h+= fmtDate( oB.Dat,1) +"<br>";
		}

		h+= oB.Sco ? oB.Sco : "&nbsp;";

		return h;
	}
}

function htmlFiche( jat, jou)
{
	var h="";
	var j, ie, be, e, it, t, ibmin, b, ba, bm, ja, im, r, c, ia1, ia2, b1, b2;

	if( !jou)
		jou = 0;
	j = jat.J[ jou];
	if( j) {
		h+= "<table border='0' cellspacing='0' cellpadding='5'><tr valign='top'>";

		h+= "<td align=right>Nom:</td><td><b>"+ j.Nom +"</b></td></tr>";
		if( !j.Equ)
			h+= "<tr><td align=right>Prenom:</td><td><b>"+ v( j.Pre) +"</b>&nbsp;</td></tr>";
		h+= "<tr><td align=right>Classement:</td><td>"+ v( j.Cls) +"&nbsp;</td></tr>";
//		h+= "<tr><td align=right>Double:</td><td>"+ v( j.Cld) +"&nbsp;</td></tr>";
		h+= "<tr><td align=right>Club:</td><td>"+ v( j.Clu) +"&nbsp;</td></tr>";
		h+= "<tr><td align=right>Année:</td><td>"+ (j.Dat ? j.Dat.getFullYear() : "&nbsp;") +"</td></tr>";
		if( !j.Equ)
//			h+= "<tr><td align=right>Licence:</td><td>"+ (j.Lic ? "<a href='http://www.fft.fr/bdd/recherche_classement/liste_classement_palmares.asp?LICENCE="+ j.Lic +"' target='_blank'>"+ j.Lic +"</a>" : "&nbsp;") +"</td></tr>";
			h+= "<tr><td align=right>Licence:</td><td>"+ (j.Lic ? "<a href='http://www.fft.fr/palmares/asp/competiteur/palmares.asp?LICENCE="+ j.Lic.substring(0,7) +"' target='_blank'>"+ j.Lic +"</a>" : "&nbsp;") +"</td></tr>";	//2004

//		h+= "<tr><td align=right>Sexe:</td><td>"+ v( j.Sex) +"</td></tr>";

		h+= "<tr><td align=right valign=top>Adresse:</td><td>"+ v( j.Ad1) + (j.Ad2 ? "<br>"+ j.Ad2 : "") +"<br>"+ v( j.Cdp) +" "+ v( j.Vil) +"</td></tr>";
		h+= "<tr><td align=right valign=top>Téléphone:</td><td>"+ v( j.Te1) + (j.Te2 ? "<br>"+ j.Te2 :"") +"</td></tr>";
		h+= "<tr><td align=right>Mél:</td><td>"+ (j.Mel ? "<a href='mailto:"+ j.Mel +"'>"+ j.Mel +"</a>" : "&nbsp;") +"</td></tr>";

		h+= "<tr><td align=right valign=top>Commentaire:</td><td>"+ v( j.Cmt).split( "\n").join( "<br>") +"&nbsp;</td></tr>";

		h+= "<tr><td align=right valign=top>";
		if( j.Equ) {
			h+= "Equipiers:</td><td>";

			for( c=0; c < j.Equ.length; c++) {
				e = jat.J[ j.Equ[c]];
				if( e)
					h+= "<a href='fich.htm#j"+ j.Equ[c] +"' onclick='return gotoHRef( this.href)'>"+ e.Nom +" "+ v( e.Pre) +"</a> "+ v( e.Cls) +"<br>";
			}
		} else {
			h+= "Equipes:</td><td>";

			for( ie=0; ie < jat.J.length; ie++) {
				e = jat.J[ ie];
				if( e && e.Equ) {
					for( c=0; c < e.Equ.length; c++) {
						if( e.Equ[c] == jou)
							h+= "<a href='fich.htm#j"+ ie +"' onclick='return gotoHRef( this.href)'>"+ e.Nom +"</a> ";
					}
				}
			}
		}			
		h+= "</td></tr>";

		h+= "<tr><td align=right valign=top>Matches:</td><td>";
		h+= "<table>";
		for( ie=0; ie < jat.E.length; ie++) {
			be = 0;

			e = jat.E[ ie];

			if( j.Ins & ( 1 << ie)) {
				if( !( be++))
					h+= "<tr><td colspan=2><b>"+ e.Nom +"</b></td></tr>";
			}

			for( it=0; it < e.T.length; it++) {
				t = e.T[ it];
				if( !t) continue;
					
				if( t.Typ < 2) {
					ibmin = iBasColQ( iColMinQ( t.Qua) +1, t.Qua);
					for( ib=t.B.length-1; ib >=ibmin ; ib--) {
						b = t.B[ib]; 
						if( b && b.Jou==jou) {
							if( !( be++))
								h+= "<tr><td colspan=2><b>"+ e.Nom +"</b></td></tr>";

							ba = t.B[ IAUTRE( ib)];
							bm = t.B[ IMATCH( ib)];

							h+= htmlMatch( jat, ba, bm, ie, it, ib);
						}
					}
				} else {	//Poule

					for( im = (t.Col * t.Col)-1; im>0; im--) {

						bm = t.B[ im];
						r = iRowPoule( im, t.Col);
						c = iColPoule( im, t.Col);

						if( bm && !isCache( bm)) 
						{
							ia1 = POULE_ADVERSAIRE1( im, t.Col);
							ia2 = POULE_ADVERSAIRE2( im, t.Col);

							b1 = t.B[ ia1];
							b2 = t.B[ ia2];

							if( ((b1 && b1.Jou == jou) || (b2 && b2.Jou == jou)) && ia1 != ia2) {
								if( !( be++))
									h+= "<tr><td colspan=2><b>"+ e.Nom +"</b></td></tr>";

								ba = (b1.Jou == jou ? b2 : b1);

								h+= htmlMatch( jat, ba, bm, ie, it, im);
							}
						}
					}
				}
			}
		}
		h+= "</table>";

		h+= "</td></tr></table>";
	}
	return h;

	function htmlMatch( jat, ba, bm, ie, it, ib)
	{
		var h="";
		var ja;
		
		h= "<tr>";
		if( ba && ba.Jou>=0) {
			ja = jat.J[ ba.Jou];
			h+= "<td><a href='#j"+ ba.Jou +"' onclick='return gotoHRef( this.href)'>"+ ja.Nom +" "+ v( ja.Pre) +"</a></td><td>"+ v( ja.Cls) +"</td>";
		} else
		if( ba && ba.QE)
			h+= "<td>Q"+ (ba.QE!=-1?ba.QE:"") +"</td><td></td>";
		else {
			var c, t;
			t = jat.E[ ie].T[it];
			if( (t.Typ==0 || t.Typ==1) && t.Qua==1 && (c = iCol( ib))< 5)
				h+= "<td><i>"+ (c>1? "1/"+ (1<<(c-1)) +" " : "") +"finaliste</i></td><td></td>";
			else
				h+= "<td></td><td></td>";
		}

		h+= "<td>: <a href='tabl.htm#e"+ ie +";t"+ it +";b"+ ib +"'>";
		if( bm && bm.Jou>=0) {
			if( bm.Jou == jou && String( bm.Sco).indexOf( "VD") == -1)
				h+= "victoire</a></td><td>"+ v( bm.Sco);
			else
				h+= "défaite</a></td><td>"+ v( bm.Sco);
		} else
			h+= "à jouer</a>";

		h+= "</td>";

		if( bm && bm.Dat && jat.Deb && jat.Deb <= bm.Dat && bm.Dat < (jat.Fin.valueOf() + unjour))
			h+= "<td>, <a href='plan.htm#d"+ iJour( bm.Dat, jat.Deb) +"'>"+ fmtDate( bm.Dat, 1) +"</a></td>";
		h+= "</tr>";

		return h;
	}
}

function htmlPlanning( jat, jour)
{
	var h="";
	var i, j, m, e, t, b, b1, b2, j1, j2, nm, c;
	var njour;

	njour = (jat.Fin - jat.Deb) / unjour +1;

	if( njour>99)	//v0999
		njour=99;

	if( !jour)
		jour = 0;
	if( jour >= njour)
		jour = njour -1;

	//===================================

	if( jat.D[ jour] && (nm = jat.D[ jour].M.length)) {

		h+= "<table border='1' cellspacing='0' cellpadding='5' width='100%'>";
		h+= "<tr>";
		h+= "<th>Heure</th>";
		h+= "<th>Tableau</th>";
		h+= "<th>Joueur 1</th>";
		h+= "<th>V/D</th>";
		h+= "<th>Score</th>";
		h+= "<th>Joueur 2</th>";
		h+= "</tr>";

		for( i=0; nm>i; i++) {

			m = jat.D[ jour].M[i];

			e = m.epreuve(jat);
			t = m.tableau(jat);
			b = m.boite(jat);

			if( t.Typ == 0 || t.Typ == 1) {
				b1 = t.B[ ADVERSAIRE1( m.b)];
				b2 = t.B[ ADVERSAIRE2( m.b)];
			} else {
				//Poule
				b1 = t.B[ POULE_ADVERSAIRE1( m.b, t.Col)];
				b2 = t.B[ POULE_ADVERSAIRE2( m.b, t.Col)];
			}

			j1 = (b1 && b1.Jou>=0) ? jat.J[ b1.Jou] : 0;
			j2 = (b2 && b2.Jou>=0) ? jat.J[ b2.Jou] : 0;

			h+= "<tr>";

			h+= "<td>"+ fmtHeure( b.Dat) +"</td>";
			h+= "<td>"+ e.Nom +"<br><a href='tabl.htm#e"+ m.e +";t"+ m.t +";b"+ m.b +"'>"+ t.Nom +"</a></td>";

			h+= "<td>"+ htmlJoueur( j1, t, b1, m.b) +"</td>";

			if( b && b.Jou>=0) {
				h+= "<td align=center>"+ ((b1 && b.Jou == b1.Jou) ? "V" : "D") +"</td>";
				h+= "<td align=center>"+ v( b.Sco) +"</td>";
			} else
				h+= "<td>&nbsp;</td><td>&nbsp;</td>";

			h+= "<td>"+ htmlJoueur( j2, t, b2, m.b) +"</td>";

			h+= "</tr>";
		}

		h+= "</table>";
	}
	return h;

	function htmlJoueur( oJ, oT, oB, ib)
	{
		var h="";

		if( oJ)
			h+= "<a href='fich.htm#j"+ oB.Jou +"'>"+ oJ.Nom +" "+ v( oJ.Pre) +"</a> "+ v( oJ.Cls);
		else
		if( oB.QE)
			h+= "Q"+ (oB.QE!=-1?oB.QE:"");
		else
		if( (oT.Typ==0 || oT.Typ==1) && oT.Qua==1 && (c = iCol( m.b))< 4)
			h+= "<i>"+ (c? "1/"+ (1<<c) +" " : "") +"finaliste</i>";
		else
			h+= "&nbsp;";

		return h;
	}
}

function isMatch( t, i) {
	if( ADVERSAIRE1( i) > iBoiteMaxQ( t.Col, t.Qua) 
	||  ADVERSAIRE2( i) > iBoiteMaxQ( t.Col, t.Qua))
		return false;

	if( t.Typ == 2)	//Poule
		return iColPoule( i, t.Col) < t.Col && iColPoule( i, t.Col) < iRowPoule( i, t.Col);

	if( t.Typ == 3)	//Poule A/R
		return iColPoule( i, t.Col) < t.Col && iColPoule( i, t.Col) != iRowPoule( i, t.Col);

	b = t.B[ ADVERSAIRE1( i)];
	if( b && (b.Jou>=0 || b.QE))
		return true;

	b = t.B[ ADVERSAIRE2( i)];
	if( b && (b.Jou>=0 || b.QE)) 
		return true;

	return false;
}

function htmlResultat( jat, ie, nc)
{
	var h="";
	var oE, iv;

	if( !nc)
		nc = 3;	//Nb tours

	e = jat.E[ ie]; 

	for( it=0; it < e.T.length; it++) { 
		t = e.T[ it]; 
		if( !t) continue;

		if( (t.Typ == 0 || t.Typ == 1) && t.Qua == 1) {

			h+= "<h4><a href='tabl.htm#e"+ ie +";t"+ it +"'>"+ t.Nom +"</a></h4><blockQuote><table cellpadding=5>";

			b = t.B[ 0];
			if( b && b.Jou>=0) {
				j = jat.J[ b.Jou];

				h+= "<tr><td>Vainqueur:</a></td>";

				h+= "<td><a href='fich.htm#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ v( j.Clu) +"</td><td>"+ v( b.Sco) +"</td></tr>";
			}
			
			cMax = iColMaxQ( t.Col, t.Qua);
			for( c=0; c<nc && c<cMax; c++) {

				s = c ? ("1/"+ (1<<c) +" finalistes: ") : "Finaliste: ";

				for( ib = iHautCol( c); ib >= iBasColQ( c, t.Qua); ib--) {

					//1/c Finaliste
					b = t.B[ ib];
					if( b && b.Jou>=0) {

						if( c < cMax) {
							b1 = t.B[ ADVERSAIRE1( ib)];
							iv = (b1 && b1.Jou == b.Jou) ? ADVERSAIRE2( ib) : ADVERSAIRE1( ib);
							b = t.B[ iv];
						}

						if( b && b.Jou>=0) {
							h+= "<tr><td>"+ s +"</td><td>";
							s = "&nbsp;";

							j = jat.J[ b.Jou];
							h+= "<a href='fich.htm#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ v( j.Clu) +"</td></tr>";
						}
						
					} else {

						if( isMatch( t, ib)) {

							for( iv = ADVERSAIRE1( ib);; iv = IAUTRE( iv)) {

								b = t.B[ iv];

								if( b && b.Jou>=0) {
									h+= "<tr><td>"+ s +"</td><td>";
									s = "&nbsp;";

									j = jat.J[ b.Jou];
									h+= "<a href='fich.htm#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ v( j.Clu) +"</td></tr>";
								}
								if( iv & 1)
									break;
							}
						}
					}
				}
			}

			h+= "</table></blockQuote>";
		}
	}
	return h;
}

function htmlListe( jat)
{
	var istart, tri, nom;

	var re;
	var i;
	var u = String( document.location).split( "#");
	var p = u[1];
	curU = u[0];

	if( p)
	{
		p = p.split( "&");

		re = new RegExp( "^([a-z]+)=([A-Za-z0-9%]+)$");

		for( i=0; i < p.length; i++)
		{
			if( p[i].match(re)) {
				//try {
					eval( RegExp.$1 + "=\"" + unescape( RegExp.$2) + "\";");
				//} catch(e) {}
			}
		}

	}

	return htmlListeParam( jat, istart, tri, nom);
}

function htmlListeParam( jat, istart, tri, nom, npp)
{
	var h="";
	function strcmp(a,b) {
		if( a==b) return 0;
		if( a>b) return 1;
		return -1;
	}
	function cmp_Nom(a,b) {   
		ja = jat.J[ a];
		jb = jat.J[ b];
		return strcmp(ja.Nom, jb.Nom);
	}
	function cmp_Ann(a,b) {
		ja = jat.J[ a];
		jb = jat.J[ b];
		var r = (jb.Dat ? jb.Dat :0) - (ja.Dat ? ja.Dat :0);
		return r ? r : cmp_Nom(a,b);
	}
	function cmp_Sex(a,b) {   
		ja = jat.J[ a];
		jb = jat.J[ b];
		var r = strcmp(ja.Sex, jb.Sex);
		return r ? r : cmp_Nom(a,b);
	}
	function cmp_Cla(a,b) {   
		ja = jat.J[ a];
		jb = jat.J[ b];
		var r = -strcmp(ja.Cls, jb.Cls);
		return r ? r : cmp_Nom(a,b);
	}
	function cmp_Clu(a,b) {   
		ja = jat.J[ a];
		jb = jat.J[ b];
		var r = strcmp(ja.Clu, jb.Clu);
		return r ? r : cmp_Nom(a,b);
	}

	var nav="";

	//Paramètres par défaut

	if( isNaN( istart))	istart=0;
	if( isNaN( npp))	npp=20;
	if( !tri) tri="Nom";
	if( !nom) nom="";

	istart = Number( istart);

	var nj = jat.J.length;

	//Index des joueurs affichés
	var ind = new Array(nj);
	for( i=0; i < nj; i++)
		ind[i]=i;

	//Filtre par nom
	if( nom && nom.length) {
		var ind2=new Array();
		for( i=0; i < nj; i++) {
			j = jat.J[ i];

			if( RegExp( "^"+ nom, "i").exec( j.Nom))	//commençant par
//			if( RegExp( nom, "i").exec( j.Nom))		//contenant
				ind2[ ind2.length] = i;
		}
		ind = ind2;
		nj = ind.length;
	}

	//Formulaire de recherche par Nom
	h+= "<form name='frmlist' method='get' onsubmit=\"return gotoHash('tri="+ tri +"&nom='+ escape( document.frmlist.nom.value) ); \">";
	h+= "Rechercher par nom:&nbsp;";
	h+= "<input type='text'   name='nom' id='nom' value='"+ nom +"'>";
	h+= "<input type='submit' value='Go'>";
	if( nom)
		h+= " <input type='button' value='Tous' onclick=\"return gotoHash('tri="+ tri +"&nom=');\">";
	h+= "</form>";

	if( !istart || istart < 0 || istart >= nj)
		istart = 0;

	nav = "<p>"+ (nj < jat.J.length ? nj +" / " : "")+ jat.J.length +"&nbsp;participants.  ";
	if( nj > npp) {
		if( istart > 0)
			nav += "<a href='#istart="+ (istart-npp) +"&tri="+ tri +"&nom="+ escape( nom) +"' onclick='return gotoHRef( this.href)'>&lt;&lt;&lt;</a> ";

		for( ij=0; ij < nj; ij += npp) {
			if( ij == istart)
				nav += " ["+ (Math.floor(ij / npp) +1) +"]";
			else
				nav += " <a href='#istart="+ ij +"&tri="+ tri +"&nom="+ escape( nom) +"' onclick='return gotoHRef( this.href)'>&nbsp;"+ (Math.floor(ij / npp) +1) +"&nbsp;</a>";
		}
		if( istart+npp < nj)
			nav += "&nbsp;<a href='#istart="+ (istart+npp) +"&tri="+ tri +"&nom="+ escape( nom) +"' onclick='return gotoHRef( this.href)'>&gt;&gt;&gt;</a>";
	}
	nav += "</p>";

	if( nj == 0) {
		h+= "<i>Liste vide</i><br>\n";
	} else {
		h+= nav;

		h+= "<table border='1' cellspacing='0' cellpadding='3'><tr>";

		var cols = new Array( "Sexe", "Nom - Prénom", "Année", "Classement", "Club");
		var k;
		for( k=0; cols.length>k; k++) {

			iv=cols[k];
			v3 = String( iv).substring(0, 3);
			if( tri == v3)
				h+= "<th>"+ iv +"</th>";
			else
				h+= "<th><a href='#tri="+ v3 +"&nom="+ escape( nom) +"' onclick='return gotoHRef( this.href)'>"+ iv +"</a></th>";
		}
		h+= "</tr>";

		//Tri l'index
		ind.sort( eval( "cmp_"+ tri));

		for( ij=istart; ij < nj && ij < (istart+npp); ij++) {
			if( ind[ ij] >= 0) {
				j = jat.J[ ind[ ij]];
				if( j) {
					h+= "<tr><td align=center>"+ j.Sex +"</td>";
					h+= "<td><a href='fich.htm#j"+ ind[ ij] +"'>"+ j.Nom +" "+ v( j.Pre) +"</a></td>";
					h+= "<td align=center>"+ (j.Dat ? j.Dat.getFullYear() : "&nbsp;") +"</td>";
					h+= "<td align=center>"+ (j.Cls ? j.Cls : "&nbsp;") +"</td>";
					h+= "<td>"+ v( j.Clu) + "&nbsp;</td></tr>";
				}
			}
		}
		h+= "</table>";

		h+= nav;
	}
	return h;
}

//=========Fonctions Netscape

// Netscape fix resize bug Ns4
function NS_CssFix() 
{
	if( document.NS.initWidth  != window.innerWidth ||
	    document.NS.initHeight != window.innerHeight) 
		document.location = document.location;
}

function NS_CssFixCheckIn() 
{
	if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) 
	{
		if (typeof document.NS == 'undefined')
		{
			document.NS = new Object;
			document.NS.initWidth  = window.innerWidth;
			document.NS.initHeight = window.innerHeight;
		}
		window.onresize = NS_CssFix;
	}
}

NS_CssFixCheckIn();
