

(function($){

   $.fn.linkedSelect = function(url,destination,params) {

      var params = $.extend({

         firstOption : 'Please Select',

         loadingText : 'Loading...'

      },params);

      var $dest = $(destination);

      return this.each(function(){

         $(this).bind('change', function() {

            var $$ = $(this);

            $dest.attr('disabled','false')
                 .append('<option value="">' +params.loadingText+ '</option>')
                 .ajaxStart(function(){

                    $$.show();

            });
            $.get(url, {str: $$.val() }, function(response){
              
				//alert("response:" + response);
				
                  var options = '<option value="">' +params.firstOption+ '</option>';
                  options += response;
                     

               $dest.removeAttr('disabled')
                    .html(options)
                    .find('option:first')
                    .attr('selected', 'selected');

            }); // end getJSON            
			
           
         });  // end change

      }); // end return each

   };  // end function

})(jQuery);