var MyScore;
var Charts = false;
var TypeConst = "Type your comments here...";

function CloseAllExcept(i, j)
{
	if (j != 0 && OpenFavoriteDebateBox != "")
		CloseFavoriteDebateBox(document.getElementById("addFavoriteDebate" + i));
	else if (j != 1 && OpenReportObjBox != "")
		CloseReportObjBox(document.getElementById("reportDebate" + i));
}

function HideComments()
{
	document.getElementById("postCommentLink").style.display = "block";
	document.getElementById("formNewComment").style.display = "none";
}

function LoadScore(Total, Score)
{
	Total = parseInt(Total);
	Score = parseInt(Score);
	
	var o = document.getElementById("scoreYes");
	var q = document.getElementById("scoreNo");
	var r = document.getElementById("scoreTotal");
	
	if (Total < 0)
		r.innerHTML = Total;
	else
		r.innerHTML = "+" + Total;
	
	if (Score == 0)
	{
		o.style.borderColor = "";
		o.style.backgroundColor = "";
		o.style.color = "";
		o.style.cursor = "pointer";
		
		q.style.borderColor = "#2d55af";
		q.style.backgroundColor = "#3764d2";
		q.style.color = "#ffffff";
		q.style.cursor = "default";
	}
	else if (Score == 1)
	{
		o.style.borderColor = "#2d55af";
		o.style.backgroundColor = "#3764d2";
		o.style.color = "#ffffff";
		o.style.cursor = "default";
		
		q.style.borderColor = "";
		q.style.backgroundColor = "";
		q.style.color = "";
		q.style.cursor = "pointer";
	}
	
	MyScore = Score;
}

function LoadTab(t)
{
	t = parseInt(t);
	
	// Reformat the tabs.
	var o = document.getElementById("tabs");
	o.className = "focus" + t;
	
	// Display the requested content.
	var p = new Array(2);
	p[0] = document.getElementById("rounds");
	p[1] = document.getElementById("comments");
	p[2] = document.getElementById("votes");
	
	for (i = 0; i < p.length; i++)
	{
		p[i].style.display = "none";
	}
	
	p[t].style.display = "block";
	
	if (ShowCharts == true && t == 2 && Charts == false)
	{
		document.getElementById("votes").innerHTML = "<p>This page is being redesigned to show the voter's picture and username.</p>";//AjaxGet("http://www.debate.org/debates/debate/votes/?id=" + DebateId,false,true);
		Charts = true;
	}
}

function NewCommentBlur(o,p)
{
	if (o.value == "" || o.value == TypeConst)
	{
		o.value = TypeConst;
		o.style.color = "#808080";
		p.innerHTML = FormatNumber(CommentsLenMax,0,0) + " Characters Remaining";
	}
}

function NewCommentFocus(o,p)
{
	if (o.value == TypeConst)
	{
		o.value = "";
		o.style.color = "#000000";
		p.innerHTML = FormatNumber(CommentsLenMax,0,0) + " Characters Remaining";
	}
}

function ShowComments()
{
	document.getElementById("postCommentLink").style.display = "none";
	document.getElementById("formNewComment").style.display = "block";
}

function UpdateScore(Score)
{
	if (MyStats[3] == 1)
		alert("In order to continue, you must first verify your email address. Go to the following web address to verify your email address:\n\nhttp://www.debate.org/verify/");
	else if (MyScore != Score)
	{
		var x = AjaxGet("http://www.debate.org/debates/debate/score/?id=" + DebateId + "&score=" + Score,false,true);
		
		if (x.substring(x.length-4,x.length) != "true")
			alert("An unexpected connection error occurred. Please try your request again. If you continue to encounter problems, please contact Customer Support.")
		else
		{
			x = x.split(",");
			LoadScore(x[0], x[1], x[2]);
		}
	}
}

function VerifyComments(o)
{
	if (o.newComment.value == "" || o.newComment.value == TypeConst) {alert("Type your comments."); o.newComment.focus(); return false;}
	return true;
}
