
with Interfaces;                              use Interfaces;
with Interfaces.C;                            use Interfaces.C;
with Ada.Characters.Latin_1;                  use Ada.Characters.Latin_1;
with GNATCOM;                                 use GNATCOM;
with GNATCOM.Initialize;
with GNATCOM.Types;                           use GNATCOM.Types;
with GNATCOM.Events;                          use GNATCOM.Events;
with GNATCOM.Create.COM_Interface;            use GNATCOM.Create.COM_Interface;
with GNATCOM.Iinterface;                      use GNATCOM.Iinterface;
with GNATCOM.Dispinterface;                   use GNATCOM.Dispinterface;
with GNATOCX;                                 use GNATOCX;
with GNATOCX.IOleClientSite_Interface;        use GNATOCX.IOleClientSite_Interface;
with GNATOCX.IOleObject_Interface;            use GNATOCX.IOleObject_Interface;
with GWindows;                                use GWindows;
with GWindows.Types;                          use GWindows.Types;
with GWindows.Windows.Main;                   use GWindows.Windows.Main;
with GWindows.ActiveX;                        use GWindows.ActiveX;
with GWindows.GStrings;                       use GWindows.GStrings;
with GWindows.GStrings.Constants;             use GWindows.GStrings.Constants;
with GWindows.GStrings.Unbounded;             use GWindows.GStrings.Unbounded;
with GWindows.Base;                           use GWindows.Base;
with GWindows.Application;                    use GWindows.Application;
with GWindows.Constants;                      use GWindows.Constants;
with GWindows.GStrings.Handling;              use GWindows.GStrings.Handling;
with GWindows.AuxHelper;                      use GWindows.AuxHelper;
with GProfileConfig;                          use GProfileConfig;

with SHDocVw;
with SHDocVw.IWebBrowser2_Interface;          use SHDocVw.IWebBrowser2_Interface;
with SHDocVw.DWebBrowserEvents2_Events;       use SHDocVw.DWebBrowserEvents2_Events;
with MSHTML;                                  use MSHTML;
with MSHTML.IHTMLDocument2_Interface;         use MSHTML.IHTMLDocument2_Interface;
with MSHTMLHST;                               use MSHTMLHST;
with MSHTMLHST.IDocHostUIHandler_Object;      use MSHTMLHST.IDocHostUIHandler_Object;
with MSHTML.IHTMLElementCollection_Interface; use MSHTML.IHTMLElementCollection_Interface;
with MSHTML.IHTMLElement_Interface;           use MSHTML.IHTMLElement_Interface;
with MSHTML.IHTMLEventObj_Interface;          use MSHTML.IHTMLEventObj_Interface;
with MSHTML.IHTMLButtonElement_Interface;     use MSHTML.IHTMLButtonElement_Interface;
with MSHTML.IHTMLTable_Interface;             use MSHTML.IHTMLTable_Interface;
with MSHTML.IHTMLTableRow_Interface;          use MSHTML.IHTMLTableRow_Interface;
with MSHTML.IHTMLTableCell_Interface;         use MSHTML.IHTMLTableCell_Interface;
with MSHTML.IHTMLStyle_Interface;             use MSHTML.IHTMLStyle_Interface;
with MSHTML.IHTMLInputTextElement_Interface;  use MSHTML.IHTMLInputTextElement_Interface;
with MSHTML.IHTMLElement2_Interface;          use MSHTML.IHTMLElement2_Interface;

with HtmlForm;                                use HtmlForm;
with AboutBox;                                use AboutBox;
with RTSDDMessageBox;                         use RTSDDMessageBox;

package body PublicDNSPluginConfig is

   type Html_App_Window_Type is new Main_Window_Type with null record;
   procedure On_Destroy (Window : in out Html_App_Window_Type);
   type WebBrowserEvents2_Event_Type is new DWebBrowserEvents2_Event with null record;
   procedure DocumentComplete(
			      This  : WebBrowserEvents2_Event_Type;
			      pDisp : GNATCOM.Types.VARIANT;
			      URL   : GNATCOM.Types.VARIANT
			     );
   procedure NavigateComplete2(
			       This  : WebBrowserEvents2_Event_Type;
			       pDisp : GNATCOM.Types.VARIANT;
			       URL   : GNATCOM.Types.VARIANT
			      );
   --  Override from SHDocVw.DWebBrowserEvents2_Events.DWebBrowserEvents2_Event
   WebBrowser_Event_Object : aliased WebBrowserEvents2_Event_Type;
   --  Create event object
   WebBrowser_Event : Pointer_To_COM_Interface_Type :=
     SHDocVw.DWebBrowserEvents2_Events.Create (WebBrowser_Event_Object'Unchecked_Access);
   --  Create COM interface wrapper around event object
   WebBrowser_Events_CPoint : IConnectionPoint_Type;
   --  Interface to connection point with in COM object
   --  Used to connect and disconnect event object
   --  Disconnect is performed automaticly when Handle_Events is finalized

   type DocHostUIHandler_Object_Type is
     new IDocHostUIHandler_Object_Type with null record;
   function ShowContextMenu(
			    This           : DocHostUIHandler_Object_Type;
			    dwID           : DWORD;
			    ppt            : access Point_Type;
			    pcmdtReserved  : access IUnknown;
			    pdispReserved  : access IDispatch
			   ) return HRESULT;
   function GetHostInfo(
			This           : DocHostUIHandler_Object_Type;
			pInfo          : access DOCHOSTUIINFO
		       ) return HRESULT;
   g_oDocHostUIHandler  : DocHostUIHandler_Object_Type;
   g_oWebClientSite     : IOleClientSite_Type;
   g_fOldQueryInterface : af_IOleClientSite_QueryInterface;
   function g_fNewQueryInterface(
				 This   : access IOleClientSite;
				 riid   : Pointer_To_GUID;
				 ppvObj : Pointer_To_Pointer_To_Void
				) return HRESULT;
   pragma Convention (StdCall, g_fNewQueryInterface);

   type DHtmlForm_type is new HtmlForm_type with null record;
   procedure UpdateData(
			This       : in out DHtmlForm_type;
			bReadOp    : Boolean := False
		       );

   Main_Window : Html_App_Window_Type;
   IC_Control  : aliased ActiveX_Type;
   IC_COM      : IWebBrowser2_Type;
   Main_Url    : GString := "res://" & GetAppFileName & "/PUBLICDNSPLUGINCONFIG.HTM";
   -- HtmlForm
   g_oHtmlForm : DHtmlForm_type;
   g_usVersionHTMLString : GString_Unbounded := To_GString_Unbounded(GetVersionString & "&nbsp;&beta;");
   g_usCopyRightDates    : GString_Unbounded := To_GString_Unbounded("2006-2017");
   g_usStatusStr         : GString_Unbounded := To_GString_Unbounded("Готово");
   g_usDomainZoneName    : GString_Unbounded;
   g_usSetupImageSRC     : GString_Unbounded := To_GString_Unbounded("SETUP.GIF");
   g_usUninstallImageSRC : GString_Unbounded := To_GString_Unbounded("UNINSTALL32.PNG");
   g_usRestartImageSRC   : GString_Unbounded := To_GString_Unbounded("RESTARTHS.PNG");
   procedure OnSetupClick(oEventObj : in out IHTMLEventObj_Type);
   procedure OnExitClick(oEventObj : in out IHTMLEventObj_Type);
   procedure DoAboutBox(oEventObj : in out IHTMLEventObj_Type);
   procedure TestDnsZoneName(oEventObj : in out IHTMLEventObj_Type);
   procedure TestPublicIP(oEventObj : in out IHTMLEventObj_Type);
   procedure TestPrivateIP(oEventObj : in out IHTMLEventObj_Type);
   procedure TestPublicRange(oEventObj : in out IHTMLEventObj_Type);
   procedure TestPrivateRange(oEventObj : in out IHTMLEventObj_Type);
   procedure TestPublicSubnet(oEventObj : in out IHTMLEventObj_Type);
   procedure TestPrivateSubnet(oEventObj : in out IHTMLEventObj_Type);
   procedure TestPublicIPv6(oEventObj : in out IHTMLEventObj_Type);
   procedure TestPrivateIPv6(oEventObj : in out IHTMLEventObj_Type);
   procedure SaveParameters(oEventObj : in out IHTMLEventObj_Type);
   procedure ReloadParameters(oEventObj : in out IHTMLEventObj_Type);
   procedure OnUninstallClick(oEventObj : in out IHTMLEventObj_Type);
   procedure OnRestartClick(oEventObj : in out IHTMLEventObj_Type);
   g_aOnClickEvents      : aliased Event_Descriptors  :=
     (
	(To_GString_Unbounded("setup_button"), OnSetupClick'Access),
        (To_GString_Unbounded("exit_button"), OnExitClick'Access),
        (To_GString_Unbounded("about_icon"), DoAboutBox'Access),
        (To_GString_Unbounded("test_dns_zone_name"), TestDnsZoneName'Access),
        (To_GString_Unbounded("test_public_ip_button"), TestPublicIP'Access),
        (To_GString_Unbounded("test_private_ip_button"), TestPrivateIP'Access),
        (To_GString_Unbounded("test_public_range_button"), TestPublicRange'Access),
        (To_GString_Unbounded("test_private_range_button"), TestPrivateRange'Access),
        (To_GString_Unbounded("test_public_subnet_button"), TestPublicSubnet'Access),
        (To_GString_Unbounded("test_private_subnet_button"), TestPrivateSubnet'Access),
        (To_GString_Unbounded("test_public_ip6_button"), TestPublicIPv6'Access),
        (To_GString_Unbounded("test_private_ip6_button"), TestPrivateIPv6'Access),
        (To_GString_Unbounded("save_button"), SaveParameters'Access),
        (To_GString_Unbounded("load_button"), ReloadParameters'Access),
        (To_GString_Unbounded("uninstall_button"), OnUninstallClick'Access),
        (To_GString_Unbounded("restart_button"), OnRestartClick'Access)
     );


   procedure Start_Application is
      Left       : Integer := GetConfigInt(
					   "WindowPlacement",
					   "leftNormal",
					   Use_Default
					  );
      Top        : Integer := GetConfigInt(
					   "WindowPlacement",
					   "topNormal",
					   Use_Default
					  );
      Width      : Integer := GetConfigInt(
					   "WindowPlacement",
					   "widthNormal",
					   Use_Default
					  );
      Height     : Integer := GetConfigInt(
					   "WindowPlacement",
					   "heightNormal",
					   Use_Default
					  );
      bMaximized : Boolean := GetConfigInt(
					   "WindowPlacement",
					   "bMaximized"
					  ) /= 0;
      nCmdShow    : Integer := SW_SHOWNORMAL;
      oOleObject  : IOleObject_Type;
      pClientSite : aliased Pointer_To_IOleClientSite;
   begin
      g_usDomainZoneName := To_GString_Unbounded(
						 GetConfigString(
						   "service_settings",
						   "dns_zone_name",
						   ""
						  )
						);
      if bMaximized then
	 nCmdShow := SW_SHOWMAXIMIZED;
      end if;
      GNATCOM.Initialize.Initialize_COM;
      Create (
	      Main_Window,
	      "Тестовое HTML приложение",
	      Left,
	      Top,
	      Width,
	      Height
	     );
      Create (
              IC_Control,
              Main_Window,
              SHDocVw.CLSID_WebBrowser,
              1,
              1,
              1,
              1
             );
      Dock (IC_Control, GWindows.Base.Fill);
      Large_Icon (Main_Window, "MAIN_FRAME");
      Query (IC_COM, Interfac (IC_Control));
      Query (oOleObject, IC_COM);
      GetClientSite(oOleObject, pClientSite'Unchecked_Access);
      g_fOldQueryInterface := pClientSite.Vtbl.QueryInterface;
      Attach(g_oWebClientSite, pClientSite);
      Create(g_oDocHostUIHandler);
      pClientSite.Vtbl.QueryInterface := g_fNewQueryInterface'Access;
      SetClientSite(oOleObject, pClientSite);
      SHDocVw.DWebBrowserEvents2_Events.Set_Events(
						   WebBrowser_Events_CPoint,
						   For_Object      => IC_COM,
						   Event_Interface => WebBrowser_Event
						  );
      Navigate(
	       IC_COM,
	       To_BSTR_From_GString(Main_Url)
	      );
      ShowWindow(Main_Window, nCmdShow);
      UpdateWindow (Main_Window);
      Message_Loop;
   end Start_Application;

   procedure On_Destroy (Window : in out Html_App_Window_Type) is
      nLeft      : Integer;
      nTop       : Integer;
      nWidth     : Integer;
      nHeight    : Integer;
      WP         : WindowPlacement_Type := WindowPlacement(Window);
      nMaximized : Integer := 0;
   begin
      nLeft   := WP.rcNormalPosition.Left;
      nTop    := WP.rcNormalPosition.Top;
      nWidth  := WP.rcNormalPosition.Right - nLeft;
      nHeight := WP.rcNormalPosition.Bottom - nTop;
      if WP.showCmd = SW_SHOWMAXIMIZED then
	 nMaximized := 1;
      end if;
      WriteConfigInt(
		     "WindowPlacement",
		     "bMaximized",
		     nMaximized
		    );
      WriteConfigInt(
		     "WindowPlacement",
		     "leftNormal",
		     nLeft
		    );
      WriteConfigInt(
		     "WindowPlacement",
		     "topNormal",
		     nTop
		    );
      WriteConfigInt(
		     "WindowPlacement",
		     "widthNormal",
		     nWidth
		    );
      WriteConfigInt(
		     "WindowPlacement",
		     "heightNormal",
		     nHeight
		    );
      On_Destroy(Main_Window_Type(Window));
   end On_Destroy;

   procedure NavigateComplete2(
			       This  : WebBrowserEvents2_Event_Type;
			       pDisp : GNATCOM.Types.VARIANT;
			       URL   : GNATCOM.Types.VARIANT
			      )
   is
      pragma Unreferenced (This, URL);
      pWebControlDisp      : Pointer_To_IDispatch := pDisp.u.pdispVal;
      oWebControlDisp      : Dispinterface_Type;
      oHtmlControl         : IWebBrowser2_Type;
   begin
      Attach(oWebControlDisp, pWebControlDisp);
      Query(oHtmlControl, oWebControlDisp);
      Create(
             g_oHtmlForm,
             IC_Control'Access,
	     oHtmlControl,
	     g_aOnClickEvents'Access
	    );
   end NavigateComplete2;

   procedure DocumentComplete(
			      This  : WebBrowserEvents2_Event_Type;
			      pDisp : GNATCOM.Types.VARIANT;
			      URL   : GNATCOM.Types.VARIANT
			     )
   is
      bServiceInstalled : Boolean := GetConfigInt(
						  "service_settings",
						  "bServiceInstalled",
						  0
						 ) /= 0;
      nSingleIP         : Integer := GetConfigInt(
						  "service_settings",
						  "public_ip_count",
						  0
						 );
      nRangeIP          : Integer := GetConfigInt(
						  "service_settings",
						  "public_range_count",
						  0
						 );
      nSubnetIP         : Integer := GetConfigInt(
						  "service_settings",
						  "public_subnet_count",
						  0
						 );
      nPublicIPv6       : Integer := GetConfigInt(
						  "service_settings",
						  "public_ip6_count",
						  0
						 );
      nSinglePrivateIP  : Integer := GetConfigInt(
						  "service_settings",
						  "private_ip_count",
						  0
						 );
      nRangePrivateIP   : Integer := GetConfigInt(
						  "service_settings",
						  "private_range_count",
						  0
						 );
      nSubnetPrivateIP  : Integer := GetConfigInt(
						  "service_settings",
						  "private_subnet_count",
						  0
						 );
      nPrivateIPv6      : Integer := GetConfigInt(
						  "service_settings",
						  "private_ip6_count",
						  0
						 );
      oElement             : IHTMLElement_Type;
      oPublicTableElement  : IHTMLElement_Type;
      oPrivateTableElement : IHTMLElement_Type;
      oButton              : IHTMLButtonElement_Type;
      oSettingsTable       : IHTMLTable_Type;
      oPublicIPTemplateRow : IHTMLTableRow_Type;
      nRowIndex            : Integer;
      oDispatch            : Dispinterface_Type;
      pDispatch            : Pointer_To_IDispatch;
      oNewRow              : IHTMLTableRow_Type;
      oNewCell             : IHTMLTableCell_Type;
      oElementCollection   : IHTMLElementCollection_Type;
      oStyle               : IHTMLStyle_Type;
      pStyle               : Pointer_To_IHTMLStyle;
      oInputText           : IHTMLInputTextElement_Type;
      sDocTitle            : GString := Get_title(g_oHtmlForm);
   begin
      Text(Main_Window, sDocTitle);
      GetElement(
		 g_oHtmlForm,
		 "setup_button",
		 oElement
		);
      Query(oButton, oElement);
      if bServiceInstalled then
	 g_usSetupImageSRC := To_GString_Unbounded("SETUP_HIDEN.GIF");
	 Put_disabled(oButton, VARIANT_BOOL_TRUE);
	 GetElement(
	     g_oHtmlForm,
	     "restart_button",
	     oElement
	    );
	 Query(oButton, oElement);
	 g_usRestartImageSRC := To_GString_Unbounded("RESTARTHS.PNG");
	 Put_disabled(oButton, VARIANT_BOOL_FALSE);
	 GetElement(
	     g_oHtmlForm,
	     "uninstall_button",
	     oElement
	    );
	 Query(oButton, oElement);
	 g_usUninstallImageSRC := To_GString_Unbounded("UNINSTALL32.PNG");
	 Put_disabled(oButton, VARIANT_BOOL_FALSE);
      else
	 g_usSetupImageSRC := To_GString_Unbounded("SETUP.GIF");
         Put_disabled(oButton, VARIANT_BOOL_FALSE);
	 GetElement(
	     g_oHtmlForm,
	     "restart_button",
	     oElement
	    );
	 Query(oButton, oElement);
	 g_usRestartImageSRC := To_GString_Unbounded("RESTARTHS_GRAY.PNG");
	 Put_disabled(oButton, VARIANT_BOOL_TRUE);
	 GetElement(
	     g_oHtmlForm,
	     "uninstall_button",
	     oElement
	    );
	 Query(oButton, oElement);
	 g_usUninstallImageSRC := To_GString_Unbounded("UNINSTALL32_GRAY.PNG");
	 Put_disabled(oButton, VARIANT_BOOL_TRUE);
         UpdateData(g_oHtmlForm);
      end if;
      UpdateData(g_oHtmlForm);
      GetElement(
		 g_oHtmlForm,
		 "public_settings_table",
		 oPublicTableElement
		);
      Query(oSettingsTable, oPublicTableElement);
      if nSingleIP > 0 then
	 for J in 0 .. nSingleIP - 1 loop
	    GetElement(
		g_oHtmlForm,
		"public_ip_row_template",
		oElement
	       );
	    Query(oPublicIPTemplateRow, oElement);
	    nRowIndex := Integer(Get_rowIndex(oPublicIPTemplateRow));
	    pDispatch := insertRow(oSettingsTable, Interfaces.C.long(nRowIndex));
	    Attach(oDispatch, pDispatch);
	    Query(oNewRow, oDispatch);
	    GetElement(
		g_oHtmlForm,
		"public_ip_description",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oNewCell, oDispatch);
	       Put_align(oNewCell, To_BSTR_From_GString("right"));
	       Put_width(oNewCell, To_VARIANT_From_GString("45%"));
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    GetElement(
		g_oHtmlForm,
		"public_ip_cell",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    pDispatch := Get_children(oElement);
	    Attach(oDispatch, pDispatch);
	    Query(oElementCollection, oDispatch);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("insert_public_ip")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("none")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("delete_public_ip")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("public_ip")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "single_ip" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("test_public_ip_button")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	 end loop;
      end if;
      if nRangeIP > 0 then
	 for J in 0 .. nRangeIP - 1 loop
	    GetElement(
		g_oHtmlForm,
		"public_range_row_template",
		oElement
	       );
	    Query(oPublicIPTemplateRow, oElement);
	    nRowIndex := Integer(Get_rowIndex(oPublicIPTemplateRow));
	    pDispatch := insertRow(oSettingsTable, Interfaces.C.long(nRowIndex));
	    Attach(oDispatch, pDispatch);
	    Query(oNewRow, oDispatch);
	    GetElement(
		g_oHtmlForm,
		"public_range_description",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oNewCell, oDispatch);
	       Put_align(oNewCell, To_BSTR_From_GString("right"));
	       Put_width(oNewCell, To_VARIANT_From_GString("45%"));
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    GetElement(
		g_oHtmlForm,
		"public_range_cell",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    pDispatch := Get_children(oElement);
	    Attach(oDispatch, pDispatch);
	    Query(oElementCollection, oDispatch);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("insert_public_range")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("none")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("delete_public_range")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("range_begin")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "range_begin_ip" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("range_symbol")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("range_end")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "range_end_ip" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("test_public_range_button")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	 end loop;
      end if;
      if nSubnetIP > 0 then
	 for J in 0 .. nSubnetIP - 1 loop
	    GetElement(
		g_oHtmlForm,
		"public_subnet_row_template",
		oElement
	       );
	    Query(oPublicIPTemplateRow, oElement);
	    nRowIndex := Integer(Get_rowIndex(oPublicIPTemplateRow));
	    pDispatch := insertRow(oSettingsTable, Interfaces.C.long(nRowIndex));
	    Attach(oDispatch, pDispatch);
	    Query(oNewRow, oDispatch);
	    GetElement(
		g_oHtmlForm,
		"public_subnet_description",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oNewCell, oDispatch);
	       Put_align(oNewCell, To_BSTR_From_GString("right"));
	       Put_width(oNewCell, To_VARIANT_From_GString("45%"));
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    GetElement(
		g_oHtmlForm,
		"public_subnet_cell",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    pDispatch := Get_children(oElement);
	    Attach(oDispatch, pDispatch);
	    Query(oElementCollection, oDispatch);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("insert_public_subnet")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("none")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("delete_public_subnet")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("subnet_address")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "subnet_address_ip" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("subnet_symbol")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("subnet_mask")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "subnet_mask_ip" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("test_public_subnet_button")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	 end loop;
      end if;
      if nPublicIPv6 > 0 then
	 for J in 0 .. nPublicIPv6 - 1 loop
	    GetElement(
		g_oHtmlForm,
		"public_ip6_row_template",
		oElement
	       );
	    Query(oPublicIPTemplateRow, oElement);
	    nRowIndex := Integer(Get_rowIndex(oPublicIPTemplateRow));
	    pDispatch := insertRow(oSettingsTable, Interfaces.C.long(nRowIndex));
	    Attach(oDispatch, pDispatch);
	    Query(oNewRow, oDispatch);
	    GetElement(
		g_oHtmlForm,
		"public_ip6_description",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oNewCell, oDispatch);
	       Put_align(oNewCell, To_BSTR_From_GString("right"));
	       Put_width(oNewCell, To_VARIANT_From_GString("45%"));
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    GetElement(
		g_oHtmlForm,
		"public_ip6_cell",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    pDispatch := Get_children(oElement);
	    Attach(oDispatch, pDispatch);
	    Query(oElementCollection, oDispatch);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("insert_public_ip6")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("none")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("delete_public_ip6")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("ip6_prefix")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "public_ip6_prefix" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("ip6_symbol")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("prefix_length")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName    : GString := "public_ip6_prefix_length" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       nPrefixLength : Integer := GetConfigInt(
						"service_settings",
						sEntryName,
						0
					       );
	       sPrefixLength : GString := Trim(Image(nPrefixLength), GWindows.GStrings.Constants.Left);
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sPrefixLength));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("test_public_ip6_button")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	 end loop;
      end if;
      GetElement(
		 g_oHtmlForm,
		 "private_settings_table",
		 oPrivateTableElement
		);
      Query(oSettingsTable, oPrivateTableElement);
      if nSinglePrivateIP > 0 then
	 for J in 0 .. nSinglePrivateIP - 1 loop
	    GetElement(
		g_oHtmlForm,
		"private_ip_row_template",
		oElement
	       );
	    Query(oPublicIPTemplateRow, oElement);
	    nRowIndex := Integer(Get_rowIndex(oPublicIPTemplateRow));
	    pDispatch := insertRow(oSettingsTable, Interfaces.C.long(nRowIndex));
	    Attach(oDispatch, pDispatch);
	    Query(oNewRow, oDispatch);
	    GetElement(
		g_oHtmlForm,
		"private_ip_description",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oNewCell, oDispatch);
	       Put_align(oNewCell, To_BSTR_From_GString("right"));
	       Put_width(oNewCell, To_VARIANT_From_GString("45%"));
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    GetElement(
		g_oHtmlForm,
		"private_ip_cell",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    pDispatch := Get_children(oElement);
	    Attach(oDispatch, pDispatch);
	    Query(oElementCollection, oDispatch);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("insert_private_ip")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("none")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("delete_private_ip")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("private_ip")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "private_ip" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("test_private_ip_button")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	 end loop;
      end if;
      if nRangePrivateIP > 0 then
	 for J in 0 .. nRangePrivateIP - 1 loop
	    GetElement(
		g_oHtmlForm,
		"private_range_row_template",
		oElement
	       );
	    Query(oPublicIPTemplateRow, oElement);
	    nRowIndex := Integer(Get_rowIndex(oPublicIPTemplateRow));
	    pDispatch := insertRow(oSettingsTable, Interfaces.C.long(nRowIndex));
	    Attach(oDispatch, pDispatch);
	    Query(oNewRow, oDispatch);
	    GetElement(
		g_oHtmlForm,
		"private_range_description",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oNewCell, oDispatch);
	       Put_align(oNewCell, To_BSTR_From_GString("right"));
	       Put_width(oNewCell, To_VARIANT_From_GString("45%"));
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    GetElement(
		g_oHtmlForm,
		"private_range_cell",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    pDispatch := Get_children(oElement);
	    Attach(oDispatch, pDispatch);
	    Query(oElementCollection, oDispatch);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("insert_private_range")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("none")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("delete_private_range")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("private_range_begin")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "private_range_begin" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("private_range_symbol")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("private_range_end")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "private_range_end" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("test_private_range_button")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	 end loop;
      end if;
      if nSubnetPrivateIP > 0 then
	 for J in 0 .. nSubnetPrivateIP - 1 loop
	    GetElement(
		g_oHtmlForm,
		"private_subnet_row_template",
		oElement
	       );
	    Query(oPublicIPTemplateRow, oElement);
	    nRowIndex := Integer(Get_rowIndex(oPublicIPTemplateRow));
	    pDispatch := insertRow(oSettingsTable, Interfaces.C.long(nRowIndex));
	    Attach(oDispatch, pDispatch);
	    Query(oNewRow, oDispatch);
	    GetElement(
		g_oHtmlForm,
		"private_subnet_description",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oNewCell, oDispatch);
	       Put_align(oNewCell, To_BSTR_From_GString("right"));
	       Put_width(oNewCell, To_VARIANT_From_GString("45%"));
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    GetElement(
		g_oHtmlForm,
		"private_subnet_cell",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    pDispatch := Get_children(oElement);
	    Attach(oDispatch, pDispatch);
	    Query(oElementCollection, oDispatch);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("insert_private_subnet")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("none")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("delete_private_subnet")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("private_subnet_address")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "private_subnet_address" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("private_subnet_symbol")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("private_subnet_mask")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "private_subnet_mask" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("test_private_subnet_button")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	 end loop;
      end if;
      if nPrivateIPv6 > 0 then
	 for J in 0 .. nPrivateIPv6 - 1 loop
	    GetElement(
		g_oHtmlForm,
		"privaite_ip6_row_template",
		oElement
	       );
	    Query(oPublicIPTemplateRow, oElement);
	    nRowIndex := Integer(Get_rowIndex(oPublicIPTemplateRow));
	    pDispatch := insertRow(oSettingsTable, Interfaces.C.long(nRowIndex));
	    Attach(oDispatch, pDispatch);
	    Query(oNewRow, oDispatch);
	    GetElement(
		g_oHtmlForm,
		"privaite_ip6_description",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oNewCell, oDispatch);
	       Put_align(oNewCell, To_BSTR_From_GString("right"));
	       Put_width(oNewCell, To_VARIANT_From_GString("45%"));
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    GetElement(
		g_oHtmlForm,
		"privaite_ip6_cell",
		oElement
	       );
	    declare
	       sCellHTML : GString := GetInnerHTML(oElement);
	    begin
	       pDispatch := insertCell(oNewRow, -1);
	       Attach(oDispatch, pDispatch);
	       Query(oElement, oDispatch);
	       SetInnerHTML(oElement, sCellHTML);
	    end;
	    pDispatch := Get_children(oElement);
	    Attach(oDispatch, pDispatch);
	    Query(oElementCollection, oDispatch);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("insert_privaite_ip6")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("none")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("delete_private_ip6")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("ip6_private_prefix")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName : GString := "private_ip6_prefix" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       sIPAddress : GString := GetConfigString(
						"service_settings",
						sEntryName,
						""
					       );
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sIPAddress));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("ip6_private_symbol")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("prefix_private_length")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    Query(oInputText, oDispatch);
	    declare
	       sEntryName    : GString := "private_ip6_prefix_length" & Trim(Image(J), GWindows.GStrings.Constants.Left);
	       nPrefixLength : Integer := GetConfigInt(
						"service_settings",
						sEntryName,
						0
					       );
	       sPrefixLength : GString := Trim(Image(nPrefixLength), GWindows.GStrings.Constants.Left);
	    begin
	       Put_value(oInputText, To_BSTR_From_GString(sPrefixLength));
	    end;
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	    pDispatch := item(
		       oElementCollection,
		       To_VARIANT_From_GString("test_private_ip6_button")
		      );
	    Attach(oDispatch, pDispatch);
	    Query(oElement, oDispatch);
	    pStyle := Get_style(oElement);
	    Attach(oStyle, pStyle);
	    Put_display(
		 oStyle,
		 To_BSTR_From_GString("inline")
		);
	 end loop;
      end if;
   end DocumentComplete;

   function ShowContextMenu(
			    This           : DocHostUIHandler_Object_Type;
			    dwID           : DWORD;
			    ppt            : access Point_Type;
			    pcmdtReserved  : access IUnknown;
			    pdispReserved  : access IDispatch
			   ) return HRESULT
   is
   begin
      if dwID = CONTEXT_MENU_CONTROL then
	 return S_FALSE;
      end if;
      return S_OK;
   end ShowContextMenu;

   function GetHostInfo(
			This           : DocHostUIHandler_Object_Type;
			pInfo          : access DOCHOSTUIINFO
		       ) return HRESULT
   is
   begin
      pInfo.all.dwFlags := DOCHOSTUIFLAG_NO3DBORDER or DOCHOSTUIFLAG_DIALOG;
      return S_OK;
   end GetHostInfo;


   function g_fNewQueryInterface(
				 This   : access IOleClientSite;
				 riid   : Pointer_To_GUID;
				 ppvObj : Pointer_To_Pointer_To_Void
				) return HRESULT
   is
   begin
      if riid.all = IID_IDocHostUIHandler then
	 ppvObj.all := Address(g_oDocHostUIHandler);
	 return S_OK;
      end if;
      return g_fOldQueryInterface(
				  This,
				  riid,
				  ppvObj
				 );
   end g_fNewQueryInterface;

   procedure UpdateData(
			This       : in out DHtmlForm_type;
			bReadOp    : Boolean := False
		       )
   is
   begin
      DDX_DHtml_ElementInnerHtml(
				 This,
				 "version_descript",
				 g_usVersionHTMLString,
				 bReadOp
				);
      DDX_DHtml_ElementInnerHtml(
				 This,
				 "version_str",
				 g_usVersionHTMLString,
				 bReadOp
				);
      DDX_DHtml_ElementInnerText(
				 This,
				 "cr_dates",
				 g_usCopyRightDates,
				 bReadOp
				);
      DDX_DHtml_ElementInnerText(
				 This,
				 "status_text",
				 g_usStatusStr,
				 bReadOp
				);
      DDX_DHtml_InputValue(
			   This,
			   "dns_zone_name",
			   g_usDomainZoneName,
			   bReadOp
			  );
      DDX_DHtml_Img_Src(
			This,
			"setup_image",
			g_usSetupImageSRC,
			bReadOp
		       );
      DDX_DHtml_Img_Src(
			This,
			"uninstall_image",
			g_usUninstallImageSRC,
			bReadOp
		       );
      DDX_DHtml_Img_Src(
			This,
			"restart_image",
			g_usRestartImageSRC,
			bReadOp
		       );
   end UpdateData;

   procedure OnExitClick(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      Close(Main_Window);
   end OnExitClick;

   procedure DoAboutBox(oEventObj : in out IHTMLEventObj_Type)
   is
      nResult : Integer;
   begin
      Show_AboutBox(
		    Main_Window,
		    nResult
		   );
   end DoAboutBox;

   procedure OnSetupClick(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end OnSetupClick;

   procedure TestDnsZoneName(oEventObj : in out IHTMLEventObj_Type)
   is
      oDomainZoneName         : IHTMLElement_Type;
      oDomainZoneNameElement2 : IHTMLElement2_Type;
      nDialogRet              : Integer;
   begin
      UpdateData(g_oHtmlForm, True);
      GetElement(
		 g_oHtmlForm,
		 "dns_zone_name",
		 oDomainZoneName
		);
      Query(oDomainZoneNameElement2, oDomainZoneName);
      if g_usDomainZoneName = Null_GString_Unbounded then
	 g_usMessageTypeImageSRC := To_GString_Unbounded("ERROR_ICON.PNG");
	 g_usMessageText := To_GString_Unbounded(
					  "Нечего проверять!" & CR & LF
					    & "Заполните поле имени DNS-зоны."
					 );
	 Show_RTSDDMessageBox(Main_Window, nDialogRet);
	 focus(oDomainZoneNameElement2);
	 return;
      end if;
      declare
	 sDomainZoneName : GString := To_GString_From_Unbounded(g_usDomainZoneName);
	 nZoneLast       : Integer := sDomainZoneName'Last;
      begin
	 if sDomainZoneName(nZoneLast) /= '.' then
	    g_usDomainZoneName := To_GString_Unbounded(sDomainZoneName & '.');
	    UpdateData(g_oHtmlForm);
	 end if;
      end;
   end TestDnsZoneName;

   procedure TestPublicIP(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end TestPublicIP;

   procedure TestPrivateIP(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end TestPrivateIP;

   procedure TestPublicRange(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end TestPublicRange;

   procedure TestPrivateRange(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end TestPrivateRange;

   procedure TestPublicSubnet(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end TestPublicSubnet;

   procedure TestPrivateSubnet(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end TestPrivateSubnet;

   procedure TestPublicIPv6(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end TestPublicIPv6;

   procedure TestPrivateIPv6(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end TestPrivateIPv6;

   procedure SaveParameters(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end SaveParameters;

   procedure ReloadParameters(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end ReloadParameters;

   procedure OnUninstallClick(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end OnUninstallClick;

   procedure OnRestartClick(oEventObj : in out IHTMLEventObj_Type)
   is
   begin
      null;
   end OnRestartClick;

end PublicDNSPluginConfig;
