PageSourceSearch

http://electricprojects.ru/bitrix/js/main/utils.js

js electricprojects.ru collected 2026-10-06 04:15:37 UTC 30,951 bytes, 1,353 lines download raw bytes

1var phpVars;
2if(!phpVars)
3{
4	phpVars = {
5		ADMIN_THEME_ID: '.default',
6		LANGUAGE_ID: 'en',
7		FORMAT_DATE: 'DD.MM.YYYY',
8		FORMAT_DATETIME: 'DD.MM.YYYY HH:MI:SS',
9		opt_context_ctrl: false,
10		cookiePrefix: 'BITRIX_SM',
11		titlePrefix: '',
12		bitrix_sessid: '',
13		messHideMenu: '',
14		messShowMenu: '',
15		messHideButtons: '',
16		messShowButtons: '',
17		messFilterInactive: '',
18		messFilterActive: '',
19		messFilterLess: '',
20		messLoading: 'Loading...',
21		messMenuLoading: '',
22		messMenuLoadingTitle: '',
23		messNoData: '',
24		messExpandTabs: '',
25		messCollapseTabs: '',
26		messPanelFixOn: '',
27		messPanelFixOff: '',
28		messPanelCollapse: '',
29		messPanelExpand: ''
30	};
31}
32
33var jsUtils =
34{
35	arEvents: Array(),
36
37	addEvent: function(el, evname, func, capture)
38	{
39		if(el.attachEvent) // IE
40			el.attachEvent("on" + evname, func);
41		else if(el.addEventListener) // Gecko / W3C
42			el.addEventListener(evname, func, false);
43		else
44			el["on" + evname] = func;
45		this.arEvents[this.arEvents.length] = {'element': el, 'event': evname, 'fn': func};
46	},
47
48	removeEvent: function(el, evname, func)
49	{
50		if(el.detachEvent) // IE
51			el.detachEvent("on" + evname, func);
52		else if(el.removeEventListener) // Gecko / W3C
53			el.removeEventListener(evname, func, false);
54		else
55			el["on" + evname] = null;
56	},
57
58	removeAllEvents: function(el)
59	{
60		var i;
61		for(i=0; i<this.arEvents.length; i++)
62		{
63			if(this.arEvents[i] && (el==false || el==this.arEvents[i].element))
64			{
65				jsUtils.removeEvent(this.arEvents[i].element, this.arEvents[i].event, this.arEvents[i].fn);
66				this.arEvents[i] = null;
67			}
68		}
69		if(el==false)
70			this.arEvents.length = 0;
71	},
72
73	IsDoctype: function()
74	{
75		if (document.compatMode)
76			return (document.compatMode == "CSS1Compat");
77
78		if (document.documentElement && document.documentElement.clientHeight)
79			return true;
80
81		return false;
82	},
83
84	GetRealPos: function(el)
85	{
86		if(window.BX)
87			return BX.pos(el);
88
89		if(!el || !el.offsetParent)
90			return false;
91
92		var res = Array();
93		res["left"] = el.offsetLeft;
94		res["top"] = el.offsetTop;
95		var objParent = el.offsetParent;
96
97		while(objParent && objParent.tagName != "BODY")
98		{
99			res["left"] += objParent.offsetLeft;
100			res["top"] += objParent.offsetTop;
101			objParent = objParent.offsetParent;
102		}
103		res["right"] = res["left"] + el.offsetWidth;
104		res["bottom"] = res["top"] + el.offsetHeight;
105
106		return res;
107	},
108
109	FindChildObject: function(obj, tag_name, class_name, recursive)
110	{
111		if(!obj)
112			return null;
113		var tag = tag_name.toUpperCase();
114		var cl = (class_name? class_name.toLowerCase() : null);
115		var n = obj.childNodes.length;
116		for(var j=0; j<n; j++)
117		{
118			var child = obj.childNodes[j];
119			if(child.tagName && child.tagName.toUpperCase() == tag)
120				if(!class_name || child.className.toLowerCase() == cl)
121					return child;
122			if(recursive == true)
123			{
124				var deepChild;
125				if((deepChild = jsUtils.FindChildObject(child, tag_name, class_name, true)))
126					return deepChild;
127			}
128		}
129		return null;
130	},
131
132	FindParentObject: function(obj, tag_name, class_name)
133	{
134		if(!obj)
135			return null;
136		var o = obj;
137		var tag = tag_name.toUpperCase();
138		var cl = (class_name? class_name.toLowerCase() : null);
139		while(o.parentNode)
140		{
141			var parent = o.parentNode;
142			if(parent.tagName && parent.tagName.toUpperCase() == tag)
143				if(!class_name || parent.className.toLowerCase() == cl)
144					return parent;
145			o = parent;
146		}
147		return null;
148	},
149
150	FindNextSibling: function(obj, tag_name)
151	{
152		if(!obj)
153			return null;
154		var o = obj;
155		var tag = tag_name.toUpperCase();
156		while(o.nextSibling)
157		{
158			var sibling = o.nextSibling;
159			if(sibling.tagName && sibling.tagName.toUpperCase() == tag)
160				return sibling;
161			o = sibling;
162		}
163		return null;
164	},
165
166	FindPreviousSibling: function(obj, tag_name)
167	{
168		if(!obj)
169			return null;
170		var o = obj;
171		var tag = tag_name.toUpperCase();
172		while(o.previousSibling)
173		{
174			var sibling = o.previousSibling;
175			if(sibling.tagName && sibling.tagName.toUpperCase() == tag)
176				return sibling;
177			o = sibling;
178		}
179		return null;
180	},
181
182	bOpera : navigator.userAgent.toLowerCase().indexOf('opera') != -1,
183	bIsIE : document.attachEvent && navigator.userAgent.toLowerCase().indexOf('opera') == -1,
184
185	IsIE: function()
186	{
187		return this.bIsIE;
188	},
189
190	IsOpera: function()
191	{
192		return this.bOpera;
193	},
194
195	IsSafari: function()
196	{
197		var userAgent = navigator.userAgent.toLowerCase();
198		return (/webkit/.test(userAgent));
199	},
200
201	IsEditor: function()
202	{
203		var userAgent = navigator.userAgent.toLowerCase();
204		var version = (userAgent.match( /.+(msie)[\/: ]([\d.]+)/ ) || [])[2];
205		var safari = /webkit/.test(userAgent);
206
207		if (this.IsOpera() || (document.all && !document.compatMode && version < 6) || safari)
208			return false;
209
210		return true;
211	},
212
213	ToggleDiv: function(div)
214	{
215		var style = document.getElementById(div).style;
216		if(style.display!="none")
217			style.display = "none";
218		else
219			style.display = "block";
220		return (style.display != "none");
221	},
222
223	urlencode: function(s)
224	{
225		return escape(s).replace(new RegExp('\\+','g'), '%2B');
226	},
227
228	OpenWindow: function(url, width, height)
229	{
230		var w = screen.width, h = screen.height;
231		if(this.IsOpera())
232		{
233			w = document.body.offsetWidth;
234			h = document.body.offsetHeight;
235		}
236		window.open(url, '', 'status=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',top='+Math.floor((h - height)/2-14)+',left='+Math.floor((w - width)/2-5));
237	},
238
239	SetPageTitle: function(s)
240	{
241		document.title = phpVars.titlePrefix+s;
242		var h1 = document.getElementsByTagName("H1");
243		if(h1)
244			h1[0].innerHTML = s;
245	},
246
247	LoadPageToDiv: function(url, div_id)
248	{
249		var div = document.getElementById(div_id);
250		if(!div)
251			return;
252		CHttpRequest.Action = function(result)
253		{
254			CloseWaitWindow();
255			document.getElementById(div_id).innerHTML = result;
256		}
257		ShowWaitWindow();
258		CHttpRequest.Send(url);
259	},
260
261	trim: function(s)
262	{
263		if (typeof s == 'string' || typeof s == 'object' && s.constructor == String)
264		{
265			var r, re;
266
267			re = /^[\s\r\n]+/g;
268			r = s.replace(re, "");
269			re = /[\s\r\n]+$/g;
270			r = r.replace(re, "");
271			return r;
272		}
273		else
274			return s;
275	},
276
277	Redirect: function(args, url)
278	{
279		var e = null, bShift = false;
280		if(args && args.length > 0)
281			e = args[0];
282		if(!e)
283			e = window.event;
284		if(e)
285			bShift = e.shiftKey;
286
287		if(bShift)
288			window.open(url);
289		else
290		{
291			ShowWaitWindow();
292			window.location.href=url;
293		}
294	},
295
296	False: function(){return false;},
297
298	AlignToPos: function(pos, w, h)
299	{
300		var x = pos["left"], y = pos["bottom"];
301
302		var scroll = jsUtils.GetWindowScrollPos();
303		var size = jsUtils.GetWindowInnerSize();
304
305		if((size.innerWidth + scroll.scrollLeft) - (pos["left"] + w) < 0)
306		{
307			if(pos["right"] - w >= 0 )
308				x = pos["right"] - w;
309			else
310				x = scroll.scrollLeft;
311		}
312
313		if((size.innerHeight + scroll.scrollTop) - (pos["bottom"] + h) < 0)
314		{
315			if(pos["top"] - h >= 0)
316				y = pos["top"] - h;
317			else
318				y = scroll.scrollTop;
319		}
320
321		return {'left':x, 'top':y};
322	},
323
324	// evaluate js string in window scope
325	EvalGlobal: function(script)
326	{
327		try {
328		if (window.execScript)
329			window.execScript(script, 'javascript');
330		else if (jsUtils.IsSafari())
331			window.setTimeout(script, 0);
332		else
333			window.eval(script);
334		} catch (e) {/*alert("Error! jsUtils.EvalGlobal");*/}
335	},
336
337	GetStyleValue: function(el, styleProp)
338	{
339		var res;
340		if(el.currentStyle)
341			res = el.currentStyle[styleProp];
342		else if(window.getComputedStyle)
343			res = document.defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
344		if(!res)
345			res = '';
346		return res;
347	},
348
349	GetWindowInnerSize: function(pDoc)
350	{
351		var width, height;
352		if (!pDoc)
353			pDoc = document;
354
355		if (self.innerHeight) // all except Explorer
356		{
357			width = self.innerWidth;
358			height = self.innerHeight;
359		}
360		else if (pDoc.documentElement && (pDoc.documentElement.clientHeight || pDoc.documentElement.clientWidth)) // Explorer 6 Strict Mode
361		{
362			width = pDoc.documentElement.clientWidth;
363			height = pDoc.documentElement.clientHeight;
364		}
365		else if (pDoc.body) // other Explorers
366		{
367			width = pDoc.body.clientWidth;
368			height = pDoc.body.clientHeight;
369		}
370		return {innerWidth : width, innerHeight : height};
371	},
372
373	GetWindowScrollPos: function(pDoc)
374	{
375		var left, top;
376		if (!pDoc)
377			pDoc = document;
378
379		if (self.pageYOffset) // all except Explorer
380		{
381			left = self.pageXOffset;
382			top = self.pageYOffset;
383		}
384		else if (pDoc.documentElement && (pDoc.documentElement.scrollTop || pDoc.documentElement.scrollLeft)) // Explorer 6 Strict
385		{
386			left = document.documentElement.scrollLeft;
387			top = document.documentElement.scrollTop;
388		}
389		else if (pDoc.body) // all other Explorers
390		{
391			left = pDoc.body.scrollLeft;
392			top = pDoc.body.scrollTop;
393		}
394		return {scrollLeft : left, scrollTop : top};
395	},
396
397	GetWindowScrollSize: function(pDoc)
398	{
399		var width, height;
400		if (!pDoc)
401			pDoc = document;
402
403		if ( (pDoc.compatMode && pDoc.compatMode == "CSS1Compat"))
404		{
405			width = pDoc.documentElement.scrollWidth;
406			height = pDoc.documentElement.scrollHeight;
407		}
408		else
409		{
410			if (pDoc.body.scrollHeight > pDoc.body.offsetHeight)
411				height = pDoc.body.scrollHeight;
412			else
413				height = pDoc.body.offsetHeight;
414
415			if (pDoc.body.scrollWidth > pDoc.body.offsetWidth ||
416				(pDoc.compatMode && pDoc.compatMode == "BackCompat") ||
417				(pDoc.documentElement && !pDoc.documentElement.clientWidth)
418			)
419				width = pDoc.body.scrollWidth;
420			else
421				width = pDoc.body.offsetWidth;
422		}
423		return {scrollWidth : width, scrollHeight : height};
424	},
425
426	GetWindowSize: function()
427	{
428		var innerSize = jsUtils.GetWindowInnerSize();
429		var scrollPos = jsUtils.GetWindowScrollPos();
430		var scrollSize = jsUtils.GetWindowScrollSize();
431
432		return  {
433			innerWidth : innerSize.innerWidth, innerHeight : innerSize.innerHeight,
434			scrollLeft : scrollPos.scrollLeft, scrollTop : scrollPos.scrollTop,
435			scrollWidth : scrollSize.scrollWidth, scrollHeight : scrollSize.scrollHeight
436		};
437	},
438
439
440	arCustomEvents: {},
441
442	addCustomEvent: function(eventName, eventHandler, arParams, handlerContextObject)
443	{
444		if (!this.arCustomEvents[eventName])
445			this.arCustomEvents[eventName] = [];
446
447		if (!arParams)
448			arParams = [];
449		if (!handlerContextObject)
450			handlerContextObject = false;
451
452		this.arCustomEvents[eventName].push(
453			{
454				handler: eventHandler,
455				arParams: arParams,
456				obj: handlerContextObject
457			}
458		);
459	},
460
461	removeCustomEvent: function(eventName, eventHandler)
462	{
463		if (!this.arCustomEvents[eventName])
464			return;
465
466		var l = this.arCustomEvents[eventName].length;
467		if (l == 1)
468		{
469			delete this.arCustomEvents[eventName];
470			return;
471		}
472
473		for (var i = 0; i < l; i++)
474		{
475			if (!this.arCustomEvents[eventName][i])
476				continue;
477			if (this.arCustomEvents[eventName][i].handler == eventHandler)
478			{
479				delete this.arCustomEvents[eventName][i];
480				return;
481			}
482		}
483	},
484
485	onCustomEvent: function(eventName, arEventParams)
486	{
487		if (!this.arCustomEvents[eventName])
488			return;
489
490		if (!arEventParams)
491			arEventParams = [];
492
493		var h;
494		for (var i = 0, l = this.arCustomEvents[eventName].length; i < l; i++)
495		{
496			h = this.arCustomEvents[eventName][i];
497			if (!h || !h.handler)
498				continue;
499
500			if (h.obj)
501				h.handler.call(h.obj, h.arParams, arEventParams);
502			else
503				h.handler(h.arParams, arEventParams);
504		}
505	},
506
507	loadJSFile: function(arJs, oCallBack, pDoc)
508	{
509		if (!pDoc)
510			pDoc = document;
511		if (typeof arJs == 'string')
512			arJs = [arJs];
513		var callback = function()
514		{
515			if (!oCallBack)
516				return;
517			if (typeof oCallBack == 'function')
518				return oCallBack();
519			if (typeof oCallBack != 'object' || !oCallBack.func)
520				return;
521			var p = oCallBack.params || {};
522			if (oCallBack.obj)
523				oCallBack.func.apply(oCallBack.obj, p);
524			else
525				oCallBack.func(p);
526		};
527		var load_js = function(ind)
528		{
529			if (ind >= arJs.length)
530				return callback();
531			var oSript = pDoc.body.appendChild(pDoc.createElement('script'));
532			oSript.src = arJs[ind];
533			var bLoaded = false;
534			oSript.onload = oSript.onreadystatechange = function()
535			{
536				if (!bLoaded && (!oSript.readyState || oSript.readyState == "loaded" || oSript.readyState == "complete"))
537				{
538					bLoaded = true;
539					setTimeout(function (){load_js(++ind);}, 50);
540				}
541			};
542		};
543		load_js(0);
544	},
545
546	loadCSSFile: function(arCSS, pDoc, pWin)
547	{
548		if (typeof arCSS == 'string')
549		{
550			var bSingle = true;
551			arCSS = [arCSS];
552		}
553		var i, l = arCSS.length, pLnk = [];
554		if (l == 0)
555			return;
556		if (!pDoc)
557			pDoc = document;
558		if (!pWin)
559			pWin = window;
560		if (!pWin.bxhead)
561		{
562			var heads = pDoc.getElementsByTagName('HEAD');
563			pWin.bxhead = heads[0];
564		}
565		if (!pWin.bxhead)
566			return;
567		for (i = 0; i < l; i++)
568		{
569			var lnk = document.createElement('LINK');
570			lnk.href = arCSS[i];
571			lnk.rel = 'stylesheet';
572			lnk.type = 'text/css';
573			pWin.bxhead.appendChild(lnk);
574			pLnk.push(lnk);
575		}
576		if (bSingle)
577			return lnk;
578		return pLnk;
579	},
580
581	appendBXHint : function(node, html)
582	{
583		if (!node || !node.parentNode || !html)
584			return;
585		var oBXHint = new BXHint(html);
586		node.parentNode.insertBefore(oBXHint.oIcon, node);
587		node.parentNode.removeChild(node);
588		oBXHint.oIcon.style.marginLeft = "5px";
589	},
590
591	PreventDefault : function(e)
592	{
593		if(!e) e = window.event;
594		if(e.stopPropagation)
595		{
596			e.preventDefault();
597			e.stopPropagation();
598		}
599		else
600		{
601			e.cancelBubble = true;
602			e.returnValue = false;
603		}
604		return false;
605	},
606
607	CreateElement: function(tag, arAttr, arStyles, pDoc)
608	{
609		if (!pDoc)
610			pDoc = document;
611		var pEl = pDoc.createElement(tag), p;
612		if(arAttr)
613		{
614			for(p in arAttr)
615			{
616				if(p == 'className' || p == 'class')
617				{
618					pEl.setAttribute('class', arAttr[p]);
619					if (jsUtils.IsIE())
620						pEl.setAttribute('className', arAttr[p]);
621					continue;
622				}
623
624				if (arAttr[p] != undefined && arAttr[p] != null)
625					pEl.setAttribute(p, arAttr[p]);
626			}
627		}
628		if(arStyles)
629		{
630			for(p in arStyles)
631				pEl.style[p] = arStyles[p];
632		}
633		return pEl;
634	},
635
636	in_array: function(needle, haystack)
637	{
638		for(var i=0; i<haystack.length; i++)
639		{
640			if(haystack[i] == needle)
641				return true;
642		}
643		return false;
644	},
645
646	htmlspecialchars: function(str)
647	{
648		if(!str.replace)
649			return str;
650
651		return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
652	}
653}
654
655/************************************************/
656
657function JCFloatDiv()
658{
659	var _this = this;
660	this.floatDiv = null;
661	this.x = this.y = 0;
662
663	this.Create = function(arParams)
664	{
665		var div = document.body.appendChild(document.createElement("DIV"));
666		div.id = arParams.id;
667		div.style.position = 'absolute';
668		div.style.left = '-10000px';
669		div.style.top = '-10000px';
670		if(arParams.className)
671			div.className = arParams.className;
672		if(arParams.zIndex)
673			div.style.zIndex = arParams.zIndex;
674		if(arParams.width)
675			div.style.width = arParams.width+'px';
676		if(arParams.height)
677			div.style.height = arParams.height+'px';
678		return div;
679	}
680
681	this.Show = function(div, left, top, dxShadow, restrictDrag, showSubFrame)
682	{
683		if (showSubFrame !== false)
684			showSubFrame = true;
685		var zIndex = parseInt(div.style.zIndex);
686		if(zIndex <= 0 || isNaN(zIndex))
687			zIndex = 100;
688
689		//document.title = 'zIndex = ' + zIndex;
690		div.style.zIndex = zIndex;
691
692		if (left < 0)
693			left = 0;
694
695		if (top < 0)
696			top = 0;
697
698		div.style.left = parseInt(left) + "px";
699		div.style.top = parseInt(top) + "px";
700
701		if(jsUtils.IsIE() && showSubFrame === true)
702		{
703			var frame = document.getElementById(div.id+"_frame");
704			if(!frame)
705			{
706				frame = document.createElement("IFRAME");
707				frame.src = "javascript:''";
708				frame.id = div.id+"_frame";
709				frame.style.position = 'absolute';
710				frame.style.borderWidth = '0px';
711				frame.style.zIndex = zIndex-1;
712				document.body.appendChild(frame);
713			}
714			frame.style.width = div.offsetWidth + "px";
715			frame.style.height = div.offsetHeight + "px";
716			frame.style.left = div.style.left;
717			frame.style.top = div.style.top;
718			frame.style.visibility = 'visible';
719		}
720
721		/*Restrict drag*/
722		div.restrictDrag = restrictDrag || false;
723
724		/*shadow*/
725		if(isNaN(dxShadow))
726			dxShadow = 5;
727
728		if(dxShadow > 0)
729		{
730			var img = document.getElementById(div.id+'_shadow');
731			if(!img)
732			{
733				if(jsUtils.IsIE())
734				{
735		 			img = document.createElement("DIV");
736		 			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/bitrix/themes/"+phpVars.ADMIN_THEME_ID+"/images/shadow.png',sizingMethod='scale')";
737				}
738				else
739				{
740		 			img = document.createElement("IMG");
741					img.src = '/bitrix/themes/' + phpVars.ADMIN_THEME_ID+'/images/shadow.png';
742				}
743				img.id = div.id+'_shadow';
744				img.style.position = 'absolute';
745				img.style.zIndex = zIndex-2;
746				img.style.left = '-1000px';
747				img.style.top = '-1000px';
748				img.style.lineHeight = 'normal';
749				document.body.appendChild(img);
750			}
751			img.style.width = div.offsetWidth+'px';
752			img.style.height = div.offsetHeight+'px';
753			img.style.left = parseInt(div.style.left)+dxShadow+'px';
754			img.style.top = parseInt(div.style.top)+dxShadow+'px';
755			img.style.visibility = 'visible';
756		}
757		div.dxShadow = dxShadow;
758	}
759
760	this.Close = function(div)
761	{
762		if(!div)
763			return;
764		var sh = document.getElementById(div.id+"_shadow");
765		if(sh)
766			sh.style.visibility = 'hidden';
767
768		var frame = document.getElementById(div.id+"_frame");
769		if(frame)
770			frame.style.visibility = 'hidden';
771	}
772
773	this.Move = function(div, x, y)
774	{
775		if(!div)
776			return;
777
778		var dxShadow = div.dxShadow;
779		var left = parseInt(div.style.left)+x;
780		var top = parseInt(div.style.top)+y;
781
782		if (div.restrictDrag)
783		{
784			//Left side
785			if (left < 0)
786				left = 0;
787
788			//Right side
789			if ( (document.compatMode && document.compatMode == "CSS1Compat"))
790				windowWidth = document.documentElement.scrollWidth;
791			else
792			{
793				if (document.body.scrollWidth > document.body.offsetWidth ||
794					(document.compatMode && document.compatMode == "BackCompat") ||
795					(document.documentElement && !document.documentElement.clientWidth)
796				)
797					windowWidth = document.body.scrollWidth;
798				else
799					windowWidth = document.body.offsetWidth;
800			}
801
802			var floatWidth = div.offsetWidth;
803			if (left > (windowWidth - floatWidth - dxShadow))
804				left = windowWidth - floatWidth - dxShadow;
805
806			//Top side
807			if (top < 0)
808				top = 0;
809		}
810
811		div.style.left = left+'px';
812		div.style.top = top+'px';
813
814		this.AdjustShadow(div);
815	}
816
817	this.HideShadow = function(div)
818	{
819		var sh = document.getElementById(div.id + "_shadow");
820		sh.style.visibility = 'hidden';
821	}
822
823	this.UnhideShadow = function(div)
824	{
825		var sh = document.getElementById(div.id + "_shadow");
826		sh.style.visibility = 'visible';
827	}
828
829	this.AdjustShadow = function(div)
830	{
831		var sh = document.getElementById(div.id + "_shadow");
832		if(sh && sh.style.visibility != 'hidden')
833		{
834			var dxShadow = div.dxShadow;
835
836			sh.style.width = div.offsetWidth+'px';
837			sh.style.height = div.offsetHeight+'px';
838			sh.style.left = parseInt(div.style.left)+dxShadow+'px';
839			sh.style.top = parseInt(div.style.top)+dxShadow+'px';
840		}
841
842		var frame = document.getElementById(div.id+"_frame");
843		if(frame)
844		{
845			frame.style.width = div.offsetWidth + "px";
846			frame.style.height = div.offsetHeight + "px";
847			frame.style.left = div.style.left;
848			frame.style.top = div.style.top;
849		}
850	}
851
852	this.StartDrag = function(e, div)
853	{
854		if(!e)
855			e = window.event;
856		this.x = e.clientX + document.body.scrollLeft;
857		this.y = e.clientY + document.body.scrollTop;
858		this.floatDiv = div;
859
860		jsUtils.addEvent(document, "mousemove", this.MoveDrag);
861		document.onmouseup = this.StopDrag;
862		if(document.body.setCapture)
863			document.body.setCapture();
864
865		document.onmousedown = jsUtils.False;
866		var b = document.body;
867		b.ondrag = jsUtils.False;
868		b.onselectstart = jsUtils.False;
869		b.style.MozUserSelect = _this.floatDiv.style.MozUserSelect = 'none';
870		b.style.cursor = 'move';
871	}
872
873	this.StopDrag = function(e)
874	{
875		if(document.body.releaseCapture)
876			document.body.releaseCapture();
877
878		jsUtils.removeEvent(document, "mousemove", _this.MoveDrag);
879		document.onmouseup = null;
880
881		this.floatDiv = null;
882
883		document.onmousedown = null;
884		var b = document.body;
885		b.ondrag = null;
886		b.onselectstart = null;
887		b.style.MozUserSelect = _this.floatDiv.style.MozUserSelect = '';
888		b.style.cursor = '';
889	}
890
891	this.MoveDrag = function(e)
892	{
893		var x = e.clientX + document.body.scrollLeft;
894		var y = e.clientY + document.body.scrollTop;
895
896		if(_this.x == x && _this.y == y)
897			return;
898
899		_this.Move(_this.floatDiv, (x - _this.x), (y - _this.y));
900		_this.x = x;
901		_this.y = y;
902	}
903}
904var jsFloatDiv = new JCFloatDiv();
905
906/************************************************/
907
908var BXHint = function(innerHTML, element, addParams)
909{
910	this.oDivOver = false;
911	this.timeOutID = null;
912	this.oIcon = null;
913	this.freeze = false;
914	this.x = 0;
915	this.y = 0;
916	this.time = 700;
917
918	if (!innerHTML)
919		innerHTML = "";
920	this.Create(innerHTML, element, addParams);
921}
922
923BXHint.prototype.Create = function(innerHTML, element, addParams)
924{
925	var
926		_this = this,
927		width = 0,
928		height = 0,
929		className = null,
930		type = "icon";
931	this.bWidth = true;
932
933	if (addParams)
934	{
935		if (addParams.width === false)
936			this.bWidth = false;
937		else if (addParams.width)
938			width = addParams.width;
939
940		if (addParams.height)
941			height = addParams.height;
942
943		if (addParams.className)
944			className = addParams.className;
945
946		if (addParams.type && (addParams.type == "link" || addParams.type == "icon"))
947			type = addParams.type;
948		if (addParams.time > 0)
949			this.time = addParams.time;
950	}
951
952	if (element)
953		type = "element";
954
955	if (type == "icon")
956	{
957		var element = document.createElement("IMG");
958		element.src = (addParams && addParams.iconSrc) ? addParams.iconSrc : "/bitrix/themes/"+phpVars.ADMIN_THEME_ID+"/public/popup/hint.gif";
959		element.ondrag = jsUtils.False;
960	}
961	else if (type == "link")
962	{
963		var element = document.createElement("A");
964		element.href = "";
965		element.onclick = function(e){return false;}
966		element.innerHTML = "[?]";
967	}
968
969	this.element = element;
970	if (type == "element")
971	{
972		if(addParams && addParams.show_on_click)
973		{
974			jsUtils.addEvent(
975				element,
976				"click",
977				function (event)
978				{
979					if (!event)
980						event = window.event;
981					_this.GetMouseXY(event);
982					_this.timeOutID = setTimeout(function () {_this.Show(innerHTML,width,height,className) }, 10);
983				}
984			);
985		}
986		else
987		{
988			jsUtils.addEvent(
989				element,
990				"mouseover",
991				function (event)
992				{
993					if (!event)
994						event = window.event;
995					_this.GetMouseXY(event);
996					_this.timeOutID = setTimeout(function () {_this.Show(innerHTML,width,height,className) }, 750);
997				}
998			);
999		}
1000
1001		jsUtils.addEvent(
1002			element,
1003			"mouseout",
1004			function(event)
1005			{
1006				if (_this.timeOutID)
1007					clearTimeout(_this.timeOutID);
1008				_this.SmartHide(_this);
1009			}
1010		);
1011	}
1012	else
1013	{
1014		this.oIcon = element;
1015		element.onmouseover = function(event) {if (!event) event = window.event; _this.GetMouseXY(event); _this.Show(innerHTML,width,height,className)};
1016		element.onmouseout = function() {_this.SmartHide(_this);};
1017	}
1018}
1019
1020BXHint.prototype.IsFrozen = function()
1021{
1022	return this.freeze;
1023}
1024
1025BXHint.prototype.Freeze = function()
1026{
1027	this.freeze = true;
1028	this.Hide();
1029}
1030
1031BXHint.prototype.UnFreeze = function()
1032{
1033	this.freeze = false;
1034}
1035
1036BXHint.prototype.GetMouseXY = function(event)
1037{
1038	if (event.pageX || event.pageY)
1039	{
1040		this.x = event.pageX;
1041		this.y = event.pageY;
1042	}
1043	else if (event.clientX || event.clientY)
1044	{
1045		this.x = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
1046		this.y = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
1047	}
1048}
1049
1050BXHint.prototype.Show = function(innerHTML, width, height, className)
1051{
1052	//Delete previous hint
1053	var old = document.getElementById("__BXHint_div");
1054	if (old)
1055		this.Hide();
1056
1057	if (this.freeze)
1058		return;
1059
1060	var _this = this;
1061	var oDiv = document.body.appendChild(document.createElement("DIV"));
1062	oDiv.onmouseover = function(){_this.oDivOver = true};
1063	oDiv.onmouseout = function(){_this.oDivOver = false; _this.SmartHide(_this);}
1064	oDiv.id = "__BXHint_div";
1065	oDiv.className = (className) ? className : "bxhint";
1066	oDiv.style.position = 'absolute';
1067	if (width && this.bWidth)
1068		oDiv.style.width = width + "px";
1069
1070	if (height)
1071		oDiv.style.height = height + "px";
1072	oDiv.innerHTML = innerHTML;
1073
1074	var w = oDiv.offsetWidth;
1075	var h = oDiv.offsetHeight;
1076	if (this.bWidth)
1077	{
1078		if (!width && w>200)
1079			w = Math.round(Math.sqrt(1.618*w*h));
1080		oDiv.style.width = w + "px";
1081		h = oDiv.offsetHeight;
1082	}
1083
1084	var pos = {left : this.x + 10, right : this.x + w, top : this.y, bottom : this.y + h};
1085
1086	pos = this.AlignToPos(pos, w, h);
1087
1088	oDiv.style.zIndex = 2100;
1089
1090	jsFloatDiv.Show(oDiv, pos.left, pos.top,3);
1091
1092//	oDiv.ondrag = jsUtils.False;
1093//	oDiv.onselectstart = jsUtils.False;
1094//	oDiv.style.MozUserSelect = 'none';
1095	oDiv = null;
1096}
1097
1098BXHint.prototype.AlignToPos = function(pos, w, h)
1099{
1100	var body = document.body;
1101	if((body.clientWidth + body.scrollLeft) < (pos.left + w))
1102		pos.left = (pos.left - w >= 0) ? (pos.left - w) : body.scrollLeft;
1103
1104	if((body.clientHeight + body.scrollTop) - (pos["bottom"]) < 0)
1105		pos.top = (pos.top - h >= 0) ? (pos.top - h) : body.scrollTop;
1106
1107	return pos;
1108}
1109
1110BXHint.prototype.Hide = function()
1111{
1112	var oDiv = document.getElementById("__BXHint_div");
1113
1114	if (!oDiv)
1115		return;
1116
1117	jsFloatDiv.Close(oDiv);
1118	oDiv.parentNode.removeChild(oDiv);
1119	oDiv = null;
1120}
1121
1122BXHint.prototype.SmartHide = function(_this)
1123{
1124	setTimeout(function ()
1125		{
1126			if (!_this.oDivOver)
1127				_this.Hide();
1128		}, 100
1129	);
1130}
1131
1132/************************************************/
1133
1134function WaitOnKeyPress(e)
1135{
1136	if(!e) e = window.event
1137	if(!e) return;
1138	if(e.keyCode == 27)
1139		CloseWaitWindow();
1140}
1141
1142function ShowWaitWindow()
1143{
1144	CloseWaitWindow();
1145
1146	var obWndSize = jsUtils.GetWindowSize();
1147
1148	var div = document.body.appendChild(document.createElement("DIV"));
1149	div.id = "wait_window_div";
1150	div.innerHTML = phpVars.messLoading;
1151	div.className = "waitwindow";
1152	//div.style.left = obWndSize.scrollLeft + (obWndSize.innerWidth - div.offsetWidth) - (jsUtils.IsIE() ? 5 : 20) + "px";
1153	div.style.right = (5 - obWndSize.scrollLeft) + 'px';
1154	div.style.top = obWndSize.scrollTop + 5 + "px";
1155
1156	if(jsUtils.IsIE())
1157	{
1158		var frame = document.createElement("IFRAME");
1159		frame.src = "javascript:''";
1160		frame.id = "wait_window_frame";
1161		frame.className = "waitwindow";
1162		frame.style.width = div.offsetWidth + "px";
1163		frame.style.height = div.offsetHeight + "px";
1164		frame.style.right = div.style.right;
1165		frame.style.top = div.style.top;
1166		document.body.appendChild(frame);
1167	}
1168	jsUtils.addEvent(document, "keypress", WaitOnKeyPress);
1169}
1170
1171function CloseWaitWindow()
1172{
1173	jsUtils.removeEvent(document, "keypress", WaitOnKeyPress);
1174
1175	var frame = document.getElementById("wait_window_frame");
1176	if(frame)
1177		frame.parentNode.removeChild(frame);
1178
1179	var div = document.getElementById("wait_window_div");
1180	if(div)
1181		div.parentNode.removeChild(div);
1182}
1183
1184/************************************************/
1185
1186var jsSelectUtils =
1187{
1188	addNewOption: function(select_id, opt_value, opt_name, do_sort, check_unique)
1189	{
1190		var oSelect = (typeof(select_id) == 'string' || select_id instanceof String? document.getElementById(select_id) : select_id);
1191		if(oSelect)
1192		{
1193			var n = oSelect.length;
1194			if(check_unique !== false)
1195			{
1196				for(var i=0;i<n;i++)
1197					if(oSelect[i].value==opt_value)
1198						return;
1199			}
1200			var newoption = new Option(opt_name, opt_value, false, false);
1201			oSelect.options[n]=newoption;
1202		}
1203		if(do_sort === true)
1204			this.sortSelect(select_id);
1205	},
1206
1207	deleteOption: function(select_id, opt_value)
1208	{
1209		var oSelect = (typeof(select_id) == 'string' || select_id instanceof String? document.getElementById(select_id) : select_id);
1210		if(oSelect)
1211		{
1212			for(var i=0;i<oSelect.length;i++)
1213				if(oSelect[i].value==opt_value)
1214				{
1215					oSelect.remove(i);
1216					break;
1217				}
1218		}
1219	},
1220
1221	deleteSelectedOptions: function(select_id)
1222	{
1223		var oSelect = (typeof(select_id) == 'string' || select_id instanceof String? document.getElementById(select_id) : select_id);
1224		if(oSelect)
1225		{
1226			var i=0;
1227			while(i<oSelect.length)
1228				if(oSelect[i].selected)
1229				{
1230					oSelect[i].selected=false;
1231					oSelect.remove(i);
1232				}
1233				else
1234					i++;
1235		}
1236	},
1237
1238	deleteAllOptions: function(oSelect)
1239	{
1240		if(oSelect)
1241		{
1242			for(var i=oSelect.length-1; i>=0; i--)
1243				oSelect.remove(i);
1244		}
1245	},
1246
1247	optionCompare: function(record1, record2)
1248	{
1249		var value1 = record1.optText.toLowerCase();
1250		var value2 = record2.optText.toLowerCase();
1251		if (value1 > value2) return(1);
1252		if (value1 < value2) return(-1);
1253		return(0);
1254	},
1255
1256	sortSelect: function(select_id)
1257	{
1258		var oSelect = (typeof(select_id) == 'string' || select_id instanceof String? document.getElementById(select_id) : select_id);
1259		if(oSelect)
1260		{
1261			var myOptions = [];
1262			var n = oSelect.options.length;
1263			for (var i=0;i<n;i++)
1264			{
1265				myOptions[i] = {
1266					optText:oSelect[i].text,
1267					optValue:oSelect[i].value
1268				};
1269			}
1270			myOptions.sort(this.optionCompare);
1271			oSelect.length=0;
1272			n = myOptions.length;
1273			for(var i=0;i<n;i++)
1274			{
1275				var newoption = new Option(myOptions[i].optText, myOptions[i].optValue, false, false);
1276				oSelect[i]=newoption;
1277			}
1278		}
1279	},
1280
1281	selectAllOptions: function(select_id)
1282	{
1283		var oSelect = (typeof(select_id) == 'string' || select_id instanceof String? document.getElementById(select_id) : select_id);
1284		if(oSelect)
1285		{
1286			var n = oSelect.length;
1287			for(var i=0;i<n;i++)
1288				oSelect[i].selected=true;
1289		}
1290	},
1291
1292	selectOption: function(select_id, opt_value)
1293	{
1294		var oSelect = (typeof(select_id) == 'string' || select_id instanceof String? document.getElementById(select_id) : select_id);
1295		if(oSelect)
1296		{
1297			var n = oSelect.length;
1298			for(var i=0;i<n;i++)
1299				oSelect[i].selected = (oSelect[i].value == opt_value);
1300		}
1301	},
1302
1303	addSelectedOptions: function(oSelect, to_select_id, check_unique, do_sort)
1304	{
1305		if(!oSelect)
1306			return;
1307		var n = oSelect.length;
1308		for(var i=0; i<n; i++)
1309			if(oSelect[i].selected)
1310				this.addNewOption(to_select_id, oSelect[i].value, oSelect[i].text, do_sort, check_unique);
1311	},
1312
1313	moveOptionsUp: function(oSelect)
1314	{
1315		if(!oSelect)
1316			return;
1317		var n = oSelect.length;
1318		for(var i=0; i<n; i++)
1319		{
1320			if(oSelect[i].selected && i>0 && oSelect[i-1].selected == false)
1321			{
1322				var option1 = new Option(oSelect[i].text, oSelect[i].value);
1323				var option2 = new Option(oSelect[i-1].text, oSelect[i-1].value);
1324				oSelect[i] = option2;
1325				oSelect[i].selected = false;
1326				oSelect[i-1] = option1;
1327				oSelect[i-1].selected = true;
1328			}
1329		}
1330	},
1331
1332	moveOptionsDown: function(oSelect)
1333	{
1334		if(!oSelect)
1335			return;
1336		var n = oSelect.length;
1337		for(var i=n-1; i>=0; i--)
1338		{
1339			if(oSelect[i].selected && i<n-1 && oSelect[i+1].selected == false)
1340			{
1341				var option1 = new Option(oSelect[i].text, oSelect[i].value);
1342				var option2 = new Option(oSelect[i+1].text, oSelect[i+1].value);
1343				oSelect[i] = option2;
1344				oSelect[i].selected = false;
1345				oSelect[i+1] = option1;
1346				oSelect[i+1].selected = true;
1347			}
1348		}
1349	}
1350
1351}
1352
1353/************************************************/

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.