/****
*
*   A set of javascript functions to do row filtering in a table given a 
*   form containing search parameters.
*
*  Compatibility : IE4+
*  	
*  Author  : Sidney Chong
*  Date    : 24/8/2001
*  Version : 1.0d
*
*  Modified by Berend Jan Weenink
*  To suit specific filtering requirements
*
****/

function _TF_showAll(table) {

	var tb = document.getElementById(table);

	for (i=0;i<tb.rows.length;i++)
	{
		tb.rows[i].style.display = "";
	}
}

function doFilter(tble,input) {
    var tb = document.getElementById(tble);
    if (tb != null) {
        var inputField = input;

        var conditions = new Array();
        var inputFilter = document.getElementById(inputField);
        var strFilterValue = inputFilter.value.split(" ");

        for (ss=0; ss<strFilterValue.length; ss++){
	        if (strFilterValue[ss] != "") {
		        index = conditions.length;
		        conditions[index] = new Object;
		        //conditions[index].name = inputFilter.getAttribute("TF_colKey");
		        conditions[index].value = strFilterValue[ss];
	        }
        }
        _BJ_filterTable(tb, conditions);
    }
}



function _BJ_filterTable(tb, conditions) {
	//given an array of conditions, lets search the table

	for (i=0; i<tb.rows.length; i++) {
		var rw = tb.rows[i];
		var show = false;	
		if (conditions.length > 0) {
			for (j=0; j<rw.cells.length; j++) {
				var cl = rw.cells[j];
				//var colKey = cl.getAttribute("TF_colKey");
				for (k=0; k<conditions.length; k++)	{

					//if (colKey == null) { //attribute not found
                    //	continue; //so lets not search on this cell.
					//}
					//if (conditions[k].name.toUpperCase() == colKey.toUpperCase()) {

	                    if(document.all){
	                        var val = cl.innerText.toLowerCase();
	                    } else{
	                        var val = cl.textContent .toLowerCase();
	                    }
	
	                    var conVals = conditions[k].value.toLowerCase();
	                    if (val.indexOf(conVals)>=0) {
                            show = true;
                   			continue;
	                    } else if(show != true) {
                            show = false;
	                    }
					//}
				}
			}
		}
		if (show == true || conditions.length <= 0)
			tb.rows[i].style.display = "";
		else
			tb.rows[i].style.display = "none";
	}
}