Index: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocument.java
===================================================================
--- trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocument.java	(revision 1436)
+++ trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocument.java	(revision 1490)
@@ -16,4 +16,5 @@
 
 import de.ugoe.cs.autoquest.eventcore.guimodel.IDialog;
+import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
 
 /**
@@ -69,4 +70,40 @@
     }
 
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
+     */
+    @Override
+    public double getDistanceTo(IGUIElement otherElement) {
+        if (otherElement instanceof HTMLServer) {
+            // use the implementation provided by the server
+            return otherElement.getDistanceTo(this);
+        }
+        else if (otherElement instanceof HTMLDocument) {
+            if (this.getSpecification().getSimilarity(otherElement.getSpecification())) {
+                return DISTANCE_NONE;
+            }
+            else {
+                // use the implementation provided by the server to check if the document resists
+                // at least on the same server
+                return getServer().getDistanceTo(otherElement);
+            }
+        }
+        else if (otherElement instanceof HTMLPageElement) {
+            HTMLDocumentSpec documentSpec =
+                ((HTMLPageElementSpec) otherElement.getSpecification()).getPage();
+            
+            if (this.getSpecification().getSimilarity(documentSpec)) {
+                return DISTANCE_SAME_DOCUMENT;
+            }
+            else {
+                // use the implementation provided by the server to check if the document resists
+                // at least on the same server
+                return getServer().getDistanceTo(otherElement);
+            }
+        }
+        
+        return DISTANCE_DISTINCT_SERVER;
+    }
+
     /**
      * <p>
Index: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLGUIElement.java
===================================================================
--- trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLGUIElement.java	(revision 1436)
+++ trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLGUIElement.java	(revision 1490)
@@ -26,5 +26,5 @@
  * @author Patrick Harms
  */
-public class HTMLGUIElement extends AbstractDefaultGUIElement {
+public abstract class HTMLGUIElement extends AbstractDefaultGUIElement {
 
     /**
@@ -34,4 +34,39 @@
      */
     private static final long serialVersionUID = 1L;
+    
+    /**
+     * <p>
+     * the default distance value for different servers
+     * </p>
+     */
+    protected static final double DISTANCE_DISTINCT_SERVER = 1.0;
+
+    /**
+     * <p>
+     * the default distance value for same server but different documents
+     * </p>
+     */
+    protected static final double DISTANCE_SAME_SERVER = 0.75;
+
+    /**
+     * <p>
+     * the default distance value for same document but different page elements
+     * </p>
+     */
+    protected static final double DISTANCE_SAME_DOCUMENT = 0.5;
+
+    /**
+     * <p>
+     * the default distance value for same parent div but different page elements 
+     * </p>
+     */
+    protected static final double DISTANCE_SAME_DIV = 0.2;
+
+    /**
+     * <p>
+     * the default distance value for identical elements
+     * </p>
+     */
+    protected static final double DISTANCE_NONE = 0.0;
 
     /**
Index: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElement.java
===================================================================
--- trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElement.java	(revision 1436)
+++ trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElement.java	(revision 1490)
@@ -14,4 +14,6 @@
 
 package de.ugoe.cs.autoquest.plugin.html.guimodel;
+
+import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
 
 /**
@@ -78,4 +80,77 @@
     }
 
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
+     */
+    @Override
+    public double getDistanceTo(IGUIElement otherElement) {
+        if ((otherElement instanceof HTMLServer) || (otherElement instanceof HTMLDocument)) {
+            // use the implementation provided by the server or document
+            return otherElement.getDistanceTo(this);
+        }
+        else if (otherElement instanceof HTMLPageElement) {
+            if (this == otherElement) {
+                return DISTANCE_NONE;
+            }
+            
+            HTMLDocumentSpec documentSpec1 =
+                ((HTMLPageElementSpec) this.getSpecification()).getPage();
+            HTMLDocumentSpec documentSpec2 =
+                ((HTMLPageElementSpec) otherElement.getSpecification()).getPage();
+            
+            if (!documentSpec1.getSimilarity(documentSpec2)) {
+                if (!documentSpec1.getServer().getSimilarity(documentSpec2.getServer())) {
+                    return DISTANCE_DISTINCT_SERVER;
+                }
+                else {
+                    return DISTANCE_SAME_SERVER;
+                }
+            }
+            else {
+                // check if they have the same parent div element. If so, they are very close.
+                // If not, they may be structured completely differently
+                IGUIElement parentDiv1 = this;
+                
+                while (parentDiv1 != null) {
+                    if ((parentDiv1 instanceof HTMLPageElement) &&
+                        ("div".equals(((HTMLPageElement) parentDiv1).getTagName())))
+                    {
+                        break;
+                    }
+                    else {
+                        parentDiv1 = parentDiv1.getParent();
+                    }
+                }
+                
+                IGUIElement parentDiv2 = (HTMLPageElement) otherElement;
+                
+                while (parentDiv2 != null) {
+                    if ((parentDiv2 instanceof HTMLPageElement) &&
+                        ("div".equals(((HTMLPageElement) parentDiv2).getTagName())))
+                    {
+                        break;
+                    }
+                    else {
+                        parentDiv2 = parentDiv2.getParent();
+                    }
+                }
+                
+                // a check for the identity of the objects is sufficient. That they resist on the
+                // same document was checked beforehand. So even a condense of the GUI model should
+                // not cause an invalid result here.
+                if ((parentDiv1 == parentDiv2) ||
+                    ((parentDiv1 != null) && (parentDiv1.equals(parentDiv2))))
+                {
+                    return DISTANCE_SAME_DIV;
+                }
+                else {
+                    return DISTANCE_SAME_DOCUMENT;
+                }
+            }
+        }
+        
+        return DISTANCE_DISTINCT_SERVER;
+    }
+    
     /*
      * (non-Javadoc)
Index: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServer.java
===================================================================
--- trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServer.java	(revision 1436)
+++ trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServer.java	(revision 1490)
@@ -16,4 +16,5 @@
 
 import de.ugoe.cs.autoquest.eventcore.guimodel.IFrame;
+import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
 
 /**
@@ -86,3 +87,39 @@
     }
 
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
+     */
+    @Override
+    public double getDistanceTo(IGUIElement otherElement) {
+        if (otherElement instanceof HTMLServer) {
+            if (this.equals(otherElement)) {
+                return DISTANCE_NONE;
+            }
+            else {
+                return DISTANCE_DISTINCT_SERVER;
+            }
+        }
+        else if (otherElement instanceof HTMLDocument) {
+            if (this.equals(((HTMLDocument) otherElement).getServer())) {
+                return DISTANCE_SAME_SERVER;
+            }
+            else {
+                return DISTANCE_DISTINCT_SERVER;
+            }
+        }
+        else if (otherElement instanceof HTMLPageElement) {
+            HTMLServerSpec serverSpec =
+                ((HTMLPageElementSpec) otherElement.getSpecification()).getPage().getServer();
+            
+            if (this.getSpecification().getSimilarity(serverSpec)) {
+                return DISTANCE_SAME_SERVER;
+            }
+            else {
+                return DISTANCE_DISTINCT_SERVER;
+            }
+        }
+        
+        return DISTANCE_DISTINCT_SERVER;
+    }
+
 }
