﻿//
// JScript 文件 
//
cdcdict_mydicturl="bbs.24en.com";
//document.domain="chadanci.com";

function CDC$(aControlID){
    return document.getElementById(aControlID);
}
function ShiftVisible(aObjName){
    var targetElement=CDC$(aObjName);
	if (targetElement.style.display == "none" || targetElement.style.display == "") {
		targetElement.style.display = "block";
	} else {
		targetElement.style.display = "none";
	} 
	return false;
}

function textOnOff(aObj){
    ShiftVisible(aObj+"_more");
    ShiftVisible(aObj+"_less");
	return false;
}
function ShiftCommentArea(aObj){
    ShiftVisible(aObj+"_content");
    ShiftVisible(aObj+"_hint");
	return false;
}
//通用的复制代码
var Clipboard=0;
function CopyUrl(){ 
    copyit(window.location.toString());
	alert("地址复制成功！");
    return false;
}
function Copycomment(){ 
    var reg=/(<BR>|<.*?>)/igm;
    var newLine = String.fromCharCode(13) +String.fromCharCode(10);
    copyit( word_title+ "\r\n" + CDC$("panel_comment").innerHTML.replace(reg, newLine) +"\r\n（查单词在线词典：www.chadanci.com）");
    CDC$("link_Copycomment").innerHTML="<font color=red>复制成功</font>"
    return false;
}
function GetClipboard(){  
	return Clipboard;
}
function copyit(textit) {
	Clipboard=textit;
	if (window.clipboardData) {
		window.clipboardData.setData("Text",textit);
	} else {
		var flashcopier = 'flashcopier';
		if(!CDC$(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		CDC$(flashcopier).innerHTML = '';
		var divinfo = '<embed src="/images/_clipboard.swf" width="0" height="0" type="application/x-shockwave-flash" id="flashforcopy" name="flashforcopy"></embed>';
		CDC$(flashcopier).innerHTML = divinfo; 
	}
}
//通用的复制代码 结束 

function onInitpage(){  
    _pageloaded=true;
    CDC$("w").focus();
    try{
        var rng   =   CDC$("w").createTextRange();
        rng.select();
        CDC$('pronounce_input').value=CDC$('_pronounce_input').value ; 
    }catch(e){
        CDC$("w").select();
    } 
    window.document.title="【D】 - "+_pwords+" - 在线词典";
}
function SelectInput(){ 
    if(CDC$('panel_pronounceinput').style.display!="block"){
        CDC$("w").focus();
        CDC$("w").select();
    }
}
function QueryWord(aword){
    if(window._dictShow){
        _dictShow( aword );
    }
}
function Submit(){ 
    var word=CDC$("w").value;
    word=word.replace(" ","");
    if(word.length==0){
        alert("请输入查询内容！");
        return false;
    }else{
        window.location="/w/"+ CDC$("w").value.replace(" ", "+");
        return false;
    }
}
onSubmit=Submit;
function OnKeyDown(aevent)
{
    if(!aevent){
        aevent= window.event;
    }
    if(CDC$("w").value=="请输入要查询的单词"){
        CDC$("w").value="";
    }
	if( aevent.keyCode==13){ 
        Submit();
	} 
} 
 
//历史记录 
function HistoryInited(){ 
    getwHistoryObj().AppendHistory(_wordhistory, _wordrefpage, hasResult);
    return;
} 
function ShowHistory(aWList){   
    var Html="";  
    if(aWList!="null" && aWList!=null){
        aWList=aWList.split("|"); 
        var aCount=Math.min(16, aWList.length);
	    for(var i=0; i<aCount; i++){ 
	        //[wordinfo, times, referpage ]
	        var aItemInfo =aWList[i].split("[=]"); 
	        //旧历史，清空
	        if(aItemInfo.length==1){
	            getwHistoryObj().AppendHistory('--!--');
	            return;
	        }
	        var link = ParseHistoryItem( aItemInfo[0] );
	        if(link[1]==""){
	            Html+= "<li><a href=\"/w/"+ escape(link[0]) +"\">"+ link[0] +"</a>";
	        }else{
	            Html+= "<li><a href=\"/jp/w/"+ escape(link[0]) +"&type="+ link[1] +"\">"+ link[0] +"</a>";
	        } 
	    }
        Html= "<OL>"+ Html +"</OL>"; 
    }else{
        Html="<UL><li>无</UL>";            
        CDC$("panel_clearhistory").style.display="none";
    }
    CDC$("panel_history").innerHTML=Html;
    return;
}
function ParseHistoryItem(aItemString){
    if(aItemString.indexOf("{j}")!=-1){
        return [aItemString.replace("{j}",""), "jc"];
    }else if(aItemString.indexOf("{c}")!=-1){
        return [aItemString.replace("{c}",""), "cj"];
    }else{
        return [aItemString, ""];
    }
}
function getwHistoryObj(){ 
    if (navigator.appName.indexOf ("Microsoft") != -1) {
        return window.ahistory;
    } else {
        return window.document.ahistory;
    }
}
//检测生词本
function chw_callback( result ){
  if(result.error == null){ 
    if(result.value=="no"){ 
        CDC$('suggest2mydict_panel').style.display="block";
    }
  }
}
function Suggest2MyDict(anewword){ 
    try{
        if(CDC$("amw_panel") !=undefined){
            PageClass.CheckMyWord(word_title,  CDC$("_langs").innerHTML, chw_callback);
        }
    }catch(e){
    }
}

//音标输入转换 
function replace(source, oldvalue, newvalue) { 
    var i = source.indexOf(oldvalue);
    var retString = "";
    if (i == -1) {
        return source;
    }
    retString += source.substring(0,i) + newvalue;
    if ( i + oldvalue.length < source.length){
        retString += replace(source.substring(i + oldvalue.length, source.length), oldvalue, newvalue);
    }
    return retString;
}
function UpdatePreview(aKeyEvent){
    try{
        if(aKeyEvent==null){
            aKeyEvent=window.event;
        }
        if(aKeyEvent.keyCode>=37 && aKeyEvent.keyCode<=40){
            return;
        }
    }catch(e){
        //
    }
    s = CDC$('pronounce_input').value; 
    s = replace(s,'A','&#230;');
    s = replace(s,'B','&#593;');
    s = replace(s,'E','&#601;');
    s = replace(s,'F','&#643;');
    s = replace(s,'G','&#658;');
    s = replace(s,'J','&#650;');
    s = replace(s,'L','&#602;');
    s = replace(s,'N','&#331;');
    s = replace(s,'O','&#596;');
    s = replace(s,'R','&#652;');
    s = replace(s,'T','&#240;');
    s = replace(s,'X','&#603;');
    s = replace(s,'Y','&#604;');
    s = replace(s,'Z','&#952;');
    s = replace(s,'`','\'');
    s = replace(s,'.',"&#716;");
    CDC$('pronounce_prev').innerHTML = "[ "+s+" ]"; 
} 
function istpro(aLetter){
    CDC$("pronounce_input").value+=aLetter;
    CDC$("pronounce_input").focus();
    UpdatePreview();
}
function onSubmitPronounce(){
    if(!_Submited){
        var word=CDC$("pronounce_input").value ;
        word=word.replace(/( )/igm, "");
        if(word.length!=0){
            CDC$("panel_pronounceinput").style.display = "none";
            _Submited=true;  
            var Url="";
            if(!CDC$("pronouncequery_blur").checked || CDC$("pronouncequery_more").checked ){
                Url ="/w/["+ word +"]{"+ (CDC$("pronouncequery_blur").checked?1:0)+ (CDC$("pronouncequery_more").checked?1:0)+"}" ;
            }else{
                Url="/w/["+ word +"]";
            }
            document.location=Url;
        }
    } 
}
//音标查词
function OnKeyDown2(aevent){
    if(!aevent){
        aevent= window.event;
    } 
	if( aevent.keyCode==13){ 
        onSubmitPronounce();
	}
}
//
function RefreshPronounceQuery(){
     document.location ="/w/"+ _wordhistory +"{"+ (CDC$("pqueryoption_1").checked?1:0)+ (CDC$("pqueryoption_2").checked?1:0)+"}" ;
}
//
function LoadPronouce(aWord,aPanelID){
    CDC$(aPanelID).innerHTML= GetFlashCode('Speaker_swf_'+aPanelID, '/speaker_wv.swf', 'w='+aWord, 16, 16, false);
}

//添加我的生词  开始
function amw_callback(result){ 
  if(result.error == null){ 
    if(result.value=="yes"){
        CDC$("amw_panel").innerHTML='<a href="http://' +cdcdict_mydicturl+ '/mydict/" title="查看我的生词本" target="_blank">添加成功</a>';
        CDC$("amw_panel2").innerHTML=CDC$("amw_panel").innerHTML;  
    }else if(result.value=="no"){
        CDC$("amw_panel").innerHTML='<a href="http://' +cdcdict_mydicturl+ '/mydict/" title="查看我的生词本" target="_blank">你添过这个词了</a>';
         CDC$("amw_panel2").innerHTML=CDC$("amw_panel").innerHTML;  
    }else if(result.value=="error"){
        CDC$("amw_panel").innerHTML='添加失败';
    }else if(result.value=="login"){
        if(confirm("只有登录沪江部落后，才能添加自己的生词，现在是否登录？")){ 
            document.location.href="http://" +cdcdict_mydicturl+ "/login.aspx?Reset=1&ReturnUrl="+ escape(document.location.href);
        }else{
            CDC$("amw_panel").innerHTML='<a href="###" onclick="Do_AddMyWord();return false;"><img src="/images/btn_myword_add.gif" alt="添加到我的生词本"/></a>'; 
            CDC$("amw_panel2").innerHTML='<a href="###" onclick="AddMyWord();return false;" class="gray">加入生词本</a>'; 
        }
    }else{
        alert(result.value);
    }
  }
}
function Do_AddMyWord(){
    try{
        PageClass.AddMyWord(word_title, CDC$("_amw_comment").innerHTML, ReferPage , CDC$("_langs").innerHTML, amw_callback);
    }catch(e){ 
    }
}
function AddMyWord(){
    CDC$("amw_panel").innerHTML='<img align="absmiddle" src="/images/loading.gif" />';
    CDC$("amw_panel2").innerHTML='<img align="absmiddle" src="/images/loading.gif" />';  
    setTimeout("Do_AddMyWord();", 500);
    if(CDC$('suggest2mydict_panel').style.display != 'none'){
        CDC$('suggest2mydict_panel').style.display='none';
    }
} 
//添加我的生词  结束 

//不适合例句投票	
function DownSentences_callback(result){
    if(result.error == null){  
        CDC$("sent_"+ result.value[1]).innerHTML="已评";
    }else{
        alert("错误反馈1："+result.error);
    }
}
function downSentences(SID){
    try{  
        PageClass.DownSentences( SID, DownSentences_callback);
        CDC$("sent_"+ SID).innerHTML='<img align="absmiddle" src="/images/loading.gif" />';
    }catch(e){ 
    }
}
//原词参考：
var oriwordrefershowed=false;
function ShowOriWord_refer(){ 
    if(oriwordrefershowed==false){ 
        oriwordrefershowed=true;
        var oriword_encode=CDC$("panel_regulate_content").innerHTML;
        var aHtml='<div class="regulate_text_span"><a href="http://www.google.com/search?q=fy%20'+ oriword_encode +'&hl=zh-CN&lr=" target="_blank">查Google</a></div>';
        aHtml+='<div class="regulate_text_span"><a href="http://www.baidu.com/s?ie=utf-8&wd='+ oriword_encode +'&cl=3" target="_blank">查Baidu</a></div>';
        aHtml+='<div class="regulate_text_span"><a href="/search/q?all='+ oriword_encode +'" target="_blank"></a></div>';
        aHtml+='<div class="regulate_text_span"><a href="http://209.161.33.50/dictionary/'+ oriword_encode +'" target="_blank">韦氏词典</a></div><br />';
        aHtml+='<div class="regulate_text_span"><a href="http://pewebdic2.cw.idm.fr/display/display.html?search_str='+ oriword_encode +'" target="_blank">朗文英英词典</a></div>';
        aHtml+='<div class="regulate_text_span"><a href="http://dictionary.reference.com/browse/'+ oriword_encode +'" target="_blank">Dictionary</a></div>';
        aHtml+='<div class="regulate_text_span"><a href="http://del.icio.us/search/?fr=del_icio_us&p='+ oriword_encode +'&type=all" target="_blank">相关书签</a></div>';
        aHtml+='<div class="regulate_text_span"><a href="http://en.wikipedia.org/wiki/'+ oriword_encode +'" target="_blank">维基百科</a></div><br/>';
        CDC$("panel_regulate_content").innerHTML=aHtml;
    }
    return ShiftVisible("panel_regulate_content"); 
} 

function ShowMathon_Msg(){ 
    try{
        if(window.external.max_version){
            if( getcookie("maxinstall_hint")=="") {
                CDC$("maxthon_panel").style.display="block";
            }
        }
    }catch(e){ 
    }
}
function Mathon_Install(NeverShow){
    setcookie("maxinstall_hint", "never" , 9999999, "/");
    CDC$("maxthon_panel").style.display="none";
    return false;
}

function ShiftDictable2(aa){
} 