diff --git a/Nasal/gui.nas b/Nasal/gui.nas
index 292f873c6..1eea0ec95 100644
--- a/Nasal/gui.nas
+++ b/Nasal/gui.nas
@@ -89,11 +89,31 @@ var setCursor = func(x = nil, y = nil, cursor = nil) {
     fgcommand("set-cursor", args);
     return args.getNode("cursor").getValue();
 }
+
+##
+# Supported mouse cursor types.
+#
 var cursor_types = { none: 0, pointer: 1, wait: 2, crosshair: 3, leftright: 4,
     topside: 5, bottomside: 6, leftside: 7, rightside: 8,
     topleft: 9, topright: 10, bottomleft: 11, bottomright: 12,
 };
 
+##
+# Find a GUI element by given name.
+# dialog: dialog root property.
+# name: name of GUI element to be searched.
+# Returns GUI element when found, nil otherwise.
+#
+var findElementByName = func(dialog,name) {
+	foreach( var child; dialog.getChildren() ) {
+		var n = child.getNode( "name" );
+		if( n != nil and n.getValue() == name )
+			return child;
+		var f = findElementByName(child, name);
+		if( f != nil ) return f;
+	}
+	return nil;
+};
 
 
 ########################################################################
diff --git a/gui/dialogs/replay.xml b/gui/dialogs/replay.xml
index d584a4c83..dfb41342a 100644
--- a/gui/dialogs/replay.xml
+++ b/gui/dialogs/replay.xml
@@ -26,7 +26,7 @@
 
 			# Populate the view combo box with a list of the available views
 			initViews : func(update) {
-				var combo = me.findElementByName( me.dlgRoot, "view-selector" );
+				var combo = gui.findElementByName( me.dlgRoot, "view-selector" );
 				if (update)
 					combo.removeChildren("value");
 
@@ -35,21 +35,21 @@
 				foreach (var v; view.views) {
 					var name = "Unnamed view " ~ v.getIndex();
 					if (v.getNode("name") != nil) {
-					  name = v.getNode("name").getValue();
+						name = v.getNode("name").getValue();
 					}
 
 					# Pre-populate the combo box selected value
 					if (i == current_view) {
-					  setprop("/sim/replay/view-name", name);
+						setprop("/sim/replay/view-name", name);
 					}
 					if (update)
 						combo.getNode("value[" ~ i ~ "]", 1).setValue(name);
-					i = i + 1;
+					i += 1;
 				}
 			},
 
 			open : func {
-				var replaySlider = me.findElementByName( me.dlgRoot, "replay-time-slider" );
+				var replaySlider = gui.findElementByName( me.dlgRoot, "replay-time-slider" );
 				me.maxProp = replaySlider.getChild("max");
 				me.minProp = replaySlider.getChild("min");
 				me.speedUpListenerId = setlistener( "/sim/speed-up", func(n) { me.updateListener(n); }, 1, 1 );
@@ -72,24 +72,13 @@
 				}
 				setprop("/sim/gui/dialogs/replay/time-factor","" ~ SpeedUp ~ "x");
 				me.initViews(0);
-		    },
+			},
 
 			close : func {
 				removelistener( me.speedUpListenerId );
 				removelistener( me.viewListenerId );
 			},
 
-		    findElementByName : func(base,name) {
-		      foreach( var child; base.getChildren() ) {
-		        var n = child.getNode( "name" );
-		        if( n != nil and n.getValue() == name )
-		          return child;
-		        var f = me.findElementByName(child,name);
-		        if( f != nil ) return f;
-		      }
-		      return nil;
-		    },
-
 		};
 
 		var controller = ReplayDialogController.new( cmdarg() );
@@ -147,7 +136,7 @@
 				<object-name>replay-looped</object-name>
 			</binding>
 		</checkbox>
-        <input>
+		<input>
 			<name>replay-duration</name>
 			<pref-width>40</pref-width>
 			<color>
@@ -161,7 +150,7 @@
 				<command>dialog-apply</command>
 				<object-name>replay-duration</object-name>
 			</binding>
-        </input>
+		</input>
 
 		<empty><pref-width>40</pref-width></empty>
 
@@ -214,8 +203,8 @@
 				<alpha type="float">0.8</alpha>
 			</color>
 			<binding>
-			  <command>nasal</command>
-			  <script>controls.speedup(-1);</script>
+				<command>nasal</command>
+				<script>controls.speedup(-1);</script>
 			</binding>
 		</button>
 		<text>
@@ -242,12 +231,12 @@
 				<alpha type="float">0.8</alpha>
 			</color>
 			<binding>
-			  <command>nasal</command>
-			  <script>controls.speedup(1);</script>
+				<command>nasal</command>
+				<script>controls.speedup(1);</script>
 			</binding>
 		</button>
 
-        <empty><stretch>1</stretch></empty>
+		<empty><stretch>1</stretch></empty>
 
 		<button>
 			<legend>Hide</legend>
@@ -260,10 +249,10 @@
 			</color>
 			<pref-width>40</pref-width>
 			<binding>
-			  <command>nasal</command>
-			  <script><![CDATA[
+				<command>nasal</command>
+				<script><![CDATA[
 				setprop("/sim/messages/copilot", "Replay active. 'Esc' to stop. 'Ctrl-R' to show replay controls.");
-			  ]]></script>
+				]]></script>
 			</binding>
 			<binding>
 				<command>dialog-close</command>
@@ -286,8 +275,8 @@
 				<alpha type="float">0.8</alpha>
 			</color>
 			<binding>
-			  <command>nasal</command>
-			  <script>controls.replaySkip(-30);</script>
+				<command>nasal</command>
+				<script>controls.replaySkip(-30);</script>
 			</binding>
 		</button>
 
@@ -302,8 +291,8 @@
 				<alpha type="float">0.8</alpha>
 			</color>
 			<binding>
-			  <command>nasal</command>
-			  <script>controls.replaySkip(-5);</script>
+				<command>nasal</command>
+				<script>controls.replaySkip(-5);</script>
 			</binding>
 		</button>
 
@@ -335,7 +324,7 @@
 			<min>0</min><!-- property is updated on "dialog open" -->
 			<max>1.0</max><!-- property is updated on "dialog open" -->
 			<property>/sim/replay/time</property>
-			<live>true</live>				
+			<live>true</live>
 			<binding>
 				<command>dialog-apply</command>
 				<object-name>replay-time-slider</object-name>
@@ -367,8 +356,8 @@
 				<alpha type="float">0.8</alpha>
 			</color>
 			<binding>
-			  <command>nasal</command>
-			  <script>controls.replaySkip(5);</script>
+				<command>nasal</command>
+				<script>controls.replaySkip(5);</script>
 			</binding>
 		</button>
 
diff --git a/gui/dialogs/scenario.xml b/gui/dialogs/scenario.xml
index 7a238328d..dc2749ff3 100644
--- a/gui/dialogs/scenario.xml
+++ b/gui/dialogs/scenario.xml
@@ -108,17 +108,6 @@
     <open><![CDATA[
       var dlg_root = cmdarg();
 
-      var findElementByName = func(rootN, name) {
-        foreach( var child; rootN.getChildren() ) {
-          var n = child.getNode( "name" );
-          if( n != nil and n.getValue() == name )
-            return child;
-          var f = findElementByName(child,name);
-          if( f != nil ) return f;
-        }
-        return nil;
-      };
-
       var isEnabledScenario = func(scenario) {
         foreach( var n; props.globals.getNode("sim/ai",1).getChildren("scenario") )
           if( n.getValue() == scenario )
@@ -138,7 +127,7 @@
         propertyRoot.getNode("selected",1).setBoolValue(isEnabledScenario(file));
         propertyRoot.getNode("name",1).setValue(file);
 
-        var group = findElementByName( dlg_root, columns[math.mod(nr,2)] ).getChild("group", nr, 1 );
+        var group = gui.findElementByName( dlg_root, columns[math.mod(nr,2)] ).getChild("group", nr, 1 );
         group.getNode("layout",1).setValue("hbox");
         var cb = group.getNode("checkbox",1);
         cb.getNode("property",1).setValue(propertyRoot.getNode("selected").getPath());
diff --git a/gui/dialogs/sound.xml b/gui/dialogs/sound.xml
index f85e403a8..671e0c731 100644
--- a/gui/dialogs/sound.xml
+++ b/gui/dialogs/sound.xml
@@ -329,19 +329,8 @@
     <open><![CDATA[
       var dlg_root = cmdarg();
 
-      var findElementByName = func(rootN, name) {
-        foreach( var child; rootN.getChildren() ) {
-          var n = child.getNode( "name" );
-          if( n != nil and n.getValue() == name )
-            return child;
-          var f = findElementByName(child,name);
-          if( f != nil ) return f;
-        }
-        return nil;
-      };
-
       # Fill the sound device combo box
-      var combo = findElementByName( dlg_root, "source-selection" );
+      var combo = gui.findElementByName( dlg_root, "source-selection" );
       var wsn = props.globals.getNode( "sim/sound/devices" );
       if( wsn != nil ) {
         var devices = wsn.getChildren("device");
diff --git a/gui/dialogs/weather.xml b/gui/dialogs/weather.xml
index 908ab6f4c..81155653f 100644
--- a/gui/dialogs/weather.xml
+++ b/gui/dialogs/weather.xml
@@ -1961,7 +1961,7 @@
 
 
           # fill the METAR source combo box
-          var combo = me.findElementByName( me.dlgRoot, "source-selection" );
+          var combo = gui.findElementByName( me.dlgRoot, "source-selection" );
           var wsn = props.globals.getNode( "/environment/weather-scenarios" );
           if( wsn != nil ) {
             var scenarios = wsn.getChildren("scenario");
@@ -2020,17 +2020,6 @@
           return nil;
         },
 
-        findElementByName : func(base,name) {
-          foreach( var child; base.getChildren() ) {
-            var n = child.getNode( "name" );
-            if( n != nil and n.getValue() == name )
-              return child;
-            var f = me.findElementByName(child,name);
-            if( f != nil ) return f;
-          }
-          return nil;
-        },
-
         scenarioListener : func( n ) {
           description = "";
           metar = "nil";