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