	
	//default validation message used if none supplied
	validation_msg = 'Please check all fields.';
	
	//enter field,message pairs into the array
	required_fields = ['enquiry','Please make sure you have entered an enquiry.',
					   'email','Please make sure you have entered your email address.',
					   'name','Please make sure you have entered your name.',
					   'phone','Please make sure you have entered your phone number.'];
	
	jQuery(document).ready(function() {
				
		//make sure that all fields are completed...
		$("#contact_form").submit( function(){
				if (validate_fields()) {
					$.blockUI({ message: $('#msg') });
					$(this).ajaxSubmit({
						target: '#result',
						data: {
							ss_ajax:'contact_form'
						}
					});
				} else {
					alert(validation_msg);
				}
				return false;
		});
		
		$("#enquiry_type").change(function() {
			if ($(this).val() == "Information Request") {
				$("#enquiry").val('Please supply me with the following pieces of information:\n\n1. Copies of Financials\n2. Tax File Number (TFN)\n3. Australian Business Number (ABN)\n4. Australian Company Number (ACN)\n5. ATO Running Balance Accounts\n\n(Please remove any items which are not applicable, or add any additional items.)');
			}
			
		});
		
	});
	
	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;	
		}
	}
