if (typeof MVD.CMS === 'undefined') {
	MVD.CMS = {};
}

MVD.CMS.ComGet = function () {

	var messages = { noComments: 'Envi&aacute; tu comentario', aComment: '1 comentario', comments: ' comentarios' };
	var notList = [];

	function update(text) {
		var listcc, cc, el, link;
		eval('listcc = ' + text);
		if (listcc.length == notList.length) {
			for (var i=0; i<notList.length; i++) {
				cc = listcc[i];
				el = document.getElementById('cantCom' + notList[i]);
				if (el) {
					link = el.getElementsByTagName('a')[0];
					if (link) {
						if (cc === 0) {
							if (messages.noComments) {
								link.innerHTML = messages.noComments;
								el.style.display = 'block';
							}
						} else if (cc == 1) {
							link.innerHTML = messages.aComment;
							el.style.display = 'block';
						} else if (cc > 1) {
							link.innerHTML = '' + cc + messages.comments;
							el.style.display = 'block';
						}
					}
				}
			}
		}
	}

	return {
		add : function (id) {
			notList.push(id);
		},
		get : function () {
			if (notList.length > 0) {
				MVD.Ajax.postGX('angetnotcantcoms', {ucs: notList.join(',') }, update);
			}
		},
		getIds : function () {
			return notList.slice();
		},
		setMessage: function (id, text) {
			messages[id] = text;
			return this;
		}
	};
} ();

// BackCompatibility
function addNot(id) {
	MVD.CMS.ComGet.add(id);
}

function getnotcom() {
	MVD.CMS.ComGet.get();
}

