﻿/*사용
function ctl_popup() {
           var p = new PopupObject('popup081008', '/popup/popup081008.html', 500, 730);
           if(p != null) {
                     p.top = 10;
                     p.left = 10;
                     Popup_RegisterPopup(p);
           }
           Popup_ShowPopup();
}
*/


// 팝업창 관리 관련
var POPUP_REGISTRY = null;                              // 등록된 팝업 객체 배열
function Popup_RegisterPopup(popupObject)
{
           if (POPUP_REGISTRY == null)
                     POPUP_REGISTRY = new Array();
           if (popupObject != null)
                     POPUP_REGISTRY[POPUP_REGISTRY.length] = popupObject;
}
function Popup_ShowPopup()
{
           if (POPUP_REGISTRY != null)
           {
                     for (var i = 0; i < POPUP_REGISTRY.length; i++)
                     {
                                if (POPUP_REGISTRY[i] != null)
                                          POPUP_REGISTRY[i].show();
                     }
           }
}
function PopupObject(name, url, width, height)
{
           this.name          = (name == null)? "popup": name;
           this.url  = (url == null)? "about:blank": url;
           this.width         = (width == null)? 300: width;
           this.height        = (height == null)? 400: height;
           this.top = null;
           this.left  = null;
           this.scroll          = null;
           this.resize         = null;
           this.showFrom    = null;
           this.showTo                  = null;

           this.open = PopupObject_Open;
           this.show = PopupObject_Show;
}
function PopupObject_Open()
{
           var feature = "width=" + this.width;
           feature += ",height=" + this.height;
           if (this.top != null)
                     feature += ",top=" + this.top;
           if (this.left != null)
                     feature += ",left=" + this.left;
           if (this.scroll != null)
                     feature += ",scrollbars=" + this.scroll;
           if (this.resize != null)
                     feature += ",resizable=" + this.resize;
           return window.open(this.url, this.name, feature);
}
function PopupObject_Show()
{
           // 게시 기간이 설정되었다면
           if (this.showFrom != null && this.showTo != null)
           {
                     var now = new Date();
                     if (this.showFrom.valueOf() > now.valueOf() || this.showTo.valueOf() < now.valueOf())
                                return false;
           }

           // 쿠키가 설정되었다면
           if (GetCookie(this.name) == 'nothanks')
                     return false;

           return this.open();
}

// 쿠키 관련
var COOKIE = null;                                                   // 분석된 쿠키 배열
function GetCookie(cookie_name)
{
           if (COOKIE == null)
           {
                     COOKIE = new Array();
                     var s = String(document.cookie);
                     var a = s.split(/\s*;\s*/);
                     for (i = 0; i < a.length; i++)
                     {
                                var b = a[i].split(/\s*=\s*/);
                                if (b[1] != null && b[1] != "")
                                          COOKIE[b[0]] = unescape(b[1]);
                     }
           }
           return COOKIE[cookie_name];
}
function Popup_SetCookie(name, value, expire_time)
{
           if (expire_time == null)
                     expire_time = 24;           // 1일
           var today = new Date();
           today.setHours(today.getHours() + expire_time);
           document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
}
