function head_mouseover(w) {
	var z = parseInt(w) + 1;
	document.getElementById('p_' + w).className = 'tmon';
	document.getElementById('l_' + w).className = 'lon';
	document.getElementById('l_' + z).className = 'lon';
}

function head_mouseout(w) {
	var z = parseInt(w) + 1;
	document.getElementById('p_' + w).className = 'tm';
	document.getElementById('l_' + w).className = 'l';
	document.getElementById('l_' + z).className = 'l';
}

function load_TinyMCE_forum(xid) {
	if (!xid) xid = "html";
	if (!window.mce_forum) {
		tinyMCE.init({
			plugins : "safari,paste,emotions",
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,sub,sup,|,bullist,numlist,blockquote,|,emotions,|,undo,redo",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "bottom",
			theme_advanced_toolbar_align : "left",
			accessibility_warnings : false,
			relative_urls : false,
			mode : "textareas",
			theme : "advanced",
			editor_selector: "TinyMCE",
			language : "ru",
			file_browser_callback : "browser",
			content_css : "/SiteNN/TinyMCE/message.css",
			valid_elements: "br,div,p,b/strong,i/em,u,ul,ol,li,sub,sup,strike,strikethrough,blockquote,a[href|target],img[src|alt]",
			force_br_newlines : true,
			forced_root_block : '',
			cleanup_on_startup : true,
			paste_auto_cleanup_on_paste : true,
			remove_trailing_nbsp : true,
			inline_styles : false
		});
		window.mce_forum = xid;
	}
}

function reply(id, quote) {
	if (1) {
		var t;
		var o = "Ответ";
		t = document.getElementById(id + "_user");
		if (t) o += " пользователю " + "<b>" + t.innerHTML + "</b>";
		t = document.getElementById(id + "_date");
		if (t) o += " на сообщение от " + t.innerHTML;
		t = document.getElementById("quot");
		if (t) t.innerHTML = o;
	}
	if (typeof(tinyMCE) == "object") {
		var tiny = tinyMCE.getInstanceById("html");
	}
	if (quote == "qq") {
		var b = document.getElementById(id + "_body");
		if (b) {
			var h = b.innerHTML.replace(/<blockquote>.*<\/blockquote>/i, "");
			if (tiny) tiny.setContent("<blockquote>" + h + "</blockquote><br/>" + tiny.getContent());
		}
	}
	var f = document.getElementById("publishForm");
	if (f) {
		f.reply.value = unescape(id);
	}
	location.href = "#";
	location.href = "#send";
}

function mbtowc(s) {
	if (typeof(s) == "object") {
		for (var i in s) s[i] = mbtowc(s[i]);
		return s;
	}
	if (typeof(s) != "string") {
		return s;
	}
	var r = "";
	var q = "?";
	for (var i = 0; i < s.length; i ++) {
		var c = s.charCodeAt(i);
		var n = s.length - i;
		if (c > 0xff) {
			r += String.fromCharCode(c);
		} else if (c < 0x80) {
			r += String.fromCharCode(c);
		} else if (c < 0xc2) {
			r += q;
			continue;
		} else if (c < 0xe0) {
			if (n < 2) {
				r += q;
				continue;
			}
			var c1 = s.charCodeAt(++ i);
			if (!((c1 ^ 0x80) < 0x40)) {
				r += q;
				continue;
			}
			r += String.fromCharCode(((c & 0x1f) << 6) | (c1 ^ 0x80));
		} else if (c < 0xf0) {
			if (n < 3) {
				r += q;
				continue;
			}
			var c1 = s.charCodeAt(++ i);
			var c2 = s.charCodeAt(++ i);
			if (!((c1 ^ 0x80) < 0x40 && (c2 ^ 0x80) < 0x40 && (c >= 0xe1 || c1 >= 0xa0))) {
				r += q;
				continue;
			}
			r += String.fromCharCode(((c & 0x0f) << 12) | ((c1 ^ 0x80) << 6) | (c2 ^0x80));
		} else if (c < 0xf8) {
			if (n < 4) {
				r += q;
				continue;
			}
			var c1 = s.charCodeAt(++ i);
			var c2 = s.charCodeAt(++ i);
			var c3 = s.charCodeAt(++ i);
			if (!((c1 ^ 0x80) < 0x40 && (c2 ^ 0x80) < 0x40 && (c >= 0xf1 || c1 >= 0x90))) {
				r += q;
				continue;
			}
			r += String.fromCharCode(((c & 0x07) << 18) | ((c1 ^ 0x80) << 12) | ((c2 ^ 0x80) << 6) | (c3 ^ 0x80));
		} else {
			r += q;
		}
	}
	return r;
}

function hideInfo() {
	document.getElementById("flash").style.zIndex = 3;
	document.getElementById("class-t1").style.display = 'none';
	document.getElementById("class-t2").style.display = 'none';
	document.getElementById("logo").style.display = 'none';
}

function devushkinoFlashReal() {
	if (flash_version() >= 8) {
		document.getElementById("flash").innerHTML = display_flash("/Flash/v14.swf", "100%", "266", { version: 8, wmode: 'opaque' });
		// "<iframe src='javascript:false' style='position: absolute; width: 100%; height: 266px; z-index: 1; display: none;' id='devushkino_flash_iframe' frameborder='0' scrolling='no'></iframe>";
		// document.getElementById("devushkino_flash_iframe").style.display = "block";
	}
}

function devushkinoFlash() {
	var devushkino_flash_window_onload = window.onload;
	window.onload = function() {
		if (devushkino_flash_window_onload) {
			devushkino_flash_window_onload();
		}
		devushkinoFlashReal();
	}
}
devushkinoFlash();

function html_auto_save(id) {
	var window_onload = window.onload;
	window.onload = function() {
		if (typeof(window_onload) == "function") window_onload();
		window.auto_save_id = id;
		var tiny = tinyMCE.getInstanceById("html");
		var auto = document.getElementById("html-auto-save");
		if (tiny && auto) {
			if (confirm("Страница была автоматически сохранена. Открыть сохраненный вариант для редактирования?")) {
				window.setTimeout("html_auto_load()", 1000);
			}
		}
	}
}

function html_auto_load() {
	var id = window.auto_save_id;
	var tiny = tinyMCE.getInstanceById("html");
	var auto = document.getElementById("html-auto-save");
	if (tiny && auto) {
		tiny.setContent(auto.value);
	}
}

function html_auto_send() {
	var id = window.auto_save_id;
	var tiny = tinyMCE.getInstanceById("html");
	if (tiny) {
		var html = tiny.getContent();
		JsHttpRequest.query(
			"/SiteNN/request/?a=save",
			{ id: id, html: html },
			function (result, errors) {
				if (result && result.OK && result.date) {
					document.getElementById("date-auto-save").innerHTML = "Автоматическое сохранение в " + result.date;
				}
				window.setTimeout("html_auto_send()", 30000);
			}
		);
	}
}
