// Рейтинг
function comment_poll(id)
{
  for(i = 1; i <= id; i++)
  {
    document.getElementById('com' + i).src = "/dataimg/catalog/comment_star_full.gif";
  }
  for(i = id + 1; i <= 10; i++)
  {
    document.getElementById('com' + i).src = "/dataimg/catalog/comment_star_empty.gif";
  }
  document.getElementById('comment_mark').value = id;
}
function comment_poll_del(id)
{
  for(i = 1; i <= id; i++)
  {
    document.getElementById('del' + i).src = "/dataimg/catalog/comment_star_full.gif";
  }
  for(i = id + 1; i <= 10; i++)
  {
    document.getElementById('del' + i).src = "/dataimg/catalog/comment_star_empty.gif";
  }
  document.getElementById('comment_mark_del').value = id;
}
// Обработка формы отзыва
function addcomment()
{
  var pattern = /^$/;
  if(document.getElementById('comment_title').value.match(pattern))
  {
    alert('Please fill out the "Title"');
    return false;
  }
  if(document.getElementById('comment_text').value.match(pattern))
  {
    alert('Please fill out the "Write review"');
    return false;
  }
  alert('Your review will be added after checking');
  return true;
}
// Обработка формы ссылки
function addlink()
{
  var pattern = /^$/;
  if(document.getElementById('link_title').value.match(pattern))
  {
    alert('Please fill out the "Title"');
    return false;
  }
  if(document.getElementById('link_link').value.match(pattern))
  {
    alert('Please fill out the "Link"');
    return false;
  }
  if(document.getElementById('link_category').value == 0)
  {
    alert('Please select category links');
    return false;
  }
  if(document.getElementById('link_text').value.match(pattern))
  {
    alert('Please fill out the "Write review"');
    return false;
  }
  alert('Your link will be added after checking');
  return true;
}
// Обработка формы добавления вопроса
function addpost()
{
  var pattern = /^$/;
  if(document.getElementById('post_title').value.match(pattern))
  {
    alert('Please fill out the "Title"');
    return false;
  }
  if(document.getElementById('post_text').value.match(pattern))
  {
    alert('Please fill out the "Write review"');
    return false;
  }
  alert('Your review will be added after checking');
  return true;
}
// Обработка формы добавления ответа
function addanswer()
{
  var pattern = /^$/;
  if(document.getElementById('post_title').value.match(pattern))
  {
    alert('Please fill out the "Title"');
    return false;
  }
  if(document.getElementById('post_text').value.match(pattern))
  {
    alert('Please fill out the "Answer"');
    return false;
  }
  alert('Your review will be added after checking');
  return true;
}
// Читать дальше
function showfullcomment(id_comment)
{
  var linkid = document.getElementById('commentmore_' + id_comment);
  linkid.style.display = 'none';
  var commentid = document.getElementById('fullcomment_' + id_comment);
  commentid.style.display = 'inline';
}
// Читать дальше
function showfulllink(id_link)
{
  var linkid = document.getElementById('linkmore_' + id_link);
  linkid.style.display = 'none';
  var commentid = document.getElementById('fulllink_' + id_link);
  commentid.style.display = 'inline';
}
// Читать дальше
function showfullpost(id_post)
{
  var linkid = document.getElementById('postmore_' + id_post);
  linkid.style.display = 'none';
  var commentid = document.getElementById('fullpost_' + id_post);
  commentid.style.display = 'inline';
}
// Функция отображения и скрытия формы добавления комментариев, ссылок
function id_show(id_comment)
{
  var form = document.getElementById(id_comment);
  if(form.style.visibility == 'hidden')
  {
    form.style.visibility = 'visible';
    form.style.display = 'block';
  }
  else
  {
    form.style.visibility = 'hidden';
    form.style.display = 'none';
  }
}
// Удалить
function comment_delete(id_comment)
{
  if(confirm("You want to remove your review?"))
  {
    bhv.sendRequest('get', 
                    '/user/user.comments.manage.php',
                    '&manage=delete&id_comment=' + id_comment,
                    true,
                    function(){document.getElementById('commentchange').innerHTML = this.responseText;},
                    null);
  }
  return false;
}
// Редактировать
function comment_edit(id_comment)
{
  bhv.sendRequest('get', 
                  '/user/user.comments.edit.php',
                  '&id_comment=' + id_comment,
                  true,
                  function(){document.getElementById('comment' + id_comment).innerHTML = this.responseText;},
                  null);
}
// Сохранение отредактированного сообщения
function comment_save(id_comment)
{
  // Формируем список параметров
  var parameters = '&id_comment=' + id_comment;
  parameters += '&manage=edit';
  parameters += '&name=' + document.getElementById('comment_title' + id_comment).value
  parameters += '&comment=' + document.getElementById('comment_text' + id_comment).value
  parameters += '&mark=' + document.getElementById('comment_mark').value
  parameters = encodeURI(parameters);
  // Отправляем асинхронный запрос
  bhv.sendRequest('get', 
                  '/user/user.comments.manage.php', 
                  parameters,
                  true,
                  function(){document.getElementById('commentchange').innerHTML = this.responseText;},
                  null);
}
// Отображение ответа
function shop_answer_show(id_comment)
{
  document.getElementById('shop_answer_maximize_' + id_comment).style.display = 'block';
  document.getElementById('shop_answer_minimize_' + id_comment).style.display = 'none';
}
// Сокрытие ответа
function shop_answer_hide(id_comment)
{
  document.getElementById('shop_answer_maximize_' + id_comment).style.display = 'none';
  document.getElementById('shop_answer_minimize_' + id_comment).style.display = 'block';
}