function encodeKey(value){
	return encodeURIComponent(value);
	//return value;
}

function getSearchUrl(keyId,nodeId, classId){
	var key = document.getElementById(keyId);
	if(key.value == ""){
		alert("\u8BF7\u8F93\u5165\u67E5\u8BE2\u5173\u952E\u5B57\uFF01");
		key.focus();
		return false;
	}
	var url = search_keyword_template_path + 'search_result_hdrc.jsp?NODE_ID=' + nodeId + '&SEARCH_WORD=' + encodeKey(key.value);
	if(document.getElementById(classId)){
		url += '&ARTICLE_CLASS_ID=' + document.getElementById(classId).value; 
	}
	url += '&SEARCH_NODE_ID=all'; // search all sites
	return url;
}

function submitSearch(keyId, nodeId, classId){
	var url = getSearchUrl(keyId,nodeId, classId);
	if(url==false) return false;
	if(document.location.href.indexOf(search_keyword_template_path+"search_result_hdrc.jsp") == -1){
		window.open(url);
	}else{
		top.location.href = url;
	}
	/*
	var key = document.getElementById(keyId);
	if(key.value == ""){
		alert("\u8BF7\u8F93\u5165\u67E5\u8BE2\u5173\u952E\u5B57\uFF01");
		key.focus();
		return false;
	}
	var url = '/symbol/fullsearch/search_result.jsp?NODE_ID=' + nodeId ;
	if(classId){
		url += '&ARTICLE_CLASS_ID=' + document.getElementById(classId).value; 
	}
	var searchform = document.createElement('FORM');
	searchform.action = url;
	if(document.location.href.indexOf("/symbol/fullsearch/search_result.jsp") == -1){
		searchform.target = '_blank';
	}else{
		searchform.target = '_top';
	}
	
	searchform.method = 'post';
	var searchword = document.createElement("input");
	searchword.type='hidden';
	searchword.name='SEARCH_WORD';
	searchword.value=key.value;
	searchform.appendChild(searchword);
	document.body.appendChild(searchform);
	searchform.submit();	
	*/
}


function searchKeyPress(keyId, nodeId, classId){
	if(event.keyCode == 13){		
		//document.getElementById("Submit2").focus();		
		submitSearch(keyId, nodeId, classId);
	}
}

function submitHightSearch(){
	var key = document.getElementById("title").value +" "+ document.getElementById("content").value +" "+ document.getElementById("key").value +" "+ document.getElementById("summary").value ;
	if(Trim(key) == ""){
		alert("请至少输入一个查询条件！");
		document.getElementById("title").focus();
		return false;
	}
	
	var url = search_keyword_template_path + 'search_hight_result.jsp?NODE_ID=root&SEARCH_WORD=' + encodeKey(key);
	if(document.getElementById("ARTICLE_CLASS_ID")){
		url += '&ARTICLE_CLASS_ID=' + document.getElementById("ARTICLE_CLASS_ID").value; 
	}
	url += '&SEARCH_NODE_ID=all'; // search all sites
	window.open(url);	
	//top.location.href = url;	
}

function LTrim(str){ //去掉字符串 的头空格
var i;
for(i=0;i<=str.lenght;i++){ if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;
}
str = str.substring(i,str.length);
return str;
}

function RTrim(str){
var i;
for(i=str.length-1;i>=0;i--){
if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;
}
str = str.substring(0,i+1);
return str;
}

function Trim(str){ 
return LTrim(RTrim(str));

}