/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */
(function($){$.fn.addOption=function(){var a=arguments;if(a.length==0){return this;}var sO=true;var m=false;if(typeof a[0]=="object"){m=true;var _5=a[0];}if(a.length>=2){if(typeof a[1]=="boolean"){sO=a[1];}else{if(typeof a[2]=="boolean"){sO=a[2];}}if(!m){var v=a[0];var t=a[1];}}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return;}if(m){for(var i in _5){$(this).addOption(i,_5[i],sO);}}else{var _9=document.createElement("option");_9.value=v;_9.text=t;var i;var r=false;var o=this.options;var oL=o.length;for(i=0;i<oL;i++){if(o[i].value==_9.value){r=true;break;}}if(i<oL&&!r){i=oL;}this.options[i]=_9;if(sO){o[i].selected=true;}}});return this;};$.fn.ajaxAddOption=function(_e,_f,_10,fn,_12){if(typeof _e!="string"){return this;}if(typeof _f!="object"){_f={};}if(typeof _10!="boolean"){_10=true;}this.each(function(){var el=this;$.getJSON(_e,_f,function(r){$(el).addOption(r,_10);if(typeof fn=="function"){if(typeof _12=="object"){fn.apply(el,_12);}else{fn.call(el);}}});});return this;};$.fn.removeOption=function(){var a=arguments;if(a.length==0){return this;}var ta=typeof a[0];if(ta=="string"){var v=a[0];}else{if(ta=="object"||ta=="function"){var v=a[0];}else{if(ta=="number"){var i=a[0];}else{return this;}}}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return;}if(v){var o=this.options;var oL=o.length;for(var i=oL-1;i>=0;i--){if(v.constructor==RegExp){if(o[i].value.match(v)){o[i]=null;}}else{if(o[i].value==v){o[i]=null;}}}}else{this.remove(i);}});return this;};$.fn.sortOptions=function(_1d){var a=typeof _1d=="undefined"?true:_1d;this.each(function(){if(this.nodeName.toLowerCase()!="select"){return;}var o=this.options;var oL=o.length;var sA=[];for(var i=0;i<oL;i++){sA[i]={v:o[i].value,t:o[i].text};}sA.sort(function(o1,o2){o1t=o1.t.toLowerCase();o2t=o2.t.toLowerCase();if(o1t==o2t){return 0;}if(a){return o1t<o2t?-1:1;}else{return o1t>o2t?-1:1;}});for(var i=0;i<oL;i++){o[i].text=sA[i].t;o[i].value=sA[i].v;}});return this;};$.fn.selectOptions=function(_26,_27){var v=_26;var vT=typeof _26;var c=_27||false;if(vT!="string"&&vT!="function"&&vT!="object"){return this;}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return this;}var o=this.options;var oL=o.length;for(var i=0;i<oL;i++){if(v.constructor==RegExp){if(o[i].value.match(v)){o[i].selected=true;}else{if(c){o[i].selected=false;}}}else{if(o[i].value==v){o[i].selected=true;}else{if(c){o[i].selected=false;}}}}});return this;};$.fn.copyOptions=function(to,_2f){var w=_2f||"selected";if($(to).size()==0){return this;}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return this;}var o=this.options;var oL=o.length;for(var i=0;i<oL;i++){if(w=="all"||(w=="selected"&&o[i].selected)){$(to).addOption(o[i].value,o[i].text);}}});return this;};$.fn.containsOption=function(_34,fn){var _36=false;var v=_34;var vT=typeof _34;var fT=typeof fn;if(vT!="string"&&vT!="function"&&vT!="object"){return fT=="function"?this:_36;}this.each(function(){if(this.nodeName.toLowerCase()!="select"){return this;}if(_36&&fT!="function"){return false;}var o=this.options;var oL=o.length;for(var i=0;i<oL;i++){if(v.constructor==RegExp){if(o[i].value.match(v)){_36=true;if(fT=="function"){fn.call(o[i]);}}}else{if(o[i].value==v){_36=true;if(fT=="function"){fn.call(o[i]);}}}}});return fT=="function"?this:_36;};})(jQuery);