var OpenReportObjBox = "";

function FindCheckedReasons(o)
{
	var x = "";
	
	if (o.reason0.checked == true) {x += "0,"}
	if (o.reason1.checked == true) {x += "1,"}
	if (o.reason2.checked == true) {x += "2,"}
	if (o.reason3.checked == true) {x += "3,"}
	if (o.reason4.checked == true) {x += "4,"}
	if (o.reason5.checked == true) {x += "5,"}
	if (o.reason6.checked == true) {x += "6,"}
	if (o.reason7.checked == true) {x += "7,"}
	if (o.reason8.checked == true) {x += "8,"}
	if (o.reason9.checked == true) {x += "9,"}
	
	return x;
}

function FindReportObjName(Type)
{
	if (Type == 0)
		return "debate";
	else if (Type == 1)
		return "argument";
	else if (Type == 2)
		return "comment";
	else if (Type == 3)
		return "photo";
	else if (Type == 4)
		return "profile";
	else if (Type == 5)
		return "topic";
	else if (Type == 6)
		return "post";
}

function ReportObj(BoxObj, Id, SubId, Type)
{
	var ShowForm = false;
	if (OpenReportObjBox == BoxObj)
		CloseReportObjBox(BoxObj);
	else
	{
		if (OpenReportObjBox != "")
			CloseReportObjBox(OpenReportObjBox);
		
		BoxObj.style.display = "inline";
		OpenReportObjBox = BoxObj;
		
		var ObjName = FindReportObjName(Type)
		var x = "";
		
		if (MyStats == "")
		{
			x += "<p>You must first login before reporting this " + ObjName + ".</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 report this " + ObjName + ", 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
		{
			ShowForm = true;
			BoxObj.style.height = "360px";
			
			x += "<div id=\"confirmTxt\"></div>";
			x += "<form action=\"http://www.debate.org/report/\" id=\"" + BoxObj + "Form\" method=\"get\" onSubmit=\"return SubmitReportObj(this);\">";
			x += "<div class=\"check\"><input id=\"reason0\" name=\"reason\" type=\"checkbox\" value=\"0\" /><label for=\"reason0\">Advertising or Spam</label></div>";
			x += "<div class=\"check\"><input id=\"reason1\" name=\"reason\" type=\"checkbox\" value=\"1\" /><label for=\"reason1\">Fraud or Phishing</label></div>";
			x += "<div class=\"check\"><input id=\"reason2\" name=\"reason\" type=\"checkbox\" value=\"2\" /><label for=\"reason2\">Harassment or Privacy Invasion</label></div>";
			x += "<div class=\"check\"><input id=\"reason3\" name=\"reason\" type=\"checkbox\" value=\"3\" /><label for=\"reason3\">Harm to Minors</label></div>";
			x += "<div class=\"check\"><input id=\"reason4\" name=\"reason\" type=\"checkbox\" value=\"4\" /><label for=\"reason4\">Hate Content</label></div>";
			x += "<div class=\"check\"><input id=\"reason5\" name=\"reason\" type=\"checkbox\" value=\"5\" /><label for=\"reason5\">Impersonation or Misrepresentation</label></div>";
			x += "<div class=\"check\"><input id=\"reason6\" name=\"reason\" type=\"checkbox\" value=\"6\" /><label for=\"reason6\">Insulting Other Member(s)</label></div>";
			x += "<div class=\"check\"><input id=\"reason7\" name=\"reason\" type=\"checkbox\" value=\"7\" /><label for=\"reason7\">Nudity or Pornography</label></div>";
			x += "<div class=\"check\"><input id=\"reason8\" name=\"reason\" type=\"checkbox\" value=\"8\" /><label for=\"reason8\">Violence or Threats</label></div>";
			x += "<div class=\"check\"><input id=\"reason9\" name=\"reason\" type=\"checkbox\" value=\"9\" /><label for=\"reason9\">Other (please specify)</label></div>";
			x += "<div class=\"cmtLabel\">Optional Comments:</div>";
			x += "<div class=\"cmtInput\"><input id=\"reportComments\" name=\"reportComments\" type=\"text\" maxlength=\"100\" value=\"\" /></div>";
			x += "<div class=\"btn\"><input name=\"submit\" type=\"submit\" value=\"Send Report\" /></div>";
			x += "<div class=\"notice\">By its very nature, Debate.org can lead to heated exchanges between members. Please do not report content unless it is in clear violation of the <a href=\"http://www.debate.org/legal/terms/\" target=\"legal\">Terms of Use</a>.</div>"
			x += "<input id=\"boxId\" name=\"boxId\" type=\"hidden\" value=\"" + BoxObj.id + "\" />";
			x += "<input id=\"id\" name=\"id\" type=\"hidden\" value=\"" + Id + "\" />";
			x += "<input id=\"subId\" name=\"subId\" type=\"hidden\" value=\"" + SubId + "\" />";
			x += "<input id=\"type\" name=\"type\" type=\"hidden\" value=\"" + Type + "\" />";
			x += "</form>";
		}
		x = "<div class=\"close\"><a href=\"#\" onClick=\"CloseReportObjBox(document.getElementById('" + BoxObj.id + "')); return false;\">Close Window</a></div><div class=\"title\" id=\"reportTitle\">Why are you reporting this " + ObjName + "?</div>" + x;
		BoxObj.innerHTML = x;
	}
	
	if (ShowForm == true)
		var o = document.getElementById(BoxObj + "Form");
}

function CloseReportObjBox(o)
{
	OpenReportObjBox = "";
	o.style.display = "none";
	o.innerHTML = "";
}

function SubmitReportObj(o)
{
	var ObjName = FindReportObjName(o.type.value)
	var Reasons = FindCheckedReasons(o);
	
	if (Reasons == "")
	{
		alert("Select the reason(s) you are reporting this " + ObjName + ".");
	}
	else
	{
		var x = AjaxGet("http://www.debate.org/report/?id=" + o.id.value + "&subId=" + o.subId.value + "&type=" + o.type.value + "&reasons=" + Reasons + "&comments=" + escape(o.reportComments.value),false,true);
		
		if (x.toLowerCase() == "true")
		{
			document.getElementById(o.boxId.value).style.height = "75px";
			o.style.display = "none";
			document.getElementById("reportTitle").innerHTML = "Report Confirmation";
			document.getElementById("confirmTxt").innerHTML = "This " + ObjName + " has been reported to Customer Support. If warranted, our support staff will either edit or remove the " + ObjName + ".<br /><br />Thank you for helping to keep Debate.org a clean and safe place.";
		}
		else
			alert("An unexpected connection error occurred. Please try your request again. If you continue to encounter problems, please contact Customer Support.");
	}
	
	return false;
}
