  var AddCommentPopupID = 0;
      
  var commentHeights = new Array();
  var objectStyle;
  
  var loadedComments = new Array();
  
  function showComments(id)
  {
    targetID = id;
    toggler = document.getElementById('addcommentlink_' + id);
    toggler.href = 'javascript: toggleVisibility("addcomment_' + id + '", TOGGLE_OFF); hideComments(' + id + ');';
    document.getElementById('collapser_' + id).href = toggler.href;
    document.getElementById('blogheader_' + id).href = toggler.href;
    
    animObject = document.getElementById('comments_' + id);
    animObject.style.visibility = 'visible';
    if( animObject.offsetHeight == 0 )
      animObject.style.height = commentHeights[id] + 'px';
    else
    {
      commentHeights[id] = animObject.offsetHeight;
      animObject.style.height = animObject.offsetHeight + 'px';
    }
  }
  
  function hideComments(id)
  {
    targetID = id;
    toggler = document.getElementById('addcommentlink_' + id);
    toggler.href = 'javascript: toggleVisibility("addcomment_' + id + '", TOGGLE_ON);  showComments(' + id + ');';
    document.getElementById('collapser_' + id).href = toggler.href;
    document.getElementById('blogheader_' + id).href = toggler.href;
    
    animObject = document.getElementById('comments_' + id);
    animObject.style.visibility = 'hidden';
    animObject.style.height = '0px';
  }
  
  function loadedComment(id)
  {
    commentsObject = document.getElementById('comments_' + id);
    commentHeights[id] = commentsObject.offsetHeight;
    commentsObject.style.visibility = 'visible';
    
    toggler = document.getElementById('addcommentlink_' + id);
    toggler.href = 'javascript: toggleVisibility("addcomment_' + id + '", TOGGLE_OFF); hideComments(' + id + ');';
    toggler.style.visibility = 'visible';
    document.getElementById('collapser_' + id).href = toggler.href;
    document.getElementById('blogheader_' + id).href = toggler.href;
  }
  
  function loadComments(id)
  {
    var isLoaded = false;

    if( ! isLoaded )
    {
      var thisAjax = new suAjax();
      thisAjax.request('comments.php?id=' + id);
    }
    else
      showComments(id);
  }
  
  function changeCommentPage(id, page)
  {
    var thisAjax = new suAjax('comments.php?id=' + id + '&p=' + page);
    animObject = document.getElementById('comments_' + id);
    animObject.style.height = 'auto';
  }
  
  function showAddCommentPopup(id)
  {
    AddCommentPopupID = id;
    var thisAjax = new suAjax('addcommentpopup.php');
    showpopup(490, 290);
  }
  
  function checkField(idName, value)
  {
    idObject = document.getElementById(idName);
    if( idObject.value == value )
      idObject.value = '';
  }
  
  function incrementBlogCounter(id)
  {
    commentCount = document.getElementById('h_commentCount_' + id);
    commentCount.value++;
    if( commentCount.value == 1 )
      document.getElementById('commentCount_' + id).innerHTML = commentCount.value + ' kommentar';
    else
      document.getElementById('commentCount_' + id).innerHTML = commentCount.value + ' kommentarer';
  }
  
  function addComment(id)
  {
    commentDiv = document.getElementById('addcomment_' + id);
    commentDiv.style.height = '0px';
    commentDiv.style.marginBottom = '0px';
  
    txtName = document.getElementById('txtName_' + id).value;
    txtComment = document.getElementById('txtComment_' + id).value;
    var thisAjax = new suAjax('addcomment.php?name=' + escape(txtName) + '&comment=' + escape(txtComment) + '&id=' + id);
    
    if( commentHeights[id] > 0 )
    {
      var d = new Date();
      
      incrementBlogCounter(id);
      commentSection = document.getElementById('commentlist_' + id);
      commentSection.innerHTML = '' +
      '<div class="blogcomment">' +
      '  <div class="blogcommenttitle">' +
      '    <span class="blogcommentname">' + txtName + '</span> sier' +
      '  </div>' +
      '  <span class="blogcommentdate">' +
      '    ' + d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate() +
      '  </span>' +
      '  <div class="blogcommenttext">' +
      '    ' + txtComment +
      '  </div>' +
      '  <div class="blogcommentseparator">' +
      '  </div>' +
      '</div>' + commentSection.innerHTML;
      setTimeout("showComments(" + id + ")", 500);
      
      commentSection.style.height = commentSection.offsetHeight + 25 + 'px';
    }
    else
    {
      document.getElementById('cToggle_' + id).style.visibility = 'hidden';
      incrementBlogCounter(id);
      setTimeout("loadComments(" + id + ")", 2000);
    }
  }