// JavaScript Document

function lh_topSearch(form){
	if(!validateSearch(form)){
		return;
	}
	
	var myhf = document.getElementById("mylhform");
	if(myhf!=null && myhf.show.value=="set" && typeof displistchoice=="function"){
		var mode = form.ls_mode.options[form.ls_mode.selectedIndex].value;
		displistchoice(mode,form.ls_inp.value,"");
	}else{
		form.submit();
	}
}

function validateSearch(form){
	if(form.ls_inp.value==""){
		if(form.ls_mode.selectedIndex==1){
			alert("Please input an English word!");
			form.ls_inp.focus();
			return false;
		}else if(form.ls_mode.selectedIndex==0){
			alert("Please input a valid pinyin!");
			form.ls_inp.focus();
			return false;
		}
	}
	return true;
}
function setNav(module){
	if(document.getElementById("navtd_"+module)!=null){
		markNav(document.getElementById("navtd_"+module));
	}
}
function markNav(td){
	/* td.style.backgroundColor="#fc0"; */
	td.style.borderRight="solid 1px #000";
	td.style.borderLeft="solid 1px #000";
}

function unmarkNav(td,sel){
	
	if(sel!=1){
		td.style.borderRight="solid 1px #ff6";
		td.style.borderLeft="solid 1px #ff6";
	}
/*	
	else{
		td.style.backgroundColor="#ff6";
	}
*/
}

/* mouseover and mouseout for general himg in my hanzi & search */
function hc_mark(elem){
  //elem.style.backgroundColor="#cccccc";
  elem.style.backgroundColor="#ff6";
}
function hc_umark(elem){
  elem.style.backgroundColor="";
}


//Part-search
function searchHPart(uniint){
	var myhf = document.getElementById("mylhform");
	if(myhf!=null && myhf.show.value=="set" && typeof displistchoice=="function"){
		displistchoice("prt",uniint,"");
		//myhlist("prt",uniint,1,"",false);
	}else{
		var form = document.lhpartsrchform;
		form.show.value="list";
		form.type.value="prt";
		form.code.value=uniint;
		form.submit();
	}
}

//Open popup "window" 
function openPop(contentElement,width,height,x,y){
	
	var div,elem;
	if((div=document.getElementById("lh_popDiv"))==null){
		div = document.createElement("div");
		div.id = "lh_popDiv";
	}
	div.style.position = "absolute";
	div.style.visibility = "visible";
	if(width!=""){
		div.style.width = width+"px";
	}
	if(height!=""){
		div.style.height = height+"px";
	}
	div.style.left = x+"px";
	div.style.top = y+"px";
	
	var topdiv = document.createElement("div");
	topdiv.id = "lh_popTopDiv";
	elem = document.createElement("a");
	elem.href = "javascript:closePop()";
	elem.appendChild(document.createTextNode("Close"));
	topdiv.appendChild(elem);
	div.appendChild(topdiv);
	div.appendChild(contentElement);
	document.body.appendChild(div);
}

//Close popup "window" 
function closePop(){
	var div=document.getElementById("lh_popDiv");
	if(div!=null){
		document.body.removeChild(div);
	}
}


