if(typeof kannuu==="undefined"){
kannuu={};
}
kannuu.merge=function(to,_2,_3){
for(var i in _2){
if(!_3||i in _3){
to[i]=_2[i];
}
}
};
kannuu.clone=function(_5,_6){
if(!_6){
_6=0;
}
var _7=new _5.constructor();
for(var i in _5){
if(_6&&typeof _5[i]==="object"){
_7[i]=kannuu.clone(_5[i],_6-1);
}else{
_7[i]=_5[i];
}
}
return _7;
};
kannuu.Communicator=function(_9){
if(typeof _9==="object"){
kannuu.merge(this,_9);
}
if(!/^2/.test(this.api)){
throw new Error("Unsupported kannuu API version: "+this.api);
}
this.menuCache={};
if(!this.method){
this.method=/^(?:http:)?\/\//.test(this.URL)?kannuu.Communicator.JSONP:kannuu.Communicator.XHR;
}
this.activeCallbackNo=-1;
this.indexVersion=0;
};
kannuu.Communicator.urlParameters={api:false,dataSource:true,optCount:false,menuLevels:false,menuCount:false,suggest:false};
kannuu.Communicator.callbacks=[];
kannuu.Communicator.cleanupTimer=null;
kannuu._purgeCommCallback=function(no){
delete kannuu.Communicator.callbacks[no];
while(kannuu.Communicator.callbacks.length>0&&!kannuu.Communicator.callbacks[kannuu.Communicator.callbacks.length-1]){
kannuu.Communicator.callbacks.pop();
}
if(kannuu.Communicator.callbacks.length==0){
window.clearInterval(kannuu.Communicator.cleanupTimer);
kannuu.Communicator.cleanupTimer=null;
}
};
kannuu._setCleanupTimer=function(){
if(!kannuu.Communicator.cleanupTimer){
kannuu.Communicator.cleanupTimer=window.setInterval(function(){
for(var i=kannuu.Communicator.callbacks.length-1;i>=0;--i){
if(kannuu.Communicator.callbacks[i]){
kannuu.Communicator.callbacks[i](null,"ping");
}
}
},1000);
}
};
kannuu._newXHR=function(){
if(typeof XMLHttpRequest!=="undefined"){
return new XMLHttpRequest();
}else{
if(typeof ActiveXObject!=="undefined"){
return new ActiveXObject("Microsoft.XMLHTTP");
}else{
throw new Error("XMLHttpRequest not supported");
}
}
};
kannuu.Communicator.prototype={URL:null,api:"2",optCount:100,menuCount:20,collapseMore:false,refreshAllMenus:false,aggressiveFetch:true,requestTimeout:30,onError:function(){
},onCacheReset:function(){
},onCacheChange:function(){
},getCachedMenu:function(_c){
if(!(_c=this._resolveMenu(_c,true))){
return null;
}
return _c.menu;
},getCachedMenuId:function(_d){
if(!(_d=this._resolveMenu(_d))){
return 0;
}
return _d.id?_d.id:0;
},getCachedMenuKey:function(_e){
if(!(_e=this._resolveMenu(_e))){
return 0;
}
return _e.key;
},getCompletion:function(_f){
if(!(_f=this._resolveMenu(_f))){
return null;
}
var _10={completion:[""]},opt=_f.option||_f.id,_12=true;
while(opt){
if(typeof opt==="object"){
if(opt.completion){
_10.completion[_10.completion.length-1]+=(_12?"":opt.value)+opt.completion[0];
_10.completion=_10.completion.concat(opt.completion.slice(1));
if(opt.compl_leaf){
_10.compl_leaf=opt.compl_leaf;
opt=null;
}else{
opt=opt.compl_id;
}
}else{
if(!_12){
_10.completion[_10.completion.length-1]+=opt.value;
}
if(opt.leaf){
_10.compl_leaf=opt.leaf;
opt=null;
}else{
opt=opt.id;
}
}
}else{
_10.compl_id=opt;
opt=this.menuCache[opt];
if(opt){
if(opt.key.length>1&&opt.key[opt.key.length-1]==""){
_10.completion.push("");
}
opt=opt.options[0];
}
}
_12=false;
}
if("compl_id" in _10&&"compl_leaf" in _10){
delete _10.compl_id;
}
return _10;
},getAds:function(_13){
if(!(_13=this._resolveMenu(_13))){
return null;
}
var _14=_13.menu;
while(_14){
if(_14.ads){
return _14.ads;
}
_14=this.menuCache[_14.options[0].id];
}
return null;
},getMenu:function(_15,_16,_17,_18){
if(!(_15=this._resolveMenu(_15))){
return false;
}
if(_15.menu){
if(_16){
_16.call(typeof _17==="object"?_17:this,_15.menu);
}
if(this.aggressiveFetch||_18&&"filter" in _18){
this.method(_15,null,null,_18);
}
return true;
}
this.method(_15,_16,typeof _17==="object"?_17:this,_18);
return true;
},cancel:function(_19){
if(_19){
if(kannuu.Communicator.callbacks[_19]){
kannuu.Communicator.callbacks[_19](this,"abort");
}
return;
}
for(var i=kannuu.Communicator.callbacks.length-1;i>=0;--i){
if(kannuu.Communicator.callbacks[i]){
kannuu.Communicator.callbacks[i](this,"abort");
}
}
},requestsPending:function(){
return kannuu.Communicator.callbacks.length>0;
},_matchOptionID:function(_1b){
for(var m in this.menuCache){
var mm=this.menuCache[m];
for(var o in mm.options){
var oo=mm.options[o];
if(oo.id&&oo.id==_1b.id){
_1b.key=kannuu.clone(mm.key);
_1b.key[_1b.key.length-1]+=oo.value;
_1b.option=oo;
return true;
}
}
if(mm.more&&mm.more.id==_1b.id){
_1b.key=mm.key;
return true;
}
}
return false;
},_matchMenuKey:function(_20){
var key=_20.key.join("ÿ");
for(var m in this.menuCache){
var mm=this.menuCache[m];
if(mm.key.join("ÿ")==key){
_20.menu=mm;
_20.id=m;
return true;
}
}
return false;
},_onMatchedOption:function(_24,oo){
_24.id=oo.id;
_24.option=oo;
if(_24.id&&_24.id in this.menuCache){
_24.menu=this.menuCache[_24.id];
}else{
if(_24.menu){
delete _24.menu;
}
}
},_matchLookAhead:function(_26,mm,opt){
if(!mm.more||!mm.more.chars||mm.more.id in this.menuCache||mm.more.chars.indexOf(opt.charAt(0))<0){
return false;
}
_26.id=mm.more.id;
_26.key=mm.key;
if(_26.menu){
delete _26.menu;
}
_26.chr=opt.charAt(0);
return true;
},_matchOptionKey:function(_29){
var key=_29.key.join("ÿ");
for(var m in this.menuCache){
var mm=this.menuCache[m],mk=mm.key.join("ÿ");
if(mm.key.length!=_29.key.length||key.substr(0,mk.length)!=mk){
continue;
}
for(var o in mm.options){
var oo=mm.options[o];
if(mk+oo.value==key){
this._onMatchedOption(_29,oo);
return true;
}
}
if(this._matchLookAhead(_29,mm,key.substr(mk.length))){
return true;
}
}
return false;
},_matchOptionValue:function(_30){
for(;;){
for(var o in _30.menu.options){
var oo=_30.menu.options[o];
if(oo.value.charAt(0)==_30.chr.charAt(0)){
_30.key=kannuu.clone(_30.key);
_30.key[_30.key.length-1]+=_30.chr.charAt(0);
delete _30.chr;
this._onMatchedOption(_30,oo);
return true;
}
}
if(!_30.id&&_30.menu.more&&_30.menu.more.id in this.menuCache){
_30.menu=this.menuCache[_30.menu.more.id];
}else{
break;
}
}
return this._matchLookAhead(_30,_30.menu,_30.chr);
},_resolveMenu:function(_33,_34){
if(typeof _33==="number"){
_33={id:_33};
}else{
if(typeof _33==="string"){
_33={key:[_33]};
}else{
if(typeof _33==="object"&&_33.constructor===Array){
_33={key:_33};
}
}
}
if(_33.id){
if(_33.id in this.menuCache){
_33.menu=this.menuCache[_33.id];
_33.key=_33.menu.key;
}else{
if("chr" in _33){
return null;
}else{
if(_33.id==1){
_33.key=[""];
}else{
if(_34||!this._matchOptionID(_33)){
return null;
}
}
}
}
}else{
if(_33.key){
if(!this._matchMenuKey(_33)&&("chr" in _33||_34||!this._matchOptionKey(_33))){
return null;
}
}else{
return null;
}
}
if("chr" in _33&&(!_33.menu||!this._matchOptionValue(_33)||_34&&!_33.menu)){
return null;
}
return _33;
},_buildURL:function(_35,_36){
var a={};
kannuu.merge(a,this,kannuu.Communicator.urlParameters);
if(_36){
kannuu.merge(a,_36);
}
kannuu.merge(a,_35);
for(var i in kannuu.Communicator.urlParameters){
if(kannuu.Communicator.urlParameters[i]&&!(i in a)){
throw new Error("Required URL parameter \""+i+"\" is not specified");
}
}
if(!this.URL){
throw new Error("Service URL is not specified");
}
var url=this.URL,sep="?";
for(var i in a){
if(typeof a[i]==="undefined"){
continue;
}
url+=sep;
sep="&";
if(typeof a[i]==="object"&&a[i].constructor===Array){
for(var j=0;j<a[i].length;++j){
if(j>0){
url+=sep;
}
url+=i+(j+1).toString()+"="+encodeURIComponent(a[i][j].toString());
}
}else{
url+=i+"="+encodeURIComponent(a[i].toString());
}
}
if(this.indexVersion){
url+="&ver="+this.indexVersion;
}
return url;
},_startJSONP:function(_3c,cb,obj,_3f){
var _40=kannuu.Communicator.callbacks.length,_41=document.createElement("script"),_42=this,_43=(new Date()).getTime();
kannuu.Communicator.callbacks.push(function(_44,_45){
if(!_45){
kannuu._purgeCommCallback(_40);
_42._onDataReceived(_44,_3c.id);
if(_40==_42.activeCallbackNo||_42.refreshAllMenus){
if(_3c.chr){
_42.getMenu(_3c,cb,obj);
}else{
if(cb){
cb.call(obj,_42.getCachedMenu(_3c));
}
}
}
_41.parentNode.removeChild(_41);
}else{
if(_45=="abort"&&_44===_42||_45=="ping"&&(new Date()).getTime()-_43>1000*_42.requestTimeout){
if(cb){
var _46=_42.refreshAllMenus&&!_3c.chr&&_42.getCachedMenu(_3c);
if(_46){
cb.call(obj,_46);
}
}
_41.parentNode.removeChild(_41);
kannuu._purgeCommCallback(_40);
if(_45!="abort"&&(_40==_42.activeCallbackNo||_42.refreshAllMenus)){
_42.onError(_41.innerHTML?_41.innerHTML:"JSONP request timed out");
}
}
}
});
kannuu._setCleanupTimer();
_42.activeCallbackNo=_40;
_41.setAttribute("src",this._buildURL({menuId:_3c.id,key:_3c.key,jsonp:"kannuu.Communicator.callbacks["+_40+"]"},_3f));
_41.setAttribute("type","text/javascript");
document.getElementsByTagName("head")[0].appendChild(_41);
},_startXHR:function(_47,cb,obj,_4a){
var _4b=kannuu.Communicator.callbacks.length,xhr=kannuu._newXHR(),_4d=this,_4e=(new Date()).getTime();
kannuu.Communicator.callbacks.push(function(_4f){
if(!_4f){
if(xhr.readyState<4){
return;
}
var _50=null;
if(xhr.status<400){
try{
_50=eval("("+xhr.responseText+")");
}
catch(err){
_4d.onError(err.message);
}
}else{
_4d.onError(xhr.responseText);
}
kannuu._purgeCommCallback(_4b);
if(_50){
_4d._onDataReceived(_50,_47.id);
if(_4b==_4d.activeCallbackNo||_4d.refreshAllMenus){
if(_47.chr){
_4d.getMenu(_47,cb,obj);
}else{
if(cb){
cb.call(obj,_4d.getCachedMenu(_47));
}
}
}
}
xhr.onreadystatechange=null;
delete xhr;
}else{
if(_4f=="abort"&&_50===_4d||_4f=="ping"&&(new Date()).getTime()-_4e>1000*_4d.requestTimeout){
if(cb){
var _51=_4d.refreshAllMenus&&!_47.chr?_4d.getCachedMenu(_47):null;
if(_51){
cb.call(obj,_51);
}
}
kannuu._purgeCommCallback(_4b);
xhr.onreadystatechange=null;
xhr.abort();
delete xhr;
if(_4f!="abort"&&(_4b==_4d.activeCallbackNo||_4d.refreshAllMenus)){
_4d.onError("AJAX request timed out");
}
}
}
});
kannuu._setCleanupTimer();
_4d.activeCallbackNo=_4b;
xhr.onreadystatechange=kannuu.Communicator.callbacks[_4b];
xhr.open("GET",this._buildURL({menuId:_47.id,key:_47.key},_4a),true);
xhr.send(null);
},_onDataReceived:function(_52,_53){
if(_52.version&&this.indexVersion&&_52.version!=this.indexVersion){
this.onCacheReset();
this.menuCache={};
}
if(_52.version){
this.indexVersion=_52.version;
}
if(this.collapseMore){
for(var i in _52.response){
while(_52.response[i].more&&_52.response[i].more.id in _52.response){
var _55=_52.response[_52.response[i].more.id];
_52.response[i].options=_52.response[i].options.concat(_55.options);
if(_55.more){
_52.response[i].more=_55.more;
}else{
delete _52.response[i].more;
}
delete _52.response[_52.response[i].more.id];
}
}
for(var i in this.menuCache){
if(this.menuCache[i].more&&this.menuCache[i].more.id in _52.response){
_52.response[this.menuCache[i].more.id].parent=i;
}
}
}
for(var i in _52.response){
if(i in this.menuCache&&(!_52.response[i].timestamp||this.menuCache[i].timestamp>=_52.response[i].timestamp)){
continue;
}
var _56=_52.response[i].options;
delete _52.response[i].options;
if(typeof _52.response[i].more==="number"){
_52.response[i].more={id:_52.response[i].more};
}
var _57;
if(this.collapseMore&&_52.response[i].parent){
_57=this.menuCache[_52.response[i].parent];
if(_52.response[i].more){
_57.more=_52.response[i].more;
}else{
delete _57.more;
}
}else{
_57=this.menuCache[parseInt(i)]=_52.response[i];
_57.options=[];
_57.id=parseInt(i);
}
for(var j in _56){
var o={value:_56[j].v};
if(_56[j].i){
o.id=_56[j].i;
}else{
o.leaf=_56[j].l;
}
if(_56[j].p){
o.priority=_56[j].p;
}
if(_56[j].f){
o.endOfField=true;
}
if(_56[j].c){
o.completion=_56[j].c;
}
if(_56[j].cl){
o.compl_leaf=_56[j].cl;
}
if(_56[j].ci){
o.compl_id=_56[j].ci;
}
_57.options.push(o);
}
if(!_57.timestamp||_52.response[i].timestamp&&_52.response[i].timestamp>_57.timestamp){
_57.timestamp=_52.response[i].timestamp||0;
}
}
for(var m in this.menuCache){
var mm=this.menuCache[m];
for(var o in m.options){
var oo=m.options[o];
if(oo.id&&oo.id in this.menuCache){
this.menuCache[oo.id].parent=m;
}
}
if(mm.more&&mm.more.id in this.menuCache){
this.menuCache[mm.more.id]=m;
}
}
this.onCacheChange();
}};
kannuu.Communicator.JSONP=kannuu.Communicator.prototype._startJSONP;
kannuu.Communicator.XHR=kannuu.Communicator.prototype._startXHR;
if(typeof kannuu==="undefined"){
kannuu={};
}
kannuu.UICore=function(){
this._inMethod=new this.inputMethod();
this._selected=-1;
this._stack=[1];
this._options=[];
this._displayed=false;
this._autoAcceptTimer=null;
this._autoPulldownTimer=null;
this._typeaheadTimer=null;
this._entered="";
this._proposed="";
this.kannuu.refreshAllMenus=true;
if(this.kannuu.api.indexOf("m")<0){
this.kannuu.api=this.kannuu.api+"m";
}
this.kannuu.onCacheChange=this.bind("_onCacheChange");
this.kannuu.onCacheReset=this.bind("back",kannuu.UICore.PHRASE);
this._getMenu();
};
kannuu.UICore.FRAGMENT=0;
kannuu.UICore.WORD=1;
kannuu.UICore.PHRASE=2;
kannuu.UICore.UP=-1;
kannuu.UICore.DOWN=1;
kannuu.UICore.QWERTY=function(){
};
kannuu.UICore.QWERTY.prototype={toChar:function(_5d){
return _5d;
},matchChar:function(_5e,chr){
return _5e==chr;
}};
kannuu.UICore.QWERTY_NO_CASE=function(){
};
kannuu.UICore.QWERTY_NO_CASE.prototype={toChar:function(_60,_61){
return _61&&_60.toLowerCase()==_61?_60.toUpperCase():_60.toLowerCase();
},matchChar:function(_62,chr){
return _62.toLowerCase()==chr.toLowerCase();
}};
kannuu.UICore.DIGITS=function(){
};
kannuu.UICore.DIGITS.prototype={digitMap:{"0":" 0","1":".,1-()/!","2":"abc2","3":"def3","4":"ghi4","5":"jkl5","6":"mno6","7":"pqrs7","8":"tuv8","9":"wxyz9"},toChar:function(_64,_65){
if(_64 in this.digitMap){
var i=_65?this.digitMap[_64].indexOf(_65.toLowerCase()):0;
if(i<0){
return _64;
}
if(++i==this.digitMap[_64].length){
i=0;
}
return this.digitMap[_64].charAt(i);
}else{
return _64.toLowerCase();
}
},matchChar:function(_67,chr){
return _67 in this.digitMap?this.digitMap[_67].indexOf(chr.toLowerCase())>=0:_67.toLowerCase()==chr.toLowerCase();
}};
kannuu.matchOption=function(_69,_6a){
for(var i=0;i<_69.options.length;++i){
if(_69.options[i].value?_6a.substr(0,_69.options[i].value.length)==_69.options[i].value:!_6a){
return i;
}
}
return -1;
};
kannuu.composePhrase3=function(pfx,ifx,sfx){
pfx=pfx.slice(0);
pfx[pfx.length-1]+=ifx;
if(sfx.length){
pfx[pfx.length-1]+=sfx[0];
return pfx.concat(sfx.slice(1));
}else{
return pfx;
}
};
kannuu.UICore.prototype={inputMethod:kannuu.UICore.QWERTY,initialSuggest:10,initialMenuCount:50,accept:function(_6f){
if(typeof _6f==="undefined"){
_6f=kannuu.UICore.FRAGMENT;
}
this._cancelTimers();
if(_6f>kannuu.UICore.FRAGMENT){
this._entered=this._proposed="";
}
if(!this._topMenuId()||this._selected<0||this._selected>this._options.length){
return;
}
if(!("value" in this._options[this._selected])){
this.onAdSelected(this._selected,this._options[this._selected]);
this._hideMenu();
return;
}
var _70=this.kannuu.getCompletion({id:this._topMenuId(),chr:this._options[this._selected].value}),_71=_70.compl_leaf||null,_72=_70.compl_id||0;
_70=_70.completion;
if(_6f==kannuu.UICore.WORD){
if(_70.length>1||_70[0]===""&&_70.length>2){
_71=null;
_72=0;
}
if(_70[0]===""&&_70.length>1){
_70=[this._options[this._selected].value,_70[1]];
}else{
_70=[this._options[this._selected].value+_70[0]];
}
}else{
if(_6f==kannuu.UICore.FRAGMENT){
_71=null;
_72=0;
_70=[this._options[this._selected].value];
if(!this._consumeTypeahead(_70[0])){
this._entered=this._proposed="";
}
}else{
_70[0]=this._options[this._selected].value+_70[0];
}
}
this._options=[];
this._selected=-1;
var _73,key=[""],_75="";
while((_73=this._topMenu())&&_70.length){
key=_73.key;
var _76=kannuu.matchOption(_73,_70[0]);
if(_76<0){
break;
}
_75=_73.options[_76].value;
if(!(_70[0]=_70[0].substr(_75.length))){
_70.shift();
}
_71=_73.options[_76].leaf||_71;
this._stack.push(_73.options[_76].id||0);
}
if(_73){
_71=null;
_72=0;
_70=[];
}
if(_70.length){
if(_72){
this._stack[this._stack.length-1]=_72;
}
}
if(_71!=null){
key=kannuu.composePhrase3(key,_75,_70);
this.onUpdateTextBox(key,"",[]);
this.onCompleted(key,_71);
}else{
this._updateTextBox();
}
if(this._topMenuId()){
this._getMenu();
}else{
this._hideMenu();
}
},back:function(_77,_78){
if(typeof _77==="undefined"){
_77=kannuu.UICore.FRAGMENT;
}
this._cancelTimers();
if(this._stack.length>0&&this._topMenuId()==0){
this.onUndoCompletion();
}
if(_77>kannuu.UICore.FRAGMENT){
this._entered=this._proposed="";
}else{
if(this._entered){
this._entered=this._entered.substr(0,this._entered.length-1);
this._proposed=this._proposed.substr(0,this._proposed.length-1);
this._updateTextBox();
return;
}
}
var _79=false;
this._selected=-1;
if(this._displayed&&!_78){
this._hideMenu();
_79=_77<kannuu.UICore.PHRASE;
}
if(!_79){
while(this._stack.length>1){
this._stack.pop();
if(_77==kannuu.UICore.FRAGMENT||_77==kannuu.UICore.WORD&&this._topMenu().key[this._topMenu().key.length-1]==""){
break;
}
}
}
if(_78){
this._updateMenu();
}else{
if(this._stack.length>1){
this._startAutoPulldown();
}
}
this._updateTextBox();
},move:function(inc){
this._cancelTimers();
if(!this._displayed){
this._updateMenu();
}else{
this._selected+=inc;
if(this._selected<0){
this._selected=this._options.length-1;
}
if(this._selected>=this._options.length){
this._selected=0;
}
this.onSelectionChange(this._selected);
this._updateTextBox();
}
},select:function(id){
this._cancelTimers();
this._selected=id;
this.onSelectionChange(this._selected);
this._updateTextBox();
},enter:function(chr){
this._cancelAutoAccept();
this._cancelAutoPulldown();
if(!this._topMenuId()){
return;
}
if(this._displayed&&this._entered){
if(!this._inMethod.matchChar(chr,this._entered.charAt(this._entered.length-1))){
this.accept();
if(this.isCompleted()){
return;
}
}else{
this.move(1);
this._startAutoAccept();
return;
}
}
if(this._displayed){
this._entered+=chr;
this._proposed+=this._inMethod.toChar(chr);
}else{
if(!this._entered||!this._typeaheadTimer||!this._inMethod.matchChar(chr,this._entered.charAt(this._entered.length-1))){
this._entered+=chr;
this._proposed+=this._inMethod.toChar(chr);
}else{
this._proposed=this._proposed.substr(0,this._proposed.length-1)+this._inMethod.toChar(chr,this._proposed.charAt(this._proposed.length-1));
}
this._updateTextBox();
this._startTypeahead();
}
this._selected=-1;
this._updateMenu();
},isCompleted:function(){
return this._stack.length>0&&this._topMenuId()==0;
},isEmpty:function(){
return this._stack.length<=1&&!this._displayed;
},hideUI:function(){
this._hideMenu();
this._updateTextBox();
},onCompleted:function(_7d,_7e){
},onUndoCompletion:function(){
},onAdSelected:function(id,ad){
},onHideMenu:function(){
throw Error("No one implemented kannuu.UICore.onHideMenu()!");
},onShowMenu:function(){
throw Error("No one implemented kannuu.UICore.onShowMenu()!");
},onClearMenu:function(){
throw Error("No one implemented kannuu.UICore.onClearMenu()!");
},onInsertOption:function(_81,_82,_83){
throw Error("No one implemented kannuu.UICore.onInsertOption()!");
},onInsertAd:function(ad){
return [];
},onUpdateTextBox:function(_85,_86,_87){
throw Error("No one implemented kannuu.UICore.onUpdateTextBox()!");
},onSelectionChange:function(id){
throw Error("No one implemented kannuu.UICore.onSelectionChange()!");
},bind:function(_89){
if(typeof _89==="string"){
_89=this[_89];
}
var _8a=this;
return function(){
_89.apply(_8a,arguments);
};
},logBind:function(_8b){
var _8c=_8b;
if(typeof _8b==="string"){
_8b=this[_8b];
}
var _8d=this;
return function(){
log(_8c+":"+_8b.toString());
_8b.apply(_8d,arguments);
};
},_getMenu:function(){
if(this._topMenuId()==1){
this.kannuu.getMenu(this._topMenuId(),this._onGetMenu,this,{suggest:this.initialSuggest,menuCount:this.initialMenuCount});
}else{
this.kannuu.getMenu(this._topMenuId(),this._onGetMenu,this);
}
},_topMenuId:function(_8e){
if(typeof _8e==="undefined"){
_8e=-1;
}else{
_8e=-_8e-1;
}
_8e+=this._stack.length;
if(_8e<0){
return 0;
}else{
return this._stack[_8e];
}
},_topMenu:function(_8f){
var id=this._topMenuId(_8f);
if(id){
return this.kannuu.getCachedMenu(id);
}else{
return null;
}
},_updateTextBox:function(){
var _91=this._topMenu(),key;
if(_91){
this.onUpdateTextBox(_91.key,this._selected>=0&&("value" in this._options[this._selected])?this._options[this._selected].value:"",this._selected>=0?"value" in this._options[this._selected]?this.kannuu.getCompletion({id:_91.id,chr:this._options[this._selected].value}).completion:"":this._proposed?[this._proposed]:[]);
}else{
if(key=this.kannuu.getCachedMenuKey(this._topMenuId())){
this.onUpdateTextBox(key,"",this._proposed?[this._proposed]:[]);
}
}
},_hideMenu:function(){
if(this._displayed){
this._displayed=false;
this._selected=-1;
this.onHideMenu();
}
},_showMenu:function(){
if(!this._displayed){
this.onShowMenu();
}
this._displayed=true;
},_onGetMenu:function(_93){
if(_93.id==this._topMenuId()&&(this._displayed||_93.id!=1)){
this._updateMenu();
}
},_consumeTypeahead:function(str){
for(var i=0;i<str.length&&this._entered;++i){
if(!this._inMethod.matchChar(this._entered.charAt(0),str.charAt(i))){
return false;
}
this._entered=this._entered.substr(1);
this._proposed=this._proposed.substr(1);
}
return true;
},_matchEntered:function(str){
var i,_98=0;
for(i=0;i<str.length&&i<this._entered.length;++i){
if(!this._inMethod.matchChar(this._entered.charAt(i),str.charAt(i))){
break;
}
if(this._proposed.charAt(i)==str.charAt(i)){
++_98;
}
}
return i+_98/100;
},_onCacheChange:function(){
if(this._displayed){
this._updateMenu();
}
},_updateMenu:function(){
if(this._selected>=0){
for(var i=0;i<this._options.length&&!("value" in this._options[i]);++i){
this._selected--;
}
}
this.onClearMenu();
this._options=[];
var _9a=0,_9b=this._topMenu();
if(!_9b){
this._hideMenu();
this._getMenu();
return;
}
for(;;){
for(var i=0;i<_9b.options.length;++i){
var _9c=this._matchEntered(_9b.options[i].value);
if(!_9c&&this._entered){
continue;
}
var id=this.onInsertOption(_9b.key,_9b.options[i].value,this.kannuu.getCompletion({id:_9b.id,chr:_9b.options[i].value}));
if(id<0){
continue;
}
this._options.splice(id,0,_9b.options[i]);
if(_9c>_9a){
_9a=_9c;
if(this._selected<0){
this._selected=id;
}
}
}
if(this._options.length==0&&this._entered){
this._entered=this._proposed="";
continue;
}else{
if(this._options.length==1||_9a>=2&&_9a>=_9b.options[this._selected].value.length){
this._selected=0;
this.accept();
}else{
if(this._entered){
this._startAutoAccept();
}
if(this._selected<0||this._selected>=this._options.length){
this._selected=0;
}
var ads=this.kannuu.getAds(_9b.id);
if(ads){
for(var i=0;i<ads.length;++i){
var ids=this.onInsertAd(ads[i]);
for(var j=0;j<ids.length;++j){
this._options.splice(ids[j],0,ads[i]);
if(ids[j]<=this._selected){
this._selected++;
}
}
}
}
this._showMenu();
this.onSelectionChange(this._selected);
this._updateTextBox();
}
}
break;
}
},_startAutoAccept:function(){
if(this._autoAcceptTimer){
this._cancelAutoAccept();
}
this._autoAcceptTimer=window.setTimeout(this.bind("accept"),3000);
},_cancelAutoAccept:function(){
if(this._autoAcceptTimer){
window.clearTimeout(this._autoAcceptTimer);
this._autoAcceptTimer=null;
}
},_startAutoPulldown:function(){
if(this._autoPulldownTimer){
this._cancelAutoAccept();
}
this._autoPulldownTimer=window.setTimeout(this.bind("_updateMenu"),1000);
},_cancelAutoPulldown:function(){
if(this._autoPulldownTimer){
window.clearTimeout(this._autoPulldownTimer);
this._autoPulldownTimer=null;
}
},_startTypeahead:function(){
if(this._typeaheadTimer){
this._cancelTypeahead();
}
this._typeaheadTimer=window.setTimeout(this.bind("_updateTextBox"),1000);
},_cancelTypeahead:function(){
if(this._typeaheadTimer){
window.clearTimeout(this._typeaheadTimer);
this._typeaheadTimer=null;
}
},_cancelTimers:function(){
this._cancelAutoAccept();
this._cancelAutoPulldown();
this._cancelTypeahead();
}};
if(typeof kannuu==="undefined"){
kannuu={};
}
kannuu.setInnerText=function(_a1,to){
_a1.innerHTML="";
if(to){
_a1.appendChild(document.createTextNode(to.replace(/(?:^\s+|\s+$)/g,"")));
_a1.innerHTML=(/^\s./.test(to)?"&nbsp;":"")+_a1.innerHTML+(/\s$/.test(to)?"&nbsp;":"");
}
};
kannuu.arrayIndexOf=function(_a3,elt){
for(var i=0;i<_a3.length;++i){
if(_a3[i]===elt){
return i;
}
}
return -1;
};
kannuu.resolveEvent=function(e){
if(e){
return e;
}else{
return window.event;
}
};
kannuu.stopEvent=function(e){
if("cancelBubble" in e){
e.cancelBubble=true;
}
if("returnValue" in e){
e.returnValue=false;
}else{
if(e.stopPropagation){
e.stopPropagation();
}
if(e.preventDefault){
e.preventDefault();
}
}
};
kannuu.isIE=function(){
return /msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent);
};
kannuu.toggleSelection=function(_a8,elt){
var m=_a8.exec(elt.className);
if(m){
var _ab=elt.className;
elt.className=elt.className.substr(0,m.index)+" "+elt.className.substr(m.index+m[0].length);
elt.className+=" "+m[1];
if(!/Selected/.test(m[0])){
elt.className+="Selected";
}
return true;
}
return false;
};
kannuu.findParent=function(elt,tag){
if(!elt){
return null;
}
do{
elt=elt.parentNode;
}while(elt&&elt.tagName.toLowerCase()!==tag);
return elt;
};
kannuu.configureCreateElement=function(){
kannuu.createExtElement=/MSIE/.test(navigator.userAgent)?function(str){
return document.createElement("<"+str+"/>");
}:function(str){
var spl=str.split(/\s+/),tag=spl.shift(),elt=document.createElement(tag);
for(var i=0;i<spl.length;++i){
if(/^(\w+)=['"](.*)['"]$/.exec(spl[i])){
elt.setAttribute(RegExp.$1,RegExp.$2);
}
}
return elt;
};
};
kannuu.createElement=function(str){
if(!/\s/.test(str)){
return document.createElement(str);
}
if(!kannuu.createExtElement){
kannuu.configureCreateElement();
}
return kannuu.createExtElement(str);
};
kannuu._uniqueIds={};
kannuu.uniqueId=function(_b5){
if(!(_b5 in kannuu._uniqueIds)){
kannuu._uniqueIds[_b5]=0;
}
return _b5+(kannuu._uniqueIds[_b5]++).toString();
};
kannuu.srcElement=function(e){
return e.target?e.target:e.srcElement;
};
kannuu.BasicWidget=function(){
this.widgetNode=kannuu.createElement("div class='kannuuWidget' style='position:relative'");
this.widgetNode.className+=" "+this.attachToText.className;
this.widgetNode.id=this.attachToText.id;
this.attachToText.id="";
this.widgetNode.innerHTML="<div style='width:100%;overflow:hidden' class='kannuuTextBox'></div>"+"<div style='position:absolute;z-index:1;"+(kannuu.isIE()?"visibility:hidden":"display:none")+"' class='kannuuMenuPane'></div>";
this.attachToText.parentNode.insertBefore(this.widgetNode,this.attachToText);
this.attachToText.parentNode.removeChild(this.attachToText);
this.menuPane=this.widgetNode.firstChild.nextSibling;
this.createTextBox(this.widgetNode.firstChild);
this.createMenuPane(this.menuPane);
delete this.attachToText;
this.onClearMenu();
this.completedURL="";
if(this.attachToButton){
this.attachToButton.onclick=this.bind("onClick_Find");
}
};
kannuu.BasicWidget.prototype={optionSeparatorHTML:"&nbsp;| ",fieldSeparatorChar:"▪",valueFieldSeparatorChar:" ",urlTarget:"_self",parseLeafData:function(str){
str=str.split("@",2);
return {url:str[0],title:(str.length>1?str[1]:"")};
},createMenuPane:function(_b8){
this.menuList=kannuu.createElement("div class='kannuuMenuList'");
_b8.appendChild(this.menuList);
},renderOption:function(_b9,_ba,_bb,_bc,_bd){
var _be=kannuu.createElement("span");
_be.onclick=this.bind("onClick_Option");
if(_bc.firstChild&&_bc.firstChild.tagName&&_bc.firstChild.tagName.toLowerCase()!=="div"){
_be.innerHTML=this.optionSeparatorHTML;
}
_be.appendChild(document.createTextNode(_b9[_b9.length-1]));
var id=kannuu.uniqueId("kannuu_opt_"),a=kannuu.createElement("a id='"+id+"' class='kannuuMenuOptionLink'");
a.onclick=this.bind("onClick_Fragment");
kannuu.setInnerText(a,_ba===""?this.fieldSeparatorChar:_ba);
_be.appendChild(a);
if(_bb.length>0&&(_bb[0]||_bb.length>1)){
_be.appendChild(document.createTextNode(_bb.length>1&&_ba===""&&_bb[0]===""?_bb[1]:_bb[0]));
}
_bc.insertBefore(_be,_bd);
return id;
},renderAdLinks:function(ad,_c2){
var id=kannuu.uniqueId("kannuu_ad_"),_c4=kannuu.createElement("a href='"+ad.url+"' id='"+id+"' class='kannuuMenuAdLink'");
kannuu.setInnerText(_c4,ad.title);
_c2.insertBefore(_c4,_c2.firstChild);
this.optionAnchors.splice(0,0,id);
return [0];
},onHideMenu:function(){
if(kannuu.isIE()){
this.menuPane.style.visibility="hidden";
}else{
this.menuPane.style.display="none";
}
},onShowMenu:function(){
if(kannuu.isIE()){
this.menuPane.style.visibility="visible";
}else{
this.menuPane.style.display="block";
}
if(this.menuList.offsetHeight>this.maxMenuHeight){
this.menuList.style.height=this.maxMenuHeight+"px";
}
},onClearMenu:function(){
this.optionAnchors=[];
this.subTitles={};
this.menuList.innerHTML="";
},onInsertOption:function(_c5,_c6,_c7){
var div=null,_c9=null;
if("compl_leaf" in _c7){
_c9=this.parseLeafData(_c7.compl_leaf);
if(_c9.title&&_c9.title in this.subTitles){
div=this.subTitles[_c9.title];
}
}
if(!div){
div=kannuu.createElement("div class='kannuuMenuOption'");
this.menuList.appendChild(div);
if(_c9&&_c9.title){
this.subTitles[_c9.title]=div;
div.appendChild(kannuu.createElement("div class='kannuuMenuOptionInfo'"));
div.firstChild.innerHTML=_c9.title;
}
div.onclick=this.bind("onClick_Option");
this.optionAnchors.push(this.renderOption(_c5,_c6,_c7.completion,div,div.firstChild));
return this.optionAnchors.length-1;
}else{
var _ca=div.getElementsByTagName("a"),id=kannuu.arrayIndexOf(this.optionAnchors,_ca[_ca.length-1].id)+1;
this.optionAnchors.splice(id,0,this.renderOption(_c5,_c6,_c7.completion,div,div.lastChild));
return id;
}
},onClick_Fragment:function(e){
e=kannuu.resolveEvent(e);
this.select(kannuu.arrayIndexOf(this.optionAnchors,kannuu.srcElement(e).id));
this.accept();
},onClick_Option:function(e){
e=kannuu.resolveEvent(e);
for(var _ce=kannuu.srcElement(e);_ce;_ce=_ce.parentNode){
var _cf=_ce.getElementsByTagName("a");
if(_cf.length){
this.select(kannuu.arrayIndexOf(this.optionAnchors,_cf[0].id));
break;
}
}
},onClick_Find:function(e){
e=kannuu.resolveEvent(e);
if(this.completedURL){
window.open(this.completedURL,this.urlTarget);
kannuu.stopEvent(e);
}
},onInsertAd:function(ad){
if(this.optionAnchors.length>0&&/^kannuu_ad_/.test(this.optionAnchors[0])){
return [];
}
var div=kannuu.createElement("div class='kannuuMenuAd'"),_d3=kannuu.createElement("div class='kannuuMenuAdInfo'");
_d3.innerHTML=ad.body;
div.onclick=this.bind("onClick_Option");
this.menuList.insertBefore(div,this.menuList.firstChild);
div.appendChild(_d3);
return this.renderAdLinks(ad,div);
},onSelectionChange:function(id){
var _d5=this.menuPane.getElementsByTagName("a");
for(var i=0;i<_d5.length;++i){
if(kannuu.toggleSelection(/\s*(kannuuMenu[A-Za-z]*Link)Selected\s*/,_d5[i])){
kannuu.toggleSelection(/\s*(kannuuMenu[A-Za-z]*)Selected\s*/,kannuu.findParent(_d5[i],"div"));
this.onLinkSelectionChange(_d5[i],false);
break;
}
}
if(id>=0){
var _d7=document.getElementById(this.optionAnchors[id]),div=kannuu.findParent(_d7,"div");
kannuu.toggleSelection(/\s*(kannuuMenu[A-Za-z]*Link)\s*/,_d7);
kannuu.toggleSelection(/\s*(kannuuMenu[A-Za-z]*)\s*/,div);
this.onLinkSelectionChange(_d7,true);
if(div.offsetTop-this.menuList.scrollTop<0){
this.menuList.scrollTop=div.offsetTop;
}else{
if(div.offsetTop+div.offsetHeight>this.menuList.offsetHeight+this.menuList.scrollTop){
this.menuList.scrollTop=(div.offsetTop+div.offsetHeight)-this.menuList.offsetHeight;
}
}
}
},onCompleted:function(_,_da){
this.completedURL=this.parseLeafData(_da).url;
},onUndoCompletion:function(){
this.completedURL="";
},onAdSelected:function(id,_){
window.open(document.getElementById(this.optionAnchors[id]).href,"_self");
},onLinkSelectionChange:function(_dd,_de){
}};
kannuu.KbdWidget=function(){
this._caretTimer=null;
this._blurTimer=null;
};
kannuu.KbdWidget.prototype={createTextBox:function(_df){
this.textBoxNode=_df;
_df.innerHTML="<input type='button' class='kannuuTextBoxUnderlay'><input type='hidden'>"+"<div class='kannuuTextBoxPane'><table class='kannuuCompactTable'><tr>"+"<td class='kannuuTextBoxPrefix'></td><td class='kannuuTextBoxCaretOff'><div style='overflow:hidden'>&nbsp;</div></td>"+"<td class='kannuuTextBoxInfix'></td><td class='kannuuTextBoxSuffix'></td>"+"</tr></table></div>";
this.focusNode=_df.firstChild;
this.valueNode=this.focusNode.nextSibling;
this.textBoxBody=this.valueNode.nextSibling.firstChild;
this.textBoxPrefixNode=this.textBoxBody.rows[0].cells[0];
this.textBoxCaretNode=this.textBoxBody.rows[0].cells[1];
this.textBoxInfixNode=this.textBoxBody.rows[0].cells[2];
this.textBoxSuffixNode=this.textBoxBody.rows[0].cells[3];
if(this.attachToText.getAttribute("name")){
this.valueNode.setAttribute("name",this.attachToText.getAttribute("name"));
this.attachToText.setAttribute("name","");
}
_df.insertBefore(this.focusNode,_df.firstChild);
if(this.attachToText.getAttribute("tabindex")){
this.focusNode.setAttribute("tabindex",this.attachToText.getAttribute("tabindex"));
}
this.focusNode.onfocus=this.bind("onFocus");
this.focusNode.onblur=this.bind("onBlur");
this.widgetNode.onclick=this.bind("_grabFocus");
},_grabFocus:function(e){
e=kannuu.resolveEvent(e);
if(!this._caretTimer){
this.focusNode.focus();
kannuu.stopEvent(e);
}
},_toggleCaret:function(){
this.textBoxCaretNode.className={kannuuTextBoxCaretOn:"kannuuTextBoxCaretOff",kannuuTextBoxCaretOff:"kannuuTextBoxCaretOn"}[this.textBoxCaretNode.className];
this.textBoxPrefixNode.innerText=this.textBoxPrefixNode.innerText;
this.textBoxInfixNode.innerText=this.textBoxInfixNode.innerText;
},onFocus:function(){
if(this._blurTimer){
window.clearTimeout(this._blurTimer);
this._blurTimer=null;
}
this.textBoxCaretNode.className="kannuuTextBoxCaretOn";
if(!this._caretTimer){
this._caretTimer=window.setInterval(this.bind("_toggleCaret"),500);
}
},postBlur:function(){
this.hideUI();
this._blurTimer=null;
},onBlur:function(){
if(this._caretTimer){
window.clearInterval(this._caretTimer);
this._caretTimer=null;
}
this.textBoxCaretNode.className="kannuuTextBoxCaretOff";
this._blurTimer=window.setTimeout(this.bind("postBlur"),300);
},onUpdateTextBox:function(_e1,_e2,_e3){
kannuu.setInnerText(this.textBoxPrefixNode,_e1.join(this.fieldSeparatorChar));
kannuu.setInnerText(this.textBoxInfixNode,_e2);
kannuu.setInnerText(this.textBoxSuffixNode,_e3.length>0?(_e2===""&&_e1[_e1.length-1]?this.fieldSeparatorChar:"")+(_e3.length>1&&_e2===""&&_e3[0]===""?_e3[1]:_e3[0]):"");
this.textBoxNode.scrollLeft=Math.max(this.textBoxBody.offsetWidth-this.textBoxNode.offsetWidth,0);
this.valueNode.value=_e1.join(this.valueFieldSeparatorChar);
},_parseKeyEvent:function(e){
if(e.keyCode in this.keyMap){
return {action:this.keyMap[e.keyCode]};
}else{
var _e5=e.charCode?e.charCode:e.keyCode;
if(_e5>=32&&_e5<32768){
return {charCode:_e5};
}else{
return null;
}
}
},_bypassNavKey:function(k){
return (k.action==="back"||k.action==="accept")&&this.isEmpty()||k.action==="accept"&&this.isCompleted();
},onKeyPress:function(e){
e=kannuu.resolveEvent(e);
var k=this._parseKeyEvent(e);
if(k&&k.charCode){
this.enter(String.fromCharCode(k.charCode));
kannuu.stopEvent(e);
}
},onKeyDown:function(e){
e=kannuu.resolveEvent(e);
var k=this._parseKeyEvent(e);
if(k){
if(k.action&&!this._bypassNavKey(k)){
if(typeof k.action==="string"){
this[k.action].call(this);
}else{
this[k.action[0]].call(this,k.action[1]);
}
kannuu.stopEvent(e);
}
}
},onKeyCheck:function(e){
e=kannuu.resolveEvent(e);
var k=this._parseKeyEvent(e);
if(k&&!(k.action&&this._bypassNavKey(k))){
kannuu.stopEvent(e);
}
}};
kannuu.DesktopWidget=function(){
this.focusNode.onkeypress=this.bind("onKeyPress");
this.focusNode.onkeydown=this.bind("onKeyDown");
this.focusNode.onkeyup=this.bind("onKeyCheck");
};
kannuu.DesktopWidget.prototype={keyMap:{37:"back",8:["back",kannuu.UICore.WORD],38:["move",kannuu.UICore.UP],39:"accept",40:["move",kannuu.UICore.DOWN],13:["accept",kannuu.UICore.WORD]}};
kannuu.ForwardingWidget=function(){
};
kannuu.ForwardingWidget.prototype={bind:kannuu.UICore.prototype.bind,createTextBox:function(_ed){
_ed.appendChild(kannuu.createElement("a class='kannuuSearchLink' href='"+this.searchPageURL+"'"));
kannuu.setInnerText(_ed.firstChild,"Click here to search");
}};
kannuu.Widget=function(_ee){
kannuu.merge(this,_ee);
for(var i=0;i<kannuu.Widget._baseList.length;++i){
kannuu[kannuu.Widget._baseList[i]].call(this);
}
};
kannuu.Widget.prototype=null;
kannuu.Widget.configure=function(_f0){
kannuu.Widget.prototype={};
for(var i=0;i<_f0.length;++i){
kannuu.merge(kannuu.Widget.prototype,kannuu[_f0[i]].prototype);
}
kannuu.Widget._baseList=_f0;
};
kannuu.configureWidget=function(_f2){
if(!kannuu.Widget.prototype){
if(/series60/i.test(navigator.userAgent)){
if("SymbianWidget" in kannuu){
kannuu.Widget.configure(["UICore","BasicWidget","KbdWidget","DocEventHandler","SymbianWidget","ClickToCall"]);
}else{
kannuu.Widget.configure(["BasicWidget","ForwardingWidget"]);
}
}else{
if(/(?:iphone|android)/i.test(navigator.userAgent)){
if("TouchWidget" in kannuu){
var _f3=["UICore","BasicWidget","KbdWidget","DocEventHandler","TouchWidget","ClickToCall"];
_f3.push(/android/i.test(navigator.userAgent)?"DroidWidget":"iPhoneWidget");
kannuu.Widget.configure(_f3);
}else{
kannuu.Widget.configure(["BasicWidget","ForwardingWidget"]);
}
}else{
kannuu.Widget.configure(["UICore","BasicWidget","KbdWidget","DesktopWidget"]);
}
}
}
if(/series60/i.test(navigator.userAgent)){
if("SymbianWidget" in kannuu){
kannuu.SymbianWidget.configureInputMethod(_f2);
}else{
if(_f2.kannuu){
delete _f2.kannuu;
}
}
}else{
if(/(?:iphone|android)/i.test(navigator.userAgent)){
if("TouchWidget" in kannuu){
kannuu.TouchWidget.configureInputMethod(_f2);
}else{
if(_f2.kannuu){
delete _f2.kannuu;
}
}
}
}
if(_f2.kannuu){
if(!_f2.kannuu.api){
_f2.kannuu.api="2a";
}
if(!_f2.kannuu.URL){
_f2.kannuu.URL="http://kannuu.info/fcgi-bin/kanWAS-lookup";
}
_f2.kannuu=new kannuu.Communicator(_f2.kannuu);
}
if(_f2.attachTo){
if(_f2.attachTo.button){
_f2.attachToButton=typeof _f2.attachTo.button==="string"?document.getElementById(_f2.attachTo.button):_f2.attachTo.button;
}
_f2.attachToText=typeof _f2.attachTo.text==="string"?document.getElementById(_f2.attachTo.text):_f2.attachTo.text;
delete _f2.attachTo;
}
return new kannuu.Widget(_f2);
};

