function toggle() {
	for (var i = 0; i < arguments.length; i++) {
		var obj = $(arguments[i]);
		obj.style.display = (obj.style.display == 'none' ? '' : 'none');
	}
}

function hide() {
	for (var i = 0; i < arguments.length; i++) {
		$(arguments[i]).style.display = 'none';
	}
}

function show() {
	for (var i = 0; i < arguments.length; i++) {
		$(arguments[i]).style.display = '';
	}
}

function ask(str, func) {
	if (confirm(str)) {
		if (typeof func == "string") {
			(Function(func))();
		} else if (typeof func == "function") {
			func();
		}
		return true;
	}
	return false;
}

function pDel (obj) {
	var slide = $(obj, "parent").slide;
	var h = slide.getSize().size.y;
	slide.replaceEffect(function(t) { this.style.height = ((1 - t) * h) + "px"; if (t == 1) this.remove(); }, 500);
	obj.onclick = function () { return false; };
	return false;
}

function addInsInp(type, name, label, where, value) {
	value = value ? ' value="' + value + '"' : "";
	var inp = $c("span", {className: 'inp'}, '<label>' + label + ':</label><input type="' + type + '" class="' + type + '" name="' + name + '[]"' + value + ' /> <a href="#" onclick="return pDel(this);">удалить</a><br />');
	inp.style.display = 'none';
	$(where).appendChild(inp);
	inp.slideIn();
	return false;
}
function addCarInsImage() { return addInsInp('file', 'photo', 'Фото', 'addCarImages'); }
function addPollInsVariant() { return addInsInp('text', 'variants', 'Вариант ответа', 'addPollVariants'); }
function addPostInsVideo(link) { return addInsInp('text', 'video', 'Ссылка на видео', 'addPostVideos', link); }
function addPostInsImage() { return addInsInp('file', 'photo', 'Фото', 'addPostImages'); }

function addVideo() { }

var curNick = "";
function commentReply(parent, lev, num, nick) {
	document.leaveCommentForm.comment_parent.value = parent;
	document.leaveCommentForm.level.value = lev + 1;
	document.leaveCommentForm.number.value = num;
	var comment = document.leaveCommentForm.text.value;
	if ((curNick != "") && (comment.substr(0, curNick.length + 1) == curNick + ":")) {
		comment = nick + ":" + comment.substr(curNick.length + 1);
	} else {
		comment = nick + ": " + comment;
	}
	curNick = nick;
	document.leaveCommentForm.text.value = comment;
	document.leaveCommentForm.text.focus();
	return false;
}

function  photoChange(obj) {
	var vs = $(obj, 'parent', 'parent', 'div', 0, 'span');
	for (var i in vs)
		hide(vs[i]);
	show(vs[obj.value]);
}

function photoChangeE(obj) {
	var vs = $(obj, 'parent', 'parent', 'div', 0, 'span');
	for (var i in vs)
		hide(vs[i]);
	var tmp = { '2': 0, '1': 1, '0': 2, '-1': 3 };
	show(vs[tmp[obj.value]]);
}

function getCheckedRadio(name) {
	alert(name);
	if (arguments.length == 1)
		var inputs = document.getElementsByTagName('input');
	else
		var inputs = $(arguments[1]).getElementsByTagName('input');
	alert(inputs.length);
	for (var i in inputs) {
		alert(inputs[i].name);
		if (inputs[i].name == name && inputs[i].checked) {
			alert(inputs[i].value);
			return inputs[i];
		}
	}
	return null;
}

function getPhotoCheckedRadio(obj) {
	var ch = $(obj, 'input');
	for (var i in ch) {
		if (ch[i].checked)
			return ch[i];
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return {x: curleft, y: curtop};
}

function mousePos(e) {
	var pos = {x: 0, y: 0};
	if (arguments.length > 1) {
		pos = findPos(arguments[1]);
	}
	if ($isdef(e.pageX)) {
		return { x: e.pageX - pos.x, y: e.pageY - pos.y };
	} else {
		if ($isdef(document.documentElement.scrollTop)) {
			return { x: e.clientX + document.documentElement.scrollLeft - pos.x, y: e.clientY + document.documentElement.scrollTop - pos.y };
		} else {
			return { x: e.clientX + document.body.scrollLeft - pos.x, y: e.clientY + document.body.scrollTop - pos.y };
		}
	}
}

function mouseIsOut(_e, obj) {
	var e = $event(_e);
	var x = e.toElement;
	while (x) {
		if (x == obj) {
			return false;
		}
		x = x.parentNode;
	}
	return true;
}

var maxV = 3, deltaV = 10;
var minX = 20, deltaT = 50;
Math.sgn = function (x) {
	if (x > 0)
		return 1;
	if (x < 0)
		return -1;
	return 0;
}
function moveGallery(gallery, t) {
	with (gallery) {
		if (((from == to) || stop) && (Math.abs(v) < 1)) {
			v = 0;
		} else {
			if ((Math.abs(from - to) < 1) && (Math.abs(v) < 1)) {
				from = to;
				v = 0;
			} else {
				var x = to - from;
				var mV = maxV;
				var mX = minX
				if (turbo) {
					mV *= 5;
					mX *= 5;
				}
				if (Math.abs(x) < mX) {
					mV = Math.abs(x * mV / mX);
				}
				var napr = (Math.sgn(x) == Math.sgn(v));
				if (stop) {
					var dV = - deltaV * Math.sgn(v) * t / 1000;
					if (Math.abs(dV) > Math.abs(v)) {
						v = 0;
					} else {
						v += dV;
					}
				} else if ((Math.abs(v) < mV) || (!napr)) {
					v += deltaV * Math.sgn(x) * t / 1000;
				}
				if (Math.abs(v) > mV) {
					if (Math.abs(x) < mX) {
						v = mV * Math.sgn(v);
					} else {
						v -= Math.sgn(v) * deltaV * t / 1000;
					}
				}
				var deltaX = v * deltaT * t / 1000;
				if ((napr) && (Math.abs(deltaX) > Math.abs(x)))
					deltaX = x;
				from += deltaX;
			}
			parent.scrollLeft = Math.round(from);
		}
	}
	gallery.checkButtons();
}

var Galleries = [];
function moveGalleries(t) {
	for (var i in Galleries) {
		moveGallery(Galleries[i], t);
	}
}

function defineGallery(id) {
	var gallery = $(id, 'div', 0, 'ul', 0);
	var thumbs = $(gallery, 'li');
	var picholder = $(id, 'div', 2, 'div', 1);
	picholder.parent = $(picholder, "parent");
	var num = thumbs.length;
	gallery.style.width = (num * 180) + "px";
	var width = (num - 4) * 180;
	$extend(gallery, {"num": num, cur: -1, moveTo: Function.empty});
	if (num > 4) {
		$(id).className = "gallery gallery-full";
		$extend(gallery, {from: 0, to: 0, v: 0, stop: true, turbo: false, parent: $(gallery, "parent")});
		gallery.from = gallery.to = gallery.parent.scrollLeft;
		
		var btns = $(id, 'div', 1);
		var btnLeft = $(btns, 'span', 0), btnRight = $(btns, 'span', 1);
		btnLeft.onmousedown = btnRight.onmousedown = function () { gallery.turbo = true; }
		btnLeft.onmouseup = btnLeft.onmouseout = 
		btnRight.onmouseup = btnRight.onmouseout = function () { gallery.turbo = false; }

		gallery.checkButtons = function () {
			var tLeft = "left" + (gallery.v < 0 && gallery.turbo ? " turbo" : "") + (gallery.from == 0 ? " pause" : "");
			if (tLeft != btnLeft.className) { btnLeft.className = tLeft; }
			var tRight = "right" + (gallery.v > 0 && gallery.turbo ? " turbo" : "") + (gallery.from == width ? " pause" : "");
			if (tRight != btnRight.className) { btnRight.className = tRight; }
		}
		
		gallery.onmousemove = gallery.onmouseover = btns.onmousemove = btns.onmouseover = function (_e) {
			var e = $event(_e);
			var ofs = mousePos(e, $(id));
			if (ofs.x < 70) {
				gallery.to = 0;
				gallery.stop = false;
			} else if (ofs.x > 640) {
				gallery.to = width;
				gallery.stop = false;
			} else {
				gallery.stop = true;
			}
		}
		
		gallery.onmouseout = btns.onmouseout = function (e) {
			if (mouseIsOut(e, gallery) && mouseIsOut(e, btns)) {
				gallery.stop = true;
			}
		}
		gallery.moveTo = function (i) {
			gallery.stop = false;
			gallery.turbo = true;
			gallery.to = i * 180 - 270;
			if (gallery.to > width)
				gallery.to = width;
			if (gallery.to < 0)
				gallery.to = 0;
		}
		Galleries[Galleries.length] = gallery;
	}
	for (var i = 0; i < num; i++) {
		var lnk = $(thumbs[i], 'a', 0);
		thumbs[i].image = false;
		thumbs[i].imgsrc = lnk.href;
		lnk.num = i;
		var timg = $(lnk, 'img', 0);
		timg.onload = function() {
			var h = this.getSize().size.y;
			this.style.marginTop = (h == 0 ? 0 : ((120 - h) / 2) + 'px');
			this.onload = Function.empty;
		}
		if (timg.complete && $browser.opera) {
			timg.onload();
		}
		lnk.onclick = function() {
			gallery.openPic(this.num);
			return false;
		}
	}
	$extend(picholder, {
		change: function (el) {
			var timg = $(this, "*");
			if (timg.length > 0) {
				this.removeChild(timg[0]);
			}
			this.appendChild(el);
			this.open();
		},
		open: function () {
			this.parent.replaceEffect("height", 500, this.getSize().size.y + 10);
		},
		close: function () {
			this.parent.replaceEffect("height", 500, 0);
		}
	});
	
	$extend(gallery, {
		openPic: function (i) {
			if (i < 0 || i >= this.num) {
				return;
			}
			var curThumb = thumbs[i];
			if (i == gallery.cur) {
				this.closePic();
				return;
			}
			this.changeCur(i);
			if (curThumb.image) {
				picholder.change(curThumb.image);
			} else {
				curThumb.startLoad();
				var timg = $c("img", {
					onload: function () {
						curThumb.stopLoad();
						curThumb.image = this;
						if (i == gallery.cur) {
							picholder.change(this);
						}
						this.onload = Function.empty;
					},
					src: curThumb.imgsrc
				});
				if ($browser.opera) {
					if (timg.complete) {
						timg.onload();
					} else {
						setTimeout(function () { timg.onload(); }, 3000);
					}
				}
			}
			return false;
		},
		closePic: function () {
			this.changeCur(-1);
			picholder.close();
		},
		changeCur: function(i) {
			if (i == this.cur) { return; }
			if (this.cur != -1) { thumbs[this.cur].className = ""; }
			if (i != -1) { thumbs[i].className = "selected"; }
			this.cur = i;
		}
	});
	
	var pBtns = $(id, 'div', 2, 'div', 0);
	var pLRBtn = $(pBtns, 'span', 0), pCloseBtn = $(pBtns, 'span', 1);

	picholder.parent.onmouseover = picholder.parent.onmousemove = function (_e) {
		if (gallery.cur == -1) return;
		pBtns.style.display = '';
		var e = $event(_e);
		var ofs = mousePos(e, picholder), tcn, tt;
		if (ofs.x > 345) {
			tcn = (gallery.cur == num - 1 ? 'none' : 'right');
			tt = (gallery.cur == num - 1 ? '' : 'Показать следующую');
		} else {
			tcn = (gallery.cur == 0 ? 'none' : 'left');
			tt = (gallery.cur == num - 1 ? '' : 'Показать предыдущую');
		}
		if (tcn != pLRBtn.className) { pLRBtn.className = tcn; }
		if (tt != picholder.parent.title) { picholder.parent.title = tt; }
	}
	
	picholder.parent.onmouseout = function () {
		if (gallery.cur == -1) return;
		pBtns.style.display = 'none';
	}
	
	picholder.onclick = pLRBtn.onclick = function (_e) {
		if (gallery.cur == -1) return;
		var e = $event(_e), ofs = mousePos(e, picholder);
		if (ofs.x > 345) {
			gallery.openPic(gallery.cur + 1);
		} else {
			gallery.openPic(gallery.cur - 1);
		}
		gallery.moveTo(gallery.cur);
		this.parent.onmousemove(e);
	}
	
	pCloseBtn.onclick = function () { gallery.closePic(); }
}

$extend($Element.Methods, {
	startLoad: function () {
		if (!this.loading) {
			this.style.position = 'relative';
			this.loadSpan = $c('span', {className: 'loading'});
			this.loading = true;
			this.appendChild(this.loadSpan);
		}
	},
	stopLoad: function () {
		if (this.loading) {
			this.loading = false;
			this.style.position = '';
			this.removeChild(this.loadSpan);
		}
	},
	insertPrev: function(el) {
		$(this, "parent").insertBefore(el, this);
	},
	changeTag: function(tag) {
		var prop = {};
		if (arguments.length > 1)
			prop = arguments[1];
		var el = $c(tag, prop, this.innerHTML);
		this.insertPrev(el);
		this.remove();
		return el;
	},
	slideIn: function(isIn) {
		if (typeof isIn == "undefined") { isIn = (this.style.display == "none"); };
		var h = 0;
		if (!isIn) { h = this.getSize().size.y; }
		var cont = $c('span');
		$extend(cont.style, {
			display: 'block',
			overflow: 'hidden',
			height: h
		});
		this.insertPrev(cont);
		this.remove();
		cont.appendChild(this);
		this.style.display = '';
		if (isIn) { h = this.getSize().size.y; }
		cont.addEffect("height", 500, isIn ? 0 : h, isIn ? h : 0);
		this.slide = cont;
	},
	reverseSlide: function (isIn) {
		if (this.slide) {
			this.slide.reverseEffect();
		} else {
			this.slideIn(typeof isIn == "undefined" ? this.style.display == "none" : isIn);
		}
	}
});

$extend(String.prototype, {
	isNatural: function() {
		return ((this.indexOf(".") == -1) && (this.indexOf("-") == -1) && ((this - 1) + 1 == this));
	}
});

function vote(id, isPlus, obj, url) {
	var rating = $(obj, "parent");
	var voters = $(rating, "a");
	var rater = $("post" + id + "rating");
	if (typeof url == "undefined") {
		url = ajaxUrl();
	}
	rater.startLoad();
	var plusminus = (isPlus ? 'plus' : 'minus');
	voters = [
		voters[0].changeTag("span", {className: "btn btn-minus", title: "-"}),
		voters[1].changeTag("span", {className: "btn btn-plus", title: "+"})
	];
	var rData = { 'post_id' : id };
	rData['post_rating_' + plusminus] = true;
	$ajax.request({
		'url': url,
		data: rData,
		onSuccess: function (code, raw) {
			rater.stopLoad();
			if (code == null) {
				alert('Server error:' + raw);
			} else {
				if (code.error) {
					alert(code.errorText);
				} else {
					rater.innerHTML = eval(rater.innerHTML + (isPlus ? '+' : '-') + '1');
					rating.className = 'rating rating-' + plusminus;
					$(voters[isPlus ? 1 : 0], "img", 0).src = '/images/' + plusminus + '-v.gif';
				}
			}
		}
	});
	return false;
}

function cVote(obj, id, pm) {
	var votes = $(obj, "parent", "span", 0);
	var rData = {
		vote_comment: 1,
		how_vote: (pm == "+" ? 1 : -1),
		comment_id: id
	};
	$ajax.request({
		url: ajaxUrl(),
		data: rData,
		onSuccess: function(code, raw) {
			if (code == null) {
				alert('Server error:' + raw);
			} else {
				if (code.error) {
					alert(code.errorText);
				} else {
					votes.innerHTML = eval(votes.innerHTML + pm + "1");
				}
			}
		}
	});
	return false;
}

function ajaxUrl() { return '/l' + window.location.pathname; }

function $post(url, obj) {
	if (typeof url == "object") {
		obj = url;
		url = window.location.pathname;
	}
	var innForm = '';
	for (var i in obj) {
		innForm += '<input type="hidden" name="' + i + '" value="' + obj[i] + '" />';
	}
	var postForm = $c('form', { method: "post", action: url}, innForm);
	postForm.style.display = 'none';
	document.body.appendChild(postForm);
	postForm.submit();
	return false;
}

function $post_ajax(url, obj) {
	if (typeof url == "object") {
		obj = url;
		url = ajaxUrl();
	}
	$ajax.request({
		'url': url,
		data: obj,
		onSuccess: function (code, raw) { if (code == null) { log("server error: " + raw); } else { if (code.error) { log("error: " + code.errorText); } else { if (code.text) { log("success: " + code.text); } else { log("success"); } } } }
	});
	return false;
}

function openNav() {
	var nav = $('navList');
	var vars = $(nav, "ul", 0, "li");
	var x = 0;
	for (var i in vars) {
		if (vars[i].className == "selected") {
			x = - i * 25 - 1;
		}
	}
	$extend(nav, {
		onmouseover: function () {
			this.className = "hover";
			this.style.marginTop = x + "px";
		},
		onmouseout: function () {
			this.className = "";
			this.style.marginTop = 0;
		}
	});
	nav.onmouseover();
	return false;
}

function modelSelector(parent, child, url, dflt) {
	parent = $(parent);
	child = $(child);
	var mark = parent.options[parent.selectedIndex].value;
	if (mark == "") {
		child.clearOptions();
		return;
	}
	if (!$isdef(url)) url = "/l/auto_a/mark/";
	if (!$isdef(dflt)) dflt = "";
	parent.disabled = true;
	$ajax.request({
		"url": url + mark,
		method: "get",
		cache: true,
		onSuccess: function (data, raw) {
			if (data == null) {
				alert("Server error: " + raw);
			} else {
				child.clearOptions();
				child.appendOption(dflt, "");
				for (var i in data) {
					child.appendOption(data[i].real_name, i);
				}
			}
			parent.disabled = false;
		}
	});
}

function yearSelect(obj, year) {
	obj = $(obj);
	selectedYear = obj.options[obj.selectedIndex].value;
	obj.clearOptions();
	obj.appendOption("", "");
	var maxYear = (new Date()).getFullYear();
	if (year == "") {
		year = 1885;
	}
	for (var i = maxYear; i >= year; i--) {
		obj.appendOption(i, i);
	}
	if (selectedYear != "" && selectedYear >= year) {
		obj.selectOption(maxYear - selectedYear + 1);
	}
}

var grZin = 100;
function openGroup(obj) {
	var group = $(obj, "parent", "parent");
	var effect = new $effect2.empty();
	group.isGrOpen = false;
	var cont = $c('span', {style: {display: 'block', overflow: 'hidden', height: 0}});
	var models = $(group, "p", 0);
	models.insertPrev(cont);
	group.className += ' markContent-full';
	var h = models.getSize().size.y;
	models.remove();
	cont.appendChild(models);
	group.grOpen = function () {
		if (!this.isGrOpen) {
			this.isGrOpen = true;
			$(group, "parent").style.zIndex = grZin++;
			group.className = "markContent markContent-full markContent-open";
			effect.stop();
			effect = new $effect2.create({object: cont, params: {height: {to: models.getSize().size.y}}}, 500);
			effect.start();
		}
		return false;
	}
	group.grClose = function () {
		if (this.isGrOpen) {
			this.isGrOpen = false;
			group.className = "markContent markContent-full";
			effect.stop();
			effect = new $effect2.create({object: cont, params: {height: {to: 0}}}, 500);
			effect.start();
		}
		return false;
	}
	group.grReOpen = function () {
		if (this.isGrOpen) {
			effect.stop();
			effect = new $effect2.create({object: cont, params: {height: {to: models.getSize().size.y}}}, 500);
			effect.start();
		}
	};
	group.grOpen();
	obj.onmouseover = function() { group.grOpen(); };
	group.onmouseout = function(_e) {
		if (mouseIsOut(_e, this)) {
			this.grClose();
		}
	};
	return false;
}

function openShitModels(obj, id) {
	var group = $(obj, "parent", "parent", "parent", "parent");
	toggle(id + "_true", id + "_shit");
	group.grReOpen();
	return false;
}

function defineMarkList(list) {
	var lostObj = $(list);
	var list = $(list, "div");
	var listByName = [];
	for (var i in list) {
		var stats = $(list[i], "div", 0, "input", 0).value.split(",");
		
		listByName.push({name: $(list[i], "div", 0, "h3", 0, "a", 0).innerHTML.toLowerCase(), obj: list[i], stats: [parseInt(stats[0]), parseInt(stats[1])] });
	}
	$('groupListSearchName').onkeyup = function () {
		this.replaceEffect(function(t) { if (t == 1) {
			if (this.value == "") {
				for (var i in listByName) {
					listByName[i].obj.style.display = '';
				}
			} else {
				for (var i in listByName) {
					listByName[i].obj.style.display = (listByName[i].name.indexOf(this.value.toLowerCase()) != -1) ? '' : 'none';
				}
			}
		} }, 100);
	}
	$('groupListSearchSort').onchange = function () {
		for (var i in listByName) {
			listByName[i].obj.remove();
		}
		var sortType = this.options[this.selectedIndex].value;
		listByName.sort(function(a, b) { return groupSort(a, b, sortType); });
		for (var i = 0; i < listByName.length; i++) {
			lostObj.appendChild(listByName[i].obj);
		}
	}
}

function groupSort(a, b, type) {
	if (type == -1) {
		if (a.name > b.name) return 1;
		if (a.name < b.name) return -1;
		return 0;
	}
	if (a.stats[type] < b.stats[type]) return 1;
	if (a.stats[type] > b.stats[type]) return -1;
	return groupSort(a, b, -1);
}

function dms(lat, lng) {
	var coords = {
		'lat': { 'pre': (lat > 0 ? "N " : "S "), 'val': Math.abs(lat) },
		'lng': { 'pre': (lng > 0 ? "E " : "W "), 'val': Math.abs(lng) }
	}
	for (var i in coords) {
		coords[i].res = Math.floor(coords[i].val) + "\u00B0 ";
		coords[i].val = (coords[i].val - Math.floor(coords[i].val)) * 60;
		coords[i].res += Math.floor(coords[i].val) + "' ";
		coords[i].val = (coords[i].val - Math.floor(coords[i].val)) * 60;
		coords[i].res += Math.floor(coords[i].val) + '"';
	}
	return coords.lat.pre + coords.lat.res + " " + coords.lng.pre + coords.lng.res;
}

function colorPicker(obj, input) {
	obj = $(obj); input = $(input);
	var tmp = ["0", "5", "a", "f"];
	var current = 0;
	for (var i = 0; i < 64; i++) {
		var color = tmp[Math.floor(i / 16)] + tmp[Math.floor((i % 16) / 4)] + tmp[i % 4];
		var cBox = $c("a", {
			style: { background: "#" + color },
			href: "",
			'color': color,
			num: i,
			onclick: function () {
				$(obj, "a", current).className = "";
				$(obj, "a", this.num).className = "selected";
				current = this.num;
				input.value = this.color;
				return false;
			}
		});
		if (input.value == color) {
			cBox.className = "selected";
			current = i;
		}
		obj.appendChild(cBox);
	}
}

function calendar(obj, iDay, iMonth, iYear) {
	obj = $(obj); iDay = $(iDay); iMonth = $(iMonth); iYear = $(iYear);
	var dayHead = { 1: "Пн", 2: "Вт", 3: "Ср", 4: "Чт", 5: "Пт", 6: "Сб", 7: "Вс" };
	var dayClass = { 1: "mo", 2: "tu", 3: "we", 4: "th", 5: "fr", 6: "st", 7: "su" };
	var monthHead = { 1: "Январь", 2: "Февраль", 3: "Март", 4: "Апрель", 5: "Май", 6: "Июнь", 7: "Июль", 8: "Август", 9: "Сентябрь", 10: "Октябрь", 11: "Ноябрь", 12: "Декабрь"};
	var curDay = "", curMonth = "", curYear = "";
	var updateInput = function () {
		iDay.value = curDay;
		iMonth.value = curMonth;
		iYear.value = curYear;
	}
	var clearInput = function () {
		iDay.value = iMonth.value = iYear.value = "";
	}
	var tmpDate = new Date(eval(iYear.value), eval(iMonth.value + "-1"), eval(iDay.value));
	if (tmpDate.getTime() > 0) {
		curDay = tmpDate.getDate();
		curMonth = tmpDate.getMonth() + 1;
		curYear = tmpDate.getFullYear();
		updateInput();
	} else {
		tmpDate = new Date();
		curDay = -1;
		curMonth = tmpDate.getMonth() + 1;
		curYear = tmpDate.getFullYear();
		clearInput();
	}
	var changeMonthObj = $c("div", {className: "month"});
	changeMonthObj.appendChild($c("a", {
		href: "",
		className: "btnPrev",
		onclick: function () {
			curMonth--;
			if (curMonth < 1) {
				curMonth = 12;
				curYear--;
			}
			obj.showMonth();
			return false;
		}
	}, "&lt;"));
	changeMonthObj.monthObj = $c("span");
	changeMonthObj.appendChild(changeMonthObj.monthObj);
	changeMonthObj.appendChild($c("a", {
		href: "",
		className: "btnNext",
		onclick: function () {
			curMonth++;
			if (curMonth > 12) {
				curMonth = 1;
				curYear++;
			}
			obj.showMonth();
			return false;
		}
	}, "&gt;"));
	obj.appendChild(changeMonthObj);
	var tableObj = $c("div");
	obj.appendChild(tableObj);
	obj.showMonth = function () {
		changeMonthObj.monthObj.innerHTML = monthHead[curMonth] + " " + curYear;
		var table = $c('table');
		var head = table.insertRow(0);
		for (var j = 1; j < 8; j++) {
			$extend(head.insertCell(j-1), {
				className: "head " + dayClass[j],
				innerHTML: "<span>" + dayHead[j] + "</span>"
			});
		}
		var days = [];
		var current = 1;
		var week = 1, curWeek = table.insertRow(1);
		for (var i = 1; i < 33; i++) {
			var day = new Date(curYear, curMonth - 1, i);
			day.dayOfWeek = day.getDay();
			day.dayOfWeek = (day.dayOfWeek == 0 ? 7 : day.dayOfWeek);
			if (i == 1) {
				for (var j = 1; j < day.dayOfWeek; j++) {
					var sp = curWeek.insertCell(j-1);
					sp.className = dayClass[j];
					sp.innerHTML = "<span></span>";
				}
			} else if (day.getMonth() != curMonth - 1) {
				if (day.dayOfWeek == 1) break;
				for (var j = day.dayOfWeek; j < 8; j++) {
					var sp = curWeek.insertCell(j-1);
					sp.className = dayClass[j];
					sp.innerHTML = "<span></span>";
				}
				break;
			}
			var dayLnk = $c("a", {
				href: "",
				onclick: function () {
					curDay = this.innerHTML;
					updateInput();
					days[current].className = "";
					days[this.innerHTML].className = "selected";
					current = this.innerHTML;
					return false;
				}
			}, i);
			if (iDay.value == i && iMonth.value == curMonth && iYear.value == curYear) {
				dayLnk.className = "selected";
				current = i;
			}
			days[i] = dayLnk;
			var dayTd = curWeek.insertCell(day.dayOfWeek - 1);
			dayTd.className = dayClass[day.dayOfWeek];
			dayTd.appendChild(dayLnk);
			if (day.dayOfWeek == 7) {
				week++;
				curWeek = table.insertRow(week);
			}
		}
		tableObj.innerHTML = "";
		tableObj.appendChild(table);
	}
	obj.showMonth();
}

function openHelp(tip) {
	if (!$isdef(tip)) {
		tip = "helpTip";
	}
	tip = $(tip);
	if (tip.idEffect) {
		tip.reverseEffect();
	} else {
		tip.replaceEffect('height', 500, $(tip, 'div', 0).getSize().size.y + 10);
	}
	return false;
}

function formCheck() {
	if (arguments.length < 2)
		return true;
	var form = arguments[0];
	var inputs = arguments[1];
	var alrt = arguments.length > 2 ? arguments[2] : false;
	for (var i in inputs) {
		var a = inputs[i];
		var v = form[i].value;
		var err = a.text ? a.text : "Ошибка";
		var len_err = a.len_text ? a.len_text : err;
		var line_err = a.line_text ? a.line_text : err;
		if (a.maxlen ? v.length > a.maxlen : false) {
			return formChechError(a.maxlen_text ? a.maxlen_text : len_err, a.hint, alrt);
		}
		if (a.minlen ? v.length < a.minlen : false) {
			return formChechError(a.minlen_text ? a.minlen_text : len_err, a.hint, alrt);
		}
		if (a.maxline ? v.split("\n").length > a.maxline : false) {
			return formChechError(a.maxline_text ? a.maxline_text : line_err, a.hint, alrt);
		}
		if (a.minline ? v.split("\n").length < a.minline : false) {
			return formChechError(a.minline_text ? a.minline_text : line_err, a.hint, alrt);
		}
		if (a.chars) {
			for (var j = 0; j < v.length; j++) {
				if (a.chars.indexOf(v.charAt(j)) == -1) {
					return formChechError(a.chars_text ? a.chars_text : err, a.hint, alrt);
				}
			}
		}
		if (a.check ? form[i].checked != a.check : false) {
			return formChechError(a.check_text ? a.check_text : err, a.hint, alrt);
		}
		if (a.natural ? !v.isNatural() : false) {
			return formChechError(a.natural_text ? a.natural_text : err, a.hint, alrt);
		}
		if (a.select ? form[i].selectedIndex == 0 : false) {
			return formChechError(a.select_text ? a.select_text : err, a.hint, alrt);
		}
	}
	return true;
}

function formChechError(text, hint, alrt) {
	if (!$isdef(text))
		return false;
	if ($isdef(hint)) {
		$(hint).innerHTML = text;
	}
	if ($isdef(alrt)) {
		if (alrt)
			alert(text);
	}
	return false;
}

function openPostMenu(obj) {
	var menu = $(obj, "parent");
	menu.className = (menu.className == "postMenu" ? "postMenu postMenu-open" : "postMenu");
	return false;
}

function pleaseLogin() {
	alert("Пожалуйста, авторизуйтесь или зарегистрируйтесь.");
	return false;
}

function zoomImage(obj) {
	obj.target = "_blank";
	return true;
}