var sortableListHeaderOffsetY = 0;




function sortableListLockHeaders(){
    var div = getById("sortableListScrollPane");
    var y = div.scrollTop;
    elements = document.getElementsByTagName("th");
    for(var i = 0; i < elements.length; i++){
        var node = elements.item(i);
        for(var j = 0; j < node.attributes.length; j++) {
            if(node.attributes.item(j).nodeName == "id") {
                if(node.attributes.item(j).nodeValue == "sortableListFixedHeader") {
                    eval("node.style.position=\"relative\";");
                    eval("node.style.top=\"" + y + "px\";");
                }
            }
        }
    }
}








var sortableListScrollable = false;
var sortableListHilitedRow = -1;
var sortableListRowHiliteStyle = null;
var sortableListColumnCount = 0;
var sortableListRowStyles = null;
var sortableListJavascriptCommon = null;

function setSortableListJavascriptCommon(jsc) {
    sortableListJavascriptCommon = jsc;
}

function setSortableListRowHiliteStyle(hiliteStyle) {
    sortableListRowHiliteStyle = hiliteStyle;
}

function setSortableListColumnCount(colcount) {
    sortableListColumnCount = colcount;
}

function setSortableListRowStyles(styleArray) {
    sortableListRowStyles = styleArray;
}

function setSortableListScrollable(isso) {
    sortableListScrollable = isso;
}


function sc(rownum) {

    if (sortableListRowStyles == null) {
        alert('row styles not set with setSortableListRowStyles();');
        return;
    }
    if (sortableListColumnCount < 1) {
        alert('column count not set with setSortableListColumnCount();');
        return;
    }
    if (sortableListRowHiliteStyle == null) {
        alert('hilite style not set with setSortableListRowHiliteStyle();');
        return;
    }

    if (sortableListHilitedRow == rownum) {
        // don't unhilite...
       // return;
    }

    if (sortableListScrollable) {
        sortableListLockHeaders();
    }

    if (sortableListHilitedRow >= 0) {
        // unhilite the old one...
        var styleIndex = sortableListHilitedRow % sortableListRowStyles.length;
        for (var i = 0; i < sortableListColumnCount; i++) {
            var td = getById('c' + sortableListHilitedRow + '_' + i);
            if (td != null) {
                td.className = sortableListRowStyles[styleIndex];
            }
        }
        if (sortableListHilitedRow == rownum) {
            // then they clicked on the hilited row, and we have just
            // unhilited it, so we are finito!!! like un burrito...
            sortableListHilitedRow = -1;
            return;
        }
    }
    // so the old one has been unhilited...
    // now all we got to do is hilite the new one...

    for (var i = 0; i < sortableListColumnCount; i++) {
        var td = getById('c' + rownum + '_' + i);
        if (td != null) {
            td.className = sortableListRowHiliteStyle;
        }
    }
    sortableListHilitedRow = rownum;
    return;
}



var sortableListSearchPopupWindow = null;

function sortableListClearSearchInputs() {
    var toform = getById("slippils");
    if (toform != null) {
        toform.searchmin.value = '';
        toform.searchmax.value = '';
        toform.searchcol.value = '';
    }
}

function sortableListSearchText(searchCol, form, slipname) {
    if (form.searchText.value == null || form.searchText.value.length == 0) {
        alert('please enter in the text to search for...');
        return false;
    }
    if (sortableListSearchPopupWindow != null) {
        sortableListSearchPopupWindow.close();
    }
    var toform = getById(slipname + "_slippils");
    if (toform != null) {
        toform[slipname + '_searchtxt'].value = form.searchText.value;
        toform[slipname + '_searchmin'].value = '';
        toform[slipname + '_searchmax'].value = '';
        toform[slipname + '_searchcol'].value = searchCol;
        toform.submit();
    }
    return true;
}




function sortableListLimitRange(searchCol, form, slipname) {
    if (form.searchMax.value == null || form.searchMax.value.length == 0) {
        alert('please enter in the maximum text to search for...');
        return false;
    }
    if (form.searchMin.value == null || form.searchMin.value.length == 0) {
        alert('please enter in the minimum text to search for...');
        return false;
    }
    if (sortableListSearchPopupWindow != null) {
        sortableListSearchPopupWindow.close();
    }
    var toform = getById(slipname + "_slippils");
    if (toform != null) {
        toform[slipname + '_searchtxt'].value = '';
        toform[slipname + '_searchmin'].value = form.searchMin.value;
        toform[slipname + '_searchmax'].value = form.searchMax.value;
        toform[slipname + '_searchcol'].value = searchCol;
        toform.submit();
    }
    return true;
}



function sortableListNoRange(searchCol, slipname) {
    if (sortableListSearchPopupWindow != null) {
        sortableListSearchPopupWindow.close();
    }
    var toform = getById(slipname + "_slippils");
    if (toform != null) {
        toform[slipname + '_searchtxt'].value = '';
        toform[slipname + '_searchmin'].value = '';
        toform[slipname + '_searchmax'].value = '';
        toform[slipname + '_searchcol'].value = searchCol;
        toform.submit();
    }
    return true;
}



function sortableListSearchPopup(url, searchCol, colName) {
    var w = 280;
    var h = 230;
    if (sortableListSearchPopupWindow != null) {
        sortableListSearchPopupWindow.close();
    }
    wn = 'sortableListSearchPopupWindow';
    if (navigator.appVersion.indexOf('4') != -1) {
        // Vars for centering the new window on Version 4 Browsers
        x4 = screen.width/2 - (w/2);
        y4 = screen.height/2 - (h/2);
        sortableListSearchPopupWindow = window.open(url, wn,'height='+h+',width='+w+',scrollbars=0,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + x4 + ',top=' + y4 + '');
    } else {
        sortableListSearchPopupWindow = window.open(url, wn,'height='+h+',width='+w+',scrollbars=0,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=150,top=150');
    }
    var foo = sortableListSearchPopupWindow;
    foo.focus();
}
