﻿(function() {

//	@ Ntreevsoft Inner Popup JS v1.01 (2009.03.23)
//   script by Su-hyung, park

// 이미지파일 경로 및 타이틀 이미지 명 정의
var nSetting = {
	path : "http://public.gametree.co.kr/Global/img/nPopup/",
	title : 'npop_title_bm.gif'
}

var nRoot, nDoc = document, nMask, nIng = false;
var nPopup = window.nPopup = function(url, width, height) {

    if( /nPopupOut=true/.test(nDoc.cookie)) return null;

    nRoot = /khtml/i.test(navigator.userAgent) ? nDoc.body : nDoc.documentElement || nDoc.body;
    var el = this.el = this.el ? this.el : nDoc.createElement('div');
    el.id = 'nPop'+parseInt(Math.random()*1000).toString();
    el.innerHTML = [
        '<table border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;"><tr><td style="background:#eaeaea; border:1px solid #444;">',
        '<p onmousedown="nPopup.dragStart(\''+el.id+'\',event)" onmouseup="nPopup.dragEnd()" style="position:relative;background:url('+nSetting.path+'npop_titlebg.gif); border-left:1px solid #f5f5f5; border-right:1px solid #f5f5f5;  font:bold 12px dotum; padding:4px 8px 5px; margin:0; cursor:move; text-align:left;"><img src="'+nSetting.path+nSetting.title+'" ondragstart="return false" alt="" /></p>',
        '<div style="border-left:1px solid #f5f5f5; border-right:1px solid #f5f5f5; padding:0 7px;"><div style="background:#bababa; border:1px solid #fff;">',
        '<div style="height:'+height+'px;width:'+width+'px;overflow:hidden;" id="'+el.id+'_content"></div>',
        '</div></div>',
        '<div style="background:url('+nSetting.path+'npop_footbg.gif) 0 bottom; border-left:1px solid #f5f5f5; border-right:1px solid #f5f5f5; font:normal 11px dotum; color:#828282; padding:0 10px 8px 6px; text-align:left;">',
        '<label><input type="checkbox" id="'+el.id+'_chk" style="position:relative;top:3px;vertical-align:text-bottom;background:none;border:none" />오늘 하루 이창을 열지 않습니다.</label>',
        '<img src="'+nSetting.path+'npop_close.gif" width="29" height="16" alt="닫기" onclick="nPopup.hide(\''+el.id+'\')" style="position:absolute;right:25px;margin-top:6px;cursor:pointer;" />',
        '<img src="'+nSetting.path+'npop_x.gif" width="15" height="14" alt="닫기" onclick="nPopup.hide(\''+el.id+'\')" style="position:absolute;top:8px;right:25px;cursor:pointer;" />',
        '</div>',
        '</td>',
        '<td style="width:15px; background:url('+nSetting.path+'npop_rshadow.png); _background:none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+nSetting.path+'npop_rshadow.png\', sizingMethod=\'crop\');"></td>',
        '</tr><tr>',
        '<td style="height:15px; background:url('+nSetting.path+'npop_bshadow.png); _background:none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+nSetting.path+'npop_bshadow.png\', sizingMethod=\'crop\');"></td>',
        '<td style="width:15px; height:15px; background:url('+nSetting.path+'npop_cshadow.png); _background:none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+nSetting.path+'npop_cshadow.png\', sizingMethod=\'crop\');"></td>',
        '</tr>',
        '</table>',
    ].join('');

    var pos = /(?:nPopupPos=([^;]+))/.exec(nDoc.cookie);
    pos = pos ? String(pos[1]).split('|') : [];

    el.style.position = 'absolute';
    el.style.left = (pos[0] || (nRoot.clientWidth/2 - width/2)) + 'px';
    el.style.top = (pos[1] || (nRoot.clientHeight/2 - height/2)) + 'px';
    el.style.zIndex = '997';
    el.style.display = 'block';

    // 임시 함수를 생성 후 페이지가 준비되는데로 실행되도록 클로징 설정
   var func = function() {
        var body = nDoc.body;
        body.insertBefore(el, body.firstChild)
        nPopup.getContent(url, el.id+'_content', width, height);
    };
    if (document.getElementsByTagName('html')[0] && document.getElementsByTagName('body')[0])
        func();
    else if (el.addEventListener)
        window.addEventListener('load', func, false);
    else
        window.attachEvent("onload", func);
}

nPopup.dragStart = function(id, e) {
    var evt = e ? e : window.event;
    this.el = nDoc.getElementById(id);

    if (!nMask) nMask = nDoc.createElement('div');
    with (nMask.style) {
        background = '#fff'; position = 'absolute'; top = '0'; left = '0'; display = 'block'; opacity = '0.3';
        width = nRoot.scrollWidth+'px'; height = nRoot.scrollHeight+'px'; zIndex = '996';
	    try { filter = "alpha(opacity=30)" } catch(e) {};
	}
    nDoc.body.appendChild(nMask);

    // 드래그 발동시 고정값들을 미리 저장한다
    this.clientLeft = this.el.offsetLeft - evt.clientX;
    this.clientTop = this.el.offsetTop - evt.clientY;
    this.revLeft = this.el.clientWidth - this.clientLeft;
    this.revTop = this.el.clientHeight - this.clientTop;

    // 이벤트 캡쳐미스, 중복클릭 등의 경우에 이벤트가 계속 축적되어 이벤트가 해제되지 않는 경우를 대비하여
    // Element의 Static handler을 사용하여 마우스이동을 캡쳐
    nDoc.body.onselectstart = function() { return false; };
    if (!nIng) {
        nDoc._onmousemove = nDoc.onmousemove;
        nDoc.onmousemove = nPopup.dragMove;
        nIng = true;
    }
}

nPopup.dragMove = function(e) {
    var obj = nPopup,
        evt = e ? e : window.event,
        left = evt.clientX+obj.clientLeft,
        top = evt.clientY+obj.clientTop;

    // 마우스클릭 상태가 풀리면 드래그 해제 (IE전용)
    if ( evt.button != 1 && !(evt.which == 1 && !evt.metaKey) ) return nPopup.dragEnd();

    // 초기 위치는 정중앙으로
    obj.el.style.left = Math.max(5, Math.min(left, nRoot.scrollWidth - obj.el.clientWidth))+'px';
    obj.el.style.top = Math.max(53, Math.min(top, nRoot.scrollHeight - obj.el.clientHeight))+'px';
}

nPopup.dragEnd = function(id) {
    nMask.style.display = 'none';
    nDoc.onmousemove = nDoc._onmousemove;
    nDoc.body.onselectstart = null;

    nPopup.save('nPopupPos',nPopup.el.offsetLeft+'|'+nPopup.el.offsetTop, 7);
    nIng = false;
}

nPopup.save = function(name, value, delay) {
    var today = new Date();
    today.setDate(today.getDate()+(delay||1));
    nDoc.cookie = name+'='+value+'; path=/; '+(delay ? 'expires='+today.toGMTString() : '');
}

nPopup.clean = function() {
    nPopup.save('nPopupOut', 'false', -1);
    nPopup.save('nPopupPos', '', -1);
}

nPopup.getContent = function(url, id, width, height) {
    try {  var ajax = new ActiveXObject("Microsoft.XMLHTTP") }
    catch(e) {
        var ajax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
    }

    if (/^http/.test(location.href)) {
		var postData = /(^[^?]+)\??(.+$)?/.exec(url);
        ajax.open('post', postData[1], true);
	    ajax.onreadystatechange = function() {
		    if ( ajax.readyState == 4 ) {
			    if ( ajax.status == 200 || ajax.status == 304 ) {
					if (nDoc.getElementById(id))
					{
						nDoc.getElementById(id).innerHTML = ajax.responseText.replace(/{path}/g, nSetting.path);
					}
			    } else {
					if (nDoc.getElementById(id))
					{
						nDoc.getElementById(id).innerHTML = 'Content load failed... <br />error code : '+ajax.status;
					}
			    }
		    }
	    }
	    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	    ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	    ajax.setRequestHeader("Pragma", "no-cache");
	    ajax.send(postData[2]||'');
    } else {
        nDoc.getElementById(id).innerHTML = '<iframe src="'+url+'" frameborder="0" width="'+width+'" height="'+height+'" name="nPopupFrame" scrolling="no" onload="nPopup.setIframe(this)"></iframe>';
    }
}

nPopup.setIframe = function(obj) {
    with (frames.nPopupFrame.window) {
        document.body.style.padding = '0';
        document.body.style.margin = '0';
    }
}

nPopup.hide = function(id) {
    if ( nDoc.getElementById(id+'_chk').checked )
        nPopup.save('nPopupOut', 'true', 1);

    nDoc.getElementById(id).style.display = 'none';
}

/////////////////////

var nRoot2, nDoc2 = document, nMask2, nIng2 = false;
var nPopup2 = window.nPopup2 = function(url, width, height) {

    if( /nPopup2Out=true/.test(nDoc2.cookie)) return null;

    nRoot2 = /khtml/i.test(navigator.userAgent) ? nDoc2.body : nDoc2.documentElement || nDoc2.body;
    var el = this.el = this.el ? this.el : nDoc2.createElement('div');
    el.id = 'nPop2'+parseInt(Math.random()*1000).toString();
    el.innerHTML = [
        '<table border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;"><tr><td style="background:#eaeaea; border:1px solid #444;">',
        '<p onmousedown="nPopup2.dragStart(\''+el.id+'\',event)" onmouseup="nPopup2.dragEnd()" style="position:relative;background:url('+nSetting.path+'npop_titlebg.gif); border-left:1px solid #f5f5f5; border-right:1px solid #f5f5f5;  font:bold 12px dotum; padding:4px 8px 5px; margin:0; cursor:move; text-align:left;"><img src="'+nSetting.path+nSetting.title+'" ondragstart="return false" alt="" /></p>',
        '<div style="border-left:1px solid #f5f5f5; border-right:1px solid #f5f5f5; padding:0 7px;"><div style="background:#bababa; border:1px solid #fff;">',
        '<div style="height:'+height+'px;width:'+width+'px;overflow:hidden;" id="'+el.id+'_content">',
		'<div><span style="font-size: 8pt"><img height="357" alt="" width="388" usemap="#abbf1fbc" src="/popup.jpg" />&nbsp;<map id="abbf1fbc" name="abbf1fbc">',
		'<area alt="대표계정 설정 하러 가기" href="/GameAccount/Account3.aspx" coords="115,305,274,334" shape="rect" /></map></span></div>',
        '</div></div></div>',
        '<div style="background:url('+nSetting.path+'npop_footbg.gif) 0 bottom; border-left:1px solid #f5f5f5; border-right:1px solid #f5f5f5; font:normal 11px dotum; color:#828282; padding:0 10px 8px 6px; text-align:left;">',
        '<label><input type="checkbox" id="'+el.id+'_chk" style="position:relative;top:3px;vertical-align:text-bottom;background:none;border:none" />오늘 하루 이창을 열지 않습니다.</label>',
        '<img src="'+nSetting.path+'npop_close.gif" width="29" height="16" alt="닫기" onclick="nPopup2.hide(\''+el.id+'\')" style="position:absolute;right:25px;margin-top:6px;cursor:pointer;" />',
        '<img src="'+nSetting.path+'npop_x.gif" width="15" height="14" alt="닫기" onclick="nPopup2.hide(\''+el.id+'\')" style="position:absolute;top:8px;right:25px;cursor:pointer;" />',
        '</div>',
        '</td>',
        '<td style="width:15px; background:url('+nSetting.path+'npop_rshadow.png); _background:none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+nSetting.path+'npop_rshadow.png\', sizingMethod=\'crop\');"></td>',
        '</tr><tr>',
        '<td style="height:15px; background:url('+nSetting.path+'npop_bshadow.png); _background:none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+nSetting.path+'npop_bshadow.png\', sizingMethod=\'crop\');"></td>',
        '<td style="width:15px; height:15px; background:url('+nSetting.path+'npop_cshadow.png); _background:none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+nSetting.path+'npop_cshadow.png\', sizingMethod=\'crop\');"></td>',
        '</tr>',
        '</table>',
    ].join('');

    var pos = /(?:nPopup2Pos=([^;]+))/.exec(nDoc2.cookie);
    pos = pos ? String(pos[1]).split('|') : [];

    el.style.position = 'absolute';
    el.style.left = (pos[0] || (nRoot2.clientWidth/2 - width/2)) + 'px';
    el.style.top = (pos[1] || (nRoot2.clientHeight/2 - height/2)) + 'px';
    el.style.zIndex = '997';
    el.style.display = 'block';

    // 임시 함수를 생성 후 페이지가 준비되는데로 실행되도록 클로징 설정
	
   var func2 = function() {
        var body = nDoc2.body;
        body.insertBefore(el, body.firstChild)
        //nPopup2.getContent(url, el.id+'_content', width, height);
    };
    if (document.getElementsByTagName('html')[0] && document.getElementsByTagName('body')[0])
        func2();
    if (el.addEventListener)
        window.addEventListener('load', func2, false);
    else
        window.attachEvent("onload", func2);
	
}

nPopup2.dragStart = function(id, e) {
    var evt = e ? e : window.event;
    this.el = nDoc2.getElementById(id);

    if (!nMask2) nMask2 = nDoc2.createElement('div');
    with (nMask2.style) {
        background = '#fff'; position = 'absolute'; top = '0'; left = '0'; display = 'block'; opacity = '0.3';
        width = nRoot2.scrollWidth+'px'; height = nRoot2.scrollHeight+'px'; zIndex = '996';
	    try { filter = "alpha(opacity=30)" } catch(e) {};
	}
    nDoc2.body.appendChild(nMask2);

    // 드래그 발동시 고정값들을 미리 저장한다
    this.clientLeft = this.el.offsetLeft - evt.clientX;
    this.clientTop = this.el.offsetTop - evt.clientY;
    this.revLeft = this.el.clientWidth - this.clientLeft;
    this.revTop = this.el.clientHeight - this.clientTop;

    // 이벤트 캡쳐미스, 중복클릭 등의 경우에 이벤트가 계속 축적되어 이벤트가 해제되지 않는 경우를 대비하여
    // Element의 Static handler을 사용하여 마우스이동을 캡쳐
    nDoc2.body.onselectstart = function() { return false; };
    if (!nIng2) {
        nDoc2._onmousemove = nDoc2.onmousemove;
        nDoc2.onmousemove = nPopup2.dragMove;
        nIng2 = true;
    }
}

nPopup2.dragMove = function(e) {
    var obj = nPopup2,
        evt = e ? e : window.event,
        left = evt.clientX+obj.clientLeft,
        top = evt.clientY+obj.clientTop;

    // 마우스클릭 상태가 풀리면 드래그 해제 (IE전용)
    if ( evt.button != 1 && !(evt.which == 1 && !evt.metaKey) ) return nPopup2.dragEnd();

    // 초기 위치는 정중앙으로
    obj.el.style.left = Math.max(5, Math.min(left, nRoot2.scrollWidth - obj.el.clientWidth))+'px';
    obj.el.style.top = Math.max(53, Math.min(top, nRoot2.scrollHeight - obj.el.clientHeight))+'px';
}

nPopup2.dragEnd = function(id) {
    nMask2.style.display = 'none';
    nDoc2.onmousemove = nDoc2._onmousemove;
    nDoc2.body.onselectstart = null;

    nPopup2.save('nPopup2Pos',nPopup2.el.offsetLeft+'|'+nPopup2.el.offsetTop, 7);
    nIng2 = false;
}

nPopup2.save = function(name, value, delay) {
    var today = new Date();
    today.setDate(today.getDate()+(delay||1));
    nDoc2.cookie = name+'='+value+'; path=/; '+(delay ? 'expires='+today.toGMTString() : '');
}

nPopup2.clean = function() {
    nPopup2.save('nPopup2Out', 'false', -1);
    nPopup2.save('nPopup2Pos', '', -1);
}

nPopup2.getContent = function(url, id, width, height) {
    try {  var ajax = new ActiveXObject("Microsoft.XMLHTTP") }
    catch(e) {
        var ajax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
    }

    if (/^http/.test(location.href)) {
		var postData = /(^[^?]+)\??(.+$)?/.exec(url);
        ajax.open('post', postData[1], true);
	    ajax.onreadystatechange = function() {
		    if ( ajax.readyState == 4 ) {
			    if ( ajax.status == 200 || ajax.status == 304 ) {
				    nDoc2.getElementById(id).innerHTML = ajax.responseText.replace(/{path}/g, nSetting.path);
			    } else {
				    nDoc2.getElementById(id).innerHTML = 'Content load failed... <br />error code : '+ajax.status;
			    }
		    }
	    }
	    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	    ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	    ajax.setRequestHeader("Pragma", "no-cache");
	    ajax.send(postData[2]||'');
    } else {
        nDoc2.getElementById(id).innerHTML = '<iframe src="'+url+'" frameborder="0" width="'+width+'" height="'+height+'" name="nPopup2Frame" scrolling="no" onload="nPopup2.setIframe(this)"></iframe>';
    }
}

nPopup2.setIframe = function(obj) {
    with (frames.nPopup2Frame.window) {
        document.body.style.padding = '0';
        document.body.style.margin = '0';
    }
}

nPopup2.hide = function(id) {
    if ( nDoc2.getElementById(id+'_chk').checked )
        nPopup2.save('nPopup2Out', 'true', 1);

    nDoc2.getElementById(id).style.display = 'none';
}


/////////////////////

})();