﻿jQuery(function($) {
	$("input[name='ProviderType']").click(function() {
		var t = $(this).val().split(',');
		$("#Category,#Specialty").each(function() {
			var select = $(this);

			$.getJSON("/Search/" + $(this).attr("id") + "List",
					{ providerTypes: t },
					function(data) {
						select
							.clearSelect()
							.fillSelect(data);
					}
				);
		});
	});
});

$.fn.clearSelect = function() {
	return this.each(function() {
		if (this.tagName == 'SELECT')
			this.options.length = 0;
	});
};

$.fn.fillSelect = function(data) {
	return this
			.each(function() {
				if (this.tagName != 'SELECT')
					return;
				var dropdownList = this;
				$.each(data, function(index, option) {
					var option = new Option(option.Text, option.Value);
					if ($.browser.msie)
						dropdownList.add(option);
					else
						dropdownList.add(option, null);
				});
			});
};