/**
 * ë¹ íë©´ ì¤í
 */
POPUP_DEFAULT = "/common/web/null.html";
POPUP_DEFAULT_NAME = "";
POPUP_DEFAULT_WIDTH = 300;
POPUP_DEFAULT_HEIGHT = 300;
POPUP_DEFAULT_STYLE = "toolbar=no,status=no,directories=no,scrollbars=no,location=no,resizable=no,border=0,menubar=no";
POPUP_MSG_STYLE = "toolbar=no,status=no,directories=no,scrollbars=yes,location=no,resizable=no,border=0,menubar=no";


// ì¼ë°íìëª¨ë
var mode = "GENERAL";

var childWindow   = new Array;
var childWindowNm = new Array;
var windowCnt     = 0;

var openWindowURL       = POPUP_DEFAULT;
var openWindowName      = POPUP_DEFAULT_NAME;
var openWindowWidth     = POPUP_DEFAULT_WIDTH;
var openWindowHeight    = POPUP_DEFAULT_HEIGHT;
var openWindowStyle     = POPUP_DEFAULT_STYLE;
var openWindowParams    = "";

/**
 * 실제 팝업을 띄우기 전에 이름으로 DB에서 팝업관련 정보들을 불러온다.
 */
 
function openPopup(popupWindowCode, params) {
	//alert("popupWindowCode="+popupWindowCode);
    openWindowParams = params;
    //target frame 생성
    var oIFrame = document.createElement("<iframe name='searchPopupInfoF' src='/common/web/null.html' width='0' height='0' ></iframe>");
    if(!document.all("searchPopupInfoF")){
        document.body.appendChild(oIFrame);
    }
    
    //form 생성
    var searchFormName = "searchPopupInfoForm";
    var oForm = document.createElement("<form name=" + searchFormName + " method=post target=searchPopupInfoF></form>");
    if(!document.forms(searchFormName)){
        document.body.appendChild(oForm);
    }
    
    //element 생성한다. 기존에 있을경우 팝업 이름을 대체한다.
    var oInput = document.createElement("<input type=hidden name=popupName value=" + popupWindowCode + " >");
    if(document.forms(searchFormName).popupName){
        document.forms(searchFormName).popupName.value = popupWindowCode;
    }else{
        document.forms(searchFormName).appendChild(oInput);
    }
    
    //request를 요청한다.
    document.forms(searchFormName).action = "/common31/js/popupInfo.jsp";
    document.forms(searchFormName).submit();
}
 
/**
 * DB에서 불러온 팝업 정보로 Popup 을 띄운다.
 */
function openPopupByRetrievedInfo(objPopupInfo){
    openWindowURL       = objPopupInfo.url;
    openWindowName      = objPopupInfo.popup_name;
    openWindowWidth     = objPopupInfo.width;
    openWindowHeight    = objPopupInfo.height;
    // DB에 팝업 features정보가 없을경우 defalut 정보로 셋팅.
    openWindowStyle     = (objPopupInfo.features?objPopupInfo.features:POPUP_DEFAULT_STYLE);
    
    var openWindowObject;
    var xpos = (screen.availWidth - openWindowWidth)/2;
    var ypos = (screen.availHeight - openWindowHeight)/2;
    //if (openPopup.arguments.length == 2)    // params 값이 있으면
    if(openWindowParams != "")
        openWindowURL = openWindowURL+"?"+openWindowParams;

    if (mode == "MODAL") {
    	//alert(openWindowParams);
        // 모달팝업모드시
        openWindowStyle = "dialogWidth:"+openWindowWidth+"px;dialogHeight:"+openWindowHeight+"px; edge: Sunken; center: Yes; help: No; resizable: No; status: No;"
        openWindowObject = window.showModalDialog(openWindowURL, window , openWindowStyle);
    }
    else {
    	//alert(openWindowParams);
        // 일반팝업모드시
        openWindowStyle = openWindowStyle + ',top='+ ypos +',left='+ xpos +',width=' + openWindowWidth + ',height=' + openWindowHeight;
        var strTmp = "";
        var valuelist    = openWindowURL.split("&");
        for (var i=0; i < valuelist.length; i++ ) {
            strTmp += "|" + valuelist[i];
        }
        openWindowURL = strTmp.substring(1,strTmp.length);
        openWindowObject = window.open("/common/web/null.html", openWindowName, openWindowStyle);
        if (openWindowObject) {
        	
        	if (!document.popup_form) {
				var popupForm = document.createElement("<form name='popup_form' action='/common/js/popupjs.jsp' method='post'>");
				var urlInput = document.createElement("<input type='hidden' name='url'>");
				
				popupForm.appendChild(urlInput);
				document.body.insertBefore(popupForm);
			}
        	popup_form.url.value = openWindowURL;
        	popup_form.target = openWindowName;
        	popup_form.submit();
        }
        
        childWindow[windowCnt] = openWindowObject;
        childWindowNm[windowCnt++] = openWindowName;
        
        openWindowObject.focus();
    }
}

// 모달팝업모드
function openModalPopup(popupWindowCode, params) {
    mode = "MODAL";
    openPopup(popupWindowCode, params);
}

function closePopup(){ // 팝업창(자식창) 닫아주는 부분
	if(childWindow) {
		for(var c=0; c<childWindow.length; c++) {
			if (!childWindow[c].closed && childWindow[c].name==childWindowNm[c])
				childWindow[c].close();
		}
	}
	if (CalView) {
		if (!CalView.closed && CalView.name=="")
			CalView.close();
	}
}

