function ValidateForm(prForm) {
	var cntChecks;
	if (prForm.m_1.value == "") {alert("Please fill in your Name");prForm.m_1.focus();return(false);}
	if (prForm.m_2.value == "") {alert("Please fill in your Surname");prForm.m_2.focus();return(false);}
	if (prForm.m_5.value == "") {alert("Please fill in your Mobile");prForm.m_5.focus();return(false);}
	if (prForm.m_6.value.length < 2 || prForm.m_6.value.indexOf("@") == -1){alert("Please fill in your E-mail address");prForm.m_6.focus();return(false);}
	if (prForm.m_6.value.toLowerCase() != prForm.confirmEmailAddress.value.toLowerCase()){alert("E-mail address and Confirm e-mail address do not match");prForm.m_6.focus();return(false);}
	if (paymentTypeId==1) {
		if (prForm.m_10.value == "") 					{alert("Please fill in your Reference No. / Quote No");prForm.m_10.focus();return(false);}
		if (prForm.p4.value == "") 						{alert("Please fill in your Payment amount");prForm.p4.focus();return(false);}
		if (!prForm.p4.value.match(/^[0-9\.]+$/)) 	{alert("Payment amount: Only numbers and '.' allowed");prForm.p4.focus();return(false);}
		if (prForm.m_7.value == "") 						{alert("Please select the branch that is doing your move");prForm.m_7.focus();return(false);}
	} else if (paymentTypeId>1) {
		var myForm = document.getElementById('myForm');
		var hasEnteredProduct = false;
		for (var i=0;i<products.length;i++) {if (Number(myForm['product_quantity'+i].value) > 0){hasEnteredProduct = true;break;};};
		if (!hasEnteredProduct) {alert("Please fill in the quantity for Bicycles");return(false);};
	}
	return true;
}	

function SubmitForm(){
	var frm = document.getElementById('myForm');
	//frm.submit();
	if (!ValidateForm(frm)){ 
		return false;
	} else {
		frm.submit();
	}
}

var _postage = 0;
function buildDynamicFields () {
	var myForm = document.getElementById('myForm');
	var html = '';
	var total = 0;
	for (var i=0;i<products.length;i++) {
		var qty = Number(myForm["product_quantity"+i].value);
		
		if (qty > 0) {
			var price = products[i].priceZAR.toFixed(2);
			total += (qty * price);
			var desc = products[i].desc;
			var name = products[i].name;
		};
		
		if (i == 0) {
			html += '<input name="m_8" id="m_8" type="hidden" value="'+qty+'">';		// single bike qty
		};
		if (i == 1) {
			html += '<input name="m_9" id="m_9" type="hidden" value="'+qty+'">';		// tandem bike qty
		};
	};
	html += '<input type="hidden" name="p4" id="p4" value="'+total+'"><br>';
	document.getElementById('divDynamicFields').innerHTML = html;
};
