public TextEditorDemo()
        {
            Control.AttachToDocument();

            var text = new TextEditor(Control);

            text.InnerHTML = "<p>jsc:javascript <b>TextEditor</b></p>";

            text.IsFadeEnabled = false;

            var cookie = new Cookie("TextData");



            var save = new IHTMLButton("save to cookie");
            var load = new IHTMLButton("load from cookie");

            save.onclick += delegate { cookie.Value = text.InnerHTML; };
            load.onclick += delegate { text.InnerHTML = cookie.Value; };

            this.Control.appendChild(save, load);
        }
        public ConvertASToCS()
        {
            Native.Document.title = "ConvertASToCS";

            Native.Document.body.style.padding = "0";
            Native.Document.body.style.margin = "0";


            var cookie = new Cookie("DeclaringType").BindTo(DeclaringType);

            #region Title
            var MyTitleText = new IHTMLDiv("This tool allows you to copy various parts of flash doc html file in and generate C# headers.");
            MyTitleText.style.paddingTop = "12px";
            MyTitleText.style.paddingLeft = "15px";
            MyTitleText.style.fontFamily = IStyle.FontFamilyEnum.Tahoma;
            MyTitleText.style.fontSize = "13px";


            var MyTitle = new IHTMLDiv(MyTitleText);
            MyTitle.style.background = "url(" + Assets.Path + "titleTableTop.jpg) repeat-x";
            MyTitle.style.height = "44px";
            MyTitle.AttachToDocument();

            var MyTitleMiddleTextFloat = new IHTMLDiv();

            MyTitleMiddleTextFloat.style.paddingTop = "3px";
            MyTitleMiddleTextFloat.style.Float = IStyle.FloatEnum.right;

            var MyTitleMiddleText = new IHTMLDiv(new IHTMLLabel("DeclaringType: ", DeclaringType), DeclaringType);
            MyTitleMiddleText.style.paddingTop = "3px";
            MyTitleMiddleText.style.paddingLeft = "15px";
            MyTitleMiddleText.style.fontFamily = IStyle.FontFamilyEnum.Tahoma;
            MyTitleMiddleText.style.fontSize = "20px";



            var MyTitleMiddle = new IHTMLDiv(MyTitleMiddleTextFloat, MyTitleMiddleText);
            MyTitleMiddle.style.background = "url(" + Assets.Path + "titleTableMiddle.jpg) repeat-x";
            MyTitleMiddle.style.height = "31px";
            MyTitleMiddle.AttachToDocument();

            var MyTitleShadow = new IHTMLDiv("");
            MyTitleShadow.style.background = "url(" + Assets.Path + "titleTableBottom.jpg) repeat-x";
            MyTitleShadow.style.height = "5px";
            MyTitleShadow.AttachToDocument();
            #endregion



            DocumentBody = new IHTMLDiv().AttachToDocument();
            DocumentBody.style.padding = "1em";
            DocumentBody.style.backgroundImage = "url(assets/ConvertASToCS/flash_logo.png)";
            DocumentBody.style.backgroundPosition = "right top";
            DocumentBody.style.backgroundRepeat = "no-repeat";


            a = new IHTMLTextArea().AttachTo(DocumentBody);
            a.style.backgroundColor = Color.Transparent;
            a.style.border = "1px solid gray";


            Func<IHTMLImage, string, IHTMLAnchor> CreateButton =
                (img, text) =>
                {
                    img.style.border = "0px";

                    var htext = new IHTMLAnchor("#", img, new IHTMLSpan(text)).AttachTo(MyTitleMiddleTextFloat);

                    htext.onclick += e => e.PreventDefault();
                    htext.style.margin = "1em";

                    return htext;
                };


            AddEvents(CreateButton((Assets.Path + "ak590dyt.pubevent(en-US,VS.80).gif"), "Events"));
            AddConstants(CreateButton((Assets.Path + "ak590dyt.pubproperty(en-US,VS.80).gif"), "Constants"));
            AddProperties(CreateButton((Assets.Path + "ak590dyt.pubproperty(en-US,VS.80).gif"), "Properties"));
            AddMethods(CreateButton((Assets.Path + "deshae98.pubmethod(en-us,VS.90).gif"), "Methods"));
            AddAny(CreateButton((Assets.Path + "deshae98.pubmethod(en-us,VS.90).gif"), "Any"));
            AddProxy(CreateButton((Assets.Path + "deshae98.pubmethod(en-us,VS.90).gif"), "Proxy"));
        }
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            var f = new ConsoleForm();

            f.InitializeConsoleFormWriter();
            f.Show();

            // shard across browsers in the same session?
            var session = new Cookie("session").DefaultToRandomInt32();
            //Native.Window.localStorage

            var random = new Cookie("random").DefaultToRandomInt32();


            Console.WriteLine("\n Console has been redirected!");
            Console.WriteLine("\n " + new { session = session.IntegerValue.ToString("x8") });

            #region WaitInHandler
            page.WaitInHandler.onclick +=
                delegate
                {
                    page.WaitInHandler.disabled = true;
                    new IXMLHttpRequest(
                        url: "/wait",
                        handler: r =>
                            {
                                page.WaitInHandler.disabled = false;

                            }
                    );
                };
            #endregion

            page.CheckDatabase.onclick +=
                delegate
                {
                    service.CheckDatabase("",
                        Console.WriteLine
                    );

                };

            #region CheckServerForSession
            page.CheckServerForSession.onclick +=
                delegate
                {
                    page.CheckServerForSession.disabled = true;

                    service.CheckServerForSession("" + session.IntegerValue,
                        x =>
                        {
                            Console.WriteLine(x);
                            page.CheckServerForSession.disabled = false;
                        }
                    );
                };
            #endregion

            page.DoLongOperation.onclick +=
                delegate
                {
                    page.DoLongOperation.disabled = true;

                    // can we send IEvent as argument directly?
                    // can we set a field on client side and have
                    // it updated on each call?
                    service.DoLongOperation("" + session.IntegerValue,
                        delegate
                        {
                            page.DoLongOperation.disabled = false;

                        }
                    );
                };

            #region UseCurrentIdToGetOutput
            page.UseCurrentIdToGetOutput.disabled = true;

            // enable while clickonce is active
            page.GetCurrentIdToStartListening.onclick +=
                delegate
                {
                    page.GetCurrentIdToStartListening.disabled = true;

                    service.SelectTransactionKey(
                        "" + session.IntegerValue,
                        id =>
                        {
                            Console.WriteLine(new { id });
                            page.UseCurrentIdToGetOutput.disabled = false;

                            page.UseCurrentIdToGetOutput.onclick +=
                                delegate
                                {
                                    page.UseCurrentIdToGetOutput.disabled = true;



                                    service.SelectContentUpdates(
                                        "" + session.IntegerValue,
                                        id,
                                        y: Console.Write,
                                        ynextid: nextid =>
                                        {
                                            id = nextid;

                                            Console.WriteLine(new { id });
                                            page.UseCurrentIdToGetOutput.disabled = false;
                                        }
                                    );

                                };
                        }
                     );

                };
            #endregion


            #region StartServerSentEvents
            page.StopServerSentEvents.disabled = true;

            page.StartServerSentEvents.onclick +=
                delegate
                {
                    page.StartServerSentEvents.disabled = true;



                    page.StopServerSentEvents.disabled = false;

                    //var n = new XElement("e",
                    //      new XAttribute("session", "" + session.IntegerValue)
                    //);

                    //var q = new StringBuilder();

                    //q.Append("/xml");
                    ////q.Append("?");

                    ////q.Append("e=" + n.ToString());


                    // Web Console(12961): Uncaught ReferenceError: EventSource is not defined at http://192.168.1.100:14690/view-source:46617
                    var s = new EventSource("/stream");

                    s["SystemConsoleOut"] =
                        e =>
                        {
                            //Console.WriteLine(new { SystemConsoleOut = new { e.lastEventId, e.data } });
                            Console.Write(((string)e.data)
                                .Replace("\\n", "\n")
                                .Replace("\\r", "\r")
                                );
                        };

                    s.onerror +=
                       e =>
                       {

                           //Console.WriteLine(new { onerror = new { s.readyState } });

                           if (s.readyState == 2)
                           {
                               // why are we getting that error??

                               s = null;

                               page.StartServerSentEvents.disabled = false;
                               page.StopServerSentEvents.disabled = true;
                           }
                       };

                    page.StopServerSentEvents.onclick +=
                        delegate
                        {
                            if (s == null)
                                return;

                            s.close();
                            s = null;

                            page.StartServerSentEvents.disabled = false;
                            page.StopServerSentEvents.disabled = true;

                        };

                };
            #endregion


            page.ChangeSessionTo.innerText = "session " + session.IntegerValue.ToString("x8");
        }