[open-ils-commits] r429 - in grpl/trunk: . phone_renewal phone_renewal/continuous_integration phone_renewal/continuous_integration/app phone_renewal/continuous_integration/config phone_renewal/continuous_integration/lib phone_renewal/continuous_integration/lib/tasks phone_renewal/continuous_integration/mini_dci_monitor phone_renewal/continuous_integration/mini_dci_monitor/web_server phone_renewal/continuous_integration/mini_dci_monitor/web_server/images phone_renewal/continuous_integration/script phone_renewal/doc phone_renewal/lib phone_renewal/lib/TelephoneRenewals phone_renewal/lib/TelephoneRenewals/Fakes phone_renewal/sounds phone_renewal/t phone_renewal/t/tlib phone_renewal/tools phone_renewal/vendor (dkyle)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri May 1 11:20:14 EDT 2009


Author: dkyle
Date: 2009-05-01 11:20:12 -0400 (Fri, 01 May 2009)
New Revision: 429

Added:
   grpl/trunk/phone_renewal/
   grpl/trunk/phone_renewal/.vim
   grpl/trunk/phone_renewal/README.txt
   grpl/trunk/phone_renewal/Rakefile
   grpl/trunk/phone_renewal/continuous_integration/
   grpl/trunk/phone_renewal/continuous_integration/README
   grpl/trunk/phone_renewal/continuous_integration/Rakefile
   grpl/trunk/phone_renewal/continuous_integration/app/
   grpl/trunk/phone_renewal/continuous_integration/app/all_projects_builder.rb
   grpl/trunk/phone_renewal/continuous_integration/app/build_tagger.rb
   grpl/trunk/phone_renewal/continuous_integration/app/builder.rb
   grpl/trunk/phone_renewal/continuous_integration/app/builder_client.rb
   grpl/trunk/phone_renewal/continuous_integration/app/dci_server.rb
   grpl/trunk/phone_renewal/continuous_integration/app/dir_context.rb
   grpl/trunk/phone_renewal/continuous_integration/app/do_build_on_server.rb
   grpl/trunk/phone_renewal/continuous_integration/app/investigator.rb
   grpl/trunk/phone_renewal/continuous_integration/app/project.rb
   grpl/trunk/phone_renewal/continuous_integration/config/
   grpl/trunk/phone_renewal/continuous_integration/config/environment.rb
   grpl/trunk/phone_renewal/continuous_integration/config/my_projects.rb
   grpl/trunk/phone_renewal/continuous_integration/lib/
   grpl/trunk/phone_renewal/continuous_integration/lib/constructor.rb
   grpl/trunk/phone_renewal/continuous_integration/lib/nohup.rb
   grpl/trunk/phone_renewal/continuous_integration/lib/platform.rb
   grpl/trunk/phone_renewal/continuous_integration/lib/service_installer.rb
   grpl/trunk/phone_renewal/continuous_integration/lib/tasks/
   grpl/trunk/phone_renewal/continuous_integration/lib/tasks/osx_remove_startup_item.rake
   grpl/trunk/phone_renewal/continuous_integration/lib/tasks/osx_startup_item.rake
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/stop_web
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/images/
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/images/logo16.ico
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/images/logo64.png
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/index.rhtml
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/layout.rhtml
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/log
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/mini_server.rb
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/project.rhtml
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/view_build.rhtml
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/view_server_log.rhtml
   grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/web_server.rb
   grpl/trunk/phone_renewal/continuous_integration/script/
   grpl/trunk/phone_renewal/continuous_integration/script/rebuild_all_now
   grpl/trunk/phone_renewal/continuous_integration/script/sample_init_script.sh
   grpl/trunk/phone_renewal/continuous_integration/script/server
   grpl/trunk/phone_renewal/continuous_integration/script/stop_server
   grpl/trunk/phone_renewal/deploy_app.pl
   grpl/trunk/phone_renewal/deploy_sounds.pl
   grpl/trunk/phone_renewal/doc/
   grpl/trunk/phone_renewal/doc/GRPL_Phone_Renewals_Proposal.pdf
   grpl/trunk/phone_renewal/doc/Telephone_renewal_notes.pdf
   grpl/trunk/phone_renewal/doc/example_dialplan_and_sip_config.txt
   grpl/trunk/phone_renewal/doc/project_wiki.html
   grpl/trunk/phone_renewal/doc/renew_all_items_workflow.pdf
   grpl/trunk/phone_renewal/doc/renewal_result_data_structures.pdf
   grpl/trunk/phone_renewal/eg_auth.pl
   grpl/trunk/phone_renewal/lib/
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/AllItemsRenewer.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/AppConfig.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/CallHandler.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/ERGateway.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/Emailer.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/EvergreenRenewal.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/FakeEvergreenRenewal.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/FakePhoneMenu.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/IndividualItemsRenewer.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/LogChannel.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/Logger.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/ObjectContext.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/PhoneMenu.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/PromptManager.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/PromptStore.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalAnnouncer.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalLogger.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalResult.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalResultSet.pm
   grpl/trunk/phone_renewal/lib/TelephoneRenewals/SoundIndexPrinter.pm
   grpl/trunk/phone_renewal/lib/prompt_manager.agi.pl
   grpl/trunk/phone_renewal/lib/telephone_renewal_menu.agi.pl
   grpl/trunk/phone_renewal/lib/test_against_fake_asterisk.pl
   grpl/trunk/phone_renewal/lib/test_against_fake_asterisk_and_fake_evergreen.pl
   grpl/trunk/phone_renewal/lib/test_against_fake_evergreen.pl
   grpl/trunk/phone_renewal/print_sound_index.pl
   grpl/trunk/phone_renewal/run_tests.pl
   grpl/trunk/phone_renewal/sounds/
   grpl/trunk/phone_renewal/sounds/barcode.gsm
   grpl/trunk/phone_renewal/sounds/call_our_office_for_further_assistance.gsm
   grpl/trunk/phone_renewal/sounds/could_not_be_renewed_due_to_error.gsm
   grpl/trunk/phone_renewal/sounds/dummy_message1.gsm
   grpl/trunk/phone_renewal/sounds/dummy_message2.gsm
   grpl/trunk/phone_renewal/sounds/goodbye.gsm
   grpl/trunk/phone_renewal/sounds/has_been_renewed.gsm
   grpl/trunk/phone_renewal/sounds/item_with_barcode_ending.gsm
   grpl/trunk/phone_renewal/sounds/items_checked_out.gsm
   grpl/trunk/phone_renewal/sounds/may_not_be_renewed_at_this_time.gsm
   grpl/trunk/phone_renewal/sounds/of_your_items_have_been_renewed.gsm
   grpl/trunk/phone_renewal/sounds/please_enter_barcode.gsm
   grpl/trunk/phone_renewal/sounds/please_enter_your_card_number.gsm
   grpl/trunk/phone_renewal/sounds/press_1_to_continue_renewing_individual_items.gsm
   grpl/trunk/phone_renewal/sounds/press_1_to_hear_renewal_details.gsm
   grpl/trunk/phone_renewal/sounds/press_1_to_renew_all_or_press_2_for_individual.gsm
   grpl/trunk/phone_renewal/sounds/prompt_manager_ask_for_prompt_number.gsm
   grpl/trunk/phone_renewal/sounds/prompt_manager_error.gsm
   grpl/trunk/phone_renewal/sounds/prompt_manager_exit.gsm
   grpl/trunk/phone_renewal/sounds/prompt_manager_intro.gsm
   grpl/trunk/phone_renewal/sounds/prompt_manager_is_currently.gsm
   grpl/trunk/phone_renewal/sounds/prompt_manager_main_menu.gsm
   grpl/trunk/phone_renewal/sounds/prompt_manager_prompt_number.gsm
   grpl/trunk/phone_renewal/sounds/prompt_manager_recording_menu.gsm
   grpl/trunk/phone_renewal/sounds/some_items_could_not_be_renewed.gsm
   grpl/trunk/phone_renewal/sounds/thanks_for_calling.gsm
   grpl/trunk/phone_renewal/sounds/unexpected_error_occurred.gsm
   grpl/trunk/phone_renewal/sounds/was_not_recognized.gsm
   grpl/trunk/phone_renewal/sounds/welcome_to_the_phone_renewal_system.gsm
   grpl/trunk/phone_renewal/sounds/you_currently_have.gsm
   grpl/trunk/phone_renewal/sounds/you_currently_have_no_items_checked_out.gsm
   grpl/trunk/phone_renewal/sounds/your_card_number_could_not_be_found.gsm
   grpl/trunk/phone_renewal/store_updated_sounds.pl
   grpl/trunk/phone_renewal/t/
   grpl/trunk/phone_renewal/t/tlib/
   grpl/trunk/phone_renewal/t/tlib/AllItemsRenewerTest.pm
   grpl/trunk/phone_renewal/t/tlib/AppConfigTest.pm
   grpl/trunk/phone_renewal/t/tlib/CallHandlerTest.pm
   grpl/trunk/phone_renewal/t/tlib/EmailerTest.pm
   grpl/trunk/phone_renewal/t/tlib/IndividualItemsRenewerTest.pm
   grpl/trunk/phone_renewal/t/tlib/LogChannelTest.pm
   grpl/trunk/phone_renewal/t/tlib/LoggerTest.pm
   grpl/trunk/phone_renewal/t/tlib/ObjectContextTest.pm
   grpl/trunk/phone_renewal/t/tlib/PromptManagerTest.pm
   grpl/trunk/phone_renewal/t/tlib/PromptStoreTest.pm
   grpl/trunk/phone_renewal/t/tlib/RenewalAnnouncerTest.pm
   grpl/trunk/phone_renewal/t/tlib/RenewalLoggerTest.pm
   grpl/trunk/phone_renewal/t/tlib/RenewalResultSetTest.pm
   grpl/trunk/phone_renewal/t/tlib/RenewalResultTest.pm
   grpl/trunk/phone_renewal/t/tlib/SoundIndexPrinterTest.pm
   grpl/trunk/phone_renewal/t/tlib/TestHelper.pm
   grpl/trunk/phone_renewal/t/tlib/UnitTestSuite.pm
   grpl/trunk/phone_renewal/t/unit_tests.t
   grpl/trunk/phone_renewal/tools/
   grpl/trunk/phone_renewal/tools/new_class.pl
   grpl/trunk/phone_renewal/vendor/
   grpl/trunk/phone_renewal/vendor/Class-Inner-0.1.tar.gz
   grpl/trunk/phone_renewal/vendor/Devel-Symdump-2.08.tar.gz
   grpl/trunk/phone_renewal/vendor/Error-0.17015.tar.gz
   grpl/trunk/phone_renewal/vendor/File-Path-Expand-1.02.tar.gz
   grpl/trunk/phone_renewal/vendor/MIME-Lite-3.024.tar.gz
   grpl/trunk/phone_renewal/vendor/Module-Build-0.32.tar.gz
   grpl/trunk/phone_renewal/vendor/SMTP-Server-1.1.tar.gz
   grpl/trunk/phone_renewal/vendor/Sub-Uplevel-0.2002.tar.gz
   grpl/trunk/phone_renewal/vendor/Test-Exception-0.27.tar.gz
   grpl/trunk/phone_renewal/vendor/Test-MockObject-1.09.tar.gz
   grpl/trunk/phone_renewal/vendor/Test-Simple-0.86.tar.gz
   grpl/trunk/phone_renewal/vendor/Test-Unit-0.25.tar.gz
   grpl/trunk/phone_renewal/vendor/UNIVERSAL-can-1.12.tar.gz
   grpl/trunk/phone_renewal/vendor/UNIVERSAL-isa-1.01.tar.gz
   grpl/trunk/phone_renewal/vendor/asterisk-perl-0.10.tar.gz
Log:
Telephone Renewals with Asterisk

Added: grpl/trunk/phone_renewal/.vim
===================================================================
--- grpl/trunk/phone_renewal/.vim	                        (rev 0)
+++ grpl/trunk/phone_renewal/.vim	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,2 @@
+let g:fuzzy_ignore = "continuous_integration/*"
+let g:fuzzy_matching_limit = 20

Added: grpl/trunk/phone_renewal/README.txt
===================================================================
--- grpl/trunk/phone_renewal/README.txt	                        (rev 0)
+++ grpl/trunk/phone_renewal/README.txt	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,186 @@
+Sun Apr  5 02:18:17 EDT 2009
+crosby
+
+UNIT TESTS
+
+perl t/unit_tests.pl
+
+
+APP CONFIGURATION
+
+To configure the log file and sounds dir locations, email notification
+settings, etc, edit the bootstrap script:
+
+lib/telephone_renewal_menu.agi.pl
+  ...
+  my $call_handler = $objectContext->get_call_handler(
+    smtp_host_and_port => "localhost:25",
+    error_email_recipients => [ 
+      'crosby at atomicobject.com', 
+      'bott at grpl.org', 
+      'dkyle at grpl.org' 
+    ],
+    error_email_from  => 'GRPL <telephonerenewals at grpl.org>',
+    error_email_subject  => '[ERROR] Telephone Renewal Error',
+  );
+  ...
+
+The log file and sounds directory are also configurable, but the defaults
+ought to work for default asterisk installations.
+To see default app config settings, view the AppConfig class constructor:
+
+lib/TelephoneRenewals/AppConfig.pm
+  ...
+  my $self = {
+    log_file => '/var/log/asterisk/telephone_renewals.log',
+    sounds_dir => '/var/lib/asterisk/sounds/phone_renewals',
+    smtp_host_and_port => 'localhost:25',
+    error_email_recipients => [ "not set" ],
+    error_email_from  => 'GRPL <telephonerenewals at grpl.org>',
+    error_email_subject  => '[ERROR] Telephone Renewal Error',
+  };
+  ...
+
+
+DEPLOYMENT
+
+(NOTE: all scripts are designed to be run from this dir, the project root.)
+
+deploy_app.pl
+  Deploy the application code.
+  Will prompt for overwrite if the app directory exists already.
+  NOTE: The sound files used in the voice menu are deployed separately via
+  deploy_sounds.pl
+
+  The AGI scripts are stored in svn with the proper executable bit set, but
+  it won't hurt to double check, eg, see that the file:
+  /var/lib/asterisk/agi-bin/phone_renewals/telephone_renewal_menu.agi.pl
+  is executable.
+
+deploy_sounds.pl
+  Deploy the voice menu sound files.  Will prompt to overwrite if needed.
+  NOTE: The Prompt Manager is used in deployment to record new versions of
+  existing sound files.  These new files will land in the deployed sound
+  directory, and will be overwritten by deploy_sounds.pl.  THUS! it is
+  important to backup the sound files from production into this svn repository
+  via the store_updated_sounds.pl
+
+store_updated_sounds.pl
+  Backup the sound files from the deployed sound dir into ./sounds.
+
+print_sound_index.pl
+  Prints a sheet of prompt/sound index numbers followed by their base names.
+  This sheet can be printed out as a reference for people using the Prompt
+  Manager voice menu.
+
+
+ASTERISK CONFIGURATION
+
+The main phone renewal system is encapsulated by the
+telephone_renewal_menu.agi.pl script, so minimally, all you need is one line
+in your dial plan to execute the script via AGI.
+
+Example: (in /etc/asterisk/extensions.conf)
+
+[phone-renewals]
+exten => _X.,1,AGI(phone_renewals/telephone_renewal_menu.agi.pl) ; matches any extension.
+
+This is the context that should be used by live, incoming calls from the real
+world.
+
+
+LOGGING / ERROR NOTIFICATION
+
+Each call gets logged, capturing library card number, renewal activity, and
+errors.
+
+Unexpected errors will cause error notification to be sent to administrators.
+
+Example log output:
+[Sun Apr  5 03:34:25 EDT 2009] - INFO - Handling new call ******************************
+[Sun Apr  5 03:34:37 EDT 2009] - INFO - Patron 22876876545666 has 5 items out.
+[Sun Apr  5 03:34:46 EDT 2009] - INFO - Patron 22876876545666 renewing all items...
+[Sun Apr  5 03:34:50 EDT 2009] - INFO - Renewal FAILED: 37777777777777 - unknown barcode
+[Sun Apr  5 03:35:03 EDT 2009] - INFO - Renewal FAILED: 38888888888888 - no renewals allowed
+[Sun Apr  5 03:35:09 EDT 2009] - INFO - Renewal FAILED: 34545454545458 - ouch
+[Sun Apr  5 03:35:09 EDT 2009] - ERROR - Renewal result contained unexpected status 'ouch' for barcode 34545454545458
+[Sun Apr  5 03:35:09 EDT 2009] - ERROR - TelephoneRenewals::Emailer is disabled; set AppConfig smtp_host_and_port to enable it. at /var/lib/asterisk/agi-bin/phone_renewals/TelephoneRenewals/Logger.pm line 55
+
+[Sun Apr  5 03:35:22 EDT 2009] - INFO - Renewed ok: 31111111111111
+[Sun Apr  5 03:35:28 EDT 2009] - INFO - Renewed ok: 32222222222222
+[Sun Apr  5 03:35:33 EDT 2009] - INFO - Hanging up.
+
+Example email notification:
+----
+From: GRPL <telephonerenewals at grpl.org>
+To: crosby at atomicobject.com
+Subject: [ERROR] Telephone Renewal Error
+
+An error occurred in the GRPL telephone renewal system:
+
+[Sun Apr  5 03:42:29 EDT 2009] - ERROR - Rigged to explode -- barcode 18776666555544.  This is an intentionally unhandled error for testing purposes.
+ at /var/lib/asterisk/agi-bin/phone_renewals/TelephoneRenewals/IndividualItemsRenewer.pm line 42
+----
+
+
+PHONE RENEWAL SYSTEM ADMIN / TESTING
+
+For internal administration, you could setup an alternate context, to be
+accessed by hard-wired phones in your lap, or SIP (and softphone) clients:
+
+Example: (in /etc/asterisk/extensions.conf)
+
+[phone-renewals-admin]
+exten => 100,1,AGI(phone_renewals/prompt_manager.agi.pl)
+exten => 200,1,AGI(phone_renewals/test_against_fake_evergreen.pl)
+exten => 300,1,AGI(phone_renewals/telephone_renewal_menu.agi.pl)
+
+Extension 100 will invoke the sound Prompt Manager, which lets you
+review and record a specific sound file, or to review and record all
+configured sound files in order.
+
+Extension 200 will invoke the phone menu system BUT using a faked-out
+EvergreenRenewal module, with pre-programmed responses to certain entries.
+
+Extension 300 invokes the actual phone menu system, including access to the
+Evergreen system.  (Included here for ease of access.)
+
+This is just a sample; these extensions are independant of one another.
+
+
+SYSTEM TESTING WITHOUT A PHONE
+
+test_against_fake_asterisk.pl
+test_against_fake_asterisk_and_fake_evergreen.pl
+  These two scripts invoke a command-line interface to the menu system.
+  The inputs are a little less controlled than they would be if you were using
+  a phone (no automatic looping to protect from empty inputs, no verification
+  of barcode length, etc.)
+
+  You may or may not wish to hit your actual Evergreen system.  The first
+  script WILL hit your Evergreen, the second will use FakeEvergreenRenewal
+  with its preprogrammed responses.
+
+
+CONTINUOUS INTEGRATION
+
+The folder continuous_integration/ is a self-contained continuous integration
+server called "DCI".
+
+See doc/project_wiki.html subject ContinousIntegration for details on
+installation and usage.
+
+In short:
+
+- DCI uses svn to checkout your project and watch for new checkins.
+- It's internal configuration (continuous_integration/config/my_projects.rb)
+  is already setup for phone_renewals
+- You need to install Ruby, Ruby Gems, and Rake (in that order)
+
+To install as a service and start:
+  cd continuous_integration
+  sudo rake install_init_script user=(your_unix_userid)
+  sudo /etc/init.d/dci_server start
+  (hit http://localhost:4444... or note the URL that gets printed by the
+  installer)
+

Added: grpl/trunk/phone_renewal/Rakefile
===================================================================
--- grpl/trunk/phone_renewal/Rakefile	                        (rev 0)
+++ grpl/trunk/phone_renewal/Rakefile	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,12 @@
+# This is a Rakefile that defines build tasks.
+# Rake is a tool from the Ruby world.  This project doesn't use Ruby
+# for any production code or tooling; however the Continuous Integration
+# server residing under continuous_integration/ expects its target projects
+# to be "buildable" via Rake.
+
+desc "Execute the unit test suite"
+task :run_tests do 
+  sh "perl run_tests.pl"
+end
+
+task :default => :run_tests

Added: grpl/trunk/phone_renewal/continuous_integration/README
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/README	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/README	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,21 @@
+Sun Mar  5 16:38:52 EST 2006
+
+DCI (Dave's Continuous Integration server)
+
+Target project(s) configured in config/my_projects.rb
+
+rake install_init_script  # Write /etc/init.d/dci_server and add it to default runlevel via rc-update
+rake remove_init_script   # Uninstall the DCI server init script
+
+
+Start/stop DCI server process:
+  script/server
+  script/stop_server
+  (preferred: sudo /etc/init.d/dci_server [start|stop|restart]
+
+Start/stop DCI web monitor:
+  script/web      (http://yourserver:4444)
+  script/stop_web
+  (preferred: sudo /etc/init.d/dci_server [start|stop|restart]
+
+Project working copies and logfiles are kept in ./data/projects and ./data/logs, respectively.

Added: grpl/trunk/phone_renewal/continuous_integration/Rakefile
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/Rakefile	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/Rakefile	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,79 @@
+$dci_dir = File.expand_path(File.dirname(__FILE__)) 
+$init_script = "/etc/init.d/dci_server"
+
+desc "Write /etc/init.d/dci_server and add it to default runlevel via rc-update"
+task :install_init_script do
+  user = ENV["user"]
+  unless user
+    who = `whoami`.strip
+    puts "Please supply a user id to use when launching the DCI server."
+    puts "If you don't have a user created for this express purpose, you might just use whoever has this project checked out locally."
+    puts "Perhaps #{who}?"
+    puts "Eg, 'rake install_init_script user=#{who}'"
+    $stdout.flush
+    raise "Can't install script without setting a user id for launching"
+  end
+
+  $dci_dir = File.expand_path(File.dirname(__FILE__)) 
+  $init_script = "/etc/init.d/dci_server"
+  script_text =<<EOS
+#!/bin/sh
+#
+# /etc/init.d/dci_server
+#
+### BEGIN INIT INFO
+# Provides:     dci_server
+# Required-Start:   $local_fs $remote_fs $network 
+# X-UnitedLinux-Should-Start: $named $time dhcp radiusd
+# Required-Stop:    $local_fs $remote_fs $network
+# X-UnitedLinux-Should-Stop:  
+# Default-Start:    3 5
+# Default-Stop:     0 1 2 6
+# Short-Description:    DCI Server
+# Description:      Start the DCI Server
+### END INIT INFO
+
+#
+# main part 
+#
+case "$1" in
+  start)
+    echo Starting...
+    su - #{user} -c "#{$dci_dir}/script/server"
+    su - #{user} -c "#{$dci_dir}/mini_dci_monitor/web"
+    exit $?
+    ;;
+  stop)
+    echo Stopping...
+    su - #{user} -c "#{$dci_dir}/mini_dci_monitor/stop_web"
+    su - #{user} -c "#{$dci_dir}/script/stop_server"
+    exit $?
+    ;;
+  restart)
+    $0 stop
+    echo Sleeping...
+    sleep 3
+    $0 start
+    ;;
+  *)
+    echo "I don't understand."
+    ;;
+esac
+EOS
+
+  File.open($init_script,"w") do |f|
+    f.print script_text
+  end
+  print "Wrote #{$init_script}"
+  sh "chmod +x #{$init_script}"
+  sh "sudo rc-update add dci_server default"
+  puts "DCI should now automatically launch at boot."
+  puts "To start the server and its web monitor now, run 'sudo /etc/init.d/dci_server start'"
+  puts "The web monitor should then be visible at http://#{`hostname`.strip}:4444"
+end
+
+desc "Uninstall the DCI server init script"
+task :remove_init_script do
+  sh "sudo rc-update del dci_server default"
+  sh "sudo rm #{$init_script}"
+end

Added: grpl/trunk/phone_renewal/continuous_integration/app/all_projects_builder.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/all_projects_builder.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/all_projects_builder.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,21 @@
+require 'yaml'
+
+class AllProjectsBuilder
+	def initialize(investigator)
+		@investigator = investigator
+	end
+
+	def rebuild_all_successful_projects
+		names = @investigator.project_names
+
+		names.each do |project|
+			status = YAML.load(@investigator.project_status(project))
+
+			if status['status'] == 'success'
+				@investigator.force_build(project)
+			end
+		end
+
+		nil
+	end
+end

Added: grpl/trunk/phone_renewal/continuous_integration/app/build_tagger.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/build_tagger.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/build_tagger.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,23 @@
+class BuildTagger
+  def initialize project
+    @project = project
+  end
+  
+  def tag_tested_build test_succeeded
+    tag_location = @project.build_tag_location
+    raise "build_tag_location must be provided to tag builds" unless tag_location
+
+	  status = test_succeeded ? "success" : "failure"
+
+	  tag_name = eval(%|"#{@project.build_tag_format}"|, binding)
+	  tag_message = eval(%|"#{@project.build_tag_message}"|, binding)
+	  tag_uri = "#{tag_location}/#{tag_name}"
+	  
+	  @project.exec_command(%|svn cp -m "#{tag_message}" "#{@project.working_copy}" "#{tag_uri}"|)
+  end
+  
+  # The interpolated build string may call methods on project.
+  def method_missing(name, *args, &block)
+    @project.send name, *args, &block
+  end
+end
\ No newline at end of file

Added: grpl/trunk/phone_renewal/continuous_integration/app/builder.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/builder.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/builder.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,111 @@
+require 'constructor'
+require 'logger'
+require 'thread'
+require 'build_tagger'
+
+#
+# Continuous integration heart.  
+# Wakes up periodically, checks its registered project for updates,
+# builds/tests as needed.
+#
+class Builder
+	constructor :period, :log_dir, :accessors => true
+	attr_reader :projects
+
+	def setup
+		@cycle_mutex = Mutex.new
+		@log = Logger.new(log_file)
+		@log.level = 1
+	end
+
+	def log_file
+		"#{@log_dir}/server.log"
+	end
+
+	# Add a target project for building
+	def <<(project)
+		@projects ||= []
+		@projects << project
+		@log.debug "Tracking project #{project.name}"
+	end
+
+	# Main loop for server: periodically check all projects, building as needed.
+	def run
+		@log.info "Builder activated (pid=#{$$})"
+		@alive = true
+
+		@thread = Thread.new do
+			while @alive
+				@projects.each do |project|
+					begin 
+						cycle project if project.auto_build?
+					rescue => oops
+						@log.error "Cycle failed for #{project.name}: #{oops}"
+						@log.error oops.backtrace.join("\n\t")
+					end
+				end
+				sleep @period
+			end
+		end
+	end
+
+	def cycle(project,force=false)
+		@cycle_mutex.synchronize do 
+			@log.debug "Cycling project #{project.name}"
+			if force or not project.up_to_date?
+				@log.info "Project #{project.name} not up-to-date" unless force
+				@log.info "Project #{project.name} force build" if force
+
+				# Sync wc
+				if project.has_working_copy?
+					@log.info "Updating #{project.name}..."
+					project.update
+				else
+					@log.info "Checking out #{project.name}..."
+					project.checkout
+				end
+				# Build
+				@log.info "Building #{project.name}..."
+				build_result = project.build
+ 			  status_word = build_result	? "successful" : "failed"
+				@log.info "Project #{project.name} (#{project.current_build_number}) #{status_word.upcase}"		
+
+				if project.tag_builds?
+				  @log.info "Tagging #{status_word} build for project #{project.name}"
+				  begin
+				    BuildTagger.new(project).tag_tested_build build_result
+				  rescue => error
+				    @log.error "Build tagging for project #{project.name} FAILED! (#{error})"
+				  end
+				else
+				  @log.info "Not tagging project #{project.name}"
+			  end
+			else 
+				# No work required
+				@log.debug "Project #{project.name} is up-to-date"
+			end
+		end
+	end
+
+	def force_build(project)
+		Thread.new do 
+		  cycle project,true 
+		end
+	end
+
+	def auto_build_all
+		Thread.new do 
+			@projects.each do |project|
+				cycle project,true if project.auto_build?
+			end
+		end
+	end
+
+	def stop
+		@log.info "Shutdown begin"
+		@alive = false
+		@thread.wakeup
+		@thread.join(3) || @log.error("Main thread didn't exit")
+		@log.info "Shutdown complete"
+	end
+end

Added: grpl/trunk/phone_renewal/continuous_integration/app/builder_client.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/builder_client.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/builder_client.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,27 @@
+require 'drb'
+
+class BuilderClient
+	def initialize(url)
+		@server = DRbObject.new(nil,url)
+		@server.ping
+	end
+
+	def list_project_names
+		puts @server.project_names
+	end
+
+	def rebuild_all_successful_projects
+		@server.rebuild_all_successful_projects
+	end
+
+	def list_project_statuses
+		@server.project_names.each do |pname|
+			puts @server.project_status(pname)
+		end
+	end
+	
+	def force_build(name)
+	  @server.force_build(name)
+  end
+end
+

Added: grpl/trunk/phone_renewal/continuous_integration/app/dci_server.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/dci_server.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/dci_server.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,45 @@
+# Launches the DCI server.
+
+require 'drb'
+require 'logger'
+require 'dir_context'
+require 'project'
+require 'builder'
+require 'investigator'
+
+class DciServer
+	def launch(project_config)
+		# File context
+		context = DirContext.new(:base_dir => APP_ROOT + '/data/')
+
+		# Build and start builder server
+		builder = Builder.new(
+			:period => 30, 
+			:log_dir => context.log_dir
+		)
+
+		# Configure projects
+		eval(File.read(project_config), binding)
+
+		# Start DRb server
+		url = "druby://0.0.0.0:42420"
+		DRb.start_service url, Investigator.new(builder)
+		puts "Started DRb service on #{url}"
+		STDOUT.flush
+
+		# Interrupt handler
+		trap :INT do 
+			builder.stop
+			DRb.stop_service
+		end
+
+		# Force initial builds
+#		builder.auto_build_all
+
+		# Launch periodic cycles
+		builder.run
+
+		# Hang on DRb thread
+		DRb.thread.join
+	end
+end

Added: grpl/trunk/phone_renewal/continuous_integration/app/dir_context.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/dir_context.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/dir_context.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,30 @@
+require 'constructor'
+require 'fileutils'
+class DirContext
+	include FileUtils
+
+	constructor :base_dir
+	def setup
+		mkdir_p @base_dir
+	end
+
+	def log_dir(ext=nil)
+		dir = "#{base_dir}/logs"
+		dir = "#{base_dir}/logs/#{ext}" if ext
+		mkdir_p dir
+		dir
+	end
+
+	def proj_dir(ext=nil)
+		dir = "#{base_dir}/projects"
+		dir = "#{base_dir}/projects/#{ext}" if ext
+		dir
+	end
+
+	def base_dir(ext=nil)
+		dir = File.expand_path(@base_dir)
+		dir = "#{dir}/#{ext}" if ext
+		mkdir_p dir
+		dir
+	end
+end

Added: grpl/trunk/phone_renewal/continuous_integration/app/do_build_on_server.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/do_build_on_server.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/do_build_on_server.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,7 @@
+require 'drb'
+
+ at url = "druby://localhost:42420"
+dci = DRbObject.new(nil, at url)
+puts "'#{dci.project_name}' @ '#{dci.project_repository}'"
+puts "Triggering build"
+dci.do_build

Added: grpl/trunk/phone_renewal/continuous_integration/app/investigator.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/investigator.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/investigator.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,83 @@
+require 'constructor'
+require 'all_projects_builder'
+
+class Investigator
+	def initialize(builder)
+		@builder = builder
+	end
+
+	def ping; 'pong'; end
+
+	def project_names
+		@builder.projects.map do |x| x.name end
+	end
+
+	def current_build_number(proj_name)
+		get_project(proj_name).current_build_number
+	end
+
+	def available_build_numbers(proj_name)
+		get_project(proj_name).available_build_numbers
+	end
+
+	def project_status(proj_name, build_num=nil)
+		on_project proj_name do |proj|
+			return nil unless proj
+			build_num ||= proj.current_build_number # default to current build
+			fname = proj.summary_file(build_num)
+			return File.read(fname) if File.exists?(fname)
+			return nil # no status
+		end
+	end
+
+	def build_output(proj_name,build_num=nil)
+		on_project proj_name do |proj|
+			build_num ||= proj.current_build_number # default to current build
+			fname = proj.log_file(build_num)
+			File.read(fname) rescue return "(No build output)"
+		end
+	end
+
+	def svn_output(proj_name)
+		on_project proj_name do |proj|
+			File.read(proj.svn_out_file) rescue return "(No SVN output)" 
+		end
+	end
+
+	def svn_error(proj_name)
+		on_project proj_name do |proj|
+			File.read(proj.svn_err_file) rescue return "(No SVN error file)"
+		end
+	end
+
+	def server_log
+		File.read @builder.log_file rescue return "(No server log)"
+	end
+
+	def force_build(proj_name)
+		on_project proj_name do |project|
+			@builder.force_build project
+		end
+	end
+
+	def rebuild_all_successful_projects
+		AllProjectsBuilder.new(self).rebuild_all_successful_projects
+	end
+		
+	private 
+	def get_project(proj_name)
+		@builder.projects.find do |x| x.name == proj_name end
+	end
+	def on_project(proj_name)
+		yield get_project(proj_name)
+	end
+
+	def get_file_data(method_name, proj_name, build_num=nil)
+		on_project proj_name do |proj|
+			build_num ||= proj.current_build_number # default to current build
+			fname = proj.send(:method_name, build_num)
+			File.read(fname)
+		end
+	end
+	
+end

Added: grpl/trunk/phone_renewal/continuous_integration/app/project.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/app/project.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/app/project.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,310 @@
+require 'constructor'
+require 'fileutils'
+require 'yaml'
+
+#
+# Encapsulate actions and data regarding a project targeted for continuous
+# integration.  Assumes project is stored in Subversion.
+#
+class Project
+	include FileUtils
+	constructor :name, :repository, :working_copy, :monitor_path, :log_dir, :auto_build, :rake_target,
+	            :build_tag_format, :build_tag_location, :build_tag_message, :perforce, :git,
+	            :accessors => true, :strict => false
+
+	# Called after auto-init
+	def setup
+		mkdir_p @log_dir
+		@auto_build = true unless @auto_build == false
+
+    # A string to be interpolated when tagging a build to get the tag name
+		# status will be either 'success' or 'failure'.
+		@build_tag_format ||= '#{name}_#{Time.now.strftime("%Y-%m-%d:%H:%M:%S")}_dci_build_#{current_build_number}_#{status}'
+		
+		# A string to be interpolated when tagging a build to get the tag commit message
+		# status will be either 'success' or 'failure'.
+		@build_tag_message ||= 'DCI auto-tag'
+
+    if @perforce
+      @repository = @perforce[:workspace]
+    end
+
+    if @git
+      @repository = @git[:url]
+    end
+	end
+
+	def has_working_copy?
+		return File.exist?(@working_copy)
+	end
+	
+	def has_monitor_path?
+	  if @monitor_path.nil?
+	    return false
+    end
+    
+	  return File.exists?(@monitor_path)
+  end
+
+	def changes_on_server?
+    if perforce?
+      output = p4_in_working_copy("sync -n ./...")
+#      puts "PERFORCE PEEKING:\n#{output}"
+      if output =~ /up-to-date/
+#        puts "NO CHANGES ON SERVER"
+        return false
+      else
+#        puts "FOUND CHANGES ON SERVER"
+        return true
+      end
+    elsif git?
+      remote_head = exec_command_and_return_output(%|git ls-remote #{@repository} refs/heads/master|).split.first.strip
+      local_head = exec_command_and_return_output(%|cat #{@working_copy}/.git/refs/heads/master|).strip
+      return remote_head != local_head
+    else
+      working_path = has_monitor_path? ? @monitor_path : @working_copy
+      exec_command(%|svn status -u "#{working_path}"|) do |outfile|
+        s = File.read(outfile) 
+        if s =~ /^\s*\*/ # look for asterisks; they're the telltale
+          return true
+        else
+          return false
+        end
+      end
+    end
+	end
+
+	def auto_build?
+		@auto_build
+	end
+
+	def up_to_date?
+		has_working_copy? and not changes_on_server?
+	end
+	
+	def tag_builds?
+	 @build_tag_location
+	end
+
+  def perforce?
+    !@perforce.nil?
+  end
+
+  def git?
+    !@git.nil?
+  end
+
+  def p4_options_string
+    "-p #{@perforce[:host_and_port]} -u #{@perforce[:username]} -P #{@perforce[:password]} -c #{@perforce[:workspace]}"
+  end
+
+  def checkout
+    if perforce?
+      mkdir_p @working_copy
+      p4_in_working_copy("sync -f ./...")
+    elsif git?
+      exec_command(%|git clone #{@repository} #{@working_copy}|)
+    else 
+      exec_command(%|svn checkout "#{@repository}" "#{@working_copy}"|)
+    end
+  end 
+
+	def update
+    if perforce?
+      p4_in_working_copy("sync ./...")
+    elsif git?
+      exec_command(%|cd #{working_copy}; git pull|)
+    else
+      exec_command(%|svn update "#{@working_copy}"|)
+    end
+	end
+	
+	def svn_info
+		cmd = %|svn info "#{@working_copy}"|
+		`#{cmd}`
+	end
+
+	def svn_revision
+    if svn_info =~ /Revision: (\d+)/
+      return $1.to_i
+    else
+      return -1
+    end
+	end
+
+  def p4_in_working_copy(str)
+    cd @working_copy do
+      cmd = "p4 #{p4_options_string} #{str}"
+      return `#{cmd} 2>&1`
+    end
+  end
+
+  def perforce_revision
+    rev = -1
+    begin
+      changelist_nums = []
+      p4_in_working_copy("changes ./...").each_line do |line|
+        nums << line.split(/ /)[1].to_i
+      end
+      return -1 if changelist_nums.empty?
+      return changelist_nums.sort.last
+    rescue Exception 
+      return -1
+    end
+  end
+
+  def git_revision
+    `cat #{@working_copy}/.git/refs/heads/master`
+  end
+
+	def log_file(num)
+		filebase_for_build(num) + ".log"
+	end
+
+	def summary_file(num)
+		filebase_for_build(num) + ".yml"
+	end
+
+	def available_summary_build_numbers
+	  Dir["#{@log_dir}/build_*.yml"].map do |yfile|
+			if yfile =~ /build_(\d\d\d\d).yml/
+				$1.to_i
+			end
+		end.sort
+	end
+
+	def svn_error_file
+		"#{@log_dir}/svn_errors."
+	end
+		
+
+	def current_build_number
+		bnum = File.read(build_num_file).chomp.to_i if File.exist?(build_num_file)
+		bnum ||= 0
+		bnum
+	end
+
+	def available_build_numbers
+		Dir["#{@log_dir}/build_*.yml"].map do |sfile|
+			if sfile =~ /build_(\d\d\d\d).yml/
+				$1.to_i
+			end
+		end.sort
+	end
+
+	def build
+		bnum = next_build_number
+		info = {}
+		info['build_num'] = bnum
+		info['status'] = 'incomplete'
+		info['name'] = @name
+		info['repository'] = @repository
+		info['revision'] = revision
+		info['start_time'] = Time.now
+		info['status'] = 'building'
+		save_build_info info,bnum
+		target = @rake_target.to_s
+
+		# Go
+		begin
+			saved_wd = pwd
+			cd working_copy
+			IO.popen("rake --nosearch #{target} > #{log_file(bnum)} 2>&1") 
+		rescue => ouch
+			info['status'] = 'error'
+			raise ouch
+		ensure
+			cd saved_wd
+			save_build_info info,bnum
+		end
+
+		# Wait for build
+		Process.wait
+
+		st = 'success'
+		ret = true
+
+		if $?.exitstatus != 0
+			st = 'failure'
+			ret = false
+		end
+		
+		info['status'] = st
+		info['end_time'] = Time.now
+		info['build_time'] = info['end_time'] - info['start_time']
+		save_build_info info,bnum
+		
+    return ret
+	end
+
+  def revision
+    case
+      when perforce? : perforce_revision
+      when git? : git_revision
+      else svn_revision
+    end
+  end
+
+	# zero-padded 4-length number format:
+	def filebase_for_build(num)
+		"#{@log_dir}/build_#{num.to_s.rjust(4,'0')}"
+	end
+
+	# Increment, save and return next build number
+	def next_build_number
+		bnum = current_build_number + 1
+		File.open(build_num_file,"w") do |f| f.write bnum end
+		return bnum
+	end
+
+	def build_num_file
+		"#{@log_dir}/build_num.txt"
+	end
+
+
+	def save_build_info(h, num)
+		File.open summary_file(num),"w"  do |f| 
+			f.write YAML.dump(h) 
+		end
+	end
+
+	def load_build_info(num)
+		info_file = filebase_for_build(num) + ".yml"
+		if File.exist?(summary_file(num))
+			return YAML.load(File.read(summary_file(num)))
+		else 
+			return 'status' => 'non-existant build'
+		end
+	end
+
+	# Execute an svn command
+	# Redirects stdout and stderr to temp files for post-exec use.
+	def exec_command(cmd)
+		todo = %|#{cmd} > "#{svn_out_file}" 2> "#{svn_err_file}"| 
+		IO.popen(todo) 
+    Process.wait
+    status = $?.exitstatus
+		if status != 0	
+			msg = "Total bonage (#{status}) for command '#{todo}'"
+			msg += ":\n#{File.read(svn_err_file)}" if File.exist?(svn_err_file)
+			raise msg
+		end
+		yield svn_out_file if block_given?
+	end
+  
+  def exec_command_and_return_output(command)
+    output = nil
+    exec_command command do |outfile|
+      output = File.read outfile
+    end
+    output
+  end
+
+	def svn_out_file
+    "#{@log_dir}/last_svn.out"
+	end
+
+	def svn_err_file
+    "#{@log_dir}/last_svn.err"
+	end
+end

Added: grpl/trunk/phone_renewal/continuous_integration/config/environment.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/config/environment.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/config/environment.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,13 @@
+# The path to the root directory of your application.
+APP_ROOT = File.join(File.dirname(__FILE__), '..')
+
+ADDITIONAL_LOAD_PATHS = []
+ADDITIONAL_LOAD_PATHS.concat %w(
+  app 
+	lib
+).map { |dir| "#{APP_ROOT}/#{dir}" }.select { |dir| File.directory?(dir) }
+
+# Prepend to $LOAD_PATH
+ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) }
+
+# Require any additional libraries needed

Added: grpl/trunk/phone_renewal/continuous_integration/config/my_projects.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/config/my_projects.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/config/my_projects.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,6 @@
+builder << Project.new( 
+	:name => 'GRPL Phone Renewal', 
+	:repository => 'svn://svn.grpl.org/mieg/phone_renewal',
+	:working_copy => context.proj_dir('phone_renewal'),
+	:log_dir => context.log_dir('phone_renewal')
+)

Added: grpl/trunk/phone_renewal/continuous_integration/lib/constructor.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/lib/constructor.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/lib/constructor.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,130 @@
+class Class
+  #
+  # Declarative means to define object properties by passing a hash 
+  # to the constructor, which will set the corresponding ivars.
+  # Eg,
+  #  class Horse
+  #    constructor :name, :breed, :weight
+  #  end
+  #  Horse.new :name => 'Ed', :breed => 'Mustang', :weight => 342
+  #
+  # By default the ivars do not get accessors defined.
+  # But you can get them auto-made if you want:
+  #  class Horse
+  #    constructor :name, :breed, :weight, :accessors => true
+  #  end
+  #  ...
+  #  puts my_horse.weight
+  # 
+  # You can enforce strict argument checking with :strict option.
+  # This means that the constructor will raise an error if you pass
+  # more or fewer arguments than declared.
+  # Eg,
+  #  class Donkey
+  #    constructor :age, :odor, :strict => true
+  #  end
+  # ... this forces you to pass both an age and odor key to the Donkey constructor.
+  #
+  def constructor(*attrs)
+    # Look for embedded options in the listing:
+    opts = attrs.find { |a| a.kind_of?(Hash) and attrs.delete(a) } 
+    do_acc = opts.nil? ? false : opts[:accessors] == true
+    require_args = opts.nil? ? false : opts[:strict] == true
+    super_args = opts.nil? ? nil : opts[:super]
+
+    # Incorporate superclass's constructor keys, if our superclass
+    if superclass.constructor_keys
+      attrs = [attrs,superclass.constructor_keys].flatten
+    end
+    # Generate ivar assigner code lines
+    assigns = ''
+    attrs.each do |k|
+      assigns += "@#{k.to_s} = args[:#{k.to_s}]\n"
+    end 
+
+    # If accessors option is on, declare accessors for the attributes:
+    if do_acc
+      self.class_eval "attr_accessor " + attrs.map {|x| ":#{x.to_s}"}.join(',')
+    end
+
+    # If user supplied super-constructor hints:
+    super_call = ''
+    if super_args
+      list = super_args.map do |a|
+        case a
+        when String
+          %|"#{a}"|
+        when Symbol
+          %|:#{a}|
+        end
+      end
+      super_call  = %|super(#{list.join(',')})|
+    end
+
+    # If strict is on, define the constructor argument validator method,
+    # and setup the initializer to invoke the validator method.
+    # Otherwise, insert lax code into the initializer.
+    validation_code = "return if args.nil?"
+    if require_args
+      self.class_eval do 
+        def _validate_constructor_args(args)
+          # First, make sure we've got args of some kind
+          unless args and args.keys and args.keys.size > 0 
+            raise ConstructorArgumentError.new(self.class.constructor_keys)
+          end
+          # Scan for missing keys in the argument hash
+          a_keys = args.keys
+          missing = []
+          self.class.constructor_keys.each do |ck|
+            unless a_keys.member?(ck)
+              missing << ck
+            end
+            a_keys.delete(ck) # Delete inbound keys as we address them
+          end
+          if missing.size > 0 || a_keys.size > 0
+            raise ConstructorArgumentError.new(missing,a_keys)
+          end
+        end
+      end
+      # Setup the code to insert into the initializer:
+      validation_code = "_validate_constructor_args args "
+    end
+
+    # Generate the initializer code
+    self.class_eval %{
+      def initialize(args=nil)
+        #{super_call}
+        #{validation_code}
+        #{assigns}
+        setup if respond_to?(:setup)
+      end
+    }
+
+    # Remember our constructor keys
+    @_ctor_keys = attrs
+  end
+
+  # Access the constructor keys for this class
+  def constructor_keys; @_ctor_keys; end
+end
+
+# Fancy validation exception, based on missing and extraneous keys.
+class ConstructorArgumentError < RuntimeError
+  def initialize(missing,rejected=[])
+    err_msg = ''
+    if missing.size > 0
+      err_msg = "Missing constructor args [#{missing.join(',')}]"
+    end
+    if rejected.size > 0
+      # Some inbound keys were not addressed earlier; this means they're unwanted
+      if err_msg
+        err_msg << "; " # Appending to earlier message about missing items
+      else
+        err_msg = ''
+      end
+      # Enumerate the rejected key names
+      err_msg << "Rejected constructor args [#{rejected.join(',')}]"
+    end
+    super err_msg
+  end
+end

Added: grpl/trunk/phone_renewal/continuous_integration/lib/nohup.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/lib/nohup.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/lib/nohup.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,63 @@
+#
+# nohup.rb
+# 
+# Convenience for creating scripts that want to TSR.
+# Invoke nohup with a block (and some optional arguments)
+# and your code will execute in a nohup'd process.
+# All stdout/stderr output will be redirecte to a log.
+# The PID of your script will be stored in a file.  (This file is removed at exit.)
+#
+if ARGV[0] == '--doing-nohup'
+	ARGV.shift
+	$nohupping = true
+end
+
+def log_it(msg)
+	puts "[#{Time.now}] #{msg}"
+end
+
+def nohup(options={})
+	# First, let's avoid complications.  nohup is only going to work on linux and osx
+	case RUBY_PLATFORM
+	when /(linux|darwin)/
+		# Who is being run? (The program name typed by the user at the prompt)
+		target = $0
+
+		if $nohupping
+			# Write PID to file
+			pid_file = File.expand_path "#{target}.pid"
+			File.open(pid_file,"w") do |f|
+				puts "WRITING TO PID FILE #{$$} > #{pid_file}"
+				f.write $$.to_s
+			end
+			
+			begin
+				# GO!
+				log_it "nohup START for #{target} with PID #{$$}"
+				yield
+
+			rescue Exception => e
+				# Don't let the runtime get this exception, it'll harm our log output:
+				s = e.backtrace.shift + ": #{e.message} (#{e.class.name})"
+				s << "\n" + e.backtrace.map {|m| "  from #{m}"}.join("\n")
+				log_it s
+			ensure
+				# Delete PID file
+				require 'fileutils'
+				FileUtils.rm pid_file
+				log_it "nohup DONE for #{target} with PID #{$$}"
+			end
+
+		else
+			# We're the first execution -- re-execute ourselves using nohup:
+			log = File.expand_path "#{target}.nohup.out"	
+			log_setup = ">> #{log} 2> #{log}" if log
+			cmd = "nohup ruby #{target} --doing-nohup #{ARGV.join(' ')} #{log_setup} &"
+			exec cmd
+		end
+	when /win/
+		yield
+	else
+		raise 'unsupported platform'
+	end
+end

Added: grpl/trunk/phone_renewal/continuous_integration/lib/platform.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/lib/platform.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/lib/platform.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,130 @@
+#
+# platform.rb: naive platform detection for Ruby
+# author: Matt Mower <self at mattmower.com>
+#
+
+# == Platform
+#
+# Platform is a simple module which parses the Ruby constant
+# RUBY_PLATFORM and works out the OS, it's implementation,
+# and the architecture it's running on.
+#
+# The motivation for writing this was coming across a case where
+#
+# +if RUBY_PLATFORM =~ /win/+
+#
+# didn't behave as expected (i.e. on powerpc-darwin-8.1.0)
+#
+# It is hoped that providing a library for parsing the platform
+# means that we can cover all the cases and have something which
+# works reliably 99% of the time.
+#
+# Please report any anomalies or new combinations to the author(s).
+#
+# == Use
+#
+# require "platform"
+#
+# defines
+#
+# Platform::OS (:unix,:win32,:vms,:os2,:unknown)
+# Platform::IMPL (:macosx,:linux,:mswin,:irix,:solaris,:vms,:bccwin,:wince,:os2,:unknown)
+# Platform::ARCH (:i86,:ia64,:powerpc,:alpha,:sparc,:mips,:unknown)
+#
+# if an unknown configuration is encountered any (or all) of
+# these constant may have the value :unknown.
+#
+# To display the combination for your setup run
+#
+# ruby platform.rb
+#
+# == Credits
+#
+# Apart from the initial author Matt Mower, the following authors
+# have participated in making this happen: 
+#  
+#  * Edward Faulkner
+#  * Michael Fellinger
+#  * Robert Klemme
+#  * Hugh Sasse
+#  * Kaspar Schiess 
+#
+# == Release Information
+#
+# This is currently a draft that will be maturing hopefully into a 
+# release. Release form is not yet decided. Send suggestions and bugs
+# to Kaspar Schiess <eule at space dot ch>.  
+#
+module Platform
+
+   if RUBY_PLATFORM =~ /darwin/i
+      OS = :unix
+      IMPL = :macosx
+   elsif RUBY_PLATFORM =~ /linux/i
+      OS = :unix
+      IMPL = :linux
+   elsif RUBY_PLATFORM =~ /freebsd/i
+      OS = :unix
+      IMPL = :freebsd
+   elsif RUBY_PLATFORM =~ /netbsd/i
+      OS = :unix
+      IMPL = :netbsd
+   elsif RUBY_PLATFORM =~ /mswin/i
+      OS = :win32
+      IMPL = :mswin
+   elsif RUBY_PLATFORM =~ /cygwin/i
+      OS = :unix
+      IMPL = :cygwin
+   elsif RUBY_PLATFORM =~ /mingw/i
+      OS = :win32
+      IMPL = :mingw
+   elsif RUBY_PLATFORM =~ /bccwin/i
+      OS = :win32
+      IMPL = :bccwin
+   elsif RUBY_PLATFORM =~ /wince/i
+      OS = :win32
+      IMPL = :wince
+   elsif RUBY_PLATFORM =~ /vms/i
+      OS = :vms
+      IMPL = :vms
+   elsif RUBY_PLATFORM =~ /os2/i
+      OS = :os2
+      IMPL = :os2 # maybe there is some better choice here?
+   elsif RUBY_PLATFORM =~ /solaris/i # tnx to Hugh Sasse
+      OS = :unix
+      IMPL = :solaris
+   elsif RUBY_PLATFORM =~ /irix/i # i.e. mips-irix6.5
+      OS = :unix
+      IMPL = :irix
+   else
+      OS = :unknown
+      IMPL = :unknown
+   end
+
+   # whither AIX, SOLARIS, and the other unixen?
+
+   if RUBY_PLATFORM =~ /(i\d86)/i
+      ARCH = :x86
+   elsif RUBY_PLATFORM =~ /ia64/i
+      ARCH = :ia64
+   elsif RUBY_PLATFORM =~ /powerpc/i
+      ARCH = :powerpc
+   elsif RUBY_PLATFORM =~ /alpha/i
+      ARCH = :alpha
+   elsif RUBY_PLATFORM =~ /sparc/i
+      ARCH = :sparc
+   elsif RUBY_PLATFORM =~ /mips/i
+      ARCH = :mips # is actually a Silicon Graphics Indigo. How should that be represented ? 
+   else
+      ARCH = :unknown
+   end
+
+   # What about AMD, Turion, Motorola, etc..?
+
+end
+
+if __FILE__ == $0
+   puts "Platform OS=#{Platform::OS}, IMPL=#{Platform::IMPL}, ARCH=#{Platform::ARCH}"
+end
+
+

Added: grpl/trunk/phone_renewal/continuous_integration/lib/service_installer.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/lib/service_installer.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/lib/service_installer.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,26 @@
+class ServiceInstaller
+	def install_macosx_service
+		raise "Not implemented"
+	end
+
+	def remove_macosx_service
+		raise "Not implemented"
+	end
+
+	def install_linux_service
+		raise "Not implemented"
+	end
+
+	def remove_linux_service
+		raise "Not implemented"
+	end
+
+	def install_mswin_service
+		raise "Not implemented"
+	end
+
+	def remove_mswin_service
+		raise "Not implemented"
+	end
+
+end

Added: grpl/trunk/phone_renewal/continuous_integration/lib/tasks/osx_remove_startup_item.rake
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/lib/tasks/osx_remove_startup_item.rake	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/lib/tasks/osx_remove_startup_item.rake	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,19 @@
+namespace :dci do
+namespace :osx do
+
+  desc "REMOVE DCI Server StartupItem from /Library/StartupItems (for OS X)"
+  task :remove_startup_item do
+
+    # Paths and filenames:
+    dci_si_dir = "/Library/StartupItems/DciServer"
+    script_file = "#{dci_si_dir}/DciServer"
+    plist_file = "#{dci_si_dir}/StartupParameters.plist"
+
+    # Make the directory
+    FileUtils::Verbose.rm script_file
+    FileUtils::Verbose.rm plist_file
+    FileUtils::Verbose.rmdir dci_si_dir
+
+  end
+end # close osx namespace
+end # close dci namespace

Added: grpl/trunk/phone_renewal/continuous_integration/lib/tasks/osx_startup_item.rake
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/lib/tasks/osx_startup_item.rake	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/lib/tasks/osx_startup_item.rake	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,73 @@
+namespace :dci do
+namespace :osx do
+
+  desc "Install DCI Server StartupItem in /Library/StartupItems (for OS X)"
+  task :startup_item do
+
+    script_data = <<END_OF_SCRIPT
+#!/bin/sh
+
+##
+# DciServer starter
+##
+
+. /etc/rc.common
+
+#DCI_SERVER=#{File.expand_path("/Users/xrbuild/svn/dci_server")}
+
+StartService ()
+{
+  cd $DCI_SERVER
+  script/server
+}
+
+StopService ()
+{
+  cd $DCI_SERVER
+  script/stop_server
+}
+
+RestartService ()
+{
+  cd $DCI_SERVER
+  script/stop_server
+  script/server
+}
+
+RunService "$1"
+END_OF_SCRIPT
+
+    plist_data = <<END_OF_PLIST
+{
+  Description     = "Daves Continuous Integration Server";
+  Provides        = ("DCI Server");
+  OrderPreference = "None";
+}
+END_OF_PLIST
+
+    # Paths and filenames:
+    dci_si_dir = "/Library/StartupItems/DciServer"
+    script_file = "#{dci_si_dir}/DciServer"
+    plist_file = "#{dci_si_dir}/StartupParameters.plist"
+
+    # Make the directory
+    FileUtils::Verbose.mkdir_p dci_si_dir
+
+    # Write the init script
+    File.open(script_file,"w") do |f|
+      f.write script_data
+    end
+
+    # Write the plist config file
+    File.open(plist_file,"w") do |f|
+      f.write plist_data
+    end
+
+    # Fix ownership and perms
+    sh "chown -R root:wheel #{dci_si_dir}"
+    sh "chmod 755 #{dci_si_dir}"
+    sh "chmod 755 #{script_file}"
+    sh "chmod 644 #{plist_file}"
+  end
+end # close osx namespace
+end # close dci namespace

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/stop_web
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/stop_web	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/stop_web	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,13 @@
+#!/usr/bin/ruby
+
+
+pid_file = "#{File.dirname(__FILE__)}/web.pid"
+
+if File.exists?(pid_file) 
+	pid = File.read(pid_file).strip
+	begin
+		`kill -s int #{pid}`
+	rescue => oops
+		puts oops
+	end
+end


Property changes on: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/stop_web
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,12 @@
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../lib/nohup.rb"
+
+nohup do 
+	# Go to the program directory and load the web server
+	dir = File.dirname(__FILE__) + "/web_server"
+	Dir.chdir dir
+	load 'web_server.rb'
+	$DciHost = ARGV.shift
+	launch_mini_server
+end


Property changes on: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/images/logo16.ico
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/images/logo16.ico
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/images/logo64.png
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/images/logo64.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/index.rhtml
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/index.rhtml	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/index.rhtml	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,23 @@
+<h2>Projects</h2>
+<table class="projects">
+  <tr>
+    <th>Project</th>
+    <th>Status</th>
+    <th>Build #</th>
+    <th>Last Build/Test Run</th>
+    <th>Action</th>
+  </tr>
+<% @project_names.each do |proj| %>
+  <tr>
+  <td class="name"><a href="/view_build/<%=proj%>/current"><%= proj %></a></td>
+  <td class="status<%=@infos[proj]['status']%>"><%= @infos[proj]['status'] %></td>
+  <td class="build"><%= @infos[proj]['build_num'] %></td>
+  <%
+    @timespan = "not done"
+    @timespan = format("%.1f", at infos[proj]['build_time'] / 60.0) + " mins" if @infos[proj]['build_time']
+  %>
+  <td class="time"><%= @infos[proj]['start_time'] %> (<%= @timespan %>)</td>
+  <td class="action"><a href="/force_build/<%=proj%>">Force Build</a></td>
+  </tr>
+<% end %>
+</table>

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/layout.rhtml
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/layout.rhtml	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/layout.rhtml	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,56 @@
+<html>
+<head>
+<title>DCI Monitor</title>
+<% if @refresh %>
+	<meta http-equiv="refresh" content="5" /\>
+<% end %>
+<style>
+body {
+  font: normal 10pt verdana;
+}
+.footer {
+  font-style: italic;
+	font-size: 8pt;
+}
+a.headerlink {
+  text-decoration: none;
+  color: black;
+}
+table.projects {
+  width: 80%;
+}
+table.projects td.statusfailure {
+  color: red;
+  font-weight: bold;
+}
+table.projects td.statussuccess {
+  color: green;
+}
+table.projects td.time, table.projects td.build
+{
+  color: grey;
+  font-size: 12;
+}
+table.projects th
+{
+  text-align: left;
+  color: white; background-color: black;
+  font: normal 10pt verdana;
+}
+</style>
+</head>
+<body>
+<h1><img border="0" src="/images/logo64.png"><a href="/index" class="headerlink">Server Monitor: <small><%= dci_host %></small></a></h1>
+<%= @main_content  %>
+<hr>
+<div class="footer" style="float: left;">
+	<%= Time.now %>
+</div>
+<div class="footer" style="float: right;">
+	Projects on <%= dci_host %>:<%= dci_port %>
+	<br>
+	Webapp on <%= hostname %>
+</div>
+</body>
+</html>
+

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/log
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/log	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/log	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1 @@
+ADDING ROOT images


Property changes on: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/log
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/mini_server.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/mini_server.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/mini_server.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,426 @@
+require 'webrick'
+require 'erb'
+
+#
+# mini_server.rb
+#
+# Quick-n-dirty framework for writing standalone webapps in the fastest
+# possible way.
+# 
+# 
+
+class Framework
+	# Initialize the MiniServer framework with a server factory,
+	# which is an object that creates new instances of your MiniServer
+	# subclass via #create_instance
+  def initialize(server_factory)
+    @server_factory = server_factory
+		@global_session = { :flash => Flash.new }
+  end
+
+	# Start a WEBrick server and mount /
+	# This method creates a new instance of your miniserver
+	# with each requst.
+  def launch
+    @s = WEBrick::HTTPServer.new( :Port => 4444 )
+		# Use favicon only if user has specified
+		@s.mount_proc "/favicon.ico" do |req,res|
+			fname = Framework[:favicon]
+			if fname
+				type = 'ico'
+				if fname =~ /\.(\w+)$/
+					type = $1
+				end
+				File.open(File.dirname(__FILE__) + "/" + fname,'rb') do |f|
+					res['content-type'] = "image/#{type}"
+					res.body = f.read
+				end
+			end
+		end
+		# User-configurable file serving roots
+		Framework[:serve_files].each do |rel_path|
+			File.open("log","w") do |f| f.puts "ADDING ROOT #{rel_path}" end
+			rel_path = rel_path.to_s
+			rel_path.gsub!(/^[\/\.]*/,'')
+			@s.mount "/#{rel_path}", WEBrick::HTTPServlet::FileHandler, File.dirname(__FILE__)+'/'+rel_path
+		end if Framework[:serve_files]
+
+    @s.mount_proc '/' do |req,res|
+			# Reload the server code
+      @mini_server = @server_factory.create_instance
+
+      res['content-type'] = nil
+      res.body = nil
+
+			# Break the request URI path on '/', pop the first item 
+      path_elements = req.path.split(/\//)
+      path_elements.shift
+      action = path_elements.shift
+      unless action and @mini_server.respond_to?(action)
+        action = "index"
+      end
+
+			# Setup the mini server instance prior to invoking the action
+      @mini_server.setup
+      @mini_server.request = req
+      @mini_server.response = res
+      @mini_server.session = @global_session
+      @mini_server.path_elements = path_elements
+
+      catch :done do 
+			  # Execute 'before' filters
+				@mini_server.class.before_filters.each do |filt|
+					# only if the current action is not excluded from the filter def:
+					unless filt.except?(action)
+						@mini_server.send filt.method
+					end
+				end
+				# Now, invoke the action!
+				@mini_server.send action
+      end
+			# Render the data from the action into its ERB template
+			# (unless we've already created output content)
+      unless @mini_server.output
+        catch :done do
+          @mini_server.render(action)
+        end
+      end
+        
+			# Set content type if it hasn't been set 
+      res['content-type'] ||= "text/html"
+			# Set the body
+      res.body ||= @mini_server.output
+
+      @mini_server.reset
+			# Make sure old flash vars get removed, and recent ones get aged
+			@global_session[:flash].age_and_purge 
+    end
+
+		# Let 'er rip
+
+		launch_browser if Framework[:launch_browser]
+    @s.start
+	end
+
+	def self.[](key)
+		@@framework_options ||= {}
+		@@framework_options[key.to_sym]
+	end
+	def self.[]=(key,val)
+		@@framework_options ||= {}
+		@@framework_options[key.to_sym] = val
+	end
+
+	def launch_browser
+		Thread.new do 
+			sleep 1
+			# Fire up the browser
+			case RUBY_PLATFORM
+				when /win/ then :windows
+					require 'win32ole'
+					s = WIN32OLE.new("Shell.Application")
+					r = s.open("http://localhost:4444")
+				when /linux/ then :linux
+				when /darwin/ then :osx
+			end
+		end
+  end
+
+  def shutdown
+    @s.shutdown
+  end
+
+	# Provide one-hop-lifespan variable storage.
+	# Like a short-lived session.  Entries will be auto-deleted
+	# at the end of the next request.
+	# Useful for setting a variable you want to finish using after
+	# a redirect.
+	class Flash
+		Entry = Struct.new('Entry',:key,:value,:age)
+
+		def initialize
+			@vars = {}
+		end
+
+		def []=(k,v)
+			entry = Entry.new(k,v,0)
+			@vars[k] = entry
+		end
+
+		def [](k)
+			@vars[k].value if @vars[k]
+		end
+
+		def age_and_purge
+			@vars.values.each do |ent|
+				ent.age += 1
+				@vars.delete ent.key if ent.age > 1
+			end
+		end
+	end
+
+end
+
+class MiniServer
+	include ERB::Util
+
+  attr_accessor :request, :response, :session, :path_elements
+  attr_accessor :output
+
+  @@layout_sym = :layout
+	@@user_class = nil
+	@@user_src_file = nil
+
+	# Detect the creation of a subclass and capture
+	# its class and filename (for subsequent reloading).
+	# It is expected that in one process there should be only
+	# one MiniServer subclass; as such, the class and its filename
+	# are stored as singletons @@user_class and @@user_src_file in this class.
+  def self.inherited(c)
+    @@user_class = c
+		# Use the call stack text to determine the source file 
+		# where resides the subclass definition.
+		file = ''
+    pieces = caller[0].split(/:/)
+		pieces.each_index do |i|
+			case i
+				when pieces.size - 2
+					file += pieces[i]
+				when pieces.size - 1
+				else
+					file += pieces[i] + ":"
+			end
+		end
+    @@user_src_file = file
+  end
+
+	def self.launch_browser(yn=true)
+		Framework[:launch_browser] = yn
+	end
+
+	def self.serve_files_in(*dirs)
+		list = Framework[:serve_files] 
+		list ||= []
+		list += dirs.flatten
+		Framework[:serve_files] = list
+	end
+
+	def self.favicon(relfile)
+		Framework[:favicon] = relfile
+	end
+
+	# Fulfill the 'server factory' requirements of the Framework.
+  def self.create_instance
+    load @@user_src_file if @@user_src_file
+		if @@user_class
+			return @@user_class.new 
+		else
+			# Use the default MiniServer implementation if there is no user subclass
+			return MiniServer.new
+		end
+  end
+
+
+	class BeforeFilter
+		include Comparable
+		attr_reader :method
+		def initialize(mname,options={})
+			@method = mname.to_s
+			@options = options
+		end
+		# Is the given action excepted from the filtering?
+		def except?(action)
+			setting = @options[:except]
+			item = action.to_sym
+			setting == action.to_sym or (setting and setting.kind_of?(Array) and setting.member?(:action.to_sym))
+		end
+
+		def <=>(o)
+			self.method <=> o.method
+		end
+	end
+
+	def self.before_filter(mname, options={})
+		@@before_filters ||= []
+		@@before_filters << BeforeFilter.new(mname,options) unless @@before_filters.find { |x| x.method == mname.to_s }
+	end
+
+	def self.before_filters
+		@@before_filters ||= []
+	end
+
+	# Called by the framework before action is invoked.
+	# Sets the default layout.
+  def setup
+    @layout_name = self.class.layout
+  end
+
+
+  def self.layout(sym=nil)
+    @@layout_sym = sym unless sym.nil?
+    @@layout_sym
+  end
+
+	# Set the default layout back to 'layout'
+  def reset
+    @@layout_sym = :layout
+  end
+
+	# Set/get the current layout
+  def layout(layout_name)
+    @layout_name = layout_name
+  end
+
+	# Get the layout template as an ERB.  Default is 'layout.rhtml'.
+	# If the default or currently-set layout is missing,
+	# a minimal HTML document wrapper is returned.
+  def layout_template
+    unless @layout_name.nil?
+      tname = template_filename(@layout_name)
+      if File.exist?(tname)
+        return ERB.new(File.read(tname))
+      else
+        puts "MiniServer layout FAILED: no such file '#{tname}'"
+      end
+    end
+    return ERB.new(%|<html><body><%= @main_content %></body></html>|)
+  end
+
+	# Correct the given string to a template filename
+  def template_filename(str)
+		str = str.to_s
+    str += '.rhtml' unless str =~ /\.[^\.]+$/
+    str
+  end
+
+	# Load and process the ERB template for the given filename.
+	# Then wrap the result within the current 'layout'.
+  def render(filename)
+    filename = template_filename(filename)
+    if File.exist?(filename)
+			# Found the template, do the thing...
+      erb = ERB.new(File.read(filename))
+      @main_content = erb.result(binding)
+    else
+			# Ooop
+      @main_content = %|<h1>Error: No template '#{filename}'</h1>|
+    end
+    @output = layout_template.result(binding)
+    throw :done
+  end
+
+	# Programmatically push a data blob out to the client.
+	# No more code inside the current action will be executed.
+  def send_data(data, content_type=nil)
+		response['content-type'] = content_type if content_type
+    @output = data
+    throw :done
+  end
+
+	# HTTP redirect.  Execution of the current action ceases.
+	def redirect(action)
+		response.set_redirect WEBrick::HTTPStatus::Found, "/#{action.to_s}"
+		throw :done
+	end
+	
+	# Access the current HTTP request paramters	
+	def params
+		@request.query
+	end
+
+	# Access the cookies using hash-like syntax
+	def cookies
+		CookieWrapper.new(request,response)
+	end
+
+	# Provide hash-like syntax around the normal WEBrick cookie API
+	class CookieWrapper
+		def initialize(req,res)
+			@request = req
+			@response = res
+		end
+		def []=(k,v)
+			@response.cookies << WEBrick::Cookie.new(k.to_s,v)
+		end
+
+		def [](k)
+			ck = @request.cookies.find do |c| c.name == k.to_s end
+			if ck
+				return ck.value
+			else
+				return nil
+			end
+		end
+	end
+
+	# Access the flash
+	def flash
+		session[:flash]
+	end
+
+	# Log a message
+	def log(msg)
+		puts "[#{Time.now}] #{msg}"
+	end
+
+	# Default index
+  def index 
+    miniserver_help
+  end
+
+  def miniserver_help
+    send_data %|<html><head><title>Welcome to MiniServer</title></head>
+    <body><h1>Welcome to MiniServer</h1>
+    <p>
+    <code>mini_server.rb<code> is a mini-framework for chucking together the
+    quickest, dirtiest webapps ever.
+    <p>
+<pre>
+require 'mini_server'
+
+class RealQuickServer &lt; MiniServer
+  def index
+  end
+
+  def another_url
+  end
+end
+</pre>
+    <p>
+    That's all; magic <code>at_exit</code> will detect your class and launch it 
+    in the framework on port 4444.
+    <p>
+    By default, the framework will invoke the method that corresponds to the first
+    step in the request path.  Output is generated by invoking ERB against the 
+    template file that matches the name of the method.  Eg, <code>index.rhtml</code>
+    or <code>another_url.rhtml</code>.  The template is invoked with a binding to the
+    current instance of your class so you get all your instance vars.
+    <p>
+    You can select a different template by invoking <code>render :some_other_file</code>.
+    <p>
+    Furthermore, you get a layout.
+    The layout template is <code>layout.rhtml</code> by default but this can be 
+    configured at the class and method levels using <code>layout :some_layout</code>.
+    <p>
+    Hitting <code>http://localhost:4444/index</code> and
+    <code>http://localhost:4444/anoter_url</code> will invoke the respective
+    instance methods in your server class.  
+    </body></html>
+    |
+  end
+end
+
+def launch_mini_server
+	return if $FW
+  $FW = Framework.new(MiniServer)
+  trap("INT") do 
+    $FW.shutdown 
+  end
+  $FW.launch
+end
+
+# Autolaunch the server
+at_exit do 
+  launch_mini_server
+end
+

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/project.rhtml
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/project.rhtml	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/project.rhtml	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,7 @@
+(<a href="/index">Back</a>)
+<h2><%= @project_name %></h2> 
+<h3>Status:</h3>
+<pre>
+<%= @status %>
+</pre>
+<a href="/view_log/<%= @project_name %>/current">Latest Log</a>

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/view_build.rhtml
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/view_build.rhtml	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/view_build.rhtml	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,55 @@
+<%
+def toplink(title)
+  %|<div class="subheader"><a href="#top">#{title}</a></div>|
+end
+%>
+<style> 
+.subheader {
+  font: bold 12pt verdana;
+}
+.subheader a {
+  text-decoration: none;
+  color: black;
+}
+
+.success, .failure, .building {
+	font: bold 12pt verdana;
+  color: white;
+}
+.success { 
+  background-color: green;
+}
+.failure { 
+  background-color: red;
+}
+.building { 
+  background-color: yellow;
+}
+
+</style>
+
+<a name="top"></a> 
+<h2><%= @project_name %>: <span class="<%=@pass_fail%>"><%=@pass_fail%></span></h2>
+<h3>Build <%= @build_num %> <%= '(Current)' if @current %></h3> 
+<a href="#status">Status</a> | <a href="#build">Output</a> | <a href="#svn">SVN</a>
+<p class="allbuildnums">Build #
+<% @all_build_nums.each do |bnum| %>
+  <a href="/view_build/<%=@project_name%>/<%=bnum%>"><%=bnum%></a>
+<% end %>
+</p>
+
+<%= toplink 'Status' %><a name="status"/>
+<pre><%= @status %></pre>
+
+<%= toplink 'Build Output' %><a name="output"/>
+<pre><%= @build_output %></pre>
+
+<% if @svn_output %><a name="svn"/>
+	<%= toplink 'SVN Output' %>
+	<pre><%= @svn_output %></pre>
+<% end %>
+
+<% if @svn_error %>
+	<%= toplink 'SVN Error' %>
+	<pre><%= @svn_error %></pre>
+<% end %>

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/view_server_log.rhtml
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/view_server_log.rhtml	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/view_server_log.rhtml	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,4 @@
+<h2>Server Log</h2> 
+<pre>
+<%= @server_log %>
+</pre>

Added: grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/web_server.rb
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/web_server.rb	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/mini_dci_monitor/web_server/web_server.rb	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,90 @@
+require File.dirname(__FILE__) + '/../../config/environment'
+require 'mini_server'
+require 'project'
+require 'builder_client'
+
+class WebServer < MiniServer
+	serve_files_in 'images'
+	favicon 'images/logo16.ico'
+
+	def index
+		@project_names = dci.project_names
+		@infos = {}
+		@refresh = true
+		@project_names.each do |proj|
+			status_text = dci.project_status(proj)
+			@infos[proj] = YAML.load(status_text) if status_text
+			@infos[proj] ||= {} # in case there is no status text available
+		end
+	end
+
+	# Project overview
+	def project
+		@project_name = shift	
+		@status = dci.project_status(@project_name)
+	end
+
+	def view_server_log
+		@server_log = dci.server_log
+	end
+
+	def view_build
+		@project_name = shift
+		@build_num = shift
+		@all_build_nums = dci.available_build_numbers(@project_name)
+		if @build_num == 'current'
+			# Ask server for current build #
+			@build_num = dci.current_build_number(@project_name)
+			@svn_output = dci.svn_output(@project_name)
+			@svn_error = dci.svn_error(@project_name)
+			@current = true
+		end
+		@status = dci.project_status(@project_name, @build_num)
+		if @status and (@status.kind_of?(String) or @status.kind_of?(IO))
+			status_hash = YAML.load(@status) 
+			@pass_fail = status_hash['status']
+		else
+			@pass_fail = :unknown
+		end
+		begin
+			@build_output = dci.build_output(@project_name, @build_num)
+		rescue Exception => oops
+			log oops
+		end
+		@build_output = "(No build output available)" if @build_output.nil? or @build_output.strip == ''
+	end
+
+	def force_build
+		dci.force_build shift
+		redirect :index
+	end
+
+	private
+	def dci_host
+		return $DciHost if $DciHost
+		# else local host
+		hostname
+	end
+
+	def dci_port
+		42420
+	end
+
+	def hostname
+		`hostname`.split(/\./)[0].chomp
+	end
+
+	def dci_url
+		"druby://#{dci_host}:#{dci_port}"
+	end
+
+	def dci
+		@dci_server ||= DRbObject.new(nil, dci_url)
+		@dci_server.ping
+		@dci_server
+	end
+
+	def shift
+		path_elements.shift
+	end
+end

Added: grpl/trunk/phone_renewal/continuous_integration/script/rebuild_all_now
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/script/rebuild_all_now	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/script/rebuild_all_now	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,9 @@
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + '/../config/environment'
+require 'project'
+require 'builder_client'
+
+url = "druby://localhost:42420"
+client = BuilderClient.new(url)
+client.rebuild_all_successful_projects


Property changes on: grpl/trunk/phone_renewal/continuous_integration/script/rebuild_all_now
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/continuous_integration/script/sample_init_script.sh
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/script/sample_init_script.sh	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/script/sample_init_script.sh	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# /etc/init.d/dci_server
+#
+### BEGIN INIT INFO
+# Provides:     dci_server
+# Required-Start:   $local_fs $remote_fs $network 
+# X-UnitedLinux-Should-Start: $named $time dhcp radiusd
+# Required-Stop:    $local_fs $remote_fs $network
+# X-UnitedLinux-Should-Stop:  
+# Default-Start:    3 5
+# Default-Stop:     0 1 2 6
+# Short-Description:    DCI Server
+# Description:      Start the DCI Server
+### END INIT INFO
+
+#
+# main part 
+#
+case "$1" in
+  start)
+    echo Starting...
+    su - dci -c "__DCI_SERVER_DIR__/script/server"
+    exit $?
+    ;;
+  stop)
+    echo Stopping...
+    su - dci -c "/home/dci/dci_server/script/stop_server"
+    exit $?
+    ;;
+  restart)
+    $0 stop
+    echo Sleeping...
+    sleep 3
+    $0 start
+    ;;
+  *)
+    echo "I don't understand."
+    ;;
+esac
+


Property changes on: grpl/trunk/phone_renewal/continuous_integration/script/sample_init_script.sh
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/continuous_integration/script/server
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/script/server	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/script/server	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,23 @@
+#!/usr/bin/ruby
+# 
+# Launches the DCI server.
+#
+require File.dirname(__FILE__) + '/../config/environment'
+require 'dci_server'
+require 'nohup'
+
+# Locate project config file
+project_config = File.expand_path("#{APP_ROOT}/config/my_projects.rb")
+if ARGV[0] == 'testing'
+	project_config = File.expand_path("#{APP_ROOT}/systest/test_projects/systest_projects.rb")
+end
+
+unless File.exist?(project_config)
+	puts "Can't find project config file '#{project_config}'"
+	exit 1
+end
+
+nohup do 
+	# Launch the server.  This call is synchronous.
+	DciServer.new.launch(project_config)
+end


Property changes on: grpl/trunk/phone_renewal/continuous_integration/script/server
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/continuous_integration/script/stop_server
===================================================================
--- grpl/trunk/phone_renewal/continuous_integration/script/stop_server	                        (rev 0)
+++ grpl/trunk/phone_renewal/continuous_integration/script/stop_server	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,13 @@
+#!/usr/bin/ruby
+
+
+pid_file = "#{File.dirname(__FILE__)}/server.pid"
+
+if File.exists?(pid_file) 
+	pid = File.read(pid_file).strip
+	begin
+		`kill -s int #{pid}`
+	rescue => oops
+		puts oops
+	end
+end


Property changes on: grpl/trunk/phone_renewal/continuous_integration/script/stop_server
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/deploy_app.pl
===================================================================
--- grpl/trunk/phone_renewal/deploy_app.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/deploy_app.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,37 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my $agi_bin = "/var/lib/asterisk/agi-bin";
+my $phone_renewals = "$agi_bin/phone_renewals";
+
+sub sh {
+  my ($cmd) = @_;
+  print "$cmd\n";
+  print `$cmd`;
+}
+
+if (-d $phone_renewals) {
+  print "Phone renewals directory $phone_renewals already exists.\n";
+  print "Ok to replace? [y|N] ";
+  my $answer = <STDIN>;
+  if ($answer =~ /^y/i) {
+    sh("rm -rf $phone_renewals");
+  } else {
+    print "Aborting.\n";
+    exit 1;
+  }
+}
+
+sh "cp eg_auth.pl $agi_bin";
+
+sh "svn export lib $phone_renewals";
+print "Deployed phone renewals application.\n";
+
+my $sounds_dir = "/var/lib/asterisk/sounds/phone_renewals";
+if (not (-d $sounds_dir)) {
+  print "WARNING: I don't see sounds directory at $sounds_dir\n";
+  print "Try using deploy_sounds.pl\n";
+}
+
+exit 0


Property changes on: grpl/trunk/phone_renewal/deploy_app.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/deploy_sounds.pl
===================================================================
--- grpl/trunk/phone_renewal/deploy_sounds.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/deploy_sounds.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,31 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my $sounds_src = "sounds";
+my $sounds_dest = "/var/lib/asterisk/sounds/phone_renewals";
+
+sub sh {
+  my ($cmd) = @_;
+  print "$cmd\n";
+  print `$cmd`;
+}
+
+if (-d $sounds_dest) {
+  print "Sound directory $sounds_dest exists.\n";
+  print "Ok to overwrite? [y|N] ";
+  my $answer = <STDIN>;
+  if ($answer =~ /^y/i) {
+    sh("sudo rm $sounds_dest/*.*");
+  } else {
+    print "Aborting.\n";
+    exit 1;
+  }
+} else {
+  sh("sudo mkdir $sounds_dest");
+}
+
+sh "sudo cp $sounds_src/*.* $sounds_dest/";
+print "Deployed sound files to $sounds_dest\n";
+exit 0
+


Property changes on: grpl/trunk/phone_renewal/deploy_sounds.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/doc/GRPL_Phone_Renewals_Proposal.pdf
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/doc/GRPL_Phone_Renewals_Proposal.pdf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/doc/Telephone_renewal_notes.pdf
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/doc/Telephone_renewal_notes.pdf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/doc/example_dialplan_and_sip_config.txt
===================================================================
--- grpl/trunk/phone_renewal/doc/example_dialplan_and_sip_config.txt	                        (rev 0)
+++ grpl/trunk/phone_renewal/doc/example_dialplan_and_sip_config.txt	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,44 @@
+Sun Apr  5 04:23:39 EDT 2009
+crosby
+
+These are some simple examples I used during development.
+For a softphone, I used X-Lite: 
+
+
+# Sample setup in /etc/asterisk/extensions.conf:
+
+;;
+;; Primary context:
+;;
+
+[phone-renewals] # SIP id 1000
+exten => _X.,1,AGI(phone_renewals/telephone_renewal_menu.agi.pl)
+
+;;
+;; Admin / testing:
+;;
+
+[phone-renewals-admin] # SIP id 2000
+exten => 100,1,AGI(phone_renewals/prompt_manager.agi.pl)
+exten => 200,1,AGI(phone_renewals/test_against_fake_evergreen.pl)
+exten => 300,1,AGI(phone_renewals/telephone_renewal_menu.agi.pl)
+
+
+# Sample SIP phone setup.
+# This is very minimal, but it was all I needed in order to service the X-Lite
+# voip / sip phone:
+[general]
+[1000]
+type=friend
+host=dynamic
+context=phone-renewals
+
+[2000]
+type=friend
+host=dynamic
+context=phone-renewals-admin
+
+[3000]
+type=friend
+host=dynamic
+context=phone-test

Added: grpl/trunk/phone_renewal/doc/project_wiki.html
===================================================================
--- grpl/trunk/phone_renewal/doc/project_wiki.html	                        (rev 0)
+++ grpl/trunk/phone_renewal/doc/project_wiki.html	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,10221 @@
+<!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>
+<script id="versionArea" type="text/javascript">
+//<![CDATA[
+var version = {title: "TiddlyWiki", major: 2, minor: 5, revision: 0, date: new Date("Mar 9, 2009"), extensions: {}};
+//]]>
+</script>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+<meta name="copyright" content="
+TiddlyWiki created by Jeremy Ruston, (jeremy [at] osmosoft [dot] com)
+
+Copyright (c) UnaMesa Association 2004-2009
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright notice, this
+list of conditions and the following disclaimer in the documentation and/or other
+materials provided with the distribution.
+
+Neither the name of the UnaMesa Association nor the names of its contributors may be
+used to endorse or promote products derived from this software without specific
+prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+" />
+<script id="jsheadArea" type="text/javascript">
+//<![CDATA[
+/*
+ * jQuery JavaScript Library v1.3.2
+ * http://jquery.com/
+ *
+ * Copyright (c) 2009 John Resig
+ * Dual licensed under the MIT and GPL licenses.
+ * http://docs.jquery.com/License
+ *
+ * Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009)
+ * Revision: 6246
+ */
+(function(){var l=this,g,y=l.jQuery,p=l.$,o=l.jQuery=l.$=function(E,F){return new o.fn.init(E,F)},D=/^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,f=/^.[^:#\[\.,]*$/;o.fn=o.prototype={init:function(E,H){E=E||document;if(E.nodeType){this[0]=E;this.length=1;this.context=E;return this}if(typeof E==="string"){var G=D.exec(E);if(G&&(G[1]||!H)){if(G[1]){E=o.clean([G[1]],H)}else{var I=document.getElementById(G[3]);if(I&&I.id!=G[3]){return o().find(E)}var F=o(I||[]);F.context=document;F.selector=E;return F}}else{return o(H).find(E)}}else{if(o.isFunction(E)){return o(document).ready(E)}}if(E.selector&&E.context){this.selector=E.selector;this.context=E.context}return this.setArray(o.isArray(E)?E:o.makeArray(E))},selector:"",jquery:"1.3.2",size:function(){return this.length},get:function(E){return E===g?Array.prototype.slice.call(this):this[E]},pushStack:function(F,H,E){var G=o(F);G.prevObject=this;G.context=this.context;if(H==="find"){G.selector=this.selector+(this.selector?" ":"")+E}else{if(H){G.selector=this.selector+"."+H+"("+E+")"}}return G},setArray:function(E){this.length=0;Array.prototype.push.apply(this,E);return this},each:function(F,E){return o.each(this,F,E)},index:function(E){return o.inArray(E&&E.jquery?E[0]:E,this)},attr:function(F,H,G){var E=F;if(typeof F==="string"){if(H===g){return this[0]&&o[G||"attr"](this[0],F)}else{E={};E[F]=H}}return this.each(function(I){for(F in E){o.attr(G?this.style:this,F,o.prop(this,E[F],G,I,F))}})},css:function(E,F){if((E=="width"||E=="height")&&parseFloat(F)<0){F=g}return this.attr(E,F,"curCSS")},text:function(F){if(typeof F!=="object"&&F!=null){return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(F))}var E="";o.each(F||this,function(){o.each(this.childNodes,function(){if(this.nodeType!=8){E+=this.nodeType!=1?this.nodeValue:o.fn.text([this])}})});return E},wrapAll:function(E){if(this[0]){var F=o(E,this[0].ownerDocument).clone();if(this[0].parentNode){F.insertBefore(this[0])}F.map(function(){var G=this;while(G.firstChild){G=G.firstChild}return G}).append(this)}return this},wrapInner:function(E){return this.each(function(){o(this).contents().wrapAll(E)})},wrap:function(E){return this.each(function(){o(this).wrapAll(E)})},append:function(){return this.domManip(arguments,true,function(E){if(this.nodeType==1){this.appendChild(E)}})},prepend:function(){return this.domManip(arguments,true,function(E){if(this.nodeType==1){this.insertBefore(E,this.firstChild)}})},before:function(){return this.domManip(arguments,false,function(E){this.parentNode.insertBefore(E,this)})},after:function(){return this.domManip(arguments,false,function(E){this.parentNode.insertBefore(E,this.nextSibling)})},end:function(){return this.prevObject||o([])},push:[].push,sort:[].sort,splice:[].splice,find:function(E){if(this.length===1){var F=this.pushStack([],"find",E);F.length=0;o.find(E,this[0],F);return F}else{return this.pushStack(o.unique(o.map(this,function(G){return o.find(E,G)})),"find",E)}},clone:function(G){var E=this.map(function(){if(!o.support.noCloneEvent&&!o.isXMLDoc(this)){var I=this.outerHTML;if(!I){var J=this.ownerDocument.createElement("div");J.appendChild(this.cloneNode(true));I=J.innerHTML}return o.clean([I.replace(/ jQuery\d+="(?:\d+|null)"/g,"").replace(/^\s*/,"")])[0]}else{return this.cloneNode(true)}});if(G===true){var H=this.find("*").andSelf(),F=0;E.find("*").andSelf().each(function(){if(this.nodeName!==H[F].nodeName){return}var I=o.data(H[F],"events");for(var K in I){for(var J in I[K]){o.event.add(this,K,I[K][J],I[K][J].data)}}F++})}return E},filter:function(E){return this.pushStack(o.isFunction(E)&&o.grep(this,function(G,F){return E.call(G,F)})||o.multiFilter(E,o.grep(this,function(F){return F.nodeType===1})),"filter",E)},closest:function(E){var G=o.expr.match.POS.test(E)?o(E):null,F=0;return this.map(function(){var H=this;while(H&&H.ownerDocument){if(G?G.index(H)>-1:o(H).is(E)){o.data(H,"closest",F);return H}H=H.parentNode;F++}})},not:function(E){if(typeof E==="string"){if(f.test(E)){return this.pushStack(o.multiFilter(E,this,true),"not",E)}else{E=o.multiFilter(E,this)}}var F=E.length&&E[E.length-1]!==g&&!E.nodeType;return this.filter(function(){return F?o.inArray(this,E)<0:this!=E})},add:function(E){return this.pushStack(o.unique(o.merge(this.get(),typeof E==="string"?o(E):o.makeArray(E))))},is:function(E){return !!E&&o.multiFilter(E,this).length>0},hasClass:function(E){return !!E&&this.is("."+E)},val:function(K){if(K===g){var E=this[0];if(E){if(o.nodeName(E,"option")){return(E.attributes.value||{}).specified?E.value:E.text}if(o.nodeName(E,"select")){var I=E.selectedIndex,L=[],M=E.options,H=E.type=="select-one";if(I<0){return null}for(var F=H?I:0,J=H?I+1:M.length;F<J;F++){var G=M[F];if(G.selected){K=o(G).val();if(H){return K}L.push(K)}}return L}return(E.value||"").replace(/\r/g,"")}return g}if(typeof K==="number"){K+=""}return this.each(function(){if(this.nodeType!=1){return}if(o.isArray(K)&&/radio|checkbox/.test(this.type)){this.checked=(o.inArray(this.value,K)>=0||o.inArray(this.name,K)>=0)}else{if(o.nodeName(this,"select")){var N=o.makeArray(K);o("option",this).each(function(){this.selected=(o.inArray(this.value,N)>=0||o.inArray(this.text,N)>=0)});if(!N.length){this.selectedIndex=-1}}else{this.value=K}}})},html:function(E){return E===g?(this[0]?this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g,""):null):this.empty().append(E)},replaceWith:function(E){return this.after(E).remove()},eq:function(E){return this.slice(E,+E+1)},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments),"slice",Array.prototype.slice.call(arguments).join(","))},map:function(E){return this.pushStack(o.map(this,function(G,F){return E.call(G,F,G)}))},andSelf:function(){return this.add(this.prevObject)},domManip:function(J,M,L){if(this[0]){var I=(this[0].ownerDocument||this[0]).createDocumentFragment(),F=o.clean(J,(this[0].ownerDocument||this[0]),I),H=I.firstChild;if(H){for(var G=0,E=this.length;G<E;G++){L.call(K(this[G],H),this.length>1||G>0?I.cloneNode(true):I)}}if(F){o.each(F,z)}}return this;function K(N,O){return M&&o.nodeName(N,"table")&&o.nodeName(O,"tr")?(N.getElementsByTagName("tbody")[0]||N.appendChild(N.ownerDocument.createElement("tbody"))):N}}};o.fn.init.prototype=o.fn;function z(E,F){if(F.src){o.ajax({url:F.src,async:false,dataType:"script"})}else{o.globalEval(F.text||F.textContent||F.innerHTML||"")}if(F.parentNode){F.parentNode.removeChild(F)}}function e(){return +new Date}o.extend=o.fn.extend=function(){var J=arguments[0]||{},H=1,I=arguments.length,E=false,G;if(typeof J==="boolean"){E=J;J=arguments[1]||{};H=2}if(typeof J!=="object"&&!o.isFunction(J)){J={}}if(I==H){J=this;--H}for(;H<I;H++){if((G=arguments[H])!=null){for(var F in G){var K=J[F],L=G[F];if(J===L){continue}if(E&&L&&typeof L==="object"&&!L.nodeType){J[F]=o.extend(E,K||(L.length!=null?[]:{}),L)}else{if(L!==g){J[F]=L}}}}}return J};var b=/z-?index|font-?weight|opacity|zoom|line-?height/i,q=document.defaultView||{},s=Object.prototype.toString;o.extend({noConflict:function(E){l.$=p;if(E){l.jQuery=y}return o},isFunction:function(E){return s.call(E)==="[object Function]"},isArray:function(E){return s.call(E)==="[object Array]"},isXMLDoc:function(E){return E.nodeType===9&&E.documentElement.nodeName!=="HTML"||!!E.ownerDocument&&o.isXMLDoc(E.ownerDocument)},globalEval:function(G){if(G&&/\S/.test(G)){var F=document.getElementsByTagName("head")[0]||document.documentElement,E=document.createElement("script");E.type="text/javascript";if(o.support.scriptEval){E.appendChild(document.createTextNode(G))}else{E.text=G}F.insertBefore(E,F.firstChild);F.removeChild(E)}},nodeName:function(F,E){return F.nodeName&&F.nodeName.toUpperCase()==E.toUpperCase()},each:function(G,K,F){var E,H=0,I=G.length;if(F){if(I===g){for(E in G){if(K.apply(G[E],F)===false){break}}}else{for(;H<I;){if(K.apply(G[H++],F)===false){break}}}}else{if(I===g){for(E in G){if(K.call(G[E],E,G[E])===false){break}}}else{for(var J=G[0];H<I&&K.call(J,H,J)!==false;J=G[++H]){}}}return G},prop:function(H,I,G,F,E){if(o.isFunction(I)){I=I.call(H,F)}return typeof I==="number"&&G=="curCSS"&&!b.test(E)?I+"px":I},className:{add:function(E,F){o.each((F||"").split(/\s+/),function(G,H){if(E.nodeType==1&&!o.className.has(E.className,H)){E.className+=(E.className?" ":"")+H}})},remove:function(E,F){if(E.nodeType==1){E.className=F!==g?o.grep(E.className.split(/\s+/),function(G){return !o.className.has(F,G)}).join(" "):""}},has:function(F,E){return F&&o.inArray(E,(F.className||F).toString().split(/\s+/))>-1}},swap:function(H,G,I){var E={};for(var F in G){E[F]=H.style[F];H.style[F]=G[F]}I.call(H);for(var F in G){H.style[F]=E[F]}},css:function(H,F,J,E){if(F=="width"||F=="height"){var L,G={position:"absolute",visibility:"hidden",display:"block"},K=F=="width"?["Left","Right"]:["Top","Bottom"];function I(){L=F=="width"?H.offsetWidth:H.offsetHeight;if(E==="border"){return}o.each(K,function(){if(!E){L-=parseFloat(o.curCSS(H,"padding"+this,true))||0}if(E==="margin"){L+=parseFloat(o.curCSS(H,"margin"+this,true))||0}else{L-=parseFloat(o.curCSS(H,"border"+this+"Width",true))||0}})}if(H.offsetWidth!==0){I()}else{o.swap(H,G,I)}return Math.max(0,Math.round(L))}return o.curCSS(H,F,J)},curCSS:function(I,F,G){var L,E=I.style;if(F=="opacity"&&!o.support.opacity){L=o.attr(E,"opacity");return L==""?"1":L}if(F.match(/float/i)){F=w}if(!G&&E&&E[F]){L=E[F]}else{if(q.getComputedStyle){if(F.match(/float/i)){F="float"}F=F.replace(/([A-Z])/g,"-$1").toLowerCase();var M=q.getComputedStyle(I,null);if(M){L=M.getPropertyValue(F)}if(F=="opacity"&&L==""){L="1"}}else{if(I.currentStyle){var J=F.replace(/\-(\w)/g,function(N,O){return O.toUpperCase()});L=I.currentStyle[F]||I.currentStyle[J];if(!/^\d+(px)?$/i.test(L)&&/^\d/.test(L)){var H=E.left,K=I.runtimeStyle.left;I.runtimeStyle.left=I.currentStyle.left;E.left=L||0;L=E.pixelLeft+"px";E.left=H;I.runtimeStyle.left=K}}}}return L},clean:function(F,K,I){K=K||document;if(typeof K.createElement==="undefined"){K=K.ownerDocument||K[0]&&K[0].ownerDocument||document}if(!I&&F.length===1&&typeof F[0]==="string"){var H=/^<(\w+)\s*\/?>$/.exec(F[0]);if(H){return[K.createElement(H[1])]}}var G=[],E=[],L=K.createElement("div");o.each(F,function(P,S){if(typeof S==="number"){S+=""}if(!S){return}if(typeof S==="string"){S=S.replace(/(<(\w+)[^>]*?)\/>/g,function(U,V,T){return T.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?U:V+"></"+T+">"});var O=S.replace(/^\s+/,"").substring(0,10).toLowerCase();var Q=!O.indexOf("<opt")&&[1,"<select multiple='multiple'>","</select>"]||!O.indexOf("<leg")&&[1,"<fieldset>","</fieldset>"]||O.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,"<table>","</table>"]||!O.indexOf("<tr")&&[2,"<table><tbody>","</tbody></table>"]||(!O.indexOf("<td")||!O.indexOf("<th"))&&[3,"<table><tbody><tr>","</tr></tbody></table>"]||!O.indexOf("<col")&&[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"]||!o.support.htmlSerialize&&[1,"div<div>","</div>"]||[0,"",""];L.innerHTML=Q[1]+S+Q[2];while(Q[0]--){L=L.lastChild}if(!o.support.tbody){var R=/<tbody/i.test(S),N=!O.indexOf("<table")&&!R?L.firstChild&&L.firstChild.childNodes:Q[1]=="<table>"&&!R?L.childNodes:[];for(var M=N.length-1;M>=0;--M){if(o.nodeName(N[M],"tbody")&&!N[M].childNodes.length){N[M].parentNode.removeChild(N[M])}}}if(!o.support.leadingWhitespace&&/^\s/.test(S)){L.insertBefore(K.createTextNode(S.match(/^\s*/)[0]),L.firstChild)}S=o.makeArray(L.childNodes)}if(S.nodeType){G.push(S)}else{G=o.merge(G,S)}});if(I){for(var J=0;G[J];J++){if(o.nodeName(G[J],"script")&&(!G[J].type||G[J].type.toLowerCase()==="text/javascript")){E.push(G[J].parentNode?G[J].parentNode.removeChild(G[J]):G[J])}else{if(G[J].nodeType===1){G.splice.apply(G,[J+1,0].concat(o.makeArray(G[J].getElementsByTagName("script"))))}I.appendChild(G[J])}}return E}return G},attr:function(J,G,K){if(!J||J.nodeType==3||J.nodeType==8){return g}var H=!o.isXMLDoc(J),L=K!==g;G=H&&o.props[G]||G;if(J.tagName){var F=/href|src|style/.test(G);if(G=="selected"&&J.parentNode){J.parentNode.selectedIndex}if(G in J&&H&&!F){if(L){if(G=="type"&&o.nodeName(J,"input")&&J.parentNode){throw"type property can't be changed"}J[G]=K}if(o.nodeName(J,"form")&&J.getAttributeNode(G)){return J.getAttributeNode(G).nodeValue}if(G=="tabIndex"){var I=J.getAttributeNode("tabIndex");return I&&I.specified?I.value:J.nodeName.match(/(button|input|object|select|textarea)/i)?0:J.nodeName.match(/^(a|area)$/i)&&J.href?0:g}return J[G]}if(!o.support.style&&H&&G=="style"){return o.attr(J.style,"cssText",K)}if(L){J.setAttribute(G,""+K)}var E=!o.support.hrefNormalized&&H&&F?J.getAttribute(G,2):J.getAttribute(G);return E===null?g:E}if(!o.support.opacity&&G=="opacity"){if(L){J.zoom=1;J.filter=(J.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(K)+""=="NaN"?"":"alpha(opacity="+K*100+")")}return J.filter&&J.filter.indexOf("opacity=")>=0?(parseFloat(J.filter.match(/opacity=([^)]*)/)[1])/100)+"":""}G=G.replace(/-([a-z])/ig,function(M,N){return N.toUpperCase()});if(L){J[G]=K}return J[G]},trim:function(E){return(E||"").replace(/^\s+|\s+$/g,"")},makeArray:function(G){var E=[];if(G!=null){var F=G.length;if(F==null||typeof G==="string"||o.isFunction(G)||G.setInterval){E[0]=G}else{while(F){E[--F]=G[F]}}}return E},inArray:function(G,H){for(var E=0,F=H.length;E<F;E++){if(H[E]===G){return E}}return -1},merge:function(H,E){var F=0,G,I=H.length;if(!o.support.getAll){while((G=E[F++])!=null){if(G.nodeType!=8){H[I++]=G}}}else{while((G=E[F++])!=null){H[I++]=G}}return H},unique:function(K){var F=[],E={};try{for(var G=0,H=K.length;G<H;G++){var J=o.data(K[G]);if(!E[J]){E[J]=true;F.push(K[G])}}}catch(I){F=K}return F},grep:function(F,J,E){var G=[];for(var H=0,I=F.length;H<I;H++){if(!E!=!J(F[H],H)){G.push(F[H])}}return G},map:function(E,J){var F=[];for(var G=0,H=E.length;G<H;G++){var I=J(E[G],G);if(I!=null){F[F.length]=I}}return F.concat.apply([],F)}});var C=navigator.userAgent.toLowerCase();o.browser={version:(C.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[0,"0"])[1],safari:/webkit/.test(C),opera:/opera/.test(C),msie:/msie/.test(C)&&!/opera/.test(C),mozilla:/mozilla/.test(C)&&!/(compatible|webkit)/.test(C)};o.each({parent:function(E){return E.parentNode},parents:function(E){return o.dir(E,"parentNode")},next:function(E){return o.nth(E,2,"nextSibling")},prev:function(E){return o.nth(E,2,"previousSibling")},nextAll:function(E){return o.dir(E,"nextSibling")},prevAll:function(E){return o.dir(E,"previousSibling")},siblings:function(E){return o.sibling(E.parentNode.firstChild,E)},children:function(E){return o.sibling(E.firstChild)},contents:function(E){return o.nodeName(E,"iframe")?E.contentDocument||E.contentWindow.document:o.makeArray(E.childNodes)}},function(E,F){o.fn[E]=function(G){var H=o.map(this,F);if(G&&typeof G=="string"){H=o.multiFilter(G,H)}return this.pushStack(o.unique(H),E,G)}});o.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(E,F){o.fn[E]=function(G){var J=[],L=o(G);for(var K=0,H=L.length;K<H;K++){var I=(K>0?this.clone(true):this).get();o.fn[F].apply(o(L[K]),I);J=J.concat(I)}return this.pushStack(J,E,G)}});o.each({removeAttr:function(E){o.attr(this,E,"");if(this.nodeType==1){this.removeAttribute(E)}},addClass:function(E){o.className.add(this,E)},removeClass:function(E){o.className.remove(this,E)},toggleClass:function(F,E){if(typeof E!=="boolean"){E=!o.className.has(this,F)}o.className[E?"add":"remove"](this,F)},remove:function(E){if(!E||o.filter(E,[this]).length){o("*",this).add([this]).each(function(){o.event.remove(this);o.removeData(this)});if(this.parentNode){this.parentNode.removeChild(this)}}},empty:function(){o(this).children().remove();while(this.firstChild){this.removeChild(this.firstChild)}}},function(E,F){o.fn[E]=function(){return this.each(F,arguments)}});function j(E,F){return E[0]&&parseInt(o.curCSS(E[0],F,true),10)||0}var h="jQuery"+e(),v=0,A={};o.extend({cache:{},data:function(F,E,G){F=F==l?A:F;var H=F[h];if(!H){H=F[h]=++v}if(E&&!o.cache[H]){o.cache[H]={}}if(G!==g){o.cache[H][E]=G}return E?o.cache[H][E]:H},removeData:function(F,E){F=F==l?A:F;var H=F[h];if(E){if(o.cache[H]){delete o.cache[H][E];E="";for(E in o.cache[H]){break}if(!E){o.removeData(F)}}}else{try{delete F[h]}catch(G){if(F.removeAttribute){F.removeAttribute(h)}}delete o.cache[H]}},queue:function(F,E,H){if(F){E=(E||"fx")+"queue";var G=o.data(F,E);if(!G||o.isArray(H)){G=o.data(F,E,o.makeArray(H))}else{if(H){G.push(H)}}}return G},dequeue:function(H,G){var E=o.queue(H,G),F=E.shift();if(!G||G==="fx"){F=E[0]}if(F!==g){F.call(H)}}});o.fn.extend({data:function(E,G){var H=E.split(".");H[1]=H[1]?"."+H[1]:"";if(G===g){var F=this.triggerHandler("getData"+H[1]+"!",[H[0]]);if(F===g&&this.length){F=o.data(this[0],E)}return F===g&&H[1]?this.data(H[0]):F}else{return this.trigger("setData"+H[1]+"!",[H[0],G]).each(function(){o.data(this,E,G)})}},removeData:function(E){return this.each(function(){o.removeData(this,E)})},queue:function(E,F){if(typeof E!=="string"){F=E;E="fx"}if(F===g){return o.queue(this[0],E)}return this.each(function(){var G=o.queue(this,E,F);if(E=="fx"&&G.length==1){G[0].call(this)}})},dequeue:function(E){return this.each(function(){o.dequeue(this,E)})}});
+/*
+ * Sizzle CSS Selector Engine - v0.9.3
+ *  Copyright 2009, The Dojo Foundation
+ *  Released under the MIT, BSD, and GPL Licenses.
+ *  More information: http://sizzlejs.com/
+ */
+(function(){var R=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,L=0,H=Object.prototype.toString;var F=function(Y,U,ab,ac){ab=ab||[];U=U||document;if(U.nodeType!==1&&U.nodeType!==9){return[]}if(!Y||typeof Y!=="string"){return ab}var Z=[],W,af,ai,T,ad,V,X=true;R.lastIndex=0;while((W=R.exec(Y))!==null){Z.push(W[1]);if(W[2]){V=RegExp.rightContext;break}}if(Z.length>1&&M.exec(Y)){if(Z.length===2&&I.relative[Z[0]]){af=J(Z[0]+Z[1],U)}else{af=I.relative[Z[0]]?[U]:F(Z.shift(),U);while(Z.length){Y=Z.shift();if(I.relative[Y]){Y+=Z.shift()}af=J(Y,af)}}}else{var ae=ac?{expr:Z.pop(),set:E(ac)}:F.find(Z.pop(),Z.length===1&&U.parentNode?U.parentNode:U,Q(U));af=F.filter(ae.expr,ae.set);if(Z.length>0){ai=E(af)}else{X=false}while(Z.length){var ah=Z.pop(),ag=ah;if(!I.relative[ah]){ah=""}else{ag=Z.pop()}if(ag==null){ag=U}I.relative[ah](ai,ag,Q(U))}}if(!ai){ai=af}if(!ai){throw"Syntax error, unrecognized expression: "+(ah||Y)}if(H.call(ai)==="[object Array]"){if(!X){ab.push.apply(ab,ai)}else{if(U.nodeType===1){for(var aa=0;ai[aa]!=null;aa++){if(ai[aa]&&(ai[aa]===true||ai[aa].nodeType===1&&K(U,ai[aa]))){ab.push(af[aa])}}}else{for(var aa=0;ai[aa]!=null;aa++){if(ai[aa]&&ai[aa].nodeType===1){ab.push(af[aa])}}}}}else{E(ai,ab)}if(V){F(V,U,ab,ac);if(G){hasDuplicate=false;ab.sort(G);if(hasDuplicate){for(var aa=1;aa<ab.length;aa++){if(ab[aa]===ab[aa-1]){ab.splice(aa--,1)}}}}}return ab};F.matches=function(T,U){return F(T,null,null,U)};F.find=function(aa,T,ab){var Z,X;if(!aa){return[]}for(var W=0,V=I.order.length;W<V;W++){var Y=I.order[W],X;if((X=I.match[Y].exec(aa))){var U=RegExp.leftContext;if(U.substr(U.length-1)!=="\\"){X[1]=(X[1]||"").replace(/\\/g,"");Z=I.find[Y](X,T,ab);if(Z!=null){aa=aa.replace(I.match[Y],"");break}}}}if(!Z){Z=T.getElementsByTagName("*")}return{set:Z,expr:aa}};F.filter=function(ad,ac,ag,W){var V=ad,ai=[],aa=ac,Y,T,Z=ac&&ac[0]&&Q(ac[0]);while(ad&&ac.length){for(var ab in I.filter){if((Y=I.match[ab].exec(ad))!=null){var U=I.filter[ab],ah,af;T=false;if(aa==ai){ai=[]}if(I.preFilter[ab]){Y=I.preFilter[ab](Y,aa,ag,ai,W,Z);if(!Y){T=ah=true}else{if(Y===true){continue}}}if(Y){for(var X=0;(af=aa[X])!=null;X++){if(af){ah=U(af,Y,X,aa);var ae=W^!!ah;if(ag&&ah!=null){if(ae){T=true}else{aa[X]=false}}else{if(ae){ai.push(af);T=true}}}}}if(ah!==g){if(!ag){aa=ai}ad=ad.replace(I.match[ab],"");if(!T){return[]}break}}}if(ad==V){if(T==null){throw"Syntax error, unrecognized expression: "+ad}else{break}}V=ad}return aa};var I=F.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF_-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(T){return T.getAttribute("href")}},relative:{"+":function(aa,T,Z){var X=typeof T==="string",ab=X&&!/\W/.test(T),Y=X&&!ab;if(ab&&!Z){T=T.toUpperCase()}for(var W=0,V=aa.length,U;W<V;W++){if((U=aa[W])){while((U=U.previousSibling)&&U.nodeType!==1){}aa[W]=Y||U&&U.nodeName===T?U||false:U===T}}if(Y){F.filter(T,aa,true)}},">":function(Z,U,aa){var X=typeof U==="string";if(X&&!/\W/.test(U)){U=aa?U:U.toUpperCase();for(var V=0,T=Z.length;V<T;V++){var Y=Z[V];if(Y){var W=Y.parentNode;Z[V]=W.nodeName===U?W:false}}}else{for(var V=0,T=Z.length;V<T;V++){var Y=Z[V];if(Y){Z[V]=X?Y.parentNode:Y.parentNode===U}}if(X){F.filter(U,Z,true)}}},"":function(W,U,Y){var V=L++,T=S;if(!U.match(/\W/)){var X=U=Y?U:U.toUpperCase();T=P}T("parentNode",U,V,W,X,Y)},"~":function(W,U,Y){var V=L++,T=S;if(typeof U==="string"&&!U.match(/\W/)){var X=U=Y?U:U.toUpperCase();T=P}T("previousSibling",U,V,W,X,Y)}},find:{ID:function(U,V,W){if(typeof V.getElementById!=="undefined"&&!W){var T=V.getElementById(U[1]);return T?[T]:[]}},NAME:function(V,Y,Z){if(typeof Y.getElementsByName!=="undefined"){var U=[],X=Y.getElementsByName(V[1]);for(var W=0,T=X.length;W<T;W++){if(X[W].getAttribute("name")===V[1]){U.push(X[W])}}return U.length===0?null:U}},TAG:function(T,U){return U.getElementsByTagName(T[1])}},preFilter:{CLASS:function(W,U,V,T,Z,aa){W=" "+W[1].replace(/\\/g,"")+" ";if(aa){return W}for(var X=0,Y;(Y=U[X])!=null;X++){if(Y){if(Z^(Y.className&&(" "+Y.className+" ").indexOf(W)>=0)){if(!V){T.push(Y)}}else{if(V){U[X]=false}}}}return false},ID:function(T){return T[1].replace(/\\/g,"")},TAG:function(U,T){for(var V=0;T[V]===false;V++){}return T[V]&&Q(T[V])?U[1]:U[1].toUpperCase()},CHILD:function(T){if(T[1]=="nth"){var U=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(T[2]=="even"&&"2n"||T[2]=="odd"&&"2n+1"||!/\D/.test(T[2])&&"0n+"+T[2]||T[2]);T[2]=(U[1]+(U[2]||1))-0;T[3]=U[3]-0}T[0]=L++;return T},ATTR:function(X,U,V,T,Y,Z){var W=X[1].replace(/\\/g,"");if(!Z&&I.attrMap[W]){X[1]=I.attrMap[W]}if(X[2]==="~="){X[4]=" "+X[4]+" "}return X},PSEUDO:function(X,U,V,T,Y){if(X[1]==="not"){if(X[3].match(R).length>1||/^\w/.test(X[3])){X[3]=F(X[3],null,null,U)}else{var W=F.filter(X[3],U,V,true^Y);if(!V){T.push.apply(T,W)}return false}}else{if(I.match.POS.test(X[0])||I.match.CHILD.test(X[0])){return true}}return X},POS:function(T){T.unshift(true);return T}},filters:{enabled:function(T){return T.disabled===false&&T.type!=="hidden"},disabled:function(T){return T.disabled===true},checked:function(T){return T.checked===true},selected:function(T){T.parentNode.selectedIndex;return T.selected===true},parent:function(T){return !!T.firstChild},empty:function(T){return !T.firstChild},has:function(V,U,T){return !!F(T[3],V).length},header:function(T){return/h\d/i.test(T.nodeName)},text:function(T){return"text"===T.type},radio:function(T){return"radio"===T.type},checkbox:function(T){return"checkbox"===T.type},file:function(T){return"file"===T.type},password:function(T){return"password"===T.type},submit:function(T){return"submit"===T.type},image:function(T){return"image"===T.type},reset:function(T){return"reset"===T.type},button:function(T){return"button"===T.type||T.nodeName.toUpperCase()==="BUTTON"},input:function(T){return/input|select|textarea|button/i.test(T.nodeName)}},setFilters:{first:function(U,T){return T===0},last:function(V,U,T,W){return U===W.length-1},even:function(U,T){return T%2===0},odd:function(U,T){return T%2===1},lt:function(V,U,T){return U<T[3]-0},gt:function(V,U,T){return U>T[3]-0},nth:function(V,U,T){return T[3]-0==U},eq:function(V,U,T){return T[3]-0==U}},filter:{PSEUDO:function(Z,V,W,aa){var U=V[1],X=I.filters[U];if(X){return X(Z,W,V,aa)}else{if(U==="contains"){return(Z.textContent||Z.innerText||"").indexOf(V[3])>=0}else{if(U==="not"){var Y=V[3];for(var W=0,T=Y.length;W<T;W++){if(Y[W]===Z){return false}}return true}}}},CHILD:function(T,W){var Z=W[1],U=T;switch(Z){case"only":case"first":while(U=U.previousSibling){if(U.nodeType===1){return false}}if(Z=="first"){return true}U=T;case"last":while(U=U.nextSibling){if(U.nodeType===1){return false}}return true;case"nth":var V=W[2],ac=W[3];if(V==1&&ac==0){return true}var Y=W[0],ab=T.parentNode;if(ab&&(ab.sizcache!==Y||!T.nodeIndex)){var X=0;for(U=ab.firstChild;U;U=U.nextSibling){if(U.nodeType===1){U.nodeIndex=++X}}ab.sizcache=Y}var aa=T.nodeIndex-ac;if(V==0){return aa==0}else{return(aa%V==0&&aa/V>=0)}}},ID:function(U,T){return U.nodeType===1&&U.getAttribute("id")===T},TAG:function(U,T){return(T==="*"&&U.nodeType===1)||U.nodeName===T},CLASS:function(U,T){return(" "+(U.className||U.getAttribute("class"))+" ").indexOf(T)>-1},ATTR:function(Y,W){var V=W[1],T=I.attrHandle[V]?I.attrHandle[V](Y):Y[V]!=null?Y[V]:Y.getAttribute(V),Z=T+"",X=W[2],U=W[4];return T==null?X==="!=":X==="="?Z===U:X==="*="?Z.indexOf(U)>=0:X==="~="?(" "+Z+" ").indexOf(U)>=0:!U?Z&&T!==false:X==="!="?Z!=U:X==="^="?Z.indexOf(U)===0:X==="$="?Z.substr(Z.length-U.length)===U:X==="|="?Z===U||Z.substr(0,U.length+1)===U+"-":false},POS:function(X,U,V,Y){var T=U[2],W=I.setFilters[T];if(W){return W(X,V,U,Y)}}}};var M=I.match.POS;for(var O in I.match){I.match[O]=RegExp(I.match[O].source+/(?![^\[]*\])(?![^\(]*\))/.source)}var E=function(U,T){U=Array.prototype.slice.call(U);if(T){T.push.apply(T,U);return T}return U};try{Array.prototype.slice.call(document.documentElement.childNodes)}catch(N){E=function(X,W){var U=W||[];if(H.call(X)==="[object Array]"){Array.prototype.push.apply(U,X)}else{if(typeof X.length==="number"){for(var V=0,T=X.length;V<T;V++){U.push(X[V])}}else{for(var V=0;X[V];V++){U.push(X[V])}}}return U}}var G;if(document.documentElement.compareDocumentPosition){G=function(U,T){var V=U.compareDocumentPosition(T)&4?-1:U===T?0:1;if(V===0){hasDuplicate=true}return V}}else{if("sourceIndex" in document.documentElement){G=function(U,T){var V=U.sourceIndex-T.sourceIndex;if(V===0){hasDuplicate=true}return V}}else{if(document.createRange){G=function(W,U){var V=W.ownerDocument.createRange(),T=U.ownerDocument.createRange();V.selectNode(W);V.collapse(true);T.selectNode(U);T.collapse(true);var X=V.compareBoundaryPoints(Range.START_TO_END,T);if(X===0){hasDuplicate=true}return X}}}}(function(){var U=document.createElement("form"),V="script"+(new Date).getTime();U.innerHTML="<input name='"+V+"'/>";var T=document.documentElement;T.insertBefore(U,T.firstChild);if(!!document.getElementById(V)){I.find.ID=function(X,Y,Z){if(typeof Y.getElementById!=="undefined"&&!Z){var W=Y.getElementById(X[1]);return W?W.id===X[1]||typeof W.getAttributeNode!=="undefined"&&W.getAttributeNode("id").nodeValue===X[1]?[W]:g:[]}};I.filter.ID=function(Y,W){var X=typeof Y.getAttributeNode!=="undefined"&&Y.getAttributeNode("id");return Y.nodeType===1&&X&&X.nodeValue===W}}T.removeChild(U)})();(function(){var T=document.createElement("div");T.appendChild(document.createComment(""));if(T.getElementsByTagName("*").length>0){I.find.TAG=function(U,Y){var X=Y.getElementsByTagName(U[1]);if(U[1]==="*"){var W=[];for(var V=0;X[V];V++){if(X[V].nodeType===1){W.push(X[V])}}X=W}return X}}T.innerHTML="<a href='#'></a>";if(T.firstChild&&typeof T.firstChild.getAttribute!=="undefined"&&T.firstChild.getAttribute("href")!=="#"){I.attrHandle.href=function(U){return U.getAttribute("href",2)}}})();if(document.querySelectorAll){(function(){var T=F,U=document.createElement("div");U.innerHTML="<p class='TEST'></p>";if(U.querySelectorAll&&U.querySelectorAll(".TEST").length===0){return}F=function(Y,X,V,W){X=X||document;if(!W&&X.nodeType===9&&!Q(X)){try{return E(X.querySelectorAll(Y),V)}catch(Z){}}return T(Y,X,V,W)};F.find=T.find;F.filter=T.filter;F.selectors=T.selectors;F.matches=T.matches})()}if(document.getElementsByClassName&&document.documentElement.getElementsByClassName){(function(){var T=document.createElement("div");T.innerHTML="<div class='test e'></div><div class='test'></div>";if(T.getElementsByClassName("e").length===0){return}T.lastChild.className="e";if(T.getElementsByClassName("e").length===1){return}I.order.splice(1,0,"CLASS");I.find.CLASS=function(U,V,W){if(typeof V.getElementsByClassName!=="undefined"&&!W){return V.getElementsByClassName(U[1])}}})()}function P(U,Z,Y,ad,aa,ac){var ab=U=="previousSibling"&&!ac;for(var W=0,V=ad.length;W<V;W++){var T=ad[W];if(T){if(ab&&T.nodeType===1){T.sizcache=Y;T.sizset=W}T=T[U];var X=false;while(T){if(T.sizcache===Y){X=ad[T.sizset];break}if(T.nodeType===1&&!ac){T.sizcache=Y;T.sizset=W}if(T.nodeName===Z){X=T;break}T=T[U]}ad[W]=X}}}function S(U,Z,Y,ad,aa,ac){var ab=U=="previousSibling"&&!ac;for(var W=0,V=ad.length;W<V;W++){var T=ad[W];if(T){if(ab&&T.nodeType===1){T.sizcache=Y;T.sizset=W}T=T[U];var X=false;while(T){if(T.sizcache===Y){X=ad[T.sizset];break}if(T.nodeType===1){if(!ac){T.sizcache=Y;T.sizset=W}if(typeof Z!=="string"){if(T===Z){X=true;break}}else{if(F.filter(Z,[T]).length>0){X=T;break}}}T=T[U]}ad[W]=X}}}var K=document.compareDocumentPosition?function(U,T){return U.compareDocumentPosition(T)&16}:function(U,T){return U!==T&&(U.contains?U.contains(T):true)};var Q=function(T){return T.nodeType===9&&T.documentElement.nodeName!=="HTML"||!!T.ownerDocument&&Q(T.ownerDocument)};var J=function(T,aa){var W=[],X="",Y,V=aa.nodeType?[aa]:aa;while((Y=I.match.PSEUDO.exec(T))){X+=Y[0];T=T.replace(I.match.PSEUDO,"")}T=I.relative[T]?T+"*":T;for(var Z=0,U=V.length;Z<U;Z++){F(T,V[Z],W)}return F.filter(X,W)};o.find=F;o.filter=F.filter;o.expr=F.selectors;o.expr[":"]=o.expr.filters;F.selectors.filters.hidden=function(T){return T.offsetWidth===0||T.offsetHeight===0};F.selectors.filters.visible=function(T){return T.offsetWidth>0||T.offsetHeight>0};F.selectors.filters.animated=function(T){return o.grep(o.timers,function(U){return T===U.elem}).length};o.multiFilter=function(V,T,U){if(U){V=":not("+V+")"}return F.matches(V,T)};o.dir=function(V,U){var T=[],W=V[U];while(W&&W!=document){if(W.nodeType==1){T.push(W)}W=W[U]}return T};o.nth=function(X,T,V,W){T=T||1;var U=0;for(;X;X=X[V]){if(X.nodeType==1&&++U==T){break}}return X};o.sibling=function(V,U){var T=[];for(;V;V=V.nextSibling){if(V.nodeType==1&&V!=U){T.push(V)}}return T};return;l.Sizzle=F})();o.event={add:function(I,F,H,K){if(I.nodeType==3||I.nodeType==8){return}if(I.setInterval&&I!=l){I=l}if(!H.guid){H.guid=this.guid++}if(K!==g){var G=H;H=this.proxy(G);H.data=K}var E=o.data(I,"events")||o.data(I,"events",{}),J=o.data(I,"handle")||o.data(I,"handle",function(){return typeof o!=="undefined"&&!o.event.triggered?o.event.handle.apply(arguments.callee.elem,arguments):g});J.elem=I;o.each(F.split(/\s+/),function(M,N){var O=N.split(".");N=O.shift();H.type=O.slice().sort().join(".");var L=E[N];if(o.event.specialAll[N]){o.event.specialAll[N].setup.call(I,K,O)}if(!L){L=E[N]={};if(!o.event.special[N]||o.event.special[N].setup.call(I,K,O)===false){if(I.addEventListener){I.addEventListener(N,J,false)}else{if(I.attachEvent){I.attachEvent("on"+N,J)}}}}L[H.guid]=H;o.event.global[N]=true});I=null},guid:1,global:{},remove:function(K,H,J){if(K.nodeType==3||K.nodeType==8){return}var G=o.data(K,"events"),F,E;if(G){if(H===g||(typeof H==="string"&&H.charAt(0)==".")){for(var I in G){this.remove(K,I+(H||""))}}else{if(H.type){J=H.handler;H=H.type}o.each(H.split(/\s+/),function(M,O){var Q=O.split(".");O=Q.shift();var N=RegExp("(^|\\.)"+Q.slice().sort().join(".*\\.")+"(\\.|$)");if(G[O]){if(J){delete G[O][J.guid]}else{for(var P in G[O]){if(N.test(G[O][P].type)){delete G[O][P]}}}if(o.event.specialAll[O]){o.event.specialAll[O].teardown.call(K,Q)}for(F in G[O]){break}if(!F){if(!o.event.special[O]||o.event.special[O].teardown.call(K,Q)===false){if(K.removeEventListener){K.removeEventListener(O,o.data(K,"handle"),false)}else{if(K.detachEvent){K.detachEvent("on"+O,o.data(K,"handle"))}}}F=null;delete G[O]}}})}for(F in G){break}if(!F){var L=o.data(K,"handle");if(L){L.elem=null}o.removeData(K,"events");o.removeData(K,"handle")}}},trigger:function(I,K,H,E){var G=I.type||I;if(!E){I=typeof I==="object"?I[h]?I:o.extend(o.Event(G),I):o.Event(G);if(G.indexOf("!")>=0){I.type=G=G.slice(0,-1);I.exclusive=true}if(!H){I.stopPropagation();if(this.global[G]){o.each(o.cache,function(){if(this.events&&this.events[G]){o.event.trigger(I,K,this.handle.elem)}})}}if(!H||H.nodeType==3||H.nodeType==8){return g}I.result=g;I.target=H;K=o.makeArray(K);K.unshift(I)}I.currentTarget=H;var J=o.data(H,"handle");if(J){J.apply(H,K)}if((!H[G]||(o.nodeName(H,"a")&&G=="click"))&&H["on"+G]&&H["on"+G].apply(H,K)===false){I.result=false}if(!E&&H[G]&&!I.isDefaultPrevented()&&!(o.nodeName(H,"a")&&G=="click")){this.triggered=true;try{H[G]()}catch(L){}}this.triggered=false;if(!I.isPropagationStopped()){var F=H.parentNode||H.ownerDocument;if(F){o.event.trigger(I,K,F,true)}}},handle:function(K){var J,E;K=arguments[0]=o.event.fix(K||l.event);K.currentTarget=this;var L=K.type.split(".");K.type=L.shift();J=!L.length&&!K.exclusive;var I=RegExp("(^|\\.)"+L.slice().sort().join(".*\\.")+"(\\.|$)");E=(o.data(this,"events")||{})[K.type];for(var G in E){var H=E[G];if(J||I.test(H.type)){K.handler=H;K.data=H.data;var F=H.apply(this,arguments);if(F!==g){K.result=F;if(F===false){K.preventDefault();K.stopPropagation()}}if(K.isImmediatePropagationStopped()){break}}}},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),fix:function(H){if(H[h]){return H}var F=H;H=o.Event(F);for(var G=this.props.length,J;G;){J=this.props[--G];H[J]=F[J]}if(!H.target){H.target=H.srcElement||document}if(H.target.nodeType==3){H.target=H.target.parentNode}if(!H.relatedTarget&&H.fromElement){H.relatedTarget=H.fromElement==H.target?H.toElement:H.fromElement}if(H.pageX==null&&H.clientX!=null){var I=document.documentElement,E=document.body;H.pageX=H.clientX+(I&&I.scrollLeft||E&&E.scrollLeft||0)-(I.clientLeft||0);H.pageY=H.clientY+(I&&I.scrollTop||E&&E.scrollTop||0)-(I.clientTop||0)}if(!H.which&&((H.charCode||H.charCode===0)?H.charCode:H.keyCode)){H.which=H.charCode||H.keyCode}if(!H.metaKey&&H.ctrlKey){H.metaKey=H.ctrlKey}if(!H.which&&H.button){H.which=(H.button&1?1:(H.button&2?3:(H.button&4?2:0)))}return H},proxy:function(F,E){E=E||function(){return F.apply(this,arguments)};E.guid=F.guid=F.guid||E.guid||this.guid++;return E},special:{ready:{setup:B,teardown:function(){}}},specialAll:{live:{setup:function(E,F){o.event.add(this,F[0],c)},teardown:function(G){if(G.length){var E=0,F=RegExp("(^|\\.)"+G[0]+"(\\.|$)");o.each((o.data(this,"events").live||{}),function(){if(F.test(this.type)){E++}});if(E<1){o.event.remove(this,G[0],c)}}}}}};o.Event=function(E){if(!this.preventDefault){return new o.Event(E)}if(E&&E.type){this.originalEvent=E;this.type=E.type}else{this.type=E}this.timeStamp=e();this[h]=true};function k(){return false}function u(){return true}o.Event.prototype={preventDefault:function(){this.isDefaultPrevented=u;var E=this.originalEvent;if(!E){return}if(E.preventDefault){E.preventDefault()}E.returnValue=false},stopPropagation:function(){this.isPropagationStopped=u;var E=this.originalEvent;if(!E){return}if(E.stopPropagation){E.stopPropagation()}E.cancelBubble=true},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=u;this.stopPropagation()},isDefaultPrevented:k,isPropagationStopped:k,isImmediatePropagationStopped:k};var a=function(F){var E=F.relatedTarget;while(E&&E!=this){try{E=E.parentNode}catch(G){E=this}}if(E!=this){F.type=F.data;o.event.handle.apply(this,arguments)}};o.each({mouseover:"mouseenter",mouseout:"mouseleave"},function(F,E){o.event.special[E]={setup:function(){o.event.add(this,F,a,E)},teardown:function(){o.event.remove(this,F,a)}}});o.fn.extend({bind:function(F,G,E){return F=="unload"?this.one(F,G,E):this.each(function(){o.event.add(this,F,E||G,E&&G)})},one:function(G,H,F){var E=o.event.proxy(F||H,function(I){o(this).unbind(I,E);return(F||H).apply(this,arguments)});return this.each(function(){o.event.add(this,G,E,F&&H)})},unbind:function(F,E){return this.each(function(){o.event.remove(this,F,E)})},trigger:function(E,F){return this.each(function(){o.event.trigger(E,F,this)})},triggerHandler:function(E,G){if(this[0]){var F=o.Event(E);F.preventDefault();F.stopPropagation();o.event.trigger(F,G,this[0]);return F.result}},toggle:function(G){var E=arguments,F=1;while(F<E.length){o.event.proxy(G,E[F++])}return this.click(o.event.proxy(G,function(H){this.lastToggle=(this.lastToggle||0)%F;H.preventDefault();return E[this.lastToggle++].apply(this,arguments)||false}))},hover:function(E,F){return this.mouseenter(E).mouseleave(F)},ready:function(E){B();if(o.isReady){E.call(document,o)}else{o.readyList.push(E)}return this},live:function(G,F){var E=o.event.proxy(F);E.guid+=this.selector+G;o(document).bind(i(G,this.selector),this.selector,E);return this},die:function(F,E){o(document).unbind(i(F,this.selector),E?{guid:E.guid+this.selector+F}:null);return this}});function c(H){var E=RegExp("(^|\\.)"+H.type+"(\\.|$)"),G=true,F=[];o.each(o.data(this,"events").live||[],function(I,J){if(E.test(J.type)){var K=o(H.target).closest(J.data)[0];if(K){F.push({elem:K,fn:J})}}});F.sort(function(J,I){return o.data(J.elem,"closest")-o.data(I.elem,"closest")});o.each(F,function(){if(this.fn.call(this.elem,H,this.fn.data)===false){return(G=false)}});return G}function i(F,E){return["live",F,E.replace(/\./g,"`").replace(/ /g,"|")].join(".")}o.extend({isReady:false,readyList:[],ready:function(){if(!o.isReady){o.isReady=true;if(o.readyList){o.each(o.readyList,function(){this.call(document,o)});o.readyList=null}o(document).triggerHandler("ready")}}});var x=false;function B(){if(x){return}x=true;if(document.addEventListener){document.addEventListener("DOMContentLoaded",function(){document.removeEventListener("DOMContentLoaded",arguments.callee,false);o.ready()},false)}else{if(document.attachEvent){document.attachEvent("onreadystatechange",function(){if(document.readyState==="complete"){document.detachEvent("onreadystatechange",arguments.callee);o.ready()}});if(document.documentElement.doScroll&&l==l.top){(function(){if(o.isReady){return}try{document.documentElement.doScroll("left")}catch(E){setTimeout(arguments.callee,0);return}o.ready()})()}}}o.event.add(l,"load",o.ready)}o.each(("blur,focus,load,resize,scroll,unload,click,dblclick,mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,change,select,submit,keydown,keypress,keyup,error").split(","),function(F,E){o.fn[E]=function(G){return G?this.bind(E,G):this.trigger(E)}});o(l).bind("unload",function(){for(var E in o.cache){if(E!=1&&o.cache[E].handle){o.event.remove(o.cache[E].handle.elem)}}});(function(){o.support={};var F=document.documentElement,G=document.createElement("script"),K=document.createElement("div"),J="script"+(new Date).getTime();K.style.display="none";K.innerHTML='   <link/><table></table><a href="/a" style="color:red;float:left;opacity:.5;">a</a><select><option>text</option></select><object><param/></object>';var H=K.getElementsByTagName("*"),E=K.getElementsByTagName("a")[0];if(!H||!H.length||!E){return}o.support={leadingWhitespace:K.firstChild.nodeType==3,tbody:!K.getElementsByTagName("tbody").length,objectAll:!!K.getElementsByTagName("object")[0].getElementsByTagName("*").length,htmlSerialize:!!K.getElementsByTagName("link").length,style:/red/.test(E.getAttribute("style")),hrefNormalized:E.getAttribute("href")==="/a",opacity:E.style.opacity==="0.5",cssFloat:!!E.style.cssFloat,scriptEval:false,noCloneEvent:true,boxModel:null};G.type="text/javascript";try{G.appendChild(document.createTextNode("window."+J+"=1;"))}catch(I){}F.insertBefore(G,F.firstChild);if(l[J]){o.support.scriptEval=true;delete l[J]}F.removeChild(G);if(K.attachEvent&&K.fireEvent){K.attachEvent("onclick",function(){o.support.noCloneEvent=false;K.detachEvent("onclick",arguments.callee)});K.cloneNode(true).fireEvent("onclick")}o(function(){var L=document.createElement("div");L.style.width=L.style.paddingLeft="1px";document.body.appendChild(L);o.boxModel=o.support.boxModel=L.offsetWidth===2;document.body.removeChild(L).style.display="none"})})();var w=o.support.cssFloat?"cssFloat":"styleFloat";o.props={"for":"htmlFor","class":"className","float":w,cssFloat:w,styleFloat:w,readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",tabindex:"tabIndex"};o.fn.extend({_load:o.fn.load,load:function(G,J,K){if(typeof G!=="string"){return this._load(G)}var I=G.indexOf(" ");if(I>=0){var E=G.slice(I,G.length);G=G.slice(0,I)}var H="GET";if(J){if(o.isFunction(J)){K=J;J=null}else{if(typeof J==="object"){J=o.param(J);H="POST"}}}var F=this;o.ajax({url:G,type:H,dataType:"html",data:J,complete:function(M,L){if(L=="success"||L=="notmodified"){F.html(E?o("<div/>").append(M.responseText.replace(/<script(.|\s)*?\/script>/g,"")).find(E):M.responseText)}if(K){F.each(K,[M.responseText,L,M])}}});return this},serialize:function(){return o.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?o.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||/select|textarea/i.test(this.nodeName)||/text|hidden|password|search/i.test(this.type))}).map(function(E,F){var G=o(this).val();return G==null?null:o.isArray(G)?o.map(G,function(I,H){return{name:F.name,value:I}}):{name:F.name,value:G}}).get()}});o.each("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","),function(E,F){o.fn[F]=function(G){return this.bind(F,G)}});var r=e();o.extend({get:function(E,G,H,F){if(o.isFunction(G)){H=G;G=null}return o.ajax({type:"GET",url:E,data:G,success:H,dataType:F})},getScript:function(E,F){return o.get(E,null,F,"script")},getJSON:function(E,F,G){return o.get(E,F,G,"json")},post:function(E,G,H,F){if(o.isFunction(G)){H=G;G={}}return o.ajax({type:"POST",url:E,data:G,success:H,dataType:F})},ajaxSetup:function(E){o.extend(o.ajaxSettings,E)},ajaxSettings:{url:location.href,global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:function(){return l.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},ajax:function(M){M=o.extend(true,M,o.extend(true,{},o.ajaxSettings,M));var W,F=/=\?(&|$)/g,R,V,G=M.type.toUpperCase();if(M.data&&M.processData&&typeof M.data!=="string"){M.data=o.param(M.data)}if(M.dataType=="jsonp"){if(G=="GET"){if(!M.url.match(F)){M.url+=(M.url.match(/\?/)?"&":"?")+(M.jsonp||"callback")+"=?"}}else{if(!M.data||!M.data.match(F)){M.data=(M.data?M.data+"&":"")+(M.jsonp||"callback")+"=?"}}M.dataType="json"}if(M.dataType=="json"&&(M.data&&M.data.match(F)||M.url.match(F))){W="jsonp"+r++;if(M.data){M.data=(M.data+"").replace(F,"="+W+"$1")}M.url=M.url.replace(F,"="+W+"$1");M.dataType="script";l[W]=function(X){V=X;I();L();l[W]=g;try{delete l[W]}catch(Y){}if(H){H.removeChild(T)}}}if(M.dataType=="script"&&M.cache==null){M.cache=false}if(M.cache===false&&G=="GET"){var E=e();var U=M.url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+E+"$2");M.url=U+((U==M.url)?(M.url.match(/\?/)?"&":"?")+"_="+E:"")}if(M.data&&G=="GET"){M.url+=(M.url.match(/\?/)?"&":"?")+M.data;M.data=null}if(M.global&&!o.active++){o.event.trigger("ajaxStart")}var Q=/^(\w+:)?\/\/([^\/?#]+)/.exec(M.url);if(M.dataType=="script"&&G=="GET"&&Q&&(Q[1]&&Q[1]!=location.protocol||Q[2]!=location.host)){var H=document.getElementsByTagName("head")[0];var T=document.createElement("script");T.src=M.url;if(M.scriptCharset){T.charset=M.scriptCharset}if(!W){var O=false;T.onload=T.onreadystatechange=function(){if(!O&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){O=true;I();L();T.onload=T.onreadystatechange=null;H.removeChild(T)}}}H.appendChild(T);return g}var K=false;var J=M.xhr();if(M.username){J.open(G,M.url,M.async,M.username,M.password)}else{J.open(G,M.url,M.async)}try{if(M.data){J.setRequestHeader("Content-Type",M.contentType)}if(M.ifModified){J.setRequestHeader("If-Modified-Since",o.lastModified[M.url]||"Thu, 01 Jan 1970 00:00:00 GMT")}J.setRequestHeader("X-Requested-With","XMLHttpRequest");J.setRequestHeader("Accept",M.dataType&&M.accepts[M.dataType]?M.accepts[M.dataType]+", */*":M.accepts._default)}catch(S){}if(M.beforeSend&&M.beforeSend(J,M)===false){if(M.global&&!--o.active){o.event.trigger("ajaxStop")}J.abort();return false}if(M.global){o.event.trigger("ajaxSend",[J,M])}var N=function(X){if(J.readyState==0){if(P){clearInterval(P);P=null;if(M.global&&!--o.active){o.event.trigger("ajaxStop")}}}else{if(!K&&J&&(J.readyState==4||X=="timeout")){K=true;if(P){clearInterval(P);P=null}R=X=="timeout"?"timeout":!o.httpSuccess(J)?"error":M.ifModified&&o.httpNotModified(J,M.url)?"notmodified":"success";if(R=="success"){try{V=o.httpData(J,M.dataType,M)}catch(Z){R="parsererror"}}if(R=="success"){var Y;try{Y=J.getResponseHeader("Last-Modified")}catch(Z){}if(M.ifModified&&Y){o.lastModified[M.url]=Y}if(!W){I()}}else{o.handleError(M,J,R)}L();if(X){J.abort()}if(M.async){J=null}}}};if(M.async){var P=setInterval(N,13);if(M.timeout>0){setTimeout(function(){if(J&&!K){N("timeout")}},M.timeout)}}try{J.send(M.data)}catch(S){o.handleError(M,J,null,S)}if(!M.async){N()}function I(){if(M.success){M.success(V,R)}if(M.global){o.event.trigger("ajaxSuccess",[J,M])}}function L(){if(M.complete){M.complete(J,R)}if(M.global){o.event.trigger("ajaxComplete",[J,M])}if(M.global&&!--o.active){o.event.trigger("ajaxStop")}}return J},handleError:function(F,H,E,G){if(F.error){F.error(H,E,G)}if(F.global){o.event.trigger("ajaxError",[H,F,G])}},active:0,httpSuccess:function(F){try{return !F.status&&location.protocol=="file:"||(F.status>=200&&F.status<300)||F.status==304||F.status==1223}catch(E){}return false},httpNotModified:function(G,E){try{var H=G.getResponseHeader("Last-Modified");return G.status==304||H==o.lastModified[E]}catch(F){}return false},httpData:function(J,H,G){var F=J.getResponseHeader("content-type"),E=H=="xml"||!H&&F&&F.indexOf("xml")>=0,I=E?J.responseXML:J.responseText;if(E&&I.documentElement.tagName=="parsererror"){throw"parsererror"}if(G&&G.dataFilter){I=G.dataFilter(I,H)}if(typeof I==="string"){if(H=="script"){o.globalEval(I)}if(H=="json"){I=l["eval"]("("+I+")")}}return I},param:function(E){var G=[];function H(I,J){G[G.length]=encodeURIComponent(I)+"="+encodeURIComponent(J)}if(o.isArray(E)||E.jquery){o.each(E,function(){H(this.name,this.value)})}else{for(var F in E){if(o.isArray(E[F])){o.each(E[F],function(){H(F,this)})}else{H(F,o.isFunction(E[F])?E[F]():E[F])}}}return G.join("&").replace(/%20/g,"+")}});var m={},n,d=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];function t(F,E){var G={};o.each(d.concat.apply([],d.slice(0,E)),function(){G[this]=F});return G}o.fn.extend({show:function(J,L){if(J){return this.animate(t("show",3),J,L)}else{for(var H=0,F=this.length;H<F;H++){var E=o.data(this[H],"olddisplay");this[H].style.display=E||"";if(o.css(this[H],"display")==="none"){var G=this[H].tagName,K;if(m[G]){K=m[G]}else{var I=o("<"+G+" />").appendTo("body");K=I.css("display");if(K==="none"){K="block"}I.remove();m[G]=K}o.data(this[H],"olddisplay",K)}}for(var H=0,F=this.length;H<F;H++){this[H].style.display=o.data(this[H],"olddisplay")||""}return this}},hide:function(H,I){if(H){return this.animate(t("hide",3),H,I)}else{for(var G=0,F=this.length;G<F;G++){var E=o.data(this[G],"olddisplay");if(!E&&E!=="none"){o.data(this[G],"olddisplay",o.css(this[G],"display"))}}for(var G=0,F=this.length;G<F;G++){this[G].style.display="none"}return this}},_toggle:o.fn.toggle,toggle:function(G,F){var E=typeof G==="boolean";return o.isFunction(G)&&o.isFunction(F)?this._toggle.apply(this,arguments):G==null||E?this.each(function(){var H=E?G:o(this).is(":hidden");o(this)[H?"show":"hide"]()}):this.animate(t("toggle",3),G,F)},fadeTo:function(E,G,F){return this.animate({opacity:G},E,F)},animate:function(I,F,H,G){var E=o.speed(F,H,G);return this[E.queue===false?"each":"queue"](function(){var K=o.extend({},E),M,L=this.nodeType==1&&o(this).is(":hidden"),J=this;for(M in I){if(I[M]=="hide"&&L||I[M]=="show"&&!L){return K.complete.call(this)}if((M=="height"||M=="width")&&this.style){K.display=o.css(this,"display");K.overflow=this.style.overflow}}if(K.overflow!=null){this.style.overflow="hidden"}K.curAnim=o.extend({},I);o.each(I,function(O,S){var R=new o.fx(J,K,O);if(/toggle|show|hide/.test(S)){R[S=="toggle"?L?"show":"hide":S](I)}else{var Q=S.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),T=R.cur(true)||0;if(Q){var N=parseFloat(Q[2]),P=Q[3]||"px";if(P!="px"){J.style[O]=(N||1)+P;T=((N||1)/R.cur(true))*T;J.style[O]=T+P}if(Q[1]){N=((Q[1]=="-="?-1:1)*N)+T}R.custom(T,N,P)}else{R.custom(T,S,"")}}});return true})},stop:function(F,E){var G=o.timers;if(F){this.queue([])}this.each(function(){for(var H=G.length-1;H>=0;H--){if(G[H].elem==this){if(E){G[H](true)}G.splice(H,1)}}});if(!E){this.dequeue()}return this}});o.each({slideDown:t("show",1),slideUp:t("hide",1),slideToggle:t("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(E,F){o.fn[E]=function(G,H){return this.animate(F,G,H)}});o.extend({speed:function(G,H,F){var E=typeof G==="object"?G:{complete:F||!F&&H||o.isFunction(G)&&G,duration:G,easing:F&&H||H&&!o.isFunction(H)&&H};E.duration=o.fx.off?0:typeof E.duration==="number"?E.duration:o.fx.speeds[E.duration]||o.fx.speeds._default;E.old=E.complete;E.complete=function(){if(E.queue!==false){o(this).dequeue()}if(o.isFunction(E.old)){E.old.call(this)}};return E},easing:{linear:function(G,H,E,F){return E+F*G},swing:function(G,H,E,F){return((-Math.cos(G*Math.PI)/2)+0.5)*F+E}},timers:[],fx:function(F,E,G){this.options=E;this.elem=F;this.prop=G;if(!E.orig){E.orig={}}}});o.fx.prototype={update:function(){if(this.options.step){this.options.step.call(this.elem,this.now,this)}(o.fx.step[this.prop]||o.fx.step._default)(this);if((this.prop=="height"||this.prop=="width")&&this.elem.style){this.elem.style.display="block"}},cur:function(F){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null)){return this.elem[this.prop]}var E=parseFloat(o.css(this.elem,this.prop,F));return E&&E>-10000?E:parseFloat(o.curCSS(this.elem,this.prop))||0},custom:function(I,H,G){this.startTime=e();this.start=I;this.end=H;this.unit=G||this.unit||"px";this.now=this.start;this.pos=this.state=0;var E=this;function F(J){return E.step(J)}F.elem=this.elem;if(F()&&o.timers.push(F)&&!n){n=setInterval(function(){var K=o.timers;for(var J=0;J<K.length;J++){if(!K[J]()){K.splice(J--,1)}}if(!K.length){clearInterval(n);n=g}},13)}},show:function(){this.options.orig[this.prop]=o.attr(this.elem.style,this.prop);this.options.show=true;this.custom(this.prop=="width"||this.prop=="height"?1:0,this.cur());o(this.elem).show()},hide:function(){this.options.orig[this.prop]=o.attr(this.elem.style,this.prop);this.options.hide=true;this.custom(this.cur(),0)},step:function(H){var G=e();if(H||G>=this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;var E=true;for(var F in this.options.curAnim){if(this.options.curAnim[F]!==true){E=false}}if(E){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;this.elem.style.display=this.options.display;if(o.css(this.elem,"display")=="none"){this.elem.style.display="block"}}if(this.options.hide){o(this.elem).hide()}if(this.options.hide||this.options.show){for(var I in this.options.curAnim){o.attr(this.elem.style,I,this.options.orig[I])}}this.options.complete.call(this.elem)}return false}else{var J=G-this.startTime;this.state=J/this.options.duration;this.pos=o.easing[this.options.easing||(o.easing.swing?"swing":"linear")](this.state,J,0,1,this.options.duration);this.now=this.start+((this.end-this.start)*this.pos);this.update()}return true}};o.extend(o.fx,{speeds:{slow:600,fast:200,_default:400},step:{opacity:function(E){o.attr(E.elem.style,"opacity",E.now)},_default:function(E){if(E.elem.style&&E.elem.style[E.prop]!=null){E.elem.style[E.prop]=E.now+E.unit}else{E.elem[E.prop]=E.now}}}});if(document.documentElement.getBoundingClientRect){o.fn.offset=function(){if(!this[0]){return{top:0,left:0}}if(this[0]===this[0].ownerDocument.body){return o.offset.bodyOffset(this[0])}var G=this[0].getBoundingClientRect(),J=this[0].ownerDocument,F=J.body,E=J.documentElement,L=E.clientTop||F.clientTop||0,K=E.clientLeft||F.clientLeft||0,I=G.top+(self.pageYOffset||o.boxModel&&E.scrollTop||F.scrollTop)-L,H=G.left+(self.pageXOffset||o.boxModel&&E.scrollLeft||F.scrollLeft)-K;return{top:I,left:H}}}else{o.fn.offset=function(){if(!this[0]){return{top:0,left:0}}if(this[0]===this[0].ownerDocument.body){return o.offset.bodyOffset(this[0])}o.offset.initialized||o.offset.initialize();var J=this[0],G=J.offsetParent,F=J,O=J.ownerDocument,M,H=O.documentElement,K=O.body,L=O.defaultView,E=L.getComputedStyle(J,null),N=J.offsetTop,I=J.offsetLeft;while((J=J.parentNode)&&J!==K&&J!==H){M=L.getComputedStyle(J,null);N-=J.scrollTop,I-=J.scrollLeft;if(J===G){N+=J.offsetTop,I+=J.offsetLeft;if(o.offset.doesNotAddBorder&&!(o.offset.doesAddBorderForTableAndCells&&/^t(able|d|h)$/i.test(J.tagName))){N+=parseInt(M.borderTopWidth,10)||0,I+=parseInt(M.borderLeftWidth,10)||0}F=G,G=J.offsetParent}if(o.offset.subtractsBorderForOverflowNotVisible&&M.overflow!=="visible"){N+=parseInt(M.borderTopWidth,10)||0,I+=parseInt(M.borderLeftWidth,10)||0}E=M}if(E.position==="relative"||E.position==="static"){N+=K.offsetTop,I+=K.offsetLeft}if(E.position==="fixed"){N+=Math.max(H.scrollTop,K.scrollTop),I+=Math.max(H.scrollLeft,K.scrollLeft)}return{top:N,left:I}}}o.offset={initialize:function(){if(this.initialized){return}var L=document.body,F=document.createElement("div"),H,G,N,I,M,E,J=L.style.marginTop,K='<div style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;"><div></div></div><table style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;" cellpadding="0" cellspacing="0"><tr><td></td></tr></table>';M={position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"};for(E in M){F.style[E]=M[E]}F.innerHTML=K;L.insertBefore(F,L.firstChild);H=F.firstChild,G=H.firstChild,I=H.nextSibling.firstChild.firstChild;this.doesNotAddBorder=(G.offsetTop!==5);this.doesAddBorderForTableAndCells=(I.offsetTop===5);H.style.overflow="hidden",H.style.position="relative";this.subtractsBorderForOverflowNotVisible=(G.offsetTop===-5);L.style.marginTop="1px";this.doesNotIncludeMarginInBodyOffset=(L.offsetTop===0);L.style.marginTop=J;L.removeChild(F);this.initialized=true},bodyOffset:function(E){o.offset.initialized||o.offset.initialize();var G=E.offsetTop,F=E.offsetLeft;if(o.offset.doesNotIncludeMarginInBodyOffset){G+=parseInt(o.curCSS(E,"marginTop",true),10)||0,F+=parseInt(o.curCSS(E,"marginLeft",true),10)||0}return{top:G,left:F}}};o.fn.extend({position:function(){var I=0,H=0,F;if(this[0]){var G=this.offsetParent(),J=this.offset(),E=/^body|html$/i.test(G[0].tagName)?{top:0,left:0}:G.offset();J.top-=j(this,"marginTop");J.left-=j(this,"marginLeft");E.top+=j(G,"borderTopWidth");E.left+=j(G,"borderLeftWidth");F={top:J.top-E.top,left:J.left-E.left}}return F},offsetParent:function(){var E=this[0].offsetParent||document.body;while(E&&(!/^body|html$/i.test(E.tagName)&&o.css(E,"position")=="static")){E=E.offsetParent}return o(E)}});o.each(["Left","Top"],function(F,E){var G="scroll"+E;o.fn[G]=function(H){if(!this[0]){return null}return H!==g?this.each(function(){this==l||this==document?l.scrollTo(!F?H:o(l).scrollLeft(),F?H:o(l).scrollTop()):this[G]=H}):this[0]==l||this[0]==document?self[F?"pageYOffset":"pageXOffset"]||o.boxModel&&document.documentElement[G]||document.body[G]:this[0][G]}});o.each(["Height","Width"],function(I,G){var E=I?"Left":"Top",H=I?"Right":"Bottom",F=G.toLowerCase();o.fn["inner"+G]=function(){return this[0]?o.css(this[0],F,false,"padding"):null};o.fn["outer"+G]=function(K){return this[0]?o.css(this[0],F,false,K?"margin":"border"):null};var J=G.toLowerCase();o.fn[J]=function(K){return this[0]==l?document.compatMode=="CSS1Compat"&&document.documentElement["client"+G]||document.body["client"+G]:this[0]==document?Math.max(document.documentElement["client"+G],document.body["scroll"+G],document.documentElement["scroll"+G],document.body["offset"+G],document.documentElement["offset"+G]):K===g?(this.length?o.css(this[0],J):null):this.css(J,typeof K==="string"?K:K+"px")}})})();
+//]]>
+</script>
+<!--PRE-HEAD-START-->
+<!--{{{-->
+<link rel='alternate' type='application/rss+xml' title='RSS' href='index.xml' />
+<!--}}}-->
+<!--PRE-HEAD-END-->
+<title> GRPL Telephone Renewals </title>
+<style id="styleArea" type="text/css">
+#saveTest {display:none;}
+#messageArea {display:none;}
+#copyright {display:none;}
+#storeArea {display:none;}
+#storeArea div {padding:0.5em; margin:1em 0em 0em 0em; border-color:#fff #666 #444 #ddd; border-style:solid; border-width:2px; overflow:auto;}
+#shadowArea {display:none;}
+#javascriptWarning {width:100%; text-align:center; font-weight:bold; background-color:#dd1100; color:#fff; padding:1em 0em;}
+</style>
+<!--POST-HEAD-START-->
+
+<!--POST-HEAD-END-->
+</head>
+<body onload="main();" onunload="if(window.checkUnsavedChanges) checkUnsavedChanges(); if(window.scrubNodes) scrubNodes(document.body);">
+<!--PRE-BODY-START-->
+
+<!--PRE-BODY-END-->
+<div id="copyright">
+Welcome to TiddlyWiki created by Jeremy Ruston, Copyright &copy; 2007 UnaMesa Association
+</div>
+<noscript>
+<div id="javascriptWarning">
+This page requires JavaScript to function properly.<br /><br />If you are using Microsoft Internet Explorer you may need to click on the yellow bar above and select 'Allow Blocked Content'. You must then click 'Yes' on the following security warning.
+</div>
+</noscript>
+<div id="saveTest"></div>
+<div id="backstageCloak"></div>
+<div id="backstageButton"></div>
+<div id="backstageArea"><div id="backstageToolbar"></div></div>
+<div id="backstage">
+	<div id="backstagePanel"></div>
+</div>
+<div id="contentWrapper"></div>
+<div id="contentStash"></div>
+<div id="shadowArea">
+<div title="MarkupPreHead">
+<pre>&lt;!--{{{--&gt;
+&lt;link rel='alternate' type='application/rss+xml' title='RSS' href='index.xml' /&gt;
+&lt;!--}}}--&gt;</pre>
+</div>
+<div title="ColorPalette">
+<pre>Background: #fff
+Foreground: #000
+PrimaryPale: #8cf
+PrimaryLight: #18f
+PrimaryMid: #04b
+PrimaryDark: #014
+SecondaryPale: #ffc
+SecondaryLight: #fe8
+SecondaryMid: #db4
+SecondaryDark: #841
+TertiaryPale: #eee
+TertiaryLight: #ccc
+TertiaryMid: #999
+TertiaryDark: #666
+Error: #f88</pre>
+</div>
+<div title="StyleSheetColors">
+<pre>/*{{{*/
+body {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
+
+a {color:[[ColorPalette::PrimaryMid]];}
+a:hover {background-color:[[ColorPalette::PrimaryMid]]; color:[[ColorPalette::Background]];}
+a img {border:0;}
+
+h1,h2,h3,h4,h5,h6 {color:[[ColorPalette::SecondaryDark]]; background:transparent;}
+h1 {border-bottom:2px solid [[ColorPalette::TertiaryLight]];}
+h2,h3 {border-bottom:1px solid [[ColorPalette::TertiaryLight]];}
+
+.button {color:[[ColorPalette::PrimaryDark]]; border:1px solid [[ColorPalette::Background]];}
+.button:hover {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::SecondaryLight]]; border-color:[[ColorPalette::SecondaryMid]];}
+.button:active {color:[[ColorPalette::Background]]; background:[[ColorPalette::SecondaryMid]]; border:1px solid [[ColorPalette::SecondaryDark]];}
+
+.header {background:[[ColorPalette::PrimaryMid]];}
+.headerShadow {color:[[ColorPalette::Foreground]];}
+.headerShadow a {font-weight:normal; color:[[ColorPalette::Foreground]];}
+.headerForeground {color:[[ColorPalette::Background]];}
+.headerForeground a {font-weight:normal; color:[[ColorPalette::PrimaryPale]];}
+
+.tabSelected{color:[[ColorPalette::PrimaryDark]];
+	background:[[ColorPalette::TertiaryPale]];
+	border-left:1px solid [[ColorPalette::TertiaryLight]];
+	border-top:1px solid [[ColorPalette::TertiaryLight]];
+	border-right:1px solid [[ColorPalette::TertiaryLight]];
+}
+.tabUnselected {color:[[ColorPalette::Background]]; background:[[ColorPalette::TertiaryMid]];}
+.tabContents {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::TertiaryPale]]; border:1px solid [[ColorPalette::TertiaryLight]];}
+.tabContents .button {border:0;}
+
+#sidebar {}
+#sidebarOptions input {border:1px solid [[ColorPalette::PrimaryMid]];}
+#sidebarOptions .sliderPanel {background:[[ColorPalette::PrimaryPale]];}
+#sidebarOptions .sliderPanel a {border:none;color:[[ColorPalette::PrimaryMid]];}
+#sidebarOptions .sliderPanel a:hover {color:[[ColorPalette::Background]]; background:[[ColorPalette::PrimaryMid]];}
+#sidebarOptions .sliderPanel a:active {color:[[ColorPalette::PrimaryMid]]; background:[[ColorPalette::Background]];}
+
+.wizard {background:[[ColorPalette::PrimaryPale]]; border:1px solid [[ColorPalette::PrimaryMid]];}
+.wizard h1 {color:[[ColorPalette::PrimaryDark]]; border:none;}
+.wizard h2 {color:[[ColorPalette::Foreground]]; border:none;}
+.wizardStep {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];
+	border:1px solid [[ColorPalette::PrimaryMid]];}
+.wizardStep.wizardStepDone {background:[[ColorPalette::TertiaryLight]];}
+.wizardFooter {background:[[ColorPalette::PrimaryPale]];}
+.wizardFooter .status {background:[[ColorPalette::PrimaryDark]]; color:[[ColorPalette::Background]];}
+.wizard .button {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::SecondaryLight]]; border: 1px solid;
+	border-color:[[ColorPalette::SecondaryPale]] [[ColorPalette::SecondaryDark]] [[ColorPalette::SecondaryDark]] [[ColorPalette::SecondaryPale]];}
+.wizard .button:hover {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::Background]];}
+.wizard .button:active {color:[[ColorPalette::Background]]; background:[[ColorPalette::Foreground]]; border: 1px solid;
+	border-color:[[ColorPalette::PrimaryDark]] [[ColorPalette::PrimaryPale]] [[ColorPalette::PrimaryPale]] [[ColorPalette::PrimaryDark]];}
+
+.wizard .notChanged {background:transparent;}
+.wizard .changedLocally {background:#80ff80;}
+.wizard .changedServer {background:#8080ff;}
+.wizard .changedBoth {background:#ff8080;}
+.wizard .notFound {background:#ffff80;}
+.wizard .putToServer {background:#ff80ff;}
+.wizard .gotFromServer {background:#80ffff;}
+
+#messageArea {border:1px solid [[ColorPalette::SecondaryMid]]; background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]];}
+#messageArea .button {color:[[ColorPalette::PrimaryMid]]; background:[[ColorPalette::SecondaryPale]]; border:none;}
+
+.popupTiddler {background:[[ColorPalette::TertiaryPale]]; border:2px solid [[ColorPalette::TertiaryMid]];}
+
+.popup {background:[[ColorPalette::TertiaryPale]]; color:[[ColorPalette::TertiaryDark]]; border-left:1px solid [[ColorPalette::TertiaryMid]]; border-top:1px solid [[ColorPalette::TertiaryMid]]; border-right:2px solid [[ColorPalette::TertiaryDark]]; border-bottom:2px solid [[ColorPalette::TertiaryDark]];}
+.popup hr {color:[[ColorPalette::PrimaryDark]]; background:[[ColorPalette::PrimaryDark]]; border-bottom:1px;}
+.popup li.disabled {color:[[ColorPalette::TertiaryMid]];}
+.popup li a, .popup li a:visited {color:[[ColorPalette::Foreground]]; border: none;}
+.popup li a:hover {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; border: none;}
+.popup li a:active {background:[[ColorPalette::SecondaryPale]]; color:[[ColorPalette::Foreground]]; border: none;}
+.popupHighlight {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
+.listBreak div {border-bottom:1px solid [[ColorPalette::TertiaryDark]];}
+
+.tiddler .defaultCommand {font-weight:bold;}
+
+.shadow .title {color:[[ColorPalette::TertiaryDark]];}
+
+.title {color:[[ColorPalette::SecondaryDark]];}
+.subtitle {color:[[ColorPalette::TertiaryDark]];}
+
+.toolbar {color:[[ColorPalette::PrimaryMid]];}
+.toolbar a {color:[[ColorPalette::TertiaryLight]];}
+.selected .toolbar a {color:[[ColorPalette::TertiaryMid]];}
+.selected .toolbar a:hover {color:[[ColorPalette::Foreground]];}
+
+.tagging, .tagged {border:1px solid [[ColorPalette::TertiaryPale]]; background-color:[[ColorPalette::TertiaryPale]];}
+.selected .tagging, .selected .tagged {background-color:[[ColorPalette::TertiaryLight]]; border:1px solid [[ColorPalette::TertiaryMid]];}
+.tagging .listTitle, .tagged .listTitle {color:[[ColorPalette::PrimaryDark]];}
+.tagging .button, .tagged .button {border:none;}
+
+.footer {color:[[ColorPalette::TertiaryLight]];}
+.selected .footer {color:[[ColorPalette::TertiaryMid]];}
+
+.sparkline {background:[[ColorPalette::PrimaryPale]]; border:0;}
+.sparktick {background:[[ColorPalette::PrimaryDark]];}
+
+.error, .errorButton {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::Error]];}
+.warning {color:[[ColorPalette::Foreground]]; background:[[ColorPalette::SecondaryPale]];}
+.lowlight {background:[[ColorPalette::TertiaryLight]];}
+
+.zoomer {background:none; color:[[ColorPalette::TertiaryMid]]; border:3px solid [[ColorPalette::TertiaryMid]];}
+
+.imageLink, #displayArea .imageLink {background:transparent;}
+
+.annotation {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; border:2px solid [[ColorPalette::SecondaryMid]];}
+
+.viewer .listTitle {list-style-type:none; margin-left:-2em;}
+.viewer .button {border:1px solid [[ColorPalette::SecondaryMid]];}
+.viewer blockquote {border-left:3px solid [[ColorPalette::TertiaryDark]];}
+
+.viewer table, table.twtable {border:2px solid [[ColorPalette::TertiaryDark]];}
+.viewer th, .viewer thead td, .twtable th, .twtable thead td {background:[[ColorPalette::SecondaryMid]]; border:1px solid [[ColorPalette::TertiaryDark]]; color:[[ColorPalette::Background]];}
+.viewer td, .viewer tr, .twtable td, .twtable tr {border:1px solid [[ColorPalette::TertiaryDark]];}
+
+.viewer pre {border:1px solid [[ColorPalette::SecondaryLight]]; background:[[ColorPalette::SecondaryPale]];}
+.viewer code {color:[[ColorPalette::SecondaryDark]];}
+.viewer hr {border:0; border-top:dashed 1px [[ColorPalette::TertiaryDark]]; color:[[ColorPalette::TertiaryDark]];}
+
+.highlight, .marked {background:[[ColorPalette::SecondaryLight]];}
+
+.editor input {border:1px solid [[ColorPalette::PrimaryMid]];}
+.editor textarea {border:1px solid [[ColorPalette::PrimaryMid]]; width:100%;}
+.editorFooter {color:[[ColorPalette::TertiaryMid]];}
+
+#backstageArea {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::TertiaryMid]];}
+#backstageArea a {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::Background]]; border:none;}
+#backstageArea a:hover {background:[[ColorPalette::SecondaryLight]]; color:[[ColorPalette::Foreground]]; }
+#backstageArea a.backstageSelTab {background:[[ColorPalette::Background]]; color:[[ColorPalette::Foreground]];}
+#backstageButton a {background:none; color:[[ColorPalette::Background]]; border:none;}
+#backstageButton a:hover {background:[[ColorPalette::Foreground]]; color:[[ColorPalette::Background]]; border:none;}
+#backstagePanel {background:[[ColorPalette::Background]]; border-color: [[ColorPalette::Background]] [[ColorPalette::TertiaryDark]] [[ColorPalette::TertiaryDark]] [[ColorPalette::TertiaryDark]];}
+.backstagePanelFooter .button {border:none; color:[[ColorPalette::Background]];}
+.backstagePanelFooter .button:hover {color:[[ColorPalette::Foreground]];}
+#backstageCloak {background:[[ColorPalette::Foreground]]; opacity:0.6; filter:'alpha(opacity:60)';}
+/*}}}*/</pre>
+</div>
+<div title="StyleSheetLayout">
+<pre>/*{{{*/
+* html .tiddler {height:1%;}
+
+body {font-size:.75em; font-family:arial,helvetica; margin:0; padding:0;}
+
+h1,h2,h3,h4,h5,h6 {font-weight:bold; text-decoration:none;}
+h1,h2,h3 {padding-bottom:1px; margin-top:1.2em;margin-bottom:0.3em;}
+h4,h5,h6 {margin-top:1em;}
+h1 {font-size:1.35em;}
+h2 {font-size:1.25em;}
+h3 {font-size:1.1em;}
+h4 {font-size:1em;}
+h5 {font-size:.9em;}
+
+hr {height:1px;}
+
+a {text-decoration:none;}
+
+dt {font-weight:bold;}
+
+ol {list-style-type:decimal;}
+ol ol {list-style-type:lower-alpha;}
+ol ol ol {list-style-type:lower-roman;}
+ol ol ol ol {list-style-type:decimal;}
+ol ol ol ol ol {list-style-type:lower-alpha;}
+ol ol ol ol ol ol {list-style-type:lower-roman;}
+ol ol ol ol ol ol ol {list-style-type:decimal;}
+
+.txtOptionInput {width:11em;}
+
+#contentWrapper .chkOptionInput {border:0;}
+
+.externalLink {text-decoration:underline;}
+
+.indent {margin-left:3em;}
+.outdent {margin-left:3em; text-indent:-3em;}
+code.escaped {white-space:nowrap;}
+
+.tiddlyLinkExisting {font-weight:bold;}
+.tiddlyLinkNonExisting {font-style:italic;}
+
+/* the 'a' is required for IE, otherwise it renders the whole tiddler in bold */
+a.tiddlyLinkNonExisting.shadow {font-weight:bold;}
+
+#mainMenu .tiddlyLinkExisting,
+	#mainMenu .tiddlyLinkNonExisting,
+	#sidebarTabs .tiddlyLinkNonExisting {font-weight:normal; font-style:normal;}
+#sidebarTabs .tiddlyLinkExisting {font-weight:bold; font-style:normal;}
+
+.header {position:relative;}
+.header a:hover {background:transparent;}
+.headerShadow {position:relative; padding:4.5em 0em 1em 1em; left:-1px; top:-1px;}
+.headerForeground {position:absolute; padding:4.5em 0em 1em 1em; left:0px; top:0px;}
+
+.siteTitle {font-size:3em;}
+.siteSubtitle {font-size:1.2em;}
+
+#mainMenu {position:absolute; left:0; width:10em; text-align:right; line-height:1.6em; padding:1.5em 0.5em 0.5em 0.5em; font-size:1.1em;}
+
+#sidebar {position:absolute; right:3px; width:16em; font-size:.9em;}
+#sidebarOptions {padding-top:0.3em;}
+#sidebarOptions a {margin:0em 0.2em; padding:0.2em 0.3em; display:block;}
+#sidebarOptions input {margin:0.4em 0.5em;}
+#sidebarOptions .sliderPanel {margin-left:1em; padding:0.5em; font-size:.85em;}
+#sidebarOptions .sliderPanel a {font-weight:bold; display:inline; padding:0;}
+#sidebarOptions .sliderPanel input {margin:0 0 .3em 0;}
+#sidebarTabs .tabContents {width:15em; overflow:hidden;}
+
+.wizard {padding:0.1em 1em 0em 2em;}
+.wizard h1 {font-size:2em; font-weight:bold; background:none; padding:0em 0em 0em 0em; margin:0.4em 0em 0.2em 0em;}
+.wizard h2 {font-size:1.2em; font-weight:bold; background:none; padding:0em 0em 0em 0em; margin:0.4em 0em 0.2em 0em;}
+.wizardStep {padding:1em 1em 1em 1em;}
+.wizard .button {margin:0.5em 0em 0em 0em; font-size:1.2em;}
+.wizardFooter {padding:0.8em 0.4em 0.8em 0em;}
+.wizardFooter .status {padding:0em 0.4em 0em 0.4em; margin-left:1em;}
+.wizard .button {padding:0.1em 0.2em 0.1em 0.2em;}
+
+#messageArea {position:fixed; top:2em; right:0em; margin:0.5em; padding:0.5em; z-index:2000; _position:absolute;}
+.messageToolbar {display:block; text-align:right; padding:0.2em 0.2em 0.2em 0.2em;}
+#messageArea a {text-decoration:underline;}
+
+.tiddlerPopupButton {padding:0.2em 0.2em 0.2em 0.2em;}
+.popupTiddler {position: absolute; z-index:300; padding:1em 1em 1em 1em; margin:0;}
+
+.popup {position:absolute; z-index:300; font-size:.9em; padding:0; list-style:none; margin:0;}
+.popup .popupMessage {padding:0.4em;}
+.popup hr {display:block; height:1px; width:auto; padding:0; margin:0.2em 0em;}
+.popup li.disabled {padding:0.4em;}
+.popup li a {display:block; padding:0.4em; font-weight:normal; cursor:pointer;}
+.listBreak {font-size:1px; line-height:1px;}
+.listBreak div {margin:2px 0;}
+
+.tabset {padding:1em 0em 0em 0.5em;}
+.tab {margin:0em 0em 0em 0.25em; padding:2px;}
+.tabContents {padding:0.5em;}
+.tabContents ul, .tabContents ol {margin:0; padding:0;}
+.txtMainTab .tabContents li {list-style:none;}
+.tabContents li.listLink { margin-left:.75em;}
+
+#contentWrapper {display:block;}
+#splashScreen {display:none;}
+
+#displayArea {margin:1em 17em 0em 14em;}
+
+.toolbar {text-align:right; font-size:.9em;}
+
+.tiddler {padding:1em 1em 0em 1em;}
+
+.missing .viewer,.missing .title {font-style:italic;}
+
+.title {font-size:1.6em; font-weight:bold;}
+
+.missing .subtitle {display:none;}
+.subtitle {font-size:1.1em;}
+
+.tiddler .button {padding:0.2em 0.4em;}
+
+.tagging {margin:0.5em 0.5em 0.5em 0; float:left; display:none;}
+.isTag .tagging {display:block;}
+.tagged {margin:0.5em; float:right;}
+.tagging, .tagged {font-size:0.9em; padding:0.25em;}
+.tagging ul, .tagged ul {list-style:none; margin:0.25em; padding:0;}
+.tagClear {clear:both;}
+
+.footer {font-size:.9em;}
+.footer li {display:inline;}
+
+.annotation {padding:0.5em; margin:0.5em;}
+
+* html .viewer pre {width:99%; padding:0 0 1em 0;}
+.viewer {line-height:1.4em; padding-top:0.5em;}
+.viewer .button {margin:0em 0.25em; padding:0em 0.25em;}
+.viewer blockquote {line-height:1.5em; padding-left:0.8em;margin-left:2.5em;}
+.viewer ul, .viewer ol {margin-left:0.5em; padding-left:1.5em;}
+
+.viewer table, table.twtable {border-collapse:collapse; margin:0.8em 1.0em;}
+.viewer th, .viewer td, .viewer tr,.viewer caption,.twtable th, .twtable td, .twtable tr,.twtable caption {padding:3px;}
+table.listView {font-size:0.85em; margin:0.8em 1.0em;}
+table.listView th, table.listView td, table.listView tr {padding:0px 3px 0px 3px;}
+
+.viewer pre {padding:0.5em; margin-left:0.5em; font-size:1.2em; line-height:1.4em; overflow:auto;}
+.viewer code {font-size:1.2em; line-height:1.4em;}
+
+.editor {font-size:1.1em;}
+.editor input, .editor textarea {display:block; width:100%; font:inherit;}
+.editorFooter {padding:0.25em 0em; font-size:.9em;}
+.editorFooter .button {padding-top:0px; padding-bottom:0px;}
+
+.fieldsetFix {border:0; padding:0; margin:1px 0px 1px 0px;}
+
+.sparkline {line-height:1em;}
+.sparktick {outline:0;}
+
+.zoomer {font-size:1.1em; position:absolute; overflow:hidden;}
+.zoomer div {padding:1em;}
+
+* html #backstage {width:99%;}
+* html #backstageArea {width:99%;}
+#backstageArea {display:none; position:relative; overflow: hidden; z-index:150; padding:0.3em 0.5em 0.3em 0.5em;}
+#backstageToolbar {position:relative;}
+#backstageArea a {font-weight:bold; margin-left:0.5em; padding:0.3em 0.5em 0.3em 0.5em;}
+#backstageButton {display:none; position:absolute; z-index:175; top:0em; right:0em;}
+#backstageButton a {padding:0.1em 0.4em 0.1em 0.4em; margin:0.1em 0.1em 0.1em 0.1em;}
+#backstage {position:relative; width:100%; z-index:50;}
+#backstagePanel {display:none; z-index:100; position:absolute; width:90%; margin:0em 3em 0em 3em; padding:1em 1em 1em 1em;}
+.backstagePanelFooter {padding-top:0.2em; float:right;}
+.backstagePanelFooter a {padding:0.2em 0.4em 0.2em 0.4em;}
+#backstageCloak {display:none; z-index:20; position:absolute; width:100%; height:100px;}
+
+.whenBackstage {display:none;}
+.backstageVisible .whenBackstage {display:block;}
+/*}}}*/</pre>
+</div>
+<div title="StyleSheetLocale">
+<pre>/***
+StyleSheet for use when a translation requires any css style changes.
+This StyleSheet can be used directly by languages such as Chinese, Japanese and Korean which need larger font sizes.
+***/
+/*{{{*/
+body {font-size:0.8em;}
+#sidebarOptions {font-size:1.05em;}
+#sidebarOptions a {font-style:normal;}
+#sidebarOptions .sliderPanel {font-size:0.95em;}
+.subtitle {font-size:0.8em;}
+.viewer table.listView {font-size:0.95em;}
+/*}}}*/</pre>
+</div>
+<div title="StyleSheetPrint">
+<pre>/*{{{*/
+ at media print {
+#mainMenu, #sidebar, #messageArea, .toolbar, #backstageButton, #backstageArea {display: none ! important;}
+#displayArea {margin: 1em 1em 0em 1em;}
+/* Fixes a feature in Firefox 1.5.0.2 where print preview displays the noscript content */
+noscript {display:none;}
+}
+/*}}}*/</pre>
+</div>
+<div title="PageTemplate">
+<pre>&lt;!--{{{--&gt;
+&lt;div class='header' macro='gradient vert [[ColorPalette::PrimaryLight]] [[ColorPalette::PrimaryMid]]'&gt;
+&lt;div class='headerShadow'&gt;
+&lt;span class='siteTitle' refresh='content' tiddler='SiteTitle'&gt;&lt;/span&gt;&amp;nbsp;
+&lt;span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'&gt;&lt;/span&gt;
+&lt;/div&gt;
+&lt;div class='headerForeground'&gt;
+&lt;span class='siteTitle' refresh='content' tiddler='SiteTitle'&gt;&lt;/span&gt;&amp;nbsp;
+&lt;span class='siteSubtitle' refresh='content' tiddler='SiteSubtitle'&gt;&lt;/span&gt;
+&lt;/div&gt;
+&lt;/div&gt;
+&lt;div id='mainMenu' refresh='content' tiddler='MainMenu'&gt;&lt;/div&gt;
+&lt;div id='sidebar'&gt;
+&lt;div id='sidebarOptions' refresh='content' tiddler='SideBarOptions'&gt;&lt;/div&gt;
+&lt;div id='sidebarTabs' refresh='content' force='true' tiddler='SideBarTabs'&gt;&lt;/div&gt;
+&lt;/div&gt;
+&lt;div id='displayArea'&gt;
+&lt;div id='messageArea'&gt;&lt;/div&gt;
+&lt;div id='tiddlerDisplay'&gt;&lt;/div&gt;
+&lt;/div&gt;
+&lt;!--}}}--&gt;</pre>
+</div>
+<div title="ViewTemplate">
+<pre>&lt;!--{{{--&gt;
+&lt;div class='toolbar' macro='toolbar [[ToolbarCommands::ViewToolbar]]'&gt;&lt;/div&gt;
+&lt;div class='title' macro='view title'&gt;&lt;/div&gt;
+&lt;div class='subtitle'&gt;&lt;span macro='view modifier link'&gt;&lt;/span&gt;, &lt;span macro='view modified date'&gt;&lt;/span&gt; (&lt;span macro='message views.wikified.createdPrompt'&gt;&lt;/span&gt; &lt;span macro='view created date'&gt;&lt;/span&gt;)&lt;/div&gt;
+&lt;div class='tagging' macro='tagging'&gt;&lt;/div&gt;
+&lt;div class='tagged' macro='tags'&gt;&lt;/div&gt;
+&lt;div class='viewer' macro='view text wikified'&gt;&lt;/div&gt;
+&lt;div class='tagClear'&gt;&lt;/div&gt;
+&lt;!--}}}--&gt;</pre>
+</div>
+<div title="EditTemplate">
+<pre>&lt;!--{{{--&gt;
+&lt;div class='toolbar' macro='toolbar [[ToolbarCommands::EditToolbar]]'&gt;&lt;/div&gt;
+&lt;div class='title' macro='view title'&gt;&lt;/div&gt;
+&lt;div class='editor' macro='edit title'&gt;&lt;/div&gt;
+&lt;div macro='annotations'&gt;&lt;/div&gt;
+&lt;div class='editor' macro='edit text'&gt;&lt;/div&gt;
+&lt;div class='editor' macro='edit tags'&gt;&lt;/div&gt;&lt;div class='editorFooter'&gt;&lt;span macro='message views.editor.tagPrompt'&gt;&lt;/span&gt;&lt;span macro='tagChooser excludeLists'&gt;&lt;/span&gt;&lt;/div&gt;
+&lt;!--}}}--&gt;</pre>
+</div>
+<div title="GettingStarted">
+<pre>To get started with this blank TiddlyWiki, you'll need to modify the following tiddlers:
+* SiteTitle &amp; SiteSubtitle: The title and subtitle of the site, as shown above (after saving, they will also appear in the browser title bar)
+* MainMenu: The menu (usually on the left)
+* DefaultTiddlers: Contains the names of the tiddlers that you want to appear when the TiddlyWiki is opened
+You'll also need to enter your username for signing your edits: &lt;&lt;option txtUserName&gt;&gt;</pre>
+</div>
+<div title="OptionsPanel">
+<pre>These InterfaceOptions for customising TiddlyWiki are saved in your browser
+
+Your username for signing your edits. Write it as a WikiWord (eg JoeBloggs)
+
+&lt;&lt;option txtUserName&gt;&gt;
+&lt;&lt;option chkSaveBackups&gt;&gt; SaveBackups
+&lt;&lt;option chkAutoSave&gt;&gt; AutoSave
+&lt;&lt;option chkRegExpSearch&gt;&gt; RegExpSearch
+&lt;&lt;option chkCaseSensitiveSearch&gt;&gt; CaseSensitiveSearch
+&lt;&lt;option chkAnimate&gt;&gt; EnableAnimations
+
+----
+Also see [[AdvancedOptions]]</pre>
+</div>
+<div title="ImportTiddlers">
+<pre>&lt;&lt;importTiddlers&gt;&gt;</pre>
+</div>
+</div>
+<!--POST-SHADOWAREA-->
+<div id="storeArea">
+<div title="17 March 2009" modifier="DavidCrosby" created="200903171924" tags="journal" changecount="1">
+<pre>Type the text for '17 March 2009'</pre>
+</div>
+<div title="AutomatedTests" modifier="DavidCrosby" created="200904071852" modified="200904080324" changecount="7">
+<pre>!! Unit Tests
+Unit tests are written per class.  Chiefly, they specify and assert the behavior of an individual class.  Classes like CallHandler, which rely heavily on other objects like Logger, PhoneMenu and Evergreen, are tested using mock objects (this project is utilizing {{{Test::MockObject}}} to accomplish this).  Assertions are made about which methods on these mocks are called by the object-under-test, which arguments are passed, and how the results are handled.
+
+Eg, the unit tests for {{{lib/TelephoneRenewals/CallHandler.pm}}} are in {{{t/tlib/CallHandlerTest.pm}}}.
+
+Our tests are written xUnit style -- a group of tests are authored by subclassing {{{Test::Unit::TestCase}}} containing methods with names beginning with {{{test_}}}.  Some project-specific helper functions have been written to instrument mock objects and make certain assertions... these are written in {{{TestHelper}}}, and all our unit test cases subclass {{{TestHelper}}} which subclasses {{{Test::Unit::TestCase}}}.
+
+The file {{{t/tlib/UnitTestSuite.pm}}} is a self-generating test suite... it discovers all files in {{{t/tlib/*Test.pm}}} and loads them into the test suite.  The bootstrap script {{{t/unit_tests.pl}}} can be used to invoke the suite (but it doesn't summarize results or set shell exit status based on failire.  For that, read on...)
+
+The script {{{run_tests.pl}}} is a wrapper AROUND {{{t/unit_tests.pl}}} which summarizes the pass/fail count and sets shell exit status appropriate to failure/success.  ''This would be useful in a continuous integration scenario.''
+
+* Shell exit is 0 when all tests pass
+* Shell exit is 1 when any test fails
+To run the unit test suit from the console:
+
+{{{perl run_tests.pl}}}
+{{{
+STARTING TEST RUN
+1..52
+ok PASS test_RenewalAnnouncer_should_announce_successful_renewal
+ok PASS test_RenewalAnnouncer_should_log_and_announce_system_error_for_error_status
+ok PASS test_RenewalAnnouncer_should_announce_failure_because_of_limits
+ok PASS test_RenewalAnnouncer_should_announce_failure_because_of_barcode
+ok PASS test_Logger_should_log_a_timestamped_info_message
+ok PASS test_Logger_should_log_a_timestamped_error_message
+...
+!!! FAILURES !!!
+51 passed, 1 FAILED
+}}}
+
+On top of that, there's a Rakefile that executes {{{run_tests.pl}}}... this is here mainly to support ContinuousIntegration via DCI.
+
+!! Integration tests
+(coming soon -- an automated test that exercises the full system minus phones, hitting a real Evergreen service, for a few realistic scenarios.)
+</pre>
+</div>
+<div title="CallHandlerWorkFlow" modifier="DavidCrosby" created="200904021554" modified="200904021555" changecount="2">
+<pre>In thinking through what happens when someone says &quot;renew all&quot; and
+there are some (or none) failed renewals, I came up with the attached
+workflow.  When everything's ok, the caller may decide to hear details
+on the renewed items.  But if at least one item failed, it seems like
+a good idea to give details on all items, pass or fail, without asking
+the caller if they want to hear about it first.
+
+Diagram PDF: http://svn.grpl.org/mieg/phone_renewal/browser/doc/renew_all_items_workflow.pdf</pre>
+</div>
+<div title="CodeDesign" modifier="DavidCrosby" created="200904071928" modified="200904071933" changecount="4">
+<pre>The Phone Renewal system is composed of a system of collaborating objects.
+
+Most classes reside under the {{{TelephoneRenewals}}} Perl package, so when I say {{{CallHandler}}} I'm really talking about {{{TelephoneRenewals::CallHandler}}}, which resides in {{{lib/TelephoneRenewals/CallHandler.pm}}}.
+
+The system is launched via the {{{lib/telephone_renewal_menu.agi.pl}}} script, which instantiates an {{{ObjectContext}}} (our super factory, which knows how to build and compose all objects and their dependencies) and procures a {{{CallHandler}}} instance, which implements the core business logic of the app via a single call, {{{$call_handler-&gt;handle_call}}}.
+
+{{{CallHandler}}}'s constructor contains this code snippet:
+{{{
+sub new {
+  my ($class, %args) = @_;
+  ...
+  foreach my $varname qw(evergreen_renewal phone_menu all_items_renewer individual_items_renewer logger) {
+    ...
+    $self-&gt;{$varname} = $args{$varname};
+  }
+  ...(this method dynamically assigns incoming values from an argument hash to internal instance variabls of the same name)
+}}}
+which tells us that {{{CallHandler}}} is composed of objects {{{evergreen_renewal}}}, {{{phone_menu}}}, {{{logger}}}, etc.
+&gt; ''Convention says that these components have key names and instance variable names written in underscore format corresponding to their class names.''
+We can then infer that the {{{evergreen_renewal}}} object is of type {{{EvergreenRenewal}}}, so we can refer to that class for more information.
+
+The {{{ObjectContext}}} supplies its targets with the same references all around -- this means that if several classes are implemented in terms of {{{EvergreenRenewal}}}, they'll be given references to ''the same instance of the evergreen_renewal object''.  This facilitates inter-object communication.
+
+See also AutomatedTests and ManualTests.
+</pre>
+</div>
+<div title="ConfigurationAndDeployment" modifier="DavidCrosby" created="200904071504" modified="200904071526" changecount="17">
+<pre>Essential deployment and configuration instructions are homed in the README.txt file in the project root.
+''Most up-to-date deployment specifics are probably in the README, so be sure to double check the actual file''
+
+See also LoggingAndErrorNotification
+
+http://svn.grpl.org/mieg/phone_renewal/browser/README.txt
+!! Deploy application code
+{{{deploy_app.pl}}}
+Copies the {{{lib}}} directory as {{{/var/lib/asterisk/agi-bin/phone_renewals}}}
+
+!! Deploy sound files
+{{{deploy_sounds.pl}}}
+Copies the {{{sounds}}} directory as {{{/var/lib/asterisk/sounds/phone_renewals}}}
+
+!! Store updated sounds to SVN
+{{{store_updated_sounds.pl}}}
+Copies sound files FROM {{{/var/lib/asterisk/sounds/phone_renewals}}} into {{{sounds}}}.
+This is because using PromptManager to record new sound files operates on the deployed sounds directory, and you really ought to back those up in svn, especially if you need to re-deploy at a later time.  This practice will let you treat the SVN repository as the official source of sounds, lets you reinstall the system on another box, etc.
+
+!! Asterisk dial plan setup
+
+The phone renewal perl app is designed to handle the entire incoming call from Answer to Hangup, so the dial plan is a no-brainer.
+
+Edit {{{/etc/asterisk/extensions.conf}}} and create a context/extension that runs the {{{telephone_renewal_menu.agi.pl}}} script:
+{{{
+[phone-renewals]
+exten =&gt; _X.,1,AGI(phone_renewals/telephone_renewal_menu.agi.pl) ; matches any extension.
+}}}
+To provide admin access to, eg, PromptManager, and a testing mode of the app:
+{{{
+[phone-renewals-admin]
+exten =&gt; 100,1,AGI(phone_renewals/prompt_manager.agi.pl)
+exten =&gt; 200,1,AGI(phone_renewals/test_against_fake_evergreen.pl)
+exten =&gt; 300,1,AGI(phone_renewals/telephone_renewal_menu.agi.pl)
+}}}
+
+!! Configuring application settings
+Configure email notification settings, log file, etc by editing the main script:
+
+{{{lib/telephone_renewal_menu.agi.pl}}}
+{{{
+  ...
+  my $call_handler = $objectContext-&gt;get_call_handler(
+    smtp_host_and_port =&gt; &quot;localhost:25&quot;,
+    error_email_recipients =&gt; [
+      'crosby at atomicobject.com',
+      'bott at grpl.org',
+      'dkyle at grpl.org'
+    ],
+    error_email_from  =&gt; 'GRPL &lt;telephonerenewals at grpl.org&gt;',
+    error_email_subject  =&gt; '[ERROR] Telephone Renewal Error',
+  );
+  ...
+}}}
+
+The {{{log_file}}} and {{{sounds_dir}}} settings have useful defaults.  For reference, they're configured in the AppConfig class:
+
+{{{lib/TelephoneRenewals::AppConfig.pm}}}
+{{{
+lib/TelephoneRenewals/AppConfig.pm
+  ...
+  my $self = {
+    log_file =&gt; '/var/log/asterisk/telephone_renewals.log',
+    sounds_dir =&gt; '/var/lib/asterisk/sounds/phone_renewals',
+    smtp_host_and_port =&gt; 'localhost:25',
+    error_email_recipients =&gt; [ &quot;not set&quot; ],
+    error_email_from  =&gt; 'GRPL &lt;telephonerenewals at grpl.org&gt;',
+    error_email_subject  =&gt; '[ERROR] Telephone Renewal Error',
+  };
+  ...
+}}}</pre>
+</div>
+<div title="ContactInfo" modifier="DavidCrosby" created="200903171919" modified="200903171919" changecount="2">
+<pre>Bill Ott 
+bott at grpl.org
+616 988 5480 (616 988 5402 ext 5480)
+
+Doug Kyle
+dkyle at grpl.org
+616 988 5402 ext 5481
+
+Main Library
+111 Library Street NE
+Grand Rapids MI 49503
+
+David Crosby
+Atomic Object LLC
+crosby at atomicobject.com
+Office: 616 776 6020</pre>
+</div>
+<div title="ContinuousIntegration" modifier="DavidCrosby" created="200904080316" modified="200904081246" changecount="5">
+<pre>!! What's DCI?
+DCI (a self-contained continuous build server) is built into the project under {{{continuous_integration}}}.
+It doesn't //have// to live there... you could move this directory to a location outside of the project.  It's just here to lower the bar for entry.
+
+DCI runs as a demon that watches your project via svn.  When a checkin is made, DCI updates to the latest version of the project then executes the build (for us, this is a set of AutomatedTests, there's no build artifact per se.)  The build fails if any tests do not pass.
+
+You can monitor the current status of the project and browse test output via its companion web interface, the &quot;mini dci monitor&quot; process, on port 4444 of the machine running the server, eg http://phoneserver:4444.
+
+DCI is written in Ruby, and expects to be able to build the project via its Rakefile.  Phone renewals has a Rakefile in its project root; all it does is delegate to the {{{run_tests.pl}}} script.
+
+!! DCI Setup
+Dependencies:
+* Ruby 1.8
+* Ruby Gems (think CPAN)
+* Rake
+** Installed via: {{{sudo gem install rake}}}
+
+To move the DCI server to a more neutral location outside the phone renewal project (recommended, especially if you'd like to put other projects under continuous integration), just move or copy the entire {{{continuous_integration}}} directory to some other place, eg,
+{{{
+svn export continuous_integration ~/dci_server
+}}}
+(Using svn export will drop all the {{{.svn}}} metadata directories.)
+
+To setup your system to launch DCI at system boot time via a unix init script:
+{{{
+  cd continuous_integration
+  sudo rake install_init_script user=(your_unix_userid)
+  sudo /etc/init.d/dci_server start
+}}}
+(This installation builds the init script from a template, substituting the user id and path to your installation of the DCI app.)
+The init script is the best way to hand start/stop the server; it handles both the DCI server proper and the web monitor.
+
+To uninstall the init script:
+{{{
+  cd continuous_integration
+  sudo rake remove_init_script user=(your_unix_userid)
+}}}
+
+!! Configuration
+DCI can handle multiple projects.  To configure a project to be built/tested, update the config file:
+
+{{{continuous_integration/config/my_projects.rb}}}
+{{{
+builder &lt;&lt; Project.new(
+  :name =&gt; 'GRPL Phone Renewal',
+  :repository =&gt; 'svn://svn.grpl.org/mieg/phone_renewal',
+  :working_copy =&gt; context.proj_dir('phone_renewal'),
+  :log_dir =&gt; context.log_dir('phone_renewal')
+)
+}}}
+&gt; ''Restart DCI after updating the projects file:'' {{{sudo /etc/init.d/dci_server restart}}}
+
+!! Under the hood
+* DCI uses SVN to (initially) checkout its own private working copy of its configured projects
+* then watches them for updates on a 30-second cycle.  
+* If a project has any updates, the Rakefile is execute (we call this &quot;building&quot;, though for dynamic languages that don't really have binary build artifacts, this boils down to running the test suite)
+* If the build exits cleanly, it's marked with &quot;success&quot;
+* Otherwise, the build is marked &quot;fail&quot;
+* Using the web monitor, you can view the build output and determine cause of failure (you can review successful builds too.)
+** This is generally what you'd see on the command line
+** DCI makes no presumption or interpretation of build output
+** The exit status of running Rake is the pass/fail determinant: 0 exit is pass, non-zero exit is fail.
+* History of all builds is kept
+** ''YOU WANT TO KEEP AN EYE ON THIS...'' after a long time, you end up with a great deal of build history.  DCI doesn't rotate-out old data.
+** {{{continuous_integration/data/logs/phone_renewal/build_0042.log}}} contains the raw build output
+** {{{continuous_integration/data/logs/phone_renewal/build_0042.yml}}} contains metadata about the build:
+*** name
+*** status (success/fail/building)
+*** start_time
+*** end_time
+*** build_time (in seconds)
+*** build_num
+*** revision (from svn)
+
+You can clean out old build history by deleting the log and yml files.  
+&gt; In a pinch (if messing with the files under data/ has hosed your DCI server), shutdown DCI and {{{rm -rf data}}}, restart serer.  Your project will be checked out anew and rebuilt.</pre>
+</div>
+<div title="DavidCrosby" modifier="DavidCrosby" created="200903171919" changecount="1">
+<pre>crosby at atomicobject.com</pre>
+</div>
+<div title="DefaultTiddlers" modifier="DavidCrosby" created="200903171915" modified="200904081247" changecount="4">
+<pre>PhoneRenewals
+DevelopmentNotes
+ContactInfo</pre>
+</div>
+<div title="DevelopmentNotes" modifier="DavidCrosby" created="200904080301" modified="200904080358" changecount="3">
+<pre>ProjectLayout
+CodeDesign
+AutomatedTests
+ManualTests
+ContinuousIntegration
+PerlModuleDependencies
+
+EvergreenRenewalPerlModule
+RenewalResultStructure
+CallHandlerWorkFlow</pre>
+</div>
+<div title="EvergreenRenewalPerlModule" modifier="DougKyle" created="200904021552" modified="200905011504" changecount="6">
+<pre>Doug Kyle and Bill Ott wrote EvergreenRenewal.pm, ERGateway.pm and modified various file written by Dave Crosby to fit our integration with Evergreen.
+
+EvergreenRenewal.pm contains renewal logic and ERGateway.pm contains OSRF Gateway calls.  The Evergreen integration could have done other ways, but we guess that the OSRF gateway implementation will be most portable.
+
+! Renewal results as compound data structures
+See RenewalResultStructure for a description of how the {{{EvergreenRenewal}}} module is expected to report on success or failure for item renewal, or a list of renewals.
+
+!Starting implementation of EvergreenRenewal module
+(email from Dave to Bill and Doug, Apr 2 2009)
+Hi guys,
+
+Attached is a copy of the EvergreenRenewal perl module (stubbed with
+comments) that we peeked at yesterday.  As I described earlier, this
+is the &quot;wishful thinking&quot; interface for Evergreen utility access, and
+the wishing is done by CallHandler (and his two new helpers,
+IndividualItemsRenewer and AllItemsRenewer).
+
+What I need from you guys is guidance and/or hard code that starts to
+answer the functions outlined in EvergreenRenewal.
+
+I brewed up a data structure for encapsulating the result of
+individual and multiple renewals, which are described in the comments
+within EvergreenRenewal.
+
+The home of these files is in the phone_renewal repository at:
+
+http://svn.grpl.org/mieg/phone_renewal/browser/lib/TelephoneRenewals/EvergreenRenewal.pm
+http://svn.grpl.org/mieg/phone_renewal/browser/lib/TelephoneRenewals/RenewalResult.pm
+(and coming soon)
+http://svn.grpl.org/mieg/phone_renewal/browser/lib/TelephoneRenewals/RenewalResultList.pm
+(maybe RenewalResultSet?... I'll get this done soon and keep you
+updated.)
+
+A diagram is stored at:
+http://svn.grpl.org/mieg/phone_renewal/browser/doc/renewal_result_data_structures.pdf
+
+I'm also tracking this stuff to some extent in the self-contained
+project wiki file:
+http://svn.grpl.org/mieg/phone_renewal/browser/doc/project_wiki.html
+
+(It may be a better idea for me to transfer such things into the Trac
+wiki for this project; currently I don't have login for that Trac,
+however.)
+
+Thanks!
+/Dave
+
+
+!Exceptions and errors from EvergreenRenewal
+(another email, same day)
+
+As you work on those functions, recall that the CallHandler is
+designed to handle actual exceptions by jumping to the end of the
+menu, announcing that an unexpected error occurred, saying &quot;goodbye&quot;
+(and probably something like &quot;for further assistance call our desk at
+1-800-whatever&quot;, as part of the standard exit announcement) and then
+hanging up.
+
+This means it's up to you to decide in EvergreenRenewal whether or not
+to return an &quot;expected&quot; failure (such as an &quot;invalid&quot; string return
+for bad library card number) or to raise an actual exception via the
+Perl function &quot;croak&quot;, such as:
+
+croak(&quot;Lost connection to Evergreen&quot;);
+
+or something.  As part of the blanket error handler in CallHandler,
+I'm going to implement a logger.  Calling patrons of course won't be
+bothered with the details, but you shouldn't have to worry about
+logging inside EvergreenRenewal itself.  (If you find that you'd
+really like to log something from there, let me know... the Logger
+component I intend to write will be reusable wherever we need it.)
+
+In the case where the Evergreen API raises an exception (via croak or
+die), and we desire to translate that into an expected error, I've
+been using this strategy to capture and handle exceptions:
+
+eval {
+ $something-&gt;that_might(&quot;explode&quot;);
+ # nothing from this point until the end of the eval block will run
+if the preceding line raises an error
+};
+if ($@) {
+ # $a will be undefined if that eval block finished safely, otherwise
+it'll be a string containing an error message
+}
+
+</pre>
+</div>
+<div title="FakeEvergreenRenewal" modifier="DavidCrosby" created="200904072111" modified="200904072112" changecount="3">
+<pre>Provides a false implementation of the methods normally used to interface with the Evergreen system.
+If you're testing via command-line, you don't need to enter the full 14 digits for lib card # or barcode.  See ManualTests for more info.
+
+Inputs that cause certain kinds of behavior:
+* Library card numbers that begin with 2 will be accepted, all others will be unrecognized.  Length doesn't matter.
+** Any card number beginning with 21 will have two items out.
+** Any card number beginning with 22 will have 5 items out.
+* Renewing all items
+** If you use a card # starting with 21, both items will renew Ok
+** If you use a card # starting with 22, you'll get three varieties of failure (unknown barcode, renewal limitation, and unexpected error) and 2 ok renewals
+* Renewing individual items (regardless of lib card #)
+** Barcode starts with 4: unkown barcode
+** Barcode starts with 5: no renewals allowed
+** Barcode starts with 6: croaks w unexpected error (to test the blanket error capturing in {{{CallHandler}}})
+** All other barcodes will renew ok
+</pre>
+</div>
+<div title="LoggingAndErrorNotification" modifier="DavidCrosby" created="200904071527" modified="200904071534" changecount="7">
+<pre>!! Logging
+The app writes to a custom log file, tracking calls, renewal activity and errors.
+&gt; ''THIS LOG SHOULD BE TARGETED FOR ROTATION'' -- the app won't do it for you
+
+{{{/var/log/asterisk/telephone_renewals.log}}}
+{{{
+[Sun Apr  5 03:34:25 EDT 2009] - INFO - Handling new call ******************************
+[Sun Apr  5 03:34:37 EDT 2009] - INFO - Patron 22876876545666 has 5 items out.
+[Sun Apr  5 03:34:46 EDT 2009] - INFO - Patron 22876876545666 renewing all items...
+[Sun Apr  5 03:34:50 EDT 2009] - INFO - Renewal FAILED: 37777777777777 - unknown barcode
+[Sun Apr  5 03:35:03 EDT 2009] - INFO - Renewal FAILED: 38888888888888 - no renewals allowed
+[Sun Apr  5 03:35:09 EDT 2009] - INFO - Renewal FAILED: 34545454545458 - ouch
+[Sun Apr  5 03:35:09 EDT 2009] - ERROR - Renewal result contained unexpected status 'ouch' for barcode 34545454545458
+[Sun Apr  5 03:35:09 EDT 2009] - ERROR - TelephoneRenewals::Emailer is disabled; set AppConfig smtp_host_and_port to enable it. at /var/lib/asterisk/agi-bin/phone_renewals/TelephoneRenewals/Logger.pm line 55
+
+[Sun Apr  5 03:35:22 EDT 2009] - INFO - Renewed ok: 31111111111111
+[Sun Apr  5 03:35:28 EDT 2009] - INFO - Renewed ok: 32222222222222
+[Sun Apr  5 03:35:33 EDT 2009] - INFO - Hanging up.
+}}}
+
+Logging is accomplished via the {{{Logger}}} class, which utilizes a {{{LogChannel}}} (to abstract the file manipulation) and an {{{Emailer}}} (for sending error notifications to admins).
+
+!! Error notification via Email
+When the main app encounters an unexpected failure, the error is logged via {{{$logger-&gt;log_and_email_error(&quot;the msg&quot;)}}} and, if the {{{Emailer}}} is enabled (and working properly) an email notification is sent to a list of admin email addresses.  (See ConfigurationAndDeployment to configure the emailer settings.)
+
+Sample email notification:
+{{{
+From: GRPL &lt;telephonerenewals at grpl.org&gt;
+To: crosby at atomicobject.com
+Subject: [ERROR] Telephone Renewal Error
+
+An error occurred in the GRPL telephone renewal system:
+
+[Sun Apr  5 03:42:29 EDT 2009] - ERROR - Rigged to explode -- barcode 18776666555544.  This is an intentionally unhandled error for testing purposes.
+ at /var/lib/asterisk/agi-bin/phone_renewals/TelephoneRenewals/IndividualItemsRenewer.pm line 42
+}}}
+
+
+</pre>
+</div>
+<div title="MainMenu" modifier="DavidCrosby" created="200903171858" modified="200904081308" changecount="26">
+<pre>PhoneRenewals
+[[Config/Deploy|ConfigurationAndDeployment]]
+PromptManager
+DevelopmentNotes
+SvnRepository
+PerlAgiModuleInstall
+ContactInfo
+
+WikiMarkupReference
+[[Edit|MainMenu]]</pre>
+</div>
+<div title="ManualTests" modifier="DavidCrosby" created="200904071845" modified="200904071851" changecount="6">
+<pre>* {{{lib/test_against_fake_asterisk_and_fake_evergreen.pl}}}
+* {{{lib/test_against_fake_asterisk.pl}}}
+* {{{lib/test_against_fake_evergreen.pl}}}
+Meaning...
+!! test_against_fake_asterisk_and_fake_evergreen - Core logic exercise, minus database or phone
+
+You can run the application with a faked out phone menu and Evergreen interface.  This exercises core logic behavior as implemented by CallHandler and its renewal delegates.  No assertions are made, you just get a chance to play with the system without using the phone or a real database.
+
+See FakeEvergreenRenewal for info on what inputs you can use to trigger various simulated Evergreen behaviors.
+
+{{{perl lib/test_against_fake_asterisk_and_evergreen.pl}}}
+{{{
+(PhoneMenu - Initialized)
+Thanks for calling the Grand Rapids Public Library telephone renewal system.
+Please enter your 14 digit library card number: 21333....
+You currently have 2 items checked out.
+To renew all of your items, press 1 now.  To renew individual items, press 2, or press 0 to exit: 2
+Please enter the item's 14 digit barcode: 3219....
+Item with barcode ending 9.... has been renewed.
+To renew another item, press 1.  If you're done renewing items, press 0: 1
+Please enter the item's 14 digit barcode: 500012345
+Item with barcode ending 12345 may not be renewed at this time.
+To renew another item, press 1.  If you're done renewing items, press 0: 0
+Thanks for calling GRPL.  If you need further assistance, please call us at 1-800-GRPL. Goodbye!
+}}}
+
+!! test_against_fake_asterisk - Core logic plus real database, no phone
+{{{perl lib/test_against_fake_asterisk.pl}}}
+* Also runs in the console, but this time we're really connecting to Evergreen.
+
+!! test_against_fake_evergreen - Normal app using phone, but no Evergreen database
+{{{perl lib/test_against_fake_evergreen.pl}}}
+* Runs in Asterisk (See ConfigurationAndDeployment for sample of how to set this up).
+* Uses the same faked-out Evergreen module as the first described manual test
+* See FakeEvergreenRenewal for info on what inputs you can use to trigger various simulated Evergreen behaviors.
+</pre>
+</div>
+<div title="PerlAgiModuleInstall" modifier="DavidCrosby" created="200903240137" modified="200904071545" changecount="6">
+<pre>CPAN and docs for the AGI module: http://search.cpan.org/dist/asterisk-perl/lib/Asterisk/AGI.pm
+
+But my CPAN isn't working properly, so I did this:
+
+Download: http://asterisk.gnuinter.net/files/asterisk-perl-0.10.tar.gz
+
+Ran these shell commands:
+{{{
+tar xvfz asterisk-perl-0.10.tar.gz
+cd asterisk-perl-0.10
+perl Makefile.PL
+make all
+sudo make install
+}}}
+
+Sanity check: (will explode if module is not available)
+{{{
+perl -e &quot;use Asterisk::AGI;&quot;
+}}}
+</pre>
+</div>
+<div title="PerlModuleDependencies" modifier="DavidCrosby" created="200904071547" modified="200904071607" changecount="9">
+<pre>Though the custom source code for the phone renewal system is self-contained, there are a few additional Perl modules that are expected to be installed on your system.  I got ALL of these from CPAN, so if your local CPAN command-line client is working properly, Bob's your uncle.  I manually downloaded and installed each of them because:
+* I wanted a clear record of what I was depending on
+* My CPAN client is misconfigured
+
+Most of these guys can be built and installed like this:
+{{{
+tar xvzf Test-Unit-0.25.tar.gz
+perl Makefile.PL
+make
+sudo make install
+}}}
+
+SOME of these guys use the newer {{{Build.PL}}} build system.  (You need to first install {{{Module-Build-0.32.tar.gz}}}).
+{{{
+perl Build.PL
+./Build
+./Build test
+sudo ./Build install
+}}}
+
+!! Module archives stored in vendor/
+&gt; ''Sorry, I forgot the interdepencies of these modules...'' watch the build setup output, a module will scream about its deps, leading you down the bunny trail...
+* {{{asterisk-perl-0.10.tar.gz}}}
+** Interface to Asterisk via the AGI protocol
+
+* {{{MIME-Lite-3.024.tar.gz}}}
+** Used by {{{Emailer}}} class to send email notifications
+
+* {{{Module-Build-0.32.tar.gz}}}
+** Some modules need this to build via {{{Build.PL}}}
+
+The following modules are in support of the automated tests... they are not required by the app itself.
+* {{{Test-Unit-0.25.tar.gz}}}
+* {{{Test-Simple-0.86.tar.gz}}}
+* {{{Sub-Uplevel-0.2002.tar.gz}}}
+* {{{Test-Exception-0.27.tar.gz}}}
+* {{{Test-MockObject-1.09.tar.gz}}}
+* {{{UNIVERSAL-can-1.12.tar.gz}}}
+* {{{UNIVERSAL-isa-1.01.tar.gz}}}
+* {{{Class-Inner-0.1.tar.gz}}}
+* {{{Devel-Symdump-2.08.tar.gz}}}
+* {{{Error-0.17015.tar.gz}}}
+* {{{SMTP-Server-1.1.tar.gz}}}
+
+* {{{File-Path-Expand-1.02.tar.gz}}}
+** Hmmmm... this is probably not needed.
+</pre>
+</div>
+<div title="PhoneRenewals" modifier="DavidCrosby" created="200903171916" modified="200904081308" changecount="11">
+<pre>This is the project wiki for the Telephone Renewals project.
+Of interest:
+* ConfigurationAndDeployment - ''Start here.'' Explains how to build/test/deploy the phone renewals application.
+* PromptManager - how to manage and record sound files
+* LoggingAndErrorNotification - info about the logging and error emailer
+* DevelopmentNotes - project layout, code design, automated and manual tests, module dependencies etc.
+** EvergreenRenewalPerlModule and RenewalResultStructure - (April 2009) notes on to-be-done implementation of EvergreenRenewal module</pre>
+</div>
+<div title="ProjectLayout" modifier="DavidCrosby" created="200904071537" modified="200904071544" changecount="8">
+<pre>The {{{lib}}} directory contains the entire application, ready to be copied into place (see ConfigurationAndDeployment).
+In addition, the {{{sounds}}} directory is meant to deploy and backup the system prompts.
+
+Automated tests live in the {{{t}}} subdirectory.  See AutomatedTests and ManualTests.
+
+The {{{tools}}} dir houses development scripts (eg {{{new_class.pl}}}, which stubs out a new Perl module for a class, and its corresponding unit test).
+
+The root of the project contains the main administrative scripts, such as
+* deploy_app.pl
+* deploy_sounds.pl
+* store_updated_sounds.pl
+* print_sound_index.pl (See PromptManagerSoundList)
+See DevelopmentProcess
+&gt; ''As of April 7... this tree is only for reference, it's probably already out of date''
+{{{
+|-- README.txt
+|-- deploy_app.pl
+|-- deploy_sounds.pl
+|-- doc
+|   |-- GRPL_Phone_Renewals_Proposal.pdf
+|   |-- Telephone_renewal_notes.pdf
+|   |-- example_dialplan_and_sip_config.txt
+|   |-- project_wiki.html
+|   |-- renew_all_items_workflow.pdf
+|   `-- renewal_result_data_structures.pdf
+|-- lib
+|   |-- TelephoneRenewals
+|   |   |-- AllItemsRenewer.pm
+|   |   |-- AppConfig.pm
+|   |   |-- CallHandler.pm
+|   |   |-- Emailer.pm
+|   |   |-- EvergreenRenewal.pm
+|   |   |-- Fakes
+|   |   |   |-- FakeEvergreenRenewal.pm
+|   |   |   `-- FakePhoneMenu.pm
+|   |   |-- IndividualItemsRenewer.pm
+|   |   |-- LogChannel.pm
+|   |   |-- Logger.pm
+|   |   |-- ObjectContext.pm
+|   |   |-- PhoneMenu.pm
+|   |   |-- PromptManager.pm
+|   |   |-- PromptStore.pm
+|   |   |-- RenewalAnnouncer.pm
+|   |   |-- RenewalLogger.pm
+|   |   |-- RenewalResult.pm
+|   |   |-- RenewalResultSet.pm
+|   |   `-- SoundIndexPrinter.pm
+|   |-- prompt_manager.agi.pl
+|   |-- telephone_renewal_menu.agi.pl
+|   |-- test_against_fake_asterisk.pl
+|   |-- test_against_fake_asterisk_and_fake_evergreen.pl
+|   `-- test_against_fake_evergreen.pl
+|-- print_sound_index.pl
+|-- projlayout.txt
+|-- sounds
+|   |-- barcode.gsm
+|   |-- call_our_office_for_further_assistance.gsm
+|   |-- could_not_be_renewed_due_to_error.gsm
+|   |-- dummy_message1.gsm
+|   |-- dummy_message2.gsm
+|   |-- goodbye.gsm
+|   |-- has_been_renewed.gsm
+|   |-- item_with_barcode_ending.gsm
+|   |-- items_checked_out.gsm
+|   |-- may_not_be_renewed_at_this_time.gsm
+|   |-- of_your_items_have_been_renewed.gsm
+|   |-- please_enter_barcode.gsm
+|   |-- please_enter_your_card_number.gsm
+|   |-- press_1_to_continue_renewing_individual_items.gsm
+|   |-- press_1_to_hear_renewal_details.gsm
+|   |-- press_1_to_renew_all_or_press_2_for_individual.gsm
+|   |-- prompt_manager_ask_for_prompt_number.gsm
+|   |-- prompt_manager_error.gsm
+|   |-- prompt_manager_exit.gsm
+|   |-- prompt_manager_intro.gsm
+|   |-- prompt_manager_is_currently.gsm
+|   |-- prompt_manager_main_menu.gsm
+|   |-- prompt_manager_prompt_number.gsm
+|   |-- prompt_manager_recording_menu.gsm
+|   |-- some_items_could_not_be_renewed.gsm
+|   |-- thanks_for_calling.gsm
+|   |-- unexpected_error_occurred.gsm
+|   |-- was_not_recognized.gsm
+|   |-- welcome_to_the_phone_renewal_system.gsm
+|   |-- you_currently_have.gsm
+|   |-- you_currently_have_no_items_checked_out.gsm
+|   `-- your_card_number_could_not_be_found.gsm
+|-- store_updated_sounds.pl
+|-- t
+|   |-- tlib
+|   |   |-- AllItemsRenewerTest.pm
+|   |   |-- AppConfigTest.pm
+|   |   |-- CallHandlerTest.pm
+|   |   |-- EmailerTest.pm
+|   |   |-- IndividualItemsRenewerTest.pm
+|   |   |-- LogChannelTest.pm
+|   |   |-- LoggerTest.pm
+|   |   |-- ObjectContextTest.pm
+|   |   |-- PromptManagerTest.pm
+|   |   |-- PromptStoreTest.pm
+|   |   |-- RenewalAnnouncerTest.pm
+|   |   |-- RenewalLoggerTest.pm
+|   |   |-- RenewalResultSetTest.pm
+|   |   |-- RenewalResultTest.pm
+|   |   |-- SoundIndexPrinterTest.pm
+|   |   |-- TestHelper.pm
+|   |   `-- UnitTestSuite.pm
+|   `-- unit_tests.t
+|-- tools
+|   `-- new_class.pl
+}}}</pre>
+</div>
+<div title="PromptManager" modifier="DavidCrosby" created="200904071449" modified="200904081304" changecount="12">
+<pre>!! Recording new sound files to replace defaults
+The phone renewal project initially has a set of text-to-voice prompts.
+
+To record over them, use the Prompt Manager voice menu.  You can select a specific sound to review and re-record, or cycle through ALL sound prompts.
+
+You can use {{{print_sound_index.pl}}} to see the index of sound files.  (See PromptStore).
+
+!! Setup
+The Prompt Manager is an AGI script that provides a voice-driven menu allowing you to review and record the various sound files used by the phone renewal system.
+{{{lib/prompt_manager.agi.pl}}}
+This script is deployed automatically along with the phone renewal system.  ''However, you need to configure an extension'' in your dialplan to open it up to admin users:
+
+{{{/etc/asterisk/extensions.conf}}}
+{{{
+...
+[phone-renewals-admin]
+exten =&gt; 100,1,AGI(phone_renewals/prompt_manager.agi.pl)
+...
+}}}
+
+!! Adding NEW sounds
+The prompt manager can only deal with the sounds that are defined in the PromptStore class.
+If you update that class (and redeploy the application) you can now address that sound.
+
+If you're using PromptManager and you specify a prompt number that isn't defined by PromptStore, ''IT WILL WORK'... the new sound file will be named, eg, {{{765.gsm}}} and will show up in the repository if you run {{{store_updated_sounds.pl}}} (which you will need to add via {{{svn add sounds/765.gsm}}} and then checkin.
+This approach isn't as advisable as defining a new named sound entry in PromptStore, because in order to use the prompt from within the application, your code will need to refer to the new sound by its index directly.
+</pre>
+</div>
+<div title="PromptStore" modifier="DavidCrosby" created="200904071453" modified="200904081301" changecount="8">
+<pre>TelephoneRenewals::PromptStore.pm is the class that provides abstract access to sounds available to the system.
+It provides methods to lookup sound file paths by name, by their prompt IDs, and to list all available prompt ids.
+
+The configuration of available sounds is done within a private initializer method, via code like:
+{{{
+...
+&amp;$add_sound(&quot;welcome_to_the_phone_renewal_system&quot;);
+&amp;$add_sound(&quot;please_enter_your_card_number&quot;);
+&amp;$add_sound(&quot;your_card_number_could_not_be_found&quot;);
+...
+}}}
+
+To add or remove sounds from the system, update this method.   For example, to add a prompt called &quot;ask_for_birthday&quot;, you'd add a line of code:
+{{{
+&amp;$add_sound(&quot;ask_for_birthday&quot;);
+}}}
+which would correspond to the sound file {{{sounds/ask_for_birthday.gsm}}}
+
+!! List of prompts
+(as of April 2009; this list could very well be out of date.)
+
+This list is generated by running {{{print_sound_index.pl}}}: (to be 100% up to date, you should ''run this script yourself'')
+{{{
+perl print_sound_index.pl
+}}}
+
+100  - welcome_to_the_phone_renewal_system
+101  - please_enter_your_card_number
+102  - your_card_number_could_not_be_found
+103  - you_currently_have
+104  - items_checked_out
+105  - you_currently_have_no_items_checked_out
+106  - unexpected_error_occurred
+107  - press_1_to_renew_all_or_press_2_for_individual
+108  - of_your_items_have_been_renewed
+109  - some_items_could_not_be_renewed
+110  - press_1_to_hear_renewal_details
+111  - item_with_barcode_ending
+112  - has_been_renewed
+113  - may_not_be_renewed_at_this_time
+114  - could_not_be_renewed_due_to_error
+115  - please_enter_barcode
+116  - barcode
+117  - was_not_recognized
+118  - press_1_to_continue_renewing_individual_items
+119  - thanks_for_calling
+120  - call_our_office_for_further_assistance
+121  - goodbye
+122  - prompt_manager_intro
+123  - prompt_manager_main_menu
+124  - prompt_manager_ask_for_prompt_number
+125  - prompt_manager_prompt_number
+126  - prompt_manager_is_currently
+127  - prompt_manager_recording_menu
+128  - prompt_manager_error
+129  - prompt_manager_exit
+130  - dummy_message1
+131  - dummy_message2
+</pre>
+</div>
+<div title="RenewalResultStructure" modifier="DougKyle" created="200904080349" modified="200905011506" changecount="7">
+<pre>A Renewal Result will contain the Evergreen status code on failure, see RenewalAnnouncer.pm
+
+!! {{{TelephoneRenewals::RenewalResult}}}
+* ''status''
+** &quot;success&quot;
+** &quot;unknown barcode&quot;
+** &quot;no renewals allowed&quot;
+** //some other string, which will be interpreted as an unexpected error and logged by {{{CallHandler}}}//
+* ''barcode''
+** 14-length string representing item barcode
+* //last_5_digits_of_barcode//
+** Calculated field, returns last 5 characters of ''barcode'' as string
+
+!! {{{TelephoneRenewals::RenewalResultSet}}}
+* ''status''
+** &quot;ok&quot;
+** &quot;failures&quot;
+* ''successful_renewals''
+** An array reference containing {{{RenewalResult}}} objects pertaining to renewals that succeeded.
+* ''failed_renewals''
+** An array reference containing {{{RenewalResult}}} objects pertaining to renewals that failed or errored.
+
+!! Use
+These data structures have very little behavior, they're just a means of encapsulating compound data.
+
+Both of these objects can be built by passing their values as a hash to their constructors, or by building them with no constructor args and setting individual fields.
+</pre>
+</div>
+<div title="SiteSubtitle" modifier="YourName" created="200903171858" changecount="1">
+<pre></pre>
+</div>
+<div title="SiteTitle" modifier="YourName" created="200903171857" changecount="1">
+<pre>GRPL Telephone Renewals</pre>
+</div>
+<div title="SvnRepository" modifier="DavidCrosby" created="200904011744" modified="200904011749" changecount="7">
+<pre>Subversion: {{{svn://svn.grpl.org/mieg/phone_renewal}}}
+
+TRAC: http://svn.grpl.org/mieg/phone_renewal
+</pre>
+</div>
+<div title="TelephoneRenewal::EvergreenRenewal" modifier="DavidCrosby" created="200904011750" modified="200904011751" changecount="3">
+<pre>!validate_library_card_number
+Arguments: $library_card_number, String, should be 14 chars long</pre>
+</div>
+<div title="WikiMarkupReference" modifier="DavidCrosby" created="200904011748" changecount="1">
+<pre>http://tiddlywiki.org/wiki/TiddlyWiki_Markup</pre>
+</div>
+</div>
+<!--POST-STOREAREA-->
+<!--POST-BODY-START-->
+<!--POST-BODY-END-->
+<script id="jsArea" type="text/javascript">
+//<![CDATA[
+//
+// Please note:
+//
+// * This code is designed to be readable but for compactness it only includes brief comments. You can see fuller comments
+//   in the project Subversion repository at http://svn.tiddlywiki.org/Trunk/core/
+//
+// * You should never need to modify this source code directly. TiddlyWiki is carefully designed to allow deep customisation
+//   without changing the core code. Please consult the development group at http://groups.google.com/group/TiddlyWikiDev
+//
+
+//--
+//-- Configuration repository
+//--
+
+// Miscellaneous options
+var config = {
+	numRssItems: 20, // Number of items in the RSS feed
+	animDuration: 400, // Duration of UI animations in milliseconds
+	cascadeFast: 20, // Speed for cascade animations (higher == slower)
+	cascadeSlow: 60, // Speed for EasterEgg cascade animations
+	cascadeDepth: 5, // Depth of cascade animation
+	locale: "en" // W3C language tag
+};
+
+// Hashmap of alternative parsers for the wikifier
+config.parsers = {};
+
+// Adaptors
+config.adaptors = {};
+config.defaultAdaptor = null;
+
+// Backstage tasks
+config.tasks = {};
+
+// Annotations
+config.annotations = {};
+
+// Custom fields to be automatically added to new tiddlers
+config.defaultCustomFields = {};
+
+// Messages
+config.messages = {
+	messageClose: {},
+	dates: {},
+	tiddlerPopup: {}
+};
+
+// Options that can be set in the options panel and/or cookies
+config.options = {
+	chkRegExpSearch: false,
+	chkCaseSensitiveSearch: false,
+	chkIncrementalSearch: true,
+	chkAnimate: true,
+	chkSaveBackups: true,
+	chkAutoSave: false,
+	chkGenerateAnRssFeed: false,
+	chkSaveEmptyTemplate: false,
+	chkOpenInNewWindow: true,
+	chkToggleLinks: false,
+	chkHttpReadOnly: true,
+	chkForceMinorUpdate: false,
+	chkConfirmDelete: true,
+	chkInsertTabs: false,
+	chkUsePreForStorage: true, // Whether to use <pre> format for storage
+	chkDisplayInstrumentation: false,
+	txtBackupFolder: "",
+	txtEditorFocus: "text",
+	txtMainTab: "tabTimeline",
+	txtMoreTab: "moreTabAll",
+	txtMaxEditRows: "30",
+	txtFileSystemCharSet: "UTF-8",
+	txtTheme: ""
+	};
+config.optionsDesc = {};
+
+// Default tiddler templates
+var DEFAULT_VIEW_TEMPLATE = 1;
+var DEFAULT_EDIT_TEMPLATE = 2;
+config.tiddlerTemplates = {
+	1: "ViewTemplate",
+	2: "EditTemplate"
+};
+
+// More messages (rather a legacy layout that should not really be like this)
+config.views = {
+	wikified: {
+		tag: {}
+	},
+	editor: {
+		tagChooser: {}
+	}
+};
+
+// Backstage tasks
+config.backstageTasks = ["save","sync","importTask","tweak","upgrade","plugins"];
+
+// Extensions
+config.extensions = {};
+
+// Macros; each has a 'handler' member that is inserted later
+config.macros = {
+	today: {},
+	version: {},
+	search: {sizeTextbox: 15},
+	tiddler: {},
+	tag: {},
+	tags: {},
+	tagging: {},
+	timeline: {},
+	allTags: {},
+	list: {
+		all: {},
+		missing: {},
+		orphans: {},
+		shadowed: {},
+		touched: {},
+		filter: {}
+	},
+	closeAll: {},
+	permaview: {},
+	saveChanges: {},
+	slider: {},
+	option: {},
+	options: {},
+	newTiddler: {},
+	newJournal: {},
+	tabs: {},
+	gradient: {},
+	message: {},
+	view: {defaultView: "text"},
+	edit: {},
+	tagChooser: {},
+	toolbar: {},
+	plugins: {},
+	refreshDisplay: {},
+	importTiddlers: {},
+	upgrade: {
+		source: "http://www.tiddlywiki.com/upgrade/",
+		backupExtension: "pre.core.upgrade"
+	},
+	sync: {},
+	annotations: {}
+};
+
+// Commands supported by the toolbar macro
+config.commands = {
+	closeTiddler: {},
+	closeOthers: {},
+	editTiddler: {},
+	saveTiddler: {hideReadOnly: true},
+	cancelTiddler: {},
+	deleteTiddler: {hideReadOnly: true},
+	permalink: {},
+	references: {type: "popup"},
+	jump: {type: "popup"},
+	syncing: {type: "popup"},
+	fields: {type: "popup"}
+};
+
+// Browser detection... In a very few places, there's nothing else for it but to know what browser we're using.
+config.userAgent = navigator.userAgent.toLowerCase();
+config.browser = {
+	isIE: config.userAgent.indexOf("msie") != -1 && config.userAgent.indexOf("opera") == -1,
+	isGecko: config.userAgent.indexOf("gecko") != -1,
+	ieVersion: /MSIE (\d.\d)/i.exec(config.userAgent), // config.browser.ieVersion[1], if it exists, will be the IE version string, eg "6.0"
+	isSafari: config.userAgent.indexOf("applewebkit") != -1,
+	isBadSafari: !((new RegExp("[\u0150\u0170]","g")).test("\u0150")),
+	firefoxDate: /gecko\/(\d{8})/i.exec(config.userAgent), // config.browser.firefoxDate[1], if it exists, will be Firefox release date as "YYYYMMDD"
+	isOpera: config.userAgent.indexOf("opera") != -1,
+	isLinux: config.userAgent.indexOf("linux") != -1,
+	isUnix: config.userAgent.indexOf("x11") != -1,
+	isMac: config.userAgent.indexOf("mac") != -1,
+	isWindows: config.userAgent.indexOf("win") != -1
+};
+
+// Basic regular expressions
+config.textPrimitives = {
+	upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]",
+	lowerLetter: "[a-z0-9_\\-\u00df-\u00ff\u0151\u0171]",
+	anyLetter:   "[A-Za-z0-9_\\-\u00c0-\u00de\u00df-\u00ff\u0150\u0170\u0151\u0171]",
+	anyLetterStrict: "[A-Za-z0-9\u00c0-\u00de\u00df-\u00ff\u0150\u0170\u0151\u0171]"
+};
+if(config.browser.isBadSafari) {
+	config.textPrimitives = {
+		upperLetter: "[A-Z\u00c0-\u00de]",
+		lowerLetter: "[a-z0-9_\\-\u00df-\u00ff]",
+		anyLetter:   "[A-Za-z0-9_\\-\u00c0-\u00de\u00df-\u00ff]",
+		anyLetterStrict: "[A-Za-z0-9\u00c0-\u00de\u00df-\u00ff]"
+	};
+}
+config.textPrimitives.sliceSeparator = "::";
+config.textPrimitives.sectionSeparator = "##";
+config.textPrimitives.urlPattern = "(?:file|http|https|mailto|ftp|irc|news|data):[^\\s'\"]+(?:/|\\b)";
+config.textPrimitives.unWikiLink = "~";
+config.textPrimitives.wikiLink = "(?:(?:" + config.textPrimitives.upperLetter + "+" +
+	config.textPrimitives.lowerLetter + "+" +
+	config.textPrimitives.upperLetter +
+	config.textPrimitives.anyLetter + "*)|(?:" +
+	config.textPrimitives.upperLetter + "{2,}" +
+	config.textPrimitives.lowerLetter + "+))";
+
+config.textPrimitives.cssLookahead = "(?:(" + config.textPrimitives.anyLetter + "+)\\(([^\\)\\|\\n]+)(?:\\):))|(?:(" + config.textPrimitives.anyLetter + "+):([^;\\|\\n]+);)";
+config.textPrimitives.cssLookaheadRegExp = new RegExp(config.textPrimitives.cssLookahead,"mg");
+
+config.textPrimitives.brackettedLink = "\\[\\[([^\\]]+)\\]\\]";
+config.textPrimitives.titledBrackettedLink = "\\[\\[([^\\[\\]\\|]+)\\|([^\\[\\]\\|]+)\\]\\]";
+config.textPrimitives.tiddlerForcedLinkRegExp = new RegExp("(?:" + config.textPrimitives.titledBrackettedLink + ")|(?:" +
+	config.textPrimitives.brackettedLink + ")|(?:" +
+	config.textPrimitives.urlPattern + ")","mg");
+config.textPrimitives.tiddlerAnyLinkRegExp = new RegExp("("+ config.textPrimitives.wikiLink + ")|(?:" +
+	config.textPrimitives.titledBrackettedLink + ")|(?:" +
+	config.textPrimitives.brackettedLink + ")|(?:" +
+	config.textPrimitives.urlPattern + ")","mg");
+
+config.glyphs = {
+	browsers: [
+		function() {return config.browser.isIE;},
+		function() {return true;}
+	],
+	currBrowser: null,
+	codes: {
+		downTriangle: ["\u25BC","\u25BE"],
+		downArrow: ["\u2193","\u2193"],
+		bentArrowLeft: ["\u2190","\u21A9"],
+		bentArrowRight: ["\u2192","\u21AA"]
+	}
+};
+
+//--
+//-- Shadow tiddlers
+//--
+
+config.shadowTiddlers = {
+	StyleSheet: "",
+	MarkupPreHead: "",
+	MarkupPostHead: "",
+	MarkupPreBody: "",
+	MarkupPostBody: "",
+	TabTimeline: '<<timeline>>',
+	TabAll: '<<list all>>',
+	TabTags: '<<allTags excludeLists>>',
+	TabMoreMissing: '<<list missing>>',
+	TabMoreOrphans: '<<list orphans>>',
+	TabMoreShadowed: '<<list shadowed>>',
+	AdvancedOptions: '<<options>>',
+	PluginManager: '<<plugins>>',
+	ToolbarCommands: '|~ViewToolbar|closeTiddler closeOthers +editTiddler > fields syncing permalink references jump|\n|~EditToolbar|+saveTiddler -cancelTiddler deleteTiddler|'
+};
+
+//--
+//-- Translateable strings
+//--
+
+// Strings in "double quotes" should be translated; strings in 'single quotes' should be left alone
+
+merge(config.options,{
+	txtUserName: "YourName"});
+
+merge(config.tasks,{
+	save: {text: "save", tooltip: "Save your changes to this TiddlyWiki", action: saveChanges},
+	sync: {text: "sync", tooltip: "Synchronise changes with other TiddlyWiki files and servers", content: '<<sync>>'},
+	importTask: {text: "import", tooltip: "Import tiddlers and plugins from other TiddlyWiki files and servers", content: '<<importTiddlers>>'},
+	tweak: {text: "tweak", tooltip: "Tweak the appearance and behaviour of TiddlyWiki", content: '<<options>>'},
+	upgrade: {text: "upgrade", tooltip: "Upgrade TiddlyWiki core code", content: '<<upgrade>>'},
+	plugins: {text: "plugins", tooltip: "Manage installed plugins", content: '<<plugins>>'}
+});
+
+// Options that can be set in the options panel and/or cookies
+merge(config.optionsDesc,{
+	txtUserName: "Username for signing your edits",
+	chkRegExpSearch: "Enable regular expressions for searches",
+	chkCaseSensitiveSearch: "Case-sensitive searching",
+	chkIncrementalSearch: "Incremental key-by-key searching",
+	chkAnimate: "Enable animations",
+	chkSaveBackups: "Keep backup file when saving changes",
+	chkAutoSave: "Automatically save changes",
+	chkGenerateAnRssFeed: "Generate an RSS feed when saving changes",
+	chkSaveEmptyTemplate: "Generate an empty template when saving changes",
+	chkOpenInNewWindow: "Open external links in a new window",
+	chkToggleLinks: "Clicking on links to open tiddlers causes them to close",
+	chkHttpReadOnly: "Hide editing features when viewed over HTTP",
+	chkForceMinorUpdate: "Don't update modifier username and date when editing tiddlers",
+	chkConfirmDelete: "Require confirmation before deleting tiddlers",
+	chkInsertTabs: "Use the tab key to insert tab characters instead of moving between fields",
+	txtBackupFolder: "Name of folder to use for backups",
+	txtMaxEditRows: "Maximum number of rows in edit boxes",
+	txtFileSystemCharSet: "Default character set for saving changes (Firefox/Mozilla only)"});
+
+merge(config.messages,{
+	customConfigError: "Problems were encountered loading plugins. See PluginManager for details",
+	pluginError: "Error: %0",
+	pluginDisabled: "Not executed because disabled via 'systemConfigDisable' tag",
+	pluginForced: "Executed because forced via 'systemConfigForce' tag",
+	pluginVersionError: "Not executed because this plugin needs a newer version of TiddlyWiki",
+	nothingSelected: "Nothing is selected. You must select one or more items first",
+	savedSnapshotError: "It appears that this TiddlyWiki has been incorrectly saved. Please see http://www.tiddlywiki.com/#Download for details",
+	subtitleUnknown: "(unknown)",
+	undefinedTiddlerToolTip: "The tiddler '%0' doesn't yet exist",
+	shadowedTiddlerToolTip: "The tiddler '%0' doesn't yet exist, but has a pre-defined shadow value",
+	tiddlerLinkTooltip: "%0 - %1, %2",
+	externalLinkTooltip: "External link to %0",
+	noTags: "There are no tagged tiddlers",
+	notFileUrlError: "You need to save this TiddlyWiki to a file before you can save changes",
+	cantSaveError: "It's not possible to save changes. Possible reasons include:\n- your browser doesn't support saving (Firefox, Internet Explorer, Safari and Opera all work if properly configured)\n- the pathname to your TiddlyWiki file contains illegal characters\n- the TiddlyWiki HTML file has been moved or renamed",
+	invalidFileError: "The original file '%0' does not appear to be a valid TiddlyWiki",
+	backupSaved: "Backup saved",
+	backupFailed: "Failed to save backup file",
+	rssSaved: "RSS feed saved",
+	rssFailed: "Failed to save RSS feed file",
+	emptySaved: "Empty template saved",
+	emptyFailed: "Failed to save empty template file",
+	mainSaved: "Main TiddlyWiki file saved",
+	mainFailed: "Failed to save main TiddlyWiki file. Your changes have not been saved",
+	macroError: "Error in macro <<\%0>>",
+	macroErrorDetails: "Error while executing macro <<\%0>>:\n%1",
+	missingMacro: "No such macro",
+	overwriteWarning: "A tiddler named '%0' already exists. Choose OK to overwrite it",
+	unsavedChangesWarning: "WARNING! There are unsaved changes in TiddlyWiki\n\nChoose OK to save\nChoose CANCEL to discard",
+	confirmExit: "--------------------------------\n\nThere are unsaved changes in TiddlyWiki. If you continue you will lose those changes\n\n--------------------------------",
+	saveInstructions: "SaveChanges",
+	unsupportedTWFormat: "Unsupported TiddlyWiki format '%0'",
+	tiddlerSaveError: "Error when saving tiddler '%0'",
+	tiddlerLoadError: "Error when loading tiddler '%0'",
+	wrongSaveFormat: "Cannot save with storage format '%0'. Using standard format for save.",
+	invalidFieldName: "Invalid field name %0",
+	fieldCannotBeChanged: "Field '%0' cannot be changed",
+	loadingMissingTiddler: "Attempting to retrieve the tiddler '%0' from the '%1' server at:\n\n'%2' in the workspace '%3'",
+	upgradeDone: "The upgrade to version %0 is now complete\n\nClick 'OK' to reload the newly upgraded TiddlyWiki"});
+
+merge(config.messages.messageClose,{
+	text: "close",
+	tooltip: "close this message area"});
+
+config.messages.backstage = {
+	open: {text: "backstage", tooltip: "Open the backstage area to perform authoring and editing tasks"},
+	close: {text: "close", tooltip: "Close the backstage area"},
+	prompt: "backstage: ",
+	decal: {
+		edit: {text: "edit", tooltip: "Edit the tiddler '%0'"}
+	}
+};
+
+config.messages.listView = {
+	tiddlerTooltip: "Click for the full text of this tiddler",
+	previewUnavailable: "(preview not available)"
+};
+
+config.messages.dates.months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December"];
+config.messages.dates.days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
+config.messages.dates.shortMonths = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
+config.messages.dates.shortDays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
+// suffixes for dates, eg "1st","2nd","3rd"..."30th","31st"
+config.messages.dates.daySuffixes = ["st","nd","rd","th","th","th","th","th","th","th",
+		"th","th","th","th","th","th","th","th","th","th",
+		"st","nd","rd","th","th","th","th","th","th","th",
+		"st"];
+config.messages.dates.am = "am";
+config.messages.dates.pm = "pm";
+
+merge(config.messages.tiddlerPopup,{
+	});
+
+merge(config.views.wikified.tag,{
+	labelNoTags: "no tags",
+	labelTags: "tags: ",
+	openTag: "Open tag '%0'",
+	tooltip: "Show tiddlers tagged with '%0'",
+	openAllText: "Open all",
+	openAllTooltip: "Open all of these tiddlers",
+	popupNone: "No other tiddlers tagged with '%0'"});
+
+merge(config.views.wikified,{
+	defaultText: "The tiddler '%0' doesn't yet exist. Double-click to create it",
+	defaultModifier: "(missing)",
+	shadowModifier: "(built-in shadow tiddler)",
+	dateFormat: "DD MMM YYYY",
+	createdPrompt: "created"});
+
+merge(config.views.editor,{
+	tagPrompt: "Type tags separated with spaces, [[use double square brackets]] if necessary, or add existing",
+	defaultText: "Type the text for '%0'"});
+
+merge(config.views.editor.tagChooser,{
+	text: "tags",
+	tooltip: "Choose existing tags to add to this tiddler",
+	popupNone: "There are no tags defined",
+	tagTooltip: "Add the tag '%0'"});
+
+merge(config.messages,{
+	sizeTemplates:
+		[
+		{unit: 1024*1024*1024, template: "%0\u00a0GB"},
+		{unit: 1024*1024, template: "%0\u00a0MB"},
+		{unit: 1024, template: "%0\u00a0KB"},
+		{unit: 1, template: "%0\u00a0B"}
+		]});
+
+merge(config.macros.search,{
+	label: "search",
+	prompt: "Search this TiddlyWiki",
+	accessKey: "F",
+	successMsg: "%0 tiddlers found matching %1",
+	failureMsg: "No tiddlers found matching %0"});
+
+merge(config.macros.tagging,{
+	label: "tagging: ",
+	labelNotTag: "not tagging",
+	tooltip: "List of tiddlers tagged with '%0'"});
+
+merge(config.macros.timeline,{
+	dateFormat: "DD MMM YYYY"});
+
+merge(config.macros.allTags,{
+	tooltip: "Show tiddlers tagged with '%0'",
+	noTags: "There are no tagged tiddlers"});
+
+config.macros.list.all.prompt = "All tiddlers in alphabetical order";
+config.macros.list.missing.prompt = "Tiddlers that have links to them but are not defined";
+config.macros.list.orphans.prompt = "Tiddlers that are not linked to from any other tiddlers";
+config.macros.list.shadowed.prompt = "Tiddlers shadowed with default contents";
+config.macros.list.touched.prompt = "Tiddlers that have been modified locally";
+
+merge(config.macros.closeAll,{
+	label: "close all",
+	prompt: "Close all displayed tiddlers (except any that are being edited)"});
+
+merge(config.macros.permaview,{
+	label: "permaview",
+	prompt: "Link to an URL that retrieves all the currently displayed tiddlers"});
+
+merge(config.macros.saveChanges,{
+	label: "save changes",
+	prompt: "Save all tiddlers to create a new TiddlyWiki",
+	accessKey: "S"});
+
+merge(config.macros.newTiddler,{
+	label: "new tiddler",
+	prompt: "Create a new tiddler",
+	title: "New Tiddler",
+	accessKey: "N"});
+
+merge(config.macros.newJournal,{
+	label: "new journal",
+	prompt: "Create a new tiddler from the current date and time",
+	accessKey: "J"});
+
+merge(config.macros.options,{
+	wizardTitle: "Tweak advanced options",
+	step1Title: "These options are saved in cookies in your browser",
+	step1Html: "<input type='hidden' name='markList'></input><br><input type='checkbox' checked='false' name='chkUnknown'>Show unknown options</input>",
+	unknownDescription: "//(unknown)//",
+	listViewTemplate: {
+		columns: [
+			{name: 'Option', field: 'option', title: "Option", type: 'String'},
+			{name: 'Description', field: 'description', title: "Description", type: 'WikiText'},
+			{name: 'Name', field: 'name', title: "Name", type: 'String'}
+			],
+		rowClasses: [
+			{className: 'lowlight', field: 'lowlight'}
+			]}
+	});
+
+merge(config.macros.plugins,{
+	wizardTitle: "Manage plugins",
+	step1Title: "Currently loaded plugins",
+	step1Html: "<input type='hidden' name='markList'></input>", // DO NOT TRANSLATE
+	skippedText: "(This plugin has not been executed because it was added since startup)",
+	noPluginText: "There are no plugins installed",
+	confirmDeleteText: "Are you sure you want to delete these plugins:\n\n%0",
+	removeLabel: "remove systemConfig tag",
+	removePrompt: "Remove systemConfig tag",
+	deleteLabel: "delete",
+	deletePrompt: "Delete these tiddlers forever",
+	listViewTemplate: {
+		columns: [
+			{name: 'Selected', field: 'Selected', rowName: 'title', type: 'Selector'},
+			{name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
+			{name: 'Description', field: 'desc', title: "Description", type: 'String'},
+			{name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size'},
+			{name: 'Forced', field: 'forced', title: "Forced", tag: 'systemConfigForce', type: 'TagCheckbox'},
+			{name: 'Disabled', field: 'disabled', title: "Disabled", tag: 'systemConfigDisable', type: 'TagCheckbox'},
+			{name: 'Executed', field: 'executed', title: "Loaded", type: 'Boolean', trueText: "Yes", falseText: "No"},
+			{name: 'Startup Time', field: 'startupTime', title: "Startup Time", type: 'String'},
+			{name: 'Error', field: 'error', title: "Status", type: 'Boolean', trueText: "Error", falseText: "OK"},
+			{name: 'Log', field: 'log', title: "Log", type: 'StringList'}
+			],
+		rowClasses: [
+			{className: 'error', field: 'error'},
+			{className: 'warning', field: 'warning'}
+			]}
+	});
+
+merge(config.macros.toolbar,{
+	moreLabel: "more",
+	morePrompt: "Reveal further commands"
+	});
+
+merge(config.macros.refreshDisplay,{
+	label: "refresh",
+	prompt: "Redraw the entire TiddlyWiki display"
+	});
+
+merge(config.macros.importTiddlers,{
+	readOnlyWarning: "You cannot import into a read-only TiddlyWiki file. Try opening it from a file:// URL",
+	wizardTitle: "Import tiddlers from another file or server",
+	step1Title: "Step 1: Locate the server or TiddlyWiki file",
+	step1Html: "Specify the type of the server: <select name='selTypes'><option value=''>Choose...</option></select><br>Enter the URL or pathname here: <input type='text' size=50 name='txtPath'><br>...or browse for a file: <input type='file' size=50 name='txtBrowse'><br><hr>...or select a pre-defined feed: <select name='selFeeds'><option value=''>Choose...</option></select>",
+	openLabel: "open",
+	openPrompt: "Open the connection to this file or server",
+	openError: "There were problems fetching the tiddlywiki file",
+	statusOpenHost: "Opening the host",
+	statusGetWorkspaceList: "Getting the list of available workspaces",
+	step2Title: "Step 2: Choose the workspace",
+	step2Html: "Enter a workspace name: <input type='text' size=50 name='txtWorkspace'><br>...or select a workspace: <select name='selWorkspace'><option value=''>Choose...</option></select>",
+	cancelLabel: "cancel",
+	cancelPrompt: "Cancel this import",
+	statusOpenWorkspace: "Opening the workspace",
+	statusGetTiddlerList: "Getting the list of available tiddlers",
+	errorGettingTiddlerList: "Error getting list of tiddlers, click Cancel to try again",
+	step3Title: "Step 3: Choose the tiddlers to import",
+	step3Html: "<input type='hidden' name='markList'></input><br><input type='checkbox' checked='true' name='chkSync'>Keep these tiddlers linked to this server so that you can synchronise subsequent changes</input><br><input type='checkbox' name='chkSave'>Save the details of this server in a 'systemServer' tiddler called:</input> <input type='text' size=25 name='txtSaveTiddler'>",
+	importLabel: "import",
+	importPrompt: "Import these tiddlers",
+	confirmOverwriteText: "Are you sure you want to overwrite these tiddlers:\n\n%0",
+	step4Title: "Step 4: Importing %0 tiddler(s)",
+	step4Html: "<input type='hidden' name='markReport'></input>", // DO NOT TRANSLATE
+	doneLabel: "done",
+	donePrompt: "Close this wizard",
+	statusDoingImport: "Importing tiddlers",
+	statusDoneImport: "All tiddlers imported",
+	systemServerNamePattern: "%2 on %1",
+	systemServerNamePatternNoWorkspace: "%1",
+	confirmOverwriteSaveTiddler: "The tiddler '%0' already exists. Click 'OK' to overwrite it with the details of this server, or 'Cancel' to leave it unchanged",
+	serverSaveTemplate: "|''Type:''|%0|\n|''URL:''|%1|\n|''Workspace:''|%2|\n\nThis tiddler was automatically created to record the details of this server",
+	serverSaveModifier: "(System)",
+	listViewTemplate: {
+		columns: [
+			{name: 'Selected', field: 'Selected', rowName: 'title', type: 'Selector'},
+			{name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
+			{name: 'Size', field: 'size', tiddlerLink: 'size', title: "Size", type: 'Size'},
+			{name: 'Tags', field: 'tags', title: "Tags", type: 'Tags'}
+			],
+		rowClasses: [
+			]}
+	});
+
+merge(config.macros.upgrade,{
+	wizardTitle: "Upgrade TiddlyWiki core code",
+	step1Title: "Update or repair this TiddlyWiki to the latest release",
+	step1Html: "You are about to upgrade to the latest release of the TiddlyWiki core code (from <a href='%0' class='externalLink' target='_blank'>%1</a>). Your content will be preserved across the upgrade.<br><br>Note that core upgrades have been known to interfere with older plugins. If you run into problems with the upgraded file, see <a href='http://www.tiddlywiki.org/wiki/CoreUpgrades' class='externalLink' target='_blank'>http://www.tiddlywiki.org/wiki/CoreUpgrades</a>",
+	errorCantUpgrade: "Unable to upgrade this TiddlyWiki. You can only perform upgrades on TiddlyWiki files stored locally",
+	errorNotSaved: "You must save changes before you can perform an upgrade",
+	step2Title: "Confirm the upgrade details",
+	step2Html_downgrade: "You are about to downgrade to TiddlyWiki version %0 from %1.<br><br>Downgrading to an earlier version of the core code is not recommended",
+	step2Html_restore: "This TiddlyWiki appears to be already using the latest version of the core code (%0).<br><br>You can continue to upgrade anyway to ensure that the core code hasn't been corrupted or damaged",
+	step2Html_upgrade: "You are about to upgrade to TiddlyWiki version %0 from %1",
+	upgradeLabel: "upgrade",
+	upgradePrompt: "Prepare for the upgrade process",
+	statusPreparingBackup: "Preparing backup",
+	statusSavingBackup: "Saving backup file",
+	errorSavingBackup: "There was a problem saving the backup file",
+	statusLoadingCore: "Loading core code",
+	errorLoadingCore: "Error loading the core code",
+	errorCoreFormat: "Error with the new core code",
+	statusSavingCore: "Saving the new core code",
+	statusReloadingCore: "Reloading the new core code",
+	startLabel: "start",
+	startPrompt: "Start the upgrade process",
+	cancelLabel: "cancel",
+	cancelPrompt: "Cancel the upgrade process",
+	step3Title: "Upgrade cancelled",
+	step3Html: "You have cancelled the upgrade process"
+	});
+
+merge(config.macros.sync,{
+	listViewTemplate: {
+		columns: [
+			{name: 'Selected', field: 'selected', rowName: 'title', type: 'Selector'},
+			{name: 'Tiddler', field: 'tiddler', title: "Tiddler", type: 'Tiddler'},
+			{name: 'Server Type', field: 'serverType', title: "Server type", type: 'String'},
+			{name: 'Server Host', field: 'serverHost', title: "Server host", type: 'String'},
+			{name: 'Server Workspace', field: 'serverWorkspace', title: "Server workspace", type: 'String'},
+			{name: 'Status', field: 'status', title: "Synchronisation status", type: 'String'},
+			{name: 'Server URL', field: 'serverUrl', title: "Server URL", text: "View", type: 'Link'}
+			],
+		rowClasses: [
+			],
+		buttons: [
+			{caption: "Sync these tiddlers", name: 'sync'}
+			]},
+	wizardTitle: "Synchronize with external servers and files",
+	step1Title: "Choose the tiddlers you want to synchronize",
+	step1Html: "<input type='hidden' name='markList'></input>", // DO NOT TRANSLATE
+	syncLabel: "sync",
+	syncPrompt: "Sync these tiddlers",
+	hasChanged: "Changed while unplugged",
+	hasNotChanged: "Unchanged while unplugged",
+	syncStatusList: {
+		none: {text: "...", display:null, className:'notChanged'},
+		changedServer: {text: "Changed on server", display:null, className:'changedServer'},
+		changedLocally: {text: "Changed while unplugged", display:null, className:'changedLocally'},
+		changedBoth: {text: "Changed while unplugged and on server", display:null, className:'changedBoth'},
+		notFound: {text: "Not found on server", display:null, className:'notFound'},
+		putToServer: {text: "Saved update on server", display:null, className:'putToServer'},
+		gotFromServer: {text: "Retrieved update from server", display:null, className:'gotFromServer'}
+		}
+	});
+
+merge(config.macros.annotations,{
+	});
+
+merge(config.commands.closeTiddler,{
+	text: "close",
+	tooltip: "Close this tiddler"});
+
+merge(config.commands.closeOthers,{
+	text: "close others",
+	tooltip: "Close all other tiddlers"});
+
+merge(config.commands.editTiddler,{
+	text: "edit",
+	tooltip: "Edit this tiddler",
+	readOnlyText: "view",
+	readOnlyTooltip: "View the source of this tiddler"});
+
+merge(config.commands.saveTiddler,{
+	text: "done",
+	tooltip: "Save changes to this tiddler"});
+
+merge(config.commands.cancelTiddler,{
+	text: "cancel",
+	tooltip: "Undo changes to this tiddler",
+	warning: "Are you sure you want to abandon your changes to '%0'?",
+	readOnlyText: "done",
+	readOnlyTooltip: "View this tiddler normally"});
+
+merge(config.commands.deleteTiddler,{
+	text: "delete",
+	tooltip: "Delete this tiddler",
+	warning: "Are you sure you want to delete '%0'?"});
+
+merge(config.commands.permalink,{
+	text: "permalink",
+	tooltip: "Permalink for this tiddler"});
+
+merge(config.commands.references,{
+	text: "references",
+	tooltip: "Show tiddlers that link to this one",
+	popupNone: "No references"});
+
+merge(config.commands.jump,{
+	text: "jump",
+	tooltip: "Jump to another open tiddler"});
+
+merge(config.commands.syncing,{
+	text: "syncing",
+	tooltip: "Control synchronisation of this tiddler with a server or external file",
+	currentlySyncing: "<div>Currently syncing via <span class='popupHighlight'>'%0'</span> to:</"+"div><div>host: <span class='popupHighlight'>%1</span></"+"div><div>workspace: <span class='popupHighlight'>%2</span></"+"div>", // Note escaping of closing <div> tag
+	notCurrentlySyncing: "Not currently syncing",
+	captionUnSync: "Stop synchronising this tiddler",
+	chooseServer: "Synchronise this tiddler with another server:",
+	currServerMarker: "\u25cf ",
+	notCurrServerMarker: "  "});
+
+merge(config.commands.fields,{
+	text: "fields",
+	tooltip: "Show the extended fields of this tiddler",
+	emptyText: "There are no extended fields for this tiddler",
+	listViewTemplate: {
+		columns: [
+			{name: 'Field', field: 'field', title: "Field", type: 'String'},
+			{name: 'Value', field: 'value', title: "Value", type: 'String'}
+			],
+		rowClasses: [
+			],
+		buttons: [
+			]}});
+
+merge(config.shadowTiddlers,{
+	DefaultTiddlers: "[[GettingStarted]]",
+	MainMenu: "[[GettingStarted]]",
+	SiteTitle: "My TiddlyWiki",
+	SiteSubtitle: "a reusable non-linear personal web notebook",
+	SiteUrl: "http://www.tiddlywiki.com/",
+	SideBarOptions: '<<search>><<closeAll>><<permaview>><<newTiddler>><<newJournal "DD MMM YYYY" "journal">><<saveChanges>><<slider chkSliderOptionsPanel OptionsPanel "options \u00bb" "Change TiddlyWiki advanced options">>',
+	SideBarTabs: '<<tabs txtMainTab "Timeline" "Timeline" TabTimeline "All" "All tiddlers" TabAll "Tags" "All tags" TabTags "More" "More lists" TabMore>>',
+	TabMore: '<<tabs txtMoreTab "Missing" "Missing tiddlers" TabMoreMissing "Orphans" "Orphaned tiddlers" TabMoreOrphans "Shadowed" "Shadowed tiddlers" TabMoreShadowed>>'
+	});
+
+merge(config.annotations,{
+	AdvancedOptions: "This shadow tiddler provides access to several advanced options",
+	ColorPalette: "These values in this shadow tiddler determine the colour scheme of the ~TiddlyWiki user interface",
+	DefaultTiddlers: "The tiddlers listed in this shadow tiddler will be automatically displayed when ~TiddlyWiki starts up",
+	EditTemplate: "The HTML template in this shadow tiddler determines how tiddlers look while they are being edited",
+	GettingStarted: "This shadow tiddler provides basic usage instructions",
+	ImportTiddlers: "This shadow tiddler provides access to importing tiddlers",
+	MainMenu: "This shadow tiddler is used as the contents of the main menu in the left-hand column of the screen",
+	MarkupPreHead: "This tiddler is inserted at the top of the <head> section of the TiddlyWiki HTML file",
+	MarkupPostHead: "This tiddler is inserted at the bottom of the <head> section of the TiddlyWiki HTML file",
+	MarkupPreBody: "This tiddler is inserted at the top of the <body> section of the TiddlyWiki HTML file",
+	MarkupPostBody: "This tiddler is inserted at the end of the <body> section of the TiddlyWiki HTML file immediately after the script block",
+	OptionsPanel: "This shadow tiddler is used as the contents of the options panel slider in the right-hand sidebar",
+	PageTemplate: "The HTML template in this shadow tiddler determines the overall ~TiddlyWiki layout",
+	PluginManager: "This shadow tiddler provides access to the plugin manager",
+	SideBarOptions: "This shadow tiddler is used as the contents of the option panel in the right-hand sidebar",
+	SideBarTabs: "This shadow tiddler is used as the contents of the tabs panel in the right-hand sidebar",
+	SiteSubtitle: "This shadow tiddler is used as the second part of the page title",
+	SiteTitle: "This shadow tiddler is used as the first part of the page title",
+	SiteUrl: "This shadow tiddler should be set to the full target URL for publication",
+	StyleSheetColors: "This shadow tiddler contains CSS definitions related to the color of page elements. ''DO NOT EDIT THIS TIDDLER'', instead make your changes in the StyleSheet shadow tiddler",
+	StyleSheet: "This tiddler can contain custom CSS definitions",
+	StyleSheetLayout: "This shadow tiddler contains CSS definitions related to the layout of page elements. ''DO NOT EDIT THIS TIDDLER'', instead make your changes in the StyleSheet shadow tiddler",
+	StyleSheetLocale: "This shadow tiddler contains CSS definitions related to the translation locale",
+	StyleSheetPrint: "This shadow tiddler contains CSS definitions for printing",
+	TabAll: "This shadow tiddler contains the contents of the 'All' tab in the right-hand sidebar",
+	TabMore: "This shadow tiddler contains the contents of the 'More' tab in the right-hand sidebar",
+	TabMoreMissing: "This shadow tiddler contains the contents of the 'Missing' tab in the right-hand sidebar",
+	TabMoreOrphans: "This shadow tiddler contains the contents of the 'Orphans' tab in the right-hand sidebar",
+	TabMoreShadowed: "This shadow tiddler contains the contents of the 'Shadowed' tab in the right-hand sidebar",
+	TabTags: "This shadow tiddler contains the contents of the 'Tags' tab in the right-hand sidebar",
+	TabTimeline: "This shadow tiddler contains the contents of the 'Timeline' tab in the right-hand sidebar",
+	ToolbarCommands: "This shadow tiddler determines which commands are shown in tiddler toolbars",
+	ViewTemplate: "The HTML template in this shadow tiddler determines how tiddlers look"
+	});
+
+//--
+//-- Main
+//--
+
+var params = null; // Command line parameters
+var store = null; // TiddlyWiki storage
+var story = null; // Main story
+var formatter = null; // Default formatters for the wikifier
+var anim = typeof Animator == "function" ? new Animator() : null; // Animation engine
+var readOnly = false; // Whether we're in readonly mode
+var highlightHack = null; // Embarrassing hack department...
+var hadConfirmExit = false; // Don't warn more than once
+var safeMode = false; // Disable all plugins and cookies
+var showBackstage; // Whether to include the backstage area
+var installedPlugins = []; // Information filled in when plugins are executed
+var startingUp = false; // Whether we're in the process of starting up
+var pluginInfo,tiddler; // Used to pass information to plugins in loadPlugins()
+
+// Whether to use the JavaSaver applet
+var useJavaSaver = (config.browser.isSafari || config.browser.isOpera) && (document.location.toString().substr(0,4) != "http");
+
+// Starting up
+function main()
+{
+	var t10,t9,t8,t7,t6,t5,t4,t3,t2,t1,t0 = new Date();
+	startingUp = true;
+	jQuery.noConflict();
+	window.onbeforeunload = function(e) {if(window.confirmExit) return confirmExit();};
+	params = getParameters();
+	if(params)
+		params = params.parseParams("open",null,false);
+	store = new TiddlyWiki();
+	invokeParamifier(params,"oninit");
+	story = new Story("tiddlerDisplay","tiddler");
+	addEvent(document,"click",Popup.onDocumentClick);
+	saveTest();
+	loadOptionsCookie();
+	for(var s=0; s<config.notifyTiddlers.length; s++)
+		store.addNotification(config.notifyTiddlers[s].name,config.notifyTiddlers[s].notify);
+	t1 = new Date();
+	loadShadowTiddlers();
+	t2 = new Date();
+	store.loadFromDiv("storeArea","store",true);
+	t3 = new Date();
+	invokeParamifier(params,"onload");
+	t4 = new Date();
+	readOnly = (window.location.protocol == "file:") ? false : config.options.chkHttpReadOnly;
+	var pluginProblem = loadPlugins();
+	t5 = new Date();
+	formatter = new Formatter(config.formatters);
+	invokeParamifier(params,"onconfig");
+	story.switchTheme(config.options.txtTheme);
+	showBackstage = !readOnly;
+	t6 = new Date();
+	for(var m in config.macros) {
+		if(config.macros[m].init)
+			config.macros[m].init();
+	}
+	t7 = new Date();
+	store.notifyAll();
+	t8 = new Date();
+	restart();
+	refreshDisplay();
+	t9 = new Date();
+	if(pluginProblem) {
+		story.displayTiddler(null,"PluginManager");
+		displayMessage(config.messages.customConfigError);
+	}
+	if(showBackstage)
+		backstage.init();
+	t10 = new Date();
+	if(config.options.chkDisplayInstrumentation) {
+		displayMessage("LoadShadows " + (t2-t1) + " ms");
+		displayMessage("LoadFromDiv " + (t3-t2) + " ms");
+		displayMessage("LoadPlugins " + (t5-t4) + " ms");
+		displayMessage("Macro init " + (t7-t6) + " ms");
+		displayMessage("Notify " + (t8-t7) + " ms");
+		displayMessage("Restart " + (t9-t8) + " ms");
+		displayMessage("Total: " + (t10-t0) + " ms");
+	}
+	startingUp = false;
+}
+
+// Restarting
+function restart()
+{
+	invokeParamifier(params,"onstart");
+	if(story.isEmpty()) {
+		story.displayDefaultTiddlers();
+	}
+	window.scrollTo(0,0);
+}
+
+function saveTest()
+{
+	var s = document.getElementById("saveTest");
+	if(s.hasChildNodes())
+		alert(config.messages.savedSnapshotError);
+	s.appendChild(document.createTextNode("savetest"));
+}
+
+function loadShadowTiddlers()
+{
+	var shadows = new TiddlyWiki();
+	shadows.loadFromDiv("shadowArea","shadows",true);
+	shadows.forEachTiddler(function(title,tiddler){config.shadowTiddlers[title] = tiddler.text;});
+	delete shadows;
+}
+
+function loadPlugins()
+{
+	if(safeMode)
+		return false;
+	var tiddlers = store.getTaggedTiddlers("systemConfig");
+	var toLoad = [];
+	var nLoaded = 0;
+	var map = {};
+	var nPlugins = tiddlers.length;
+	installedPlugins = [];
+	for(var i=0; i<nPlugins; i++) {
+		var p = getPluginInfo(tiddlers[i]);
+		installedPlugins[i] = p;
+		var n = p.Name;
+		if(n)
+			map[n] = p;
+		n = p.Source;
+		if(n)
+			map[n] = p;
+	}
+	var visit = function(p) {
+		if(!p || p.done)
+			return;
+		p.done = 1;
+		var reqs = p.Requires;
+		if(reqs) {
+			reqs = reqs.readBracketedList();
+			for(var i=0; i<reqs.length; i++)
+				visit(map[reqs[i]]);
+		}
+		toLoad.push(p);
+	};
+	for(i=0; i<nPlugins; i++)
+		visit(installedPlugins[i]);
+	for(i=0; i<toLoad.length; i++) {
+		p = toLoad[i];
+		pluginInfo = p;
+		tiddler = p.tiddler;
+		if(isPluginExecutable(p)) {
+			if(isPluginEnabled(p)) {
+				p.executed = true;
+				var startTime = new Date();
+				try {
+					if(tiddler.text)
+						window.eval(tiddler.text);
+					nLoaded++;
+				} catch(ex) {
+					p.log.push(config.messages.pluginError.format([exceptionText(ex)]));
+					p.error = true;
+				}
+				pluginInfo.startupTime = String((new Date()) - startTime) + "ms";
+			} else {
+				nPlugins--;
+			}
+		} else {
+			p.warning = true;
+		}
+	}
+	return nLoaded != nPlugins;
+}
+
+function getPluginInfo(tiddler)
+{
+	var p = store.getTiddlerSlices(tiddler.title,["Name","Description","Version","Requires","CoreVersion","Date","Source","Author","License","Browsers"]);
+	p.tiddler = tiddler;
+	p.title = tiddler.title;
+	p.log = [];
+	return p;
+}
+
+// Check that a particular plugin is valid for execution
+function isPluginExecutable(plugin)
+{
+	if(plugin.tiddler.isTagged("systemConfigForce")) {
+		plugin.log.push(config.messages.pluginForced);
+		return true;
+	}
+	if(plugin["CoreVersion"]) {
+		var coreVersion = plugin["CoreVersion"].split(".");
+		var w = parseInt(coreVersion[0],10) - version.major;
+		if(w == 0 && coreVersion[1])
+			w = parseInt(coreVersion[1],10) - version.minor;
+		if(w == 0 && coreVersion[2])
+			w = parseInt(coreVersion[2],10) - version.revision;
+		if(w > 0) {
+			plugin.log.push(config.messages.pluginVersionError);
+			return false;
+		}
+	}
+	return true;
+}
+
+function isPluginEnabled(plugin)
+{
+	if(plugin.tiddler.isTagged("systemConfigDisable")) {
+		plugin.log.push(config.messages.pluginDisabled);
+		return false;
+	}
+	return true;
+}
+
+function invokeMacro(place,macro,params,wikifier,tiddler)
+{
+	try {
+		var m = config.macros[macro];
+		if(m && m.handler) {
+			var tiddlerElem = story.findContainingTiddler(place);
+			window.tiddler = tiddlerElem ? store.getTiddler(tiddlerElem.getAttribute("tiddler")) : null;
+			window.place = place;
+			m.handler(place,macro,params.readMacroParams(),wikifier,params,tiddler);
+		} else {
+			createTiddlyError(place,config.messages.macroError.format([macro]),config.messages.macroErrorDetails.format([macro,config.messages.missingMacro]));
+		}
+	} catch(ex) {
+		createTiddlyError(place,config.messages.macroError.format([macro]),config.messages.macroErrorDetails.format([macro,ex.toString()]));
+	}
+}
+
+//--
+//-- Paramifiers
+//--
+
+function getParameters()
+{
+	var p = null;
+	if(window.location.hash) {
+		p = decodeURIComponent(window.location.hash.substr(1));
+		if(config.browser.firefoxDate != null && config.browser.firefoxDate[1] < "20051111")
+			p = convertUTF8ToUnicode(p);
+	}
+	return p;
+}
+
+function invokeParamifier(params,handler)
+{
+	if(!params || params.length == undefined || params.length <= 1)
+		return;
+	for(var i=1; i<params.length; i++) {
+		var p = config.paramifiers[params[i].name];
+		if(p && p[handler] instanceof Function)
+			p[handler](params[i].value);
+		else {
+			var h = config.optionHandlers[params[i].name.substr(0,3)];
+			if(h && h.set instanceof Function)
+				h.set(params[i].name,params[i].value);
+		}
+	}
+}
+
+config.paramifiers = {};
+
+config.paramifiers.start = {
+	oninit: function(v) {
+		safeMode = v.toLowerCase() == "safe";
+	}
+};
+
+config.paramifiers.open = {
+	onstart: function(v) {
+		if(!readOnly || store.tiddlerExists(v) || store.isShadowTiddler(v))
+			story.displayTiddler("bottom",v,null,false,null);
+	}
+};
+
+config.paramifiers.story = {
+	onstart: function(v) {
+		var list = store.getTiddlerText(v,"").parseParams("open",null,false);
+		invokeParamifier(list,"onstart");
+	}
+};
+
+config.paramifiers.search = {
+	onstart: function(v) {
+		story.search(v,false,false);
+	}
+};
+
+config.paramifiers.searchRegExp = {
+	onstart: function(v) {
+		story.prototype.search(v,false,true);
+	}
+};
+
+config.paramifiers.tag = {
+	onstart: function(v) {
+		story.displayTiddlers(null,store.filterTiddlers("[tag["+v+"]]"),null,false,null);
+	}
+};
+
+config.paramifiers.newTiddler = {
+	onstart: function(v) {
+		if(!readOnly) {
+			story.displayTiddler(null,v,DEFAULT_EDIT_TEMPLATE);
+			story.focusTiddler(v,"text");
+		}
+	}
+};
+
+config.paramifiers.newJournal = {
+	onstart: function(v) {
+		if(!readOnly) {
+			var now = new Date();
+			var title = now.formatString(v.trim());
+			story.displayTiddler(null,title,DEFAULT_EDIT_TEMPLATE);
+			story.focusTiddler(title,"text");
+		}
+	}
+};
+
+config.paramifiers.readOnly = {
+	onconfig: function(v) {
+		var p = v.toLowerCase();
+		readOnly = p == "yes" ? true : (p == "no" ? false : readOnly);
+	}
+};
+
+config.paramifiers.theme = {
+	onconfig: function(v) {
+		story.switchTheme(v);
+	}
+};
+
+config.paramifiers.upgrade = {
+	onstart: function(v) {
+		upgradeFrom(v);
+	}
+};
+
+config.paramifiers.recent= {
+	onstart: function(v) {
+		var titles=[];
+		var tiddlers=store.getTiddlers("modified","excludeLists").reverse();
+		for(var i=0; i<v && i<tiddlers.length; i++)
+			titles.push(tiddlers[i].title);
+		story.displayTiddlers(null,titles);
+	}
+};
+
+config.paramifiers.filter = {
+	onstart: function(v) {
+		story.displayTiddlers(null,store.filterTiddlers(v),null,false);
+	}
+};
+
+//--
+//-- Formatter helpers
+//--
+
+function Formatter(formatters)
+{
+	this.formatters = [];
+	var pattern = [];
+	for(var n=0; n<formatters.length; n++) {
+		pattern.push("(" + formatters[n].match + ")");
+		this.formatters.push(formatters[n]);
+	}
+	this.formatterRegExp = new RegExp(pattern.join("|"),"mg");
+}
+
+config.formatterHelpers = {
+
+	createElementAndWikify: function(w)
+	{
+		w.subWikifyTerm(createTiddlyElement(w.output,this.element),this.termRegExp);
+	},
+
+	inlineCssHelper: function(w)
+	{
+		var styles = [];
+		config.textPrimitives.cssLookaheadRegExp.lastIndex = w.nextMatch;
+		var lookaheadMatch = config.textPrimitives.cssLookaheadRegExp.exec(w.source);
+		while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
+			var s,v;
+			if(lookaheadMatch[1]) {
+				s = lookaheadMatch[1].unDash();
+				v = lookaheadMatch[2];
+			} else {
+				s = lookaheadMatch[3].unDash();
+				v = lookaheadMatch[4];
+			}
+			if(s=="bgcolor")
+				s = "backgroundColor";
+			styles.push({style: s, value: v});
+			w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
+			config.textPrimitives.cssLookaheadRegExp.lastIndex = w.nextMatch;
+			lookaheadMatch = config.textPrimitives.cssLookaheadRegExp.exec(w.source);
+		}
+		return styles;
+	},
+
+	applyCssHelper: function(e,styles)
+	{
+		for(var t=0; t< styles.length; t++) {
+			try {
+				e.style[styles[t].style] = styles[t].value;
+			} catch (ex) {
+			}
+		}
+	},
+
+	enclosedTextHelper: function(w)
+	{
+		this.lookaheadRegExp.lastIndex = w.matchStart;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
+			var text = lookaheadMatch[1];
+			if(config.browser.isIE)
+				text = text.replace(/\n/g,"\r");
+			createTiddlyElement(w.output,this.element,null,null,text);
+			w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
+		}
+	},
+
+	isExternalLink: function(link)
+	{
+		if(store.tiddlerExists(link) || store.isShadowTiddler(link)) {
+			return false;
+		}
+		var urlRegExp = new RegExp(config.textPrimitives.urlPattern,"mg");
+		if(urlRegExp.exec(link)) {
+			return true;
+		}
+		if(link.indexOf(".")!=-1 || link.indexOf("\\")!=-1 || link.indexOf("/")!=-1 || link.indexOf("#")!=-1) {
+			return true;
+		}
+		return false;
+	}
+
+};
+
+//--
+//-- Standard formatters
+//--
+
+config.formatters = [
+{
+	name: "table",
+	match: "^\\|(?:[^\\n]*)\\|(?:[fhck]?)$",
+	lookaheadRegExp: /^\|([^\n]*)\|([fhck]?)$/mg,
+	rowTermRegExp: /(\|(?:[fhck]?)$\n?)/mg,
+	cellRegExp: /(?:\|([^\n\|]*)\|)|(\|[fhck]?$\n?)/mg,
+	cellTermRegExp: /((?:\x20*)\|)/mg,
+	rowTypes: {"c":"caption", "h":"thead", "":"tbody", "f":"tfoot"},
+	handler: function(w)
+	{
+		var table = createTiddlyElement(w.output,"table",null,"twtable");
+		var prevColumns = [];
+		var currRowType = null;
+		var rowContainer;
+		var rowCount = 0;
+		w.nextMatch = w.matchStart;
+		this.lookaheadRegExp.lastIndex = w.nextMatch;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
+			var nextRowType = lookaheadMatch[2];
+			if(nextRowType == "k") {
+				table.className = lookaheadMatch[1];
+				w.nextMatch += lookaheadMatch[0].length+1;
+			} else {
+				if(nextRowType != currRowType) {
+					rowContainer = createTiddlyElement(table,this.rowTypes[nextRowType]);
+					currRowType = nextRowType;
+				}
+				if(currRowType == "c") {
+					// Caption
+					w.nextMatch++;
+					if(rowContainer != table.firstChild)
+						table.insertBefore(rowContainer,table.firstChild);
+					rowContainer.setAttribute("align",rowCount == 0?"top":"bottom");
+					w.subWikifyTerm(rowContainer,this.rowTermRegExp);
+				} else {
+					var theRow = createTiddlyElement(rowContainer,"tr",null,(rowCount&1)?"oddRow":"evenRow");
+					theRow.onmouseover = function() {addClass(this,"hoverRow");};
+					theRow.onmouseout = function() {removeClass(this,"hoverRow");};
+					this.rowHandler(w,theRow,prevColumns);
+					rowCount++;
+				}
+			}
+			this.lookaheadRegExp.lastIndex = w.nextMatch;
+			lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		}
+	},
+	rowHandler: function(w,e,prevColumns)
+	{
+		var col = 0;
+		var colSpanCount = 1;
+		var prevCell = null;
+		this.cellRegExp.lastIndex = w.nextMatch;
+		var cellMatch = this.cellRegExp.exec(w.source);
+		while(cellMatch && cellMatch.index == w.nextMatch) {
+			if(cellMatch[1] == "~") {
+				// Rowspan
+				var last = prevColumns[col];
+				if(last) {
+					last.rowSpanCount++;
+					last.element.setAttribute("rowspan",last.rowSpanCount);
+					last.element.setAttribute("rowSpan",last.rowSpanCount); // Needed for IE
+					last.element.valign = "center";
+				}
+				w.nextMatch = this.cellRegExp.lastIndex-1;
+			} else if(cellMatch[1] == ">") {
+				// Colspan
+				colSpanCount++;
+				w.nextMatch = this.cellRegExp.lastIndex-1;
+			} else if(cellMatch[2]) {
+				// End of row
+				if(prevCell && colSpanCount > 1) {
+					prevCell.setAttribute("colspan",colSpanCount);
+					prevCell.setAttribute("colSpan",colSpanCount); // Needed for IE
+				}
+				w.nextMatch = this.cellRegExp.lastIndex;
+				break;
+			} else {
+				// Cell
+				w.nextMatch++;
+				var styles = config.formatterHelpers.inlineCssHelper(w);
+				var spaceLeft = false;
+				var chr = w.source.substr(w.nextMatch,1);
+				while(chr == " ") {
+					spaceLeft = true;
+					w.nextMatch++;
+					chr = w.source.substr(w.nextMatch,1);
+				}
+				var cell;
+				if(chr == "!") {
+					cell = createTiddlyElement(e,"th");
+					w.nextMatch++;
+				} else {
+					cell = createTiddlyElement(e,"td");
+				}
+				prevCell = cell;
+				prevColumns[col] = {rowSpanCount:1,element:cell};
+				if(colSpanCount > 1) {
+					cell.setAttribute("colspan",colSpanCount);
+					cell.setAttribute("colSpan",colSpanCount); // Needed for IE
+					colSpanCount = 1;
+				}
+				config.formatterHelpers.applyCssHelper(cell,styles);
+				w.subWikifyTerm(cell,this.cellTermRegExp);
+				if(w.matchText.substr(w.matchText.length-2,1) == " ") // spaceRight
+					cell.align = spaceLeft ? "center" : "left";
+				else if(spaceLeft)
+					cell.align = "right";
+				w.nextMatch--;
+			}
+			col++;
+			this.cellRegExp.lastIndex = w.nextMatch;
+			cellMatch = this.cellRegExp.exec(w.source);
+		}
+	}
+},
+
+{
+	name: "heading",
+	match: "^!{1,6}",
+	termRegExp: /(\n)/mg,
+	handler: function(w)
+	{
+		w.subWikifyTerm(createTiddlyElement(w.output,"h" + w.matchLength),this.termRegExp);
+	}
+},
+
+{
+	name: "list",
+	match: "^(?:[\\*#;:]+)",
+	lookaheadRegExp: /^(?:(?:(\*)|(#)|(;)|(:))+)/mg,
+	termRegExp: /(\n)/mg,
+	handler: function(w)
+	{
+		var stack = [w.output];
+		var currLevel = 0, currType = null;
+		var listLevel, listType, itemType, baseType;
+		w.nextMatch = w.matchStart;
+		this.lookaheadRegExp.lastIndex = w.nextMatch;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		while(lookaheadMatch && lookaheadMatch.index == w.nextMatch) {
+			if(lookaheadMatch[1]) {
+				listType = "ul";
+				itemType = "li";
+			} else if(lookaheadMatch[2]) {
+				listType = "ol";
+				itemType = "li";
+			} else if(lookaheadMatch[3]) {
+				listType = "dl";
+				itemType = "dt";
+			} else if(lookaheadMatch[4]) {
+				listType = "dl";
+				itemType = "dd";
+			}
+			if(!baseType)
+				baseType = listType;
+			listLevel = lookaheadMatch[0].length;
+			w.nextMatch += lookaheadMatch[0].length;
+			var t;
+			if(listLevel > currLevel) {
+				for(t=currLevel; t<listLevel; t++) {
+					var target = (currLevel == 0) ? stack[stack.length-1] : stack[stack.length-1].lastChild;
+					stack.push(createTiddlyElement(target,listType));
+				}
+			} else if(listType!=baseType && listLevel==1) {
+				w.nextMatch -= lookaheadMatch[0].length;
+				return;
+			} else if(listLevel < currLevel) {
+				for(t=currLevel; t>listLevel; t--)
+					stack.pop();
+			} else if(listLevel == currLevel && listType != currType) {
+				stack.pop();
+				stack.push(createTiddlyElement(stack[stack.length-1].lastChild,listType));
+			}
+			currLevel = listLevel;
+			currType = listType;
+			var e = createTiddlyElement(stack[stack.length-1],itemType);
+			w.subWikifyTerm(e,this.termRegExp);
+			this.lookaheadRegExp.lastIndex = w.nextMatch;
+			lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		}
+	}
+},
+
+{
+	name: "quoteByBlock",
+	match: "^<<<\\n",
+	termRegExp: /(^<<<(\n|$))/mg,
+	element: "blockquote",
+	handler: config.formatterHelpers.createElementAndWikify
+},
+
+{
+	name: "quoteByLine",
+	match: "^>+",
+	lookaheadRegExp: /^>+/mg,
+	termRegExp: /(\n)/mg,
+	element: "blockquote",
+	handler: function(w)
+	{
+		var stack = [w.output];
+		var currLevel = 0;
+		var newLevel = w.matchLength;
+		var t;
+		do {
+			if(newLevel > currLevel) {
+				for(t=currLevel; t<newLevel; t++)
+					stack.push(createTiddlyElement(stack[stack.length-1],this.element));
+			} else if(newLevel < currLevel) {
+				for(t=currLevel; t>newLevel; t--)
+					stack.pop();
+			}
+			currLevel = newLevel;
+			w.subWikifyTerm(stack[stack.length-1],this.termRegExp);
+			createTiddlyElement(stack[stack.length-1],"br");
+			this.lookaheadRegExp.lastIndex = w.nextMatch;
+			var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+			var matched = lookaheadMatch && lookaheadMatch.index == w.nextMatch;
+			if(matched) {
+				newLevel = lookaheadMatch[0].length;
+				w.nextMatch += lookaheadMatch[0].length;
+			}
+		} while(matched);
+	}
+},
+
+{
+	name: "rule",
+	match: "^----+$\\n?|<hr ?/?>\\n?",
+	handler: function(w)
+	{
+		createTiddlyElement(w.output,"hr");
+	}
+},
+
+{
+	name: "monospacedByLine",
+	match: "^(?:/\\*\\{\\{\\{\\*/|\\{\\{\\{|//\\{\\{\\{|<!--\\{\\{\\{-->)\\n",
+	element: "pre",
+	handler: function(w)
+	{
+		switch(w.matchText) {
+		case "/*{{{*/\n": // CSS
+			this.lookaheadRegExp = /\/\*\{\{\{\*\/\n*((?:^[^\n]*\n)+?)(\n*^\/\*\}\}\}\*\/$\n?)/mg;
+			break;
+		case "{{{\n": // monospaced block
+			this.lookaheadRegExp = /^\{\{\{\n((?:^[^\n]*\n)+?)(^\}\}\}$\n?)/mg;
+			break;
+		case "//{{{\n": // plugin
+			this.lookaheadRegExp = /^\/\/\{\{\{\n\n*((?:^[^\n]*\n)+?)(\n*^\/\/\}\}\}$\n?)/mg;
+			break;
+		case "<!--{{{-->\n": //template
+			this.lookaheadRegExp = /<!--\{\{\{-->\n*((?:^[^\n]*\n)+?)(\n*^<!--\}\}\}-->$\n?)/mg;
+			break;
+		default:
+			break;
+		}
+		config.formatterHelpers.enclosedTextHelper.call(this,w);
+	}
+},
+
+{
+	name: "wikifyComment",
+	match: "^(?:/\\*\\*\\*|<!---)\\n",
+	handler: function(w)
+	{
+		var termRegExp = (w.matchText == "/***\n") ? (/(^\*\*\*\/\n)/mg) : (/(^--->\n)/mg);
+		w.subWikifyTerm(w.output,termRegExp);
+	}
+},
+
+{
+	name: "macro",
+	match: "<<",
+	lookaheadRegExp: /<<([^>\s]+)(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg,
+	handler: function(w)
+	{
+		this.lookaheadRegExp.lastIndex = w.matchStart;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		if(lookaheadMatch && lookaheadMatch.index == w.matchStart && lookaheadMatch[1]) {
+			w.nextMatch = this.lookaheadRegExp.lastIndex;
+			invokeMacro(w.output,lookaheadMatch[1],lookaheadMatch[2],w,w.tiddler);
+		}
+	}
+},
+
+{
+	name: "prettyLink",
+	match: "\\[\\[",
+	lookaheadRegExp: /\[\[(.*?)(?:\|(~)?(.*?))?\]\]/mg,
+	handler: function(w)
+	{
+		this.lookaheadRegExp.lastIndex = w.matchStart;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
+			var e;
+			var text = lookaheadMatch[1];
+			if(lookaheadMatch[3]) {
+				// Pretty bracketted link
+				var link = lookaheadMatch[3];
+				e = (!lookaheadMatch[2] && config.formatterHelpers.isExternalLink(link)) ?
+						createExternalLink(w.output,link) : createTiddlyLink(w.output,decodeURIComponent(link),false,null,w.isStatic,w.tiddler);
+			} else {
+				// Simple bracketted link
+				e = createTiddlyLink(w.output,decodeURIComponent(text),false,null,w.isStatic,w.tiddler);
+			}
+			createTiddlyText(e,text);
+			w.nextMatch = this.lookaheadRegExp.lastIndex;
+		}
+	}
+},
+
+{
+	name: "wikiLink",
+	match: config.textPrimitives.unWikiLink+"?"+config.textPrimitives.wikiLink,
+	handler: function(w)
+	{
+		if(w.matchText.substr(0,1) == config.textPrimitives.unWikiLink) {
+			w.outputText(w.output,w.matchStart+1,w.nextMatch);
+			return;
+		}
+		if(w.matchStart > 0) {
+			var preRegExp = new RegExp(config.textPrimitives.anyLetterStrict,"mg");
+			preRegExp.lastIndex = w.matchStart-1;
+			var preMatch = preRegExp.exec(w.source);
+			if(preMatch.index == w.matchStart-1) {
+				w.outputText(w.output,w.matchStart,w.nextMatch);
+				return;
+			}
+		}
+		if(w.autoLinkWikiWords || store.isShadowTiddler(w.matchText)) {
+			var link = createTiddlyLink(w.output,w.matchText,false,null,w.isStatic,w.tiddler);
+			w.outputText(link,w.matchStart,w.nextMatch);
+		} else {
+			w.outputText(w.output,w.matchStart,w.nextMatch);
+		}
+	}
+},
+
+{
+	name: "urlLink",
+	match: config.textPrimitives.urlPattern,
+	handler: function(w)
+	{
+		w.outputText(createExternalLink(w.output,w.matchText),w.matchStart,w.nextMatch);
+	}
+},
+
+{
+	name: "image",
+	match: "\\[[<>]?[Ii][Mm][Gg]\\[",
+	lookaheadRegExp: /\[([<]?)(>?)[Ii][Mm][Gg]\[(?:([^\|\]]+)\|)?([^\[\]\|]+)\](?:\[([^\]]*)\])?\]/mg,
+	handler: function(w)
+	{
+		this.lookaheadRegExp.lastIndex = w.matchStart;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
+			var e = w.output;
+			if(lookaheadMatch[5]) {
+				var link = lookaheadMatch[5];
+				e = config.formatterHelpers.isExternalLink(link) ? createExternalLink(w.output,link) : createTiddlyLink(w.output,link,false,null,w.isStatic,w.tiddler);
+				addClass(e,"imageLink");
+			}
+			var img = createTiddlyElement(e,"img");
+			if(lookaheadMatch[1])
+				img.align = "left";
+			else if(lookaheadMatch[2])
+				img.align = "right";
+			if(lookaheadMatch[3]) {
+				img.title = lookaheadMatch[3];
+				img.setAttribute("alt",lookaheadMatch[3]);
+			}
+			img.src = lookaheadMatch[4];
+			w.nextMatch = this.lookaheadRegExp.lastIndex;
+		}
+	}
+},
+
+{
+	name: "html",
+	match: "<[Hh][Tt][Mm][Ll]>",
+	lookaheadRegExp: /<[Hh][Tt][Mm][Ll]>((?:.|\n)*?)<\/[Hh][Tt][Mm][Ll]>/mg,
+	handler: function(w)
+	{
+		this.lookaheadRegExp.lastIndex = w.matchStart;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
+			createTiddlyElement(w.output,"span").innerHTML = lookaheadMatch[1];
+			w.nextMatch = this.lookaheadRegExp.lastIndex;
+		}
+	}
+},
+
+{
+	name: "commentByBlock",
+	match: "/%",
+	lookaheadRegExp: /\/%((?:.|\n)*?)%\//mg,
+	handler: function(w)
+	{
+		this.lookaheadRegExp.lastIndex = w.matchStart;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		if(lookaheadMatch && lookaheadMatch.index == w.matchStart)
+			w.nextMatch = this.lookaheadRegExp.lastIndex;
+	}
+},
+
+{
+	name: "characterFormat",
+	match: "''|//|__|\\^\\^|~~|--(?!\\s|$)|\\{\\{\\{",
+	handler: function(w)
+	{
+		switch(w.matchText) {
+		case "''":
+			w.subWikifyTerm(w.output.appendChild(document.createElement("strong")),/('')/mg);
+			break;
+		case "//":
+			w.subWikifyTerm(createTiddlyElement(w.output,"em"),/(\/\/)/mg);
+			break;
+		case "__":
+			w.subWikifyTerm(createTiddlyElement(w.output,"u"),/(__)/mg);
+			break;
+		case "^^":
+			w.subWikifyTerm(createTiddlyElement(w.output,"sup"),/(\^\^)/mg);
+			break;
+		case "~~":
+			w.subWikifyTerm(createTiddlyElement(w.output,"sub"),/(~~)/mg);
+			break;
+		case "--":
+			w.subWikifyTerm(createTiddlyElement(w.output,"strike"),/(--)/mg);
+			break;
+		case "{{{":
+			var lookaheadRegExp = /\{\{\{((?:.|\n)*?)\}\}\}/mg;
+			lookaheadRegExp.lastIndex = w.matchStart;
+			var lookaheadMatch = lookaheadRegExp.exec(w.source);
+			if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
+				createTiddlyElement(w.output,"code",null,null,lookaheadMatch[1]);
+				w.nextMatch = lookaheadRegExp.lastIndex;
+			}
+			break;
+		}
+	}
+},
+
+{
+	name: "customFormat",
+	match: "@@|\\{\\{",
+	handler: function(w)
+	{
+		switch(w.matchText) {
+		case "@@":
+			var e = createTiddlyElement(w.output,"span");
+			var styles = config.formatterHelpers.inlineCssHelper(w);
+			if(styles.length == 0)
+				e.className = "marked";
+			else
+				config.formatterHelpers.applyCssHelper(e,styles);
+			w.subWikifyTerm(e,/(@@)/mg);
+			break;
+		case "{{":
+			var lookaheadRegExp = /\{\{[\s]*([\w]+[\s\w]*)[\s]*\{(\n?)/mg;
+			lookaheadRegExp.lastIndex = w.matchStart;
+			var lookaheadMatch = lookaheadRegExp.exec(w.source);
+			if(lookaheadMatch) {
+				w.nextMatch = lookaheadRegExp.lastIndex;
+				e = createTiddlyElement(w.output,lookaheadMatch[2] == "\n" ? "div" : "span",null,lookaheadMatch[1]);
+				w.subWikifyTerm(e,/(\}\}\})/mg);
+			}
+			break;
+		}
+	}
+},
+
+{
+	name: "mdash",
+	match: "--",
+	handler: function(w)
+	{
+		createTiddlyElement(w.output,"span").innerHTML = "&mdash;";
+	}
+},
+
+{
+	name: "lineBreak",
+	match: "\\n|<br ?/?>",
+	handler: function(w)
+	{
+		createTiddlyElement(w.output,"br");
+	}
+},
+
+{
+	name: "rawText",
+	match: "\\\"{3}|<nowiki>",
+	lookaheadRegExp: /(?:\"{3}|<nowiki>)((?:.|\n)*?)(?:\"{3}|<\/nowiki>)/mg,
+	handler: function(w)
+	{
+		this.lookaheadRegExp.lastIndex = w.matchStart;
+		var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
+		if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
+			createTiddlyElement(w.output,"span",null,null,lookaheadMatch[1]);
+			w.nextMatch = this.lookaheadRegExp.lastIndex;
+		}
+	}
+},
+
+{
+	name: "htmlEntitiesEncoding",
+	match: "(?:(?:&#?[a-zA-Z0-9]{2,8};|.)(?:&#?(?:x0*(?:3[0-6][0-9a-fA-F]|1D[c-fC-F][0-9a-fA-F]|20[d-fD-F][0-9a-fA-F]|FE2[0-9a-fA-F])|0*(?:76[89]|7[7-9][0-9]|8[0-7][0-9]|761[6-9]|76[2-7][0-9]|84[0-3][0-9]|844[0-7]|6505[6-9]|6506[0-9]|6507[0-1]));)+|&#?[a-zA-Z0-9]{2,8};)",
+	handler: function(w)
+	{
+		createTiddlyElement(w.output,"span").innerHTML = w.matchText;
+	}
+}
+
+];
+
+//--
+//-- Wikifier
+//--
+
+function getParser(tiddler,format)
+{
+	if(tiddler) {
+		if(!format)
+			format = tiddler.fields["wikiformat"];
+		var i;
+		if(format) {
+			for(i in config.parsers) {
+				if(format == config.parsers[i].format)
+					return config.parsers[i];
+			}
+		} else {
+			for(i in config.parsers) {
+				if(tiddler.isTagged(config.parsers[i].formatTag))
+					return config.parsers[i];
+			}
+		}
+	}
+	return formatter;
+}
+
+function wikify(source,output,highlightRegExp,tiddler)
+{
+	if(source) {
+		var wikifier = new Wikifier(source,getParser(tiddler),highlightRegExp,tiddler);
+		var t0 = new Date();
+		wikifier.subWikify(output);
+		if(tiddler && config.options.chkDisplayInstrumentation)
+			displayMessage("wikify:" +tiddler.title+ " in " + (new Date()-t0) + " ms");
+	}
+}
+
+function wikifyStatic(source,highlightRegExp,tiddler,format)
+{
+	var e = createTiddlyElement(document.body,"pre");
+	e.style.display = "none";
+	var html = "";
+	if(source && source != "") {
+		if(!tiddler)
+			tiddler = new Tiddler("temp");
+		var wikifier = new Wikifier(source,getParser(tiddler,format),highlightRegExp,tiddler);
+		wikifier.isStatic = true;
+		wikifier.subWikify(e);
+		html = e.innerHTML;
+		removeNode(e);
+	}
+	return html;
+}
+
+function wikifyPlain(title,theStore,limit)
+{
+	if(!theStore)
+		theStore = store;
+	if(theStore.tiddlerExists(title) || theStore.isShadowTiddler(title)) {
+		return wikifyPlainText(theStore.getTiddlerText(title),limit,tiddler);
+	} else {
+		return "";
+	}
+}
+
+function wikifyPlainText(text,limit,tiddler)
+{
+	if(limit > 0)
+		text = text.substr(0,limit);
+	var wikifier = new Wikifier(text,formatter,null,tiddler);
+	return wikifier.wikifyPlain();
+}
+
+function highlightify(source,output,highlightRegExp,tiddler)
+{
+	if(source) {
+		var wikifier = new Wikifier(source,formatter,highlightRegExp,tiddler);
+		wikifier.outputText(output,0,source.length);
+	}
+}
+
+function Wikifier(source,formatter,highlightRegExp,tiddler)
+{
+	this.source = source;
+	this.output = null;
+	this.formatter = formatter;
+	this.nextMatch = 0;
+	this.autoLinkWikiWords = tiddler && tiddler.autoLinkWikiWords() == false ? false : true;
+	this.highlightRegExp = highlightRegExp;
+	this.highlightMatch = null;
+	this.isStatic = false;
+	if(highlightRegExp) {
+		highlightRegExp.lastIndex = 0;
+		this.highlightMatch = highlightRegExp.exec(source);
+	}
+	this.tiddler = tiddler;
+}
+
+Wikifier.prototype.wikifyPlain = function()
+{
+	var e = createTiddlyElement(document.body,"div");
+	e.style.display = "none";
+	this.subWikify(e);
+	var text = getPlainText(e);
+	removeNode(e);
+	return text;
+};
+
+Wikifier.prototype.subWikify = function(output,terminator)
+{
+	try {
+		if(terminator)
+			this.subWikifyTerm(output,new RegExp("(" + terminator + ")","mg"));
+		else
+			this.subWikifyUnterm(output);
+	} catch(ex) {
+		showException(ex);
+	}
+};
+
+Wikifier.prototype.subWikifyUnterm = function(output)
+{
+	var oldOutput = this.output;
+	this.output = output;
+	this.formatter.formatterRegExp.lastIndex = this.nextMatch;
+	var formatterMatch = this.formatter.formatterRegExp.exec(this.source);
+	while(formatterMatch) {
+		// Output any text before the match
+		if(formatterMatch.index > this.nextMatch)
+			this.outputText(this.output,this.nextMatch,formatterMatch.index);
+		// Set the match parameters for the handler
+		this.matchStart = formatterMatch.index;
+		this.matchLength = formatterMatch[0].length;
+		this.matchText = formatterMatch[0];
+		this.nextMatch = this.formatter.formatterRegExp.lastIndex;
+		for(var t=1; t<formatterMatch.length; t++) {
+			if(formatterMatch[t]) {
+				this.formatter.formatters[t-1].handler(this);
+				this.formatter.formatterRegExp.lastIndex = this.nextMatch;
+				break;
+			}
+		}
+		formatterMatch = this.formatter.formatterRegExp.exec(this.source);
+	}
+	if(this.nextMatch < this.source.length) {
+		this.outputText(this.output,this.nextMatch,this.source.length);
+		this.nextMatch = this.source.length;
+	}
+	this.output = oldOutput;
+};
+
+Wikifier.prototype.subWikifyTerm = function(output,terminatorRegExp)
+{
+	var oldOutput = this.output;
+	this.output = output;
+	terminatorRegExp.lastIndex = this.nextMatch;
+	var terminatorMatch = terminatorRegExp.exec(this.source);
+	this.formatter.formatterRegExp.lastIndex = this.nextMatch;
+	var formatterMatch = this.formatter.formatterRegExp.exec(terminatorMatch ? this.source.substr(0,terminatorMatch.index) : this.source);
+	while(terminatorMatch || formatterMatch) {
+		if(terminatorMatch && (!formatterMatch || terminatorMatch.index <= formatterMatch.index)) {
+			if(terminatorMatch.index > this.nextMatch)
+				this.outputText(this.output,this.nextMatch,terminatorMatch.index);
+			this.matchText = terminatorMatch[1];
+			this.matchLength = terminatorMatch[1].length;
+			this.matchStart = terminatorMatch.index;
+			this.nextMatch = this.matchStart + this.matchLength;
+			this.output = oldOutput;
+			return;
+		}
+		if(formatterMatch.index > this.nextMatch)
+			this.outputText(this.output,this.nextMatch,formatterMatch.index);
+		this.matchStart = formatterMatch.index;
+		this.matchLength = formatterMatch[0].length;
+		this.matchText = formatterMatch[0];
+		this.nextMatch = this.formatter.formatterRegExp.lastIndex;
+		for(var t=1; t<formatterMatch.length; t++) {
+			if(formatterMatch[t]) {
+				this.formatter.formatters[t-1].handler(this);
+				this.formatter.formatterRegExp.lastIndex = this.nextMatch;
+				break;
+			}
+		}
+		terminatorRegExp.lastIndex = this.nextMatch;
+		terminatorMatch = terminatorRegExp.exec(this.source);
+		formatterMatch = this.formatter.formatterRegExp.exec(terminatorMatch ? this.source.substr(0,terminatorMatch.index) : this.source);
+	}
+	if(this.nextMatch < this.source.length) {
+		this.outputText(this.output,this.nextMatch,this.source.length);
+		this.nextMatch = this.source.length;
+	}
+	this.output = oldOutput;
+};
+
+Wikifier.prototype.outputText = function(place,startPos,endPos)
+{
+	while(this.highlightMatch && (this.highlightRegExp.lastIndex > startPos) && (this.highlightMatch.index < endPos) && (startPos < endPos)) {
+		if(this.highlightMatch.index > startPos) {
+			createTiddlyText(place,this.source.substring(startPos,this.highlightMatch.index));
+			startPos = this.highlightMatch.index;
+		}
+		var highlightEnd = Math.min(this.highlightRegExp.lastIndex,endPos);
+		var theHighlight = createTiddlyElement(place,"span",null,"highlight",this.source.substring(startPos,highlightEnd));
+		startPos = highlightEnd;
+		if(startPos >= this.highlightRegExp.lastIndex)
+			this.highlightMatch = this.highlightRegExp.exec(this.source);
+	}
+	if(startPos < endPos) {
+		createTiddlyText(place,this.source.substring(startPos,endPos));
+	}
+};
+
+//--
+//-- Macro definitions
+//--
+
+config.macros.today.handler = function(place,macroName,params)
+{
+	var now = new Date();
+	var text = params[0] ? now.formatString(params[0].trim()) : now.toLocaleString();
+	createTiddlyElement(place,"span",null,null,text);
+};
+
+config.macros.version.handler = function(place)
+{
+	createTiddlyElement(place,"span",null,null,formatVersion());
+};
+
+config.macros.list.handler = function(place,macroName,params)
+{
+	var type = params[0] || "all";
+	var list = document.createElement("ul");
+	place.appendChild(list);
+	if(this[type].prompt)
+		createTiddlyElement(list,"li",null,"listTitle",this[type].prompt);
+	var results;
+	if(this[type].handler)
+		results = this[type].handler(params);
+	for(var t = 0; t < results.length; t++) {
+		var li = document.createElement("li");
+		list.appendChild(li);
+		createTiddlyLink(li,typeof results[t] == "string" ? results[t] : results[t].title,true);
+	}
+};
+
+config.macros.list.all.handler = function(params)
+{
+	return store.reverseLookup("tags","excludeLists",false,"title");
+};
+
+config.macros.list.missing.handler = function(params)
+{
+	return store.getMissingLinks();
+};
+
+config.macros.list.orphans.handler = function(params)
+{
+	return store.getOrphans();
+};
+
+config.macros.list.shadowed.handler = function(params)
+{
+	return store.getShadowed();
+};
+
+config.macros.list.touched.handler = function(params)
+{
+	return store.getTouched();
+};
+
+config.macros.list.filter.handler = function(params)
+{
+	var filter = params[1];
+	var results = [];
+	if(filter) {
+		var tiddlers = store.filterTiddlers(filter);
+		for(var t=0; t<tiddlers.length; t++)
+			results.push(tiddlers[t].title);
+	}
+	return results;
+};
+
+config.macros.allTags.handler = function(place,macroName,params)
+{
+	var tags = store.getTags(params[0]);
+	var ul = createTiddlyElement(place,"ul");
+	if(tags.length == 0)
+		createTiddlyElement(ul,"li",null,"listTitle",this.noTags);
+	for(var t=0; t<tags.length; t++) {
+		var title = tags[t][0];
+		var info = getTiddlyLinkInfo(title);
+		var li = createTiddlyElement(ul,"li");
+		var btn = createTiddlyButton(li,title + " (" + tags[t][1] + ")",this.tooltip.format([title]),onClickTag,info.classes);
+		btn.setAttribute("tag",title);
+		btn.setAttribute("refresh","link");
+		btn.setAttribute("tiddlyLink",title);
+	}
+};
+
+config.macros.timeline.handler = function(place,macroName,params)
+{
+	var field = params[0] || "modified";
+	var tiddlers = store.reverseLookup("tags","excludeLists",false,field);
+	var lastDay = "";
+	var last = params[1] ? tiddlers.length-Math.min(tiddlers.length,parseInt(params[1])) : 0;
+	var dateFormat = params[2] || this.dateFormat;
+	for(var t=tiddlers.length-1; t>=last; t--) {
+		var tiddler = tiddlers[t];
+		var theDay = tiddler[field].convertToLocalYYYYMMDDHHMM().substr(0,8);
+		if(theDay != lastDay) {
+			var ul = document.createElement("ul");
+			place.appendChild(ul);
+			createTiddlyElement(ul,"li",null,"listTitle",tiddler[field].formatString(dateFormat));
+			lastDay = theDay;
+		}
+		createTiddlyElement(ul,"li",null,"listLink").appendChild(createTiddlyLink(place,tiddler.title,true));
+	}
+};
+
+config.macros.tiddler.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	params = paramString.parseParams("name",null,true,false,true);
+	var names = params[0]["name"];
+	var tiddlerName = names[0];
+	var className = names[1] || null;
+	var args = params[0]["with"];
+	var wrapper = createTiddlyElement(place,"span",null,className);
+	if(!args) {
+		wrapper.setAttribute("refresh","content");
+		wrapper.setAttribute("tiddler",tiddlerName);
+	}
+	var text = store.getTiddlerText(tiddlerName);
+	if(text) {
+		var stack = config.macros.tiddler.tiddlerStack;
+		if(stack.indexOf(tiddlerName) !== -1)
+			return;
+		stack.push(tiddlerName);
+		try {
+			var n = args ? Math.min(args.length,9) : 0;
+			for(var i=0; i<n; i++) {
+				var placeholderRE = new RegExp("\\$" + (i + 1),"mg");
+				text = text.replace(placeholderRE,args[i]);
+			}
+			config.macros.tiddler.renderText(wrapper,text,tiddlerName,params);
+		} finally {
+			stack.pop();
+		}
+	}
+};
+
+config.macros.tiddler.renderText = function(place,text,tiddlerName,params)
+{
+	wikify(text,place,null,store.getTiddler(tiddlerName));
+};
+
+config.macros.tiddler.tiddlerStack = [];
+
+config.macros.tag.handler = function(place,macroName,params)
+{
+	createTagButton(place,params[0],null,params[1],params[2]);
+};
+
+config.macros.tags.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	params = paramString.parseParams("anon",null,true,false,false);
+	var ul = createTiddlyElement(place,"ul");
+	var title = getParam(params,"anon","");
+	if(title && store.tiddlerExists(title))
+		tiddler = store.getTiddler(title);
+	var sep = getParam(params,"sep"," ");
+	var lingo = config.views.wikified.tag;
+	var prompt = tiddler.tags.length == 0 ? lingo.labelNoTags : lingo.labelTags;
+	createTiddlyElement(ul,"li",null,"listTitle",prompt.format([tiddler.title]));
+	for(var t=0; t<tiddler.tags.length; t++) {
+		createTagButton(createTiddlyElement(ul,"li"),tiddler.tags[t],tiddler.title);
+		if(t<tiddler.tags.length-1)
+			createTiddlyText(ul,sep);
+	}
+};
+
+config.macros.tagging.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	params = paramString.parseParams("anon",null,true,false,false);
+	var ul = createTiddlyElement(place,"ul");
+	var title = getParam(params,"anon","");
+	if(title == "" && tiddler instanceof Tiddler)
+		title = tiddler.title;
+	var sep = getParam(params,"sep"," ");
+	ul.setAttribute("title",this.tooltip.format([title]));
+	var tagged = store.getTaggedTiddlers(title);
+	var prompt = tagged.length == 0 ? this.labelNotTag : this.label;
+	createTiddlyElement(ul,"li",null,"listTitle",prompt.format([title,tagged.length]));
+	for(var t=0; t<tagged.length; t++) {
+		createTiddlyLink(createTiddlyElement(ul,"li"),tagged[t].title,true);
+		if(t<tagged.length-1)
+			createTiddlyText(ul,sep);
+	}
+};
+
+config.macros.closeAll.handler = function(place)
+{
+	createTiddlyButton(place,this.label,this.prompt,this.onClick);
+};
+
+config.macros.closeAll.onClick = function(e)
+{
+	story.closeAllTiddlers();
+	return false;
+};
+
+config.macros.permaview.handler = function(place)
+{
+	createTiddlyButton(place,this.label,this.prompt,this.onClick);
+};
+
+config.macros.permaview.onClick = function(e)
+{
+	story.permaView();
+	return false;
+};
+
+config.macros.saveChanges.handler = function(place,macroName,params)
+{
+	if(!readOnly)
+		createTiddlyButton(place,params[0] || this.label,params[1] || this.prompt,this.onClick,null,null,this.accessKey);
+};
+
+config.macros.saveChanges.onClick = function(e)
+{
+	saveChanges();
+	return false;
+};
+
+config.macros.slider.onClickSlider = function(ev)
+{
+	var e = ev || window.event;
+	var n = this.nextSibling;
+	var cookie = n.getAttribute("cookie");
+	var isOpen = n.style.display != "none";
+	if(config.options.chkAnimate && anim && typeof Slider == "function")
+		anim.startAnimating(new Slider(n,!isOpen,null,"none"));
+	else
+		n.style.display = isOpen ? "none" : "block";
+	config.options[cookie] = !isOpen;
+	saveOptionCookie(cookie);
+	return false;
+};
+
+config.macros.slider.createSlider = function(place,cookie,title,tooltip)
+{
+	var c = cookie || "";
+	var btn = createTiddlyButton(place,title,tooltip,this.onClickSlider);
+	var panel = createTiddlyElement(null,"div",null,"sliderPanel");
+	panel.setAttribute("cookie",c);
+	panel.style.display = config.options[c] ? "block" : "none";
+	place.appendChild(panel);
+	return panel;
+};
+
+config.macros.slider.handler = function(place,macroName,params)
+{
+	var panel = this.createSlider(place,params[0],params[2],params[3]);
+	var text = store.getTiddlerText(params[1]);
+	panel.setAttribute("refresh","content");
+	panel.setAttribute("tiddler",params[1]);
+	if(text)
+		wikify(text,panel,null,store.getTiddler(params[1]));
+};
+
+// <<gradient [[tiddler name]] vert|horiz rgb rgb rgb rgb... >>
+config.macros.gradient.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	var panel = wikifier ? createTiddlyElement(place,"div",null,"gradient") : place;
+	panel.style.position = "relative";
+	panel.style.overflow = "hidden";
+	panel.style.zIndex = "0";
+	if(wikifier) {
+		var styles = config.formatterHelpers.inlineCssHelper(wikifier);
+		config.formatterHelpers.applyCssHelper(panel,styles);
+	}
+	params = paramString.parseParams("color");
+	var locolors = [], hicolors = [];
+	for(var t=2; t<params.length; t++) {
+		var c = params[t].value;
+		if(params[t].name == "snap") {
+			hicolors[hicolors.length-1] = c;
+		} else {
+			locolors.push(c);
+			hicolors.push(c);
+		}
+	}
+	drawGradient(panel,params[1].value != "vert",locolors,hicolors);
+	if(wikifier)
+		wikifier.subWikify(panel,">>");
+	if(document.all) {
+		panel.style.height = "100%";
+		panel.style.width = "100%";
+	}
+};
+
+config.macros.message.handler = function(place,macroName,params)
+{
+	if(params[0]) {
+		var names = params[0].split(".");
+		var lookupMessage = function(root,nameIndex) {
+				if(names[nameIndex] in root) {
+					if(nameIndex < names.length-1)
+						return (lookupMessage(root[names[nameIndex]],nameIndex+1));
+					else
+						return root[names[nameIndex]];
+				} else
+					return null;
+			};
+		var m = lookupMessage(config,0);
+		if(m == null)
+			m = lookupMessage(window,0);
+		createTiddlyText(place,m.toString().format(params.splice(1)));
+	}
+};
+
+
+config.macros.view.views = {
+	text: function(value,place,params,wikifier,paramString,tiddler) {
+		highlightify(value,place,highlightHack,tiddler);
+	},
+	link: function(value,place,params,wikifier,paramString,tiddler) {
+		createTiddlyLink(place,value,true);
+	},
+	wikified: function(value,place,params,wikifier,paramString,tiddler) {
+		if(params[2])
+			value=params[2].unescapeLineBreaks().format([value]);
+		wikify(value,place,highlightHack,tiddler);
+	},
+	date: function(value,place,params,wikifier,paramString,tiddler) {
+		value = Date.convertFromYYYYMMDDHHMM(value);
+		createTiddlyText(place,value.formatString(params[2] ? params[2] : config.views.wikified.dateFormat));
+	}
+};
+
+config.macros.view.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	if((tiddler instanceof Tiddler) && params[0]) {
+		var value = store.getValue(tiddler,params[0]);
+		if(value) {
+			var type = params[1] || config.macros.view.defaultView;
+			var handler = config.macros.view.views[type];
+			if(handler)
+				handler(value,place,params,wikifier,paramString,tiddler);
+		}
+	}
+};
+
+config.macros.edit.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	var field = params[0];
+	var rows = params[1] || 0;
+	var defVal = params[2] || '';
+	if((tiddler instanceof Tiddler) && field) {
+		story.setDirty(tiddler.title,true);
+		var e,v;
+		if(field != "text" && !rows) {
+			e = createTiddlyElement(null,"input");
+			if(tiddler.isReadOnly())
+				e.setAttribute("readOnly","readOnly");
+			e.setAttribute("edit",field);
+			e.setAttribute("type","text");
+			e.value = store.getValue(tiddler,field) || defVal;
+			e.setAttribute("size","40");
+			e.setAttribute("autocomplete","off");
+			place.appendChild(e);
+		} else {
+			var wrapper1 = createTiddlyElement(null,"fieldset",null,"fieldsetFix");
+			var wrapper2 = createTiddlyElement(wrapper1,"div");
+			e = createTiddlyElement(wrapper2,"textarea");
+			if(tiddler.isReadOnly())
+				e.setAttribute("readOnly","readOnly");
+			e.value = v = store.getValue(tiddler,field) || defVal;
+			rows = rows || 10;
+			var lines = v.match(/\n/mg);
+			var maxLines = Math.max(parseInt(config.options.txtMaxEditRows),5);
+			if(lines != null && lines.length > rows)
+				rows = lines.length + 5;
+			rows = Math.min(rows,maxLines);
+			e.setAttribute("rows",rows);
+			e.setAttribute("edit",field);
+			place.appendChild(wrapper1);
+		}
+		return e;
+	}
+};
+
+config.macros.tagChooser.onClick = function(ev)
+{
+	var e = ev || window.event;
+	var lingo = config.views.editor.tagChooser;
+	var popup = Popup.create(this);
+	var tags = store.getTags(this.getAttribute("tags"));
+	if(tags.length == 0)
+		createTiddlyText(createTiddlyElement(popup,"li"),lingo.popupNone);
+	for(var t=0; t<tags.length; t++) {
+		var tag = createTiddlyButton(createTiddlyElement(popup,"li"),tags[t][0],lingo.tagTooltip.format([tags[t][0]]),config.macros.tagChooser.onTagClick);
+		tag.setAttribute("tag",tags[t][0]);
+		tag.setAttribute("tiddler",this.getAttribute("tiddler"));
+	}
+	Popup.show();
+	e.cancelBubble = true;
+	if(e.stopPropagation) e.stopPropagation();
+	return false;
+};
+
+config.macros.tagChooser.onTagClick = function(ev)
+{
+	var e = ev || window.event;
+	if(e.metaKey || e.ctrlKey) stopEvent(e); //# keep popup open on CTRL-click
+	var tag = this.getAttribute("tag");
+	var title = this.getAttribute("tiddler");
+	if(!readOnly)
+		story.setTiddlerTag(title,tag,0);
+	return false;
+};
+
+config.macros.tagChooser.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	if(tiddler instanceof Tiddler) {
+		var lingo = config.views.editor.tagChooser;
+		var btn = createTiddlyButton(place,lingo.text,lingo.tooltip,this.onClick);
+		btn.setAttribute("tiddler",tiddler.title);
+		btn.setAttribute("tags",params[0]);
+	}
+};
+
+config.macros.refreshDisplay.handler = function(place)
+{
+	createTiddlyButton(place,this.label,this.prompt,this.onClick);
+};
+
+config.macros.refreshDisplay.onClick = function(e)
+{
+	refreshAll();
+	return false;
+};
+
+config.macros.annotations.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	var title = tiddler ? tiddler.title : null;
+	var a = title ? config.annotations[title] : null;
+	if(!tiddler || !title || !a)
+		return;
+	var text = a.format([title]);
+	wikify(text,createTiddlyElement(place,"div",null,"annotation"),null,tiddler);
+};
+
+//--
+//-- NewTiddler and NewJournal macros
+//--
+
+config.macros.newTiddler.createNewTiddlerButton = function(place,title,params,label,prompt,accessKey,newFocus,isJournal)
+{
+	var tags = [];
+	for(var t=1; t<params.length; t++) {
+		if((params[t].name == "anon" && t != 1) || (params[t].name == "tag"))
+			tags.push(params[t].value);
+	}
+	label = getParam(params,"label",label);
+	prompt = getParam(params,"prompt",prompt);
+	accessKey = getParam(params,"accessKey",accessKey);
+	newFocus = getParam(params,"focus",newFocus);
+	var customFields = getParam(params,"fields","");
+	if(!customFields && !store.isShadowTiddler(title))
+		customFields = String.encodeHashMap(config.defaultCustomFields);
+	var btn = createTiddlyButton(place,label,prompt,this.onClickNewTiddler,null,null,accessKey);
+	btn.setAttribute("newTitle",title);
+	btn.setAttribute("isJournal",isJournal ? "true" : "false");
+	if(tags.length > 0)
+		btn.setAttribute("params",tags.join("|"));
+	btn.setAttribute("newFocus",newFocus);
+	btn.setAttribute("newTemplate",getParam(params,"template",DEFAULT_EDIT_TEMPLATE));
+	if(customFields !== "")
+		btn.setAttribute("customFields",customFields);
+	var text = getParam(params,"text");
+	if(text !== undefined)
+		btn.setAttribute("newText",text);
+	return btn;
+};
+
+config.macros.newTiddler.onClickNewTiddler = function()
+{
+	var title = this.getAttribute("newTitle");
+	if(this.getAttribute("isJournal") == "true") {
+		title = new Date().formatString(title.trim());
+	}
+	var params = this.getAttribute("params");
+	var tags = params ? params.split("|") : [];
+	var focus = this.getAttribute("newFocus");
+	var template = this.getAttribute("newTemplate");
+	var customFields = this.getAttribute("customFields");
+	if(!customFields && !store.isShadowTiddler(title))
+		customFields = String.encodeHashMap(config.defaultCustomFields);
+	story.displayTiddler(null,title,template,false,null,null);
+	var tiddlerElem = story.getTiddler(title);
+	if(customFields)
+		story.addCustomFields(tiddlerElem,customFields);
+	var text = this.getAttribute("newText");
+	if(typeof text == "string" && story.getTiddlerField(title,"text"))
+		story.getTiddlerField(title,"text").value = text.format([title]);
+	for(var t=0;t<tags.length;t++)
+		story.setTiddlerTag(title,tags[t],+1);
+	story.focusTiddler(title,focus);
+	return false;
+};
+
+config.macros.newTiddler.handler = function(place,macroName,params,wikifier,paramString)
+{
+	if(!readOnly) {
+		params = paramString.parseParams("anon",null,true,false,false);
+		var title = params[1] && params[1].name == "anon" ? params[1].value : this.title;
+		title = getParam(params,"title",title);
+		this.createNewTiddlerButton(place,title,params,this.label,this.prompt,this.accessKey,"title",false);
+	}
+};
+
+config.macros.newJournal.handler = function(place,macroName,params,wikifier,paramString)
+{
+	if(!readOnly) {
+		params = paramString.parseParams("anon",null,true,false,false);
+		var title = params[1] && params[1].name == "anon" ? params[1].value : config.macros.timeline.dateFormat;
+		title = getParam(params,"title",title);
+		config.macros.newTiddler.createNewTiddlerButton(place,title,params,this.label,this.prompt,this.accessKey,"text",true);
+	}
+};
+
+//--
+//-- Search macro
+//--
+
+config.macros.search.handler = function(place,macroName,params)
+{
+	var searchTimeout = null;
+	var btn = createTiddlyButton(place,this.label,this.prompt,this.onClick,"searchButton");
+	var txt = createTiddlyElement(null,"input",null,"txtOptionInput searchField");
+	if(params[0])
+		txt.value = params[0];
+	if(config.browser.isSafari) {
+		txt.setAttribute("type","search");
+		txt.setAttribute("results","5");
+	} else {
+		txt.setAttribute("type","text");
+	}
+	place.appendChild(txt);
+	txt.onkeyup = this.onKeyPress;
+	txt.onfocus = this.onFocus;
+	txt.setAttribute("size",this.sizeTextbox);
+	txt.setAttribute("accessKey",this.accessKey);
+	txt.setAttribute("autocomplete","off");
+	txt.setAttribute("lastSearchText","");
+};
+
+// Global because there's only ever one outstanding incremental search timer
+config.macros.search.timeout = null;
+
+config.macros.search.doSearch = function(txt)
+{
+	if(txt.value.length > 0) {
+		story.search(txt.value,config.options.chkCaseSensitiveSearch,config.options.chkRegExpSearch);
+		txt.setAttribute("lastSearchText",txt.value);
+	}
+};
+
+config.macros.search.onClick = function(e)
+{
+	config.macros.search.doSearch(this.nextSibling);
+	return false;
+};
+
+config.macros.search.onKeyPress = function(ev)
+{
+	var e = ev || window.event;
+	switch(e.keyCode) {
+		case 13: // Ctrl-Enter
+		case 10: // Ctrl-Enter on IE PC
+			config.macros.search.doSearch(this);
+			break;
+		case 27: // Escape
+			this.value = "";
+			clearMessage();
+			break;
+	}
+	if(config.options.chkIncrementalSearch) {
+		if(this.value.length > 2) {
+			if(this.value != this.getAttribute("lastSearchText")) {
+				if(config.macros.search.timeout)
+					clearTimeout(config.macros.search.timeout);
+				var txt = this;
+				config.macros.search.timeout = setTimeout(function() {config.macros.search.doSearch(txt);},500);
+			}
+		} else {
+			if(config.macros.search.timeout)
+				clearTimeout(config.macros.search.timeout);
+		}
+	}
+};
+
+config.macros.search.onFocus = function(e)
+{
+	this.select();
+};
+
+//--
+//-- Tabs macro
+//--
+
+config.macros.tabs.handler = function(place,macroName,params)
+{
+	var cookie = params[0];
+	var numTabs = (params.length-1)/3;
+	var wrapper = createTiddlyElement(null,"div",null,"tabsetWrapper " + cookie);
+	var tabset = createTiddlyElement(wrapper,"div",null,"tabset");
+	tabset.setAttribute("cookie",cookie);
+	var validTab = false;
+	for(var t=0; t<numTabs; t++) {
+		var label = params[t*3+1];
+		var prompt = params[t*3+2];
+		var content = params[t*3+3];
+		var tab = createTiddlyButton(tabset,label,prompt,this.onClickTab,"tab tabUnselected");
+		tab.setAttribute("tab",label);
+		tab.setAttribute("content",content);
+		tab.title = prompt;
+		if(config.options[cookie] == label)
+			validTab = true;
+	}
+	if(!validTab)
+		config.options[cookie] = params[1];
+	place.appendChild(wrapper);
+	this.switchTab(tabset,config.options[cookie]);
+};
+
+config.macros.tabs.onClickTab = function(e)
+{
+	config.macros.tabs.switchTab(this.parentNode,this.getAttribute("tab"));
+	return false;
+};
+
+config.macros.tabs.switchTab = function(tabset,tab)
+{
+	var cookie = tabset.getAttribute("cookie");
+	var theTab = null;
+	var nodes = tabset.childNodes;
+	for(var t=0; t<nodes.length; t++) {
+		if(nodes[t].getAttribute && nodes[t].getAttribute("tab") == tab) {
+			theTab = nodes[t];
+			theTab.className = "tab tabSelected";
+		} else {
+			nodes[t].className = "tab tabUnselected";
+		}
+	}
+	if(theTab) {
+		if(tabset.nextSibling && tabset.nextSibling.className == "tabContents")
+			removeNode(tabset.nextSibling);
+		var tabContent = createTiddlyElement(null,"div",null,"tabContents");
+		tabset.parentNode.insertBefore(tabContent,tabset.nextSibling);
+		var contentTitle = theTab.getAttribute("content");
+		wikify(store.getTiddlerText(contentTitle),tabContent,null,store.getTiddler(contentTitle));
+		if(cookie) {
+			config.options[cookie] = tab;
+			saveOptionCookie(cookie);
+		}
+	}
+};
+
+//--
+//-- Tiddler toolbar
+//--
+
+// Create a toolbar command button
+config.macros.toolbar.createCommand = function(place,commandName,tiddler,className)
+{
+	if(typeof commandName != "string") {
+		var c = null;
+		for(var t in config.commands) {
+			if(config.commands[t] == commandName)
+				c = t;
+		}
+		commandName = c;
+	}
+	if((tiddler instanceof Tiddler) && (typeof commandName == "string")) {
+		var command = config.commands[commandName];
+		if(command.isEnabled ? command.isEnabled(tiddler) : this.isCommandEnabled(command,tiddler)) {
+			var text = command.getText ? command.getText(tiddler) : this.getCommandText(command,tiddler);
+			var tooltip = command.getTooltip ? command.getTooltip(tiddler) : this.getCommandTooltip(command,tiddler);
+			var cmd;
+			switch(command.type) {
+			case "popup":
+				cmd = this.onClickPopup;
+				break;
+			case "command":
+			default:
+				cmd = this.onClickCommand;
+				break;
+			}
+			var btn = createTiddlyButton(null,text,tooltip,cmd);
+			btn.setAttribute("commandName",commandName);
+			btn.setAttribute("tiddler",tiddler.title);
+			if(className)
+				addClass(btn,className);
+			place.appendChild(btn);
+		}
+	}
+};
+
+config.macros.toolbar.isCommandEnabled = function(command,tiddler)
+{
+	var title = tiddler.title;
+	var ro = tiddler.isReadOnly();
+	var shadow = store.isShadowTiddler(title) && !store.tiddlerExists(title);
+	return (!ro || (ro && !command.hideReadOnly)) && !(shadow && command.hideShadow);
+};
+
+config.macros.toolbar.getCommandText = function(command,tiddler)
+{
+	return tiddler.isReadOnly() && command.readOnlyText || command.text;
+};
+
+config.macros.toolbar.getCommandTooltip = function(command,tiddler)
+{
+	return tiddler.isReadOnly() && command.readOnlyTooltip || command.tooltip;
+};
+
+config.macros.toolbar.onClickCommand = function(ev)
+{
+	var e = ev || window.event;
+	e.cancelBubble = true;
+	if(e.stopPropagation) e.stopPropagation();
+	var command = config.commands[this.getAttribute("commandName")];
+	return command.handler(e,this,this.getAttribute("tiddler"));
+};
+
+config.macros.toolbar.onClickPopup = function(ev)
+{
+	var e = ev || window.event;
+	e.cancelBubble = true;
+	if(e.stopPropagation) e.stopPropagation();
+	var popup = Popup.create(this);
+	var command = config.commands[this.getAttribute("commandName")];
+	var title = this.getAttribute("tiddler");
+	var tiddler = store.fetchTiddler(title);
+	popup.setAttribute("tiddler",title);
+	command.handlePopup(popup,title);
+	Popup.show();
+	return false;
+};
+
+// Invoke the first command encountered from a given place that is tagged with a specified class
+config.macros.toolbar.invokeCommand = function(place,className,event)
+{
+	var children = place.getElementsByTagName("a");
+	for(var t=0; t<children.length; t++) {
+		var c = children[t];
+		if(hasClass(c,className) && c.getAttribute && c.getAttribute("commandName")) {
+			if(c.onclick instanceof Function)
+				c.onclick.call(c,event);
+			break;
+		}
+	}
+};
+
+config.macros.toolbar.onClickMore = function(ev)
+{
+	var e = this.nextSibling;
+	e.style.display = "inline";
+	removeNode(this);
+	return false;
+};
+
+config.macros.toolbar.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	for(var t=0; t<params.length; t++) {
+		var c = params[t];
+		switch(c) {
+		case '>':
+			var btn = createTiddlyButton(place,this.moreLabel,this.morePrompt,config.macros.toolbar.onClickMore);
+			addClass(btn,"moreCommand");
+			var e = createTiddlyElement(place,"span",null,"moreCommand");
+			e.style.display = "none";
+			place = e;
+			break;
+		default:
+			var className = "";
+			switch(c.substr(0,1)) {
+			case "+":
+				className = "defaultCommand";
+				c = c.substr(1);
+				break;
+			case "-":
+				className = "cancelCommand";
+				c = c.substr(1);
+				break;
+			}
+			if(c in config.commands)
+				this.createCommand(place,c,tiddler,className);
+			break;
+		}
+	}
+};
+
+//--
+//-- Menu and toolbar commands
+//--
+
+config.commands.closeTiddler.handler = function(event,src,title)
+{
+	if(story.isDirty(title) && !readOnly) {
+		if(!confirm(config.commands.cancelTiddler.warning.format([title])))
+			return false;
+	}
+	story.setDirty(title,false);
+	story.closeTiddler(title,true);
+	return false;
+};
+
+config.commands.closeOthers.handler = function(event,src,title)
+{
+	story.closeAllTiddlers(title);
+	return false;
+};
+
+config.commands.editTiddler.handler = function(event,src,title)
+{
+	clearMessage();
+	var tiddlerElem = story.getTiddler(title);
+	var fields = tiddlerElem.getAttribute("tiddlyFields");
+	story.displayTiddler(null,title,DEFAULT_EDIT_TEMPLATE,false,null,fields);
+	story.focusTiddler(title,config.options.txtEditorFocus||"text");
+	return false;
+};
+
+config.commands.saveTiddler.handler = function(event,src,title)
+{
+	var newTitle = story.saveTiddler(title,event.shiftKey);
+	if(newTitle)
+		story.displayTiddler(null,newTitle);
+	return false;
+};
+
+config.commands.cancelTiddler.handler = function(event,src,title)
+{
+	if(story.hasChanges(title) && !readOnly) {
+		if(!confirm(this.warning.format([title])))
+			return false;
+	}
+	story.setDirty(title,false);
+	story.displayTiddler(null,title);
+	return false;
+};
+
+config.commands.deleteTiddler.handler = function(event,src,title)
+{
+	var deleteIt = true;
+	if(config.options.chkConfirmDelete)
+		deleteIt = confirm(this.warning.format([title]));
+	if(deleteIt) {
+		store.removeTiddler(title);
+		story.closeTiddler(title,true);
+		autoSaveChanges();
+	}
+	return false;
+};
+
+config.commands.permalink.handler = function(event,src,title)
+{
+	var t = encodeURIComponent(String.encodeTiddlyLink(title));
+	if(window.location.hash != t)
+		window.location.hash = t;
+	return false;
+};
+
+config.commands.references.handlePopup = function(popup,title)
+{
+	var references = store.getReferringTiddlers(title);
+	var c = false;
+	for(var r=0; r<references.length; r++) {
+		if(references[r].title != title && !references[r].isTagged("excludeLists")) {
+			createTiddlyLink(createTiddlyElement(popup,"li"),references[r].title,true);
+			c = true;
+		}
+	}
+	if(!c)
+		createTiddlyText(createTiddlyElement(popup,"li",null,"disabled"),this.popupNone);
+};
+
+config.commands.jump.handlePopup = function(popup,title)
+{
+	story.forEachTiddler(function(title,element) {
+		createTiddlyLink(createTiddlyElement(popup,"li"),title,true,null,false,null,true);
+		});
+};
+
+config.commands.syncing.handlePopup = function(popup,title)
+{
+	var tiddler = store.fetchTiddler(title);
+	if(!tiddler)
+		return;
+	var serverType = tiddler.getServerType();
+	var serverHost = tiddler.fields['server.host'];
+	var serverWorkspace = tiddler.fields['server.workspace'];
+	if(!serverWorkspace)
+		serverWorkspace = "";
+	if(serverType) {
+		var e = createTiddlyElement(popup,"li",null,"popupMessage");
+		e.innerHTML = config.commands.syncing.currentlySyncing.format([serverType,serverHost,serverWorkspace]);
+	} else {
+		createTiddlyElement(popup,"li",null,"popupMessage",config.commands.syncing.notCurrentlySyncing);
+	}
+	if(serverType) {
+		createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
+		var btn = createTiddlyButton(createTiddlyElement(popup,"li"),this.captionUnSync,null,config.commands.syncing.onChooseServer);
+		btn.setAttribute("tiddler",title);
+		btn.setAttribute("server.type","");
+	}
+	createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
+	createTiddlyElement(popup,"li",null,"popupMessage",config.commands.syncing.chooseServer);
+	var feeds = store.getTaggedTiddlers("systemServer","title");
+	for(var t=0; t<feeds.length; t++) {
+		var f = feeds[t];
+		var feedServerType = store.getTiddlerSlice(f.title,"Type");
+		if(!feedServerType)
+			feedServerType = "file";
+		var feedServerHost = store.getTiddlerSlice(f.title,"URL");
+		if(!feedServerHost)
+			feedServerHost = "";
+		var feedServerWorkspace = store.getTiddlerSlice(f.title,"Workspace");
+		if(!feedServerWorkspace)
+			feedServerWorkspace = "";
+		var caption = f.title;
+		if(serverType == feedServerType && serverHost == feedServerHost && serverWorkspace == feedServerWorkspace) {
+			caption = config.commands.syncing.currServerMarker + caption;
+		} else {
+			caption = config.commands.syncing.notCurrServerMarker + caption;
+		}
+		btn = createTiddlyButton(createTiddlyElement(popup,"li"),caption,null,config.commands.syncing.onChooseServer);
+		btn.setAttribute("tiddler",title);
+		btn.setAttribute("server.type",feedServerType);
+		btn.setAttribute("server.host",feedServerHost);
+		btn.setAttribute("server.workspace",feedServerWorkspace);
+	}
+};
+
+config.commands.syncing.onChooseServer = function(e)
+{
+	var tiddler = this.getAttribute("tiddler");
+	var serverType = this.getAttribute("server.type");
+	if(serverType) {
+		store.addTiddlerFields(tiddler,{
+			"server.type": serverType,
+			"server.host": this.getAttribute("server.host"),
+			"server.workspace": this.getAttribute("server.workspace")
+			});
+	} else {
+		store.setValue(tiddler,"server",null);
+	}
+	return false;
+};
+
+config.commands.fields.handlePopup = function(popup,title)
+{
+	var tiddler = store.fetchTiddler(title);
+	if(!tiddler)
+		return;
+	var items = [];
+	store.forEachField(tiddler,function(tiddler,fieldName,value){items.push({field:fieldName,value:value});},true);
+	items.sort(function(a,b) {return a.field < b.field ? -1 : (a.field == b.field ? 0 : +1);});
+	if(items.length > 0)
+		ListView.create(popup,items,this.listViewTemplate);
+	else
+		createTiddlyElement(popup,"div",null,null,this.emptyText);
+};
+
+//--
+//-- Tiddler() object
+//--
+
+function Tiddler(title)
+{
+	this.title = title;
+	this.text = "";
+	this.modifier = null;
+	this.created = new Date();
+	this.modified = this.created;
+	this.links = [];
+	this.linksUpdated = false;
+	this.tags = [];
+	this.fields = {};
+	return this;
+}
+
+Tiddler.prototype.getLinks = function()
+{
+	if(this.linksUpdated==false)
+		this.changed();
+	return this.links;
+};
+
+// Returns the fields that are inherited in string field:"value" field2:"value2" format
+Tiddler.prototype.getInheritedFields = function()
+{
+	var f = {};
+	for(var i in this.fields) {
+		if(i=="server.host" || i=="server.workspace" || i=="wikiformat"|| i=="server.type") {
+			f[i] = this.fields[i];
+		}
+	}
+	return String.encodeHashMap(f);
+};
+
+// Increment the changeCount of a tiddler
+Tiddler.prototype.incChangeCount = function()
+{
+	var c = this.fields['changecount'];
+	c = c ? parseInt(c,10) : 0;
+	this.fields['changecount'] = String(c+1);
+};
+
+// Clear the changeCount of a tiddler
+Tiddler.prototype.clearChangeCount = function()
+{
+	if(this.fields['changecount']) {
+		delete this.fields['changecount'];
+	}
+};
+
+Tiddler.prototype.doNotSave = function()
+{
+	return this.fields['doNotSave'];
+};
+
+// Returns true if the tiddler has been updated since the tiddler was created or downloaded
+Tiddler.prototype.isTouched = function()
+{
+	var changeCount = this.fields['changecount'];
+	if(changeCount === undefined)
+		changeCount = 0;
+	return changeCount > 0;
+};
+
+// Change the text and other attributes of a tiddler
+Tiddler.prototype.set = function(title,text,modifier,modified,tags,created,fields)
+{
+	this.assign(title,text,modifier,modified,tags,created,fields);
+	this.changed();
+	return this;
+};
+
+// Change the text and other attributes of a tiddler without triggered a tiddler.changed() call
+Tiddler.prototype.assign = function(title,text,modifier,modified,tags,created,fields)
+{
+	if(title != undefined)
+		this.title = title;
+	if(text != undefined)
+		this.text = text;
+	if(modifier != undefined)
+		this.modifier = modifier;
+	if(modified != undefined)
+		this.modified = modified;
+	if(created != undefined)
+		this.created = created;
+	if(fields != undefined)
+		this.fields = fields;
+	if(tags != undefined)
+		this.tags = (typeof tags == "string") ? tags.readBracketedList() : tags;
+	else if(this.tags == undefined)
+		this.tags = [];
+	return this;
+};
+
+// Get the tags for a tiddler as a string (space delimited, using [[brackets]] for tags containing spaces)
+Tiddler.prototype.getTags = function()
+{
+	return String.encodeTiddlyLinkList(this.tags);
+};
+
+// Test if a tiddler carries a tag
+Tiddler.prototype.isTagged = function(tag)
+{
+	return this.tags.indexOf(tag) != -1;
+};
+
+// Static method to convert "\n" to newlines, "\s" to "\"
+Tiddler.unescapeLineBreaks = function(text)
+{
+	return text ? text.unescapeLineBreaks() : "";
+};
+
+// Convert newlines to "\n", "\" to "\s"
+Tiddler.prototype.escapeLineBreaks = function()
+{
+	return this.text.escapeLineBreaks();
+};
+
+// Updates the secondary information (like links[] array) after a change to a tiddler
+Tiddler.prototype.changed = function()
+{
+	this.links = [];
+	var text = this.text;
+	// remove 'quoted' text before scanning tiddler source
+	text = text.replace(/\/%((?:.|\n)*?)%\//g,"").
+		replace(/\{{3}((?:.|\n)*?)\}{3}/g,"").
+		replace(/"""((?:.|\n)*?)"""/g,"").
+		replace(/\<nowiki\>((?:.|\n)*?)\<\/nowiki\>/g,"").
+		replace(/\<html\>((?:.|\n)*?)\<\/html\>/g,"").
+		replace(/\<script((?:.|\n)*?)\<\/script\>/g,"");
+	var t = this.autoLinkWikiWords() ? 0 : 1;
+	var tiddlerLinkRegExp = t==0 ? config.textPrimitives.tiddlerAnyLinkRegExp : config.textPrimitives.tiddlerForcedLinkRegExp;
+	tiddlerLinkRegExp.lastIndex = 0;
+	var formatMatch = tiddlerLinkRegExp.exec(text);
+	while(formatMatch) {
+		var lastIndex = tiddlerLinkRegExp.lastIndex;
+		if(t==0 && formatMatch[1] && formatMatch[1] != this.title) {
+			// wikiWordLink
+			if(formatMatch.index > 0) {
+				var preRegExp = new RegExp(config.textPrimitives.unWikiLink+"|"+config.textPrimitives.anyLetter,"mg");
+				preRegExp.lastIndex = formatMatch.index-1;
+				var preMatch = preRegExp.exec(text);
+				if(preMatch.index != formatMatch.index-1)
+					this.links.pushUnique(formatMatch[1]);
+			} else {
+				this.links.pushUnique(formatMatch[1]);
+			}
+		}
+		else if(formatMatch[2-t] && !config.formatterHelpers.isExternalLink(formatMatch[3-t])) // titledBrackettedLink
+			this.links.pushUnique(formatMatch[3-t]);
+		else if(formatMatch[4-t] && formatMatch[4-t] != this.title) // brackettedLink
+			this.links.pushUnique(formatMatch[4-t]);
+		tiddlerLinkRegExp.lastIndex = lastIndex;
+		formatMatch = tiddlerLinkRegExp.exec(text);
+	}
+	this.linksUpdated = true;
+};
+
+Tiddler.prototype.getSubtitle = function()
+{
+	var modifier = this.modifier;
+	if(!modifier)
+		modifier = config.messages.subtitleUnknown;
+	var modified = this.modified;
+	if(modified)
+		modified = modified.toLocaleString();
+	else
+		modified = config.messages.subtitleUnknown;
+	return config.messages.tiddlerLinkTooltip.format([this.title,modifier,modified]);
+};
+
+Tiddler.prototype.isReadOnly = function()
+{
+	return readOnly;
+};
+
+Tiddler.prototype.autoLinkWikiWords = function()
+{
+	return !(this.isTagged("systemConfig") || this.isTagged("excludeMissing"));
+};
+
+Tiddler.prototype.generateFingerprint = function()
+{
+	return "0x" + Crypto.hexSha1Str(this.text);
+};
+
+Tiddler.prototype.getServerType = function()
+{
+	var serverType = null;
+	if(this.fields['server.type'])
+		serverType = this.fields['server.type'];
+	if(!serverType)
+		serverType = this.fields['wikiformat'];
+	if(serverType && !config.adaptors[serverType])
+		serverType = null;
+	return serverType;
+};
+
+Tiddler.prototype.getAdaptor = function()
+{
+	var serverType = this.getServerType();
+	return serverType ? new config.adaptors[serverType]() : null;
+};
+
+//--
+//-- TiddlyWiki() object contains Tiddler()s
+//--
+
+function TiddlyWiki()
+{
+	var tiddlers = {}; // Hashmap by name of tiddlers
+	this.tiddlersUpdated = false;
+	this.namedNotifications = []; // Array of {name:,notify:} of notification functions
+	this.notificationLevel = 0;
+	this.slices = {}; // map tiddlerName->(map sliceName->sliceValue). Lazy.
+	this.clear = function() {
+		tiddlers = {};
+		this.setDirty(false);
+	};
+	this.fetchTiddler = function(title) {
+		var t = tiddlers[title];
+		return t instanceof Tiddler ? t : null;
+	};
+	this.deleteTiddler = function(title) {
+		delete this.slices[title];
+		delete tiddlers[title];
+	};
+	this.addTiddler = function(tiddler) {
+		delete this.slices[tiddler.title];
+		tiddlers[tiddler.title] = tiddler;
+	};
+	this.forEachTiddler = function(callback) {
+		for(var t in tiddlers) {
+			var tiddler = tiddlers[t];
+			if(tiddler instanceof Tiddler)
+				callback.call(this,t,tiddler);
+		}
+	};
+}
+
+TiddlyWiki.prototype.setDirty = function(dirty)
+{
+	this.dirty = dirty;
+};
+
+TiddlyWiki.prototype.isDirty = function()
+{
+	return this.dirty;
+};
+
+TiddlyWiki.prototype.tiddlerExists = function(title)
+{
+	var t = this.fetchTiddler(title);
+	return t != undefined;
+};
+
+TiddlyWiki.prototype.isShadowTiddler = function(title)
+{
+	return config.shadowTiddlers[title] === undefined ? false : true;
+};
+
+TiddlyWiki.prototype.createTiddler = function(title)
+{
+	var tiddler = this.fetchTiddler(title);
+	if(!tiddler) {
+		tiddler = new Tiddler(title);
+		this.addTiddler(tiddler);
+		this.setDirty(true);
+	}
+	return tiddler;
+};
+
+TiddlyWiki.prototype.getTiddler = function(title)
+{
+	var t = this.fetchTiddler(title);
+	if(t != undefined)
+		return t;
+	else
+		return null;
+};
+
+TiddlyWiki.prototype.getShadowTiddlerText = function(title)
+{
+	if(typeof config.shadowTiddlers[title] == "string")
+		return config.shadowTiddlers[title];
+	else
+		return "";
+};
+
+TiddlyWiki.prototype.getTiddlerText = function(title,defaultText)
+{
+	if(!title)
+		return defaultText;
+	var pos = title.indexOf(config.textPrimitives.sectionSeparator);
+	var section = null;
+	if(pos != -1) {
+		section = title.substr(pos + config.textPrimitives.sectionSeparator.length);
+		title = title.substr(0,pos);
+	}
+	pos = title.indexOf(config.textPrimitives.sliceSeparator);
+	if(pos != -1) {
+		var slice = this.getTiddlerSlice(title.substr(0,pos),title.substr(pos + config.textPrimitives.sliceSeparator.length));
+		if(slice)
+			return slice;
+	}
+	var tiddler = this.fetchTiddler(title);
+	if(tiddler) {
+		if(!section)
+			return tiddler.text;
+		var re = new RegExp("(^!{1,6}" + section.escapeRegExp() + "[ \t]*\n)","mg");
+		re.lastIndex = 0;
+		var match = re.exec(tiddler.text);
+		if(match) {
+			var t = tiddler.text.substr(match.index+match[1].length);
+			var re2 = /^!/mg;
+			re2.lastIndex = 0;
+			match = re2.exec(t); //# search for the next heading
+			if(match)
+				t = t.substr(0,match.index-1);//# don't include final \n
+			return t;
+		}
+		return defaultText;
+	}
+	if(this.isShadowTiddler(title))
+		return this.getShadowTiddlerText(title);
+	if(defaultText != undefined)
+		return defaultText;
+	return null;
+};
+
+TiddlyWiki.prototype.getRecursiveTiddlerText = function(title,defaultText,depth)
+{
+	var bracketRegExp = new RegExp("(?:\\[\\[([^\\]]+)\\]\\])","mg");
+	var text = this.getTiddlerText(title,null);
+	if(text == null)
+		return defaultText;
+	var textOut = [];
+	var lastPos = 0;
+	do {
+		var match = bracketRegExp.exec(text);
+		if(match) {
+			textOut.push(text.substr(lastPos,match.index-lastPos));
+			if(match[1]) {
+				if(depth <= 0)
+					textOut.push(match[1]);
+				else
+					textOut.push(this.getRecursiveTiddlerText(match[1],"[[" + match[1] + "]]",depth-1));
+			}
+			lastPos = match.index + match[0].length;
+		} else {
+			textOut.push(text.substr(lastPos));
+		}
+	} while(match);
+	return textOut.join("");
+};
+
+TiddlyWiki.prototype.slicesRE = /(?:^([\'\/]{0,2})~?([\.\w]+)\:\1[\t\x20]*([^\n]+)[\t\x20]*$)|(?:^\|([\'\/]{0,2})~?([\.\w]+)\:?\4\|[\t\x20]*([^\n]+)[\t\x20]*\|$)/gm;
+
+// @internal
+TiddlyWiki.prototype.calcAllSlices = function(title)
+{
+	var slices = {};
+	var text = this.getTiddlerText(title,"");
+	this.slicesRE.lastIndex = 0;
+	var m = this.slicesRE.exec(text);
+	while(m) {
+		if(m[2])
+			slices[m[2]] = m[3];
+		else
+			slices[m[5]] = m[6];
+		m = this.slicesRE.exec(text);
+	}
+	return slices;
+};
+
+// Returns the slice of text of the given name
+TiddlyWiki.prototype.getTiddlerSlice = function(title,sliceName)
+{
+	var slices = this.slices[title];
+	if(!slices) {
+		slices = this.calcAllSlices(title);
+		this.slices[title] = slices;
+	}
+	return slices[sliceName];
+};
+
+// Build an hashmap of the specified named slices of a tiddler
+TiddlyWiki.prototype.getTiddlerSlices = function(title,sliceNames)
+{
+	var r = {};
+	for(var t=0; t<sliceNames.length; t++) {
+		var slice = this.getTiddlerSlice(title,sliceNames[t]);
+		if(slice)
+			r[sliceNames[t]] = slice;
+	}
+	return r;
+};
+
+TiddlyWiki.prototype.suspendNotifications = function()
+{
+	this.notificationLevel--;
+};
+
+TiddlyWiki.prototype.resumeNotifications = function()
+{
+	this.notificationLevel++;
+};
+
+// Invoke the notification handlers for a particular tiddler
+TiddlyWiki.prototype.notify = function(title,doBlanket)
+{
+	if(!this.notificationLevel) {
+		for(var t=0; t<this.namedNotifications.length; t++) {
+			var n = this.namedNotifications[t];
+			if((n.name == null && doBlanket) || (n.name == title))
+				n.notify(title);
+		}
+	}
+};
+
+// Invoke the notification handlers for all tiddlers
+TiddlyWiki.prototype.notifyAll = function()
+{
+	if(!this.notificationLevel) {
+		for(var t=0; t<this.namedNotifications.length; t++) {
+			var n = this.namedNotifications[t];
+			if(n.name)
+				n.notify(n.name);
+		}
+	}
+};
+
+// Add a notification handler to a tiddler
+TiddlyWiki.prototype.addNotification = function(title,fn)
+{
+	for(var i=0; i<this.namedNotifications.length; i++) {
+		if((this.namedNotifications[i].name == title) && (this.namedNotifications[i].notify == fn))
+			return this;
+	}
+	this.namedNotifications.push({name: title, notify: fn});
+	return this;
+};
+
+TiddlyWiki.prototype.removeTiddler = function(title)
+{
+	var tiddler = this.fetchTiddler(title);
+	if(tiddler) {
+		this.deleteTiddler(title);
+		this.notify(title,true);
+		this.setDirty(true);
+	}
+};
+
+// Reset the sync status of a freshly synced tiddler
+TiddlyWiki.prototype.resetTiddler = function(title)
+{
+	var tiddler = this.fetchTiddler(title);
+	if(tiddler) {
+		tiddler.clearChangeCount();
+		this.notify(title,true);
+		this.setDirty(true);
+	}
+};
+
+TiddlyWiki.prototype.setTiddlerTag = function(title,status,tag)
+{
+	var tiddler = this.fetchTiddler(title);
+	if(tiddler) {
+		var t = tiddler.tags.indexOf(tag);
+		if(t != -1)
+			tiddler.tags.splice(t,1);
+		if(status)
+			tiddler.tags.push(tag);
+		tiddler.changed();
+		tiddler.incChangeCount();
+		this.notify(title,true);
+		this.setDirty(true);
+	}
+};
+
+TiddlyWiki.prototype.addTiddlerFields = function(title,fields)
+{
+	var tiddler = this.fetchTiddler(title);
+	if(!tiddler)
+		return;
+	merge(tiddler.fields,fields);
+	tiddler.changed();
+	tiddler.incChangeCount();
+	this.notify(title,true);
+	this.setDirty(true);
+};
+
+TiddlyWiki.prototype.saveTiddler = function(title,newTitle,newBody,modifier,modified,tags,fields,clearChangeCount,created)
+{
+	var tiddler = this.fetchTiddler(title);
+	if(tiddler) {
+		created = created || tiddler.created; // Preserve created date
+		this.deleteTiddler(title);
+	} else {
+		created = created || modified;
+		tiddler = new Tiddler();
+	}
+	tiddler.set(newTitle,newBody,modifier,modified,tags,created,fields);
+	this.addTiddler(tiddler);
+	if(clearChangeCount)
+		tiddler.clearChangeCount();
+	else
+		tiddler.incChangeCount();
+	if(title != newTitle)
+		this.notify(title,true);
+	this.notify(newTitle,true);
+	this.setDirty(true);
+	return tiddler;
+};
+
+TiddlyWiki.prototype.incChangeCount = function(title)
+{
+	var tiddler = this.fetchTiddler(title);
+	if(tiddler)
+		tiddler.incChangeCount();
+};
+
+TiddlyWiki.prototype.getLoader = function()
+{
+	if(!this.loader)
+		this.loader = new TW21Loader();
+	return this.loader;
+};
+
+TiddlyWiki.prototype.getSaver = function()
+{
+	if(!this.saver)
+		this.saver = new TW21Saver();
+	return this.saver;
+};
+
+// Return all tiddlers formatted as an HTML string
+TiddlyWiki.prototype.allTiddlersAsHtml = function()
+{
+	return this.getSaver().externalize(store);
+};
+
+// Load contents of a TiddlyWiki from an HTML DIV
+TiddlyWiki.prototype.loadFromDiv = function(src,idPrefix,noUpdate)
+{
+	this.idPrefix = idPrefix;
+	var storeElem = (typeof src == "string") ? document.getElementById(src) : src;
+	if(!storeElem)
+		return;
+	var tiddlers = this.getLoader().loadTiddlers(this,storeElem.childNodes);
+	this.setDirty(false);
+	if(!noUpdate) {
+		for(var i = 0;i<tiddlers.length; i++)
+			tiddlers[i].changed();
+	}
+};
+
+// Load contents of a TiddlyWiki from a string
+// Returns null if there's an error
+TiddlyWiki.prototype.importTiddlyWiki = function(text)
+{
+	var posDiv = locateStoreArea(text);
+	if(!posDiv)
+		return null;
+	var content = "<" + "html><" + "body>" + text.substring(posDiv[0],posDiv[1] + endSaveArea.length) + "<" + "/body><" + "/html>";
+	// Create the iframe
+	var iframe = document.createElement("iframe");
+	iframe.style.display = "none";
+	document.body.appendChild(iframe);
+	var doc = iframe.document;
+	if(iframe.contentDocument)
+		doc = iframe.contentDocument; // For NS6
+	else if(iframe.contentWindow)
+		doc = iframe.contentWindow.document; // For IE5.5 and IE6
+	// Put the content in the iframe
+	doc.open();
+	doc.writeln(content);
+	doc.close();
+	// Load the content into a TiddlyWiki() object
+	var storeArea = doc.getElementById("storeArea");
+	this.loadFromDiv(storeArea,"store");
+	// Get rid of the iframe
+	iframe.parentNode.removeChild(iframe);
+	return this;
+};
+
+TiddlyWiki.prototype.updateTiddlers = function()
+{
+	this.tiddlersUpdated = true;
+	this.forEachTiddler(function(title,tiddler) {
+		tiddler.changed();
+	});
+};
+
+// Return an array of tiddlers matching a search regular expression
+TiddlyWiki.prototype.search = function(searchRegExp,sortField,excludeTag,match)
+{
+	var candidates = this.reverseLookup("tags",excludeTag,!!match);
+	var results = [];
+	for(var t=0; t<candidates.length; t++) {
+		if((candidates[t].title.search(searchRegExp) != -1) || (candidates[t].text.search(searchRegExp) != -1))
+			results.push(candidates[t]);
+	}
+	if(!sortField)
+		sortField = "title";
+	results.sort(function(a,b) {return a[sortField] < b[sortField] ? -1 : (a[sortField] == b[sortField] ? 0 : +1);});
+	return results;
+};
+
+// Returns a list of all tags in use
+//   excludeTag - if present, excludes tags that are themselves tagged with excludeTag
+// Returns an array of arrays where [tag][0] is the name of the tag and [tag][1] is the number of occurances
+TiddlyWiki.prototype.getTags = function(excludeTag)
+{
+	var results = [];
+	this.forEachTiddler(function(title,tiddler) {
+		for(var g=0; g<tiddler.tags.length; g++) {
+			var tag = tiddler.tags[g];
+			var n = true;
+			for(var c=0; c<results.length; c++) {
+				if(results[c][0] == tag) {
+					n = false;
+					results[c][1]++;
+				}
+			}
+			if(n && excludeTag) {
+				var t = this.fetchTiddler(tag);
+				if(t && t.isTagged(excludeTag))
+					n = false;
+			}
+			if(n)
+				results.push([tag,1]);
+		}
+	});
+	results.sort(function(a,b) {return a[0].toLowerCase() < b[0].toLowerCase() ? -1 : (a[0].toLowerCase() == b[0].toLowerCase() ? 0 : +1);});
+	return results;
+};
+
+// Return an array of the tiddlers that are tagged with a given tag
+TiddlyWiki.prototype.getTaggedTiddlers = function(tag,sortField)
+{
+	return this.reverseLookup("tags",tag,true,sortField);
+};
+
+// Return an array of the tiddlers that link to a given tiddler
+TiddlyWiki.prototype.getReferringTiddlers = function(title,unusedParameter,sortField)
+{
+	if(!this.tiddlersUpdated)
+		this.updateTiddlers();
+	return this.reverseLookup("links",title,true,sortField);
+};
+
+// Return an array of the tiddlers that do or do not have a specified entry in the specified storage array (ie, "links" or "tags")
+// lookupMatch == true to match tiddlers, false to exclude tiddlers
+TiddlyWiki.prototype.reverseLookup = function(lookupField,lookupValue,lookupMatch,sortField)
+{
+	var results = [];
+	this.forEachTiddler(function(title,tiddler) {
+		var f = !lookupMatch;
+		for(var lookup=0; lookup<tiddler[lookupField].length; lookup++) {
+			if(tiddler[lookupField][lookup] == lookupValue)
+				f = lookupMatch;
+		}
+		if(f)
+			results.push(tiddler);
+	});
+	if(!sortField)
+		sortField = "title";
+	results.sort(function(a,b) {return a[sortField] < b[sortField] ? -1 : (a[sortField] == b[sortField] ? 0 : +1);});
+	return results;
+};
+
+// Return the tiddlers as a sorted array
+TiddlyWiki.prototype.getTiddlers = function(field,excludeTag)
+{
+	var results = [];
+	this.forEachTiddler(function(title,tiddler) {
+		if(excludeTag == undefined || !tiddler.isTagged(excludeTag))
+			results.push(tiddler);
+	});
+	if(field)
+		results.sort(function(a,b) {return a[field] < b[field] ? -1 : (a[field] == b[field] ? 0 : +1);});
+	return results;
+};
+
+// Return array of names of tiddlers that are referred to but not defined
+TiddlyWiki.prototype.getMissingLinks = function(sortField)
+{
+	if(!this.tiddlersUpdated)
+		this.updateTiddlers();
+	var results = [];
+	this.forEachTiddler(function (title,tiddler) {
+		if(tiddler.isTagged("excludeMissing") || tiddler.isTagged("systemConfig"))
+			return;
+		for(var n=0; n<tiddler.links.length;n++) {
+			var link = tiddler.links[n];
+			if(this.fetchTiddler(link) == null && !this.isShadowTiddler(link))
+				results.pushUnique(link);
+		}
+	});
+	results.sort();
+	return results;
+};
+
+// Return an array of names of tiddlers that are defined but not referred to
+TiddlyWiki.prototype.getOrphans = function()
+{
+	var results = [];
+	this.forEachTiddler(function (title,tiddler) {
+		if(this.getReferringTiddlers(title).length == 0 && !tiddler.isTagged("excludeLists"))
+			results.push(title);
+	});
+	results.sort();
+	return results;
+};
+
+// Return an array of names of all the shadow tiddlers
+TiddlyWiki.prototype.getShadowed = function()
+{
+	var results = [];
+	for(var t in config.shadowTiddlers) {
+		if(this.isShadowTiddler(t))
+			results.push(t);
+	}
+	results.sort();
+	return results;
+};
+
+// Return an array of tiddlers that have been touched since they were downloaded or created
+TiddlyWiki.prototype.getTouched = function()
+{
+	var results = [];
+	this.forEachTiddler(function(title,tiddler) {
+		if(tiddler.isTouched())
+			results.push(tiddler);
+		});
+	results.sort();
+	return results;
+};
+
+// Resolves a Tiddler reference or tiddler title into a Tiddler object, or null if it doesn't exist
+TiddlyWiki.prototype.resolveTiddler = function(tiddler)
+{
+	var t = (typeof tiddler == 'string') ? this.getTiddler(tiddler) : tiddler;
+	return t instanceof Tiddler ? t : null;
+};
+
+// Filter a list of tiddlers
+TiddlyWiki.prototype.filterTiddlers = function(filter)
+{
+	var results = [];
+	if(filter) {
+		var tiddler;
+		var re = /([^\s\[\]]+)|(?:\[([ \w]+)\[([^\]]+)\]\])|(?:\[\[([^\]]+)\]\])/mg;
+		var match = re.exec(filter);
+		while(match) {
+			if(match[1] || match[4]) {
+				var title = match[1] || match[4];
+				tiddler = this.fetchTiddler(title);
+				if(tiddler) {
+					results.pushUnique(tiddler);
+				} else if(this.isShadowTiddler(title)) {
+					tiddler = new Tiddler();
+					tiddler.set(title,this.getTiddlerText(title));
+					results.pushUnique(tiddler);
+				} else {
+					results.pushUnique(new Tiddler(title));
+				}
+			} else if(match[2]) {
+				switch(match[2]) {
+					case "tag":
+						var matched = this.getTaggedTiddlers(match[3]);
+						for(var m = 0; m < matched.length; m++)
+							results.pushUnique(matched[m]);
+						break;
+					case "sort":
+						results = this.sortTiddlers(results,match[3]);
+						break;
+				}
+			}
+			match = re.exec(filter);
+		}
+	}
+	return results;
+};
+
+// Sort a list of tiddlers
+TiddlyWiki.prototype.sortTiddlers = function(tiddlers,field)
+{
+	var asc = +1;
+	switch(field.substr(0,1)) {
+	case "-":
+		asc = -1;
+		// Note: this fall-through is intentional
+		/*jsl:fallthru*/
+	case "+":
+		field = field.substr(1);
+		break;
+	}
+	if(TiddlyWiki.standardFieldAccess[field])
+		tiddlers.sort(function(a,b) {return a[field] < b[field] ? -asc : (a[field] == b[field] ? 0 : asc);});
+	else
+		tiddlers.sort(function(a,b) {return a.fields[field] < b.fields[field] ? -asc : (a.fields[field] == b.fields[field] ? 0 : +asc);});
+	return tiddlers;
+};
+
+// Returns true if path is a valid field name (path),
+// i.e. a sequence of identifiers, separated by '.'
+TiddlyWiki.isValidFieldName = function(name)
+{
+	var match = /[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*/.exec(name);
+	return match && (match[0] == name);
+};
+
+// Throws an exception when name is not a valid field name.
+TiddlyWiki.checkFieldName = function(name)
+{
+	if(!TiddlyWiki.isValidFieldName(name))
+		throw config.messages.invalidFieldName.format([name]);
+};
+
+function StringFieldAccess(n,readOnly)
+{
+	this.set = readOnly ?
+			function(t,v) {if(v != t[n]) throw config.messages.fieldCannotBeChanged.format([n]);} :
+			function(t,v) {if(v != t[n]) {t[n] = v; return true;}};
+	this.get = function(t) {return t[n];};
+}
+
+function DateFieldAccess(n)
+{
+	this.set = function(t,v) {
+		var d = v instanceof Date ? v : Date.convertFromYYYYMMDDHHMM(v);
+		if(d != t[n]) {
+			t[n] = d; return true;
+		}
+	};
+	this.get = function(t) {return t[n].convertToYYYYMMDDHHMM();};
+}
+
+function LinksFieldAccess(n)
+{
+	this.set = function(t,v) {
+		var s = (typeof v == "string") ? v.readBracketedList() : v;
+		if(s.toString() != t[n].toString()) {
+			t[n] = s; return true;
+		}
+	};
+	this.get = function(t) {return String.encodeTiddlyLinkList(t[n]);};
+}
+
+TiddlyWiki.standardFieldAccess = {
+	// The set functions return true when setting the data has changed the value.
+	"title":    new StringFieldAccess("title",true),
+	// Handle the "tiddler" field name as the title
+	"tiddler":  new StringFieldAccess("title",true),
+	"text":     new StringFieldAccess("text"),
+	"modifier": new StringFieldAccess("modifier"),
+	"modified": new DateFieldAccess("modified"),
+	"created":  new DateFieldAccess("created"),
+	"tags":     new LinksFieldAccess("tags")
+};
+
+TiddlyWiki.isStandardField = function(name)
+{
+	return TiddlyWiki.standardFieldAccess[name] != undefined;
+};
+
+// Sets the value of the given field of the tiddler to the value.
+// Setting an ExtendedField's value to null or undefined removes the field.
+// Setting a namespace to undefined removes all fields of that namespace.
+// The fieldName is case-insensitive.
+// All values will be converted to a string value.
+TiddlyWiki.prototype.setValue = function(tiddler,fieldName,value)
+{
+	TiddlyWiki.checkFieldName(fieldName);
+	var t = this.resolveTiddler(tiddler);
+	if(!t)
+		return;
+	fieldName = fieldName.toLowerCase();
+	var isRemove = (value === undefined) || (value === null);
+	var accessor = TiddlyWiki.standardFieldAccess[fieldName];
+	if(accessor) {
+		if(isRemove)
+			// don't remove StandardFields
+			return;
+		var h = TiddlyWiki.standardFieldAccess[fieldName];
+		if(!h.set(t,value))
+			return;
+	} else {
+		var oldValue = t.fields[fieldName];
+		if(isRemove) {
+			if(oldValue !== undefined) {
+				// deletes a single field
+				delete t.fields[fieldName];
+			} else {
+				// no concrete value is defined for the fieldName
+				// so we guess this is a namespace path.
+				// delete all fields in a namespace
+				var re = new RegExp('^'+fieldName+'\\.');
+				var dirty = false;
+				for(var n in t.fields) {
+					if(n.match(re)) {
+						delete t.fields[n];
+						dirty = true;
+					}
+				}
+				if(!dirty)
+					return;
+			}
+		} else {
+			// the "normal" set case. value is defined (not null/undefined)
+			// For convenience provide a nicer conversion Date->String
+			value = value instanceof Date ? value.convertToYYYYMMDDHHMMSSMMM() : String(value);
+			if(oldValue == value)
+				return;
+			t.fields[fieldName] = value;
+		}
+	}
+	// When we are here the tiddler/store really was changed.
+	this.notify(t.title,true);
+	if(!fieldName.match(/^temp\./))
+		this.setDirty(true);
+};
+
+// Returns the value of the given field of the tiddler.
+// The fieldName is case-insensitive.
+// Will only return String values (or undefined).
+TiddlyWiki.prototype.getValue = function(tiddler,fieldName)
+{
+	var t = this.resolveTiddler(tiddler);
+	if(!t)
+		return undefined;
+	fieldName = fieldName.toLowerCase();
+	var accessor = TiddlyWiki.standardFieldAccess[fieldName];
+	if(accessor) {
+		return accessor.get(t);
+	}
+	return t.fields[fieldName];
+};
+
+// Calls the callback function for every field in the tiddler.
+// When callback function returns a non-false value the iteration stops
+// and that value is returned.
+// The order of the fields is not defined.
+// @param callback a function(tiddler,fieldName,value).
+TiddlyWiki.prototype.forEachField = function(tiddler,callback,onlyExtendedFields)
+{
+	var t = this.resolveTiddler(tiddler);
+	if(!t)
+		return undefined;
+	var n,result;
+	for(n in t.fields) {
+		result = callback(t,n,t.fields[n]);
+		if(result)
+			return result;
+		}
+	if(onlyExtendedFields)
+		return undefined;
+	for(n in TiddlyWiki.standardFieldAccess) {
+		if(n == "tiddler")
+			// even though the "title" field can also be referenced through the name "tiddler"
+			// we only visit this field once.
+			continue;
+		result = callback(t,n,TiddlyWiki.standardFieldAccess[n].get(t));
+		if(result)
+			return result;
+	}
+	return undefined;
+};
+
+//--
+//-- Story functions
+//--
+
+function Story(containerId,idPrefix)
+{
+	this.container = containerId;
+	this.idPrefix = idPrefix;
+	this.highlightRegExp = null;
+	this.tiddlerId = function(title) {
+		var id = this.idPrefix + title;
+		return id==this.container ? this.idPrefix + "_" + title : id;
+	};
+	this.containerId = function() {
+		return this.container;
+	};
+}
+
+Story.prototype.getTiddler = function(title)
+{
+	return document.getElementById(this.tiddlerId(title));
+};
+
+Story.prototype.getContainer = function()
+{
+	return document.getElementById(this.containerId());
+};
+
+Story.prototype.forEachTiddler = function(fn)
+{
+	var place = this.getContainer();
+	if(!place)
+		return;
+	var e = place.firstChild;
+	while(e) {
+		var n = e.nextSibling;
+		var title = e.getAttribute("tiddler");
+		fn.call(this,title,e);
+		e = n;
+	}
+};
+
+Story.prototype.displayDefaultTiddlers = function()
+{
+	this.displayTiddlers(null,store.filterTiddlers(store.getTiddlerText("DefaultTiddlers")));
+};
+
+Story.prototype.displayTiddlers = function(srcElement,titles,template,animate,unused,customFields,toggle)
+{
+	for(var t = titles.length-1;t>=0;t--)
+		this.displayTiddler(srcElement,titles[t],template,animate,unused,customFields);
+};
+
+Story.prototype.displayTiddler = function(srcElement,tiddler,template,animate,unused,customFields,toggle,animationSrc)
+{
+	var title = (tiddler instanceof Tiddler) ? tiddler.title : tiddler;
+	var tiddlerElem = this.getTiddler(title);
+	if(tiddlerElem) {
+		if(toggle)
+			this.closeTiddler(title,true);
+		else
+			this.refreshTiddler(title,template,false,customFields);
+	} else {
+		var place = this.getContainer();
+		var before = this.positionTiddler(srcElement);
+		tiddlerElem = this.createTiddler(place,before,title,template,customFields);
+	}
+	if(animationSrc && typeof animationSrc !== "string") {
+		srcElement = animationSrc;
+	}
+	if(srcElement && typeof srcElement !== "string") {
+		if(config.options.chkAnimate && (animate == undefined || animate == true) && anim && typeof Zoomer == "function" && typeof Scroller == "function")
+			anim.startAnimating(new Zoomer(title,srcElement,tiddlerElem),new Scroller(tiddlerElem));
+		else
+			window.scrollTo(0,ensureVisible(tiddlerElem));
+	}
+};
+
+Story.prototype.positionTiddler = function(srcElement)
+{
+	var place = this.getContainer();
+	var before = null;
+	if(typeof srcElement == "string") {
+		switch(srcElement) {
+		case "top":
+			before = place.firstChild;
+			break;
+		case "bottom":
+			before = null;
+			break;
+		}
+	} else {
+		var after = this.findContainingTiddler(srcElement);
+		if(after == null) {
+			before = place.firstChild;
+		} else if(after.nextSibling) {
+			before = after.nextSibling;
+			if(before.nodeType != 1)
+				before = null;
+		}
+	}
+	return before;
+};
+
+Story.prototype.createTiddler = function(place,before,title,template,customFields)
+{
+	var tiddlerElem = createTiddlyElement(null,"div",this.tiddlerId(title),"tiddler");
+	tiddlerElem.setAttribute("refresh","tiddler");
+	if(customFields)
+		tiddlerElem.setAttribute("tiddlyFields",customFields);
+	place.insertBefore(tiddlerElem,before);
+	var defaultText = null;
+	if(!store.tiddlerExists(title) && !store.isShadowTiddler(title))
+		defaultText = this.loadMissingTiddler(title,customFields,tiddlerElem);
+	this.refreshTiddler(title,template,false,customFields,defaultText);
+	return tiddlerElem;
+};
+
+Story.prototype.loadMissingTiddler = function(title,fields,tiddlerElem)
+{
+	var tiddler = new Tiddler(title);
+	tiddler.fields = typeof fields == "string" ? fields.decodeHashMap() : (fields || {});
+	var serverType = tiddler.getServerType();
+	var host = tiddler.fields['server.host'];
+	var workspace = tiddler.fields['server.workspace'];
+	if(!serverType || !host)
+		return null;
+	var sm = new SyncMachine(serverType,{
+			start: function() {
+				return this.openHost(host,"openWorkspace");
+			},
+			openWorkspace: function() {
+				return this.openWorkspace(workspace,"getTiddler");
+			},
+			getTiddler: function() {
+				return this.getTiddler(title,"onGetTiddler");
+			},
+			onGetTiddler: function(context) {
+				var tiddler = context.tiddler;
+				if(tiddler && tiddler.text) {
+					var downloaded = new Date();
+					if(!tiddler.created)
+						tiddler.created = downloaded;
+					if(!tiddler.modified)
+						tiddler.modified = tiddler.created;
+					store.saveTiddler(tiddler.title,tiddler.title,tiddler.text,tiddler.modifier,tiddler.modified,tiddler.tags,tiddler.fields,true,tiddler.created);
+					autoSaveChanges();
+				}
+				delete this;
+				return true;
+			},
+			error: function(message) {
+				displayMessage("Error loading missing tiddler from %0: %1".format([host,message]));
+			}
+		});
+	sm.go();
+	return config.messages.loadingMissingTiddler.format([title,serverType,host,workspace]);
+};
+
+Story.prototype.chooseTemplateForTiddler = function(title,template)
+{
+	if(!template)
+		template = DEFAULT_VIEW_TEMPLATE;
+	if(template == DEFAULT_VIEW_TEMPLATE || template == DEFAULT_EDIT_TEMPLATE)
+		template = config.tiddlerTemplates[template];
+	return template;
+};
+
+Story.prototype.getTemplateForTiddler = function(title,template,tiddler)
+{
+	return store.getRecursiveTiddlerText(template,null,10);
+};
+
+Story.prototype.refreshTiddler = function(title,template,force,customFields,defaultText)
+{
+	var tiddlerElem = this.getTiddler(title);
+	if(tiddlerElem) {
+		if(tiddlerElem.getAttribute("dirty") == "true" && !force)
+			return tiddlerElem;
+		template = this.chooseTemplateForTiddler(title,template);
+		var currTemplate = tiddlerElem.getAttribute("template");
+		if((template != currTemplate) || force) {
+			var tiddler = store.getTiddler(title);
+			if(!tiddler) {
+				tiddler = new Tiddler();
+				if(store.isShadowTiddler(title)) {
+					var tags = [];
+					tiddler.set(title,store.getTiddlerText(title),config.views.wikified.shadowModifier,version.date,tags,version.date);
+				} else {
+					var text = template=="EditTemplate" ?
+								config.views.editor.defaultText.format([title]) :
+								config.views.wikified.defaultText.format([title]);
+					text = defaultText || text;
+					var fields = customFields ? customFields.decodeHashMap() : null;
+					tiddler.set(title,text,config.views.wikified.defaultModifier,version.date,[],version.date,fields);
+				}
+			}
+			tiddlerElem.setAttribute("tags",tiddler.tags.join(" "));
+			tiddlerElem.setAttribute("tiddler",title);
+			tiddlerElem.setAttribute("template",template);
+			tiddlerElem.onmouseover = this.onTiddlerMouseOver;
+			tiddlerElem.onmouseout = this.onTiddlerMouseOut;
+			tiddlerElem.ondblclick = this.onTiddlerDblClick;
+			tiddlerElem[window.event?"onkeydown":"onkeypress"] = this.onTiddlerKeyPress;
+			tiddlerElem.innerHTML = this.getTemplateForTiddler(title,template,tiddler);
+			applyHtmlMacros(tiddlerElem,tiddler);
+			if(store.getTaggedTiddlers(title).length > 0)
+				addClass(tiddlerElem,"isTag");
+			else
+				removeClass(tiddlerElem,"isTag");
+			if(store.tiddlerExists(title)) {
+				removeClass(tiddlerElem,"shadow");
+				removeClass(tiddlerElem,"missing");
+			} else {
+				addClass(tiddlerElem,store.isShadowTiddler(title) ? "shadow" : "missing");
+			}
+			if(customFields)
+				this.addCustomFields(tiddlerElem,customFields);
+			forceReflow();
+		}
+	}
+	return tiddlerElem;
+};
+
+Story.prototype.addCustomFields = function(place,customFields)
+{
+	var fields = customFields.decodeHashMap();
+	var w = document.createElement("div");
+	w.style.display = "none";
+	place.appendChild(w);
+	for(var t in fields) {
+		var e = document.createElement("input");
+		e.setAttribute("type","text");
+		e.setAttribute("value",fields[t]);
+		w.appendChild(e);
+		e.setAttribute("edit",t);
+	}
+};
+
+Story.prototype.refreshAllTiddlers = function(force)
+{
+	var e = this.getContainer().firstChild;
+	while(e) {
+		var template = e.getAttribute("template");
+		if(template && e.getAttribute("dirty") != "true") {
+			this.refreshTiddler(e.getAttribute("tiddler"),force ? null : template,true);
+		}
+		e = e.nextSibling;
+	}
+};
+
+Story.prototype.onTiddlerMouseOver = function(e)
+{
+	if(window.addClass instanceof Function)
+		addClass(this,"selected");
+};
+
+Story.prototype.onTiddlerMouseOut = function(e)
+{
+	if(window.removeClass instanceof Function)
+		removeClass(this,"selected");
+};
+
+Story.prototype.onTiddlerDblClick = function(ev)
+{
+	var e = ev || window.event;
+	var target = resolveTarget(e);
+	if(target && target.nodeName.toLowerCase() != "input" && target.nodeName.toLowerCase() != "textarea") {
+		if(document.selection && document.selection.empty)
+			document.selection.empty();
+		config.macros.toolbar.invokeCommand(this,"defaultCommand",e);
+		e.cancelBubble = true;
+		if(e.stopPropagation) e.stopPropagation();
+		return true;
+	}
+	return false;
+};
+
+Story.prototype.onTiddlerKeyPress = function(ev)
+{
+	var e = ev || window.event;
+	clearMessage();
+	var consume = false;
+	var title = this.getAttribute("tiddler");
+	var target = resolveTarget(e);
+	switch(e.keyCode) {
+	case 9: // Tab
+		if(config.options.chkInsertTabs && target.tagName.toLowerCase() == "textarea") {
+			replaceSelection(target,String.fromCharCode(9));
+			consume = true;
+		}
+		if(config.isOpera) {
+			target.onblur = function() {
+				this.focus();
+				this.onblur = null;
+			};
+		}
+		break;
+	case 13: // Ctrl-Enter
+	case 10: // Ctrl-Enter on IE PC
+	case 77: // Ctrl-Enter is "M" on some platforms
+		if(e.ctrlKey) {
+			blurElement(this);
+			config.macros.toolbar.invokeCommand(this,"defaultCommand",e);
+			consume = true;
+		}
+		break;
+	case 27: // Escape
+		blurElement(this);
+		config.macros.toolbar.invokeCommand(this,"cancelCommand",e);
+		consume = true;
+		break;
+	}
+	e.cancelBubble = consume;
+	if(consume) {
+		if(e.stopPropagation) e.stopPropagation(); // Stop Propagation
+		e.returnValue = true; // Cancel The Event in IE
+		if(e.preventDefault ) e.preventDefault(); // Cancel The Event in Moz
+	}
+	return !consume;
+};
+
+Story.prototype.getTiddlerField = function(title,field)
+{
+	var tiddlerElem = this.getTiddler(title);
+	var e = null;
+	if(tiddlerElem ) {
+		var children = tiddlerElem.getElementsByTagName("*");
+		for(var t=0; t<children.length; t++) {
+			var c = children[t];
+			if(c.tagName.toLowerCase() == "input" || c.tagName.toLowerCase() == "textarea") {
+				if(!e)
+					e = c;
+				if(c.getAttribute("edit") == field)
+					e = c;
+			}
+		}
+	}
+	return e;
+};
+
+Story.prototype.focusTiddler = function(title,field)
+{
+	var e = this.getTiddlerField(title,field);
+	if(e) {
+		e.focus();
+		e.select();
+	}
+};
+
+Story.prototype.blurTiddler = function(title)
+{
+	var tiddlerElem = this.getTiddler(title);
+	if(tiddlerElem && tiddlerElem.focus && tiddlerElem.blur) {
+		tiddlerElem.focus();
+		tiddlerElem.blur();
+	}
+};
+
+Story.prototype.setTiddlerField = function(title,tag,mode,field)
+{
+	var c = this.getTiddlerField(title,field);
+	var tags = c.value.readBracketedList();
+	tags.setItem(tag,mode);
+	c.value = String.encodeTiddlyLinkList(tags);
+};
+
+Story.prototype.setTiddlerTag = function(title,tag,mode)
+{
+	this.setTiddlerField(title,tag,mode,"tags");
+};
+
+Story.prototype.closeTiddler = function(title,animate,unused)
+{
+	var tiddlerElem = this.getTiddler(title);
+	if(tiddlerElem) {
+		clearMessage();
+		this.scrubTiddler(tiddlerElem);
+		if(config.options.chkAnimate && animate && anim && typeof Slider == "function")
+			anim.startAnimating(new Slider(tiddlerElem,false,null,"all"));
+		else {
+			removeNode(tiddlerElem);
+			forceReflow();
+		}
+	}
+};
+
+Story.prototype.scrubTiddler = function(tiddlerElem)
+{
+	tiddlerElem.id = null;
+};
+
+Story.prototype.setDirty = function(title,dirty)
+{
+	var tiddlerElem = this.getTiddler(title);
+	if(tiddlerElem)
+		tiddlerElem.setAttribute("dirty",dirty ? "true" : "false");
+};
+
+Story.prototype.isDirty = function(title)
+{
+	var tiddlerElem = this.getTiddler(title);
+	if(tiddlerElem)
+		return tiddlerElem.getAttribute("dirty") == "true";
+	return null;
+};
+
+Story.prototype.areAnyDirty = function()
+{
+	var r = false;
+	this.forEachTiddler(function(title,element) {
+		if(this.isDirty(title))
+			r = true;
+	});
+	return r;
+};
+
+Story.prototype.closeAllTiddlers = function(exclude)
+{
+	clearMessage();
+	this.forEachTiddler(function(title,element) {
+		if((title != exclude) && element.getAttribute("dirty") != "true")
+			this.closeTiddler(title);
+	});
+	window.scrollTo(0,ensureVisible(this.container));
+};
+
+Story.prototype.isEmpty = function()
+{
+	var place = this.getContainer();
+	return place && place.firstChild == null;
+};
+
+Story.prototype.search = function(text,useCaseSensitive,useRegExp)
+{
+	this.closeAllTiddlers();
+	highlightHack = new RegExp(useRegExp ? text : text.escapeRegExp(),useCaseSensitive ? "mg" : "img");
+	var matches = store.search(highlightHack,"title","excludeSearch");
+	this.displayTiddlers(null,matches);
+	highlightHack = null;
+	var q = useRegExp ? "/" : "'";
+	if(matches.length > 0)
+		displayMessage(config.macros.search.successMsg.format([matches.length.toString(),q + text + q]));
+	else
+		displayMessage(config.macros.search.failureMsg.format([q + text + q]));
+};
+
+Story.prototype.findContainingTiddler = function(e)
+{
+	while(e && !hasClass(e,"tiddler"))
+		e = e.parentNode;
+	return e;
+};
+
+Story.prototype.gatherSaveFields = function(e,fields)
+{
+	if(e && e.getAttribute) {
+		var f = e.getAttribute("edit");
+		if(f)
+			fields[f] = e.value.replace(/\r/mg,"");
+		if(e.hasChildNodes()) {
+			var c = e.childNodes;
+			for(var t=0; t<c.length; t++)
+				this.gatherSaveFields(c[t],fields);
+		}
+	}
+};
+
+Story.prototype.hasChanges = function(title)
+{
+	var e = this.getTiddler(title);
+	if(e) {
+		var fields = {};
+		this.gatherSaveFields(e,fields);
+		var tiddler = store.fetchTiddler(title);
+		if(!tiddler)
+			return false;
+		for(var n in fields) {
+			if(store.getValue(title,n) != fields[n])
+				return true;
+		}
+	}
+	return false;
+};
+
+Story.prototype.saveTiddler = function(title,minorUpdate)
+{
+	var tiddlerElem = this.getTiddler(title);
+	if(tiddlerElem) {
+		var fields = {};
+		this.gatherSaveFields(tiddlerElem,fields);
+		var newTitle = fields.title || title;
+		if(!store.tiddlerExists(newTitle))
+			newTitle = newTitle.trim();
+		if(store.tiddlerExists(newTitle) && newTitle != title) {
+			if(!confirm(config.messages.overwriteWarning.format([newTitle.toString()])))
+				return null;
+		}
+		if(newTitle != title)
+			this.closeTiddler(newTitle,false);
+		tiddlerElem.id = this.tiddlerId(newTitle);
+		tiddlerElem.setAttribute("tiddler",newTitle);
+		tiddlerElem.setAttribute("template",DEFAULT_VIEW_TEMPLATE);
+		tiddlerElem.setAttribute("dirty","false");
+		if(config.options.chkForceMinorUpdate)
+			minorUpdate = !minorUpdate;
+		if(!store.tiddlerExists(newTitle))
+			minorUpdate = false;
+		var newDate = new Date();
+		var extendedFields = store.tiddlerExists(newTitle) ? store.fetchTiddler(newTitle).fields : (newTitle!=title && store.tiddlerExists(title) ? store.fetchTiddler(title).fields : merge({},config.defaultCustomFields));
+		for(var n in fields) {
+			if(!TiddlyWiki.isStandardField(n))
+				extendedFields[n] = fields[n];
+		}
+		var tiddler = store.saveTiddler(title,newTitle,fields.text,minorUpdate ? undefined : config.options.txtUserName,minorUpdate ? undefined : newDate,fields.tags,extendedFields);
+		autoSaveChanges(null,[tiddler]);
+		return newTitle;
+	}
+	return null;
+};
+
+Story.prototype.permaView = function()
+{
+	var links = [];
+	this.forEachTiddler(function(title,element) {
+		links.push(String.encodeTiddlyLink(title));
+	});
+	var t = encodeURIComponent(links.join(" "));
+	if(t == "")
+		t = "#";
+	if(window.location.hash != t)
+		window.location.hash = t;
+};
+
+Story.prototype.switchTheme = function(theme)
+{
+	if(safeMode)
+		return;
+
+	var isAvailable = function(title) {
+		var s = title ? title.indexOf(config.textPrimitives.sectionSeparator) : -1;
+		if(s!=-1)
+			title = title.substr(0,s);
+		return store.tiddlerExists(title) || store.isShadowTiddler(title);
+	};
+
+	var getSlice = function(theme,slice) {
+		var r;
+		if(readOnly)
+			r = store.getTiddlerSlice(theme,slice+"ReadOnly") || store.getTiddlerSlice(theme,"Web"+slice);
+		r = r || store.getTiddlerSlice(theme,slice);
+		if(r && r.indexOf(config.textPrimitives.sectionSeparator)==0)
+			r = theme + r;
+		return isAvailable(r) ? r : slice;
+	};
+
+	var replaceNotification = function(i,name,theme,slice) {
+		var newName = getSlice(theme,slice);
+		if(name!=newName && store.namedNotifications[i].name==name) {
+			store.namedNotifications[i].name = newName;
+			return newName;
+		}
+		return name;
+	};
+
+	var pt = config.refresherData.pageTemplate;
+	var vi = DEFAULT_VIEW_TEMPLATE;
+	var vt = config.tiddlerTemplates[vi];
+	var ei = DEFAULT_EDIT_TEMPLATE;
+	var et = config.tiddlerTemplates[ei];
+
+	for(var i=0; i<config.notifyTiddlers.length; i++) {
+		var name = config.notifyTiddlers[i].name;
+		switch(name) {
+		case "PageTemplate":
+			config.refresherData.pageTemplate = replaceNotification(i,config.refresherData.pageTemplate,theme,name);
+			break;
+		case "StyleSheet":
+			removeStyleSheet(config.refresherData.styleSheet);
+			config.refresherData.styleSheet = replaceNotification(i,config.refresherData.styleSheet,theme,name);
+			break;
+		case "ColorPalette":
+			config.refresherData.colorPalette = replaceNotification(i,config.refresherData.colorPalette,theme,name);
+			break;
+		default:
+			break;
+		}
+	}
+	config.tiddlerTemplates[vi] = getSlice(theme,"ViewTemplate");
+	config.tiddlerTemplates[ei] = getSlice(theme,"EditTemplate");
+	if(!startingUp) {
+		if(config.refresherData.pageTemplate!=pt || config.tiddlerTemplates[vi]!=vt || config.tiddlerTemplates[ei]!=et) {
+			refreshAll();
+			this.refreshAllTiddlers(true);
+		} else {
+			setStylesheet(store.getRecursiveTiddlerText(config.refresherData.styleSheet,"",10),config.refreshers.styleSheet);
+		}
+		config.options.txtTheme = theme;
+		saveOptionCookie("txtTheme");
+	}
+};
+
+//--
+//-- Backstage
+//--
+
+var backstage = {
+	area: null,
+	toolbar: null,
+	button: null,
+	showButton: null,
+	hideButton: null,
+	cloak: null,
+	panel: null,
+	panelBody: null,
+	panelFooter: null,
+	currTabName: null,
+	currTabElem: null,
+	content: null,
+
+	init: function() {
+		var cmb = config.messages.backstage;
+		this.area = document.getElementById("backstageArea");
+		this.toolbar = document.getElementById("backstageToolbar");
+		this.button = document.getElementById("backstageButton");
+		this.button.style.display = "block";
+		var t = cmb.open.text + " " + glyph("bentArrowLeft");
+		this.showButton = createTiddlyButton(this.button,t,cmb.open.tooltip,
+						function(e) {backstage.show(); return false;},null,"backstageShow");
+		t = glyph("bentArrowRight") + " " + cmb.close.text;
+		this.hideButton = createTiddlyButton(this.button,t,cmb.close.tooltip,
+						function(e) {backstage.hide(); return false;},null,"backstageHide");
+		this.cloak = document.getElementById("backstageCloak");
+		this.panel = document.getElementById("backstagePanel");
+		this.panelFooter = createTiddlyElement(this.panel,"div",null,"backstagePanelFooter");
+		this.panelBody = createTiddlyElement(this.panel,"div",null,"backstagePanelBody");
+		this.cloak.onmousedown = function(e) {backstage.switchTab(null);};
+		createTiddlyText(this.toolbar,cmb.prompt);
+		for(t=0; t<config.backstageTasks.length; t++) {
+			var taskName = config.backstageTasks[t];
+			var task = config.tasks[taskName];
+			var handler = task.action ? this.onClickCommand : this.onClickTab;
+			var text = task.text + (task.action ? "" : glyph("downTriangle"));
+			var btn = createTiddlyButton(this.toolbar,text,task.tooltip,handler,"backstageTab");
+			btn.setAttribute("task",taskName);
+			addClass(btn,task.action ? "backstageAction" : "backstageTask");
+			}
+		this.content = document.getElementById("contentWrapper");
+		if(config.options.chkBackstage)
+			this.show();
+		else
+			this.hide();
+	},
+
+	isVisible: function() {
+		return this.area ? this.area.style.display == "block" : false;
+	},
+
+	show: function() {
+		this.area.style.display = "block";
+		if(anim && config.options.chkAnimate) {
+			backstage.toolbar.style.left = findWindowWidth() + "px";
+			var p = [{style: "left", start: findWindowWidth(), end: 0, template: "%0px"}];
+			anim.startAnimating(new Morpher(backstage.toolbar,config.animDuration,p));
+		} else {
+			backstage.area.style.left = "0px";
+		}
+		this.showButton.style.display = "none";
+		this.hideButton.style.display = "block";
+		config.options.chkBackstage = true;
+		saveOptionCookie("chkBackstage");
+		addClass(this.content,"backstageVisible");
+	},
+
+	hide: function() {
+		if(this.currTabElem) {
+			this.switchTab(null);
+		} else {
+			backstage.toolbar.style.left = "0px";
+			if(anim && config.options.chkAnimate) {
+				var p = [{style: "left", start: 0, end: findWindowWidth(), template: "%0px"}];
+				var c = function(element,properties) {backstage.area.style.display = "none";};
+				anim.startAnimating(new Morpher(backstage.toolbar,config.animDuration,p,c));
+			} else {
+				this.area.style.display = "none";
+			}
+			this.showButton.style.display = "block";
+			this.hideButton.style.display = "none";
+			config.options.chkBackstage = false;
+			saveOptionCookie("chkBackstage");
+			removeClass(this.content,"backstageVisible");
+		}
+	},
+
+	onClickCommand: function(e) {
+		var task = config.tasks[this.getAttribute("task")];
+		displayMessage(task);
+		if(task.action) {
+			backstage.switchTab(null);
+			task.action();
+		}
+		return false;
+	},
+
+	onClickTab: function(e) {
+		backstage.switchTab(this.getAttribute("task"));
+		return false;
+	},
+
+	// Switch to a given tab, or none if null is passed
+	switchTab: function(tabName) {
+		var tabElem = null;
+		var e = this.toolbar.firstChild;
+		while(e)
+			{
+			if(e.getAttribute && e.getAttribute("task") == tabName)
+				tabElem = e;
+			e = e.nextSibling;
+			}
+		if(tabName == backstage.currTabName)
+			return;
+		if(backstage.currTabElem) {
+			removeClass(this.currTabElem,"backstageSelTab");
+		}
+		if(tabElem && tabName) {
+			backstage.preparePanel();
+			addClass(tabElem,"backstageSelTab");
+			var task = config.tasks[tabName];
+			wikify(task.content,backstage.panelBody,null,null);
+			backstage.showPanel();
+		} else if(backstage.currTabElem) {
+			backstage.hidePanel();
+		}
+		backstage.currTabName = tabName;
+		backstage.currTabElem = tabElem;
+	},
+
+	isPanelVisible: function() {
+		return backstage.panel ? backstage.panel.style.display == "block" : false;
+	},
+
+	preparePanel: function() {
+		backstage.cloak.style.height = findWindowHeight() + "px";
+		backstage.cloak.style.display = "block";
+		removeChildren(backstage.panelBody);
+		return backstage.panelBody;
+	},
+
+	showPanel: function() {
+		backstage.panel.style.display = "block";
+		if(anim && config.options.chkAnimate) {
+			backstage.panel.style.top = (-backstage.panel.offsetHeight) + "px";
+			var p = [{style: "top", start: -backstage.panel.offsetHeight, end: 0, template: "%0px"}];
+			anim.startAnimating(new Morpher(backstage.panel,config.animDuration,p),new Scroller(backstage.panel,false));
+		} else {
+			backstage.panel.style.top = "0px";
+		}
+		return backstage.panelBody;
+	},
+
+	hidePanel: function() {
+		if(backstage.currTabElem)
+			removeClass(backstage.currTabElem,"backstageSelTab");
+		backstage.currTabElem = null;
+		backstage.currTabName = null;
+		if(anim && config.options.chkAnimate) {
+			var p = [
+				{style: "top", start: 0, end: -(backstage.panel.offsetHeight), template: "%0px"},
+				{style: "display", atEnd: "none"}
+			];
+			var c = function(element,properties) {backstage.cloak.style.display = "none";};
+			anim.startAnimating(new Morpher(backstage.panel,config.animDuration,p,c));
+		 } else {
+			backstage.panel.style.display = "none";
+			backstage.cloak.style.display = "none";
+		}
+	}
+};
+
+config.macros.backstage = {};
+
+config.macros.backstage.handler = function(place,macroName,params)
+{
+	var backstageTask = config.tasks[params[0]];
+	if(backstageTask)
+		createTiddlyButton(place,backstageTask.text,backstageTask.tooltip,function(e) {backstage.switchTab(params[0]); return false;});
+};
+
+//--
+//-- ImportTiddlers macro
+//--
+
+config.macros.importTiddlers.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	if(readOnly) {
+		createTiddlyElement(place,"div",null,"marked",this.readOnlyWarning);
+		return;
+	}
+	var w = new Wizard();
+	w.createWizard(place,this.wizardTitle);
+	this.restart(w);
+};
+
+config.macros.importTiddlers.onCancel = function(e)
+{
+	var wizard = new Wizard(this);
+	var place = wizard.clear();
+	config.macros.importTiddlers.restart(wizard);
+	return false;
+};
+
+config.macros.importTiddlers.onClose = function(e)
+{
+	backstage.hidePanel();
+	return false;
+};
+
+config.macros.importTiddlers.restart = function(wizard)
+{
+	wizard.addStep(this.step1Title,this.step1Html);
+	var s = wizard.getElement("selTypes");
+	for(var t in config.adaptors) {
+		var e = createTiddlyElement(s,"option",null,null,config.adaptors[t].serverLabel ? config.adaptors[t].serverLabel : t);
+		e.value = t;
+	}
+	if(config.defaultAdaptor)
+		s.value = config.defaultAdaptor;
+	s = wizard.getElement("selFeeds");
+	var feeds = this.getFeeds();
+	for(t in feeds) {
+		e = createTiddlyElement(s,"option",null,null,t);
+		e.value = t;
+	}
+	wizard.setValue("feeds",feeds);
+	s.onchange = config.macros.importTiddlers.onFeedChange;
+	var fileInput = wizard.getElement("txtBrowse");
+	fileInput.onchange = config.macros.importTiddlers.onBrowseChange;
+	fileInput.onkeyup = config.macros.importTiddlers.onBrowseChange;
+	wizard.setButtons([{caption: this.openLabel, tooltip: this.openPrompt, onClick: config.macros.importTiddlers.onOpen}]);
+	wizard.formElem.action = "javascript:;";
+	wizard.formElem.onsubmit = function() {
+		if(this.txtPath.value.length)
+			this.lastChild.firstChild.onclick();
+	};
+};
+
+config.macros.importTiddlers.getFeeds = function()
+{
+	var feeds = {};
+	var tagged = store.getTaggedTiddlers("systemServer","title");
+	for(var t=0; t<tagged.length; t++) {
+		var title = tagged[t].title;
+		var serverType = store.getTiddlerSlice(title,"Type");
+		if(!serverType)
+			serverType = "file";
+		feeds[title] = {title: title,
+						url: store.getTiddlerSlice(title,"URL"),
+						workspace: store.getTiddlerSlice(title,"Workspace"),
+						workspaceList: store.getTiddlerSlice(title,"WorkspaceList"),
+						tiddlerFilter: store.getTiddlerSlice(title,"TiddlerFilter"),
+						serverType: serverType,
+						description: store.getTiddlerSlice(title,"Description")};
+	}
+	return feeds;
+};
+
+config.macros.importTiddlers.onFeedChange = function(e)
+{
+	var wizard = new Wizard(this);
+	var selTypes = wizard.getElement("selTypes");
+	var fileInput = wizard.getElement("txtPath");
+	var feeds = wizard.getValue("feeds");
+	var f = feeds[this.value];
+	if(f) {
+		selTypes.value = f.serverType;
+		fileInput.value = f.url;
+		wizard.setValue("feedName",f.serverType);
+		wizard.setValue("feedHost",f.url);
+		wizard.setValue("feedWorkspace",f.workspace);
+		wizard.setValue("feedWorkspaceList",f.workspaceList);
+		wizard.setValue("feedTiddlerFilter",f.tiddlerFilter);
+	}
+	return false;
+};
+
+config.macros.importTiddlers.onBrowseChange = function(e)
+{
+	var wizard = new Wizard(this);
+	var fileInput = wizard.getElement("txtPath");
+	fileInput.value = config.macros.importTiddlers.getURLFromLocalPath(this.value);
+	var serverType = wizard.getElement("selTypes");
+	serverType.value = "file";
+	return true;
+};
+
+config.macros.importTiddlers.getURLFromLocalPath = function(v)
+{
+	if(!v||!v.length)
+		return v;
+	v = v.replace(/\\/g,"/"); // use "/" for cross-platform consistency
+	var u;
+	var t = v.split(":");
+	var p = t[1]||t[0]; // remove drive letter (if any)
+	if (t[1] && (t[0]=="http"||t[0]=="https"||t[0]=="file")) {
+		u = v;
+	} else if(p.substr(0,1)=="/") {
+		u = document.location.protocol + "//" + document.location.hostname + (t[1] ? "/" : "") + v;
+	} else {
+		var c = document.location.href.replace(/\\/g,"/");
+		var pos = c.lastIndexOf("/");
+		if (pos!=-1)
+			c = c.substr(0,pos); // remove filename
+		u = c + "/" + p;
+	}
+	return u;
+};
+
+config.macros.importTiddlers.onOpen = function(e)
+{
+	var wizard = new Wizard(this);
+	var fileInput = wizard.getElement("txtPath");
+	var url = fileInput.value;
+	var serverType = wizard.getElement("selTypes").value || config.defaultAdaptor;
+	var adaptor = new config.adaptors[serverType]();
+	wizard.setValue("adaptor",adaptor);
+	wizard.setValue("serverType",serverType);
+	wizard.setValue("host",url);
+	var ret = adaptor.openHost(url,null,wizard,config.macros.importTiddlers.onOpenHost);
+	if(ret !== true)
+		displayMessage(ret);
+	wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusOpenHost);
+	return false;
+};
+
+config.macros.importTiddlers.onOpenHost = function(context,wizard)
+{
+	var adaptor = wizard.getValue("adaptor");
+	if(context.status !== true)
+		displayMessage("Error in importTiddlers.onOpenHost: " + context.statusText);
+	var ret = adaptor.getWorkspaceList(context,wizard,config.macros.importTiddlers.onGetWorkspaceList);
+	if(ret !== true)
+		displayMessage(ret);
+	wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusGetWorkspaceList);
+};
+
+config.macros.importTiddlers.onGetWorkspaceList = function(context,wizard)
+{
+	if(context.status !== true)
+		displayMessage("Error in importTiddlers.onGetWorkspaceList: " + context.statusText);
+	wizard.setValue("context",context);
+	var workspace = wizard.getValue("feedWorkspace");
+	if(!workspace && context.workspaces.length==1)
+		workspace = context.workspaces[0].title;
+	if(workspace) {
+		var ret = context.adaptor.openWorkspace(workspace,context,wizard,config.macros.importTiddlers.onOpenWorkspace);
+		if(ret !== true)
+			displayMessage(ret);
+		wizard.setValue("workspace",workspace);
+		wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusOpenWorkspace);
+		return;
+	}
+	wizard.addStep(config.macros.importTiddlers.step2Title,config.macros.importTiddlers.step2Html);
+	var s = wizard.getElement("selWorkspace");
+	s.onchange = config.macros.importTiddlers.onWorkspaceChange;
+	for(var t=0; t<context.workspaces.length; t++) {
+		var e = createTiddlyElement(s,"option",null,null,context.workspaces[t].title);
+		e.value = context.workspaces[t].title;
+	}
+	var workspaceList = wizard.getValue("feedWorkspaceList");
+	if(workspaceList) {
+		var list = workspaceList.parseParams("workspace",null,false,true);
+		for(var n=1; n<list.length; n++) {
+			if(context.workspaces.findByField("title",list[n].value) == null) {
+				e = createTiddlyElement(s,"option",null,null,list[n].value);
+				e.value = list[n].value;
+			}
+		}
+	}
+	if(workspace) {
+		t = wizard.getElement("txtWorkspace");
+		t.value = workspace;
+	}
+	wizard.setButtons([{caption: config.macros.importTiddlers.openLabel, tooltip: config.macros.importTiddlers.openPrompt, onClick: config.macros.importTiddlers.onChooseWorkspace}]);
+};
+
+config.macros.importTiddlers.onWorkspaceChange = function(e)
+{
+	var wizard = new Wizard(this);
+	var t = wizard.getElement("txtWorkspace");
+	t.value = this.value;
+	this.selectedIndex = 0;
+	return false;
+};
+
+config.macros.importTiddlers.onChooseWorkspace = function(e)
+{
+	var wizard = new Wizard(this);
+	var adaptor = wizard.getValue("adaptor");
+	var workspace = wizard.getElement("txtWorkspace").value;
+	wizard.setValue("workspace",workspace);
+	var context = wizard.getValue("context");
+	var ret = adaptor.openWorkspace(workspace,context,wizard,config.macros.importTiddlers.onOpenWorkspace);
+	if(ret !== true)
+		displayMessage(ret);
+	wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusOpenWorkspace);
+	return false;
+};
+
+config.macros.importTiddlers.onOpenWorkspace = function(context,wizard)
+{
+	if(context.status !== true)
+		displayMessage("Error in importTiddlers.onOpenWorkspace: " + context.statusText);
+	var adaptor = wizard.getValue("adaptor");
+	var ret = adaptor.getTiddlerList(context,wizard,config.macros.importTiddlers.onGetTiddlerList,wizard.getValue("feedTiddlerFilter"));
+	if(ret !== true)
+		displayMessage(ret);
+	wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.statusGetTiddlerList);
+};
+
+config.macros.importTiddlers.onGetTiddlerList = function(context,wizard)
+{
+	if(context.status !== true) {
+		wizard.setButtons([{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}],config.macros.importTiddlers.errorGettingTiddlerList);
+		return;
+	}
+	// Extract data for the listview
+	var listedTiddlers = [];
+	if(context.tiddlers) {
+		for(var n=0; n<context.tiddlers.length; n++) {
+			var tiddler = context.tiddlers[n];
+			listedTiddlers.push({
+				title: tiddler.title,
+				modified: tiddler.modified,
+				modifier: tiddler.modifier,
+				text: tiddler.text ? wikifyPlainText(tiddler.text,100) : "",
+				tags: tiddler.tags,
+				size: tiddler.text ? tiddler.text.length : 0,
+				tiddler: tiddler
+			});
+		}
+	}
+	listedTiddlers.sort(function(a,b) {return a.title < b.title ? -1 : (a.title == b.title ? 0 : +1);});
+	// Display the listview
+	wizard.addStep(config.macros.importTiddlers.step3Title,config.macros.importTiddlers.step3Html);
+	var markList = wizard.getElement("markList");
+	var listWrapper = document.createElement("div");
+	markList.parentNode.insertBefore(listWrapper,markList);
+	var listView = ListView.create(listWrapper,listedTiddlers,config.macros.importTiddlers.listViewTemplate);
+	wizard.setValue("listView",listView);
+	wizard.setValue("context",context);
+	var txtSaveTiddler = wizard.getElement("txtSaveTiddler");
+	txtSaveTiddler.value = config.macros.importTiddlers.generateSystemServerName(wizard);
+	wizard.setButtons([
+			{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel},
+			{caption: config.macros.importTiddlers.importLabel, tooltip: config.macros.importTiddlers.importPrompt, onClick: config.macros.importTiddlers.doImport}
+		]);
+};
+
+config.macros.importTiddlers.generateSystemServerName = function(wizard)
+{
+	var serverType = wizard.getValue("serverType");
+	var host = wizard.getValue("host");
+	var workspace = wizard.getValue("workspace");
+	var pattern = config.macros.importTiddlers[workspace ? "systemServerNamePattern" : "systemServerNamePatternNoWorkspace"];
+	return pattern.format([serverType,host,workspace]);
+};
+
+config.macros.importTiddlers.saveServerTiddler = function(wizard)
+{
+	var txtSaveTiddler = wizard.getElement("txtSaveTiddler").value;
+	if(store.tiddlerExists(txtSaveTiddler)) {
+		if(!confirm(config.macros.importTiddlers.confirmOverwriteSaveTiddler.format([txtSaveTiddler])))
+			return;
+		store.suspendNotifications();
+		store.removeTiddler(txtSaveTiddler);
+		store.resumeNotifications();
+	}
+	var serverType = wizard.getValue("serverType");
+	var host = wizard.getValue("host");
+	var workspace = wizard.getValue("workspace");
+	var text = config.macros.importTiddlers.serverSaveTemplate.format([serverType,host,workspace]);
+	store.saveTiddler(txtSaveTiddler,txtSaveTiddler,text,config.macros.importTiddlers.serverSaveModifier,new Date(),["systemServer"]);
+};
+
+config.macros.importTiddlers.doImport = function(e)
+{
+	var wizard = new Wizard(this);
+	if(wizard.getElement("chkSave").checked)
+		config.macros.importTiddlers.saveServerTiddler(wizard);
+	var chkSync = wizard.getElement("chkSync").checked;
+	wizard.setValue("sync",chkSync);
+	var listView = wizard.getValue("listView");
+	var rowNames = ListView.getSelectedRows(listView);
+	var adaptor = wizard.getValue("adaptor");
+	var overwrite = [];
+	var t;
+	for(t=0; t<rowNames.length; t++) {
+		if(store.tiddlerExists(rowNames[t]))
+			overwrite.push(rowNames[t]);
+	}
+	if(overwrite.length > 0) {
+		if(!confirm(config.macros.importTiddlers.confirmOverwriteText.format([overwrite.join(", ")])))
+			return false;
+	}
+	wizard.addStep(config.macros.importTiddlers.step4Title.format([rowNames.length]),config.macros.importTiddlers.step4Html);
+	for(t=0; t<rowNames.length; t++) {
+		var link = document.createElement("div");
+		createTiddlyLink(link,rowNames[t],true);
+		var place = wizard.getElement("markReport");
+		place.parentNode.insertBefore(link,place);
+	}
+	wizard.setValue("remainingImports",rowNames.length);
+	wizard.setButtons([
+			{caption: config.macros.importTiddlers.cancelLabel, tooltip: config.macros.importTiddlers.cancelPrompt, onClick: config.macros.importTiddlers.onCancel}
+		],config.macros.importTiddlers.statusDoingImport);
+	var wizardContext = wizard.getValue("context");
+	var tiddlers = wizardContext ? wizardContext.tiddlers : [];
+	for(t=0; t<rowNames.length; t++) {
+		var context = {
+			allowSynchronous:true,
+			tiddler:tiddlers[tiddlers.findByField("title",rowNames[t])]
+		};
+		adaptor.getTiddler(rowNames[t],context,wizard,config.macros.importTiddlers.onGetTiddler);
+	}
+	return false;
+};
+
+config.macros.importTiddlers.onGetTiddler = function(context,wizard)
+{
+	if(!context.status)
+		displayMessage("Error in importTiddlers.onGetTiddler: " + context.statusText);
+	var tiddler = context.tiddler;
+	store.suspendNotifications();
+	store.saveTiddler(tiddler.title, tiddler.title, tiddler.text, tiddler.modifier, tiddler.modified, tiddler.tags, tiddler.fields, true, tiddler.created);
+	if(!wizard.getValue("sync")) {
+		store.setValue(tiddler.title,'server',null);
+	}
+	store.resumeNotifications();
+	if(!context.isSynchronous)
+		store.notify(tiddler.title,true);
+	var remainingImports = wizard.getValue("remainingImports")-1;
+	wizard.setValue("remainingImports",remainingImports);
+	if(remainingImports == 0) {
+		if(context.isSynchronous) {
+			store.notifyAll();
+			refreshDisplay();
+		}
+		wizard.setButtons([
+				{caption: config.macros.importTiddlers.doneLabel, tooltip: config.macros.importTiddlers.donePrompt, onClick: config.macros.importTiddlers.onClose}
+			],config.macros.importTiddlers.statusDoneImport);
+		autoSaveChanges();
+	}
+};
+
+//--
+//-- Upgrade macro
+//--
+
+config.macros.upgrade.handler = function(place)
+{
+	var w = new Wizard();
+	w.createWizard(place,this.wizardTitle);
+	w.addStep(this.step1Title,this.step1Html.format([this.source,this.source]));
+	w.setButtons([{caption: this.upgradeLabel, tooltip: this.upgradePrompt, onClick: this.onClickUpgrade}]);
+};
+
+config.macros.upgrade.onClickUpgrade = function(e)
+{
+	var me = config.macros.upgrade;
+	var w = new Wizard(this);
+	if(window.location.protocol != "file:") {
+		alert(me.errorCantUpgrade);
+		return false;
+	}
+	if(story.areAnyDirty() || store.isDirty()) {
+		alert(me.errorNotSaved);
+		return false;
+	}
+	var localPath = getLocalPath(document.location.toString());
+	var backupPath = getBackupPath(localPath,me.backupExtension);
+	w.setValue("backupPath",backupPath);
+	w.setButtons([],me.statusPreparingBackup);
+	var original = loadOriginal(localPath);
+	w.setButtons([],me.statusSavingBackup);
+	var backup = config.browser.isIE ? ieCopyFile(backupPath,localPath) : saveFile(backupPath,original);
+	if(backup != true) {
+		w.setButtons([],me.errorSavingBackup);
+		alert(me.errorSavingBackup);
+		return false;
+	}
+	w.setButtons([],me.statusLoadingCore);
+	var load = loadRemoteFile(me.source,me.onLoadCore,w);
+	if(typeof load == "string") {
+		w.setButtons([],me.errorLoadingCore);
+		alert(me.errorLoadingCore);
+		return false;
+	}
+	return false;
+};
+
+config.macros.upgrade.onLoadCore = function(status,params,responseText,url,xhr)
+{
+	var me = config.macros.upgrade;
+	var w = params;
+	var errMsg;
+	if(!status)
+		errMsg = me.errorLoadingCore;
+	var newVer = me.extractVersion(responseText);
+	if(!newVer)
+		errMsg = me.errorCoreFormat;
+	if(errMsg) {
+		w.setButtons([],errMsg);
+		alert(errMsg);
+		return;
+	}
+	var onStartUpgrade = function(e) {
+		w.setButtons([],me.statusSavingCore);
+		var localPath = getLocalPath(document.location.toString());
+		saveFile(localPath,responseText);
+		w.setButtons([],me.statusReloadingCore);
+		var backupPath = w.getValue("backupPath");
+		var newLoc = document.location.toString() + '?time=' + new Date().convertToYYYYMMDDHHMM() + '#upgrade:[[' + encodeURI(backupPath) + ']]';
+		window.setTimeout(function () {window.location = newLoc;},10);
+	};
+	var step2 = [me.step2Html_downgrade,me.step2Html_restore,me.step2Html_upgrade][compareVersions(version,newVer) + 1];
+	w.addStep(me.step2Title,step2.format([formatVersion(newVer),formatVersion(version)]));
+	w.setButtons([{caption: me.startLabel, tooltip: me.startPrompt, onClick: onStartUpgrade},{caption: me.cancelLabel, tooltip: me.cancelPrompt, onClick: me.onCancel}]);
+};
+
+config.macros.upgrade.onCancel = function(e)
+{
+	var me = config.macros.upgrade;
+	var w = new Wizard(this);
+	w.addStep(me.step3Title,me.step3Html);
+	w.setButtons([]);
+	return false;
+};
+
+config.macros.upgrade.extractVersion = function(upgradeFile)
+{
+	var re = /^var version = \{title: "([^"]+)", major: (\d+), minor: (\d+), revision: (\d+)(, beta: (\d+)){0,1}, date: new Date\("([^"]+)"\)/mg;
+	var m = re.exec(upgradeFile);
+	return  m ? {title: m[1], major: m[2], minor: m[3], revision: m[4], beta: m[6], date: new Date(m[7])} : null;
+};
+
+function upgradeFrom(path)
+{
+	var importStore = new TiddlyWiki();
+	var tw = loadFile(path);
+	if(window.netscape !== undefined)
+		tw = convertUTF8ToUnicode(tw);
+	importStore.importTiddlyWiki(tw);
+	importStore.forEachTiddler(function(title,tiddler) {
+		if(!store.getTiddler(title)) {
+			store.addTiddler(tiddler);
+		}
+	});
+	refreshDisplay();
+	saveChanges(); //# To create appropriate Markup* sections
+	alert(config.messages.upgradeDone.format([formatVersion()]));
+	window.location = window.location.toString().substr(0,window.location.toString().lastIndexOf('?'));
+}
+
+//--
+//-- Sync macro
+//--
+
+// Synchronisation handlers
+config.syncers = {};
+
+// Sync state.
+var currSync = null;
+
+// sync macro
+config.macros.sync.handler = function(place,macroName,params,wikifier,paramString,tiddler)
+{
+	if(!wikifier.isStatic)
+		this.startSync(place);
+};
+
+config.macros.sync.cancelSync = function()
+{
+	currSync = null;
+};
+
+config.macros.sync.startSync = function(place)
+{
+	if(currSync)
+		config.macros.sync.cancelSync();
+	currSync = {};
+	currSync.syncList = this.getSyncableTiddlers();
+	currSync.syncTasks = this.createSyncTasks(currSync.syncList);
+	this.preProcessSyncableTiddlers(currSync.syncList);
+	var wizard = new Wizard();
+	currSync.wizard = wizard;
+	wizard.createWizard(place,this.wizardTitle);
+	wizard.addStep(this.step1Title,this.step1Html);
+	var markList = wizard.getElement("markList");
+	var listWrapper = document.createElement("div");
+	markList.parentNode.insertBefore(listWrapper,markList);
+	currSync.listView = ListView.create(listWrapper,currSync.syncList,this.listViewTemplate);
+	this.processSyncableTiddlers(currSync.syncList);
+	wizard.setButtons([{caption: this.syncLabel, tooltip: this.syncPrompt, onClick: this.doSync}]);
+};
+
+config.macros.sync.getSyncableTiddlers = function()
+{
+	var list = [];
+	store.forEachTiddler(function(title,tiddler) {
+		var syncItem = {};
+		syncItem.serverType = tiddler.getServerType();
+		syncItem.serverHost = tiddler.fields['server.host'];
+		if(syncItem.serverType && syncItem.serverHost) {
+			syncItem.serverWorkspace = tiddler.fields['server.workspace'];
+			syncItem.tiddler = tiddler;
+			syncItem.title = tiddler.title;
+			syncItem.isTouched = tiddler.isTouched();
+			syncItem.selected = syncItem.isTouched;
+			syncItem.syncStatus = config.macros.sync.syncStatusList[syncItem.isTouched ? "changedLocally" : "none"];
+			syncItem.status = syncItem.syncStatus.text;
+			list.push(syncItem);
+		}
+		});
+	list.sort(function(a,b) {return a.title < b.title ? -1 : (a.title == b.title ? 0 : +1);});
+	return list;
+};
+
+config.macros.sync.preProcessSyncableTiddlers = function(syncList)
+{
+	for(var i=0; i<syncList.length; i++) {
+		var si = syncList[i];
+		si.serverUrl = si.syncTask.syncMachine.generateTiddlerInfo(si.tiddler).uri;
+	}
+};
+
+config.macros.sync.processSyncableTiddlers = function(syncList)
+{
+	for(var i=0; i<syncList.length; i++) {
+		var si = syncList[i];
+		if(si.syncStatus.display)
+			si.rowElement.style.display = si.syncStatus.display;
+		if(si.syncStatus.className)
+			si.rowElement.className = si.syncStatus.className;
+	}
+};
+
+config.macros.sync.createSyncTasks = function(syncList)
+{
+	var syncTasks = [];
+	for(var i=0; i<syncList.length; i++) {
+		var si = syncList[i];
+		var r = null;
+		for(var j=0; j<syncTasks.length; j++) {
+			var cst = syncTasks[j];
+			if(si.serverType == cst.serverType && si.serverHost == cst.serverHost && si.serverWorkspace == cst.serverWorkspace)
+				r = cst;
+		}
+		if(r) {
+			si.syncTask = r;
+			r.syncItems.push(si);
+		} else {
+			si.syncTask = this.createSyncTask(si);
+			syncTasks.push(si.syncTask);
+		}
+	}
+	return syncTasks;
+};
+
+config.macros.sync.createSyncTask = function(syncItem)
+{
+	var st = {};
+	st.serverType = syncItem.serverType;
+	st.serverHost = syncItem.serverHost;
+	st.serverWorkspace = syncItem.serverWorkspace;
+	st.syncItems = [syncItem];
+	st.syncMachine = new SyncMachine(st.serverType,{
+		start: function() {
+			return this.openHost(st.serverHost,"openWorkspace");
+		},
+		openWorkspace: function() {
+			return this.openWorkspace(st.serverWorkspace,"getTiddlerList");
+		},
+		getTiddlerList: function() {
+			return this.getTiddlerList("onGetTiddlerList");
+		},
+		onGetTiddlerList: function(context) {
+			var tiddlers = context.tiddlers;
+			for(var i=0; i<st.syncItems.length; i++) {
+				var si = st.syncItems[i];
+				var f = tiddlers.findByField("title",si.title);
+				if(f !== null) {
+					if(tiddlers[f].fields['server.page.revision'] > si.tiddler.fields['server.page.revision']) {
+						si.syncStatus = config.macros.sync.syncStatusList[si.isTouched ? 'changedBoth' : 'changedServer'];
+					}
+				} else {
+					si.syncStatus = config.macros.sync.syncStatusList.notFound;
+				}
+				config.macros.sync.updateSyncStatus(si);
+			}
+		},
+		getTiddler: function(title) {
+			return this.getTiddler(title,"onGetTiddler");
+		},
+		onGetTiddler: function(context) {
+			var tiddler = context.tiddler;
+			var syncItem = st.syncItems.findByField("title",tiddler.title);
+			if(syncItem !== null) {
+				syncItem = st.syncItems[syncItem];
+				store.saveTiddler(tiddler.title, tiddler.title, tiddler.text, tiddler.modifier, tiddler.modified, tiddler.tags, tiddler.fields, true, tiddler.created);
+				syncItem.syncStatus = config.macros.sync.syncStatusList.gotFromServer;
+				config.macros.sync.updateSyncStatus(syncItem);
+			}
+		},
+		putTiddler: function(tiddler) {
+			return this.putTiddler(tiddler,"onPutTiddler");
+		},
+		onPutTiddler: function(context) {
+			var title = context.title;
+			var syncItem = st.syncItems.findByField("title",title);
+			if(syncItem !== null) {
+				syncItem = st.syncItems[syncItem];
+				store.resetTiddler(title);
+				if(context.status) {
+					syncItem.syncStatus = config.macros.sync.syncStatusList.putToServer;
+					config.macros.sync.updateSyncStatus(syncItem);
+				}
+			}
+		}
+	});
+	st.syncMachine.go();
+	return st;
+};
+
+config.macros.sync.updateSyncStatus = function(syncItem)
+{
+	var e = syncItem.colElements["status"];
+	removeChildren(e);
+	createTiddlyText(e,syncItem.syncStatus.text);
+	if(syncItem.syncStatus.display)
+		syncItem.rowElement.style.display = syncItem.syncStatus.display;
+	if(syncItem.syncStatus.className)
+		syncItem.rowElement.className = syncItem.syncStatus.className;
+};
+
+config.macros.sync.doSync = function(e)
+{
+	var rowNames = ListView.getSelectedRows(currSync.listView);
+	var sl = config.macros.sync.syncStatusList;
+	for(var i=0; i<currSync.syncList.length; i++) {
+		var si = currSync.syncList[i];
+		if(rowNames.indexOf(si.title) != -1) {
+			var r = true;
+			switch(si.syncStatus) {
+			case sl.changedServer:
+				r = si.syncTask.syncMachine.go("getTiddler",si.title);
+				break;
+			case sl.notFound:
+			case sl.changedLocally:
+			case sl.changedBoth:
+				r = si.syncTask.syncMachine.go("putTiddler",si.tiddler);
+				break;
+			default:
+				break;
+			}
+			if(!r)
+				displayMessage("Error in doSync: " + r);
+		}
+	}
+	return false;
+};
+
+function SyncMachine(serverType,steps)
+{
+	this.serverType = serverType;
+	this.adaptor = new config.adaptors[serverType]();
+	this.steps = steps;
+}
+
+SyncMachine.prototype.go = function(step,context)
+{
+	var r = context ? context.status : null;
+	if(typeof r == "string") {
+		this.invokeError(r);
+		return r;
+	}
+	var h = this.steps[step ? step : "start"];
+	if(!h)
+		return null;
+	r = h.call(this,context);
+	if(typeof r == "string")
+		this.invokeError(r);
+	return r;
+};
+
+SyncMachine.prototype.invokeError = function(message)
+{
+	if(this.steps.error)
+		this.steps.error(message);
+};
+
+SyncMachine.prototype.openHost = function(host,nextStep)
+{
+	var me = this;
+	return me.adaptor.openHost(host,null,null,function(context) {me.go(nextStep,context);});
+};
+
+SyncMachine.prototype.getWorkspaceList = function(nextStep)
+{
+	var me = this;
+	return me.adaptor.getWorkspaceList(null,null,function(context) {me.go(nextStep,context);});
+};
+
+SyncMachine.prototype.openWorkspace = function(workspace,nextStep)
+{
+	var me = this;
+	return me.adaptor.openWorkspace(workspace,null,null,function(context) {me.go(nextStep,context);});
+};
+
+SyncMachine.prototype.getTiddlerList = function(nextStep)
+{
+	var me = this;
+	return me.adaptor.getTiddlerList(null,null,function(context) {me.go(nextStep,context);});
+};
+
+SyncMachine.prototype.generateTiddlerInfo = function(tiddler)
+{
+	return this.adaptor.generateTiddlerInfo(tiddler);
+};
+
+SyncMachine.prototype.getTiddler = function(title,nextStep)
+{
+	var me = this;
+	return me.adaptor.getTiddler(title,null,null,function(context) {me.go(nextStep,context);});
+};
+
+SyncMachine.prototype.putTiddler = function(tiddler,nextStep)
+{
+	var me = this;
+	if(me.adaptor.putTiddler)
+		return me.adaptor.putTiddler(tiddler,null,null,function(context) {me.go(nextStep,context);});
+	return false;
+};
+
+//--
+//-- Manager UI for groups of tiddlers
+//--
+
+config.macros.plugins.handler = function(place,macroName,params,wikifier,paramString)
+{
+	var wizard = new Wizard();
+	wizard.createWizard(place,this.wizardTitle);
+	wizard.addStep(this.step1Title,this.step1Html);
+	var markList = wizard.getElement("markList");
+	var listWrapper = document.createElement("div");
+	markList.parentNode.insertBefore(listWrapper,markList);
+	listWrapper.setAttribute("refresh","macro");
+	listWrapper.setAttribute("macroName","plugins");
+	listWrapper.setAttribute("params",paramString);
+	this.refresh(listWrapper,paramString);
+};
+
+config.macros.plugins.refresh = function(listWrapper,params)
+{
+	var wizard = new Wizard(listWrapper);
+	var selectedRows = [];
+	ListView.forEachSelector(listWrapper,function(e,rowName) {
+			if(e.checked)
+				selectedRows.push(e.getAttribute("rowName"));
+		});
+	removeChildren(listWrapper);
+	params = params.parseParams("anon");
+	var plugins = installedPlugins.slice(0);
+	var t,tiddler,p;
+	var configTiddlers = store.getTaggedTiddlers("systemConfig");
+	for(t=0; t<configTiddlers.length; t++) {
+		tiddler = configTiddlers[t];
+		if(plugins.findByField("title",tiddler.title) == null) {
+			p = getPluginInfo(tiddler);
+			p.executed = false;
+			p.log.splice(0,0,this.skippedText);
+			plugins.push(p);
+		}
+	}
+	for(t=0; t<plugins.length; t++) {
+		p = plugins[t];
+		p.size = p.tiddler.text ? p.tiddler.text.length : 0;
+		p.forced = p.tiddler.isTagged("systemConfigForce");
+		p.disabled = p.tiddler.isTagged("systemConfigDisable");
+		p.Selected = selectedRows.indexOf(plugins[t].title) != -1;
+		p.desc = store.getTiddlerSlice(p.tiddler.title,"Description");
+	}
+	if(plugins.length == 0) {
+		createTiddlyElement(listWrapper,"em",null,null,this.noPluginText);
+		wizard.setButtons([]);
+	} else {
+		var listView = ListView.create(listWrapper,plugins,this.listViewTemplate,this.onSelectCommand);
+		wizard.setValue("listView",listView);
+		wizard.setButtons([
+				{caption: config.macros.plugins.removeLabel, tooltip: config.macros.plugins.removePrompt, onClick: config.macros.plugins.doRemoveTag},
+				{caption: config.macros.plugins.deleteLabel, tooltip: config.macros.plugins.deletePrompt, onClick: config.macros.plugins.doDelete}
+			]);
+	}
+};
+
+config.macros.plugins.doRemoveTag = function(e)
+{
+	var wizard = new Wizard(this);
+	var listView = wizard.getValue("listView");
+	var rowNames = ListView.getSelectedRows(listView);
+	if(rowNames.length == 0) {
+		alert(config.messages.nothingSelected);
+	} else {
+		for(var t=0; t<rowNames.length; t++)
+			store.setTiddlerTag(rowNames[t],false,"systemConfig");
+	}
+};
+
+config.macros.plugins.doDelete = function(e)
+{
+	var wizard = new Wizard(this);
+	var listView = wizard.getValue("listView");
+	var rowNames = ListView.getSelectedRows(listView);
+	if(rowNames.length == 0) {
+		alert(config.messages.nothingSelected);
+	} else {
+		if(confirm(config.macros.plugins.confirmDeleteText.format([rowNames.join(", ")]))) {
+			for(var t=0; t<rowNames.length; t++) {
+				store.removeTiddler(rowNames[t]);
+				story.closeTiddler(rowNames[t],true);
+			}
+		}
+	}
+};
+
+//--
+//-- Message area
+//--
+
+function getMessageDiv()
+{
+	var msgArea = document.getElementById("messageArea");
+	if(!msgArea)
+		return null;
+	if(!msgArea.hasChildNodes())
+		createTiddlyButton(createTiddlyElement(msgArea,"div",null,"messageToolbar"),
+			config.messages.messageClose.text,
+			config.messages.messageClose.tooltip,
+			clearMessage);
+	msgArea.style.display = "block";
+	return createTiddlyElement(msgArea,"div");
+}
+
+function displayMessage(text,linkText)
+{
+	var e = getMessageDiv();
+	if(!e) {
+		alert(text);
+		return;
+	}
+	if(linkText) {
+		var link = createTiddlyElement(e,"a",null,null,text);
+		link.href = linkText;
+		link.target = "_blank";
+	} else {
+		e.appendChild(document.createTextNode(text));
+	}
+}
+
+function clearMessage()
+{
+	var msgArea = document.getElementById("messageArea");
+	if(msgArea) {
+		removeChildren(msgArea);
+		msgArea.style.display = "none";
+	}
+	return false;
+}
+
+//--
+//-- Refresh mechanism
+//--
+
+config.notifyTiddlers = [
+	{name: "StyleSheetLayout", notify: refreshStyles},
+	{name: "StyleSheetColors", notify: refreshStyles},
+	{name: "StyleSheet", notify: refreshStyles},
+	{name: "StyleSheetPrint", notify: refreshStyles},
+	{name: "PageTemplate", notify: refreshPageTemplate},
+	{name: "SiteTitle", notify: refreshPageTitle},
+	{name: "SiteSubtitle", notify: refreshPageTitle},
+	{name: "ColorPalette", notify: refreshColorPalette},
+	{name: null, notify: refreshDisplay}
+];
+
+config.refreshers = {
+	link: function(e,changeList)
+		{
+		var title = e.getAttribute("tiddlyLink");
+		refreshTiddlyLink(e,title);
+		return true;
+		},
+
+	tiddler: function(e,changeList)
+		{
+		var title = e.getAttribute("tiddler");
+		var template = e.getAttribute("template");
+		if(changeList && changeList.indexOf(title) != -1 && !story.isDirty(title))
+			story.refreshTiddler(title,template,true);
+		else
+			refreshElements(e,changeList);
+		return true;
+		},
+
+	content: function(e,changeList)
+		{
+		var title = e.getAttribute("tiddler");
+		var force = e.getAttribute("force");
+		if(force != null || changeList == null || changeList.indexOf(title) != -1) {
+			removeChildren(e);
+			wikify(store.getTiddlerText(title,""),e,null,store.fetchTiddler(title));
+			return true;
+		} else
+			return false;
+		},
+
+	macro: function(e,changeList)
+		{
+		var macro = e.getAttribute("macroName");
+		var params = e.getAttribute("params");
+		if(macro)
+			macro = config.macros[macro];
+		if(macro && macro.refresh)
+			macro.refresh(e,params);
+		return true;
+		}
+};
+
+config.refresherData = {
+	styleSheet: "StyleSheet",
+	defaultStyleSheet: "StyleSheet",
+	pageTemplate: "PageTemplate",
+	defaultPageTemplate: "PageTemplate",
+	colorPalette: "ColorPalette",
+	defaultColorPalette: "ColorPalette"
+};
+
+function refreshElements(root,changeList)
+{
+	var nodes = root.childNodes;
+	for(var c=0; c<nodes.length; c++) {
+		var e = nodes[c], type = null;
+		if(e.getAttribute && (e.tagName ? e.tagName != "IFRAME" : true))
+			type = e.getAttribute("refresh");
+		var refresher = config.refreshers[type];
+		var refreshed = false;
+		if(refresher != undefined)
+			refreshed = refresher(e,changeList);
+		if(e.hasChildNodes() && !refreshed)
+			refreshElements(e,changeList);
+	}
+}
+
+function applyHtmlMacros(root,tiddler)
+{
+	var e = root.firstChild;
+	while(e) {
+		var nextChild = e.nextSibling;
+		if(e.getAttribute) {
+			var macro = e.getAttribute("macro");
+			if(macro) {
+				e.removeAttribute("macro");
+				var params = "";
+				var p = macro.indexOf(" ");
+				if(p != -1) {
+					params = macro.substr(p+1);
+					macro = macro.substr(0,p);
+				}
+				invokeMacro(e,macro,params,null,tiddler);
+			}
+		}
+		if(e.hasChildNodes())
+			applyHtmlMacros(e,tiddler);
+		e = nextChild;
+	}
+}
+
+function refreshPageTemplate(title)
+{
+	var stash = createTiddlyElement(document.body,"div");
+	stash.style.display = "none";
+	var display = story.getContainer();
+	var nodes,t;
+	if(display) {
+		nodes = display.childNodes;
+		for(t=nodes.length-1; t>=0; t--)
+			stash.appendChild(nodes[t]);
+	}
+	var wrapper = document.getElementById("contentWrapper");
+
+	var isAvailable = function(title) {
+		var s = title ? title.indexOf(config.textPrimitives.sectionSeparator) : -1;
+		if(s!=-1)
+			title = title.substr(0,s);
+		return store.tiddlerExists(title) || store.isShadowTiddler(title);
+	};
+	if(!title || !isAvailable(title))
+		title = config.refresherData.pageTemplate;
+	if(!isAvailable(title))
+		title = config.refresherData.defaultPageTemplate; //# this one is always avaialable
+	wrapper.innerHTML = store.getRecursiveTiddlerText(title,null,10);
+	applyHtmlMacros(wrapper);
+	refreshElements(wrapper);
+	display = story.getContainer();
+	removeChildren(display);
+	if(!display)
+		display = createTiddlyElement(wrapper,"div",story.containerId());
+	nodes = stash.childNodes;
+	for(t=nodes.length-1; t>=0; t--)
+		display.appendChild(nodes[t]);
+	removeNode(stash);
+}
+
+function refreshDisplay(hint)
+{
+	if(typeof hint == "string")
+		hint = [hint];
+	var e = document.getElementById("contentWrapper");
+	refreshElements(e,hint);
+	if(backstage.isPanelVisible()) {
+		e = document.getElementById("backstage");
+		refreshElements(e,hint);
+	}
+}
+
+function refreshPageTitle()
+{
+	document.title = getPageTitle();
+}
+
+function getPageTitle()
+{
+	var st = wikifyPlain("SiteTitle");
+	var ss = wikifyPlain("SiteSubtitle");
+	return st + ((st == "" || ss == "") ? "" : " - ") + ss;
+}
+
+function refreshStyles(title,doc)
+{
+	setStylesheet(title == null ? "" : store.getRecursiveTiddlerText(title,"",10),title,doc || document);
+}
+
+function refreshColorPalette(title)
+{
+	if(!startingUp)
+		refreshAll();
+}
+
+function refreshAll()
+{
+	refreshPageTemplate();
+	refreshDisplay();
+	refreshStyles("StyleSheetLayout");
+	refreshStyles("StyleSheetColors");
+	refreshStyles(config.refresherData.styleSheet);
+	refreshStyles("StyleSheetPrint");
+}
+
+//--
+//-- Options stuff
+//--
+
+config.optionHandlers = {
+	'txt': {
+		get: function(name) {return encodeCookie(config.options[name].toString());},
+		set: function(name,value) {config.options[name] = decodeCookie(value);}
+	},
+	'chk': {
+		get: function(name) {return config.options[name] ? "true" : "false";},
+		set: function(name,value) {config.options[name] = value == "true";}
+	}
+};
+
+function loadOptionsCookie()
+{
+	if(safeMode)
+		return;
+	var cookies = document.cookie.split(";");
+	for(var c=0; c<cookies.length; c++) {
+		var p = cookies[c].indexOf("=");
+		if(p != -1) {
+			var name = cookies[c].substr(0,p).trim();
+			var value = cookies[c].substr(p+1).trim();
+			var optType = name.substr(0,3);
+			if(config.optionHandlers[optType] && config.optionHandlers[optType].set)
+				config.optionHandlers[optType].set(name,value);
+		}
+	}
+}
+
+function saveOptionCookie(name)
+{
+	if(safeMode)
+		return;
+	var c = name + "=";
+	var optType = name.substr(0,3);
+	if(config.optionHandlers[optType] && config.optionHandlers[optType].get)
+		c += config.optionHandlers[optType].get(name);
+	c += "; expires=Fri, 1 Jan 2038 12:00:00 UTC; path=/";
+	document.cookie = c;
+}
+
+function removeCookie(name)
+{
+	document.cookie = name + "=; expires=Thu, 01-Jan-1970 00:00:01 UTC; path=/;";
+}
+
+function encodeCookie(s)
+{
+	return escape(convertUnicodeToHtmlEntities(s));
+}
+
+function decodeCookie(s)
+{
+	s = unescape(s);
+	var re = /&#[0-9]{1,5};/g;
+	return s.replace(re,function($0) {return String.fromCharCode(eval($0.replace(/[&#;]/g,"")));});
+}
+
+
+config.macros.option.genericCreate = function(place,type,opt,className,desc)
+{
+	var typeInfo = config.macros.option.types[type];
+	var c = document.createElement(typeInfo.elementType);
+	if(typeInfo.typeValue)
+		c.setAttribute("type",typeInfo.typeValue);
+	c[typeInfo.eventName] = typeInfo.onChange;
+	c.setAttribute("option",opt);
+	c.className = className || typeInfo.className;
+	if(config.optionsDesc[opt])
+		c.setAttribute("title",config.optionsDesc[opt]);
+	place.appendChild(c);
+	if(desc != "no")
+		createTiddlyText(place,config.optionsDesc[opt] || opt);
+	c[typeInfo.valueField] = config.options[opt];
+	return c;
+};
+
+config.macros.option.genericOnChange = function(e)
+{
+	var opt = this.getAttribute("option");
+	if(opt) {
+		var optType = opt.substr(0,3);
+		var handler = config.macros.option.types[optType];
+		if(handler.elementType && handler.valueField)
+			config.macros.option.propagateOption(opt,handler.valueField,this[handler.valueField],handler.elementType,this);
+	}
+	return true;
+};
+
+config.macros.option.types = {
+	'txt': {
+		elementType: "input",
+		valueField: "value",
+		eventName: "onchange",
+		className: "txtOptionInput",
+		create: config.macros.option.genericCreate,
+		onChange: config.macros.option.genericOnChange
+	},
+	'chk': {
+		elementType: "input",
+		valueField: "checked",
+		eventName: "onclick",
+		className: "chkOptionInput",
+		typeValue: "checkbox",
+		create: config.macros.option.genericCreate,
+		onChange: config.macros.option.genericOnChange
+	}
+};
+
+config.macros.option.propagateOption = function(opt,valueField,value,elementType,elem)
+{
+	config.options[opt] = value;
+	saveOptionCookie(opt);
+	var nodes = document.getElementsByTagName(elementType);
+	for(var t=0; t<nodes.length; t++) {
+		var optNode = nodes[t].getAttribute("option");
+		if(opt == optNode && nodes[t]!=elem)
+			nodes[t][valueField] = value;
+	}
+};
+
+config.macros.option.handler = function(place,macroName,params,wikifier,paramString)
+{
+	params = paramString.parseParams("anon",null,true,false,false);
+	var opt = (params[1] && params[1].name == "anon") ? params[1].value : getParam(params,"name",null);
+	var className = (params[2] && params[2].name == "anon") ? params[2].value : getParam(params,"class",null);
+	var desc = getParam(params,"desc","no");
+	var type = opt.substr(0,3);
+	var h = config.macros.option.types[type];
+	if(h && h.create)
+		h.create(place,type,opt,className,desc);
+};
+
+config.macros.options.handler = function(place,macroName,params,wikifier,paramString)
+{
+	params = paramString.parseParams("anon",null,true,false,false);
+	var showUnknown = getParam(params,"showUnknown","no");
+	var wizard = new Wizard();
+	wizard.createWizard(place,this.wizardTitle);
+	wizard.addStep(this.step1Title,this.step1Html);
+	var markList = wizard.getElement("markList");
+	var chkUnknown = wizard.getElement("chkUnknown");
+	chkUnknown.checked = showUnknown == "yes";
+	chkUnknown.onchange = this.onChangeUnknown;
+	var listWrapper = document.createElement("div");
+	markList.parentNode.insertBefore(listWrapper,markList);
+	wizard.setValue("listWrapper",listWrapper);
+	this.refreshOptions(listWrapper,showUnknown == "yes");
+};
+
+config.macros.options.refreshOptions = function(listWrapper,showUnknown)
+{
+	var opts = [];
+	for(var n in config.options) {
+		var opt = {};
+		opt.option = "";
+		opt.name = n;
+		opt.lowlight = !config.optionsDesc[n];
+		opt.description = opt.lowlight ? this.unknownDescription : config.optionsDesc[n];
+		if(!opt.lowlight || showUnknown)
+			opts.push(opt);
+	}
+	opts.sort(function(a,b) {return a.name.substr(3) < b.name.substr(3) ? -1 : (a.name.substr(3) == b.name.substr(3) ? 0 : +1);});
+	var listview = ListView.create(listWrapper,opts,this.listViewTemplate);
+	for(n=0; n<opts.length; n++) {
+		var type = opts[n].name.substr(0,3);
+		var h = config.macros.option.types[type];
+		if(h && h.create) {
+			h.create(opts[n].colElements['option'],type,opts[n].name,null,"no");
+		}
+	}
+};
+
+config.macros.options.onChangeUnknown = function(e)
+{
+	var wizard = new Wizard(this);
+	var listWrapper = wizard.getValue("listWrapper");
+	removeChildren(listWrapper);
+	config.macros.options.refreshOptions(listWrapper,this.checked);
+	return false;
+};
+
+//--
+//-- Saving
+//--
+
+var saveUsingSafari = false;
+
+var startSaveArea = '<div id="' + 'storeArea">'; // Split up into two so that indexOf() of this source doesn't find it
+var endSaveArea = '</d' + 'iv>';
+
+// If there are unsaved changes, force the user to confirm before exitting
+function confirmExit()
+{
+	hadConfirmExit = true;
+	if((store && store.isDirty && store.isDirty()) || (story && story.areAnyDirty && story.areAnyDirty()))
+		return config.messages.confirmExit;
+}
+
+// Give the user a chance to save changes before exitting
+function checkUnsavedChanges()
+{
+	if(store && store.isDirty && store.isDirty() && window.hadConfirmExit === false) {
+		if(confirm(config.messages.unsavedChangesWarning))
+			saveChanges();
+	}
+}
+
+function updateLanguageAttribute(s)
+{
+	if(config.locale) {
+		var mRE = /(<html(?:.*?)?)(?: xml:lang\="([a-z]+)")?(?: lang\="([a-z]+)")?>/;
+		var m = mRE.exec(s);
+		if(m) {
+			var t = m[1];
+			if(m[2])
+				t += ' xml:lang="' + config.locale + '"';
+			if(m[3])
+				t += ' lang="' + config.locale + '"';
+			t += ">";
+			s = s.substr(0,m.index) + t + s.substr(m.index+m[0].length);
+		}
+	}
+	return s;
+}
+
+function updateMarkupBlock(s,blockName,tiddlerName)
+{
+	return s.replaceChunk(
+			"<!--%0-START-->".format([blockName]),
+			"<!--%0-END-->".format([blockName]),
+			"\n" + convertUnicodeToFileFormat(store.getRecursiveTiddlerText(tiddlerName,"")) + "\n");
+}
+
+function updateOriginal(original,posDiv,localPath)
+{
+	if(!posDiv)
+		posDiv = locateStoreArea(original);
+	if(!posDiv) {
+		alert(config.messages.invalidFileError.format([localPath]));
+		return null;
+	}
+	var revised = original.substr(0,posDiv[0] + startSaveArea.length) + "\n" +
+				convertUnicodeToFileFormat(store.allTiddlersAsHtml()) + "\n" +
+				original.substr(posDiv[1]);
+	var newSiteTitle = convertUnicodeToFileFormat(getPageTitle()).htmlEncode();
+	revised = revised.replaceChunk("<title"+">","</title"+">"," " + newSiteTitle + " ");
+	revised = updateLanguageAttribute(revised);
+	revised = updateMarkupBlock(revised,"PRE-HEAD","MarkupPreHead");
+	revised = updateMarkupBlock(revised,"POST-HEAD","MarkupPostHead");
+	revised = updateMarkupBlock(revised,"PRE-BODY","MarkupPreBody");
+	revised = updateMarkupBlock(revised,"POST-SCRIPT","MarkupPostBody");
+	return revised;
+}
+
+function locateStoreArea(original)
+{
+	// Locate the storeArea div's
+	var posOpeningDiv = original.indexOf(startSaveArea);
+	var limitClosingDiv = original.indexOf("<"+"!--POST-STOREAREA--"+">");
+	if(limitClosingDiv == -1)
+		limitClosingDiv = original.indexOf("<"+"!--POST-BODY-START--"+">");
+	var posClosingDiv = original.lastIndexOf(endSaveArea,limitClosingDiv == -1 ? original.length : limitClosingDiv);
+	return (posOpeningDiv != -1 && posClosingDiv != -1) ? [posOpeningDiv,posClosingDiv] : null;
+}
+
+function autoSaveChanges(onlyIfDirty,tiddlers)
+{
+	if(config.options.chkAutoSave)
+		saveChanges(onlyIfDirty,tiddlers);
+}
+
+function loadOriginal(localPath)
+{
+	return loadFile(localPath);
+}
+
+// Save this tiddlywiki with the pending changes
+function saveChanges(onlyIfDirty,tiddlers)
+{
+	if(onlyIfDirty && !store.isDirty())
+		return;
+	clearMessage();
+	var t0 = new Date();
+	var originalPath = document.location.toString();
+	if(originalPath.substr(0,5) != "file:") {
+		alert(config.messages.notFileUrlError);
+		if(store.tiddlerExists(config.messages.saveInstructions))
+			story.displayTiddler(null,config.messages.saveInstructions);
+		return;
+	}
+	var localPath = getLocalPath(originalPath);
+	var original = loadOriginal(localPath);
+	if(original == null) {
+		alert(config.messages.cantSaveError);
+		if(store.tiddlerExists(config.messages.saveInstructions))
+			story.displayTiddler(null,config.messages.saveInstructions);
+		return;
+	}
+	var posDiv = locateStoreArea(original);
+	if(!posDiv) {
+		alert(config.messages.invalidFileError.format([localPath]));
+		return;
+	}
+	saveMain(localPath,original,posDiv);
+	if(config.options.chkSaveBackups)
+		saveBackup(localPath,original);
+	if(config.options.chkSaveEmptyTemplate)
+		saveEmpty(localPath,original,posDiv);
+	if(config.options.chkGenerateAnRssFeed && saveRss instanceof Function)
+		saveRss(localPath);
+	if(config.options.chkDisplayInstrumentation)
+		displayMessage("saveChanges " + (new Date()-t0) + " ms");
+}
+
+function saveMain(localPath,original,posDiv)
+{
+	var save;
+	try {
+		var revised = updateOriginal(original,posDiv,localPath);
+		save = saveFile(localPath,revised);
+	} catch (ex) {
+		showException(ex);
+	}
+	if(save) {
+		displayMessage(config.messages.mainSaved,"file://" + localPath);
+		store.setDirty(false);
+	} else {
+		alert(config.messages.mainFailed);
+	}
+}
+
+function saveBackup(localPath,original)
+{
+	var backupPath = getBackupPath(localPath);
+	var backup = copyFile(backupPath,localPath);
+	if(!backup)
+		backup = saveFile(backupPath,original);
+	if(backup)
+		displayMessage(config.messages.backupSaved,"file://" + backupPath);
+	else
+		alert(config.messages.backupFailed);
+}
+
+function saveEmpty(localPath,original,posDiv)
+{
+	var emptyPath,p;
+	if((p = localPath.lastIndexOf("/")) != -1)
+		emptyPath = localPath.substr(0,p) + "/";
+	else if((p = localPath.lastIndexOf("\\")) != -1)
+		emptyPath = localPath.substr(0,p) + "\\";
+	else
+		emptyPath = localPath + ".";
+	emptyPath += "empty.html";
+	var empty = original.substr(0,posDiv[0] + startSaveArea.length) + original.substr(posDiv[1]);
+	var emptySave = saveFile(emptyPath,empty);
+	if(emptySave)
+		displayMessage(config.messages.emptySaved,"file://" + emptyPath);
+	else
+		alert(config.messages.emptyFailed);
+}
+
+function getLocalPath(origPath)
+{
+	var originalPath = convertUriToUTF8(origPath,config.options.txtFileSystemCharSet);
+	// Remove any location or query part of the URL
+	var argPos = originalPath.indexOf("?");
+	if(argPos != -1)
+		originalPath = originalPath.substr(0,argPos);
+	var hashPos = originalPath.indexOf("#");
+	if(hashPos != -1)
+		originalPath = originalPath.substr(0,hashPos);
+	// Convert file://localhost/ to file:///
+	if(originalPath.indexOf("file://localhost/") == 0)
+		originalPath = "file://" + originalPath.substr(16);
+	// Convert to a native file format
+	var localPath;
+	if(originalPath.charAt(9) == ":") // pc local file
+		localPath = unescape(originalPath.substr(8)).replace(new RegExp("/","g"),"\\");
+	else if(originalPath.indexOf("file://///") == 0) // FireFox pc network file
+		localPath = "\\\\" + unescape(originalPath.substr(10)).replace(new RegExp("/","g"),"\\");
+	else if(originalPath.indexOf("file:///") == 0) // mac/unix local file
+		localPath = unescape(originalPath.substr(7));
+	else if(originalPath.indexOf("file:/") == 0) // mac/unix local file
+		localPath = unescape(originalPath.substr(5));
+	else // pc network file
+		localPath = "\\\\" + unescape(originalPath.substr(7)).replace(new RegExp("/","g"),"\\");
+	return localPath;
+}
+
+function getBackupPath(localPath,title,extension)
+{
+	var slash = "\\";
+	var dirPathPos = localPath.lastIndexOf("\\");
+	if(dirPathPos == -1) {
+		dirPathPos = localPath.lastIndexOf("/");
+		slash = "/";
+	}
+	var backupFolder = config.options.txtBackupFolder;
+	if(!backupFolder || backupFolder == "")
+		backupFolder = ".";
+	var backupPath = localPath.substr(0,dirPathPos) + slash + backupFolder + localPath.substr(dirPathPos);
+	backupPath = backupPath.substr(0,backupPath.lastIndexOf(".")) + ".";
+	if(title)
+		backupPath += title.replace(/[\\\/\*\?\":<> ]/g,"_") + ".";
+	backupPath += (new Date()).convertToYYYYMMDDHHMMSSMMM() + "." + (extension || "html");
+	return backupPath;
+}
+
+//--
+//-- RSS Saving
+//--
+
+function saveRss(localPath)
+{
+	var rssPath = localPath.substr(0,localPath.lastIndexOf(".")) + ".xml";
+	if(saveFile(rssPath,convertUnicodeToFileFormat(generateRss())))
+		displayMessage(config.messages.rssSaved,"file://" + rssPath);
+	else
+		alert(config.messages.rssFailed);
+}
+
+tiddlerToRssItem = function(tiddler,uri)
+{
+	var s = "<title" + ">" + tiddler.title.htmlEncode() + "</title" + ">\n";
+	s += "<description>" + wikifyStatic(tiddler.text,null,tiddler).htmlEncode() + "</description>\n";
+	for(var i=0; i<tiddler.tags.length; i++)
+		s += "<category>" + tiddler.tags[i] + "</category>\n";
+	s += "<link>" + uri + "#" + encodeURIComponent(String.encodeTiddlyLink(tiddler.title)) + "</link>\n";
+	s +="<pubDate>" + tiddler.modified.toGMTString() + "</pubDate>\n";
+	return s;
+};
+
+function generateRss()
+{
+	var s = [];
+	var d = new Date();
+	var u = store.getTiddlerText("SiteUrl");
+	// Assemble the header
+	s.push("<" + "?xml version=\"1.0\"?" + ">");
+	s.push("<rss version=\"2.0\">");
+	s.push("<channel>");
+	s.push("<title" + ">" + wikifyPlain("SiteTitle").htmlEncode() + "</title" + ">");
+	if(u)
+		s.push("<link>" + u.htmlEncode() + "</link>");
+	s.push("<description>" + wikifyPlain("SiteSubtitle").htmlEncode() + "</description>");
+	s.push("<language>" + config.locale + "</language>");
+	s.push("<copyright>Copyright " + d.getFullYear() + " " + config.options.txtUserName.htmlEncode() + "</copyright>");
+	s.push("<pubDate>" + d.toGMTString() + "</pubDate>");
+	s.push("<lastBuildDate>" + d.toGMTString() + "</lastBuildDate>");
+	s.push("<docs>http://blogs.law.harvard.edu/tech/rss</docs>");
+	s.push("<generator>TiddlyWiki " + formatVersion() + "</generator>");
+	// The body
+	var tiddlers = store.getTiddlers("modified","excludeLists");
+	var n = config.numRssItems > tiddlers.length ? 0 : tiddlers.length-config.numRssItems;
+	for(var i=tiddlers.length-1; i>=n; i--) {
+		s.push("<item>\n" + tiddlerToRssItem(tiddlers[i],u) + "\n</item>");
+	}
+	// And footer
+	s.push("</channel>");
+	s.push("</rss>");
+	// Save it all
+	return s.join("\n");
+}
+
+//--
+//-- Filesystem code
+//--
+
+function convertUTF8ToUnicode(u)
+{
+	return config.browser.isOpera || !window.netscape ? manualConvertUTF8ToUnicode(u) : mozConvertUTF8ToUnicode(u);
+}
+
+function manualConvertUTF8ToUnicode(utf)
+{
+	var uni = utf;
+	var src = 0;
+	var dst = 0;
+	var b1, b2, b3;
+	var c;
+	while(src < utf.length) {
+		b1 = utf.charCodeAt(src++);
+		if(b1 < 0x80) {
+			dst++;
+		} else if(b1 < 0xE0) {
+			b2 = utf.charCodeAt(src++);
+			c = String.fromCharCode(((b1 & 0x1F) << 6) | (b2 & 0x3F));
+			uni = uni.substring(0,dst++).concat(c,utf.substr(src));
+		} else {
+			b2 = utf.charCodeAt(src++);
+			b3 = utf.charCodeAt(src++);
+			c = String.fromCharCode(((b1 & 0xF) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F));
+			uni = uni.substring(0,dst++).concat(c,utf.substr(src));
+		}
+	}
+	return uni;
+}
+
+function mozConvertUTF8ToUnicode(u)
+{
+	try {
+		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+		var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+		converter.charset = "UTF-8";
+	} catch(ex) {
+		return manualConvertUTF8ToUnicode(u);
+	} // fallback
+	var s = converter.ConvertToUnicode(u);
+	var fin = converter.Finish();
+	return fin.length > 0 ? s+fin : s;
+}
+
+function convertUnicodeToFileFormat(s)
+{
+	return config.browser.isOpera || !window.netscape ? convertUnicodeToHtmlEntities(s) : mozConvertUnicodeToUTF8(s);
+}
+
+function convertUnicodeToHtmlEntities(s)
+{
+	var re = /[^\u0000-\u007F]/g;
+	return s.replace(re,function($0) {return "&#" + $0.charCodeAt(0).toString() + ";";});
+}
+
+function convertUnicodeToUTF8(s)
+{
+// return convertUnicodeToFileFormat to allow plugin migration
+	return convertUnicodeToFileFormat(s);
+}
+
+function manualConvertUnicodeToUTF8(s)
+{
+	return unescape(encodeURIComponent(s));
+}
+
+function mozConvertUnicodeToUTF8(s)
+{
+	try {
+		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+		var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+		converter.charset = "UTF-8";
+	} catch(ex) {
+		return manualConvertUnicodeToUTF8(s);
+	} // fallback
+	var u = converter.ConvertFromUnicode(s);
+	var fin = converter.Finish();
+	return fin.length > 0 ? u + fin : u;
+}
+
+function convertUriToUTF8(uri,charSet)
+{
+	if(window.netscape == undefined || charSet == undefined || charSet == "")
+		return uri;
+	try {
+		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+		var converter = Components.classes["@mozilla.org/intl/utf8converterservice;1"].getService(Components.interfaces.nsIUTF8ConverterService);
+	} catch(ex) {
+		return uri;
+	}
+	return converter.convertURISpecToUTF8(uri,charSet);
+}
+
+function copyFile(dest,source)
+{
+	return config.browser.isIE ? ieCopyFile(dest,source) : false;
+}
+
+function saveFile(fileUrl,content)
+{
+	var r = mozillaSaveFile(fileUrl,content);
+	if(!r)
+		r = ieSaveFile(fileUrl,content);
+	if(!r)
+		r = javaSaveFile(fileUrl,content);
+	return r;
+}
+
+function loadFile(fileUrl)
+{
+	var r = mozillaLoadFile(fileUrl);
+	if((r == null) || (r == false))
+		r = ieLoadFile(fileUrl);
+	if((r == null) || (r == false))
+		r = javaLoadFile(fileUrl);
+	return r;
+}
+
+function ieCreatePath(path)
+{
+	try {
+		var fso = new ActiveXObject("Scripting.FileSystemObject");
+	} catch(ex) {
+		return null;
+	}
+
+	var pos = path.lastIndexOf("\\");
+	if(pos==-1)
+		pos = path.lastIndexOf("/");
+	if(pos!=-1)
+		path = path.substring(0,pos+1);
+
+	var scan = [path];
+	var parent = fso.GetParentFolderName(path);
+	while(parent && !fso.FolderExists(parent)) {
+		scan.push(parent);
+		parent = fso.GetParentFolderName(parent);
+	}
+
+	for(i=scan.length-1;i>=0;i--) {
+		if(!fso.FolderExists(scan[i])) {
+			fso.CreateFolder(scan[i]);
+		}
+	}
+	return true;
+}
+
+// Returns null if it can't do it, false if there's an error, true if it saved OK
+function ieSaveFile(filePath,content)
+{
+	ieCreatePath(filePath);
+	try {
+		var fso = new ActiveXObject("Scripting.FileSystemObject");
+	} catch(ex) {
+		return null;
+	}
+	var file = fso.OpenTextFile(filePath,2,-1,0);
+	file.Write(content);
+	file.Close();
+	return true;
+}
+
+// Returns null if it can't do it, false if there's an error, or a string of the content if successful
+function ieLoadFile(filePath)
+{
+	try {
+		var fso = new ActiveXObject("Scripting.FileSystemObject");
+		var file = fso.OpenTextFile(filePath,1);
+		var content = file.ReadAll();
+		file.Close();
+	} catch(ex) {
+		return null;
+	}
+	return content;
+}
+
+function ieCopyFile(dest,source)
+{
+	ieCreatePath(dest);
+	try {
+		var fso = new ActiveXObject("Scripting.FileSystemObject");
+		fso.GetFile(source).Copy(dest);
+	} catch(ex) {
+		return false;
+	}
+	return true;
+}
+
+// Returns null if it can't do it, false if there's an error, true if it saved OK
+function mozillaSaveFile(filePath,content)
+{
+	if(window.Components) {
+		try {
+			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+			var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
+			file.initWithPath(filePath);
+			if(!file.exists())
+				file.create(0,0664);
+			var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
+			out.init(file,0x20|0x02,00004,null);
+			out.write(content,content.length);
+			out.flush();
+			out.close();
+			return true;
+		} catch(ex) {
+			return false;
+		}
+	}
+	return null;
+}
+
+// Returns null if it can't do it, false if there's an error, or a string of the content if successful
+function mozillaLoadFile(filePath)
+{
+	if(window.Components) {
+		try {
+			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+			var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
+			file.initWithPath(filePath);
+			if(!file.exists())
+				return null;
+			var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
+			inputStream.init(file,0x01,00004,null);
+			var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
+			sInputStream.init(inputStream);
+			var contents = sInputStream.read(sInputStream.available());
+			sInputStream.close();
+			inputStream.close();
+			return contents;
+		} catch(ex) {
+			return false;
+		}
+	}
+	return null;
+}
+
+function javaUrlToFilename(url)
+{
+	var f = "//localhost";
+	if(url.indexOf(f) == 0)
+		return url.substring(f.length);
+	var i = url.indexOf(":");
+	return i > 0 ? url.substring(i-1) : url;
+}
+
+function javaSaveFile(filePath,content)
+{
+	try {
+		if(document.applets["TiddlySaver"])
+			return document.applets["TiddlySaver"].saveFile(javaUrlToFilename(filePath),"UTF-8",content);
+	} catch(ex) {
+	}
+	try {
+		var s = new java.io.PrintStream(new java.io.FileOutputStream(javaUrlToFilename(filePath)));
+		s.print(content);
+		s.close();
+	} catch(ex) {
+		return null;
+	}
+	return true;
+}
+
+function javaLoadFile(filePath)
+{
+	try {
+		if(document.applets["TiddlySaver"])
+			return String(document.applets["TiddlySaver"].loadFile(javaUrlToFilename(filePath),"UTF-8"));
+	} catch(ex) {
+	}
+	var content = [];
+	try {
+		var r = new java.io.BufferedReader(new java.io.FileReader(javaUrlToFilename(filePath)));
+		var line;
+		while((line = r.readLine()) != null)
+			content.push(new String(line));
+		r.close();
+	} catch(ex) {
+		return null;
+	}
+	return content.join("\n");
+}
+
+//--
+//-- Server adaptor base class
+//--
+
+function AdaptorBase()
+{
+	this.host = null;
+	this.store = null;
+	return this;
+}
+
+AdaptorBase.prototype.close = function()
+{
+	return true;
+};
+
+AdaptorBase.prototype.fullHostName = function(host)
+{
+	if(!host)
+		return '';
+	host = host.trim();
+	if(!host.match(/:\/\//))
+		host = 'http://' + host;
+	if(host.substr(host.length-1) == '/')
+		host = host.substr(0,host.length-1);
+	return host;
+};
+
+AdaptorBase.minHostName = function(host)
+{
+	return host ? host.replace(/^http:\/\//,'').replace(/\/$/,'') : '';
+};
+
+AdaptorBase.prototype.setContext = function(context,userParams,callback)
+{
+	if(!context) context = {};
+	context.userParams = userParams;
+	if(callback) context.callback = callback;
+	context.adaptor = this;
+	if(!context.host)
+		context.host = this.host;
+	context.host = this.fullHostName(context.host);
+	if(!context.workspace)
+		context.workspace = this.workspace;
+	return context;
+};
+
+// Open the specified host
+AdaptorBase.prototype.openHost = function(host,context,userParams,callback)
+{
+	this.host = host;
+	context = this.setContext(context,userParams,callback);
+	context.status = true;
+	if(callback)
+		window.setTimeout(function() {context.callback(context,userParams);},10);
+	return true;
+};
+
+// Open the specified workspace
+AdaptorBase.prototype.openWorkspace = function(workspace,context,userParams,callback)
+{
+	this.workspace = workspace;
+	context = this.setContext(context,userParams,callback);
+	context.status = true;
+	if(callback)
+		window.setTimeout(function() {callback(context,userParams);},10);
+	return true;
+};
+
+//--
+//-- Server adaptor for talking to static TiddlyWiki files
+//--
+
+function FileAdaptor()
+{
+}
+
+FileAdaptor.prototype = new AdaptorBase();
+
+FileAdaptor.serverType = 'file';
+FileAdaptor.serverLabel = 'TiddlyWiki';
+
+FileAdaptor.loadTiddlyWikiCallback = function(status,context,responseText,url,xhr)
+{
+	context.status = status;
+	if(!status) {
+		context.statusText = "Error reading file";
+	} else {
+		context.adaptor.store = new TiddlyWiki();
+		if(!context.adaptor.store.importTiddlyWiki(responseText)) {
+			context.statusText = config.messages.invalidFileError.format([url]);
+			context.status = false;
+		}
+	}
+	context.complete(context,context.userParams);
+};
+
+// Get the list of workspaces on a given server
+FileAdaptor.prototype.getWorkspaceList = function(context,userParams,callback)
+{
+	context = this.setContext(context,userParams,callback);
+	context.workspaces = [{title:"(default)"}];
+	context.status = true;
+	if(callback)
+		window.setTimeout(function() {callback(context,userParams);},10);
+	return true;
+};
+
+// Gets the list of tiddlers within a given workspace
+FileAdaptor.prototype.getTiddlerList = function(context,userParams,callback,filter)
+{
+	context = this.setContext(context,userParams,callback);
+	if(!context.filter)
+		context.filter = filter;
+	context.complete = FileAdaptor.getTiddlerListComplete;
+	if(this.store) {
+		var ret = context.complete(context,context.userParams);
+	} else {
+		ret = loadRemoteFile(context.host,FileAdaptor.loadTiddlyWikiCallback,context);
+		if(typeof ret != "string")
+			ret = true;
+	}
+	return ret;
+};
+
+FileAdaptor.getTiddlerListComplete = function(context,userParams)
+{
+	if(context.status) {
+		if(context.filter) {
+			context.tiddlers = context.adaptor.store.filterTiddlers(context.filter);
+		} else {
+			context.tiddlers = [];
+			context.adaptor.store.forEachTiddler(function(title,tiddler) {context.tiddlers.push(tiddler);});
+		}
+		for(var i=0; i<context.tiddlers.length; i++) {
+			context.tiddlers[i].fields['server.type'] = FileAdaptor.serverType;
+			context.tiddlers[i].fields['server.host'] = AdaptorBase.minHostName(context.host);
+			context.tiddlers[i].fields['server.page.revision'] = context.tiddlers[i].modified.convertToYYYYMMDDHHMM();
+		}
+		context.status = true;
+	}
+	if(context.callback) {
+		window.setTimeout(function() {context.callback(context,userParams);},10);
+	}
+	return true;
+};
+
+FileAdaptor.prototype.generateTiddlerInfo = function(tiddler)
+{
+	var info = {};
+	info.uri = tiddler.fields['server.host'] + "#" + tiddler.title;
+	return info;
+};
+
+// Retrieve a tiddler from a given workspace on a given server
+FileAdaptor.prototype.getTiddler = function(title,context,userParams,callback)
+{
+	context = this.setContext(context,userParams,callback);
+	context.title = title;
+	context.complete = FileAdaptor.getTiddlerComplete;
+	return context.adaptor.store ?
+		context.complete(context,context.userParams) :
+		loadRemoteFile(context.host,FileAdaptor.loadTiddlyWikiCallback,context);
+};
+
+FileAdaptor.getTiddlerComplete = function(context,userParams)
+{
+	var t = context.adaptor.store.fetchTiddler(context.title);
+	t.fields['server.type'] = FileAdaptor.serverType;
+	t.fields['server.host'] = AdaptorBase.minHostName(context.host);
+	t.fields['server.page.revision'] = t.modified.convertToYYYYMMDDHHMM();
+	context.tiddler = t;
+	context.status = true;
+	if(context.allowSynchronous) {
+		context.isSynchronous = true;
+		context.callback(context,userParams);
+	} else {
+		window.setTimeout(function() {context.callback(context,userParams);},10);
+	}
+	return true;
+};
+
+FileAdaptor.prototype.close = function()
+{
+	delete this.store;
+	this.store = null;
+};
+
+config.adaptors[FileAdaptor.serverType] = FileAdaptor;
+
+config.defaultAdaptor = FileAdaptor.serverType;
+
+//--
+//-- Remote HTTP requests
+//--
+
+function loadRemoteFile(url,callback,params)
+{
+	return httpReq("GET",url,callback,params);
+}
+
+function httpReq(type,url,callback,params,headers,data,contentType,username,password,allowCache)
+{
+	var x = null;
+	try {
+		x = new XMLHttpRequest(); //# Modern
+	} catch(ex) {
+		try {
+			x = new ActiveXObject("Msxml2.XMLHTTP"); //# IE 6
+		} catch(ex2) {
+		}
+	}
+	if(!x)
+		return "Can't create XMLHttpRequest object";
+	x.onreadystatechange = function() {
+		try {
+			var status = x.status;
+		} catch(ex) {
+			status = false;
+		}
+		if(x.readyState == 4 && callback && (status !== undefined)) {
+			if([0, 200, 201, 204, 207].contains(status))
+				callback(true,params,x.responseText,url,x);
+			else
+				callback(false,params,null,url,x);
+			x.onreadystatechange = function(){};
+			x = null;
+		}
+	};
+	if(window.Components && window.netscape && window.netscape.security && document.location.protocol.indexOf("http") == -1)
+		window.netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
+	try {
+		if(!allowCache)
+			url = url + (url.indexOf("?") < 0 ? "?" : "&") + "nocache=" + Math.random();
+		x.open(type,url,true,username,password);
+		if(data)
+			x.setRequestHeader("Content-Type", contentType || "application/x-www-form-urlencoded");
+		if(x.overrideMimeType)
+			x.setRequestHeader("Connection", "close");
+		if(headers) {
+			for(var n in headers)
+				x.setRequestHeader(n,headers[n]);
+		}
+		x.setRequestHeader("X-Requested-With", "TiddlyWiki " + formatVersion());
+		x.send(data);
+	} catch(ex) {
+		return exceptionText(ex);
+	}
+	return x;
+}
+
+// included for compatibility
+function getXMLHttpRequest()
+{
+	try {
+		var x = new XMLHttpRequest(); // Modern
+	} catch(ex) {
+		try {
+			x = new ActiveXObject("Msxml2.XMLHTTP"); // IE 6
+		} catch (ex2) {
+			return null;
+		}
+	}
+	return x;
+}
+
+// included for compatibility
+function doHttp(type,url,data,contentType,username,password,callback,params,headers,allowCache)
+{
+	return httpReq(type,url,callback,params,headers,data,contentType,username,password,allowCache);
+}
+
+//--
+//-- TiddlyWiki-specific utility functions
+//--
+
+function formatVersion(v)
+{
+	v = v || version;
+	return v.major + "." + v.minor + "." + v.revision + (v.beta ? " (beta " + v.beta + ")" : "");
+}
+
+function compareVersions(v1,v2)
+{
+	var a = ["major","minor","revision"];
+	for(var i = 0; i<a.length; i++) {
+		var x1 = v1[a[i]] || 0;
+		var x2 = v2[a[i]] || 0;
+		if(x1<x2)
+			return 1;
+		if(x1>x2)
+			return -1;
+	}
+	x1 = v1.beta || 9999;
+	x2 = v2.beta || 9999;
+	if(x1<x2)
+		return 1;
+	return x1 > x2 ? -1 : 0;
+}
+
+function createTiddlyButton(parent,text,tooltip,action,className,id,accessKey,attribs)
+{
+	var btn = document.createElement("a");
+	if(action) {
+		btn.onclick = action;
+		btn.setAttribute("href","javascript:;");
+	}
+	if(tooltip)
+		btn.setAttribute("title",tooltip);
+	if(text)
+		btn.appendChild(document.createTextNode(text));
+	btn.className = className || "button";
+	if(id)
+		btn.id = id;
+	if(attribs) {
+		for(var i in attribs) {
+			btn.setAttribute(i,attribs[i]);
+		}
+	}
+	if(parent)
+		parent.appendChild(btn);
+	if(accessKey)
+		btn.setAttribute("accessKey",accessKey);
+	return btn;
+}
+
+function createTiddlyLink(place,title,includeText,className,isStatic,linkedFromTiddler,noToggle)
+{
+	var text = includeText ? title : null;
+	var i = getTiddlyLinkInfo(title,className);
+	var btn = isStatic ? createExternalLink(place,store.getTiddlerText("SiteUrl",null) + "#" + title) : createTiddlyButton(place,text,i.subTitle,onClickTiddlerLink,i.classes);
+	if(isStatic)
+		btn.className += ' ' + className;
+	btn.setAttribute("refresh","link");
+	btn.setAttribute("tiddlyLink",title);
+	if(noToggle)
+		btn.setAttribute("noToggle","true");
+	if(linkedFromTiddler) {
+		var fields = linkedFromTiddler.getInheritedFields();
+		if(fields)
+			btn.setAttribute("tiddlyFields",fields);
+	}
+	return btn;
+}
+
+function refreshTiddlyLink(e,title)
+{
+	var i = getTiddlyLinkInfo(title,e.className);
+	e.className = i.classes;
+	e.title = i.subTitle;
+}
+
+function getTiddlyLinkInfo(title,currClasses)
+{
+	var classes = currClasses ? currClasses.split(" ") : [];
+	classes.pushUnique("tiddlyLink");
+	var tiddler = store.fetchTiddler(title);
+	var subTitle;
+	if(tiddler) {
+		subTitle = tiddler.getSubtitle();
+		classes.pushUnique("tiddlyLinkExisting");
+		classes.remove("tiddlyLinkNonExisting");
+		classes.remove("shadow");
+	} else {
+		classes.remove("tiddlyLinkExisting");
+		classes.pushUnique("tiddlyLinkNonExisting");
+		if(store.isShadowTiddler(title)) {
+			subTitle = config.messages.shadowedTiddlerToolTip.format([title]);
+			classes.pushUnique("shadow");
+		} else {
+			subTitle = config.messages.undefinedTiddlerToolTip.format([title]);
+			classes.remove("shadow");
+		}
+	}
+	if(typeof config.annotations[title]=="string")
+		subTitle = config.annotations[title];
+	return {classes: classes.join(" "),subTitle: subTitle};
+}
+
+function createExternalLink(place,url)
+{
+	var link = document.createElement("a");
+	link.className = "externalLink";
+	link.href = url;
+	link.title = config.messages.externalLinkTooltip.format([url]);
+	if(config.options.chkOpenInNewWindow)
+		link.target = "_blank";
+	place.appendChild(link);
+	return link;
+}
+
+// Event handler for clicking on a tiddly link
+function onClickTiddlerLink(ev)
+{
+	var e = ev || window.event;
+	var target = resolveTarget(e);
+	var link = target;
+	var title = null;
+	var fields = null;
+	var noToggle = null;
+	do {
+		title = link.getAttribute("tiddlyLink");
+		fields = link.getAttribute("tiddlyFields");
+		noToggle = link.getAttribute("noToggle");
+		link = link.parentNode;
+	} while(title == null && link != null);
+	if(!store.isShadowTiddler(title)) {
+		var f = fields ? fields.decodeHashMap() : {};
+		fields = String.encodeHashMap(merge(f,config.defaultCustomFields,true));
+	}
+	if(title) {
+		var toggling = e.metaKey || e.ctrlKey;
+		if(config.options.chkToggleLinks)
+			toggling = !toggling;
+		if(noToggle)
+			toggling = false;
+		if(store.getTiddler(title))
+			fields = null;
+		story.displayTiddler(target,title,null,true,null,fields,toggling);
+	}
+	clearMessage();
+	return false;
+}
+
+// Create a button for a tag with a popup listing all the tiddlers that it tags
+function createTagButton(place,tag,excludeTiddler,title,tooltip)
+{
+	var btn = createTiddlyButton(place,title||tag,(tooltip||config.views.wikified.tag.tooltip).format([tag]),onClickTag);
+	btn.setAttribute("tag",tag);
+	if(excludeTiddler)
+		btn.setAttribute("tiddler",excludeTiddler);
+	return btn;
+}
+
+// Event handler for clicking on a tiddler tag
+function onClickTag(ev)
+{
+	var e = ev || window.event;
+	var popup = Popup.create(this);
+	var tag = this.getAttribute("tag");
+	var title = this.getAttribute("tiddler");
+	if(popup && tag) {
+		var tagged = store.getTaggedTiddlers(tag);
+		var titles = [];
+		var li,r;
+		for(r=0;r<tagged.length;r++) {
+			if(tagged[r].title != title)
+				titles.push(tagged[r].title);
+		}
+		var lingo = config.views.wikified.tag;
+		if(titles.length > 0) {
+			var openAll = createTiddlyButton(createTiddlyElement(popup,"li"),lingo.openAllText.format([tag]),lingo.openAllTooltip,onClickTagOpenAll);
+			openAll.setAttribute("tag",tag);
+			createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
+			for(r=0; r<titles.length; r++) {
+				createTiddlyLink(createTiddlyElement(popup,"li"),titles[r],true);
+			}
+		} else {
+			createTiddlyText(createTiddlyElement(popup,"li",null,"disabled"),lingo.popupNone.format([tag]));
+		}
+		createTiddlyElement(createTiddlyElement(popup,"li",null,"listBreak"),"div");
+		var h = createTiddlyLink(createTiddlyElement(popup,"li"),tag,false);
+		createTiddlyText(h,lingo.openTag.format([tag]));
+	}
+	Popup.show();
+	e.cancelBubble = true;
+	if(e.stopPropagation) e.stopPropagation();
+	return false;
+}
+
+// Event handler for 'open all' on a tiddler popup
+function onClickTagOpenAll(ev)
+{
+	var tiddlers = store.getTaggedTiddlers(this.getAttribute("tag"));
+	story.displayTiddlers(this,tiddlers);
+	return false;
+}
+
+function onClickError(ev)
+{
+	var e = ev || window.event;
+	var popup = Popup.create(this);
+	var lines = this.getAttribute("errorText").split("\n");
+	for(var t=0; t<lines.length; t++)
+		createTiddlyElement(popup,"li",null,null,lines[t]);
+	Popup.show();
+	e.cancelBubble = true;
+	if(e.stopPropagation) e.stopPropagation();
+	return false;
+}
+
+function createTiddlyDropDown(place,onchange,options,defaultValue)
+{
+	var sel = createTiddlyElement(place,"select");
+	sel.onchange = onchange;
+	for(var t=0; t<options.length; t++) {
+		var e = createTiddlyElement(sel,"option",null,null,options[t].caption);
+		e.value = options[t].name;
+		if(options[t].name == defaultValue)
+			e.selected = true;
+	}
+	return sel;
+}
+
+function createTiddlyPopup(place,caption,tooltip,tiddler)
+{
+	if(tiddler.text) {
+		createTiddlyLink(place,caption,true);
+		var btn = createTiddlyButton(place,glyph("downArrow"),tooltip,onClickTiddlyPopup,"tiddlerPopupButton");
+		btn.tiddler = tiddler;
+	} else {
+		createTiddlyText(place,caption);
+	}
+}
+
+function onClickTiddlyPopup(ev)
+{
+	var e = ev || window.event;
+	var tiddler = this.tiddler;
+	if(tiddler.text) {
+		var popup = Popup.create(this,"div","popupTiddler");
+		wikify(tiddler.text,popup,null,tiddler);
+		Popup.show();
+	}
+	if(e) e.cancelBubble = true;
+	if(e && e.stopPropagation) e.stopPropagation();
+	return false;
+}
+
+function createTiddlyError(place,title,text)
+{
+	var btn = createTiddlyButton(place,title,null,onClickError,"errorButton");
+	if(text) btn.setAttribute("errorText",text);
+}
+
+function merge(dst,src,preserveExisting)
+{
+	for(var i in src) {
+		if(!preserveExisting || dst[i] === undefined)
+			dst[i] = src[i];
+	}
+	return dst;
+}
+
+// Returns a string containing the description of an exception, optionally prepended by a message
+function exceptionText(e,message)
+{
+	var s = e.description || e.toString();
+	return message ? "%0:\n%1".format([message,s]) : s;
+}
+
+// Displays an alert of an exception description with optional message
+function showException(e,message)
+{
+	alert(exceptionText(e,message));
+}
+
+function alertAndThrow(m)
+{
+	alert(m);
+	throw(m);
+}
+
+function glyph(name)
+{
+	var g = config.glyphs;
+	var b = g.currBrowser;
+	if(b == null) {
+		b = 0;
+		while(!g.browsers[b]() && b < g.browsers.length-1)
+			b++;
+		g.currBrowser = b;
+	}
+	if(!g.codes[name])
+		return "";
+	return g.codes[name][b];
+}
+
+if(!window.console) {
+	console = {tiddlywiki:true,log:function(message) {displayMessage(message);}};
+}
+
+//-
+//- Animation engine
+//-
+
+function Animator()
+{
+	this.running = 0; // Incremented at start of each animation, decremented afterwards. If zero, the interval timer is disabled
+	this.timerID = 0; // ID of the timer used for animating
+	this.animations = []; // List of animations in progress
+	return this;
+}
+
+// Start animation engine
+Animator.prototype.startAnimating = function() //# Variable number of arguments
+{
+	for(var t=0; t<arguments.length; t++)
+		this.animations.push(arguments[t]);
+	if(this.running == 0) {
+		var me = this;
+		this.timerID = window.setInterval(function() {me.doAnimate(me);},10);
+	}
+	this.running += arguments.length;
+};
+
+// Perform an animation engine tick, calling each of the known animation modules
+Animator.prototype.doAnimate = function(me)
+{
+	var a = 0;
+	while(a < me.animations.length) {
+		var animation = me.animations[a];
+		if(animation.tick()) {
+			a++;
+		} else {
+			me.animations.splice(a,1);
+			if(--me.running == 0)
+				window.clearInterval(me.timerID);
+		}
+	}
+};
+
+Animator.slowInSlowOut = function(progress)
+{
+	return(1-((Math.cos(progress * Math.PI)+1)/2));
+};
+
+//--
+//-- Morpher animation
+//--
+
+// Animate a set of properties of an element
+function Morpher(element,duration,properties,callback)
+{
+	this.element = element;
+	this.duration = duration;
+	this.properties = properties;
+	this.startTime = new Date();
+	this.endTime = Number(this.startTime) + duration;
+	this.callback = callback;
+	this.tick();
+	return this;
+}
+
+Morpher.prototype.assignStyle = function(element,style,value)
+{
+	switch(style) {
+	case "-tw-vertScroll":
+		window.scrollTo(findScrollX(),value);
+		break;
+	case "-tw-horizScroll":
+		window.scrollTo(value,findScrollY());
+		break;
+	default:
+		element.style[style] = value;
+		break;
+	}
+};
+
+Morpher.prototype.stop = function()
+{
+	for(var t=0; t<this.properties.length; t++) {
+		var p = this.properties[t];
+		if(p.atEnd !== undefined) {
+			this.assignStyle(this.element,p.style,p.atEnd);
+		}
+	}
+	if(this.callback)
+		this.callback(this.element,this.properties);
+};
+
+Morpher.prototype.tick = function()
+{
+	var currTime = Number(new Date());
+	var progress = Animator.slowInSlowOut(Math.min(1,(currTime-this.startTime)/this.duration));
+	for(var t=0; t<this.properties.length; t++) {
+		var p = this.properties[t];
+		if(p.start !== undefined && p.end !== undefined) {
+			var template = p.template || "%0";
+			switch(p.format) {
+			case undefined:
+			case "style":
+				var v = p.start + (p.end-p.start) * progress;
+				this.assignStyle(this.element,p.style,template.format([v]));
+				break;
+			case "color":
+				break;
+			}
+		}
+	}
+	if(currTime >= this.endTime) {
+		this.stop();
+		return false;
+	}
+	return true;
+};
+
+//--
+//-- Zoomer animation
+//--
+
+function Zoomer(text,startElement,targetElement,unused)
+{
+	var e = createTiddlyElement(document.body,"div",null,"zoomer");
+	createTiddlyElement(e,"div",null,null,text);
+	var winWidth = findWindowWidth();
+	var winHeight = findWindowHeight();
+	var p = [
+		{style: 'left', start: findPosX(startElement), end: findPosX(targetElement), template: '%0px'},
+		{style: 'top', start: findPosY(startElement), end: findPosY(targetElement), template: '%0px'},
+		{style: 'width', start: Math.min(startElement.scrollWidth,winWidth), end: Math.min(targetElement.scrollWidth,winWidth), template: '%0px', atEnd: 'auto'},
+		{style: 'height', start: Math.min(startElement.scrollHeight,winHeight), end: Math.min(targetElement.scrollHeight,winHeight), template: '%0px', atEnd: 'auto'},
+		{style: 'fontSize', start: 8, end: 24, template: '%0pt'}
+	];
+	var c = function(element,properties) {removeNode(element);};
+	return new Morpher(e,config.animDuration,p,c);
+}
+
+//--
+//-- Scroller animation
+//--
+
+function Scroller(targetElement)
+{
+	var p = [{style: '-tw-vertScroll', start: findScrollY(), end: ensureVisible(targetElement)}];
+	return new Morpher(targetElement,config.animDuration,p);
+}
+
+//--
+//-- Slider animation
+//--
+
+// deleteMode - "none", "all" [delete target element and it's children], [only] "children" [but not the target element]
+function Slider(element,opening,unused,deleteMode)
+{
+	element.style.overflow = 'hidden';
+	if(opening)
+		element.style.height = '0px'; // Resolves a Firefox flashing bug
+	element.style.display = 'block';
+	var left = findPosX(element);
+	var width = element.scrollWidth;
+	var height = element.scrollHeight;
+	var winWidth = findWindowWidth();
+	var p = [];
+	var c = null;
+	if(opening) {
+		p.push({style: 'height', start: 0, end: height, template: '%0px', atEnd: 'auto'});
+		p.push({style: 'opacity', start: 0, end: 1, template: '%0'});
+		p.push({style: 'filter', start: 0, end: 100, template: 'alpha(opacity:%0)'});
+	} else {
+		p.push({style: 'height', start: height, end: 0, template: '%0px'});
+		p.push({style: 'display', atEnd: 'none'});
+		p.push({style: 'opacity', start: 1, end: 0, template: '%0'});
+		p.push({style: 'filter', start: 100, end: 0, template: 'alpha(opacity:%0)'});
+		switch(deleteMode) {
+		case "all":
+			c = function(element,properties) {removeNode(element);};
+			break;
+		case "children":
+			c = function(element,properties) {removeChildren(element);};
+			break;
+		}
+	}
+	return new Morpher(element,config.animDuration,p,c);
+}
+
+//--
+//-- Popup menu
+//--
+
+var Popup = {
+	stack: [] // Array of objects with members root: and popup:
+	};
+
+Popup.create = function(root,elem,className)
+{
+	var stackPosition = this.find(root,"popup");
+	Popup.remove(stackPosition+1);
+	var popup = createTiddlyElement(document.body,elem || "ol","popup",className || "popup");
+	popup.stackPosition = stackPosition;
+	Popup.stack.push({root: root, popup: popup});
+	return popup;
+};
+
+Popup.onDocumentClick = function(ev)
+{
+	var e = ev || window.event;
+	if(e.eventPhase == undefined)
+		Popup.remove();
+	else if(e.eventPhase == Event.BUBBLING_PHASE || e.eventPhase == Event.AT_TARGET)
+		Popup.remove();
+	return true;
+};
+
+Popup.show = function(valign,halign,offset)
+{
+	var curr = Popup.stack[Popup.stack.length-1];
+	this.place(curr.root,curr.popup,valign,halign,offset);
+	addClass(curr.root,"highlight");
+	if(config.options.chkAnimate && anim && typeof Scroller == "function")
+		anim.startAnimating(new Scroller(curr.popup));
+	else
+		window.scrollTo(0,ensureVisible(curr.popup));
+};
+
+Popup.place = function(root,popup,valign,halign,offset)
+{
+	if(!offset)
+		var offset = {x:0,y:0};
+	if(popup.stackPosition >= 0 && !valign && !halign) {
+		offset.x = offset.x + root.offsetWidth;
+	} else {
+		offset.x = (halign == 'right') ? offset.x + root.offsetWidth : offset.x;
+		offset.y = (valign == 'top') ? offset.y : offset.y + root.offsetHeight;
+	}
+	var rootLeft = findPosX(root);
+	var rootTop = findPosY(root);
+	var popupLeft = rootLeft + offset.x;
+	var popupTop = rootTop + offset.y;
+	var winWidth = findWindowWidth();
+	if(popup.offsetWidth > winWidth*0.75)
+		popup.style.width = winWidth*0.75 + "px";
+	var popupWidth = popup.offsetWidth;
+	var scrollWidth = winWidth - document.body.offsetWidth;
+	if(popupLeft + popupWidth > winWidth - scrollWidth - 1) {
+		if(halign == 'right')
+			popupLeft = popupLeft - root.offsetWidth - popupWidth;
+		else
+			popupLeft = winWidth - popupWidth - scrollWidth - 1;
+	}
+	popup.style.left = popupLeft + "px";
+	popup.style.top = popupTop + "px";
+	popup.style.display = "block";
+};
+
+Popup.find = function(e)
+{
+	var pos = -1;
+	for (var t=this.stack.length-1; t>=0; t--) {
+		if(isDescendant(e,this.stack[t].popup))
+			pos = t;
+	}
+	return pos;
+};
+
+Popup.remove = function(pos)
+{
+	if(!pos) var pos = 0;
+	if(Popup.stack.length > pos) {
+		Popup.removeFrom(pos);
+	}
+};
+
+Popup.removeFrom = function(from)
+{
+	for(var t=Popup.stack.length-1; t>=from; t--) {
+		var p = Popup.stack[t];
+		removeClass(p.root,"highlight");
+		removeNode(p.popup);
+	}
+	Popup.stack = Popup.stack.slice(0,from);
+};
+
+//--
+//-- Wizard support
+//--
+
+function Wizard(elem)
+{
+	if(elem) {
+		this.formElem = findRelated(elem,"wizard","className");
+		this.bodyElem = findRelated(this.formElem.firstChild,"wizardBody","className","nextSibling");
+		this.footElem = findRelated(this.formElem.firstChild,"wizardFooter","className","nextSibling");
+	} else {
+		this.formElem = null;
+		this.bodyElem = null;
+		this.footElem = null;
+	}
+}
+
+Wizard.prototype.setValue = function(name,value)
+{
+	if(this.formElem)
+		this.formElem[name] = value;
+};
+
+Wizard.prototype.getValue = function(name)
+{
+	return this.formElem ? this.formElem[name] : null;
+};
+
+Wizard.prototype.createWizard = function(place,title)
+{
+	this.formElem = createTiddlyElement(place,"form",null,"wizard");
+	createTiddlyElement(this.formElem,"h1",null,null,title);
+	this.bodyElem = createTiddlyElement(this.formElem,"div",null,"wizardBody");
+	this.footElem = createTiddlyElement(this.formElem,"div",null,"wizardFooter");
+};
+
+Wizard.prototype.clear = function()
+{
+	removeChildren(this.bodyElem);
+};
+
+Wizard.prototype.setButtons = function(buttonInfo,status)
+{
+	removeChildren(this.footElem);
+	for(var t=0; t<buttonInfo.length; t++) {
+		createTiddlyButton(this.footElem,buttonInfo[t].caption,buttonInfo[t].tooltip,buttonInfo[t].onClick);
+		insertSpacer(this.footElem);
+		}
+	if(typeof status == "string") {
+		createTiddlyElement(this.footElem,"span",null,"status",status);
+	}
+};
+
+Wizard.prototype.addStep = function(stepTitle,html)
+{
+	removeChildren(this.bodyElem);
+	var w = createTiddlyElement(this.bodyElem,"div");
+	createTiddlyElement(w,"h2",null,null,stepTitle);
+	var step = createTiddlyElement(w,"div",null,"wizardStep");
+	step.innerHTML = html;
+	applyHtmlMacros(step,tiddler);
+};
+
+Wizard.prototype.getElement = function(name)
+{
+	return this.formElem.elements[name];
+};
+
+//--
+//-- ListView gadget
+//--
+
+var ListView = {};
+
+// Create a listview
+ListView.create = function(place,listObject,listTemplate,callback,className)
+{
+	var table = createTiddlyElement(place,"table",null,className || "listView twtable");
+	var thead = createTiddlyElement(table,"thead");
+	var r = createTiddlyElement(thead,"tr");
+	for(var t=0; t<listTemplate.columns.length; t++) {
+		var columnTemplate = listTemplate.columns[t];
+		var c = createTiddlyElement(r,"th");
+		var colType = ListView.columnTypes[columnTemplate.type];
+		if(colType && colType.createHeader) {
+			colType.createHeader(c,columnTemplate,t);
+			if(columnTemplate.className)
+				addClass(c,columnTemplate.className);
+		}
+	}
+	var tbody = createTiddlyElement(table,"tbody");
+	for(var rc=0; rc<listObject.length; rc++) {
+		var rowObject = listObject[rc];
+		r = createTiddlyElement(tbody,"tr");
+		for(c=0; c<listTemplate.rowClasses.length; c++) {
+			if(rowObject[listTemplate.rowClasses[c].field])
+				addClass(r,listTemplate.rowClasses[c].className);
+		}
+		rowObject.rowElement = r;
+		rowObject.colElements = {};
+		for(var cc=0; cc<listTemplate.columns.length; cc++) {
+			c = createTiddlyElement(r,"td");
+			columnTemplate = listTemplate.columns[cc];
+			var field = columnTemplate.field;
+			colType = ListView.columnTypes[columnTemplate.type];
+			if(colType && colType.createItem) {
+				colType.createItem(c,rowObject,field,columnTemplate,cc,rc);
+				if(columnTemplate.className)
+					addClass(c,columnTemplate.className);
+			}
+			rowObject.colElements[field] = c;
+		}
+	}
+	if(callback && listTemplate.actions)
+		createTiddlyDropDown(place,ListView.getCommandHandler(callback),listTemplate.actions);
+	if(callback && listTemplate.buttons) {
+		for(t=0; t<listTemplate.buttons.length; t++) {
+			var a = listTemplate.buttons[t];
+			if(a && a.name != "")
+				createTiddlyButton(place,a.caption,null,ListView.getCommandHandler(callback,a.name,a.allowEmptySelection));
+		}
+	}
+	return table;
+};
+
+ListView.getCommandHandler = function(callback,name,allowEmptySelection)
+{
+	return function(e) {
+		var view = findRelated(this,"TABLE",null,"previousSibling");
+		var tiddlers = [];
+		ListView.forEachSelector(view,function(e,rowName) {
+					if(e.checked)
+						tiddlers.push(rowName);
+					});
+		if(tiddlers.length == 0 && !allowEmptySelection) {
+			alert(config.messages.nothingSelected);
+		} else {
+			if(this.nodeName.toLowerCase() == "select") {
+				callback(view,this.value,tiddlers);
+				this.selectedIndex = 0;
+			} else {
+				callback(view,name,tiddlers);
+			}
+		}
+	};
+};
+
+// Invoke a callback for each selector checkbox in the listview
+ListView.forEachSelector = function(view,callback)
+{
+	var checkboxes = view.getElementsByTagName("input");
+	var hadOne = false;
+	for(var t=0; t<checkboxes.length; t++) {
+		var cb = checkboxes[t];
+		if(cb.getAttribute("type") == "checkbox") {
+			var rn = cb.getAttribute("rowName");
+			if(rn) {
+				callback(cb,rn);
+				hadOne = true;
+			}
+		}
+	}
+	return hadOne;
+};
+
+ListView.getSelectedRows = function(view)
+{
+	var rowNames = [];
+	ListView.forEachSelector(view,function(e,rowName) {
+				if(e.checked)
+					rowNames.push(rowName);
+				});
+	return rowNames;
+};
+
+ListView.columnTypes = {};
+
+ListView.columnTypes.String = {
+	createHeader: function(place,columnTemplate,col)
+		{
+			createTiddlyText(place,columnTemplate.title);
+		},
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var v = listObject[field];
+			if(v != undefined)
+				createTiddlyText(place,v);
+		}
+};
+
+ListView.columnTypes.WikiText = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var v = listObject[field];
+			if(v != undefined)
+				wikify(v,place,null,null);
+		}
+};
+
+ListView.columnTypes.Tiddler = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var v = listObject[field];
+			if(v != undefined && v.title)
+				createTiddlyPopup(place,v.title,config.messages.listView.tiddlerTooltip,v);
+		}
+};
+
+ListView.columnTypes.Size = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var v = listObject[field];
+			if(v != undefined) {
+				var t = 0;
+				while(t<config.messages.sizeTemplates.length-1 && v<config.messages.sizeTemplates[t].unit)
+					t++;
+				createTiddlyText(place,config.messages.sizeTemplates[t].template.format([Math.round(v/config.messages.sizeTemplates[t].unit)]));
+			}
+		}
+};
+
+ListView.columnTypes.Link = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var v = listObject[field];
+			var c = columnTemplate.text;
+			if(v != undefined)
+				createTiddlyText(createExternalLink(place,v),c || v);
+		}
+};
+
+ListView.columnTypes.Date = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var v = listObject[field];
+			if(v != undefined)
+				createTiddlyText(place,v.formatString(columnTemplate.dateFormat));
+		}
+};
+
+ListView.columnTypes.StringList = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var v = listObject[field];
+			if(v != undefined) {
+				for(var t=0; t<v.length; t++) {
+					createTiddlyText(place,v[t]);
+					createTiddlyElement(place,"br");
+				}
+			}
+		}
+};
+
+ListView.columnTypes.Selector = {
+	createHeader: function(place,columnTemplate,col)
+		{
+			createTiddlyCheckbox(place,null,false,this.onHeaderChange);
+		},
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var e = createTiddlyCheckbox(place,null,listObject[field],null);
+			e.setAttribute("rowName",listObject[columnTemplate.rowName]);
+		},
+	onHeaderChange: function(e)
+		{
+			var state = this.checked;
+			var view = findRelated(this,"TABLE");
+			if(!view)
+				return;
+			ListView.forEachSelector(view,function(e,rowName) {
+								e.checked = state;
+							});
+		}
+};
+
+ListView.columnTypes.Tags = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var tags = listObject[field];
+			createTiddlyText(place,String.encodeTiddlyLinkList(tags));
+		}
+};
+
+ListView.columnTypes.Boolean = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			if(listObject[field] == true)
+				createTiddlyText(place,columnTemplate.trueText);
+			if(listObject[field] == false)
+				createTiddlyText(place,columnTemplate.falseText);
+		}
+};
+
+ListView.columnTypes.TagCheckbox = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var e = createTiddlyCheckbox(place,null,listObject[field],this.onChange);
+			e.setAttribute("tiddler",listObject.title);
+			e.setAttribute("tag",columnTemplate.tag);
+		},
+	onChange : function(e)
+		{
+			var tag = this.getAttribute("tag");
+			var tiddler = this.getAttribute("tiddler");
+			store.setTiddlerTag(tiddler,this.checked,tag);
+		}
+};
+
+ListView.columnTypes.TiddlerLink = {
+	createHeader: ListView.columnTypes.String.createHeader,
+	createItem: function(place,listObject,field,columnTemplate,col,row)
+		{
+			var v = listObject[field];
+			if(v != undefined) {
+				var link = createTiddlyLink(place,listObject[columnTemplate.tiddlerLink],false,null);
+				createTiddlyText(link,listObject[field]);
+			}
+		}
+};
+
+//--
+//-- Augmented methods for the JavaScript Number(), Array(), String() and Date() objects
+//--
+
+// Clamp a number to a range
+Number.prototype.clamp = function(min,max)
+{
+	var c = this;
+	if(c < min)
+		c = min;
+	if(c > max)
+		c = max;
+	return c;
+};
+
+// Add indexOf function if browser does not support it
+if(!Array.indexOf) {
+Array.prototype.indexOf = function(item,from)
+{
+	if(!from)
+		from = 0;
+	for(var i=from; i<this.length; i++) {
+		if(this[i] === item)
+			return i;
+	}
+	return -1;
+};}
+
+// Find an entry in a given field of the members of an array
+Array.prototype.findByField = function(field,value)
+{
+	for(var t=0; t<this.length; t++) {
+		if(this[t][field] == value)
+			return t;
+	}
+	return null;
+};
+
+// Return whether an entry exists in an array
+Array.prototype.contains = function(item)
+{
+	return this.indexOf(item) != -1;
+};
+
+// Adds, removes or toggles a particular value within an array
+//  value - value to add
+//  mode - +1 to add value, -1 to remove value, 0 to toggle it
+Array.prototype.setItem = function(value,mode)
+{
+	var p = this.indexOf(value);
+	if(mode == 0)
+		mode = (p == -1) ? +1 : -1;
+	if(mode == +1) {
+		if(p == -1)
+			this.push(value);
+	} else if(mode == -1) {
+		if(p != -1)
+			this.splice(p,1);
+	}
+};
+
+// Return whether one of a list of values exists in an array
+Array.prototype.containsAny = function(items)
+{
+	for(var i=0; i<items.length; i++) {
+		if(this.indexOf(items[i]) != -1)
+			return true;
+	}
+	return false;
+};
+
+// Return whether all of a list of values exists in an array
+Array.prototype.containsAll = function(items)
+{
+	for(var i = 0; i<items.length; i++) {
+		if(this.indexOf(items[i]) == -1)
+			return false;
+	}
+	return true;
+};
+
+// Push a new value into an array only if it is not already present in the array. If the optional unique parameter is false, it reverts to a normal push
+Array.prototype.pushUnique = function(item,unique)
+{
+	if(unique === false) {
+		this.push(item);
+	} else {
+		if(this.indexOf(item) == -1)
+			this.push(item);
+	}
+};
+
+Array.prototype.remove = function(item)
+{
+	var p = this.indexOf(item);
+	if(p != -1)
+		this.splice(p,1);
+};
+
+if(!Array.prototype.map) {
+Array.prototype.map = function(fn,thisObj)
+{
+	var scope = thisObj || window;
+	var a = [];
+	for(var i=0, j=this.length; i < j; ++i) {
+		a.push(fn.call(scope,this[i],i,this));
+	}
+	return a;
+};}
+
+// Get characters from the right end of a string
+String.prototype.right = function(n)
+{
+	return n < this.length ? this.slice(this.length-n) : this;
+};
+
+// Trim whitespace from both ends of a string
+String.prototype.trim = function()
+{
+	return this.replace(/^\s*|\s*$/g,"");
+};
+
+// Convert a string from a CSS style property name to a JavaScript style name ("background-color" -> "backgroundColor")
+String.prototype.unDash = function()
+{
+	var s = this.split("-");
+	if(s.length > 1) {
+		for(var t=1; t<s.length; t++)
+			s[t] = s[t].substr(0,1).toUpperCase() + s[t].substr(1);
+	}
+	return s.join("");
+};
+
+// Substitute substrings from an array into a format string that includes '%1'-type specifiers
+String.prototype.format = function(substrings)
+{
+	var subRegExp = /(?:%(\d+))/mg;
+	var currPos = 0;
+	var r = [];
+	do {
+		var match = subRegExp.exec(this);
+		if(match && match[1]) {
+			if(match.index > currPos)
+				r.push(this.substring(currPos,match.index));
+			r.push(substrings[parseInt(match[1])]);
+			currPos = subRegExp.lastIndex;
+		}
+	} while(match);
+	if(currPos < this.length)
+		r.push(this.substring(currPos,this.length));
+	return r.join("");
+};
+
+// Escape any special RegExp characters with that character preceded by a backslash
+String.prototype.escapeRegExp = function()
+{
+	var s = "\\^$*+?()=!|,{}[].";
+	var c = this;
+	for(var t=0; t<s.length; t++)
+		c = c.replace(new RegExp("\\" + s.substr(t,1),"g"),"\\" + s.substr(t,1));
+	return c;
+};
+
+// Convert "\" to "\s", newlines to "\n" (and remove carriage returns)
+String.prototype.escapeLineBreaks = function()
+{
+	return this.replace(/\\/mg,"\\s").replace(/\n/mg,"\\n").replace(/\r/mg,"");
+};
+
+// Convert "\n" to newlines, "\b" to " ", "\s" to "\" (and remove carriage returns)
+String.prototype.unescapeLineBreaks = function()
+{
+	return this.replace(/\\n/mg,"\n").replace(/\\b/mg," ").replace(/\\s/mg,"\\").replace(/\r/mg,"");
+};
+
+// Convert & to "&amp;", < to "&lt;", > to "&gt;" and " to "&quot;"
+String.prototype.htmlEncode = function()
+{
+	return this.replace(/&/mg,"&amp;").replace(/</mg,"&lt;").replace(/>/mg,"&gt;").replace(/\"/mg,"&quot;");
+};
+
+// Convert "&amp;" to &, "&lt;" to <, "&gt;" to > and "&quot;" to "
+String.prototype.htmlDecode = function()
+{
+	return this.replace(/&lt;/mg,"<").replace(/&gt;/mg,">").replace(/&quot;/mg,"\"").replace(/&amp;/mg,"&");
+};
+
+// Convert a string to it's JSON representation by encoding control characters, double quotes and backslash. See json.org
+String.prototype.toJSONString = function()
+{
+	var m = {
+		'\b': '\\b',
+		'\f': '\\f',
+		'\n': '\\n',
+		'\r': '\\r',
+		'\t': '\\t',
+		'"' : '\\"',
+		'\\': '\\\\'
+		};
+	var replaceFn = function(a,b) {
+		var c = m[b];
+		if(c)
+			return c;
+		c = b.charCodeAt();
+		return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
+		};
+	if(/["\\\x00-\x1f]/.test(this))
+		return '"' + this.replace(/([\x00-\x1f\\"])/g,replaceFn) + '"';
+	return '"' + this + '"';
+};
+
+// Parse a space-separated string of name:value parameters
+// The result is an array of objects:
+//   result[0] = object with a member for each parameter name, value of that member being an array of values
+//   result[1..n] = one object for each parameter, with 'name' and 'value' members
+String.prototype.parseParams = function(defaultName,defaultValue,allowEval,noNames,cascadeDefaults)
+{
+	var parseToken = function(match,p) {
+		var n;
+		if(match[p]) // Double quoted
+			n = match[p];
+		else if(match[p+1]) // Single quoted
+			n = match[p+1];
+		else if(match[p+2]) // Double-square-bracket quoted
+			n = match[p+2];
+		else if(match[p+3]) // Double-brace quoted
+			try {
+				n = match[p+3];
+				if(allowEval)
+					n = window.eval(n);
+			} catch(ex) {
+				throw "Unable to evaluate {{" + match[p+3] + "}}: " + exceptionText(ex);
+			}
+		else if(match[p+4]) // Unquoted
+			n = match[p+4];
+		else if(match[p+5]) // empty quote
+			n = "";
+		return n;
+	};
+	var r = [{}];
+	var dblQuote = "(?:\"((?:(?:\\\\\")|[^\"])+)\")";
+	var sngQuote = "(?:'((?:(?:\\\\\')|[^'])+)')";
+	var dblSquare = "(?:\\[\\[((?:\\s|\\S)*?)\\]\\])";
+	var dblBrace = "(?:\\{\\{((?:\\s|\\S)*?)\\}\\})";
+	var unQuoted = noNames ? "([^\"'\\s]\\S*)" : "([^\"':\\s][^\\s:]*)";
+	var emptyQuote = "((?:\"\")|(?:''))";
+	var skipSpace = "(?:\\s*)";
+	var token = "(?:" + dblQuote + "|" + sngQuote + "|" + dblSquare + "|" + dblBrace + "|" + unQuoted + "|" + emptyQuote + ")";
+	var re = noNames ? new RegExp(token,"mg") : new RegExp(skipSpace + token + skipSpace + "(?:(\\:)" + skipSpace + token + ")?","mg");
+	var params = [];
+	do {
+		var match = re.exec(this);
+		if(match) {
+			var n = parseToken(match,1);
+			if(noNames) {
+				r.push({name:"",value:n});
+			} else {
+				var v = parseToken(match,8);
+				if(v == null && defaultName) {
+					v = n;
+					n = defaultName;
+				} else if(v == null && defaultValue) {
+					v = defaultValue;
+				}
+				r.push({name:n,value:v});
+				if(cascadeDefaults) {
+					defaultName = n;
+					defaultValue = v;
+				}
+			}
+		}
+	} while(match);
+	// Summarise parameters into first element
+	for(var t=1; t<r.length; t++) {
+		if(r[0][r[t].name])
+			r[0][r[t].name].push(r[t].value);
+		else
+			r[0][r[t].name] = [r[t].value];
+	}
+	return r;
+};
+
+// Process a string list of macro parameters into an array. Parameters can be quoted with "", '',
+// [[]], {{ }} or left unquoted (and therefore space-separated). Double-braces {{}} results in
+// an *evaluated* parameter: e.g. {{config.options.txtUserName}} results in the current user's name.
+String.prototype.readMacroParams = function()
+{
+	var p = this.parseParams("list",null,true,true);
+	var n = [];
+	for(var t=1; t<p.length; t++)
+		n.push(p[t].value);
+	return n;
+};
+
+// Process a string list of unique tiddler names into an array. Tiddler names that have spaces in them must be [[bracketed]]
+String.prototype.readBracketedList = function(unique)
+{
+	var p = this.parseParams("list",null,false,true);
+	var n = [];
+	for(var t=1; t<p.length; t++) {
+		if(p[t].value)
+			n.pushUnique(p[t].value,unique);
+	}
+	return n;
+};
+
+// Returns array with start and end index of chunk between given start and end marker, or undefined.
+String.prototype.getChunkRange = function(start,end)
+{
+	var s = this.indexOf(start);
+	if(s != -1) {
+		s += start.length;
+		var e = this.indexOf(end,s);
+		if(e != -1)
+			return [s,e];
+	}
+};
+
+// Replace a chunk of a string given start and end markers
+String.prototype.replaceChunk = function(start,end,sub)
+{
+	var r = this.getChunkRange(start,end);
+	return r ? this.substring(0,r[0]) + sub + this.substring(r[1]) : this;
+};
+
+// Returns a chunk of a string between start and end markers, or undefined
+String.prototype.getChunk = function(start,end)
+{
+	var r = this.getChunkRange(start,end);
+	if(r)
+		return this.substring(r[0],r[1]);
+};
+
+
+// Static method to bracket a string with double square brackets if it contains a space
+String.encodeTiddlyLink = function(title)
+{
+	return title.indexOf(" ") == -1 ? title : "[[" + title + "]]";
+};
+
+// Static method to encodeTiddlyLink for every item in an array and join them with spaces
+String.encodeTiddlyLinkList = function(list)
+{
+	if(list) {
+		var results = [];
+		for(var t=0; t<list.length; t++)
+			results.push(String.encodeTiddlyLink(list[t]));
+		return results.join(" ");
+	} else {
+		return "";
+	}
+};
+
+// Convert a string as a sequence of name:"value" pairs into a hashmap
+String.prototype.decodeHashMap = function()
+{
+	var fields = this.parseParams("anon","",false);
+	var r = {};
+	for(var t=1; t<fields.length; t++)
+		r[fields[t].name] = fields[t].value;
+	return r;
+};
+
+// Static method to encode a hashmap into a name:"value"... string
+String.encodeHashMap = function(hashmap)
+{
+	var r = [];
+	for(var t in hashmap)
+		r.push(t + ':"' + hashmap[t] + '"');
+	return r.join(" ");
+};
+
+// Static method to left-pad a string with 0s to a certain width
+String.zeroPad = function(n,d)
+{
+	var s = n.toString();
+	if(s.length < d)
+		s = "000000000000000000000000000".substr(0,d-s.length) + s;
+	return s;
+};
+
+String.prototype.startsWith = function(prefix)
+{
+	return !prefix || this.substring(0,prefix.length) == prefix;
+};
+
+// Returns the first value of the given named parameter.
+function getParam(params,name,defaultValue)
+{
+	if(!params)
+		return defaultValue;
+	var p = params[0][name];
+	return p ? p[0] : defaultValue;
+}
+
+// Returns the first value of the given boolean named parameter.
+function getFlag(params,name,defaultValue)
+{
+	return !!getParam(params,name,defaultValue);
+}
+
+// Substitute date components into a string
+Date.prototype.formatString = function(template)
+{
+	var t = template.replace(/0hh12/g,String.zeroPad(this.getHours12(),2));
+	t = t.replace(/hh12/g,this.getHours12());
+	t = t.replace(/0hh/g,String.zeroPad(this.getHours(),2));
+	t = t.replace(/hh/g,this.getHours());
+	t = t.replace(/mmm/g,config.messages.dates.shortMonths[this.getMonth()]);
+	t = t.replace(/0mm/g,String.zeroPad(this.getMinutes(),2));
+	t = t.replace(/mm/g,this.getMinutes());
+	t = t.replace(/0ss/g,String.zeroPad(this.getSeconds(),2));
+	t = t.replace(/ss/g,this.getSeconds());
+	t = t.replace(/[ap]m/g,this.getAmPm().toLowerCase());
+	t = t.replace(/[AP]M/g,this.getAmPm().toUpperCase());
+	t = t.replace(/wYYYY/g,this.getYearForWeekNo());
+	t = t.replace(/wYY/g,String.zeroPad(this.getYearForWeekNo()-2000,2));
+	t = t.replace(/YYYY/g,this.getFullYear());
+	t = t.replace(/YY/g,String.zeroPad(this.getFullYear()-2000,2));
+	t = t.replace(/MMM/g,config.messages.dates.months[this.getMonth()]);
+	t = t.replace(/0MM/g,String.zeroPad(this.getMonth()+1,2));
+	t = t.replace(/MM/g,this.getMonth()+1);
+	t = t.replace(/0WW/g,String.zeroPad(this.getWeek(),2));
+	t = t.replace(/WW/g,this.getWeek());
+	t = t.replace(/DDD/g,config.messages.dates.days[this.getDay()]);
+	t = t.replace(/ddd/g,config.messages.dates.shortDays[this.getDay()]);
+	t = t.replace(/0DD/g,String.zeroPad(this.getDate(),2));
+	t = t.replace(/DDth/g,this.getDate()+this.daySuffix());
+	t = t.replace(/DD/g,this.getDate());
+	var tz = this.getTimezoneOffset();
+	var atz = Math.abs(tz);
+	t = t.replace(/TZD/g,(tz < 0 ? '+' : '-') + String.zeroPad(Math.floor(atz / 60),2) + ':' + String.zeroPad(atz % 60,2));
+	t = t.replace(/\\/g,"");
+	return t;
+};
+
+Date.prototype.getWeek = function()
+{
+	var dt = new Date(this.getTime());
+	var d = dt.getDay();
+	if(d==0) d=7;// JavaScript Sun=0, ISO Sun=7
+	dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week to calculate weekNo
+	var n = Math.floor((dt.getTime()-new Date(dt.getFullYear(),0,1)+3600000)/86400000);
+	return Math.floor(n/7)+1;
+};
+
+Date.prototype.getYearForWeekNo = function()
+{
+	var dt = new Date(this.getTime());
+	var d = dt.getDay();
+	if(d==0) d=7;// JavaScript Sun=0, ISO Sun=7
+	dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week
+	return dt.getFullYear();
+};
+
+Date.prototype.getHours12 = function()
+{
+	var h = this.getHours();
+	return h > 12 ? h-12 : ( h > 0 ? h : 12 );
+};
+
+Date.prototype.getAmPm = function()
+{
+	return this.getHours() >= 12 ? config.messages.dates.pm : config.messages.dates.am;
+};
+
+Date.prototype.daySuffix = function()
+{
+	return config.messages.dates.daySuffixes[this.getDate()-1];
+};
+
+// Convert a date to local YYYYMMDDHHMM string format
+Date.prototype.convertToLocalYYYYMMDDHHMM = function()
+{
+	return this.getFullYear() + String.zeroPad(this.getMonth()+1,2) + String.zeroPad(this.getDate(),2) + String.zeroPad(this.getHours(),2) + String.zeroPad(this.getMinutes(),2);
+};
+
+// Convert a date to UTC YYYYMMDDHHMM string format
+Date.prototype.convertToYYYYMMDDHHMM = function()
+{
+	return this.getUTCFullYear() + String.zeroPad(this.getUTCMonth()+1,2) + String.zeroPad(this.getUTCDate(),2) + String.zeroPad(this.getUTCHours(),2) + String.zeroPad(this.getUTCMinutes(),2);
+};
+
+// Convert a date to UTC YYYYMMDD.HHMMSSMMM string format
+Date.prototype.convertToYYYYMMDDHHMMSSMMM = function()
+{
+	return this.getUTCFullYear() + String.zeroPad(this.getUTCMonth()+1,2) + String.zeroPad(this.getUTCDate(),2) + "." + String.zeroPad(this.getUTCHours(),2) + String.zeroPad(this.getUTCMinutes(),2) + String.zeroPad(this.getUTCSeconds(),2) + String.zeroPad(this.getUTCMilliseconds(),4);
+};
+
+// Static method to create a date from a UTC YYYYMMDDHHMM format string
+Date.convertFromYYYYMMDDHHMM = function(d)
+{
+	var hh = d.substr(8,2) || "00";
+	var mm = d.substr(10,2) || "00";
+	return new Date(Date.UTC(parseInt(d.substr(0,4),10),
+			parseInt(d.substr(4,2),10)-1,
+			parseInt(d.substr(6,2),10),
+			parseInt(hh,10),
+			parseInt(mm,10),0,0));
+};
+
+//--
+//-- Crypto functions and associated conversion routines
+//--
+
+// Crypto 'namespace'
+function Crypto() {}
+
+// Convert a string to an array of big-endian 32-bit words
+Crypto.strToBe32s = function(str)
+{
+	var be=[];
+	var len=Math.floor(str.length/4);
+	var i, j;
+	for(i=0, j=0; i<len; i++, j+=4) {
+		be[i]=((str.charCodeAt(j)&0xff) << 24)|((str.charCodeAt(j+1)&0xff) << 16)|((str.charCodeAt(j+2)&0xff) << 8)|(str.charCodeAt(j+3)&0xff);
+	}
+	while(j<str.length) {
+		be[j>>2] |= (str.charCodeAt(j)&0xff)<<(24-(j*8)%32);
+		j++;
+	}
+	return be;
+};
+
+// Convert an array of big-endian 32-bit words to a string
+Crypto.be32sToStr = function(be)
+{
+	var str='';
+	for(var i=0;i<be.length*32;i+=8) {
+		str += String.fromCharCode((be[i>>5]>>>(24-i%32)) & 0xff);
+	}
+	return str;
+};
+
+// Convert an array of big-endian 32-bit words to a hex string
+Crypto.be32sToHex = function(be)
+{
+	var hex='0123456789ABCDEF';
+	var str='';
+	for(var i=0;i<be.length*4;i++) {
+		str += hex.charAt((be[i>>2]>>((3-i%4)*8+4))&0xF) + hex.charAt((be[i>>2]>>((3-i%4)*8))&0xF);
+	}
+	return str;
+};
+
+// Return, in hex, the SHA-1 hash of a string
+Crypto.hexSha1Str = function(str)
+{
+	return Crypto.be32sToHex(Crypto.sha1Str(str));
+};
+
+// Return the SHA-1 hash of a string
+Crypto.sha1Str = function(str)
+{
+	return Crypto.sha1(Crypto.strToBe32s(str),str.length);
+};
+
+// Calculate the SHA-1 hash of an array of blen bytes of big-endian 32-bit words
+Crypto.sha1 = function(x,blen)
+{
+	// Add 32-bit integers, wrapping at 32 bits
+	function add32(a,b)
+	{
+		var lsw=(a&0xFFFF)+(b&0xFFFF);
+		var msw=(a>>16)+(b>>16)+(lsw>>16);
+		return (msw<<16)|(lsw&0xFFFF);
+	}
+	function AA(a,b,c,d,e)
+	{
+		b=(b>>>27)|(b<<5);
+		var lsw=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF);
+		var msw=(a>>16)+(b>>16)+(c>>16)+(d>>16)+(e>>16)+(lsw>>16);
+		return (msw<<16)|(lsw&0xFFFF);
+	}
+	function RR(w,j)
+	{
+		var n=w[j-3]^w[j-8]^w[j-14]^w[j-16];
+		return (n>>>31)|(n<<1);
+	}
+
+	var len=blen*8;
+	x[len>>5] |= 0x80 << (24-len%32);
+	x[((len+64>>9)<<4)+15]=len;
+	var w=new Array(80);
+
+	var k1=0x5A827999;
+	var k2=0x6ED9EBA1;
+	var k3=0x8F1BBCDC;
+	var k4=0xCA62C1D6;
+
+	var h0=0x67452301;
+	var h1=0xEFCDAB89;
+	var h2=0x98BADCFE;
+	var h3=0x10325476;
+	var h4=0xC3D2E1F0;
+
+	for(var i=0;i<x.length;i+=16) {
+		var j=0;
+		var t;
+		var a=h0;
+		var b=h1;
+		var c=h2;
+		var d=h3;
+		var e=h4;
+		while(j<16) {
+			w[j]=x[i+j];
+			t=AA(e,a,d^(b&(c^d)),w[j],k1);
+			e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
+		}
+		while(j<20) {
+			w[j]=RR(w,j);
+			t=AA(e,a,d^(b&(c^d)),w[j],k1);
+			e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
+		}
+		while(j<40) {
+			w[j]=RR(w,j);
+			t=AA(e,a,b^c^d,w[j],k2);
+			e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
+		}
+		while(j<60) {
+			w[j]=RR(w,j);
+			t=AA(e,a,(b&c)|(d&(b|c)),w[j],k3);
+			e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
+		}
+		while(j<80) {
+			w[j]=RR(w,j);
+			t=AA(e,a,b^c^d,w[j],k4);
+			e=d; d=c; c=(b>>>2)|(b<<30); b=a; a=t; j++;
+		}
+		h0=add32(h0,a);
+		h1=add32(h1,b);
+		h2=add32(h2,c);
+		h3=add32(h3,d);
+		h4=add32(h4,e);
+	}
+	return [h0,h1,h2,h3,h4];
+};
+
+//--
+//-- RGB colour object
+//--
+
+// Construct an RGB colour object from a '#rrggbb', '#rgb' or 'rgb(n,n,n)' string or from separate r,g,b values
+function RGB(r,g,b)
+{
+	this.r = 0;
+	this.g = 0;
+	this.b = 0;
+	if(typeof r == "string") {
+		if(r.substr(0,1) == "#") {
+			if(r.length == 7) {
+				this.r = parseInt(r.substr(1,2),16)/255;
+				this.g = parseInt(r.substr(3,2),16)/255;
+				this.b = parseInt(r.substr(5,2),16)/255;
+			} else {
+				this.r = parseInt(r.substr(1,1),16)/15;
+				this.g = parseInt(r.substr(2,1),16)/15;
+				this.b = parseInt(r.substr(3,1),16)/15;
+			}
+		} else {
+			var rgbPattern = /rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/;
+			var c = r.match(rgbPattern);
+			if(c) {
+				this.r = parseInt(c[1],10)/255;
+				this.g = parseInt(c[2],10)/255;
+				this.b = parseInt(c[3],10)/255;
+			}
+		}
+	} else {
+		this.r = r;
+		this.g = g;
+		this.b = b;
+	}
+	return this;
+}
+
+// Mixes this colour with another in a specified proportion
+// c = other colour to mix
+// f = 0..1 where 0 is this colour and 1 is the new colour
+// Returns an RGB object
+RGB.prototype.mix = function(c,f)
+{
+	return new RGB(this.r + (c.r-this.r) * f,this.g + (c.g-this.g) * f,this.b + (c.b-this.b) * f);
+};
+
+// Return an rgb colour as a #rrggbb format hex string
+RGB.prototype.toString = function()
+{
+	return "#" + ("0" + Math.floor(this.r.clamp(0,1) * 255).toString(16)).right(2) +
+				 ("0" + Math.floor(this.g.clamp(0,1) * 255).toString(16)).right(2) +
+				 ("0" + Math.floor(this.b.clamp(0,1) * 255).toString(16)).right(2);
+};
+
+//--
+//-- DOM utilities - many derived from www.quirksmode.org
+//--
+
+function drawGradient(place,horiz,locolors,hicolors)
+{
+	if(!hicolors)
+		hicolors = locolors;
+	for(var t=0; t<= 100; t+=2) {
+		var bar = document.createElement("div");
+		place.appendChild(bar);
+		bar.style.position = "absolute";
+		bar.style.left = horiz ? t + "%" : 0;
+		bar.style.top = horiz ? 0 : t + "%";
+		bar.style.width = horiz ? (101-t) + "%" : "100%";
+		bar.style.height = horiz ? "100%" : (101-t) + "%";
+		bar.style.zIndex = -1;
+		var p = t/100*(locolors.length-1);
+		var hc = hicolors[Math.floor(p)];
+		if(typeof hc == "string")
+			hc = new RGB(hc);
+		var lc = locolors[Math.ceil(p)];
+		if(typeof lc == "string")
+			lc = new RGB(lc);
+		bar.style.backgroundColor = hc.mix(lc,p-Math.floor(p)).toString();
+	}
+}
+
+function createTiddlyText(parent,text)
+{
+	return parent.appendChild(document.createTextNode(text));
+}
+
+function createTiddlyCheckbox(parent,caption,checked,onChange)
+{
+	var cb = document.createElement("input");
+	cb.setAttribute("type","checkbox");
+	cb.onclick = onChange;
+	parent.appendChild(cb);
+	cb.checked = checked;
+	cb.className = "chkOptionInput";
+	if(caption)
+		wikify(caption,parent);
+	return cb;
+}
+
+function createTiddlyElement(parent,element,id,className,text,attribs)
+{
+	var e = document.createElement(element);
+	if(className != null)
+		e.className = className;
+	if(id != null)
+		e.setAttribute("id",id);
+	if(text != null)
+		e.appendChild(document.createTextNode(text));
+	if(attribs) {
+		for(var n in attribs) {
+			e.setAttribute(n,attribs[n]);
+		}
+	}
+	if(parent != null)
+		parent.appendChild(e);
+	return e;
+}
+
+function addEvent(obj,type,fn)
+{
+	if(obj.attachEvent) {
+		obj['e'+type+fn] = fn;
+		obj[type+fn] = function(){obj['e'+type+fn](window.event);};
+		obj.attachEvent('on'+type,obj[type+fn]);
+	} else {
+		obj.addEventListener(type,fn,false);
+	}
+}
+
+function removeEvent(obj,type,fn)
+{
+	if(obj.detachEvent) {
+		obj.detachEvent('on'+type,obj[type+fn]);
+		obj[type+fn] = null;
+	} else {
+		obj.removeEventListener(type,fn,false);
+	}
+}
+
+function addClass(e,className)
+{
+	var currClass = e.className.split(" ");
+	if(currClass.indexOf(className) == -1)
+		e.className += " " + className;
+}
+
+function removeClass(e,className)
+{
+	var currClass = e.className.split(" ");
+	var i = currClass.indexOf(className);
+	while(i != -1) {
+		currClass.splice(i,1);
+		i = currClass.indexOf(className);
+	}
+	e.className = currClass.join(" ");
+}
+
+function hasClass(e,className)
+{
+	if(e.className && e.className.split(" ").indexOf(className) != -1) {
+		return true;
+	}
+	return false;
+}
+
+// Find the closest relative with a given property value (property defaults to tagName, relative defaults to parentNode)
+function findRelated(e,value,name,relative)
+{
+	name = name || "tagName";
+	relative = relative || "parentNode";
+	if(name == "className") {
+		while(e && !hasClass(e,value)) {
+			e = e[relative];
+		}
+	} else {
+		while(e && e[name] != value) {
+			e = e[relative];
+		}
+	}
+	return e;
+}
+
+// Resolve the target object of an event
+function resolveTarget(e)
+{
+	var obj;
+	if(e.target)
+		obj = e.target;
+	else if(e.srcElement)
+		obj = e.srcElement;
+	if(obj.nodeType == 3) // defeat Safari bug
+		obj = obj.parentNode;
+	return obj;
+}
+
+// Prevent an event from bubbling
+function stopEvent(e)
+{
+	var ev = e || window.event;
+	ev.cancelBubble = true;
+	if(ev.stopPropagation) ev.stopPropagation();
+	return false;
+}
+
+// Return the content of an element as plain text with no formatting
+function getPlainText(e)
+{
+	var text = "";
+	if(e.innerText)
+		text = e.innerText;
+	else if(e.textContent)
+		text = e.textContent;
+	return text;
+}
+
+// Get the scroll position for window.scrollTo necessary to scroll a given element into view
+function ensureVisible(e)
+{
+	var posTop = findPosY(e);
+	var posBot = posTop + e.offsetHeight;
+	var winTop = findScrollY();
+	var winHeight = findWindowHeight();
+	var winBot = winTop + winHeight;
+	if(posTop < winTop) {
+		return posTop;
+	} else if(posBot > winBot) {
+		if(e.offsetHeight < winHeight)
+			return posTop - (winHeight - e.offsetHeight);
+		else
+			return posTop;
+	} else {
+		return winTop;
+	}
+}
+
+// Get the current width of the display window
+function findWindowWidth()
+{
+	return window.innerWidth || document.documentElement.clientWidth;
+}
+
+// Get the current height of the display window
+function findWindowHeight()
+{
+	return window.innerHeight || document.documentElement.clientHeight;
+}
+
+// Get the current horizontal page scroll position
+function findScrollX()
+{
+	return window.scrollX || document.documentElement.scrollLeft;
+}
+
+// Get the current vertical page scroll position
+function findScrollY()
+{
+	return window.scrollY || document.documentElement.scrollTop;
+}
+
+function findPosX(obj)
+{
+	var curleft = 0;
+	while(obj.offsetParent) {
+		curleft += obj.offsetLeft;
+		obj = obj.offsetParent;
+	}
+	return curleft;
+}
+
+function findPosY(obj)
+{
+	var curtop = 0;
+	while(obj.offsetParent) {
+		curtop += obj.offsetTop;
+		obj = obj.offsetParent;
+	}
+	return curtop;
+}
+
+// Blur a particular element
+function blurElement(e)
+{
+	if(e && e.focus && e.blur) {
+		e.focus();
+		e.blur();
+	}
+}
+
+// Create a non-breaking space
+function insertSpacer(place)
+{
+	var e = document.createTextNode(String.fromCharCode(160));
+	if(place)
+		place.appendChild(e);
+	return e;
+}
+
+// Remove all children of a node
+function removeChildren(e)
+{
+	while(e && e.hasChildNodes())
+		removeNode(e.firstChild);
+}
+
+// Remove a node and all it's children
+function removeNode(e)
+{
+	scrubNode(e);
+	e.parentNode.removeChild(e);
+}
+
+// Remove any event handlers or non-primitve custom attributes
+function scrubNode(e)
+{
+	if(!config.browser.isIE)
+		return;
+	var att = e.attributes;
+	if(att) {
+		for(var t=0; t<att.length; t++) {
+			var n = att[t].name;
+			if(n !== 'style' && (typeof e[n] === 'function' || (typeof e[n] === 'object' && e[n] != null))) {
+				try {
+					e[n] = null;
+				} catch(ex) {
+				}
+			}
+		}
+	}
+	var c = e.firstChild;
+	while(c) {
+		scrubNode(c);
+		c = c.nextSibling;
+	}
+}
+
+// Add a stylesheet, replacing any previous custom stylesheet
+function setStylesheet(s,id,doc)
+{
+	if(!id)
+		id = "customStyleSheet";
+	if(!doc)
+		doc = document;
+	var n = doc.getElementById(id);
+	if(doc.createStyleSheet) {
+		// Test for IE's non-standard createStyleSheet method
+		if(n)
+			n.parentNode.removeChild(n);
+		// This failed without the &nbsp;
+		doc.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd","&nbsp;<style id='" + id + "'>" + s + "</style>");
+	} else {
+		if(n) {
+			n.replaceChild(doc.createTextNode(s),n.firstChild);
+		} else {
+			n = doc.createElement("style");
+			n.type = "text/css";
+			n.id = id;
+			n.appendChild(doc.createTextNode(s));
+			doc.getElementsByTagName("head")[0].appendChild(n);
+		}
+	}
+}
+
+function removeStyleSheet(id)
+{
+	var e = document.getElementById(id);
+	if(e)
+		e.parentNode.removeChild(e);
+}
+
+// Force the browser to do a document reflow when needed to workaround browser bugs
+function forceReflow()
+{
+	if(config.browser.isGecko) {
+		setStylesheet("body {top:0px;margin-top:0px;}","forceReflow");
+		setTimeout(function() {setStylesheet("","forceReflow");},1);
+	}
+}
+
+// Replace the current selection of a textarea or text input and scroll it into view
+function replaceSelection(e,text)
+{
+	if(e.setSelectionRange) {
+		var oldpos = e.selectionStart;
+		var isRange = e.selectionEnd > e.selectionStart;
+		e.value = e.value.substr(0,e.selectionStart) + text + e.value.substr(e.selectionEnd);
+		e.setSelectionRange(isRange ? oldpos : oldpos + text.length,oldpos + text.length);
+		var linecount = e.value.split('\n').length;
+		var thisline = e.value.substr(0,e.selectionStart).split('\n').length-1;
+		e.scrollTop = Math.floor((thisline - e.rows / 2) * e.scrollHeight / linecount);
+	} else if(document.selection) {
+		var range = document.selection.createRange();
+		if(range.parentElement() == e) {
+			var isCollapsed = range.text == "";
+			range.text = text;
+			if(!isCollapsed) {
+				range.moveStart('character', -text.length);
+				range.select();
+			}
+		}
+	}
+}
+
+// Returns the text of the given (text) node, possibly merging subsequent text nodes
+function getNodeText(e)
+{
+	var t = "";
+	while(e && e.nodeName == "#text") {
+		t += e.nodeValue;
+		e = e.nextSibling;
+	}
+	return t;
+}
+
+// Returns true if the element e has a given ancestor element
+function isDescendant(e,ancestor)
+{
+	while(e) {
+		if(e === ancestor)
+			return true;
+		e = e.parentNode;
+	}
+	return false;
+}
+
+//--
+//-- LoaderBase and SaverBase
+//--
+
+function LoaderBase() {}
+
+LoaderBase.prototype.loadTiddler = function(store,node,tiddlers)
+{
+	var title = this.getTitle(store,node);
+	if(safeMode && store.isShadowTiddler(title))
+		return;
+	if(title) {
+		var tiddler = store.createTiddler(title);
+		this.internalizeTiddler(store,tiddler,title,node);
+		tiddlers.push(tiddler);
+	}
+};
+
+LoaderBase.prototype.loadTiddlers = function(store,nodes)
+{
+	var tiddlers = [];
+	for(var t = 0; t < nodes.length; t++) {
+		try {
+			this.loadTiddler(store,nodes[t],tiddlers);
+		} catch(ex) {
+			showException(ex,config.messages.tiddlerLoadError.format([this.getTitle(store,nodes[t])]));
+		}
+	}
+	return tiddlers;
+};
+
+function SaverBase() {}
+
+SaverBase.prototype.externalize = function(store)
+{
+	var results = [];
+	var tiddlers = store.getTiddlers("title");
+	for(var t = 0; t < tiddlers.length; t++) {
+		if(!tiddlers[t].doNotSave())
+			results.push(this.externalizeTiddler(store, tiddlers[t]));
+	}
+	return results.join("\n");
+};
+
+//--
+//-- TW21Loader (inherits from LoaderBase)
+//--
+
+function TW21Loader() {}
+
+TW21Loader.prototype = new LoaderBase();
+
+TW21Loader.prototype.getTitle = function(store,node)
+{
+	var title = null;
+	if(node.getAttribute) {
+		title = node.getAttribute("title");
+		if(!title)
+			title = node.getAttribute("tiddler");
+	}
+	if(!title && node.id) {
+		var lenPrefix = store.idPrefix.length;
+		if(node.id.substr(0,lenPrefix) == store.idPrefix)
+			title = node.id.substr(lenPrefix);
+	}
+	return title;
+};
+
+TW21Loader.prototype.internalizeTiddler = function(store,tiddler,title,node)
+{
+	var e = node.firstChild;
+	var text = null;
+	if(node.getAttribute("tiddler")) {
+		text = getNodeText(e).unescapeLineBreaks();
+	} else {
+		while(e.nodeName!="PRE" && e.nodeName!="pre") {
+			e = e.nextSibling;
+		}
+		text = e.innerHTML.replace(/\r/mg,"").htmlDecode();
+	}
+	var modifier = node.getAttribute("modifier");
+	var c = node.getAttribute("created");
+	var m = node.getAttribute("modified");
+	var created = c ? Date.convertFromYYYYMMDDHHMM(c) : version.date;
+	var modified = m ? Date.convertFromYYYYMMDDHHMM(m) : created;
+	var tags = node.getAttribute("tags");
+	var fields = {};
+	var attrs = node.attributes;
+	for(var i = attrs.length-1; i >= 0; i--) {
+		var name = attrs[i].name;
+		if(attrs[i].specified && !TiddlyWiki.isStandardField(name)) {
+			fields[name] = attrs[i].value.unescapeLineBreaks();
+		}
+	}
+	tiddler.assign(title,text,modifier,modified,tags,created,fields);
+	return tiddler;
+};
+
+//--
+//-- TW21Saver (inherits from SaverBase)
+//--
+
+function TW21Saver() {}
+
+TW21Saver.prototype = new SaverBase();
+
+TW21Saver.prototype.externalizeTiddler = function(store,tiddler)
+{
+	try {
+		var extendedAttributes = "";
+		var usePre = config.options.chkUsePreForStorage;
+		store.forEachField(tiddler,
+			function(tiddler,fieldName,value) {
+				// don't store stuff from the temp namespace
+				if(typeof value != "string")
+					value = "";
+				if(!fieldName.match(/^temp\./))
+					extendedAttributes += ' %0="%1"'.format([fieldName,value.escapeLineBreaks().htmlEncode()]);
+			},true);
+		var created = tiddler.created;
+		var modified = tiddler.modified;
+		var attributes = tiddler.modifier ? ' modifier="' + tiddler.modifier.htmlEncode() + '"' : "";
+		attributes += (usePre && created == version.date) ? "" :' created="' + created.convertToYYYYMMDDHHMM() + '"';
+		attributes += (usePre && modified == created) ? "" : ' modified="' + modified.convertToYYYYMMDDHHMM() +'"';
+		var tags = tiddler.getTags();
+		if(!usePre || tags)
+			attributes += ' tags="' + tags.htmlEncode() + '"';
+		return ('<div %0="%1"%2%3>%4</'+'div>').format([
+				usePre ? "title" : "tiddler",
+				tiddler.title.htmlEncode(),
+				attributes,
+				extendedAttributes,
+				usePre ? "\n<pre>" + tiddler.text.htmlEncode() + "</pre>\n" : tiddler.text.escapeLineBreaks().htmlEncode()
+			]);
+	} catch (ex) {
+		throw exceptionText(ex,config.messages.tiddlerSaveError.format([tiddler.title]));
+	}
+};
+
+//]]>
+</script>
+<script id="jsdeprecatedArea" type="text/javascript">
+//<![CDATA[
+//--
+//-- Deprecated Tiddler code
+//--
+
+// @Deprecated: Use tiddlerToRssItem(tiddler,uri) instead
+Tiddler.prototype.toRssItem = function(uri)
+{
+	return tiddlerToRssItem(this,uri);
+};
+
+// @Deprecated: Use "<item>\n" + tiddlerToRssItem(tiddler,uri)  + "\n</item>" instead
+Tiddler.prototype.saveToRss = function(uri)
+{
+	return "<item>\n" + tiddlerToRssItem(this,uri) + "\n</item>";
+};
+
+//]]>
+</script>
+<script id="jqueryArea" type="text/javascript">
+//<![CDATA[
+//]]>
+</script>
+<script type="text/javascript">
+//<![CDATA[
+if(useJavaSaver)
+	document.write("<applet style='position:absolute;left:-1px' name='TiddlySaver' code='TiddlySaver.class' archive='TiddlySaver.jar' width='1' height='1'></applet>");
+//]]>
+</script>
+<!--POST-SCRIPT-START-->
+
+<!--POST-SCRIPT-END-->
+</body>
+</html>

Added: grpl/trunk/phone_renewal/doc/renew_all_items_workflow.pdf
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/doc/renew_all_items_workflow.pdf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/doc/renewal_result_data_structures.pdf
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/doc/renewal_result_data_structures.pdf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/eg_auth.pl
===================================================================
--- grpl/trunk/phone_renewal/eg_auth.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/eg_auth.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,3 @@
+$TelephoneRenewals::eg_auth{usr} = '';
+$TelephoneRenewals::eg_auth{passw} = '';
+$TelephoneRenewals::eg_auth{host} = '';

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/AllItemsRenewer.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/AllItemsRenewer.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/AllItemsRenewer.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,66 @@
+package TelephoneRenewals::AllItemsRenewer;
+use strict;
+use warnings;
+use Carp qw(croak);
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(phone_menu evergreen_renewal renewal_announcer renewal_logger) {
+    if (not($args{$varname})) {
+      croak "AllItemsRenewer cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub renew_all_items {
+  my ($self, $library_card_number) = @_;
+  my $evergreen_renewal = $self->{evergreen_renewal};
+  my $phone_menu = $self->{phone_menu};
+  my $renewal_logger = $self->{renewal_logger};
+
+  $renewal_logger->info("Patron $library_card_number renewing all items...");
+
+  my $results = $evergreen_renewal->renew_all_items($library_card_number);
+  $phone_menu->announce_count_of_renewed_items($results->count_successful_renewals);
+
+  if ($results->status eq "failures") {
+    $phone_menu->announce_some_items_failed_to_renew;
+    $self->_announce_renewals($results->failed_renewals);
+    $self->_announce_renewals($results->successful_renewals);
+
+  } else {
+    # TODO: announce "successful renewal of all items"?
+    my $choice = $phone_menu->prompt_for_details;
+    if ($choice eq "yes") {
+      $self->_announce_renewals($results->successful_renewals);
+    } else {
+      # Just log them
+      $self->_log_renewals($results->successful_renewals);
+    }
+  }
+  
+}
+
+# Private helper to loop over renewal
+sub _announce_renewals {
+  my ($self, $renewal_results) = @_;
+  foreach my $renewal_result (@$renewal_results) {
+    #$self->{renewal_logger}->log_result($renewal_result);
+    $self->{renewal_announcer}->announce_renewal_result($renewal_result);
+  }
+}
+
+sub _log_renewals {
+  my ($self, $renewal_results) = @_;
+  foreach my $renewal_result (@$renewal_results) {
+    $self->{renewal_logger}->log_result($renewal_result);
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/AppConfig.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/AppConfig.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/AppConfig.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,112 @@
+package TelephoneRenewals::AppConfig;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  our %eg_auth;
+  do '/etc/asterisk/eg_auth.pl';
+  my $self = {
+    eg_usr => $eg_auth{usr},
+    eg_passw => $eg_auth{passw},
+    eg_host => $eg_auth{host},
+    log_file => '/var/log/asterisk/telephone_renewals.log',
+    sounds_dir => '/var/lib/asterisk/sounds/phone_renewals',
+    smtp_host_and_port => 'localhost:25',
+    error_email_recipients => [ "not set" ],
+    error_email_from  => 'GRPL <telephonerenewals at grpl.org>',
+    error_email_subject  => '[ERROR] Telephone Renewal Error',
+  };
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub eg_usr {
+  my ($self, $eg_usr) = @_;
+  if (defined($eg_usr)) {
+    $self->{eg_usr} = $eg_usr;
+  } else {
+    return $self->{eg_usr};
+  }
+}
+
+sub eg_passw {
+  my ($self, $eg_passw) = @_;
+  if (defined($eg_passw)) {
+    $self->{eg_passw} = $eg_passw;
+  } else {
+    return $self->{eg_passw};
+  }
+}
+
+sub eg_host {
+  my ($self, $eg_host) = @_;
+  if (defined($eg_host)) {
+    $self->{eg_host} = $eg_host;
+  } else {
+    return $self->{eg_host};
+  }
+}
+
+sub clear_smtp_host_and_port {
+  my ($self) = @_;
+  $self->{smtp_host_and_port} = undef;
+}
+
+sub log_file {
+  my ($self, $log_file) = @_;
+  if (defined($log_file)) {
+    $self->{log_file} = $log_file;
+  } else {
+    return $self->{log_file};
+  }
+}
+
+sub sounds_dir {
+  my ($self, $sounds_dir) = @_;
+  if (defined($sounds_dir)) {
+    $self->{sounds_dir} = $sounds_dir;
+  } else {
+    return $self->{sounds_dir};
+  }
+}
+
+sub smtp_host_and_port {
+  my ($self, $smtp_host_and_port) = @_;
+  if (defined($smtp_host_and_port)) {
+    $self->{smtp_host_and_port} = $smtp_host_and_port;
+  } else {
+    return $self->{smtp_host_and_port};
+  }
+}
+
+sub error_email_recipients {
+  my ($self, $error_email_recipients) = @_;
+  if (defined($error_email_recipients)) {
+    $self->{error_email_recipients} = $error_email_recipients;
+  } else {
+    return $self->{error_email_recipients};
+  }
+}
+
+sub error_email_from {
+  my ($self, $error_email_from) = @_;
+  if (defined($error_email_from)) {
+    $self->{error_email_from} = $error_email_from;
+  } else {
+    return $self->{error_email_from};
+  }
+}
+
+sub error_email_subject {
+  my ($self, $error_email_subject) = @_;
+  if (defined($error_email_subject)) {
+    $self->{error_email_subject} = $error_email_subject;
+  } else {
+    return $self->{error_email_subject};
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/CallHandler.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/CallHandler.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/CallHandler.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,107 @@
+package TelephoneRenewals::CallHandler;
+use strict;
+use warnings;
+use Carp qw(croak);
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(evergreen_renewal phone_menu all_items_renewer individual_items_renewer logger) {
+    if (not($args{$varname})) {
+      croak "CallHandler cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  $self->{max_card_number_failures} = 3;
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub handle_call {
+  my ($self) = @_;
+  my $phone_menu = $self->{phone_menu};
+  my $evergreen_renewal = $self->{evergreen_renewal};
+  my $logger = $self->{logger};
+
+  $logger->info("Handling new call ******************************");
+  eval {
+    $phone_menu->initialize();
+    $phone_menu->answer_and_play_welcome_message();
+
+    my $library_card_number = $self->_acquire_and_validate_library_card_number;
+    my $count_of_items_out = $evergreen_renewal->count_items_out($library_card_number);
+    $logger->info("Patron $library_card_number has $count_of_items_out items out.");
+
+    if ($count_of_items_out == 0) {
+      # Caller has no items out, so tell them, and get out
+      $phone_menu->announce_no_items_out;
+
+    } else {
+      # Caller has items out
+      $phone_menu->announce_count_of_items_out($count_of_items_out);
+
+      my $renewal_choice = $phone_menu->prompt_to_renew_items;
+
+      if ($renewal_choice eq "all") {
+        $self->{all_items_renewer}->renew_all_items($library_card_number);
+
+      } elsif ($renewal_choice eq "individual") {
+        $self->{individual_items_renewer}->renew_individual_items($library_card_number);
+      } else {
+        $logger->info("Patron $library_card_number decided not to renew any items.");
+      }
+    }
+
+  };
+
+  # Warn user of unexpected errors;
+  if ($@) {
+    $logger->log_and_email_error($@);
+    $phone_menu->announce_unexpected_error;
+  }
+  
+  $logger->info("Hanging up.");
+  $phone_menu->say_goodbye_and_hangup;
+}
+
+
+=head2 
+
+Private helper method to solicit and validate the caller's library card
+number.
+
+=cut
+
+sub _acquire_and_validate_library_card_number {
+  my ($self) = @_;
+  my $phone_menu = $self->{phone_menu};
+  my $evergreen_renewal = $self->{evergreen_renewal};
+
+  # First try
+  my $library_card_number = $phone_menu->accept_library_card_number;
+  my $card_validity = $evergreen_renewal->validate_library_card_number($library_card_number);
+
+  # Make sure we've got a good card number before moving on
+  my $tries = 1;
+  my @attempted_numbers = ($library_card_number);
+  while ($card_validity ne "valid") {
+    # Abort after too many failures:
+    if ($tries >= $self->{max_card_number_failures}) {
+      my $msg = "Failed to acquire card number from caller after ".$self->{max_card_number_failures}." tries.";
+      $msg .= " Tried numbers: " . join(", ", at attempted_numbers);
+      croak $msg;
+    }
+    # Ask again
+    $phone_menu->announce_bad_library_card_number;
+    $library_card_number = $phone_menu->accept_library_card_number;
+    $card_validity = $evergreen_renewal->validate_library_card_number($library_card_number);
+    $tries++;
+    push(@attempted_numbers, $library_card_number);
+  }
+  return $library_card_number;
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/ERGateway.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/ERGateway.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/ERGateway.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,178 @@
+package TelephoneRenewals::ERGateway;
+
+use Digest::MD5(md5_hex);
+use LWP::UserAgent();
+use HTTP::Request::Common;
+use JSON;
+
+
+my %service = (
+		'ACTOR' => 'open-ils.actor',
+		'ASSET' => 'open-ils.asset',
+		'CIRC'  => 'open-ils.circ',
+		'AUTH'  => 'open-ils.auth',
+	      );
+
+sub new {
+  my ($class, $host) = @_;
+  my $self = {};
+  $self->{host} = $host;
+  $self->{host_url} = "http://$host/gateway";
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+
+sub get_authtok {
+        my ($self,$u,$p) = @_;
+	$p = md5_hex($p);
+	$ru = [$u];
+	my $s = $self->call_osrf('AUTH','open-ils.auth.authenticate.init',$ru);
+	my $seed = decode_json $s;
+	my $md5_passwd = md5_hex( $seed->{payload}[0] . $p );
+
+	my $login;
+	$login->{type}= 'staff';
+	$login->{username} = $u;
+	$login->{password} = $md5_passwd;
+
+	my $s_json = encode_json $login;
+
+	my $res = $self->call_osrf('AUTH','open-ils.auth.authenticate.complete',$s_json,'json');
+
+	my $at = decode_json $res;
+	return $at->{payload}[0]->{payload}->{authtoken};
+}
+
+sub get_eg_version {
+        my ($self) = @_;
+        my $res = $self->call_osrf('ACTOR','opensrf.open-ils.system.ils_version');
+        my $ver = decode_json $res;
+        return $ver->{payload}[0]->{textcode} || $ver->{payload}[0];
+}
+
+sub patron_exists {
+	my ($self,$at,$bc) = @_;
+	$ary = [$at, $bc];
+        my $res = $self->call_osrf('ACTOR','open-ils.actor.barcode.exists',$ary);
+	my $id = decode_json $res;
+        return $id->{payload}[0]->{textcode} || $id->{payload}[0];
+}
+
+sub get_items_out {
+	my ($self,$at,$uid) = @_;
+	my $aref = [$at, $uid];
+	my $res = $self->call_osrf('ACTOR','open-ils.actor.user.checked_out',$aref);
+	my $items = decode_json $res;
+	my @iarry;
+	foreach (@{$items->{payload}[0]->{out}}){
+		push @iarry,$_;
+	}
+	foreach (@{$items->{payload}[0]->{overdue}}){
+                push @iarry,$_;
+        }
+        return @iarry;
+}
+
+sub get_patron {
+        my ($self,$at,$bc) = @_;
+        my $aref= [$at, $bc];
+        my $res = $self->call_osrf('ACTOR','open-ils.actor.user.fleshed.retrieve_by_barcode',$aref);
+        return $res;
+}
+
+sub get_patron_id {
+	my ($self,$at,$bc) = @_;
+	my $aref= [$at, $bc];
+	my $res = $self->call_osrf('ACTOR','open-ils.actor.user.retrieve_id_by_barcode_or_username',$aref);
+	my $id = decode_json $res;
+        return $id->{payload}[0]->{textcode} || $id->{payload}[0];
+}
+
+sub get_item_barcode_from_circ {  
+	my $self = shift;
+	my $cid = shift;
+	my $aref = [$cid];
+	my $res = $self->call_osrf('CIRC','open-ils.circ.fleshed.retrieve',$aref);
+	##  The nasty kludge(tm)
+	$res =~ s/(.*?S\sacp\-\-\*\/\[)(.*?)(\/\*\-\-S\s.*)/$2/;
+	$res =~ s/\"//g;
+	my @a = split(/,/,$res);
+	return $a[6];
+}
+
+sub get_patron_id_from_circ {
+	my $self = shift;
+        my $cid = shift;
+        my $aref = [$cid];
+        my $res = $self->call_osrf('CIRC','open-ils.circ.fleshed.retrieve',$aref);
+        ##  The nasty kludge(tm)
+	$res =~ s/(.*?S\scirc\-\-\*\/\[)(.*?)(\]\/\*\-\-.*)/$2/;
+	$res =~ s/\"//g;
+	my @a = split(/,/,$res);
+	return $a[24];
+}
+
+sub renew_item {
+	my ($self,$at,$p,$i) = @_;
+	$at = '"'.$at.'"';
+	my $circ;
+	$circ->{barcode} = $i;
+	$circ->{patron_barcode} = $p;
+	$circ->{phone_renewal} = 't';
+	my $j = encode_json $circ;
+	my $ua  = LWP::UserAgent->new;
+	my $req = POST $self->{host_url}, [
+				method=>"open-ils.circ.renew",
+				service=>"open-ils.circ",
+				param=>$at,
+				param=>"$j"
+			];
+	my $res = $ua->request($req);
+	my $eg_status;
+	($eg_status = $res->content) =~ s/.*(textcode)(\":\")(\w*).*/$3/; 
+	return $eg_status; # any string other than "SUCCESS" will contain the failure reason
+}	
+
+
+sub call_osrf {
+	my ($self,$s,$m,$p,$j) = @_;
+
+	my $url;
+	if ($j){
+		$url = $self->{host_url} . '?method=' . $m . '&service=' . $service{$s} . '&param=' . $p;
+	}else{
+		my $pstring; 
+		foreach $param (@{$p}) {
+			$pstring .=  '&param="' . $param . '"';
+		}
+		$url = $self->{host_url} . '?method=' . $m . '&service=' . $service{$s} . $pstring;
+	}
+        my $ua  = LWP::UserAgent->new;
+        my $req = GET $url;
+        my $res = $ua->request($req);
+        return $res->content;
+}
+
+sub post_osrf {
+	my ($self,$s,$m,$p) = @_;
+
+        my $url;
+	my $ua  = LWP::UserAgent->new;
+	my %hash;
+	$hash{method}=$m;
+	$hash{service}=$s;
+	foreach $param (@{$p}){
+		$hash{param}=$param;
+	}
+        my $req = POST $self->{host_url},\%hash; 
+        my $res = $ua->request($req);
+        return $res->content;
+
+}
+
+
+
+1;
+__END__
+

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/Emailer.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/Emailer.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/Emailer.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,48 @@
+package TelephoneRenewals::Emailer;
+use strict;
+use warnings;
+use Carp;
+
+use MIME::Lite;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(app_config) {
+    if (not($args{$varname})) {
+      croak "Emailer cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  # Configure the sending subsystem:
+  my $smtp_server = $self->{app_config}->smtp_host_and_port;
+  if ($smtp_server) {
+    MIME::Lite->send('smtp', $smtp_server, Timeout => 60);
+    $self->{deliver_mail} = 1;
+  } else {
+    $self->{deliver_mail} = 0;
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub send_email {
+  my ($self, $opts) = @_;
+  unless ($self->{deliver_mail}) {
+    croak "TelephoneRenewals::Emailer is disabled; set AppConfig smtp_host_and_port to enable it."
+  }
+
+  my $email = MIME::Lite->new(
+    From => $opts->{from},
+    To => $opts->{to},
+    Subject => $opts->{subject},
+    Data => $opts->{body}
+  );
+  # Send!
+  $email->send();
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/EvergreenRenewal.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/EvergreenRenewal.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/EvergreenRenewal.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,109 @@
+package TelephoneRenewals::EvergreenRenewal;
+use strict;
+use warnings;
+use TelephoneRenewals::RenewalResult;
+use TelephoneRenewals::RenewalResultSet;
+use TelephoneRenewals::ERGateway;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+  foreach my $varname qw(app_config renewal_logger) {
+    if (not($args{$varname})) {
+      croak "LogChannel cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+  my $erg =  TelephoneRenewals::ERGateway->new($self->{app_config}->{eg_host});
+  my $at = $erg->get_authtok($self->{app_config}->{eg_usr},$self->{app_config}->{eg_passw}) || die "get_authtok failed: $@ \n";
+  $self->{authtoken} = $at;
+  $self->{erg} = $erg;
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub validate_library_card_number {
+  my ($self, $library_card_number) = @_;
+  # Determine if the given library card number is valid.
+  # Return "valid" if it is.
+  # Return "invalid" otherwise.
+  my $ver = $self->{erg}->get_eg_version();
+  my $res;
+  if ($ver =~ /^1-2/){
+  	$res = $self->{erg}->patron_exists($self->{authtoken},$library_card_number);
+  }elsif ($ver =~ /^1-4/){
+	$res = $self->{erg}->get_patron_id($self->{authtoken},$library_card_number);
+  }
+  if ( $res eq 'ACTOR_USER_NOT_FOUND' ) {
+	return 'invalid';
+  } else {
+	$self->{patron_id} = $res;
+	return 'valid';
+  }
+}
+
+sub count_items_out {
+  my ($self, $library_card_number) = @_;
+  # $library_card_number is a string like "12345"
+  #
+  # Use Evergreen to count all items out under the given card number.
+  #
+  # Return integer value: # of items out, 0 if none.
+  $self->validate_library_card_number($library_card_number) unless $self->{patron_id};
+  my @item_list = $self->{erg}->get_items_out($self->{authtoken},$self->{patron_id});
+  $self->{items_out} = \@item_list;
+  return scalar @item_list;
+}
+
+sub renew_all_items {
+  my ($self, $library_card_number) = @_;
+  #
+  # Use evergreen to discover all items out for this library card number,
+  # then attempt renewal on each item.
+  #
+  # Collect two lists: successful_renewals and failed_renewals
+  # The lists contain "RenewalResult" structures:
+  #   new TelephoneRenewals::RenewalResult(status => 'success', barcode => '12345678912345');
+  #
+  # Also include a status field in the return: 
+  #   ok
+  #   failures
+  #
+  # Eg,
+  # new TelephoneRenewals::RenewalResultList(
+  #   status => "failures",
+  #   successful_renewals =>  [ ... ],
+  #   failed_renewals =>  [ ... ],
+  # )
+  $self->count_items_out($library_card_number) unless $self->{items_out};
+  my $rset = TelephoneRenewals::RenewalResultSet->new();
+  foreach my $i ( @{$self->{items_out}} ) {
+	my $bc = $self->{erg}->get_item_barcode_from_circ($i);
+	my $res = $self->renew_item_by_barcode($library_card_number,$bc);
+	if ($res->{status} eq 'SUCCESS') {
+		$rset->add_successful_renewal($res);
+	} else {
+		$rset->add_failed_renewal($res);
+	}
+  }
+  $rset->{status} = 'failures' if $rset->count_failed_renewals;
+  return $rset;
+}
+
+sub renew_item_by_barcode {
+  my ($self, $library_card_number, $barcode) = @_;
+  # Library card number is a string like "1234567"
+  # Barcode is the full barcode string like "111111111111"
+  # Returns:
+  #   new RenewalResult(status => 'success', barcode => '12345678912345');
+  
+  my $renstat = $self->{erg}->renew_item($self->{authtoken},$library_card_number,$barcode);
+  my $renres = TelephoneRenewals::RenewalResult->new(status => $renstat, barcode => "$barcode", patron=>$library_card_number);
+  $self->{renewal_logger}->log_result($renres);
+  return $renres;
+
+}
+
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/FakeEvergreenRenewal.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/FakeEvergreenRenewal.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/FakeEvergreenRenewal.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,109 @@
+package TelephoneRenewals::Fakes::FakeEvergreenRenewal;
+use strict;
+use warnings;
+use Carp;
+use TelephoneRenewals::RenewalResult;
+use TelephoneRenewals::RenewalResultSet;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub validate_library_card_number {
+  my ($self, $library_card_number) = @_;
+  # Determine if the given library card number is valid.
+  # Return "valid" if it is.
+  # Retrun "invalid" otherwise.
+  if ($library_card_number =~ /^2/) {
+    return "valid";
+  } else {
+    return "invalid";
+  }
+}
+
+sub count_items_out {
+  my ($self, $library_card_number) = @_;
+  # $library_card_number is a string like "12345"
+  #
+  # Use Evergreen to count all items out under the given card number.
+  #
+  # Return integer value: # of items out, 0 if none.
+  if ($library_card_number =~ /^21/) {
+    return 2;
+  } elsif ($library_card_number =~ /^22/) {
+    return 5;
+  } else {
+    return 0;
+  }
+}
+
+sub renew_all_items {
+  my ($self, $library_card_number) = @_;
+  #
+  # Use evergreen to discover all items out for this library card number,
+  # then attempt renewal on each item.
+  #
+  # Collect two lists: successful_renewals and failed_renewals
+  # The lists contain "RenewalResult" structures:
+  #   new RenewalResult(status => 'success', barcode => '12345678912345');
+  #
+  # Also include a status field in the return: 
+  #   ok
+  #   failures
+  # {
+  #   status => "some failures",
+  #   successful_renewals =>  [ ... ],
+  #   failed_renewals =>  [ ... ],
+  # }
+
+  if ($library_card_number =~ /^22/) {
+    return new TelephoneRenewals::RenewalResultSet(
+      status => "failures",
+      successful_renewals => [
+        new TelephoneRenewals::RenewalResult(status => "success", barcode => "31111111111111"),
+        new TelephoneRenewals::RenewalResult(status => "success", barcode => "32222222222222"),
+      ],
+      failed_renewals => [
+        new TelephoneRenewals::RenewalResult(status => "unknown barcode", barcode => "37777777777777"),
+        new TelephoneRenewals::RenewalResult(status => "no renewals allowed", barcode => "38888888888888"),
+        new TelephoneRenewals::RenewalResult(status => "ouch", barcode => "34545454545458"),
+      ],
+    );
+
+  } else {
+    return new TelephoneRenewals::RenewalResultSet(
+      status => "ok",
+      successful_renewals => [
+        new TelephoneRenewals::RenewalResult(status => "success", barcode => "31111111111111"),
+        new TelephoneRenewals::RenewalResult(status => "success", barcode => "32222222222222"),
+      ],
+      failed_renewals => [
+      ],
+    );
+  }
+}
+
+sub renew_item_by_barcode {
+  my ($self, $library_card_number, $barcode) = @_;
+  # Library card number is a string like "1234567"
+  # Barcode is the full barcode string like "111111111111"
+  # Returns:
+  #   new RenewalResult(status => 'success', barcode => '12345678912345');
+  if ((not defined $barcode) || ($barcode =~ /^4/)) {
+    return new TelephoneRenewals::RenewalResult(status => "unknown barcode", barcode => $barcode),
+  } elsif ($barcode =~ /^187/) {
+    croak "Rigged to explode -- barcode $barcode.  This is an intentionally unhandled error for testing purposes.\n";
+  } elsif ($barcode =~ /^5/) {
+    return new TelephoneRenewals::RenewalResult(status => "no renewals allowed", barcode => $barcode),
+  } elsif ($barcode =~ /^6/) {
+    return new TelephoneRenewals::RenewalResult(status => "crazy breakage", barcode => $barcode),
+  } else {
+    return new TelephoneRenewals::RenewalResult(status => "success", barcode => $barcode),
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/FakePhoneMenu.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/FakePhoneMenu.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/Fakes/FakePhoneMenu.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,201 @@
+package TelephoneRenewals::Fakes::FakePhoneMenu;
+use strict;
+use warnings;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub _log {
+  my ($self,$message) = @_;
+  print "(PhoneMenu - $message)\n";
+}
+
+sub _say {
+  my ($self,$message) = @_;
+  print "$message\n";
+}
+
+sub _prompt {
+  my ($self,$message) = @_;
+  print $message;
+  my $input = <STDIN>;
+  chomp($input);
+  return $input;
+}
+
+# ----------------------------------
+sub initialize {
+  my ($self) = @_;
+  $| = 1;
+  $self->_log("Initialized");
+}
+
+sub answer_and_play_welcome_message {
+  my ($self) = @_;
+  # AGI->answer
+  # Play "Thank you for calling the Grand Rapids Public Library"
+  # no return
+  $self->_say("Thanks for calling the Grand Rapids Public Library telephone renewal system.");
+}
+
+sub accept_library_card_number {
+  my ($self) = @_;
+  # Play: "Please enter your N digit library card number"
+  #
+  # Accept ? digits
+  # Loop if no user input?
+  # return digit string, or undef on abort/hangup
+  my $input = $self->_prompt("Please enter your 14 digit library card number: ");
+  return $input;
+}
+
+sub announce_bad_library_card_number {
+  my ($self) = @_;
+  # Play: "Your library card was not recognized"
+  # no return
+  $self->_say("We couldn't find your library card number.");
+}
+
+sub announce_some_items_failed_to_renew {
+  my ($self) = @_;
+  # Play: "Some of your items could not be renewed."
+  $self->_say("Some of your items could not be renewed.");
+}
+
+sub announce_count_of_items_out {
+  my ($self, $count) = @_;
+  # Play: "You currently have..."
+  # SayDigits: $count to string
+  # Play: "...items checked out."
+  # no return
+  $self->_say("You currently have $count items checked out.");
+}
+
+sub announce_no_items_out {
+  my ($self) = @_;
+  # Play: "You currently have no items checked out."
+  # no return
+  $self->_say("You currently have no items checked out.");
+}
+
+sub announce_count_of_renewed_items {
+  my ($self, $count) = @_;
+  # Play: "You have renewed..."
+  # SayDigits: $count to string
+  # Play: "...items."
+  # no return
+  $self->_say("$count of your items have been renewed.");
+}
+
+
+sub announce_renewal_success {
+  my ($self, $barcode_ending) = @_;
+  # Play "Your item has been renewed."
+  # TODO: make use of actual barcode number?
+  # no return
+  $self->_say("Item with barcode ending $barcode_ending has been renewed.");
+}
+
+sub announce_renewal_failure_due_to_renewal_limitations {
+  my ($self, $barcode_ending) = @_;
+  # Play "Your item could not be renewed due to renewal limitations."
+  # TODO: make use of actual barcode number?
+  # no return
+  $self->_say("Item with barcode ending $barcode_ending may not be renewed at this time.");
+}
+
+sub announce_renewal_failure_due_to_unknown_barcode {
+  my ($self, $barcode) = @_;
+  # Play "Your item could not be renewed because we did not recognize the barcode you entered."
+  # TODO: make use of actual barcode number?
+  # no return
+  $self->_say("Barcode $barcode was not recognized.");
+}
+
+sub announce_renewal_failure_due_to_error {
+  my ($self, $barcode) = @_;
+  # Play "Your item could not be renewed due to renewal limitations."
+  # TODO: make use of actual barcode number?
+  # no return
+  $self->_say("Item with barcode ending $barcode could not be renewed due to a system error.");
+}
+
+sub announce_unexpected_error {
+  my ($self) = @_;
+  # Play "We're sorry, an error has occurred with the renewal service. Please call... ??"
+  # TODO: How to verbally redirect users on error?
+  # no return
+  $self->_say("We're sorry, something went wrong.");
+}
+
+sub prompt_for_barcode {
+  my ($self) = @_;
+  # Play "Please enter the 14 digit barcode of the item you wish to renew."
+  # Read 14 digit string via get-data
+  # return digit string
+  my $input = $self->_prompt("Please enter the item's 14 digit barcode: ");
+  return $input;
+}
+
+sub prompt_for_details {
+  my ($self) = @_;
+  # Play "If you would like to hear the barcodes of the renewed items, press 1 now, or press 0 to exit."
+  # Read 1 digit
+  # Return "yes" if digit is 1
+  # Return "no" if digit is 0
+  my $input = $self->_prompt("To hear the last 5 digits of your renewed items, press 1 now, otherwise press 0: ");
+  if ($input =~ /^1/) {
+    return "yes";
+  } else {
+    return "no";
+  }
+}
+
+sub prompt_to_continue_individual_renewal {
+  my ($self) = @_;
+  # Play "To renew another item, press 1 now, or press 0 to exit."
+  # Read 1 digit
+  # Return "yes" if digit is 1
+  # Return "no" if digit is 0
+  my $input = $self->_prompt("To renew another item, press 1.  If you're done renewing items, press 0: ");
+  if ($input =~ /^1/) {
+    return "yes";
+  } else {
+    return "no";
+  }
+}
+
+sub prompt_to_renew_items {
+  my ($self) = @_;
+  # Play "To renew all of your checked-out items, press 1 now.  To renew individual items, press 2, or press 0 to exit."
+  # Read 1 digit
+  # Return "all" if digit is 1
+  # Return "individual" if digit is 2
+  # Return "exit" if digit is 0
+  my $input = $self->_prompt("To renew all of your items, press 1 now.  To renew individual items, press 2, or press 0 to exit: ");
+  if ($input =~ /^1/) {
+    return "all";
+  } elsif ($input =~ /^2/) {
+    return "individual";
+  } else {
+    return "exit";
+  }
+}
+
+sub say_goodbye_and_hangup {
+  my ($self) = @_;
+  # Play "Thank you for calling the Grand Rapids Public Library. If need further assistance, please call 1-800-GRPL"
+  # TODO: robustify the play cmd (how? test this well w asterisk) in case
+  #       we've been disconnected from caller.
+  # AGI->hangup
+  # no return
+  $self->_say("Thanks for calling GRPL.  If you need further assistance, please call us at 1-800-GRPL. Goodbye!");
+}
+
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/IndividualItemsRenewer.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/IndividualItemsRenewer.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/IndividualItemsRenewer.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,54 @@
+package TelephoneRenewals::IndividualItemsRenewer;
+use strict;
+use warnings;
+use Carp qw(croak);
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(evergreen_renewal phone_menu renewal_announcer renewal_logger) {
+    if (not($args{$varname})) {
+      croak "IndividualItemsRenewer cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub renew_individual_items {
+  my ($self, $library_card_number) = @_;
+  my $phone_menu = $self->{phone_menu};
+  my $evergreen_renewal = $self->{evergreen_renewal};
+  my $renewal_announcer = $self->{renewal_announcer};
+  my $renewal_logger = $self->{renewal_logger};
+
+  $renewal_logger->info("Patron $library_card_number renewing individual items...");
+
+  my $keep_renewing = 1;
+
+  my ($empty,$max_empty) = (0,3);
+  while ($keep_renewing) {
+    my $barcode = $phone_menu->prompt_for_barcode;
+    if (not defined $barcode) {
+      $empty++;
+      if ($empty >= $max_empty) {
+        $keep_renewing = 0;
+      }
+      next;
+    }
+    my $renewal_result = $evergreen_renewal->renew_item_by_barcode($library_card_number, $barcode);
+
+    $renewal_announcer->announce_renewal_result($renewal_result);
+    #$renewal_logger->log_result($renewal_result);
+
+    my $continue_choice = $phone_menu->prompt_to_continue_individual_renewal;
+    if ($continue_choice ne "yes") {
+      $keep_renewing = 0;
+    }
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/LogChannel.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/LogChannel.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/LogChannel.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,37 @@
+package TelephoneRenewals::LogChannel;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(app_config) {
+    if (not($args{$varname})) {
+      croak "LogChannel cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub write_message {
+  my ($self, $message) = @_;
+  eval {
+    my $log_file = $self->{app_config}->log_file;
+    if (open LOGCHANFILE, ">> $log_file") {
+      print LOGCHANFILE "$message\n";
+      close LOGCHANFILE
+    } else {
+      print STDERR "!! TelephoneRenewals::LogChannel - FAILED TO OPEN LOG FILE: '$log_file'\n  (Wanted to write message: $message)\n"
+    }
+  };
+  if ($@) {
+    print STDERR "!! TelephoneRenewals::LogChannel - FAILED TO WRITE LOG MESSAGE: $message\n  (Failure due to exception: $@)\n"
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/Logger.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/Logger.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/Logger.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,70 @@
+package TelephoneRenewals::Logger;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(log_channel emailer app_config) {
+    if (not($args{$varname})) {
+      croak "Logger cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub info {
+  my ($self,$message) = @_;
+  $self->_log("INFO", $message);
+}
+
+sub error {
+  my ($self,$message) = @_;
+  $self->_log("ERROR", $message);
+}
+
+sub log_and_email_error {
+  my ($self, $message) = @_;
+  $self->error($message);
+
+  eval {
+    $self->_email_error($message);
+  };
+  if ($@) {
+    $self->error($@);
+  }
+}
+
+# Private helpers:
+
+sub _log {
+  my ($self,$level,$message) = @_;
+  my $formatted_message = $self->_format_log_message_current_time($level,$message);
+  $self->{log_channel}->write_message($formatted_message);
+}
+
+sub _email_error {
+  my ($self,$message) = @_;
+  my $config = $self->{app_config};
+  my $formatted_message = $self->_format_log_message_current_time("ERROR",$message);
+  $self->{emailer}->send_email({
+    to => $config->error_email_recipients,
+    from => $config->error_email_from,
+    subject => $config->error_email_subject,
+    body => "An error occurred in the GRPL telephone renewal system:\n\n$formatted_message"
+  });
+}
+
+sub _format_log_message_current_time {
+  my ($self, $level, $message) = @_;
+  my $date_string = `date`;
+  chomp($date_string);
+  return "[$date_string] - $level - $message";
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/ObjectContext.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/ObjectContext.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/ObjectContext.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,169 @@
+package TelephoneRenewals::ObjectContext;
+use strict;
+use warnings;
+
+use TelephoneRenewals::CallHandler;
+use TelephoneRenewals::EvergreenRenewal;
+use TelephoneRenewals::PromptStore;
+use TelephoneRenewals::PhoneMenu;
+use TelephoneRenewals::AppConfig;
+use TelephoneRenewals::LogChannel;
+use TelephoneRenewals::Emailer;
+use TelephoneRenewals::Logger;
+use TelephoneRenewals::RenewalAnnouncer;
+use TelephoneRenewals::RenewalLogger;
+use TelephoneRenewals::AllItemsRenewer;
+use TelephoneRenewals::IndividualItemsRenewer;
+use Asterisk::AGI; 
+
+use TelephoneRenewals::PromptManager;
+
+use TelephoneRenewals::SoundIndexPrinter;
+
+use TelephoneRenewals::Fakes::FakeEvergreenRenewal;
+use TelephoneRenewals::Fakes::FakePhoneMenu;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub get_call_handler {
+  my ($self,%args) = @_;
+
+  # Logging and notification components:
+
+  my $app_config = new TelephoneRenewals::AppConfig;
+
+  $app_config->eg_usr( $args{eg_usr} ) if $args{eg_usr};  
+  $app_config->eg_passw( $args{eg_passw} ) if $args{eg_passw};
+  $app_config->eg_host( $args{eg_host} ) if $args{eg_host};
+  $app_config->log_file( $args{log_file} ) if $args{log_file};
+  $app_config->smtp_host_and_port( $args{smtp_host_and_port} ) if $args{smtp_host_and_port};
+  $app_config->error_email_recipients( $args{error_email_recipients} ) if $args{error_email_recipients};
+  if ($args{disable_error_email}) {
+    $app_config->clear_smtp_host_and_port;
+  }
+
+  my $log_channel = new TelephoneRenewals::LogChannel(
+    app_config => $app_config,
+  );
+
+  my $emailer = new TelephoneRenewals::Emailer(
+    app_config => $app_config,
+  );
+
+  my $logger = new TelephoneRenewals::Logger(
+    log_channel => $log_channel,
+    emailer => $emailer,
+    app_config => $app_config,
+  );
+
+  my $renewal_logger = new TelephoneRenewals::RenewalLogger(
+    logger => $logger,
+  );
+
+  # Evergreen and Asterisk wrappers:
+
+  my $evergreen_renewal = new TelephoneRenewals::EvergreenRenewal(
+   app_config => $app_config,
+   renewal_logger => $renewal_logger,
+  );
+
+  if ($args{fake_evergreen_renewal}) {
+    $evergreen_renewal = new TelephoneRenewals::Fakes::FakeEvergreenRenewal;
+  }
+
+  my $prompt_store = new TelephoneRenewals::PromptStore(
+    app_config => $app_config
+  );
+
+  my $agi = new Asterisk::AGI; 
+  my $phone_menu = new TelephoneRenewals::PhoneMenu(
+    agi => $agi, 
+    prompt_store => $prompt_store
+  );
+
+  if ($args{fake_phone_menu}) {
+    $phone_menu = new TelephoneRenewals::Fakes::FakePhoneMenu;
+  }
+    
+  # Business logic delegates:
+
+  my $renewal_announcer = new TelephoneRenewals::RenewalAnnouncer(
+    phone_menu => $phone_menu,
+    logger => $logger,
+  );
+
+#  moved up so I could use in EvergreenRenewal
+#  my $renewal_logger = new TelephoneRenewals::RenewalLogger(
+#    logger => $logger,
+#  );
+
+  my $all_items_renewer = new TelephoneRenewals::AllItemsRenewer(
+    evergreen_renewal => $evergreen_renewal,
+    phone_menu => $phone_menu,
+    renewal_announcer => $renewal_announcer,
+    renewal_logger => $renewal_logger,
+  );
+
+  my $individual_items_renewer = new TelephoneRenewals::IndividualItemsRenewer(
+    evergreen_renewal => $evergreen_renewal,
+    phone_menu => $phone_menu,
+    renewal_announcer => $renewal_announcer,
+    renewal_logger => $renewal_logger,
+  );
+
+  # (main business logic:)
+  
+  my $call_handler = new TelephoneRenewals::CallHandler(
+    evergreen_renewal => $evergreen_renewal,
+    phone_menu => $phone_menu,
+    all_items_renewer => $all_items_renewer,
+    individual_items_renewer => $individual_items_renewer,
+    logger => $logger,
+  );
+
+  return $call_handler;
+}
+
+sub get_prompt_manager {
+  my ($self) = @_;
+
+  my $agi = new Asterisk::AGI; 
+
+  my $app_config = new TelephoneRenewals::AppConfig;
+
+  my $prompt_store = new TelephoneRenewals::PromptStore(
+    app_config => $app_config
+  );
+
+  my $prompt_manager = new TelephoneRenewals::PromptManager(
+    agi => $agi,
+    prompt_store => $prompt_store,
+  );
+
+  return $prompt_manager;
+}
+
+sub get_sound_index_printer {
+  my ($self) = @_;
+
+  my $app_config = new TelephoneRenewals::AppConfig;
+
+  my $prompt_store = new TelephoneRenewals::PromptStore(
+    app_config => $app_config
+  );
+
+  my $sound_index_printer = new TelephoneRenewals::SoundIndexPrinter(
+    prompt_store => $prompt_store
+  );
+
+  return $sound_index_printer;
+}
+
+1;
+

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/PhoneMenu.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/PhoneMenu.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/PhoneMenu.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,202 @@
+package TelephoneRenewals::PhoneMenu;
+use strict;
+use Carp;
+use warnings;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(agi prompt_store) {
+    if (not($args{$varname})) {
+      croak "PhoneMenu cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub initialize {
+  my ($self) = @_;
+  $|=1; # use unbuffered output, to stop STDOUT from getting plugged
+  my %input = $self->{agi}->ReadParse();
+  $self->{agi_environment} = \%input;
+}
+
+sub answer_and_play_welcome_message {
+  my ($self) = @_;
+  my $agi = $self->{agi};
+
+  $agi->answer;
+  $agi->exec("Wait", "1");
+  $self->_play("welcome_to_the_phone_renewal_system");
+}
+
+sub accept_library_card_number {
+  my ($self) = @_;
+  return $self->_prompt_barcode("please_enter_your_card_number");
+}
+
+sub announce_bad_library_card_number {
+  my ($self) = @_;
+  $self->_play("your_card_number_could_not_be_found");
+}
+
+sub announce_count_of_items_out {
+  my ($self, $count) = @_;
+  $self->_play("you_currently_have");
+  $self->_say_number($count);
+  $self->_play("items_checked_out");
+}
+
+sub announce_no_items_out {
+  my ($self) = @_;
+  $self->_play("you_currently_have_no_items_checked_out");
+}
+
+sub announce_count_of_renewed_items {
+  my ($self, $count) = @_;
+  $self->_say_number($count);
+  $self->_play("of_your_items_have_been_renewed");
+}
+
+sub announce_renewal_success {
+  my ($self, $barcode) = @_;
+  $self->_play("item_with_barcode_ending");
+  $self->_say_digits($barcode);
+  $self->_play("has_been_renewed");
+}
+
+sub announce_renewal_failure_due_to_renewal_limitations {
+  my ($self, $barcode) = @_;
+  $self->_play("item_with_barcode_ending");
+  $self->_say_digits($barcode);
+  $self->_play("may_not_be_renewed_at_this_time");
+}
+
+sub announce_renewal_failure_due_to_unknown_barcode {
+  my ($self, $barcode) = @_;
+  $self->_play("barcode");
+  $self->_say_digits($barcode);
+  $self->_play("was_not_recognized"); 
+}
+
+sub announce_renewal_failure_due_to_error {
+  my ($self, $barcode) = @_;
+  $self->_play("barcode");
+  $self->_say_digits($barcode);
+  $self->_play("could_not_be_renewed_due_to_error");
+}
+
+sub announce_unexpected_error {
+  my ($self) = @_;
+  $self->_play("unexpected_error_occurred");
+}
+
+sub announce_some_items_failed_to_renew {
+  my ($self) = @_;
+  $self->_play("some_items_could_not_be_renewed");
+}
+
+sub prompt_for_barcode {
+  my ($self) = @_;
+  return $self->_prompt_barcode("please_enter_barcode");
+}
+
+sub prompt_for_details {
+  my ($self) = @_;
+  return $self->_prompt_choice(
+    "press_1_to_hear_renewal_details",
+    1 => "yes",
+    0 => "no",
+    fail => "no"
+  );
+}
+
+sub prompt_to_continue_individual_renewal {
+  my ($self) = @_;
+  return $self->_prompt_choice(
+    "press_1_to_continue_renewing_individual_items",
+    1 => "yes",
+    0 => "no",
+    fail => "no"
+  );
+}
+
+sub prompt_to_renew_items {
+  my ($self) = @_;
+  return $self->_prompt_choice(
+    "press_1_to_renew_all_or_press_2_for_individual",
+    1 => "all",
+    2 => "individual",
+    0 => "exit",
+    fail => "exit"
+  );
+}
+
+sub say_goodbye_and_hangup {
+  my ($self) = @_;
+  $self->_play("thanks_for_calling");
+  $self->_play("call_our_office_for_further_assistance");
+  $self->_play("goodbye");
+  $self->{agi}->hangup;
+}
+
+# HELPERS
+
+sub _play {
+  my ($self, $sound_name) = @_;
+  my $agi = $self->{agi};
+
+  my $sound_file = $self->{prompt_store}->sound_file($sound_name);
+  $self->{agi}->stream_file($sound_file);
+}
+
+sub _prompt_barcode {
+  my ($self,$sound_name) = @_;
+  my $input = $self->{agi}->get_data(
+    $self->{prompt_store}->sound_file($sound_name),
+    5000, 
+    14
+  );
+  return $input;
+}
+
+sub _prompt_choice {
+  my ($self,$sound_name,%choices) = @_;
+  my ($tries,$max) = (0,3);
+  while ($tries < $max) {
+    $tries++;
+    my $input = $self->{agi}->get_data(
+      $self->{prompt_store}->sound_file($sound_name),
+      5000, 
+      1
+    );
+    if (defined $input) {
+      my $result = $choices{$input};
+      if (defined $result) {
+        return $result;
+      }
+    }
+  }
+  my $fallback = $choices{fail};
+  if (defined $fallback) {
+    return $fallback;
+  } else {
+    return "fail";
+  }
+}
+
+sub _say_number {
+  my ($self,$count) = @_;
+  $self->{agi}->say_number("$count");
+}
+
+sub _say_digits {
+  my ($self,$digit_string) = @_;
+  $self->{agi}->say_digits("$digit_string");
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/PromptManager.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/PromptManager.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/PromptManager.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,173 @@
+package TelephoneRenewals::PromptManager;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(agi prompt_store) {
+    if (not($args{$varname})) {
+      croak "PromptManager cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub handle_call {
+  my ($self) = @_;
+  my $agi = $self->{agi};
+  my $prompt_store = $self->{prompt_store};
+
+  # Answer
+  $self->_initialize_agi;
+  $agi->answer;
+  $agi->exec("Wait", "1");
+  $self->_play("prompt_manager_intro");
+
+  eval {
+    # Main menu
+    my $in_main_menu = 1;
+    while ($in_main_menu) {
+      my $choice = $self->_prompt_choice(
+        "prompt_manager_main_menu",
+        1 => "individual_prompt",
+        2 => "all_prompts",
+        0 => "exit",
+        fail => "exit"
+      );
+      if ($choice eq "individual_prompt") {
+        $self->_edit_individual_prompt;
+      } elsif ($choice eq "all_prompts") {
+        $self->_edit_all_prompts;
+      } elsif ($choice eq "exit") {
+        $in_main_menu = 0;
+      }
+    }
+  };
+  if ($@) {
+    print STDERR $@;
+    $self->_play("prompt_manager_error");
+  }
+  $self->_play("prompt_manager_exit");
+  $agi->hangup;
+}
+
+# Private helpers
+
+sub _initialize_agi {
+  my ($self) = @_;
+  $|=1; # use unbuffered output, to stop STDOUT from getting plugged
+  my %input = $self->{agi}->ReadParse();
+  $self->{agi_environment} = \%input;
+}
+
+sub _play {
+  my ($self, $sound_name) = @_;
+  my $agi = $self->{agi};
+  my $sound_file = $self->{prompt_store}->sound_file($sound_name);
+  $self->{agi}->stream_file([$sound_file], '0');
+}
+
+sub _prompt_choice {
+  my ($self,$sound_name,%choices) = @_;
+  my ($tries,$max) = (0,3);
+  while ($tries < $max) {
+    $tries++;
+    my $input = $self->{agi}->get_data(
+      $self->{prompt_store}->sound_file($sound_name),
+      5000, 
+      1
+    );
+    if (defined $input) {
+      my $result = $choices{$input};
+      if (defined $result) {
+        return $result;
+      }
+    }
+  }
+  my $fallback = $choices{fail};
+  if (defined $fallback) {
+    return $fallback;
+  } else {
+    return "fail";
+  }
+}
+
+sub _edit_individual_prompt {
+  my ($self) = @_;
+  my $agi = $self->{agi};
+
+  # Get prompt number
+  my $prompt_number = $self->{agi}->get_data(
+    $self->{prompt_store}->sound_file("prompt_manager_ask_for_prompt_number"),
+    5000,
+    3
+  );
+
+  # Lookup the sound file by prompt number
+  my $sound_file = $self->{prompt_store}->sound_file_for_prompt_number($prompt_number);
+  
+  $self->_review_and_record_prompt($prompt_number, $sound_file);
+}
+
+sub _edit_all_prompts {
+  my ($self) = @_;
+  my $agi = $self->{agi};
+  
+  my $all_prompt_numbers = $self->{prompt_store}->all_prompt_numbers;
+  foreach my $prompt_number (@$all_prompt_numbers) {
+    my $sound_file = $self->{prompt_store}->sound_file_for_prompt_number($prompt_number);
+    $self->_review_and_record_prompt($prompt_number, $sound_file);
+  }
+}
+
+
+sub _review_and_record_prompt {
+  my ($self, $prompt_number, $sound_file) = @_;
+  my $agi = $self->{agi};
+
+  # Recording menu:
+  my $in_record_menu = 1;
+  while ($in_record_menu) {
+    # Play the current sound file
+    $self->_play("prompt_manager_prompt_number");
+    $agi->say_number($prompt_number,'0');
+    $agi->stream_file("beep");
+    $self->{agi}->stream_file($sound_file, '0');
+    $agi->stream_file("beep");
+
+    my $action = $self->_prompt_choice(
+      "prompt_manager_recording_menu",
+      1 => "record",
+      2 => "replay",
+      0 => "continue",
+      fail => "continue"
+    );
+    if ($action eq "record") {
+      $self->{agi}->record_file(
+        $sound_file, # path to sound file, MINUS the extension
+        "gsm", # type of sound file
+        "#*1234567890",  # digit(s) that will stop the recording
+        30000, # max time (in millis) for a recording.
+        0, # sound file offset 
+        1, # beep?
+        2  # amount of silence to treat as "i'm done"
+      );
+
+    } elsif ($action eq "replay") {
+      # Let the menu start again
+
+    } elsif ($action eq "continue") {
+      # Be done
+      $in_record_menu = 0;
+    }
+  }
+
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/PromptStore.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/PromptStore.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/PromptStore.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,125 @@
+package TelephoneRenewals::PromptStore;
+use strict;
+use warnings;
+use File::Basename;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(app_config) {
+    if (not($args{$varname})) {
+      croak "PromptStore cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  $self->{sounds_dir} = $self->{app_config}->sounds_dir;
+
+
+  bless $self, ref $class || $class;
+
+  $self->_initialize_prompt_list;
+  return $self;
+}
+
+sub sound_file {
+  my ($self,$name) = @_;
+  return $self->{sounds_dir} . "/" . $name;
+}
+
+sub sound_file_for_prompt_number {
+  my ($self,$prompt_number) = @_;
+  my $sound_name = $self->sound_name_for_prompt_number($prompt_number);
+  return $self->sound_file($sound_name);
+}
+
+sub sound_name_for_prompt_number {
+  my ($self,$prompt_number) = @_;
+  my $sound_name = $self->{prompt_index}->{$prompt_number};
+  if (not(defined $sound_name) || $sound_name eq '') {
+    $sound_name = "$prompt_number";
+  }
+  return $sound_name;
+}
+
+sub all_prompt_numbers {
+  my ($self) = @_;
+  my $index = $self->{prompt_index};
+  my @sorted = sort(keys(%$index));
+  return \@sorted;
+}
+
+# PRIVATE HELPERS:
+
+sub _initialize_prompt_list {
+  my ($self) = @_;
+
+  # Make a hash ref to store mappings like "101" => "my_sound_name": 
+  $self->{prompt_index} = {};
+  # Create a little subroutine for easy adding of sounds to the store.
+  # This will auto-number new entries, starting at $next_number,
+  # counting up $number_step at a time.
+  my $next_number = 100;
+  my $number_step = 1;
+  my $add_sound = sub {
+    my($name) = @_;
+    $self->{prompt_index}->{"$next_number"} = $name;
+    $next_number += $number_step;
+  };
+
+  # Add the names of all sounds that we're going to use in the app:
+  &$add_sound("welcome_to_the_phone_renewal_system");
+
+  &$add_sound("please_enter_your_card_number");
+
+  &$add_sound("your_card_number_could_not_be_found");
+
+  &$add_sound("you_currently_have");
+  &$add_sound("items_checked_out");
+
+  &$add_sound("you_currently_have_no_items_checked_out");
+
+  &$add_sound("unexpected_error_occurred");
+
+  &$add_sound("press_1_to_renew_all_or_press_2_for_individual");
+
+  &$add_sound("of_your_items_have_been_renewed");
+
+  &$add_sound("some_items_could_not_be_renewed");
+
+  &$add_sound("press_1_to_hear_renewal_details");
+
+  &$add_sound("item_with_barcode_ending");
+  &$add_sound("has_been_renewed");
+  &$add_sound("may_not_be_renewed_at_this_time");
+  &$add_sound("could_not_be_renewed_due_to_error");
+
+  &$add_sound("please_enter_barcode");
+
+  &$add_sound("barcode");
+  &$add_sound("was_not_recognized");
+
+  &$add_sound("press_1_to_continue_renewing_individual_items");
+
+  &$add_sound("thanks_for_calling");
+  &$add_sound("call_our_office_for_further_assistance");
+  &$add_sound("goodbye");
+
+  &$add_sound("prompt_manager_intro");
+  &$add_sound("prompt_manager_main_menu");
+  &$add_sound("prompt_manager_ask_for_prompt_number");
+  &$add_sound("prompt_manager_prompt_number");
+  &$add_sound("prompt_manager_is_currently");
+  &$add_sound("prompt_manager_recording_menu");
+  &$add_sound("prompt_manager_error");
+  &$add_sound("prompt_manager_exit");
+
+  &$add_sound("dummy_message1");
+  &$add_sound("dummy_message2");
+
+}
+
+1;
+

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalAnnouncer.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalAnnouncer.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalAnnouncer.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,45 @@
+package TelephoneRenewals::RenewalAnnouncer;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(phone_menu logger) {
+    if (not($args{$varname})) {
+      croak "RenewalAnnouncer cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+# need to add an annouce for COPY_NEEDED_FOR_HOLD
+sub announce_renewal_result {
+  my ($self, $renewal_result) = @_;
+  my $phone_menu = $self->{phone_menu};
+  my $status = $renewal_result->status;
+  my $barcode = $renewal_result->barcode;
+  my $patron = $renewal_result->patron;
+  my $barcode_last_5 = $renewal_result->last_5_digits_of_barcode;
+
+  if ($status eq "SUCCESS") {
+    $phone_menu->announce_renewal_success($barcode_last_5);
+  }
+  elsif ($status eq "ASSET_COPY_NOT_FOUND") {
+    $phone_menu->announce_renewal_failure_due_to_unknown_barcode($barcode);
+  } 
+  elsif ($status =~ /COPY_NEEDED_FOR_HOLD|COPY_CIRC_NOT_ALLOWED|MAX_RENEWALS_REACHED|ACTION_CIRCULATION_NOT_FOUND/) {
+    $phone_menu->announce_renewal_failure_due_to_renewal_limitations($barcode_last_5);
+  }
+  else {
+    $self->{logger}->log_and_email_error("Renewal result contained unexpected status '$status' for patron $patron barcode $barcode");
+    $phone_menu->announce_renewal_failure_due_to_error($barcode);
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalLogger.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalLogger.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalLogger.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,38 @@
+package TelephoneRenewals::RenewalLogger;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(logger) {
+    if (not($args{$varname})) {
+      croak "RenewalLogger cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub info {
+  my ($self, $message) = @_;
+  $self->{logger}->info($message);
+}
+
+sub log_result {
+  my ($self, $renewal_result) = @_;
+  my $status = $renewal_result->status;
+  my $barcode = $renewal_result->barcode;
+  my $patron = $renewal_result->patron;
+  if ($status eq "SUCCESS") {
+    $self->{logger}->info("Renewed OK: $patron - $barcode");
+  } else {
+    $self->{logger}->info("Renewal FAILED: $patron - $barcode - $status");
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalResult.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalResult.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalResult.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,58 @@
+package TelephoneRenewals::RenewalResult;
+use strict;
+use warnings;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  $self->{status} = $args{status};
+  $self->{barcode} = $args{barcode};
+  $self->{patron} = $args{patron};
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub status {
+  my ($self, $status) = @_;
+  if (defined($status)) {
+    $self->{status} = $status;
+  } else {
+    return $self->{status};
+  }
+}
+
+sub barcode {
+  my ($self, $barcode) = @_;
+  if (defined($barcode)) {
+    $self->{barcode} = $barcode;
+  } else {
+    return $self->{barcode};
+  }
+}
+
+sub patron {
+  my ($self, $patron) = @_;
+  if (defined($patron)) {
+    $self->{patron} = $patron;
+  } else {
+    return $self->{patron};
+  }
+}
+
+sub last_5_digits_of_barcode {
+  my ($self) = @_;
+  my $barcode = $self->{barcode};
+  if (not($barcode)) {
+    return "";
+  }
+  my $length = length($barcode);
+  if ($length <= 5) {
+    return $barcode;
+  } else {
+    return substr($barcode, $length - 5);
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalResultSet.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalResultSet.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/RenewalResultSet.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,73 @@
+package TelephoneRenewals::RenewalResultSet;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  $self->{status} = $args{status} || "";
+  $self->{successful_renewals} = $args{successful_renewals} || [];
+  $self->{failed_renewals} = $args{failed_renewals} || [];
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub add_successful_renewal {
+  my ($self, $renewal) = @_;
+  my $listref = $self->successful_renewals;
+  push(@$listref, $renewal);
+}
+
+sub add_failed_renewal {
+  my ($self, $renewal) = @_;
+  my $listref = $self->failed_renewals;
+  push(@$listref, $renewal);
+}
+
+# Accessors:
+
+sub status {
+  my ($self, $status) = @_;
+  if (defined($status)) {
+    $self->{status} = $status;
+  } else {
+    return $self->{status};
+  }
+}
+
+sub successful_renewals {
+  my ($self, $successful_renewals) = @_;
+  if (defined($successful_renewals)) {
+    $self->{successful_renewals} = $successful_renewals;
+  } else {
+    return $self->{successful_renewals};
+  }
+}
+
+sub failed_renewals {
+  my ($self, $failed_renewals) = @_;
+  if (defined($failed_renewals)) {
+    $self->{failed_renewals} = $failed_renewals;
+  } else {
+    return $self->{failed_renewals};
+  }
+}
+
+sub count_successful_renewals {
+  my $self = shift;
+  my $listref = $self->{successful_renewals};
+  my $count = @$listref;
+  return $count;
+}
+
+sub count_failed_renewals {
+  my $self = shift;
+  my $listref = $self->{failed_renewals};
+  my $count = @$listref;
+  return $count;
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/TelephoneRenewals/SoundIndexPrinter.pm
===================================================================
--- grpl/trunk/phone_renewal/lib/TelephoneRenewals/SoundIndexPrinter.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/TelephoneRenewals/SoundIndexPrinter.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,36 @@
+package TelephoneRenewals::SoundIndexPrinter;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my ($class, %args) = @_;
+  my $self = {};
+
+  foreach my $varname qw(prompt_store) {
+    if (not($args{$varname})) {
+      croak "SoundIndexPrinter cannot be built without a '$varname' object.";
+    }
+    $self->{$varname} = $args{$varname};
+  }
+
+  bless $self, ref $class || $class;
+  return $self;
+}
+
+sub print {
+  my ($self, $io) = @_;
+  my $prompt_store = $self->{prompt_store};
+
+  print $io "                         Phone Renewal Prompts\n";
+  print $io "#      Name\n";
+  print $io "----   ------------------------------------------------------------\n";
+
+  my $numbers = $prompt_store->all_prompt_numbers;
+  foreach my $number (@$numbers) {
+    my $name = $prompt_store->sound_name_for_prompt_number($number);
+    print $io "$number  - $name\n";
+  }
+}
+
+1;

Added: grpl/trunk/phone_renewal/lib/prompt_manager.agi.pl
===================================================================
--- grpl/trunk/phone_renewal/lib/prompt_manager.agi.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/prompt_manager.agi.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+use strict;
+use File::Basename;
+use lib dirname(__FILE__);
+
+use TelephoneRenewals::ObjectContext;
+
+my $objectContext = new TelephoneRenewals::ObjectContext;
+my $prompt_manager = $objectContext->get_prompt_manager();
+$prompt_manager->handle_call();


Property changes on: grpl/trunk/phone_renewal/lib/prompt_manager.agi.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/lib/telephone_renewal_menu.agi.pl
===================================================================
--- grpl/trunk/phone_renewal/lib/telephone_renewal_menu.agi.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/telephone_renewal_menu.agi.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+use strict;
+use File::Basename;
+use lib dirname(__FILE__);
+
+use TelephoneRenewals::ObjectContext;
+
+my $objectContext = new TelephoneRenewals::ObjectContext;
+my $call_handler = $objectContext->get_call_handler();
+$call_handler->handle_call();


Property changes on: grpl/trunk/phone_renewal/lib/telephone_renewal_menu.agi.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/lib/test_against_fake_asterisk.pl
===================================================================
--- grpl/trunk/phone_renewal/lib/test_against_fake_asterisk.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/test_against_fake_asterisk.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use strict;
+use File::Basename;
+use lib dirname(__FILE__);
+
+use TelephoneRenewals::ObjectContext;
+
+my $objectContext = new TelephoneRenewals::ObjectContext;
+my $call_handler = $objectContext->get_call_handler(
+  fake_phone_menu => 1,
+  log_file => "deleteme_testing.log",
+  disable_error_email => 1,
+#  smtp_host_and_port => "anubis:2525",
+#  error_email_recipients => 'crosby at atomicobject.com',
+);
+$call_handler->handle_call();


Property changes on: grpl/trunk/phone_renewal/lib/test_against_fake_asterisk.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/lib/test_against_fake_asterisk_and_fake_evergreen.pl
===================================================================
--- grpl/trunk/phone_renewal/lib/test_against_fake_asterisk_and_fake_evergreen.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/test_against_fake_asterisk_and_fake_evergreen.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+use strict;
+use File::Basename;
+use lib dirname(__FILE__);
+
+use TelephoneRenewals::ObjectContext;
+
+my $objectContext = new TelephoneRenewals::ObjectContext;
+my $call_handler = $objectContext->get_call_handler(
+  fake_evergreen_renewal => 1,
+  fake_phone_menu => 1,
+  log_file => "deleteme_testing.log",
+  disable_error_email => 1,
+#  smtp_host_and_port => "anubis:2525",
+#  error_email_recipients => 'crosby at atomicobject.com',
+);
+$call_handler->handle_call();


Property changes on: grpl/trunk/phone_renewal/lib/test_against_fake_asterisk_and_fake_evergreen.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/lib/test_against_fake_evergreen.pl
===================================================================
--- grpl/trunk/phone_renewal/lib/test_against_fake_evergreen.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/lib/test_against_fake_evergreen.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use strict;
+use File::Basename;
+use lib dirname(__FILE__);
+
+use TelephoneRenewals::ObjectContext;
+
+my $objectContext = new TelephoneRenewals::ObjectContext;
+my $call_handler = $objectContext->get_call_handler(
+  fake_evergreen_renewal => 1,
+#  log_file => "deleteme_testing.log",
+  disable_error_email => 1,
+#  smtp_host_and_port => "anubis:2525",
+#  error_email_recipients => 'crosby at atomicobject.com',
+);
+$call_handler->handle_call();


Property changes on: grpl/trunk/phone_renewal/lib/test_against_fake_evergreen.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/print_sound_index.pl
===================================================================
--- grpl/trunk/phone_renewal/print_sound_index.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/print_sound_index.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,12 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use lib "lib";
+
+use TelephoneRenewals::ObjectContext;
+
+my $object_context = new TelephoneRenewals::ObjectContext;
+my $sound_index_printer = $object_context->get_sound_index_printer;
+
+$sound_index_printer->print(*STDOUT);


Property changes on: grpl/trunk/phone_renewal/print_sound_index.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/run_tests.pl
===================================================================
--- grpl/trunk/phone_renewal/run_tests.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/run_tests.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,35 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+# Accumulators:
+my $ok = 0;
+my $not_ok = 0;
+
+# Run the actual driver script, capture line-by-line results and track pass/fail:
+open TESTPROC, "perl t/unit_tests.t|" or die "MAN! $!";
+while(<TESTPROC>) {
+  print $_;
+  $ok += 1 if ($_ =~ /^ok/);
+  $not_ok += 1 if ($_ =~ /^not ok/);
+}
+close TESTPROC;
+
+# Indicate failure if needed
+if ($not_ok) {
+  print "!!! FAILURES !!!\n";
+}
+
+# Print short summary
+my $total = $ok + $not_ok;
+print "$total total, $ok passed";
+if ($not_ok) {
+  print ", $not_ok FAILED";
+} else {
+  print ", all ok.";
+}
+print "\n";
+
+# Exit 1 if failures, 0 otherwise
+exit 1 if $not_ok;
+exit 0;


Property changes on: grpl/trunk/phone_renewal/run_tests.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/sounds/barcode.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/barcode.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/call_our_office_for_further_assistance.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/call_our_office_for_further_assistance.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/could_not_be_renewed_due_to_error.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/could_not_be_renewed_due_to_error.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/dummy_message1.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/dummy_message1.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/dummy_message2.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/dummy_message2.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/goodbye.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/goodbye.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/has_been_renewed.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/has_been_renewed.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/item_with_barcode_ending.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/item_with_barcode_ending.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/items_checked_out.gsm
===================================================================
--- grpl/trunk/phone_renewal/sounds/items_checked_out.gsm	                        (rev 0)
+++ grpl/trunk/phone_renewal/sounds/items_checked_out.gsm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,11 @@
+ÕiÕ¦P`I$’HãS¥FÛq¸ç]¯IxbÔà\ÿ®z¹ÔçÅ!%zî”P†úìÔ®G}Å–î#>Éc˜ì¸¦VCBÔ鬥ä•,¶î8ä”ì·Û…"©O®ë’7\‹l·Sl¶·Öh{e¼¦Ì¾ªQøу²6Ó}Jã…
++&2¡€°/d’ÆóÖiC&3,FÒ£pjvŠx›ø<Kw,•âŠè›î¬ÇLüäÔáTv"qhÞävF’wLr£rGé&Æ£^(„ã	çcV6OÔâCöé~§ZÅ÷4YqG6ìêLàÄ´”,_ÜD]Û­XÒמ˜‘䌣¦ÅÛû²ä¦6êÂžUH½zYp³lªe³6õÔ¢Zª´›KZ'{em,k"mHŸoH(]Ý•k´»qË[Õ&CZ»Ñ¨8âK—i†iu(üiHU<‰F¡gL.ÜnÆÛÕ(RÚ:Ïk¦×Q·-ͦZ‘0—×géX›¶ù^¨·Œþ(‹ÔèbÙºËÅ^]W$fe„ôœjÆÛÉ…úÛMÑceè6UÇÓc{Y4Ö¨Ãeù€ÌËG7ËnGʧ·"~8œÌãÆZ/·Ò^e-{ÐÃO,†Íc–¤=ÊÍebÈýÕ§É#˜cÖÝÒ]l±ûeEJ£j5ÔË"¨ïŠ¢£ËÁõW§’eÃGm¨ßÒ_l®sË¡Š,I©3e$K"‰´|Ë"L³ñ´’gáQž±XsÒ |j«gâF䍨¨Í¡ç$š#icIci8§Ïag‹ž#Ò^”f3ÑÁ!ìázÓÂÖ›	¹­m#?#e5
+ßd§%ºŽÕ’ƒ%uÛå(}µÉ.q¨nGSw&b7cè…)guŸÚ”B-…(™#nIÜÔ£Ñ\Έ̞¢½ô\ðÃümrPaÜ(½\”d‚Kp\´ÐƒQó¶ðÅBΟG%"ë$Hï)+ÝÚaºÓd"”7‰e}C
+„m3ÐÁæYw‹
+º¦‰µmÉ×jÚcV ÌÛq¶äÞ`²ëÏWZà@#nIz HãqÈäÚdrä`Hã’9#ð`FãŽÉ#Ô FåqÈÛtÀ7’6ÜÙ¢’XÛÜ€IŽWXÀI#nG$¨€K#mÉ#~ 8܍ÆÚÚ2Ãb3é¬Ç$ÉÆZ,¶vÖÔ†f5wPÇb¾ç!Ü»X×Úòýñ’åi{‹.70)a£fÁ±‡j3$“
+á…èüd
+í¡Úòý¥“³Hu©¬*˜ÉE¢˜{çIÅÖq%—bÆñ|t›Ùòým¬ª:œu*ú¾©84ªb
+úR¶ã×H%:¦
+˜Ú3õ²çm„É>µq+ºl¢G$ƒ
+M1ô}ßâclÙ´älËRÌü²6³œËkSÒJÈ\àŒþÄ’$õŠé ãÕ-¦ÖçBf¬ ¯I$dU`ë;‘’ÚV/’l¤k08‹êFëÖ(L&knHÜi#ÛØÉ5ìõXÜͮܖIcߊe[ϳgÖ)k¦+së7"´¦„ÉD>±Îw«­%aËRñn¶ÝjV××-{©¬ž*“ïnÉ,ƒÌ¦ÑÝv«%2^Zã‡m(ºzY"Ö®cåjŽ¨‡öˆ”H,räNGšÇøZLÏ¢èUr'"ÕìkñªœBؘÌ–²Bî\î·$–"9*>¥[Ü!4ÛtkÔkÊ(ìâa;¢·JÝØ ÈÊ’KÖÀªšZG$è ŒÕ]#Õ¥SÞq£åG+¬[ºmªhë…0œe6’FAa£oy#–ÖäÖ*Tª†®I`×ã¨é×™R´ ÏHOv9m©±ÆüÖksa|šŠåi³3Ë´Ð^ähÓ#’Õì4ŽJÕí{ìüƒî·mñ›ž%ýFb9)8Ùñ¸äo6܍ÆzÕ¯”h¶†Êukv)m‡,7GéâêðZæ ‡-¦<‘ÈÜÕp½¬'#’$Pˆ`žå&•‰§+M6¹ ‹µmÅÔ¶d}–Åe(ç¬C]*
+µ–©Èâiw$Êc{JfIŸÔ²dY.™§¨ëƒÈålX+qË]½¥6Yj¨úê§û¯QEÔ³[Ý6‹IFÛK¹+®È¦¨š‹I6{–:äð™±ZÜÕ1cYgĺ3‰ì±×F8΢ÄÔ‹Ç6œéÇèEÜRÉÕ.LÞÁF¬¢qÆ<à¥îÍD±‹(ÆÛkÆ侺ª£Õ-L'‹¥6øš¾èd:[J¥ÔÊäFZD¥?Ú%Eh]WÔ«<£‰ÆÛ‹ÇmŒ!ö$¹î‚$Ÿª¸åî¢l„ƒÕ¨YcR€ù¢ÒE#Ö Ku²Ü]Ô Æ”†IŠ )dŠTÌÕç2£‹ 84µû+‰ 'Q1)‹ É2Å#ˆàBËTÙ.Ùo’Þ$©âÆäqÉÐSç5ûHY^Ç+s+5‰Càâ–<cÙ®ÝiʏòmkVå¹'Kaá¹!—¥ÏQ‹¯‹&:b–dÙnÌáF̦(}ÚÒÈBåázå¶#_‘¹#Z`8¥’[$
\ No newline at end of file

Added: grpl/trunk/phone_renewal/sounds/may_not_be_renewed_at_this_time.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/may_not_be_renewed_at_this_time.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/of_your_items_have_been_renewed.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/of_your_items_have_been_renewed.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/please_enter_barcode.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/please_enter_barcode.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/please_enter_your_card_number.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/please_enter_your_card_number.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/press_1_to_continue_renewing_individual_items.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/press_1_to_continue_renewing_individual_items.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/press_1_to_hear_renewal_details.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/press_1_to_hear_renewal_details.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/press_1_to_renew_all_or_press_2_for_individual.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/press_1_to_renew_all_or_press_2_for_individual.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/prompt_manager_ask_for_prompt_number.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/prompt_manager_ask_for_prompt_number.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/prompt_manager_error.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/prompt_manager_error.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/prompt_manager_exit.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/prompt_manager_exit.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/prompt_manager_intro.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/prompt_manager_intro.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/prompt_manager_is_currently.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/prompt_manager_is_currently.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/prompt_manager_main_menu.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/prompt_manager_main_menu.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/prompt_manager_prompt_number.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/prompt_manager_prompt_number.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/prompt_manager_recording_menu.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/prompt_manager_recording_menu.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/some_items_could_not_be_renewed.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/some_items_could_not_be_renewed.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/thanks_for_calling.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/thanks_for_calling.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/unexpected_error_occurred.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/unexpected_error_occurred.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/was_not_recognized.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/was_not_recognized.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/welcome_to_the_phone_renewal_system.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/welcome_to_the_phone_renewal_system.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/you_currently_have.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/you_currently_have.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/you_currently_have_no_items_checked_out.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/you_currently_have_no_items_checked_out.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/sounds/your_card_number_could_not_be_found.gsm
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/sounds/your_card_number_could_not_be_found.gsm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/store_updated_sounds.pl
===================================================================
--- grpl/trunk/phone_renewal/store_updated_sounds.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/store_updated_sounds.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,31 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my $sounds_from = "/var/lib/asterisk/sounds/phone_renewals";
+my $sounds_to = "sounds";
+
+sub sh {
+  my ($cmd) = @_;
+  print "$cmd\n";
+  print `$cmd`;
+}
+
+if (not (-d $sounds_from)) {
+  print "Sound directory $sounds_from doesn't exist?\n";
+  exit 1;
+}
+
+sh "sudo cp $sounds_from/*.* $sounds_to/";
+print "Copied sound files from $sounds_from\n";
+sh "svn status sounds";
+
+print "Commit these sounds to svn? [y|N] ";
+my $answer = <STDIN>;
+if ($answer =~ /^y/i) {
+  sh "svn ci -m \"Updated sound files from $sounds_from\" sounds";
+} else { 
+  print "Sound files NOT checked in; don't forget to commit them using 'svn commit' when you're done.\n";
+}
+exit 0
+


Property changes on: grpl/trunk/phone_renewal/store_updated_sounds.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/t/tlib/AllItemsRenewerTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/AllItemsRenewerTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/AllItemsRenewerTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,180 @@
+package AllItemsRenewerTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::AllItemsRenewer;
+use TelephoneRenewals::RenewalResult;
+use TelephoneRenewals::RenewalResultSet;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_phone_menu", 
+    "mock_evergreen_renewal",
+    "mock_renewal_announcer",
+    "mock_renewal_logger",
+  );
+
+  $self->{all_items_renewer} = new TelephoneRenewals::AllItemsRenewer(
+    evergreen_renewal => $self->{mock_evergreen_renewal},
+    phone_menu => $self->{mock_phone_menu},
+    renewal_announcer => $self->{mock_renewal_announcer},
+    renewal_logger => $self->{mock_renewal_logger},
+  );
+
+  $self->{result_set} = new TelephoneRenewals::RenewalResultSet(
+    status => "ok",
+    successful_renewals => [ "good1", "good2", "good3" ]
+  );
+  $self->{successful_renewal_count} = 3;
+
+  $self->configure_mock("mock_evergreen_renewal", 
+    { renew_all_items => $self->{result_set} }
+  );
+
+  $self->configure_mock("mock_phone_menu", 
+    { announce_count_of_renewed_items => "unused" },
+    { prompt_for_details => "yes" },
+    { announce_some_items_failed_to_renew => "unused" },
+  );
+
+  $self->configure_mock("mock_renewal_announcer", 
+    { announce_renewal_result => "unused" },
+  );
+
+  $self->configure_mock("mock_renewal_logger", 
+    { info => "unused" },
+    { log_result => "unused" },
+  );
+
+}
+
+# For executing the method under test
+sub execute {
+  my $self = shift;
+  $self->{all_items_renewer}->renew_all_items("libcardnum");
+}
+
+# TESTS
+
+sub test_AllItemsRenewer_should_renew_all_items_and_announce_count_of_renewed_items {
+  my $self = shift;
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_evergreen_renewal",
+    { "renew_all_items" => [ "libcardnum" ] },
+  );
+  $self->assert_methods_called("mock_phone_menu",
+    { "announce_count_of_renewed_items" => [ $self->{successful_renewal_count} ] },
+  );
+}
+
+sub test_AllItemsRenewer_should_log_all_renewal_results_on_success {
+  my $self = shift;
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_renewal_logger",
+    { "info" => [ "Patron libcardnum renewing all items..." ] },
+    { "log_result" => [ "good1" ] },
+    { "log_result" => [ "good2" ] },
+    { "log_result" => [ "good3" ] },
+  );
+}
+
+sub test_AllItemsRenewer_should_log_all_renewal_results_on_failure {
+  my $self = shift;
+
+  $self->{result_set}->status("failures");
+  $self->{result_set}->failed_renewals(["bad1","bad2"]);
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_renewal_logger",
+    { "info" => [ "Patron libcardnum renewing all items..." ] },
+    { "log_result" => [ "bad1" ] },
+    { "log_result" => [ "bad2" ] },
+    { "log_result" => [ "good1" ] },
+    { "log_result" => [ "good2" ] },
+    { "log_result" => [ "good3" ] },
+  );
+}
+
+sub test_AllItemsRenewer_should_ask_if_user_wants_details_if_no_failures {
+  my $self = shift;
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { "prompt_for_details" => []  },
+  );
+}
+
+sub test_AllItemsRenewer_should_announce_successful_renewal_details_upon_request {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->set_always("prompt_for_details", "yes");
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { "prompt_for_details" => []  }
+  );
+
+  $self->assert_methods_called("mock_renewal_announcer",
+    { "announce_renewal_result" => [ "good1" ] },
+    { "announce_renewal_result" => [ "good2" ] },
+    { "announce_renewal_result" => [ "good3" ] },
+  );
+}
+
+sub test_AllItemsRenewer_should_not_announce_details_if_user_says_no {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->set_always("prompt_for_details", "no");
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { "prompt_for_details" => []  }
+  );
+
+  $self->assert_methods_not_called("mock_renewal_announcer", "announce_renewal_result");
+  $self->assert_no_more_methods_called("mock_renewal_announcer");
+}
+
+sub test_AllItemsRenewer_should_announce_details_of_successes_and_failures_when_there_are_failures {
+  my $self = shift;
+
+  $self->{result_set}->status("failures");
+  $self->{result_set}->failed_renewals(["bad1","bad2"]);
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_evergreen_renewal",
+    { "renew_all_items" => ["libcardnum"]  }
+  );
+  $self->assert_methods_called("mock_phone_menu",
+    { "announce_some_items_failed_to_renew" => []  }
+  );
+  $self->assert_methods_called("mock_renewal_announcer",
+    { "announce_renewal_result" => [ "bad1" ]  },
+    { "announce_renewal_result" => [ "bad2" ]  },
+    { "announce_renewal_result" => [ "good1" ]  },
+    { "announce_renewal_result" => [ "good2" ]  },
+    { "announce_renewal_result" => [ "good3" ]  },
+  );
+
+  $self->assert_methods_not_called("mock_phone_menu", "prompt_for_details");
+  $self->assert_no_more_methods_called("mock_phone_menu");
+  $self->assert_no_more_methods_called("mock_evergreen_renewal");
+  $self->assert_no_more_methods_called("mock_renewal_announcer");
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/AppConfigTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/AppConfigTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/AppConfigTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,46 @@
+package AppConfigTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::AppConfig;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->{app_config} = new TelephoneRenewals::AppConfig();
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_AppConfig_should_have_settings {
+  my $self = shift;
+  my $app_config = $self->{app_config};
+
+  $self->assert_not_null($app_config->log_file, "No log_file setting.");
+  $self->assert_not_null($app_config->sounds_dir, "No sounds_dir setting.");
+  $self->assert_not_null($app_config->smtp_host_and_port, "No smtp_host_and_port setting.");
+  $self->assert_not_null($app_config->error_email_recipients, "No error_email_recipients setting.");
+  $self->assert_not_null($app_config->error_email_from, "No error_email_from setting.");
+  $self->assert_not_null($app_config->error_email_subject, "No error_email_subject setting.");
+}
+
+sub test_AppConfig_should_clear_smtp_host_and_port {
+  my $self = shift;
+  my $app_config = $self->{app_config};
+
+  $self->assert_not_null($app_config->smtp_host_and_port, "No smtp_host_and_port setting.");
+
+  $app_config->clear_smtp_host_and_port;
+
+  $self->assert_null($app_config->smtp_host_and_port, "smtp_host_and_port not cleared.");
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/CallHandlerTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/CallHandlerTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/CallHandlerTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,292 @@
+package CallHandlerTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::CallHandler;
+use TelephoneRenewals::RenewalResult;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_phone_menu", 
+    "mock_evergreen_renewal",
+    "mock_all_items_renewer",
+    "mock_individual_items_renewer",
+    "mock_logger",
+  );
+
+  $self->{call_handler} = new TelephoneRenewals::CallHandler(
+    evergreen_renewal => $self->{mock_evergreen_renewal},
+    phone_menu => $self->{mock_phone_menu},
+    all_items_renewer => $self->{mock_all_items_renewer},
+    individual_items_renewer => $self->{mock_individual_items_renewer},
+    logger => $self->{mock_logger}
+  );
+
+  $self->configure_mock("mock_phone_menu", 
+    { initialize => "unused" },
+    { answer_and_play_welcome_message => "unused" },
+    { accept_library_card_number => "libcardnum" },
+    { announce_bad_library_card_number => "unused" },
+    { announce_count_of_items_out => "unused" },
+    { prompt_to_renew_items => "random answer" },
+    { say_goodbye_and_hangup => "unused" },
+  );
+
+  $self->{count_of_items_out} = 5;
+
+  $self->configure_mock("mock_evergreen_renewal", 
+    { validate_library_card_number => "valid" },
+    { count_items_out => $self->{count_of_items_out} },
+    { renew_all_items => $self->{renew_all_results} },
+  );
+
+  $self->configure_mock("mock_all_items_renewer", 
+    { renew_all_items => "unused" }
+  );
+
+  $self->configure_mock("mock_individual_items_renewer", 
+    { renew_individual_items => "unused" }
+  );
+
+
+  $self->setup_log_capturing($self->{mock_logger});
+}
+
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_CallHandler_should_answer_call {
+  my $self = shift;
+
+  $self->{call_handler}->handle_call;
+  
+  $self->assert_methods_called("mock_phone_menu", 
+    { initialize => [] },
+    { answer_and_play_welcome_message => [] },
+  );
+  $self->assert_logged("info", "Handling new call ******************************");
+}
+
+
+sub test_CallHandler_should_accept_and_validate_card_number_then_count_items_out {
+  my $self = shift;
+
+  $self->{call_handler}->handle_call;
+
+  $self->assert_methods_called("mock_evergreen_renewal", 
+    { validate_library_card_number => ["libcardnum"] },
+    { count_items_out => ["libcardnum"] },
+  );
+
+  $self->assert_methods_called("mock_phone_menu", 
+    { accept_library_card_number => [] },
+    { announce_count_of_items_out => [ $self->{count_of_items_out}] }
+  );
+
+  $self->assert_logged("info", "Patron libcardnum has " . $self->{count_of_items_out} . " items out.");
+
+  $self->assert_methods_not_called("mock_phone_menu", "announce_bad_library_card_number");
+}
+
+sub test_CallHandler_should_reprompt_for_card_number_when_invalid {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->set_series("accept_library_card_number",
+    "bad num",
+    "another bad num",
+    "a good card"
+  );
+
+  $self->{mock_evergreen_renewal}->set_series("validate_library_card_number",
+    "invalid",
+    "invalid",
+    "valid"
+  );
+
+  $self->{call_handler}->handle_call;
+
+  $self->assert_methods_called("mock_evergreen_renewal", 
+    { validate_library_card_number => ["bad num"] },
+    { validate_library_card_number => ["another bad num"] },
+    { validate_library_card_number => ["a good card"] },
+    { count_items_out => ["a good card"] },
+  );
+
+  $self->assert_methods_called("mock_phone_menu", 
+    { announce_bad_library_card_number => [] },
+    { announce_bad_library_card_number => [] },
+  );
+}
+
+sub test_CallHandler_should_abort_after_3_invalid_card_numbers {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->set_series("accept_library_card_number",
+    "bad num",
+    "another bad num",
+    "still bad",
+    "ASKED TOO MANY TIMES?"
+  );
+
+  $self->{mock_evergreen_renewal}->set_series("validate_library_card_number",
+    "invalid",
+    "invalid",
+    "invalid"
+  );
+
+  $self->{mock_phone_menu}->mock("announce_unexpected_error");
+
+  $self->{call_handler}->handle_call;
+
+  $self->assert_methods_called("mock_evergreen_renewal", 
+    { validate_library_card_number => ["bad num"] },
+    { validate_library_card_number => ["another bad num"] },
+    { validate_library_card_number => ["still bad"] },
+  );
+
+  $self->assert_no_more_methods_called("mock_evergreen_renewal");
+
+  # See we didn't proceed
+  $self->assert_methods_not_called("mock_evergreen_renewal", "count_items_out");
+
+  # See error logged and emailed
+  $self->assert_logged_regexp("log_and_email_error", qr/^Failed to acquire card number from caller after 3 tries. Tried numbers: bad num, another bad num, still bad/);
+#
+#  $self->assert_next_method_call("mock_logger", sub {
+#    my ($method_name, $args) = @_;
+#    $self->assert_equals("log_and_email_error", $method_name);
+#    $self->assert_matches(, @$args[0]);
+#  });
+
+  # See error announced to user, then exited
+  $self->assert_methods_called("mock_phone_menu",
+    { announce_unexpected_error => [] }
+  );
+  $self->assert_hungup_and_finished();
+}
+
+sub test_CallHandler_should_announce_no_items_out_when_the_count_is_zero {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->mock("announce_no_items_out");
+  $self->{mock_evergreen_renewal}->set_always("count_items_out", 0);
+
+  $self->{call_handler}->handle_call;
+
+  $self->assert_methods_not_called("mock_phone_menu", 
+    "announce_count_of_items_out",
+    "prompt_to_renew_items"
+  );
+
+  $self->assert_methods_called("mock_phone_menu", 
+    { announce_no_items_out => [] },
+  );
+
+  $self->assert_hungup_and_finished;
+}
+
+sub test_CallHandler_should_renew_all_items_when_user_chooses_to {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->set_always("prompt_to_renew_items", "all");
+
+  $self->{call_handler}->handle_call;
+
+  $self->assert_methods_called("mock_phone_menu", 
+    { prompt_to_renew_items => [] }
+  );
+  $self->assert_methods_called("mock_all_items_renewer",
+    { renew_all_items => [ "libcardnum" ] }
+  );
+
+  # Show that we didn't execute the individual renewal code
+  $self->assert_methods_not_called("mock_individual_items_renewer", "renew_individual_items");
+
+  $self->assert_hungup_and_finished;
+}
+
+sub test_CallHandler_should_renew_individual_items_when_user_chooses_to {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->set_always("prompt_to_renew_items", "individual");
+
+  $self->{call_handler}->handle_call;
+
+  $self->assert_methods_called("mock_phone_menu", 
+    { prompt_to_renew_items => [] }
+  );
+  $self->assert_methods_called("mock_individual_items_renewer",
+    { renew_individual_items => [ "libcardnum" ] }
+  );
+
+  # Show that we didn't execute the "renew all" code
+  $self->assert_methods_not_called("mock_all_items_renewer", "renew_all_items");
+
+  $self->assert_hungup_and_finished;
+}
+
+sub test_CallHandler_should_calmly_exit_when_user_decides_not_to_renew_anything {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->set_always("prompt_to_renew_items", "never mind");
+
+  $self->{call_handler}->handle_call;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { prompt_to_renew_items => [] }
+  );
+
+  $self->assert_logged("info", "Patron libcardnum decided not to renew any items.");
+
+  $self->assert_methods_not_called("mock_all_items_renewer", "renew_all_items");
+  $self->assert_methods_not_called("mock_individual_items_renewer", "renew_individual_items");
+
+  $self->assert_hungup_and_finished;
+}
+
+sub test_CallHandler_should_warn_user_and_exit_when_an_exception_is_raised {
+  my $self = shift;
+
+  $self->{mock_phone_menu}->mock("accept_library_card_number", sub {
+    croak "CARD NUMBER FAIL";
+  });
+  $self->{mock_phone_menu}->mock("announce_unexpected_error");
+
+  $self->{call_handler}->handle_call;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { accept_library_card_number => [] },
+    { announce_unexpected_error => [] }
+  );
+
+  $self->assert_methods_not_called("mock_evergreen_renewal", "count_items_out");
+
+  $self->assert_hungup_and_finished();
+}
+
+# HELPERS
+
+sub assert_hungup_and_finished {
+  my $self = shift;
+
+  $self->assert_logged("info", "Hanging up.");
+
+  # Make sure we hungup
+  my ($mname,$args) = $self->{mock_phone_menu}->next_call; 
+  $self->assert($mname, "Failed to get 'next_call' from mock_phone_menu when looking for 'say_goodbye_and_hangup'");
+  $self->assert_equals("say_goodbye_and_hangup", $mname);
+  ($mname,$args) = $self->{mock_phone_menu}->next_call; 
+  $self->assert_null($mname, "Expected no further calls on mock_phone_menu");
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/EmailerTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/EmailerTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/EmailerTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,196 @@
+package EmailerTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::Emailer;
+use Test::MockObject;
+
+use File::Basename;
+use Net::SMTP::Server;
+use Net::SMTP::Server::Client;
+
+if ($@) {
+  print "FAILED: $@";
+}
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_app_config"
+  );
+
+  $self->configure_mock("mock_app_config",
+    { "smtp_host_and_port" => "localhost:34343"}
+  );
+
+  $self->{emailer} = new TelephoneRenewals::Emailer(
+    app_config => $self->{mock_app_config}
+  );
+}
+
+sub tear_down {
+  my $self = shift;
+  $self->delete_temp_file;
+}
+
+# TESTS:
+
+sub test_Emailer_should_send_email_via_smtp {
+  my $self = shift;
+
+  $self->start_smtp_server;
+
+  $self->{emailer}->send_email({
+    from => 'commander_test at this.place',
+    to => [ 'recipient1 at other.place', 'recipient2 at other.place' ],
+    subject => "What's up now?",
+    body => "This is from me to you."
+  });
+
+  my $full_message = $self->collect_from_smtp_server;
+
+  $self->assert_matches(qr/From: commander_test\@this.place/mi, $full_message);
+  $self->assert_matches(qr/To: recipient1\@other.place/mi, $full_message);
+  $self->assert_matches(qr/To: recipient2\@other.place/mi, $full_message);
+  $self->assert_matches(qr/Subject: What's up now\?/mi, $full_message);
+  $self->assert_matches(qr/This is from me to you.\s*$/mi, $full_message);
+}
+
+sub test_Emailer_should_croak_with_a_special_message_when_disabled {
+  my $self = shift;
+
+  $self->{mock_app_config}->set_always("smtp_host_and_port", undef);
+  # Rebuild (because the mailer configures itself in the constructor)
+  $self->{emailer} = new TelephoneRenewals::Emailer(
+    app_config => $self->{mock_app_config}
+  );
+
+  eval {
+    $self->{emailer}->send_email({
+      from => 'commander_test at this.place',
+      to => [ 'recipient1 at other.place', 'recipient2 at other.place' ],
+      subject => "What's up now?",
+      body => "This is from me to you."
+    });
+  };
+  my $error = $@;
+  $self->assert_not_null($error, "Expected an error");
+  $self->assert_matches(qr/Emailer is disabled; set AppConfig smtp_host_and_port to enable it/im, $error);
+}
+
+sub test_Emailer_just_lets_fly_with_unexpected_errors {
+  my $self = shift;
+
+  $self->{mock_app_config}->set_always("smtp_host_and_port", "localhost:50001");
+  # Rebuild (because the mailer configures itself in the constructor)
+  $self->{emailer} = new TelephoneRenewals::Emailer(
+    app_config => $self->{mock_app_config}
+  );
+
+  eval {
+    $self->{emailer}->send_email({
+      from => 'commander_test at this.place',
+      to => [ 'recipient1 at other.place', 'recipient2 at other.place' ],
+      subject => "What's up now?",
+      body => "This is from me to you."
+    });
+  };
+  my $error = $@;
+  $self->assert_not_null($error, "Expected an error");
+  $self->assert_matches(qr/failed to connect to mail server/im, $error);
+}
+
+# HELPERS:
+
+sub start_smtp_server {
+  my ($self) = @_;
+
+  my $pid = fork();
+  if (not defined $pid) {
+    croak "Couldn't fork another process";
+  } elsif ($pid == 0) {
+    # Child process: SMTP one-off
+    eval {
+      my $server = new Net::SMTP::Server('localhost', 34343) || croak("Failed to launch server: $!\n");
+      my $conn = $server->accept();
+      my $client = new Net::SMTP::Server::Client($conn) || croak("Unable to handle client connection: $!\n");
+      $client->process();
+      $self->write_temp_file($client->{MSG});
+    };
+    croak "Child process w SMTP server FAIL: $@" if $@;
+    exit 0;
+
+  } else {
+    # Parent
+    $self->{child_pid} = $pid;
+    $self->wait_until_smtp_server_is_available;
+  }
+}
+
+sub temp_file {
+  my $dirname = dirname(__FILE__);
+  return "$dirname/DELETEME_emailer_test.txt";
+}
+
+sub write_temp_file {
+  my ($self,$text) = @_;
+  my $file = $self->temp_file;
+  open(TEMPFH, "> $file") or die "can't open $file: $!";
+  print TEMPFH $text;
+  close TEMPFH;
+}
+
+sub read_temp_file {
+  my ($self) = @_;
+  my $file = $self->temp_file;
+  open(TEMPFH, "< $file") or die "can't open $file: $!";
+  my @lines = <TEMPFH>;
+  close TEMPFH;
+  return join("", at lines);
+}
+
+sub delete_temp_file {
+  my ($self) = @_;
+  unlink $self->temp_file;
+}
+
+sub collect_from_smtp_server {
+  my ($self) = @_;
+  my $pause = 0.2;
+  $self->nap($pause);
+  my $data;
+  my $ok = 0;
+  my $tries = 0;
+  while ($tries < (2/$pause) && (not $ok)) {
+    eval {
+      $data = $self->read_temp_file;
+      $ok = 1;
+    };
+    $tries++;
+    $self->nap($pause) unless $ok;
+  }
+  
+  if (not $ok) {
+    kill 9, $self->{child_pid};
+    croak "FAILED TO COLLECT: $@\n" if (not $ok);
+  } else {
+    waitpid($self->{child_pid},0);
+  }
+
+  return $data;
+}
+
+sub wait_until_smtp_server_is_available {
+  my ($self) = @_;
+  $self->nap(0.3);
+}
+
+sub nap {
+  my ($self,$seconds) = @_;
+  select(undef,undef,undef,$seconds);
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/IndividualItemsRenewerTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/IndividualItemsRenewerTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/IndividualItemsRenewerTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,183 @@
+package IndividualItemsRenewerTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::IndividualItemsRenewer;
+use TelephoneRenewals::RenewalResult;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_phone_menu", 
+    "mock_evergreen_renewal",
+    "mock_renewal_announcer",
+    "mock_renewal_logger",
+  );
+
+  $self->{individual_items_renewer} = new TelephoneRenewals::IndividualItemsRenewer(
+    evergreen_renewal => $self->{mock_evergreen_renewal},
+    phone_menu => $self->{mock_phone_menu},
+    renewal_announcer => $self->{mock_renewal_announcer},
+    renewal_logger => $self->{mock_renewal_logger},
+  );
+
+  $self->configure_mock("mock_phone_menu", 
+    { prompt_for_barcode => "barcode 1" },
+    { prompt_to_continue_individual_renewal => "no" },
+  );
+
+  $self->configure_mock("mock_evergreen_renewal", 
+    { renew_item_by_barcode => "fake result 1" }
+  );
+
+  $self->configure_mock("mock_renewal_announcer", 
+    { announce_renewal_result => "unused" }
+  );
+
+  $self->configure_mock("mock_renewal_logger", 
+    { info => "unused" },
+    { log_result => "unused" },
+  );
+}
+
+# For executing the method under test
+sub execute {
+  my $self = shift;
+  $self->{individual_items_renewer}->renew_individual_items("libcardnum");
+}
+
+#
+# TESTS:
+#
+
+sub test_IndividualItemsRenewer_should_prompt_for_barcode_and_renew_the_item {
+  my $self = shift;
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { prompt_for_barcode => [] },
+    { prompt_to_continue_individual_renewal => [] },
+  );
+  $self->assert_methods_called("mock_evergreen_renewal",
+    { renew_item_by_barcode => [ "libcardnum", "barcode 1" ] }
+  );
+  $self->assert_methods_called("mock_renewal_announcer",
+    { announce_renewal_result => [ "fake result 1" ] }
+  );
+  $self->assert_methods_called("mock_renewal_logger",
+    { info => [ "Patron libcardnum renewing individual items..." ] },
+    { log_result => [ "fake result 1" ] },
+  );
+
+  $self->assert_no_more_methods_called("mock_phone_menu");
+  $self->assert_no_more_methods_called("mock_evergreen_renewal");
+  $self->assert_no_more_methods_called("mock_renewal_announcer");
+}
+
+sub test_IndividualItemsRenewer_should_allow_multiple_renewals {
+  my $self = shift;
+
+  # Prepare for multiple calls:
+  $self->{mock_phone_menu}->set_series("prompt_for_barcode",
+    "barcode 1",
+    "barcode 2",
+    "barcode 3",
+  );
+  $self->{mock_evergreen_renewal}->set_series("renew_item_by_barcode",
+    "fake result 1",
+    "fake result 2",
+    "fake result 3",
+  );
+  $self->{mock_phone_menu}->set_series("prompt_to_continue_individual_renewal",
+    "yes",
+    "yes",
+    "no",
+  );
+
+  # Go
+  $self->execute;
+
+  # Peek
+  $self->assert_methods_called("mock_phone_menu",
+    { prompt_for_barcode => [] },
+    { prompt_to_continue_individual_renewal => [] },
+    { prompt_for_barcode => [] },
+    { prompt_to_continue_individual_renewal => [] },
+    { prompt_for_barcode => [] },
+    { prompt_to_continue_individual_renewal => [] },
+  );
+  $self->assert_methods_called("mock_evergreen_renewal",
+    { renew_item_by_barcode => [ "libcardnum", "barcode 1" ] },
+    { renew_item_by_barcode => [ "libcardnum", "barcode 2" ] },
+    { renew_item_by_barcode => [ "libcardnum", "barcode 3" ] },
+  );
+  $self->assert_methods_called("mock_renewal_announcer",
+    { announce_renewal_result => [ "fake result 1" ] },
+    { announce_renewal_result => [ "fake result 2" ] },
+    { announce_renewal_result => [ "fake result 3" ] },
+  );
+  $self->assert_methods_called("mock_renewal_logger",
+    { info => [ "Patron libcardnum renewing individual items..." ] },
+    { log_result => [ "fake result 1" ] },
+    { log_result => [ "fake result 2" ] },
+    { log_result => [ "fake result 3" ] },
+  );
+
+  # See that we finished clean:
+  $self->assert_no_more_methods_called("mock_phone_menu");
+  $self->assert_no_more_methods_called("mock_evergreen_renewal");
+  $self->assert_no_more_methods_called("mock_renewal_announcer");
+}
+
+sub test_IndividualItemsRenewer_should_not_renew_nonentries_and_give_up_after_3 {
+  my $self = shift;
+
+  # Prepare for multiple calls:
+  $self->{mock_phone_menu}->set_series("prompt_for_barcode",
+    undef,
+    undef,
+    undef,
+  );
+  $self->{mock_evergreen_renewal}->set_series("renew_item_by_barcode",
+    "fake result 1",
+    "fake result 2",
+    "fake result 3",
+  );
+  $self->{mock_phone_menu}->set_series("prompt_to_continue_individual_renewal",
+    "yes",
+    "yes",
+    "no",
+  );
+
+  # Go
+  $self->execute;
+
+  # Peek
+  $self->assert_methods_called("mock_phone_menu",
+    { prompt_for_barcode => [] },
+    { prompt_for_barcode => [] },
+    { prompt_for_barcode => [] },
+  );
+  $self->assert_methods_not_called("mock_phone_menu",
+    "prompt_to_continue_individual_renewal"
+  );
+  $self->assert_methods_not_called("mock_evergreen_renewal",
+    "renew_item_by_barcode"
+  );
+  $self->assert_methods_not_called("mock_renewal_announcer",
+    "announce_renewal_resualt"
+  );
+
+  # See that we finished clean:
+  $self->assert_no_more_methods_called("mock_phone_menu");
+  $self->assert_no_more_methods_called("mock_evergreen_renewal");
+  $self->assert_no_more_methods_called("mock_renewal_announcer");
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/LogChannelTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/LogChannelTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/LogChannelTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,64 @@
+package LogChannelTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::LogChannel;
+use Test::MockObject;
+use File::Basename;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+
+  $self->build_mocks(
+    "mock_app_config"
+  );
+
+  $self->configure_mock("mock_app_config",
+    { log_file => $self->temp_log_file },
+  );
+
+  $self->{log_channel} = new TelephoneRenewals::LogChannel(
+    app_config => $self->{mock_app_config},
+  );
+}
+
+sub tear_down {
+  my $self = shift;
+  unlink $self->temp_log_file
+}
+
+# TESTS:
+
+sub test_LogChannel_write_out_to_a_file {
+  my $self = shift;
+
+  $self->{log_channel}->write_message("Line one.");
+  $self->{log_channel}->write_message("Line two.");
+  $self->{log_channel}->write_message("Line three.");
+
+  $self->assert_deep_equals(
+    [ "Line one.\n", "Line two.\n", "Line three.\n" ],
+    $self->temp_log_file_contents
+  );
+}
+
+# HELPERS:
+
+sub temp_log_file {
+  my $dirname = dirname(__FILE__);
+  return "$dirname/DELETEME_log_channel_test.log"
+}
+
+sub temp_log_file_contents {
+  my ($self) = @_;
+  my $file = $self->temp_log_file;
+  open(TEMPFH, "< $file") or die "can't open $file: $!";
+  my @lines = <TEMPFH>;
+  return \@lines;
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/LoggerTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/LoggerTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/LoggerTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,111 @@
+package LoggerTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::Logger;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_log_channel", 
+    "mock_emailer", 
+    "mock_app_config"
+  );
+
+  $self->configure_mock("mock_log_channel",
+    { "write_message" => [] }
+  );
+
+  $self->configure_mock("mock_emailer",
+    { "send_email" => [] }
+  );
+  $self->configure_mock("mock_app_config",
+    { "error_email_recipients" => ['admin 1', 'admin 2'] },
+    { "error_email_from" => 'the system' },
+    { "error_email_subject" => 'the subject' },
+  );
+
+  $self->{logger} = new TelephoneRenewals::Logger(
+    log_channel => $self->{mock_log_channel},
+    emailer => $self->{mock_emailer},
+    app_config => $self->{mock_app_config},
+  );
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_Logger_should_log_a_timestamped_error_message {
+  my $self = shift;
+
+  $self->{logger}->error("This is the error.");
+  $self->assert_log_channel_written("ERROR", "This is the error.");
+}
+
+sub test_Logger_should_log_a_timestamped_info_message {
+  my $self = shift;
+
+  $self->{logger}->info("Some information.");
+  $self->assert_log_channel_written("INFO", "Some information.");
+}
+
+sub test_Logger_should_log_an_error_and_send_email_notification {
+  my $self = shift;
+
+  $self->{logger}->log_and_email_error("Stuff went wrong!");
+
+  $self->assert_log_channel_written("ERROR", "Stuff went wrong!");
+
+  $self->assert_next_method_call("mock_emailer", sub {
+    my ($method_name, $args) = @_;
+    $self->assert_equals("send_email", $method_name);
+    my $opts = @$args[0];
+    $self->assert_not_null($opts, "Didn't see any options passed to send_email");
+    $self->assert_deep_equals(['admin 1', 'admin 2'], $opts->{to});
+    $self->assert_equals('the system', $opts->{from});
+    $self->assert_equals('the subject', $opts->{subject});
+    my $body = $opts->{body};
+    $self->assert_not_null($body, "Email sent without body");
+    $self->assert_matches(qr/an error occurred/i, $body);
+    $self->assert_matches(qr/GRPL/i, $body);
+    $self->assert_matches(qr/phone renewal/i, $body);
+    $self->assert_matches(qr/stuff went wrong/i, $body);
+  });
+
+}
+
+sub test_Logger_should_log_an_additional_error_when_emailer_fails {
+  my $self = shift;
+
+  $self->{mock_emailer}->mock("send_email", sub {
+    croak "KerDOOOOF";
+  });
+
+  $self->{logger}->log_and_email_error("Stuff went wrong!");
+
+  $self->assert_log_channel_written("ERROR", "Stuff went wrong!");
+  $self->assert_log_channel_written("ERROR", "KerDOOOOF");
+
+}
+
+# HELPERS:
+
+sub assert_log_channel_written {
+  my ($self, $level, $message) = @_;
+  $self->assert_next_method_call("mock_log_channel", sub {
+    my ($method_name, $args) = @_;
+    $self->assert_equals("write_message", $method_name);
+    $self->assert(@$args[0], "mock_log_channel->write_message called with no argument");
+    $self->assert_matches(qr/^\[.*?\] - $level - $message/, @$args[0]);
+  });
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/ObjectContextTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/ObjectContextTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/ObjectContextTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,41 @@
+package ObjectContextTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::ObjectContext;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->{object_context} = new TelephoneRenewals::ObjectContext();
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_ObjectContext_should_build_CallHandler {
+  my $self = shift;
+  my $call_handler = $self->{object_context}->get_call_handler;
+  $self->assert_not_null($call_handler, "CallHandler not built"); 
+}
+
+sub test_ObjectContext_should_build_PromptManager {
+  my $self = shift;
+  my $prompt_manager = $self->{object_context}->get_prompt_manager;
+  $self->assert_not_null($prompt_manager, "PromptManager not built"); 
+}
+
+sub test_ObjectContext_should_build_SoundIndexPrinter {
+  my $self = shift;
+  my $sound_index_printer = $self->{object_context}->get_sound_index_printer;
+  $self->assert_not_null($sound_index_printer, "SoundIndexPrinter not built"); 
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/PromptManagerTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/PromptManagerTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/PromptManagerTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,36 @@
+package PromptManagerTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::PromptManager;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_prompt_store",
+    "mock_agi"
+  );
+
+  $self->{prompt_manager} = new TelephoneRenewals::PromptManager(
+    agi => $self->{mock_agi},
+    prompt_store => $self->{mock_prompt_store},
+  );
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_PromptManager_has_no_unit_tests {
+  my $self = shift;
+#  $self->assert(0, "Implement Me.");
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/PromptStoreTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/PromptStoreTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/PromptStoreTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,86 @@
+package PromptStoreTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::PromptStore;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_app_config",
+  );
+
+  $self->{mock_app_config}->set_always("sounds_dir", "THE_SOUNDS_DIR");
+
+  $self->{prompt_store} = new TelephoneRenewals::PromptStore(
+    app_config => $self->{mock_app_config}
+  );
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_PromptStore_should_resolve_the_path_to_the_requested_sound {
+  my $self = shift;
+  my $name = "welcome_to_the_phone_renewal_system";
+  my $base = "THE_SOUNDS_DIR";
+
+  $self->assert_equals("$base/$name", $self->{prompt_store}->sound_file($name));
+}
+
+sub test_PromptStore_should_list_the_prompt_index_numbers {
+  my $self = shift;
+  my $list = $self->{prompt_store}->all_prompt_numbers;
+  $self->assert_equals(100, @$list[0]);
+  $self->assert_equals(101, @$list[1]);
+  $self->assert_equals(102, @$list[2]);
+}
+
+sub test_PromptStore_should_provide_sound_names_given_a_prompt_number {
+  my $self = shift;
+
+  my $name = $self->{prompt_store}->sound_name_for_prompt_number(100);
+  $self->assert_equals("welcome_to_the_phone_renewal_system", $name);
+
+  $name = $self->{prompt_store}->sound_name_for_prompt_number("100");
+  $self->assert_equals("welcome_to_the_phone_renewal_system", $name);
+
+  $name = $self->{prompt_store}->sound_name_for_prompt_number(103);
+  $self->assert_equals("you_currently_have", $name);
+
+  $name = $self->{prompt_store}->sound_name_for_prompt_number("103");
+  $self->assert_equals("you_currently_have", $name);
+}
+
+sub test_PromptStore_should_provide_sound_files_given_a_prompt_number {
+  my $self = shift;
+  my $base = "THE_SOUNDS_DIR";
+
+  my $file = $self->{prompt_store}->sound_file_for_prompt_number(100);
+  $self->assert_equals("$base/welcome_to_the_phone_renewal_system", $file);
+
+  $file = $self->{prompt_store}->sound_file_for_prompt_number("100");
+  $self->assert_equals("$base/welcome_to_the_phone_renewal_system", $file);
+
+  $file = $self->{prompt_store}->sound_file_for_prompt_number(103);
+  $self->assert_equals("$base/you_currently_have", $file);
+
+  $file = $self->{prompt_store}->sound_file_for_prompt_number("103");
+  $self->assert_equals("$base/you_currently_have", $file);
+}
+
+sub test_PromptStore_should_default_a_sound_name_to_the_given_prompt_number_when_dealing_with_unknown_prompt_id {
+  my $self = shift;
+  my $name = $self->{prompt_store}->sound_name_for_prompt_number(876312);
+  $self->assert_equals("876312", $name);
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/RenewalAnnouncerTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/RenewalAnnouncerTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/RenewalAnnouncerTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,108 @@
+package RenewalAnnouncerTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::RenewalAnnouncer;
+use TelephoneRenewals::RenewalResult;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks("mock_phone_menu", "mock_logger");
+
+  $self->{renewal_announcer} = new TelephoneRenewals::RenewalAnnouncer(
+    phone_menu => $self->{mock_phone_menu},
+    logger => $self->{mock_logger}
+  );
+
+  $self->configure_mock("mock_phone_menu",
+    { announce_renewal_success => "unused" },
+    { announce_renewal_failure_due_to_unknown_barcode => "unused" },
+    { announce_renewal_failure_due_to_renewal_limitations => "unused" },
+    { announce_renewal_failure_due_to_error => "unused" },
+  );
+
+  $self->configure_mock("mock_logger",
+    { log_and_email_error => "unused" }
+  );
+
+  $self->{renewal_result} = new TelephoneRenewals::RenewalResult(
+    status => "something odd",
+    barcode => "barcooode55443"
+  );
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# Run the method under test:
+sub execute {
+  my ($self) = @_;
+  my $renewal_result = $self->{renewal_result};
+  $self->{renewal_announcer}->announce_renewal_result($renewal_result);
+}
+
+# TESTS:
+
+sub test_RenewalAnnouncer_should_announce_successful_renewal {
+  my $self = shift;
+  
+  $self->{renewal_result}->status("success");
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { announce_renewal_success => [ "55443" ] }
+  );
+  $self->assert_no_more_methods_called("mock_phone_menu");
+}
+
+sub test_RenewalAnnouncer_should_announce_failure_because_of_barcode {
+  my $self = shift;
+  
+  $self->{renewal_result}->status("unknown barcode");
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { announce_renewal_failure_due_to_unknown_barcode => [ "barcooode55443" ] }
+  );
+  $self->assert_no_more_methods_called("mock_phone_menu");
+}
+
+sub test_RenewalAnnouncer_should_announce_failure_because_of_limits {
+  my $self = shift;
+  
+  $self->{renewal_result}->status("no renewals allowed");
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_phone_menu",
+    { announce_renewal_failure_due_to_renewal_limitations => [ "55443" ] }
+  );
+  $self->assert_no_more_methods_called("mock_phone_menu");
+}
+
+sub test_RenewalAnnouncer_should_log_and_announce_system_error_for_error_status {
+  my $self = shift;
+  
+  $self->{renewal_result}->status("some unexpected status");
+
+  $self->execute;
+
+  $self->assert_methods_called("mock_logger",
+    { log_and_email_error => ["Renewal result contained unexpected status 'some unexpected status' for barcode barcooode55443"] }
+  );
+
+  $self->assert_methods_called("mock_phone_menu",
+    { announce_renewal_failure_due_to_error => [ "barcooode55443" ] }
+  );
+  $self->assert_no_more_methods_called("mock_phone_menu");
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/RenewalLoggerTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/RenewalLoggerTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/RenewalLoggerTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,75 @@
+package RenewalLoggerTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::RenewalLogger;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_logger"
+  );
+
+  $self->{renewal_logger} = new TelephoneRenewals::RenewalLogger(
+    logger => $self->{mock_logger}
+  );
+
+  $self->setup_log_capturing($self->{mock_logger});
+
+
+  $self->{success_result} = new TelephoneRenewals::RenewalResult(
+    status => "success",
+    barcode => "12345678911111",
+  );
+  $self->{bad_result} = new TelephoneRenewals::RenewalResult(
+    status => "unknown barcode",
+    barcode => "12345678922222",
+  );
+  $self->{limited_result} = new TelephoneRenewals::RenewalResult(
+    status => "no renewals allowed",
+    barcode => "12345678933333",
+  );
+  $self->{odd_result} = new TelephoneRenewals::RenewalResult(
+    status => "some reason",
+    barcode => "12345678944444",
+  );
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_RenewalLogger_should_pass_thru_calls_on_info_to_the_logger {
+  my $self = shift;
+  $self->{renewal_logger}->info("a message");
+
+  $self->assert_logged("info", "a message");
+}
+
+sub test_RenewalLogger_should_log_successful_results {
+  my $self = shift;
+  $self->{renewal_logger}->log_result($self->{success_result});
+
+  $self->assert_logged("info", "Renewed ok: 12345678911111");
+}
+
+sub test_RenewalLogger_should_log_unsuccessful_results {
+  my $self = shift;
+  $self->{renewal_logger}->log_result($self->{bad_result});
+  $self->{renewal_logger}->log_result($self->{limited_result});
+  $self->{renewal_logger}->log_result($self->{odd_result});
+  
+  $self->assert_logged("info", "Renewal FAILED: 12345678922222 - unknown barcode");
+  $self->assert_logged("info", "Renewal FAILED: 12345678933333 - no renewals allowed");
+  $self->assert_logged("info", "Renewal FAILED: 12345678944444 - some reason");
+}
+
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/RenewalResultSetTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/RenewalResultSetTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/RenewalResultSetTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,60 @@
+package RenewalResultSetTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::RenewalResultSet;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->{renewal_result_set} = new TelephoneRenewals::RenewalResultSet();
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_RenewalResultSet_should_provide_status_and_list_field_accessors {
+  my $self = shift;
+  my $renewal_result_set = $self->{renewal_result_set};
+
+  $self->assert_equals("", $renewal_result_set->status);
+  $renewal_result_set->status("something good");
+  $self->assert_equals("something good", $renewal_result_set->status);
+
+  $self->assert_deep_equals([], $renewal_result_set->successful_renewals);
+  $renewal_result_set->successful_renewals([1,2,3]);
+  $self->assert_deep_equals([1,2,3], $renewal_result_set->successful_renewals);
+
+  $self->assert_deep_equals([], $renewal_result_set->failed_renewals);
+  $renewal_result_set->failed_renewals([1,2,3]);
+  $self->assert_deep_equals([1,2,3], $renewal_result_set->failed_renewals);
+}
+
+sub test_RenewalResultSet_should_let_you_add_items_to_its_lists {
+  my $self = shift;
+  my $renewal_result_set = $self->{renewal_result_set};
+
+  $self->assert_deep_equals([], $renewal_result_set->successful_renewals);
+  $self->assert_equals(0, $renewal_result_set->count_successful_renewals);
+  $renewal_result_set->add_successful_renewal("r1");
+  $renewal_result_set->add_successful_renewal("r2");
+  $renewal_result_set->add_successful_renewal("r3");
+  $self->assert_deep_equals(["r1","r2","r3"], $renewal_result_set->successful_renewals);
+  $self->assert_equals(3, $renewal_result_set->count_successful_renewals);
+
+  $self->assert_deep_equals([], $renewal_result_set->failed_renewals);
+  $self->assert_equals(0, $renewal_result_set->count_failed_renewals);
+  $renewal_result_set->add_failed_renewal("fr1");
+  $renewal_result_set->add_failed_renewal("fr2");
+  $self->assert_deep_equals(["fr1","fr2"], $renewal_result_set->failed_renewals);
+  $self->assert_equals(2, $renewal_result_set->count_failed_renewals);
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/RenewalResultTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/RenewalResultTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/RenewalResultTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,81 @@
+package RenewalResultTest;
+
+use strict;
+use Carp;
+use base 'Test::Unit::TestCase';
+use TelephoneRenewals::RenewalResult;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+}
+
+sub tear_down {
+  my $self = shift;
+}
+
+# TESTS:
+
+sub test_RenewalResult_should_be_built_with_status_and_barcode {
+  my $self = shift;
+
+  my $result = new TelephoneRenewals::RenewalResult(
+    status => "some status",
+    barcode => "abc123"
+  );
+
+  $self->assert_equals("some status", $result->status);
+  $self->assert_equals("abc123", $result->barcode);
+}
+
+sub test_RenewalResult_should_set_and_get_its_fields {
+  my $self = shift;
+
+  my $result = new TelephoneRenewals::RenewalResult(
+    status => "first status",
+    barcode => "first barcode"
+  );
+
+  $self->assert_equals("first status", $result->status);
+  $result->status("new status");
+  $self->assert_equals("new status", $result->status);
+
+  $self->assert_equals("first barcode", $result->barcode);
+  $result->barcode("new barcode");
+  $self->assert_equals("new barcode", $result->barcode);
+}
+
+sub test_RenewalResult_should_return_the_last_5_digits_of_the_barcode {
+  my $self = shift;
+
+  my $result = new TelephoneRenewals::RenewalResult(
+    status => "the status",
+    barcode => "lalalaDDDDD"
+  );
+
+  $self->assert_equals("DDDDD", $result->last_5_digits_of_barcode);
+
+  $result->barcode("1234");
+  $self->assert_equals("1234", $result->last_5_digits_of_barcode);
+
+  $result->barcode("123");
+  $self->assert_equals("123", $result->last_5_digits_of_barcode);
+
+  $result->barcode("1");
+  $self->assert_equals("1", $result->last_5_digits_of_barcode);
+
+  $result->barcode("");
+  $self->assert_equals("", $result->last_5_digits_of_barcode);
+}
+
+sub test_RenewalResult_should_gracefully_return_empty_string_for_last_5_of_barcode_if_barcode_not_set {
+  my $self = shift;
+
+  my $result = new TelephoneRenewals::RenewalResult(); # no args
+
+  $self->assert_equals("", $result->last_5_digits_of_barcode);
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/SoundIndexPrinterTest.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/SoundIndexPrinterTest.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/SoundIndexPrinterTest.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,74 @@
+package SoundIndexPrinterTest;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use TelephoneRenewals::SoundIndexPrinter;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my $self = shift;
+
+  $self->build_mocks(
+    "mock_prompt_store"
+  );
+
+  $self->{sound_index_printer} = new TelephoneRenewals::SoundIndexPrinter(
+    prompt_store => $self->{mock_prompt_store}
+  );
+
+}
+
+sub tear_down {
+  my $self = shift;
+  close(STRINGIO);
+}
+
+# TESTS:
+
+sub test_SoundIndexPrinter_should_iterate_over_available_sound_files_and_print_a_nice_list {
+  my $self = shift;
+
+  # Mock up the prompt_store behaviors:
+  $self->{mock_prompt_store}->set_always("all_prompt_numbers", 
+    [ "123", "456", "789" ]
+  );
+
+  $self->{mock_prompt_store}->set_series("sound_name_for_prompt_number", 
+    "first_sound_name",
+    "another_sound_name",
+    "the_last_sound_name"
+  );
+
+  # Open a filehandle that will dump to a string:
+  my $string_io = "";
+  open(STRINGIO, '>', \$string_io);
+
+  # Go!
+  $self->{sound_index_printer}->print(*STRINGIO);
+
+#  close(STRINGIO);
+
+  $self->assert_methods_called("mock_prompt_store",
+    { all_prompt_numbers => [] },
+    { sound_name_for_prompt_number => [ "123" ] },
+    { sound_name_for_prompt_number => [ "456" ] },
+    { sound_name_for_prompt_number => [ "789" ] },
+  );
+
+  my $expected_output = <<'ENDOUTPUT';
+                         Phone Renewal Prompts
+#      Name
+----   ------------------------------------------------------------
+123  - first_sound_name
+456  - another_sound_name
+789  - the_last_sound_name
+ENDOUTPUT
+
+  $self->assert_equals($expected_output, $string_io);
+
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/tlib/TestHelper.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/TestHelper.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/TestHelper.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,151 @@
+package TestHelper;
+
+use strict;
+use base 'Test::Unit::TestCase';
+use Test::MockObject;
+
+sub build_mocks {
+  my($self, @mock_roots) = @_;
+  foreach my $name (@mock_roots) {
+    $self->{$name} = Test::MockObject->new;
+  }
+}
+
+sub configure_mock {
+  my ($self, $mock_name, @calls) = @_;
+  my $mock_object = $self->get_mock($mock_name);
+  foreach my $call_info (@calls) {
+    while(my($mname, $return) = each %$call_info) { 
+      $mock_object->set_always($mname, $return);
+    }
+  }
+}
+
+sub get_mock {
+  my ($self, $mock_name) = @_;
+  my $mock_object = $self->{$mock_name};
+  $self->assert_not_null($mock_object, "No mock object available called '$mock_name'");
+  return $mock_object;
+}
+
+=head2 
+
+For a given mock object, assert that a set of calls occurred, and assert the contents
+of the arguments passed to the calls.
+
+Proves that all desired calls were made, and in the given order.
+
+Allows other calls to have been made before, during and after the list of desired calls.
+
+=cut
+
+sub assert_methods_called {
+  my ($self, $mock_name, @call_list) = @_;
+  my $mock_object = $self->get_mock($mock_name);
+
+  # Loop through all expected method call specifications:
+  foreach my $call_info (@call_list) {
+    while(my($expected_mname, $expected_args) = each %$call_info) { # Get the key/val pair from our call spec
+      # Search forward in the recorded call list to find the call we're looking for:
+      my ($called_mname, $args) = $mock_object->next_call; 
+      while ($called_mname && ($called_mname ne $expected_mname)) {
+        ($called_mname, $args) = $mock_object->next_call; 
+      }
+      # We may have exhausted the list:
+      $self->assert($called_mname, "Failed to find call $mock_name->$expected_mname(". join(",",@$expected_args) .")... it didn't happen, or it happened out of order.");
+
+      # Compare the arguments passed to the call:
+      shift @$args; # (remove $self)
+      $self->assert_deep_equals($expected_args, $args, "Bad args passed to $mock_name->$called_mname.  Expected: (".join(",",@$expected_args) . ") but got: (" . join(",", @$args) . ")");
+    }
+  }
+}
+
+=head2 
+
+For a given mock object, assert that a set of calls did NOT occur.
+Fail on first disappointment.
+
+=cut
+
+sub assert_methods_not_called {
+  my ($self, $mock_name, @mnames) = @_;
+  my $mock_object = $self->get_mock($mock_name);
+  foreach my $mname (@mnames) {
+    $self->assert(not($mock_object->called($mname)), "Expected $mock_name->$mname NOT to be called");
+  }
+}
+
+sub assert_no_more_methods_called {
+  my ($self, $mock_name) = @_;
+  my $mock_object = $self->get_mock($mock_name);
+  my ($mname,$args) = $mock_object->next_call; 
+  shift @$args; # (remove $self)
+  if ($mname) {
+    $self->assert_null($mname, "Expected no further calls on $mock_name, but found at least: $mname(".join(",",@$args).")");
+  }
+}
+
+sub assert_next_method_call {
+  my ($self, $mock_name, $block) = @_;
+  my $mock_object = $self->get_mock($mock_name);
+  my ($mname,$args) = $mock_object->next_call;
+  $self->assert($mname, "Ran out of method calls on $mock_name");
+  shift @$args; # remove mock object self
+  &$block($mname, $args);
+}
+
+# LOGGER HELPERS:
+
+sub setup_log_capturing {
+  my ($self, $mock_logger) = @_;
+
+  $self->{captured_logs} = [];
+  my $captured_logs = $self->{captured_logs};
+
+  $mock_logger->mock("info", sub {
+    my ($mock, $message) = @_;
+    push(@$captured_logs, "info|$message");
+  });
+  $mock_logger->mock("error", sub {
+    my ($mock, $message) = @_;
+    push(@$captured_logs, "error|$message");
+  });
+  $mock_logger->mock("log_and_email_error", sub {
+    my ($mock, $message) = @_;
+    push(@$captured_logs, "log_and_email_error|$message");
+  });
+}
+
+sub assert_logged {
+  my ($self,$method,$message) = @_;
+  my $captured_logs = $self->{captured_logs};
+  my $found = 0;
+  foreach my $item (@$captured_logs) {
+    my ($called_method, $sent_message) = split(/\|/,$item);
+    if (($called_method eq $method) && ($sent_message eq $message)) {
+      $found = 1;
+    }
+  };
+
+  if (not $found) {
+    $self->assert(0, "Didn't find message '$message' for logger method $method in captured log list:\n  ".join("\n  ",@$captured_logs));
+  }
+}
+
+sub assert_logged_regexp {
+  my ($self,$method,$message_regexp) = @_;
+  my $captured_logs = $self->{captured_logs};
+  my $found = 0;
+  foreach my $item (@$captured_logs) {
+    my ($called_method, $sent_message) = split(/\|/,$item);
+    if (($called_method eq $method) && ($sent_message =~ $message_regexp)) {
+      $found = 1;
+    }
+  };
+
+  if (not $found) {
+    $self->assert(0, "Didn't find a message matching $message_regexp for logger method $method in captured log list:\n  ".join("\n  ",@$captured_logs));
+  }
+}
+1;

Added: grpl/trunk/phone_renewal/t/tlib/UnitTestSuite.pm
===================================================================
--- grpl/trunk/phone_renewal/t/tlib/UnitTestSuite.pm	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/tlib/UnitTestSuite.pm	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,29 @@
+package UnitTestSuite;
+
+use Test::Unit::TestSuite;
+use File::Basename;
+
+sub new {
+  my $class = shift;
+  return bless {}, $class;
+}
+
+sub suite {
+  my $class = shift;
+  my $suite = Test::Unit::TestSuite->empty_new("TelephoneRenewals unit test suite");
+
+  my $dirname = dirname(__FILE__);
+  opendir(TLIB, $dirname);
+  my @test_files = grep(/Test.pm$/,readdir(TLIB));
+  closedir(TLIB);
+
+  foreach $test_file (@test_files) {
+    my $suite_name = basename($test_file, ".pm");
+#      print "Adding test suite $suite_name\n";
+    $suite->add_test($suite_name);
+  }
+
+  return $suite;
+}
+
+1;

Added: grpl/trunk/phone_renewal/t/unit_tests.t
===================================================================
--- grpl/trunk/phone_renewal/t/unit_tests.t	                        (rev 0)
+++ grpl/trunk/phone_renewal/t/unit_tests.t	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+use strict;
+use lib 't/tlib', 'tlib', '../lib', 'lib';
+
+# NOTE: This script will run the test suite.
+# But it WON'T summarize at the end, and the shell exit value
+# will not be set indicating success/failure.  Use the wrapper
+# script ../run_tests.pl to accomplish that.
+
+# Using HarnessUnit runner as an alternative to TestRunner.  
+# For one, it yields more Perl-ish test output, and it 
+# has a nice way of showing you what specifications are being met
+# or broken. 
+use Test::Unit::HarnessUnit;
+my $testrunner = Test::Unit::HarnessUnit->new();
+my $x = $testrunner->start("UnitTestSuite");
+
+
+# OLD:
+#use Test::Unit::TestRunner;
+#my $testrunner = Test::Unit::TestRunner->new();
+#$testrunner->start("UnitTestSuite");
+


Property changes on: grpl/trunk/phone_renewal/t/unit_tests.t
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/tools/new_class.pl
===================================================================
--- grpl/trunk/phone_renewal/tools/new_class.pl	                        (rev 0)
+++ grpl/trunk/phone_renewal/tools/new_class.pl	2009-05-01 15:20:12 UTC (rev 429)
@@ -0,0 +1,109 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Carp qw(croak);
+
+my ($class_name) = @ARGV;
+croak "Please supply class name" unless $class_name;
+
+# This script is biased to use TelephoneRenewals as the base package
+my $package_base = "TelephoneRenewals";
+
+my $package_name = $package_base . "::" . $class_name;
+
+
+# Generate source code
+my $source_code = generate_source_code_stub($package_name, $class_name);
+my $test_code = generate_test_code_stub($package_name, $class_name);
+
+
+my $proj_dir = ".";
+my $lib_dir = "$proj_dir/lib";
+my $tlib_dir = "$proj_dir/t/tlib";
+
+my $package_dir = "$lib_dir/$package_base";
+$package_dir =~ s/::/\//g;
+
+my $source_file = "$package_dir/$class_name.pm";
+my $test_file = "$tlib_dir/" . $class_name . "Test.pm";
+
+write_file($source_file, $source_code);
+write_file($test_file, $test_code);
+
+sub generate_source_code_stub {
+  my ($package_name, $class_name) = @_;
+
+  my $code = <<SOURCETEMPLATE;
+package $package_name;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+  my (\$class, %args) = \@_;
+  my \$self = {};
+
+  foreach my \$varname qw(something) {
+    if (not(\$args{\$varname})) {
+      croak "$class_name cannot be built without a '\$varname' object.";
+    }
+    \$self->{\$varname} = \$args{\$varname};
+  }
+
+  bless \$self, ref \$class || \$class;
+  return \$self;
+}
+
+1;
+SOURCETEMPLATE
+  return $code;
+}
+
+sub generate_test_code_stub {
+  my ($target_package_name, $target_class_name) = @_;
+  my $test_package_name = $target_class_name . "Test";
+  my $test_method_name = "test_" . $target_class_name . "_should_work_properly";
+  my $code = <<TESTTEMPLATE;
+package $test_package_name;
+
+use strict;
+use Carp;
+use base 'TestHelper';
+use $target_package_name;
+use Test::MockObject;
+
+# SETUP
+
+sub set_up {
+  my \$self = shift;
+
+  \$self->{target} = new $target_package_name();
+}
+
+sub tear_down {
+  my \$self = shift;
+}
+
+# TESTS:
+
+sub $test_method_name {
+  my \$self = shift;
+  \$self->assert(0, "Implement Me.");
+}
+
+1;
+TESTTEMPLATE
+  return $code;
+}
+
+sub write_file {
+  my ($file_name, $text) = @_;
+  if (-e $file_name) {
+    print "NOT OVERWRITING $file_name\n";
+  } else {
+    open MYFILE, ">$file_name\n";
+    print MYFILE $text;
+    close (MYFILE); 
+    print "Wrote $file_name\n";
+  }
+}


Property changes on: grpl/trunk/phone_renewal/tools/new_class.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: grpl/trunk/phone_renewal/vendor/Class-Inner-0.1.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Class-Inner-0.1.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/Devel-Symdump-2.08.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Devel-Symdump-2.08.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/Error-0.17015.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Error-0.17015.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/File-Path-Expand-1.02.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/File-Path-Expand-1.02.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/MIME-Lite-3.024.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/MIME-Lite-3.024.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/Module-Build-0.32.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Module-Build-0.32.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/SMTP-Server-1.1.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/SMTP-Server-1.1.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/Sub-Uplevel-0.2002.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Sub-Uplevel-0.2002.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/Test-Exception-0.27.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Test-Exception-0.27.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/Test-MockObject-1.09.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Test-MockObject-1.09.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/Test-Simple-0.86.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Test-Simple-0.86.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/Test-Unit-0.25.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/Test-Unit-0.25.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/UNIVERSAL-can-1.12.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/UNIVERSAL-can-1.12.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/UNIVERSAL-isa-1.01.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/UNIVERSAL-isa-1.01.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: grpl/trunk/phone_renewal/vendor/asterisk-perl-0.10.tar.gz
===================================================================
(Binary files differ)


Property changes on: grpl/trunk/phone_renewal/vendor/asterisk-perl-0.10.tar.gz
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the open-ils-commits mailing list