var PATH = './../../ajax/';

USER.ajax = function(func, data, cbfunc) {
	$.ajax({
		type: 'POST',
		url: PATH + func,
		data: data,
		success: function(response) {
			if (cbfunc && typeof (cbfunc) === 'function') { cbfunc(response); }
		}
	});
}

USER.setUser = function(Uid) {
	user.data.info.Uid = Uid;
}

USER.getUser = function(cbfunc) {
	UTIL.checkLS('user.data', function (response) {
		if (typeof response.info === 'string') return;
		user.data = response;
		if (cbfunc && typeof (cbfunc) === 'function') { cbfunc(response); }
	});
	
	USER.ajax('getUser', {}, function(response) {
		if (typeof response === 'string') return;
		user.data = response;
		if (supportsLocalStorage()) {
			localStorage.setItem('user.data', JSON.stringify(user.data));
		}	
		if (cbfunc && typeof (cbfunc) === 'function') { cbfunc(response); }
	});
}

USER.getUserGroups = function(cbfunc) {
	UTIL.checkLS('user.data.groups', function (response) {
		if (typeof response === 'string') return;
		user.data.groups = response;
		if (cbfunc && typeof (cbfunc) === 'function') { cbfunc(response); }
	});

	USER.ajax('getUserGroups', {}, function(response) {
		if (typeof response === 'string') return;
		user.data.groups = response;
		if (supportsLocalStorage()) {
			localStorage.setItem('user.data.groups', JSON.stringify(response));
		}	
		if (cbfunc && typeof (cbfunc) === 'function') { cbfunc(response); }
	});
}
