Index: /trunk/FACT++/src/RemoteControl.cc
===================================================================
--- /trunk/FACT++/src/RemoteControl.cc	(revision 14049)
+++ /trunk/FACT++/src/RemoteControl.cc	(revision 14050)
@@ -23,8 +23,8 @@
         {
             fCurrentServer = s;
-            return false;
+            return true;
         }
         lout << kRed << "Unkown server '" << s << "'" << endl;
-        return true;
+        return false;
     }
 
@@ -32,8 +32,8 @@
     {
         fCurrentServer = "";
-        return false;
+        return true;
     }
 
-    return !SendDimCommand(lout, fCurrentServer, str);
+    return SendDimCommand(lout, fCurrentServer, str);
 }
 
Index: /trunk/FACT++/src/RemoteControl.h
===================================================================
--- /trunk/FACT++/src/RemoteControl.h	(revision 14049)
+++ /trunk/FACT++/src/RemoteControl.h	(revision 14050)
@@ -1,4 +1,6 @@
 #ifndef FACT_RemoteControl
 #define FACT_RemoteControl
+
+#include "InterpreterV8.h"
 
 // **************************************************************************
@@ -59,5 +61,5 @@
 
 template <class T>
-class RemoteControl : public T, public RemoteControlImp
+class RemoteControl : public T, public RemoteControlImp, public InterpreterV8
 {
 private:
@@ -135,4 +137,53 @@
         T::UpdatePrompt();
     }
+
+    // ===========================================================================
+
+    virtual void JsLoad(const std::string &)         { SetSection(-2); }
+    virtual void JsStart(const std::string &)        { SetSection(-1); }
+    virtual void JsEnd(const std::string &)          { SetSection(-3); }
+    virtual bool JsSend(const std::string &str)      { return ProcessCommand(str); }
+    virtual void JsPrint(const std::string &msg)     { fImp->Comment(msg); }
+    virtual void JsException(const std::string &str) { fImp->Error(str); }
+
+    void JsSleep(uint32_t ms)
+    {
+        const Time timeout = ms<=0 ? Time(Time::none) : Time()+boost::posix_time::millisec(ms);
+
+        T::GetStreamOut().Display(true);
+        T::GetStreamOut().SetBacklog(false);
+        T::GetStreamOut().SetNullOutput(false);
+        while (timeout>Time() && !T::IsScriptStopped())
+            usleep(1);
+        T::GetStreamOut().SetNullOutput(true);
+        T::GetStreamOut().SetBacklog(true);
+    }
+
+    int JsWait(const string &server, int32_t state, uint32_t ms)
+    {
+        const ClientList::const_iterator l = fClientList.find(server);
+        if (l==fClientList.end())
+        {
+            lout << kRed << "Server '" << server << "' not found." << endl;
+            T::StopScript();
+            return -1;
+        }
+
+        const Time timeout = ms<=0 ? Time(Time::none) : Time()+boost::posix_time::millisec(ms);
+
+        T::GetStreamOut().Display(true);
+        T::GetStreamOut().SetBacklog(false);
+        T::GetStreamOut().SetNullOutput(false);
+        while (l->second->GetState()!=state && timeout>Time() && !T::IsScriptStopped())
+            usleep(1);
+        T::GetStreamOut().SetNullOutput(true);
+        T::GetStreamOut().SetBacklog(true);
+
+        return l->second->GetState()==state;
+    }
+
+
+    // ===========================================================================
+
 
 public:
@@ -196,4 +247,10 @@
         }
 
+        if (str.substr(0, 4)==".js ")
+        {
+            JsRun(Tools::Trim(str.substr(3)));
+            return true;
+        }
+
         if (str.substr(0, 3)==".s ")
         {
@@ -210,22 +267,7 @@
             }
 
-            const ClientList::const_iterator l = fClientList.find(server);
-            if (l==fClientList.end())
-            {
-                lout << kRed << "Server '" << server << "' not found." << endl;
-                return true;
-            }
-
-            const Time timeout = ms<=0 ? Time(Time::none) : Time()+boost::posix_time::millisec(ms);
-
-            T::GetStreamOut().Display(true);
-            T::GetStreamOut().SetBacklog(false);
-            T::GetStreamOut().SetNullOutput(false);
-            while (l->second->GetState()!=state && timeout>Time() && !T::IsScriptStopped())
-                usleep(1);
-            T::GetStreamOut().SetNullOutput(true);
-            T::GetStreamOut().SetBacklog(true);
-
-            if (l->second->GetState()==state)
+            const int rc = JsWait(server, state, ms);
+
+            if (rc<0 || rc==1)
                 return true;
 
@@ -267,5 +309,5 @@
         }
 
-        return ProcessCommand(str);
+        return !ProcessCommand(str);
     }
 
