﻿// prototype.js 필요
var Popup = {
    openPopup: function(popId, pageURL, pTop, pLeft, pWidth, pHeight, scrollbar, layerColor, popupMode) {
        if (this.readCookie('nopopup' + popId) != 'no')
            this['openPopup' + popupMode]('popup' + popId, pageURL, pTop, pLeft, pWidth, pHeight, scrollbar, layerColor);
    },

    //팝업
    openPopupP: function(popId, pageURL, pTop, pLeft, pWidth, pHeight, scrollbar) {
        window.open(pageURL, popId, "top=" + pTop + ",left=" + pLeft + ",width=" + pWidth + ",height=" + pHeight + ",scrollbars=" + scrollbar);
    },

    //레이어
    openPopupL: function(popId, pageURL, pTop, pLeft, pWidth, pHeight, scrollbar, layerColor) {
        if ($(popId)) $(popId).remove();
        else {
            var pLayer = document.createElement('div');
            var pFrame = document.createElement('iframe');
            pLayer.id = popId;
            pFrame.id = popId + 'f';
            pFrame.name = popId + 'f';
            pFrame.src = pageURL;
            pFrame.scrolling = scrollbar;
            pFrame.allowTransparency = 'true';
            pFrame.frameBorder = '0';
            Element.setStyle(pLayer, {
                position: 'absolute',
                top: pTop + 'px',
                left: pLeft + 'px',
                width: pWidth + 'px',
                height: pHeight + 'px',
                overflow: 'hidden',
                //backgroundColor: layerColor, 
                padding: '0px',
                zIndex: '100'
            });
            Element.setStyle(pFrame, {
                margin: '0px',
                width: pWidth - 1 + 'px',
                height: pHeight - 1 + 'px'
            });

            pLayer.appendChild(pFrame);
            $$('body')[0].appendChild(pLayer);
        }
    },

    //색있는레이어
    openPopupD: function(popId, pageURL, pTop, pLeft, pWidth, pHeight, scrollbar, layerColor) {
        if ($(popId)) $(popId).remove();
        else {
            var pLayer = document.createElement('div');
            var pFrame = document.createElement('iframe');
            pLayer.id = popId;
            pFrame.id = popId + 'f';
            pFrame.name = popId + 'f';
            pFrame.src = pageURL;
            pFrame.scrolling = scrollbar;
            pFrame.allowTransparency = 'true';
            pFrame.frameBorder = '0';
            Element.setStyle(pLayer, {
                position: 'absolute',
                top: '0px',
                left: '0px',
                width: '100%',
                height: document.documentElement.scrollHeight + 'px',
                overflow: 'hidden',
                backgroundColor: layerColor,
                filter: 'alpha(opacity=40)',
                '-moz-opacity': '.50',
                opacity: '.40',
                padding: '0px',
                zIndex: '10000'
            });

            Element.setStyle(pFrame, {
                margin: '0 0 0 0',
                width: pWidth + 'px',
                height: pHeight + 'px'

            });

            var pLayer2 = document.createElement('div');
            pLayer2.id = popId + "s";
            Element.setStyle(pLayer2, {
                position: 'absolute',
                top: pTop + 'px',
                left: pLeft + 'px',
                zIndex: '100000'
            });

            pLayer2.appendChild(pFrame);
            $$('body')[0].appendChild(pLayer2);
            $$('body')[0].appendChild(pLayer);
        }
    },

    //레이어 리사이즈
    resizePopup: function(popId, pWidth, pHeight) {
        if ($('popup' + popId)) {
            var pFrame = $('popup' + popId).getElementsByTagName("iframe");
            $('popup' + popId).style.width = pWidth + 'px';
            $('popup' + popId).style.height = pHeight + 'px';
            Element.setStyle(pFrame[0], {
                margin: '0px',
                width: pWidth - 1 + 'px',
                height: pHeight - 1 + 'px'
            });
        }
    },

    closeLayer: function(popId) {
        if ($('popup' + popId)) $('popup' + popId).remove();
    },

    closePopup: function(popId, popupMode) {
        var noOpen = false;
        if ($('noOpen')) noOpen = $('noOpen').checked;
        if (noOpen) this.createCookie('nopopup' + popId, 'no', 1);
        this['closePopup' + popupMode](popId);
    },

    closePopupP: function(popId, noOpen) {
        self.close();
    },

    closePopupL: function(popId) {
        parent.Popup.closeLayer(popId);
    },

    closeLayerD: function(popId) {
        parent.Popup.closeLayer(popId);
        parent.Popup.closeLayer(popId + "s");
    },

    createCookie: function(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            date.setHours(00, 00, 00); //추가: 삭제 시간을 0시로 초기화
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    },

    readCookie: function(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }
}