

var PLAYERNAME =0;
var PLAYERSTRENGTH =1;
var GAMESPLAYED =2;
var GAMESCASHED =3;
var GAMESBUBBLED =4;
var NLHRANKPOINTS =5;
var NONNLHRANKPOINTS =6;
var SNGKNOCKOUTS =7;
var ITMPERCENTAGE =8;
var ROIPERCENTAGE =9;
var HEADSUPWINS =10;
var HEADSUPLOSSES =11;
var PROFIT =12;
var FINISH_EARLY =13;
var FINISH_EARLYMID =14;
var FINISH_MID =15;
var FINISH_MIDLATE =16;
var FINISH_LATE =17;
var VALIDGAMESPLAYED =18;
var TENPLUSPLAYERGAMESPLAYED=19;
var AVG_FINISH=20;
var STRENGTH_GAMESWON=21;
var STRENGTH_NLHRANKPOINTS=22;
var STRENGTH_NONNLHRANKPOINTS=23;
var STRENGTH_SNGKNOCKOUTS=24;
var STRENGTH_ITMPERCENTAGE=25;
var STRENGTH_ROIPERCENTAGE=26;
var STRENGTH_HEADSUP=27;
var STRENGTH_FINISH=28;
var HEADSUPPERCENTAGE=29;
var EARLY_COUNT=30;
var EARLYMID_COUNT=31;
var MID_COUNT=32;
var LATEMID_COUNT=33;
var LATE_COUNT=34;
var ITM_COUNT=35;
var ROI_INVESTMENT=36;
var ROI_RETURN=37;
var GAMES_WON=38;
var SECOND_PLACES=39;

<!-- write game summary panel -->
function write_gameSummary(gameinfo_array,gamefinish_array,gamestoprint) 
{
  document.write("<div id=game_summary_panel>");
  if (gamestoprint==undefined)
  {
    gamestoprint=10;
  }
  for (a=gameinfo_array.length; a>=(gameinfo_array.length-gamestoprint); a--) 
  {
    //check if game exist
    if (gameinfo_array[a]==undefined) 
    {
      //document.write("game#" + a + " undefined<br>");
    } 
    else 
    {
      document.write("<div class=singlegameinfo><font size=2 color=&#34;0000cc>");
      document.write("<a href=../gameresults/#gm");
      document.write(gameinfo_array[a][0][2]);
      document.write(a);
      document.write(">");
      document.write("GAME#" + a + " </a></font>  ");
      document.write("<b><font size=2pt>");
      //game - eg NLH
      if (gameinfo_array[a][1][0]==undefined) 
      {
	document.write("n/a");
      } 
      else 
      {
	document.write("&nbsp;&nbsp;<font size=2>");
	document.write(gameinfo_array[a][1][0] + " ");
	//check if game type 1 exist eg heads up, KO
	if (gameinfo_array[a][1][1]==undefined) 
        {
	  document.write("");
	}
        else
        {
	  document.write(gameinfo_array[a][1][1] + "  ");
	}
	document.write("</font><br>");
      }
      document.write("</font></b>");
      //check if date exist
      document.write("<font size=1pt>");
      if ((gameinfo_array[a][0][0]==undefined)||(gameinfo_array[a][0][1]==undefined)||(gameinfo_array[a][0][2]==undefined)) {
	document.write("<br>");
      } else {
	document.write("&nbsp;&nbsp;&nbsp;&nbsp;<font size=2>" + gameinfo_array[a][0][0] + " " + gameinfo_array[a][0][1] + ", " + gameinfo_array[a][0][2] + "</font><br>");
      }
      document.write("</font>");
      //check dmg chip time
      document.write("<font size=1pt>");
      if (gameinfo_array[a][2][0]==undefined)
      {
        //
      }
      else 
      { 
        document.write("&nbsp;&nbsp;&nbsp;&nbsp;dmg=<font color=&#35;dd0000>" + gameinfo_array[a][2][0] + "</font>"); 
        //check KO bounty amount
	if (gameinfo_array[a][2][1]==0) 
        {
          //not bounty game
        } 
        else 
        { 
          document.write("+<font color=&#35;dd0000>" + gameinfo_array[a][2][1] + "</font>");
        }
        //starting stack
	if (gameinfo_array[a][2][2]==undefined)
        {
          //no starting stack info
        }
	else 
        { 
          document.write("<br>&nbsp;&nbsp;&nbsp;&nbsp;stack=<font color=&#35;dd0000>" + gameinfo_array[a][2][2] + "</font> "); 
	  if (gameinfo_array[a][2][3]==undefined) 
          {
            //no stack info to print
          }
	  else 
          { 
            document.write("<br>&nbsp;&nbsp;&nbsp;&nbsp;blinds=<font color=&#35;dd0000>" + gameinfo_array[a][2][3] + "</font> min "); 
	  }
	}
      }
      document.write("</font>");
      document.write("<br>");
      //check winner
      document.write("<font size=1>WINNER:</font> <font size=2 color=&#34;00aa00><b>" + gamefinish_array[a][1] + "</b></font>");
      document.write("<br>");
      //check #players
      document.write("<font size=1pt>");
      document.write("&nbsp;&nbsp;&nbsp;&nbsp;# of plyrs: " + ((gamefinish_array[a].length-1)/3) + "<br>");
      document.write("</font>");
      document.write("</div><br>");
    }
  }
  document.write("</div>");
}





<!-- rank player (single game) -->
function gameRankPlayer(i_entrants, i_position, r_buyin) 
{
  /////INVALIDS
  if ( i_entrants==undefined) 
  {
    return "Func gameRankPlayer INVALID 1 - missing three arguments";
  }
  if ( r_buyin==undefined) 
  {
    return "Func gameRankPlayer INVALID 2 - missing two arguments";
  }
  if ( i_position==undefined) 
  {
    return "Func gameRankPlayer INVALID 3 - missing one argument";
  }
  var temprankpoints = 0;
  if ( i_position<=(i_entrants/2) ) 
  {
    /////only the first half (minus 1 if odd)
    /////finishes of a tournament receive
    /////rank points
    temprankpoints = ( 2 * Math.sqrt(i_entrants) * Math.sqrt(2) * Math.log(i_entrants) * Math.sqrt(r_buyin) )
                   / ( Math.log(10) * (Math.log(i_position+2)/Math.log(10)+i_position) )
                   + r_buyin/10;
    /////multiplying by 10 to give 
    /////sense of "largeness"
    temprankpoints = temprankpoints * 10;
  }
  else 
  {
    temprankpoints = 0;
  }
  return temprankpoints;
}




<!-- initialize rank table -- >
function init_RankTable(tablestats)
{
  tablestats[0]=new Array(18);
  tablestats[0][0]="okay";
  tablestats[0][PLAYERNAME]="Player ID";
  tablestats[0][PLAYERSTRENGTH]="rating<sup>0</sup>";
  tablestats[0][GAMESPLAYED]="games played<sup>1</sup>";
  tablestats[0][GAMESCASHED]="games cashed<sup>2</sup>";
  tablestats[0][GAMESBUBBLED]="bubbles<sup>5</sup>";
  tablestats[0][NLHRANKPOINTS]="NLH rank pts<sup>3</sup>";
  tablestats[0][NONNLHRANKPOINTS]="non-NLH rank pts<sup>4</sup>";
  tablestats[0][SNGKNOCKOUTS]="SNG KOs<sup>5</sup>";
  tablestats[0][ITMPERCENTAGE]="ITM%<sup>5</sup>";
  tablestats[0][ROIPERCENTAGE]="ROI%<sup>1</sup>";
  tablestats[0][HEADSUPWINS]="headsup wins<sup>6</sup>";
  tablestats[0][HEADSUPLOSSES]="headsup losses<sup>6</sup>";
  tablestats[0][PROFIT]="profit";
  tablestats[0][FINISH_EARLY]="Early Finish<sup>7</sup>";
  tablestats[0][FINISH_EARLYMID]="EarlyMid Finish<sup>7</sup>";
  tablestats[0][FINISH_MID]="Mid Finish<sup>7</sup>";
  tablestats[0][FINISH_MIDLATE]="MidLate Finish<sup>7</sup>";
  tablestats[0][FINISH_LATE]="Late Finish<sup>7</sup>";
  tablestats[0][VALIDGAMESPLAYED]="6+plyr games";
  tablestats[0][TENPLUSPLAYERGAMESPLAYED]="10+plyr games";
  tablestats[0][AVG_FINISH]="AVG FiN";
  tablestats[0][STRENGTH_GAMESWON]="s_cashed";
  tablestats[0][STRENGTH_NLHRANKPOINTS]="s_nlh";
  tablestats[0][STRENGTH_NONNLHRANKPOINTS]="s_n-nlh";
  tablestats[0][STRENGTH_SNGKNOCKOUTS]="s_KOs";
  tablestats[0][STRENGTH_ITMPERCENTAGE]="s_itm";
  tablestats[0][STRENGTH_ROIPERCENTAGE]="s_roi";
  tablestats[0][STRENGTH_HEADSUP]="s_hu";
  tablestats[0][STRENGTH_FINISH]="s_fin";
  tablestats[0][HEADSUPPERCENTAGE]="hu %";
  tablestats[0][EARLY_COUNT]="e_ct";
  tablestats[0][EARLYMID_COUNT]="em_ct";
  tablestats[0][MID_COUNT]="mid_ct";
  tablestats[0][LATEMID_COUNT]="lm_ct";
  tablestats[0][LATE_COUNT]="l_ct";
  tablestats[0][ITM_COUNT]="itm_ct";
  tablestats[0][ROI_INVESTMENT]="roi_i";
  tablestats[0][ROI_RETURN]="roi_r";
  tablestats[0][GAMES_WON]="gm wins";
  tablestats[0][SECOND_PLACES]="2nd places";

  return tablestats;
}





<!-- add player name to rank table -->
function addPlayers(tablestats,game) 
{
  var playeronlist=false;
  var playercount=0;
  for (num=1; num<game.length; num++) 
  {
    if (game[num]==undefined) 
    {
      //document.write("game number " + num + " undefined game<br>");
    } 
    else 
    {
      for (pos=0; pos<((game[num].length-1)/3); pos++) 
      {
        //check if name is on list
        //document.write("checking player " + game[num][(pos*3+1)] + "<br>");
	for (player=1; player<=playercount; player++) 
        {
	  if (game[num][(pos*3+1)]==tablestats[player][PLAYERNAME]) 
          {
	    playeronlist=true;
	  }
	}
	if (playeronlist==false) 
        {
	  //add player on list
	  playercount++;
          tablestats[playercount]=new Array(18);
          tablestats[playercount][PLAYERNAME]=game[num][(pos*3+1)];
          //document.write(" *** added " + tablestats[playercount][PLAYERNAME] + " onto player list || player count is now " + playercount + "<br>");
	} 
        else 
        {
	  //document.write(" -- player already on list<br>");
	  playeronlist=false;
	}
      }
    }
  }
  return tablestats;
}




 
<!-- add games played -->
function addGamesPlayed(tablestats,game)
{
  var gamecount = 0;
  var validgamecount = 0;
  var tenplus = 0;
  var cashed = 0;
  for (player=1; player<tablestats.length; player++) 
  {
    for (num=1; num<game.length; num++) 
    {
      if (game[num]==undefined) 
      {
        //document.write("--" + num + "game not defined<br>");
      } 
      else 
      {
        for (pos=0; pos<((game[num].length-1)/3); pos++) 
        {
	  if (game[num][pos*3+1]==tablestats[player][0]) 
          {
	    gamecount++;
            if ( ((game[num].length-1)/3)>2 ) 
            {
              if (game[num][pos*3+3]>0) 
              {
                cashed++;
              }
	      if ( ((game[num].length-1)/3)>=6 ) 
              {
                validgamecount++;
                if ( ((game[num].length-1)/3)>=10 ) 
                {
                  tenplus++;
                }
              }
            }
	  }
	}
      }
    }
    tablestats[player][GAMESPLAYED]=gamecount;
    tablestats[player][VALIDGAMESPLAYED]=validgamecount;
    tablestats[player][TENPLUSPLAYERGAMESPLAYED]=tenplus;
    tablestats[player][GAMESCASHED]=cashed;
    gamecount=0;
    validgamecount=0;
    tenplus=0;
    cashed=0;
  }
  return tablestats;
}




<!-- add bubble count -->
function addBubble(tablestats,game) 
{
  var gamecount=0;
  //times bubbled
  for (player=1; player<tablestats.length; player++) 
  {
    //document.write(player + " " + tablestats[player][PLAYERNAME] + "<br>");
    for (num=1; num<game.length; num++) 
    {
      if (game[num]==undefined) {
        //document.write("--" + gamenum + "game not defined<br>");
      } 
      else 
      if ( ((game[num].length-1)/3)>=6 ) 
      {
	//document.write("--game number " + num + "<br>");
        for (pos=0; pos<((game[num].length-1)/3); pos++) 
        {
	  //document.write("-----" + gamefinish_array[num][pos*3+1] + "<br>");
	  if (game[num][pos*3+1]==tablestats[player][0]) 
          {
	    if (game[num][pos*3+3]==0) 
            {
	      if (game[num][pos*3]>0) 
              {
	        gamecount++;
    		//document.write("bubbled game " + num + "<br>");
	      }
	    }
	  }
	}
      }
    }
    tablestats[player][GAMESBUBBLED]=gamecount;
    gamecount=0;
  }
  return tablestats;
}





<!-- add NLH Rank Points -->
function addNLHRankPoints(tablestats,game,info)
{
  var rankpointcount = 0;
  for (player=1; player<tablestats.length; player++) 
  {
    for (gamenum=1; gamenum<game.length; gamenum++)
    {
      if ( (game[gamenum]==undefined)||(info[gamenum][1][0]!="NLH") ) 
      {
        //document.write("--" + gamenum + " failed or non NLH<br>");
      } else 
      if ( ((game[gamenum].length-1)/3)>=6 ) 
      {
        for (pos=0; pos<((game[gamenum].length-1)/3); pos++) 
        {
	  if (game[gamenum][pos*3+1]==tablestats[player][PLAYERNAME]) 
          {
	    rankpointcount = rankpointcount + gameRankPlayer(((game[gamenum].length-1)/3),(pos+1),info[gamenum][2][0]);
	  }
	}
      }
    }
    tablestats[player][NLHRANKPOINTS]=rankpointcount;
    rankpointcount=0;
    
  }
  return tablestats;
}




<!-- add_gamewins -->
function addGameWins(tablestats,game,info)
{
  var gmwins=0;
  for (player=1; player<tablestats.length; player++) 
  {
    for (gamenum=1; gamenum<game.length; gamenum++)
    {
      if (game[gamenum]==undefined) 
      {
        //document.write("--" + gamenum + " failed<br>");
      } else 
      if ( ((game[gamenum].length-1)/3)>=6 ) 
      {
	if (game[gamenum][1]==tablestats[player][PLAYERNAME]) 
        {
	  gmwins++;
	}
      }
    }
    tablestats[player][GAMES_WON]=gmwins;
    gmwins=0;
  }
  return tablestats;
}




<!-- add_gamewins -->
function add2ndPlace(tablestats,game,info)
{
  var gmwins=0;
  for (player=1; player<tablestats.length; player++) 
  {
    for (gamenum=1; gamenum<game.length; gamenum++)
    {
      if (game[gamenum]==undefined) 
      {
        //document.write("--" + gamenum + " failed<br>");
      } else 
      if ( ((game[gamenum].length-1)/3)>=6 ) 
      {
	if (game[gamenum][4]==tablestats[player][PLAYERNAME]) 
        {
	  gmwins++;
	}
      }
    }
    tablestats[player][SECOND_PLACES]=gmwins;
    gmwins=0;
  }
  return tablestats;
}




<!-- create_RankTable -->
function create_RankTable(gameinfo_array,gamefinish_array,mingames,rebuys_array,addons_array) 
{
  //var player_array = create_PlayerList(gamefinish_array);
  var rank_table = new Array();
  rank_table = init_RankTable(rank_table);
  rank_table = addPlayers(rank_table,gamefinish_array);
  rank_table = addGamesPlayed(rank_table,gamefinish_array);
  rank_table = addBubble(rank_table,gamefinish_array);
  rank_table = addNLHRankPoints(rank_table,gamefinish_array,gameinfo_array);
  rank_table = addGameWins(rank_table,gamefinish_array,gameinfo_array);
  rank_table = add2ndPlace(rank_table,gamefinish_array,gameinfo_array);

var rankpointcount=0;

	  //non-NLH Rank pts
	  for (player=1; player<rank_table.length; player++) {
    for (gamenum=1; gamenum<gamefinish_array.length; gamenum++) {
      if ( (gamefinish_array[gamenum]==undefined)||(gameinfo_array[gamenum][1][0]=="NLH") ) {
        //document.write("--" + gamenum + "game not defined<br>");
      } else 
      if ( ((gamefinish_array[gamenum].length-1)/3)>=6 ) {
	//document.write("--game number " + gamenum + "<br>");
        for (pos=0; pos<((gamefinish_array[gamenum].length-1)/3); pos++) {
	  if (gamefinish_array[gamenum][pos*3+1]==rank_table[player][PLAYERNAME]) {
	    rankpointcount = rankpointcount + gameRankPlayer(((gamefinish_array[gamenum].length-1)/3),(pos+1),gameinfo_array[gamenum][2][0]);
	  }
	}
      }
    }
    rank_table[player][NONNLHRANKPOINTS]=rankpointcount;
    rankpointcount=0;
  }


	  //sng KOs
  var kocount = 0;
	  for (player=1; player<rank_table.length; player++) {
    //document.write(rank_table[player][PLAYERNAME] + "<br>");
    for (gamenum=1; gamenum<gamefinish_array.length; gamenum++) {
      if (gamefinish_array[gamenum]==undefined) {
        //document.write("--" + gamenum + "game not defined<br>");
      } else 
      if ( ((gamefinish_array[gamenum].length-1)/3)>=6 ) {
	//document.write("--game number " + gamenum + "<br>");
        for (pos=0; pos<((gamefinish_array[gamenum].length-1)/3); pos++) {
	  if (gamefinish_array[gamenum][pos*3+2]==rank_table[player][PLAYERNAME]) {
	    //document.write("KO in " + gamenum + " <br>");
	    kocount++;
	  }
	}
      }
    }
    rank_table[player][SNGKNOCKOUTS]=kocount;
    kocount=0;
  }
	  //ITM%
  var itm=0;
	  for (player=1; player<rank_table.length; player++) {
    //document.write(rank_table[player][PLAYERNAME] + "<br>");
    for (gamenum=1; gamenum<gamefinish_array.length; gamenum++) {
      if (gamefinish_array[gamenum]==undefined) {
        //document.write("--" + gamenum + "game not defined<br>");
      } else 
      if ( ((gamefinish_array[gamenum].length-1)/3)>=6 ) {
	//document.write("--game number " + gamenum + "<br>");
        for (pos=0; pos<((gamefinish_array[gamenum].length-1)/3); pos++) {
	  if (gamefinish_array[gamenum][pos*3+1]==rank_table[player][PLAYERNAME]) {
	    if (gamefinish_array[gamenum][pos*3+3]>0) {
	      itm++;
	    }
	  }
	}
      }
    }
    rank_table[player][ITMPERCENTAGE]=(itm/rank_table[player][VALIDGAMESPLAYED])*100;
    rank_table[player][ITM_COUNT]=itm;
    itm=0;
  }
	  //ROI%
  var i=0;
  var r=0;
  for (player=1; player<rank_table.length; player++) {
    //document.write("player name=" + rank_table[player][PLAYERNAME] + "<br>");
    for (gamenum=1; gamenum<gamefinish_array.length; gamenum++) {
      if (gamefinish_array[gamenum]==undefined) {
        //document.write("--" + gamenum + "game not defined<br>");
      } else 
      if ( ((gamefinish_array[gamenum].length-1)/3)>0 ) {
	//document.write("--game number " + gamenum + "<br>");
        for (pos=0; pos<((gamefinish_array[gamenum].length-1)/3); pos++) {
	  if (gamefinish_array[gamenum][pos*3+1]==rank_table[player][PLAYERNAME]) {
	    //document.write("1.investement= " + i +"<br>");
	    i=i+gameinfo_array[gamenum][2][0];
	    //document.write("2.investement= " + i +"<br>");
	    //document.write("1.return= " + r +"<br>");
	    r=r+gamefinish_array[gamenum][pos*3+3];
	    //document.write("2.return= " + r +"<br>");
	  }
	  //check for bounties
	  if ( (gamefinish_array[gamenum][pos*3+2]==rank_table[player][PLAYERNAME])&&(gameinfo_array[gamenum][1][1]=="KO") ) {
	    //document.write("KO at " + gamenum + "<br>");
	    r=r+gameinfo_array[gamenum][2][1];
	  }
	}
      }
    }
    for (gamenum=1; gamenum<rebuys_array.length; gamenum++)
    {
      if (rebuys_array[gamenum]!=undefined)
      {
        for (rebuy=0;rebuy<rebuys_array[gamenum].length;rebuy++)
        {
          if (rebuys_array[gamenum][rebuy] == rank_table[player][PLAYERNAME])
          {
            //document.write("game " + gamenum + " " + rebuys_array[gamenum][rebuy] + " rebought<br>");
	    i=i+gameinfo_array[gamenum][2][0];
          }
        }
      }
    }
    for (gamenum=1; gamenum<addons_array.length; gamenum++)
    {
      if (addons_array[gamenum]!=undefined)
      {
        for (addon=0;addon<addons_array[gamenum].length;addon++)
        {
          if (rebuys_array[gamenum][addon] == rank_table[player][PLAYERNAME])
          {
            //document.write("game " + gamenum + " " + addons_array[gamenum][addon] + " added on<br>");
	    i=i+gameinfo_array[gamenum][2][0];
          }
        }
      }
    }
    rank_table[player][ROIPERCENTAGE]=((r-i)/i)*100;
    rank_table[player][ROI_INVESTMENT]=i;
    rank_table[player][ROI_RETURN]=r;
    rank_table[player][PROFIT]=r-i;
    r=0;
    i=0;
  }
	  //heads up wins and losses
  var wins =0;
  var losses =0;
	  for (player=1; player<rank_table.length; player++) {
    //document.write(rank_table[player][PLAYERNAME] + "<br>");
    for (gamenum=1; gamenum<gamefinish_array.length; gamenum++) {
      if (gamefinish_array[gamenum]==undefined) {
        //document.write("--" + gamenum + "game not defined<br>");
      } else 
      if ( (((gamefinish_array[gamenum].length-1)/3)==2) && (gameinfo_array[gamenum][2][0]>=0) ) {
	//document.write("--game number " + gamenum + "<br>");
        for (pos=0; pos<((gamefinish_array[gamenum].length-1)/3); pos++) {
	  if (gamefinish_array[gamenum][pos*3+1]==rank_table[player][PLAYERNAME]) {
	    if (pos==0) {
	      wins++;
	    }
	    if (pos==1) {
	      losses++;
	    }
	  }
	}
      }
    }
    rank_table[player][HEADSUPWINS]=wins;
    rank_table[player][HEADSUPLOSSES]=losses;
    wins=0;
    losses=0;
  }
	  //heads up wins and losses
  var e=0;
  var em=0;
  var m=0;
  var ml=0;
  var l=0;
  var totalfinishpoints = 0;
	  for (player=1; player<rank_table.length; player++) {
           rank_table[player][AVG_FINISH]=0;
  }
 	  for (player=1; player<rank_table.length; player++) {
    for (gamenum=1; gamenum<gamefinish_array.length; gamenum++) {
      if (gamefinish_array[gamenum]==undefined) {
        //document.write("--" + gamenum + "game not defined<br>");
      } else 
      if ( ((gamefinish_array[gamenum].length-1)/3)>=10 ) {
	//document.write("--game number " + gamenum + "<br>");
        for (pos=0; pos<((gamefinish_array[gamenum].length-1)/3); pos++) {
	  if (gamefinish_array[gamenum][pos*3+1]==rank_table[player][PLAYERNAME]) {
	    if( ((pos+1)/((gamefinish_array[gamenum].length-1)/3)) <= .1) {
	      l++;
	    } else
	    if( ((pos+1)/((gamefinish_array[gamenum].length-1)/3)) <= .3) {
	      ml++;
	    } else
	    if( ((pos+1)/((gamefinish_array[gamenum].length-1)/3)) <= .7) {
	      m++;
	    } else
	    if( ((pos+1)/((gamefinish_array[gamenum].length-1)/3)) <= .9) {
	      em++;
	    } else
	    if( ((pos+1)/((gamefinish_array[gamenum].length-1)/3)) <= 1) {
	      e++;
	    }
	    totalfinishpoints=totalfinishpoints + ((pos+1)/((gamefinish_array[gamenum].length-1)/3));
	  }
	}
      }
    }
    if (rank_table[player][TENPLUSPLAYERGAMESPLAYED]>0) {
      rank_table[player][AVG_FINISH]=1-totalfinishpoints/rank_table[player][TENPLUSPLAYERGAMESPLAYED];
    } else {
      rank_table[player][AVG_FINISH]=0;
    }
    totalfinishpoints = 0;
	    rank_table[player][EARLY_COUNT]=e;
    rank_table[player][EARLYMID_COUNT]=em;
    rank_table[player][MID_COUNT]=m;
    rank_table[player][LATEMID_COUNT]=ml;
    rank_table[player][LATE_COUNT]=l;
	    //document.write(rank_table[player][PLAYERNAME] + " AVG FINISH = " + rank_table[player][AVG_FINISH].toFixed(0) + "<br>");
    rank_table[player][FINISH_EARLY]=((e/rank_table[player][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
    rank_table[player][FINISH_EARLYMID]=((em/rank_table[player][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
    rank_table[player][FINISH_MID]=((m/rank_table[player][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
    rank_table[player][FINISH_MIDLATE]=((ml/rank_table[player][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
    rank_table[player][FINISH_LATE]=((l/rank_table[player][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
    e=0;
    em=0;
    m=0;
    ml=0;
    l=0;
  }
	  rank_table = delete_villain(rank_table);
	  //player strength
  var strength_table = new Array();
	  for (i=1; i<rank_table.length; i++) {
    rank_table[i][STRENGTH_NLHRANKPOINTS]=0;
    rank_table[i][STRENGTH_NONNLHRANKPOINTS]=0;
    rank_table[i][STRENGTH_SNGKNOCKOUTS]=0;
    rank_table[i][STRENGTH_GAMESWON]=0;
    rank_table[i][STRENGTH_ITMPERCENTAGE]=0;
    rank_table[i][STRENGTH_ROIPERCENTAGE]=0;
    rank_table[i][STRENGTH_HEADSUP]=0;
    rank_table[i][STRENGTH_FINISH]=0;
    if ( (rank_table[i][HEADSUPWINS]==0)&&(rank_table[i][HEADSUPLOSSES]==0) ) {
      rank_table[i][HEADSUPPERCENTAGE]=0;
    } else {
      rank_table[i][HEADSUPPERCENTAGE]=rank_table[i][HEADSUPWINS]/(rank_table[i][HEADSUPWINS]+rank_table[i][HEADSUPLOSSES]);
    }
  }
	  rank_table = addStrength(rank_table);
  rank_table = sort_RankTable(rank_table,PLAYERSTRENGTH,NLHRANKPOINTS);
	  return rank_table;
	}
<!-- add player strength stats -->
function addStrength(statstable) {
	  //NLHRANKPOINTS STRENGTH
  statstable = sort_RankTable(statstable,NLHRANKPOINTS,GAMESPLAYED);
  var distributionpoint = 10;
  var firstplayernum=1;
  var secondplayernum=firstplayernum+1;
  var found = false;
  while ( (distributionpoint > 0) && (firstplayernum < statstable.length) ) {
    if ( (statstable[firstplayernum][GAMESPLAYED]>=5) && (statstable[firstplayernum][NLHRANKPOINTS] > 0) ){
      statstable[firstplayernum][STRENGTH_NLHRANKPOINTS]=distributionpoint;
	      distributionpoint--;
	      //document.write(statstable[firstplayernum][PLAYERNAME] + " scores " + statstable[firstplayernum][STRENGTH_NLHRANKPOINTS] + " for NLHRANKPOINTS strength<br>");
	      //document.write("for " + statstable[firstplayernum][NLHRANKPOINTS] + "<br>");
	    }
	    firstplayernum++; 
	  }

	  //NONNLHRANKPOINTS STRENGTH
	  statstable = sort_RankTable(statstable,NONNLHRANKPOINTS,GAMESPLAYED);
	  distributionpoint=10;
	  firstplayernum=1;
	  secondplayernum=firstplayernum+1;
	  while ( (distributionpoint > 0) && (firstplayernum < statstable.length) ) {
	    if ( (statstable[firstplayernum][GAMESPLAYED]>=5) && (statstable[firstplayernum][NONNLHRANKPOINTS] > 0) ){
	      statstable[firstplayernum][STRENGTH_NONNLHRANKPOINTS]=distributionpoint;
	      distributionpoint--;
	      //document.write(statstable[firstplayernum][PLAYERNAME] + " scores " + statstable[firstplayernum][STRENGTH_NONNLHRANKPOINTS] + " for NONNLHRANKPOINTS strength<br>");
	      //document.write("for " + statstable[firstplayernum][NONNLHRANKPOINTS] + "<br>"); 
	    }
	    firstplayernum++; 
	  }

	  var positionholder = 0;

	  //SNGKNOCKOUT STRENGTH
	  statstable = sort_RankTable(statstable,SNGKNOCKOUTS,GAMESPLAYED);

	  distributionpoint=10;
	  firstplayernum=1;
	  secondplayernum=firstplayernum+1;

	  while ( (distributionpoint > 0) && (firstplayernum < statstable.length) && (secondplayernum < statstable.length) && ((distributionpoint-positionholder)>0 || positionholder>0) ) {
	    //find next valid player
	    while ( (found==false) && (secondplayernum<(statstable.length-1)) ){
		if (statstable[secondplayernum][GAMESPLAYED]>=5) {
	          found=true;
		} else {
		  secondplayernum++;
	      }
	    }
	    found=false;

	    if ( (statstable[firstplayernum][GAMESPLAYED]>=5) && (statstable[firstplayernum][SNGKNOCKOUTS]>0) ){
	      statstable[firstplayernum][STRENGTH_SNGKNOCKOUTS]=distributionpoint;
	      if (statstable[firstplayernum][SNGKNOCKOUTS]==statstable[secondplayernum][SNGKNOCKOUTS]) {
		//document.write("if statement true <br>");
		positionholder++;
	      } else {
		//document.write("if statement false <br>");
	        distributionpoint=(distributionpoint-positionholder)-1;
	        positionholder=0;
	      }

	      //document.write(statstable[firstplayernum][PLAYERNAME] + " scores " + statstable[firstplayernum][STRENGTH_SNGKNOCKOUTS] + " for KNOCKOUT strength<br>");
	      //document.write("for " + statstable[firstplayernum][SNGKNOCKOUTS] + "<br>"); 
	    }

	    firstplayernum=secondplayernum;
	    secondplayernum++;

	  }

	  //GAMESwon STRENGTH
	  statstable = sort_RankTable(statstable,GAMES_WON,GAMESPLAYED);

	  distributionpoint=10;
	  firstplayernum=1;
	  secondplayernum=firstplayernum+1;
	  positionholder=0;
	  while ( (distributionpoint > 0) && (firstplayernum < statstable.length) && ((distributionpoint-positionholder)>0) ) {
	    //find next valid player
	    while ( (found==false) && (secondplayernum<(statstable.length-1)) ){
		if (statstable[secondplayernum][GAMESPLAYED]>=5) {
	          found=true;
		} else {
		  secondplayernum++;
	      }
	    }
	    found=false;
	    if ( (statstable[firstplayernum][GAMESPLAYED]>=5) && (statstable[firstplayernum][GAMES_WON]>0) ){
	      statstable[firstplayernum][STRENGTH_GAMESWON]=distributionpoint;
	      if (statstable[firstplayernum][GAMES_WON]==statstable[secondplayernum][GAMES_WON]) {
		positionholder++;
	      } else {
	        distributionpoint=(distributionpoint-positionholder)-1;
	        positionholder=0;
	      }
	      //document.write(statstable[firstplayernum][PLAYERNAME] + " scores " + statstable[firstplayernum][STRENGTH_GAMESWON] + " for GAMESCASHED strength<br>");
	      //document.write("for " + statstable[firstplayernum][GAMESCASHED] + "<br>"); 
	    }
	    firstplayernum=secondplayernum;
	    secondplayernum++;
	  }

	  //ITMPERCENTAGE STRENGTH
	  statstable = sort_RankTable(statstable,ITMPERCENTAGE,GAMESPLAYED);
	  distributionpoint=10;
	  firstplayernum=1;
	  secondplayernum=firstplayernum+1;
	  positionholder=0;
	  while ( (distributionpoint > 0) && (secondplayernum < statstable.length) && ((distributionpoint-positionholder)>0) ) {
	    //find next valid player
	    while ( (found==false) && (secondplayernum<(statstable.length-1)) ){
	      if (statstable[secondplayernum][GAMESPLAYED]>=5) {
	        found=true;
	      } else {
		secondplayernum++;
	      }
	    }
	    found=false;
	    if ( (statstable[firstplayernum][GAMESPLAYED]>=5) && (statstable[secondplayernum]!=undefined) ){
	      statstable[firstplayernum][STRENGTH_ITMPERCENTAGE]=distributionpoint;
	      if (statstable[firstplayernum][ITMPERCENTAGE]==statstable[secondplayernum][ITMPERCENTAGE]) {
		  positionholder++;
	      } else {
	        distributionpoint=(distributionpoint-positionholder)-1;
	        positionholder=0;
	      }
	      //document.write(statstable[firstplayernum][PLAYERNAME] + " scores " + statstable[firstplayernum][STRENGTH_ITMPERCENTAGE] + " for ITMPERCENTAGE strength<br>");
	      //document.write("for " + statstable[firstplayernum][ITMPERCENTAGE] + "<br>"); 
	    }
	    firstplayernum=secondplayernum;
	    secondplayernum++;
	  }

	  //ROIPERCENTAGE STRENGTH
	  statstable = sort_RankTable(statstable,ROIPERCENTAGE,GAMESPLAYED);
	  distributionpoint=10;
	  firstplayernum=1;
	  secondplayernum=firstplayernum+1;
	  positionholder=0;
	  while ( (distributionpoint > 0) && (secondplayernum < statstable.length) && ((distributionpoint-positionholder)>0) ) {
	    //find next valid player
	    while ( (found==false) && (secondplayernum<(statstable.length-1)) ){
	      if (statstable[secondplayernum][GAMESPLAYED]>=5) {
	        found=true;
	      } else {
		secondplayernum++;
	      }
	    }
	    found=false;
	    if ( (statstable[firstplayernum][GAMESPLAYED]>=5) && (statstable[secondplayernum]!=undefined) ){
	      statstable[firstplayernum][STRENGTH_ROIPERCENTAGE]=distributionpoint;
	      if (statstable[firstplayernum][ROIPERCENTAGE]==statstable[secondplayernum][ROIPERCENTAGE]) {
		  positionholder++;
	      } else {
	        distributionpoint=(distributionpoint-positionholder)-1;
	        positionholder=0;
	      }
	      //document.write(statstable[firstplayernum][PLAYERNAME] + " scores " + statstable[firstplayernum][STRENGTH_ROIPERCENTAGE] + " for ROIPERCENTAGE strength<br>");
	      //document.write("for " + statstable[firstplayernum][ROIPERCENTAGE] + "<br>"); 
	    }
	    firstplayernum=secondplayernum;
	    secondplayernum++;
	  }

	  //HEADSUP STRENGTH
//	  statstable = sort_RankTable(statstable,HEADSUPPERCENTAGE,GAMESPLAYED);
//	  distributionpoint=10;
//	  firstplayernum=1;
//	  secondplayernum=firstplayernum+1;
//	  while ( (distributionpoint > 0) && (secondplayernum < statstable.length) && ((distributionpoint-positionholder)>0) ) {
//	    //find next valid player
//	    while ( (found==false) && (secondplayernum<(statstable.length-1)) ){
//	      if (statstable[secondplayernum][GAMESPLAYED]>=5) {
//	        found=true;
//	      } else {
//		  secondplayernum++;
//	      }
//	    }
//	    found=false;
//	    if ( (statstable[firstplayernum][GAMESPLAYED]>=5) && (statstable[firstplayernum][HEADSUPPERCENTAGE]>0) ){
//	      statstable[firstplayernum][STRENGTH_HEADSUP]=distributionpoint;
//	      if (statstable[firstplayernum][HEADSUPPERCENTAGE]==statstable[secondplayernum][HEADSUPPERCENTAGE]) {
//		  positionholder++;
//	      } else {
//	        distributionpoint=(distributionpoint-positionholder)-1;
//	        positionholder=0;
//	      }
//	      //document.write(statstable[firstplayernum][PLAYERNAME] + " scores " + statstable[firstplayernum][STRENGTH_HEADSUP] + " for HEADSUP strength<br>");
//	      //document.write("for " + statstable[firstplayernum][HEADSUPPERCENTAGE] + "<br>"); 
//	    }
//	    firstplayernum=secondplayernum;
//	    secondplayernum++;
//	  }

	  //FINISH STRENGTH
	  statstable = sort_RankTable(statstable,AVG_FINISH,GAMESPLAYED);
	  distributionpoint=10;
	  firstplayernum=1;
	  secondplayernum=firstplayernum+1;
	  while ( (distributionpoint > 0) && (secondplayernum < statstable.length) && ((distributionpoint-positionholder)>0) ) {
	    //find next valid player
	    while ( (found==false) && (secondplayernum<(statstable.length-1)) ){
	      if (statstable[secondplayernum][GAMESPLAYED]>=5) {
	        found=true;
	      } else {
		secondplayernum++;
	      }
	    }
	    found=false;
	    if ( (statstable[firstplayernum][GAMESPLAYED]>=5) && (statstable[secondplayernum]!=undefined) ){
	      statstable[firstplayernum][STRENGTH_FINISH]=distributionpoint;
	      if (statstable[firstplayernum][AVG_FINISH]==statstable[secondplayernum][AVG_FINISH]) {
		  positionholder++;
	      } else {
	        distributionpoint=(distributionpoint-positionholder)-1;
	        positionholder=0;
	      }
	      //document.write(statstable[firstplayernum][PLAYERNAME] + " scores " + statstable[firstplayernum][STRENGTH_FINISH] + " for STRENGTH_FINISH strength<br>");
	      //document.write("for " + statstable[firstplayernum][AVG_FINISH] + "<br>"); 
	    }
	    firstplayernum=secondplayernum;
	    secondplayernum++;
	  }
	  for (playernum = 1; playernum<statstable.length; playernum++) {
	    statstable[playernum][PLAYERSTRENGTH] = statstable[playernum][STRENGTH_GAMESWON]
								+ statstable[playernum][STRENGTH_NLHRANKPOINTS]
								+ statstable[playernum][STRENGTH_NONNLHRANKPOINTS]
								+ statstable[playernum][STRENGTH_SNGKNOCKOUTS]
								+ statstable[playernum][STRENGTH_ITMPERCENTAGE]
								+ statstable[playernum][STRENGTH_ROIPERCENTAGE]
								//+ statstable[playernum][STRENGTH_HEADSUP]
								+ statstable[playernum][STRENGTH_FINISH];
	  }

	return statstable;

	}



<!-- sort table -->
	function sort_RankTable(stats,col,col2) {

	  var temp_holder = new Array();
//document.write("test sort_RankTable");
	  for (player=1; player<stats.length; player++) {
	    for (j=1; j<(stats.length-1); j++) {
	      //document.write ("swap " + player + "," + j + "<br>");
	      if ( stats[j][col] < stats[j+1][col] ) {
		temp_holder=stats[j];
		stats[j]=stats[j+1];
		stats[j+1]=temp_holder;
	      } else 
	      if ( stats[j][col] == stats[j+1][col] ) {
		if ( stats[j][col2] < stats[j+1][col2] ) {
		  temp_holder=stats[j];
		  stats[j]=stats[j+1];
		  stats[j+1]=temp_holder;
		}
	      }
	    }
	  }

	  return stats;

	}


<!-- print table -->
	function print_RankTable(stats,year,mingames) {

	  var barcount = 0;
	  document.write("<center>" + year + " Standings</center>");
	  //document.write("testing function print_RankTable()<br>");
	  if (stats==undefined) {
	    document.write("fugly error --> func print_RankTable unwanted execution<br>");
	  } else {
            //part 1
	    document.write("<table id=stats>");
	    document.write("<tr bgcolor=#999999>");
	    //print headings
	    document.write("<td>pos</td>");
	    document.write("<td class=singledigit></td>");
	    document.write("<td class=full>");
	     document.write(stats[0][PLAYERNAME]);
	    document.write("</td>");
	    document.write("<td class=full>");
	     document.write(stats[0][PLAYERSTRENGTH]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][GAMESPLAYED]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][GAMESCASHED]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][GAMES_WON]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(" ");
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][SECOND_PLACES]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][GAMESBUBBLED]);
	    document.write("</td>");
	    document.write("<td class=percentage align=center>");
	     document.write(stats[0][NLHRANKPOINTS]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(" ");
	    document.write("</td>");
	    document.write("<td class=percentage align=center>");
	     document.write(stats[0][NONNLHRANKPOINTS]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(" ");
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][SNGKNOCKOUTS]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(" ");
	    document.write("</td>");
	    document.write("<td class=percentage align=center>");
	     document.write(stats[0][ITMPERCENTAGE]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(" ");
	    document.write("</td>");
	    document.write("<td class=percentage align=center>");
	     document.write(stats[0][ROIPERCENTAGE]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(" ");
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][HEADSUPWINS]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][HEADSUPLOSSES]);
	    document.write("</td>");
	    //write player stats
	    for (player=1; player<stats.length; player++) {
	    if (stats[player][GAMESPLAYED]>=mingames) 
            {
	      document.write("<tr>");

	      document.write("<td align=right>");
	      document.write(player);
	      document.write("</td>");

	      document.write("<td align=center>");
	      document.write("[]");
	      document.write("</td>");

	      document.write("<td><font size=2>");
	      document.write(stats[player][PLAYERNAME]);
	      document.write("</td>");

	      barcount = 5;
	      document.write("<td align=left><font size=2>");
	      while (barcount<stats[player][PLAYERSTRENGTH]) {
	        if (barcount<=15) 
                {
	          document.write("<img src=../images/redbar.gif>");
	        } else
		  if (barcount<=25) 
                  {
		    document.write("<img src=../images/yellowbar.gif>");
		  }
                  else 
                  {
		    document.write("<img src=../images/greenbar.gif>");
		  }
		  barcount = barcount+5;
		}
		document.write("<font size=1 color=#0066ff>&nbsp;&nbsp;" + stats[player][PLAYERSTRENGTH] + "</font>");
		document.write("</td>");


		document.write("<td align=center><font size=2>");
		  document.write(stats[player][GAMESPLAYED]);
		document.write("</td>");
		document.write("<td align=center><font size=2>");
		  document.write(stats[player][GAMESCASHED]);
		document.write("</td>");
		document.write("<td align=center><font size=2>");
		  document.write(stats[player][GAMES_WON]);
		document.write("</td>");
	        document.write("<td class=singledigit align=center><font color=#0066ff size=1>");
                  if (stats[player][STRENGTH_GAMESWON]>=1)
	            document.write("+" + stats[player][STRENGTH_GAMESWON]);
                  else
	            document.write(" ");
	        document.write("</font></td>");
		document.write("<td align=center><font size=2>");
		  document.write(stats[player][SECOND_PLACES]);
		document.write("</td>");
		document.write("<td align=center><font size=2>");
		  document.write(stats[player][GAMESBUBBLED]);
		document.write("</td>");
		document.write("<td align=right><font size=2>");
		  document.write(stats[player][NLHRANKPOINTS].toFixed(2));
		document.write("</td>");
	        document.write("<td class=singledigit align=center><font color=#0066ff size=1>");
                  if (stats[player][STRENGTH_NLHRANKPOINTS]>=1)
	            document.write("+" + stats[player][STRENGTH_NLHRANKPOINTS]);
	          else
	            document.write(" ");
	        document.write("</font></td>");
		document.write("<td align=right><font size=2>");
		  document.write(stats[player][NONNLHRANKPOINTS].toFixed(2));
		document.write("</td>");
	        document.write("<td class=singledigit align=center><font color=#0066ff size=1>");
                  if (stats[player][STRENGTH_NONNLHRANKPOINTS]>=1)
	            document.write("+" + stats[player][STRENGTH_NONNLHRANKPOINTS]);
                  else
	            document.write(" ");
	        document.write("</font></td>");
		document.write("<td align=center><font size=2>");
		  document.write(stats[player][SNGKNOCKOUTS]);
		document.write("</td>");
	        document.write("<td class=singledigit align=center><font color=#0066ff size=1>");
                  if (stats[player][STRENGTH_SNGKNOCKOUTS]>=1)
	            document.write("+" + stats[player][STRENGTH_SNGKNOCKOUTS]);
                  else
	            document.write(" ");
	        document.write("</font></td>");
		document.write("<td align=right><font size=2>");
		  document.write(stats[player][ITMPERCENTAGE].toFixed(2) + "%");
		document.write("</td>");
	        document.write("<td class=singledigit align=center><font color=#0066ff size=1>");
                  if (stats[player][STRENGTH_ITMPERCENTAGE]>=1)
	            document.write("+" + stats[player][STRENGTH_ITMPERCENTAGE]);
                  else
	            document.write(" ");
	        document.write("</font></td>");
		document.write("<td align=right>");
		if (stats[player][ROIPERCENTAGE]<0) {
		  document.write("<font size=2 color=#ff0000>");
	 	} else {
		  document.write("<font size=2 color=#00ff00>");
		}
		  document.write(stats[player][ROIPERCENTAGE].toFixed(2) + "%");
		document.write("</td>");
	        document.write("<td class=singledigit align=center><font color=#0066ff size=1>");
                  if (stats[player][STRENGTH_ROIPERCENTAGE]>=1)
	            document.write("+" + stats[player][STRENGTH_ROIPERCENTAGE]);
                  else
	            document.write(" ");
	        document.write("</font></td>");
		document.write("<td align=center><font size=2>");
		  document.write(stats[player][HEADSUPWINS]);
		document.write("</td>");
		document.write("<td align=center><font size=2>");
		  document.write(stats[player][HEADSUPLOSSES]);
		document.write("</td>");	
	      }	
	    }
	    document.write("</table>");

            //part 2
	    document.write("<table id=stats>");
	    document.write("<tr bgcolor=#999999>");
	    //print headings
	    document.write("<td>pos</td>");
	    document.write("<td class=singledigit></td>");
	    document.write("<td class=full>");
	     document.write(stats[0][PLAYERNAME]);
	    document.write("</td>");
	    document.write("<td class=percentage align=center>");
	     document.write(stats[0][AVG_FINISH]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(" ");
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][FINISH_EARLY]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][FINISH_EARLYMID]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][FINISH_MID]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][FINISH_MIDLATE]);
	    document.write("</td>");
	    document.write("<td class=singledigit align=center>");
	     document.write(stats[0][FINISH_LATE]);
	    document.write("</td>");
	    //write player stats
	    for (player=1; player<stats.length; player++) {
	    if (stats[player][GAMESPLAYED]>=mingames) 
            {
	      document.write("<tr>");

	      document.write("<td align=right>");
	      document.write(player);
	      document.write("</td>");

	      document.write("<td align=center>");
	      document.write("[]");
	      document.write("</td>");

	      document.write("<td><font size=2>");
	      document.write(stats[player][PLAYERNAME]);
	      document.write("</td>");

		document.write("<td align=center>");
		if (stats[player][AVG_FINISH]>=.70) {
		  document.write("<font size=2 color=#00dd00>");
	 	}
                else
		if (stats[player][AVG_FINISH]>=.30)
                {
		  document.write("<font size=2 color=#dddd00>");
		}
                else
                {
                  document.write("<font size=2 color=#dd0000>");
		}
		  document.write("TOP " + (100-(stats[player][AVG_FINISH]*100).toFixed(0)) + "%");
		document.write("</td>");
	        document.write("<td class=singledigit align=center><font color=#0066ff size=1>");
                  if (stats[player][STRENGTH_FINISH]>=1)
	            document.write("+" + stats[player][STRENGTH_FINISH]);
                  else
	            document.write(" ");
	        document.write("</font></td>");
		document.write("<td align=center>");
		if (stats[player][FINISH_EARLY]>10) {
		  document.write("<font size=2 color=#dd0000>");
	 	} else {
		  document.write("<font size=2 color=#dddd00>");
		}
		  document.write(stats[player][FINISH_EARLY] + "%");
		document.write("</td>");
		document.write("<td align=center>");
		if (stats[player][FINISH_EARLYMID]>20) {
		  document.write("<font size=2 color=#dd0000>");
	 	} else {
		  document.write("<font size=2 color=#dddd00>");
		}
		  document.write(stats[player][FINISH_EARLYMID] + "%");
		document.write("</td>");
		document.write("<td align=center>");
		if (stats[player][FINISH_MID]>40) {
		  document.write("<font size=2 color=#00dd00>");
	 	} else {
		  document.write("<font size=2 color=#dddd00>");
		}
		  document.write(stats[player][FINISH_MID] + "%");
		document.write("</td>");
		document.write("<td align=center>");
		if (stats[player][FINISH_MIDLATE]<20) {
		  document.write("<font size=2 color=#dddd00>");
	 	} else {
		  document.write("<font size=2 color=#00dd00>");
		}
		  document.write(stats[player][FINISH_MIDLATE] + "%");
		document.write("</td>");
		document.write("<td align=center>");
		if (stats[player][FINISH_LATE]<10) {
		  document.write("<font size=2 color=#dddd00>");
	 	} else {
		  document.write("<font size=2 color=#00dd00>");
		}
		document.write(stats[player][FINISH_LATE] + "%");
		document.write("</td>");
	        document.write("</tr>");	
	      }	
	    }
	    document.write("</table>");
	  }



	  print_subscript();
	  document.write("<br><br><br>");

	}

<!-- print out subscripts -->
function print_subscript() 
{
  document.write("<font size=1>");
  document.write("<sup>0</sup> <b>MIN 5 GAMES</b> - best of (10pts max for each category): games cashed, NLH rank points, non_NLH rank points, sng KOs, ITM%, ROI%, headsup record, game finishes<br>");
  document.write("<sup>1</sup> includes headsup / only players with 5+ games played per year are shown<br>");
  document.write("<sup>2</sup> does not include HEADS up games<br>");
  document.write("<sup>3</sup> 6+player NLH games only<br>");
  document.write("<sup>4</sup> 6+player non-NLH games only<br>");
  document.write("<sup>5</sup> 6+player games only<br>");
  document.write("<sup>6</sup> min buy-in = 5<br>");
  document.write("<sup>7</sup> includes only 10+player games<br>");
  document.write("</font>");
}





<!-- write_optionsbar -->
function write_optionsbar(year) 
{
  var bar_length=1110;
  document.write("<table id=options><tr>");
  document.write("<td width=100px bgcolor=&#35;000000><center><font color=&#35;ffffff>");
  if ( year=="Overall")
  {
    document.write("Overall");
  }
  else
  {
    document.write("<a href=../overallstats");
    document.write(">");
    document.write("Overall");
    document.write("</a>");
    document.write("</font></center></td>");
  }
  bar_length=bar_length-100;

  for (y=2011; y>=2008; y--) 
  {
    document.write("<td width=100px bgcolor=&#35;000000><center><font color=&#35;ffffff>");
    if (y==year) 
    {
      document.write(y);
    } 
    else 
    {
      document.write("<a href=../");
      document.write(y);
      document.write(">");
      document.write(y);
      document.write("</a>");
    }
    document.write("</font></center></td>");
    bar_length=bar_length-100;
  }

  document.write("<td width=100px bgcolor=&#35;000000><center><font color=&#35;ffffff>");
  if ( year=="Game Results")
  {
    document.write("Game Results");
  }
  else
  {
    document.write("<a href=../gameresults/");
    document.write(">");
    document.write("Game Results");
    document.write("</a>");
    document.write("</font></center></td>");
  }
  bar_length=bar_length-100;

  document.write("<td width=100px bgcolor=&#35;000000><center><font color=&#35;ffffff>");
  if ( year=="Blind Structure")
  {
    document.write("Blind Structure");
  }
  else
  {
    document.write("<a href=../structure/");
    document.write(">");
    document.write("Blind Structure");
    document.write("</a>");
    document.write("</font></center></td>");
  }
  bar_length=bar_length-100;

  document.write("<td bgcolor=&#35;000000 width=" + bar_length + "px><center> </center></td>");
  document.write("</tr></table>");
}





<!-- combine two rankTables -->
	function combine_RankTables(r1,r2) {

	  //document.write("testing combine_RankTables1");
	  var r3 = new Array();

	  //document.write(r1[1][0]);

	  r1=sort_RankTable(r1,PLAYERNAME,GAMESPLAYED);
	  r2=sort_RankTable(r2,PLAYERNAME,GAMESPLAYED);

	  var pointerone=1;
	  var pointertwo=1;
	  var pointerthree=1;

	  r3[0]=r1[0];
	  while (pointerone<r1.length && pointertwo<r2.length) {
	    if (r1[pointerone][0]>r2[pointertwo][0]) {
	      r3[pointerthree]=r1[pointerone];
	      //document.write("added " + r3[pointerthree][0] + "<br>");
	      pointerthree++;
	      pointerone++;
	    } else 
	    if (r1[pointerone][0]<r2[pointertwo][0]) {
	      r3[pointerthree]=r2[pointertwo];
	      //document.write("added " + r3[pointerthree][0] + "<br>");
	      pointerthree++;
	      pointertwo++;
	    } else {
	      //document.write("double<br>");
	      //add the stats together
	      r3[pointerthree]=r1[pointerone];
	      r3[pointerthree][GAMESPLAYED]=r1[pointerone][GAMESPLAYED]+r2[pointertwo][GAMESPLAYED];
	      r3[pointerthree][GAMESCASHED]=r1[pointerone][GAMESCASHED]+r2[pointertwo][GAMESCASHED];
	      r3[pointerthree][GAMESBUBBLED]=r1[pointerone][GAMESBUBBLED]+r2[pointertwo][GAMESBUBBLED];
	      r3[pointerthree][NLHRANKPOINTS]=r1[pointerone][NLHRANKPOINTS]+r2[pointertwo][NLHRANKPOINTS];
	      r3[pointerthree][NONNLHRANKPOINTS]=r1[pointerone][NONNLHRANKPOINTS]+r2[pointertwo][NONNLHRANKPOINTS];
	      r3[pointerthree][SNGKNOCKOUTS]=r1[pointerone][SNGKNOCKOUTS]+r2[pointertwo][SNGKNOCKOUTS];
//ITM
	      r3[pointerthree][VALIDGAMESPLAYED]=r1[pointerone][VALIDGAMESPLAYED]+r2[pointertwo][VALIDGAMESPLAYED];
	      r3[pointerthree][TENPLUSPLAYERGAMESPLAYED]=r1[pointerone][TENPLUSPLAYERGAMESPLAYED]+r2[pointertwo][TENPLUSPLAYERGAMESPLAYED];
	      r3[pointerthree][ITM_COUNT]=r1[pointerone][ITM_COUNT]+r2[pointertwo][ITM_COUNT];
	      r3[pointerthree][ITMPERCENTAGE]=r3[pointerthree][ITM_COUNT]*100/r3[pointerthree][VALIDGAMESPLAYED];
//ROI
	      r3[pointerthree][ROI_INVESTMENT]=r1[pointerone][ROI_INVESTMENT]+r2[pointertwo][ROI_INVESTMENT];
	      r3[pointerthree][ROI_RETURN]=r1[pointerone][ROI_RETURN]+r2[pointertwo][ROI_RETURN];
	      r3[pointerthree][ROIPERCENTAGE]=(r3[pointerthree][ROI_RETURN]-r3[pointerthree][ROI_INVESTMENT])*100/r3[pointerthree][ROI_INVESTMENT]

	      r3[pointerthree][HEADSUPWINS]=r1[pointerone][HEADSUPWINS]+r2[pointertwo][HEADSUPWINS];
	      r3[pointerthree][HEADSUPLOSSES]=r1[pointerone][HEADSUPLOSSES]+r2[pointertwo][HEADSUPLOSSES];

	      r3[pointerthree][EARLY_COUNT]=r1[pointerone][EARLY_COUNT]+r2[pointertwo][EARLY_COUNT];
	      r3[pointerthree][EARLYMID_COUNT]=r1[pointerone][EARLYMID_COUNT]+r2[pointertwo][EARLYMID_COUNT];
	      r3[pointerthree][MID_COUNT]=r1[pointerone][MID_COUNT]+r2[pointertwo][MID_COUNT];
	      r3[pointerthree][LATEMID_COUNT]=r1[pointerone][LATEMID_COUNT]+r2[pointertwo][LATEMID_COUNT];
	      r3[pointerthree][LATE_COUNT]=r1[pointerone][LATE_COUNT]+r2[pointertwo][LATE_COUNT];

	      r3[pointerthree][FINISH_EARLY]=((r3[pointerthree][EARLY_COUNT]/r3[pointerthree][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
	      r3[pointerthree][FINISH_EARLYMID]=((r3[pointerthree][EARLYMID_COUNT]/r3[pointerthree][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
	      r3[pointerthree][FINISH_MID]=((r3[pointerthree][MID_COUNT]/r3[pointerthree][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
	      r3[pointerthree][FINISH_MIDLATE]=((r3[pointerthree][LATEMID_COUNT]/r3[pointerthree][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);
	      r3[pointerthree][FINISH_LATE]=((r3[pointerthree][LATE_COUNT]/r3[pointerthree][TENPLUSPLAYERGAMESPLAYED])*100).toFixed(0);

	      //document.write("added " + r3[pointerthree][0] + "<br>");
	      pointerone++;
	      pointertwo++;
	      pointerthree++;
	    }
	  }
	  addStrength(r3);
	  r3=sort_RankTable(r3,PLAYERSTRENGTH,GAMESPLAYED);

	  return r3;

	}

<!-- delete villian -->
function delete_villain(stats) 
{
  //var tempholder = new Array();
  for (i=1; i<stats.length; i++) 
  {
    if (stats[i][PLAYERNAME]=="VILLAIN") 
    {
      if (i==stats.length) 
      {
	stats[i]=0;
      } 
      else 
      {
	stats[i]=stats[stats.length-1];
        stats[stats.length-1]="";
      }
      
    }
  }

  return stats;
}






