﻿document.write('<div id="POPUP_WINDOW" class="x-hidden">');
document.write('<div class="x-window-header" id="POPUP_TITLE" style="text-align:left"></div>');
document.write('<div id="POPUP_CONTENT" style="background-color:White"></div>');
document.write('</div>');

var TnfPopupWin;
var DEFAULT_POPUP_WIDTH = 500;
var DEFAULT_POPUP_HEIGHT = 800;
var DEFAULT_POPUP_MODAL = true;
var DEFAULT_POPUP_RESIZABLE = false;
var DEFAULT_POPUP_SCROLL = true;
var DEFAULT_POPUP_CLOSABLE = true;

function ShowPopup(_url, _title, _width, _height, _modal, _resizable, _scroll, _win_LEFT, _win_TOP, _win_Center) {

    if(_width == undefined) {
        _width = DEFAULT_POPUP_WIDTH;
    }
    if(_height == undefined) {
        _height = DEFAULT_POPUP_HEIGHT;
    }
    if(_modal == undefined) {
        _modal = DEFAULT_POPUP_MODAL;
    }
    if(_resizable == undefined) {
        _resizable = DEFAULT_POPUP_RESIZABLE;
    }
    if(_scroll == undefined) {
        _scroll = DEFAULT_POPUP_SCROLL;
    }
    /*
    if(_closable == undefined) {
        _closable = DEFAULT_POPUP_CLOSABLE;
    }
    */
    var _content = Ext.get('POPUP_CONTENT');

    _content.load({
		url: _url,
		text: '<p style="color:#AAAAAA">Loading...</p>'
	});

	if(!TnfPopupWin){
		TnfPopupWin = new Ext.Window({
		applyTo			: 'POPUP_WINDOW',
		title           : _title,
		modal           : DEFAULT_POPUP_MODAL,
		maskDisabled	: true,
		resizable		: _resizable,
		layout			: 'fit',
		width			: _width,
		height          : _height,
		autoHeight      : false,
		autoScroll		: _scroll,
		closable        : DEFAULT_POPUP_CLOSABLE,
		closeAction		:'hide',
		plain			: true,
		items			: _content
		});	
	    TnfPopupWin.show();
	    if (_win_Center == "Y") {
    	    TnfPopupWin.setPosition(TnfPopupWin.x, (TnfPopupWin.y - (_height /2)) < 0 ? 0 : (TnfPopupWin.y - (_height /2)));
	    } else {
	        TnfPopupWin.setPosition(_win_LEFT, _win_TOP);
	    }
	
	}
	else {
	    TnfPopupWin.setTitle(_title);
	    TnfPopupWin.setSize(_width, _height);
	    //TnfPopupWin.center();
	    TnfPopupWin.show();
	    if (_win_Center == "Y") {
    	    TnfPopupWin.setPosition(TnfPopupWin.x, (TnfPopupWin.y - (_height /2)) < 0 ? 0 : (TnfPopupWin.y - (_height /2)));
	    } else {
	        TnfPopupWin.setPosition(_win_LEFT, _win_TOP);
	    }
	}
}

function ShowDefaultPopup() {
    //try {
        var TmpArr = _MainPopup.reverse();
        var left = 0;
        
        for(i = 0; i < TmpArr.length; i++) {
            var PopObj = TmpArr[i];
            if (i == 0) {
                left = PopObj.Left;
            }
			//alert(getCookie("yulchon01"));
            if(getCookie("yulchon01") != "yulchon01_cookie") {
                if (PopObj.center == "Y"){
                window.open("/popup.asp?CD="+ PopObj.IDX , "yulchon"+i, "width="+PopObj.Width+",height="+PopObj.Height+",toolbar=no,location=no,status=yes,menubar=no,scrollbars="+PopObj.Scroll+",resizable=no,left="+(document.body.clientWidth - PopObj.Width) / 2+",top="+(document.body.clientHeight - PopObj.Height) / 2);
                } else {
                window.open("/popup.asp?CD="+ PopObj.IDX , "yulchon"+i, "width="+PopObj.Width+",height="+PopObj.Height+",toolbar=no,location=no,status=yes,menubar=no,scrollbars="+PopObj.Scroll+",resizable=no,left="+left+",top="+ PopObj.Top);
                }
                left += PopObj.Width + 10;
            }
        }
    //} catch(e) {}
}

function setCookie(strName, strValue) {
    var objExpireDate = new Date();

	objExpireDate.setDate(objExpireDate.getDate() + (24 * 60 * 60 * 1000)); 
	
	document.cookie = strName + "=" + escape(strValue) + "; path=/; expires=" + objExpireDate.toGMTString() + ";";
}

function delCookie(strName) {
    var objExpireDate = new Date();

	objExpireDate.setDate(objExpireDate.getDate() - 1);
	
	document.cookie = strName + "=;expires=" + objExpireDate.toGMTString();
}

function getCookie(strName) {
    var strCookieName = strName + "=";
	var objCookie = document.cookie;
	
	if (objCookie.length > 0) 
	{
		var nBegin = objCookie.indexOf(strCookieName);
		
		if (nBegin < 0) 
		{
			return;
		}

		nBegin += strCookieName.length;
		
		var nEnd = objCookie.indexOf(";", nBegin);
		
		if (nEnd == -1) 
		{
			nEnd = objCookie.length;
		}
	}
	//alert(objCookie.substring(nBegin, nEnd));
	
	return unescape(objCookie.substring(nBegin, nEnd));
}