var OpenFavoriteForumBox = "";

function AddFavoriteForum(BoxObj, Id)
{
	var ShowForm = false;
	if (OpenFavoriteForumBox == BoxObj)
		CloseFavoriteForumBox(BoxObj);
	else
	{
		if (OpenFavoriteForumBox != "")
			CloseFavoriteForumBox(OpenFavoriteForumBox);
		
		BoxObj.style.display = "inline";
		OpenFavoriteForumBox = BoxObj;
		
		var x = "";
		
		if (MyStats == "")
		{
			x += "<p>You must first login before adding this forum topic to your list of favorites.</p>";
			x += "<p><a href=\"http://www.debate.org/login/\">Login to your account.</a></p>";
			x += "<p><a href=\"http://www.debate.org/join/\">Become a member.</a></p>";
		}
		else if (MyStats[3] == 1)
		{
			x += "<p>Before you can add this forum topic to your list of favorites, you will first need to verify your email address.</p>";
			x += "<p><a href=\"http://www.debate.org/verify/\">Verify your email address.</a></p>";
		}
		else
		{
			BoxObj.innerHTML = "Loading...";
			var y = AjaxGet("http://www.debate.org/member/favorites/forums/add/?id=" + Id,false,true);
			y = y.split(",");
			
			if (y == "0")
			{
				ShowForm = true;
				
				x += "<div id=\"confirmTxt\"></div>";
				x += "<form action=\"http://www.debate.org/member/favorites/forums/add/\" id=\"" + BoxObj + "Form\" method=\"get\" onSubmit=\"return SubmitAddFavoriteForum(this);\">";
				x += "<div class=\"check\"><input id=\"notify_0\" name=\"notify_0\" type=\"checkbox\" value=\"true\" checked=\"checked\" /><label for=\"notify_0\">Email me when there are new posts for this forum topic.</label></div>";
				x += "<div class=\"btn\"><input name=\"submit\" type=\"submit\" value=\"Add to My Favorites\" /></div>";
				x += "<input id=\"add\" name=\"add\" type=\"hidden\" value=\"true\" />";
				x += "<input id=\"boxId\" name=\"boxId\" type=\"hidden\" value=\"" + BoxObj.id + "\" />";
				x += "<input id=\"id\" name=\"id\" type=\"hidden\" value=\"" + Id + "\" />";
				x += "</form>";
			}
			else if (y == "1")
			{
				x += "<p>You must first login before adding this forum topic to your list of favorites.</p>";
				x += "<p><a href=\"http://www.debate.org/login/\">Login to your account.</a> Or, <a href=\"http://www.debate.org/join/\">become a member.</a></p>";
			}
			else if (y == "2")
			{
				x += "<p>Before you can add this forum topic to your list of favorites, you will first need to verify your email address.</p>";
				x += "<p><a href=\"http://www.debate.org/verify/\">Verify your email address.</a></p>";
			}
			else if (y == "3")
				x += "<p>This forum topic cannot be added to your list of favorites at this time.</p>";
			else if (y == "4")
			{
				x += "<p>This forum topic is already on your list of favorites.</p>";
				x += "<p><a href=\"http://www.debate.org/member/favorites/forums/\">View your favorite forum topics.</a></p>";
			}
			else
				x += "<p>An unexpected connection error occurred. Please try your request again. If you continue to encounter problems, please contact <a href=\"http://www.debate.org/help/contact/?subject=1\">Customer Support</a>.</p>";
		}
		x = "<div class=\"close\"><a href=\"#\" onClick=\"CloseFavoriteForumBox(document.getElementById('" + BoxObj.id + "')); return false;\">Close Window</a></div><div class=\"title\">Add this Forum Topic to My Favorites</div>" + x;
		BoxObj.innerHTML = x;
	}
	
	if (ShowForm == true)
		var o = document.getElementById(BoxObj + "Form");
}

function CloseFavoriteForumBox(o)
{
	OpenFavoriteForumBox = "";
	o.style.display = "none";
	o.innerHTML = "";
}

function SubmitAddFavoriteForum(o)
{
	var x = AjaxGet("http://www.debate.org/member/favorites/forums/add/?add=true&id=" + o.id.value + "&notify_0=" + o.notify_0.checked,false,true);
	
	if (x.toLowerCase() == "true")
	{
		document.getElementById(o.boxId.value).style.height = "100px";
		o.style.display = "none";
		document.getElementById("confirmTxt").innerHTML = "This forum topic has been added to your list of favorites.<br /><br /><a href=\"http://www.debate.org/member/favorites/forums/\">Manage your list of favorite forum topics.</a>";
	}
	else
		alert("An unexpected connection error occurred. Please try your request again. If you continue to encounter problems, please contact Customer Support.");
	
	return false;
}
