Popup = function(oParent, show_top)
{
	this.oParent = null;
	this.oFirer = null;
	this.oPopup = null;
	this.oBodyIframe = null;
	this.oBody = null;
	this.oTitleSec = null;
	this.oContent = null;
	this.oCloseBtn = null;

	this.show_top = null;
	this.is_show = false;

	this.top = null;
	this.left = null;
	this.width = null;

	this.isDrag = false;
	this.dragX = 0;
	this.dragY = 0;

	if(oParent == null || typeof(oParent) == 'undefined')
	{
		this.oParent = document.body;
		this.top = "0px";
		this.left = "0px";

		var oThis = this;

		this.oParent.attachEvent("onmouseup", function() { oThis.EndDrag(); } );
		this.oParent.attachEvent("onmousemove", function(e) { oThis.MoveDrag(e); } );
	}else {
		this.oParent = oParent;
		this.oParent.style.position = "relative";
		this.top = this.oParent.offsetHeight+"px";
		this.left = "0px";
	}

	if(typeof(show_top) == 'undefined')
	{
		this.show_top = true;
	}else {
		this.show_top = show_top;
	}


	//var dd = this.caller;
	//alert(this.caller);
	this.Init();
}; 

Popup.prototype.SetTitle = function(title)
{
	if(this.show_top == true)
	{
		this.oTitleSec.innerHTML = title;
	}
};

Popup.prototype.SetContent = function(content)
{
	if( typeof(content) == 'object' ) 
	{
		this.oContent.innerHTML = '';
		this.oContent.insertAdjacentElement("beforeEnd",content);
	}else {
		this.oContent.innerHTML = content;
	}

};

Popup.prototype.Init = function()
{
	this.oPopup = document.createElement('div');
	this.oPopup.style.display = "none";
	this.oPopup.style.position = "absolute";
	this.oPopup.style.zIndex = 100;
	this.oParent.insertAdjacentElement("beforeEnd",this.oPopup);

	this.oBodyIframe = document.createElement('iframe');
	this.oBodyIframe.frameBorder = 0;
	this.oBodyIframe.style.top = "0px";
	this.oBodyIframe.style.left = "0px";
	this.oBodyIframe.style.backgroundColor = "#FFFFFF";
	this.oBodyIframe.style.position = "absolute";
	this.oPopup.insertAdjacentElement("beforeEnd",this.oBodyIframe);

	this.oBody = document.createElement('div');
	this.oBody.style.top = "0px";
	this.oBody.style.left = "0px";
	this.oBody.style.position = "absolute";
	if(typeof HTMLElement!="undefined")
	{
		this.oBody.style.border = "2px outset #686868";
	}else {
		this.oBody.style.border = "2px outset #FFFFFF";
	}

	this.oPopup.insertAdjacentElement("beforeEnd",this.oBody);

	if(this.show_top == true)
	{
		this.MakeTopSec();
	}

	this.oContent = document.createElement('div');
	this.oBody.insertAdjacentElement("beforeEnd",this.oContent);
};

Popup.prototype.MakeTopSec = function()
{
	var oThis = this;

	var oTop = document.createElement('div');
	oTop.style.width = "100%";
	oTop.style.height = "27px";
	oTop.style.position = "relative";
	oTop.style.backgroundImage = 'url(/images/bg_popup_tit.gif)';
	oTop.attachEvent("onmousedown", function(e) { oThis.StartDrag(e); } );
	oTop.attachEvent("onselectstart", function(e) { return false; } );

	this.oBody.insertAdjacentElement("beforeEnd",oTop);

	this.oTitleSec = document.createElement('div');
	this.oTitleSec.style.border = "0px solid red";
	this.oTitleSec.style.position = "absolute";
	this.oTitleSec.style.top = "5px";
	this.oTitleSec.style.left = "10px";
	this.oTitleSec.style.fontSize = "12px";
	this.oTitleSec.style.cursor = "default";
	oTop.insertAdjacentElement("beforeEnd",this.oTitleSec);

	this.oCloseBtn = document.createElement('img');
	this.oCloseBtn.src = "/images/icon_close.gif";
	this.oCloseBtn.style.width = "12px";
	this.oCloseBtn.style.position = "absolute";
	this.oCloseBtn.style.top = "6px";
	this.oCloseBtn.style.cursor = "pointer";
	this.oCloseBtn.oPopup = this;
	this.oCloseBtn.attachEvent("onmousedown", function(e){if(e.eventPhase != null) e.stopPropagation(); else event.cancelBubble=true;} );
	this.oCloseBtn.attachEvent("onclick", function() { oThis.Hide(); } );

	//var pFunc = function(obj) { obj.Hide(); }	
	//this.AddThisEventListener(this, this.oCloseBtn, 'onclick', pFunc);

	oTop.insertAdjacentElement("beforeEnd",this.oCloseBtn);
};

Popup.prototype.AddThisEventListener = function(oThis, oTarget, event, pFunc)
{
	var pWrappedFunc = function() { pFunc.call(this,oThis); };
	oTarget.attachEvent(event, pWrappedFunc);
	
}

Popup.prototype.Show = function()
{
	this.oBody.style.width = this.width;

	this.oPopup.style.display = "block";

	this.AdjustSize();

	if(this.oParent == document.body)
	{
		if(this.top == '0px')
		{
			var oBody_height = this.oParent.scrollHeight;
			this.top = ((oBody_height/2)-(this.oBody.offsetHeight/2)) + 'px';
		}

		if(this.left == '0px')
		{
			var oBody_width = this.oParent.clientWidth;
			this.left = ((oBody_width/2)-(this.oBody.offsetWidth/2)) + 'px';
		}
	}

	this.oPopup.style.top = this.top;
	this.oPopup.style.left = this.left;

	if(this.show_top == true)
	{
		this.oCloseBtn.style.left = (this.oBody.clientWidth - this.oCloseBtn.width - 10) + "px";
	}

	this.is_show = true;
};	

Popup.prototype.AdjustSize = function()
{
	this.oBodyIframe.width = this.oBody.offsetWidth;
	this.oBodyIframe.height = this.oBody.offsetHeight;

}

Popup.prototype.Hide = function(mode)
{
	this.oPopup.style.display = "none";

	if(typeof(mode) != 'undefined')
	{
		if(mode == 1)
		{
			this.Remove();
		}
	}
	this.is_show = false;
};

Popup.prototype.Remove = function()
{
	//alert(this.oPopup.parentNode);
	this.oPopup.parentNode.removeChild(this.oPopup);
};


Popup.prototype.StartDrag = function(e)
{
	//alert(e.srcElement.innerHtml);

	//alert("START");
	//var srcObj = event.srcElement;
	//srcObj.style.filter = "alpha(opacity=80)";

	
	this.dragY = e.clientY - parseInt(this.oPopup.style.top);
	this.dragX = e.clientX - parseInt(this.oPopup.style.left);

	//document.getElementById("temp").innerText = srcObj.style.left+", "+srcObj.style.top+", "+event.clientX+", "+event.clientY+", "+event.x+", "+event.y+", "+tempY+", "+tempX;
	//srcObj.style.top = event.y;
	//srcObj.style.left = event.x;
	
	this.isDrag = true;
};

Popup.prototype.MoveDrag = function(e)
{
	if (this.isDrag == true)
	{
		this.oPopup.style.top = (e.clientY - this.dragY) + 'px';
		this.oPopup.style.left = (e.clientX - this.dragX) + 'px';					
	}
};

Popup.prototype.EndDrag = function()
{
	this.isDrag = false;
	this.dragX = 0;
	this.dragY = 0;
};

var oPopupProcessing = null;	//Ã³¸®Áß ÆË¾÷Ã¢

function ShowProcessingPopup()
{
	oPopupProcessing = new Popup(null, false);	
	
	oPopupProcessing.width = "200px";
	var content = '<div style="width:100%;height:50px;text-align:center;margin:20px auto;">Ã³¸®Áß...</div>';
	oPopupProcessing.SetContent(content);
	oPopupProcessing.Show();

}

function HideProcessingPopup()
{
	oPopupProcessing.Hide(1);

}