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');
}

var pwnd = new Object();
function pwnd_move_start(evt) {
	var wnd = fo("my_wnd");
	pwnd.visible = true;
	var e = window.event ? window.event : evt;
	pwnd.x = (window.event ? e.clientX : e.pageX) - wnd.style.left.slice(0, wnd.style.left.length - 2);
	pwnd.y = (window.event ? e.clientY : e.pageY) - wnd.style.top.slice(0, wnd.style.top.length - 2);
}
function pwnd_move_finish() {
	var wnd = fo("my_wnd");
	pwnd.visible = false;
}
function pwnd_move(evt) {
	var wnd = fo("my_wnd");
	if (pwnd.visible) {
		var e = window.event ? window.event : evt;
		wnd.style.left = (window.event ? e.clientX : e.pageX) - pwnd.x;
		wnd.style.top = (window.event ? e.clientY : e.pageY) - pwnd.y;
	}
}
function pwnd_close() {
	var wnd = fo("my_wnd");
	wnd.style.cursor = "default";
	wnd.parentNode.removeChild(wnd);
}
function pwnd_open(content, width, height) {
	var wnd = fo("my_wnd");
	if (wnd) wnd.parentNode.removeChild(wnd);
	var res = "";
	var width = width != 0 ? Number(width) : 600;
	var height = height != 0 ? Number(height) : 500;
	var left = window.screen.width ? (window.screen.width / 2 - width / 2) : 100;
	var top = window.screen.height ? (window.screen.height / 2 - height / 2) - 100 : 100;
	res += "<table cellpadding=0 cellspacing=0 width=" + (width + 4) + "px height=" + (height + 20) + "px style=\"display:block;border:2px outset #99ccff;\">";
	res += "<tr><td><table cellpadding=0 cellspacing=0 width=100%><tr>";
	res += "<td style=\"padding:2px;font-family:arial;font-size:8pt;font-weight:bold;cursor:default;background-color:#C1D2EE;\" unselectable=on height=10px width=100% onmousedown=\"pwnd_move_start(event);\" onmouseup=\"pwnd_move_finish();\" onmousemove=\"pwnd_move(event);\" onmouseout=\"pwnd_move_finish();\"></td>";
	res += "<td unselectable=on onclick=\"pwnd_close();\" style=\"height:10px;background-color:#C1D2EE;border-left:2px outset #99ccff;font-family:arial;font-size:8pt;font-weight:bold;cursor:hand;padding-left:8px;padding-right:8px;\">x</td>";
	res += "</tr></table></td></tr>";
	res += "<tr valign=top><td style=\"border-top:2px outset #99ccff;background-color:#F4FDFD;\"><iframe id=\"swnd_wnd\" frameborder=0 style=\"width:" + width + "px;height:" + height + "px;\"></iframe></td></tr>";
	res += "</table>";
	var wnd = document.createElement("SPAN");
	wnd.id = "my_wnd";
	wnd.style.position = "absolute";
	wnd.style.left = left;
	wnd.style.top = top + document.body.scrollTop;
	
	wnd.innerHTML = res;
	document.body.appendChild(wnd);
	fo("swnd_wnd").contentWindow.document.write("<body leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0>" + content + "</body>");
}

function io(path, width, height) {
	pwnd_open("<img src=\"" + path + "\" border=0 width=\"" + width + "\" height=\"" + height + "\">", width, height);
}
