PageSourceSearch

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

js muzkom.ru collected 2026-10-06 10:06:07 UTC 97,969 bytes, 4,003 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		var zIndex = (this.PARAMS.zIndex ? this.PARAMS.zIndex : parseInt(BX.style(wait, 'z-index'))-1);
1767		this.CreateOverlay(zIndex);
1768		this.OVERLAY.style.display = 'block';
1769		this.OVERLAY.className = 'bx-core-dialog-overlay';
1770
1771		var post_data = '', method = 'GET';
1772		if (this.PARAMS.content_post)
1773		{
1774			post_data = this.PARAMS.content_post;
1775			method = 'POST';
1776		}
1777
1778		var url = this.PARAMS.content_url
1779			+ (this.PARAMS.content_url.indexOf('?')<0?'?':'&')+'bxsender=' + this._sender;
1780
1781		this.auth_callback = BX.delegate(function(){
1782			this.PARAMS.content = '';
1783			this.hideNotify();
1784			this.Show();
1785		}, this);
1786
1787		BX.ajax({
1788			method: method,
1789			dataType: 'html',
1790			url: url,
1791			data: post_data,
1792			skipAuthCheck: true,
1793			onsuccess: BX.delegate(function(data) {
1794				BX.closeWait(null, wait);
1795
1796				this.SetContent(data || '&nbsp;');
1797				this.Show();
1798			}, this)
1799		});
1800	}
1801	else
1802	{
1803		BX.WindowManager.currently_loaded = null;
1804		BX.CDialog.superclass.Show.apply(this, arguments);
1805
1806		this.adjustPos();
1807
1808		this.OVERLAY.className = 'bx-core-dialog-overlay';
1809
1810		this.__adjustSize();
1811
1812		BX.addCustomEvent(this, 'onWindowResize', BX.proxy(this.__adjustSize, this));
1813
1814		if (this.PARAMS.resizable && (this.PARAMS.content_url || this.PARAMS.resize_id))
1815			BX.addCustomEvent(this, 'onWindowResizeFinished', BX.delegate(this.__onResizeFinished, this));
1816	}
1817};
1818
1819BX.CDialog.prototype.GetInnerPos = function()
1820{
1821	return {'width': parseInt(this.PARTS.CONTENT_DATA.style.width), 'height': parseInt(this.PARTS.CONTENT_DATA.style.height)};
1822};
1823
1824BX.CDialog.prototype.adjustPos = function()
1825{
1826	if (!this.bExpanded)
1827	{
1828		var currentWindow = window;
1829		if (top.BX.SidePanel.Instance && top.BX.SidePanel.Instance.getTopSlider())
1830		{
1831			currentWindow = top.BX.SidePanel.Instance.getTopSlider().getWindow();
1832		}
1833		var windowSize = currentWindow.BX.GetWindowInnerSize();
1834		var windowScroll = currentWindow.BX.GetWindowScrollPos();
1835
1836		var style = {
1837			left: parseInt(windowScroll.scrollLeft + windowSize.innerWidth / 2 - parseInt(this.DIV.offsetWidth) / 2) + 'px',
1838			top: Math.max(parseInt(windowScroll.scrollTop + windowSize.innerHe
1838ight / 2 - parseInt(this.DIV.offsetHeight) / 2), 0) + 'px'
1839		};
1840		if (this.PARAMS.zIndex)
1841		{
1842			style["z-index"] = this.PARAMS.zIndex;
1843		}
1844
1845		BX.adjust(this.DIV, {
1846			style: style
1847		});
1848	}
1849};
1850
1851BX.CDialog.prototype.GetContent = function () {return this.PARTS.CONTENT_DATA};
1852
1853BX.CDialog.prototype.btnSave = BX.CDialog.btnSave = {
1854	title: BX.message('JS_CORE_WINDOW_SAVE'),
1855	id: 'savebtn',
1856	name: 'savebtn',
1857	className: BX.browser.IsIE() && BX.browser.IsDoctype() && !BX.browser.IsIE10() ? '' : 'adm-btn-save',
1858	action: function () {
1859		this.disableUntilError();
1860		this.parentWindow.PostParameters();
1861	}
1862};
1863
1864BX.CDialog.prototype.btnCancel = BX.CDialog.btnCancel = {
1865	title: BX.message('JS_CORE_WINDOW_CANCEL'),
1866	id: 'cancel',
1867	name: 'cancel',
1868	action: function () {
1869		this.parentWindow.Close();
1870	}
1871};
1872
1873BX.CDialog.prototype.btnClose = BX.CDialog.btnClose = {
1874	title: BX.message('JS_CORE_WINDOW_CLOSE'),
1875	id: 'close',
1876	name: 'close',
1877	action: function () {
1878		this.parentWindow.Close();
1879	}
1880};
1881
1882/* special child for admin forms loaded into public page */
1883BX.CAdminDialog = function(arParams)
1884{
1885	BX.CAdminDialog.superclass.constructor.apply(this, arguments);
1886
1887	this._sender = 'core_window_cadmindialog';
1888
1889	BX.addClass(this.DIV, 'bx-core-adm-admin-dialog');
1890
1891	this.PARTS.CONTENT.insertBefore(this.PARTS.HEAD, this.PARTS.CONTENT.firstChild);
1892	this.PARTS.HEAD.className = 'bx-core-adm-dialog-tabs';
1893};
1894BX.extend(BX.CAdminDialog, BX.CDialog);
1895
1896BX.CAdminDialog.prototype.SetHead = function()
1897{
1898	BX.CAdminDialog.superclass.SetHead.apply(this, arguments);
1899
1900	if (this.PARTS.HEAD.firstChild && BX.type.isElementNode(this.PARTS.HEAD.firstChild))
1901	{
1902		var ob = this.PARTS.HEAD.firstChild, new_width = 0, marginLeft = 0, marginRight = 0;
1903
1904		while (ob)
1905		{
1906			if (BX.type.isElementNode(ob))
1907			{
1908				marginLeft = parseInt(BX.style(ob, 'margin-left'), 10);
1909				if (isNaN(marginLeft))
1910					marginLeft = 0;
1911				marginRight = parseInt(BX.style(ob, 'margin-right'), 10);
1912				if (isNaN(marginRight))
1913					marginRight = 0;
1914				new_width += ob.offsetWidth + marginLeft + marginRight;
1915			}
1916			ob = BX.nextSibling(ob);
1917		}
1918
1919		this.SETTINGS.min_width = Math.max(new_width, this.SETTINGS.min_width) - 2;
1920		if (this.PARAMS.width < this.SETTINGS.min_width)
1921		{
1922			BX.adjust(this.PARTS.CONTENT_DATA, {
1923				style: {
1924					width: this.SETTINGS.min_width + 'px'
1925				}
1926			});
1927		}
1928	}
1929};
1930
1931BX.CAdminDialog.prototype.SetContent = function(html)
1932{
1933	this.__form = null;
1934
1935	if (BX.type.isElementNode(html))
1936	{
1937		if (html.parentNode)
1938			html.parentNode.removeChild(html);
1939	}
1940
1941	this.PARAMS.content = html;
1942	BX.cleanNode(this.PARTS.CONTENT_DATA);
1943
1944	BX.adjust(this.PARTS.CONTENT_DATA, {
1945		children: [
1946			this.PARAMS.content || '&nbsp;'
1947		]
1948	});
1949
1950	if (this.PARAMS.content_url && this.GetForm())
1951	{
1952		this.__form.appendChild(BX.create('INPUT', {props:{type:'submit'},style:{display:'none'}}));
1953		this.__form.onsubmit = BX.delegate(this.__submit, this);
1954	}
1955};
1956
1957BX.CAdminDialog.prototype.__expandGetSize = function()
1958{
1959	var res = BX.CAdminDialog.superclass.__expandGetSize.apply(this, arguments);
1960
1961	res.width -= parseInt(BX.style(this.PARTS.CONTENT_DATA, 'padding-right')) + parseInt(BX.style(this.PARTS.CONTENT_DATA, 'padding-left'));
1962	res.height -= parseInt(BX.style(this.PARTS.CONTENT_DATA, 'padding-top')) + parseInt(BX.style(this.PARTS.CONTENT_DATA, 'padding-bottom'));
1963
1964	res.height -= this.PARTS.HEAD.offsetHeight;
1965
1966	return res;
1967};
1968
1969BX.CAdminDialog.prototype.Submit = function()
1970{
1971	var FORM = this.GetForm();
1972	if (FORM && !FORM['bxpublic'] && !/bxpublic=/.test(FORM.action))
1973	{
1974		FORM.appendChild(BX.create('INPUT', {
1975			props: {
1976				type: 'hidden',
1977				name: 'bxpublic',
1978				value: 'Y'
1979			}
1980		}));
1981	}
1982
1983	return BX.CAdminDialog.superclass.Submit.apply(this, arguments);
1984};
1985
1986BX.CAdminDialog.prototype.btnSave = BX.CAdminDialog.btnSave = {
1987	title: BX.message('JS_CORE_WINDOW_SAVE'),
1988	id: 'savebtn',
1989	name: 'savebtn',
1990	className: 'adm-btn-save',
1991	action: function () {
1992		this.disableUntilError();
1993		this.parentWindow.Submit();
1994	}
1995};
1996
1997BX.CAdminDialog.btnCancel = BX.CAdminDialog.superclass.btnCancel;
1998BX.CAdminDialog.btnClose = BX.CAdminDialog.superclass.btnClose;
1999
2000BX.CDebugDialog = function(arParams)
2001{
2002	BX.CDebugDialog.superclass.constructor.apply(this, arguments);
2003};
2004BX.extend(BX.CDebugDialog, BX.CDialog);
2005
2006BX.CDebugDialog.prototype.ShowDetails = function(div_id)
2007{
2008	var div = BX(div_id);
2009	if (div)
2010	{
2011		if (this.div_detail_current)
2012			this.div_detail_current.style.display = 'none';
2013
2014		div.style.display = 'block';
2015		this.div_detail_current = div;
2016	}
2017};
2018
2019BX.CDebugDialog.prototype.SetContent = function(html)
2020{
2021	if (!html)
2022		return;
2023
2024	var arHtml = html.split('#DIVIDER#');
2025	if (arHtml.length > 1)
2026	{
2027		this.PARAMS.content = arHtml[1];
2028
2029		this.PARTS.CONTENT_DATA.style.overflow = 'hidden';
2030
2031		BX.CDebugDialog.superclass.SetContent.apply(this, [arHtml[1]]);
2032
2033		this.PARTS.CONTENT_INNER = this.PARTS.CONTENT_DATA.firstChild.nextSibling;
2034		this.PARTS.CONTENT_TOP = this.PARTS.CONTENT_DATA.insertBefore(BX.create('DIV', {
2035			props: {
2036				className: 'bx-debug-content-top'
2037			},
2038			html: arHtml[0]
2039		}), this.PARTS.CONTENT_INNER);
2040		this.PARTS.CONTENT_INNER.style.overflow = 'auto';
2041	}
2042	else
2043	{
2044		BX.CDebugDialog.superclass.SetContent.apply(this, arguments);
2045	}
2046};
2047
2048BX.CDebugDialog.prototype.__adjustSize = function()
2049{
2050	BX.CDebugDialog.superclass.__adjustSize.apply(this, arguments);
2051
2052	if (this.PARTS.CONTENT_TOP)
2053	{
2054		var new_height = this.PARTS.CONTENT_DATA.offsetHeight - this.PARTS.HEAD.offsetHeight - this.PARTS.CONTENT_TOP.offsetHeight - 38;
2055
2056		if (new_height > 0)
2057		{
2058			this.PARTS.CONTENT_INNER.style.height = new_height + 'px';
2059		}
2060	}
2061};
2062
2063
2064/* class for dialog window with editors */
2065
2066BX.CEditorDialog = function(arParams)
2067{
2068	BX.CEditorDialog.superclass.constructor.apply(this, arguments);
2069
2070	BX.removeClass(this.PARTS.CONTENT, 'bx-core-adm-dialog-content-wrap');
2071	BX.removeClass(this.PARTS.CONTENT_DATA, 'bx-core-adm-dialog-content');
2072
2073	BX.removeClass(this.PARTS.CONTENT_DATA.lastChild, 'bx-core-adm-dialog-content-wrap-inner');
2074	BX.removeClass(this.PARTS.BUTTONS_CONTAINER, 'bx-core-adm-dialog-buttons');
2075
2076	BX.addClass(this.PARTS.CONTENT, 'bx-core-editor-dialog-content-wrap');
2077	BX.addClass(this.PARTS.CONTENT_DATA, 'bx-core-editor-dialog-content');
2078	BX.addClass(this.PARTS.BUTTONS_CONTAINER, 'bx-core-editor-dialog-buttons');
2079};
2080BX.extend(BX.CEditorDialog, BX.CDialog);
2081
2082BX.CEditorDialog.prototype.SetContent  = function()
2083{
2084	BX.CEditorDialog.superclass.SetContent.apply(this, arguments);
2085
2086	BX.removeClass(this.PARTS.CONTENT_DATA.lastChild, 'bx-core-adm-dialog-content-wrap-inner');
2087};
2088
2089/* class for wizards in admin section */
2090BX.CWizardDialog = function(arParams)
2091{
2092	BX.CWizardDialog.superclass.constructor.apply(this, arguments);
2093
2094	BX.removeClass(this.PARTS.CONTENT, 'bx-core-adm-dialog-content-wrap');
2095	BX.removeClass(this.PARTS.CONTENT_DATA, 'bx-core-adm-dialog-content');
2096	BX.removeClass(this.PARTS.CONTENT_DATA.lastChild, 'bx-core-adm-dialog-content-wrap-inner');
2097	BX.removeClass(this.PARTS.BUTTONS_CONTAINER, 'bx-core-adm-dialog-buttons');
2098
2099	BX.addClass(this.PARTS.CONTENT, 'bx-core-wizard-dialog-content-wrap');
2100};
2101
2102BX.extend(BX.CWizardDialog, BX.CDialog);
2103
2104/* class for auth dialog */
2105BX.CAuthDialog = function(arParams)
2106{
2107	arParams.resizable = false;
2108	arParams.width = 350;
2109	arParams.height = 200;
2110
2111	arParams.buttons = [this.btnSave];
2112
2113	BX.CAuthDialog.superclass.constructor.apply(this, arguments);
2114	this._sender = 'core_window_cauthdialog';
2115
2116	BX.addClass(this.DIV, 'bx-core-auth-dialog');
2117
2118	BX.AUTHAGENT = this;
2119};
2120BX.extend(BX.CAuthDialog, BX.CDialog);
2121
2122BX.CAuthDialog.prototype.btnSave = BX.CAuthDialog.btnSave = {
2123	title: BX.message('JS_CORE_WINDOW_AUTH'),
2124	id: 'savebtn',
2125	name: 'savebtn',
2126	className: 'adm-btn-save',
2127	action: function () {
2128		this.disableUntilError();
2129		this.parentWindow.Submit('', this.parentWindow.PARAMS.content_url);
2130	}
2131};
2132
2133BX.CAuthDialog.prototype.SetError = function(error)
2134{
2135	BX.closeWait();
2136
2137	if (!!error)
2138		this.ShowError(error.MESSAGE || error);
2139};
2140
2141BX.CAuthDialog.prototype.setAuthResult = function(result)
2142{
2143	BX.closeWait();
2144
2145	if (result === false)
2146	{
2147		this.Close();
2148		if (this.PARAMS.callback)
2149			this.PARAMS.callback();
2150	}
2151	else
2152	{
2153		this.SetError(result);
2154	}
2155};
2156
2157/* MENU CLASSES */
2158
2159BX.CWindowFloat = function(node)
2160{
2161	BX.CWindowFloat.superclass.constructor.apply(this, [node, 'float']);
2162
2163	this.SETTINGS.resizable = false;
2164};
2165BX.extend(BX.CWindowFloat, BX.CWindow);
2166
2167BX.CWindowFloat.prototype.adjustPos = function()
2168{
2169	if (this.PARAMS.parent)
2170		this.adjustToNode();
2171	else if (this.PARAMS.x && this.PARAMS.y)
2172		this.adjustToPos([this.PARAMS.x, this.PARAMS.y]);
2173};
2174
2175BX.CWindowFloat.prototype.adjustToPos = function(pos)
2176{
2177	this.DIV.style.left = parseInt(pos[0]) + 'px';
2178	this.DIV.style.top = parseInt(pos[1]) + 'px';
2179};
2180
2181BX.CWindowFloat.prototype.adjustToNodeGetPos = function()
2182{
2183	return BX.pos(this.PARAMS.parent);
2184};
2185
2186BX.CWindowFloat.prototype.adjustToNode = function(el)
2187{
2188	el = el || this.PARAMS.parent;
2189
2190	this.PARAMS.parent = BX(el);
2191
2192	if (this.PARAMS.parent)
2193	{
2194		var pos = this.adjustToNodeGetPos();
2195
2196		this.DIV.style.top = pos.top + 'px';//(pos.top - 26) + 'px';
2197		this.DIV.style.left = pos.left + 'px';
2198
2199		this.PARAMS.parent.OPENER = this;
2200	}
2201};
2202
2203BX.CWindowFloat.prototype.Show = function()
2204{
2205	this.adjustToPos([-1000, -1000]);
2206	BX.CWindowFloat.superclass.Show.apply(this, arguments);
2207	this.adjustPos();
2208};
2209
2210/* menu opener class */
2211/*
2212{
2213	DOMNode DIV,
2214	BX.CMenu or Array MENU,
2215	TYPE = 'hover' | 'click',
2216	TIMEOUT: 1000
2217	ATTACH_MODE: 'top' | 'right'
2218	ACTIVE_CLASS: className for opener element when menu is opened
2219}
2220*/
2221BX.COpener = function(arParams)
2222{
2223	this.PARAMS = arParams || {};
2224
2225	this.MENU = arParams.MENU || [];
2226
2227	this.DIV = arParams.DIV;
2228	this.ATTACH = arParams.ATTACH || arParams.DIV;
2229	this.ATTACH_MODE = arParams.ATTACH_MODE || 'bottom';
2230
2231	this.ACTIVE_CLASS = arParams.ACTIVE_CLASS || '';
2232	this.PUBLIC_FRAME = arParams.PUBLIC_FRAME || 0;
2233	this.LEVEL = arParams.LEVEL || 0;
2234
2235	this.CLOSE_ON_CLICK = typeof arParams.CLOSE_ON_CLICK != 'undefined' ? !!arParams.CLOSE_ON_CLICK : true;
2236	this.ADJUST_ON_CLICK = typeof arParams.ADJUST_ON_CLICK != 'undefined' ? !!arParams.ADJUST_ON_CLICK : true;
2237
2238	this.TYPE = this.PARAMS.TYPE == 'hover' ? 'hover' : 'click';
2239
2240	this._openTimeout = null;
2241
2242	if (this.PARAMS.TYPE == 'hover' && arParams.TIMEOUT !== 0)
2243		this.TIMEOUT = arParams.TIMEOUT || 1000;
2244	else
2245		this.TIMEOUT = 0;
2246
2247	if (!!this.PARAMS.MENU_URL)
2248	{
2249		this.bMenuLoaded = false;
2250		this.bMenuLoading = false;
2251
2252		this.MENU = [{
2253			TEXT: BX.message('JS_CORE_LOADING'),
2254			CLOSE_ON_CLICK: false
2255		}];
2256
2257		if (this.PARAMS.MENU_PRELOAD)
2258		{
2259			BX.defer(this.Load, this)();
2260		}
2261	}
2262
2263	BX.ready(BX.defer(this.Init, this));
2264};
2265
2266BX.COpener.prototype.Init = function()
2267{
2268	this.DIV = BX(this.DIV);
2269
2270	switch (this.TYPE)
2271	{
2272		case 'hover':
2273			BX.bind(this.DIV, 'mouseover', BX.proxy(this.Open, this));
2274			BX.bind(this.DIV, 'click', BX.proxy(this.Toggle, this));
2275		break;
2276
2277		case 'click':
2278			BX.bind(this.DIV, 'click', BX.proxy(this.Toggle, this));
2279		break;
2280	}
2281
2282	//BX.bind(window, 'scroll', BX.delegate(this.__close_immediately, this));
2283
2284	this.bMenuInit = false;
2285};
2286
2287BX.COpener.prototype.Load = function()
2288{
2289	if (this.PARAMS.MENU_URL && !this.bMenuLoaded)
2290	{
2291		if (!this.bMenuLoading)
2292		{
2293			var url = this.PARAMS.MENU_URL;
2294			if (url.indexOf('sessid=') <= 0)
2295				url += (url.indexOf('?') > 0 ? '&' : '?') + 'sessid=' + BX.bitrix_sessid();
2296
2297			this.bMenuLoading = true;
2298			BX.ajax.loadJSON(url, BX.proxy(this.SetMenu, this), BX.proxy(this.LoadFailed, this));
2299		}
2300	}
2301};
2302
2303BX.COpener.prototype.SetMenu = function(menu)
2304{
2305	this.bMenuLoaded = true;
2306	this.bMenuLoading = false;
2307	if (this.bMenuInit)
2308	{
2309		this.MENU.setItems(menu);
2310	}
2311	else
2312	{
2313		this.MENU = menu;
2314	}
2315};
2316
2317BX.COpener.prototype.LoadFailed = function(type, error)
2318{
2319	this.bMenuLoading = false;
2320	this.SetMenu([{
2321		TEXT: BX.message('JS_CORE_NO_DATA'),
2322		CLOSE_ON_CLICK: true
2323	}]);
2324	BX.debug(arguments);
2325};
2326
2327BX.COpener.prototype.checkAdminMenu = function()
2328{
2329	if (document.documentElement.id == 'bx-admin-prefix')
2330		return true;
2331
2332	return !!BX.findParent(this.DIV, {property: {id: 'bx-admin-prefix'}});
2333};
2334
2335BX.COpener.prototype.Toggle = function(e)
2336{
2337	this.__clear_timeout();
2338
2339	if (!this.bMenuInit || !this.MENU.visible())
2340	{
2341		var t = this.TIMEOUT;
2342		this.TIMEOUT = 0;
2343		this.Open(e);
2344		this.TIMEOUT = t;
2345	}
2346	else
2347	{
2348		this.MENU.Close();
2349	}
2350
2351	return !!(e||window.event) && BX.PreventDefault(e);
2352};
2353
2354BX.COpener.prototype.GetMenu = function()
2355{
2356	if (!this.bMenuInit)
2357	{
2358		if (BX.type.isArray(this.MENU))
2359		{
2360			this.MENU = new BX.CMenu({
2361				ITEMS: this.MENU,
2362				ATTACH_MODE: this.ATTACH_MODE,
2363				SET_ID: this.checkAdminMenu() ? 'bx-admin-prefix' : '',
2364				CLOSE_ON_CLICK: !!this.CLOSE_ON_CLICK,
2365				ADJUST_ON_CLICK: !!this.ADJUST_ON_CLICK,
2366				PUBLIC_FRAME: !!this.PUBLIC_FRAME,
2367				LEVEL: this.LEVEL,
2368				parent: BX(this.DIV),
2369				parent_attach: BX(this.ATTACH)
2370			});
2371
2372			if (this.LEVEL > 0)
2373			{
2374				BX.bind(this.MENU.DIV, 'mouseover', BX.proxy(this._on_menu_hover, this));
2375				BX.bind(this.MENU.DIV, 'mouseout', BX.proxy(this._on_menu_hout, this));
2376			}
2377		}
2378
2379		BX.addCustomEvent(this.MENU, 'onMenuOpen', BX.proxy(this.handler_onopen, this));
2380		BX.addCustomEvent(this.MENU, 'onMenuClose', BX.proxy(this.handler_onclose, this));
2381
2382		BX.addCustomEvent('onMenuItemHover', BX.proxy(this.handler_onover, this));
2383
2384		this.bMenuInit = true;
2385	}
2386
2387	return this.MENU;
2388};
2389
2390BX.COpener.prototype.Open = function()
2391{
2392	this.GetMenu();
2393
2394	this.bOpen = true;
2395
2396	this.__clear_timeout();
2397
2398	if (this.TIMEOUT > 0)
2399	{
2400		BX.bind(this.DIV, 'mouseout', BX.proxy(this.__clear_timeout, this));
2401		this._openTimeout = setTimeout(BX.proxy(this.__open, this), this.TIMEOUT);
2402	}
2403	else
2404	{
2405		this.__open();
2406	}
2407
2408	if (!!this.PARAMS.MENU_URL && !this.bMenuLoaded)
2409	{
2410		this._loadTimeout = setTimeout(BX.proxy(this.Load, this), parseInt(this.TIMEOUT/2));
2411	}
2412
2413	return true;
2414};
2415
2416BX.COpener.prototype.__clear_timeout = function()
2417{
2418	if (!!this._openTimeout)
2419		clearTimeout(this._openTimeout);
2420	if (!!this._loadTimeout)
2421		clearTimeout(this._loadTimeout);
2422
2423	BX.unbind(this.DIV, 'mouseout', BX.proxy(this.__clear_timeout, this));
2424};
2425
2426BX.COpener.prototype._on_menu_hover = function()
2427{
2428	this.bMenuHover = true;
2429
2430	this.__clear_timeout();
2431
2432	if (this.ACTIVE_CLASS)
2433		BX.addClass(this.DIV, this.ACTIVE_CLASS);
2434
2435};
2436
2437BX.COpener.prototype._on_menu_hout = function()
2438{
2439	this.bMenuHover = false;
2440};
2441
2442BX.COpener.prototype.handler_onover = function(level, opener)
2443{
2444	if (this.bMenuHover)
2445		return;
2446
2447	if (opener != this && level == this.LEVEL-1 && this.ACTIVE_CLASS)
2448	{
2449		BX.removeClass(this.DIV, this.ACTIVE_CLASS);
2450	}
2451
2452	if (this.bMenuInit && level <= this.LEVEL-1 && this.MENU.visible())
2453	{
2454		if (opener != this)
2455		{
2456			this.__clear_timeout();
2457			this._openTimeout = setTimeout(BX.proxy(this.Close, this), this.TIMEOUT);
2458		}
2459	}
2460};
2461
2462BX.COpener.prototype.handler_onopen = function()
2463{
2464	this.bOpen = true;
2465
2466	if (this.ACTIVE_CLASS)
2467		BX.addClass(this.DIV, this.ACTIVE_CLASS);
2468
2469	BX.defer(function() {
2470		BX.onCustomEvent(this, 'onOpenerMenuOpen');
2471	}, this)();
2472};
2473
2474BX.COpener.prototype.handler_onclose = function()
2475{
2476	this.bOpen = false;
2477	BX.onCustomEvent(this, 'onOpenerMenuClose');
2478
2479	if (this.ACTIVE_CLASS)
2480		BX.removeClass(this.DIV, this.ACTIVE_CLASS);
2481};
2482
2483BX.COpener.prototype.Close = function()
2484{
2485	if (!this.bMenuInit)
2486		return;
2487
2488	if (!!this._openTimeout)
2489		clearTimeout(this._openTimeout);
2490
2491	this.bOpen = false;
2492
2493	this.__close();
2494};
2495
2496BX.COpener.prototype.__open = function()
2497{
2498	this.__clear_timeout();
2499
2500	if (this.bMenuInit && this.bOpen && !this.MENU.visible())
2501		this.MENU.Show();
2502};
2503
2504BX.COpener.prototype.__close = function()
2505{
2506	if (this.bMenuInit && !this.bOpen && this.MENU.visible())
2507		this.MENU.Hide();
2508};
2509
2510BX.COpener.prototype.__close_immediately = function() {
2511	this.bOpen = false; this.__close();
2512};
2513
2514BX.COpener.prototype.isMenuVisible = function() {
2515	return null != this.MENU.visible && this.MENU.visible()
2516};
2517
2518/* common menu class */
2519
2520BX.CMenu = function(arParams)
2521{
2522	BX.CMenu.superclass.constructor.apply(this);
2523
2524	this.DIV.style.width = 'auto';//this.DIV.firstChild.offsetWidth + 'px';
2525	this.DIV.style.height = 'auto';//this.DIV.firstChild.offsetHeight + 'px';
2526
2527	this.PARAMS = arParams || {};
2528	this.PARTS = {};
2529
2530	this.PARAMS.ATTACH_MODE = this.PARAMS.ATTACH_MODE || 'bottom';
2531	this.PARAMS.CLOSE_ON_CLICK = typeof this.PARAMS.CLOSE_ON_CLICK == 'undefined' ? true : this.PARAMS.CLOSE_ON_CLICK;
2532	this.PARAMS.ADJUST_ON_CLICK = typeof this.PARAMS.ADJUST_ON_CLICK == 'undefined' ? true : this.PARAMS.ADJUST_ON_CLICK;
2533	this.PARAMS.PUBLIC_FRAME = typeof this.PARAMS.PUBLIC_FRAME == 'undefined' ? false : this.PARAMS.PUBLIC_FRAME;
2534	this.PARAMS.LEVEL = this.PARAMS.LEVEL || 0;
2535
2536	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 : '');
2537	if (!!this.PARAMS.SET_ID)
2538		this.DIV.id = this.PARAMS.SET_ID;
2539
2540	if (this.PARAMS.LEVEL == 0)
2541	{
2542		this.ARROW = this.DIV.appendChild(BX.create('SPAN', {props: {className: 'bx-core-popup-menu-angle'}, style: {left:'15px'}}));
2543	}
2544
2545	if (!!this.PARAMS.CLASS_NAME)
2546		this.DIV.className += ' ' + this.PARAMS.CLASS_NAME;
2547
2548	BX.bind(this.DIV, 'click', BX.eventCancelBubble);
2549
2550	this.ITEMS = [];
2551
2552	this.setItems(this.PARAMS.ITEMS);
2553
2554	BX.addCustomEvent('onMenuOpen', BX.proxy(this._onMenuOpen, this));
2555	BX.addCustomEvent('onMenuItemSelected', BX.proxy(this.Hide, this));
2556};
2557BX.extend(BX.CMenu, BX.CWindowFloat);
2558
2559BX.CMenu.broadcastCloseEvent = function()
2560{
2561	BX.onCustomEvent("onMenuItemSelected");
2562};
2563
2564BX.CMenu._toggleChecked = function()
2565{
2566	BX.toggleClass(this, 'bx-core-popup-menu-item-checked');
2567};
2568
2569BX.CMenu._itemDblClick = function()
2570{
2571	window.location.href = this.href;
2572};
2573
2574BX.CMenu.prototype.toggleArrow = function(v)
2575{
2576	if (!!this.ARROW)
2577	{
2578		if (typeof v == 'undefined')
2579		{
2580			v = this.ARROW.style.visibility == 'hidden';
2581		}
2582
2583		this.ARROW.style.visibility = !!v ? 'visible' : 'hidden';
2584	}
2585};
2586
2587BX.CMenu.prototype.visible = function()
2588{
2589	return this.DIV.style.display !== 'none';
2590};
2591
2592BX.CMenu.prototype._onMenuOpen = function(menu, menu_level)
2593{
2594	if (this.visible())
2595	{
2596		if (menu_level == this.PARAMS.LEVEL && menu != this)
2597		{
2598			this.Hide();
2599		}
2600	}
2601};
2602
2603BX.CMenu.prototype.onUnRegister = function()
2604{
2605	if (!this.visible())
2606		return;
2607
2608	this.Hide();
2609};
2610
2611BX.CMenu.prototype.setItems = function(items)
2612{
2613	this.PARAMS.ITEMS = items;
2614
2615	BX.cleanNode(this.DIV);
2616
2617	if (!!this.ARROW)
2618		this.DIV.appendChild(this.ARROW);
2619
2620	if (this.PARAMS.ITEMS)
2621	{
2622		this.PARAMS.ITEMS = BX.util.array_values(this.PARAMS.ITEMS);
2623
2624		var bIcons = false;
2625		var cnt = 0;
2626		for (var i = 0, len = this.PARAMS.ITEMS.length; i < len; i++)
2627		{
2628			if ((i == 0 || i == len-1) && this.PARAMS.ITEMS[i].SEPARATOR)
2629				continue;
2630
2631			cnt++;
2632
2633			if (!bIcons)
2634				bIcons = !!this.PARAMS.ITEMS[i].GLOBAL_ICON;
2635
2636			this.addItem(this.PARAMS.ITEMS[i], i);
2637		}
2638
2639		// Occam turning in his grave
2640		if (cnt === 1)
2641			BX.addClass(this.DIV, 'bx-core-popup-menu-single-item');
2642		else
2643			BX.removeClass(this.DIV, 'bx-core-popup-menu-single-item');
2644
2645		if (!bIcons)
2646			BX.addClass(this.DIV, 'bx-core-popup-menu-no-icons');
2647		else
2648			BX.removeClass(this.DIV, 'bx-core-popup-menu-no-icons');
2649
2650	}
2651};
2652
2653BX.CMenu.prototype.addItem = function(item)
2654{
2655	this.ITEMS.push(item);
2656
2657	if (item.SEPARATOR)
2658	{
2659		item.NODE = BX.create(
2660			'DIV', {props: {className: 'bx-core-popup-menu-separator'}}
2661		);
2662	}
2663	else
2664	{
2665		var bHasMenu = (!!item.MENU
2666			&& (
2667				(BX.type.isArray(item.MENU) && item.MENU.length > 0)
2668				|| item.MENU instanceof BX.CMenu
2669			) || !!item.MENU_URL
2670		);
2671
2672		if (item.DISABLED)
2673		{
2674			item.CLOSE_ON_CLICK = false;
2675			item.LINK = null;
2676			item.ONCLICK = null;
2677			item.ACTION = null;
2678		}
2679
2680		var attrs = {};
2681		if (!!item.LINK || BX.browser.IsIE() && !BX.browser.IsDoctype())
2682		{
2683			attrs.href = item.LINK || 'javascript:void(0)';
2684		}
2685		if (this.PARAMS.PUBLIC_FRAME)
2686		{
2687			attrs.target = '_top';
2688		}
2689
2690		item.NODE = BX.create(!!item.LINK || BX.browser.IsIE() && !BX.browser.IsDoctype() ? 'A' : 'SPAN', {
2691			props: {
2692				className: 'bx-core-popup-menu-item'
2693					+ (bHasMenu ? ' bx-core-popup-menu-item-opener' : '')
2694					+ (!!item.DEFAULT ? ' bx-core-popup-menu-item-default' : '')
2695					+ (!!item.DISABLED ? ' bx-core-popup-menu-item-disabled' : '')
2696					+ (!!item.CHECKED ? ' bx-core-popup-menu-item-checked' : ''),
2697					title: !!BX.message['MENU_ENABLE_TOOLTIP'] || !!item.SHOW_TITLE ? item.TITLE || '' : '',
2698				BXMENULEVEL: this.PARAMS.LEVEL
2699			},
2700			attrs: attrs,
2701			events: {
2702				mouseover: function()
2703				{
2704					BX.onCustomEvent('onMenuItemHover', [this.BXMENULEVEL, this.OPENER])
2705				}
2706			},
2707			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>'
2708		});
2709
2710		if (bHasMenu && !item.DISABLED)
2711		{
2712			item.NODE.OPENER = new BX.COpener({
2713				DIV: item.NODE,
2714				ACTIVE_CLASS: 'bx-core-popup-menu-item-opened',
2715				TYPE: 'hover',
2716				MENU: item.MENU,
2717				MENU_URL: item.MENU_URL,
2718				MENU_PRELOAD: !!item.MENU_PRELOAD,
2719				LEVEL: this.PARAMS.LEVEL + 1,
2720				ATTACH_MODE:'right',
2721				TIMEOUT: 500
2722			});
2723		}
2724		else if (this.PARAMS.CLOSE_ON_CLICK && (typeof item.CLOSE_ON_CLICK == 'undefined' || !!item.CLOSE_ON_CLICK))
2725		{
2726			BX.bind(item.NODE, 'click', BX.CMenu.broadcastCloseEvent);
2727		}
2728		else if (this.PARAMS.ADJUST_ON_CLICK && (typeof item.ADJUST_ON_CLICK == 'undefined' || !!item.ADJUST_ON_CLICK))
2729		{
2730			BX.bind(item.NODE, 'click', BX.defer(this.adjustPos, this));
2731		}
2732
2733		if (bHasMenu && !!item.LINK)
2734		{
2735			BX.bind(item.NODE, 'dblclick', BX.CMenu._itemDblClick);
2736		}
2737
2738		if (typeof item.CHECKED != 'undefined')
2739		{
2740			BX.bind(item.NODE, 'click', BX.CMenu._toggleChecked);
2741		}
2742
2743		item.ONCLICK = item.ACTION || item.ONCLICK;
2744		if (!!item.ONCLICK)
2745		{
2746			if (BX.type.isString(item.ONCLICK))
2747			{
2748				item.ONCLICK = new Function("event", item.ONCLICK);
2749			}
2750
2751			BX.bind(item.NODE, 'click', item.ONCLICK);
2752		}
2753	}
2754
2755	this.DIV.appendChild(item.NODE);
2756};
2757
2758BX.CMenu.prototype._documentClickBind = function()
2759{
2760	this._documentClickUnBind();
2761	BX.bind(document, 'click', BX.proxy(this._documentClick, this));
2762};
2763
2764BX.CMenu.prototype._documentClickUnBind = function()
2765{
2766	BX.unbind(document, 'click', BX.proxy(this._documentClick, this));
2767};
2768
2769BX.CMenu.prototype._documentClick = function(e)
2770{
2771	e = e||window.event;
2772	if(!!e && !(BX.getEventButton(e) & BX.MSLEFT))
2773		return;
2774
2775	this.Close();
2776};
2777
2778BX.CMenu.prototype.Show = function()
2779{
2780	BX.onCustomEvent(this, 'onMenuOpen', [this, this.PARAMS.LEVEL]);
2781	BX.CMenu.superclass.Show.apply(this, []);
2782
2783	this.bCloseEventFired = false;
2784
2785	BX.addCustomEvent(this.PARAMS.parent_attach, 'onChangeNodePosition', BX.proxy(this.adjustToNode, this));
2786
2787	(BX.defer(this._documentClickBind, this))();
2788};
2789
2790BX.CMenu.prototype.Close = // we shouldn't 'Close' window - only hide
2791BX.CMenu.prototype.Hide = function()
2792{
2793	if (!this.visible())
2794		return;
2795
2796	BX.removeCustomEvent(this.PARAMS.parent_attach, 'onChangeNodePosition', BX.proxy(this.adjustToNode, this));
2797
2798	this._documentClickUnBind();
2799
2800	if (!this.bCloseEventFired)
2801	{
2802		BX.onCustomEvent(this, 'onMenuClose', [this, this.PARAMS.LEVEL]);
2803		this.bCloseEventFired = true;
2804	}
2805	BX.CMenu.superclass.Hide.apply(this, arguments);
2806
2807
2808//	this.DIV.onclick = null;
2809	//this.PARAMS.parent.onclick = null;
2810};
2811
2812BX.CMenu.prototype.__adjustMenuToNode = function()
2813{
2814	var pos = BX.pos(this.PARAMS.parent_attach),
2815		bFixed = !!BX.findParent(this.PARAMS.parent_attach, BX.is_fixed);
2816
2817	if (bFixed)
2818		this.DIV.style.position = 'fixed';
2819	else
2820		this.DIV.style.position = 'absolute';
2821
2822	if (!pos.top)
2823	{
2824		this.DIV.style.top = '-1000px';
2825		this.DIV.style.left = '-1000px';
2826	}
2827
2828	if (this.bTimeoutSet) return;
2829
2830	var floatWidth = this.DIV.offsetWidth, floatHeight = this.DIV.offsetHeight;
2831	if (!floatWidth)
2832	{
2833		setTimeout(BX.delegate(function(){
2834			this.bTimeoutSet = false; this.__adjustMenuToNode();
2835		}, this), 100);
2836
2837		this.bTimeoutSet = true;
2838		return;
2839	}
2840
2841	var menu_pos = {},
2842		wndSize = BX.GetWindowSize();
2843
2844/*
2845	if (BX.browser.IsIE() && !BX.browser.IsDoctype())
2846	{
2847		pos.top -= 4; pos.bottom -= 4;
2848		pos.left -= 2; pos.right -= 2;
2849	}
2850*/
2851
2852	switch (this.PARAMS.ATTACH_MODE)
2853	{
2854		case 'bottom':
2855			menu_pos.top = pos.bottom + 9;
2856			menu_pos.left = pos.left;
2857
2858			var arrowPos = 0;
2859			if (!!this.ARROW)
2860			{
2861				if (pos.width > floatWidth)
2862					arrowPos = parseInt(floatWidth/2 - 7);
2863				else
2864					arrowPos = parseInt(Math.min(floatWidth, pos.width)/2 - 7);
2865
2866				if (arrowPos < 7)
2867				{
2868					menu_pos.left -= 15;
2869					arrowPos += 15;
2870				}
2871			}
2872
2873			if (menu_pos.left > wndSize.scrollWidth - floatWidth - 10)
2874			{
2875				var orig_menu_pos = menu_pos.left;
2876				menu_pos.left = wndSize.scrollWidth - floatWidth - 10;
2877
2878				if (!!this.ARROW)
2879					arrowPos += orig_menu_pos - menu_pos.left;
2880			}
2881
2882			if (bFixed)
2883			{
2884				menu_pos.left -= wndSize.scrollLeft;
2885			}
2886
2887			if (!!this.ARROW)
2888				this.ARROW.style.left = arrowPos + 'px';
2889		break;
2890		case 'right':
2891			menu_pos.top = pos.top-1;
2892			menu_pos.left = pos.right;
2893
2894			if (menu_pos.left > wndSize.scrollWidth - floatWidth - 10)
2895			{
2896				menu_pos.left = pos.left - floatWidth - 1;
2897			}
2898		break;
2899	}
2900
2901	if (bFixed)
2902	{
2903		menu_pos.top -= wndSize.scrollTop;
2904	}
2905
2906	if (!!this.ARROW)
2907		this.ARROW.className = 'bx-core-popup-menu-angle';
2908
2909	if((menu_pos.top + floatHeight >
2909 wndSize.scrollTop + wndSize.innerHeight)
2910		|| (menu_pos.top + floatHeight > wndSize.scrollHeight))
2911	{
2912		var new_top = this.PARAMS.ATTACH_MODE == 'bottom'
2913			? pos.top - floatHeight - 9
2914			: pos.bottom - floatHeight + 1;
2915
2916		if((new_top > wndSize.scrollTop)
2917			|| (menu_pos.top + floatHeight > wndSize.scrollHeight))
2918		{
2919			if ((menu_pos.top + floatHeight > wndSize.scrollHeight))
2920			{
2921				menu_pos.top = Math.max(0, wndSize.scrollHeight-floatHeight);
2922				this.toggleArrow(false);
2923			}
2924			else
2925			{
2926				menu_pos.top = new_top;
2927
2928				if (!!this.ARROW)
2929					this.ARROW.className = 'bx-core-popup-menu-angle-bottom';
2930			}
2931		}
2932	}
2933
2934	if (menu_pos.top + menu_pos.left == 0)
2935	{
2936		this.Hide();
2937	}
2938	else
2939	{
2940		this.DIV.style.top = menu_pos.top + 'px';
2941		this.DIV.style.left = menu_pos.left + 'px';
2942	}
2943};
2944
2945BX.CMenu.prototype.adjustToNode = function(el)
2946{
2947	this.PARAMS.parent_attach = BX(el) || this.PARAMS.parent_attach || this.PARAMS.parent;
2948	this.__adjustMenuToNode();
2949};
2950
2951
2952/* components toolbar class */
2953
2954BX.CMenuOpener = function(arParams)
2955{
2956	BX.CMenuOpener.superclass.constructor.apply(this);
2957
2958	this.PARAMS = arParams || {};
2959	this.setParent(this.PARAMS.parent);
2960	this.PARTS = {};
2961
2962	this.SETTINGS.drag_restrict = true;
2963
2964	this.defaultAction = null;
2965
2966	this.timeout = 500;
2967
2968	this.DIV.className = 'bx-component-opener';
2969	this.DIV.ondblclick = BX.PreventDefault;
2970
2971	if (this.PARAMS.component_id)
2972	{
2973		this.PARAMS.transform = !!this.PARAMS.transform;
2974	}
2975
2976	this.OPENERS = [];
2977
2978	this.DIV.appendChild(BX.create('SPAN', {
2979		props: {className: 'bx-context-toolbar' + (this.PARAMS.transform ? ' bx-context-toolbar-vertical-mode' : '')}
2980	}));
2981
2982	//set internal structure and register draggable element
2983	this.PARTS.INNER = this.DIV.firstChild.appendChild(BX.create('SPAN', {
2984		props: {className: 'bx-context-toolbar-inner'},
2985		html: '<span class="bx-context-toolbar-drag-icon"></span><span class="bx-context-toolbar-vertical-line"></span><br>'
2986	}));
2987
2988	this.EXTRA_BUTTONS = {};
2989
2990	var btnCount = 0;
2991	for (var i = 0, len = this.PARAMS.menu.length; i < len; i++)
2992	{
2993		var item = this.addItem(this.PARAMS.menu[i]);
2994		if (null != item)
2995		{
2996			btnCount++;
2997			this.PARTS.INNER.appendChild(item);
2998			this.PARTS.INNER.appendChild(BX.create('BR'));
2999		}
3000	}
3001	var bHasButtons = btnCount > 0;
3002
3003	//menu items will be attached here
3004
3005	this.PARTS.ICONS = this.PARTS.INNER.appendChild(BX.create('SPAN', {
3006		props: {className: 'bx-context-toolbar-icons'}
3007	}));
3008
3009	if (this.PARAMS.component_id)
3010	{
3011		this.PARAMS.pin = !!this.PARAMS.pin;
3012
3013		if (bHasButtons)
3014			this.PARTS.ICONS.appendChild(BX.create('SPAN', {props: {className: 'bx-context-toolbar-separator'}}));
3015
3016		this.PARTS.ICON_PIN = this.PARTS.ICONS.appendChild(BX.create('A', {
3017			attrs: {
3018				href: 'javascript:void(0)'
3019			},
3020			props: {
3021				className: this.PARAMS.pin
3022							? 'bx-context-toolbar-pin-fixed'
3023							: 'bx-context-toolbar-pin'
3024			},
3025			events: {
3026				click: BX.delegate(this.__pin_btn_clicked, this)
3027			}
3028		}));
3029	}
3030
3031
3032	if (this.EXTRA_BUTTONS['components2_props'])
3033	{
3034		var btn = this.EXTRA_BUTTONS['components2_props'] || {URL: 'javascript:void(0)'};
3035		if (null == this.defaultAction)
3036		{
3037			this.defaultAction = btn.ONCLICK;
3038			this.defaultActionTitle = btn.TITLE || btn.TEXT;
3039		}
3040
3041		btn.URL = 'javascript:' + BX.util.urlencode(btn.ONCLICK);
3042
3043		this.ATTACH = this.PARTS.ICONS.appendChild(BX.create('SPAN', {
3044			props: {className: 'bx-context-toolbar-button bx-context-toolbar-button-settings' },
3045			children:
3046			[
3047				BX.create('SPAN',
3048				{
3049					props:{className: 'bx-context-toolbar-button-inner'},
3050					children:
3051					[
3052						BX.create('A', {
3053							attrs: {href: btn.URL},
3054							events: {
3055								mouseover: BX.proxy(this.__msover_text, this),
3056								mouseout: BX.proxy(this.__msout_text, this),
3057								mousedown: BX.proxy(this.__msdown_text, this)
3058							},
3059							html: '<span class="bx-context-toolbar-button-icon bx-context-toolbar-settings-icon"></span>'
3060						}),
3061						BX.create('A', {
3062							attrs: {href: 'javascript: void(0)'},
3063							props: {className: 'bx-context-toolbar-button-arrow'},
3064							events: {
3065								mouseover: BX.proxy(this.__msover_arrow, this),
3066								mouseout: BX.proxy(this.__msout_arrow, this),
3067								mousedown: BX.proxy(this.__msdown_arrow, this)
3068							},
3069							html: '<span class="bx-context-toolbar-button-arrow"></span>'
3070						})
3071					]
3072				})
3073			]
3074		}));
3075
3076		this.OPENER = this.ATTACH.firstChild.lastChild;
3077
3078		var opener = this.attachMenu(this.EXTRA_BUTTONS['components2_submenu']['MENU']);
3079
3080		BX.addCustomEvent(opener, 'onOpenerMenuOpen', BX.proxy(this.__menu_open, this));
3081		BX.addCustomEvent(opener, 'onOpenerMenuClose', BX.proxy(this.__menu_close, this));
3082	}
3083
3084	if (btnCount > 1)
3085	{
3086		this.PARTS.ICONS.appendChild(BX.create('span', { props: {className: 'bx-context-toolbar-separator bx-context-toolbar-separator-switcher'}}));
3087
3088		this.ICON_TRANSFORM = this.PARTS.ICONS.appendChild(BX.create('A', {
3089			attrs: {href: 'javascript: void(0)'},
3090			props: {className: 'bx-context-toolbar-switcher'},
3091			events: {
3092				click: BX.delegate(this.__trf_btn_clicked, this)
3093			}
3094		}));
3095	}
3096
3097	if (this.PARAMS.HINT)
3098	{
3099		this.DIV.BXHINT = this.HINT = new BX.CHint({
3100			parent: this.DIV,
3101			hint:this.PARAMS.HINT.TEXT || '',
3102			title: this.PARAMS.HINT.TITLE || '',
3103			hide_timeout: this.timeout/2,
3104			preventHide: false
3105		});
3106	}
3107
3108	BX.addCustomEvent(this, 'onWindowDragFinished', BX.delegate(this.__onMoveFinished, this));
3109	BX.addCustomEvent('onDynamicModeChange', BX.delegate(this.__onDynamicModeChange, this));
3110	BX.addCustomEvent('onTopPanelCollapse', BX.delegate(this.__onPanelCollapse, this));
3111
3112	BX.addCustomEvent('onMenuOpenerMoved', BX.delegate(this.checkPosition, this));
3113	BX.addCustomEvent('onMenuOpenerUnhide', BX.delegate(this.checkPosition, this));
3114
3115	if (this.OPENERS)
3116	{
3117		for (i=0,len=this.OPENERS.length; i<len; i++)
3118		{
3119			BX.addCustomEvent(this.OPENERS[i], 'onOpenerMenuOpen', BX.proxy(this.__hide_hint, this));
3120		}
3121	}
3122};
3123BX.extend(BX.CMenuOpener, BX.CWindowFloat);
3124
3125BX.CMenuOpener.prototype.setParent = function(new_parent)
3126{
3127	new_parent = BX(new_parent);
3128	if(new_parent.OPENER && new_parent.OPENER != this)
3129	{
3130		new_parent.OPENER.Close();
3131		new_parent.OPENER.clearHoverHoutEvents();
3132	}
3133
3134	if(this.PARAMS.parent && this.PARAMS.parent != new_parent)
3135	{
3136		this.clearHoverHoutEvents();
3137		this.PARAMS.parent.OPENER = null;
3138	}
3139
3140	this.PARAMS.parent = new_parent;
3141	this.PARAMS.parent.OPENER = this;
3142};
3143
3144BX.CMenuOpener.prototype.setHoverHoutEvents = function(hover, hout)
3145{
3146	if(!this.__opener_events_set)
3147	{
3148		BX.bind(this.Get(), 'mouseover', hover);
3149		BX.bind(this.Get(), 'mouseout', hout);
3150		this.__opener_events_set = true;
3151	}
3152};
3153
3154BX.CMenuOpener.prototype.clearHoverHoutEvents = function()
3155{
3156	if(this.Get())
3157	{
3158		BX.unbindAll(this.Get());
3159		this.__opener_events_set = false;
3160	}
3161};
3162
3163
3164BX.CMenuOpener.prototype.unclosable = true;
3165
3166BX.CMenuOpener.prototype.__check_intersection = function(pos_self, pos_other)
3167{
3168	return !(pos_other.right <= pos_self.left || pos_other.left >= pos_self.right
3169			|| pos_other.bottom <= pos_self.top || pos_other.top >= pos_self.bottom);
3170};
3171
3172
3173BX.CMenuOpener.prototype.__msover_text = function() {
3174	this.bx_hover = true;
3175	if (!this._menu_open)
3176		BX.addClass(this.ATTACH, 'bx-context-toolbar-button-text-hover');
3177};
3178
3179BX.CMenuOpener.prototype.__msout_text = function() {
3180	this.bx_hover = false;
3181	if (!this._menu_open)
3182		BX.removeClass(this.ATTACH, 'bx-context-toolbar-button-text-hover bx-context-toolbar-button-text-active');
3183};
3184
3185BX.CMenuOpener.prototype.__msover_arrow = function() {
3186	this.bx_hover = true;
3187	if (!this._menu_open)
3188		BX.addClass(this.ATTACH, 'bx-context-toolbar-button-arrow-hover');
3189};
3190
3191BX.CMenuOpener.prototype.__msout_arrow = function() {
3192	this.bx_hover = false;
3193	if (!this._menu_open)
3194		BX.removeClass(this.ATTACH, 'bx-context-toolbar-button-arrow-hover bx-context-toolbar-button-arrow-active');
3195};
3196
3197BX.CMenuOpener.prototype.__msdown_text = function() {
3198	this.bx_active = true;
3199	if (!this._menu_open)
3200		BX.addClass(this.ATTACH, 'bx-context-toolbar-button-text-active');
3201};
3202
3203BX.CMenuOpener.prototype.__msdown_arrow = function() {
3204	this.bx_active = true;
3205	if (!this._menu_open)
3206		BX.addClass(this.ATTACH, 'bx-context-toolbar-button-arrow-active');
3207};
3208
3209BX.CMenuOpener.prototype.__menu_close = function() {
3210	this._menu_open = false;
3211	this.bx_active = false;
3212	BX.removeClass(this.ATTACH, 'bx-context-toolbar-button-active bx-context-toolbar-button-text-active bx-context-toolbar-button-arrow-active');
3213	if (!this.bx_hover)
3214	{
3215		BX.removeClass(this.ATTACH, 'bx-context-toolbar-button-hover bx-context-toolbar-button-text-hover bx-context-toolbar-button-arrow-hover');
3216		this.bx_hover = false;
3217	}
3218};
3219
3220BX.CMenuOpener.prototype.__menu_open = function() {
3221	this._menu_open = true;
3222};
3223
3224BX.CMenuOpener.prototype.checkPosition = function()
3225{
3226	if (this.isMenuVisible() || this.DIV.style.display == 'none'
3227		|| this == BX.proxy_context || BX.proxy_context.zIndex > this.zIndex)
3228		return;
3229
3230	this.correctPosition(BX.proxy_context);
3231};
3232
3233BX.CMenuOpener.prototype.correctPosition = function(opener)
3234{
3235	var pos_self = BX.pos(this.DIV), pos_other = BX.pos(opener.Get());
3236	if (this.__check_intersection(pos_self, pos_other))
3237	{
3238		var new_top = pos_other.top - pos_self.height;
3239		if (new_top < 0)
3240			new_top = pos_other.bottom;
3241
3242		this.DIV.style.top = new_top + 'px';
3243
3244		BX.addCustomEvent(opener, 'onMenuOpenerHide', BX.proxy(this.restorePosition, this));
3245		BX.onCustomEvent(this, 'onMenuOpenerMoved');
3246	}
3247};
3248
3249BX.CMenuOpener.prototype.restorePosition = function()
3250{
3251	if (!this.MOUSEOVER && !this.isMenuVisible())
3252	{
3253		if (this.originalPos)
3254			this.DIV.style.top = this.originalPos.top + 'px';
3255
3256		BX.removeCustomEvent(BX.proxy_context, 'onMenuOpenerHide', BX.proxy(this.restorePosition, this));
3257		if (this.restore_pos_timeout) clearTimeout(this.restore_pos_timeout);
3258	}
3259	else
3260	{
3261		this.restore_pos_timeout = setTimeout(BX.proxy(this.restorePosition, this), this.timeout);
3262	}
3263};
3264
3265
3266BX.CMenuOpener.prototype.Show = function()
3267{
3268	BX.CMenuOpener.superclass.Show.apply(this, arguments);
3269
3270	this.SetDraggable(this.PARTS.INNER.firstChild);
3271
3272	this.DIV.style.width = 'auto';
3273	this.DIV.style.height = 'auto';
3274
3275	if (!this.PARAMS.pin)
3276	{
3277		this.DIV.style.left = '-1000px';
3278		this.DIV.style.top = '-1000px';
3279
3280		this.Hide();
3281	}
3282	else
3283	{
3284		this.bPosAdjusted = true;
3285		this.bMoved = true;
3286
3287		if (this.PARAMS.top) this.DIV.style.top = this.PARAMS.top + 'px';
3288		if (this.PARAMS.left) this.DIV.style.left = this.PARAMS.left + 'px';
3289
3290		this.DIV.style.display = (!BX.admin.dynamic_mode || BX.admin.dynamic_mode_show_borders) ? 'block' : 'none';
3291
3292		if (this.DIV.style.display == 'block')
3293		{
3294			setTimeout(BX.delegate(function() {BX.onCustomEvent(this, 'onMenuOpenerUnhide')}, this), 50);
3295		}
3296	}
3297};
3298
3299BX.CMenuOpener.prototype.executeDefaultAction = function()
3300{
3301	if (this.defaultAction)
3302	{
3303		if (BX.type.isFunction(this.defaultAction))
3304			this.defaultAction();
3305		else if(BX.type.isString(this.defaultAction))
3306			BX.evalGlobal(this.defaultAction);
3307	}
3308};
3309
3310BX.CMenuOpener.prototype.__onDynamicModeChange = function(val)
3311{
3312	this.DIV.style.display = val ? 'block' : 'none';
3313};
3314
3315BX.CMenuOpener.prototype.__onPanelCollapse = function(bCollapsed, dy)
3316{
3317	this.DIV.style.top = (parseInt(this.DIV.style.top) + dy) + 'px';
3318	if (this.PARAMS.pin)
3319	{
3320		this.__savePosition();
3321	}
3322};
3323
3324BX.CMenuOpener.prototype.__onMoveFinished = function()
3325{
3326	BX.onCustomEvent(this, 'onMenuOpenerMoved');
3327
3328	this.bMoved = true;
3329
3330	if (this.PARAMS.pin)
3331		this.__savePosition();
3332};
3333
3334BX.CMenuOpener.prototype.__savePosition = function()
3335{
3336	var arOpts = {};
3337
3338	arOpts.pin = this.PARAMS.pin;
3339	if (!this.PARAMS.pin)
3340	{
3341		arOpts.top = false; arOpts.left = false; arOpts.transform = false;
3342	}
3343	else
3344	{
3345		arOpts.transform = this.PARAMS.transform;
3346		if (this.bMoved)
3347		{
3348			arOpts.left = parseInt(this.DIV.style.left);
3349			arOpts.top = parseInt(this.DIV.style.top);
3350		}
3351	}
3352
3353	BX.WindowManager.saveWindowOptions(this.PARAMS.component_id, arOpts);
3354};
3355
3356BX.CMenuOpener.prototype.__pin_btn_clicked = function() {this.Pin()};
3357BX.CMenuOpener.prototype.Pin = function(val)
3358{
3359	if (null == val)
3360		this.PARAMS.pin = !this.PARAMS.pin;
3361	else
3362		this.PARAMS.pin = !!val;
3363
3364	this.PARTS.ICON_PIN.className = (this.PARAMS.pin ? 'bx-context-toolbar-pin-fixed' : 'bx-context-toolbar-pin');
3365
3366	this.__savePosition();
3367};
3368
3369BX.CMenuOpener.prototype.__trf_btn_clicked = function() {this.Transform()};
3370BX.CMenuOpener.prototype.Transform = function(val)
3371{
3372	var pos = {};
3373
3374	if (null == val)
3375		this.PARAMS.transform = !this.PARAMS.transform;
3376	else
3377		this.PARAMS.transform = !!val;
3378
3379	if (this.bMoved)
3380	{
3381		pos = BX.pos(this.DIV);
3382	}
3383
3384	if (this.PARAMS.transform)
3385		BX.addClass(this.DIV.firstChild, 'bx-context-toolbar-vertical-mode');
3386	else
3387		BX.removeClass(this.DIV.firstChild, 'bx-context-toolbar-vertical-mode');
3388
3389	if (!this.bMoved)
3390	{
3391		this.adjustPos();
3392	}
3393	else
3394	{
3395		this.DIV.style.left = (pos.right - this.DIV.offsetWidth - (BX.browser.IsIE() && !BX.browser.IsDoctype() ? 2 : 0)) + 'px';
3396	}
3397
3398	this.__savePosition();
3399};
3400
3401BX.CMenuOpener.prototype.adjustToNodeGetPos = function()
3402{
3403	var pos = BX.pos(this.PARAMS.parent/*, true*/);
3404
3405	var scrollSize = BX.GetWindowScrollSize();
3406	var floatWidth = this.DIV.offsetWidth;
3407
3408	pos.left -= BX.admin.__border_dx;
3409	pos.top -= BX.admin.__border_dx;
3410
3411	if (true || !this.PARAMS.transform)
3412	{
3413		pos.top -= 45;
3414	}
3415
3416	if (pos.left > scrollSize.scrollWidth - floatWidth)
3417	{
3418		pos.left = scrollSize.scrollWidth - floatWidth;
3419	}
3420
3421	return pos;
3422};
3423
3424BX.CMenuOpener.prototype.addItem = function(item)
3425{
3426	if (item.TYPE)
3427	{
3428		this.EXTRA_BUTTONS[item.TYPE] = item;
3429		return null;
3430	}
3431	else
3432	{
3433		var q = new BX.CMenuOpenerItem(item);
3434		if (null == this.defaultAction)
3435		{
3436			if (q.item.ONCLICK)
3437			{
3438				this.defaultAction = item.ONCLICK;
3439			}
3440			else if (q.item.MENU)
3441			{
3442				this.defaultAction = BX.delegate(function() {this.Open()}, q.item.OPENER);
3443			}
3444
3445			this.defaultActionTitle = item.TITLE || item.TEXT;
3446
3447			BX.addClass(q.Get(), 'bx-content-toolbar-default');
3448		}
3449		if (q.item.OPENER) this.OPENERS[this.OPENERS.length] = q.item.OPENER;
3450		return q.Get();
3451	}
3452};
3453
3454BX.CMenuOpener.prototype.attachMenu = function(menu)
3455{
3456	var opener = new BX.COpener({
3457		'DIV':  this.OPENER,
3458		'ATTACH': this.ATTACH,
3459		'MENU': menu,
3460		'TYPE': 'click'
3461	});
3462
3463	this.OPENERS[this.OPENERS.length] = opener;
3464
3465	return opener;
3466};
3467
3468BX.CMenuOpener.prototype.__hide_hint = function()
3469{
3470	if (this.HINT) this.HINT.__hide_immediately();
3471};
3472
3473BX.CMenuOpener.prototype.isMenuVisible = function()
3474{
3475	for (var i=0,len=this.OPENERS.length; i<len; i++)
3476	{
3477		if (this.OPENERS[i].isMenuVisible())
3478			return true;
3479	}
3480
3481	return false;
3482};
3483
3484BX.CMenuOpener.prototype.Hide = function()
3485{
3486	if (!this.PARAMS.pin)
3487	{
3488		this.DIV.style.display = 'none';
3489		BX.onCustomEvent(this, 'onMenuOpenerHide');
3490	}
3491};
3492BX.CMenuOpener.prototype.UnHide = function()
3493{
3494	this.DIV.style.display = 'block';
3495	if (!this.bPosAdjusted && !this.PARAMS.pin)
3496	{
3497		this.adjustPos();
3498		this.bPosAdjusted = true;
3499	}
3500
3501	if (null == this.originalPos && !this.bMoved)
3502	{
3503		this.originalPos = BX.pos(this.DIV);
3504	}
3505
3506	BX.onCustomEvent(this, 'onMenuOpenerUnhide');
3507};
3508
3509BX.CMenuOpenerItem = function(item)
3510{
3511	this.item = item;
3512
3513	if (this.item.ACTION && !this.item.ONCLICK)
3514	{
3515		this.item.ONCLICK = this.item.ACTION;
3516	}
3517
3518	this.DIV = BX.create('SPAN');
3519	this.DIV.appendChild(BX.create('SPAN', {props: {className: 'bx-context-toolbar-button-underlay'}}));
3520
3521	this.WRAPPER = this.DIV.appendChild(BX.create('SPAN', {
3522		props: {className: 'bx-context-toolbar-button-wrapper'},
3523		children: [
3524			BX.create('SPAN', {
3525				props: {className: 'bx-context-toolbar-button', title: item.TITLE},
3526				children: [
3527					BX.create('SPAN', {
3528						props: {className: 'bx-context-toolbar-button-inner'}
3529					})
3530				]
3531			})
3532		]
3533	}));
3534
3535	var btn_icon = BX.create('SPAN', {
3536		props: {className: 'bx-context-toolbar-button-icon' + (this.item.ICON || this.item.ICONCLASS ? ' ' + (this.item.ICON || this.item.ICONCLASS) : '')},
3537		attrs: (
3538				!(this.item.ICON || this.item.ICONCLASS)
3539				&&
3540				(this.item.SRC || this.item.IMAGE)
3541			)
3542			? {
3543				style: 'background: scroll transparent url(' + (this.item.SRC || this.item.IMAGE) + ') no-repeat center center !important;'
3544			}
3545			: {}
3546	}), btn_text = BX.create('SPAN', {
3547		props: {className: 'bx-context-toolbar-button-text'},
3548		text: this.item.TEXT
3549	});
3550
3551	if (this.item.ACTION && !this.item.ONCLICK)
3552	{
3553		this.item.ONCLICK = this.item.ACTION;
3554	}
3555
3556	this.bHasMenu = !!this.item.MENU;
3557	this.bHasAction = !!this.item.ONCLICK;
3558
3559	if (this.bHasAction)
3560	{
3561		this.LINK = this.WRAPPER.firstChild.firstChild.appendChild(BX.create('A', {
3562			attrs: {
3563				'href': 'javascript: void(0)'
3564			},
3565			events: {
3566				mouseover: this.bHasMenu ? BX.proxy(this.__msover_text, this) : BX.proxy(this.__msover, this),
3567				mouseout: this.bHasMenu ? BX.proxy(this.__msout_text, this) : BX.proxy(this.__msout, this),
3568				mousedown: this.bHasMenu ? BX.proxy(this.__msdown_text, this) : BX.proxy(this.__msdown, this)
3569			},
3570			children: [btn_icon, btn_text]
3571		}));
3572
3573		if (this.bHasMenu)
3574		{
3575			this.LINK_MENU = this.WRAPPER.firstChild.firstChild.appendChild(BX.create('A', {
3576				props: {className: 'bx-context-toolbar-button-arrow'},
3577				attrs: {
3578					'href': 'javascript: void(0)'
3579				},
3580				events: {
3581					mouseover: BX.proxy(this.__msover_arrow, this),
3582					mouseout: BX.proxy(this.__msout_arrow, this),
3583					mousedown: BX.proxy(this.__msdown_arrow, this)
3584				},
3585				children: [
3586					BX.create('SPAN', {props: {className: 'bx-context-toolbar-button-arrow'}})
3587				]
3588			}));
3589		}
3590
3591	}
3592	else if (this.bHasMenu)
3593	{
3594		this.item.ONCLICK = null;
3595
3596		this.LINK = this.LINK_MENU = this.WRAPPER.firstChild.firstChild.appendChild(BX.create('A', {
3597			attrs: {
3598				'href': 'javascript: void(0)'
3599			},
3600			events: {
3601				mouseover: BX.proxy(this.__msover, this),
3602				mouseout: BX.proxy(this.__msout, this),
3603				mousedown: BX.proxy(this.__msdown, this)
3604			},
3605			children: [
3606				btn_icon,
3607				btn_text
3608			]
3609		}));
3610
3611		this.LINK.appendChild(BX.create('SPAN', {props: {className: 'bx-context-toolbar-single-button-arrow'}}));
3612
3613	}
3614
3615	if (this.bHasMenu)
3616	{
3617		this.item.SUBMENU = new BX.CMenu({
3618			ATTACH_MODE:'bottom',
3619			ITEMS:this.item['MENU'],
3620			//PARENT_MENU:this.parentMenu,
3621			parent: this.LINK_MENU,
3622			parent_attach: this.WRAPPER.firstChild
3623		});
3624
3625		this.item.OPENER = new BX.COpener({
3626			DIV: this.LINK_MENU,
3627			TYPE: 'click',
3628			MENU: this.item.SUBMENU
3629		});
3630
3631		BX.addCustomEvent(this.item.OPENER, 'onOpenerMenuOpen', BX.proxy(this.__menu_open, this));
3632		BX.addCustomEvent(this.item.OPENER, 'onOpenerMenuClose', BX.proxy(this.__menu_close, this));
3633	}
3634
3635	if (this.bHasAction)
3636	{
3637		BX.bind(this.LINK, 'click', BX.delegate(this.__click, this));
3638	}
3639};
3640
3641BX.CMenuOpenerItem.prototype.Get = function() {return this.DIV;};
3642BX.CMenuOpenerItem.prototype.__msover = function() {
3643	this.bx_hover = true;
3644	if (!this._menu_open)
3645		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-hover');
3646};
3647BX.CMenuOpenerItem.prototype.__msout = function() {
3648	this.bx_hover = false;
3649	if (!this._menu_open)
3650		BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-hover bx-context-toolbar-button-active');
3651};
3652BX.CMenuOpenerItem.prototype.__msover_text = function() {
3653	this.bx_hover = true;
3654	if (!this._menu_open)
3655		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-text-hover');
3656};
3657BX.CMenuOpenerItem.prototype.__msout_text = function() {
3658	this.bx_hover = false;
3659	if (!this._menu_open)
3660		BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-text-hover bx-context-toolbar-button-text-active');
3661};
3662BX.CMenuOpenerItem.prototype.__msover_arrow = function() {
3663	this.bx_hover = true;
3664	if (!this._menu_open)
3665		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-arrow-hover');
3666};
3667BX.CMenuOpenerItem.prototype.__msout_arrow = function() {
3668	this.bx_hover = false;
3669	if (!this._menu_open)
3670		BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-arrow-hover bx-context-toolbar-button-arrow-active');
3671};
3672BX.CMenuOpenerItem.prototype.__msdown = function() {
3673	this.bx_active = true;
3674	if (!this._menu_open)
3675		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-active');
3676};
3677BX.CMenuOpenerItem.prototype.__msdown_text = function() {
3678	this.bx_active = true;
3679	if (!this._menu_open)
3680		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-text-active');
3681};
3682BX.CMenuOpenerItem.prototype.__msdown_arrow = function() {
3683	this.bx_active = true;
3684	if (!this._menu_open)
3685		BX.addClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-arrow-active');
3686};
3687BX.CMenuOpenerItem.prototype.__menu_close = function() {
3688
3689	this._menu_open = false;
3690	this.bx_active = false;
3691	BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-active bx-context-toolbar-button-text-active bx-context-toolbar-button-arrow-active');
3692	if (!this.bx_hover)
3693	{
3694		BX.removeClass(this.LINK.parentNode.parentNode, 'bx-context-toolbar-button-hover bx-context-toolbar-button-text-hover bx-context-toolbar-button-arrow-hover');
3695		this.bx_hover = false;
3696	}
3697};
3698BX.CMenuOpenerItem.prototype.__menu_open = function() {
3699	this._menu_open = true;
3700};
3701
3702BX.CMenuOpenerItem.prototype.__click = function() {BX.evalGlobal(this.item.ONCLICK)};
3703
3704/* global page opener class */
3705BX.CPageOpener = function(arParams)
3706{
3707	//if (null == arParams.pin) arParams.pin = true;
3708	BX.CPageOpener.superclass.constructor.apply(this, arguments);
3709
3710	this.timeout = 505;
3711
3712	window.PAGE_EDIT_CONTROL = this;
3713};
3714BX.extend(BX.CPageOpener, BX.CMenuOpener);
3715
3716BX.CPageOpener.prototype.checkPosition = function()
3717{
3718	if (/*this.isMenuVisible() || this.DIV.style.display == 'none' || */this == BX.proxy_context)
3719		return;
3720
3721	this.correctPosition(BX.proxy_context);
3722};
3723
3724BX.CPageOpener.prototype.correctPosition = function(opener)
3725{
3726	if (this.bPosCorrected) return;
3727	var pos_self;
3728	if (this.DIV.style.display == 'none')
3729	{
3730		pos_self = this.adjustToNodeGetPos();
3731		pos_self.bottom = pos_self.top + 30;
3732		pos_self.right = pos_self.left + 300;
3733	}
3734	else
3735	{
3736		pos_self = BX.pos(this.DIV);
3737	}
3738
3739	var pos_other = BX.pos(opener.Get());
3740	if (this.__check_intersection(pos_self, pos_other))
3741	{
3742		this.DIV.style.display = 'none';
3743		BX.addCustomEvent(opener, 'onMenuOpenerHide', BX.proxy(this.restorePosition, this));
3744
3745		this.bPosCorrected = true;
3746	}
3747};
3748
3749BX.CPageOpener.prototype.restorePosition = function()
3750{
3751	if (BX.proxy_context && BX.proxy_context.Get().style.display == 'none')
3752	{
3753		this.bPosCorrected = false;
3754
3755		if (this.PARAMS.parent.bx_over || this.PARAMS.pin)
3756			this.UnHide();
3757
3758		BX.removeCustomEvent('onMenuOpenerHide', BX.proxy(this.restorePosition, this));
3759	}
3760};
3761
3762BX.CPageOpener.prototype.UnHide = function()
3763{
3764	if (!this.bPosCorrected)
3765		BX.CPageOpener.superclass.UnHide.apply(this, arguments);
3766};
3767
3768BX.CPageOpener.prototype.Remove = function()
3769{
3770	BX.admin.removeComponentBorder(this.PARAMS.parent);
3771	BX.userOptions.save('global', 'settings', 'page_edit_control_enable', 'N');
3772	this.DIV.style.display = 'none';
3773};
3774
3775/******* HINT ***************/
3776BX.CHintSimple = function()
3777{
3778	BX.CHintSimple.superclass.constructor.apply(this, arguments);
3779};
3780BX.extend(BX.CHintSimple, BX.CHint);
3781
3782BX.CHintSimple.prototype.Init = function()
3783{
3784	this.DIV = document.body.appendChild(BX.create('DIV', {props: {className: 'bx-tooltip-simple'}, style: {display: 'none'}, children: [(this.CONTENT = BX.create('DIV'))]}));
3785
3786	if (this.HINT_TITLE)
3787		this.CONTENT.appendChild(BX.create('B', {text: this.HINT_TITLE}));
3788
3789	if (this.HINT)
3790		this.CONTENT_TEXT = this.CONTENT.appendChild(BX.create('DIV')).appendChild(BX.create('SPAN', {html: this.HINT}));
3791
3792	if (this.PARAMS.preventHide)
3793	{
3794		BX.bind(this.DIV, 'mouseout', BX.proxy(this.Hide, this));
3795		BX.bind(this.DIV, 'mouseover', BX.proxy(this.Show, this));
3796	}
3797
3798	this.bInited = true;
3799};
3800
3801/*************************** admin informer **********************************/
3802BX.adminInformer = {
3803
3804	itemsShow: 3,
3805
3806	Init: function (itemsShow)
3807	{
3808		if(itemsShow)
3809			BX.adminInformer.itemsShow = itemsShow;
3810
3811		var informer = BX("admin-informer");
3812
3813		if(informer)
3814			document.body.appendChild(informer);
3815
3816		BX.addCustomEvent("onTopPanelCollapse", BX.proxy(BX.adminInformer.Close, BX.adminInformer));
3817	},
3818
3819	Toggle: function(notifyBlock)
3820	{
3821		var informer = BX("admin-informer");
3822
3823		if(!informer)
3824			return false;
3825
3826		var pos = BX.pos(notifyBlock);
3827
3828		informer.style.top = (parseInt(pos.top)+parseInt(pos.height)+7)+'px';
3829		informer.style.left = pos.left+'px';
3830
3831		if(!BX.hasClass(informer, "adm-informer-active"))
3832			BX.adminInformer.Show(informer);
3833		else
3834			BX.adminInformer.Hide(informer);
3835
3836		return false;
3837	},
3838
3839	Close: function()
3840	{
3841		BX.adminInformer.Hide(BX("admin-informer"));
3842	},
3843
3844	OnInnerClick: function(event)
3845	{
3846		var target = event.target || event.srcElement;
3847
3848		if(target.nodeName.toLowerCase() != 'a' || BX.hasClass(target,"adm-informer-footer"))
3849		{
3850			return BX.PreventDefault(event);
3851		}
3852
3853		return true;
3854	},
3855
3856	ToggleExtra : function()
3857	{
3858		var footerLink = BX("adm-informer-footer");
3859
3860		if (BX.hasClass(footerLink, "adm-informer-footer-collapsed"))
3861			this.ShowAll();
3862		else
3863			this.HideExtra();
3864
3865		return false;
3866	},
3867
3868	ShowAll: function()
3869	{
3870		var informer = BX("admin-informer");
3871		for(var i=0; i<informer.children.length; i++)
3872
3873			if(BX.hasClass(informer.children[i], "adm-informer-item") && informer.children[i].style.display == "none") {
3874				informer.children[i].style.display = "block";
3875			}
3876
3877		var footerLink = BX("adm-informer-footer");
3878
3879		if(footerLink.textContent !== undefined)
3880			footerLink.textContent = BX.message('JSADM_AI_HIDE_EXTRA');
3881		else
3882			footerLink.innerText = BX.message('JSADM_AI_HIDE_EXTRA');
3883
3884		BX.removeClass(footerLink, "adm-informer-footer-collapsed");
3885
3886		return false;
3887	},
3888
3889	HideExtra: function()
3890	{
3891		var informer = BX("admin-informer");
3892		var hided = 0;
3893
3894		for(var i=BX.adminInformer.itemsShow+1; i<informer.children.length; i++)
3895		{
3896			if (BX.hasClass(informer.children[i], "adm-informer-item") && informer.children[i].style.display == "block") {
3897				informer.children[i].style.display = "none";
3898				hided++;
3899			}
3900		}
3901
3902		var footerLink = BX("adm-informer-footer");
3903
3904		var linkText = BX.message('JSADM_AI_ALL_NOTIF')+" ("+(BX.adminInformer.itemsShow+parseInt(hided))+")";
3905
3906		if(footerLink.textContent !== undefined)
3907			footerLink.textContent = linkText;
3908		else
3909			footerLink.innerText = linkText;
3910
3911		BX.addClass(footerLink, "adm-informer-footer-collapsed");
3912
3913		return false;
3914	},
3915
3916	Show: function(informer)
3917	{
3918		var notifButton = BX("adm-header-notif-block");
3919		if (notifButton)
3920			BX.addClass(notifButton, "adm-header-notif-block-active");
3921
3922		BX.onCustomEvent(informer, 'onBeforeAdminInformerShow');
3923		setTimeout(
3924			BX.proxy(function() {
3925					BX.bind(document, "click", BX.proxy(BX.adminInformer.Close, BX.adminInformer));
3926				},
3927				BX.adminInformer
3928			),0
3929		);
3930		BX.addClass(informer, "adm-informer-active");
3931		setTimeout(function() {BX.addClass(informer, "adm-informer-animate");},0);
3932	},
3933
3934	Hide: function(informer)
3935	{
3936		var notifButton = BX("adm-header-notif-block");
3937		if (notifButton)
3938			BX.removeClass(notifButton, "adm-header-notif-block-active");
3939
3940		BX.unbind(document, "click", BX.proxy(BX.adminInformer.Close, BX.adminInformer));
3941
3942		BX.removeClass(informer, "adm-informer-animate");
3943
3944		if (this.IsAnimationSupported())
3945			setTimeout(function() {BX.removeClass(informer, "adm-informer-active");}, 300);
3946		else
3947			BX.removeClass(informer, "adm-informer-active");
3948
3949		BX.onCustomEvent(informer, 'onAdminInformerHide');
3950		//setTimeout(function() {BX.adminInformer.HideExtra();},500);
3951	},
3952
3953	IsAnimationSupported : function()
3954	{
3955		var d = document.body || document.documentElement;
3956		if (typeof(d.style.transition) == "string")
3957			return true;
3958		else if (typeof(d.style.MozTransition) == "string")
3959			return true;
3960		else if (typeof(d.style.OTransition) == "string")
3961			return true;
3962		else if (typeof(d.style.WebkitTransition) == "string")
3963			return true;
3964		else if (typeof(d.style.msTransition) == "string")
3965			return true;
3966
3967		return false;
3968	},
3969
3970
3971	SetItemHtml: function(itemIdx, html)
3972	{
3973		var itemHtmlDiv = BX("adm-informer-item-html-"+itemIdx);
3974
3975		if(!itemHtmlDiv)
3976			return false;
3977
3978		itemHtmlDiv.innerHTML = html;
3979
3980		return true;
3981	},
3982
3983	SetItemFooter: function(itemIdx, html)
3984	{
3985		var itemFooterDiv = BX("adm-informer-item-footer-"+itemIdx);
3986
3987		if(!itemFooterDiv)
3988			return false;
3989
3990		itemFooterDiv.innerHTML = html;
3991
3992		if(html)
3993			itemFooterDiv.style.display = "block";
3994		else
3995			itemFooterDiv.style.display = "none";
3996
3997		return true;
3998	}
3999
4000};
4001
4002}
4002)(window);
4003

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.