﻿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 = 300;
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, _closable, _autoheight) {
    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;
    }
    
    if(_autoheight == undefined) {
        _autoheight = true;
    }
    
    
    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      : _autoheight,
		autoScroll		: _scroll,
		closable        : _closable,
		closeAction		:'hide',
		plain			: true,
		items			: _content
		});	

	    TnfPopupWin.show();
	    TnfPopupWin.setPosition(TnfPopupWin.x, (TnfPopupWin.y - (_height /2)) < 0 ? 0 : (TnfPopupWin.y - (_height /2)));
	
	}
	else {
	    TnfPopupWin.setTitle(_title);
	    TnfPopupWin.setSize(_width, _height);
	    TnfPopupWin.center();
	    TnfPopupWin.show();
	    TnfPopupWin.setPosition(TnfPopupWin.x, (TnfPopupWin.y - (_height /2)) < 0 ? 0 : (TnfPopupWin.y - (_height /2)));
	}
}

function ShowContact() {
    ShowPopup('/popup/Contact.html','<img src="/image/popup/Contact.png" class="png24"/>', 450, 394);
}

function ShowSitemap() {
    ShowPopup('/popup/Sitemap.html','<img src="/image/popup/sitemap.png" class="png24"/>', 640, 284);
}

function ShowUseAgree() {
    ShowPopup('/popup/UseAgreement.html','<img src="/image/popup/useagree.png" class="png24"/>', 450, 490);
}

function ShowPrivacy() {
    ShowPopup('/popup/Privacy.html','<img src="/image/popup/person.png" class="png24"/>', 450, 480);
}

function ShowDistinct() {
    ShowPopup('/popup/Distinct.html','<img src="/image/popup/dist.png" class="png24"/>', 450, 470);
}

function ShowLogin() {
    ShowPopup('/MessageFrame.aspx?u=' + escape('/Login/Login01.aspx'),'<img src="/image/popup/login.png" class="png24"/>', 438, 250);
}

function ShowIDFind() {
    ShowPopup('/MessageFrame.aspx?u=' + escape('/Login/FindId.aspx'),'<img src="/image/popup/idfind.png" class="png24"/>', 438, 250);
}

function ShowJoin() {
    ShowPopup('/MessageFrame.aspx?u=' + escape('/Join/Join01.aspx') + '&w=703&h=705&img=' + escape('<img src="/image/popup/joinus.png" class="png24"/>'),'<img src="/image/popup/joinus.png" class="png24"/>', 703, 705);
}

function ShowRealName() {
    ShowPopup('/MessageFrame.aspx?u=' + escape('/Join/RealName.aspx'),'', 438, 370, false, false);
}

function ShowPreviewGoods(cc, gc) {
    ShowPopup('/MessageFrame.aspx?u=' + escape('/shop/PreviewGoods.aspx?cc='+cc+'&gc='+gc),'<img src="/image/product_shop/preview/logo.png" class="png24"/>', 617, 280);
}

function ResizeLayerPopupWin(width, height, img) {
    if(Ext.get("_PopupFrame") != null) {
        top.Ext.get('_PopupFrame').dom.style.width = width + "px";
        top.Ext.get('_PopupFrame').dom.style.height = height + "px";
        top.TnfPopupWin.setTitle(img);
        top.TnfPopupWin.setSize(Number(width) + 23, Number(height) + 15);
    }
}

function ShowDefaultPopup() {
    //try {
        var TmpArr = _MainPopup.reverse();
        var left = 0;
        
        for(i = 0; i < TmpArr.length; i++) {
            var PopObj = TmpArr[i];
            
            if(getCookie(PopObj.Image + "_ING") != "DONE" && getCookie(PopObj.Image + "_ING") != "TODAY") {
                window.open("/popup/main/MainPopup.aspx?IMG=" + PopObj.Image + "&Target=" + PopObj.Target + "&LINK=" + PopObj.Link, "", "width="+PopObj.Width+",height="+PopObj.Height+",toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,left="+left+",top=0");
                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;
		}
	}
	
	return unescape(objCookie.substring(nBegin, nEnd));
}