	var CurrentGenreId;
	var PriceMatrix = false;
	var TIMEOUT_DELAY = 2500;
	var CurrProductGroupId = '';
	var CurrPriceRange = '';
	var CurrHoutDikteId = '';
	var CurrDepthRange = '';
	var CurrWidthRange = '';

	function InvokeFormAction(formValue, actionValue)
	{
		document.forms[formValue].action += actionValue;
		document.forms[formValue].submit();
	}
	function InvokeAction(value)
	{
		document.forms[0].action += value;
		document.forms[0].submit();
	}
	function AmountChanged(value)
	{
		if (value != null)
			PriceMatrix = true;
	}
	function InvokePriceMatrix()
	{
		if (PriceMatrix)
			InvokeFormAction('Product','AddToCart');
			//document.forms[1].submit();
		else
			alert('Om te bestellen dient u het aantal op te geven in de prijzen matrix');
	}
	function DecreaseQuantity(Seqno)
	{
	    document.forms['ShoppingCart']['Quantity_' + Seqno].value = parseInt(document.forms['ShoppingCart']['Quantity_' + Seqno].value) - 1;

		var re = new RegExp(/^[0-9]+$/);
		if (document.forms['ShoppingCart']['Quantity_' + Seqno].value < 1 || !re.test(document.forms['ShoppingCart']['Quantity_' + Seqno].value))
		{
		    document.forms['ShoppingCart']['Quantity_' + Seqno].value = 1;
		}
	}

	function IncreaseQuantity(Seqno)
	{
	    document.forms['ShoppingCart']['Quantity_' + Seqno].value = parseInt(document.forms['ShoppingCart']['Quantity_' + Seqno].value) + 1;

		var re = new RegExp(/^[0-9]+$/);
		if (document.forms['ShoppingCart']['Quantity_' + Seqno].value < 1 || !re.test(document.forms['ShoppingCart']['Quantity_' + Seqno].value))
		{
		    document.forms['ShoppingCart']['Quantity_' + Seqno].value = 1;
		}
	}
	function CartRemoveItem(i)
	{
	    InvokeFormAction('ShoppingCart', 'Delete&Seqno=' + i);
	}

	function ShowTellAFriendForm()
	{
		document.getElementById('TellAFriendForm').style.display = 'block';
		//document.getElementById('TellAFriendButton').style.display = 'none';
	}
	function TellAFriend(ProductId)
	{
		document.forms['Product'].action = 'Pages/Products/ViewProduct.asp?ShopProductId=' + ProductId + '&Action=TellAFriend';
		document.forms['Product'].submit();
	}


	function ShowGenreItems(elementId)
	{
		if (document.getElementById('GenreItems_' + elementId).style.display != 'block')
			document.getElementById('GenreItems_' + elementId).style.display = 'block';

		var myQuery = new QueryString();
		myQuery.read();

		if (myQuery.getStatus())
		{
			var aQueryData = myQuery.getAll();
			if (elementId != aQueryData['ShopGenreId'] && aQueryData['ShopGenreId'] != null)
				document.getElementById('GenreItems_' + aQueryData['ShopGenreId']).style.display = 'none';
		}
		if (CurrentGenreId != null)
		{
			if (elementId != CurrentGenreId)
				document.getElementById('GenreItems_' + CurrentGenreId).style.display = 'none';
		}

	}
	function HideGenreItems(elementId)
	{
		if (document.getElementById('GenreItems_' + elementId).style.display != 'none')
			document.getElementById('GenreItems_' + elementId).style.display = 'none';

		if (CurrentGenreId == null)
		{
			var myQuery = new QueryString();
			myQuery.read();

			if (myQuery.getStatus())
			{
				var aQueryData = myQuery.getAll();
				if (aQueryData['ShopGenreId'] != null)
					document.getElementById('GenreItems_' + aQueryData['ShopGenreId']).style.display = 'block';
			}
		}
		else
		{
			document.getElementById('GenreItems_' + CurrentGenreId).style.display = 'block';
		}

	}
	function SetGenre(genreId)
	{
		CurrentGenreId = genreId;
	}
	function LoadProducts(genreId, categoryId, htmlOutputId, loadCategory)
	{
		if (genreId != null && categoryId != null)
		{
			document.getElementById(htmlOutputId).innerHTML = '<img src="Images/ajax-loader.gif" alt="loader" />';
			$("#" + htmlOutputId).load("Classes/Ajax/Products.asp?ShopGenreId=" + genreId + '&ShopCategoryId=' + categoryId);
			//dhtmlHistory.add('Products' + genreId + '&' + categoryId, 'link');
			document.getElementById('OutputAccessoires').innerHTML = "";
			this.LoadProductFilter();
		}
		else
		{
			document.getElementById(htmlOutputId).innerHTML = "Er is geen categorie geselecteerd";
		}
		if (loadCategory)
		{
			this.LoadCategoryName(categoryId, 'CategoryNameHolder');
		}
		document.getElementById('OutputAccessoires').innerHTML = "";

	}
	function LoadProductsWithParams(genreId, categoryId, ProductGroupId, HoutDikteId, PriceRange, htmlOutputId, SortBy, SortOrder, Page)
	{
		if (genreId != null && categoryId != null)
		{
			$("#" + htmlOutputId).html('<img src="Images/ajax-loader.gif" alt="loader" />').load("Classes/Ajax/Products.asp?ShopGenreId=" + genreId + '&ShopCategoryId=' + categoryId + '&ProductGroupId=' + ProductGroupId + '&PriceRange=' + PriceRange + '&HoutDikteId=' + HoutDikteId + '&SortBy=' + SortBy + '&SortOrder=' + SortOrder + '&Page=' + Page);
		}
		else
		{
			document.getElementById('OutputAccessoires').innerHTML = "Er is geen categorie geselecteerd";
		}
    }
    function LoadSearchWithParams(SearchTerms, htmlOutputId, SortBy, SortOrder, Page) {
        $("#" + htmlOutputId).html('<img src="Images/ajax-loader.gif" alt="loader" />').load("Classes/Ajax/SearchProducts.asp?SearchTerms=" + SearchTerms + '&SortBy=' + SortBy + '&SortOrder=' + SortOrder + '&Page=' + Page);
    }

	function FilterProducts(productGroupId, priceRange, HoutDikteId, DepthRange, WidthRange)
	{
		$('.woodFilter').each(function () {
			$(this).removeClass('selectedFilter');
		});

		$('.priceFilter').each(function () {
			$(this).removeClass('selectedFilter');
		});

		$('.typeFilter').each(function () {
			$(this).removeClass('selectedFilter');
		});

		$('.widthFilter').each(function () {
			$(this).removeClass('selectedFilter');
		});
		
		$('.depthFilter').each(function () {
			$(this).removeClass('selectedFilter');
		});
				
		if (productGroupId != '') {
			CurrProductGroupId = productGroupId;
		}
		if (CurrProductGroupId != '') {
			$('#typeFilter_' + CurrProductGroupId).addClass('selectedFilter');
		}
		if (productGroupId == 'clear') { CurrProductGroupId = 'clear'; }

		if (priceRange != '') {
			CurrPriceRange = priceRange;
		}
		if (CurrPriceRange != '') {
			$('#priceFilter_' + CurrPriceRange).addClass('selectedFilter');
		}
		if (priceRange == 'clear') { CurrPriceRange = 'clear'; }

		if (HoutDikteId != '') {
			CurrHoutDikteId = HoutDikteId;
		}
		if (CurrHoutDikteId != '') {
			$('#woodFilter_' + CurrHoutDikteId).addClass('selectedFilter');
		}
		if (HoutDikteId == 'clear') { CurrHoutDikteId = 'clear'; }

		if (DepthRange != '') {
			CurrDepthRange = DepthRange;
			}
		if (CurrDepthRange != '') {
			$('#depthFilter_' + CurrDepthRange).addClass('selectedFilter');
		}
		if (DepthRange == 'clear') { CurrDepthRange = 'clear'; }
		
		if (WidthRange != '') {
			CurrWidthRange = WidthRange;
		}
		if (CurrWidthRange != '') {
			$('#widthFilter_' + CurrWidthRange).addClass('selectedFilter');
		}
		if (WidthRange == 'clear') { CurrWidthRange = 'clear'; }
				
		document.getElementById('OutputProducts').innerHTML = '<img src="Images/ajax-loader.gif" alt="loader" />';
		$("#" + 'OutputProducts').load("Classes/Ajax/Products.asp?ProductGroupId=" + CurrProductGroupId + '&priceRange=' + CurrPriceRange + '&HoutDikteId=' + CurrHoutDikteId + '&depthRange=' + CurrDepthRange + '&widthRange=' + CurrWidthRange);
	}

	function LoadProduct(productId, htmlOutputId)
	{
		if (productId != null)
		{
			document.getElementById(htmlOutputId).innerHTML = '<img src="Images/ajax-loader.gif" alt="loader" />';
			$("#" + htmlOutputId).load("Classes/Ajax/Product.asp?ShopProductId=" + productId);
			this.LoadAccessoires(productId, 'OutputAccessoires');
		}
		else
		{
			document.getElementById(htmlOutputId).innerHTML = "Er is geen product geselecteerd";
		}
	}


	function LoadCategoryName(categoryId, htmlOutputId)
	{
		document.getElementById(htmlOutputId).innerHTML = '<img src="Images/ajax-loader_small.gif" alt="loader" />';
		$("#" + htmlOutputId).load("Classes/Ajax/CategoryName.asp?CategoryId=" + categoryId);
	}
	function LoadSmallShoppingCart(htmlOutputId)
	{
		document.getElementById(htmlOutputId).innerHTML = '<img src="Images/ajax-loader_small.gif" alt="loader" />';
		$("#" + htmlOutputId).load("Classes/Ajax/SmallShoppingCart.asp");
	}
	function LoadAccessoires(productId, htmlOutputId)
	{
		document.getElementById(htmlOutputId).innerHTML = '<img src="Images/ajax-loader.gif" alt="loader" />';
		$("#" + htmlOutputId).load('Classes/Ajax/Accessoires.asp?ShopProductId=' + productId);
	}
	function LoadAccessoiresWithParams(productId, htmlOutputId, SortBy, SortOrder, Page)
	{
		document.getElementById(htmlOutputId).innerHTML = '<img src="Images/ajax-loader.gif" alt="loader" />';
		$("#" + htmlOutputId).load('Classes/Ajax/Accessoires.asp?ShopProductId=' + productId + '&SortBy=' + SortBy + '&SortOrder=' + SortOrder + '&Page=' + Page);
	}
	function LoadProductFilter()
	{
		document.getElementById('OutputProductFilter').innerHTML = '<img src="Images/ajax-loader_small.gif" alt="loader" />';
		$("#OutputProductFilter").load('Classes/Ajax/ProductFilter.asp');
	}


	function AddToCartQuickAjax(productId)
	{
		document.getElementById('SmallShoppingCart').innerHTML = '<img src="Images/ajax-loader_small.gif" alt="loader" />';
		$("#SmallShoppingCart").load("Classes/Ajax/SmallShoppingCart.asp?Action=Add&ShopProductId=" + productId + "&Quantity=1", ShowAddedToCartMessage);
	}
	function AddToCart()
	{
	    InvokeFormAction(2, 'AddToCart');
	}

	function ViewThumbImage(DetailImageLink)
	{
		document.getElementById('DetailImage').src = DetailImageLink;
		document.getElementById('DetailLink').href = DetailImageLink;
		document.getElementById('Enlarge').href = DetailImageLink;
	}

	function ShowAddedToCartMessage()
	{
		document.onmousemove=getMouseCoordinates;
		document.getElementById("AddedToCartMessage").innerHTML = "Product is toegevoegd aan uw winkelwagen";
		document.getElementById("AddedToCartMessage").style.display = "block";
		setTimeout('HideAddedToCartMessage()', TIMEOUT_DELAY);
	}

	function HideAddedToCartMessage()
	{
		document.onmousemove = null;
		document.getElementById("AddedToCartMessage").style.display = "none";
		document.getElementById("AddedToCartMessage").innerHTML = "";
		clearTimeout();
	}


	function getMouseCoordinates(event)
	{
		var MouseX = 0;
		var MouseY = 0;
		var IE = document.all?true:false;
		var ev = event || window.event;


		if (IE) {
			MouseX = ev.clientX+document.body.scrollLeft;
       	MouseY = ev.clientY+document.body.scrollTop;
		}
		else {
			MouseX = ev.pageX;
			MouseY = ev.pageY;
		}

		if (document.getElementById("AddedToCartMessage") != null) {
			document.getElementById("AddedToCartMessage").style.left = (MouseX + 30) + "px";
			document.getElementById("AddedToCartMessage").style.top = (MouseY + 30) + "px";
		}
	}

	// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser
	function pageload(hash) {
		// hash doesn't contain the first # character.
		if(hash) {
			// find the a-element with the given id
			var a = $("#"+hash);
			if (a.attr("target") != "undefined")
			{
				// There was a target defined, load the URL inside this target
				$("#"+a.attr("target")).load(a.attr("href"));
				alert('Loading content inside: ' + a.attr("target"));
			}
			else
			{
				// Somthing else??
			}
		} else {
			// start page
			// Could load some defaults... PE:
			// $("#load").empty();
		}
	}


