try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

window.onerror = function (msg, url, line) {
	alert(msg + '\nURL: ' + url + '\nLine ' + line);
};



function popupImg(url, width, height, title) {
	var scrollbars = 0;
	var x = (screen.width - width) / 2;
	var y = (screen.height - height) / 2;

	if (x < 0) x = 0;
	if (y < 0) y = 0;

	var w = width > screen.width ? screen.width : width;
	if (height > screen.availHeight) {
		h = screen.availHeight - 29;
		scrollbars = 1;
		w += 16;
	} else {
		h = height;
	}
	wnd = window.open('', 'popupImg', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scrollbars + ',resizable=0,copyhistory=0,width=' + w + ',height=' + h + ',top=' + y + ',left=' + x);

	wnd.document.open();
	wnd.document.write("<html><head><title>"+title+"</title></head><body bgcolor=#ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0><a href='javascript:window.close()'><img src='" + url + "' border=0></a></body></html>");
	wnd.document.close;
	wnd.focus();

	return false;
}



/**
 * Главное меню
 */

var menu = {
	show: function (el) {
		AJS.addClass(el, 'active');
	},
	hide: function (el) {
		AJS.removeClass(el, 'active');
	}
}

AJS.AEV(window, 'load', function () {
	var li = AJS.$bytc('li', 'mmitem', AJS.$('mainmenu'));
	AJS.map(li, function (el, idx) {
		AJS.AEV(el, 'mouseover', function () { menu.show(el); });
		AJS.AEV(el, 'mouseout', function () { menu.hide(el); });
	});
});



/**
 * Форма поиска по сайту
 */

var search = {
	go: function () {
		if (this.submit()) document.site_search.submit();
	},
	submit: function () {
		var f = document.site_search;
		if (f.text.value.length == 0) {
			alert("Введите строку для поиска");
			f.text.focus();
			return false;
		}
		return true;
	}
};



/**
 * Форматирует число, добавляя разделители разрядов
 * r - кол-во знаков после запятой
 * g - кол-во знаков в группе
 */
Number.prototype.format = function (r, g) {
	var i, m, n = '';
	if (!g) g = 3;
	m = this.toFixed(r).toString().split('.');
	for (i = 0; i < m[0].length; i++) {
		n = m[0].charAt(m[0].length-i-1) + (i%g || !i ? '' : ' ') + n;
	}
	if (m[1]) n += ',' + m[1];
	return n;
}

