// JavaScript Document Filter functions for search-lists.html

function FilterData() 
{
	var tf = document.getElementById("filterTF");
	if (!tf.value)
	{
		// If the text field is empty, remove any filter that is set on the data set.
		dsBirdslist.filter(null);
		return;
	}
	// Set a filter on the data set that matches any row
	// that begins with the string in the text field.
	var regExpStr = tf.value;
	if (!document.getElementById("containsCB").checked)
		regExpStr = "^" + regExpStr;
	var regExp = new RegExp(regExpStr, "i");
	var filterFunc = function(ds, row, rowNumber)
	{
		var str = row[filter];
		if (str && str.search(regExp) != -1)
			return row;
		return null;
	};
	dsBirdslist.filter(filterFunc);
}

function StartFilterTimer()
{
	if (StartFilterTimer.timerID)
		clearTimeout(StartFilterTimer.timerID);
	StartFilterTimer.timerID = setTimeout(function() { StartFilterTimer.timerID = null; FilterData(); }, 100);
}
