//
//
function TrimString(aString) 
{ 
	return aString.replace(/(^\s*)|(\s*$)/g, ""); 
}

function f_GetPiece(astring, aIndex, aDirect, aOffset){ 
	if( aIndex<0 || aIndex>astring.Length -1){
		return "";
	}
	if(aDirect==-1){
		if (aIndex - aOffset >-2 )
		{
			return astring.substr(aIndex - aOffset+1, aOffset);
		}else{
			return "";
		}
	}else{
		if (aIndex + aOffset < astring.Length)
		{
			return astring.substr(aIndex, aOffset);
		}else{
			return "";
		}
	}
}
function HjHjContains(aString, aWord){
	return aString.indexOf("'"+aWord+"'")!= -1;
}

function Screen_getCnSplit(sentence, Mousepos)
{
	var reg=/(\')/igm;
	var wordlist="";
	if (TrimString(sentence).Length == 0) {
		return "";
	}
	var reg2=/[a-z]/igm; 
	if (!reg2.test(sentence))
	{  
		var aWords = "";
		var Curword = "";
		for (var b = 2; b < 6; b++)
		{
			Curword = f_GetPiece(sentence, Mousepos, -1, b);
			if (Curword != "" && !HjHjContains(aWords, Curword))
			{
				aWords+=",'"+Curword.replace( reg, "$1$1")+"'";
			}
			Curword = f_GetPiece(sentence, Mousepos, 1, b);
			if (Curword != "" && !HjHjContains(aWords,Curword))
			{
				aWords+=",'"+Curword.replace( reg, "$1$1")+"'";
			}
		}
		for(var b=1;b<6;b++){ 
			for(var m=b+1;m<6;m++){
				Curword = f_GetPiece(sentence, Mousepos + b, -1, m);
				if (Curword != "" && !HjHjContains(aWords,Curword))
				{
					aWords+=",'"+Curword.replace( reg, "$1$1")+"'";
				}
			}
		}
		if (aWords.length > 0)
		{
			aWords+=",'"+sentence.substr(Math.max(0, Mousepos), 1)+"'";
			aWords=aWords.substring(1, aWords.length);
			return aWords;
		}
	}
	return TrimString( sentence.substr(Math.max(0, Mousepos), 1) );
} 
function hj$(objID){
	return document.getElementById(objID);
} 
function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}
function GetSelectContentText()
{
	if (document.frames["hjdContent"].getSelection) return document.frames["hjdContent"].getSelection();
	else if (document.frames["hjdContent"].document.getSelection) return document.frames["hjdContent"].document.getSelection();
	else if (document.frames["hjdContent"].document.selection) returndocument.frames["hjdContent"].document.selection.createRange().text;
	else return '';
}   

function HJ$(aControlID){
	return document.getElementById(aControlID);
}
function ShiftVisible(aObjName){
	var targetElement=HJ$(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;
}
function ShiftCommentArea2(aObj){
	ShiftVisible(aObj+"_content");
	if(HJ$(aObj+"_content").style.display=="none"){
		HJ$(aObj+"_expend").className="expend_on";
	}else{
		HJ$(aObj+"_expend").className="expend_off";
	}
	return false;
}
//
function ShowLoading(){
	try{
		document.getElementById("loading").style.top= (document.documentElement.scrollTop +5)+"px";	
		document.getElementById("loading").style.display='block';	
		document.getElementById("typeing").style.display='none';
	}catch(e){
		//
	}
}
function HideLoading(){
	try{ 
		document.getElementById("loading").style.display='none';	
		document.getElementById("typeing").style.display='none';
	}catch(e){
		//
	}
}
//
var timer_lastShowtypeing=0;
function Hidetypeing(aaa){ 
	try{
		document.getElementById("typeing").style.display='none';
	}catch(e){
		//
	}
	timer_lastShowtypeing=0;
}
function Showtypeing(){
	if(timer_lastShowtypeing!=0){
		clearTimeout(timer_lastShowtypeing);
	}
	try{
		document.getElementById("loading").style.display='none';	
		document.getElementById("typeing").style.top= (document.documentElement.scrollTop +5)+"px";	
		document.getElementById("typeing").style.display='block';
		timer_lastShowtypeing=setTimeout("Hidetypeing();",2000);
	}catch(e){
		//
	}
}
function hjdContent_src(aSrc){
	if(aSrc){
		if(hjdContent_src().indexOf(aSrc)==-1){
			document.frames["hjdContent"].location.href=aSrc;
		}
	}else{
		return document.frames["hjdContent"].location.href;
	}
}
//Flash
function GetFlash(id, playerfile, flashvers ,width, height, NotTransparent){
	if(NotTransparent==true){
		NotTransparent="window";
	}else{
		NotTransparent="transparent";
	}
	var str="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0'";
	str+="width='"+ width+ "' height='"+ height+ "' id='"+ id +"' align='middle' >";
	str+="<param name='allowScriptAccess' value='always' />";
	str+="<param name='movie' value='"+playerfile+"' />";
	str+="<param name='quality' value='high' />";
	str+="<param name='scale' value='noScale' />";
	str+="<param name='align' value='tl' />";
	str+="<param name='wmode' value='"+NotTransparent+"' />"; 
	str+="<param name='flashvars' value='"+flashvers+"' />";
	str+="<embed src='"+playerfile+"' quality='high' scale='noScale' bgcolor='#ffffff' width='"+ width+ "' height='"+ height+ "' flashvars='"+flashvers+"' id='"+ id +"' name='"+ id +"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/>";
	str+="</object>";
	document.write(str);
}
function GetFlashCode(id, playerfile, flashvers ,width, height, transparent){
	if(transparent!=true){
		transparent="window";
	}else{
		transparent="transparent";
	}
	var str="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0'";
	str+="width='"+ width+ "' height='"+ height+ "' id='"+ id +"' align='middle' >";
	str+="<param name='allowScriptAccess' value='always' />";
	str+="<param name='movie' value='"+playerfile+"' />";
	str+="<param name='quality' value='high' />";
	str+="<param name='scale' value='noScale' />";
	str+="<param name='wmode' value='"+transparent+"' />"; 
	str+="<param name='flashvars' value='"+flashvers+"' />";
	str+="<embed src='"+playerfile+"' quality='high' scale='noScale' bgcolor='#ffffff' width='"+ width+ "' height='"+ height+ "' flashvars='"+flashvers+"' id='"+ id +"' name='"+ id +"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'/>";
	str+="</object>";
	return str;
}
function GetWord(aWord){
	var ID= 9999999*Math.random();
	GetFlash("hjw_"+ ID, "http://dict.hjenglish.com/speaker_wv.swf", "w="+ aWord.split(" ").join("#"), 16, 16, false ); 
}
function GetWordCode(aWord){
	var ID= 9999999*Math.random();
	return GetFlashCode("hjw_"+ ID, "http://dict.hjenglish.com/speaker_wv.swf", "w="+ aWord.split(" ").join("#"), 32, 16, false ); 
}
//
//