/**********************************************************************************************
            레이어 팝업 모듈            - 07. 2. 13  by Hamt -



모든 페이지에 인클루드 되는 파일에 이 소스를 추가한다. 

<!-- new popup start -->
<div id="dialogbackgroundlayer" style="display:none;position:absolute;z-index:11;" onclick="win.dialog_close()">
</div>
<div id="dialoglayer" style="display:none;position:absolute;z-index:12;">
</div>
<div id="confirmmessage" style='width:1px;height:1px;position:absolute;z-index:13;'></div>
<div id=message style="display:none;position:absolute;left:0px;top:100px;padding:15px;background:#000000;color:#ffff00;font-size:13px;font-weight:bold;z-index:100;"></div>
<!--object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"
 width="0" height="0" id="sound_confirm">
<param name="FileName" value="/hamt_pop/confirm.mp3">
<param name="AutoStart" value="false">
<param name="ShowTracker" value="false">
<param name="ShowControls" value="false">
<param name="ShowGotoBar" value="false">
<param name="ShowDisplay" value="false">
<param name="ShowStatusBar" value="false">
<param name="AutoSize" value="false">
<embed width="1" height="1" src="/hamt_pop/confirm.mp3"
AutoStart="false"
ShowTracker="false"
ShowControls="false"
ShowGotoBar="false"
ShowDisplay="false"
ShowStatusBar="false"
AutoSize="false"
pluginspage="http://www.microsoft.com/windows/windowsmedia/download/">
</object-->

<script>
var win = new new_popup();
</script>
<!-- new popup end -->

/***********************************************************************************************/

var popup_req = false;//for popup ajax
var popup_script = false;//dialog_open 네번째 인자로 레이어 팝업창을 띄운 직후 실행할 스크립트 값
var in_alertcount = 0;
function new_popup(objname)
{
	if(!objname)
		objname = 'win';
	this.objName = objname;
    this.agent_name = navigator.userAgent.toLowerCase();
    this.is_ie = ((this.agent_name.indexOf("msie") != -1) && (this.agent_name.indexOf("opera") == -1));
    this.is_gecko = navigator.product;

    this.position_x = 0;
    this.position_y = 0;

	this.confirmflag = false;
	this.confirmokscript;

    
    this.dlg = document.getElementById('dialoglayer');
    this.msg = document.getElementById('message');
	this.confirmmsg = document.getElementById('confirmmessage');
	this.confirmmsg.style.display = 'none';

	var html = "<div id=confirmmsg_top style='background:url(/hamt_pop/images/tl.gif) no-repeat left top;position:relative;'>";
		html += "<div style='padding-top:15px;padding-right:15px;background:url(/hamt_pop/images/tr.gif) no-repeat right top;position:relative;right:-15px;color:white;'>";
		html += "<div id=confirmmsg_body style='color:white;'></div>";
		html += "<div style='text-align:center;padding-top:20px;'>";
		html += "<img src='/hamt_pop/images/btn_ok.gif' style='cursor:pointer;' onclick='"+this.objName+".in_confirmanswer(1);'>&nbsp;&nbsp;";
		html += "<img src='/hamt_pop/images/btn_cancel.gif' style='cursor:pointer;margin-left:10px;' onclick='"+this.objName+".in_confirmanswer(2);'>";
		html += "</div></div></div>";
		html += "<div id=confirmmsg_bottom style='height:15px;background:url(/hamt_pop/images/bl.gif) no-repeat left top;position:relative;'>";
		html += "<div style='height:15px;background:url(/hamt_pop/images/br.gif) no-repeat right top;position:relative;right:-15px;'>";
		html += "</div></div>";
	this.confirmmsg.innerHTML = html;


	this.dlg_bg = document.getElementById('dialogbackgroundlayer');
    this.dlg_bg.style.left = '0px';
    this.dlg_bg.style.top = '0px';
    this.dlg_bg.style.background = "#000";
    this.dlg_bg.style.opacity = (70/100);
    this.dlg_bg.style.MozOpacity = (70/100);
    this.dlg_bg.style.KhtmlOpacity = (70/100);
    this.dlg_bg.style.filter = 'alpha(opacity=70)';

	this.msg.style.opacity = (80/100);
    this.msg.style.MozOpacity = (80/100);
    this.msg.style.KhtmlOpacity = (80/100);
    this.msg.style.filter = 'alpha(opacity=80)';
	this.msg.zIndex = 100000;

    this.in_confirm = function(msg, script, w_width, w_height)
    {
		this.confirmokscript = script;
		this.confirmflag = true;
		if(!w_width)
			w_width = 300;
		this.confirmmsg.style.width='';
		this.confirmmsg.style.height='';
		document.getElementById('confirmmsg_top').style.width = w_width+'px';
		document.getElementById('confirmmsg_bottom').style.width = w_width+'px';
		document.getElementById('confirmmsg_body').innerHTML = msg;
		var mode = 'body';
		if(document.body.scrollTop < document.documentElement.scrollTop)
			mode = 'documentElement';
		
	    eval('var oriscrolltop = document.'+mode+'.scrollTop;');
		//alert(oriscrolltop);
	    eval('document.'+mode+'.scrollTop = 100000;');
        eval('var height = document.body.clientHeight+document.'+mode+'.scrollTop;');
	    eval('document.'+mode+'.scrollTop = oriscrolltop;');

	    if (this.is_gecko)
			height += 70;
		
		
		this.dlg_bg.style.width = '100%';
		this.dlg_bg.style.height = height + 'px';
		this.dlg_bg.style.display = '';	
	    if (!w_height)
			w_height = oriscrolltop + (document.body.clientHeight/2-100/2);

	    this.confirmmsg.style.left = "50%";
	    this.confirmmsg.style.top = w_height + "px";
	    this.confirmmsg.style.marginLeft = w_width/2*-1+"px";


	    this.confirmmsg.style.display = '';
		//sound_confirm.play();		
    }	
	this.in_confirmanswer = function(ans)
	{
		this.confirmflag = false;
		this.confirm_close();

		if(ans == 1)
		{
			eval(this.confirmokscript);
			return 
		}
		this.confirmscript = '';	
	}
	this.confirm_close = function()
	{
		if(this.confirmflag)
		    return;
		this.dlg_bg.style.display = 'none';
		this.confirmmsg.style.display = 'none';
		document.getElementById('confirmmsg_body').innerHTML = '';
	}

    this.dialog_open = function(url, w_width, w_height, run_script) {
		var height = document.body.clientHeight;
		if (this.is_gecko) 
		    height += 70;

		if (!w_height) 
		    w_height = document.documentElement.scrollTop + 170;

		this.dlg_bg.style.height = height + 'px';
		this.dlg_bg.style.width = '100%';
		this.dlg_bg.style.display = '';

		this.dlg.style.left = "50%";
		this.dlg.style.top = w_height + "px";
		this.dlg.style.marginLeft = w_width/2*-1+"px";
		if (run_script)
			popup_script = run_script;
		else
			popup_script = false;

		if(url.length) this.load(url);
		this.dlg.style.display = '';

	}

    this.dialog_open_post = function(url, querystring, w_width, w_height, run_script) {
		var height = document.body.clientHeight;
		if (!w_height) w_height = 170;
		if (this.is_gecko) height += 10;
	
		this.dlg_bg.style.height = height + 'px';
		this.dlg_bg.style.display = '';

		this.dlg.style.left = "50%";
		this.dlg.style.top = w_height + "px";
		this.dlg.style.marginLeft = w_width/2*-1+"px";
		if (run_script)
			popup_script = run_script;
		else
			popup_script = false;

		this.load_post(url, querystring);
		this.dlg.style.display = '';

	}
	
    this.dialog_close= function() {
		if(this.confirmflag)
		    return;
		this.dlg_bg.style.display = 'none';
		this.dlg.style.display = 'none';
		this.dlg.innerHTML = '';
	}

    this.in_alert = function(message, x, y) {
		if(!x)
			x = 0;
		if(!y)
			y = 0;
		var st = document.body.scrollTop;
		if(st < document.documentElement.scrollTop)
			st = document.documentElement.scrollTop;

		this.msg.innerHTML = message;
		this.msg.style.display = '';
		
		if(y)
			this.msg.style.top = st+parseInt(y)+'px';
		else
			this.msg.style.top = st+'px';

		if(x)
			this.msg.style.left = x+'px';
		else
			this.msg.style.left = '0px';

		window.setTimeout(this.in_alert_hidden, 2000);
		in_alertcount++;
	}
	this.in_absalert = function(message, e)
	{			
		var x=0;
		var y=0;

		if(document.all)
		{
			x = event.clientX;
			y = event.clientY;
		}
		else if(arguments[0])
		{
			x = arguments[0].clientX;
			y = arguments[0].clientY;
		}
		
		this.in_alert(message, x, y);		
	}
    this.in_alert_hidden = function() {
		in_alertcount--;
		if(!in_alertcount)
			document.getElementById('message').style.display = 'none';
	}

    this.load = function(url) {
		popup_req= false;
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			try {
				popup_req = new XMLHttpRequest();
			}
			catch(e) {
				popup_req = false;
			}
		}
		// branch for IE/Windows ActiveX version
		else if (window.ActiveXObject) {
			try {
				popup_req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				try {
					this.req= new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) {
					popup_req  = false;
				}
			}
		}
		if (popup_req ) {

			popup_req.onreadystatechange = this.processPopup;
			popup_req.open("GET", url, true);
			popup_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
			popup_req.send("");
		}
    }
    this.load_post = function(url, querystring) {
		popup_req= false;
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			try {
				popup_req = new XMLHttpRequest();
			}
			catch(e) {
				popup_req = false;
			}
		}
		// branch for IE/Windows ActiveX version
		else if (window.ActiveXObject) {
			try {
				popup_req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				try {
					this.req= new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) {
					popup_req  = false;
				}
			}
		}
		if (popup_req ) {
			popup_req.onreadystatechange = this.processPopup;
			popup_req.open("POST", url, true);
			popup_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
			popup_req.send(querystring);
		}
    }	
    this.processPopup = function() {
		// only if req shows "loaded"
		var obj = document.getElementById('dialoglayer');
		if (popup_req.readyState == 4) {
			if (popup_req.status == 200)
			{
				obj.innerHTML = popup_req.responseText;
			}
			else
			{
				eval(popup_req.responseText);
			}
		
			if (popup_script)
				eval(popup_script);
		}
    }
}


