var nLen, np
function initArrays()
{
nLen = oTable.rows.length
np=Array(nLen)
}

function sorter(colNo,orderKey)
{
if (nLen>500) {
//if using asp you could reload the page here and let the server sort your large table, as this script struggles at about // // 500 records (this is on my PC which is quite old)
} else { //client side sorting is preferred unless the table is too big.
tStart = new Date()
sStatus = window.status
window.status="Sorting... Please wait"
b1.style.cursor="wait";
setTimeout("doSort("+colNo+")",1)
}
}

function doSort(colNo)
// Client side sorting routine
{
var iRow, sCount=0
var p1, xp
var sorted=false

//First, load the np array with data from the table.  For this sort I have a variable
// sort column, then a second and third sort column. 
//Obviously the sort would be faster if you don't need this facility

//You may also be able to dispense with the type checker.

for (p1=1;p1<nLen;p1++) //I've set p1 to 1 because I have one header column.

np[p1]=Array(p1,oTable.rows[p1].cells[colNo].innerText)

//Now pass through the array, determining the new position of each record in the table 
while (!sorted) {
sorted = true
iRow=1
p1=1
while (iRow<nLen-sCount)
{
if (np[p1][1]>np[iRow][1]) {  //Compare variable row.
xp=np[iRow]
np[iRow]=np[p1]
np[p1]=xp
sorted=false
} else if (np[p1][1]==np[iRow][1]) {
//If variable row values are the same, check the second and third sort columns.

}
p1=iRow++
}
sCount++  //Each pass through the sort leaves the largest value at the bottom.
}

//Now move the table rows.
for (p1=1;p1<nLen;p1++)
if (p1!=np[p1][0]) {
oTable.moveRow(np[p1][0],p1)
for (p2=p1+1;p2<nLen;p2++)
if (np[p2][0]<np[p1][0]) np[p2][0]++
}

b1.style.cursor="";
window.status=sStatus
}

function getType(valToCheck)
{
if (isNaN(valToCheck)) return valToCheck
else return Number(valToCheck)
}