/** =============================================
Comment: window.open 을 위한 인자들을 받아 화면 중앙에 IE Popup Window를 띄운다. (width, height 속성값을 참조한다)
Return : object (window.open 객체)
Usage  :
--------------------------------------------- **/
function fn_windowOpen(theURL, winName, features, bReturn)
{

    // 모니터화면의 가로.세로 크기
    var iScreenWidth  = screen.width;
    var iScreenHeight = screen.height;

    // 모니터화면 사용가능한 영역의 가로.세로 크기
    var iScreenAvailWidth  = screen.availwidth;
    var iScreenAvailHeight = screen.availheight;

    // 전체 프레임을 감싸고 있는 Expolor창의 가로.세로 크기(테두리나 로케이션바, 메뉴바 등을 제외한 body의 크기임)
    var iParentWindowWidth  = parent.parent.window.document.body.clientWidth;
    var iParentWindowHeight = parent.parent.window.document.body.clientHeight;

    // 전체 프레임을 감싸고 있는 Expolor창의 절대 X.Y좌표(왼쪽.꼭대기) 값(테두리나 로케이션바, 메뉴바 등을 제외한 body의 크기임)
    // scrollLeft: 왼쪽으로부터 scroll된 값(당연히 0)
    // clientLeft: 왼쪽 테두리로부터의 값(테두리의 크기가 2정도 됨, 보통 2)
    // !!!필요한것은 모니터화면으로부터의 절대 X, Y 좌표인데 현재로서는 구할 수가 없다!!! (ㅠ_ㅠ)
    var iParentWindowLeft   = parent.parent.window.document.body.scrollLeft;   //scrollLeft; //clientLeft;
    var iParentWindowTop    = parent.parent.window.document.body.scrollTop;    //scrollTop;  //clientTop;

    // 이 함수를 호출한 영역의 가로.세로 크기
    // (실제로 팝업창의 위치는 content영역의 중간인것이 이상적이라 사료됨.
    //  위의 iParentWindowLeft/iParentWindowTop 만 구할 수 있다면 반영이 가능하나.. 쩝!)
    var iWindowWidth  = window.document.body.clientWidth;
    var iWindowHeight = window.document.body.clientHeight;

    // 이 함수를 호출한 영역의 Expolor창의 상대 X.Y좌표(왼쪽.꼭대기) 값
    var iWindowLeft   = window.document.body.scrollLeft;
    var iWindowTop    = window.document.body.scrollTop;

    var reRegExp = new RegExp("\"", "gi"); // varRegExp = /pattern/flag;

    var iFeaturesWidth  = 0;
    var iFeaturesHeight = 0;
    var iFeaturesLeft   = 0;
    var iFeaturesTop    = 0;

    var sStrTemp = new String("");
    var sFeatures = "";

    var arrayFeatures = features.toLowerCase().split(",");

    for (var ii = 0; ii < arrayFeatures.length; ii++) {
        if (arrayFeatures[ii].indexOf("width") != -1) {
            sFeatures = sFeatures + arrayFeatures[ii];

            reRegExp = new RegExp("\"|=|width", "gi");
            sStrTemp = fn_trim(arrayFeatures[ii]);
            sStrTemp = sStrTemp.replace(reRegExp, "");

            iFeaturesWidth = sStrTemp * 1;
            if (iFeaturesWidth == sStrTemp) {
                iFeaturesLeft   = iParentWindowLeft + ( (/*iParentWindowWidth*/iScreenAvailWidth / 2) - (iFeaturesWidth / 2) );
                if (iFeaturesLeft + iFeaturesWidth > iScreenAvailWidth) {
                    iFeaturesLeft = iScreenAvailWidth - iFeaturesWidth;
                }
                if (iFeaturesLeft < 0) {
                    iFeaturesLeft = 0;
                }
                sFeatures = sFeatures + ", " + "left=" + iFeaturesLeft;
            }
        } else if (arrayFeatures[ii].indexOf("height") != -1) {
            sFeatures = sFeatures + arrayFeatures[ii];

            reRegExp = new RegExp("\"|=|height", "gi");
            sStrTemp = fn_trim(arrayFeatures[ii]);
            sStrTemp = sStrTemp.replace(reRegExp, "");

            iFeaturesHeight = sStrTemp * 1;
            if (iFeaturesHeight == sStrTemp) {
                iFeaturesTop   = iParentWindowTop + ( (/*iParentWindowHeight*/iScreenAvailHeight / 2) - (iFeaturesHeight / 2) );
                if (iFeaturesTop + iFeaturesHeight > iScreenAvailHeight) {
                    iFeaturesTop = iScreenAvailHeight - iFeaturesHeight;
                }
                if (iFeaturesTop < 0) {
                    iFeaturesTop = 0;
                }
                sFeatures = sFeatures + ", " + "top=" + iFeaturesTop;
            }
        } else if (arrayFeatures[ii].indexOf("left") != -1) {
            // 무시
        } else if (arrayFeatures[ii].indexOf("top" ) != -1) {
            // 무시
        } else {
            sFeatures = sFeatures + arrayFeatures[ii];
        }
        if (ii < arrayFeatures.length -1) {
            sFeatures = sFeatures + ", ";
        }
    }

    var win_popup_temp = window.open(theURL, winName, sFeatures);

    if (bReturn) {
        return win_popup_temp;
    }
}

var win_popup_1 = null; 
/** =============================================
Comment: 일반적인 공통 팝업
Return : String (code, desc)
Usage  : onClick="javascript:fn_popup_1("/popup.kto?func_name=zipcodelist2", "frm_search", "zip_code2,full_name2", "aa", "");;"
  zip_code2, full_name2 등은 해당 form에서 유일한 이름이어야 한다.
--------------------------------------------- **/
function fn_popup_1(sAction, sFormName, sResult, sParam, sOption)
{
/*
**선결요건**
해당 부모 Page 의 하단에 아래 코드 추가.
<form name="frm_popup_1" target="">
  <input type="hidden" name="form_name" value="">
  <input type="hidden" name="result" value="">
  <input type="hidden" name="param"  value="">
  <input type="hidden" name="option" value="">
</form>
*/
    if (fn_isNotNullByVal(sFormName) && fn_isNotNullByVal(sResult)) {
        // 필수 인자가 비어있지 않으면.
        if (win_popup_1 != null) { /* && !win_popup_1.closed*/
            // 팝업창이 이미 생성되어있으면 // 포커스만 이동시킨다.
            win_popup_1.focus();
        } else {
            // 팝업창 생성
            win_popup_1 = fn_windowOpen("", "win_popup_1", sOption + ", dependent", true); //

            win_popup_1.focus();

            // 조건 설정후 submit();
            document.frm_popup_1.form_name.value = sFormName;
            document.frm_popup_1.result.value = sResult;
            document.frm_popup_1.param.value  = sParam;
            document.frm_popup_1.option.value = sOption;

            document.frm_popup_1.target = win_popup_1.name;
            document.frm_popup_1.action = sAction;
            document.frm_popup_1.method = "post";

            document.frm_popup_1.submit();
        }
    } else {
        // 필수 인자가 하나라도 비어 있으면
        alert("공통 팝업1(): 자바스크립트 호출 인자 오류!");
    }
}

/** =============================================
Comment: 모달 팝업
Return : String
Usage  : fn_showModal
--------------------------------------------- **/
function fn_showModal(sAction, sFormName, sResult, sParam, sOption) {
    /*----------
		다이얼로그창의 크기를 직접 세팅하는 이유:
		기존에 작성된 소스(팝업사용 페이지)의 변화를 최소화 하고
		다이얼로그 창의 크기 변화 없이 뜨도록 함으로서 시각적
		속도 개선을 위함이다.
		다이얼로그 창이 뜬후에 창의 크기를 조절 하는 경우는
		시각적으로 수행성능이 떨어 지는것처럼 보인다.
	----------*/
	var sWidth;
	var sHeight;
	var iWindowWidth  = 300;
	var iWindowHeight = 300;
	// 새로운 크기의 창 팝이 필요 할시 아래 if문에 else if 로 추가 하세요
	if (sAction.indexOf("popup.kto?func_name=zipcodelist") >= 0) {  // 우편번호 조회
		iWindowWidth  = 400 + (5 * 2);
		iWindowHeight = 540 + (5 * 2 + 19);
	} else {
		// 기본적인 팝업
		iWindowWidth  = 540 + (5 * 2);
		iWindowHeight = 540 + (5 * 2 + 19);
	}

	sWidth  = iWindowWidth  + "px";
	sHeight = iWindowHeight + "px";
	if (sAction.indexOf("?") >= 0){
		sAction = sAction 	+ "&"
							+ "form_name=" + sFormName + "&"
							+ "param="     + sParam    + "&"
							+ "result="    + sResult ;
	} else {
		sAction = sAction	+ "?"
							+ "form_name=" + sFormName + "&"
							+ "param="     + sParam    + "&"
							+ "result="    + sResult ;
	}
	sFeature =  "dialogWidth:" + sWidth
				+ ";dialogHeight:" + sHeight
				+ ";resizable:no;status:no"
				+ ";scroll:no;help:no";
	
	//window.showModalDialog(sAction,window,sFeature);
	
	//클라이언트 브라우저 조사
	var appname = navigator.appName;    
   	if(appname == "Microsoft Internet Explorer"){ appname = "IE"; }
   	if(appname=="IE"){ window.showModalDialog(sAction, window, sFeature); }
    //클라이언트가 리눅스 모질라를 웹 브라우저로 사용하는 경우 
    //리눅스에서는 showModalDialog를 지원하지 않음 
    else { window.open(sAction, "", "width="+sWidth+",height="+sHeight+",resizable=no,status=no,scrollbars=no,modal=yes"); }
	
}