	/* Author: Thomas Fung */
	/* Function: Redirect ProductPage from ProductGrid to ProductDisplay Search by Category instead of ProductDisplay.aspx?Product= */
	$(document).ready(function(){
		
		var filename = window.location.href.substr(window.location.href.lastIndexOf("/") + 1);
		filename = filename.toUpperCase();		
		
		if (filename.indexOf("ORDERS.ASPX") > -1)
		{			
			$('.normalRow td a').each(function (i)
			{			
				this.href = this.href.replace('Product=', 'Search=');		
			});	
			
			$('.alternateRow td a').each(function (i)
			{
				this.href = this.href.replace('Product=', 'Search=');
			});	
		}
		else if (filename.indexOf("PRODFAVOURITES.ASPX") > -1)
		{
			// strips out additional parameters of category etc;
			// http://saddlerytrading.customer-self-service.com/ProductDisplay.aspx?popup=1&Category=SX5001582&Search=DSP2100
			// Example: remove Popup and Category parameter
			var newURL; 
			$('.normalRow td a').each(function (i)
			{			
				newURL = this.href.substr(this.href.lastIndexOf("/"), this.href.lastIndexOf("?") - this.href.lastIndexOf("/")) + "?" + "Search=" + this.href.substr(this.href.lastIndexOf("=") + 1)
				this.href = newURL;				
			});	
			
			$('.alternateRow td a').each(function (i)
			{
				newURL = this.href.substr(this.href.lastIndexOf("/"), this.href.lastIndexOf("?") - this.href.lastIndexOf("/")) + "?" + "Search=" + this.href.substr(this.href.lastIndexOf("=") + 1)
				this.href = newURL;
			});	
		}
		
	});			
