
function item_comment( element_ids, pars ) {
	this.element_ids = element_ids;
	this.pars = pars;
	
	this.request_url = '/api/comment';
}

item_comment.prototype.onException = function (req, e) {
	trace(e);
}
item_comment.prototype.onComplete = function (req)
{
	var dom = req.responseXML.documentElement;
	var res = xml2js(dom);

	if (res.errorcode != 0) {
		// error.
		return;
	}
	
	var location = window.location;
	var delim = (location.search == '') ? '?' : '&';
	location.search += delim + "rand=" + Math.floor(Math.random() * 65536);
	
}


item_comment.prototype.post_comment = function ()
{
	this.pars._post = 'cmd';
	var body = $F( this.element_ids.comment_text );

	body = body.replace(/^\s*/, '');
	body = body.replace(/\s*$/, '');
	if (body == '') {
		Element.show(this.element_ids.emptybody);
		return;
	}

	this.pars.body = body;

	this.pars.rand = Math.floor(Math.random() * 65536);

		var aj = new Ajax.Request( this.request_url, {
										method: 'post',
										parameters: $H(this.pars).toQueryString(),
										onComplete: this.onComplete.bind(this),
										onException: this.onException.bind(this)
									} );
}
