function postSubShow (postId) {
	var currentClass = $("post" + postId + "SubControl").className;
	if (currentClass == "postLikeOff") {
		$("post" + postId + "Sub").style.display = "block";
		$("post" + postId + "SubControl").className = "postLikeOn";
		if (document.getElementById("postReply" + postId + "Text") != null) {
			$("postReply" + postId + "Text").focus();
		}
	} else {
		$("post" + postId + "Sub").style.display = "none";
		$("post" + postId + "SubControl").className = "postLikeOff";
	}
}

function postPrep () {
	tmpLength = 0;
	tmpText = $F("postText");
	tmpLength = tmpText.length;
	tmpRemaining = 350-tmpLength;
	$("postCount").innerHTML = tmpRemaining;
	if (tmpRemaining > 15) {
		$("postCount").style.color = "#b6b6b6";
		$("postCount").style.fontWeight = "normal";
		if (tmpRemaining == 350) {
			$("postSubmit").setAttribute("disabled", "disabled");
		} else {
			$("postSubmit").removeAttribute("disabled");
		}
	} else if (tmpRemaining < 16 && tmpRemaining > -1) {
		$("postCount").style.color = "#c09898";
		$("postCount").style.fontWeight = "normal";
		$("postSubmit").removeAttribute("disabled");
	} else {
		$("postCount").style.color = "#c00";
		$("postCount").style.fontWeight = "bold";
		$("postSubmit").setAttribute("disabled", "disabled");
	}
}

function postReplyPrep (postId) {
	tmpLength = 0;
	tmpText = $F("postReply" + postId + "Text");
	tmpLength = tmpText.length;
	tmpRemaining = 350-tmpLength;
	$("postReply" + postId + "Count").innerHTML = tmpRemaining;
	if (tmpRemaining > 15) {
		$("postReply" + postId + "Count").style.color = "#b6b6b6";
		$("postReply" + postId + "Count").style.fontWeight = "normal";
		if (tmpRemaining == 350) {
			$("postReply" + postId + "Submit").setAttribute("disabled", "disabled");
		} else {
			$("postReply" + postId + "Submit").removeAttribute("disabled");
		}
	} else if (tmpRemaining < 16 && tmpRemaining > -1) {
		$("postReply" + postId + "Count").style.color = "#c09898";
		$("postReply" + postId + "Count").style.fontWeight = "normal";
		$("postReply" + postId + "Submit").removeAttribute("disabled");
	} else {
		$("postReply" + postId + "Count").style.color = "#c00";
		$("postReply" + postId + "Count").style.fontWeight = "bold";
		$("postReply" + postId + "Submit").setAttribute("disabled", "disabled");
	}
}

function postLoadIntoFrame (postContainer, postQs, postForm, postInsertion) {
	if (postForm === undefined) {
		postForm = "";
	}
	if (postInsertion === undefined) {
		postInsertion = 0;
	}
	
	if (postInsertion == 1) {
		if (postForm != "") {
			new Ajax.Updater(postContainer, "/data/posts.php?"+postQs, {
				method: "post", parameters: postForm, insertion: Insertion.Bottom
			});
		} else {
			new Ajax.Updater(postContainer, "/data/posts.php?"+postQs, {
				method: "post", insertion: Insertion.Bottom
			});
		}
	} else if (postInsertion == -1) {
		if (postForm != "") {
			new Ajax.Request("/data/posts.php?"+postQs, {
				method: "post",
				parameters: postForm,
				onSuccess: function(transport) {
					location.reload();
				}
			});
		} else {
			new Ajax.Request("/data/posts.php?"+postQs, {
				method: "post",
				onSuccess: function(transport) {
					location.reload();
				}
			});
		}
	} else {
		if (postForm != "") {
			new Ajax.Updater(postContainer, "/data/posts.php?"+postQs, {
				method: "post", parameters: postForm
			});
		} else {
			new Ajax.Updater(postContainer, "/data/posts.php?"+postQs, {
				method:"post"
			});
		}
	}
}

function postSubmitDo () {
	$("postSubmitWait").style.display = "inline";
	tmpPostAs = $F("postAs");
	tmpPostIn = $F("postIn");
	tmpPostText = escape($F("postText"));
	$("postSubmit").setAttribute("disabled", "disabled");
	postLoadIntoFrame("postFrameField", "", "ax=post&cid="+tmpPostIn+"&pa="+tmpPostAs+"&px="+tmpPostText, -1);
}


function postReplyDo (postId) {
	$("postReply" + postId + "SubmitWait").style.display = "inline";
	tmpPostAs = $F("postReply" + postId + "As");
	tmpPostText = escape($F("postReply" + postId + "Text"));
	$("postReply" + postId + "Submit").setAttribute("disabled", "disabled");
	postLoadIntoFrame("postFramePost"+postId, "", "ax=reply&pid="+postId+"&pa="+tmpPostAs+"&px="+tmpPostText);
}
