(function(a){a.cpSelectBox={currentUrlParams:null,numPerPage:20,activeSelect:null,popupWrapper:null,lockMenu:false,popupMouseOver:false,firstPopupMouseUp:true,scrollBarWidth:null,o:{loadUsedValues:false,widthHeightMode:"client",optionBorderHeight:0,additionalWrapperWidth:0,popupStretch:true,popupStretchMaxWidth:500,popupMarginTop:0,popupExtraWidth:0,selectWrapPosition:"select",selectInputParentClass:null,onFocusCallback:null,onBlurCallback:null},buildSelectBox:function(c){return this.each(function(){var j=this;j.o=a.extend(true,{},a.cpSelectBox.o);j.o=a.extend(j.o,c||{});var h=(j.tagName=="SELECT"?j:a(j).find("select").get(0));if(h==undefined){return false}j.origSelect=h;j.sstatus=0;j.inputFocused=false;setTimeout(function(){a.cpSelectBox.chooseOption(j)},1);h.reset=function(){a.cpSelectBox.chooseOption(j,0)};var f;if(j.o.selectWrapPosition=="select"){a(h).wrap('<div style="width: '+a.cpSelectBox.getWidth(j,h)+'px;" />');f=a(h).parent()}else{if(j.o.selectWrapPosition=="fhWrapper"){a(j).wrap("<div />");f=a(j).parent()}else{a(j).find("."+j.o.selectWrapPosition).wrap("<div />");f=a(j).find("."+j.o.selectWrapPosition).parent()}}f.css({position:"relative"});j.selectWrap=f;f.addClass("sb_selectWrap");f.wrap("<div />");j.allWrap=f.parent();var d=document.createElement("INPUT");a(d).attr({type:"text",value:"",tabindex:"-1",style:"cursor: default;"}).addClass("fhIgnore");(j.o.selectInputParentClass!=null?a(j).find("."+j.o.selectInputParentClass):f).append(d);j.selectInput=d;var e;if(j.o.selectWrapPosition=="select"){a(d).wrap('<div class="cpSB_selectWrapOuter"><div class="cpSB_selectWrapInner" style="position: relative;"></div></div>');e=a(d).parent()}else{e=f}var g=document.createElement("DIV");a(g).html("<div class='cpSB_dropdownIcon'><hr style='display: none;' /></div>");a(g).attr({style:"position: absolute; width: 100%; left: 0; top: 0;"}).addClass("cpSB_inputOverlay");setTimeout(function(){a(g).css("height",a.cpSelectBox.getHeight(j,d)+"px")},1);e.append(g);var i=document.createElement("INPUT");a(i).attr({type:"text",style:"position: absolute; left: -9999px; top: 0; width: 1px; height: 1px; border: 0;"}).addClass("fhIgnore");f.append(i);j.hControllerInput=i;a(h).css("display","none");a(h).attr({tabindex:"-1"});a(d).focus(function(){setTimeout(function(){a(i).focus()},1)});a(g).mousedown(function(k){if(k.button==((a.browser.msie&&parseInt(a.browser.version,10)<9)?1:0)){a.cpSelectBox.openPopup(j);a.cpSelectBox.firstPopupMouseUp=false;a("body").unbind("mouseup",a.cpSelectBox.mouseUpHandler).bind("mouseup",a.cpSelectBox.mouseUpHandler);setTimeout(function(){a(i).focus()},1)}return false});a(d).mousedown(function(k){if(k.button==((a.browser.msie&&parseInt(a.browser.version,10)<9)?1:0)){a.cpSelectBox.openPopup(j);a.cpSelectBox.firstPopupMouseUp=false;a("body").unbind("mouseup",a.cpSelectBox.mouseUpHandler).bind("mouseup",a.cpSelectBox.mouseUpHandler)}setTimeout(function(){a(i).focus()},1);return false});a(d).keypress(function(){setTimeout(function(){a(i).focus()},1)});a(i).focus(function(){if(j.o.onFocusCallback!=null){j.o.onFocusCallback(j)}var k=a(window).scrollLeft();j.inputFocused=true;clearTimeout(j.closePopupTimer);if(a.cpSelectBox.activeSelect!=null&&a.cpSelectBox.activeSelect!=f){a.cpSelectBox.activeSelect.removeClass("cpSB_inputActive");a.cpSelectBox.activeSelect=f;f.addClass("cpSB_inputActive")}else{if(a.cpSelectBox.popupWrapper==null){f.addClass("cpSB_inputActive")}}a(i).val("");if(k>0){setTimeout(function(){a(window).scrollLeft(k)},1)}});a(i).blur(function(){j.inputFocused=false;if(a.cpSelectBox.popupWrapper==null){f.removeClass("cpSB_inputActive")}j.closePopupTimer=setTimeout(function(){a.cpSelectBox.closePopup(j)},100)});a(i).keydown(function(l){var k=true;if(a.cpSelectBox.popupWrapper!=null&&a.cpSelectBox.firstPopupMouseUp&&((l.keyCode>=33&&l.keyCode<=40)||l.keyCode==13)){j.chosen=(+a(j.sbActive).attr("sbI"))}switch(l.keyCode){case 27:if(a.cpSelectBox.popupWrapper!=null){a.cpSelectBox.closePopup(j)}break;case 13:if(a.cpSelectBox.popupWrapper!=null){a.cpSelectBox.chooseOption(j,j.chosen);a.cpSelectBox.closePopup(j)}break;case 38:case 37:case 40:case 39:a.cpSelectBox.chooseOption(j,j.chosen+(l.keyCode<=38?-1:1));break;case 36:a.cpSelectBox.chooseOption(j,0);break;case 35:a.cpSelectBox.chooseOption(j,h.length-1);break;case 33:a.cpSelectBox.chooseOption(j,(j.chosen>(a.cpSelectBox.numPerPage-1)?(j.chosen-(a.cpSelectBox.numPerPage-1)):0));break;case 34:a.cpSelectBox.chooseOption(j,(j.chosen<(h.length-(a.cpSelectBox.numPerPage-1))?(j.chosen+(a.cpSelectBox.numPerPage-1)):(h.length-1)));break;default:var m=a(this);if(j.sstatus<3){timeout=setTimeout(function(){var o=m.val().toLowerCase();if(o!=""){if(j.sstatus==0){j.sstatus=1;if(a.cpSelectBox.popupWrapper!=null){j.origChosen=(+a(j.sbActive).attr("sbI"))}else{j.origChosen=j.chosen}j.firstAlphaPos=-1;var p=a(h).find("option:isw('"+o.charAt(0)+"')");j.alphaPos=new Array();if(p.length>0){p.each(function(q){var r=a(this).prevAll().size();j.alphaPos.push(r);if(j.firstAlphaPos==-1&&r>j.origChosen){j.firstAlphaPos=q}});if(j.firstAlphaPos==-1){j.firstAlphaPos=0}}}if(j.sstatus==1&&o.length>1&&o.charAt(o.length-1)!=o.charAt(o.length-2)){j.sstatus=2}if(j.sstatus==1){if(j.alphaPos.length>0){a.cpSelectBox.chooseOption(j,j.alphaPos[((j.firstAlphaPos+o.length-1)%j.alphaPos.length)])}else{j.sstatus=3}}else{var p=a(h).find("option:isw('"+o+"')");if(p.length>0){var n;if(p.length>1){p.each(function(q){var r=a(this).prevAll().size();if(q==0){n=r}if(r>j.origChosen){n=r;return false}})}else{n=p.prevAll().size();j.sstatus=3}a.cpSelectBox.chooseOption(j,n)}else{j.sstatus=3}}}},1)}clearTimeout(j.resetTypeTimer);j.resetTypeTimer=setTimeout(function(){m.val("");j.sstatus=0},1000);k=false;break}if(k){l.returnValue=false;l.cancelBubble=true;return false}})})},chooseOption:function(g,h,k){if(a.cpSelectBox.popupWrapper==null||a.cpSelectBox.firstPopupMouseUp){if(h==undefined&&g.o.loadUsedValues){a.cpSelectBox.getUrlParams();if(a.cpSelectBox.currentUrlParams[g.origSelect.name]){h=g.origSelect.selectedIndex}else{h=0}}if(h<0){h=0}if(h>(g.origSelect.length-1)){h=(g.origSelect.length-1)}g.chosen=h;g.origSelect.selectedIndex=h;a(g.selectInput).val(g.origSelect[g.origSelect.selectedIndex].text);if(a.cpSelectBox.popupWrapper!=null&&k!==false){var j=a(g.popupBoxInner).find("div:eq("+h+")");a(g.sbActive).removeClass("cpSB_puActive");j.addClass("cpSB_puActive");g.sbActive=j.get(0);var c=a(g.popupBoxInner).scrollTop();var d=c+(g.oHeight*a.cpSelectBox.numPerPage)-1;var i=(g.oHeight*h);var f=i+g.oHeight-1;if(!((i>=c)&&(f<=d))){var e=i;if(i>c){e=f-((g.oHeight*a.cpSelectBox.numPerPage)-1);if(h==(g.origSelect.length-1)){e=(g.oHeight*g.origSelect.length)+5}}else{if(h==0){e=0}}a(g.popupBoxInner).scrollTop(e)}}}},closePopup:function(c){if(a.cpSelectBox.lockMenu!==true){clearTimeout(c.closePopupTimer);a(c.popupBox).css({display:"none"});if(a.cpSelectBox.activeSelect!=c.selectWrap){c.selectWrap.removeClass("cpSB_inputActive")}else{a.cpSelectBox.popupWrapper=null;a("body").unbind("mousewheel",a.cpSelectBox.mouseWheelHandler);if(c.inputFocused){c.selectWrap.addClass("cpSB_inputActive")}else{if(c.o.onBlurCallback!=null){c.o.onBlurCallback(c)}}}}},openPopup:function(e){a(document).mousedown();if(a.cpSelectBox.popupWrapper!=null){if(a.cpSelectBox.popupWrapper==e){a.cpSelectBox.closePopup(a.cpSelectBox.popupWrapper);return false}else{a.cpSelectBox.closePopup(a.cpSelectBox.popupWrapper)}}if(a.cpSelectBox.activeSelect!=null&&a.cpSelectBox.activeSelect!=e.selectWrap){a.cpSelectBox.activeSelect.removeClass("cpSB_inputActive")}a.cpSelectBox.activeSelect=e.selectWrap;a.cpSelectBox.popupWrapper=e;e.selectWrap.removeClass("cpSB_inputActive");var i=e.popupBox;if(i==undefined){i=document.createElement("DIV");a(i).attr({style:"position: absolute; "+(!e.o.popupStretch?("width: "+(a.cpSelectBox.getWidth(e,e)+e.o.popupExtraWidth)+"px; "):"")+"margin-top: "+(a.cpSelectBox.getHeight(e,e.selectInput)+e.o.popupMarginTop)+"px;"}).addClass("cpSB_popup");var k=document.createElement("DIV");a(k).attr({style:"overflow-x: hidden; overflow-y: auto; white-space: nowrap;"}).addClass("cpSB_popupInner");a(i).append(k);a(e.origSelect).find("option").each(function(n){var m=document.createElement("DIV");if(e.o.optionBorderHeight!=0){var l=document.createElement("SPAN");a(l).css({display:"block"});a(l).html(a(this).text());a(m).append(l)}else{a(m).html(a(this).text())}if(this.selected){a(m).addClass("cpSB_puActive");e.sbActive=m}a(m).mouseover(function(){a(e.sbActive).removeClass("cpSB_puActive");a(this).addClass("cpSB_puActive");e.sbActive=this});a(m).mouseup(function(){if(a.cpSelectBox.firstPopupMouseUp){a.cpSelectBox.chooseOption(e,n);a.cpSelectBox.lockMenu=false;a.cpSelectBox.closePopup(e)}});a(m).attr({style:"cursor: default;",sbi:n});a(k).append(m)});e.selectWrap.before(a(i));e.oHeight=a.cpSelectBox.getHeight(e,a(k).find((e.o.optionBorderHeight!=0?"span":"div")+":eq(0)").get(0))+e.o.optionBorderHeight;a(k).css({height:(e.oHeight*(e.origSelect.length>a.cpSelectBox.numPerPage?a.cpSelectBox.numPerPage:e.origSelect.length))+"px"});a(i).mouseover(function(){a.cpSelectBox.popupMouseOver=e});a(i).mouseout(function(){a.cpSelectBox.popupMouseOver=false});a(i).mousedown(function(l){a.cpSelectBox.lockMenu=true;setTimeout(function(){a(e.hControllerInput).focus()},1);setTimeout(function(){a.cpSelectBox.lockMenu=false},125);a("body").unbind("mouseup",a.cpSelectBox.mouseUpHandler).bind("mouseup",a.cpSelectBox.mouseUpHandler);return false});e.popupBox=i;e.popupBoxInner=k;if(e.o.popupStretch){var h=a(i).width();var c=(a.cpSelectBox.getWidth(e,e)+e.o.popupExtraWidth)-e.o.additionalWrapperWidth;var f=(e.origSelect.length>a.cpSelectBox.numPerPage);var g=null;if(f){if(a.cpSelectBox.scrollBarWidth==null){a.cpSelectBox.scrollBarWidth=getScrollbarWidth()}g=h+a.cpSelectBox.scrollBarWidth;if(g<c){g=c}}else{if(h<c){g=c}}if(g!=null){a(k).css("width",(e.o.popupStretchMaxWidth&&g>e.o.popupStretchMaxWidth?e.o.popupStretchMaxWidth:g)+"px")}}}else{a(i).css({display:"block"});k=e.popupBoxInner}var d={top:parseInt(a(window).scrollTop()),left:parseInt(a(window).scrollLeft()),height:a(window).height(),width:a(window).width()};if(i.offHeight==undefined){i.offHeight=parseInt(a(i).offset().top+0.5);i.boxHeight=a.cpSelectBox.getHeight(e,i);i.boxWidth=a(i).width()}i.offWidth=parseInt(a(i).offset().left+0.5);if((i.offHeight+i.boxHeight)>(d.height+d.top)){a(i).css({"margin-top":(a.cpSelectBox.getHeight(e,e.selectInput)+e.o.popupMarginTop+((d.height+d.top)-(i.offHeight+i.boxHeight)))+"px"})}else{a(i).css({"margin-top":(a.cpSelectBox.getHeight(e,e.selectInput)+e.o.popupMarginTop)+"px"})}if((i.offWidth+i.boxWidth-parseInt(a(i).css("margin-left")))>(d.width+d.left)){a(i).css({"margin-left":((d.width+d.left)-(i.offWidth+i.boxWidth-parseInt(a(i).css("margin-left"))))+"px"})}else{a(i).css({"margin-left":0})}var j=a(k).find("div:eq("+e.origSelect.selectedIndex+")");a(e.sbActive).removeClass("cpSB_puActive");a(j).addClass("cpSB_puActive");e.sbActive=j;a(k).scrollTop(e.oHeight*e.chosen);a("body").unbind("mouseup",a.cpSelectBox.mouseUpHandler).bind("mouseup",a.cpSelectBox.mouseUpHandler).unbind("mousewheel",a.cpSelectBox.mouseWheelHandler).bind("mousewheel",a.cpSelectBox.mouseWheelHandler)},mouseWheelHandler:function(c,f){if(a.cpSelectBox.popupMouseOver!==false){var e=a.cpSelectBox.popupMouseOver;var d=a(e.popupBoxInner).scrollTop()+(-3*e.oHeight*f);if(d<5){d=0}else{if(d>(a(e.popupBoxInner).scrollTop()+(e.oHeight*a.cpSelectBox.numPerPage)-5)){d=(e.oHeight*e.origSelect.length)+5}}a(e.popupBoxInner).scrollTop(d)}return false},mouseUpHandler:function(){if(!a.cpSelectBox.firstPopupMouseUp){if(a.cpSelectBox.popupWrapper!=null){a(a.cpSelectBox.popupWrapper.hControllerInput).focus()}setTimeout(function(){a.cpSelectBox.firstPopupMouseUp=true},25)}a.cpSelectBox.lockMenu=false;a("body").unbind("mouseup",a.cpSelectBox.mouseUpHandler)},getWidth:function(d,c){return(d.o.widthHeightMode=="client"?c.offsetWidth:a(c).width())},getHeight:function(d,c){return(d.o.widthHeightMode=="client"?c.offsetHeight:a(c).height())},getUrlParams:function b(){a.cpSelectBox.currentUrlParams=new Object();if(window.location.search.length<=1){return}var e=window.location.search.substring(1);var d=e.split("&");for(var c=0;c<d.length;c++){a.cpSelectBox.currentUrlParams[d[c].split("=")[0]]=decodeURIComponent(d[c].split("=")[1])}}};a.fn.buildSelectBox=a.cpSelectBox.buildSelectBox})(jQuery);jQuery.expr[":"].isw=function(c,d,b){return(c.textContent||c.innerText||"").toLowerCase().indexOf(b[3].toLowerCase())==0};function getScrollbarWidth(){var c=$('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');$("body").append(c);var b=$("div",c).innerWidth();c.css("overflow-y","scroll");var a=$("div",c).innerWidth();$(c).remove();return(b-a)}(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(i){var g=i||window.event,f=[].slice.call(arguments,1),j=0,h=true,e=0,d=0;i=c.event.fix(g);i.type="mousewheel";if(i.wheelDelta){j=i.wheelDelta/120}if(i.detail){j=-i.detail/3}d=j;if(g.axis!==undefined&&g.axis===g.HORIZONTAL_AXIS){d=0;e=-1*j}if(g.wheelDeltaY!==undefined){d=g.wheelDeltaY/120}if(g.wheelDeltaX!==undefined){e=-1*g.wheelDeltaX/120}f.unshift(i,j,e,d);return c.event.handle.apply(this,f)}})(jQuery);
