var COOKIE_NAME = "WETAXPOPUP";

function initPopup() {
    var popwin = null;
    var docList = document.getElementsByName("popdoc");
    var popseqList = document.getElementsByName("popseq");;
    var popdialogList = document.getElementsByName("popdialog");;
    var poptitleList = document.getElementsByName("poptitle");
    var popSizeList = document.getElementsByName("popSize");
    var popdivList = document.getElementsByName("popdiv");
    
    var features = ",location=no,toolbar=no,resizable=no,status=no,titlebar=no,menubar=no";
    var docObj = null;
    
    var popseq = 0;
    var title = "";
    var isDialog = false;
    var popSize = "";
    var popdiv = "01";
    
    var isPopup = "";
    for(var i = 0; i < docList.length; i++) {
        popseq = popseqList[i].value;
        isPopup = getCookie(COOKIE_NAME + popseq);
        if(isPopup == "Y") continue;
        
        docObj = docList[i];
        title = poptitleList[i].value;
        isDialog = (popdialogList[i].value == "Y");
        popdiv = popdivList[i].value;
        if(popdiv != "99") {        
            popSize = (popSizeList[i].value == "") ? "width=335,height=300" : popSizeList[i].value;
        } else {
            popSize = popSizeList[i].value;
        }
        features = popSize + features;

        switch (popdiv) {
            case '01' :
                popwin = openPopupNormal(popseq, features, title, docObj);
                break;
            case '02' :
                popwin = openPopupError(popseq, features, title, docObj);
                break;
            case '03' :
                popwin = openPopupEtc(popseq, features, title, docObj);
                break;
            case '99' :
                popwin = openPopupFile(popseq, features, docObj);
                break;
            default :
                popwin = openPopupNormal(popseq, features, title, docObj);
                break;
               
        }

    }
}


/*¼³ ¸í : 1. ±ÇÁ¤ÈÆ
		2. 2008/05/15 Ãß°¡
		3. ÆË¾÷ Á¾·á ½Ã  ¿ÀÇÁ³Ê°¡ º¯°æ µÇ°Å³ª Å¬·ÎÁî µÆÀ» °æ¿ì ¿¹¿ÜÃ³¸®
*/
function closePopupWin() {
	try{
		opener.closePopup(popseq, top.window);
	}catch(e){
		self.close();
	}
}

function openPopupNormal(popseq, features, title, docObj) {

	//Æ÷¿öµù ÆäÀÌÁö·Î ³Ñ¾î°¡±âÀü ¸ÞÀÎÀ» °ÅÃ³°¥½Ã¿¡ ÆË¾÷À» ¶ç¿ìÁö ¾Ê´Â´Ù.
	if(fwCMD != null && fwCMD != "" && fwCMD != undefined)
		return false;

	if(popseq == "89" && bpesNtfYn == "Y")	//·Î±×ÀÎ ÈÄ ÀüÀÚ°íÁö½ÅÃ»ÀÚÀÏ °æ¿ì ÆË¾÷ ¼û±è
		return false;

	if(popseq == "118" && LINK_PARAM_VALUE == "LPTIFB0R0")	//ÀÌº¥Æ® ÆË¾÷ ¿ÜºÎ¸µÅ©¸¦ ÅëÇØ Á¢»ö ÇßÀ» °æ¿ì ¼û±è
		return false;

	if(popseq == "145" && usrDiv !="21")	//·Î±×ÀÎ ÈÄ ¹ýÀÎÁß¿¡ ´ëÇ¥¹ýÀÎ ¼³Á¤ÀÌnullÀÎ »ç¶÷¸¸ 
		return false;
		
	if(popseq == "145" && checkCnt != "1")	//¹ýÀÎÁß Ã¶È¸ÇÑ »ç¶÷¸¸ ÆË¾÷ ¶ç¿ì±â
		return false;
	
	if(popseq == "119" && logon == false)	//È¸¿øÁ¤º¸°øÀ¯ ÆË¾÷ Á¦¾î - ºñ·Î±×ÀÎ½Ã ºñÈ°¼ºÈ­
		return false;
		
	if(popseq == "119" && logon == true && (shareSido == 99 || shareSido == 26 || shareSido == 28 || shareSido == 31))	//È¸¿øÁ¤º¸°øÀ¯ ÆË¾÷ Á¦¾î - µ¿ÀÇÇÏÁö ¾Ê°Å³ª ÀÌ¹Ì °øÀ¯µÈ È¸¿ø Á¦¿Ü
		return false;
		
	if(popseq == "119" && logon == true && !(sidoCod == 26 || sidoCod == 28 || sidoCod == 31))	//È¸¿øÁ¤º¸°øÀ¯ ÆË¾÷ Á¦¾î - ½Ãµµ ÄÚµå°¡ ÀÌÅÃ½º °øÀ¯Áö¿ª ¾Æ´Ò °æ¿ì ºñÈ°¼º
		return false;
	
    var popwin = null;
    popwin = window.open("", COOKIE_NAME + popseq, features);
    popwin.document.open();

    popwin.document.write("<html>");
    popwin.document.write("<head>");
    popwin.document.write("<title>" + title + "</title>");
    popwin.document.write("<meta http-equiv='Content-Type' content='text/html;charset=euc-kr'>");
    popwin.document.write("<meta http-equiv='X-UA-Compatible' content='IE=EmulateIE7'>");    
    popwin.document.write("<link href='/css/popup.css' rel='stylesheet' type='text/css'>");
    popwin.document.write("<script type='text/javascript'>");
    popwin.document.write("function closePopupWin(){");
    popwin.document.write("try{ opener.closePopup(" + popseq + ", top.window); }");
    popwin.document.write("catch(e){ self.close(); }}");
    popwin.document.write("</script>");
    popwin.document.write("</head>");
    popwin.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' onLoad='opener.changeSize(top.window);'>");
    popwin.document.write("<div id='content'>");
    popwin.document.write("<center>");
    popwin.document.write(docObj.innerHTML);
    popwin.document.write("</center>");
    popwin.document.write("</div>");
    popwin.document.write("<div align='right' style='padding-right:20;'>");
    popwin.document.write("<table border='0' cellspacing='0' cellpadding='0'>");
    popwin.document.write("<tr>");
    popwin.document.write("<td>");
    //popwin.document.write("<input type='checkbox' id='rememberClose' onClick='opener.closePopup(" + popseq + ", top.window);'>");
    popwin.document.write("<input type='checkbox' id='rememberClose' onClick='closePopupWin();'>");
    popwin.document.write("<span class='text'>ÇÏ·çµ¿¾È ÀÌÃ¢À» ¿­Áö ¾ÊÀ½</span>");
    popwin.document.write("&nbsp;&nbsp;&nbsp;");
    //popwin.document.write("<img src='/image/popup/common/bt_close.gif' width='68' height='17' align='absmiddle' style='cursor:hand;' onClick='opener.closePopup(" + popseq + ", top.window);'>");
    popwin.document.write("<img src='/image/popup/common/bt_close.gif' width='68' height='17' align='absmiddle' style='cursor:hand;' onClick='closePopupWin();'>");
    popwin.document.write("</td>");
    popwin.document.write("</tr>");
    popwin.document.write("</table>");
    popwin.document.write("</div>");
    popwin.document.write("</body>");
    popwin.document.write("</html>");

    popwin.document.close();
    popwin.focus();
    return popwin;
}

function openPopupError(popseq, features, title, docObj) {
    var popwin = null;
    popwin = window.open("", COOKIE_NAME + popseq, features);
    popwin.document.open();

    popwin.document.write("<html>");
    popwin.document.write("<head>");
    popwin.document.write("<title>" + title + "</title>");
    popwin.document.write("<meta http-equiv='Content-Type' content='text/html;charset=euc-kr'>");
    popwin.document.write("<meta http-equiv=X-UA-Compatible' content='IE=EmulateIE7'>");
    popwin.document.write("<link href='/css/popup.css' rel='stylesheet' type='text/css'>");
    popwin.document.write("<script type='text/javascript'>");
    popwin.document.write("function closePopupWin(){");
    popwin.document.write("try{ opener.closePopup(" + popseq + ", top.window); }");
    popwin.document.write("catch(e){ self.close(); }}");
    popwin.document.write("</script>");
    popwin.document.write("</head>");
    popwin.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' onLoad='opener.changeSize(top.window);'>");
    popwin.document.write("<div id='content'>");
    popwin.document.write("<center>");
    popwin.document.write(docObj.innerHTML);
    popwin.document.write("</center>");
    popwin.document.write("</div>");
    popwin.document.write("<div align='right' style='padding-right:20;'>");
    popwin.document.write("<table border='0' cellspacing='0' cellpadding='0'>");
    popwin.document.write("<tr>");
    popwin.document.write("<td>");
    //popwin.document.write("<input type='checkbox' id='rememberClose' onClick='opener.closePopup(" + popseq + ", top.window);'>");
    popwin.document.write("<input type='checkbox' id='rememberClose' onClick='closePopupWin();'>");
    popwin.document.write("<span class='text'>ÇÏ·çµ¿¾È ÀÌÃ¢À» ¿­Áö ¾ÊÀ½</span>");
    popwin.document.write("&nbsp;&nbsp;&nbsp;");
    //popwin.document.write("<img src='/image/popup/common/bt_close.gif' width='68' height='17' align='absmiddle' style='cursor:hand;' onClick='opener.closePopup(" + popseq + ", top.window);'>");
    popwin.document.write("<img src='/image/popup/common/bt_close.gif' width='68' height='17' align='absmiddle' style='cursor:hand;' onClick='closePopupWin();'>");
    popwin.document.write("</td>");
    popwin.document.write("</tr>");
    popwin.document.write("</table>");
    popwin.document.write("</div>");
    popwin.document.write("</body>");
    popwin.document.write("</html>");

    popwin.document.close();
    popwin.focus();
    return popwin;
}

function openPopupEtc(popseq, features, title, docObj) {
    var popwin = null;
    popwin = window.open("", COOKIE_NAME + popseq, features);
    popwin.document.open();

    popwin.document.write("<html>");
    popwin.document.write("<head>");
    popwin.document.write("<title>" + title + "</title>");
    popwin.document.write("<meta http-equiv='Content-Type' content='text/html;charset=euc-kr'>");
    popwin.document.write("<meta http-equiv=X-UA-Compatible' content='IE=EmulateIE7'>");
    popwin.document.write("<link href='/css/popup.css' rel='stylesheet' type='text/css'>");
    popwin.document.write("<script type='text/javascript'>");
    popwin.document.write("function closePopupWin(){");
    popwin.document.write("try{ opener.closePopup(" + popseq + ", top.window); }");
    popwin.document.write("catch(e){ self.close(); }}");
    popwin.document.write("</script>");
    popwin.document.write("</head>");
    popwin.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' onLoad='opener.changeSize(top.window);'>");
    popwin.document.write("<div id='content'>");
    popwin.document.write("<center>");
    popwin.document.write(docObj.innerHTML);
    popwin.document.write("</center>");
    popwin.document.write("</div>");
    popwin.document.write("<div align='right' style='padding-right:20;'>");
    popwin.document.write("<table border='0' cellspacing='0' cellpadding='0'>");
    popwin.document.write("<tr>");
    popwin.document.write("<td>");
    //popwin.document.write("<input type='checkbox' id='rememberClose' onClick='opener.closePopup(" + popseq + ", top.window);'>");
    popwin.document.write("<input type='checkbox' id='rememberClose' onClick='closePopupWin();'>");
    popwin.document.write("<span class='text'>ÇÏ·çµ¿¾È ÀÌÃ¢À» ¿­Áö ¾ÊÀ½</span>");
    popwin.document.write("&nbsp;&nbsp;&nbsp;");
    //popwin.document.write("<img src='/image/popup/common/bt_close.gif' width='68' height='17' align='absmiddle' style='cursor:hand;' onClick='opener.closePopup(" + popseq + ", top.window);'>");
    popwin.document.write("<img src='/image/popup/common/bt_close.gif' width='68' height='17' align='absmiddle' style='cursor:hand;' onClick='closePopupWin();'>");
    popwin.document.write("</td>");
    popwin.document.write("</tr>");
    popwin.document.write("</table>");
    popwin.document.write("</div>");
    popwin.document.write("</body>");
    popwin.document.write("</html>");

    popwin.document.close();
    popwin.focus();
    return popwin;
}

function openPopupFile(popseq, features, docObj) {
    var popwin = null;
    popwin = window.open(docObj.innerHTML, COOKIE_NAME + popseq, features);
    return popwin;
}

function moveOpenerPage(page) {
    if(page == null || page == '') {
        return false;
    }

    linkForm.page.value = page;
    linkForm.submit();
}

var popupCount = 4;
var popupList = new Array(popupCount);
var sizeList = new Array(popupCount);

popupList[0]  = "/html/popup/2007/0001/popup.html";     // 2007³âµµ Àç»ê¼¼ ÀÌ·¸½À´Ï´Ù
popupList[1]  = "/html/popup/2007/0004/popup.html";     // À§ÅÃ½º °³ÅëÁö¿ª ¹× ÀÎÅÍ³Ý µî±â½ÅÃ» °¡´ÉÁö¿ª ¾È³»
popupList[2]  = "/html/popup/2007/0003/popup.html";     // 8¿ùÀº ±ÕµîÇÒ ÁÖ¹Î¼¼ ³³ºÎÀÇ ´ÞÀÔ´Ï´Ù.
popupList[3] = "/html/popup/2008/0001/popup.html";      // ÀÚµ¿Â÷¼¼ ÀÎÇÏ ¹× ¼¼À²±¸°£ Ãà¼Ò

sizeList[0]  = "width=400,height=649";
sizeList[1]  = "width=433,height=544";
sizeList[2]  = "width=400,height=542";
sizeList[3] = "width=433,height=545";

function openPopup(idx) {
    var param = popupList[idx] + "";

    var features = sizeList[idx] + ",location=no,toolbar=no,resizable=yes,status=no,titlebar=no,menubar=no";
    var winObj = window.open(param, COOKIE_NAME + idx, features);

    return winObj;
}