include(g_oGlobals.DIR_WS_ROOT + '/styles/default/js/default.js');

var Article = {
	id: null,

	Controller: {
		init: function(p_iID) {
			Article.id = p_iID;

			Ajax.init('../xfer/ajax.php');
		},

		postComment: function() {
			_e('validation_submit').style.display = 'none';
			_e('validation_ajax_loader').style.display = '';

			Ajax.send({
				'object': new Object(),
				'class': 'comment',
				'function': 'post',
				'param': [
					'article_id', Article.id,
					'author', _e('author').value,
					'message', _e('comment').value,
					'validation', _e('validation_text').value
				],
				'callback': Article.Interface.postComment
			});
		}
	},

	Interface: {
		commentButtonHovering: 0,

		commentButtonHover: function() {
			if (Article.Interface.commentButtonHovering == 0) {
				_e('validation_submit').src = g_oGlobals.DIR_WS_BLOG + 'button.php?t=' + g_oGlobals.COMMENT_POST + '&c=ffffff&w=120&s=small_hover';
				Article.Interface.commentButtonHovering = 1;
			}
		},

		commentButtonLeave: function() {
			_e('validation_submit').src = g_oGlobals.DIR_WS_BLOG + 'button.php?t=' + g_oGlobals.COMMENT_POST + '&c=202020&w=120';
			Article.Interface.commentButtonHovering = 0;
		},

		postComment: function(p_aData) {
			_e('validation_ajax_loader').style.display = 'none';

			if (p_aData.result['success'] == false) {
				l_oCurDate = new Date();
				
				_e('comment_error').innerHTML = p_aData.result['reason'];
				_e('comment_error').style.display = '';
				
				_e('validation_submit').style.display = '';

				return;
			}

			_e('comment_error').style.display = 'none';

			l_oCurDate = new Date();
			_e('comment').value = '';
			_e('author').value = '';

			l_oNewComment = document.createElement('div');
			l_oNewComment.className = "comment";

			l_sQuote = new String(p_aData.object.data['message']);
			l_oCommentQuote = document.createElement('div');
			l_oCommentQuote.className = 'quote';
			l_oCommentQuote.innerHTML = '<span class="quote_start">&#8220;</span>';
			l_oCommentQuote.innerHTML += l_sQuote.replace(/\r?\n/g, '<br />');
			l_oCommentQuote.innerHTML += '<span class="quote_end">&#8221;</span>';

			l_oAuthor = document.createElement('div');
			l_oAuthor.className = 'author';
			l_oAuthor.innerHTML = p_aData.object.data['author_footer'];

			l_oNewComment.appendChild(l_oCommentQuote);
			l_oNewComment.appendChild(l_oAuthor);

			l_oComments = _e('comments');
			for (l_iKey in l_oComments.childNodes) {
				if (l_oComments.childNodes[l_iKey].nodeType == 1) l_oLastComment = l_oComments.childNodes[l_iKey];
			}
			l_oComments.insertBefore(l_oNewComment, l_oLastComment);
	
			_e('validation_submit').style.display = '';
		}
	}
}

