var errors;
var popup;

function submitForm(){
	
	errors = 0;
	popup="\nYour form entries are incomplete:\n";

	// check all mandatory regular text fields
	var textFieldNames = new Array("title","first_name","last_name","organisation","address1","city","postcode","tel_no");
	for (var i=0; i<textFieldNames.length; i++){
		textCheck(textFieldNames[i]);
	}	
	// check email field
	if (!emailCheck("email")){
		popup+="\nPlease check that all email addresses are valid\n";
	}
	
	// check that an attendee option has been chosen
	radioSetCheck("attendee_type");
	// check that payment method option has been chosen
//	radioSetCheck("payment_method");

	// check that Terms and Conditions checkbox has been checked
	if (!checkboxCheck("tandc")){
		popup+="\nPlease tick to confirm that you have read and\nagree with the Terms and Conditions\n";
	}
	
	if (errors > 0){
		popup+="\nPlease complete the fields marked\nwith a red * and then re-submit.\n";
		alert(popup);
	}else{
		var msg = "The total payable amount is " + calculateFee() + ". Continue?";
		if (confirm(msg)){
			document.forms.Form1.submit();
		}			
	}
}

function calculateFee(){
	
	// initialise sum value
	var sum = 0;
	
	// chosen attendee options
	if (radioCheckboxDetect("attendee_type_conf_only")){
		sum = 450;
	}else if (radioCheckboxDetect("attendee_type_conf_accom8-10")){
		sum = 800;
	}else if (radioCheckboxDetect("attendee_type_conf_accom9-11")){
		sum = 800;
	}else if (radioCheckboxDetect("attendee_type_conf_accom8-11")){
		sum = 1090;
	}

	// chosen payment option
	if (radioCheckboxDetect("payment_method_debit_card")){
		// add 1 percent
		sum = sum * 1.01;
	}else if (radioCheckboxDetect("payment_method_credit_card")){
		// add 3 percent
		sum = sum * 1.03;
	}
	
	sum = formatAsMoney(sum);

	// add to 'amount' field
	document.getElementById("amount").value = sum;

	return sum + " CHF";	
}
