 /**
 * 
 * File		:		form_validation.js  
 * Author	:		Peter Cotton 
 * Date		:		Friday 2nd June 2006
 * Purpose	:		Functions to verify data from HTML forms.
 * Note		:		Calls functions in data_validation.js.
 * 
 * History	:		Version 1.0 Original
 * 
 *  */
 
 
 
 
/**
 * Function to check and submit the user registration form
 * @param none
 * @return none
 * */
 function checkUserRegistrationForm(){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check username entered
 	if (data.username.value == '' || reWhiteSpace.test(data.username.value)){
 		alert('A username must be entered.');
 		return;
 	}
 	
 	// check password1 entered
 	if (data.password1.value == '' || reWhiteSpace.test(data.password1.value)){
 		alert('A password must be entered.');
 		return;
 	}
 	
 	// check password2 entered
 	if (data.password2.value == ''){
 		alert('The password must be confirmed.');
 		return;
 	}
 		
 	// check password1 and password2 match
 	if (data.password1.value != data.password2.value){
 		alert('The password and confirmed password do not match.');
 		return;
 	}
 	
 	// check email entered
 	if (!isEmail(data.email.value)){
 		alert('A valid email address must be entered.');
 		return;
 	}
 		
 	data.action='process.php?link=account/process_register.php';
 	data.submit();
 }
 
 
 
 /**
 * Function to check and submit the distributor registration form
 * @param none
 * @return none
 * */
 function checkDistributorRegistrationForm(){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check company name entered
 	if (data.companyname.value == '' || reWhiteSpace.test(data.companyname.value)){
 		alert('A company name must be entered.');
 		return;
 	}
 	
 	// check company number entered
 	if (data.companynumber.value == '' || reWhiteSpace.test(data.companynumber.value)){
 		alert('A company number must be entered.');
 		return;
 	}
 	
 	// check password1 entered
 	if (data.password1.value == '' || reWhiteSpace.test(data.password1.value)){
 		alert('A password must be entered.');
 		return;
 	}
 	
 	// check password2 entered
 	if (data.password2.value == ''){
 		alert('The password must be confirmed.');
 		return;
 	}
 		
 	// check password1 and password2 match
 	if (data.password1.value != data.password2.value){
 		alert('The password and confirmed password do not match.');
 		return;
 	}
 	
 	// check surname entered
 	if (data.surname.value == '' || reWhiteSpace.test(data.surname.value)){
 		alert('A surname must be entered.');
 		return;
 	}
 	
 	// check telephone number entered
 	if (data.telno.value == '' || reWhiteSpace.test(data.telno.value)){
 		alert('A telephone number must be entered.');
 		return;
 	}
 	
 	// check email entered
 	if (!isEmail(data.email.value)){
 		alert('A valid email address must be entered.');
 		return;
 	}
 		
 	data.action='process.php?link=distributor/process_register.php';
 	data.submit();
 }
 
 
 
 /**
 * Function to check and submit the user profile form
 * @param none
 * @return none
 * */
 function checkProfileForm(){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check email entered
 	if (! isEmail(data.email.value)){
 		alert('A valid email address must be entered.');
 		return;
 	}
 		
 	data.action='process.php?link=account/process_profile.php';
 	data.submit();
 
 }
 
 
 
 
 /**
 * Function to check and submit the news form
 * @param int id
 * @return none
 * */
 function checkNewsForm(id){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	if (data.text.value == '' || reWhiteSpace.test(data.text.value)){
 		alert('Text for the news item must be entered.');
 		return;
 	}
 	
 	data.id.value=id;
 	data.mode.value='save';
 	data.link.value='admin/process_news.php';
 	data.action='process.php';
 	data.submit();
 }
 
 
 
 /**
 * Function to check and submit the upload form
 * @param none
 * @return none
 * */
 function checkUploadForm(level){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check name entered
 	if (data.name.value == '' || reWhiteSpace.test(data.name.value)){
 		alert('A name must be entered for the file you are uploading.');
 		return;
 	}
 	
 	// check file selected
 	if (data.uploadfile.value == '' || reWhiteSpace.test(data.uploadfile.value)){
 		alert('A file must be selected using the file picker provided.');
 		return;
 	}
 	// if the user is not an administrator (level 4)
 	if (level != 4){
 		// check file ends with .vrp or .xml extension
 		if (!(data.uploadfile.value.substring(data.uploadfile.value.length-4) == '.xml' || data.uploadfile.value.substring(data.uploadfile.value.length-4) == '.vrp')){
 			alert('The file selected to upload must have a .vrp or .xml extension.');
 			return;
 		}
 	} else {
 		// IF the file is a project file
 		if (data.type.value == 1){
 			// check file ends with .vrp or .xml extension
 			if (!(data.uploadfile.value.substring(data.uploadfile.value.length-4) == '.xml' || data.uploadfile.value.substring(data.uploadfile.value.length-4) == '.vrp')){
 				alert('The file selected to upload must have a .vrp or .xml extension.');
 				return;
 			}
 		}
 	}
 	// check description entered
 	if (data.description.value == '' || reWhiteSpace.test(data.description.value)){
 		alert('A description must be entered for the file you are uploading.');
 		return;
 	}
 	
 	data.submit();
 }
 
 
 /**
 * Function to check and submit the forum post form
 * @param int id
 * @return none
 * */
 function checkForumPostForm(){
	
	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// if this is a new thread, it MUST have a title
	if (data.thread.value == '') {
 		if (data.title.value == '' || reWhiteSpace.test(data.title.value)){
 			alert('A title for the post must be entered.');
 			return;
 		}
 	} else {
 	// if this is a post for an existing thread, the title may be (none)
 		if (data.title.value == '' || reWhiteSpace.test(data.title.value)){
 			data.title.value = '(none)';
 		}
 	}
 	
 	
 	
 	if (data.body.value == '' || reWhiteSpace.test(data.body.value)){
 		alert('A body for the post must be entered.');
 		return;
 	}
 	
 	data.action='process.php';
 	data.link.value='forums/process_newmessage.php';
 	data.submit();
 }
 
 
 
 /**
 * Function to check and submit the add to favourites form
 * @param none
 * @return none
 * */
 function checkAddToFavsForm(thread){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// ask the user if they want to receive email notifications for this thread
 	var user_input = confirm("Do you want to receive email notifications when somebody adds a post to this forum?");
 	
 	// if the user has said they do want notification, set the form variable accordingly
 	if (user_input){
 		data.notify.value=1;
 	}
 	
 	data.thread.value=thread;
 	data.action='process.php';
 	data.link.value='forums/process_addtofavs.php';
 	data.submit();
 }
 
 
 
 /**
 * Function to check and submit the remove from favourites form
 * @param none
 * @return none
 * */
 function checkRemoveFromFavsForm(thread){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// ask the user if they are sure they want to remove it from their favourites
 	var user_input = confirm("Are you sure you want to remove this thread from your favourites?");
 	
 	// if the user has said they aren't sure, exit
 	if (!user_input){
 		return;
 	}
 	
 	data.thread.value=thread;
 	data.action='process.php';
 	data.link.value='forums/process_removefromfavs.php';
 	data.submit();
 }
 
 
 
 
 /**
 * Function to check and submit the notify form
 * @param thread
 * @param notify
 * @return none
 * */
 function checkNotifyForm(thread, notify){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	data.notify.value=notify;
 	data.thread.value=thread;
 	data.action='process.php';
 	data.link.value='forums/process_changenotify.php';
 	data.submit();
 }
 
 
 
 
 /**
  * Function to check and submit the contact us form
  * @param none
  * @return none
  * */
  function checkContactUsForm(){
  	
  	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check name has been entered
  	if (data.name.value == '' || reWhiteSpace.test(data.name.value)){
  		alert('A name must be entered.');
  		return;
  	}
  	
  	// check a valid email address has been entered
  	if (!isEmail(data.email.value)){
  		alert('A valid email address must be entered.');
  		return;
  	}
  	
  	// check a message has been entered
  	if (data.message.value == '' || reWhiteSpace.test(data.message.value)){
  		alert('A message must be entered.');
  		return;
  	}
  	
  	data.submit();
  }
  
  
  
  
/**
 * Function to check and submit the distributor contact form
 * @param none
 * @return none
 * */
 function checkContactForm(){
 	
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check surname entered
 	if (data.surname.value == '' || reWhiteSpace.test(data.surname.value)){
 		alert('A surname must be entered.');
 		return;
 	}
 	
 	// check telephone number entered
 	if (data.telno.value == '' || reWhiteSpace.test(data.telno.value)){
 		alert('A telephone number must be entered.');
 		return;
 	}
 	
 	// check email entered
 	if (!isEmail(data.email.value)){
 		alert('A valid email address must be entered.');
 		return;
 	}
 		
 	data.action='process.php';
 	data.link.value='distributor/process_contact.php';
 	data.submit();
 }
 
 
 
 /*
 * Function to check a user is certain they want to delete a contact
 * @param	id
 * @return	void
 */
 function checkRemoveContact(id){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// ask the user if they are sure they want to remove the contact
 	var ask_user = confirm('Are you sure you want to permenantly delete this contact?');
 	
 	// if the user clicked 'cancel', return
 	if (!ask_user){
 		return;
 	}
 
 	data.id.value=id;
 	data.link.value='distributor/process_removecontact.php';
 	data.action='process.php';
 	data.submit();
 }
 
 
 
 
 /**
 * Function to check and submit the distributor address form
 * @param none
 * @return none
 * */
 function checkAddressForm(){
 	
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check line1 entered
 	if (data.line1.value == '' || reWhiteSpace.test(data.line1.value)){
 		alert('Line 1 must be filled.');
 		return;
 	}
 	
 	// check postcode entered
 	if (data.postcode.value=='' || reWhiteSpace.test(data.postcode.value)){
 		alert('A post code must be entered.');
 		return;
 	}
 	
 	// check country entered
 	if (data.country.value=='' || reWhiteSpace.test(data.country.value)){
 		alert('A country must be entered.');
 		return;
 	}
		
 	data.action='process.php';
 	data.link.value='distributor/process_address.php';
 	data.submit();
 }
 
 
 
 /*
 * Function to check a user is certain they want to delete an address
 * @param	id
 * @return	void
 */
 function checkRemoveAddress(id){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// ask the user if they are sure they want to remove the address
 	var ask_user = confirm('Are you sure you want to permenantly delete this address?');
 	
 	// if the user clicked 'cancel', return
 	if (!ask_user){
 		return;
 	}
 
 	data.id.value=id;
 	data.link.value='distributor/process_removeaddress.php';
 	data.action='process.php';
 	data.submit();
 }
 
 
 
 
 /*
 * Function to check the admin stock control 'new stock' form
 * @param	none
 * @return	void
 */
 function checkAddStockForm(){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// get user to confirm that they want to add the stock
 	var proceed = confirm("Are you sure you want to add "+data.quantity.value+" copies of Virtual Racer to the system?");

	// if the user clicked 'Ok' (or 'yes') 	
 	if (proceed){
 		// check a valid quantity has been entered
 		if (reWhiteSpace.test(data.quantity.value) || !isPosInt(data.quantity.value)){
 			alert("A valid quantity must be entered.");
 			return;
 		}
 	
 		data.link.value='admin/process_addstock.php';
 		data.action='process.php';
 		data.submit();
 	}
 }
 
 
 
 
 
 /*
 * Function to check the admin stock control 'dispatch stock' form
 * @param	max quantity to allow
 * @return	void
 */
 function checkDispatchStockForm(max_quantity){
 	
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check a distributor has been selected
 	if (data.distributor.selectedIndex == 0){
 		alert("A distributor must be selected.");
 		return;
 	}
 	
 	// check a license type has been selected
 	if (data.licensetype.selectedIndex == 0){
 		alert("A license type must be selected.");
 		return;
 	}
 
 	// check a valid quantity has been entered
 	if (!isPosInt(data.quantity.value)){
 		alert("A valid quantity must be entered.");
 		return;
 	}
 	
 	// check the quantity is no more than the maximum available
 	if (data.quantity.value > max_quantity){
 		alert("There are only "+max_quantity+" available licenses.");
 		return;
 	}
 	
 	// if they have selected to load an existing address
 	if (data.addressradio[0].checked){
 		
 		// check an address has been selected
 		if (data.address.selectedIndex == 0){
 			alert("An address must be selected.");
 			return;
 		}
 	
 	// if they have selected to enter a new address
 	} else {
 	
 		// check address type selected
 		if (data.addresstype.selectedIndex == 0){
 			alert("An address type must be selected.");
 			return;
 		}
 	
 		// check line1 has been entered
 		if (data.line1.value == '' || reWhiteSpace.test(data.line1.value)){
 			alert("Line 1 of the new address must be entered.");
 			return;
 		}
 		
 		// check that a post code has been entered
 		if (data.postcode.value == '' || reWhiteSpace.test(data.postcode.value)){
 			alert("A post code for the new address must be entered.");
 			return;
 		}
 		
 		// check that a country has been entered
 		if (data.country.value == '' || reWhiteSpace.test(data.country.value)){
 			alert("A country for the the new address must be entered.");
 			return;
 		}
 	}
 	
 	data.link.value='admin/process_dispatch.php';
 	data.action='process.php';
 	data.submit();
 }
 
 
 
 
 
 /*
 * Function to check the change password form for a user account
 * @param	none
 * @return	void
 */
 function checkUserAccountPasswordForm(){
 	
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check the old password was entered
 	if (data.old.value == '' || reWhiteSpace.test(data.old.value)){
 		alert('Your old password must be entered.');
 		return;
 	}
 	
 	// check the new password was entered
 	if (data.password.value == '' || reWhiteSpace.test(data.password.value)){
 		alert('Your new password must be entered.');
 		return;
 	}
 	
 	// check the new password was confirmed
 	if (data.confirm.value == '' || reWhiteSpace.test(data.confirm.value)){
 		alert('Your new password must be confirmed.');
 		return;
 	}
 	
 	// check the new and confirmed new passwords match
 	if (data.password.value != data.confirm.value){
 		alert('Your new password and confirmed passwords do not match.');
 		return;
 	}
 	
 	// proceed with action
 	data.link.value='account/process_password.php';
 	data.submit();
 }
 
 
 
 
 
 /*
 * Function to check the change password form for a distributor account
 * @param	none
 * @return	void
 */
 function checkDistributorAccountPasswordForm(){
 	
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check the old password was entered
 	if (data.old.value == '' || reWhiteSpace.test(data.old.value)){
 		alert('Your old password must be entered.');
 		return;
 	}
 	
 	// check the new password was entered
 	if (data.password.value == '' || reWhiteSpace.test(data.password.value)){
 		alert('Your new password must be entered.');
 		return;
 	}
 	
 	// check the new password was confirmed
 	if (data.confirm.value == ''){
 		alert('Your new password must be confirmed.');
 		return;
 	}
 	
 	// check the new and confirmed new passwords match
 	if (data.password.value != data.confirm.value){
 		alert('Your new password and confirmed passwords do not match.');
 		return;
 	}
 	
 	// proceed with action
 	data.link.value='distributor/process_password.php';
 	data.submit();
 }
 
 
 
 
 
 /*
 * Function to check the issue user update administrator form
 * @param	none
 * @return	void
 */
 function checkUserUpdateForm(){
 	
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check a subject entered
 	if (data.subject.value == '' || reWhiteSpace.test(data.subject.value)){
 		alert('A subject must be entered.');
 		return;
 	}
 	
 	// check a body was entered
 	if (data.body.value == '' || reWhiteSpace.test(data.body.value)){
 		alert('A body must be entered.');
 		return;
 	}
 	
 	// proceed with action
 	data.action = 'process.php';
 	data.link.value='admin/process_newupdate.php';
 	data.submit();
 }
 
 
 
 
 
 /**
 * Function to check the registered owner form
 * @param	none
 * @return	void
 */
 function checkRegisteredOwnerForm(){
 	
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check a subject entered
 	if (data.key.value == '' || reWhiteSpace.test(data.key.value)){
 		alert('A license key must be entered.');
 		return;
 	}
 	
 	// proceed with action
 	data.submit();
 }
 
 
 
 
 
 /**
 * Function to check if a user wants to remove a news item
 * @param	id of news to be removed
 * @return	void
 */
 function checkRemoveNewsForm(id){
 	
 	// ask user if they are sure they want to remove the news item
 	var proceed = confirm("Are you sure that you want to remove this news item?");
 	
 	// if user clicked 'OK', continue
 	if (proceed){
 		data.mode.value='remove';
 		data.id.value=id;
 		data.link.value='admin/process_news.php';
 		data.action='process.php';
 		data.submit();
 	}
 	
 }
 
 
 
 
 
 
 
 /*
 * Function to check the add to basket
 * @param	param_product
 * @param	param_available
 * @return	void
 */
 function checkAddToBasketForm(param_product, param_available){

 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check a valid quantity has been entered
 	if (reWhiteSpace.test(data.quantity.value) || !isPosInt(data.quantity.value) || data.quantity.value==0){
 		alert("A valid quantity must be entered.");
 		return;
 	}
 	
 	// check the quantity is equal to or less than the max available
 	if (param_available < data.quantity.value){
 		alert("There are only "+param_available+" copies of this item available. Please enter a valid quantity and try again.");
 		return;
 	}
 	
 	data.product.value=param_product;
 	data.link.value='store/process_addtobasket.php';
	data.action='process.php';
	data.submit();
 }
 
 
 
 
 
 /*
 * Function to check the purchase delivery address form
 * @param	none
 * @return	void
 */
 function checkOrderAddressForm(){
 	
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// if they have selected to load an existing address
 	if (data.addressradio[0].checked){
 		
 		// check an address has been selected
 		if (data.address.selectedIndex == 0){
 			alert("An address must be selected.");
 			return;
 		}
 	
 	// if they have selected to enter a new address
 	} else {
 	
 		// check line1 has been entered
 		if (data.line1.value == '' || reWhiteSpace.test(data.line1.value)){
 			alert("Line 1 of the new address must be entered.");
 			return;
 		}
 		
 		// check that a post code has been entered
 		if (data.postcode.value == '' || reWhiteSpace.test(data.postcode.value)){
 			alert("A post code for the new address must be entered.");
 			return;
 		}
 		
 		// check that a country has been entered
 		if (data.country.value == '' || reWhiteSpace.test(data.country.value)){
 			alert("A country for the the new address must be entered.");
 			return;
 		}
 	}
 	
 	data.link.value='store/confirm.php';
 	data.action='store.php';
 	data.submit();
 }
 
 
 
 
 /**
 * Function to check and submit the drag coefficient form
 * @param int id
 * @return none
 * */
 function checkDragCoefficientForm(id){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check 'make' entry field
 	if (data.make.value == '' || reWhiteSpace.test(data.make.value)){
 		alert('A make must be entered.');
 		return;
 	}
 	
 	// check 'model' entry field
 	if (data.model.value == '' || reWhiteSpace.test(data.model.value)){
 		alert('A model must be entered.');
 		return;
 	}
 	
 	// if the Cd is not a number
 	if(isNaN(data.cd.value) || data.cd.value<0){
 		alert("The Cd value must be a positive number.");
 		return;
 	}
 	
 	data.id.value=id;
 	data.mode.value='save';
 	data.link.value='admin/process_dragcoefficient.php';
 	data.action='process.php';
 	data.submit();
 }
 
 
 
 /**
 * Function to check if a user wants to remove a drag coefficient
 * @param	id of drag coefficient to be removed
 * @return	void
 */
 function checkRemoveDragCoefficientForm(id){
 	
 	// ask user if they are sure they want to remove the drag coefficient
 	var proceed = confirm("Are you sure that you want to remove this drag coefficient item?");
 	
 	// if user clicked 'OK', continue
 	if (proceed){
 		data.mode.value='remove';
 		data.id.value=id;
 		data.link.value='admin/process_dragcoefficient.php';
 		data.action='process.php';
 		data.submit();
 	}
 }
 
 
 
 
 /**
 * Function to check and submit the chassis form
 * @param int id
 * @return none
 * */
 function checkChassisForm(id){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check 'make' entry field
 	if (data.make.value == '' || reWhiteSpace.test(data.make.value)){
 		alert('A make must be entered.');
 		return;
 	}
 	
 	// check 'model' entry field
 	if (data.model.value == '' || reWhiteSpace.test(data.model.value)){
 		alert('A model must be entered.');
 		return;
 	}
 	
 	// if the mass is not a number
 	if(isNaN(data.mass.value) || data.mass.value<0){
 		alert("The mass value must be a positive number.");
 		return;
 	}
 	
 	// if the wheelbase is not a number
 	if(isNaN(data.wheelbase.value) || data.wheelbase.value<0){
 		alert("The wheelbase value must be a positive number.");
 		return;
 	}
 	
 	// if the wgtsplitfr is not a number
 	if(isNaN(data.wgtsplitfr.value) || data.wgtsplitfr.value<0){
 		alert("The wgt split fr value must be a positive number.");
 		return;
 	}
 	
 	// if the height is not a number
 	if(isNaN(data.height.value) || data.height.value<0){
 		alert("The height value must be a positive number.");
 		return;
 	}
 	
 	// if the width is not a number
 	if(isNaN(data.width.value) || data.width.value<0){
 		alert("The width value must be a positive number.");
 		return;
 	}
 	
 	data.id.value=id;
 	data.mode.value='save';
 	data.link.value='admin/process_chassis.php';
 	data.action='process.php';
 	data.submit();
 }
 
 
 
 /**
 * Function to check if a user wants to remove a chassis
 * @param	id of chassis record to be removed
 * @return	void
 */
 function checkRemoveChassisForm(id){
 	
 	// ask user if they are sure they want to remove the chassis record
 	var proceed = confirm("Are you sure that you want to remove this chassis record?");
 	
 	// if user clicked 'OK', continue
 	if (proceed){
 		data.mode.value='remove';
 		data.id.value=id;
 		data.link.value='admin/process_chassis.php';
 		data.action='process.php';
 		data.submit();
 	}
 }
 
 
 
 
 
 /**
 * Function to check and submit the gearbox form
 * @param int id
 * @return none
 * */
 function checkGearboxForm(id){
 
 	reWhiteSpace = new RegExp(/^\s+$/);
 	
 	// check 'make' entry field
 	if (data.make.value == '' || reWhiteSpace.test(data.make.value)){
 		alert('A make must be entered.');
 		return;
 	}
 	
 	// check 'model' entry field
 	if (data.model.value == '' || reWhiteSpace.test(data.model.value)){
 		alert('A model must be entered.');
 		return;
 	}
 	
 	// if g1 ratio is not a number
 	if(isNaN(data.g1ratio.value) || data.g1ratio.value<0){
 		alert("The gear 1 ratio value must be a positive number.");
 		return;
 	}
 	
 	// if g2 ratio is not a number
 	if(isNaN(data.g2ratio.value) || data.g2ratio.value<0){
 		alert("The gear 2 ratio value must be a positive number.");
 		return;
 	}
 	
 	// if g3 ratio is not a number
 	if(isNaN(data.g3ratio.value) || data.g3ratio.value<0){
 		alert("The gear 3 ratio value must be a positive number.");
 		return;
 	}
 	
 	// if g4 ratio is not a number
 	if(isNaN(data.g4ratio.value) || data.g4ratio.value<0){
 		alert("The gear 4 ratio value must be a positive number.");
 		return;
 	}
 	
 	// if g5 ratio is not a number
 	if(isNaN(data.g5ratio.value) || data.g5ratio.value<0){
 		alert("The gear 5 ratio value must be a positive number.");
 		return;
 	}
 	
 	// if g6 ratio is not a number
 	if(isNaN(data.g6ratio.value) || data.g6ratio.value<0){
 		alert("The gear 6 ratio value must be a positive number.");
 		return;
 	}
 	
 	// if g7 ratio is not a number
 	if(isNaN(data.g7ratio.value) || data.g7ratio.value<0){
 		alert("The gear 7 ratio value must be a positive number.");
 		return;
 	}
 	
 	// if final drive ratio is not a number
 	if(isNaN(data.finaldriveratio.value) || data.finaldriveratio.value<0){
 		alert("The final drive ratio value must be a positive number.");
 		return;
 	}
 	
 	data.id.value=id;
 	data.mode.value='save';
 	data.link.value='admin/process_gearbox.php';
 	data.action='process.php';
 	data.submit();
 }
 
 
 
 /**
 * Function to check if a user wants to remove a gearbox
 * @param	id of gearbox record to be removed
 * @return	void
 */
 function checkRemoveGearboxForm(id){
 	
 	// ask user if they are sure they want to remove the gearbox record
 	var proceed = confirm("Are you sure that you want to remove this gearbox record?");
 	
 	// if user clicked 'OK', continue
 	if (proceed){
 		data.mode.value='remove';
 		data.id.value=id;
 		data.link.value='admin/process_gearbox.php';
 		data.action='process.php';
 		data.submit();
 	}
 }