	function getProductPage(brandName, categoryId, startIndex, count, productContext)
	{
			//assignError("", errorContainer);
			document.body.style.cursor = 'wait';

			new Ajax.Request("" + "/consumer/brands/getProductPage.do", {
				asynchronous: true,
				method: "get",
				parameters: "brandName=" + brandName + "&categoryId=" + categoryId + "&startIndex=" + startIndex + "&count=" + count,
				onSuccess: function(request) {
					crawlXML(request.responseXML.documentElement, count, brandName, productContext);
				},
				onFailure: function(request) {
					alert(request.statusText);
					alert("We're currently experiencing technical problems on this website; please try again later. We apologize for any inconvenience.");
				},
				onComplete: function(request) {
						document.body.style.cursor = 'default'
				}
			});
	}

	function crawlXML(doc, pageSize, brandName, productContext)
	{
		//Check if we got any products back from AJAX call
		if(doc.hasChildNodes())
		{
			//Get all product elements
			var products = doc.getElementsByTagName("product");
			var productCount = 0;
			var productTitle = "";

			//Loop through each product
			for (i=0; i<products.length; i++)
			{
				var product = products[i];

				//Loop through each element in the product
				for (j=0; j<product.childNodes.length; j++)
				{
					//Set the product row back to block style in the event that the previous link was clicked and the row was
					//hidden from a next link.
					document.getElementById("row-" + productContext + (i+1)).style.display = 'block';

					var productElement = product.childNodes[j];

					//Reset the appropriate span to the product value.
					if (productElement.nodeName == "title")
					{
						document.getElementById("title-" + productContext + (i+1)).innerHTML = productElement.childNodes[0].nodeValue;
						var nodeValue = productElement.childNodes[0].nodeValue;
						document.getElementById("title-" + productContext + (i+1) + "hidden").value = nodeValue.replace(/&eacute;/, "é");

						//Save off product title so we can use it in an alt tag.
						productTitle = productElement.childNodes[0].nodeValue;
					}

					else if (productElement.nodeName == "upc")
					{
						var selectedBrand = document.getElementById("selectedBrand").value;
						var imageURL = document.getElementById("imageURL").value;
						//document.getElementById("nutrition-" + productContext + (i+1)).style.display="block";

						var onErrorEvent = "this.onerror=null; this.src='/images/brands/brand_info/no_image/" + selectedBrand + ".jpg';";
						document.getElementById("image-" + productContext + (i+1)).innerHTML = '<img id="productImage" onerror="' + onErrorEvent + '" src="' + imageURL + '/' + productElement.childNodes[0].nodeValue + '.jpg" alt="' + productTitle + '"/>';

					 	document.getElementById("currentUpc-" + productContext + (i+1)).value = productElement.childNodes[0].nodeValue;
					}

					else if (productElement.nodeName == "description")
					{
						document.getElementById("description-" + productContext + (i+1)).innerHTML = productElement.childNodes[0].nodeValue;
					}

					else if (productElement.nodeName == "showNutrition")
					{
						var nodeValue = productElement.childNodes[0].nodeValue;
						if (nodeValue == "true")
							document.getElementById("nutrition-" + productContext + (i+1)).style.display="block";
						else
							document.getElementById("nutrition-" + productContext + (i+1)).style.display="none";
					}

					else if (productElement.nodeName == "showStoreLocator")
					{
						var nodeValue = productElement.childNodes[0].nodeValue;
						if (nodeValue == "true")
							document.getElementById("storelocator-" + productContext + (i+1)).style.display="block";
						else
							document.getElementById("storelocator-" + productContext + (i+1)).style.display="none";
					}

				}
				productCount++;
			}

			//If we have more rows than we do products, hide the extra rows. This can happen
			//when a next link is clicked and the next page doesn't contain a full page worth of products
			for (i = pageSize; i>productCount; i--)
			{
				if (document.getElementById("row-" + productContext + i) != null)
					document.getElementById("row-" + productContext + i).style.display = 'none';
			}

			var startIndex = document.getElementById("startIndex-" + productContext).innerHTML;
			var endIndex = document.getElementById("endIndex-" + productContext).innerHTML;
			var totalCount = document.getElementById("totalCount-" + productContext).innerHTML;

			//Check if the previous, next, or show all link was clicked
			if (parseInt(pageSize) == parseInt(totalCount))
			{
				//Show all was clicked, update the page indexes
				document.getElementById("startIndex-" + productContext).innerHTML = 1;
				document.getElementById("endIndex-" + productContext).innerHTML = parseInt(totalCount);
				document.getElementById("startIndexBot-" + productContext).innerHTML = parseInt(startIndex);
				document.getElementById("endIndexBot-" + productContext).innerHTML = parseInt(totalCount);

				//Disable the previous, next, and show all links
				document.getElementById("nextLink-" + productContext).style.display = 'none';
				document.getElementById("next-" + productContext).style.display = 'inline';
				document.getElementById("nextLinkBot-" + productContext).style.display = 'none';
				document.getElementById("nextBot-" + productContext).style.display = 'inline';
				document.getElementById("previousLink-" + productContext).style.display = 'none';
				document.getElementById("previous-" + productContext).style.display = 'inline';
				document.getElementById("previousLinkBot-" + productContext).style.display = 'none';
				document.getElementById("previousBot-" + productContext).style.display = 'inline';
				document.getElementById("showAllLink-" + productContext).style.display = 'none';
				document.getElementById("showAll-" + productContext).style.display = 'inline';
				document.getElementById("showAllLinkBot-" + productContext).style.display = 'none';
				document.getElementById("showAllBot-" + productContext).style.display = 'inline';


			}
			else if (parseInt(pageSize) > 0)
			{
				//Update the page indexes
				document.getElementById("startIndex-" + productContext).innerHTML = parseInt(startIndex) + parseInt(pageSize);
				document.getElementById("endIndex-" + productContext).innerHTML = parseInt(endIndex) + parseInt(productCount);
				document.getElementById("startIndexBot-" + productContext).innerHTML = parseInt(startIndex) + parseInt(pageSize);
				document.getElementById("endIndexBot-" + productContext).innerHTML = parseInt(endIndex) + parseInt(productCount);

				//Determine if we should disable/enable the next link
				//alert(parseInt(totalCount) == (parseInt(endIndex) + parseInt(productCount)));
				if (parseInt(totalCount) == (parseInt(endIndex) + parseInt(productCount)))
				{
					document.getElementById("nextLink-" + productContext).style.display = 'none';
					document.getElementById("next-" + productContext).style.display = 'inline';
					document.getElementById("nextLinkBot-" + productContext).style.display = 'none';
					document.getElementById("nextBot-" + productContext).style.display = 'inline';
				}
				else
				{
					document.getElementById("nextLink-" + productContext).style.display = 'inline';
					document.getElementById("next-" + productContext).style.display = 'none';
					document.getElementById("nextLinkBot-" + productContext).style.display = 'inline';
					document.getElementById("nextBot-" + productContext).style.display = 'none';

				}

				//Enable the previous link
				document.getElementById("previousLink-" + productContext).style.display = 'inline';
				document.getElementById("previous-" + productContext).style.display = 'none';
				document.getElementById("previousLinkBot-" + productContext).style.display = 'inline';
				document.getElementById("previousBot-" + productContext).style.display = 'none';
			}
			else
			{
				//Update the page indexes
				document.getElementById("startIndex-" + productContext).innerHTML = parseInt(startIndex) + parseInt(pageSize);
				document.getElementById("startIndexBot-" + productContext).innerHTML = parseInt(startIndex) + parseInt(pageSize);

				//End index is the starting index plus the page size (-1)
				document.getElementById("endIndex-" + productContext).innerHTML = parseInt(startIndex) + parseInt(pageSize) + ((parseInt(pageSize) * -1) - 1);
				document.getElementById("endIndexBot-" + productContext).innerHTML = parseInt(startIndex) + parseInt(pageSize) + ((parseInt(pageSize) * -1) - 1);

				//Determine if we should disable/enable the previous link
				if ((parseInt(startIndex) + parseInt(pageSize)) == 1)
				{
					document.getElementById("previousLink-" + productContext).style.display = 'none';
					document.getElementById("previous-" + productContext).style.display = 'inline';
					document.getElementById("previousLinkBot-" + productContext).style.display = 'none';
					document.getElementById("previousBot-" + productContext).style.display = 'inline';
				}
				else
				{
					document.getElementById("previousLink-" + productContext).style.display = 'inline';
					document.getElementById("previous-" + productContext).style.display = 'none';
					document.getElementById("previousLinkBot-" + productContext).style.display = 'inline';
					document.getElementById("previousBot-" + productContext).style.display = 'none';
				}

				//Enable the previous link
				document.getElementById("nextLink-" + productContext).style.display = 'inline';
				document.getElementById("next-" + productContext).style.display = 'none';
				document.getElementById("nextLinkBot-" + productContext).style.display = 'inline';
				document.getElementById("nextBot-" + productContext).style.display = 'none';
			}
	  }
}


	function displayStoreLocatorFields(event, categoryId, productId, productTitle)
	{
			document.body.style.cursor = 'wait';
			var brandId = document.getElementById("selectedBrandDbId").value;
			//var product = document.getElementById(productId + "hidden").value;
			var state = document.getElementById("state").value;
			var city = document.getElementById("city").value;

			getBrandsForCategoryOverride(categoryId, brandId, 'ajaxError', "false");
			getProductsForBrandOverride(brandId, categoryId, productId, productTitle, 'ajaxError', "false");
			//getCategoriesOverride(categoryId, 'ajaxError',"false");

			if (state != null && state != "" && city != null && city != "")
			{
				getStatesOverride(state, 'ajaxError', "false");
				getCitiesForStateOverride(city, state, 'ajaxError', "false");
			}
			else
			{
				getStatesOverride("", 'ajaxError', "false");
			}


			//selectOption(document.getElementById('categorySelect'), category);
			//selectOption(document.getElementById('brandSelect'), brand);

			if(document.body.scrollTop == 0)
	 			$('storeLocatorDiv').style.top = screen.availHeight/5 + document.body.scrollTop + 20;
	 		else
	 			$('storeLocatorDiv').style.top = screen.availHeight/5 + document.body.scrollTop

		  $('storeLocatorDiv').style.left = screen.availWidth/4 + "px";

		  new Effect.Appear('storeLocatorDiv');
		  document.body.style.cursor = 'default';

	}

	//Overrode function in searchFormJavaScriptInclude.jsp so that we can control when the drop down selects an item
	function getBrandsForCategoryOverride(category, brandId, errorContainer, showProgress) {
		var parms = "category" + "=" + category;
		retrieveSelectContent(
			parms, "/consumer/storelocator/getBrandIdsForCategory.jsp",
			function(request) {
					var doc = request.responseXML.documentElement;
					if(doc.hasChildNodes())
					{
						var brandSelect = document.getElementById('brandSelect')
						//Get all filtered elements
						var brands = doc.getElementsByTagName("brand");

						brandSelect.options.length = 1;
						brandSelect.options[0].value = "-1";
						brandSelect.options[0].text = 'Brand';

						//Loop through each item
						for (i=1; i<=brands.length; i++)
						{
							brandSelect.options.length = i + 1;

							var brand = brands[i-1];

							//Loop through each element in the brand
							for (j=0; j<brand.childNodes.length; j++)
							{

								var brandElement = brand.childNodes[j];

								if (brandElement.nodeName == "id")
								{
									brandSelect.options[i].value = brandElement.childNodes[0].nodeValue;
								}

								else if (brandElement.nodeName == "name")
								{
									brandSelect.options[i].text = brandElement.childNodes[0].nodeValue;
								}
							}
						}
					}
					selectOption(document.getElementById('brandSelect'), brandId);
			},
			errorContainer,
			"brandProgress",
			showProgress);
	}

	//Overrode function in searchFormJavaScriptInclude.jsp so that we can control when the drop down selects an item
	function getProductsForBrandOverride(brandId, categoryId, upc, productTitle, errorContainer, showProgress)
	{
      var parms = "brand" + "=" + brandId + "&category=" + categoryId;
			retrieveSelectContent(
				parms, "/consumer/storelocator/getProductsForBrandById.jsp",
				function(request)
				{
					productSelect = document.getElementById("productSelect");

					productSelect = document.getElementById("productSelect");
					productSelect.disabled=false;

					var doc = request.responseXML.documentElement;
					if(doc.hasChildNodes())
					{
						//Get all filtered elements
						var products = doc.getElementsByTagName("product");

						productSelect.options.length = 1;
						productSelect.options[0].value = "-1";
						productSelect.options[0].text = 'Product';

						//Loop through each item
						for (i=1; i<=products.length; i++)
						{
							productSelect.options.length = i + 1;

							var product = products[i-1];

							//Loop through each element in the product
							for (j=0; j<product.childNodes.length; j++)
							{

								var productElement = product.childNodes[j];

								if (productElement.nodeName == "upc")
								{
									productSelect.options[i].value = productElement.childNodes[0].nodeValue;
								}

								else if (productElement.nodeName == "name")
								{
									productSelect.options[i].text = productElement.childNodes[0].nodeValue;
								}
							}
						}
					}
					selectProductOption(productSelect, upc, productTitle);
				},
				errorContainer,
				"productProgress",
				showProgress);
	}

	//Overrode function in searchFormJavaScriptInclude.jsp so that we can control when the drop down selects an item
	function getCitiesForStateOverride(city, state, errorContainer, showProgress) {
		var parms = "state" + "=" + state;
		retrieveSelectContent(
			parms, "/consumer/storelocator/getCitiesForState.jsp",
			function(request) {
				citySelect = document.getElementById("citySelect");
				citySelect.disabled=false;

				assignCities(request.responseText);
				selectOption(document.getElementById('citySelect'), city);
			},
			errorContainer,
			"cityProgress",
			showProgress);
	}


	function getCategoriesOverride(categoryId, errorContainer, showProgress)
	{
			retrieveSelectContent(
				"", "/consumer/storelocator/getCategoryIds.jsp",
				function(request)
				{
					categorySelect = document.getElementById("categorySelect");

					var doc = request.responseXML.documentElement;
					if(doc.hasChildNodes())
					{
						//Get all filtered elements
						var categories = doc.getElementsByTagName("category");

						categorySelect.options.length = 1;
						categorySelect.options[0].value = "-1";
						categorySelect.options[0].text = 'Category';

						//Loop through each item
						for (i=1; i<=categories.length; i++)
						{
							categorySelect.options.length = i + 1;

							var category = categories[i-1];

							//Loop through each element in the category
							for (j=0; j<category.childNodes.length; j++)
							{

								var categoryElement = category.childNodes[j];

								if (categoryElement.nodeName == "id")
								{
									categorySelect.options[i].value = categoryElement.childNodes[0].nodeValue;
								}

								else if (categoryElement.nodeName == "name")
								{
									categorySelect.options[i].text = categoryElement.childNodes[0].nodeValue;
								}
							}
						}
					}

					selectOption(categorySelect, categoryId);
				},
				errorContainer,
				"categoryProgress",
				showProgress);
	}

	function getStatesOverride(selectedState, errorContainer, showProgress)
	{
		retrieveSelectContent(
			"", "/consumer/storelocator/getStates.jsp",
			function(request)
			{
				stateSelect = document.getElementById("stateSelect");
				var doc = request.responseXML.documentElement;

				//Check if we got any products back from AJAX call
				if(doc.hasChildNodes())
				{
					//Get all product elements
					var states = doc.getElementsByTagName("state");

					stateSelect.options.length = 1;
					stateSelect.options[0].value = "";
					stateSelect.options[0].text = 'State';

					//Loop through each state
					for (i=1; i<states.length; i++)
					{
						var state = states[i];
						var stateCode = state.childNodes[0].childNodes[0].nodeValue;
						var stateName = state.childNodes[1].childNodes[0].nodeValue;

						stateSelect.options.length = i + 1;
						stateSelect.options[i].value = stateCode;
						stateSelect.options[i].text = stateName;
					}
				}
				selectOption(document.getElementById('stateSelect'), selectedState);
			},
			errorContainer,
			"stateProgress",
			showProgress);
	}

	function selectOption(selectField, selectedValue)
	{
		var options = selectField.options;
		for (i=0; i<options.length; i++)
		{
			if (options[i].value == selectedValue)
			{
				options[i].selected = true;
			}
		}
	}


	function selectProductOption(productField, upc, title)
	{
		var options = productField.options;
		for (i=0; i<options.length; i++)
		{
			if (options[i].value == upc)
			{
				options[i].selected = true;
				return;
			}
		}

		for (i=0; i<options.length; i++)
		{
			if (options[i].text == title)
			{
				options[i].selected = true;
				return;
			}
		}
	}

