var dumb = function() { }
var last = '';
var thispage = 0;
var curgroupID = 0;

function VoteText(textID, vote, div)
 {
  new Ajax.Updater('voter' + div,
                   '/ajax/text_balls.html?textID=' + textID + '&vote=' + vote + '&div=' + div + '&digest=' + habradigest,
                   {asynchronous:true, onSuccess: dumb });

  return false;
 }

function VotePost(postID, vote, div)
 {
  new Ajax.Updater('voter' + div,
                   '/ajax/group_balls.html?postID=' + postID + '&vote=' + vote + '&div=' + div + '&digest=' + habradigest,
                   {asynchronous:true, onSuccess: dumb });

  return false;
 }

function VoteVoting(votingID, vote, div)
 {
  new Ajax.Updater('voter' + div,
                   '/ajax/voting_balls.html?votingID=' + votingID + '&vote=' + vote + '&div=' + div + '&digest=' + habradigest,
                   {asynchronous:true, onSuccess: dumb });

  return false;
 }

function VoteComment(commentID, vote)
 {
  new Ajax.Updater('voter' + commentID,
                   '/ajax/comment_balls.html?commentID=' + commentID + '&vote=' + vote + '&digest=' + habradigest,
                   {asynchronous:true, onSuccess: dumb });

  return false;
 }

function OpenComment(commentID)
 {
  $('hiddenl' + commentID).style.display = 'none';
  $('hiddenc' + commentID).style.display = 'block';

  return false;
 }

var SubmitCommentID = 0;

function SubmitCommentUnlock(request)
 {
  if (s = $('cpb' + SubmitCommentID)) s.disabled = false;
  if (s = $('csb' + SubmitCommentID)) s.disabled = false;
 }

function SubmitComment(commentID, f)
 {
  id = SubmitCommentID = commentID > 0 ? commentID : 'f';

  if (s = $('cpb' + id)) s.disabled = true;
  if (s = $('csb' + id)) s.disabled = true;

  new Ajax.Updater('commentsdiv',
                   '/ajax/comment.html?commentID=' + commentID, 
                   {asynchronous:true, 
                    parameters: Form.serialize(f), 
                    onSuccess: SubmitCommentUnlock }); 

  return false;
 }

function VotePoll(id)
 {
  new Ajax.Updater('vpd' + id,
                   '/ajax/votepoll.html?id=' + id + '&digest=' + habradigest, 
                   {asynchronous: true, 
                    parameters: Form.serialize($('vp' + id)), 
                    onSuccess: dumb }); 

  return false;
 }

function VotePollAlt(id)
 {
  new Ajax.Updater('vpd' + id,
                   '/ajax/votepoll.html?alt=1&id=' + id + '&digest=' + habradigest, 
                   {asynchronous: true, 
                    parameters: Form.serialize($('vp' + id)), 
                    onSuccess: dumb }); 

  return false;
 }

function VotePollVeryAlt(id)
 {
  new Ajax.Updater('vpd' + id,
                   '/ajax/votepoll.html?veryalt=1&id=' + id + '&digest=' + habradigest, 
                   {asynchronous: true, 
                    parameters: Form.serialize($('vp' + id)), 
                    onSuccess: dumb }); 

  return false;
 }

function ReadAlso(page)
 {
  new Ajax.Updater('read_also',
                   '/ajax/read_also.html?page=' + page, 
                   {asynchronous:true, 
                    parameters: '', 
                    onSuccess: dumb }); 

  return false;
 }

function PopularGroups(page)
 {
  new Ajax.Updater('popular_groups',
                   '/ajax/popular_groups.html?page=' + page, 
                   {asynchronous:true, 
                    parameters: '', 
                    onSuccess: dumb }); 

  return false;
 }

function NewGroups(page)
 {
  new Ajax.Updater('new_groups',
                   '/ajax/new_groups.html?page=' + page, 
                   {asynchronous:true, 
                    parameters: '', 
                    onSuccess: dumb }); 

  return false;
 }

function SetPendingStatus(messageID, pendingID, status)
 {
  new Ajax.Updater('msgbody',
                   '/ajax/set_pending_status.html?digest=' + habradigest + '&messageID=' + messageID + '&pendingID=' + pendingID + '&status=' + status, 
                   {asynchronous:true, 
                    parameters: '', 
                    onSuccess: dumb }); 

  return false;
 }

function UpdateGroupStuff()
 {
  if ($('writebutton'))
   new Ajax.Updater('writebutton',
                    '/ajax/group_write_button.html?digest=' + habradigest + '&groupID=' + curgroupID, 
                    {asynchronous:true, 
                     parameters: '', 
                     onSuccess: dumb }); 

  if ($('groupuserscnt'))
   new Ajax.Updater('groupuserscnt',
                    '/ajax/group_users_count.html?digest=' + habradigest + '&groupID=' + curgroupID, 
                    {asynchronous:true, 
                     parameters: '', 
                     onSuccess: dumb }); 

  if ($('userslist'))
   new Ajax.Updater('userslist',
                    '/ajax/group_userslist.html?digest=' + habradigest + '&page=' + curpage + '&groupID=' + curgroupID, 
                    {asynchronous:true, 
                     parameters: '', 
                     onSuccess: dumb }); 

  return false;
 }

function JoinGroup(groupID, uid)
 {
  curgroupID = groupID;

  new Ajax.Updater('grjn' + uid,
                   '/ajax/join_group.html?digest=' + habradigest + '&groupID=' + groupID + '&uid=' + uid, 
                   {asynchronous:true, 
                    parameters: '', 
                    onSuccess: UpdateGroupStuff }); 

  return false;
 }

function LeaveGroup(groupID, uid)
 {
  curgroupID = groupID;

  new Ajax.Updater('grjn' + uid,
                   '/ajax/leave_group.html?digest=' + habradigest + '&groupID=' + groupID + '&uid=' + uid, 
                   {asynchronous:true, 
                    parameters: '', 
                    onSuccess: UpdateGroupStuff }); 

  return false;
 }

function Favourite(kind, kindID, target, killalso)
 {
  if (killalso)
   $(killalso).innerHTML = '';

  new Ajax.Updater(target,
                   '/ajax/favourites.html?digest=' + habradigest + '&kind=' + kind + '&kindID=' + kindID,
                   {asynchronous:true, 
                    parameters: '', 
                    onSuccess: dumb }); 

  return false;
 }

function KillFavourite(kind, kindID, target, killalso)
 {
  if (killalso)
   $(killalso).innerHTML = '';

  new Ajax.Updater('maindata',
                   '/ajax/favourites.html?page=' + thispage + '&digest=' + habradigest + '&kill=1&kind=' + kind + '&kindID=' + kindID,
                   {asynchronous:true, 
                    parameters: '', 
                    onSuccess: dumb }); 

  return false;
 }

var successPostFunc = function() 
 {
  if (last)
   {
    $('reply_link' + last).style.display = 'none';
   }

  last = '';
 }

var successVoteFunc = function() 
 {
  last = '';
 }

function focusme(i)
 {
  if (i = $(i))
   i.focus();
 }

function saw(id)
 {
  if (last)
   {
    $('reply' + last).style.display = 'none';
   }

  $('reply' + id).style.display = 'inline';

  last = id;

  setTimeout("focusme('reply" + id + "ta');", 150);
 }

function sawnf(id)
 {
  if (last)
   {
    $('reply' + last).style.display = 'none';
   }

  $('reply' + id).style.display = 'inline';

  last = id;
 }

function scom(id)
 {
  $('hide_com' + id).style.display = $('hide_com' + id).style.display == 'none' ? 'inline' : 'none';
 }

var PreviewCommentID = 0;

function UnlockPreviewComment(request)
 {
  if (s = $('cpb' + PreviewCommentID)) s.disabled = false;
  if (s = $('csb' + PreviewCommentID)) s.disabled = false;
 }

function PreviewComment(id)
 {
  PreviewCommentID = id;

  if (s = $('cpb' + id)) s.disabled = true;
  if (s = $('csb' + id)) s.disabled = true;

  new Ajax.Updater('preview' + id,
                   '/ajax/comment_preview.html?digest=' + habradigest,
                   {asynchronous: true, 
                    parameters: Form.serialize($('form' + id)), 
                    onSuccess: UnlockPreviewComment }); 
 }

function PicturesLoader(id)
 {
  width = 600;
  height = 220;

  var left = Math.round((document.body.clientWidth - width) / 2);
  var top = Math.round((document.body.clientHeight - height) / 2);

  var win = window.open('/misc/pictures_addict.html?ta=' + id, 
                        '', 
                        'toolbar=no,' +
                        'scrollbars=yes,' + 
                        'status=no,' +
                        'height=' + height + ',' + 
                        'width=' + width + ',' + 
                        'top=' + top + ',' + 
                        'left=' + left);

  win.focus();
 }
