function loadJSON(url) {
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = url;
headID.appendChild(newScript);
_suggest_wordposition = -1;
_suggest_hlbefore = '';
}
var _suggest_suggestlength = 0;
var _suggest_entersearch = false;
var _suggest_force_wordposition = -1;
var _suggest_count = 0;
function processJSONSuggest(sresult, servercount){
var htmlresult = "";
//var mapsource = "[map] ";
//var dictsource = "[dict] ";
var mapsource = "
";
var dictsource = "
";
var searchfor = document.getElementById('searchfor').value;
//htmlresult += "
" + source + d + " | \n";
}
}
}
document.getElementById('_suggest_disp').innerHTML = htmlresult;
if (document.getElementById('_suggest_disp').innerHTML != "") {
document.getElementById('_suggest_disp').style.visibility="visible";
}
else {
document.getElementById('_suggest_disp').style.visibility="hidden";
}
if (_suggest_force_wordposition != -1) {
_suggest_wordposition = _suggest_force_wordposition;
_suggest_force_wordposition = -1;
var hl = document.getElementById('_sg'+_suggest_wordposition);
_suggest_L4(hl);
_suggest_hlbefore = hl;
};
/*
if(!_suggest_entersearch) {
document.getElementById('_suggest_disp').style.visibility="visible";
}
else{
document.getElementById('_suggest_disp').style.visibility="hidden";
_suggest_entersearch = false;
}
*/
if(_suggest_entersearch) {
document.getElementById('_suggest_disp').style.visibility="hidden";
//document.getElementById('exampleselect').style.visibility="visible";
_suggest_entersearch = false;
}
}
function clearSuggestDiv() {
document.getElementById('_suggest_disp').innerHTML= "";
document.getElementById('_suggest_disp').style.visibility="hidden";
//document.getElementById('exampleselect').style.visibility="visible";
}
function _suggest_L2(x) {
//x.style.cssText = '';
x.style.backgroundColor = '#ffffff';
x.style.color = '#000000';
}
function _suggest_L4(x) {
//x.style.cssText = 'color:red;background-color:#bdffbd;border:0px solid blue;';
x.style.backgroundColor = '#bdffbd';
x.style.color = 'red';
_suggest_wordposition = parseInt(x.id.substr(3));
if(_suggest_hlbefore!='') _suggest_L2(_suggest_hlbefore);
_suggest_hlbefore = x;
}
function dosuggestClicked(checked) {
if (checked) {
_suggest_load(document.getElementById("searchfor").value);
} else {
clearSuggestDiv();
}
}
/*
function is_special_key(e) {
var keycode;
var character;
if (window.event) {
keycode = window.event.keyCode; // IE
} else if (e) {
keycode = e.which; //Firefox
}
if (! keycode)
return true;
character = String.fromCharCode(keycode);
//alert(keycode);
if (character) {
return false;
} else {
return true;
}
}
*/
function suggest_navigation_keys_check(e) {
var keycode;
if (window.event) {
keycode = window.event.keyCode; // IE
}
else if (e) keycode = e.which; //Firefox
if(document.getElementById('_suggest_disp').style.visibility!="hidden"){
switch(keycode) {
case 40: //down arrow
if(_suggest_wordposition<_suggest_suggestlength-1) {
_suggest_wordposition++;
}
else {
_suggest_wordposition = 0;
//_suggest_hlbefore = '';
}
if(_suggest_hlbefore!='') _suggest_L2(_suggest_hlbefore);
var hl = document.getElementById('_sg'+_suggest_wordposition);
_suggest_L4(hl);
_suggest_hlbefore = hl;
break;
case 37: //left arrow
break;
case 39: //right arrow
break;
case 38: //up arrow
if(_suggest_wordposition>0) {
_suggest_wordposition--;
}
else {
_suggest_wordposition = _suggest_suggestlength-1;
}
if(_suggest_hlbefore!='') _suggest_L2(_suggest_hlbefore);
var hl = document.getElementById('_sg'+_suggest_wordposition);
_suggest_L4(hl);
_suggest_hlbefore = hl;
break;
/*
case 32://spacebar
var hl = document.getElementById('_sg'+_suggest_wordposition);
document.getElementById('searchfor').value = getInnerWord(hl);
document.getElementById('_suggest_disp').style.visibility="hidden";
*/
break;
case 13://enter
if (_suggest_timer) {
clearTimeout(_suggest_timer);
}
document.getElementById('_suggest_disp').style.visibility="hidden";
//document.getElementById('exampleselect').style.visibility="visible";
var hl = document.getElementById('_sg'+_suggest_wordposition);
//document.getElementById('searchfor').value = getInnerWord(hl);
if (hl) {
document.getElementById('searchfor').value = hl.title;
_suggest_entersearch = true;
hl.onclick();
//doSearch(''); // form's onsubmit will do that
}
break;
case 27://esc
document.getElementById('_suggest_disp').style.visibility="hidden";
//document.getElementById('exampleselect').style.visibility="visible";
break;
//default :alert(keycode);
default :
//return false; // no navigation keys
return true; // nativation keys
}
//return true; // nativation keys
}
else {
if(keycode == 40) {
// force suggest
_suggest_old_headword = "";
_suggest_force_wordposition = 0;
}
}
}
var _suggest_timer = 0;
var _suggest_old_headword = "";
function _suggest_load() {
var str = document.getElementById('searchfor').value;
//alert(str + ", old = " + _suggest_old_headword);
if ( str != _suggest_old_headword ) {
_suggest_old_headword = str;
str = str.replace(new RegExp(/'/g),"'");
str = encodeURIComponent(str);
if (_suggest_timer) {
clearTimeout(_suggest_timer);
}
_suggest_timer = setTimeout("_suggest_doLoad('"+str+"')", 300);
}
}
var _suggest_wordposition = -1;
var _suggest_hlbefore = '';
function _suggest_doLoad(str) {
if(!str || str.length < 3 || ! document.getElementById('dosuggest').checked ) {
document.getElementById('_suggest_disp').innerHTML="";
document.getElementById('_suggest_disp').style.visibility="hidden";
//document.getElementById('exampleselect').style.visibility="visible";
return;
}
_suggest_count++;
loadJSON('http://search.longdo.com/Suggest/HeadSearch?ds=head,poi,poi2&json=1&num=20&count='+ _suggest_count + '&key='+str);
}
function _suggest_setword(str,hosttarget) {
document.getElementById('searchfor').value = str;
window.location="http://"+hosttarget+".longdo.com/search/"+encodeURIComponent(str);
//document.getElementById('searchform').onsubmit();
clearSuggestDiv();
}
/*
function getInnerWord(x){
var w = x.innerHTML;
var strInputCode = w;
strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});
var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
return strTagStrippedText;
}
*/
function setSuggestDivPosition () {
document.getElementById('_suggest_disp').style.top = document.getElementById('searchfor').style.top;
//document.getElementById('_suggest_disp').style.height = "500px";
/*
var ietop = 0;
if (browser == "IE") {
ietop = document.getElementById ('news').offsetHeight + document.getElementById('news_content').offsetHeight + document.getElementById('space').offsetHeight;
}
var suggesttop = document.getElementById('searchs').offsetTop + ietop + 45;
document.getElementById('_suggest_disp').style.top = suggesttop;
if (browser == "IE" && version == 6) {
document.getElementById('_suggest_disp').style.height = document.getElementById('searchresult').style.height;
}
*/
}