/**************************************************************************
  ·¹ÀÌ¾î ÆË¾÷ ¸ðµâ
  ¸ðµç ÆäÀÌÁö¿¡ ÀÎÅ¬·çµå µÇ´Â ÆÄÀÏ¿¡ ÀÌ ¼Ò½º¸¦ Ãß°¡ÇÑ´Ù.

  <!-- 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=message style="display:none;position:absolute;left:0px;top:0px;padding:3px;background:#cc0000;color:#ffffff;font-size:13px;font-weight:bold;z-index:100;"></div>
  <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()
{
	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.ajax_url = '';

	this.dlg_bg = document.getElementById('dialogbackgroundlayer');
	this.dlg = document.getElementById('dialoglayer');
	this.msg = document.getElementById('message');

	this.dlg_bg.style.left = '0px';

	this.dlg_bg.style.top = '0px';
	this.dlg_bg.style.width = '100%';
        //this.dlg_bg.style.height = '100%';
	this.dlg_bg.style.background = "#000000";
	this.dlg_bg.style.opacity = (50/100);
	this.dlg_bg.style.MozOpacity = (50/100);
	this.dlg_bg.style.KhtmlOpacity = (50/100);
	this.dlg_bg.style.filter = 'alpha(opacity=50)';


        /**
         * dialog open scroll scroll
         */
        this.dialog_open_scroll = function(url, w_width, w_height, w_margin, run_script)
	{
                //body scroll no (2007-07-17)
                //document.body.scroll = "no";
                var objSelect = document.getElementsByTagName("select");
                for (var i=0; i < objSelect.length; i++) {
                  objSelect[i].style.display = "none";
                }

                var bgHeight;
                if (document.body.clientHeight > document.body.scrollHeight) {
                  bgHeight = document.body.clientHeight;
                } else {
                  bgHeight = document.body.scrollHeight;
                }

                var width = document.body.scrollWidth;
                var height = bgHeight;

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

                var cwidth = document.body.clientWidth - w_margin;
                var cheight = document.body.clientHeight - w_margin;
                //alert("cwidth : " + cwidth);
                //alert("cheight : " + cheight);

                this.dlg.style.width = w_width;
                this.dlg.style.height = w_height;

                this.dlg.style.overflowY = "auto";
                var p_left = document.body.clientWidth/2 - w_width/2;
                var p_top = document.body.clientHeight/2 - w_height/2 + document.body.scrollTop;
                //alert("p_left : " + p_left);
                //alert("p_top : " + p_top);
                this.dlg.style.left = p_left;
                this.dlg.style.top = p_top;


                this.dlg.style.display = 'block';
//                this.dlg.innerHTML = makeLoading2();
                if (run_script)
			popup_script = run_script;
		else
			popup_script = false;
                this.load(url);


	}

        /**
         * dialog open scroll auto
         */
        this.dialog_open_auto= function(url, w_width, w_height, w_margin, run_script)
	{
                //body scroll no (2007-07-17)
                //document.body.scroll = "no";
                var objSelect = document.getElementsByTagName("select");
                for (var i=0; i < objSelect.length; i++) {
                  objSelect[i].style.display = "none";
                }

                var bgHeight;
                if (document.body.clientHeight > document.body.scrollHeight) {
                  bgHeight = document.body.clientHeight;
                } else {
                  bgHeight = document.body.scrollHeight;
                }
                var width = document.body.scrollWidth;
                var height = bgHeight;

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

                var cwidth = document.body.clientWidth - w_margin;
                var cheight = document.body.clientHeight - w_margin;
                //alert("cwidth : " + cwidth);
                //alert("cheight : " + cheight);


                var digWidth;
                var digHeight;
                if (w_width > cwidth) {
                  //alert('width Å©´Ù');
                  digWidth = cwidth;
                  this.dlg.style.overflowX = "auto";
                } else {
                  //alert('width ÀÛ´Ù');
                  digWidth = w_width;
                  this.dlg.style.overflowX = "hidden";
                }

                if (w_height > cheight) {
                  //alert('height Å©´Ù');
                  digHeight = cheight;
                  this.dlg.style.overflowY = "auto";
                } else {
                  //alert('height ÀÛ´Ù');
                  digHeight = w_height;
                  this.dlg.style.overflowY = "hidden";

                }
                this.dlg.style.width = digWidth;
                this.dlg.style.height = digHeight;
                //alert("digWidth : " + digWidth);
                //alert("digHeight : " + digHeight);
                var p_left = document.body.clientWidth/2 - digWidth/2;
                var p_top = document.body.clientHeight/2 - digHeight/2 + document.body.scrollTop;
                //alert("p_left : " + p_left);
                //alert("p_top : " + p_top);
                this.dlg.style.left = p_left;
                this.dlg.style.top = p_top;


                this.dlg.style.display = 'block';
//                this.dlg.innerHTML = makeLoading2();
		if (run_script)
			popup_script = run_script;
		else
			popup_script = false;

		this.load(url);


	}

        /**
         * dialog close
         */
	this.dialog_close= function()
	{

                var objSelect = document.getElementsByTagName("select");

                for (var i=0; i < objSelect.length; i++) {
                  objSelect[i].style.display = "inline";
                }

		this.dlg_bg.style.display = 'none';
		this.dlg.style.display = 'none';
                this.dlg.innerHTML = '';

                //body scroll yes (2007-07-17)
                //document.body.scroll = "yes";
                document.getElementById('message').style.display = 'none'      //alt messageµµ ´Ý´Â´Ù.



	}

        /**
         * dialog message
         */
	this.in_alert = function(message)
	{
		this.msg.innerHTML = message;
                this.msg.style.top = document.body.scrollTop;
		this.msg.style.display = 'block';
		window.setTimeout(this.in_alert_hidden, 5000);           //5ÃÊ µ¿¾È º¸¿©Áø´Ù.
		in_alertcount++;
	}

        /**
         * dialog message hidden
         */
	this.in_alert_hidden = function()
	{
		in_alertcount--;
		if(!in_alertcount)
			document.getElementById('message').style.display = 'none';
	}

        /**
         * dialog ajax load
         */
	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("");
		}
	}

        /**
         * dialog ajax process :: script & loading
         */
	this.processPopup = function() {
		// only if req shows "loaded"
		var obj = document.getElementById('dialoglayer');
//                obj.innerHTML = makeLoading2();
		if (popup_req.readyState == 4 && popup_req.status == 200) {
			// only if "OK"
			obj.innerHTML = popup_req.responseText;
			if (popup_script) {
                          eval(popup_script);
                        }
		}
	}

}

