MediaWiki:Vector.js

From Baloogan Campaign Wiki
Revision as of 19:26, 22 January 2014 by Baloogan (talk | contribs)

Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for users using the Vector skin */
function handleClick()
{
           try{ TOGGLEA=(TOGGLEA % 2)}catch(e){
              TOGGLEA=0;
           }; // initialize TOGGLEA, HOLDX, and HOLDY

           switch(TOGGLEA){
           case 0: // this makes it four times as big as it was originally
//                   document.getElementById('baloogan_image').setAttribute('width' ,HOLDX*4);
document.getElementById('baloogan_image').className = "baloogan_big_image";

           break;
           case 1: // this sets to a original size
//                   document.getElementById('baloogan_image').setAttribute('width' ,HOLDX);
document.getElementById('baloogan_image').className = "baloogan_small_image";
           break;
           }
           TOGGLEA++;
}

document.getElementById('baloogan_image').onclick = handleClick;

// Discussion mediawiki extension
// version 2.1
// Copyright (c) 2009-2011 Vladimir Kolmogorov http://commenterra.com

CallInitAjaxDiscussion();
function CallInitAjaxDiscussion()
{
	if (typeof window.ajax_discussions!='object') return;
	for (i in window.ajax_discussions)
	{
		x = window.ajax_discussions[i];
		if (!x) continue;
		window.ajax_discussions[i] = null;
		InitAjaxDiscussion(x);
	}
}

function ScrollToElement(x)
{
	var y = 0;
	while (x != null)
	{
		y += x.offsetTop;
		x = x.offsetParent;
	}
	window.scroll(0,y-20);
}

function SetDiscussionCookie(cookie_name, value)
{
	document.cookie = 'ajax-discussion-' + cookie_name + '=' + value + '; expires=Wed, 1 Jan 2020 12:0:0 GMT;path=/;';
}

function GetDiscussionCookie(cookie_name)
{
	var m = RegExp('ajax-discussion-' + cookie_name + '=([^;]*)').exec(document.cookie);
	if (m) return m[1];
	return null;
}


function _DisplayDiscussionTime(t, format)
{
	if (format == 0)
	{
		var a = new Date();
		t = parseInt((a.getTime() - wgDiscussionClientTime.getTime())/1000) + wgDiscussionServerTime - t;
		if (t < 0) t = 0;

		var i, a = [60, 60, 24, 7, 30/7, 365*7/30];
		for (i=0; ; i++)
		{
			if (i == 6 || t < a[i]) return D_MSG_NTimeAgo(Math.floor(t), i);
			t /= a[i];
		}
	}
	else
	{
		function display_two_digits(i) { return (i < 10) ? ('0'+i) : i; }
		var a = new Date(1000*t);
		return D_MSG_NDate(a.getDate(), a.getMonth()) + ' ' + a.getFullYear() + ", " + display_two_digits(a.getHours()) + ":" + display_two_digits(a.getMinutes());
	}
}

function DisplayDiscussionTime(t, edit_t, format)
{
	var s = _DisplayDiscussionTime(t, format);
	if (edit_t>=0) s += ', &nbsp;&nbsp; ' + D_MSG_lastEdit + ' ' + _DisplayDiscussionTime(edit_t, format);
	return s;
}

function LimitDiscussionCommentCharacters(t, limit, counter)
{
	if (limit <= 0) return;
	while ( 1 )
	{
		var n = limit - t.value.replace(/\r/g, '').replace(/\n(> )+/g, '\n').replace(/^(> )+/g, '').length;
		if (n >= 0) { counter.value = n; return; }
		t.value = t.value.substring(0, t.value.length+n);
	}
}

function _FormatDiscussionComment(input) // duplicated in DiscussionSpecialPage.php
{
	var flag = -1, t = '', q = '';
	var i, i_max, lines = input.split('\n');
	for (i_max=lines.length-1; ;i_max--)
	{
		if (i_max < 0) return '&nbsp;';
		if (lines[i_max].match(/\S/)) break;
	}
	for (i=0; ;i++)
	{
		if (lines[i].match(/\S/)) break;
	}
	for (; i<=i_max; i++)
	{
		var s = lines[i];
		if (s.substring(0, 2) == '> ')
		{
			s = s.substring(2, s.length);
			if (flag > 0) q += '\n';
			q += s;
			flag = 1;
		}
		else
		{
			s = s.replace(/>/g, '&gt;').replace(/</g, '&lt;');
			s = s.replace(/(\s)(http:\/\/\S*)/g, '$1<a href="$2">$2</a>').replace(/^(http:\/\/\S*)/, '<a href="$1">$1</a>');
			var m = /^(\s*)([\s\S]*)$/.exec(s);
			if (m) s = m[1].replace(/\t/g, '    ').replace(/ /g, '&nbsp;') + m[2];
			if (flag > 0) { t += '<div class="discussion-comment-quote">' + _FormatDiscussionComment(q) + '</div>'; q = ''; }
			else if (flag == 0) t += '<br />';
			t += s;
			flag = 0;
		}
	}
	if (flag > 0) t += '<div class="discussion-comment-quote">' + _FormatDiscussionComment(q) + '</div>';
	return t;
}

function FormatDiscussionComment(text)
{
	return _FormatDiscussionComment(text.replace(/\r/g, ''));
}

function DisplayAdminActions(status)
{
	var s = '';
	if (status == 2) s += ' <span class="discussion-action0">'+D_MSG_AdminActionHide+'</span> ';
	else             s += ' <a class="discussion-action" onclick="DiscussionChangeCommentStatus(parentNode, 2);return false;">'+D_MSG_AdminActionHide+'</a> ';
	if (status == 1) s += ' <span class="discussion-action0">'+D_MSG_AdminActionBlock+'</span> ';
	else             s += ' <a class="discussion-action" title="'+D_MSG_CommentWillAppearAsBlocked+'" onclick="DiscussionChangeCommentStatus(parentNode, 1);return false;">'+D_MSG_AdminActionBlock+'</a> ';
	if (status == 0) s += ' <span class="discussion-action0">'+D_MSG_AdminActionApprove+'</span> ';
	else             s += ' <a class="discussion-action" onclick="DiscussionChangeCommentStatus(parentNode, 0);return false;">'+D_MSG_AdminActionApprove+'</a> ';
	return s;
}

function DisplayDiscussionComment(params, c)
{
	var reply_action = '', admin_actions = '', edit_action = '';
	if (params.can_post > 0)
	{
		var h = (c.status != 0) ? ' style="visibility:hidden;"' : '';
		reply_action = '<a class="discussion-action"'+h+' onclick="\
				var w=document.getElementById(\''+params.id+'\');\
				if (!onDiscussionAction(w)) return false;\
				w.my.post.parent = parentNode.parentNode.parentNode;\
				PostCommentInit(w);\
				return false;\
			  ">'+D_MSG_Reply+'</a>';
	}
	else if (params.can_post < 0)
	{
		reply_action = '<a class="discussion-action discussion-disabled" href="'+params.login_url+'" title="'+D_MSG_PleaseSignIn+'">'+D_MSG_Reply+'</a>';
	}

	if (params.can_do_admin) admin_actions = '<div class="discussion-action" style="width:30px;height:1px;"></div><span>'+DisplayAdminActions(c.status)+'</span>';

	if (wgUserName && c.author_id && c.author_id==wgUserName)
	{
		edit_action = '<a class="discussion-action" onclick="\
				var w=document.getElementById(\''+params.id+'\');\
				if (!onDiscussionAction(w)) return false;\
				w.my.post.edit = parentNode.parentNode.parentNode;\
				PostCommentInit(w);\
				return false;\
			">'+D_MSG_Edit+'</a>';
	}

	var header;
	if (params.can_view < 2 && c.status != 0)
	{
		header = '<em>'+D_MSG_ThisCommentHasBeenBlocked+'</em>';
	}
	else
	{
		header = '<div class="discussion-comment-author">' + c.author + '</div>'
		       + '<div class="discussion-comment-date">(' + DisplayDiscussionTime(c.time, c.edit_time, params.time_format) + ')</div>'
		       + reply_action
		       + admin_actions
		       + edit_action; // DiscussionChangeCommentStatusFinish() assumes that admin_actions follows reply_action immediately
	}

	var highlight = (c.id == params.comment_to_highlight) ? '-highlight' : '';

	return '<div class="discussion-comment-header' + highlight + '">'
	     +   header
	     +   '<div style="clear:both;"></div>'
	     + '</div>'
	     + '<div class="discussion-comment-text' + highlight + '">'
	     +   FormatDiscussionComment(c.text)
	     + '</div>';
}

//////////////////////// permissions /////////////////////
function in_array(x, array)
{
	for (var k=0; k<array.length; k++)
	{
		if (array[k] == x) return true;
	}
	return false;
}

function DiscussionCanView(groups, params)
{
	if (in_array(params.moderator_group, groups)) return 2;
	if (in_array(params.view_group, groups)) return 1;
	return 0;
}

function DiscussionCanPost(groups, params)
{
	if (in_array(params.moderator_group, groups)) return 2;
	if (in_array(params.post_group, groups)) return 2;
	if (in_array(params.restricted_post_group, groups)) return 1;
	return 0;
}

function DiscussionCanDoAdmin(groups, params)
{
	if (in_array(params.moderator_group, groups)) return true;
	return false;
}
//////////////////////// permissions end /////////////////

function InitAjaxDiscussion(params)
{
	var w = document.getElementById(params.id);
	if (!w) return;

	var user = wgUserName, groups = wgUserGroups;
	if (!user) groups = ["*"];
	params.can_view = DiscussionCanView(groups, params);
	if (!params.can_view)
	{
		document.getElementById(params.id+'_HEADER_VISIBLE').style.display = 'none';
		w.innerHTML = '';
		return;
	}
	params.can_post = DiscussionCanPost(groups, params);
	if (!params.can_post && !wgUserName && (params.post_group == 'user' || params.restricted_post_group == 'user'))
	{
		params.can_post = -1; // indicates that the user can post after logging in
	}
	params.can_do_admin = DiscussionCanDoAdmin(groups, params);

	switch (typeof params.page_sizes)
	{
		case 'string': params.page_sizes = params.page_sizes.split(','); break;
		case 'number': params.page_sizes = [params.page_sizes]; break;
		default: break;
	}
	var i;
	for (i=0; i<params.page_sizes.length; i++)
	{
		params.page_sizes[i] = parseInt(params.page_sizes[i]);
		if (params.page_sizes[i] < 1) params.page_sizes[i] = 1;
	}
	params.page_size = params.page_sizes[0];
	i = parseInt(GetDiscussionCookie('page_size'));
	if (in_array(i, params.page_sizes)) params.page_size = i;

	params.retrieve_block_size = 3*params.page_size;
	params.page_size0 = params.page_size;

	var time_format = GetDiscussionCookie('time_format');
	if (time_format === null) time_format = params.time_format;
	params.time_format = (parseInt(time_format)) ? 1 : 0;

	w.my = {};
	w.my.params = params;

	InitDiscussionHeader(w);

	w.innerHTML =
		  '<div class="discussion-loading" style="display:none">'+D_MSG_loading+'</div>'
		+ '<div class="discussion-body"><div class="discussion-prev" style="display:none">...</div><div class="discussion-next" style="display:none">...</div></div>'
	w.my.loading = w.childNodes[0];
	w.my.body    = w.childNodes[1];
	w.my.footer  = document.getElementById(params.id + '_FOOTER');
	w.my.footer.style.display = 'none';

	w.my.comment_id_retrieved = 2147483647; // comments with id >= w.my.comment_id_retrieved have been retrieved

	w.my.comments = [];
	w.my.received_comment_num = 0;
	w.my.received_valid_comment_num = 0; // counts only comments that have been added to the DOM tree
	w.my.show_all = false;
	w.my.first_visible = null;
	w.my.last_visible = null;

	w.my.post = {};
	w.my.post.input = null;
	w.my.options_flag = 0;

	w.my.params.comment_to_highlight = 0;
	var url = document.location.href;
	var m = /\#comment=(\d*):(\d*)/.exec(url);
	if (m && m[1]==params.discussion_id)
	{
		w.my.params.comment_to_highlight = parseInt(m[2]);
		if (w.my.params.comment_to_highlight < 0) w.my.params.comment_to_highlight = 0;
	}
	w.my.params.comment_to_highlight_present = 0;

	var is_hidden;
	if (params.init_display.match(/\!hide/)) is_hidden = true;
	else if (params.init_display.match(/\!show/)) is_hidden = false;
	else
	{
		is_hidden = params.init_display.match(/hide/);
		if (GetDiscussionCookie('hidden') == 1) is_hidden = true;
	}

	if (is_hidden && !w.my.params.comment_to_highlight)
	{
		SetDiscussionStatus(w, -2);
		SetDiscussionHeader(w);
	}
	else
	{
		DisplayCommentsWithFixedStart(w);
	}
}

function onDiscussionAction(w)
{
	if (w.my.status) return false;
	//var x = document.getElementById(w.my.params.id+'_OPTIONS_LINK');
	//if (x.flag) { x.flag = false; document.getElementById(w.my.params.id+'_OPTIONS').style.display='none'; }
	return true;
}

function sortNumber(a,b) { return a - b; }

function InitDiscussionHeader(w, params)
{
	var params = w.my.params;
	SetDiscussionHeader(w);
	if (w.events_added) return;
	w.events_added = true;

	var id = params.id, x;

	x = document.getElementById(id + '_COMMENT_NUM');
	x.w = w;
	addClickHandler(x, function() {
		if (w.my.status == -2)
		{
			SetDiscussionStatus(w, 0);
			SetDiscussionCookie('hidden', 0);
			if (!w.my.first_visible) DisplayCommentsWithFixedStart(w);
		}
		else
		{
			if (!onDiscussionAction(w)) return false;
			SetDiscussionCookie('hidden', 1);
			SetDiscussionStatus(w, -2);
		}
		return false;
	} );

	x = document.getElementById(id + '_POST');
	x.w = w;
	x.lastChild.innerHTML = D_MSG_PostComment;
	if (params.can_post > 0)
	{
		addClickHandler(x, function() {
			if (w.my.status == -2)
			{
				SetDiscussionStatus(w, 0);
				w.my.post_todo = true;
				if (!w.my.first_visible) DisplayCommentsWithFixedStart(w);
			}
			if (!onDiscussionAction(w)) return false;
			w.my.post_todo = false;
			w.my.post.parent = null;
			PostCommentInit(w);
			return false;
		} );
	}
	else if (params.can_post < 0)
	{
		x.href = params.login_url;
		x.title = D_MSG_PleaseSignIn;
	}
	else
	{
		x.style.display = 'none';
	}

	// options panel TODO
}

function SetDiscussionHeader(w)
{
	var params = w.my.params;
	var id = params.id, x;
	var num = params.comment_num1;
	var comment_num = D_MSG_NComments(num);
	if (params.can_view == 2 && params.comment_num2 > 0)
	{
		var hnum = ', ' + D_MSG_NHiddenComments(params.comment_num2);
		num += hnum;
		comment_num += hnum;
	}

	x = document.getElementById(id + '_COMMENT_NUM');
	x.lastChild.innerHTML = comment_num;

	if (w.my.status == -2) x.title = 'show';
	else x.title = 'hide';
}

function SetDiscussionFooter(w)
{
	if (!(w.my.status == 0 && w.my.received_valid_comment_num))
	{
		w.my.footer.style.display = 'none';
		return;
	}

	var sl = '', sr = '';

	var prev = MoveToNeighbor(w, w.my.first_visible, -1, 0), next = MoveToNeighbor(w, w.my.last_visible, 1, 0);
	if (w.my.params.recent_link)
	{
		sr += ' <a class="discussion-action" href="'+w.my.params.recent_link+'"><b>'+D_MSG_RecentComments+'</b></a> ';
	}
	if (!w.my.show_all)
	{
		sr += ' <a class="discussion-action" onclick="\
			var w=document.getElementById(\''+w.my.params.id+'\');\
			if (!w.my.status) onDiscussionShowAll(w, true);\
			return false;\
		     "><b>'+D_MSG_ShowAllComments+'</b></a> ';
	}
	if (prev)
	{
		sl += ' <a style="cursor:pointer;" onclick="\
		      var w=document.getElementById(\''+w.my.params.id+'\');\
		      if (!w.my.status) onDiscussionPrev(w);\
		      return false;\
		      "><b>'+D_MSG_Previous+'</b></a> ';
	}
	if (next)
	{
		sl += ' <a style="cursor:pointer;" onclick="\
		      var w=document.getElementById(\''+w.my.params.id+'\');\
		      if (!w.my.status) onDiscussionNext(w);\
		      return false;\
		      "><b>'+((w.my.params.incremental && !w.my.show_all) ? D_MSG_More : D_MSG_Next)+'</b></a> ';
	}

	w.my.footer.firstChild.firstChild.firstChild.innerHTML = sl;
	w.my.footer.firstChild.firstChild.lastChild.innerHTML = sr;
	w.my.footer.style.display = (w.my.params.comment_num1 > 0) ? '' : 'none';
}

///////////////////////////////////////

// -2:hidden
// -1:posting a comment or admin action
// 0:normal
// 1:waiting for comments from the server
// 2:redrawing
function SetDiscussionStatus(w, status)
{
	var old_status = w.my.status;
	if (status == -2)
	{
		w.my.loading.style.display = 'none';
		w.my.body.style.display = 'none';
	}
	else
	{
		if (w.my.params.incremental && !w.my.show_all)
		{
			w.my.body.style.display = '';
		}
		else
		{
			if (status > 0) w.my.body.style.display = 'none';
			w.my.loading.style.display = (status == 1) ? '' : 'none';
			if (w.my.show_all && w.my.params.show_all_order==0 && ((status>0 && old_status<=0) || (status<=0 && old_status>0)))
			{
				ReverseVisibleComments(w);
			}
			if (status <= 0) w.my.body.style.display = '';
		}
	}
	w.my.status = status;
	if (old_status == -2 || status == -2) SetDiscussionHeader(w);
	SetDiscussionFooter(w);
	if (status == 0 && w.my.post_todo)
	{
		w.my.post_todo = false;
		w.my.post.parent = null;
		PostCommentInit(w);
	}
}

function ReverseVisibleComments(w)
{
	if (!w.my.first_visible) return;
	var first_visible_prev = MoveToNeighbor(w, w.my.first_visible, -1, 0);
	var last_visible_next = MoveToNeighbor(w, w.my.last_visible, 1, 0);
	var last = w.my.last_visible; while (last.my.depth > 0) last = last.parentNode.parentNode.parentNode;
	if (last == w.my.first_visible) return;
	var next = last.nextSibling;
	while ( 1 )
	{
		var x = last.previousSibling;
		var y = x.cloneNode(true), xx = x, yy = y;
		while ( 1 )
		{
			yy.my = xx.my;
			xx = MoveToNextTreeNeighbor(xx);
			if (xx.my.depth <= x.my.depth) break;
			yy = MoveToNextTreeNeighbor(yy);
		}
		w.my.body.removeChild(x);
		w.my.body.insertBefore(y, next);
		if (x == w.my.first_visible) break;
	}
	w.my.first_visible = MoveToNeighbor(w, first_visible_prev, 1, 0);
	w.my.last_visible = MoveToNeighbor(w, last_visible_next, -1, 0);
}

///////////////////////////////////////

function DisplayCommentsWithFixedStart(w)
{
	var need_to_request_more_comments = false;
	if (w.my.first_visible)
	{
		var x, n;
		if (!w.my.show_all)
		{
			for (n=1, x=w.my.first_visible; x != w.my.last_visible; n++) x = MoveToNeighbor(w, x, 1, 0);
			while ( n > w.my.params.page_size )
			{
				w.my.last_visible = MoveToNeighbor(w, w.my.last_visible, -1, -1);
				n --;
			}
			while ( n < w.my.params.page_size )
			{
				x = MoveToNeighbor(w, w.my.last_visible, 1, 1);
				if (!x) break;
				w.my.last_visible = x;
				n ++;
			}
			if (w.my.comment_id_retrieved && (n < w.my.params.page_size || !MoveToNeighbor(w, w.my.last_visible, 1, 0))) need_to_request_more_comments = true;
		}
		else
		{
			var flag = -1;
			for (n=1, x=w.my.first_visible; x; n++)
			{
				if (x.my.depth == 0)
				{
					if (n>w.my.params.show_all_page_size) break;
					if (x==w.my.body.lastChild.previousSibling && w.my.comment_id_retrieved)
					{
						need_to_request_more_comments = true;
						break;
					}
				}
				if (x == w.my.last_visible) flag = 1;
				x = MoveToNextTreeNeighbor(x);
			}
			if (!need_to_request_more_comments)
			{
				x = MoveToNeighbor(w, x, -1, 0);
				while ( w.my.last_visible != x ) w.my.last_visible = MoveToNeighbor(w, w.my.last_visible, flag, flag);
			}
		}
	}
	else need_to_request_more_comments = w.my.comment_id_retrieved;

	var c = w.my.params.comment_to_highlight;
	if (c && w.my.params.comment_to_highlight_present!=2)
	{
		if (w.my.params.comment_to_highlight_present==1 || c<w.my.comment_id_retrieved) need_to_request_more_comments = true;
		c = null;
	}

	if (need_to_request_more_comments)
	{
		SetDiscussionStatus(w, 1);
		var comments = w.my.params.init_comments;
		w.my.params.init_comments = null;
		if (comments && (w.my.params.can_view < 2 || !w.my.params.init_view_flag))
		{
			ProcessAjaxComments({responseText:comments});
		}
		else
		{
			sajax_do_call( "wfAjaxQueryComments", [w.my.params.discussion_id, w.my.params.retrieve_block_size, w.my.comment_id_retrieved], ProcessAjaxComments );
		}
	}
	else
	{
		SetDiscussionStatus(w, 0);

		if (!w.my.first_visible) return;

		if (!w.my.init_flag)
		{
			w.my.init_flag = true;
			var prev = MoveToNeighbor(w, w.my.first_visible, -1, 0), next = MoveToNeighbor(w, w.my.last_visible, 1, 0);
			if (!prev && !next && !w.my.show_all)
			{
				onDiscussionShowAll(w, false);
				return;
			}
		}

		if (c && w.my.params.comment_to_highlight_present)
		{
			x = w.my.body.firstChild.nextSibling;
			while (x.my.id != c) x = MoveToNextTreeNeighbor(x);
			var y = x;
			while (y.my.depth > w.my.params.counted_depth) y = y.parentNode.parentNode.parentNode;
			if (y.my.is_visible)
			{
				ScrollToElement(x);
				w.my.params.comment_to_highlight = 0;

			}
			else
			{
				onDiscussionNext(w);
			}
		}
	}
}

function ProcessAjaxComments(request)
{
	var x = request.responseText.split('|');
	var id = x[0];
	var w = document.getElementById(id);
	var i, comment_num1 = parseInt(x[1]), comment_num2 = parseInt(x[2]), n = parseInt(x[3]), n_comment_id_max_new = parseInt(x[4]), n_comment_id_max = parseInt(x[5]);
	if (x.length != 8*n+6 || n_comment_id_max != w.my.comment_id_retrieved) return;

	w.my.params.comment_num1 = comment_num1;
	w.my.params.comment_num2 = comment_num2;
	SetDiscussionHeader(w);

	w.my.comment_id_retrieved = n_comment_id_max_new;
	for (i=0; i<n; i++)
	{
		var c = {};
		c.id        = parseInt(x[8*i+6]);
		c.parent    = parseInt(x[8*i+7]);
		c.status    = parseInt(x[8*i+8]);
		c.time      = x[8*i+9];
		c.edit_time = x[8*i+10];
		c.author_id = x[8*i+11].replace(/\#1/g, '|').replace(/\#0/g, '#');
		c.author    = x[8*i+12].replace(/\#1/g, '|').replace(/\#0/g, '#');
		c.text      = x[8*i+13].replace(/\#1/g, '|').replace(/\#0/g, '#');

		w.my.comments[w.my.comments.length] = c;
		w.my.received_comment_num ++;

		if (c.id == w.my.params.comment_to_highlight) w.my.params.comment_to_highlight_present = 1;
	}

	IncreaseLastVisible(w, null); // make end of page visible, so that we can append new comments
	for (i=0; i<w.my.comments.length; i++) // first add comments of depth 0 (in rev chronological order)
	{
		c = w.my.comments[i];
		if (c.parent == 0) { DTreeAddComment(w, c); w.my.received_valid_comment_num ++; }
	}
	var unprocessed_comments = []; // comments whose parent has not been retrieved yet
	for (i=w.my.comments.length-1; i>=0; i--)
	{
		c = w.my.comments[i];
		if (c.parent == 0) continue;
		if (DTreeAddComment(w, c)) w.my.received_valid_comment_num ++;
		else unprocessed_comments[unprocessed_comments.length] = c;
	}

	w.my.comments = [];
	for (i=unprocessed_comments.length-1; i>=0; i--) w.my.comments[w.my.comments.length] = unprocessed_comments[i];

	if (w.my.received_valid_comment_num > 0)
	{
		if (!w.my.first_visible) w.my.first_visible = MoveToNeighbor(w, null, 1, 0);
		w.my.last_visible = MoveToNeighbor(w, null, -1, 0);
	}
	DisplayCommentsWithFixedStart(w);
}

function DTreeAddComment(w, c)
{
	var p, depth = 0;
	if (!c.parent) p = w.my.body;
	else
	{
		p = document.getElementById(w.my.params.id + c.parent);
		if (!p) return false;
		depth = p.parentNode.my.depth + 1;
		p = p.lastChild;
	}

	var x = document.createElement('div');
	x.innerHTML =
	       '<div class="discussion-comment gainlayout" id="'+w.my.params.id+c.id+'">'
	     +   DisplayDiscussionComment(w.my.params, c)
	     +   '<div class="discussion-reply-toggle" style="display:none"><a onclick="var x=parentNode.parentNode.parentNode;if(x.my.w.my.status)return false;if(x.my.is_expanded)onDiscussionCollapse(x);else onDiscussionExpand(x);return false;"></a></div>'
	     +   '<div class="discussion-reply-info" style="display:none"></div>'
	     +   '<div class="discussion-replies" style="display:none"><div class="discussion-prev" style="display:none">...</div><div class="discussion-next" style="display:none">...</div></div>'
	     + '</div>';

	p.insertBefore(x, p.lastChild);

	var is_expanded = (!w.my.expand_all && (','+w.my.params.collapsed_depths+',').indexOf(','+depth+',')!=-1) ? 0 : 1;
	x.my = {w:w,id:c.id,text:c.text,time:c.time,status:c.status,author_id:c.author_id,depth:depth,reply_num:0,is_expanded:is_expanded,is_visible:1};

	var expand_flag = false;
	if (c.id == w.my.params.comment_to_highlight)
	{
		w.my.params.comment_to_highlight_present = 2;
		expand_flag = true;
	}

	while (p != w.my.body)
	{
		p = p.parentNode.parentNode;
		p.my.reply_num ++;
		var is_expanded = p.my.is_expanded;
		if (expand_flag) is_expanded = true;
		p.my.is_expanded = -1;
		SetExpandedStatus(p, is_expanded);
		p = p.parentNode;
	}
	return true;
}

///////////////////////////////////////

function onDiscussionPrev(w)
{
	if (!w.my.show_all)
	{
		var m, n, x;
		for (n=1, x=w.my.first_visible; x != w.my.last_visible; n++) x = MoveToNeighbor(w, x, 1, 0);
		for (m=0; m<w.my.params.page_size; m++)
		{
			x = MoveToNeighbor(w, w.my.first_visible, -1, 1);
			if (!x) break;
			w.my.first_visible = x;
			n ++;
			if (n > w.my.params.page_size)
			{
				w.my.last_visible = MoveToNeighbor(w, w.my.last_visible, -1, -1);
				n --;
			}
		}
	}
	else
	{
		SetDiscussionStatus(w, 2);
		var first_visible_new = w.my.first_visible.my.show_all_prev;
		var last_visible_new = MoveToNeighbor(w, w.my.first_visible, -1, 0);
		DecreaseFirstVisible(w, first_visible_new);
		DecreaseLastVisible(w, last_visible_new);
		SetDiscussionStatus(w, 0);
	}
	SetDiscussionFooter(w);
}

function onDiscussionNext(w)
{
	if (w.my.params.incremental && !w.my.show_all)
	{
		w.my.params.page_size += w.my.params.page_size0;
	}
	else
	{
		if (w.my.show_all) SetDiscussionStatus(w, 2);
		var x = MoveToNeighbor(w, w.my.last_visible, 1, 1);
		if (!x) return;
		w.my.last_visible = x;
		var first_visible_old = w.my.first_visible;
		IncreaseFirstVisible(w, x);
		if (w.my.show_all) w.my.first_visible.my.show_all_prev = first_visible_old;
	}
	DisplayCommentsWithFixedStart(w);
}

function onDiscussionExpand(x)
{
	var w = x.my.w, last_visible_next = MoveToNeighbor(w, w.my.last_visible, 1, 0);
	if (x.my.depth >= w.my.params.counted_depth || w.my.show_all)
	{
		SetExpandedStatus(x, 1);
		if (x == w.my.last_visible) w.my.last_visible = MoveToNeighbor(w, last_visible_next, -1, 0);
		return;
	}
	var y, n0, n1, n, x_next0 = MoveToNeighbor(w, x, 1, 0);
	for (n0=0, y=x; y!=w.my.first_visible; n0++) y = MoveToNeighbor(w, y, -1, 0);
	for (n1=0, y=x; y!=w.my.last_visible; n1++) y = MoveToNeighbor(w, y, 1, 0);
	SetExpandedStatus(x, 1);
	if (x == w.my.last_visible) w.my.last_visible = MoveToNeighbor(w, last_visible_next, -1, 0);
	for (y=x, n=n0+n1; y!=x_next0; y=MoveToNeighbor(w, y, 1, 0), n++)
	{
		y.my.is_visible = 1;
		y.style.display = '';
		y.lastChild.lastChild.firstChild.style.display = 'none';
		y.lastChild.lastChild.lastChild.style.display = 'none';
	}
	if (w.my.params.incremental) w.my.params.page_size += n - (n0+n1) - 1;
	for ( ; n>w.my.params.page_size && n1>0; n--, n1--) w.my.last_visible = MoveToNeighbor(w, w.my.last_visible, -1, -1);
	for ( ; n>w.my.params.page_size && n0>0; n--, n0--) w.my.first_visible = MoveToNeighbor(w, w.my.first_visible, 1, -1);
	for ( ; n>w.my.params.page_size; n--) w.my.last_visible = MoveToNeighbor(w, w.my.last_visible, -1, -1);
	SetDiscussionFooter(w);
}

function onDiscussionCollapse(x)
{
	var w = x.my.w, y;
	for (y=w.my.first_visible; y.my.depth > x.my.depth; y=y.parentNode.parentNode.parentNode) {}
	if (y == x) w.my.first_visible = x;
	for (y=w.my.last_visible; y.my.depth > x.my.depth; y=y.parentNode.parentNode.parentNode) {}
	if (y == x) w.my.last_visible = x;
	if (w.my.params.incremental && x.my.depth < w.my.params.counted_depth && !w.my.show_all)
	{
		for (y=MoveToNeighbor(w, x, 1, 0); y && y.my.is_visible && y.my.depth>x.my.depth; y=MoveToNeighbor(w, y, 1, 0)) w.my.params.page_size--;
	}
	SetExpandedStatus(x, 0);
	if (x.my.depth < w.my.params.counted_depth && !w.my.show_all)
	{
		DisplayCommentsWithFixedStart(w);
	}
}

function onDiscussionShowAll(w, expand_all)
{
	if (w.my.show_all) return;
	SetDiscussionStatus(w, 2);
	var x;
	while ( (x = MoveToNeighbor(w, w.my.first_visible, -1, 1)) ) w.my.first_visible = x;
	w.my.show_all = true;
	if (expand_all)
	{
		w.my.expand_all = true;
		for (x=MoveToNeighbor(w, null, 1, 0); x; x=MoveToNeighbor(w, x, 1, 0)) SetExpandedStatus(x, 1);
	}
	w.my.params.retrieve_block_size = Math.round(1.25*w.my.params.show_all_page_size);
	DisplayCommentsWithFixedStart(w);
}

///////////////////////////////////////

function SetExpandedStatus(x, is_expanded)
{
	if (x.my.is_expanded == is_expanded) return;

	var w = x.w;
	var w_replies = x.lastChild.lastChild;
	var w_reply_info = w_replies.previousSibling;
	var w_toggle = w_reply_info.previousSibling;

	if (x.my.reply_num == 0)
	{
		w_toggle.style.display = 'none';
		w_reply_info.style.display = 'none';
		w_replies.style.display = 'none';
	}
	else
	{
		w_toggle.style.display = '';
		if (is_expanded)
		{
			w_toggle.firstChild.innerHTML = '[<b>-</b>]';
			w_reply_info.style.display = 'none';
			w_replies.style.display = '';
		}
		else
		{
			w_toggle.firstChild.innerHTML = '[<b>+</b>]';
			w_reply_info.innerHTML = D_MSG_NReplies(x.my.reply_num);
			w_reply_info.style.display = '';
			w_replies.style.display = 'none';
		}
	}
	x.my.is_expanded = is_expanded;
}

function SetVisibleStatus(x, is_visible)
{
	if (x.my.is_visible == is_visible) return;

	var p = x.parentNode;
	if (is_visible)
	{
		x.style.display = '';
		if ( x.nextSibling == p.lastChild ) p.lastChild.style.display = 'none';
		if ( x.previousSibling == p.firstChild ) p.firstChild.style.display = 'none';
	}
	else
	{
		x.style.display = 'none';
		if ( x.nextSibling == p.lastChild ) p.lastChild.style.display = '';
		if ( x.previousSibling == p.firstChild ) p.firstChild.style.display = '';
		if ( (x.nextSibling == p.lastChild || !x.nextSibling.my.is_visible) && (x.previousSibling == p.firstChild || !x.previousSibling.my.is_visible) ) p.lastChild.style.display = 'none';
	}
	x.my.is_visible = is_visible;
}

function MoveToNextTreeNeighbor(x)
{
	if (x.my.reply_num > 0)
	{
		return x.lastChild.lastChild.firstChild.nextSibling;
	}
	while ( 1 )
	{
		if (x.nextSibling.nextSibling)
		{
			return x.nextSibling;
		}
		if (x.my.depth == 0) return null;
		x = x.parentNode.parentNode.parentNode;
	}
}

function MoveToNeighbor(w, x, dir, update_visibility)
{
	if (dir > 0)
	{
		if (!x) return w.my.body.firstChild.nextSibling;
		if (x.my.depth < w.my.params.counted_depth && x.my.is_expanded && x.my.reply_num > 0)
		{
			x = x.lastChild.lastChild.firstChild.nextSibling;
			if (update_visibility > 0) SetVisibleStatus(x, 1);
			return x;
		}
		while ( 1 )
		{
			if (x.nextSibling.nextSibling)
			{
				if (update_visibility < 0) SetVisibleStatus(x, 0);
				x = x.nextSibling;
				if (update_visibility > 0) SetVisibleStatus(x, 1);
				return x;
			}
			if (x.my.depth == 0) return null;
			if (update_visibility < 0) SetVisibleStatus(x, 0);
			x = x.parentNode.parentNode.parentNode;
		}
	}
	else
	{
		if (!x) x = w.my.body.lastChild.previousSibling;
		else
		{
			if (update_visibility < 0) SetVisibleStatus(x, 0);
			if (x.previousSibling.previousSibling) x = x.previousSibling;
			else
			{
				if (x.my.depth == 0) return null;
				return x.parentNode.parentNode.parentNode;
			}
		}
		while ( x.my.depth < w.my.params.counted_depth && x.my.is_expanded && x.my.reply_num > 0)
		{
			if (update_visibility > 0) SetVisibleStatus(x, 1);
			x = x.lastChild.lastChild.lastChild.previousSibling;
		}
		if (update_visibility > 0) SetVisibleStatus(x, 1);
		return x;
	}
}

function IncreaseFirstVisible(w, stop) { while (w.my.first_visible != stop) w.my.first_visible = MoveToNeighbor(w, w.my.first_visible, 1, -1); }
function IncreaseLastVisible(w, stop)  { while (w.my.last_visible  != stop) w.my.last_visible  = MoveToNeighbor(w, w.my.last_visible, 1, 1); }
function DecreaseFirstVisible(w, stop) { while (w.my.first_visible != stop) w.my.first_visible = MoveToNeighbor(w, w.my.first_visible, -1, 1); }
function DecreaseLastVisible(w, stop)  { while (w.my.last_visible  != stop) w.my.last_visible  = MoveToNeighbor(w, w.my.last_visible, -1, -1); }

///////////////////////////////////////////
//            posting comment            //
///////////////////////////////////////////

function PostCommentInit(w)
{
	if (w.my.post.input) return;
	var next, p;
	if (w.my.post.parent)
	{
		p = w.my.post.parent;
		w.my.post.quote_text = p.my.text;
		if (p.my.depth >= w.my.params.max_depth)
		{
			p = (p.my.depth > 0) ? p.parentNode.parentNode.parentNode : null;
		}
	}
	else
	{
		p = null;
		w.my.post.quote_text = '';
	}

	if (w.my.post.edit)
	{
		w.my.post.edit.style.display = 'none';
		next = w.my.post.edit.nextSibling;
	}
	else if (p)
	{
		w.my.post.parent = p.my.id;
		next = p.lastChild.lastChild.lastChild;
		p.my.reply_num ++;
		if (p.my.reply_num == 1)
		{
			SetExpandedStatus(p, 0);
			SetExpandedStatus(p, 1);
		}
		else
		{
			if (w.my.show_all)
			{
				SetExpandedStatus(p, 1);
			}
			else
			{
				MakeCommentVisible(next.previousSibling, false);
			}
		}
	}
	else
	{
		w.my.post.parent = 0;
		while (w.my.first_visible && MoveToNeighbor(w, w.my.first_visible, -1, 0)) onDiscussionPrev(w);
		if (w.my.show_all && w.my.params.show_all_order==0)
		{
			next = w.my.body.lastChild;
		}
		else
		{
			next = w.my.body.childNodes[1];
		}
	}

	var x = document.createElement('div');
	next.parentNode.insertBefore(x, next);
	w.my.post.input = next.previousSibling;
	SetDiscussionStatus(w, -1);

	var author_characters_max = (w.my.params.author_characters_max >= 1) ? w.my.params.author_characters_max : 1;

	var time_string = '';
	if (w.my.post.edit)
	{
		time_string = DisplayDiscussionTime(w.my.post.edit.my.time, -1, w.my.params.time_format) + ', &nbsp;&nbsp; ' + D_MSG_lastEdit + ' ';
	}

	var i = w.my.post.input;
	i.innerHTML =
		  '<div class="discussion-comment-header gainlayout">'
		+   '<div class="discussion-comment-author"></div>'
		+   '<div class="discussion-comment-date">('+time_string+D_MSG_currentTime+')</div>'
		+   '<div style="clear:left;"></div>'
		+ '</div>'
		+ '<div class="discussion-comment-text"></div>'
		+ '<div class="discussion-input gainlayout">'
		+   '<div>'+D_MSG_Name+' <input type="text" maxlength="'+author_characters_max+'" size="'+author_characters_max+'" /> <span style="color:red;margin-left:15px;"></span></div>'
		+   '<textarea rows="8" onkeyup="\
			var w=document.getElementById(\''+w.my.params.id+'\');\
			LimitDiscussionCommentCharacters(this, '+w.my.params.characters_max+', w.my.post.w_chars_left);\
			if (w.my.params.preview==1) { w.my.post.b_submit.disabled = true; w.my.post.b_preview.disabled = false; }\
		     "></textarea>'
		+   '<span>'+D_MSG_CharactersLeft+' <input type="text" readonly="readonly" size="5" style="margin-right:20px;"/></span>'
		+   '<input type="button" value="'+D_MSG_Submit+'" onclick="\
			var w=document.getElementById(\''+w.my.params.id+'\');\
			PostCommentSubmit(w);\
		    " />'
		+   '<input type="button" value="'+D_MSG_Preview+'" onclick="\
			var w=document.getElementById(\''+w.my.params.id+'\');\
			PostCommentShowPreview(w);\
		    " />'
		+   '<input type="button" value="'+D_MSG_Quote+'" style="margin-left:20px;" onclick="\
			var w=document.getElementById(\''+w.my.params.id+'\');\
			PostCommentQuote(w);\
		    " />'
		+   '<input type="button" value="'+D_MSG_Cancel+'" style="margin-left:20px;" onclick="\
			var w=document.getElementById(\''+w.my.params.id+'\');\
			PostCommentCancel(w);\
		    " />'
		+ '</div>';

	ScrollToElement(w.my.post.input);

	w.my.post.w_preview_author = i.childNodes[0].childNodes[0];
	w.my.post.w_preview_date   = i.childNodes[0].childNodes[1];
	w.my.post.w_preview_text   = i.childNodes[1];
	w.my.post.w_author         = i.childNodes[2].childNodes[0].getElementsByTagName('input')[0];
	w.my.post.w_author_msg     = i.childNodes[2].childNodes[0].getElementsByTagName('span')[0];
	w.my.post.w_text           = i.childNodes[2].childNodes[1];
	w.my.post.w_chars_left     = i.childNodes[2].childNodes[2].lastChild;
	w.my.post.b_submit         = i.childNodes[2].childNodes[3];
	w.my.post.b_preview        = i.childNodes[2].childNodes[4];
	w.my.post.b_quote          = i.childNodes[2].childNodes[5];
	w.my.post.b_cancel         = i.childNodes[2].childNodes[6];

	w.my.post.w_preview_author.parentNode.style.display = 'none';
	w.my.post.w_preview_text.style.display = 'none';
	if (wgUserName)
	{
		w.my.post.w_author.parentNode.style.display = 'none';
		w.my.post.w_author.value = wgUserName;
	}
	if (!w.my.post.quote_text || !w.my.params.quoting) w.my.post.b_quote.style.display = 'none';
	if (w.my.params.preview==0) w.my.post.b_preview.style.display = 'none';
	else if (w.my.params.preview==1) w.my.post.b_submit.disabled = 'true';
	if (w.my.params.characters_max > 0) LimitDiscussionCommentCharacters(w.my.post.w_text, w.my.params.characters_max, w.my.post.w_chars_left);
	else w.my.post.w_chars_left.parentNode.style.display = 'none';

	if (w.my.post.edit)
	{
		w.my.post.w_text.value = w.my.post.edit.my.text;
		PostCommentShowPreview(w);
	}
}

function PostCommentShowPreview(w)
{
	if (!w.my.post.w_author.value) { w.my.post.w_author_msg.innerHTML = D_MSG_PleaseEnterYourName; return; }
	if (w.my.params.preview==1) { w.my.post.b_submit.disabled = false; w.my.post.b_preview.disabled = true; }
	w.my.post.w_preview_author.parentNode.style.display = '';
	w.my.post.w_preview_text.style.display = '';
	w.my.post.w_author_msg.innerHTML = '';
	var author = w.my.post.w_author.value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
	if (wgUserName) author = '<a href="'+w.my.params.author_url_prefix+author+'">'+author+'</a>';
	w.my.post.w_preview_author.innerHTML = author;
	w.my.post.w_preview_text.innerHTML = FormatDiscussionComment(w.my.post.w_text.value);
}

function PostCommentGetResponse(request)
{
	var s = request.responseText.split('|', 2);
	id = s[0];
	var w = document.getElementById(id);
	if (s[1]) w.innerHTML = s[1] + '<br /><input type="button" value="' + D_MSG_OK + '" onclick="var w=document.getElementById(\''+id+'\');InitAjaxDiscussion(w.my.params);" />';
	else InitAjaxDiscussion(w.my.params);
}

function DiscussionEncode(t)
{
	if (!wgUseDiscussionEncoding) return t;
	var s0 = '', s = '', n = 2;
	for (var i=0; i<t.length; i++) { c = t.charCodeAt(i).toString(16); if (c.length != n && s) { s0 += '.'+n+'.'+s; s = ''; } n = c.length; s += c; }
	if (s) s0 += '.'+n+'.'+s;
	return s0;
}

function PostCommentSubmit(w)
{
	if (!w.my.post.w_author.value) { w.my.post.w_author_msg.innerHTML = D_MSG_PleaseEnterYourName; return; }
	w.my.post.w_author_msg.innerHTML = '';
	w.my.post.b_submit.disabled = true;
	w.my.post.b_preview.disabled = true;
	w.my.post.b_quote.disabled = true;
	w.my.post.b_cancel.disabled = true;
	var text = DiscussionEncode(w.my.post.w_text.value);
	if (w.my.post.edit)
	{
		sajax_do_call( "wfAjaxEditComment", [w.my.params.discussion_id, w.my.post.edit.my.id, text] , PostCommentGetResponse ); // w
	}
	else
	{
		var author = DiscussionEncode(w.my.post.w_author.value);
		sajax_do_call( "wfAjaxSubmitComment", [w.my.params.discussion_id, w.my.post.parent, author, text] , PostCommentGetResponse ); // w 
	}
}

function PostCommentQuote(w)
{
	if (!w.my.post.quote_text) return;
	if (w.my.params.preview==1) { w.my.post.b_submit.disabled = true; w.my.post.b_preview.disabled = false; }
	w.my.post.w_text.value = '> ' + w.my.post.quote_text.replace(/\n/g, '\n> ') + '\n' + w.my.post.w_text.value;
	LimitDiscussionCommentCharacters(w.my.post.w_text, w.my.params.characters_max, w.my.post.w_chars_left);
}

function PostCommentCancel(w)
{
	var p = w.my.post.input.parentNode;
	p.removeChild(w.my.post.input);
	if (w.my.post.edit)
	{
		w.my.post.edit.style.display = '';
		w.my.post.edit = null;
	}
	else if (p != w.my.body)
	{
		p = p.parentNode.parentNode;
		p.my.reply_num --;
		if (p.my.reply_num == 0)
		{
			SetExpandedStatus(p, 0);
			SetExpandedStatus(p, 1);
		}
	}
	w.my.post.input = null;
	SetDiscussionStatus(w, 0);
}

///////////////////////////////////////////

// called when posting a comment
function MakeCommentVisible(x, highlight_flag)
{
	var w = x.my.w, parents = [], y = x, d;
	while ( 1 )
	{
		parents[parents.length] = y;
		if (y.my.depth == 0) break;
		y = y.parentNode.parentNode.parentNode;
	}
	if (w.my.show_all && !y.my.is_visible) return; // should't be here
	for (d=0; ; d++)
	{
		y = parents[parents.length-d-1];
		if (!y.my.is_visible && y.my.depth<=w.my.params.counted_depth && !w.my.show_all)
		{
			var x0 = w.my.first_visible, x1 = w.my.last_visible, n = 1;
			while (x0 != x1) { x0 = MoveToNeighbor(w, x0, 1, 0); n ++; }
			x0 = w.my.first_visible;
			while ( 1 )
			{
				x0 = MoveToNeighbor(w, x0, -1, 0);
				if (!x0 || x0 == y) break;
				x1 = MoveToNeighbor(w, x1, 1, 0);
				if (!x1 || x1 == y) break;
			}
			if (!x1 || x0 == y)
			{
				while ( 1 )
				{
					w.my.first_visible = MoveToNeighbor(w, w.my.first_visible, -1, 1);
					n ++;
					if (n > w.my.params.page_size) { w.my.last_visible = MoveToNeighbor(w, w.my.last_visible, -1, -1); n--; }
					if (y.my.is_visible) break;
				}
			}
			else
			{
				while ( 1 )
				{
					w.my.last_visible = MoveToNeighbor(w, w.my.last_visible, 1, 1);
					n ++;
					if (n > w.my.params.page_size) { w.my.first_visible = MoveToNeighbor(w, w.my.first_visible, 1, -1); n--; }
					if (y.my.is_visible) break;
				}
			}
		}
		if (y == x) break;
		if (!y.my.is_expanded) onDiscussionExpand(y);
	}
	SetDiscussionFooter(w);
}

///////////////////////////////////////////

function DiscussionChangeCommentStatus(admin_actions, new_status)
{
	var x = admin_actions.parentNode.parentNode.parentNode;
	var w = x.my.w;
	if (w.my.status != 0) return;

	var admin_action_info = document.createElement('div');
	var next = admin_actions.parentNode;
	next.parentNode.insertBefore(admin_action_info, next);
	admin_action_info = next.previousSibling;
	admin_action_info.admin_actions = admin_actions;
	//admin_action_info.innerHTML = '<a style="cursor:pointer;" onclick="DiscussionChangeCommentStatusFinish(parentNode, -1);">'+D_MSG_close+'</a>';
	SetDiscussionStatus(w, -1);
	sajax_do_call( "wfAjaxChangeCommentStatus", [w.my.params.discussion_id, x.my.id, new_status] , admin_action_info );
}

function DiscussionChangeCommentStatusFinish(admin_action_info, new_status)
{
	var x = admin_action_info.parentNode.parentNode;
	var w = x.my.w;
	if (new_status >= 0)
	{
		x.my.status = new_status;
		admin_action_info.admin_actions.innerHTML = DisplayAdminActions(new_status);
		admin_action_info.admin_actions.previousSibling.previousSibling.style.visibility = (new_status!=0) ? 'hidden' : 'visible';
	}
	admin_action_info.parentNode.removeChild(admin_action_info);
	SetDiscussionStatus(w, 0);
}