﻿function PhPopupWindow( width, height, top, left )
{
	this.m_iWidth	= width;
	this.m_iHeight	= height;
	this.m_iTop		= top;
	this.m_iLeft	= left;
	this.m_oParent	= null;
	
	this.ContentElement	= null;
	this.RootElement	= null;
	
	this.InitObject();
}

PhPopupWindow.prototype.InitObject = function()
{
	var container	= document.createElement( 'div' );
	var table		= new PhTable( 3, 3, 0, 0 );
	var i			= 0;
	var j			= 0;
	
	container.style.width		= this.m_iWidth+'px';
	
//	if( this.m_iHeight > 0 )
//	{
//		alert( 'hi' );
//		container.style.height	= this.m_iHeight+'px';
//	}
		
	container.style.position	= 'absolute';
	container.style.top			= this.m_iTop+'px';
	container.style.left		= this.m_iLeft+'px';
	container.style.visibility	= 'hidden';
	
	table.Cells[0][0].id					= 'popup_upper_left_corner';
	table.Cells[0][0].style.backgroundImage = 'url(system/controls/popup_window/popup_topLeftCnr.png)';
	table.Cells[0][1].id					= 'popup_top_border';
	table.Cells[0][1].style.width			= (this.m_iWidth-44)+'px';
	table.Cells[0][1].style.backgroundImage = 'url(system/controls/popup_window/popup_topRpt.png)';
	table.Cells[0][2].id					= 'popup_upper_right_corner';
	table.Cells[0][2].style.backgroundImage = 'url(system/controls/popup_window/popup_topRtCnr.png)';
	
	table.Cells[1][0].id					= 'popup_left_border';
	//table.Cells[1][0].style.height			= (this.m_iHeight-44)+'px';
	table.Cells[1][0].style.backgroundImage = 'url(system/controls/popup_window/popup_leftRpt.png)';
	
	var wrapper = document.createElement( 'div' );
	wrapper.style.width = (this.m_iWidth-44)+'px';
	//wrapper.style.height = (this.m_iHeight-44)+'px';
	wrapper.style.position = 'relative';
	
	table.Cells[1][1].id					= 'popup_center';
	table.Cells[1][1].appendChild( wrapper );
	
	table.Cells[1][2].id					= 'popup_right_border';
	//table.Cells[1][2].style.height			= (this.m_iHeight-44)+'px';
	table.Cells[1][2].style.backgroundImage = 'url(system/controls/popup_window/popup_rtRpt.png)';
	
	table.Cells[2][0].id					= 'popup_lower_left_corner';
	table.Cells[2][0].style.backgroundImage = 'url(system/controls/popup_window/popup_btmLeftCnr.png)';
	table.Cells[2][1].id					= 'popup_bottom_border';
	table.Cells[2][1].style.width			= (this.m_iWidth-44)+'px';
	table.Cells[2][1].style.backgroundImage = 'url(system/controls/popup_window/popup_btmRpt.png)';
	table.Cells[2][2].id					= 'popup_lower_right_corner';
	table.Cells[2][2].style.backgroundImage = 'url(system/controls/popup_window/popup_btmRtCnr.png)';	
	
	for( i = 0; i < 3; i++ )
	{
		for( j = 0; j < 3; j++ )
		{
			table.Cells[i][j].className = 'png';
		}
	}
	
	container.appendChild( table.Table );
	
	this.RootElement		= container;
	//this.ContentElement		= table.Cells[1][1];
	this.ContentElement		= wrapper;
}

PhPopupWindow.prototype.AttachToElement = function( parent )
{
	this.m_oParent	= (typeof( parent ) == 'string')? document.getElementById( parent ) : parent;
	
	if( this.m_oParent != null )
		this.m_oParent.appendChild( this.RootElement );
}

PhPopupWindow.prototype.SetPosition = function( top, left )
{
	this.m_iTop		= top;
	this.m_iLeft	= left;
	
	this.RootElement.style.top		= this.m_iTop+'px';
	this.RootElement.style.left	= this.m_iLeft+'px';
}

PhPopupWindow.prototype.DisplayMessage = function( msg )
{
	this.ContentElement.innerHTML = msg;
	g_oClient.CenterElementInWindow( this.RootElement );
	this.Show( 3 );
}

PhPopupWindow.prototype.Show = function( time_out )
{
	var me = this;
	
	this.RootElement.style.visibility = 'visible';
	
	if( time_out != null && time_out > 0 )
		setTimeout( function(){me.Hide();}, time_out*1000 );
}

PhPopupWindow.prototype.Hide = function()
{
	this.RootElement.style.visibility = 'hidden';
}