var ParentNum;
var CommentTable;
var ParentColumn;

var Comment =
{
	chCommentForm : function (id)
	{
		$(id).style.display = ($(id).style.display == 'block') ? 'none' : 'block';  
	},
    
	clearForm : function (F)
	{
		if(F.value == 'Post a Comment')
			F.value = '';
    },

	saveComment : function (F)
	{
		this.clearForm(F.COMMENT_CONTENT);
		
		
		if(form.checkValue(F.COMMENT_CONTENT, 1, 'The comment field is empty.'))
		{
			$(F).send({
				onComplete : function (Msg)
				{
					
					if(Msg == "OK")
						Comment.ListLoad();
					else
					{
					  if(!Msg)
					  {
					      Comment.saveComment(F);
					      
					  }
					  else
					  alert('Msg :'+Msg);
					   
					    
					}
						
				} 
			});
		}
		
		return false;  
	},

	removeComment : function (Num)
	{
		if(!confirm('Delete comment ?')) return;
		var Result = Ajax.exec('/_Component/Comment/saveComment.php?Mode=DELETE',
							{ "COMMENT_NUM" : Num , "COMMENT_TABLE" : CommentTable} );
		if(Result.text == "OK")
		{
			this.ListLoad();
		}
		else alert(Result.text);
	},

	ListLoad : function()
	{
		var Top = document.documentElement.scrollTop;
		var Param = 
		{
			'PARENT_COLUMN' : ParentColumn,
			'COMMENT_TABLE' : CommentTable,
			'PARENT_NUM' : ParentNum,
			'onComplete' : function () 
				{ 
					document.documentElement.scrollTop = Top; 
				}
		}

		AutoRun.setComponent($('CommentArea'), 'Comment', "CommentList.php", Param);
	}
}

addEvent(window, 'load', Comment.ListLoad);