var my_browser = navigator.userAgent.toLowerCase();

var my_browser = navigator.userAgent.toLowerCase();
var my_version = null;
if (my_browser.indexOf("msie") != -1 && my_browser.indexOf("opera") == -1) {
	if (my_browser.indexOf("msie 5.0") != -1) my_version = 5;
	else if (my_browser.indexOf("msie 5.5") != -1) my_version = 5.5;
	else if (my_browser.indexOf("msie 6.0") != -1) my_version = 6;
	my_browser = "ie";
}
else if (my_browser.indexOf("opera") != -1) my_browser = "opera";
else if (navigator.product.toLowerCase().indexOf("gecko") != -1) my_browser = "gecko";
else my_browser = "unknown";

function fo(id) {
	return document.getElementById(id);
}

function is_empty(id, title) {
	if (!fo(id) || fo(id).value == "") {
		window.alert('Не заполнено поле "' + title + '"');
		return true;
	}
	return false;
}

function is_longer(id, title, val) {
	if (fo(id).value.length > Number(val)) {
		window.alert('Поле "' + title + '" не может быть длиннее чем ' + String(val) + '. Сейчас его длина составляет ' + fo(id).value.length);
		return true;
	}
	return false;
}

function is_shorter(id, title, val) {
	if (fo(id).value.length < Number(val)) {
		window.alert('Поле "' + title + '" не может быть короче чем ' + String(val) + '. Сейчас его длина составляет ' + fo(id).value.length);
		return true;
	}
	return false;
}

function sb(id) {
	var pl = fo(id + "p");
	if (fo(id).style.display != "block") {
		fo(id).style.display = "block";
		if (pl) pl.innerText = "-";
	}
	else {
		fo(id).style.display = "none";
		if (pl) pl.innerText = "+";
	}
}
function update_rubr(name, cmin, cmax) {
	var inputs = document.getElementsByTagName("input");
	var cnt = 0;
	var inp = fo(name + "_rubrinfo");
	var inner = "";
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].checked && inputs[i].name && inputs[i].id && inputs[i].checked && inputs[i].name.slice(0, String(name).length) == name) {
			inner += "<br><span class=\"mm\">" + (cnt + 1) + ". " + "<input type=checkbox onclick=\"fo(\'" + inputs[i].id + "\').checked = false;update_rubr(\'" + name + "\');\" checked> " + fo(inputs[i].id + "1").innerHTML + " </span><span class=\"sm\">(" + update_rubr_parent(inputs[i]) + ")</span>";
			cnt++;
		}
	}
	if (cmin && cnt < cmin) {
		alert('Вы не можете выбрать менее ' + String(cmin) + ' элементов');
		return false;
	}
	if (cmax && cnt > cmax) {
		alert('Вы не можете выбрать более ' + String(cmax) + ' элементов');
		return false;
	}
	if (cnt != 0) inp.innerHTML = "<br><b class=\"mm\">Выбранные рубрики:</b>" + inner;
	else inp.innerHTML = "";
}

function update_rubr_parent(obj) {
	var parent = obj.parentNode;
	if (parent && parent.tagName) {
		if (parent.tagName.toLowerCase() == "div" && parent.id && fo(parent.id + "t")) {
			var inner = update_rubr_parent(parent);
			return (inner ? inner + " // " : "") + fo(parent.id + "t").innerHTML;
		}
		else return update_rubr_parent(parent);
	}
	return "";
}

function wo(url, width, height, scrollbar, resize, content, menu) {
	var left = '';
	var top = '';
	var width = width != 0 ? (Number(width) + 20) : 600;
	var height = height != 0 ? (Number(height) + 20) : 500;
	if (window.screen.width) left = ',left=' + (window.screen.width / 2 - width / 2);
	if (window.screen.height) top = ',top=' + (window.screen.height / 2 - height / 2);
	var width = width ? ',width=' + width : "";
	var height = height ? ',height=' + height : "";
	var wnd = window.open(url, '_blank', 'menubar=' + (menu ? 'yes' : 'no') + ',resizable=' + (resize ? 'yes' : 'no') + ',status=no,toolbar=no,scrollbars=' + (scrollbar ? 'yes' : 'no') + width + height + top + left);
	if (content) wnd.document.write(content);
}

function woi(url) {
	window.open(url, '_blank', 'width=600,height=500,scrollbars=yes,menubar=no,resizable=no,status=no,toolbar=no');
}

