File size: 179,752 Bytes
5dfece0
 
 
5dc17bf
 
 
 
 
5dfece0
 
 
5dc17bf
 
 
8b139d2
f3080cd
5dfece0
04212b0
39d6d32
 
 
5dc17bf
 
 
 
 
5dfece0
60ad16f
d41b73b
 
60ad16f
5dc17bf
 
60ad16f
5dfece0
117c540
5dc17bf
 
 
 
 
 
5dfece0
1f5bfdb
 
 
 
117c540
 
 
 
 
 
5dfece0
 
117c540
 
8b139d2
 
 
 
 
5dc17bf
5dfece0
 
117c540
5dc17bf
04212b0
 
 
dfcd1e9
04212b0
 
5dc17bf
 
 
dfcd1e9
04212b0
117c540
85c77db
117c540
85c77db
 
 
 
 
 
 
 
5dfece0
85c77db
 
 
8b139d2
 
 
 
 
 
 
2fa7407
ad49718
5dc17bf
 
 
 
 
 
d55f5ff
5dfece0
b2efd1c
5dfece0
 
 
5dc17bf
5dfece0
 
 
b2efd1c
5dfece0
04212b0
5dfece0
 
2fa7407
 
 
 
c788628
 
 
2fa7407
 
117c540
 
ad49718
1530447
ad49718
 
2fa7407
 
 
 
 
 
 
 
 
5dfece0
 
 
f3080cd
 
 
5dfece0
117c540
 
c788628
5dfece0
 
 
5dc17bf
 
04212b0
 
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
 
c788628
 
5dfece0
c788628
5dc17bf
 
 
 
 
 
 
5dfece0
 
 
117c540
 
 
04212b0
5dc17bf
 
 
 
 
 
 
 
 
6c04945
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
64b6ec1
5dc17bf
d55f5ff
5dc17bf
04212b0
5dc17bf
 
5dfece0
5dc17bf
 
 
 
 
 
 
6c04945
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
5dfece0
04212b0
5dfece0
 
 
8b139d2
5dfece0
 
5dc17bf
 
 
 
 
 
 
 
 
 
5dfece0
 
8b139d2
5dfece0
117c540
5927cf9
 
 
 
 
 
 
 
 
 
 
 
d41b73b
5927cf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d41b73b
5927cf9
d41b73b
af60ec7
5927cf9
 
 
 
 
 
 
 
 
 
 
 
2cf3371
5927cf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2cf3371
5dfece0
04212b0
5dc17bf
 
 
 
5927cf9
5dc17bf
 
 
2fa7407
 
5dc17bf
 
 
 
2fa7407
5dc17bf
 
 
 
 
2fa7407
c788628
 
5927cf9
2fa7407
 
 
 
c788628
2fa7407
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117c540
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2fa7407
 
 
 
 
 
 
 
 
 
5dfece0
 
d41b73b
5dfece0
c546719
04212b0
117c540
5927cf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93840d1
117c540
 
 
 
 
 
 
d41b73b
c788628
 
 
 
 
 
 
 
 
d41b73b
c788628
 
 
d41b73b
 
 
c788628
d41b73b
 
 
 
 
 
 
 
c788628
 
d41b73b
 
 
 
 
 
 
 
 
c788628
d41b73b
 
5dc17bf
 
d41b73b
 
 
 
 
 
5dc17bf
 
 
 
 
d41b73b
5dc17bf
 
 
 
 
 
6c04945
5dc17bf
 
 
 
 
 
 
 
 
 
 
c546719
5dc17bf
 
 
 
 
 
 
 
b66f47c
 
c546719
 
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
117c540
 
 
 
 
 
 
 
 
 
c546719
5dc17bf
b66f47c
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
b66f47c
 
5dc17bf
b29738d
b66f47c
5dc17bf
b66f47c
 
5dc17bf
 
b29738d
 
 
 
5dc17bf
 
b29738d
 
5dc17bf
b29738d
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b66f47c
5dc17bf
9c70185
 
 
 
 
b66f47c
b29738d
5dc17bf
117c540
 
 
 
 
 
 
 
 
 
 
5927cf9
 
5dc17bf
9c70185
5927cf9
 
 
 
 
 
 
 
 
 
 
 
 
9c70185
5927cf9
 
 
 
 
 
 
 
 
9c70185
5927cf9
 
5dc17bf
5927cf9
5dc17bf
 
 
 
 
 
 
8b139d2
 
5dc17bf
 
8b139d2
 
 
 
5dc17bf
8b139d2
 
 
 
 
5dc17bf
 
2fa7407
 
 
 
 
 
 
 
 
 
 
64b6ec1
2fa7407
64b6ec1
2fa7407
 
d55f5ff
5970288
d55f5ff
 
 
2fa7407
 
d55f5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
b29738d
d55f5ff
b29738d
 
d55f5ff
2fa7407
d55f5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
5970288
d55f5ff
 
 
 
 
 
5970288
d55f5ff
 
 
5970288
d55f5ff
 
5970288
d55f5ff
 
 
 
 
 
5970288
d55f5ff
5970288
d55f5ff
 
 
 
 
 
 
 
 
 
 
c788628
2e435a7
 
 
 
 
d55f5ff
 
 
 
5970288
d55f5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
5970288
 
c546719
 
d55f5ff
2fa7407
 
 
 
c546719
2fa7407
fa71b37
 
 
 
 
5dc17bf
 
2fa7407
64b6ec1
7867861
d55f5ff
 
b7c22f1
d55f5ff
 
b2efd1c
d55f5ff
 
7867861
64b6ec1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d55f5ff
 
 
 
 
 
 
5dc17bf
 
 
07cdd91
04212b0
 
 
5dc17bf
5927cf9
 
 
5dfece0
5927cf9
 
 
 
5dfece0
5927cf9
8b139d2
 
 
 
 
 
04212b0
8b139d2
 
 
 
 
 
 
 
 
 
 
04212b0
 
 
5dfece0
 
 
 
 
 
 
5dc17bf
 
1179f4b
 
 
5dfece0
c546719
04212b0
 
5dc17bf
5dfece0
 
 
117c540
 
 
5dfece0
 
 
 
 
117c540
5dfece0
 
 
 
 
117c540
 
 
 
 
 
 
 
 
5dfece0
117c540
 
5dfece0
 
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
ad49718
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad49718
117c540
 
 
 
ad49718
117c540
 
ad49718
117c540
 
 
 
ad49718
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0bc3e96
 
ad49718
 
 
24da474
 
117c540
24da474
 
ad49718
 
 
 
04212b0
 
 
c788628
 
 
 
 
 
5dfece0
 
 
 
 
c788628
5dfece0
5dc17bf
 
 
04212b0
 
 
5dfece0
 
 
5dc17bf
5dfece0
 
5dc17bf
 
 
04212b0
 
5dc17bf
04c7825
5dfece0
 
 
 
 
 
 
 
 
 
 
af9ad05
04c7825
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
 
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad49718
5dc17bf
 
 
 
ad49718
5dc17bf
 
 
 
ad49718
 
 
 
 
24da474
c788628
 
24da474
 
 
 
 
 
 
e7688d0
c788628
 
e7688d0
 
 
 
 
 
 
 
 
 
 
24da474
 
 
 
 
 
 
 
 
 
5dc17bf
af9ad05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
 
5dfece0
 
5927cf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
 
 
 
5dfece0
5927cf9
5dfece0
5927cf9
5dfece0
04212b0
5dfece0
04212b0
 
 
5dfece0
04212b0
 
 
5dfece0
5927cf9
 
 
 
 
5dc17bf
5927cf9
 
 
 
 
 
 
5dc17bf
 
5dfece0
04212b0
 
 
5dfece0
04212b0
5dfece0
 
 
04212b0
 
5dfece0
 
 
 
04212b0
 
24da474
5927cf9
24da474
5dc17bf
24da474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
24da474
 
5dc17bf
117c540
5dfece0
b2efd1c
b7c22f1
5dfece0
 
 
 
 
 
 
 
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c788628
117c540
 
 
5dfece0
117c540
 
 
 
 
 
5dfece0
117c540
 
 
 
 
c788628
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
117c540
 
2743ee5
117c540
 
 
 
 
 
 
 
 
 
 
 
 
c788628
117c540
 
 
af9ad05
117c540
 
 
24da474
 
 
117c540
24da474
c546719
24da474
 
04212b0
24da474
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2743ee5
c9d039a
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24da474
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24da474
117c540
 
 
 
24da474
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24da474
04212b0
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
 
117c540
 
ad49718
5dc17bf
 
8b139d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
 
 
 
 
 
 
 
 
5dc17bf
04212b0
5dc17bf
 
 
ad49718
 
 
 
 
 
85c77db
 
9f13c6a
85c77db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4936a9
85c77db
c4936a9
85c77db
 
 
64b6ec1
 
 
 
 
 
 
 
 
 
85c77db
 
 
 
 
 
 
117c540
64b6ec1
117c540
85c77db
 
117c540
c4936a9
85c77db
c4936a9
85c77db
6c04945
85c77db
 
 
 
 
 
 
 
 
 
 
 
c4936a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85c77db
c4936a9
85c77db
 
c4936a9
 
85c77db
 
 
 
 
c4936a9
9f13c6a
 
 
 
 
 
 
 
 
 
ad49718
6c04945
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
1179f4b
5dfece0
 
 
 
 
 
 
85c77db
1179f4b
5dfece0
ad49718
2789126
5dfece0
 
 
 
 
 
 
04212b0
ad49718
5dfece0
117c540
5dfece0
ad49718
c788628
ad49718
 
 
 
1179f4b
ad49718
 
1179f4b
 
af9ad05
1179f4b
 
 
ad49718
5dc17bf
5dfece0
04212b0
cdb1676
04212b0
cdb1676
 
5dc17bf
ad49718
5dc17bf
ad49718
 
e7688d0
ad49718
 
 
 
 
c788628
 
 
 
 
 
 
 
 
cdb1676
c788628
24da474
ad49718
cdb1676
ad49718
 
 
 
117c540
24da474
1179f4b
24da474
 
117c540
 
 
 
 
5dc17bf
 
c788628
5dc17bf
ad49718
5dc17bf
04212b0
 
117c540
 
ad49718
 
04212b0
 
 
 
117c540
 
5dc17bf
 
 
04212b0
5dc17bf
 
 
 
 
117c540
 
6c04945
5dfece0
5dc17bf
85c77db
5dc17bf
e7688d0
04c7825
 
 
 
 
 
 
 
5dc17bf
 
d55f5ff
64b6ec1
 
 
 
 
 
 
 
 
 
 
 
 
 
d55f5ff
5dc17bf
a7246a5
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
a7246a5
c788628
ad49718
24da474
85c77db
5dc17bf
24da474
5dc17bf
24da474
 
e7688d0
24da474
447c59a
e7688d0
 
24da474
 
 
 
117c540
 
24da474
1179f4b
f5b89ca
1179f4b
117c540
 
f5b89ca
 
a7246a5
5dc17bf
 
 
 
 
 
 
a7246a5
 
5dc17bf
 
 
 
c788628
 
 
 
 
a7246a5
5dc17bf
24da474
 
 
5dc17bf
 
 
 
 
 
 
 
 
1179f4b
 
85c77db
117c540
 
f5b89ca
117c540
 
 
 
 
 
 
 
 
f5b89ca
117c540
 
 
 
 
 
 
1179f4b
5dc17bf
1179f4b
 
 
 
 
 
 
1f5bfdb
04212b0
5dc17bf
 
 
e7688d0
 
5dc17bf
 
 
 
 
 
64b6ec1
c4936a9
 
 
c484f5f
c4936a9
c484f5f
c4936a9
 
 
 
 
 
 
 
 
117c540
c4936a9
 
 
 
 
 
 
 
117c540
 
c4936a9
 
 
 
b2efd1c
c4936a9
 
 
 
 
 
 
 
 
 
 
 
 
 
117c540
c4936a9
 
 
c484f5f
c4936a9
 
 
 
 
 
 
 
 
 
 
 
 
 
117c540
c4936a9
 
 
 
 
 
 
 
117c540
c4936a9
 
 
 
 
 
 
c484f5f
c4936a9
 
b2efd1c
 
c4936a9
117c540
 
c4936a9
 
 
 
 
 
 
 
 
5dfece0
c4936a9
 
5dfece0
c4936a9
 
 
 
 
 
 
 
5dfece0
c4936a9
5dc17bf
5dfece0
5dc17bf
 
 
 
5dfece0
1534178
117c540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
 
5dc17bf
5dfece0
 
5dc17bf
 
 
5dfece0
 
 
04212b0
 
 
5dfece0
5dc17bf
 
5dfece0
5dc17bf
 
7168c77
04212b0
5dfece0
5dc17bf
af9ad05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad49718
 
 
 
 
 
 
 
 
 
 
 
7168c77
ad49718
 
 
5dc17bf
 
 
 
 
 
 
 
 
 
7168c77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
5dc17bf
 
 
 
 
 
 
5dfece0
5dc17bf
 
 
 
 
 
 
 
 
 
 
5dfece0
04212b0
5dc17bf
 
 
 
 
5dfece0
 
5dc17bf
 
 
 
 
 
 
 
 
 
04212b0
5dc17bf
04212b0
 
5dc17bf
 
 
 
 
 
 
 
 
 
5dfece0
04212b0
5dfece0
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
5dfece0
5dc17bf
 
 
 
 
 
 
5dfece0
 
 
5dc17bf
 
5dfece0
5dc17bf
 
 
 
04212b0
5dc17bf
 
 
 
 
 
 
 
 
5dfece0
af9ad05
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
ad49718
 
 
 
 
 
 
 
 
 
 
 
 
 
7168c77
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
5dfece0
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
5dc17bf
 
5dfece0
 
5dc17bf
 
5dfece0
c788628
5dfece0
6c04945
5dfece0
 
 
 
 
5dc17bf
5dfece0
 
 
 
 
5dc17bf
5dfece0
04212b0
 
5dfece0
5dc17bf
 
 
 
5dfece0
5dc17bf
04212b0
 
 
 
 
5dc17bf
04212b0
5dc17bf
04212b0
 
5dc17bf
 
 
 
04212b0
 
 
 
 
5dc17bf
04212b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
04212b0
5dc17bf
 
04212b0
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
5dc17bf
5dfece0
5dc17bf
 
 
 
 
5dfece0
04212b0
5dc17bf
 
 
 
 
 
5dfece0
 
04212b0
5dc17bf
5dfece0
5dc17bf
5dfece0
5dc17bf
 
 
 
 
 
5dfece0
5dc17bf
 
 
 
 
5dfece0
5dc17bf
 
 
 
 
5dfece0
 
 
 
 
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
5dc17bf
5dfece0
5dc17bf
5dfece0
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
5dfece0
5dc17bf
 
 
5dfece0
 
5dc17bf
 
5dfece0
5dc17bf
 
 
 
 
5dfece0
 
 
5dc17bf
 
5dfece0
6c04945
5dfece0
04212b0
5dfece0
 
04212b0
5dfece0
 
 
04212b0
5dc17bf
5dfece0
 
04212b0
5dfece0
 
 
5dc17bf
5dfece0
04212b0
 
 
 
 
 
 
 
 
5dc17bf
04212b0
 
 
 
 
 
 
04c7825
e7688d0
04c7825
 
 
 
 
 
04212b0
 
 
5dc17bf
 
04212b0
 
 
 
 
5dc17bf
 
04212b0
 
 
 
 
 
5dfece0
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117c540
c788628
 
 
 
 
 
 
117c540
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
 
5dfece0
 
 
 
 
5dc17bf
5dfece0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
 
04212b0
 
 
 
5dc17bf
 
04212b0
 
 
 
5dc17bf
 
04212b0
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
 
6c04945
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
dfcd1e9
a7246a5
04212b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
 
04212b0
 
 
 
 
 
5dc17bf
 
04212b0
 
 
 
 
 
 
 
 
9529e83
ad49718
5dc17bf
04212b0
 
5dc17bf
 
 
04212b0
7168c77
dfcd1e9
 
04212b0
 
dfcd1e9
 
 
04212b0
dfcd1e9
 
 
 
 
 
 
 
7168c77
dfcd1e9
 
 
 
a7246a5
5dc17bf
 
 
 
04212b0
 
 
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04212b0
 
 
dfcd1e9
5dc17bf
 
 
 
 
 
04212b0
5dc17bf
 
 
 
 
04212b0
 
 
 
 
 
5dc17bf
04212b0
ad49718
 
 
 
 
 
04212b0
5dc17bf
5dfece0
5dc17bf
6c04945
5dfece0
 
5dc17bf
 
 
 
 
 
 
5dfece0
 
5dc17bf
 
 
 
5dfece0
 
 
 
 
 
 
 
5dc17bf
5dfece0
 
 
5dc17bf
5dfece0
 
 
5dc17bf
5dfece0
 
 
 
 
 
 
5dc17bf
5dfece0
 
 
5dc17bf
5dfece0
 
 
5dc17bf
04c7825
 
 
 
5dfece0
e7688d0
 
 
 
 
 
 
 
 
 
 
 
c788628
 
 
 
 
 
 
 
 
 
 
 
24da474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af9ad05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dc17bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
5dc17bf
 
 
5dfece0
5dc17bf
 
 
 
d55f5ff
 
5dfece0
d55f5ff
 
 
 
 
 
 
 
 
 
 
 
5927cf9
 
5dfece0
5927cf9
 
 
 
 
 
 
5dc17bf
 
 
 
2fa7407
5dc17bf
 
5927cf9
5dc17bf
 
 
5dfece0
5dc17bf
5927cf9
 
 
5dc17bf
 
 
 
 
 
5927cf9
 
 
c546719
2fa7407
 
5927cf9
2fa7407
 
 
 
 
5927cf9
 
 
 
2fa7407
 
 
 
 
 
 
 
f3080cd
 
 
 
 
117c540
 
 
f3080cd
117c540
 
f3080cd
 
 
 
 
 
 
 
 
 
2fa7407
 
 
c788628
 
2fa7407
 
 
 
 
 
 
 
117c540
2fa7407
 
c788628
 
2fa7407
 
 
c788628
 
 
 
 
 
117c540
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117c540
 
c788628
 
 
 
 
 
 
117c540
c788628
 
 
 
 
 
 
 
 
 
 
fa71b37
2fa7407
c788628
 
 
 
 
 
117c540
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
2fa7407
 
 
 
 
 
c788628
2fa7407
c788628
2fa7407
 
 
 
c788628
 
2fa7407
 
c788628
 
2fa7407
c788628
2fa7407
 
 
c788628
 
 
 
2fa7407
 
 
 
 
 
 
 
 
 
 
d55f5ff
 
b29738d
 
d55f5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c788628
2e435a7
 
 
 
 
d55f5ff
 
 
 
 
c788628
d55f5ff
 
 
 
 
e628dc2
d55f5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b29738d
d55f5ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c788628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dfece0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
    
    <link rel="stylesheet" href="https://use.typekit.net/zos0ars.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="static/style.css">
    <link rel="stylesheet" href="static/MenuStyle.css">
    <link rel="stylesheet" href="static/LegendPageStyle.css">
    <link rel="stylesheet" href="static/popups.css">
    <link rel="stylesheet" href="static/IMG-Larger.css">
    <link rel="stylesheet" href="static/searchButton.css">
    <meta charset="utf-8">
    <title>ADR Console</title>
    <link rel = "icon"  type = "image/png"  sizes = "180x154" href = "static/images/TSAlogoCropped180x154.png">
    <link rel = "icon" type = "image/png" sizes = "32x27" href = "static/images/TSAlogoCropped32x27.png">
    <link rel = "icon" type = "image/png" sizes = "16x14" href = "static/images/TSAlogoCropped16x14.png">
    <link rel = "mask-icon" href = "static/images/TSAlogoCropped180x154.png">
    <link rel = "shortcut icon" href = "static/images/TSAlogoCropped180x154.png">



  </head>
  <body >
    <div id="pdf-container"></div>

    <div id="all">
      <!-- {% include 'loading.html' %} -->
      {% include 'loading.html' %}
    </div>
    <!--Main tab links-->
    <div class="tab" >
      <div class="container"  id="toggle">
        <div class="bar1"></div>
        <div class="bar2"></div>
        <div class="bar3"></div>
      </div>
      
      <button class="tablinks"  id="pagetitle" onclick="openTab(event, 'home')">ADR Console <i class="fa fa-home" > </i></button>
      <!-- <button class="tablinks" id="LegendHist" onclick="openTab(event, 'legends')">Legends History  <i class="fa fa-caret-down"></i></button> -->
      <a class="tablinks" id="LegendHist" href="{{ url_for('legendDirectory') }}">
        Legends History <i class="fa fa-caret-down"></i>
        </a>
          <!-- Container for dynamic tabs -->
 
          <div id="dynamicTabs" class="dynamicdropdownclass">
            <!-- This will be the dropdown content (FramestabsDropdown) -->
            <!-- <div id="FramestabsDropdown"></div> -->
          </div> 
      <button class="dropbtn" onclick="userguideclick()"><img id="infoImg" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAHz0lEQVR4nNVbW0xVVxC9SAEfNPGRCJICGoWKRkUUNfEVFUnsn0ZjfARfAWmq8UNLfSUmxkLxCzDS6kcrDx8/xkeiaFujJia1ifFDRPyw0Fi0xjeliKi4mnU49+bcfeZwufeefaErmYQczt2zZ/bsPbNn5ng8mgFgAoDNAA4B+BnAnwBaYUer+b/L5rv8TYbn/wYA0QCWAKgG8DfCx2NzLI4Z7emvAJAEoNScsC5w7O8AjPL0FwBIAfA9gLeIHDoAHAaQ3JeCxwLYDaA90GyfPn2KM2fOoKSkBOvXr0dOTg6mT5+OjIwMg/g3n23YsMF45+zZs3j27FlvFPEvgG8AxERa+GwAjT3NrL6+HkVFRZg8eTKioqLAnwVD/M2UKVOwc+dO3L17N5AiGgBkRUr4AgCd0izev3+P6upqZGVlBS1wIJo2bRpqamoMHg7gFtwGIEqX4HEATkmcP378iGPHjmHMmDGuC67S2LFjDUWQpwOOc3u6LfynAH6RuN25cwezZ8/WLrhK8+bN62lrMN6Id1P43yUuR44cQVxcXMSF9xJ5l5WVOSnht7CVgG6z/1Ud+c2bN1i+fHmfCa7SypUrjTkJuBzydgAQJe35V69eYc6cOdqEiY2NRXx8fNC/mzVrFp4/fy4poTZUBWxTR3r58qXhmnSZc0VFBdrb231ny9SpU4MaIzMz01ggAV+F4uc7VbOfO3eutpU/dcruYJqbm4M+Y2gJXiUqLjIrmAivUR1B557nSjshWCvwngkOwVLgiBHd4a0faJq6hCcVFDC2ksEAKJQxKysrpeGKAgmfqsb23Iu6Xd2WLVtE4Z88eYKYmJiQxhw4cKAUJ/Du8FlPCvjB+jajrfnz52sVnsQLkRTirl27NqxxeWYJEWNFT/f5t9Y3Gd7qFt5LvAm2tbUZfOnOeGt0Y9za2lpVAQwYEiUFlFrf+vDhA8aNGxcxBZBo7qNHjw7Z7J3uDoJ1lajCf6Kmr6qqqiIqvE46fpz3Iz888kuvAfhCfUPHldaJoqOjkZycjKSkpJByB4GICRcBuVYF1Fj/w9MzEoJPmjTJsDRr9NbY2Ijx48e7zkvwCD9ZY34/82cmR6fgEydOxIULFxzv9Eyfuc1z925bePPIq4AM9T9cGR2C07x37dqFzk4xoeTDtWvXXOfNLS3gcyqg0PqELmjAgAGuT2DQoEHGyvYG5eXlrvOnTEKitcBjVmF8YEbWbeaDBw/GlStX/DjT/Lu6ukQFrFixQosFnj9/XmVV5jGTBj4UFxe7ynTIkCG4evWq35X64MGDxon/+vVrm/D02cOGDdOigNJSv1CHqKMCmq1P1q1b56rZX79+3Rj33r17KCwsNBTiDX8l3LhxQ4vwpI0bN6rs/qACuuNPE4sWLXKNIX37yZMnkZuba/PvO3bsEBWwd+9ebQpg8UVBKxXg54uys7O1TcBKXstQwaBFF8+ZM2eq7LqoAD/QNHULzz0u3f5YQtPhgbw0YQIr9f7w9IUCVq1aJa4+Cx46+TopoCvSW+DEiROiAtasWaOVr9MWaNN1CDpdfKT0NWOCkSNHauXtdAg2W5+4lYjoKUsj4datW9otb9OmTaIbvGx9wvq8zkkcOHBAVACf61YAAzApEDqkOxS20s2bN0UF6Kw5BAqFN0fiMkQaOnSokWpT0dra6moaLIjLUL54HWZXh45JLF26VFz906dPa1991hcEpHlzAsyR+cC2FB2TOHyYfU12sDCiWwF79uxR2bZYU2Lsw/OhoaFByyTu378vKiA1NVW7AphqU/CjVQFsQnSlJOVEw4cPF1NgTU1N2oVncCcgR+3ufKwzLF2yxKZjA0xZ61YAb6Sq+du6TtHdgekDT+u0tDTXJrFv3z5RAVu3brW9m5CQgP379yMvLy9svizuCJ7nW6kyNMrswPSBLW9uKeDixYuiAhYvXux7h+nwo0ePoqOjw8gWuREbCKvP0liCU32w0vom9+yCBQtcUcCDBw9EBfCsWbZsGerq6nw5wpaWFldcMTvJhHOnTBSeYO+tWUL2gQUFlprDmQizQVxVCepzeqCUlJSwheecmYZT8A+LwJ6egO7eWz/Qf4czmREjRqA3YJbIrYQoW/gEbO9ReEuLDNtJ/MC2k1AnwzD33bt3joLTTFkLcCscXr16tcSmvtdN1QCy1F4BNklxT4U6KV6yJDx8+BALFy50RXASGzqE7cYHmb0S3gsAtr4VFjHZihbKxBITE42Dji6J+cDbt28jPz/f1fYbzk2qNQD40hMK0N14bFNCOJbAWkG4h6rTyjsIXxWS8JbzgI3HULdDOGeC28Q97+BlLoX9MQWAeLPx2K7aqiqj7tdXgtOStDZLK0rwS51Z44RIdJKpxABN8PPWlXdHeGU72M4ErxtjN1YkmqrS09Ol8NbPMLV+QwQgz4ynbeAJz9udjvLWjBkzjHqClFKzfjKjTXAhTrAFS1bQPNmWwl7fUHKM/A27OpjJEZIZUpATnJ8PFwBiAHyt3h0kMNF67tw5oz7PEjVvgExSeD+b4+ryGfP2fIfZ2xcvXqAXYGy/PeKfzVnB3lsztS5uC00gr/KAF5tIAkAi6ypqgtVlMJNT7Hif7w9Ad3otl3145oTDxV9MYDJ30q8/nvY4gK1o5seWjFjon5sASDEruyX5vzrz3XwA6bon+B8RXxEBPsptqAAAAABJRU5ErkJggg=="></button>

</div>
<div id="FramestabsDropdown"> </div>
    <div id="mySidebar"  class="slide-out">
        <div id="menuOptions">
          <li onclick="openTab(event, 'home')" >Measure Plans </li>
          <li><a href="{{ url_for('searchDocument') }}">Search in Documents</a></li>
        </div>
    </div>

    <div id="home" class="tabcontent" >

        <div id="loading"  hidden> </div>

        <div id="canvaswindow" hidden="until-found">
          <canvas id="myCanvas"></canvas>
          <br>
            <input type="button" value="Draw New Shape" id="NewShapeButtonId" /> 
            <input type="button" value="Undo" id="undoButtonId" />
            <div id="colorpickers">
              <input type="color" id="color" value="#2FFFFF" >
            </div>
            <input type="button" value="Save" id="savecanvas" />
        </div>

    <div id="rightside" hidden="until-found"> 
      
        <div id="backgroundimg" > 
           <div id="imgs">
                <!-- image here -->
           </div>
          <div id="underimgbuttons">
              <!-- buttons here -->
          </div>
        </div> 
    </div>
            

     
        
    <div id="myModal" class="modal" >
      <span class="close">&times;</span>
      <img class="modal-content" id="img01">
      <div id="caption"></div>
    </div>


    <form method="post"  id="myForm" enctype="multipart/form-data">

      <!-- <div class="projnamedp">
        <input type="text" placeholder="Project" name="selectproj" class="selectionsProj" id="selectionsProjid"  oninput="filterFunction(this,event)" >
        <ul>
        </ul>
    </div> -->
    <input type="button" id="refreshAPIbutton" title="Refresh data retrieved from MC" value="Refresh data retrieved from MC ">
      <div id ="">
          <select name="selectproj" class="selectionsProj" id="selectionsProjid"  required  >     </select>
      </div>
  
      <div id ="projectpart">
          <select name="selectprojp" class="selectionsProjp" id="selectionsProjpid" required>    </select>
      </div>
  
      <div id ="projectsection">
          <select name="selectprojs" class="selectionsProjs" onchange=getproj() required>   </select>
      </div>

  
      <div id ="tomeasurediv">
          <div>
            <label id="measureLabel">Document To Measure</label>  
              <input type="search" onkeyup=filterFunction(this.id) id="tomeasureSearchInput">
              <!-- <button id="refreshDropboxButtonID"></button>  -->
              <i hidden class="fa fa-dropbox fa-lg" id="refreshDropboxButtonID"> 
                <span class="dropboxtip">The console updates projects retrieved from Dropbox automatically at 9:00 am and 9:00 p.m. If you need to access any projects in between, just click on this button. Please note that it will refresh the files related to the project you chose only.</span> </i>            
  
          </div>
          <div id="measureCheckbox">
            <!-- <select style="margin-left: -1%;" hidden name="measureselectname"  id="measureselectid"  multiple size="5"></select> -->
            <div id="measureContainer" hidden required></div>
            <div id="dxfdiv" hidden="until-found">
                <input type="button" id="pdftodxfFileButton" onclick="document.getElementById('pdftodxfFile').click();" value="Upload DXF File" >
                <input type="file" id="pdftodxfFile" name="pdftodxfFilename" > 
            </div>
            <select id='selectunitA' hidden>
              <option id="m2" value="m2" >m&#xb2; </option>
              <option id="mm2" value="mm2" >mm&#xb2;  </option>
            </select>
            <select id='selectunitP' hidden>
              <option id="m" value="m" >m </option>
              <option id="mm"value="mm" >mm  </option>
            </select>
          </div>
      </div>
  
      <div id ="relvDocdiv">
        <label id="relvDocLabel">Other Relevant Documents</label> 
        <input type="search" onkeyup=filterFunction(this.id) id="relevantSearchInput"> 
        <br>
        <div id ="relvdiv">
          <div id="relvselectid" hidden></div>
          <!-- <select style="margin-left: -1%;" hidden name="relvselectname"  id="relvselectid"  multiple size="5">   </select> -->
          <iframe id="pdfFrame" hidden></iframe>
        </div>
      </div>
   
      <div id="ratios">   </div>
   
      <div id="radiosColors" hidden="until-found">

        <div id="checkboxLine">
          <input type="checkbox" id="levelcheckbox">
          <label id="nLevels" name="levelsnamelabel">Leveled Plan</label>
          <i class="fa fa-info-circle" id="infotool">
            <span class="tooltiptext">
              Choose whether this project contains levels or not. Leave the checkbox unchecked if you want to measure the entirety of the plan.
              <br> Please check the box on this line if you want to measure certain areas of the plan or have the plan divided into levels. Once the checkbox is ticked, a window will appear that will allow you to draw on the PDF. Click the save button at the bottom of the page when you are done.
            </span>
          </i>
        </div>
        
        <div class="button-container">
          <input type="button" id="popupforextratext" title="Add Key Information" value="Add Key Information">
        </div>
        <!-- <br>
        <input type="checkbox" id="levelcheckbox" >
        <label id=nLevels name="levelsnamelabel"  >Leveled Plan </label>
        <i  class="fa fa-info-circle" id="infotool" > <span class="tooltiptext">Choose whether this project contains levels or not. Leave the checkbox unchecked if you want to measure the entirety of the plan. <br> Please check the box on this line if you want to measure certain areas of the plan or have the plan divided into levels. Once the checkbox is ticked, a window will apear that will allow you to draw on the PDF. Click the save button at the bottom of the page when you are done. </span> </i> -->
        
      </div>

     <div id ="saveOPdiv">
      <button id="measureADRbutton">Measure using ADR</button> 
      <script src="https://cdn.lordicon.com/bhenfmcm.js"></script>
      <lord-icon
          src="https://cdn.lordicon.com/ynwbvguu.json"
          trigger="hover" colors="primary:black"   id="addicon" style="display: none;" onclick="duplicate()" >
      </lord-icon>
      </div>
      <audio id="myAudio" autoplay></audio>
    </form>  
    <div id="progressBar" hidden>
      <div id="progress">0%</div>
  </div>

    <div id ="duplicater" class="duplicaterclass" hidden="until-found">
      <label id="labelArrayId" hidden="until-found"> </label>
      <select name="measurementscripts" class="measurementselections" id="measurementselectionsid" >    </select>

      <select name="select" class="selections"  id="selectionsid" > 
      </select>
      <select name="measureitem" class="measureitems"  id="measureitemsid"> </select>
        <br>
        <div id="repeatforloop" class="repeatforloopclass00" name="repeatforloopname " >  
              <select type="text" id="text0" name="text1name" placeholder="GB-1" class=gb> </select>
              <input type="text" id="text1" name="text2name"  placeholder="A" class=a>
              <input type="text" id="text2" name="text3name" placeholder="Depth" class=depth>
              <script src="https://cdn.lordicon.com/bhenfmcm.js" ></script>
              <lord-icon
                  onclick="addmctnameicon()"
                  src="https://cdn.lordicon.com/mecwbjnp.json"
                  trigger="hover"
                  class="addmctnameclass"
                  id="addmctnameid"
                  colors="primary:black,secondary:black">
              </lord-icon>
        </div>   

    </div>   
    <button  hidden id="doneebackground"   onclick="getSecondData()" > Export Summary </button>
    <button  hidden id="summarytoXML"   onclick=summary_to_XML() > Summary to XML</button>
    <div  hidden id ="duplicaterhidden" class="duplicaterclasshidden">
        <label id="labelArrayId" hidden="until-found"> </label>
        <select name="measurementscripts" class="measurementselections" id="measurementselectionsid" > 
          <option value="" disabled selected hidden>Select</option>
        </select>
        <select name="select" class="selections" id="selectionsid">    </select>
        <select type="text" name="measureitem" class="measureitems" id="measureitemsid">    </select>
        <!-- <select name="select" class="selections" id="selectionsM-M2" >    </select> -->
        <br> 
        <div id="repeatforloophidden" class="repeatforloopclasshidden" name="repeatforloopnamehidden " >    <!-- onchange="getmctName()" -->
      

              <select type="text" id="text0" name="text1name" placeholder="GB-1" class=gb> </select>
              <input type="text" id="text1" name="text2name"  placeholder="A" class=a>
              <input type="text" id="text2" name="text3name" placeholder="Depth" class=depth>
              <script src="https://cdn.lordicon.com/bhenfmcm.js" ></script>
              <lord-icon
                  onclick="addmctnameicon()"
                  src="https://cdn.lordicon.com/mecwbjnp.json"
                  trigger="hover"
                  class="addmctnameclass"
                  id="addmctnameid"
                  colors="primary:black,secondary:black">
              </lord-icon>
              <script src="https://cdn.lordicon.com/bhenfmcm.js"></script>
              <lord-icon
                  onclick="deletemctnameicon()"
                  src="https://cdn.lordicon.com/rivoakkk.json"
                  trigger="hover"
                  class="deletemctnameclass"
                  id="deletemctnameid"
                  colors="primary:black,secondary:black">
              </lord-icon>
        </div>   
 
      </div>
     
    </div>
    
    <div id="legends" class="tabcontent">
        <ul class="graynavbarLegend" >
          <label class="label1">Project Name / Project Part / NRM Section /</label> <label class="label2">Legend</label>
          <div class="legendtime"> 
            <div style="display: inline-flex;">
              <label class="CreatedTime"> Created Time </label>
              <button id="sortBtnCreateDesc" class="sortbutton" onclick="sortlegends(this.id)"><i id="CreatesortDesc" class="fa fa-sort-amount-desc" aria-hidden="true" ></i> </button>
              <button id="sortBtnCreateAsc" class="sortbutton" onclick="sortlegends(this.id)"><i id="CreatesortAsc" class="fa fa-sort-amount-asc" aria-hidden="true" ></i></button>
            </div>
            <div style="display: inline-flex;">
              <label class="EditTime"> Last Edited Time   </label>
              <button id="sortBtnEditDesc" class="sortbutton" onclick="sortlegends(this.id)"><i id="EditsortDesc" class="fa fa-sort-amount-desc" aria-hidden="true" ></i></button>
              <button id="sortBtnEditAsc"class="sortbutton" onclick="sortlegends(this.id)"><i id="EditsortAsc" class="fa fa-sort-amount-asc" aria-hidden="true" ></i> </button>
            </div>
          </div>
        </ul>
        
    </div>
    <div id="consoleContent"></div>
    <div class="dropdown-content"   id="dropdown-contentUserguideId" name="tobeclosed">
            <div id="userguidetext" >
                <div id="UserguideRibbon"> 
                  <label id="UserGuideHeader"> User Guide Text: Before using this tool, kindly read the following carefully.   </label>
                      <button id="homeguidebutton" style="background-color: transparent; border: none;" onclick="ShowSectionUserguide(this)">
                        <i class="fa fa-home fa-lg" id="userguideHome"></i>
                      </button> 

                      <div class="Userguidecontainer" id="UserGuidetoggle" onclick="userguidetoggleFunction()">
                            <div class="UserGuidebar1"></div>
                            <div class="UserGuidebar2"></div>
                            <div class="UserGuidebar3"></div>
                      </div>

                     
                      <button type="button" class="closeModal" id="userguideClose" data-dismiss="modal">&times;</button>
                      <button style="background-color: transparent; border: none;"  id="userguideTableMaya" onclick="userguideMayaTableClick()">
                        <i class="fa fa-th fa-lg" aria-hidden="true"></i>
                      </button> 
                      <div id="UserGuideSideBar">
                            <div id="UserGuidemenuOptions">
                              <li onclick="ShowSectionUserguide(this)">1.0 Substructure</li>
                              <li onclick="ShowSectionUserguide(this)">2.1 Frames</li>
                              <li onclick="ShowSectionUserguide(this)">2.2 Upper Floor</li>
                              <li onclick="ShowSectionUserguide(this)">2.3 Roof</li>
                              <li onclick="ShowSectionUserguide(this)">2.4 Stairs</li>
                              <li onclick="ShowSectionUserguide(this)">2.5 External Walls</li>
                              <li onclick="ShowSectionUserguide(this)">2.6 External Openings</li>
                              <li onclick="ShowSectionUserguide(this)">2.7 Internal Walls</li>
                              <li onclick="ShowSectionUserguide(this)">2.8 Internal Openings</li>
                              <li onclick="ShowSectionUserguide(this)">3.1 Wall Finishes</li>
                              <li onclick="ShowSectionUserguide(this)">3.2 Floor Finishes</li>
                              <li onclick="ShowSectionUserguide(this)">3.3 Ceiling Finishes</li>
                              <li onclick="ShowSectionUserguide(this)">4.0 Fittings, Furnishings and Equipments</li>
                              <li onclick="ShowSectionUserguide(this)">5.0 Services</li>
                              <li onclick="ShowSectionUserguide(this)">5.1 Sanitary</li>
                              <li onclick="ShowSectionUserguide(this)">7.0 Works to existing buildings</li>
                              <li onclick="ShowSectionUserguide(this)">8.1 Site Preparation Works</li>
                              <li onclick="ShowSectionUserguide(this)">8.2 Roads, Paths, Pavings</li>
                              <li onclick="ShowSectionUserguide(this)">8.3 Soft Landscaping</li>
                              <li onclick="ShowSectionUserguide(this)">8.4 Fencing, Railing, Walls</li>
                              <li onclick="ShowSectionUserguide(this)">8.5 External Fixtures</li>
                              <li onclick="ShowSectionUserguide(this)">8.6 External Drainage</li>
                              <li onclick="ShowSectionUserguide(this)">8.7 External Services</li>
                              <li onclick="ShowSectionUserguide(this)">8.8 Minor Buildings</li>
                      
                            </div>
                      </div>
                </div>
              
                
                <div id="textfirstpage">
                      <label style="font-weight: bold;">
                        After reading this user guide, if you still encounter any issues or have suggestions for improving the system, please don't hesitate to contact the ADR team.
                    </label>
                    <br>
                      <label style="font-style: italic;">
                        This page provides general guidance on using the console. For details on a specific section, refer to the menu and select the desired section by clicking the '<i class="fa fa-bars" aria-hidden="true"></i>' icon.
                        <br> 
                        In the top right corner, you will find this icon '<i class="fa fa-th fa-lg" aria-hidden="true"></i>', which, when clicked, takes you to a Google Spreadsheet containing a summarized table of the main AI features implemented and
                        planned for the ADR console, along with the sections where they are applied.
                    </label>

                
                      <br>
                      The tool is divided into two main parts: 
                        <br><br>
                        <i class="fa fa-circle" aria-hidden="true">  </i>  <label id="userguideheadings"> First Part </label>
                          <br>
                          <div style="margin-left: 40px;">
                              The system automatically refreshes all data retrieved every 5 minutes from the MC including project names, parts, sections, and MC-T names every. However, if you notice missing information, click this button 
                              <span style="background-color: blue; color: white; padding: 2px 8px; border-radius: 4px; font-style: italic; margin-top: 5px;">Refresh data received from MC</span> to retrieve the latest MC updates. 

                              <br>
                              <label id="underlinedLables">Inputs: </label>
                              <br>
                                
                                <li>
                                      Use the three dropdown menus to select the project name, part, and section to measure. 
                                      <br>
                                      <img src="static/images/Dropdowns_3.png" alt="Dropdown menus example" style="margin-top: 10px; width:240px;">
                                      <label style="font-style: italic; margin-left: -10px; margin-top: 50px;color: #2e83c7;"> Ensure the correct 'Project Section' is selected, as it affects the applied code. </label>
                                      <br>
                                </li>
                                <li>
                                      <label style="font-size: 15px;"> Document To Measure: </label>
                                      <br>
                                      Clicking a document's name opens a PDF preview in a separate tab attached to the black ribbon inside the console. Checking the box next to the document selects it as the document to measure.
                                      
                                      <br>
                                      <li>
                                        When retrieving documents for measurement, if multiple files share the same name on Dropbox, a popup may appear. In such cases, please rename the files in Dropbox, then return to the console and click the following icon:
                                        <i hidden class="fa fa-dropbox" style="color:white; background-color: #2e83c7; border-radius: 4px;"></i> to retrieve the updated documents. You can then select the desired document for measurement. Please note that this process will refresh all documents in the selected project folder.
                                      </li>
                                      <br>
                                      <label style="font-style: italic;"> Pixel-to-Metric conversion important notes:</label> 
                                      <br>
                                      Upon selecting a plan, the console automatically downloads the PDF with a colored rectangle. Open it in Foxit Reader, Adobe, or Bluebeam to measure its area and perimeter in the desired metric unit. 
                                      Enter these values in the provided textboxes. A dropdown next to each textbox lets you choose between meters (m) or millimeters (mm) for accurate scaling.
                                      <br>
                                      This rectangle serves as a scale check for Bluebeam. Refer to the relevant section for further details.
                                      <br>
                                      <li>
                                        Click <span style="background-color: #b216c7; color: white; padding: 2px 8px; border-radius: 4px; font-style: italic;">Add Key Information</span> button to open a popup where you can input additional details to assist in the detection process.
                                      </li>
                                      </li>
                              <label id="underlinedLables">Outputs: </label> <br>
                                    The right panel displays results in three sections:
                                    <li>A preview of the measured plan, which you can click to expand.</li>
                                    <li>Three buttons:
                                      <li> <label style="font-weight: bold;" >"Legend and Data Created" </label> – Access the Google Sheet legend.</li>
                                      <li> <label style="font-weight: bold;" >"Click to View as PDF" </label>– Opens the marked-up PDF in Dropbox. <label>(Do not download for this feature.)  </label></li>
                                      <li> This icon <i class='fa fa-refresh' style="color:white; padding: 3px 3px;background-color: rgb(255,0,255); border-radius: 4px;"></i> button allows you to get the deleted markups (in case you deleted any from the pdf on dropbox).</li>
                                    </li>

                                    <br> 
                                    <label style="font-weight: bold;" > ONLY IN DROPBOX VIEW. DO NOT DOWNLOAD THE PDF FOR THIS FEATURE. </label>
                                    <br>
                                    <label style="font-style: oblique;" >
                                      Note : The algorithm is based on detecting shapes and colors from the plan. Some shapes such as tables and textboxes carrying plan-related information, may also be viewed as shapes and so added to the algorithm. 
                                  </label>
                                    Any markup that you deem unnecessary in the pdf can be removed. After deleting any markup, the console will notify you with a message asking whether you would like to delete it from legend or not and the legend will be updated accordingly.
                                  </div>
                                    <br> 
                                <i class="fa fa-circle" aria-hidden="true"> </i>  <label id="userguideheadings"> Second Part </label> 
                                <br><br>
                                <div style="margin-left: 40px;"> 
                                      To open the Google sheet with the created legend, first click the button labeled "Legend and Data created." Names of each shape should go in the first column of the sheet labeled ‘Guess’. 
                                      <br>Ex. GB-1.
                                      <br> Then, return to this page, the ADR Console, to finish entering the remaining data after you have finished entering the guessed names in the legend.
                                      <br> Three dropdown menus and three text boxes are present. 
                                    
                              
                                      <li style="list-style-type:square;"> You can select the type of the shape from the first dropdown: <!--by selecting either: -->
                                          <br>  &emsp;&emsp;   e.g. (1.0 Substructure) Ground Beam or Pile Cap. Refer to the relevant section for more details. 
                                          <!-- <br> &emsp;&emsp; b. (3.2 Floor Finishes) Floor or Wall -->
                                      </li>
                                      <li style="list-style-type:square;">  In the second dropdown, you will find a list of MC-T Names. Choose Accordingly.</li>
                                      <li style="list-style-type:square;"> The third dropdown menu has the unit of the MC-T Name you have chosen.</li>
                                    <br> Note: If the unit was (m), choose whether you wish to extract perimeter or length data from the third selection.
                                    <br><br><label  style="font-style: italic;"> Regarding the MC-T naming process: </label>
                                    Then add the relevant detail and depth to the rows underneath the dropdowns.
                                    You can add/ subtract rows by using the + and - button.
                                  
                                    <br>
                                  
                                    You can add another block and repeat the process for another item by clicking the button next to "Measure using ADR". 

                            </div>
                              
                        
                </div>
                <div id="1_0textUserGuide" hidden class="othesectionsuserguide">
                  User guide in progress...

                </div>
                <div id="2_1textUserGuide" hidden class="othesectionsuserguide">
                  User guide in progress...

                </div>
                <div id="2_7textUserGuide" hidden class="othesectionsuserguide">
                  User guide in progress...                  

                </div>
                <div id="2_8textUserGuide" hidden class="othesectionsuserguide">
                  User guide in progress...

                </div>
                <div id="3_2textUserGuide" hidden class="othesectionsuserguide">
                  User guide in progress...

                </div>
                <div id="3_3textUserGuide" hidden class="othesectionsuserguide">
                  User guide in progress...

                </div>
            </div>
    </div>
<!-- POP-UP code -- to handle errors -->
<!-- Link to trigger modal -->

<!-- Modal popup box -->
<div id="mpopupBox" class="mpopup" name="tobeclosed">
    <!-- Modal content -->
    <div class="modal-content">
        <div class="modal-header">
           <button type="button" class="closeModal" data-dismiss="modal">&times;</button>
            <h2 id="TopTextModal">Error</h2>
        </div>
        <div class="modal-body">
          <p id="modal-bodyText"> 
          </p>
          <br>
        </div>

    </div>
</div>




<div id="dialog-container" class="overlay" name="tobeclosed">
  <!-- Modal content -->
  <div class="modal-content">
      <div class="modal-header">
         <button type="button" class="closeModal" >&times;</button>
          <h2 id="TopTextModalWarning">Warning!</h2>
      </div>

        <div class="modal-body">
          <p id="modal-bodyTextp">The console updates projects retrieved from Dropbox automatically at 9:00 am and 9:00 p.m. If you need to access any projects in between, just click on this button. Please note that it will refresh the files related to the project you chose only. 
          </p>
          <div id="duplicaterExtra" hidden="until-found">
                <div id="repeatforloopExtra" class="repeatforloopclassExtra0" name="repeatforloopExtraname " > 
                  <label id="modalColIndex">Index</label>
                  <i class="fa fa-info-circle smallFaIcon" id="infotoolModal">
                    <span class="tooltiptext" id="modaltooltips">
                       Index of column. (Optional)
                    </span>
                  </i>
                  <label id="modalColumn">Type</label> <label id="modalGray">(from drawing)</label>
                  <i class="fa fa-info-circle smallFaIcon" id="infotoolModal">
                    <span class="tooltiptext" id="modaltooltips">
                      Enter the title for the column as it will be shown in Bluebeam columns. This helps organize and categorize extracted information.
                    </span>
                  </i>
                  <label id="modalKeyword">Specification</label> <label  id="modalGray">(from drawing)</label>
                  <i class="fa fa-info-circle smallFaIcon" id="infotoolModal">
                    <span class="tooltiptext" id="modaltooltips">
                      Provide a word or phrase from the data you want to help detect relevant information in the drawing. 
                    </span>
                  </i>
                  <label id="modalCharacter">Count</label>
                  <i class="fa fa-info-circle smallFaIcon" id="infotoolModal">
                    <span class="tooltiptext" id="modaltooltips">
                      Set the number of characters that is expected to be captured. This helps refine the extraction by limiting or expanding the detected text. 
                    </span>
                  </i>
                  <br>
                  <input type="number" id="textextra" name="text0name" placeholder="Eg: 1" >
                  <input type="text" id="text0extra" name="text1name" placeholder="Eg: Wall Type" > 
                  <input type="text" id="text1extra" name="text2name"  placeholder="Eg:NBS K10/" >
                  <input type="number" id="text2extra" name="text3name" placeholder="Eg: 3" min="0">
                  
                  <script src="https://cdn.lordicon.com/bhenfmcm.js" ></script>
                  <lord-icon
                      onclick="addmctnameiconPopup()"
                      src="https://cdn.lordicon.com/mecwbjnp.json"
                      trigger="hover"
                      class="addmctnameclassExtra"
                      id="addmctnameidExtra"
                      colors="primary:black,secondary:black">
                  </lord-icon>
                </div> 
            </div>
            <div hidden="until-found" id="duplicaterExtraHidden" >
                <div id="repeatforloopExtrahidden" class="repeatforloopclassExtrahidden" name="repeatforloopnameExtrahidden " >    <!-- onchange="getmctName()" -->
                  <input type="number" id="textextra" name="text0name" placeholder="Eg: 1" >
                  <input type="text" id="text0extra" name="text1name" placeholder="Eg:Specification" > 
                  <input type="text" id="text1extra" name="text2name"  placeholder="Eg:NBS K10/" >
                  <input type="number" id="text2extra" name="text3name" placeholder="Eg: 3" >
                  <script src="https://cdn.lordicon.com/bhenfmcm.js" ></script>
                  <lord-icon
                      onclick="addmctnameiconPopup()"
                      src="https://cdn.lordicon.com/mecwbjnp.json"
                      trigger="hover"
                      class="addmctnameclassExtra"
                      id="addmctnameidExtra"
                      colors="primary:black,secondary:black">
                  </lord-icon>
                  <script src="https://cdn.lordicon.com/bhenfmcm.js"></script>
                  <lord-icon
                      onclick="deletemctnameiconPopup()"
                      src="https://cdn.lordicon.com/rivoakkk.json"
                      trigger="hover"
                      class="deletemctnameclassExtra"
                      id="deletemctnameidExtra"
                      colors="primary:black,secondary:black">
                  </lord-icon>
            </div>   
    
          </div>

        <br>
        <div class="text-right">
          <button class="dialog-btn btn-primary" id="confirm">Ok</button>
          <button class="dialog-btn btn-cancel" id="cancel">Cancel</button>
        </div>
        <br>
      </div>
  </div>
</div>

  </body>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.14.305/pdf.min.js"></script>
<script > 

///////////////////////////////////////////////BEGIN JS CODE//////////////////////////////////////////////////

var ActiveSections=['1.0','2.1','2.7','2.8','3.2','3.3']

var menuItems = document.querySelectorAll("#UserGuidemenuOptions li");

menuItems.forEach(function (item) {
    // Extract the section number (first part of the text)
    var sectionNumber = item.textContent.trim().split(" ")[0];

    // If the section is not in ActiveSections, disable it
    if (!ActiveSections.includes(sectionNumber)) {
        item.id = "disabledSection";  // Assign ID
        item.style.color = "#bdbcbc"; // Greyed-out text
        item.style.cursor = "not-allowed"; // Change cursor
        item.onclick = null; // Disable clicking
    }
});

function updateProgressBar(value) {
    const progressBar = document.getElementById('progress');
    progressBar.style.width = value + '%';
    progressBar.innerText = Math.round(value) + '%';
}


// Function to send the Dropbox link and keyword to the server
function getURLParams() {
    const urlParams = new URLSearchParams(window.location.search);
    return {
        pdfLink: urlParams.get('pdfLink'),
        keyword: JSON.parse(decodeURIComponent(urlParams.get('keyword') || "[]")),  // Decode and parse
        pageNumber: parseInt(urlParams.get('page')) || 1,
        zoomRect: urlParams.get('zoom')  // Expecting format: "x,y,width,height"
    };
}
function processPdf() {
    // const pdfLink = 'https://www.dropbox.com/scl/fi/hnp4mqigb51a5kp89kgfa/00801-ARC-20-ZZ-S-A-0002.pdf?rlkey=45abeoebzqw4qwnslnei6dkd6&st=m4yrcjm2&dl=1'; // Dropbox link
    // const keyword = ['115 INTEGRATED MRI ROOM LININGS','710 TRANSPORTATION'] ;  // Example keyword
    const { pdfLink, keyword, pageNumber, zoomRect } = getURLParams();
    // Create a new FormData object to send the data as form data
    const formData = new FormData();
    formData.append('pdf_link', pdfLink);
    formData.append('keyword', JSON.stringify(keyword)); 
    // Send the data to the Flask server
    fetch('/api/process-data', {
        method: 'POST',
        body: formData,
    })
    .then(response => response.json())
    .then(data => {
        if (data.download_link) {
            //window.location.href = data.download_link; // This will use the rect info from Flask
            console.log('Done!')
        } else {
            alert('Error: ' + data.error);
        }
    })
    .catch(error => {
        console.error('Error:', error);
    });
}
// Call the function to process the PDF
// processPdf();  
////////////////////////////////////////////////////////////////////

PopupElement=document.getElementById('modal-bodyText');

sectionSelect=document.getElementById('section-select');
$(sectionSelect).select2({
  closeOnSelect: true,
  width:'20ch'

  });
// add project names to first dropdown from google sheet
firstdropdown=document.getElementsByClassName('selectionsProj')[0];
seconddropdown=document.getElementsByClassName('selectionsProjp')[0];
thirddropdown=document.getElementsByClassName('selectionsProjs')[0];


$(firstdropdown).select2({
  placeholder:'Projects',
  closeOnSelect: true,
  width:'51ch'

  });
  
$(seconddropdown).select2({
  placeholder:'Project Parts',
  closeOnSelect: true,
  width:'51ch'
  });
$(thirddropdown).select2({
  placeholder:'Sections',
  closeOnSelect: true,
  width:'51ch'
  });
var measSelect = document.getElementById("measureselectid");

var relvSelect = document.getElementById("relvselectid");
document.getElementById("all").style.display = "block";

PrjNamesArray=[];
PrjPartsArray=[];
PrjSectionsArray=[];
var partsArrwithID=[];
var firstDpwnValue;
var prjids=[]

displayprjnames()
function displayprjnames(){

  var eventSource = new EventSource('/getprojectnames/');
    document.getElementById('progressBar').removeAttribute('hidden')
    document.getElementById('progressBar').style.display='block';
    eventSource.onmessage = function (event) {
              var progress = parseInt(event.data);  // Progress value from Flask
              if (progress <= 100) {
                  console.log(progress);  // Log progress for debugging
                  document.getElementById('progress').style.width = progress + '%';
                  document.getElementById('progress').textContent = progress + '%';
              } else {
                  // Final data handling when progress reaches 100%
                  console.log('Process completed!');
                  
                  // Parse and handle the final response data (documentsToMeasure, RelevantDocuments, extracted_path)
                  var data = JSON.parse(event.data);  // Assuming the result is a JSON array
                  console.log('Final result:', data);
                  // You can use this data to update your page or handle it accordingly

                  eventSource.close();  // Close the connection when finished
                  document.getElementById('progressBar').setAttribute('hidden',true)
                  document.getElementById('progressBar').style.display='none';
                  document.getElementById('progress').style.width = '0%'; // Reset progress for the next process
                  document.getElementById('progress').textContent = '0%';

                  document.getElementById("all").style.display = "none";
                  prjids=data[1];
                  var op0 = document.createElement("OPTION") ;
                    op0.text= 'Projects'
                    op0.value= "";
                    op0.hidden=true;
                    firstdropdown.add(op0);
                  for (let i=0;i<data[0].length;i++)
                  {
                    opt=document.createElement("option");
                    opt.textContent=data[0][i];
                    opt.text=data[0][i];
                    firstdropdown.append(opt);
                    PrjNamesArray.push(data[0][i]);
                  }
      
                }
  }


      eventSource.onerror = function (error) {
        console.error('Error occurred:', error);
        eventSource.close();  // Close on error
        PopupElement.textContent='Error occured while retrieving the Project Names. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
        ShowPopUp();
      };
}
/*Get chosen value and send to flask to  get project parts*/

$(firstdropdown).on("change", function (e) { 
  console.log('clickeds')
  firstDpwnValue=firstdropdown.value;
  seconddropdown.innerHTML='';
  var op0 = document.createElement("OPTION") ;
  op0.text= 'Project Part'
  op0.value= "";
  op0.hidden=true;
  seconddropdown.add(op0);
  var ii, L = seconddropdown.options.length - 1;
  for(ii = L; ii >= 0; ii--) {
        if (seconddropdown.options[ii].value)
        seconddropdown.remove(ii);
      } 

  displayprojparts(prjids[(firstdropdown.selectedIndex)-1]);
})
var partsArrIDsonly=[]
function displayprojparts(val){
  document.getElementById("all").style.display = "block";
  console.log(val)
  $.get('/getprojectparts/'+JSON.stringify(val))
  .success(function(data){
    document.getElementById("all").style.display = "none";
    partsArrwithID= data[0];
    partsArrIDsonly= data[1];

    for (let i=0;i<data[0].length;i++)
    {
      opt=document.createElement("option");
      opt.value=data[0][i];
      opt.text=data[0][i];
      seconddropdown.append(opt);
      PrjPartsArray.push(data[0][i]);
      
    }

  })
  .error(function(jqXHR, textStatus, errorThrown) { 
          PopupElement.textContent='Error occured while retrieving the Project Parts. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
          ShowPopUp();
     });
}
$(seconddropdown).on("change", function (e) { 
    thirddropdown.innerHTML='';
    var op0 = document.createElement("OPTION") ;
    op0.text= 'Section'
    op0.value= "";
    op0.hidden=true;
    thirddropdown.add(op0);
  displayprojsections(prjids[(firstdropdown.selectedIndex)-1],partsArrIDsonly[(seconddropdown.selectedIndex)-1]);
})
function isValueNotInDropdown(dropdown, value) {
  // const dropdown = document.getElementById(dropdownId);
  const values = Array.from(dropdown.options).map(option => option.value);
  return !values.includes(value); // Check if the value is not in dropdown values
}
function displayprojsections(projectid,Partid){
  console.log(seconddropdown.selectedIndex)
  document.getElementById("all").style.display = "block";
  if (measSelect && measSelect.hasChildNodes()) { 
    while (measSelect.firstChild) {
        measSelect.removeChild(measSelect.firstChild);
    }
}

    if (relvSelect && relvSelect.hasChildNodes()) { 
          while (relvSelect.firstChild) {
            relvSelect.removeChild(relvSelect.firstChild);
          }
      }
      $.get('/getprojectsections/' + JSON.stringify([projectid, Partid]))
  .done(function(data) {
    document.getElementById("all").style.display = "none";

    for (let i = 0; i < data.length; i++) {
      let valueDoesNotExist = isValueNotInDropdown(thirddropdown, data[i]);

      if (valueDoesNotExist) {
        let opt = document.createElement("option");
        opt.value = data[i];
        opt.text = data[i];

        let isActive = false;
        for (let d = 0; d < ActiveSections.length; d++) {
          if (data[i].startsWith(ActiveSections[d])) {
            isActive = true;
            break; // Exit loop early if active
          }
        }

        if (!isActive) {
          opt.style.color = '#bdbcbc';
          opt.style.cursor = 'not-allowed';
          opt.setAttribute('disabled', true);
        }

        thirddropdown.append(opt);
        PrjSectionsArray.push(data[i]);
      }
    }
  })
  .fail(function(jqXHR, textStatus, errorThrown) { 
          PopupElement.textContent='Error occured while retrieving the Project Sections. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
          ShowPopUp();
     });

}


/*Menu bar icon mySidebar and Toggle*/
var $mySidebar = document.getElementById('mySidebar');
var $toggle = document.getElementById('toggle');
$toggle.addEventListener('click', function() {
 
  var isOpen = $mySidebar.classList.contains('slide-in');
    w3_open();
    $mySidebar.setAttribute('class', isOpen ? 'slide-out' : 'slide-in');
    $toggle.classList.toggle("change");
  

  if ($mySidebar.classList.contains('slide-out')){
    w3_close()
}

});
// if (thirddropdown.value){
  MCTNames={}
  var workerMCT = new Worker('../static/MC_T_API_Worker.js');
  // workerMCT.postMessage(thirddropdown.value)
  workerMCT.onmessage= function(event){
    console.log('refreshed')
    if (thirddropdown.value){
      sectionNumber=thirddropdown.value;
    
    MCTNames=event.data;
    MCTNames=MCTNames[sectionNumber.toString().toLowerCase()]

    }
    console.log('MCtname::',MCTNames)
   }
// }
var val=''
var worker = new Worker('../static/API_Refresh_workerJS.js');
postAPIrefreshData()
function postAPIrefreshData()
{


worker.onmessage= function(event){
  if (firstdropdown.value)
  {        
    val='firstonly'
    console.log(val)
  }  
  if ((firstdropdown.value) && (seconddropdown.value))
  {        
    val='firstSecond'
    console.log(val)
  } 

  if (val=='firstonly')
       worker.postMessage(firstdropdown.value)
  else if (val=='firstSecond') 
  {
    
    worker.postMessage([firstdropdown.value,seconddropdown.value,partsArrIDsonly[seconddropdown.selectedIndex-1]])
  }
  var data=JSON.parse(event.data);
  console.log(data)
   if (data)
   {
      if (confirm(data[0]+"\n")){
        document.getElementById('all').style.display='block';
        
        $.get('/refreshAPIAppendNewTables')
        .success(function(successData){
        if (data[1]==='project')
        {
          // console.log('projjjj')
          // displayprjnames();
          console.log(data[2])
          for (let d=0;d<data[2].length;d++)
          {
            console.log(data[2][d])
            opt=document.createElement("option");
            opt.textContent=data[2][d];
            opt.text=data[2][d];
            firstdropdown.append(opt);
            PrjNamesArray.push(data[2][d]);
          }
        }
        else if (data[1]==='part')
        {  if (firstdropdown.value)
          {
            console.log(data[2])
            for (let d=0;d<data[2].length;d++)
            {
              console.log(data[2][d])
              opt=document.createElement("option");
              opt.textContent=data[2][d];
              opt.text=data[2][d];
              seconddropdown.append(opt);
              // PrjPartsArray.push(data[2][d]);
            }
          }
        }
        else if (data[1]==='section')
        {
          if ((firstdropdown.value) && (seconddropdown.value))
            {
              console.log(data[2])
              for (let d=0;d<data[2].length;d++)
              {
                console.log(data[2][d])
                opt=document.createElement("option");
                opt.textContent=data[2][d];
                opt.text=data[2][d];
                if(!(data[2][d].startsWith('1.0')  )  && !(data[2][d].startsWith('3.2')  ) && !(data[2][d].startsWith('2.8')) && !(data[2][d].startsWith('3.3'))  && !(data[2][d].startsWith('2.1')) && !(data[i].startsWith('2.7'))) //||data[i].startsWith('2.2')))
                  {
                    opt.style.color='#bdbcbc';
                    opt.style.cursor='not-allowed';
                    opt.setAttribute('disabled',true)
                  }
                thirddropdown.append(opt);
                // PrjPartsArray.push(data[2][d]);
              }
            }
        }
      
          document.getElementById('all').style.display='none';
        })
        .error(function(jqXHR, textStatus, errorThrown) { 
        PopupElement.textContent='Error occured while retrieving projects. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
        ShowPopUp();
        });

      }
        
      else{
        worker.terminate()
      }


  }

  // }
 }



}



/*worker.onmessage= function(event){
}
*/



// var workerDropbox = new Worker('../static/DropboxWorker.js');
// workerDropbox.onmessage= function(event)
//   {
//     var dataDropbox=JSON.parse(event.data);
//   }
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
// /*Retrieve MCTNAMES Dictionary from API - Flask*/
var mctnameEmpty=false;
var sectionNumber;
function getALLMCTNAMES(){
  MCTNames={}
  document.getElementById("all").style.display = "block";
$.get( '/RetrieveMCTNames/')
  .success (function(data){
    // document.getElementById("all").style.display = "none";
    console.log(data)
    MCTNames=data;
    sectionNumber = projsec.value.split(" ")[0]; // Get first item after splitting by space
    console.log(sectionNumber);

    // Find the first key in MCTNames that starts with sectionNumber
    let matchedKey = Object.keys(MCTNames).find(key => key.toLowerCase().startsWith(sectionNumber.toLowerCase()));

    if (matchedKey) {
        console.log(matchedKey); // Found matching key
        let matchedValue = MCTNames[matchedKey]; // Store matched value without overwriting MCTNames

        console.log('MCTname::', matchedValue);

        if (matchedValue && matchedValue.length ==0) { // Ensure matchedValue exists and has length
            mctnameEmpty = true;
        } else {
            mctnameEmpty = false;
        }
    } else {
        console.log("No matching key found in MCTNames");
        mctnameEmpty = false; // Handle case where no key is found
    }

    
  })
  .error(function(jqXHR, textStatus, errorThrown) { 
        PopupElement.textContent='Error occured while retrieving the MC-T Names. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
        ShowPopUp();
      });
  // return  MCTNames
    }
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________

/****Values of MCTname rows at the end of the conssole( grouping shapes) --> legend summary ****/
document.getElementById('duplicater').childNodes[1].value=[0,0]
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
/*Tab View of User Guide*/
// document.getElementById('secondpage').addEventListener('click',function(){
//   document.getElementById('textsecondpage').removeAttribute('hidden'); 
//   document.getElementById('textfirstpage').setAttribute('hidden',true)

// });
// document.getElementById('firstpage').addEventListener('click',function(){
//   document.getElementById('textfirstpage').removeAttribute('hidden');
//   document.getElementById('textsecondpage').setAttribute('hidden',true)

// });
function w3_open() {
  document.getElementById("home").style.marginLeft = "25%";
  document.getElementById("legends").style.marginLeft = "25%";
  
  document.getElementById("home").style.transition= '0.8s';
  document.getElementById("legends").style.transition= '0.8s';

  document.getElementById("mySidebar").style.width = "25%";
  document.getElementById("mySidebar").style.display = "block";
 }
 
function w3_close() {
  document.getElementById("home").style.marginLeft = "0%";
  document.getElementById("legends").style.marginLeft = "0%";
  document.getElementById("home").style.transition= '1.5s'
  document.getElementById("legends").style.transition= '1.5s'
  document.getElementById("mySidebar").style.display = "none";
}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
/*Red Alert to fill in the first 3 dropdowns: prj name, part, section*/
document.getElementById('measureADRbutton').addEventListener('click',function(){
  if (!document.getElementsByClassName('selectionsProj')[0].value)
    document.getElementsByClassName('selectionsProj')[0].style.boxShadow='0 0 8px 2px rgb(255, 0, 0)';
  if (!document.getElementsByClassName('selectionsProjp')[0].value)
    document.getElementsByClassName('selectionsProjp')[0].style.boxShadow='0 0 8px 2px rgb(255, 0, 0)';
  if (!document.getElementsByClassName('selectionsProjs')[0].value)
    document.getElementsByClassName('selectionsProjs')[0].style.boxShadow='0 0 8px 2px rgb(255, 0, 0)';
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
if (document.getElementById('imgContainer')) {
    document.getElementById('imgContainer').innerHTML = '';
}
});

//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
/*Toggle Tab View of Home and Legend along with the Menu bar icon*/
function openTab(evt, tabname) {
  var i, tabcontent, tablinks;

 

  // Hide all tab contents
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // Remove "active" class from all tab buttons
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // Show selected tab content and mark button as active
  var tab = document.getElementById(tabname);
  if (tab) {
    tab.style.display = "block";
    tab.className += " active";
    // evt.currentTarget.className += " active";
  } else {
    console.error('Tab content with ID ' + tabname + ' not found.');
  }
}

// Start with the first tab open
document.getElementById("pagetitle").click();

// Function to add a new tab dynamically
function addIframeTab(title, url) {
  var tabId = "tab_" + Date.now(); // Unique ID for each tab

  // Create a new button in the ribbon
  var newTab = document.createElement("button");
  newTab.className = "tablinks";
  newTab.innerHTML = title + ' <i class="fa fa-times" onclick="removeTab(event, \'' + tabId + '\')"></i>';
  newTab.onclick = function (event) {
    // Delay opening the tab to ensure it has been added to the DOM
    setTimeout(function() {
      openTab(event, tabId);
    }, 10); // 10ms delay to allow DOM rendering
  };

// Dynamically create tab labels and append them to FramestabsDropdown
var tabnameDrpdwn = document.createElement("label");
  tabnameDrpdwn.className = "tabslabel";
  tabnameDrpdwn.innerHTML = title 
  // Append new tab button to the dynamicTabs container
  document.getElementById("dynamicTabs").appendChild(newTab);
  document.getElementById("FramestabsDropdown").appendChild(tabnameDrpdwn);
  tabnameDrpdwn.addEventListener('click',function(){
    openTab('click',tabId)
  })  

// Event listener for mouseover on dynamicTabs
document.getElementById("dynamicTabs").addEventListener('mouseover', function() {
  // Check and log all the labels inside FramestabsDropdown
  const labels = document.getElementById("FramestabsDropdown").children;
  if (labels.length > 0) {
    document.getElementById("FramestabsDropdown").style.display = 'block';
  }
});

document.getElementById("FramestabsDropdown").addEventListener('mouseover', function() {
  // Stay visible when hovering over the dropdown
  document.getElementById("FramestabsDropdown").style.display = 'block';
});

document.addEventListener('click', function(event) {
  const dropdown = document.getElementById("FramestabsDropdown");

  if (!dropdown.contains(event.target)) {
    dropdown.style.display = 'none';
  }
});

// Handle clicks inside iframes
document.querySelectorAll("iframe").forEach((iframe) => {
  iframe.contentWindow?.addEventListener("mousedown", function () {
    document.getElementById("FramestabsDropdown").style.display = "none";
  });
});



//FramestabsDropdown
  // Create a corresponding iframe container in the console
  var iframeContainer = document.createElement("div");
  iframeContainer.id = tabId;
  iframeContainer.className = "tabcontent";
  iframeContainer.style.display = "none"; // Initially hidden

  // Create the iframe and set its source
  var iframe = document.createElement("iframe");
  iframe.src = url;
  iframe.style.width = "100%";
  iframe.style.height = "100vh";

  iframeContainer.appendChild(iframe);

  // Append the iframe container to the consoleContent area
  document.getElementById("consoleContent").appendChild(iframeContainer);

  // Open the new tab after the content is added
  setTimeout(function() {
    newTab.click();
  }, 10); // Short delay before clicking the new tab
}

// Function to remove a tab
function removeTab(event, tabId) {
  event.stopPropagation(); // Prevent tab click event

  var tabButton = event.target.parentElement;
  var tabContent = document.getElementById(tabId);

  if (tabButton) tabButton.remove();
  if (tabContent) tabContent.remove();

  // Switch to the home tab if the removed tab was active
  document.getElementById("pagetitle").click();
}
function downloadPdf(pdfname,downloadPDFName) {
  console.log('pdfname===',pdfname)
    fetch('/get-pdf/'+JSON.stringify(pdfname))
        .then(response => response.blob())
        .then(blob => {
            const url = URL.createObjectURL(blob);
            var link = document.createElement('a');
            link.href = url;
            link.download = downloadPDFName;
            link.dispatchEvent(new MouseEvent('click'));
                    })
        .catch(error => console.error('Error fetching PDF:', error));
}


//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
/*Add icon to duplicate 'duplicater' div (big section that includes 3 dropdowns,3 textboxes, 2 buttons(add,delete)*/
  var dupliateiExtra = 0; // i 
  var clonedDivIdExtra=0;
  var originalExtra = document.getElementById('duplicaterhidden');
  var addciconvalExtra=0; //div duplicate
  var jjExtra=0;

  var dupliatei = 0; // i 
  var clonedDivId=0;
  var original = document.getElementById('duplicaterhidden');
  var addciconval=0; //div duplicate
  var jj=0;

  const vals = [];
  var canvasimg;
  var ry = [[]];
  var section = document.getElementsByClassName("selectionsProjs")[0]
  function duplicate() {
    /*Create array of addciconval w jj */

      addciconval+=1;
      jj=0;
      var clone = original.cloneNode(true); // "deep" clone
      console.log('clonee',clone.children)
      clone.id = 'duplicater' + ++dupliatei;
      clonedDivId=clone.id;
      clone.children[0].value=[addciconval,jj]
      clone.children[5].style.marginLeft='5px';
      // clone.children[1].style.marginBottom='10px';
      clone.children[5].children[4].id='addmctnameid'+dupliatei
      clone.children[5].children[6].style.display='none'
      clone.children[5].style.marginTop='8px';
console.log('ayhaga', clone.children[5])
      clone.removeAttribute("hidden");
      clone.setAttribute('class','duplicaterclass'+dupliatei);
      clone.getElementsByClassName('measurementselections')[0].setAttribute('name', 'measurementscripts'+dupliatei);
      clone.getElementsByClassName('measurementselections')[0].setAttribute('class', 'measurementselections'+dupliatei);
      clone.getElementsByClassName('measureitems')[0].setAttribute('name', 'measureitem'+dupliatei);
      clone.getElementsByClassName('measureitems')[0].setAttribute('class', 'measureitems'+dupliatei);
      clone.getElementsByClassName('selections')[0].setAttribute('name', 'select'+dupliatei);
      clone.getElementsByClassName('selections')[0].setAttribute('class', 'selections'+dupliatei);
      clone.getElementsByClassName('repeatforloopclasshidden')[0].setAttribute('id', 'repeatforloop'+addciconval+'0');
      clone.getElementsByClassName('repeatforloopclasshidden')[0].setAttribute('name', 'repeatforloopname'+addciconval+'0');
      clone.getElementsByClassName('repeatforloopclasshidden')[0].setAttribute('class', 'repeatforloopclass'+addciconval+'0');
      if (thirddropdown.value.startsWith('3.2') || thirddropdown.value.startsWith('3.3'))
             { 

              clone.children[5].children[1].setAttribute('disabled','True')
              clone.children[5].children[2].setAttribute('disabled','True')

              clone.children[5].children [1].style.cursor='not-allowed';
              clone.children[5].children[2].style.cursor='not-allowed';

              // document.getElementById('duplicater' + dupliatei).children[8].children[1].style.cursor='not-allowed';
              // document.getElementById('duplicater' + dupliatei).children[8].children[2].style.cursor='not-allowed';

             }
      
      original.parentNode.appendChild(clone);
      clone.parentElement.insertBefore(clone, document.getElementById('doneebackground')); 
  
      /*Based on the NRM section , populate the second part of the interface*/
      if (addciconval>0){
      var inputs1 = document.getElementsByClassName("measurementselections"+dupliatei)[0];  //1sr dpdwn
      var selections1 = document.getElementsByClassName("selections"+dupliatei)[0]; //2nd dropdown
      var measitem1 = document.getElementsByClassName("measureitems"+dupliatei)[0];  //3rd dpdwn

    $(inputs1).select2({
      placeholder:'Select',
      closeOnSelect: true,
      width:'15ch'
   
    });
    $(selections1).select2({
      placeholder:'Select MC-T Name',
      closeOnSelect: true,
      width:'23ch'
    });
    $(measitem1).select2({
      placeholder:'Select unit',
      closeOnSelect: true,
      width:'11ch'
    });
    $(inputs1).on("change", function (e) { 
      get3rddropdown();
    });
    $(selections1).on("change", function (e) { 
      get3rddropdown();
    })

        if (section.value.startsWith('1.0'))
          {
          var opt = document.createElement("OPTION");
          opt.text= 'Select';
          opt.value= "";
          opt.hidden=true;
          inputs1.add(opt);
          var optn = document.createElement("OPTION");
          optn.text= 'Ground Beams';
          optn.value= "ground beams";
          inputs1.add(optn);
          var optn1 = document.createElement("OPTION");
          optn1.text= 'Pile Caps';
          optn1.value= "pile caps";
          inputs1.add(optn1);
          }
        if (section.value.startsWith('3.2'))
          {
          var opt = document.createElement("OPTION");
          opt.text= 'Select';
          opt.value= "";
          opt.hidden=true;
          inputs1.add(opt);

          var optn = document.createElement("OPTION");
          optn.text= 'Floor';
          optn.value= "Floor";
          inputs1.add(optn);

          var optn1 = document.createElement("OPTION");
          optn1.text= 'Wall';
          optn1.value= "Wall";
          inputs1.add(optn1);

          var optn2 = document.createElement("OPTION");
          optn2.text= 'Internal Doors';
          optn2.value= "Internal Doors";
          inputs1.add(optn2);
          }
          
        if (section.value.startsWith('2.7'))
          {
          var opt = document.createElement("OPTION");
          opt.text= 'Select';
          opt.value= "";
          opt.hidden=true;
          inputs1.add(opt);

          var optn = document.createElement("OPTION");
          optn.text= 'Internal Walls';
          optn.value= "Internal Walls";
          inputs1.add(optn);

          }
        if (section.value.startsWith('2.8'))
          { 
          var opt = document.createElement("OPTION");
          opt.text= 'Select';
          opt.value= "";
          opt.hidden=true;
          inputs1.add(opt);

          var optn = document.createElement("OPTION");
          optn.text= 'Single Door';
          optn.value= "Single Door";
          inputs1.add(optn);

          var optn1 = document.createElement("OPTION");
          optn1.text= 'Double Door';
          optn1.value= "Double Door";
          inputs1.add(optn1);

          }
          if (section.value.startsWith('2.1'))
          { 
          var opt = document.createElement("OPTION");
          opt.text= 'Select';
          opt.value= "";
          opt.hidden=true;
          inputs1.add(opt);

          var optn = document.createElement("OPTION");
          optn.text= 'Column';
          optn.value= "Column";
          inputs1.add(optn);

          var optn1 = document.createElement("OPTION");
          optn1.text= 'Wall';
          optn1.value= "Wall";
          inputs1.add(optn1);

          }
        }


  }
  function userguidetoggleFunction() { 
    var dropdownContentUserguideId = document.getElementById("dropdown-contentUserguideId");
    var UserGuideSideBar = document.getElementById('UserGuideSideBar');
    var UserGuidetoggle = document.getElementById('UserGuidetoggle');

    var isOpen = UserGuideSideBar.style.display === "block";

    // **Close the dropdown when opening User Guide**
    dropdownContentUserguideId.classList.remove("active");

    // **Toggle the sidebar visibility properly**
    if (isOpen) {
        UserGuideSideBar.style.display = "none";
        UserGuideSideBar.classList.remove('UserGuideslide-in');
        UserGuideSideBar.classList.add('UserGuideslide-out');
        UserGuidetoggle.classList.remove("change");
    } else {
        UserGuideSideBar.style.display = "block";
        UserGuideSideBar.style.width = "25%";
        UserGuideSideBar.classList.add('UserGuideslide-in');
        UserGuideSideBar.classList.remove('UserGuideslide-out');
        UserGuidetoggle.classList.add("change");
    }
}

function ShowSectionUserguide(element) {
    var textFirstPage = document.getElementById('textfirstpage');
    var UserGuideSideBar = document.getElementById('UserGuideSideBar');
    var UserGuidetoggle = document.getElementById('UserGuidetoggle');
    var isOpen = UserGuideSideBar.style.display === "block";



    // **If clicking home and already on home, only toggle icon**
    if (element.id === 'homeguidebutton' || element.parentElement?.id === 'homeguidebutton') {
        if (textFirstPage.style.display === 'block') {
            return; // Exit function to prevent further toggling
        }
        hideAllSections();
        textFirstPage.style.display = 'block';
        return;
    } 

    // **If clicking a section, hide sidebar and update content**
    if (element.tagName === 'LI') {
        hideAllSections();
                // **Toggle the sidebar visibility properly**
      if (isOpen) {
            UserGuideSideBar.style.display = "none";
            UserGuideSideBar.classList.remove('UserGuideslide-in');
            UserGuideSideBar.classList.add('UserGuideslide-out');
            UserGuidetoggle.classList.remove("change");
        } else {
            UserGuideSideBar.style.display = "block";
            UserGuideSideBar.style.width = "25%";
            UserGuideSideBar.classList.add('UserGuideslide-in');
            UserGuideSideBar.classList.remove('UserGuideslide-out');
            UserGuidetoggle.classList.add("change");
        }

        if (element.textContent.startsWith('1.0')) {
            document.getElementById('1_0textUserGuide').style.display = 'block';
            document.getElementById('1_0textUserGuide').removeAttribute('hidden');

        } 
        else if (element.textContent.startsWith('2.1')) {
            document.getElementById('2_1textUserGuide').style.display = 'block';
            document.getElementById('2_1textUserGuide').removeAttribute('hidden');
        } 
        else if (element.textContent.startsWith('2.7')) {
            document.getElementById('2_7textUserGuide').style.display = 'block';
            document.getElementById('2_7textUserGuide').removeAttribute('hidden');
        } 
        else if (element.textContent.startsWith('2.8')) {
            document.getElementById('2_8textUserGuide').style.display = 'block';
            document.getElementById('2_8textUserGuide').removeAttribute('hidden');
        } 
        else if (element.textContent.startsWith('3.2')) {
            document.getElementById('3_2textUserGuide').style.display = 'block';
            document.getElementById('3_2textUserGuide').removeAttribute('hidden');
        } 
        else if (element.textContent.startsWith('3.3')) {
            document.getElementById('3_3textUserGuide').style.display = 'block';
            document.getElementById('3_3textUserGuide').removeAttribute('hidden');
        }
    }
}

// Function to hide all sections before showing the selected one
function hideAllSections() {
    document.getElementById('textfirstpage').style.display = 'none';
    document.getElementById('1_0textUserGuide').style.display = 'none';
    document.getElementById('2_1textUserGuide').style.display = 'none';
    document.getElementById('2_7textUserGuide').style.display = 'none';
    document.getElementById('2_8textUserGuide').style.display = 'none';
    document.getElementById('3_2textUserGuide').style.display = 'none';
    document.getElementById('3_3textUserGuide').style.display = 'none';
}

//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
/*User Guide button toggle*/
function userguideclick(){
  document.getElementById('textfirstpage').style.display='block'
  var acc = document.getElementsByClassName("dropdown-content")[0];
  var userguideClose=document.getElementById("userguideClose")
  var i;
  acc.classList.toggle("active");

  /* Toggle between hiding and showing the active panel */
  if (acc.style.display === "block") {
    acc.style.display = "none";

  } else {
    acc.style.display = "block";
    acc.style.backgroundColor=(0, 153, 255); 
  }

  close.onclick = function() {
    acc.style.display = "none";
};

}
function userguideMayaTableClick(){
    var userguideTableMaya=document.getElementById('userguideTableMaya')    
    window.open('https://docs.google.com/spreadsheets/d/10TjB8EbSiDHybo9YsDDzekxi8iQECpprXdqptHCZzec/edit?gid=875423041#gid=875423041');

}

//to be retrieved from python code
var areainpixels=0;
var prminpixels=0;

//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
/*Populate dropdowns*/

//get the 3 dropdown elements
  var proj = document.getElementsByClassName("selectionsProj")[0];
  var proj1 = document.getElementsByClassName("selectionsProjp")[0];
  var projsec = document.getElementsByClassName("selectionsProjs")[0];
  var pdfname;

projsec.addEventListener('input',function(){
    projsec.style.boxShadow=( '2px 2px 2px gray')
  })

var ratioAunit=1;
var ratioPunit=1;
var pdfnames='';

//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
function getSelectValues(select) {
  var result = [];
  var options = select && select.options;
  var opt;

  for (var i=0, iLen=options.length; i<iLen; i++) {
    opt = options[i];
    

    if (opt.selected) {
      result.push(opt.value || opt.text);
    }
  }
  console.log('selectedddddd',result)
  return result;
}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________

  //Retrieves list of projects  
var doorSchedulePDF;
  function getproj(){
    getALLMCTNAMES();
    
    var proj = document.getElementsByClassName("selectionsProj")[0];
    var projectVal=proj.value.toString() //selected project
    
    var inputs = document.getElementsByTagName("select")[1]; //second dropdown(project part)
    var p=document.getElementById("selectionsProjpid") //project part
    
    var sections = document.getElementsByClassName("selectionsProjs")[0];
    chooseFirstdrpdwn();
    var eventSource = new EventSource('/getmethod/' + JSON.stringify(projectVal));
    document.getElementById('progressBar').removeAttribute('hidden')
    document.getElementById('progressBar').style.display='block';
    eventSource.onmessage = function (event) {
              var progress = parseInt(event.data);  // Progress value from Flask
              if (progress <= 100) {
                  console.log(progress);  // Log progress for debugging
                  document.getElementById('progress').style.width = progress + '%';
                  document.getElementById('progress').textContent = progress + '%';
              } else {
                  // Final data handling when progress reaches 100%
                  console.log('Process completed!');
                  
                  // Parse and handle the final response data (documentsToMeasure, RelevantDocuments, extracted_path)
                  var data = JSON.parse(event.data);  // Assuming the result is a JSON array
                  console.log('Final result:', data);
                  // You can use this data to update your page or handle it accordingly

                  eventSource.close();  // Close the connection when finished
                  document.getElementById('progressBar').setAttribute('hidden',true)
                  document.getElementById('progressBar').style.display='none';
                  document.getElementById('progress').style.width = '0%'; // Reset progress for the next process
                  document.getElementById('progress').textContent = '0%';


                  document.getElementById('refreshDropboxButtonID').style.display = "block";
                  document.getElementById("all").style.display = "none";
                  if (sections.value.startsWith('3.2') || sections.value.startsWith('3.3') || sections.value.startsWith('2.7') ){
                    document.getElementById('dxfdiv').removeAttribute('hidden'); 
                    document.getElementById('pdftodxfFile').setAttribute('required',true)
                  }

                  else{
                    document.getElementById('dxfdiv').setAttribute('hidden',true)
                  }

                    extracted_path=data[2]
                    var docsToMeasure=data[0]; //
                    var relvDocs=data[1]
                    var projname = document.getElementsByClassName("selectionsProj")[0];
                    var projpart = document.getElementsByClassName("selectionsProjp")[0];
                    var projsec = document.getElementsByClassName("selectionsProjs")[0];

                    var meas = document.getElementById("measureCheckbox") ;
                    var relv = document.getElementById("relvdiv") ; 
                    const measids=[];
                    const relvids=[];
                    const measoptns=[];

                    // var measSelect = document.getElementById("measureselectid");
                    var measSelect = document.getElementById("measureContainer");

                    var relvSelect = document.getElementById("relvselectid");
                    var levelcheckbox=  document.getElementById("levelcheckbox");
                  
                    
                    measSelect.removeAttribute("hidden");
                    relvSelect.removeAttribute("hidden");
                    if (measSelect && measSelect.hasChildNodes()) { 
                        while (measSelect.firstChild) {
                            measSelect.removeChild(measSelect.firstChild);
                        }
                    }

                    var optn2 = document.createElement("div"); // Use a <div> instead of <option>
                    optn2.textContent = 'Select project to measure'; // Set text content
                    optn2.hidden = true; // Keep it hidden
                    optn2.id = 'hidden';

                    measSelect.appendChild(optn2); // Append to div instead of .add()
                    document.getElementById("hidden").required = true;
                
                    
                  if (relvSelect && relvSelect.hasChildNodes()) { 
                        while (relvSelect.firstChild) {
                          relvSelect.removeChild(relvSelect.firstChild);
                        }
                    }
                  const nameSet = new Set(); // To track unique names
                  const nameSetRelv = new Set(); // To track unique names

                // Action foconst nameSet = new Set(); // To track unique names

              // Action for when the checkbox is clicked
              function handleCheckboxChange(event) {
                // Uncheck all checkboxes before checking the current one
                document.querySelectorAll('input[name="measureCheckbox"]').forEach(checkbox => {
                  checkbox.checked = false;
                });

                // Check the current checkbox
                event.target.checked = true;

                // Action when checkbox is clicked (e.g., log the selected project)
                let selectedValue = event.target.value;
                console.log("Selected project:", selectedValue);

                // Highlight the selected item
                document.querySelectorAll(".measure-item").forEach(item => {
                  item.style.backgroundColor = ''; // Reset background color for all items
                });
                event.target.closest(".measure-item").style.backgroundColor = '#d3f8d3'; // Highlight the selected item



                  // Show alert immediately to prompt the user
                  if (projsec.value.startsWith('3.2') || projsec.value.startsWith('3.3') || projsec.value.startsWith('2.7')) {
                      // downloadPdf(selectedValue);
                      downloadPdf(selectedValue,'DXF_File_:'+selectedValue)
                      // window.alert("Measure the purple shape drawn on the PDF using Foxit Reader, Bluebeam, or any other external tool, then enter its area and perimeter in your desired scale.");
                  }
                  // else{
                  //   window.alert("Measure the purple shape drawn on the PDF using Foxit Reader, Bluebeam, or any other external tool, then enter its area and perimeter in your desired scale.");
                  // }
                  canvasimg='';
                  ry=[[]];
                  levelcheckbox.checked=false;
                  pdfname=selectedValue;
                  measSelect.style.boxShadow='none';

                  
                  document.getElementById("all").style.display = "block";

                  pixelArr=[projname.value, projpart.value,projsec.value, pdfname]
                // Open popup immediately before initiating the PDF download
                var eventSource = new EventSource('/pixelimg/' + JSON.stringify(pixelArr));
                document.getElementById('progressBar').removeAttribute('hidden')
                document.getElementById('progressBar').style.display='block';
                eventSource.onmessage = function (event) {
                          var progress = parseInt(event.data);  // Progress value from Flask
                          if (progress <= 100) {
                              console.log(progress);  // Log progress for debugging
                              document.getElementById('progress').style.width = progress + '%';
                              document.getElementById('progress').textContent = progress + '%';
                          } else {
                              // Final data handling when progress reaches 100%
                              console.log('Process completed!');
                              
                              // Parse and handle the final response data (documentsToMeasure, RelevantDocuments, extracted_path)
                              var data = JSON.parse(event.data);  // Assuming the result is a JSON array
                              console.log('Final result:', data);
                              // You can use this data to update your page or handle it accordingly

                              eventSource.close();  // Close the connection when finished

                          document.getElementById('progressBar').setAttribute('hidden',true)
                          document.getElementById('progressBar').style.display='none';
                          document.getElementById('progress').style.width = '0%'; // Reset progress for the next process
                          document.getElementById('progress').textContent = '0%';
                          document.getElementById("all").style.display = "none";
                              // Display link or any additional data if needed
                              window.open(data[2]);
                              downloadPdf(pdfname,'Pixel_Conversion_File_:'+pdfname)
                                  document.getElementById("all").style.display = "none";
                                
                                  document.getElementById('measureADRbutton').onclick= function()
                                  {
                                    if (!areaRatio.value){
                                      if (!(projsec.value.startsWith('3.2')) & !(projsec.value.startsWith('2.8')) & !(projsec.value.startsWith('3.3')) & !(projsec.value.startsWith('2.7')) )
                                          areaRatio.style.boxShadow='0 0 8px 2px rgb(255, 0, 0)';
                                    }
                                    if (!prmRatio.value)
                                    {
                                      if (!(projsec.value.startsWith('2.8')))
                                            prmRatio.style.boxShadow='0 0 8px 2px rgb(255, 0, 0)';
                                    }

                                  }
                                  document.getElementById('radiosColors').removeAttribute('hidden');
                                  var scalelbl= document.createElement("label");
                                  scalelbl.innerText='Scale Document';
                                  scalelbl.id='measureLabel';
                                  var br1=  document.createElement("br");
                                  var areadiv=document.createElement("div");
                                  areadiv.id='areadiv'
                                  var areaRatiolbl= document.createElement("label");
                                  areaRatiolbl.innerText='Area:'
                                  areaRatiolbl.id='radiolbl';
                    
                                  var areaRatio= document.createElement("input");
                                  areaRatio.type='number';
                                  areaRatio.id='arealvlinput';
                                  areaRatio.className='lvlinput';
                                  areaRatio.name='areaRatio';
                                  areaRatio.style.marginLeft='78px';
                                  areaRatio.style.textAlign='right';
                                  areaRatio.step=".0000001";
                                  areaRatio.min = "0"; // Allow only positive numbers (>= 0)
                                  if( projsec.value.startsWith('3.2') || projsec.value.startsWith('3.3') || projsec.value.startsWith('2.1') || projsec.value.startsWith('2.7')){ 
                                    areaRatio.setAttribute('disabled',true)
                                    areaRatio.style.cursor='not-allowed';
                                    areaRatio.style.backgroundColor='rgba(101, 101, 101, 0.27)'
                                    document.getElementById('selectunitA').setAttribute('disabled',true)
                                    document.getElementById('selectunitA').style.cursor='not-allowed';
                                    document.getElementById('selectunitA').style.backgroundColor='rgba(101, 101, 101, 0.27)'
                                  }

                                  else{ // section 1.0
                                    areaRatio.removeAttribute('disabled')
                                    areaRatio.style.cursor='pointer';
                                    document.getElementById('selectunitA').removeAttribute('disabled')
                                    document.getElementById('selectunitA').style.cursor='pointer';
                                  }
                                  areaRatio.addEventListener('change',function(){
                                    areaRatio.value=(Number(areaRatio.value)).toFixed(7)
                                    areaRatio.style.boxShadow='none';
                                  })
                                  areaRatio.required=true;
                                  selectunitA=document.getElementById('selectunitA')
                                  selectunitA.removeAttribute('hidden')
                                  
                                  areadiv.append(areaRatiolbl,areaRatio,selectunitA)
                                  var br2=  document.createElement("br");
                                  var br3=  document.createElement("br");
                                  var prmdiv=document.createElement("div");
                                  prmdiv.id='prmdiv'
                                  var prmRatiolbl= document.createElement("label");
                                  prmRatiolbl.innerText='Perimeter:'
                                  prmRatiolbl.id='radiolbl';

                                  var prmRatio= document.createElement("input");
                                  prmRatio.type='number';
                                  prmRatio.id='perimlvlinput';
                                  prmRatio.className='lvlinput';
                                  prmRatio.name='prmRatio';
                                  prmRatio.style.textAlign='right';
                                  prmRatio.style.marginLeft='49px';
                                  prmRatio.step=".0000001";
                                  prmRatio.min = "0"; // Allow only positive numbers (>= 0)
                                  prmRatio.addEventListener('change',function(){
                                    prmRatio.value=(Number(prmRatio.value)).toFixed(7)
                                    prmRatio.style.boxShadow='none';
                                  })
                                  prmRatio.required=true;
                                  selectunitP=document.getElementById('selectunitP')
                                  selectunitP.removeAttribute('hidden')

                                  prmdiv.append(prmRatiolbl, prmRatio,selectunitP)
                                  var ratiosdiv= document.getElementById("ratios");
                                  ratiosdiv.innerHTML='';
                                  ratiosdiv.append(scalelbl);
                                  ratiosdiv.append(br1);
                                  ratiosdiv.append(areadiv)
                                  ratiosdiv.append(prmdiv)
                                  areainpixels=data[0];
                                  prminpixels=data[1];   


                                  if( projsec.value.startsWith('2.8')) {
                                    areaRatio.setAttribute('disabled',true)
                                    areaRatio.style.cursor='not-allowed';
                                    areaRatio.style.backgroundColor='rgba(101, 101, 101, 0.27)'
                                    document.getElementById('selectunitA').setAttribute('disabled',true)
                                    document.getElementById('selectunitA').style.cursor='not-allowed';
                                    document.getElementById('selectunitA').style.backgroundColor='rgba(101, 101, 101, 0.27)'

                                    prmRatio.setAttribute('disabled',true)
                                    prmRatio.style.cursor='not-allowed';
                                    prmRatio.style.backgroundColor='rgba(101, 101, 101, 0.27)'
                                    document.getElementById('selectunitP').setAttribute('disabled',true)
                                    document.getElementById('selectunitP').style.cursor='not-allowed';
                                    document.getElementById('selectunitP').style.backgroundColor='rgba(101, 101, 101, 0.27)'
                                  }
                        };
                      }


                      eventSource.onerror = function (error) {
                        console.error('Error occurred:', error);
                        eventSource.close();  // Close on error
                        PopupElement.textContent='Error occured while uploading the pdf to the Dropbox. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
                        ShowPopUp();
                      };

                                selectunitA.addEventListener('change',function(){
                                  value=document.getElementById('selectunitA').value
                                  if (value=='mm2')
                                    ratioAunit=1000000;
                                  else
                                    ratioAunit=1;
                                })
                                selectunitP.addEventListener('change',function(){
                                  value=document.getElementById('selectunitP').value
                                  if (value=='mm'){
                                    ratioPunit=1000;
                                  }
                                  else
                                    ratioPunit=1;

                                })     
                              // }
                              // for 2.8 multiple pdfs
                              // else{
                              //   pdfnames=getSelectValues(elem)
                              // }
              } 

              // Action for when the label is clicked (no checkbox change)
              function handleLabelClick(event) {
                // Action when label is clicked (e.g., log the selected project via the label)
                let selectedLabel = event.target.textContent;
                console.log("Label clicked: ", selectedLabel);
                // Optional: Highlight the selected item
                document.querySelectorAll(".measure-item").forEach(item => {
                  item.style.backgroundColor = ''; // Reset background color for all items
                });
                // event.target.closest(".measure-item").style.backgroundColor = '#919592'; // Highlight the selected item
                    // Show loading indicator
                  document.getElementById("all").style.display = "block";
                  fetch('/getdropboxurl/'+ JSON.stringify(selectedLabel), {

                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        body: JSON.stringify({ filename: "your_pdf_filename_here.pdf" })
                      })
                      .then(response => response.blob())
                      .then(blob => {
                        document.getElementById("all").style.display = "none";
                        const url = URL.createObjectURL(blob);
                            // Set the URL to the iframe's src to load the content inside the page
                            addIframeTab(selectedLabel,url);
                            // addIframeTab("Google", "https://www.google.com");
                      })
                      .catch(function(jqXHR, textStatus, errorThrown) {
                            // Handle error
                            PopupElement.textContent = 'Error occurred while retrieving the dropbox URL. Refresh and try again. If the error continues, please contact the ADR team to fix it.';
                            ShowPopUp();
                          });
              }

              for (let i = 0; i < docsToMeasure.length; i++) {
                let name = docsToMeasure[i][0];

                // Create div for the measure item
                let div = document.createElement("div");
                div.className = "measure-item";

                // Create the checkbox
                let checkbox = document.createElement("input");
                checkbox.type = "checkbox";
                checkbox.name = "measureCheckbox";
                checkbox.value = name;
                checkbox.onclick = handleCheckboxChange; // Handle checkbox click

                // Create the label
                let label = document.createElement("label");
                label.textContent = name;
                label.onclick = handleLabelClick; // Handle label click

                // Append checkbox and label to the div
                div.appendChild(checkbox);
                div.appendChild(label);

                // Append the item to the select container
                measSelect.appendChild(div);
                    // Check for duplicates
                if (nameSet.has(name)) {
                    label.style.color = "red"; // Highlight duplicate (optional)
                    
                    document.getElementById("TopTextModal").textContent='Error: Duplicates Error'
                    PopupElement.textContent = 'Duplicate project names were detected while retrieving the project PDFs. Please visit Dropbox and rename the relevant files that you will be working on to ensure each project has a unique name. Once the renaming is complete, return to the console and click on the Dropbox icon to retrieve the updated project names.';
                    ShowPopUp();
                } else {
                    nameSet.add(name); // Add unique name to the set
                }
              }



              for (let i = 0; i < relvDocs.length; i++) {
                let name = relvDocs[i][0];

                // Create div for the measure item
                let div = document.createElement("div");
                div.className = "relv-item";  //relvselectid .relv-item
                // Create the label
                let label = document.createElement("label");
                label.textContent = name;
                label.onclick= function(event) 
                  {
                          // Action when label is clicked (e.g., log the selected project via the label)
                    let relevantDocumentName = event.target.textContent;
                    console.log("Label clicked: ", relevantDocumentName);
                    if (projsec.value.startsWith('2.8')){
                      doorSchedulePDF=relevantDocumentName
                      console.log(doorSchedulePDF)
                    }
                    // Optional: Highlight the selected item
                    document.querySelectorAll(".relv-item").forEach(item => {
                      item.style.backgroundColor = ''; // Reset background color for all items

                    });
                    event.target.closest(".relv-item").style.backgroundColor ='#d3f8d3'; // Highlight the selected item
                    document.getElementById('relvselectid').style.boxShadow='';
                  };


                div.appendChild(label);

                // Append the item to the select container
                relvSelect.appendChild(div);
                // Handle duplicate names
                if (nameSetRelv.has(name)) {
                  label.style.color = "red"; // Highlight duplicate (optional)
                } else {
                  nameSetRelv.add(name);
                }
              }

                  relvids.push(relvSelect) ;
                  measids.push(measSelect);

              document.addEventListener("click", function(event) {
                const iframe = document.getElementById("pdfFrame");
                if (!iframe.contains(event.target)) {
                  const iframe = document.getElementById("pdfFrame");
                  iframe.style.display = "none";
                }
              });
                  document.getElementById('measureADRbutton').onclick= function()
                  {
                    if (!measSelect.value) {
                        measSelect.style.boxShadow = '0 0 8px 2px rgb(255, 0, 0)';
                        measSelect.setAttribute("required", "")
                    }

                    if (!relvSelect.value) {
                        if (sectionNumber.startsWith('2.8')) {
                          relvSelect.style.boxShadow = '0 0 8px 2px rgb(255, 0, 0)';
                            relvSelect.setAttribute("required", "")
                        }
                    }


                  }

              }


              if (document.getElementById('arealvlinput')){
                if( projsec.value.startsWith('3.2') || projsec.value.startsWith('2.8') || projsec.value.startsWith('3.3')  || projsec.value.startsWith('2.1')  || projsec.value.startsWith('2.7')){
                    document.getElementById('arealvlinput').setAttribute('disabled',true)
                    document.getElementById('selectunitA').setAttribute('disabled',true)
                  }
                else{ // section 1.0
                  document.getElementById('arealvlinput').removeAttribute('disabled')
                  document.getElementById('selectunitA').removeAttribute('disabled')
                }
              }

          };

          eventSource.onerror = function (error) {
          console.error('Error occurred:', error);
          eventSource.close();  // Close on error
          PopupElement.textContent='Error occured while retrieving the Project Names. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
          ShowPopUp();
          };

}  
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________

function ImgLarger(id, src){
// Get the modal
    var modal = document.getElementById('myModal');

    // Get the image and insert it inside the modal - use its "alt" text as a caption
    var img = document.getElementById(id);
    var modalImg = document.getElementById('img01');
    var captionText = document.getElementById("caption");
        modal.style.display = "block";
        modalImg.src = src;
        captionText.innerHTML = 'Preview';


    // Get the <span> element that closes the modal
    var span = document.getElementsByClassName("close")[0];

    // When the user clicks on <span> (x), close the modal
    span.onclick = function() { 
        modal.style.display = "none";
    }
}

var spreadsheetId='';
var spreadsheetURL='';
var colorsUsed='';
var list1='';
var SimilarAreaDictionary='';
var tomeasureproj=''
var pdfpath=[];
var interval = null;
var namepathArr=''

var allcolors=['#2FFFFF'];
// Main Function - form submit 
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
document.getElementById('pdftodxfFile').addEventListener('input',function(){
  console.log('hghjk')
  const files = document.getElementById("pdftodxfFile");
   dxffile=files.files[0];
  console.log(dxffile)
});
function ImgSide(imgdata, spreadsheetLink, pdfLink) {
    var backimg = document.getElementById('backgroundimg');
    backimg.innerHTML=''
    
    // Create a container for the image and buttons
    var imgContainer = document.createElement('div');
    imgContainer.className = 'imgContainer';
    
    var imgcanvas = document.createElement("img");
    imgcanvas.src = 'data:image/gif;base64,' + imgdata;
    imgcanvas.height = 600;
    imgcanvas.id = 'imgcanvas';
    imgcanvas.alt = "Larry";
    imgcanvas.style.zIndex = 999;

    imgcanvas.addEventListener('click', function () {
        ImgLarger(imgcanvas.id, imgcanvas.src);
    });

    var buttonContainer = document.createElement('div');
    buttonContainer.style.display = 'flex';
    buttonContainer.style.marginTop = '10px';
///////////////////////////////////////////////////////////////
    var legendbutton = document.createElement("button");
    legendbutton.className = 'measureADRbutton2';
    legendbutton.innerText = 'Legend and Data created';
    legendbutton.style.backgroundColor = 'rgb(5, 43, 235)';


    
    if ( projsec.value.startsWith('2.8')){
      legendbutton.setAttribute('disabled',true);
      legendbutton.style.cursor='not-allowed';
      legendbutton.style.boxShadow = 'none';
      legendbutton.style.color = 'white';
      legendbutton.style.backgroundColor="rgb(154,152,152)";
    }
    else{
    legendbutton.addEventListener('mouseover', function () {
        legendbutton.style.boxShadow = '0 0 8px 2px rgb(5, 43, 235)';
    });
    legendbutton.addEventListener('mouseout', function () {
        legendbutton.style.boxShadow = 'none';
    });



      legendbutton.addEventListener('click', function () {
        window.open(spreadsheetLink);
    });
    }
//////////////////////////////////////////////////////////////
    var imgbutton = document.createElement("button");
    imgbutton.className = 'measureADRbutton2';
    imgbutton.innerText = 'Click to view as PDF';
    imgbutton.id='clickpdfurldp'
    imgbutton.style.backgroundColor = 'rgb(255,0,255)';

    imgbutton.addEventListener('mouseover', function () {
        imgbutton.style.boxShadow = '0 0 8px 2px rgb(255,0,255)';
    });
    imgbutton.addEventListener('mouseout', function () {
        imgbutton.style.boxShadow = 'none';
    });

    imgbutton.addEventListener('click', function () {
        window.open(pdfLink);
    });
/////////////////////////////////////////////////////////////
  var refreshpdfmarkups = document.createElement("button");
  refreshpdfmarkups.className = 'measureADRbutton2';
  refreshpdfmarkups.id='refreshpdfmarkups'
  refreshpdfmarkups.style.backgroundColor = 'rgb(255,80,255)';
  refreshpdfmarkups.style.padding = '10px 20px';

    // Create the icon element
    const icon = document.createElement('i');
    icon.className = 'fa fa-refresh'; // Add Font Awesome classes
    icon.setAttribute('aria-hidden', 'true'); // Add accessibility attribute

    // Set button text and append the icon
    // refreshpdfmarkups.textContent = ' Refresh';
    refreshpdfmarkups.prepend(icon); // Add icon before the text

  refreshpdfmarkups.addEventListener('mouseover', function () {
    refreshpdfmarkups.style.boxShadow = '0 0 8px 2px rgb(255,80,255)';
    });
    refreshpdfmarkups.addEventListener('mouseout', function () {
      refreshpdfmarkups.style.boxShadow = 'none';
    });

////////////////////////////////////////////////////////////
    buttonContainer.appendChild(legendbutton);
    buttonContainer.appendChild(imgbutton);
    buttonContainer.appendChild(refreshpdfmarkups);


    imgContainer.appendChild(imgcanvas);
    imgContainer.appendChild(buttonContainer);

    backimg.appendChild(imgContainer);
} 
function updatepreview(pdfname){
 console.log('pdfpath',pdfname)
   
    $.get( '/updatepreviewimg/'+ JSON.stringify(pdfname))
    .success( function(data) {
      document.getElementById("loading").hidden = true;
      ImgSide(data,spreadsheetURL,dropboxLink)
    
    })  
} 



// Function to update dropdown options
function updateDropdown(options) {
    const dropdowns = document.getElementsByName('text1name');

    dropdowns.forEach((dropdown) => {
        // Save the currently selected value
        const selectedValue = dropdown.value;

        // Clear the dropdown
        dropdown.innerHTML = '';

        // Repopulate with new options
        options.forEach((value) => {
            const option = document.createElement('option');
            option.value = value;
            option.textContent = value;
            dropdown.appendChild(option);
        });

        // Restore the previously selected value if it still exists
        if (options.includes(selectedValue)) {
            dropdown.value = selectedValue;
        }
    });
}

// Function to start the worker and periodic updates
function startDropdownUpdates() {
    const guessedNamesWorker = new Worker('../static/guessedNamesWorker.js');
    // Handle messages from the worker
    guessedNamesWorker.onmessage = function (event) {
        if (event.data.status === 'success') {
            console.log('Updating dropdown with new data:', event.data.data);
            updateDropdown(event.data.data); // Update the dropdown
        } else {
            console.error('Error from worker:', event.data.error);
        }
    };

    // Send an initial fetch message to the worker
    guessedNamesWorker.postMessage('fetch');

    // Periodically fetch data every 3 seconds
    setInterval(() => {
        guessedNamesWorker.postMessage('fetch');
    }, 3000);
}




function getData(form) {

  document.getElementById("loading").hidden = false;

  document.getElementById('measureADRbutton').setAttribute('disabled',true);
  document.getElementById('measureADRbutton').style.cursor='not-allowed';
  document.getElementById('measureADRbutton').style.boxShadow = 'none';
  document.getElementById('measureADRbutton').style.color = 'white';
  document.getElementById('measureADRbutton').style.backgroundColor="rgb(154,152,152)";


  var formData = new FormData(form);
  
  clearInterval(interval)
  val=0;
  answers=[];
  var ratio1=0;
  var ratio2=0;
  tomeasureproj='';
  pdfpath=[];
  formvalues=Object.fromEntries(formData);

 console.log(formData,formvalues)
// iterate through entries...
  tomeasureproj=formvalues['measureCheckbox']; //proj name


  if( formvalues['selectprojs'].startsWith('3.2') || formvalues['selectprojs'].startsWith('3.3') || formvalues['selectprojs'].startsWith('2.7') ){
    ratio1=1
    ratio2=prminpixels/(formvalues['prmRatio']/ratioPunit);
    console.log(ratio2, prminpixels,formvalues['prmRatio'],ratioPunit)
  }
  else if (formvalues['selectprojs'].startsWith('1.0') ){
    ratio1=(formvalues['areaRatio']/ratioAunit)/areainpixels;
    ratio2=(formvalues['prmRatio']/ratioPunit)/prminpixels;
    console.log('ratioss',ratio1,ratio2)
  }
  else if (formvalues['selectprojs'].startsWith('2.8') || formvalues['selectprojs'].startsWith('2.1') ){
    ratio1=1;
    ratio2=(formvalues['prmRatio']/ratioPunit)/prminpixels;
    console.log('ratioss',ratio1,ratio2)
  }
  pdfpath.push(formvalues['selectproj'],formvalues['selectprojp'] ,formvalues['selectprojs']) //project name - part - section

  if (canvasimg){
    console.log('canvasimg')
    buf=canvasimg.split("data:image/png;base64,")
    answers.push(tomeasureproj, 220,allcolors , ratio1, ratio2 ,pdfpath,buf[1]);
    formData.append('answers',JSON.stringify(answers)) 
 } 

  else{
    console.log('else')
    
    if ( formvalues['selectprojs'].startsWith('3.2') || formvalues['selectprojs'].startsWith('3.3') )
      {
        console.log('elseif')
        answers.push(tomeasureproj, 0,[], ratio1, ratio2 ,pdfpath); 
        formData.append('file',dxffile) 
        formData.append('answers',JSON.stringify(answers)) 
      }

    else if ( formvalues['selectprojs'].startsWith('2.7'))
      {
        console.log('elseif')
        console.log(groupedValues)
        answers.push(tomeasureproj, 0,[], ratio1, ratio2 ,pdfpath,groupedValues); 
        formData.append('file',dxffile) 
        formData.append('answers',JSON.stringify(answers)) 
      } 

    else if (formvalues['selectprojs'].startsWith('1.0'))
        {
          console.log('whyyyy hereeee')
          file=''
        answers.push(tomeasureproj, 0,[] , ratio1, ratio2 ,pdfpath);
        formData.append('answers',JSON.stringify(answers)) 
       } 
    else if (formvalues['selectprojs'].startsWith('2.1'))
    {
      answers.push(tomeasureproj, 0,[] , ratio1, ratio2 ,pdfpath);
      formData.append('answers',JSON.stringify(answers)) 
    }
    else if (formvalues['selectprojs'].startsWith('2.8') )
    {
      answers.push(tomeasureproj, 0,[] , 0,0,pdfpath , doorSchedulePDF);
      formData.append('answers',JSON.stringify(answers)) 
    }
  }
 
  if  (formvalues['selectprojs'].startsWith('1.0') || formvalues['selectprojs'].startsWith('3.2') || formvalues['selectprojs'].startsWith('2.8') || formvalues['selectprojs'].startsWith('3.3') || formvalues['selectprojs'].startsWith('2.7') ) //formvalues['selectprojs'].startsWith('2.1') 
  {  
    // console.log(formData)
    $.ajax({
            type: "POST",
            url: "/savebase64Img/",
            contentType: "application/json",  // set content type header to use Flask response.get_json()
            data: formData,// convert data/object to JSON to send
            processData: false, // Prevent jQuery from automatically processing the data
            contentType: false,
            success: function(response) {
                console.log(response);
            },
            error: function(err) {
              var TopTextModal = document.getElementById("TopTextModalWarning");
              TopTextModal.textContent='Error'
              PopupElement.textContent='Error occured. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
              ShowPopUp();
 
            }
          })
          .done(function(data){
        // var mp3_url = 'https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3';
        // (new Audio(mp3_url)).play()
        // retrieveLinks()
           if (!(formvalues['selectprojs'].startsWith('2.8')) )
              startDropdownUpdates(); // Start the dropdown updates


            document.getElementById("loading").hidden = true;
            document.getElementById("rightside").hidden = false;
            document.getElementById('duplicater').removeAttribute('hidden');
            if (formvalues['selectprojs'].startsWith('3.2') || formvalues['selectprojs'].startsWith('3.3') )
             { 
              document.getElementById('duplicater').children[8].children[1].setAttribute('disabled','True')
              document.getElementById('duplicater').children[8].children[2].setAttribute('disabled','True')

              document.getElementById('duplicater').children[8].children[1].style.cursor='not-allowed';
              document.getElementById('duplicater').children[8].children[2].style.cursor='not-allowed';

             }
            document.getElementById('addicon').style.display='inline-block';
            document.getElementById('doneebackground').removeAttribute('hidden');
            document.getElementById('summarytoXML').removeAttribute('hidden');
            if (mctnameEmpty){
              document.getElementById('doneebackground').setAttribute('disabled','True')
              document.getElementById('doneebackground').style.cursor='not-allowed';
              document.getElementById('doneebackground').style.boxShadow = 'none';
              document.getElementById('doneebackground').style.color = 'white';
              document.getElementById('doneebackground').style.backgroundColor="rgb(154,152,152)";

              document.getElementById('summarytoXML').setAttribute('disabled','True')
              document.getElementById('summarytoXML').style.cursor='not-allowed';
              document.getElementById('summarytoXML').style.boxShadow = 'none';
              document.getElementById('summarytoXML').style.color = 'white';
              document.getElementById('summarytoXML').style.backgroundColor="rgb(154,152,152)";

            }
            
            

            // clearInterval()
            document.getElementById('measureADRbutton').removeAttribute('disabled');
            document.getElementById('measureADRbutton').style.cursor='pointer';
            document.getElementById('measureADRbutton').style.color = 'white';
            document.getElementById('measureADRbutton').style.backgroundColor="#16c72e";
            document.getElementById('measureADRbutton').style.padding='10px 102px';
            document.getElementById('measureADRbutton').addEventListener('mouseover',function(){
              document.getElementById('measureADRbutton').style.color='black';
              document.getElementById('measureADRbutton').style.boxShadow=' 0 0 8px 2px #16c72e';
            })
            document.getElementById('measureADRbutton').addEventListener('mouseout',function(){
              document.getElementById('measureADRbutton').style.color='white';
              document.getElementById('measureADRbutton').style.boxShadow='none';
            });

            if (formvalues['selectprojs'].startsWith('3.2') || formvalues['selectprojs'].startsWith('3.3') || formvalues['selectprojs'].startsWith('2.7') )
            { //
            // /* data[0]--> img , SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]

                SimilarAreaDictionary=data[1];
                spreadsheetURL=data[2];
                spreadsheetId=data[3];
                // spreadsheetURL=data[4];
                list1= data[5];
                
                dropboxLink=data[6];
                console.log(data[7])
                // console.log(dropboxLink)
                

                
            }
            if (formvalues['selectprojs'].startsWith('2.8'))
            { //base64.b64encode(buffer).decode('utf-8') ,pdflink,list1.to_dict(),  repeated_labels , not_found]
             // /* data[0]--> img , data[1]-->dataframe (goes to legend lsa ) , data [2] -->pdf dropbox shareable link ,data[3]-> spreadsheetId, data[4],spreadsheeturl */   
                // SimilarAreaDictionary=data[1];
                // listofimages=data[0];
                console.log('2.8Daata',data)
                dropboxLink=data[1];
                list1= data[2] // list of pdf markups 
                Repeated_Labels2_8=data[3]
                Not_Found2_8=data[4]  
                console.log(Repeated_Labels2_8,Not_Found2_8)    
            }
            if (formvalues['selectprojs'].startsWith('2.2'))
              {
                //ignore data[0] --> img passed directly
                //dropboxLink=data[1]
              
                //spreadsheetId=data[2]
                //spreadsheetURL=data[3]


            }
            if (formvalues['selectprojs'].startsWith('2.1'))
              {
                //ignore data[0] --> img passed directly
                //dropboxLink=data[1]
              
                //spreadsheetId=data[2]
                //spreadsheetURL=data[3]
                spreadsheetURL=data[0]

            }
            if (formvalues['selectprojs'].startsWith('1.0'))
              {// section 1.0
              console.log('?')
              SimilarAreaDictionary=data[1];
              spreadsheetURL= data[2];
              spreadsheetId=  data[3];
              colorsUsed = data[4];
              list1 = data[5]; //list of pdf markups 
              dropboxLink=data[6];
              namepathArr=data[8];
            }
            
            // if (!(formvalues['selectprojs'].startsWith('2.8')))
            // {
              ImgSide(data[0],spreadsheetURL,dropboxLink)
              if (formvalues['selectprojs'].startsWith('2.8')) {
                let messages = [];
                if (Repeated_Labels2_8)
                if (Repeated_Labels2_8.length > 0) {
                    messages.push('The following label(s) are represented on multiple doors: ' + Repeated_Labels2_8);
                }

                if (Not_Found2_8.length > 0) {
                    messages.push('The following label(s) not found on the plan: ' + Not_Found2_8);
                }

                if (messages.length > 0) {
                    var TopTextModal = document.getElementById("TopTextModal");
                    TopTextModal.textContent = 'Warning';

                    PopupElement.textContent = messages.join('\n'); // Show both messages if both conditions are met
                    ShowPopUp();
                }
            }

            // }
              
            // else{
            //   console.log(listofimages.length)
            //   for(var p=0;p<listofimages.length;p++)
            //   {
            //     ImgSide(listofimages[p],spreadsheetURLs[p],dropboxLinks[p])
            //   }
            // }
            // getlegendstoDirectory()
//////////////////////////////////////////////////////////////////////////////////////////
            let delrows2 = {
              content : {},
              id     : {},
              subject :{},
              color:{}
            };

            var delrows1='';
            var flag=0;
            pdfpath=[];
            pdfpath.push(formvalues['selectproj'],formvalues['selectprojp'] ,formvalues['selectprojs'])
if (formvalues['selectprojs'].startsWith('1.0') || formvalues['selectprojs'].startsWith('3.2') ||  formvalues['selectprojs'].startsWith('3.3')||  formvalues['selectprojs'].startsWith('2.7')) { // || formvalues['selectprojs'].startsWith('2.8')
    const interval = 6000; // Interval in milliseconds
    let delrows1 = ''; // Initial data storage
    let delrows2 = ''; // Updated data storage

    console.log('Starting first AJAX request...');

    // First AJAX request
    $.ajax({
        type: "POST",
        url: "/_submission",
        contentType: "application/json",
        data: JSON.stringify({
            dict1: JSON.stringify(list1),
            spreadsheetId: spreadsheetId,
            pdfpathpath: JSON.stringify(pdfpath),
            path: Object.fromEntries(formData)['measureCheckbox']
        }),
        dataType: "json",
        success: function (data1) {
            delrows1 = data1[0];
            console.log('First AJAX response received:', JSON.stringify(delrows1));
        },
        error: function (err) {
            console.error('Error occurred during first AJAX call:', err);
            var TopTextModal = document.getElementById("TopTextModalWarning");
            TopTextModal.textContent='Error'
            PopupElement.textContent = 'Error occurred. Refresh and try again. If the error continues, please contact the ADR team to fix it.';
            ShowPopUp();
        }
    });

    // Function to perform AJAX requests and compare data
    async function fetchAndCompareData() {
        try {
            console.log('Fetching data...');

            // Second AJAX request
            const data11 = await $.ajax({
                type: "POST",
                url: "/_submission",
                contentType: "application/json",
                data: JSON.stringify({
                    dict1: JSON.stringify(list1),
                    spreadsheetId: spreadsheetId,
                    pdfpathpath: JSON.stringify(pdfpath),
                    path: Object.fromEntries(formData)['measureCheckbox']
                }),
                dataType: "json"
            });

            delrows2 = data11[0];
            console.log('Second AJAX response received:', JSON.stringify(delrows2));

            // Compare data
            if (JSON.stringify(delrows1) === JSON.stringify(delrows2)) {
                console.log('Data is the same');
            } else {
                console.log('Differences found:', delrows1, delrows2);
                if (confirm("Changes have been made in the markups. Would you like to save and view them in the legend?")) {
                    delrows1 = delrows2;
                    document.getElementById("loading").hidden = false;
                    document.getElementById("loading").style.marginTop = '20%';
                    document.getElementById("loading").style.marginLeft = '65%';

                    updatepreview([pdfpath, Object.fromEntries(formData)['measureCheckbox']]);

                    await $.ajax({
                        type: "POST",
                        url: "/deletemarkupsroute",
                        contentType: "application/json",
                        data: JSON.stringify({
                            dict: JSON.stringify(SimilarAreaDictionary),
                            deletedrows: delrows2,
                            path: Object.fromEntries(formData)['measureCheckbox'],
                            spreadsheetId: spreadsheetId,
                            areaPermArr: JSON.stringify(data[7]),
                            section: Object.fromEntries(formData)['selectprojs'],
                            pdfpathpath: JSON.stringify(pdfpath)
                        }),
                        dataType: "json"
                    });

                    console.log('Markups updated');
                }
            }

        } catch (err) {
            var TopTextModal = document.getElementById("TopTextModalWarning");
            TopTextModal.textContent='Error'
            console.error('Error occurred during fetchAndCompareData:', err);
            PopupElement.textContent = 'Error occurred. Refresh and try again. If the error continues, please contact the ADR team to fix it.';
            ShowPopUp();
        } finally {
            // Always continue fetching data every 6 seconds
            console.log(`Waiting for ${interval} ms before next fetch...`);
            setTimeout(fetchAndCompareData, interval); // Continue the interval
        }
    }

    // Initial interval-based call
    setTimeout(fetchAndCompareData, interval);

    // Button click event listener
    document.addEventListener("click", function (event) {
    if (event.target && event.target.id === "refreshpdfmarkups") {
        console.log('Button clicked. Fetching data immediately...');
        fetchAndCompareData();
    }
});
}

            /////////////////////////
  });
}

}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
document.getElementById("myForm").addEventListener("submit", function (e) {
  e.preventDefault(); // Prevent form submission
    let isChecked = document.querySelector('input[name="measureCheckbox"]:checked') !== null;
    let sectionNumber = projsec.value; // Ensure projsec is defined
    let isRelvClicked = document.querySelector(".relv-item[style*='background-color']") !== null;
    
    let TopTextModal = document.getElementById("TopTextModal");
    TopTextModal.textContent = "Warning: Missing Inputs";
    if (sectionNumber.startsWith('2.8')) {

        // If section starts with '2.8', both measureCheckbox and relv-item must be selected
        if (!isChecked & !isRelvClicked) {
            document.getElementById('relvselectid').style.boxShadow='0 0 8px 2px rgb(255, 0, 0)';
            PopupElement.textContent = "Please select at least one project from 'Documents to Measure' and one relevant item rom 'Other Relevant Documents' before proceeding!";
            ShowPopUp();
            return;
        }
        else if (!isChecked){
            PopupElement.textContent = "Please select at least one project from 'Documents to Measure' before proceeding!";
            ShowPopUp();
            return;
        }
        else if (!isRelvClicked){
            document.getElementById('relvselectid').style.boxShadow='0 0 8px 2px rgb(255, 0, 0)';
            PopupElement.textContent = "Please select at least one relevant item from 'Other Relevant Documents' before proceeding!";
            ShowPopUp();
            return;
        }
    } else {
        // If section is not '2.8', only measureCheckbox is required
        if (!isChecked) {
            PopupElement.textContent = "Please select at least one project before proceeding from 'Documents to Measure' section!";
            ShowPopUp();
            return;
        }
    }

    // If validation passes, proceed with form submission
    getData(e.target);
});
////////////////////////////////////////////
var measitemVal='';

function get3rddropdown(){
  console.log('ayhagaaaaaaaaaaaaaaaaa')
  // selections=measitem.value.toString() //3rd dpdwn value
  var unit;
  if (addciconval>0){

    for (let i =1 ; i <=addciconval ; i++){
      var inputs1 = document.getElementsByClassName("measurementselections"+i)[0];  //1sr dpdwn
      var selections1 = document.getElementsByClassName("selections"+i)[0]; //2nd dropdown
      var measitem1 = document.getElementsByClassName("measureitems"+i)[0];  //3rd dpdwn
    
    
      measitemVal1=measitem1.value.toString() //3rd dpdwn value

      
        if(( (inputs1.value=='ground beams' ) || (inputs1.value=='pile caps' ) ) & (!selections1.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
        {  //1.0
        selections1.innerHTML='';


            for (let m=0;m<MCTNames.length;m++)
            {
              var opt0 = document.createElement("OPTION") ;
              opt0.text= MCTNames[m][0];
              opt0.textContent= MCTNames[m][0];
              opt0.value= MCTNames[m][0];
              selections1.add(opt0);
            }
            console.log(section.value.toString())
            
      }
      else if(( (inputs1.value=='Wall' ) || (inputs1.value=='Column' ) ) & (!selections1.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
        {  //1.0
        selections1.innerHTML='';


            for (let m=0;m<MCTNames.length;m++)
            {
              var opt0 = document.createElement("OPTION") ;
              opt0.text= MCTNames[m][0];
              opt0.textContent= MCTNames[m][0];
              opt0.value= MCTNames[m][0];
              selections1.add(opt0);
            }
            console.log(section.value.toString())
            
      }
      else if(( (inputs1.value=='Floor' ) || (inputs1.value=='Wall' ) ) & (!selections1.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
        {   //3.2
        selections1.innerHTML='';


            for (let m=0;m<MCTNames.length;m++)
            {
              var opt0 = document.createElement("OPTION") ;
              opt0.text= MCTNames[m][0];
              opt0.textContent= MCTNames[m][0];
              opt0.value= MCTNames[m][0];
              selections1.add(opt0);
            }
            console.log(section.value.toString())
            
      } 
      else if(( (inputs1.value=='Ceiling' ) ) & (!selections1.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
        {   //3.3
        selections1.innerHTML='';


            for (let m=0;m<MCTNames.length;m++)
            {
              var opt0 = document.createElement("OPTION") ;
              opt0.text= MCTNames[m][0];
              opt0.textContent= MCTNames[m][0];
              opt0.value= MCTNames[m][0];
              selections1.add(opt0);
            }
            console.log(section.value.toString())
            
      }
      else if(( (inputs1.value=='Internal Walls' ) ) & (!selections1.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
        {   //3.3
        selections1.innerHTML='';


            for (let m=0;m<MCTNames.length;m++)
            {
              var opt0 = document.createElement("OPTION") ;
              opt0.text= MCTNames[m][0];
              opt0.textContent= MCTNames[m][0];
              opt0.value= MCTNames[m][0];
              selections1.add(opt0);
            }
            console.log(section.value.toString())
            
      }  

      // if (inputs1.value.startsWith('Floor') & (selections1.value.startsWith('Wall') || !selections1.value )){
      //   selections1.innerHTML='';
      //   var opt2 = document.createElement("OPTION") ;
      //   opt2.text= 'Floor:m2';
      //   opt2.value= 'Floor:m2';
      //   opt2.id='floorA' ;
      //   selections1.add(opt2);

      // }

      // if (inputs1.value.startsWith('Wall') & (selections1.value.startsWith('Floor') || !selections1.value ) ){
      //   selections1.innerHTML='';
      //   var opt3 = document.createElement("OPTION") ;
      //   opt3.text= 'Wall:m';
      //   opt3.value= 'Wall:m';
      //   opt3.id='WallP';
      //   selections1.add(opt3);

      // }

        // measitem1.innerHTML='';
        // var ii, L = measitem1.options.length - 1;
        //   for(ii = L; ii >= 0; ii--) {
        //     if (measitem1.options[ii].value=='Area')
        //       measitem1.remove(ii);
        //   } 


    
  // });
   if (selections1.value )
  {
    for(var l in MCTNames){
        if(MCTNames[l][0] == selections1.value){
          // Add an element to the dictionary
          unit=MCTNames[l][1]
          break; // If you want to break out of the loop once you've found a match
        }
    }
   
    
    
    if (unit=='m2' )
    { measitem1.innerHTML='';
      var opt10 = document.createElement("OPTION") ;  
      opt10.text= 'Area:m2';
      opt10.value= 'Area:m2';
      opt10.id='Area:m2';
      measitem1.add(opt10);
    }
    if (unit=='m' & !(measitem1.value=='Perimeter:m'))
    { measitem1.innerHTML='';
    
    

      var opt11 = document.createElement("OPTION") ;  
      opt11.text= 'Length:m';
      opt11.value= 'Length:m';
      opt11.id='Length:m';
      measitem1.add(opt11);

      var opt12 = document.createElement("OPTION") ;  
      opt12.text= 'Perimeter:m';
      opt12.value= 'Perimeter:m';
      opt12.id='Perimeter:m';
      measitem1.add(opt12);
    
  }
    if (unit=='nr')
    { measitem1.innerHTML='';
      var opt13 = document.createElement("OPTION") ;  
      opt13.text= 'Count:Nr';
      opt13.value= 'Count:Nr';
      opt13.id='Count:Nr';
      measitem1.add(opt13);

    }

  }
    }

  }
  // $(inputs).on("change", function (e) { 
    if(( (inputs.value=='ground beams' ) || (inputs.value=='pile caps' ) ) & (!selections.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
   {
    selections.innerHTML='';
 
      for (let m=0;m<MCTNames.length;m++)
      { 
        var opt0 = document.createElement("OPTION") ;
        opt0.text= MCTNames[m][0];
        opt0.textContent= MCTNames[m][0];
        opt0.value= MCTNames[m][0];
        selections.add(opt0);
      }

   }
   if(( (inputs.value=='Wall' ) || (inputs.value=='Column' ) ) & (!selections.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
   {
    selections.innerHTML='';
 
      for (let m=0;m<MCTNames.length;m++)
      { 
        var opt0 = document.createElement("OPTION") ;
        opt0.text= MCTNames[m][0];
        opt0.textContent= MCTNames[m][0];
        opt0.value= MCTNames[m][0];
        selections.add(opt0);
      }

   }
   else if(( (inputs.value=='Floor' ) || (inputs.value=='Wall' ) ) & (!selections.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
   {
    selections.innerHTML='';
 
      for (let m=0;m<MCTNames.length;m++)
      { 
        var opt0 = document.createElement("OPTION") ;
        opt0.text= MCTNames[m][0];
        opt0.textContent= MCTNames[m][0];
        opt0.value= MCTNames[m][0];
        selections.add(opt0);
      }

   }
   else if(( (inputs.value=='Ceiling' ) ) & (!selections.value))//& (selections.value.startsWith('Pile') || !selections.value )) || (inputs.children[0].value=='pile caps'  & (selections.value.startsWith('Ground') || !selections.value )))
   {
    selections.innerHTML='';
 
      for (let m=0;m<MCTNames.length;m++)
      { 
        var opt0 = document.createElement("OPTION") ;
        opt0.text= MCTNames[m][0];
        opt0.textContent= MCTNames[m][0];
        opt0.value= MCTNames[m][0];
        selections.add(opt0);
      }

   }

  //  if (inputs.value=='Floor' & (selections.value.startsWith('Wall') || !selections.value )){
  //   selections.innerHTML='';
  //   var optn = document.createElement("OPTION") ;
  //   optn.text= 'Floor:m2';
  //   optn.value= 'Floor:m2';
  //   optn.id='floorA' ;
  //   selections.add(optn);

  //  }

  //  if (inputs.value=='Wall' & (selections.value.startsWith('Floor') || !selections.value ) ){
  //   selections.innerHTML='';

  //   var opt = document.createElement("OPTION") ;
  //   opt.text= 'Wall:m';
  //   opt.value= 'Wall:m';
  //   opt.id='WallP';
  //   selections.add(opt);

  //  }
  // })
console.log(selections.value)
  if (selections.value)
  {
    for(var l in MCTNames){
        if(MCTNames[l][0] == selections.value){
          // Add an element to the dictionary
          unit=MCTNames[l][1]
          break; // If you want to break out of the loop once you've found a match
        }
    }
  
    
    if (unit=='m2' )
    {  measitem.innerHTML='';
      var opt10 = document.createElement("OPTION") ;  
      opt10.text= 'Area:m2';
      opt10.value= 'Area:m2';
      opt10.id='Area:m2';
      measitem.add(opt10);
    }
    
    if (unit=='m' & !(measitem.value=='Perimeter:m'))
    {
      measitem.innerHTML='';
      var opt11 = document.createElement("OPTION") ;  
      opt11.text= 'Length:m';
      opt11.value= 'Length:m';
      opt11.id='Length:m';
      measitem.add(opt11);

      var opt12 = document.createElement("OPTION") ;  
      opt12.text= 'Perimeter:m';
      opt12.value= 'Perimeter:m';
      opt12.id='Perimeter:m';
      measitem.add(opt12);
    
  }
    if (unit=='nr' )
    {  measitem.innerHTML='';
      var opt13 = document.createElement("OPTION") ;  
      opt13.text= 'Count:Nr';
      opt13.value= 'Count:Nr';
      opt13.id='Count:Nr';
      measitem.add(opt13);

    }
  }

}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
var repeatforloopI=0;
var repeatforloopIextra=0;
function getmctName(){
  
  var listofnames=[];
  var flag=0;
  arrallvalues=[];
  arrmctNames=[];
  arrFinalMCNames=[];
 
  var allmcnamestext= document.querySelectorAll('input[name="text1name"]');
  allmcnamestext.forEach(function(elem){
    if (elem.value)
      arrallvalues.push(elem.value);
  })
 
  for (ii=0 ; ii<=addciconval; ii++){
    if (ii==0){
      //first one -- not duplicated yet --first row onlyy
    var divduplicater=  document.getElementsByClassName('duplicaterclass')[0].children;
    var selections = divduplicater[3];//ex: Gb:m 
    measitemVal=divduplicater[5].value; // ex:area
    var div=divduplicater[8].children;// first repeatforloopclass
    var divValues=['text1'+div[0].value, div[1].value , div[2].value]; 
    mctname=[selections.value ,divValues , measitemVal ];
    
//////////////////////////////////////////


  count=0;
  var ii0selections='';
  for (let child =1;child <divduplicater.length;child++)
   {
    console.log('here3')
    if( divduplicater[child] instanceof(HTMLDivElement) )
      count++;
      console.log(divduplicater)
      ii0selections=divduplicater[3].value;
      measitemVal=divduplicater[5].value;
      console.log('gfd  ',ii0selections,measitemVal)
        if (divduplicater[child].className.startsWith('repeatforloopclass') && child !=5)
        {
          console.log('c',divduplicater[child].children)
          var divValues2=['text1'+divduplicater[child].children[0].value, divduplicater[child].children[1].value , divduplicater[child].children[2].value];
          mctname1=[ii0selections ,divValues2 , measitemVal];
          console.log('divValues2',mctname1)
          if(divduplicater[child].children[0].value && divduplicater[child].children[1].value && divduplicater[child].children[2].value)
          { 
            // console.log(mctname1);
            flag=1;
            arrmctNames.push(mctname1);
          }
      
          else if(divduplicater[child].children[0].value && !divduplicater[child].children[1].value && !divduplicater[child].children[2].value) {
            mctname1=[ii0selections ,[ 'text1'+divduplicater[child].children[0].value ], measitemVal ];
            flag=1;
            arrmctNames.push( mctname1);
          }
          else if(divduplicater[child].children[0].value && divduplicater[child].children[1].value && !divduplicater[child].children[2].value) {
            mctname1=[ii0selections ,['text1'+divduplicater[child].children[0].value ,  divduplicater[child].children[1].value] , measitemVal];
            flag=1;
            arrmctNames.push( mctname1);
          }
          }
    }

  }
  
  // else if (ii>0){
  //   var divduplicater=  document.getElementsByClassName('duplicaterclass'+ii)[0].children;
    
  //   console.log(divduplicater)
  //   selections = divduplicater[3];//document.getElementsByClassName("selections")[0]; 
  //   measitemVal=divduplicater[5].value;
  //   div=divduplicater[8].children;

  //   var divValues=['text1'+div[0].value, div[1].value , div[2].value];
  //   mctname=[selections.value ,divValues , measitemVal ];

  //   if(div[0].value && div[1].value && div[2].value)
  //   { 
  //     flag=1;
  //     arrmctNames.push( mctname);
  //   }
  //   else if (div[0].value && !div[1].value && !div[2].value) {
  //     mctname=[selections.value ,['text1'+div[0].value ], measitemVal ];
  //     flag=1;
  //     arrmctNames.push( mctname);
  //   }
  //   else if (div[0].value && div[1].value && !div[2].value) {
  //     mctname=[selections.value ,['text1'+div[0].value, div[1].value ] , measitemVal ];
  //     flag=1;
  //     arrmctNames.push( mctname);
  //   }
    
  // }

  if (ii>0 )//&& addciconval >0 && jj>0)
  {
    count=0;
    var ii0selections='';
    var replicatedDivChildren=document.getElementsByClassName('duplicaterclass'+ii)[0].children;   

    for (let o =0;o <=replicatedDivChildren.length;o++)
    {
      if( replicatedDivChildren[o] instanceof(HTMLDivElement) )
      {   count++;
          ii0selections=replicatedDivChildren[3].value;
          measitemVal=replicatedDivChildren[5].value;
          console.log('lkjhgf',replicatedDivChildren)
      }
    }

    for (child=0;child<replicatedDivChildren.length;child++)
    {
        if (replicatedDivChildren[child].className.startsWith('repeatforloopclass') && child !=5)
        {
          var divValues2=['text1'+replicatedDivChildren[child].children[0].value, replicatedDivChildren[child].children[1].value , replicatedDivChildren[child].children[2].value];
          mctname1=[ii0selections ,divValues2 , measitemVal];
          if(replicatedDivChildren[child].children[0].value && replicatedDivChildren[child].children[1].value && replicatedDivChildren[child].children[2].value)
          { 
            arrmctNames.push(mctname1);
            flag=1;
          }
          else if(replicatedDivChildren[child].children[0].value && !replicatedDivChildren[child].children[1].value && !replicatedDivChildren[child].children[2].value)
          { 
            mctname1=[ii0selections ,['text1'+replicatedDivChildren[child].children[0].value] , measitemVal];
            arrmctNames.push(mctname1);
            flag=1;
          }
          else if(replicatedDivChildren[child].children[0].value && replicatedDivChildren[child].children[1].value && !replicatedDivChildren[child].children[2].value)
          { 
            mctname1=[ii0selections ,['text1'+replicatedDivChildren[child].children[0].value, replicatedDivChildren[child].children[1].value] , measitemVal];
            arrmctNames.push(mctname1);
            flag=1;
          }

        }
    }
  }
   arrFinalMCNames= arrmctNames.slice();
  if(arrmctNames.length >1){
    var name=[];
    allnames=[];
    arrFinalMCNames = arrmctNames.slice();
    var newarr=[];
    for (let i=0;i<arrmctNames.length; i++)
    { str='';
      newarr=[];
  
      for (let j=i+1; j<arrmctNames.length; j++)
      {
        if (arrmctNames[i][0] == arrmctNames[j][0] && arrmctNames[i][2] == arrmctNames[j][2] &&arrmctNames[i][1][1] == arrmctNames[j][1][1] && arrmctNames[i][1][2] == arrmctNames[j][1][2])
        { var selectionsname=arrmctNames[i][0] ; 
          measitemVal=arrmctNames[i][2];
          flag=1;
          console.log('foorrr',arrmctNames[i][0],arrmctNames[i]);
        
          if (allnames.includes(arrmctNames[i][1][0]) )
          {
            var index = allnames.indexOf(allnames[i] );
            if (index !== -1) {
              allnames.splice(index, 1);
            }
          }
          if (!name.includes(arrmctNames[i][1][0]  ) ){
            // console.log('msh mwgod');
            name.push(arrmctNames[i][1][0]);
            newarr.push(arrmctNames[i][1][0]);
            var index = arrFinalMCNames.indexOf(arrmctNames[i] );
            if (index !== -1) {
              arrFinalMCNames.splice(index, 1);
            }
          }
          if (!name.includes(arrmctNames[j][1][0]  ) ){
            // console.log('msh mwgodj')
            name.push(arrmctNames[j][1][0]);
            newarr.push(arrmctNames[j][1][0]);
            var index1 = arrFinalMCNames.indexOf(arrmctNames[j] );
            if (index1 !== -1) {
              arrFinalMCNames.splice(index1, 1);
            }
          }
          if (!name.includes(arrmctNames[i][1][1] ) ||!name.includes(arrmctNames[i][1][2] ) ){
            name.push( arrmctNames[i][1][1] , arrmctNames[i][1][2] );
            newarr.push(arrmctNames[i][1][1] , arrmctNames[i][1][2] ); 

          }

      }

      }
      if (newarr.length >0){
        flag=1;
        arrFinalMCNames.push([selectionsname , newarr, measitemVal ]);
       
      }
  }
  }
  arrFinalMCNames.push([spreadsheetId , pdfpath[2]]);
  console.log(arrFinalMCNames)
  }
  if (flag==1){
  
  $.get( '/mctnametoGoogleSheet/'+ JSON.stringify(arrFinalMCNames))
  .success( function(data) {
    console.log('dataaaaa',data)

      spreadsheetURL=spreadsheetURL+ '/edit#gid='+data[0].toString()
      console.log('spreadsheetURL',spreadsheetURL)
      document.getElementById('all').style.display='none';
      window.open(spreadsheetURL.toString()) //sheetid 
  })
  .error(function(jqXHR, textStatus, errorThrown) { 
          PopupElement.textContent='Error occured while exporting the summary. Check your connection, refresh and try again. If the error continues, please contact the ADR team to fix it. ';
          ShowPopUp();
     });
}

}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
function addmctnameicon(){
  // guessednamesDropdown()
  repeatforloopI+=1
  var dupDiv;
  if (clonedDivId==0){
  var dupDiv=document.getElementById('duplicater'); //pass kol div hna 
  }
  else{
  var dupDiv=document.getElementById(clonedDivId); //pass kol div hna  //akher div et3mlt
  }

  var div=document.getElementById('repeatforloophidden')
  var clone = div.cloneNode(true); // "deep" clone

  jj++;
  if (clonedDivId==0)
    clone.style.marginLeft='5px';
  else
    clone.style.marginLeft='5px';

window.onclick = elem => {
  if (elem.target.tagName.startsWith('LORD-ICON') && elem.target.id.startsWith('addmctnameid')){
    clone.id = 'repeatforloop'+  elem.target.parentElement.parentElement.childNodes[1].value[0] + ++elem.target.parentElement.parentElement.childNodes[1].value[1];
    clone.setAttribute('class','repeatforloopclass'+elem.target.parentElement.parentElement.childNodes[1].value[0] + elem.target.parentElement.parentElement.childNodes[1].value[1]);
    clone.setAttribute('name','repeatforloopname'+elem.target.parentElement.parentElement.childNodes[1].value[0] + elem.target.parentElement.parentElement.childNodes[1].value[1]);
    clone.childNodes[11].id='addmctnameid'+elem.target.parentElement.parentElement.childNodes[1].value[0] + elem.target.parentElement.parentElement.childNodes[1].value[1];
    clone.childNodes[15].id='deletemctnameid'+elem.target.parentElement.parentElement.childNodes[1].value[0] + elem.target.parentElement.parentElement.childNodes[1].value[1];

    if (elem.target.parentElement.nextElementSibling)
    {
      $("#"+elem.target.parentElement.parentElement.id).append(clone);
    }
    else
    {
      $("#"+elem.target.parentElement.parentElement.id).append(clone);
      $("#"+elem.target.parentElement.id).insertBefore(clone,document.getElementById('doneebackground')); 
    }

    if (thirddropdown.value.startsWith('3.2') || thirddropdown.value.startsWith('3.3'))
    { 
      document.getElementById( 'repeatforloop'+  elem.target.parentElement.parentElement.childNodes[1].value[0] +elem.target.parentElement.parentElement.childNodes[1].value[1]).children[1].setAttribute('disabled','True')
      document.getElementById( 'repeatforloop'+  elem.target.parentElement.parentElement.childNodes[1].value[0] +elem.target.parentElement.parentElement.childNodes[1].value[1]).children[2].setAttribute('disabled','True')
    document.getElementById( 'repeatforloop'+  elem.target.parentElement.parentElement.childNodes[1].value[0] +elem.target.parentElement.parentElement.childNodes[1].value[1]).children[1].style.cursor='not-allowed';
    document.getElementById( 'repeatforloop'+  elem.target.parentElement.parentElement.childNodes[1].value[0] +elem.target.parentElement.parentElement.childNodes[1].value[1]).children[2].style.cursor='not-allowed';
    }
  }
}
}
 //___________________________________________________________________________________________________________
 //___________________________________________________________________________________________________________
function deletemctnameicon(){
  window.onclick = elem => {
    if (elem.target.tagName.startsWith('LORD-ICON') && elem.target.id.startsWith('deletemctnameid'))
    {
      var numb = elem.target.parentElement.id.match(/\d/g);
      if (numb==null)
        numb='';
      else
        numb = numb.join("");
      var deletethisdiv= document.getElementById('repeatforloop'+ numb);
      deletethisdiv.parentNode.removeChild(deletethisdiv);
    }
  }
}

function addmctnameiconPopup(){
  // guessednamesDropdown()
  repeatforloopIextra+=1
  var dupDivExtra;
  if (clonedDivIdExtra==0){
  var dupDivExtra=document.getElementById('duplicaterExtra'); //pass kol div hna 
  }
  else{
  var dupDivExtra=document.getElementById(clonedDivIdExtra); //pass kol div hna  //akher div et3mlt
  }

  var divExtra=document.getElementById('repeatforloopExtrahidden')
  var cloneExtra = divExtra.cloneNode(true); // "deep" clone
  jjExtra++;

  // if (clonedDivIdExtra==0)
  //   clone.style.marginLeft='5px';
  // else
  //   clone.style.marginLeft='5px';

window.onclick = elem => {
  if (elem.target.tagName.startsWith('LORD-ICON') && elem.target.id.startsWith('addmctnameidExtra')){
    // console.log('repeatforloopExtraaa', elem.target.parentElement.parentElement.childNodes[1].value )
    cloneExtra.id = 'repeatforloopExtra'+ jjExtra;
    cloneExtra.setAttribute('class','repeatforloopclassExtra'+jjExtra);
    cloneExtra.setAttribute('name','repeatforloopnameExtra'+jjExtra);
    cloneExtra.childNodes[11].id='addmctnameidExtra'+jjExtra;
    cloneExtra.childNodes[15].id='deletemctnameidExtra'+jjExtra;

    if (elem.target.parentElement.nextElementSibling)
    {
      $("#"+elem.target.parentElement.parentElement.id).append(cloneExtra);
    }
    else
    {
      $("#"+elem.target.parentElement.parentElement.id).append(cloneExtra);
      $("#"+elem.target.parentElement.id).insertBefore(cloneExtra,document.getElementById('doneebackground')); 
    }
    
  }
}
console.log()
if (sectionNumber.startsWith('2.7'))
{
    textextra= cloneExtra.children[0]
    textextra.style.backgroundColor = "rgba(101, 101, 101, 0.27)";
    textextra.style.cursor='not-allowed';
    textextra.disabled="disabled";

} 
if (sectionNumber.startsWith('2.8'))
{
  text2extra= cloneExtra.children[3]
  text2extra.style.backgroundColor ="rgba(101, 101, 101, 0.27)";
  text2extra.style.cursor='not-allowed';
  text2extra.disabled="disabled";
}
}

function deletemctnameiconPopup(){
  window.onclick = elem => {

    if (elem.target.tagName.startsWith('LORD-ICON') && elem.target.id.startsWith('deletemctnameidExtra'))
    {
      var numb = elem.target.parentElement.id.match(/\d/g);
      if (numb==null)
        numb='';
      else
        numb = numb.join("");
      var deletethisdivExtra= document.getElementById('repeatforloopExtra'+ numb);
      deletethisdivExtra.parentNode.removeChild(deletethisdivExtra);
    }
  }
}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
function colors(){
  var ele = document.getElementsByName('fullimage');
  var levels = document.getElementsByName('levelsnamelabel')[0];
  var levelsin = document.getElementsByName('levelsnameinput')[0]; //number of colors -- color pickers
  var drp = document.getElementById("colorpickers");
  for (i = 0; i < ele.length; i++) {
     if (ele[i].checked)
      if (ele[i].value==220){
        console.log(ele[i].value);
        levels.style.visibility='visible';
        levelsin.style.visibility='visible';
      }
      else
      {
        levels.style.visibility='hidden';
        levelsin.style.visibility='hidden';
        drp.innerHTML='';
      }
 }

}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
var canvas = document.querySelector("#myCanvas");
var ctx = canvas.getContext("2d");
var drp;
var color = 'rgb(47,255,255)';
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
function change(e){
    color = this.value;
    allcolors.push( color);
}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
let hex2rgb= c=> `rgb(${c.match(/\w\w/g).map(x=>+`0x${x}`)})`;

myCanvas.addEventListener("click", e => {
   
  var offset = canvas.getBoundingClientRect();
  var x = e.clientX - offset.left;
  var y = e.clientY - offset.top;
  //a new point is pushed on the last array of ry
  ry[ry.length - 1].push({ x: x, y: y, color:hex2rgb(color) });
  drawChart();

});
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
// function guessednamesDropdown(){
//   // 
//   $.get('/getguessednamepath/')
      
//       .success(function(arrayofvalues) {
//         console.log('arrayofvalues',arrayofvalues)
//         var text1name=  document.getElementsByName('text1name')
//                 // Loop through each dropdown
//         text1name.forEach((dropdown, index) => {
//             // Clear existing options
//             dropdown.innerHTML = '';
            
//             // Populate with arrayofvalues
//             arrayofvalues.forEach(value => {
//                 let option = document.createElement('option');
//                 option.value = value;
//                 option.text = value;
//                 dropdown.appendChild(option);
//             });
//         });
        
//       })
//       .error(function(jqXHR, textStatus, errorThrown) { 
//                 PopupElement.textContent='Error occured while retrieving the Legend Guessed Names. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
//                 ShowPopUp();
//               });
// }


function drawChart() {
  ctx.lineWidth = 5;

  // for every array in the ry array
  for (let index = 0; index < ry.length; index++) {
    // for every point in the ry[index]
    for (let i = 0; i < ry[index].length; i++) {
      firstcircle=[]
      let l = ry[index][i];
      // draw the circle
      if (i==0){
        drawCircle(l.x, l.y);
        firstcircle=[l.x,l.y]
      }
      // draw the line
      if (i > 0) {
      
        let last = ry[index][i - 1];
        ctx.beginPath();
        ctx.moveTo(last.x, last.y);
        ctx.lineTo(l.x, l.y);
        ctx.strokeStyle = l.color;
        ctx.stroke();
      }
    }
  }
}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
function drawCircle(x, y) {
  ctx.beginPath();
  ctx.arc(x, y,1, 0, Math.PI *2);
  ctx.strokeStyle = 'rgb(47,255,255)';
  ctx.stroke();
}
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
/*If the plan contains levels, open canvas window*/
/*Set canvas code to be visible on the new window with the pdftoimg as the background*/
var levelsin = document.getElementById('levelcheckbox');
var canvaswindow= document.getElementById('canvaswindow');
var undoButtonId=document.getElementById('undoButtonId');
NewShapeButtonId=document.getElementById('NewShapeButtonId');
var savecanvas=document.getElementById('savecanvas');

levelsin.addEventListener('click',function(){
  if (document.getElementsByClassName("selectionsProjs")[0].value.startsWith('1.0'))
  {  
  document.getElementById("all").style.display = "block";
  if( document.getElementById('levelcheckbox').checked)
    {
      $.get( '/canvaspdftoimgBackground/'+pdfname)
      .success (function(data){ 
        document.getElementById("all").style.display = "none";
          var popup = window.open('');   
          console.log(popup)
          popup.document.write('<html><head><title>ADR Console:Draw on PDF tool</title><link rel="stylesheet" href="static/style.css"></head><body>');

            var element = popup.document.createElement('div');
            element.setAttribute('id', 'mydiv');
            canvaswindow.childNodes[1].height=data[1]; //canvas -->child 3
            canvaswindow.childNodes[1].width=data[2];
            canvaswindow.childNodes[1].style.width= 0.5*screen.width +'px'
          
            HeightStyleratio= canvaswindow.childNodes[1].height *  0.5*screen.width  /  canvaswindow.childNodes[1].width ;
            canvaswindow.childNodes[1].style.height= HeightStyleratio.toString() + 'px';
            element.append(canvaswindow);
            console.log(canvaswindow.childNodes)
            
            canvaswindow.removeAttribute('hidden');
            var imgDrawon =document.createElement("img");
            imgDrawon.src = 'data:image/gif;base64,' +data[0];
            console.log('srcc'+imgDrawon.src)
            imgDrawon.width=data[2];
            imgDrawon.style.width='700px';
            imgDrawon.id='imgcanvas';
            imgDrawon.alt="Larry";
       
            imgDrawon.onload = function(){
            ctx.drawImage(imgDrawon,0,0);
            var scale = data[2] / canvaswindow.childNodes[1].style.width.slice(0,-2) ; // get the scale that matches display size 
            ctx.setTransform(scale,0,0,scale,0,0);         
          }
          undoButtonId.addEventListener("click", e => {
          //when undoButtonId is clicked the last point from the last array is deleted
            if (ry[ry.length - 1].length > 0) 
            {
              ry[ry.length - 1].pop();
            } 
            else {
              //if the last array is empty I delete this array 
              ry.pop();
              //and then I delete the last point from the last array
              ry[ry.length - 1].pop();
            }
            // delete everything
            
            ctx.clearRect(0,0, canvas.width, canvas.height); 
            //redraw background to draw lines over again
            ctx.drawImage(imgDrawon,0,0,canvaswindow.childNodes[1].style.width.slice(0, -2),canvaswindow.childNodes[1].style.height.slice(0, -2));
            drawChart();
          });

          var win = popup.document.body;
          win.appendChild(element);
          var drp=popup.document.body.childNodes[0].childNodes[0].childNodes[9];//color picker div
          NewShapeButtonId.addEventListener('click',function(){       
            ry.push([]);
          });
          drp.childNodes[1].addEventListener('click',function(){ //color picker
            drp.childNodes[1].onchange=change;
          })
      })
      .error(function(jqXHR, textStatus, errorThrown) { 
        PopupElement.textContent='Levels are not supported in this Section. ';
        ShowPopUp();
        document.getElementById('levelcheckbox').checked=false;
     });
      
      savecanvas.addEventListener('click',function(){
        var image = new Image();
        image.id = "pic";
        image.src = canvas.toDataURL("image/png");
        canvasimg=image.src;
      })    
    }
  }
  else{
    PopupElement.textContent='Levels are not supported in this Section. ';
    ShowPopUp();
    document.getElementById('levelcheckbox').checked=false;
  }
})
//___________________________________________________________________________________________________________
function getSecondData(){
  document.getElementById('all').style.display='block';

  getmctName()
}
//___________________________________________________________________________________________________________
var section = document.getElementsByClassName("selectionsProjs")[0]
var inputs= document.getElementById('measurementselectionsid');
var selections= document.getElementById('selectionsid');
var measitem= document.getElementById('measureitemsid');


function chooseFirstdrpdwn()
{
 
  inputs.innerHTML='';
  selections.innerHTML='';
  measitem.innerHTML='';
 
  if (section.value.startsWith('1.0'))
    {
   
    var opt = document.createElement("OPTION");
    opt.text= 'Select';
    opt.value= "";
    opt.hidden=true;
    inputs.add(opt);
    var optn = document.createElement("OPTION");
    optn.text= 'Ground Beams';
    optn.value= "ground beams";
    inputs.add(optn);
    var optn1 = document.createElement("OPTION");
    optn1.text= 'Pile Caps';
    optn1.value= "pile caps";
    inputs.add(optn1);
    }
  if (section.value.startsWith('3.2'))
    {
    var opt = document.createElement("OPTION");
    opt.text= 'Select';
    opt.value= "";
    opt.hidden=true;
    inputs.add(opt);
    var optn = document.createElement("OPTION");
    optn.text= 'Floor';
    optn.value= "Floor";
    inputs.add(optn);
    var optn1 = document.createElement("OPTION");
    optn1.text= 'Wall';
    optn1.value= "Wall";
    inputs.add(optn1);
    var optn2 = document.createElement("OPTION");
    optn2.text= 'Internal Doors';
    optn2.value= "Internal Doors";
    inputs.add(optn2);
    }
    if (section.value.startsWith('3.3'))
    {
    var opt = document.createElement("OPTION");
    opt.text= 'Select';
    opt.value= "";
    opt.hidden=true;
    inputs.add(opt);
    var optn = document.createElement("OPTION");
    optn.text= 'Ceiling';
    optn.value= "Ceiling";
    inputs.add(optn);
    }
    if (section.value.startsWith('2.7'))
    {
    var opt = document.createElement("OPTION");
    opt.text= 'Select';
    opt.value= "";
    opt.hidden=true;
    inputs.add(opt);
    var optn = document.createElement("OPTION");
    optn.text= 'Internal Walls';
    optn.value= "Internal Walls";
    inputs.add(optn);
    }
    if (section.value.startsWith('2.8'))
    {
    var opt = document.createElement("OPTION");
    opt.text= 'Select';
    opt.value= "";
    opt.hidden=true;
    inputs.add(opt);
    var optn = document.createElement("OPTION");
    optn.text= 'Single Door';
    optn.value= "Single Door";
    inputs.add(optn);
    var optn1 = document.createElement("OPTION");
    optn1.text= 'Double Door';
    optn1.value= "Double Door";
    inputs.add(optn1);
    }
    if (section.value.startsWith('2.1'))
    {
    var opt = document.createElement("OPTION");
    opt.text= 'Select';
    opt.value= "";
    opt.hidden=true;
    inputs.add(opt);
    var optn = document.createElement("OPTION");
    optn.text= 'Column';
    optn.value= "Column";
    inputs.add(optn);
    var optn1 = document.createElement("OPTION");
    optn1.text= 'Wall';
    optn1.value= "Wall";
    inputs.add(optn1);
    }

$(inputs).select2({
  
  placeholder:'Select',
  closeOnSelect: true,
  width:'15ch'
});
$(selections).select2({
  placeholder:'Select MC-T Name',
  closeOnSelect: true,
  width:'23ch'
});
$(measitem).select2({
  placeholder:'Select unit',
  closeOnSelect: true,
  width:'11ch'
});
}
$(inputs).on("change", function (e) { 
  get3rddropdown();
})

$(selections).on("change", function (e) { 
  get3rddropdown();
})
$(inputs).css('width', '50px');
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________

function summary_to_XML(){
  console.log(pdfpath)
  $.get('/summarytoXML/'+JSON.stringify([pdfpath,tomeasureproj]))
  .success(function(xmllink){
    console.log(xmllink)
    window.open(xmllink)
        })
        .error(function(jqXHR, textStatus, errorThrown) { 
        PopupElement.textContent='Error occured while exporting summary to XML. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
        ShowPopUp();
        });
}
var closeButtons = document.querySelectorAll(".closeModal");
var allCloseDivs = document.getElementsByName("tobeclosed");

closeButtons.forEach(function(button) {
    button.addEventListener("click", function() {
        allCloseDivs.forEach(function(div) {
            div.style.display = "none";
        });
    });
});
//___________________________________________________________________________________________________________
//___________________________________________________________________________________________________________
/* POP-UP code JS*/
// Select modal

var mpopup = document.getElementById('mpopupBox');
// Select close action element
// var close = document.getElementsByClassName("closeModal")[0];
function ShowPopUp(){
// Open modal
    mpopup.style.display = "block";
}
// Close modal once close element is clicked
//   close.onclick = function() {
//     mpopup.style.display = "none";
// };
// Close modal when user clicks outside of the modal box
  window.onclick = function(event) {
    if (event.target == mpopup) {
        mpopup.style.display = "none";
    }
};
// closeDialog.onclick = function() {
//     dialog_container.style.display = "none";
// };

var dialog_container = document.getElementById('dialog-container');
// Select close action element
// var closeDialog = document.getElementsByClassName("closeModal")[0];
function ShowPopUpWarning(){
// Open modal
dialog_container.style.display = "block";
}
// Close modal once close element is clicked
// closeDialog.onclick = function() {
//     console.log()
//     dialog_container.style.display = "none";
// };
// Close modal when user clicks outside of the modal box
  window.onclick = function(event) {
    if (event.target == dialog_container) {
      dialog_container.style.display = "none";
    }
};


function filterFunction(id) {
  var input, filter, ul, li, a, i;
  input = document.getElementById(id);
  filter = input.value.toUpperCase();
  if (id.toString().startsWith('tomeasure'))
      a = document.querySelectorAll("#measureContainer .measure-item");

    // a = document.getElementById("measureselectid").children;
  else
    // a = document.getElementById("relvselectid").children;
    a = document.querySelectorAll("#relvselectid .relv-item");
  // a = div.getElementsByTagName("option");
  for (i = 0; i < a.length; i++) {
    txtValue = a[i].textContent || a[i].innerText;
    if (txtValue.toUpperCase().indexOf(filter) > -1) {
      a[i].style.display = "";
    } else {
      a[i].style.display = "none";
    }
  }
}


// Call function when show dialog btn is clicked
var duplicaterExtra = document.getElementById("duplicaterExtra");
var overlaymeText = document.getElementById("modal-bodyTextp");
var overlayme = document.getElementById("dialog-container");
document.getElementById("refreshDropboxButtonID").disabled=false;

// if (document.getElementById("refreshDropboxButtonID").disabled==false){


  document.getElementById("refreshDropboxButtonID").onclick = function()
  {
    TopTextModal.textContent='Warning: Dropbox Refresh';
    if (document.getElementById("refreshDropboxButtonID").disabled==false)
    overlayme.style.display = "block";
    overlaymeText.textContent='The console updates projects retrieved from Dropbox automatically at 9:00 am and 9:00 p.m. If you need to access any projects in between, just click on this button. Please note that it will refresh the files related to the project you chose only.'; 
    duplicaterExtra.setAttribute('hidden',true)
  };


// Call function when show dialog btn is clicked
var TopTextModal = document.getElementById("TopTextModalWarning");

document.getElementById("refreshAPIbutton").disabled=false;
document.getElementById("refreshAPIbutton").onclick = function()
  {
    TopTextModal.textContent='Warning: MC Refresh';
    if (document.getElementById("refreshAPIbutton").disabled==false)
    {
      console.log(overlaymeText.textContent)
    overlaymeText.textContent='This is not a mandatory button. The system already runs at half-hour intervals to update the dropdowns and MC-Templates from the MC. Using this would manually refresh the data retrieved, disregarding the 30-minute interval.';
    overlayme.style.display = "block";
    duplicaterExtra.setAttribute('hidden',true)
  }
  };



document.getElementById("popupforextratext").disabled=false;
document.getElementById("popupforextratext").onclick = function(){
if (sectionNumber.startsWith('2.7'))
{
    textextra= document.getElementById("textextra")
    textextra.style.backgroundColor = "rgba(101, 101, 101, 0.27)";
    // textextra.style.border='2px solid #2f83c6'
    textextra.style.cursor='not-allowed';
    textextra.disabled="disabled";

}
if (sectionNumber.startsWith('2.8'))
{
  text2extra= document.getElementById("text2extra")
  text2extra.style.backgroundColor = "rgba(101, 101, 101, 0.27)";
  text2extra.style.cursor='not-allowed';
  text2extra.disabled="disabled";
}
  duplicaterExtra.removeAttribute('hidden'); 
  TopTextModal.textContent='Define Information to Extract from Drawing'
    if (document.getElementById("popupforextratext").disabled==false)
    {    
      overlaymeText.textContent='';
      overlayme.style.display = "block";
  }
  };
// }


document.getElementById("confirm").onclick = function(){confirmDialogR()};
function confirmDialogR() {
 /* code executed if confirm is clicked */ 
    overlayme.style.display = "none";
   console.log(document.getElementById("confirm").parentElement.parentElement.children[0].textContent)
    if (document.getElementById("confirm").parentElement.parentElement.children[0].textContent.startsWith('The'))
    {
      console.log('hereeeeeeeee')
      callrefreshDropbox();
    }
    else if(document.getElementById("confirm").parentElement.parentElement.children[0].textContent.startsWith('This')){

      callrefreshAPI();
    }
    else{
      getpopuptext();
    }

}

// If cancel btn is clicked , the function cancel() is executed
document.getElementById("cancel").onclick = function(){cancelDialog()};
function cancelDialog() {
    overlayme.style.display = "none";
}

var extracted_path;
function callrefreshDropbox(){
  console.log('ldropboxx' , extracted_path)
  document.getElementById("refreshDropboxButtonID").style.backgroundColor = "gray";
  document.getElementById("refreshDropboxButtonID").style.cursor='not-allowed';
  document.getElementById("refreshDropboxButtonID").disabled="disabled";
  
  TopTextModal=document.getElementById("TopTextModal");
  $.get('/postdropboxprojects/' + encodeURIComponent(JSON.stringify(extracted_path)))
      
     .success(function(stringReturned) {
      if (stringReturned.startsWith('Updated'))
      {
      console.log('DONEEEE')
      
      TopTextModal.textContent= "Success!";
      TopTextModal.style.color='green';
      PopupElement.textContent=stringReturned;
     }
     else{
      PopupElement.textContent=stringReturned;
     }
      ShowPopUp();
      document.getElementById("refreshDropboxButtonID").style.cursor='pointer';
      document.getElementById("refreshDropboxButtonID").style.backgroundColor = "#1680c7";
      document.getElementById("refreshDropboxButtonID").disabled = false; 
      })
     .error(function(jqXHR, textStatus, errorThrown) { 
          PopupElement.textContent='Error occured while retrieving projects from the dropbox. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
          ShowPopUp();    
      });

}


function refreshAPIbuutton(dataa){  
                $.get('/refreshAPIAppendNewTables')
                .success(function(successData){

                  if (dataa[1]==='project')
                      {
                        // console.log('projjjj')
                        // displayprjnames();
                        console.log(dataa[2])
                        for (let d=0;d<dataa[2].length;d++)
                        {
                          console.log(dataa[2][d])
                          opt=document.createElement("option");
                          opt.textContent=dataa[2][d];
                          opt.text=dataa[2][d];
                          firstdropdown.append(opt);
                          PrjNamesArray.push(dataa[2][d]);
                        }
                      }
                      else if (dataa[1]==='part')
                      {  if (firstdropdown.value)
                        {
                          console.log(dataa[2])
                          for (let d=0;d<dataa[2].length;d++)
                          {
                            console.log(dataa[2][d])
                            opt=document.createElement("option");
                            opt.textContent=dataa[2][d];
                            opt.text=dataa[2][d];
                            seconddropdown.append(opt);
                            // PrjPartsArray.push(data[2][d]);
                          }
                        }
                      }
                      else if (dataa[1]==='section')
                      {
                        if ((firstdropdown.value) && (seconddropdown.value))
                          {
                            console.log(dataa[2])
                            for (let d=0;d<dataa[2].length;d++)
                            {
                              console.log(dataa[2][d])
                              opt=document.createElement("option");
                              opt.textContent=dataa[2][d];
                              opt.text=dataa[2][d];
                              if(!(dataa[2][d].startsWith('1.0')  ) || (data[i].startsWith('3.2') ) || (data[i].startsWith('2.8')) || (data[i].startsWith('3.3')) || (data[i].startsWith('2.1')) || (data[i].startsWith('2.7')) )//||data[i].startsWith('2.2')))
                                {
                                  opt.style.color='#bdbcbc';
                                  opt.style.cursor='not-allowed';
                                  opt.setAttribute('disabled',true)
                                }
                              thirddropdown.append(opt);
                              // PrjPartsArray.push(data[2][d]);
                            }
                          }
                      }
                  TopTextModal=document.getElementById("TopTextModalWarning");
                  TopTextModal.textContent= "Success!";
                  TopTextModal.style.color='green';
                  PopupElement.textContent='Console is up to date!';
                  ShowPopUp();
                  document.getElementById("refreshAPIbutton").style.cursor='pointer';
                  document.getElementById("refreshAPIbutton").style.backgroundColor = "#003CFF";
                  document.getElementById("refreshAPIbutton").disabled = false; 
                  document.getElementById('all').style.display='none';
                })
                .error(function(jqXHR, textStatus, errorThrown) { 
                PopupElement.textContent='Error occured while retrieving projects. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
                ShowPopUp();
                });
}

function callrefreshAPI(){
  console.log('l')
  document.getElementById("refreshAPIbutton").style.backgroundColor = "gray";
  document.getElementById("refreshAPIbutton").style.cursor='not-allowed';
  document.getElementById("refreshAPIbutton").disabled="disabled";
  if (thirddropdown.value){
    console.log('yes')
          $.get( '/RetrieveMCTNames/')
          .success (function(data){
            console.log(data)
            MCTNames=data;
            // console.log('jjw')
            sectionNumber=thirddropdown.value;
            MCTNames=MCTNames[sectionNumber.toString().toLowerCase()]

            // console.log('pn')
            console.log(MCTNames)
          })
          .error(function(jqXHR, textStatus, errorThrown) { 
                PopupElement.textContent='Error occured while retrieving the MC-T Names. Refresh and try again. If the error continues, please contact the ADR team to fix it. ';
                ShowPopUp();
              });
          // return  MCTNames
        }
        if ((firstdropdown.value) && (seconddropdown.value))
        {        
          $.getJSON('/refreshAPI', {prjname: firstdropdown.value, prjpart: seconddropdown.value,prjpartid:partsArrIDsonly[seconddropdown.selectedIndex-1],},function(data11){
            refreshAPIbuutton(data11)
          
        })
        } 

        else  if (firstdropdown.value)
        {        
          $.getJSON('/refreshAPI', {prjname: firstdropdown.value, }
          ,function(data11){
            refreshAPIbuutton(data11)
          })

        }  
        else if (!firstdropdown.value){
          $.getJSON('/refreshAPI',function(data11){
  
            refreshAPIbuutton(data11)
          
        })
        }

}

var groupedValues = [];

function getpopuptext(){
  // Select all text input fields inside the modal
  const inputs = document.querySelectorAll('.modal-body input[type="text"], .modal-body input[type="number"]');
  const values = [];
  
  // Loop through the inputs and add their values to the array
  inputs.forEach(input => {
    values.push(input.value);
  });
  
  console.log("Collected input values:", values);

  // Group the values into subarrays of 4
  // const groupedValues = [];
  for (let i = 0; i < values.length; i += 4) {
    groupedValues.push(values.slice(i, i + 4));
  }
  
  console.log("Grouped input values:", groupedValues);
  
  return groupedValues;

}

</script>