function report()
{
	this.ajaxURL = "/ajax/forums_report.php";
	this.post_sid = 0;
	this.user_sid = 0;
	this.container = null;
	
	/**
	 * Opens the Popup Window for reporting the Post and User
	 */
	this.open = function(post_sid, user_sid)
	{
		if (this.container)
			return false;
		
		this.post_sid = post_sid;
		this.user_sid = user_sid;
		
		this.container = $(document.createElement("div"));
		$("body").append(this.container);
		this.container.addClass("popup");
		this.container.css({
			"display": "none",
			"width": "600px",
			"height": "250px",
			"margin-left": "-300px",
			"margin-top": "-125px"
		});
		
		var title = $(document.createElement("div"));
		this.container.append(title);
		title.addClass("title");
		title.html("" +
			"<div style='float: left; width: 70%;'>" +
				"Report Post" +
			"</div>" +
			"<div style='float: left; width: 30%; text-align: right;'>" +
				"<img class='png' src='http://zacisa.info/images/icons/cancel.png' onclick='report.close();' />" +
			"</div>" +
			"<div class='clear'></div>");
		
		var body = $(document.createElement("div"));
		this.container.append(body);
		body.addClass("body");
		//body.html("<div style='font-size: 18px; text-align: center;'>Checking Data...</div>");
		
		this.container.show("800");
		this.container.draggable({ containment: "body", handle: ".title" });
		
		$.post(this.ajaxURL,
			{ type: "check", "post_sid": this.post_sid },
			function(data)
			{
				if (data == 0)
				{
					report.setupForm();
				} else {
					report.container.children(".body").html("<div style='font-size: 16px; text-align: center;'>This Post has already been reported</div>" +
						"<br/>An Admin will be along shortly to deal with this User's Post. Thank you for letting us know.");
				}
			});
	};
	
	/**
	 * Closes the Popup Window
	 */
	this.close = function()
	{
		if (this.container)
		{
			this.container.hide("800");
			this.container = null;
		}
	};
	
	/**
	 * Sets Up the Report Form to be Submitted
	 */
	this.setupForm = function()
	{
		var body = "Type: " +
			"<select>" +
				"<option value='Off-Topic'>Off-Topic</option>" +
				"<option value='SPAM'>SPAM</option>" +
				"<option value='Flaming Others'>Flaming Others</option>" +
				"<option value='Inappropriate Content'>Inappropriate Content</option>" +
				"<option value='Other'>Other</option>" +
			"</select><br/>" +
			"<textarea style='width: 99%; height: 150px;'></textarea><br/>" +
			"<div style='text-align: center;'>" +
				"<input type='button' value='Report Post' class='button' onclick='report.submit()' />" +
			"</div>";
		
		this.container.children(".body").html(body);
	};
	
	/**
	 * Submits the Report
	 */
	this.submit = function()
	{
		$.post(this.ajaxURL,
			{ type: "report", post_sid: this.post_sid, user_sid: this.user_sid,
			  r_type: this.container.children(".body").children("select").val(),
			  text: this.container.children(".body").children("textarea").val() });

		this.container.children(".body").html("<div style='font-size: 16px; text-align: center;'>This Post has been reported</div>" +
			"<br/>An Admin will be along shortly to deal with this User's Post. Thank you for leting us know.");
	};
};
var report = new report();

function moveThread()
{
	this.ajaxURL = "/ajax/forums_move_thread.php";
	this.thread_sid = 0;
	this.container = null;
	
	/**
	 * Opens the Popup Window for moving a Thread to a new Category
	 */
	this.open = function(thread_sid)
	{
		if (this.container)
			return false;
		
		this.thread_sid = thread_sid;
		
		this.container = $(document.createElement("div"));
		$("body").append(this.container);
		this.container.addClass("popup");
		this.container.css({
			"display": "none",
			"width": "300px",
			"height": "80px",
			"margin-left": "-150px",
			"margin-top": "-40px"
		});
		
		var title = $(document.createElement("div"));
		this.container.append(title);
		title.addClass("title");
		title.html("" +
			"<div style='float: left; width: 70%;'>" +
				"Move Thread" +
			"</div>" +
			"<div style='float: left; width: 30%; text-align: right;'>" +
				"<img class='png' src='http://zacisa.info/images/icons/cancel.png' onclick='moveThread.close();' />" +
			"</div>" +
			"<div class='clear'></div>");
		
		var body = $(document.createElement("div"));
		this.container.append(body);
		body.addClass("body");
		body.html("Populating Move Thread Form");
		
		this.grabCategories();
		
		this.container.show("800");
		this.container.draggable({ containment: "body", handle: ".title" });
	};

	/**
	 * Closes the Popup Window
	 */
	this.close = function()
	{
		if (this.container)
		{
			this.container.remove();
			this.container = null;
		}
	};
	
	/**
	 * Grabs all available valid Categories that this Thread can be moved to
	 */
	this.grabCategories = function()
	{
		$.post(this.ajaxURL,
			{ type: "grab_categories", thread_sid: this.thread_sid },
			function(data)
			{
				moveThread.container.children(".body").html(data);
			});
	};
	
	/**
	 * Moves the Thread
	 */
	this.move = function()
	{
		$.post(this.ajaxURL,
			{ type: "move", thread_sid: this.thread_sid,
			  category_sid: this.container.children(".body").children("select").val() });
		
		$("#thread_"+this.thread_sid).remove();
		this.close();
	}
};
var moveThread = new moveThread();

function AdminAction()
{
	this.ajaxURL = "/ajax/forums_actions.php";
	
	this.lock = function(sid)
	{
		$.post(this.ajaxURL,
			{ type: "lock", sid: sid },
			function(data)
			{
				var lock = $("#lock_"+sid);
				var lockObj = $("#lock_obj_"+sid);
				if (lock.html() == "[+L]")
				{
					lock.html("[-L]");
					lockObj.html("<img src='http://zacisa.info/images/icons/lock.png' />");
				} else {
					lock.html("[+L]");
					lockObj.html("");
				}
			});
	};
	
	this.sticky = function(sid)
	{
		$.post(this.ajaxURL,
				{ type: "sticky", sid: sid },
				function(data)
				{
					var sticky = $("#sticky_"+sid);
					var stickyObj = $("#sticky_obj_"+sid);
					if (sticky.html() == "[+S]")
					{
						sticky.html("[-S]");
						stickyObj.html("<img src='http://zacisa.info/images/icons/sticky.gif' />");
						$("#thread_"+sid).attr("id", "threadOld_"+sid).clone().prependTo("#category_threads tbody").attr("id", "thread_"+sid);
					} else {
						sticky.html("[+S]");
						stickyObj.html("");
						$("#thread_"+sid).attr("id", "threadOld_"+sid).clone().appendTo("#category_threads tbody").attr("id", "thread_"+sid);
					}
					$("#threadOld_"+sid).remove();
				});
	};
	
	this.deleteThread = function(sid)
	{
		$.post(this.ajaxURL,
				{ type: "delete_thread", sid: sid },
				function(data)
				{
					$("#thread_"+sid).remove();
				});
	};
};
var AdminAction = new AdminAction();

/**
 * Deals with setting Thread settings such as View Level
 */
function AdminThreadSettings()
{
	this.ajaxURL = "/ajax/forums_thread_settings.php";
	this.thread_sid = 0;
	this.container = null;
	
	/**
	 * Opens the Thread Settings Popup
	 * 
	 * @param int sid
	 * @param text value
	 */
	this.open = function(sid, value)
	{
		if (!this.container)
		{
			this.thread_sid = sid;
			this.container = $(document.createElement("div"));
			this.container.addClass("popup");
			this.container.css({
				display: "none",
				width: "170px",
				height: "80px",
				"margin-left": "-80px",
				"margin-top": "-30px"
			});
			$("body").append(this.container);

			var title = $(document.createElement("div"));
			this.container.append(title);
			title.addClass("title");
			title.html("" +
				"<div style='float: left; width: 70%;'>" +
					"Thread Settings" +
				"</div>" +
				"<div style='float: left; width: 30%; text-align: right;'>" +
					"<img class='png' src='http://zacisa.info/images/icons/cancel.png' onclick='AdminThreadSettings.close();' />" +
				"</div>" +
				"<div class='clear'></div>");
			
			var body = $(document.createElement("div"));
			this.container.append(body);
			body.addClass("body");
			body.html("Can Delete: " +
				"<select formType='can_delete'>" +
					"<option value='y'>Yes</option>" +
					"<option value='n'>No</option>" +
				"</select>" +
				"<br/>" +
				"<select formType='view_type'>" +
					"<option value='public'>Public</option>" +
					"<option value='member'>Members</option>" +
					"<option value='admin'>Admins</option>" +
				"</select>&nbsp;" +
				"<input type='button' class='button' value='Update' onclick='AdminThreadSettings.update();' />");
			this.container.find("[formType='view_type']").val(value);
			
			this.container.show(400);
			this.container.draggable({ containment: "body", handle: ".title" });
		}
	};
	
	/**
	 * Closes the Popup
	 */
	this.close = function()
	{
		if (this.container)
		{
			this.container.hide(400);
			setTimeout(function()
			{
				AdminThreadSettings.container.remove();
				AdminThreadSettings.container = null;
			}, 401);
		}
	};
	
	/**
	 * Updates the View Type Setting for the thread.
	 */
	this.update = function()
	{
		$.post(this.ajaxURL,
			{ type: "update_view_type", sid: this.thread_sid, view_type: this.container.find("[formType='view_type']").val(),
			  can_delete: this.container.find("[formType='can_delete']").val() });
		this.close();
	};
};
var AdminThreadSettings = new AdminThreadSettings();

/**
 * Class to help in ignoring/unignoring User's specific CSS Post Colors
 */
function IgnoreUserCSS()
{
	this.ajaxURL = "/ajax/forums_ignore.php";
	this.ignore_sid = 0;
	this.css_sid = 0;
	
	/**
	 * Will ignore the selected User's Post Color for this Color Scheme
	 * 
	 * @param int user_sid
	 * @param int css_sid
	 */
	this.ignore = function(user_sid, css_sid)
	{
		this.ignore_sid = user_sid;
		this.css_sid = css_sid;
		var post_color = $("[user_sid='"+this.ignore_sid+"'][type='post']").css("color");
		
		$.post(this.ajaxURL,
			{ type: "ignore_user_post_color", ignore_sid: this.ignore_sid, css_sid: this.css_sid });
		
		/**
		 * Override there css color settings automatically without a reload to take effect
		 */
		$("[user_sid='"+this.ignore_sid+"'][type='post']").css("color", "");
		$("[user_sid='"+this.ignore_sid+"'][type='quote']").addClass("css_default_color");
		$("[user_sid='"+this.ignore_sid+"'][type='ignore_link']").html("[Unignore User Post Color]");
		$("[user_sid='"+this.ignore_sid+"'][type='ignore_link']").unbind();
		$("[user_sid='"+this.ignore_sid+"'][type='ignore_link']").attr("onclick", "");
		$("[user_sid='"+this.ignore_sid+"'][type='ignore_link']").click(function()
		{
			IgnoreUserCSS.unignore(user_sid, css_sid, post_color);
		});
	};
	
	this.unignore = function(user_sid, css_sid, post_color)
	{
		this.ignore_sid = user_sid;
		this.css_sid = css_sid;

		$.post(this.ajaxURL,
			{ type: "unignore_user_post_color", ignore_sid: this.ignore_sid, css_sid: this.css_sid });
		
		/**
		 * Reset User Post color
		 */
		$("[user_sid='"+this.ignore_sid+"'][type='post']").css("color", post_color);
		$("[user_sid='"+this.ignore_sid+"'][type='quote']").removeClass("css_default_color").css("color", post_color);
		$("[user_sid='"+this.ignore_sid+"'][type='ignore_link']").html("[Ignore User Post Color]");
		$("[user_sid='"+this.ignore_sid+"'][type='ignore_link']").unbind("click");
		$("[user_sid='"+this.ignore_sid+"'][type='ignore_link']").attr("onclick", "");
		$("[user_sid='"+this.ignore_sid+"'][type='ignore_link']").click(function()
		{
			IgnoreUserCSS.ignore(user_sid, css_sid);
		});
	};
};
var IgnoreUserCSS = new IgnoreUserCSS();

/**
 * Deletes a Forum Post through ajax and gets rid of the html without a reload
 * 
 * @param sid
 */
function DeletePost(sid)
{
	if (confirm("Are you sure you wish to delete this post? It cannot be undone."))
	{
		$.post("/ajax/forums_actions_public.php",
			{ type: "delete_post", sid: sid });
		$("tr[post_sid='"+sid+"']").remove();
	}
};

/*
var iHasASecretKeys = new Array(65,87,69,83,79,77,69,13,13);
var iHasASecretKeyIndex = 0;
$().ready(function()
{
	$("html").keyup(function(e)
	{
		if (e.keyCode == iHasASecretKeys[iHasASecretKeyIndex])
		{
			iHasASecretKeyIndex++;
			if (iHasASecretKeyIndex >= iHasASecretKeys.length)
			{
				$.post("/ajax/forums_secret.php",
					{ valid: "true" },
					function(data)
					{
						window.location = "/forum/The-Secret-Realm-of-ZaKa/68838";
					});
			}
		} else {
			iHasASecretKeyIndex = 0;
		}
	});
});
*/

/*
$().ready(function()
{
	$("body").sortable({
		items: ".reorder-forum",
		handle: ".body_header"
	});
	$(".reorder-forum").disableSelection();

	$(".reorder-forum table tbody").sortable({
		items: "tr"
	});
});
*/

//Ignore MargetGID News Widget
function MarkgetGID_Ignore()
{
	$("#marketgid_ignore").hide();
	$("#marketgid_unignore").show();
	$("#marketgid").hide();
	$.post("/ajax/forums_ajax.php",
		{ action: "marketgid_ignore" });
};

//Unignore MargetGID News Widget
function MarkgetGID_Unignore()
{
	$("#marketgid_ignore").show();
	$("#marketgid_unignore").hide();
	$("#marketgid").show();
	$.post("/ajax/forums_ajax.php",
		{ action: "marketgid_unignore" });
};