(function(f){var b=38,i=40,h=13,c=27,j=115;f.widget("ui.combobox",{init:function(){var o=this;var m=this.options;var n=f('<input type = "text" />');if(this.element[0].tagName.toLowerCase()=="select"){a(m,this.element)}function q(){o.hideList();f(document).unbind("click",q)}this.arrowElem=f(this.options.arrowHTML.call(this)).click(function(s){if(o.isListVisible()){o.hideList()}else{o.showList();f(document).click(q)}return false});function k(s,t){var u=o.element.attr(s);if(u){if(s=="class"){t.addClass(u)}else{t.attr(s,u)}}}k("class",n);k("name",n);k("title",n);k("dir",n);k("lang",n);k("xml:lang",n);k("size",n);k("value",n);var r=m.data[0];var p=new RegExp("^<[^>]+>([^<]+)</[^>]+>$","g");var l=p.exec(m.listHTML(r,0));if(l!=null&&l.length>1){n.attr("value",l[1])}if(this.element.attr("maxlength")!=-1){n.attr("maxlength",this.element.attr("maxlength"))}this.oldElem=this.element.unbind("getData.combobox").unbind("setData.combobox").unbind("remove").after(this.arrowElem).after(n).remove();this.listElem=this.buildList().insertAfter(this.arrowElem).hide();k("id",n);k("class",this.listElem);k("class",this.arrowElem);this.element=n.keyup(function(s){if(s.which==j){o.showList(s)}}).change(e(this,"fireEvent","select"));if(m.autoShow){this.element.focus(e(this,"showList")).blur(function(s){o.finishSelection(o.selectedIndex,s);o.hideList()})}},_init:function(){this.init.apply(this,arguments)},cleanup:function(){if(this.boundKeyHandler){f(document).unbind("keyup",this.boundKeyHandler)}this.arrowElem.remove();this.listElem.remove()},destroy:function(){var k=this.element;this.element=this.oldElem.insertBefore(this.arrowElem);k.remove()},setData:function(k,m){this.options[k]=m;if(k=="disabled"&&this.isListVisible()){this.hideList()}if(k=="data"||k=="listContainerTag"||k=="listHTML"){var l=this.isListVisible();this.listElem=this.buildList().replaceAll(this.listElem);this[l?"showList":"hideList"]()}},buildList:function(){var n=this;var l=this.options;var k=l.listContainerTag;var m=f("<"+k+' class = "ui-combobox-list"></'+k+">");f.each(l.data,function(o,p){f(l.listHTML(p,o)).appendTo(m).click(e(n,"finishSelection",o)).mouseover(e(n,"changeSelection",o))});return m},isListVisible:function(){return this.listElem.is(":visible")},showList:function(m){if(this.options.disabled){return}var k=this.element.position();k.top+=this.element.height()+5;k.width=this.element.width();k.position="absolute";this.boundKeyHandler=e(this,"keyHandler");f(document).keyup(this.boundKeyHandler);f(".ui-combobox-list").hide();this.listElem.css(k).show();this.changeSelection(this.findSelection(),m);var o=f(window).scrollTop();var n=f(".ui-combobox-list").height();var l=n+o;f(window).scrollTop(l)},hideList:function(){this.listElem.hide();f(document).unbind("keyup",this.boundKeyHandler)},keyHandler:function(m){if(this.options.disabled){return}var l=this.options.data.length;switch(m.which){case c:this.hideList();break;case b:var k=this.selectedIndex-1;if(k<0){k=l-1}this.changeSelection(k,m);break;case i:this.changeSelection((this.selectedIndex+1)%l,m);break;case h:this.finishSelection(this.selectedIndex,m);break;default:this.fireEvent("key",m);this.changeSelection(this.findSelection());break}},prepareCallbackObj:function(l){l=l||this.element.val();var k=f.inArray(l,this.options.data);return{value:l,index:k,isCustom:k==-1,inputElement:this.element,listElement:this.listElement}},fireEvent:function(k,l,m){this.element.triggerHandler("combobox"+k,[l,this.prepareCallbackObj(m)],this.options[k])},findSelection:function(){var n=this.options.data;var o=this.element.val().toLowerCase();for(var m=0,k=n.length;m<k;++m){var l=n[m].toLowerCase().indexOf(o);if(l==0){return m}}if(this.options.matchMiddle){for(var m=0,k=n.length;m<k;++m){var l=n[m].toLowerCase().indexOf(o);if(l!=-1){return m}}}return 0},changeSelection:function(k,l){this.selectedIndex=k;this.listElem.children(".selected").removeClass("selected");this.listElem.children(":eq("+k+")").addClass("selected");if(l){this.fireEvent("change",l,this.options.data[k])}},finishSelection:function(o,p){var k=this.options.data[o];var n=new RegExp("^<[^>]+>([^<]+)</[^>]+>$","g");var q=n.exec(this.options.listHTML(k,o));if(q!=null&&q.length>1){this.element.val(q[1])}this.hideList();this.fireEvent("select",p);var l=location.href;n=new RegExp("^http://([^/]+)/.*$","ig");var s=n.exec(l);if(s!=null&&s.length>1){var m=s[1];if(k!=undefined&&k!=""&&k!=-1&&k!=-2){var r=m+"/"+k;r=r.replace("//","/");window.location="http://"+r}}}});f.extend(f.ui.combobox,{getter:"getData",version:"1.0.6",defaults:{data:[],autoShow:true,matchMiddle:true,change:function(l,k){},select:function(l,k){},key:function(l,k){},arrowURL:"/gc_1_0/images/structure/drop_down.png",arrowHTML:function(){return f('<img class = "ui-combobox-arrow" border = "0" src = "'+this.options.arrowURL+'" width = "18" height = "22" />')},listContainerTag:"span",listHTML:d}});var g=f.fn.combobox;f.fn.combobox=function(){var k=g.apply(this,arguments);if(!(k instanceof f)){return k}var l=false;var m=f(f.map(k,function(p){var n=f.data(p,"combobox");if(n&&n.element[0]!=p){l=true;var o=n.element[0];f.data(o,"combobox",n);return o}else{return p}}));return !l?k:m.bind("setData.combobox",function(p,n,o){return f.data(this,"combobox").setData(n,o)}).bind("getData.combobox",function(o,n){return f.data(this,"combobox").getData(n)}).bind("remove",function(){return f.data(this,"combobox").cleanup()})};function d(o,k){var l=o;if(o.indexOf("FFFFFF")==-1){var n="";var m=o;if(o.indexOf(" - ")>-1){n=o.substring(0,o.indexOf(" - ")+2);m=o.substring(o.indexOf(" - ")+3,o.length)}l="<span onmouseout=\"$(this).css('color','#6E6E6D');\" onmouseover=\"$(this).css('color','#87D300');\" class=\"rangename\">"+n+" <span>"+m+"</span></span>";return'<a class = "ui-combobox-item even">'+l+"</a>"}else{var l=o.substring(6,o.length)}return'<span class = "ui-combobox-item odd">'+l+"</span>"}function e(m,k){var l=[].slice.call(arguments,2);return function(){m[k].apply(m,l.concat([].slice.call(arguments)))}}function a(m,l){var n={},k=[];l.children().each(function(o){if(this.tagName.toLowerCase()=="option"){var q=f(this).text(),p=this.getAttribute("value")||q;n[p]=q;k.push(p)}});if(!m.data.length){m.data=k}if(m.listHTML==d){m.listHTML=function(p,o){return d(n[p]||p)}}}})(jQuery);
