Index: gli/trunk/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- gli/trunk/src/org/greenstone/gatherer/Gatherer.java	(revision 16328)
+++ gli/trunk/src/org/greenstone/gatherer/Gatherer.java	(revision 16329)
@@ -170,12 +170,9 @@
 	    // We don't have a local Greenstone!
 	    go.gsdl_path = null;
+	    go.gsdl3_path=null;
+	    go.gsdl3_src_path=null;
 
 	    // We have to use our own collect directory since we can't use the Greenstone one
 	    setCollectDirectoryPath(getGLIUserDirectoryPath() + "collect" + File.separator);
-	    if (go.run_gsdl3){	 
-		GS3=true;
-		go.gsdl3_path=null;
-		go.gsdl3_src_path=null;
-	    }
 	}
 	// No, we have a local Greenstone
@@ -198,9 +195,5 @@
 	    }
 
-	    if (!go.run_gsdl3){	 
-		Configuration.CONFIG_XML = "configRemote.xml";
-	    }else{
-		Configuration.GS3_CONFIG_XML = "config3Remote.xml";
-	    }
+	    Configuration.CONFIG_XML = "configRemote.xml"; 
 
 	    File collect_directory = new File(Gatherer.getCollectDirectoryPath());
@@ -212,6 +205,6 @@
 	    if (go.fedora_info.isActive()) {
 		Configuration.TEMPLATE_CONFIG_XML = "xml/" + Configuration.FEDORA_CONFIG_PREFIX + Configuration.CONFIG_XML;
-
-	    }
+	    }
+	    // else, the CONFIG_XML uses the default config file, which is for the local GS server
 	}
 
@@ -268,5 +261,5 @@
 	    new Configuration(getGLIUserDirectoryPath(), gsdl_path, gsdl3_path, gsdl3_src_path, site_name,
 			      fedora_info);
-
+	    
 	    // Check we know where Perl is
 	    Configuration.perl_path = perl_path;
@@ -304,4 +297,20 @@
 	    }
 
+	    // Finally, we're ready to find out the version of the remote Greenstone server 
+	    if(isGsdlRemote) {
+		int greenstoneVersion = 2;
+		requestGLIServerURL();
+		gliserver_url_string = Configuration.gliserver_url.toString();
+		
+		greenstoneVersion = RemoteGreenstoneServer.getGreenstoneVersion();
+		// Display the version to make error reports a lot more useful
+		System.err.println("Remote Greenstone server version: " + greenstoneVersion);
+		if(greenstoneVersion >= 3) {
+		    this.GS3 = true;
+		    Configuration.prepareForGS3();
+		} 
+		
+		library_url_string = RemoteGreenstoneServer.getLibraryURL(Configuration.gliserver_url.toString());
+	    }
 
 	    // Start up the local library server, if that's what we want
@@ -309,5 +318,5 @@
 		LocalLibraryServer.start(gsdl_path, local_library_path);
 	    }
-
+	    
 	    // The "-library_url" option overwrites anything in the config files
 	    if (library_url_string != null && library_url_string.length() > 0) {
@@ -320,4 +329,5 @@
 		}
 	    }
+  
 
 	    // Check that we now know the Greenstone library URL, since we need this for previewing collections
@@ -325,30 +335,4 @@
 	    if (Configuration.library_url == null) {
 		missingEXEC(); 
-
-		if ((Configuration.library_url!=null) && isGsdlRemote && (gliserver_url_string==null)){
-		    if (GS3){
-			default_gliserver_url = new URL(Configuration.library_url.toString() + "/cgi-bin/gliserver4gs3.pl");
-		    }else{
-			String default_gliserver_str = "";
-			String library_url_str = Configuration.library_url.toString();			
-			int cut_pos = library_url_str.lastIndexOf("/library");
-
-			if (cut_pos>0) {
-			    default_gliserver_str = library_url_str.substring(0,cut_pos) + "/gliserver.pl";
-			}
-			else {
-			    cut_pos = library_url_str.lastIndexOf("/");
-			    if (cut_pos>0) {
-				default_gliserver_str = library_url_str.substring(0,cut_pos) + "/gliserver.pl";
-			    }
-			    else {
-				default_gliserver_str = library_url_str + "/gliserver.pl";
-			    }
-			}
-
-			default_gliserver_url = new URL(default_gliserver_str);
-		    }
-		    missingGLIServer();
-		}
 	    }
 
@@ -366,20 +350,4 @@
 	    // If we're using a remote Greenstone we need to know where the gliserver script is
 	    DebugStream.println("Configuration.gliserver_url = " + Configuration.gliserver_url);
-	    if (isGsdlRemote) {
-		if (Configuration.gliserver_url == null) {
-		    if (Configuration.library_url != null) {
-			if (GS3){
-			    default_gliserver_url = new URL(Configuration.library_url.toString() + "/cgi-bin/gliserver4gs3.pl");
-			}else{
-			    String library_url = Configuration.library_url.toString();
-			    default_gliserver_url = new URL(library_url.substring(0,library_url.lastIndexOf("/library")) + "/gliserver.pl");
-			}
-		    }
-		    missingGLIServer();
-		}
-		if (Configuration.gliserver_url != null) {
-		    gliserver_url_string = Configuration.gliserver_url.toString();
-		}
-	    }
 
 	    if (GS3) {
@@ -480,4 +448,5 @@
 	}
 
+	
 	// Create GUI Manager (last) or else suffer the death of a thousand NPE's
 	g_man = new GUIManager(size);
@@ -497,4 +466,15 @@
 
     }
+
+    
+    /** Returns the correct version of the (local or remote) Greenstone server if init() has already been called. */
+    public static int serverVersionNumber() { 
+	return GS3 ? 3 : 2;
+    } 
+
+    /** Returns "Server: version number" if init() has already been called. */
+    public static String getServerVersionAsString() { 
+	return "Server: v" + serverVersionNumber();
+    } 
 
     public void openGUI()
@@ -607,6 +587,8 @@
 
 	// Get the gui to deallocate
-	g_man.destroy();
-	g_man_built = false;
+	if(g_man != null) {
+	    g_man.destroy();
+	    g_man_built = false;
+	}
 
 	// Flush debug
@@ -818,5 +800,5 @@
 	    dialog = new WarningDialog("warning.MissingEXEC", Dictionary.get("MissingEXEC.Title"), Dictionary.get("MissingEXEC.Message"), "general.library_url", false);
 	}
-	dialog.setValueField(new URLField(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false)));
+	dialog.setValueField(new URLField.Text(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false)));
 	dialog.display();
 	dialog.dispose();
@@ -891,4 +873,5 @@
 		}
 		catch (Exception exception) {
+		    // TODO: move into dictionary
 		    String[] errorMessage = {"Failed to connect to the Fedora server.", "It might not be running, or",
 					     "incorrect username and/or password."};
@@ -909,21 +892,38 @@
 
 
-    static private void missingGLIServer()
+    static private void requestGLIServerURL()
     {
 	WarningDialog dialog;
-	if (GS3) {
-	    dialog = new WarningDialog("warning.MissingGLIServer", Dictionary.get("MissingGLIServer_GS3.Title"), Dictionary.get("MissingGLIServer_GS3.Message"), "general.gliserver_url", false);
-	}else {
-	    dialog = new WarningDialog("warning.MissingGLIServer", Dictionary.get("MissingGLIServer.Title"), Dictionary.get("MissingGLIServer.Message"), "general.gliserver_url", false);
-	}
-	dialog.setValueField(new URLField(Configuration.getColor("coloring.editable_foreground", false), Configuration.getColor("coloring.editable_background", false)));
-	
+	String[] defaultURLs = {
+	    "http://localhost:8080/greenstone3/cgi-bin/gliserver.pl", 
+	    "http://localhost:8080/gsdl/cgi-bin/gliserver.pl"
+	};
+
+	// Warning dialog with no cancel button and no "turn off warning" checkbox 
+	// (since user-input of the gliserver script is mandatory)
+	dialog = new WarningDialog("warning.MissingGLIServer", Dictionary.get("MissingGLIServer.Title"), Dictionary.get("MissingGLIServer.Message"), "general.gliserver_url", false, false); 
+
+	dialog.setValueField(new URLField.DropDown(Configuration.getColor("coloring.editable_foreground", false), 
+						   Configuration.getColor("coloring.editable_background", false), 
+						   defaultURLs, "general.gliserver_url", "general.open_collection",  
+						   "gliserver.pl"));
+
 	if (Gatherer.default_gliserver_url!=null){
 	    dialog.setValueField(Gatherer.default_gliserver_url.toString());
 	}
+
+	// A WarningDialog cannot always be made to respond (let alone to exit the program) on close. We
+	// handle the response of this particular WarningDialog here: a URL for gliserver.pl is a crucial
+	// piece of user-provided data. Therefore, if no URL was entered for gliserver.pl, it'll exit safely.
+	dialog.addWindowListener(new WindowAdapter() {
+		public void windowClosing(WindowEvent e) {
+		    Gatherer.exit();
+		}
+	    });
 	
 	dialog.display();
 	dialog.dispose();
 	dialog = null;
+
 	
 	String gliserver_url_string = Configuration.getString("general.gliserver_url", true);
