//
//-------------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (c) Copyright IBM Corp. 2007
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//-------------------------------------------------------------------
//

		dojo.registerModulePath("wc", "wc");

		//AJAX request support
		dojo.require("dojo.io.*");
			
		//product quick view with tooltip widget
		dojo.require("wc.widget.ProductQuickView");
		dojo.require("wc.widget.BaseContent");
		dojo.require("wc.widget.ToolTipContent");
		
		//category menu support
		dojo.require("dojo.widget.Button");
		dojo.require("dojo.widget.Menu2");

		//range slider widget
		dojo.require("wc.widget.RangeSlider");
				
		//reload widgets when parts of the page has been re-loaded from server
		dojo.require("dojo.xml.Parse");
			
		//publish and subscribe event support
		dojo.require("dojo.event.*");

		//back, forward and bookmarking
		dojo.require("dojo.undo.browser");

		//scrollable pane
		dojo.require("wc.widget.ScrollablePane");
		dojo.require("dojo.animation.*");
		dojo.require("dojo.lfx.*");
		dojo.require("dojo.string.extras");
		dojo.require("dojo.collections.ArrayList");
		
		
		var beginIndex = 0;
		var prevIndex = null; 
		var nextIndex = null;


		/**********************************************************
		* Function to create a WC product object with useful parameters for the Web 2.0 store.
		**********************************************************/	
		function WCProduct() 
		{
				this.catentryId = "";
				this.SKU = "";
				this.name = "";
				this.identifierCounter = "";
				this.shortDescription = "";
				this.smallImageSrc = "";
				this.mediumImageSrc = "";
				this.price = "";
				this.brand = "";
				this.features = new Vector();
				this.filterNames = new Vector();
				this.filterValues = new Vector();
				this.productDisplayURL = "";
				this.dragSourceType = "";
				this.baseContentHTML = "";
				this.toolTipHTML = "";
				this.category = "search";
				this.newArrival = "false";
				this.clearance = "false";
				this.hotBuy = "false";
				this.showPrice = "true";
				this.listPrice = "";
		}

	fastFinderJS={
		totalResultsMessage : "UNDEFINED",
		pagingMessage : "UNDEFINED",
		pagingMessage2 : "UNDEFINED",

		catalogEntriesResultSet : new Vector(),
		catalogEntriesByPrice : new Vector(),
		catalogEntriesByPopularity : new Vector(),

		pageSize : 12,
		resultsPerRow : 4,
		displayCounter : 0,
		displayRowCounter : 0,
		totalProductsInCategory : "UNDEFINED",
		productIdentifierString : "catBrowse",

		catalogEntriesResultSetTotal : 0,
		catalogEntriesResultSetTotalPages : 0,
		catalogEntriesResultSetCurrentPageNumber : 0,
		displayTotal : this.pageSize,
		beginIndex : 0,
		prevIndex : null, 
		nextIndex : null,

		imagePath : "UNDEFINED",
		viewType : "image",
		storeId : "UNDEFINED",
		catalogId : "UNDEFINED",

		filterNames : new Vector(),
		filterValuesVector : new Vector(),
		
		hashValue : "",
		

		/**********************************************************
		* Function to create a ProductQuickView widget using JavaScript. 
		*
		*	Parameters:
		*	productObj - the WC product object
		* identifierString - the identifier of the catalog entry element
		* imageSize - the size of the image
		* showCompare - show the compare icon in the tooltip
		* imagePath - the image path
		* viewType - "image" or "detailed" view
		* storeId - the store id
		* catalogId - the catalog id
		* bottomBorder - determines whether or not to show a bottom border
		* rightBorder - determines whether or not to show a right border
		**********************************************************/
		createProductWidget : function(parentObject, productObj, identifierString, imageSize, showCompare, imagePath, viewType, storeId, catalogId, bottomBorder, rightBorder) 
		{
				var _id = identifierString + productObj.identifierCounter;
				var widgetHTML = ""
				
				if(productObj.baseContentHTML == null || productObj.baseContentHTML == ""){
					
					//alert("productObj.smallImageSrc:" + productObj.smallImageSrc + "\nproductObj.mediumImageSrc:" + productObj.mediumImageSrc + "\nimagePath:" + imagePath);
					if(productObj.smallImageSrc == "") productObj.smallImageSrc = imagePath + "NoImageIcon_sm45.jpg";
					if(productObj.mediumImageSrc == "") productObj.mediumImageSrc = imagePath + "NoImageIcon_sm.jpg";

					//var _baseContentImgSrc = (viewType == "image")? productObj.mediumImageSrc : productObj.smallImageSrc;
					var _baseContentImgSrc = productObj.smallImageSrc;
					var _baseContentNamePrice = "";
					var _baseContentNameTD = "";
					var _baseContentPriceTD = "";

					if (viewType == "image") {
						_baseContentNamePrice = ""
												+"<td id='"+ _id + "Td' class='thumbnails'>\n";
						if (rightBorder) {
							_baseContentNamePrice = _baseContentNamePrice
												+"	<div class='categoryDisplayBox'>\n";
						}
						else {
							_baseContentNamePrice = _baseContentNamePrice
												+"	<div class='categoryDisplayBoxNoBorder'>\n";
						}
						_baseContentNamePrice = _baseContentNamePrice
												+"	<div id='"+ _id + "' class='imageHolder'>\n"
												+"	<table><tr><td>\n"
												+"		<a id='imgcatBrowse"+ _id + "' href='"+ productObj.productDisplayURL +"' >\n"
												+"			<img src='"+ imagePath + _baseContentImgSrc +"' alt='"+ productObj.shortDescription +"' />\n"
												+"		</a>\n"
												+"	</td></tr></table>\n"
												+"	</div>\n"
												+"	<div class='categoryDisplayBoxSpecial'>\n";
						if (productObj.hotBuy == 'true') {
							_baseContentNamePrice = _baseContentNamePrice
												+"		<span class='itemFlag'>RED HOT DEAL</span>\n";
						}
						else if (productObj.clearance == 'true') {
							_baseContentNamePrice = _baseContentNamePrice
												+"		<span class='itemFlag'>CLEARANCE</span>\n";
						}
						else if (productObj.newArrival == 'true') {
							_baseContentNamePrice = _baseContentNamePrice
												+"		<span class='itemFlag'>NEW</span>\n";
						}
						_baseContentNamePrice = _baseContentNamePrice
												+"	</div>\n"
												+"	<div id='" + _id + "NamePriceDiv'>\n"
												+"		<div class='itemNameSm'><a href='"+ productObj.productDisplayURL +"'>" + productObj.name + "</a></div>\n";
						if (productObj.showPrice == 'true') {												
							_baseContentNamePrice = _baseContentNamePrice
												+"		<span class='priceSm'>Reg. " + productObj.listPrice + "</span><br />\n";
							if (productObj.listPrice != productObj.displayPrice) {
								_baseContentNamePrice = _baseContentNamePrice
												+"		<span class='lowestPriceSm'>Sale " + productObj.displayPrice + "</span>\n";
							}
						}
						else {
							_baseContentNamePrice = _baseContentNamePrice
												+"		<span class='priceSm'>Call for price</span><br />\n";
						}
						_baseContentNamePrice = _baseContentNamePrice
												+"	</div>\n";
						if (bottomBorder) {
							_baseContentNamePrice = _baseContentNamePrice
												+"	<div class='categoryDisplayBoxSeparatorBottom'>\n";
						}
						_baseContentNamePrice = _baseContentNamePrice
												+"	</div>\n"
												+"</td>\n";
					} 
					else if (viewType == "detailed") 
					{
						_baseContentNamePrice = ""
											+"	<td id='"+ _id + "Td' align='left' valign='top'>\n"
											+"		<div id='"+ _id + "' align='left' >\n"
											+"			<a id='imgcatBrowse"+ _id + "' href='"+ productObj.productDisplayURL +"' >\n"
											+"				<img src='"+ imagePath + _baseContentImgSrc +"' alt='"+ productObj.shortDescription +"' border='0' />\n"
											+"			</a>\n"
											+"		</div>\n"
											+"	</td>\n"
											+"	<td id='"+ _id +"NameTd'>\n"
											+"		" + productObj.name + "\n"
											+"		<br/>\n"
											+"		" + productObj.shortDescription + "\n"
											+"	</td>\n"
											+"	<td id='"+ _id +"PriceTd' align='right'>\n"
											+"		" + productObj.displayPrice + "\n"
											+"	</td>\n";
					}
//					widgetHTML = _baseContentNamePrice;

					widgetHTML = ""	
									+"			<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n"
									+"				<tbody id='"+ _id + "Table' >\n"
									+"					<tr id='"+ _id + "Tr' >\n"
									+"						" + _baseContentNamePrice
									+"					</tr>\n"
									+"				</tbody>\n"
									+"			</table>\n"; 
				}else{
					widgetHTML = productObj.baseContentHTML;
				}
				var div = document.createElement("div");
				parentObject.appendChild(div);
								
				// create the ProductQuickView
				var productQuickViewWidget = dojo.widget.createWidget("ProductQuickView", {
																							id: "productQuickView" + productObj.identifierCounter,
																							defaultContent: false,
																							identifier: _id
																							}, div);

				var topDiv = document.createElement("div");
				productQuickViewWidget.domNode.appendChild(topDiv);

				var baseContentWidget = dojo.widget.createWidget("BaseContent", {
																					id: "productQuickViewBase" + productObj.identifierCounter,
																					dragSourceId: _id,
																					dragSourceType: productObj.dragSourceType,
																					catentryId: productObj.catentryId,
																					userInnerHtml: widgetHTML
																					}, topDiv);
				
				/*var tooltipDiv = this.createProductToolTipWidget(productQuickViewWidget.domNode, productObj, identifierString, showCompare, imagePath, storeId, catalogId);*/
		},

		/**********************************************************
		* Function to create a product tool tip.
		**********************************************************/
		/*createProductToolTipWidget : function(parentObject, productObj, identifierString, showCompare, imagePath, storeId, catalogId) 
		{
				var _id = identifierString + productObj.identifierCounter;
				var widgetHTML = "";

				if(productObj.toolTipHTML == null || productObj.toolTipHTML == ""){
					var _productToolTipCompareLink = ""
					if (showCompare) {
						_productToolTipCompareLink = ""
													+"	<a id='comparelink"+ productObj.identifierCounter + "' href='javascript: Add2CompareAjax(\"" + productObj.catentryId + "\");'  >\n"
													+"		<img src='"+ imagePath  +"compare.gif' alt='compare' border='0' className='category_popup_iconimages' class='category_popup_iconimages' />\n"
													+"	</a>\n";
					}

					widgetHTML = ""	
									+"			<div class='imageRollover'>\n"
									+"			Click to view product details\n"
									+"				<div class='imageHolder'>\n"
									+"					<table><tr><td>\n"
									+"					<a id='imgcatBrowse"+ productObj.identifierCounter + "' href='"+ productObj.productDisplayURL +"' >\n"
									+"						<img src='"+ imagePath + productObj.mediumImageSrc +"' alt='"+ productObj.shortDescription +"' />\n"
									+"					</a>\n"
									+"					</table></tr></td>\n"
									+"				</div>\n"
									+"					<div id='tooltipHeaderDetailDiv"+ productObj.identifierCounter +"' className='category_popup_headerTitle' class='category_popup_headerTitle' >\n"
									+"						<div class='itemNameSm'>" + productObj.name + "</div>\n";
					if (productObj.showPrice == 'true') {
						widgetHTML = widgetHTML
									+"						<span class='priceSm'>Reg. " + productObj.listPrice + "</span><br />\n";
						if (productObj.listPrice != productObj.displayPrice) {
							widgetHTML = widgetHTML
									+"						<span class='lowestPriceSm'>Sale " + productObj.displayPrice + "</span>\n";
						}
					}
					else {
						widgetHTML = widgetHTML
									+"						<span class='priceSm'>Call for price</span><br />\n";
					}
					widgetHTML = widgetHTML
									+"					</div>\n"
									+"				</div>\n"
									+"			</div>\n";
				}else{
					widgetHTML = productObj.toolTipHTML;
				}

				var div = document.createElement("div");
//				div.setAttribute("class", "imageRollover");
				parentObject.appendChild(div);
				var toolTipContentWidget = dojo.widget.createWidget("ToolTipContent", {
																					id: "productToolTip" + productObj.identifierCounter,
																					connectId: _id,
																					toggleDuration: "250",
																					userInnerHtml:widgetHTML
																					}, div);
			toolTipContentWidget.productObj = productObj;
		},*/

		addElementToVector : function(targetVector, catentryId, SKU, name, identifierCounter, shortDescription, smallImageSrc, mediumImageSrc, 
									price, displayPrice, brand, productDisplayURL, dragSourceType, filterNamesVector, filterValuesVector, baseContentHTML, toolTipHTML,
									newArrival, clearance, hotBuy, showPrice, listPrice){
			
			var wcProduct = new WCProduct();
			wcProduct.catentryId = catentryId;
			wcProduct.SKU = SKU;
			wcProduct.name = name;
			wcProduct.identifierCounter = identifierCounter;
			wcProduct.shortDescription = shortDescription;
			wcProduct.smallImageSrc = smallImageSrc;
			wcProduct.mediumImageSrc = mediumImageSrc;
			wcProduct.price = price;
			wcProduct.displayPrice = displayPrice;
			wcProduct.brand = brand;
			wcProduct.productDisplayURL = productDisplayURL;
			wcProduct.dragSourceType = dragSourceType;
//			wcProduct.features = featuresArray;
			
			wcProduct.baseContentHTML = baseContentHTML;
			wcProduct.toolTipHTML = toolTipHTML;
			
			wcProduct.filterNames = filterNamesVector;
			wcProduct.filterValues = filterValuesVector;
			wcProduct.newArrival = newArrival;
			wcProduct.clearance = clearance;
			wcProduct.hotBuy = hotBuy;
			wcProduct.showPrice = showPrice;
			wcProduct.listPrice = listPrice;

			targetVector.addElement(wcProduct);
			
//			for (i=0;i<filterNamesVector.size();++i) {
//				alert('vector element ' + (i+1) + ': ' + filterNamesVector.elementAt(i));
//				var tempValuesVector = filterValuesVector.elementAt(i);
//				for (j=0;j<tempValuesVector.size();++j) {
//					alert('value vector element ' + (j+1) + ': ' + tempValuesVector.elementAt(j));
//				}
//			}
		},

		
		writeHistoryCookie : function(){
			//alert('writing cookie...');
			var cookieString = 'HOMFastFinder=';
			var filterNotFound = true;
			for (i=0; i<fastFinderJS.filterNames.size(); ++i) {
				var filterValuesForm = document.getElementById("FilterValues"+(i+1)+"Form");
				var filterValueElements = filterValuesForm.elements;
				var selectedValue = '';
				var count = 0;
				for (j=0; j<filterValueElements.length; ++j) {
					if (filterValueElements[j].checked) {
						selectedValue = '' + (i+1) + '.' + (j+1);
						++count;
					}
				}
				if (selectedValue != '' && count == 1 && filterValueElements.length > 1) {
					if (filterNotFound) {
						cookieString = cookieString + 'filterNames_';
						filterNotFound = false;
					}
					cookieString = cookieString + selectedValue + '|';
				}
			}
		    document.cookie = cookieString +
		    				 '&orderBy1_' + document.FastFinderForm.orderBy1.value +
		    				 '&itemsPerPage_' + document.FastFinderForm.itemsPerPage.value +
		    				 '&beginIndex_' + document.FastFinderForm.beginIndex.value +
		    				 '&minPrice_' + document.FastFinderForm.minPrice.value +
		    				 '&maxPrice_' + document.FastFinderForm.maxPrice.value +
		    				 '&timestamp_' + fastFinderJS.hashValue;
		},
		
		showResults : function(filterAction) {
			this.viewType = document.FastFinderForm.pageView.value;
			cursor_wait();
			//destroy only catalog browsing widgets
			dojo.lang.forEach(dojo.widget.byType("ProductQuickView"), function(widget) {
				tempStr = widget.identifier;
				tempStr = tempStr.substring(0,9);
				if (tempStr == this.productIdentifierString) {
					widget.destroy();
				}
			});
			
			//destroy all HTML in the results division
			//initialize global variables
			var productObj = null;
				
			var fastFinderResultsDiv = document.getElementById("fastFinderResults");
			for (j=0; j<fastFinderResultsDiv.childNodes.length; j++) {
				fastFinderResultsDiv.removeChild(fastFinderResultsDiv.childNodes[j]);
			}
			this.displayCounter = 0;
			this.displayRowCounter = 0;
			
			this.generateResultSet(filterAction);
			this.showTotalResultsMessage();
			this.showPagingMessage();
//			this.showPagingMessage2();

			var numRows = 1;
			if (this.displayTotal % this.resultsPerRow == 0) {
				numRows = this.displayTotal / this.resultsPerRow;
			}
			else {
				numRows = Math.floor(this.displayTotal/this.resultsPerRow)+1;
			}
			
			//create new product quick view HTML for the new result set and display them
//			for (i=beginIndex; i<(beginIndex + this.displayTotal); i++) {
			for (i=beginIndex; i<(beginIndex + (numRows * this.resultsPerRow)); i++) {
				this.displayCounter++;
				if (i < beginIndex + this.displayTotal) {
					productObj = this.catalogEntriesResultSet.elementAt(i);
				}
	
				var td1 = document.createElement("td");
				td1.setAttribute("id", "browseCatEntry"+i);
				td1.setAttribute("width", "25%");
		
				if (this.viewType == "image") {
					if (((this.displayCounter-1) % this.resultsPerRow) == 0 ) {
						this.displayRowCounter++;
						
						var tr1 = document.createElement("tr");
						tr1.setAttribute("id", "displayRow"+this.displayRowCounter);
					} else {
						var tr1 = document.getElementById("displayRow"+this.displayRowCounter);
					}
				} else if (this.viewType == "detailed") {
					this.displayRowCounter++;
					var tr1 = document.createElement("tr");
					tr1.setAttribute("id", "displayRow"+this.displayRowCounter);
				}
				tr1.appendChild(td1);
				
				if (i%this.pageSize == 0) {
					var table1 = document.createElement("table");
					table1.setAttribute("width", "100%");
					table1.setAttribute("border", "0");
					table1.setAttribute("cellpadding", "0");
					table1.setAttribute("cellspacing", "0");
					
					var tbody1 = document.createElement("tbody");
					tbody1.setAttribute("id", "displayItemsTable");
					
					table1.appendChild(tbody1);
					tbody1.appendChild(tr1);
					fastFinderResultsDiv.appendChild(table1);
				} else {
					var tbody1 = document.getElementById("displayItemsTable");
					tbody1.appendChild(tr1);
				}

				if (i < beginIndex + this.displayTotal) {
					var sideBorder = true;
					var bottomBorder = true;
					if (numRows == this.displayRowCounter) {
						bottomBorder = false;
					}
					if ((i+1) % this.resultsPerRow == 0) {
						sideBorder = false;
					}
					this.createProductWidget(td1,productObj, this.productIdentifierString, "medium", false, this.imagePath, this.viewType, this.storeId, this.catalogId, bottomBorder, sideBorder);
				}
			}
			
			// let Dojo parse the whole results division to create the widgets from HTML


			//Parsing is slowing down the operation and with the modified code we don't need it, so commented..
			//var testObj = new dojo.xml.Parse();
			//var testObjects = testObj.parseElement(document.getElementById("fastFinderResults"));
			//var testParse = dojo.widget.getParser();
			//testParse.createComponents(testObjects);

			cursor_clear();
			
			//Save in History
			//var historyObject = new HistoryTracker(document.getElementById('fastFinder_div').innerHTML, 'fastFinder_div');
			//dojo.undo.browser.addToHistory(historyObject);
			this.writeHistoryCookie();
		},
		
		//
		// Generate the result set based on user input. Set the helper global javascript variables.
		//
		generateResultSet : function(filterAction) {
			if (document.FastFinderForm.initialState.value == "false") {
				var tempList = null;
				if (filterAction != "beginIndex" && filterAction != "view") {
					if (filterAction == 'price' || filterAction == 'orderBy' || filterAction == 'filter') {
						beginIndex = 0;
					}
					// re-build the result set based on criterias selected by user
					this.catalogEntriesResultSet = new Vector();
					//this.catalogEntriesResultSet.removeAllElements();
					
					// 1. Get the initial sorted list by price or by popularity 
					if (document.FastFinderForm.orderBy1.value == "OfferPriceLowToHigh") {
						tempList = new Vector();
						var inserted = 'false';
						tempList.addElement(this.catalogEntriesByPopularity.elementAt(0));
						for (i=1; i<this.catalogEntriesByPopularity.size(); ++i) {
							var newPrice = new Number(this.catalogEntriesByPopularity.elementAt(i).price);
							inserted = 'false';
							for (j=0; j<tempList.size(); ++j) {
								var oldPrice = new Number(tempList.elementAt(j).price);
								if (newPrice < oldPrice) {
									tempList.insertElementAt(this.catalogEntriesByPopularity.elementAt(i),j);
									inserted = 'true';
									break;
								}
							}
							if (inserted == 'false') {
								tempList.addElement(this.catalogEntriesByPopularity.elementAt(i));
							}
						}
					}
					else if (document.FastFinderForm.orderBy1.value == "OfferPriceHighToLow") {
						tempList = new Vector();
						var inserted = 'false';
						tempList.addElement(this.catalogEntriesByPopularity.elementAt(0));
						for (i=1; i<this.catalogEntriesByPopularity.size(); ++i) {
							var newPrice = new Number(this.catalogEntriesByPopularity.elementAt(i).price);
							inserted = 'false';
							for (j=0; j<tempList.size(); ++j) {
								var oldPrice = new Number(tempList.elementAt(j).price);
								if (newPrice > oldPrice) {
									tempList.insertElementAt(this.catalogEntriesByPopularity.elementAt(i),j);
									inserted = 'true';
									break;
								}
							}
							if (inserted == 'false') {
								tempList.addElement(this.catalogEntriesByPopularity.elementAt(i));
							}
						}
					}
					else if (document.FastFinderForm.orderBy1.value == "NewArrivalsFirst") {
						tempList = new Vector();
						for (i=0; i<this.catalogEntriesByPopularity.size(); ++i) {
							if (this.catalogEntriesByPopularity.elementAt(i).newArrival == 'true') {
								if (tempList.size()==0) {
									tempList.addElement(this.catalogEntriesByPopularity.elementAt(i));
								}
								else {
									tempList.insertElementAt(this.catalogEntriesByPopularity.elementAt(i),0);
								}
							}
							else {
								tempList.addElement(this.catalogEntriesByPopularity.elementAt(i));
							}
						}
					}
					else if (document.FastFinderForm.orderBy1.value == "ClearanceFirst") {
						tempList = new Vector();
						for (i=0; i<this.catalogEntriesByPopularity.size(); ++i) {
							if (this.catalogEntriesByPopularity.elementAt(i).clearance == 'true') {
								if (tempList.size()==0) {
									tempList.addElement(this.catalogEntriesByPopularity.elementAt(i));
								}
								else {
									tempList.insertElementAt(this.catalogEntriesByPopularity.elementAt(i),0);
								}
							}
							else {
								tempList.addElement(this.catalogEntriesByPopularity.elementAt(i));
							}
						}
					}
					else {
						tempList = this.catalogEntriesByPopularity;
					}
					
					// 2. Eliminate entries based on selected criterias
					var minPrice = parseFloat(document.FastFinderForm.minPrice.value);
					var maxPrice = parseFloat(document.FastFinderForm.maxPrice.value);

					this.filterValuesVector = new Vector();
					for (i=0; i<this.filterNames.size(); ++i) {
//					alert('filterName='+this.filterNames.elementAt(i));
						var filterValuesForm = document.getElementById("FilterValues"+(i+1)+"Form");
						var filterValueElements = filterValuesForm.elements;
						var filterValues = new Vector();
						for (j=0; j<filterValueElements.length; ++j) {
							if (filterValueElements[j].checked) {
								var unescapedValue = new String(filterValueElements[j].value);
								unescapedValue = unescapedValue.replace(/"/g,'&#034;');
								unescapedValue = unescapedValue.replace(/'/g,'&#039;');
								filterValues.addElement(unescapedValue.toString());
//								alert('adding value='+unescapedValue.toString());
							}
						}
						this.filterValuesVector.addElement(filterValues);
					}

					dojo.debug("tempList.size() = "+ tempList.size());
					for (i=0; i<tempList.size(); i++) {
						var hasPrice = false;
						var hasFilters = true;
//						var hasBrand = false;
//						var hasFeature = false;
						//check price
						var productObjNew = tempList.elementAt(i);
						dojo.debug("minPrice = "+ minPrice);
						dojo.debug("maxPrice = "+ maxPrice);
						dojo.debug("productObjNew.price = "+ productObjNew.price);
						dojo.debug("productObjNew.brand = "+ productObjNew.brand);
						if (productObjNew.price >= minPrice && productObjNew.price <= maxPrice) {
							hasPrice = true;
						}
/*						
						//check brands
						if (brands.contains(productObjNew.brand)) {
							hasBrand = true;
						}
						
						//check features
						for (f=0; f<productObjNew.features.length; f++) {
							dojo.debug("productObjNew.features["+f+ "] = "+ productObjNew.features[f]);
							if (featureNames.contains(productObjNew.features[f])) {
								hasFeature = true;
								break;
							}
						}
*/
						// check filters
//						if (productObjNew.dragSourceType != 'package') {
							for (j=0; j<this.filterNames.size(); ++j) {
								var hasFilter = false;
								var filterName = this.filterNames.elementAt(j);
								var filterValues = this.filterValuesVector.elementAt(j);
								for (k=0; k<productObjNew.filterNames.size(); ++k) {
									if (filterName == unescape(productObjNew.filterNames.elementAt(k))) {
//									alert('filterName='+filterName+', filterValue='+productObjNew.filterValues[k]);
										var prodFilterValues = productObjNew.filterValues.elementAt(k);
										for (l=0; l<prodFilterValues.size(); ++l) {
											var prodFilterValue = unescape(prodFilterValues.elementAt(l));
											if (filterValues.contains(prodFilterValue)) {
//											alert('hasFilter=true');
												hasFilter = true;
												break;
											}
										}
									}
								}
								if (hasFilter == false) {
//								alert('hasFilters=false');
									hasFilters = false;
									break;
								}
							}
//						}
						
						
						dojo.debug("checking catentry = "+ productObjNew.catentryId);
						dojo.debug("hasPrice="+ hasPrice + ", hasFilters=" + hasFilters);
						if(hasPrice && hasFilters) {
							dojo.debug("adding catentry = "+ productObjNew.catentryId);
							this.catalogEntriesResultSet.addElement(productObjNew);
						}
					}
					
					for (i=0; i<this.filterNames.size(); ++i) {
						var filterValuesForm = document.getElementById("FilterValues"+(i+1)+"Form");
						var filterValueLIs = filterValuesForm.getElementsByTagName("li");
						for (j=0; j<filterValueLIs.length; ++j) {
							var filterValueLI = filterValueLIs[j];
							filterValueLI.style.visibility='hidden';
							filterValueLI.style.display='none';
						}
					}

					for (i=0; i<this.catalogEntriesResultSet.size(); ++i) {
						var filteredProductObj = this.catalogEntriesResultSet.elementAt(i);
						for (k=0; k<filteredProductObj.filterNames.size(); ++k) {
							var filterName = filteredProductObj.filterNames.elementAt(k);
							var filterValues = filteredProductObj.filterValues.elementAt(k);
							for (l=0; l<filterValues.size(); ++l) {
								var filterValue = filterValues.elementAt(l).replace(/&#034;/g,'"');
								filterValue = filterValue.replace(/&#039;/g,"'");
								var filterValueLI = document.getElementById(filterName + "_" + filterValue);
								if (filterValueLI != null) {
									filterValueLI.style.visibility='visible';
									filterValueLI.style.display='block';
								}
							}
						}
					}
										
				}
			} else {
				this.catalogEntriesResultSet = new Vector();
				for (k=0; k<this.catalogEntriesByPopularity.size(); k++) {
					this.catalogEntriesResultSet.addElement(this.catalogEntriesByPopularity.elementAt(k));
				}
                            
				var viewsTR = document.getElementById("sorts");
				var viewTypeTD2 = document.getElementById("viewTypeTD2");
				var viewTypeTD1 = document.getElementById("viewTypeTD1");
				if(viewsTR != null && viewTypeTD2 != null && viewTypeTD1 != null){
					viewsTR.removeChild(viewTypeTD2);
				}
			}
			
			// 3. Set all totals based on current result set and beginIndex
			this.catalogEntriesResultSetTotal = this.catalogEntriesResultSet.size();
			this.catalogEntriesResultSetTotalPages = Math.ceil(this.catalogEntriesResultSetTotal/this.pageSize);
			if (this.pageSize >= this.catalogEntriesResultSetTotal || beginIndex > this.catalogEntriesResultSetTotal) {
				beginIndex = 0;
			}
			this.catalogEntriesResultSetCurrentPageNumber = Math.floor(beginIndex/this.pageSize) + 1;
			
			if (this.catalogEntriesResultSetTotal < (this.catalogEntriesResultSetCurrentPageNumber*this.pageSize)) {
				this.displayTotal = (this.catalogEntriesResultSetTotal-beginIndex);
			} else {
				this.displayTotal = this.pageSize;
			}
			
			if (beginIndex == 0) {
				prevIndex = 0;
			} else {
				prevIndex = beginIndex-this.pageSize;
			}
			if ( (beginIndex+this.displayTotal) >= this.catalogEntriesResultSetTotal) {
				nextIndex = beginIndex;
			} else {
				nextIndex = beginIndex+this.displayTotal;
			}
			
		},

		showTotalResultsMessage : function() {
			var resultsTD = document.getElementById("totalResultsMessageDisplay");
			
			if(resultsTD != null){
				var text = this.totalResultsMessage;
				if (this.catalogEntriesResultSetTotal != 0) {
					text = text.replace(/%0/, beginIndex+1);
				} else {
					text = text.replace(/%0/, beginIndex);
				}
				if (beginIndex+this.displayTotal > this.catalogEntriesResultSetTotal) {
					text = text.replace(/%1/, this.catalogEntriesResultSetTotal);
				}
				else {
					text = text.replace(/%1/, beginIndex+this.displayTotal);
				}
//				text = text.replace(/%2/, this.totalProductsInCategory);
				text = text.replace(/%2/, this.catalogEntriesResultSetTotal);
				var textNode = document.createTextNode(text);
				
				if (resultsTD.childNodes.length == 1) {
					resultsTD.removeChild(resultsTD.firstChild);
				}
				resultsTD.appendChild(textNode);
			}else{
				dojo.debug("totalResultsMessageDisplay"+" element is missing");
			}
		},
		
		showPagingMessage2 : function() {
			var resultsTDTop = document.getElementById("pagingMessage2DisplayTop");
			var resultsTDBottom = document.getElementById("pagingMessage2DisplayBottom");
			var text = this.pagingMessage2;
			if (this.catalogEntriesResultSetTotal != 0) {
				text = text.replace(/%0/, this.catalogEntriesResultSetCurrentPageNumber);  
			} else {
				text = text.replace(/%0/, 0);
			}
			text = text.replace(/%1/, this.catalogEntriesResultSetTotalPages);
			
			var textNodeTop = document.createTextNode(text);
			var textNodeBottom = document.createTextNode(text);
			
			if (resultsTDTop.childNodes.length == 1) {
				resultsTDTop.removeChild(resultsTDTop.firstChild);
			}
			resultsTDTop.appendChild(textNodeTop);
			
			if (resultsTDBottom.childNodes.length == 1) {
				resultsTDBottom.removeChild(resultsTDBottom.firstChild);
			}
			resultsTDBottom.appendChild(textNodeBottom);
		},

		showPagingMessage : function() {
			var prevControlsTD = document.getElementById("prevControlsBottom");
			while (prevControlsTD.childNodes.length > 0) {
				prevControlsTD.removeChild(prevControlsTD.firstChild);
			}
			var pagingControlsTD = document.getElementById("pagingControlsBottom");
			while (pagingControlsTD.childNodes.length > 0) {
				pagingControlsTD.removeChild(pagingControlsTD.firstChild);
			}
			var nextControlsTD = document.getElementById("nextControlsBottom");
			while (nextControlsTD.childNodes.length > 0) {
				nextControlsTD.removeChild(nextControlsTD.firstChild);
			}
			
			// build prev link
			if (this.catalogEntriesResultSetCurrentPageNumber > 1) {
				var prevAnchor = document.createElement("a");
				prevAnchor.setAttribute("href", "javascript:filterWithPrevIndex();");
				var textNodePrev = document.createTextNode("Previous");
				prevAnchor.appendChild(textNodePrev);
				prevControlsTD.appendChild(prevAnchor);
			}
			
			// build page number links
			if (this.catalogEntriesResultSetTotalPages > 1) {
				for (i=0; i<this.catalogEntriesResultSetTotalPages; ++i) {
//					if (i > 0) {
//						var textNodePageSeparator = document.createTextNode(" | ");
//						pagingControlsTD.appendChild(textNodePageSeparator);
//					}
					if (i == this.catalogEntriesResultSetCurrentPageNumber-1) {
						var pageLi = document.createElement("li");
						var pageAnchor = document.createElement("a");
						pageAnchor.setAttribute("class", "current");
						pageAnchor.setAttribute("href", "#");
						pageAnchor.style.fontWeight = "bold";
						var textNodePage = document.createTextNode(i+1);
						pagingControlsTD.appendChild(pageLi);
						pageLi.appendChild(pageAnchor);
						pageAnchor.appendChild(textNodePage);
					}
					else {
						var pageLi = document.createElement("li");
						var pageAnchor = document.createElement("a");
						pageAnchor.setAttribute("href", "javascript:filterWithIndex("+(i*this.pageSize)+");");
						var textNodePage = document.createTextNode(i+1);
						pageLi.appendChild(pageAnchor);
						pageAnchor.appendChild(textNodePage);
						pagingControlsTD.appendChild(pageLi);
					}
				}
			}
			
			// build next link
			if (this.catalogEntriesResultSetCurrentPageNumber < this.catalogEntriesResultSetTotalPages) {
				var nextAnchor = document.createElement("a");
				nextAnchor.setAttribute("href", "javascript:filterWithNextIndex();");
				var textNodeNext = document.createTextNode("Next");
				nextAnchor.appendChild(textNodeNext);
				nextControlsTD.appendChild(nextAnchor);
			}
		},

		createViewTypeTD1 : function() {
			var viewTypeTD1 = document.createElement("td");
			viewTypeTD1.setAttribute("id", "viewTypeTD1");
			
			var imageSelected = document.createElement("img");
			imageSelected.setAttribute("id", "imageTypeImageSelected");
			imageSelected.setAttribute("src", this.imagePath + "icon_image_selected.gif");
			imageSelected.setAttribute("border", "0");
			imageSelected.setAttribute("className", "ff_iconimages");
			imageSelected.setAttribute("class", "ff_iconimages");
			
			var detailedTypeLink = document.createElement("a");
			detailedTypeLink.setAttribute("href", "javascript: filterWithView('detailed');");
			detailedTypeLink.setAttribute("id", "detailedTypeLink");
			var detailedTypeImage = document.createElement("img");
			detailedTypeImage.setAttribute("src", this.imagePath + "icon_list.gif");
			detailedTypeImage.setAttribute("border", "0");
			detailedTypeImage.setAttribute("className", "ff_iconimages");
			detailedTypeImage.setAttribute("class", "ff_iconimages");
			detailedTypeLink.appendChild(detailedTypeImage);
			
			viewTypeTD1.appendChild(imageSelected);
			viewTypeTD1.appendChild(detailedTypeLink);
			
			return viewTypeTD1;
		},
		
		createViewTypeTD2 : function() {
			var viewTypeTD2 = document.createElement("td");
			viewTypeTD2.setAttribute("id", "viewTypeTD2");
			
			var detailedSelected = document.createElement("img");
			detailedSelected.setAttribute("id", "detailedTypeImageSelected");
			detailedSelected.setAttribute("src", this.imagePath + "icon_list_selected.gif");
			detailedSelected.setAttribute("border", "0");
			detailedSelected.setAttribute("className", "ff_iconimages");
			detailedSelected.setAttribute("class", "ff_iconimages");
				
			var imageTypeLink = document.createElement("a");
			imageTypeLink.setAttribute("href", "javascript: filterWithView('image');");
			imageTypeLink.setAttribute("id", "imageTypeLink");
			var imageTypeImage = document.createElement("img");
			imageTypeImage.setAttribute("src", this.imagePath + "icon_image.gif");
			imageTypeImage.setAttribute("border", "0");
			imageTypeImage.setAttribute("className", "ff_iconimages");
			imageTypeImage.setAttribute("class", "ff_iconimages");
			imageTypeLink.appendChild(imageTypeImage);
			
			viewTypeTD2.appendChild(imageTypeLink);
			viewTypeTD2.appendChild(detailedSelected);
			
			return viewTypeTD2;		
		},
		
		filterResults : function(type, value, action){
			if (type == 'price') {
				this.filterResultsWithPrice(value);
			}
			else if (type == 'view') {
				this.filterResultsWithView(value);
			}
			else if (type == 'prevIndex') {
				this.filterResultsWithPrevIndex();
			}
			else if (type == 'nextIndex') {
				this.filterResultsWithNextIndex();
			}
			else if (type == 'index') {
				this.filterResultsWithIndex(value);
			}
			else if (type == 'orderBy') {
				this.filterResultsWithOrderBy(value);
			}
			else if (type == 'pageSize') {
				this.filterResultsWithPageSize(value);
			}
			else if (type == 'attributes') {
				this.filterResultsWithAttributes();
			}
			else if (type == 'brand') {
				this.filterResultsWithBrands();
			}
			else if (type == 'features') {
				this.filterResultsWithFeatures();
			}
			
			for (i=0; i<this.filterNames.size(); ++i) {
				var filterValuesForm = document.getElementById("FilterValues"+(i+1)+"Form");
				var filterValuesFormName = filterValuesForm.name;
				var filterValuesFormDiv = document.getElementById(filterValuesFormName+'Div');
				var filterValuesFormHeaderDiv = document.getElementById(filterValuesFormName+'Header');
				var filterValuesFormHeaderText = document.getElementById(filterValuesFormName+'HeaderText');
				var filterValuesFormReset = document.getElementById(filterValuesFormName+'Reset');
				var filterValueElements = filterValuesForm.elements;
				var selectedValue = '';
				var count = 0;
				for (j=0; j<filterValueElements.length; ++j) {
					if (filterValueElements[j].checked) {
						selectedValue = eval('filterValuesForm.filterNameValue'+(j+1)+'.value');
						++count;
					}
				}
				if (selectedValue != '' && count == 1 && filterValueElements.length > 1) {
					// hide the values
					filterValuesFormDiv.style.visibility = 'hidden';
					filterValuesFormDiv.style.display = 'none';
					// change the header color and text
					filterValuesFormHeaderDiv.style.backgroundColor = '#eeece8';
					while (filterValuesFormHeaderText.childNodes.length > 0) {
						filterValuesFormHeaderText.removeChild(filterValuesFormHeaderText.firstChild);
					}
					var headerTextNode = document.createTextNode(selectedValue);
					filterValuesFormHeaderText.appendChild(headerTextNode);
					// make the 'reset' link visible
					filterValuesFormReset.style.visibility = 'visible';
					filterValuesFormReset.style.display = 'block';
				}
				else if (count == filterValueElements.length) {
					// change the header color and text
					filterValuesFormHeaderDiv.style.backgroundColor = '#eeece8';
					while (filterValuesFormHeaderText.childNodes.length > 0) {
						filterValuesFormHeaderText.removeChild(filterValuesFormHeaderText.firstChild);
					}
					var headerTextNode = document.createTextNode(this.filterNames.elementAt(i));
					filterValuesFormHeaderText.appendChild(headerTextNode);
					// make the values visible
					filterValuesFormDiv.style.visibility = 'visible';
					filterValuesFormDiv.style.display = 'block';
					// hide the reset link
					filterValuesFormReset.style.visibility = 'hidden';
					filterValuesFormReset.style.display = 'none';
					filterValuesFormHeaderDiv.style.backgroundColor = '#fff';
				}
			}
			
			this.showResults(action);
		},
		
		filterResultsWithPrice : function(_this){
			values = _this.getCurrentValues();
			this.filterResultsWithPriceRange(values.upper, values.lower);
		},

		filterResultsWithPriceRange : function(upper, lower){
			document.FastFinderForm.maxPrice.value = upper;
			document.FastFinderForm.minPrice.value = lower;
			document.FastFinderForm.initialState.value = "false";
			
//			this.showResults("price");
		},

		filterResultsWithView : function(view){
			document.FastFinderForm.pageView.value = view;
			this.viewType = view;
			document.FastFinderForm.initialState.value = "false";
			
			var viewsTR = document.getElementById("sorts");
			
			var viewTypeTD1 = document.getElementById("viewTypeTD1");
			var viewTypeTD2 = document.getElementById("viewTypeTD2");
			
			if (this.viewType == "image") {
				if (viewTypeTD2 != null) {
					viewsTR.removeChild(viewTypeTD2);
				}
				if (viewTypeTD1 == null) {
					viewTypeTD1 = this.createViewTypeTD1();
				}
				viewsTR.appendChild(viewTypeTD1);
			} else if (this.viewType == "detailed") {
				if (viewTypeTD1 != null) {
					viewsTR.removeChild(viewTypeTD1);
				}
				if (viewTypeTD2 == null) {
					viewTypeTD2 = this.createViewTypeTD2();
				}
				viewsTR.appendChild(viewTypeTD2);
			}
			
//			this.showResults("view");
		},

		filterResultsWithPrevIndex : function(){
			document.FastFinderForm.beginIndex.value = prevIndex;
			beginIndex = prevIndex;
			document.FastFinderForm.initialState.value = "false";
			
//			this.showResults("beginIndex");
		},

		filterResultsWithNextIndex : function(){
			document.FastFinderForm.beginIndex.value = nextIndex;
			beginIndex = nextIndex;
			document.FastFinderForm.initialState.value = "false";
			
//			this.showResults("beginIndex");
		},

		filterResultsWithIndex : function(newIndex){
			document.FastFinderForm.beginIndex.value = newIndex;
			beginIndex = newIndex;
//			nextIndex = newIndex + this.pageSize;
//			prevIndex = newIndex - this.pageSize;
			
			document.FastFinderForm.initialState.value = "false";
			
//			this.showResults("beginIndex");
		},

		filterResultsWithOrderBy : function(orderByNode){
			document.FastFinderForm.orderBy1.value = orderByNode.value;
			document.FastFinderForm.initialState.value = "false";
			
//			this.showResults("orderBy");
		},

		filterResultsWithBrands : function(){
			document.FastFinderForm.initialState.value = "false";
			
//			this.showResults("brand");
		},

		filterResultsWithFeatures : function(){
			document.FastFinderForm.initialState.value = "false";
		
//			this.showResults("features");
		},

		filterResultsWithAttributes : function(){
			document.FastFinderForm.initialState.value = "false";
		
//			this.showResults("filter");
		},

		filterResultsWithPageSize : function(pageSizeNode){
			document.FastFinderForm.itemsPerPage.value = pageSizeNode.value;
			fastFinderJS.pageSize = parseInt(pageSizeNode.value);
			document.FastFinderForm.beginIndex.value = 0;
			beginIndex = 0;
			
			document.FastFinderForm.initialState.value = "false";
			
//			this.showResults("beginIndex");
		},


		add2History : function(actionArray, formArray, url){
			//each entry in the history stack need have unique value. so we need attach a timestamp after each url.
			if(url == null || url =="") {
				fastFinderJS.hashValue = (new Date()).getTime();
				url = "identifier=" + fastFinderJS.hashValue;
			}
			var historyObject = new fastFinderJS.HistoryTracker(actionArray, formArray, url);
			dojo.undo.browser.addToHistory(historyObject);	
		},

		
		HistoryTracker:function(actionArray, formArray, changeUrl){
			// summary: History state object for history tracking
			// description:History state object for history tracking
			// workAreaModeValue: String
			//		the html to be displayed
			// elementId: String
			//		the name of the DOM object
			// changeUrl: String
			//		the url for the current state of this page
			this.actionArray = null;
			this.formArray = null;
			
			this.actionArray = actionArray;
			this.formArray = formArray;

			//TODO: commenting this out breaks FF 1.5. Others? Can't seem to find iframe id/name?
			this.changeUrl =  changeUrl;
		},

		processBookmarkURL : function(){
		// summary: This function is for handling bookmarked urls
		// Description: If there is bookmark information in the url, extract the url after #. 
		//              update context for MyAccountCenterLinkDisplay_Context with the bookmarked url.
					 
			var bookmarkId = location.hash;	
			if(bookmarkId){					        
				bookmarkId = bookmarkId.substring(1, bookmarkId.length);
			}   
			if(bookmarkId){
				//to do the best is to make several var for the urls
				//and then each time add to history, just add in the workareamode
				//later have a function called sth, it will say if this is the mode, then url = this
				//if that mode, url = that
				//and then call load context from url.
				//the benifit of this is that even this is page is load from bookmark id, 
				//we still can have the correct mode for it.
			   
					var indexOfIdentifier = bookmarkId.indexOf("identifier", 0);
					if ( indexOfIdentifier >= 0) {
						var realUrl = bookmarkId.substring(0, indexOfIdentifier - 1);
				}
			}

			if(bookmarkId == null || bookmarkId == ""){
				//Do something here
			}
		},

		
		goBack:function(){
		// summary: this function belong to HistoryTracking for receiving Back notifications
		// description: this function belong to HistoryTracking for receiving Back notifications	
			if(this.formArray != null){
				//Load the forms
				for(formIndex in this.formArray){
					var formObject = this.formArray[formIndex];
					document[formObject.form][formObject.formElementName][formObject.formElementProperty] = formObject.formElementPropertyValue;
				}
			}

			if(this.actionArray != null){
				//Call all the functions
				for(actionIndex in this.actionArray){
					var actionObject = this.actionArray[actionIndex];
					var func = actionObject.action;
					func.apply(actionObject.actionNameSpace, actionObject.actionParameter);
				}
			}
		},
			
		goForward:function(){
		// summary: this function belong to HistoryTracking for receiving forward notifications
		// description:this function belong to HistoryTracking for receiving forward notifications	
			if(this.formArray != null){
				//Load the forms
				for(formIndex in this.formArray){
					var formObject = this.formArray[formIndex];

					document[formObject.form][formObject.formElementName][formObject.formElementProperty] = formObject.formElementPropertyValue;
				}
			}

			if(this.actionArray != null){
				//Call all the functions
				for(actionIndex in this.actionArray){
					var actionObject = this.actionArray[actionIndex];
					var func = actionObject.action;
					func.apply(actionObject.actionNameSpace, actionObject.actionParameter);
				}
			}
		},
			

		initFastFinderHistory : function(){
			//each entry in the history stack need have unique hashcode value. so we need attach a timestamp after each url.
			var params = [];
			var actionArray = [];
			var formArray = [];
			var url = "identifier=" + (new Date()).getTime();

			var widget = dojo.widget.byId('fastFinderRangeSlider');
			params.push(widget.firstHandle);
			params.push(parseFloat(document.FastFinderForm.minPrice.value));
			actionArray = fastFinderJS.addAction(actionArray, widget.setUnitPosition, widget, params);

			params = [];
			params.push(widget.secondHandle);
			params.push(parseFloat(document.FastFinderForm.maxPrice.value));
			actionArray = fastFinderJS.addAction(actionArray, widget.setUnitPosition, widget, params);

			params = [];
			params.push("price");
			params.push(widget);
			params.push("price");
			actionArray = fastFinderJS.addAction(actionArray, fastFinderJS.filterResults, fastFinderJS, params);

			params = [];
			params.push("pageSize");
			params.push(document.ItemsPerPageForm.itemsPerPage);
			params.push("beginIndex");
			actionArray = fastFinderJS.addAction(actionArray, fastFinderJS.filterResults, fastFinderJS, params);

			params = [];
			params.push("");
			params.push("");
			params.push("");
			actionArray = fastFinderJS.addAction(actionArray, fastFinderJS.filterResults, fastFinderJS, params);

			formArray = fastFinderJS.getFormArray(formArray, "FastFinderForm");
			formArray = fastFinderJS.getFormArray(formArray, "SortResultForm");
			formArray = fastFinderJS.getFormArray(formArray, "ItemsPerPageForm");
			for (i=0; i<fastFinderJS.filterNames.size(); ++i) {
				formArray = fastFinderJS.getFormArray(formArray, "FilterValues" + (i+1) + "Form");
			}

			var historyObject = new fastFinderJS.HistoryTracker(actionArray, formArray, url);
			dojo.undo.browser.setInitialState(historyObject);
		},

		initFastFinderForms : function(){
			var cookies=document.cookie;
			var ind=cookies.indexOf('HOMFastFinder');
			if (ind != -1) {
				var ind1=cookies.indexOf('=',ind);
				var ind2=cookies.indexOf(';',ind1);
				if (ind2==-1) ind2=cookies.length;
				var cookieValue = unescape(cookies.substring(ind1+1,ind2));
				//alert('cookie value = ' + cookieValue);
				
				// get timestamp value
				ind1 = cookieValue.indexOf('timestamp_');
				ind2 = cookieValue.length;
				var timestampValue = cookieValue.substring(ind1+10,ind2);
				var hashValue = location.hash.substring(location.hash.indexOf("identifier=")+11);
				//alert('timestamp value = ' + timestampValue + ', hashValue = ' + hashValue);
				if (hashValue != '' && timestampValue == hashValue) {
					document.FastFinderForm.initialState.value = 'false';
					fastFinderJS.hashValue = hashValue;
					this.initFastFinderHistory();

					// init filter checkboxes
					for (i=0; i<this.filterNames.size(); ++i) {
						var filterValuesForm = document.getElementById("FilterValues"+(i+1)+"Form");
						var filterValueCheckboxes = filterValuesForm.getElementsByTagName("input");
						for (j=0; j<filterValueCheckboxes.length; ++j) {
							filterValueCheckboxes[j].checked = true;
						}
					}
					// get filter names
					ind1 = cookieValue.indexOf('filterNames_');
					if (ind1 != -1) {
						ind2 = cookieValue.indexOf('&',ind1);
						var filterNames = cookieValue.substring(ind1+12,ind2);
						ind1 = 0;
						ind2 = 0;
						while (ind1 < filterNames.length) {
							ind2 = filterNames.indexOf('|',ind1);
							var filterIndex = filterNames.substring(ind1,ind2);
							var filterFormNumber = filterIndex.substring(0,filterIndex.indexOf('.'));
							var filterValuesForm = document.getElementById("FilterValues"+filterFormNumber+"Form");
							var filterValueCheckboxes = filterValuesForm.getElementsByTagName("input");
							for (i=0; i<filterValueCheckboxes.length; ++i) {
								filterValueCheckboxes[i].checked = false;
							}
							var filterCheckboxNumber = filterIndex.substring(filterIndex.indexOf('.')+1);
							var filter = document.getElementById("filter" + filterFormNumber + filterCheckboxNumber);
							filter.checked = true;
							ind1 = ind2+1;
						}
					}

					// get sort by value
					ind1 = cookieValue.indexOf('orderBy1_');
					ind2 = cookieValue.indexOf('&',ind1);
					var orderBy1Value = cookieValue.substring(ind1+9,ind2);
					//alert('orderBy1 value = ' + orderBy1Value);
					document.FastFinderForm.orderBy1.value = orderBy1Value;
					document.SortResultForm.orderBy1.value = orderBy1Value;

					// get items per page value
					ind1 = cookieValue.indexOf('itemsPerPage_');
					ind2 = cookieValue.indexOf('&',ind1);
					var itemsPerPageValue = cookieValue.substring(ind1+13,ind2);
					//alert('itemsPerPage value = ' + itemsPerPageValue);
					document.FastFinderForm.itemsPerPage.value = itemsPerPageValue;
					document.ItemsPerPageForm.itemsPerPage.value = itemsPerPageValue;

					// get beginning index value
					ind1 = cookieValue.indexOf('beginIndex_');
					ind2 = cookieValue.indexOf('&',ind1);
					var beginIndexValue = cookieValue.substring(ind1+11,ind2);
					//alert('beginIndex value = ' + beginIndexValue);
					document.FastFinderForm.beginIndex.value = beginIndexValue;

					// get min price value
					ind1 = cookieValue.indexOf('minPrice_');
					ind2 = cookieValue.indexOf('&',ind1);
					var minPriceValue = cookieValue.substring(ind1+9,ind2);
					//alert('minPrice value = ' + minPriceValue);
					document.FastFinderForm.minPrice.value = minPriceValue;

					// get max price value
					ind1 = cookieValue.indexOf('maxPrice_');
					ind2 = cookieValue.indexOf('&',ind1);
					var maxPriceValue = cookieValue.substring(ind1+9,ind2);
					//alert('maxPrice value = ' + maxPriceValue);
					document.FastFinderForm.maxPrice.value = maxPriceValue;
					var range = parseFloat(maxPriceValue) - parseFloat(minPriceValue);
					
					var widget = dojo.widget.byId('fastFinderRangeSlider');
					widget.setUnitPosition(widget.firstHandle, minPriceValue);
					widget.setUnitPosition(widget.secondHandle, maxPriceValue);
				}
				else {
					this.initFastFinderHistory();
				}
			}
			else {
				this.initFastFinderHistory();
			}
			
			for (i=0; i<fastFinderJS.filterNames.size(); ++i) {
				var filterValuesForm = document.getElementById("FilterValues"+(i+1)+"Form");
				var filterValuesFormName = filterValuesForm.name;
				var filterValuesFormDiv = document.getElementById(filterValuesFormName+'Div');
				var filterValuesFormHeaderDiv = document.getElementById(filterValuesFormName+'Header');
				var filterValuesFormHeaderText = document.getElementById(filterValuesFormName+'HeaderText');
				var filterValuesFormReset = document.getElementById(filterValuesFormName+'Reset');
				var filterValueElements = filterValuesForm.elements;
				var selectedValue = '';
				var count = 0;
				for (j=0; j<filterValueElements.length; ++j) {
					if (filterValueElements[j].checked) {
						selectedValue = eval('filterValuesForm.filterNameValue'+(j+1)+'.value');
						++count;
					}
				}
				if (selectedValue != '' && count == 1 && filterValueElements.length > 1) {
					// hide the values
					filterValuesFormDiv.style.visibility = 'hidden';
					filterValuesFormDiv.style.display = 'none';
					// change the header color and text
					filterValuesFormHeaderDiv.style.backgroundColor = '#eeece8';
					while (filterValuesFormHeaderText.childNodes.length > 0) {
						filterValuesFormHeaderText.removeChild(filterValuesFormHeaderText.firstChild);
					}
					var headerTextNode = document.createTextNode(selectedValue);
					filterValuesFormHeaderText.appendChild(headerTextNode);
					// make the 'reset' link visible
					filterValuesFormReset.style.visibility = 'visible';
					filterValuesFormReset.style.display = 'block';
				}
			}
			beginIndex = parseInt(document.FastFinderForm.beginIndex.value);
			fastFinderJS.beginIndex = parseInt(document.FastFinderForm.beginIndex.value);
			fastFinderJS.pageSize = parseInt(document.FastFinderForm.itemsPerPage.value);
			
		},

		
		addAction : function (actionArray, newAction, newActionNameSpace, newActionParameter){
			var actionObject = new Object();
			actionObject["action"] = newAction;
			actionObject["actionNameSpace"] = newActionNameSpace;
			actionObject["actionParameter"] = newActionParameter;
			actionArray.push(actionObject);

			return actionArray;
		},

		addForm : function (formArray, newFormName, newElementName, newElementProperty, newElementPropertyValue){
			var formObject = new Object();
			formObject["form"] = newFormName;
			formObject["formElementName"] = newElementName;
			formObject["formElementProperty"] = newElementProperty;
			formObject["formElementPropertyValue"] = newElementPropertyValue;

			formArray.push(formObject);
			return formArray;
		},

		getFormArray : function(formArray, formName){
			if(!formArray)
				formArray = [];
			var formNode = document.forms[formName];
			
			for(var i = 0; i < formNode.elements.length; i++){
				var element = formNode.elements[i];
				if(!element || element.tagName.toLowerCase() == "fieldset") { continue; }
				
				var name = element.name;
				var type = element.type.toLowerCase();

				if(type == "select-multiple"){
					for(var j = 0; j < element.options.length; j++){
						if(element.options[j].selected) {
							//this.addForm(formArray, formName, name, "selected", newElementPropertyValue)
							//values.push(name + "=" + enc(formNode.options[j].value));
						}
						this.addForm(formArray, formName, name, "selectedIndex", element.selectedIndex);
					}
				}else if(dojo.lang.inArray(["radio", "checkbox"], type)){
					//if(formNode.checked){
						//values.push(name + "=" + enc(formNode.value));
					//}
					this.addForm(formArray, formName, name, "checked", element.checked);
				}else{
					//values.push(name + "=" + enc(formNode.value));
					this.addForm(formArray, formName, name, "value", element.value);
				}
			}
			return formArray;
		},
		
		onLoad : function(){
			fastFinderJS.initFastFinderForms();
			fastFinderJS.showResults();
		}
	}
		

	fastFinderJS.HistoryTracker.prototype.back		=	fastFinderJS.goBack;
	fastFinderJS.HistoryTracker.prototype.forward	=	fastFinderJS.goForward;
	
//	function onLoad(){
//		fastFinderJS.initFastFinderHistory();
//		fastFinderJS.initFastFinderForms();
//		fastFinderJS.showResults();
//	}

//	dojo.addOnLoad(onLoad);
