	
	//default validation message used if none supplied
	validation_msg = 'Please check all fields.';
	
	//enter field,message pairs into the array
	required_fields = ['business_name','Please make sure you have entered your business name.',
					   'email','Please make sure you have entered a contact email address.'];
	
	jQuery(document).ready(function() {
				
		//make sure that all fields are completed...
		$("#change_of_details_form").submit( function(){
				if (validate_fields()) {
					$.blockUI({ message: $('#msg') });
					$(this).ajaxSubmit({
						target: '#result',
						data: {
							ss_ajax:'change_of_details_form'
						}
					});
				} else {
					alert(validation_msg);
				}
				return false;
		});
		
	});
	
	function unblock_form() {
		$.unblockUI();
	}
	
	function validate_fields() {
		
		//check required fields
		for(i=0;i<required_fields.length;i+=2) {
			var cv = required_fields[i];
			var t = i+1;
			var msg = required_fields[t];
			val_to_check = $('#'+cv).fieldValue();
			if (!val_to_check[0]) {
				validation_msg = msg;
				return false;
			}
			//if the name of the field contains email then make sure it is a valid email
			if (cv.search(/email/) != -1 && ! is_valid_email(val_to_check)) {
				validation_msg = 'Sorry, the email address you entered appears to be incorreect, please check it.';
				return false;
			}
		}
		
		//add any further validation here
		
		return true;
	}
	
	function is_valid_email(val) {
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(val)) {
			return true;
		} else {
			return false;	
		}
	}
