﻿function ShiftVisible(aObjName){
	var targetElement=$(aObjName);
	if (targetElement.style.display == "none" || targetElement.style.display == "") {
		targetElement.style.display = "block";
	} else {
		targetElement.style.display = "none";
	}
	return false;
}
function ShiftVisible_jpcom(aObjName, a_linkObj, a_Bool){
	var targetElement=$(aObjName);
	if(typeof(a_Bool)=="undefined" || a_Bool==null){
		if (targetElement.style.display == "none" || targetElement.style.display == "") {
			targetElement.style.display = "block";
			a_linkObj.innerHTML="<b>[ - ]</b>";
		} else {
			targetElement.style.display = "none";
			a_linkObj.innerHTML="<b>[ + ]</b>";
		}
	}else{
		if(a_Bool){
			targetElement.style.display = "block";
			a_linkObj.innerHTML="<b>[ - ]</b>";
		}else{
			targetElement.style.display = "none";
			a_linkObj.innerHTML="<b>[ + ]</b>";
		}
	}
	return false;
}
function ShiftExplanPanels(aObjCounts, aLinkObj){
	//ShiftVisible_jpcom com_panel_1
	//click2expend_0 
	if(expen_click=="-"){
		expen_click="+";
		aLinkObj.innerHTML="<b>[ + ]</b>";
		for(var i=0;i<aObjCounts;i++){
			ShiftVisible_jpcom("com_panel_"+i, $("click2expend_"+ i) ,false);
		}
	}else{
		expen_click="-";
		aLinkObj.innerHTML="<b>[ - ]</b>";
		for(var i=0;i<aObjCounts;i++){
			ShiftVisible_jpcom("com_panel_"+i, $("click2expend_"+ i) ,true);
		}
	}
}

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());
	return false;
}
function Copycomment(){
	var reg=/(<BR>)/igm;
	copyit( _word_title+ "\r\n" + $("panel_comment").innerHTML.replace(reg, "\r\n") +"\r\n（沪江在线词典：Dict.hjenglish.com）");
	$("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(!$(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		$(flashcopier).innerHTML = '';
		var divinfo = '<embed src="/common/_clipboard.swf" width="0" height="0" type="application/x-shockwave-flash" id="flashforcopy" name="flashforcopy"></embed>';
		$(flashcopier).innerHTML = divinfo; 
	}
	alert("地址复制成功！");
}

function onInit(){	
	_pageloaded=true;
	$("w").focus();
	//window.document.title="【D】 - "+_pwords+" - 在线日语词典";
	//显示伸缩控制栏
	for(var i=0; i<_matchcounts_int; i++){
		$("click2expend_"+i ).style.display="block";
	}
}

function SelectInput(){ 
	document.getElementById("w").focus();
	document.getElementById("w").select(); 
}
function QueryWord(aword){
	if(window._dictShow){
		_dictShow( aword );
	}
}
function Submit(type){ 
	var word=$("w").value; 
	word=word.replace(" ","");
	var Searchby_letter="";
	var reg=/([^a-zA-Z\.0-9-]{1,})/igm
	if( !reg.test(word)  ){  
		Searchby_letter="&letter=1";
	}else{
		//假名字符
		reg=/([\u3042-\u30f6]{1,})/igm
		if(  reg.test(word)  ){
			type="jc";
		}
	}
	//
	if(word.length==0){
		alert("请输入查询内容！");
		return false;
	}else{
		document.getElementById("testdic").style.display="none";
		try{
			window.location="/jp/w/"+ escape( $("w").value.replace(" ", "+")) + Searchby_letter+ "&type="+ type ;
		}catch(e){
			window.location="/jp/w/"+  $("w").value.replace(" ", "+") + Searchby_letter+ "&type="+ type ;
		}
		return false;
	}
}

function onChange(aevent){
	if(!aevent){ 
		aevent= window.event;
	}
	// 
	if(aevent.keyCode!=40 && aevent.keyCode!=38){ 
		if(_wListInited){
			var word=$("w").value;
			if(word.length>0){
				var word=document.getElementById("w").value; 
				var re=/[a-zA-Z]{1,}/igm ;
				if(re.test(word)){
					document.getElementById("testdic").style.display="none";
					document.getElementById("testdic").innerHTML= "";
					return;
				} 
				if(word.length>LastCompleteWord.length && LastCompleteWord !=""){ 
					if(word.indexOf(LastCompleteWord)==0){
						document.getElementById("testdic").style.display="none";
						document.getElementById("testdic").innerHTML= "";
						return;
					}
				} 
				try{
					document.getElementById("aFlash").DoStringtyped(word);
				}catch(e){
					getwListObj().SetVariable("Stringtyped", word);
				} 
			}else{
				var word=document.getElementById("w").value; 
				var re=/[a-zA-Z]{1,}/igm ;
				if(re.test(word)){
					document.getElementById("testdic").style.display="none";
					document.getElementById("testdic").innerHTML= "";
					return;
				}
			}
		}
	}
}

function OnKeyDown(aevent)
{
	if(!aevent){ 
		aevent= window.event;
	}
	if(document.getElementById("w").value=="请输入要查询的单词"){
		document.getElementById("w").value="";
	} 
	if( aevent.keyCode==13){ 
		if(aevent.ctrlKey){ 
			Submit("cj");
		}else{
			Submit("jc");
		}
		return false;
	}else if(aevent.keyCode==40){
		ShiftSelect(1);
	}else if(aevent.keyCode==38){
		ShiftSelect(-1);
	}
}
var _initdisable=false;
function ShiftDictable2(aBool){ 
	try{
		if(_pageloaded){
			ShiftDictable(aBool);
		}
	}
	catch(e){
		//
	}
}
//历史查询
//var _wordhistory="<%=_wordhistory %>";
//var ReferPage = "--";
//var hasResult= ("<%=hasResult %>"=="True")?1:0;
function HistoryInited(){ 
	getwHistoryObj().AppendHistory(_wordhistory, ReferPage, 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>";            
		document.getElementById("panel_clearhistory").style.display="none";
	}
	document.getElementById("panel_history").innerHTML=Html;
	return;
}
//检测生词本
function chw_callback( result ){
  if(result.error == null){ 
	if(result.value=="no"){ 
		$('suggest2mydict_panel').style.display="block";
	}
  } 
}
function Suggest2MyDict(anewword){ 
	//日语的提示意义不大，忽略
}
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 shiftsearchby_letter_label(){ 
	  
}

//单词自动提示
//word downlist
var _wListInited=false;
var ItemSelected=-1;
var LastCompleteWord="";
function ReturnList(aList){
	var word=document.getElementById("w").value;
	if(aList!="--none" && aList.toString()!="null"){
		aList=aList.split("|");
		var ItemHtml="";
		for(var i=0; i<aList.length; i++){ 
			ItemHtml+= '<div id="item_'+i +'" class="itemNormal" onclick="wordSelect(this);" onmouseover="MouseOver(this);" onmouseout="MouseOut(this);">'+ aList[i].replace(word, "<span class='markchar'>"+word+"</span>") +'</div>';
		}
		document.getElementById("testdic").innerHTML= ItemHtml;
		document.getElementById("testdic").style.display="block";
		ItemSelected=-1; 
	}else{
		if(word!=""){
			LastCompleteWord=word;
		}
		document.getElementById("testdic").style.display="none";
		document.getElementById("testdic").innerHTML= "";
		return;
	}
}
function getwListObj(){ 
	if (navigator.appName.indexOf ("Microsoft") != -1) {
		return window.aFlash;
	} else {
		return window.document.aFlash;
	} 
}
function MouseOver(aObj){
	aObj.className="itemOver";
}
function MouseOut(aObj){
	aObj.className="itemNormal";
}
function wordSelect(aObj){
	document.getElementById("testdic").style.display="none";
	if ( document.all ) {
		document.getElementById("w").value =aObj.innerText;
	}else{
		document.getElementById("w").value =aObj.textContent;
	}		
	ItemSelected =Number(document.getElementById("w").getAttribute("id").split("_")[1]);
}
function ShiftSelect(step){
	var aNObj = document.getElementById("item_"+ (ItemSelected+ step));
	if(aNObj!=null){
		if(ItemSelected!=-1){
			document.getElementById("item_"+ ItemSelected).className="itemNormal"; 
		}
		ItemSelected=ItemSelected+ step;
		aNObj.className="itemOver";
		if ( document.all ) {
			document.getElementById("w").value =aNObj.innerText;
		}else{
			document.getElementById("w").value =aNObj.textContent;
		}		
		document.getElementById("testdic").scrollTop=18*(ItemSelected-3);
	}
}
function wlistInited(){  
	_wListInited=true;
}
function MouseDownOnBody(aevent){
	if(!aevent){ 
		aevent= window.event;
	}
	var srcElement ;
	if ( document.all ) {
		srcElement = aevent.srcElement; 
	}else{
		srcElement = aevent.target; 
	} 
	if(srcElement.getAttribute("id")!=null && srcElement.getAttribute("id").indexOf("item_")==-1 && srcElement.getAttribute("id")!="testdic"){
		document.getElementById("testdic").innerHTML= "";
		document.getElementById("testdic").style.display="none";
	}
}

//添加我的生词  开始
function amw_callback(result){  
  if(result.error == null){
	var retValue=result.value[0];
	var aTurnID=result.value[1];
	if( retValue=="yes"){
		document.getElementById("amw_panel_"+aTurnID).innerHTML='<a href="http://'+ _HjDict_MyDictUrl+ '/mydict/" title="查看我的生词本" target="_blank">添加成功，查看生词本</a>';
		UpdateMydict();
		
	}else if( retValue=="no"){
		document.getElementById("amw_panel_"+aTurnID).innerHTML='<a href="http://'+ _HjDict_MyDictUrl+ '/mydict/" title="查看我的生词本" target="_blank">你添过这个词了</a>';
	
	}else if( retValue=="error"){
		document.getElementById("amw_panel_"+aTurnID).innerHTML='添加失败';
		
	}else if( retValue=="login"){
		if(confirm("只有登录沪江部落后，才能添加自己的生词，现在是否登录？")){ 
			window.open("http://"+ _HjDict_MyDictUrl+ "/login.aspx?returnURL="+ escape("http://bulo.hjenglish.com/mydict/"));    
			document.getElementById("amw_panel_"+aTurnID).innerHTML='请登录后刷新';     
		}else{
			document.getElementById("amw_panel_"+aTurnID).innerHTML='<a href="###" onclick="Do_AddMyWord('+aTurnID+');return false;"><img src="/images/btn_myword_add.gif" alt="将这个单词添加到我的生词本"/></a></a>'; 
		}
	}
  }else{
	alert(result.error);
  }
}
function UpdateMydict(){ 
}
function Do_AddMyWord(aID) {
    var comment = HJ$("amw_comment_" + aID).value;
    comment = comment.replace(/<br><br>/igm, "\n");
    comment = comment.replace(/<br\/>/igm, "\n");
    comment = comment.replace(/<br>/igm, "\n");
    var regEx = /<[^>]*>/g;
    comment = comment.replace(regEx, "");
    PageClass.AddMyWord($("amw_word_" + aID).value, comment, _ReferPage, _searchtype, aID, amw_callback);
}
function AddMyWord(aID){ 
	document.getElementById("amw_panel_"+aID).innerHTML='<img align="absmiddle" src="/images/loading.gif" />';
	setTimeout("Do_AddMyWord("+aID+");", 500 ); 
}
