//bool putJavaScriptCodeViewerOnTheLeft,
		public ascx_Javascript_AST buildGui( bool addUrlLoadTextBox)
		{
			var mainGui = this.add_1x1("Files or ScriptBlocks","Javascript Source (you can edit this code and see the results in realtime)");
			var splitContainer = this.controls<SplitContainer>();
			if (addUrlLoadTextBox)			
			{
				showJavascriptsFromUrl = 
				splitContainer.insert_Above<Panel>(25)
							  .add_LabelAndComboBoxAndButton("Enter Url to load Javascripts","","Open",  loadJavascriptsFromUrl)
							  .controls<ComboBox>();								  
			}
			/*if (putJavaScriptCodeViewerOnTheLeft)
			{				
				splitContainer.splitterDistance(this.width()/3);
				javascriptCode = mainGui[1].add_TreeView().showSelection().sort();
				sourceCode = mainGui[0].add_SourceCodeViewer(); 				
			}
			else			
			{*/
				javascriptCode = mainGui[0].add_TreeView().showSelection().sort();
				sourceCode = mainGui[1].add_SourceCodeViewer(); 
			//}
			pagesVisited = javascriptCode.insert_Above<ComboBox>(25).dropDownList();
			
			codeSnippet = sourceCode.insert_Below<TextBox>(100).multiLine().scrollBars(); 
			tabControl  = javascriptCode.insert_Below<TabControl>();
			
			jsAST = tabControl.add_Tab("Javascript - View Ast Tree")
								  .add_TreeView()
								  .showSelection();
								  
			jsFunctions = tabControl.add_Tab("JScript: Functions")
								  		.add_TreeView()
								  		.showSelection()
								  		.sort();
			
			jsIdentifiers = tabControl.add_Tab("JScript: Identifiers")
								  		  .add_TreeView()
								  		  .showSelection()
								  		  .sort();

			jsValues = tabControl.add_Tab("JScript: Values")
								  	 .add_TreeView()
								  	 .showSelection()
								  	 .sort();
								  		
			
			allAST = tabControl.add_Tab("Javascript - View Ast Elements")					    
								   .add_TreeView()
								   .showSelection()
								   .sort();
			
			var searchTab = tabControl.add_Tab("Search in Code")
									  .add_LabelAndComboBoxAndButton("search for (case sensitive)","","show",
									  	(text)=> {
									  				sourceCode.editor().invoke("searchForTextInTextEditor_findNext", text);
									  			 });
									  					  
			//tabControl.select_Tab(searchTab);
			javaScriptLoadMessage = javascriptCode.insert_Below<Panel>(20);
													  
			allAST.insert_Below<Panel>(25)
				  .add_CheckBox("Render this view (some performace impact on large scripts)", 0,0, 
				  		(value)=>{
				  					RenderViewAstElementsTreeView = value;
				  					processJavascript();
				  				 })
				  .autoSize(); 
				  
				  
			allAST.jint_configure_showSelectionDetails(sourceCode, codeSnippet); 
			jsFunctions.jint_configure_showSelectionDetails(sourceCode, codeSnippet); 
			jsIdentifiers.jint_configure_showSelectionDetails(sourceCode, codeSnippet); 
			jsValues.jint_configure_showSelectionDetails(sourceCode, codeSnippet); 

			javascriptCode.afterSelect<string>(
				(jsCode) => {
								sourceCode.editor().clearBookmarksAndMarkers();
								sourceCode.set_Text(jsCode,"*.js");
								sourceCode.editor().refresh(); 
							});
			
			sourceCode.onTextChanged(processJavascript);
			
			pagesVisited.onSelection<IE_HtmlPage>(
				(htmlPage)=>{
								var allScriptsCompiledOk = javascriptCode.populateWithHtmlPageScripts(htmlPage);
								javascriptCode.add_Node("zzz [Original Html Code for: {0}]".format(htmlPage.PageUri.str()),htmlPage.PageSource);
								handleCompilationResult(allScriptsCompiledOk);								
							});
							
			pagesVisited.onSelection<Jint_Wrapper>(
				(jintWrapper)=>{									
									var allScriptsCompiledOk = javascriptCode.populateWithHtmlPageScripts(jintWrapper.JavaScripts);
									javascriptCode.add_Node("zzz_[Original Code for: {0}]".format(jintWrapper.Uri.str()),jintWrapper.Html);
									handleCompilationResult(allScriptsCompiledOk);
							   });
			
			javascriptCode.onDrop(
				(fileOrFolder)=>{
									if (fileOrFolder.fileExists()) 
										javascriptCode.add_Node(fileOrFolder.str(), fileOrFolder.fileContents());
									else if (fileOrFolder.dirExists()) 
									{
										javascriptCode.clear();
										foreach(var file in fileOrFolder.files("*.js",true))
											javascriptCode.add_Node(file.str(), file.fileContents()); 
									}
								});


			this.add_ContextMenu().add_MenuItem("Show log viewer",()=> this.insert_Below<Panel>(90).add_LogViewer());
			
			return this;

		}
        public void buildGui()
        {
            try
            {
                var topPanel = this.add_Panel();
                //serializedString = topPanel.insert_Right(200).add_GroupBox("Serialized Object").add_SourceCodeViewer();
                //var serializedStringPanel = serializedString.splitContainer().panel2Collapsed(true);
                propertyGrid = topPanel.add_GroupBox("").add_PropertyGrid().helpVisible(false);
                treeView = propertyGrid.parent().insert_Left<Panel>().add_TreeView().sort();
                //treeView.splitterDistance(300);
                var toStringValue = propertyGrid.parent().insert_Below<Panel>(100).add_GroupBox("ToString Value (not editable):").add_TextArea();
                var optionsPanel = treeView.insert_Below<Panel>(70);
                var objectName = toStringValue.parent().insert_Above<Panel>(20).add_TextBox("name", "");
                //propertyGrid.onValueChange(updateSerializedString);

                //setSerializedStringSyncWithPropertyGrid();

                //serializedString.insert_Above(20).add_Link("Sync Serialized String With PropertyGrid", 0, 0, () => updateSerializedStringSyncWithPropertyGrid());

                LinkLabel invokeLink = null;
                invokeLink = optionsPanel.add_CheckBox("Show Methods", 0, 0,
                                (value) =>
                                {
                                    ShowMethods = value;
                                    invokeLink.enabled(value);
                                    refresh();
                                })
                                         .append_Link("invoke", invokeSelectedMethod)
                                            .leftAdd(-16).topAdd(5).bringToFront()
                                            .enabled(false);

                optionsPanel.add_CheckBox("Show Property and Field info", 22, 0,
                    (value) =>
                    {
                        ShowPropertyAndFieldInfo = value;
                        refresh();
                    })
                            .autoSize()
                            .append_Link("refresh", () => refresh())
                            .left(200);
                optionsPanel.add_CheckBox("Sort Values", 0, 135,
                    (value) =>
                    {
                        Sorted = value;
                        try
                        {
                            treeView.sort(Sorted);  // throwing "Unable to cast object of type 'System.Boolean' to type 'System.Windows.Forms.TreeView'"
                        }
                        catch//(Exception ex)
                        {
                            //ex.log();
                        }
                    }).@checked(true);

                simpleView_CheckBox = optionsPanel.add_CheckBox("Simple View", 0, 220,
                    (value) =>
                    {
                        SimpleView = value;
                        //propertyGrid.splitContainer().panel1Collapsed(value);
                        refresh();
                    })
                            .bringToFront();

                /*showSerializedString_CheckBox = optionsPanel.add_CheckBox("Show serialized string", 44, 0,
                    (value) =>
                    {
                        ShowSerializedString = value;
                        serializedStringPanel.panel2Collapsed(!value);
                        refresh();
                    })
                             .autoSize();*/

                createObjectWhenNull_CheckBox = optionsPanel.add_CheckBox("Create Object When Null", 44, 150,
                    (value) =>
                    {
                        CreateObjectWhenNull = value;
                    })
                            .bringToFront()
                            .autoSize();

                treeView.afterSelect<object>(
                    (selectedObject) =>
                    {
                        var treeNode = treeView.selected();
                        objectName.set_Text(treeNode.get_Text());
                        var tag = WinForms_ExtensionMethods_TreeView.get_Tag(treeNode);
                        if (tag.notNull())// && tag.str() != treeNode.get_Text())
                        {
                            propertyGrid.show(selectedObject);
                            var toString = selectedObject.str();
                            if (toString == "System.__ComObject")
                                toString += " : {0}".format(selectedObject.comObject_TypeName());
                            toStringValue.set_Text(toString);

                            propertyGrid.parent().set_Text(selectedObject.typeFullName());
                            if (treeNode.nodes().size() == 0)
                            {
                                addObjectPropertyAndFields(treeNode, selectedObject);
                            }
                        }
                        else if (treeNode.nodes().size() == 0)
                        {
                            propertyGrid.show(null as object);
                            propertyGrid.parent().set_Text("[null value]");
                            toStringValue.set_Text("[null value]");
                            objectName.set_Text("");
                            treeNode.color(Color.Red);
                        }

                    });
                treeView.add_ContextMenu().add_MenuItem("Invoke Method", () => invokeSelectedMethod());
            }
            catch (Exception ex)
            {
                ex.log("in buildGui", true);
            }
            guiReady = true;
        }