// JavaScript Document

var mystr
var regExp
//add Right string functionality
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function MyLimitFunc(typeid, dataSet) //THIS IS THE GOOD FUNCTION FOR TYPE FILTERING OF DB LIST, 6/11 1:10 PM
{
user_dataset.filter(null); // Turn off non-destructive filtering. || row["title"].search(/^S/) != -1
	regExp = new RegExp("^" + typeid);
	
	var limitFunc = function(ds, row, rowNumber)
	{
		if (row["type_id"].search(regExp) != -1)
		return row; // Return the row to keep it in the data set.
	return null; // Return null to remove the row from the data set.
	
	};
	dataset.addFilter(limitFunc);
	dataset.applyFilters();
	//dataSet.filter(limitFunc);
}

function MyDeptFunc(deptid, dataSet) //THIS IS THE GOOD FUNCTION FOR DEPT FILTERING OF STAFF LIST, 6/11 1:10 PM
{
dataSet.filter(null); // Turn off non-destructive filtering. || row["title"].search(/^S/) != -1
	regExp = new RegExp("^" + deptid);

	var deptlimitFunc = function(ds, row, rowNumber)
		{	
		if (row["@dept_id"].search(regExp) != -1)
		return row; // Return the row to keep it in the data set.
	return null; // Return null to remove the row from the data set.
	
	};
	dataSet.addFilter(deptlimitFunc);
	dataSet.applyFilters();
	//dataSet.filter(limitFunc);
}

function MyQueryFunc(ltr, dataSet) //THIS IS THE GOOD FUNCTION FOR LETTER FILTERING OF DB LIST, 6/11 10:37 AM
{

	//regExp = new RegExp("^" + ltr);
	regExp = new RegExp("^" + ltr, "i");
	
	var filterFunc = function(ds, row, rowNumber)
	{
		if (row["title"].search(regExp) != -1)
		return row; // Return the row to keep it in the data set.
	return null; // Return null to remove the row from the data set.
	
	};

	dataSet.filter(filterFunc);
}
	// Now that the data is filtered. Decide if we
	// should show the menu or not.

function MyLtrFunc(ltr, dataSet) //THIS IS THE GOOD FUNCTION FOR LETTER FILTERING OF STAFF LIST, 6/11 10:37 AM
{

	regExp = new RegExp("^" + ltr);
	
	var ltrfilterFunc = function(ds, row, rowNumber)
	{
		if (row["last_name"].search(regExp) != -1)
		return row; // Return the row to keep it in the data set.
	return null; // Return null to remove the row from the data set.
	
	};

	dataSet.filter(ltrfilterFunc);
}
	// Now that the data is filtered. Decide if we
	// should show the menu or not.

function MyFLtrFunc(ltr, dataSet) //THIS IS THE GOOD FUNCTION FOR LETTER FILTERING OF STAFF LIST, 6/11 10:37 AM
{

	regExp = new RegExp("^" + ltr);
	
	var ltrfilterFunc = function(ds, row, rowNumber)
	{
		if (row["first_name"].search(regExp) != -1)
		return row; // Return the row to keep it in the data set.
	return null; // Return null to remove the row from the data set.
	
	};

	dataSet.filter(ltrfilterFunc);
}
	// Now that the data is filtered. Decide if we
	// should show the menu or not.


// get the letter to filter by.
function searchme(href)
{
	 mystr = Right(href, 1);   
	 //regExp = new RegExp("^" + mystr);
	 //regExp = new RegExp(mystr + "/i");
	//alert(regExp);
	//return regExp;
//	myFilterFunc();
user_dataset.filter(myFilterFunc);
}
        // var regExp = new RegExp(regExpStr, "i");
var myFilterFunc = function(dataSet, row, rowNumber)
{
	 //var mystr = Right(href, 1);   
	 regExp = new RegExp("^" + mystr);
	 //alert(regExp);
	 user_dataset.filter(null); // Turn off non-destructive filtering. || row["title"].search(/^S/) != -1
	if (row["title"].search(regExp) != -1) 
		return row; // Return the row to keep it in the data set.
	return null; // Return null to remove the row from the data set.
}


// Filter out all rows that don't have a path that begins
// with the letter 's'.
//var myFilterFunc = function(dataSet, row, rowNumber)
//{
//	if (row["title"].search(/^S/) != -1)
//		return row; // Return the row to keep it in the data set.
//	return null; // Return null to remove the row from the data set.
//}; // Filter the rows in the data set.
