var ProductGrid=function(){function u(t,u){if(typeof t!="undefined"&&typeof u!="undefined"){n=t;i=u;for(grid in n)r[grid]=null}}function f(n,u,f){f>0&&(t=i[u].filter(function(n){if(f>=n.QuantityFrom&&(f<=n.QuantityTo||!n.QuantityTo))return n})[0],typeof t!="undefined"?($(n).find("td").removeClass("bolded"),n.hasClass("table-horizontal")?$(n).find("td:nth-of-type("+t.Index+")").addClass("bolded"):n.hasClass("table-vertical")&&$(n).find("tr:nth-of-type("+(t.Index+1)+") td").addClass("bolded"),r[u]!=t.Index&&(r[u]=t.Index,n.hasClass("table-horizontal")?$(n).find("td:nth-of-type("+t.Index+")").effect("highlight",{color:"#333"},500):n.hasClass("table-vertical")&&$(n).find("tr:nth-of-type("+(t.Index+1)+") td").effect("highlight",{color:"#333"},500))):(r[u]=null,$(n).find("td").removeClass("bolded")))}function e(i,r,u){var f=null;if(typeof t!="undefined"&&typeof n[i]!="undefined"){var s=u.length?u.data("grid-id").toString().split(","):[],e=r.filter(function(n){return s.indexOf(n)>-1}),o=e.length?e[0]:0;f=typeof n[i][o]!="undefined"?n[i][o][0].Prices.filter(function(n){if(t.Index==n.Index)return n})[0].ListPrice:n[i][r[0]][0].Prices.filter(function(n){if(t.Index==n.Index)return n})[0].ListPrice}return f}function o(i){var r=null;return typeof t!="undefined"&&typeof n[i]!="undefined"&&(r=n[i][Object.keys(n[i])[0]][0].SetupCharge),r}function s(i){var u=1,r;return typeof t!="undefined"&&typeof n[i][Object.keys(n[i])[0]]!="undefined"&&(r=n[i][Object.keys(n[i])[0]][0].Prices.filter(function(n){if(t.Index==n.Index)return n})[0].AdditionalCost,r.length&&(u=Math.max.apply(Math,r.map(function(n){return n.CostIndex})))),u}function h(i,r){var e=null,u,f;return typeof t!="undefined"&&typeof n[i][Object.keys(n[i])[0]]!="undefined"&&(u=n[i][Object.keys(n[i])[0]][0].Prices.filter(function(n){if(t.Index==n.Index)return n}),u.length&&(f=u[0].AdditionalCost.filter(function(n){if(n.CostIndex==r)return n}),f.length&&(e=f[0].Sell))),e}function c(i,r){var e=null,u,f;return typeof t!="undefined"&&typeof n[i][Object.keys(n[i])[0]]!="undefined"&&(u=n[i][Object.keys(n[i])[0]][0].Prices.filter(function(n){if(t.Index==n.Index)return n}),u.length&&(f=u[0].AdditionalCost.filter(function(n){if(n.CostIndex==r)return n}),f.length&&(e=f[0].SetupCharge))),e}function l(i,r){var u=null;if(typeof t!="undefined"&&typeof n[i]!="undefined")if(typeof r!="undefined")for(grid in n[i])n[i][grid].forEach(function(n){var t=n.Colors.filter(function(n){if(n.Id==r)return n.Id})[0];t&&(u=t.GridId)});else u=n[i][Object.keys(n[i])[0]][0].GridId;return u}function a(i){var r=[],u;if(typeof t!="undefined"&&typeof n[i]!="undefined")for(grid in n[i])u=n[i][grid][0].Colors.filter(function(n){if(n.Enabled)return n}),u.forEach(function(n){var t=[],i;t=r.filter(function(t){return t.Id==n.Id});t.length?(i=t[0].GridId.toString().split(),i.push(grid),t[0].GridId=i.join(",")):(n.GridId=parseInt(grid),r.push(n))});return r}function v(t){var o=$("#productPricingGrid").html(),s=Handlebars.compile(o),f="";if(typeof t!="undefined"){var r=n[t],h=i[t],u=Object.keys(r)[0],e=0;r[u][0].hasOwnProperty("Prices")&&r[u][0].Prices.length>0&&(e=numeral().unformat(r[u][0].Prices[0].ListPrice));f=s({quantities:h,comment:r[u][0].Comment,grids:r,hidePrice:e>0?!1:!0})}return f}function y(t){var h=$("#productPricingVerticalGrid").html(),c=Handlebars.compile(h),o="",e,u;if(typeof t!="undefined"){var r=n[t],l=i[t],f=Object.keys(r)[0],s=0;r[f][0].hasOwnProperty("Prices")&&r[f][0].Prices.length>0&&(s=numeral().unformat(r[f][0].Prices[0].ListPrice));e=l.map(function(n){return{QuantityFrom:n.QuantityFrom,QuantityTo:n.QuantityTo,Prices:[]}});for(grid in r)for(u=0;u<r[grid][0].Prices.length;u++)typeof e[u]!="undefined"&&e[u].Prices.push(r[grid][0].Prices[u]);o=c({quantities:e,comment:r[f][0].Comment,grids:r,hidePrice:s>0?!1:!0})}return o}function p(n){return typeof n!="undefined"?i[n]:[]}function w(t,i){var r={};if(t&&i)for(grid in n[t])n[t][grid].forEach(function(n){var t=n.Colors.filter(function(n){if(n.Id==i)return n.Id})[0];t&&(typeof r[grid]=="undefined"&&(r[grid]=[]),r[grid].push(t.Id))});return r}var r={},n={},i={},t={};return{InitGrids:function(n,t){u(n,t)},GetQuantityRange:function(n){return p(n)},UpdateGrid:function(n,t,i){f(n,t,i)},GetPrice:function(n,t,i){return e(n,t,i)},GetSetupCharge:function(n){return o(n)},GetGridHtml:function(n){return v(n)},GetVerticalGridHtml:function(n){return y(n)},GetDecorationColourMax:function(n){return s(n)},GetDecorationColourCost:function(n,t){return h(n,t)},GetDecorationColourSetupCharge:function(n,t){return c(n,t)},GetColourGridId:function(n,t){return l(n,t)},GetDecorationMethodColours:function(n){return a(n)},GetColorEnabledGrids:function(n,t){return w(n,t)}}}()