// To customise your product order form do a search and replace on each product name.
// For example, do a search for each occurence of the word "product_1" and replace
// them with your product name (such as "pair_of_socks"). When the invoice step occurs,
// all underscores (the _ character) get replaced with spaces, so the above product would 
// appear on the invoice presented to the customer as "pair of socks". Replace all occurences 
// of "product_number" (where number is a digit) with meaningful product names.
// Any alphanumeric character can be used, but do not use the hyphen "-" character.
// You must also replace the visible product descriptions without underscores such as "Product 1".

// When your account is activated, change the ACTION from test_payment.pl to make_payment.pl

function toDollarsAndCents(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

function FormatFields()
{

document.form1.DVD1_Order_2011.value = document.form1.DVD1_Order_qty_2011.value + "," + document.form1.DVD1_Order_value_2011.value;
document.form1.DVD2_Order_2011.value = document.form1.DVD2_Order_qty_2011.value + "," + document.form1.DVD2_Order_value_2011.value;
document.form1.Cap.value = document.form1.Cap_qty.value + "," + document.form1.Cap_value.value;
document.form1.Back_Issue.value = document.form1.Back_Issue_qty.value + "," + document.form1.Back_Issue_value.value;
document.form1.Other_Payment.value = document.form1.Other_Payment_qty.value + "," + document.form1.Other_Payment_value.value;

document.form1.DVD1_Order_subtotal_2011.value = toDollarsAndCents(document.form1.DVD1_Order_qty_2011.value * document.form1.DVD1_Order_value_2011.value);
document.form1.DVD2_Order_subtotal_2011.value = toDollarsAndCents(document.form1.DVD2_Order_qty_2011.value * document.form1.DVD2_Order_value_2011.value);
document.form1.Cap_subtotal.value = toDollarsAndCents(document.form1.Cap_qty.value * document.form1.Cap_value.value);
document.form1.Back_Issue_subtotal.value = toDollarsAndCents(document.form1.Back_Issue_qty.value * document.form1.Back_Issue_value.value);
document.form1.Other_Payment_subtotal.value = toDollarsAndCents(document.form1.Other_Payment_qty.value * document.form1.Other_Payment_value.value);

document.form1.OrderTotal.value = 0;

document.form1.OrderTotal.value = toDollarsAndCents(parseFloat(document.form1.OrderTotal.value)

			 + parseFloat(document.form1.DVD1_Order_subtotal_2011.value)
			 + parseFloat(document.form1.DVD2_Order_subtotal_2011.value)
			 + parseFloat(document.form1.Cap_subtotal.value)
			 + parseFloat(document.form1.Back_Issue_subtotal.value)
			 + parseFloat(document.form1.Other_Payment_subtotal.value));

}


