// Squirrelmail Accessibility Enhancement user script
// version 1.04
// 2005-09-30
//
// Copyright (c) 2005, Ruud H.G. van Tol
// Dr.Ruud <rvtol+greasemonkey@isolution.nl>
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Mozilla/Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Hello World", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name         Squirrelmail Accessibility Enhancements (by Dr.Ruud)
// @namespace    http://www.isolution.nl
// @description  Alt-R = mark Read, Alt-U = mark Unread, Alt-D = Delete, Alt-A = toggle All
// @include      https://webmail.xs4all.nl/src/right_main.php
// @include      https://webmail.xs4all.nl/src/right_main.php?*
// @include      https://dovemail.xs4all.nl/src/right_main.php
// @include      https://dovemail.xs4all.nl/src/right_main.php?*
// ==/UserScript==

(function() {
  var doc = document, elm, frm, i, lang, n = document.forms.length;

////
/// change some button faces and give them access keys
//
  for (i=0; i<n; i++) {
    elm = doc.forms[i].elements;
    if (elm['markUnread']) {

      lang = ('Unread' == elm['markUnread'].value) ? 'en' : 'nl';

      switch (lang) {
      case 'nl':
        insertLabel(doc, elm['markRead'],   'l', 'ge(L)ezen');
        insertLabel(doc, elm['markUnread'], 'n', 'o(N)gelezen');
        insertLabel(doc, elm['delete'],     'w', '(W)eg');
        break;
      default:
        insertLabel(doc, elm['markRead'],   'r', '(R)ead');
        insertLabel(doc, elm['markUnread'], 'u', '(U)nread');
        insertLabel(doc, elm['delete'],     'd', '(D)elete');
      }
      frm = doc.forms[i];
      break;
  } }

  var allAs = frm.getElementsByTagName('a'), e;
  n = allAs.length;

////
/// change an anchor and give it an access key
//
  for (i=0; i<n; i++) {
    e = allAs[i];
    if (String(e.href).match(/javascript:void/)
    &&  String(e.onclick).match(/CheckAll/)) {

      switch (lang) {
      case 'nl':
        e.accessKey = 's';
        e.innerHTML = '(S)electie omkeren';
        break;
      default:
        e.accessKey = 'a';
        e.innerHTML = 'toggle (A)ll';
  } } }

//---------------------------------------------

  function insertLabel(doc, elm, key, txt) {
    if (!elm.id) elm.id = elm.name;

    var newLabel = doc.createElement('label');
    newLabel.setAttribute('for', elm.id);
    newLabel.accessKey = key;
    newLabel.innerHTML = '&nbsp;';

    elm.parentNode.insertBefore(newLabel, elm);
    elm.value = txt;
  }
})();

