function RecommendComment(comment_id)
{
	try
	{
		document.getElementById("Comment_Action_Form").action = "/site/comments/recommend.asp?rand=" + RandomNumber(10000);
		document.getElementById("comments_action_form_id").value = comment_id;
		document.getElementById("Comment_Action_Form").submit();
	}
	catch (err)
	{
		alert("RecommendComment() - " + err.description);
	}
}

function ProcessCommentRecommendResult(text)
{
	try
	{
		alert(text);
	}
	catch (err)
	{
		alert("ProcessCommentRecommendResult() - " + err.description);
	}
}

function ReportComment(comment_id)
{
	try
	{
		if ((document.getElementById("comments_allowanonymouscommentreports").value == "1") || (document.getElementById("comments_loggedin").value == "1"))
		{
			if (document.getElementById("report_comment_table").style.display == "none")
			{
				document.getElementById("ReportCommentForm").action = "/site/comments/report.asp?rand=" + RandomNumber(10000);
				document.getElementById("report_comment_id").value = comment_id;
				document.getElementById("report_comment_details").value = "";
				document.getElementById("report_comment_table").style.display = "";
				PositionCommentReportForm();
			}
		}
		else
		{
			alert("You need to be signed in to report comments!");
		}
	}
	catch (err)
	{
		alert("RecommendComment() - " + err.description);
	}
}

function PositionCommentReportForm()
{
	try
	{
		if (document.getElementById("report_comment_table").style.display != "none")
		{
			var height = parseInt(document.getElementById("report_comment_table").style.height);
			var width = parseInt(document.getElementById("report_comment_table").style.width);

			var avail_height = parseInt(GetClientHeight());
			var avail_width = parseInt(GetClientWidth());

			var scroll_top =  parseInt(GetScrollTop());
			var scroll_left = parseInt(GetScrollLeft());

			var top = parseInt((avail_height - height) / 2);
			var left = parseInt((avail_width - width) / 2);

			if (avail_height == 8)
				top = scroll_top + 200;
			else
				top = top + scroll_top;

			left = left + scroll_left;

			if (top < 0)
				top = 0;

			if (left < 0)
				left = 0;

			document.getElementById("report_comment_table").style.left = left;
			document.getElementById("report_comment_table").style.top = top;
		}
	}
	catch (err)
	{
		//alert("PositionCommentReportForm() - " + err.description);
	}
}

function ProcessCommentReportResult(result)
{
	try
	{
		document.getElementById("report_comment_table").style.display = "none";
		alert(result);
	}
	catch (err)
	{
		alert("ProcessCommentReportResult() - " + err.description);
	}
}

function AddComment()
{
	try
	{
		if (document.getElementById("add_comment_table").style.display == "none")
		{
			document.getElementById("comment_text").value = "";
			document.getElementById("add_comment_table").style.display = "";
			PositionCommentAddForm();
		}
	}
	catch(err)
	{
		alert("AddComment() - " + err.description);
	}
}

function PositionCommentAddForm()
{
	try
	{
		if (document.getElementById("add_comment_table").style.display != "none")
		{
			var height = parseInt(document.getElementById("add_comment_table").style.height);
			var width = parseInt(document.getElementById("add_comment_table").style.width);

			var avail_height = parseInt(GetClientHeight());
			var avail_width = parseInt(GetClientWidth());

			var scroll_top =  parseInt(GetScrollTop());
			var scroll_left = parseInt(GetScrollLeft());

			var top = parseInt((avail_height - height) / 2);
			var left = parseInt((avail_width - width) / 2);

			if (avail_height == 8)
				top = scroll_top + 200;
			else
				top = top + scroll_top;

			left = left + scroll_left;

			if (top < 0)
				top = 0;

			if (left < 0)
				left = 0;
/*
			var debug_msg = "";
			debug_msg = debug_msg + "height : " + height + "\r\n";
			debug_msg = debug_msg + "width : " + width + "\r\n";
			debug_msg = debug_msg + "avail_height : " + avail_height + "\r\n";
			debug_msg = debug_msg + "avail_width : " + avail_width + "\r\n";
			debug_msg = debug_msg + "scroll_top : " + scroll_top + "\r\n";
			debug_msg = debug_msg + "scroll_left : " + scroll_left + "\r\n";
			debug_msg = debug_msg + "top : " + top + "\r\n";
			debug_msg = debug_msg + "left : " + left + "\r\n";

			alert(debug_msg);
*/
			document.getElementById("add_comment_table").style.left = left;
			document.getElementById("add_comment_table").style.top = top;
		}
	}
	catch (err)
	{
		//alert("PositionCommentAddForm() - " + err.description );
	}
}

function ProcessCommentAddResult(text, a_name)
{
	try
	{
		alert(text);
		document.getElementById("add_comment_table").style.display = "none"
		RefreshComments(a_name);
	}
	catch (err)
	{
		alert("ProcessCommentAddResult() - " + err.description );
	}
}

function RefreshComments(a_name)
{
	try
	{
		var url = location.href;
		if (url.indexOf('#') != -1)
			url = url.substring(0, url.indexOf('#'));

		window.location.href = url + a_name;
		
		// Javascript 1.2
		try
		{
			 window.location.reload(true);
		}
		catch (err)
		{
			// Javascript 1.1
			try
			{
				window.location.replace(url + a_name);
			}
			catch (err) // Javascript 1.0
			{
			}
		}
		
	}
	catch (err)
	{
		alert("RefreshComments() - " + err.description );
	}
}

function GetCommentAnchorPosition(anchorName)
{
	try
	{
		var a_tags = document.getElementsByTagName("a");

		for(var i = 0; i < a_tags.length; i++)
		{
			if(a_tags[i].name == anchorName)
				var anchor = a_tags[i];
		}
	
		if (document.layers)
		{
			return { x: anchor.x, y: anchor.y };
		}
		else if (document.getElementById)
		{
			var coords = {x: 0, y: 0 };
			while (anchor)
			{
				coords.x += anchor.offsetLeft;
				coords.y += anchor.offsetTop;
				anchor = anchor.offsetParent;
			}
			return coords;
		}
	}
	catch(err)
	{
		alert("GetCommentAnchorPosition() - " + err.description);
	}
}

function ScrollMeTo(anchorName)
{
	try
	{
		var coords = GetCommentAnchorPosition(anchorName);
		scrollTo(coords.x , coords.y);
	}
	catch(err)
	{
		alert("ScrollMeTo() - " + err.description);
	}
}

function CheckCommentScroll()
{
	try
	{
		if (String(window.location.hash).indexOf("Comment") > -1)
			ScrollMeTo(String(window.location.hash).replace('#', ''));
	}
	catch(err)
	{}
}

function SortComments(option)
{
	alert("In Development!");
}
