var SimpleComplete=new Class({Implements:Options,oCompleteEl:null,oRequest:null,aExtraData:null,options:{afterComplete:function(){},url:false,fieldName:false,minLength:3,returnKey:false},initialize:function(a,b){this.oCompleteEl=$(a);this.setOptions(b);this.build()},build:function(){this.oCompleteEl.removeEvents();this.oCompleteEl.addEvent("keyup",function(a){this.oRequest!==null&&this.oRequest.cancel();if(this.options.fieldName!==false){switch(a.code){case 8:case 46:case 37:case 39:return}a=a.target.get("value");
if(!(a.length<this.options.minLength)){var b=this.options.fieldName,c=$H();if(this.aExtraData!==null)c=$H(this.aExtraData);c[b]=a;this.oRequest=(new Request.JSON({url:this.options.url,method:"post",data:c.toQueryString(),onComplete:this.HandleResponse.bind(this)})).send()}}}.bind(this))},HandleResponse:function(a){if(a.length>0){var b=a[0];if(typeof b=="object"){b=$H(b);b=this.options.returnKey!==false&&b.has(this.options.returnKey)?b[this.options.returnKey]:b.getValues()[0]}var c=this.oCompleteEl.get("value").length;
this.oCompleteEl.set("value",b);this.oCompleteEl.selectRange(c,this.oCompleteEl.get("value").length)}typeof this.options.afterComplete=="function"&&this.options.afterComplete(a)},SetExtraData:function(a){this.aExtraData=a}});

