if(typeof(bsn)=="undefined"){_b=bsn={}}if(typeof(_b.Autosuggest)=="undefined"){_b.Autosuggest={}}else{alert("Autosuggest is already set!")}_b.AutoSuggest=function(e,d){if(!document.getElementById){return 0}this.fld=_b.DOM.gE(e);if(!this.fld){return 0}this.sInp="";this.nInpC=0;this.aSug=[];this.iHigh=0;this.oP=d?d:{};var a,b={minchars:1,meth:"get",varname:"input",className:"autosuggest",timeout:3000,delay:500,offsety:-5,shownoresults:true,noresults:"No results!",maxheight:250,cache:true,maxentries:25};for(a in b){if(typeof(this.oP[a])!=typeof(b[a])){this.oP[a]=b[a]}}var c=this;this.fld.onkeypress=function(f){return c.onKeyPress(f)};this.fld.onkeyup=function(f){return c.onKeyUp(f)};this.fld.setAttribute("autocomplete","off")};_b.AutoSuggest.prototype.onKeyPress=function(e){var d=(window.event)?window.event.keyCode:e.keyCode;var c=13;var b=9;var f=27;var a=true;switch(d){case c:this.setHighlightedValue();a=false;break;case f:this.clearSuggestions();break}return a};_b.AutoSuggest.prototype.onKeyUp=function(e){var c=(window.event)?window.event.keyCode:e.keyCode;var b=38;var d=40;var a=true;switch(c){case b:this.changeHighlight(c);a=false;break;case d:this.changeHighlight(c);a=false;break;default:this.getSuggestions(this.fld.value)}return a};_b.AutoSuggest.prototype.getSuggestions=function(g){if(g==this.sInp){return 0}_b.DOM.remE(this.idAs);this.sInp=g;if(g.length<this.oP.minchars){this.aSug=[];this.nInpC=g.length;return 0}var d=this.nInpC;this.nInpC=g.length?g.length:0;var b=this.aSug.length;if(this.nInpC>d&&b&&b<this.oP.maxentries&&this.oP.cache){var a=[];for(var e=0;e<b;e++){if(this.aSug[e].value.substr(0,g.length).toLowerCase()==g.toLowerCase()){a.push(this.aSug[e])}}this.aSug=a;this.createList(this.aSug);return false}else{var f=this;var c=this.sInp;clearTimeout(this.ajID);this.ajID=setTimeout(function(){f.doAjaxRequest(c)},this.oP.delay)}return false};_b.AutoSuggest.prototype.doAjaxRequest=function(c){if(c!=this.fld.value){return false}var g=this;if(typeof(this.oP.script)=="function"){var d=this.oP.script(encodeURIComponent(this.sInp))}else{var d=this.oP.script+this.oP.varname+"="+encodeURIComponent(this.sInp)}if(!d){return false}var b=this.oP.meth;var c=this.sInp;var a=function(h){g.setSuggestions(h,c)};var e=function(h){alert("AJAX error: "+h)};var f=new _b.Ajax();f.makeRequest(d,b,a,e)};_b.AutoSuggest.prototype.setSuggestions=function(req,input){if(input!=this.fld.value){return false}this.aSug=[];if(this.oP.json){var jsondata=eval("("+req.responseText+")");for(var i=0;i<jsondata.results.length;i++){this.aSug.push({id:jsondata.results[i].id,value:jsondata.results[i].value,info:jsondata.results[i].info})}}else{var xml=req.responseXML;var results=xml.getElementsByTagName("results")[0].childNodes;for(var i=0;i<results.length;i++){if(results[i].hasChildNodes()){this.aSug.push({id:results[i].getAttribute("id"),value:results[i].childNodes[0].nodeValue,info:results[i].getAttribute("info")})}}}this.idAs="as_"+this.fld.id;this.createList(this.aSug)};_b.AutoSuggest.prototype.createList=function(b){var t=this;_b.DOM.remE(this.idAs);this.killTimeout();if(b.length==0&&!this.oP.shownoresults){return false}var h=_b.DOM.getPos(this.fld);var g=h.x+"px";var p=(h.y+this.fld.offsetHeight+this.oP.offsety)+"px";var r=this.fld.offsetWidth+"px";var o=new Element("div",{id:this.idAs,"class":this.oP.className,styles:{position:"absolute",top:p,left:g,width:r,"z-index":"9999"}});var d=new Element("div");var e=new Element("div",{"class":"as_corner"});var j=new Element("div",{"class":"as_bar"});var v=new Element("div",{"class":"as_header"});e.inject(v);j.inject(v);v.inject(o);var n=_b.DOM.cE("ul",{id:"as_ul"});for(var w=0;w<b.length;w++){var B=b[w].value;var s=B.toLowerCase().indexOf(this.sInp.toLowerCase());var l=B.substring(0,s)+"<em>"+B.substring(s,s+this.sInp.length)+"</em>"+B.substring(s+this.sInp.length);var u=_b.DOM.cE("span",{},l,true);if(b[w].info!=""){var z=_b.DOM.cE("br",{});u.appendChild(z);var k=_b.DOM.cE("small",{},b[w].info);u.appendChild(k)}var y=_b.DOM.cE("a",{href:"#"});var f=_b.DOM.cE("span",{className:"tl"}," ");var c=_b.DOM.cE("span",{className:"tr"}," ");y.appendChild(f);y.appendChild(c);y.appendChild(u);y.name=w+1;y.onclick=function(){t.setHighlightedValue();return false};y.onmouseover=function(){t.setHighlight(this.name)};var m=_b.DOM.cE("li",{},y);n.appendChild(m)}if(b.length==0&&this.oP.shownoresults){var m=_b.DOM.cE("li",{className:"as_warning"},this.oP.noresults);n.appendChild(m)}o.appendChild(n);var x=_b.DOM.cE("div",{className:"as_corner"});var A=_b.DOM.cE("div",{className:"as_bar"});var q=_b.DOM.cE("div",{className:"as_footer"});q.appendChild(x);q.appendChild(A);o.appendChild(q);o.onmouseover=function(){t.killTimeout()};o.onmouseout=function(){t.resetTimeout()};o.inject(document.body);this.iHigh=0;t=this;this.toID=setTimeout(function(){t.clearSuggestions()},this.oP.timeout)};_b.AutoSuggest.prototype.changeHighlight=function(a){var b=_b.DOM.gE("as_ul");if(!b){return false}var c;if(a==40){c=this.iHigh+1}else{if(a==38){c=this.iHigh-1}}if(c>b.childNodes.length){c=b.childNodes.length}if(c<1){c=1}this.setHighlight(c)};_b.AutoSuggest.prototype.setHighlight=function(b){var a=_b.DOM.gE("as_ul");if(!a){return false}if(this.iHigh>0){this.clearHighlight()}this.iHigh=Number(b);a.childNodes[this.iHigh-1].className="as_highlight";this.killTimeout()};_b.AutoSuggest.prototype.clearHighlight=function(){var a=_b.DOM.gE("as_ul");if(!a){return false}if(this.iHigh>0){a.childNodes[this.iHigh-1].className="";this.iHigh=0}};_b.AutoSuggest.prototype.setHighlightedValue=function(){if(this.iHigh){this.sInp=this.fld.value=this.aSug[this.iHigh-1].value;this.fld.focus();if(this.fld.selectionStart){this.fld.setSelectionRange(this.sInp.length,this.sInp.length)}this.clearSuggestions();if(typeof(this.oP.callback)=="function"){this.oP.callback(this.aSug[this.iHigh-1])}}};_b.AutoSuggest.prototype.killTimeout=function(){clearTimeout(this.toID)};_b.AutoSuggest.prototype.resetTimeout=function(){clearTimeout(this.toID);var a=this;this.toID=setTimeout(function(){a.clearSuggestions()},1000)};_b.AutoSuggest.prototype.clearSuggestions2=function(){this.killTimeout();var a=_b.DOM.gE(this.idAs);var c=this;if(a){var b=new _b.Fader(a,1,0,250,function(){_b.DOM.remE(c.idAs)})}};_b.AutoSuggest.prototype.clearSuggestions=function(){this.killTimeout();_b.DOM.remE(this.idAs)};if(typeof(_b.Ajax)=="undefined"){_b.Ajax={}}_b.Ajax=function(){this.req={};this.isIE=false};_b.Ajax.prototype.makeRequest=function(c,b,a,d){if(b!="POST"){b="GET"}this.onComplete=a;this.onError=d;var e=this;if(window.XMLHttpRequest){this.req=new XMLHttpRequest();this.req.onreadystatechange=function(){e.processReqChange()};this.req.open("GET",c,true);this.req.send(null)}else{if(window.ActiveXObject){this.req=new ActiveXObject("Microsoft.XMLHTTP");if(this.req){this.req.onreadystatechange=function(){e.processReqChange()};this.req.open(b,c,true);this.req.send()}}}};_b.Ajax.prototype.processReqChange=function(){if(this.req.readyState==4){if(this.req.status==200){this.onComplete(this.req)}else{this.onError(this.req.status)}}};if(typeof(_b.DOM)=="undefined"){_b.DOM={}}_b.DOM.cE=function(g,c,b,f){var h=document.createElement(g);if(!h){return 0}for(var d in c){h[d]=c[d]}var e=typeof(b);if(e=="string"&&!f){h.appendChild(document.createTextNode(b))}else{if(e=="string"&&f){h.innerHTML=b}else{if(e=="object"){h.appendChild(b)}}}return h};_b.DOM.gE=function(c){var a=typeof(c);if(a=="undefined"){return 0}else{if(a=="string"){var b=document.getElementById(c);if(!b){return 0}else{if(typeof(b.appendChild)!="undefined"){return b}else{return 0}}}else{if(typeof(c.appendChild)!="undefined"){return c}else{return 0}}}};_b.DOM.remE=function(a){var b=this.gE(a);if(!b){return 0}else{if(b.parentNode.removeChild(b)){return true}else{return 0}}};_b.DOM.getPos=function(c){var c=this.gE(c);var b=c;var d=0;if(b.offsetParent){while(b.offsetParent){d+=b.offsetLeft;b=b.offsetParent}}else{if(b.x){d+=b.x}}var b=c;var a=0;if(b.offsetParent){while(b.offsetParent){a+=b.offsetTop;b=b.offsetParent}}else{if(b.y){a+=b.y}}return{x:d,y:a}};if(typeof(_b.Fader)=="undefined"){_b.Fader={}}_b.Fader=function(b,f,e,a,d){if(!b){return 0}this.e=b;this.from=f;this.to=e;this.cb=d;this.nDur=a;this.nInt=50;this.nTime=0;var c=this;this.nID=setInterval(function(){c._fade()},this.nInt)};_b.Fader.prototype._fade=function(){this.nTime+=this.nInt;var a=Math.round(this._tween(this.nTime,this.from,this.to,this.nDur)*100);var c=a/100;if(this.e.filters){try{this.e.filters.item("DXImageTransform.Microsoft.Alpha").opacity=a}catch(b){this.e.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+a+")"}}else{this.e.style.opacity=c}if(this.nTime==this.nDur){clearInterval(this.nID);if(this.cb!=undefined){this.cb()}}};_b.Fader.prototype._tween=function(e,a,g,f){return a+((g-a)*(e/f))};
