Ajax.CachedAutocompleter=Class.create();Object.extend(Object.extend(Ajax.CachedAutocompleter.prototype,Autocompleter.Base.prototype),{initialize:function(c,d,b,a){this.baseInitialize(c,d,a);this.options.asynchronous=true;this.options.onComplete=this.onComplete.bind(this);this.options.defaultParams=this.options.parameters||null;this.url=b;this.cache={}},getUpdatedChoices:function(){this.startIndicator();var a=this.getToken();if(this.cache[a]){this.updateChoices(this.cache[a])}else{entry=encodeURIComponent(this.options.paramName)+"="+encodeURIComponent(a);this.options.parameters=this.options.callback?this.options.callback(this.element,entry):entry;if(this.options.defaultParams){this.options.parameters+="&"+this.options.defaultParams}new Ajax.Request(this.url,this.options)}},onComplete:function(a){this.updateChoices(this.cache[this.getToken()]=a.responseText)},markPrevious:function(){if(this.index>0){this.index--}else{this.index=this.entryCount-1;this.update.scrollTop=this.update.scrollHeight}selection=this.getEntry(this.index);selection_top=selection.offsetTop;if(selection_top<this.update.scrollTop){this.update.scrollTop=this.update.scrollTop-selection.offsetHeight}},markNext:function(){if(this.index<this.entryCount-1){this.index++}else{this.index=0;this.update.scrollTop=0}selection=this.getEntry(this.index);selection_bottom=selection.offsetTop+selection.offsetHeight;if(selection_bottom>this.update.scrollTop+this.update.offsetHeight){this.update.scrollTop=this.update.scrollTop+selection.offsetHeight}},updateChoices:function(c){if(!this.changed&&this.hasFocus){this.update.innerHTML=c;Element.cleanWhitespace(this.update);Element.cleanWhitespace(this.update.down());if(this.update.firstChild&&this.update.down().childNodes){this.entryCount=this.update.down().childNodes.length;for(var a=0;a<this.entryCount;a++){var b=this.getEntry(a);b.autocompleteIndex=a;this.addObservers(b)}}else{this.entryCount=0}this.stopIndicator();this.update.scrollTop=0;this.index=0;if(this.entryCount==1&&this.options.autoSelect){this.selectEntry();this.hide()}else{this.render()}}}});Ajax.GoogleSearch=Class.create();Object.extend(Object.extend(Ajax.GoogleSearch.prototype,Ajax.CachedAutocompleter.prototype),{initialize:function(c,d,b,a){this.baseInitialize(c,d,a);this.options.asynchronous=true;this.options.onComplete=this.onComplete.bind(this);this.options.defaultParams=this.options.parameters||null;this.url=b;this.cache={}},onKeyPress:function(a){if(this.active){switch(a.keyCode){case Event.KEY_TAB:case Event.KEY_RETURN:this.selectEntry();window.location="/Search.aspx?q="+this.element.value;Event.stop(a);case Event.KEY_ESC:this.hide();this.active=false;Event.stop(a);return;case Event.KEY_LEFT:case Event.KEY_RIGHT:return;case Event.KEY_UP:this.markPrevious();this.render();Event.stop(a);return;case Event.KEY_DOWN:this.markNext();this.render();Event.stop(a);return}}else{if(a.keyCode==Event.KEY_TAB||a.keyCode==Event.KEY_RETURN||(Prototype.Browser.WebKit>0&&a.keyCode==0)){return}}this.changed=true;this.hasFocus=true;if(this.observer){clearTimeout(this.observer)}this.observer=setTimeout(this.onObserverEvent.bind(this),this.options.frequency*1000)},updateChoices:function(c){if(!this.changed&&this.hasFocus){this.update.innerHTML=c;Element.cleanWhitespace(this.update);Element.cleanWhitespace(this.update.down());if(this.update.firstChild&&this.update.down().childNodes){this.entryCount=this.update.down().childNodes.length;for(var a=0;a<this.entryCount;a++){var b=this.getEntry(a);b.autocompleteIndex=a;this.addObservers(b)}}else{this.entryCount=0}this.stopIndicator();this.update.scrollTop=0;this.index=-1;if(this.entryCount==1&&this.options.autoSelect){this.selectEntry();this.hide()}else{this.render()}}},selectEntry:function(){this.active=false;this.updateElement(this.getCurrentEntry())},onClick:function(b){var a=Event.findElement(b,"LI");this.index=a.autocompleteIndex;this.selectEntry();this.hide();window.location="/Search.aspx?q="+this.element.value}});
