1tablefilterjs = {};
2tablefilterjs.decodeHTML = function(text)
3{
4    return jQuery('<div/>').html(text).text();
5};
6tablefilterjs.find_th_eq = function( col, $table )
7{
8    var eq = -1;
9    $table.find('th').each(function() {
10	if( jQuery(this).text() == col )
11	    eq = jQuery(this).index();
12    });
13    return eq;
14};
15jQuery(document).ready(function ()
16{
17    jQuery(".tablefilterjs").each(function() {
18	$table = jQuery(this).find("table");
19
20	var filters = jQuery.parseJSON( tablefilterjs.decodeHTML(jQuery(this).data("filters")) );
21
22	for( col in filters )
23	{
24	    if( isNaN( col ) )
25	    {
26		var eq = tablefilterjs.find_th_eq( col, $table );
27		if( eq == -1)
28		    continue;
29	    } else
30	    {
31		var eq = parseInt( col ) - 1;
32	    }
33            var regex = new RegExp( filters[col][0], filters[col][1] );
34    	    $table.find("tr:has(td)").each(function() {
35		if( ! jQuery(this).find("td").eq(eq).text().match( regex ) )
36		    jQuery(this).hide();
37	    });
38	}
39
40    });
41});
42