//
// Game data display functions - MODIFY the TWO FUNCTIONS below for each season - MLF
//

var ns=(document.layers || navigator.appName=="Netscape");
var ie=(document.all);
var w3=(document.getElementById && self.innerWidth && (window.pageXOffset>-1));
//my way of making sure the browser will have what I need

function populateseasonchange() {
  addItem('Fall 2006',   '2006 - Fall Season');
  addItem('Spring 2006', '2006 - Spring Season');
  addItem('Fall 2005',   '2005 - Fall Season');
  addItem('All seasons', '2005 thru Current season');
  addItem('default', 'Show Current Season --------------------');
}

function setseason (sseason) {
  // Use this function to set the season, the season variables and the scores array to the desired one.
  // "seasonname, seasonyear, seasonage, seasonageup, seasonmaxage" are the season variables
  // "seasonmaxage" variable is necessary to be able to include THREE age levels if user wants to see "Entire Year" stats and fall ball
  //                has already started (i.e. It is possible to have played 7U, 8U and 9U teams all in the same year)
  // Determine and default to *current season* if none is specified
  switch (sseason) {
    case "All seasons" :
      // Set scorearray to all seasons
      scorearray.length = 0;
      scorearray = spring2006scorearray.concat(fall2005scorearray); 
      seasonname = sseason;
      seasonyear = sseason.substr(sseason.length-4,4);
      seasonage = "12U";
      seasonageup = "13U";
      seasonagemax = "";
      break;
    case "Fall 2006" :
      // Set scorearray to fall2006scorearray
      scorearray.length = 0;
      scorearray = fall2006scorearray.slice(0);
      seasonname = sseason;
      seasonyear = "2006";
      seasonage = "12U";
      seasonageup = "13U";
      seasonagemax = "";
      break;
    case "Spring 2006" :
      // Set scorearray to spring2006scorearray
      scorearray.length = 0;
      scorearray = spring2006scorearray.slice(0);
      seasonname = sseason;
      seasonyear = "2006";
      seasonage = "11U";
      seasonageup = "12U";
      seasonagemax = "";
      break;
    case "Fall 2005" :
      // Set scorearray to fall2005scorearray
      scorearray.length = 0;
      scorearray = fall2005scorearray.slice(0);
      seasonname = sseason;
      seasonyear = "2005";
      seasonage = "11U";
      seasonageup = "12U";
      seasonagemax = "";
      break;
    case "Spring 2004" :
      // Set scorearray to spring2004scorearray
      scorearray.length = 0;
      scorearray = spring2004scorearray.slice(0);
      seasonname = sseason;
      seasonyear = "2004";
      seasonage = "10U";
      seasonageup = "11U";
      seasonagemax = "";
      break;
    case "All of 2004" :
      // Set scorearray to spring2004scorearray + fall2004scorearray
      scorearray.length = 0;
      scorearray = fall2004scorearray.concat(spring2004scorearray); 
      seasonname = sseason;
      seasonyear = sseason.substr(sseason.length-4,4);
      seasonage = "10U";
      seasonageup = "11U";
      seasonagemax = "12U";
      break;
    default :
      // Default to current season (determine first by guess)
      today = new Date();
      seasonnametemp = "" + ((today.getMonth() < 7) ? "Spring" : "Fall");  // If July (month #6) or earlier - still spring
      seasonname = seasonnametemp + " " + today.getYear();
      seasonyear = today.getYear();
      if (seasonyear < 1000) { seasonyear+=1900; }
      seasonage = "" + ((seasonyear-1995) + ((today.getMonth() < 7)?0:1)) + "U";
      seasonageup = "" + ((seasonyear-1995) + ((today.getMonth() < 7)?1:2)) + "U";
      seasonagemax = "";
      currentseasonarraycommand = seasonnametemp.toLowerCase() + seasonyear + "scorearray.slice(0)";
      scorearray.length = 0;
      scorearray = eval(currentseasonarraycommand);
    }
}

//
// Game data display functions - DO NOT MODIFY - MLF
//

function addItem(_a,_b) {
  _c = document.seasonchange.seasonpage.length; 
  if (ie) {
    var _t = document.createElement("OPTION");
      _t.value = _a;
      _t.text  = _b;
    document.seasonchange.seasonpage.options.add(_t,_c);
  }
  if (ns) {
    for (var _j = document.seasonchange.seasonpage.options.length; _j > _c; _j--) {
      document.seasonchange.seasonpage.options[_j] = document.seasonchange.seasonpage.options[_j-1]; }
    document.seasonchange.seasonpage.options[_c] = new Option(_b,_a,false,false);
  }
  document.seasonchange.seasonpage.selectedIndex=0;
}

function sort_and_print_game_record (howtoprint) {

  if (howtoprint == "individual results by date") {

    // Combine scorearray data into single elements and assign to temporary array for sorting
    var temparray = new Array();
    for (var i=0; i<(scorearray.length); i=i+9) {
      gamedateyear = scorearray[i+6]; if (gamedateyear<10) {gamedateyear="0"+gamedateyear;}
      gamedatemonth = scorearray[i+7]; if (gamedatemonth<10) {gamedatemonth="0"+gamedatemonth;}
      gamedatedate = scorearray[i+8]; if (gamedatedate<10) {gamedatedate="0"+gamedatedate;}
      temparray[i/9] = gamedateyear + "|" + gamedatemonth + "|" + gamedatedate + "|" + 
                       scorearray[i] + "|" + scorearray[i+1] + "|" + scorearray[i+2] + "|" + scorearray[i+3] + "|" + scorearray[i+4] + "|" + scorearray[i+5] ;
    }
    temparray.sort();
    temparray.reverse();
    // temparray is now properly sorted; take score data apart and display.
    var sortedscores = new Array();
    pipe="|";
    for (var i=0; i<(temparray.length); i++) {
      currentgamearray = temparray[i].split(pipe);
      sortedscores[i*9+0] = currentgamearray[3];
      sortedscores[i*9+1] = currentgamearray[4];
      sortedscores[i*9+2] = currentgamearray[5];
      sortedscores[i*9+3] = currentgamearray[6];
      sortedscores[i*9+4] = currentgamearray[7];
      sortedscores[i*9+5] = currentgamearray[8];
      sortedscores[i*9+6] = currentgamearray[0];
      sortedscores[i*9+7] = currentgamearray[1];
      sortedscores[i*9+8] = currentgamearray[2];
    }
  }

  if (howtoprint == "individual results alpha") {

    // Combine scorearray data into single elements and assign to temporary array for sorting
    var temparray = new Array();
    for (var i=0; i<(scorearray.length); i=i+9) {
      gamedateyear = scorearray[i+6]; if (gamedateyear<10) {gamedateyear="0"+gamedateyear;}
      gamedatemonth = scorearray[i+7]; if (gamedatemonth<10) {gamedatemonth="0"+gamedatemonth;}
      gamedatedate = scorearray[i+8]; if (gamedatedate<10) {gamedatedate="0"+gamedatedate;}
      temparray[i/9] = scorearray[i] + "|" + scorearray[i+1] + "|" + gamedateyear + "|" + gamedatemonth + "|" + gamedatedate + "|" + scorearray[i+2] + "|" + scorearray[i+3] + "|" + scorearray[i+4] + "|" + scorearray[i+5] ;
    }
    temparray.sort();
    // temparray is now properly sorted; take score data apart and display.
    var sortedscores = new Array();
    pipe="|";
    for (var i=0; i<(temparray.length); i++) {
      currentgamearray = temparray[i].split(pipe);
      sortedscores[i*9+0] = currentgamearray[0];
      sortedscores[i*9+1] = currentgamearray[1];
      sortedscores[i*9+2] = currentgamearray[5];
      sortedscores[i*9+3] = currentgamearray[6];
      sortedscores[i*9+4] = currentgamearray[7];
      sortedscores[i*9+5] = currentgamearray[8];
      sortedscores[i*9+6] = currentgamearray[2];
      sortedscores[i*9+7] = currentgamearray[3];
      sortedscores[i*9+8] = currentgamearray[4];
    }
  }

    // Every game is now sorted and ready to display
    var rs=0, ra=0, total_rs=0, total_ra=0, total_games=0;
    var currentteamname="", nextteamname="", fo="", fc="", tdoc="", tdol="", tdc="", bo="", bc="", gametype="", gamedate="";
    var wlt="";
    tdoc = "<TD ALIGN=CENTER VALIGN=MIDDLE>";
    tdol = "<TD ALIGN=LEFT VALIGN=MIDDLE><FONT COLOR=#AAAAAA FACE=Arial SIZE=2>&nbsp; &nbsp; &nbsp;<B>vs.</B></FONT> ";
    tdc = "</TD>";
    fo = "<FONT FACE='Arial' SIZE=2 COLOR=WHITE>";
    fc = "</FONT>";
    bo = "<B>";
    bc = "</B>";
    for (var i=0; i<(sortedscores.length); i=i+9) {
      currentteamname = sortedscores[i];
      nextteamname = sortedscores[i+9];
      currentteamnameformatted = "<B>" + sortedscores[i] + "</B> &nbsp;" + sortedscores[i+1];
      rs = sortedscores[i+3];
      ra = 	sortedscores[i+4];
      total_rs = total_rs + parseFloat(rs);
      total_ra = total_ra + parseFloat(ra);
      total_games++;
      // Print each game result
      gametype = sortedscores[i+5].substr(0,1); // first letter of game type
      gamedate = sortedscores[i+7] + "/" + sortedscores[i+8] + "/" + sortedscores[i+6];
      wlt = sortedscores[i+2];
      if (wlt=="F") {wlt="&nbsp;W*";} // Display (F)orfeits as (W)ins  on screen
      document.write("<TR>" +
               tdol + fo + currentteamnameformatted + fc + tdc +
               tdoc + fo + bo + wlt + bc + fc + tdc +
               tdoc + fo + bo + rs + bc + fc + tdc +
               tdoc + fo + bo + ra + bc + fc + tdc +
               tdoc + fo + bo + gametype.toUpperCase() + bc + fc + tdc +
               tdoc + fo + bo + gamedate + bc + fc + tdc + "</TR>");
      rs=0; ra = 0;
    }
    document.write("<TR>" +
             "<TD COLSPAN=6 ALIGN=CENTER VALIGN=MIDDLE>" +
             "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=85%><TR><TD ALIGN=LEFT>" +
             fo + "Average game score for these " + total_games + " games:" + fc + "</TD><TD ALIGN=RIGHT>" +
             "<FONT FACE='Arial,Verdana' SIZE=2 COLOR=#44CC44><B>&nbsp; OKC Venom </B></FONT>" + "</TD><TD>" +
             fo + "&nbsp;- " + bo + (Math.floor((total_rs * 10) / total_games) / 10) + bc + fc + "</TD><TD>" +
             fo + "&nbsp; Opponents - " + bo + (Math.floor((total_ra * 10) / total_games) / 10) + bc + fc + "</TD></TR></TABLE>" + tdc + "</TR>");
}

function print_game_record (howtoprint, whichrecord, maxage) {
  var countwin=0, countloss=0, counttie=0, rs=0, ra=0, total_rs=0, total_ra=0, total_games=0;
  var currentteamname="", nextteamname="", fo="", fc="", tdoc="", tdol="", tdc="", bo="", bc="", gametype="", gamedate="";
  var gamedatemonth="", gamedatedate="", gamedateyear="", wlt="";
  tdoc = "<TD ALIGN=CENTER VALIGN=MIDDLE>";
  tdol = "<TD ALIGN=LEFT VALIGN=MIDDLE><FONT COLOR=#AAAAAA FACE=Arial SIZE=2>&nbsp; &nbsp; &nbsp;<B>vs.</B></FONT> ";
  tdc = "</TD>";
  fo = "<FONT FACE='Arial' SIZE=2 COLOR=WHITE>";
  fc = "</FONT>";
  bo = "<B>";
  bc = "</B>";

    // COMBINE scorearray DATA INTO SINGLE ELEMENTS AND ASSIGN TO TEMPORARY ARRAY FOR SORTING

    var temparray = new Array();
    for (var i=0; i<(scorearray.length); i=i+9) {
      gamedateyear = scorearray[i+6]; if (gamedateyear<10) {gamedateyear="0"+gamedateyear;}
      gamedatemonth = scorearray[i+7]; if (gamedatemonth<10) {gamedatemonth="0"+gamedatemonth;}
      gamedatedate = scorearray[i+8]; if (gamedatedate<10) {gamedatedate="0"+gamedatedate;}
      temparray[i/9] = scorearray[i] + "|" + scorearray[i+1] + "|" + gamedateyear + "|" + gamedatemonth + "|" + gamedatedate + "|" + scorearray[i+2] + "|" + scorearray[i+3] + "|" + scorearray[i+4] + "|" + scorearray[i+5] ;
    }
    temparray.sort();

    // temparray IS NOW PROPERLY SORTED; TAKE SCORE DATA APART AND DISPLAY.

    var sortedscores = new Array();
    pipe="|";
    for (var i=0; i<(temparray.length); i++) {
      currentgamearray = temparray[i].split(pipe);
      sortedscores[i*9+0] = currentgamearray[0];
      sortedscores[i*9+1] = currentgamearray[1];
      sortedscores[i*9+2] = currentgamearray[5];

      sortedscores[i*9+3] = parseInt(currentgamearray[6]);
      sortedscores[i*9+4] = parseInt(currentgamearray[7]);

      sortedscores[i*9+5] = currentgamearray[8];
      sortedscores[i*9+6] = currentgamearray[2];
      sortedscores[i*9+7] = currentgamearray[3];
      sortedscores[i*9+8] = currentgamearray[4];
    }
    scorearray.length = 0;
    scorearray = sortedscores.slice(0);

  mainloop :
  for (var i=0; i<(scorearray.length); i=i+9) {
    currentteamname = scorearray[i];
    nextteamname = scorearray[i+9];
    if ((scorearray[i+1] != whichrecord && scorearray[i+1] != maxage) && whichrecord != "all") { continue mainloop; }
    showage = '&nbsp; '+scorearray[i+1];
    if (scorearray[i+2] == "W" || scorearray[i+2] == "F") {countwin = countwin + 1;}
    if (scorearray[i+2] == "L") {countloss = countloss + 1;}
    if (scorearray[i+2] == "T") {counttie = counttie + 1;}
    rs = rs + scorearray[i+3];
    ra = ra + scorearray[i+4];
    total_rs = total_rs + parseFloat(scorearray[i+3]);
    total_ra = total_ra + parseFloat(scorearray[i+4]);
    total_games++;
    dimzerowinopen = (countwin==0)?'':bo  //the "dimzero" variables make sure 0's aren't BOLDed.
    dimzerowinclose = (countwin==0)?'':bc 
    dimzerolossopen = (countloss==0)?'':bo 
    dimzerolossclose = (countloss==0)?'':bc 
    dimzerotieopen = (counttie==0)?'':bo 
    dimzerotieclose = (counttie==0)?'':bc 
    if ((currentteamname + scorearray[i+1] != nextteamname + scorearray[i+10]) && howtoprint == "cumulative") {
      // NEW TEAM COMING UP, PRINT OLD TOTALS AND RESET COUNT TOTALS
      document.write("<TR>" +
               tdol + fo + bo + currentteamname + bc + showage + fc + tdc +
               tdoc + fo + dimzerowinopen + countwin + dimzerowinclose + fc + tdc +
               tdoc + fo + dimzerolossopen + countloss + dimzerolossclose + fc + tdc +
               tdoc + fo + dimzerotieopen + counttie + dimzerotieclose + fc + tdc +
               tdoc + fo + bo + rs + bc + fc + tdc +
               tdoc + fo + bo + ra + bc + fc + tdc + "</TR>");
      countwin=0; countloss=0; counttie=0; rs=0; ra = 0;
    }
    if (howtoprint == "individual results alpha") {
      // PRINT EACH GAME RESULT
      gametype = scorearray[i+5].substr(0,1); // first letter of game type
      gamedatemonth = scorearray[i+7]; if (gamedatemonth<10) {gamedatemonth="0"+gamedatemonth;}
      gamedatedate = scorearray[i+8]; if (gamedatedate<10) {gamedatedate="0"+gamedatedate;}
      gamedateyear = scorearray[i+6]; if (gamedateyear<10) {gamedateyear="0"+gamedateyear;}
      gamedate = gamedatemonth + "/" + gamedatedate + "/" + gamedateyear;
      wlt = scorearray[i+2];
      if (wlt=="F") {wlt="W";} // Display (F)orfeits as (W)ins  on screen
      document.write("<TR>" +
               tdol + fo + bo + currentteamname + bc + showage + fc + tdc +
               tdoc + fo + bo + wlt + bc + fc + tdc +
               tdoc + fo + bo + rs + bc + fc + tdc +
               tdoc + fo + bo + ra + bc + fc + tdc +
               tdoc + fo + bo + gametype.toUpperCase() + bc + fc + tdc +
               tdoc + fo + bo + gamedate + bc + fc + tdc + "</TR>");
      countwin=0; countloss=0; counttie=0; rs=0; ra = 0;
    }
  }
  document.write("<TR>" +
           "<TD COLSPAN=6 ALIGN=CENTER VALIGN=MIDDLE>" +
           "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD ALIGN=LEFT>" +
           fo + "Average game score for these " + total_games + " games:" + fc + "</TD><TD ALIGN=RIGHT>" +
           "<FONT FACE='Arial,Verdana' SIZE=2 COLOR=#44CC44><B>&nbsp; OKC Venom </B></FONT>" + "</TD><TD>" +
           fo + "&nbsp;- " + bo + (Math.floor((total_rs * 10) / total_games) / 10) + bc + fc + "</TD><TD>" +
           fo + "&nbsp; Opponents - " + bo + (Math.floor((total_ra * 10) / total_games) / 10) + bc + fc + "</TD></TR></TABLE>" + tdc + "</TR>");
}

function print_game_record_header (howtoprint, whichrecord, maxage) {
  seasonyeartext=seasonyear;
  if (seasonyear == "sons") { seasonyeartext="All"; }
  if (howtoprint == "cumulative") {
    document.write("<TR BGCOLOR=#006600>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=290><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>" + seasonyeartext + " Cumulative Record<BR>vs. Each " + whichrecord + ((seasonagemax=="" || (seasonname.substr(0,3)=="All" && maxage=="showspringonly"))?"":" &amp; "+seasonagemax) + " Team Played</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=53><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Wins</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=54><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Losses</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=53><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Ties</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=60><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Runs<BR>Scored</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=60><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Runs<BR>Allowed</B></FONT></TD>");
    document.write("</TR>");
  }
  if (howtoprint == "individual results alpha") {
    document.write("<TR BGCOLOR=#006600>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=290><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>" + seasonyeartext + " Individual Game Results<BR>vs. Each Team Played</B> - (alpha list)</FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=40><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>WLT</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=50><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Runs<BR>Scored</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=50><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Runs<BR>Allowed</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=60><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>(T)ourn<BR>(L)eague</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=80><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Date</B></FONT></TD>");
    document.write("</TR>");
  }
  if (howtoprint == "individual results by date") {
    document.write("<TR BGCOLOR=#006600>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=290><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>" + seasonyeartext + " Individual Game Results<BR>vs. Each Team Played</B> - (by date)</FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=40><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>WLT</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=50><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Runs<BR>Scored</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=50><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Runs<BR>Allowed</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=80><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>(T)ourn<BR>(L)eague</B></FONT></TD>");
    document.write("  <TD BGCOLOR=#006600 ALIGN=CENTER VALIGN=MIDDLE WIDTH=80><FONT FACE=Arial SIZE=2 COLOR=WHITE><B>Date</B></FONT></TD>");
    document.write("</TR>");
  }
}

function print_over_all_wlt_record (whichrecord, maxage) {
  var countwin=0, countloss=0, counttie=0, countgames=0, rs=0, ra=0, pct=0;
  for (var i=0; i<(scorearray.length); i=i+9) {
    if (whichrecord == "all") {
      if (scorearray[i+2] == "W" || scorearray[i+2] == "F") {countwin = countwin + 1;}
      if (scorearray[i+2] == "L") {countloss = countloss + 1;}
      if (scorearray[i+2] == "T") {counttie = counttie + 1;}
      rs = rs + scorearray[i+3];
      ra = ra + scorearray[i+4];
    } 
    if ((scorearray[i+1] == whichrecord) || (scorearray[i+1] == maxage)) {
      if (scorearray[i+2] == "W" || scorearray[i+2] == "F") {countwin = countwin + 1;}
      if (scorearray[i+2] == "L") {countloss = countloss + 1;}
      if (scorearray[i+2] == "T") {counttie = counttie + 1;}
      rs = rs + scorearray[i+3];
      ra = ra + scorearray[i+4];
    }
  }
  countgames = countwin + countloss + counttie;
  pct = (Math.floor(countwin / countgames * 1000) / 1000);
  pct = pct.toString();
  if (pct.substring(0,1) == "1") { pct += "."; }
  if (pct.substring(0,1) == "0") { pct = pct.substring(1); }
  while (pct.length != 4) { pct += "0"; }  
  document.write("<TR>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + countwin + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + countloss + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + counttie + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + pct + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + rs + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + ra + "</B></FONT></TD>" + "</TR>");
}

function complete_wlt_record_since_inception () {
  var countwin=0, countloss=0, counttie=0, countgames=0, rs=0, ra=0, pct=0;
  var countwinup=0, countlossup=0, counttieup=0, countgamesup=0, rsup=0, raup=0, pctup=0;
  var countwindown=0, countlossdown=0, counttiedown=0, countgamesdown=0, rsdown=0, radown=0, pctdown=0;
  var countwinsame=0, countlosssame=0, counttiesame=0, countgamessame=0, rssame=0, rasame=0, pctsame=0;
  for (var i=0; i<(historicalscorearray2.length); i=i+9) {
    if (historicalscorearray2[i+2] == "W" || historicalscorearray2[i+2] == "F") {countwin = countwin + 1;}
    if (historicalscorearray2[i+2] == "L") {countloss = countloss + 1;}
    if (historicalscorearray2[i+2] == "T") {counttie = counttie + 1;}
    rs = rs + historicalscorearray2[i+3];
    ra = ra + historicalscorearray2[i+4];
  }
  for (var j=0; j<(seasonarray.length); j=j+2) {
    CSarray = eval(seasonarray[j]+".slice(0);");
    CSage = seasonarray[j+1] + "U";  
    CSageplus1 = (seasonarray[j+1]+1) + "U";  
    CSageplus2 = (seasonarray[j+1]+2) + "U";  
    CSageminus1 = (seasonarray[j+1]-1) + "U";
    for (var i=0; i<(CSarray.length); i=i+9) {
      if (CSarray[i+1] == CSageplus1 || CSarray[i+1] == CSageplus2) {
        if (CSarray[i+2] == "W" || CSarray[i+2] == "F") {countwinup = countwinup + 1;}
        if (CSarray[i+2] == "L") {countlossup = countlossup + 1;}
        if (CSarray[i+2] == "T") {counttieup = counttieup + 1;}
        rsup = rsup + CSarray[i+3];
        raup = raup + CSarray[i+4];
      }
      if (CSarray[i+1] == CSage) {
        if (CSarray[i+2] == "W" || CSarray[i+2] == "F") {countwinsame = countwinsame + 1;}
        if (CSarray[i+2] == "L") {countlosssame = countlosssame + 1;}
        if (CSarray[i+2] == "T") {counttiesame = counttiesame + 1;}
        rssame = rssame + CSarray[i+3];
        rasame = rasame + CSarray[i+4];
      }
      if (CSarray[i+1] == CSageminus1) {
        if (CSarray[i+2] == "W" || CSarray[i+2] == "F") {countwindown = countwindown + 1;}
        if (CSarray[i+2] == "L") {countlossdown = countlossdown + 1;}
        if (CSarray[i+2] == "T") {counttiedown = counttiedown + 1;}
        rsdown = rsdown + CSarray[i+3];
        radown = radown + CSarray[i+4];
      }
    }
	CSarray=new Array();
  }
  countgames = countwin + countloss + counttie;
  countgamesup = countwinup + countlossup + counttieup;
  countgamessame = countwinsame + countlosssame + counttiesame;
  countgamesdown = countwindown + countlossdown + counttiedown;
  pct = (Math.floor(countwin / countgames * 1000) / 1000);
  pctup = (Math.floor(countwinup / countgamesup * 1000) / 1000);
  pctsame = (Math.floor(countwinsame / countgamessame * 1000) / 1000);
  pctdown = (Math.floor(countwindown / countgamesdown * 1000) / 1000);
  if (countgames==0) { pct=0; }
  if (countgamesup==0) { pctup=0; }
  if (countgamessame==0) { pctsame=0; }
  if (countgamesdown==0) { pctdown=0; }
  pct = pct.toString();
  pctup = pctup.toString();
  pctsame = pctsame.toString();
  pctdown = pctdown.toString();
  if (pct.substring(0,1) == "1") { pct += "."; }
  if (pct.substring(0,1) == "0") { pct = pct.substring(1); }
  while (pct.length != 4) { pct += "0"; }  
  if (pctup.substring(0,1) == "1") { pctup += "."; }
  if (pctup.substring(0,1) == "0") { pctup = pctup.substring(1); }
  while (pctup.length != 4) { pctup += "0"; }  
  if (pctsame.substring(0,1) == "1") { pctsame += "."; }
  if (pctsame.substring(0,1) == "0") { pctsame = pctsame.substring(1); }
  while (pctsame.length != 4) { pctsame += "0"; }  
  if (pctdown.substring(0,1) == "1") { pctdown += "."; }
  if (pctdown.substring(0,1) == "0") { pctdown = pctdown.substring(1); }
  while (pctdown.length != 4) { pctdown += "0"; }  
  document.write("<BR><IMG SRC='images/record/teamrecordsinceforming.gif' WIDTH=292 HEIGHT=23 BORDER=0 ALT=''><BR>");
  document.write("<IMG SRC='images/filler.gif' WIDTH=1 HEIGHT=10 BORDER=0 ALT=''><BR>");
  document.write("<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=1 bordercolorlight=#000000 bordercolordark=#FFFFFF bordercolor=#000000 bgcolor=#000000 WIDTH=290>");
  document.write("<TR BGCOLOR=#000000>");
  document.write("  <TD ALIGN=CENTER VALIGN=TOP WIDTH=86><FONT FACE=Arial SIZE=2 COLOR=#33BB33><B>vs.</B></FONT></TD>");
  document.write("  <TD ALIGN=CENTER VALIGN=TOP WIDTH=34><FONT FACE=Arial SIZE=2 COLOR=#33BB33><B>Win</B></FONT></TD>");
  document.write("  <TD ALIGN=CENTER VALIGN=TOP WIDTH=34><FONT FACE=Arial SIZE=2 COLOR=#33BB33><B>Loss</B></FONT></TD>");
  document.write("  <TD ALIGN=CENTER VALIGN=TOP WIDTH=34><FONT FACE=Arial SIZE=2 COLOR=#33BB33><B>Tie</B></FONT></TD>");
  document.write("  <TD ALIGN=CENTER VALIGN=TOP WIDTH=34><FONT FACE=Arial SIZE=2 COLOR=#33BB33><B>PCT</B></FONT></TD>");
  document.write("  <TD ALIGN=CENTER VALIGN=TOP WIDTH=34><FONT FACE=Arial SIZE=2 COLOR=#33BB33><B>RS</B></FONT></TD>");
  document.write("  <TD ALIGN=CENTER VALIGN=TOP WIDTH=34><FONT FACE=Arial SIZE=2 COLOR=#33BB33><B>RA</B></FONT></TD>");
  document.write("</TR>");
  document.write("<TR>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>All teams</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + countwin + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + countloss + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + counttie + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + pct + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + rs + "</B></FONT></TD>" +
           "<TD ALIGN=CENTER VALIGN=TOP><FONT FACE='Arial' SIZE=2 COLOR=WHITE><B>" + ra + "</B></FONT></TD>" + "</TR>");
  document.write("</TABLE>");
}

function total_win_count2 () {
  var countwin=0;
  for (var i=0; i<(historicalscorearray2.length); i=i+9) {
    if (historicalscorearray2[i+2] == "W" || historicalscorearray2[i+2] == "F") {countwin = countwin + 1;}
  }
  return countwin;
}

function total_run_count2 () {
  var rs=0;
  for (var i=0; i<(historicalscorearray2.length); i=i+9) {
    rs = rs + historicalscorearray2[i+3];
  }
  return rs;
}
