This repository has been archived by the owner on Jul 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnacc.js
1562 lines (1321 loc) · 74.5 KB
/
nacc.js
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
/***************************************************************************/
/**
The NA Cleatime Calculator (NACC)
This is the second version of the NACC. It is designed to be a browser-based
cleantime calculator (meaning it relies solely on HTML, JavaScript and CSS).
NACC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NACC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this code. If not, see <http://www.gnu.org/licenses/>.
*/
/********************************************************************************************
######################################### MAIN CONTEXT ######################################
********************************************************************************************/
/**
\brief This is the main class function for the NACC.
\param inContainerElementID A DOM ID to the DOM element that will contain this instance. It will usually be an empty div element, but can be any block-level DOM element.
\param inStyle This is the style (leave blank/null for default gray. The "BT" style would be 'NA-BT', as that is the CSS name it has been given).
\param inLang A string, with the language selector (Example: 'en' -the default-, 'es' -Spanish-, etc.).
\param inTagLayout The tag layout (either 'linear' or 'tabular' -default is 'linear')
\param inShowSpecialTags If true, then the "specialty" (over 2 years) tags are displayed. Default is false.
\param inDirectoryRoot This is a path (relative to the execution path) to the main directory. Leave as '' or null for standard implementations.
\param inYear An initial calculation year (integer -entire year, like '1953'). If you want the instance to immediately appear with a calculation, then ALL 3 of these must be specified.
\param inMonth An initial calculation month (integer 1-12). If you want the instance to immediately appear with a calculation, then ALL 3 of these must be specified.
\param inDay An initial calculation day (integer 1-31). If you want the instance to immediately appear with a calculation, then ALL 3 of these must be specified.
*/
function NACC(inContainerElementID, inStyle, inLang, inTagLayout, inShowSpecialTags, inDirectoryRoot, inYear, inMonth, inDay) {
/********************************************************************************************
########################################## PROPERTIES #######################################
********************************************************************************************/
/// This contains any GET parameters.
var m_getParameters = null;
/// This contains any directory offset (used when in plugin situations).
var m_relative_directory_root = null;
/// This is the style selector.
var m_style_selector = null;
/// This is the language selector.
var m_lang_selector = null;
/// This is an array, with all the language-specific strings.
var m_lang = null;
/// This specifies the keytag layout.
var m_keytag_layout = null;
/// This specifies whether the specialty keytags are displayed.
var m_keytag_special = null;
/// This is the object that "owns" this instance.
var m_my_container = null;
/// This is the form that contains the popups.
var m_my_form = null;
/// This is the prompt above the popups.
var m_my_prompt = null;
/// This is the fieldset that contains the popups and the results.
var m_my_fieldset = null;
/// This is the fieldset legend that contains the popups.
var m_my_legend = null;
/// This is the fieldset legend internal div that contains the popups.
var m_my_legend_div = null;
/// This is a div that will contain the popups.
var m_popup_container = null;
/// This is the month popup.
var m_month_popup = null;
/// This is the day of the month popup.
var m_day_popup = null;
/// This is the year popup.
var m_year_popup = null;
/// This is the calculate button.
var m_calculate_button = null;
/// This is the calculate results div.
var m_calculation_results_div = null;
/// This is the calculate results display toggle button.
var m_calculation_results_display_toggle_button = null;
/// This is the calculate results special tags display checkbox.
var m_calculation_results_show_special_tags_checkbox = null;
/// This is the label for the calculate results special tags display checkbox.
var m_calculation_results_show_special_tags_checkbox_label = null;
/// This is the calculate results text div.
var m_calculation_results_text_div = null;
/// This is the calculate results keytags div.
var m_calculation_results_keytags_div = null;
/************************************/
/* LOCALIZATION */
/************************************/
this.m_lang = Array();
// Make sure that we have a valid container element.
if ( inContainerElementID && document.getElementById(inContainerElementID) ) {
/************************************/
/* ENGLISH */
/************************************/
/** We need to instantiate an object for each language. The key needs to be the language selector. */
this.m_lang['en'] = new Object();
/* The following are strings to be assigned to each language. */
/** This is the header, at the top. */
this.m_lang['en'].section_title = 'NA Cleantime Calculator';
/** This is the prompt over the popup menus. */
this.m_lang['en'].prompt = 'Please enter your Clean Date';
/** This is the text for the calculate button. */
this.m_lang['en'].calculate_button_text = 'Calculate';
/** This is the text for the change layout button. */
this.m_lang['en'].change_layout_button_text = 'Change Tag Layout';
/** This is the text for the show special tags checkbox. */
this.m_lang['en'].change_use_special_tags_label = 'Show Special Tags';
/** These are the months, spelled out. */
this.m_lang['en'].months = Array(
"ERROR",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
);
/** These are for the top (days) blurb. */
this.m_lang['en'].result_invalid = 'Please select a valid clean date!';
this.m_lang['en'].result_1_day = 'You have been clean for 1 day!';
this.m_lang['en'].result_days_format = 'You have been clean for %d days!';
/** These are for the second (months, years and days) blurb. */
this.m_lang['en'].result_months_format = 'This is %d months.';
this.m_lang['en'].result_months_and_1_day_format = 'This is %d months and 1 day.';
this.m_lang['en'].result_months_and_days_format = 'This is %d months and %d days.';
this.m_lang['en'].result_1_year = 'This is 1 year.';
this.m_lang['en'].result_1_year_and_1_day = 'This is 1 year and 1 day.';
this.m_lang['en'].result_1_year_and_1_month = 'This is 1 year and 1 month.';
this.m_lang['en'].result_1_year_1_month_and_1_day = 'This is 1 year, 1 month and 1 day.';
this.m_lang['en'].result_1_year_months_and_1_day_format = 'This is 1 year, %d months and 1 day.';
this.m_lang['en'].result_1_year_months_and_days_format = 'This is 1 year, %d months and %d days.';
this.m_lang['en'].result_1_year_days_format = 'This is 1 year and %d days.';
this.m_lang['en'].result_years_format = 'This is %d years.';
this.m_lang['en'].result_years_months_format = 'This is %d years and %d months.';
this.m_lang['en'].result_years_1_month_and_1_day_format = 'This is %d years, 1 month and 1 day.';
this.m_lang['en'].result_years_months_and_1_day_format = 'This is %d years, %d months and 1 day.';
this.m_lang['en'].result_years_and_1_month_format = 'This is %d years and 1 month.';
this.m_lang['en'].result_years_and_1_day_format = 'This is %d years and 1 day.';
this.m_lang['en'].result_years_and_days_format = 'This is %d years and %d days.';
this.m_lang['en'].result_years_1_month_and_days_format = 'This is %d years, 1 month and %d days.';
this.m_lang['en'].result_years_months_and_days_format = 'This is %d years, %d months and %d days.';
/************************************/
/* SPANISH */
/************************************/
this.m_lang['es'] = new Object();
/* The following are strings to be assigned to each language. */
/** This is the header, at the top. */
this.m_lang['es'].section_title = 'Calculadora de Tiempo Limpio NA';
/** This is the prompt over the popup menus. */
this.m_lang['es'].prompt = 'Por favor, entra tu fecha de inicio.';
/** This is the text for the calculate button. */
this.m_lang['es'].calculate_button_text = 'Calcular';
/** This is the text for the change layout button. */
this.m_lang['es'].change_layout_button_text = 'Cambiar los llaveros de posición.';
/** This is the text for the show special tags checkbox. */
this.m_lang['es'].change_use_special_tags_label = 'Mostrar Llaveros Especiales.';
/** These are the months, spelled out. */
this.m_lang['es'].months = Array(
"ERROR",
"Enero",
"Febrero",
"Marzo",
"Abril",
"Mayo",
"Junio",
"Julio",
"Agosto",
"Septiembre",
"Octubre",
"Noviembre",
"Diciembre"
);
this.m_lang['es'].result_invalid = '¡Por favor, entra una fecha de inicio válido!';
this.m_lang['es'].result_1_day = '¡Has estado limpio por 1 día!';
this.m_lang['es'].result_days_format = '¡Has estado limpio por %d días!';
/** These are for the second (months, years and days) blurb. */
this.m_lang['es'].result_months_format = 'Esto suma un total de %d meses.';
this.m_lang['es'].result_months_and_1_day_format = 'Esto suma un total de %d meses y un día.';
this.m_lang['es'].result_months_and_days_format = 'Esto suma un total de %d meses y %d días.';
this.m_lang['es'].result_1_year = 'Esto suma un total de 1 año.';
this.m_lang['es'].result_1_year_and_1_day = 'Esto suma un total de 1 año y 1 día.';
this.m_lang['es'].result_1_year_and_1_month = 'Esto suma un total de 1 año y 1 mes.';
this.m_lang['es'].result_1_year_1_month_and_1_day = 'Esto suma un total de 1 año, 1 mes y 1 día.';
this.m_lang['es'].result_1_year_months_and_1_day_format = 'Esto suma un total de 1 año, %d meses y 1 día.';
this.m_lang['es'].result_1_year_months_and_days_format = 'Esto suma un total de 1 año, %d meses y %d días.';
this.m_lang['es'].result_1_year_days_format = 'Esto suma un total de 1 año y %d días.';
this.m_lang['es'].result_years_format = 'Esto suma un total de %d años.';
this.m_lang['es'].result_years_months_format = 'Esto suma un total de %d años y %d meses.';
this.m_lang['es'].result_years_1_month_and_1_day_format = 'Esto suma un total de %d años, 1 mes y 1 día.';
this.m_lang['es'].result_years_months_and_1_day_format = 'Esto suma un total de %d años, %d meses y 1 día.';
this.m_lang['es'].result_years_and_1_month_format = 'Esto suma un total de %d años y 1 mes.';
this.m_lang['es'].result_years_and_1_day_format = 'Esto suma un total de %d años y 1 día.';
this.m_lang['es'].result_years_and_days_format = 'Esto suma un total de %d años y %d días.';
this.m_lang['es'].result_years_1_month_and_days_format = 'Esto suma un total de %d años, 1 mes y %d días.';
this.m_lang['es'].result_years_months_and_days_format = 'Esto suma un total de %d años, %d meses y %d días.';
/************************************/
/* SIMPLIFIED CHINESE */
/************************************/
this.m_lang['zh-Hans'] = new Object();
/* The following are strings to be assigned to each language. */
/** This is the header, at the top. */
this.m_lang['zh-Hans'].section_title = 'NA 清醒时间计算器';
/** This is the prompt over the popup menus. */
this.m_lang['zh-Hans'].prompt = '请输入您的清醒日期';
/** This is the text for the calculate button. */
this.m_lang['zh-Hans'].calculate_button_text = '计算';
/** This is the text for the change layout button. */
this.m_lang['zh-Hans'].change_layout_button_text = '更改钥匙扣设置';
/** This is the text for the show special tags checkbox. */
this.m_lang['zh-Hans'].change_use_special_tags_label = '显示特殊钥匙扣';
/** These are the months, spelled out. */
this.m_lang['zh-Hans'].months = Array(
"错误",
"1月",
"2月",
"3月",
"4月",
"5月",
"6月",
"7月",
"8月",
"9月",
"10月",
"11月",
"12月"
);
this.m_lang['zh-Hans'].result_invalid = '请选择一个有效的清醒日期';
this.m_lang['zh-Hans'].result_1_day = '您已经清醒一天了!';
this.m_lang['zh-Hans'].result_days_format = '您已经清醒%d天了! ';
/** These are for the second (months, years and days) blurb. */
this.m_lang['zh-Hans'].result_months_format = '这是%d个月了';
this.m_lang['zh-Hans'].result_months_and_1_day_format = '这是%d个月零一天了.';
this.m_lang['zh-Hans'].result_months_and_days_format = '这是%d个月%d天了.';
this.m_lang['zh-Hans'].result_1_year = '这是一年了.';
this.m_lang['zh-Hans'].result_1_year_and_1_day = '这是一年零一天了.';
this.m_lang['zh-Hans'].result_1_year_and_1_month = '这是一年一个月了. ';
this.m_lang['zh-Hans'].result_1_year_1_month_and_1_day = '这是一年一个月零一天了. ';
this.m_lang['zh-Hans'].result_1_year_months_and_1_day_format = '这是一年,%d个月零一天了.';
this.m_lang['zh-Hans'].result_1_year_days_format = '这是一年,%d天了. ';
this.m_lang['zh-Hans'].result_years_format = '这是%d年了. ';
this.m_lang['zh-Hans'].result_years_months_format = '这是%d年%d月了. ';
this.m_lang['zh-Hans'].result_years_1_month_and_1_day_format = '这是%d年,一个月零一天了.';
this.m_lang['zh-Hans'].result_years_months_and_1_day_format = '这是%d年,%d月零一天了.';
this.m_lang['zh-Hans'].result_years_and_1_month_format = '这是%d年一个月了. ';
this.m_lang['zh-Hans'].result_years_and_1_day_format = '这是%d年零一天了. ';
this.m_lang['zh-Hans'].result_years_and_days_format = '这是%d年%d天了.';
this.m_lang['zh-Hans'].result_years_1_month_and_days_format = '这是%d年,一个月%d天了.';
this.m_lang['zh-Hans'].result_years_months_and_days_format = '这是%d个年,%d个月,%d天了.';
/************************************/
/* TRADITIONAL CHINESE */
/************************************/
this.m_lang['zh-Hant'] = new Object();
/* The following are strings to be assigned to each language. */
/** This is the header, at the top. */
this.m_lang['zh-Hant'].section_title = 'NA 清醒時間計算器';
/** This is the prompt over the popup menus. */
this.m_lang['zh-Hant'].prompt = '請輸入您的清醒日期';
/** This is the text for the calculate button. */
this.m_lang['zh-Hant'].calculate_button_text = '計算';
/** This is the text for the change layout button. */
this.m_lang['zh-Hant'].change_layout_button_text = '更改鑰匙扣設置';
/** This is the text for the show special tags checkbox. */
this.m_lang['zh-Hant'].change_use_special_tags_label = '顯示特殊鑰匙扣';
/** These are the months, spelled out. */
this.m_lang['zh-Hant'].months = Array(
"錯誤",
"1月",
"2月",
"3月",
"4月",
"5月",
"6月",
"7月",
"8月",
"9月",
"10月",
"11月",
"12月"
);
this.m_lang['zh-Hant'].result_invalid = '請選擇一個有效的清醒日期';
this.m_lang['zh-Hant'].result_1_day = '您已經清醒一天了!';
this.m_lang['zh-Hant'].result_days_format = '您已经清醒%d天了! ';
/** These are for the second (months, years and days) blurb. */
this.m_lang['zh-Hant'].result_months_format = '這是%d個月了';
this.m_lang['zh-Hant'].result_months_and_1_day_format = '這是%d個月零一天了.';
this.m_lang['zh-Hant'].result_months_and_days_format = '這是%d個月%d天了.';
this.m_lang['zh-Hant'].result_1_year = '這是一年了.';
this.m_lang['zh-Hant'].result_1_year_and_1_day = '這是一年零一天了.';
this.m_lang['zh-Hant'].result_1_year_and_1_month = '這是一年一個月了. ';
this.m_lang['zh-Hant'].result_1_year_1_month_and_1_day = '這是一年一個月零一天了. ';
this.m_lang['zh-Hant'].result_1_year_months_and_1_day_format = '這是一年,%d個月零一天了.';
this.m_lang['zh-Hant'].result_1_year_days_format = '這是一年,%d天了. ';
this.m_lang['zh-Hant'].result_years_format = '這是%d年了. ';
this.m_lang['zh-Hant'].result_years_months_format = '這是%d年%d月了. ';
this.m_lang['zh-Hant'].result_years_1_month_and_1_day_format = '這是%d年,一個月零一天了.';
this.m_lang['zh-Hant'].result_years_months_and_1_day_format = '這是%d年,%d月零一天了.';
this.m_lang['zh-Hant'].result_years_and_1_month_format = '這是%d年一個月了. ';
this.m_lang['zh-Hant'].result_years_and_1_day_format = '這是%d年零一天了. ';
this.m_lang['zh-Hant'].result_years_and_days_format = '這是%d年%d天了.';
this.m_lang['zh-Hant'].result_years_1_month_and_days_format = '這是%d年,一個月%d天了.';
this.m_lang['zh-Hant'].result_years_months_and_days_format = '這是%d個年,%d個月,%d天了.';
/************************************/
/* ITALIAN */
/************************************/
this.m_lang['it'] = new Object();
/** This is the header, at the top. */
this.m_lang['it'].section_title = 'NA Tempo di Pulizia';
/** This is the prompt over the popup menus. */
this.m_lang['it'].prompt = 'Inserisci la tua data di pulizia';
/** This is the text for the calculate button. */
this.m_lang['it'].calculate_button_text = 'Calcola';
/** This is the text for the change layout button. */
this.m_lang['it'].change_layout_button_text = 'Cambia presentazione dei portachiavi';
/** This is the text for the show special tags checkbox. */
this.m_lang['it'].change_use_special_tags_label = 'Mostra Tag Speciali';
/** These are the months, spelled out. */
this.m_lang['it'].months = Array(
"ERRORE",
"gennaio",
"febbraio",
"marzo",
"aprile",
"maggio",
"giugno",
"luglio",
"agosto",
"settembre",
"ottobre",
"novembre",
"dicembre"
);
/** These are for the top (days) blurb. */
this.m_lang['it'].result_invalid = 'Si prega di selezionare una data pulita valida!';
this.m_lang['it'].result_1_day = 'Sei stato pulito per 1 giorno!';
this.m_lang['it'].result_days_format = 'Ei stato pulito per %d giorni!';
/** These are for the second (months, years and days) blurb. */
this.m_lang['it'].result_months_format = 'Questo è di %d mesi.';
this.m_lang['it'].result_months_and_1_day_format = 'Questo è di %d mesi e 1 giorno.';
this.m_lang['it'].result_months_and_days_format = 'Questo è di %d mesi e %d giorni.';
this.m_lang['it'].result_1_year = 'Questo è di 1 anno.';
this.m_lang['it'].result_1_year_and_1_day = 'Questo è di 1 anno e 1 giorno.';
this.m_lang['it'].result_1_year_and_1_month = 'Questo è di 1 anno e 1 mese.';
this.m_lang['it'].result_1_year_1_month_and_1_day = 'Questo è di 1 anno, 1 mese e 1 giorno.';
this.m_lang['it'].result_1_year_months_and_1_day_format = 'Questo è di 1 anno, %d mesi e 1 giorno.';
this.m_lang['it'].result_1_year_months_and_days_format = 'Questo è di 1 anno, %d mesi e %d giorni.';
this.m_lang['it'].result_1_year_days_format = 'Questo è di 1 year e %d giorni.';
this.m_lang['it'].result_years_format = 'Questo è di %d anni.';
this.m_lang['it'].result_years_months_format = 'Questo è di %d anni e %d mesi.';
this.m_lang['it'].result_years_1_month_and_1_day_format = 'Questo è di %d anni, 1 mese e 1 giorno.';
this.m_lang['it'].result_years_months_and_1_day_format = 'Questo è di %d anni, %d mesi e 1 giorno.';
this.m_lang['it'].result_years_and_1_month_format = 'Questo è di %d anni e 1 mese.';
this.m_lang['it'].result_years_and_1_day_format = 'Questo è di %d anni e 1 giorno.';
this.m_lang['it'].result_years_and_days_format = 'Questo è di %d anni e %d giorni.';
this.m_lang['it'].result_years_1_month_and_days_format = 'Questo è di %d anni, 1 mese e %d giorni.';
this.m_lang['it'].result_years_months_and_days_format = 'Questo è di %d anni, %d mesi e %d giorni.';
/************************************/
/* MAIN CODE */
/************************************/
// First, see if we have any GET parameters supplied.
// GET parameters trump arguments passed in, and arguments trump defaults.
this.m_getParameters = this.getParameters();
// See if a root directory was specified.
if ( this.m_getParameters['NACC-dir-root'] ) {
this.m_relative_directory_root = this.m_getParameters['NACC-dir-root'] + (!this.m_getParameters['NACC-dir-root'].toString().match(/\/$/) ? '/' : '');
} else {
if ( inDirectoryRoot ) {
this.m_relative_directory_root = inDirectoryRoot + (!inDirectoryRoot.toString().match(/\/$/) ? '/' : '');
} else {
this.m_relative_directory_root = '';
};
};
// See if a style was specified.
if ( this.m_getParameters['NACC-style'] ) {
this.m_style_selector = this.m_getParameters['NACC-style'];
} else {
if ( inStyle ) {
this.m_style_selector = inStyle;
} else {
this.m_style_selector = null;
};
};
// See if a language was specified.
if ( this.m_getParameters['NACC-lang'] ) {
this.m_lang_selector = this.m_getParameters['NACC-lang'];
} else {
if ( inLang ) {
this.m_lang_selector = inLang;
} else {
this.m_lang_selector = 'en';
};
};
// See if an initial tag layout was specified.
if ( this.m_getParameters['NACC-tag-layout'] ) {
this.m_keytag_layout = this.m_getParameters['NACC-tag-layout'];
} else {
if ( inTagLayout ) {
this.m_keytag_layout = inTagLayout;
} else {
this.m_keytag_layout = 'linear';
};
};
// See if we want to initially display the "specialty" tags.
if ( this.m_getParameters['NACC-special-tags'] ) {
this.m_keytag_special = true;
} else {
this.m_keytag_special = inShowSpecialTags ? true : false;
};
// The first thing that we do, is reference the container element.
this.m_my_container = document.getElementById(inContainerElementID);
// Link this NACC instance with the container element.
this.m_my_container.nacc_instance = this;
// Make sure the container is tagged with the NACC-Instance class.
if ( this.m_my_container.className ) {
this.m_my_container.className += ' NACC-Instance'; // Appending to any existing class.
} else {
this.m_my_container.className = 'NACC-Instance'; // From scratch.
};
// If a style was specified, we add that, as well.
if ( this.m_style_selector ) {
this.m_my_container.className += ' ' + this.m_style_selector;
};
// Clear the decks for action, matey!
this.m_my_container.innerHTML = '';
// This is where we actually create everything.
this.createHeader();
this.createForm();
// This is a function that makes sure that the days of the month popup menu is valid.
this.evaluateMonthDays();
// See if a date was supplied. If so, we immediately calculate.
var year = parseInt(this.m_getParameters['NACC-year']);
var month = parseInt(this.m_getParameters['NACC-month']);
var day = parseInt(this.m_getParameters['NACC-day']);
// Look for any passed-in parameters.
if ( !year ) {
year = parseInt(inYear);
};
if ( !month ) {
month = parseInt(inMonth);
};
if ( !day ) {
year = parseInt(inDay);
};
// We have to have all 3 to do an immediate calculation.
if ( year && month && day ) {
// Set up the popups to reflect the given date.
this.m_month_popup.selectedIndex = month - 1;
for ( var i = 0; i < this.m_year_popup.options.length; i++ ) {
if ( parseInt(this.m_year_popup.options[i].value) == parseInt(year) ) {
this.m_year_popup.selectedIndex = i;
break;
};
};
this.m_day_popup.selectedIndex = day - 1;
// Make sure we're kosher.
this.evaluateMonthDays();
// Just run a calculation, as if the button were hit. The form will be evaluated.
this.calculateCleantime(this.m_calculate_button);
};
} else {
// Let folks know they borked it.
alert('NACC ERROR: INVALID CONTAINER ELEMENT ID');
};
};
/********************************************************************************************
################################### INTERNAL UTILITY METHODS ################################
********************************************************************************************/
/**
\brief This allows us to compare today to a given date.
Cribbed from here: https://gist.github.com/clecuona/2945438
\param inFromDate The date that will be the one we compare against.
This date should always be earlier than the current date.
\returns an object, with the total number of days, and the span, in years, months and days.
*/
NACC.prototype.dateSpan = function(inFromDate) {
var difference = new Object;
difference.totalDays = 0;
difference.years = 0;
difference.months = 0;
difference.days = 0;
var dt2 = new Date();
var dt1 = inFromDate;
if ( dt2 > dt1 ) {
difference.totalDays = parseInt((dt2.getTime() - dt1.getTime()) / 86400000);
var year1 = dt1.getFullYear();
var year2 = dt2.getFullYear();
var month1 = dt1.getMonth();
var month2 = dt2.getMonth();
var day1 = dt1.getDate();
var day2 = dt2.getDate();
difference.years = year2 - year1;
difference.months = month2 - month1;
difference.days = day2 - day1;
if ( difference.days < 0 ) {
// Use temporary date to get the number of days remaining in the month
var numDays = new Date(year1, month1 + 1, 1, 0, 0, -1).getDate();
difference.months -= 1;
difference.days += numDays;
};
if ( difference.months < 0 ) {
difference.months += 12;
difference.years -= 1;
};
};
return difference;
};
/***********************************************************************/
/**
\brief This simply generates a random numerical ID.
\param inPrefix If this is supplied, it is a prefix that is prepended.
\returns a random ID as a string, with the prefix (or 'NACC') prepended.
*/
NACC.prototype.generateID = function(inPrefix) {
if ( !inPrefix ) { // We always have some kind of prefix.
inPrefix = 'NACC';
};
return inPrefix + '-' + Math.random().toString(36).substr(2, 10);
};
/***********************************************************************/
/**
\brief This checks the month and year, and disables any month days
that are not available for the given month. It will also
move the selection, if a selected day is too far down.
*/
NACC.prototype.evaluateMonthDays = function() {
var dtmp1 = new Date(this.m_year_popup.value, this.m_month_popup.value, 1, 0, 0, -1);
var numDays = parseInt(dtmp1.getDate());
this.m_day_popup.selectedIndex = Math.min(this.m_day_popup.selectedIndex + 1, numDays) - 1;
for ( var i = 0; i < this.m_day_popup.options.length; i++ ) {
this.m_day_popup.options[i].disabled = (i >= numDays);
};
};
/***********************************************************************/
/**
\brief This displays the results of the calculation.
*/
NACC.prototype.displayCalculationResults = function(inCalculationResults) {
var days_blurb = '';
if ( 1 == inCalculationResults.totalDays ) {
days_blurb = this.m_lang[this.m_lang_selector].result_1_day;
} else {
days_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_days_format, inCalculationResults.totalDays);
};
var main_blurb = '';
// We select the appropriate format to display the result, based on how many day, months and years are in the result.
// We count days until 90, then months and years.
if ( 0 < inCalculationResults.totalDays ) {
if ( 90 < inCalculationResults.totalDays ) { // Have to have more than 90 days to start counting months, years and days.
if ( 0 < inCalculationResults.years ) {
if ( (1 == inCalculationResults.years) && (0 == inCalculationResults.months) && (0 == inCalculationResults.days) ) {
main_blurb = this.m_lang[this.m_lang_selector].result_1_year;
} else if ( (1 == inCalculationResults.years) && (1 == inCalculationResults.months) && (0 == inCalculationResults.days) ) {
main_blurb = this.m_lang[this.m_lang_selector].result_1_year_and_1_month;
} else if ( (1 == inCalculationResults.years) && (1 == inCalculationResults.months) && (1 == inCalculationResults.days) ) {
main_blurb = this.m_lang[this.m_lang_selector].result_1_year_1_month_and_1_day;
} else if ( (1 == inCalculationResults.years) && (0 == inCalculationResults.months) && (1 == inCalculationResults.days) ) {
main_blurb = this.m_lang[this.m_lang_selector].result_1_year_and_1_day;
} else if ( (1 == inCalculationResults.years) && (0 == inCalculationResults.months) && (1 < inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_1_year_days_format, inCalculationResults.days);
} else if ( (1 == inCalculationResults.years) && (1 < inCalculationResults.months) && (1 < inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_1_year_months_and_days_format, inCalculationResults.months, inCalculationResults.days);
} else if ( (0 == inCalculationResults.months) && (0 == inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_years_format, inCalculationResults.years);
} else if ( (1 == inCalculationResults.months) && (0 == inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_years_and_1_month_format, inCalculationResults.years);
} else if ( (0 == inCalculationResults.months) && (1 == inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_years_and_1_day_format, inCalculationResults.years);
} else if ( 1 == inCalculationResults.months ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_years_1_month_and_days_format, inCalculationResults.years, inCalculationResults.days);
} else if ( 1 == inCalculationResults.days ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_years_months_and_1_day_format, inCalculationResults.years, inCalculationResults.months);
} else if ( (0 == inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_years_months_format, inCalculationResults.years, inCalculationResults.months);
} else if ( (0 == inCalculationResults.months) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_years_and_days_format, inCalculationResults.years, inCalculationResults.days);
} else {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_years_months_and_days_format, inCalculationResults.years, inCalculationResults.months, inCalculationResults.days);
};
} else { // If we have less than a year, we have fewer choices.
if ( (1 == inCalculationResults.months) && (1 == inCalculationResults.days) ) {
main_blurb = this.m_lang[this.m_lang_selector].result_1_month_and_1_day;
} else if ( (1 == inCalculationResults.months) && (1 < inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_1_month_days_format, inCalculationResults.days);
} else if ( (1 < inCalculationResults.months) && (1 < inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_months_and_days_format, inCalculationResults.months, inCalculationResults.days);
} else if ( (1 < inCalculationResults.months) && (1 == inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_months_and_1_day_format, inCalculationResults.months);
} else if ( (1 < inCalculationResults.months) && (0 == inCalculationResults.days) ) {
main_blurb = this.sprintf(this.m_lang[this.m_lang_selector].result_months_format, inCalculationResults.months);
};
};
};
} else {
days_blurb = this.m_lang[this.m_lang_selector].result_invalid;
};
var months = (inCalculationResults.years * 12) + inCalculationResults.months;
this.createResultsDiv(inCalculationResults.totalDays, months, days_blurb, main_blurb);
};
/********************************************************************************************
####################################### CALLBACK METHODS ####################################
********************************************************************************************/
/**
\brief This is called when the month or year popup is changed.
The day popup is adjusted to reflect the available days.
\param inObject This is the popup object. We use it to get our main instance.
*/
NACC.prototype.monthOrYearPopupChanged = function(inObject) {
inObject.owner.evaluateMonthDays();
};
/***********************************************************************/
/**
\brief This is called when the Calculate button is hit.
\param inObject This is the button object. We use it to get our main instance.
*/
NACC.prototype.calculateCleantime = function(inObject) {
var owner = inObject.owner;
var year = parseInt(owner.m_year_popup.value);
var month = parseInt(owner.m_month_popup.value) - 1;
var day = parseInt(owner.m_day_popup.value);
// If this was triggered by the rearrange layout button, we toggle the layout.
if ( inObject == owner.m_calculation_results_display_toggle_button ) {
owner.m_keytag_layout = (owner.m_keytag_layout == 'linear') ? 'tabular' : 'linear';
};
// If it was triggered by the checkbox, then we togle the special tags state.
if ( inObject == owner.m_calculation_results_show_special_tags_checkbox ) {
owner.m_keytag_special = !owner.m_keytag_special;
};
owner.calculate(year, month, day);
};
/***********************************************************************/
/**
\brief This actually performs the calculation. Called when the
Calculate button is hit.
\param inYear This is the year for the date.
\param inMonth This is the year for the date (0-based).
\param inDay This is the year for the date.
*/
NACC.prototype.calculate = function(inYear, inMonth, inDay) {
this.displayCalculationResults(this.dateSpan(new Date(inYear, inMonth, inDay, 0, 0, 0, 0)));
};
/********************************************************************************************
################################### DOM OBJECT INSTANTIATION ################################
********************************************************************************************/
/**
\brief This creates a DOM object, and returns it. If a DOM object
is passed in as a container, then the created object is added
to that container as a child.
\param inObjectName A string. The type of object (i.e. 'div', 'img', etc.)
\param inClass A string. One or more classnames for the object. If left nil
or blank, then no class is applied.
\param inContainer A DOM element reference. If non-nil, the parent for the new object.
\returns a new DOM object.
*/
NACC.prototype.createDOMObject = function(inObjectName, inClass, inContainer) {
var newObject = document.createElement(inObjectName);
// Make sure we got something, first.
if ( null != newObject ) {
// See if we were given a CSS class. This may have whitespace.
var objectID = inClass ? inClass : '';
if ( objectID ) {
newObject.className = objectID;
};
// Make sure we don't have whitespace in our ID (not allowed).
objectID = objectID.replace(/\s+?/, '-');
// If we are contained, then our ID derives from the container's ID.
if ( (null != inContainer) && inContainer.id ) {
objectID = inContainer.id + '-' + objectID;
}
newObject.id = this.generateID(objectID);
// See if we were given a container. If so, we append into that.
if ( null != inContainer ) {
inContainer.appendChild(newObject);
};
};
return newObject;
};
/***********************************************************************/
/**
\brief This creates the a single select option, and appends it into the given select.
\param inSelectObject This is the select element that will contain the option.
\param inDisplayString This is the string to be displayed.
\param inValue This is the value for the option.
\param inDisabled if true, then the option is disabled.
\returns the option object (which is automatically added to the select).
*/
NACC.prototype.createOptionObject = function(inSelectObject, inDisplayString, inValue, inDisabled) {
var newObject = null;
if ( inSelectObject && inDisplayString ) { // We can do without a value, but need a select and a display string.
newObject = this.createDOMObject('option', 'NACC-Option', inSelectObject);
if ( newObject ) {
newObject.value = inValue;
newObject.innerHTML = inDisplayString;
if ( inDisabled ) {
newObject.enabled = false;
};
};
};
return newObject;
};
/***********************************************************************/
/**
\brief This creates and returns one keytag object, as an img.
\brief inTag The name of the tag to be created.
\param isClosed if true, then the top of the ring will be closed.
\returns an img object.
*/
NACC.prototype.createOneKeytag = function(inTag, isClosed) {
var tagSrc = this.m_relative_directory_root + 'images/' + this.m_lang_selector + '/' + inTag + '.png';
return this.createKeytag(tagSrc, isClosed);
};
/***********************************************************************/
/**
\brief This creates and returns one keytag object, as an img.
\param inSrc The path to the source image.
\param isClosed if true, then the top of the ring will be closed.
\returns an img object.
*/
NACC.prototype.createKeytag = function(inSrc, isClosed) {
// We use CSS to create the closure at the top.
var className = 'NACC-Keytag' + ((isClosed || (this.m_keytag_layout != 'linear')) ? ' NACC-Keytag-Ringtop' : '');
var imgObject = this.createDOMObject('img', className, this.m_calculation_results_keytags_div);
if ( null != imgObject ) {
imgObject.src = inSrc;
};
return imgObject;
};
/***********************************************************************/
/**
\brief This creates and returns one white keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createWhiteKeytag = function(inFace) {
// White keytag will always be closed.
var ret = this.createOneKeytag('01' + (inFace ? '_Front' : ''), true);
if ( null != ret ) {
ret.className += ' NACC-White-Tag';
};
return ret;
};
/***********************************************************************/
/**
\brief This creates and returns one orange keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createOrangeKeytag = function(inFace) {
return this.createOneKeytag('02' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one green keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createGreenKeytag = function(inFace) {
return this.createOneKeytag('03' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one red keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createRedKeytag = function(inFace) {
return this.createOneKeytag('04' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one blue keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createBlueKeytag = function(inFace) {
return this.createOneKeytag('05' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one yellow keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createYellowKeytag = function(inFace) {
return this.createOneKeytag('06' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one year keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createYearKeytag = function(inFace) {
return this.createOneKeytag('07' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one gray keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createGrayKeytag = function(inFace) {
return this.createOneKeytag('08' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one black keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createBlackKeytag = function(inFace) {
return this.createOneKeytag('09' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one granite keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createDecadeKeytag = function(inFace) {
return this.createOneKeytag('10' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one decades keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.createDecadesKeytag = function(inFace) {
return this.createOneKeytag('11' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one 25-year keytag object, as an img.
\param inFace If this will be the logo side, this should be true.
\returns an img object.
*/
NACC.prototype.create25YearKeytag = function(inFace) {
return this.createOneKeytag('12' + (inFace ? '_Front' : ''), !inFace);
};
/***********************************************************************/
/**
\brief This creates and returns one 10,000 day keytag object, as an img.
\param inFace If this will be the logo side, this should be true.