<!--
// 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 validate_Email(field)
{
	with (field)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) 
		  {return false;}
		else {return true;}
	}
}

function validate_form(f) {
	if (f.UNITxPRICE_qty.value == 0) {
		alert("Please select at least one Motorpass Super Saver Plus.")
		return false
	}
	
	if (f.Delivery_Name.value == "") {
		alert("Please enter a delivery name.")
		return false
	}
	
	if (f.Delivery_Address.value == "") {
		alert("Please enter a street address.")
		return false
	}
	
	if (f.Delivery_Suburb.value == "") {
		alert("Please enter a street suburb.")
		return false
	}
	
	if (f.Delivery_State.value == "") {
		alert("Please enter your state.")
		return false
	}
	
	if (f.Postcode.value == "") {
		alert("Please enter your Postcode.")
		return false
	}
	
	if (!validate_Email(f.Email)) {
		alert("Please enter a valid Email address.")
		return false
	}
	
	if (!f.chkAgreeToTerms.checked) {
		alert("Please read and agree to the terms and conditions.")
		return false
	}
	
	return true
}

function FormatFields()
{

document.form1.UNITxPRICE.value = document.form1.UNITxPRICE_qty.value + "," + document.form1.UNITxPRICE_value.value;


document.form1.UNITxPRICE_subtotal.value = toDollarsAndCents(document.form1.UNITxPRICE_qty.value * document.form1.UNITxPRICE_value.value);

document.form1.OrderTotal.value = 0;

document.form1.OrderTotal.value = toDollarsAndCents(parseFloat(document.form1.OrderTotal.value)
			 + parseFloat(document.form1.UNITxPRICE_subtotal.value) + parseFloat(document.form1.Postage.value));

}

//-->

