
var pfxr_cursel=-1;var panelhide=false;function select_dict_mode(m){if(panelhide){$('html').css('overflow-x','hidden');$($$('under-content')).css('display','none');$('.rtab').css('display','block');var w=$(window).width();$($$('cplx')).css('left',w-248+"px").css('right','auto').css('width','100%').css('float','none').animate({left:"0px"},'normal',function(){$('html').css('overflow-x','auto');panelhide=false;});}
$($$('ltab'+dict_mode)).removeClass('ltab-sel');$($$('rtab'+dict_mode)).css('display','none');dict_mode=m;$($$('ltab'+dict_mode)).addClass('ltab-sel');$($$('rtab'+dict_mode)).css('display','block');window.location.hash=dict_mode;return false;}
function hide_panel(){$('html').css('overflow-x','hidden');var w=$(window).width();$($$('cplx')).animate({left:(w-248)+"px"},'normal',function(){$($$('cplx')).css('left','auto').css('float','right').css('right','-10px').css('width','70px');$('.rtab').css('display','none');$('html').css('overflow-x','auto');$($$('under-content')).css('display','table-cell');panelhide=true;});}
function check_hash(){var h=window.location.hash;h=(h=='')?orig_mode:h.substr(1);if(h!=dict_mode)select_dict_mode(h);}
var msg0="<p>Hi! Welcome to the new search feature at thai-lan&shy;gu&shy;age.&#8203;com.</p><p>Enter English or Thai search terms in the area above. As you type, I'll see if I can sug&shy;gest the most rel&shy;e&shy;vant re&shy;sults.</p><p>To get the full result de&shy;tails at any time, press the green ar&shy;row icon.</p><p>Click <a href='/dict'>here</a> for the old search page.</p>";function keyevent2char(e){if(e.altKey||e.ctrlKey)
return 0;return e.charCode||e.keyCode||e.which;}
function eventSource(e){var targ;if(e.target)
targ=e.target;else if(e.srcElement)
targ=e.srcElement;else
return null;if(targ.nodeType==3)
targ=targ.parentNode;return targ;}
function trie_init(){$(".tl-go-but").attr('src','/img/go.png').mouseenter(function(){$(this).attr('src','/img/_go.png');}).mouseleave(function(){$(this).attr('src','/img/go.png');});function cancel_sel(){if(pfxr_cursel==-1)
return;pfxr.childNodes[pfxr_cursel].className="";gotoid.value="";pfxr_cursel=-1;update_msg();}
var tb=$$('pfx-search');var jqtb=new jQuery(tb);var pfxr=$$("pfx-results");var gotoid=$$("pfx-search-gotoid");var pfx;jqtb.keydown(function(e){var i;switch(e.keyCode){case 27:if(pfxr_cursel!=-1){cancel_sel();e.preventDefault();return;}
pfx="";break;case 8:i=getCaretPosition(jqtb[0]);pfx=jqtb.val();pfx=pfx.slice(0,i-1)+pfx.slice(i);break;case 46:i=getCaretPosition(jqtb[0]);if(i>=pfx.length)
return;pfx=jqtb.val();pfx=pfx.slice(0,i)+pfx.slice(i+1);break;case 40:case 38:if(pfxr.style.visibility=="hidden")
return;var c=pfxr.childNodes.length;var oldsel=pfxr_cursel;if(pfxr_cursel==-1){if(e.keyCode!=40)
return;pfxr_cursel=0;}
else if(e.keyCode==40&&pfxr_cursel<c-1)
pfxr_cursel++;else if(e.keyCode==38&&pfxr_cursel>0)
pfxr_cursel--;else
return;if(oldsel!=-1)
pfxr.childNodes[oldsel].className="";pfxr.childNodes[pfxr_cursel].className="sel";var id=pfxr.childNodes[pfxr_cursel].firstChild.href.split('/').pop();gotoid.value=id;update_msg();return;default:return;}
if(pfx.length==0){cancel_sel();pfxr.style.visibility="hidden";bubbleHigh();$$("pfx-search-text").innerHTML=msg0;}
else{prefix_search(pfx);}});jqtb.keypress(function(e){var code=keyevent2char(e);if(code==13){var id=parseInt($($$("pfx-search-gotoid")).val());if(id>0){document.location='/id/'+id;return false;}
return fullsearch();}
if(e.charCode!==null&&e.charCode==0)
return;if(code<32)
return;var i=getCaretPosition(tb);pfx=tb.value;pfx=pfx.slice(0,i)+String.fromCharCode(code)+pfx.slice(i);prefix_search(pfx);});jqtb.keyup(function(e){if(window.event)
return;var code;if((code=keyevent2char(e))==0)
return;if(code==27){if(pfxr_cursel!=-1)
cancel_sel();else
tb.value="";}});jqtb[0].onpaste=function(){if(!window.clipboardData)
return;var i=getCaretPosition(tb);pfx=tb.value;pfx=pfx.slice(0,i)+window.clipboardData.getData('Text')+pfx.slice(i);prefix_search(pfx);}
$($$("pfx-search-go")).click(function(){return fullsearch();});$(".ltab > a").click(function(){var m=$(this).parent().attr('id').substr(4,1);return select_dict_mode(m);});pfx=jqtb.val();if(pfx!="")
prefix_search(pfx);else{bubbleHigh();$($$("pfx-search-text")).html(msg0);}
if(dict_mode==1){$($$('ehk')).css('visibility','visible');$($$('ehk-sb-arrow')).css('visibility','visible');$($$('ehk-speech')).css('visibility','visible');}}
function bubbleHigh(){$($$("ehk-speech")).css('top','285px').css('left','180px');$($$("pfx-search-text")).css('minHeight','120px');$($$("ehk-sb-arrow")).css('top','355px').css('left','110px').attr('src','http://img2.thai-language.net/anime/sb-arrow.png');}
function bubbleLow(){$($$("ehk-speech")).css('top','410px').css('left','160px');$($$("pfx-search-text")).css('minHeight','50px');$($$("ehk-sb-arrow")).css('top','445px').css('left','80px').attr('src','http://img2.thai-language.net/anime/sb-arrow3.png');}
var g_exact;var g_extra;var g_total;var g_srch;var g_f_capped;var g_f_norm;function update_msg(){bubbleLow();var ss="“<span style='font-variant:small-caps;'>"+g_srch+"</span>";if(g_f_norm)
ss+="” (a typo in the input was corrected).";else
ss+=".”";var msg="<p>";if(pfxr_cursel!=-1)
msg+="Press enter to view the highlighted result, or press [Escape] to change the search.</p>";else if(g_total==0){msg+="Sorry, I couldn't find any matches for "+ss+"</p><p>Please change your search text. You can press [Escape] to start over.</p>";bubbleHigh();}
else{if(g_srch.indexOf(" AND ")!=-1)
msg+="I found "+g_extra+" matches for "+ss+"</p>";else{msg+="I found ";if(g_exact>0){if(g_exact==1)
msg+="1 exact match";else
msg+=g_exact+" exact matches";if(g_extra>0)
msg+=" and ";}
if(g_extra>0)
msg+=g_extra+" partial matches";msg+=" for "+ss;if(g_f_capped)
msg+=" I stopped searching, so there may be addi&shy;tion&shy;al matches.";msg+="</p>";}
msg+="<p style='margin-bottom:0px;'>";if(g_total==1)
msg+="Press [Enter] to go to the entry.";else if(g_total<=15)
msg+="Click on a result, or select one of the re&shy;sults with the key&shy;board down-arrow.";else
msg+="Here's a preview of the first 15 matches. To ex&shy;plore the re&shy;sults in de&shy;tail, press [Enter] or click the green ar&shy;row icon.";msg+="</p>";}
$$("pfx-search-text").innerHTML=msg;}
var xmlhttp_tk=null;var timer_tk=null;function fullsearch(){var st=jQuery.trim($($$('pfx-search')).val());if(xmlhttp_tk!=null)
xmlhttp_tk.abort();if(!(xmlhttp_tk=newAjax()))
return;xmlhttp_tk.onreadystatechange=function(){if(xmlhttp_tk.readyState==4&&xmlhttp_tk.status==200){var domDoc=xmlhttp_tk.responseXML;xmlhttp_tk=null;var response=domDoc.documentElement;var results_node=response.firstChild;var rna=results_node.attributes;g_srch=rna.getNamedItem("s").nodeValue;hide_panel();var results=results_node.childNodes;var s="";s+=group_output(results[0],"exact",false);s+=group_output(results[1],"partial",false);s+=group_output(results[2],"complete sentence",true);$$('under-content').innerHTML=s;}};var est=encodeURIComponent(st);if(est.length>60){xmlhttp_tk.open("POST","/xml");xmlhttp_tk.send("<?xml version=\"1.0\" encoding=\"utf-8\" ?><tl-xml-request><type>FullSearch</type><parameters><input>"+xmlencode(st)+"</input><fmt>"+xlit_format+"</fmt></parameters></tl-xml-request>");}
else{xmlhttp_tk.open("GET","/xml/FullSearch?fmt="+xlit_format+"&input="+est);xmlhttp_tk.send(null);}
return false;}
function group_output(grp,sGrp,fwide){var c=parseInt(grp.attributes.getNamedItem("c").nodeValue);if(c==0)
return"";var group=grp.childNodes;var c2=group.length;var s="";if(c2==c)
s="<b>"+c+" "+sGrp+" matches</b><br /><br />";else
s="<b>Showing the first "+c2+" out of "+c+" "+sGrp+" matches</b><br /><br />";if(fwide)
s+=wide_format(group);else
s+=table_format(group);return s+"<br /><br />";}
function wide_format(group){var s="";for(var i=0;i<group.length;i++){var result=group[i];var th=result.firstChild;var id=parseInt(result.attributes.getNamedItem("id").nodeValue);var xl=th.nextSibling;var en=xl.nextSibling;s+="<div class='cs-box'>";s+="<div lang='th'><a href='/id/"+id+"'>";if(th.firstChild!=null)
s+=th.firstChild.nodeValue;s+="</a></div>";if(xlit_format!='F'&&xl.firstChild!=null){s+="<div class='tl-xlit'>";var sx=xl.firstChild.nodeValue;if(xlit_format==0){for(var j=0;j<sx.length;j++){if(sx[j]=='M')
s+="<span class=tt>M</span> ";else if(sx[j]=='R')
s+="<span class=tt>R</span> ";else if(sx[j]=='F')
s+="<span class=tt>F</span> ";else if(sx[j]=='L')
s+="<span class=tt>L</span> ";else if(sx[j]=='H')
s+="<span class=tt>H</span> ";else
s+=sx[j];}}
else
s+=sx;s+="</div>";}
if(en.firstChild!=null)
s+=en.firstChild.nodeValue;s+="</div>";}
return s;}
function table_format(group){var s="";s+="<table class=gridtable cellspacing='0'>";for(var i=0;i<group.length;i++){var result=group[i];var th=result.firstChild;s+="<tr>";var id=parseInt(result.attributes.getNamedItem("id").nodeValue);var xl=th.nextSibling;var en=xl.nextSibling;s+="<td class='th'><a href='/id/"+id+"'>";if(th.firstChild!=null)
s+=th.firstChild.nodeValue;s+="</a></td>";if(xlit_format!='F'){s+="<td>";if(xl.firstChild!=null){var sx=xl.firstChild.nodeValue;if(xlit_format==0){for(var j=0;j<sx.length;j++){if(sx[j]=='M')
s+="<span class=tt>M</span> ";else if(sx[j]=='R')
s+="<span class=tt>R</span> ";else if(sx[j]=='F')
s+="<span class=tt>F</span> ";else if(sx[j]=='L')
s+="<span class=tt>L</span> ";else if(sx[j]=='H')
s+="<span class=tt>H</span> ";else
s+=sx[j];}}
else
s+=sx;}
s+="</td>";}
s+="<td>";if(en.firstChild!=null)
s+=en.firstChild.nodeValue;s+="</td></tr>";}
s+="</table>";return s;}
function prefix_search(pfx){pfx=jQuery.trim(pfx);if(xmlhttp_tk!=null)
xmlhttp_tk.abort();if(!(xmlhttp_tk=newAjax()))
return;xmlhttp_tk.onreadystatechange=function(){if(xmlhttp_tk.readyState==4&&xmlhttp_tk.status==200){var domDoc=xmlhttp_tk.responseXML;xmlhttp_tk=null;var response=domDoc.documentElement;var results_node=response.firstChild;var pfxr=$$("pfx-results");var rna=results_node.attributes;var n_err=rna.getNamedItem("error");if(n_err!=null){pfxr.style.visibility="hidden";if(timer_tk!=null)
clearTimeout(timer_tk);bubbleHigh();$$("pfx-search-text").innerHTML=n_err.nodeValue;var retry=parseInt(rna.getNamedItem("retry").nodeValue);if(retry!=0)
timer_tk=setTimeout("prefix_search('"+pfx+"')",retry*1000);return;}
timer_tk=null;if(rna.getNamedItem("empty")!=null)
return;g_srch=rna.getNamedItem("s").nodeValue;g_exact=parseInt(rna.getNamedItem("exact").nodeValue);g_extra=parseInt(rna.getNamedItem("extra").nodeValue);g_total=g_exact+g_extra;g_f_norm=(rna.getNamedItem("norm")!=null);g_f_capped=(rna.getNamedItem("capped")!=null);update_msg();var results=results_node.childNodes;if(results.length==0){pfxr.style.visibility="hidden";return;}
var id;var s="";for(var i=0;i<results.length;i++){var result=results[i];id=parseInt(result.attributes[0].value);var th=result.firstChild;var xl=th.nextSibling;var en=xl.nextSibling;s+="<dl><a href='/id/"+id+"'><dd class=i>";if(th.attributes.getNamedItem("exact")!=null)
s+="<img src='/img/check.png' />";else if(th.attributes.getNamedItem("star")!=null)
s+="<img src='/img/star.gif' />";s+="</dd><dt>";if(th.firstChild!=null)
s+=th.firstChild.nodeValue;s+="</dt>";if(xlit_format!='F'){s+="<dd class=x>";if(xl.firstChild!=null){var sx=xl.firstChild.nodeValue;if(xlit_format==0){for(var j=0;j<sx.length;j++){if(sx[j]=='M')
s+="<span class=tt>M</span> ";else if(sx[j]=='R')
s+="<span class=tt>R</span> ";else if(sx[j]=='F')
s+="<span class=tt>F</span> ";else if(sx[j]=='L')
s+="<span class=tt>L</span> ";else if(sx[j]=='H')
s+="<span class=tt>H</span> ";else
s+=sx[j];}}
else
s+=sx;}
s+="</dd>";}
s+="<dd>";if(en.firstChild!=null)
s+=en.firstChild.nodeValue;s+="</dd></a></dl>";}
$($$("pfx-search-gotoid")).val((g_total==1)?id:"");pfxr_cursel=-1;pfxr.innerHTML=s;pfxr.style.visibility="visible";bubbleLow();}};var epfx=encodeURIComponent(pfx);if(epfx.length>60){xmlhttp_tk.open("POST","/xml");xmlhttp_tk.send("<?xml version=\"1.0\" encoding=\"utf-8\" ?><tl-xml-request><type>PrefixSearch</type><parameters><input>"+xmlencode(pfx)+"</input><fmt>"+xlit_format+"</fmt></parameters></tl-xml-request>");}
else{xmlhttp_tk.open("GET","/xml/PrefixSearch?fmt="+xlit_format+"&input="+epfx);xmlhttp_tk.send(null);}
setTimeout(function(){if(xmlhttp_tk!=null)$$("pfx-search-text").innerHTML="Checking...";},200);}
