DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (3663d7c37d88)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!--
/*  This defines <datepicker/> <timepicker/> and <datetimepicker/>
    which all descend from datetimepicker-base to get date/time parsing
    and consistent behavior.
    It relies on <minimonth/> for the date picker's drop down.
    You can be notified of change event as follows:
      <datepicker id="my-date-picker" onchange="myDatePick( this );"/>
    May get/set value in javascript with 
      document.getElementById("my-date-picker").value = new Date();
    May disable/enable in javascript with
      document.getElementById("my-date-picker").disabled = true;
    May also disable/enable a datetimepicker's component
      datepicker or timepicker individually with 
      document.getElementById("my-datetimepicker").datepickerdisabled = true;
      document.getElementById("my-datetimepicker").timepickerdisabled = true;

*/
-->
<bindings id="xulDatePicker"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <binding id="datetextpicker"
           extends="chrome://calendar/content/datetimepickers/datetimepickers.xml#datetimepicker-base">               
    <content>
      <xul:hbox flex="1">
        <xul:textbox anonid="date-textbox" flex="1"
                     onfocus="this.select();"
                     onkeypress="if (event.keyCode == Components.interfaces.nsIDOMKeyEvent.DOM_VK_RETURN) fireGoEvent();"/>
        <xul:button anonid="date-go-button" oncommand="fireGoEvent()"/>
      </xul:hbox>
    </content>
    <implementation>
      <field name="mRelativeDates">[]</field>
      <field name="mDayNames">[]</field>
      <field name="mRelationWords">[]</field>
      <field name="mMonthLongNames">[]</field>
      <field name="mMonthShortNames">[]</field>

      <constructor><![CDATA[
        var goButton = document.getAnonymousElementByAttribute(this, "anonid", "date-go-button");
        goButton.setAttribute("label", calGetString("calendar", "go"));
        // Load the stuff we're going to use to parse written dates
        this.mRelativeDates = [
            {word:calGetString("calendar", "today").toLowerCase(), offset: 0},
            {word:calGetString("calendar", "yesterday").toLowerCase(), offset: -1},
            {word:calGetString("calendar", "tomorrow").toLowerCase(), offset: 1}];
        var i;
        for (i = 1; i <= 7; i++) {
          this.mDayNames.push(calGetString("dateFormat", "day."+i+".name").toLowerCase());
        }

        for (i = 1; i <= 12; i++) {
          this.mMonthLongNames.push(calGetString("dateFormat", "month."+i+".name").toLowerCase());
          this.mMonthShortNames.push(calGetString("dateFormat", "month."+i+".Mmm").toLowerCase());
        }

        // note that some languages have different conjugations of
        // next/last depending on the day
        this.mRelationWords = [
            {word:calGetString("calendar", "last1"), offset: -1},
            {word:calGetString("calendar", "last2"), offset: -1},
            {word:calGetString("calendar", "next1"), offset: 0},
            {word:calGetString("calendar", "next2"), offset: 0}];        

        // Set the value to today
        var text = document.getAnonymousElementByAttribute(this, "anonid", "date-textbox");
        text.value = calGetString("calendar", "today");
      ]]></constructor>

      <property name="value">
        <getter><![CDATA[
          return this.mValue;
        ]]></getter>
        <setter><![CDATA[
         var text = document.getAnonymousElementByAttribute(this, "anonid", "date-textbox");
          try {
            text.value = this.formatDate(val);
          } catch(ex) {}
          return val;
        ]]></setter>
      </property>

      <method name="fireGoEvent">
        <body><![CDATA[
          var text = document.getAnonymousElementByAttribute(this, "anonid", "date-textbox");
          var date = this.parseLanguageDate(text.value);
          if (!date) {
            date = this.parseDateTime(text.value);
          }
          if (date) {
            // format fails if year <= 1600 on win2k, so try format first.
            var prettyDate;
            try { 
              prettyDate = this.formatDate(date);
            } catch (ex) {} // fall thru
          }
          if (date && prettyDate) {
            this.mValue = date;
            text.value = prettyDate;
            this.fireEvent("command", date);
            return;
          }
        ]]></body>
      </method>

      <!-- This function will take written (with words) dates and, if
         - possible, return a Date() object described by the words.  Note
         - that this function will not parse explicit dates, like 1/1/06,
         - you should use parseDateTime for that.
        -->
      <method name="parseLanguageDate">
        <parameter name="aValue"/>
        <body><![CDATA[
           if (!aValue) {
             return null;
           }
           var val = aValue.toLowerCase();
           // Look for the easy ones like today, tomorrow, etc
           for each (var rel in this.mRelativeDates) {
             if (val == rel.word) {
               var now = new Date();
               now.setDate(now.getDate()+rel.offset);
               return now;
             }
           }

           var parser = this;

           // Takes a written day of the week and returns a js-date
           // corresponding to the nearest day in the future that is
           // that day of the week
           function getDateForDay(aWord) {
             for (var i in parser.mDayNames) {
               if (aWord != parser.mDayNames[i]) {
                 continue;
               }
               // Figure out what day of the week today is.
               var today = now();

               // i-weekday gets the offset. Add 7 to ensure that the %
               // operation stays positive.
               var offset = (i - today.weekday + 7) % 7;
               today.day = today.day + offset;
               return today.jsDate;
             }
             return null;
           }

           // Remove commas
           val = val.replace(',', '');

           if (val.indexOf(' ') == -1) {
             // Just a single word, or a single date.
             return getDateForDay(val);
           }

           // Replace month names with numbers
           for (var i in this.mMonthLongNames) {
             if (val.indexOf(this.mMonthLongNames[i]) != -1) {
               var newVal = val.replace(this.mMonthLongNames[i], Number(i)+1);
               newVal = newVal.replace(' ', '/');
               return this.parseDateTime(newVal);
             }
          }

          // Same for short month names
           for (var i in this.mMonthShortNames) {
             if (val.indexOf(this.mMonthShortNames[i]) != -1) {
               var newVal = val.replace(this.mMonthShortNames[i], Number(i)+1);
               newVal = newVal.replace(' ', '/');
               return this.parseDateTime(newVal);
             }
          }

          // Now for the cool 'next' and 'last'
          var words = val.split(' ');
          var offset, day;
          for each (let word in words) {
            for each (let rel in this.mRelationWords) {
              if (word == rel.word) {
                offset = rel.offset;
                break;
              }
            }
            for (var i in this.mDayNames) {
              if (word == this.mDayNames[i]) {
                day = getDateForDay(word);
                break;
              }
            }
          }

          if (day && offset != undefined) {
            day.setDate(day.getDate()+(7*offset));
            return day;
          }
          return null;
        ]]></body>
      </method>
    </implementation>
  </binding>
  <binding id="datepicker" extends="chrome://calendar/content/datetimepickers/datetimepickers.xml#datetimepicker-base">
    <!-- ::::::::::::::::: CONTENT ::::::::::::::::::::::::: -->
    <!-- Desired behavior: when user is done editing the date field 
         and either leaves the field (onblur) or closes the dialog 
         (13 is enter/return key), parse the date and redisplay it
         in the date field using the current format to verify
         whether the date was parsed correctly.
         This cannot be done with textbox oninput, so use a workaround.
         This was done with textbox onkeypress="parseTextBoxDate(true)"
         and onblur="parseTextBoxDate(true)" which worked in Moz1.6, but
         no longer works in Moz1.7.
         Therefore constructor stores attribute kDatePicker on the textbox,
         and the onblur and onkeypress commands navigate to this kDatePicker.
         xul:Textbox contains an xul:hbox which contains html:input.
         Onkeypress and onblur are not documented attributes of xul:textbox,
         but become attributes of the html:input.
         Not clear how to navigate from the textbox to the input, otherwise 
         could put kDatePicker property on the input element.
         [document.getAnonymousNodes(textBox) fails as of Moz1.7b]).
         So navigate parents to textbox in order to call parseTextBoxDate.
         [this comment is outside the <content> so it won't become a
         node that interferes with navigation to interior nodes.] -->
    <resources>
      <stylesheet src="chrome://calendar/content/widgets/calendar-widget-bindings.css"/>
    </resources>               
    <content>
      <xul:hbox flex="1" id="hbox" class="datepicker-box-class">
        <xul:menulist editable="true" sizetopopup="false"
                      class="datepicker-text-class"
                      onchange="this.kDatePicker.parseTextBoxDate(true);"
                      onkeypress="if (event.keyCode == 13) this.kDatePicker.parseTextBoxDate(true);"
                      xbl:inherits="disabled">
          <xul:menupopup popupanchor="bottomright" popupalign="topright"
                         anonid="datepopup"
                         onpopupshowing="this.parentNode.kDatePicker.onPopup();"
                         onpopuphiding="this.firstChild.hidePopupList();">
            <xul:minimonth/>
          </xul:menupopup>
        </xul:menulist>
      </xul:hbox>
    </content>

    <!-- ::::::::::::::::: INTERFACE ::::::::::::::::::::::::: -->
    <implementation>
      <constructor>
        <![CDATA[
          var hbox = document.getAnonymousNodes(this)[0];
          this.kTextBox = hbox.firstChild;

          var val = this.getAttribute("value");
          if (val) {
            this.value = new Date(val); // setting value property calls update
          } else {
            this.value = new Date();
          }

          this.kTextBox.kDatePicker = this; // enable call back to method in Moz1.7
          this.kTextBox.menupopup.kDatePicker = this;
          this.kMinimonth = this.kTextBox.menupopup.firstChild;
          this.mInPopup = false;
          this.kMinimonth.addEventListener("select", this.clickDate, false);

        ]]>
      </constructor>

      <destructor>
        <![CDATA[
          this.kMinimonth.removeEventListener("select", this.clickDate, false);
        ]]>
      </destructor>

      <method name="update">
        <parameter name="aValue"/>
        <parameter name="aRefresh"/>
        <body>
          <![CDATA[
            if (aValue != null) {
              // format fails if year <= 1600 on win2k, so try format first.
              var formattedValue = null;
              try { 
                formattedValue = this.formatDate(aValue);
              } catch (ex) {} // fall thru

              if (formattedValue) {
                // format succeeded, safe to set value
                var dateChanged = true;
                if (this.mValue != null) {
                  dateChanged = (this.mValue.getDate() != aValue.getDate()) ||
                                (this.mValue.getMonth() != aValue.getMonth()) ||
                                (this.mValue.getFullYear() != aValue.getFullYear());
                }
                this.mValue = aValue;
                this.kTextBox.value = formattedValue;
                if (aRefresh && dateChanged) {
                  this.fireEvent("change");
                }
              }
            } else {
              // invalid date, revert to previous date
              // set textBox.value property, not attribute
              if (this.mValue) {
                this.kTextBox.value = this.formatDate(this.mValue);
              }
            }
          ]]>
        </body>
      </method>

      <method name="onPopup">
        <body>
          <![CDATA[
            this.mInPopup = true;
            this.kMinimonth.update( this.mValue );
            this.mInPopup = false;
            // select all to remove cursor since can't type while popped-up
            this.select();
          ]]>
        </body>
      </method>

      <method name="parseTextBoxDate">
        <parameter name="aRefresh"/>
        <body>
          <![CDATA[
            this.update(this.parseDateTime(this.kTextBox.value), aRefresh);
            this.lastDateParseIncludedTime = false;
          ]]>
        </body>
      </method>

      <method name="select">
        <body>
          <![CDATA[
            // select all in text box
            this.kTextBox.select();
          ]]>
        </body>
      </method>

      <method name="clickDate">
        <parameter name="aEvent" />
        <body>
          <![CDATA[
            var datepicker = aEvent.target.parentNode.parentNode.kDatePicker;
            if (! datepicker.mInPopup)
            {
              // aEvent.target is the minimonth
              datepicker.update(new Date(aEvent.target.value), true);
              // select changed value so no cursor appears (can't type to it).
              datepicker.select();
              aEvent.target.parentNode.hidePopup();
            }
          ]]>
        </body>
      </method>

      </implementation>

      <!-- ::::::::::::::::: HANDLERS ::::::::::::::::::::::::: -->
      <handlers>
          <handler event="bindingattached" action="this.initialize();"/>

          <handler event="blur" phase="capturing">
            <![CDATA[
              this.parseTextBoxDate(true);
            ]]>
          </handler>
      </handlers>

  </binding>
    
  <binding id="timepicker" extends="chrome://calendar/content/datetimepickers/datetimepickers.xml#datetimepicker-base">
    <!-- ::::::::::::::::: CONTENT ::::::::::::::::::::::::: -->
    <!-- Desired behavior: when user is done editing the time field 
         and either leaves the field (onblur) or closes the dialog 
         (13 is enter/return key), parse the time and redisplay it
         in the time field using the current format to verify
         whether the time was parsed correctly.
         This cannot be done with textbox oninput, so use a workaround.
         This was done with textbox onkeypress="parseTextBoxTime(true)"
         and onblur="parseTextBoxTime(true)" which worked in Moz1.6, but
         no longer works in Moz1.7.
         Therefore constructor stores attribute kTimePicker on the textbox,
         and the onblur and onkeypress commands navigate to this kTimePicker.
         xul:Textbox contains an xul:hbox which contains html:input.
         Onkeypress and onblur are not documented attributes of xul:textbox,
         but become attributes of the html:input.
         Not clear how to navigate from the textbox to the input, otherwise 
         could put kTimePicker property on the input element.
         [document.getAnonymousNodes(textBox) fails as of Moz1.7b]).
         So navigate parents to textbox in order to call parseTextBoxTime.
         [this comment is outside the <content> so it won't become a
         node that interferes with navigation to interior nodes.] -->
    <content>
      <xul:hbox flex="1" id="hbox" class="timepicker-box-class">
        <xul:menulist editable="true" sizetopopup="false"
                      id="timepicker-text"
                      class="timepicker-text-class"
                      onchange="this.kTimePicker.parseTextBoxTime(true);"
                      onkeypress="if (event.keyCode == 13) this.kTimePicker.parseTextBoxTime(true);"
                      xbl:inherits="disabled">
          <xul:menupopup popupalign="topright" popupanchor="bottomright"
                         onpopupshowing="onPopup(this)"
                         onpopuphiding="onHide(this)">
            <xul:timepicker-grids />
          </xul:menupopup>
        </xul:menulist>
      </xul:hbox>
    </content>

    <!-- ::::::::::::::::: INTERFACE ::::::::::::::::::::::::: -->
    <implementation>
      <constructor>
        <![CDATA[
          var hbox = document.getAnonymousNodes(this)[0];
          this.kTextBox = hbox.childNodes[0];
          this.kTextBox.kTimePicker = this; // enable call back to method in Moz1.7

          var val = this.getAttribute("value");
          if (val)
            this.value = (new Date(val));
          else
            this.value = (new Date());
        ]]>
      </constructor>
      
      <method name="update">
        <parameter name="aValue"/>
        <parameter name="aRefresh"/>
        <body>
          <![CDATA[
            if (aValue != null) {
              this.mValue = aValue;
            }
            // set textBox.value property, not attribute
            this.kTextBox.value = this.formatTime(this.mValue);

            if (aValue != null && aRefresh) {
              var event = document.createEvent('Events');
              event.initEvent("change", true, true);
              this.dispatchEvent(event);;
            }
          ]]>
        </body>
      </method>

      <method name="parseTextBoxTime">
        <parameter name="aRefresh"/>
        <body>
          <![CDATA[
            var time = this.parseTime(this.kTextBox.value);
            this.update(time, aRefresh);
            return time;
          ]]>
        </body>
      </method>

      <method name="onPopup">
        <parameter name="aPopup" />
        <body>
          <![CDATA[
            // select all to remove cursor since can't type while popped-up
            this.select();
            var timePickerGrid = aPopup.childNodes[0]; 
            timePickerGrid.onPopupShowing(this, aPopup);
          ]]>
        </body>
      </method>

      <method name="onHide">
        <parameter name="aPopup"/>
        <body>
          <![CDATA[
            // This is the timepicker grid.  Why aren't we using anonid?
            aPopup.childNodes[0].onPopupHiding();
          ]]>
        </body>
      </method>

      <method name="select">
        <body>
          <![CDATA[
            // select all in text box
            this.kTextBox.select();
          ]]>
        </body>
      </method>

    </implementation>

    <!-- ::::::::::::::::: HANDLERS ::::::::::::::::::::::::: -->

    <handlers>
      <handler event="bindingattached" action="this.initialize();"/>
      <handler event="blur" phase="capturing">
        <![CDATA[
          this.parseTextBoxTime(true);
        ]]>
      </handler>
    </handlers>

  </binding>

  <binding id="timepicker-hour">
    <content>
      <xul:spacer flex="1"/>
      <xul:vbox anonid="hourbox"
                onclick="clickHour(this.parentNode, this.parentNode.getAttribute('value'))"
                ondblclick="doubleClickHour(this.parentNode, this.parentNode.getAttribute('value'))">
        <xul:box>
          <xul:label class="time-picker-hour-label" anonid="hourlabel" xbl:inherits="value=label,selected"/>
        </xul:box> 
        <xul:spacer flex="1"/>
      </xul:vbox>
      <xul:spacer flex="1"/>
    </content>
    <handlers>
      <handler event="DOMMouseScroll">
        <![CDATA[
          var rows = event.detail;
          if (rows == UIEvent.SCROLL_PAGE_UP) {
            rows = -1;
          } else if (rows == UIEvent.SCROLL_PAGE_DOWN) {
            rows = 1;
          } else { 
            // In this case event.detail contains the default number of lines
            // to scroll.  We always want to only scroll 1 hour though
            rows = (rows > 0) ? 1 : -1;
          }
          moveHours(rows);
        ]]>
      </handler>
    </handlers>
  </binding>

  <binding id="timepicker-minute">
    <content>
      <xul:spacer flex="1"/>
      <xul:vbox anonid="minutebox"
                onclick="clickMinute(this.parentNode, this.parentNode.getAttribute('value'))">
        <xul:box>
          <xul:label class="time-picker-minute-label" anonid="minutelabel" xbl:inherits="value=label,selected"/>
        </xul:box>
      </xul:vbox>
      <xul:spacer flex="1"/>
    </content>
    <handlers>
      <handler event="DOMMouseScroll">
        <![CDATA[
          var rows = event.detail;
          if (rows == UIEvent.SCROLL_PAGE_UP) {
            rows = -1;
          } else if (rows == UIEvent.SCROLL_PAGE_DOWN) {
            rows = 1;
          } else { 
            // In this case event.detail contains the default number of lines
            // to scroll.  We always want to only scroll 1 minute though
            rows = (rows > 0) ? 1 : -1;
          }
          moveMinutes(rows);
        ]]>
      </handler>
    </handlers>
  </binding>

  <binding id="timepicker-grids" extends="xul:box">
    <resources>
      <stylesheet src="chrome://calendar/skin/datetimepickers/datetimepickers.css"/>
    </resources>
    
    <!-- ::::::::::::::::: CONTENT ::::::::::::::::::::::::: -->
    <content>
      <!-- Box to hold time picker internals -->
      <vbox anonid="time-picker-grids"
            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
        <!-- Hour Grid -->
        <grid anonid="time-picker-hour-grid">
          <columns>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
            <column class="time-picker-hour-column-class" flex="1"/>
          </columns>
          <rows>
            <row flex="1">
              <timepicker-hour class="time-picker-hour-box-class" value="0"
                               anonid="time-picker-hour-box-0"    label="0"/>
              <timepicker-hour class="time-picker-hour-box-class" value="1"
                               anonid="time-picker-hour-box-1"    label="1"/>
              <timepicker-hour class="time-picker-hour-box-class" value="2"
                               anonid="time-picker-hour-box-2"    label="2"/>
              <timepicker-hour class="time-picker-hour-box-class" value="3"
                               anonid="time-picker-hour-box-3"    label="3"/>
              <timepicker-hour class="time-picker-hour-box-class" value="4"
                               anonid="time-picker-hour-box-4"    label="4"/>
              <timepicker-hour class="time-picker-hour-box-class" value="5"
                               anonid="time-picker-hour-box-5"    label="5"/>
              <timepicker-hour class="time-picker-hour-box-class" value="6"
                               anonid="time-picker-hour-box-6"    label="6"/>
              <timepicker-hour class="time-picker-hour-box-class" value="7"
                               anonid="time-picker-hour-box-7"    label="7"/>
              <timepicker-hour class="time-picker-hour-box-class" value="8"
                               anonid="time-picker-hour-box-8"    label="8"/>
              <timepicker-hour class="time-picker-hour-box-class" value="9" 
                               anonid="time-picker-hour-box-9"    label="9"/>
              <timepicker-hour class="time-picker-hour-box-class" value="10"
                               anonid="time-picker-hour-box-10"   label="10"/>
              <timepicker-hour class="time-picker-hour-box-class" value="11"
                               anonid="time-picker-hour-box-11"   label="11"/>
            </row>
            <row flex="1">
              <timepicker-hour class="time-picker-hour-box-class" value="12"
                               anonid="time-picker-hour-box-12"   label="12"/>
              <timepicker-hour class="time-picker-hour-box-class" value="13"
                               anonid="time-picker-hour-box-13"   label="13"/>
              <timepicker-hour class="time-picker-hour-box-class" value="14"
                               anonid="time-picker-hour-box-14"   label="14"/>
              <timepicker-hour class="time-picker-hour-box-class" value="15"
                               anonid="time-picker-hour-box-15"   label="15"/>
              <timepicker-hour class="time-picker-hour-box-class" value="16"
                               anonid="time-picker-hour-box-16"   label="16"/>
              <timepicker-hour class="time-picker-hour-box-class" value="17"
                               anonid="time-picker-hour-box-17"   label="17"/>
              <timepicker-hour class="time-picker-hour-box-class" value="18"
                               anonid="time-picker-hour-box-18"   label="18"/>
              <timepicker-hour class="time-picker-hour-box-class" value="19"
                               anonid="time-picker-hour-box-19"   label="19"/>
              <timepicker-hour class="time-picker-hour-box-class" value="20"
                               anonid="time-picker-hour-box-20"   label="20"/>
              <timepicker-hour class="time-picker-hour-box-class" value="21"
                               anonid="time-picker-hour-box-21"   label="21"/>
              <timepicker-hour class="time-picker-hour-box-class" value="22"
                               anonid="time-picker-hour-box-22"   label="22"/>
              <timepicker-hour class="time-picker-hour-box-class" value="23"
                               anonid="time-picker-hour-box-23"   label="23"/>
            </row>
          </rows>
        </grid> <!-- Hour Grid -->
        <!-- Five  Minute Grid -->
        <vbox anonid="time-picker-five-minute-grid-box" flex="1">
          <grid anonid="time-picker-five-minute-grid" flex="1">
            <columns>
              <column class="time-picker-five-minute-column-class" flex="1"/>
              <column class="time-picker-five-minute-column-class" flex="1"/>
              <column class="time-picker-five-minute-column-class" flex="1"/>
              <column class="time-picker-five-minute-column-class" flex="1"/>
              <column class="time-picker-five-minute-column-class" flex="1"/>
              <column class="time-picker-five-minute-column-class" flex="1"/>
            </columns>
            <rows>
              <row flex="1">
                <timepicker-minute class="time-picker-five-minute-class"   value="0"
                                   anonid="time-picker-five-minute-box-0"  label=":00"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="5"
                                   anonid="time-picker-five-minute-box-5"  label=":05"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="10"
                                   anonid="time-picker-five-minute-box-10" label=":10"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="15"
                                   anonid="time-picker-five-minute-box-15" label=":15"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="20"
                                   anonid="time-picker-five-minute-box-20" label=":20"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="25"
                                   anonid="time-picker-five-minute-box-25" label=":25"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-five-minute-class"   value="30"
                                   anonid="time-picker-five-minute-box-30" label=":30"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="35"
                                   anonid="time-picker-five-minute-box-35" label=":35"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="40"
                                   anonid="time-picker-five-minute-box-40" label=":40"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="45"
                                   anonid="time-picker-five-minute-box-45" label=":45"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="50"
                                   anonid="time-picker-five-minute-box-50" label=":50"/>
                <timepicker-minute class="time-picker-five-minute-class"   value="55"
                                   anonid="time-picker-five-minute-box-55" label=":55"/>
              </row>
            </rows>
          </grid> <!-- Five  Minute Grid -->
          <hbox class="time-picker-minutes-bottom">
            <spacer flex="1"/>
            <label class="time-picker-more-control-label" value="&raquo;" onclick="clickMore()"/>
          </hbox>
        </vbox> <!-- Five  Minute Grid Box -->
        <!-- One  Minute Grid -->
        <vbox anonid="time-picker-one-minute-grid-box" flex="1" hidden="true">
          <grid anonid="time-picker-one-minute-grid" flex="1">
            <columns>
              <column class="time-picker-one-minute-column-class" flex="1"/>
              <column class="time-picker-one-minute-column-class" flex="1"/>
              <column class="time-picker-one-minute-column-class" flex="1"/>
              <column class="time-picker-one-minute-column-class" flex="1"/>
              <column class="time-picker-one-minute-column-class" flex="1"/>
            </columns>
            <rows >
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="0"
                                   anonid="time-picker-one-minute-box-0"  label=":00"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="1"
                                   anonid="time-picker-one-minute-box-1"  label=":01"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="2"
                                   anonid="time-picker-one-minute-box-2"  label=":02"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="3"
                                   anonid="time-picker-one-minute-box-3"  label=":03"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="4"
                                   anonid="time-picker-one-minute-box-4"  label=":04"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="5"
                                   anonid="time-picker-one-minute-box-5"  label=":05"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="6"
                                   anonid="time-picker-one-minute-box-6"  label=":06"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="7"
                                   anonid="time-picker-one-minute-box-7"  label=":07"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="8"
                                   anonid="time-picker-one-minute-box-8"  label=":08"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="9"
                                   anonid="time-picker-one-minute-box-9"  label=":09"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="10"
                                   anonid="time-picker-one-minute-box-10" label=":10"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="11"
                                   anonid="time-picker-one-minute-box-11" label=":11"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="12"
                                   anonid="time-picker-one-minute-box-12" label=":12"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="13"
                                   anonid="time-picker-one-minute-box-13" label=":13"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="14"
                                   anonid="time-picker-one-minute-box-14" label=":14"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="15"
                                   anonid="time-picker-one-minute-box-15" label=":15"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="16"
                                   anonid="time-picker-one-minute-box-16" label=":16"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="17"
                                   anonid="time-picker-one-minute-box-17" label=":17"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="18"
                                   anonid="time-picker-one-minute-box-18" label=":18"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="19"
                                   anonid="time-picker-one-minute-box-19" label=":19"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="20"
                                   anonid="time-picker-one-minute-box-20" label=":20"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="21"
                                   anonid="time-picker-one-minute-box-21" label=":21"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="22"
                                   anonid="time-picker-one-minute-box-22" label=":22"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="23"
                                   anonid="time-picker-one-minute-box-23" label=":23"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="24"
                                   anonid="time-picker-one-minute-box-24" label=":24"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="25"
                                   anonid="time-picker-one-minute-box-25" label=":25"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="26"
                                   anonid="time-picker-one-minute-box-26" label=":26"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="27"
                                   anonid="time-picker-one-minute-box-27" label=":27"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="28"
                                   anonid="time-picker-one-minute-box-28" label=":28"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="29"
                                   anonid="time-picker-one-minute-box-29" label=":29"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="30"
                                   anonid="time-picker-one-minute-box-30" label=":30"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="31"
                                   anonid="time-picker-one-minute-box-31" label=":31"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="32"
                                   anonid="time-picker-one-minute-box-32" label=":32"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="33"
                                   anonid="time-picker-one-minute-box-33" label=":33"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="34"
                                   anonid="time-picker-one-minute-box-34" label=":34"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="35"
                                   anonid="time-picker-one-minute-box-35" label=":35"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="36"
                                   anonid="time-picker-one-minute-box-36" label=":36"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="37"
                                   anonid="time-picker-one-minute-box-37" label=":37"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="38"
                                   anonid="time-picker-one-minute-box-38" label=":38"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="39"
                                   anonid="time-picker-one-minute-box-39" label=":39"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="40"
                                   anonid="time-picker-one-minute-box-40" label=":40"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="41"
                                   anonid="time-picker-one-minute-box-41" label=":41"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="42"
                                   anonid="time-picker-one-minute-box-42" label=":42"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="43"
                                   anonid="time-picker-one-minute-box-43" label=":43"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="44"
                                   anonid="time-picker-one-minute-box-44" label=":44"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="45"
                                   anonid="time-picker-one-minute-box-45" label=":45"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="46"
                                   anonid="time-picker-one-minute-box-46" label=":46"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="47"
                                   anonid="time-picker-one-minute-box-47" label=":47"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="48"
                                   anonid="time-picker-one-minute-box-48" label=":48"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="49"
                                   anonid="time-picker-one-minute-box-49" label=":49"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="50"
                                   anonid="time-picker-one-minute-box-50" label=":50"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="51"
                                   anonid="time-picker-one-minute-box-51" label=":51"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="52"
                                   anonid="time-picker-one-minute-box-52" label=":52"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="53"
                                   anonid="time-picker-one-minute-box-53" label=":53"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="54"
                                   anonid="time-picker-one-minute-box-54" label=":54"/>
              </row>
              <row flex="1">
                <timepicker-minute class="time-picker-one-minute-class"   value="55"
                                   anonid="time-picker-one-minute-box-55" label=":55"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="56"
                                   anonid="time-picker-one-minute-box-56" label=":56"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="57"
                                   anonid="time-picker-one-minute-box-57" label=":57"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="58"
                                   anonid="time-picker-one-minute-box-58" label=":58"/>
                <timepicker-minute class="time-picker-one-minute-class"   value="59"
                                   anonid="time-picker-one-minute-box-59" label=":59"/>
              </row>
            </rows>
          </grid>  <!-- One  Minute Grid -->
          <hbox class="time-picker-minutes-bottom">
            <spacer flex="1"/>
            <label class="time-picker-more-control-label" value="&laquo;" onclick="clickLess()"/>
          </hbox>
        </vbox> <!-- One  Minute Grid Box -->
      </vbox> <!-- Box to hold time picker internals -->
    </content>

    <!-- ::::::::::::::::: INTERFACE ::::::::::::::::::::::::: -->
    <implementation>
      <constructor>
        <![CDATA[
          // set by onPopupShowing
          this.mPicker = null;
          this.mPopup = null;

          // The currently selected time
          this.mSelectedTime = new Date(); 
          // The selected hour and selected minute items
          this.mSelectedHourItem = null;
          this.mSelectedMinuteItem = null;
          // constants use to specify one and five minute view
          this.kMINUTE_VIEW_FIVE = 5;
          this.kMINUTE_VIEW_ONE = 1;
        ]]>
      </constructor>

      <!-- Set up the picker, called when the popup pops -->
      <method name="onPopupShowing">
        <parameter name="aPicker"/>
        <parameter name="aPopup"/>
        <body>
          <![CDATA[
            this.mPicker = aPicker;
            this.mPopup = aPopup;

            // if there is a Date object in the popup item's 
            // value attribute, use it, otherwise use Now.
            var inputTime = this.mPicker.value;
            if (inputTime) {
              this.mSelectedTime = new Date(inputTime);
            } else {
              this.mSelectedTime = new Date();
            }

            // select the hour item
            var hours24 = this.mSelectedTime.getHours();
            var hourItemId = "time-picker-hour-box-" + hours24;
            var hourItem = document.getAnonymousElementByAttribute(this, "anonid", hourItemId);
            this.selectHourItem( hourItem );

            // Show the five minute view if we are an even five minutes, 
            // otherwise one minute view
            var minutesByFive = this.calcNearestFiveMinutes( this.mSelectedTime );

            if (minutesByFive == this.mSelectedTime.getMinutes()) {
              this.clickLess();
            } else {
              this.clickMore();
            }
          ]]>
        </body>
      </method>

      <method name="onPopupHiding">
        <body>
          <![CDATA[
            if (this.hasChanged)
                this.timeSelected();
          ]]>
        </body>
      </method>

      <!-- Called when the more tab is clicked, and possibly at startup -->
      <method name="clickMore">
        <body>
          <![CDATA[
            // switch to one minute view
            this.switchMinuteView( this.kMINUTE_VIEW_ONE );

            // select minute box corresponding to the time
            var minutes = this.mSelectedTime.getMinutes();
            var oneMinuteItemId = "time-picker-one-minute-box-" + minutes;
            var oneMinuteItem = document.getAnonymousElementByAttribute(this, "anonid", oneMinuteItemId);
            this.selectMinuteItem(oneMinuteItem);
          ]]>
        </body>
      </method>

      <!-- Called when the less tab is clicked, and possibly at startup -->
      <method name="clickLess">
        <body>
          <![CDATA[
            // switch to five minute view
            this.switchMinuteView( this.kMINUTE_VIEW_FIVE );

            // select closest five minute box, 
            // BUT leave the selected time at what may NOT be an even five minutes
            // So that If they click more again the proper non-even-five minute 
            // box will be selected
            var minutesByFive = this.calcNearestFiveMinutes(this.mSelectedTime);
            var fiveMinuteItemId = "time-picker-five-minute-box-"+minutesByFive;
            var fiveMinuteItem = document.getAnonymousElementByAttribute(this, "anonid", fiveMinuteItemId);
            this.selectMinuteItem(fiveMinuteItem);
          ]]>
        </body>
      </method>

      <!-- Called when one of the hour boxes is clicked -->
      <method name="clickHour">
        <parameter name="hourItem"/>
        <parameter name="hourNumber"/>
        <body>
          <![CDATA[
            // select the item
            this.selectHourItem( hourItem );

            // Change the hour in the selected time. 
            this.mSelectedTime.setHours( hourNumber );

            this.hasChanged = true;
          ]]>
        </body>
      </method>

      <!-- Called when one of the hour boxes is double clicked
           Sets the time to the selected hour, on the hour, and closes the popup -->
      <method name="doubleClickHour">
        <parameter name="hourItem"/>
        <parameter name="hourNumber"/>
        <body>
          <![CDATA[
            // set the minutes to :00
            this.mSelectedTime.setMinutes(0);
            
            // remove the popup grid
            this.mPopup.hidePopup();
          ]]>
        </body>
      </method>
  
      <!-- Called when one of the minute boxes is clicked, 
           Calls the client's onchange and Closes the popup -->
      <method name="clickMinute">
        <parameter name="minuteItem"/>
        <parameter name="minuteNumber"/>
        <body>
          <![CDATA[
            // set the minutes in the selected time
            this.mSelectedTime.setMinutes(minuteNumber);
            this.selectMinuteItem(minuteItem);
            this.hasChanged = true;
            // remove the popup grid
            this.mPopup.hidePopup();
          ]]>
        </body>
      </method>

      <!-- Called by clickMinute when one of the minute boxes is clicked, 
           Sets the value property and calls the client's onchange. -->
      <method name="timeSelected">
        <body>
          <![CDATA[
            // Copy picked time to avoid problems changing Date object in place
            var pickedTime = new Date( this.mSelectedTime );

            // put the picked time in the value property, and update
            this.mPicker.update(pickedTime, true);
            // select changed value so no cursor appears (can't type to it).
            this.mPicker.select();
          ]]>
        </body>
      </method>

      <!-- Helper function to switch between "one" and "five" minute views -->
      <method name="switchMinuteView">
        <parameter name="view"/>
        <body>
          <![CDATA[
            var fiveMinuteBox = document.getAnonymousElementByAttribute(this, "anonid", "time-picker-five-minute-grid-box");
            var oneMinuteBox = document.getAnonymousElementByAttribute(this, "anonid", "time-picker-one-minute-grid-box");

            if (view == this.kMINUTE_VIEW_ONE) {
              fiveMinuteBox.setAttribute( "hidden", true );
              oneMinuteBox.setAttribute( "hidden", false );
            } else {
              fiveMinuteBox.setAttribute( "hidden", false );
              oneMinuteBox.setAttribute( "hidden", true );
            }
          ]]>
        </body>
      </method>

      <!-- Helper function to select an hour item -->
      <method name="selectHourItem">
        <parameter name="hourItem"/>
        <body>
          <![CDATA[
            // clear old selection, if there is one
            if (this.mSelectedHourItem != null)
              this.mSelectedHourItem.removeAttribute( "selected" );
            // set selected attribute, to cause the selected style to apply
            hourItem.setAttribute( "selected" , "true" );
            // remember the selected item so we can deselect it
            this.mSelectedHourItem = hourItem;
          ]]>
        </body>
      </method>

      <!-- Helper function to select an minute item -->
      <method name="selectMinuteItem">
        <parameter name="minuteItem"/>
        <body>
          <![CDATA[
            // clear old selection, if there is one
            if (this.mSelectedMinuteItem != null)
              this.mSelectedMinuteItem.removeAttribute( "selected" );
            // set selected attribute, to cause the selected style to apply
            minuteItem.setAttribute( "selected" , "true" );
            // remember the selected item so we can deselect it
            this.mSelectedMinuteItem = minuteItem;
          ]]>
        </body>
      </method>
      <method name="moveMinutes">
        <parameter name="aNumber"/>
        <body>
          <![CDATA[
            if (!this.mSelectedTime)
              return;

            var idPrefix = "time-picker-one-minute-box-";

            // Everything above assumes that we are showing the one-minute-grid,
            // If not, we need to do these corrections;
            var fiveMinuteBox = document.getAnonymousElementByAttribute(
                                this, "anonid", "time-picker-five-minute-grid-box");

            if (fiveMinuteBox.getAttribute("hidden") == 'false') {
              aNumber *= 5;
              idPrefix = "time-picker-five-minute-box-";

              // If the detailed view was shown before, then mSelectedTime.getMinutes
              // might not be a multiple of 5.
              this.mSelectedTime.setMinutes(this.calcNearestFiveMinutes(this.mSelectedTime));
            }

            var newMinutes = this.mSelectedTime.getMinutes() + aNumber;

            // Handle rollover cases
            if (newMinutes < 0)
                newMinutes += 60;
            if (newMinutes > 59)
                newMinutes -= 60;

            this.mSelectedTime.setMinutes(newMinutes);

            var minuteItemId = idPrefix + this.mSelectedTime.getMinutes();
            var minuteItem = document.getAnonymousElementByAttribute(this, "anonid", minuteItemId);

            this.selectMinuteItem(minuteItem);
            this.mPicker.kTextBox.value = this.mPicker.formatTime(this.mSelectedTime);
            this.hasChanged = true;
          ]]>
        </body>
      </method>
      <method name="moveHours">
        <parameter name="aNumber"/>
        <body>
          <![CDATA[
            if (!this.mSelectedTime)
              return;

            var newHours = this.mSelectedTime.getHours() + aNumber;

            // Handle rollover cases
            if (newHours < 0)
                newHours += 24;
            if (newHours > 23)
                newHours -= 24;

            this.mSelectedTime.setHours(newHours);

            var hourItemId = "time-picker-hour-box-" + this.mSelectedTime.getHours();
            var hourItem = document.getAnonymousElementByAttribute(this, "anonid", hourItemId);

            this.selectHourItem(hourItem);
            this.mPicker.kTextBox.value = this.mPicker.formatTime(this.mSelectedTime);
            this.hasChanged = true;
          ]]>
        </body>
      </method>

      <!-- Helper function to calulate the nearest even five minutes -->
      <method name="calcNearestFiveMinutes">
        <parameter name="time"/>
        <body>
          <![CDATA[
            var minutes = time.getMinutes();
            var minutesByFive = Math.round( minutes / 5 ) * 5;

            if (minutesByFive > 59)
              minutesByFive = 55;
            return minutesByFive;
          ]]>
        </body>
      </method>
    </implementation>

    <!-- ::::::::::::::::: HANDLERS ::::::::::::::::::::::::: -->

    <handlers>
      <handler event="bindingattached" action="this.initialize();"/>
    </handlers>

  </binding>
  
  <binding id="datetimepicker" extends="chrome://calendar/content/datetimepickers/datetimepickers.xml#datetimepicker-base"
           inherits="value,onchange,disabled,datepickerdisabled,timepickerdisabled">
    <!-- ::::::::::::::::: CONTENT ::::::::::::::::::::::::: -->
    <!-- onchange was simply "onDatePick()" in Moz1.6, but stopped working in Moz1.7
         so had to add navigation by parents. -->
    <content>
      <xul:hbox flex="1" anonid="hbox">
        <xul:datepicker anonid="date-picker" 
                        onchange="this.parentNode.parentNode.onDatePick();"
                        xbl:inherits="value,disabled,disabled=datepickerdisabled"/>
        <xul:timepicker anonid="time-picker" 
                        onchange="this.parentNode.parentNode.onTimePick();"
                        xbl:inherits="value,disabled,disabled=timepickerdisabled"/>
      </xul:hbox>
    </content>

    <!-- ::::::::::::::::: INTERFACE ::::::::::::::::::::::::: -->
    <implementation>
      <property name="datepickerdisabled" 
                onset="if (val) this.kDatePicker.setAttribute('disabled', 'true');
                       else this.kDatePicker.removeAttribute('disabled');"
                onget="return this.kDatePicker.getAttribute('disabled')=='true';"/>

      <!-- timepicker may be disabled alone for all day events -->
      <property name="timepickerdisabled"
                onset="if (val) this.kTimePicker.setAttribute('disabled', 'true');
                       else this.kTimePicker.removeAttribute('disabled');"
                onget="return this.kTimePicker.getAttribute('disabled')=='true';"/>

      <constructor>
        <![CDATA[
          this.kDatePicker =
      document.getAnonymousElementByAttribute(this, "anonid", "date-picker");
          this.kTimePicker =
      document.getAnonymousElementByAttribute(this, "anonid", "time-picker");

          var val = this.getAttribute("value");
          this.mValue = (val ? new Date(val)
                             : new Date());
        ]]>
      </constructor>

      <method name="update">
        <parameter name="aValue"/>
        <parameter name="aRefresh"/>
        <body>
          <![CDATA[
            if (aValue != null) {         
              this.mValue = aValue;
            }
            // set textBox.value property, not attribute
            this.kDatePicker.update(this.mValue, aRefresh);
            this.kTimePicker.update(this.mValue, aRefresh);
            if (aRefresh) {
              this.fireEvent("change");
            }
          ]]>
        </body>
      </method>

      <!-- Date was changed by gui: update value. -->
      <method name="onDatePick">
        <body>
          <![CDATA[
            var tempTime;
            if (this.kDatePicker.lastDateParseIncludedTime)
              tempTime = new Date(this.kDatePicker.value);
            else
              tempTime = new Date(this.mValue);
            var newDate = new Date(this.kDatePicker.value);
            // Note: create new date because setting month and date of month in
            // either order can lead to unexpected results (month may be advanced
            // automatically if day of month is temporarily out of range).
            var dateTime = new Date(newDate.getFullYear(),
                                    newDate.getMonth(),
                                    newDate.getDate(),
                                    tempTime.getHours(),
                                    tempTime.getMinutes(),
                                    tempTime.getSeconds());
            this.mValue = dateTime;
            this.kTimePicker.update(dateTime, false);
            this.fireEvent("change");
          ]]>
        </body>
      </method>

      <!-- Time was changed by gui: update value -->
      <method name="onTimePick">
        <body>
          <![CDATA[
            var dateTime = new Date(this.mValue);
            var newTime = this.kTimePicker.value;
            dateTime.setHours(newTime.getHours());
            dateTime.setMinutes(newTime.getMinutes());
            dateTime.setSeconds(newTime.getSeconds());
            this.mValue = dateTime;
            this.kDatePicker.update(dateTime, false);
            this.fireEvent("change");
          ]]>
        </body>
      </method>

    </implementation>

    <!-- ::::::::::::::::: HANDLERS ::::::::::::::::::::::::: -->

    <handlers>
      <handler event="bindingattached" action="this.initialize();"/>
    </handlers>

  </binding>

  <binding id="datetimepicker-base" extends="chrome://global/content/bindings/general.xml#basecontrol"
           inherits="value,onchange">
    <resources>
      <stylesheet src="chrome://calendar/skin/datetimepickers/datetimepickers.css"/>
    </resources>
    <implementation>
      <constructor>
        <![CDATA[
          this.initDateFormat();
          this.initTimeFormat();
        ]]>
      </constructor>

      <property name="value" 
                onget="return this.mValue"
                onset="this.update(val, false)"/>

      <property name="lastDateParseIncludedTime" 
                onget="return this.mLastDateParseIncludedTime;"
                onset="this.mLastDateParseIncludedTime = val;" />

      <method name="update">
        <parameter name="aValue"/>
        <parameter name="aRefresh"/>
        <body>
          <![CDATA[
            if (aValue != null) {         
              this.mValue = aValue;
            }
          ]]>
        </body>
      </method>

      <method name="fireEvent">
        <parameter name="aEventName"/>
        <parameter name="aDetail"/>
        <body>
          <![CDATA[
            var event = document.createEvent('Events');
            event.initEvent(aEventName, true, true);
            event.detail = aDetail;
            this.dispatchEvent(event);
          ]]>
        </body>
      </method>

      <!-- Parameter aValue may be a date or a date time. Dates are
           read according to locale/OS setting (d-m-y or m-d-y or ...). 
           (see initDateFormat). Uses parseTime() for times.
      -->
      <method name="parseDateTime">
        <parameter name="aValue"/>
        <body>
          <![CDATA[
            this.mLastDateParseIncludedTime = false;
            var tempDate = null;
            if (!this.probeSucceeded)
              return null; // avoid errors accessing uninitialized data.

            var year = Number.MIN_VALUE; var month = -1; var day = -1; var timeString = null;
            if (this.alphaMonths == null) {
              // SHORT NUMERIC DATE, such as 2002-03-04, 4/3/2002, or CE2002Y03M04D.
              // Made of digits & nonDigits.  (Nondigits may be unicode letters
              // which do not match \w, esp. in CJK locales.)
              // (.*)? binds to null if no suffix.
              var parseNumShortDateRegex = /^\D*(\d+)\D+(\d+)\D+(\d+)(.*)?$/;
              var dateNumbersArray = parseNumShortDateRegex.exec(aValue);
              if (dateNumbersArray != null) {
                year = Number(dateNumbersArray[this.yearIndex]);
                month = Number(dateNumbersArray[this.monthIndex]) - 1; // 0-based
                day = Number(dateNumbersArray[this.dayIndex]);
                timeString = dateNumbersArray[4];
              }
            } else {
              // SHORT DATE WITH ALPHABETIC MONTH, such as "dd MMM yy" or "MMMM dd, yyyy"
              // (\d+|[^\d\W]) is digits or letters, not both together.
              // Allows 31dec1999 (no delimiters between parts) if OS does (w2k does not).
              // Allows Dec 31, 1999 (comma and space between parts)
              // (Only accepts ASCII month names; JavaScript RegExp does not have an
              // easy way to describe unicode letters short of a HUGE character range
              // regexp derived from the Alphabetic ranges in 
              // http://www.unicode.org/Public/UNIDATA/DerivedCoreProperties.txt)
              // (.*)? binds to null if no suffix.
              var parseAlphShortDateRegex = /^\s*(\d+|[^\d\W]+)\W{0,2}(\d+|[^\d\W]+)\W{0,2}(\d+|[^\d\W]+)(.*)?$/;
              var datePartsArray = parseAlphShortDateRegex.exec(aValue);
              if (datePartsArray != null) {
                year = Number(datePartsArray[this.yearIndex]);
                var monthString = datePartsArray[this.monthIndex].toUpperCase();
                for (var m = 0; m < this.alphaMonths.length; m++) {
                  if (monthString == this.alphaMonths[m]) {
                    month = m;
                    break;
                  }
                }
                day = Number(datePartsArray[this.dayIndex]);
                timeString = datePartsArray[4];
              }
            }
            if (year != Number.MIN_VALUE && month != -1 && day != -1) {
              // year, month, day successfully parsed
              if (0 <= year && year < 100) {
                // If 0 <= year < 100, treat as 2-digit year (like formatDate):
                //   parse year as up to 30 years in future or 69 years in past.
                //   (Covers 30-year mortgage and most working people's birthdate.)
                // otherwise will be treated as four digit year.
                var currentYear = new Date().getFullYear();
                var currentCentury = currentYear - currentYear % 100;
                year = currentCentury + year;
                if (year < currentYear - 69)
                  year += 100;
                if (year > currentYear + 30)
                  year -= 100;
              }
              // if time is also present, parse it
              var hours = 0; var minutes = 0; var seconds = 0;
              if (timeString != null) {
                var time = this.parseTime(dateNumbersArray[4]);
                if (time != null) {
                  hours = time.getHours();
                  minutes = time.getMinutes();
                  seconds = time.getSeconds();
                  this.mLastDateParseIncludedTime = true;
                }
              }
              tempDate = new Date(year, month, day, hours, minutes, seconds, 0);
            } //else did not match regex, not a valid date
            return tempDate;
          ]]>
        </body>
      </method>
      
      <!-- Parse a variety of time formats so that cut and paste is likely to work.
           separator:            ':'         '.'        ' '        symbol        none
                                 "12:34:56"  "12.34.56" "12 34 56" "12h34m56s"   "123456"
           seconds optional:     "02:34"     "02.34"    "02 34"    "02h34m"      "0234"
           minutes optional:     "12"        "12"       "12"       "12h"         "12"
           1st hr digit optional:"9:34"      " 9.34"     "9 34"     "9H34M"       "934am"
           skip nondigit prefix  " 12:34"    "t12.34"   " 12 34"   "T12H34M"     "T0234"
           am/pm optional        "02:34 a.m.""02.34pm"  "02 34 A M" "02H34M P.M." "0234pm"
           am/pm prefix          "a.m. 02:34""pm02.34"  "A M 02 34" "P.M. 02H34M" "pm0234"
           am/pm cyrillic        "02:34\u0430.\u043c."  "02 34 \u0420 \u041c"
           am/pm arabic          "\u063502:34" (RTL 02:34a) "\u0645 02.34" (RTL 02.34 p)
           above/below noon      "\u4e0a\u534802:34"    "\u4e0b\u5348 02 34"
           noon before/after     "\u5348\u524d02:34"    "\u5348\u5f8c 02 34"
      -->
      <method name="parseTime">
        <parameter name="aValue"/>
        <body>
          <![CDATA[
            // Try/catch this, since some people are apparently
            // interested in using the datepicker in remote apps, where
            // calGetString wouldn't exist
            try {
              var noon = calGetString("dateFormat", "noon");
              if (aValue.toLowerCase() == noon.toLowerCase()) {
                return new Date(0, 0, 0, 12, 0, 0, 0);
              }

              var midnight = calGetString("dateFormat", "midnight");
              if (aValue.toLowerCase() == midnight.toLowerCase()) {
                return new Date(0, 0, 0, 0, 0, 0, 0);
              }
            } catch(ex) {
            }

            var time = null;
            var timePartsArray = this.parseTimeRegExp.exec(aValue);
            const PRE_INDEX=1, HR_INDEX=2, MIN_INDEX=4, SEC_INDEX=6, POST_INDEX=8;

            if (timePartsArray != null) {
              var hoursString   = timePartsArray[HR_INDEX]
              var hours         = Number(hoursString);
              var hoursSuffix   = timePartsArray[HR_INDEX + 1];
              if (!(0 <= hours && hours < 24)) return null;

              var minutesString = timePartsArray[MIN_INDEX];
              var minutes       = (minutesString == null? 0 : Number(minutesString));
              var minutesSuffix = timePartsArray[MIN_INDEX + 1];
              if (!(0 <= minutes && minutes < 60)) return null;

              var secondsString = timePartsArray[SEC_INDEX];
              var seconds       = (secondsString == null? 0 : Number(secondsString));
              var secondsSuffix = timePartsArray[SEC_INDEX + 1];
              if (!(0 <= seconds && seconds < 60)) return null;

              var ampmCode = null;
              if (timePartsArray[PRE_INDEX] || timePartsArray[POST_INDEX]) {
                if (this.ampmIndex && timePartsArray[this.ampmIndex]) {
                  // try current format order first
                  var ampmString = timePartsArray[this.ampmIndex];
                  if (this.amRegExp.test(ampmString)) {
                    ampmCode = "AM";
                  } else if (this.pmRegExp.test(ampmString)) {
                    ampmCode = "PM";
                  }
                }
                if (ampmCode == null) { // not yet found
                  // try any format order
                  var preString = timePartsArray[PRE_INDEX];
                  var postString = timePartsArray[POST_INDEX];
                  if ((preString && this.amRegExp.test(preString)) ||
                      (postString && this.amRegExp.test(postString))) {
                    ampmCode = "AM";
                  } else if ((preString && this.pmRegExp.test(preString)) ||
                             (postString && this.pmRegExp.test(postString))) {
                    ampmCode = "PM";
                  } // else no match, ignore and treat as 24hour time.
                }
              }
              if (ampmCode == "AM") {
                if (hours == 12)
                  hours = 0;
              } else if (ampmCode == "PM") {
                if (hours < 12) 
                  hours += 12;
              }
              time = new Date(0, 0, 0, hours, minutes, seconds, 0);
            }  // else did not match regex, not valid time
            return time;
          ]]>
        </body>
      </method>
      
      <method name="initDateFormat">
        <body>
          <![CDATA[
            // probe the dateformat  
            this.yearIndex = -1;
            this.monthIndex = -1;
            this.dayIndex = -1;
            this.twoDigitYear = false;
            this.alphaMonths = null;
            this.probeSucceeded = false;
            this.mLastDateParseIncludedTime = false;

            // SHORT NUMERIC DATE, such as 2002-03-04, 4/3/2002, or CE2002Y03M04D.
            // Made of digits & nonDigits.  (Nondigits may be unicode letters
            // which do not match \w, esp. in CJK locales.)
            this.parseShortDateRegex = /^\D*(\d+)\D+(\d+)\D+(\d+)\D?$/;
            var probeDate = new Date(2002,3-1,4); // month is 0-based
            var probeString = this.formatDate(probeDate);
            var probeArray = this.parseShortDateRegex.exec(probeString);
            if (probeArray != null) { 
              // Numeric month format
              for (var i = 1; i <= 3; i++) { 
                switch (Number(probeArray[i])) {
                  case 2:    this.twoDigitYear = true; // fall thru
                  case 2002: this.yearIndex = i;       break;
                  case 3:    this.monthIndex = i;      break;
                  case 4:    this.dayIndex = i;        break;
                }
              }
              // All three indexes are set (not -1) at this point.
              this.probeSucceeded = true;
            } else {
              // SHORT DATE WITH ALPHABETIC MONTH, such as "dd MMM yy" or "MMMM dd, yyyy"
              // (\d+|[^\d\W]) is digits or letters, not both together.
              // Allows 31dec1999 (no delimiters between parts) if OS does (w2k does not).
              // Allows Dec 31, 1999 (comma and space between parts)
              // (Only accepts ASCII month names; JavaScript RegExp does not have an
              // easy way to describe unicode letters short of a HUGE character range
              // regexp derived from the Alphabetic ranges in 
              // http://www.unicode.org/Public/UNIDATA/DerivedCoreProperties.txt)
              this.parseShortDateRegex = /^\s*(\d+|[^\d\W]+)\W{0,2}(\d+|[^\d\W]+)\W{0,2}(\d+|[^\d\W]+)\s*$/;
              probeArray = this.parseShortDateRegex.exec(probeString);
              if (probeArray != null) {
                for (var j = 1; j <= 3; j++) { 
                  switch (Number(probeArray[j])) {
                    case 2:    this.twoDigitYear = true; // fall thru
                    case 2002: this.yearIndex = j;       break;
                    case 4:    this.dayIndex = j;        break;
                    default:   this.monthIndex = j;      break;
                  }
                }
                if (this.yearIndex != -1 && this.dayIndex != -1 && this.monthIndex != -1) {
                  this.probeSucceeded = true;
                  // Fill this.alphaMonths with month names.
                  this.alphaMonths = new Array(12);
                  for (var m = 0; m < 12; m++) {
                    probeDate.setMonth(m);
                    probeString = this.formatDate(probeDate);
                    probeArray = this.parseShortDateRegex.exec(probeString);
                    if (probeArray != null) 
                      this.alphaMonths[m] = probeArray[this.monthIndex].toUpperCase();
                    else
                      this.probeSucceeded = false;
                  }
                }
              }
            }
            if (! this.probeSucceeded)
              dump("\nOperating system short date format is not recognized: "+probeString+"\n");
          ]]>
        </body>
      </method>
      
      <!-- Time format in 24-hour format or 12-hour format with am/pm string.
           Should match formats
                HH:mm,       H:mm,       HH:mm:ss,       H:mm:ss
                hh:mm tt,    h:mm tt,    hh:mm:ss tt,    h:mm:ss tt
             tt hh:mm,    tt h:mm,    tt hh:mm:ss,    tt h:mm:ss
           where
           HH is 24 hour digits, with leading 0.  H is 24 hour digits, no leading 0.
           hh is 12 hour digits, with leading 0.  h is 12 hour digits, no leading 0.
           mm and ss are is minutes and seconds digits, with leading 0.
           tt is localized AM or PM string.
           ':' may be ':' or a units marker such as 'h', 'm', or 's' in  15h12m00s
           or may be omitted as in 151200.
      -->
      <method name="initTimeFormat">
        <body>
          <![CDATA[
            // probe the Time format
            this.ampmIndex = null;  
            // Digits         HR       sep      MIN     sep      SEC     sep
            //   Index:       2        3        4       5        6       7    
            var digitsExpr = "(\\d?\\d)(\\D)?(?:(\\d\\d)(\\D)?(?:(\\d\\d)(\\D)?)?)?";
            // any letters or '.': non-digit alphanumeric, period (a.m.), or space (P M)
            var anyAmPmExpr = "(?:[^\\d\\W]|[. ])+"; 
            // digitsExpr has 6 captures, so index of first ampmExpr is 1, of last is 8.
            var probeTimeRegExp =
              new RegExp("^("+anyAmPmExpr+")?\\s?"+digitsExpr+"("+anyAmPmExpr+")?\\s*$");
            const PRE_INDEX=1, HR_INDEX=2, MIN_INDEX=4, SEC_INDEX=6, POST_INDEX=8;
            var amProbeTime = new Date(2000,0,1,6,12,34);
            var amProbeString = amProbeTime.toLocaleFormat("%X");
            var pmProbeTime = new Date(2000,0,1,18,12,34);
            var pmProbeString = pmProbeTime.toLocaleFormat("%X");
            var amFormatExpr = null, pmFormatExpr = null;
            if (amProbeString != pmProbeString) {
              var amProbeArray = probeTimeRegExp.exec(amProbeString);
              var pmProbeArray = probeTimeRegExp.exec(pmProbeString);
              if (amProbeArray != null && pmProbeArray != null) {
                if (amProbeArray[PRE_INDEX] && pmProbeArray[PRE_INDEX] &&
                    amProbeArray[PRE_INDEX] != pmProbeArray[PRE_INDEX]) {
                  this.ampmIndex = PRE_INDEX;
                } else if (amProbeArray[POST_INDEX] && pmProbeArray[POST_INDEX]) {
                  if (amProbeArray[POST_INDEX] != pmProbeArray[POST_INDEX]) {
                    this.ampmIndex = POST_INDEX;
                  } else {
                    // check if need to append previous character,
                    // captured by the optional separator pattern after seconds digits,
                    // or after minutes if no seconds, or after hours if no minutes.
                    for (var k = SEC_INDEX; k >= HR_INDEX; k -= 2) { 
                      var nextSepI = k + 1;
                      var nextDigitsI = k + 2;
                      if ((k == SEC_INDEX ||
                           (!amProbeArray[nextDigitsI] && !pmProbeArray[nextDigitsI]))
                          && amProbeArray[nextSepI] && pmProbeArray[nextSepI]
                          && amProbeArray[nextSepI] != pmProbeArray[nextSepI])
                      {
                        amProbeArray[POST_INDEX] =
                          amProbeArray[nextSepI] + amProbeArray[POST_INDEX];
                        pmProbeArray[POST_INDEX] =
                          pmProbeArray[nextSepI] + pmProbeArray[POST_INDEX];
                        this.ampmIndex = POST_INDEX;
                        break;
                      }
                    }
                  }
                }
                if (this.ampmIndex) {
                  var makeFormatRegExp = function(string) {
                    // make expr to accept either as provided, lowercased, or uppercased
                    var regExp = string.replace(/(\W)/g, "[$1]"); // escape punctuation
                    var lowercased = string.toLowerCase();
                    if (string != lowercased)
                      regExp += "|"+lowercased;
                    var uppercased = string.toUpperCase();
                    if (string != uppercased)
                      regExp += "|"+uppercased;
                    return regExp;
                  };
                  amFormatExpr = makeFormatRegExp(amProbeArray[this.ampmIndex]);
                  pmFormatExpr = makeFormatRegExp(pmProbeArray[this.ampmIndex]);
                }
              } 
            }
            // International formats ([roman, cyrillic]|arabic|chinese/kanji characters)
            // covering languages of U.N. (en,fr,sp,ru,ar,zh) and G8 (en,fr,de,it,ru,ja).
            // See examples at parseTimeOfDay.
            var amExpr =
              "[Aa\u0410\u0430][. ]?[Mm\u041c\u043c][. ]?|\u0635|\u4e0a\u5348|\u5348\u524d";
            var pmExpr =
              "[Pp\u0420\u0440][. ]?[Mm\u041c\u043c][. ]?|\u0645|\u4e0b\u5348|\u5348\u5f8c";
            if (this.ampmIndex){
              amExpr = amFormatExpr+"|"+amExpr;
              pmExpr = pmFormatExpr+"|"+pmExpr;
            }
            var ampmExpr = amExpr+"|"+pmExpr;
            // Must build am/pm formats into parse time regexp so that it can
            // match them without mistaking the initial char for an optional divider.
            // (For example, want to be able to parse both "12:34pm" and
            // "12H34M56Spm" for any characters H,M,S and any language's "pm".
            // The character between the last digit and the "pm" is optional.
            // Must recogize "pm" directly, otherwise in "12:34pm" the "S" pattern
            // matches the "p" character so only "m" is matched as ampm suffix.)
            //
            // digitsExpr has 6 captures, so index of first ampmExpr is 1, of last is 8.
            this.parseTimeRegExp =
              new RegExp("("+ampmExpr+")?\\s?"+digitsExpr+"("+ampmExpr+")?\\s*$");
            this.amRegExp = new RegExp("^(?:"+amExpr+")$");
            this.pmRegExp = new RegExp("^(?:"+pmExpr+")$");
            // build time display format that mimics "%x" format without seconds
            var ampmSep = (pmProbeString.indexOf(' ') != -1? " " : "");
	          if (this.ampmIndex == PRE_INDEX)
              this.kTimeFormatString = "%p" + ampmSep + "%I:%M";
            else if (this.ampmIndex == POST_INDEX)
              this.kTimeFormatString = "%I:%M" + ampmSep + "%p";
            else
              this.kTimeFormatString = "%H:%M";
          ]]>
        </body>
      </method>

      <method name="formatDate">
        <parameter name="aDate"/>
        <body>
          <![CDATA[
            // workaround for bugs 354073/327869:
            // aDate.toLocaleFormat("%x") exits application
            // if year before 1900 (e.g., typo) on MSWindows (due to MS bug).
            var nsIScriptableDateFormat =
              Components.interfaces.nsIScriptableDateFormat;
            var dateService =
              Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
                        .getService(nsIScriptableDateFormat);
            return dateService.FormatDate("", dateService.dateFormatShort,
                                          aDate.getFullYear(),
                                          aDate.getMonth()+1,
                                          aDate.getDate());
          ]]>
        </body>
      </method>

      <method name="formatTime">
        <parameter name="aValue"/>
        <body>
          <![CDATA[
            // remove leading zero in hours before colon in xx01:23pmxx
            return aValue.toLocaleFormat(this.kTimeFormatString).replace(/0(\d):/,"$1:");
          ]]>
        </body>
      </method>
    </implementation>
  </binding>
  
</bindings>