﻿
function ShowNewThread()
{
	document.getElementById("newThread").style.display = "block";
	window.location.hash = "#newThread";
}

function HideNewThread()
{
	document.getElementById("newThread").style.display = "none";
}


function ShowNewComment(id)
{
	document.getElementById(id).style.display = "block";
	window.location.hash = "#" + id;
}

function HideNewComment(id)
{
	document.getElementById(id).style.display = "none";
}

function CommentLoad(isLoggedIn)
{
	if (isLoggedIn)
	{
		var hashString = window.location.hash;
		
		hashString = hashString.substring(1, hashString.length);
		
		var control = document.getElementById(hashString);
		
		if (control)
		{
			control.style.display = "block";
		}
	}
}

function CheckNewComment(titleId, bodyId, errorId)
{
	var errorString = "";
	
	if (titleId != null)
	{
		var titleString = document.getElementById(titleId).value
		titleString = titleString.replace(/\s/g, "");
		if (! titleString.length > 0)
			errorString += "title";
	}
	
	if (bodyId != null)
	{
		var bodyString = document.getElementById(bodyId).value
		bodyString = bodyString.replace(/\s/g, "");
		if (! bodyString.length > 0)
		{
			if (errorString.length > 0)
				errorString += " and ";
		
			errorString += "comment";
		}
	}
	
	if (errorString.length > 0)
		errorString = "Please provide a " + errorString + ".";
	
	if (errorString.length > 0)
	{
		var errorDiv = document.getElementById(errorId);
		errorDiv.style.display = "block";
		errorDiv.innerHTML = errorString;
		return false;
	}
	else
	{
		return true;
	}
}

function CommentDisplayMessage(errorId, message)
{
	var errorDiv = document.getElementById(errorId);
	errorDiv.style.display = "block";
	errorDiv.innerHTML = message;
		
	return false;
}

