function getKey (row) {
  switch (sortType) {
  case 'key'   : return row.cells[sortCol].getAttribute('key');
  case 'alpha' : return row.cells[sortCol].firstChild.nodeValue;
  case 'num'   : return parseFloat(row.cells[sortCol].firstChild.nodeValue);
  }
}

function compareRows(row1,row2) {
  var cell1 = getKey(row1);
  var cell2 = getKey(row2);
  return cell1 < cell2 ? - 1 : (cell1 == cell2 ? 0 : 1);
}

function sortTable (id, col, type) 
{
  table = document.getElementById(id);
  sortCol = col; sortType = type;
  var rows = new Array();

  for (var r = 1; r < table.rows.length; r++)
    rows[r] = table.rows[r];
  
  rows.sort(compareRows);

  for (var r = 1; r < rows.length; r++) {
    table.deleteRow(rows[r].rowIndex);
    table.tBodies[0].appendChild(rows[r]);
  }
}


