//
//
var LastAjaxObj=0;
var last_googleword={word:"",lang:"en",page:""};//word/lang

function loadingGoogle_Done(Mydata){
	if(HJ$("word_local").innerHTML!=last_googleword.word){
		return ;
	}
	try{
		if(Mydata.length>0){ 
			var html = "";
			// 
			if(last_googleword.lang=="en"){				
				if(Mydata.indexOf("找不到关于")==-1){ 
					var result_about =window.external.RegAction(1, Mydata, "(<p>相关词句.*?<\/p>)", "\\1"); 
					if( result_about.length>0 ){
						result_about =window.external.RegAction(2, result_about, "<a href=\".*?\">(.*?)<\/a>", "<a href=\"###\" onclick=\"window.external.SearchWordInClient(\'\\1\', false);return false;\">\\1</a>"); 
						html+= result_about;		
					} 
					var result_explan =window.external.RegAction(1, Mydata, "(<ul type=\"disc\">.*?<\/ul>)", "\\1");   
					if( result_explan.length>0 ){
						//
						result_explan =window.external.RegAction(2, result_explan, "<a href=\"(.*?)\">(.*?)<\/a>", "<a href=\"http://www.google.cn\\1\" target=\"_blank\">\\2</a>"); 
						html+= result_explan;
					}
					html+= "<div style='padding-left:25px;'>[<a href='"+ last_googleword.page +"' target='_blank'>网络注释由Google提供</a>]</div>";
				}
			}else{
				var result_explan =window.external.RegAction(1, Mydata, "<!--メインカラム -->.*?(<table .*table>).*?<!--メインカラム -->", "\\1"); 
				if( result_explan.length>0 ){
					result_explan =window.external.RegAction(2, result_explan, "\"5\"", "\"0\""); 
					result_explan =window.external.RegAction(2, result_explan, "EAE4BF", "DDF39A");
					result_explan =window.external.RegAction(2, result_explan, "提供：", "<br/>提供：");					
					html+= result_explan;		
					html+= "<br/>[<a href='"+ last_googleword.page +"' target='_blank'>网络注释由Yahoo辞书提供</a>]";
				}
			}
			//
			if(html.length>0){
				HJ$("google_loading").innerHTML="";
				HJ$("google_loading").style.display="none";
				//
				HJ$("googleabout_explan").innerHTML=html;
				HJ$("googleabout").style.display="block";
			}else{
				HJ$("google_loading").innerHTML="<span class='green'>[暂无网络释义]</span>";
			}
		}else{
			HJ$("google_loading").innerHTML="<span class='green'>[暂无网络释义]</span>";
		}
		last_googleword = {word:"",lang:"en",page:""};
	}catch(e){
		HJ$("google_loading").innerHTML="<span class='green'>[网络释义无法加载]</span>";
	}
	delete LastAjaxObj;
	LastAjaxObj=null;
	LastAjaxObj=0;
}
function loadingGoogle(aWord, alang){
	if(window.external.NetConnented_Cache){
		var word = HJ$("word_local").innerHTML;
		if(aWord==word && word.length>0 && word.indexOf("[")==-1 ){
			try{
				if (LastAjaxObj!=0)
				{
					LastAjaxObj.abort();
				}
				HJ$("google_loading").style.display="none";
				delete LastAjaxObj;
				LastAjaxObj=null;
				LastAjaxObj=0;
			}catch(e){}
			last_googleword.word = aWord;
			last_googleword.lang = alang;
			if(alang=="en"){
				last_googleword.page = "http://www.google.cn/custom?q=define:"+ encodeURI(aWord)+"&hl=zh-CN&newwindow=1&client=pub-9431223457990277&channel=4743174050&cof=&oi=definel&defl=en";
				LastAjaxObj = $.get(last_googleword.page, null, loadingGoogle_Done ); 
			}else{
				last_googleword.page = "http://dic.yahoo.co.jp/dsearch?enc=UTF-8&p="+ encodeURI(aWord) +"&stype=1&dtype=2";
				LastAjaxObj = $.get(last_googleword.page, null, loadingGoogle_Done ); 
			}
			HJ$("google_loading").innerHTML="<img src='images/loading.gif' align='absmiddle'/> 加载网络释义...";
			HJ$("google_loading").style.display="block";
			HJ$("googleabout").style.display="none";
		}	
	}
}
//
// ============================ 
var LastAjaxObj_onlinedict=0;
var last_onlineword={word:"",lang:"",ctrl:false};

function loadingDictOnline_Done(Mydata){ 
	if(HJ$("word_local").innerHTML!=last_onlineword.word){
		return ;
	}
	try{
		if(Mydata.length>0){ 
			var retList=eval(Mydata);
			var t_lang = retList[0];
			var t_hasresult = retList[1];
			var t_suglist = retList[2];
			var html = "<BR>";
			if(t_hasresult || t_suglist.length>0){
				if(t_hasresult){
					html+= "<img src='images/icon_ie.gif' align='absmiddle'/> <a href=\"###\" onclick='return ViewOnlineExplan(\""+ last_onlineword.word +"\");'>点击查看联机注释</a><br/>";
				}
				if(t_suglist.length>0){
					html+= "<b>你要查的或许是：</b><div style='padding:10px 10px 10px 25px;'>";
					for(var i=0;i<t_suglist.length;i++){
						html+= "<a href='###' onclick='return ViewOnlineExplan(\""+ t_suglist[i] +"\");'>"+ t_suglist[i] +"</a>, ";
					}
					html+= "</div>";
				}
				DoLocalNoResult(false,html);
				//HJ$("panel_dictonline").innerHTML=html;
				//补查google释义
				setTimeout("loadingGoogle(\""+ last_onlineword.word+ "\",\""+ last_onlineword.lang+ "\");", 30); 
			}else{
				DoLocalNoResult(false);
			}
		}else{ 
			DoLocalNoResult(false);
		}
		last_onlineword = {aword:"",alang:"",ctrl:false};
	}catch(e){ 
		DoLocalNoResult(false, "<br/>加载联机注释未成功"+e.message);
	}
	delete LastAjaxObj_onlinedict;
	LastAjaxObj_onlinedict=null;
	LastAjaxObj_onlinedict=0;
}

function loadingDictOnline(aword, alang, actrl){
	try{
		if (LastAjaxObj_onlinedict!=0)
		{
			LastAjaxObj_onlinedict.abort();
		}
		delete LastAjaxObj_onlinedict;
		LastAjaxObj_onlinedict=null;
		LastAjaxObj_onlinedict=0;
	}catch(e){}
	//
	actrl= ((actrl==true)?"1":"0");
	last_onlineword={word:aword,lang:alang,ctrl:actrl}; 
	//	
	HJ$("panel_dictonline").style.display= "block";
	HJ$("panel_dictonline").innerHTML= "<BR><span style='font-size:14px;'>本地词库暂无相符的解释</span><BR><BR><img src='images/loading.gif' align='absmiddle'/> 查询联机词库中 ..."; 

	var url="http://dict.hjenglish.com/client/api_clientquery.aspx?w="+encodeURI(aword)+"&lang="+ alang +"&ctrl="+ actrl; 
	LastAjaxObj_onlinedict = $.get(url, null, loadingDictOnline_Done );
	//	
}