if(!Function.prototype.apply){Function.prototype.apply=function(oScope,args){var sarg=[];var rtrn,call;if(!oScope){oScope=window}if(!args){args=[]}for(var i=0;i<args.length;i++){sarg[i]="args["+i+"]"}call="oScope.__applyTemp__("+sarg.join(",")+");";oScope.__applyTemp__=this;rtrn=eval(call);oScope.__applyTemp__=null;return rtrn}}function alternativeScrollIntoView(i,f){var e=i;e.scrollTop=0;var a=e.getClientRects()[0];var g=a.top;var d=a.bottom;var b=f.getClientRects()[0].bottom;if(b==0){return}while(b>d||b<g){var c="down";if(b<g){c="up"}e.doScroll(c);b=f.getClientRects()[0].bottom}}(function(a){a.ajaxAutocompleter=function(b,d,c){if(!b||!document.getElementById(b)){throw new Error("Input field missing or invalid")}if(!d){throw new Error("Autocompleter requires server side URL")}this.element=a("#"+b).get(0);this.url=d;this.listElem=[];this.opt=a.extend({listID:"list_container_div",listClassName:"autocomplete_menu",minChars:1,noMatchText:"::No matches found::",frequency:500,match:"all",highlightClass:"highlight",listWidth:350,listHeight:100,listZIndex:100,hideElemId:[],loadingImgID:null,updateElement:null,beforeXHRCallback:null,global_var_name:b+"_autocomplete",listValueProperty:"ac_value",closeListOnEscape:true,method:"GET",post_data:{},headers:{},ZF_params_style:false,hide_no_results:false,onEnterCallback:function(){},firstItemHighlighted:true,showDirectionsDiv:false,dummy:""},c||{});this.list=a('<div id="'+this.opt.listID+'" class="'+this.opt.listClassName+'" style="width:'+this.opt.listWidth+"px;height:"+this.opt.listHeight+'px;"></div>').appendTo("body").get(0);var g="To close the list, click outside of it";if(this.opt.closeListOnEscape){g+=" or press Esc"}this.list.title=g;window[this.opt.global_var_name]=this;this.oldVal="";this.newVal="";this.isActive=false;this.isOpen=false;this.launchSearch=false;this.hasChanged=false;this.activeIndex=undefined;this.listItems=null;this.listItemsNo=0;this.element.onkeyup=this.close(this,this.initSearch);this.element.onkeypress=this.close(this,this.onKeyPress);this.searchObserver=null;a(this.element).attr("autocomplete","off");a(this.list).css("display","none");this.blurObserver=null;this.element.hasFocus=false;this.element.onblur=this.close(this,this.onBlur);this.list.onblur=this.close(this,this.onBlur);this.list.onfocus=this.close(this,this.onFocus);this.element.onfocus=this.close(this,this.onFocus);this.ifr=null;this.browser_ver=parseFloat(a.browser.version.substring(0,3));this.isIE=a.browser.msie;this.isIE7=this.isIE&&(this.browser_ver>=7);if(this.isIE&&this.opt.closeListOnEscape){this.element.onkeydown=this.close(this,this.onKeyDown)}var i=/Chrome/;this.isChrome=i.test(navigator.userAgent);var e=/Apple/;this.isSafari=e.test(navigator.vendor);var f=this.opt.global_var_name;a(window).scroll(function(){var j=window[f];j.onScroll()})};a.ajaxAutocompleter.prototype={close:function(b,c,d){if(null==d){return function(){return c.apply(b,arguments)}}else{return function(){return c.apply(b,d)}}},isIEFix:function(){if(typeof this.isIE5=="undefined"){this.isIE5=a.browser.msie&&(this.browser_ver==5)}if(this.isIE5&&(typeof this.hideElemId=="undefined")){this.hideElemId=this.opt.hideElemId}if(typeof this.useIframe=="undefined"){this.useIframe=a.browser.msie&&(this.browser_ver>=5)&&(this.browser_ver<7)}return this.useIframe},initSearch:function(d){var b=d||window.event;if(b&&(a.browser.msie||this.isChrome||this.isSafari)&&this.isOpen){var c=b.keyCode;if(c==37||c==38||c==39||c==40){this.onKeyPress(b);return}}if(this.searchObserver){clearTimeout(this.searchObserver)}else{this.searchObserver=setTimeout(this.close(this,this.initSearch),this.opt.frequency);return}this.oldVal=this.newVal;this.newVal=a.trim(this.element.value);if(this.newVal!=this.oldVal){this.launchSearch=false;this.hasChanged=false;this.searchObserver=setTimeout(this.close(this,this.initSearch),this.opt.frequency)}else{if(!this.hasChanged){if(this.isOpen){this.hideList()}if(this.newVal.length>=this.opt.minChars){this.performSearch(this.newVal)}}}},performSearch:function(b){if(this.opt.loadingImgID){a("#"+this.opt.loadingImgID).show()}var e=this;this.listElem=[];if(this.opt.beforeXHRCallback){this.opt.beforeXHRCallback()}if(!this.opt.ZF_params_style){if(this.url.indexOf("?")==-1){this.url_end="?"}else{this.url_end="&"}}else{if(this.url.indexOf("/")==this.url.length){this.url_end=""}else{this.url_end="/"}}var d="&",c="=";if(this.opt.ZF_params_style){d=c="/"}a.ajax({url:e.url+e.url_end+"value"+c+encodeURIComponent(b)+d+"match"+c+e.opt.match,type:e.opt.method,dataType:"json",beforeSend:function(f){var g;for(h in e.opt.headers){g=e.opt.headers[h];f.setRequestHeader(h,g)}},success:function(n){e.listElem=n;var m='style="';if(e.opt.listWidth){m+="width:"+e.opt.listWidth+"px;"}if(e.opt.listHeight){m+="height:"+e.opt.listHeight+"px;"}m+='"';var q="<ul "+m+">";var k=(e.opt.match=="all"?new RegExp(b,"i"):new RegExp("^"+b,"i"));var j;var o;var g,r;var f=false;var l;var p;for(o=0;o<e.listElem.length;o++){g=e.listElem[o];r=g[e.opt.listValueProperty].toString();l=r.match(k);if(l!==null){p="";for(var s in g){if(g[s]!=""){if(s!=e.opt.listValueProperty){p+=" "+s+'="'+g[s]+'"'}}}j='<span class="'+e.opt.highlightClass+'">'+l[0]+"</span>";q+="<li "+e.opt.listValueProperty+'="'+e.htmlspecialchars(r)+'"'+p+">"+r.replace(k,j)+"</li>";f=true}}if(!f){q+="<li "+e.opt.listValueProperty+'="'+b+'">'+e.opt.noMatchText+"</li>"}q+="</ul>";e.onFinishSearch(q,f)}})},onFinishSearch:function(b,c){this.hideLoadingImg();if(!c&&this.opt.hide_no_results){return}this.list.innerHTML=b;this.listItems=this.list.getElementsByTagName("li");this.listItemsNo=this.listItems.length;if(this.firstItemHighlighted){this.activeIndex=0;this.listItems[this.activeIndex].className="selected"}else{this.activeIndex=undefined}if((this.listItemsNo>=2)||(this.listItems[0].innerHTML.indexOf(this.opt.noMatchText)==-1)){this.attachListMouseEvents()}else{this.listItems[0].index=0;this.listItems[0].onclick=this.close(this,this.hideList);this.listItems[0].title="Click to close"}this.showList();this.element.focus();this.element.hasFocus=true;this.list_ul=this.list.getElementsByTagName("ul")[0];this.list_ul.scrollTop=0;if(this.isChrome||this.isSafari){this.list_ul.onscroll=this.close(this,this.onFocus)}},hideLoadingImg:function(){if(this.opt.loadingImgID){a("#"+this.opt.loadingImgID).hide()}},showList:function(){this.isOpen=true;if(!this.list.style.position){this.list.style.position="absolute";var e=a(this.element).offset();a(this.list).css("top",(e.top+a(this.element).outerHeight())+"px");a(this.list).css("left",e.left+"px");this.list.style.zIndex=this.opt.listZIndex}if(this.opt.showDirectionsDiv){a(this.list).append('<div style="font-size:10px;background-color:#dcdcdc;">*'+this.list.title+"</div>")}a(this.list).fadeIn("fast");if(this.isIEFix()){if(this.isIE5){for(var c=0;c<this.hideElemId.length;c++){a("#"+this.hideElemId[c]).hide()}}else{var b=a(this.list).offset();var f=a(this.list).outerHeight();var d=a(this.list).outerWidth();var g=document.createElement("IFRAME");g.setAttribute("src","");g.scrolling="no";g.frameBorder="0";g.style.zIndex=this.list.style.zIndex-10;g.style.position="absolute";g.style.border=0;a(g).css("left",b.left+"px");a(g).css("top",b.top+"px");a(g).css("width",d+"px");a(g).css("height",f+"px");g.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";g.style.display="block";this.ifr=g;document.body.appendChild(this.ifr)}}},hideList:function(){this.isOpen=false;this.hasChanged=false;a(this.list).hide();if(this.isIEFix()){if(this.isIE5){for(var b=0;b<this.hideElemId.length;b++){a("#"+this.hideElemId[b]).show()}}else{if(this.ifr){document.body.removeChild(this.ifr);this.ifr=null}}}},attachListMouseEvents:function(){var c;var b;var d=this;for(c=0;c<this.listItemsNo;c++){this.listItems[c].index=c;this.listItems[c].onmouseover=this.close(this,this.handleListMouseEvents);this.listItems[c].onmouseout=this.close(this,this.handleListMouseEvents);this.listItems[c].onmousedown=this.close(this,this.handleListMouseEvents);a(this.listItems[c]).find("span."+this.opt.highlightClass).mousedown(function(e){(d.close(d,d.handleListMouseEvents,[e]))()})}},handleListMouseEvents:function(b){var f=b||window.event;if(f){var i=f.type;var d=f.srcElement?f.srcElement:(f.target?f.target:null);if(d){var g=d.tagName.toLowerCase();var c=(g=="li")?d:d.parentNode;if(c&&(c.tagName.toLowerCase()=="li")){switch(i){case"mouseover":if((typeof this.activeIndex!=="undefined")&&(this.listItems[this.activeIndex].className=="selected")){this.listItems[this.activeIndex].className=""}c.className="selected";this.activeIndex=c.index;break;case"mouseout":c.className="";break;case"click":case"mousedown":if(this.opt.updateElement){(this.opt.updateElement)(c)}else{this.updateElement(c)}this.element.focus();break;default:break}this.stopEvt(f)}}}},updateElement:function(b){this.hideList();this.hasChanged=true;this.oldVal=this.newVal;if(this.activeIndex){this.newVal=this.listItems[this.activeIndex].getAttribute(this.opt.listValueProperty)}else{this.newVal=b.getAttribute(this.opt.listValueProperty)}this.newVal=this.stripslashes(this.newVal);this.element.value=this.newVal;this.oldVal=this.newVal;if(this.searchObserver){clearTimeout(this.searchObserver)}},onKeyDown:function(b){var c=b||window.event;if(c.keyCode==27){this.onKeyPress(c);return false}if(c.keyCode==13){if(c.srcElement.id==this.element.id){if(this.opt.onEnterCallback){return this.opt.onEnterCallback.call()}return false}}},onKeyPress:function(c){if(!this.isOpen){return}var f=c||window.event;if(f.keyCode==9||f.keyCode==13){if(typeof this.activeIndex!="undefined"){if(this.opt.updateElement){(this.opt.updateElement)(this.listItems[this.activeIndex])}else{this.updateElement(this.listItems[this.activeIndex])}return false}}else{if(f.keyCode==38){if(typeof this.activeIndex!="undefined"){this.listItems[this.activeIndex].className="";this.activeIndex=this.activeIndex==0?this.listItemsNo-1:this.activeIndex-1}else{this.activeIndex=this.listItemsNo-1}this.listItems[this.activeIndex].className="selected";this.list_ul=this.list.getElementsByTagName("ul")[0];if(this.activeIndex==this.listItemsNo-1){this.list_ul.scrollTop=this.list_ul.scrollHeight+this.list_ul.offsetHeight;if(a.browser.msie){this.listItems[this.activeIndex].scrollIntoView(false)}}var b=this.listItems[this.activeIndex].offsetTop;if(b<this.list_ul.scrollTop){this.list_ul.scrollTop=this.list_ul.scrollTop-this.listItems[this.activeIndex].offsetHeight}}else{if(f.keyCode==40){if(typeof this.activeIndex!="undefined"){this.listItems[this.activeIndex].className="";this.activeIndex=this.activeIndex==(this.listItemsNo-1)?0:this.activeIndex+1}else{this.activeIndex=0}this.listItems[this.activeIndex].className="selected";this.list_ul=this.list.getElementsByTagName("ul")[0];if(this.activeIndex==0){this.list_ul.scrollTop=0}var d=this.listItems[this.activeIndex].offsetTop+this.listItems[this.activeIndex].offsetHeight;if(d>(this.list_ul.scrollTop+this.list_ul.offsetHeight)){this.list_ul.scrollTop=this.list_ul.scrollTop+this.listItems[this.activeIndex].offsetHeight}}else{if(f.keyCode==37||f.keyCode==39){this.hasChanged=true;return}else{if((f.keyCode==27)&&this.opt.closeListOnEscape){if(this.searchObserver){clearTimeout(this.searchObserver)}this.stopEvt(f);this.element.blur();this.hideList();return}}}}}this.hasChanged=true;this.stopEvt(f);if(this.searchObserver){clearTimeout(this.searchObserver)}this.searchObserver=setTimeout(this.close(this,this.initSearch),this.opt.frequency)},stopEvt:function(b){if(b.stopPropagation){b.stopPropagation()}b.cancelBubble=true},onBlur:function(b){if(this.isOpen){var d=b||window.event;if(d){var c=d.srcElement?d.srcElement:(d.target?d.target:null);this.blurObserver=setTimeout(this.close(this,this.hideList),250);if(c.id==this.element.id){this.element.hasFocus=false}}}},onFocus:function(b){if(this.blurObserver){clearTimeout(this.blurObserver)}var d=b||window.event;if(d){var c=d.srcElement?d.srcElement:(d.target?d.target:null);if(c.id==this.element.id){this.element.hasFocus=true}else{this.element.hasFocus=false}if(this.isChrome&&d.type=="scroll"){this.element.focus()}}},addslashes:function(b){return(b+"").replace(/([\\"'])/g,"\\$1").replace(/\0/g,"\\0")},stripslashes:function(b){return(b+"").replace(/\0/g,"0").replace(/\\([\\'"])/g,"$1")},htmlspecialchars:function(d,g){var f={},e="",b="",c="";b=d.toString();if(false===(f=this.get_html_translation_table("HTML_SPECIALCHARS",g))){return false}for(e in f){c=f[e];b=b.split(e).join(c)}return b},get_html_translation_table:function(k,g){var e={},j={},d=0,b="";var f={},c={};var l={},i={};f[0]="HTML_SPECIALCHARS";f[1]="HTML_ENTITIES";c[0]="ENT_NOQUOTES";c[2]="ENT_COMPAT";c[3]="ENT_QUOTES";l=!isNaN(k)?f[k]:k?k.toUpperCase():"HTML_SPECIALCHARS";i=!isNaN(g)?c[g]:g?g.toUpperCase():"ENT_COMPAT";if(l!=="HTML_SPECIALCHARS"&&l!=="HTML_ENTITIES"){throw Error("Table: "+l+" not supported")}e["38"]="&amp;";if(i!=="ENT_NOQUOTES"){e["34"]="&quot;"}if(i==="ENT_QUOTES"){e["39"]="&#039;"}e["60"]="&lt;";e["62"]="&gt;";if(l==="HTML_ENTITIES"){e["160"]="&nbsp;";e["161"]="&iexcl;";e["162"]="&cent;";e["163"]="&pound;";e["164"]="&curren;";e["165"]="&yen;";e["166"]="&brvbar;";e["167"]="&sect;";e["168"]="&uml;";e["169"]="&copy;";e["170"]="&ordf;";e["171"]="&laquo;";e["172"]="&not;";e["173"]="&shy;";e["174"]="&reg;";e["175"]="&macr;";e["176"]="&deg;";e["177"]="&plusmn;";e["178"]="&sup2;";e["179"]="&sup3;";e["180"]="&acute;";e["181"]="&micro;";e["182"]="&para;";e["183"]="&middot;";e["184"]="&cedil;";e["185"]="&sup1;";e["186"]="&ordm;";e["187"]="&raquo;";e["188"]="&frac14;";e["189"]="&frac12;";e["190"]="&frac34;";e["191"]="&iquest;";e["192"]="&Agrave;";e["193"]="&Aacute;";e["194"]="&Acirc;";e["195"]="&Atilde;";e["196"]="&Auml;";e["197"]="&Aring;";e["198"]="&AElig;";e["199"]="&Ccedil;";e["200"]="&Egrave;";e["201"]="&Eacute;";e["202"]="&Ecirc;";e["203"]="&Euml;";e["204"]="&Igrave;";e["205"]="&Iacute;";e["206"]="&Icirc;";e["207"]="&Iuml;";e["208"]="&ETH;";e["209"]="&Ntilde;";e["210"]="&Ograve;";e["211"]="&Oacute;";e["212"]="&Ocirc;";e["213"]="&Otilde;";e["214"]="&Ouml;";e["215"]="&times;";e["216"]="&Oslash;";e["217"]="&Ugrave;";e["218"]="&Uacute;";e["219"]="&Ucirc;";e["220"]="&Uuml;";e["221"]="&Yacute;";e["222"]="&THORN;";e["223"]="&szlig;";e["224"]="&agrave;";e["225"]="&aacute;";e["226"]="&acirc;";e["227"]="&atilde;";e["228"]="&auml;";e["229"]="&aring;";e["230"]="&aelig;";e["231"]="&ccedil;";e["232"]="&egrave;";e["233"]="&eacute;";e["234"]="&ecirc;";e["235"]="&euml;";e["236"]="&igrave;";e["237"]="&iacute;";e["238"]="&icirc;";e["239"]="&iuml;";e["240"]="&eth;";e["241"]="&ntilde;";e["242"]="&ograve;";e["243"]="&oacute;";e["244"]="&ocirc;";e["245"]="&otilde;";e["246"]="&ouml;";e["247"]="&divide;";e["248"]="&oslash;";e["249"]="&ugrave;";e["250"]="&uacute;";e["251"]="&ucirc;";e["252"]="&uuml;";e["253"]="&yacute;";e["254"]="&thorn;";e["255"]="&yuml;"}for(d in e){b=String.fromCharCode(d);j[b]=e[d]}return j},onScroll:function(){try{var b=a(this.element).offset();a(this.list).css("top",(b.top+a(this.element).outerHeight())+"px");a(this.list).css("left",b.left+"px")}catch(c){}},dummy:""}})(jQuery);
