
/* constructor */

function ArticleDetails(items_ns)
{
	/*this.current_page = 1;
	this.total_page = 1;
	this.paging_offset = 0;*/
	
	this.items_ns = items_ns;
	
	this.init = __ArticlesDetails_init;
	this.flagArticleAsBad = __ArticlesDetails_flagArticleAsBad;
	this.rateArticle = __ArticlesDetails_rateArticle;
	this.writeComment = __ArticlesDetails_writeComment;
}

/* functions */

function __ArticlesDetails_init()
{
	$('#' + this.items_ns + '')
}

function __ArticlesDetails_flagArticleAsBad(news_id, callback)
{
	$.ajax({
		type: 'GET',
		url: 'webservices/Infocar2NewsProxy.cfm',
		data: {
			'method': 'FlagArticleAsBad',
			'comment_id': news_id
		},
		dataType: 'xml',
		success: __ArticlesDetails_flagArticleAsBadSuccess,
		error: __ArticlesDetails_flagArticleAsBadError,
		obj: this,
		callback: callback
	});
}

function __ArticlesDetails_rateArticle(news_id, rate, callback)
{
	$.ajax({
		type: 'GET',
		url: 'webservices/Infocar2NewsProxy.cfm',
		data: {
			'method': 'RateArticle',
			'news_id': news_id,
			'rate': rate
		},
		dataType: 'xml',
		success: __ArticlesDetails_rateArticleSuccess,
		error: __ArticlesDetails_rateArticleError,
		obj: this,
		callback: callback
	});
}

function __ArticlesDetails_writeComment(news_id, /*author, */title, content, callback)
{
	$.ajax({
		type: 'GET',
		url: 'webservices/Infocar2NewsProxy.cfm',
		data: {
			'method': 'WriteComment',
			'news_id': news_id,
			/*'author': author,*/
			'title': title,
			'content': content
		},
		dataType: 'string',
		success: __ArticlesDetails_writeCommentSuccess,
		error: __ArticlesDetails_writeCommentError,
		obj: this,
		callback: callback
	});
}

/* events */

function __ArticlesDetails_flagArticleAsBadSuccess(xml)
{
	var thiz = this.obj;
	
	if (this.callback != null)
		this.callback($('result', xml).text() == '1');
}

function __ArticlesDetails_flagArticleAsBadError(error)
{
	this.callback(false);
}

function __ArticlesDetails_rateArticleSuccess(xml)
{
	var thiz = this.obj;
	
	if (this.callback != null)
		this.callback($('result', xml).text() == '1', $('result', xml).attr('avg'));
}

function __ArticlesDetails_rateArticleError()
{
	this.callback(false, 0);
}

function __ArticlesDetails_writeCommentSuccess(xml)
{
	var thiz = this.obj;
	
	if (this.callback != null)
		this.callback(xml.indexOf('1') >= 0);
}

function __ArticlesDetails_writeCommentError(error)
{
	this.callback(false);
}

