(function(a){a.fn.addOption=function(){var b=function(k,p,m,q){var n=document.createElement("option");n.value=p,n.text=m;var l=k.options;var o=l.length;if(!k.cache){k.cache={};for(var j=0;j<o;j++){k.cache[l[j].value]=j;}}if(typeof k.cache[p]=="undefined"){k.cache[p]=o;}k.options[k.cache[p]]=n;if(q){n.selected=true;}};var c=arguments;if(c.length==0){return this;}var d=true;var e=false;var f,g,h;if(typeof(c[0])=="object"){e=true;f=c[0];}if(c.length>=2){if(typeof(c[1])=="boolean"){d=c[1];}else{if(typeof(c[2])=="boolean"){d=c[2];}}if(!e){g=c[0];h=c[1];}}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return;}if(e){for(var i in f){b(this,i,f[i],d);}}else{b(this,g,h,d);}});return this;};a.fn.ajaxAddOption=function(i,f,j,h,k){if(typeof(i)!="string"){return this;}if(typeof(f)!="object"){f={};}if(typeof(j)!="boolean"){j=true;}this.each(function(){var b=this;a.getJSON(i,f,function(c){a(b).addOption(c,j);if(typeof h=="function"){if(typeof k=="object"){h.apply(b,k);}else{h.call(b);}}});});return this;};a.fn.removeOption=function(){var l=arguments;if(l.length==0){return this;}var h=typeof(l[0]);var m,c;if(h=="string"||h=="object"||h=="function"){m=l[0];if(m.constructor==Array){var f=m.length;for(var g=0;g<f;g++){this.removeOption(m[g],l[1]);}return this;}}else{if(h=="number"){c=l[0];}else{return this;}}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return;}if(this.cache){this.cache=null;}var e=false;var b=this.options;if(!!m){var i=b.length;for(var d=i-1;d>=0;d--){if(m.constructor==RegExp){if(b[d].value.match(m)){e=true;}}else{if(b[d].value==m){e=true;}}if(e&&l[1]===true){e=b[d].selected;}if(e){b[d]=null;}e=false;}}else{if(l[1]===true){e=b[c].selected;}else{e=true;}if(e){this.remove(c);}}});return this;};a.fn.sortOptions=function(d){var b=a(this).selectedValues();var c=typeof(d)=="undefined"?true:!!d;this.each(function(){if(this.nodeName.toLowerCase()!="select"){return;}var h=this.options;var e=h.length;var i=[];for(var f=0;f<e;f++){i[f]={v:h[f].value,t:h[f].text};}i.sort(function(g,j){o1t=g.t.toLowerCase(),o2t=j.t.toLowerCase();if(o1t==o2t){return 0;}if(c){return o1t<o2t?-1:1;}else{return o1t>o2t?-1:1;}});for(var f=0;f<e;f++){h[f].text=i[f].t;h[f].value=i[f].v;}}).selectOptions(b,true);return this;};a.fn.selectOptions=function(m,k){var h=m;var l=typeof(m);if(l=="object"&&h.constructor==Array){var c=this;a.each(h,function(){c.selectOptions(this,k);});}var f=k||false;if(l!="string"&&l!="function"&&l!="object"){return this;}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return this;}var d=this.options;var b=d.length;for(var e=0;e<b;e++){if(h.constructor==RegExp){if(d[e].value.match(h)){d[e].selected=true;}else{if(f){d[e].selected=false;}}}else{if(d[e].value==h){d[e].selected=true;}else{if(f){d[e].selected=false;}}}}});return this;};a.fn.copyOptions=function(c,f){var e=f||"selected";if(a(c).size()==0){return this;}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return this;}var d=this.options;var b=d.length;for(var g=0;g<b;g++){if(e=="all"||(e=="selected"&&d[g].selected)){a(c).addOption(d[g].value,d[g].text);}}});return this;};a.fn.containsOption=function(m,k){var h=false;var l=m;var c=typeof(l);var f=typeof(k);if(c!="string"&&c!="function"&&c!="object"){return f=="function"?this:h;}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return this;}if(h&&f!="function"){return false;}var d=this.options;var b=d.length;for(var e=0;e<b;e++){if(l.constructor==RegExp){if(d[e].value.match(l)){h=true;if(f=="function"){k.call(d[e],e);}}}else{if(d[e].value==l){h=true;if(f=="function"){k.call(d[e],e);}}}}});return f=="function"?this:h;};a.fn.selectedValues=function(){var b=[];this.selectedOptions().each(function(){b[b.length]=this.value;});return b;};a.fn.selectedTexts=function(){var b=[];this.selectedOptions().each(function(){b[b.length]=this.text;});return b;};a.fn.selectedOptions=function(){return this.find("option:selected");};})(jQuery);