PageSourceSearch

https://www.zauglom.ru/published/SC/html/scripts/js/functions.js

js zauglom.ru collected 2026-10-04 21:00:19 UTC 16,555 bytes, 727 lines download raw bytes

1function getElementComputedStyle(elem, prop) {
2	if (typeof elem != "object") {
3		elem = document.getElementById(elem);
4	}
5
6	// external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
7	if (document.defaultView && document.defaultView.getComputedStyle) {
8		if (prop.match(/[A-Z]/)) {
9			prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
10		}
11		return document.defaultView.getComputedStyle(elem, "")
12				.getPropertyValue(prop);
13	}
14
15	// external stylesheet for Explorer and Opera 9
16	if (elem.currentStyle) {
17		var i;
18		while ((i = prop.indexOf("-")) != -1) {
19			prop = prop.substr(0, i) + prop.substr(i + 1, 1).toUpperCase()
20					+ prop.substr(i + 2);
21		}
22		return elem.currentStyle[prop];
23	}
24
25	return "";
26}
27
28function getWindowSize(wnd) {
29
30	var windowWidth, windowHeight;
31
32	if (wnd.innerHeight) { // all except Explorer
33		if (wnd.document.documentElement.clientWidth) {
34			windowWidth = wnd.document.documentElement.clientWidth;
35		} else {
36			wnd.windowWidth = wnd.innerWidth;
37		}
38		windowHeight = wnd.innerHeight;
39	} else if (wnd.document.documentElement
40			&& wnd.document.documentElement.clientHeight) { // Explorer 6 Strict
41		// Mode
42		windowWidth = wnd.document.documentElement.clientWidth;
43		windowHeight = wnd.document.documentElement.clientHeight;
44	} else if (wnd.document.body) { // other Explorers
45		windowWidth = wnd.document.body.clientWidth;
46		windowHeight = wnd.document.body.clientHeight;
47	}
48
49	return [windowWidth, windowHeight];
50}
51
52function number_format(a, b, c, d) {
53	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
54	e = a + '';
55	f = e.split('.');
56	if (!f[0]) {
57		f[0] = '0';
58	}
59	if (!f[1]) {
60		f[1] = '';
61	}
62	if (f[1].length < b) {
63		g = f[1];
64		for (i = f[1].length + 1; i <= b; i++) {
65			g += '0';
66		}
67		f[1] = g;
68	}
69	if (d != '' && f[0].length > 3) {
70		h = f[0];
71		f[0] = '';
72		for (j = 3; j < h.length; j += 3) {
73			i = h.slice(h.length - j, h.length - j + 3);
74			f[0] = d + i + f[0] + '';
75		}
76		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
77		f[0] = j + f[0];
78	}
79	c = (b <= 0) ? '' : c;
80	return f[0] + c + f[1];
81}
82
83function getLayer(layerName, pwindow) {
84	if (!pwindow) {
85		pwindow = window;
86	}
87
88	if (pwindow.document.getElementById) {
89		return pwindow.document.getElementById(layerName);
90	}
91	if (pwindow.document.all)
92		return pwindow.document.all[layerName];
93	if (pwindow.document.layers)
94		return pwindow.document.layers[layerName];
95	return null;
96}
97
98function changeState(id_name, state) {
99
100	var layer = getLayer(id_name);
101	if (is_null(layer))
102		return;
103
104	if (is_null(state) ? layer.style.display != 'block' : state) {
105		layer.style.display = 'block';
106	} else {
107		layer.style.display = 'none';
108	}
109}
110
111function is_null(obj) {
112
113	if (typeof(obj) == 'undefined')
114		return true;
115	if (obj == null)
116		return true;
117	return false;
118}
119
120function getAbsolutePos(el) {
121	var SL = 0, ST = 0;
122	var is_div = /^div$/i.test(el.tagName);
123	if (is_div && el.scrollLeft)
124		SL = el.scrollLeft;
125	if (is_div && el.scrollTop)
126		ST = el.scrollTop;
127	var r = {
128		x : el.offsetLeft - SL,
129		y : el.offsetTop - ST
130	};
131	if (el.offsetParent) {
132		var tmp = this.getAbsolutePos(el.offsetParent);
133		r.x += tmp.x;
134		r.y += tmp.y;
135	}
136	return r;
137}
138
139function getElementsByClass(searchClass, node, tag) {
140
141	var classElements = new Array();
142	if (node == null)
143		node = document;
144	if (tag == null)
145		tag = '*';
146	var els = node.getElementsByTagName(tag);
147	var elsLen = els.length;
148
149	var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
150	for (var i = 0, j = 0; i < elsLen; i++) {
151		if (pattern.test(els[i].className)) {
152			classElements[j] = els[i];
153			j++;
154		}
155	}
156
157	return classElements;
158}
159
160function getElementByClass(searchClass, node, tag) {
161
162	var elems = getElementsByClass(searchClass, node, tag);
163	if (!elems.length)
164		return null;
165
166	return elems[0];
167}
168
169function createTag(tag, pel, wnd) {
170
171	if (!wnd)
172		wnd = window;
173	if (!pel)
174		pel = wnd.document.body;
175
176	el = wnd.document.createElement(tag);
177	pel.appendChild(el);
178	return el;
179}
180
181function deleteTag(element, parent) {
182
183	if (!parent)
184		parent = element.parentNode;
185
186	parent.removeChild(element);
187}
188
189function open_window(link, w, h) {
190
191	var win = "width=" + w + ",height=" + h
192			+ ",menubar=no,location=no,resizable=yes,scrollbars=yes";
193	var newWin = window.open(link, 'newWin', win);
194	if (newWin) {
195		newWin.focus();
196	}
197	return newWin;
198}
199
200function select_getCurrValue(selectEntry) {
201
202	for (var i = 0; i < selectEntry.options.length; i++) {
203
204		if (selectEntry.options[i].selected) {
205			return selectEntry.options[i].value;
206		}
207	}
208
209	return null;
210}
211
212function select_getCurrOption(selectEntry) {
213
214	for (var i = 0; i < selectEntry.options.length; i++) {
215
216		if (selectEntry.options[i].selected) {
217			return selectEntry.options[i];
218		}
219	}
220
221	return null;
222}
223
224function select_selectOptionByValue(selectEntry, value) {
225
226	for (var i = 0; i < selectEntry.options.length; i++) {
227
228		selectEntry.options[i].selected = (value == selectEntry.options[i].value);
229	}
230}
231
232function select_getOptionByValue(selectEntry, value) {
233
234	for (var i = 0; i < selectEntry.options.length; i++) {
235
236		if (selectEntry.options[i].value == value)
237			return selectEntry.options[i];
238	}
239	return null;
240}
241
242function findSelectedIndex(ob) {
243
244	for (i = 0; i < ob.length; i++) {
245		if (ob[i].selected)
246			return i;
247	}
248	return -1;
249}
250
251function select_addOption(oListbox, text, value, isDefaultSelected, isSelected) {
252	var oOption = document.createElement("option");
253	oOption.appendChild(document.createTextNode(text));
254	oOption.setAttribute("value", value);
255
256	if (isDefaultSelected)
257		oOption.defaultSelected = true;
258	else if (isSelected)
259		oOption.selected = true;
260
261	oListbox.appendChild(oOption);
262}
263
264function confirmDelete(id, ask, url) { // confirm order delete
265
266	if (window.confirm(ask)) { // delete
267		window.location = url + id;
268	}
269}
270
271function formatPrice(price) {
272
273	return defaultCurrency.getView(price);
274}
275
276function allowInsertAtCarret(field) {
277
278	return document.selection
279			|| (field.selectionStart || field.selectionStart == '0') || false;
280}
281
282function insertAtCarret(field, value) {
283
284	// IE support
285	if (document.selection) {
286		field.focus();
287		sel = document.selection.createRange();
288		sel.text = value;
289		// MOZILLA/NETSCAPE support
290	} else if (field.selectionStart || field.selectionStart == '0') {
291		var startPos = field.selectionStart;
292		var endPos = field.selectionEnd;
293		var scrollTop = field.scrollTop;
294		field.value = field.value.substring(0, startPos) + value
295				+ field.value.substring(endPos, field.value.length);
296
297		field.focus();
298		var cPos = startPos + (value.length);
299		field.selectionStart = cPos;
300		field.selectionEnd = cPos;
301		field.scrollTop = scrollTop;
302	} else {
303		field.value += "\n" + value;
304	}
305	// reposition cursor if possible
306	if (field.createTextRange) {
307		field.caretPos = document.selection.createRange().duplicate();
308	}
309}
310
311FadeSteps = ["ff", "ee", "dd", "cc", "bb", "aa", "99"];
312FadeTimeout = 600;
313
314function fadeBlock(targetId) {
315
316	DoFade(FadeSteps.length - 1, targetId);
317}
318
319function DoFade(colorId, targetId) {
320
321	if (colorId >= 0 && document.getElementById(targetId)) {
322		document.getElementById(targetId).style.backgroundColor = "#ffff"
323				+ FadeSteps[colorId];
324
325		colorId--;
326
327		// Wait a little bit and fade another shade
328		setTimeout("DoFade(" + colorId + ",'" + targetId + "')", FadeTimeout);
329	} else if (document.getElementById(targetId).getAttribute('obj_wnd')) {
330		document.getElementById(targetId).getAttribute('obj_wnd').close();
331	}
332}
333
334function __alert(message) {
335	var _msg = new Message();
336	_msg.__type = MSGTYPE_SUCCESS;
337	_msg.__message = message;
338	_msg.showMessage();
339}
340
341var MSGTYPE_SUCCESS = 1;
342var MSGTYPE_ERROR = 2;
343
344var Message = function() {
345
346	this.__type = null;
347	this.__code = null;
348	this.__message = null;
349	this.__params = null;
350
351	this.init = function(data) {
352
353		if (data.type)
354			this.__type = data.type;
355		if (data.code)
356			this.__code = data.code;
357		if (data.message)
358			this.__message = data.message;
359		if (data.params)
360			this.__params = data.params;
361	};
362
363	this.isError = function() {
364
365		return this.__type == MSGTYPE_ERROR;
366	};
367
368	this.isSuccess = function() {
369
370		return this.__type == MSGTYPE_SUCCESS;
371	};
372
373	this.getMessage = function() {
374
375		return this.__message;
376	};
377
378	this.getParams = function() {
379
380		return this.__params;
381	};
382
383	this.showMessage = function() {
384
385		var msgWnd = new wnd();
386		msgWnd.move(100, 100);
387		msgWnd.setWidth(400);
388		var messageBlock = msgWnd.getContentObj();
389		messageBlock.className = this.isSuccess()
390				? "success_block"
391				: "error_block";
392		messageBlock.innerHTML = this.getMessage();
393		messageBlock.id = 'wnd-msg-block';
394		messageBlock.style.position = 'fixed';
395		w_size = getWindowSize(window);
396		w1_size = msgWnd.getSize();
397		msgWnd.move((w_size[0] - w1_size[0]) / 2, (w_size[1] - w1_size[1]) / 4);
398		msgWnd.show();
399		msgWnd.fade();
400	};
401};
402
403var wnd = function() {
404
405	if (getLayer('wnd-init')) {
406		this.__objDiv = getLayer('wnd-init');
407		this.__objDiv.parentNode.removeChild(this.__objDiv);
408	}
409	this.__objDiv = createTag('div');
410	this.__objDiv.id = 'wnd-init';
411	this.__objDiv.className = 'wnd_init';
412	this.__objDiv.setAttribute('obj_wnd', this);
413	/*
414	 * var objCloseDiv = createTag('div', this.__objDiv);
415	 * objCloseDiv.style.textAlign = 'right'; objCloseButton =
416	 * createTag('img',objCloseDiv); objCloseButton.src =
417	 * window.url_img+'/w_close.gif'; objCloseButton.alt = translate.btn_close;
418	 */
419	var objWnd = this;
420	/*
421	 * objCloseButton.onclick = function (){
422	 * 
423	 * objWnd.close(); }
424	 */
425	this.__objContent = createTag('div', this.__objDiv);
426
427	this.fade = function() {
428
429		setTimeout("getLayer('" + this.__objDiv.id
430						+ "').style.display = 'none'", 5000);
431	};
432
433	this.getSize = function() {
434		return [this.__objDiv.offsetWidth, this.__objDiv.offsetHeight];
435	};
436
437	this.getContentObj = function() {
438		return this.__objContent;
439	};
440
441	this.setWidth = function(w) {
442		this.__objDiv.style.width = w + 'px';
443	};
444
445	this.setHeight = function(h) {
446		this.__objDiv.style.height = h + 'px';
447	};
448
449	this.show = function() {
450		this.__objDiv.style.visibility = 'visible';
451	};
452
453	this.hide = function() {
454		this.__objDiv.style.visibility = 'hidden';
455	};
456
457	this.close = function() {
458		this.hide();
459		this.__objDiv.parentNode.removeChild(this.__objDiv);
460	};
461
462	this.move = function(x, y) {
463		this.__objDiv.style.left = x + "px";
464		this.__objDiv.style.top = y + "px";
465	};
466};
467
468function getFormByElem(elem) {
469
470	var max = 50;
471	var p = elem.parentNode;
472	while (p && p.tagName && !(/^form$/i.test(p.tagName)) && 0 < max--) {
473		p = p.parentNode;
474	}
475
476	if (p && p.tagName && /^form$/i.test(p.tagName))
477		return p;
478
479	return null;
480}
481
482function getCookie(name) {
483	var start = document.cookie.indexOf(name + '=');
484	var len = start + name.length + 1;
485	if ((!start) && (name != document.cookie.substring(0, name.length))) {
486		return null;
487	}
488	if (start == -1)
489		return null;
490	var end = document.cookie.indexOf(';', len);
491	if (end == -1)
492		end = document.cookie.length;
493	return unescape(document.cookie.substring(len, end));
494}
495
496function setCookie(name, value, expires, path, domain, secure) {
497	var today = new Date();
498	today.setTime(today.getTime());
499	if (expires) {
500		expires = expires * 1000 * 60 * 60 * 24;
501	}
502	var expires_date = new Date(today.getTime() + (expires));
503	document.cookie = name + '='
504			+ escape(value)
505			+ ((expires) ? ';expires=' + expires_date.toGMTString() : '')
506			+
507			// expires.toGMTString()
508			((path) ? ';path=' + path : '')
509			+ ((domain) ? ';domain=' + domain : '')
510			+ ((secure) ? ';secure' : '');
511}
512
513function deleteCookie(name, path, domain) {
514	if (getCookie(name))
515		document.cookie = name + '=' + ((path) ? ';path=' + path : '')
516				+ ((domain) ? ';domain=' + domain : '')
517				+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
518}
519
520function catchResult(e) {
521	alert(e);
522}
523
524function openFadeIFrame(url, caption) {
525
526	sswgt_CartManager.shop_url = (window.WAROOT_URL != null)
527			? window.WAROOT_URL
528			: ORIG_URL;
529	sizes = getPageSize();
530	sswgt_CartManager.show(url, sizes[0] * 0.7, sizes[1] * 0.7);
531}
532
533function resizeFadeIFrame(width, height) {
534	sswgt_CartManager.resizeFrame(width, height);
535}
536
537function closeFadeIFrame() {
538	sswgt_CartManager.hide();
539}
540
541function split_query(query) {
542
543	var gets = query.split(/\&/);
544	var q_get = {};
545	var t = null;
546	for (var i = gets.length - 1; i >= 0; i--) {
547
548		t = gets[i].split(/\=/);
549		if (t[0] != null) {
550			q_get[t[0]] = t[1] ? t[1] : '';
551		}
552	}
553	return q_get;
554}
555
556function set_query(query, url) {
557
558	if (!url)
559		url = document.location.href;
560
561	var reg = /([^\?]*)\?([^\#]*)(|\#.*)$/;
562	var results = url.match(reg);
563
564	var path_part = results && results[1] ? results[1] : '';
565	var get_part = results && results[2] ? results[2] : '';
566	var anchor_part = results && results[3] ? results[3] : '';
567
568	var mode = query.search(/^\?/) == -1 ? 'update' : 'new';
569
570	query = query.replace(/^\?|^\&/, '');
571
572	var q_get = split_query(query);
573	var u_get = split_query(get_part);
574	var new_query = '';
575	if (mode == 'update') {// update
576
577		for (var k in q_get) {
578
579			u_get[k] = q_get[k] ? q_get[k] : null;
580		}
581	} else { // new query
582
583		for (var k in q_get) {
584
585			if (!q_get[k])
586				q_get[k] = u_get[k] ? u_get[k] : null;
587		}
588		u_get = q_get;
589	}
590
591	for (var k in u_get) {
592		if (k && (u_get[k] != null))
593			new_query += '&' + k + '=' + u_get[k];
594	}
595	return '?' + new_query.replace(/^\&/, '') + anchor_part;
596}
597
598var AjaxCptHndls = {
599
600	__handlers : {},
601
602	register : function(event_name, cpt_id, handler) {
603
604		if (is_null(this.__handlers[cpt_id]))
605			this.__handlers[cpt_id] = {};
606
607		this.__handlers[cpt_id][event_name] = handler;
608	},
609
610	call : function(event_name, cpt_id, data) {
611
612		if (is_null(this.__handlers[cpt_id][event_name]))
613			return;
614
615		return this.__handlers[cpt_id][event_name](data);
616	}
617};
618
619function getEventObject(ev) {
620
621	var my_ev = {};
622	ev = ev ? ev : window.event;
623	if (ev.srcElement) {
624		my_ev.target = ev.srcElement;
625	} else {
626		my_ev.target = ev.target;
627	}
628
629	my_ev.ev = ev;
630	return my_ev;
631}
632
633function getPageSize() {
634
635	var xScroll, yScroll;
636
637	if (window.innerHeight && window.scrollMaxY) {
638		xScroll = window.innerWidth + window.scrollMaxX;
639		yScroll = window.innerHeight + window.scrollMaxY;
640	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all
641		// but
642		// Explorer
643		// Mac
644		xScroll = document.body.scrollWidth;
645		yScroll = document.body.scrollHeight;
646	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla
647		// and Safari
648		xScroll = document.body.offsetWidth;
649		yScroll = document.body.offsetHeight;
650	}
651
652	var windowWidth, windowHeight;
653
654	if (self.innerHeight) { // all except Explorer
655		if (document.documentElement.clientWidth) {
656			windowWidth = document.documentElement.clientWidth;
657		} else {
658			windowWidth = self.innerWidth;
659		}
660		windowHeight = self.innerHeight;
661	} else if (document.documentElement
662			&& document.documentElement.clientHeight) { // Explorer 6 Strict
663		// Mode
664		windowWidth = document.documentElement.clientWidth;
665		windowHeight = document.documentElement.clientHeight;
666	} else if (document.body) { // other Explorers
667		windowWidth = document.body.clientWidth;
668		windowHeight = document.body.clientHeight;
669	}
670
671	// for small pages with total height less then height of the viewport
672	if (yScroll < windowHeight) {
673		pageHeight = windowHeight;
674	} else {
675		pageHeight = yScroll;
676	}
677
678	// for small pages with total width less then width of the viewport
679	if (xScroll < windowWidth) {
680		pageWidth = xScroll;
681	} else {
682		pageWidth = windowWidth;
683	}
684
685	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
686	return arrayPageSize;
687}
688
689var beforeUnloadHandler_contentChanged = false;
690var beforeUnloadHandler = function() {
691
692	if (beforeUnloadHandler_contentChanged)
693		return translate.msg_unsaved_changes;
694	if (window.tinyMCE) {
695		var anyDirty = false;
696		for (var n in tinyMCE.instances) {
697			var inst = tinyMCE.instances[n];
698			if (!tinyMCE.isInstance(inst))
699				continue;
700			if (inst.isDirty())
701				return translate.msg_unsaved_changes;
702		}
703	}
704	return;
705};
706
707function getCookie(c_name) {
708	if (document.cookie.length > 0) {
709		c_start = document.cookie.indexOf(c_name + "=");
710		if (c_start != -1) {
711			c_start = c_start + c_name.length + 1;
712			c_end = document.cookie.indexOf(";", c_start);
713			if (c_end == -1)
714				c_end = document.cookie.length;
715			return unescape(document.cookie.substring(c_start, c_end));
716		}
717	}
718	return null;
719}
720
721function setCookie(c_name, value, expiredays) {
722	var exdate = new Date();
723	exdate.setDate(exdate.getDate() + expiredays);
724	document.cookie = c_name + "=" + escape(value)
725			+ ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
726}
727window.onbeforeunload = beforeUnloadHandler;

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.