
function CBPrice(type,rrp,deal,savingMode){var html='';rrp1=rrp.replace('$','');rrp2=rrp1.replace(/,/g,'');dealOnline=deal.replace('Price: ','');var dealSub='';endIndex=deal.indexOf('&#');if(endIndex>0){dealSub=deal.substring(0,endIndex);}else{dealSub=deal;}deal1=dealSub.replace('Price: $','');deal2=deal1.replace(/,/g,'');rrpValue=parseFloat(rrp2);dealValue=parseFloat(deal2);addTaxRRP=rrpValue*1;daRRP=addTaxRRP.toFixed(2);viewRRP=dollarAmount(daRRP);if(daRRP>dealValue){var dollar=daRRP-dealValue;dollarFix=dollar.toFixed(2);dollValue=dollarAmount(dollarFix);save=(daRRP-dealValue)/daRRP;saveValue=Math.round(save*Math.pow(10,2))*100/Math.pow(10,2);if(savingMode=="Percentage"||savingMode==""){if(type=="item"){html='<h3 id="buyprice" class="red2"><span>Our Price: '+dealOnline+'</span></h3>'+'<h4><span class="rrp2">RRP: '+viewRRP+'</span>'+'<span class="save2">Save '+saveValue+'%</span></h4>';}else if(type=="pricelist"){html='<li class="rrp"><span>RRP: '+viewRRP+'</span></li>'+'<li id="buyprice" class="red"><span>Pay: '+dealOnline+'</span></li>'+'<li class="save"><span>Save '+saveValue+'%</span></li>';}return html;}else if(savingMode=="Dollar"){if(type=="item"){html='<h3 id="buyprice" class="red2"><span>Our Price: '+dealOnline+'</span></h3>'+'<h4><span class="rrp2">RRP: '+viewRRP+'</span>'+'<span class="save2">Save '+dollValue+'</span></h4>';}else if(type=="pricelist"){html='<li class="rrp"><span>RRP: '+viewRRP+'</span></li>'+'<li id="buyprice" class="red"><span>Pay: '+dealOnline+'</span></li>'+'<li class="save"><span>Save '+dollValue+'</span></li>';}return html;}}else if(daRRP<=dealValue){if(type=="item"){html='<h3 id="buyprice" class="red2"><span>Our Price: '+dealOnline+'</span></h3>';}else if(type=="pricelist"){html='<li id="buyprice" class="red"><span>Pay: '+dealOnline+'</span></li>';}return html;}else{html='<div id="buyprice" class="red3">Pay: '+dealOnline.replace("(prices include GST)","")+'</div>';return html;}}function checkNum(data){var valid="0123456789.";var ok=1;var checktemp;for(var i=0;i<data.length;i++){checktemp=""+data.substring(i,i+1);if(valid.indexOf(checktemp)=="-1")return 0;}return 1;}function dollarAmount(number){Num=number.toString();dec=Num.indexOf(".");end=((dec>-1)?""+Num.substring(dec,Num.length):".00");Num=""+parseInt(Num);var temp1="";var temp2="";if(checkNum(Num)==0){}else{if(end.length==2)end+="0";if(end.length==1)end+="00";if(end=="")end+=".00";var count=0;for(var k=Num.length-1;k>=0;k--){var oneChar=Num.charAt(k);if(count==3){temp1+=",";temp1+=oneChar;count=1;continue;}else{temp1+=oneChar;count++;}}for(var k=temp1.length-1;k>=0;k--){var oneChar=temp1.charAt(k);temp2+=oneChar;}temp2="$"+temp2+end;return temp2;}}
