/**
 * Dynamic Select
 * Populate and repopulate a select on the fly.
 *
 * Copyright (c) 2009 PJ Dietz
 * Version: 1.00
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * http://pjdietz.com/jquery-plugins/dynamic-select/
 */
(function($){var DynamicSelect;DynamicSelect=function(element,options){this.domSelect=element;this.domSelect.data('dynamicSelect',this);if(typeof options==="object"&&typeof options.filter==="function"){this.filter=options.filter;}};DynamicSelect.prototype={filter:function(options){return options;},set:function(value){this.domSelect.val(value);this.domSelect.change();},setFilter:function(func){this.filter=func;},update:function(opts){var
opt,subopt,option,optgroup,i,u,j,v;this.domSelect.empty();opts=this.filter(opts);for(i=0,u=opts.length;i<u;i+=1){opt=opts[i];if(!$.isArray(opt.value)){option=$("<option></option").attr("value",opt.value).text(opt.label);this.domSelect.append(option);}
else{optgroup=$('<optgroup></optgroup>').attr('label',opt.label);for(j=0,v=opt.value.length;j<v;j+=1){subopt=opt.value[j];optgroup.append($('<option></option>').attr('value',subopt.value).text(subopt.label));}
this.domSelect.append(optgroup);}}
this.domSelect.change();}};if(typeof $.fn.dynamicSelect==="undefined"){$.fn.extend({dynamicSelect:function(){var method,options;if(typeof arguments[0]!=="string"){method="create";options=arguments[0];}
else{method=arguments[0];options=arguments[1];}
return this.each(function(){var ds;ds=$(this).data("dynamicSelect");if(typeof ds==="undefined"){ds=new DynamicSelect($(this),options);}
switch(method){case"set":ds.set(options);break;case"setFilter":ds.setFilter(options);break;case"update":ds.update(options);break;}});}});}}(jQuery));

