/*
$Id: 
Copyright(C) 1996-2005 INCREMENT P CORP.
*/
function CPopup( oDoc, oLayer, oContents )
{
	var oOwner = this;
	this.zIndexBase	= 25;
	this.xOffset = 85;

	function CancelEvent( e )
	{
		var	oEvent = CMN_GetEvent( this.ownerDocument, e );
		
		
		CMN_PreventDefault( oEvent );
	}

	
	var fCreateImage = function( strSrc )
	{
		var o = oDoc.createElement( "img" );
		o.style.position	= "absolute";
		o.style.zIndex		= oOwner.zIndexBase; 
		o.src			= strSrc;
		o.onclick		= function(e)
		{
			var oEvent = CMN_GetEvent( this.ownerDocument, e );
			CMN_PreventDefault( oEvent );
			if( oOwner.OnClickContent )
			{
				oOwner.OnClickContent();
			}
		}
		o.onmousedown		= CancelEvent;
		return	o;
	}

	
	

	
	this.Draw = function( nCenterX, nCenterY )
	{
	
		var nTextWidth	= this.oContents.offsetWidth;
		var nTextHeight	= this.oContents.offsetHeight;
		var nBoxLeft	= nCenterX - this.xOffset;
		var nBoxTop 	= nCenterY - 30 + 1 - nTextHeight - 8 - 8 + 2;
		
		this.oContents.style.left	= nBoxLeft + 8;
		this.oContents.style.top	= nBoxTop  + 8;
		this.oContents.style.zIndex	= this.zIndexBase; 
		
		this.oTL.style.left	= nBoxLeft;
		this.oTL.style.top	= nBoxTop;
		this.oTL.style.zIndex	= this.zIndexBase; 
		
		this.oTM.style.left	= nBoxLeft + 8;
		this.oTM.style.top	= nBoxTop ;
		this.oTM.style.width	= nTextWidth;
		this.oTM.style.height	= 8;
		this.oTM.style.zIndex	= this.zIndexBase; 
		
		this.oTR.style.left	= nBoxLeft + 8 + nTextWidth;
		this.oTR.style.top	= nBoxTop;
		this.oTR.style.zIndex	= this.zIndexBase; 
		
		this.oCL.style.left	= nBoxLeft;
		this.oCL.style.top	= nBoxTop + 8;
		this.oCL.style.width	= 8;
		this.oCL.style.height	= nTextHeight;
		this.oCL.style.zIndex	= this.zIndexBase; 
		
		this.oCR.style.left	= nBoxLeft + 8 + nTextWidth;
		this.oCR.style.top	= nBoxTop + 8;
		this.oCR.style.width	= 8;
		this.oCR.style.height	= nTextHeight;
		this.oCR.style.zIndex	= this.zIndexBase; 
		
		this.oBL.style.left	= nBoxLeft;
		this.oBL.style.top	= nBoxTop + 8 + nTextHeight;
		this.oBL.style.zIndex	= this.zIndexBase; 
		
		this.oBM.style.left	= nBoxLeft + 8;
		this.oBM.style.top	= nBoxTop + 8 + nTextHeight;
		this.oBM.style.width	= nTextWidth;
		this.oBM.style.height	= 8;
		this.oBM.style.zIndex	= this.zIndexBase; 
		
		this.oBR.style.left	= nBoxLeft + 8 + nTextWidth;
		this.oBR.style.top	= nBoxTop + 8 + nTextHeight;
		this.oBR.style.zIndex	= this.zIndexBase; 
		
		this.oHK.style.left	= nCenterX;
		this.oHK.style.top	= nCenterY - 30;
		this.oHK.style.zIndex	= this.zIndexBase + 1; 
		
		this.oBtn.style.left	= nBoxLeft + 8 + nTextWidth - 20;
		this.oBtn.style.top	= nBoxTop + 8;
		this.oBtn.style.zIndex	= this.zIndexBase + 1;
	}

	this.Remove = function()
	{
		oLayer.removeChild( this.oTL );
		oLayer.removeChild( this.oTM );
		oLayer.removeChild( this.oTR );
		oLayer.removeChild( this.oCL );
		oLayer.removeChild( this.oCR );
		oLayer.removeChild( this.oBL );
		oLayer.removeChild( this.oBM );
		oLayer.removeChild( this.oHK );
		oLayer.removeChild( this.oBR );
		oLayer.removeChild( this.oContents );
		oLayer.removeChild( this.oBtn );
	}

	this.GetRect = function( nCenterX, nCenterY )
	{
	
		var nTextWidth	= this.oContents.offsetWidth;
		var nTextHeight	= this.oContents.offsetHeight;
		var oRet = new Object();
		oRet.Left	= nCenterX - this.xOffset;
		oRet.Top 	= nCenterY - 30 + 1 - nTextHeight - 8 - 8;
		oRet.Bottom	= nCenterY;
		oRet.Right 	= oRet.Left + 8 + nTextWidth + 8;
		return	oRet;
	}

	oContents.style.position	= "absolute";
	oContents.style.zIndex		= 40;
	oContents.style.backgroundColor	= "white";
	oContents.onclick		= function(e)
	{
		var oEvent = CMN_GetEvent( this.ownerDocument, e );
		CMN_PreventDefault( oEvent );
		if( oOwner.OnClickContent )
		{
			oOwner.OnClickContent();
		}
	}
	oContents.onmousedown		= CancelEvent;
	oContents.style.overflow	= "hidden";

	var strRootPath = "parts/";
	this.oTL	= fCreateImage( strRootPath + "tl.gif" );
	this.oTM	= fCreateImage( strRootPath + "tm.gif" );
	this.oTR	= fCreateImage( strRootPath + "tr.gif" );
	this.oCL	= fCreateImage( strRootPath + "cl.gif" );
	this.oCR	= fCreateImage( strRootPath + "cr.gif" );
	this.oBL	= fCreateImage( strRootPath + "bl.gif" );
	this.oBM	= fCreateImage( strRootPath + "bm.gif" );
	this.oHK	= fCreateImage( strRootPath + "hk1.gif" );
	this.oBR	= fCreateImage( strRootPath + "br.gif" );
	this.oBtn	= CreateButton(	oDoc,
					strRootPath + "btu.gif",
					strRootPath + "btd.gif" );
	this.oContents	= oContents;

	oLayer.appendChild( this.oTL );
	oLayer.appendChild( this.oTM );
	oLayer.appendChild( this.oTR );
	oLayer.appendChild( this.oCL );
	oLayer.appendChild( this.oCR );
	oLayer.appendChild( this.oBL );
	oLayer.appendChild( this.oBM );
	oLayer.appendChild( this.oHK );
	oLayer.appendChild( this.oBR );
	oLayer.appendChild( this.oBtn );
	oLayer.appendChild( this.oContents );

	
	this.OnClosePopup = null;
	this.OnClickContent = null;

	
	this.oBtn.OnClickButton = function()
	{
		
		
		
		if(	oOwner.OnClosePopup != null && 
			oOwner.OnClosePopup() === false )
		{
			
			return;
		}
		oOwner.Remove();
	}
	
	this.Draw( -1024, -1024 );
	return	this;
}

