// JavaScript Document
var dsStates = new Spry.Data.XMLDataSet("/blog/iTunes/spry.xml", "states/state")

//##############################入力ボックスで絞り込み　ここから
function FilterData()
{
	var tf = document.getElementById("filterTF");
	//var tf2 = document.getElementById("filterTF2"); //追加
	if (!tf.value)
	{
		// If the text field is empty, remove any filter
		// that is set on the data set.

		dsStates.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 str1 = row["catalog"];
		var str2 = row["album"];
		var str3 = row["artist"];
		var str4 = row["format"];
		var str5 = row["genre"];
		var str6 = row["release"];
		     if (str1 && str1.search(regExp) != -1)
			return row;
		else if (str2 && str2.search(regExp) != -1)
			return row;
		else if (str3 && str3.search(regExp) != -1)
			return row;
		else if (str4 && str4.search(regExp) != -1)
			return row;
		else if (str5 && str5.search(regExp) != -1)
			return row;
		else if (str6 && str6.search(regExp) != -1)
			return row;
		return null;
		
	};

	dsStates.filter(filterFunc);
}

function StartFilterTimer()
{
	if (StartFilterTimer.timerID)
		clearTimeout(StartFilterTimer.timerID);
	StartFilterTimer.timerID = setTimeout(function() { StartFilterTimer.timerID = null; FilterData(); }, 50);
}
//##############################入力ボックスで絞り込み　ここまで



//##############################セレクトメニューで絞り込み　ここから
function FilterData2()
{
	var tf = document.getElementById("filterTF2");
	if (!tf.value)
	{
		// If the text field is empty, remove any filter
		// that is set on the data set.

		dsStates.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 str1 = row["genre"];
		var str2 = row["release"];
		var str3 = row["format"];
		     if (str1 && str1.search(regExp) != -1)
			return row;
		else if (str2 && str2.search(regExp) != -1)
			return row;
		else if (str3 && str3.search(regExp) != -1)
			return row;
		return null;
		
	};

	dsStates.filter(filterFunc);
}

function StartFilterTimer2()
{
	if (StartFilterTimer2.timerID)
		clearTimeout(StartFilterTimer2.timerID);
	StartFilterTimer2.timerID = setTimeout(function() { StartFilterTimer2.timerID = null; FilterData2(); }, 50);
}
//##############################セレクトメニューで絞り込み　ここまで




//##############################セル背景の色交互　ここから
function ToggleFilter()
{
	if (!ToggleFilter.filtered)
		dsEmployees.filter(function(ds, row, rowNum) { if (rowNum % 2) return row; return null; });
	else
		dsEmployees.filter(null);
	ToggleFilter.filtered = !ToggleFilter.filtered;
}
//##############################セル背景の色交互　ここまで