
var filter_qty,filter_price,filter_colour,helptext;filter_qty=null;filter_price=null;filter_colour=null;helptext='Select a <b>colour</b>, and/or <b>price</b> preference and/or <b>quantity</b> required to display available stock.';function setObjectValue(id,value){var elm=document.getElementById(id);if(elm){if('input'===elm.tagName.toLowerCase()){elm.value=value;}else{elm.innerHTML=value;}}}
function product_info(id){var p,info,odd,s;p=products[id];info='<div style="background-color:#48593b;">&nbsp;</div>';info+='<div class="product_description">'+p.description+'</div>';info+='<div class="product_price">';if(p.discount>0){info+='<span style="font-size:9pt;text-decoration:line-through;color:black;font-weight:normal">$'+p.old_price.toFixed(2)+'</span>';info+='<span style="font-size:9pt;color:black"> - '+p.discount.toFixed(0)+'% = </span>';}
info+='$'+p.price.toFixed(2)+'/'+p.unit;info+='</div>';info+='<table style="width:100%">';info+='<tr><td style="color:black;font-weight:bold" colspan="3">';info+='Item # '+id+'</td><td style="font-size:7pt">Stock</td></tr>';info+='<tr>';odd=0;for(s in p.stock){if(p.stock.hasOwnProperty(s)){info+='<td style="background-color:#'+colours[s].back+';color:#'+colours[s].fore+'">'+colours[s].name+'</td>';info+='<td style="text-align:right;font-weight:bold">'+p.stock[s]+p.plus[s]+'</td>';odd=odd+1;if(odd===2){odd=0;info+='</tr><tr>';}}}
info+='</tr>';info+='</table>';info+='<div class="click_to_order">Click thumbnail to order<br>+ means item on order</div>';setObjectValue('product_info',info);document.getElementById('search_options').style.display='none';document.getElementById('search_info').style.display='none';}
function clear_info(){setObjectValue('product_info','');document.getElementById('search_options').style.display='';document.getElementById('search_info').style.display='';}
function search_colour(){var h,c,odd;h='<div>Stock displayed on this page is available in these colours:</div>';h+='<table style="width:100%">';h+='<tr>';odd=0;for(c in colours){if(colours.hasOwnProperty(c)){h+='<td style="font-size:7pt;border:1px solid black;color:#'+colours[c].fore+';background-color:#'+colours[c].back+'" onclick="choose_colour(\''+c+'\')">'+colours[c].name+'</td> ';odd=odd+1;if(odd===4){odd=0;h+='</tr><tr>';}}}
h+='</tr>';h+='</table>';setObjectValue('colour_chooser',h);setObjectValue('price_chooser','');}
function search_price_break(){var h,odd,p;h='<div>Stock displayed on this page is available in these price breaks:</div>';h+='<table style="width:100%">';h+='<tr>';odd=0;for(p in price_breaks){if(price_breaks.hasOwnProperty(p)){h+='<td style="text-align:center;font-weight:bold;border:1px solid black;" onclick="choose_price_break(\''+p+'\')">$'+price_breaks[p].min.toString()+' - $'+price_breaks[p].max.toString()+'</td> ';odd=odd+1;if(odd===2){odd=0;h+='</tr><tr>';}}}
h+='</tr>';h+='</table>';setObjectValue('price_chooser',h);setObjectValue('colour_chooser','');}
function isNull(val){return(val===null);}
function apply_filter(){var i,c,el,pid,vis,okay,num_hidden;setObjectValue('colour_chooser','');setObjectValue('price_chooser','');if(isNull(filter_colour)&&isNull(filter_price)&&isNull(filter_qty)){i='Showing all products';}else{if(!isNull(filter_qty)){i='These products have '+filter_qty.toString()+' available ';}else{i='These products are available ';}
if(!isNull(filter_colour)){i+=' in '+colours[filter_colour].name;}
if(!isNull(filter_price)){i+=' in the price range $'+price_breaks[filter_price].min.toString()+' - $'+price_breaks[filter_price].max.toString();}}
num_hidden=0;for(pid in products){if(products.hasOwnProperty(pid)){vis=true;if(!isNull(filter_price)){if(parseFloat(products[pid].price)<parseFloat(price_breaks[filter_price].min)){vis=false;}
if(parseFloat(products[pid].price)>=parseFloat(price_breaks[filter_price].max)){vis=false;}}
if(!isNull(filter_colour)){if(isNull(products[pid].stock[filter_colour])){vis=false;}
if(!isNull(filter_qty)){if(parseFloat(products[pid].stock[filter_colour])<parseFloat(filter_qty)){vis=false;}}}else if(!isNull(filter_qty)){okay=false;for(c in products[pid].stock){if(parseFloat(products[pid].stock[c])>=filter_qty){okay=true;}}
if(!okay){vis=false;}}
el=document.getElementById('product_'+pid);if(el!==null){if(vis){document.getElementById('product_'+pid).style.display='';}else{num_hidden=num_hidden+1;document.getElementById('product_'+pid).style.display='none';}}}}
window.status=num_hidden.toString()+' products hidden';setObjectValue('search_info',i);}
function choose_colour(c){filter_colour=c;apply_filter();}
function choose_price_break(p){filter_price=p;apply_filter();}
function search_show_all(){filter_colour=null;filter_price=null;filter_qty=null;apply_filter();}
function search_qty_required(){filter_qty=prompt('Enter the quantity you require:','');apply_filter();}