// Quick Search
var proptypes = new Spry.Data.HTMLDataSet(null, "proptypesData");
var subdivisions = new Spry.Data.HTMLDataSet(null, "subdivisionData");
var Links = new Spry.Data.HTMLDataSet(null, "{proptypes::tablename}");
var city = new Spry.Data.HTMLDataSet(null, "cityData");
// subdivisions.setColumnType("AvgPrice","number");
// var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel1");
// var CollapsiblePanel2 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel2");

var HideExtras = true; // make global
var HideMe = true; // make global

// Links.addObserver(ObsCallback);
Spry.Utils.addLoadListener(function(){
	// if (HideExtras) HideIt();
});

function ObsCallback(notificationType, notifier, data)
{
	// alert(notificationType);
	if (notificationType == "onPostLoad" || notificationType == "onPostSort") {
		alert(HideExtras);
		HideIt();
	}
}

function HighLight(obj){
	// alert("in SetIt");
	Spry.$$(obj.parent).toggleClassName("hilite");
}

function SetIt(){
	// alert("in SetIt");
	Spry.$$("table.prtable th:nth-child(3),table.prtable td:nth-child(3)").toggleClassName("HideIt");
    Spry.$$("table.prtable th:nth-child(4),table.prtable td:nth-child(4)").toggleClassName("HideIt");
}

function HideIt(){
	// alert("in HideIt");
	// Spry.$$("table.prtable th:nth-child(2),table.prtable td:nth-child(2)").toggleClassName("HideIt");
	if (HideExtras) {
	  Spry.$$("table.prtable th:nth-child(3),table.prtable td:nth-child(3)").addClassName("HideIt");
	  Spry.$$("table.prtable th:nth-child(4),table.prtable td:nth-child(4)").addClassName("HideIt");
	  HideExtras = false;
	} else {
	  Spry.$$("table.prtable th:nth-child(3),table.prtable td:nth-child(3)").removeClassName("HideIt");
	  Spry.$$("table.prtable th:nth-child(4),table.prtable td:nth-child(4)").removeClassName("HideIt");
	  HideExtras = true;
	}
	HideMe = HideExtras;
	// alert (HideExtras);
}

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.

		subdivisions.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["Subdivision"];
		if (str && str.search(regExp) != -1)
			return row;
		return null;
	};

	subdivisions.filter(filterFunc);
}

function StartFilterTimer()
{
	if (StartFilterTimer.timerID)
		clearTimeout(StartFilterTimer.timerID);
	StartFilterTimer.timerID = setTimeout(function() { StartFilterTimer.timerID = null; FilterData(); }, 100);
}

function FilterCityData()
{
	var tf = document.getElementById("filterTF");
	if (!tf.value)
	{
		// If the text field is empty, remove any filter
		// that is set on the data set.

		city.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["Name"];
		if (str && str.search(regExp) != -1)
			return row;
		return null;
	};

	city.filter(filterFunc);
}

function StartFilterCityTimer()
{
	if (StartFilterCityTimer.timerID)
		clearTimeout(StartFilterCityTimer.timerID);
	StartFilterCityTimer.timerID = setTimeout(function() { StartFilterCityTimer.timerID = null; FilterCityData(); }, 100);
}


