function na_restore_img_src(name, nsdoc)
{
  var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
  if (name == '')
    return;
  if (img && img.altsrc) {
    img.src    = img.altsrc;
    img.altsrc = null;
  } 
}

function na_preload_img()
{ 
  var img_list = na_preload_img.arguments;
  if (document.preloadlist == null) 
    document.preloadlist = new Array();
  var top = document.preloadlist.length;
  for (var i=0; i < img_list.length; i++) {
    document.preloadlist[top+i]     = new Image;
    document.preloadlist[top+i].src = img_list[i+1];
  } 
}

function na_change_img_src(name, nsdoc, rpath, preload)
{ 
  var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
  if (name == '')
    return;
  if (img) {
    img.altsrc = img.src;
    img.src    = rpath;
  } 
}

function search_item() {
	query = document.formSearch.searchTerm.value;
	if (CheckStr(query, " ", "")==0) {
		alert ("검색어를 입력하세요");
		document.formSearch.searchTerm.value = ""
		document.formSearch.searchTerm.focus();
		return;
	}
	if(document.formSearch.search_cate.value == "total") document.formSearch.action = "<%=HomeUrl%>/search/search_total.jsp";
	else if(document.formSearch.search_cate.value == "news") document.formSearch.action = "<%=HomeUrl%>/search/search_news.jsp";
	else if(document.formSearch.search_cate.value == "study") document.formSearch.action = "<%=HomeUrl%>/search/search_study.jsp";
	else if(document.formSearch.search_cate.value == "krict") document.formSearch.action = "<%=HomeUrl%>/search/search_krict.jsp";
	else if(document.formSearch.search_cate.value == "custom") document.formSearch.action = "<%=HomeUrl%>/search/search_custom.jsp";

	document.formSearch.submit();
}

function CheckStr(strOriginal, strFind, strChange){
	var position, strOri_Length;
	position = strOriginal.indexOf(strFind);
	while (position != -1){
	  strOriginal = strOriginal.replace(strFind, strChange);
	  position    = strOriginal.indexOf(strFind);
	}
	strOri_Length = strOriginal.length;
	return strOri_Length;
}

function search_item(thisform) {
	query = thisform.searchTerm.value;
	if (CheckStr(query, " ", "")==0) {
		alert ("검색어를 입력하세요");
		thisform.searchTerm.value = ""
		thisform.searchTerm.focus();
		return;
	}
	if(thisform.search_cate.value == "total") thisform.action = "<%=HomeUrl%>/search/search_total.jsp";
	else if(thisform.search_cate.value == "news") thisform.action = "<%=HomeUrl%>/search/search_news.jsp";
	else if(thisform.search_cate.value == "study") thisform.action = "<%=HomeUrl%>/search/search_study.jsp";
	else if(thisform.search_cate.value == "krict") thisform.action = "<%=HomeUrl%>/search/search_krict.jsp";
	else if(thisform.search_cate.value == "custom") thisform.action = "<%=HomeUrl%>/search/search_custom.jsp";

	thisform.submit();
}

function change_searchTerm(new_searchTerm) {		// 추천 검색어
	document.formSearch.searchTerm.value = new_searchTerm;
	document.formSearch.submit();
}

function change_page(){	// 카테고리 탭 전환
	if(document.formSearch.search_cate.value == "total") document.formSearch.action = "<%=HomeUrl%>/search/search_total.jsp";
	else if(document.formSearch.search_cate.value == "news") document.formSearch.action = "<%=HomeUrl%>/search/search_news.jsp";
	else if(document.formSearch.search_cate.value == "study") document.formSearch.action = "<%=HomeUrl%>/search/search_study.jsp";
	else if(document.formSearch.search_cate.value == "krict") document.formSearch.action = "<%=HomeUrl%>/search/search_krict.jsp";
	else if(document.formSearch.search_cate.value == "custom") document.formSearch.action = "<%=HomeUrl%>/search/search_custom.jsp";
}

function search_tab(search_cate, searchTerm) {
	if(search_cate == "total") document.formSearch.action = "<%=HomeUrl%>/search/search_total.jsp";
	else if(search_cate == "news") document.formSearch.action = "<%=HomeUrl%>/search/search_news.jsp";
	else if(search_cate == "study") document.formSearch.action = "<%=HomeUrl%>/search/search_study.jsp";
	else if(search_cate == "krict") document.formSearch.action = "<%=HomeUrl%>/search/search_krict.jsp";
	else if(search_cate == "custom") document.formSearch.action = "<%=HomeUrl%>/search/search_custom.jsp";

	document.formSearch.searchTerm.value = searchTerm;
	document.formSearch.submit();
}

function handleEnter (event, thisform) {	 // 엔터로 검색
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; 
	if (keyCode == 13) { 
		search_item(thisform);
		return false; 
	} 
	else 
		return true;
}


var keystatus = 1;
function setTextBox(flag) {
	var textbox = document.formSearch.searchTerm; 
	var _event; 
	switch ( getNavigatorType() ) {
		case 1 : // IE
			_event = window.event;
			nodeName = _event.srcElement.nodeName;
			break;
		case 2 : // Netscape
			_event = event;
			nodeName = _event.target.nodeName;
			break;
		default :
			nodeName = "None"; 
			break;
	}
	key = _event.keyCode;
	if ( keystatus == 1 && flag && key != 13) {
		textbox.value = "";
		keystatus = 2;
	}
}

function getNavigatorType() {
	if ( navigator.appName == "Microsoft Internet Explorer" )
		return 1;  
	else if ( navigator.appName == "Netscape" )
		return 2;	
	else 
		return 0;
}

function subjectSubstring(title, max){	
	var strlen = parseInt(max);		
	var bylen = parseInt(0);
	
	var c_lenc = parseInt(title.length);
	
	try{
		if(c_lenc > max){
	    	if(c_lenc > max - 1 ) {
		    	strlen = 0;
		    	for (var x = 0 ; bylen < (max-1)*2 && strlen < c_lenc ; x++) {
			    	c_char = title.charAt(strlen);
			    	ch=c_char.charCodeAt();
			    	bylen++;
			    	strlen++;
			    	if (ch>255||(ch>64&&ch< 91)) bylen++;
		    	}
	    	}
	    	if (c_lenc > strlen) {
	    		title = title.substring(0, strlen) + "..";
	    	}
		}
	} catch(e){
		alert("e:"+e);
	}
	
	document.write(title);
}
// 글자수의 Max값을 주어 넘어갔을경우 ..을 붙이고 값을 반환

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
		if ((obj=MM_findObj(args[i]))!=null) {
		v=args[i+2];
    if (obj.style) {
			obj=obj.style; 
			v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
    obj.visibility=v; 
		}
}
