
	var placesAvailable = 0;
	var totalNumber = 0;
	var totalCost = 0;
	var pricePerPerson = 195.0;


        var chars = '123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';
        var turinValue = '';

        function doTurin() {
                var r1 = Math.round( Math.random() * chars.length);
                var r2 = Math.round( Math.random() * chars.length);
                var r3 = Math.round( Math.random() * chars.length);
                var r4 = Math.round( Math.random() * chars.length);
                turinValue = '' + chars.charAt( r1);
                turinValue = turinValue + chars.charAt( r2);
                turinValue = turinValue + chars.charAt( r3);
                turinValue = turinValue + chars.charAt( r4);
                var theTurin = document.getElementById( 'turin');
                theTurin.innerHTML = turinValue;
                document.bookingForm.turinValue.value == '';
        }


	/*
	 * Update the form
	 */
	function updateForm() {
		totalNumber = 0;
	
		// Card name
		document['bookingForm'].cardname.value = document['bookingForm'].name.value;
		if ((document['bookingForm'].name.value != '') && (document['bookingForm'].name.value != null)) {
		}
		
		// Update the amount
		if (document['bookingForm'].bookedPlaces.value > placesAvailable) {
			if (document.getElementById( 'notEnoughPlaces') != null) {
				document.getElementById( 'notEnoughPlaces').style.display = 'inline';
			}
			document.getElementById( 'totalCost').innerHTML = '';
		}
		else {
			if (document.getElementById( 'notEnoughPlaces') != null) {
				document.getElementById( 'notEnoughPlaces').style.display = 'none';
			}
			if (document['bookingForm'].bookedPlaces.value > 0) {
				totalNumber += parseInt( document['bookingForm'].bookedPlaces.value);
			}
			if (document.getElementById( 'totalCost') != null) {
				if (totalNumber > 0) {
					document.getElementById( 'totalCost').innerHTML = '' + (totalNumber * pricePerPerson);
				}
				else {
					document.getElementById( 'totalCost').innerHTML = '';
				}
			}
		}
	}
	
	
	/*
	 * Check the form is filled in right
	 */
	function checkForm() {
		var bookedPlaces = document['bookingForm'].bookedPlaces.value;
		var bookedType = document['bookingForm'].bookedType.value;
		var bookedLocation = document['bookingForm'].bookedLocation.value;
		var bookedDate = document['bookingForm'].bookedDate.value;
		
		// Everything must be > 0
		var error = false;

		if (! error) {
			if (document['bookingForm'].voucher.value != '') {
				document['bookingForm'].payment.value = 'voucher';
			}
		}

		// Name		
		if (! error) {
			if (document['bookingForm'].name.value == '') {
				alert( 'ERROR: Please enter your name');
				error = true;
			}
		}
		
		// Address
		if (! error) {
			if (document['bookingForm'].address.value == '') {
				alert( 'ERROR: Please enter your address and postcode');
				error = true;
			}
		}
		
		// Telephone
		if (! error) {
			if (document['bookingForm'].telno.value == '') {
				alert( 'ERROR: Please enter a telephone number where you can be contacted');
				error = true;
			}
		}
		
		// Email
		if (! error) {
			if (document['bookingForm'].email.value == '') {
				alert( 'ERROR: Please enter your email address where we can send your booking confirmation');
				error = true;
			}
		}
		
		if (! error) {
			if (bookedPlaces < 0) {
				alert( 'ERROR: You have asked for a negative number of places on ' + bookedDate + ' in the ' + bookedLocation);
				error = true;
			}
			if (bookedPlaces <= 0) {
				alert( 'ERROR: You have not booked any places on ' + bookedDate + ' in the ' + bookedLocation);
				error = true;
			}		
		}
		if (! error) {
			//alert( 'places = ' + document['bookingForm'].bookedPlaces.value
					//+ 'location = ' + document['bookingForm'].bookedLocation.value
					//+ 'date = ' + document['bookingForm'].bookedDate.value);
		}
		
		if (! error) {
			if (! document['bookingForm'].accepted.checked) {
				alert( 'Please confirm that you have read the Terms and Conditions');
				error = true;
			}		
		}
	
		if( ! error) {
			// Check the turin
			//alert( 'if( ' + document.bookingForm.turinValue.value + '==' + turinValue + ') {');
			if( document.bookingForm.turinValue.value == turinValue) {
                		document.bookingForm.turincheck.value = 'FAB';
					return( true);
			}
			else {
				alert( 'Please type the four characters exactly as you see them in the white box.');
				doTurin();
				return( false);
			}
		}	

		// Activity level
		if (! error) {
			var activityChecked = false;
			if(typeof(document['bookingForm']) != 'undefined') { 
				for (i=0; i < document['bookingForm'].activity.length;i++) {
					if (document['bookingForm'].activity[i].checked) {
						activityChecked = true;
					}
				}
			}
			else {
				activityChecked = true;
			}

			if ( ! activityChecked) {
				alert( 'ERROR: Please select what level of activity you want - Level 1, Level 2 or Taster');
				error = true;
			}
		}
		
		return( !error);
	}

	
	
	function updateSummary( type, date, location, available) {
		if (document.getElementById( 'bookingSummary') != null) {
			document.getElementById( 'bookingSummary').style.display = 'inline';
		}
		if (document.getElementById( 'placeDateType') != null) {
			var html = 'Number of places to book for ';
			html += '<strong><font color="#4040ff">'; html += type; html += '</font></strong>';
			html += ' training on ';
			html += '<strong><font color="#4040ff">'; html += date; html += '</font></strong>';
			html += ' in the ';
			html += '<strong><font color="#4040ff">'; html += location; html += '</font></strong>';
			document.getElementById( 'placeDateType').innerHTML = html;
		}
		
		placesAvailable = available;
		document['bookingForm'].bookedPlaces.value = '0';
		document['bookingForm'].bookedLocation.value = location;
		document['bookingForm'].bookedDate.value = date;
		document['bookingForm'].bookedType.value = type;
		updateForm();
	}

