//Begin recording. Opens a new browser window and connects to browser events.
		public void Record(ContextMenuStrip cmsMenu)
		{
			this.InitializeContextMenu(cmsMenu);
			_writer = new SWATWikiGenerator();
			_writer.Initialize(BrowserType.InternetExplorer, true);
			_recording = true;
			_inetExplorer = new WebBrowserEvents("NewWindow", null, ref _writer);
			RecordJScriptBoxSetup();
		}
		public void Record(ContextMenuStrip cmsMenu, ArrayList browserNames, ArrayList indexes, System.Windows.Forms.CheckedListBox.CheckedIndexCollection checkedIndices)
		{
			this.InitializeContextMenu(cmsMenu);
			_writer = new SWATWikiGenerator();
			_writer.Initialize(BrowserType.InternetExplorer, false);
			_recording = true;

			RecordJScriptBoxSetup();

			foreach (int a in checkedIndices)
			{
				string titleContents = (String)browserNames[a];
				int _index = (int)indexes[a];
				int indexCount = 0;
				ShellWindows m_IEFoundBrowsers = new ShellWindowsClass();
				foreach (InternetExplorer Browser in m_IEFoundBrowsers)
				{
                    try
                    {
                        if (Browser.LocationName != "" && Browser.Document is mshtml.HTMLDocument)
                        {
                            if ((((mshtml.HTMLDocument)Browser.Document).title).Equals(titleContents))
                            {
                                if (indexCount == _index)
                                {
                                    _inetExplorer = new WebBrowserEvents("AttachToWindow", Browser, ref _writer);
                                    break;
                                }
                                else
                                    indexCount++;
                            }
                        }
                    }
                    catch (System.Runtime.InteropServices.COMException) { continue; }
				}
			}
		}
		public void JScriptPump()
		{
			while (_recording)
			{
				// polling time checking for JS box in ms
				Thread.Sleep(230);
				//Console.WriteLine("Thread Pump running...");

				// JScriptWindow Polling
				if (!JScriptWindowFound)
				{
					dialogHwnd = FindWindowByCaption(32770, "Microsoft Internet Explorer");
					if (dialogHwnd == IntPtr.Zero) {
						dialogHwnd = FindWindowByCaption(32770, "Windows Internet Explorer");
					} 

					// case the JavaScript window has been found. We need to attach a listener to it
					if (dialogHwnd != IntPtr.Zero)
					{
						Console.WriteLine("Window Found...");
						JScriptWindowFound = true;
						dialogHWnd_buttonOK = FindWindowEx(dialogHwnd, IntPtr.Zero, "Button", "OK");
						dialogHWnd_buttonCancel = FindWindowEx(dialogHwnd, IntPtr.Zero, "Button", "Cancel");
					}
				}

				// WARNING: TODO: create its own thread pump:Modal Window Polling
				modalWindowHwnd = GetForegroundWindow();
				if ((int)GetWindowText(modalWindowHwnd, Buff, nChars) > 0)
				{
					if (Buff.ToString().Contains("-- Webpage Dialog") && (!modalWindowFound))
					{
						Console.WriteLine("Modal Window Found: " + Buff.ToString());
						_writer.AttachBrowser(Buff.ToString(), 0);
						modalWindowFound = true;

						//_browser.AttachToWindow(Buff.ToString(), 0);
						//_inetExplorer = new WebBrowserEvents("PopUp", null, ref _writer);


						ShellWindows m_IEFoundBrowsers = new ShellWindowsClass();
						foreach (IWebBrowser2 Browser in m_IEFoundBrowsers)
						{

							if (Browser.Document is mshtml.HTMLDocument)
							{
								Console.WriteLine("found IE window: " + ((mshtml.HTMLDocument)Browser.Document).uniqueID + ", " + ((mshtml.HTMLDocument)Browser.Document).referrer + ", " + ((mshtml.HTMLDocument)Browser.Document).protocol);
								//if ((((mshtml.HTMLDocument)Browser.Document).title).Contains("-- Webpage Dialog"))
								if ((((mshtml.HTMLDocument)Browser.Document).title).Contains(""))
								{
									Console.WriteLine("Attempt to attach to modal window");
									_inetExplorer = new WebBrowserEvents("AttachToModalWindow", (InternetExplorer)Browser, ref _writer);
									//Console.WriteLine("doc: " + ((mshtml.HTMLDocument)Browser.Document).body.style.backgroundColor.ToString());
									break;
								}
							}
						}
					}
				}
			}
		}