Object.extend(Event,{KEY_PAGE_UP:33,KEY_PAGE_DOWN:34,KEY_END:35,KEY_HOME:36,KEY_INSERT:45,KEY_SHIFT:16,KEY_CTRL:17,KEY_ALT:18});
var AutoAssist=Class.create();
AutoAssist.prototype={version:"0.6.5",requestNo:0,responseNo:0,visible:false,hasFocus:false,cssSelector:{main:"aa",under:"under_aa",highlight:"aa_highlight",wait:"aa_wait"},defaultOptions:{eventName:"onSelect",typing_timeout:200},initialize:function(_1,_2,_3){
this.txtBox=$(_1);
this.txtBox.setAttribute("autocomplete","off");
var _4=navigator.appName;
if(_4.indexOf("Microsoft")!=-1){
this.txtBox.onkeydown=this.onkeydown.bindAsEventListener(this);
}else{
this.txtBox.onkeypress=this.onkeydown.bindAsEventListener(this);
}
this.txtBox.autoassist=this;
this.timeoutId=0;
this.getURL=_2;
this.floatDiv=document.createElement("div");
this.floatDiv.style.position="absolute";
Element.addClassName(this.floatDiv,this.cssSelector.main);
Element.hide(this.floatDiv);
this.bottomDiv=document.createElement("iframe");
this.bottomDiv.style.position="absolute";
this.bottomDiv.frameBorder="0";
this.bottomDiv.scrolling="no";
Element.addClassName(this.bottomDiv,this.cssSelector.under);
Element.hide(this.bottomDiv);
document.body.appendChild(this.floatDiv);
document.body.appendChild(this.bottomDiv);
this.bufferDiv=document.createElement("div");
Element.addClassName(this.bufferDiv,this.cssSelector.main);
this.currentNodeIndex=-1;
this.size=-1;
this.setOptions(_3);
Event.observe(document,"click",this.forceSelect.bindAsEventListener(this));
Event.observe(this.txtBox,"dblclick",this.doRequest.bindAsEventListener(this));
Event.observe(this.txtBox,"focus",this.setFocus.bindAsEventListener(this));
Event.observe(this.txtBox,"blur",this.resetFocus.bindAsEventListener(this));
},setOptions:function(_5){
this.options=this.defaultOptions;
Object.extend(this.options,_5||{});
},onkeydown:function(_6){
switch(_6.keyCode){
case Event.KEY_PAGE_UP:
case Event.KEY_PAGE_DOWN:
case Event.KEY_LEFT:
case Event.KEY_RIGHT:
case Event.KEY_END:
case Event.KEY_HOME:
case Event.KEY_INSERT:
case Event.KEY_SHIFT:
case Event.KEY_CTRL:
case Event.KEY_ALT:
return;
case Event.KEY_TAB:
case Event.KEY_ESC:
this.forceSelect();
return;
case Event.KEY_UP:
this.up();
return false;
case Event.KEY_DOWN:
this.down();
return false;
case Event.KEY_RETURN:
if(this.visible){
this.select();
}
return false;
default:
this.log("evt.keyCode:"+_6.keyCode);
if(this.timeoutId!=0){
clearTimeout(this.timeoutId);
}
this.timeoutId=setTimeout(this.doRequest.bind(this),this.options.typing_timeout);
}
},forceSelect:function(){
if(this.visible){
this.currentNodeIndex=0;
this.select();
}
},setFocus:function(){
this.hasFocus=true;
},resetFocus:function(){
this.hasFocus=false;
},select:function(){
if(this.currentNode()){
var _7=this.currentNode().getAttribute(this.options.eventName);
try{
eval(_7);
}
catch(e){
}
this.hide();
}
},currentNode:function(){
if(this.children){
return this.children[this.currentNodeIndex];
}else{
return undefined;
}
},highlight:function(h){
if(this.currentNode()){
Element.removeClassName(this.currentNode(),this.cssSelector.highlight);
}
this.currentNodeIndex=h;
if(this.currentNode()){
Element.addClassName(this.currentNode(),this.cssSelector.highlight);
}
},up:function(){
if(this.currentNodeIndex>-1){
this.highlight(this.currentNodeIndex-1);
}
},down:function(){
if(this.currentNodeIndex<this.size-1){
this.highlight(this.currentNodeIndex+1);
}
},cleanup:function(){
this.size=0;
this.currentNodeIndex=-1;
this.bufferDiv.innerHTML="";
},isValidNode:function(n){
return (n.nodeType==1)&&(n.getAttribute(this.options.eventName)!=undefined);
},preRequest:function(){
if(this.txtBox.value.length<1){
this.cleanup();
this.hide();
return false;
}
return true;
},getURL:function(){
},doRequest:function(){
if(this.preRequest()){
this.onLoading();
var _a={method:"get",onSuccess:this.onSuccess.bindAsEventListener(this),onFailure:this.onFailure.bindAsEventListener(this)};
var _b=this.getURL();
this.currentRequest=new Ajax.Updater(this.bufferDiv,_b,_a);
this.requestNo++;
this.log(_b);
}
},onException:function(){
this.log("onException");
},onFailure:function(){
this.log("onFailure");
this.hide();
this.cleanup();
Element.removeClassName(this.txtBox,this.cssSelector.wait);
},onLoading:function(){
this.cleanup();
Element.addClassName(this.txtBox,this.cssSelector.wait);
},onSuccess:function(){
setTimeout(this.updateContent.bind(this,arguments[0]),10);
},updateContent:function(){
this.responseNo++;
this.log(this.requestNo+"/"+this.responseNo);
var tx=((this.currentRequest==null)||(this.currentRequest.transport==arguments[0]));
this.log(tx);
if(tx&&this.bufferDiv.innerHTML!=""&&this.hasFocus){
this.floatDiv.innerHTML=this.bufferDiv.innerHTML;
this.size=0;
this.currentNodeIndex=-1;
var _d=this.floatDiv.childNodes;
this.children=new Array();
if(_d.length>0){
for(var i=0;i<_d.length;i++){
var _f=_d[i];
if(this.isValidNode(_f)){
var f=new Function("this.highlight("+this.size+"); ");
Event.observe(_f,"mouseover",f.bindAsEventListener(this));
Event.observe(_f,"click",this.select.bindAsEventListener(this));
this.children.push(_f);
this.size++;
}
}
this.down();
if(!this.visible){
this.show();
}else{
var _11=new positionInfo(this.floatDiv);
this.bottomDiv.height=_11.getElementHeight()+"px";
}
}
Element.removeClassName(this.txtBox,this.cssSelector.wait);
}else{
if(this.visible){
this.hide();
}
Element.removeClassName(this.txtBox,this.cssSelector.wait);
this.cleanup();
}
},show:function(){
if(this.txtBox.focus){
this.floatDiv.style.width=this.txtBox.offsetWidth-8+"px";
var p=Position.cumulativeOffset(this.txtBox);
this.floatDiv.style.top=p[1]+this.txtBox.offsetHeight+"px";
this.floatDiv.style.left=p[0]+"px";
this.visible=true;
Element.show(this.floatDiv);
var _13=new positionInfo(this.floatDiv);
this.bottomDiv.style.width=this.txtBox.offsetWidth-8+"px";
this.bottomDiv.style.top=p[1]+this.txtBox.offsetHeight+"px";
this.bottomDiv.style.left=p[0]+"px";
this.bottomDiv.height=_13.getElementHeight()+"px";
Element.show(this.bottomDiv);
}
},hide:function(_14){
this.visible=false;
Element.hide(this.floatDiv);
Element.hide(this.bottomDiv);
},log:function(msg){
try{
$("log").value=msg+"<br/>\n"+$("log").value;
}
catch(e){
}
}};
function noenter(evt){
evt=(evt)?evt:window.event;
return !(evt.keyCode==13);
}


