PageSourceSearch

https://intervalwatch.ru/bitrix/js/main/core/core_window.js

js intervalwatch.ru collected 2026-10-08 16:26:43 UTC 97,284 bytes, 3,978 lines download raw bytes

1;(function(window) {
2if (BX.WindowManager) return;
3
4/* windows manager */
5BX.WindowManager = {
6	_stack: [],
7	_runtime_resize: {},
8	_delta: 2,
9	_delta_start: 1000,
10	currently_loaded: null,
11
12	settings_category: 'BX.WindowManager.9.5',
13
14	register: function (w)
15	{
16		this.currently_loaded = null;
17		var div = w.Get();
18
19		div.style.zIndex = w.zIndex = this.GetZIndex();
20
21		w.WM_REG_INDEX = this._stack.length;
22		this._stack.push(w);
23
24		if (this._stack.length < 2)
25		{
26			BX.bind(document, 'keyup', BX.proxy(this.__checkKeyPress, this));
27		}
28	},
29
30	unregister: function (w)
31	{
32		if (null == w.WM_REG_INDEX)
33			return null;
34
35		var _current;
36		if (this._stack.length > 0)
37		{
38			while ((_current = this.__pop_stack()) != w)
39			{
40				if (!_current)
41				{
42					_current = null;
43					break;
44				}
45			}
46
47			if (this._stack.length <= 0)
48			{
49				this.enableKeyCheck();
50			}
51
52			return _current;
53		}
54		else
55		{
56			return null;
57		}
58	},
59
60	__pop_stack: function(clean)
61	{
62		if (this._stack.length > 0)
63		{
64			var _current = this._stack.pop();
65			_current.WM_REG_INDEX = null;
66			BX.onCustomEvent(_current, 'onWindowUnRegister', [clean === true]);
67
68			return _current;
69		}
70		else
71			return null;
72	},
73
74	clean: function()
75	{
76		while (this.__pop_stack(true)){}
77		this._stack = null;
78		this.disableKeyCheck();
79	},
80
81	Get: function()
82	{
83		if (this.currently_loaded)
84			return this.currently_loaded;
85		else if (this._stack.length > 0)
86			return this._stack[this._stack.length-1];
87		else
88			return null;
89	},
90
91	setStartZIndex: function(value)
92	{
93		this._delta_start = value;
94	},
95
96	restoreStartZIndex: function()
97	{
98		this._delta_start = 1000;
99	},
100
101	GetZIndex: function()
102	{
103		var _current;
104		return (null != (_current = this._stack[this._stack.length-1])
105			? parseInt(_current.Get().style.zIndex) + this._delta
106			: this._delta_start
107		);
108	},
109
110	__get_check_url: function(url)
111	{
112		var pos = url.indexOf('?');
113		return pos == -1 ? url : url.substring(0, pos);
114	},
115
116	saveWindowSize: function(url, params)
117	{
118		var check_url = this.__get_check_url(url);
119		if (BX.userOptions)
120		{
121			BX.userOptions.save(this.settings_category, 'size_' + check_url, 'width', params.width);
122			BX.userOptions.save(this.settings_category, 'size_' + check_url, 'height', params.height);
123		}
124
125		this._runtime_resize[check_url] = params;
126	},
127
128	saveWindowOptions: function(wnd_id, opts)
129	{
130		if (BX.userOptions)
131		{
132			for (var i in opts)
133			{
134				if(opts.hasOwnProperty(i))
135				{
136					BX.userOptions.save(this.settings_category, 'options_' + wnd_id, i, opts[i]);
137				}
138			}
139		}
140	},
141
142	getRuntimeWindowSize: function(url)
143	{
144		return this._runtime_resize[this.__get_check_url(url)];
145	},
146
147	disableKeyCheck: function()
148	{
149		BX.unbind(document, 'keyup', BX.proxy(this.__checkKeyPress, this));
150	},
151
152	enableKeyCheck: function()
153	{
154		BX.bind(document, 'keyup', BX.proxy(this.__checkKeyPress, this));
155	},
156
157	__checkKeyPress: function(e)
158	{
159		if (null == e)
160			e = window.event;
161
162		if (e.keyCode == 27)
163		{
164			var wnd = BX.WindowManager.Get();
165			if (wnd && !wnd.unclosable) wnd.Close();
166		}
167	}
168};
169
170BX.garbage(BX.WindowManager.clean, BX.WindowManager);
171
172/* base button class */
173BX.CWindowButton = function(params)
174{
175	if (params.btn)
176	{
177		this.btn = params.btn;
178		this.parentWindow = params.parentWindow;
179
180		if (/save|apply/i.test(this.btn.name))
181		{
182			BX.bind(this.btn, 'click', BX.delegate(this.disableUntilError, this));
183		}
184	}
185	else
186	{
187		this.title = params.title; // html value attr
188		this.hint = params.hint; // html title attr
189		this.id = params.id; // html name and id attrs
190		this.name = params.name; // html name or value attrs when id and title 're absent
191		this.className = params.className; // className for button input
192
193		this.action = params.action;
194		this.onclick = params.onclick;
195
196		// you can override button creation method
197		if (params.Button && BX.type.isFunction(params.Button))
198			this.Button = params.Button;
199
200		this.btn = null;
201	}
202};
203
204BX.CWindowButton.prototype.disable = function()
205{
206	if (this.btn)
207		this.parentWindow.showWait(this.btn);
208};
209BX.CWindowButton.prototype.enable = function(){
210	if (this.btn)
211		this.parentWindow.closeWait(this.btn);
212};
213
214BX.CWindowButton.prototype.emulate = function()
215{
216	if (this.btn && this.btn.disabled)
217		return;
218
219	var act =
220		this.action
221		? BX.delegate(this.action, this)
222		: (
223			this.onclick
224			? this.onclick
225			: (
226				this.btn
227				? this.btn.getAttribute('onclick')
228				: ''
229			)
230		);
231
232	if (act)
233	{
234		setTimeout(act, 50);
235		if (this.btn && /save|apply/i.test(this.btn.name) && !this.action)
236		{
237			this.disableUntilError();
238		}
239	}
240};
241
242BX.CWindowButton.prototype.Button = function(parentWindow)
243{
244	this.parentWindow = parentWindow;
245
246	var btn = {
247		props: {
248			'type': 'button',
249			'name': this.id ? this.id : this.name,
250			'value': this.title ? this.title : this.name,
251			'id': this.id
252		}
253	};
254
255	if (this.hint)
256		btn.props.title = this.hint;
257	if (!!this.className)
258		btn.props.className = this.className;
259
260	if (this.action)
261	{
262		btn.events = {
263			'click': BX.delegate(this.action, this)
264		};
265	}
266	else if (this.onclick)
267	{
268		if (BX.browser.IsIE())
269		{
270			btn.events = {
271				'click': BX.delegate(function() {eval(this.onclick)}, this)
272			};
273		}
274		else
275		{
276			btn.attrs = {
277				'onclick': this.onclick
278			};
279		}
280	}
281
282	this.btn = BX.create('INPUT', btn);
283
284	return this.btn;
285};
286
287BX.CWindowButton.prototype.disableUntilError = function() {
288	this.disable();
289	if (!this.__window_error_handler_set)
290	{
291		BX.addCustomEvent(this.parentWindow, 'onWindowError', BX.delegate(this.enable, this));
292		this.__window_error_handler_set = true;
293	}
294};
295
296/* base window class */
297BX.CWindow = function(div, type)
298{
299	this.DIV = div || document.createElement('DIV');
300
301	this.SETTINGS = {
302		resizable: false,
303		min_height: 0,
304		min_width: 0,
305		top: 0,
306		left: 0,
307		draggable: false,
308		drag_restrict: true,
309		resize_restrict: true
310	};
311
312	this.ELEMENTS = {
313		draggable: [],
314		resizer: [],
315		close: []
316	};
317
318	this.type = type == 'float' ? 'float' : 'dialog';
319
320	BX.adjust(this.DIV, {
321		props: {
322			className: 'bx-core-window'
323		},
324		style: {
325			'zIndex': 0,
326			'position': 'absolute',
327			'display': 'none',
328			'top': this.SETTINGS.top + 'px',
329			'left': this.SETTINGS.left + 'px',
330			'height': '100px',
331			'width': '100px'
332		}
333	});
334
335	this.isOpen = false;
336
337	BX.addCustomEvent(this, 'onWindowRegister', BX.delegate(this.onRegister, this));
338	BX.addCustomEvent(this, 'onWindowUnRegister', BX.delegate(this.onUnRegister, this));
339
340	this.MOUSEOVER = null;
341	BX.bind(this.DIV, 'mouseover', BX.delegate(this.__set_msover, this));
342	BX.bind(this.DIV, 'mouseout', BX.delegate(this.__unset_msover, this));
343
344	BX.ready(BX.delegate(function() {
345		document.body.appendChild(this.DIV);
346	}, this));
347};
348
349BX.CWindow.prototype.Get = function () {return this.DIV};
350BX.CWindow.prototype.visible = function() {return this.isOpen;};
351
352BX.CWindow.prototype.Show = function(bNotRegister)
353{
354	this.DIV.style.display = 'block';
355
356	if (!bNotRegister)
357	{
358		BX.WindowManager.register(this);
359		BX.onCustomEvent(this, 'onWindowRegister');
360	}
361};
362
363BX.CWindow.prototype.Hide = function()
364{
365	BX.WindowManager.unregister(this);
366	this.DIV.style.display = 'none';
367};
368
369BX.CWindow.prototype.onRegister = function()
370{
371	this.isOpen = true;
372};
373
374BX.CWindow.prototype.onUnRegister = function(clean)
375{
376	this.isOpen = false;
377
378	if (clean || (this.PARAMS && this.PARAMS.content_url))
379	{
380		if (clean) {BX.onCustomEvent(this, 'onWindowClose', [this, true]);}
381
382		if (this.DIV.parentNode)
383			this.DIV.parentNode.removeChild(this.DIV);
384	}
385	else
386	{
387		this.DIV.style.display = 'none';
388	}
389};
390
391BX.CWindow.prototype.CloseDialog = // compatibility
392BX.CWindow.prototype.Close = function(bImmediately)
393{
394	BX.onCustomEvent(this, 'onBeforeWindowClose', [this]);
395	if (bImmediately !== true)
396	{
397		if (this.denyClose)
398			return false;
399	}
400
401	BX.onCustomEvent(this, 'onWindowClose', [this]);
402
403	//this crashes vis editor in ie via onWindowResizeExt event handler
404	//if (this.bExpanded) this.__expand();
405	// alternative version:
406	if (this.bExpanded)
407	{
408		var pDocElement = BX.GetDocElement();
409		BX.unbind(window, 'resize', BX.proxy(this.__expand_onresize, this));
410		pDocElement.style.overflow = this.__expand_settings.overflow;
411	}
412
413	BX.WindowManager.unregister(this);
414
415	return true;
416};
417
418BX.CWindow.prototype.SetResize = function(elem)
419{
420	elem.style.cursor = 'se-resize';
421	BX.bind(elem, 'mousedown', BX.proxy(this.__startResize, this));
422
423	this.ELEMENTS.resizer.push(elem);
424	this.SETTINGS.resizable = true;
425};
426
427BX.CWindow.prototype.SetExpand = function(elem, event_name)
428{
429	event_name = event_name || 'click';
430	BX.bind(elem, event_name, BX.proxy(this.__expand, this));
431};
432
433BX.CWindow.prototype.__expand_onresize = function()
434{
435	var windowSize = BX.GetWindowInnerSize();
436	this.DIV.style.width = windowSize.innerWidth + "px";
437	this.DIV.style.height = windowSize.innerHeight + "px";
438
439	BX.onCustomEvent(this, 'onWindowResize');
440};
441
442BX.CWindow.prototype.__expand = function()
443{
444	var pDocElement = BX.GetDocElement();
445
446	if (!this.bExpanded)
447	{
448		var wndScroll = BX.GetWindowScrollPos(),
449			wndSize = BX.GetWindowInnerSize();
450
451		this.__expand_settings = {
452			resizable: this.SETTINGS.resizable,
453			draggable: this.SETTINGS.draggable,
454			width: this.DIV.style.width,
455			height: this.DIV.style.height,
456			left: this.DIV.style.left,
457			top: this.DIV.style.top,
458			scrollTop: wndScroll.scrollTop,
459			scrollLeft: wndScroll.scrollLeft,
460			overflow: BX.style(pDocElement, 'overflow')
461		};
462
463		this.SETTINGS.resizable = false;
464		this.SETTINGS.draggable = false;
465
466		window.scrollTo(0,0);
467		pDocElement.style.overflow = 'hidden';
468
469		this.DIV.style.top = '0px';
470		this.DIV.style.left = '0px';
471
472		this.DIV.style.width = wndSize.innerWidth + 'px';
473		this.DIV.style.height = wndSize.innerHeight + 'px';
474
475		this.bExpanded = true;
476
477		BX.onCustomEvent(this, 'onWindowExpand');
478		BX.onCustomEvent(this, 'onWindowResize');
479
480		BX.bind(window, 'resize', BX.proxy(this.__expand_onresize, this));
481	}
482	else
483	{
484		BX.unbind(window, 'resize', BX.proxy(this.__expand_onresize, this));
485
486		this.SETTINGS.resizable = this.__expand_settings.resizable;
487		this.SETTINGS.draggable = this.__expand_settings.draggable;
488
489		pDocElement.style.overflow = this.__expand_settings.overflow;
490
491		this.DIV.style.top = this.__expand_settings.top;
492		this.DIV.style.left = this.__expand_settings.left;
493		this.DIV.style.width = this.__expand_settings.width;
494		this.DIV.style.height = this.__expand_settings.height;
495
496		window.scrollTo(this.__expand_settings.scrollLeft, this.__expand_settings.scrollTop);
497
498		this.bExpanded = false;
499
500		BX.onCustomEvent(this, 'onWindowNarrow');
501		BX.onCustomEvent(this, 'onWindowResize');
502
503	}
504};
505
506BX.CWindow.prototype.Resize = function(x, y)
507{
508	var new_width = Math.max(x - this.pos.left + this.dx, this.SETTINGS.min_width);
509	var new_height = Math.max(y - this.pos.top + this.dy, this.SETTINGS.min_height);
510
511	if (this.SETTINGS.resize_restrict)
512	{
513		var scrollSize = BX.GetWindowScrollSize();
514
515		if (this.pos.left + new_width > scrollSize.scrollWidth - this.dw)
516			new_width = scrollSize.scrollWidth - this.pos.left - this.dw;
517	}
518
519	this.DIV.style.width = new_width + 'px';
520	this.DIV.style.height = new_height + 'px';
521
522	BX.onCustomEvent(this, 'onWindowResize');
523};
524
525BX.CWindow.prototype.__startResize = function(e)
526{
527	if (!this.SETTINGS.resizable)
528		return false;
529
530	if(!e) e = window.event;
531
532	this.wndSize = BX.GetWindowScrollPos();
533	this.wndSize.innerWidth = BX.GetWindowInnerSize().innerWidth;
534
535	this.pos = BX.pos(this.DIV);
536
537	this.x = e.clientX + this.wndSize.scrollLeft;
538	this.y = e.clientY + this.wndSize.scrollTop;
539
540	this.dx = this.pos.left + this.pos.width - this.x;
541	this.dy = this.pos.top + this.pos.height - this.y;
542	this.dw = this.pos.width - parseInt(this.DIV.style.width);
543
544	BX.bind(document, "mousemove", BX.proxy(this.__moveResize, this));
545	BX.bind(document, "mouseup", BX.proxy(this.__stopResize, this));
546
547	if(document.body.setCapture)
548		document.body.setCapture();
549
550	document.onmousedown = BX.False;
551
552	var b = document.body;
553	b.ondrag = b.onselectstart = BX.False;
554	b.style.MozUserSelect = this.DIV.style.MozUserSelect = 'none';
555	b.style.cursor = 'se-resize';
556
557	BX.onCustomEvent(this, 'onWindowResizeStart');
558
559	return true;
560};
561
562BX.CWindow.prototype.__moveResize = function(e)
563{
564	if(!e) e = window.event;
565
566	var windowScroll = BX.GetWindowScrollPos();
567
568	var x = e.clientX + windowScroll.scrollLeft;
569	var y = e.clientY + windowScroll.scrollTop;
570
571	if(this.x == x && this.y == y)
572		return;
573
574	this.Resize(x, y);
575
576	this.x = x;
577	this.y = y;
578};
579
580BX.CWindow.prototype.__stopResize = function()
581{
582	if(document.body.releaseCapture)
583		document.body.releaseCapture();
584
585	BX.unbind(document, "mousemove", BX.proxy(this.__moveResize, this));
586	BX.unbind(document, "mouseup", BX.proxy(this.__stopResize, this));
587
588	document.onmousedown = null;
589
590	var b = document.body;
591	b.ondrag = b.onselectstart = null;
592	b.style.MozUserSelect = this.DIV.style.MozUserSelect = '';
593	b.style.cursor = '';
594
595	BX.onCustomEvent(this, 'onWindowResizeFinished')
596};
597
598BX.CWindow.prototype.SetClose = function(elem)
599{
600	BX.bind(elem, 'click', BX.proxy(this.Close, this));
601	this.ELEMENTS.close.push(elem);
602};
603
604BX.CWindow.prototype.SetDraggable = function(elem)
605{
606	BX.bind(elem, 'mousedown', BX.proxy(this.__startDrag, this));
607
608	elem.style.cursor = 'move';
609
610	this.ELEMENTS.draggable.push(elem);
611	this.SETTINGS.draggable = true;
612};
613
614BX.CWindow.prototype.Move = function(x, y)
615{
616	var dxShadow = 1; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
617
618	var left = parseInt(this.DIV.style.left)+x;
619	var top = parseInt(this.DIV.style.top)+y;
620
621	if (this.SETTINGS.drag_restrict)
622	{
623		//Left side
624		if (left < 0)
625			left = 0;
626
627		//Right side
628		var scrollSize = BX.GetWindowScrollSize();
629		var floatWidth = this.DIV.offsetWidth;
630		var floatHeight = this.DIV.offsetHeight;
631
632		if (left > (scrollSize.scrollWidth - floatWidth - dxShadow))
633			left = scrollSize.scrollWidth - floatWidth - dxShadow;
634
635		var scrollHeight = Math.max(
636			document.body.scrollHeight, document.documentElement.scrollHeight,
637			document.body.offsetHeight, document.documentElement.offsetHeight,
638			document.body.clientHeight, document.documentElement.clientHeight,
639			scrollSize.scrollHeight
640		);
641
642		if (top > (scrollHeight - floatHeight - dxShadow))
643			top = scrollHeight - floatHeight - dxShadow;
644
645		//Top side
646		if (top < 0)
647			top = 0;
648	}
649
650	this.DIV.style.left = left+'px';
651	this.DIV.style.top = top+'px';
652
653	//this.AdjustShadow(div);
654};
655
656BX.CWindow.prototype.__startDrag = function(e)
657{
658	if (!this.SETTINGS.draggable)
659		return false;
660
661	if(!e) e = window.event;
662
663	this.x = e.clientX + document.body.scrollLeft;
664	this.y = e.clientY + document.body.scrollTop;
665
666	this.__bWasDragged = false;
667	BX.bind(document, "mousemove", BX.proxy(this.__moveDrag, this));
668	BX.bind(document, "mouseup", BX.proxy(this.__stopDrag, this));
669
670	if(document.body.setCapture)
671		document.body.setCapture();
672
673	document.onmousedown = BX.False;
674
675	var b = document.body;
676	b.ondrag = b.onselectstart = BX.False;
677	b.style.MozUserSelect = this.DIV.style.MozUserSelect = 'none';
678	b.style.cursor = 'move';
679	return BX.PreventDefault(e);
680};
681
682BX.CWindow.prototype.__moveDrag = function(e)
683{
684	if(!e) e = window.event;
685
686	var x = e.clientX + document.body.scrollLeft;
687	var y = e.clientY + document.body.scrollTop;
688
689	if(this.x == x && this.y == y)
690		return;
691
692	this.Move((x - this.x), (y - this.y));
693	this.x = x;
694	this.y = y;
695
696	if (!this.__bWasDragged)
697	{
698		BX.onCustomEvent(this, 'onWindowDragStart');
699		this.__bWasDragged = true;
700		BX.bind(BX.proxy_context, "click", BX.PreventDefault);
701	}
702
703	BX.onCustomEvent(this, 'onWindowDrag');
704};
705
706BX.CWindow.prototype.__stopDrag = function(e)
707{
708	if(document.body.releaseCapture)
709		document.body.releaseCapture();
710
711	BX.unbind(document, "mousemove", BX.proxy(this.__moveDrag, this));
712	BX.unbind(document, "mouseup", BX.proxy(this.__stopDrag, this));
713
714	document.onmousedown = null;
715
716	var b = document.body;
717	b.ondrag = b.onselectstart = null;
718	b.style.MozUserSelect = this.DIV.style.MozUserSelect = '';
719	b.style.cursor = '';
720
721	if (this.__bWasDragged)
722	{
723		BX.onCustomEvent(this, 'onWindowDragFinished');
724		var _proxy_context = BX.proxy_context;
725		setTimeout(function(){BX.unbind(_proxy_context, "click", BX.PreventDefault)}, 100);
726		this.__bWasDragged = false;
727	}
728	return BX.PreventDefault(e);
729};
730
731BX.CWindow.prototype.DenyClose = function()
732{
733	this.denyClose = true;
734};
735
736BX.CWindow.prototype.AllowClose = function()
737{
738	this.denyClose = false;
739};
740
741BX.CWindow.prototype.ShowError = function(str)
742{
743	BX.onCustomEvent(this, 'onWindowError', [str]);
744
745	if (this._wait)
746		BX.closeWait(this._wait);
747
748	window.alert(str);
749};
750
751BX.CWindow.prototype.__set_msover = function() {this.MOUSEOVER = true;};
752BX.CWindow.prototype.__unset_msover = function() {this.MOUSEOVER = false;};
753
754/* dialog window class extends window class */
755BX.CWindowDialog = function() {
756	var a = arguments;
757	a[1] = 'dialog';
758	BX.CWindowDialog.superclass.constructor.apply(this, a);
759
760	this.DIV.style.top = '10px';
761	this.OVERLAY = null;
762};
763BX.extend(BX.CWindowDialog, BX.CWindow);
764
765BX.CWindowDialog.prototype.__resizeOverlay = function()
766{
767	var windowSize = BX.GetWindowScrollSize();
768	this.OVERLAY.style.width = windowSize.scrollWidth + "px";
769};
770
771BX.CWindowDialog.prototype.CreateOverlay = function(zIndex)
772{
773	if (null == this.OVERLAY)
774	{
775		var windowSize = BX.GetWindowScrollSize();
776
777		// scrollHeight in BX.GetWindowScrollSize may be incorrect
778		var scrollHeight = Math.max(
779			document.body.scrollHeight, document.documentElement.scrollHeight,
780			document.body.offsetHeight, document.documentElement.offsetHeight,
781			document.body.clientHeight, document.documentElement.clientHeight,
782			windowSize.scrollHeight
783		);
784
785		this.OVERLAY = document.body.appendChild(BX.create("DIV", {
786			style: {
787				position: 'absolute',
788				top: '0px',
789				left: '0px',
790				zIndex: zIndex || (parseInt(this.DIV.style.zIndex)-2),
791				width: windowSize.scrollWidth + "px",
792				height: scrollHeight + "px"
793			}
794		}));
795	}
796
797	return this.OVERLAY;
798};
799
800BX.CWindowDialog.prototype.Show = function()
801{
802	BX.CWindowDialog.superclass.Show.apply(this, arguments);
803
804	this.CreateOverlay();
805
806	this.OVERLAY.style.display = 'block';
807	this.OVERLAY.style.zIndex = parseInt(this.DIV.style.zIndex)-2;
808
809	BX.unbind(window, 'resize', BX.proxy(this.__resizeOverlay, this));
810	BX.bind(window, 'resize', BX.proxy(this.__resizeOverlay, this));
811};
812
813BX.CWindowDialog.prototype.onUnRegister = function(clean)
814{
815	BX.CWindowDialog.superclass.onUnRegister.apply(this, arguments);
816
817	if (this.clean)
818	{
819		if (this.OVERLAY.parentNode)
820			this.OVERLAY.parentNode.removeChild(this.OVERLAY);
821	}
822	else
823	{
824		this.OVERLAY.style.display = 'none';
825	}
826
827	BX.unbind(window, 'resize', BX.proxy(this.__resizeOverlay, this));
828};
829
830/* standard bitrix dialog extends BX.CWindowDialog */
831/*
832	arParams = {
833		(
834			title: 'dialog title',
835			head: 'head block html',
836			content: 'dialog content',
837			icon: 'head icon classname or filename',
838
839			resize_id: 'some id to save resize information'// useless if resizable = false
840		)
841		or
842		(
843			content_url: url to content load
844				loaded content scripts can use BX.WindowManager.Get() to get access to the current window object
845		)
846
847		height: window_height_in_pixels,
848		width: window_width_in_pixels,
849
850		draggable: true|false,
851		resizable: true|false,
852
853		min_height: min_window_height_in_pixels, // useless if resizable = false
854		min_width: min_window_width_in_pixels, // useless if resizable = false
855
856		buttons: [
857			'html_code',
858			BX.CDialog.btnSave, BX.CDialog.btnCancel, BX.CDialog.btnClose
859		]
860	}
861*/
862BX.CDialog = function(arParams)
863{
864	BX.CDialog.superclass.constructor.apply(this);
865
866	this._sender = 'core_window_cdialog';
867
868	this.PARAMS = arParams || {};
869
870	for (var i in this.defaultParams)
871	{
872		if (typeof this.PARAMS[i] == 'undefined')
873			this.PARAMS[i] = this.defaultParams[i];
874	}
875
876	this.PARAMS.width = (!isNaN(parseInt(this.PARAMS.width)))
877		? this.PARAMS.width
878		: this.defaultParams['width'];
879	this.PARAMS.height = (!isNaN(parseInt(this.PARAMS.height)))
880		? this.PARAMS.height
881		: this.defaultParams['height'];
882
883	if (this.PARAMS.resize_id || this.PARAMS.content_url)
884	{
885		var arSize = BX.WindowManager.getRuntimeWindowSize(this.PARAMS.resize_id || this.PARAMS.content_url);
886		if (arSize)
887		{
888			this.PARAMS.width = arSize.width;
889			this.PARAMS.height = arSize.height;
890		}
891	}
892
893	BX.addClass(this.DIV, 'bx-core-adm-dialog');
894	this.DIV.id = 'bx-admin-prefix';
895
896	this.PARTS = {};
897
898	this.DIV.style.height = null;
899	this.DIV.style.width = null;
900
901	this.PARTS.TITLEBAR = this.DIV.appendChild(BX.create('DIV', {props: {
902			className: 'bx-core-adm-dialog-head'
903		}
904	}));
905
906	this.PARTS.TITLE_CONTAINER = this.PARTS.TITLEBAR.appendChild(BX.create('SPAN', {
907		props: {className: 'bx-core-adm-dialog-head-inner'},
908		text: this.PARAMS.title
909	}));
910
911	this.PARTS.TITLEBAR_ICONS = this.PARTS.TITLEBAR.appendChild(BX.create('DIV', {
912		props: {
913			className: 'bx-core-adm-dialog-head-icons'
914		},
915		children: (this.PARAMS.resizable ? [
916			BX.create('SPAN', {props: {className: 'bx-core-adm-icon-expand', title: BX.message('JS_CORE_WINDOW_EXPAND')}}),
917			BX.create('SPAN', {props: {className: 'bx-core-adm-icon-close', title: BX.message('JS_CORE_WINDOW_CLOSE')}})
918		] : [
919			BX.create('SPAN', {props: {className: 'bx-core-adm-icon-close', title: BX.message('JS_CORE_WINDOW_CLOSE')}})
920		])
921	}));
922
923
924	this.PARTS.CONTENT = this.DIV.appendChild(BX.create('DIV', {
925		props: {className: 'bx-core-adm-dialog-content-wrap adm-workarea'}
926	}));
927
928	this.PARTS.CONTENT_DATA = this.PARTS.CONTENT.appendChild(BX.create('DIV', {
929		props: {className: 'bx-core-adm-dialog-content'},
930		style: {
931			height: this.PARAMS.height + 'px',
932			width: this.PARAMS.width + 'px'
933		}
934	}));
935
936	this.PARTS.HEAD = this.PARTS.CONTENT_DATA.appendChild(BX.create('DIV', {
937		props: {
938			className: 'bx-core-adm-dialog-head-block' + (this.PARAMS.icon ? ' ' + this.PARAMS.icon : '')
939		}
940	}));
941
942	this.SetHead(this.PARAMS.head);
943	this.SetContent(this.PARAMS.content);
944	this.SetTitle(this.PARAMS.title);
945	this.SetClose(this.PARTS.TITLEBAR_ICONS.lastChild);
946
947	if (this.PARAMS.resizable)
948	{
949		this.SetExpand(this.PARTS.TITLEBAR_ICONS.firstChild);
950		this.SetExpand(this.PARTS.TITLEBAR, 'dblclick');
951
952		BX.addCustomEvent(this, 'onWindowExpand', BX.proxy(this.__onexpand, this));
953		BX.addCustomEvent(this, 'onWindowNarrow', BX.proxy(this.__onexpand, this));
954	}
955
956	this.PARTS.FOOT = this.PARTS.BUTTONS_CONTAINER = this.PARTS.CONTENT.appendChild(BX.create('DIV', {
957			props: {
958				className: 'bx-core-adm-dialog-buttons'
959			},
960			//events: {
961			//	'click': BX.delegateEvent({property:{type: /button|submit/}}, BX.delegate(function() {this.showWait(BX.proxy_context)}, this))
962			//},
963			children: this.ShowButtons()
964		}
965	));
966
967	if (this.PARAMS.draggable)
968		this.SetDraggable(this.PARTS.TITLEBAR);
969
970	if (this.PARAMS.resizable)
971	{
972		this.PARTS.RESIZER = this.DIV.appendChild(BX.create('DIV', {
973			props: {className: 'bx-core-resizer'}
974		}));
975
976		this.SetResize(this.PARTS.RESIZER);
977
978		this.SETTINGS.min_width = this.PARAMS.min_width;
979		this.SETTINGS.min_height = this.PARAMS.min_height;
980	}
981
982	this.auth_callback = BX.delegate(function(){
983		this.PARAMS.content = '';
984		this.hideNotify();
985		this.Show();
986	}, this)
987};
988BX.extend(BX.CDialog, BX.CWindowDialog);
989
990BX.CDialog.prototype.defaultParams = {
991	width: 700,
992	height: 400,
993	min_width: 500,
994	min_height: 300,
995
996	resizable: true,
997	draggable: true,
998
999	title: '',
1000	icon: ''
1001};
1002
1003BX.CDialog.prototype.showWait = function(el)
1004{
1005	if (BX.type.isElementNode(el) && (el.type == 'button' || el.type == 'submit'))
1006	{
1007		BX.defer(function(){el.disabled = true})();
1008
1009		var bSave = (BX.hasClass(el, 'adm-btn-save') || BX.hasClass(el, 'adm-btn-save')),
1010			pos = BX.pos(el, true);
1011
1012		el.bxwaiter = this.PARTS.FOOT.appendChild(BX.create('DIV', {
1013			props: {className: 'adm-btn-load-img' + (bSave ? '-green' : '')},
1014			style: {
1015				top: parseInt((pos.bottom + pos.top)/2 - 10) + 'px',
1016				left: parseInt((pos.right + pos.left)/2 - 10) + 'px'
1017			}
1018		}));
1019
1020		BX.addClass(el, 'adm-btn-load');
1021
1022		this.lastWaitElement = el;
1023
1024		return el.bxwaiter;
1025	}
1026	return null;
1027};
1028
1029BX.CDialog.prototype.closeWait = function(el)
1030{
1031	el = el || this.lastWaitElement;
1032
1033	if (BX.type.isElementNode(el))
1034	{
1035		if (el.bxwaiter)
1036		{
1037			if(el.bxwaiter.parentNode)
1038			{
1039				el.bxwaiter.parentNode.removeChild(el.bxwaiter);
1040			}
1041
1042			el.bxwaiter = null;
1043		}
1044
1045		el.disabled = false;
1046		BX.removeClass(el, 'adm-btn-load');
1047
1048		if (this.lastWaitElement == el)
1049			this.lastWaitElement = null;
1050	}
1051};
1052
1053BX.CDialog.prototype.Authorize = function(arAuthResult)
1054{
1055	this.bSkipReplaceContent = true;
1056	this.ShowError(BX.message('JSADM_AUTH_REQ'));
1057
1058	BX.onCustomEvent(this, 'onWindowError', []);
1059
1060	BX.closeWait();
1061
1062	(new BX.CAuthDialog({
1063		content_url: this.PARAMS.content_url,
1064		auth_result: arAuthResult,
1065		callback: BX.delegate(function(){
1066			if (this.auth_callback)
1067				this.auth_callback()
1068		}, this)
1069	})).Show();
1070};
1071
1072BX.CDialog.prototype.ShowError = function(str)
1073{
1074	BX.onCustomEvent(this, 'onWindowError', [str]);
1075
1076	this.closeWait();
1077
1078	if (this._wait)
1079		BX.closeWait(this._wait);
1080
1081	this.Notify(str, true);
1082};
1083
1084
1085BX.CDialog.prototype.__expandGetSize = function()
1086{
1087	var pDocElement = BX.GetDocElement();
1088	pDocElement.style.overflow = 'hidden';
1089
1090	var wndSize = BX.GetWindowInnerSize();
1091
1092	pDocElement.scrollTop = 0;
1093
1094	this.DIV.style.top = '-' + this.dxShadow + 'px';
1095	this.DIV.style.left = '-' + this.dxShadow + 'px';
1096
1097	return {
1098		width: (wndSize.innerWidth - parseInt(BX.style(this.PARTS.CONTENT, 'padding-right')) - parseInt(BX.style(this.PARTS.CONTENT, 'padding-left'))) + this.dxShadow,
1099		height: (wndSize.innerHeight - this.PARTS.TITLEBAR.offsetHeight - this.PARTS.FOOT.offsetHeight - parseInt(BX.style(this.PARTS.CONTENT, 'padding-top')) - parseInt(BX.style(this.PARTS.CONTENT, 'padding-bottom'))) + this.dxShadow
1100	};
1101};
1102
1103BX.CDialog.prototype.__expand = function()
1104{
1105	var pDocElement = BX.GetDocElement();
1106	this.dxShadow = 2;
1107
1108	if (!this.bExpanded)
1109	{
1110		var wndScroll = BX.GetWindowScrollPos();
1111
1112		this.__expand_settings = {
1113			resizable: this.SETTINGS.resizable,
1114			draggable: this.SETTINGS.draggable,
1115			width: this.PARTS.CONTENT_DATA.style.width,
1116			height: this.PARTS.CONTENT_DATA.style.height,
1117			left: this.DIV.style.left,
1118			top: this.DIV.style.top,
1119			scrollTop: wndScroll.scrollTop,
1120			scrollLeft: wndScroll.scrollLeft,
1121			overflow: BX.style(pDocElement, 'overflow')
1122		};
1123
1124		this.SETTINGS.resizable = false;
1125		this.SETTINGS.draggable = false;
1126
1127		var pos = this.__expandGetSize();
1128
1129		this.PARTS.CONTENT_DATA.style.width = pos.width + 'px';
1130		this.PARTS.CONTENT_DATA.style.height = pos.height + 'px';
1131
1132		window.scrollTo(0,0);
1133		pDocElement.style.overflow = 'hidden';
1134
1135		this.bExpanded = true;
1136
1137		BX.onCustomEvent(this, 'onWindowExpand');
1138		BX.onCustomEvent(this, 'onWindowResize');
1139		BX.onCustomEvent(this, 'onWindowResizeExt', [{'width': pos.width, 'height': pos.height}]);
1140
1141		BX.bind(window, 'resize', BX.proxy(this.__expand_onresize, this));
1142	}
1143	else
1144	{
1145		BX.unbind(window, 'resize', BX.proxy(this.__expand_onresize, this));
1146
1147		this.SETTINGS.resizable = this.__expand_settings.resizable;
1148		this.SETTINGS.draggable = this.__expand_settings.draggable;
1149
1150		pDocElement.style.overflow = this.__expand_settings.overflow;
1151
1152		this.DIV.style.top = this.__expand_settings.top;
1153		this.DIV.style.left = this.__expand_settings.left;
1154		this.PARTS.CONTENT_DATA.style.width = this.__expand_settings.width;
1155		this.PARTS.CONTENT_DATA.style.height = this.__expand_settings.height;
1156		window.scrollTo(this.__expand_settings.scrollLeft, this.__expand_settings.scrollTop);
1157		this.bExpanded = false;
1158
1159		BX.onCustomEvent(this, 'onWindowNarrow');
1160		BX.onCustomEvent(this, 'onWindowResize');
1161		BX.onCustomEvent(this, 'onWindowResizeExt', [{'width': parseInt(this.__expand_settings.width), 'height': parseInt(this.__expand_settings.height)}]);
1162	}
1163};
1164
1165BX.CDialog.prototype.__expand_onresize = function()
1166{
1167	var pos = this.__expandGetSize();
1168
1169	this.PARTS.CONTENT_DATA.style.width = pos.width + 'px';
1170	this.PARTS.CONTENT_DATA.style.height = pos.height + 'px';
1171
1172	BX.onCustomEvent(this, 'onWindowResize');
1173	BX.onCustomEvent(this, 'onWindowResizeExt', [pos]);
1174};
1175
1176BX.CDialog.prototype.__onexpand = function()
1177{
1178	var ob = this.PARTS.TITLEBAR_ICONS.firstChild;
1179	ob.className = BX.toggle(ob.className, ['bx-core-adm-icon-expand', 'bx-core-adm-icon-narrow']);
1180	ob.title = BX.toggle(ob.title, [BX.message('JS_CORE_WINDOW_EXPAND'), BX.message('JS_CORE_WINDOW_NARROW')]);
1181
1182	if (this.PARTS.RESIZER)
1183	{
1184		this.PARTS.RESIZER.style.display = this.bExpanded ? 'none' : 'block';
1185	}
1186};
1187
1188
1189BX.CDialog.prototype.__startResize = function(e)
1190{
1191	if (!this.SETTINGS.resizable)
1192		return false;
1193
1194	if(!e) e = window.event;
1195
1196	this.wndSize = BX.GetWindowScrollPos();
1197	this.wndSize.innerWidth = BX.GetWindowInnerSize().innerWidth;
1198
1199	this.pos = BX.pos(this.PARTS.CONTENT_DATA);
1200
1201	this.x = e.clientX + this.wndSize.scrollLeft;
1202	this.y = e.clientY + this.wndSize.scrollTop;
1203
1204	this.dx = this.pos.left + this.pos.width - this.x;
1205	this.dy = this.pos.top + this.pos.height - this.y;
1206
1207
1208	// TODO: suspicious
1209	this.dw = this.pos.width - parseInt(this.PARTS.CONTENT_DATA.style.width) + parseInt(BX.style(this.PARTS.CONTENT, 'padding-right'));
1210
1211	BX.bind(document, "mousemove", BX.proxy(this.__moveResize, this));
1212	BX.bind(document, "mouseup", BX.proxy(this.__stopResize, this));
1213
1214	if(document.body.setCapture)
1215		document.body.setCapture();
1216
1217	document.onmousedown = BX.False;
1218
1219	var b = document.body;
1220	b.ondrag = b.onselectstart = BX.False;
1221	b.style.MozUserSelect = this.DIV.style.MozUserSelect = 'none';
1222	b.style.cursor = 'se-resize';
1223
1224	BX.onCustomEvent(this, 'onWindowResizeStart');
1225
1226	return true;
1227};
1228
1229BX.CDialog.prototype.Resize = function(x, y)
1230{
1231	var new_width = Math.max(x - this.pos.left + this.dx, this.SETTINGS.min_width);
1232	var new_height = Math.max(y - this.pos.top + this.dy, this.SETTINGS.min_height);
1233
1234	if (this.SETTINGS.resize_restrict)
1235	{
1236		var scrollSize = BX.GetWindowScrollSize();
1237
1238		if (this.pos.left + new_width > scrollSize.scrollWidth - this.dw)
1239			new_width = scrollSize.scrollWidth - this.pos.left - this.dw;
1240	}
1241
1242	this.PARTS.CONTENT_DATA.style.width = new_width + 'px';
1243	this.PARTS.CONTENT_DATA.style.height = new_height + 'px';
1244
1245	BX.onCustomEvent(this, 'onWindowResize');
1246	BX.onCustomEvent(this, 'onWindowResizeExt', [{'height': new_height, 'width': new_width}]);
1247};
1248
1249BX.CDialog.prototype.SetSize = function(obSize)
1250{
1251	this.PARTS.CONTENT_DATA.style.width = obSize.width + 'px';
1252	this.PARTS.CONTENT_DATA.style.height = obSize.height + 'px';
1253
1254	BX.onCustomEvent(this, 'onWindowResize');
1255	BX.onCustomEvent(this, 'onWindowResizeExt', [obSize]);
1256};
1257
1258BX.CDialog.prototype.GetParameters = function(form_name)
1259{
1260	var form = this.GetForm();
1261
1262	if(!form)
1263		return "";
1264
1265	var i, s = "";
1266	var n = form.elements.length;
1267
1268	var delim = '';
1269	for(i=0; i<n; i++)
1270	{
1271		if (s != '') delim = '&';
1272		var el = form.elements[i];
1273		if (el.disabled)
1274			continue;
1275
1276		switch(el.type.toLowerCase())
1277		{
1278			case 'text':
1279			case 'textarea':
1280			case 'password':
1281			case 'hidden':
1282				if (null == form_name && el.name.substr(el.name.length-4) == '_alt' && form.elements[el.name.substr(0, el.name.length-4)])
1283					break;
1284				s += delim + el.name + '=' + BX.util.urlencode(el.value);
1285				break;
1286			case 'radio':
1287				if(el.checked)
1288					s += delim + el.name + '=' + BX.util.urlencode(el.value);
1289				break;
1290			case 'checkbox':
1291				s += delim + el.name + '=' + BX.util.urlencode(el.checked ? 'Y':'N');
1292				break;
1293			case 'select-one':
1294				var val = "";
1295				if (null == form_name && form.elements[el.name + '_alt'] && el.selectedIndex == 0)
1296					val = form.elements[el.name+'_alt'].value;
1297				else
1298					val = el.value;
1299				s += delim + el.name + '=' + BX.util.urlencode(val);
1300				break;
1301			case 'select-multiple':
1302				var j, bAdded = false;
1303				var l = el.options.length;
1304				for (j=0; j<l; j++)
1305				{
1306					if (el.options[j].selected)
1307					{
1308						s += delim + el.name + '=' + BX.util.urlencode(el.options[j].value);
1309						bAdded = true;
1310					}
1311				}
1312				if (!bAdded)
1313					s += delim + el.name + '=';
1314				break;
1315			default:
1316				break;
1317		}
1318	}
1319
1320	return s;
1321};
1322
1323BX.CDialog.prototype.PostParameters = function(params)
1324{
1325	var url = this.PARAMS.content_url;
1326
1327	if (null == params)
1328		params = "";
1329
1330	params += (params == "" ? "" : "&") + "bxsender=" + this._sender;
1331
1332	var index = url.indexOf('?');
1333	if (index == -1)
1334		url += '?' + params;
1335	else
1336		url = url.substring(0, index) + '?' + params + "&" + url.substring(index+1);
1337
1338	BX.showWait();
1339
1340	this.auth_callback = BX.delegate(function(){
1341		this.hideNotify();
1342		this.PostParameters(params);
1343	}, this);
1344
1345	BX.ajax.Setup({skipAuthCheck:true},true);
1346	BX.ajax.post(url, this.GetParameters(), BX.delegate(function(result) {
1347		BX.closeWait();
1348		if (!this.bSkipReplaceContent)
1349		{
1350			this.ClearButtons(); // buttons are appended during form reload, so we should clear footer
1351			this.SetContent(result);
1352			this.Show(true);
1353		}
1354
1355		this.bSkipReplaceContent = false;
1356	}, this));
1357};
1358
1359BX.CDialog.prototype.Submit = function(params, url)
1360{
1361	var FORM = this.GetForm();
1362	if (FORM)
1363	{
1364		FORM.onsubmit = null;
1365
1366		FORM.method = 'POST';
1367		if (!FORM.action || url)
1368		{
1369			url = url || this.PARAMS.content_url;
1370			if (null != params)
1371			{
1372				var index = url.indexOf('?');
1373				if (index == -1)
1374					url += '?' + params;
1375				else
1376					url = url.substring(0, index) + '?' + params + "&" + url.substring(index+1);
1377			}
1378
1379			FORM.action = url;
1380		}
1381
1382		if (!FORM._bxsender)
1383		{
1384			FORM._bxsender = FORM.appendChild(BX.create('INPUT', {
1385				attrs: {
1386					type: 'hidden',
1387					name: 'bxsender',
1388					value: this._sender
1389				}
1390			}));
1391		}
1392
1393		this._wait = BX.showWait();
1394
1395		this.auth_callback = BX.delegate(function(){
1396			this.hideNotify();
1397			this.Submit(params);
1398		}, this);
1399
1400		BX.ajax.submit(FORM, BX.delegate(function(){this.closeWait()}, this));
1401	}
1402	else
1403	{
1404		window.alert('no form registered!');
1405	}
1406};
1407
1408BX.CDialog.prototype.GetForm = function()
1409{
1410	if (null == this.__form)
1411	{
1412		var forms = this.PARTS.CONTENT_DATA.getElementsByTagName('FORM');
1413		this.__form = forms[0] ? forms[0] : null;
1414	}
1415
1416	return this.__form;
1417};
1418
1419BX.CDialog.prototype.GetRealForm = function()
1420{
1421	if (null == this.__rform)
1422	{
1423		var forms = this.PARTS.CONTENT_DATA.getElementsByTagName('FORM');
1424		this.__rform = forms[1] ? forms[1] : (forms[0] ? forms[0] : null);
1425	}
1426
1427	return this.__rform;
1428};
1429
1430BX.CDialog.prototype._checkButton = function(btn)
1431{
1432	var arCustomButtons = ['btnSave', 'btnCancel', 'btnClose'];
1433
1434	for (var i = 0; i < arCustomButtons.length; i++)
1435	{
1436		if (this[arCustomButtons[i]] && (btn == this[arCustomButtons[i]]))
1437			return arCustomButtons[i];
1438	}
1439
1440	return false;
1441};
1442
1443BX.CDialog.prototype.ShowButtons = function()
1444{
1445	var result = [];
1446	if (this.PARAMS.buttons)
1447	{
1448		if (this.PARAMS.buttons.title) this.PARAMS.buttons = [this.PARAMS.buttons];
1449
1450		for (var i=0, len=this.PARAMS.buttons.length; i<len; i++)
1451		{
1452			if (BX.type.isNotEmptyString(this.PARAMS.buttons[i]))
1453			{
1454				result.push(this.PARAMS.buttons[i]);
1455			}
1456			else if (BX.type.isElementNode(this.PARAMS.buttons[i]))
1457			{
1458				result.push(this.PARAMS.buttons[i]);
1459			}
1460			else if (this.PARAMS.buttons[i])
1461			{
1462				//if (!(this.PARAMS.buttons[i] instanceof BX.CWindowButton))
1463				if (!BX.is_subclass_of(this.PARAMS.buttons[i], BX.CWindowButton))
1464				{
1465					var b = this._checkButton(this.PARAMS.buttons[i]); // hack to set links to real CWindowButton object in btnSave etc;
1466					this.PARAMS.buttons[i] = new BX.CWindowButton(this.PARAMS.buttons[i]);
1467					if (b) this[b] = this.PARAMS.buttons[i];
1468				}
1469
1470				result.push(this.PARAMS.buttons[i].Button(this));
1471			}
1472		}
1473	}
1474
1475	return result;
1476};
1477
1478BX.CDialog.prototype.setAutosave = function () {
1479	if (!this.bSetAutosaveDelay)
1480	{
1481		this.bSetAutosaveDelay = true;
1482		setTimeout(BX.proxy(this.setAutosave, this), 10);
1483	}
1484};
1485
1486BX.CDialog.prototype.SetTitle = function(title)
1487{
1488	this.PARAMS.title = title;
1489	BX.cleanNode(this.PARTS.TITLE_CONTAINER).appendChild(document.createTextNode(this.PARAMS.title));
1490};
1491
1492BX.CDialog.prototype.SetHead = function(head)
1493{
1494	this.PARAMS.head = BX.util.trim(head);
1495	this.PARTS.HEAD.innerHTML = this.PARAMS.head || "&nbsp;";
1496	this.PARTS.HEAD.style.display = this.PARAMS.head ? 'block' : 'none';
1497	this.adjustSize();
1498};
1499
1500BX.CDialog.prototype.Notify = function(note, bError)
1501{
1502	if (!this.PARTS.NOTIFY)
1503	{
1504		this.PARTS.NOTIFY = this.DIV.insertBefore(BX.create('DIV', {
1505			props: {className: 'adm-warning-block'},
1506			children: [
1507				BX.create('SPAN', {
1508					props: {className: 'adm-warning-text'}
1509				}),
1510				BX.create('SPAN', {
1511					props: {className: 'adm-warning-icon'}
1512				}),
1513				BX.create('SPAN', {
1514					props: {className: 'adm-warning-close'},
1515					events: {click: BX.proxy(this.hideNotify, this)}
1516				})
1517			]
1518		}), this.DIV.firstChild);
1519	}
1520
1521	if (bError)
1522		BX.addClass(this.PARTS.NOTIFY, 'adm-warning-block-red');
1523	else
1524		BX.removeClass(this.PARTS.NOTIFY, 'adm-warning-block-red');
1525
1526	this.PARTS.NOTIFY.firstChild.innerHTML = note || '&nbsp;';
1527	this.PARTS.NOTIFY.firstChild.style.width = (this.PARAMS.width-50) + 'px';
1528	BX.removeClass(this.PARTS.NOTIFY, 'adm-warning-animate');
1529};
1530
1531BX.CDialog.prototype.hideNotify = function()
1532{
1533	BX.addClass(this.PARTS.NOTIFY, 'adm-warning-animate');
1534};
1535
1536BX.CDialog.prototype.__adjustHeadToIcon = function()
1537{
1538	if (!this.PARTS.HEAD.offsetHeight)
1539	{
1540		setTimeout(BX.delegate(this.__adjustHeadToIcon, this), 50);
1541	}
1542	else
1543	{
1544		if (this.icon_image && this.icon_image.height && this.icon_image.height > this.PARTS.HEAD.offsetHeight - 5)
1545		{
1546			this.PARTS.HEAD.style.height = this.icon_image.height + 5 + 'px';
1547			this.adjustSize();
1548		}
1549
1550		this.icon_image.onload = null;
1551		this.icon_image = null;
1552	}
1553};
1554
1555BX.CDialog.prototype.SetIcon = function(icon_class)
1556{
1557	if (this.PARAMS.icon != icon_class)
1558	{
1559		if (this.PARAMS.icon)
1560			BX.removeClass(this.PARTS.HEAD, this.PARAMS.icon);
1561
1562		this.PARAMS.icon = icon_class;
1563
1564		if (this.PARAMS.icon)
1565		{
1566			BX.addClass(this.PARTS.HEAD, this.PARAMS.icon);
1567
1568			var icon_file = (BX.style(this.PARTS.HEAD, 'background-image') || BX.style(this.PARTS.HEAD, 'backgroundImage'));
1569			if (BX.type.isNotEmptyString(icon_file) && icon_file != 'none')
1570			{
1571				var match = icon_file.match(new RegExp('url\\s*\\(\\s*(\'|"|)(.+?)(\\1)\\s*\\)'));
1572				if(match)
1573				{
1574					icon_file = match[2];
1575					if (BX.type.isNotEmptyString(icon_file))
1576					{
1577						this.icon_image = new Image();
1578						this.icon_image.onload = BX.delegate(this.__adjustHeadToIcon, this);
1579						this.icon_image.src = icon_file;
1580					}
1581				}
1582			}
1583		}
1584	}
1585	this.adjustSize();
1586};
1587
1588BX.CDialog.prototype.SetIconFile = function(icon_file)
1589{
1590	this.icon_image = new Image();
1591	this.icon_image.onload = BX.delegate(this.__adjustHeadToIcon, this);
1592	this.icon_image.src = icon_file;
1593
1594	BX.adjust(this.PARTS.HEAD, {style: {backgroundImage: 'url(' + icon_file + ')', backgroundPosition: 'right 9px'/*'99% center'*/}});
1595	this.adjustSize();
1596};
1597
1598/*
1599BUTTON: {
1600	title: 'title',
1601	'action': function executed in window object context
1602}
1603BX.CDialog.btnSave || BX.CDialog.btnCancel - standard buttons
1604*/
1605
1606BX.CDialog.prototype.SetButtons = function(a)
1607{
1608	if (BX.type.isString(a))
1609	{
1610		if (a.length > 0)
1611		{
1612			this.PARTS.BUTTONS_CONTAINER.innerHTML += a;
1613
1614			var btns = this.PARTS.BUTTONS_CONTAINER.getElementsByTagName('INPUT');
1615			if (btns.length > 0)
1616			{
1617				this.PARAMS.buttons = [];
1618				for (var i = 0; i < btns.length; i++)
1619				{
1620					this.PARAMS.buttons.push(new BX.CWindowButton({btn: btns[i], parentWindow: this}));
1621				}
1622			}
1623		}
1624	}
1625	else
1626	{
1627		this.PARAMS.buttons = a;
1628		BX.adjust(this.PARTS.BUTTONS_CONTAINER, {
1629			children: this.ShowButtons()
1630		});
1631	}
1632	this.adjustSize();
1633};
1634
1635BX.CDialog.prototype.ClearButtons = function()
1636{
1637	BX.cleanNode(this.PARTS.BUTTONS_CONTAINER);
1638	this.adjustSize();
1639};
1640
1641BX.CDialog.prototype.SetContent = function(html)
1642{
1643	this.__form = null;
1644
1645	if (BX.type.isElementNode(html))
1646	{
1647		if (html.parentNode)
1648			html.parentNode.removeChild(html);
1649	}
1650	else if (BX.type.isString(html))
1651	{
1652		html = BX.create('DIV', {html: html});
1653	}
1654
1655	this.PARAMS.content = html;
1656	BX.cleanNode(this.PARTS.CONTENT_DATA);
1657
1658	BX.adjust(this.PARTS.CONTENT_DATA, {
1659		children: [
1660			this.PARTS.HEAD,
1661			BX.create('DIV', {
1662				props: {
1663					className: 'bx-core-adm-dialog-content-wrap-inner'
1664				},
1665				children: [this.PARAMS.content]
1666			})
1667		]
1668	});
1669
1670	if (this.PARAMS.content_url && this.GetForm())
1671	{
1672		this.__form.submitbtn = this.__form.appendChild(BX.create('INPUT', {props:{type:'submit'},style:{display:'none'}}));
1673		this.__form.onsubmit = BX.delegate(this.__submit, this);
1674	}
1675};
1676
1677BX.CDialog.prototype.__submit = function(e)
1678{
1679	for (var i=0,len=this.PARAMS.buttons.length; i<len; i++)
1680	{
1681		if (
1682			this.PARAMS.buttons[i]
1683			&& (
1684				this.PARAMS.buttons[i].name && /save|apply/i.test(this.PARAMS.buttons[i].name)
1685				||
1686				this.PARAMS.buttons[i].btn && this.PARAMS.buttons[i].btn.name && /save|apply/i.test(this.PARAMS.buttons[i].btn.name)
1687			)
1688		)
1689		{
1690			this.PARAMS.buttons[i].emulate();
1691			break;
1692		}
1693	}
1694
1695	return BX.PreventDefault(e);
1696};
1697
1698BX.CDialog.prototype.SwapContent = function(cont)
1699{
1700	cont = BX(cont);
1701
1702	BX.cleanNode(this.PARTS.CONTENT_DATA);
1703	cont.parentNode.removeChild(cont);
1704	this.PARTS.CONTENT_DATA.appendChild(cont);
1705	cont.style.display = 'block';
1706	this.SetContent(cont.innerHTML);
1707};
1708
1709// this method deprecated
1710BX.CDialog.prototype.adjustSize = function()
1711{
1712};
1713
1714// this method deprecated
1715BX.CDialog.prototype.__adjustSize = function()
1716{
1717};
1718
1719BX.CDialog.prototype.adjustSizeEx = function()
1720{
1721	BX.defer(this.__adjustSizeEx, this)();
1722};
1723
1724BX.CDialog.prototype.__adjustSizeEx = function()
1725{
1726	var ob = this.PARTS.CONTENT_DATA.firstChild,
1727		new_height = 0,
1728		marginTop,
1729		marginBottom;
1730
1731	while (ob)
1732	{
1733		if (BX.type.isElementNode(ob))
1734		{
1735			marginTop = parseInt(BX.style(ob, 'margin-top'), 10);
1736			if (isNaN(marginTop))
1737				marginTop = 0;
1738			marginBottom = parseInt(BX.style(ob, 'margin-bottom'), 10);
1739			if (isNaN(marginBottom))
1740				marginBottom = 0;
1741			new_height += ob.offsetHeight + marginTop + marginBottom;
1742		}
1743		ob = BX.nextSibling(ob);
1744	}
1745
1746	if (new_height)
1747		this.PARTS.CONTENT_DATA.style.height = new_height + 'px';
1748};
1749
1750
1751BX.CDialog.prototype.__onResizeFinished = function()
1752{
1753	BX.WindowManager.saveWindowSize(
1754		this.PARAMS.resize_id || this.PARAMS.content_url, {height: parseInt(this.PARTS.CONTENT_DATA.style.height), width: parseInt(this.PARTS.CONTENT_DATA.style.width)}
1755	);
1756};
1757
1758BX.CDialog.prototype.Show = function(bNotRegister)
1759{
1760	if ((!this.PARAMS.content) && this.PARAMS.content_url && BX.ajax && !bNotRegister)
1761	{
1762		var wait = BX.showWait();
1763
1764		BX.WindowManager.currently_loaded = this;
1765
1766		this.CreateOverlay(parseInt(BX.style(wait, 'z-index'))-1);
1767		this.OVERLAY.style.display = 'block';
1768		this.OVERLAY.className = 'bx-core-dialog-overlay';
1769
1770		var post_data = '', method = 'GET';
1771		if (this.PARAMS.content_post)
1772		{
1773			post_data = this.PARAMS.content_post;
1774			method = 'POST';
1775		}
1776
1777		var url = this.PARAMS.content_url
1778			+ (this.PARAMS.content_url.indexOf('?')<0?'?':'&')+'bxsender=' + this._sender;
1779
1780		this.auth_callback = BX.delegate(function(){
1781			this.PARAMS.content = '';
1782			this.hideNotify();
1783			this.Show();
1784		}, this);
1785
1786		BX.ajax({
1787			method: method,
1788			dataType: 'html',
1789			url: url,
1790			data: post_data,
1791			skipAuthCheck: true,
1792			onsuccess: BX.delegate(function(data) {
1793				BX.closeWait(null, wait);
1794
1795				this.SetContent(data || '&nbsp;');
1796				this.Show();
1797			}, this)
1798		});
1799	}
1800	else
1801	{
1802		BX.WindowManager.currently_loaded = null;
1803		BX.CDialog.superclass.Show.apply(this, arguments);
1804
1805		this.adjustPos();
1806
1807		this.OVERLAY.className = 'bx-core-dialog-overlay';
1808
1809		this.__adjustSize();
1810
1811		BX.addCustomEvent(this, 'onWindowResize', BX.proxy(this.__adjustSize, this));
1812
1813		if (this.PARAMS.resizable && (this.PARAMS.content_url || this.PARAMS.resize_id))
1814			BX.addCustomEvent(this, 'onWindowResizeFinished', BX.delegate(this.__onResizeFinished, this));
1815	}
1816};
1817
1818BX.CDialog.prototype.GetInnerPos = function()
1819{
1820	return {'width': parseInt(this.PARTS.CONTENT_DATA.style.width), 'height': parseInt(this.PARTS.CONTENT_DATA.style.height)};
1821};
1822
1823BX.CDialog.prototype.adjustPos = function()
1824{
1825	if (!this.bExpanded)
1826	{
1827		var windowSize = BX.GetWindowInnerSize();
1828		var windowScroll = BX.GetWindowScrollPos();
1829
1830		BX.adjust(this.DIV, {
1831			style: {
1832				left: parseInt(windowScroll.scrollLeft + windowSize.innerWidth / 2 - parseInt(this.DIV.offsetWidth) / 2) + 'px',
1833				top: Math.max(parseInt(windowScroll.scrollTop + windowSize.innerHe
1833ight / 2 - parseInt(this.DIV.offsetHeight) / 2), 0) + 'px'
1834			}
1835		});
1836	}
1837};
1838
1839BX.CDialog.prototype.GetContent = function () {return this.PARTS.CONTENT_DATA};
1840
1841BX.CDialog.prototype.btnSave = BX.CDialog.btnSave = {
1842	title: BX.message('JS_CORE_WINDOW_SAVE'),
1843	id: 'savebtn',
1844	name: 'savebtn',
1845	className: BX.browser.IsIE() && BX.browser.IsDoctype() && !BX.browser.IsIE10() ? '' : 'adm-btn-save',
1846	action: function () {
1847		this.disableUntilError();
1848		this.parentWindow.PostParameters();
1849	}
1850};
1851
1852BX.CDialog.prototype.btnCancel = BX.CDialog.btnCancel = {
1853	title: BX.message('JS_CORE_WINDOW_CANCEL'),
1854	id: 'cancel',
1855	name: 'cancel',
1856	action: function () {
1857		this.parentWindow.Close();
1858	}
1859};
1860
1861BX.CDialog.prototype.btnClose = BX.CDialog.btnClose = {
1862	title: BX.message('JS_CORE_WINDOW_CLOSE'),
1863	id: 'close',
1864	name: 'close',
1865	action: function () {
1866		this.parentWindow.Close();
1867	}
1868};
1869
1870/* special child for admin forms loaded into public page */
1871BX.CAdminDialog = function(arParams)
1872{
1873	BX.CAdminDialog.superclass.constructor.apply(this, arguments);
1874
1875	this._sender = 'core_window_cadmindialog';
1876
1877	BX.addClass(this.DIV, 'bx-core-adm-admin-dialog');
1878
1879	this.PARTS.CONTENT.insertBefore(this.PARTS.HEAD, this.PARTS.CONTENT.firstChild);
1880	this.PARTS.HEAD.className = 'bx-core-adm-dialog-tabs';
1881};
1882BX.extend(BX.CAdminDialog, BX.CDialog);
1883
1884BX.CAdminDialog.prototype.SetHead = function()
1885{
1886	BX.CAdminDialog.superclass.SetHead.apply(this, arguments);
1887
1888	if (this.PARTS.HEAD.firstChild && BX.type.isElementNode(this.PARTS.HEAD.firstChild))
1889	{
1890		var ob = this.PARTS.HEAD.firstChild, new_width = 0, marginLeft = 0, marginRight = 0;
1891
1892		while (ob)
1893		{
1894			if (BX.type.isElementNode(ob))
1895			{
1896				marginLeft = parseInt(BX.style(ob, 'margin-left'), 10);
1897				if (isNaN(marginLeft))
1898					marginLeft = 0;
1899				marginRight = parseInt(BX.style(ob, 'margin-right'), 10);
1900				if (isNaN(marginRight))
1901					marginRight = 0;
1902				new_width += ob.offsetWidth + marginLeft + marginRight;
1903			}
1904			ob = BX.nextSibling(ob);
1905		}
1906
1907		this.SETTINGS.min_width = Math.max(new_width, this.SETTINGS.min_width) - 2;
1908		if (this.PARAMS.width < this.SETTINGS.min_width)
1909		{
1910			BX.adjust(this.PARTS.CONTENT_DATA, {
1911				style: {
1912					width: this.SETTINGS.min_width + 'px'
1913				}
1914			});
1915		}
1916	}
1917};
1918
1919BX.CAdminDialog.prototype.SetContent = function(html)
1920{
1921	this.__form = null;
1922
1923	if (BX.type.isElementNode(html))
1924	{
1925		if (html.parentNode)
1926			html.parentNode.removeChild(html);
1927	}
1928
1929	this.PARAMS.content = html;
1930	BX.cleanNode(this.PARTS.CONTENT_DATA);
1931
1932	BX.adjust(this.PARTS.CONTENT_DATA, {
1933		children: [
1934			this.PARAMS.content || '&nbsp;'
1935		]
1936	});
1937
1938	if (this.PARAMS.content_url && this.GetForm())
1939	{
1940		this.__form.appendChild(BX.create('INPUT', {props:{type:'submit'},style:{display:'none'}}));
1941		this.__form.onsubmit = BX.delegate(this.__submit, this);
1942	}
1943};
1944
1945BX.CAdminDialog.prototype.__expandGetSize = function()
1946{
1947	var res = BX.CAdminDialog.superclass.__expandGetSize.apply(this, arguments);
1948
1949	res.width -= parseInt(BX.style(this.PARTS.CONTENT_DATA, 'padding-right')) + parseInt(BX.style(this.PARTS.CONTENT_DATA, 'padding-left'));
1950	res.height -= parseInt(BX.style(this.PARTS.CONTENT_DATA, 'padding-top')) + parseInt(BX.style(this.PARTS.CONTENT_DATA, 'padding-bottom'));
1951
1952	res.height -= this.PARTS.HEAD.offsetHeight;
1953
1954	return res;
1955};
1956
1957BX.CAdminDialog.prototype.Submit = function()
1958{
1959	var FORM = this.GetForm();
1960	if (FORM && !FORM['bxpublic'] && !/bxpublic=/.test(FORM.action))
1961	{
1962		FORM.appendChild(BX.create('INPUT', {
1963			props: {
1964				type: 'hidden',
1965				name: 'bxpublic',
1966				value: 'Y'
1967			}
1968		}));
1969	}
1970
1971	return BX.CAdminDialog.superclass.Submit.apply(this, arguments);
1972};
1973
1974BX.CAdminDialog.prototype.btnSave = BX.CAdminDialog.btnSave = {
1975	title: BX.message('JS_CORE_WINDOW_SAVE'),
1976	id: 'savebtn',
1977	name: 'savebtn',
1978	className: 'adm-btn-save',
1979	action: function () {
1980		this.disableUntilError();
1981		this.parentWindow.Submit();
1982	}
1983};
1984
1985BX.CAdminDialog.btnCancel = BX.CAdminDialog.superclass.btnCancel;
1986BX.CAdminDialog.btnClose = BX.CAdminDialog.superclass.btnClose;
1987
1988BX.CDebugDialog = function(arParams)
1989{
1990	BX.CDebugDialog.superclass.constructor.apply(this, arguments);
1991};
1992BX.extend(BX.CDebugDialog, BX.CDialog);
1993
1994BX.CDebugDialog.prototype.ShowDetails = function(div_id)
1995{
1996	var div = BX(div_id);
1997	if (div)
1998	{
1999		if (this.div_detail_current)
2000			this.div_detail_current.style.display = 'none';
2001
2002		div.style.display = 'block';
2003		this.div_detail_current = div;
2004	}
2005};
2006
2007BX.CDebugDialog.prototype.SetContent = function(html)
2008{
2009	if (!html)
2010		return;
2011
2012	var arHtml = html.split('#DIVIDER#');
2013	if (arHtml.length > 1)
2014	{
2015		this.PARAMS.content = arHtml[1];
2016
2017		this.PARTS.CONTENT_DATA.style.overflow = 'hidden';
2018
2019		BX.CDebugDialog.superclass.SetContent.apply(this, [arHtml[1]]);
2020
2021		this.PARTS.CONTENT_INNER = this.PARTS.CONTENT_DATA.firstChild.nextSibling;
2022		this.PARTS.CONTENT_TOP = this.PARTS.CONTENT_DATA.insertBefore(BX.create('DIV', {
2023			props: {
2024				className: 'bx-debug-content-top'
2025			},
2026			html: arHtml[0]
2027		}), this.PARTS.CONTENT_INNER);
2028		this.PARTS.CONTENT_INNER.style.overflow = 'auto';
2029	}
2030	else
2031	{
2032		BX.CDebugDialog.superclass.SetContent.apply(this, arguments);
2033	}
2034};
2035
2036BX.CDebugDialog.prototype.__adjustSize = function()
2037{
2038	BX.CDebugDialog.superclass.__adjustSize.apply(this, arguments);
2039
2040	if (this.PARTS.CONTENT_TOP)
2041	{
2042		var new_height = this.PARTS.CONTENT_DATA.offsetHeight - this.PARTS.HEAD.offsetHeight - this.PARTS.CONTENT_TOP.offsetHeight - 38;
2043
2044		if (new_height > 0)
2045		{
2046			this.PARTS.CONTENT_INNER.style.height = new_height + 'px';
2047		}
2048	}
2049};
2050
2051
2052/* class for dialog window with editors */
2053
2054BX.CEditorDialog = function(arParams)
2055{
2056	BX.CEditorDialog.superclass.constructor.apply(this, arguments);
2057
2058	BX.removeClass(this.PARTS.CONTENT, 'bx-core-adm-dialog-content-wrap');
2059	BX.removeClass(this.PARTS.CONTENT_DATA, 'bx-core-adm-dialog-content');
2060
2061	BX.removeClass(this.PARTS.CONTENT_DATA.lastChild, 'bx-core-adm-dialog-content-wrap-inner');
2062	BX.removeClass(this.PARTS.BUTTONS_CONTAINER, 'bx-core-adm-dialog-buttons');
2063
2064	BX.addClass(this.PARTS.CONTENT, 'bx-core-editor-dialog-content-wrap');
2065	BX.addClass(this.PARTS.CONTENT_DATA, 'bx-core-editor-dialog-content');
2066	BX.addClass(this.PARTS.BUTTONS_CONTAINER, 'bx-core-editor-dialog-buttons');
2067};
2068BX.extend(BX.CEditorDialog, BX.CDialog);
2069
2070BX.CEditorDialog.prototype.SetContent  = function()
2071{
2072	BX.CEditorDialog.superclass.SetContent.apply(this, arguments);
2073
2074	BX.removeClass(this.PARTS.CONTENT_DATA.lastChild, 'bx-core-adm-dialog-content-wrap-inner');
2075};
2076
2077/* class for wizards in admin section */
2078BX.CWizardDialog = function(arParams)
2079{
2080	BX.CWizardDialog.superclass.constructor.apply(this, arguments);
2081
2082	BX.removeClass(this.PARTS.CONTENT, 'bx-core-adm-dialog-content-wrap');
2083	BX.removeClass(this.PARTS.CONTENT_DATA, 'bx-core-adm-dialog-content');
2084	BX.removeClass(this.PARTS.CONTENT_DATA.lastChild, 'bx-core-adm-dialog-content-wrap-inner');
2085	BX.removeClass(this.PARTS.BUTTONS_CONTAINER, 'bx-core-adm-dialog-buttons');
2086
2087	BX.addClass(this.PARTS.CONTENT, 'bx-core-wizard-dialog-content-wrap');
2088};
2089
2090BX.extend(BX.CWizardDialog, BX.CDialog);
2091
2092/* class for auth dialog */
2093BX.CAuthDialog = function(arParams)
2094{
2095	arParams.resizable = false;
2096	arParams.width = 350;
2097	arParams.height = 200;
2098
2099	arParams.buttons = [this.btnSave];
2100
2101	BX.CAuthDialog.superclass.constructor.apply(this, arguments);
2102	this._sender = 'core_window_cauthdialog';
2103
2104	BX.addClass(this.DIV, 'bx-core-auth-dialog');
2105
2106	BX.AUTHAGENT = this;
2107};
2108BX.extend(BX.CAuthDialog, BX.CDialog);
2109
2110BX.CAuthDialog.prototype.btnSave = BX.CAuthDialog.btnSave = {
2111	title: BX.message('JS_CORE_WINDOW_AUTH'),
2112	id: 'savebtn',
2113	name: 'savebtn',
2114	className: 'adm-btn-save',
2115	action: function () {
2116		this.disableUntilError();
2117		this.parentWindow.Submit('', this.parentWindow.PARAMS.content_url);
2118	}
2119};
2120
2121BX.CAuthDialog.prototype.SetError = function(error)
2122{
2123	BX.closeWait();
2124
2125	if (!!error)
2126		this.ShowError(error.MESSAGE || error);
2127};
2128
2129BX.CAuthDialog.prototype.setAuthResult = function(result)
2130{
2131	BX.closeWait();
2132
2133	if (result === false)
2134	{
2135		this.Close();
2136		if (this.PARAMS.callback)
2137			this.PARAMS.callback();
2138	}
2139	else
2140	{
2141		this.SetError(result);
2142	}
2143};
2144
2145/* MENU CLASSES */
2146
2147BX.CWindowFloat = function(node)
2148{
2149	BX.CWindowFloat.superclass.constructor.apply(this, [node, 'float']);
2150
2151	this.SETTINGS.resizable = false;
2152};
2153BX.extend(BX.CWindowFloat, BX.CWindow);
2154
2155BX.CWindowFloat.prototype.adjustPos = function()
2156{
2157	if (this.PARAMS.parent)
2158		this.adjustToNode();
2159	else if (this.PARAMS.x && this.PARAMS.y)
2160		this.adjustToPos([this.PARAMS.x, this.PARAMS.y]);
2161};
2162
2163BX.CWindowFloat.prototype.adjustToPos = function(pos)
2164{
2165	this.DIV.style.left = parseInt(pos[0]) + 'px';
2166	this.DIV.style.top = parseInt(pos[1]) + 'px';
2167};
2168
2169BX.CWindowFloat.prototype.adjustToNodeGetPos = function()
2170{
2171	return BX.pos(this.PARAMS.parent);
2172};
2173
2174BX.CWindowFloat.prototype.adjustToNode = function(el)
2175{
2176	el = el || this.PARAMS.parent;
2177
2178	this.PARAMS.parent = BX(el);
2179
2180	if (this.PARAMS.parent)
2181	{
2182		var pos = this.adjustToNodeGetPos();
2183
2184		this.DIV.style.top = pos.top + 'px';//(pos.top - 26) + 'px';
2185		this.DIV.style.left = pos.left + 'px';
2186
2187		this.PARAMS.parent.OPENER = this;
2188	}
2189};
2190
2191BX.CWindowFloat.prototype.Show = function()
2192{
2193	this.adjustToPos([-1000, -1000]);
2194	BX.CWindowFloat.superclass.Show.apply(this, arguments);
2195	this.adjustPos();
2196};
2197
2198/* menu opener class */
2199/*
2200{
2201	DOMNode DIV,
2202	BX.CMenu or Array MENU,
2203	TYPE = 'hover' | 'click',
2204	TIMEOUT: 1000
2205	ATTACH_MODE: 'top' | 'right'
2206	ACTIVE_CLASS: className for opener element when menu is opened
2207}
2208*/
2209BX.COpener = function(arParams)
2210{
2211	this.PARAMS = arParams || {};
2212
2213	this.MENU = arParams.MENU || [];
2214
2215	this.DIV = arParams.DIV;
2216	this.ATTACH = arParams.ATTACH || arParams.DIV;
2217	this.ATTACH_MODE = arParams.ATTACH_MODE || 'bottom';
2218
2219	this.ACTIVE_CLASS = arParams.ACTIVE_CLASS || '';
2220	this.LEVEL = arParams.LEVEL || 0;
2221
2222	this.CLOSE_ON_CLICK = typeof arParams.CLOSE_ON_CLICK != 'undefined' ? !!arParams.CLOSE_ON_CLICK : true;
2223	this.ADJUST_ON_CLICK = typeof arParams.ADJUST_ON_CLICK != 'undefined' ? !!arParams.ADJUST_ON_CLICK : true;
2224
2225	this.TYPE = this.PARAMS.TYPE == 'hover' ? 'hover' : 'click';
2226
2227	this._openTimeout = null;
2228
2229	if (this.PARAMS.TYPE == 'hover' && arParams.TIMEOUT !== 0)
2230		this.TIMEOUT = arParams.TIMEOUT || 1000;
2231	else
2232		this.TIMEOUT = 0;
2233
2234	if (!!this.PARAMS.MENU_URL)
2235	{
2236		this.bMenuLoaded = false;
2237		this.bMenuLoading = false;
2238
2239		this.MENU = [{
2240			TEXT: BX.message('JS_CORE_LOADING'),
2241			CLOSE_ON_CLICK: false
2242		}];
2243
2244		if (this.PARAMS.MENU_PRELOAD)
2245		{
2246			BX.defer(this.Load, this)();
2247		}
2248	}
2249
2250	BX.ready(BX.defer(this.Init, this));
2251};
2252
2253BX.COpener.prototype.Init = function()
2254{
2255	this.DIV = BX(this.DIV);
2256
2257	switch (this.TYPE)
2258	{
2259		case 'hover':
2260			BX.bind(this.DIV, 'mouseover', BX.proxy(this.Open, this));
2261			BX.bind(this.DIV, 'click', BX.proxy(this.Toggle, this));
2262		break;
2263
2264		case 'click':
2265			BX.bind(this.DIV, 'click', BX.proxy(this.Toggle, this));
2266		break;
2267	}
2268
2269	//BX.bind(window, 'scroll', BX.delegate(this.__close_immediately, this));
2270
2271	this.bMenuInit = false;
2272};
2273
2274BX.COpener.prototype.Load = function()
2275{
2276	if (this.PARAMS.MENU_URL && !this.bMenuLoaded)
2277	{
2278		if (!this.bMenuLoading)
2279		{
2280			var url = this.PARAMS.MENU_URL;
2281			if (url.indexOf('sessid=') <= 0)
2282				url += (url.indexOf('?') > 0 ? '&' : '?') + 'sessid=' + BX.bitrix_sessid();
2283
2284			this.bMenuLoading = true;
2285			BX.ajax.loadJSON(url, BX.proxy(this.SetMenu, this), BX.proxy(this.LoadFailed, this));
2286		}
2287	}
2288};
2289
2290BX.COpener.prototype.SetMenu = function(menu)
2291{
2292	this.bMenuLoaded = true;
2293	this.bMenuLoading = false;
2294	if (this.bMenuInit)
2295	{
2296		this.MENU.setItems(menu);
2297	}
2298	else
2299	{
2300		this.MENU = menu;
2301	}
2302};
2303
2304BX.COpener.prototype.LoadFailed = function(type, error)
2305{
2306	this.bMenuLoading = false;
2307	this.SetMenu([{
2308		TEXT: BX.message('JS_CORE_NO_DATA'),
2309		CLOSE_ON_CLICK: true
2310	}]);
2311	BX.debug(arguments);
2312};
2313
2314BX.COpener.prototype.checkAdminMenu = function()
2315{
2316	if (document.documentElement.id == 'bx-admin-prefix')
2317		return true;
2318
2319	return !!BX.findParent(this.DIV, {property: {id: 'bx-admin-prefix'}});
2320};
2321
2322BX.COpener.prototype.Toggle = function(e)
2323{
2324	this.__clear_timeout();
2325
2326	if (!this.bMenuInit || !this.MENU.visible())
2327	{
2328		var t = this.TIMEOUT;
2329		this.TIMEOUT = 0;
2330		this.Open(e);
2331		this.TIMEOUT = t;
2332	}
2333	else
2334	{
2335		this.MENU.Close();
2336	}
2337
2338	return !!(e||window.event) && BX.PreventDefault(e);
2339};
2340
2341BX.COpener.prototype.GetMenu = function()
2342{
2343	if (!this.bMenuInit)
2344	{
2345		if (BX.type.isArray(this.MENU))
2346		{
2347			this.MENU = new BX.CMenu({
2348				ITEMS: this.MENU,
2349				ATTACH_MODE: this.ATTACH_MODE,
2350				SET_ID: this.checkAdminMenu() ? 'bx-admin-prefix' : '',
2351				CLOSE_ON_CLICK: !!this.CLOSE_ON_CLICK,
2352				ADJUST_ON_CLICK: !!this.ADJUST_ON_CLICK,
2353				LEVEL: this.LEVEL,
2354				parent: BX(this.DIV),
2355				parent_attach: BX(this.ATTACH)
2356			});
2357
2358			if (this.LEVEL > 0)
2359			{
2360				BX.bind(this.MENU.DIV, 'mouseover', BX.proxy(this._on_menu_hover, this));
2361				BX.bind(this.MENU.DIV, 'mouseout', BX.proxy(this._on_menu_hout, this));
2362			}
2363		}
2364
2365		BX.addCustomEvent(this.MENU, 'onMenuOpen', BX.proxy(this.handler_onopen, this));
2366		BX.addCustomEvent(this.MENU, 'onMenuClose', BX.proxy(this.handler_onclose, this));
2367
2368		BX.addCustomEvent('onMenuItemHover', BX.proxy(this.handler_onover, this));
2369
2370		this.bMenuInit = true;
2371	}
2372
2373	return this.MENU;
2374};
2375
2376BX.COpener.prototype.Open = function()
2377{
2378	this.GetMenu();
2379
2380	this.bOpen = true;
2381
2382	this.__clear_timeout();
2383
2384	if (this.TIMEOUT > 0)
2385	{
2386		BX.bind(this.DIV, 'mouseout', BX.proxy(this.__clear_timeout, this));
2387		this._openTimeout = setTimeout(BX.proxy(this.__open, this), this.TIMEOUT);
2388	}
2389	else
2390	{
2391		this.__open();
2392	}
2393
2394	if (!!this.PARAMS.MENU_URL && !this.bMenuLoaded)
2395	{
2396		this._loadTimeout = setTimeout(BX.proxy(this.Load, this), parseInt(this.TIMEOUT/2));
2397	}
2398
2399	return true;
2400};
2401
2402BX.COpener.prototype.__clear_timeout = function()
2403{
2404	if (!!this._openTimeout)
2405		clearTimeout(this._openTimeout);
2406	if (!!this._loadTimeout)
2407		clearTimeout(this._loadTimeout);
2408
2409	BX.unbind(this.DIV, 'mouseout', BX.proxy(this.__clear_timeout, this));
2410};
2411
2412BX.COpener.prototype._on_menu_hover = function()
2413{
2414	this.bMenuHover = true;
2415
2416	this.__clear_timeout();
2417
2418	if (this.ACTIVE_CLASS)
2419		BX.addClass(this.DIV, this.ACTIVE_CLASS);
2420
2421};
2422
2423BX.COpener.prototype._on_menu_hout = function()
2424{
2425	this.bMenuHover = false;
2426};
2427
2428BX.COpener.prototype.handler_onover = function(level, opener)
2429{
2430	if (this.bMenuHover)
2431		return;
2432
2433	if (opener != this && level == this.LEVEL-1 && this.ACTIVE_CLASS)
2434	{
2435		BX.removeClass(this.DIV, this.ACTIVE_CLASS);
2436	}
2437
2438	if (this.bMenuInit && level <= this.LEVEL-1 && this.MENU.visible())
2439	{
2440		if (opener != this)
2441		{
2442			this.__clear_timeout();
2443			this._openTimeout = setTimeout(BX.proxy(this.Close, this), this.TIMEOUT);
2444		}
2445	}
2446};
2447
2448BX.COpener.prototype.handler_onopen = function()
2449{
2450	this.bOpen = true;
2451
2452	if (this.ACTIVE_CLASS)
2453		BX.addClass(this.DIV, this.ACTIVE_CLASS);
2454
2455	BX.defer(function() {
2456		BX.onCustomEvent(this, 'onOpenerMenuOpen');
2457	}, this)();
2458};
2459
2460BX.COpener.prototype.handler_onclose = function()
2461{
2462	this.bOpen = false;
2463	BX.onCustomEvent(this, 'onOpenerMenuClose');
2464
2465	if (this.ACTIVE_CLASS)
2466		BX.removeClass(this.DIV, this.ACTIVE_CLASS);
2467};
2468
2469BX.COpener.prototype.Close = function()
2470{
2471	if (!this.bMenuInit)
2472		return;
2473
2474	if (!!this._openTimeout)
2475		clearTimeout(this._openTimeout);
2476
2477	this.bOpen = false;
2478
2479	this.__close();
2480};
2481
2482BX.COpener.prototype.__open = function()
2483{
2484	this.__clear_timeout();
2485
2486	if (this.bMenuInit && this.bOpen && !this.MENU.visible())
2487		this.MENU.Show();
2488};
2489
2490BX.COpener.prototype.__close = function()
2491{
2492	if (this.bMenuInit && !this.bOpen && this.MENU.visible())
2493		this.MENU.Hide();
2494};
2495
2496BX.COpener.prototype.__close_immediately = function() {
2497	this.bOpen = false; this.__close();
2498};
2499
2500BX.COpener.prototype.isMenuVisible = function() {
2501	return null != this.MENU.visible && this.MENU.visible()
2502};
2503
2504/* common menu class */
2505
2506BX.CMenu = function(arParams)
2507{
2508	BX.CMenu.superclass.constructor.apply(this);
2509
2510	this.DIV.style.width = 'auto';//this.DIV.firstChild.offsetWidth + 'px';
2511	this.DIV.style.height = 'auto';//this.DIV.firstChild.offsetHeight + 'px';
2512
2513	this.PARAMS = arParams || {};
2514	this.PARTS = {};
2515
2516	this.PARAMS.ATTACH_MODE = this.PARAMS.ATTACH_MODE || 'bottom';
2517	this.PARAMS.CLOSE_ON_CLICK = typeof this.PARAMS.CLOSE_ON_CLICK == 'undefined' ? true : this.PARAMS.CLOSE_ON_CLICK;
2518	this.PARAMS.ADJUST_ON_CLICK = typeof this.PARAMS.ADJUST_ON_CLICK == 'undefined' ? true : this.PARAMS.ADJUST_ON_CLICK;
2519	this.PARAMS.LEVEL = this.PARAMS.LEVEL || 0;
2520
2521	this.DIV.className = 'bx-core-popup-menu bx-core-popup-menu-' + this.PARAMS.ATTACH_MODE + ' bx-core-popup-menu-level' + this.PARAMS.LEVEL + (typeof this.PARAMS.ADDITIONAL_CLASS != 'undefined' ? ' ' + this.PARAMS.ADDITIONAL_CLASS : '');
2522	if (!!this.PARAMS.SET_ID)
2523		this.DIV.id = this.PARAMS.SET_ID;
2524
2525	if (this.PARAMS.LEVEL == 0)
2526	{
2527		this.ARROW = this.DIV.appendChild(BX.create('SPAN', {props: {className: 'bx-core-popup-menu-angle'}, style: {left:'15px'}}));
2528	}
2529
2530	if (!!this.PARAMS.CLASS_NAME)
2531		this.DIV.className += ' ' + this.PARAMS.CLASS_NAME;
2532
2533	BX.bind(this.DIV, 'click', BX.eventCancelBubble);
2534
2535	this.ITEMS = [];
2536
2537	this.setItems(this.PARAMS.ITEMS);
2538
2539	BX.addCustomEvent('onMenuOpen', BX.proxy(this._onMenuOpen, this));
2540	BX.addCustomEvent('onMenuItemSelected', BX.proxy(this.Hide, this));
2541};
2542BX.extend(BX.CMenu, BX.CWindowFloat);
2543
2544BX.CMenu.broadcastCloseEvent = function()
2545{
2546	BX.onCustomEvent("onMenuItemSelected");
2547};
2548
2549BX.CMenu._toggleChecked = function()
2550{
2551	BX.toggleClass(this, 'bx-core-popup-menu-item-checked');
2552};
2553
2554BX.CMenu._itemDblClick = function()
2555{
2556	window.location.href = this.href;
2557};
2558
2559BX.CMenu.prototype.toggleArrow = function(v)
2560{
2561	if (!!this.ARROW)
2562	{
2563		if (typeof v == 'undefined')
2564		{
2565			v = this.ARROW.style.visibility == 'hidden';
2566		}
2567
2568		this.ARROW.style.visibility = !!v ? 'visible' : 'hidden';
2569	}
2570};
2571
2572BX.CMenu.prototype.visible = function()
2573{
2574	return this.DIV.style.display !== 'none';
2575};
2576
2577BX.CMenu.prototype._onMenuOpen = function(menu, menu_level)
2578{
2579	if (this.visible())
2580	{
2581		if (menu_level == this.PARAMS.LEVEL && menu != this)
2582		{
2583			this.Hide();
2584		}
2585	}
2586};
2587
2588BX.CMenu.prototype.onUnRegister = function()
2589{
2590	if (!this.visible())
2591		return;
2592
2593	this.Hide();
2594};
2595
2596BX.CMenu.prototype.setItems = function(items)
2597{
2598	this.PARAMS.ITEMS = items;
2599
2600	BX.cleanNode(this.DIV);
2601
2602	if (!!this.ARROW)
2603		this.DIV.appendChild(this.ARROW);
2604
2605	if (this.PARAMS.ITEMS)
2606	{
2607		this.PARAMS.ITEMS = BX.util.array_values(this.PARAMS.ITEMS);
2608
2609		var bIcons = false;
2610		var cnt = 0;
2611		for (var i = 0, len = this.PARAMS.ITEMS.length; i < len; i++)
2612		{
2613			if ((i == 0 || i == len-1) && this.PARAMS.ITEMS[i].SEPARATOR)
2614				continue;
2615
2616			cnt++;
2617
2618			if (!bIcons)
2619				bIcons = !!this.PARAMS.ITEMS[i].GLOBAL_ICON;
2620
2621			this.addItem(this.PARAMS.ITEMS[i], i);
2622		}
2623
2624		// Occam turning in his grave
2625		if (cnt === 1)
2626			BX.addClass(this.DIV, 'bx-core-popup-menu-single-item');
2627		else
2628			BX.removeClass(this.DIV, 'bx-core-popup-menu-single-item');
2629
2630		if (!bIcons)
2631			BX.addClass(this.DIV, 'bx-core-popup-menu-no-icons');
2632		else
2633			BX.removeClass(this.DIV, 'bx-core-popup-menu-no-icons');
2634
2635	}
2636};
2637
2638BX.CMenu.prototype.addItem = function(item)
2639{
2640	this.ITEMS.push(item);
2641
2642	if (item.SEPARATOR)
2643	{
2644		item.NODE = BX.create(
2645			'DIV', {props: {className: 'bx-core-popup-menu-separator'}}
2646		);
2647	}
2648	else
2649	{
2650		var bHasMenu = (!!item.MENU
2651			&& (
2652				(BX.type.isArray(item.MENU) && item.MENU.length > 0)
2653				|| item.MENU instanceof BX.CMenu
2654			) || !!item.MENU_URL
2655		);
2656
2657		if (item.DISABLED)
2658		{
2659			item.CLOSE_ON_CLICK = false;
2660			item.LINK = null;
2661			item.ONCLICK = null;
2662			item.ACTION = null;
2663		}
2664
2665		item.NODE = BX.create(!!item.LINK || BX.browser.IsIE() && !BX.browser.IsDoctype() ? 'A' : 'SPAN', {
2666			props: {
2667				className: 'bx-core-popup-menu-item'
2668					+ (bHasMenu ? ' bx-core-popup-menu-item-opener' : '')
2669					+ (!!item.DEFAULT ? ' bx-core-popup-menu-item-default' : '')
2670					+ (!!item.DISABLED ? ' bx-core-popup-menu-item-disabled' : '')
2671					+ (!!item.CHECKED ? ' bx-core-popup-menu-item-checked' : ''),
2672					title: !!BX.message['MENU_ENABLE_TOOLTIP'] || !!item.SHOW_TITLE ? item.TITLE || '' : '',
2673				BXMENULEVEL: this.PARAMS.LEVEL
2674			},
2675			attrs: !!item.LINK || BX.browser.IsIE() && !BX.browser.IsDoctype() ? {href: item.LINK || 'javascript:void(0)'} : {},
2676			events: {
2677				mouseover: function()
2678				{
2679					BX.onCustomEvent('onMenuItemHover', [this.BXMENULEVEL, this.OPENER])
2680				}
2681			},
2682			html: '<span class="bx-core-popup-menu-item-icon' + (item.GLOBAL_ICON ? ' '+item.GLOBAL_ICON : '') + '"></span><span class="bx-core-popup-menu-item-text">'+(item.HTML||(item.TEXT? BX.util.htmlspecialchars(item.TEXT) : ''))+'</span>'
2683		});
2684
2685		if (bHasMenu && !item.DISABLED)
2686		{
2687			item.NODE.OPENER = new BX.COpener({
2688				DIV: item.NODE,
2689				ACTIVE_CLASS: 'bx-core-popup-menu-item-opened',
2690				TYPE: 'hover',
2691				MENU: item.MENU,
2692				MENU_URL: item.MENU_URL,
2693				MENU_PRELOAD: !!item.MENU_PRELOAD,
2694				LEVEL: this.PARAMS.LEVEL + 1,
2695				ATTACH_MODE:'right',
2696				TIMEOUT: 500
2697			});
2698		}
2699		else if (this.PARAMS.CLOSE_ON_CLICK && (typeof item.CLOSE_ON_CLICK == 'undefined' || !!item.CLOSE_ON_CLICK))
2700		{
2701			BX.bind(item.NODE, 'click', BX.CMenu.broadcastCloseEvent);
2702		}
2703		else if (this.PARAMS.ADJUST_ON_CLICK && (typeof item.ADJUST_ON_CLICK == 'undefined' || !!item.ADJUST_ON_CLICK))
2704		{
2705			BX.bind(item.NODE, 'click', BX.defer(this.adjustPos, this));
2706		}
2707
2708		if (bHasMenu && !!item.LINK)
2709		{
2710			BX.bind(item.NODE, 'dblclick', BX.CMenu._itemDblClick);
2711		}
2712
2713		if (typeof item.CHECKED != 'undefined')
2714		{
2715			BX.bind(item.NODE, 'click', BX.CMenu._toggleChecked);
2716		}
2717
2718		item.ONCLICK = item.ACTION || item.ONCLICK;
2719		if (!!item.ONCLICK)
2720		{
2721			if (BX.type.isString(item.ONCLICK))
2722			{
2723				item.ONCLICK = new Function("event", item.ONCLICK);
2724			}
2725
2726			BX.bind(item.NODE, 'click', item.ONCLICK);
2727		}
2728	}
2729
2730	this.DIV.appendChild(item.NODE);
2731};
2732
2733BX.CMenu.prototype._documentClickBind = function()
2734{
2735	this._documentClickUnBind();
2736	BX.bind(document, 'click', BX.proxy(this._documentClick, this));
2737};
2738
2739BX.CMenu.prototype._documentClickUnBind = function()
2740{
2741	BX.unbind(document, 'click', BX.proxy(this._documentClick, this));
2742};
2743
2744BX.CMenu.prototype._documentClick = function(e)
2745{
2746	e = e||window.event;
2747	if(!!e && !(BX.getEventButton(e) & BX.MSLEFT))
2748		return;
2749
2750	this.Close();
2751};
2752
2753BX.CMenu.prototype.Show = function()
2754{
2755	BX.onCustomEvent(this, 'onMenuOpen', [this, this.PARAMS.LEVEL]);
2756	BX.CMenu.superclass.Show.apply(this, []);
2757
2758	this.bCloseEventFired = false;
2759
2760	BX.addCustomEvent(this.PARAMS.parent_attach, 'onChangeNodePosition', BX.proxy(this.adjustToNode, this));
2761
2762	(BX.defer(this._documentClickBind, this))();
2763};
2764
2765BX.CMenu.prototype.Close = // we shouldn't 'Close' window - only hide
2766BX.CMenu.prototype.Hide = function()
2767{
2768	if (!this.visible())
2769		return;
2770
2771	BX.removeCustomEvent(this.PARAMS.parent_attach, 'onChangeNodePosition', BX.proxy(this.adjustToNode, this));
2772
2773	this._documentClickUnBind();
2774
2775	if (!this.bCloseEventFired)
2776	{
2777		BX.onCustomEvent(this, 'onMenuClose', [this, this.PARAMS.LEVEL]);
2778		this.bCloseEventFired = true;
2779	}
2780	BX.CMenu.superclass.Hide.apply(this, arguments);
2781
2782
2783//	this.DIV.onclick = null;
2784	//this.PARAMS.parent.onclick = null;
2785};
2786
2787BX.CMenu.prototype.__adjustMenuToNode = function()
2788{
2789	var pos = BX.pos(this.PARAMS.parent_attach),
2790		bFixed = !!BX.findParent(this.PARAMS.parent_attach, BX.is_fixed);
2791
2792	if (bFixed)
2793		this.DIV.style.position = 'fixed';
2794	else
2795		this.DIV.style.position = 'absolute';
2796
2797	if (!pos.top)
2798	{
2799		this.DIV.style.top = '-1000px';
2800		this.DIV.style.left = '-1000px';
2801	}
2802
2803	if (this.bTimeoutSet) return;
2804
2805	var floatWidth = this.DIV.offsetWidth, floatHeight = this.DIV.offsetHeight;
2806	if (!floatWidth)
2807	{
2808		setTimeout(BX.delegate(function(){
2809			this.bTimeoutSet = false; this.__adjustMenuToNode();
2810		}, this), 100);
2811
2812		this.bTimeoutSet = true;
2813		return;
2814	}
2815
2816	var menu_pos = {},
2817		wndSize = BX.GetWindowSize();
2818
2819/*
2820	if (BX.browser.IsIE() && !BX.browser.IsDoctype())
2821	{
2822		pos.top -= 4; pos.bottom -= 4;
2823		pos.left -= 2; pos.right -= 2;
2824	}
2825*/
2826
2827	switch (this.PARAMS.ATTACH_MODE)
2828	{
2829		case 'bottom':
2830			menu_pos.top = pos.bottom + 9;
2831			menu_pos.left = pos.left;
2832
2833			var arrowPos = 0;
2834			if (!!this.ARROW)
2835			{
2836				if (pos.width > floatWidth)
2837					arrowPos = parseInt(floatWidth/2 - 7);
2838				else
2839					arrowPos = parseInt(Math.min(floatWidth, pos.width)/2 - 7);
2840
2841				if (arrowPos < 7)
2842				{
2843					menu_pos.left -= 15;
2844					arrowPos += 15;
2845				}
2846			}
2847
2848			if (menu_pos.left > wndSize.scrollWidth - floatWidth - 10)
2849			{
2850				var orig_menu_pos = menu_pos.left;
2851				menu_pos.left = wndSize.scrollWidth - floatWidth - 10;
2852
2853				if (!!this.ARROW)
2854					arrowPos += orig_menu_pos - menu_pos.left;
2855			}
2856
2857			if (bFixed)
2858			{
2859				menu_pos.left -= wndSize.scrollLeft;
2860			}
2861
2862			if (!!this.ARROW)
2863				this.ARROW.style.left = arrowPos + 'px';
2864		break;
2865		case 'right':
2866			menu_pos.top = pos.top-1;
2867			menu_pos.left = pos.right;
2868
2869			if (menu_pos.left > wndSize.scrollWidth - floatWidth - 10)
2870			{
2871				menu_pos.left = pos.left - floatWidth - 1;
2872			}
2873		break;
2874	}
2875
2876	if (bFixed)
2877	{
2878		menu_pos.top -= wndSize.scrollTop;
2879	}
2880
2881	if (!!this.ARROW)
2882		this.ARROW.className = 'bx-core-popup-menu-angle';
2883
2884	if((menu_pos.top + floatHeight >
2884 wndSize.scrollTop + wndSize.innerHeight)
2885		|| (menu_pos.top + floatHeight > wndSize.scrollHeight))
2886	{
2887		var new_top = this.PARAMS.ATTACH_MODE == 'bottom'
2888			? pos.top - floatHeight - 9
2889			: pos.bottom - floatHeight + 1;
2890
2891		if((new_top > wndSize.scrollTop)
2892			|| (menu_pos.top + floatHeight > wndSize.scrollHeight))
2893		{
2894			if ((menu_pos.top + floatHeight > wndSize.scrollHeight))
2895			{
2896				menu_pos.top = Math.max(0, wndSize.scrollHeight-floatHeight);
2897				this.toggleArrow(false);
2898			}
2899			else
2900			{
2901				menu_pos.top = new_top;
2902
2903				if (!!this.ARROW)
2904					this.ARROW.className = 'bx-core-popup-menu-angle-bottom';
2905			}
2906		}
2907	}
2908
2909	if (menu_pos.top + menu_pos.left == 0)
2910	{
2911		this.Hide();
2912	}
2913	else
2914	{
2915		this.DIV.style.top = menu_pos.top + 'px';
2916		this.DIV.style.left = menu_pos.left + 'px';
2917	}
2918};
2919
2920BX.CMenu.prototype.adjustToNode = function(el)
2921{
2922	this.PARAMS.parent_attach = BX(el) || this.PARAMS.parent_attach || this.PARAMS.parent;
2923	this.__adjustMenuToNode();
2924};
2925
2926
2927/* components toolbar class */
2928
2929BX.CMenuOpener = function(arParams)
2930{
2931	BX.CMenuOpener.superclass.constructor.apply(this);
2932
2933	this.PARAMS = arParams || {};
2934	this.setParent(this.PARAMS.parent);
2935	this.PARTS = {};
2936
2937	this.SETTINGS.drag_restrict = true;
2938
2939	this.defaultAction = null;
2940
2941	this.timeout = 500;
2942
2943	this.DIV.className = 'bx-component-opener';
2944	this.DIV.ondblclick = BX.PreventDefault;
2945
2946	if (this.PARAMS.component_id)
2947	{
2948		this.PARAMS.transform = !!this.PARAMS.transform;
2949	}
2950
2951	this.OPENERS = [];
2952
2953	this.DIV.appendChild(BX.create('SPAN', {
2954		props: {className: 'bx-context-toolbar' + (this.PARAMS.transform ? ' bx-context-toolbar-vertical-mode' : '')}
2955	}));
2956
2957	//set internal structure and register draggable element
2958	this.PARTS.INNER = this.DIV.firstChild.appendChild(BX.create('SPAN', {
2959		props: {className: 'bx-context-toolbar-inner'},
2960		html: '<span class="bx-context-toolbar-drag-icon"></span><span class="bx-context-toolbar-vertical-line"></span><br>'
2961	}));
2962
2963	this.EXTRA_BUTTONS = {};
2964
2965	var btnCount = 0;
2966	for (var i = 0, len = this.PARAMS.menu.length; i < len; i++)
2967	{
2968		var item = this.addItem(this.PARAMS.menu[i]);
2969		if (null != item)
2970		{
2971			btnCount++;
2972			this.PARTS.INNER.appendChild(item);
2973			this.PARTS.INNER.appendChild(BX.create('BR'));
2974		}
2975	}
2976	var bHasButtons = btnCount > 0;
2977
2978	//menu items will be attached here
2979
2980	this.PARTS.ICONS = this.PARTS.INNER.appendChild(BX.create('SPAN', {
2981		props: {className: 'bx-context-toolbar-icons'}
2982	}));
2983
2984	if (this.PARAMS.component_id)
2985	{
2986		this.PARAMS.pin = !!this.PARAMS.pin;
2987
2988		if (bHasButtons)
2989			this.PARTS.ICONS.appendChild(BX.create('SPAN', {props: {className: 'bx-context-toolbar-separator'}}));
2990
2991		this.PARTS.ICON_PIN = this.PARTS.ICONS.appendChild(BX.create('A', {
2992			attrs: {
2993				href: 'javascript:void(0)'
2994			},
2995			props: {
2996				className: this.PARAMS.pin
2997							? 'bx-context-toolbar-pin-fixed'
2998							: 'bx-context-toolbar-pin'
2999			},
3000			events: {
3001				click: BX.delegate(this.__pin_btn_clicked, this)
3002			}
3003		}));
3004	}
3005
3006
3007	if (this.EXTRA_BUTTONS['components2_props'])
3008	{
3009		var btn = this.EXTRA_BUTTONS['components2_props'] || {URL: 'javascript:void(0)'};
3010		if (null == this.defaultAction)
3011		{
3012			this.defaultAction = btn.ONCLICK;
3013			this.defaultActionTitle = btn.TITLE || btn.TEXT;
3014		}
3015
3016		btn.URL = 'javascript:' + BX.util.urlencode(btn.ONCLICK);
3017
3018		this.ATTACH = this.PARTS.ICONS.appendChild(BX.create('SPAN', {
3019			props: {className: 'bx-context-toolbar-button bx-context-toolbar-button-settings' },
3020			children:
3021			[
3022				BX.create('SPAN',
3023				{
3024					props:{className: 'bx-context-toolbar-button-inner'},
3025					children:
3026					[
3027						BX.create('A', {
3028							attrs: {href: btn.URL},
3029							events: {
3030								mouseover: BX.proxy(this.__msover_text, this),
3031								mouseout: BX.proxy(this.__msout_text, this),
3032								mousedown: BX.proxy(this.__msdown_text, this)
3033							},
3034							html: '<span class="bx-context-toolbar-button-icon bx-context-toolbar-settings-icon"></span>'
3035						}),
3036						BX.create('A', {
3037							attrs: {href: 'javascript: void(0)'},
3038							props: {className: 'bx-context-toolbar-button-arrow'},
3039							events: {
3040								mouseover: BX.proxy(this.__msover_arrow, this),
3041								mouseout: BX.proxy(this.__msout_arrow, this),
3042								mousedown: BX.proxy(this.__msdown_arrow, this)
3043							},
3044							html: '<span class="bx-context-toolbar-button-arrow"></span>'
3045						})
3046					]
3047				})
3048			]
3049		}));
3050
3051		this.OPENER = this.ATTACH.firstChild.lastChild;
3052
3053		var opener = this.attachMenu(this.EXTRA_BUTTONS['components2_submenu']['MENU']);
3054
3055		BX.addCustomEvent(opener, 'onOpenerMenuOpen', BX.proxy(this.__menu_open, this));
3056		BX.addCustomEvent(opener, 'onOpenerMenuClose', BX.proxy(this.__menu_close, this));
3057	}
3058
3059	if (btnCount > 1)
3060	{
3061		this.PARTS.ICONS.appendChild(BX.create('span', { props: {className: 'bx-context-toolbar-separator bx-context-toolbar-separator-switcher'}}));
3062
3063		this.ICON_TRANSFORM = this.PARTS.ICONS.appendChild(BX.create('A', {
3064			attrs: {href: 'javascript: void(0)'},
3065			props: {className: 'bx-context-toolbar-switcher'},
3066			events: {
3067				click: BX.delegate(this.__trf_btn_clicked, this)
3068			}
3069		}));
3070	}
3071
3072	if (this.PARAMS.HINT)
3073	{
3074		this.DIV.BXHINT = this.HINT = new BX.CHint({
3075			parent: this.DIV,
3076			hint:this.PARAMS.HINT.TEXT || '',
3077			title: this.PARAMS.HINT.TITLE || '',
3078			hide_timeout: this.timeout/2,
3079			preventHide: false
3080		});
3081	}
3082
3083	BX.addCustomEvent(this, 'onWindowDragFinished', BX.delegate(this.__onMoveFinished, this));
3084	BX.addCustomEvent('onDynamicModeChange', BX.delegate(this.__onDynamicModeChange, this));
3085	BX.addCustomEvent('onTopPanelCollapse', BX.delegate(this.__onPanelCollapse, this));
3086
3087	BX.addCustomEvent('onMenuOpenerMoved', BX.delegate(this.checkPosition, this));
3088	BX.addCustomEvent('onMenuOpenerUnhide', BX.delegate(this.checkPosition, this));
3089
3090	if (this.OPENERS)
3091	{
3092		for (i=0,len=this.OPENERS.length; i<len; i++)
3093		{
3094			BX.addCustomEvent(this.OPENERS[i], 'onOpenerMenuOpen', BX.proxy(this.__hide_hint, this));
3095		}
3096	}
3097};
3098BX.extend(BX.CMenuOpener, BX.CWindowFloat);
3099
3100BX.CMenuOpener.prototype.setParent = function(new_parent)
3101{
3102	new_parent = BX(new_parent);
3103	if(new_parent.OPENER && new_parent.OPENER != this)
3104	{
3105		new_parent.OPENER.Close();
3106		new_parent.OPENER.clearHoverHoutEvents();
3107	}
3108
3109	if(this.PARAMS.parent && this.PARAMS.parent != new_parent)
3110	{
3111		this.clearHoverHoutEvents();
3112		this.PARAMS.parent.OPENER = null;
3113	}
3114
3115	this.PARAMS.parent = new_parent;
3116	this.PARAMS.parent.OPENER = this;
3117};
3118
3119BX.CMenuOpener.prototype.setHoverHoutEvents = function(hover, hout)
3120{
3121	if(!this.__opener_events_set)
3122	{
3123		BX.bind(this.Get(), 'mouseover', hover);
3124		BX.bind(this.Get(), 'mouseout', hout);
3125		this.__opener_events_set = true;
3126	}
3127};
3128
3129BX.CMenuOpener.prototype.clearHoverHoutEvents = function()
3130{
3131	if(this.Get())
3132	{
3133		BX.unbindAll(this.Get());
3134		this.__opener_events_set = false;
3135	}
3136};
3137
3138
3139BX.CMenuOpener.prototype.unclosable = true;
3140
3141BX.CMenuOpener.prototype.__check_intersection = function(pos_self, pos_other)
3142{
3143	return !(pos_other.right <= pos_self.left || pos_other.left >= pos_self.right
3144			|| pos_other.bottom <= pos_self.top || pos_other.top >= pos_self.bottom);
3145};
3146
3147
3148BX.CMenuOpener.prototype.__msover_text = function() {
3149	this.bx_hover = true;
3150	if (!this._menu_open)
3151		BX.addClass(this.ATTACH, 'bx-context-toolbar-button-text-hover');
3152};
3153
3154BX.CMenuOpener.prototype.__msout_text = function() {
3155	this.bx_hover = false;
3156	if (!this._menu_open)
3157		BX.removeClass(this.ATTACH, 'bx-context-toolbar-button-text-hover bx-context-toolbar-button-text-active');
3158};
3159
3160BX.CMenuOpener.prototype.__msover_arrow = function() {
3161	this.bx_hover = true;
3162	if (!this._menu_open)
3163		BX.addClass(this.ATTACH, 'bx-context-toolbar-button-arrow-hover');
3164};
3165
3166BX.CMenuOpener.prototype.__msout_arrow = function() {
3167	this.bx_hover = false;
3168	if (!this._menu_open)
3169		BX.removeClass(this.ATTACH, 'bx-context-toolbar-button-arrow-hover bx-context-toolbar-button-arrow-active');
3170};
3171
3172BX.CMenuOpener.prototype.__msdown_text = function() {
3173	this.bx_active = true;
3174	if (!this._menu_open)
3175		BX.addClass(this.ATTACH, 'bx-context-toolbar-button-text-active');
3176};
3177
3178BX.CMenuOpener.prototype.__msdown_arrow = function() {
3179	this.bx_active = true;
3180	if (!this._menu_open)
3181		BX.addClass(this.ATTACH, 'bx-context-toolbar-button-arrow-active');
3182};
3183
3184BX.CMenuOpener.prototype.__menu_close = function() {
3185	this._menu_open = false;
3186	this.bx_active = false;
3187	BX.removeClass(this.ATTACH, 'bx-context-toolbar-button-active bx-context-toolbar-button-text-active bx-context-toolbar-button-arrow-active');
3188	if (!this.bx_hover)
3189	{
3190		BX.removeClass(this.ATTACH, 'bx-context-toolbar-button-hover bx-context-toolbar-button-text-hover bx-context-toolbar-button-arrow-hover');
3191		this.bx_hover = false;
3192	}
3193};
3194
3195BX.CMenuOpener.prototype.__menu_open = function() {
3196	this._menu_open = true;
3197};
3198
3199BX.CMenuOpener.prototype.checkPosition = function()
3200{
3201	if (this.isMenuVisible() || this.DIV.style.display == 'none'
3202		|| this == BX.proxy_context || BX.proxy_context.zIndex > this.zIndex)
3203		return;
3204
3205	this.correctPosition(BX.proxy_context);
3206};
3207
3208BX.CMenuOpener.prototype.correctPosition = function(opener)
3209{
3210	var pos_self = BX.pos(this.DIV), pos_other = BX.pos(opener.Get());
3211	if (this.__check_intersection(pos_self, pos_other))
3212	{
3213		var new_top = pos_other.top - pos_self.height;
3214		if (new_top < 0)
3215			new_top = pos_other.bottom;
3216
3217		this.DIV.style.top = new_top + 'px';
3218
3219		BX.addCustomEvent(opener, 'onMenuOpenerHide', BX.proxy(this.restorePosition, this));
3220		BX.onCustomEvent(this, 'onMenuOpenerMoved');
3221	}
3222};
3223
3224BX.CMenuOpener.prototype.restorePosition = function()
3225{
3226	if (!this.MOUSEOVER && !this.isMenuVisible())
3227	{
3228		if (this.originalPos)
3229			this.DIV.style.top = this.originalPos.top + 'px';
3230
3231		BX.removeCustomEvent(BX.proxy_context, 'onMenuOpenerHide', BX.proxy(this.restorePosition, this));
3232		if (this.restore_pos_timeout) clearTimeout(this.restore_pos_timeout);
3233	}
3234	else
3235	{
3236		this.restore_pos_timeout = setTimeout(BX.proxy(this.restorePosition, this), this.timeout);
3237	}
3238};
3239
3240
3241BX.CMenuOpener.prototype.Show = function()
3242{
3243	BX.CMenuOpener.superclass.Show.apply(this, arguments);
3244
3245	this.SetDraggable(this.PARTS.INNER.firstChild);
3246
3247	this.DIV.style.width = 'auto';
3248	this.DIV.style.height = 'auto';
3249
3250	if (!this.PARAMS.pin)
3251	{
3252		this.DIV.style.left = '-1000px';
3253		this.DIV.style.top = '-1000px';
3254
3255		this.Hide();
3256	}
3257	else
3258	{
3259		this.bPosAdjusted = true;
3260		this.bMoved = true;
3261
3262		if (this.PARAMS.top) this.DIV.style.top = this.PARAMS.top + 'px';
3263		if (this.PARAMS.left) this.DIV.style.left = this.PARAMS.left + 'px';
3264
3265		this.DIV.style.display = (!BX.admin.dynamic_mode || BX.admin.dynamic_mode_show_borders) ? 'block' : 'none';
3266
3267		if (this.DIV.style.display == 'block')
3268		{
3269			setTimeout(BX.delegate(function() {BX.onCustomEvent(this, 'onMenuOpenerUnhide')}, this), 50);
3270		}
3271	}
3272};
3273
3274BX.CMenuOpener.prototype.executeDefaultAction = function()
3275{
3276	if (this.defaultAction)
3277	{
3278		if (BX.type.isFunction(this.defaultAction))
3279			this.defaultAction();
3280		else if(BX.type.isString(this.defaultAction))
3281			BX.evalGlobal(this.defaultAction);
3282	}
3283};
3284
3285BX.CMenuOpener.prototype.__onDynamicModeChange = function(val)
3286{
3287	this.DIV.style.display = val ? 'block' : 'none';
3288};
3289
3290BX.CMenuOpener.prototype.__onPanelCollapse = function(bCollapsed, dy)
3291{
3292	this.DIV.style.top = (parseInt(this.DIV.style.top) + dy) + 'px';
3293	if (this.PARAMS.pin)
3294	{
3295		this.__savePosition();
3296	}
3297};
3298
3299BX.CMenuOpener.prototype.__onMoveFinished = function()
3300{
3301	BX.onCustomEvent(this, 'onMenuOpenerMoved');
3302
3303	this.bMoved = true;
3304
3305	if (this.PARAMS.pin)
3306		this.__savePosition();
3307};
3308
3309BX.CMenuOpener.prototype.__savePosition = function()
3310{
3311	var arOpts = {};
3312
3313	arOpts.pin = this.PARAMS.pin;
3314	if (!this.PARAMS.pin)
3315	{
3316		arOpts.top = false; arOpts.left = false; arOpts.transform = false;
3317	}
3318	else
3319	{
3320		arOpts.transform = this.PARAMS.transform;
3321		if (this.bMoved)
3322		{
3323			arOpts.left = parseInt(this.DIV.style.left);
3324			arOpts.top = parseInt(this.DIV.style.top);
3325		}
3326	}
3327
3328	BX.WindowManager.saveWindowOptions(this.PARAMS.component_id, arOpts);
3329};
3330
3331BX.CMenuOpener.prototype.__pin_btn_clicked = function() {this.Pin()};
3332BX.CMenuOpener.prototype.Pin = function(val)
3333{
3334	if (null == val)
3335		this.PARAMS.pin = !this.PARAMS.pin;
3336	else
3337		this.PARAMS.pin = !!val;
3338
3339	this.PARTS.ICON_PIN.className = (this.PARAMS.pin ? 'bx-context-toolbar-pin-fixed' : 'bx-context-toolbar-pin');
3340
3341	this.__savePosition();
3342};
3343
3344BX.CMenuOpener.prototype.__trf_btn_clicked = function() {this.Transform()};
3345BX.CMenuOpener.prototype.Transform = function(val)
3346{
3347	var pos = {};
3348
3349	if (null == val)
3350		this.PARAMS.transform = !this.PARAMS.transform;
3351	else
3352		this.PARAMS.transform = !!val;
3353
3354	if (this.bMoved)
3355	{
3356		pos = BX.pos(this.DIV);
3357	}
3358
3359	if (this.PARAMS.transform)
3360		BX.addClass(this.DIV.firstChild, 'bx-context-toolbar-vertical-mode');
3361	else
3362		BX.removeClass(this.DIV.firstChild, 'bx-context-toolbar-vertical-mode');
3363
3364	if (!this.bMoved)
3365	{
3366		this.adjustPos();
3367	}
3368	else
3369	{
3370		this.DIV.style.left = (pos.right - this.DIV.offsetWidth - (BX.browser.IsIE() && !BX.browser.IsDoctype() ? 2 : 0)) + 'px';
3371	}
3372
3373	this.__savePosition();
3374};
3375
3376BX.CMenuOpener.prototype.adjustToNodeGetPos = function()
3377{
3378	var pos = BX.pos(this.PARAMS.parent/*, true*/);
3379
3380	var scrollSize = BX.GetWindowScrollSize();
3381	var floatWidth = this.DIV.offsetWidth;
3382
3383	pos.left -= BX.admin.__border_dx;
3384	pos.top -= BX.admin.__border_dx;
3385
3386	if (true || !this.PARAMS.transform)
3387	{
3388		pos.top -= 45;
3389	}
3390
3391	if (pos.left > scrollSize.scrollWidth - floatWidth)
3392	{
3393		pos.left = scrollSize.scrollWidth - floatWidth;
3394	}
3395
3396	return pos;
3397};
3398
3399BX.CMenuOpener.prototype.addItem = function(item)
3400{
3401	if (item.TYPE)
3402	{
3403		this.EXTRA_BUTTONS[item.TYPE] = item;
3404		return null;
3405	}
3406	else
3407	{
3408		var q = new BX.CMenuOpenerItem(item);
3409		if (null == this.defaultAction)
3410		{
3411			if (q.item.ONCLICK)
3412			{
3413				this.defaultAction = item.ONCLICK;
3414			}
3415			else if (q.item.MENU)
3416			{
3417				this.defaultAction = BX.delegate(function() {this.Open()}, q.item.OPENER);
3418			}
3419
3420			this.defaultActionTitle = item.TITLE || item.TEXT;
3421
3422			BX.addClass(q.Get(), 'bx-content-toolbar-default');
3423		}
3424		if (q.item.OPENER) this.OPENERS[this.OPENERS.length] = q.item.OPENER;
3425		return q.Get();
3426	}
3427};
3428
3429BX.CMenuOpener.prototype.attachMenu = function(menu)
3430{
3431	var opener = new BX.COpener({
3432		'DIV':  this.OPENER,
3433		'ATTACH': this.ATTACH,
3434		'MENU': menu,
3435		'TYPE': 'click'
3436	});
3437
3438	this.OPENERS[this.OPENERS.length] = opener;
3439
3440	return opener;
3441};
3442
3443BX.CMenuOpener.prototype.__hide_hint = function()
3444{
3445	if (this.HINT) this.HINT.__hide_immediately();
3446};
3447
3448BX.CMenuOpener.prototype.isMenuVisible = function()
3449{
3450	for (var i=0,len=this.OPENERS.length; i<len; i++)
3451	{
3452		if (this.OPENERS[i].isMenuVisible())
3453			return true;
3454	}
3455
3456	return false;
3457};
3458
3459BX.CMenuOpener.prototype.Hide = function()
3460{
3461	if (!this.PARAMS.pin)
3462	{
3463		this.DIV.style.display = 'none';
3464		BX.onCustomEvent(this, 'onMenuOpenerHide');
3465	}
3466};
3467BX.CMenuOpener.prototype.UnHide = function()
3468{
3469	this.DIV.style.display = 'block';
3470	if (!this.bPosAdjusted && !this.PARAMS.pin)
3471	{
3472		this.adjustPos();
3473		this.bPosAdjusted = true;
3474	}
3475
3476	if (null == this.originalPos && !this.bMoved)
3477	{
3478		this.originalPos = BX.pos(this.DIV);
3479	}
3480
3481	BX.onCustomEvent(this, 'onMenuOpenerUnhide');
3482};
3483
3484BX.CMenuOpenerItem = function(item)
3485{
3486	this.item = item;
3487
3488	if (this.item.ACTION && !this.item.ONCLICK)
3489	{
3490		this.item.ONCLICK = this.item.ACTION;
3491	}
3492
3493	this.DIV = BX.create('SPAN');
3494	this.DIV.appendChild(BX.create('SPAN', {props: {className: 'bx-context-toolbar-button-underlay'}}));
3495
3496	this.WRAPPER = this.DIV.appendChild(BX.create('SPAN', {
3497		props: {className: 'bx-context-toolbar-button-wrapper'},
3498		children: [
3499			BX.create('SPAN', {
3500				props: {className: 'bx-context-toolbar-button', title: item.TITLE},
3501				children: [
3502					BX.create('SPAN', {
3503						props: {className: 'bx-context-toolbar-button-inner'}
3504					})
3505				]
3506			})
3507		]
3508	}));
3509
3510	var btn_icon = BX.create('SPAN', {
3511		props: {className: 'bx-context-toolbar-button-icon' + (this.item.ICON || this.item.ICONCLASS ? ' ' + (this.item.ICON || this.item.ICONCLASS) : '')},
3512		attrs: (
3513				!(this.item.ICON || this.item.ICONCLASS)
3514				&&
3515				(this.item.SRC || this.item.IMAGE)
3516			)
3517			? {
3518				style: 'background: scroll transparent url(' + (this.item.SRC || this.item.IMAGE) + ') no-repeat center center !important;'
3519			}
3520			: {}
3521	}), btn_text = BX.create('SPAN', {
3522		props: {className: 'bx-context-toolbar-button-text'},
3523		text: this.item.TEXT
3524	});
3525
3526	if (this.item.ACTION && !this.item.ONCLICK)
3527	{
3528		this.item.ONCLICK = this.item.ACTION;
3529	}
3530
3531	this.bHasMenu = !!this.item.MENU;
3532	this.bHasAction = !!this.item.ONCLICK;
3533
3534	if (this.bHasAction)
3535	{
3536		this.LINK = this.WRAPPER.firstChild.firstChild.appendChild(BX.create('A', {
3537			attrs: {
3538				'href': 'javascript: void(0)'
3539			},
3540			events: {
3541				mouseover: this.bHasMenu ? BX.proxy(this.__msover_text, this) : BX.proxy(this.__msover, this),
3542				mouseout: this.bHasMenu ? BX.proxy(this.__msout_text, this) : BX.proxy(this.__msout, this),
3543				mousedown: this.bHasMenu ? BX.proxy(this.__msdown_text, this) : BX.proxy(this.__msdown, this)
3544			},
3545			children: [btn_icon, btn_text]
3546		}));
3547
3548		if (this.bHasMenu)
3549		{
3550			this.LINK_MENU = this.WRAPPER.firstChild.firstChild.appendChild(BX.create('A', {
3551				props: {className: 'bx-context-toolbar-button-arrow'},
3552				attrs: {
3553					'href': 'javascript: void(0)'
3554				},
3555				events: {
3556					mouseover: BX.proxy(this.__msover_arrow, this),
3557					mouseout: BX.proxy(this.__msout_arrow, this),
3558					mousedown: BX.proxy(this.__msdown_arrow, this)
3559				},
3560				children: [
3561					BX.create('SPAN', {props: {className: 'bx-context-toolbar-button-arrow'}})
3562				]
3563			}));
3564		}
3565
3566	}
3567	else if (this.bHasMenu)
3568	{
3569		this.item.ONCLICK = null;
3570
3571		this.LINK = this.LINK_MENU = this.WRAPPER.firstChild.firstChild.appendChild(BX.create('A', {
3572			attrs: {
3573				'href': 'javascript: void(0)'
3574			},
3575			events: {
3576				mouseover: BX.proxy(this.__msover, this),
3577				mouseout: BX.proxy(this.__msout, this),
3578				mousedown: BX.proxy(this.__msdown, this)
3579			},
3580			children: [
3581				btn_icon,
3582				btn_text
3583			]
3584		}));
3585
3586		this.LINK.appendChild(BX.create('SPAN', {props: {className: 'bx-context-toolbar-single-button-arrow'}}));
3587
3588	}
3589
3590	if (this.bHasMenu)
3591	{
3592		this.item.SUBMENU = new BX.CMenu({
3593			ATTACH_MODE:'bottom',
3594			ITEMS:this.item['MENU'],
3595			//PARENT_MENU:this.parentMenu,
3596			parent: this.LINK_MENU,
3597			parent_attach: this.WRAPPER.firstChild
3598		});
3599
3600		this.item.OPENER = new BX.COpener({
3601			DIV: this.LINK_MENU,
3602			TYPE: 'click',
3603			MENU: this.item.SUBMENU
3604		});
3605
3606		BX.addCustomEvent(this.item.OPENER, 'onOpenerMenuOpen', BX.proxy(this.__menu_open, this));
3607		BX.addCustomEvent(this.item.OPENER, 'onOpenerMenuClose', BX.proxy(this.__menu_close, this));
3608	}
3609
3610	if (this.bHasAction)
3611	{
3612		BX.bind(this.LINK, 'click', BX.delegate(this.__click, this));
3613	}
3614};
3615
3616BX.CMenuOpenerItem.prototype.Get = function() {return this.DIV;};
3617BX.CMenuOpenerItem.prototype.__msover = function() {
3618	this.bx_hover = true;
3619	if (!this._menu_open)
3620		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-hover');
3621};
3622BX.CMenuOpenerItem.prototype.__msout = function() {
3623	this.bx_hover = false;
3624	if (!this._menu_open)
3625		BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-hover bx-context-toolbar-button-active');
3626};
3627BX.CMenuOpenerItem.prototype.__msover_text = function() {
3628	this.bx_hover = true;
3629	if (!this._menu_open)
3630		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-text-hover');
3631};
3632BX.CMenuOpenerItem.prototype.__msout_text = function() {
3633	this.bx_hover = false;
3634	if (!this._menu_open)
3635		BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-text-hover bx-context-toolbar-button-text-active');
3636};
3637BX.CMenuOpenerItem.prototype.__msover_arrow = function() {
3638	this.bx_hover = true;
3639	if (!this._menu_open)
3640		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-arrow-hover');
3641};
3642BX.CMenuOpenerItem.prototype.__msout_arrow = function() {
3643	this.bx_hover = false;
3644	if (!this._menu_open)
3645		BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-arrow-hover bx-context-toolbar-button-arrow-active');
3646};
3647BX.CMenuOpenerItem.prototype.__msdown = function() {
3648	this.bx_active = true;
3649	if (!this._menu_open)
3650		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-active');
3651};
3652BX.CMenuOpenerItem.prototype.__msdown_text = function() {
3653	this.bx_active = true;
3654	if (!this._menu_open)
3655		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-text-active');
3656};
3657BX.CMenuOpenerItem.prototype.__msdown_arrow = function() {
3658	this.bx_active = true;
3659	if (!this._menu_open)
3660		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-arrow-active');
3661};
3662BX.CMenuOpenerItem.prototype.__menu_close = function() {
3663
3664	this._menu_open = false;
3665	this.bx_active = false;
3666	BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-active bx-context-toolbar-button-text-active bx-context-toolbar-button-arrow-active');
3667	if (!this.bx_hover)
3668	{
3669		BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-hover bx-context-toolbar-button-text-hover bx-context-toolbar-button-arrow-hover');
3670		this.bx_hover = false;
3671	}
3672};
3673BX.CMenuOpenerItem.prototype.__menu_open = function() {
3674	this._menu_open = true;
3675};
3676
3677BX.CMenuOpenerItem.prototype.__click = function() {BX.evalGlobal(this.item.ONCLICK)};
3678
3679/* global page opener class */
3680BX.CPageOpener = function(arParams)
3681{
3682	//if (null == arParams.pin) arParams.pin = true;
3683	BX.CPageOpener.superclass.constructor.apply(this, arguments);
3684
3685	this.timeout = 505;
3686
3687	window.PAGE_EDIT_CONTROL = this;
3688};
3689BX.extend(BX.CPageOpener, BX.CMenuOpener);
3690
3691BX.CPageOpener.prototype.checkPosition = function()
3692{
3693	if (/*this.isMenuVisible() || this.DIV.style.display == 'none' || */this == BX.proxy_context)
3694		return;
3695
3696	this.correctPosition(BX.proxy_context);
3697};
3698
3699BX.CPageOpener.prototype.correctPosition = function(opener)
3700{
3701	if (this.bPosCorrected) return;
3702	var pos_self;
3703	if (this.DIV.style.display == 'none')
3704	{
3705		pos_self = this.adjustToNodeGetPos();
3706		pos_self.bottom = pos_self.top + 30;
3707		pos_self.right = pos_self.left + 300;
3708	}
3709	else
3710	{
3711		pos_self = BX.pos(this.DIV);
3712	}
3713
3714	var pos_other = BX.pos(opener.Get());
3715	if (this.__check_intersection(pos_self, pos_other))
3716	{
3717		this.DIV.style.display = 'none';
3718		BX.addCustomEvent(opener, 'onMenuOpenerHide', BX.proxy(this.restorePosition, this));
3719
3720		this.bPosCorrected = true;
3721	}
3722};
3723
3724BX.CPageOpener.prototype.restorePosition = function()
3725{
3726	if (BX.proxy_context && BX.proxy_context.Get().style.display == 'none')
3727	{
3728		this.bPosCorrected = false;
3729
3730		if (this.PARAMS.parent.bx_over || this.PARAMS.pin)
3731			this.UnHide();
3732
3733		BX.removeCustomEvent('onMenuOpenerHide', BX.proxy(this.restorePosition, this));
3734	}
3735};
3736
3737BX.CPageOpener.prototype.UnHide = function()
3738{
3739	if (!this.bPosCorrected)
3740		BX.CPageOpener.superclass.UnHide.apply(this, arguments);
3741};
3742
3743BX.CPageOpener.prototype.Remove = function()
3744{
3745	BX.admin.removeComponentBorder(this.PARAMS.parent);
3746	BX.userOptions.save('global', 'settings', 'page_edit_control_enable', 'N');
3747	this.DIV.style.display = 'none';
3748};
3749
3750/******* HINT ***************/
3751BX.CHintSimple = function()
3752{
3753	BX.CHintSimple.superclass.constructor.apply(this, arguments);
3754};
3755BX.extend(BX.CHintSimple, BX.CHint);
3756
3757BX.CHintSimple.prototype.Init = function()
3758{
3759	this.DIV = document.body.appendChild(BX.create('DIV', {props: {className: 'bx-tooltip-simple'}, style: {display: 'none'}, children: [(this.CONTENT = BX.create('DIV'))]}));
3760
3761	if (this.HINT_TITLE)
3762		this.CONTENT.appendChild(BX.create('B', {text: this.HINT_TITLE}));
3763
3764	if (this.HINT)
3765		this.CONTENT_TEXT = this.CONTENT.appendChild(BX.create('DIV')).appendChild(BX.create('SPAN', {html: this.HINT}));
3766
3767	if (this.PARAMS.preventHide)
3768	{
3769		BX.bind(this.DIV, 'mouseout', BX.proxy(this.Hide, this));
3770		BX.bind(this.DIV, 'mouseover', BX.proxy(this.Show, this));
3771	}
3772
3773	this.bInited = true;
3774};
3775
3776/*************************** admin informer **********************************/
3777BX.adminInformer = {
3778
3779	itemsShow: 3,
3780
3781	Init: function (itemsShow)
3782	{
3783		if(itemsShow)
3784			BX.adminInformer.itemsShow = itemsShow;
3785
3786		var informer = BX("admin-informer");
3787
3788		if(informer)
3789			document.body.appendChild(informer);
3790
3791		BX.addCustomEvent("onTopPanelCollapse", BX.proxy(BX.adminInformer.Close, BX.adminInformer));
3792	},
3793
3794	Toggle: function(notifyBlock)
3795	{
3796		var informer = BX("admin-informer");
3797
3798		if(!informer)
3799			return false;
3800
3801		var pos = BX.pos(notifyBlock);
3802
3803		informer.style.top = (parseInt(pos.top)+parseInt(pos.height)+7)+'px';
3804		informer.style.left = pos.left+'px';
3805
3806		if(!BX.hasClass(informer, "adm-informer-active"))
3807			BX.adminInformer.Show(informer);
3808		else
3809			BX.adminInformer.Hide(informer);
3810
3811		return false;
3812	},
3813
3814	Close: function()
3815	{
3816		BX.adminInformer.Hide(BX("admin-informer"));
3817	},
3818
3819	OnInnerClick: function(event)
3820	{
3821		var target = event.target || event.srcElement;
3822
3823		if(target.nodeName.toLowerCase() != 'a' || BX.hasClass(target,"adm-informer-footer"))
3824		{
3825			return BX.PreventDefault(event);
3826		}
3827
3828		return true;
3829	},
3830
3831	ToggleExtra : function()
3832	{
3833		var footerLink = BX("adm-informer-footer");
3834
3835		if (BX.hasClass(footerLink, "adm-informer-footer-collapsed"))
3836			this.ShowAll();
3837		else
3838			this.HideExtra();
3839
3840		return false;
3841	},
3842
3843	ShowAll: function()
3844	{
3845		var informer = BX("admin-informer");
3846		for(var i=0; i<informer.children.length; i++)
3847
3848			if(BX.hasClass(informer.children[i], "adm-informer-item") && informer.children[i].style.display == "none") {
3849				informer.children[i].style.display = "block";
3850			}
3851
3852		var footerLink = BX("adm-informer-footer");
3853
3854		if(footerLink.textContent !== undefined)
3855			footerLink.textContent = BX.message('JSADM_AI_HIDE_EXTRA');
3856		else
3857			footerLink.innerText = BX.message('JSADM_AI_HIDE_EXTRA');
3858
3859		BX.removeClass(footerLink, "adm-informer-footer-collapsed");
3860
3861		return false;
3862	},
3863
3864	HideExtra: function()
3865	{
3866		var informer = BX("admin-informer");
3867		var hided = 0;
3868
3869		for(var i=BX.adminInformer.itemsShow+1; i<informer.children.length; i++)
3870		{
3871			if (BX.hasClass(informer.children[i], "adm-informer-item") && informer.children[i].style.display == "block") {
3872				informer.children[i].style.display = "none";
3873				hided++;
3874			}
3875		}
3876
3877		var footerLink = BX("adm-informer-footer");
3878
3879		var linkText = BX.message('JSADM_AI_ALL_NOTIF')+" ("+(BX.adminInformer.itemsShow+parseInt(hided))+")";
3880
3881		if(footerLink.textContent !== undefined)
3882			footerLink.textContent = linkText;
3883		else
3884			footerLink.innerText = linkText;
3885
3886		BX.addClass(footerLink, "adm-informer-footer-collapsed");
3887
3888		return false;
3889	},
3890
3891	Show: function(informer)
3892	{
3893		var notifButton = BX("adm-header-notif-block");
3894		if (notifButton)
3895			BX.addClass(notifButton, "adm-header-notif-block-active");
3896
3897		BX.onCustomEvent(informer, 'onBeforeAdminInformerShow');
3898		setTimeout(
3899			BX.proxy(function() {
3900					BX.bind(document, "click", BX.proxy(BX.adminInformer.Close, BX.adminInformer));
3901				},
3902				BX.adminInformer
3903			),0
3904		);
3905		BX.addClass(informer, "adm-informer-active");
3906		setTimeout(function() {BX.addClass(informer, "adm-informer-animate");},0);
3907	},
3908
3909	Hide: function(informer)
3910	{
3911		var notifButton = BX("adm-header-notif-block");
3912		if (notifButton)
3913			BX.removeClass(notifButton, "adm-header-notif-block-active");
3914
3915		BX.unbind(document, "click", BX.proxy(BX.adminInformer.Close, BX.adminInformer));
3916
3917		BX.removeClass(informer, "adm-informer-animate");
3918
3919		if (this.IsAnimationSupported())
3920			setTimeout(function() {BX.removeClass(informer, "adm-informer-active");}, 300);
3921		else
3922			BX.removeClass(informer, "adm-informer-active");
3923
3924		BX.onCustomEvent(informer, 'onAdminInformerHide');
3925		//setTimeout(function() {BX.adminInformer.HideExtra();},500);
3926	},
3927
3928	IsAnimationSupported : function()
3929	{
3930		var d = document.body || document.documentElement;
3931		if (typeof(d.style.transition) == "string")
3932			return true;
3933		else if (typeof(d.style.MozTransition) == "string")
3934			return true;
3935		else if (typeof(d.style.OTransition) == "string")
3936			return true;
3937		else if (typeof(d.style.WebkitTransition) == "string")
3938			return true;
3939		else if (typeof(d.style.msTransition) == "string")
3940			return true;
3941
3942		return false;
3943	},
3944
3945
3946	SetItemHtml: function(itemIdx, html)
3947	{
3948		var itemHtmlDiv = BX("adm-informer-item-html-"+itemIdx);
3949
3950		if(!itemHtmlDiv)
3951			return false;
3952
3953		itemHtmlDiv.innerHTML = html;
3954
3955		return true;
3956	},
3957
3958	SetItemFooter: function(itemIdx, html)
3959	{
3960		var itemFooterDiv = BX("adm-informer-item-footer-"+itemIdx);
3961
3962		if(!itemFooterDiv)
3963			return false;
3964
3965		itemFooterDiv.innerHTML = html;
3966
3967		if(html)
3968			itemFooterDiv.style.display = "block";
3969		else
3970			itemFooterDiv.style.display = "none";
3971
3972		return true;
3973	}
3974
3975};
3976
3977}
3977)(window);
3978

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.