/*
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( \"tournoi_tabl.php#\" + this.options[this.selectedIndex].value,1)'>\n";
		h+= "<option selected><choisissez un tableau></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'>===== "+ jat.E[ e].Nom +" =====</option>";

		for (t = 0; oE.T.length > t; t++) 
		{
		    if (!oE.T[t]) continue; //EC 080310
		    
			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, ms, njour, deb;
 
	if( !jat.Deb || !jat.Fin || !jat.D.length)
		return h;
 
	deb = jat.Deb;
	njour = (jat.Fin - jat.Deb) / unjour +1;
 
	if( isNaN(jour)) {
		h+= "<select onchange='gotoHRef( \"tournoi_plan.php#\" + this.options[this.selectedIndex].value,1)'>\n";
		h+= "<option selected><choisissez une date></option>\n";
	} else
		h+= "<select onchange='gotoHash( this.options[this.selectedIndex].value)'>\n";
		h+= "<option selected><choisissez une date></option>\n";
 
	ms = deb.valueOf();
	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( new Date( ms)) +"</option>\n";
		}
		ms += unjour;
	}
	h+= "</select>\n";
 
	return h;
}
 
function htmlNomJour( jat, jour)
{
	var h="";
 
	if( jat.Deb && jat.D[ jour])
		h+= fmtDateL( new Date( jat.Deb.valueOf() + jour * (Date.UTC( 2002,1,2) - Date.UTC( 2002,1,1)) ));
 
	return h;
}
 
function htmlMenujour2( jat, jour)
{
	var h="";
	var i, ms, njour, deb;
	var bp=0, is, mss, d;
 
	if( !jat.Deb || !jat.Fin || !jat.D.length)
		return h;
 
	deb = jat.Deb;
	njour = (jat.Fin - jat.Deb) / unjour +1;
	jour = parseInt( jour);
 
	ms = deb.valueOf();
	for( i=0; i< njour; i++) 
	{
		if( jat.D[i] && jat.D[i].M.length) 
		{
			d = new Date( ms);
 
			if( !bp && i < jour)
			{
				bp = 1;
					h+= "<a href='#d"+ i + "' onclick='return gotoHRef( this.href)'><<<</a> ";
					
			}
 
			if( i == jour)
				h+= " ["+ fmtDateS( d) +"] ";
			else
				h+= "<a href='#d"+ i + "' onclick='return gotoHRef( this.href)'>"+ fmtDateS( d) +"</a> ";
 
			if( i > jour)
			{
				is = i;
				mss = ms;
			}
		}
		ms += unjour;
	}
 
	if( is >= 0)
        h+= "<a href='#d"+ is + "' onclick='return gotoHRef( this.href)'>>>></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='95%' align='center'>";
 
			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) + " ";
 
							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)
//PD: 190203 suppression du club								h+= Club( oJ.Clu);
								h+= " ";
 
							h+= htmlScore( jat, oB);
						}
					}
 
					h+= "</td>\n";
 
					if( iv & 1)
						break;
 
					iv = IMATCH( iv);
					ib = IMATCH( ib);
				}
 
				h+= "</tr>\n";
			}
 
			h+= "</table>";
		} else {
			//Poule
//190203 Couleur des bordures dans les boites des poules			h+= "<table border=1 cellspacing=0 cellpadding=5>\n";
			h+= "<table border=1 bordercolor=#EDBAB1 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 +" "+ v( oJ.Pre).substring( 0, 1) +"</td>";
				} else
					h+= " </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+= " </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);
//PD 200203 : ajout suite commentaire Eloi Chabaud
//PD 260203						h+= " "
						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)
//PD: 190203 suppression du n° d'ordre			h+= "<i><small>"+ oB.Ord +"</small></i> ";
			h+= "";
		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 +"</a> ";
			else
				h+= "Q"+ oB.QE +" ";
		}
 
		if( oB.Jou>=0) {
			h+= "<a href='tournoi_fich.php#j" + oB.Jou +"'>";
			if( oB.Ord || ib==0)
//190203 Nom et prénom en gras				h+= "<b>"+ oJ.Nom +" "+ v( oJ.Pre) +"</b></a> "+ v( oJ.Cls);
				h+= "<B>"+ oJ.Nom +" </B> "+ v( oJ.Pre) +"</a> "+ v( oJ.Cls);
			else
				h+= oJ.Nom +" "+ 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='tournoi_fich.php#j"+ breq.Jou +"'>";
				h+= jreq.Nom +" "+ v( jreq.Pre).substring( 0, 1) +"</a>";
				h+= " se retire";
			}
		}
 
		return h;
	}
 
	function htmlScore( jat, oB)
	{
		var h="";
 
		if( oB.Dat) {
//PD 260203 			if( jat.Deb && jat.Deb <= oB.Dat && oB.Dat < (jat.Fin.valueOf() + 86400000))
			if( jat.Deb && jat.Deb <= oB.Dat && oB.Dat < (jat.Fin.valueOf() + unjour))
 
				h+= "<a href='tournoi_plan.php#d"+ iJour( oB.Dat, jat.Deb) +"'>" + fmtDate( oB.Dat,1) +"</a><br>";
			else
				h+= fmtDate( oB.Dat,1) +"<br>";
		}
 
		h+= oB.Sco ? oB.Sco : " ";
 
		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 cellspacing=0 cellpadding=5><tr valign=top>";
 
//	Affichage du nom
//190203 Nom en gras		h+= "<td align=right>Nom:</td><td><b>"+ j.Nom +"</b></td></tr>";
				h+= "<td align=right>Nom:</td><td><b>"+ j.Nom +"</b></td></tr>";
		if( !j.Equ)
 
//	Affichage du prénom
//190203 Prénom en gras			h+= "<tr><td align=right>Prenom:</td><td><b>"+ v( j.Pre) +"</b> </td></tr>";
			h+= "<tr><td align=right>Prénom:</td><td>"+ v( j.Pre) +" </td></tr>";
		h+= "<tr><td align=right>Classement:</td><td>"+ v( j.Cls) +" </td></tr>";
 
//-------PD le 17/02/2003 : les lignes suivantes sont en commentaire mais on peut les rendre actives pour afficher plus d'infos
// Affichage de "double"
//		h+= "<tr><td align=right>Double:</td><td>"+ v( j.Cld) +" </td></tr>";
 
// Affichage du club
//		h+= "<tr><td align=right>Club:</td><td>"+ Club( v( j.Clu)) +" </td></tr>";
		h+= "<tr><td align=right>Année:</td><td>"+ (j.Dat ? j.Dat.getFullYear() : " ") +"</td></tr>";
		if( !j.Equ)
 
//PD 190203		Affichage licence avec lien sur palmares vers site FFT
//PD 190203		h+= "<tr><td align=right>Licence:</td><td>"+ (j.Lic ? "<a  href='http://www.fft.fr/bdd/recherche_classement/palmares.asp?LICENCE="+ j.Lic +"' target='_blank'>"+ j.Lic +"</a>" : " ") +"</td></tr>";
 
//PD 190203		Affichage licence sans lien sur palmares
		h+= "<tr><td align=right>Licence:</td><td>"+ v(j.Lic )  + " </td></tr>";
		
		h+= "<tr><td align=right>Sexe:</td><td>"+ v( j.Sex) +"</td></tr>";
 
//	Affichage Adresse
//		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>";
 
//Affichage Téléphone
//		h+= "<tr><td align=right valign=top>Téléphone:</td><td>"+ v( j.Te1) + (j.Te2 ? "<br>"+ j.Te2 :"") +" </td></tr>";
 
//	Affichage e-mail
//		h+= "<tr><td align=right>Mél:</td><td>"+ (j.Mel ? "<a href='mailto:"+ j.Mel +"'>"+ j.Mel +"</a>" : " ") +"</td></tr>";
 
//	Affichage Commentaire
//		h+= "<tr><td align=right valign=top>Commentaire:</td><td>"+ v( j.Cmt).split( "\n").join( "<br>") +" </td></tr>";
//	Affichage Equipiers
//		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='t_fich.php#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='t_fich.php#j"+ ie +"' onclick='return gotoHRef( this.href)'>"+ e.Nom +"</a> ";
//					}
//				}
//			}
//		}			
		h+= " </td></tr>";
 
//	Affichage des matchs joués ou à jouer
		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;   //EC 080310
			    
				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);
 
//PD 26020203								h+= htmlMatch( jat, ba, bm, ie, it, bm);
								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 +"</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='tournoi_tabl.php#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>";
 
//PD 260203		if( bm && bm.Dat && jat.Deb && jat.Deb <= bm.Dat && bm.Dat < (jat.Fin.valueOf() + 86400000))
		if( bm && bm.Dat && jat.Deb && jat.Deb <= bm.Dat && bm.Dat < (jat.Fin.valueOf() + unjour))
			h+= "<td>, <a href='tournoi_plan.php#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 deb, njour;
//PD 260203 suppression par Eloi	var unjour = (Date.UTC( 2002,1,2) - Date.UTC( 2002,1,1));
 
	deb = jat.Deb;
 
	njour = (jat.Fin - jat.Deb) / unjour +1;
 
	if( njour>40)	
		njour=40;
 
	if( !jour)
		jour = 0;
	if( jour >= njour)
		jour = njour -1;
 
	//===================================
 
	if( jat.D[ jour] && (nm = jat.D[ jour].M.length)) {
 
		h+= "<table class=liste>";
		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 align=center>"+ fmtHeure( b.Dat) +"</td>";
			h+= "<td align=center>"+ e.Nom +"<br><a href='tournoi_tabl.php#e"+ m.e +";t"+ m.t +";b"+ m.b +"'>"+ t.Nom +"</a></td>";
 
			h+= "<td align=center>"+ 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 align=center>"+ 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='tournoi_fich.php#j"+ oB.Jou +"'>"+ oJ.Nom +" "+ v( oJ.Pre) +"</a> "+ v( oJ.Cls);
		else
		if( oB.QE)
			h+= "Q"+ 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+= " ";
 
		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; //EC 080310
 
		if( (t.Typ == 0 || t.Typ == 1) && t.Qua == 1) {
 
			h+= "<h4><a href='tournoi_tabl.php#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>";
 
//PD: 190203 suppression du club				h+= "<td><a href='t_fich.php#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ Club( v( j.Clu)) +"</td><td>"+ v( b.Sco) +"</td></tr>";
				h+= "<td><a href='tournoi_fich.php#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ " " +"</td><td>"+ v( b.Sco) +"</td></tr>";
			}
			
			cMax = iColMaxQ( t.Col, t.Qua);
			for( c=0; c<nc; c++) {
				if( c <= cMax) {
 
					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 = " ";
 
								j = jat.J[ b.Jou];
 
//PD: 190203 suppression du club								h+= "<a href='t_fich.php#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ Club( v( j.Clu)) +"</td></tr>";
								h+= "<a href='tournoi_fich.php#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ " " +"</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 = " ";
 
										j = jat.J[ b.Jou];
 
//PD: 190203 suppression du club										h+= "<a href='t_fich.php#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ Club( v( j.Clu)) +"</td></tr>";
										h+= "<a href='tournoi_fich.php#j"+ b.Jou +"'><b>"+ j.Nom +"</b> "+ v( j.Pre) +" "+ v( j.Cls) +"</a> "+ " " +"</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( "&");
 
//PD 260203		re = new RegExp( "^([a-z]+)=([A-Za-z0-9]+)$");
		re = new RegExp( "^([a-z]+)=([A-Za-z0-9%]+)$");
 
		for( i=0; i < p.length; i++)
		{
			if( p[i].match(re)) {
				//try {
//PD 260203					eval( RegExp.$1 + "=\"" + RegExp.$2 + "\";");
					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
//PD 260203	h+= "<form name='frmlist' method='get' onsubmit=\"return gotoHash('tri="+ tri +"&nom='+ document.frmlist.nom.value ); \">";
	h+= "<form name='frmlist' method='get' onsubmit=\"return gotoHash('tri="+ tri +"&nom='+ escape( document.frmlist.nom.value) ); \">";
	h+= "Rechercher un nom ";
//	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+= "<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)'><<<</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)'> "+ (Math.floor(ij / npp) +1) +" </a>";
		}
		if( istart+npp < nj)
			nav += " <a href='#istart="+ (istart+npp) +"&tri="+ tri +"&nom="+ escape( nom) +"' onclick='return gotoHRef( this.href)'>>>></a>";
	}
	nav += "</p>";
 
	if( nj == 0) {
		h+= "<i>Liste vide</i><br>\n";
	} else {
		h+= nav;
 
		h+= "<table class=liste><tr>";
 
		var cols = new Array( "Sexe", "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
//PD 260203				h+= "<th><a href='#tri="+ v3 +"&nom="+ nom +"' onclick='return gotoHRef( this.href)'>"+ iv +"</a></th>";
				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='tournoi_fich.php#j"+ ind[ ij] +"'>"+ j.Nom +" "+ v( j.Pre) +"</a></td>";
					h+= "<td align=center>"+ (j.Dat ? j.Dat.getFullYear() : " ") +"</td>";
					h+= "<td align=center>"+ (j.Cls ? j.Cls : " ") +"</td>";
					h+= "<td>"+ v( j.Clu) + " </td></tr>";
				}
			}
		}
		h+= "</table>";
 
		h+= nav;
	}
	return h;
}
 
// ==========Spécial Décaler et Déclarer
function htmlListe3( jat)
{
	var h="";
	
	function strcmp(a,b) {
		if( a==b) return 0;
		if( a>b) return 1;
		return -1;
	}
	
	//fonctions de comparaison pour le tri de joueurs
	var fnTri={
		Nom: function(a,b) {   
			var ja = jat.J[ a];
			var jb = jat.J[ b];
			return strcmp(ja.Nom, jb.Nom);
		}
		,NomPrenom: function(a,b) {   
			var ja = jat.J[ a];
			var jb = jat.J[ b];
			return strcmp(ja.Nom, jb.Nom) || strcmp(ja.Pre, jb.Pre)
			;
		}
	};
 
	var nj = jat.J.length;	//nombre de joueurs
 
	if( 0 == nj) {
		h+= "<i>Liste vide</i>\n";
	} else {
 
		//Index des joueurs a trier
		var ind = new Array(nj);
		for( var i=0; i < nj; i++) {
			ind[i]=i;
		}
		ind.sort( fnTri[ "NomPrenom"]);	//tri
 
		//Résultat
		for( i=0; i < nj; i++) {
			var j = jat.J[ ind[ i]]; //un joueur
			if( j && j.Ins) {	//inscrit seulement
				h+= '<option value="'+ escapeHTML( (j.Pre || "") +' '+ j.Nom ) + '"">'+ escapeHTML( j.Nom +' '+ (j.Pre || "")) + "</option>\n";
			}
		}
	}
 
	return h;
}
 
function escapeHTML( s)
{
	return String(s).replace( /&/g, "&amp;").replace( /</g, "&lt;").replace( />/g, "&gt;").replace( /"/g, "&quot;");	//.replace( /'/g, "&apos;");
}
 
//=========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();