/* ---------- Autosuggest (5-10kb) ---------- */
if(typeof(bsn)=="undefined")_b=bsn={};if(typeof(_b.Autosuggest)=="undefined")_b.Autosuggest={};else alert("Autosuggest is already set!");var autoSuggestSearchQueryVar='s';_b.AutoSuggest=function(id,param){if(!document.getElementById)return 0;this.fld=_b.DOM.gE(id);if(!this.fld)return 0;this.sInp="";this.nInpC=0;this.aSug=[];this.iHigh=0;this.params=param.params;this.onResultClick=function(){};this.oP=param?param:{};var k,def={minchars:1,meth:"get",varname:"input",className:"autosuggest",timeout:2500,delay:500,offsety:-5,shownoresults:true,noresults:"No results!",maxheight:250,cache:true,maxentries:25};for(k in def){if(typeof(this.oP[k])!=typeof(def[k]))this.oP[k]=def[k];}var p=this;this.fld.onkeypress=function(ev){return p.onKeyPress(ev);};this.fld.onkeyup=function(ev){return p.onKeyUp(ev);};this.fld.setAttribute("autocomplete","off");};_b.AutoSuggest.prototype.onKeyPress=function(ev){var key=(window.event)?window.event.keyCode:ev.keyCode;var RETURN=13;var TAB=9;var ESC=27;var bubble=1;switch(key){case RETURN:this.setHighlightedValue();bubble=0;break;case ESC:this.clearSuggestions();break;}return bubble;};_b.AutoSuggest.prototype.onKeyUp=function(ev){var key=(window.event)?window.event.keyCode:ev.keyCode;var ARRUP=38;var ARRDN=40;var bubble=1;switch(key){case ARRUP:this.changeHighlight(key);bubble=0;break;case ARRDN:this.changeHighlight(key);bubble=0;break;default:this.getSuggestions(this.fld.value);}return bubble;};_b.AutoSuggest.prototype.getSuggestions=function(val){if(val==this.sInp)return 0;_b.DOM.remE(this.idAs);this.sInp=val;if(val.length<this.oP.minchars){this.aSug=[];this.nInpC=val.length;return 0;}var ol=this.nInpC;this.nInpC=val.length?val.length:0;var l=this.aSug.length;if(this.nInpC>ol&&l&&l<this.oP.maxentries&&this.oP.cache){var arr=[];for(var i=0;i<l;i++){if(this.aSug[i].value.substr(0,val.length).toLowerCase()==val.toLowerCase())arr.push(this.aSug[i]);}this.aSug=arr;this.createList(this.aSug);return false;}else{var pointer=this;var input=this.sInp;clearTimeout(this.ajID);this.ajID=setTimeout(function(){pointer.doAjaxRequest(input);},this.oP.delay);}return false;};_b.AutoSuggest.prototype.doAjaxRequest=function(input){if(input!=this.fld.value)return false;var pointer=this;var url=this.oP.script;var querystring='';var params=this.params.split(',');params.push(autoSuggestSearchQueryVar+'='+this.fld.value);for(i=0;i<params.length;i++){if(i==0){var amp='?';}else{var amp='&';}querystring+=amp+params[i];}url=url+querystring;var meth=this.oP.meth;var input=this.sInp;var onSuccessFunc=function(req){pointer.setSuggestions(req,input);};var onErrorFunc=function(status){};var myAjax=new _b.Ajax();myAjax.makeRequest(url,meth,onSuccessFunc,onErrorFunc);};_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(arr){var pointer=this;_b.DOM.remE(this.idAs);this.killTimeout();if(arr.length==0&&!this.oP.shownoresults)return false;var div=_b.DOM.cE("div",{id:this.idAs,className:this.oP.className});var hcorner=_b.DOM.cE("div",{className:"as_corner"});var hbar=_b.DOM.cE("div",{className:"as_bar"});var header=_b.DOM.cE("div",{className:"as_header"});header.appendChild(hcorner);header.appendChild(hbar);div.appendChild(header);var ul=_b.DOM.cE("ul",{id:"as_ul"});for(var i=0;i<arr.length;i++){var val=arr[i].value;var st=val.toLowerCase().indexOf(this.sInp.toLowerCase());var output=val.substring(0,st)+"<em>"+val.substring(st,st+this.sInp.length)+"</em>"+val.substring(st+this.sInp.length);var span=_b.DOM.cE("span",{},output,true);if(arr[i].info!=""){var br=_b.DOM.cE("br",{});span.appendChild(br);var small=_b.DOM.cE("small",{},arr[i].info);span.appendChild(small);}var a=_b.DOM.cE("a",{});var tl=_b.DOM.cE("span",{className:"tl"}," ");var tr=_b.DOM.cE("span",{className:"tr"}," ");a.appendChild(tl);a.appendChild(tr);a.appendChild(span);a.name=i+1;a.onclick=function(){pointer.setHighlightedValue();autoSuggestOnResultClick();return false;};a.onmouseover=function(){pointer.setHighlight(this.name);};var li=_b.DOM.cE("li",{},a);ul.appendChild(li);}if(arr.length==0&&this.oP.shownoresults){var li=_b.DOM.cE("li",{className:"as_warning"},this.oP.noresults);ul.appendChild(li);}div.appendChild(ul);var fcorner=_b.DOM.cE("div",{className:"as_corner"});var fbar=_b.DOM.cE("div",{className:"as_bar"});var footer=_b.DOM.cE("div",{className:"as_footer"});footer.appendChild(fcorner);footer.appendChild(fbar);div.appendChild(footer);var pos=_b.DOM.getPos(this.fld);div.style.left=pos.x+"px";div.style.top=(pos.y+this.fld.offsetHeight+this.oP.offsety)+"px";div.style.width=this.fld.offsetWidth+"px";div.onmouseover=function(){pointer.killTimeout();};div.onmouseout=function(){pointer.resetTimeout();};document.getElementsByTagName("body")[0].appendChild(div);this.iHigh=0;var pointer=this;this.toID=setTimeout(function(){pointer.clearSuggestions();},this.oP.timeout);};_b.AutoSuggest.prototype.changeHighlight=function(key){var list=_b.DOM.gE("as_ul");if(!list)return false;var n;if(key==40)n=this.iHigh+1;else if(key==38)n=this.iHigh-1;if(n>list.childNodes.length)n=list.childNodes.length;if(n<1)n=1;this.setHighlight(n);};_b.AutoSuggest.prototype.setHighlight=function(n){var list=_b.DOM.gE("as_ul");if(!list)return false;if(this.iHigh>0)this.clearHighlight();this.iHigh=Number(n);list.childNodes[this.iHigh-1].className="as_highlight";this.killTimeout();};_b.AutoSuggest.prototype.clearHighlight=function(){var list=_b.DOM.gE("as_ul");if(!list)return false;if(this.iHigh>0){list.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 pointer=this;this.toID=setTimeout(function(){pointer.clearSuggestions();},1000);};_b.AutoSuggest.prototype.clearSuggestions=function(){this.killTimeout();var ele=_b.DOM.gE(this.idAs);var pointer=this;if(ele){var fade=new _b.Fader(ele,1,0,250,function(){_b.DOM.remE(pointer.idAs);});}};if(typeof(_b.Ajax)=="undefined")_b.Ajax={};_b.Ajax=function(){this.req={};this.isIE=false;};_b.Ajax.prototype.makeRequest=function(url,meth,onComp,onErr){if(meth!="POST")meth="GET";this.onComplete=onComp;this.onError=onErr;var pointer=this;if(window.XMLHttpRequest){this.req=new XMLHttpRequest();this.req.onreadystatechange=function(){pointer.processReqChange();};this.req.open("GET",url,true);this.req.send(null);}else if(window.ActiveXObject){this.req=new ActiveXObject("Microsoft.XMLHTTP");if(this.req){this.req.onreadystatechange=function(){pointer.processReqChange();};this.req.open(meth,url,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(type,attr,cont,html){var ne=document.createElement(type);if(!ne)return 0;for(var a in attr)ne[a]=attr[a];var t=typeof(cont);if(t=="string"&&!html)ne.appendChild(document.createTextNode(cont));else if(t=="string"&&html)ne.innerHTML=cont;else if(t=="object")ne.appendChild(cont);return ne;};_b.DOM.gE=function(e){var t=typeof(e);if(t=="undefined")return 0;else if(t=="string"){var re=document.getElementById(e);if(!re)return 0;else if(typeof(re.appendChild)!="undefined")return re;else return 0;}else if(typeof(e.appendChild)!="undefined")return e;else return 0;};_b.DOM.remE=function(ele){var e=this.gE(ele);if(!e)return 0;else if(e.parentNode.removeChild(e))return true;else return 0;};_b.DOM.getPos=function(e){var e=this.gE(e);var obj=e;var curleft=0;if(obj.offsetParent){while(obj.offsetParent){curleft+=obj.offsetLeft;obj=obj.offsetParent;}}else if(obj.x)curleft+=obj.x;var obj=e;var curtop=0;if(obj.offsetParent){while(obj.offsetParent){curtop+=obj.offsetTop;obj=obj.offsetParent;}}else if(obj.y)curtop+=obj.y;return{x:curleft,y:curtop};};if(typeof(_b.Fader)=="undefined")_b.Fader={};_b.Fader=function(ele,from,to,fadetime,callback){if(!ele)return 0;this.e=ele;this.from=from;this.to=to;this.cb=callback;this.nDur=fadetime;this.nInt=50;this.nTime=0;var p=this;this.nID=setInterval(function(){p._fade();},this.nInt);};_b.Fader.prototype._fade=function(){this.nTime+=this.nInt;var ieop=Math.round(this._tween(this.nTime,this.from,this.to,this.nDur)*100);var op=ieop/100;if(this.e.filters){try{this.e.filters.item("DXImageTransform.Microsoft.Alpha").opacity=ieop;}catch(e){this.e.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+ieop+')';}}else{this.e.style.opacity=op;}if(this.nTime==this.nDur){clearInterval(this.nID);if(this.cb!=undefined)this.cb();}};_b.Fader.prototype._tween=function(t,b,c,d){return b+((c-b)*(t/d));};
/* ---------- Modalbox ---------- */
if(!window.Modalbox)var Modalbox=new Object();Modalbox.Methods={overrideAlert:false,focusableElements:new Array,currFocused:0,initialized:false,active:true,options:{title:"ModalBox Window",overlayClose:true,width:500,height:90,overlayOpacity:.65,overlayDuration:.25,slideDownDuration:.5,slideUpDuration:.5,resizeDuration:.25,inactiveFade:true,transitions:true,loadingString:"Please wait. Loading...",closeString:"Close window",closeValue:"&times;",params:{},method:'get',autoFocusing:true,aspnet:false,resizeCSSID:''},_options:new Object,setOptions:function(options){Object.extend(this.options,options||{});},_init:function(options){Object.extend(this._options,this.options);this.setOptions(options);this.MBoverlay=new Element("div",{id:"MB_overlay",style:"opacity: 0"});this.MBwindowwrapper=new Element("div",{id:"MB_windowwrapper"}).update(this.MBwindow=new Element("div",{id:"MB_window",style:"display: none"}).update(this.MBframe=new Element("div",{id:"MB_frame"}).update(this.MBheader=new Element("div",{id:"MB_header"}).update(this.MBcaption=new Element("div",{id:"MB_caption"})))));this.MBclose=new Element("a",{id:"MB_close",title:this.options.closeString,href:"#"}).update("<span>"+this.options.closeValue+"</span>");this.MBheader.insert({'bottom':this.MBclose});this.MBcontent=new Element("div",{id:"MB_content"}).update(this.MBloading=new Element("div",{id:"MB_loading"}).update(this.options.loadingString));this.MBframe.insert({'bottom':this.MBcontent});var injectToEl=this.options.aspnet?$(document.body).down('form'):$(document.body);injectToEl.insert({'top':this.MBwindowwrapper});injectToEl.insert({'top':this.MBoverlay});var scrollOffsets=document.viewport.getScrollOffsets();if(scrollOffsets[1]>0){$('MB_window').setStyle({top:scrollOffsets[1]+'px'});}Event.observe(window,'scroll',function(){scrollOffsets=document.viewport.getScrollOffsets();$('MB_window').setStyle({top:scrollOffsets[1]+'px'});});this.initScrollX=window.pageXOffset||document.body.scrollLeft||document.documentElement.scrollLeft;this.initScrollY=window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop;this.hideObserver=this._hide.bindAsEventListener(this);this.kbdObserver=this._kbdHandler.bindAsEventListener(this);this._initObservers();this.initialized=true;},show:function(content,options){if(!this.initialized)this._init(options);this._cleanUpContentIDs();this.content=content;this.setOptions(options);if(this.options.title)$(this.MBcaption).update(this.options.title);else{$(this.MBheader).hide();$(this.MBcaption).hide();}if(this.MBwindow.style.display=="none"){this._appear();this.event("onShow");}else{this._update();this.event("onUpdate");}},hide:function(options){if(this.initialized){if(options&&typeof options.element!='function')Object.extend(this.options,options);this.event("beforeHide");if(this.options.transitions)Effect.SlideUp(this.MBwindow,{duration:this.options.slideUpDuration,transition:Effect.Transitions.sinoidal,afterFinish:this._deinit.bind(this)});else{$(this.MBwindow).hide();this._deinit();}Event.stopObserving(window,'scroll');}else throw("Modalbox is not initialized.");},_hide:function(event){event.stop();if(event.element().id=='MB_overlay'&&!this.options.overlayClose)return false;this.hide();},alert:function(message){var html='<div class="MB_alert"><p>'+message+'</p><input type="button" onclick="Modalbox.hide()" value="OK" /></div>';Modalbox.show(html,{title:'Alert: '+document.title,width:300});},_appear:function(){if(Prototype.Browser.IE&&!navigator.appVersion.match(/\b7.0\b/)){window.scrollTo(0,0);this._prepareIE("100%","hidden");}this._setWidth();if(this.options.transitions){$(this.MBoverlay).setStyle({opacity:0});new Effect.Fade(this.MBoverlay,{from:0,to:this.options.overlayOpacity,duration:this.options.overlayDuration,afterFinish:function(){new Effect.SlideDown(this.MBwindow,{duration:this.options.slideDownDuration,transition:Effect.Transitions.sinoidal,afterFinish:function(){this.loadContent();}.bind(this)});}.bind(this)});}else{$(this.MBoverlay).setStyle({opacity:this.options.overlayOpacity});$(this.MBwindow).show();this.loadContent();}this._setWidthAndPosition=this._setWidthAndPosition.bindAsEventListener(this);Event.observe(window,"resize",this._setWidthAndPosition);},resize:function(byWidth,byHeight,options){var oWidth=$(this.MBoverlay).getWidth();var wHeight=$(this.MBwindow).getHeight();var wWidth=$(this.MBwindow).getWidth();var hHeight=$(this.MBheader).getHeight();var cHeight=$(this.MBcontent).getHeight();var newHeight=((wHeight-hHeight+byHeight)<cHeight)?(cHeight+hHeight):(wHeight+byHeight);var el=$(this.MBwindow);var contentEl=$(this.MBcontent);var windowBottomMargin=10;newHeight+=windowBottomMargin;var windowOffset=(parseInt(el.getStyle('margin-top'),0)+parseInt(el.getStyle('margin-bottom'),0)+parseInt(el.getStyle('border-top-width'),0)+parseInt(el.getStyle('border-bottom-width'),0))+windowBottomMargin;var contentPadding=(parseInt(contentEl.getStyle('padding-top'))+parseInt(contentEl.getStyle('padding-bottom')));if((newHeight+windowOffset+contentPadding)>document.viewport.getHeight()){newHeight=document.viewport.getHeight()-windowOffset-windowBottomMargin;newcHeight=newHeight-hHeight-parseInt($(this.MBframe).getStyle('padding-bottom'),0)-parseInt($(this.MBcontent).getStyle('padding-bottom'),0);$(this.MBcontent).setStyle({height:newcHeight+'px'});}else if($(this.MBcontent).getStyle('height')){$(this.MBcontent).setStyle({height:''});}var newWidth=wWidth+byWidth;this.options.width=newWidth;if(options)this.setOptions(options);if(this.options.transitions&&!Modalbox.animating){Modalbox.animating=true;new Effect.Morph(this.MBwindow,{style:"width:"+newWidth+"px; height:"+newHeight+"px;",duration:this.options.resizeDuration,beforeStart:function(fx){fx.element.setStyle({overflow:"hidden"});},afterFinish:function(fx){fx.element.setStyle({overflow:"visible"});this.event("_afterResize");this.event("afterResize");Modalbox.animating=false;}.bind(this)});}else{this.MBwindow.setStyle({width:newWidth+"px",height:newHeight+"px"});setTimeout(function(){this.event("_afterResize");this.event("afterResize");}.bind(this),1);}},resizeToContent:function(options){if(typeof options=="undefined"){options=new Object();}var mbimages=$('MB_content').select('img');var totalimages=mbimages.length;if(mbimages[0]){if(typeof options.imagesloaded=="undefined"){var loadedImages=$A();var loadedImageTotal=0;mbimages.each(function(o,idx){loadedImages[idx]=new Image();loadedImages[idx].src=o.src;loadedImages[idx].onload=function(){loadedImageTotal++;if(loadedImageTotal==totalimages){var imageincomplete=false;mbimages.each(function(i){if(i.height==0){imageincomplete=true;}});if(imageincomplete||Modalbox.animating){Modalbox.resizeToContent();}else{options.imagesloaded=true;Modalbox.resizeToContent(options);}}};});}}var byHeight=this.options.height-$(this.MBwindow).getHeight();if(options.resizeCSSID&&$(options.resizeCSSID)){var byWidth=$(options.resizeCSSID).getWidth()-$(this.MBwindow).getWidth()+(parseInt($(this.MBcontent).getStyle('padding-left'),0)+parseInt($(this.MBcontent).getStyle('padding-right'),0))+15;}else{var byWidth=0;}if(byHeight!=0){if(options)this.setOptions(options);Modalbox.resize(byWidth,byHeight);}},resizeToInclude:function(element,options){var el=$(element);var elHeight=el.getHeight()+parseInt(el.getStyle('margin-top'),0)+parseInt(el.getStyle('margin-bottom'),0)+parseInt(el.getStyle('border-top-width'),0)+parseInt(el.getStyle('border-bottom-width'),0);if(elHeight>0){if(options)this.setOptions(options);Modalbox.resize(0,elHeight);}},_update:function(){$(this.MBcontent).update($(this.MBloading).update(this.options.loadingString));this.loadContent();},loadContent:function(){if(this.event("beforeLoad")!=false){if(typeof this.content=='string'){var htmlRegExp=new RegExp(/<\/?[^>]+>/gi);if(htmlRegExp.test(this.content)){this._insertContent(this.content.stripScripts(),function(){this.content.extractScripts().map(function(script){return eval(script.replace("<!--","").replace("// -->",""));}.bind(window));}.bind(this));}else new Ajax.Request(this.content,{method:this.options.method.toLowerCase(),parameters:this.options.params,onComplete:function(transport){var response=new String(transport.responseText);this._insertContent(transport.responseText.stripScripts(),function(){response.extractScripts().map(function(script){return eval(script.replace("<!--","").replace("// -->",""));}.bind(window));});}.bind(this),onException:function(instance,exception){Modalbox.hide();throw('Modalbox Loading Error: '+exception);}});}else if(typeof this.content=='object'){this._insertContent(this.content);}else{Modalbox.hide();throw('Modalbox Parameters Error: Please specify correct URL or HTML element (plain HTML or object)');}}},_insertContent:function(content,callback){$(this.MBcontent).hide().update("");if(typeof content=='string'){this.MBcontent.update(new Element("div",{style:"display: none"}).update(content)).down().show();}else if(typeof content=='object'){var _htmlObj=content.cloneNode(true);if(content.id)content.id="MB_"+content.id;$(content).select('*[id]').each(function(el){el.id="MB_"+el.id;});this.MBcontent.update(_htmlObj).down('div').show();if(Prototype.Browser.IE)$$("#MB_content select").invoke('setStyle',{'visibility':''});}if(this.options.height==this._options.height){Modalbox.resize((this.options.width-$(this.MBwindow).getWidth()),$(this.MBcontent).getHeight()-$(this.MBwindow).getHeight()+$(this.MBheader).getHeight(),{afterResize:function(){setTimeout(function(){this._putContent(callback);}.bind(this),1);}.bind(this)});}else{this._setWidth();this.MBcontent.setStyle({overflow:'auto',height:$(this.MBwindow).getHeight()-$(this.MBheader).getHeight()-13+'px'});setTimeout(function(){this._putContent(callback);}.bind(this),1);}},_putContent:function(callback){this.MBcontent.show();this._setFocus();if(callback!=undefined)callback();this.event("afterLoad");},activate:function(options){this.setOptions(options);this.active=true;$(this.MBclose).observe("click",this.hideObserver);if(this.options.overlayClose)$(this.MBoverlay).observe("click",this.hideObserver);$(this.MBclose).show();if(this.options.transitions&&this.options.inactiveFade)new Effect.Appear(this.MBwindow,{duration:this.options.slideUpDuration});},deactivate:function(options){this.setOptions(options);this.active=false;$(this.MBclose).stopObserving("click",this.hideObserver);if(this.options.overlayClose)$(this.MBoverlay).stopObserving("click",this.hideObserver);$(this.MBclose).hide();if(this.options.transitions&&this.options.inactiveFade)new Effect.Fade(this.MBwindow,{duration:this.options.slideUpDuration,to:.75});},_initObservers:function(){$(this.MBclose).observe("click",this.hideObserver);if(this.options.overlayClose)$(this.MBoverlay).observe("click",this.hideObserver);if(Prototype.Browser.Gecko)Event.observe(document,"keypress",this.kbdObserver);else Event.observe(document,"keydown",this.kbdObserver);},_removeObservers:function(){$(this.MBclose).stopObserving("click",this.hideObserver);if(this.options.overlayClose)$(this.MBoverlay).stopObserving("click",this.hideObserver);if(Prototype.Browser.Gecko)Event.stopObserving(document,"keypress",this.kbdObserver);else Event.stopObserving(document,"keydown",this.kbdObserver);},_setFocus:function(){if(this.focusableElements.length>0&&this.options.autoFocusing==true){var firstEl=this.focusableElements.find(function(el){return el.tabIndex==1;})||this.focusableElements.first();this.currFocused=this.focusableElements.toArray().indexOf(firstEl);firstEl.focus();}else if($(this.MBclose).visible())$(this.MBclose).focus();},_findFocusableElements:function(){if(this.options.autoFocusing===true){this.MBcontent.select('input:not([type=hidden]):enabled, select, textarea, button, a[href]').invoke('addClassName','MB_focusable');this.focusableElements=this.MBcontent.select('.MB_focusable');}},_kbdHandler:function(event){var node=event.element();switch(event.keyCode){case Event.KEY_TAB:return(true);event.stop();if(node!=this.focusableElements[this.currFocused])this.currFocused=this.focusableElements.toArray().indexOf(node);if(!event.shiftKey){if(this.currFocused==this.focusableElements.length-1){this.focusableElements.first().focus();this.currFocused=0;}else{this.currFocused++;this.focusableElements[this.currFocused].focus();}}else{if(this.currFocused==0){this.focusableElements.last().focus();this.currFocused=this.focusableElements.length-1;}else{this.currFocused--;this.focusableElements[this.currFocused].focus();}}break;case Event.KEY_ESC:if(this.active)this._hide(event);break;case 32:this._preventScroll(event);break;case 0:if(event.which==32)this._preventScroll(event);break;case Event.KEY_UP:case Event.KEY_DOWN:case Event.KEY_PAGEDOWN:case Event.KEY_PAGEUP:case Event.KEY_HOME:case Event.KEY_END:if(Prototype.Browser.WebKit&&!["textarea","select"].include(node.tagName.toLowerCase()))event.stop();else if((node.tagName.toLowerCase()=="input"&&["submit","button"].include(node.type))||(node.tagName.toLowerCase()=="a"))event.stop();break;}},_preventScroll:function(event){if(!["input","textarea","select","button"].include(event.element().tagName.toLowerCase()))event.stop();},_deinit:function(){this._removeObservers();Event.stopObserving(window,"resize",this._setWidthAndPosition);if(this.options.transitions){Effect.toggle(this.MBoverlay,'appear',{duration:this.options.overlayDuration,afterFinish:this._removeElements.bind(this)});}else{this.MBoverlay.hide();this._removeElements();}$(this.MBcontent).setStyle({overflow:'',height:''});},_cleanUpContentIDs:function(){if(typeof this.content=='object'){if(this.content.id&&this.content.id.match(/MB_/)){this.content.id=this.content.id.replace(/MB_/,"");}this.content.select('*[id]').each(function(el){el.id=el.id.replace(/MB_/,"");});}},_removeElements:function(){$(this.MBoverlay).remove();$(this.MBwindowwrapper).remove();if(Prototype.Browser.IE&&!navigator.appVersion.match(/\b7.0\b/)){this._prepareIE("","");window.scrollTo(this.initScrollX,this.initScrollY);}this._cleanUpContentIDs();this.initialized=false;this.event("afterHide");this.setOptions(this._options);},_setWidth:function(){$(this.MBwindow).setStyle({width:this.options.width+"px",height:this.options.height+"px"});},_setWidthAndPosition:function(){$(this.MBwindow).setStyle({width:this.options.width+"px"});},_getScrollTop:function(){var theTop;if(document.documentElement&&document.documentElement.scrollTop)theTop=document.documentElement.scrollTop;else if(document.body)theTop=document.body.scrollTop;return theTop;},_prepareIE:function(height,overflow){$$('html, body').invoke('setStyle',{width:height,height:height,overflow:overflow});$$("select").invoke('setStyle',{'visibility':overflow});},event:function(eventName){if(this.options[eventName]){var returnValue=this.options[eventName]();this.options[eventName]=null;if(returnValue!=undefined)return returnValue;else return true;}return true;}};Object.extend(Modalbox,Modalbox.Methods);if(Modalbox.overrideAlert)window.alert=Modalbox.alert;
/* ---------- Core.js ---------- */
var ANF_Error = function(namespace, e){alert('ERROR \n Who:  '+namespace+'\n Name: '+e.name+' \n Message: '+e.message);}
function showFormWorking(){$('formWorking').style.display='block';}
function hideFormWorking(){$('formWorking').style.display='none';}
function showFormBusy(elementId){$(elementId).className='busy';}
function hideFormBusy(elementId){$(elementId).className='';}
function showElement(element){$(element).style.display='block';}
function hideElement(element){$(element).style.display='none';}
function scrollToPosition(x, y){self.scrollTo(x, y);}
function doInputTooltip(options){options.targetPosition=options.targetPosition?options.targetPosition:'topRight';options.tipPosition=options.tipPosition?options.tipPosition:'topLeft';new Tooltip(options.target,options.tooltip,{hook:{target:options.targetPosition,tip:options.tipPosition},offset:{x:5,y:0},trigger:options.target,start_effect:function(element){element.style.display='none';element.appear({duration:.400})},delay:{start:0,end:.250}})}
function resizeIframe(iframeID){if(self==parent)return false;var h=document.body.offsetHeight;h=h?h:document.body.scrollHeight;h=h?h:document.body.height;parent.document.getElementById(iframeID).height=h}    
function InputValidator(options){this.init=function(options){this.input=document.getElementById(options.inputId);this.maxLength=options.maxLength;this.maxWords=options.maxWords;this.onValdiateComplete=options.onValdiateComplete;var that=this;new Form.Element.Observer(options.inputId,.2,function(el,value){that.validate();});this.validate();};this.validate=function(){var value=this.getInputValue();if(this.maxLength&&this.maxLength!=null){if(value.length>this.maxLength){this.setInputValue(value.substr(0,this.maxLength));}}if(this.maxWords&&this.maxWords!=null){var words=value.split(' ');var newWords;if(words.length>this.maxWords){for(var i=0;i<this.maxWords;i++){newWords.push(words[i]);}newWords.join(' ');this.setInputValue(newWords);}}this.onValdiateComplete(value);};this.getInputValue=function(){return(this.input.value);};this.setInputValue=function(value){this.input.value=value;};this.onValdiateComplete=function(value){};this.init(options);};
function textInputDefaultValue(inputId,defaultValue, onfocusCallback){var input=document.getElementById(inputId);var defaultClass=input.className;if(input.value==''){input.value=defaultValue;input.title=defaultValue;input.className=defaultClass+' hint';}input.onfocus=function(){onfocusCallback();input.className=defaultClass;if(this.value==defaultValue){this.value='';}};input.onblur=function(){if(this.value==''){input.className=defaultClass+' hint';this.value=defaultValue;}};}

var PhonekySearch                   = function(config){
    var that                        = this;
    this.searchInterval;
    this.searchDisabled;
    this.searchInput;
    this.autoSuggestContainer; 
    this.recentlyViewed; 
    this.init                       = function(config){      
        this.autoSuggestContainer   = config.autoSuggestContainer?document.getElementById(config.autoSuggestContainer):false;
        this.searchInput            = config.searchInputId?document.getElementById(config.searchInputId):false;
        this.searchInput.onkeydown  = this.searchCache;  
        this.searchInput.onchange   = this.searchCache;          
        this.recentlyViewed         = config.recentlyViewed?config.recentlyViewed:false;
    }
    this.searchCache            = function(e){
        if(!e){ e = window.event; }   
        // escape key pressed
        if(e && e.keyCode){
            if(e.keyCode==27){  
                setTimeout(function(){
                    that.searchInput.value = ""; 
                }, 100);
                return(true);
            }          
        }          
         
        clearInterval(this.searchInterval);
        this.searchInterval = setTimeout(function(){that._searchCache();}, 150);
    } 
    this._searchCache           = function(){  
        // don't perform a search if search has been disabled
        if(this.searchDisabled){return;}
                                                                                 
        this.autoSuggestContainer.innerHTML          = '';
        this.hide();
             
        var q = this.searchInput.value;
        if(q.length==0 && this.recentlyViewed){     
            this.displayAutoSuggest(this.recentlyViewed.split('|'));
            return; 
        }
        else if(q.length<=2){return;}      
        // singularize all keywords in the search string first
        q = q.replace(/(?=[s])s/, ' ');
        
        var matches         = new Array(); 
        var matchesString   = "";
        for(var i=0; i<ba.length; i++){ 
            if(matches.length>=10){continue;} 
            if(matchesString.search(new RegExp(ba[i]+" ","gi"))!=-1){continue;}  
            if(ba[i].search(new RegExp("[^\w\d]?"+q,"gi"))==-1){continue;}
            if(ba[i].search(new RegExp("^"+q,"gi"))==-1){continue;}                  
            matches.push(ba[i]);
            matchesString += ba[i]+" "; 
        }  
        // no matches found for whole phrase, try split phrase
        if(matches.length<10){          
            for(var i=0; i<ba.length; i++){ 
                if(matches.length>=10){continue;} 
                if(matchesString.search(new RegExp(ba[i]+" ","gi"))!=-1){continue;}  
                if(this.hasKeywords(q, ba[i])){
                    matches.push(ba[i]);
                    matchesString += ba[i]+" ";     
                }               
            }    
        }                                     
        clearInterval(this.searchInterval); 
        this.displayAutoSuggest(matches);
    }
    this.displayAutoSuggest       = function(businesses){ 
        if(businesses.length<=0){return;}                           
        var b = new Array();
        for(var i=0; i<businesses.length; i++){ 
            b['id']     = businesses[i].split(' ');
            b['name']   = businesses[i].replace(b['id'][0]+" ", '');
            b['id']     = b['id'][0];
            var link            = document.createElement('a');
                link.innerHTML  = b['name'];
                link.title      = b['name'];
                link.href       = '/profile?bid='+b['id'];
                link.onclick    = function(){
                    $('s').value        = this.innerHTML;
                    $('s').className    = 'inputText execute';
                    $('s').disabled     = 'disabled';
                    that.searchDisabled      = true;
                    that.hide();
                }
            this.autoSuggestContainer.appendChild(link);       
        }                                                      
        this.show();      
    }  
    this.hasKeywords                = function(keywords, string){
        var keywords = keywords.split(' ');
        for(var i=0; i<keywords.length; i++){       
            if(string.search(new RegExp("[^\w\d]?"+keywords[i],"gi"))==-1){return(false);}
        }  
        return(true);    
    }  
    this.hide                       = function(){
        this.autoSuggestContainer.style.visibility   = 'hidden'   
    }
    this.show                       = function(){
        this.autoSuggestContainer.style.visibility   = 'visible'   
    }
    this.init(config);                
}
