;(function($) {
	$.fn.provideFilters = function(options){
		options = jQuery.extend({
			excluded: [],
			fieldsToChangeBoundingBox: [],
			mandatory: [],
			changeBoundingBox: function(){},
			delay: 2000
		},options);
		this.each(
			function(){
				new $.FilterProvider(this, options);
			}
		);
		return this;
	};	
	$.FilterProvider = function(form, options){
		var $form = $(form);
		var timeoutP;
		$form.find(":input").bind("change",function(){
			$("#errorMsgCon").hide();
			if(exists(this,options.excluded)){
				return true;
			}
			if(!checkMandatories()){
				enableSubmit();
				return true;
			}
			if(exists(this,options.fieldsToChangeBoundingBox) && typeof options.changeBoundingBox == 'function'){
				options.changeBoundingBox();
			}
            //setSearchStatus("#readyToSearchTxt");
			clearTimeout(timeoutP);
			timeoutP = setTimeout(function(){sendSubmit();}, options.delay);
		});
		if(jQuery.browser.msie){
			$("input[type='checkbox']").unbind( 'click' );
			$("input[type='radio']").unbind( 'click' );
			$("input[type='checkbox']").bind( 'click', function() {
			    $(this).trigger( 'change' );
			});
			$("input[type='radio']").bind( 'click', function() {
				$(this).trigger( 'change' );
			});
		}
		function sendSubmit(){
			if (typeof options.submitHandler == 'function') {
				options.submitHandler($form);
			} else {
				$form.submit();
			}
		}
		function exists(obj,arr){
			return $.inArray(obj.name,arr) > -1;
		}
		function checkMandatories(){
			for ( var i = 0; i < options.mandatory.length; i++) {
				if($(options.mandatory[i]).val() == '') return false;
			}
			return true;
		}
	};
})(jQuery);