<HTML>
  <HEAD>
    <SCRIPT>

      function setPassword()
      {
        // This should be done once each time you start the application.
        // Doing this additional times (i.e. each time you create a new
        // window) is acceptable.
        //
        // Note:  You can also access the connection object by creating
        // an ActiveX object with the class name
        // "TradeIdeasWindow.ConnectionControl".  That will allow you to set
        // the account information before you create any windows.
        TradeIdeasWindowX1.Connection.UserName = username.value;
        TradeIdeasWindowX1.Connection.Password = password.value;
      }

      function setServerUrl()
      {
        // This is typically not required.  It is available primarily for
        // test purposes.  The default value of this property is our
        // production server.
        TradeIdeasWindowX1.Connection.ServerUrl = server_url.value;
      }

      function getList()
      {
        // In this example we create the symbol list object each time it is
        // needed.  This gives us the ability to work on a different symbol
        // list each time.
        //
        // A typical application would have a fixed number of lists (i.e.
        // "short positions" and "long positions") and would not need this
        // flexibility.  That application could create these objects once
        // when the application first starts.
        //
        // Note: SymbolList is an array property, not a function.  In
        // some development environments the list id would be in [] rather
        // than ().

        var list = TradeIdeasWindowX1.Connection.SymbolList(list_id.value);
        // The list name is updated every time we update the symbols in the
        // list.  A typical application would have a fixed name for each list
        // id.
        list.Name = list_name.value;
        return list;
      }

      function addSymbol()
      {
        getList().AddSymbol(symbol.value);
      }

      function deleteSymbol()
      {
        getList().DeleteSymbol(symbol.value);
      }

      function setSymbolList()
      {
        var list = getList();

        // The next two lines are just a silly example / test code.
        // A typical application would never need to call ClearWorkList.
        // Each time you create a new list object the work list is empty.
        // Each time you send the work list to the server, the work list
        // is cleared.  If you have multiple list objects each one has
        // its own work list, even if two list objects point to the
        // same list id
        list.AddToWorkList('silly');
        list.ClearWorkList();

        // Add the symbols to the work list, one at a time, then
        // send the entire list to the server at once.
        var listItems = symbol_list.value.split('\r\n');
        var line;
        for (line in listItems)
        {
          list.AddToWorkList(listItems[line]);
        }
        list.SendWorkList();
      }

      function resetConnection()
      {
        TradeIdeasWindowX1.Connection.reset();
      }

      function requestSymbolLists()
      {
        if (listOfLists)
        {
          // You can optionally set DataPresent to false here.
          listOfLists.refreshData();
        }
        else
        {
          listOfLists = TradeIdeasWindowX1.Connection.getListOfLists();
        }
      }

      function showSymbolLists()
      {
        if (!listOfLists)
        {
          list_names_output.innerText = "No request!";
        }
        else if (!listOfLists.DataPresent)
        {
          list_names_output.innerText = "Waiting for response.";
        }
        else
        {
          var output="";
          var list;
          listOfLists.ResetPointer();
          while (list = listOfLists.GetNextList())
          {
            output = output + list.id + ";" + list.name + "\r\n";
          }
          list_names_output.innerText = output;
        }
      }
    </SCRIPT>
  </HEAD>
  <BODY>
    <object classid="clsid:E940966A-5FEE-47AA-8EDF-324E45D9AFAE" id="TradeIdeasWindowX1" width="326" height="256" align="center">
    <param name="AxBorderStyle" value="3">
    Please install the TradeIdeasWindow ActiveX control before using this demo.
    </object>
    <BR>
    <HR>
    Username: <INPUT ID="username"><BR>
    Password: <INPUT TYPE="password" ID="password"><BR>
    <BUTTON ONCLICK="setPassword()">Set Password</BUTTON>
    <HR>
    Server URL: <INPUT ID="server_url"><BR>
    <BUTTON ONCLICK="setServerUrl()">Set</BUTTON>  
    <HR>
    List ID: <INPUT ID="list_id"><BR>
    List Name: <INPUT ID="list_name"><BR>
    <HR>
    Symbol: <INPUT ID="symbol"><BR>
    <BUTTON ONCLICK="addSymbol()">Add Symbol</BUTTON><BR>
    <BUTTON ONCLICK="deleteSymbol()">Delete Symbol</BUTTON>
    <HR>
    <TEXTAREA ROWS=7 ID="symbol_list"></TEXTAREA><BR>
    <BUTTON ONCLICK="setSymbolList()">Set Symbol List</BUTTON>
    <HR>
    <object classid="clsid:49AB7098-51E7-41B3-9833-FB5FAE3EAF1F" id="StatusBarX1" align="center">
    <param name="AxBorderStyle" value="1">
    Please install the TradeIdeasWindow ActiveX control before using this demo.
    </object><BR>
    <BUTTON ONCLICK="resetConnection()">Reset Connection</BUTTON>
    <HR>
    <TEXTAREA ROWS=7 ID="list_names_output"></TEXTAREA><BR>
    <BUTTON ONCLICK="requestSymbolLists()">Request Symbol Lists</BUTTON><BR>
    <BUTTON ONCLICK="showSymbolLists()">Show Symbol Lists</BUTTON>
  </BODY>
</HTML>  
<SCRIPT>
  server_url.value = TradeIdeasWindowX1.Connection.ServerUrl;
  listOfLists = 0;
</SCRIPT>