var onManageMembershipSuccessHandler;
var onManageMembershipErrorHandler;

function manageMembership(action, userId, groupId, contextPath, confirmMsg) {
	var uri = 'my/ajax/communities/change?userId=' + userId + '&groupId=' + groupId;
	if (confirmMsg != null) {
		if(!confirm(confirmMsg)) {
			return false;
		}
	}
	if (typeof contextPath != "undefined") {
		Gallery.contextPath = contextPath;
	}
	//initListValues("", perPage);
	var url = uri;
	if (typeof Gallery.contextPath != "undefined"){
		url = Gallery.contextPath + url;
	}	
	AjaxRequest.post({
		'url':url,
		'parameters':{
						'itype':"",
						'action':action
					 },
		"onSuccess":			
			function (req) {
				var response = req.responseText;
				if (response != "error") {
					if (onManageMembershipSuccessHandler != null) {
						onManageMembershipSuccessHandler(action, '', uri, response);
					} else {
						window.location.reload();
					}
				} else {
					if (onManageMembershipErrorHandler != null) {
						onManageMembershipErrorHandler(action, '', uri);
					}
				}
			},
		"onLoading":function() { showLoadingProgress(document.getElementById("defaultDisplayElement")); },
		"onComplete": function() { hideLoadingProgress(); },
		"onError": function (req) { 
			hideLoadingProgress(); 
			alert("Ошибка...");	
		}			
	});
	return false;
}
onManageMembershipErrorHandler = function(action, itype, reqUri) {
	alert('Ошибка');
}
function delCommunity(groupId, contextPath, confirmMsg) {
	var uri = 'my/communities/remove?&groupId=' + groupId;
	return Gallery.performAction('remove', "", uri, contextPath, confirmMsg);
}