function ToggleSmallPopup(popup_id)
{
    $('.small_popup:not(#' + popup_id + '_content)').removeClass('small_popup_visible');
    $('.small_popup_link:not(#' + popup_id + '_link)').removeClass('small_popup_link_selected');
	$('#' + popup_id + '_content').toggleClass('small_popup_visible');
	$('#' + popup_id + '_link').toggleClass('small_popup_link_selected');
}

function CloseSmallPopup(popup_id)
{
	$('#' + popup_id + '_content').removeClass('small_popup_visible');
	$('#' + popup_id + '_link').removeClass('small_popup_link_selected');
}


var PopupWindow = new function()
{

	this._WindowID = -1;
	this._WindowIDPrefix = 'windowdiv';

	this._CreateWindowDIV = function ()
	{
        var obj = document.createElement('div');
		this._WindowID++;
        obj.id = this._WindowIDPrefix + this._WindowID;
        document.body.appendChild(obj);
		return obj;
	}
	
	this._DestroyWindowDIVByID = function(id)
	{
		var obj = document.getElementById(this._WindowIDPrefix + id);

		if (obj)
		{
			obj.parentNode.removeChild(obj);
		}
		if (id == this._WindowID) this._WindowID--;
		
	}
	
	this._DestroyWindowDIV = function(obj)
	{
		obj.parentNode.removeChild(obj);
		if (obj.id == (this._WindowIDPrefix + this._WindowID)) this._WindowID--;
	}

	this.CloseAll = function ()
	{
		var result = true;
		
		while (this._WindowID >= 0)
		{
			if (!this.CloseLast())
				result = false;
		}
		
		return result;
	}
	
	this.CloseLast = function ()
	{
		this.Close(this._WindowID);
	}

	this.Close = function (id)
	{
		var jqobj = $('#' + this._WindowIDPrefix + id);
	
		if (jqobj)
		{
			jqobj.dialog('close');
			return true;
		}
		else return false;
	}
	

	this.Open = function (url, title, width, height, waitmsg, formid, nooverlay)
	{

		this.CloseLast();

		if (this._WindowID >= 0) nooverlay = true;
		var obj = this._CreateWindowDIV();
	
		var jqobj = $('#' + obj.id);
	
		jqobj.css('margin', '0px'); // IE7 Debug
		jqobj.attr('innerHTML', waitmsg);
		
		var options =  {
					modal: true,
					draggable: false,
					resizable: false,
					overlay: { 
						opacity: 0.84,
						background: "#27231F"					
					},
					position: ['', 100],
					dialogClass: 'flora',
					title: title,
					close: function() { PopupWindow._DestroyWindowDIV(obj); }
			}

		if (width) options.width = width;
		if (height) options.height = height;
		if (!nooverlay) options.overlay = { opacity: 0.8, backgroundColor: 'black' };
	
		jqobj.dialog( options );
		jqobj.data("resizable.dialog", false);
		
		GetURL(url, jqobj, document.getElementById(formid) );
	
	}

}