
function filterit( attr ){
	var val = document.getElementById("filterit").value;
	if( val != '' )
		val = new RegExp( val,"i" );

	var tbl = document.getElementById("filtertbl");
	var cells = tbl.getElementsByTagName("TR");
	for( var row =0; row < cells.length; row++ ){
		var curr = cells [ row ];
		if( curr.getAttribute( attr ) ){
				var attrval = curr.getAttribute( attr );
				if( ! attrval.match( val ) )
					curr.style.display = "none";
				else
					curr.style.display = "block";
		}
	}
}


function refreshList(){
	var tbl = document.getElementById("filtertbl");
	var cells = tbl.getElementsByTagName("TR");
	for( var row =0; row < cells.length; row++ ){
		var curr = cells [ row ];
		curr.style.display = "none";
	}

	var str_arr = new Array();
	var thestring = "";
	for ( counter = 1; counter < 8; counter++ ){
		var chkbx = document.getElementById( "ch"+counter );
		if( chkbx.checked ){
			str_arr[ str_arr.length ] = chkbx.strval;
			thestring += chkbx.strval;
			checkTheList( chkbx.strval );
		}
	}
}

function checkTheList( val ){
	if( val != '' )
		val = new RegExp( val,"i" );
	else
		return;
	var tbl = document.getElementById("filtertbl");
	var cells = tbl.getElementsByTagName("TR");
	for( var row =0; row < cells.length; row++ ){
		var curr = cells [ row ];
		if( curr.getAttribute( 'filterattr' ) ){
				var attrval = curr.getAttribute( 'filterattr' );
				if( attrval.match( val ) )
					curr.style.display = "block";
		}
	}
}

function listPartners(){
	var custom = hasURLParam( "_type" );
	if( custom ){
		customize_optiosn ( getMappings( custom ) );
	}
}

function getMappings( custom ){
	var ret = null;
	if( custom == '1' ){
		ret = new Array("Pending Case","Service Providers","Policy Application Upload" );
	}

	for ( counter = 1; ret && counter < 8; counter++ ){
		var chkbx = document.getElementById( "ch"+counter );
		if( chkbx.checked ){
			var needcheck = false;
			for ( counter1 = 0; counter1 < ret.length; counter1++ ){
				if( ret[ counter1 ] == chkbx.strval )
					needcheck = true;
			}
			if( needcheck )
				chkbx.checked = true;
			else
				chkbx.checked = false;
		}
	}

	return ret;
}

function customize_optiosn( customlist ){
	if( ! customlist )
		return;

	var tbl = document.getElementById("filtertbl");
	var cells = tbl.getElementsByTagName("TR");
	for( var row =0; row < cells.length; row++ ){
		var curr = cells [ row ];
		curr.style.display = "none";
	}

	for ( counter = 0; counter < customlist.length; counter++ ){
			checkTheList( customlist[ counter ] );
	}

}

function hasURLParam( name ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return null;
	else
		return results[1];
}
