var photoalbum = function(json)
{
	this.photoobj = json;
	this.photos = [];
	this.alts = [];
	this.counter = 0;
	this.total = 0;
	this.title = '';
	var self = this;

	for (var i in this.photoobj)
	{
		var tmpphoto = new Image();
		tmpphoto.src = 'http://golosmsk.ru/images/photo/500/' + this.photoobj[i].id + '.' + this.photoobj[i].type;
		tmpphoto.alt = this.photoobj[i].alt;
		tmpphoto.title = this.photoobj[i].alt;
		this.photos.push(tmpphoto);
		this.alts.push(this.photoobj[i].alt);
		if (this.photoobj[i].current == 1) this.counter = i.replace(/ph/, '');
		this.total ++;
	}

	this.init = function()
	{
		var container = document.getElementById('maincontent');
		var spans = container.getElementsByTagName('SPAN');
		this.title = container.getElementsByTagName('B')[0];
		if (this.counter != 0)
		{
			spans[0].onclick = this.previmg;
			spans[0].className = 'activ';
		}
		if (this.total > 1)
		{
			spans[1].onclick = this.nextimg;
			spans[1].className = 'activ';
		}

		if ((this.counter >= 0 && this.counter <= this.total) && typeof this.photos[this.counter] != 'undefined')
		{
			container.appendChild(this.photos[this.counter].cloneNode(true));
			this.title.innerHTML = this.alts[this.counter];
		}
		document.oncontextmenu = function() {window.close();}
	}

	this.previmg = function()
	{
		if (self.counter > 0) self.counter --;

		var container = document.getElementById('maincontent');
		var spans = container.getElementsByTagName('SPAN');

		if (self.counter > 0)
		{ spans[0].className = 'activ';}
		else {spans[0].className = 'deactiv';}

		if (self.counter < self.total - 1)
		{ spans[1].className = 'activ';}
		else {spans[1].className = 'deactiv';}

		document.images[0].src = self.photos[self.counter].src;
		document.images[0].width = self.photos[self.counter].width;
		document.images[0].height = self.photos[self.counter].height;
		document.images[0].alt = self.alts[self.counter];
		self.title.innerHTML = self.alts[self.counter];
	}

	this.nextimg = function()
	{
		if (self.counter < self.total) self.counter ++;

		var container = document.getElementById('maincontent');
		var spans = container.getElementsByTagName('SPAN');

		if (self.counter > 0)
		{ spans[0].className = 'activ';}
		else {spans[0].className = 'deactiv';}

		if (self.counter < self.total - 1)
		{ spans[1].className = 'activ';}
		else {spans[1].className = 'deactiv';}
		if (!self.photos[self.counter]) return;
		document.images[0].src = self.photos[self.counter].src;
		document.images[0].width = self.photos[self.counter].width;
		document.images[0].height = self.photos[self.counter].height;
		document.images[0].alt = self.alts[self.counter];
		self.title.innerHTML = self.alts[self.counter];
	}
}

function checkerrorform(oForm)
{
	if (oForm.message.value == '')
	{
		alert('Заполните обязательное поле');
		oForm.message.focus();
		return false;
	}
	return true;
}

function checkpriceform(oForm)
{
	if (oForm.name.value == '')
	{
		alert('Заполните обязательное поле');
		oForm.name.focus();
		return false;
	}
	return true;
}


function checkcommentform(oForm)
{
	if (oForm.name.value == '')
	{
		alert('Заполните обязательные поля');
		oForm.name.focus();
		return false;
	}
	else if (oForm.message.value == '')
	{
		alert('Заполните обязательные поля');
		oForm.message.focus();
		return false;
	}
	return true;
}

function switchazsrating(oSelect)
{
	var order = oSelect.options[oSelect.selectedIndex].value;
	if (order == 'top')
	{
		G('#azstoplist').style.display = 'block';
		G('#azsbotlist').style.display = 'none';
	}
	else
	{
		G('#azstoplist').style.display = 'none';
		G('#azsbotlist').style.display = 'block';
	}
}

function switchazsprice(oSelect)
{
	var order = oSelect.options[oSelect.selectedIndex].value;
	if (order == 'top')
	{
		G('#azsbestprice').style.display = 'block';
		G('#azsbadprice').style.display = 'none';
	}
	else
	{
		G('#azsbestprice').style.display = 'none';
		G('#azsbadprice').style.display = 'block';
	}
}

function switchazsrating(oSelect)
{
	var order = oSelect.options[oSelect.selectedIndex].value;
	if (order == 'top')
	{
		G('#azstoplist').style.display = 'block';
		G('#azsbotlist').style.display = 'none';
	}
	else
	{
		G('#azstoplist').style.display = 'none';
		G('#azsbotlist').style.display = 'block';
	}
}

function replaceform(linkobj, id)
{
	var fobj = document.getElementById('commentform');
	var name = G('#name' + id).innerHTML;
	G('textarea', fobj)[0].value = name + ', ';
	if (fobj.parentNode.className == 'box1_bg')
	{
		id = parseInt(id);
		var currentDiv = linkobj.parentNode.parentNode;
		var commentsContainer = currentDiv.parentNode;
		var nextDiv = nextNode(currentDiv);
		var closeDiv = nextNode(nextDiv);
		if (!nextDiv) commentsContainer.appendChild(fobj);
		else nextDiv.appendChild(fobj);
		fobj.action = '?comment=' + id;
		nextDiv.style.display = 'block';
		closeDiv.style.display = 'block';
		document.getElementById('addcommentform').style.display = 'none';
	}
	else if (fobj.parentNode.className == 'comments_answer')
	{
		id = parseInt(id);
		nextNode(fobj.parentNode).style.display = 'none';
		fobj.parentNode.style.display = 'none';
		var currentDiv = linkobj.parentNode.parentNode;
		var commentsContainer = currentDiv.parentNode;
		var nextDiv = nextNode(currentDiv);
		var closeDiv = nextNode(nextDiv);
		if (!nextDiv) commentsContainer.appendChild(fobj);
		else nextDiv.appendChild(fobj);
		fobj.action = '?comment=' + id;
		nextDiv.style.display = 'block';
		closeDiv.style.display = 'block';
	}
}

function closecommentform(oImg)
{
	var currDiv = oImg.parentNode;
	currDiv.style.display = 'none';
	var prevDiv = prevNode(currDiv);
	prevDiv.style.display = 'none';
	var oForm = prevDiv.getElementsByTagName('FORM')[0];
	oForm.action = '?comment=0';
	var root = G('#addcommentform');
	root.style.display = 'block';
	var fcontainer = G('div', root)[1];
	fcontainer.appendChild(oForm);
	G('textarea', oForm)[0].value = '';
}

function cancel()
{
	var oTd = document.getElementById('addformtd');
	var oForm = document.getElementById('commentform');
	oForm.action = '?comment=0';
	oTd.appendChild(oForm);
	var addformdiv = document.getElementById('addcommentform');
	addformdiv.style.display = 'block';
}

function nextNode(node)
{
	var next = node.nextSibling;
	if (!next) return false;
	return next.nodeType == 1 ? next : nextNode(next);
}

function prevNode(node)
{
	var prev = node.previousSibling;
	if (!prev) return false;
	return prev.nodeType == 1 ? prev : prevNode(prev);
}

window.onload = function()
{
	var sOkrug = G('#searchbyokrug') || false;
	if (!!sOkrug) sOkrug.onchange = searchByOkrug;
}

function searchByOkrug()
{
	document.location = '/azs/search/okrug/'+this.options[this.selectedIndex].value+'/';
}

var voting = function(container, module, place)
{
	this.container = container;
	this.place = place;
	this.imgcontainer = G('div', this.container)[0];
	this.activeImgSrc = '/images/voting/star1.gif';
	this.inactiveImgSrc = '/images/voting/star0.gif';
	this.module = module;
	this.numVoters = G('#'+this.module+'numvoters') || null;
	this.sevBall = G('#'+this.midule+'sevball') || null;

	this.activeImgObj = new Image();
	this.activeImgObj.src = this.activeImgSrc;

	this.inactiveImgObj = new Image();
	this.inactiveImgObj.src = this.inactiveImgSrc;

	this.cfg = null;
	var self = this;

	this.init = function()
	{
		var req = getrequestobj();
		req.open('get', '/modules/voting.php?module='+this.module+'&id='+this.place);
		req.onreadystatechange = function()
		{
			if (req.readyState != 4 || req.status != 200) return false;
			self.cfg = eval('(' + req.responseText + ')');
			req.abort();
			for (var i=0; i<5; i++)
			{
				var img = i < self.cfg.intBall ? self.activeImgObj.cloneNode(true) :
				self.inactiveImgObj.cloneNode(true);
				img.id = 'vote-' + self.module + '-' + i;
				if (self.cfg.disabled == 0)
				{
					img.onmouseover = self.reDraw;
					img.onmouseout = self.reStore;
					img.onclick = self.vote;
					img.style.cursor = 'pointer';
				}
				self.imgcontainer.appendChild(img);
			}
			if (!!self.sevBall)
			self.sevBall.innerHTML = self.cfg.ball;
			if (!!self.numVoters)
			self.numVoters.innerHTML = self.cfg.voters;
		};
		req.send(null);
	}

	this.reStore = function()
	{
		var num = self.cfg.intBall;
		self.fill(num);
	}

	this.reDraw = function()
	{
		var num = parseInt(this.id.replace(/.*?(\d)$/, '$1')) + 1;
		self.fill(num);
	}

	this.fill = function(num)
	{
		var img = G('img', self.imgcontainer);
		for (var i=0; i<5; i++)
		img[i].src = i < num? self.activeImgSrc : self.inactiveImgSrc;
	}

	this.vote = function()
	{
		var mark = parseInt(this.id.replace(/.*?(\d)$/, '$1')) + 1;
		var req = getrequestobj();
		req.open('get', '/modules/voting.php?module='+self.module+'&id='+self.place+'&mark='+mark);
		req.onreadystatechange = function()
		{
			if (req.readyState != 4 || req.status != 200) return false;
			self.cfg = eval('(' + req.responseText + ')');
			var img = G('img', self.imgcontainer);
			for (var i=0; i<5; i++)
			{
				img[i].src = i < self.cfg.intBall ? self.activeImgSrc : self.inactiveImgSrc;

				img[i].onmouseover = null;
				img[i].onmouseout = null;
				img[i].onclick = null;
				img[i].style.cursor = 'auto';
			}
			if (!!self.sevBall)
			self.sevBall.innerHTML = self.cfg.ball;
			if (!!self.numVoters)
			self.numVoters.innerHTML = self.cfg.voters;
		};
		req.send(null);
	}
}

function G(selector, container)
{
	container = container || document;
	selector = selector.replace(/\s/, '');
	//смотрим, есть ли последовательность элтов
	var isSequence = selector.indexOf('>');
	var dotNum = selector.indexOf('.');
	var cellNum = selector.indexOf('#');
	if (isSequence != -1)
	{
		var parentSelector = selector.substr(0, isSequence);
		var childSelector = selector.substr(isSequence);
		var elements = G(parentSelector, container) || false;
		if (!elements) return false;
		var count = elements.length || false;
		if (!count) return false;
		for (var i=0; i<count; i++)
		{}
		return false;
	}
	if (/^(\*|[a-z0-9]+)$/i.test(selector))
	{
		return container.getElementsByTagName(selector.toUpperCase());
	}
	else if (dotNum != -1)
	{
		var el = selector.substr(0, dotNum);
		el = el == ''?'*':el;
		var clname = selector.substr(dotNum);
		var elements = container.getElementsByTagName(el.toUpperCase()) || false;
		if (!elements) return false;
		var count = elements.length || false;
		if (!count) return false;
		var array = [];
		for (var i=0; i<count; i++)
		{
			if (elements[i].className == clname) array.push(elements[i]);
		}
		return array;
	}
	else if (cellNum != -1)
	{
		return document.getElementById(selector.substr(cellNum + 1));
	}
	return false;
}

var getrequestobj = function()
{
	if (window.ActiveXObject)
	{
		getrequestobj = function()
		{return new ActiveXObject("Microsoft.XMLHTTP");}
	}
	else
	{
		getrequestobj = function()
		{return new XMLHttpRequest;}
	}
	return getrequestobj();
}

function winopen(url, w, h)
{
	Win = open(url, "displayWindow", "width="+w+",height="+h+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
	Win.focus();
}

function hide(iEl)
{
	var oEl = document.getElementById(iEl) || false;
	if (!oEl) return false;
	oEl.style.display = oEl.style.display == 'none' ? 'block' : 'none';
}

function changeSearch(oForm, oSelect)
{
    if (oSelect.options[oSelect.selectedIndex].value == 'name')
        oForm.action = '/azs/search/';
    else oForm.action = '/search/';
    return true;
}

<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->