var dsList = new Spry.Data.XMLDataSet(null, "/list");
var dsComments = new Spry.Data.NestedXMLDataSet(dsList, "comentario", { useCache: false, subPaths: "user/significatives/entry[string[last()-1]='NICK']" });
var dsCommentsUsers = new Spry.Data.NestedXMLDataSet(dsComments, "user/significatives/entry", { useCache: false, subPaths: "user/significatives/entry[string[last()-1]='NICK']" });
var dsCommentsFull = new Spry.Data.XMLDataSet(null, "/list/comentario", { useCache: false, subPaths: "user/significatives/entry[string[last()-1]='NICK']" });

var pvCommenting = new Spry.Data.PagedView(dsCommentsFull, { pageSize: 10 });
var pvCommentingPagedInfo = pvCommenting.getPagingInfo();


function loadComments(item) {
	dsList.setURL("/su/services/getComments?ITEMID=" + item + "&page=1" + "&ts=" + timestamp());
	dsList.loadData();
}

function loadAllComments(item) {
	dsCommentsFull.setURL("/su/services/listComments?ITEMID=" + item +"&ts=" + timestamp());
	dsCommentsFull.loadData();
}

function addComment(formulario) {
	var cmForm = document.getElementById(formulario);
	cmForm.action = "/su/services/addComment";
	Spry.Utils.submitForm(cmForm, commentingResponse, {method:'post', errorCallback: commentingError, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}});
}

/*** events ***/

function commentingLoginResponse(req) {
	addComment('commentingForm');
}

commentingError = function (req) {
	printError('commentingResponseData', req);
}

commentingResponse = function (req) {
	Spry.Utils.setInnerHTML('commentingResponseData', 'El comentario ha sido aņadido.');
}
