function individuel(nom, elo, gr) {
 nb=parseInt(gr.length/4);
 if (elo.length>=4) {elo_int=parseInt(elo.substring(elo.length-4,elo.length));} else {elo_int=0;}
 fide = isFide(elo);
  	
 if (elo!="") elo=" ("+elo+")";

 moy_elo=0;
 nb_joueurs=0;

 for (j=0; j<nb; j++) {
  temp=gr[4*j+2];
  if (temp.length>=4) {moy_elo=moy_elo+parseInt(temp.substring(temp.length-4,temp.length)); nb_joueurs++;}
 }

 if (nb_joueurs>0) strmoy=" <i>(moy:"+parseInt(moy_elo/nb_joueurs+.5)+")</i>"; else strmoy="";

 document.write("<br><table border=1 cellspacing=1 cellpadding=0 background='/img/fond2.jpg'>");
 document.write("<tr><th width=500 background='/img/fond4.jpg' class=moyen>"+nom+elo+"</th></tr>");
 document.write("<tr><td width=500>");
 document.write("<br><center><table border=1 cellspacing=0 cellpadding=0>");
 document.write("<tr><th width=50>Ronde</th><th width=50>Coul.</th><th><b>Adversaires</b>"+strmoy+"</th><th width=50>Score</th></tr>");

 points=0;
 nb_parties=0;

 perf_elo=0;
 perf_points=0;
 perf_nb=0;
 
 fide_elo=0;
 fide_points=0;
 fide_nb=0;

 for (j=0; j<nb; j++) {
  temp=gr[4*j+2];
  if (temp.length>=4) {temp_int=parseInt(temp.substring(temp.length-4,temp.length));} else {temp_int=0;}
  perf_ok=0;

  if ((gr[4*j+3]!='') && (gr[4*j+3]!=' ')) nb_parties=nb_parties+1; else perf_ok=1;

  if (gr[4*j+3]=='0') {
   if (fide==false && temp_int>0) {
    if (temp_int-elo_int<=350) {
     perf_elo=perf_elo+temp_int;
     perf_nb++;
     perf_ok=1;
    }
    if (isFide(temp)) {
     fide_elo=fide_elo+temp_int;
     fide_nb++;
    }    
   }
   else if (fide==true && isFide(temp)==true) {
    if (temp_int-elo_int>350) temp_int = elo_int+350;
    if (elo_int-temp_int>350) temp_int = elo_int-350;
    perf_elo=perf_elo+temp_int;
    perf_nb++;
    perf_ok=1;
   }
  }

  if (gr[4*j+3]=='1') {
   points++;
   if (fide==false && temp_int>0) {
    if (elo_int-temp_int<=350) {
     perf_elo=perf_elo+temp_int;
     perf_nb++;
     perf_points++;
     perf_ok=1;
    }
    if (isFide(temp)) {
     fide_elo=fide_elo+temp_int;
     fide_nb++;
     fide_points=fide_points+1;
    }    
   }
   else if (fide==true && isFide(temp)==true) {
    if (temp_int-elo_int>350) temp_int = elo_int+350;
    if (elo_int-temp_int>350) temp_int = elo_int-350;
    perf_elo=perf_elo+temp_int;
    perf_nb++;
    perf_points++;
    perf_ok=1;
   }
  }

  if (gr[4*j+3]=='2' || gr[4*j+3]=='1/2') {
   points=points+.5;
   if (fide==false && temp_int>0) {
    perf_elo=perf_elo+temp_int;
    perf_nb++;
    perf_points=perf_points+0.5;
    perf_ok=1;
    if (isFide(temp)) {
     fide_elo=fide_elo+temp_int;
     fide_nb++;
     fide_points=fide_points+.5;
    }    
   }
   else if (fide==true && isFide(temp)==true) {
    if (temp_int-elo_int>350) temp_int = elo_int+350;
    if (elo_int-temp_int>350) temp_int = elo_int-350;
    perf_elo=perf_elo+temp_int;
    perf_nb++;
    perf_points=perf_points+0.5;
    perf_ok=1;
   }
  }

  if (gr[4*j+3]=='1F') points=points+1;

  ligne_individuel(j+1, gr[4*j], gr[4*j+1], gr[4*j+2], gr[4*j+3], perf_ok);
 }
 
 perf_moyenne=parseInt(perf_elo/perf_nb+.5);
 perf_pourcentage=parseInt(100*perf_points/perf_nb+.5);
 if (perf_nb>0) strPerf="Performance Elo : <b>"+(perf_moyenne+perf(perf_pourcentage))+"</b>"; else strPerf="&nbsp;";

 strFide="";
 if (fide) {
  delta=100*perf_points-pourcTheorique(elo_int-perf_moyenne)*perf_nb;
  gainFide=parseInt(15*delta)/100;
  strFide="<br><i>Variation Fide: <b>";
  if (gainFide>=0) strFide=strFide+"+";
  strFide=strFide+gainFide+"</b> (coef. 15)</i>";
 }
 
 strFFE="";
 if (!fide) {
  if (fide_nb>=3) {
   fide_moyenne=parseInt(fide_elo/fide_nb+.5);
   fide_pourcentage=parseInt(100*fide_points/fide_nb+.5);
   if (fide_pourcentage>50) {
    perfFide=parseInt(fide_moyenne+12.5*(2*fide_points-fide_nb));
   }
   else {
    perfFide=fide_moyenne+perf(fide_pourcentage);
   }

   strFide="<br><i>Perf. Fide: <b>"+perfFide+"</b> sur "+fide_nb+" parties.</i>";
  }
 }  

 document.write("<tr><td>&nbsp;</td><td>&nbsp;</td><td align=center>"+strPerf+strFide+strFFE+"</td><th>"+points+" / "+nb_parties+"</th></tr>");
 document.write("</table></center><br>");
 if (perf_nb<nb_parties) document.write("<div align=left class=petit>&nbsp;(*) Partie non-compatible pour la performance elo.</div>");
 document.write("</td></tr>");
 document.write("</table>");
}

function ligne_individuel(num,coul,nom,elo,res,perf_ok) {
 if (res=="2" || res=="1/2") res="&frac12;";
 if (res=="") res="&nbsp;";
 if (perf_ok==0) res=res+"*";
 document.write("<tr align=center><td align=center><b>"+num+"</b></td><td>");
 if (coul=='b' || coul=='B') {document.write("<img src='/img/case14b.gif' width=14 height=14>");}
 else if (coul=='n' || coul=='N') {document.write("<img src='/img/case14n.gif' width=14 height=14>");}
 else {document.write("&nbsp;");}
 document.write("</td><td align=left><table border=0 cellspacing=0 cellpadding=0><tr><td width=180>&nbsp;"+nom+"</td><td class=petit align=right width=60>"+elo+"&nbsp;</td></tr></table></td><td>"+res+"</td></tr>");
}

function perf(p)
{
 if (p<50) return (-1*perf(100-p));
 if (p==50) return 0;
 if (p==51) return 7;
 if (p==52) return 14;
 if (p==53) return 21;
 if (p==54) return 29;
 if (p==55) return 36;
 if (p==56) return 43;
 if (p==57) return 50;
 if (p==58) return 57;
 if (p==59) return 65;
 if (p==60) return 72;
 if (p==61) return 80;
 if (p==62) return 87;
 if (p==63) return 95;
 if (p==64) return 102;
 if (p==65) return 110;
 if (p==66) return 117;
 if (p==67) return 125;
 if (p==68) return 133;
 if (p==69) return 141;
 if (p==70) return 149;
 if (p==71) return 158;
 if (p==72) return 166;
 if (p==73) return 175;
 if (p==74) return 184;
 if (p==75) return 193;
 if (p==76) return 202;
 if (p==77) return 211;
 if (p==78) return 220;
 if (p==79) return 230;
 if (p==80) return 240;
 if (p==81) return 251;
 if (p==82) return 262;
 if (p==83) return 273;
 if (p==84) return 284;
 if (p==85) return 296;
 if (p==86) return 309;
 if (p==87) return 322;
 if (p==88) return 336;
 if (p==89) return 351;
 if (p==90) return 366;
 if (p==91) return 383;
 if (p==92) return 401;
 if (p==93) return 422;
 if (p==94) return 444;
 if (p>=95) return 470;
}

function pourcTheorique(p)
{
 if (p<0) return (100-pourcTheorique(-p));
 if (p<4) return 50;
 if (p<11) return 51;
 if (p<18) return 52;
 if (p<26) return 53;
 if (p<33) return 54;
 if (p<40) return 55;
 if (p<47) return 56;
 if (p<54) return 57;
 if (p<62) return 58;
 if (p<69) return 59;
 if (p<77) return 60;
 if (p<84) return 61;
 if (p<92) return 62;
 if (p<99) return 63;
 if (p<107) return 64;
 if (p<114) return 65;
 if (p<122) return 66;
 if (p<130) return 67;
 if (p<138) return 68;
 if (p<146) return 69;
 if (p<154) return 70;
 if (p<163) return 71;
 if (p<171) return 72;
 if (p<180) return 73;
 if (p<189) return 74;
 if (p<198) return 75;
 if (p<207) return 76;
 if (p<216) return 77;
 if (p<226) return 78;
 if (p<236) return 79;
 if (p<246) return 80;
 if (p<257) return 81;
 if (p<268) return 82;
 if (p<279) return 83;
 if (p<291) return 84;
 if (p<303) return 85;
 if (p<316) return 86;
 if (p<329) return 87;
 if (p<345) return 88;
 if (p<358) return 89;
 if (p<375) return 90;
 if (p<392) return 91;
 if (p<412) return 92;
 if (p<433) return 93;
 if (p<457) return 94;
 if (p<485) return 95;
 if (p<518) return 96;
 if (p<560) return 97;
 if (p<620) return 98;
 if (p<736) return 99;
 return 100;
}

function isFide(elo) 
{
 if (elo.length>=4) {
  if (elo.substring(0, 2)=='CF' || elo.substring(0, 2)=='MI' || elo.substring(0, 2)=='GM' || elo.substring(0, 2)=='MF') {
   return true;
  }
 }
 return false;
}