

function wmxPopupWindow()
{
	//Private variables
	var _handle = null;
	var _height = '';
	var _initialized = false;
	var _fullscreen = '';
	var _left = '';
	var _location = '';
	var _menubar = '';
	var _resizable = '';
	var _scrollbars = '';
	var _status = '';
	var _toolbar = '';
	var _top = '';
	var _width = '';
	var _popupIframe;
	
	//Public properties
	this.delay = 0;
	this.focus = true;
	this.hasLocation = false;
	this.hasMenubar = false;
	this.hasScrollbars = false;
	this.hasStatus = false;
	this.hasToolbar = false;
	this.height = 500;
	this.isFullscreen = false;
	this.isResizable = false;
	this.left = '';
	this.top = '';
	this.name = '';
	this.url = '';
	this.width = 660;
	this.zIndex = 1000;
	this.closeText = 'close';
	
	//Public functions
	this.initialize = function()
	{
		_fullscreen = "fullscreen=" + (this.isFullscreen ? "yes" : "no");
		_height = "height=" + this.height;
		_left = "left=" + (this.left != "" ? this.left : ((cmxdocument.scrollLeft() / 2) - (this.width / 2)));
		_location = "location=" + (this.hasLocation ? "yes" : "no");
		_menubar = "menubar=" + (this.hasMenubar ? "yes" : "no");
		_resizable = "resizable=" + (this.isResizable ? "yes" : "no");
		_scrollbars = "scrollbars=" + (this.hasScrollbars ? "yes" : "no");
		_status = "status=" + (this.hasStatus ? "yes" : "no");
		_toolbar = "toolbar=" + (this.hasToolbar ? "yes" : "no");
		_top = "top=" + (this.top != "" ? this.top : ((cmxdocument.scrollTop() / 2) - (this.height / 2)));
		_width = "width=" + this.width;
		
	};

	this.openDhtml = function()
	{
		if (this.url != '')
		{
			var _mainzIndex = (parseInt(this.zIndex) + 1);
			var _closezIndex = (parseInt(this.zIndex) - 1);
			var _closeTop = (parseInt(this.top) - 20);
			var _closeWidth = (parseInt(this.width) - 6);

			if (!_initialized)
			{
				this.initialize();
				_initialized = true;
			}

			document.write("<div id=\"pop" + this.name + "\" class=\"pop\" style=\"width: " + this.width + "px; height: " + this.height + "px; z-index: " + _mainzIndex + "; top: " +  _closeTop + "px; left: " + this.left + "px;\">");
			document.write("<div id='close_" + this.name + "' class=\"close\" style='z-index: " + _closezIndex + "; width: " +_closeWidth + "px; height: 10px' onclick='" + this.name + ".closeElements()'>" + this.closeText + "</div>");
			document.write("<div id='" + this.name + "' class=\"popup\" style='z-index: " + this.zIndex + "; width: " + this.width + "px; height: " + (this.height - 18) + "px;'><iframe src='" + this.url + "' scrolling='auto' frameborder=\"0\" style=\"width: " + this.width + "px; height: " + (this.height - 18) + "px\"></iframe></div>");
			document.write("</div>");
			_popupContainer = $("pop" + this.name);
			this.createIframe();
			this._popupIframe = $$('.wmxPopup_iframe')[0];
			this.showIframe();
		}
	};

	this.open = function()
	{
		if (!_initialized)
		{
			this.initialize();
			_initialized = true;
		}
	
		var options = new String();
		options += _fullscreen;
		options += ',' + _height;
		options += ',' + _left;
		options += ',' + _location;
		options += ',' + _menubar;
		options += ',' + _resizable;
		options += ',' + _scrollbars;
		options += ',' + _status;
		options += ',' + _toolbar;
		options += ',' + _top;
		options += ',' + _width;
		
		try
		{
			if (this.url !=	'')	
			{ 
				if	(this.delay	> 0)
				{	
					if(this.focus)						
						window.setTimeout("popUp('"+this.url+"', '"+this.name+"', '"+options+"')", this.delay * 1000);
					else
						window.setTimeout("popUnder('"+this.url+"', '"+this.name+"', '"+options+"')", this.delay * 1000);												
				}
				else
				{
					if(this.focus)
						popUp(this.url,	this.name, options); 
					else
						popUnder(this.url,	this.name, options); 					
				}
			} 
		}
		catch(e)
		{}
	};
		
	this.closeElements = function()
	{
		document.getElementById("pop" + this.name).style.display = "none";

		this.hideIframe();
	};
		
	this.createIframe = function()
	{
		var iframe = new Element('iframe', {'class': 'wmxPopup_iframe', src: 'about:blank'});
		Element.insert(_popupContainer, {'after': iframe});
		iframe.setStyle({display: 'none'});
	};
	
	this.showIframe = function()
	{
		var contentHeight = this.height - 18;
		var contentWidth = this.width;
		var contentLeft = this.left;
		var contentRight = this.right;
		var contentTop = this.top;
		var contentZIndex = this.zIndex;
		var contentBorder = "0";
		
		if (this._popupIframe)
		{
			if(contentLeft)
			{
				this._popupIframe.setStyle({
					height: contentHeight + 'px',
					width: contentWidth + 'px',
					position: 'absolute',
					left: contentLeft + 'px',
					top: contentTop + 'px',
					zIndex: contentZIndex - 5,
					display: 'block',
					border: contentBorder
				});
			}
			if(contentRight)
			{
				this._popupIframe.setStyle({
					height: contentHeight + 'px',
					width: contentWidth + 'px',
					position: 'absolute',
					right: contentRight + 'px',
					top: contentTop + 'px',
					zIndex: contentZIndex - 5,
					display: 'block',
					border: contentBorder
				});
			}
		}
	};

	this.hideIframe = function()
	{
		if(this._popupIframe)
		{
			this._popupIframe.setStyle({display: 'none'});
		}
	};
}






function popUnder(url, name, options)
{
	_handle=window.open(url, name, options, true); 
	_handle.blur();
}

function popUp(url, name, options)
{
	_handle=window.open(url, name, options, true); 
	_handle.focus();
}

var handleCenter;		
function popUpCenter(url, name, height, width, content, otherOptions)
{    
	var left, top, options;
	var screenWidth = 0;
	var screenHeight = 0;
	var tempWidth, tempHeight;

	if (cmxbrowser.supportsLayers || cmxbrowser.supportsDOM && !cmxbrowser.ie)
	{
			screenWidth = screen.availWidth/2;
			screenHeight = screen.availHeight/2;
	}
			
	if (cmxbrowser.ie)
	{
		screenWidth = screen.width/2;
		screenHeight = screen.height/2;
	}
	    
	if (width != 0)
		left = screenWidth - width/2;
	else
		left = screenWidth;
		
	if (height != 0)
		top = screenHeight - height/2;
	else
		top = screenHeight;
			
	options = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;
	
	if (otherOptions != null)
		options+= "," + otherOptions;

	if (handleCenter)
	{
	    if(!handleCenter.closed)
	    {
	        handleCenter.window.close();
	    }
	}
    
        handleCenter = window.open(url, name, options, true);
     

    if(content != null)
    {
		handleCenter.document.open();
		handleCenter.document.write(content);
		handleCenter.document.close();
	}
    if (handleCenter != null)
	    handleCenter.focus();
}

