/*******************************************************************/
/*                                                                 */
/* Copyright (c) 2005-2009 4Psite.com                              */
/*                                                                 */
/*                                                                 */
/*******************************************************************/

var fbrand = 'ALL';
var pricev = 'ALL';
var account = 'ALL';

var ds1 = new Spry.Data.DataSet();

ds1.addObserver(processData); 

ds1.setDataFromArray(myArrayOfData);

ds1.setColumnType("Price", "number");
ds1.setColumnType("Memprice", "number");
ds1.setColumnType("Sprice", "number");

//var ds1 = new Spry.Data.HTMLDataSet(null, "filterTable");
//var ss1 = new Spry.Data.HTMLDataSet(null, "sizeTable");
var pv1 = new Spry.Data.PagedView( ds1 ,{ pageSize: 999 });
var pv1Info = pv1.getPagingInfo();

//ss1.distinct(); // Remove all duplicate rows.

ds1.filterData(null); // Turn off destructive filtering.

// Filter out all rows that don't have a path that begins
// with the letter 's'.
var myFilterFunc = function(dataSet, row, rowNumber)
{
	if (account == 'ALL' && pricev == 'ALL' ) return row;	
	if (account == 'ALL' && pricev == row["Pricer"] ) return row;
	if (account == row["Author"] && pricev == 'ALL' ) return row;
	if (account == row["Author"] && pricev == row["Pricer"] ) return row;
	
    return null; // Return null to remove the row from the data set.
}

ds1.filter(myFilterFunc); // Filter the rows in the data set.
ds1.filter(null); // Turn off non-destructive filtering.

function filterV(form) {
 var x = form.author.selectedIndex;
 account  = form.author.options[x].value;
 var x = form.prices.selectedIndex;
 pricev  = form.prices.options[x].value;
 ds1.filter(myFilterFunc);
 return (false);
}

function processData(notificationType, notifier, thisdata) {
    if (notificationType != "onPostLoad") return;

    var rows = ds1.getData();
    var numRows = rows.length;
    for (var i = 0; i < numRows; i++) {
       var row = rows[i];
	   m_price = eval(row.Price + row.Mem);
	   row.Memprice = m_price.toFixed(2);
	   row.Price = row.Price.toFixed(2);
    }
} 

Array.prototype.unique = function () {
	var r = new Array();
	o:for(var i = 0, n = this.length; i < n; i++)
	{
		for(var x = 0, y = r.length; x < y; x++)
		{
			if(r[x]==this[i])
			{
				continue o;
			}
		}
		r[r.length] = this[i];
	}
	return r;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function selbrand(brandv) {
   var arr = brandv.split("`");	
   var unique = arr.unique();
   var t = unique.sort();
   listObj = document.filter;
   listObj.author.length=0;
   listObj.author[0] = new Option("View all", "ALL");
   var k=1;
   for (i=1; i<(t.length+1); i++) {
	 if ( trim(t[i-1]) != '' ) { 
	  listObj.author[k] = new Option(t[i-1],t[i-1]);
	  k = k + 1;
	 }
   }
   listObj.author.selected = true;   
}

