var spelers = new Array();
var sortering = new Array();
var headertekst = ";;Naam;Team;Rating;Pnt;Prt;;Rc;Tpr;w-z;brd;";
var opNaamString = "";
var opTeamString = "";
var opTopscoreString = "";
var opRatingString = "";
var opTprString = "";
function SetTprOverzicht(tprselect)
{
    // bestaat the box
    if(this.GetElementByID('tproverzicht') == null) return;
    // collect the hidden fields
    var counter = 1;
    while(true)
    {
        if(this.GetElementByID('speler'+counter))
        {
          this.spelers[counter-1] = this.GetElementByID('speler'+counter).value;
          this.sortering[counter-1] = counter-1;
          counter++;
        }
        else
        {
           break;
        }
    }
    this.spelers.sort();
    this.maakOverzicht(1);
}
function changetprbox(select)
{
    var sb = this.GetElementByID(select);
    this.maakOverzicht(sb.options[sb.selectedIndex].id);
}
function maakOverzicht(item)
{
    var tr = this.GetElementByID('tproverzicht');
    switch(item)
    { 
        case "3":
          if(this.opTopscoreString == "")
          {
              this.sorteerOp(12,7,"true");
              this.opTopscoreString = this.createTable();
          }
          tr.innerHTML = this.opTopscoreString;
          break;
        case "4":
          if(this.opRatingString == "")
          {
              this.sorteerOp(4,9,"true");
              this.opRatingString = this.createTable();
          }
          tr.innerHTML = this.opRatingString;
          break;
        case "5":
          if(this.opTprString == "")
          {
              this.sorteerOp(9,8,"true");
              this.opTprString = this.createTable();
          }
          tr.innerHTML = this.opTprString;
          break;    
        case "2":
          if(this.opTeamString == "")
          {
              this.sorteerOp(3,2,"");
              this.opTeamString = this.createTable();
          }
          tr.innerHTML = this.opTeamString;
          break;
        case "1":
        default:
          if(this.opNaamString == "")
          {
              this.opNaamString = this.createTable();
          }
          tr.innerHTML = this.opNaamString;
        break;  
    }
}
function sorteerOp(item1,item2,nummersort)
{
    var sorteerarray = new Array();
    for(var i=0;i<this.spelers.length;i++)
    {
        items = this.spelers[i].split(';');
        sorteerarray[i] = items[item1] + ";" + items[item2] + ";" + i;
    }
    if(nummersort == "")  sorteerarray.sort();
    else  sorteerarray.sort(this.sortNumber);
    for(var i=0;i<sorteerarray.length;i++)
    {
        items = sorteerarray[i].split(';');
        this.sortering[i] = items[2];
    }
}
function sortNumber(a, b)
{
    itemsa = a.split(';');
    itemsb = b.split(';');
    een = itemsa[0];
    twee = itemsb[0]; 
    if(een == twee)
    {
        return Math.floor(itemsb[1]) - Math.floor(itemsa[1]);
    }   
    return Math.floor(twee) - Math.floor(een);
}
function createTable()
{
    trclass = "onevenregelzh";
    retValue = "<TABLE border=0 cellspacing=0 cellpading=0>" + this.maakTableRow(this.headertekst,"rondeheader");
    for(var i=0;i<this.spelers.length;i++)
    {
        retValue += maakTableRow(this.spelers[this.sortering[i]],trclass);
        if(trclass == "onevenregelzh") trclass = "evenregelzh";
        else trclass = "onevenregelzh";
    }
    return retValue + "<table>";
}
function maakTableRow(row,trclass)
{
    items = row.split(';');
    retValue = "<tr class=" + trclass + "><td>" + items[1] + "&nbsp;" + items[2] + "</td>";
    retValue += "<td>&nbsp;" + items[3] + "</td>";
    retValue += "<td width=40px align=center>" + items[4] + "</td>";
    retValue += "<td width=30px align=center>" + items[5] + "</td>";
    retValue += "<td width=30px align=center>" + items[6] + "</td>";
    retValue += "<td width=40px align=center>" + items[7] + "%</td>";
    retValue += "<td width=40px align=center>" + items[8] + "</td>";
    retValue += "<td width=40px align=center>" + items[9] + "</td>";
    retValue += "<td width=30px align=center>" + items[11] + "</td>";
    retValue += "<td width=30px align=center>" + items[10] + "</td>";
    return retValue + "</tr>";
}

