diff --git a/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_html.html b/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_html.html
index ee2ee76cd1216191fe9c5a5498bae5215368c84b..4eb9ba00221c6d98aa10a861324ec81a402e43f0 100644
--- a/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_html.html
+++ b/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_html.html
@@ -12,13 +12,24 @@
     <!-- custom script -->
     <script src="gadget_global.js" type="text/javascript"></script>
     <script src="gadget_jabberclient_page_dialog.js" type="text/javascript"></script>
+
+    <script id="input-template" type="text/x-handlebars-template">
+      <input class="input-content" type="text" data-enhanced="true" name="content"
+        placeholder="Write something..." value="" required>
+    </script>
+    <script id="textarea-template" type="text/x-handlebars-template">
+      <textarea class="textarea-content" type="text" data-enhanced="true" name="content" 
+        placeholder="Write a multi-line message..." value="" required></textarea>
+    </script>
   </head>
   <body>
       <div class="discussion-content"></div>
       <div data-role="footer" data-position="fixed" data-tap-toggle="false">
         <form class="message-form">
-          <div class="ui-input-text ui-corner-all ui-body-inherit ui-shadow-inset ui-input-has-clear">
-            <input type="text" data-enhanced="true" name="content" placeholder="Write something..." value="" required>
+          <div class="ui-input-text ui-corner-all ui-body-inherit ui-shadow-inset ui-input-has-clear ui-input-has-multiline">
+            <div class="custom-mode-change ui-btn ui-btn-icon-notext ui-input-clear ui-input-btn ui-corner-all ui-icon-comment ui-btn-left">
+              <input data-enhanced="true" type="button" value="">
+            </div>
             <div class="ui-btn ui-input-clear ui-input-btn ui-corner-all ui-icon-edit ui-btn-icon-notext">
               <input data-enhanced="true" type="submit" value="Send">
             </div>
diff --git a/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_html.xml b/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_html.xml
index 909a867e4550429d0661292daaee10d35095ea7a..c80c48702c079907fdaa65a714ba9524d84886d2 100644
--- a/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_html.xml
+++ b/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_html.xml
@@ -234,7 +234,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>949.30780.1199.42069</string> </value>
+                <value> <string>950.63332.2255.41369</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -252,7 +252,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1456843290.96</float>
+                        <float>1462370312.21</float>
                         <string>UTC</string>
                       </tuple>
                     </state>
diff --git a/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_js.js b/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_js.js
index 4fa4f549c91731ec78308be24f0fbc3b48e479b0..ed035e1104bbe64b5bd74c80c51b85b7815f0c09 100644
--- a/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_js.js
+++ b/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_js.js
@@ -1,6 +1,6 @@
-/*global window, document, rJS, RSVP, loopEventListener*/
+/*global window, document, rJS, RSVP, Handlebars, loopEventListener*/
 /*jslint nomen: true, indent: 2, maxerr: 3 */
-(function (window, document, rJS, RSVP, loopEventListener) {
+(function (window, document, rJS, RSVP, Handlebars, loopEventListener) {
   "use strict";
 
   function scroll() {
@@ -13,10 +13,29 @@
       });
   }
 
-  // MESSAGE_FRESHNESS 30 minutes
-  var MESSAGE_FRESHNESS = 1800000;
+  function getDomFromString(str) {
+    var temp_div = document.createElement('div');
+    temp_div.innerHTML = str.trim();
+    return temp_div.firstChild;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Handlebars
+  /////////////////////////////////////////////////////////////////
+  // Precompile the templates while loading the first gadget instance
+  var gadget_klass = rJS(window),
+    input_source = gadget_klass.__template_element
+                         .getElementById("input-template")
+                         .innerHTML,
+    input_template = Handlebars.compile(input_source),
+    textarea_source = gadget_klass.__template_element
+                         .getElementById("textarea-template")
+                         .innerHTML,
+    textarea_template = Handlebars.compile(textarea_source),
+    // MESSAGE_FRESHNESS 30 minutes
+    MESSAGE_FRESHNESS = 1800000;
 
-  rJS(window)
+  gadget_klass
     /////////////////////////////////////////////////////////////////
     // ready
     /////////////////////////////////////////////////////////////////
@@ -30,6 +49,10 @@
       return g.getElement()
         .push(function (element) {
           g.props.element = element;
+          g.props.template_container = element.querySelector('.ui-input-has-multiline');
+          g.props.keep_text_dict = {'oneline': '', 'textarea': ''};
+          g.props.template_container.insertBefore(getDomFromString(input_template()),
+                                                  g.props.template_container.firstChild);
         });
     })
 
@@ -48,9 +71,12 @@
     /////////////////////////////////////////////////////////////////
     .declareMethod("render", function (options) {
       var gadget = this,
-        ul = document.createElement("ul");
+        ul = document.createElement("ul"),
+        template_container = gadget.props.template_container;
       ul.setAttribute("data-role", "listview");
       gadget.props.jid = options.jid;
+      template_container.children[0].focus();
+      template_container.children[0].select();
       return gadget.updateHeader({
         page_title: options.jid
       })
@@ -108,21 +134,28 @@
               index = line.indexOf('] ');
               if (index !== -1) {
                 // Check message freshness
+                // If we receive one multiline message, then the lines after the first
+                // would not start with the date. So this would return Invalid Date
                 message_date = new Date(line.substring(1, index));
-                if (previous_message_date === undefined) {
-                  previous_message_date = new Date(message_date - MESSAGE_FRESHNESS - 2);
-                }
-                if (message_date - previous_message_date > MESSAGE_FRESHNESS) {
-                  is_old = true;
-                }
-                // Check direction
-                tmp_line = line.substring(index + 2);
-                if (tmp_line.indexOf('> ') === 0) {
-                  message_is_incoming = false;
-                } else if (tmp_line.indexOf('< ') === 0) {
-                  message_is_incoming = true;
+                // Check direction and cut the date from the start of the line. 
+                // This should be done only if it is a unique line or the first
+                // line of a multi-line message. Other lines will retain direction
+                // of the first
+                if (isNaN(message_date) === false) {
+                  if (previous_message_date === undefined) {
+                    previous_message_date = new Date(message_date - MESSAGE_FRESHNESS - 2);
+                  }
+                  if (message_date - previous_message_date > MESSAGE_FRESHNESS) {
+                    is_old = true;
+                  }
+                  tmp_line = line.substring(index + 2);
+                  if (tmp_line.indexOf('> ') === 0) {
+                    message_is_incoming = false;
+                  } else if (tmp_line.indexOf('< ') === 0) {
+                    message_is_incoming = true;
+                  }
+                  line = tmp_line.substring(2);
                 }
-                line = tmp_line.substring(2);
                 if (message_is_incoming !== is_incoming || is_old) {
                   appendText(displayed_text, is_incoming);
                   is_incoming = message_is_incoming;
@@ -149,13 +182,21 @@
     })
 
     .declareService(function () {
-      var form_gadget = this;
-
+      var form_gadget = this,
+        template_container = form_gadget.props.template_container,
+        keep_text_dict = form_gadget.props.keep_text_dict;
       function formSubmit(submit_event) {
         return form_gadget.notifySubmitting()
           .push(function () {
             var text = submit_event.target[0].value;
             submit_event.target[0].value = "";
+            keep_text_dict.oneline = "";
+            keep_text_dict.textarea = "";
+            template_container.removeChild(template_container.firstChild);
+            template_container.insertBefore(getDomFromString(input_template()),
+                                            template_container.firstChild);
+            template_container.children[0].focus();
+            template_container.children[0].select();
             return form_gadget.jio_putAttachment(
               form_gadget.props.jid,
               'MESSAGE',
@@ -185,8 +226,41 @@
       );
     })
 
+    .declareService(function () {
+      var gadget = this,
+        template_container = gadget.props.template_container,
+        keep_text_dict = gadget.props.keep_text_dict;
+      function changeMode() {
+        if (template_container.children[0].className === 'input-content') {
+          keep_text_dict.oneline = template_container.children[0].value;
+          template_container.removeChild(template_container.firstChild);
+          template_container.insertBefore(getDomFromString(textarea_template()),
+                                                          template_container.firstChild);
+          template_container.children[0].value = keep_text_dict.textarea;
+        } else {
+          keep_text_dict.textarea = template_container.children[0].value;
+          template_container.removeChild(template_container.firstChild);
+          template_container.insertBefore(getDomFromString(input_template()),
+                                                          template_container.firstChild);
+          template_container.children[0].value = keep_text_dict.oneline;
+        }
+        var typing_field = template_container.children[0];
+        typing_field.focus();
+        typing_field.select();
+        typing_field.selectionStart = typing_field.selectionEnd = typing_field.value.length;
+      }
+
+      // Listen to button click
+      return loopEventListener(
+        gadget.props.element.querySelector('.custom-mode-change'),
+        'click',
+        false,
+        changeMode
+      );
+    })
+
     .declareService(function () {
       scroll();
     });
 
-}(window, document, rJS, RSVP, loopEventListener));
\ No newline at end of file
+}(window, document, rJS, RSVP, Handlebars, loopEventListener));
\ No newline at end of file
diff --git a/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_js.xml b/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_js.xml
index 27a0cecfe880f2b63c85363cb96ed82bccd36458..4c06125d29d4e4ea965518066cb8a71150c0ba24 100644
--- a/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_js.xml
+++ b/bt5/erp5_web_jabber_client/PathTemplateItem/web_page_module/jabber_gadget_page_dialog_js.xml
@@ -230,7 +230,7 @@
             </item>
             <item>
                 <key> <string>serial</string> </key>
-                <value> <string>949.36447.38496.63744</string> </value>
+                <value> <string>950.63396.22857.42769</string> </value>
             </item>
             <item>
                 <key> <string>state</string> </key>
@@ -248,7 +248,7 @@
                     </tuple>
                     <state>
                       <tuple>
-                        <float>1456908330.96</float>
+                        <float>1462370315.51</float>
                         <string>UTC</string>
                       </tuple>
                     </state>