var payment_cost = {}; var textfield_cost = {}; payment_cost["Cash"] = '0'; payment_cost["Credit Card (add 2% Credit Card Charge)"] = '2%'; textfield_cost['23'] = '1'; textfield_cost['24'] = '1'; textfield_cost['30'] = '1'; textfield_cost['31'] = '1'; textfield_cost['33'] = '1'; textfield_cost['34'] = '1'; 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 * 21 + form['qty[3]'].value * 24 + form['qty[5]'].value * 3.5 + form['qty[6]'].value * 3.5 + form['qty[7]'].value * 3.5 + form['qty[8]'].value * 3.5 + form['qty[11]'].value * 12.5 + form['qty[12]'].value * 13 + form['qty[13]'].value * 14 + form['qty[14]'].value * 15 + form['qty[17]'].value * 3.5 + form['qty[18]'].value * 4 + form['qty[20]'].value * 3 + form['qty[21]'].value * 3.5 + form['qty[23]'].value * (6.5 + (form[':[23]'].value ? 1 : 0)) + form['qty[24]'].value * (9 + (form[':[24]'].value ? 1 : 0)) + form['qty[26]'].value * 13 + form['qty[27]'].value * 14 + form['qty[30]'].value * (16 + (form[':[30]'].value ? 1 : 0)) + form['qty[31]'].value * (20 + (form[':[31]'].value ? 1 : 0)) + form['qty[33]'].value * (12 + (form[':[33]'].value ? 1 : 0)) + form['qty[34]'].value * (15 + (form[':[34]'].value ? 1 : 0)) ; 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; }