function browser(field_name, current_url, type, win) {
	tinyMCE.selectedInstance.windowManager.open({
		file : "../../files/browser.php?R=" + type + "&X=" + field_name,
		width : 600,
		height : 400,
		inline : 0
	}, {
		dialog : win
	});
}

function preview(what, w, h, s) {
	if (!what) return;
	if (!w) w = 600;
	if (!h) h = 400;
	s = s ? 1 : 0;
	scr_w = screen.width;
	scr_h = screen.height;
	l = (scr_w - w) / 2;
	t = (scr_h - h) / 2;
	popup = window.open(what, "window_id", "width=" + w + "px,height=" + h + "px,left=" + l + "px,top=" + t + "px,scrollbars=" + s + ",location=0,toolbar=0,resizable=1,menubar=0,status=0,dependent=1");
	popup.focus();
}

function load_FCKeditor(id) {
	if (!id) id = "html";
	if (!window.fck || window.fck != id) {
		var old_onload = window.onload;
		window.onload = function() {
			if (old_onload) old_onload();
			var fck = new FCKeditor(id, '100%', 400);
			fck.BasePath = '/SiteNN/FCKeditor/';
			fck.ReplaceTextarea();
		};
		window.fck = id;
	}
}

function load_TinyMCE(id) {
	if (!id) id = "html";
	if (!window.mce) {
		tinyMCE.init({
			plugins : "safari,advimage,advlink,media,table,save,contextmenu,paste,fullscreen",
			theme_advanced_buttons1 : "save,fullscreen,code,|,undo,redo,|,cut,copy,paste,pastetext,pasteword,|,link,unlink,image,media,|,bold,italic,underline,strikethrough,sub,sup,|,forecolor,backcolor,removeformat",
			theme_advanced_buttons2 : "formatselect,fontsizeselect,|,table,|,row_before,row_after,delete_row,|,col_before,col_after,delete_col,|,visualaid,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,blockquote,hr",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			accessibility_warnings : false,
			relative_urls : false,
			valid_elements : "*[*]",
			mode : "textareas",
			theme : "advanced",
			editor_selector: "TinyMCE",
			language : "ru",
			file_browser_callback : "browser",
			content_css : "/SiteNN/TinyMCE/content.css",
			fix_table_elements : 0,
			custom_elements : "noindex"
		});
		window.mce = id;
	}
}

function load_Calendar(id) {
	Calendar.setup({ inputField: id, ifFormat: "%d.%m.%Y", showsTime: false, button: id + "_control", singleClick: true, step: 1 });
}

function _m_a_i_l_t_o(u, d, e, t) {
	if (!e) return;
	if (!t) return;
	var m = "m" + "a" + "i" + "l" + "t" + "o";
	switch (e.type) {
		case "mouseover":
			window.status = m  + ":" + u + "@" + d;
			t.href		= m  + ":" + u + "@" + d;
			return true;
			break;
		case "mouseout":
			window.status = "";
			t.href		= "";
			return true;
			break;
		case "click":
			top.location.href = m  + ":" + u + "@" + d;
			return false;
			break;
	}
}

function post_message(form) {
	if (!form) return;
	var tiny;
	var html;
	var reply;
	if (typeof(tinyMCE) != "undefined") tiny = tinyMCE.getInstanceById("html");
	if (tiny) html = tiny.getContent();
	else if (form.html) html = form.html.value;
	if (form.reply) reply = form.reply.value;
	else reply = "";
	if (html) {
		if (form.submiter) form.submiter.disabled = true;
		JsHttpRequest.query(
			form.action + "&batch=1&random=" + Math.round(Math.random() * 1000000),
			{ html: html, reply: reply },
			function (result, errors) {
				if (result.OK) {
					document.getElementById("messages").innerHTML += result.HTML;
					if (tiny) tiny.setContent("");
					else if (form.html) form.html.value = "";
				} else {
					alert("Ваше сообщение не отправлено");
				}
				if (form.submiter) form.submiter.disabled = false;
			}
		);
	} else {
		alert("Пожалуйста, введите текст сообщения");
	}
	return false;
}

function reply(id, quote) {
	var form = document.forms.the_post;
	if (form && form.reply) form.reply.value = id;
	if (quote == "qq") {
		if (document.getElementById(id + "_body")) {
			var html = document.getElementById(id + "_body").innerHTML;
			if (typeof(tinyMCE) != "undefined") {
				var tiny = tinyMCE.selectedInstance;
				if (tiny) tiny.setContent("<blockquote>" + html + "</blockquote><br/>" + tiny.getContent());
			} else if (form && form.html) {
				html = html.replace(/^/m, "> ");
				form.html.value = html + "\n" + form.html.value;
			}
		}
	}
}

function trace(o) {
	var r = "";
	var z = document.getElementById("xbenchmark");
	if (typeof(o) == "object") {
		if (z) {
			for (i in o) {
				var x = "" + o[i];
				r += i + " = " + x.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;") + "<br/>"; // "
			}
			z.innerHTML = r;
		} else {
			for (i in o) {
				var x = "" + o[i];
				r += i + " = " + x + "\n";
			}
			alert(r);
		}
	} else {
		if (x) x.innerHTML = o.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;") + "<br/>"; // "
		else alert(o);
	}
}

function dump(o) {
	return trace(o);
}

function move_up(i) {
	var f = document.getElementById("theForm");
	if (!f) return;
	var t1 = f['title[' + (i - 0) + ']'];
	var t2 = f['title[' + (i - 1) + ']'];
	var n1 = f['order[' + (i - 0) + ']'];
	var n2 = f['order[' + (i - 1) + ']'];
	if (!t1 || !t2 || !n1 || !n2) return;
	var t;
	t = t1.value;
	t1.value = t2.value;
	t2.value = t;
	var n;
	n = n1.value;
	n1.value = n2.value;
	n2.value = n;
}

function move_down(i) {
	var f = document.getElementById("theForm");
	if (!f) return;
	var t1 = f['title[' + (i + 0) + ']'];
	var t2 = f['title[' + (i + 1) + ']'];
	var n1 = f['order[' + (i + 0) + ']'];
	var n2 = f['order[' + (i + 1) + ']'];
	if (!t1 || !t2 || !n1 || !n2) return;
	var t;
	t = t1.value;
	t1.value = t2.value;
	t2.value = t;
	var n;
	n = n1.value;
	n1.value = n2.value;
	n2.value = n;
}

function loginFormSubmit() {
	document.getElementById("loginForm").submit();
}

function searchFormSubmit() {
	document.getElementById("searchForm").submit();
}

function display_flash(src, width, height, a) {
	if (!window.flash_id) window.flash_id = 1;
	var isIE  = !!(navigator.appVersion.indexOf("MSIE") != -1);
	var isWin = !!(navigator.appVersion.toLowerCase().indexOf("win") != -1);
	var isOpera = !!(navigator.userAgent.indexOf("Opera") != -1);
	var id = window.flash_id ++;
	var r = "";
	if (!a) a = {};
	if (!a.id) a.id = "flash_" + id;
	if (!a.version) a.version = 9;
	if (!a.align) a.align = "middle";
	if (!a.access) a.access = "sameDomain";
	if (!a.quality) a.quality = "high";
	if (!a.background) a.background = "#ffffff";
	if (!a.wmode) a.wmode = "transparent";
	if (!a.scale) a.scale = "noscale";
	if (!a.play) a.play = "true";
	if (!a.loop) a.loop = "true";
	if (!a.menu) a.menu = "true";
	if (!a.salign) a.salign = "";
	if (!a.devicefont) a.devicefont = "false";
	if (!a.fullscreen) a.fullscreen = "false";
	if (isIE && isWin && !isOpera) {
		r += ""
		 + "<object"
		 + " classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\""
		 + " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + a.version + ",0,0,0\""
		 + " width=\"" + width + "\""
		 + " height=\"" + height + "\""
		 + " align=\"" + a.align + "\""
		 + " id=\"" + a.id + "\""
		 + " name=\"" + a.id + "\""
		 + ">"
		 + "<param name=\"movie\" value=\"" + src + "\" />"
		 + "<param name=\"quality\" value=\"" + a.quality + "\" />"
		 + "<param name=\"bgcolor\" value=\"" + a.background + "\" />"
		 + "<param name=\"allowScriptAccess\" value=\"" + a.access + "\" />"
		 + "<param name=\"wmode\" value=\"" + a.wmode + "\" />"
		 + "<param name=\"scale\" value=\"" + a.scale + "\" />"
		 + "<param name=\"play\" value=\"" + a.play + "\" />"
		 + "<param name=\"loop\" value=\"" + a.loop + "\" />"
		 + "<param name=\"menu\" value=\"" + a.menu + "\" />"
		 + "<param name=\"salign\" value=\"" + a.salign + "\" />"
		 + "<param name=\"devicefont\" value=\"" + a.devicefont + "\" />"
		 + "<param name=\"allowFullScreen\" value=\"" + a.fullscreen + "\" />"
		 + "</object>"
		;
	} else {
		r += "<embed"
		 + " src=\"" + src + "\""
		 + " width=\"" + width + "\""
		 + " height=\"" + height + "\""
		 + " align=\"" + a.align + "\""
		 + " name=\"" + a.id + "\""
		 + " quality=\"" + a.quality + "\""
		 + " bgcolor=\"" + a.background + "\""
		 + " allowScriptAccess=\"" + a.access + "\""
		 + " wmode=\"" + a.wmode + "\""
		 + " scale=\"" + a.scale + "\""
		 + " play=\"" + a.play + "\""
		 + " loop=\"" + a.loop + "\""
		 + " menu=\"" + a.menu + "\""
		 + " salign=\"" + a.salign + "\""
		 + " devicefont=\"" + a.devicefont + "\""
		 + " allowFullScreen=\"" + a.fullscreen + "\""
		 + " type=\"application/x-shockwave-flash\""
		 + " pluginspage=\"http://www.macromedia.com/go/getflashplayer\""
		 + "/>"
		;
	}
	return r;
}

function display_banner(src, width, height, href, param) {
	document.write(display_flash("/SiteNN/images/flash/place-03.swf?path=" + escape(src) + "&href=" + escape(href) + "&width=" + width + "&height=" + height + (param.scale ? "&scale=" + escape(param.scale) : ""), width, height, param));
}

