PageSourceSearch

https://podarok.by/bitrix/js/main/ajax.js?159466980035509

js podarok.by collected 2026-09-25 10:29:16 UTC 35,509 bytes, 1,431 lines download raw bytes

1/***********************************************************
2Bitrix AJAX library ver 6.5 alpha 
3***********************************************************/
4
5/*
6private CAjaxThread class - description of current AJAX request thread.
7*/
8function CAjaxThread(TID)
9{
10	this.TID = TID;
11	this.httpRequest = this._CreateHttpObject();
12	this.arAction = [];
13}
14
15CAjaxThread.prototype._CreateHttpObject = function()
16{
17	var obj = null;
18	if (window.XMLHttpRequest)
19	{
20		try {obj = new XMLHttpRequest();} catch(e){}
21	}
22	else if (window.ActiveXObject)
23	{
24		try {obj = new ActiveXObject("Microsoft.XMLHTTP");} catch(e){}
25		if (!obj)
26			try {obj = new ActiveXObject("Msxml2.XMLHTTP");} catch (e){}
27	}
28	return obj;
29}
30
31CAjaxThread.prototype.addAction = function(obHandler)
32{
33	this.arAction.push(obHandler);
34}
35
36CAjaxThread.prototype.clearActions = function()
37{
38	this.arAction = [];
39}
40
41CAjaxThread.prototype.nextAction = function()
42{
43	return this.arAction.shift();
44}
45
46CAjaxThread.prototype.Clear = function()
47{
48	this.arAction = null;
49	this.httpRequest = null;
50}
51
52/*
53public CAjax main class
54*/
55function CAjax()
56{
57	this.arThreads = {};
58	this.obTemporary = null;
59}
60
61CAjax.prototype._PrepareData = function(arData, prefix)
62{
63	var data = '';
64	if (null != arData)
65	{
66		for(var i in arData)
67		{
68			if (data.length > 0) data += '&';
69			var name = jsAjaxUtil.urlencode(i);
70			if(prefix)
71				name = prefix + '[' + name + ']';
72			if(typeof arData[i] == 'object')
73				data += this._PrepareData(arData[i], name)
74			else
75				data += name + '=' + jsAjaxUtil.urlencode(arData[i])
76		}
77	}
78	return data;
79}
80
81CAjax.prototype.GetThread = function(TID)
82{
83	return this.arThreads[TID];
84}
85
86CAjax.prototype.InitThread = function()
87{
88	while (true)
89	{
90		var TID = 'TID' + Math.floor(Math.random() * 1000000);
91		if (!this.arThreads[TID]) break;
92	}
93
94	this.arThreads[TID] = new CAjaxThread(TID);
95	
96	return TID;
97}
98
99CAjax.prototype.AddAction = function(TID, obHandler)
100{
101	if (this.arThreads[TID])
102	{
103		this.arThreads[TID].addAction(obHandler);
104	}
105}
106
107CAjax.prototype._OnDataReady = function(TID, result)
108{
109	if (!this.arThreads[TID]) return;
110
111	while (obHandler = this.arThreads[TID].nextAction())
112	{
113		obHandler(result);
114	}
115}
116	
117CAjax.prototype._Close = function(TID)
118{
119	if (!this.arThreads[TID]) return;
120
121	this.arThreads[TID].Clear();
122	this.arThreads[TID] = null;
123}
124	
125CAjax.prototype._SetHandler = function(TID)
126{
127	var oAjax = this;
128	
129	function __cancelQuery(e)
130	{
131		if (!e) e = window.event
132		if (!e) return;
133		if (e.keyCode == 27)
134		{
135			oAjax._Close(TID);
136			jsEvent.removeEvent(document, 'keypress', this);
137		}
138	}
139	
140	function __handlerReadyStateChange()
141	{
142		if (oAjax.bCancelled) return;
143		if (!oAjax.arThreads[TID]) return;
144		if (!oAjax.arThreads[TID].httpRequest) return;
145		if (oAjax.arThreads[TID].httpRequest.readyState == 4)
146		{
147			var status = oAjax.arThreads[TID].httpRequest.getResponseHeader('X-Bitrix-Ajax-Status');
148			var bRedirect = (status == 'Redirect');
149			
150			var s = oAjax.arThreads[TID].httpRequest.responseText;
151			
152			jsAjaxParser.mode = 'implode';
153			s = jsAjaxParser.process(s);
154			
155			if (!bRedirect)
156				oAjax._OnDataReady(TID, s);
157
158			oAjax.__prepareOnload();
159
160			if (jsAjaxParser.code.length > 0)
161				jsAjaxUtil.EvalPack(jsAjaxParser.code);
162			
163			oAjax.__runOnload();
164			//setTimeout(function() {alert(1); oAjax.__runOnload(); alert(2)}, 30);
165			oAjax._Close(TID);
166		}
167	}
168
169	this.arThreads[TID].httpRequest.onreadystatechange = __handlerReadyStateChange;
170	jsEvent.addEvent(document, "keypress", __cancelQuery);
171}
172
173CAjax.prototype.__prepareOnload = function()
174{
175	this.obTemporary = window.onload;
176	window.onload = null;
177}
178
179CAjax.prototype.__runOnload = function()
180{
181	if (window.onload) window.onload();
182	window.onload = this.obTemporary;
183	this.obTemporary = null;
184}
185
186CAjax.prototype.Send = function(TID, url, arData)
187{
188	if (!this.arThreads[TID]) return;
189
190	if (null != arData)
191		var data = this._PrepareData(arData);
192	else
193		var data = '';
194
195	if (data.length > 0) 
196	{
197		if (url.indexOf('?') == -1)
198			url += '?' + data;
199		else
200			url += '&' + data;	
201	}
202
203	if(this.arThreads[TID].httpRequest)
204	{
205		this.arThreads[TID].httpRequest.open("GET", url, true);
206		this._SetHandler(TID);
207		return this.arThreads[TID].httpRequest.send("");
208	}
209}
210
211CAjax.prototype.Post = function(TID, url, arData)
212{
213	var data = '';
214
215	if (null != arData)
216		data = this._PrepareData(arData);
217	if(this.arThreads[TID].httpRequest)
218	{
219		this.arThreads[TID].httpRequest.open("POST", url, true);
220		this._SetHandler(TID);
221		this.arThreads[TID].httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
222		return this.arThreads[TID].httpRequest.send(data);
223	}
224}
225
226/*
227public CAjaxForm - class to send forms via iframe
228*/
229function CAjaxForm(obForm, obHandler, bFirst)
230{
231	this.obForm = obForm;
232	this.obHandler = obHandler;
233	this.obFrame = null;
234
235	this.isFormProcessed = false;
236	
237	if (null == bFirst)
238		this.bFirst = false;
239	else
240		this.bFirst = bFirst;
241	
242	this.__tmpFormTarget = '';
243	this.obAJAXIndicator = null;
244	
245	this.currentBrowserDetected = "";
246	if (window.opera)
247		this.currentBrowserDetected = "Opera";
248	else if (navigator.userAgent)
249	{
250		if (navigator.userAgent.indexOf("MSIE") != -1)
251			this.currentBrowserDetected = "IE";
252		else if (navigator.userAgent.indexOf("Firefox") != -1)
253			this.currentBrowserDetected = "Firefox";
254	}
255
256	this.IsIE9 = !!document.documentMode && document.documentMode >= 9;
257}
258
259CAjaxForm.prototype.setProcessedFlag = function(value)
260{
261	if (null == value) value = true;
262	else value = value ? true : false;
263	
264	this.obForm.bxAjaxProcessed = value;
265	this.isFormProcessed = value;
266}
267
268CAjaxForm.isFormProcessed = function(obForm)
269{
270	if (obForm.bxAjaxProcessed)
271		return obForm.bxAjaxProcessed;
272	else
273		return false;
274}
275
276CAjaxForm.prototype.process = function()
277{
278	var _this = this;
279
280	function __formResultHandler()
281	{
282		if (!_this.obFrame.contentWindow.document || _this.obFrame.contentWindow.document.body.innerHTML.length == 0) return;
283
284		if (null != _this.obHandler)
285		{
286			_this.obHandler(_this.obFrame.contentWindow.document.body.innerHTML);
287		}
288
289		if (_this.obFrame.contentWindow.AJAX_runExternal)
290			_this.obFrame.contentWindow.AJAX_runExternal();
291
292		if (_this.obFrame.contentWindow.AJAX_runGlobal)
293			_this.obFrame.contentWindow.AJAX_runGlobal();
294
295		if (_this.bFirst)
296		{
297			try
298			{
299				_this.obForm.target = _this.__tmpFormTarget;
300				_this.obAJAXIndicator.parentNode.removeChild(_this.obAJAXIndicator);
301				_this.obForm.bxAjaxProcessed = false;
302			}
303			catch (e) 
304			{
305				_this.obForm = null;
306			}
307			
308			_this.obAJAXIndicator = null;
309
310			if (this.currentBrowserDetected != 'IE') 
311				jsEvent.removeAllEvents(_this.obFrame);
312
313			// fixing another strange bug. Now for FF
314			var TimerID = setTimeout("document.body.removeChild(document.getElementById('" + _this.obFrame.id + "'));", 100);
315			_this.obFrame = null;
316			
317			if (window.onFormLoaded)
318			{
319				window.onFormLoaded();
320				window.onFormLoaded = null;
321			}
322		}
323	}
324
325	if (this.obForm.target && this.obForm.target.substring(0, 5) == 'AJAX_')
326		return;
327
328	if (this.currentBrowserDetected == 'IE')
329	{
330		if (this.IsIE9)
331		{
332			this.obAJAXIndicator = document.createElement('input');
333			this.obAJAXIndicator.setAttribute('name', 'AJAX_CALL');
334			this.obAJAXIndicator.setAttribute('type', 'hidden');
335		} 
336		else
337		{
338			this.obAJAXIndicator = document.createElement('<input name="AJAX_CALL" type="hidden" />');
339		}
340	}
341	else
342	{
343		this.obAJAXIndicator = document.createElement('INPUT');
344		this.obAJAXIndicator.type = 'hidden';
345		this.obAJAXIndicator.name = 'AJAX_CALL';
346	}
347	
348	this.obAJAXIndicator.value = 'Y';
349	
350	this.obForm.appendChild(this.obAJAXIndicator);
351
352	var frameName = 'AJAX_' + Math.round(Math.random() * 100000);
353	
354	if (this.currentBrowserDetected == 'IE')
355		if (this.IsIE9)
356		{
357			this.obFrame = document.createElement('iframe');
358			this.obFrame.setAttribute('name', frameName);
359		}
360		else
361		{
362			this.obFrame = document.createElement('<iframe name="' + frameName + '"></iframe>');
363		}
364	else
365		this.obFrame = document.createElement('IFRAME');
366	
367	this.obFrame.style.display = 'none';
368	this.obFrame.src = 'javascript:\'\'';
369	this.obFrame.id = frameName;
370	this.obFrame.name = frameName;
371	
372	document.body.appendChild(this.obFrame);
373
374	this.__tmpFormTarget = this.obForm.target;
375	this.obForm.target = frameName;
376
377	// one more strange bug in IE..
378	if (this.currentBrowserDetected == 'IE') 
379		this.obFrame.attachEvent("onload", __formResultHandler);
380	else
381		jsEvent.addEvent(this.obFrame, 'load', __formResultHandler);
382	this.setProcessedFlag();
383}
384
385var jsAjaxParser = {
386	code: [],
387	mode: 'implode',
388	
389	regexp: null,
390	regexp_src: null,
391	
392	process: function(s)
393	{
394		this.code = [];
395		
396		if (null == this.regexp)
397			this.regexp = /(<script([^>]*)>)([\S\s]*?)(<\/script>)/i;
398
399		do
400		{
401			var arMatch = s.match(this.regexp);
402			
403			if (null == arMatch) 
404				break;
405
406			var pos = arMatch.index;
407			var len = arMatch[0].length;
408			
409			if (pos > 0)
410				this.code.push({TYPE: 'STRING', DATA: s.substring(0, pos)});
411			
412			if (typeof arMatch[1] == 'undefined' || arMatch[1].indexOf('src=') == -1)
413			{
414				var script = arMatch[3];
415				script = script.replace('<!--', '');
416
417				this.code.push({TYPE: 'SCRIPT', DATA: script});
418			}
419			else
420			{
421				if (null == this.regexp_src) 
422					this.regexp_src = /src="([^"]*)?"/i;
423				var arResult = this.regexp_src.exec(arMatch[1]);
424			
425				if (null != arResult && arResult[1])
426				{
427					this.code.push({TYPE: 'SCRIPT_EXT', DATA: arResult[1]});
428				}
429			}
430			
431			s = s.substring(pos + len);
432		} while (true);
433
434		if (s.length > 0)
435		{
436			this.code.push({TYPE: 'STRING', DATA: s});
437		}
438		
439		if (this.mode == 'implode')
440		{
441			s = '';
442			for (var i = 0, cnt = this.code.length; i < cnt; i++)
443			{
444				if (this.code[i].TYPE == 'STRING') 
445					s += this.code[i].DATA;
446			}
447			
448			return s;
449		}
450		else
451			return this.code;
452	}
453}
454
455/*
456public jsAjaxUtil - utility object
457*/
458var jsAjaxUtil = {
459	// remove all DOM node children (with events)
460	RemoveAllChild: function(pNode)
461	{
462		try
463		{
464			while(pNode.childNodes.length>0)
465			{
466				jsEvent.clearObject(pNode.childNodes[0]);
467				pNode.removeChild(pNode.childNodes[0]);
468			}
469		}
470		catch(e)
471		{}
472	},
473
474	// evaluate js string in window scope
475	EvalGlobal: function(script)
476	{
477		if (window.execScript)
478			window.execScript(script, 'javascript');
479		else if (jsAjaxUtil.IsSafari())
480			window.setTimeout(script, 0);
481		else
482			window.eval(script);
483	},
484	
485	arLoadedScripts: [],
486	
487	__isScriptLoaded: function (script_src)
488	{
489		for (var i=0; i<jsAjaxUtil.arLoadedScripts.length; i++)
490			if (jsAjaxUtil.arLoadedScripts[i] == script_src) return true;
491		return false;
492	},
493	
494	// evaluate external script
495	EvalExternal: function(script_src)
496	{
497		if (
498			/\/bitrix\/js\/main\/ajax.js$/i.test(script_src)
499			||
500			/\/bitrix\/js\/main\/core\/core.js$/i.test(script_src)
501		) return;
502	
503		if (jsAjaxUtil.__isScriptLoaded(script_src)) return;
504		jsAjaxUtil.arLoadedScripts.push(script_src);
505
506		var obAjaxThread = new CAjaxThread();
507
508		obAjaxThread.httpRequest.open("GET", script_src, false); // make *synchronous* request for script source
509		obAjaxThread.httpRequest.send("");
510		
511		var s = obAjaxThread.httpRequest.responseText;
512		obAjaxThread.Clear();
513		obAjaxThread = null;
514		
515		jsAjaxUtil.EvalGlobal(s); // evaluate script source
516	},
517	
518	EvalPack: function(code)
519	{
520		for (var i = 0, cnt = code.length; i < cnt; i++)
521		{
522			if (code[i].TYPE == 'SCRIPT_EXT' || code[i].TYPE == 'SCRIPT_SRC')
523				jsAjaxUtil.EvalExternal(code[i].DATA);
524			else if (code[i].TYPE == 'SCRIPT')
525				jsAjaxUtil.EvalGlobal(code[i].DATA);
526		}
527	},
528	
529	// urlencode js version
530	urlencode: function(s)
531	{
532		return escape(s).replace(new RegExp('\\+','g'), '%2B');
533	},
534	
535	// trim js version
536	trim: function(s)
537	{
538		var r, re;
539		re = /^[ \r\n]+/g;
540		r = s.replace(re, "");
541		re = /[ \r\n]+$/g;
542		r = r.replace(re, "");
543		return r;
544	},
545	
546	GetWindowSize: function()
547	{
548		var innerWidth, innerHeight;
549
550		if (self.innerHeight) // all except Explorer
551		{
552			innerWidth = self.innerWidth;
553			innerHeight = self.innerHeight;
554		}
555		else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
556		{
557			innerWidth = document.documentElement.clientWidth;
558			innerHeight = document.documentElement.clientHeight;
559		}
560		else if (document.body) // other Explorers
561		{
562			innerWidth = document.body.clientWidth;
563			innerHeight = document.body.clientHeight;
564		}
565
566		var scrollLeft, scrollTop;
567		if (self.pageYOffset) // all except Explorer
568		{
569			scrollLeft = self.pageXOffset;
570			scrollTop = self.pageYOffset;
571		}
572		else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
573		{
574			scrollLeft = document.documentElement.scrollLeft;
575			scrollTop = document.documentElement.scrollTop;
576		}
577		else if (document.body) // all other Explorers
578		{
579			scrollLeft = document.body.scrollLeft;
580			scrollTop = document.body.scrollTop;
581		}
582
583		var scrollWidth, scrollHeight;
584
585		if ( (document.compatMode && document.compatMode == "CSS1Compat"))
586		{
587			scrollWidth = document.documentElement.scrollWidth;
588			scrollHeight = document.documentElement.scrollHeight;
589		}
590		else
591		{
592			if (document.body.scrollHeight > document.body.offsetHeight)
593				scrollHeight = document.body.scrollHeight;
594			else
595				scrollHeight = document.body.offsetHeight;
596
597			if (document.body.scrollWidth > document.body.offsetWidth || 
598				(document.compatMode && document.compatMode == "BackCompat") ||
599				(document.documentElement && !document.documentElement.clientWidth)
600			)
601				scrollWidth = document.body.scrollWidth;
602			else
603				scrollWidth = document.body.offsetWidth;
604		}
605
606		return  {"innerWidth" : innerWidth, "innerHeight" : innerHeight, "scrollLeft" : scrollLeft, "scrollTop" : scrollTop, "scrollWidth" : scrollWidth, "scrollHeight" : scrollHeight};
607	},
608
609	// get element position relative to the whole window
610	GetRealPos: function(el)
611	{
612		if (el.getBoundingClientRect)
613		{
614			var obRect = el.getBoundingClientRect();
615			var obWndSize = jsAjaxUtil.GetWindowSize();
616			var arPos = {
617				left: obRect.left + obWndSize.scrollLeft, 
618				top: obRect.top + obWndSize.scrollTop, 
619				right: obRect.right + obWndSize.scrollLeft, 
620				bottom: obRect.bottom + obWndSize.scrollTop
621			};
622			return arPos;
623		}
624		
625		if(!el || !el.offsetParent)
626			return false;
627
628		var res = Array();
629		res["left"] = el.offsetLeft;
630		res["top"] = el.offsetTop;
631		var objParent = el.offsetParent;
632		
633		while(objParent && objParent.tagName != "BODY")
634		{
635			res["left"] += objParent.offsetLeft;
636			res["top"] += objParent.offsetTop;
637			objParent = objParent.offsetParent;
638		}
639		res["right"] = res["left"] + el.offsetWidth;
640		res["bottom"] = res["top"] + el.offsetHeight;
641		
642		return res;
643	},
644	
645	IsIE: function()
646	{
647		return (document.attachEvent && !jsAjaxUtil.IsOpera());
648	},
649
650	IsOpera: function()
651	{
652		return (navigator.userAgent.toLowerCase().indexOf('opera') != -1);
653	},
654	
655	IsSafari: function()
656	{
657		var userAgent = navigator.userAgent.toLowerCase();
658		return (/webkit/.test(userAgent));
659	},
660
661	// simple ajax data loading method (without any visual effects)
662	LoadData: function(url, obHandler)
663	{
664		if (!obHandler) return;
665
666		var TID = jsAjax.InitThread();
667		jsAjax.AddAction(TID, obHandler);
668		jsAjax.Send(TID, url);
669		
670		return TID;
671	},
672	
673	// simple ajax data post method (without any visual effects)
674	PostData: function(url, arData, obHandler)
675	{
676		if (!obHandler) return;
677
678		var TID = jsAjax.InitThread();
679		jsAjax.AddAction(TID, obHandler);
680		jsAjax.Post(TID, url, arData);
681		
682		return TID;
683	},
684	
685	__LoadDataToDiv: function(url, cont, bReplace, bShadow)
686	{
687		if (null == bReplace) bReplace = true;
688		if (null == bShadow) bShadow = true;
689		
690		if (typeof cont == 'string' || typeof cont == 'object' && cont.constructor == String)
691			var obContainerNode = document.getElementById(cont);
692		else
693			var obContainerNode = cont;
694		
695		if (!obContainerNode) return;
696
697		var rnd_tid = Math.round(Math.random() * 1000000);
698		
699		function __putToContainer(data)
700		{
701			if (!obContainerNode) return;
702			
703			//setTimeout('jsAjaxUtil.CloseLocalWaitWindow(\'' + rnd_tid + '\', \'' + obContainerNode.id + '\')', 100);
704			jsAjaxUtil.CloseLocalWaitWindow(rnd_tid, obContainerNode);
705
706			if (bReplace)
707			{
708				jsAjaxUtil.RemoveAllChild(obContainerNode);
709				obContainerNode.innerHTML = data;
710			}
711			else
712				obContainerNode.innerHTML += data;
713		}
714
715		jsAjaxUtil.ShowLocalWaitWindow(rnd_tid, obContainerNode, bShadow);
716		var TID = jsAjaxUtil.LoadData(url, __putToContainer);
717	},
718	
719	// insert ajax data to container (with visual effects)
720	InsertDataToNode: function(url, cont, bShadow)
721	{
722		if (null == bShadow) bShadow = true;
723		jsAjaxUtil.__LoadDataToDiv(url, cont, true, bShadow);
724	},
725
726	// append ajax data to container (with visual effects)
727	AppendDataToNode: function(url, cont, bShadow)
728	{
729		if (null == bShadow) bShadow = true;
730		jsAjaxUtil.__LoadDataToDiv(url, cont, false, bShadow);
731	},
732	
733	GetStyleValue: function(el, styleProp)
734	{
735		if(el.currentStyle)
736			var res = el.currentStyle[styleProp];
737		else if(window.getComputedStyle)
738			var res = document.defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
739		return res;
740	},
741	
742	// show ajax visuality
743	ShowLocalWaitWindow: function (TID, cont, bShadow)
744	{
745		if (typeof cont == 'string' || typeof cont == 'object' && cont.constructor == String)
746			var obContainerNode = document.getElementById(cont);
747		else
748			var obContainerNode = cont;
749		
750		if (obContainerNode.getBoundingClientRect)
751		{
752			var obRect = obContainerNode.getBoundingClientRect();
753			var obWndSize = jsAjaxUtil.GetWindowSize();
754
755			var arContainerPos = {
756				left: obRect.left + obWndSize.scrollLeft, 
757				top: obRect.top + obWndSize.scrollTop, 
758				right: obRect.right + obWndSize.scrollLeft, 
759				bottom: obRect.bottom + obWndSize.scrollTop
760			};
761		}
762		else
763			var arContainerPos = jsAjaxUtil.GetRealPos(obContainerNode);
764		
765		var container_id = obContainerNode.id;
766		
767		if (!arContainerPos) return;
768		
769		if (null == bShadow) bShadow = true;
770		
771		if (bShadow)
772		{
773			var obWaitShadow = document.body.appendChild(document.createElement('DIV'));
774			obWaitShadow.id = 'waitshadow_' + container_id + '_' + TID;
775			obWaitShadow.className = 'waitwindowlocalshadow';
776			obWaitShadow.style.top = (arContainerPos.top - 5) + 'px';
777			obWaitShadow.style.left = (arContainerPos.left - 5) + 'px';
778			obWaitShadow.style.height = (arContainerPos.bottom - arContainerPos.top + 10) + 'px';
779			obWaitShadow.style.width = (arContainerPos.right - arContainerPos.left + 10) + 'px';
780		}
781		
782		var obWaitMessage = document.body.appendChild(document.createElement('DIV'));
783		obWaitMessage.id = 'wait_' + container_id + '_' + TID;
784		obWaitMessage.className = 'waitwindowlocal';
785		
786		var div_top = arContainerPos.top + 5;
787		if (div_top < document.body.scrollTop) div_top = document.body.scrollTop + 5;
788		
789		obWaitMessage.style.top = div_top + 'px';
790		obWaitMessage.style.left = (arContainerPos.left + 5) + 'px';
791		
792		if(jsAjaxUtil.IsIE())
793		{
794			var frame = document.createElement("IFRAME");
795			frame.src = "javascript:''";
796			frame.id = 'waitframe_' + container_id + '_' + TID;
797			frame.className = "waitwindowlocal";
798			frame.style.width = obWaitMessage.offsetWidth + "px";
799			frame.style.height = obWaitMessage.offsetHeight + "px";
800			frame.style.left = obWaitMessage.style.left;
801			frame.style.top = obWaitMessage.style.top;
802			document.body.appendChild(frame);
803		}
804		
805		function __Close(e)
806		{
807			if (!e) e = window.event
808			if (!e) return;
809			if (e.keyCode == 27)
810			{
811				jsAjaxUtil.CloseLocalWaitWindow(TID, cont);
812				jsEvent.removeEvent(document, 'keypress', __Close);
813			}
814		}
815		
816		jsEvent.addEvent(document, 'keypress', __Close);
817	},
818
819	// hide ajax visuality
820	CloseLocalWaitWindow: function(TID, cont)
821	{
822		if (typeof cont == 'string' || typeof cont == 'object' && cont.constructor == String)
823			var obContainerNode = document.getElementById(cont);
824		else
825			var obContainerNode = cont;
826	
827		var container_id = obContainerNode.id;
828		
829		var obWaitShadow = document.getElementById('waitshadow_' + container_id + '_' + TID);
830		if (obWaitShadow)
831			document.body.removeChild(obWaitShadow);
832		var obWaitMessageFrame = document.getElementById('waitframe_' + container_id + '_' + TID);
833		if (obWaitMessageFrame)
834			document.body.removeChild(obWaitMessageFrame);
835		var obWaitMessage = document.getElementById('wait_' + container_id + '_' + TID);
836		if (obWaitMessage)
837			document.body.removeChild(obWaitMessage);
838	},
839
840	// simple form sending vithout visual effects. use onsubmit="SendForm(this, MyFunction)"
841	SendForm: function(obForm, obHandler)
842	{
843		if (typeof obForm == 'string' || typeof obForm == 'object' && obForm.constructor == String)
844			var obFormHandler = document.getElementById(obForm);
845		else
846			var obFormHandler = obForm;
847			
848		if (!obFormHandler.name || obFormHandler.name.length <= 0)
849		{
850			obFormHandler.name = 'AJAXFORM_' + Math.floor(Math.random() * 1000000);
851		}
852	
853		var obFormMigrate = new CAjaxForm(obFormHandler, obHandler, true);
854		obFormMigrate.process();
855
856		return true;
857	},
858	
859	// ajax form submit with visuality and put data to container. use onsubmit="InsertFormDataToNode(this, 'cont_id')"
860	InsertFormDataToNode: function(obForm, cont, bShadow)
861	{
862		if (null == bShadow) bShadow = true;
863		return jsAjaxUtil.__LoadFormToDiv(obForm, cont, true, bShadow);
864	},
865
866	// similiar with InsertFormDataToNode but append data to container
867	AppendFormDataToNode: function(obForm, cont, bShadow)
868	{
869		if (null == bShadow) bShadow = true;
870		return jsAjaxUtil.__LoadFormToDiv(obForm, cont, false, bShadow);
871	},
872	
873	__LoadFormToDiv: function(obForm, cont, bReplace, bShadow)
874	{
875		if (null == bReplace) bReplace = true;
876		if (null == bShadow) bShadow = true;
877		
878		if (typeof cont == 'string' || typeof cont == 'object' && cont.constructor == String)
879			var obContainerNode = document.getElementById(cont);
880		else
881			var obContainerNode = cont;
882		
883		if (!obContainerNode) return;
884
885		function __putToContainer(data)
886		{
887			if (!obContainerNode) return;
888			
889			if (bReplace)
890			{
891				jsAjaxUtil.RemoveAllChild(obContainerNode);
892				obContainerNode.innerHTML = data;
893			}
894			else
895				obContainerNode.innerHTML += data;
896				
897			jsAjaxUtil.CloseLocalWaitWindow(obContainerNode.id, obContainerNode);
898		}
899
900		jsAjaxUtil.ShowLocalWaitWindow(obContainerNode.id, obContainerNode, bShadow);
901		
902		return jsAjaxUtil.SendForm(obForm, __putToContainer);
903	},
904
905	// load to page new title, css files or script code strings
906	UpdatePageData: function (arData)
907	{
908		if (arData.TITLE) jsAjaxUtil.UpdatePageTitle(arData.TITLE);
909		if (arData.NAV_CHAIN) jsAjaxUtil.UpdatePageNavChain(arData.NAV_CHAIN);
910		if (arData.CSS && arData.CSS.length > 0) jsAjaxUtil.UpdatePageCSS(arData.CSS);
911		if (arData.SCRIPTS && arData.SCRIPTS.length > 0) jsAjaxUtil.UpdatePageScripts(arData.SCRIPTS);
912	},
913	
914	UpdatePageScripts: function(arScripts)
915	{
916		for (var i = 0; i < arScripts.length; i++)
917		{
918			jsAjaxUtil.EvalExternal(arScripts[i]);
919		}
920	},
921	
922	UpdatePageCSS: function (arCSS)
923	{
924		jsStyle.UnloadAll();
925		for (var i = 0; i < arCSS.length; i++)
926		{
927			jsStyle.Load(arCSS[i]);
928		}
929	},
930	
931	UpdatePageTitle: function(title)
932	{
933		var obTitle = document.getElementById('pagetitle');
934		if (obTitle) 
935		{
936			obTitle.removeChild(obTitle.firstChild);
937			if (!obTitle.firstChild)
938				obTitle.appendChild(document.createTextNode(title));
939			else
940				obTitle.insertBefore(document.createTextNode(title), obTitle.firstChild);
941		}
942		
943		document.title = title;
944	},
945	
946	UpdatePageNavChain: function(nav_chain)
947	{
948		var obNavChain = document.getElementById('navigation');
949		if (obNavChain)
950		{
951			obNavChain.innerHTML = nav_chain;
952		}
953	},
954	
955	ScrollToNode: function(node)
956	{
957		if (typeof node == 'string' || typeof node == 'object' && node.constructor == String)
958			var obNode = document.getElementById(node);
959		else
960			var obNode = node;
961		
962		if (obNode.scrollIntoView)
963			obNode.scrollIntoView(true);
964		else
965		{
966			var arNodePos = jsAjaxUtil.GetRealPos(obNode);
967			window.scrollTo(arNodePos.left, arNodePos.top);
968		}
969	}
970}
971
972/*
973public jsStyle - external CSS manager
974*/
975var jsStyle = {
976
977	arCSS: {},
978	bInited: false,
979	
980	Init: function()
981	{
982		var arStyles = document.getElementsByTagName('LINK');
983		if (arStyles.length > 0)
984		{
985			for (var i = 0; i<arStyles.length; i++)
986			{
987				if (arStyles[i].href)
988				{
989					var filename = arStyles[i].href;
990					var pos = filename.indexOf('://');
991					if (pos != -1)
992						filename = filename.substr(filename.indexOf('/', pos + 3));
993					
994					arStyles[i].bxajaxflag = false;
995					this.arCSS[filename] = arStyles[i];
996				}
997			}
998		}
999		
1000		this.bInited = true;
1001	},
1002	
1003	Load: function(filename)
1004	{
1005		if (!this.bInited) 
1006			this.Init();
1007	
1008		if (null != this.arCSS[filename])
1009		{
1010			this.arCSS[filename].disabled = false;
1011			return;
1012		}
1013
1014		/*
1015		var cssNode = document.createElement('link');
1016		cssNode.type = 'text/css';
1017		cssNode.rel = 'stylesheet';
1018		cssNode.href = filename;
1019		document.getElementsByTagName("head")[0].appendChild(cssNode);
1020		*/
1021		
1022		var link = document.createElement("STYLE");
1023		link.type = 'text/css';
1024
1025		var head = document.getElementsByTagName("HEAD")[0];
1026		head.insertBefore(link, head.firstChild);
1027		//head.appendChild(link);
1028		
1029		if (jsAjaxUtil.IsIE())
1030		{
1031			link.styleSheet.addImport(filename);
1032		}
1033		else
1034		{
1035			var obAjaxThread = new CAjaxThread();
1036			obAjaxThread.httpRequest.onreadystatechange = null;
1037
1038			obAjaxThread.httpRequest.open("GET", filename, false); // make *synchronous* request for css source
1039			obAjaxThread.httpRequest.send("");
1040			
1041			var s = obAjaxThread.httpRequest.responseText;
1042			
1043			// convert relative resourse paths in css to absolute. current path to css will be lost.
1044			var pos = filename.lastIndexOf('/');
1045			if (pos != -1)
1046			{
1047				var dirname = filename.substring(0, pos);
1048				s = s.replace(/url\(([^\/\\].*?)\)/gi, 'url(' + dirname + '/$1)');
1049			}
1050			
1051			obAjaxThread.Clear();
1052			obAjaxThread = null;
1053
1054			link.appendChild(document.createTextNode(s));
1055		}
1056			
1057	},
1058	
1059	Unload: function(filename)
1060	{
1061		if (!this.bInited) this.Init();
1062	
1063		if (null != this.arCSS[filename])
1064		{
1065			this.arCSS[filename].disabled = true;
1066		}
1067	},
1068	
1069	UnloadAll: function()
1070	{
1071		if (!this.bInited) this.Init();	
1072		else
1073			for (var i in this.arCSS)
1074			{
1075				if (this.arCSS[i].bxajaxflag)
1076					this.Unload(i);
1077			}
1078	}
1079}
1080
1081/*
1082public jsEvent - cross-browser event manager object
1083*/
1084var jsEvent = {
1085	
1086	objectList: [null],
1087	objectEventList: [null],
1088
1089	__eventManager: function(e)
1090	{
1091		if (!e) e = window.event
1092		var result = true;
1093	
1094		// browser comptiability
1095		try
1096		{
1097			if (e.srcElement)
1098				e.currentTarget = e.srcElement;
1099		}
1100		catch (e) {}
1101		
1102		if (this.bxEventIndex && jsEvent.objectEventList[this.bxEventIndex] && jsEvent.objectEventList[this.bxEventIndex][e.type])
1103		{
1104			var len = jsEvent.objectEventList[this.bxEventIndex][e.type].length;
1105			for (var i=0; i<len; i++)
1106			{
1107				if (jsEvent.objectEventList[this.bxEventIndex][e.type] && jsEvent.objectEventList[this.bxEventIndex][e.type][i])
1108				{
1109					var tmp_result = jsEvent.objectEventList[this.bxEventIndex][e.type][i](e);
1110					if ('boolean' == typeof tmp_result) result = result && tmp_result;
1111					if (!result) return false;
1112				}
1113			}
1114		}
1115
1116		return true;
1117	},
1118	
1119	addEvent: function(obElement, event, obHandler)
1120	{
1121		if (!obElement.bxEventIndex)
1122		{
1123			obElement.bxEventIndex = jsEvent.objectList.length;
1124			jsEvent.objectList[obElement.bxEventIndex] = obElement;
1125		}
1126		
1127		if (!jsEvent.objectEventList[obElement.bxEventIndex])
1128			jsEvent.objectEventList[obElement.bxEventIndex] = {};
1129
1130		if (!jsEvent.objectEventList[obElement.bxEventIndex][event])
1131		{
1132			jsEvent.objectEventList[obElement.bxEventIndex][event] = [];
1133			
1134			if (obElement['on' + event]) 
1135				jsEvent.objectEventList[obElement.bxEventIndex][event].push(obElement['on' + event]);
1136			
1137			obElement['on' + event] = null;
1138			obElement['on' + event] = jsEvent.__eventManager;
1139		}
1140		
1141		jsEvent.objectEventList[obElement.bxEventIndex][event].push(obHandler);
1142	},
1143	
1144	removeEvent: function(obElement, event, obHandler)
1145	{
1146		if (obElement.bxEventIndex)
1147		{
1148			if (jsEvent.objectEventList[obElement.bxEventIndex][event])
1149			{
1150				for (var i=0; i<jsEvent.objectEventList[obElement.bxEventIndex][event].length; i++)
1151				{
1152					if (obHandler == jsEvent.objectEventList[obElement.bxEventIndex][event][i])
1153					{
1154						delete jsEvent.objectEventList[obElement.bxEventIndex][event][i];
1155						return;
1156					}
1157				}
1158			}
1159		}
1160	},
1161	
1162	removeAllHandlers: function(obElement, event)
1163	{
1164		if (obElement.bxEventIndex)
1165		{
1166			if (jsEvent.objectEventList[obElement.bxEventIndex][event])
1167			{
1168				// possible memory leak. must be checked;
1169				jsEvent.objectEventList[obElement.bxEventIndex][event] = [];
1170			}
1171		}
1172	},
1173
1174	removeAllEvents: function(obElement)
1175	{
1176		if (obElement.bxEventIndex)
1177		{
1178			if (jsEvent.objectEventList[obElement.bxEventIndex])
1179			{
1180				// possible memory leak. must be checked;
1181				jsEvent.objectEventList[obElement.bxEventIndex] = [];
1182			}
1183		}
1184	},
1185	
1186	clearObject: function(obElement)
1187	{
1188		if (obElement.bxEventIndex)
1189		{
1190			if (jsEvent.objectEventList[obElement.bxEventIndex])
1191			{
1192				// possible memory leak. must be checked;
1193				delete jsEvent.objectEventList[obElement.bxEventIndex];
1194			}
1195			
1196			if (jsEvent.objectList[obElement.bxEventIndex])
1197			{
1198				// possible memory leak. must be checked;
1199				delete jsEvent.objectList[obElement.bxEventIndex];
1200			}
1201			
1202			delete obElement.bxEventIndex;
1203		}
1204	}
1205}
1206
1207var jsAjaxHistory = {
1208	expected_hash: '',
1209	counter: 0,
1210	bInited: false,
1211	
1212	obFrame: null,
1213	obImage: null,
1214	bHashCollision: false,
1215	
1216	obTimer: null,
1217	
1218	__hide_object: function(ob)
1219	{
1220		ob.style.position = 'absolute';
1221		ob.style.top = '-1000px';
1222		ob.style.left = '-1000px';
1223		ob.style.height = '10px';
1224		ob.style.width = '10px';
1225	},
1226	
1227	init: function(node)
1228	{
1229		if (jsAjaxHistory.bInited) return;
1230		
1231		jsAjaxHistory.expected_hash = window.location.hash;
1232
1233		if (!jsAjaxHistory.expected_hash || jsAjaxHistory.expected_hash == '#') jsAjaxHistory.expected_hash = '__bx_no_hash__';
1234		
1235		var obCurrentState = {'node': node, 'title':window.document.title, 'data': document.getElementById(node).innerHTML};
1236		var obNavChain = document.getElementById('navigation');
1237		if (null != obNavChain)
1238			obCurrentState.nav_chain = obNavChain.innerHTML;
1239		
1240		jsAjaxHistoryContainer.put(jsAjaxHistory.expected_hash, obCurrentState);
1241
1242		jsAjaxHistory.obTimer = setTimeout(jsAjaxHistory.__hashListener, 500);
1243		
1244		if (jsAjaxUtil.IsIE())
1245		{
1246			jsAjaxHistory.obFrame = document.createElement('IFRAME');
1247			jsAjaxHistory.__hide_object(jsAjaxHistory.obFrame);
1248			
1249			document.body.appendChild(jsAjaxHistory.obFrame);
1250			
1251			jsAjaxHistory.obFrame.contentWindow.document.open();
1252			jsAjaxHistory.obFrame.contentWindow.document.write(jsAjaxHistory.expected_hash);
1253			jsAjaxHistory.obFrame.contentWindow.document.close();
1254			jsAjaxHistory.obFrame.contentWindow.document.title = window.document.title;
1255		}
1256		else if (jsAjaxUtil.IsOpera())
1257		{
1258			jsAjaxHistory.obImage = document.createElement('IMG');
1259			jsAjaxHistory.__hide_object(jsAjaxHistory.obImage);
1260			
1261			document.body.appendChild(jsAjaxHistory.obImage);
1262			
1263			jsAjaxHistory.obImage.setAttribute('src', 'javascript:location.href = \'javascript:jsAjaxHistory.__hashListener();\';');
1264		}
1265		
1266		jsAjaxHistory.bInited = true;
1267	},
1268
1269	__hashListener: function()
1270	{
1271		if (jsAjaxHistory.obTimer)
1272		{
1273			window.clearTimeout(jsAjaxHistory.obTimer);
1274			jsAjaxHistory.obTimer = null;
1275		}
1276	
1277		if (null != jsAjaxHistory.obFrame)
1278			var current_hash = jsAjaxHistory.obFrame.contentWindow.document.body.innerText;
1279		else
1280			var current_hash = window.location.hash;
1281
1282		if (!current_hash || current_hash == '#') current_hash = '__bx_no_hash__';
1283		
1284		if (current_hash.indexOf('#') == 0) current_hash = current_hash.substring(1);
1285		
1286		if (current_hash != jsAjaxHistory.expected_hash)
1287		{
1288			var state = jsAjaxHistoryContainer.get(current_hash);
1289			if (state)
1290			{
1291				document.getElementById(state.node).innerHTML = state.data;
1292				jsAjaxUtil.UpdatePageTitle(state.title);
1293				if (state.nav_chain) 
1294					jsAjaxUtil.UpdatePageNavChain(state.nav_chain);
1295				
1296				jsAjaxHistory.expected_hash = current_hash;
1297				if (null != jsAjaxHistory.obFrame)
1298				{
1299					var __hash = current_hash == '__bx_no_hash__' ? '' : current_hash;
1300					if (window.location.hash != __hash && window.location.hash != '#' + __hash)
1301						window.location.hash = __hash;
1302				}
1303			}
1304		}
1305		
1306		jsAjaxHistory.obTimer = setTimeout(jsAjaxHistory.__hashListener, 500);
1307	},
1308
1309	put: function(node, new_hash)
1310	{
1311		//alert(new_hash);
1312		var state = {
1313			'node': node,
1314			'title': window.document.title,
1315			'data': document.getElementById(node).innerHTML
1316		};
1317		
1318		var obNavChain = document.getElementById('navigation');
1319		if (obNavChain)
1320			state.nav_chain = obNavChain.innerHTML;
1321		
1322		//var new_hash = '#cnt' + (++jsAjaxHistory.counter);
1323		jsAjaxHistoryContainer.put(new_hash, state);
1324		jsAjaxHistory.expected_hash = new_hash;
1325
1326		window.location.hash = jsAjaxUtil.urlencode(new_hash);
1327
1328		if (null != jsAjaxHistory.obFrame)
1329		{
1330			jsAjaxHistory.obFrame.contentWindow.document.open();
1331			jsAjaxHistory.obFrame.contentWindow.document.write(new_hash);
1332			jsAjaxHistory.obFrame.contentWindow.document.close();
1333			jsAjaxHistory.obFrame.contentWindow.document.title = state.title;
1334		}
1335	},
1336
1337	checkRedirectStart: function(param_name, param_value)
1338	{
1339		var current_hash = window.location.hash;
1340		if (current_hash.substring(0, 1) == '#') current_hash = current_hash.substring(1);
1341		
1342		if (current_hash.substring(0, 5) == 'view/')
1343		{
1344			jsAjaxHistory.bHashCollision = true;
1345			document.write('<' + 'div id="__ajax_hash_collision_' + param_value + '" style="display: none;">');
1346		}
1347	},
1348	
1349	checkRedirectFinish: function(param_name, param_value)
1350	{
1351		document.write('</div>');
1352		
1353		var current_hash = window.location.hash;
1354		if (current_hash.substring(0, 1) == '#') current_hash = current_hash.substring(1);
1355		
1356		jsEvent.addEvent(window, 'load', function () 
1357		{
1358			//alert(current_hash);
1359			if (current_hash.substring(0, 5) == 'view/')
1360			{
1361				var obColNode = document.getElementById('__ajax_hash_collision_' + param_value);
1362				var obNode = obColNode.firstChild;
1363				jsAjaxUtil.RemoveAllChild(obNode);
1364				obColNode.style.display = 'block';
1365				
1366				// IE, Opera and Chrome automatically modifies hash with urlencode, but FF doesn't ;-(
1367				if (!jsAjaxUtil.IsIE() && !jsAjaxUtil.IsOpera() && !jsAjaxUtil.IsSafari())
1368					current_hash = jsAjaxHistory.urlencode(current_hash);
1369				
1370				current_hash += (current_hash.indexOf('%3F') == -1 ? '%3F' : '%26') + param_name + '=' + param_value;
1371				
1372				var url = '/bitrix/tools/ajax_redirector.php?hash=' + current_hash; //jsAjaxHistory.urlencode(current_hash);
1373				jsAjaxUtil.InsertDataToNode(url, obNode, false);
1374			}
1375		});
1376	},
1377	
1378	urlencode: function(s)
1379	{
1380		if (window.encodeURIComponent)
1381			return encodeURIComponent(s);
1382		else if (window.encodeURI)
1383			return encodeURI(s);
1384		else
1385			return jsAjaxUtil.urlencode(s);
1386	}
1387}
1388
1389var jsAjaxHistoryContainer = {
1390	arHistory: {},
1391	
1392	put: function(hash, state)
1393	{
1394		this.arHistory[hash] = state;
1395	},
1396	
1397	get: function(hash)
1398	{
1399		return this.arHistory[hash];
1400	}
1401}
1402
1403// for compatibility with IE 5.0 browser
1404if (![].pop)
1405{
1406	Array.prototype.pop = function()
1407	{
1408		if (this.length <= 0) return false;
1409		var element = this[this.length-1];
1410		delete this[this.length-1];
1411		this.length--;
1412		return element;
1413	}
1414	
1415	Array.prototype.shift = function()
1416	{
1417		if (this.length <= 0) return false;
1418		var tmp = this.reverse();
1419		var element = tmp.pop();
1420		this.prototype = tmp.reverse();
1421		return element;
1422	}
1423	
1424	Array.prototype.push = function(element)
1425	{
1426		this[this.length] = element;
1427	}
1428}
1429
1430var jsAjax = new CAjax();
1431

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.