// ============================================================================
// Ratings
// ============================================================================
function Comment(id, xsl)
{
	this._id		= id;
	this._xsl		= xsl;
	this._userid	= $('ctl00_hdnUserID').value;
	this._siteid	= $('ctl00_hdnSiteID').value;
	this._articleid = getQueryVariable("id");
	
	this.initCommentView = function(obj)
	{
		this._commentView = $(obj);
		
		this.getComments();
	};
	
	this.submit = function()
	{
		if (this._txt.value.trim() != '' && this._userid != 0)
		{
			var url = AjaxURL + '/CommentAdd';
			var inParameters = Object.toQueryString(
								{
									'iSiteID': this._siteid,
									'iArticleID': this._articleid,
									'iReplyOn': 0,
									'iUserID': this._userid,
									'sComment': this._txt.value,
									'sControlID': this._id,
									'sXSLTemplate': this._xsl
								});
			
			var ajax = new Ajax(url, 
			{
				update: this._commentView,
				method: 'post', 
				data: inParameters
			});
			
			ajax.request();
		}
	};
	
	this.getComments = function()
	{
		var url = AjaxURL + '/CommentView';
		var inParameters = Object.toQueryString(
							{
								'iArticleID': this._articleid,
								'iUserID': this._userid,
								'sControlID': this._id,
								'sXSLTemplate': this._xsl
							});
		
		var ajax = new Ajax(url, 
		{
			update: this._commentView,
			method: 'post', 
			data: inParameters
		});
		
		ajax.request();
	};
	
	this.postReply = function(commentID)
	{
		var txt = $E('textarea', 'Reply_' + commentID);
		
		if (txt.value.trim() != '' && this._userid != 0)
		{
			var url = AjaxURL + '/CommentAdd';
			var inParameters = Object.toQueryString(
								{
									'iSiteID': this._siteid,
									'iArticleID': this._articleid,
									'iReplyOn': commentID,
									'iUserID': this._userid,
									'sComment': txt.value,
									'sControlID': this._id,
									'sXSLTemplate': this._xsl
								});
			
			var ajax = new Ajax(url, 
			{
				update: this._commentView,
				method: 'post', 
				data: inParameters
			});
			
			ajax.request();
		}
		
		var objReply = $('Report_' + commentID);
		var objReport = $('Reply_' + commentID);
		objReply.style.display = 'none';
		objReport.style.display = 'none';
	};
	
	this.postReport = function(commentID)
	{
	
		var txt = $E('textarea', 'Report_' + commentID);
		
		if (txt.value.trim() != '' && this._userid != 0)
		{
			var url = AjaxURL + '/CommentReport';
			var inParameters = Object.toQueryString(
								{
									'iSiteID': this._siteid,
									'iArticleID': this._articleid,
									'iCommentID': commentID,
									'iUserID': this._userid,
									'sComment': txt.value,
									'sControlID': this._id,
									'sXSLTemplate': this._xsl
								});
			
			var ajax = new Ajax(url, 
			{
				update: this._commentView,
				method: 'post', 
				data: inParameters
			});
			
			ajax.request();
		}
	
		var objReply = $('Report_' + commentID);
		var objReport = $('Reply_' + commentID);
		objReply.style.display = 'none';
		objReport.style.display = 'none';
	};
};

Comment.prototype._id;
Comment.prototype._xsl;
Comment.prototype._userid;
Comment.prototype._siteid;
Comment.prototype._articleid;
Comment.prototype._txt;
Comment.prototype._commentView;

// static
Comment.init = function(obj)
{
	obj._txt = document.createElement('textarea');
	var btn	= document.createElement('input');
	
	obj._txt.cols = 50;
	obj._txt.rows = 3;
	if (!window.ie)
		obj._txt.wrap = "virtual";
	
	btn.type = "button";
	btn.value = "Submit";
	btn.id = obj._id + "_SubmitButton";
	
	$('Comment_TextArea').appendChild(obj._txt);
	$('Comment_Button').appendChild(btn);
	
	if (obj._userid == 0)
	{
		btn.disabled = true
		obj._txt.disabled = true;
	}
};

Comment.showBox = function(id)
{
	var oneline = $('OneLine_' + id);
	var box = $('FullPostBox_' + id);
	var objReply = $('Report_' + id);
	var objReport = $('Reply_' + id);
	
	box.style.display = 'block'; 
	oneline.style.display = 'none';
	
	if (objReply != "undefined" && objReply != "undefined")
	{
		objReply.style.display = 'none';
		objReport.style.display = 'none';
	}
};

Comment.showOneLine = function(id)
{
	var oneline = $('OneLine_' + id);
	var box = $('FullPostBox_' + id);
	var objReply = $('Report_' + id);
	var objReport = $('Reply_' + id);
	
	box.style.display = 'none'; 
	oneline.style.display = 'block';
	
	if (objReply != "undefined" && objReply != "undefined")
	{
		objReply.style.display = 'none';
		objReport.style.display = 'none';
	}
};


Comment.showReport = function(id)
{
	var objReply = $('Report_' + id);
	var objReport = $('Reply_' + id);
	objReply.style.display = 'none';
	objReport.style.display = 'block';
	
};

Comment.showReply = function(id)
{
	var objReply = $('Report_' + id);
	var objReport = $('Reply_' + id);
	objReply.style.display = 'block';
	objReport.style.display = 'none';
};