var winLoc = window.location.host;

if(winLoc == 'www.370ztune.com' || winLoc == '370ztune.com' || winLoc == 'dev.370ztune.com' || winLoc == 'stage.370ztune.com')
{
	BP.fm.baseLink = window.location.host + '/';
}
else
{
	BP.fm.baseLink = '370ztune.com' + '/';
}

BP.fm.categoryLink = function(tpl_string, match, all_vals, current_val)
{
	var page_name = BP.data.stores.pages.finder;
	var link = '/' + page_name + '?category_name=' + current_val + '&category_id=' + all_vals.id;
	return link;
}

BP.fm.manufacturerLink = function(tpl_string, match, all_vals, current_val)
{
	var page_name = BP.data.stores.pages.finder;
	var web_name = all_vals.productmanufacturer_webname;
	
	var link = '/' + page_name + '?man_name=' + web_name + '&manufacturer_id=' + current_val;
	return link;
}

BP.fm.productLink = function(tpl_string, match, all_vals, current_val)
{
	var page_name = BP.data.stores.pages.product;
	var man_name = all_vals.productmanufacturer_webname;
	
	var link = '/' + page_name + '?m=' + man_name + '&n=' + all_vals.web_name + '&id=' + current_val;
	return link;
}

BP.fm.productImg = function(tpl_string, match, all_vals, current_val)
{
	var id_to_match = all_vals.id;
	var product_images = BP.data.stores.productImagesStore;
	
	// search the array of images for one with this product id
	for(var cnt = 0; cnt < product_images.length; cnt++)
	{
		var what = product_images[cnt];
		if (product_images[cnt]['product_id'] == id_to_match)
		{
			var result = BP.data.productImagePath + product_images[cnt]['filename'];
			// remove item from the main array to reduce future loops
			BP.data.stores.productImagesStore.splice(cnt, 1);
			return result;
		}
	}
}

BP.fm.productPageProductImageFullSize = function(tpl_string, match, all_vals, current_val) {
	if(parseInt(all_vals.width) > 300)
	{
		var image_path = BP.data.productImagePath + current_val;
		return image_path;
	}
	else
	{
		return tpl_string;
	}
}

BP.fm.productPageProductImageMainSize = function(tpl_string, match, all_vals, current_val) {
	if(parseInt(all_vals.width) === 300)
	{
		var image_path = BP.data.productImagePath + current_val;
		return image_path;
	}
	else
	{
		return tpl_string;
	}
}

BP.fm.productPageProductImageThumbSize = function(tpl_string, match, all_vals, current_val) {
	if(parseInt(all_vals.width) === 90)
	{
		var image_path = BP.data.productImagePath + current_val;
		return image_path;
	}
	else
	{
		return tpl_string;
	}
}

BP.fm.urlEncode = function(tpl_string, match, all_vals, current_val)
{
	var result = encodeURIComponent(current_val);
	return result;
}

BP.fm.productDescription = function(tpl_string, match, all_vals, current_val)
{
	var line_breaked_desc = BP.util.nl2br(current_val, true);
	return line_breaked_desc;
}