var currentid=0;

function ShowCommentForm(parentid, commenttype, showrate) {
	getElm('commentAddStatus').style.display='none';
	getElm('parentid').value=parentid;
	getElm('commenttype').value=commenttype;
	getElm('commentAdd').style.display='block';
	if(!showrate) {
		getElm('ratingmarks').style.display='none';
		if(getElm('comment'+currentid)) {
			getElm('comment'+currentid).className='commtext';
		}
		currentid = parentid;
		if(getElm('comment'+currentid)) {
			getElm('comment'+currentid).className='commtextsel';
		}
		getElm('commentto').innerHTML="Ответ на выбранный отзыв";
	} else {
		if(getElm('comment'+currentid)) {
			getElm('comment'+currentid).className='commtext';
		}
		currentid =0;
		getElm('ratingmarks').style.display='block';
		getElm('commentto').innerHTML="Отзыв о товаре";
	}
	getElm('author').focus();
}

function SetRating(mark) {
	if(getElm('commentrating')) {
		getElm('commentrating').value = mark;
	}
	for(var i=1;i<6; i++) 
	{
		if(getElm('mark'+i)) 
		{
			if(i>mark)
			{
				getElm('mark'+i).src = 'http://at-communication.com/gfx/rating/empty.gif';
			}
			else 
			{
				getElm('mark'+i).src = 'http://at-communication.com/gfx/rating/full.gif';
			}
		}
	}
}

function AddWIComment(lang) {
	getElm('commentAdd').style.display='none';
	getElm('ratingmarks').style.display='none';
	getElm('commentAddStatus').innerHTML = "<br />Идёт отправка отзыва...";
	getElm('commentAddStatus').style.display='block';
	JsHttpRequest.query(
	'/backend.php?type=wicomment&action=add', 
    {
		'commentName': getElm('author').value, 
		'commentText': getElm('newcomment').value,
		'commentType': getElm('commenttype').value,
		'parentID': getElm('parentid').value,
		'WItemID': getElm('witemid').value,
		'lang': lang,
		'commentRating': getElm('commentrating').value
		
	},
  
    function(result, errors) {
		getElm('commentAdd').style.display='none';
		getElm('ratingmarks').style.display='none';
		getElm('commentto').innerHTML=" ";
		if(result['output'])  {
			getElm('commentAddStatus').innerHTML = "<br />"+result['output'];
			getElm('commentAddStatus').style.display='block';
		}
	},
    true
    );
}

/* функции для работы с полным списком комментариев */
function invCommBlock(BlockType, BlockID)
{
	if(getElm(BlockType+'_'+BlockID) && getElm('a_'+BlockType+'_'+BlockID)) 
	{
		if(getElm('a_'+BlockType+'_'+BlockID).src.indexOf('hide')>1) 
		{
			getElm(BlockType+'_'+BlockID).style.display = 'none';
			getElm('a_'+BlockType+'_'+BlockID).src = 'http://at-communication.com/gfx/show.gif';
			getElm('a_'+BlockType+'_'+BlockID).alt = 'показать';
			getElm('a_'+BlockType+'_'+BlockID).title = 'показать';
		}
		else
		{
			getElm(BlockType+'_'+BlockID).style.display = 'block';
			getElm('a_'+BlockType+'_'+BlockID).src= 'http://at-communication.com/gfx/hide.gif';
			getElm('a_'+BlockType+'_'+BlockID).alt = 'скрыть';
			getElm('a_'+BlockType+'_'+BlockID).title = 'скрыть';			
		}
	}
}

function hideCommBlocks()
{
	var Imgs = new Array;
	Imgs = document.images;
	for(var i=0; i<Imgs.length; i++)
	{
		if(Imgs[i].className=='commpm') 
		{
			Imgs[i].src='http://at-communication.com/gfx/show.gif';
			Imgs[i].alt='показать';
			Imgs[i].title='показать';
			if(getElm(Imgs[i].id.replace('a_',''))) 
			{
				getElm(Imgs[i].id.replace('a_','')).style.display='none';
			}
		}
	}
}