function SortableTable(id,rows,cols,border,width,align) {
 this.id = id
 this.rows = rows
 this.cols = cols
 this.border = border
 this.width = width
 this.align = align
 this.buttons = new Array(cols)
 this.numeric = new Array(cols)
 for(var i=0;i<cols;++i) 
  this.buttons[i]=" "
 for(var i=0;i<cols;++i) 
  this.numeric[i]=false
 this.data = new Array(rows)
 for(var i=0;i<rows;++i) {
  this.data[i] = new Array(cols)
  for(var j=0;j<cols;++j)
   this.data[i][j] = " "
 }
 this.display = SortableTable_display
 this.setButtons = SortableTable_setButtons
 this.setData = SortableTable_setData
 this.setNumeric = SortableTable_setNumeric
 this.sort = SortableTable_sort
}
function SortableTable_setData(data) {
 if(data == null) return
 if(data.length > 0) {
  for(var i=0;i<this.rows;++i) {
   if(i>=data.length) break
   if(data[i] != null) {
    var n = data[i].length
    if(n > this.cols) n = this.cols
    for(var j=0;j<n;++j)
     if(data[i][j]!=null) this.data[i][j] = data[i][j]
   }
  }
 }
}
function SortableTable_setButtons(buttons) {
 if(buttons == null) return
 var n = buttons.length
 if(n > this.cols) n = this.cols
 for(var i=0;i<n;++i)
  if(buttons[i]!=null) this.buttons[i] = buttons[i]
}
function SortableTable_display() {
//   CHECK FOR tableSortBy COOKIE
 if(document.cookie.length > 0) {
  var search = this.id + "="
  var offset = document.cookie.indexOf(this.id+"=") 
  if(offset != -1) { 
   offset += search.length 
   var end = document.cookie.indexOf(";", offset) 
   if(end == -1) end = document.cookie.length
   this.sort(document.cookie.substring(offset, end))
  }   
 }
//   ADJUST ANY AND ALL BELOW TO CREATE TABLE "VIEW"
 document.writeln('<FORM NAME="tableForm">')
 document.write('Sort columns with links:<br>')
 document.write('<img src="images/c_8x8.gif" width="8" height="8" border="0"><span class="font8"> = Team Captain</span>')
 document.write('<div align="center">')
 document.write('<center>')
 document.write('<TABLE cellpadding="1" cellspacing="0" BORDER="'+this.border+'" width="')
 document.writeln(this.width+'" align="'+this.align+'">')
 document.writeln('<TR>')
//   ADD height="30" TO <TR> ABOVE FOR IMAGE HEIGHT -- ADJUST ACCORDINGLY
//   DISPLAY LINKED TEXT
 for(var i=0;i<this.cols;++i) {
  document.write('<TD>')
  document.write('<a href="#" ONCLICK="SortableTable_handleColumnButton(\'')
  document.write(this.id+'\','+i+')">')
  document.write(this.buttons[i])
  document.writeln('</TD>')
//   ---  FOR IMAGES, SUBSTITUTE THE FOLLOWING ABOVE
//   document.write('<TD>')
//   document.write('<INPUT TYPE="IMAGE" SRC="')
//   document.write(this.buttons[i])
//   document.write('" ONCLICK="SortableTable_handleColumnButton(\'')
//   document.write(this.id+'\','+i+')">')
//   document.writeln('</TD>')
//   ---  FOR BUTTONS, SUBSTITUTE THE FOLLOWING ABOVE
//   document.write('<TD>')
//   document.write('<INPUT TYPE="BUTTON" VALUE="')
//   document.write(this.buttons[i])
//   document.write('" ONCLICK="SortableTable_handleColumnButton(\'')
//   document.write(this.id+'\','+i+')">')
//   document.writeln('</TD>')
 }
 document.writeln('</TR>')
//   DISPLAY SORTED/UNSORTED TABLE
// <td onmouseover="this.style.backgroundColor='#E1E1E1'" onmouseout="this.style.backgroundColor='#FFFFFF'" border-style: solid; border-color: #000000; background-color:#FFFFFF">
//    document.write('<TD><span class="font8">')
 for(var i=0;i<this.rows;++i) {
  document.writeln('<TR onmouseover="this.style.backgroundColor=\'#E1E1E1\'" onmouseout="this.style.backgroundColor=\'#FFFFFF\'">')
  for(var j=0;j<this.cols;++j) {
   document.write('<TD>')
    document.write('<span class="font8">')
    document.write(this.data[i][j])
    document.writeln('</span></TD>')
  }
  document.writeln('</TR>')
 }
 document.writeln('</TABLE>')
 document.writeln('</center>')
 document.writeln('</div>')
 document.writeln('</FORM>')
}
function SortableTable_setNumeric(n) {
 this.numeric[n] = true
}
function SortableTable_sort(n) {
//   SORT ROWS
 var changes=true
 for(;changes;) {
  changes = false
  for(var i=0;i<this.rows-1;++i) {
   if(this.numeric[n]) {
    var v1 = parseFloat(this.data[i][n])
    if(isNaN(v1)) v1 = 0;
    var v2 = parseFloat(this.data[i+1][n])
    if(isNaN(v2)) v2 = 0;
    if(v1 > v2) {
     changes = true
     var temp = this.data[i]
     this.data[i] = this.data[i+1]
     this.data[i+1] = temp
    }   
   }else{
    if(this.data[i][n] > this.data[i+1][n]) {
     changes = true
     var temp = this.data[i]
     this.data[i] = this.data[i+1]
     this.data[i+1] = temp
    }
   }
  }
 } 
}
function SortableTable_handleColumnButton(id,n) {
//   SET COOKIE AND RELOAD
 document.cookie = id + "="+n
 window.location.reload()
}