
var oBtnReply = null;
var oBtnReset = null;
var oBtnPreview = null;
var oCommentAction = null;
var oCommentParentID = null;
var oCommentRootID = null;
var oForm = null;
var oFormHead = null;
var oFormHeadPar = null;
var oFormSubject = null;
var oFormText = null;
var oPreview = null;


var Comment_New = function() {

        var sOut = null;

	oCommentAction.value = "postnew";	
	sOut = "New Comment";
	oFormHeadPar.innerHTML = sOut;

};

var Comment_Preview = function() {

	var sPreviewText = null;
	var bIsValid = null;

	bIsValid = Comment_Validate();

	if(bIsValid) {
		sPreviewText = "<h3>Preview</h3><h4>" + oFormSubject.value + "</h4><p>" + oFormText.value + "</p>";
		oPreview.innerHTML = sPreviewText;
	        oPreview.className = "showMe";
	} else {
		return;
	}

};

var Comment_Reply = function(nParentID, nRootID, sSubject, sDateTS, nUserID, sUserName) {

        var sOut = null;

	oCommentAction.value = "postreply";
	oCommentParentID.value = nParentID;
	oCommentRootID.value = nRootID;

	sOut = "Reply to: <a href=\"#post-"+nParentID+"\">" + sSubject + " "  + sDateTS +  "</a> posted by <a href=\"/My/Member/"+sUserName+"-"+nUserID+".html\"> " + sUserName + "</a>, or <a id=\"commentCancelReply\" href=\"javascript:;\" onclick=\"Comment_New();\">Cancel Reply</a>";
	
	oFormHeadPar.innerHTML = sOut;

};

var Comment_Reset = function() {

        oCommentAction.value = "postnew";
        oCommentParentID.value = '0';
        oCommentRootID.value = '0';
        oFormHeadPar.innerHTML = "New Comment";
	oFormSubject.value = "";
	oFormText.value = "";
	oPreview.innerHTML = "";
	oPreview.className = "hideMe";
};

var Comment_Validate = function() {

	var bIsValid = false;

	if(oFormSubject.value.length <= 0 || oFormText.value.length <= 0) {
                alert('Please fill in all form fields.');
		return false;
	} else {
		bIsValid = true;
	}

	if(oFormSubject.value.length > 255) {
                alert('Please limit your subject length to less than 255 characters, and you comment length to less than 2,000 characters.');
		return false;
	} else {
		bIsValid = true;
	}

	return bIsValid;
};

var Init_Comments_Form = function() {

	oBtnReset = document.getElementById('commentFormReset');
	oBtnPreview = document.getElementById('commentFormPreview');
	oCommentAction = document.getElementById('commentAction');
	oCommentParentID = document.getElementById('commentParentID');
	oCommentRootID = document.getElementById('commentRootID');
	oForm = document.getElementById('commentForm');
	oFormHead = document.getElementById('formHead');
	oFormHeadPar = oFormHead.getElementsByTagName('p')[0];
	oFormSubject = document.getElementById('commentSubject');
	oFormText = document.getElementById('commentText');
	oPreview = document.getElementById('formPreview');
	
	oForm.onsubmit = function() {
		return Comment_Validate();
	};
	
	oBtnPreview.onclick = Comment_Preview;

	oBtnReset.onclick = Comment_Reset;

};

var Init_Comments_Scripts = function() {

	Init_Comments_Form();
}
