//==============================================================================
// File: DoComments.js
// Version: 2
// Date: August 21, 2009
// Author: Johnnie Rose, Jr. (johnnie@jerrata.com)
// Copyright: Jerrata DoComments (c)2009 Jerrata Solutions, all rights reserved.
// Need help? Please contact support@jerrata.com for assistance.
//==============================================================================

//==============================================================================
// SITE PREFERENCES
// Please change the following options to customize DoComments to your website.

//==============================================================================
// Set DOCOMMENTS_LOCATION to the directory where you put DoComments.php, but:
//	1) don't include the http://, https:// or www prefixes
//	2) include a slash at the end of the URL
// For example, if you installed DoComments to:
// http://www.yoursite.com/docomments/, you'd enter: yoursite.com/docomments/
// as the DOCOMMENTS_LOCATION.
var DOCOMMENTS_LOCATION = "icanstophurricanes.com/comments/";

//==============================================================================
// Set DOCOMMENTS_USING_HTTPS to true if you're using the HTTPS protocol. Set
// DOCOMMENTS_USING_HTTPS to false, otherwise.
var DOCOMMENTS_USING_HTTPS = false;

//==============================================================================
// This is the success message that guests see when a comment is accepted for
// moderation but is not yet live on your website.
var DOCOMMENTS_MESSAGE_ACCEPTED_FOR_MODERATION = "Thanks! Your comment was successfully accepted for moderation and, if approved, will be live shortly.";

//==============================================================================
// This is the amount of space, in pixels, that appears between a comment's
// byline (for example, "Anonymous rates this 5/5 and writes...") and the
// comment itself and also between the comment and its timestamp.
var DOCOMMENTS_SPACING_COMMENT_CUSHION = 5;

//==============================================================================
// This is the amount of space, in pixels, that appears between two comments.
var DOCOMMENTS_SPACING_BETWEEN_COMMENTS = 30;

//==============================================================================
// If this is set to true, then topic ratings will be displayed as percentages
// (for example, 100% will be shown for a topic with a 5/5 rating). If this is
// set to false, then topic ratings will be displayed as a number out of 5
// (for example, 5/5).
var DOCOMMENTS_SHOW_TOPIC_RATINGS_AS_PERCENTAGES = true;

//==============================================================================
// This is the color in which the number of 'good comment' votes that a comment
// has received will be shown.  Default is dark green: #008000
var DOCOMMENTS_GOOD_VOTES_COLOR = "#008000";

//==============================================================================
// This is the color in which the number of 'bad comment' votes that a comment
// has received will be shown.  Default is bright red: #ff0000
var DOCOMMENTS_BAD_VOTES_COLOR = "#ff0000";

//==============================================================================
// This is the color in which the heart and slashed-heart ("<3" and "</3")
// symbols will be shown when the user's mouse is NOT overhead.  The user will
// click these symbols to vote a comment as good/bad.  Default is gray: #9e9e9e
var DOCOMMENTS_SYMBOL_COLOR_NO_HOVER = "#9e9e9e";

//==============================================================================
// This is the color in which the heart and slashed-heart ("<3" and "</3")
// symbols will be shown when the user's mouse IS overhead.  The user will
// click these symbols to vote a comment as good/bad.  Default is black: #000000
var DOCOMMENTS_SYMBOL_COLOR_HOVER = "#000000";

//==============================================================================
// This is the color of the border between a comment's byline (for example,
// "Anonymous rates this 5/5 and writes...") and the comment itself.  Default is
// black: #000000
var DOCOMMENTS_BYLINE_BOTTOM_BORDER_COLOR = "#000000";

//==============================================================================
// Determines the color of all non-link text, also excluding the good/bad vote
// count whose colors are determined, above.  Default is black: #000000
var DOCOMMENTS_TEXT_COLOR = "#000000";

//==============================================================================
// This is the color of a comment's 'reply' link and any byline (for example,
// the "Anonymous" in "@Anonymous:" would be highlighted in this color and, when
// clicked, makes the browser jump to Anonymous' comment.  Default blue: #0000ff
var DOCOMMENTS_LINK_COLOR = "#0000ff";

//==============================================================================
// Guests' comments will be backed by this color.  Default is white: #ffffff
var DOCOMMENTS_GUEST_COMMENT_BACKGROUND_COLOR = "#ffffff";

//==============================================================================
// Comments posted by a site administrator have a different background color
// than comments posted by guests.  (Login to your account at
// http://docomments.jerrata.com/admin to post a reply as a site administrator.)
// Default is white: #ffffff
var DOCOMMENTS_ADMIN_COMMENT_BACKGROUND_COLOR = "#ffffff";

//==============================================================================
// Determines the appearance of a comment's reply link and any byline (for
// example, the "Anonymous" in "@Anonymous:".  Valid values include "underline"
// and the default: "none"
var DOCOMMENTS_LINK_TEXT_DECORATION = "none";

//==============================================================================
// These values control the appearance of a comment's author's name (for example
// "Anonymous" in "Anonymous rates this 5/5 and writes..."
var DOCOMMENTS_LARGE_TEXT_FONT_FACE = "Arial";
var DOCOMMENTS_LARGE_TEXT_FONT_SIZE = "24";

//==============================================================================
// These values control the appearance of the remainder of a comment's byline
// (for example, "rates this 5/5 and writes..." in "Anonymous rates this 5/5 and
// writes...") as well as the number of good/bad votes, any preface (for example
// "@Anonymous:") and the text of the comment itself.
var DOCOMMENTS_MEDIUM_TEXT_FONT_FACE = "Arial";
var DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE = "14";

//==============================================================================
// These values control the appearance of a comment's timestamp.
var DOCOMMENTS_SMALL_TEXT_FONT_FACE = "Arial";
var DOCOMMENTS_SMALL_TEXT_FONT_SIZE = "10";

//==============================================================================
//==============================================================================
//==============================================================================
// PLEASE DO NOT MODIFY ANY TEXT PAST THIS POINT
// PLEASE DO NOT MODIFY ANY TEXT PAST THIS POINT
// PLEASE DO NOT MODIFY ANY TEXT PAST THIS POINT
// Otherwise, DoComments may cease to work properly.  If you need assistance,
// contact support@jerrata.com

if(typeof docomments_topic == "undefined")
	var docomments_topic = "Default";

var POST_FORM_CLOSE_DELAY = 2000;
var post_form_cur_height = 0;
var POST_FORM_SHRINK_HEIGHT_INCREMENT = -5;
var POST_FORM_GROW_HEIGHT_INCREMENT = 5;
var POST_FORM_MAX_HEIGHT = 460;
var POST_FORM_ANIM_DELAY = 25;
var anim_timeout = null;
var highlight_comment_id = null;
var paginate = true;
var is_reply = false;
var parent_comment_id = null;
var refresh_comments_timeout = null;
var comments;
var num_comments_on_page;
var num_comments_in_topic = 0;
var topic_rating;
var topic_rated;
var num_pages_of_comments;
var cur_pageno = 1;
var captcha_a;
var add_others_comments_in_realtime_interval;
var add_others_comments_in_realtime;
var COMMENT_MAXLENGTH = 1000;
var vote_comment_req = null;
var post_comment_req;
var get_comments_req;
var latest_comment_id = 0;
//==============================================================================
var ASYNCHRONOUS_AJAX = true;
var DOCOMMENTS_ACTION = "a";
var DOCOMMENTS_ACTION_GET_COMMENTS = "g";
var DOCOMMENTS_ACTION_POST_COMMENT = "p";
var DOCOMMENTS_ACTION_VOTE_COMMENT = "v";
var RESULT_OK = "o";
var RESULT_FAILED = "f";
var RETRY_INTERVAL = 60000;
//==============================================================================
var response;
var response_caret = 0;

//==============================================================================
function AffectPostCommentFormHeight(increment)
{
	var new_height = post_form_cur_height + increment;
	
	if(new_height < 1 || new_height > POST_FORM_MAX_HEIGHT)
	{
		anim_timeout = null;
		
		if(increment > 0)
			DoneShowingPostCommentForm();
		else
			DoneHidingPostCommentForm();
		return;
	}
	
	post_form_cur_height = new_height;
	document.getElementById("docomments_post").style.height = post_form_cur_height;
	anim_timeout = setTimeout("AffectPostCommentFormHeight(" + increment + ")",POST_FORM_ANIM_DELAY);
}

//==============================================================================
function DoneHidingPostCommentForm()
{
	post_form_cur_height = 1;
	document.getElementById("docomments_post").style.height = post_form_cur_height;
	document.getElementById("docomments_post").style.visibility = "hidden";
}

//==============================================================================
function HidePostCommentForm()
{
	if(anim_timeout != null)
	{
		clearTimeout(anim_timeout);
		anim_timeout = null;
	}
	
	AffectPostCommentFormHeight(POST_FORM_SHRINK_HEIGHT_INCREMENT);
}

//==============================================================================
function DoneShowingPostCommentForm()
{
	post_form_cur_height = POST_FORM_MAX_HEIGHT;
	document.getElementById("docomments_post").style.height = post_form_cur_height;
}

//==============================================================================
function ShowPostCommentForm()
{
	if(anim_timeout != null)
	{
		clearTimeout(anim_timeout);
		anim_timeout = null;
	}
	
	document.getElementById("docomments_post").style.visibility = "visible";
	AffectPostCommentFormHeight(POST_FORM_GROW_HEIGHT_INCREMENT);
}

//==============================================================================
function LoadPrevPage()
{
	ChangePage(cur_pageno - 1);
}

//==============================================================================
function LoadNextPage()
{
	ChangePage(cur_pageno + 1);
}

//==============================================================================
function VoteCommentHandler()
{
	if(vote_comment_req.readyState == 4)
	{
		if(vote_comment_req.status == 200)
		{
			if(vote_comment_req.responseText != null)
			{
				switch(vote_comment_req.responseText.substring(0,1))
				{
					case RESULT_OK:
						latest_comment_id = 0;
						RefreshComments();
						break;
					case RESULT_FAILED:
						ResponseSet(vote_comment_req.responseText);
						alert(ResponseReadString());
						break;
					default:	// unrecognized system response
						alert("DoComments was unable to submit your vote because the system's response was unrecognized. Please try again.");
						break;
				}
			}
			else	// no system response
			{
				alert("DoComments was unable to submit your vote because the system did not respond. Please try again.");
			}
			
			vote_comment_req = null;
		}
	}
}

//==============================================================================
function VoteCommentAs(which_comment,opinion)
{
	if(opinion != "good" && opinion != "bad")
		return;
		
	if(vote_comment_req != null)
	{
		alert("Please wait until any earlier vote has been recorded.");
		return;
	}
		
	// determine where DoComments.php is
	var DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW = "";
	var DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW = "";
	
	if(DOCOMMENTS_USING_HTTPS)
	{
		DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += "https://";
		DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += "https://www.";
	}
	else
	{
		DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += "http://";
		DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += "http://www.";
	}
	
	DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += DOCOMMENTS_LOCATION + "DoComments.php";
	DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += DOCOMMENTS_LOCATION + "DoComments.php";

	// prepare request
	var data = "comment_id=" + encodeURIComponent(which_comment);
	data += "&opinion=" + encodeURIComponent(opinion);
	
	// request
	try
	{
		if(window.XMLHttpRequest)
			vote_comment_req = new XMLHttpRequest();
		else
			vote_comment_req = new ActiveXObject("Microsoft.XMLHTTP");
			
		vote_comment_req.onreadystatechange = VoteCommentHandler;
		vote_comment_req.open("POST",DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW + "?" + DOCOMMENTS_ACTION + "=" + DOCOMMENTS_ACTION_VOTE_COMMENT,ASYNCHRONOUS_AJAX);
		vote_comment_req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		vote_comment_req.send(data);
	}
	catch(e)
	{
		try
		{
			if(window.XMLHttpRequest)
				vote_comment_req = new XMLHttpRequest();
			else
				vote_comment_req = new ActiveXObject("Microsoft.XMLHTTP");
				
			vote_comment_req.onreadystatechange = VoteCommentHandler;
			vote_comment_req.open("POST",DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW + "?" + DOCOMMENTS_ACTION + "=" + DOCOMMENTS_ACTION_VOTE_COMMENT,ASYNCHRONOUS_AJAX);
			vote_comment_req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			vote_comment_req.send(data);
		}
		catch(e)
		{
			alert("DoComments was unable to submit your vote because it could not contact its serverside handler. (Error 4)");
			return;
		}
	}
}

//==============================================================================
function HighlightHiddenComment(which_comment)
{
	highlight_comment_id = which_comment;
	paginate = false;
	latest_comment_id = 0;
	RefreshComments();
}

//==============================================================================
function SetAsReplyTo(which_comment)
{
	var html = "";
	
	if(which_comment != null)
	{
		for(var i = 0; i < comments.length; i++)
		{
			if(comments[i]["comment_id"] == which_comment)
				break;
		}
		
		is_reply = true;
		parent_comment_id = comments[i]["comment_id"];
		
		html += '<table cellpadding="0" cellspacing="0">';
		html += '	<tr>';
		html += '		<td colspan="2" style="height:1px;"></td>';
		html += '	</tr>';
		html += '	<tr>';
		html += '		<td valign="middle">';
		html += '			<input checked id="docomments_post_contents_is_reply" onclick="javascript:SetAsReplyTo(null);" type="checkbox">';
		html += '		</td>';
		html += '		<td valign="middle">';
		html += '			<nobr><font onclick="javascript:document.getElementById(\'docomments_post_contents_is_reply\').click();" style="color:' + DOCOMMENTS_TEXT_COLOR + ';cursor:pointer;cursor:hand;font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">&nbsp;Post my message as a reply and preface it with @</font><font onclick="javascript:HighlightHiddenComment(' + parent_comment_id + ');" style="color:' + DOCOMMENTS_LINK_COLOR + ';cursor:pointer;cursor:hand;font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';text-decoration:' + DOCOMMENTS_LINK_TEXT_DECORATION + ';">' + comments[i]["author_name"] + '</font><font onclick="javascript:document.getElementById(\'docomments_post_contents_is_reply\').click();" style="color:' + DOCOMMENTS_TEXT_COLOR + ';cursor:pointer;cursor:hand;font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">:</font></nobr>';
		html += '		</td>';
		html += '	</tr>';
		html += '	<tr>';
		html += '		<td colspan="2" style="height:1px;"></td>';
		html += '	</tr>';
		html += '</table>';
	}
	else
	{
		is_reply = false;
		parent_comment_id = null;
		
		alert("Your message will no longer be posted as a reply.");
	}
	
	document.getElementById("docomments_post_contents_is_reply_container").innerHTML = html;
	
	if(which_comment != null)
	{
		window.location = "#docomments_post_form";
		ShowPostCommentForm();
	}
}

//==============================================================================
function PostCommentHandler()
{
	if(post_comment_req.readyState == 4)
	{
		if(post_comment_req.status == 200)
		{
			if(post_comment_req.responseText != null)
			{
				switch(post_comment_req.responseText.substring(0,1))
				{
					case RESULT_OK:
						ResponseSet(post_comment_req.responseText);
						if(ResponseReadChar() == "y")
						{
							alert(DOCOMMENTS_MESSAGE_ACCEPTED_FOR_MODERATION);
						}
						else	// now live
						{
							document.getElementById("docomments_post_contents_comment").value = "";
							UpdateNumCharsRemaining("docomments_post_contents_comment","docomments_post_contents_comment_title");
							ChangePage(1);
						}
						setTimeout("HidePostCommentForm()",POST_FORM_CLOSE_DELAY);
						break;
					case RESULT_FAILED:
						ResponseSet(post_comment_req.responseText);
						alert(ResponseReadString());
						break;
					default:	// unrecognized system response
						alert("DoComments was unable to post your comment because the system's response was unrecognized. Please try again.");
						break;
				}
			}
			else	// no system response
			{
				alert("DoComments was unable to post your comment because the system did not respond. Please try again.");
			}
			
			document.getElementById("docomments_post_contents_cancel_button").disabled = false;
			document.getElementById("docomments_post_contents_post_comment_button").disabled = false;
			document.getElementById("docomments_post_contents_post_comment_button").value = "Post Comment";
		}
	}
}

//==============================================================================
function PostComment()
{
	// validate
	if(document.getElementById("docomments_post_contents_author_name").value == "")
	{
		alert("Please enter your name (your first name or a nickname is fine).");
		document.getElementById("docomments_post_contents_author_name").focus();
		return;
	}
				
	if(document.getElementById("docomments_post_contents_author_email_addr").value != "" && (document.getElementById("docomments_post_contents_author_email_addr").value.indexOf("@") == -1 || document.getElementById("docomments_post_contents_author_email_addr").value.indexOf(".") == -1))
	{
		alert("The email address that you've entered doesn't appear to be valid. Please enter your valid email address.");
		document.getElementById("docomments_post_contents_author_email_addr").focus();
		return;
	}
	
	if(document.getElementById("docomments_post_contents_author_email_on_reply").checked && document.getElementById("docomments_post_contents_author_email_addr").value == "")
	{
		alert("If you'd like DoComments to notify you of replies to your comment, please enter your valid email address.");
		document.getElementById("docomments_post_contents_author_email_addr").focus();
		return;
	}
				
	if(document.getElementById("docomments_post_contents_author_url").value != "" && document.getElementById("docomments_post_contents_author_url").value.indexOf("http") == -1)
	{
		alert("Please enter a valid Web address (example: http://jerrata.com) to which this comment will point.");
		document.getElementById("docomments_post_contents_author_url").focus();
		return;
	}
				
	if(document.getElementById("docomments_post_contents_comment").value == "" || document.getElementById("docomments_post_contents_comment").value.length > COMMENT_MAXLENGTH)
	{
		alert("Please enter a comment that's between 1 and " + COMMENT_MAXLENGTH + " characters in length, inclusive.");
		document.getElementById("docomments_post_contents_comment").focus();
		return;
	}
	
	if(document.getElementById("docomments_post_contents_captcha_entered").value == "")
	{
		alert("Please enter your answer to the captcha into the highlighted field.");
		document.getElementById("docomments_post_contents_captcha_entered").focus();
		return;
	}
	
	// determine where DoComments.php is
	var DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW = "";
	var DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW = "";
	
	if(DOCOMMENTS_USING_HTTPS)
	{
		DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += "https://";
		DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += "https://www.";
	}
	else
	{
		DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += "http://";
		DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += "http://www.";
	}
	
	DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += DOCOMMENTS_LOCATION + "DoComments.php";
	DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += DOCOMMENTS_LOCATION + "DoComments.php";

	// prepare request
	var data = "topic_name=" + encodeURIComponent(docomments_topic);
	data += "&author_name=" + encodeURIComponent(document.getElementById("docomments_post_contents_author_name").value);
	
	if(document.getElementById("docomments_post_contents_author_email_addr").value != "")
	{
		data += "&author_email_addr_exists=y";
		data += "&author_email_addr=" + encodeURIComponent(document.getElementById("docomments_post_contents_author_email_addr").value);
	}
	else
	{
		data += "&author_email_addr_exists=n";
		data += "&author_email_addr=noexist";
	}
	
	if(document.getElementById("docomments_post_contents_author_email_on_reply").checked)
		data += "&author_email_on_reply=y";
	else
		data += "&author_email_on_reply=n";
		
	if(document.getElementById("docomments_post_contents_author_url").value != "")
	{
		data += "&author_url_exists=y";
		data += "&author_url=" + encodeURIComponent(document.getElementById("docomments_post_contents_author_url").value);
	}
	else
	{
		data += "&author_url_exists=n";
		data += "&author_url=noexist";
	}
	
	data += "&comment_rating=" + encodeURIComponent(document.getElementById("docomments_post_contents_rating").value);
	data += "&comment_text=" + encodeURIComponent(document.getElementById("docomments_post_contents_comment").value);
	data += "&captcha_a=" + encodeURIComponent(captcha_a);
	data += "&captcha_entered=" + encodeURIComponent(document.getElementById("docomments_post_contents_captcha_entered").value.toLowerCase());
	
	if(is_reply)
	{
		data += "&is_reply=y";
		data += "&parent_comment_id=" + encodeURIComponent(parent_comment_id);
	}
	else
	{
		data += "&is_reply=n";
		data += "&parent_comment_id=0";
	}
	
	// update gui
	document.getElementById("docomments_post_contents_cancel_button").disabled = true;
	document.getElementById("docomments_post_contents_post_comment_button").value = "Posting comment...";
	document.getElementById("docomments_post_contents_post_comment_button").disabled = true;
	
	// request
	try
	{
		if(window.XMLHttpRequest)
			post_comment_req = new XMLHttpRequest();
		else
			post_comment_req = new ActiveXObject("Microsoft.XMLHTTP");
			
		post_comment_req.onreadystatechange = PostCommentHandler;
		post_comment_req.open("POST",DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW + "?" + DOCOMMENTS_ACTION + "=" + DOCOMMENTS_ACTION_POST_COMMENT,ASYNCHRONOUS_AJAX);
		post_comment_req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		post_comment_req.send(data);
	}
	catch(e)
	{
		try
		{
			if(window.XMLHttpRequest)
				post_comment_req = new XMLHttpRequest();
			else
				post_comment_req = new ActiveXObject("Microsoft.XMLHTTP");
				
			post_comment_req.onreadystatechange = PostCommentHandler;
			post_comment_req.open("POST",DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW + "?" + DOCOMMENTS_ACTION + "=" + DOCOMMENTS_ACTION_POST_COMMENT,ASYNCHRONOUS_AJAX);
			post_comment_req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			post_comment_req.send(data);
		}
		catch(e)
		{
			alert("DoComments was unable to post your comment because it could not contact its serverside handler. (Error 3)");
			document.getElementById("docomments_post_contents_cancel_button").disabled = false;
			document.getElementById("docomments_post_contents_post_comment_button").disabled = false;
			document.getElementById("docomments_post_contents_post_comment_button").value = "Post Comment";
			return;
		}
	}
}

//==============================================================================
function ChangePostMethod(which_method)
{
	if(which_method != "anonymous" && which_method != "with_my_details")
	{
		ChangePostMethod("anonymous");
		return;
	}
	
	switch(which_method)
	{
		case "anonymous":
			document.getElementById("docomments_post_contents_author_name").value = "Anonymous";
			document.getElementById("docomments_post_contents_author_email_addr").value = "";
			document.getElementById("docomments_post_contents_author_email_on_reply").checked = false;
			document.getElementById("docomments_post_contents_author_url").value = "";
			
			document.getElementById("docomments_post_contents_author_name").disabled = true;
			document.getElementById("docomments_post_contents_author_email_addr").disabled = true;
			document.getElementById("docomments_post_contents_author_email_on_reply").disabled = true;
			document.getElementById("docomments_post_contents_author_url").disabled = true;
			break;
		case "with_my_details":
			document.getElementById("docomments_post_contents_author_name").disabled = false;
			document.getElementById("docomments_post_contents_author_name").value = "";
			document.getElementById("docomments_post_contents_author_email_addr").disabled = false;
			document.getElementById("docomments_post_contents_author_email_on_reply").disabled = false;
			document.getElementById("docomments_post_contents_author_url").disabled = false;
			document.getElementById("docomments_post_contents_author_name").focus();
			break;
	}
}

//==============================================================================
function UpdateNumCharsRemaining(which_textarea,which_title)
{
	var num_chars_left = COMMENT_MAXLENGTH - document.getElementById(which_textarea).value.length;
	
	switch(num_chars_left)
	{
		case 0:
			document.getElementById(which_title).innerHTML = "Comment: (No characters remaining; no HTML, please)";
			break;
		case 1:
			document.getElementById(which_title).innerHTML = "Comment: (1 character remaining; no HTML, please)";
			break;
		case -1:
			document.getElementById(which_title).innerHTML = "Comment: (-1 character remaining; no HTML, please)";
			break;
		default:
			document.getElementById(which_title).innerHTML = "Comment: (" + num_chars_left + " characters remaining; no HTML, please)";
			break;
	}
}

//==============================================================================
function CommentIsVisible(which_comment)
{
	if(comments == null)
		return false;
		
	for(var i = 0; i < comments.length; i++)
	{
		if(comments[i]["comment_id"] == which_comment)
			return true;
	}
	
	return false;
}

//==============================================================================
function RenderComments()
{
	var html = "";
	
	// render comments
	if(comments == null)
	{
		html += '<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">No comments have been posted under this topic.</font>';
	}
	else
	{
		for(var i = 0; i < comments.length; i++)
		{
			html += '<table cellpadding="0" cellspacing="0" style="width:100%;">';
			html += '	<tr>';
			html += '		<td style="border-bottom:1px solid ' + DOCOMMENTS_BYLINE_BOTTOM_BORDER_COLOR + ';text-align:left;">';
			html += '			<nobr>';
			html += '				<a name="comment' + comments[i]["comment_id"] + '">';
			
			if(comments[i]["author_url_exists"])
				html += '<a href="' + comments[i]["author_url"] + '" style="color:' + DOCOMMENTS_LINK_COLOR + ';text-decoration:' + DOCOMMENTS_LINK_TEXT_DECORATION + ';"><font style="font-family:' + DOCOMMENTS_LARGE_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_LARGE_TEXT_FONT_SIZE + ';">' + comments[i]["author_name"] + '</font></a><font style="font-family:' + DOCOMMENTS_LARGE_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_LARGE_TEXT_FONT_SIZE + ';">&nbsp;</font>';
			else
				html += '<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_LARGE_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_LARGE_TEXT_FONT_SIZE + ';">' + comments[i]["author_name"] + '&nbsp;</font>';
				
			html += '</a><font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">';
			
			if(comments[i]["is_rated"])
				html += 'rates this ' + comments[i]["comment_rating"] + '/5 and ';
				
			html += 'writes...</font>';
			html += '			</nobr>';
			html += '		</td>';
			html += '		<td style="border-bottom:1px solid ' + DOCOMMENTS_BYLINE_BOTTOM_BORDER_COLOR + ';text-align:right;">';
			html += '			<nobr>';
			html += '				<font style="color:' + DOCOMMENTS_GOOD_VOTES_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">' + comments[i]["num_good_votes"] + '</font><font style="font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">&nbsp;&nbsp;</font><font onclick="javascript:VoteCommentAs(' + comments[i]["comment_id"] + ',\'good\');" onmouseout="this.style.color = \'' + DOCOMMENTS_SYMBOL_COLOR_NO_HOVER + '\';" onmouseover="this.style.color = \'' + DOCOMMENTS_SYMBOL_COLOR_HOVER + '\';" style="color:' + DOCOMMENTS_SYMBOL_COLOR_NO_HOVER + ';cursor:pointer;cursor:hand;font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';"><strong>&lt;3</strong></font>';			
			html += '				<font style="color:' + DOCOMMENTS_SYMBOL_COLOR_NO_HOVER + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">&nbsp;&nbsp;&nbsp;</font>';
			html += '				<font style="color:' + DOCOMMENTS_BAD_VOTES_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">' + comments[i]["num_bad_votes"] + '</font><font style="font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">&nbsp;&nbsp;</font><font onclick="javascript:VoteCommentAs(' + comments[i]["comment_id"] + ',\'bad\');" onmouseout="this.style.color = \'' + DOCOMMENTS_SYMBOL_COLOR_NO_HOVER + '\';" onmouseover="this.style.color = \'' + DOCOMMENTS_SYMBOL_COLOR_HOVER + '\';" style="color:' + DOCOMMENTS_SYMBOL_COLOR_NO_HOVER + ';cursor:pointer;cursor:hand;font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';"><strong>&lt;/3</strong></font>';
			html += '				<font style="color:' + DOCOMMENTS_SYMBOL_COLOR_NO_HOVER + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">&nbsp;&nbsp;&nbsp;</font>';
			html += '				<font onclick="SetAsReplyTo(' + comments[i]["comment_id"] + ');" style="color:' + DOCOMMENTS_LINK_COLOR + ';cursor:pointer;cursor:hand;font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';text-decoration:' + DOCOMMENTS_LINK_TEXT_DECORATION + ';">reply</font>';
			html += '			</nobr>';
			html += '		</td>';
			html += '	</tr>';
			html += '	<tr>';
			html += '		<td colspan="2" style="height:' + DOCOMMENTS_SPACING_COMMENT_CUSHION + 'px;';

			if(comments[i]["do_hilite"])
				html += 'background-color:' + DOCOMMENTS_ADMIN_COMMENT_BACKGROUND_COLOR + ';';
			else
				html += 'background-color:' + DOCOMMENTS_GUEST_COMMENT_BACKGROUND_COLOR + ';';
				
			html += '"></td>';
			html += '	</tr>';
			html += '	<tr>';
			html += '		<td colspan="2" style="';
			
			if(comments[i]["do_hilite"])
				html += 'background-color:' + DOCOMMENTS_ADMIN_COMMENT_BACKGROUND_COLOR + ';';
			else
				html += 'background-color:' + DOCOMMENTS_GUEST_COMMENT_BACKGROUND_COLOR + ';';
				
			html += '">';
			html += '			<table cellpadding="5" cellspacing="0">';
			html += '				<tr>';
			html += '					<td>';
			
			if(comments[i]["is_reply"])
			{
				if(comments[i]["parent_comment_author_name"] != null)
				{
					if(CommentIsVisible(comments[i]["parent_comment_id"]))
						html += '<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">@</font><a href="#comment' + comments[i]["parent_comment_id"] + '" style="color:' + DOCOMMENTS_LINK_COLOR + ';text-decoration:' + DOCOMMENTS_LINK_TEXT_DECORATION + ';"><font style="font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">' + comments[i]["parent_comment_author_name"] + '</font></a><font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">:</font> ';
					else
						html += '<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">@</font><font onclick="javascript:HighlightHiddenComment(' + comments[i]["parent_comment_id"] + ');" style="color:' + DOCOMMENTS_LINK_COLOR + ';cursor:pointer;cursor:hand;font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';text-decoration:' + DOCOMMENTS_LINK_TEXT_DECORATION + ';">' + comments[i]["parent_comment_author_name"] + '</font><font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">:</font> ';
				}
				else
				{
					if(CommentIsVisible(comments[i]["parent_comment_id"]))
						html += '<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">@</font><a href="#comment' + comments[i]["parent_comment_id"] + '" style="color:' + DOCOMMENTS_LINK_COLOR + ';text-decoration:' + DOCOMMENTS_LINK_TEXT_DECORATION + ';"><font style="font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">comment #' + comments[i]["parent_comment_id"] + '</font></a><font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">:</font> ';
					else
						html += '<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">@</font><font onclick="javascript:HighlightHiddenComment(' + comments[i]["parent_comment_id"] + ');" style="color:' + DOCOMMENTS_LINK_COLOR + ';cursor:pointer;cursor:hand;font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';text-decoration:' + DOCOMMENTS_LINK_TEXT_DECORATION + ';">comment #' + comments[i]["parent_comment_id"] + '</font><font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">:</font> ';
				}
			}
			
			html += '						<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">' + comments[i]["comment"] + '</font>';
			html += '					</td>';
			html += '				</tr>';
			html += '			</table>';
			html += '		</td>';
			html += '	</tr>';
			html += '	<tr>';
			html += '		<td colspan="2" style="height:' + DOCOMMENTS_SPACING_COMMENT_CUSHION + 'px;';
			
			if(comments[i]["do_hilite"])
				html += 'background-color:' + DOCOMMENTS_ADMIN_COMMENT_BACKGROUND_COLOR + ';';
			else
				html += 'background-color:' + DOCOMMENTS_GUEST_COMMENT_BACKGROUND_COLOR + ';';
				
			html += '"></td>';
			html += '	</tr>';
			html += '	<tr>';
			html += '		<td colspan="2" style="text-align:right;">';
			html += '			<nobr>';
			html += '				<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_SMALL_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_SMALL_TEXT_FONT_SIZE + ';">Posted ' + comments[i]["t"] + '</font>';
			html += '			</nobr>';
			html += '		</td>';
			html += '	</tr>';
			
			if(i < (comments.length - 1))
			{
				html += '<tr>';
				html += '	<td colspan="2" style="height:' + DOCOMMENTS_SPACING_BETWEEN_COMMENTS + 'px;"></td>';
				html += '</tr>';
			}
			
			html += '</table>';
		}
	}
	
	document.getElementById("docomments_comments_container").innerHTML = html;
	
	// render page selector
	if(num_pages_of_comments > 1)
	{
		if(document.getElementById("docomments_page_selector").options.length != num_pages_of_comments)
		{
			document.getElementById("docomments_page_selector").options.length = 0;
			
			for(var f = 1; f <= num_pages_of_comments; f++)
				document.getElementById("docomments_page_selector").options[f - 1] = new Option(String(f),String(f));
		}
		
		for(var g = 0; g < document.getElementById("docomments_page_selector").options.length; g++)
		{
			if(document.getElementById("docomments_page_selector").options[g].value == String(cur_pageno))
				document.getElementById("docomments_page_selector").options[g].selected = true;
		}
		
		if(cur_pageno == 1)
			document.getElementById("docomments_read_contents_prev_page_button").disabled = true;
		else
			document.getElementById("docomments_read_contents_prev_page_button").disabled = false;
			
		if(cur_pageno < num_pages_of_comments)
			document.getElementById("docomments_read_contents_next_page_button").disabled = false;
		else
			document.getElementById("docomments_read_contents_next_page_button").disabled = true;
		
		document.getElementById("docomments_page_selector_container").style.visibility = "visible";
	}
	else
	{
		document.getElementById("docomments_page_selector_container").style.visibility = "hidden";
	}
	
	// render topic rating
	if(document.getElementById("docomments_topic_rating") != null)
	{
		if(topic_rated)
		{
			if(DOCOMMENTS_SHOW_TOPIC_RATINGS_AS_PERCENTAGES)
				document.getElementById("docomments_topic_rating").innerHTML = String(Math.round(parseFloat(100) * (parseFloat(topic_rating) / parseFloat(5)))) + "%";
			else
				document.getElementById("docomments_topic_rating").innerHTML = topic_rating + "/5";
		}
		else
		{
			document.getElementById("docomments_topic_rating").innerHTML = "Not rated";
		}
	}
	
	// render num comments in topic
	if(document.getElementById("docomments_num_comments_in_topic") != null)
		document.getElementById("docomments_num_comments_in_topic").innerHTML = num_comments_in_topic;
}

//==============================================================================
function ChangePage(new_pageno)
{
	latest_comment_id = 0;
	cur_pageno = parseInt(new_pageno);
	RefreshComments();
}

//==============================================================================
function GetCommentsHandler()
{
	if(get_comments_req.readyState == 4)
	{
		if(get_comments_req.status == 200)
		{
			if(get_comments_req.responseText != null)
			{
				switch(get_comments_req.responseText.substring(0,1))
				{
					case RESULT_OK:
						ResponseSet(get_comments_req.responseText);
						
						if(ResponseReadChar() == "y")
						{
							add_others_comments_in_realtime = true;
							add_others_comments_in_realtime_interval = ResponseReadInt();
						}
						else
						{
							add_others_comments_in_realtime = false;
						}
						
						COMMENT_MAXLENGTH = ResponseReadInt();
						
						if(document.getElementById("docomments_post_contents_comment_title").innerHTML == "")
							UpdateNumCharsRemaining("docomments_post_contents_comment","docomments_post_contents_comment_title");
							
						if(latest_comment_id == 0)
						{
							if(document.getElementById("docomments_post_contents_captcha_q").innerHTML == "")
							{
								document.getElementById("docomments_post_contents_captcha_q").innerHTML = ResponseReadString();
								captcha_a = ResponseReadString();
							}
							else	// discard unneeded captcha
							{
								ResponseReadString();
								ResponseReadString();
							}
						}
						
						if(ResponseReadChar() == "y")	// client needs update
						{
							num_pages_of_comments = ResponseReadInt();
							if(num_pages_of_comments > 0)
							{
								num_comments_in_topic = ResponseReadInt();
								latest_comment_id = ResponseReadInt();
								
								if(ResponseReadChar() == "y")
								{
									topic_rated = true;
									topic_rating = ResponseReadString();
								}
								else
								{
									topic_rated = false;
								}
								
								num_comments_on_page = ResponseReadInt();
								if(num_comments_on_page > 0)
								{
									var new_comments = new Array();
									
									for(var i = 0; i < num_comments_on_page; i++)
									{
										new_comments[i] = new Array();
										new_comments[i]["comment_id"] = ResponseReadInt();
										
										if(ResponseReadChar() == "y")
										{
											new_comments[i]["is_reply"] = true;
											new_comments[i]["parent_comment_id"] = ResponseReadInt();
											
											if(ResponseReadChar() == "y")
												new_comments[i]["parent_comment_author_name"] = ResponseReadString();
											else
												new_comments[i]["parent_comment_author_name"] = null;
										}
										else
										{
											new_comments[i]["is_reply"] = false;
										}
										
										new_comments[i]["author_name"] = ResponseReadString();
										
										if(ResponseReadChar() == "y")
											new_comments[i]["do_hilite"] = true;
										else
											new_comments[i]["do_hilite"] = false;
										
										if(ResponseReadChar() == "y")
										{
											new_comments[i]["author_url_exists"] = true;
											new_comments[i]["author_url"] = ResponseReadString();
										}
										else
										{
											new_comments[i]["author_url_exists"] = false;
										}
										
										if(ResponseReadChar() == "y")
										{
											new_comments[i]["is_rated"] = true;
											new_comments[i]["comment_rating"] = ResponseReadInt();
										}
										else
										{
											new_comments[i]["is_rated"] = false;
										}
										
										new_comments[i]["comment"] = ResponseReadString();
										new_comments[i]["num_good_votes"] = ResponseReadInt();
										new_comments[i]["num_bad_votes"] = ResponseReadInt();
										new_comments[i]["t"] = ResponseReadString();
									}
									
									comments = new_comments;
								}
								else
								{
									comments = null;
								}
							}
							else
							{
								num_comments_in_topic = 0;
								latest_comment_id = 0;
								topic_rated = false;
								num_comments_on_page = 0;
								comments = null;
							}
						}
						
						RenderComments();
						
						if(highlight_comment_id != null)
						{
							window.location = '#comment' + highlight_comment_id;
							highlight_comment_id = null;
						}
						
						// reread comments after awhile, if applicable
						if(add_others_comments_in_realtime)
							refresh_comments_timeout = setTimeout("RefreshComments()",add_others_comments_in_realtime_interval);
						break;
					case RESULT_FAILED:
						ResponseSet(get_comments_req.responseText);
						DisplayError(ResponseReadString());
						break;
					default:	// unrecognized system response
						refresh_comments_timeout = setTimeout("RefreshComments()",RETRY_INTERVAL);
						break;
				}
			}
			else	// no system response
			{
				refresh_comments_timeout = setTimeout("RefreshComments()",RETRY_INTERVAL);
			}
		}
	}
}

//==============================================================================
function RefreshComments()
{
	if(refresh_comments_timeout != null)
	{
		clearTimeout(refresh_comments_timeout);
		refresh_comments_timeout = null;
	}
	
	GetComments(cur_pageno);
}
	
//==============================================================================
function GetComments(pageno)
{
	// determine where DoComments.php is
	var DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW = "";
	var DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW = "";
	
	if(DOCOMMENTS_USING_HTTPS)
	{
		DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += "https://";
		DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += "https://www.";
	}
	else
	{
		DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += "http://";
		DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += "http://www.";
	}
	
	DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW += DOCOMMENTS_LOCATION + "DoComments.php";
	DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW += DOCOMMENTS_LOCATION + "DoComments.php";

	// prepare request
	var data = "topic_name=" + encodeURIComponent(docomments_topic);
	data += "&pageno=" + encodeURIComponent(pageno);
	data += "&latest_comment_id=" + encodeURIComponent(latest_comment_id);
	
	if(paginate)
		data += "&paginate=y";
	else
		data += "&paginate=n";

	// request
	try
	{
		if(window.XMLHttpRequest)
			get_comments_req = new XMLHttpRequest();
		else
			get_comments_req = new ActiveXObject("Microsoft.XMLHTTP");
			
		get_comments_req.onreadystatechange = GetCommentsHandler;
		get_comments_req.open("POST",DOCOMMENTS_AJAX_HANDLER_LOCATION_SANS_WWW + "?" + DOCOMMENTS_ACTION + "=" + DOCOMMENTS_ACTION_GET_COMMENTS,ASYNCHRONOUS_AJAX);
		get_comments_req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		get_comments_req.send(data);
	}
	catch(e)
	{
		try
		{
			if(window.XMLHttpRequest)
				get_comments_req = new XMLHttpRequest();
			else
				get_comments_req = new ActiveXObject("Microsoft.XMLHTTP");
				
			get_comments_req.onreadystatechange = GetCommentsHandler;
			get_comments_req.open("POST",DOCOMMENTS_AJAX_HANDLER_LOCATION_WITH_WWW + "?" + DOCOMMENTS_ACTION + "=" + DOCOMMENTS_ACTION_GET_COMMENTS,ASYNCHRONOUS_AJAX);
			get_comments_req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			get_comments_req.send(data);
		}
		catch(e)
		{
			DisplayError("DoComments was unable to serve comments for this topic because it could not contact its serverside handler. (Error 2)");
			return;
		}
	}
}

//==============================================================================
function DisplayError(message)
{
	document.getElementById("docomments_read").innerHTML = '<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">' + message + '</font>';
}

//==============================================================================
// RESPONSE
//==============================================================================
function ResponseReadString()
{
	var string_length = ResponseReadInt();
	var s = response.substr(response_caret,string_length);
	response_caret += string_length;
	return s;
}

//==============================================================================
function ResponseReadChar()
{
	var c = response.substr(response_caret,1);
	response_caret++;
	return c;
}

//==============================================================================
function ResponseReadInt()
{
	var index = response.indexOf("|",response_caret+1);
	var a = parseInt(response.substring(response_caret,index));
	response_caret = index + 1;
	return a;
}

//==============================================================================
function ResponseSet(s)
{
	response = s;
	response_caret = 1;	// autoskip the first character (status code)
}

//==============================================================================
document.getElementById("docomments_comments_container").innerHTML = '<font style="color:' + DOCOMMENTS_TEXT_COLOR + ';font-family:' + DOCOMMENTS_MEDIUM_TEXT_FONT_FACE + ';font-size:' + DOCOMMENTS_MEDIUM_TEXT_FONT_SIZE + ';">Loading comments. Please wait...</font>';
ChangePage(1);
