function getChannel (id) {
	return ChannelManager.getChannel(id);
}

function startBufferize () {
	var channel = ChannelManager.getChannel (currentChat.id);	
	channel.toBuffer = true;
}


function outBuffer () {
	//var activeChannelId = 6;
	var channel = ChannelManager.getChannel (currentChat.id);	
	channel.toBuffer = false;
	channel.view.outBuffer(Ext.getDom("MessagesBlock"), Ext.getDom("UsersBlock"));	
}

function addUser (channelId, messageId, userId, userInfo) {
	channel = getChannel (channelId);	
	channel.addUser(messageId, userId, userInfo);
//	outBuffer ();
}

function updateUser (channelId, messageId, userId, userInfo) {
	addUser(channelId, messageId, userId, userInfo);
}

function delUser (channelId, messageId, userId) {
	channel = getChannel (channelId);	
	channel.delUser(messageId, userId);
//	outBuffer ();
}

function userBanned (channelId, messageId, userId, userNick, clearMessages, timeStr, reason, modNick) {
	channel = getChannel (channelId);	
	channel.userBanned (messageId, userId, userNick, clearMessages, timeStr, reason, modNick);
}

function userChangeNick (channelId, messageId, userId, oldNick, newNick) {
	channel = getChannel (channelId);	
	channel.userChangeNick (messageId, userId, oldNick, newNick);
}

var startTm;
function startConnectionTest () {
	now = new Date;
	startTm = now;
}
var finishTm;
function finishConnectionTest () {
	finishTm = new Date;
	tmDelta = finishTm-startTm;
	if (tmDelta < 2000) {
		//alert("shortStreaming");
		ChatApp.daemonTimeout = 3;
	}
	else
		ChatApp.daemonTimeout = 30;
	
	if (!ChatApp.alreadyDoConnectionTest) {
		if (ChatApp.emptyChatAction) {
			var channel = getChannel(ChatApp.getCurrentChat().id);
			var usersCount = channel.usersIds.length;
			if (usersCount == 1) {
				var user = channel.users[channel.usersIds[0]];
				if (user.id == CurrentUser.Id && CurrentUser.IsTempNick)
					ChatApp.emptyChatAction();
			}
		}
		ChatApp.alreadyDoConnectionTest = true;	
	}
}


function addMessage (channelId, messageId, userId, userNick, messageTime, messageText) {
	channel = getChannel (channelId);	
	channel.addMessage(messageId, userId, userNick, messageTime, messageText);
//	outBuffer ();
}

function accessForbidden () {
	ChatApp.accessForbidden ();
}

function delMessage (channelId, messageId, delMessageId) {
}

/*function renameUser(channelId, messageId, userId, userNick) {
	channel = getChannel (channelId);
	channel.renameUser(messageId,userId, userNick);
}*/

function moderatorAdded (channelId, messageId, userId) {
	channel = getChannel (channelId);	
	channel.moderatorAdded(messageId, userId);
}

function moderatorDeleted (channelId, messageId, userId) {
	channel = getChannel (channelId);	
	channel.moderatorDeleted(messageId, userId);
}