

(function(jQuery){

		jQuery.fn.linkedSelect = function(url,destination,params) {

			var params = jQuery.extend({

				firstOption : 'Please Select',

				loadingText : 'Loading...'

			},params);

			var jQuerydest = jQuery(destination);

			return this.each(function(){

				jQuery(this).bind('change', function() {

					var jQueryjQuery = jQuery(this);

					jQuerydest.attr('disabled','false')
					.append('<option value="">' +params.loadingText+ '</option>')
					.ajaxStart(function(){

						jQueryjQuery.show();

					});

					jQuery.getJSON(url,{str: jQueryjQuery.val() }, function(j){

						if (j.length > 0) {

							var options = '<option value="">' +params.firstOption+ '</option>';

							for (var i = 0; i < j.length; i++) {

								options += '<option value="' + j[i].optionValue + '" class="' + j[i].optionClass + '">' + j[i].optionDisplay + '</option>';

							}

						}

						jQuerydest.removeAttr('disabled')
						.html(options)
						.find('option:first')
						.attr('selected', 'selected');

					}); // end getJSON

				});  // end change

			}); // end return each

		};  // end function

})(jQuery);



