diff --git a/src/webim/INSTALL.txt b/src/webim/INSTALL.txt
index 6b2c7d15..e36e4414 100644
--- a/src/webim/INSTALL.txt
+++ b/src/webim/INSTALL.txt
@@ -1,5 +1,5 @@
 
-Web Instant Messenger 1.0.9
+Web Instant Messenger 1.0.10
 Copyright (c) 2005-2008 Web Messenger Creators Community.
 
 This program and the accompanying materials are made available under
diff --git a/src/webim/INSTALL_RUS.txt b/src/webim/INSTALL_RUS.txt
index b4927893..69e393f1 100644
--- a/src/webim/INSTALL_RUS.txt
+++ b/src/webim/INSTALL_RUS.txt
@@ -1,5 +1,5 @@
 
-Web Instant Messenger 1.0.9
+Web Instant Messenger 1.0.10
 Copyright (c) 2005-2008 ���������� ������������� Web Messenger.
 
 ������ ����������� ����������� � ������������� ��������� ��������� ���
diff --git a/src/webim/button.php b/src/webim/button.php
index 46e7a071..2736f76a 100644
--- a/src/webim/button.php
+++ b/src/webim/button.php
@@ -17,8 +17,9 @@ require_once('libs/operator.php');
 
 $image = verifyparam("image","/^\w+$/", "webim");
 $lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
-if( !$lang || !in_array($lang,$available_locales) )
+if(!$lang || !in_array($lang,$available_locales)) {
 	$lang = $current_locale;
+}
 
 $image_postfix = has_online_operators() ? "on" : "off";
 $filename = "locales/${lang}/button/${image}_${image_postfix}.gif";
diff --git a/src/webim/client.php b/src/webim/client.php
index 26f8b141..8e801f6d 100644
--- a/src/webim/client.php
+++ b/src/webim/client.php
@@ -31,7 +31,8 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
 		}
 		
 		$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
-		$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $_SERVER['REMOTE_ADDR'];
+		$extAddr = $_SERVER['REMOTE_ADDR'];
+		$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
 		$visitor = $remote_visitor();
 		$thread = create_thread($visitor['name'], $remoteHost, $referer,$current_locale);
 		$_SESSION['threadid'] = $thread['threadid'];
diff --git a/src/webim/install/dbinfo.php b/src/webim/install/dbinfo.php
index e89a3eaf..3ec2e9ff 100644
--- a/src/webim/install/dbinfo.php
+++ b/src/webim/install/dbinfo.php
@@ -30,6 +30,7 @@ $dbtables = array(
 		"lastpingagent" => "datetime DEFAULT 0",
 		"userTyping" => "int DEFAULT 0",
 		"agentTyping" => "int DEFAULT 0",
+		"messageCount" => "varchar(16)"
 	),
 
 	"chatmessage" => array(
@@ -59,7 +60,7 @@ $dbtables = array(
 $memtables = array();
 
 $dbtables_can_update = array(
-	"chatthread" => array("agentId", "userTyping", "agentTyping"),
+	"chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount"),
 	"chatmessage" => array("agentId"),
 );
 
@@ -108,7 +109,7 @@ function create_table($id,$link) {
 
 function get_tables($link) {
 	global $mysqldb, $errors;
-	$result = mysql_query("SHOW TABLES FROM $mysqldb");
+	$result = mysql_query("SHOW TABLES FROM `$mysqldb`");
 	if( $result ) {
 		$arr = array();
 		while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
diff --git a/src/webim/install/dbperform.php b/src/webim/install/dbperform.php
index 5e4eff6b..94236e46 100644
--- a/src/webim/install/dbperform.php
+++ b/src/webim/install/dbperform.php
@@ -80,6 +80,13 @@ if($act == "createdb") {
 			runsql("ALTER TABLE chatthread ADD userTyping int DEFAULT 0", $link);
 		}
 
+		if( in_array("chatthread.messageCount", $absent) ) {
+			runsql("ALTER TABLE chatthread ADD messageCount varchar(16)", $link);
+			runsql("ALTER TABLE chatmessage ADD index idx_threadid_ikind (threadid, ikind)", $link);
+			runsql("UPDATE chatthread t SET t.messageCount = (SELECT COUNT(*) FROM chatmessage WHERE chatmessage.threadid = t.threadid AND ikind = 1)", $link); 
+			runsql("ALTER TABLE chatmessage DROP INDEX idx_threadid_ikind", $link);
+		}
+
 	}
 }
 
diff --git a/src/webim/install/whatsnew.txt b/src/webim/install/whatsnew.txt
index fe123115..2ce54509 100644
--- a/src/webim/install/whatsnew.txt
+++ b/src/webim/install/whatsnew.txt
@@ -1,4 +1,15 @@
 
+  1.0.10
+  ------
+  
+  [+] Number of messages from visitor in history
+  [+] State "loading" (means user is still loading his window)
+  [!] Company logo link target is now an option in config
+  [!] Mail encoding fixed (separate option)
+  [!] Operator/user locale is stored in cookie
+  [!] localized dates
+  [!] fixed installing on DB with numeric name
+
   1.0.9
   -----
 
diff --git a/src/webim/leavemessage.php b/src/webim/leavemessage.php
index bcff0d24..34f0d8b3 100644
--- a/src/webim/leavemessage.php
+++ b/src/webim/leavemessage.php
@@ -43,16 +43,10 @@ if( count($errors) > 0 ) {
 	exit;
 }
 
-// FIXME mail encoding
+$subject = getstring2_("leavemail.subject", array($visitor_name), $webim_messages_locale);
+$body = getstring2_("leavemail.body", array($visitor_name,$email,$message), $webim_messages_locale); 
 
-$subject = getstring2_("leavemail.subject", array($visitor_name), $webim_messages_encoding);
-$body = getstring2_("leavemail.body", array($visitor_name,$email,$message), $webim_messages_encoding); 
-
-$headers = 'From: '.$webim_from_email."\r\n" .
-   'Reply-To: '.$email."\r\n" .
-   'X-Mailer: PHP/'.phpversion();
-
-mail($webim_messages_mail,$subject,wordwrap($body,70),$headers);
+webim_mail($webim_messages_mail, $email, $subject, $body);
 
 
 start_html_output();
diff --git a/src/webim/libs/chat.php b/src/webim/libs/chat.php
index 797a2354..519b8310 100644
--- a/src/webim/libs/chat.php
+++ b/src/webim/libs/chat.php
@@ -22,6 +22,7 @@ $state_queue = 0;
 $state_waiting = 1;
 $state_chatting = 2;
 $state_closed = 3;
+$state_loading = 4;
 
 $kind_user = 1;
 $kind_agent = 2;
@@ -166,13 +167,14 @@ function print_thread_messages($thread, $token, $lastid, $isuser,$format) {
 	}
 }
 
-function get_user_name($username, $id="") {
+function get_user_name($username, $addr) {
 	global $presentable_name_pattern;
-       	return str_replace("{id}", $id, str_replace("{name}", $username, $presentable_name_pattern));
+	return str_replace("{addr}", $addr, 
+			str_replace("{name}", $username, $presentable_name_pattern));
 }
 
 function setup_chatview_for_user($thread,$level) {
-	global $page, $webimroot, $user_can_change_name, $company_logo_link, $company_name;
+	global $page, $webimroot, $user_can_change_name, $company_logo_link, $company_name, $webim_host;
 	$page = array();
 	$page['agent'] = false;
 	$page['user'] = true;
@@ -192,22 +194,24 @@ function setup_chatview_for_user($thread,$level) {
 
 	$params = "thread=".$thread['threadid']."&token=".$thread['ltoken'];
 	$page['selfLink'] = "$webimroot/client.php?".$params."&level=".$level;
+	$page['webimHost'] = $webim_host;
 
 }
 
 function setup_chatview_for_operator($thread,$operator) {
-	global $page, $webimroot, $company_logo_link, $company_name;
+	global $page, $webimroot, $company_logo_link, $company_name, $webim_host;
 	$page = array();
 	$page['agent'] = true;
 	$page['user'] = false;
 	$page['canpost'] = true;
 	$page['ct.chatThreadId'] = $thread['threadid'];
 	$page['ct.token'] = $thread['ltoken'];
-	$page['ct.user.name'] = topage(get_user_name($thread['userName']));
+	$page['ct.user.name'] = topage(get_user_name($thread['userName'],$thread['remote']));
 
 	$page['ct.company.name'] = topage($company_name);
 	$page['ct.company.chatLogoURL'] = topage($company_logo_link);
 	$page['send_shortcut'] = "Ctrl-Enter";
+	$page['webimHost'] = $webim_host;
 
 	// TODO
 	$page['namePostfix'] = "";	
@@ -273,14 +277,21 @@ function update_thread_access($threadid, $params, $link) {
 }
 
 function ping_thread($thread, $isuser,$istyping) {
-	global $kind_for_agent, $state_chatting, $state_waiting, $kind_conn, $connection_timeout;
+	global $kind_for_agent, $state_queue, $state_loading, $state_chatting, $state_waiting, $kind_conn, $connection_timeout;
 	$link = connect();
 	$params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP",
 					($isuser ? "userTyping" : "agentTyping") => ($istyping? "1" : "0") );
 	
 	$lastping = $thread[$isuser ? "lpagent" : "lpuser"];
 	$current = $thread['current'];
-	
+
+	if( $thread['istate'] == $state_loading && $isuser) {
+		$params['istate'] = $state_queue;
+		commit_thread($thread['threadid'], $params, $link);
+		mysql_close($link);
+		return;
+	}
+
  	if( $lastping > 0 && abs($current-$lastping) > $connection_timeout ) {
 		$params[$isuser ? "lastpingagent" : "lastpinguser"] = "0";
 		if( !$isuser ) {
@@ -302,7 +313,7 @@ function ping_thread($thread, $isuser,$istyping) {
 }
 
 function commit_thread($threadid,$params,$link) {
-	$query = "update chatthread set lrevision = ".next_revision($link).", dtmmodified = CURRENT_TIMESTAMP";
+	$query = "update chatthread t set lrevision = ".next_revision($link).", dtmmodified = CURRENT_TIMESTAMP";
 	foreach( $params as $k => $v ) {
 	    $query .= ", ".$k."=".$v;
 	}
@@ -330,7 +341,8 @@ function close_thread($thread,$isuser) {
 	
 	if( $thread['istate'] != $state_closed ) {
 		$link = connect();
-		commit_thread( $thread['threadid'], array('istate' => $state_closed), $link);
+		commit_thread( $thread['threadid'], array('istate' => $state_closed, 
+			'messageCount' => '(SELECT COUNT(*) FROM chatmessage WHERE chatmessage.threadid = t.threadid AND ikind = 1)'), $link);
 		mysql_close($link);
 	}
 
@@ -353,11 +365,12 @@ function thread_by_id($id) {
 }
 
 function create_thread($username,$remoteHost,$referer,$lang) {
+	global $state_loading;
 	$link = connect();
 
 	$query = sprintf(
-		 "insert into chatthread (userName,"."ltoken,remote,referer,lrevision,locale,dtmcreated,dtmmodified) values ".
-								 "('%s',"."%s,'%s','%s',%s,'%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)",
+		 "insert into chatthread (userName,"."ltoken,remote,referer,lrevision,locale,dtmcreated,dtmmodified,istate) values ".
+								 "('%s',"."%s,'%s','%s',%s,'%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$state_loading)",
 			mysql_real_escape_string($username),
 			next_token(),
 			mysql_real_escape_string($remoteHost),
@@ -384,7 +397,7 @@ function do_take_thread($threadid,$operatorId,$operatorName) {
 }
 
 function reopen_thread($threadid) {
-	global $state_queue,$state_waiting,$state_chatting,$state_closed,$kind_events;
+	global $state_queue,$state_loading,$state_waiting,$state_chatting,$state_closed,$kind_events;
 	$thread = thread_by_id($threadid);
 
 	if( !$thread )
@@ -393,7 +406,7 @@ function reopen_thread($threadid) {
 	if( $thread['istate'] == $state_closed )
 		return FALSE;
 
-	if( $thread['istate'] != $state_chatting && $thread['istate'] != $state_queue ) {
+	if( $thread['istate'] != $state_chatting && $thread['istate'] != $state_queue && $thread['istate'] != $state_loading ) {
 		$link = connect();
 		commit_thread( $threadid, 
 			array("istate" => $state_waiting ), $link);
@@ -405,7 +418,7 @@ function reopen_thread($threadid) {
 }
 
 function take_thread($thread,$operator) {
-	global $state_queue, $state_waiting, $state_chatting, $kind_events, $home_locale;
+	global $state_queue, $state_loading, $state_waiting, $state_chatting, $kind_events, $home_locale;
 
 	$state = $thread['istate'];
 	$threadid = $thread['threadid'];
@@ -413,7 +426,7 @@ function take_thread($thread,$operator) {
 
 	$operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname'];
 
-	if( $state == $state_queue || $state == $state_waiting) {
+	if( $state == $state_queue || $state == $state_waiting || $state == $state_loading) {
 		do_take_thread($threadid, $operator['operatorid'], $operatorName);
 
 		if( $state == $state_waiting  ) {
diff --git a/src/webim/libs/common.php b/src/webim/libs/common.php
index 9e782f40..f9afb65d 100644
--- a/src/webim/libs/common.php
+++ b/src/webim/libs/common.php
@@ -17,7 +17,7 @@ session_start();
 require_once(dirname(__FILE__).'/converter.php');
 require_once(dirname(__FILE__).'/config.php');
 
-$version = 'v1.0.9';
+$version = 'v1.0.10/pre1';
 
 function myiconv($in_enc, $out_enc, $string) {
 	global $_utf8win1251, $_win1251utf8;
@@ -69,6 +69,12 @@ function debugexit_print( $var ) {
 function get_user_locale() {
 	global $available_locales, $default_locale;
 
+	if( isset($_COOKIE['webim_locale']) ) {
+		$requested_lang = $_COOKIE['webim_locale'];
+		if( in_array($requested_lang,$available_locales) )
+			return $requested_lang;
+	}
+
 	if( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ) {
 		$requested_langs = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
 		foreach( $requested_langs as $requested_lang) {
@@ -87,12 +93,13 @@ function get_user_locale() {
 }
 
 function get_locale() {
-	global $available_locales;
+	global $available_locales, $webimroot;
 
 	$locale = verifyparam("locale", "/^[\w-]{2,5}$/", "");
 
 	if( $locale && in_array($locale,$available_locales) ) {
 		$_SESSION['locale'] = $locale;
+		setcookie('webim_locale', $locale, time()+60*60*24*1000, "$webimroot/");
 	} else if( isset($_SESSION['locale']) ){
 	    $locale = $_SESSION['locale'];
 	}
@@ -102,13 +109,8 @@ function get_locale() {
 	return $locale;
 }
 
-function set_locale($locale) {
-	global $current_locale, $available_locales;
-	if( in_array($locale,$available_locales) )
-		$current_locale = $locale;
-}
-
 $current_locale = get_locale();
+setlocale(LC_TIME, $current_locale);
 $messages = array();
 $output_encoding = array();
 
@@ -179,6 +181,11 @@ function getlocal($text) {
 	return myiconv($webim_encoding,getoutputenc(), getstring_($text,$current_locale));
 }
 
+function getlocal_($text,$locale) {
+	global $webim_encoding;
+	return myiconv($webim_encoding,getoutputenc(), getstring_($text,$locale));
+}
+
 function topage($text) {
 	global $webim_encoding;
 	return myiconv($webim_encoding,getoutputenc(), $text);
@@ -350,8 +357,8 @@ function date_diff($seconds) {
 	}
 }
 
-function is_valid_email($mail) {
-	return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $mail);
+function is_valid_email($email) {
+	return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
 }
 
 function quote_smart($value,$link) {
@@ -377,7 +384,7 @@ function get_month_selection($fromtime,$totime) {
 	$result = array();
 	do {
 		$current = mktime(0,0,0,$month,1,$year);
-		$result[date("m.y",$current)] = date("M, Y",$current);
+		$result[date("m.y",$current)] = strftime("%B, %Y",$current);
 		$month++;
 		if( $month > 12 ) {
 			$month = 1;
@@ -400,4 +407,17 @@ function set_form_date($utime,$prefix) {
 	$page["form${prefix}month"] = date("m.y", $utime);
 }
 
+function webim_mail($toaddr, $reply_to, $subject, $body) {
+	global $webim_encoding, $webim_from_email, $mail_encoding;
+
+	$headers = "From: $webim_from_email\r\n"
+	   ."Reply-To: ".myiconv($webim_encoding, $mail_encoding, $reply_to)."\r\n"
+	   ."Content-Type: text/plain; charset=$mail_encoding\r\n"
+	   .'X-Mailer: PHP/'.phpversion();
+
+	$real_subject = "=?".$mail_encoding."?B?".base64_encode(myiconv($webim_encoding,$mail_encoding,$subject))."?=";
+
+	mail($toaddr, $real_subject, wordwrap(myiconv($webim_encoding, $mail_encoding, $body),70), $headers);
+}
+
 ?>
\ No newline at end of file
diff --git a/src/webim/libs/config.php b/src/webim/libs/config.php
index 05cc69a4..29a6e767 100644
--- a/src/webim/libs/config.php
+++ b/src/webim/libs/config.php
@@ -40,6 +40,11 @@ $force_charset_in_connection = true;
  */
 $compatibility_encoding = "cp1251";
 
+/*
+ * This encoding will be used for emails
+ */
+$mail_encoding = $webim_encoding;
+
 /*
  *   From field in outgoing mail.
  */
@@ -49,7 +54,7 @@ $webim_from_email = "webim@yourdomain.com"; /* email from field */
  *   Inbox for left messages
  */
 $webim_messages_mail = "operators@yourdomain.com";
-$webim_messages_encoding = "en";
+$webim_messages_locale = "en";
 
 /*
  *   Company international name.
@@ -61,6 +66,11 @@ $company_name = "My Company Ltd.";
  */
 $company_logo_link = "";
 
+/*
+ * Web Messenger host
+ */
+$webim_host = "";
+
 /*
  *   Locales 
  */
@@ -74,7 +84,7 @@ $default_locale = "en";                     /* if user does not provide known la
 $user_can_change_name = true;
 
 /*
- *   How to build presentable visitor name from {name}. Default: {name}
+ *   How to build presentable visitor name from {name} or {addr}. Default: {name}
  */ 
 $presentable_name_pattern = "{name}";
 
diff --git a/src/webim/locales/en/properties b/src/webim/locales/en/properties
index 98a777df..f7857cc5 100644
--- a/src/webim/locales/en/properties
+++ b/src/webim/locales/en/properties
@@ -55,6 +55,7 @@ chat.thread.state_wait=In queue
 chat.thread.state_wait_for_another_agent=Waiting for operator
 chat.thread.state_chatting_with_agent=In chat
 chat.thread.state_closed=Closed
+chat.thread.state_loading=Loading
 clients.title=List of awaiting visitors
 clients.no_clients=The list of awaiting visitors is empty
 clients.intro=The page displays list of awaiting visitors.
@@ -79,6 +80,7 @@ page_analysis.search.title=Chats history
 page.analysis.search.head_name=Name
 page.analysis.search.head_host=Visitor's address
 page.analysis.search.head_operator=Operator
+page.analysis.search.head_messages=Visitor's messages
 page.analysis.search.head_time=Time in chat
 common.asterisk_explanation=<b><font class="red">*</font></b> - mandatory fields
 page_agents.title=Agents
diff --git a/src/webim/locales/ru/properties b/src/webim/locales/ru/properties
index 8e0b12f3..acad71eb 100644
--- a/src/webim/locales/ru/properties
+++ b/src/webim/locales/ru/properties
@@ -13,9 +13,9 @@ page_login.remember=
 page_login.error=������ ������������ ����� ��� ������
 agent.not_logged_in=���� ������ ��������, �������, ����������, �����
 page_client.pending_users=�� ���� �������� ����� ����������� ������ ��������� ������ �����������.
-chat.window.title.agent=��� ����������
-chat.window.title.user=��� ����������
-chat.window.product_name=��� <span class="grey">����������</span>
+chat.window.title.agent=��� ����������
+chat.window.title.user=��� ����������
+chat.window.product_name=��� <span class="grey">����������</span>
 chat.window.close_title=������� ������
 chat.window.chatting_with=�� ��������� �:
 chat.window.poweredby=�������������:
@@ -55,6 +55,7 @@ chat.thread.state_wait=
 chat.thread.state_wait_for_another_agent=�������� ���������
 chat.thread.state_chatting_with_agent=� �������
 chat.thread.state_closed=�������
+chat.thread.state_loading=�����������
 clients.title=������ ��������� �����������
 clients.no_clients=� ���� ������� ��������� ����������� ���
 clients.intro=�� ���� �������� ����� ����������� ������ ��������� ������ �����������.
@@ -79,6 +80,7 @@ page_analysis.search.title=
 page.analysis.search.head_name=���
 page.analysis.search.head_host=����� ����������
 page.analysis.search.head_operator=��������
+page.analysis.search.head_messages=��������� ����������
 page.analysis.search.head_time=����� � �������
 common.asterisk_explanation=<b><font class="red">*</font></b> - ����, ������������ ��� ����������
 page_agents.title=������
@@ -99,14 +101,14 @@ leftMenu.client_agents=
 leftMenu.client_gen_button=��� ������
 admin.content.description=����� �������, ��������� ������ ������������������ ����������
 admin.content.client_agents=��������, �������� ������� ��������. ���������� �� ������� � �������������.
-admin.content.client_gen_button=��������� HTML-���� ��� ������ "��� �����������".
+admin.content.client_gen_button=��������� HTML-���� ��� ������ "��� �����������".
 page.gen_button.title=��������� HTML-���� ������
-page.gen_button.intro=�� ���� �������� �� ������ �������� HTML-��� ������ "��� �����������" ��� ���������� �� ����� �����.
+page.gen_button.intro=�� ���� �������� �� ������ �������� HTML-��� ������ "��� �����������" ��� ���������� �� ����� �����.
 page.gen_button.code=HTML-���
 page.gen_button.sample=������
 page.gen_button.code.description=<strong>��������!</strong> ��� ��������<br/> �����-���� ���������<br/> � ���� ��� �����������������<br/> ������ �� �������������!
-mail.user.history.subject=��� ����������: ������� �������
-mail.user.history.body=�����������, {0}!\n\n�� ������ �������, �������� �������: \n\n{1}\n--- \n� ���������,\n��� ����������
+mail.user.history.subject=��� ����������: ������� �������
+mail.user.history.body=�����������, {0}!\n\n�� ������ �������, �������� �������: \n\n{1}\n--- \n� ���������,\n��� ����������
 errors.header=<font color="#c13030"><b>��������� ������:</b><br/><ul>
 errors.prefix=<li class="error">
 errors.suffix=</li>
@@ -130,7 +132,7 @@ image.chat.message=/locales/ru/images/message.gif
 image.button.login=/locales/ru/images/login.gif
 image.button.save=/locales/ru/images/save.gif
 image.button.search=/locales/ru/images/search.gif
-app.title=��� ����������
+app.title=��� ����������
 chat.came.from=���������� ������ �� �������� {0}
 content.history=����� �� ������� ��������
 content.logoff=�������� �������.
@@ -162,7 +164,7 @@ install.title=
 installed.login_link=����� � �������
 installed.message=<b>��������� ������� ���������. </b>
 installed.notice=�� ������ ����� � ������� ��� admin � ������ �������.<br/>� ����� ������������, �������, ����������, ������� /webim/install � ������ ������� � ��������� ������.
-leavemail.body=��� ���������� {0} ������� ���������:\n\n{2}\n\n��� email: {1}\n\n--- \n� ���������,\n��� ���-����������
+leavemail.body=��� ���������� '{0}' ������� ���������:\n\n{2}\n\n�mail: {1}\n\n--- \n� ���������,\n��� ��� ����������
 leavemail.subject=������ �� {0}
 leavemessage.close=�������
 leavemessage.descr=� ���������, ������ ��� �� ������ ���������� ���������. ���������� ���������� ����� ��� �������� ��� ���� ������ � �� �������� � ���� �� ������������ ������.
diff --git a/src/webim/mail.php b/src/webim/mail.php
index b9a06bec..f883e297 100644
--- a/src/webim/mail.php
+++ b/src/webim/mail.php
@@ -52,16 +52,10 @@ foreach( $output as $msg ) {
 	$history .= $msg;
 }
 
-// FIXME mail encoding?
-
 $subject = getstring("mail.user.history.subject");
 $body = getstring2("mail.user.history.body", array($thread['userName'],$history) ); 
 
-$headers = 'From: '.$webim_from_email."\r\n" .
-   'Reply-To: '.$webim_from_email."\r\n" .
-   'X-Mailer: PHP/'.phpversion();
-
-mail($email,$subject,wordwrap($body,70),$headers);
+webim_mail($email, $webim_from_email, $subject, $body);
 
 start_html_output();
 require('view/chat_mailsent.php');
diff --git a/src/webim/operator/history.php b/src/webim/operator/history.php
index 78a24145..6e49bcce 100644
--- a/src/webim/operator/history.php
+++ b/src/webim/operator/history.php
@@ -28,7 +28,8 @@ if($query !== false) {
 	$result = mysql_query(
 		 "select DISTINCT unix_timestamp(chatthread.dtmcreated) as created, ". 
     	 "unix_timestamp(chatthread.dtmmodified) as modified, chatthread.threadid, ".
-		 "chatthread.remote, chatthread.agentName, chatthread.userName ".
+		 "chatthread.remote, chatthread.agentName, chatthread.userName, ".
+		 "messageCount as size ".
 		 "from chatthread, chatmessage ".
 		 "where chatmessage.threadid = chatthread.threadid and ".
 			"((chatthread.userName LIKE '%%$query%%') or ".
diff --git a/src/webim/operator/update.php b/src/webim/operator/update.php
index f0ca98b9..8a3d4208 100644
--- a/src/webim/operator/update.php
+++ b/src/webim/operator/update.php
@@ -27,14 +27,16 @@ $threadstate_to_string = array(
 	$state_queue => "wait",
 	$state_waiting => "prio",
 	$state_chatting => "chat",
-	$state_closed => "closed"
+	$state_closed => "closed",
+	$state_loading => "wait"
 );
 
 $threadstate_key = array(
 	$state_queue => "chat.thread.state_wait",
 	$state_waiting => "chat.thread.state_wait_for_another_agent",
 	$state_chatting => "chat.thread.state_chatting_with_agent",
-	$state_closed => "chat.thread.state_closed"
+	$state_closed => "chat.thread.state_closed",
+	$state_loading => "chat.thread.state_loading"
 );
 
 function thread_to_xml($thread) {
@@ -50,7 +52,7 @@ function thread_to_xml($thread) {
 	$result .= " canopen=\"true\"";
 
 	$result .= " state=\"$state\" typing=\"".$thread['userTyping']."\">";
-	$result .= "<name>".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'])))."</name>";
+	$result .= "<name>".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'],$thread['remote'])))."</name>";
 	$result .= "<addr>".htmlspecialchars(htmlspecialchars($thread['remote']))."</addr>";
 	$result .= "<agent>".htmlspecialchars(htmlspecialchars($threadoperator))."</agent>";
 	$result .= "<time>".$thread['unix_timestamp(dtmcreated)']."000</time>";
diff --git a/src/webim/view/chat_ajaxed.php b/src/webim/view/chat_ajaxed.php
index 0c8df75e..5566e038 100644
--- a/src/webim/view/chat_ajaxed.php
+++ b/src/webim/view/chat_ajaxed.php
@@ -45,7 +45,18 @@ var threadParams = { servl:"<?php echo $webimroot ?>/thread.php",wroot:"<?php ec
 		    <td height="10"></td>
 			</tr>
 			<tr>
-		    <td align="center"><?php if( $page['ct.company.chatLogoURL'] ) { ?><a onclick="window.open('<?php echo getlocal("site.url") ?>');return false;" href="_blank"><img src="<?php echo $page['ct.company.chatLogoURL'] ?>" border="0" alt=""></a><?php } ?></td>
+		    <td align="center">
+		    	<?php if( $page['ct.company.chatLogoURL'] ) { ?>
+		    		<?php if( $page['webimHost'] ) { ?>
+		            	<a onclick="window.open('<?php echo $page['webimHost'] ?>');return false;" href="_blank">
+			            	<img src="<?php echo $page['ct.company.chatLogoURL'] ?>" border="0" alt="">
+			            </a>
+			        <?php } ?>
+		    		<?php if( !$page['webimHost'] ) { ?>
+		            	<img src="<?php echo $page['ct.company.chatLogoURL'] ?>" border="0" alt="">
+			        <?php } ?>
+		        <?php } ?>
+		    </td>
 			</tr>
 			<tr>
 		    <td height="5"></td>
diff --git a/src/webim/view/thread_search.php b/src/webim/view/thread_search.php
index 69237d81..d992c1e0 100644
--- a/src/webim/view/thread_search.php
+++ b/src/webim/view/thread_search.php
@@ -70,6 +70,7 @@
 			<td class='table' bgcolor='#276db8' height='30'><span class='header'><?php echo getlocal("page.analysis.search.head_name") ?></span></td><td width='3'></td>
 			<td class='table' bgcolor='#276db8' height='30'><span class='header'><?php echo getlocal("page.analysis.search.head_host") ?></span></td><td width='3'></td>
 			<td class='table' bgcolor='#276db8' height='30'><span class='header'><?php echo getlocal("page.analysis.search.head_operator") ?></span></td><td width='3'></td>
+			<td class='table' bgcolor='#276db8' height='30'><span class='header'><?php echo getlocal("page.analysis.search.head_messages") ?></span></td><td width='3'></td>
 			<td class='table' bgcolor='#276db8' height='30'><span class='header'><?php echo getlocal("page.analysis.search.head_time") ?></span></td>
 		</tr>
 		<?php foreach( $page['pagination.items'] as $chatthread ) { ?>
@@ -84,10 +85,13 @@
         			<?php if( $chatthread['agentName'] ) { ?><?php echo topage(htmlspecialchars($chatthread['agentName'])) ?><?php } ?>
 				</td><td background='<?php echo $webimroot ?>/images/tablediv3.gif'><img width='3' height='1' border='0' alt='' src='<?php echo $webimroot ?>/images/free.gif'></td>
 				<td height='30' class='table'>
-					<?php echo date("d M Y H:i:s", $chatthread['created']) ?>,  <?php echo date_diff($chatthread['modified']-$chatthread['created']) ?>
+        			<?php echo topage(htmlspecialchars($chatthread['size'])) ?>
+				</td><td background='<?php echo $webimroot ?>/images/tablediv3.gif'><img width='3' height='1' border='0' alt='' src='<?php echo $webimroot ?>/images/free.gif'></td>
+				<td height='30' class='table'>
+					<?php echo strftime("%B, %d %Y %H:%M:%S", $chatthread['created']) ?>,  <?php echo date_diff($chatthread['modified']-$chatthread['created']) ?>
 				</td>
 			</tr>
-			<tr><td height='2' colspan='7'></td></tr><tr><td bgcolor='#e1e1e1' colspan='7'><img width='1' height='1' border='0' alt='' src='<?php echo $webimroot ?>/images/free.gif'></td></tr><tr><td height='2' colspan='7'></td></tr>
+			<tr><td height='2' colspan='9'></td></tr><tr><td bgcolor='#e1e1e1' colspan='9'><img width='1' height='1' border='0' alt='' src='<?php echo $webimroot ?>/images/free.gif'></td></tr><tr><td height='2' colspan='9'></td></tr>
 		<?php } ?>
 	</table>
 	<br />