void MainChatTab::RejoinChannels()
{
	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ )
	{
		ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
		if ( tmp->GetPanelType() == CPT_Channel )
		{

			// TODO: This will not rejoin passworded channels.
			wxString name = m_chat_tabs->GetPageText( i );
			bool alreadyin = false;
			try
			{
				serverSelector().GetServer().GetChannel( name ).GetMe();
				alreadyin = true;
			}
			catch ( ... ) {}
			if ( !alreadyin )
			{
				serverSelector().GetServer().JoinChannel( name, _T( "" ) );
				tmp->SetChannel( &serverSelector().GetServer().GetChannel( name ) );
			}

		} else if ( tmp->GetPanelType() == CPT_User )
		{

			wxString name = m_chat_tabs->GetPageText( i );
			if ( serverSelector().GetServer().UserExists( name ) ) tmp->SetUser( &serverSelector().GetServer().GetUser( name ) );

		}
	}
}
void MainChatTab::LeaveChannels()
{
	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ ) {
		ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
		if ( tmp->GetPanelType() == CPT_Channel )
		{
			tmp->StatusMessage( _( "Disconnected from server, chat closed." ) );
			tmp->SetChannel( 0 );
		} else if ( tmp->GetPanelType() == CPT_User )
		{
			tmp->StatusMessage( _( "Disconnected from server, chat closed." ) );
			tmp->SetUser( 0 );
		}
	}
}
ChatPanel* MainChatTab::AddChatPanel( Channel& channel, bool doFocus )
{

	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ ) {
		if ( m_chat_tabs->GetPageText( i ) == channel.GetName() ) {
			ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
			if ( tmp->GetPanelType() == CPT_Channel ) {
				if ( doFocus )
					m_chat_tabs->SetSelection( i );
				tmp->SetChannel( &channel );
				return tmp;
			}
		}
	}

	ChatPanel* chat = new ChatPanel( m_chat_tabs, channel, m_imagelist );
	m_chat_tabs->InsertPage( m_chat_tabs->GetPageCount() - 1, chat, channel.GetName(), doFocus, wxBitmap( channel_xpm ) );
	if ( doFocus )
		chat->FocusInputBox();
	return chat;
}