var win = null;

var	TEST_PRIVATE_IP = "";//"192.168.101.222";//협약도서관, "192.168.999.999";//비협약도서관;

function loadActiveX(argClassName)
{
 try {
  var obj = new ActiveXObject(argClassName);
  if(null == obj) { throws; }
  return obj;
 }
 catch(e) { return null; }
}

//뷰어를 popup으로 열기 - IE에서 resize안됨
function openviewer_popup(argcno, argsysid, db_num, doc_id) {
	//thisfrm = document.frmViewer;
	var	popwidth = screen.availWidth;
	var	popheight = screen.availHeight;
	var	poptop = 0;
	var	popleft = 0;
	var macAddress = "";
	var dt=new Date();
	var getTime = dt.getHours()+""+dt.getMinutes()+""+dt.getSeconds();
//alert(getTime);
	if(poptop < 0) { poptop = 0; }

	var	winprops = "height=" + popheight + ",width=" + popwidth + ","
			+ "top=" + poptop + ",left=" + popleft + ","
			+ "toolbar=no,resizable=yes,location=no,scrollbars=yes,status=no";
//	var	win_viewer = window.open("", "pop_viewer", winprops);
	var	win_viewer = window.open("", getTime, winprops);
	win_viewer.focus();

	/* MacAddress 가져오는부분 */
	xsys = loadActiveX("XViewer.SysRes");
	if(null == this.xsys) {
		macAddress = "none";
	}
	else {
		macAddress = this.xsys.MacAddress;
		macAddress = macAddress.substring(0,2)+'-'+macAddress.substring(2,4)+'-'+macAddress.substring(4,6)+'-'+macAddress.substring(6,8)+'-'+macAddress.substring(8,10)+'-'+macAddress.substring(10,12);
	}
	/* MacAddress 가져오는부분 */

	document.frmViewer.cno.value = argcno;
	document.frmViewer.lip.value = macAddress;
	document.frmViewer.v_db.value = db_num;
	document.frmViewer.v_doc_id.value = doc_id;
	if(null == argsysid) {
		document.frmViewer.sysid.value = "";
	} else {
		document.frmViewer.sysid.value = argsysid;
	}
//	document.frmViewer.target = "pop_viewer";
	document.frmViewer.target = getTime;
	document.frmViewer.action = '/JavaClient/jsp/dasen/viewWonmun.jsp';
	document.frmViewer.submit();
}

//뷰어를 popup으로 열기 - IE에서 resize안됨
function openviewer_old_popup(argcno, argsysid, db_num, doc_id) {
	document.frmViewer.action = 'http://ultra.dlibrary.go.kr/ndli/dasencgi/bin/view_list.cgi//'+db_num+'_'+doc_id+'.dliv';
	document.frmViewer.v_mode.value = "fulltext";
	document.frmViewer.v_db.value = db_num;
	document.frmViewer.v_doc_no.value = doc_id;

	document.frmViewer.target = '_self';
	document.frmViewer.submit();
}

//뷰어를 창으로 열기
function openviewer_win(argcno, argsysid,argdb,argdoc) {
	thisfrm = document.frmViewer;

	thisfrm.cno.value = argcno;
	thisfrm.lip.value = TEST_PRIVATE_IP;
	thisfrm.v_db.value = argdb;
	thisfrm.v_doc_id.value = argdoc;
	if(null == argsysid) { thisfrm.sysid.value = ""; }
	else { thisfrm.sysid.value = argsysid; }
	thisfrm.target = "win_viewer";
	thisfrm.submit();
}

//뷰어도움말페이지 보기
function openHelpPage() {
	var	popwidth = 800;
	var	popheight = 700;
	var	poptop = (screen.height - popheight) / 2 - 40;
	var	popleft = (screen.width - popwidth) / 2;

	if(poptop < 0) { poptop = 0; }

	var	winprops = "height=" + popheight + ",width=" + popwidth + ","
			+ "top=" + poptop + ",left=" + popleft + ","
			+ "toolbar=no,resizable=no,location=no,scrollbars=yes,status=no";
	var	win_url = "";
	win_url = "http://192.168.101.234:8090/help_viewer/viewer_help.jsp";
	//win_url = "./help_viewer/viewer_help_" + objUser.lang + ".jsp";

	var	win_help = window.open(win_url, "pop_help", winprops);
	//var	win_help = window.open(win_url);
	win_help.focus();
}

function brief_win(kwstr,dbno,docid)
{
	var new_url= null;
	//alert(kwstr);
	//alert(dbno);
	//alert(docid);

	new_url = "/JavaClient/jsp/wonmun/full2.jsp?v_kw_str="+kwstr+"&v_db="+dbno+"&v_doc_no="+docid+"&mode=1";
	//alert('[' + new_url + ']');		// for test
	win = window.open(new_url, 'view_window', 'scrollbars=yes,resizable=yes,toolbar=no,width=668,height=500');
}

function brief_win1(kwstr,dbno,docid)
{
	var new_url= null;
	//alert(kwstr);
	//alert(dbno);
	//alert(docid);

	new_url = "/JavaClient/jsp/ndli/full2.jsp?v_kw_str="+kwstr+"&v_db="+dbno+"&v_doc_no="+docid+"&mode=1";
	//alert('[' + new_url + ']');		// for test
	win = window.open(new_url, 'view_window', 'scrollbars=yes,resizable=yes,toolbar=no,width=668,height=500');
}

function go_normal()
{
        document.location.replace("print_form.cgi?v_searchtype=1");
}

function go_detail()
{
        document.location.replace("print_form.cgi?v_searchtype=0");
}

function select_submit(mode)
{
        if(mode == 1) 	/* search */
	{
		if(document.select.v_kw_query.value.length == 0)
		{
			alert("키워드 : 검색어를 입력하시기 바랍니다.");
                        return false;
		}
                document.select.action="/dasencgi/brief.cgi";
	}
        else if(mode == 0) /* scan */
                document.select.action="/dasencgi/scan.cgi";
/*        document.select.submit(); */
}

function run_submit(form, mode)
{
        if(mode == 1)
                form.action="/dasencgi/brief.cgi";
        else if(mode == 0)
                form.action="/dasencgi/scan.cgi";
	form.submit();
}

function multilang_open(name)
{
	var	url = "";

	if(win != null)
		win.close();

	win = window.open('', 'multilang_window', 'scrollbars=yes,resizable=yes,toolbar=yes,width=800,height=620');

	if(win != null)
	{
		win.location.href = 'http://211.185.62.18/JavaClient/jsp/multilang/print_frame.cgi?v_name='+name;
		win.focus();
	}
	return;
}

function view_win(mode, dbno, docid)
{
	if(mode != 'fulltext')
		selectwin = window.open('','view_window','scrollbars=yes,resizable=yes,width=600,height=450');
	else
		document.view.action = "/JavaClient/jsp/dasen/searchAticle.jsp";
	document.view.v_mode.value = mode;
	document.view.dbNoArr.value = dbno;
	document.view.docNo.value = docid;

	if(mode != 'fulltext')
		selectwin.focus();
	else
		document.view.target = '_self';
	document.view.submit();
}
function view_win1(mode, dbno, docid)
{
	if(mode != 'fulltext')
		selectwin = window.open('','view_window','scrollbars=yes,resizable=yes,width=600,height=450');
	else
		document.view.action = "/JavaClient/jsp/dasen/searchKwonho.jsp";
	document.view1.v_mode.value = mode;
	document.view1.dbNoArr.value = dbno;
	document.view1.docNo.value = docid;

	if(mode != 'fulltext')
		selectwin.focus();
	else
		document.view1.target = '_self';
	document.view1.submit();
}

function viewer_win(url) {
        win = window.open('', 'viewer_window', 'scrollbars=yes,resizable=yes,toolbar=no,width=400,height=300');

        win.document.write("<html>\n");
        win.document.write("<head><title>Viewer 다운로드</title></head>\n");
        win.document.write("<body>\n");
        win.document.write("<font size=+1 face=돋움체>뷰어를 다운로드 합니다.</font>\n");
        win.document.write("<form name=viewer action='" + url +"'>\n");
        win.document.write("</form>\n");
        win.document.write("<script language=Javascript>\n");
        win.document.write("document.viewer.submit();\n");
        win.document.write("</script>\n");
        win.focus();
        //win.close();
}

function open_window(Seqno, ControlNo)
{
	aa = window.open('', 'win', 'scrollbars=yes,resizable=yes,toolbar=no,left=50,top=20,width=900,height=700');
	aa.document.location = '/dasencgi/NL_UH102CB?seqno='+Seqno+'&ctrno='+ControlNo;

/*
	if(aa != null)
	{
		aa.document.write("<HTML>\n");
		aa.document.write("<head>\n");
		aa.document.write("</head>\n");
		aa.document.write("<body>\n");
		aa.document.write("<form name=fmCall action=http://211.185.62.18:8080/dasencgi/NL_UH102CB method=post>\n");
		aa.document.write("<input type=hidden name='seqno' value="+Seqno+">\n");
		aa.document.write("<input type=hidden name='ctrno' value="+ControlNo+">\n");
		aa.document.write("</form>\n");
		aa.document.write("<script language=JavaScript>\n");
		aa.document.write("document.fmCall.submit();\n");
		aa.document.write("</script>\n");
		aa.document.write("</body>\n");
		aa.document.write("</HTML>\n");
	}
*/
}

function help_win(url) {
        win = window.open('', 'help_window', 'scrollbars=yes,resizable=yes,toolbar=no,width=650,height=600');
        //var url = "../html/help.html#help_" + num;
        win.location.href = url;
        win.focus();
}

function open_codetree(db_id, code_id)
{
//	var url = "/codecgi/bin/codetree.cgi?v_dbid=" + db_id;
	var url = "codetree.jsp?menu=1&command=&dbNoArr=&v_dbid=" + db_id;
	if(code_id.length > 0)
		url = url + "&v_codeid=" + code_id + "&v_class1=&v_class2=&kwStr=";

	//parent.left.document.location.href = url;
	//document.location.href = "http://211.185.62.18/NCL/HTML/doc/cen_svc_406.html";

	document.location.href = url;
}
/*
function Check_Kwstr()
{
	var find = 0;
	for(var i=0; i < document.all.length; i++)
	{
		var field_name = "" + document.all(i).name + "";
		var pos = field_name.indexOf('kwStr');
		if(pos != -1)
		{
			if(document.all(i).value.length != 0)
				find = 1;
		}
	}
	if(find == 0)
	{
		alert("필드제한 : 검색어를 입력하시기 바랍니다.");
		return false;
	}
	return true;
}
*/

function full_win(dbno, pos) {
 	document.full_view.v_db.value = dbno;
 	document.full_view.v_pos.value = pos;
 	document.full_view.submit();
}

function view_win2(controlNumber)  {
	var new_url = 'http://211.185.62.18/Map/main.jsp?code=' + controlNumber;
	//alert('[' + new_url + ']');		// for test
//	win = window.open(new_url, 'brief_window', 'scrollbars=yes,resizable=yes,toolbar=yes,width=750,height=620');
	win = window.open(new_url, 'brief_window', 'scrollbars=yes,resizable=yes,toolbar=no,width=750,height=620');
/*
	if (win != null)  {
		win.location = new_url;
		win.focus();
	}
	*/
}

function marc_win() {
	selectwin = window.open('','marc_window','scrollbars=yes,resizable=yes,width=600,height=600');
	//selectwin.focus();
	//document.marc_view.target = '_self';
	document.marc_view.submit();
}

function view_win3(mode, dbno, docid, v_control_no)
{
	document.view.v_mode.value = mode;
	document.view.dbNoArr.value = dbno;
	document.view.docNo.value = docid;
	document.view.v_control_no.value = v_control_no;
	document.view.target = '_self';
	document.view.action='/JavaClient/jsp/dasen/searchAticle.jsp';
	document.view.submit();
}

function Err_Confirm(num){
	var num;
	//alert(num);

	location.href="http://www.dlibrary.go.kr/JavaClient/jsp/wonmun/Admin/ADMIN/NL_UH701we.jsp?controlno="+num;
}

function CheckForm(){

   var f = document.frm_WriteCheck;

   if (isEmpty(f.Title.value))
   {
      alert("글제목을 입력해주세요.");
	  f.Title.focus();
	  return false;
     }

      if ( isEmpty(f.Contents.value) )
   {
      alert("내용을 입력해주세요.");
	   f.Contents.focus();
	  return false;
   }
	 f.submit();
	 return true;

}

function Clear() {
   document.frm_WriteCheck.reset();
   return false;
}

function isEmpty(data){
   for ( var i = 0 ; i < data.length ; i++ ) {
      if ( data.substring( i, i+1 ) != " " )
         return false;
      }
   return true;
}

function briefwin(kwstr,dbno)
{
	var new_url= null;
	//alert(kwstr);
	//alert(dbno);
	//alert(docid);

	//new_url = "/JavaClient/jsp/ndli/full2.jsp?v_kw_str="+kwstr+"&v_db="+dbno+"&v_doc_no="+docid+"&mode=1";
	new_url="/JavaClient/Servlet/SearchServlet?command=brief&kwStr="+encodeURIComponent(kwstr)+"&v_db_str=&v_cmp_str=&dbNoArr="+dbno+"&v_sort1=1&v_sort_type=0&v_close=&startNo=1&pageNum=5&mode=0&ViewMode=1";
	//alert('[' + new_url + ']');		// for test
	win = window.open(new_url, 'view_window', 'scrollbars=yes,resizable=yes,toolbar=no,width=668,height=500');
}