﻿//SEENI
//HOW THIS PLUGIN WORKS?
//

(function($) {
	$.fn.clearProductFilters = function(options) {
		var defaults = {
			formWrapperDivID: "",
			txtSearchID: ""
		};
		if (options) {
			$.extend(defaults, options);
		}

		// iterate over matched elements
		return this.each(function() {
			var $this = $(this);
			$this.click(function(e) {
				e.preventDefault();

				$("#" + options.formWrapperDivID).clearForm();

				var $txtSearch = $("#" + options.txtSearchID + ".clear_value");
				$txtSearch.val($txtSearch.attr("title"));
				$txtSearch.addClass("clear_value_off");

				$txtSearch.focus(function() {
					if ($(this).val() == $(this).attr("title")) {
						$(this).val("");
						$(this).removeClass("clear_value_off");
					}
				}).blur(function() {
					if ($(this).val() == "") {
						$(this).val($(this).attr("title"));
						$(this).addClass("clear_value_off");
					}
				});

				return false;
			});
		});
	};

	$.fn.clearForm = function() {
		// iterate each matching form
		return this.each(function() {
			// iterate the elements within the form
			$(':input', this).each(function() {
				var type = this.type, tag = this.tagName.toLowerCase();
				if (type == 'text' || type == 'password' || tag == 'textarea')
					this.value = '';
				else if (type == 'checkbox' || type == 'radio')
					this.checked = false;
				else if (tag == 'select')
					this.selectedIndex = 0;
			});
		});
	};	
	
})(jQuery);


