com={};com.schachopen={};
com.schachopen.tablesearch = {};
com.schachopen.tablesearch.tables = [];
com.schachopen.tablesearch.action = function( tableNr, queryNr ){
			var tmp = com.schachopen.tablesearch.tables[tableNr];
			if( tmp.queryNr > queryNr ) return;
			var searchField = tmp.searchField;
			var s 		= tmp.searchField.value;
			var rows 	= tmp.t.select('tbody > tr');
			for(var y=0; y<rows.length; y++){
				var words = "";
				var cols  = rows[y].select('td');
				
				for(var z=0; z<cols.length; z++){
				 	var w = cols[z].innerHTML.strip();
				 	w = w.toLowerCase();
				 	if(w!="") words += w;
				}

				var query = [];
				var qToken = searchField.value.split(" ");
				for( var j=0; j<qToken.length; j++ ){
					qToken[j] = qToken[j].strip();
					qToken[j] = qToken[j].toLowerCase();
					if(qToken[j]!="") query.push(qToken[j]);
				}				
				var visible = true;
				
				for(var z=0; z<query.length; z++){
					var found = false;
					if(words.search(query[z])>-1) found = true;
					if(found) visible = true;
					else{
						visible = false;
						break;
					}
				}
				if( (query.length===1 && query[0]=="") || s=="search ..." ) visible = true;
				if(visible) rows[y].show();
				else rows[y].hide();
			}
}
com.schachopen.tablesearch.listener = function(e){
	var tableNr = e.element().readAttribute('counter');
	var table = com.schachopen.tablesearch.tables[tableNr];
	table.queryNr++;
	window.setTimeout('com.schachopen.tablesearch.action( '+tableNr+', '+table.queryNr+' );',500);	
}

