function validator(form) {

	// reset all error status on this panel
	clearErrors(form);

	// set form validity to be true initially
	valid = true;
	
	form.find(':input').each(function() {

		// will only validate a field with an ID
		if (this.id) {
		
			currentInput = this;
		
			// normalise ID by stripping out passenger count number
			getId = currentInput.id.split('_')[0];
			
			// test if field ID is logged in fields object
			if (fields[getId]) {
				
				fieldRule = fields[getId];
				
				// test if field ID is a required field and has validation actions
				if (fieldRule.required) {
				
					if (currentInput.value == '') {
					
						// visual notification of validation failure
						displayError(currentInput);
						
						// update global validation state with local result		
						valid = false;
						
					}
					
				}
				
				if (fieldRule.actions) {
				
					stringToValidate = currentInput.value;
				
					// iterate over the validation actions
					$.each(fieldRule.actions,function(name,value) {
					
						// test if there is a function for this validation action
						if (rules[name]) {
							
							// test validation action
							internalValidity = rules[name](stringToValidate,value);
							
							// if failed...
							if (!internalValidity) {

								// visual notification of validation failure
								displayError(currentInput);

								// update global validation state with local result							
								valid = false;
								
								return false;
								
							}
							
						} else {

							console.log("can't find validation rule for " + name + ' ' + value);
						
						}
						
						
					});
				
				}
				
			}
			
		}
	
	});
	
	return valid;

}

var rules = {

	string: function(value,test) {
		if (typeof test == 'boolean') {
			testVal = (value != '') ? true : false;
		} else {
			temp = test.join('|');
			testVal = (temp.match(value) != '') ? true : false;
		}
		return testVal;
	},
	regexp: function(value,test) {	
		myregex = new RegExp(test);
		testVal = (value.match(myregex)) ? true : false;
		return testVal;	
	},
	minLength: function(value,test) {	
		testVal = (value.length >= test) ? true : false;
		return testVal;
	},
	maxLength: function(value,test) {
		testVal = (value.length <= test) ? true : false;
		return testVal;
	},
	phonenumber: function(value,test) {		
		testVal = (value.match(/^[\d\s]*$/)) ? true: false;
		return testVal;
	},
	integer: function(value,test) {
		testVal = (value.match(/^\d*$/)) ? true : false;
		return testVal;
	},
	minInclusive: function(value,test) {
		testVal = (parseInt(value) >= parseInt(test)) ? true : false;
		return testVal;	
	},
	maxInclusive: function(value,test) {
		testVal = (parseInt(test) >= parseInt(value)) ? true : false;
		return testVal;	
	},
	minExclusive: function(value,test) {
		testVal = (parseInt(value) > parseInt(test)) ? true : false;
		return testVal;	
	},
	maxExclusive: function(value,test) {
		testVal = (parseInt(test) > parseInt(value)) ? true : false;
		return testVal;	
	}
}
