﻿
function doPotalSearch(){
    if($F('query')==''){
       $('query').focus();
       alert('검색어를 입력하십시오.');
       return;
    }
//    $('search_word').value=$('query').value;
    $('searchText').value=$('query').value;
    document.potal_form.submit();

}

function openime() {
	//var str = escape(eval("document."+ formName + ".keyword.value"));
	var wnd = window.open('HAN/inputassist.htm','문자입력기', 'toolbar=no, width=580, height=480');
	wnd.focus(); 
} 

function setInput(str){
 $('query').value+=str; 
}

  function showErrReport(){
        if(myProp.UserId==''){
            alert('로그인을 하셔야 오류신고를 하실 수 있습니다.');
            return;
        }
       	window.open('err_report.aspx','오류신고','toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=yes,titlebar=no, resizable=no,width=790,height=480, top=100, left=100' );      

    }
    
    function showEbook(str){
        var url='E_BOOK/main/temp_pi.asp?seoji_id=' + str
        window.open(url,'','');
    }

// 원문 이미지 뷰어
//	var popImageViewer;
    function getMiddleImageInfo()
    {
       if(myProp.objMiddleImg.readyState == 'complete')
        {
//    		alert(myProp.objMiddleImg.width + ",,,, " + myProp.objMiddleImg.height);
            myProp.nMiddleWidth = myProp.objMiddleImg.width;
            myProp.nMiddleHeight = myProp.objMiddleImg.height;
//    		delete myProp.objMiddleImg;

//		    myProp.objLargeImg = new Image();
		    var strTempImage = myProp.strLargeUrl + myProp.strImagePath + "_0003.jpg";
		    myProp.objLargeImg.src = strTempImage;
		    myProp.objLargeImg.onreadystatechange = getLargeImageInfo;
        }
    }
    function getLargeImageInfo()
    {
        if(myProp.objLargeImg.readyState == 'complete')
        {
            myProp.nLargeWidth = myProp.objLargeImg.width;
            myProp.nLargeHeight = myProp.objLargeImg.height;
//alert( myProp.nMiddleWidth + ', ' + myProp.nMiddleHeight + ' /// ' +  myProp.nLargeWidth + ', ' +myProp.nLargeHeight );
//    		delete myProp.objMiddleImg;
//    		delete myProp.objLargeImg;
    		
    		makeImageViewer();
/*
            var strUrl = 'ImageViewer.aspx?curpage=' + myProp.nCurImagePage + '&imgpath=' + myProp.strImagePath + '&endpage=' + myProp.nEndImagePage;
            strUrl += '&mw=' + myProp.nMiddleWidth + '&mh=' + myProp.nMiddleHeight + '&lw=' + myProp.nLargeWidth + '&lh=' + myProp.nLargeHeight;
            myProp.popImageViewer.location.href = strUrl;
*/
        }
    }
    
    function makeImageViewer()
    {
//		var popImageViewer = window.open('','popImageViewer','width=1024,height=768,left=0,top=0,titlebar=no');
    	var	strDoc = '<html>\n<head>\n<title>한국불교문화종합시스템 원문 뷰어</title>\n';

		strDoc += '<STYLE>\n';
		strDoc += 'A:link {font-size:12;COLOR: white; TEXT-DECORATION: none}\n';
		strDoc += 'A:visited { font-size:12;COLOR: white; TEXT-DECORATION: none}\n';
		strDoc += 'A:active { font-size:12;COLOR: white; TEXT-DECORATION: none}\n';
		strDoc += 'A:hover { font-size:12;COLOR: white; TEXT-DECORATION: none}\n';


		strDoc += '.ebook {\n';
		strDoc += '	font-family: "돋움", "굴림";\n';
		strDoc += '	font-size: 12px;\n';
		strDoc += '	color: #333333;\n';
		strDoc += '}\n';
		strDoc += '.keyin {\n';
		strDoc += '	font-family: "돋움", "굴림";\n';
		strDoc += '	font-size: 11px;\n';
		strDoc += '	color: #666666;\n';
		strDoc += '}\n';
		strDoc += '</STYLE>\n';
		strDoc += '<META HTTP-EQUIV="imagetoolbar" CONTENT="no">\n';
		strDoc += '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">\n';
		strDoc += '<META HTTP-EQUIV="expires" CONTENT="-1">\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/module_function.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/class.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/module_variables.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/create_toolbar_area.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/create_middle_area.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/create_buffer_area.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/events.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/pagemove_function.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/enlarge_function.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/shrink_function.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/Content.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/start.js"></SCRIPT>\n';

        strDoc += '<script language="javascript">\n';
        strDoc += '<!--\n';
        strDoc += ' function Initialize() {\n';
		strDoc += '	    InitAction("불교전서", ' + myProp.nCurImagePage + ', "' + myProp.strImagePath + '", ' + myProp.nEndImagePage + ', ' + myProp.nMiddleWidth + ', ' + myProp.nMiddleHeight + ', ' + myProp.nLargeWidth + ', ' + myProp.nLargeHeight + ');\n';
		strDoc += '	    Timer.GoPageTime = 30;\n';
        strDoc += '}\n';
        strDoc += '//-->\n';
        strDoc += '</script>\n';

	    strDoc += '</head>\n';

	    strDoc += '<body style="margin:5 0 0 5;" onload="Initialize();">\n';
	    strDoc += '</body></html>';

        myProp.popImageViewer.document.open( "text/html", "replace" );
	    myProp.popImageViewer.document.write( strDoc );
	
    	myProp.popImageViewer.document.close();

        myProp.popImageViewer.focus();
//        myProp.popImageViewer.location.reload();
    	return;
    }
    
    function showImageViewer(curid,maxid){
        myProp.nMiddleWidth = "0";
        myProp.nMiddleHeight = "0";
        myProp.nLargeWidth = "0";
        myProp.nLargeHeight = "0";
    
        myProp.strImagePath = curid.substring(0, 8) + "I" + curid.substring(9, curid.length-5); //페이지 ID로 이미지경로 ID 얻음.
        var nPos = curid.lastIndexOf("_");
        myProp.nCurImagePage = parseInt(curid.substring(nPos+1, curid.length), 10);
        myProp.nEndImagePage = parseInt(maxid.substring(nPos+1, maxid.length), 10);
        
		myProp.strMiddleUrl = 'img_content/bj/small/' + myProp.strImagePath + '/';
		myProp.strLargeUrl = 'img_content/bj/large/' + myProp.strImagePath + '/';
		var strTempImage = myProp.strMiddleUrl + myProp.strImagePath + "_0003.jpg";

        var strUrl = 'ImageViewer.aspx?curpage=' + myProp.nCurImagePage + '&imgpath=' + myProp.strImagePath + '&endpage=' + myProp.nEndImagePage;
		myProp.popImageViewer = window.open('','popImageViewer','width=1024,height=768,left=0,top=0,titlebar=no,status=no');
        myProp.popImageViewer.focus();
//return;
//		myProp.objMiddleImg = new Image();
		myProp.objMiddleImg.src = strTempImage;
		myProp.objMiddleImg.onreadystatechange = getMiddleImageInfo;
        
//		myProp.objLargeImg = new Image();
//		strTempImage = myProp.strLargeUrl + myProp.strImagePath + "_0003.jpg";
//		myProp.objLargeImg.src = strTempImage;
//		myProp.objLargeImg.onreadystatechange = getLargeImageInfo;

//alert( myProp.nMiddleWidth + ', ' + myProp.nMiddleHeight + ' /// ' +  myProp.nLargeWidth + ', ' +myProp.nLargeHeight );
/*		var popImageViewer = window.open('','popImageViewer','width=1024,height=768,left=0,top=0,titlebar=no');
    	
    	var	strDoc = '<html>\n<head>\n<title>한국불교문화종합정보서비스 원문 뷰어</title>\n';

		strDoc += '<STYLE>\n';
		strDoc += 'A:link {font-size:12;COLOR: white; TEXT-DECORATION: none}\n';
		strDoc += 'A:visited { font-size:12;COLOR: white; TEXT-DECORATION: none}\n';
		strDoc += 'A:active { font-size:12;COLOR: white; TEXT-DECORATION: none}\n';
		strDoc += 'A:hover { font-size:12;COLOR: white; TEXT-DECORATION: none}\n';


		strDoc += '.ebook {\n';
		strDoc += '	font-family: "돋움", "굴림";\n';
		strDoc += '	font-size: 12px;\n';
		strDoc += '	color: #333333;\n';
		strDoc += '}\n';
		strDoc += '.keyin {\n';
		strDoc += '	font-family: "돋움", "굴림";\n';
		strDoc += '	font-size: 11px;\n';
		strDoc += '	color: #666666;\n';
		strDoc += '}\n';
		strDoc += '</STYLE>\n';
		strDoc += '<META HTTP-EQUIV="imagetoolbar" CONTENT="no">\n';
		strDoc += '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">\n';
		strDoc += '<META HTTP-EQUIV="expires" CONTENT="-1">\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/module_function.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/class.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/module_variables.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/create_toolbar_area.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/create_middle_area.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/create_buffer_area.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/events.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/pagemove_function.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/enlarge_function.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/shrink_function.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="Jscript.Encode" SRC="ImageViewer/Content.js"></SCRIPT>\n';
		strDoc += '<SCRIPT LANGUAGE="javascript" SRC="ImageViewer/start.js"></SCRIPT>\n';

	    strDoc += '</head>\n';

	    strDoc += '<body style="margin:5 0 0 5;">\n';
		strDoc += '<SCRIPT LANGUAGE="javascript">\n';
		strDoc += '	InitAction("불교전서", ' + nCurPage + ', "' + myProp.strImagePath + '", ' + nEndPage + ');\n';
		strDoc += '	Timer.GoPageTime = 0;\n';
		strDoc += '</SCRIPT>\n';
	    strDoc += '</body></html>';

	    var	oImgViewDoc = popImageViewer.document.open( "text/html", "replace" );
	    oImgViewDoc.write( strDoc );
	
    	oImgViewDoc.close();
        popImageViewer.focus();
        popImageViewer.location.reload();    
*/    }

    function createBookmark(){
        if(myProp.UserId==''){
            alert('로그인을 하셔야 책갈피를 하실 수 있습니다.');
            return;
        }
        var url='Ajax.aspx';
        var datatype ;
        
        if(myProp.DataType=='bj'){
            datatype="1";
        }else{
            datatype="2";
        }
        
        data='userid=' + myProp.UserId + '&datatype=' + datatype + '&seojiid=' + myProp.SeojiId + '&pageid=' + myProp.PageId + '&type=2';
        
        //data='userid=abraham&datatype=2&seojiid=DGUL_HD_T_0174_003&pageid=DGUL_HD_T_0174_004_004&type=2';
        
        sendRequest(on_createBookmark, data,'GET',url,true,true);
    }
    
    function on_createBookmark(oj){
        var res=decodeURIComponent(oj.responseText);
        
        if(res=='SUCCESS'){
            alert('책갈피가 등록되었습니다.');
        }else{
            alert('책갈피 등록이 실패하였습니다.');
        }
    }
    
    // 불교전서에서 불교사전 링크
    function on_GetBSDicData(oj)
    {
        if( oj.responseText == null )
            return;
        if( oj.responseText == '' )
            return;
        
        var strBSDic = oj.responseText;
	    var objBSDic = $("bsView");
	    if( objBSDic == null )
    	    return;
    	objBSDic.innerHTML = "";

//	    var objBody = document.all.body;
	    objBSDic.removeNode(true);
	    objBSDic = document.createElement('div');

	    objBSDic.setAttribute('id', 'bsView');
	    objBSDic.style.visibility = "hidden";
	    objBSDic.style.position = "absolute";
	    document.body.appendChild( objBSDic );
    	
        var strHtml="";
        
        strHtml  = "<table width='300' border='0' cellspacing='0' cellpadding='0'>\n";
        strHtml += "<tr><td width='3' height='3'><img src='image/cha/bs_table_01.gif' width='3' height='3'></td>\n";
        strHtml += "<td background='image/cha/bs_table_02.gif'></td>\n";
        strHtml += "<td width='3' height='3'><img src='image/cha/bs_table_03.gif' width='3' height='3'></td></tr>\n";

        strHtml += "<tr><td width='3' background='image/cha/bs_table_04.gif'></td>\n";
        strHtml += "<td background='image/cha/bs_table_05.gif' align='right' style='padding: 0px 2px 0px 0px'><img width='21' src='image/cha/close.gif' style='cursor:hand;' onclick='$(\"bsView\").style.visibility = \"hidden\";'/></td>\n";
        strHtml += "<td width='3' background='image/cha/bs_table_06.gif'></td></tr>\n";

        strHtml += "<tr><td width='3' background='image/cha/bs_table_04.gif'></td>\n";
        strHtml += "<td background='image/cha/bs_table_05.gif'  style='padding: 0px 10px 10px 10px' class='bs_dic'>" + strBSDic + "</td>\n";
        strHtml += "<td width='3' background='image/cha/bs_table_06.gif'></td></tr>\n";
        strHtml += "<tr><td width='3' height='3'><img src='image/cha/bs_table_07.gif' width='3' height='3'></td>\n";
        strHtml += "<td background='image/cha/bs_table_08.gif'></td>\n";
        strHtml += "<td width='3' height='3'><img src='image/cha/bs_table_09.gif' width='3' height='3'></td></tr></table>";
//        objBSDic.style.left = myProp.bj2bsClickX + 5;
//	    objBSDic.style.top = myProp.bj2bsClickY + 5;
	    objBSDic.style.zIndex = 5;
    	
    	objBSDic.style.zIndex = 10;
	    objBSDic.innerHTML = strHtml;
	    
	    bsView_SetSize();
	    objBSDic.style.visibility = "visible";
//	    alert( $(pageArea).offsetLeft + ", " + $(pageArea).offsetTop );
//	    alert( "x:" + objBSDic.offsetLeft + ", y:" + objBSDic.offsetTop + ", w:" + objBSDic.clientWidth + ", h:" + objBSDic.clientHeight );
    }
    
    function bsView_SetSize()
    {
	    var objBSDic = $("bsView");
	    var objL = myProp.bj2bsClickX + 5;
	    var objT = myProp.bj2bsClickY + 5;
	    var objR = objL + objBSDic.clientWidth;
	    var objB = objT + objBSDic.clientHeight;
	    
	    var objPW = $("pageArea").clientWidth;
	    var objPH = $("pageArea").clientHeight;
	    var objPL = $("pageArea").offsetLeft;
	    var objPT = $("pageArea").offsetTop;
	    var objPR = objPL + objPW;
	    var objPB = objPT + objPH;
	    
//	    if( objR <= objPR && objB > objPB )
	    if( objB > objPB )
	    {
	        if( objBSDic.clientHeight < objPH )
	        {
	            objT = objPT + (objPH-objBSDic.clientHeight);
	            objB = objT + objBSDic.clientHeight;
	        }
	        else
	        {
	            objT = objPT + 10;
	            objB = objT + (objPH - 10);
//	            objBSDic.style.height = objPH - 10;
	            objBSDic.style.overflowY = "auto";
	        }
	    }
	    
//	    if( objR > objPR && objB <= objPB )
	    if( objR > objPR )
	    {
	        if( objBSDic.clientWidth < objPW )
	        {
	            objL = objPL + (objPW-objBSDic.clientWidth);
	            objR = objL + objBSDic.clientWidth;
	        }
	        else
	        {
	            objL = objPL + 10;
	            objR = objL + (objPW - 10);
//	            objBSDic.style.width = objPW - 10;
	            objBSDic.style.overflowX = "auto";
	        }
	    }
	    
	    objBSDic.style.left = objL;
	    objBSDic.style.top = objT;
	    objBSDic.style.width = objR-objL;
	    objBSDic.style.height = objB-objT;
    }
    
    function ds_search(dic_word){
 	    var url;
	    var userid;
	    var data;	
        
        myProp.bj2bsClickX = event.x;
        myProp.bj2bsClickY = event.y;
        
	    url="Ajax.aspx";
	    data='type=10&bj2bs=' + encodeURIComponent(dic_word);
	    sendRequest(on_GetBSDicData, data,'POST',url,true,true);
	    
    /*
        var url;
        
        url='bs_detail.aspx?srch=' + encodeURIComponent(data);        
        MM_openBrWindow(url,'','status=yes,width=872,height=627');
    */
    }
    
    function bs_LinkID(strDicID)
    {
 	    var url;
	    var userid;
	    var data;	
        
	    url="Ajax.aspx";
	    data='type=11&bsLinkID=' + strDicID;
	    sendRequest(on_GetBSDicData, data,'POST',url,true,true);
    }
        
    
    function ResetPageMove(){
        $('move_first').href="#";
        $('move_prev').href="#";
        $('move_next').href="#";
        $('move_last').href="#";
    }
    
    function ResetImageViewer(){
        if($('imageViewer')!=null){
            $('imageViewer').href="#";
        }
    }
    
    function ResetHeje(){
        if($('heje')!=null){
            $('heje').href="#";
        }
    }
    
    function ResetPageInfo(){
        if($('page_info')!=null){
            $('page_info').innerText="";
        }
    }
    
    function ResetEbook(){
        if($('e_book')!=null){
            $('e_book').href="#";
        }
    }
    
    function ResetZoom(btrue){
        if($('zoomin')!=null){
            if(btrue){
                $('zoomin').href="javascript:zoomIn();";
            }else{
                $('zoomin').href="#";
            }
        }
        if($('zoomout')!=null){
            if(btrue){
                $('zoomout').href="javascript:zoomOut();";
            }else{
                $('zoomin').href="#";
            }
        }
    }
    
    function ResetPageMode(btrue){
       if($('one')!=null){
            if(btrue){
                $('one').href="javascript:setPageMode('one');";
            }else{
                $('one').href="#";
            }
        }
       if($('two')!=null){
            if(btrue){
                $('two').href="javascript:setPageMode('two');";
            }else{
                $('two').href="#";
            }
        }
       if($('comp')!=null){
            if(btrue){
                $('comp').href="javascript:setPageMode('comp');";
            }else{
                $('comp').href="#";
            }
        }
    }  
    
    function ResetDirMode(btrue){
        if($('horz')!=null){
            if(btrue){
                $('horz').href="javascript:setDirMode('horz');";
            }else{
                $('horz').href="#";
            }
        }
        if($('vert')!=null){
            if(btrue){
                $('vert').href="javascript:setDirMode('vert');";
            }else{
                $('vert').href="#";
            }
        }
    }  
 
    function ResetBookmark(btrue){
        if($('bookmark')!=null){
            if(btrue){
                $('bookmark').href="javascript:createBookmark();";
            }else{
                $('bookmark').href="#";
            }
        }
    }
    
    
    
//     function PaveMoveVisible(btrue){
//        $('imgMoveFirst').style.visibility=btrue;
//        $('imgMovePrev').style.visibility=btrue;
//        $('imgMoveNext').style.visibility=btrue;
//        $('imgMoveLast').style.visibility=btrue;
//    }
//    
//    function ImageViewerVisible(btrue){
//        if($('imgImageViewer')!=null){
//            $('imgImageViewer').style.visibility=btrue;
//        }
//    }
//    
//    function HejeVisible(btrue){
//        if($('imgHeje')!=null){
//            $('imgHeje').style.visibility=btrue;
//        }
//    }
//    
//    function PageInfoVisible(btrue){
//        if($('page_info')!=null){
//            $('page_info').style.visibility=btrue;
//        }
//    }
//    
//    function EbookVisible(btrue){
//        if($('imgEbook')!=null){
//            $('imgEbook').style.visibility=btrue;
//        }
//    }
//    
//    function ZoomVisible(btrue){
//        if($('imgZoomIn')!=null){
//            $('imgZoomIn').style.visibility=btrue;
//        }
//        if($('imgZoomOut')!=null){
//            $('imgZoomOut').style.visibility=btrue;
//        }
//    }
//    
//    function PageModeVisible(btrue){
//       if($('imgOne')!=null){
//             $('imgOne').style.visibility=btrue;;
//        }
//       if($('imgTwo')!=null){
//            $('imgTwo').style.visibility=btrue;
//        }
//       if($('imgComp')!=null){
//            $('imgComp').style.visibility=btrue;
//       }
//    }  
//    
//    function DirModeVisible(btrue){
//        if($('imgHorz')!=null){
//            $('imgHorz').style.visibility=btrue;
//        }
//        if($('imgVert')!=null){
//            $('imgVert').style.visibility=btrue;
//        }
//    }  
// 
//    function BookmarkVisible(btrue){
//        if($('imgBookMark')!=null){
//            $('imgBookMark').style.visibility=btrue;
//        }
//    }
//    
//    function setInitVisible(){
//        PaveMoveVisible('hidden');
//        ImageViewerVisible('hidden');
//        HejeVisible('hidden');
//        EbookVisible('hidden');
//        ZoomVisible('hidden');
//        PageModeVisible('hidden');
//        DirModeVisible('hidden');
//        PageInfoVisible('hidden');
//    }
    
    function ResetByLevel(strLevel){
        if(strLevel=='1'){
            ResetPageMove();
            ResetImageViewer();
            ResetHeje();
            ResetPageInfo();
            ResetEbook();
            ResetZoom(false);
            ResetPageMode(false);
            ResetDirMode(false);
            ResetBookmark(false);            
        }else if(strLevel=='2'){
            ResetPageMove();
            ResetImageViewer();
            ResetHeje();
            ResetPageInfo();
            ResetEbook();
            ResetZoom(true);
            ResetPageMode(false);
            ResetDirMode(false);
            ResetBookmark(false);            
        }else{
            ResetPageMove();
            ResetImageViewer();
            ResetHeje();
            ResetPageInfo();
            ResetEbook();
            ResetZoom(true);
            ResetPageMode(true);
            ResetDirMode(true);
            ResetBookmark(true);            
        }
    }