Gallery.addOnSuccessHandler('sendActionRequest', function(itype, data, actionForm) {
	if (actionForm == 'f_commentadd') {
		if (data == "success") {
			document.getElementById("generalNoticeMessageHolder").style.display = 'block';
			document.getElementById("noticeMsg").innerHTML = localizedMessages['comment.add.success'];
			document.getElementById("text").value = "";
		} else if (data == "success?mod") {
			document.getElementById("generalNoticeMessageHolder").style.display = 'block';
			document.getElementById("noticeMsg").innerHTML = localizedMessages['comment.add.success2'];
			document.getElementById("text").value = "";
		} else {
			document.getElementById("errorMsg").innerHTML = localizedMessages[data];
			Gallery.offset[itype] = 0;
		}
	}
});

Gallery.addOnBeforeActionHandler('sendActionRequest', function() {
	document.getElementById("generalNoticeMessageHolder").style.display = 'none';
	document.getElementById("noticeMsg").innerHTML = "";
	document.getElementById("errorMsg").innerHTML = "";
});

function toggleCommentsNotification(checkEl) {
	var mailNotifEl = document.getElementById('newCommentMailNotificationOn');
	if (checkEl.checked == true) {
		mailNotifEl.disabled = false;
	} else {
		mailNotifEl.disabled = true;
	}
}

function changeSubscriptionStatus(contextPath, resourceType) {
	var notif = document.getElementById('newCommentNotificationOn').checked;
	var mailNotif = document.getElementById('newCommentMailNotificationOn').checked;
	var resourceId = document.getElementById('ownerId').value;
	
	var uri = 'my/changesubscription/' + resourceType + '?notif=' + notif + '&mailNotif=' 
			+ mailNotif + '&resourceId=' + resourceId; 
	
	Gallery.addOnSuccessHandler('performAction', function(action, itype) {
		if (itype == 'subscriptions') {
			document.getElementById("noticeMsg").innerHTML = localizedMessages['comment.subsc.success'];
		}
	});
	Gallery.addOnErrorHandler('performAction', function(action, itype) {
		if (itype == 'subscriptions') {
			document.getElementById("errorMsg").innerHTML = localizedMessages['gallery.comment.subsc.error'];
		}
	});
	Gallery.performAction('', 'subscriptions', uri, contextPath);
}

function onStartWritingComment(textArea) {
	if (textArea.value == "") { 
		var notifEl = document.getElementById('newCommentNotificationOn');
		if (notifEl.checked == false) {
			notifEl.checked = true;
			toggleCommentsNotification(notifEl);
		}
	}
}