[Checkins] SVN: zc.selenium/trunk/src/zc/selenium/ Initial import. A way to write selenium tests in Python rather than in HTML tables, including a way to push and pop ZODB state from within selenium.

Gary Poster gary at zope.com
Tue Aug 15 17:19:33 EDT 2006


Log message for revision 69543:
  Initial import.  A way to write selenium tests in Python rather than in HTML tables, including a way to push and pop ZODB state from within selenium.
  

Changed:
  A   zc.selenium/trunk/src/zc/selenium/__init__.py
  A   zc.selenium/trunk/src/zc/selenium/configure.zcml
  A   zc.selenium/trunk/src/zc/selenium/dbs.py
  A   zc.selenium/trunk/src/zc/selenium/pytest.py
  A   zc.selenium/trunk/src/zc/selenium/pytest.txt
  A   zc.selenium/trunk/src/zc/selenium/resource.py
  A   zc.selenium/trunk/src/zc/selenium/resources/
  A   zc.selenium/trunk/src/zc/selenium/resources/SeleneseRunner.html
  A   zc.selenium/trunk/src/zc/selenium/resources/SeleniumLog.html
  A   zc.selenium/trunk/src/zc/selenium/resources/TestPrompt.html
  A   zc.selenium/trunk/src/zc/selenium/resources/TestRunner-splash.html
  A   zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta
  A   zc.selenium/trunk/src/zc/selenium/resources/TestRunner.html
  A   zc.selenium/trunk/src/zc/selenium/resources/domviewer/
  A   zc.selenium/trunk/src/zc/selenium/resources/domviewer/butmin.gif
  A   zc.selenium/trunk/src/zc/selenium/resources/domviewer/butplus.gif
  A   zc.selenium/trunk/src/zc/selenium/resources/domviewer/domviewer.css
  A   zc.selenium/trunk/src/zc/selenium/resources/domviewer/domviewer.html
  A   zc.selenium/trunk/src/zc/selenium/resources/domviewer/selenium-domviewer.js
  A   zc.selenium/trunk/src/zc/selenium/resources/iedoc.xml
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/html-xpath-patched.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/htmlutils.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-api.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserbot.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserdetect.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-commandhandlers.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-executionloop.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-logging.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-seleneserunner.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-testrunner.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-version.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/user-extensions.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/user-extensions.js.sample
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/xmlextras.js
  A   zc.selenium/trunk/src/zc/selenium/resources/scripts/xpath.js
  A   zc.selenium/trunk/src/zc/selenium/resources/selenium-logo.png
  A   zc.selenium/trunk/src/zc/selenium/resources/selenium.css
  A   zc.selenium/trunk/src/zc/selenium/resources/tests/
  A   zc.selenium/trunk/src/zc/selenium/resources/tests/TestSuite.html
  A   zc.selenium/trunk/src/zc/selenium/resources/tests/pop.html
  A   zc.selenium/trunk/src/zc/selenium/resources/tests/push.html
  A   zc.selenium/trunk/src/zc/selenium/results.pt
  A   zc.selenium/trunk/src/zc/selenium/results.py
  A   zc.selenium/trunk/src/zc/selenium/tests.py

-=-
Added: zc.selenium/trunk/src/zc/selenium/__init__.py
===================================================================
--- zc.selenium/trunk/src/zc/selenium/__init__.py	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/__init__.py	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1 @@
+#

Added: zc.selenium/trunk/src/zc/selenium/configure.zcml
===================================================================
--- zc.selenium/trunk/src/zc/selenium/configure.zcml	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/configure.zcml	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:browser="http://namespaces.zope.org/browser"
+    >
+
+  <browser:resourceDirectory
+      name="selenium"
+      directory="resources"
+      layer="default"
+      />
+
+  <class class=".results.Results">
+    <require
+        permission="zope.Public"
+        interface="zope.publisher.interfaces.IPublishTraverse"
+        attributes="__call__"
+        />
+  </class>
+
+  <browser:resource
+      name="selenium_results"
+      factory=".results.Results"
+      permission="zope.Public"
+      />
+
+  <browser:resource
+      name="selenium-push.html"
+      factory=".dbs.PushDBs"
+      permission="zope.Public"
+      />
+
+  <browser:resource
+      name="selenium-pop.html"
+      factory=".dbs.PopDBs"
+      permission="zope.Public"
+      />
+
+  <module module=".pytest">
+    <allow attributes="suite" />
+  </module>
+
+</configure>

Added: zc.selenium/trunk/src/zc/selenium/dbs.py
===================================================================
--- zc.selenium/trunk/src/zc/selenium/dbs.py	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/dbs.py	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 Zope Corporation. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Visible Source
+# License, Version 1.0 (ZVSL).  A copy of the ZVSL should accompany this
+# distribution.
+#
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Demo storage push/pop operations, as resources.
+
+$Id: dbs.py 12602 2006-07-06 06:29:48Z fred $
+"""
+
+from ZODB.DemoStorage import DemoStorage
+from ZODB.DB import DB
+from zope.exceptions.interfaces import UserError
+
+import zc.selenium.resource
+
+
+class PushDBs(zc.selenium.resource.ResourceBase):
+
+    def GET(self):
+        publication = self.request.publication
+        if [1
+            for d in publication.db.databases.values()
+            if not isinstance(d._storage, DemoStorage)
+            ]:
+            raise UserError("Wrong mode")
+
+        databases = {}
+        for name, db in publication.db.databases.items():
+            DB(DemoStorage(base=db._storage),
+               databases=databases, database_name=name,
+               )
+
+        newdb = databases[publication.db.database_name]
+        newdb.pushed_base = publication.db # hacking extra attr onto db
+        publication.db = newdb
+
+        return 'Done'
+
+class PopDBs(zc.selenium.resource.ResourceBase):
+
+    def GET(self):
+        publication = self.request.publication
+        publication.db = publication.db.pushed_base
+
+        return 'Done'

Added: zc.selenium/trunk/src/zc/selenium/pytest.py
===================================================================
--- zc.selenium/trunk/src/zc/selenium/pytest.py	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/pytest.py	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,204 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Visible Source
+# License, Version 1.0 (ZVSL).  A copy of the ZVSL should accompany this
+# distribution.
+#
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+"""Infrastructure to allow sellenium tests to be written in Python
+
+$Id: pytest.py 13165 2006-08-14 22:33:23Z fred $
+"""
+import os.path
+import sys
+import urlparse
+
+import zope.publisher.interfaces.browser
+
+from zope import component, interface
+
+
+class ISeleniumTest(zope.publisher.interfaces.browser.IBrowserPublisher):
+    """A page that is a selenium test
+    """
+
+    def __call__():
+        """Return the selenium test
+        """
+
+def suite(request):
+    tests = [item for item in component.getAdapters([request], ISeleniumTest)]
+    tests.sort()
+    return '\n'.join([
+        ('<tr><td><a href="/@@/%s">%s</a></td></tr>' % (
+             name,
+             (test.__doc__ or '').strip().split('\n')[0] or name,
+             )
+         )
+        for name, test in tests
+        ])
+
+
+class Row:
+
+    def __init__(self, output, name, cssClass=None):
+        self.output = output
+        self.__name__ = name
+        self.cssClass = cssClass
+
+    def __call__(self, arg1='', arg2='', lineno=True, frame=None):
+        if lineno and self.__name__ != 'comment':
+            if frame is None:
+                frame = sys._getframe(1)
+            filename = frame.f_code.co_filename
+            base = os.path.basename(filename)
+            Row(self.output, 'comment', 'lineinfo')(
+                '%s:%s <span class="longpath">%s:%d</span>'
+                % (base, frame.f_lineno, filename, frame.f_lineno))
+
+        append = self.output.append
+        if self.cssClass:
+            append('<tr class="%s">\n<td>' % self.cssClass)
+        else:
+            append('<tr>\n<td>')
+        append(self.__name__)
+        append('</td>\n')
+        append('<td>')
+        append(arg1)
+        append('</td>\n')
+        append('<td>')
+        append(arg2)
+        append('</td>\n')
+        append('</tr>\n')
+
+
+# Moving the embedded stylesheet to a separate file and using @import
+# doesn't work for some reason (probably related to the way Selenium
+# loads the test).
+#
+header = """<html>
+<head>
+<title>%s</title>
+<style type="text/css">
+
+.longpath:before {
+  content: "(";
+  font-size: 90%%;
+  }
+
+.longpath {
+  font-size: 90%%;
+  }
+
+.longpath:after {
+  content: ")";
+  font-size: 90%%;
+  }
+
+</style>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<tbody>
+<tr>
+<td rowspan="1" colspan="3">%s</td>
+</tr>
+
+"""
+
+footer = '</tbody></table></body></html>'
+
+class Selenium:
+
+    def __init__(self, request, title, message=None):
+        if message is None:
+            message = title
+        self.output = [header % (title, message)]
+        url = str(request.URL)
+        self.server = urlparse.urlsplit(url)[1]
+
+    def push(self):
+        self.open('http://%s/@@/selenium-push.html' % self.server,
+                  lineno=False)
+
+    def pop(self):
+        self.open('http://%s/@@/selenium-pop.html' % self.server,
+                  lineno=False)
+
+    def __getattr__(self, name):
+        return Row(self.output, name)
+
+    def __str__(self):
+        return ''.join(self.output) + footer
+
+class Test(object):
+    component.adapts(zope.publisher.interfaces.browser.IBrowserRequest)
+    interface.implements(ISeleniumTest)
+
+    def __init__(self, request):
+        self.request = request
+        title = (self.__doc__ or '').split('\n')[0]
+        mess = ''
+        if title:
+            mess += '\n<h1>%s</h1>\n' % title
+            mess += '<br>\n'.join((self.__doc__ or '').split('\n')[1:])
+
+        self.selenium = Selenium(self.request, title, mess)
+
+    def browserDefault(self, request):
+        return self, ()
+
+    def sharedSetUp(self):
+        self.selenium.push()
+
+    def sharedTearDown(self):
+        self.selenium.pop()
+
+    def setUp(self):
+        self.selenium.push()
+
+    def tearDown(self):
+        self.selenium.pop()
+
+    def __call__(self):
+        tests = [name for name in dir(self) if name.startswith('test')]
+        tests.sort()
+        s = self.selenium
+        outputDoc(self, self.sharedSetUp.__doc__, 2)
+        self.sharedSetUp()
+        for test in tests:
+            test = getattr(self, test)
+            outputDoc(self, test.__doc__, 2)
+            outputDoc(self, self.setUp.__doc__, 3)
+            self.setUp()
+            test()
+            outputDoc(self, self.tearDown.__doc__, 3)
+            self.tearDown()
+
+        self.sharedTearDown()
+
+        return str(s)
+
+
+# function to avoid class namespace clutter
+def outputDoc(self, doc, level):
+    if not doc:
+        return
+    doc = doc.strip()
+    if not doc:
+        return
+
+    title = doc.split('\n')[0]
+    mess = ''
+    if title:
+        mess += '\n<h%d>%s</h%d>' % (level, title, level)
+        mess += '<br>\n'.join(doc.split('\n')[1:])
+
+    self.selenium.comment(mess)

Added: zc.selenium/trunk/src/zc/selenium/pytest.txt
===================================================================
--- zc.selenium/trunk/src/zc/selenium/pytest.txt	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/pytest.txt	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,495 @@
+Writing Selenium Tests in Python
+================================
+
+HTML is a cumbersome format for writting tests.  Selenium's test
+format, HTML rows, leads to lots of extra boilerplate that is a pain to
+manage and that distracts from the actual test content.
+
+The pytest module allows a much more concise format to be used.  Test
+go from source like this::
+  
+  <tr>
+   <td>verifyLocation</td>
+   <td>/FIPS/home/fred/addIntelProductProcessFromHomePage.html</td>
+   <td>&nbsp;</td>
+  </tr> 
+
+to source like this::
+
+  s.verifyLocation("/FIPS/home/fred/addIntelProductProcessFromHomePage.html")
+
+The Python format provides other benefits:
+
+- Generation of comments containing line information, so that, when a
+  test fails, there is clear indication of where in the test the
+  failure occurred.
+
+- Generation of test comments from doc strings.
+
+- Automatic management (push/pop) of demo storages.
+
+- Organzation of tests into Python methods.
+
+- The option of using Python scripting (fuctions, loops, etc.) to 
+  improve test structuring.
+
+- Automatic test discovery.  Tests don't have to be put in a central
+  place and hand knit into the test suite.
+
+How it works
+------------
+
+Python Selenium tests are request adapters (resources) that, when run,
+generate HTML tables.  They provide the ISeleniumTest marker interface.   
+This interface is used to look them up and knit them into the test suite.
+
+How to write a test
+-------------------
+
+To write a Selenium test, you need to create a Python component and
+register it in ZCML.  The component is written by subclassing
+zc.selenium.pytest.Test:
+
+    >>> import zc.selenium.pytest
+    >>> class Test(zc.selenium.pytest.Test):
+    ...     """My first test
+    ...
+    ...     Anyone can write a test
+    ...     in Python
+    ...     """
+    ...
+    ...     def test1(self):
+    ...         s = self.selenium
+    ...         s.comment("show something")
+    ...         s.foo('bar')
+    ...         s.splat('eeek', 'oy')
+    ...
+    ...     def test2(self):
+    ...         """Show something
+    ...         """    
+    ...         s = self.selenium
+    ...         s.foo('bar')
+    ...
+    ...     def Waaa(self):
+    ...         s = self.selenium
+    ...         s.comment("No one ever calls me!")
+
+If we use this to adapt a request, and call it, we'll get a single
+HTML table:
+
+    >>> from zope.publisher.browser import TestRequest
+    >>> print Test(TestRequest())()
+    <html>
+    <head>
+    <title>My first test</title>
+    <style type="text/css">
+    ...
+    </style>
+    </head>
+    <body>
+    <table cellpadding="1" cellspacing="1" border="1">
+    <tbody>
+    <tr>
+    <td rowspan="1" colspan="3">
+    <h1>My first test</h1>
+    <br>
+        Anyone can write a test<br>
+        in Python<br>
+        </td>
+    </tr>
+    <BLANKLINE>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-push.html</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-push.html</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>show something</td>
+    <td></td>
+    </tr>
+    <tr class="lineinfo">
+    <td>comment</td>
+    <td><doctest pytest.txt[1]>:11 ...</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>foo</td>
+    <td>bar</td>
+    <td></td>
+    </tr>
+    <tr class="lineinfo">
+    <td>comment</td>
+    <td><doctest pytest.txt[1]>:12 ...</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>splat</td>
+    <td>eeek</td>
+    <td>oy</td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-pop.html</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>
+    <h2>Show something</h2></td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-push.html</td>
+    <td></td>
+    </tr>
+    <tr class="lineinfo">
+    <td>comment</td>
+    <td><doctest pytest.txt[1]>:18 ...</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>foo</td>
+    <td>bar</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-pop.html</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-pop.html</td>
+    <td></td>
+    </tr>
+    </tbody></table></body></html>
+
+There are a number of things to note about this example.
+
+- Each test class defines a single Selenium test, ultimately a
+  Selenium table. 
+
+- Tests are orgaized into test methods.  Methods with names that start
+  with "test" are called automatically in name order.  Other methods
+  can be defined for whatever purpose.
+
+- Methods emit Selenium commands by calling methods on self.selenium.
+  The method names become Selenium commands.  Methods take one or 2
+  string arguments.  The pytest framework will accept any method name
+  a blindly create a Selenium statement.  In this example, I used
+  invalid Selenium commands, "foo" and "splat" to illustrate
+  this. Ultimately, we're just generating HTML rows. :)
+
+- For each non-comment Selenium command, a comment was generated
+  giving the file name and line number.  (The details of the generated
+  comments are not guaranteed, and are strictly for human consumption.)
+
+- Selenium push and pop cals are generated at the beginning and end of
+  the test and for each tst method.  This allows the test to be
+  independent from other tests and for test methods to be independent
+  from one another.  This behavior can be overridden, as we'll see
+  later. 
+
+- The test doc string is used to create the test documentation:
+
+  o The first line of the docstring provides the title for the
+    generated HTML page and a heading line in the first line of the
+    documentation row.
+
+  o The remaining text is included in the documentation row, with a
+    break for each line ending in the text.
+
+- The doc strings for the test methods are included as comments.  The
+  first line is included as a heading and the remaining lines are
+  included, separated by breaks.
+
+It's also possible to control what frame is used as the source for
+line number and filename reporting by using the `frame` keyword
+argument to the command function.  This can be used to allow helper
+methods to report the "test logic" location of caller rather than
+cluttering the test with it's own location.
+
+    >>> import sys
+    >>> class FrameSample(zc.selenium.pytest.Test):
+    ...     """Frame selection example."""
+    ...
+    ...     def test_frame_selection(self):
+    ...         """Show frame selection"""
+    ...         self.my_helper()
+    ...
+    ...     def my_helper(self):
+    ...         self.selenium.sample(frame=sys._getframe(1))
+
+    >>> print FrameSample(TestRequest())()
+    <html>
+    <head>
+    <title>Frame selection example.</title>
+    <style type="text/css">
+    ...
+    </style>
+    </head>
+    <body>
+    <table cellpadding="1" cellspacing="1" border="1">
+    <tbody>
+    <tr>
+    <td rowspan="1" colspan="3">
+    <h1>Frame selection example.</h1>
+    </td>
+    </tr>
+    <BLANKLINE>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-push.html</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>
+    <h2>Show frame selection</h2></td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-push.html</td>
+    <td></td>
+    </tr>
+    <tr class="lineinfo">
+    <td>comment</td>
+    <td><doctest pytest.txt[5]>:6 ...</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>sample</td>
+    <td></td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-pop.html</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-pop.html</td>
+    <td></td>
+    </tr>
+    </tbody></table></body></html>
+
+Set up and tear down
+--------------------
+
+Tests can define setUp and tearDown methods that are run before and
+after each test method.  Test can also define sharedSetUp and
+sharedTearDown methods that are run at the beginning and end of the
+test.  The default setUp and sharedSetUp push a new demo strorage. The
+default tearDown and sharedTearDown pop the storage that the set up
+methods pushed.
+
+
+    >>> import zc.selenium.pytest
+    >>> class Second(zc.selenium.pytest.Test):
+    ...     """My second test
+    ...     """
+    ...
+    ...     def sharedSetUp(self):
+    ...         """Basic set up
+    ...         
+    ...         Because we can.
+    ...         """
+    ...         super(Second, self).sharedSetUp()
+    ...         self.selenium.foo('start')
+    ...
+    ...     def sharedTearDown(self):
+    ...         super(Second, self).sharedTearDown()
+    ...         self.selenium.foo('end')
+    ...
+    ...     def setUp(self):
+    ...         self.selenium.comment('No push needed')
+    ...
+    ...     def tearDown(self):
+    ...         """Doc strings for setUp and tearDown become comments
+    ...         """
+    ...         self.selenium.comment('No pop needed')
+    ...         
+    ...     def testx(self):
+    ...         s = self.selenium
+    ...         s.open(s.server)
+    ...
+    ...     def testy(self):
+    ...         """Show something
+    ...         """    
+    ...         s = self.selenium
+    ...         s.foo('bar')
+    ...         s.baz(lineno=False)
+
+    >>> print Second(TestRequest())()
+    <html>
+    <head>
+    <title>My second test</title>
+    <style type="text/css">
+    ...
+    </style>
+    </head>
+    <body>
+    <table cellpadding="1" cellspacing="1" border="1">
+    <tbody>
+    <tr>
+    <td rowspan="1" colspan="3">
+    <h1>My second test</h1>
+        </td>
+    </tr>
+    <BLANKLINE>
+    <tr>
+    <td>comment</td>
+    <td>
+    <h2>Basic set up</h2>        <br>
+            Because we can.</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-push.html</td>
+    <td></td>
+    </tr>
+    <tr class="lineinfo">
+    <td>comment</td>
+    <td><doctest pytest.txt[8]>:11 ...</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>foo</td>
+    <td>start</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>No push needed</td>
+    <td></td>
+    </tr>
+    <tr class="lineinfo">
+    <td>comment</td>
+    <td><doctest pytest.txt[8]>:27 ...</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>127.0.0.1</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>
+    <h3>Doc strings for setUp and tearDown become comments</h3></td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>No pop needed</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>
+    <h2>Show something</h2></td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>No push needed</td>
+    <td></td>
+    </tr>
+    <tr class="lineinfo">
+    <td>comment</td>
+    <td><doctest pytest.txt[8]>:33 ...</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>foo</td>
+    <td>bar</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>baz</td>
+    <td></td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>
+    <h3>Doc strings for setUp and tearDown become comments</h3></td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>comment</td>
+    <td>No pop needed</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>open</td>
+    <td>http://127.0.0.1/@@/selenium-pop.html</td>
+    <td></td>
+    </tr>
+    <tr class="lineinfo">
+    <td>comment</td>
+    <td><doctest pytest.txt[8]>:15 ...</td>
+    <td></td>
+    </tr>
+    <tr>
+    <td>foo</td>
+    <td>end</td>
+    <td></td>
+    </tr>
+    </tbody></table></body></html>
+
+Some things to note, in addition to the fact that out set-up and
+tear-down methods were called:
+
+- If a set-up or tear-down method has a doc string, it is output as a
+  comment. 
+
+- The selenium object has a variable, server, that can be used to
+  generate URLs, as illustrated by the testx method.
+
+- The lineno keyword argument to the selenium command function can be
+  used to disable the comment directive containing line number
+  information.  This can be useful with certain selenium directives
+  that deal with confirmation dialogs, since no intervening comment
+  directive may be allowed.
+
+Registration
+------------
+
+To get our tests to be used in the Selenium test suite, we need to
+register them as request adapters.  We would normally use ZCML like
+the following::
+
+    <adapter 
+        factory=".Second" 
+        name="some-url-for-the-second-test.html"
+        permission="zope.Public"
+        />
+
+We'll illustrate this using the component API:
+
+    >>> from zope import component
+    >>> component.provideAdapter(Test, name='first.html')
+    >>> component.provideAdapter(Second, name='second.html')
+
+The test suite used the zc.selenium.pytest.suite function to
+compute rows for the test suite:
+
+    >>> print zc.selenium.pytest.suite(TestRequest())
+    <tr><td><a href="/@@/first.html">My first test</a></td></tr>
+    <tr><td><a href="/@@/second.html">My second test</a></td></tr>
+
+For each test, a row is output with a link to the test resource and a
+link title computed from the test doc string.  The tests are output in
+adapter (resource) name order.
+


Property changes on: zc.selenium/trunk/src/zc/selenium/pytest.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zc.selenium/trunk/src/zc/selenium/resource.py
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resource.py	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resource.py	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Visible Source
+# License, Version 1.0 (ZVSL).  A copy of the ZVSL should accompany this
+# distribution.
+#
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Base class for zc.selenium's active resources.
+
+"""
+__docformat__ = "reStructuredText"
+
+import zope.interface
+import zope.publisher.browser
+import zope.publisher.interfaces.browser
+
+import zope.app.publisher.browser.resource
+
+
+class ResourceBase(zope.publisher.browser.BrowserView,
+                   zope.app.publisher.browser.resource.Resource):
+
+    zope.interface.implements(
+        zope.publisher.interfaces.browser.IBrowserPublisher)
+
+    def __init__(self, request):
+        self.request = request
+        self.context = self
+
+    def publishTraverse(self, request, name):
+        raise NotFound(None, name)
+
+    def browserDefault(self, request):
+        return getattr(self, request.method), ()

Added: zc.selenium/trunk/src/zc/selenium/resources/SeleneseRunner.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/SeleneseRunner.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/SeleneseRunner.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,106 @@
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+<meta content="text/html; charset=ISO-8859-1"
+http-equiv="content-type">
+<title>Selenium Functional Test Runner</title>
+<link rel="stylesheet" type="text/css" href="selenium.css" />
+<script language="JavaScript" type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
+<script type="text/javascript" src="scripts/xmlextras.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/html-xpath-patched.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-seleneserunner.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/xpath.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
+<script language="JavaScript" type="text/javascript">
+    function openDomViewer() {
+        var autFrame = document.getElementById('myiframe');
+        var autFrameDocument = getIframeDocument(autFrame);
+        var domViewer = window.open('domviewer/domviewer.html');
+        domViewer.rootDocument = autFrameDocument;
+        return false;
+    }
+    
+    function cleanUp() {
+    	if (LOG != null) {
+		LOG.close();
+	}
+    }
+    
+</script>
+<script>
+</script>
+</head>
+
+<body onLoad="runTest()" onUnload="cleanUp()">
+
+<table border="1" style="height: 100%;">
+  <tr>
+    <td width="50%" height="30%">
+      <table>
+      <tr>
+        <td>
+          <img src="selenium-logo.png">
+        </td>
+        <td>
+          <h1><a href="http://selenium.thoughtworks.com" >Selenium</a> Functional Testing for Web Apps</h1>
+          Open Source From <a href="http://www.thoughtworks.com">ThoughtWorks, Inc</a> and Friends
+          <form action="">
+          <br/>Slow Mode:<INPUT TYPE="CHECKBOX" NAME="FASTMODE" VALUE="YES" onmouseup="slowClicked()"> 
+
+          <fieldset>
+            <legend>Tools</legend>
+
+            <button type="button" id="domViewer1" onclick="openDomViewer();">
+              View DOM
+            </button>
+            <button type="button" onclick="LOG.show();">
+              Show Log
+            </button>
+          </fieldset>
+
+          </form>
+
+        </td>
+      </tr>
+      </table>
+      <form action="">
+        <label id="context" name="context"></label>
+      </form>
+    </td>
+    <td width="50%" height="30%">
+      <b>Last Four Test Commands:</b><br/>
+      <div id="commandList"></div>
+    </td>
+  </tr>
+  <tr>
+    <td colspan="2" height="70%">
+      <iframe name="myiframe" id="myiframe" src="" height="100%" width="100%"></iframe>
+    </td>
+  </tr>
+</table>
+
+</body>
+</html>
+

Added: zc.selenium/trunk/src/zc/selenium/resources/SeleniumLog.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/SeleniumLog.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/SeleniumLog.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,79 @@
+<html>
+
+<head>
+<title>Selenium Log Console</title>
+<link id="cssLink" rel="stylesheet" href="selenium.css" />
+
+</head>
+<body id="logging-console">
+
+<script language="JavaScript">
+
+var logLevels = {
+    debug: 0,
+    info: 1,
+    warn: 2,
+    error: 3
+};
+
+var logLevelThreshold = null;
+
+function getThresholdLevel() {
+    var buttons = document.getElementById('logLevelChooser').level;
+    for (var i = 0; i < buttons.length; i++) {
+        if (buttons[i].checked) {
+            return buttons[i].value;
+        }
+    }
+}
+
+function setThresholdLevel(logLevel) {
+    logLevelThreshold = logLevel;
+    var buttons = document.getElementById('logLevelChooser').level;
+    for (var i = 0; i < buttons.length; i++) {
+    	if (buttons[i].value==logLevel) {
+            buttons[i].checked = true;
+        }
+        else {
+            buttons[i].checked = false;
+        }
+    }
+}
+
+function append(message, logLevel) {
+    if (logLevelThreshold==null) {
+    	logLevelThreshold = getThresholdLevel();
+    }
+    if (logLevels[logLevel] < logLevels[logLevelThreshold]) {
+        return;
+    }
+    var log = document.getElementById('log');
+    var newEntry = document.createElement('li');
+    newEntry.className = logLevel;
+    newEntry.appendChild(document.createTextNode(message));
+    log.appendChild(newEntry);
+    if (newEntry.scrollIntoView) {
+        newEntry.scrollIntoView();
+    }
+}
+
+</script>
+
+<div id="banner">
+  <form id="logLevelChooser">
+      <input id="level-error" type="radio" name="level" 
+             value="error" /><label for="level-error">Error</label>
+      <input id="level-warn" type="radio" name="level"
+             value="warn" /><label for="level-warn">Warn</label>
+      <input id="level-info" type="radio" name="level" checked="yes"
+             value="info" /><label for="level-info">Info</label>
+      <input id="level-debug" type="radio" name="level" 
+             value="debug" /><label for="level-debug">Debug</label>
+  </form>
+  <h1>Selenium Log Console</h1>
+</div>
+
+<ul id="log"></ul>
+
+</body>
+</html>

Added: zc.selenium/trunk/src/zc/selenium/resources/TestPrompt.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/TestPrompt.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/TestPrompt.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,89 @@
+<html>
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<head>
+<meta content="text/html; charset=ISO-8859-1"
+http-equiv="content-type">
+<title>Select a Test Suite</title>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
+<script>
+
+function load() {
+	if (browserVersion.isHTA) {
+		document.getElementById("save-div").style.display = "inline";
+	}
+}
+
+function autoCheck() {
+	var auto = document.getElementById("auto");
+	var autoDiv = document.getElementById("auto-div");
+	if (auto.checked) {
+		autoDiv.style.display = "inline";
+	} else {
+		autoDiv.style.display = "none";
+	}
+}
+
+function saveCheck() {
+	var results = document.getElementById("results");
+	var check =  document.getElementById("save").checked;
+	if (check) {
+		results.firstChild.nodeValue = "Results file ";
+		document.getElementById("resultsUrl").value = "results.html";
+	} else {
+		results.firstChild.nodeValue = "Results URL ";
+		document.getElementById("resultsUrl").value = "../postResults";
+	}
+}
+
+function go() {
+	var inputs = document.getElementsByTagName("input");
+	var queryString = "";
+	for (var i = 0; i < inputs.length; i++) {
+		var elem = inputs[i];
+		var name = elem.name;
+		var value = elem.value;
+		if (elem.checked) {
+			value = "true";
+		}
+		queryString += escape(name) + "=" + escape(value);
+		if (i < (inputs.length - 1)) {
+			queryString += "&";
+		}
+	}
+	window.parent.queryString = queryString;
+	window.parent.loadSuiteFrame();
+	return false;
+}
+</script>
+</head>
+<body onload="load()" style="font-size: x-small">
+<form id="prompt" target="_top" method="GET" onsubmit="return go();" action="TestRunner.html">
+<p>Select an HTML test suite:</p>
+<input id="test" name="test" size="30" value="tests/TestSuite.html"/>
+<p><label for="auto">Auto-run </label><input id="auto" type="checkbox" name="auto" value="false" onclick="autoCheck();"/>
+<div id="auto-div" style="display: none">
+<label for="close" >Close afterwards </label><input id="close" type="checkbox" name="close" />
+<div id="save-div" style="display: none">
+	<br/><label for="save">Save to file </label><input id="save" type="checkbox" name="save" onclick="saveCheck();"/>
+</div>
+<p id="results" >Results URL <input id="resultsUrl" name="resultsUrl" value="/@@selenium_results"/></p>
+</div>
+<p><input type="submit" value="go"/></p>
+</form>
+</body>
+</html>

Added: zc.selenium/trunk/src/zc/selenium/resources/TestRunner-splash.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/TestRunner-splash.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/TestRunner-splash.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,55 @@
+<!--
+Copyright 2005 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<html>
+<link rel="stylesheet" type="text/css" href="selenium.css" />
+<body>
+<table width="100%">
+
+<tr>
+  <th>&uarr;</th>
+  <th>&uarr;</th>
+  <th>&uarr;</th>
+</tr>
+<tr>
+  <th width="25%">Test Suite</th>
+  <th width="50%">Current Test</th>
+  <th width="25%">Control Panel</th>
+</tr>
+<tr><td>&nbsp;</td></tr>
+
+<tr>
+<td></td>
+<td class="selenium splash">
+
+<img src="selenium-logo.png" align="right">
+
+<h1>Selenium</h1>
+<h2>by <a href="http://www.thoughtworks.com">ThoughtWorks</a> and friends</h2>
+
+<p>
+For more information on Selenium, visit
+
+<pre>
+    <a href="http://selenium.openqa.org" target="_blank">http://selenium.openqa.org</a>
+</pre>
+
+</td>
+<tr>
+
+</table>
+</body>
+</html>

Added: zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,148 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium" >
+<!-- the previous line is only relevant if you rename this
+     file to "TestRunner.hta" -->
+
+<!-- The copyright notice and other comments have been moved to after the HTA declaration,
+     to work-around a bug in IE on Win2K whereby the HTA application doesn't function correctly -->
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
+
+<title>Selenium Functional Test Runner</title>
+<link rel="stylesheet" type="text/css" href="selenium.css" />
+<script language="JavaScript" type="text/javascript" src="scripts/html-xpath-patched.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-testrunner.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/xpath.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
+<script language="JavaScript" type="text/javascript">
+    function openDomViewer() {
+        var autFrame = document.getElementById('myiframe');
+        var autFrameDocument = getIframeDocument(autFrame);
+        this.rootDocument = autFrameDocument;
+        var domViewer = window.open('domviewer/domviewer.html');
+        return false;
+    }
+</script>
+</head>
+
+<body onload="start();">
+
+    <table class="layout">
+    <form action="" name="controlPanel">
+
+      <!-- Suite, Test, Control Panel -->
+
+      <tr class="selenium">
+        <td width="25%" height="30%" rowspan="2"><iframe name="testSuiteFrame" id="testSuiteFrame" src="./TestPrompt.html" application="yes"></iframe></td>
+        <td width="50%" height="30%" rowspan="2"><iframe name="testFrame" id="testFrame" application="yes"></iframe></td>
+        <th width="25%" height="1" class="header">
+          <h1><a href="http://selenium.thoughtworks.com" title="The Selenium Project">Selenium</a> TestRunner</h1>
+        </th>
+      </tr>
+
+      <tr class="selenium">
+        <td width="25%" height="30%" id="controlPanel">
+
+          <fieldset>
+            <legend>Execute Tests</legend>
+            
+            <div>
+              <input id="modeRun" type="radio" name="runMode" value="0" checked="checked"/><label for="modeRun">Run</label>
+              <input id="modeWalk" type="radio" name="runMode" value="500" /><label for="modeWalk">Walk</label>
+              <input id="modeStep" type="radio" name="runMode" value="-1" /><label for="modeStep">Step</label>
+            </div>
+            
+            <div>
+              <button type="button" id="runSuite" onclick="startTestSuite();"
+                      title="Run the entire Test-Suite">
+                <strong>All</strong>
+              </button>
+              <button type="button" id="runTest" onclick="runSingleTest();"
+                      title="Run the current Test">
+                <em>Selected</em>
+              </button>
+              <button type="button" id="continueTest" disabled="disabled"
+                      title="Continue the Test">
+                Continue
+              </button>
+            </div>
+            
+          </fieldset>
+
+          <table id="stats" align="center">
+            <tr>
+              <td colspan="2" align="right">Elapsed:</td>
+              <td id="elapsedTime" colspan="2">00.00</td>
+            </tr>
+            <tr>
+              <th colspan="2">Tests</th>
+              <th colspan="2">Commands</th>
+            </tr>
+            <tr>
+              <td class="count" id="testRuns">0</td>
+              <td>run</td>
+              <td class="count" id="commandPasses">0</td>
+              <td>passed</td>
+            </tr>
+            <tr>
+              <td class="count" id="testFailures">0</td>
+              <td>failed</td>
+              <td class="count" id="commandFailures">0</td>
+              <td>failed</td>
+            </tr>
+            <tr>
+              <td colspan="2"></td>
+              <td class="count" id="commandErrors">0</td>
+              <td>incomplete</td>
+            </tr>
+          </table>
+
+          <fieldset>
+            <legend>Tools</legend>
+
+            <button type="button" id="domViewer1" onclick="openDomViewer();">
+              View DOM
+            </button>
+            <button type="button" onclick="LOG.show();">
+              Show Log
+            </button>
+
+          </fieldset>
+
+        </td>
+      </tr>
+
+      <!-- AUT -->
+
+      <tr>
+        <td colspan="3" height="70%"><iframe name="myiframe" id="myiframe" src="TestRunner-splash.html"></iframe></td>
+      </tr>
+    </form>
+    </table>
+
+</body>
+</html>


Property changes on: zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta
___________________________________________________________________
Name: svn:executable
   + *

Added: zc.selenium/trunk/src/zc/selenium/resources/TestRunner.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/TestRunner.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/TestRunner.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,148 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium" >
+<!-- the previous line is only relevant if you rename this
+     file to "TestRunner.hta" -->
+
+<!-- The copyright notice and other comments have been moved to after the HTA declaration,
+     to work-around a bug in IE on Win2K whereby the HTA application doesn't function correctly -->
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
+
+<title>Selenium Functional Test Runner</title>
+<link rel="stylesheet" type="text/css" href="selenium.css" />
+<script language="JavaScript" type="text/javascript" src="scripts/html-xpath-patched.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-testrunner.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/xpath.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
+<script language="JavaScript" type="text/javascript">
+    function openDomViewer() {
+        var autFrame = document.getElementById('myiframe');
+        var autFrameDocument = getIframeDocument(autFrame);
+        this.rootDocument = autFrameDocument;
+        var domViewer = window.open('domviewer/domviewer.html');
+        return false;
+    }
+</script>
+</head>
+
+<body onload="start();">
+
+    <table class="layout">
+    <form action="" name="controlPanel">
+
+      <!-- Suite, Test, Control Panel -->
+
+      <tr class="selenium">
+        <td width="25%" height="30%" rowspan="2"><iframe name="testSuiteFrame" id="testSuiteFrame" src="./TestPrompt.html" application="yes"></iframe></td>
+        <td width="50%" height="30%" rowspan="2"><iframe name="testFrame" id="testFrame" application="yes"></iframe></td>
+        <th width="25%" height="1" class="header">
+          <h1><a href="http://selenium.thoughtworks.com" title="The Selenium Project">Selenium</a> TestRunner</h1>
+        </th>
+      </tr>
+
+      <tr class="selenium">
+        <td width="25%" height="30%" id="controlPanel">
+
+          <fieldset>
+            <legend>Execute Tests</legend>
+            
+            <div>
+              <input id="modeRun" type="radio" name="runMode" value="0" checked="checked"/><label for="modeRun">Run</label>
+              <input id="modeWalk" type="radio" name="runMode" value="500" /><label for="modeWalk">Walk</label>
+              <input id="modeStep" type="radio" name="runMode" value="-1" /><label for="modeStep">Step</label>
+            </div>
+            
+            <div>
+              <button type="button" id="runSuite" onclick="startTestSuite();"
+                      title="Run the entire Test-Suite">
+                <strong>All</strong>
+              </button>
+              <button type="button" id="runTest" onclick="runSingleTest();"
+                      title="Run the current Test">
+                <em>Selected</em>
+              </button>
+              <button type="button" id="continueTest" disabled="disabled"
+                      title="Continue the Test">
+                Continue
+              </button>
+            </div>
+            
+          </fieldset>
+
+          <table id="stats" align="center">
+            <tr>
+              <td colspan="2" align="right">Elapsed:</td>
+              <td id="elapsedTime" colspan="2">00.00</td>
+            </tr>
+            <tr>
+              <th colspan="2">Tests</th>
+              <th colspan="2">Commands</th>
+            </tr>
+            <tr>
+              <td class="count" id="testRuns">0</td>
+              <td>run</td>
+              <td class="count" id="commandPasses">0</td>
+              <td>passed</td>
+            </tr>
+            <tr>
+              <td class="count" id="testFailures">0</td>
+              <td>failed</td>
+              <td class="count" id="commandFailures">0</td>
+              <td>failed</td>
+            </tr>
+            <tr>
+              <td colspan="2"></td>
+              <td class="count" id="commandErrors">0</td>
+              <td>incomplete</td>
+            </tr>
+          </table>
+
+          <fieldset>
+            <legend>Tools</legend>
+
+            <button type="button" id="domViewer1" onclick="openDomViewer();">
+              View DOM
+            </button>
+            <button type="button" onclick="LOG.show();">
+              Show Log
+            </button>
+
+          </fieldset>
+
+        </td>
+      </tr>
+
+      <!-- AUT -->
+
+      <tr>
+        <td colspan="3" height="70%"><iframe name="myiframe" id="myiframe" src="TestRunner-splash.html"></iframe></td>
+      </tr>
+    </form>
+    </table>
+
+</body>
+</html>

Added: zc.selenium/trunk/src/zc/selenium/resources/domviewer/butmin.gif
===================================================================
(Binary files differ)


Property changes on: zc.selenium/trunk/src/zc/selenium/resources/domviewer/butmin.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: zc.selenium/trunk/src/zc/selenium/resources/domviewer/butplus.gif
===================================================================
(Binary files differ)


Property changes on: zc.selenium/trunk/src/zc/selenium/resources/domviewer/butplus.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: zc.selenium/trunk/src/zc/selenium/resources/domviewer/domviewer.css
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/domviewer/domviewer.css	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/domviewer/domviewer.css	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,298 @@
+/******************************************************************************
+* Defines default styles for site pages.                                      *
+******************************************************************************/
+.hidden {
+	display: none;
+}
+
+img{
+    display: inline;
+	border: none;
+}
+
+.box{
+	background: #fcfcfc;
+    border: 1px solid #000;
+	border-color: blue;
+    color: #000000;
+	margin: 10px auto;
+    padding: 3px;
+	vertical-align: bottom;
+}
+a {
+  text-decoration: none;
+}
+
+body {
+  background-color: #ffffff;
+  color: #000000;
+  font-family: Arial, Helvetica, sans-serif;
+  font-size: 10pt;
+}
+
+h2 {
+  font-size: 140%;
+}
+
+h3 {
+  font-size: 120%;
+}
+
+h4 {
+  font-size: 100%;
+}
+
+pre {
+  font-family: Courier New, Courier, monospace;
+  font-size: 80%;
+}
+
+td, th {
+  font-family: Arial, Helvetica, sans-serif;
+  font-size: 10pt;
+  text-align: left;
+  vertical-align: top;
+}
+
+th {
+  font-weight: bold;
+  vertical-align: bottom;
+}
+
+ul {
+  list-style-type: square;
+}
+
+#demoBox {
+  border-color: #000000;
+  border-style: solid;
+  border-width: 1px;
+  padding: 8px;
+  width: 24em;
+}
+
+.footer {
+  margin-bottom: 0px;
+  text-align: center;
+}
+
+/* Boxed table styles */
+
+table.boxed {
+  border-spacing: 2px;
+  empty-cells: hide;
+}
+
+td.boxed, th.boxed, th.boxedHeader {
+  background-color: #ffffff;
+  border-color: #000000;
+  border-style: solid;
+  border-width: 1px;
+  color: #000000;
+  padding: 2px;
+  padding-left: 8px;
+  padding-right: 8px;
+}
+
+th.boxed {
+  background-color: #c0c0c0;
+}
+
+th.boxedHeader {
+  background-color: #808080;
+  color: #ffffff;
+}
+
+a.object {
+  color: #0000ff;
+}
+
+li {
+  white-space: nowrap;
+}
+
+ul {
+  list-style-type: square;
+  margin-left: 0px;
+  padding-left: 1em;
+}
+
+.boxlevel1{
+	background: #FFD700;
+}
+
+.boxlevel2{
+	background: #D2691E;
+}
+
+.boxlevel3{
+	background: #DCDCDC;
+}
+
+.boxlevel4{
+	background: #F5F5F5;
+}
+
+.boxlevel5{
+	background: #BEBEBE;
+}
+
+.boxlevel6{
+	background: #D3D3D3;
+}
+
+.boxlevel7{
+	background: #A9A9A9;
+}
+
+.boxlevel8{
+	background: #191970;
+}
+
+.boxlevel9{
+	background: #000080;
+}
+
+.boxlevel10{
+	background: #6495ED;
+}
+
+.boxlevel11{
+	background: #483D8B;
+}
+
+.boxlevel12{
+	background: #6A5ACD;
+}
+
+.boxlevel13{
+	background: #7B68EE;
+}
+
+.boxlevel14{
+	background: #8470FF;
+}
+
+.boxlevel15{
+	background: #0000CD;
+}
+
+.boxlevel16{
+	background: #4169E1;
+}
+
+.boxlevel17{
+	background: #0000FF;
+}
+
+.boxlevel18{
+	background: #1E90FF;
+}
+
+.boxlevel19{
+	background: #00BFFF;
+}
+
+.boxlevel20{
+	background: #87CEEB;
+}
+
+.boxlevel21{
+	background: #B0C4DE;
+}
+
+.boxlevel22{
+	background: #ADD8E6;
+}
+
+.boxlevel23{
+	background: #00CED1;
+}
+
+.boxlevel24{
+	background: #48D1CC;
+}
+
+.boxlevel25{
+	background: #40E0D0;
+}
+
+.boxlevel26{
+	background: #008B8B;
+}
+
+.boxlevel27{
+	background: #00FFFF;
+}
+
+.boxlevel28{
+	background: #E0FFFF;
+}
+
+.boxlevel29{
+	background: #5F9EA0;
+}
+
+.boxlevel30{
+	background: #66CDAA;
+}
+
+.boxlevel31{
+	background: #7FFFD4;
+}
+
+.boxlevel32{
+	background: #006400;
+}
+
+.boxlevel33{
+	background: #556B2F;
+}
+
+.boxlevel34{
+	background: #8FBC8F;
+}
+
+.boxlevel35{
+	background: #2E8B57;
+}
+
+.boxlevel36{
+	background: #3CB371;
+}
+
+.boxlevel37{
+	background: #20B2AA;
+}
+
+.boxlevel38{
+	background: #00FF7F;
+}
+
+.boxlevel39{
+	background: #7CFC00;
+}
+
+.boxlevel40{
+	background: #90EE90;
+}
+
+.boxlevel41{
+	background: #00FF00;
+}
+
+.boxlevel41{
+	background: #7FFF00;
+}
+
+.boxlevel42{
+	background: #00FA9A;
+}
+
+.boxlevel43{
+	background: #ADFF2F;
+}
+
+.boxlevel44{
+	background: #32CD32;
+}
\ No newline at end of file

Added: zc.selenium/trunk/src/zc/selenium/resources/domviewer/domviewer.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/domviewer/domviewer.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/domviewer/domviewer.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+    <head>
+        <title>DOM Viewer</title>
+        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+        <link rel="stylesheet" type="text/css" href="domviewer.css"/>
+        <script type="text/javascript" src="selenium-domviewer.js"></script>
+    </head>
+	<body onload="loadDomViewer();">
+		<h3>DOM Viewer</h3>
+		<p> This page is generated using JavaScript. If you see this text, your 
+			browser doesn't support JavaScript.</p>
+	</body>
+	
+</html>

Added: zc.selenium/trunk/src/zc/selenium/resources/domviewer/selenium-domviewer.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/domviewer/selenium-domviewer.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/domviewer/selenium-domviewer.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,188 @@
+var HIDDEN="hidden";
+var LEVEL = "level";
+var PLUS_SRC="butplus.gif";
+var MIN_SRC="butmin.gif";
+var newRoot;
+var maxColumns=1;
+
+function loadDomViewer() {
+    // See if the rootDocument variable has been set on this window.
+    var rootDocument = window.rootDocument;
+
+    // If not look to the opener for an explicity rootDocument variable, otherwise, use the opener document
+    if (!rootDocument && window.opener) {
+        rootDocument = window.opener.rootDocument || window.opener.document;
+    }
+
+    if (rootDocument) {
+        document.body.innerHTML = displayDOM(rootDocument);
+    }
+    else {
+        document.body.innerHTML = "<b>Must specify rootDocument for window. This can be done by setting the rootDocument variable on this window, or on the opener window for a popup window.</b>";
+    }
+}
+
+
+function displayDOM(root){
+    var str = "";
+    str+="<table>";
+    str += treeTraversal(root,0);
+    // to make table columns work well.
+    str += "<tr>";
+    for (var i=0; i < maxColumns; i++) {
+        str+= "<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
+    }
+    str += "</tr>";
+    str += "</table>";
+    return str;
+}
+
+function checkForChildren(element){
+    if(!element.hasChildNodes())
+        return false;
+    
+    var nodes = element.childNodes;
+    var size = nodes.length;
+    var count=0;
+    
+    for(var i=0; i< size; i++){
+        var node = nodes.item(i);
+        //if(node.toString()=="[object Text]"){
+        //this is equalent to the above
+        //but will work with more browsers
+        if(node.nodeType!=1){
+            count++;
+        }
+    }
+    
+    if(count == size)
+        return false;
+    else
+        return true;
+}
+
+function treeTraversal(root, level){
+    var str = "";
+    var nodes= null;
+    var size = null;
+    //it is supposed to show the last node, 
+    //but the last node is always nodeText type
+    //and we don't show it
+    if(!root.hasChildNodes())
+        return "";//displayNode(root,level,false);
+    
+    nodes = root.childNodes;
+    size = nodes.length;
+
+    for(var i=0; i< size; i++){
+        var element = nodes.item(i);
+        //if the node is textNode, don't display
+        if(element.nodeType==1){
+            str+= displayNode(element,level,checkForChildren(element));
+            str+=treeTraversal(element, level+1);	
+        }
+    }
+    return str;
+}
+
+function displayNode(element, level, isLink){
+    nodeContent = getNodeContent(element);
+    columns = Math.round((nodeContent.length / 12) + 0.5);
+    if (columns + level > maxColumns) {
+        maxColumns = columns + level;
+    }
+    var str ="<tr class='"+LEVEL+level+"'>";
+    for (var i=0; i < level; i++)
+        str+= "<td> </td>";
+    str+="<td colspan='"+ columns +"' class='box"+" boxlevel"+level+"' >";
+    if(isLink){
+        str+='<a onclick="hide(this);return false;" href="javascript:void();">';
+        str+='<img src="'+MIN_SRC+'" />';
+    }
+    str += nodeContent;
+    if(isLink)
+        str+="</a></td></tr>";
+    return str;
+}
+
+function getNodeContent(element) {
+    str = "";
+    id ="";
+    if (element.id != null && element.id != "") {
+        id = " ID(" + element.id +")";
+    }
+    name ="";
+    if (element.name != null && element.name != "") {
+        name = " NAME(" + element.name + ")";
+    }
+    value ="";
+    if (element.value != null && element.value != "") {
+        value = " VALUE(" + element.value + ")";
+    }
+    href ="";
+    if (element.href != null && element.href != "") {
+        href = " HREF(" + element.href + ")";
+    }
+    text ="";
+    if (element.text != null && element.text != "" && element.text != "undefined") {
+        text = " #TEXT(" + trim(element.text) +")";
+    }
+    str+=" <b>"+ element.nodeName + id + name + value + href + text + "</b>";	
+    return str;
+
+}
+
+function trim(val) {
+    val2 = val.substring(0,20) + "                   ";
+    var spaceChr = String.fromCharCode(32);
+    var length = val2.length;
+    var retVal = "";
+    var ix = length -1;
+
+    while(ix > -1){
+        if(val2.charAt(ix) == spaceChr) {
+        } else {
+            retVal = val2.substring(0, ix +1);
+            break;
+        }
+        ix = ix-1;
+    }
+    if (val.length > 20) {
+        retVal += "...";
+    }
+    return retVal;
+}
+
+function hide(hlink){
+    var isHidden = false;
+    var image = hlink.firstChild;
+    if(image.src.toString().indexOf(MIN_SRC)!=-1){
+        image.src=PLUS_SRC;
+        isHidden=true;
+    }else{
+        image.src=MIN_SRC;
+    }
+    var rowObj= hlink.parentNode.parentNode;
+    var rowLevel = parseInt(rowObj.className.substring(LEVEL.length));
+	
+    var sibling = rowObj.nextSibling;
+    var siblingLevel = sibling.className.substring(LEVEL.length);
+    if(siblingLevel.indexOf(HIDDEN)!=-1){
+        siblingLevel = siblingLevel.substring(0,siblingLevel.length - HIDDEN.length-1);
+    }
+    siblingLevel=parseInt(siblingLevel);
+    while(sibling!=null && rowLevel<siblingLevel){
+        if(isHidden){
+            sibling.className += " "+ HIDDEN;
+        }else if(!isHidden && sibling.className.indexOf(HIDDEN)!=-1){
+            var str = sibling.className;
+            sibling.className=str.substring(0, str.length - HIDDEN.length-1);
+        }
+        sibling = sibling.nextSibling;
+        siblingLevel = parseInt(sibling.className.substring(LEVEL.length));
+    }
+}
+
+function LOG(message) {
+    window.opener.LOG.warn(message);
+}

Added: zc.selenium/trunk/src/zc/selenium/resources/iedoc.xml
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/iedoc.xml	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/iedoc.xml	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,545 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<apidoc>
+<top>Defines an object that runs Selenium commands.
+
+<h3><a name="locators"></a>Element Locators</h3>
+<p>
+Element Locators tell Selenium which HTML element a command refers to.
+The format of a locator is:</p>
+<blockquote>
+<em>locatorType</em><strong>=</strong><em>argument</em>
+</blockquote>
+
+<p>
+We support the following strategies for locating elements:
+</p>
+<blockquote>
+<dl>
+<dt><strong>identifier</strong>=<em>id</em></dt>
+<dd>Select the element with the specified &#64;id attribute. If no match is
+found, select the first element whose &#64;name attribute is <em>id</em>.
+(This is normally the default; see below.)</dd>
+<dt><strong>id</strong>=<em>id</em></dt>
+<dd>Select the element with the specified &#64;id attribute.</dd>
+
+<dt><strong>name</strong>=<em>name</em></dt>
+<dd>Select the first element with the specified &#64;name attribute.</dd>
+<dd><ul class="first last simple">
+<li>username</li>
+<li>name=username</li>
+</ul>
+</dd>
+<dd>The name may optionally be followed by one or more <em>element-filters</em>, separated from the name by whitespace.  If the <em>filterType</em> is not specified, <strong>value</strong> is assumed.</dd>
+
+<dd><ul class="first last simple">
+<li>name=flavour value=chocolate</li>
+</ul>
+</dd>
+<dt><strong>dom</strong>=<em>javascriptExpression</em></dt>
+
+<dd>
+
+<dd>Find an element using JavaScript traversal of the HTML Document Object
+Model. DOM locators <em>must</em> begin with &quot;document.&quot;.
+<ul class="first last simple">
+<li>dom=document.forms['myForm'].myDropdown</li>
+<li>dom=document.images[56]</li>
+</ul>
+</dd>
+
+</dd>
+
+<dt><strong>xpath</strong>=<em>xpathExpression</em></dt>
+<dd>Locate an element using an XPath expression.
+<ul class="first last simple">
+<li>xpath=//img[&#64;alt='The image alt text']</li>
+<li>xpath=//table[&#64;id='table1']//tr[4]/td[2]</li>
+
+</ul>
+</dd>
+<dt><strong>link</strong>=<em>textPattern</em></dt>
+<dd>Select the link (anchor) element which contains text matching the
+specified <em>pattern</em>.
+<ul class="first last simple">
+<li>link=The link text</li>
+</ul>
+
+</dd>
+</dl>
+</blockquote>
+<p>
+Without an explicit locator prefix, Selenium uses the following default
+strategies:
+</p>
+
+<ul class="simple">
+<li><strong>dom</strong>, for locators starting with &quot;document.&quot;</li>
+<li><strong>xpath</strong>, for locators starting with &quot;//&quot;</li>
+<li><strong>identifier</strong>, otherwise</li>
+</ul>
+
+<h3><a name="element-filters">Element Filters</a></h3>
+<blockquote>
+<p>Element filters can be used with a locator to refine a list of candidate elements.  They are currently used only in the 'name' element-locator.</p>
+<p>Filters look much like locators, ie.</p>
+<blockquote>
+<em>filterType</em><strong>=</strong><em>argument</em></blockquote>
+
+<p>Supported element-filters are:</p>
+<p><strong>value=</strong><em>valuePattern</em></p>
+<blockquote>
+Matches elements based on their values.  This is particularly useful for refining a list of similarly-named toggle-buttons.</blockquote>
+<p><strong>index=</strong><em>index</em></p>
+<blockquote>
+Selects a single element based on its position in the list (offset from zero).</blockquote>
+</blockquote>
+
+<h3><a name="patterns"></a>String-match Patterns</h3>
+
+<p>
+Various Pattern syntaxes are available for matching string values:
+</p>
+<blockquote>
+<dl>
+<dt><strong>glob:</strong><em>pattern</em></dt>
+<dd>Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
+kind of limited regular-expression syntax typically used in command-line
+shells. In a glob pattern, "*" represents any sequence of characters, and "?"
+represents any single character. Glob patterns match against the entire
+string.</dd>
+<dt><strong>regexp:</strong><em>regexp</em></dt>
+<dd>Match a string using a regular-expression. The full power of JavaScript
+regular-expressions is available.</dd>
+<dt><strong>exact:</strong><em>string</em></dt>
+
+<dd>Match a string exactly, verbatim, without any of that fancy wildcard
+stuff.</dd>
+</dl>
+</blockquote>
+<p>
+If no pattern prefix is specified, Selenium assumes that it's a "glob"
+pattern.
+</p></top>
+<function name="click">
+<param name="locator">an element locator</param>
+<comment>Clicks on a link, button, checkbox or radio button. If the click action
+causes a new page to load (like a link usually does), call
+waitForPageToLoad.</comment>
+</function>
+<function name="fireEvent">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<param name="eventName">the event name, e.g. "focus" or "blur"</param>
+<comment>Explicitly simulate an event, to trigger the corresponding &quot;on<em>event</em>&quot;
+handler.</comment>
+</function>
+<function name="keyPress">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<param name="keycode">the numeric keycode of the key to be pressed, normally the
            ASCII value of that key.</param>
+<comment>Simulates a user pressing and releasing a key.</comment>
+</function>
+<function name="keyDown">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<param name="keycode">the numeric keycode of the key to be pressed, normally the
            ASCII value of that key.</param>
+<comment>Simulates a user pressing a key (without releasing it yet).</comment>
+</function>
+<function name="keyUp">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<param name="keycode">the numeric keycode of the key to be released, normally the
            ASCII value of that key.</param>
+<comment>Simulates a user releasing a key.</comment>
+</function>
+<function name="mouseOver">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Simulates a user hovering a mouse over the specified element.</comment>
+</function>
+<function name="mouseDown">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.</comment>
+</function>
+<function name="type">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<param name="value">the value to type</param>
+<comment>Sets the value of an input field, as though you typed it in.
+
+<p>Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
+value should be the value of the option selected, not the visible text.</p></comment>
+</function>
+<function name="check">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Check a toggle-button (checkbox/radio)</comment>
+</function>
+<function name="uncheck">
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Uncheck a toggle-button (checkbox/radio)</comment>
+</function>
+<function name="select">
+<param name="locator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+<param name="optionLocator">an option locator (a label by default)</param>
+<comment>Select an option from a drop-down using an option locator.
+
+<p>
+Option locators provide different ways of specifying options of an HTML
+Select element (e.g. for selecting a specific option, or for asserting
+that the selected option satisfies a specification). There are several
+forms of Select Option Locator.
+</p>
+<dl>
+<dt><strong>label</strong>=<em>labelPattern</em></dt>
+<dd>matches options based on their labels, i.e. the visible text. (This
+is the default.)
+<ul class="first last simple">
+<li>label=regexp:^[Oo]ther</li>
+</ul>
+</dd>
+<dt><strong>value</strong>=<em>valuePattern</em></dt>
+<dd>matches options based on their values.
+<ul class="first last simple">
+<li>value=other</li>
+</ul>
+
+
+</dd>
+<dt><strong>id</strong>=<em>id</em></dt>
+
+<dd>matches options based on their ids.
+<ul class="first last simple">
+<li>id=option1</li>
+</ul>
+</dd>
+<dt><strong>index</strong>=<em>index</em></dt>
+<dd>matches an option based on its index (offset from zero).
+<ul class="first last simple">
+
+<li>index=2</li>
+</ul>
+</dd>
+</dl>
+<p>
+If no option locator prefix is provided, the default behaviour is to match on <strong>label</strong>.
+</p></comment>
+</function>
+<function name="addSelection">
+<param name="locator">an <a href="#locators">element locator</a> identifying a multi-select box</param>
+<param name="optionLocator">an option locator (a label by default)</param>
+<comment>Add a selection to the set of selected options in a multi-select element using an option locator.
+
+ at see #doSelect for details of option locators</comment>
+</function>
+<function name="removeSelection">
+<param name="locator">an <a href="#locators">element locator</a> identifying a multi-select box</param>
+<param name="optionLocator">an option locator (a label by default)</param>
+<comment>Remove a selection from the set of selected options in a multi-select element using an option locator.
+
+ at see #doSelect for details of option locators</comment>
+</function>
+<function name="submit">
+<param name="formLocator">an <a href="#locators">element locator</a> for the form you want to submit</param>
+<comment>Submit the specified form. This is particularly useful for forms without
+submit buttons, e.g. single-input "Search" forms.</comment>
+</function>
+<function name="open">
+<param name="url">the URL to open; may be relative or absolute</param>
+<comment>Opens an URL in the test frame. This accepts both relative and absolute
+URLs.
+
+The &quot;open&quot; command waits for the page to load before proceeding,
+ie. the &quot;AndWait&quot; suffix is implicit.
+
+<em>Note</em>: The URL must be on the same domain as the runner HTML
+due to security restrictions in the browser (Same Origin Policy). If you
+need to open an URL on another domain, use the Selenium Server to start a
+new browser session on that domain.</comment>
+</function>
+<function name="selectWindow">
+<param name="windowID">the JavaScript window ID of the window to select</param>
+<comment>Selects a popup window; once a popup window has been selected, all
+commands go to that window. To select the main window again, use "null"
+as the target.</comment>
+</function>
+<function name="waitForPopUp">
+<param name="windowID">the JavaScript window ID of the window that will appear</param>
+<param name="timeout">a timeout in milliseconds, after which the action will return with an error</param>
+<comment>Waits for a popup window to appear and load up.</comment>
+</function>
+<function name="chooseCancelOnNextConfirmation">
+<comment>By default, Selenium's overridden window.confirm() function will
+return true, as if the user had manually clicked OK.  After running
+this command, the next call to confirm() will return false, as if
+the user had clicked Cancel.</comment>
+</function>
+<function name="answerOnNextPrompt">
+<param name="answer">the answer to give in response to the prompt pop-up</param>
+<comment>Instructs Selenium to return the specified answer string in response to
+the next JavaScript prompt [window.prompt()].</comment>
+</function>
+<function name="goBack">
+<comment>Simulates the user clicking the "back" button on their browser.</comment>
+</function>
+<function name="refresh">
+<comment>Simulates the user clicking the "Refresh" button on their browser.</comment>
+</function>
+<function name="close">
+<comment>Simulates the user clicking the "close" button in the titlebar of a popup
+window or tab.</comment>
+</function>
+<function name="isAlertPresent">
+<return type="boolean">true if there is an alert</return>
+<comment>Has an alert occurred?
+
+<p>
+This function never throws an exception
+</p></comment>
+</function>
+<function name="isPromptPresent">
+<return type="boolean">true if there is a pending prompt</return>
+<comment>Has a prompt occurred?
+
+<p>
+This function never throws an exception
+</p></comment>
+</function>
+<function name="isConfirmationPresent">
+<return type="boolean">true if there is a pending confirmation</return>
+<comment>Has confirm() been called?
+
+<p>
+This function never throws an exception
+</p></comment>
+</function>
+<function name="getAlert">
+<return type="string">The message of the most recent JavaScript alert</return>
+<comment>Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
+
+<p>Getting an alert has the same effect as manually clicking OK. If an
+alert is generated but you do not get/verify it, the next Selenium action
+will fail.</p>
+
+<p>NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
+dialog.</p>
+
+<p>NOTE: Selenium does NOT support JavaScript alerts that are generated in a
+page's onload() event handler. In this case a visible dialog WILL be
+generated and Selenium will hang until someone manually clicks OK.</p></comment>
+</function>
+<function name="getConfirmation">
+<return type="string">the message of the most recent JavaScript confirmation dialog</return>
+<comment>Retrieves the message of a JavaScript confirmation dialog generated during
+the previous action.
+
+<p>
+By default, the confirm function will return true, having the same effect
+as manually clicking OK. This can be changed by prior execution of the
+chooseCancelOnNextConfirmation command. If an confirmation is generated
+but you do not get/verify it, the next Selenium action will fail.
+</p>
+
+<p>
+NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
+dialog.
+</p>
+
+<p>
+NOTE: Selenium does NOT support JavaScript confirmations that are
+generated in a page's onload() event handler. In this case a visible
+dialog WILL be generated and Selenium will hang until you manually click
+OK.
+</p></comment>
+</function>
+<function name="getPrompt">
+<return type="string">the message of the most recent JavaScript question prompt</return>
+<comment>Retrieves the message of a JavaScript question prompt dialog generated during
+the previous action.
+
+<p>Successful handling of the prompt requires prior execution of the
+answerOnNextPrompt command. If a prompt is generated but you
+do not get/verify it, the next Selenium action will fail.</p>
+
+<p>NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
+dialog.</p>
+
+<p>NOTE: Selenium does NOT support JavaScript prompts that are generated in a
+page's onload() event handler. In this case a visible dialog WILL be
+generated and Selenium will hang until someone manually clicks OK.</p></comment>
+</function>
+<function name="getAbsoluteLocation">
+<return type="string">the absolute URL of the current page</return>
+<comment>Gets the absolute URL of the current page.</comment>
+</function>
+<function name="isLocation">
+<return type="boolean">true if the location matches, false otherwise</return>
+<param name="expectedLocation">the location to match</param>
+<comment>Verify the location of the current page ends with the expected location.
+If an URL querystring is provided, this is checked as well.</comment>
+</function>
+<function name="getTitle">
+<return type="string">the title of the current page</return>
+<comment>Gets the title of the current page.</comment>
+</function>
+<function name="getBodyText">
+<return type="string">the entire text of the page</return>
+<comment>Gets the entire text of the page.</comment>
+</function>
+<function name="getValue">
+<return type="string">the element value, or "on/off" for checkbox/radio elements</return>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
+For checkbox/radio elements, the value will be "on" or "off" depending on
+whether the element is checked or not.</comment>
+</function>
+<function name="getText">
+<return type="string">the text of the element</return>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Gets the text of an element. This works for any element that contains
+text. This command uses either the textContent (Mozilla-like browsers) or
+the innerText (IE-like browsers) of the element, which is the rendered
+text shown to the user.</comment>
+</function>
+<function name="getEval">
+<return type="string">the results of evaluating the snippet</return>
+<param name="script">the JavaScript snippet to run</param>
+<comment>Gets the result of evaluating the specified JavaScript snippet.  The snippet may 
+have multiple lines, but only the result of the last line will be returned.
+
+<p>Note that, by default, the snippet will run in the context of the "selenium"
+object itself, so <code>this</code> will refer to the Selenium object, and <code>window</code> will
+refer to the top-level runner test window, not the window of your application.</p>
+
+<p>If you need a reference to the window of your application, you can refer
+to <code>this.browserbot.getCurrentWindow()</code> and if you need to use
+a locator to refer to a single element in your application page, you can
+use <code>this.page().findElement("foo")</code> where "foo" is your locator.</p></comment>
+</function>
+<function name="getChecked">
+<return type="string">either "true" or "false" depending on whether the checkbox is checked</return>
+<param name="locator">an <a href="#locators">element locator</a> pointing to a checkbox or radio button</param>
+<comment>Gets whether a toggle-button (checkbox/radio) is checked.  Fails if the specified element doesn't exist or isn't a toggle-button.</comment>
+</function>
+<function name="getTable">
+<return type="string">the text from the specified cell</return>
+<param name="tableCellAddress">a cell address, e.g. "foo.1.4"</param>
+<comment>Gets the text from a cell of a table. The cellAddress syntax
+tableLocator.row.column, where row and column start at 0.</comment>
+</function>
+<function name="isSelected">
+<return type="boolean">true if the selected option matches the locator, false otherwise</return>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<param name="optionLocator">an option locator, typically just an option label (e.g. "John Smith")</param>
+<comment>Verifies that the selected option of a drop-down satisfies the optionSpecifier.
+
+<p>See the select command for more information about option locators.</p></comment>
+</function>
+<function name="getSelectedOptions">
+<return type="string[]">an array of all option labels in the specified select drop-down</return>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Gets all option labels for selected options in the specified select or multi-select element.</comment>
+</function>
+<function name="getSelectOptions">
+<return type="string[]">an array of all option labels in the specified select drop-down</return>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Gets all option labels in the specified select drop-down.</comment>
+</function>
+<function name="getAttribute">
+<return type="string">the value of the specified attribute</return>
+<param name="attributeLocator">an element locator followed by an</param>
+<comment>Gets the value of an element attribute.</comment>
+</function>
+<function name="isTextPresent">
+<return type="boolean">true if the pattern matches the text, false otherwise</return>
+<param name="pattern">a <a href="#patterns">pattern</a> to match with the text of the page</param>
+<comment>Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.</comment>
+</function>
+<function name="isElementPresent">
+<return type="boolean">true if the element is present, false otherwise</return>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Verifies that the specified element is somewhere on the page.</comment>
+</function>
+<function name="isVisible">
+<return type="boolean">true if the specified element is visible, false otherwise</return>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Determines if the specified element is visible. An
+element can be rendered invisible by setting the CSS "visibility"
+property to "hidden", or the "display" property to "none", either for the
+element itself or one if its ancestors.  This method will fail if
+the element is not present.</comment>
+</function>
+<function name="isEditable">
+<return type="boolean">true if the input element is editable, false otherwise</return>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<comment>Determines whether the specified input element is editable, ie hasn't been disabled.
+This method will fail if the specified element isn't an input element.</comment>
+</function>
+<function name="getAllButtons">
+<return type="string[]">the IDs of all buttons on the page</return>
+<comment>Returns the IDs of all buttons on the page.
+
+<p>If a given button has no ID, it will appear as "" in this array.</p></comment>
+</function>
+<function name="getAllLinks">
+<return type="string[]">the IDs of all links on the page</return>
+<comment>Returns the IDs of all links on the page.
+
+<p>If a given link has no ID, it will appear as "" in this array.</p></comment>
+</function>
+<function name="getAllFields">
+<return type="string[]">the IDs of all field on the page</return>
+<comment>Returns the IDs of all input fields on the page.
+
+<p>If a given field has no ID, it will appear as "" in this array.</p></comment>
+</function>
+<function name="getHtmlSource">
+<return type="string">the entire HTML source</return>
+<comment>Returns the entire HTML source between the opening and
+closing "html" tags.</comment>
+</function>
+<function name="setContext">
+<param name="context">the message to be sent to the browser</param>
+<param name="logLevelThreshold">one of "debug", "info", "warn", "error", sets the threshold for browser-side logging</param>
+<comment>Writes a message to the status bar and adds a note to the browser-side
+log.
+
+<p>If logLevelThreshold is specified, set the threshold for logging
+to that level (debug, info, warn, error).</p>
+
+<p>(Note that the browser-side logs will <i>not</i> be sent back to the
+server, and are invisible to the Client Driver.)</p></comment>
+</function>
+<function name="getExpression">
+<return type="string">the value passed in</return>
+<param name="expression">the value to return</param>
+<comment>Returns the specified expression.
+
+<p>This is useful because of JavaScript preprocessing.
+It is used to generate commands like assertExpression and storeExpression.</p></comment>
+</function>
+<function name="waitForCondition">
+<param name="script">the JavaScript snippet to run</param>
+<param name="timeout">a timeout in milliseconds, after which this command will return with an error</param>
+<comment>Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
+The snippet may have multiple lines, but only the result of the last line
+will be considered.
+
+<p>Note that, by default, the snippet will be run in the runner's test window, not in the window
+of your application.  To get the window of your application, you can use
+the JavaScript snippet <code>selenium.browserbot.getCurrentWindow()</code>, and then
+run your JavaScript in there</p></comment>
+</function>
+<function name="setTimeout">
+<param name="timeout">a timeout in milliseconds, after which the action will return with an error</param>
+<comment>Specifies the amount of time that Selenium will wait for actions to complete.
+
+<p>Actions that require waiting include "open" and the "waitFor*" actions.</p>
+The default timeout is 30 seconds.</comment>
+</function>
+<function name="waitForPageToLoad">
+<param name="timeout">a timeout in milliseconds, after which this command will return with an error</param>
+<comment>Waits for a new page to load.
+
+<p>You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
+(which are only available in the JS API).</p>
+
+<p>Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
+flag when it first notices a page load.  Running any other Selenium command after
+turns the flag to false.  Hence, if you want to wait for a page to load, you must
+wait immediately after a Selenium command that caused a page-load.</p></comment>
+</function>
+</apidoc>

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/html-xpath-patched.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/html-xpath-patched.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/html-xpath-patched.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,660 @@
+/*
+	html-xpath, an implementation of DOM Level 3 XPath for Internet Explorer 5+
+	Copyright (C) 2004 Dimitri Glazkov
+
+	This library is free software; you can redistribute it and/or
+	modify it under the terms of the GNU Lesser General Public
+	License as published by the Free Software Foundation; either
+	version 2.1 of the License, or (at your option) any later version.
+
+	This library is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+	Lesser General Public License for more details.
+
+	You should have received a copy of the GNU Lesser General Public
+	License along with this library; if not, write to the Free Software
+
+*/
+
+/** SELENIUM:PATCH TO ALLOW USE WITH DOCUMENTS FROM OTHER WINDOWS: 2004-11-24
+    TODO resubmit this to http://sf.net/projects/html-xpath */
+function addXPathSupport(document) {
+/** END SELENIUM:PATCH */
+
+var isIe = /MSIE [56789]/.test(navigator.userAgent) && (navigator.platform == "Win32");
+
+// Mozilla has support by default, we don't have an implementation for the rest
+if (isIe)
+{
+	// release number
+	document.DomL3XPathRelease = "0.0.3.0";
+	
+	// XPathException
+	// An Error object will be thrown, this is just a handler to instantiate that object
+	var XPathException = new _XPathExceptionHandler();
+	function _XPathExceptionHandler()
+	{
+		this.INVALID_EXPRESSION_ERR = 51;
+		this.TYPE_ERR = 52;
+		this.NOT_IMPLEMENTED_ERR = -1;
+		this.RUNTIME_ERR = -2;
+		
+		this.ThrowNotImplemented = function(message)
+		{
+			ThrowError(this.NOT_IMPLEMENTED_ERR, "This functionality is not implemented.", message);
+		}
+		
+		this.ThrowInvalidExpression = function(message)
+		{
+			ThrowError(this.INVALID_EXPRESSION_ERR, "Invalid expression", message);
+		}
+		
+		this.ThrowType = function(message)
+		{
+			ThrowError(this.TYPE_ERR, "Type error", message);
+		}
+		
+		this.Throw = function(message)
+		{
+			ThrowError(this.RUNTIME_ERR, "Run-time error", message);
+		}
+		
+		function ThrowError(code, description, message)
+		{
+			var error = new Error(code, "DOM-L3-XPath " + document.DomL3XPathRelease + ": " + description + (message ? ", \"" + message  + "\"": ""));
+			error.code = code;
+			error.name = "XPathException";
+			throw error;
+		}
+	}
+	
+	// DOMException
+	// An Error object will be thrown, this is just a handler to instantiate that object
+	var DOMException = new _DOMExceptionHandler();
+	function _DOMExceptionHandler()
+	{
+		this.ThrowInvalidState = function(message)
+		{
+			ThrowError(13, "The state of the object is no longer valid", message);
+		}
+
+		function ThrowError(code, description, message)
+		{
+			var error = new Error(code, "DOM : " + description + (message ? ", \"" + message  + "\"": ""));
+			error.code = code;
+			error.name = "DOMException";
+			throw error;
+		}
+	}
+
+	// XPathEvaluator 
+	// implemented as document object methods
+	
+	// XPathExpression createExpression(String expression, XPathNSResolver resolver)
+	document.createExpression = function
+		(
+		expression,		// String
+		resolver		// XPathNSResolver
+		)
+	{
+		// returns XPathExpression object
+		return new XPathExpression(expression, resolver);
+	}
+
+	// XPathNSResolver createNSResolver(nodeResolver)
+	document.createNSResolver = function
+		(
+		nodeResolver	// Node
+		)
+	{
+		// returns XPathNSResolver
+		return new XPathNSResolver(nodeResolver);
+	}
+
+	// XPathResult evaluate(String expresison, Node contextNode, XPathNSResolver resolver, Number type, XPathResult result)
+	document.evaluate = function
+		(
+		expression,		// String
+		contextNode,	// Node
+		resolver,		// XPathNSResolver
+		type,			// Number
+		result			// XPathResult
+		)
+		// can raise XPathException, DOMException
+	{
+		// return XPathResult
+		return document.createExpression(expression, resolver).evaluate(contextNode, type, result);
+	}
+
+	// XPathExpression
+	function XPathExpression
+	(
+		expression, // String
+		resolver // XPathNSResolver
+	)
+	{
+		this.expressionString = expression;
+		this.resolver = resolver;
+
+		// XPathResult evaluate(Node contextNode, Number type, XPathResult result)
+		this.evaluate = function
+		(
+			contextNode, // Node
+			type, // Number
+			result // XPathResult		
+		)
+			// raises XPathException, DOMException
+		{
+			// return XPathResult
+			return (result && result.constructor == XPathResult ? result.initialize(this, contextNode, resolver, type) : new XPathResult(this, contextNode, resolver, type));
+		}
+		
+		this.toString = function()
+		{
+			return "[XPathExpression]";
+		}
+	}
+
+	// XPathNSResolver
+	function XPathNSResolver(node)
+	{
+		this.node = node;
+	
+		// String lookupNamespaceURI(String prefix)
+		this.lookupNamespaceURI = function
+			(
+			prefix			// String
+			)
+		{
+			XPathException.ThrowNotImplemented();
+			// return String
+			return null;
+		}
+
+		this.toString = function()
+		{
+			return "[XPathNSResolver]";
+		}
+	}
+
+	// XPathResult
+	XPathResult.ANY_TYPE = 0;
+	XPathResult.NUMBER_TYPE = 1;
+	XPathResult.STRING_TYPE = 2;
+	XPathResult.BOOLEAN_TYPE = 3;
+	XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4;
+	XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5;
+	XPathResult.UNORDERED_SNAPSHOT_TYPE = 6;
+	XPathResult.ORDERED_SNAPSHOT_TYPE = 7;
+	XPathResult.ANY_UNORDERED_NODE_TYPE = 8;
+	XPathResult.FIRST_ORDERED_NODE_TYPE = 9;
+	
+	function XPathResult
+			(
+			expression,		// XPathExpression
+			contextNode,	// Node
+			resolver,		// XPathNSResolver
+			type			// Number
+			)
+	{
+		this.initialize = function(expression, contextNode, resolver, type)
+		{
+			this._domResult = null;
+			this._expression = expression;
+			this._contextNode = contextNode;
+			this._resolver = resolver;
+			if (type)
+			{
+				this.resultType = type;
+				this._isIterator = (type == XPathResult.UNORDERED_NODE_ITERATOR_TYPE || 
+					type == XPathResult.ORDERED_NODE_ITERATOR_TYPE || 
+					type == XPathResult.ANY_TYPE);
+				this._isSnapshot = (type == XPathResult.UNORDERED_SNAPSHOT_TYPE || type == XPathResult.ORDERED_SNAPSHOT_TYPE);
+				this._isNodeSet = type > XPathResult.BOOLEAN_TYPE;
+			}
+			else
+			{
+				this.resultType = XPathResult.ANY_TYPE;
+				this._isIterator = true;
+				this._isSnapshot = false;
+				this._isNodeSet = true;
+			}
+			return this;
+		}
+		
+		this.initialize(expression, contextNode, resolver, type);
+		
+		this.getInvalidIteratorState = function()
+		{
+			return documentChangeDetected() || !this._isIterator;
+		}
+		
+		this.getSnapshotLength = function()
+			// raises XPathException
+		{
+			if (!this._isSnapshot)
+			{
+				XPathException.ThrowType("Snapshot is not an expected result type");
+			}
+			activateResult(this);
+			// return Number
+			return this._domResult.length;
+		}
+		
+		// Node iterateNext()
+		this.iterateNext = function()
+			// raises XPathException, DOMException
+		{
+			if (!this._isIterator)
+			{
+				XPathException.ThrowType("Iterator is not an expected result type");
+			}
+			activateResult(this);
+			if (documentChangeDetected())
+			{
+				DOMException.ThrowInvalidState("iterateNext");
+			}
+			// return Node
+			return getNextNode(this);
+		}
+		
+		// Node snapshotItem(Number index)
+		this.snapshotItem = function(index)
+			// raises XPathException
+		{
+			if (!this._isSnapshot)
+			{
+				XPathException.ThrowType("Snapshot is not an expected result type");
+			}
+			// return Node
+			return getItemNode(this, index); 
+		}
+		
+		this.toString = function()
+		{
+			return "[XPathResult]";
+		}
+		
+		// returns string value of the result, if result type is STRING_TYPE
+		// otherwise throws an XPathException
+		this.getStringValue = function()
+		{
+			if (this.resultType != XPathResult.STRING_TYPE)
+			{
+				XPathException.ThrowType("The expression can not be converted to return String");
+			}
+			return getNodeText(this);
+		}
+		
+		// returns number value of the result, if the result is NUMBER_TYPE
+		// otherwise throws an XPathException
+		this.getNumberValue = function()
+		{
+			if (this.resultType != XPathResult.NUMBER_TYPE)
+			{
+				XPathException.ThrowType("The expression can not be converted to return Number");
+			}
+			var number = parseInt(getNodeText(this));
+			if (isNaN(number))
+			{
+				XPathException.ThrowType("The result can not be converted to Number");
+			}
+			return number;
+		}
+		
+		// returns boolean value of the result, if the result is BOOLEAN_TYPE
+		// otherwise throws an XPathException
+		this.getBooleanValue = function()
+		{
+			if (this.resultType != XPathResult.BOOLEAN_TYPE)
+			{
+				XPathException.ThrowType("The expression can not be converted to return Boolean");
+			}
+			
+			var	
+				text = getNodeText(this);
+				bool = (text ? text.toLowerCase() : null);
+			if (bool == "false" || bool == "true")
+			{
+				return bool;
+			}
+			XPathException.ThrowType("The result can not be converted to Boolean");
+		}
+		
+		// returns single node, if the result is ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE
+		// otherwise throws an XPathException
+		this.getSingleNodeValue = function()
+		{
+			if (this.resultType != XPathResult.ANY_UNORDERED_NODE_TYPE && 
+				this.resultType != XPathResult.FIRST_ORDERED_NODE_TYPE)
+			{
+				XPathException.ThrowType("The expression can not be converted to return single Node value");
+			}
+			return getSingleNode(this);
+		}
+		
+		function documentChangeDetected()
+		{
+			return document._XPathMsxmlDocumentHelper.documentChangeDetected();
+		}
+		
+		function getNodeText(result)
+		{
+			activateResult(result);
+			return result._textResult;
+//			return ((node = getSingleNode(result)) ? (node.nodeType == 1 ? node.innerText : node.nodeValue) : null);
+		}
+		
+		function findNode(result, current)
+		{
+			switch(current.nodeType)
+			{
+				case 1: // NODE_ELEMENT
+					var id = current.attributes.getNamedItem("id");
+					if (id)
+					{
+						return document.getElementById(id.value);
+					}
+					XPathException.Throw("unable to locate element in XML tree");
+				case 2: // NODE_ATTRIBUTE
+					var id = current.selectSingleNode("..").attributes.getNamedItem("id");
+					if (id)
+					{
+						var node = document.getElementById(id.text);
+						if (node)
+						{
+							return node.attributes.getNamedItem(current.nodeName);
+						}
+					}
+					XPathException.Throw("unable to locate attribute in XML tree");
+				case 3: // NODE_TEXT
+					var id = current.selectSingleNode("..").attributes.getNamedItem("id");
+					if (id)
+					{
+						var node = document.getElementById(id.value);
+						if (node)
+						{
+							for(child in node.childNodes)
+							{
+								if (child.nodeType == 3 && child.nodeValue == current.nodeValue)
+								{
+									return child;
+								}
+							}
+						}
+					}
+					XPathException.Throw("unable to locate text in XML tree");
+			}
+			XPathException.Throw("unknown node type");
+		}
+		
+		function activateResult(result)
+		{
+			if (!result._domResult)
+			{
+				try
+				{
+					var expression = result._expression.expressionString;
+					
+					// adjust expression if contextNode is not a document
+					if (result._contextNode != document && expression.indexOf("//") != 0)
+					{
+
+						expression = "//*[@id = '" + result._contextNode.id + "']" +
+							(expression.indexOf("/") == 0 ? "" : "/") + expression;
+					}
+					
+					if (result._isNodeSet)
+					{
+						result._domResult = document._XPathMsxmlDocumentHelper.getDom().selectNodes(expression);
+					}
+					else
+					{
+						result._domResult = true;
+						result._textResult = document._XPathMsxmlDocumentHelper.getTextResult(expression);
+					}
+					
+				}
+				catch(error)
+				{
+					alert(error.description);
+					XPathException.ThrowInvalidExpression(error.description);
+				}
+			}
+		}
+
+		function getSingleNode(result)
+		{
+			var node = getItemNode(result, 0);
+			result._domResult = null;
+			return node;
+		}
+		
+		function getItemNode(result, index)
+		{
+			activateResult(result);
+			var current = result._domResult.item(index);
+			return (current ? findNode(result, current) : null);
+		}
+		
+		function getNextNode(result)
+		{
+			var current = result._domResult.nextNode;
+			if (current)
+			{
+				return findNode(result, current);
+			}
+			result._domResult = null;
+			return null;
+		}
+	}
+	
+	document.reloadDom = function()
+	{
+		document._XPathMsxmlDocumentHelper.reset();
+	}
+
+	document._XPathMsxmlDocumentHelper = new _XPathMsxmlDocumentHelper();
+	function _XPathMsxmlDocumentHelper()
+	{
+		this.getDom = function()
+		{
+			activateDom(this);
+			return this.dom;
+		}
+		
+		this.getXml = function()
+		{
+			activateDom(this);
+			return this.dom.xml;
+		}
+		
+		this.getTextResult = function(expression)
+		{
+			expression = expression.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "\"");
+			var xslText = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
+				"<xsl:output method=\"text\"/><xsl:template match=\"*\"><xsl:value-of select=\"" + expression + "\"/>" +
+				"</xsl:template></xsl:stylesheet>";
+			var xsl = new ActiveXObject("Msxml2.DOMDocument");
+			xsl.loadXML(xslText);
+			try
+			{
+				var result = this.getDom().transformNode(xsl);
+			}
+			catch(error)
+			{
+				alert("Error: " + error.description);
+			}
+			return result;
+		}
+		
+		this.reset = function()
+		{
+			this.dom = null;
+		}
+		
+		function onPropertyChangeEventHandler()
+		{
+			document._propertyChangeDetected = true;
+		}
+		
+		this.documentChangeDetected = function()
+		{
+			return (document.ignoreDocumentChanges ? false : this._currentElementCount != document.all.length || document._propertyChangeDetected);
+		}
+		
+		function activateDom(helper)
+		{
+			if (!helper.dom)
+			{
+				var dom = new ActiveXObject("Msxml2.DOMDocument");
+/** SELENIUM:PATCH TO ALLOW PROVIDE FULL XPATH SUPPORT */
+				dom.setProperty("SelectionLanguage", "XPath");
+/** END SELENIUM:PATCH */
+				dom.async = false;
+				dom.resolveExternals = false;
+				loadDocument(dom, helper);
+				helper.dom = dom;
+				helper._currentElementCount = document.all.length;
+				document._propertyChangeDetected = false;
+			}
+			else
+			{
+				if (helper.documentChangeDetected())
+				{
+					var dom = helper.dom;
+					dom.load("");
+					loadDocument(dom, helper);
+					helper._currentElementCount = document.all.length;
+					document._propertyChangeDetected = false;
+				}
+			}
+		}
+		
+		function loadDocument(dom, helper)
+		{
+			return loadNode(dom, dom, document.body, helper);
+		}
+			
+
+/** SELENIUM:PATCH for loadNode() - see SEL-68 */
+		function loadNode(dom, domParentNode, node, helper)
+		{
+			// Bad node scenarios
+			// 1. If the node contains a /, it's broken HTML
+			// 2. If the node doesn't have a name (typically from broken HTML), the node can't be loaded
+			// 3. Node types we can't deal with
+			//
+			// In all scenarios, we just skip the node. We won't be able to
+			// query on these nodes, but they're broken anyway.
+			if (node.nodeName.indexOf("/") > -1
+			    || node.nodeName == ""
+			    || node.nodeName == "#document"
+			    || node.nodeName == "#document-fragment"
+			    || node.nodeName == "#cdata-section"
+			    || node.nodeName == "#xml-declaration"
+			    || node.nodeName == "#whitespace"
+			    || node.nodeName == "#significat-whitespace"
+			   )
+			{
+				return;
+			}
+			
+			// #comment is a <!-- comment -->, which must be created with createComment()
+			if (node.nodeName == "#comment")
+			{
+				try
+				{
+					domParentNode.appendChild(dom.createComment(node.nodeValue));
+				}
+				catch (ex)
+				{
+					// it's just a comment, we don't care
+				}
+			}
+			else if (node.nodeType == 3)
+			{
+				domParentNode.appendChild(dom.createTextNode(node.nodeValue));
+			}
+			else
+			{
+				var domNode = dom.createElement(node.nodeName.toLowerCase());
+				if (!node.id)
+				{
+					node.id = node.uniqueID;
+				}
+				domParentNode.appendChild(domNode);
+				loadAttributes(dom, domNode, node);
+				var length = node.childNodes.length;
+				for(var i = 0; i < length; i ++ )
+				{
+					loadNode(dom, domNode, node.childNodes[i], helper);
+				}
+				node.attachEvent("onpropertychange", onPropertyChangeEventHandler);
+			}
+		}
+/** END SELENIUM:PATCH */
+
+		function loadAttributes(dom, domParentNode, node)
+		{
+			for (var i = 0; i < node.attributes.length; i ++ )
+			{
+				var attribute = node.attributes[i];
+				var attributeValue = attribute.nodeValue;
+				
+/** SELENIUM:PATCH for loadAttributes() - see SEL-176 */
+				if (attributeValue && (attribute.specified || attribute.nodeName == 'value'))
+/** END SELENIUM:PATCH */
+				{
+					var domAttribute = dom.createAttribute(attribute.nodeName);
+					domAttribute.value = attributeValue;
+					domParentNode.setAttributeNode(domAttribute);				
+				}
+			}
+		}
+	
+	}
+}
+else
+{
+	document.reloadDom = function() {}
+	XPathResult.prototype.getStringValue = function()
+	{
+		return this.stringValue;
+	}
+	
+	XPathResult.prototype.getNumberValue = function()
+	{
+		return this.numberValue;
+	}
+	
+	XPathResult.prototype.getBooleanValue = function()
+	{
+		return this.booleanValue;
+	}
+	
+	XPathResult.prototype.getSingleNodeValue = function()
+	{
+		return this.singleNodeValue;	
+	}
+	
+	XPathResult.prototype.getInvalidIteratorState = function()
+	{
+		return this.invalidIteratorState;
+	}
+	
+	XPathResult.prototype.getSnapshotLength = function()
+	{
+		return this.snapshotLength;
+	}
+	
+	XPathResult.prototype.getResultType = function()
+	{
+		return this.resultType;
+	}
+}
+/** SELENIUM:PATCH TO ALLOW USE WITH CONTAINED DOCUMENTS */
+}
+/** END SELENIUM:PATCH */
+

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/htmlutils.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/htmlutils.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/htmlutils.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,426 @@
+/*
+ * Copyright 2004 ThoughtWorks, Inc
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+ 
+// This script contains some HTML utility functions that
+// make it possible to handle elements in a way that is 
+// compatible with both IE-like and Mozilla-like browsers
+
+String.prototype.trim = function() {
+  var result = this.replace( /^\s+/g, "" );// strip leading
+  return result.replace( /\s+$/g, "" );// strip trailing
+};
+String.prototype.lcfirst = function() {
+   return this.charAt(0).toLowerCase() + this.substr(1);
+};
+String.prototype.ucfirst = function() {
+   return this.charAt(0).toUpperCase() + this.substr(1);
+};
+String.prototype.startsWith = function(str) {
+    return this.indexOf(str) == 0;
+};
+
+// Returns the text in this element
+function getText(element) {
+    text = "";
+
+    if(browserVersion.isFirefox)
+    {
+        var dummyElement = element.cloneNode(true);
+        renderWhitespaceInTextContent(dummyElement);
+        text = dummyElement.textContent;
+    }
+    else if(element.textContent)
+    {
+        text = element.textContent;
+    }
+    else if(element.innerText)
+    {
+        text = element.innerText;
+    }
+
+    text = normalizeNewlines(text);
+    text = normalizeSpaces(text);
+
+    return text.trim();
+}
+
+function renderWhitespaceInTextContent(element) {
+    // Remove non-visible newlines in text nodes
+    if (element.nodeType == Node.TEXT_NODE)
+    {
+        element.data = element.data.replace(/\n|\r/g, " ");
+        return;
+    }
+
+    // Don't modify PRE elements
+    if (element.tagName == "PRE")
+    {
+        return;
+    }
+
+    // Handle inline element that force newlines
+    if (tagIs(element, ["BR", "HR"]))
+    {
+        // Replace this element with a newline text element
+        element.parentNode.replaceChild(document.createTextNode("\n"), element)
+    }
+
+    for (var i = 0; i < element.childNodes.length; i++)
+    {
+        var child = element.childNodes.item(i)
+        renderWhitespaceInTextContent(child);
+    }
+
+    // Handle block elements that introduce newlines
+// -- From HTML spec:
+//<!ENTITY % block
+//     "P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
+//      BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">
+    if (tagIs(element, ["P", "DIV"]))
+    {
+        element.appendChild(document.createTextNode("\n"), element)
+    }
+}
+
+function tagIs(element, tags)
+{
+    var tag = element.tagName;
+    for (var i = 0; i < tags.length; i++)
+    {
+        if (tags[i] == tag)
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
+/**
+ * Convert all newlines to \m
+ */
+function normalizeNewlines(text)
+{
+    return text.replace(/\r\n|\r/g, "\n");
+}
+
+/**
+ * Replace multiple sequential spaces with a single space, and then convert &nbsp; to space.
+ */
+function normalizeSpaces(text)
+{
+    // IE has already done this conversion, so doing it again will remove multiple nbsp
+    if (browserVersion.isIE)
+    {
+        return text;
+    }
+
+    // Replace multiple spaces with a single space
+    // TODO - this shouldn't occur inside PRE elements
+    text = text.replace(/\ +/g, " ");
+
+    // Replace &nbsp; with a space
+    var pat = String.fromCharCode(160); // Opera doesn't like /\240/g
+   	var re = new RegExp(pat, "g");
+    return text.replace(re, " ");
+}
+
+// Sets the text in this element
+function setText(element, text) {
+    if(element.textContent) {
+        element.textContent = text;
+    } else if(element.innerText) {
+        element.innerText = text;
+    }
+}
+
+// Get the value of an <input> element
+function getInputValue(inputElement) {
+    if (inputElement.type.toUpperCase() == 'CHECKBOX' || 
+        inputElement.type.toUpperCase() == 'RADIO') 
+    {
+        return (inputElement.checked ? 'on' : 'off');
+    }
+    return inputElement.value;
+}
+
+/* Fire an event in a browser-compatible manner */
+function triggerEvent(element, eventType, canBubble) {
+    canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
+    if (element.fireEvent) {
+        element.fireEvent('on' + eventType);
+    }
+    else {
+        var evt = document.createEvent('HTMLEvents');
+        evt.initEvent(eventType, canBubble, true);
+        element.dispatchEvent(evt);
+    }
+}
+
+function triggerKeyEvent(element, eventType, keycode, canBubble) {
+    canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
+    if (element.fireEvent) {
+		keyEvent = parent.frames['myiframe'].document.createEventObject();
+		keyEvent.keyCode=keycode;
+		element.fireEvent('on' + eventType, keyEvent);
+    }
+    else {
+        var evt = document.createEvent('KeyEvents');
+        evt.initKeyEvent(eventType, true, true, window, false, false, false, false, keycode, keycode);
+        element.dispatchEvent(evt);
+    }
+}
+
+/* Fire a mouse event in a browser-compatible manner */
+function triggerMouseEvent(element, eventType, canBubble) {
+    canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
+    if (element.fireEvent) {
+        element.fireEvent('on' + eventType);
+    }
+    else {
+        var evt = document.createEvent('MouseEvents');
+        if (evt.initMouseEvent)
+        {
+            evt.initMouseEvent(eventType, canBubble, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null)
+        }
+        else
+        {
+            // Safari
+            // TODO we should be initialising other mouse-event related attributes here
+            evt.initEvent(eventType, canBubble, true);
+        }
+        element.dispatchEvent(evt);
+    }
+}
+
+function removeLoadListener(element, command) {
+    if (window.removeEventListener)
+        element.removeEventListener("load", command, true);
+    else if (window.detachEvent)
+        element.detachEvent("onload", command);
+}
+
+function addLoadListener(element, command) {
+    if (window.addEventListener && !browserVersion.isOpera)
+        element.addEventListener("load",command, true);
+    else if (window.attachEvent)
+        element.attachEvent("onload",command);
+}
+
+function addUnloadListener(element, command) {
+    if (window.addEventListener)
+        element.addEventListener("unload",command, true);
+    else if (window.attachEvent)
+        element.attachEvent("onunload",command);
+}
+
+/**
+ * Override the broken getFunctionName() method from JsUnit
+ * This file must be loaded _after_ the jsunitCore.js
+ */
+function getFunctionName(aFunction) {
+  var regexpResult = aFunction.toString().match(/function (\w*)/);
+  if (regexpResult && regexpResult[1]) {
+      return regexpResult[1];
+  }
+  return 'anonymous';
+}
+
+function describe(object, delimiter) {
+    var props = new Array();
+    for (var prop in object) {
+        props.push(prop + " -> " + object[prop]);
+    }
+    return props.join(delimiter || '\n');
+}
+
+PatternMatcher = function(pattern) {
+    this.selectStrategy(pattern);
+};
+PatternMatcher.prototype = {
+
+    selectStrategy: function(pattern) {
+        this.pattern = pattern;
+        var strategyName = 'glob'; // by default
+        if (/^([a-z-]+):(.*)/.test(pattern)) {
+            strategyName = RegExp.$1;
+            pattern = RegExp.$2;
+        }
+        var matchStrategy = PatternMatcher.strategies[strategyName];
+        if (!matchStrategy) {
+            throw new SeleniumError("cannot find PatternMatcher.strategies." + strategyName);
+        }
+        this.strategy = matchStrategy;
+        this.matcher = new matchStrategy(pattern);
+    },
+
+    matches: function(actual) {
+        return this.matcher.matches(actual + '');
+        // Note: appending an empty string avoids a Konqueror bug
+    }
+
+};
+
+/**
+ * A "static" convenience method for easy matching
+ */
+PatternMatcher.matches = function(pattern, actual) {
+    return new PatternMatcher(pattern).matches(actual);
+};
+
+PatternMatcher.strategies = {
+
+    /**
+     * Exact matching, e.g. "exact:***"
+     */
+    exact: function(expected) {
+        this.expected = expected;
+        this.matches = function(actual) {
+            return actual == this.expected;
+        };
+    },
+
+    /**
+     * Match by regular expression, e.g. "regexp:^[0-9]+$"
+     */
+    regexp: function(regexpString) {
+        this.regexp = new RegExp(regexpString);
+        this.matches = function(actual) {
+            return this.regexp.test(actual);
+        };
+    },
+
+    /**
+     * "globContains" (aka "wildmat") patterns, e.g. "glob:one,two,*", 
+     * but don't require a perfect match; instead succeed if actual
+     * contains something that matches globString.
+     * Making this distinction is motivated by a bug in IE6 which 
+     * leads to the browser hanging if we implement *TextPresent tests 
+     * by just matching against a regular expression beginning and 
+     * ending with ".*".  The globcontains strategy allows us to satisfy 
+     * the functional needs of the *TextPresent ops more efficiently 
+     * and so avoid running into this IE6 freeze.
+     */
+    globContains: function(globString) {
+        this.regexp = new RegExp(PatternMatcher.regexpFromGlobContains(globString));
+        this.matches = function(actual) {
+            return this.regexp.test(actual);
+        };
+    },
+    
+
+    /**
+     * "glob" (aka "wildmat") patterns, e.g. "glob:one,two,*"
+     */
+    glob: function(globString) {
+        this.regexp = new RegExp(PatternMatcher.regexpFromGlob(globString));
+        this.matches = function(actual) {
+            return this.regexp.test(actual);
+        };
+    }
+    
+};
+
+PatternMatcher.convertGlobMetaCharsToRegexpMetaChars = function(glob) {
+    var re = glob;
+    re = re.replace(/([.^$+(){}\[\]\\|])/g, "\\$1");
+    re = re.replace(/\?/g, "(.|[\r\n])");
+    re = re.replace(/\*/g, "(.|[\r\n])*");
+    return re;
+};
+
+PatternMatcher.regexpFromGlobContains = function(globContains) {
+    return PatternMatcher.convertGlobMetaCharsToRegexpMetaChars(globContains);
+};
+
+PatternMatcher.regexpFromGlob = function(glob) {
+    return "^" + PatternMatcher.convertGlobMetaCharsToRegexpMetaChars(glob) + "$";
+};
+
+var Assert = {
+
+    fail: function(message) {
+        throw new AssertionFailedError(message);
+    },
+
+    /*
+     * Assert.equals(comment?, expected, actual)
+     */
+    equals: function() {
+        var args = new AssertionArguments(arguments);
+        if (args.expected === args.actual) {
+            return;
+        }
+        Assert.fail(args.comment + 
+                    "Expected '" + args.expected + 
+                    "' but was '" + args.actual + "'");
+    },
+
+    /*
+     * Assert.matches(comment?, pattern, actual)
+     */
+    matches: function() {
+        var args = new AssertionArguments(arguments);
+        if (PatternMatcher.matches(args.expected, args.actual)) {
+            return;
+        }
+        Assert.fail(args.comment + 
+                    "Actual value '" + args.actual + 
+                    "' did not match '" + args.expected + "'");
+    },
+    
+    /*
+     * Assert.notMtches(comment?, pattern, actual)
+     */
+    notMatches: function() {
+        var args = new AssertionArguments(arguments);
+        if (!PatternMatcher.matches(args.expected, args.actual)) {
+            return;
+        }
+        Assert.fail(args.comment + 
+                    "Actual value '" + args.actual + 
+                    "' did match '" + args.expected + "'");
+    }
+
+};
+
+// Preprocess the arguments to allow for an optional comment.
+function AssertionArguments(args) {
+    if (args.length == 2) {
+        this.comment = "";
+        this.expected = args[0];
+        this.actual = args[1];
+    } else {
+        this.comment = args[0] + "; ";
+        this.expected = args[1];
+        this.actual = args[2];
+    }
+}
+
+
+
+function AssertionFailedError(message) {
+    this.isAssertionFailedError = true;
+    this.isSeleniumError = true;
+    this.message = message;
+    this.failureMessage = message;
+}
+
+function SeleniumError(message) {
+    var error = new Error(message);
+    error.isSeleniumError = true;
+    return error;
+};

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-api.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-api.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-api.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,1239 @@
+/*
+ * Copyright 2004 ThoughtWorks, Inc
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+storedVars = new Object();
+
+function Selenium(browserbot) {
+	/**
+	 * Defines an object that runs Selenium commands.
+	 * 
+	 * <h3><a name="locators"></a>Element Locators</h3>
+	 * <p>
+	 * Element Locators tell Selenium which HTML element a command refers to.
+	 * The format of a locator is:</p>
+	 * <blockquote>
+	 * <em>locatorType</em><strong>=</strong><em>argument</em>
+	 * </blockquote>
+	 * 
+	 * <p>
+	 * We support the following strategies for locating elements:
+	 * </p>
+	 * <blockquote>
+	 * <dl>
+	 * <dt><strong>identifier</strong>=<em>id</em></dt>
+	 * <dd>Select the element with the specified &#64;id attribute. If no match is
+	 * found, select the first element whose &#64;name attribute is <em>id</em>.
+	 * (This is normally the default; see below.)</dd>
+	 * <dt><strong>id</strong>=<em>id</em></dt>
+	 * <dd>Select the element with the specified &#64;id attribute.</dd>
+	 * 
+	 * <dt><strong>name</strong>=<em>name</em></dt>
+	 * <dd>Select the first element with the specified &#64;name attribute.</dd>
+	 * <dd><ul class="first last simple">
+	 * <li>username</li>
+	 * <li>name=username</li>
+	 * </ul>
+	 * </dd>
+	 * <dd>The name may optionally be followed by one or more <em>element-filters</em>, separated from the name by whitespace.  If the <em>filterType</em> is not specified, <strong>value</strong> is assumed.</dd>
+	 * 
+	 * <dd><ul class="first last simple">
+	 * <li>name=flavour value=chocolate</li>
+	 * </ul>
+	 * </dd>
+	 * <dt><strong>dom</strong>=<em>javascriptExpression</em></dt>
+	 * 
+	 * <dd>
+	 * 
+	 * <dd>Find an element using JavaScript traversal of the HTML Document Object
+	 * Model. DOM locators <em>must</em> begin with &quot;document.&quot;.
+	 * <ul class="first last simple">
+	 * <li>dom=document.forms['myForm'].myDropdown</li>
+	 * <li>dom=document.images[56]</li>
+	 * </ul>
+	 * </dd>
+	 * 
+	 * </dd>
+	 * 
+	 * <dt><strong>xpath</strong>=<em>xpathExpression</em></dt>
+	 * <dd>Locate an element using an XPath expression.
+	 * <ul class="first last simple">
+	 * <li>xpath=//img[&#64;alt='The image alt text']</li>
+	 * <li>xpath=//table[&#64;id='table1']//tr[4]/td[2]</li>
+	 * 
+	 * </ul>
+	 * </dd>
+	 * <dt><strong>link</strong>=<em>textPattern</em></dt>
+	 * <dd>Select the link (anchor) element which contains text matching the
+	 * specified <em>pattern</em>.
+	 * <ul class="first last simple">
+	 * <li>link=The link text</li>
+	 * </ul>
+	 * 
+	 * </dd>
+	 * </dl>
+	 * </blockquote>
+	 * <p>
+	 * Without an explicit locator prefix, Selenium uses the following default
+	 * strategies:
+	 * </p>
+	 * 
+	 * <ul class="simple">
+	 * <li><strong>dom</strong>, for locators starting with &quot;document.&quot;</li>
+	 * <li><strong>xpath</strong>, for locators starting with &quot;//&quot;</li>
+	 * <li><strong>identifier</strong>, otherwise</li>
+	 * </ul>
+	 *
+	 * <h3><a name="element-filters">Element Filters</a></h3>
+	 * <blockquote>
+	 * <p>Element filters can be used with a locator to refine a list of candidate elements.  They are currently used only in the 'name' element-locator.</p>
+	 * <p>Filters look much like locators, ie.</p>
+	 * <blockquote>
+	 * <em>filterType</em><strong>=</strong><em>argument</em></blockquote>
+	 * 
+	 * <p>Supported element-filters are:</p>
+	 * <p><strong>value=</strong><em>valuePattern</em></p>
+	 * <blockquote>
+	 * Matches elements based on their values.  This is particularly useful for refining a list of similarly-named toggle-buttons.</blockquote>
+	 * <p><strong>index=</strong><em>index</em></p>
+	 * <blockquote>
+	 * Selects a single element based on its position in the list (offset from zero).</blockquote>
+	 * </blockquote>
+	 *
+	 * <h3><a name="patterns"></a>String-match Patterns</h3>
+	 * 
+	 * <p>
+	 * Various Pattern syntaxes are available for matching string values:
+	 * </p>
+	 * <blockquote>
+	 * <dl>
+	 * <dt><strong>glob:</strong><em>pattern</em></dt>
+	 * <dd>Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
+	 * kind of limited regular-expression syntax typically used in command-line
+	 * shells. In a glob pattern, "*" represents any sequence of characters, and "?"
+	 * represents any single character. Glob patterns match against the entire
+	 * string.</dd>
+	 * <dt><strong>regexp:</strong><em>regexp</em></dt>
+	 * <dd>Match a string using a regular-expression. The full power of JavaScript
+	 * regular-expressions is available.</dd>
+	 * <dt><strong>exact:</strong><em>string</em></dt>
+	 * 
+	 * <dd>Match a string exactly, verbatim, without any of that fancy wildcard
+	 * stuff.</dd>
+	 * </dl>
+	 * </blockquote>
+	 * <p>
+	 * If no pattern prefix is specified, Selenium assumes that it's a "glob"
+	 * pattern.
+	 * </p>
+	 */
+    this.browserbot = browserbot;
+    this.optionLocatorFactory = new OptionLocatorFactory();
+    this.page = function() {
+        return browserbot.getCurrentPage();
+    };
+}
+
+Selenium.createForFrame = function(frame) {
+    return new Selenium(BrowserBot.createForFrame(frame));
+};
+
+Selenium.prototype.reset = function() {
+	/**
+   * Clear out all stored variables and select the null (starting) window
+   */
+    storedVars = new Object();
+    this.browserbot.selectWindow("null");
+};
+
+Selenium.prototype.doClick = function(locator) {
+	/**
+   * Clicks on a link, button, checkbox or radio button. If the click action
+   * causes a new page to load (like a link usually does), call
+   * waitForPageToLoad.
+   * 
+   * @param locator an element locator
+   * 
+   */
+    var element = this.page().findElement(locator);
+    this.page().clickElement(element);
+};
+
+Selenium.prototype.doFireEvent = function(locator, eventName) {
+	/**
+   * Explicitly simulate an event, to trigger the corresponding &quot;on<em>event</em>&quot;
+   * handler.
+   *
+   * @param locator an <a href="#locators">element locator</a>
+   * @param eventName the event name, e.g. "focus" or "blur"
+   */
+    var element = this.page().findElement(locator);
+    triggerEvent(element, eventName, false);
+};
+
+Selenium.prototype.doKeyPress = function(locator, keycode) {
+	/**
+   * Simulates a user pressing and releasing a key.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @param keycode the numeric keycode of the key to be pressed, normally the
+   *            ASCII value of that key.
+   */
+    var element = this.page().findElement(locator);
+    triggerKeyEvent(element, 'keypress', keycode, true);
+};
+
+Selenium.prototype.doKeyDown = function(locator, keycode) {
+	/**
+   * Simulates a user pressing a key (without releasing it yet).
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @param keycode the numeric keycode of the key to be pressed, normally the
+   *            ASCII value of that key.
+   */
+    var element = this.page().findElement(locator);
+    triggerKeyEvent(element, 'keydown', keycode, true);
+};
+
+Selenium.prototype.doKeyUp = function(locator, keycode) {
+	/**
+   * Simulates a user releasing a key.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @param keycode the numeric keycode of the key to be released, normally the
+   *            ASCII value of that key.
+   */
+    var element = this.page().findElement(locator);
+    triggerKeyEvent(element, 'keyup', keycode, true);
+};
+
+Selenium.prototype.doMouseOver = function(locator) {
+	/**
+   * Simulates a user hovering a mouse over the specified element.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   */
+    var element = this.page().findElement(locator);
+    triggerMouseEvent(element, 'mouseover', true);
+};
+
+Selenium.prototype.doMouseDown = function(locator) {
+	/**
+   * Simulates a user pressing the mouse button (without releasing it yet) on
+   * the specified element.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   */
+    var element = this.page().findElement(locator);
+    triggerMouseEvent(element, 'mousedown', true);
+};
+
+Selenium.prototype.doType = function(locator, value) {
+	/**
+   * Sets the value of an input field, as though you typed it in.
+   * 
+   * <p>Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
+   * value should be the value of the option selected, not the visible text.</p>
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @param value the value to type
+   */
+		// TODO fail if it can't be typed into.
+    var element = this.page().findElement(locator);
+    this.page().replaceText(element, value);
+};
+
+Selenium.prototype.findToggleButton = function(locator) {
+    var element = this.page().findElement(locator);
+    if (element.checked == null) {
+        Assert.fail("Element " + locator + " is not a toggle-button.");
+    }
+    return element;
+}
+
+Selenium.prototype.doCheck = function(locator) {
+	/**
+   * Check a toggle-button (checkbox/radio)
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   */
+    this.findToggleButton(locator).checked = true;
+};
+
+Selenium.prototype.doUncheck = function(locator) {
+	/**
+   * Uncheck a toggle-button (checkbox/radio)
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   */
+    this.findToggleButton(locator).checked = false;
+};
+
+Selenium.prototype.doSelect = function(locator, optionLocator) {
+	/**
+   * Select an option from a drop-down using an option locator.
+   * 
+   * <p>
+   * Option locators provide different ways of specifying options of an HTML
+   * Select element (e.g. for selecting a specific option, or for asserting
+   * that the selected option satisfies a specification). There are several
+   * forms of Select Option Locator.
+   * </p>
+   * <dl>
+   * <dt><strong>label</strong>=<em>labelPattern</em></dt>
+   * <dd>matches options based on their labels, i.e. the visible text. (This
+   * is the default.)
+   * <ul class="first last simple">
+   * <li>label=regexp:^[Oo]ther</li>
+   * </ul>
+   * </dd>
+   * <dt><strong>value</strong>=<em>valuePattern</em></dt>
+   * <dd>matches options based on their values.
+   * <ul class="first last simple">
+   * <li>value=other</li>
+   * </ul>
+   * 
+   * 
+   * </dd>
+   * <dt><strong>id</strong>=<em>id</em></dt>
+   * 
+   * <dd>matches options based on their ids.
+   * <ul class="first last simple">
+   * <li>id=option1</li>
+   * </ul>
+   * </dd>
+   * <dt><strong>index</strong>=<em>index</em></dt>
+   * <dd>matches an option based on its index (offset from zero).
+   * <ul class="first last simple">
+   * 
+   * <li>index=2</li>
+   * </ul>
+   * </dd>
+   * </dl>
+   * <p>
+   * If no option locator prefix is provided, the default behaviour is to match on <strong>label</strong>.
+   * </p>
+   * 
+   * 
+   * @param locator an <a href="#locators">element locator</a> identifying a drop-down menu
+   * @param optionLocator an option locator (a label by default)
+   */
+    var element = this.page().findElement(locator);
+    if (!("options" in element)) {
+        throw new SeleniumError("Specified element is not a Select (has no options)");
+    }
+    var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
+    var option = locator.findOption(element);
+    this.page().selectOption(element, option);
+};
+
+Selenium.prototype.doAddSelection = function(locator, optionLocator) {
+    /**
+   * Add a selection to the set of selected options in a multi-select element using an option locator.
+   *
+   * @see #doSelect for details of option locators
+   *
+   * @param locator an <a href="#locators">element locator</a> identifying a multi-select box
+   * @param optionLocator an option locator (a label by default)
+   */
+    var element = this.page().findElement(locator);
+    if (!("options" in element)) {
+        throw new SeleniumError("Specified element is not a Select (has no options)");
+    }
+    var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
+    var option = locator.findOption(element);
+    this.page().addSelection(element, option);
+};
+
+Selenium.prototype.doRemoveSelection = function(locator, optionLocator) {
+    /**
+   * Remove a selection from the set of selected options in a multi-select element using an option locator.
+   *
+   * @see #doSelect for details of option locators
+   *
+   * @param locator an <a href="#locators">element locator</a> identifying a multi-select box
+   * @param optionLocator an option locator (a label by default)
+   */
+
+    var element = this.page().findElement(locator);
+    if (!("options" in element)) {
+        throw new SeleniumError("Specified element is not a Select (has no options)");
+    }
+    var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
+    var option = locator.findOption(element);
+    this.page().removeSelection(element, option);
+};
+
+Selenium.prototype.doSubmit = function(formLocator) {
+	/**
+   * Submit the specified form. This is particularly useful for forms without
+   * submit buttons, e.g. single-input "Search" forms.
+   * 
+   * @param formLocator an <a href="#locators">element locator</a> for the form you want to submit
+   */
+    var form = this.page().findElement(formLocator);
+    var actuallySubmit = true;
+    if (form.onsubmit) {
+    	// apply this to the correct window so alerts are properly handled, even in IE HTA mode
+    	actuallySubmit = form.onsubmit.apply(this.browserbot.getContentWindow());
+    }
+    if (actuallySubmit) {
+        form.submit();
+    }
+    
+};
+
+Selenium.prototype.doOpen = function(url) {
+	/**
+   * Opens an URL in the test frame. This accepts both relative and absolute
+   * URLs.
+   * 
+   * The &quot;open&quot; command waits for the page to load before proceeding,
+   * ie. the &quot;AndWait&quot; suffix is implicit.
+   *
+   * <em>Note</em>: The URL must be on the same domain as the runner HTML
+   * due to security restrictions in the browser (Same Origin Policy). If you
+   * need to open an URL on another domain, use the Selenium Server to start a
+   * new browser session on that domain.
+   * 
+   * @param url the URL to open; may be relative or absolute
+   */
+    this.browserbot.openLocation(url);
+    return SELENIUM_PROCESS_WAIT;
+};
+
+Selenium.prototype.doSelectWindow = function(windowID) {
+	/**
+   * Selects a popup window; once a popup window has been selected, all
+   * commands go to that window. To select the main window again, use "null"
+   * as the target.
+   * 
+   * @param windowID the JavaScript window ID of the window to select
+   */
+    this.browserbot.selectWindow(windowID);
+};
+
+Selenium.prototype.doWaitForPopUp = function(windowID, timeout) {
+	/**
+	* Waits for a popup window to appear and load up.
+	*
+	* @param windowID the JavaScript window ID of the window that will appear
+	* @param timeout a timeout in milliseconds, after which the action will return with an error
+	*/
+	if (isNaN(timeout)) {
+    	throw new SeleniumError("Timeout is not a number: " + timeout);
+    }
+    
+    testLoop.waitForCondition = function () {
+        var targetWindow = selenium.browserbot.getTargetWindow(windowID);
+        if (!targetWindow) return false;
+        if (!targetWindow.location) return false;
+        if ("about:blank" == targetWindow.location) return false;
+        if (!targetWindow.document) return false;
+        if (!targetWindow.document.readyState) return true;
+        if ('complete' != targetWindow.document.readyState) return false;
+        return true;
+    };
+    
+    testLoop.waitForConditionStart = new Date().getTime();
+    testLoop.waitForConditionTimeout = timeout;
+	
+}
+
+Selenium.prototype.doChooseCancelOnNextConfirmation = function() {
+	/**
+   * By default, Selenium's overridden window.confirm() function will
+   * return true, as if the user had manually clicked OK.  After running
+   * this command, the next call to confirm() will return false, as if
+   * the user had clicked Cancel.
+   * 
+   */
+    this.browserbot.cancelNextConfirmation();
+};
+
+
+Selenium.prototype.doAnswerOnNextPrompt = function(answer) {
+	/**
+   * Instructs Selenium to return the specified answer string in response to
+   * the next JavaScript prompt [window.prompt()].
+   * 
+   * 
+   * @param answer the answer to give in response to the prompt pop-up
+   */
+    this.browserbot.setNextPromptResult(answer);
+};
+
+Selenium.prototype.doGoBack = function() {
+    /**
+     * Simulates the user clicking the "back" button on their browser.
+     * 
+     */
+    this.page().goBack();
+};
+
+Selenium.prototype.doRefresh = function() {
+    /**
+     * Simulates the user clicking the "Refresh" button on their browser.
+     * 
+     */
+    this.page().refresh();
+};
+
+Selenium.prototype.doClose = function() {
+	/**
+   * Simulates the user clicking the "close" button in the titlebar of a popup
+   * window or tab.
+   */
+    this.page().close();
+};
+
+Selenium.prototype.isAlertPresent = function() {
+   /**
+   * Has an alert occurred?
+   * 
+   * <p>
+   * This function never throws an exception
+   * </p>
+   * @return boolean true if there is an alert
+   */
+    return this.browserbot.hasAlerts();
+};
+Selenium.prototype.isPromptPresent = function() {
+   /**
+   * Has a prompt occurred?
+   * 
+   * <p>
+   * This function never throws an exception
+   * </p>
+   * @return boolean true if there is a pending prompt
+   */
+    return this.browserbot.hasPrompts();
+};
+Selenium.prototype.isConfirmationPresent = function() {
+   /**
+   * Has confirm() been called?
+   * 
+   * <p>
+   * This function never throws an exception
+   * </p>
+   * @return boolean true if there is a pending confirmation
+   */
+    return this.browserbot.hasConfirmations();
+};
+Selenium.prototype.getAlert = function() {
+	/**
+   * Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
+   * 
+   * <p>Getting an alert has the same effect as manually clicking OK. If an
+   * alert is generated but you do not get/verify it, the next Selenium action
+   * will fail.</p>
+   * 
+   * <p>NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
+   * dialog.</p>
+   * 
+   * <p>NOTE: Selenium does NOT support JavaScript alerts that are generated in a
+   * page's onload() event handler. In this case a visible dialog WILL be
+   * generated and Selenium will hang until someone manually clicks OK.</p>
+   * @return string The message of the most recent JavaScript alert
+   */
+    if (!this.browserbot.hasAlerts()) {
+        Assert.fail("There were no alerts");
+    }
+    return this.browserbot.getNextAlert();
+};
+Selenium.prototype.getAlert.dontCheckAlertsAndConfirms = true;
+
+Selenium.prototype.getConfirmation = function() {
+	/**
+   * Retrieves the message of a JavaScript confirmation dialog generated during
+   * the previous action.
+   * 
+   * <p>
+   * By default, the confirm function will return true, having the same effect
+   * as manually clicking OK. This can be changed by prior execution of the
+   * chooseCancelOnNextConfirmation command. If an confirmation is generated
+   * but you do not get/verify it, the next Selenium action will fail.
+   * </p>
+   * 
+   * <p>
+   * NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
+   * dialog.
+   * </p>
+   * 
+   * <p>
+   * NOTE: Selenium does NOT support JavaScript confirmations that are
+   * generated in a page's onload() event handler. In this case a visible
+   * dialog WILL be generated and Selenium will hang until you manually click
+   * OK.
+   * </p>
+   * 
+   * @return string the message of the most recent JavaScript confirmation dialog
+   */
+    if (!this.browserbot.hasConfirmations()) {
+        Assert.fail("There were no confirmations");
+    }
+    return this.browserbot.getNextConfirmation();
+};
+Selenium.prototype.getConfirmation.dontCheckAlertsAndConfirms = true;
+ 
+Selenium.prototype.getPrompt = function() {
+	/**
+   * Retrieves the message of a JavaScript question prompt dialog generated during
+   * the previous action.
+   * 
+   * <p>Successful handling of the prompt requires prior execution of the
+   * answerOnNextPrompt command. If a prompt is generated but you
+   * do not get/verify it, the next Selenium action will fail.</p>
+   * 
+   * <p>NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
+   * dialog.</p>
+   * 
+   * <p>NOTE: Selenium does NOT support JavaScript prompts that are generated in a
+   * page's onload() event handler. In this case a visible dialog WILL be
+   * generated and Selenium will hang until someone manually clicks OK.</p>
+   * @return string the message of the most recent JavaScript question prompt
+   */
+    if (! this.browserbot.hasPrompts()) {
+        Assert.fail("There were no prompts");
+    }
+    return this.browserbot.getNextPrompt();
+};
+
+Selenium.prototype.getAbsoluteLocation = function() {
+	/** Gets the absolute URL of the current page.
+   * 
+   * @return string the absolute URL of the current page
+   */
+    return this.page().location;
+};
+
+Selenium.prototype.isLocation = function(expectedLocation) {
+	/**
+   * Verify the location of the current page ends with the expected location.
+   * If an URL querystring is provided, this is checked as well.
+   * @param expectedLocation the location to match
+   * @return boolean true if the location matches, false otherwise
+   */
+    var docLocation = this.page().location;
+    var actualPath = docLocation.pathname;
+    if (docLocation.protocol == "file:") {
+    	// replace backslashes with forward slashes, so IE can run off the file system
+    	var actualPath = docLocation.pathname.replace(/\\/g, "/");
+    }
+    var searchPos = expectedLocation.lastIndexOf('?');
+
+    if (searchPos == -1) {
+    	return PatternMatcher.matches('*' + expectedLocation, actualPath)
+    }
+    else {
+        var expectedPath = expectedLocation.substring(0, searchPos);
+        return PatternMatcher.matches('*' + expectedPath, actualPath)
+
+        var expectedQueryString = expectedLocation.substring(searchPos);
+        return PatternMatcher.matches(expectedQueryString, docLocation.search)
+    }
+};
+
+Selenium.prototype.getTitle = function() {
+	/** Gets the title of the current page.
+   * 
+   * @return string the title of the current page
+   */
+    return this.page().title();
+};
+
+
+Selenium.prototype.getBodyText = function() {
+	/**
+	 * Gets the entire text of the page.
+	 * @return string the entire text of the page
+	 */
+    return this.page().bodyText();
+};
+
+
+Selenium.prototype.getValue = function(locator) {
+  /**
+   * Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
+   * For checkbox/radio elements, the value will be "on" or "off" depending on
+   * whether the element is checked or not.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @return string the element value, or "on/off" for checkbox/radio elements
+   */
+    var element = this.page().findElement(locator)
+    return getInputValue(element).trim();
+}
+
+Selenium.prototype.getText = function(locator) {
+	/**
+   * Gets the text of an element. This works for any element that contains
+   * text. This command uses either the textContent (Mozilla-like browsers) or
+   * the innerText (IE-like browsers) of the element, which is the rendered
+   * text shown to the user.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @return string the text of the element
+   */
+    var element = this.page().findElement(locator);
+    return getText(element).trim();
+};
+
+Selenium.prototype.getEval = function(script) {
+	/** Gets the result of evaluating the specified JavaScript snippet.  The snippet may 
+   * have multiple lines, but only the result of the last line will be returned.
+   * 
+   * <p>Note that, by default, the snippet will run in the context of the "selenium"
+   * object itself, so <code>this</code> will refer to the Selenium object, and <code>window</code> will
+   * refer to the top-level runner test window, not the window of your application.</p>
+   *
+   * <p>If you need a reference to the window of your application, you can refer
+   * to <code>this.browserbot.getCurrentWindow()</code> and if you need to use
+   * a locator to refer to a single element in your application page, you can
+   * use <code>this.page().findElement("foo")</code> where "foo" is your locator.</p>
+   * 
+   * @param script the JavaScript snippet to run
+   * @return string the results of evaluating the snippet
+   */
+    try {
+    	return eval(script);
+    } catch (e) {
+    	throw new SeleniumError("Threw an exception: " + e.message);
+    }
+};
+
+Selenium.prototype.getChecked = function(locator) {
+	/**
+   * Gets whether a toggle-button (checkbox/radio) is checked.  Fails if the specified element doesn't exist or isn't a toggle-button.
+   * @param locator an <a href="#locators">element locator</a> pointing to a checkbox or radio button
+   * @return string either "true" or "false" depending on whether the checkbox is checked
+   */
+    var element = this.page().findElement(locator);
+    if (element.checked == null) {
+        throw new SeleniumError("Element " + locator + " is not a toggle-button.");
+    }
+    return element.checked;
+};
+
+Selenium.prototype.getTable = function(tableCellAddress) {
+	/**
+   * Gets the text from a cell of a table. The cellAddress syntax
+   * tableLocator.row.column, where row and column start at 0.
+   * 
+   * @param tableCellAddress a cell address, e.g. "foo.1.4"
+   * @return string the text from the specified cell
+   */
+    // This regular expression matches "tableName.row.column"
+    // For example, "mytable.3.4"
+    pattern = /(.*)\.(\d+)\.(\d+)/;
+
+    if(!pattern.test(tableCellAddress)) {
+        throw new SeleniumError("Invalid target format. Correct format is tableName.rowNum.columnNum");
+    }
+
+    pieces = tableCellAddress.match(pattern);
+
+    tableName = pieces[1];
+    row = pieces[2];
+    col = pieces[3];
+
+    var table = this.page().findElement(tableName);
+    if (row > table.rows.length) {
+        Assert.fail("Cannot access row " + row + " - table has " + table.rows.length + " rows");
+    }
+    else if (col > table.rows[row].cells.length) {
+        Assert.fail("Cannot access column " + col + " - table row has " + table.rows[row].cells.length + " columns");
+    }
+    else {
+        actualContent = getText(table.rows[row].cells[col]);
+        return actualContent.trim();
+    }
+};
+
+Selenium.prototype.isSelected = function(locator, optionLocator) {
+	/**
+   * Verifies that the selected option of a drop-down satisfies the optionSpecifier.
+   * 
+   * <p>See the select command for more information about option locators.</p>
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @param optionLocator an option locator, typically just an option label (e.g. "John Smith")
+   * @return boolean true if the selected option matches the locator, false otherwise
+   */
+    var element = this.page().findElement(locator);
+    var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
+    if (element.selectedIndex == -1)
+    {
+        return false;
+    }
+    return locator.isSelected(element);
+};
+
+Selenium.prototype.getSelectedOptions = function(locator) {
+    /** Gets all option labels for selected options in the specified select or multi-select element.
+   *
+   * @param locator an <a href="#locators">element locator</a>
+   * @return string[] an array of all option labels in the specified select drop-down
+   */
+   var element = this.page().findElement(locator);
+
+	var selectedOptions = [];
+
+    for (var i = 0; i < element.options.length; i++) {
+        if (element.options[i].selected)
+        {
+            var option = element.options[i].text.replace(/,/g, "\\,");
+            selectedOptions.push(option);
+        }
+    }
+    return selectedOptions.join(",");
+
+}
+
+Selenium.prototype.getSelectOptions = function(locator) {
+	/** Gets all option labels in the specified select drop-down.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @return string[] an array of all option labels in the specified select drop-down
+   */
+    var element = this.page().findElement(locator);
+
+    var selectOptions = [];
+
+    for (var i = 0; i < element.options.length; i++) {
+    	var option = element.options[i].text.replace(/,/g, "\\,");
+        selectOptions.push(option);
+    }
+    
+    return selectOptions.join(",");
+};
+
+
+Selenium.prototype.getAttribute = function(attributeLocator) {
+	/**
+   * Gets the value of an element attribute.
+   * @param attributeLocator an element locator followed by an @ sign and then the name of the attribute, e.g. "foo at bar"
+   * @return string the value of the specified attribute
+   */
+   var result = this.page().findAttribute(attributeLocator);
+   if (result == null) {
+   		throw new SeleniumError("Could not find element attribute: " + attributeLocator);
+	}
+    return result;
+};
+
+Selenium.prototype.isTextPresent = function(pattern) {
+	/**
+   * Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
+   * @param pattern a <a href="#patterns">pattern</a> to match with the text of the page
+   * @return boolean true if the pattern matches the text, false otherwise
+   */
+    var allText = this.page().bodyText();
+
+    if(allText == "") {
+        Assert.fail("Page text not found");
+    } else {
+    	var patternMatcher = new PatternMatcher(pattern);
+        if (patternMatcher.strategy == PatternMatcher.strategies.glob) {
+    		patternMatcher.matcher = new PatternMatcher.strategies.globContains(pattern);
+    	}
+    	return patternMatcher.matches(allText);
+    }
+};
+
+Selenium.prototype.isElementPresent = function(locator) {
+	/**
+   * Verifies that the specified element is somewhere on the page.
+   * @param locator an <a href="#locators">element locator</a>
+   * @return boolean true if the element is present, false otherwise
+   */
+    try {
+        this.page().findElement(locator);
+    } catch (e) {
+        return false;
+    }
+    return true;
+};
+
+Selenium.prototype.isVisible = function(locator) {
+	/**
+   * Determines if the specified element is visible. An
+   * element can be rendered invisible by setting the CSS "visibility"
+   * property to "hidden", or the "display" property to "none", either for the
+   * element itself or one if its ancestors.  This method will fail if
+   * the element is not present.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @return boolean true if the specified element is visible, false otherwise
+   */
+    var element;
+    element = this.page().findElement(locator); 
+    var visibility = this.findEffectiveStyleProperty(element, "visibility");
+    var _isDisplayed = this._isDisplayed(element);
+    return (visibility != "hidden" && _isDisplayed);
+};
+
+Selenium.prototype.findEffectiveStyleProperty = function(element, property) {
+    var effectiveStyle = this.findEffectiveStyle(element);
+    var propertyValue = effectiveStyle[property];
+    if (propertyValue == 'inherit' && element.parentNode.style) {
+        return this.findEffectiveStyleProperty(element.parentNode, property);
+    }
+    return propertyValue;
+};
+
+Selenium.prototype._isDisplayed = function(element) {
+    var display = this.findEffectiveStyleProperty(element, "display");
+    if (display == "none") return false;
+    if (element.parentNode.style) {
+        return this._isDisplayed(element.parentNode);
+    }
+    return true;
+};
+
+Selenium.prototype.findEffectiveStyle = function(element) {
+    if (element.style == undefined) {
+        return undefined; // not a styled element
+    }
+    var window = this.browserbot.getContentWindow();
+    if (window.getComputedStyle) { 
+        // DOM-Level-2-CSS
+        return window.getComputedStyle(element, null);
+    }
+    if (element.currentStyle) {
+        // non-standard IE alternative
+        return element.currentStyle;
+        // TODO: this won't really work in a general sense, as
+        //   currentStyle is not identical to getComputedStyle()
+        //   ... but it's good enough for "visibility"
+    }
+    throw new SeleniumError("cannot determine effective stylesheet in this browser");
+};
+
+Selenium.prototype.isEditable = function(locator) {
+	/**
+   * Determines whether the specified input element is editable, ie hasn't been disabled.
+   * This method will fail if the specified element isn't an input element.
+   * 
+   * @param locator an <a href="#locators">element locator</a>
+   * @return boolean true if the input element is editable, false otherwise
+   */
+    var element = this.page().findElement(locator);
+    if (element.value == undefined) {
+        Assert.fail("Element " + locator + " is not an input.");
+    }
+    return !element.disabled;
+};
+
+Selenium.prototype.getAllButtons = function() {
+	/** Returns the IDs of all buttons on the page.
+   * 
+   * <p>If a given button has no ID, it will appear as "" in this array.</p>
+   * 
+   * @return string[] the IDs of all buttons on the page
+   */
+   return this.page().getAllButtons();
+};
+
+Selenium.prototype.getAllLinks = function() {
+	/** Returns the IDs of all links on the page.
+   * 
+   * <p>If a given link has no ID, it will appear as "" in this array.</p>
+   * 
+   * @return string[] the IDs of all links on the page
+   */
+   return this.page().getAllLinks();
+};
+
+Selenium.prototype.getAllFields = function() {
+	/** Returns the IDs of all input fields on the page.
+   * 
+   * <p>If a given field has no ID, it will appear as "" in this array.</p>
+   * 
+   * @return string[] the IDs of all field on the page
+   */
+   return this.page().getAllFields();
+};
+
+Selenium.prototype.getHtmlSource = function() {
+	/** Returns the entire HTML source between the opening and
+   * closing "html" tags.
+   *
+   * @return string the entire HTML source
+   */
+	return this.page().currentDocument.getElementsByTagName("html")[0].innerHTML;
+};
+
+
+Selenium.prototype.doSetContext = function(context, logLevelThreshold) {
+	/**
+   * Writes a message to the status bar and adds a note to the browser-side
+   * log.
+   * 
+   * <p>If logLevelThreshold is specified, set the threshold for logging
+   * to that level (debug, info, warn, error).</p>
+   * 
+   * <p>(Note that the browser-side logs will <i>not</i> be sent back to the
+   * server, and are invisible to the Client Driver.)</p>
+   * 
+   * @param context
+   *            the message to be sent to the browser
+   * @param logLevelThreshold one of "debug", "info", "warn", "error", sets the threshold for browser-side logging
+   */
+    if  (logLevelThreshold==null || logLevelThreshold=="") {
+    	return this.page().setContext(context);
+    }
+    return this.page().setContext(context, logLevelThreshold);
+};
+
+Selenium.prototype.getExpression = function(expression) {
+	/**
+	 * Returns the specified expression.
+	 *
+	 * <p>This is useful because of JavaScript preprocessing.
+	 * It is used to generate commands like assertExpression and storeExpression.</p>
+	 * 
+	 * @param expression the value to return
+	 * @return string the value passed in
+	 */
+	return expression;
+}
+
+Selenium.prototype.doWaitForCondition = function(script, timeout) {
+	/**
+   * Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
+   * The snippet may have multiple lines, but only the result of the last line
+   * will be considered.
+   * 
+   * <p>Note that, by default, the snippet will be run in the runner's test window, not in the window
+   * of your application.  To get the window of your application, you can use
+   * the JavaScript snippet <code>selenium.browserbot.getCurrentWindow()</code>, and then
+   * run your JavaScript in there</p>
+   * @param script the JavaScript snippet to run
+   * @param timeout a timeout in milliseconds, after which this command will return with an error
+   */
+    if (isNaN(timeout)) {
+    	throw new SeleniumError("Timeout is not a number: " + timeout);
+    }
+    
+    testLoop.waitForCondition = function () {
+        return eval(script);
+    };
+    
+    testLoop.waitForConditionStart = new Date().getTime();
+    testLoop.waitForConditionTimeout = timeout;
+};
+
+Selenium.prototype.doSetTimeout = function(timeout) {
+	/**
+	 * Specifies the amount of time that Selenium will wait for actions to complete.
+	 *
+	 * <p>Actions that require waiting include "open" and the "waitFor*" actions.</p>
+	 * The default timeout is 30 seconds.
+	 * @param timeout a timeout in milliseconds, after which the action will return with an error
+	 */
+	testLoop.waitForConditionTimeout = timeout;
+}
+
+Selenium.prototype.doWaitForPageToLoad = function(timeout) {
+	/**
+   * Waits for a new page to load.
+   * 
+   * <p>You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
+   * (which are only available in the JS API).</p>
+   * 
+   * <p>Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
+   * flag when it first notices a page load.  Running any other Selenium command after
+   * turns the flag to false.  Hence, if you want to wait for a page to load, you must
+   * wait immediately after a Selenium command that caused a page-load.</p>
+   * @param timeout a timeout in milliseconds, after which this command will return with an error
+   */
+    this.doWaitForCondition("selenium.browserbot.isNewPageLoaded()", timeout);
+};
+
+/**
+ * Evaluate a parameter, performing JavaScript evaluation and variable substitution.
+ * If the string matches the pattern "javascript{ ... }", evaluate the string between the braces.
+ */
+Selenium.prototype.preprocessParameter = function(value) {
+    var match = value.match(/^javascript\{((.|\r?\n)+)\}$/);
+    if (match && match[1]) {
+        return eval(match[1]).toString();
+    }
+    return this.replaceVariables(value);
+};
+
+/*
+ * Search through str and replace all variable references ${varName} with their
+ * value in storedVars.
+ */
+Selenium.prototype.replaceVariables = function(str) {
+    var stringResult = str;
+
+    // Find all of the matching variable references
+    var match = stringResult.match(/\$\{\w+\}/g);
+    if (!match) {
+        return stringResult;
+    }
+
+    // For each match, lookup the variable value, and replace if found
+    for (var i = 0; match && i < match.length; i++) {
+        var variable = match[i]; // The replacement variable, with ${}
+        var name = variable.substring(2, variable.length - 1); // The replacement variable without ${}
+        var replacement = storedVars[name];
+        if (replacement != undefined) {
+            stringResult = stringResult.replace(variable, replacement);
+        }
+    }
+    return stringResult;
+};
+
+
+/**
+ *  Factory for creating "Option Locators".
+ *  An OptionLocator is an object for dealing with Select options (e.g. for
+ *  finding a specified option, or asserting that the selected option of 
+ *  Select element matches some condition.
+ *  The type of locator returned by the factory depends on the locator string:
+ *     label=<exp>  (OptionLocatorByLabel)
+ *     value=<exp>  (OptionLocatorByValue)
+ *     index=<exp>  (OptionLocatorByIndex)
+ *     id=<exp>     (OptionLocatorById)
+ *     <exp> (default is OptionLocatorByLabel).
+ */
+function OptionLocatorFactory() {
+}
+
+OptionLocatorFactory.prototype.fromLocatorString = function(locatorString) {
+    var locatorType = 'label';
+    var locatorValue = locatorString;
+    // If there is a locator prefix, use the specified strategy
+    var result = locatorString.match(/^([a-zA-Z]+)=(.*)/);
+    if (result) {
+        locatorType = result[1];
+        locatorValue = result[2];
+    }
+    if (this.optionLocators == undefined) {
+        this.registerOptionLocators();
+    }
+    if (this.optionLocators[locatorType]) {
+        return new this.optionLocators[locatorType](locatorValue);
+    }
+    throw new SeleniumError("Unkown option locator type: " + locatorType);
+};
+
+/**
+ * To allow for easy extension, all of the option locators are found by
+ * searching for all methods of OptionLocatorFactory.prototype that start
+ * with "OptionLocatorBy".
+ * TODO: Consider using the term "Option Specifier" instead of "Option Locator".
+ */
+OptionLocatorFactory.prototype.registerOptionLocators = function() {
+    this.optionLocators={};
+    for (var functionName in this) {
+      var result = /OptionLocatorBy([A-Z].+)$/.exec(functionName);
+      if (result != null) {
+          var locatorName = result[1].lcfirst();
+          this.optionLocators[locatorName] = this[functionName];
+      }
+    }
+};
+
+/**
+ *  OptionLocator for options identified by their labels.
+ */
+OptionLocatorFactory.prototype.OptionLocatorByLabel = function(label) {
+    this.label = label;
+    this.labelMatcher = new PatternMatcher(this.label);
+    this.findOption = function(element) {
+        for (var i = 0; i < element.options.length; i++) {
+            if (this.labelMatcher.matches(element.options[i].text)) {
+                return element.options[i];
+            }
+        }
+        throw new SeleniumError("Option with label '" + this.label + "' not found");
+    };
+
+    this.isSelected = function(element) {
+        var selectedLabel = element.options[element.selectedIndex].text;
+        return PatternMatcher.matches(this.label, selectedLabel)
+    };
+};
+
+/**
+ *  OptionLocator for options identified by their values.
+ */
+OptionLocatorFactory.prototype.OptionLocatorByValue = function(value) {
+    this.value = value;
+    this.valueMatcher = new PatternMatcher(this.value);
+    this.findOption = function(element) {
+        for (var i = 0; i < element.options.length; i++) {
+            if (this.valueMatcher.matches(element.options[i].value)) {
+                return element.options[i];
+            }
+        }
+        throw new SeleniumError("Option with value '" + this.value + "' not found");
+    };
+
+    this.isSelected = function(element) {
+        var selectedValue = element.options[element.selectedIndex].value;
+        return PatternMatcher.matches(this.value, selectedValue)
+    };
+};
+
+/**
+ *  OptionLocator for options identified by their index.
+ */
+OptionLocatorFactory.prototype.OptionLocatorByIndex = function(index) {
+    this.index = Number(index);
+    if (isNaN(this.index) || this.index < 0) {
+        throw new SeleniumError("Illegal Index: " + index);
+    }
+
+    this.findOption = function(element) {
+        if (element.options.length <= this.index) {
+            throw new SeleniumError("Index out of range.  Only " + element.options.length + " options available");
+        }
+        return element.options[this.index];
+    };
+
+    this.isSelected = function(element) {
+    	return this.index == element.selectedIndex;
+    };
+};
+
+/**
+ *  OptionLocator for options identified by their id.
+ */
+OptionLocatorFactory.prototype.OptionLocatorById = function(id) {
+    this.id = id;
+    this.idMatcher = new PatternMatcher(this.id);
+    this.findOption = function(element) {
+        for (var i = 0; i < element.options.length; i++) {
+            if (this.idMatcher.matches(element.options[i].id)) {
+                return element.options[i];
+            }
+        }
+        throw new SeleniumError("Option with id '" + this.id + "' not found");
+    };
+
+    this.isSelected = function(element) {
+        var selectedId = element.options[element.selectedIndex].id;
+        return PatternMatcher.matches(this.id, selectedId)
+    };
+};
+
+

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserbot.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserbot.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserbot.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,1047 @@
+/*
+* Copyright 2004 ThoughtWorks, Inc
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*
+*/
+
+/*
+* This script provides the Javascript API to drive the test application contained within
+* a Browser Window.
+* TODO:
+*    Add support for more events (keyboard and mouse)
+*    Allow to switch "user-entry" mode from mouse-based to keyboard-based, firing different
+*          events in different modes.
+*/
+
+// The window to which the commands will be sent.  For example, to click on a
+// popup window, first select that window, and then do a normal click command.
+
+BrowserBot = function(frame) {
+    this.frame = frame;
+    this.currentPage = null;
+    this.currentWindowName = null;
+
+    this.modalDialogTest = null;
+    this.recordedAlerts = new Array();
+    this.recordedConfirmations = new Array();
+    this.recordedPrompts = new Array();
+    this.openedWindows = {};
+    this.nextConfirmResult = true;
+    this.nextPromptResult = '';
+    this.newPageLoaded = false;
+    this.pageLoadError = null;
+
+    var self = this;
+    this.recordPageLoad = function() {
+    	LOG.debug("Page load detected");
+        try {
+        	LOG.debug("Page load location=" + self.getCurrentWindow().location);
+        } catch (e) {
+        	self.pageLoadError = e;
+        	return;
+        }
+        self.currentPage = null;
+        self.newPageLoaded = true;
+    };
+
+    this.isNewPageLoaded = function() {
+    	if (this.pageLoadError) throw this.pageLoadError;
+        return self.newPageLoaded;
+    };
+};
+
+BrowserBot.createForFrame = function(frame) {
+    var browserbot;
+    LOG.debug("browserName: " + browserVersion.name);
+    LOG.debug("userAgent: " + navigator.userAgent);
+    if (browserVersion.isIE) {
+        browserbot = new IEBrowserBot(frame);
+    }
+    else if (browserVersion.isKonqueror) {
+        browserbot = new KonquerorBrowserBot(frame);
+    }
+    else if (browserVersion.isSafari) {
+        browserbot = new SafariBrowserBot(frame);
+    }
+    else {
+        LOG.info("Using MozillaBrowserBot")
+        // Use mozilla by default
+        browserbot = new MozillaBrowserBot(frame);
+    }
+
+    // Modify the test IFrame so that page loads are detected.
+    addLoadListener(browserbot.getFrame(), browserbot.recordPageLoad);
+    return browserbot;
+};
+
+BrowserBot.prototype.doModalDialogTest = function(test) {
+    this.modalDialogTest = test;
+};
+
+BrowserBot.prototype.cancelNextConfirmation = function() {
+    this.nextConfirmResult = false;
+};
+
+BrowserBot.prototype.setNextPromptResult = function(result) {
+    this.nextPromptResult = result;
+};
+
+BrowserBot.prototype.hasAlerts = function() {
+    return (this.recordedAlerts.length > 0) ;
+};
+
+BrowserBot.prototype.getNextAlert = function() {
+    return this.recordedAlerts.shift();
+};
+
+BrowserBot.prototype.hasConfirmations = function() {
+    return (this.recordedConfirmations.length > 0) ;
+};
+
+BrowserBot.prototype.getNextConfirmation = function() {
+    return this.recordedConfirmations.shift();
+};
+
+BrowserBot.prototype.hasPrompts = function() {
+    return (this.recordedPrompts.length > 0) ;
+};
+
+BrowserBot.prototype.getNextPrompt = function() {
+    return this.recordedPrompts.shift();
+};
+
+BrowserBot.prototype.getFrame = function() {
+    return this.frame;
+};
+
+BrowserBot.prototype.selectWindow = function(target) {
+    // we've moved to a new page - clear the current one
+    this.currentPage = null;
+    this.currentWindowName = null;
+    if (target && target != "null") {
+        // If window exists
+        if (this.getTargetWindow(target)) {
+            this.currentWindowName = target;
+        }
+    }
+};
+
+BrowserBot.prototype.openLocation = function(target) {
+    // We're moving to a new page - clear the current one
+    this.currentPage = null;
+    this.newPageLoaded = false;
+
+    this.setOpenLocation(target);
+};
+
+BrowserBot.prototype.setIFrameLocation = function(iframe, location) {
+    iframe.src = location;
+};
+
+BrowserBot.prototype.setOpenLocation = function(location) {
+    this.getCurrentWindow().location.href = location;
+};
+
+BrowserBot.prototype.getCurrentPage = function() {
+    if (this.currentPage == null) {
+        var testWindow = this.getCurrentWindow();
+        this.modifyWindowToRecordPopUpDialogs(testWindow, this);
+        this.modifySeparateTestWindowToDetectPageLoads(testWindow);
+        this.currentPage = PageBot.createForWindow(testWindow);
+        this.newPageLoaded = false;
+    }
+
+    return this.currentPage;
+};
+
+BrowserBot.prototype.modifyWindowToRecordPopUpDialogs = function(windowToModify, browserBot) {
+    windowToModify.alert = function(alert) {
+        browserBot.recordedAlerts.push(alert);
+    };
+
+    windowToModify.confirm = function(message) {
+        browserBot.recordedConfirmations.push(message);
+        var result = browserBot.nextConfirmResult;
+        browserBot.nextConfirmResult = true;
+        return result;
+    };
+
+    windowToModify.prompt = function(message) {
+        browserBot.recordedPrompts.push(message);
+        var result = !browserBot.nextConfirmResult ? null : browserBot.nextPromptResult;
+        browserBot.nextConfirmResult = true;
+        browserBot.nextPromptResult = '';
+        return result;
+    };
+
+    // Keep a reference to all popup windows by name
+    // note that in IE the "windowName" argument must be a valid javascript identifier, it seems.
+    var originalOpen = windowToModify.open;
+    windowToModify.open = function(url, windowName, windowFeatures, replaceFlag) {
+        var openedWindow = originalOpen(url, windowName, windowFeatures, replaceFlag);
+        selenium.browserbot.openedWindows[windowName] = openedWindow;
+        return openedWindow;
+    };
+};
+
+/**
+ * The main IFrame has a single, long-lived onload handler that clears
+ * Browserbot.currentPage and sets the "newPageLoaded" flag. For separate
+ * windows, we need to attach a handler each time. This uses the
+ * "callOnWindowPageTransition" mechanism, which is implemented differently
+ * for different browsers.
+ */
+BrowserBot.prototype.modifySeparateTestWindowToDetectPageLoads = function(windowToModify) {
+    if (this.currentWindowName != null) {
+        this.callOnWindowPageTransition(this.recordPageLoad, windowToModify);
+    }
+};
+
+/**
+ * Call the supplied function when a the current page unloads and a new one loads.
+ * This is done by polling continuously until the document changes and is fully loaded.
+ */
+BrowserBot.prototype.callOnWindowPageTransition = function(loadFunction, windowObject) {
+    // Since the unload event doesn't fire in Safari 1.3, we start polling immediately
+    if (windowObject && !windowObject.closed) {
+        LOG.debug("Starting pollForLoad: " + windowObject.document.location);
+        this.pollForLoad(loadFunction, windowObject, windowObject.document.location, windowObject.document.location.href);
+    }
+};
+
+/**
+ * Set up a polling timer that will keep checking the readyState of the document until it's complete.
+ * Since we might call this before the original page is unloaded, we first check to see that the current location
+ * or href is different from the original one.
+ */
+BrowserBot.prototype.pollForLoad = function(loadFunction, windowObject, originalLocation, originalHref) {
+    var windowClosed = true;
+    try {
+    	windowClosed = windowObject.closed;
+    } catch (e) {
+    	LOG.debug("exception detecting closed window (I guess it must be closed)");
+    	LOG.exception(e);
+    	// swallow exceptions which may occur in HTA mode when the window is closed
+    }
+    if (windowClosed) {
+        return;
+    }
+
+    LOG.debug("pollForLoad original: " + originalHref);
+    try {
+
+	    var currentLocation = windowObject.document.location;
+	    var currentHref = currentLocation.href
+
+	    var sameLoc = (originalLocation === currentLocation);
+	    var sameHref = (originalHref === currentHref);
+	    var rs = windowObject.document.readyState;
+
+		if (rs == null) rs = 'complete';
+
+	    if (!(sameLoc && sameHref) && rs == 'complete') {
+	        LOG.debug("pollForLoad complete: " + rs + " (" + currentHref + ")");
+	        loadFunction();
+	        return;
+	    }
+	    var self = this;
+	    LOG.debug("pollForLoad continue: " + currentHref);
+	    window.setTimeout(function() {self.pollForLoad(loadFunction, windowObject, originalLocation, originalHref);}, 500);
+	} catch (e) {
+		this.pageLoadError = e;
+	}
+};
+
+
+BrowserBot.prototype.getContentWindow = function() {
+    return this.getFrame().contentWindow || frames[this.getFrame().id];
+};
+
+BrowserBot.prototype.getTargetWindow = function(windowName) {
+    LOG.debug("getTargetWindow(" + windowName + ")");
+    // First look in the map of opened windows
+    var targetWindow = this.openedWindows[windowName];
+    if (!targetWindow) {
+        var evalString = "this.getContentWindow().window." + windowName;
+        targetWindow = eval(evalString);
+    }
+    if (!targetWindow) {
+        throw new SeleniumError("Window does not exist");
+    }
+    return targetWindow;
+};
+
+BrowserBot.prototype.getCurrentWindow = function() {
+    var testWindow = this.getContentWindow().window;
+    if (this.currentWindowName != null) {
+        testWindow = this.getTargetWindow(this.currentWindowName);
+    }
+    return testWindow;
+};
+
+function MozillaBrowserBot(frame) {
+    BrowserBot.call(this, frame);
+}
+MozillaBrowserBot.prototype = new BrowserBot;
+
+function KonquerorBrowserBot(frame) {
+    BrowserBot.call(this, frame);
+}
+KonquerorBrowserBot.prototype = new BrowserBot;
+
+KonquerorBrowserBot.prototype.setIFrameLocation = function(iframe, location) {
+    // Window doesn't fire onload event when setting src to the current value,
+    // so we set it to blank first.
+    iframe.src = "about:blank";
+    iframe.src = location;
+};
+
+KonquerorBrowserBot.prototype.setOpenLocation = function(location) {
+    // Window doesn't fire onload event when setting src to the current value,
+    // so we set it to blank first.
+    this.getCurrentWindow().location.href = "about:blank";
+    this.getCurrentWindow().location.href = location;
+};
+
+function SafariBrowserBot(frame) {
+    BrowserBot.call(this, frame);
+}
+SafariBrowserBot.prototype = new BrowserBot;
+
+SafariBrowserBot.prototype.setIFrameLocation = KonquerorBrowserBot.prototype.setIFrameLocation;
+
+function IEBrowserBot(frame) {
+    BrowserBot.call(this, frame);
+}
+IEBrowserBot.prototype = new BrowserBot;
+
+IEBrowserBot.prototype.modifyWindowToRecordPopUpDialogs = function(windowToModify, browserBot) {
+    BrowserBot.prototype.modifyWindowToRecordPopUpDialogs(windowToModify, browserBot);
+
+    // we will call the previous version of this method from within our own interception
+    oldShowModalDialog = windowToModify.showModalDialog;
+
+    windowToModify.showModalDialog = function(url, args, features) {
+        // Get relative directory to where TestRunner.html lives
+        // A risky assumption is that the user's TestRunner is named TestRunner.html
+        var doc_location = document.location.toString();
+        var end_of_base_ref = doc_location.indexOf('TestRunner.html');
+        var base_ref = doc_location.substring(0, end_of_base_ref);
+
+        var fullURL = base_ref + "TestRunner.html?singletest=" + escape(browserBot.modalDialogTest) + "&autoURL=" + escape(url) + "&runInterval=" + runInterval;
+        browserBot.modalDialogTest = null;
+
+        var returnValue = oldShowModalDialog(fullURL, args, features);
+        return returnValue;
+    };
+};
+
+SafariBrowserBot.prototype.modifyWindowToRecordPopUpDialogs = function(windowToModify, browserBot) {
+    BrowserBot.prototype.modifyWindowToRecordPopUpDialogs(windowToModify, browserBot);
+
+    var originalOpen = windowToModify.open;
+    /*
+     * Safari seems to be broken, so that when we manually trigger the onclick method
+     * of a button/href, any window.open calls aren't resolved relative to the app location.
+     * So here we replace the open() method with one that does resolve the url correctly.
+     */
+    windowToModify.open = function(url, windowName, windowFeatures, replaceFlag) {
+
+        if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/")) {
+            return originalOpen(url, windowName, windowFeatures, replaceFlag);
+        }
+
+        // Reduce the current path to the directory
+        var currentPath = windowToModify.location.pathname || "/";
+        currentPath = currentPath.replace(/\/[^\/]*$/, "/");
+
+        // Remove any leading "./" from the new url.
+        url = url.replace(/^\.\//, "");
+
+        newUrl = currentPath + url;
+
+        return originalOpen(newUrl, windowName, windowFeatures, replaceFlag);
+    };
+};
+
+PageBot = function(pageWindow) {
+    if (pageWindow) {
+        this.currentWindow = pageWindow;
+        this.currentDocument = pageWindow.document;
+        this.location = pageWindow.location;
+        this.title = function() {return this.currentDocument.title;};
+    }
+
+    // Register all locateElementBy* functions
+    // TODO - don't do this in the constructor - only needed once ever
+    this.locationStrategies = {};
+    for (var functionName in this) {
+        var result = /^locateElementBy([A-Z].+)$/.exec(functionName);
+        if (result != null) {
+            var locatorFunction = this[functionName];
+            if (typeof(locatorFunction) != 'function') {
+                continue;
+            }
+            // Use a specified prefix in preference to one generated from
+            // the function name
+            var locatorPrefix = locatorFunction.prefix || result[1].toLowerCase();
+            this.locationStrategies[locatorPrefix] = locatorFunction;
+        }
+    }
+
+    /**
+     * Find a locator based on a prefix.
+     */
+    this.findElementBy = function(locatorType, locator, inDocument) {
+        var locatorFunction = this.locationStrategies[locatorType];
+        if (! locatorFunction) {
+            throw new SeleniumError("Unrecognised locator type: '" + locatorType + "'");
+        }
+        return locatorFunction.call(this, locator, inDocument);
+    };
+
+    /**
+     * The implicit locator, that is used when no prefix is supplied.
+     */
+    this.locationStrategies['implicit'] = function(locator, inDocument) {
+        if (locator.startsWith('//')) {
+            return this.locateElementByXPath(locator, inDocument);
+        }
+        if (locator.startsWith('document.')) {
+            return this.locateElementByDomTraversal(locator, inDocument);
+        }
+        return this.locateElementByIdentifier(locator, inDocument);
+    };
+
+};
+
+PageBot.createForWindow = function(windowObject) {
+    if (browserVersion.isIE) {
+        return new IEPageBot(windowObject);
+    }
+    else if (browserVersion.isKonqueror) {
+        return new KonquerorPageBot(windowObject);
+    }
+    else if (browserVersion.isSafari) {
+        return new SafariPageBot(windowObject);
+    }
+    else {
+        LOG.info("Using MozillaPageBot")
+        // Use mozilla by default
+        return new MozillaPageBot(windowObject);
+    }
+};
+
+MozillaPageBot = function(pageWindow) {
+    PageBot.call(this, pageWindow);
+};
+MozillaPageBot.prototype = new PageBot();
+
+KonquerorPageBot = function(pageWindow) {
+    PageBot.call(this, pageWindow);
+};
+KonquerorPageBot.prototype = new PageBot();
+
+SafariPageBot = function(pageWindow) {
+    PageBot.call(this, pageWindow);
+};
+SafariPageBot.prototype = new PageBot();
+
+IEPageBot = function(pageWindow) {
+    PageBot.call(this, pageWindow);
+};
+IEPageBot.prototype = new PageBot();
+
+/*
+* Finds an element on the current page, using various lookup protocols
+*/
+PageBot.prototype.findElement = function(locator) {
+    var locatorType = 'implicit';
+    var locatorString = locator;
+
+    // If there is a locator prefix, use the specified strategy
+    var result = locator.match(/^([A-Za-z]+)=(.+)/);
+    if (result) {
+        locatorType = result[1].toLowerCase();
+        locatorString = result[2];
+    }
+
+    var element = this.findElementBy(locatorType, locatorString, this.currentDocument);
+    if (element != null) {
+        return element;
+    }
+    for (var i = 0; i < this.currentWindow.frames.length; i++) {
+        element = this.findElementBy(locatorType, locatorString, this.currentWindow.frames[i].document);
+        if (element != null) {
+            return element;
+        }
+    }
+
+    // Element was not found by any locator function.
+    throw new SeleniumError("Element " + locator + " not found");
+};
+
+/**
+ * In non-IE browsers, getElementById() does not search by name.  Instead, we
+ * we search separately by id and name.
+ */
+PageBot.prototype.locateElementByIdentifier = function(identifier, inDocument) {
+    return PageBot.prototype.locateElementById(identifier, inDocument)
+            || PageBot.prototype.locateElementByName(identifier, inDocument)
+            || null;
+};
+
+/**
+ * In IE, getElementById() also searches by name - this is an optimisation for IE.
+ */
+IEPageBot.prototype.locateElementByIdentifer = function(identifier, inDocument) {
+    return inDocument.getElementById(identifier);
+};
+
+/**
+ * Find the element with id - can't rely on getElementById, coz it returns by name as well in IE..
+ */
+PageBot.prototype.locateElementById = function(identifier, inDocument) {
+    var element = inDocument.getElementById(identifier);
+    if (element && element.id === identifier) {
+        return element;
+    }
+    else {
+        return null;
+    }
+};
+
+/**
+ * Find an element by name, refined by (optional) element-filter
+ * expressions.
+ */
+PageBot.prototype.locateElementByName = function(locator, document) {
+    var elements = document.getElementsByTagName("*");
+
+    var filters = locator.split(' ');
+    filters[0] = 'name=' + filters[0];
+
+    while (filters.length) {
+        var filter = filters.shift();
+        elements = this.selectElements(filter, elements, 'value');
+    }
+
+    if (elements.length > 0) {
+        return elements[0];
+    }
+    return null;
+};
+
+/**
+* Finds an element using by evaluating the "document.*" string against the
+* current document object. Dom expressions must begin with "document."
+*/
+PageBot.prototype.locateElementByDomTraversal = function(domTraversal, inDocument) {
+    if (domTraversal.indexOf("document.") != 0) {
+        return null;
+    }
+
+    // Trim the leading 'document'
+    domTraversal = domTraversal.substr(9);
+    var locatorScript = "inDocument." + domTraversal;
+    var element = eval(locatorScript);
+
+    if (!element) {
+        return null;
+    }
+
+    return element;
+};
+PageBot.prototype.locateElementByDomTraversal.prefix = "dom";
+
+/**
+* Finds an element identified by the xpath expression. Expressions _must_
+* begin with "//".
+*/
+PageBot.prototype.locateElementByXPath = function(xpath, inDocument) {
+
+    // Trim any trailing "/": not valid xpath, and remains from attribute
+    // locator.
+    if (xpath.charAt(xpath.length - 1) == '/') {
+        xpath = xpath.slice(0, -1);
+    }
+
+    // Handle //tag
+    var match = xpath.match(/^\/\/(\w+|\*)$/);
+    if (match) {
+        var elements = inDocument.getElementsByTagName(match[1].toUpperCase());
+        if (elements == null) return null;
+        return elements[0];
+    }
+
+    // Handle //tag[@attr='value']
+    var match = xpath.match(/^\/\/(\w+|\*)\[@(\w+)=('([^\']+)'|"([^\"]+)")\]$/);
+    if (match) {
+        return this.findElementByTagNameAndAttributeValue(
+            inDocument,
+            match[1].toUpperCase(),
+            match[2].toLowerCase(),
+            match[3].slice(1, -1)
+        );
+    }
+
+    // Handle //tag[text()='value']
+    var match = xpath.match(/^\/\/(\w+|\*)\[text\(\)=('([^\']+)'|"([^\"]+)")\]$/);
+    if (match) {
+        return this.findElementByTagNameAndText(
+            inDocument,
+            match[1].toUpperCase(),
+            match[2].slice(1, -1)
+        );
+    }
+
+    return this.findElementUsingFullXPath(xpath, inDocument);
+};
+
+PageBot.prototype.findElementByTagNameAndAttributeValue = function(
+    inDocument, tagName, attributeName, attributeValue
+) {
+    if (browserVersion.isIE && attributeName == "class") {
+        attributeName = "className";
+    }
+    var elements = inDocument.getElementsByTagName(tagName);
+    for (var i = 0; i < elements.length; i++) {
+        var elementAttr = elements[i].getAttribute(attributeName);
+        if (elementAttr == attributeValue) {
+            return elements[i];
+        }
+    }
+    return null;
+};
+
+PageBot.prototype.findElementByTagNameAndText = function(
+    inDocument, tagName, text
+) {
+    var elements = inDocument.getElementsByTagName(tagName);
+    for (var i = 0; i < elements.length; i++) {
+        if (getText(elements[i]) == text) {
+            return elements[i];
+        }
+    }
+    return null;
+};
+
+PageBot.prototype.findElementUsingFullXPath = function(xpath, inDocument) {
+    if (browserVersion.isIE && !inDocument.evaluate) {
+        addXPathSupport(inDocument);
+    }
+
+    // Use document.evaluate() if it's available
+    if (inDocument.evaluate) {
+        return inDocument.evaluate(xpath, inDocument, null, 0, null).iterateNext();
+    }
+
+    // If not, fall back to slower JavaScript implementation
+    var context = new XPathContext();
+    context.expressionContextNode = inDocument;
+    var xpathResult = new XPathParser().parse(xpath).evaluate(context);
+    if (xpathResult && xpathResult.toArray) {
+        return xpathResult.toArray()[0];
+    }
+    return null;
+};
+
+/**
+* Finds a link element with text matching the expression supplied. Expressions must
+* begin with "link:".
+*/
+PageBot.prototype.locateElementByLinkText = function(linkText, inDocument) {
+    var links = inDocument.getElementsByTagName('a');
+    for (var i = 0; i < links.length; i++) {
+        var element = links[i];
+        if (PatternMatcher.matches(linkText, getText(element))) {
+            return element;
+        }
+    }
+    return null;
+};
+PageBot.prototype.locateElementByLinkText.prefix = "link";
+
+/**
+* Returns an attribute based on an attribute locator. This is made up of an element locator
+* suffixed with @attribute-name.
+*/
+PageBot.prototype.findAttribute = function(locator) {
+    // Split into locator + attributeName
+    var attributePos = locator.lastIndexOf("@");
+    var elementLocator = locator.slice(0, attributePos);
+    var attributeName = locator.slice(attributePos + 1);
+
+    // Find the element.
+    var element = this.findElement(elementLocator);
+
+    // Handle missing "class" attribute in IE.
+    if (browserVersion.isIE && attributeName == "class") {
+        attributeName = "className";
+    }
+
+    // Get the attribute value.
+    var attributeValue = element.getAttribute(attributeName);
+
+    return attributeValue ? attributeValue.toString() : null;
+};
+
+/*
+* Select the specified option and trigger the relevant events of the element.
+*/
+PageBot.prototype.selectOption = function(element, optionToSelect) {
+    triggerEvent(element, 'focus', false);
+    var changed = false;
+    for (var i = 0; i < element.options.length; i++) {
+        var option = element.options[i];
+        if (option.selected && option != optionToSelect) {
+            option.selected = false;
+            changed = true;
+        }
+        else if (!option.selected && option == optionToSelect) {
+            option.selected = true;
+            changed = true;
+        }
+    }
+
+    if (changed) {
+        triggerEvent(element, 'change', true);
+    }
+    triggerEvent(element, 'blur', false);
+};
+
+/*
+* Select the specified option and trigger the relevant events of the element.
+*/
+PageBot.prototype.addSelection = function(element, option) {
+    this.checkMultiselect(element);
+    triggerEvent(element, 'focus', false);
+    if (!option.selected) {
+        option.selected = true;
+        triggerEvent(element, 'change', true);
+    }
+    triggerEvent(element, 'blur', false);
+};
+
+/*
+* Select the specified option and trigger the relevant events of the element.
+*/
+PageBot.prototype.removeSelection = function(element, option) {
+    this.checkMultiselect(element);
+    triggerEvent(element, 'focus', false);
+    if (option.selected) {
+        option.selected = false;
+        triggerEvent(element, 'change', true);
+    }
+    triggerEvent(element, 'blur', false);
+};
+
+PageBot.prototype.checkMultiselect = function(element) {
+    if (!element.multiple)
+    {
+        throw new SeleniumError("Not a multi-select");
+    }
+
+};
+
+PageBot.prototype.replaceText = function(element, stringValue) {
+    triggerEvent(element, 'focus', false);
+    triggerEvent(element, 'select', true);
+    element.value=stringValue;
+    triggerEvent(element, 'change', true);
+    triggerEvent(element, 'blur', false);
+};
+
+// TODO Opera uses this too - split out an Opera version so we don't need the isGecko check here
+MozillaPageBot.prototype.clickElement = function(element) {
+
+    triggerEvent(element, 'focus', false);
+
+    // Add an event listener that detects if the default action has been prevented.
+    // (This is caused by a javascript onclick handler returning false)
+    var preventDefault = false;
+    if (browserVersion.isGecko) {
+        element.addEventListener("click", function(evt) {preventDefault = evt.getPreventDefault();}, false);
+    }
+
+    // Trigger the click event.
+    triggerMouseEvent(element, 'click', true);
+
+    // Perform the link action if preventDefault was set.
+    if (browserVersion.isGecko && !preventDefault) {
+        // Try the element itself, as well as it's parent - this handles clicking images inside links.
+        if (element.href) {
+            this.currentWindow.location.href = element.href;
+        }
+        else if (element.parentNode && element.parentNode.href) {
+            this.currentWindow.location.href = element.parentNode.href;
+        }
+    }
+
+    if (this.windowClosed()) {
+        return;
+    }
+
+    triggerEvent(element, 'blur', false);
+};
+
+KonquerorPageBot.prototype.clickElement = function(element) {
+
+    triggerEvent(element, 'focus', false);
+
+    if (element.click) {
+        element.click();
+    }
+    else {
+        triggerMouseEvent(element, 'click', true);
+    }
+
+    if (this.windowClosed()) {
+        return;
+    }
+
+    triggerEvent(element, 'blur', false);
+};
+
+SafariPageBot.prototype.clickElement = function(element) {
+
+    triggerEvent(element, 'focus', false);
+
+    var wasChecked = element.checked;
+
+    // For form element it is simple.
+    if (element.click) {
+        element.click();
+    }
+    // For links and other elements, event emulation is required.
+    else {
+        triggerMouseEvent(element, 'click', true);
+
+        // Unfortunately, triggering the event doesn't seem to activate onclick handlers.
+        // We currently call onclick for the link, but I'm guessing that the onclick for containing
+        // elements is not being called.
+        var success = true;
+        if (element.onclick) {
+            var evt = document.createEvent('HTMLEvents');
+            evt.initEvent('click', true, true);
+            var onclickResult = element.onclick(evt);
+            if (onclickResult === false) {
+                success = false;
+            }
+        }
+
+        if (success) {
+            // Try the element itself, as well as it's parent - this handles clicking images inside links.
+            if (element.href) {
+                this.currentWindow.location.href = element.href;
+            }
+            else if (element.parentNode.href) {
+                this.currentWindow.location.href = element.parentNode.href;
+            } else {
+                // This is true for buttons outside of forms, and maybe others.
+                LOG.warn("Ignoring 'click' call for button outside form, or link without href."
+                        + "Using buttons without an enclosing form can cause wierd problems with URL resolution in Safari." );
+                // I implemented special handling for window.open, but unfortunately this behaviour is also displayed
+                // when we have a button without an enclosing form that sets document.location in the onclick handler.
+                // The solution is to always use an enclosing form for a button.
+            }
+        }
+    }
+
+    if (this.windowClosed()) {
+        return;
+    }
+
+    triggerEvent(element, 'blur', false);
+};
+
+IEPageBot.prototype.clickElement = function(element) {
+
+    triggerEvent(element, 'focus', false);
+
+    var wasChecked = element.checked;
+
+    // Set a flag that records if the page will unload - this isn't always accurate, because
+    // <a href="javascript:alert('foo'):"> triggers the onbeforeunload event, even thought the page won't unload
+    var pageUnloading = false;
+    var pageUnloadDetector = function() {pageUnloading = true;};
+    this.currentWindow.attachEvent("onbeforeunload", pageUnloadDetector);
+
+    element.click();
+
+    // If the page is going to unload - still attempt to fire any subsequent events.
+    // However, we can't guarantee that the page won't unload half way through, so we need to handle exceptions.
+    try {
+        this.currentWindow.detachEvent("onbeforeunload", pageUnloadDetector);
+
+        if (this.windowClosed()) {
+            return;
+        }
+
+        // Onchange event is not triggered automatically in IE.
+        if (isDefined(element.checked) && wasChecked != element.checked) {
+            triggerEvent(element, 'change', true);
+        }
+
+        triggerEvent(element, 'blur', false);
+    }
+    catch (e) {
+        // If the page is unloading, we may get a "Permission denied" or "Unspecified error".
+        // Just ignore it, because the document may have unloaded.
+        if (pageUnloading) {
+            LOG.warn("Caught exception when firing events on unloading page: " + e.message);
+            return;
+        }
+        throw e;
+    }
+};
+
+PageBot.prototype.windowClosed = function(element) {
+    return this.currentWindow.closed;
+};
+
+PageBot.prototype.bodyText = function() {
+    return getText(this.currentDocument.body);
+};
+
+PageBot.prototype.getAllButtons = function() {
+    var elements = this.currentDocument.getElementsByTagName('input');
+    var result = '';
+
+    for (var i = 0; i < elements.length; i++) {
+        if (elements[i].type == 'button' || elements[i].type == 'submit' || elements[i].type == 'reset') {
+            result += elements[i].id;
+
+            result += ',';
+        }
+    }
+
+    return result;
+};
+
+
+PageBot.prototype.getAllFields = function() {
+    var elements = this.currentDocument.getElementsByTagName('input');
+    var result = '';
+
+    for (var i = 0; i < elements.length; i++) {
+        if (elements[i].type == 'text') {
+            result += elements[i].id;
+
+            result += ',';
+        }
+    }
+
+    return result;
+};
+
+PageBot.prototype.getAllLinks = function() {
+    var elements = this.currentDocument.getElementsByTagName('a');
+    var result = '';
+
+    for (var i = 0; i < elements.length; i++) {
+        result += elements[i].id;
+
+        result += ',';
+    }
+
+    return result;
+};
+
+PageBot.prototype.setContext = function(strContext, logLevel) {
+     //set the current test title
+    document.getElementById("context").innerHTML=strContext;
+    if (logLevel!=null) {
+    	LOG.setLogLevelThreshold(logLevel);
+    }
+};
+
+function isDefined(value) {
+    return typeof(value) != undefined;
+}
+
+PageBot.prototype.goBack = function() {
+    this.currentWindow.history.back();
+};
+
+PageBot.prototype.goForward = function() {
+    this.currentWindow.history.forward();
+};
+
+PageBot.prototype.close = function() {
+    this.currentWindow.eval("window.close();");
+};
+
+PageBot.prototype.refresh = function() {
+    this.currentWindow.location.reload(true);
+};
+
+/**
+ * Refine a list of elements using a filter.
+ */
+PageBot.prototype.selectElementsBy = function(filterType, filter, elements) {
+    var filterFunction = PageBot.filterFunctions[filterType];
+    if (! filterFunction) {
+        throw new SeleniumError("Unrecognised element-filter type: '" + filterType + "'");
+    }
+
+    return filterFunction(filter, elements);
+};
+
+PageBot.filterFunctions = {}; 
+
+PageBot.filterFunctions.name = function(name, elements) {
+    var selectedElements = [];
+    for (var i = 0; i < elements.length; i++) {
+        if (elements[i].name === name) {
+            selectedElements.push(elements[i]);
+        }
+    }
+    return selectedElements;
+};
+
+PageBot.filterFunctions.value = function(value, elements) {
+    var selectedElements = [];
+    for (var i = 0; i < elements.length; i++) {
+        if (elements[i].value === value) {
+            selectedElements.push(elements[i]);
+        }
+    }
+    return selectedElements;
+};
+
+PageBot.filterFunctions.index = function(index, elements) {
+    index = Number(index);
+    if (isNaN(index) || index < 0) {
+        throw new SeleniumError("Illegal Index: " + index);
+    }
+    if (elements.length <= index) {
+        throw new SeleniumError("Index out of range: " + index);
+    }
+    return [elements[index]];
+};
+
+PageBot.prototype.selectElements = function(filterExpr, elements, defaultFilterType) {    
+
+    var filterType = (defaultFilterType || 'value');
+    
+    // If there is a filter prefix, use the specified strategy
+    var result = filterExpr.match(/^([A-Za-z]+)=(.+)/);
+    if (result) {
+        filterType = result[1].toLowerCase();
+        filterExpr = result[2];
+    }
+
+    return this.selectElementsBy(filterType, filterExpr, elements);
+};

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserdetect.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserdetect.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserdetect.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,86 @@
+/*
+* Copyright 2004 ThoughtWorks, Inc
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*
+*/
+
+// Although it's generally better web development practice not to use browser-detection
+// (feature detection is better), the subtle browser differences that Selenium has to
+// work around seem to make it necessary. Maybe as we learn more about what we need,
+// we can do this in a more "feature-centric" rather than "browser-centric" way.
+
+BrowserVersion = function() {
+    this.name = navigator.appName;
+
+    if (window.opera != null)
+    {
+        this.browser = BrowserVersion.OPERA;
+        this.isOpera = true;
+        return;
+    }
+
+    if (this.name == "Microsoft Internet Explorer")
+    {
+        this.browser = BrowserVersion.IE;
+        this.isIE = true;
+        if (window.top.SeleniumHTARunner && window.top.document.location.pathname.match(/.hta$/i)) {
+        	this.isHTA = true;
+        }
+        return;
+    }
+
+    if (navigator.userAgent.indexOf('Safari') != -1)
+    {
+        this.browser = BrowserVersion.SAFARI;
+        this.isSafari = true;
+        this.khtml = true;
+        return;
+    }
+
+    if (navigator.userAgent.indexOf('Konqueror') != -1)
+    {
+        this.browser = BrowserVersion.KONQUEROR;
+        this.isKonqueror = true;
+        this.khtml = true;
+        return;
+    }
+
+    if (navigator.userAgent.indexOf('Firefox') != -1)
+    {
+        this.browser = BrowserVersion.FIREFOX;
+        this.isFirefox = true;
+        this.isGecko = true;
+        return;
+    }
+
+    if (navigator.userAgent.indexOf('Gecko') != -1)
+    {
+        this.browser = BrowserVersion.MOZILLA;
+        this.isMozilla = true;
+        this.isGecko = true;
+        return;
+    }
+
+    this.browser = BrowserVersion.UNKNOWN;
+}
+
+BrowserVersion.OPERA = "Opera";
+BrowserVersion.IE = "IE";
+BrowserVersion.KONQUEROR = "Konqueror";
+BrowserVersion.SAFARI = "Safari";
+BrowserVersion.FIREFOX = "Firefox";
+BrowserVersion.MOZILLA = "Mozilla";
+BrowserVersion.UNKNOWN = "Unknown";
+
+browserVersion = new BrowserVersion();

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-commandhandlers.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-commandhandlers.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-commandhandlers.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,371 @@
+/*
+* Copyright 2004 ThoughtWorks, Inc
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*
+*/
+function CommandHandlerFactory() {
+    this.actions = {};
+    this.asserts = {};
+    this.accessors = {};
+
+    var self = this;
+
+    this.registerAction = function(name, action, wait, dontCheckAlertsAndConfirms) {
+        var handler = new ActionHandler(action, wait, dontCheckAlertsAndConfirms);
+        this.actions[name] = handler;
+    };
+
+    this.registerAccessor = function(name, accessor) {
+        var handler = new AccessorHandler(accessor);
+        this.accessors[name] = handler;
+    };
+
+    this.registerAssert = function(name, assertion, haltOnFailure) {
+        var handler = new AssertHandler(assertion, haltOnFailure);
+        this.asserts[name] = handler;
+    };
+    
+    this.getCommandHandler = function(name) {
+        return this.actions[name] || this.accessors[name] || this.asserts[name] || null;
+    };
+
+    this.registerAll = function(commandObject) {
+        registerAllAccessors(commandObject);
+        registerAllActions(commandObject);
+        registerAllAsserts(commandObject);
+    };
+
+    var registerAllActions = function(commandObject) {
+        for (var functionName in commandObject) {
+            var result = /^do([A-Z].+)$/.exec(functionName);
+            if (result != null) {
+                var actionName = result[1].lcfirst();
+
+                // Register the action without the wait flag.
+                var action = commandObject[functionName];
+                self.registerAction(actionName, action, false, false);
+
+                // Register actionName + "AndWait" with the wait flag;
+                var waitActionName = actionName + "AndWait";
+                self.registerAction(waitActionName, action, true, false);
+            }
+        }
+    };
+
+ 
+    var registerAllAsserts = function(commandObject) {
+        for (var functionName in commandObject) {
+            var result = /^assert([A-Z].+)$/.exec(functionName);
+            if (result != null) {
+                var assert = commandObject[functionName];
+
+                // Register the assert with the "assert" prefix, and halt on failure.
+                var assertName = functionName;
+                self.registerAssert(assertName, assert, true);
+
+                // Register the assert with the "verify" prefix, and do not halt on failure.
+                var verifyName = "verify" + result[1];
+                self.registerAssert(verifyName, assert, false);
+            }
+        }
+    };
+
+    
+    // Given an accessor function getBlah(target),
+    // return a "predicate" equivalient to isBlah(target, value) that
+    // is true when the value returned by the accessor matches the specified value.
+    this.createPredicateFromSingleArgAccessor = function(accessor) {
+        return function(target, value) {
+            var accessorResult = accessor.call(this, target);
+            if (PatternMatcher.matches(value, accessorResult)) {
+                return new PredicateResult(true, "Actual value '" + accessorResult + "' did match '" + value + "'");
+            } else {
+                return new PredicateResult(false, "Actual value '" + accessorResult + "' did not match '" + value + "'");
+            }
+        };
+    };
+    
+    // Given a (no-arg) accessor function getBlah(),
+    // return a "predicate" equivalient to isBlah(value) that
+    // is true when the value returned by the accessor matches the specified value.
+    this.createPredicateFromNoArgAccessor = function(accessor) {
+        return function(value) {
+            var accessorResult = accessor.call(this);
+            if (PatternMatcher.matches(value, accessorResult)) {
+                return new PredicateResult(true, "Actual value '" + accessorResult + "' did match '" + value + "'");
+            } else {
+                return new PredicateResult(false, "Actual value '" + accessorResult + "' did not match '" + value + "'");
+            }
+        };
+    };
+        
+    // Given a boolean accessor function isBlah(),
+    // return a "predicate" equivalient to isBlah() that
+    // returns an appropriate PredicateResult value.
+    this.createPredicateFromBooleanAccessor = function(accessor) {
+        return function() {
+        	var accessorResult;
+        	if (arguments.length > 2) throw new SeleniumError("Too many arguments! " + arguments.length);
+        	if (arguments.length == 2) {
+            	accessorResult = accessor.call(this, arguments[0], arguments[1]);
+            } else if (arguments.length == 1) {
+            	accessorResult = accessor.call(this, arguments[0]);
+            } else {
+            	accessorResult = accessor.call(this);
+            }
+            if (accessorResult) {
+                return new PredicateResult(true, "true");
+            } else {
+                return new PredicateResult(false, "false");
+            }
+        };
+    };
+    
+    // Given an accessor fuction getBlah([target])  (target is optional)
+    // return a predicate equivalent to isBlah([target,] value) that
+    // is true when the value returned by the accessor matches the specified value.
+    this.createPredicateFromAccessor = function(accessor) {
+		if (accessor.length == 0) {
+            return self.createPredicateFromNoArgAccessor(accessor);
+        }
+        return self.createPredicateFromSingleArgAccessor(accessor);
+    };
+    
+    // Given a predicate, return the negation of that predicate.
+    // Leaves the message unchanged.
+    // Used to create assertNot, verifyNot, and waitForNot commands.
+    this.invertPredicate = function(predicate) {
+        return function(target, value) {
+            var result = predicate.call(this, target, value);
+            result.isTrue = ! result.isTrue;
+            return result;
+        };
+    };
+    
+    // Convert an isBlahBlah(target, value) function into an assertBlahBlah(target, value) function.
+    this.createAssertionFromPredicate = function(predicate) {
+    	return function(target, value) {
+    		var result = predicate.call(this, target, value);
+    		if (!result.isTrue) {
+    			Assert.fail(result.message);
+    		}
+    	};
+    };
+    
+    // Register an assertion, a verification, a negative assertion,
+    // and a negative verification based on the specified accessor.
+    this.registerAssertionsBasedOnAccessor = function(accessor, baseName, predicate) {
+        if (predicate==null) {
+            predicate = self.createPredicateFromAccessor(accessor);
+        }
+        var assertion = self.createAssertionFromPredicate(predicate);
+        // Register an assert with the "assert" prefix, and halt on failure.
+        self.registerAssert("assert" + baseName, assertion, true);
+        // Register a verify with the "verify" prefix, and do not halt on failure.
+        self.registerAssert("verify" + baseName, assertion, false);
+        
+        var invertedPredicate = self.invertPredicate(predicate);
+        var negativeAssertion = self.createAssertionFromPredicate(invertedPredicate);
+        
+        var result = /^(.*)Present$/.exec(baseName);
+        if (result==null) {
+            // Register an assertNot with the "assertNot" prefix, and halt on failure.
+            self.registerAssert("assertNot"+baseName, negativeAssertion, true);
+            // Register a verifyNot with the "verifyNot" prefix, and do not halt on failure.
+            self.registerAssert("verifyNot"+baseName, negativeAssertion, false);
+        }
+        else {
+            var invertedBaseName = result[1] + "NotPresent";
+        
+            // Register an assertNot ending w/ "NotPresent", and halt on failure.
+            self.registerAssert("assert"+invertedBaseName, negativeAssertion, true);
+            // Register an assertNot ending w/ "NotPresent", and do not halt on failure.
+            self.registerAssert("verify"+invertedBaseName, negativeAssertion, false);
+        }
+    };
+    
+    
+    // Convert an isBlahBlah(target, value) function into a waitForBlahBlah(target, value) function.
+    this.createWaitForActionFromPredicate = function(predicate) {
+    	var action = function(target, value) {
+    		var seleniumApi = this;
+		    testLoop.waitForCondition = function () {
+		    	try {
+				    return predicate.call(seleniumApi, target, value).isTrue;
+				} catch (e) {
+					// Treat exceptions as meaning the condition is not yet met.
+					// Useful, for example, for waitForValue when the element has
+					// not even been created yet.
+					// TODO: possibly should rethrow some types of exception.
+					return false;
+				}
+		    };
+    	};
+    	return action;
+    };
+    
+    // Register a waitForBlahBlah and waitForNotBlahBlah based on the specified accessor.
+    this.registerWaitForCommandsBasedOnAccessor = function(accessor, baseName, predicate) {
+        if (predicate==null) {
+            predicate = self.createPredicateFromAccessor(accessor);
+        }
+        var waitForAction = self.createWaitForActionFromPredicate(predicate);
+    	self.registerAction("waitFor"+baseName, waitForAction, false, accessor.dontCheckAlertsAndConfirms);
+        var invertedPredicate = self.invertPredicate(predicate);
+        var waitForNotAction = self.createWaitForActionFromPredicate(invertedPredicate);
+	   	self.registerAction("waitForNot"+baseName, waitForNotAction, false, accessor.dontCheckAlertsAndConfirms);
+	}
+	
+	// Register a storeBlahBlah based on the specified accessor.
+    this.registerStoreCommandBasedOnAccessor = function(accessor, baseName) {
+        var action;
+        if (accessor.length == 1) {
+	    	action = function(target, varName) {
+			    storedVars[varName] = accessor.call(this, target);
+	    	};
+	    } else {
+	    	action = function(varName) {
+			    storedVars[varName] = accessor.call(this);
+	    	};
+	    }
+    	self.registerAction("store"+baseName, action, false, accessor.dontCheckAlertsAndConfirms);
+    };
+        
+    // Methods of the form getFoo(target) result in commands:
+    // getFoo, assertFoo, verifyFoo, assertNotFoo, verifyNotFoo
+    // storeFoo, waitForFoo, and waitForNotFoo.
+    var registerAllAccessors = function(commandObject) {
+        for (var functionName in commandObject) {
+            var match = /^get([A-Z].+)$/.exec(functionName);
+            if (match != null) {
+                var accessor = commandObject[functionName];
+                var baseName = match[1];
+                self.registerAccessor(functionName, accessor);
+                self.registerAssertionsBasedOnAccessor(accessor, baseName);
+                self.registerStoreCommandBasedOnAccessor(accessor, baseName);
+                self.registerWaitForCommandsBasedOnAccessor(accessor, baseName);
+            }
+            var match = /^is([A-Z].+)$/.exec(functionName);
+            if (match != null) {
+                var accessor = commandObject[functionName];
+                var baseName = match[1];
+                var predicate = self.createPredicateFromBooleanAccessor(accessor);
+                self.registerAccessor(functionName, accessor);
+                self.registerAssertionsBasedOnAccessor(accessor, baseName, predicate);
+                self.registerStoreCommandBasedOnAccessor(accessor, baseName);
+                self.registerWaitForCommandsBasedOnAccessor(accessor, baseName, predicate);
+            }
+        }
+    };
+    
+    
+}
+
+function PredicateResult(isTrue, message) {
+    this.isTrue = isTrue;
+    this.message = message;
+}
+
+// NOTE: The CommandHandler is effectively an abstract base for
+// various handlers including ActionHandler, AccessorHandler and AssertHandler.
+// Subclasses need to implement an execute(seleniumApi, command) function,
+// where seleniumApi is the Selenium object, and command a SeleniumCommand object.
+function CommandHandler(type, haltOnFailure, executor) {
+    this.type = type;
+    this.haltOnFailure = haltOnFailure;
+    this.executor = executor;
+}
+
+// An ActionHandler is a command handler that executes the sepcified action,
+// possibly checking for alerts and confirmations (if checkAlerts is set), and
+// possibly waiting for a page load if wait is set.
+function ActionHandler(action, wait, dontCheckAlerts) {
+    CommandHandler.call(this, "action", true, action);
+    if (wait) {
+        this.wait = true;
+    }
+    // note that dontCheckAlerts could be undefined!!!
+    this.checkAlerts = (dontCheckAlerts) ? false : true;
+}
+ActionHandler.prototype = new CommandHandler;
+ActionHandler.prototype.execute = function(seleniumApi, command) {
+    if (this.checkAlerts && (null==/(Alert|Confirmation)(Not)?Present/.exec(command.command))) {
+	this.checkForAlerts(seleniumApi);
+    }
+    var processState = this.executor.call(seleniumApi, command.target, command.value);
+    // If the handler didn't return a wait flag, check to see if the
+    // handler was registered with the wait flag.
+    if (processState == undefined && this.wait) {
+        processState = SELENIUM_PROCESS_WAIT;
+    }
+    return new CommandResult(processState);
+};
+ActionHandler.prototype.checkForAlerts = function(seleniumApi) {
+    if ( seleniumApi.browserbot.hasAlerts() ) {
+        throw new SeleniumError("There was an unexpected Alert! [" + seleniumApi.browserbot.getNextAlert() + "]");
+    }
+    if ( seleniumApi.browserbot.hasConfirmations() ) {
+        throw new SeleniumError("There was an unexpected Confirmation! [" + seleniumApi.browserbot.getNextConfirmation() + "]");
+    }
+};
+
+function AccessorHandler(accessor) {
+    CommandHandler.call(this, "accessor", true, accessor);
+}
+AccessorHandler.prototype = new CommandHandler;
+AccessorHandler.prototype.execute = function(seleniumApi, command) {
+    var returnValue = this.executor.call(seleniumApi, command.target, command.value);
+    var result = new CommandResult();
+    result.result = returnValue;
+    return result;
+};
+
+/**
+ * Handler for assertions and verifications.
+ */
+function AssertHandler(assertion, haltOnFailure) {
+    CommandHandler.call(this, "assert", haltOnFailure || false, assertion);
+}
+AssertHandler.prototype = new CommandHandler;
+AssertHandler.prototype.execute = function(seleniumApi, command) {
+    var result = new CommandResult();
+    try {
+        this.executor.call(seleniumApi, command.target, command.value);
+        result.passed = true;
+    } catch (e) {
+        // If this is not a AssertionFailedError, or we should haltOnFailure, rethrow.
+        if (!e.isAssertionFailedError) {
+            throw e;
+        }
+        if (this.haltOnFailure) {
+            var error = new SeleniumError(e.failureMessage);
+            throw error;
+        }
+        result.failed = true;
+        result.failureMessage = e.failureMessage;
+    }
+    return result;
+};
+
+
+function CommandResult(processState) {
+    this.processState = processState;
+    this.result = null;
+}
+
+function SeleniumCommand(command, target, value) {
+    this.command = command;
+    this.target = target;
+    this.value = value;
+}

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-executionloop.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-executionloop.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-executionloop.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,266 @@
+/*
+* Copyright 2004 ThoughtWorks, Inc
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+SELENIUM_PROCESS_WAIT = "wait";
+
+function TestLoop(commandFactory) {
+
+    this.commandFactory = commandFactory;
+    this.waitForConditionTimeout = 30 * 1000; // 30 seconds
+
+    this.start = function() {
+        selenium.reset();
+        LOG.debug("testLoop.start()");
+        this.continueTest();
+    };
+
+    /**
+     * Select the next command and continue the test.
+     */
+    this.continueTest = function() {
+    	LOG.debug("testLoop.continueTest() - acquire the next command");
+        if (! this.aborted) {
+            this.currentCommand = this.nextCommand();
+        }
+        if (! this.requiresCallBack) {
+        	this.beginNextTest();
+        } // otherwise, just finish and let the callback invoke beginNextTest()
+    };
+    
+    this.beginNextTest = function() {
+    	LOG.debug("testLoop.beginNextTest()");
+    	if (this.currentCommand) {
+            // TODO: rename commandStarted to commandSelected, OR roll it into nextCommand
+            this.commandStarted(this.currentCommand);
+            this.resumeAfterDelay();
+        } else {
+            this.testComplete();
+        }
+    }
+    
+    /**
+     * Pause, then execute the current command.
+     */
+    this.resumeAfterDelay = function() {
+
+        // Get the command delay. If a pauseInterval is set, use it once
+        // and reset it.  Otherwise, use the defined command-interval.
+        var delay = this.pauseInterval || this.getCommandInterval();
+        this.pauseInterval = undefined;
+
+        if (delay < 0) {
+            // Pause: enable the "next/continue" button
+            this.pause();
+        } else {
+            window.setTimeout("testLoop.resume()", delay);
+        }
+    };
+
+    /**
+     * Select the next command and continue the test.
+     */
+    this.resume = function() {
+    	LOG.debug("testLoop.resume() - actually execute");
+        try {
+            this.executeCurrentCommand();
+            this.waitForConditionStart = new Date().getTime();
+            this.continueTestWhenConditionIsTrue();
+        } catch (e) {
+            this.handleCommandError(e);
+            this.testComplete();
+            return;
+        }
+    };
+
+    /**
+     * Execute the current command.  
+     * 
+     * The return value, if not null, should be a function which will be
+     * used to determine when execution can continue.
+     */
+    this.executeCurrentCommand = function() {
+
+        var command = this.currentCommand;
+        LOG.info("Executing: |" + command.command + " | " + command.target + " | " + command.value + " |");
+        
+        var handler = this.commandFactory.getCommandHandler(command.command);
+        if (handler == null) {
+            throw new SeleniumError("Unknown command: '" + command.command + "'");
+        }
+        
+        command.target = selenium.preprocessParameter(command.target);
+        command.value = selenium.preprocessParameter(command.value);
+        LOG.debug("Command found, going to execute " + command.command);
+        var result = handler.execute(selenium, command);
+		LOG.debug("Command complete");
+        this.commandComplete(result);
+
+        if (result.processState == SELENIUM_PROCESS_WAIT) {
+            this.waitForCondition = function() {
+            	LOG.debug("Checking condition: isNewPageLoaded?");
+                return selenium.browserbot.isNewPageLoaded();
+            };
+        }
+    };
+    
+    this.handleCommandError = function(e) {
+       if (!e.isSeleniumError) {
+            LOG.exception(e);
+            var msg = "Selenium failure. Please report to selenium-dev at openqa.org, with error details from the log window.";
+            if (e.message) {
+               msg += "  The error message is: " + e.message;
+            }
+            this.commandError(msg);
+        } else {
+            LOG.error(e.message);
+            this.commandError(e.message);
+        }
+    };
+
+    /**
+     * Busy wait for waitForCondition() to become true, and then carry on
+     * with test.  Fail the current test if there's a timeout or an exception.
+     */
+    this.continueTestWhenConditionIsTrue = function () {
+    	LOG.debug("testLoop.continueTestWhenConditionIsTrue()");
+        try {
+            if (this.waitForCondition == null || this.waitForCondition()) {
+            	LOG.debug("condition satisfied; let's continueTest()");
+	            this.waitForCondition = null;
+	            this.waitForConditionStart = null;
+	            this.continueTest();
+	        } else {
+	        	LOG.debug("waitForCondition was false; keep waiting!");
+	        	if (this.waitForConditionTimeout != null) {
+		        	var now = new Date();
+		        	if ((now - this.waitForConditionStart) > this.waitForConditionTimeout) {
+		        		throw new SeleniumError("Timed out after " + this.waitForConditionTimeout + "ms");
+		        	}
+		        }
+	            window.setTimeout("testLoop.continueTestWhenConditionIsTrue()", 10);
+	        }
+	    } catch (e) {
+	    	var lastResult = new CommandResult();
+    		lastResult.failed = true;
+    		lastResult.failureMessage = e.message;
+	    	this.commandComplete(lastResult);
+	    	this.testComplete();
+	    }
+    };
+
+}
+
+/** The default is not to have any interval between commands. */
+TestLoop.prototype.getCommandInterval = function() {
+    return 0;
+};
+
+TestLoop.prototype.nextCommand = noop;
+
+TestLoop.prototype.commandStarted = noop;
+
+TestLoop.prototype.commandError = noop;
+
+TestLoop.prototype.commandComplete = noop;
+
+TestLoop.prototype.testComplete = noop;
+
+TestLoop.prototype.pause = noop;
+
+function noop() {
+
+};
+
+/**
+ * Tell Selenium to expect a failure on the next command execution. This
+ * command temporarily installs a CommandFactory that generates
+ * CommandHandlers that expect a failure.
+ */
+Selenium.prototype.assertFailureOnNext = function(message) {
+    if (!message) {
+        throw new Error("Message must be provided");
+    }
+
+    var expectFailureCommandFactory =
+        new ExpectFailureCommandFactory(testLoop.commandFactory, message, "failure");
+    expectFailureCommandFactory.baseExecutor = executeCommandAndReturnFailureMessage;
+    testLoop.commandFactory = expectFailureCommandFactory;
+};
+
+/**
+ * Tell Selenium to expect an error on the next command execution. This
+ * command temporarily installs a CommandFactory that generates
+ * CommandHandlers that expect a failure.
+ */
+Selenium.prototype.assertErrorOnNext = function(message) {
+    if (!message) {
+        throw new Error("Message must be provided");
+    }
+
+    var expectFailureCommandFactory =
+        new ExpectFailureCommandFactory(testLoop.commandFactory, message, "error");
+    expectFailureCommandFactory.baseExecutor = executeCommandAndReturnErrorMessage;
+    testLoop.commandFactory = expectFailureCommandFactory;
+};
+
+function ExpectFailureCommandFactory(originalCommandFactory, expectedErrorMessage, errorType) {
+    this.getCommandHandler = function(name) {
+        var baseHandler = originalCommandFactory.getCommandHandler(name);
+        var baseExecutor = this.baseExecutor;
+        var expectFailureCommand = {};
+        expectFailureCommand.execute = function() {
+            var baseFailureMessage = baseExecutor(baseHandler, arguments);
+            var result = new CommandResult();
+            if (!baseFailureMessage) {
+                result.failed = true;
+                result.failureMessage = "Expected " + errorType + " did not occur.";
+            }
+            else {
+                if (! PatternMatcher.matches(expectedErrorMessage, baseFailureMessage)) {
+                    result.failed = true;
+                    result.failureMessage = "Expected " + errorType + " message '" + expectedErrorMessage
+                                            + "' but was '" + baseFailureMessage + "'";
+                }
+                else {
+                    result.passed = true;
+                    result.result = baseFailureMessage;
+                }
+            }
+            testLoop.commandFactory = originalCommandFactory;
+            return result;
+        };
+        return expectFailureCommand;
+    };
+};
+
+function executeCommandAndReturnFailureMessage(baseHandler, originalArguments) {
+    var baseResult = baseHandler.execute.apply(baseHandler, originalArguments);
+    if (baseResult.passed) {
+        return null;
+    }
+    return baseResult.failureMessage;
+};
+
+function executeCommandAndReturnErrorMessage(baseHandler, originalArguments) {
+    try {
+        baseHandler.execute.apply(baseHandler, originalArguments);
+        return null;
+    }
+    catch (expected) {
+        return expected.message;
+    }
+};
+

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-logging.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-logging.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-logging.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,119 @@
+/*
+* Copyright 2004 ThoughtWorks, Inc
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*/
+
+var Logger = function() {
+    this.logWindow = null;
+}
+Logger.prototype = {
+
+    setLogLevelThreshold: function(logLevel) {
+    	this.pendingLogLevelThreshold = logLevel;
+        this.show();
+        //
+        // The following message does not show up in the log -- _unless_ I step along w/ the debugger
+        // down to the append call.  I believe this is because the new log window has not yet loaded,
+        // and therefore the log msg is discarded; but if I step through the debugger, this changes
+        // the scheduling so as to load that window and make it ready.
+        // this.info("Log level programmatically set to " + logLevel + " (presumably by driven-mode test code)");
+    },
+
+    getLogWindow: function() {
+        if (this.logWindow && this.logWindow.closed) {
+            this.logWindow = null;
+        }
+        if (this.logWindow && this.pendingLogLevelThreshold && this.logWindow.setThresholdLevel) {
+            this.logWindow.setThresholdLevel(this.pendingLogLevelThreshold);
+            
+            // can't just directly log because that action would loop back to this code infinitely
+            this.pendingInfoMessage = "Log level programmatically set to " + this.pendingLogLevelThreshold + " (presumably by driven-mode test code)";
+            
+            this.pendingLogLevelThreshold = null;	// let's only go this way one time
+        }
+
+        return this.logWindow;
+    },
+    
+    openLogWindow: function() {
+        this.logWindow = window.open(
+            "SeleniumLog.html", "SeleniumLog",
+            "width=600,height=250,bottom=0,right=0,status,scrollbars,resizable"
+        );
+        return this.logWindow;
+    },
+    
+    show: function() {
+        if (! this.getLogWindow()) {
+            this.openLogWindow();
+        }
+    },
+
+    log: function(message, className) {
+        var logWindow = this.getLogWindow();
+        if (logWindow) {
+            if (logWindow.append) {
+            	if (this.pendingInfoMessage) {
+ 		    logWindow.append(this.pendingInfoMessage, "info");
+                    this.pendingInfoMessage = null;
+                }
+                logWindow.append(message, className);
+            }
+        }
+    },
+
+    close: function(message) {
+    	if (this.logWindow != null) {
+        	this.logWindow.close();
+        	this.logWindow = null;
+        }
+    },
+
+    debug: function(message) {
+        this.log(message, "debug");
+    },
+
+    info: function(message) {
+        this.log(message, "info");
+    },
+
+    warn: function(message) {
+        this.log(message, "warn");
+    },
+
+    error: function(message) {
+        this.log(message, "error");
+    },
+
+    exception: function(exception) {
+        var msg = "Unexpected Exception: " + describe(exception, ', ');
+        this.error(msg);
+    }
+
+};
+
+var LOG = new Logger();
+
+function noop() {};
+
+var DummyLogger = function() {};
+DummyLogger.prototype = {
+    show: noop,
+    log: noop,
+    debug: noop,
+    info: noop,
+    warn: noop,
+    error: noop
+};
+

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-seleneserunner.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-seleneserunner.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-seleneserunner.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,264 @@
+/*
+* Copyright 2005 ThoughtWorks, Inc
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*
+*/
+
+passColor = "#cfffcf";
+failColor = "#ffcfcf";
+errorColor = "#ffffff";
+workingColor = "#DEE7EC";
+doneColor = "#FFFFCC";
+
+slowMode = false;
+
+var cmd1 = document.createElement("div");
+var cmd2 = document.createElement("div");
+var cmd3 = document.createElement("div");
+var cmd4 = document.createElement("div");
+
+var postResult = "START";
+
+function runTest() {
+    var testAppFrame = document.getElementById('myiframe');
+    selenium = Selenium.createForFrame(testAppFrame);
+
+    commandFactory = new CommandHandlerFactory();
+    commandFactory.registerAll(selenium);
+
+    testLoop = new TestLoop(commandFactory);
+
+    testLoop.nextCommand = nextCommand;
+    testLoop.commandStarted = commandStarted;
+    testLoop.commandComplete = commandComplete;
+    testLoop.commandError = commandError;
+    testLoop.requiresCallBack = true;
+    testLoop.testComplete = function() {
+    	window.status = "Selenium Tests Complete, for this Test"
+    	// Continue checking for new results
+    	testLoop.continueTest();
+    	postResult = "START";
+    };
+
+    document.getElementById("commandList").appendChild(cmd4);
+    document.getElementById("commandList").appendChild(cmd3);
+    document.getElementById("commandList").appendChild(cmd2);
+    document.getElementById("commandList").appendChild(cmd1);
+    
+    var doContinue = getQueryVariable("continue");
+	if (doContinue != null) postResult = "OK";
+
+    testLoop.start();
+}
+
+function getQueryVariable(variable) {
+    var query = window.location.search.substring(1);
+    var vars = query.split("&");
+    for (var i=0;i<vars.length;i++) {
+        var pair = vars[i].split("=");
+        if (pair[0] == variable) {
+            return pair[1];
+        }
+    }
+}
+
+function buildBaseUrl() {
+	var lastSlash = window.location.href.lastIndexOf('/');
+	var baseUrl = window.location.href.substring(0, lastSlash+1);
+	return baseUrl;
+}
+
+function buildDriverParams() {
+    var params = "";
+
+    var host = getQueryVariable("driverhost");
+    var port = getQueryVariable("driverport");
+    if (host != undefined && port != undefined) {
+        params = params + "&driverhost=" + host + "&driverport=" + port;
+    }
+
+    var sessionId = getQueryVariable("sessionId");
+    if (sessionId != undefined) {
+        params = params + "&sessionId=" + sessionId;
+    }
+
+    return params;
+}
+
+function preventBrowserCaching() {
+    var t = (new Date()).getTime();
+    return "&counterToMakeURsUniqueAndSoStopPageCachingInTheBrowser=" + t;
+}   
+
+function nextCommand() {
+    xmlHttp = XmlHttp.create();
+    try {
+    	
+    	var url = buildBaseUrl();
+        if (postResult == "START") {
+        	url = url + "driver/?seleniumStart=true" + buildDriverParams() + preventBrowserCaching();
+        } else {
+        	url = url + "driver/?" + buildDriverParams() + preventBrowserCaching();
+        }
+        LOG.debug("XMLHTTPRequesting " + url);
+        xmlHttp.open("POST", url, true);
+        xmlHttp.onreadystatechange=handleHttpResponse;
+        xmlHttp.send(postResult);
+    } catch(e) {
+       	var s = 'xmlHttp returned:\n'
+        for (key in e) {
+            s += "\t" + key + " -> " + e[key] + "\n"
+        }
+        LOG.error(s);
+        return null;
+    }
+    return null;
+}
+
+ function handleHttpResponse() {
+ 	if (xmlHttp.readyState == 4) {
+ 		if (xmlHttp.status == 200) {
+ 			var command = extractCommand(xmlHttp);
+ 			testLoop.currentCommand = command;
+ 			testLoop.beginNextTest();
+ 		} else {
+ 			var s = 'xmlHttp returned: ' + xmlHttp.status + ": " + xmlHttp.statusText;
+ 			LOG.error(s);
+ 			testLoop.currentCommand = null;
+ 			setTimeout("testLoop.beginNextTest();", 2000);
+ 		}
+ 		
+ 	}
+ }
+
+
+function extractCommand(xmlHttp) {
+    if (slowMode) {
+        delay(2000);
+    }
+
+    var command;
+    try {
+        command = xmlHttp.responseText;
+    } catch (e) {
+        alert('could not get responseText: ' + e.message);
+    }
+    if (command.substr(0,'|testComplete'.length)=='|testComplete') {
+        return null;
+    }
+
+    return createCommandFromRequest(command);
+}
+
+function commandStarted(command) {
+    commandNode = document.createElement("div");
+    innerHTML = command.command + '(';
+    if (command.target != null && command.target != "") {
+        innerHTML += command.target;
+        if (command.value != null && command.value != "") {
+            innerHTML += ', ' + command.value;
+        }
+    }
+    innerHTML += ")";
+    commandNode.innerHTML = innerHTML;
+    commandNode.style.backgroundColor = workingColor;
+    document.getElementById("commandList").removeChild(cmd1);
+    document.getElementById("commandList").removeChild(cmd2);
+    document.getElementById("commandList").removeChild(cmd3);
+    document.getElementById("commandList").removeChild(cmd4);
+    cmd4 = cmd3;
+    cmd3 = cmd2;
+    cmd2 = cmd1;
+    cmd1 = commandNode;
+    document.getElementById("commandList").appendChild(cmd4);
+    document.getElementById("commandList").appendChild(cmd3);
+    document.getElementById("commandList").appendChild(cmd2);
+    document.getElementById("commandList").appendChild(cmd1);
+}
+
+function commandComplete(result) {
+    if (result.failed) {
+    	if (postResult == "CONTINUATION") {
+    		testLoop.aborted = true;
+    	}
+        postResult = result.failureMessage;
+        commandNode.title = result.failureMessage;
+        commandNode.style.backgroundColor = failColor;
+    } else if (result.passed) {
+        postResult = "OK";
+        commandNode.style.backgroundColor = passColor;
+    } else {
+    	if (result.result == null) {
+    		postResult = "OK";
+    	} else {
+    		postResult = "OK," + result.result;
+    	}
+        commandNode.style.backgroundColor = doneColor;
+    }
+}
+
+function commandError(message) {
+    postResult = "ERROR: " + message;
+    commandNode.style.backgroundColor = errorColor;
+    commandNode.title = message;
+}
+
+function slowClicked() {
+    slowMode = !slowMode;
+}
+
+function delay(millis) {
+    startMillis = new Date();
+    while (true) {
+        milli = new Date();
+        if (milli-startMillis > millis) {
+            break;
+        }
+    }
+}
+
+function getIframeDocument(iframe) {
+    if (iframe.contentDocument) {
+        return iframe.contentDocument;
+    }
+    else {
+        return iframe.contentWindow.document;
+    }
+}
+
+// Parses a URI query string into a SeleniumCommand object
+function createCommandFromRequest(commandRequest) {
+	//decodeURIComponent doesn't strip plus signs
+	var processed = commandRequest.replace(/\+/g, "%20");
+	// strip trailing spaces
+	var processed = processed.replace(/\s+$/, "");
+    var vars = processed.split("&");
+    var cmdArgs = new Object();
+    for (var i=0;i<vars.length;i++) {
+        var pair = vars[i].split("=");
+        cmdArgs[pair[0]] = pair[1];
+    }
+    var cmd = cmdArgs['cmd'];
+    var arg1 = cmdArgs['1'];
+    if (null == arg1) arg1 = "";
+    arg1 = decodeURIComponent(arg1);
+    var arg2 = cmdArgs['2'];
+    if (null == arg2) arg2 = "";
+    arg2 = decodeURIComponent(arg2);
+    if (cmd == null) {
+    	throw new Error("Bad command request: " + commandRequest);
+    }
+    return new SeleniumCommand(cmd, arg1, arg2);
+}
+

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-testrunner.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-testrunner.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-testrunner.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,742 @@
+/*
+* Copyright 2004 ThoughtWorks, Inc
+*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+*  limitations under the License.
+*
+*/
+
+// The current row in the list of tests (test suite)
+currentRowInSuite = 0;
+
+// An object representing the current test
+currentTest = null;
+
+// Whether or not the jsFT should run all tests in the suite
+runAllTests = false;
+
+// Whether or not the current test has any errors;
+testFailed = false;
+suiteFailed = false;
+
+// Colors used to provide feedback
+passColor = "#ccffcc";
+doneColor = "#eeffee";
+failColor = "#ffcccc";
+workingColor = "#ffffcc";
+
+// Holds the handlers for each command.
+commandHandlers = null;
+
+// The number of tests run
+numTestPasses = 0;
+
+// The number of tests that have failed
+numTestFailures = 0;
+
+// The number of commands which have passed
+numCommandPasses = 0;
+
+// The number of commands which have failed
+numCommandFailures = 0;
+
+// The number of commands which have caused errors (element not found)
+numCommandErrors = 0;
+
+// The time that the test was started.
+startTime = null;
+
+// The current time.
+currentTime = null;
+
+// An simple enum for failureType
+ERROR = 0;
+FAILURE = 1;
+
+runInterval = 0;
+
+queryString = null;
+
+function setRunInterval() {
+    // Get the value of the checked runMode option.
+    // There should be a way of getting the value of the "group", but I don't know how.
+    var runModeOptions = document.forms['controlPanel'].runMode;
+    for (var i = 0; i < runModeOptions.length; i++) {
+        if (runModeOptions[i].checked) {
+            runInterval = runModeOptions[i].value;
+            break;
+        }
+    }
+}
+
+function continueCurrentTest() {
+    document.getElementById('continueTest').disabled = true;
+    testLoop.resume();
+}
+
+function getApplicationFrame() {
+    return document.getElementById('myiframe');
+}
+
+function getSuiteFrame() {
+    return document.getElementById('testSuiteFrame');
+}
+
+function getTestFrame(){
+    return document.getElementById('testFrame');
+}
+
+function loadAndRunIfAuto() {
+    loadSuiteFrame();
+}
+
+function start() {
+	queryString = null;
+    setRunInterval();
+    loadSuiteFrame();
+}
+
+function loadSuiteFrame() {
+    var testAppFrame = document.getElementById('myiframe');
+    selenium = Selenium.createForFrame(testAppFrame);
+    registerCommandHandlers();
+
+    //set the runInterval if there is a queryParameter for it
+    var tempRunInterval = getQueryParameter("runInterval");
+    if (tempRunInterval) {
+        runInterval = tempRunInterval;
+    }
+
+    document.getElementById("modeRun").onclick = setRunInterval;
+    document.getElementById('modeWalk').onclick = setRunInterval;
+    document.getElementById('modeStep').onclick = setRunInterval;
+    document.getElementById('continueTest').onclick = continueCurrentTest;
+
+    var testSuiteName = getQueryParameter("test");
+
+    if (testSuiteName) {
+        addLoadListener(getSuiteFrame(), onloadTestSuite);
+        getSuiteFrame().src = testSuiteName;
+    } else {
+        onloadTestSuite();
+    }
+}
+
+function startSingleTest() {
+    removeLoadListener(getApplicationFrame(), startSingleTest);
+    var singleTestName = getQueryParameter("singletest");
+    addLoadListener(getTestFrame(), startTest);
+    getTestFrame().src = singleTestName;
+}
+
+function getIframeDocument(iframe)
+{
+    if (iframe.contentDocument) {
+        return iframe.contentDocument;
+    }
+    else {
+        return iframe.contentWindow.document;
+    }
+}
+
+function onloadTestSuite() {
+    removeLoadListener(getSuiteFrame(), onloadTestSuite);
+    
+    // Add an onclick function to each link in all suite tables
+    var allTables = getIframeDocument(getSuiteFrame()).getElementsByTagName("table");
+    for (var tableNum = 0; tableNum < allTables.length; tableNum++)
+    {
+        var skippedTable = allTables[tableNum];
+        for(rowNum = 1;rowNum < skippedTable.rows.length; rowNum++) {
+            addOnclick(skippedTable, rowNum);
+        }
+    }
+
+    suiteTable = getIframeDocument(getSuiteFrame()).getElementsByTagName("table")[0];
+    if (suiteTable!=null) {
+
+        if (isAutomatedRun()) {
+	    startTestSuite();
+        } else if (getQueryParameter("autoURL")) {
+
+            addLoadListener(getApplicationFrame(), startSingleTest);
+
+	    getApplicationFrame().src = getQueryParameter("autoURL");
+
+	} else {
+            testLink = suiteTable.rows[currentRowInSuite+1].cells[0].getElementsByTagName("a")[0];
+            getTestFrame().src = testLink.href;
+        }
+    }
+}
+
+// Adds an onclick function to the link in the given row in suite table.
+// This function checks whether the test has already been run and the data is
+// stored. If the data is stored, it sets the test frame to be the stored data.
+// Otherwise, it loads the fresh page.
+function addOnclick(suiteTable, rowNum) {
+    aLink = suiteTable.rows[rowNum].cells[0].getElementsByTagName("a")[0];
+    aLink.onclick = function(eventObj) {
+        srcObj = null;
+
+        // For mozilla-like browsers
+        if(eventObj)
+                srcObj = eventObj.target;
+
+        // For IE-like browsers
+        else if (getSuiteFrame().contentWindow.event)
+                srcObj = getSuiteFrame().contentWindow.event.srcElement;
+
+        // The target row (the event source is not consistently reported by browsers)
+        row = srcObj.parentNode.parentNode.rowIndex || srcObj.parentNode.parentNode.parentNode.rowIndex;
+
+        // If the row has a stored results table, use that
+        if(suiteTable.rows[row].cells[1]) {
+            var bodyElement = getIframeDocument(getTestFrame()).body;
+
+            // Create a div element to hold the results table.
+            var tableNode = getIframeDocument(getTestFrame()).createElement("div");
+            var resultsCell = suiteTable.rows[row].cells[1];
+            tableNode.innerHTML = resultsCell.innerHTML;
+
+            // Append this text node, and remove all the preceding nodes.
+            bodyElement.appendChild(tableNode);
+            while (bodyElement.firstChild != bodyElement.lastChild) {
+                bodyElement.removeChild(bodyElement.firstChild);
+            }
+        }
+        // Otherwise, just open up the fresh page.
+        else {
+            getTestFrame().src = suiteTable.rows[row].cells[0].getElementsByTagName("a")[0].href;
+        }
+
+        return false;
+    };
+}
+
+function isQueryParameterTrue(name) {
+    parameterValue = getQueryParameter(name);
+    return (parameterValue != null && parameterValue.toLowerCase() == "true");
+}
+
+function getQueryString() {
+	if (queryString != null) return queryString;
+	if (browserVersion.isHTA) {
+		var args = extractArgs();
+		if (args.length < 2) return null;
+		queryString = args[1];
+		return queryString;
+	} else {
+		return location.search.substr(1);
+	}
+}
+
+function extractArgs() {
+	var str = SeleniumHTARunner.commandLine;
+	if (str == null || str == "") return new Array();
+    var matches = str.match(/(?:"([^"]+)"|(?!"([^"]+)")\b(\S+)\b)/g);
+    // We either want non quote stuff ([^"]+) surrounded by quotes
+    // or we want to look-ahead, see that the next character isn't
+    // a quoted argument, and then grab all the non-space stuff
+    // this will return for the line: "foo" bar
+    // the results "\"foo\"" and "bar"
+
+    // So, let's unquote the quoted arguments:
+    var args = new Array;
+    for (var i = 0; i < matches.length; i++) {
+        args[i] = matches[i];
+        args[i] = args[i].replace(/^"(.*)"$/, "$1");
+    }
+    return args;
+}
+
+function getQueryParameter(searchKey) {
+	var str = getQueryString();
+	if (str == null) return null;
+	var clauses = str.split('&');
+    for (var i = 0; i < clauses.length; i++) {
+        var keyValuePair = clauses[i].split('=',2);
+        var key = unescape(keyValuePair[0]);
+        if (key == searchKey) {
+            return unescape(keyValuePair[1]);
+        }
+    }
+    return null;
+}
+
+function isNewWindow() {
+    return isQueryParameterTrue("newWindow");
+}
+
+function isAutomatedRun() {
+    return isQueryParameterTrue("auto");
+}
+
+function resetMetrics() {
+    numTestPasses = 0;
+    numTestFailures = 0;
+    numCommandPasses = 0;
+    numCommandFailures = 0;
+    numCommandErrors = 0;
+    startTime = new Date().getTime();
+}
+
+function runSingleTest() {
+    runAllTests = false;
+    resetMetrics();
+    startTest();
+}
+
+function startTest() {
+    removeLoadListener(getTestFrame(), startTest);
+
+    // Scroll to the top of the test frame
+    if (getTestFrame().contentWindow) {
+        getTestFrame().contentWindow.scrollTo(0,0);
+    }
+    else {
+        frames['testFrame'].scrollTo(0,0);
+    }
+
+    currentTest = new HtmlTest(getIframeDocument(getTestFrame()));
+
+    testFailed = false;
+    storedVars = new Object();
+
+    testLoop = initialiseTestLoop();
+    testLoop.start();
+}
+
+function HtmlTest(testDocument) {
+    this.init(testDocument);
+}
+
+HtmlTest.prototype = {
+
+    init: function(testDocument) {
+        this.document = testDocument;
+        this.document.bgColor = "";
+        this.currentRow = null;
+        this.commandRows = new Array();
+        this.headerRow = null;
+        var tables = this.document.getElementsByTagName("table");
+        for (var i = 0; i < tables.length; i++) {
+            var candidateRows = tables[i].rows;
+            for (var j = 0; j < candidateRows.length; j++) {
+                if (!this.headerRow) {
+                    this.headerRow = candidateRows[j];
+                }
+                if (candidateRows[j].cells.length >= 3) {
+                    this.addCommandRow(candidateRows[j]);
+                }
+            }
+        }
+    },
+
+    addCommandRow: function(row) {
+        if (row.cells[2] && row.cells[2].originalHTML) {
+            row.cells[2].innerHTML = row.cells[2].originalHTML;
+        }
+        row.bgColor = "";
+        this.commandRows.push(row);
+    },
+
+    nextCommand: function() {
+        if (this.commandRows.length > 0) {
+            this.currentRow = this.commandRows.shift();
+        } else {
+            this.currentRow = null;
+        }
+        return this.currentRow;
+    }
+
+};
+
+function startTestSuite() {
+    resetMetrics();
+    currentRowInSuite = 0;
+    runAllTests = true;
+    suiteFailed = false;
+
+    runNextTest();
+}
+
+function runNextTest() {
+    if (!runAllTests)
+            return;
+
+    suiteTable = getIframeDocument(getSuiteFrame()).getElementsByTagName("table")[0];
+
+    // Do not change the row color of the first row
+    if (currentRowInSuite > 0) {
+        // Provide test-status feedback
+        if (testFailed) {
+            setCellColor(suiteTable.rows, currentRowInSuite, 0, failColor);
+        } else {
+            setCellColor(suiteTable.rows, currentRowInSuite, 0, passColor);
+        }
+
+        // Set the results from the previous test run
+        setResultsData(suiteTable, currentRowInSuite);
+    }
+
+    currentRowInSuite++;
+
+    // If we are done with all of the tests, set the title bar as pass or fail
+    if (currentRowInSuite >= suiteTable.rows.length) {
+        if (suiteFailed) {
+            setCellColor(suiteTable.rows, 0, 0, failColor);
+        } else {
+            setCellColor(suiteTable.rows, 0, 0, passColor);
+        }
+
+        // If this is an automated run (i.e., build script), then submit
+        // the test results by posting to a form
+        if (isAutomatedRun())
+                postTestResults(suiteFailed, suiteTable);
+    }
+
+    else {
+        // Make the current row blue
+        setCellColor(suiteTable.rows, currentRowInSuite, 0, workingColor);
+
+        testLink = suiteTable.rows[currentRowInSuite].cells[0].getElementsByTagName("a")[0];
+        testLink.focus();
+
+        var testFrame = getTestFrame();
+        addLoadListener(testFrame, startTest);
+
+        selenium.browserbot.setIFrameLocation(testFrame, testLink.href);
+    }
+}
+
+function setCellColor(tableRows, row, col, colorStr) {
+    tableRows[row].cells[col].bgColor = colorStr;
+}
+
+// Sets the results from a test into a hidden column on the suite table.  So,
+// for each tests, the second column is set to the HTML from the test table.
+function setResultsData(suiteTable, row) {
+    // Create a text node of the test table
+    var resultTable = getIframeDocument(getTestFrame()).body.innerHTML;
+    if (!resultTable) return;
+
+    var tableNode = suiteTable.ownerDocument.createElement("div");
+    tableNode.innerHTML = resultTable;
+
+    var new_column = suiteTable.ownerDocument.createElement("td");
+    new_column.appendChild(tableNode);
+
+    // Set the column to be invisible
+    new_column.style.cssText = "display: none;";
+
+    // Add the invisible column
+    suiteTable.rows[row].appendChild(new_column);
+}
+
+// Post the results to a servlet, CGI-script, etc.  The URL of the
+// results-handler defaults to "/postResults", but an alternative location
+// can be specified by providing a "resultsUrl" query parameter.
+//
+// Parameters passed to the results-handler are:
+//      result:         passed/failed depending on whether the suite passed or failed
+//      totalTime:      the total running time in seconds for the suite.
+//
+//      numTestPasses:  the total number of tests which passed.
+//      numTestFailures: the total number of tests which failed.
+//
+//      numCommandPasses: the total number of commands which passed.
+//      numCommandFailures: the total number of commands which failed.
+//      numCommandErrors: the total number of commands which errored.
+//
+//      suite:      the suite table, including the hidden column of test results
+//      testTable.1 to testTable.N: the individual test tables
+//
+function postTestResults(suiteFailed, suiteTable) {
+
+    form = document.createElement("form");
+    document.body.appendChild(form);
+
+    form.id = "resultsForm";
+    form.method="post";
+    form.target="myiframe";
+
+    var resultsUrl = getQueryParameter("resultsUrl");
+    if (!resultsUrl) {
+        resultsUrl = "./postResults";
+    }
+
+    var actionAndParameters = resultsUrl.split('?',2);
+    form.action = actionAndParameters[0];
+    var resultsUrlQueryString = actionAndParameters[1];
+
+    form.createHiddenField = function(name, value) {
+        input = document.createElement("input");
+        input.type = "hidden";
+        input.name = name;
+        input.value = value;
+        this.appendChild(input);
+    };
+
+    if (resultsUrlQueryString) {
+        var clauses = resultsUrlQueryString.split('&');
+        for (var i = 0; i < clauses.length; i++) {
+            var keyValuePair = clauses[i].split('=',2);
+            var key = unescape(keyValuePair[0]);
+            var value = unescape(keyValuePair[1]);
+            form.createHiddenField(key, value);
+        }
+    }
+
+    form.createHiddenField("selenium.version", Selenium.version);
+    form.createHiddenField("selenium.revision", Selenium.revision);
+    
+    form.createHiddenField("result", suiteFailed == true ? "failed" : "passed");
+
+    form.createHiddenField("totalTime", Math.floor((currentTime - startTime) / 1000));
+    form.createHiddenField("numTestPasses", numTestPasses);
+    form.createHiddenField("numTestFailures", numTestFailures);
+    form.createHiddenField("numCommandPasses", numCommandPasses);
+    form.createHiddenField("numCommandFailures", numCommandFailures);
+    form.createHiddenField("numCommandErrors", numCommandErrors);
+
+    // Create an input for each test table.  The inputs are named
+    // testTable.1, testTable.2, etc.
+    for (rowNum = 1; rowNum < suiteTable.rows.length;rowNum++) {
+        // If there is a second column, then add a new input
+        if (suiteTable.rows[rowNum].cells.length > 1) {
+            var resultCell = suiteTable.rows[rowNum].cells[1];
+            form.createHiddenField("testTable." + rowNum, resultCell.innerHTML);
+            // remove the resultCell, so it's not included in the suite HTML
+            resultCell.parentNode.removeChild(resultCell); 
+        }
+    }
+    
+    form.createHiddenField("numTestTotal", rowNum);
+
+    // Add HTML for the suite itself
+    form.createHiddenField("suite", suiteTable.parentNode.innerHTML);
+
+	if (isQueryParameterTrue("save")) {
+		saveToFile(resultsUrl, form);
+	} else {
+    	form.submit();
+    }
+    document.body.removeChild(form);
+	if (isQueryParameterTrue("close")) {
+    	window.top.close();
+    }
+}
+
+function saveToFile(fileName, form) {
+	// This only works when run as an IE HTA
+	var inputs = new Object();
+	for (var i = 0; i < form.elements.length; i++) {
+		inputs[form.elements[i].name] = form.elements[i].value;
+	}
+	var objFSO = new ActiveXObject("Scripting.FileSystemObject")
+	var scriptFile = objFSO.CreateTextFile(fileName);
+	scriptFile.WriteLine("<html><body>\n<h1>Test suite results </h1>" +
+            "\n\n<table>\n<tr>\n<td>result:</td>\n<td>" + inputs["result"] + "</td>\n" +
+            "</tr>\n<tr>\n<td>totalTime:</td>\n<td>" + inputs["totalTime"] + "</td>\n</tr>\n" +
+            "<tr>\n<td>numTestPasses:</td>\n<td>" + inputs["numTestPasses"] + "</td>\n</tr>\n" +
+            "<tr>\n<td>numTestFailures:</td>\n<td>" + inputs["numTestFailures"] + "</td>\n</tr>\n" +
+            "<tr>\n<td>numCommandPasses:</td>\n<td>" + inputs["numCommandPasses"] + "</td>\n</tr>\n" +
+            "<tr>\n<td>numCommandFailures:</td>\n<td>" + inputs["numCommandFailures"] + "</td>\n</tr>\n" +
+            "<tr>\n<td>numCommandErrors:</td>\n<td>" + inputs["numCommandErrors"] + "</td>\n</tr>\n" +
+            "<tr>\n<td>" + inputs["suite"] + "</td>\n<td>&nbsp;</td>\n</tr>");
+    var testNum = inputs["numTestTotal"];
+    for (var rowNum = 1; rowNum < testNum; rowNum++) {
+    	scriptFile.WriteLine("<tr>\n<td>" + inputs["testTable." + rowNum] + "</td>\n<td>&nbsp;</td>\n</tr>");
+    }
+    scriptFile.WriteLine("</table></body></html>");
+    scriptFile.Close();
+}
+
+function printMetrics() {
+    setText(document.getElementById("commandPasses"), numCommandPasses);
+    setText(document.getElementById("commandFailures"), numCommandFailures);
+    setText(document.getElementById("commandErrors"), numCommandErrors);
+    setText(document.getElementById("testRuns"), numTestPasses + numTestFailures);
+    setText(document.getElementById("testFailures"), numTestFailures);
+
+    currentTime = new Date().getTime();
+
+    timeDiff = currentTime - startTime;
+    totalSecs = Math.floor(timeDiff / 1000);
+
+    minutes = Math.floor(totalSecs / 60);
+    seconds = totalSecs % 60;
+
+    setText(document.getElementById("elapsedTime"), pad(minutes)+":"+pad(seconds));
+}
+
+// Puts a leading 0 on num if it is less than 10
+function pad (num) {
+    return (num > 9) ? num : "0" + num;
+}
+
+/*
+ * Register all of the built-in command handlers with the CommandHandlerFactory.
+ * TODO work out an easy way for people to register handlers without modifying the Selenium sources.
+ */
+function registerCommandHandlers() {
+    commandFactory = new CommandHandlerFactory();
+    commandFactory.registerAll(selenium);
+
+}
+
+function initialiseTestLoop() {
+    testLoop = new TestLoop(commandFactory);
+
+    testLoop.getCommandInterval = function() { return runInterval; };
+    testLoop.nextCommand = nextCommand;
+    testLoop.commandStarted = commandStarted;
+    testLoop.commandComplete = commandComplete;
+    testLoop.commandError = commandError;
+    testLoop.testComplete = testComplete;
+    testLoop.pause = function() {
+        document.getElementById('continueTest').disabled = false;
+    };
+    return testLoop;
+}
+
+function nextCommand() {
+    var row = currentTest.nextCommand();
+    if (row == null) {
+        return null;
+    }
+    row.cells[2].originalHTML = row.cells[2].innerHTML;
+    return new SeleniumCommand(getText(row.cells[0]), 
+                               getText(row.cells[1]),
+                               getText(row.cells[2]));
+}
+
+function removeNbsp(value) {
+    return value.replace(/\240/g, "");
+}
+
+function scrollIntoView(element) {
+    if (element.scrollIntoView) {
+        element.scrollIntoView(false);
+        return;
+    }
+    // TODO: work out how to scroll browsers that don't support
+    // scrollIntoView (like Konqueror)
+}
+
+function commandStarted() {
+    currentTest.currentRow.bgColor = workingColor;
+    scrollIntoView(currentTest.currentRow.cells[0]);
+    printMetrics();
+}
+
+function commandComplete(result) {
+    if (result.failed) {
+        numCommandFailures += 1;
+        recordFailure(result.failureMessage);
+    } else if (result.passed) {
+        numCommandPasses += 1;
+        currentTest.currentRow.bgColor = passColor;
+    } else {
+        currentTest.currentRow.bgColor = doneColor;
+    }
+}
+
+function commandError(errorMessage) {
+    numCommandErrors += 1;
+    recordFailure(errorMessage);
+}
+
+function recordFailure(errorMsg) {
+    LOG.warn("recordFailure: " + errorMsg);
+    // Set cell background to red
+    currentTest.currentRow.bgColor = failColor;
+
+    // Set error message
+    currentTest.currentRow.cells[2].innerHTML = errorMsg;
+    currentTest.currentRow.title = errorMsg;
+    testFailed = true;
+    suiteFailed = true;
+}
+
+function testComplete() {
+    var resultColor = passColor;
+    if (testFailed) {
+        resultColor = failColor;
+        numTestFailures += 1;
+    } else {
+        numTestPasses += 1;
+    }
+
+    if (currentTest.headerRow) {
+        currentTest.headerRow.bgColor = resultColor;
+    }
+    
+    printMetrics();
+
+    window.setTimeout("runNextTest()", 1);
+}
+
+Selenium.prototype.doPause = function(waitTime) {
+    testLoop.pauseInterval = waitTime;
+};
+
+Selenium.prototype.doBreak = function() {
+    document.getElementById('modeStep').checked = true;
+    runInterval = -1;
+};
+
+/*
+ * Click on the located element, and attach a callback to notify
+ * when the page is reloaded.
+ */
+Selenium.prototype.doModalDialogTest = function(returnValue) {
+    this.browserbot.doModalDialogTest(returnValue);
+};
+
+/*
+ * Store the value of a form input in a variable
+ */
+Selenium.prototype.doStoreValue = function(target, varName) {
+    if (!varName) {
+        // Backward compatibility mode: read the ENTIRE text of the page
+        // and stores it in a variable with the name of the target
+        value = this.page().bodyText();
+        storedVars[target] = value;
+        return;
+    }
+    var element = this.page().findElement(target);
+    storedVars[varName] = getInputValue(element);
+};
+
+/*
+ * Store the text of an element in a variable
+ */
+Selenium.prototype.doStoreText = function(target, varName) {
+    var element = this.page().findElement(target);
+    storedVars[varName] = getText(element);
+};
+
+/*
+ * Store the value of an element attribute in a variable
+ */
+Selenium.prototype.doStoreAttribute = function(target, varName) {
+    storedVars[varName] = this.page().findAttribute(target);
+};
+
+/*
+ * Store the result of a literal value
+ */
+Selenium.prototype.doStore = function(value, varName) {
+    storedVars[varName] = value;
+};

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-version.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-version.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-version.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,5 @@
+Selenium.version = "0.7.0";
+Selenium.revision = "1007M";
+
+window.top.document.title += " v" + Selenium.version + " [" + Selenium.revision + "]";
+

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/user-extensions.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/user-extensions.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/user-extensions.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,3 @@
+// Add a comment action that ignores its arguments
+Selenium.prototype.doComment = function(text, text) {
+};

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/user-extensions.js.sample
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/user-extensions.js.sample	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/user-extensions.js.sample	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,75 @@
+/*
+ * By default, Selenium looks for a file called "user-extensions.js", and loads and javascript
+ * code found in that file. This file is a sample of what that file could look like.
+ *
+ * user-extensions.js provides a convenient location for adding extensions to Selenium, like
+ * new actions, checks and locator-strategies.
+ * By default, this file does not exist. Users can create this file and place their extension code
+ * in this common location, removing the need to modify the Selenium sources, and hopefully assisting
+ * with the upgrade process.
+ *
+ * You can find contributed extensions at http://wiki.openqa.org/display/SEL/Contributed%20User-Extensions
+ */
+
+// The following examples try to give an indication of how Selenium can be extended with javascript.
+
+// All do* methods on the Selenium prototype are added as actions.
+// Eg add a typeRepeated action to Selenium, which types the text twice into a text box.
+// The typeTwiceAndWait command will be available automatically
+Selenium.prototype.doTypeRepeated = function(locator, text) {
+    // All locator-strategies are automatically handled by "findElement"
+    var element = this.page().findElement(locator);
+
+    // Create the text to type
+    var valueToType = text + text;
+
+    // Replace the element text with the new text
+    this.page().replaceText(element, valueToType);
+};
+
+// All assert* methods on the Selenium prototype are added as checks.
+// Eg add a assertValueRepeated check, that makes sure that the element value
+// consists of the supplied text repeated.
+// The verify version will be available automatically.
+Selenium.prototype.assertValueRepeated = function(locator, text) {
+    // All locator-strategies are automatically handled by "findElement"
+    var element = this.page().findElement(locator);
+
+    // Create the text to verify
+    var expectedValue = text + text;
+
+    // Get the actual element value
+    var actualValue = element.value;
+
+    // Make sure the actual value matches the expected
+    Assert.matches(expectedValue, actualValue);
+};
+
+// All get* methods on the Selenium prototype result in
+// store, assert, assertNot, verify, verifyNot, waitFor, and waitForNot commands.
+// E.g. add a getTextLength method that returns the length of the text
+// of a specified element.
+// Will result in support for storeTextLength, assertTextLength, etc.
+Selenium.prototype.getTextLength = function(locator) {
+	return this.getText(locator).length;
+};
+
+// All locateElementBy* methods are added as locator-strategies.
+// Eg add a "valuerepeated=" locator, that finds the first element with the supplied value, repeated.
+// The "inDocument" is a the document you are searching.
+PageBot.prototype.locateElementByValueRepeated = function(text, inDocument) {
+    // Create the text to search for
+    var expectedValue = text + text;
+
+    // Loop through all elements, looking for ones that have a value === our expected value
+    var allElements = inDocument.getElementsByTagName("*");
+    for (var i = 0; i < allElements.length; i++) {
+        var testElement = allElements[i];
+        if (testElement.value && testElement.value === expectedValue) {
+            return testElement;
+        }
+    }
+    return null;
+};
+
+

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/xmlextras.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/xmlextras.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/xmlextras.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,153 @@
+// This is a third party JavaScript library from
+// http://webfx.eae.net/dhtml/xmlextras/xmlextras.html
+// i.e. This has not been written by ThoughtWorks.
+
+//<script>
+//////////////////
+// Helper Stuff //
+//////////////////
+
+// used to find the Automation server name
+function getDomDocumentPrefix() {
+	if (getDomDocumentPrefix.prefix)
+		return getDomDocumentPrefix.prefix;
+	
+	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
+	var o;
+	for (var i = 0; i < prefixes.length; i++) {
+		try {
+			// try to create the objects
+			o = new ActiveXObject(prefixes[i] + ".DomDocument");
+			return getDomDocumentPrefix.prefix = prefixes[i];
+		}
+		catch (ex) {};
+	}
+	
+	throw new Error("Could not find an installed XML parser");
+}
+
+function getXmlHttpPrefix() {
+	if (getXmlHttpPrefix.prefix)
+		return getXmlHttpPrefix.prefix;
+	
+	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
+	var o;
+	for (var i = 0; i < prefixes.length; i++) {
+		try {
+			// try to create the objects
+			o = new ActiveXObject(prefixes[i] + ".XmlHttp");
+			return getXmlHttpPrefix.prefix = prefixes[i];
+		}
+		catch (ex) {};
+	}
+	
+	throw new Error("Could not find an installed XML parser");
+}
+
+//////////////////////////
+// Start the Real stuff //
+//////////////////////////
+
+
+// XmlHttp factory
+function XmlHttp() {}
+
+XmlHttp.create = function () {
+	try {
+		if (window.XMLHttpRequest) {
+			var req = new XMLHttpRequest();
+			
+			// some versions of Moz do not support the readyState property
+			// and the onreadystate event so we patch it!
+			if (req.readyState == null) {
+				req.readyState = 1;
+				req.addEventListener("load", function () {
+					req.readyState = 4;
+					if (typeof req.onreadystatechange == "function")
+						req.onreadystatechange();
+				}, false);
+			}
+			
+			return req;
+		}
+		if (window.ActiveXObject) {
+			return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
+		}
+	}
+	catch (ex) {}
+	// fell through
+	throw new Error("Your browser does not support XmlHttp objects");
+};
+
+// XmlDocument factory
+function XmlDocument() {}
+
+XmlDocument.create = function () {
+	try {
+		// DOM2
+		if (document.implementation && document.implementation.createDocument) {
+			var doc = document.implementation.createDocument("", "", null);
+			
+			// some versions of Moz do not support the readyState property
+			// and the onreadystate event so we patch it!
+			if (doc.readyState == null) {
+				doc.readyState = 1;
+				doc.addEventListener("load", function () {
+					doc.readyState = 4;
+					if (typeof doc.onreadystatechange == "function")
+						doc.onreadystatechange();
+				}, false);
+			}
+			
+			return doc;
+		}
+		if (window.ActiveXObject)
+			return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
+	}
+	catch (ex) {}
+	throw new Error("Your browser does not support XmlDocument objects");
+};
+
+// Create the loadXML method and xml getter for Mozilla
+if (window.DOMParser &&
+	window.XMLSerializer &&
+	window.Node && Node.prototype && Node.prototype.__defineGetter__) {
+
+	// XMLDocument did not extend the Document interface in some versions
+	// of Mozilla. Extend both!
+	//XMLDocument.prototype.loadXML = 
+	Document.prototype.loadXML = function (s) {
+		
+		// parse the string to a new doc	
+		var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
+		
+		// remove all initial children
+		while (this.hasChildNodes())
+			this.removeChild(this.lastChild);
+			
+		// insert and import nodes
+		for (var i = 0; i < doc2.childNodes.length; i++) {
+			this.appendChild(this.importNode(doc2.childNodes[i], true));
+		}
+	};
+	
+	
+	/*
+	 * xml getter
+	 *
+	 * This serializes the DOM tree to an XML String
+	 *
+	 * Usage: var sXml = oNode.xml
+	 *
+	 */
+	// XMLDocument did not extend the Document interface in some versions
+	// of Mozilla. Extend both!
+	/*
+	XMLDocument.prototype.__defineGetter__("xml", function () {
+		return (new XMLSerializer()).serializeToString(this);
+	});
+	*/
+	Document.prototype.__defineGetter__("xml", function () {
+		return (new XMLSerializer()).serializeToString(this);
+	});
+}
\ No newline at end of file

Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/xpath.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/xpath.js	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/xpath.js	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,4169 @@
+/*
+ * xpath.js
+ *
+ * An XPath 1.0 library for JavaScript.
+ *
+ * Cameron McCormack <cam (at) mcc.id.au>
+ *
+ * This work is licensed under the Creative Commons Attribution-ShareAlike
+ * License. To view a copy of this license, visit
+ * 
+ *   http://creativecommons.org/licenses/by-sa/2.0/
+ *
+ * or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford,
+ * California 94305, USA.
+ *
+ * Revision 18: October 27, 2005
+ *   DOM 3 XPath support.  Caveats:
+ *     - namespace prefixes aren't resolved in XPathEvaluator.createExpression,
+ *       but in XPathExpression.evaluate.
+ *     - XPathResult.invalidIteratorState is not implemented.
+ *
+ * Revision 17: October 25, 2005
+ *   Some core XPath function fixes and a patch to avoid crashing certain
+ *   versions of MSXML in PathExpr.prototype.getOwnerElement, thanks to
+ *   Sébastien Cramatte <contact (at) zeninteractif.com>.
+ *
+ * Revision 16: September 22, 2005
+ *   Workarounds for some IE 5.5 deficiencies.
+ *   Fixed problem with prefix node tests on attribute nodes.
+ *
+ * Revision 15: May 21, 2005
+ *   Fixed problem with QName node tests on elements with an xmlns="...".
+ *
+ * Revision 14: May 19, 2005
+ *   Fixed QName node tests on attribute node regression.
+ *
+ * Revision 13: May 3, 2005
+ *   Node tests are case insensitive now if working in an HTML DOM.
+ *
+ * Revision 12: April 26, 2005
+ *   Updated licence.  Slight code changes to enable use of Dean
+ *   Edwards' script compression, http://dean.edwards.name/packer/ .
+ *
+ * Revision 11: April 23, 2005
+ *   Fixed bug with 'and' and 'or' operators, fix thanks to
+ *   Sandy McArthur <sandy (at) mcarthur.org>.
+ *
+ * Revision 10: April 15, 2005
+ *   Added support for a virtual root node, supposedly helpful for
+ *   implementing XForms.  Fixed problem with QName node tests and
+ *   the parent axis.
+ *
+ * Revision 9: March 17, 2005
+ *   Namespace resolver tweaked so using the document node as the context
+ *   for namespace lookups is equivalent to using the document element.
+ *
+ * Revision 8: February 13, 2005
+ *   Handle implicit declaration of 'xmlns' namespace prefix.
+ *   Fixed bug when comparing nodesets.
+ *   Instance data can now be associated with a FunctionResolver, and
+ *     workaround for MSXML not supporting 'localName' and 'getElementById',
+ *     thanks to Grant Gongaware.
+ *   Fix a few problems when the context node is the root node.
+ *   
+ * Revision 7: February 11, 2005
+ *   Default namespace resolver fix from Grant Gongaware
+ *   <grant (at) gongaware.com>.
+ *
+ * Revision 6: February 10, 2005
+ *   Fixed bug in 'number' function.
+ *
+ * Revision 5: February 9, 2005
+ *   Fixed bug where text nodes not getting converted to string values.
+ *
+ * Revision 4: January 21, 2005
+ *   Bug in 'name' function, fix thanks to Bill Edney.
+ *   Fixed incorrect processing of namespace nodes.
+ *   Fixed NamespaceResolver to resolve 'xml' namespace.
+ *   Implemented union '|' operator.
+ *
+ * Revision 3: January 14, 2005
+ *   Fixed bug with nodeset comparisons, bug lexing < and >.
+ *
+ * Revision 2: October 26, 2004
+ *   QName node test namespace handling fixed.  Few other bug fixes.
+ *   
+ * Revision 1: August 13, 2004
+ *   Bug fixes from William J. Edney <bedney (at) technicalpursuit.com>.
+ *   Added minimal licence.
+ *
+ * Initial version: June 14, 2004
+ */
+
+// XPathParser ///////////////////////////////////////////////////////////////
+
+XPathParser.prototype = new Object();
+XPathParser.prototype.constructor = XPathParser;
+XPathParser.superclass = Object.prototype;
+
+function XPathParser() {
+	this.init();
+}
+
+XPathParser.prototype.init = function() {
+	this.reduceActions = [];
+
+	this.reduceActions[3] = function(rhs) {
+		return new OrOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[5] = function(rhs) {
+		return new AndOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[7] = function(rhs) {
+		return new EqualsOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[8] = function(rhs) {
+		return new NotEqualOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[10] = function(rhs) {
+		return new LessThanOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[11] = function(rhs) {
+		return new GreaterThanOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[12] = function(rhs) {
+		return new LessThanOrEqualOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[13] = function(rhs) {
+		return new GreaterThanOrEqualOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[15] = function(rhs) {
+		return new PlusOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[16] = function(rhs) {
+		return new MinusOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[18] = function(rhs) {
+		return new MultiplyOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[19] = function(rhs) {
+		return new DivOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[20] = function(rhs) {
+		return new ModOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[22] = function(rhs) {
+		return new UnaryMinusOperation(rhs[1]);
+	};
+	this.reduceActions[24] = function(rhs) {
+		return new BarOperation(rhs[0], rhs[2]);
+	};
+	this.reduceActions[25] = function(rhs) {
+		return new PathExpr(undefined, undefined, rhs[0]);
+	};
+	this.reduceActions[27] = function(rhs) {
+		rhs[0].locationPath = rhs[2];
+		return rhs[0];
+	};
+	this.reduceActions[28] = function(rhs) {
+		rhs[0].locationPath = rhs[2];
+		rhs[0].locationPath.steps.unshift(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
+		return rhs[0];
+	};
+	this.reduceActions[29] = function(rhs) {
+		return new PathExpr(rhs[0], [], undefined);
+	};
+	this.reduceActions[30] = function(rhs) {
+		if (Utilities.instance_of(rhs[0], PathExpr)) {
+			if (rhs[0].filterPredicates == undefined) {
+				rhs[0].filterPredicates = [];
+			}
+			rhs[0].filterPredicates.push(rhs[1]);
+			return rhs[0];
+		} else {
+			return new PathExpr(rhs[0], [rhs[1]], undefined);
+		}
+	};
+	this.reduceActions[32] = function(rhs) {
+		return rhs[1];
+	};
+	this.reduceActions[33] = function(rhs) {
+		return new XString(rhs[0]);
+	};
+	this.reduceActions[34] = function(rhs) {
+		return new XNumber(rhs[0]);
+	};
+	this.reduceActions[36] = function(rhs) {
+		return new FunctionCall(rhs[0], []);
+	};
+	this.reduceActions[37] = function(rhs) {
+		return new FunctionCall(rhs[0], rhs[2]);
+	};
+	this.reduceActions[38] = function(rhs) {
+		return [ rhs[0] ];
+	};
+	this.reduceActions[39] = function(rhs) {
+		rhs[2].unshift(rhs[0]);
+		return rhs[2];
+	};
+	this.reduceActions[43] = function(rhs) {
+		return new LocationPath(true, []);
+	};
+	this.reduceActions[44] = function(rhs) {
+		rhs[1].absolute = true;
+		return rhs[1];
+	};
+	this.reduceActions[46] = function(rhs) {
+		return new LocationPath(false, [ rhs[0] ]);
+	};
+	this.reduceActions[47] = function(rhs) {
+		rhs[0].steps.push(rhs[2]);
+		return rhs[0];
+	};
+	this.reduceActions[49] = function(rhs) {
+		return new Step(rhs[0], rhs[1], []);
+	};
+	this.reduceActions[50] = function(rhs) {
+		return new Step(Step.CHILD, rhs[0], []);
+	};
+	this.reduceActions[51] = function(rhs) {
+		return new Step(rhs[0], rhs[1], rhs[2]);
+	};
+	this.reduceActions[52] = function(rhs) {
+		return new Step(Step.CHILD, rhs[0], rhs[1]);
+	};
+	this.reduceActions[54] = function(rhs) {
+		return [ rhs[0] ];
+	};
+	this.reduceActions[55] = function(rhs) {
+		rhs[1].unshift(rhs[0]);
+		return rhs[1];
+	};
+	this.reduceActions[56] = function(rhs) {
+		if (rhs[0] == "ancestor") {
+			return Step.ANCESTOR;
+		} else if (rhs[0] == "ancestor-or-self") {
+			return Step.ANCESTORORSELF;
+		} else if (rhs[0] == "attribute") {
+			return Step.ATTRIBUTE;
+		} else if (rhs[0] == "child") {
+			return Step.CHILD;
+		} else if (rhs[0] == "descendant") {
+			return Step.DESCENDANT;
+		} else if (rhs[0] == "descendant-or-self") {
+			return Step.DESCENDANTORSELF;
+		} else if (rhs[0] == "following") {
+			return Step.FOLLOWING;
+		} else if (rhs[0] == "following-sibling") {
+			return Step.FOLLOWINGSIBLING;
+		} else if (rhs[0] == "namespace") {
+			return Step.NAMESPACE;
+		} else if (rhs[0] == "parent") {
+			return Step.PARENT;
+		} else if (rhs[0] == "preceding") {
+			return Step.PRECEDING;
+		} else if (rhs[0] == "preceding-sibling") {
+			return Step.PRECEDINGSIBLING;
+		} else if (rhs[0] == "self") {
+			return Step.SELF;
+		}
+		return -1;
+	};
+	this.reduceActions[57] = function(rhs) {
+		return Step.ATTRIBUTE;
+	};
+	this.reduceActions[59] = function(rhs) {
+		if (rhs[0] == "comment") {
+			return new NodeTest(NodeTest.COMMENT, undefined);
+		} else if (rhs[0] == "text") {
+			return new NodeTest(NodeTest.TEXT, undefined);
+		} else if (rhs[0] == "processing-instruction") {
+			return new NodeTest(NodeTest.PI, undefined);
+		} else if (rhs[0] == "node") {
+			return new NodeTest(NodeTest.NODE, undefined);
+		}
+		return new NodeTest(-1, undefined);
+	};
+	this.reduceActions[60] = function(rhs) {
+		return new NodeTest(NodeTest.PI, rhs[2]);
+	};
+	this.reduceActions[61] = function(rhs) {
+		return rhs[1];
+	};
+	this.reduceActions[63] = function(rhs) {
+		rhs[1].absolute = true;
+		rhs[1].steps.unshift(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
+		return rhs[1];
+	};
+	this.reduceActions[64] = function(rhs) {
+		rhs[0].steps.push(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
+		rhs[0].steps.push(rhs[2]);
+		return rhs[0];
+	};
+	this.reduceActions[65] = function(rhs) {
+		return new Step(Step.SELF, new NodeTest(NodeTest.NODE, undefined), []);
+	};
+	this.reduceActions[66] = function(rhs) {
+		return new Step(Step.PARENT, new NodeTest(NodeTest.NODE, undefined), []);
+	};
+	this.reduceActions[67] = function(rhs) {
+		return new VariableReference(rhs[1]);
+	};
+	this.reduceActions[68] = function(rhs) {
+		return new NodeTest(NodeTest.NAMETESTANY, undefined);
+	};
+	this.reduceActions[69] = function(rhs) {
+		var prefix = rhs[0].substring(0, rhs[0].indexOf(":"));
+		return new NodeTest(NodeTest.NAMETESTPREFIXANY, prefix);
+	};
+	this.reduceActions[70] = function(rhs) {
+		return new NodeTest(NodeTest.NAMETESTQNAME, rhs[0]);
+	};
+};
+
+XPathParser.actionTable = [
+	" s s        sssssssss    s ss  s  ss",
+	"                 s                  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"                rrrrr               ",
+	" s s        sssssssss    s ss  s  ss",
+	"rs  rrrrrrrr s  sssssrrrrrr  rrs rs ",
+	" s s        sssssssss    s ss  s  ss",
+	"                            s       ",
+	"                            s       ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"  s                                 ",
+	"                            s       ",
+	" s           s  sssss          s  s ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"a                                   ",
+	"r       s                    rr  r  ",
+	"r      sr                    rr  r  ",
+	"r   s  rr            s       rr  r  ",
+	"r   rssrr            rss     rr  r  ",
+	"r   rrrrr            rrrss   rr  r  ",
+	"r   rrrrrsss         rrrrr   rr  r  ",
+	"r   rrrrrrrr         rrrrr   rr  r  ",
+	"r   rrrrrrrr         rrrrrs  rr  r  ",
+	"r   rrrrrrrr         rrrrrr  rr  r  ",
+	"r   rrrrrrrr         rrrrrr  rr  r  ",
+	"r  srrrrrrrr         rrrrrrs rr sr  ",
+	"r  srrrrrrrr         rrrrrrs rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r   rrrrrrrr         rrrrrr  rr  r  ",
+	"r   rrrrrrrr         rrrrrr  rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"                sssss               ",
+	"r  rrrrrrrrr         rrrrrrr rr sr  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"                             s      ",
+	"r  srrrrrrrr         rrrrrrs rr  r  ",
+	"r   rrrrrrrr         rrrrr   rr  r  ",
+	"              s                     ",
+	"                             s      ",
+	"                rrrrr               ",
+	" s s        sssssssss    s sss s  ss",
+	"r  srrrrrrrr         rrrrrrs rr  r  ",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s s        sssssssss      ss  s  ss",
+	" s s        sssssssss    s ss  s  ss",
+	" s           s  sssss          s  s ",
+	" s           s  sssss          s  s ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	" s           s  sssss          s  s ",
+	" s           s  sssss          s  s ",
+	"r  rrrrrrrrr         rrrrrrr rr sr  ",
+	"r  rrrrrrrrr         rrrrrrr rr sr  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"                             s      ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"                             rr     ",
+	"                             s      ",
+	"                             rs     ",
+	"r      sr                    rr  r  ",
+	"r   s  rr            s       rr  r  ",
+	"r   rssrr            rss     rr  r  ",
+	"r   rssrr            rss     rr  r  ",
+	"r   rrrrr            rrrss   rr  r  ",
+	"r   rrrrr            rrrss   rr  r  ",
+	"r   rrrrr            rrrss   rr  r  ",
+	"r   rrrrr            rrrss   rr  r  ",
+	"r   rrrrrsss         rrrrr   rr  r  ",
+	"r   rrrrrsss         rrrrr   rr  r  ",
+	"r   rrrrrrrr         rrrrr   rr  r  ",
+	"r   rrrrrrrr         rrrrr   rr  r  ",
+	"r   rrrrrrrr         rrrrr   rr  r  ",
+	"r   rrrrrrrr         rrrrrr  rr  r  ",
+	"                                 r  ",
+	"                                 s  ",
+	"r  srrrrrrrr         rrrrrrs rr  r  ",
+	"r  srrrrrrrr         rrrrrrs rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr  r  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	" s s        sssssssss    s ss  s  ss",
+	"r  rrrrrrrrr         rrrrrrr rr rr  ",
+	"                             r      "
+];
+
+XPathParser.actionTableNumber = [
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	"                 J                  ",
+	"a  aaaaaaaaa         aaaaaaa aa  a  ",
+	"                YYYYY               ",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	"K1  KKKKKKKK .  +*)('KKKKKK  KK# K\" ",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	"                            N       ",
+	"                            O       ",
+	"e  eeeeeeeee         eeeeeee ee ee  ",
+	"f  fffffffff         fffffff ff ff  ",
+	"d  ddddddddd         ddddddd dd dd  ",
+	"B  BBBBBBBBB         BBBBBBB BB BB  ",
+	"A  AAAAAAAAA         AAAAAAA AA AA  ",
+	"  P                                 ",
+	"                            Q       ",
+	" 1           .  +*)('          #  \" ",
+	"b  bbbbbbbbb         bbbbbbb bb  b  ",
+	"                                    ",
+	"!       S                    !!  !  ",
+	"\"      T\"                    \"\"  \"  ",
+	"$   V  $$            U       $$  $  ",
+	"&   &ZY&&            &XW     &&  &  ",
+	")   )))))            )))\\[   ))  )  ",
+	".   ....._^]         .....   ..  .  ",
+	"1   11111111         11111   11  1  ",
+	"5   55555555         55555`  55  5  ",
+	"7   77777777         777777  77  7  ",
+	"9   99999999         999999  99  9  ",
+	":  c::::::::         ::::::b :: a:  ",
+	"I  fIIIIIIII         IIIIIIe II  I  ",
+	"=  =========         ======= == ==  ",
+	"?  ?????????         ??????? ?? ??  ",
+	"C  CCCCCCCCC         CCCCCCC CC CC  ",
+	"J   JJJJJJJJ         JJJJJJ  JJ  J  ",
+	"M   MMMMMMMM         MMMMMM  MM  M  ",
+	"N  NNNNNNNNN         NNNNNNN NN  N  ",
+	"P  PPPPPPPPP         PPPPPPP PP  P  ",
+	"                +*)('               ",
+	"R  RRRRRRRRR         RRRRRRR RR aR  ",
+	"U  UUUUUUUUU         UUUUUUU UU  U  ",
+	"Z  ZZZZZZZZZ         ZZZZZZZ ZZ ZZ  ",
+	"c  ccccccccc         ccccccc cc cc  ",
+	"                             j      ",
+	"L  fLLLLLLLL         LLLLLLe LL  L  ",
+	"6   66666666         66666   66  6  ",
+	"              k                     ",
+	"                             l      ",
+	"                XXXXX               ",
+	" 1 0        /.-,+*)('    & %$m #  \"!",
+	"_  f________         ______e __  _  ",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1 0        /.-,+*)('      %$  #  \"!",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	" 1           .  +*)('          #  \" ",
+	" 1           .  +*)('          #  \" ",
+	">  >>>>>>>>>         >>>>>>> >> >>  ",
+	" 1           .  +*)('          #  \" ",
+	" 1           .  +*)('          #  \" ",
+	"Q  QQQQQQQQQ         QQQQQQQ QQ aQ  ",
+	"V  VVVVVVVVV         VVVVVVV VV aV  ",
+	"T  TTTTTTTTT         TTTTTTT TT  T  ",
+	"@  @@@@@@@@@         @@@@@@@ @@ @@  ",
+	"                             \x87      ",
+	"[  [[[[[[[[[         [[[[[[[ [[ [[  ",
+	"D  DDDDDDDDD         DDDDDDD DD DD  ",
+	"                             HH     ",
+	"                             \x88      ",
+	"                             F\x89     ",
+	"#      T#                    ##  #  ",
+	"%   V  %%            U       %%  %  ",
+	"'   'ZY''            'XW     ''  '  ",
+	"(   (ZY((            (XW     ((  (  ",
+	"+   +++++            +++\\[   ++  +  ",
+	"*   *****            ***\\[   **  *  ",
+	"-   -----            ---\\[   --  -  ",
+	",   ,,,,,            ,,,\\[   ,,  ,  ",
+	"0   00000_^]         00000   00  0  ",
+	"/   /////_^]         /////   //  /  ",
+	"2   22222222         22222   22  2  ",
+	"3   33333333         33333   33  3  ",
+	"4   44444444         44444   44  4  ",
+	"8   88888888         888888  88  8  ",
+	"                                 ^  ",
+	"                                 \x8a  ",
+	";  f;;;;;;;;         ;;;;;;e ;;  ;  ",
+	"<  f<<<<<<<<         <<<<<<e <<  <  ",
+	"O  OOOOOOOOO         OOOOOOO OO  O  ",
+	"`  `````````         ``````` ``  `  ",
+	"S  SSSSSSSSS         SSSSSSS SS  S  ",
+	"W  WWWWWWWWW         WWWWWWW WW  W  ",
+	"\\  \\\\\\\\\\\\\\\\\\         \\\\\\\\\\\\\\ \\\\ \\\\  ",
+	"E  EEEEEEEEE         EEEEEEE EE EE  ",
+	" 1 0        /.-,+*)('    & %$  #  \"!",
+	"]  ]]]]]]]]]         ]]]]]]] ]] ]]  ",
+	"                             G      "
+];
+
+XPathParser.gotoTable = [
+	"3456789:;<=>?@ AB  CDEFGH IJ ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"L456789:;<=>?@ AB  CDEFGH IJ ",
+	"            M        EFGH IJ ",
+	"       N;<=>?@ AB  CDEFGH IJ ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"            S        EFGH IJ ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"              e              ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                        h  J ",
+	"              i          j   ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"o456789:;<=>?@ ABpqCDEFGH IJ ",
+	"                             ",
+	"  r6789:;<=>?@ AB  CDEFGH IJ ",
+	"   s789:;<=>?@ AB  CDEFGH IJ ",
+	"    t89:;<=>?@ AB  CDEFGH IJ ",
+	"    u89:;<=>?@ AB  CDEFGH IJ ",
+	"     v9:;<=>?@ AB  CDEFGH IJ ",
+	"     w9:;<=>?@ AB  CDEFGH IJ ",
+	"     x9:;<=>?@ AB  CDEFGH IJ ",
+	"     y9:;<=>?@ AB  CDEFGH IJ ",
+	"      z:;<=>?@ AB  CDEFGH IJ ",
+	"      {:;<=>?@ AB  CDEFGH IJ ",
+	"       |;<=>?@ AB  CDEFGH IJ ",
+	"       };<=>?@ AB  CDEFGH IJ ",
+	"       ~;<=>?@ AB  CDEFGH IJ ",
+	"         \x7f=>?@ AB  CDEFGH IJ ",
+	"\x80456789:;<=>?@ AB  CDEFGH IJ\x81",
+	"            \x82        EFGH IJ ",
+	"            \x83        EFGH IJ ",
+	"                             ",
+	"                     \x84 GH IJ ",
+	"                     \x85 GH IJ ",
+	"              i          \x86   ",
+	"              i          \x87   ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"                             ",
+	"o456789:;<=>?@ AB\x8cqCDEFGH IJ ",
+	"                             ",
+	"                             "
+];
+
+XPathParser.productions = [
+	[1, 1, 2],
+	[2, 1, 3],
+	[3, 1, 4],
+	[3, 3, 3, -9, 4],
+	[4, 1, 5],
+	[4, 3, 4, -8, 5],
+	[5, 1, 6],
+	[5, 3, 5, -22, 6],
+	[5, 3, 5, -5, 6],
+	[6, 1, 7],
+	[6, 3, 6, -23, 7],
+	[6, 3, 6, -24, 7],
+	[6, 3, 6, -6, 7],
+	[6, 3, 6, -7, 7],
+	[7, 1, 8],
+	[7, 3, 7, -25, 8],
+	[7, 3, 7, -26, 8],
+	[8, 1, 9],
+	[8, 3, 8, -12, 9],
+	[8, 3, 8, -11, 9],
+	[8, 3, 8, -10, 9],
+	[9, 1, 10],
+	[9, 2, -26, 9],
+	[10, 1, 11],
+	[10, 3, 10, -27, 11],
+	[11, 1, 12],
+	[11, 1, 13],
+	[11, 3, 13, -28, 14],
+	[11, 3, 13, -4, 14],
+	[13, 1, 15],
+	[13, 2, 13, 16],
+	[15, 1, 17],
+	[15, 3, -29, 2, -30],
+	[15, 1, -15],
+	[15, 1, -16],
+	[15, 1, 18],
+	[18, 3, -13, -29, -30],
+	[18, 4, -13, -29, 19, -30],
+	[19, 1, 20],
+	[19, 3, 20, -31, 19],
+	[20, 1, 2],
+	[12, 1, 14],
+	[12, 1, 21],
+	[21, 1, -28],
+	[21, 2, -28, 14],
+	[21, 1, 22],
+	[14, 1, 23],
+	[14, 3, 14, -28, 23],
+	[14, 1, 24],
+	[23, 2, 25, 26],
+	[23, 1, 26],
+	[23, 3, 25, 26, 27],
+	[23, 2, 26, 27],
+	[23, 1, 28],
+	[27, 1, 16],
+	[27, 2, 16, 27],
+	[25, 2, -14, -3],
+	[25, 1, -32],
+	[26, 1, 29],
+	[26, 3, -20, -29, -30],
+	[26, 4, -21, -29, -15, -30],
+	[16, 3, -33, 30, -34],
+	[30, 1, 2],
+	[22, 2, -4, 14],
+	[24, 3, 14, -4, 23],
+	[28, 1, -35],
+	[28, 1, -2],
+	[17, 2, -36, -18],
+	[29, 1, -17],
+	[29, 1, -19],
+	[29, 1, -18]
+];
+
+XPathParser.DOUBLEDOT = 2;
+XPathParser.DOUBLECOLON = 3;
+XPathParser.DOUBLESLASH = 4;
+XPathParser.NOTEQUAL = 5;
+XPathParser.LESSTHANOREQUAL = 6;
+XPathParser.GREATERTHANOREQUAL = 7;
+XPathParser.AND = 8;
+XPathParser.OR = 9;
+XPathParser.MOD = 10;
+XPathParser.DIV = 11;
+XPathParser.MULTIPLYOPERATOR = 12;
+XPathParser.FUNCTIONNAME = 13;
+XPathParser.AXISNAME = 14;
+XPathParser.LITERAL = 15;
+XPathParser.NUMBER = 16;
+XPathParser.ASTERISKNAMETEST = 17;
+XPathParser.QNAME = 18;
+XPathParser.NCNAMECOLONASTERISK = 19;
+XPathParser.NODETYPE = 20;
+XPathParser.PROCESSINGINSTRUCTIONWITHLITERAL = 21;
+XPathParser.EQUALS = 22;
+XPathParser.LESSTHAN = 23;
+XPathParser.GREATERTHAN = 24;
+XPathParser.PLUS = 25;
+XPathParser.MINUS = 26;
+XPathParser.BAR = 27;
+XPathParser.SLASH = 28;
+XPathParser.LEFTPARENTHESIS = 29;
+XPathParser.RIGHTPARENTHESIS = 30;
+XPathParser.COMMA = 31;
+XPathParser.AT = 32;
+XPathParser.LEFTBRACKET = 33;
+XPathParser.RIGHTBRACKET = 34;
+XPathParser.DOT = 35;
+XPathParser.DOLLAR = 36;
+
+XPathParser.prototype.tokenize = function(s1) {
+	var types = [];
+	var values = [];
+	var s = s1 + '\0';
+
+	var pos = 0;
+	var c = s.charAt(pos++);
+	while (1) {
+		while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
+			c = s.charAt(pos++);
+		}
+		if (c == '\0' || pos >= s.length) {
+			break;
+		}
+
+		if (c == '(') {
+			types.push(XPathParser.LEFTPARENTHESIS);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == ')') {
+			types.push(XPathParser.RIGHTPARENTHESIS);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == '[') {
+			types.push(XPathParser.LEFTBRACKET);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == ']') {
+			types.push(XPathParser.RIGHTBRACKET);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == '@') {
+			types.push(XPathParser.AT);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == ',') {
+			types.push(XPathParser.COMMA);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == '|') {
+			types.push(XPathParser.BAR);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == '+') {
+			types.push(XPathParser.PLUS);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == '-') {
+			types.push(XPathParser.MINUS);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == '=') {
+			types.push(XPathParser.EQUALS);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		if (c == '$') {
+			types.push(XPathParser.DOLLAR);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+		
+		if (c == '.') {
+			c = s.charAt(pos++);
+			if (c == '.') {
+				types.push(XPathParser.DOUBLEDOT);
+				values.push("..");
+				c = s.charAt(pos++);
+				continue;
+			}
+			if (c >= '0' && c <= '9') {
+				var number = "." + c;
+				c = s.charAt(pos++);
+				while (c >= '0' && c <= '9') {
+					number += c;
+					c = s.charAt(pos++);
+				}
+				types.push(XPathParser.NUMBER);
+				values.push(number);
+				continue;
+			}
+			types.push(XPathParser.DOT);
+			values.push('.');
+			continue;
+		}
+
+		if (c == '\'' || c == '"') {
+			var delimiter = c;
+			var literal = "";
+			while ((c = s.charAt(pos++)) != delimiter) {
+				literal += c;
+			}
+			types.push(XPathParser.LITERAL);
+			values.push(literal);
+			c = s.charAt(pos++);
+			continue;
+		}
+
+		if (c >= '0' && c <= '9') {
+			var number = c;
+			c = s.charAt(pos++);
+			while (c >= '0' && c <= '9') {
+				number += c;
+				c = s.charAt(pos++);
+			}
+			if (c == '.') {
+				if (s.charAt(pos) >= '0' && s.charAt(pos) <= '9') {
+					number += c;
+					number += s.charAt(pos++);
+					c = s.charAt(pos++);
+					while (c >= '0' && c <= '9') {
+						number += c;
+						c = s.charAt(pos++);
+					}
+				}
+			}
+			types.push(XPathParser.NUMBER);
+			values.push(number);
+			continue;
+		}
+
+		if (c == '*') {
+			if (types.length > 0) {
+				var last = types[types.length - 1];
+				if (last != XPathParser.AT
+						&& last != XPathParser.DOUBLECOLON
+						&& last != XPathParser.LEFTPARENTHESIS
+						&& last != XPathParser.LEFTBRACKET
+						&& last != XPathParser.AND
+						&& last != XPathParser.OR
+						&& last != XPathParser.MOD
+						&& last != XPathParser.DIV
+						&& last != XPathParser.MULTIPLYOPERATOR
+						&& last != XPathParser.SLASH
+						&& last != XPathParser.DOUBLESLASH
+						&& last != XPathParser.BAR
+						&& last != XPathParser.PLUS
+						&& last != XPathParser.MINUS
+						&& last != XPathParser.EQUALS
+						&& last != XPathParser.NOTEQUAL
+						&& last != XPathParser.LESSTHAN
+						&& last != XPathParser.LESSTHANOREQUAL
+						&& last != XPathParser.GREATERTHAN
+						&& last != XPathParser.GREATERTHANOREQUAL) {
+					types.push(XPathParser.MULTIPLYOPERATOR);
+					values.push(c);
+					c = s.charAt(pos++);
+					continue;
+				}
+			}
+			types.push(XPathParser.ASTERISKNAMETEST);
+			values.push(c);
+			c = s.charAt(pos++);
+			continue;
+		}
+
+		if (c == ':') {
+			if (s.charAt(pos) == ':') {
+				types.push(XPathParser.DOUBLECOLON);
+				values.push("::");
+				pos++;
+				c = s.charAt(pos++);
+				continue;
+			}
+		}
+
+		if (c == '/') {
+			c = s.charAt(pos++);
+			if (c == '/') {
+				types.push(XPathParser.DOUBLESLASH);
+				values.push("//");
+				c = s.charAt(pos++);
+				continue;
+			}
+			types.push(XPathParser.SLASH);
+			values.push('/');
+			continue;
+		}
+
+		if (c == '!') {
+			if (s.charAt(pos) == '=') {
+				types.push(XPathParser.NOTEQUAL);
+				values.push("!=");
+				pos++;
+				c = s.charAt(pos++);
+				continue;
+			}
+		}
+
+		if (c == '<') {
+			if (s.charAt(pos) == '=') {
+				types.push(XPathParser.LESSTHANOREQUAL);
+				values.push("<=");
+				pos++;
+				c = s.charAt(pos++);
+				continue;
+			}
+			types.push(XPathParser.LESSTHAN);
+			values.push('<');
+			c = s.charAt(pos++);
+			continue;
+		}
+
+		if (c == '>') {
+			if (s.charAt(pos) == '=') {
+				types.push(XPathParser.GREATERTHANOREQUAL);
+				values.push(">=");
+				pos++;
+				c = s.charAt(pos++);
+				continue;
+			}
+			types.push(XPathParser.GREATERTHAN);
+			values.push('>');
+			c = s.charAt(pos++);
+			continue;
+		}
+
+		if (c == '_' || Utilities.isLetter(c.charCodeAt(0))) {
+			var name = c;
+			c = s.charAt(pos++);
+			while (Utilities.isNCNameChar(c.charCodeAt(0))) {
+				name += c;
+				c = s.charAt(pos++);
+			}
+			if (types.length > 0) {
+				var last = types[types.length - 1];
+				if (last != XPathParser.AT
+						&& last != XPathParser.DOUBLECOLON
+						&& last != XPathParser.LEFTPARENTHESIS
+						&& last != XPathParser.LEFTBRACKET
+						&& last != XPathParser.AND
+						&& last != XPathParser.OR
+						&& last != XPathParser.MOD
+						&& last != XPathParser.DIV
+						&& last != XPathParser.MULTIPLYOPERATOR
+						&& last != XPathParser.SLASH
+						&& last != XPathParser.DOUBLESLASH
+						&& last != XPathParser.BAR
+						&& last != XPathParser.PLUS
+						&& last != XPathParser.MINUS
+						&& last != XPathParser.EQUALS
+						&& last != XPathParser.NOTEQUAL
+						&& last != XPathParser.LESSTHAN
+						&& last != XPathParser.LESSTHANOREQUAL
+						&& last != XPathParser.GREATERTHAN
+						&& last != XPathParser.GREATERTHANOREQUAL) {
+					if (name == "and") {
+						types.push(XPathParser.AND);
+						values.push(name);
+						continue;
+					}
+					if (name == "or") {
+						types.push(XPathParser.OR);
+						values.push(name);
+						continue;
+					}
+					if (name == "mod") {
+						types.push(XPathParser.MOD);
+						values.push(name);
+						continue;
+					}
+					if (name == "div") {
+						types.push(XPathParser.DIV);
+						values.push(name);
+						continue;
+					}
+				}
+			}
+			if (c == ':') {
+				if (s.charAt(pos) == '*') {
+					types.push(XPathParser.NCNAMECOLONASTERISK);
+					values.push(name + ":*");
+					pos++;
+					c = s.charAt(pos++);
+					continue;
+				}
+				if (s.charAt(pos) == '_' || Utilities.isLetter(s.charCodeAt(pos))) {
+					name += ':';
+					c = s.charAt(pos++);
+					while (Utilities.isNCNameChar(c.charCodeAt(0))) {
+						name += c;
+						c = s.charAt(pos++);
+					}
+					if (c == '(') {
+						types.push(XPathParser.FUNCTIONNAME);
+						values.push(name);
+						continue;
+					}
+					types.push(XPathParser.QNAME);
+					values.push(name);
+					continue;
+				}
+				if (s.charAt(pos) == ':') {
+					types.push(XPathParser.AXISNAME);
+					values.push(name);
+					continue;
+				}
+			}
+			if (c == '(') {
+				if (name == "comment" || name == "text" || name == "node") {
+					types.push(XPathParser.NODETYPE);
+					values.push(name);
+					continue;
+				}
+				if (name == "processing-instruction") {
+					if (s.charAt(pos) == ')') {
+						types.push(XPathParser.NODETYPE);
+					} else {
+						types.push(XPathParser.PROCESSINGINSTRUCTIONWITHLITERAL);
+					}
+					values.push(name);
+					continue;
+				}
+				types.push(XPathParser.FUNCTIONNAME);
+				values.push(name);
+				continue;
+			}
+			types.push(XPathParser.QNAME);
+			values.push(name);
+			continue;
+		}
+
+		throw new Error("Unexpected character " + c);
+	}
+	types.push(1);
+	values.push("[EOF]");
+	return [types, values];
+};
+
+XPathParser.SHIFT = 's';
+XPathParser.REDUCE = 'r';
+XPathParser.ACCEPT = 'a';
+
+XPathParser.prototype.parse = function(s) {
+	var types;
+	var values;
+	var res = this.tokenize(s);
+	if (res == undefined) {
+		return undefined;
+	}
+	types = res[0];
+	values = res[1];
+	var tokenPos = 0;
+	var state = [];
+	var tokenType = [];
+	var tokenValue = [];
+	var s;
+	var a;
+	var t;
+
+	state.push(0);
+	tokenType.push(1);
+	tokenValue.push("_S");
+
+	a = types[tokenPos];
+	t = values[tokenPos++];
+	while (1) {
+		s = state[state.length - 1];
+		switch (XPathParser.actionTable[s].charAt(a - 1)) {
+			case XPathParser.SHIFT:
+				tokenType.push(-a);
+				tokenValue.push(t);
+				state.push(XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32);
+				a = types[tokenPos];
+				t = values[tokenPos++];
+				break;
+			case XPathParser.REDUCE:
+				var num = XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][1];
+				var rhs = [];
+				for (var i = 0; i < num; i++) {
+					tokenType.pop();
+					rhs.unshift(tokenValue.pop());
+					state.pop();
+				}
+				var s_ = state[state.length - 1];
+				tokenType.push(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0]);
+				if (this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32] == undefined) {
+					tokenValue.push(rhs[0]);
+				} else {
+					tokenValue.push(this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32](rhs));
+				}
+				state.push(XPathParser.gotoTable[s_].charCodeAt(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0] - 2) - 33);
+				break;
+			case XPathParser.ACCEPT:
+				return new XPath(tokenValue.pop());
+			default:
+				throw new Error("XPath parse error");
+		}
+	}
+};
+
+// XPath /////////////////////////////////////////////////////////////////////
+
+XPath.prototype = new Object();
+XPath.prototype.constructor = XPath;
+XPath.superclass = Object.prototype;
+
+function XPath(e) {
+	this.expression = e;
+}
+
+XPath.prototype.toString = function() {
+	return this.expression.toString();
+};
+
+XPath.prototype.evaluate = function(c) {
+	c.contextNode = c.expressionContextNode;
+	c.contextSize = 1;
+	c.contextPosition = 1;
+	c.caseInsensitive = false;
+	if (c.contextNode != null) {
+		var doc = c.contextNode;
+		if (doc.nodeType != 9 /*Node.DOCUMENT_NODE*/) {
+			doc = doc.ownerDocument;
+		}
+		try {
+			c.caseInsensitive = doc.implementation.hasFeature("HTML", "2.0");
+		} catch (e) {
+			c.caseInsensitive = true;
+		}
+	}
+	return this.expression.evaluate(c);
+};
+
+XPath.XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
+XPath.XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
+
+// Expression ////////////////////////////////////////////////////////////////
+
+Expression.prototype = new Object();
+Expression.prototype.constructor = Expression;
+Expression.superclass = Object.prototype;
+
+function Expression() {
+}
+
+Expression.prototype.init = function() {
+};
+
+Expression.prototype.toString = function() {
+	return "<Expression>";
+};
+
+Expression.prototype.evaluate = function(c) {
+	throw new Error("Could not evaluate expression.");
+};
+
+// UnaryOperation ////////////////////////////////////////////////////////////
+
+UnaryOperation.prototype = new Expression();
+UnaryOperation.prototype.constructor = UnaryOperation;
+UnaryOperation.superclass = Expression.prototype;
+
+function UnaryOperation(rhs) {
+	if (arguments.length > 0) {
+		this.init(rhs);
+	}
+}
+
+UnaryOperation.prototype.init = function(rhs) {
+	this.rhs = rhs;
+};
+
+// UnaryMinusOperation ///////////////////////////////////////////////////////
+
+UnaryMinusOperation.prototype = new UnaryOperation();
+UnaryMinusOperation.prototype.constructor = UnaryMinusOperation;
+UnaryMinusOperation.superclass = UnaryOperation.prototype;
+
+function UnaryMinusOperation(rhs) {
+	if (arguments.length > 0) {
+		this.init(rhs);
+	}
+}
+
+UnaryMinusOperation.prototype.init = function(rhs) {
+	UnaryMinusOperation.superclass.init.call(this, rhs);
+};
+
+UnaryMinusOperation.prototype.evaluate = function(c) {
+	return this.rhs.evaluate(c).number().negate();
+};
+
+UnaryMinusOperation.prototype.toString = function() {
+	return "-" + this.rhs.toString();
+};
+
+// BinaryOperation ///////////////////////////////////////////////////////////
+
+BinaryOperation.prototype = new Expression();
+BinaryOperation.prototype.constructor = BinaryOperation;
+BinaryOperation.superclass = Expression.prototype;
+
+function BinaryOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+BinaryOperation.prototype.init = function(lhs, rhs) {
+	this.lhs = lhs;
+	this.rhs = rhs;
+};
+
+// OrOperation ///////////////////////////////////////////////////////////////
+
+OrOperation.prototype = new BinaryOperation();
+OrOperation.prototype.constructor = OrOperation;
+OrOperation.superclass = BinaryOperation.prototype;
+
+function OrOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+OrOperation.prototype.init = function(lhs, rhs) {
+	OrOperation.superclass.init.call(this, lhs, rhs);
+};
+
+OrOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " or " + this.rhs.toString() + ")";
+};
+
+OrOperation.prototype.evaluate = function(c) {
+	var b = this.lhs.evaluate(c).bool();
+	if (b.booleanValue()) {
+		return b;
+	}
+	return this.rhs.evaluate(c).bool();
+};
+
+// AndOperation //////////////////////////////////////////////////////////////
+
+AndOperation.prototype = new BinaryOperation();
+AndOperation.prototype.constructor = AndOperation;
+AndOperation.superclass = BinaryOperation.prototype;
+
+function AndOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+AndOperation.prototype.init = function(lhs, rhs) {
+	AndOperation.superclass.init.call(this, lhs, rhs);
+};
+
+AndOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " and " + this.rhs.toString() + ")";
+};
+
+AndOperation.prototype.evaluate = function(c) {
+	var b = this.lhs.evaluate(c).bool();
+	if (!b.booleanValue()) {
+		return b;
+	}
+	return this.rhs.evaluate(c).bool();
+};
+
+// EqualsOperation ///////////////////////////////////////////////////////////
+
+EqualsOperation.prototype = new BinaryOperation();
+EqualsOperation.prototype.constructor = EqualsOperation;
+EqualsOperation.superclass = BinaryOperation.prototype;
+
+function EqualsOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+EqualsOperation.prototype.init = function(lhs, rhs) {
+	EqualsOperation.superclass.init.call(this, lhs, rhs);
+};
+
+EqualsOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " = " + this.rhs.toString() + ")";
+};
+
+EqualsOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).equals(this.rhs.evaluate(c));
+};
+
+// NotEqualOperation /////////////////////////////////////////////////////////
+
+NotEqualOperation.prototype = new BinaryOperation();
+NotEqualOperation.prototype.constructor = NotEqualOperation;
+NotEqualOperation.superclass = BinaryOperation.prototype;
+
+function NotEqualOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+NotEqualOperation.prototype.init = function(lhs, rhs) {
+	NotEqualOperation.superclass.init.call(this, lhs, rhs);
+};
+
+NotEqualOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " != " + this.rhs.toString() + ")";
+};
+
+NotEqualOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).notequal(this.rhs.evaluate(c));
+};
+
+// LessThanOperation /////////////////////////////////////////////////////////
+
+LessThanOperation.prototype = new BinaryOperation();
+LessThanOperation.prototype.constructor = LessThanOperation;
+LessThanOperation.superclass = BinaryOperation.prototype;
+
+function LessThanOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+LessThanOperation.prototype.init = function(lhs, rhs) {
+	LessThanOperation.superclass.init.call(this, lhs, rhs);
+};
+
+LessThanOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).lessthan(this.rhs.evaluate(c));
+};
+
+LessThanOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " < " + this.rhs.toString() + ")";
+};
+
+// GreaterThanOperation //////////////////////////////////////////////////////
+
+GreaterThanOperation.prototype = new BinaryOperation();
+GreaterThanOperation.prototype.constructor = GreaterThanOperation;
+GreaterThanOperation.superclass = BinaryOperation.prototype;
+
+function GreaterThanOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+GreaterThanOperation.prototype.init = function(lhs, rhs) {
+	GreaterThanOperation.superclass.init.call(this, lhs, rhs);
+};
+
+GreaterThanOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).greaterthan(this.rhs.evaluate(c));
+};
+
+GreaterThanOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " > " + this.rhs.toString() + ")";
+};
+
+// LessThanOrEqualOperation //////////////////////////////////////////////////
+
+LessThanOrEqualOperation.prototype = new BinaryOperation();
+LessThanOrEqualOperation.prototype.constructor = LessThanOrEqualOperation;
+LessThanOrEqualOperation.superclass = BinaryOperation.prototype;
+
+function LessThanOrEqualOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+LessThanOrEqualOperation.prototype.init = function(lhs, rhs) {
+	LessThanOrEqualOperation.superclass.init.call(this, lhs, rhs);
+};
+
+LessThanOrEqualOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).lessthanorequal(this.rhs.evaluate(c));
+};
+
+LessThanOrEqualOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " <= " + this.rhs.toString() + ")";
+};
+
+// GreaterThanOrEqualOperation ///////////////////////////////////////////////
+
+GreaterThanOrEqualOperation.prototype = new BinaryOperation();
+GreaterThanOrEqualOperation.prototype.constructor = GreaterThanOrEqualOperation;
+GreaterThanOrEqualOperation.superclass = BinaryOperation.prototype;
+
+function GreaterThanOrEqualOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+GreaterThanOrEqualOperation.prototype.init = function(lhs, rhs) {
+	GreaterThanOrEqualOperation.superclass.init.call(this, lhs, rhs);
+};
+
+GreaterThanOrEqualOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).greaterthanorequal(this.rhs.evaluate(c));
+};
+
+GreaterThanOrEqualOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " >= " + this.rhs.toString() + ")";
+};
+
+// PlusOperation /////////////////////////////////////////////////////////////
+
+PlusOperation.prototype = new BinaryOperation();
+PlusOperation.prototype.constructor = PlusOperation;
+PlusOperation.superclass = BinaryOperation.prototype;
+
+function PlusOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+PlusOperation.prototype.init = function(lhs, rhs) {
+	PlusOperation.superclass.init.call(this, lhs, rhs);
+};
+
+PlusOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).number().plus(this.rhs.evaluate(c).number());
+};
+
+PlusOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " + " + this.rhs.toString() + ")";
+};
+
+// MinusOperation ////////////////////////////////////////////////////////////
+
+MinusOperation.prototype = new BinaryOperation();
+MinusOperation.prototype.constructor = MinusOperation;
+MinusOperation.superclass = BinaryOperation.prototype;
+
+function MinusOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+MinusOperation.prototype.init = function(lhs, rhs) {
+	MinusOperation.superclass.init.call(this, lhs, rhs);
+};
+
+MinusOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).number().minus(this.rhs.evaluate(c).number());
+};
+
+MinusOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " - " + this.rhs.toString() + ")";
+};
+
+// MultiplyOperation /////////////////////////////////////////////////////////
+
+MultiplyOperation.prototype = new BinaryOperation();
+MultiplyOperation.prototype.constructor = MultiplyOperation;
+MultiplyOperation.superclass = BinaryOperation.prototype;
+
+function MultiplyOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+MultiplyOperation.prototype.init = function(lhs, rhs) {
+	MultiplyOperation.superclass.init.call(this, lhs, rhs);
+};
+
+MultiplyOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).number().multiply(this.rhs.evaluate(c).number());
+};
+
+MultiplyOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " * " + this.rhs.toString() + ")";
+};
+
+// DivOperation //////////////////////////////////////////////////////////////
+
+DivOperation.prototype = new BinaryOperation();
+DivOperation.prototype.constructor = DivOperation;
+DivOperation.superclass = BinaryOperation.prototype;
+
+function DivOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+DivOperation.prototype.init = function(lhs, rhs) {
+	DivOperation.superclass.init.call(this, lhs, rhs);
+};
+
+DivOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).number().div(this.rhs.evaluate(c).number());
+};
+
+DivOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " div " + this.rhs.toString() + ")";
+};
+
+// ModOperation //////////////////////////////////////////////////////////////
+
+ModOperation.prototype = new BinaryOperation();
+ModOperation.prototype.constructor = ModOperation;
+ModOperation.superclass = BinaryOperation.prototype;
+
+function ModOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+ModOperation.prototype.init = function(lhs, rhs) {
+	ModOperation.superclass.init.call(this, lhs, rhs);
+};
+
+ModOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).number().mod(this.rhs.evaluate(c).number());
+};
+
+ModOperation.prototype.toString = function() {
+	return "(" + this.lhs.toString() + " mod " + this.rhs.toString() + ")";
+};
+
+// BarOperation //////////////////////////////////////////////////////////////
+
+BarOperation.prototype = new BinaryOperation();
+BarOperation.prototype.constructor = BarOperation;
+BarOperation.superclass = BinaryOperation.prototype;
+
+function BarOperation(lhs, rhs) {
+	if (arguments.length > 0) {
+		this.init(lhs, rhs);
+	}
+}
+
+BarOperation.prototype.init = function(lhs, rhs) {
+	BarOperation.superclass.init.call(this, lhs, rhs);
+};
+
+BarOperation.prototype.evaluate = function(c) {
+	return this.lhs.evaluate(c).nodeset().union(this.rhs.evaluate(c).nodeset());
+};
+
+BarOperation.prototype.toString = function() {
+	return this.lhs.toString() + " | " + this.rhs.toString();
+};
+
+// PathExpr //////////////////////////////////////////////////////////////////
+
+PathExpr.prototype = new Expression();
+PathExpr.prototype.constructor = PathExpr;
+PathExpr.superclass = Expression.prototype;
+
+function PathExpr(filter, filterPreds, locpath) {
+	if (arguments.length > 0) {
+		this.init(filter, filterPreds, locpath);
+	}
+}
+
+PathExpr.prototype.init = function(filter, filterPreds, locpath) {
+	PathExpr.superclass.init.call(this);
+	this.filter = filter;
+	this.filterPredicates = filterPreds;
+	this.locationPath = locpath;
+};
+
+PathExpr.prototype.evaluate = function(c) {
+	var nodes;
+	var xpc = new XPathContext();
+	xpc.variableResolver = c.variableResolver;
+	xpc.functionResolver = c.functionResolver;
+	xpc.namespaceResolver = c.namespaceResolver;
+	xpc.expressionContextNode = c.expressionContextNode;
+	xpc.virtualRoot = c.virtualRoot;
+	xpc.caseInsensitive = c.caseInsensitive;
+	if (this.filter == null) {
+		nodes = [ c.contextNode ];
+	} else {
+		var ns = this.filter.evaluate(c);
+		if (!Utilities.instance_of(ns, XNodeSet)) {
+			if (this.filterPredicates != null && this.filterPredicates.length > 0 || this.locationPath != null) {
+				throw new Error("Path expression filter must evaluate to a nodset if predicates or location path are used");
+			}
+			return ns;
+		}
+		nodes = ns.toArray();
+		if (this.filterPredicates != null) {
+			// apply each of the predicates in turn
+			for (var j = 0; j < this.filterPredicates.length; j++) {
+				var pred = this.filterPredicates[j];
+				var newNodes = [];
+				xpc.contextSize = nodes.length;
+				for (xpc.contextPosition = 1; xpc.contextPosition <= xpc.contextSize; xpc.contextPosition++) {
+					xpc.contextNode = nodes[xpc.contextPosition - 1];
+					if (this.predicateMatches(pred, xpc)) {
+						newNodes.push(xpc.contextNode);
+					}
+				}
+				nodes = newNodes;
+			}
+		}
+	}
+	if (this.locationPath != null) {
+		if (this.locationPath.absolute) {
+			if (nodes[0].nodeType != 9 /*Node.DOCUMENT_NODE*/) {
+				if (xpc.virtualRoot != null) {
+					nodes = [ xpc.virtualRoot ];
+				} else {
+					if (nodes[0].ownerDocument == null) {
+						// IE 5.5 doesn't have ownerDocument?
+						var n = nodes[0];
+						while (n.parentNode != null) {
+							n = n.parentNode;
+						}
+						nodes = [ n ];
+					} else {
+						nodes = [ nodes[0].ownerDocument ];
+					}
+				}
+			} else {
+				nodes = [ nodes[0] ];
+			}
+		}
+		for (var i = 0; i < this.locationPath.steps.length; i++) {
+			var step = this.locationPath.steps[i];
+			var newNodes = [];
+			for (var j = 0; j < nodes.length; j++) {
+				xpc.contextNode = nodes[j];
+				switch (step.axis) {
+					case Step.ANCESTOR:
+						// look at all the ancestor nodes
+						if (xpc.contextNode === xpc.virtualRoot) {
+							break;
+						}
+						var m;
+						if (xpc.contextNode.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
+							m = this.getOwnerElement(xpc.contextNode);
+						} else {
+							m = xpc.contextNode.parentNode;
+						}
+						while (m != null) {
+							if (step.nodeTest.matches(m, xpc)) {
+								newNodes.push(m);
+							}
+							if (m === xpc.virtualRoot) {
+								break;
+							}
+							m = m.parentNode;
+						}
+						break;
+
+					case Step.ANCESTORORSELF:
+						// look at all the ancestor nodes and the current node
+						for (var m = xpc.contextNode; m != null; m = m.nodeType == 2 /*Node.ATTRIBUTE_NODE*/ ? this.getOwnerElement(m) : m.parentNode) {
+							if (step.nodeTest.matches(m, xpc)) {
+								newNodes.push(m);
+							}
+							if (m === xpc.virtualRoot) {
+								break;
+							}
+						}
+						break;
+
+					case Step.ATTRIBUTE:
+						// look at the attributes
+						var nnm = xpc.contextNode.attributes;
+						if (nnm != null) {
+							for (var k = 0; k < nnm.length; k++) {
+								var m = nnm.item(k);
+								if (step.nodeTest.matches(m, xpc)) {
+									newNodes.push(m);
+								}
+							}
+						}
+						break;
+
+					case Step.CHILD:
+						// look at all child elements
+						for (var m = xpc.contextNode.firstChild; m != null; m = m.nextSibling) {
+							if (step.nodeTest.matches(m, xpc)) {
+								newNodes.push(m);
+							}
+						}
+						break;
+
+					case Step.DESCENDANT:
+						// look at all descendant nodes
+						var st = [ xpc.contextNode.firstChild ];
+						while (st.length > 0) {
+							for (var m = st.pop(); m != null; ) {
+								if (step.nodeTest.matches(m, xpc)) {
+									newNodes.push(m);
+								}
+								if (m.firstChild != null) {
+									st.push(m.nextSibling);
+									m = m.firstChild;
+								} else {
+									m = m.nextSibling;
+								}
+							}
+						}
+						break;
+
+					case Step.DESCENDANTORSELF:
+						// look at self
+						if (step.nodeTest.matches(xpc.contextNode, xpc)) {
+							newNodes.push(xpc.contextNode);
+						}
+						// look at all descendant nodes
+						var st = [ xpc.contextNode.firstChild ];
+						while (st.length > 0) {
+							for (var m = st.pop(); m != null; ) {
+								if (step.nodeTest.matches(m, xpc)) {
+									newNodes.push(m);
+								}
+								if (m.firstChild != null) {
+									st.push(m.nextSibling);
+									m = m.firstChild;
+								} else {
+									m = m.nextSibling;
+								}
+							}
+						}
+						break;
+
+					case Step.FOLLOWING:
+						if (xpc.contextNode === xpc.virtualRoot) {
+							break;
+						}
+						var st = [];
+						if (xpc.contextNode.firstChild != null) {
+							st.unshift(xpc.contextNode.firstChild);
+						} else {
+							st.unshift(xpc.contextNode.nextSibling);
+						}
+						for (var m = xpc.contextNode.parentNode; m != null && m.nodeType != 9 /*Node.DOCUMENT_NODE*/ && m !== xpc.virtualRoot; m = m.parentNode) {
+							st.unshift(m.nextSibling);
+						}
+						do {
+							for (var m = st.pop(); m != null; ) {
+								if (step.nodeTest.matches(m, xpc)) {
+									newNodes.push(m);
+								}
+								if (m.firstChild != null) {
+									st.push(m.nextSibling);
+									m = m.firstChild;
+								} else {
+									m = m.nextSibling;
+								}
+							}
+						} while (st.length > 0);
+						break;
+						
+					case Step.FOLLOWINGSIBLING:
+						if (xpc.contextNode === xpc.virtualRoot) {
+							break;
+						}
+						for (var m = xpc.contextNode.nextSibling; m != null; m = m.nextSibling) {
+							if (step.nodeTest.matches(m, xpc)) {
+								newNodes.push(m);
+							}
+						}
+						break;
+
+					case Step.NAMESPACE:
+						var n = {};
+						if (xpc.contextNode.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+							n["xml"] = XPath.XML_NAMESPACE_URI;
+							n["xmlns"] = XPath.XMLNS_NAMESPACE_URI;
+							for (var m = xpc.contextNode; m != null && m.nodeType == 1 /*Node.ELEMENT_NODE*/; m = m.parentNode) {
+								for (var k = 0; k < m.attributes.length; k++) {
+									var attr = m.attributes.item(k);
+									var nm = String(attr.name);
+									if (nm == "xmlns") {
+										if (n[""] == undefined) {
+											n[""] = attr.value;
+										}
+									} else if (nm.length > 6 && nm.substring(0, 6) == "xmlns:") {
+										var pre = nm.substring(6, nm.length);
+										if (n[pre] == undefined) {
+											n[pre] = attr.value;
+										}
+									}
+								}
+							}
+							for (var pre in n) {
+								var nsn = new NamespaceNode(pre, n[pre], xpc.contextNode);
+								if (step.nodeTest.matches(nsn, xpc)) {
+									newNodes.push(nsn);
+								}
+							}
+						}
+						break;
+
+					case Step.PARENT:
+						m = null;
+						if (xpc.contextNode !== xpc.virtualRoot) {
+							if (xpc.contextNode.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
+								m = this.getOwnerElement(xpc.contextNode);
+							} else {
+								m = xpc.contextNode.parentNode;
+							}
+						}
+						if (m != null && step.nodeTest.matches(m, xpc)) {
+							newNodes.push(m);
+						}
+						break;
+
+					case Step.PRECEDING:
+						var st;
+						if (xpc.virtualRoot != null) {
+							st = [ xpc.virtualRoot ];
+						} else {
+							st = xpc.contextNode.nodeType == 9 /*Node.DOCUMENT_NODE*/
+								? [ xpc.contextNode ]
+								: [ xpc.contextNode.ownerDocument ];
+						}
+						outer: while (st.length > 0) {
+							for (var m = st.pop(); m != null; ) {
+								if (m == xpc.contextNode) {
+									break outer;
+								}
+								if (step.nodeTest.matches(m, xpc)) {
+									newNodes.unshift(m);
+								}
+								if (m.firstChild != null) {
+									st.push(m.nextSibling);
+									m = m.firstChild;
+								} else {
+									m = m.nextSibling;
+								}
+							}
+						}
+						break;
+
+					case Step.PRECEDINGSIBLING:
+						if (xpc.contextNode === xpc.virtualRoot) {
+							break;
+						}
+						for (var m = xpc.contextNode.previousSibling; m != null; m = m.previousSibling) {
+							if (step.nodeTest.matches(m, xpc)) {
+								newNodes.push(m);
+							}
+						}
+						break;
+
+					case Step.SELF:
+						if (step.nodeTest.matches(xpc.contextNode, xpc)) {
+							newNodes.push(xpc.contextNode);
+						}
+						break;
+
+					default:
+				}
+			}
+			nodes = newNodes;
+			// apply each of the predicates in turn
+			for (var j = 0; j < step.predicates.length; j++) {
+				var pred = step.predicates[j];
+				var newNodes = [];
+				xpc.contextSize = nodes.length;
+				for (xpc.contextPosition = 1; xpc.contextPosition <= xpc.contextSize; xpc.contextPosition++) {
+					xpc.contextNode = nodes[xpc.contextPosition - 1];
+					if (this.predicateMatches(pred, xpc)) {
+						newNodes.push(xpc.contextNode);
+					} else {
+					}
+				}
+				nodes = newNodes;
+			}
+		}
+	}
+	var ns = new XNodeSet();
+	ns.addArray(nodes);
+	return ns;
+};
+
+PathExpr.prototype.predicateMatches = function(pred, c) {
+	var res = pred.evaluate(c);
+	if (Utilities.instance_of(res, XNumber)) {
+		return c.contextPosition == res.numberValue();
+	}
+	return res.booleanValue();
+};
+
+PathExpr.prototype.toString = function() {
+	if (this.filter != undefined) {
+		var s = this.filter.toString();
+		if (Utilities.instance_of(this.filter, XString)) {
+			s = "'" + s + "'";
+		}
+		if (this.filterPredicates != undefined) {
+			for (var i = 0; i < this.filterPredicates.length; i++) {
+				s = s + "[" + this.filterPredicates[i].toString() + "]";
+			}
+		}
+		if (this.locationPath != undefined) {
+			if (!this.locationPath.absolute) {
+				s += "/";
+			}
+			s += this.locationPath.toString();
+		}
+		return s;
+	}
+	return this.locationPath.toString();
+};
+
+PathExpr.prototype.getOwnerElement = function(n) {
+	// DOM 2 has ownerElement
+	if (n.ownerElement) {
+		return n.ownerElement;
+	}
+	// DOM 1 Internet Explorer can use selectSingleNode (ironically)
+	try {
+		if (n.selectSingleNode) {
+			return n.selectSingleNode("..");
+		}
+	} catch (e) {
+	}
+	// Other DOM 1 implementations must use this egregious search
+	var doc = n.nodeType == 9 /*Node.DOCUMENT_NODE*/
+			? n
+			: n.ownerDocument;
+	var elts = doc.getElementsByTagName("*");
+	for (var i = 0; i < elts.length; i++) {
+		var elt = elts.item(i);
+		var nnm = elt.attributes;
+		for (var j = 0; j < nnm.length; j++) {
+			var an = nnm.item(j);
+			if (an === n) {
+				return elt;
+			}
+		}
+	}
+	return null;
+};
+
+// LocationPath //////////////////////////////////////////////////////////////
+
+LocationPath.prototype = new Object();
+LocationPath.prototype.constructor = LocationPath;
+LocationPath.superclass = Object.prototype;
+
+function LocationPath(abs, steps) {
+	if (arguments.length > 0) {
+		this.init(abs, steps);
+	}
+}
+
+LocationPath.prototype.init = function(abs, steps) {
+	this.absolute = abs;
+	this.steps = steps;
+};
+
+LocationPath.prototype.toString = function() {
+	var s;
+	if (this.absolute) {
+		s = "/";
+	} else {
+		s = "";
+	}
+	for (var i = 0; i < this.steps.length; i++) {
+		if (i != 0) {
+			s += "/";
+		}
+		s += this.steps[i].toString();
+	}
+	return s;
+};
+
+// Step //////////////////////////////////////////////////////////////////////
+
+Step.prototype = new Object();
+Step.prototype.constructor = Step;
+Step.superclass = Object.prototype;
+
+function Step(axis, nodetest, preds) {
+	if (arguments.length > 0) {
+		this.init(axis, nodetest, preds);
+	}
+}
+
+Step.prototype.init = function(axis, nodetest, preds) {
+	this.axis = axis;
+	this.nodeTest = nodetest;
+	this.predicates = preds;
+};
+
+Step.prototype.toString = function() {
+	var s;
+	switch (this.axis) {
+		case Step.ANCESTOR:
+			s = "ancestor";
+			break;
+		case Step.ANCESTORORSELF:
+			s = "ancestor-or-self";
+			break;
+		case Step.ATTRIBUTE:
+			s = "attribute";
+			break;
+		case Step.CHILD:
+			s = "child";
+			break;
+		case Step.DESCENDANT:
+			s = "descendant";
+			break;
+		case Step.DESCENDANTORSELF:
+			s = "descendant-or-self";
+			break;
+		case Step.FOLLOWING:
+			s = "following";
+			break;
+		case Step.FOLLOWINGSIBLING:
+			s = "following-sibling";
+			break;
+		case Step.NAMESPACE:
+			s = "namespace";
+			break;
+		case Step.PARENT:
+			s = "parent";
+			break;
+		case Step.PRECEDING:
+			s = "preceding";
+			break;
+		case Step.PRECEDINGSIBLING:
+			s = "preceding-sibling";
+			break;
+		case Step.SELF:
+			s = "self";
+			break;
+	}
+	s += "::";
+	s += this.nodeTest.toString();
+	for (var i = 0; i < this.predicates.length; i++) {
+		s += "[" + this.predicates[i].toString() + "]";
+	}
+	return s;
+};
+
+Step.ANCESTOR = 0;
+Step.ANCESTORORSELF = 1;
+Step.ATTRIBUTE = 2;
+Step.CHILD = 3;
+Step.DESCENDANT = 4;
+Step.DESCENDANTORSELF = 5;
+Step.FOLLOWING = 6;
+Step.FOLLOWINGSIBLING = 7;
+Step.NAMESPACE = 8;
+Step.PARENT = 9;
+Step.PRECEDING = 10;
+Step.PRECEDINGSIBLING = 11;
+Step.SELF = 12;
+
+// NodeTest //////////////////////////////////////////////////////////////////
+
+NodeTest.prototype = new Object();
+NodeTest.prototype.constructor = NodeTest;
+NodeTest.superclass = Object.prototype;
+
+function NodeTest(type, value) {
+	if (arguments.length > 0) {
+		this.init(type, value);
+	}
+}
+
+NodeTest.prototype.init = function(type, value) {
+	this.type = type;
+	this.value = value;
+};
+
+NodeTest.prototype.toString = function() {
+	switch (this.type) {
+		case NodeTest.NAMETESTANY:
+			return "*";
+		case NodeTest.NAMETESTPREFIXANY:
+			return this.value + ":*";
+		case NodeTest.NAMETESTRESOLVEDANY:
+			return "{" + this.value + "}*";
+		case NodeTest.NAMETESTQNAME:
+			return this.value;
+		case NodeTest.NAMETESTRESOLVEDNAME:
+			return "{" + this.namespaceURI + "}" + this.value;
+		case NodeTest.COMMENT:
+			return "comment()";
+		case NodeTest.TEXT:
+			return "text()";
+		case NodeTest.PI:
+			if (this.value != undefined) {
+				return "processing-instruction(\"" + this.value + "\")";
+			}
+			return "processing-instruction()";
+		case NodeTest.NODE:
+			return "node()";
+	}
+	return "<unknown nodetest type>";
+};
+
+NodeTest.prototype.matches = function(n, xpc) {
+	switch (this.type) {
+		case NodeTest.NAMETESTANY:
+			if (n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/
+					|| n.nodeType == 1 /*Node.ELEMENT_NODE*/
+					|| n.nodeType == XPathNamespace.XPATH_NAMESPACE_NODE) {
+				return true;
+			}
+			return false;
+		case NodeTest.NAMETESTPREFIXANY:
+			if ((n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/ || n.nodeType == 1 /*Node.ELEMENT_NODE*/)) {
+                var ns = xpc.namespaceResolver.getNamespace(this.value, xpc.expressionContextNode)
+                if (ns == null) {
+                    throw new Error("Cannot resolve QName " + this.value);
+                }
+				return true;	
+			}
+			return false;
+		case NodeTest.NAMETESTQNAME:
+			if (n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/
+					|| n.nodeType == 1 /*Node.ELEMENT_NODE*/
+					|| n.nodeType == XPathNamespace.XPATH_NAMESPACE_NODE) {
+				var test = Utilities.resolveQName(this.value, xpc.namespaceResolver, xpc.expressionContextNode, false);
+                if (test[0] == null) {
+                    throw new Error("Cannot resolve QName " + this.value);
+                }
+				test[0] = String(test[0]);
+				test[1] = String(test[1]);
+				if (test[0] == "") {
+					test[0] = null;
+				}
+				var node = Utilities.resolveQName(n.nodeName, xpc.namespaceResolver, n, true);
+				node[0] = String(node[0]);
+				node[1] = String(node[1]);
+				if (node[0] == "") {
+					node[0] = null;
+				}
+				if (xpc.caseInsensitive) {
+					return test[0] == node[0] && String(test[1]).toLowerCase() == String(node[1]).toLowerCase();
+				}
+				return test[0] == node[0] && test[1] == node[1];
+			}
+			return false;
+		case NodeTest.COMMENT:
+			return n.nodeType == 8 /*Node.COMMENT_NODE*/;
+		case NodeTest.TEXT:
+			return n.nodeType == 3 /*Node.TEXT_NODE*/ || n.nodeType == 4 /*Node.CDATA_SECTION_NODE*/;
+		case NodeTest.PI:
+			return n.nodeType == 7 /*Node.PROCESSING_INSTRUCTION_NODE*/
+				&& (this.value == null || n.nodeName == this.value);
+		case NodeTest.NODE:
+			return n.nodeType == 9 /*Node.DOCUMENT_NODE*/
+				|| n.nodeType == 1 /*Node.ELEMENT_NODE*/
+				|| n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/
+				|| n.nodeType == 3 /*Node.TEXT_NODE*/
+				|| n.nodeType == 4 /*Node.CDATA_SECTION_NODE*/
+				|| n.nodeType == 8 /*Node.COMMENT_NODE*/
+				|| n.nodeType == 7 /*Node.PROCESSING_INSTRUCTION_NODE*/;
+	}
+	return false;
+};
+
+NodeTest.NAMETESTANY = 0;
+NodeTest.NAMETESTPREFIXANY = 1;
+NodeTest.NAMETESTQNAME = 2;
+NodeTest.COMMENT = 3;
+NodeTest.TEXT = 4;
+NodeTest.PI = 5;
+NodeTest.NODE = 6;
+
+// VariableReference /////////////////////////////////////////////////////////
+
+VariableReference.prototype = new Expression();
+VariableReference.prototype.constructor = VariableReference;
+VariableReference.superclass = Expression.prototype;
+
+function VariableReference(v) {
+	if (arguments.length > 0) {
+		this.init(v);
+	}
+}
+
+VariableReference.prototype.init = function(v) {
+	this.variable = v;
+};
+
+VariableReference.prototype.toString = function() {
+	return "$" + this.variable;
+};
+
+VariableReference.prototype.evaluate = function(c) {
+	return c.variableResolver.getVariable(this.variable, c);
+};
+
+// FunctionCall //////////////////////////////////////////////////////////////
+
+FunctionCall.prototype = new Expression();
+FunctionCall.prototype.constructor = FunctionCall;
+FunctionCall.superclass = Expression.prototype;
+
+function FunctionCall(fn, args) {
+	if (arguments.length > 0) {
+		this.init(fn, args);
+	}
+}
+
+FunctionCall.prototype.init = function(fn, args) {
+	this.functionName = fn;
+	this.arguments = args;
+};
+
+FunctionCall.prototype.toString = function() {
+	var s = this.functionName + "(";
+	for (var i = 0; i < this.arguments.length; i++) {
+		if (i > 0) {
+			s += ", ";
+		}
+		s += this.arguments[i].toString();
+	}
+	return s + ")";
+};
+
+FunctionCall.prototype.evaluate = function(c) {
+	var f = c.functionResolver.getFunction(this.functionName, c);
+	if (f == undefined) {
+		throw new Error("Unknown function " + this.functionName);
+	}
+	var a = [c].concat(this.arguments);
+	return f.apply(c.functionResolver.thisArg, a);
+};
+
+// XString ///////////////////////////////////////////////////////////////////
+
+XString.prototype = new Expression();
+XString.prototype.constructor = XString;
+XString.superclass = Expression.prototype;
+
+function XString(s) {
+	if (arguments.length > 0) {
+		this.init(s);
+	}
+}
+
+XString.prototype.init = function(s) {
+	this.str = s;
+};
+
+XString.prototype.toString = function() {
+	return this.str;
+};
+
+XString.prototype.evaluate = function(c) {
+	return this;
+};
+
+XString.prototype.string = function() {
+	return this;
+};
+
+XString.prototype.number = function() {
+	return new XNumber(this.str);
+};
+
+XString.prototype.bool = function() {
+	return new XBoolean(this.str);
+};
+
+XString.prototype.nodeset = function() {
+	throw new Error("Cannot convert string to nodeset");
+};
+
+XString.prototype.stringValue = function() {
+	return this.str;
+};
+
+XString.prototype.numberValue = function() {
+	return this.number().numberValue();
+};
+
+XString.prototype.booleanValue = function() {
+	return this.bool().booleanValue();
+};
+
+XString.prototype.equals = function(r) {
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.bool().equals(r);
+	}
+	if (Utilities.instance_of(r, XNumber)) {
+		return this.number().equals(r);
+	}
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithString(this, Operators.equals);
+	}
+	return new XBoolean(this.str == r.str);
+};
+
+XString.prototype.notequal = function(r) {
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.bool().notequal(r);
+	}
+	if (Utilities.instance_of(r, XNumber)) {
+		return this.number().notequal(r);
+	}
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithString(this, Operators.notequal);
+	}
+	return new XBoolean(this.str != r.str);
+};
+
+XString.prototype.lessthan = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this.number(), Operators.greaterthanorequal);
+	}
+	return this.number().lessthan(r.number());
+};
+
+XString.prototype.greaterthan = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this.number(), Operators.lessthanorequal);
+	}
+	return this.number().greaterthan(r.number());
+};
+
+XString.prototype.lessthanorequal = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this.number(), Operators.greaterthan);
+	}
+	return this.number().lessthanorequal(r.number());
+};
+
+XString.prototype.greaterthanorequal = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this.number(), Operators.lessthan);
+	}
+	return this.number().greaterthanorequal(r.number());
+};
+
+// XNumber ///////////////////////////////////////////////////////////////////
+
+XNumber.prototype = new Expression();
+XNumber.prototype.constructor = XNumber;
+XNumber.superclass = Expression.prototype;
+
+function XNumber(n) {
+	if (arguments.length > 0) {
+		this.init(n);
+	}
+}
+
+XNumber.prototype.init = function(n) {
+	this.num = Number(n);
+};
+
+XNumber.prototype.toString = function() {
+	return this.num;
+};
+
+XNumber.prototype.evaluate = function(c) {
+	return this;
+};
+
+XNumber.prototype.string = function() {
+	return new XString(this.num);
+};
+
+XNumber.prototype.number = function() {
+	return this;
+};
+
+XNumber.prototype.bool = function() {
+	return new XBoolean(this.num);
+};
+
+XNumber.prototype.nodeset = function() {
+	throw new Error("Cannot convert number to nodeset");
+};
+
+XNumber.prototype.stringValue = function() {
+	return this.string().stringValue();
+};
+
+XNumber.prototype.numberValue = function() {
+	return this.num;
+};
+
+XNumber.prototype.booleanValue = function() {
+	return this.bool().booleanValue();
+};
+
+XNumber.prototype.negate = function() {
+	return new XNumber(-this.num);
+};
+
+XNumber.prototype.equals = function(r) {
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.bool().equals(r);
+	}
+	if (Utilities.instance_of(r, XString)) {
+		return this.equals(r.number());
+	}
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this, Operators.equals);
+	}
+	return new XBoolean(this.num == r.num);
+};
+
+XNumber.prototype.notequal = function(r) {
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.bool().notequal(r);
+	}
+	if (Utilities.instance_of(r, XString)) {
+		return this.notequal(r.number());
+	}
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this, Operators.notequal);
+	}
+	return new XBoolean(this.num != r.num);
+};
+
+XNumber.prototype.lessthan = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this, Operators.greaterthanorequal);
+	}
+	if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
+		return this.lessthan(r.number());
+	}
+	return new XBoolean(this.num < r.num);
+};
+
+XNumber.prototype.greaterthan = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this, Operators.lessthanorequal);
+	}
+	if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
+		return this.greaterthan(r.number());
+	}
+	return new XBoolean(this.num > r.num);
+};
+
+XNumber.prototype.lessthanorequal = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this, Operators.greaterthan);
+	}
+	if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
+		return this.lessthanorequal(r.number());
+	}
+	return new XBoolean(this.num <= r.num);
+};
+
+XNumber.prototype.greaterthanorequal = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this, Operators.lessthan);
+	}
+	if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
+		return this.greaterthanorequal(r.number());
+	}
+	return new XBoolean(this.num >= r.num);
+};
+
+XNumber.prototype.plus = function(r) {
+	return new XNumber(this.num + r.num);
+};
+
+XNumber.prototype.minus = function(r) {
+	return new XNumber(this.num - r.num);
+};
+
+XNumber.prototype.multiply = function(r) {
+	return new XNumber(this.num * r.num);
+};
+
+XNumber.prototype.div = function(r) {
+	return new XNumber(this.num / r.num);
+};
+
+XNumber.prototype.mod = function(r) {
+	return new XNumber(this.num % r.num);
+};
+
+// XBoolean //////////////////////////////////////////////////////////////////
+
+XBoolean.prototype = new Expression();
+XBoolean.prototype.constructor = XBoolean;
+XBoolean.superclass = Expression.prototype;
+
+function XBoolean(b) {
+	if (arguments.length > 0) {
+		this.init(b);
+	}
+}
+
+XBoolean.prototype.init = function(b) {
+	this.b = Boolean(b);
+};
+
+XBoolean.prototype.toString = function() {
+	return this.b.toString();
+};
+
+XBoolean.prototype.evaluate = function(c) {
+	return this;
+};
+
+XBoolean.prototype.string = function() {
+	return new XString(this.b);
+};
+
+XBoolean.prototype.number = function() {
+	return new XNumber(this.b);
+};
+
+XBoolean.prototype.bool = function() {
+	return this;
+};
+
+XBoolean.prototype.nodeset = function() {
+	throw new Error("Cannot convert boolean to nodeset");
+};
+
+XBoolean.prototype.stringValue = function() {
+	return this.string().stringValue();
+};
+
+XBoolean.prototype.numberValue = function() {
+	return this.num().numberValue();
+};
+
+XBoolean.prototype.booleanValue = function() {
+	return this.b;
+};
+
+XBoolean.prototype.not = function() {
+	return new XBoolean(!this.b);
+};
+
+XBoolean.prototype.equals = function(r) {
+	if (Utilities.instance_of(r, XString) || Utilities.instance_of(r, XNumber)) {
+		return this.equals(r.bool());
+	}
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithBoolean(this, Operators.equals);
+	}
+	return new XBoolean(this.b == r.b);
+};
+
+XBoolean.prototype.notequal = function(r) {
+	if (Utilities.instance_of(r, XString) || Utilities.instance_of(r, XNumber)) {
+		return this.notequal(r.bool());
+	}
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithBoolean(this, Operators.notequal);
+	}
+	return new XBoolean(this.b != r.b);
+};
+
+XBoolean.prototype.lessthan = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this.number(), Operators.greaterthanorequal);
+	}
+	return this.number().lessthan(r.number());
+};
+
+XBoolean.prototype.greaterthan = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this.number(), Operators.lessthanorequal);
+	}
+	return this.number().greaterthan(r.number());
+};
+
+XBoolean.prototype.lessthanorequal = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this.number(), Operators.greaterthan);
+	}
+	return this.number().lessthanorequal(r.number());
+};
+
+XBoolean.prototype.greaterthanorequal = function(r) {
+	if (Utilities.instance_of(r, XNodeSet)) {
+		return r.compareWithNumber(this.number(), Operators.lessthan);
+	}
+	return this.number().greaterthanorequal(r.number());
+};
+
+// XNodeSet //////////////////////////////////////////////////////////////////
+
+XNodeSet.prototype = new Expression();
+XNodeSet.prototype.constructor = XNodeSet;
+XNodeSet.superclass = Expression.prototype;
+
+function XNodeSet() {
+	this.init();
+}
+
+XNodeSet.prototype.init = function() {
+	this.tree = null;
+	this.size = 0;
+};
+
+XNodeSet.prototype.toString = function() {
+	var p = this.first();
+	if (p == null) {
+		return "";
+	}
+	return this.stringForNode(p);
+};
+
+XNodeSet.prototype.evaluate = function(c) {
+	return this;
+};
+
+XNodeSet.prototype.string = function() {
+	return new XString(this.toString());
+};
+
+XNodeSet.prototype.stringValue = function() {
+	return this.toString();
+};
+
+XNodeSet.prototype.number = function() {
+	return new XNumber(this.string());
+};
+
+XNodeSet.prototype.numberValue = function() {
+	return Number(this.string());
+};
+
+XNodeSet.prototype.bool = function() {
+	return new XBoolean(this.tree != null);
+};
+
+XNodeSet.prototype.booleanValue = function() {
+	return this.tree != null;
+};
+
+XNodeSet.prototype.nodeset = function() {
+	return this;
+};
+
+XNodeSet.prototype.stringForNode = function(n) {
+	if (n.nodeType == 9 /*Node.DOCUMENT_NODE*/) {
+		n = n.documentElement;
+	}
+	if (n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+		return this.stringForNodeRec(n);
+	}
+	if (n.isNamespaceNode) {
+		return n.namespace;
+	}
+	return n.nodeValue;
+};
+
+XNodeSet.prototype.stringForNodeRec = function(n) {
+	var s = "";
+	for (var n2 = n.firstChild; n2 != null; n2 = n2.nextSibling) {
+		if (n2.nodeType == 3 /*Node.TEXT_NODE*/) {
+			s += n2.nodeValue;
+		} else if (n2.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+			s += this.stringForNodeRec(n2);
+		}
+	}
+	return s;
+};
+
+XNodeSet.prototype.first = function() {
+	var p = this.tree;
+	if (p == null) {
+		return null;
+	}
+	while (p.left != null) {
+		p = p.left;
+	}
+	return p.node;
+};
+
+XNodeSet.prototype.add = function(n) {
+	if (this.tree == null) {
+		this.tree = new Object();
+		this.tree.node = n;
+		this.tree.left = null;
+		this.tree.right = null;
+		this.size = 1;
+		return;
+	}
+
+	var p = this.tree;
+	while (1) {
+		var o = this.order(n, p.node);
+		if (o == 0) {
+			return;
+		}
+		if (o > 0) {
+			if (p.right == null) {
+				p.right = new Object();
+				p.right.node = n;
+				p.right.left = null;
+				p.right.right = null;
+				this.size++;
+				return;
+			}
+			p = p.right;
+		} else {
+			if (p.left == null) {
+				p.left = new Object();
+				p.left.node = n;
+				p.left.left = null;
+				p.left.right = null;
+				this.size++;
+				return;
+			}
+			p = p.left;
+		}
+	}
+};
+
+XNodeSet.prototype.addArray = function(ns) {
+	for (var i = 0; i < ns.length; i++) {
+		this.add(ns[i]);
+	}
+};
+
+XNodeSet.prototype.toArray = function() {
+	var a = [];
+	this.toArrayRec(this.tree, a);
+	return a;
+};
+
+XNodeSet.prototype.toArrayRec = function(t, a) {
+	if (t != null) {
+		this.toArrayRec(t.left, a);
+		a.push(t.node);
+		this.toArrayRec(t.right, a);
+	}
+};
+
+XNodeSet.prototype.order = function(n1, n2) {
+	if (n1 == n2) {
+		return 0;
+	}
+	var d1 = 0;
+	var d2 = 0;
+	for (var m1 = n1; m1 != null; m1 = m1.parentNode) {
+		d1++;
+	}
+	for (var m2 = n2; m2 != null; m2 = m2.parentNode) {
+		d2++;
+	}
+	if (d1 > d2) {
+		while (d1 > d2) {
+			n1 = n1.parentNode;
+			d1--;
+		}
+		if (n1 == n2) {
+			return 1;
+		}
+	} else if (d2 > d1) {
+		while (d2 > d1) {
+			n2 = n2.parentNode;
+			d2--;
+		}
+		if (n1 == n2) {
+			return -1;
+		}
+	}
+	while (n1.parentNode != n2.parentNode) {
+		n1 = n1.parentNode;
+		n2 = n2.parentNode;
+	}
+	while (n1.previousSibling != null && n2.previousSibling != null) {
+		n1 = n1.previousSibling;
+		n2 = n2.previousSibling;
+	}
+	if (n1.previousSibling == null) {
+		return -1;
+	}
+	return 1;
+};
+
+XNodeSet.prototype.compareWithString = function(r, o) {
+	var a = this.toArray();
+	for (var i = 0; i < a.length; i++) {
+		var n = a[i];
+		var l = new XString(this.stringForNode(n));
+		var res = o(l, r);
+		if (res.booleanValue()) {
+			return res;
+		}
+	}
+	return new XBoolean(false);
+};
+
+XNodeSet.prototype.compareWithNumber = function(r, o) {
+	var a = this.toArray();
+	for (var i = 0; i < a.length; i++) {
+		var n = a[i];
+		var l = new XNumber(this.stringForNode(n));
+		var res = o(l, r);
+		if (res.booleanValue()) {
+			return res;
+		}
+	}
+	return new XBoolean(false);
+};
+
+XNodeSet.prototype.compareWithBoolean = function(r, o) {
+	return o(this.bool(), r);
+};
+
+XNodeSet.prototype.compareWithNodeSet = function(r, o) {
+	var a = this.toArray();
+	for (var i = 0; i < a.length; i++) {
+		var n = a[i];
+		var l = new XString(this.stringForNode(n));
+		var b = r.toArray();
+		for (var j = 0; j < b.length; j++) {
+			var n2 = b[j];
+			var r = new XString(this.stringForNode(n2));
+			var res = o(l, r);
+			if (res.booleanValue()) {
+				return res;
+			}
+		}
+	}
+	return new XBoolean(false);
+};
+
+XNodeSet.prototype.equals = function(r) {
+	if (Utilities.instance_of(r, XString)) {
+		return this.compareWithString(r, Operators.equals);
+	}
+	if (Utilities.instance_of(r, XNumber)) {
+		return this.compareWithNumber(r, Operators.equals);
+	}
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.compareWithBoolean(r, Operators.equals);
+	}
+	return this.compareWithNodeSet(r, Operators.equals);
+};
+
+XNodeSet.prototype.notequal = function(r) {
+	if (Utilities.instance_of(r, XString)) {
+		return this.compareWithString(r, Operators.notequal);
+	}
+	if (Utilities.instance_of(r, XNumber)) {
+		return this.compareWithNumber(r, Operators.notequal);
+	}
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.compareWithBoolean(r, Operators.notequal);
+	}
+	return this.compareWithNodeSet(r, Operators.notequal);
+};
+
+XNodeSet.prototype.lessthan = function(r) {
+	if (Utilities.instance_of(r, XString)) {
+		return this.compareWithNumber(r.number(), Operators.lessthan);
+	}
+	if (Utilities.instance_of(r, XNumber)) {
+		return this.compareWithNumber(r, Operators.lessthan);
+	}
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.compareWithBoolean(r, Operators.lessthan);
+	}
+	return this.compareWithNodeSet(r, Operators.lessthan);
+};
+
+XNodeSet.prototype.greaterthan = function(r) {
+	if (Utilities.instance_of(r, XString)) {
+		return this.compareWithNumber(r.number(), Operators.greaterthan);
+	}
+	if (Utilities.instance_of(r, XNumber)) {
+		return this.compareWithNumber(r, Operators.greaterthan);
+	}
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.compareWithBoolean(r, Operators.greaterthan);
+	}
+	return this.compareWithNodeSet(r, Operators.greaterthan);
+};
+
+XNodeSet.prototype.lessthanorequal = function(r) {
+	if (Utilities.instance_of(r, XString)) {
+		return this.compareWithNumber(r.number(), Operators.lessthanorequal);
+	}
+	if (Utilities.instance_of(r, XNumber)) {
+		return this.compareWithNumber(r, Operators.lessthanorequal);
+	}
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.compareWithBoolean(r, Operators.lessthanorequal);
+	}
+	return this.compareWithNodeSet(r, Operators.lessthanorequal);
+};
+
+XNodeSet.prototype.greaterthanorequal = function(r) {
+	if (Utilities.instance_of(r, XString)) {
+		return this.compareWithNumber(r.number(), Operators.greaterthanorequal);
+	}
+	if (Utilities.instance_of(r, XNumber)) {
+		return this.compareWithNumber(r, Operators.greaterthanorequal);
+	}
+	if (Utilities.instance_of(r, XBoolean)) {
+		return this.compareWithBoolean(r, Operators.greaterthanorequal);
+	}
+	return this.compareWithNodeSet(r, Operators.greaterthanorequal);
+};
+
+XNodeSet.prototype.union = function(r) {
+	var ns = new XNodeSet();
+	ns.tree = this.tree;
+	ns.size = this.size;
+	ns.addArray(r.toArray());
+	return ns;
+};
+
+// XPathNamespace ////////////////////////////////////////////////////////////
+
+XPathNamespace.prototype = new Object();
+XPathNamespace.prototype.constructor = XPathNamespace;
+XPathNamespace.superclass = Object.prototype;
+
+function XPathNamespace(pre, ns, p) {
+	this.isXPathNamespace = true;
+	this.ownerDocument = p.ownerDocument;
+	this.nodeName = "#namespace";
+	this.prefix = pre;
+	this.localName = pre;
+	this.namespaceURI = ns;
+	this.nodeValue = ns;
+	this.ownerElement = p;
+	this.nodeType = XPathNamespace.XPATH_NAMESPACE_NODE;
+}
+
+XPathNamespace.prototype.toString = function() {
+	return "{ \"" + this.prefix + "\", \"" + this.namespaceURI + "\" }";
+};
+
+// Operators /////////////////////////////////////////////////////////////////
+
+var Operators = new Object();
+
+Operators.equals = function(l, r) {
+	return l.equals(r);
+};
+
+Operators.notequal = function(l, r) {
+	return l.notequal(r);
+};
+
+Operators.lessthan = function(l, r) {
+	return l.lessthan(r);
+};
+
+Operators.greaterthan = function(l, r) {
+	return l.greaterthan(r);
+};
+
+Operators.lessthanorequal = function(l, r) {
+	return l.lessthanorequal(r);
+};
+
+Operators.greaterthanorequal = function(l, r) {
+	return l.greaterthanorequal(r);
+};
+
+// XPathContext //////////////////////////////////////////////////////////////
+
+XPathContext.prototype = new Object();
+XPathContext.prototype.constructor = XPathContext;
+XPathContext.superclass = Object.prototype;
+
+function XPathContext(vr, nr, fr) {
+	this.variableResolver = vr != null ? vr : new VariableResolver();
+	this.namespaceResolver = nr != null ? nr : new NamespaceResolver();
+	this.functionResolver = fr != null ? fr : new FunctionResolver();
+}
+
+// VariableResolver //////////////////////////////////////////////////////////
+
+VariableResolver.prototype = new Object();
+VariableResolver.prototype.constructor = VariableResolver;
+VariableResolver.superclass = Object.prototype;
+
+function VariableResolver() {
+}
+
+VariableResolver.prototype.getVariable = function(vn, c) {
+	var parts = Utilities.splitQName(vn);
+	if (parts[0] != null) {
+		parts[0] = c.namespaceResolver.getNamespace(parts[0], c.expressionContextNode);
+        if (parts[0] == null) {
+            throw new Error("Cannot resolve QName " + fn);
+        }
+	}
+	return this.getVariableWithName(parts[0], parts[1], c.expressionContextNode);
+};
+
+VariableResolver.prototype.getVariableWithName = function(ns, ln, c) {
+	return null;
+};
+
+// FunctionResolver //////////////////////////////////////////////////////////
+
+FunctionResolver.prototype = new Object();
+FunctionResolver.prototype.constructor = FunctionResolver;
+FunctionResolver.superclass = Object.prototype;
+
+function FunctionResolver(thisArg) {
+	this.thisArg = thisArg != null ? thisArg : Functions;
+	this.functions = new Object();
+	this.addStandardFunctions();
+}
+
+FunctionResolver.prototype.addStandardFunctions = function() {
+	this.functions["{}last"] = Functions.last;
+	this.functions["{}position"] = Functions.position;
+	this.functions["{}count"] = Functions.count;
+	this.functions["{}id"] = Functions.id;
+	this.functions["{}local-name"] = Functions.localName;
+	this.functions["{}namespace-uri"] = Functions.namespaceURI;
+	this.functions["{}name"] = Functions.name;
+	this.functions["{}string"] = Functions.string;
+	this.functions["{}concat"] = Functions.concat;
+	this.functions["{}starts-with"] = Functions.startsWith;
+	this.functions["{}contains"] = Functions.contains;
+	this.functions["{}substring-before"] = Functions.substringBefore;
+	this.functions["{}substring-after"] = Functions.substringAfter;
+	this.functions["{}substring"] = Functions.substring;
+	this.functions["{}string-length"] = Functions.stringLength;
+	this.functions["{}normalize-space"] = Functions.normalizeSpace;
+	this.functions["{}translate"] = Functions.translate;
+	this.functions["{}boolean"] = Functions.boolean_;
+	this.functions["{}not"] = Functions.not;
+	this.functions["{}true"] = Functions.true_;
+	this.functions["{}false"] = Functions.false_;
+	this.functions["{}lang"] = Functions.lang;
+	this.functions["{}number"] = Functions.number;
+	this.functions["{}sum"] = Functions.sum;
+	this.functions["{}floor"] = Functions.floor;
+	this.functions["{}ceiling"] = Functions.ceiling;
+	this.functions["{}round"] = Functions.round;
+};
+
+FunctionResolver.prototype.addFunction = function(ns, ln, f) {
+	this.functions["{" + ns + "}" + ln] = f;
+};
+
+FunctionResolver.prototype.getFunction = function(fn, c) {
+	var parts = Utilities.resolveQName(fn, c.namespaceResolver, c.contextNode, false);
+    if (parts[0] == null) {
+        throw new Error("Cannot resolve QName " + fn);
+    }
+	return this.getFunctionWithName(parts[0], parts[1], c.contextNode);
+};
+
+FunctionResolver.prototype.getFunctionWithName = function(ns, ln, c) {
+	return this.functions["{" + ns + "}" + ln];
+};
+
+// NamespaceResolver /////////////////////////////////////////////////////////
+
+NamespaceResolver.prototype = new Object();
+NamespaceResolver.prototype.constructor = NamespaceResolver;
+NamespaceResolver.superclass = Object.prototype;
+
+function NamespaceResolver() {
+}
+
+NamespaceResolver.prototype.getNamespace = function(prefix, n) {
+	if (prefix == "xml") {
+		return XPath.XML_NAMESPACE_URI;
+	} else if (prefix == "xmlns") {
+		return XPath.XMLNS_NAMESPACE_URI;
+	}
+	if (n.nodeType == 9 /*Node.DOCUMENT_NODE*/) {
+		n = n.documentElement;
+	} else if (n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
+		n = PathExpr.prototype.getOwnerElement(n);
+	} else if (n.nodeType != 1 /*Node.ELEMENT_NODE*/) {
+		n = n.parentNode;
+	}
+	while (n != null && n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+		var nnm = n.attributes;
+		for (var i = 0; i < nnm.length; i++) {
+			var a = nnm.item(i);
+			var aname = a.nodeName;
+			if (aname == "xmlns" && prefix == ""
+					|| aname == "xmlns:" + prefix) {
+				return String(a.nodeValue);
+			}
+		}
+		n = n.parentNode;
+	}
+	return null;
+};
+
+// Functions /////////////////////////////////////////////////////////////////
+
+Functions = new Object();
+
+Functions.last = function() {
+	var c = arguments[0];
+	if (arguments.length != 1) {
+		throw new Error("Function last expects ()");
+	}
+	return new XNumber(c.contextSize);
+};
+
+Functions.position = function() {
+	var c = arguments[0];
+	if (arguments.length != 1) {
+		throw new Error("Function position expects ()");
+	}
+	return new XNumber(c.contextPosition);
+};
+
+Functions.count = function() {
+	var c = arguments[0];
+	var ns;
+	if (arguments.length != 2 || !Utilities.instance_of(ns = arguments[1].evaluate(c), XNodeSet)) {
+		throw new Error("Function count expects (node-set)");
+	}
+	return new XNumber(ns.size);
+};
+
+Functions.id = function() {
+	var c = arguments[0];
+	var id;
+	if (arguments.length != 2) {
+		throw new Error("Function id expects (object)");
+	}
+	id = arguments[1].evaluate(c);
+	if (Utilities.instance_of(id, XNodeSet)) {
+		id = id.toArray().join(" ");
+	} else {
+		id = id.stringValue();
+	}
+	var ids = id.split(/[\x0d\x0a\x09\x20]+/);
+	var count = 0;
+	var ns = new XNodeSet();
+	var doc = c.contextNode.nodeType == 9 /*Node.DOCUMENT_NODE*/
+			? c.contextNode
+			: c.contextNode.ownerDocument;
+	for (var i = 0; i < ids.length; i++) {
+		var n;
+		if (doc.getElementById) {
+			n = doc.getElementById(ids[i]);
+		} else {
+			n = Utilities.getElementById(doc, ids[i]);
+		}
+		if (n != null) {
+			ns.add(n);
+			count++;
+		}
+	}
+	return ns;
+};
+
+Functions.localName = function() {
+	var c = arguments[0];
+	var n;
+	if (arguments.length == 1) {
+		n = c.contextNode;
+	} else if (arguments.length == 2) {
+		n = arguments[1].evaluate(c).first();
+	} else {
+		throw new Error("Function local-name expects (node-set?)");
+	}
+	if (n == null) {
+		return new XString("");
+	}
+	return new XString(n.localName ? n.localName : n.baseName);
+};
+
+Functions.namespaceURI = function() {
+	var c = arguments[0];
+	var n;
+	if (arguments.length == 1) {
+		n = c.contextNode;
+	} else if (arguments.length == 2) {
+		n = arguments[1].evaluate(c).first();
+	} else {
+		throw new Error("Function namespace-uri expects (node-set?)");
+	}
+	if (n == null) {
+		return new XString("");
+	}
+	return new XString(n.namespaceURI);
+};
+
+Functions.name = function() {
+	var c = arguments[0];
+	var n;
+	if (arguments.length == 1) {
+		n = c.contextNode;
+	} else if (arguments.length == 2) {
+		n = arguments[1].evaluate(c).first();
+	} else {
+		throw new Error("Function name expects (node-set?)");
+	}
+	if (n == null) {
+		return new XString("");
+	}
+	if (n.nodeType == 1 /*Node.ELEMENT_NODE*/ || n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
+		return new XString(n.nodeName);
+	} else if (n.localName == null) {
+		return new XString("");
+	} else {
+		return new XString(n.localName);
+	}
+};
+
+Functions.string = function() {
+	var c = arguments[0];
+	if (arguments.length == 1) {
+		return XNodeSet.prototype.stringForNode(c.contextNode);
+	} else if (arguments.length == 2) {
+		return arguments[1].evaluate(c).string();
+	}
+	throw new Error("Function string expects (object?)");
+};
+
+Functions.concat = function() {
+	var c = arguments[0];
+	if (arguments.length < 3) {
+		throw new Error("Function concat expects (string, string, string*)");
+	}
+	var s = "";
+	for (var i = 1; i < arguments.length; i++) {
+		s += arguments[i].evaluate(c).stringValue();
+	}
+	return new XString(s);
+};
+
+Functions.startsWith = function() {
+	var c = arguments[0];
+	if (arguments.length != 3) {
+		throw new Error("Function startsWith expects (string, string)");
+	}
+	var s1 = arguments[1].evaluate(c).stringValue();
+	var s2 = arguments[2].evaluate(c).stringValue();
+	return new XBoolean(s1.substring(0, s2.length) == s2);
+};
+
+Functions.contains = function() {
+	var c = arguments[0];
+	if (arguments.length != 3) {
+		throw new Error("Function contains expects (string, string)");
+	}
+	var s1 = arguments[1].evaluate(c).stringValue();
+	var s2 = arguments[2].evaluate(c).stringValue();
+	return new XBoolean(s1.indexOf(s2) != -1);
+};
+
+Functions.substringBefore = function() {
+	var c = arguments[0];
+	if (arguments.length != 3) {
+		throw new Error("Function substring-before expects (string, string)");
+	}
+	var s1 = arguments[1].evaluate(c).stringValue();
+	var s2 = arguments[2].evaluate(c).stringValue();
+	return new XString(s1.substring(0, s1.indexOf(s2)));
+};
+
+Functions.substringAfter = function() {
+	var c = arguments[0];
+	if (arguments.length != 3) {
+		throw new Error("Function substring-after expects (string, string)");
+	}
+	var s1 = arguments[1].evaluate(c).stringValue();
+	var s2 = arguments[2].evaluate(c).stringValue();
+	if (s2.length == 0) {
+		return new XString(s1);
+	}
+	var i = s1.indexOf(s2);
+	if (i == -1) {
+		return new XString("");
+	}
+	return new XString(s1.substring(s1.indexOf(s2) + 1));
+};
+
+Functions.substring = function() {
+	var c = arguments[0];
+	if (!(arguments.length == 3 || arguments.length == 4)) {
+		throw new Error("Function substring expects (string, number, number?)");
+	}
+	var s = arguments[1].evaluate(c).stringValue();
+	var n1 = Math.round(arguments[2].evaluate(c).numberValue()) - 1;
+	var n2 = arguments.length == 4 ? n1 + Math.round(arguments[3].evaluate(c).numberValue()) : undefined;
+	return new XString(s.substring(n1, n2));
+};
+
+Functions.stringLength = function() {
+	var c = arguments[0];
+	var s;
+	if (arguments.length == 1) {
+		s = XNodeSet.prototype.stringForNode(c.contextNode);
+	} else if (arguments.length == 2) {
+		s = arguments[1].evaluate(c).stringValue();
+	} else {
+		throw new Error("Function string-length expects (string?)");
+	}
+	return new XNumber(s.length);
+};
+
+Functions.normalizeSpace = function() {
+	var c = arguments[0];
+	var s;
+	if (arguments.length == 1) {
+		s = XNodeSet.prototype.stringForNode(c.contextNode);
+	} else if (arguments.length == 2) {
+		s = arguments[1].evaluate(c).stringValue();
+	} else {
+		throw new Error("Function normalize-space expects (string?)");
+	}
+	var i = 0;
+	var j = s.length - 1;
+	while (Utilities.isSpace(s.charCodeAt(j))) {
+		j--;
+	}
+	var t = "";
+	while (i <= j && Utilities.isSpace(s.charCodeAt(i))) {
+		i++;
+	}
+	while (i <= j) {
+		if (Utilities.isSpace(s.charCodeAt(i))) {
+			t += " ";
+			while (i <= j && Utilities.isSpace(s.charCodeAt(i))) {
+				i++;
+			}
+		} else {
+			t += s.charAt(i);
+			i++;
+		}
+	}
+	return new XString(t);
+};
+
+Functions.translate = function() {
+	var c = arguments[0];
+	if (arguments.length != 4) {
+		throw new Error("Function translate expects (string, string, string)");
+	}
+	var s1 = arguments[1].evaluate(c).stringValue();
+	var s2 = arguments[2].evaluate(c).stringValue();
+	var s3 = arguments[3].evaluate(c).stringValue();
+	var map = [];
+	for (var i = 0; i < s2.length; i++) {
+		var j = s2.charCodeAt(i);
+		if (map[j] == undefined) {
+			var k = i > s3.length ? "" : s3.charAt(i);
+			map[j] = k;
+		}
+	}
+	var t = "";
+	for (var i = 0; i < s1.length; i++) {
+		var c = s1.charCodeAt(i);
+		var r = map[c];
+		if (r == undefined) {
+			t += s1.charAt(i);
+		} else {
+			t += r;
+		}
+	}
+	return new XString(t);
+};
+
+Functions.boolean_ = function() {
+	var c = arguments[0];
+	if (arguments.length != 2) {
+		throw new Error("Function boolean expects (object)");
+	}
+	return arguments[1].evaluate(c).bool();
+};
+
+Functions.not = function() {
+	var c = arguments[0];
+	if (arguments.length != 2) {
+		throw new Error("Function not expects (object)");
+	}
+	return arguments[1].evaluate(c).bool().not();
+};
+
+Functions.true_ = function() {
+	if (arguments.length != 1) {
+		throw new Error("Function true expects ()");
+	}
+	return new XBoolean(true);
+};
+
+Functions.false_ = function() {
+	if (arguments.length != 1) {
+		throw new Error("Function false expects ()");
+	}
+	return new XBoolean(false);
+};
+
+Functions.lang = function() {
+	var c = arguments[0];
+	if (arguments.length != 2) {
+		throw new Error("Function lang expects (string)");
+	}
+	var lang;
+	for (var n = c.contextNode; n != null && n.nodeType != 9 /*Node.DOCUMENT_NODE*/; n = n.parentNode) {
+		var a = n.getAttributeNS(XPath.XML_NAMESPACE_URI, "lang");
+		if (a != null) {
+			lang = String(a);
+			break;
+		}
+	}
+	if (lang == null) {
+		return new XBoolean(false);
+	}
+	var s = arguments[1].evaluate(c).stringValue();
+	return new XBoolean(lang.substring(0, s.length) == s
+				&& (lang.length == s.length || lang.charAt(s.length) == '-'));
+};
+
+Functions.number = function() {
+	var c = arguments[0];
+	if (!(arguments.length == 1 || arguments.length == 2)) {
+		throw new Error("Function number expects (object?)");
+	}
+	if (arguments.length == 1) {
+		return new XNumber(XNodeSet.prototype.stringForNode(c.contextNode));
+	}
+	return arguments[1].evaluate(c).number();
+};
+
+Functions.sum = function() {
+	var c = arguments[0];
+	var ns;
+	if (arguments.length != 2 || !Utilities.instance_of((ns = arguments[1].evaluate(c)), XNodeSet)) {
+		throw new Error("Function sum expects (node-set)");
+	}
+	ns = ns.toArray();
+	var n = 0;
+	for (var i = 0; i < ns.length; i++) {
+		n += new XNumber(XNodeSet.prototype.stringForNode(ns[i])).numberValue();
+	}
+	return new XNumber(n);
+};
+
+Functions.floor = function() {
+	var c = arguments[0];
+	if (arguments.length != 2) {
+		throw new Error("Function floor expects (number)");
+	}
+	return new XNumber(Math.floor(arguments[1].evaluate(c).numberValue()));
+};
+
+Functions.ceiling = function() {
+	var c = arguments[0];
+	if (arguments.length != 2) {
+		throw new Error("Function ceiling expects (number)");
+	}
+	return new XNumber(Math.ceil(arguments[1].evaluate(c).numberValue()));
+};
+
+Functions.round = function() {
+	var c = arguments[0];
+	if (arguments.length != 2) {
+		throw new Error("Function round expects (number)");
+	}
+	return new XNumber(Math.round(arguments[1].evaluate(c).numberValue()));
+};
+
+// Utilities /////////////////////////////////////////////////////////////////
+
+Utilities = new Object();
+
+Utilities.splitQName = function(qn) {
+	var i = qn.indexOf(":");
+	if (i == -1) {
+		return [ null, qn ];
+	}
+	return [ qn.substring(0, i), qn.substring(i + 1) ];
+};
+
+Utilities.resolveQName = function(qn, nr, n, useDefault) {
+	var parts = Utilities.splitQName(qn);
+	if (parts[0] != null) {
+		parts[0] = nr.getNamespace(parts[0], n);
+	} else {
+		if (useDefault) {
+			parts[0] = nr.getNamespace("", n);
+			if (parts[0] == null) {
+				parts[0] = "";
+			}
+		} else {
+			parts[0] = "";
+		}
+	}
+	return parts;
+};
+
+Utilities.isSpace = function(c) {
+	return c == 0x9 || c == 0xd || c == 0xa || c == 0x20;
+};
+
+Utilities.isLetter = function(c) {
+	return c >= 0x0041 && c <= 0x005A ||
+		c >= 0x0061 && c <= 0x007A ||
+		c >= 0x00C0 && c <= 0x00D6 ||
+		c >= 0x00D8 && c <= 0x00F6 ||
+		c >= 0x00F8 && c <= 0x00FF ||
+		c >= 0x0100 && c <= 0x0131 ||
+		c >= 0x0134 && c <= 0x013E ||
+		c >= 0x0141 && c <= 0x0148 ||
+		c >= 0x014A && c <= 0x017E ||
+		c >= 0x0180 && c <= 0x01C3 ||
+		c >= 0x01CD && c <= 0x01F0 ||
+		c >= 0x01F4 && c <= 0x01F5 ||
+		c >= 0x01FA && c <= 0x0217 ||
+		c >= 0x0250 && c <= 0x02A8 ||
+		c >= 0x02BB && c <= 0x02C1 ||
+		c == 0x0386 ||
+		c >= 0x0388 && c <= 0x038A ||
+		c == 0x038C ||
+		c >= 0x038E && c <= 0x03A1 ||
+		c >= 0x03A3 && c <= 0x03CE ||
+		c >= 0x03D0 && c <= 0x03D6 ||
+		c == 0x03DA ||
+		c == 0x03DC ||
+		c == 0x03DE ||
+		c == 0x03E0 ||
+		c >= 0x03E2 && c <= 0x03F3 ||
+		c >= 0x0401 && c <= 0x040C ||
+		c >= 0x040E && c <= 0x044F ||
+		c >= 0x0451 && c <= 0x045C ||
+		c >= 0x045E && c <= 0x0481 ||
+		c >= 0x0490 && c <= 0x04C4 ||
+		c >= 0x04C7 && c <= 0x04C8 ||
+		c >= 0x04CB && c <= 0x04CC ||
+		c >= 0x04D0 && c <= 0x04EB ||
+		c >= 0x04EE && c <= 0x04F5 ||
+		c >= 0x04F8 && c <= 0x04F9 ||
+		c >= 0x0531 && c <= 0x0556 ||
+		c == 0x0559 ||
+		c >= 0x0561 && c <= 0x0586 ||
+		c >= 0x05D0 && c <= 0x05EA ||
+		c >= 0x05F0 && c <= 0x05F2 ||
+		c >= 0x0621 && c <= 0x063A ||
+		c >= 0x0641 && c <= 0x064A ||
+		c >= 0x0671 && c <= 0x06B7 ||
+		c >= 0x06BA && c <= 0x06BE ||
+		c >= 0x06C0 && c <= 0x06CE ||
+		c >= 0x06D0 && c <= 0x06D3 ||
+		c == 0x06D5 ||
+		c >= 0x06E5 && c <= 0x06E6 ||
+		c >= 0x0905 && c <= 0x0939 ||
+		c == 0x093D ||
+		c >= 0x0958 && c <= 0x0961 ||
+		c >= 0x0985 && c <= 0x098C ||
+		c >= 0x098F && c <= 0x0990 ||
+		c >= 0x0993 && c <= 0x09A8 ||
+		c >= 0x09AA && c <= 0x09B0 ||
+		c == 0x09B2 ||
+		c >= 0x09B6 && c <= 0x09B9 ||
+		c >= 0x09DC && c <= 0x09DD ||
+		c >= 0x09DF && c <= 0x09E1 ||
+		c >= 0x09F0 && c <= 0x09F1 ||
+		c >= 0x0A05 && c <= 0x0A0A ||
+		c >= 0x0A0F && c <= 0x0A10 ||
+		c >= 0x0A13 && c <= 0x0A28 ||
+		c >= 0x0A2A && c <= 0x0A30 ||
+		c >= 0x0A32 && c <= 0x0A33 ||
+		c >= 0x0A35 && c <= 0x0A36 ||
+		c >= 0x0A38 && c <= 0x0A39 ||
+		c >= 0x0A59 && c <= 0x0A5C ||
+		c == 0x0A5E ||
+		c >= 0x0A72 && c <= 0x0A74 ||
+		c >= 0x0A85 && c <= 0x0A8B ||
+		c == 0x0A8D ||
+		c >= 0x0A8F && c <= 0x0A91 ||
+		c >= 0x0A93 && c <= 0x0AA8 ||
+		c >= 0x0AAA && c <= 0x0AB0 ||
+		c >= 0x0AB2 && c <= 0x0AB3 ||
+		c >= 0x0AB5 && c <= 0x0AB9 ||
+		c == 0x0ABD ||
+		c == 0x0AE0 ||
+		c >= 0x0B05 && c <= 0x0B0C ||
+		c >= 0x0B0F && c <= 0x0B10 ||
+		c >= 0x0B13 && c <= 0x0B28 ||
+		c >= 0x0B2A && c <= 0x0B30 ||
+		c >= 0x0B32 && c <= 0x0B33 ||
+		c >= 0x0B36 && c <= 0x0B39 ||
+		c == 0x0B3D ||
+		c >= 0x0B5C && c <= 0x0B5D ||
+		c >= 0x0B5F && c <= 0x0B61 ||
+		c >= 0x0B85 && c <= 0x0B8A ||
+		c >= 0x0B8E && c <= 0x0B90 ||
+		c >= 0x0B92 && c <= 0x0B95 ||
+		c >= 0x0B99 && c <= 0x0B9A ||
+		c == 0x0B9C ||
+		c >= 0x0B9E && c <= 0x0B9F ||
+		c >= 0x0BA3 && c <= 0x0BA4 ||
+		c >= 0x0BA8 && c <= 0x0BAA ||
+		c >= 0x0BAE && c <= 0x0BB5 ||
+		c >= 0x0BB7 && c <= 0x0BB9 ||
+		c >= 0x0C05 && c <= 0x0C0C ||
+		c >= 0x0C0E && c <= 0x0C10 ||
+		c >= 0x0C12 && c <= 0x0C28 ||
+		c >= 0x0C2A && c <= 0x0C33 ||
+		c >= 0x0C35 && c <= 0x0C39 ||
+		c >= 0x0C60 && c <= 0x0C61 ||
+		c >= 0x0C85 && c <= 0x0C8C ||
+		c >= 0x0C8E && c <= 0x0C90 ||
+		c >= 0x0C92 && c <= 0x0CA8 ||
+		c >= 0x0CAA && c <= 0x0CB3 ||
+		c >= 0x0CB5 && c <= 0x0CB9 ||
+		c == 0x0CDE ||
+		c >= 0x0CE0 && c <= 0x0CE1 ||
+		c >= 0x0D05 && c <= 0x0D0C ||
+		c >= 0x0D0E && c <= 0x0D10 ||
+		c >= 0x0D12 && c <= 0x0D28 ||
+		c >= 0x0D2A && c <= 0x0D39 ||
+		c >= 0x0D60 && c <= 0x0D61 ||
+		c >= 0x0E01 && c <= 0x0E2E ||
+		c == 0x0E30 ||
+		c >= 0x0E32 && c <= 0x0E33 ||
+		c >= 0x0E40 && c <= 0x0E45 ||
+		c >= 0x0E81 && c <= 0x0E82 ||
+		c == 0x0E84 ||
+		c >= 0x0E87 && c <= 0x0E88 ||
+		c == 0x0E8A ||
+		c == 0x0E8D ||
+		c >= 0x0E94 && c <= 0x0E97 ||
+		c >= 0x0E99 && c <= 0x0E9F ||
+		c >= 0x0EA1 && c <= 0x0EA3 ||
+		c == 0x0EA5 ||
+		c == 0x0EA7 ||
+		c >= 0x0EAA && c <= 0x0EAB ||
+		c >= 0x0EAD && c <= 0x0EAE ||
+		c == 0x0EB0 ||
+		c >= 0x0EB2 && c <= 0x0EB3 ||
+		c == 0x0EBD ||
+		c >= 0x0EC0 && c <= 0x0EC4 ||
+		c >= 0x0F40 && c <= 0x0F47 ||
+		c >= 0x0F49 && c <= 0x0F69 ||
+		c >= 0x10A0 && c <= 0x10C5 ||
+		c >= 0x10D0 && c <= 0x10F6 ||
+		c == 0x1100 ||
+		c >= 0x1102 && c <= 0x1103 ||
+		c >= 0x1105 && c <= 0x1107 ||
+		c == 0x1109 ||
+		c >= 0x110B && c <= 0x110C ||
+		c >= 0x110E && c <= 0x1112 ||
+		c == 0x113C ||
+		c == 0x113E ||
+		c == 0x1140 ||
+		c == 0x114C ||
+		c == 0x114E ||
+		c == 0x1150 ||
+		c >= 0x1154 && c <= 0x1155 ||
+		c == 0x1159 ||
+		c >= 0x115F && c <= 0x1161 ||
+		c == 0x1163 ||
+		c == 0x1165 ||
+		c == 0x1167 ||
+		c == 0x1169 ||
+		c >= 0x116D && c <= 0x116E ||
+		c >= 0x1172 && c <= 0x1173 ||
+		c == 0x1175 ||
+		c == 0x119E ||
+		c == 0x11A8 ||
+		c == 0x11AB ||
+		c >= 0x11AE && c <= 0x11AF ||
+		c >= 0x11B7 && c <= 0x11B8 ||
+		c == 0x11BA ||
+		c >= 0x11BC && c <= 0x11C2 ||
+		c == 0x11EB ||
+		c == 0x11F0 ||
+		c == 0x11F9 ||
+		c >= 0x1E00 && c <= 0x1E9B ||
+		c >= 0x1EA0 && c <= 0x1EF9 ||
+		c >= 0x1F00 && c <= 0x1F15 ||
+		c >= 0x1F18 && c <= 0x1F1D ||
+		c >= 0x1F20 && c <= 0x1F45 ||
+		c >= 0x1F48 && c <= 0x1F4D ||
+		c >= 0x1F50 && c <= 0x1F57 ||
+		c == 0x1F59 ||
+		c == 0x1F5B ||
+		c == 0x1F5D ||
+		c >= 0x1F5F && c <= 0x1F7D ||
+		c >= 0x1F80 && c <= 0x1FB4 ||
+		c >= 0x1FB6 && c <= 0x1FBC ||
+		c == 0x1FBE ||
+		c >= 0x1FC2 && c <= 0x1FC4 ||
+		c >= 0x1FC6 && c <= 0x1FCC ||
+		c >= 0x1FD0 && c <= 0x1FD3 ||
+		c >= 0x1FD6 && c <= 0x1FDB ||
+		c >= 0x1FE0 && c <= 0x1FEC ||
+		c >= 0x1FF2 && c <= 0x1FF4 ||
+		c >= 0x1FF6 && c <= 0x1FFC ||
+		c == 0x2126 ||
+		c >= 0x212A && c <= 0x212B ||
+		c == 0x212E ||
+		c >= 0x2180 && c <= 0x2182 ||
+		c >= 0x3041 && c <= 0x3094 ||
+		c >= 0x30A1 && c <= 0x30FA ||
+		c >= 0x3105 && c <= 0x312C ||
+		c >= 0xAC00 && c <= 0xD7A3 ||
+		c >= 0x4E00 && c <= 0x9FA5 ||
+		c == 0x3007 ||
+		c >= 0x3021 && c <= 0x3029;
+};
+
+Utilities.isNCNameChar = function(c) {
+	return c >= 0x0030 && c <= 0x0039 
+		|| c >= 0x0660 && c <= 0x0669 
+		|| c >= 0x06F0 && c <= 0x06F9 
+		|| c >= 0x0966 && c <= 0x096F 
+		|| c >= 0x09E6 && c <= 0x09EF 
+		|| c >= 0x0A66 && c <= 0x0A6F 
+		|| c >= 0x0AE6 && c <= 0x0AEF 
+		|| c >= 0x0B66 && c <= 0x0B6F 
+		|| c >= 0x0BE7 && c <= 0x0BEF 
+		|| c >= 0x0C66 && c <= 0x0C6F 
+		|| c >= 0x0CE6 && c <= 0x0CEF 
+		|| c >= 0x0D66 && c <= 0x0D6F 
+		|| c >= 0x0E50 && c <= 0x0E59 
+		|| c >= 0x0ED0 && c <= 0x0ED9 
+		|| c >= 0x0F20 && c <= 0x0F29
+		|| c == 0x002E
+		|| c == 0x002D
+		|| c == 0x005F
+		|| Utilities.isLetter(c)
+		|| c >= 0x0300 && c <= 0x0345 
+		|| c >= 0x0360 && c <= 0x0361 
+		|| c >= 0x0483 && c <= 0x0486 
+		|| c >= 0x0591 && c <= 0x05A1 
+		|| c >= 0x05A3 && c <= 0x05B9 
+		|| c >= 0x05BB && c <= 0x05BD 
+		|| c == 0x05BF 
+		|| c >= 0x05C1 && c <= 0x05C2 
+		|| c == 0x05C4 
+		|| c >= 0x064B && c <= 0x0652 
+		|| c == 0x0670 
+		|| c >= 0x06D6 && c <= 0x06DC 
+		|| c >= 0x06DD && c <= 0x06DF 
+		|| c >= 0x06E0 && c <= 0x06E4 
+		|| c >= 0x06E7 && c <= 0x06E8 
+		|| c >= 0x06EA && c <= 0x06ED 
+		|| c >= 0x0901 && c <= 0x0903 
+		|| c == 0x093C 
+		|| c >= 0x093E && c <= 0x094C 
+		|| c == 0x094D 
+		|| c >= 0x0951 && c <= 0x0954 
+		|| c >= 0x0962 && c <= 0x0963 
+		|| c >= 0x0981 && c <= 0x0983 
+		|| c == 0x09BC 
+		|| c == 0x09BE 
+		|| c == 0x09BF 
+		|| c >= 0x09C0 && c <= 0x09C4 
+		|| c >= 0x09C7 && c <= 0x09C8 
+		|| c >= 0x09CB && c <= 0x09CD 
+		|| c == 0x09D7 
+		|| c >= 0x09E2 && c <= 0x09E3 
+		|| c == 0x0A02 
+		|| c == 0x0A3C 
+		|| c == 0x0A3E 
+		|| c == 0x0A3F 
+		|| c >= 0x0A40 && c <= 0x0A42 
+		|| c >= 0x0A47 && c <= 0x0A48 
+		|| c >= 0x0A4B && c <= 0x0A4D 
+		|| c >= 0x0A70 && c <= 0x0A71 
+		|| c >= 0x0A81 && c <= 0x0A83 
+		|| c == 0x0ABC 
+		|| c >= 0x0ABE && c <= 0x0AC5 
+		|| c >= 0x0AC7 && c <= 0x0AC9 
+		|| c >= 0x0ACB && c <= 0x0ACD 
+		|| c >= 0x0B01 && c <= 0x0B03 
+		|| c == 0x0B3C 
+		|| c >= 0x0B3E && c <= 0x0B43 
+		|| c >= 0x0B47 && c <= 0x0B48 
+		|| c >= 0x0B4B && c <= 0x0B4D 
+		|| c >= 0x0B56 && c <= 0x0B57 
+		|| c >= 0x0B82 && c <= 0x0B83 
+		|| c >= 0x0BBE && c <= 0x0BC2 
+		|| c >= 0x0BC6 && c <= 0x0BC8 
+		|| c >= 0x0BCA && c <= 0x0BCD 
+		|| c == 0x0BD7 
+		|| c >= 0x0C01 && c <= 0x0C03 
+		|| c >= 0x0C3E && c <= 0x0C44 
+		|| c >= 0x0C46 && c <= 0x0C48 
+		|| c >= 0x0C4A && c <= 0x0C4D 
+		|| c >= 0x0C55 && c <= 0x0C56 
+		|| c >= 0x0C82 && c <= 0x0C83 
+		|| c >= 0x0CBE && c <= 0x0CC4 
+		|| c >= 0x0CC6 && c <= 0x0CC8 
+		|| c >= 0x0CCA && c <= 0x0CCD 
+		|| c >= 0x0CD5 && c <= 0x0CD6 
+		|| c >= 0x0D02 && c <= 0x0D03 
+		|| c >= 0x0D3E && c <= 0x0D43 
+		|| c >= 0x0D46 && c <= 0x0D48 
+		|| c >= 0x0D4A && c <= 0x0D4D 
+		|| c == 0x0D57 
+		|| c == 0x0E31 
+		|| c >= 0x0E34 && c <= 0x0E3A 
+		|| c >= 0x0E47 && c <= 0x0E4E 
+		|| c == 0x0EB1 
+		|| c >= 0x0EB4 && c <= 0x0EB9 
+		|| c >= 0x0EBB && c <= 0x0EBC 
+		|| c >= 0x0EC8 && c <= 0x0ECD 
+		|| c >= 0x0F18 && c <= 0x0F19 
+		|| c == 0x0F35 
+		|| c == 0x0F37 
+		|| c == 0x0F39 
+		|| c == 0x0F3E 
+		|| c == 0x0F3F 
+		|| c >= 0x0F71 && c <= 0x0F84 
+		|| c >= 0x0F86 && c <= 0x0F8B 
+		|| c >= 0x0F90 && c <= 0x0F95 
+		|| c == 0x0F97 
+		|| c >= 0x0F99 && c <= 0x0FAD 
+		|| c >= 0x0FB1 && c <= 0x0FB7 
+		|| c == 0x0FB9 
+		|| c >= 0x20D0 && c <= 0x20DC 
+		|| c == 0x20E1 
+		|| c >= 0x302A && c <= 0x302F 
+		|| c == 0x3099 
+		|| c == 0x309A
+		|| c == 0x00B7 
+		|| c == 0x02D0 
+		|| c == 0x02D1 
+		|| c == 0x0387 
+		|| c == 0x0640 
+		|| c == 0x0E46 
+		|| c == 0x0EC6 
+		|| c == 0x3005 
+		|| c >= 0x3031 && c <= 0x3035 
+		|| c >= 0x309D && c <= 0x309E 
+		|| c >= 0x30FC && c <= 0x30FE;
+};
+
+Utilities.coalesceText = function(n) {
+	for (var m = n.firstChild; m != null; m = m.nextSibling) {
+		if (m.nodeType == 3 /*Node.TEXT_NODE*/ || m.nodeType == 4 /*Node.CDATA_SECTION_NODE*/) {
+			var s = m.nodeValue;
+			var first = m;
+			m = m.nextSibling;
+			while (m != null && (m.nodeType == 3 /*Node.TEXT_NODE*/ || m.nodeType == 4 /*Node.CDATA_SECTION_NODE*/)) {
+				s += m.nodeValue;
+				var del = m;
+				m = m.nextSibling;
+				del.parentNode.removeChild(del);
+			}
+			if (first.nodeType == 4 /*Node.CDATA_SECTION_NODE*/) {
+				var p = first.parentNode;
+				if (first.nextSibling == null) {
+					p.removeChild(first);
+					p.appendChild(p.ownerDocument.createTextNode(s));
+				} else {
+					var next = first.nextSibling;
+					p.removeChild(first);
+					p.insertBefore(p.ownerDocument.createTextNode(s), next);
+				}
+			} else {
+				first.nodeValue = s;
+			}
+			if (m == null) {
+				break;
+			}
+		} else if (m.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+			Utilities.coalesceText(m);
+		}
+	}
+};
+
+Utilities.instance_of = function(o, c) {
+	while (o != null) {
+		if (o.constructor === c) {
+			return true;
+		}
+		if (o === Object) {
+			return false;
+		}
+		o = o.constructor.superclass;
+	}
+	return false;
+};
+
+Utilities.getElementById = function(n, id) {
+	// Note that this does not check the DTD to check for actual
+	// attributes of type ID, so this may be a bit wrong.
+	if (n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
+		if (n.getAttribute("id") == id
+				|| n.getAttributeNS(null, "id") == id) {
+			return n;
+		}
+	}
+	for (var m = n.firstChild; m != null; m = m.nextSibling) {
+		var res = Utilities.getElementById(m, id);
+		if (res != null) {
+			return res;
+		}
+	}
+	return null;
+};
+
+// XPathException ////////////////////////////////////////////////////////////
+
+XPathException.prototype = {};
+XPathException.prototype.constructor = XPathException;
+XPathException.superclass = Object.prototype;
+
+function XPathException(c, e) {
+	this.code = c;
+	this.exception = e;
+}
+
+XPathException.prototype.toString = function() {
+	var msg = this.exception ? ": " + this.exception.toString() : "";
+	switch (this.code) {
+		case XPathException.INVALID_EXPRESSION_ERR:
+			return "Invalid expression" + msg;
+		case XPathException.TYPE_ERR:
+			return "Type error" + msg;
+	}
+};
+
+XPathException.INVALID_EXPRESSION_ERR = 51;
+XPathException.TYPE_ERR = 52;
+
+// XPathExpression ///////////////////////////////////////////////////////////
+
+XPathExpression.prototype = {};
+XPathExpression.prototype.constructor = XPathExpression;
+XPathExpression.superclass = Object.prototype;
+
+function XPathExpression(e, r, p) {
+	this.xpath = p.parse(e);
+	this.context = new XPathContext();
+	this.context.namespaceResolver = new XPathNSResolverWrapper(r);
+}
+
+XPathExpression.prototype.evaluate = function(n, t, res) {
+	this.context.expressionContextNode = n;
+	var result = this.xpath.evaluate(this.context);
+	return new XPathResult(result, t);
+}
+
+// XPathNSResolverWrapper ////////////////////////////////////////////////////
+
+XPathNSResolverWrapper.prototype = {};
+XPathNSResolverWrapper.prototype.constructor = XPathNSResolverWrapper;
+XPathNSResolverWrapper.superclass = Object.prototype;
+
+function XPathNSResolverWrapper(r) {
+	this.xpathNSResolver = r;
+}
+
+XPathNSResolverWrapper.prototype.getNamespace = function(prefix, n) {
+    if (this.xpathNSResolver == null) {
+        return null;
+    }
+	return this.xpathNSResolver.lookupNamespaceURI(prefix);
+};
+
+// NodeXPathNSResolver ///////////////////////////////////////////////////////
+
+NodeXPathNSResolver.prototype = {};
+NodeXPathNSResolver.prototype.constructor = NodeXPathNSResolver;
+NodeXPathNSResolver.superclass = Object.prototype;
+
+function NodeXPathNSResolver(n) {
+	this.node = n;
+	this.namespaceResolver = new NamespaceResolver();
+}
+
+NodeXPathNSResolver.prototype.lookupNamespaceURI = function(prefix) {
+	return this.namespaceResolver.getNamespace(prefix, this.node);
+};
+
+// XPathResult ///////////////////////////////////////////////////////////////
+
+XPathResult.prototype = {};
+XPathResult.prototype.constructor = XPathResult;
+XPathResult.superclass = Object.prototype;
+
+function XPathResult(v, t) {
+	if (t == XPathResult.ANY_TYPE) {
+		if (v.constructor === XString) {
+			t = XPathResult.STRING_TYPE;
+		} else if (v.constructor === XNumber) {
+			t = XPathResult.NUMBER_TYPE;
+		} else if (v.constructor === XBoolean) {
+			t = XPathResult.BOOLEAN_TYPE;
+		} else if (v.constructor === XNodeSet) {
+			t = XPathResult.UNORDERED_NODE_ITERATOR_TYPE;
+		}
+	}
+	this.resultType = t;
+	switch (t) {
+		case XPathResult.NUMBER_TYPE:
+			this.numberValue = v.numberValue();
+			return;
+		case XPathResult.STRING_TYPE:
+			this.stringValue = v.stringValue();
+			return;
+		case XPathResult.BOOLEAN_TYPE:
+			this.booleanValue = v.booleanValue();
+			return;
+		case XPathResult.ANY_UNORDERED_NODE_TYPE:
+		case XPathResult.FIRST_UNORDERED_NODE_TYPE:
+			if (v.constructor === XNodeSet) {
+				this.singleNodeValue = v.first();
+				return;
+			}
+			break;
+		case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
+		case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
+			if (v.constructor === XNodeSet) {
+				this.invalidIteratorState = false;
+				this.nodes = v.toArray();
+				this.iteratorIndex = 0;
+				return;
+			}
+			break;
+		case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
+		case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
+			if (v.constructor === XNodeSet) {
+				this.nodes = v.toArray();
+				this.snapshotLength = this.nodes.length;
+				return;
+			}
+			break;
+	}
+	throw new XPathException(XPathException.TYPE_ERR);
+};
+
+XPathResult.prototype.iterateNext = function() {
+	if (this.resultType != XPathResult.UNORDERED_NODE_ITERATOR_TYPE
+			&& this.resultType != XPathResult.ORDERED_NODE_ITERATOR_TYPE) {
+		throw new XPathException(XPathException.TYPE_ERR);
+	}
+	return this.nodes[this.iteratorIndex++];
+};
+
+XPathResult.prototype.snapshotItem = function(i) {
+	if (this.resultType != XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE
+			&& this.resultType != XPathResult.ORDERED_NODE_SNAPSHOT_TYPE) {
+		throw new XPathException(XPathException.TYPE_ERR);
+	}
+	return this.nodes[i];
+};
+
+XPathResult.ANY_TYPE = 0;
+XPathResult.NUMBER_TYPE = 1;
+XPathResult.STRING_TYPE = 2;
+XPathResult.BOOLEAN_TYPE = 3;
+XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4;
+XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5;
+XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE = 6;
+XPathResult.ORDERED_NODE_SNAPSHOT_TYPE = 7;
+XPathResult.ANY_UNORDERED_NODE_TYPE = 8;
+XPathResult.FIRST_ORDERED_NODE_TYPE = 9;
+
+// DOM 3 XPath support ///////////////////////////////////////////////////////
+
+function installDOM3XPathSupport(doc, p) {
+	doc.createExpression = function(e, r) {
+		try {
+			return new XPathExpression(e, r, p);
+		} catch (e) {
+			throw new XPathException(XPathException.INVALID_EXPRESSION_ERR, e);
+		}
+	};
+	doc.createNSResolver = function(n) {
+		return new NodeXPathNSResolver(n);
+	};
+	doc.evaluate = function(e, cn, r, t, res) {
+		if (t < 0 || t > 9) {
+			throw { code: 0, toString: function() { return "Request type not supported"; } };
+		}
+        return doc.createExpression(e, r, p).evaluate(cn, t, res);
+	};
+};
+
+// ---------------------------------------------------------------------------
+
+// Install DOM 3 XPath support for the current document.
+try {
+	var shouldInstall = true;
+	try {
+		if (document.implementation
+				&& document.implementation.hasFeature
+				&& document.implementation.hasFeature("XPath", null)) {
+			shouldInstall = false;
+		}
+	} catch (e) {
+	}
+	if (shouldInstall) {
+		installDOM3XPathSupport(document, new XPathParser());
+	}
+} catch (e) {
+}

Added: zc.selenium/trunk/src/zc/selenium/resources/selenium-logo.png
===================================================================
(Binary files differ)


Property changes on: zc.selenium/trunk/src/zc/selenium/resources/selenium-logo.png
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + image/png

Added: zc.selenium/trunk/src/zc/selenium/resources/selenium.css
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/selenium.css	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/selenium.css	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,211 @@
+/*
+ * Copyright 2005 ThoughtWorks, Inc
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *  
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*---( Layout )---*/
+
+body {
+    margin: 0;
+    padding: 0;
+    overflow: auto;
+}
+
+td {
+    position: static;
+}
+
+tr {
+    vertical-align: top;
+}
+
+.layout {
+    width: 100%;
+    height: 100%;
+    border-collapse: collapse;
+}
+
+.layout td {
+    margin: 0;
+    padding: 0;
+    border: 0;
+}
+
+iframe {
+    width: 100%;
+    height: 100%;
+    border: 0;
+    background: white;
+    overflow: auto;
+}
+
+/*---( Style )---*/
+
+body, html {
+    font-family: Verdana, Arial, sans-serif;
+}
+
+.selenium th, .selenium td {
+    border: 1px solid #999;
+}
+
+.header {
+    background: #ccc;
+    padding: 0;
+    font-size: 90%;
+}
+
+#controlPanel {
+    padding: 0.5ex;
+    background: #eee;
+    overflow: auto;
+    font-size: 75%;
+    text-align: center;
+}
+
+#controlPanel fieldset {
+    margin: 0.3ex;
+    padding: 0.3ex;
+}
+
+#controlPanel fieldset legend {
+    color: black;
+}
+
+#controlPanel button {
+    margin: 0.5ex;
+}
+
+#controlPanel table {
+    font-size: 100%;
+}
+
+#controlPanel th, #controlPanel td {
+    border: 0;
+}
+
+h1 {
+    margin: 0.2ex;
+    font-size: 130%;
+    font-weight: bold;
+}
+
+h2 {
+    margin: 0.2ex;
+    font-size: 80%;
+    font-weight: normal;
+}
+
+.selenium a {
+    color: black;
+    text-decoration: none;
+}
+
+.selenium a:hover {
+    text-decoration: underline;
+}
+
+button, label {
+    cursor: pointer;
+}
+
+#stats {
+    margin: 0.5em auto 0.5em auto;
+}
+
+#stats th, #stats td {
+    text-align: left;
+    padding-left: 2px;
+}
+
+#stats th {
+    text-decoration: underline;
+}
+
+#stats td.count {
+    font-weight: bold;
+    text-align: right;
+}
+
+#testRuns {
+    color: green;
+}
+
+#testFailures {
+    color: red;
+}
+
+#commandPasses {
+    color: green;
+}
+
+#commandFailures {
+    color: red;
+}
+
+#commandErrors {
+    color: #f90;
+}
+
+.splash {
+    border: 1px solid black;
+    padding: 20px;
+    background: #ccc;
+}
+
+/*---( Logging Console )---*/
+
+#logging-console {
+    background: #fff;
+    font-size: 75%;
+}
+
+#logging-console #banner {
+    display: block;
+    width: 100%;
+    position: fixed;
+    top: 0;
+    background: #ddd;
+    border-bottom: 1px solid #666;
+}
+
+#logging-console #logLevelChooser {
+    float: right;
+    margin: 3px;
+}
+
+#logging-console ul {
+    list-style-type: none;
+    margin: 0px;
+    margin-top: 3em;
+    padding-left: 5px;
+}
+
+#logging-console li {
+    margin: 2px;
+    border-top: 1px solid #ccc;
+}
+
+#logging-console li.error {
+    font-weight: bold;
+    color: red;
+}
+
+#logging-console li.warn {
+    color: red;
+}
+
+#logging-console li.debug {
+    color: green;
+}

Added: zc.selenium/trunk/src/zc/selenium/resources/tests/TestSuite.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/tests/TestSuite.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/tests/TestSuite.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,29 @@
+<html>
+<head>
+<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
+<title>Test Suite</title>
+</head>
+
+<body>
+
+<table     cellpadding="1"
+           cellspacing="1"
+           border="1">
+  <tbody>
+  <tr><td><b>Test Suite</b></td></tr>
+    <tr tal:replace="
+        structure
+        python: modules['zc.selenium.pytest'].suite(request)"
+        >
+      <td>
+        <a href="/@@/selenium-no-publish.html">
+        Make sure we can elect not to publish</a>
+      </td>
+    </tr>
+
+
+  </tbody>
+</table>
+
+</body>
+</html>

Added: zc.selenium/trunk/src/zc/selenium/resources/tests/pop.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/tests/pop.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/tests/pop.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,34 @@
+<html>
+<head>
+<title>Pop a new database</title>
+</head>
+
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+ <tbody>
+ 
+  <tr>
+   <td rowspan="1" colspan="3">
+    <h1>Pop a new database</h1>
+  </td>
+ </tr>
+ 
+<!-- Intelligence product creation form --> 
+
+  <tr tal:define="urlparse modules/urlparse;
+                  zapi     modules/zope.app.zapi;
+                  url      context/@@absolute_url;
+                  netloc python: urlparse.urlsplit(url)[1]">
+   <td>open</td>
+   <td>http://<tal:span replace="netloc"/>/@@/selenium-pop.html</td>
+   <td>&nbsp;</td>
+  </tr>
+  <tr>
+   <td>verifyTextPresent</td>
+   <td>Done</td>
+   <td>&nbsp;</td>
+  </tr>
+ </tbody>
+</table>
+</body>
+</html>

Added: zc.selenium/trunk/src/zc/selenium/resources/tests/push.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/tests/push.html	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/resources/tests/push.html	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,34 @@
+<html>
+<head>
+<title>Push a new database</title>
+</head>
+
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+ <tbody>
+ 
+  <tr>
+   <td rowspan="1" colspan="3">
+    <h1>Push a new database</h1>
+  </td>
+ </tr>
+ 
+<!-- Intelligence product creation form --> 
+
+  <tr tal:define="urlparse modules/urlparse;
+                  zapi     modules/zope.app.zapi;
+                  url      context/@@absolute_url;
+                  netloc python: urlparse.urlsplit(url)[1]">
+   <td>open</td>
+   <td>http://<tal:span replace="netloc"/>/@@/selenium-push.html</td>
+   <td>&nbsp;</td>
+  </tr>
+  <tr>
+   <td>verifyTextPresent</td>
+   <td>Done</td>
+   <td>&nbsp;</td>
+  </tr>
+ </tbody>
+</table>
+</body>
+</html>

Added: zc.selenium/trunk/src/zc/selenium/results.pt
===================================================================
--- zc.selenium/trunk/src/zc/selenium/results.pt	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/results.pt	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE
+    html PUBLIC
+    "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
+     >
+<html
+    xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:tal="http://xml.zope.org/namespaces/tal"
+    xmlns:i18n="http://xml.zope.org/namespaces/i18n"
+    xml:lang="en" lang="en"
+    i18n:domain="zc.selenium"
+    >
+  <head>
+    <title i18n:translate="">Selenium Results</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+  </head>
+  <body>
+    <div
+        tal:condition="python: request['result'] == 'passed'"
+        style="color: #0D0; font-weight: bold; font-size: 500%;
+               width: 100%; text-align: center; padding-top: 1em;"
+        >
+      <i18n:span translate="">Passed!</i18n:span>
+      <script language="Javascript1.1">
+        window.setTimeout("top.close()", 2000)
+      </script>
+    </div>
+    <div
+        tal:condition="python: request['result'] != 'passed'"
+        style="color: #F33; font-weight: bold; font-size: 500%;
+               width: 100%; text-align: center; padding-top: 1em;"
+        >
+      <i18n:span translate="">Failed!</i18n:span>
+    </div>
+  </body>
+</html>

Added: zc.selenium/trunk/src/zc/selenium/results.py
===================================================================
--- zc.selenium/trunk/src/zc/selenium/results.py	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/results.py	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,35 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 Zope Corporation. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Visible Source
+# License, Version 1.0 (ZVSL).  A copy of the ZVSL should accompany this
+# distribution.
+#
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Result reporting resource for zc.selenium.
+
+"""
+
+import sys
+
+import zope.app.pagetemplate
+
+import zc.selenium.resource
+
+class Results(zc.selenium.resource.ResourceBase):
+
+    template = zope.app.pagetemplate.ViewPageTemplateFile('results.pt')
+
+    def POST(self):
+        print >>sys.__stderr__, "in results resource"
+        # get the queue used to communicate with the test thread, this will
+        # fail horribly if not running in "Selenium test" mode
+        messages = sys.modules['__main__'].messages
+        messages.put(self.request)
+        return self.template(self)

Added: zc.selenium/trunk/src/zc/selenium/tests.py
===================================================================
--- zc.selenium/trunk/src/zc/selenium/tests.py	2006-08-15 21:13:59 UTC (rev 69542)
+++ zc.selenium/trunk/src/zc/selenium/tests.py	2006-08-15 21:19:32 UTC (rev 69543)
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Visible Source
+# License, Version 1.0 (ZVSL).  A copy of the ZVSL should accompany this
+# distribution.
+#
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+"""Test harness for zc.selenium.
+
+$Id: tests.py 12897 2006-07-26 20:11:41Z fred $
+"""
+
+import unittest
+from zope.testing import doctest
+
+
+def test_suite():
+    return doctest.DocFileSuite(
+        'pytest.txt',
+        optionflags=(doctest.ELLIPSIS | doctest.REPORT_NDIFF))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+



More information about the Checkins mailing list