var payment_cost = {}; var textfield_cost = {}; payment_cost["Cash"] = '0'; payment_cost["Credit Card (add 2% Credit Card Charge)"] = '2%'; 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[2]'].value * 7.5 + form['qty[3]'].value * 7.75 + form['qty[4]'].value * 8.5 + form['qty[5]'].value * 8 + form['qty[6]'].value * 8.5 + form['qty[7]'].value * 9 + form['qty[8]'].value * 9 + form['qty[9]'].value * 9.5 + form['qty[10]'].value * 10 + form['qty[12]'].value * 3 + form['qty[13]'].value * 4 + form['qty[15]'].value * 3.5 + form['qty[17]'].value * 3.25 + form['qty[18]'].value * 5 + form['qty[20]'].value * 6 + form['qty[21]'].value * 8 + form['qty[22]'].value * 9 + form['qty[24]'].value * 12 + form['qty[26]'].value * 15 + form['qty[28]'].value * 3.5 + form['qty[29]'].value * 3; 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; }