var payment_cost = {}; var textfield_cost = {}; payment_cost["Collection"] = ''; payment_cost["Delivery (£6.50 if under 10kg)"] = '6.5'; function format_float(value) { var i = parseFloat(value); if(isNaN(i)) { i = 0.00; } var minus = ''; if(i < 0) { minus = '-'; i = -i;} i = parseInt((i + .005) * 100); i = i / 100; s = new String(i); if(s.indexOf('.') < 0) { s += '.00'; } if(s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + s; return s; } function recalc_onclick(form, ctl, price) { var textfield = document.getElementById('tfld_'+ctl); if(textfield && textfield.value && textfield_cost[ctl]) price += parseFloat(textfield_cost[ctl]); form['tot['+ctl+']'].value = '£' + format_float(form['qty['+ctl+']'].value * price); calc_total(form); }; function calc_total(form) { var subtotal = form['qty[1]'].value * 23.99 + form['qty[2]'].value * 26.99 + form['qty[3]'].value * 24.99 + form['qty[4]'].value * 25 + form['qty[5]'].value * 29.99; form['subtotal'].value = '£ ' + format_float(subtotal); var payment = ''; for(var i = 0; i < form.payment.length; i++) { if(form.payment[i].checked) { payment = form.payment[i].value; break; } } var cost = payment_cost[payment] ? parseFloat(payment_cost[payment]) : 0; if(new String(payment_cost[payment]).match(/%/)) form['total'].value = '£ ' + format_float(subtotal + subtotal * cost / 100); else form['total'].value = '£ ' + format_float(subtotal + cost); return subtotal; }; function check_form(form) { return true; }