(function(A){A.fn.addOption=function(){var H=function(N,J,L,O){var M=document.createElement("option");M.value=J,M.text=L;var P=N.options;var I=P.length;if(!N.cache){N.cache={};for(var K=0;K<I;K++){N.cache[P[K].value]=K}}if(typeof N.cache[J]=="undefined"){N.cache[J]=I}N.options[N.cache[J]]=M;if(O){M.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 B=arguments;if(B.length==0){return this}var D=typeof (B[0]);var C,E;if(D=="string"||D=="object"||D=="function"){C=B[0]}else{if(D=="number"){E=B[0]}else{return this}}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return }if(this.cache){this.cache=null}var F=false;var I=this.options;if(!!C){var G=I.length;for(var H=G-1;H>=0;H--){if(C.constructor==RegExp){if(I[H].value.match(C)){F=true}}else{if(I[H].value==C){F=true}}if(F&&B[1]===true){F=I[H].selected}if(F){I[H]=null}F=false}}else{if(B[1]===true){F=I[E].selected}else{F=true}if(F){this.remove(E)}}});return this};A.fn.sortOptions=function(C){var B=typeof (C)=="undefined"?true:!!C;this.each(function(){if(this.nodeName.toLowerCase()!="select"){return }var F=this.options;var D=F.length;var G=[];for(var E=0;E<D;E++){G[E]={v:F[E].value,t:F[E].text}}G.sort(function(I,H){o1t=I.t.toLowerCase(),o2t=H.t.toLowerCase();if(o1t==o2t){return 0}if(B){return o1t<o2t?-1:1}else{return o1t>o2t?-1:1}});for(var E=0;E<D;E++){F[E].text=G[E].t;F[E].value=G[E].v}});return this};A.fn.selectOptions=function(D,B){var C=D;var E=typeof (D);var F=B||false;if(E!="string"&&E!="function"&&E!="object"){return this}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return this}var I=this.options;var G=I.length;for(var H=0;H<G;H++){if(C.constructor==RegExp){if(I[H].value.match(C)){I[H].selected=true}else{if(F){I[H].selected=false}}}else{if(I[H].value==C){I[H].selected=true}else{if(F){I[H].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 J=this.options;var H=J.length;for(var I=0;I<H;I++){if(B.constructor==RegExp){if(J[I].value.match(B)){D=true;if(G=="function"){C.call(J[I])}}}else{if(J[I].value==B){D=true;if(G=="function"){C.call(J[I])}}}}});return G=="function"?this:D};A.fn.selectedValues=function(){var B=[];this.find("option:selected").each(function(){B[B.length]=this.value});return B}})(jQuery);