
/*---------------------------------------------------------------*/
/* 레이어 팝업 처리 */
/*---------------------------------------------------------------*/
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 = parent.document.getElementById('dialogbackgroundlayer');
	this.dlg = parent.document.getElementById('dialoglayer');
	this.msg = parent.document.getElementById('message');

	this.parentHeight = 0;
	this.cartoonobj = null;


	this.dialog_open= function(url, w_width, w_height, run_script)
	{
	this.dlg_bg.style.left = '0px';

	this.dlg_bg.style.top = '0px';
	this.dlg_bg.style.width = '100%';

	this.dlg_bg.style.background = "#000";
	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)';


		//var height = document.body.clientHeight;

		if (!w_height) w_height = 170;
		if (this.is_gecko) height += 10;

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

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

		if (run_script)
			popup_script = run_script;
		else
			popup_script = false;

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

		if(screen.height < 1024 && w_height == 710) {
			this.dlgSizeChange();
		}

		var Array_select = document.body.getElementsByTagName("SELECT");
		for(var i=0; i < Array_select.length; i++) {	
			Array_select[i].style.visibility = "hidden";
		}
		this.dlg.style.display = '';
	}

	this.sizestate = true;
	var tmptimer = "";
	this.dlgSizeChange = function()
	{
//		if(this.sizestate) {
			this.parentHeight = parent.document.body.scrollHeight;
			this.cartoonobj = parent.document.getElementById('cartoonviewDiv');
//			if(this.cartoonobj) {
				this.dlg.style.height = (this.parentHeight / 2) + 'px';
				this.dlg.style.top = (this.parentHeight+300) / 2 + 'px';
				this.cartoonobj.style.height = (this.parentHeight / 1.8) + 'px';

				//this.sizestate = false;
//				clearTimeout(tmptimer);
//			} else {
//				this.dlgSizeChange();
//				tmptimer = setTimeout("this.dlgSizeChange()", 2000);
//			}
//		}
	}

	this.dialog_close= function()
	{
//		this.dlg_bg.style.display = 'none';
//		this.dlg.style.display = 'none';
//alert(Array_select.length);
		document.getElementById('dialogbackgroundlayer').style.display = 'none';
		document.getElementById('dialoglayer').style.display = 'none';

		var Array_select = bg_iframe.document.getElementsByTagName("SELECT");
		for(var i=0; i < Array_select.length; i++) {	
			Array_select[i].style.visibility = "visible";
		}

	}

	this.in_alert = function(message)
	{
		this.msg.innerHTML = message;
		this.msg.style.display = '';
		window.setTimeout(this.in_alert_hidden, 2000);
		in_alertcount++;
	}

	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, false);
			popup_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
//			popup_req.setRequestHeader('Content-Type', 'text/html; charset=utf-8');
			popup_req.send("");
		}
	}

	this.processPopup = function() {
		// only if req shows "loaded"
		var obj = parent.document.getElementById('dialoglayer');
		if (popup_req.readyState == 4) {
			// only if "OK"
			obj.innerHTML = popup_req.responseText;
			if (popup_script)
				eval(popup_script);
		}
	}
}
