document.observe("dom:loaded", function(){
	
	var FormWatcher = Class.create({
		initialize: function(formElement, watchFields) {
			this.formElement = $(formElement);
			this.watchFields = watchFields;
			for (var i = 0; i < watchFields.length; i++) {
				$(this.watchFields[i]).observe('change', this.onchange.bindAsEventListener(this));
			}
		},
		onchange: function(evt) {
			this.formElement.submit();
		}
	});
	
	//var formWatcher = new FormWatcher('hpi_search_form', ['manufacturer', 'model', 'trim', 'doors', 'body', 'colour', 'transmission_type', 'fuel_type']);
	//var formWatcher = new FormWatcher('hpi_search_form', ['manufacturer', 'model', 'trim']);
	var formWatcher = new FormWatcher('hpi_search_form', ['manufacturer', 'model']);
});
