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