var frontendErrorRegistrator = {
	firsterror: true,
	stack: [],
	ini: function() {
		document.body.onclick = frontendErrorRegistrator.h;
	},
	h: function(e) {
		var o;
		if (!e) {
			e = window.event;
			o = e.srcElement;
		} else o = e.target;
		if (!o) return;
		if (frontendErrorRegistrator.stack.length > 10) frontendErrorRegistrator.stack.shift();
		frontendErrorRegistrator.stack.push(o.id === '' ? o : o.id);
	},
	normalize: function() {
		var i = 0, s = frontendErrorRegistrator.stack, so = s.length, res = [], o, tmp, k, e;
		for(; i < so; i++) {
			if (typeof s[i] === 'string') {
				res[i] = '#'+ s[i];
				continue;
			}
			o = s[i];
			tmp = [];
			while (o && o.parentNode && o.tagName !== 'BODY') {
				if (o.tagName === 'TBODY') {
					o = o.parentNode;
					continue;
				}
				for (k = 0, e = o; e = e.previousSibling; e.tagName ? k++ : null);
				tmp.push(o.tagName + (k ? '-'+ k : ''));
				o = o.parentNode;
			}
			res[i] = tmp.join('>');
		}
		return res;
	},
	register: function(msg, url, line) {
		if (!frontendErrorRegistrator.firsterror || typeof msg === 'undefined' || typeof url === 'undefined' || typeof line === 'undefined') return;
		frontendErrorRegistrator.firsterror = false;
		setTimeout(function (msg, url, line) {
			if (document.body) document.body.appendChild(document.createElement("SCRIPT")).src = "/cms/ajax/register.javascript.error.php?msg="+ encodeURIComponent(msg) +"&url="+ encodeURIComponent(url) +"&line="+ encodeURIComponent(line) +"&stack="+ encodeURIComponent(frontendErrorRegistrator.normalize());
		}, 999, msg, url, line);
	}
};

window.onload = frontendErrorRegistrator.ini;
window.onerror = frontendErrorRegistrator.register;
