var cptsensTri = new Array(1,1,1,0,-1)
var cptptrs    = new Array()
var cptdata = new Array()
var cpttitres = new Array()
var bgprec = ""
// =========================================================================
function generCompet(m) {
//  affiche_attente("g&eacute;neration de la compet")
	iptrs=new Array()
	var nompilote=""
	var id=0
	var d=0
	var nd=0
	bgprec="'#f5f5f5'"
  var nommanche

	nm=cpt[0].length
	nm=nm/3
	if(nm<2) {m=0;nm=1;d=1;}
	if(nm== 0) dw('PB de longueur du tableau cpt')
	if (!m)
		m=0
		
//	for ( ic = 0 ; ic < nm ; ic++ ) {
//    nommanche[]="R"
//    }
  nl = cpt.length

// remplissage du tableau
cpttitres = new Array('','place','pilote','temps/dist','points')
cptdata = new Array()
	for ( il = 0 ; il < nl ; il++ )
		{
		id=trouve(pilotes,cpt[il][0],'')
    nompilote=lien_pil(pilotes[id][0],2006)
		if(cpt[il][0]==pilotecherche)
			buffer="<A name=p id=p>"
		else
			buffer=""
		if(m>0 || nm==1)
			//if (cpt[il][3*m+2+d]>0)
			if (cpt[il][3*m+d]!=0)
			   cptdata[il]= new Array(cpt[il][0],placeopen(cpt[il][3*m+d]),nompilote,cpt[il][3*m+1+d]+buffer,cpt[il][3*m+2+d])
   			else
			   {nd++;cptdata[il]= new Array(cpt[il][0],'','','','')}
		else
			{
			for ( ic = 1 ; ic < nm ; ic++ ) {
				buffer+=(ic>1 ? ", " : "<font size=-1 color=blue>") + cpt[il][3*ic+2+d]} + (ic>1 ? "" : "</font>")
			cptdata[il]= new Array(cpt[il][0],placeopen(cpt[il][1]),nompilote,buffer,cpt[il][2])
			}
		}

if(m==0 && nm>1)
	{cpttitres[3]="manches"; intitule="Classement g&eacute;n&eacute;ral sur "+(id_compet==102 || id_compet==555? "les 3 meilleures":nm-1)+" manches"}
else
	if(nm==1)
		intitule="Une seule manche a &eacute;t&eacute; courue"
	else
		intitule="R&eacute;sultats de la manche "+m+"/"+(nm-1)


	if(cptptrs.length==0)
		{
		if(nm>1)
			{
			dw('<TABLE width=100% style=BORDER="0" CELLSPACING="0" BGCOLOR="#f5f5f5" ><TR>')
			for ( ic = 0 ; ic < nm ; ic++ )
			    dw('<TD style="border-right: 2px outset;border-left: 1px solid;BORDER-TOP:1px solid;-moz-border-radius-topleft: 10px; -moz-border-radius-topright: 10px;" align=center id=mche'+ic+' onClick="generCompet('+ic+');" '
					+"onmouseover=\"if(this.style.backgroundColor=='#c5c5c5' || this.style.backgroundColor=='rgb(197, 197, 197)') this.style.backgroundColor='#ffffe0';\""
					+" onmouseout=\"if(this.style.backgroundColor=='#ffffe0' || this.style.backgroundColor=='rgb(255, 255, 224)') this.style.backgroundColor='#c5c5c5';\" "
					+'><B>'+(ic==0 ? 'G&eacute;n&eacute;ral':((nm>5 ? 'M':'manche')+' '+ic))+'</B></TD>');
			dw('</TR></TABLE>')
			}
		dw("<DIV style='background:#f5f5f5' id='divcpt'></DIV>")
		cptptrs=generGrid("cpt")
		calc_podium(true)
		}
	else
		cptsensTri[colprec]=cptsensTri[colprec]
	if(nm>1)
		for ( ic = 0 ; ic < nm ; ic++ )
			{
			getElement(false,"mche"+ic).style.background=(ic==m ? '#f5f5f5':'#c5c5c5')
			getElement(false,"mche"+ic).style.borderBottom=(ic==m ? '0' : '2px outset')
			}

	getElement(false,'divcpt').innerHTML="<I>"+intitule+" ("+(nl-nd)+" pilotes) : </I>"+texte_manche[m]
	bool=true
	cptptrs=resultat("cpt",colprec)
}
