﻿
    function validateQuery()
    {
        //alert(document.forms[0].ichachaInputWord.value);
        if(document.forms[0].ichachaInputWord.value=="" || document.forms[0].ichachaInputWord.value=="输入要查的中英文单词或词组...")
        {
            alert("请输入查询词");
            document.forms[0].ichachaInputWord.focus();
            return false;
        }
        return true;
    }
    
    function mousedown()
    {
        document.getElementById("imgb_search").src="/images/btn04.gif";
        //alert("mouse down triggered");
    }
    function mouseup()
    {
        document.getElementById("imgb_search").src="/images/btn01.gif";
    }
    function fetchimage()
    {
        img = new Image();
        img.src = "/images/btn04.gif";    
    }    
    function hideInputText()
    {
        var ino = document.getElementById("ichachaInputWord");
        if(ino.value=='输入英语或汉语单词或词组...' || ino.value=='输入日语或汉语单词或词组...' || ino.value=='输入法语或汉语单词或词组...' ) {
            ino.value='';
            ino.style.color='black';
        }
    }
    
    function showInputText()
    {
        var ino = document.getElementById("ichachaInputWord");
        if(ino.value=='' || ino.value=='输入英语或汉语单词或词组...' || ino.value=='输入日语或汉语单词或词组...' || ino.value=='输入法语或汉语单词或词组...') 
        {
            switch (cur_so)
            {
                case 1:
                    ino.value='输入英语或汉语单词或词组...';
                    break;
                case 2:
                    ino.value='输入日语或汉语单词或词组...';
                    break;
                case 3:
                    ino.value = '输入法语或汉语单词或词组...';
                    break;
                case 3:
                    ino.value = '输入俄语或汉语单词或词组...';
                    break;
            }
            ino.style.color='grey';
        }
    }
    
    function bookmarksite(title, url){
        if (document.all)
            window.external.AddFavorite(url, title);
        else if (window.sidebar)
            window.sidebar.addPanel(title, url, "");
    }    

    function eleHide(element) {
        var ele = document.getElementById(element);
        ele.style.display = 'none';
        return element;
    }

    function eleShow(element) {
        var ele = document.getElementById(element);
        ele.style.display = 'block';
        return element;
    }

	tab = function(obj, n){
		var o = document.getElementById('tabbox').getElementsByTagName('h2');
		for (var i=1; i<10; i++){
			if (document.getElementById('b'+i)!=undefined){
				if (document.getElementById('b'+i)==obj){
					document.getElementById('b'+i).className='r';
					eleShow('dt'+i);
					}
				else{
					document.getElementById('b'+i).className='w';
					eleHide('dt'+i);
					}
				}
			}
		}

	tabyd = function(obj, name) {
		    for (var i = 1; i < 10; i++) {
		        if (document.getElementById(name + i) != undefined) {
		            if (document.getElementById(name + i) == obj) {
		                document.getElementById(name + i).className = 'tab-current';
		                eleShow(name + '_dt' + i);
		            }
		            else {
		                document.getElementById(name + i).className = '';
		                eleHide(name + '_dt' + i);
		            }
		        }
		    }
		}		
		
	var cur_so = 0;

    function set_so(so)
    {
	    if(cur_so == so) return;
	    var c = document.getElementById('so' + so);
	    c.className = 'cur';
	    var sc = document.getElementById('so' + cur_so)
	    if(null!=sc) sc.className = '';
	    cur_so = so;
	    //showInputText();
    }	
    
  var K = K || {};
  K.config = {
    historyMax:10
  };
  
  K.$ = function(id) {
      return document.getElementById(id);
  }  
  
  K.wCookie = function(name,value) {
    var date=new Date();
    var now=date.getTime();
    date.setTime(now+365*24*60*60*1000);
    document.cookie=name+"="+encodeURIComponent (value)+"; path=/; expires="+date.toGMTString();
  }

  K.rCookie = function(name) {
        var cookie=String(document.cookie);
        var pos=cookie.indexOf(name+"=");
        if(pos!=-1){
            var end=cookie.indexOf("; ",pos);
            return decodeURIComponent(cookie.substring(pos+name.length+1,end==-1?cookie.length:end));
        }
        return "";
  }

  K.getCoords=function (node){
    var x = node.offsetLeft;
    var y = node.offsetTop;
    var parent = node.offsetParent;
    while (parent != null){
        x += parent.offsetLeft;
        y += parent.offsetTop;
        parent = parent.offsetParent;
    }
    return {x: x, y: y};
  }  
  
  initHistory=function(){
	  if(!K.$('ichachaHistory')) return ;
	  var cookie=(K.rCookie('historyT'));
	var str='';
	var arr=cookie.split('/===/');
	//alert(arr.length);
	iK=0;
	for(i =0;i<arr.length;i++){
		w=arr[i];
		if(w.replace(/^\s+/,"")!=''){
			str+='<li title="'+w+'" onclick="HistoryQuery(event);" class="ichachaItem" onmousemove="mmove(event)" onmouseout="mout(event)">'+w+'</li>' +K.$('ichachaHistory').innerHTML;
            iK++;
		}
		//if(iK>=5) break;
	}
	K.$('ichachaHistory').innerHTML=str;
  }

  function inputKey(q){
	  if(q=='') return;
	  try{		
		  if(K.$('ichachaInputWord'))K.$('ichachaInputWord').value=q;
	  }catch(e){
	  }
  }
  
  HistoryQuery=function(e){
	  e = e || window.event;
	  var src = e.srcElement || e.target;
	  closeHistory();
	  inputKey(src.innerHTML);
	  //K.Search(e,src.innerHTML,false);
  }
  
  function mmove(e){	  
	  e = e || window.event;
	  var src = e.srcElement || e.target;
	  src.className='ichachaItem2';
  }
  
  function mout(e){
	  e = e || window.event;
	  var src = e.srcElement || e.target;
	  src.className='ichachaItem';
  }
  
  function addHistory(w){
	  //if(_ichahaUiType==3) {K.wCookie('historyT','');return ;}
	  if(w.length>50) return;
	  if(!K.$('ichachaHistory')) return ;
	  if(w.replace(/^\s+/,"")!=''){
		  var historyT= w+'/===/'+ K.rCookie('historyT');
		  //alert(historyT.split('/===/').length+"**"+K.config.historyMax);
		  if(historyT.split('/===/').length>K.config.historyMax){
			  var tArr=historyT.split('/===/');			 
			  cont="";
			  historyT='';
			  for(i=0;i<K.config.historyMax;i++){
				  historyT+= cont + tArr[i];
				    cont='/===/';
			  }
		  }
		  K.wCookie('historyT',historyT);
		  K.$('ichachaHistory').innerHTML= '<li title="'+w+'" onclick="HistoryQuery(event);" class="ichachaItem" onmousemove="mmove(event)" onmouseout="mout(event)">'+w+'</li>' +K.$('ichachaHistory').innerHTML;
	 }
  }
  
  function closeHistory(){
	  if(K.$('ichachaSkinChoice')){
		  K.$('ichachaSkinChoice').style.display='none';
		  K.$('ichachaSkin').className='ichachaSkinNo';
	  }
	   if(!K.$('ichachaHistory')) return ;
	  K.$('ichachaHistory').style.display = 'none' ;
  }
  
  regShowHistory=function(e){
	if(!K.$('ichachaHistory')) return ;
	e = e || window.event;
	var src = e.srcElement || e.target;
	var xy=K.getCoords(src);
	//alert(xy.x);
	var ichachaHistory=K.$('ichachaHistory');	
	ichachaHistory.style.display= ichachaHistory.style.display=='block'?"none":'block';
	K.$('ichachaHistory').style.width= (K.$('ichachaInputWord').clientWidth+K.$('onOff').clientWidth)+'px';
	K.$('ichachaHistory').style.left=(K.getCoords(K.$('ichachaInputWord')).x-1)+"px";
	K.$('ichachaHistory').style.top=(K.getCoords(K.$('ichachaInputWord')).y+K.$('ichachaInputWord').clientHeight-1)+"px";
   if(K.is_ie){
	   if(ichachaHistory.style.display!='none')K.flashDisplay('none');else K.flashDisplay('');
   }
 }

 
 isOnHistory=function(id){
	 if(id=='ichachaHistory') return true;
	 return false;
 }

 function do_search()
 {
    var kw = document.getElementById("ichachaInputWord").value;
    if(kw=="")
    {
        alert("请输入查询词");
        document.getElementById("ichachaInputWord").focus();
        return false;
    }
    var lang = "";
    cur_so = 1;
    for (so=1;so<5;++so)
    {
        var c = document.getElementById('so' + so);
        if (c.className == 'cur')
        {
            cur_so = so;
            break;
        }
    }
    switch (cur_so)
    {
        case 1:
            lang = "/";
            break;
        case 2:
            lang = "/jp/";
            break;
        case 3:
            lang = "/fr/";
            break;
        case 4:
            lang = "/ru/";
            break;
    }
    var src = lang + kw + ".html";
    addHistory(kw);
    window.location = src;
 }
 
 function do_search_en()
 {
    var kw = document.getElementById("ichachaInputWord").value;
    if(kw=="")
    {
        alert("Please input your query");
        document.getElementById("ichachaInputWord").focus();
        return false;
    }
    var lang = "";
    cur_so = 1;
    for (so=1;so<7;++so)
    {
        var c = document.getElementById('so' + so);
        if (c.className == 'cur')
        {
            cur_so = so;
            break;
        }
    }
    switch (cur_so)
    {
        case 1:
            lang = "";
            break;
        case 2:
            lang = "japanese-chinese/";
            break;
        case 3:
            lang = "french-chinese/";
            break;
        case 4:
            lang = "russian-chinese/";
            break;
        case 5:
            lang = "french-english/";
            break;
        case 6:
            lang = "english-french/";
            break;
    }
    var src = "/en/" + lang + kw + ".html";
    addHistory(kw);
    window.location = src;
}

function do_search_utf8() {
    var kw = document.getElementById("ichachaInputWord").value;
    if (kw == "") {
        alert("请输入查询词");
        document.getElementById("ichachaInputWord").focus();
        return false;
    }
    var lang = "";
    cur_so = 1;
    for (so = 1; so < 5; ++so) {
        var c = document.getElementById('so' + so);
        if (c.className == 'cur') {
            cur_so = so;
            break;
        }
    }
    switch (cur_so) {
        case 1:
            lang = "en";
            break;
        case 2:
            lang = "jp";
            break;
        case 3:
            lang = "fr";
            break;
        case 4:
            lang = "ru";
            break;
    }
    var src = "/sutf8.aspx?q=" + kw + "&l=" + lang;
    addHistory(kw);
    window.location = src;
}

function do_search_test() {
    var kw = document.getElementById("ichachaInputWord").value;
    if (kw == "") {
        alert("请输入查询词");
        document.getElementById("ichachaInputWord").focus();
        return false;
    }
    var srclang = "";
    var tarlang = "";
    cur_so = 1;
    for (so = 1; so < 4; ++so) {
        var c = document.getElementById('so' + so);
        if (c.className == 'cur') {
            cur_so = so;
            break;
        }
    }
    switch (cur_so) {
        case 1:
            srclang = "fr";
            tarlang = "en";
            break;
        case 2:
            srclang = "en";
            tarlang = "fr";
            break;
        case 3:
            lang = "fr";
            break;
    }
    var src = "/en/search.aspx?q=" + kw + "&s=" + srclang + "&t=" + tarlang;
    addHistory(kw);
    window.location = src;
}


 document.onkeydown = function(event) {
     event = event ? event : (window.event ? window.event : null);
     //event.srcElement.type  事件发生对象的类别
     var botton = K.$('ichachaBotton');
     if (event.keyCode == 13 && null!=botton) {
         //do_search();
         botton.click() 
     }
 }
 
 function setCurLang()
 {
    var kLang = (K.rCookie("lang"));
    var curLang = 1;
    if(kLang!="")
    {
        curLang = parseInt(kLang);
        set_soK(curLang);
        return;
    }
    set_so(curLang);
    return;
 }

    function set_soK(so)
    {
	    if(cur_so == so) return;
	    var c = document.getElementById('so' + so);
	    c.className = 'cur';
   	    var sc = document.getElementById('so' + cur_so)
	    if(null!=sc) sc.className = '';
	    cur_so = so;
	    var sso = so.toString();
	    K.wCookie('lang',sso);
	    //showInputText();
	}


    fmpPlay = function(sndUrl) {
        var _flash = document.getElementById("snd");
        _flash._setVar("url", sndUrl);
        _flash._stop();
        _flash._play();
    }

    toggleTab = function(headid,cntid) {
        if (K.$(headid).className == "toggle toggleOpen") {
            K.$(headid).className = "toggle toggleClose";
            K.$(cntid).style.display = 'none';
        }
        else if (K.$(headid).className == "toggle toggleClose") {
            K.$(headid).className = "toggle toggleOpen";
            K.$(cntid).style.display = 'block';
        }
        return false;
    }

    toggle = function(headid, cntid) {
        if (K.$(headid).className == "tab_icon_open") {
            K.$(headid).className = "tab_icon_close";
            K.$(cntid).style.display = 'none';
        }
        else if (K.$(headid).className == "tab_icon_close") {
            K.$(headid).className = "tab_icon_open";
            K.$(cntid).style.display = 'block';
        }
        return false;
    }

    function triggerLinks() {
        K.$('yizhaoLinks_content').style.display = "block";
        K.$('friendly_content').style.display = "none";
    }

    function triggerLinksInner() {
        K.$('yizhaoLinks_content').style.display = "block";
    }

    function restoreLinks() {
        K.$('yizhaoLinks_content').style.display = "none";
        K.$('friendly_content').style.display = "block";
    }
    
    
