var winLoc = window.location.host;

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


BP.fm.categoryLink = function() {
	var page_name = BP.data.stores.pages.finder;
	var link = '/' + page_name + '?category_name=' + this.data.web_name + '&category_id=' + this.data.id;
	return link;
}

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

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

BP.fm.productImg = function() {
	var id_to_match = this.data.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++)
	{
		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() {
	var image_path = null;
	
	for(var cnt = 0; cnt < this.data.length; cnt++) {
		if(parseInt(this.data[cnt].width) > 300) {
			image_path = BP.data.productImagePath + this.data[cnt].filename;
		}
	}
	
	return image_path;
}

BP.fm.productPageProductMainImage = function(size) {
	var image_path = null;
	var key = String(size);
	if(this.data[key]) {
		image_path = BP.data.productImagePath + this.data[key]['filename'];
	}
	
	return image_path;
}

BP.fm.productPageProductImageThumbSize = function() {
	var image_path = null;
	
	for(var cnt = 0; cnt < this.data.length; cnt++) {
		if(parseInt(this.data[cnt].width) === 90) {
			image_path = BP.data.productImagePath + this.data[cnt].filename;
		}
	}
	
	return image_path;
}

BP.fm.decodeWebName = function(webName) {
	var decodedName = '';
	if(webName) {
		decodedName = webName.replace(/_/g, ' ');
		decodedName = decodedName.toUpperCase();
	}
	
	return decodedName;
}

BP.fm.urlEncodeProductName = function() {
	var result = BP.util.urlencode(this.data.name);
	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;
}
