/** Configure a TableTags xhtml theme table

**/
function tableSetup(height, width, isIE){
    tableSetup(height, width, isIE, '');
}
function tableSetup(height, width, isIE, tableId){
    setTableDimensions(height, width, isIE, tableId);
    alternateRows(document.getElementById(tableId + 'DataTable'));   
}

/** Change the height and width of a scrolling table.
    @See also tableScrolling.css */
    /* Note: if small width causes horizontal scrolling, 
	extra scrollbars will appear */
function setTableDimensions(newHeight, newWidth, isBrowser_ie, tableId) {

    // enforce minimums
    if(newHeight < 100)
		newHeight = 100;
    if(newWidth < 100)
        newWidth = 100;
    
    // get table elements
    var d = document.getElementById(tableId + 'ScrollTableContainer');
    var t = document.getElementById(tableId + 'DataTable');
    var b = t.tBodies[0];
    var p = document.getElementById(tableId + 'PagerDiv');
    
    d.style.height = newHeight + 'px';
    d.style.width = newWidth + 'px';
    
    if(isBrowser_ie) {
		t.style.width = newWidth - 25;  // width minus scrollContainer scrollbar
		p.style.width = newWidth - 25;   
		d.style.height = newHeight -25;
	}
	else {
        t.style.width = newWidth + 'px';
		p.style.width = newWidth + 'px'; 
        // for FF: height - top row, assuming two lines
		b.style.height = (newHeight - 25) + 'px';  
	}
	 
    
}

/** color alternating table rows */
function alternateRows(table) {
    if(table != null) {
        var rows = table.getElementsByTagName("tr");  
	for(i = 0; i < rows.length; i++){          
	    if(i % 2 == 0)
                classChange(rows[i], "alt", false)
            else
		classChange(rows[i], false, "alt");
	}        
    }
    else
        alert('table is null');
}


/** Highlight a single selected row in a table */

/** The previous row clicked by the user */
var lastSelectedRow = null;

/** Highlight the selected row, 
*   clear highlighting from the previously selected row 
*/
function highlightRow(row) {
    classChange(lastSelectedRow, false, 'selected');
    classChange(row, 'selected', false);
    lastSelectedRow = row;	    
}

	    
/** Add and/or remove an element's class 
*   e		The element to affect
*   addClass	The class to add, or false if no class is to be added
*   remClass	The class to remove, or false if no class is to be removed 
*/
function classChange(e,addClass,remClass) { 
    if(e == null)
	return;
    if (!e.className) 
	e.className = ''; 
    var clsnm = e.className; 
    if (addClass && !clsnm.match(RegExp("\\b"+addClass+"\\b"))) 
	clsnm = clsnm.replace(/(\S$)/,'$1 ')+addClass; 
    if (remClass) 
	clsnm = clsnm.replace(RegExp("(\\s*\\b"+remClass+"\\b(\\s*))*","g"),'$2'); 
    e.className=clsnm; 
}
