var frontendErrorRegistrator = {
	firsterror: true,
	stack: [],
	cms_path: '',
	ini: function(cms_path) {
		frontendErrorRegistrator.cms_path = cms_path;
		window.onerror = frontendErrorRegistrator.register;
		frontendErrorRegistrator.signOnClick();
	},
	signOnClick: function() {
		if (document.body) document.body.onclick = frontendErrorRegistrator.clicked;
		else setTimeout(frontendErrorRegistrator.signOnClick, 25);
	},
	clicked: 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('if(document.body)document.body.appendChild(document.createElement("SCRIPT")).src="'+ frontendErrorRegistrator.cms_path +'register.javascript.error.php?msg='+ encodeURIComponent(msg) +'&url='+ encodeURIComponent(url) +'&line='+ encodeURIComponent(line) +'&stack='+ encodeURIComponent(frontendErrorRegistrator.normalize()) +'";', 999);
	}
};