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();
	return false;
}

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, time) {
	Calendar.setup({ inputField: id, ifFormat: time ? "%d.%m.%Y %H:%M" : "%d.%m.%Y", showsTime: time ? true : 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 flash_version() {
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins['Shockwave Flash 2.0']) {
			return parseInt(navigator.plugins['Shockwave Flash 2.0'].description.split(" ")[2]);
		} else if (navigator.plugins['Shockwave Flash']) {
			return parseInt(navigator.plugins['Shockwave Flash'].description.split(" ")[2]);
		}
	} else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) {
		return 4;
	} else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) {
		return 3;
	} else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) {
		return 2;
	} else if ((navigator.appVersion.indexOf("MSIE") != -1) && (navigator.appVersion.toLowerCase().indexOf("win") != -1) && !(navigator.userAgent.indexOf("Opera") != -1)) {
		try {
			return parseInt(((new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7")).GetVariable("$version")).split(" ")[1]);
		} catch (e) { }
		try {
			return (new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6")) ? 6 : 0;
		} catch (e) { }
		try {
			return parseInt(((new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3")).GetVariable("$version")).split(" ")[1]);
		} catch (e) { }
		try {
			return (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) ? 2 : 0;
		} catch (e) { }
	}
	return 0;
}

function write_flash(src, width, height, a) {
	document.write(display_flash(src, width, height, a));
}

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

function menu_show(o, n) {
    if (o) {
        var d = menu_find(o, n);
        if (!d) return;
        if (window._menu_object) {
            if (window._menu_object != d) {
                window._menu_object.className = window._menu_object.className.replace("show", "hide");
				if (n) if (window._menu_object.parentNode.className && window._menu_object.parentNode.className.indexOf("active") >= 0) {
					if (window._menu_object.parentNode.className == "active") window._menu_object.parentNode.className = "";
					else window._menu_object.parentNode.className = window._menu_object.parentNode.className.replace(" active", "");
				}
                window._menu_object = null;
            }
        }
        if (window._menu_status) {
            window.clearTimeout(window._menu_status);
            window._menu_status = null;
        }
        d.className = d.className.replace("hide", "show");
		if (n) {
			if (d.parentNode.className && d.parentNode.className.indexOf("active") < 0) d.parentNode.className += " active";
			else d.parentNode.className = "active";
		}
        window._menu_object = d;
    }
}

function menu_hide(o, n) {
    if (o) {
        var d = menu_find(o, n);
        if (!d) return;
        if (window._menu_object) {
            if (window._menu_object != d) {
                window._menu_object.className = window._menu_object.className.replace("show", "hide");
				if (n) if (window._menu_object.parentNode.className && window._menu_object.parentNode.className.indexOf("active") >= 0) {
					if (window._menu_object.parentNode.className == "active") window._menu_object.parentNode.className = "";
					else window._menu_object.parentNode.className = window._menu_object.parentNode.className.replace(" active", "");
				}
                window._menu_object = null;
            }
        }
        window._menu_status = window.setTimeout("menu_hide(" + (n ? "null, true" : "") + ")", 1000);
        window._menu_object = d;
    } else {
        if (window._menu_object) {
            window._menu_object.className = window._menu_object.className.replace("show", "hide");
			if (n) if (window._menu_object.parentNode.className && window._menu_object.parentNode.className.indexOf("active") >= 0) {
				if (window._menu_object.parentNode.className == "active") window._menu_object.parentNode.className = "";
				else window._menu_object.parentNode.className = window._menu_object.parentNode.className.replace(" active", "");
			}
            window._menu_object = null;
        }
        if (window._menu_status) {
            window.clearTimeout(window._menu_status);
            window._menu_status = null;
        }
    }
}

function menu_find(o, n) {
	if (n) {
		var d = o.firstChild;
		while (d) {
			if (d.tagName && d.className && (d.className.indexOf("show") >= 0 || d.className.indexOf("hide") >= 0)) {
				return d;
			}
			d = d.nextSibling;
		}
	} else {
	    var d = null;
	    if (o.tagName == "A") {
			if (!d || !d.tagName || (d.tagName != "DIV" && d.tagName != "TABLE" && d.tagName != "P")) {
				d = o.firstChild;
				while (d && !d.tagName) d = d.nextSibling;
			}
			if (!d || !d.tagName || (d.tagName != "DIV" && d.tagName != "TABLE" && d.tagName != "P")) {
				d = o.nextSibling;
				while (d && !d.tagName) {
					d = d.nextSibling;
				}
			}
	    } else {
    	    d = o;
	    }
		if (!d || !d.tagName || (d.tagName != "DIV" && d.tagName != "TABLE" && d.tagName != "P")) return;
		else return d;
	}
}

function viewImage(o) {
	flash_hide();
	var x, y, w, h;
	if (self.innerWidth && self.innerHeight) {
		x = parseInt(self.innerWidth);
		y = parseInt(self.innerHeight);
	} else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
		x = parseInt(document.documentElement.clientWidth);
		y = parseInt(document.documentElement.clientHeight);
	} else {
		x = parseInt(document.body.clientWidth);
		y = parseInt(document.body.clientHeight);
	}
	var html = viewImageHTML(o, x, y);
	var elem = document.getElementById("viewImage");
	if (!elem) {
		elem = document.createElement("div");
		elem.id = "viewImage";
		elem.style.position = "fixed";
		elem.style.zIndex = 10000;
		document.body.appendChild(elem);
	} else {
		elem.innerHTML = "";
	}
	elem.style.visibility = "hidden";
	var shade = document.getElementById("viewImageShade");
	if (!shade) {
		shade = document.createElement("div");
		shade.id = "viewImageShade";
		shade.style.position = "fixed";
		shade.style.zIndex = 9999;
		document.body.appendChild(shade);
		shade.style.top = "0px";
		shade.style.left = "0px";
		shade.style.minWidth = "100%";
		shade.style.minHeight = "100%";
		shade.style.width = x + "px";
		shade.style.height = y + "px";
		shade.style.background = "#000000";
		var opacity = 0.5;
		if (typeof(document.body.style.opacity) == "string") {
			shade.style.opacity = opacity;
		} else if (typeof(document.body.style.MozOpacity) == "string") {
			shade.style.MozOpacity = opacity;
		} else if (typeof(document.body.style.KhtmlOpacity) == "string") {
			shade.style.KhtmlOpacity = opacity;
		} else if (document.body.filters) {
			shade.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=" + (opacity * 100) + ")";
		}
		shade.onclick = function() { viewImageQuit(); };
	} else {
		shade.style.display = "inline";
	}
	elem.style.display = "inline";
	elem.innerHTML = html;
	elem.style.width = "auto";
	elem.style.height = "auto";
	var w = elem.offsetWidth;
	var h = elem.offsetHeight;
	elem.style.top = parseInt((y - h - 100) / 2) + "px";
	elem.style.left = parseInt((x - w - 100) / 2) + "px";
	elem.style.top = "50px";
	elem.style.left = "50px";
	elem.style.position = "fixed";
	elem.style.visibility = "visible";
	if (!viewImageNext(false, true)) document.getElementById("viewImageNext").className = "disabled";
	if (!viewImagePrev(false, true)) document.getElementById("viewImagePrev").className = "disabled";
	if (navigator.appVersion.indexOf("MSIE") > 0 && navigator.appVersion.indexOf("Opera") < 0) {
		if (parseFloat(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE") + 5)) < 9) {
			elem.style.display = "block";
			elem.style.position = "absolute";
			if (typeof(elem._top) == "undefined") elem._top = elem.style.top;
			if (typeof(elem._left) == "undefined") elem._left = elem.style.left;
			elem.style.top = parseInt(elem._top) + parseInt(window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0) + "px";
			elem.style.left = parseInt(elem._left) + parseInt(window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft || 0) + "px";
			shade.style.position = "absolute";
			if (typeof(shade._top) == "undefined") shade._top = shade.style.top;
			if (typeof(shade._left) == "undefined") shade._left = shade.style.left;
			shade.style.top = parseInt(shade._top) + parseInt(window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0) + "px";
			shade.style.left = parseInt(shade._left) + parseInt(window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft || 0) + "px";
			var window_onscroll = window.onscroll;
			window.onscroll = function() {
				var elem = document.getElementById("viewImage");
				if (elem && elem.style.display != "none") {
					elem.style.top = parseInt(elem._top) + parseInt(window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0) + "px";
					elem.style.left = parseInt(elem._left) + parseInt(window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft || 0) + "px";
				}
				var shade = document.getElementById("viewImageShade");
				if (shade && shade.style.display != "none") {
					shade.style.top = parseInt(shade._top) + parseInt(window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0) + "px";
					shade.style.left = parseInt(shade._left) + parseInt(window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft || 0) + "px";
				}
				if (window_onscroll) window_onscroll();
			}
		}
	}
	return false;
}

function viewImageHTML(o, x, y) {
	window.viewImageElem = o;
	var image = o.attributes['x-image'];
	image = image ? image.value : "";
	var title = o.attributes['x-title'];
	title = title ? title.value : "";
	var width = o.attributes['x-width'];
	width = width ? parseInt(width.value) : 0;
	var height = o.attributes['x-height'];
	height = height ? parseInt(height.value) : 0;
	var position = o.attributes['x-position'];
	position = position ? parseInt(position.value) : "";
	var total = o.attributes['x-total'];
	total = total ? parseInt(total.value) : "";
	var w = width;
	var h = height;
	var src = image;
	var thumb;
	if (x && y && w && h) {
		if (w + 200 > x) {
			w = x - 200;
			h = w * height / width;
		}
		if (h + 300 > y) {
			h = y - 300;
			w = h * width / height;
		}
		if (w != width || h != height) {
			src = "/file/view2" + image + "/r=" + parseInt(w) + "," + parseInt(h) + "_wm_i.jpg";
		}
		if (0) {
			var list = o.getElementsByTagName("img");
			for (var i = 0; i < list.length; i ++) if (list[i]) {
				thumb = list[i].src;
			}
		}
	}
	var pre = thumb ? "<img src=\"" + thumb + "\"" + (w ? " width=\"" + w + "\"" : "") + (h ? " height=\"" + h + "\"" : "") + ">" : "";
	var img = image ? "<img src=\"" + src + "\"" + (w ? " width=\"" + w + "\"" : "") + (h ? " height=\"" + h + "\"" : "") + (pre ? " style=\"position: absolute;\"" : "") + ">" : "";
	return ""
	 + "<table class=\"viewImage\">"
	 + "<tr><td><table id=\"viewImageControl\"><tr>"
	 + "<td id=\"viewImagePrev\"><a href=\"\" onclick=\"return viewImagePrev()\">&#x2190;</a></td>"
	 + "<td id=\"viewImageNext\"><a href=\"\" onclick=\"return viewImageNext()\">&#x2192;</a></td>"
	 + "<td id=\"viewImageTitle\">" + title + "</td>"
	 + "<td id=\"viewImageCount\">" + (position && total ? "" + position + "/" + total : "" + position + total) + "</td>"
	 + "<td id=\"viewImageQuit\"><a href=\"\" onclick=\"return viewImageQuit()\">x</a></td>"
	 + "</tr></table></td></tr>"
	 + "<tr><td>" + img + pre + "</td></tr>"
	 + "</table>"
	;
}

function viewImageQuit() {
	var elem = document.getElementById("viewImage");
	if (elem) elem.style.display = "none";
	var shade = document.getElementById("viewImageShade");
	if (shade) shade.style.display = "none";
	flash_show();
	return false;
}

function viewImageNext(stop, r) {
	var o = window.viewImageElem;
	if (!o) return;
	var curr_image, next_image, prev_image;
	curr_image = o.attributes['x-image'] ? o.attributes['x-image'].value : "";
	next_image = "";
	prev_image = "";
	var i, o_prev, o_next, list = document.getElementsByTagName("a");
	for (i = 0; i < list.length; i ++) if (o_next = list[i]) {
		if (typeof(o_next) == "object" && o_next.attributes && o_next.attributes['x-image']) {
			next_image = o_next.attributes['x-image'].value;
			if (prev_image == curr_image) {
				if (o_next) return r ? o_next : viewImage(o_next);
			}
			o_prev = o_next;
			prev_image = next_image;
		}
	}
	if (stop) return false;
	var pager;
	list = document.getElementsByTagName("div");
	for (i = 0; i < list.length; i ++) if (o = list[i]) {
		if (typeof(o) == "object" && o.className == "pager") {
			pager = o;
			continue;
		}
	}
	if (pager) {
		list = pager.getElementsByTagName("a");
		o_prev = null;
		o_next = null;
		for (i = 0; i < list.length; i ++) if (o = list[i]) {
			o_next = o;
			if (o_prev && o_prev.className == "active") {
				if (o_next) {
					viewImageHref(o_next.href, "next", r);
					return false;
				}
			}
			o_prev = o;
		}
	}
	return false;
}

function viewImagePrev(stop, r) {
	var o = window.viewImageElem;
	if (!o) return;
	var curr_image, next_image, prev_image;
	curr_image = o.attributes['x-image'] ? o.attributes['x-image'].value : "";
	next_image = "";
	prev_image = "";
	var i, o_prev, o_next, list = document.getElementsByTagName("a");
	for (i = 0; i < list.length; i ++) if (o_next = list[i]) {
		if (typeof(o_next) == "object" && o_next.attributes && o_next.attributes['x-image']) {
			next_image = o_next.attributes['x-image'].value;
			if (next_image == curr_image) {
				if (o_prev) return r ? o_prev : viewImage(o_prev);
			}
			o_prev = o_next;
			prev_image = next_image;
		}
	}
	if (stop) return false;
	var pager;
	list = document.getElementsByTagName("div");
	for (i = 0; i < list.length; i ++) if (o = list[i]) {
		if (typeof(o) == "object" && o.className == "pager") {
			pager = o;
			break;
		}
	}
	if (pager) {
		list = pager.getElementsByTagName("a");
		o_prev = null;
		o_next = null;
		for (i = 0; i < list.length; i ++) if (o = list[i]) {
			o_next = o;
			if (o_next && o_next.className == "active") {
				if (o_prev) {
					viewImageHref(o_prev.href, "prev", r);
					return false;
				}
			}
			o_prev = o;
		}
	}
	return false;
}

function viewImageHref(href, what, r) {
	if (typeof(JsHttpRequest) == "function") {
		if (!window.viewImageBatch) window.viewImageBatch = {};
		if (window.viewImageBatch[href]) {
			if (what == "next") {
				var x = viewImageNext(1, r);
				if (r && x) document.getElementById("viewImageNext").className = "";
			}
			if (what == "prev") {
				var x = viewImagePrev(1, r);
				if (r && x) document.getElementById("viewImagePrev").className = "";
			}
		} else {
			JsHttpRequest.query(
				href.indexOf("?") < 0 ? href + "?t=batch" : href + "&t=batch",
				{ },
				function (result, errors) {
					if (result.HTML && !window.viewImageBatch[href]) {
						var div = document.createElement("div");
						div.style.position = "absolute";
						div.style.display = "none";
						div.innerHTML = result.HTML;
						if (what == "next") document.body.appendChild(div);
						if (what == "prev") document.body.insertBefore(div, document.body.firstChild);
						window.viewImageBatch[href] = 1;
						if (what == "next") {
							var x = viewImageNext(1, r);
							if (r && x) document.getElementById("viewImageNext").className = "";
						}
						if (what == "prev") {
							var x = viewImagePrev(1, r);
							if (r && x) document.getElementById("viewImagePrev").className = "";
						}
					}
				}, false
			);
		}
	}
}

function flash_text(tag, css, a) {
	var list = document.getElementById(tag);
	if (list) {
		list = [ list ];
	} else {
		list = [];
		var l = document.getElementsByTagName(tag);
		for (var i = 0; i < l.length; i ++) if (l[i] && (!css || l[i].className == css)) list[list.length] = l[i];
	}
	for (var i = 0; i < list.length; i ++) {
		var o = list[i];
		var z = o.innerHTML;
		z = z.replace("\r", "");
		z = z.replace("\n", " ");
		z = z.replace("&", "%26");
		var f = "/SiteNN/images/flash/text-03.swf";
		var w = o.offsetWidth;
		var h = o.offsetHeight;
		var x = o.offsetX;
		var y = o.offsetY;
		if (a.flash) f = a.flash;
		if (a.width) w = a.width;
		if (a.height) h = a.height;
		f += "?text=" + z;
		f += "&width=" + w;
		f += "&height=" + h;
		for (var j in a) f += "&" + j + "=" + escape(a[j]);
		var div = document.createElement("div");
		div.style.position = "absolute";
		div.innerHTML = display_flash(f, w, h, { version: 7, scale: 'noscale', wmode: 'transparent', salign: 'lt' });
		o.parentNode.insertBefore(div, o);
		o.style.visibility = "hidden";
	}
}

function flash_show() {
	if (window.movies && window.movies.length) {
		for (var i = 0; i < window.movies.length; i ++) window.movies[i].style.display = "inline";
	}
}

function flash_hide() {
	if (!window.movies) {
		window.movies = [];
		var list;
		list = document.getElementsByTagName("embed");
		if (list) for (var i = 0; i < list.length; i ++) if (list[i] && list[i].style && list[i].style.display != "none") window.movies[window.movies.length] = list[i];
		list = document.getElementsByTagName("object");
		if (list) for (var i = 0; i < list.length; i ++) if (list[i] && list[i].style && list[i].style.display != "none") window.movies[window.movies.length] = list[i];
	}
	if (window.movies && window.movies.length) {
		for (var i = 0; i < window.movies.length; i ++) window.movies[i].style.display = "none";
	}
}

function deleteCart(n) {
	if (!confirm("Удалить товар из корзины?")) return;
	var form = document.getElementById('theForm');
	form['qq[' + n + ']'].value = 0;
	form.submit();
}

function vote(href, o) {
	var v = "";
	if (o.value) v = o.value;
	if (o.attributes && o.attributes['x-value']) v = o.attributes['x-value'].value;
	if (typeof(JsHttpRequest) == "function") {
		JsHttpRequest.query(
			href.indexOf("?") < 0 ? href + "?t=batch&vote=" + escape(v) : href + "&t=batch&vote=" + escape(v),
			{ },
			function (result, errors) {
				var x = document.getElementById("poll");
				if (x) {
					x.innerHTML = result.HTML;
				} else {
					location.href = href.indexOf("?") < 0 ? href + "?vote=" + escape(v) : href + "&vote=" + escape(v);
				}
			}, false
		);
	} else {
		location.href = href.indexOf("?") < 0 ? href + "?vote=" + escape(v) : href + "&vote=" + escape(v);
	}
	return false;
}
