// $Revision: 12580 $

/*//
 * Copyright (C) 2006-2008 Palcev Anton Gennadievich
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
*/
var POPUP_IMAGES = '/static/js/windows/images/';
var POPUP_IMAGES_PATH = PopupConfig.SkinPath + 'images/';
var POPUP_SPACER_PATH = POPUP_IMAGES + 'spacer.gif';

Functions.AppendStyleSheet(document, PopupConfig.SkinPath + 'css.css');
if (IECleanup) IECleanup.AddItem(null, function(){
	Functions.RemoveEventListener(window, 'resize', PopupWindow.OnChangeSize);
	Functions.RemoveEventListener(window, 'scroll', PopupWindow.OnChangeSize);
	Functions.RemoveEventListener(document, 'mousedown', PopupWindow.CheckFocus, true);
})
function PopupWindowInit (){
	PopupWindow.WinSize = Functions.CheckWindowSize();
	Functions.AddEventListener(window, 'resize', PopupWindow.OnChangeSize);
	Functions.AddEventListener(window, 'scroll', PopupWindow.OnChangeSize);
	Functions.AddEventListener(document, 'mousedown', PopupWindow.CheckFocus, true);
	PopupWindow.DefaultTitle = document.title;
	Functions.SetInterval(PopupWindow.ChangeTitleByInterval, PopupWindow.TitleRefreshInterval, PopupWindow);
	PopupWindow.ChangeTitleByInterval();
	PopupWindow.LoadingIsComplete = true;
}
Functions.AddEventListener(window, 'load', PopupWindowInit);
var PopupWindow = new ItemsProcessor();
Object.Extend(PopupWindow, {
	SMSCount : 0,
	TitleRefreshInterval : 700, /* ms */
	ZIndex : PopupConfig.ZIndex,
	Create : function(name, title, resizable, effect, enableExtraMenu){
		if (name && this.GetItem(name)) return this.GetItem(name);
		var A = new TOXPanel(name, title, resizable, effect, enableExtraMenu);
		A.Create();
		this.AddItem(A.Name, A);
		return A;
	},
	ChangeTitleByInterval : function(){
		if (this.SMSCount != 0)
			document.title = document.title == this.DefaultTitle ? (this.SMSCount + (this.SMSCount == 1 ? ' новое сообщение' : ' новых сообщений')) : this.DefaultTitle;
		else
			document.title = this.DefaultTitle;
	},
	OnChangeSize : function(){
		PopupWindow.WinSize = Functions.CheckWindowSize();
		if (this.Count != 0){
			for (var i in PopupWindow.Items){
				var obj = PopupWindow.Items[i];
				if (!obj) continue;
				var Offset = Functions.GetElementPosition(obj.Table); 
				var Coor = Functions.CheckCoordsAndGetIt(obj.Table, Offset.X, Offset.Y, PopupWindow.WinSize.X, PopupWindow.WinSize.Y);
				Functions.SetPosition(obj.Table, Coor.X, Coor.Y);
			}
		}
	},
	CheckFocus : function(e){
		if (this.Count != 0){
			var Name;
			e = e || event;
			if (typeof e != 'string'){
				var src = e.srcElement || e.target || e;
				var Table = Functions.MoveToAncestorNode(src, 'TABLE');
				if (Table)
					Name = Table.getAttribute('name', 0);
			}
			else Name = e;
			for (var i in PopupWindow.Items){
				var O = PopupWindow.Items[i];
				if (!O) continue;
				if (!Name || O.Name != Name){
					if (Name) O.Blur();
				}
				else O.Focus();
			}
		}
	},
	OrderAllWindows : function(){
		if (this.Count == 0) return;
		var ItemFocused, LastValidItem;
		var Calc = new PopupWindow._CalcObject();
		for (var i in PopupWindow.Items){
			var Item;
			if (!(Item = PopupWindow.Items[i])) continue;
			if (Item._IsFocused){
				ItemFocused = Item;
				continue;
			}
			LastValidItem = Item;
			Item.Blur();
			Item.Table.style.zIndex = Item._IFrame.style.zIndex = PopupWindow.ZIndex;
			Calc.Run(Item.Table);
		}
		if (ItemFocused)
			Calc.Run(ItemFocused.Table);
		else if (LastValidItem)
			LastValidItem.Focus();
	},
	_CalcObject : function(){
		this.StepX = PopupConfig.OrderSlider.StepX;
		this.StepY = PopupConfig.OrderSlider.StepY;
		this.CurX = 0;
		this.CurY = 0;
		this.OffsetY = 0;
		this.Scroll = Functions.GetScrollPosition(window);
		this.Run = function (elem){
			if (this.CurX > (PopupWindow.WinSize.X-elem.offsetWidth)){
				this.CurX = 0;
				this.OffsetY += this.StepY;
				this.CurY = this.OffsetY;
			}
			if (this.CurY > (PopupWindow.WinSize.Y-elem.offsetHeight)){
				this.OffsetY += this.StepY;
				this.CurX = 0;
				this.CurY = this.OffsetY;
			}
			if (this.OffsetY > (PopupWindow.WinSize.Y-elem.offsetHeight)) this.OffsetY = 0;
			Functions.RunFunction(function(Table, CurX, CurY){
				var E = PopupConfig.OrderSlider;
				if (E.Enabled)
					(new Effects.Slider(E.Pixels, E.Time, E.Porog)).Apply(Table, CurX, CurY);
				else
					Functions.SetPosition(Table, CurX, CurY);
			}, null, [elem, this.CurX + this.Scroll.X, this.CurY + this.Scroll.Y]);
			this.CurX += this.StepX;
			this.CurY += this.StepY;
		}
	}
});
var PopupEffect = new ItemsProcessor();
if (IECleanup) IECleanup.AddItem(null, function(){PopupEffect = null;})
PopupEffect.ExceptionList = {FullSlide : 1};
PopupEffect.LoadedUserEffects = {};
PopupEffect.RegisterUserEffect = function(name, obj, E){
	this.LoadedUserEffects[name] = obj;
	if (E) this.ExceptionList[name] = true;
}
PopupEffect.GetEffect = function(name){
	var B = this.GetItem[name];
	if (B && !this.ExceptionList[name]) return B;
	if (!(B = PopupEffect.LoadedUserEffects[name]))
		switch (name){
			case 'FullSlide' 	 : B = new FullSlide(name, PopupConfig.Effects.FullSlide);break;
			default 			 : B = new CustomPopupEffect(name);break;
		}
	this.AddItem(name, B);
	return B;
}
var FullSlide = Class.Create();
FullSlide.prototype  = {
	Constructor : function(name, params){
		this.Name = name;
		this.Down = params.Down.Enabled;
		this.SpeedDown = params.Down.Time;
		this.IndexDown = params.Down.Pixels;
		this.Up = params.Up.Enabled;
		this.SpeedUp = params.Up.Time;
		this.IndexUp = params.Up.Pixels;
		this.TimeOnCompleteEffect = 0;
	},
	Apply : function(elem, state){
		this.Element = elem;
		this.State = state;
		if (this.Interval) window.clearInterval(this.Interval);
		this.OffsetHeight = this.OffsetHeight || this.Element.offsetHeight;
		if (!this.Height || this.Height < 0 || this.Height > this.OffsetHeight) this.Height = (this.State ? 1 : this.OffsetHeight);
		this.PrevInterval = this.Interval;
		if (this.State){
			if (this.Down){
				this.Index = this.IndexDown;
				this.Interval = Functions.SetInterval(this.SetHeight, this.SpeedDown, this);
				var I = this.Interval - this.PrevInterval;
				if (this.PrevInterval && this.SpeedDown < I) this.SpeedDown = I;
			}
			else
				this.Element.style.height = this.Height = this.OffsetHeight;
		}
		else{
			if (this.Up){
				this.Index = -1*this.IndexUp;
				this.Interval = Functions.SetInterval(this.SetHeight, this.SpeedUp, this);
				var I = this.Interval - this.PrevInterval;
				if (this.PrevInterval && this.SpeedUp < I) this.SpeedUp = I;
			}
			else
				this.Element.style.height = this.Height = this.OffsetHeight;
		}
	},
	SetHeight : function(){
		if (this.Height >= this.OffsetHeight) this.Height = this.OffsetHeight;
		if (this.State && this.MainDivOffset.Y && (this.MainDivOffset.Y + this.Height + this.Panel.BottomTd.offsetHeight + this.Panel.BottomShade.offsetHeight) > PopupWindow.WinSize.Y){
			this.Panel.Table.style.top =  PopupWindow.WinSize.Y - (this.Height + this.Panel.BottomTd.offsetHeight + this.Panel.BottomShade.offsetHeight + this.Panel.TopTd.offsetHeight) + 'px';
		}
		if ((this.State && this.Height >= this.OffsetHeight) || this.Height < 1){
			if (this.State)
				this.Element.style.height = this.OffsetHeight;
			else
				this.Element.style.height = 1 + 'px';
			window.clearInterval(this.Interval);
			return;
		}
		else{
			this.Element.style.height = this.Height + 'px';
		}
		this.Height += this.Index;
	}
}
var CustomPopupEffect = Class.Create();
CustomPopupEffect.prototype  = {
	Constructor : function(name){
		this.Name = name;
	},
	Apply : function(elem, state){
		this.OffsetHeight = this.OffsetHeight || this.Element.offsetHeight;
		elem.style.height = (state ? this.OffsetHeight : 1);
	}
}
PopupWindow.PreloadIsComplete = true;
var PopupIcon = Class.Create();
PopupIcon.prototype = {
	Constructor : function(icon){this.Path = icon;},
	CreateIconElement : function(Document){
		Document = Document || document;
		var thisElem = Document.createElement('DIV');
		var I = Document.createElement('IMG');
		this.IMG = thisElem.appendChild(I);
		this.IMG.src = this.Path ? this.Path : POPUP_SPACER_PATH;
		thisElem.className = 'MN_IMG_Div';
		return thisElem;
	},
	PutSRC : function(src){this.IMG.src = src}
}
var PopupTopMenu = function(){};
Object.Extend(PopupTopMenu.prototype, {
	Create : function (E){
		E.vAlign = 'top';
		E.className = 'TopTd';
		E.style.background = 'url('+POPUP_IMAGES_PATH+'top1.gif?1) bottom repeat-x';
		Functions.DisableSelection(E);
		E.oncontextmenu = Functions.CancelEvent;
		var T = document.createElement('TABLE');
		this.Table = E.appendChild(T);
		this.Table.cellPadding = 0;
		this.Table.cellSpacing = 0;
		this.Table.width = 100 + '%';
		var Row = this.Table.insertRow(-1);
		this.BaseTd = Row.insertCell(-1);
		this.BaseTd.noWrap = 'nowrap';
		this.BaseTd.style.background = 'transparent';
		this.BaseTd.style.width = 100+'%';
		this.BaseTd.style.overflow = 'hidden';
		this.BaseTd.style.height = 20+'px';
		var _D = document.createElement('TABLE');
		with (_D) width = 1, height = 1;
		this.TitleDiv = this.BaseTd.appendChild(_D);
		_D = _D.insertRow(-1).insertCell(-1);
		_D.innerHTML = this.Panel.Title;
		_D.noWrap = 'nowrap';
		_D.className = 'TB_Title';
		Functions.AddEventListenerEx(this.BaseTd, 'mousedown', this.OnMouseDown, this.Panel);
		if (this.Panel.EnableExtraMenu){
			Functions.AddEventListenerEx(this.BaseTd, 'dblclick', this.OnDblClick, this.Panel);
			this.Minimize = new TButtonUI(POPUP_IMAGES_PATH + 'minimize');
			this.Minimize.OnClick = Functions.CreateEventListener(function(obj){Functions.RunFunction(obj.Minimize, obj)}, this.Panel);
			this.Minimize.ChangeState(1);
			this.Minimize.Create(Row.insertCell(-1));
			this.Optimize = new TButtonUI(POPUP_IMAGES_PATH + 'optimize');
			this.Optimize.OnClick = Functions.CreateEventListener(function(obj){Functions.RunFunction(obj.Optimize, obj)}, this.Panel);
			this.Optimize.ChangeState(0, true);
			this.Optimize.Create(Row.insertCell(-1));
		}
		this.Order = new TButtonUI(POPUP_IMAGES_PATH + 'order2');
		this.Order.OnClick = PopupWindow.OrderAllWindows;
		this.Order.ChangeState(1);
		this.Order.Create(Row.insertCell(-1));
		this.Close = new TButtonUI(POPUP_IMAGES_PATH + 'close2');
		this.Close.OnClick = Functions.CreateEventListener(function(obj){Functions.RunFunction(obj[PopupConfig.OnCloseClick] || obj.Close, obj)}, this.Panel);
		this.Close.ChangeState(1);
		this.Close.Create(Row.insertCell(-1));
	},
	OnDblClick : function(e, A){
		if (A.Minimized)
			A.Optimize();
		else
			A.Minimize();
	},
	OnMouseDown : function(e, A){
		PopupWindow.Object = A;
		var Coords = Functions.GetElementPosition(A.Table);
		A.Left = Functions.GMP(e).X - Coords.X;
		A.Top = Functions.GMP(e).Y - Coords.Y;
		if (ThisBrowser.IsIE || ThisBrowser.IsOpera) PopupWindow.CheckFocus(A.Name);
		if (document.body.setCapture) document.body.setCapture();
		Functions.AddEventListener(document, 'mouseup', A.TopMenu.OnMouseUp);
		Functions.AddEventListener(document, 'mousemove', A.TopMenu.OnMouseMove);
		Functions.CancelEvent(e);
	},
	OnMouseMove : function(e){
		var A = PopupWindow.Object;
		if (A){
			var Coor = Functions.CheckCoordsAndGetIt(A.Table, Functions.GMP(e).X - A.Left, Functions.GMP(e).Y - A.Top, PopupWindow.WinSize.X, PopupWindow.WinSize.Y, PopupConfig.Glue);
		 	Functions.SetPosition(A.Table, Coor.X, Coor.Y);
		}
		Functions.CancelEvent(e);
	},
	OnMouseUp : function(e){
		var A = PopupWindow.Object;
		if (A){
			if (document.body.releaseCapture) document.body.releaseCapture();
			Functions.RemoveEventListener(document, 'mousemove', A.TopMenu.OnMouseMove);
			Functions.RemoveEventListener(document, 'mouseup', A.TopMenu.OnMouseUp);
		 	A = null;
		}
		Functions.CancelEvent(e);
	}
});
var PopupBottomMenu = function(){};
PopupBottomMenu.prototype.Create = function(E){
	E.className = 'BottomTd';
	E.style.background = 'url('+POPUP_IMAGES_PATH+'bottom.gif) bottom repeat-x';
	if (this.Panel.IsResizable){
		Object.Extend(PopupBottomMenu.prototype, {
			OnMouseDown : function(e, A){
				PopupWindow.Object = A;
				A.CoordsDiv = Functions.GetElementPosition(A.MainDiv);
				A.W = Functions.GMP(e).X - A.MainDiv.offsetWidth;
				A.H = Functions.GMP(e).Y - A.MainDiv.offsetHeight;
				if (ThisBrowser.IsIE || ThisBrowser.IsOpera) PopupWindow.CheckFocus(A.Name);
				if (document.body.setCapture) document.body.setCapture();
				Functions.AddEventListener(document, 'mouseup', A.BottomMenu.OnMouseUp);
				Functions.AddEventListener(document, 'mousemove', A.BottomMenu.OnMouseMove);
				Functions.CancelEvent(e);
			},
			OnMouseMove : function(e){
				var A = PopupWindow.Object;
				if (A){
					var W =  Functions.GMP(e).X - A.W;
					var H = Functions.GMP(e).Y - A.H;
					if (W < A.MinWidth) W = A.MinWidth;
					if (H < 1) H = 1;
					if ((H + A.CoordsDiv.Y + A.BottomTd.offsetHeight + A.BottomShade.offsetHeight) <= PopupWindow.WinSize.Y) A.MainDiv.style.height = H + 'px';
					if ((W + A.CoordsDiv.X) <= (PopupWindow.WinSize.X - A.RightBorder.offsetWidth - A.RightShade.offsetWidth)) A.MainDiv.style.width = W + 'px';
				}
				Functions.CancelEvent(e);
			},
			OnMouseUp : function(e){
				var A = PopupWindow.Object;
				if (A){
					if (document.body.releaseCapture) document.body.releaseCapture();
					Functions.RemoveEventListener(document, 'mousemove', A.BottomMenu.OnMouseMove);
					A.Optimize.apply(A, [true]);
					A.Effect.OffsetHeight = A.MainDiv.offsetHeight;
					Functions.RemoveEventListener(document, 'mouseup', A.BottomMenu.OnMouseUp);
					A = null;
				}
				Functions.CancelEvent(e);
			}
		});
		var MainElement = document.createElement('DIV');
		var IMG = new PopupIcon(POPUP_IMAGES_PATH + 'resize.gif');
		var I = IMG.CreateIconElement();
		MainElement.appendChild(I);
		MainElement.onmouseover = function(){this.style.cursor = 'nw-resize'};
		Functions.AddEventListenerEx(MainElement, 'mousedown', this.OnMouseDown, this.Panel);
		E.appendChild(MainElement);
	}
}
var TButtonUI = Class.Create();
TButtonUI.prototype = {
	Constructor : function (path){
		this.Path = path;
		this.MainElement = document.createElement('DIV');
		this.IMG = new PopupIcon(this.Path + '.gif');
		var I = this.IMG.CreateIconElement();
		this.MainElement.appendChild(I);
	},
	Create : function (E){
		E.appendChild(this.MainElement);
	},
	ChangeState : function(state, B){
		this.MainElement.style.zIndex = PopupWindow.ZIndex;
		if (this.State == state) return;
		switch (parseInt(state, 10)){
			case 0:
				if (!B) this.IMG.PutSRC(this.Path + '.gif')
				this.MainElement.className 	 = 'TB_Button_Off';
				this.MainElement.onmouseover = function(){this.className = 'TB_Button_Off'};
				this.MainElement.onmouseout  = function(){this.className = 'TB_Button_Off'};
				this.MainElement.onclick = Functions.CancelEvent;
			break;
			case 1:
				this.MainElement.className 	 = 'TB_Button_On';
				this.MainElement.onmouseover = Functions.CreateEventListener(function (){
																		var A = $A(arguments).pop()
																		this.className = 'TB_Button_On_Over';
																		A.IMG.PutSRC(A.Path + '_over.gif');
																	}, [this]);
				this.MainElement.onmouseout = Functions.CreateEventListener(function (){
																		var A = $A(arguments).pop()
																		this.className = 'TB_Button_On';
																		A.IMG.PutSRC(A.Path + '.gif');
																	}, [this]);
				this.MainElement.onclick = Functions.CreateEventListener(function (e){
																		var A = $A(arguments).pop()
																		if (A.OnClick)
																			Functions.RunFunction(A.OnClick, A);
																		else
																			Functions.CancelEvent(e);
																	}, [this]);
			break;
		}
		this.State = state;
	}
}
var TOXPanel = Class.Create(); 
TOXPanel.prototype = {
	Constructor : function(name, title, resizable, effect, enableExtraMenu){
		this.Name = 'tox_windows_' + (name || Math.floor(Math.random()*10000));
		this.Title = title || '';
		this.IsResizable = typeof resizable == 'undefined' ? PopupConfig.Resizable : resizable;
		this.Effect = PopupEffect.GetEffect(effect || PopupConfig.DefaultEffect);
		this.EnableExtraMenu = enableExtraMenu || PopupConfig.EnableExtraMenu;
	},
	Create : function(){
		if (typeof IECleanup != 'undefined')
			IECleanup.AddItem(this, function(){
				this.Effect = null;
				this.TopMenu = null;
				this.BottomMenu = null;
			});
		this.Table = document.createElement('TABLE');
		this.Table.setAttribute('name', this.Name, 0);	// Mozilla Bug
		this.Table.style.visibility = 'hidden';
		this.Table.className = 'PopupTable';
		this.Table.cellSpacing = 0;
		this.Table.cellPadding = 0;
		this.Table.style.zIndex = PopupConfig.ZIndex;
		document.body.appendChild(this.Table);
		var Tr = this.Table.insertRow(-1);
		var Td = Tr.insertCell(-1);
		Td.className = 'LeftTopShade';
		Td.style.background = ThisBrowser.IsIE?'none':'url("'+POPUP_IMAGES_PATH+'l_shade.png") top right no-repeat';
		Td.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+POPUP_IMAGES_PATH+'l_shade.png")';
		Td = Tr.insertCell(-1);
		Td.rowSpan = 3;
		Td.className = 'Border';
		Td.innerHTML = '<img src="'+POPUP_SPACER_PATH+'">';
		this.TopTd = Tr.insertCell(-1);
		this.TopMenu = new PopupTopMenu();
		this.TopMenu.Panel = this;
		this.TopMenu.Create(this.TopTd);
		this.RightBorder = Tr.insertCell(-1);
		this.RightBorder.rowSpan = 3;
		this.RightBorder.className = 'Border';
		this.RightBorder.innerHTML = '<img src="'+POPUP_SPACER_PATH+'">';
		this.RightShade = Tr.insertCell(-1);
		this.RightShade.className = 'RightTopShade';
		this.RightShade.style.background = ThisBrowser.IsIE?'none':'url("'+POPUP_IMAGES_PATH+'r_shade.png") top left no-repeat';
		this.RightShade.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+POPUP_IMAGES_PATH+'r_shade.png")';
		this.MainRow = this.Table.insertRow(-1);
		Td = this.MainRow.insertCell(-1);
		Td.rowSpan = 2;
		Td.className = 'LeftShadeRepeat';
		Td.style.background = ThisBrowser.IsIE?'none':'url("'+POPUP_IMAGES_PATH+'l_shade_repeat.png") top left repeat-y';
		Td.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+POPUP_IMAGES_PATH+'l_shade_repeat.png",sizingMethod="scale")';
		var MainTd = this.MainRow.insertCell(-1);
		var _D = document.createElement('DIV');
		this.MainDiv = MainTd.appendChild(_D);
		this.MainDiv.className = 'MainDiv';
		MainTd.vAlign = 'top';
		var Table = document.createElement('TABLE');
		if (!ThisBrowser.IsIE7 && ThisBrowser.IsIE) this.MainDiv.innerHTML = '<!--[if lte IE 6.5]><iframe id="TB_Iframe" style="width:'+this.Table.offsetWidth+'px;height:'+this.Table.offsetHeight+'px"></iframe><![endif]-->';
		this.MainDiv.appendChild(Table);
		Table.cellSpacing = 0;
		Table.cellPadding = 0;
		Table.width = 100 + '%';
		Td = Table.insertRow(-1).insertCell(-1);
		Td.className = 'PaddingTopTD';
		Td.innerHTML = '&nbsp;';
		Td = Table.insertRow(-1).insertCell(-1);
		this._IFrame = document.createElement('IFRAME');
		Td.appendChild(this._IFrame);
		this._IFrame.src = 'javascript:void(0)';
		this._IFrame.frameBorder = 'no';
		this._IFrame.scrolling = 'auto';
		this._IFrame.width = 410 + 'px';
		this._IFrame.height = 230 + 'px';
		this._IFrame.style.zIndex = PopupWindow.ZIndex;
		Td = this.MainRow.insertCell(-1);
		Td.rowSpan = 2;
		Td.className = 'RightShadeRepeat';
		Td.style.background = ThisBrowser.IsIE?'none':'url("'+POPUP_IMAGES_PATH+'r_shade_repeat.png") top right repeat-y';
		Td.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+POPUP_IMAGES_PATH+'r_shade_repeat.png",sizingMethod="scale")';
		var Row = this.Table.insertRow(-1);
		this.BottomTd = Row.insertCell(-1);
		this.BottomMenu = new PopupBottomMenu();
		this.BottomMenu.Panel = this;
		this.BottomMenu.Create(this.BottomTd);
		Row = this.Table.insertRow(-1);
		this.BottomShade = Row.insertCell(-1);
		this.BottomShade.style.backgroundColor = 'transparent';
		this.BottomShade.colSpan = 5;
		var Table = this.BottomShade.appendChild(document.createElement('TABLE'));
		with (Table) width = 100 + '%', cellPadding = 0, cellSpacing = 0;
		Tr = Table.insertRow(-1);
		Td = Tr.insertCell(-1);
		with (Td) innerHTML = '<img class="LeftBottomShade" src="'+POPUP_SPACER_PATH+'">', style.background = ThisBrowser.IsIE?'none':'url(\''+POPUP_IMAGES_PATH+'lb_shade.png\') top right no-repeat', style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+POPUP_IMAGES_PATH+'lb_shade.png\')';
		Td = Tr.insertCell(-1);
		with (Td) innerHTML = '&nbsp;', width = 100+'%', className = 'BottomShade', style.background = ThisBrowser.IsIE?'none':'url(\''+POPUP_IMAGES_PATH+'b_shade.png\') top left repeat-x', style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+POPUP_IMAGES_PATH+'b_shade.png\',sizingMethod=\'scale\')';
		Td = Tr.insertCell(-1);
		with (Td) innerHTML = '<img class="RightBottomShade" src="'+POPUP_SPACER_PATH+'">', style.background = ThisBrowser.IsIE?'none':'url(\''+POPUP_IMAGES_PATH+'rb_shade.png\') top right no-repeat', style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+POPUP_IMAGES_PATH+'rb_shade.png\')';
	},
	Show : function (x, y, width, height){
		Functions.RunFunction(PopupWindow.CheckFocus, this, this.Name);
		this.Effect.Panel = this;
		this.MinWidth = this.TopMenu.Table.offsetWidth - this.TopMenu.BaseTd.offsetWidth + this.TopMenu.TitleDiv.offsetWidth;
		this.MainDiv.style.height = height || PopupConfig.Height || '';
		this.MainDiv.style.width = (width ? (width < this.MinWidth ? this.MinWidth : width) : PopupConfig.Width) || '';
		if (!PopupWindow.LoadingIsComplete) PopupWindowInit();
		x = x || x == 0 ? x : Math.round((PopupWindow.WinSize.X - this.Table.offsetWidth)/2);
		y = y || y == 0 ? y : Math.round((PopupWindow.WinSize.Y - this.Table.offsetHeight)/2);
		var Coor = Functions.CheckCoordsAndGetIt(this.Table, x, y, PopupWindow.WinSize.X, PopupWindow.WinSize.Y);
		Functions.SetPosition(this.Table, Coor.X, Coor.Y);
		this._IsOpened = true;
		this.Table.style.visibility = 'visible';
		if (this.OnShow) Functions.RunFunction(this.OnShow, this);
	},
	Close : function(){
		if (this._IsOpened){
			if (this.Table) this.Table.style.display = 'none';
			PopupWindow.RemoveItem(this.Name);
			if (this.OnClose) Functions.RunFunction(this.OnClose, this);
			this._IsOpened = false;
		}
	},
	Hide : function(){
		if (this._IsOpened){
			this.Table.style.visibility = 'hidden';
			if (this.OnHide) Functions.RunFunction(this.OnHide, this);
			this._IsOpened = false;
		}
	}, 
	Focus : function(){
		if (!this._IsFocused){
			this.Table.style.zIndex = this._IFrame.style.zIndex = PopupWindow.ZIndex + 10;
			PopupWindow.ZIndex++;
			Functions.SetOpacity(this.Table, 99.999);
			if (this.OnFocus) Functions.RunFunction(this.OnFocus, this);
			this._IsFocused = true;
		}
	}, 
	Blur : function(){
		if (this._IsFocused || typeof this._IsFocused == 'undefined'){
			if (PopupConfig.OpacityOnBlur) Functions.SetOpacity(this.Table, 75);
			if (this.OnBlur) Functions.RunFunction(this.OnBlur, this);
			this._IsFocused = false;
		}
	}, 
	Optimize : function(){
		if (!arguments[0]){
			this.Effect.MainDivOffset = Functions.GetElementPosition(this.MainDiv);
			this.Effect.Apply(this.MainDiv, this.Minimized);
		}
		this.Minimized = false;
		if (this.EnableExtraMenu){
			this.TopMenu.Minimize.ChangeState(1);
			this.TopMenu.Optimize.ChangeState(0);
		}
		if (this.OnOptimize) Functions.RunFunction(this.OnOptimize, this);
	}, 
	Minimize : function(){
		if (!arguments[0]) this.Effect.Apply(this.MainDiv, this.Minimized);
		this.Minimized = true;
		if (this.EnableExtraMenu){
			this.TopMenu.Minimize.ChangeState(0);
			this.TopMenu.Optimize.ChangeState(1);
		}
		if (this.OnMinimize) Functions.RunFunction(this.OnMinimize, this);
	},
	Append : function (N){
		Functions.RunFunction(function(){
			var Window = this._IFrame.contentWindow;
			var Document = Window.document;
			Document.open();
			try {
				Document.body.appendChild(N);
			}
			catch(e){
				Document.write(N.toString());
			}
			Document.close();
		}, this);
	},
	CheckIsOpened  : function(){return this._IsOpened},
	CheckIsFocused : function(){return this._IsFocused}
}