//
var sortType;
var sortColn;
var sortOrder;
var sortStatus = new Array(
                     new Array(1, 1, 1, 1, 1, 1)
                 );
//
function doSortTable(id, index, coln, type) {
    sortType = type;
    sortColn = coln;
    sortOrder = sortStatus[index][coln];

    var tbl = document.getElementById(id);
    var rows = new Array();
    for (var i = 0; i < tbl.rows.length; i++) {
        rows.push(new Array());
        for (var j = 0; j < tbl.rows[i].cells.length; j++) {
            rows[i].push(tbl.rows[i].cells[j].innerHTML);
        }
    }
    rows.sort(sorter);
    for (var i = 0; i < rows.length; i++) {
        for (var j = 0; j < rows[i].length; j++) {
            tbl.rows[i].cells[j].innerHTML = rows[i][j];
        }
    }
    sortStatus[index][coln] = 0 - sortOrder;
}
//
function sorter(a, b) {
    var A;
    var B;
    if (sortType == "N") {
        A = parseInt(a[sortColn]);
        B = parseInt(b[sortColn]);
        if (isNaN(A)) {
            A = 0;
        }
        if (isNaN(B)) {
            B = 0;
        }
    } else {
        A = a[sortColn];
        B = b[sortColn];
    }
    if (A == B) {
        return 0;
    } else if (A > B) {
        return (0 - sortOrder);
    } else {
        return sortOrder;
    }
}
