$(document).ready( function( ) {
	$('#filter_form select').change( function( ) {
		// disable all the inputs
		$('#filter_form select').attr('disabled', true);

		var $this = $(this);
		var myregex;
		var id = $this.attr('id');
		var loc = window.location+'';
		var val = $this.find(':selected').val( );

		// remove any trailing slash
		if ('/' == loc.charAt(loc.length - 1)) {
			loc = loc.substr(0, loc.length - 1);
		}

		// remove any page information
		myregex = new RegExp('\\/page:\\d+', 'igm');
		loc = loc.replace(myregex, '');

		if (0 <= loc.indexOf('index')) {
			if (0 <= loc.indexOf(id+':')) {
				if ('' == val) {
					// remove the filter marker
					myregex = new RegExp('\\/'+id+':\\d+', 'igm');
					loc = loc.replace(myregex, '');
				}
				else {
					// replace the value there with the new one
					myregex = new RegExp('('+id+':)\\d+', 'igm');
					loc = loc.replace(myregex, '$1'+val);
				}
			}
			else {
				loc = loc+'/'+id+':'+val;
			}
		}
		else {
			loc = loc+'/index/'+id+':'+val;
		}

		window.location = loc;
	});
});