﻿/*
 * Compressed by JSA(www.xidea.org)
 */
(function($){$.fn.addOption=function(){var E=function(B,$,A,_){var E=document.createElement("option");E.value=$,E.text=A;var C=B.options,D=C.length;if(!B.cache){B.cache={};for(var F=0;F<D;F++)B.cache[C[F].value]=F}if(typeof B.cache[$]=="undefined")B.cache[$]=D;B.options[B.cache[$]]=E;if(_)E.selected=true},C=arguments;if(C.length==0)return this;var A=true,D=false,B,$,_;if(typeof(C[0])=="object"){D=true;B=C[0]}if(C.length>=2){if(typeof(C[1])=="boolean")A=C[1];else if(typeof(C[2])=="boolean")A=C[2];if(!D){$=C[0];_=C[1]}}this.each(function(){if(this.nodeName.toLowerCase()!="select")return;if(D){for(var C in B)E(this,C,B[C],A)}else E(this,$,_,A)});return this};$.fn.ajaxAddOption=function(D,B,A,C,_){if(typeof(D)!="string")return this;if(typeof(B)!="object")B={};if(typeof(A)!="boolean")A=true;this.each(function(){var E=this;$.getJSON(D,B,function(B){$(E).addOption(B,A);if(typeof C=="function")if(typeof _=="object")C.apply(E,_);else C.call(E)})});return this};$.fn.removeOption=function(){var B=arguments;if(B.length==0)return this;var A=typeof(B[0]),$,_;if(A=="string"||A=="object"||A=="function"){$=B[0];if($.constructor==Array){var C=$.length;for(var D=0;D<C;D++)this.removeOption($[D],B[1]);return this}}else if(A=="number")_=B[0];else return this;this.each(function(){if(this.nodeName.toLowerCase()!="select")return;if(this.cache)this.cache=null;var A=false,C=this.options;if(!!$){var D=C.length;for(var E=D-1;E>=0;E--){if($.constructor==RegExp){if(C[E].value.match($))A=true}else if(C[E].value==$)A=true;if(A&&B[1]===true)A=C[E].selected;if(A)C[E]=null;A=false}}else{if(B[1]===true)A=C[_].selected;else A=true;if(A)this.remove(_)}});return this};$.fn.sortOptions=function(A){var B=$(this).selectedValues(),_=typeof(A)=="undefined"?true:!!A;this.each(function(){if(this.nodeName.toLowerCase()!="select")return;var A=this.options,B=A.length,$=[];for(var C=0;C<B;C++)$[C]={v:A[C].value,t:A[C].text};$.sort(function(A,$){o1t=A.t.toLowerCase(),o2t=$.t.toLowerCase();if(o1t==o2t)return 0;if(_)return o1t<o2t?-1:1;else return o1t>o2t?-1:1});for(C=0;C<B;C++){A[C].text=$[C].t;A[C].value=$[C].v}}).selectOptions(B,true);return this};$.fn.selectOptions=function(D,_){var A=D,E=typeof(D);if(E=="object"&&A.constructor==Array){var C=this;$.each(A,function(){C.selectOptions(this,_)})}var B=_||false;if(E!="string"&&E!="function"&&E!="object")return this;this.each(function(){if(this.nodeName.toLowerCase()!="select")return this;var $=this.options,_=$.length;for(var C=0;C<_;C++)if(A.constructor==RegExp){if($[C].value.match(A))$[C].selected=true;else if(B)$[C].selected=false}else if($[C].value==A)$[C].selected=true;else if(B)$[C].selected=false});return this};$.fn.selectOptionsByText=function($){this.each(function(){var _=this.options,A=_.length;for(var B=0;B<A;B++)if(_[B].text==$)this.selectedIndex=B})};$.fn.copyOptions=function(A,B){var _=B||"selected";if($(A).size()==0)return this;this.each(function(){if(this.nodeName.toLowerCase()!="select")return this;var B=this.options,C=B.length;for(var D=0;D<C;D++)if(_=="all"||(_=="selected"&&B[D].selected))$(A).addOption(B[D].value,B[D].text)});return this};$.fn.containsOption=function(_,C){var D=false,$=_,A=typeof($),B=typeof(C);if(A!="string"&&A!="function"&&A!="object")return B=="function"?this:D;this.each(function(){if(this.nodeName.toLowerCase()!="select")return this;if(D&&B!="function")return false;var _=this.options,A=_.length;for(var E=0;E<A;E++)if($.constructor==RegExp){if(_[E].value.match($)){D=true;if(B=="function")C.call(_[E],E)}}else if(_[E].value==$){D=true;if(B=="function")C.call(_[E],E)}});return B=="function"?this:D};$.fn.selectedValues=function(){var $=[];this.selectedOptions().each(function(){$[$.length]=this.value});return $};$.fn.selectedTexts=function(){var $=[];this.selectedOptions().each(function(){$[$.length]=this.text});return $};$.fn.selectedOptions=function(){return this.find("option:selected")}})(jQuery)