1
935090232@qq.com
2020-12-01 611146e69aaa62296cf84f2ccb5aca5ebba17677
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
/*
 * Date prototype extensions. Doesn't depend on any
 * other code. Doens't overwrite existing methods.
 * Download by http://www.codefans.net
 * Adds dayNames, abbrDayNames, monthNames and abbrMonthNames static properties and isLeapYear,
 * isWeekend, isWeekDay, getDaysInMonth, getDayName, getMonthName, getDayOfYear, getWeekOfYear,
 * setDayOfYear, addYears, addMonths, addDays, addHours, addMinutes, addSeconds methods
 *
 * Copyright (c) 2006 Jæžšrn Zaefferer and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 *
 * Additional methods and properties added by Kelvin Luck: firstDayOfWeek, dateFormat, zeroTime, asString, fromString -
 * I've added my name to these methods so you know who to blame if they are broken!
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */
 
/**
 * An Array of day names starting with Sunday.
 * 
 * @example dayNames[0]
 * @result 'Sunday'
 *
 * @name dayNames
 * @type Array
 * @cat Plugins/Methods/Date
 */
Date.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
 
/**
 * An Array of abbreviated day names starting with Sun.
 * 
 * @example abbrDayNames[0]
 * @result 'Sun'
 *
 * @name abbrDayNames
 * @type Array
 * @cat Plugins/Methods/Date
 */
Date.abbrDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
 
/**
 * An Array of month names starting with Janurary.
 * 
 * @example monthNames[0]
 * @result 'January'
 *
 * @name monthNames
 * @type Array
 * @cat Plugins/Methods/Date
 */
Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
 
/**
 * An Array of abbreviated month names starting with Jan.
 * 
 * @example abbrMonthNames[0]
 * @result 'Jan'
 *
 * @name monthNames
 * @type Array
 * @cat Plugins/Methods/Date
 */
Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
 
/**
 * The first day of the week for this locale.
 *
 * @name firstDayOfWeek
 * @type Number
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.firstDayOfWeek = 1;
 
/**
 * The format that string dates should be represented as (e.g. 'dd/mm/yyyy' for UK, 'mm/dd/yyyy' for US, 'yyyy-mm-dd' for Unicode etc).
 *
 * @name format
 * @type String
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.format = 'dd/mm/yyyy';
//Date.format = 'mm/dd/yyyy';
//Date.format = 'yyyy-mm-dd';
//Date.format = 'dd mmm yy';
 
/**
 * The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear
 * only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes.
 *
 * @name format
 * @type String
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.fullYearStart = '20';
 
(function() {
 
    /**
     * Adds a given method under the given name 
     * to the Date prototype if it doesn't
     * currently exist.
     *
     * @private
     */
    function add(name, method) {
        if( !Date.prototype[name] ) {
            Date.prototype[name] = method;
        }
    };
    
    /**
     * Checks if the year is a leap year.
     *
     * @example var dtm = new Date("01/12/2008");
     * dtm.isLeapYear();
     * @result true
     *
     * @name isLeapYear
     * @type Boolean
     * @cat Plugins/Methods/Date
     */
    add("isLeapYear", function() {
        var y = this.getFullYear();
        return (y%4==0 && y%100!=0) || y%400==0;
    });
    
    /**
     * Checks if the day is a weekend day (Sat or Sun).
     *
     * @example var dtm = new Date("01/12/2008");
     * dtm.isWeekend();
     * @result false
     *
     * @name isWeekend
     * @type Boolean
     * @cat Plugins/Methods/Date
     */
    add("isWeekend", function() {
        return this.getDay()==0 || this.getDay()==6;
    });
    
    /**
     * Check if the day is a day of the week (Mon-Fri)
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.isWeekDay();
     * @result false
     * 
     * @name isWeekDay
     * @type Boolean
     * @cat Plugins/Methods/Date
     */
    add("isWeekDay", function() {
        return !this.isWeekend();
    });
    
    /**
     * Gets the number of days in the month.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.getDaysInMonth();
     * @result 31
     * 
     * @name getDaysInMonth
     * @type Number
     * @cat Plugins/Methods/Date
     */
    add("getDaysInMonth", function() {
        return [31,(this.isLeapYear() ? 29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()];
    });
    
    /**
     * Gets the name of the day.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.getDayName();
     * @result 'Saturday'
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.getDayName(true);
     * @result 'Sat'
     * 
     * @param abbreviated Boolean When set to true the name will be abbreviated.
     * @name getDayName
     * @type String
     * @cat Plugins/Methods/Date
     */
    add("getDayName", function(abbreviated) {
        return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()];
    });
 
    /**
     * Gets the name of the month.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.getMonthName();
     * @result 'Janurary'
     *
     * @example var dtm = new Date("01/12/2008");
     * dtm.getMonthName(true);
     * @result 'Jan'
     * 
     * @param abbreviated Boolean When set to true the name will be abbreviated.
     * @name getDayName
     * @type String
     * @cat Plugins/Methods/Date
     */
    add("getMonthName", function(abbreviated) {
        return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()];
    });
 
    /**
     * Get the number of the day of the year.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.getDayOfYear();
     * @result 11
     * 
     * @name getDayOfYear
     * @type Number
     * @cat Plugins/Methods/Date
     */
    add("getDayOfYear", function() {
        var tmpdtm = new Date("1/1/" + this.getFullYear());
        return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000);
    });
    
    /**
     * Get the number of the week of the year.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.getWeekOfYear();
     * @result 2
     * 
     * @name getWeekOfYear
     * @type Number
     * @cat Plugins/Methods/Date
     */
    add("getWeekOfYear", function() {
        return Math.ceil(this.getDayOfYear() / 7);
    });
 
    /**
     * Set the day of the year.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.setDayOfYear(1);
     * dtm.toString();
     * @result 'Tue Jan 01 2008 00:00:00'
     * 
     * @name setDayOfYear
     * @type Date
     * @cat Plugins/Methods/Date
     */
    add("setDayOfYear", function(day) {
        this.setMonth(0);
        this.setDate(day);
        return this;
    });
    
    /**
     * Add a number of years to the date object.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.addYears(1);
     * dtm.toString();
     * @result 'Mon Jan 12 2009 00:00:00'
     * 
     * @name addYears
     * @type Date
     * @cat Plugins/Methods/Date
     */
    add("addYears", function(num) {
        this.setFullYear(this.getFullYear() + num);
        return this;
    });
    
    /**
     * Add a number of months to the date object.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.addMonths(1);
     * dtm.toString();
     * @result 'Tue Feb 12 2008 00:00:00'
     * 
     * @name addMonths
     * @type Date
     * @cat Plugins/Methods/Date
     */
    add("addMonths", function(num) {
        var tmpdtm = this.getDate();
        
        this.setMonth(this.getMonth() + num);
        
        if (tmpdtm > this.getDate())
            this.addDays(-this.getDate());
        
        return this;
    });
    
    /**
     * Add a number of days to the date object.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.addDays(1);
     * dtm.toString();
     * @result 'Sun Jan 13 2008 00:00:00'
     * 
     * @name addDays
     * @type Date
     * @cat Plugins/Methods/Date
     */
    add("addDays", function(num) {
        //this.setDate(this.getDate() + num);
        this.setTime(this.getTime() + (num*86400000) );
        return this;
    });
    
    /**
     * Add a number of hours to the date object.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.addHours(24);
     * dtm.toString();
     * @result 'Sun Jan 13 2008 00:00:00'
     * 
     * @name addHours
     * @type Date
     * @cat Plugins/Methods/Date
     */
    add("addHours", function(num) {
        this.setHours(this.getHours() + num);
        return this;
    });
 
    /**
     * Add a number of minutes to the date object.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.addMinutes(60);
     * dtm.toString();
     * @result 'Sat Jan 12 2008 01:00:00'
     * 
     * @name addMinutes
     * @type Date
     * @cat Plugins/Methods/Date
     */
    add("addMinutes", function(num) {
        this.setMinutes(this.getMinutes() + num);
        return this;
    });
    
    /**
     * Add a number of seconds to the date object.
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.addSeconds(60);
     * dtm.toString();
     * @result 'Sat Jan 12 2008 00:01:00'
     * 
     * @name addSeconds
     * @type Date
     * @cat Plugins/Methods/Date
     */
    add("addSeconds", function(num) {
        this.setSeconds(this.getSeconds() + num);
        return this;
    });
    
    /**
     * Sets the time component of this Date to zero for cleaner, easier comparison of dates where time is not relevant.
     * 
     * @example var dtm = new Date();
     * dtm.zeroTime();
     * dtm.toString();
     * @result 'Sat Jan 12 2008 00:01:00'
     * 
     * @name zeroTime
     * @type Date
     * @cat Plugins/Methods/Date
     * @author Kelvin Luck
     */
    add("zeroTime", function() {
        this.setMilliseconds(0);
        this.setSeconds(0);
        this.setMinutes(0);
        this.setHours(0);
        return this;
    });
    
    /**
     * Returns a string representation of the date object according to Date.format.
     * (Date.toString may be used in other places so I purposefully didn't overwrite it)
     * 
     * @example var dtm = new Date("01/12/2008");
     * dtm.asString();
     * @result '12/01/2008' // (where Date.format == 'dd/mm/yyyy'
     * 
     * @name asString
     * @type Date
     * @cat Plugins/Methods/Date
     * @author Kelvin Luck
     */
    add("asString", function(format) {
        var r = format || Date.format;
        if (r.split('mm').length>1) { // ugly workaround to make sure we don't replace the m's in e.g. noveMber
            r = r.split('mmmm').join(this.getMonthName(false))
                .split('mmm').join(this.getMonthName(true))
                .split('mm').join(_zeroPad(this.getMonth()+1))
        } else {
            r = r.split('m').join(this.getMonth()+1);
        }
        r = r.split('yyyy').join(this.getFullYear())
            .split('yy').join((this.getFullYear() + '').substring(2))
            .split('dd').join(_zeroPad(this.getDate()))
            .split('d').join(this.getDate());
        return r;
    });
    
    /**
     * Returns a new date object created from the passed String according to Date.format or false if the attempt to do this results in an invalid date object
     * (We can't simple use Date.parse as it's not aware of locale and I chose not to overwrite it incase it's functionality is being relied on elsewhere)
     *
     * @example var dtm = Date.fromString("12/01/2008");
     * dtm.toString();
     * @result 'Sat Jan 12 2008 00:00:00' // (where Date.format == 'dd/mm/yyyy'
     * 
     * @name fromString
     * @type Date
     * @cat Plugins/Methods/Date
     * @author Kelvin Luck
     */
    Date.fromString = function(s)
    {
        var f = Date.format;
        
        var d = new Date('01/01/1970');
        
        if (s == '') return d;
 
        s = s.toLowerCase();
        var matcher = '';
        var order = [];
        var r = /(dd?d?|mm?m?|yy?yy?)+([^(m|d|y)])?/g;
        var results;
        while ((results = r.exec(f)) != null)
        {
            switch (results[1]) {
                case 'd':
                case 'dd':
                case 'm':
                case 'mm':
                case 'yy':
                case 'yyyy':
                    matcher += '(\\d+\\d?\\d?\\d?)+';
                    order.push(results[1].substr(0, 1));
                    break;
                case 'mmm':
                    matcher += '([a-z]{3})';
                    order.push('M');
                    break;
            }
            if (results[2]) {
                matcher += results[2];
            }
            
        }
        var dm = new RegExp(matcher);
        var result = s.match(dm);
        for (var i=0; i<order.length; i++) {
            var res = result[i+1];
            switch(order[i]) {
                case 'd':
                    d.setDate(res);
                    break;
                case 'm':
                    d.setMonth(Number(res)-1);
                    break;
                case 'M':
                    for (var j=0; j<Date.abbrMonthNames.length; j++) {
                        if (Date.abbrMonthNames[j].toLowerCase() == res) break;
                    }
                    d.setMonth(j);
                    break;
                case 'y':
                    d.setYear(res);
                    break;
            }
        }
 
        return d;
    };
    
    // utility method
    var _zeroPad = function(num) {
        var s = '0'+num;
        return s.substring(s.length-2)
        //return ('0'+num).substring(-2); // doesn't work on IE :(
    };
    
})();
 
 
/**
 * Copyright (c) 2008 Kelvin Luck (http://www.kelvinluck.com/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $Id: jquery.datePicker.js 70 2009-04-05 19:25:15Z kelvin.luck $
 **/
 
(function($){
    
    $.fn.extend({
/**
 * Render a calendar table into any matched elements.
 * 
 * @param Object s (optional) Customize your calendars.
 * @option Number month The month to render (NOTE that months are zero based). Default is today's month.
 * @option Number year The year to render. Default is today's year.
 * @option Function renderCallback A reference to a function that is called as each cell is rendered and which can add classes and event listeners to the created nodes. Default is no callback.
 * @option Number showHeader Whether or not to show the header row, possible values are: $.dpConst.SHOW_HEADER_NONE (no header), $.dpConst.SHOW_HEADER_SHORT (first letter of each day) and $.dpConst.SHOW_HEADER_LONG (full name of each day). Default is $.dpConst.SHOW_HEADER_SHORT.
 * @option String hoverClass The class to attach to each cell when you hover over it (to allow you to use hover effects in IE6 which doesn't support the :hover pseudo-class on elements other than links). Default is dp-hover. Pass false if you don't want a hover class.
 * @type jQuery
 * @name renderCalendar
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('#calendar-me').renderCalendar({month:0, year:2007});
 * @desc Renders a calendar displaying January 2007 into the element with an id of calendar-me.
 *
 * @example
 * var testCallback = function($td, thisDate, month, year)
 * {
 * if ($td.is('.current-month') && thisDate.getDay() == 4) {
 *        var d = thisDate.getDate();
 *        $td.bind(
 *            'click',
 *            function()
 *            {
 *                alert('You clicked on ' + d + '/' + (Number(month)+1) + '/' + year);
 *            }
 *        ).addClass('thursday');
 *    } else if (thisDate.getDay() == 5) {
 *        $td.html('Friday the ' + $td.html() + 'th');
 *    }
 * }
 * $('#calendar-me').renderCalendar({month:0, year:2007, renderCallback:testCallback});
 * 
 * @desc Renders a calendar displaying January 2007 into the element with an id of calendar-me. Every Thursday in the current month has a class of "thursday" applied to it, is clickable and shows an alert when clicked. Every Friday on the calendar has the number inside replaced with text.
 **/
        renderCalendar  :   function(s)
        {
            var dc = function(a)
            {
                return document.createElement(a);
            };
 
            s = $.extend({}, $.fn.datePicker.defaults, s);
            
            if (s.showHeader != $.dpConst.SHOW_HEADER_NONE) {
                var headRow = $(dc('tr'));
                for (var i=Date.firstDayOfWeek; i<Date.firstDayOfWeek+7; i++) {
                    var weekday = i%7;
                    var day = Date.dayNames[weekday];
                    headRow.append(
                        jQuery(dc('th')).attr({'scope':'col', 'abbr':day, 'title':day, 'class':(weekday == 0 || weekday == 6 ? 'weekend' : 'weekday')}).html(s.showHeader == $.dpConst.SHOW_HEADER_SHORT ? day.substr(0, 1) : day)
                    );
                }
            };
            
            var calendarTable = $(dc('table'))
                                    .attr(
                                        {
                                            'cellspacing':2
                                        }
                                    )
                                    .addClass('jCalendar')
                                    .append(
                                        (s.showHeader != $.dpConst.SHOW_HEADER_NONE ? 
                                            $(dc('thead'))
                                                .append(headRow)
                                            :
                                            dc('thead')
                                        )
                                    );
            var tbody = $(dc('tbody'));
            
            var today = (new Date()).zeroTime();
            
            var month = s.month == undefined ? today.getMonth() : s.month;
            var year = s.year || today.getFullYear();
            
            var currentDate = new Date(year, month, 1);
            
            
            var firstDayOffset = Date.firstDayOfWeek - currentDate.getDay() + 1;
            if (firstDayOffset > 1) firstDayOffset -= 7;
            var weeksToDraw = Math.ceil(( (-1*firstDayOffset+1) + currentDate.getDaysInMonth() ) /7);
            currentDate.addDays(firstDayOffset-1);
            
            var doHover = function(firstDayInBounds)
            {
                return function()
                {
                    if (s.hoverClass) {
                        var $this = $(this);
                        if (!s.selectWeek) {
                            $this.addClass(s.hoverClass);
                        } else if (firstDayInBounds && !$this.is('.disabled')) {
                            $this.parent().addClass('activeWeekHover');
                        }
                    }
                }
            };
            var unHover = function()
            {
                if (s.hoverClass) {
                    var $this = $(this);
                    $this.removeClass(s.hoverClass);
                    $this.parent().removeClass('activeWeekHover');
                }
            };
 
            var w = 0;
            while (w++<weeksToDraw) {
                var r = jQuery(dc('tr'));
                var firstDayInBounds = s.dpController ? currentDate > s.dpController.startDate : false;
                for (var i=0; i<7; i++) {
                    var thisMonth = currentDate.getMonth() == month;
                    var d = $(dc('td'))
                                .text(currentDate.getDate() + '')
                                .addClass((thisMonth ? 'current-month ' : 'other-month ') +
                                                    (currentDate.isWeekend() ? 'weekend ' : 'weekday ') +
                                                    (thisMonth && currentDate.getTime() == today.getTime() ? 'today ' : '')
                                )
                                .data('datePickerDate', currentDate.asString())
                                .hover(doHover(firstDayInBounds), unHover)
                            ;
                    r.append(d);
                    if (s.renderCallback) {
                        s.renderCallback(d, currentDate, month, year);
                    }
                    // addDays(1) fails in some locales due to daylight savings. See issue 39.
                    //currentDate.addDays(1);
                    currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1);
                }
                tbody.append(r);
            }
            calendarTable.append(tbody);
            
            return this.each(
                function()
                {
                    $(this).empty().append(calendarTable);
                }
            );
        },
/**
 * Create a datePicker associated with each of the matched elements.
 *
 * The matched element will receive a few custom events with the following signatures:
 *
 * dateSelected(event, date, $td, status)
 * Triggered when a date is selected. event is a reference to the event, date is the Date selected, $td is a jquery object wrapped around the TD that was clicked on and status is whether the date was selected (true) or deselected (false)
 * 
 * dpClosed(event, selected)
 * Triggered when the date picker is closed. event is a reference to the event and selected is an Array containing Date objects.
 *
 * dpMonthChanged(event, displayedMonth, displayedYear)
 * Triggered when the month of the popped up calendar is changed. event is a reference to the event, displayedMonth is the number of the month now displayed (zero based) and displayedYear is the year of the month.
 *
 * dpDisplayed(event, $datePickerDiv)
 * Triggered when the date picker is created. $datePickerDiv is the div containing the date picker. Use this event to add custom content/ listeners to the popped up date picker.
 *
 * @param Object s (optional) Customize your date pickers.
 * @option Number month The month to render when the date picker is opened (NOTE that months are zero based). Default is today's month.
 * @option Number year The year to render when the date picker is opened. Default is today's year.
 * @option String startDate The first date date can be selected.
 * @option String endDate The last date that can be selected.
 * @option Boolean inline Whether to create the datePicker as inline (e.g. always on the page) or as a model popup. Default is false (== modal popup)
 * @option Boolean createButton Whether to create a .dp-choose-date anchor directly after the matched element which when clicked will trigger the showing of the date picker. Default is true.
 * @option Boolean showYearNavigation Whether to display buttons which allow the user to navigate through the months a year at a time. Default is true.
 * @option Boolean closeOnSelect Whether to close the date picker when a date is selected. Default is true.
 * @option Boolean displayClose Whether to create a "Close" button within the date picker popup. Default is false.
 * @option Boolean selectMultiple Whether a user should be able to select multiple dates with this date picker. Default is false.
 * @option Number numSelectable The maximum number of dates that can be selected where selectMultiple is true. Default is a very high number.
 * @option Boolean clickInput If the matched element is an input type="text" and this option is true then clicking on the input will cause the date picker to appear.
 * @option Boolean rememberViewedMonth Whether the datePicker should remember the last viewed month and open on it. If false then the date picker will always open with the month for the first selected date visible.
 * @option Boolean selectWeek Whether to select a complete week at a time...
 * @option Number verticalPosition The vertical alignment of the popped up date picker to the matched element. One of $.dpConst.POS_TOP and $.dpConst.POS_BOTTOM. Default is $.dpConst.POS_TOP.
 * @option Number horizontalPosition The horizontal alignment of the popped up date picker to the matched element. One of $.dpConst.POS_LEFT and $.dpConst.POS_RIGHT.
 * @option Number verticalOffset The number of pixels offset from the defined verticalPosition of this date picker that it should pop up in. Default in 0.
 * @option Number horizontalOffset The number of pixels offset from the defined horizontalPosition of this date picker that it should pop up in. Default in 0.
 * @option (Function|Array) renderCallback A reference to a function (or an array of seperate functions) that is called as each cell is rendered and which can add classes and event listeners to the created nodes. Each callback function will receive four arguments; a jquery object wrapping the created TD, a Date object containing the date this TD represents, a number giving the currently rendered month and a number giving the currently rendered year. Default is no callback.
 * @option String hoverClass The class to attach to each cell when you hover over it (to allow you to use hover effects in IE6 which doesn't support the :hover pseudo-class on elements other than links). Default is dp-hover. Pass false if you don't want a hover class.
 * @type jQuery
 * @name datePicker
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('input.date-picker').datePicker();
 * @desc Creates a date picker button next to all matched input elements. When the button is clicked on the value of the selected date will be placed in the corresponding input (formatted according to Date.format).
 *
 * @example demo/index.html
 * @desc See the projects homepage for many more complex examples...
 **/
        datePicker : function(s)
        {            
            if (!$.event._dpCache) $.event._dpCache = [];
            
            // initialise the date picker controller with the relevant settings...
            s = $.extend({}, $.fn.datePicker.defaults, s);
            
            return this.each(
                function()
                {
                    var $this = $(this);
                    var alreadyExists = true;
                    
                    if (!this._dpId) {
                        this._dpId = $.event.guid++;
                        $.event._dpCache[this._dpId] = new DatePicker(this);
                        alreadyExists = false;
                    }
                    
                    if (s.inline) {
                        s.createButton = false;
                        s.displayClose = false;
                        s.closeOnSelect = false;
                        $this.empty();
                    }
                    
                    var controller = $.event._dpCache[this._dpId];
                    
                    controller.init(s);
                    
                    if (!alreadyExists && s.createButton) {
                        // create it!
                        controller.button = $('<a href="#" class="dp-choose-date" title="' + $.dpText.TEXT_CHOOSE_DATE + '">' + $.dpText.TEXT_CHOOSE_DATE + '</a>')
                                .bind(
                                    'click',
                                    function()
                                    {
                                        $this.dpDisplay(this);
                                        this.blur();
                                        return false;
                                    }
                                );
                        $this.after(controller.button);
                    }
                    
                    if (!alreadyExists && $this.is(':text')) {
                        $this
                            .bind(
                                'dateSelected',
                                function(e, selectedDate, $td)
                                {
                                    this.value = selectedDate.asString();
                                }
                            ).bind(
                                'change',
                                function()
                                {
                                    if (this.value == '') {
                                        controller.clearSelected();
                                    } else {
                                        var d = Date.fromString(this.value);
                                        if (d) {
                                            controller.setSelected(d, true, true);
                                        }
                                    }
                                }
                            );
                        if (s.clickInput) {
                            $this.bind(
                                'click',
                                function()
                                {
                                    // The change event doesn't happen until the input loses focus so we need to manually trigger it...
                                    $this.trigger('change');
                                    $this.dpDisplay();
                                }
                            );
                        }
                        var d = Date.fromString(this.value);
                        if (this.value != '' && d) {
                            controller.setSelected(d, true, true);
                        }
                    }
                    
                    $this.addClass('dp-applied');
                    
                }
            )
        },
/**
 * Disables or enables this date picker
 *
 * @param Boolean s Whether to disable (true) or enable (false) this datePicker
 * @type jQuery
 * @name dpSetDisabled
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('.date-picker').datePicker();
 * $('.date-picker').dpSetDisabled(true);
 * @desc Prevents this date picker from displaying and adds a class of dp-disabled to it (and it's associated button if it has one) for styling purposes. If the matched element is an input field then it will also set the disabled attribute to stop people directly editing the field.
 **/
        dpSetDisabled : function(s)
        {
            return _w.call(this, 'setDisabled', s);
        },
/**
 * Updates the first selectable date for any date pickers on any matched elements.
 *
 * @param String d A string representing the first selectable date (formatted according to Date.format).
 * @type jQuery
 * @name dpSetStartDate
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('.date-picker').datePicker();
 * $('.date-picker').dpSetStartDate('01/01/2000');
 * @desc Creates a date picker associated with all elements with a class of "date-picker" then sets the first selectable date for each of these to the first day of the millenium.
 **/
        dpSetStartDate : function(d)
        {
            return _w.call(this, 'setStartDate', d);
        },
/**
 * Updates the last selectable date for any date pickers on any matched elements.
 *
 * @param String d A string representing the last selectable date (formatted according to Date.format).
 * @type jQuery
 * @name dpSetEndDate
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('.date-picker').datePicker();
 * $('.date-picker').dpSetEndDate('01/01/2010');
 * @desc Creates a date picker associated with all elements with a class of "date-picker" then sets the last selectable date for each of these to the first Janurary 2010.
 **/
        dpSetEndDate : function(d)
        {
            return _w.call(this, 'setEndDate', d);
        },
/**
 * Gets a list of Dates currently selected by this datePicker. This will be an empty array if no dates are currently selected or NULL if there is no datePicker associated with the matched element.
 *
 * @type Array
 * @name dpGetSelected
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('.date-picker').datePicker();
 * alert($('.date-picker').dpGetSelected());
 * @desc Will alert an empty array (as nothing is selected yet)
 **/
        dpGetSelected : function()
        {
            var c = _getController(this[0]);
            if (c) {
                return c.getSelected();
            }
            return null;
        },
/**
 * Selects or deselects a date on any matched element's date pickers. Deselcting is only useful on date pickers where selectMultiple==true. Selecting will only work if the passed date is within the startDate and endDate boundries for a given date picker.
 *
 * @param String d A string representing the date you want to select (formatted according to Date.format).
 * @param Boolean v Whether you want to select (true) or deselect (false) this date. Optional - default = true.
 * @param Boolean m Whether you want the date picker to open up on the month of this date when it is next opened. Optional - default = true.
 * @param Boolean e Whether you want the date picker to dispatch events related to this change of selection. Optional - default = true.
 * @type jQuery
 * @name dpSetSelected
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('.date-picker').datePicker();
 * $('.date-picker').dpSetSelected('01/01/2010');
 * @desc Creates a date picker associated with all elements with a class of "date-picker" then sets the selected date on these date pickers to the first Janurary 2010. When the date picker is next opened it will display Janurary 2010.
 **/
        dpSetSelected : function(d, v, m, e)
        {
            if (v == undefined) v=true;
            if (m == undefined) m=true;
            if (e == undefined) e=true;
            return _w.call(this, 'setSelected', Date.fromString(d), v, m, e);
        },
/**
 * Sets the month that will be displayed when the date picker is next opened. If the passed month is before startDate then the month containing startDate will be displayed instead. If the passed month is after endDate then the month containing the endDate will be displayed instead.
 *
 * @param Number m The month you want the date picker to display. Optional - defaults to the currently displayed month.
 * @param Number y The year you want the date picker to display. Optional - defaults to the currently displayed year.
 * @type jQuery
 * @name dpSetDisplayedMonth
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('.date-picker').datePicker();
 * $('.date-picker').dpSetDisplayedMonth(10, 2008);
 * @desc Creates a date picker associated with all elements with a class of "date-picker" then sets the selected date on these date pickers to the first Janurary 2010. When the date picker is next opened it will display Janurary 2010.
 **/
        dpSetDisplayedMonth : function(m, y)
        {
            return _w.call(this, 'setDisplayedMonth', Number(m), Number(y), true);
        },
/**
 * Displays the date picker associated with the matched elements. Since only one date picker can be displayed at once then the date picker associated with the last matched element will be the one that is displayed.
 *
 * @param HTMLElement e An element that you want the date picker to pop up relative in position to. Optional - default behaviour is to pop up next to the element associated with this date picker.
 * @type jQuery
 * @name dpDisplay
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('#date-picker').datePicker();
 * $('#date-picker').dpDisplay();
 * @desc Creates a date picker associated with the element with an id of date-picker and then causes it to pop up.
 **/
        dpDisplay : function(e)
        {
            return _w.call(this, 'display', e);
        },
/**
 * Sets a function or array of functions that is called when each TD of the date picker popup is rendered to the page
 *
 * @param (Function|Array) a A function or an array of functions that are called when each td is rendered. Each function will receive four arguments; a jquery object wrapping the created TD, a Date object containing the date this TD represents, a number giving the currently rendered month and a number giving the currently rendered year.
 * @type jQuery
 * @name dpSetRenderCallback
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('#date-picker').datePicker();
 * $('#date-picker').dpSetRenderCallback(function($td, thisDate, month, year)
 * {
 *     // do stuff as each td is rendered dependant on the date in the td and the displayed month and year
 * });
 * @desc Creates a date picker associated with the element with an id of date-picker and then creates a function which is called as each td is rendered when this date picker is displayed.
 **/
        dpSetRenderCallback : function(a)
        {
            return _w.call(this, 'setRenderCallback', a);
        },
/**
 * Sets the position that the datePicker will pop up (relative to it's associated element)
 *
 * @param Number v The vertical alignment of the created date picker to it's associated element. Possible values are $.dpConst.POS_TOP and $.dpConst.POS_BOTTOM
 * @param Number h The horizontal alignment of the created date picker to it's associated element. Possible values are $.dpConst.POS_LEFT and $.dpConst.POS_RIGHT
 * @type jQuery
 * @name dpSetPosition
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('#date-picker').datePicker();
 * $('#date-picker').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_RIGHT);
 * @desc Creates a date picker associated with the element with an id of date-picker and makes it so that when this date picker pops up it will be bottom and right aligned to the #date-picker element.
 **/
        dpSetPosition : function(v, h)
        {
            return _w.call(this, 'setPosition', v, h);
        },
/**
 * Sets the offset that the popped up date picker will have from it's default position relative to it's associated element (as set by dpSetPosition)
 *
 * @param Number v The vertical offset of the created date picker.
 * @param Number h The horizontal offset of the created date picker.
 * @type jQuery
 * @name dpSetOffset
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('#date-picker').datePicker();
 * $('#date-picker').dpSetOffset(-20, 200);
 * @desc Creates a date picker associated with the element with an id of date-picker and makes it so that when this date picker pops up it will be 20 pixels above and 200 pixels to the right of it's default position.
 **/
        dpSetOffset : function(v, h)
        {
            return _w.call(this, 'setOffset', v, h);
        },
/**
 * Closes the open date picker associated with this element.
 *
 * @type jQuery
 * @name dpClose
 * @cat plugins/datePicker
 * @author Kelvin Luck (http://www.kelvinluck.com/)
 *
 * @example $('.date-pick')
 *        .datePicker()
 *        .bind(
 *            'focus',
 *            function()
 *            {
 *                $(this).dpDisplay();
 *            }
 *        ).bind(
 *            'blur',
 *            function()
 *            {
 *                $(this).dpClose();
 *            }
 *        );
 * @desc Creates a date picker and makes it appear when the relevant element is focused and disappear when it is blurred.
 **/
        dpClose : function()
        {
            return _w.call(this, '_closeCalendar', false, this[0]);
        },
        // private function called on unload to clean up any expandos etc and prevent memory links...
        _dpDestroy : function()
        {
            // TODO - implement this?
        }
    });
    
    // private internal function to cut down on the amount of code needed where we forward
    // dp* methods on the jQuery object on to the relevant DatePicker controllers...
    var _w = function(f, a1, a2, a3, a4)
    {
        return this.each(
            function()
            {
                var c = _getController(this);
                if (c) {
                    c[f](a1, a2, a3, a4);
                }
            }
        );
    };
    
    function DatePicker(ele)
    {
        this.ele = ele;
        
        // initial values...
        this.displayedMonth        =    null;
        this.displayedYear        =    null;
        this.startDate            =    null;
        this.endDate            =    null;
        this.showYearNavigation    =    null;
        this.closeOnSelect        =    null;
        this.displayClose        =    null;
        this.rememberViewedMonth=    null;
        this.selectMultiple        =    null;
        this.numSelectable        =    null;
        this.numSelected        =    null;
        this.verticalPosition    =    null;
        this.horizontalPosition    =    null;
        this.verticalOffset        =    null;
        this.horizontalOffset    =    null;
        this.button                =    null;
        this.renderCallback        =    [];
        this.selectedDates        =    {};
        this.inline                =    null;
        this.context            =    '#dp-popup';
        this.settings            =    {};
    };
    $.extend(
        DatePicker.prototype,
        {    
            init : function(s)
            {
                this.setStartDate(s.startDate);
                this.setEndDate(s.endDate);
                this.setDisplayedMonth(Number(s.month), Number(s.year));
                this.setRenderCallback(s.renderCallback);
                this.showYearNavigation = s.showYearNavigation;
                this.closeOnSelect = s.closeOnSelect;
                this.displayClose = s.displayClose;
                this.rememberViewedMonth =    s.rememberViewedMonth;
                this.selectMultiple = s.selectMultiple;
                this.numSelectable = s.selectMultiple ? s.numSelectable : 1;
                this.numSelected = 0;
                this.verticalPosition = s.verticalPosition;
                this.horizontalPosition = s.horizontalPosition;
                this.hoverClass = s.hoverClass;
                this.setOffset(s.verticalOffset, s.horizontalOffset);
                this.inline = s.inline;
                this.settings = s;
                if (this.inline) {
                    this.context = this.ele;
                    this.display();
                }
            },
            setStartDate : function(d)
            {
                if (d) {
                    this.startDate = Date.fromString(d);
                }
                if (!this.startDate) {
                    this.startDate = (new Date()).zeroTime();
                }
                this.setDisplayedMonth(this.displayedMonth, this.displayedYear);
            },
            setEndDate : function(d)
            {
                if (d) {
                    this.endDate = Date.fromString(d);
                }
                if (!this.endDate) {
                    this.endDate = (new Date('12/31/2999')); // using the JS Date.parse function which expects mm/dd/yyyy
                }
                if (this.endDate.getTime() < this.startDate.getTime()) {
                    this.endDate = this.startDate;
                }
                this.setDisplayedMonth(this.displayedMonth, this.displayedYear);
            },
            setPosition : function(v, h)
            {
                this.verticalPosition = v;
                this.horizontalPosition = h;
            },
            setOffset : function(v, h)
            {
                this.verticalOffset = parseInt(v) || 0;
                this.horizontalOffset = parseInt(h) || 0;
            },
            setDisabled : function(s)
            {
                $e = $(this.ele);
                $e[s ? 'addClass' : 'removeClass']('dp-disabled');
                if (this.button) {
                    $but = $(this.button);
                    $but[s ? 'addClass' : 'removeClass']('dp-disabled');
                    $but.attr('title', s ? '' : $.dpText.TEXT_CHOOSE_DATE);
                }
                if ($e.is(':text')) {
                    $e.attr('disabled', s ? 'disabled' : '');
                }
            },
            setDisplayedMonth : function(m, y, rerender)
            {
                if (this.startDate == undefined || this.endDate == undefined) {
                    return;
                }
                var s = new Date(this.startDate.getTime());
                s.setDate(1);
                var e = new Date(this.endDate.getTime());
                e.setDate(1);
                
                var t;
                if ((!m && !y) || (isNaN(m) && isNaN(y))) {
                    // no month or year passed - default to current month
                    t = new Date().zeroTime();
                    t.setDate(1);
                } else if (isNaN(m)) {
                    // just year passed in - presume we want the displayedMonth
                    t = new Date(y, this.displayedMonth, 1);
                } else if (isNaN(y)) {
                    // just month passed in - presume we want the displayedYear
                    t = new Date(this.displayedYear, m, 1);
                } else {
                    // year and month passed in - that's the date we want!
                    t = new Date(y, m, 1)
                }
                // check if the desired date is within the range of our defined startDate and endDate
                if (t.getTime() < s.getTime()) {
                    t = s;
                } else if (t.getTime() > e.getTime()) {
                    t = e;
                }
                var oldMonth = this.displayedMonth;
                var oldYear = this.displayedYear;
                this.displayedMonth = t.getMonth();
                this.displayedYear = t.getFullYear();
 
                if (rerender && (this.displayedMonth != oldMonth || this.displayedYear != oldYear))
                {
                    this._rerenderCalendar();
                    $(this.ele).trigger('dpMonthChanged', [this.displayedMonth, this.displayedYear]);
                }
            },
            setSelected : function(d, v, moveToMonth, dispatchEvents)
            {
                if (d < this.startDate || d > this.endDate) {
                    // Don't allow people to select dates outside range...
                    return;
                }
                var s = this.settings;
                if (s.selectWeek)
                {
                    d = d.addDays(- (d.getDay() - Date.firstDayOfWeek + 7) % 7);
                    if (d < this.startDate) // The first day of this week is before the start date so is unselectable...
                    {
                        return;
                    }
                }
                if (v == this.isSelected(d)) // this date is already un/selected
                {
                    return;
                }
                if (this.selectMultiple == false) {
                    this.clearSelected();
                } else if (v && this.numSelected == this.numSelectable) {
                    // can't select any more dates...
                    return;
                }
                if (moveToMonth && (this.displayedMonth != d.getMonth() || this.displayedYear != d.getFullYear())) {
                    this.setDisplayedMonth(d.getMonth(), d.getFullYear(), true);
                }
                this.selectedDates[d.toString()] = v;
                this.numSelected += v ? 1 : -1;
                var selectorString = 'td.' +( d.getMonth() == this.displayedMonth ? 'current-month' : 'other-month');
                var $td;
                $(selectorString, this.context).each(
                    function()
                    {
                        if ($(this).data('datePickerDate') == d.asString()) {
                            $td = $(this);
                            if (s.selectWeek)
                            {
                                $td.parent()[v ? 'addClass' : 'removeClass']('selectedWeek');
                            }
                            $td[v ? 'addClass' : 'removeClass']('selected'); 
                        }
                    }
                );
                $('td', this.context).not('.selected')[this.selectMultiple &&  this.numSelected == this.numSelectable ? 'addClass' : 'removeClass']('unselectable');
                
                if (dispatchEvents)
                {
                    var s = this.isSelected(d);
                    $e = $(this.ele);
                    var dClone = Date.fromString(d.asString());
                    $e.trigger('dateSelected', [dClone, $td, s]);
                    $e.trigger('change');
                }
            },
            isSelected : function(d)
            {
                return this.selectedDates[d.toString()];
            },
            getSelected : function()
            {
                var r = [];
                for(s in this.selectedDates) {
                    if (this.selectedDates[s] == true) {
                        r.push(Date.parse(s));
                    }
                }
                return r;
            },
            clearSelected : function()
            {
                this.selectedDates = {};
                this.numSelected = 0;
                $('td.selected', this.context).removeClass('selected').parent().removeClass('selectedWeek');
            },
            display : function(eleAlignTo)
            {
                if ($(this.ele).is('.dp-disabled')) return;
                
                eleAlignTo = eleAlignTo || this.ele;
                var c = this;
                var $ele = $(eleAlignTo);
                var eleOffset = $ele.offset();
                
                var $createIn;
                var attrs;
                var attrsCalendarHolder;
                var cssRules;
                
                if (c.inline) {
                    $createIn = $(this.ele);
                    attrs = {
                        'id'        :    'calendar-' + this.ele._dpId,
                        'class'    :    'dp-popup dp-popup-inline'
                    };
 
                    $('.dp-popup', $createIn).remove();
                    cssRules = {
                    };
                } else {
                    $createIn = $('body');
                    attrs = {
                        'id'        :    'dp-popup',
                        'class'    :    'dp-popup'
                    };
                    cssRules = {
                        'top'    :    eleOffset.top + c.verticalOffset,
                        'left'    :    eleOffset.left + c.horizontalOffset
                    };
                    
                    var _checkMouse = function(e)
                    {
                        var el = e.target;
                        var cal = $('#dp-popup')[0];
                        
                        while (true){
                            if (el == cal) {
                                return true;
                            } else if (el == document) {
                                c._closeCalendar();
                                return false;
                            } else {
                                el = $(el).parent()[0];
                            }
                        }
                    };
                    this._checkMouse = _checkMouse;
                    
                    c._closeCalendar(true);
                    $(document).bind(
                        'keydown.datepicker', 
                        function(event)
                        {
                            if (event.keyCode == 27) {
                                c._closeCalendar();
                            }
                        }
                    );
                }
                
                if (!c.rememberViewedMonth)
                {
                    var selectedDate = this.getSelected()[0];
                    if (selectedDate) {
                        selectedDate = new Date(selectedDate);
                        this.setDisplayedMonth(selectedDate.getMonth(), selectedDate.getFullYear(), false);
                    }
                }
                
                $createIn
                    .append(
                        $('<div></div>')
                            .attr(attrs)
                            .css(cssRules)
                            .append(
//                                $('<a href="#" class="selecteee">aaa</a>'),
                                $('<h2></h2>'),
                                $('<div class="dp-nav-prev"></div>')
                                    .append(
                                        $('<a class="dp-nav-prev-year" href="#" title="' + $.dpText.TEXT_PREV_YEAR + '">&lt;&lt;</a>')
                                            .bind(
                                                'click',
                                                function()
                                                {
                                                    return c._displayNewMonth.call(c, this, 0, -1);
                                                }
                                            ),
                                        $('<a class="dp-nav-prev-month" href="#" title="' + $.dpText.TEXT_PREV_MONTH + '">&lt;</a>')
                                            .bind(
                                                'click',
                                                function()
                                                {
                                                    return c._displayNewMonth.call(c, this, -1, 0);
                                                }
                                            )
                                    ),
                                $('<div class="dp-nav-next"></div>')
                                    .append(
                                        $('<a class="dp-nav-next-year" href="#" title="' + $.dpText.TEXT_NEXT_YEAR + '">&gt;&gt;</a>')
                                            .bind(
                                                'click',
                                                function()
                                                {
                                                    return c._displayNewMonth.call(c, this, 0, 1);
                                                }
                                            ),
                                        $('<a class="dp-nav-next-month" href="#" title="' + $.dpText.TEXT_NEXT_MONTH + '">&gt;</a>')
                                            .bind(
                                                'click',
                                                function()
                                                {
                                                    return c._displayNewMonth.call(c, this, 1, 0);
                                                }
                                            )
                                    ),
                                $('<div class="dp-calendar"></div>')
                            )
                            .bgIframe()
                        );
                    
                var $pop = this.inline ? $('.dp-popup', this.context) : $('#dp-popup');
                
                if (this.showYearNavigation == false) {
                    $('.dp-nav-prev-year, .dp-nav-next-year', c.context).css('display', 'none');
                }
                if (this.displayClose) {
                    $pop.append(
                        $('<a href="#" id="dp-close">' + $.dpText.TEXT_CLOSE + '</a>')
                            .bind(
                                'click',
                                function()
                                {
                                    c._closeCalendar();
                                    return false;
                                }
                            )
                    );
                }
                c._renderCalendar();
 
                $(this.ele).trigger('dpDisplayed', $pop);
                
                if (!c.inline) {
                    if (this.verticalPosition == $.dpConst.POS_BOTTOM) {
                        $pop.css('top', eleOffset.top + $ele.height() - $pop.height() + c.verticalOffset);
                    }
                    if (this.horizontalPosition == $.dpConst.POS_RIGHT) {
                        $pop.css('left', eleOffset.left + $ele.width() - $pop.width() + c.horizontalOffset);
                    }
//                    $('.selectee', this.context).focus();
                    $(document).bind('mousedown.datepicker', this._checkMouse);
                }
                
            },
            setRenderCallback : function(a)
            {
                if (a == null) return;
                if (a && typeof(a) == 'function') {
                    a = [a];
                }
                this.renderCallback = this.renderCallback.concat(a);
            },
            cellRender : function ($td, thisDate, month, year) {
                var c = this.dpController;
                var d = new Date(thisDate.getTime());
                
                // add our click handlers to deal with it when the days are clicked...
                
                $td.bind(
                    'click',
                    function()
                    {
                        var $this = $(this);
                        if (!$this.is('.disabled')) {
                            c.setSelected(d, !$this.is('.selected') || !c.selectMultiple, false, true);
                            if (c.closeOnSelect) {
                                c._closeCalendar();
                            }
                            // TODO: Instead of this which doesn't work in IE anyway we should find the next focusable element in the document
                            // and pass the focus onto that. That would allow the user to continue on the form as expected...
                            if (!$.browser.msie)
                            {
                                $(c.ele).trigger('focus', [$.dpConst.DP_INTERNAL_FOCUS]);
                            }
                        }
                    }
                );
                
                if (c.isSelected(d)) {
                    $td.addClass('selected');
                    if (c.settings.selectWeek)
                    {
                        $td.parent().addClass('selectedWeek');
                    }
                } else  if (c.selectMultiple && c.numSelected == c.numSelectable) {
                    $td.addClass('unselectable');
                }
                
            },
            _applyRenderCallbacks : function()
            {
                var c = this;
                $('td', this.context).each(
                    function()
                    {
                        for (var i=0; i<c.renderCallback.length; i++) {
                            $td = $(this);
                            c.renderCallback[i].apply(this, [$td, Date.fromString($td.data('datePickerDate')), c.displayedMonth, c.displayedYear]);
                        }
                    }
                );
                return;
            },
            // ele is the clicked button - only proceed if it doesn't have the class disabled...
            // m and y are -1, 0 or 1 depending which direction we want to go in...
            _displayNewMonth : function(ele, m, y) 
            {
                if (!$(ele).is('.disabled')) {
                    this.setDisplayedMonth(this.displayedMonth + m, this.displayedYear + y, true);
                }
                ele.blur();
                return false;
            },
            _rerenderCalendar : function()
            {
                this._clearCalendar();
                this._renderCalendar();
            },
            _renderCalendar : function()
            {
                // set the title...
                $('h2', this.context).html((new Date(this.displayedYear, this.displayedMonth, 1)).asString($.dpText.HEADER_FORMAT));
                
                // render the calendar...
                $('.dp-calendar', this.context).renderCalendar(
                    $.extend(
                        {},
                        this.settings, 
                        {
                            month            : this.displayedMonth,
                            year            : this.displayedYear,
                            renderCallback    : this.cellRender,
                            dpController    : this,
                            hoverClass        : this.hoverClass
                        })
                );
                
                // update the status of the control buttons and disable dates before startDate or after endDate...
                // TODO: When should the year buttons be disabled? When you can't go forward a whole year from where you are or is that annoying?
                if (this.displayedYear == this.startDate.getFullYear() && this.displayedMonth == this.startDate.getMonth()) {
                    $('.dp-nav-prev-year', this.context).addClass('disabled');
                    $('.dp-nav-prev-month', this.context).addClass('disabled');
                    $('.dp-calendar td.other-month', this.context).each(
                        function()
                        {
                            var $this = $(this);
                            if (Number($this.text()) > 20) {
                                $this.addClass('disabled');
                            }
                        }
                    );
                    var d = this.startDate.getDate();
                    $('.dp-calendar td.current-month', this.context).each(
                        function()
                        {
                            var $this = $(this);
                            if (Number($this.text()) < d) {
                                $this.addClass('disabled');
                            }
                        }
                    );
                } else {
                    $('.dp-nav-prev-year', this.context).removeClass('disabled');
                    $('.dp-nav-prev-month', this.context).removeClass('disabled');
                    var d = this.startDate.getDate();
                    if (d > 20) {
                        // check if the startDate is last month as we might need to add some disabled classes...
                        var st = this.startDate.getTime();
                        var sd = new Date(st);
                        sd.addMonths(1);
                        if (this.displayedYear == sd.getFullYear() && this.displayedMonth == sd.getMonth()) {
                            $('.dp-calendar td.other-month', this.context).each(
                                function()
                                {
                                    var $this = $(this);
                                    if (Date.fromString($this.data('datePickerDate')).getTime() < st) {
                                        $this.addClass('disabled');
                                    }
                                }
                            );
                        }
                    }
                }
                if (this.displayedYear == this.endDate.getFullYear() && this.displayedMonth == this.endDate.getMonth()) {
                    $('.dp-nav-next-year', this.context).addClass('disabled');
                    $('.dp-nav-next-month', this.context).addClass('disabled');
                    $('.dp-calendar td.other-month', this.context).each(
                        function()
                        {
                            var $this = $(this);
                            if (Number($this.text()) < 14) {
                                $this.addClass('disabled');
                            }
                        }
                    );
                    var d = this.endDate.getDate();
                    $('.dp-calendar td.current-month', this.context).each(
                        function()
                        {
                            var $this = $(this);
                            if (Number($this.text()) > d) {
                                $this.addClass('disabled');
                            }
                        }
                    );
                } else {
                    $('.dp-nav-next-year', this.context).removeClass('disabled');
                    $('.dp-nav-next-month', this.context).removeClass('disabled');
                    var d = this.endDate.getDate();
                    if (d < 13) {
                        // check if the endDate is next month as we might need to add some disabled classes...
                        var ed = new Date(this.endDate.getTime());
                        ed.addMonths(-1);
                        if (this.displayedYear == ed.getFullYear() && this.displayedMonth == ed.getMonth()) {
                            $('.dp-calendar td.other-month', this.context).each(
                                function()
                                {
                                    var $this = $(this);
                                    if (Number($this.text()) > d) {
                                        $this.addClass('disabled');
                                    }
                                }
                            );
                        }
                    }
                }
                this._applyRenderCallbacks();
            },
            _closeCalendar : function(programatic, ele)
            {
                if (!ele || ele == this.ele)
                {
                    $(document).unbind('mousedown.datepicker');
                    $(document).unbind('keydown.datepicker');
                    this._clearCalendar();
                    $('#dp-popup a').unbind();
                    $('#dp-popup').empty().remove();
                    if (!programatic) {
                        $(this.ele).trigger('dpClosed', [this.getSelected()]);
                    }
                }
            },
            // empties the current dp-calendar div and makes sure that all events are unbound
            // and expandos removed to avoid memory leaks...
            _clearCalendar : function()
            {
                // TODO.
                $('.dp-calendar td', this.context).unbind();
                $('.dp-calendar', this.context).empty();
            }
        }
    );
    
    // static constants
    $.dpConst = {
        SHOW_HEADER_NONE    :    0,
        SHOW_HEADER_SHORT    :    1,
        SHOW_HEADER_LONG    :    2,
        POS_TOP                :    0,
        POS_BOTTOM            :    1,
        POS_LEFT            :    0,
        POS_RIGHT            :    1,
        DP_INTERNAL_FOCUS    :    'dpInternalFocusTrigger'
    };
    // localisable text
    $.dpText = {
        TEXT_PREV_YEAR        :    'Previous year',
        TEXT_PREV_MONTH        :    'Previous month',
        TEXT_NEXT_YEAR        :    'Next year',
        TEXT_NEXT_MONTH        :    'Next month',
        TEXT_CLOSE            :    'Close',
        TEXT_CHOOSE_DATE    :    'Choose date',
        HEADER_FORMAT        :    'mmmm yyyy'
    };
    // version
    $.dpVersion = '$Id: jquery.datePicker.js 70 2009-04-05 19:25:15Z kelvin.luck $';
 
    $.fn.datePicker.defaults = {
        month                : undefined,
        year                : undefined,
        showHeader            : $.dpConst.SHOW_HEADER_SHORT,
        startDate            : undefined,
        endDate                : undefined,
        inline                : false,
        renderCallback        : null,
        createButton        : true,
        showYearNavigation    : true,
        closeOnSelect        : true,
        displayClose        : false,
        selectMultiple        : false,
        numSelectable        : Number.MAX_VALUE,
        clickInput            : false,
        rememberViewedMonth    : true,
        selectWeek            : false,
        verticalPosition    : $.dpConst.POS_TOP,
        horizontalPosition    : $.dpConst.POS_LEFT,
        verticalOffset        : 0,
        horizontalOffset    : 0,
        hoverClass            : 'dp-hover'
    };
 
    function _getController(ele)
    {
        if (ele._dpId) return $.event._dpCache[ele._dpId];
        return false;
    };
    
    // make it so that no error is thrown if bgIframe plugin isn't included (allows you to use conditional
    // comments to only include bgIframe where it is needed in IE without breaking this plugin).
    if ($.fn.bgIframe == undefined) {
        $.fn.bgIframe = function() {return this; };
    };
 
 
    // clean-up
    $(window)
        .bind('unload', function() {
            var els = $.event._dpCache || [];
            for (var i in els) {
                $(els[i].ele)._dpDestroy();
            }
        });
        
    
})(jQuery);