~amsn-daily/amsn/amsn-packaging

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
::Version::setSubversionId {$Id$}

package require BWidget

#TODO:
#Put items frame and listbox in scrollbars!!


namespace eval Preferences {

	proc Show {} {

		if [winfo exists .prefs] {
			raise .prefs
			catch {focus -force .prefs}
			return
		}

		#Set pixmaps
		::skin::setPixmap prefpers prefpers.gif
		::skin::setPixmap prefprofile prefprofile.gif
		::skin::setPixmap preffont preffont.gif
		::skin::setPixmap prefphone prefphone.gif

		::skin::setPixmap preflook preflook.gif
		::skin::setPixmap prefemotic prefemotic.gif
		::skin::setPixmap prefalerts prefalerts.gif


		if { [LoginList exists 0 [::config::getKey login]] == 1 } {
			PreferencesWindow .prefs -title "[trans preferences] - [trans profiledconfig] - [::config::getKey login]" -savecommand ::Preferences::Save
		} else {
			PreferencesWindow .prefs -title "[trans preferences] - [trans defaultconfig] - [::config::getKey login]" -savecommand ::Preferences::Save
		}

		#####################################################
		# Section "Personal"
		#####################################################
		set section [PreferencesSection .prefs.personal -text [trans personal]]

		set frame [ItemsFrame .prefs.personal.nicks -text [trans prefname] -icon prefpers]
		$frame addItem [TextEntry .prefs.personal.nicks.nick -width 40 -text "[trans enternick] :" \
			-storecommand ::Preferences::StoreNick -retrievecommand [list ::abook::getPersonal MFN]]
		$frame addItem [TextEntry .prefs.personal.nicks.chat -width 40 -text "[trans friendlyname] :" \
			-variable [::config::getVar p4c_name]]
		$section addItem $frame

		set frame [ItemsFrame .prefs.personal.preffont -text [trans preffont] -icon preffont]
		$frame addItem [Label .prefs.personal.preffont.lab -text [trans preffont2] -align center]
		$frame addItem [CommandButton .prefs.personal.preffont.changefont -text [trans changefont] \
			-variable [::config::getVar mychatfont] -buttoncommand ::Preferences::ChangeFont]
		$frame addItem [CommandButton .prefs.personal.preffont.changeincomingfont -text [trans changefont] \
			-variable [::config::getVar theirchatfont] -buttoncommand ::Preferences::ChangeFont]
		$section addItem $frame

		set frame [ItemsFrame .prefs.personal.prefphone -text [trans prefphone] -icon prefphone]
		#$frame addItem [Label create .prefs.personal.prefphone.lab -text [trans prefphone2]]
		$frame addItem [TextEntry .prefs.personal.prefphone.home -text "[trans myhomephone]:" -width 20 \
			-retrievecommand [list ::abook::getPersonal PHH]]
		$frame addItem [TextEntry .prefs.personal.prefphone.work -text "[trans myworkphone]:" -width 20 \
			-retrievecommand [list ::abook::getPersonal PHW]]
		$frame addItem [TextEntry .prefs.personal.prefphone.mobile -text "[trans mymobilephone]:" -width 20 \
			-retrievecommand [list ::abook::getPersonal PHM]]
		$frame addItem [CheckBox .prefs.personal.prefphone.allowsms -text [trans allow_sms] \
			-onvalue "Y" -offvalue "N" -storecommand [list ::abook::setPhone pager] -retrievecommand [list ::abook::getPersonal MOB]]
		$section addItem $frame


		.prefs addSection $section

		####################################################
		# Section Interface
		#####################################################
		set section [PreferencesSection interface -text [trans appearance]]
		.prefs addSection $section

		set frame [ItemsFrame look -text [trans preflook] -icon preflook]
		$frame addItem [Label preflook.labenc -text "[trans encoding2]:" -align left]
		$frame addItem [CommandButton preflook.encoding -text [trans encoding] -align left\
			-variable [::config::getVar encoding] -buttoncommand ::Preferences::ChangeEncoding]

		$frame addItem [Label preflook.labfont -text "[trans preffont3]:" -align left]
		$frame addItem [CommandButton preflook.font -text [trans changefont] -align left\
			-variable [::config::getGlobalVar basefont] -buttoncommand ::Preferences::ChangeBaseFont]

		$frame addItem [Label preflook.labdate -text "[trans dateformat]:" -align left]
		$frame addItem [RadioGroup preflook.date \
			-texts [list "[trans month]/[trans day]/[trans year]" "[trans day]/[trans month]/[trans year]" "[trans year]/[trans month]/[trans day]"] \
			-values [list MDY DMY YMD] -variable [::config::getVar dateformat]]

		$section addItem $frame

		####################################################
		# Section ...
		#####################################################
		set section [PreferencesSection .prefs.caca -text "Test"]
		$section addSection [PreferencesSection .prefs.caca2 -text "Test2"]
		$section addSection [PreferencesSection .prefs.caca3 -text "Test3"]

		.prefs addSection $section

		.prefs show .prefs_window

		Configure 1

	}

	proc Configure { {fullinit 0} } {

		if {![winfo exists .prefs]} {
			return
		}

		if { $fullinit } {

			.prefs.personal.nicks.chat setValue [::config::getKey p4c_name]
			if { [::MSN::myStatusIs] == "FLN" } {
				.prefs.personal.nicks.nick configure -enabled 0
				.prefs.personal.prefphone.home configure -enabled 0
				.prefs.personal.prefphone.work configure -enabled 0
				.prefs.personal.prefphone.mobile configure -enabled 0
				.prefs.personal.prefphone.allowsms configure -enabled 0

			} else {
				.prefs.personal.nicks.nick configure -enabled 1
				.prefs.personal.prefphone.home configure -enabled 1
				.prefs.personal.prefphone.work configure -enabled 1
				.prefs.personal.prefphone.mobile configure -enabled 1
			}
			if { [::abook::getPersonal MBE] == "N" } {
				.prefs.personal.prefphone.allowsms -enabled 0
			}
		}


	}

	proc Save {} {

		set must_restart 0

		# Check and save phone numbers
		if { [::MSN::myStatusIs] != "FLN" } {
			#set lfname [Rnotebook:frame $nb $Preftabs(personal)]
			set home [urlencode [.prefs.personal.prefphone.home getValue]]
			set work [urlencode [.prefs.personal.prefphone.work getValue]]
			set mobile [urlencode [.prefs.personal.prefphone.mobile getValue]]
			if { $home != [::abook::getPersonal PHH] } {
				::abook::setPhone home $home
			}
			if { $work != [::abook::getPersonal PHW] } {
				::abook::setPhone work $work
			}
			if { $mobile != [::abook::getPersonal PHM] } {
				::abook::setPhone mobile $mobile
			}
		}

		if { [preflook.font getValue] != [::config::getGlobalKey basefont]} {
			set must_restart 1
		}

		if { $must_restart } {
			msg_box [trans mustrestart]
		}

		::Event::fireEvent changedPreferences gui

	}


	proc ChangeFont { currentfont } {

		#Get current font configuration
		set fontname [lindex $currentfont 0]
		set fontstyle [lindex $currentfont 1]
		set fontcolor [lindex $currentfont 2]

		if { [catch {
				set selfont_and_color [SelectFont .fontsel -parent .prefs_window -title [trans choosebasefont] -font [list $fontname 12 $fontstyle] -initialcolor "#$fontcolor"]
			}]} {

			set selfont_and_color [SelectFont .fontsel -parent .prefs_window -title [trans choosebasefont] -font [list "helvetica" 12 [list]] -initialcolor "#000000"]

		}

		set selfont [lindex $selfont_and_color 0]
		set selcolor [lindex $selfont_and_color 1]

		if { $selfont == ""} {
			return $currentfont
		}

		set sel_fontfamily [lindex $selfont 0]
		set sel_fontstyle [lrange $selfont 2 end]


		if { $selcolor == "" } {
			set selcolor $fontcolor
		} else {
			set selcolor [string range $selcolor 1 end]
		}

		return [list $sel_fontfamily $sel_fontstyle $selcolor]
	}

	proc ChangeBaseFont {currentfont} {
		if { [winfo exists .basefontsel] } {
			raise .basefontsel
			return
		}


		if { [catch {
			set font [SelectFont .basefontsel -parent .prefs_window -title [trans choosebasefont] -font $currentfont -styles [list]]
			}]} {

			set font [SelectFont .basefontsel -parent .prefs_window -title [trans choosebasefont] -font [list "helvetica" 12 [list]] -styles [list]]

		}

		set family [lindex $font 0]
		set size [lindex $font 1]

		if { $family == "" || $size == ""} {
			return $currentfont
		}

		return [list $family $size normal]
	}

	proc ChangeEncoding { currentenc } {
		::amsn::messageBox "TODO" yesno question "[trans confirm]" .prefs_window
	}

	proc StoreNick { nick } {
		if {$nick != "" && $nick != [::abook::getPersonal MFN] && [::MSN::myStatusIs] != "FLN" && [::config::getKey emailVerified 1] == 1} {
			::MSN::changeName $nick
		}
	}
	proc StorePSM { psm } {
		if {$psm != "" && $psm != [::abook::getPersonal PSM] && [::MSN::myStatusIs] != "FLN"} {
			::MSN::changePSM $psm
		}
	}

}

#This object type is a generic and abstract preference item.
# OPTIONS
# -variable	The variable where the value will be stored/retrieved
# -retrievecommand
#		A command that needs to be called to retrieve the initial value of the text entry
# -storecommand
#		A command that needs to be called to store the value of the text entry when the "store"
#		method is called. The command will be appended one argument, the text entry value
# -enabled	Enables or disabled the item
# METHODS
# getValue()	Return the current value of the item
# setValue(val) Sets the value of the item
# draw(path)	Draws the item inside the specified container
# store()	Store the item value in the related variable
::snit::type PreferenceItem {

	#The variable where the items stores its data
	option -variable -readonly no -default ""
	#The command that must be executed to retrieve the value. This command should return the variable value
	option -retrievecommand -readonly no -default ""
	#The command that must be executed to store the command. The value in the widget will be appended as parameter to the command
	option -storecommand -readonly no -default ""

	#Enable or disable the item
	option -enabled -default true

	##########################################
	#Common methods for all preference items
	##########################################

	constructor {args} {
		$self configurelist $args
	}

	onconfigure -variable { val } {
		upvar $val var
		$self setValue $var
		set options(-variable) $val
	}
	onconfigure -retrievecommand { val } {
		$self setValue [eval $val]
		set options(-retrievecommand) $val
	}

	variable value ""

	#Return the item value
	method getValue {} {
		return $value
	}

	#Set the item value
	method setValue {new_val} {
		set value $new_val
	}

	#Draw the element in the given widget path (path must be a container)
	method draw {path} {
		label $path.l -text "Preference item"
		pack $path.l
	}

	#Store the object values
	method store {} {
		if {!$options(-enabled)} {
			status_log "$self disabled, not storing\n" blue
			return
		}
		status_log "Storing $self, value [$self getValue]\n" blue
		if { $options(-variable) != "" } {
			status_log "   in variable $options(-variable)\n" blue
			upvar $options(-variable) var
			set var [$self getValue]
		}
		if { $options(-storecommand) != "" } {
			status_log "   with command $options(-storecommand)\n" blue
			eval [concat $options(-storecommand) [list [$self getValue]]]
		}

	}

	method valueVar {} {
		return [myvar value]
	}
}

#This type is child of PreferenceItem. It groups some options under a
#frame with a label and an icon.
#Usage:
# OPTIONS
# -text 	The text to be shown in the frame header
# -icon 	A picture to be shown at the left, inside the frame
# -expand 	The frame should expand in the container. Defaults to YES
# -fill		The frame should fill all available space in X, Y or BOTH. Defaults to X
# -enabled	The frame and contained items is enabled/disabled
# METHODS
# addItem(item)		Add a PreferenceItem inside this frame
::snit::type ItemsFrame {

	#Delegate to PreferenceItem by default
	delegate method * to preferenceitem
	delegate option * to preferenceitem

	#The widget path to this item
	variable itemPath ""
	#The items contained inside the frame
	variable items [list]

	constructor {args} {
		install preferenceitem using PreferenceItem %AUTO%
		$self configurelist $args
	}

	destructor {
		#Destroy the PreferenceItem object
		$preferenceitem destroy

		#Destroy child items
		foreach item $items {
			$item destroy
		}

		#Destroy the container frame
		if [winfo exists $itemPath.f] {
			destroy $itemPath.f
		}

	}

	#########################
	#Static options (creation time)
	#########################

	#Text for the item label
	option -text -readonly yes -default ""
	#Icon for the frame
	option -icon -readonly yes -default ""
	#Options for packing the frame
	option -expand -readonly yes -default true
	option -fill -readonly yes -default x

	#########################
	#Dinamic options
	#########################
	option -enabled -default true

	#Add a new PreferenceItem to the group
	method addItem {item} {
		lappend items $item
	}

	#Triggered when the -enabled option is changed
	onconfigure -enabled { val } {
		set options(-enabled) $val
		$preferenceitem configure -enabled $val
		#Now tell all the children to enable themshelves
		set num 0
		foreach item $items {
			$item configure -enabled $val
		}
	}


	#Create the label frame and icon, and tell all children items to draw themshelves
	method draw { path } {

		#Store the path for later usage
		set itemPath $path

		#Create and pack the labelframe
		set f [labelframe $path.f -text $options(-text) -font splainf]
		pack $path.f -side top -fill x

		#If there is an icon, draw it
		if { $options(-icon) != "" } {
			frame $f.f
			label $f.icon -image [::skin::loadPixmap $options(-icon)]
			pack $f.icon -side left -padx 5 -pady 5
			pack $f.f -side left -fill x -expand true

			set f $f.f
		}

		#Now tell all the children to draw themshelves, and pack them
		set num 0
		foreach item $items {
			set f2 $f.f$num
			frame $f2
			$item draw $f2
			pack $f2 -side top -expand $options(-expand) -fill $options(-fill)

			incr num
		}
	}

	#Tell all children to store themselves
	method store {} {
		foreach item $items {
			$item store
		}
	}

}

#A text entry item. Child of PreferenceItem
#Usage:
# OPTIONS
# -text 	The text to be shown next to the text entry
# -width	The width of the text entry
# -onchange	A command that is called everytime the text entry changes to validate the input
# -enabled	Enables or disabled the text entry
# METHODS
::snit::type TextEntry {

	#Delegate to PrferenceItem!!
	delegate method * to preferenceitem
	delegate option * to preferenceitem

	#Enable or disable the item
	option -enabled -default true

	#The widget path
	variable itemPath ""

	constructor {args} {
		install preferenceitem using PreferenceItem %AUTO%
		$self configurelist $args
	}

	destructor {
		#Destroy the PreferenceItem instance
		$preferenceitem destroy
		#Destroy widgets
		destroy $itemPath.l
		destroy $itemPath.t
	}

	#########################
	#Static options (creation time)
	#########################
	#Command to be triggered when the item changes
	option -onchange -readonly yes -default ""

	#Text for the item label
	option -text -readonly yes -default ""
	#With of the textfield
	option -width -readonly yes -default ""

	#########################
	#Dinamic options
	#########################

	#Triggered when the -enabled option is changed
	onconfigure -enabled { val } {
		set options(-enabled) $val
		$preferenceitem configure -enabled $val
		if {[winfo exists $itemPath.t]} {
			if { $val } {
				$itemPath.t configure -state normal
			} else {
				$itemPath.t configure -state disabled
			}
		}
	}

	#Draw the text box in the given path
	method draw { path } {

		set itemPath $path
		#Draw an input box

		#Composed by a label... and...
		label $path.l -text $options(-text) -font sboldf

		if { $options(-enabled) } {
			set state normal
		} else {
			set state disabled
		}

		if { $options(-onchange) != "" } {
			set validatecommand [list $options(-onchange) $self %s %S]
		} else {
			set validatecommand ""
		}

		#...a text entry (can have defined width or not)
		if { [string is integer -strict $options(-width)] } {
			entry $path.t -width $options(-width) -state $state -textvariable [$self valueVar] \
				-validate all -validatecommand $validatecommand
			pack $path.t -side right -expand false -padx 5 -pady 3
			pack $path.l -side right -expand false -padx 5 -pady 3
		} else {
			entry $path.t -state $state -textvariable [$self valueVar] \
				-validate all -validatecommand $validatecommand
			pack $path.t -side right -expand true -fill x -padx 5 -pady 3
			pack $path.l -side right -expand false -padx 5 -pady 3
		}
	}

}

#A check box item. Child of PreferenceItem
#Usage:
# OPTIONS
# -text 	The text to be shown next to the check button
# -onchange	A command that is called everytime the check button value changes
# -enabled	Enables or disabled the checkbutton
# -onvalue	The value that the item will take when the checkbutton is checked. Defaults to 1
# -offvalue	The value that the item will take when the checkbutton is not checked. Defaults to 0
# METHODS
::snit::type CheckBox {

	#Delegate to PrferenceItem!!
	delegate method * to preferenceitem
	delegate option * to preferenceitem

	#Enable or disable the item
	option -enabled -default true

	#The widget path
	variable itemPath ""

	constructor {args} {
		install preferenceitem using PreferenceItem %AUTO%
		$self configurelist $args
	}

	destructor {
		#Destroy the PreferenceItem instance
		$preferenceitem destroy
		#Destroy widgets
		destroy $itemPath.c
	}

	#########################
	#Static options (creation time)
	#########################
	#Command to be triggered when the item changes
	option -onchange -readonly yes -default ""

	#Text for the item label
	option -text -readonly yes -default ""
	#ON/OFF values
	option -onvalue -readonly yes -default 1
	option -offvalue -readonly yes -default 0

	#########################
	#Dynamic options
	#########################

	#Triggered when the -enabled option is changed
	onconfigure -enabled { val } {
		set options(-enabled) $val
		$preferenceitem configure -enabled $val
		if {[winfo exists $itemPath.c]} {
			if { $val } {
				$itemPath.c configure -state normal
			} else {
				$itemPath.c configure -state disabled
			}
		}
	}


	#Draw the text box in the given path
	method draw { path } {

		set itemPath $path
		#Draw an input box

		if { $options(-enabled) } {
			set state normal
		} else {
			set state disabled
		}

		if { $options(-onchange) != "" } {
			set changecommand [list $options(-onchange) $self %s %S]
		} else {
			set changecommand ""
		}

		#...a checkbutton entry
		checkbutton $path.c -text $options(-text) -font sboldf -state $state -variable [$self valueVar] \
			-command $changecommand -onvalue $options(-onvalue) -offvalue $options(-offvalue)

		pack $path.c -side right -expand false -padx 5 -pady 3
	}

}

#A group of radio buttons. Child of PreferenceItem
#Usage:
# OPTIONS
# -texts	A list with one text for every checkbutton
# -values	A list of values corresponding to every selection. Defaults to 0, 1, 2...
# -onchange	A command that is called everytime the radio button value changes
# -enabled	Enables or disabled the radio buttons
# METHODS
::snit::type RadioGroup {

	#Delegate to PrferenceItem!!
	delegate method * to preferenceitem
	delegate option * to preferenceitem

	#Enable or disable the item
	option -enabled -default true

	#The widget path
	variable itemPath ""

	constructor {args} {
		install preferenceitem using PreferenceItem %AUTO%
		$self configurelist $args
	}

	destructor {
		#Destroy the PreferenceItem instance
		$preferenceitem destroy
		#Destroy widgets
		destroy $itemPath.f
	}

	#########################
	#Static options (creation time)
	#########################
	#Command to be triggered when the item changes
	option -onchange -readonly yes -default ""

	#Text for the item label
	option -texts -readonly yes -default [list]
	option -values -readonly yes -default [list]

	#########################
	#Dynamic options
	#########################

	#Triggered when the -enabled option is changed
	onconfigure -enabled { val } {
		set options(-enabled) $val
		$preferenceitem configure -enabled $val
		if {[winfo exists $itemPath.f]} {
			foreach child [winfo children $itemPath.f] {
				if { $val } {
					$child configure -state normal
				} else {
					$child configure -state disabled
				}
			}
		}
	}


	#Draw the text box in the given path
	method draw { path } {

		set itemPath $path
		#Draw an input box

		if { $options(-enabled) } {
			set state normal
		} else {
			set state disabled
		}

		if { $options(-onchange) != "" } {
			set changecommand [list $options(-onchange) $self %s %S]
		} else {
			set changecommand ""
		}

		frame $path.f

		set i 0
		foreach text $options(-texts) {
			radiobutton $path.f.rb$i -text $text -font sboldf -state $state -variable [$self valueVar] \
				-command $changecommand -value [lindex $options(-values) $i]
			pack $path.f.rb$i -side top -anchor nw
			incr i
		}

		pack $path.f -side left -expand false -padx 5 -pady 3
	}

}


#A command button. Child of PreferenceItem
#Usage:
# OPTIONS
# -text 	The text to be shown in the button
# -buttoncommand
#		The command that will be launched when the button is pressed. When this happens, the current item value will be appended as
#		a parameter to this command. The return value of the command is then stored as new item value
# -enabled	Enables or disabled the checkbutton
# METHODS
::snit::type CommandButton {

	#Delegate to PrferenceItem!!
	delegate method * to preferenceitem
	delegate option * to preferenceitem

	#The variable where the items stores its data
	option -buttoncommand -readonly yes -default ""

	#Enable or disable the item
	option -enabled -default true

	#The widget path
	variable itemPath ""

	constructor {args} {
		install preferenceitem using PreferenceItem %AUTO%
		$self configurelist $args
	}

	destructor {
		#Destroy the PreferenceItem instance
		$preferenceitem destroy
		#Destroy widgets
		destroy $itemPath.b
	}

	#########################
	#Static options (creation time)
	#########################
	#Text for the item label
	option -text -readonly yes -default ""
	option -align -readonly yes -default center

	#########################
	#Dynamic options
	#########################

	#Triggered when the -enabled option is changed
	onconfigure -enabled { val } {
		set options(-enabled) $val
		$preferenceitem configure -enabled $val
		if {[winfo exists $itemPath.b]} {
			if { $val } {
				$itemPath.b configure -state normal
			} else {
				$itemPath.b configure -state disabled
			}
		}
	}

	#Draw the button in the given path
	method draw { path } {

		set itemPath $path
		#Draw an input box

		if { $options(-enabled) } {
			set state normal
		} else {
			set state disabled
		}

		switch $options(-align) {
			left {
				set anchor w
			}
			right {
				set anchor e
			}
			default {
				set anchor center
			}

		}

		button $path.b -text $options(-text) -font sboldf -state $state -command [mymethod buttonPressed]
		pack $path.b -expand false -padx 5 -pady 3 -anchor $anchor
	}


	method buttonPressed {} {
		if { $options(-buttoncommand) != "" } {
			set the_command [concat $options(-buttoncommand) [list [$self getValue]]]
			set value [eval $the_command]
			$self setValue $value
		}

	}
}



#A text entry item. Child of PreferenceItem
#Usage:
# OPTIONS
# -text		The text that is shown in the label
# -align	right | left | center
::snit::type Label {

	#Delegate to PrferenceItem!!
	delegate method * to preferenceitem
	delegate option * to preferenceitem

	#The widget path
	variable itemPath ""

	constructor {args} {
		install preferenceitem using PreferenceItem %AUTO%
		$self configurelist $args

	}

	destructor {
		#Destroy the PreferenceItem instance
		$preferenceitem destroy
		#Destroy widgets
		destroy $itemPath.l
	}

	#########################
	#Static options (creation time)
	#########################

	#Text for the item label
	option -text -readonly yes -default ""
	option -align -readonly yes -default center

	#########################
	#Dinamic options
	#########################

	#Draw the text box in the given path
	method draw { path } {

		switch $options(-align) {
			left {
				set anchor w
			}
			right {
				set anchor e
			}
			default {
				set anchor center
			}

		}


		set itemPath $path
		label $path.l -text $options(-text) -font splainf
		pack $path.l -anchor $anchor
	}
}


::snit::widget PreferencesWindow {

	#Object is a children of PreferencesSection
	delegate method * to preferencessection

	#Window title
	option -title ""
	option -savecommand ""

	constructor {args} {
		install preferencessection using PreferencesSection %AUTO%
		$self configurelist $args
	}

	destructor {
		#Destroy the instance of the parent.
		#This will destroy subsections too
		$preferencessection destroy

		#Destroy the window
		if { [winfo exists $wname] } {
			destroy $wname
		}

	}

	#A list with section objects, one per listbox element
	variable sectionNames [list]
	variable wname ""

	#Show the preferences window
	method show { path } {

		#Create a window name and remember it
		set wname $path

		#Create the toplevel window
		toplevel $wname
		wm title $wname $options(-title)
    		bind $wname <Destroy> [list $self destroyWindow %W]
		bind $wname <<Escape>> [list destroy $wname]

		#Create the buttons
		set w [frame $wname.buttons]
		button $w.save -text [trans save] -default active -command [list $self savePressed]
		button $w.cancel -text [trans close] -command [list destroy $wname]
		pack $w.save $w.cancel -side right -padx 10 -pady 5
		pack $w -side bottom -fill x -expand false

		#Create the sections listbox and items area
		set w [frame $wname.top]

		#Create the sections listbox
		listbox $w.sections -width 15
		#Create the items frame
		frame $w.items

		#Do the packing
		pack $w.sections -side left -fill y
		pack $w.items -side right -fill both -expand true
		bind $w.sections <<ListboxSelect>> [list $self sectionSelected]
		pack $w -side top -fill both -expand true

		#Add sections to the listbox
		foreach section [$self getSectionsList] {
			set sectionNames [concat $sectionNames [$section insertIntoList $w.sections 0]]
		}

		wm geometry $wname 625x450
	}

	#Invoked when a section is selected in the listbox
	method sectionSelected { } {

		#Get the section object name from the sectionNames list
		set idx [$wname.top.sections curselection]
		set section [lindex $sectionNames $idx]

		#Create a new frames item, destroying previous one
		set items "$wname.top.items.f"
		if {[winfo exists $items]} {
			destroy $items
		}
		frame $items
		pack $items -anchor nw -fill both

		#Show the selected section
		$section show $items

	}

	method destroyWindow { w } {
		if { $w == $wname } {
			destroy $self
		}
	}

	method savePressed { } {
		if { $options(-savecommand) != "" } {
			$options(-savecommand)
		}

		$self storeItems

		destroy $wname
	}

}

#A section that contains zero, one or more preference items
::snit::type PreferencesSection {

	#List of items in this section
	variable items_list [list]
	#List of subsections
	variable sections_list [list]

	option -text -readonly yes -default ""

	destructor {
		#Destroy child items
		foreach item $items_list {
			$item destroy
		}
		#Destroy child sections
		foreach section $sections_list {
			$section destroy
		}
	}

	method getSectionsList { } {
		return $sections_list
	}

	method addItem { item } {
		lappend items_list $item
	}

	method addSection {section} {
		lappend sections_list $section
	}

	#Insert this section and all subsections in the given listbox.
	#Retuns a list of this section and all subsections names (recursive calls)
	method insertIntoList { lb level } {

		#Append instance to sections list
		set sectionNames $self

		#Set identation
		set ident ""
		for { set idx 0 } { $idx < $level } {incr idx } {
			set ident "$ident   "
		}

		#Add current section to the listbox
		$lb insert end "$ident$options(-text)"

		#Add all subsections and append the result of the function call to the sections list
		foreach subsection $sections_list {
			set sectionNames [concat $sectionNames [$subsection insertIntoList $lb [expr {$level + 1}]]]
		}

		#Return the sections list for this section and all subsections
		return $sectionNames
	}

	#Show the items in this section in the given path
	method show { path } {

		set idx 0

		foreach item $items_list {
			set f [frame $path.f$idx]
			$item draw $f
			pack $f -side top -fill x
			incr idx

		}
	}

	method storeItems { } {
		#Add all subsections and append the result of the function call to the sections list
		foreach subsection $sections_list {
			$subsection storeItems
		}
		foreach item $items_list {
			$item store
		}
	}

}


proc test2 {item oldval newval} {
	status_log "$item: old=$oldval new=$newval\n" blue
	return [string is integer $newval]
}

proc new_preferences {} {
	PreferencesWindow create .prefs

	PreferencesSection create .prefs.personal
	PreferencesSection create .prefs.personal.nick

	.prefs.personal addItem

	.pref_win
}



if { $initialize_amsn == 1 } {
	global myconfig proxy_server proxy_port proxy_user proxy_pass rbsel rbcon pgc

	###################### Preferences Window ###########################
	array set myconfig {}   ; # configuration backup
	set proxy_server ""
	set proxy_port ""
	set proxy_pass ""
	set proxy_user ""

	set pgc 1
}

proc PreferencesCopyConfig {} {
	global myconfig proxy_server proxy_port

	array set myconfig [::config::getAll]

	set proxy_server ""
	set proxy_port ""

	# Now process certain exceptions. Should be reverted
	# in the RestorePreferences procedure
	catch {
		set proxy_data $myconfig(proxy)
		set proxy_server [lindex $proxy_data 0]
		set proxy_port [lindex $proxy_data 1]
	}
}

## Function that makes the group list in the preferences ##
proc MakeGroupList { lfgroup lfcontact } {

	array set groups [::abook::getContactData contactlist groups]

	frame $lfgroup.lbgroup.fix
	pack $lfgroup.lbgroup.fix -side left -anchor n -expand 1 -fill x -padx 5 -pady 5
	label $lfgroup.lbgroup.fix.l -text \"[trans groups]\" -font sboldf
	pack $lfgroup.lbgroup.fix.l -side top -anchor w -pady 5

	frame $lfgroup.lbgroup.fix.list
	## create the listbox ##
	listbox $lfgroup.lbgroup.fix.list.lb -yscrollcommand "$lfgroup.lbgroup.fix.list.sb set"
	scrollbar $lfgroup.lbgroup.fix.list.sb -command "$lfgroup.lbgroup.fix.list.lb yview" -highlightthickness 0 \
		-borderwidth 1 -elementborderwidth 2

	pack $lfgroup.lbgroup.fix.list.lb -side left -anchor w -pady 0 -padx 0 -expand true -fill both
	pack $lfgroup.lbgroup.fix.list.sb -side left -anchor w -pady 0 -padx 0 -fill y
	pack $lfgroup.lbgroup.fix.list -side top -expand true -fill both


	## entries ##
	$lfgroup.lbgroup.fix.list.lb insert end "[trans nogroup]"
	foreach gr [lsort [array names groups]] {
		if { $groups($gr) != "Individuals" } {
			$lfgroup.lbgroup.fix.list.lb insert end $groups($gr)
		}
	}
	## make binding ##
	bind $lfgroup.lbgroup.fix.list.lb <<ListboxSelect>> "GroupSelectedIs $lfgroup $lfcontact"
}

## Function to be called when <<ListboxSelect>> event occurs to change rbsel value ##
proc GroupSelectedIs { lfgroup lfcontact } {
	global rbsel
	if {[$lfgroup.lbgroup.fix.list.lb curselection] != "" } {
		set rbsel [$lfgroup.lbgroup.fix.list.lb curselection]
		#Get the rbsel-th group. Note that groups must be inserted same order
		array set groups [::abook::getContactData contactlist groups]
		set rbsel [lindex [lsort [array names groups]] $rbsel]
		MakeContactList $lfcontact
	}
}

## Function to be called after pressing delete/rename/add group button ##
proc RefreshGroupList { lfgroup lfcontact } {
	global pgc pgcd
	if { $pgc == 1 } {
		vwait pgc
	}
	set pgc 1
	destroy $lfgroup.lbgroup.fix
	MakeGroupList $lfgroup $lfcontact
}

## Function to be called when a group is selected ##
proc MakeContactList { lfcontact } {
	global rbsel rbcon
	catch {DeleteContactList $lfcontact}

	if {![info exists rbsel]} { return; }
	if { ![::groups::Exists [::groups::GetName $rbsel]] || $rbsel == 0 } {
		if { $rbsel == 0 } {
			## fix the name of the group ##
			label $lfcontact.lbcontact.fix.l -text "[trans nogroup]" -font sboldf
			pack $lfcontact.lbcontact.fix.l -side top -pady 5 -padx 5  -anchor w
			frame $lfcontact.lbcontact.fix.list

			## create the listbox ##
			listbox $lfcontact.lbcontact.fix.list.lb -yscrollcommand "$lfcontact.lbcontact.fix.list.sb set"
			scrollbar $lfcontact.lbcontact.fix.list.sb -command "$lfcontact.lbcontact.fix.list.lb yview" -highlightthickness 0 \
				-borderwidth 1 -elementborderwidth 2

			pack $lfcontact.lbcontact.fix.list.lb -side left -anchor w -expand true -fill both
			pack $lfcontact.lbcontact.fix.list.sb -side left -anchor w -fill y
			pack $lfcontact.lbcontact.fix.list -side top -anchor w -pady 5 -padx 5 -expand true -fill both
			## list contacts that don't have a group ##
			set contacts [::MSN::getList FL]
			set contacts [concat $contacts [::MSN::getList EL]]
			set i 0
			while { $i < [llength $contacts] } {
				set contact [lindex $contacts $i]
				set g [::abook::getGroups $contact]
				if { [lindex $g 0] == 0 } {
					$lfcontact.lbcontact.fix.list.lb insert end $contact
				}
				incr i
			}
		## make the binding ##
		bind $lfcontact.lbcontact.fix.list.lb <<ListboxSelect>> "ContactSelectedIs $lfcontact"
		}
	} else {
		label $lfcontact.lbcontact.fix.l -text "[::groups::GetName $rbsel]" -font sboldf
		pack $lfcontact.lbcontact.fix.l -side top -pady 5 -padx 5 -anchor w
		frame $lfcontact.lbcontact.fix.list

		## create the listbox ##
		listbox $lfcontact.lbcontact.fix.list.lb -yscrollcommand "$lfcontact.lbcontact.fix.list.sb set"
		scrollbar $lfcontact.lbcontact.fix.list.sb -command "$lfcontact.lbcontact.fix.list.lb yview" -highlightthickness 0 \
			-borderwidth 1 -elementborderwidth 2

		pack $lfcontact.lbcontact.fix.list.lb -side left -anchor w -expand true -fill both
		pack $lfcontact.lbcontact.fix.list.sb -side left -anchor w -fill y
		pack $lfcontact.lbcontact.fix.list -side top -anchor w -pady 5 -padx 5 -expand true -fill both

		set groups [::abook::getContactData contactlist groups]
		set contacts [::MSN::getList FL]
		set contacts [concat $contacts [::MSN::getList EL]]
		set i 0
		while { $i < [llength $contacts] } {
			set contact [lindex $contacts $i]
			set group [::abook::getGroups $contact]
			set j 0
			while { $j < [llength $group] } {
				set g [lindex $group $j]
				if { $g == $rbsel } {
					$lfcontact.lbcontact.fix.list.lb insert end $contact
				}
				incr j
			}
			incr i
		}
		## make the binding ##
		bind $lfcontact.lbcontact.fix.list.lb <<ListboxSelect>> "ContactSelectedIs $lfcontact"
	}
}

## Function to be called when <<ListboxSelect>> event occurs to change rbsel value ##
proc ContactSelectedIs { lfcontact } {
	global rbcon
	if {[$lfcontact.lbcontact.fix.list.lb curselection] != "" } {
		set rbcon [$lfcontact.lbcontact.fix.list.lb get [$lfcontact.lbcontact.fix.list.lb curselection]]
	} else {
		set rbcon ""
	}
}

## Function to be called when the selected group becomes unvalid ##
proc DeleteContactList { lfcontact } {
	destroy $lfcontact.lbcontact.fix
	frame $lfcontact.lbcontact.fix
	pack $lfcontact.lbcontact.fix -side left -anchor n -expand 1 -fill x
}

## Function to be called when the selected group is deleted/renamed or a contact deleted/moved/copied/added ##
proc RefreshContactList { lfcontact } {
	global pcc
	if { $pcc == 1 } {
		vwait pcc
	}
	set pcc 1
	DeleteContactList $lfcontact
	MakeContactList $lfcontact
}

proc dlgMoveUser {} {
	global rbcon rbsel gsel pcc
	if {![info exists rbcon]} {return;}
	if {![info exists rbsel]} {return;}
	## check if window exists ##
	if { [winfo exists .dlgmu] } {
		set pcc 0
		return 0
	}
	## if no contact is selected -- return ##
	if { $rbcon == "" } {
		set pcc 0
		return 0
	}
	## calculate oldgid - now we get the first group int the group list - we have to improve it ##
	set oldgid [::abook::getGroups $rbcon]
	set oldgid [lindex $oldgid 0]
	## variable for the selected group -- we set to oldgid to avoid bugs ##
	set gsel $oldgid

	set bgcol2 #ABC8D2
	toplevel .dlgmu -highlightcolor $bgcol2
	wm title .dlgmu "[trans moveuser]"
	## radiobuttons for newgid ##
	frame .dlgmu.d
	array set groups [::abook::getContactData contactlist groups]
	foreach gr [array names groups] {
		if { $groups($gr) != "Individuals" } {
			radiobutton .dlgmu.d.$gr -text "$groups($gr)" -value $gr -variable gsel
			pack .dlgmu.d.$gr -side left
		}
	}
	pack .dlgmu.d -side top -pady 3 -padx 5
	## button options ##
	frame .dlgmu.b
	button .dlgmu.b.ok -text "[trans ok]"  -font sboldf \
		-command " if {![info exists gsel]} {return;}; \
			::MSN::moveUser \$rbcon $oldgid \$gsel; \
			unset gsel; \
			destroy .dlgmu; "
	button .dlgmu.b.cancel -text "[trans cancel]"  -font sboldf \
		-command "destroy .dlgmu; set pcc 0;"
	pack .dlgmu.b.ok .dlgmu.b.cancel -side right -padx 5
	pack .dlgmu.b  -side top -anchor e -pady 3
}

proc dlgCopyUser {} {
	global rbcon rbsel gsel pcc
	if {![info exists rbcon]} {return;}
	if {![info exists rbsel]} {return;}
	if { [winfo exists .dlgcu] } {
		set pcc 0
		return 0
	}
	## if no contact is selected -- return ##
	if { $rbcon == "" } {
		set pcc 0
		return 0
	}
	## calculate oldgid - now we get the first group int the group list - we have to improve it ##
	set oldgid [::abook::getGroups $rbcon]
	set oldgid [lindex $oldgid 0]
	## protection --> the contacts who are in 'nogroup' will be moved, not copied ##
	set move 0
	if { $oldgid == 0 } {
		set move 1
	}
	## variable for the selected group -- we set to oldgid to avoid bugs ##
	set gsel $oldgid

	set bgcol2 #ABC8D2
	toplevel .dlgcu -highlightcolor $bgcol2
	wm title .dlgcu "[trans moveuser]"
	## radiobuttons for newgid ##
	frame .dlgcu.d
	array set groups [::abook::getContactData contactlist groups]
	foreach gr [array names groups] {
		if { $groups($gr) != "Individuals" } {
			radiobutton .dlgcu.d.$gr -text "$groups($gr)" -value $gr -variable gsel
			pack .dlgcu.d.$gr -side left
		}
	}
	pack .dlgcu.d -side top -pady 3 -padx 5
	## button options ##
	frame .dlgcu.b
	if { $move == 0 } {
		button .dlgcu.b.ok -text "[trans ok]"  -font sboldf \
			-command " if {![info exists gsel]} {return;}; \
				::MSN::copyUser \$rbcon \$gsel; \
				unset gsel; \
				destroy .dlgcu; "
	}
	if { $move == 1 } {
		button .dlgcu.b.ok -text "[trans ok]" -font sboldf \
			-command " if {![info exists gsel]} {return;}; \
				::MSN::moveUser \$rbcon $oldgid \$gsel; \
				unset gsel; \
				destroy .dlgcu; "
	}
	button .dlgcu.b.cancel -text "[trans cancel]"  -font sboldf \
		-command "destroy .dlgcu; set pcc 0;"
	pack .dlgcu.b.ok .dlgcu.b.cancel -side right -padx 5
	pack .dlgcu.b  -side top -anchor e -pady 3
}

proc connection_check { lfname } {
	$lfname.1.ftport.bttest configure -state disabled
	$lfname.1.ftport.test configure -text [trans connecting]
	::abook::getIPConfig
	if {[winfo exists $lfname]} {
		if { [::abook::getDemographicField conntype] == "" } {
			$lfname.1.listening configure -text "[trans connectfirst]" -fg [::skin::getKey extrastderrcolor]
			$lfname.1.ftport.test configure -text "[trans connectfirst]" -fg [::skin::getKey extrastderrcolor]
		} else {
			if { [::abook::getDemographicField listening] == "false"} {
				$lfname.1.listening configure -text "[trans firewalled]" -fg [::skin::getKey extrastderrcolor]
				$lfname.1.ftport.test configure -text "[trans firewalled]" -fg [::skin::getKey extrastderrcolor]
			} else {
				$lfname.1.listening configure -text "[trans portswellconfigured]" -fg [::skin::getKey extrastdokcolor]
				$lfname.1.ftport.test configure -text "[trans ok]" -fg [::skin::getKey extrastdokcolor]
			}
		}
		$lfname.1.ftport.bttest configure -state normal
	}

}

# hide an option from the advanced preferences pane
proc hide_option { w {w_exp ""} } {
	if {!([catch {pack info $w}])} {
		pack forget $w
	}
	if {$w_exp != "" && !([catch {pack info $w_exp}])} {
		pack forget $w_exp
	}
}

# show an option from the advanced preferences pane
proc show_option { w name oldw {w_exp ""}} {
	if {$w_exp != "" && [catch {pack info $w_exp}]} {
		if {$oldw != ""} {
			pack $w_exp -anchor w -padx 15 -before $oldw
		} else {
			pack $w_exp -anchor w -padx 15
		}
		set oldw $w_exp
	}
	if {[catch {pack info $w}]} {
		set command [list pack $w]
		# pack options courtesy of advanced_options_reload procedure
		switch -glob $name {
			[0-9]* {
				lappend command -side top -padx 0 -fill x
			}
			cb* {
				lappend command -anchor w
			}
			le* -
			fr* {
				lappend command -anchor w -expand true -fill x
			}
			sp* {
				lappend command -anchor w -side top -anchor w -pady 4
			}
			l* {
				lappend command -anchor w -side top -anchor w -pady 4
			}
			default {
				return
			}
		}
		# oldw is the option *below* the current one
		if {$oldw != ""} {
			lappend command -before $oldw
		}
		eval $command
	}
}

proc filter_prefs { frm str action } {
	# action = -1 -> search box focused (do nothing)
	if {$action == -1} { return 1 }

	set optionlist [winfo children $frm]
	set oldoption ""
	# isempty means "there are no options visible below the current one"
	# as we go through the options from bottom to top, it's initialized to 1
	set isempty 1
	# isglobalempty means "the frame is completely empty"
	set isglobalempty 1
	# cycles through the list in reverse order
	set l [llength $optionlist]
	for {set i $l} {$i >= 0} {incr i -1} {
		set option [lindex $optionlist $i]
		set option_exp ""
		set text ""
		set name [regexp -inline -- (?:cb|exp|le|fr|l|sp)?\[0-9\]+$ $option]
		switch -glob $name {
			[0-9]* {
				# workaround for the date delimitators option
				catch {set text [$option.delimiters cget -text]}
			}
			cb* {
				catch {set text [$option cget -text]}
			}
			exp* {
				continue
			}
			le* {
				catch {set text [$option.lbl cget -text]}
			}
			fr* {
				catch {set text [$option.le.lbl cget -text]}
			}
			l* {
				if {$isempty} {
					# hide the title if there are no options below it
					hide_option $option
				} else {
					show_option $option $name $oldoption
					set oldoption $option
				}
				continue
			}
			sp* {
				if {$isempty} {
					hide_option $option
				} else {
					show_option $option $name $oldoption
					set oldoption $option
					# here begins a new section, so isempty is initialized
					set isempty 1
				}
				continue
			}
			default {
				set oldoption $option
				continue
			}
		}
		set j [regsub -all \[^0-9\] $name ""]
		set option_exp [regsub $name\$ $option exp$j]
		if {[winfo exists $option_exp]} {
			set text [join [list $text " " [$option_exp cget -text]]]
		} else {
			set option_exp ""
		}
		if {$text != ""} {
			if {$str == "" || [string first [string tolower $str] [string tolower $text]] != -1} {
				show_option $option $name $oldoption $option_exp
				set oldoption $option
				if {$isglobalempty} {
					set isglobalempty 0
				}
				if {$isempty} {
					set isempty 0
				}
			} else {
				hide_option $option $option_exp
			}
		}
	}
	# hide leading space
	if {[regexp -- sp\[0-9\]+$ $oldoption]} {
		hide_option $oldoption
	}
	# if the frame is empty, add a spacer to avoid the scrollbar bug
	# the name of the spacer MUST NOT begin with "sp" or it will be handled
	# as a normal spacer
	if {$isglobalempty} {
		catch {label $frm.bugfix_spacer -font bboldf}
		pack $frm.bugfix_spacer -side top -anchor w -pady 4
	} else {
		destroy $frm.bugfix_spacer
	}
	return 1
}

proc Preferences { { settings "personal"} } {
	global myconfig proxy_server proxy_port temp_BLP list_BLP Preftabs libtls proxy_user proxy_pass rbsel rbcon pager

	set temp_BLP $list_BLP
	::config::setKey libtls_temp $libtls
	set pager "N"
	if {[ winfo exists .cfg ]} {
		raise .cfg

		# This should raise the settings tab depending on the arg..
		catch {.cfg.notebook.nn raise $settings}

		return
	}

	PreferencesCopyConfig	;# Load current configuration

	toplevel .cfg
	wm state .cfg withdraw

	if { [LoginList exists 0 [::config::getKey login]] == 1 } {
		wm title .cfg "[trans preferences] - [trans profiledconfig] - [::config::getKey login]"
	} else {
		wm title .cfg "[trans preferences] - [trans defaultconfig] - [::config::getKey login]"
	}

	wm iconname .cfg [trans preferences]

	# Frame to hold the preferences tabs/notebook
	frame .cfg.notebook

	#set nb .cfg.notebook.nn
	set nb .cfg.notebook

	# Preferences Notebook
	# Modified Rnotebook to translate automaticly those keys in -tabs {}
	#Rnotebook:create $nb -tabs {personal appearance session privacy loging connection others advanced} -borderwidth 2
	    #set Preftabs(personal) 1
        #set Preftabs(appearance) 2
        #set Preftabs(session) 3
        #set Preftabs(privacy) 4
        #set Preftabs(loging) 5
        ##BLOCKING
	#set Preftabs(blocking) 6
        #set Preftabs(connection) 6
        #set Preftabs(others) 7
        #set Preftabs(advanced) 8
	NoteBook $nb.nn
	$nb.nn insert end personal -text [trans personal]
	$nb.nn insert end appearance -text [trans appearance]
	$nb.nn insert end session -text [trans session]
	$nb.nn insert end groups -text [trans groups]
	$nb.nn insert end privacy -text [trans privacy]
	$nb.nn insert end loging -text [trans loging]
	$nb.nn insert end connection -text [trans connection]
	$nb.nn insert end others -text [trans others]
	$nb.nn insert end advanced -text [trans advanced]


	#  .----------.
	# _| Personal |________________________________________________
	::skin::setPixmap prefpers prefpers.gif
	::skin::setPixmap prefprofile prefprofile.gif
	::skin::setPixmap preflocale globe.png
	::skin::setPixmap preffont preffont.gif
	::skin::setPixmap prefphone prefphone.gif
	#set frm [Rnotebook:frame $nb $Preftabs(personal)]
	set frm [$nb.nn getframe personal]
	#Scrollable frame that will contain options
	ScrolledWindow $frm.sw
	ScrollableFrame $frm.sw.sf -constrainedwidth 1
	$frm.sw setwidget $frm.sw.sf
	pack $frm.sw -anchor n -side top -expand true -fill both
	set frm [$frm.sw.sf getframe]

	## Nickname Selection Entry Frame ##
	set lfname [labelframe $frm.lfname -text [trans prefname] -font splainf]
	pack $frm.lfname -anchor n -side top -expand 1 -fill x

	label $lfname.pname -image [::skin::loadPixmap prefpers]
	pack $lfname.pname -anchor nw -side left

	frame $lfname.1
	frame $lfname.1.name

	label $lfname.1.name.label -text "[trans enternick] :" -font sboldf -padx 10
	entry $lfname.1.name.entry -font splainf -width 45
	frame $lfname.1.psm
	label $lfname.1.psm.label -text "[trans psm] :" -font sboldf -padx 10
	entry $lfname.1.psm.entry -font splainf -width 45
	frame $lfname.1.p4c
	label $lfname.1.p4c.label -text "[trans friendlyname] :" -font sboldf -padx 10
	entry $lfname.1.p4c.entry -font splainf -width 45
	frame $lfname.1.ep
	label $lfname.1.ep.label -text "[trans renamelocation] :" -font sboldf -padx 10
	entry $lfname.1.ep.entry -font splainf -width 45
	pack $lfname.1 -side top -padx 0 -pady 3 -expand 1 -fill both
	pack $lfname.1.name.label $lfname.1.name.entry -side left
	pack $lfname.1.psm.label $lfname.1.psm.entry -side left
	pack $lfname.1.p4c.label $lfname.1.p4c.entry -side left
	pack $lfname.1.ep.label $lfname.1.ep.entry -side left
	if {[::config::getKey protocol] >= 11} {
		if {[::config::getKey protocol] >= 18} {
			pack $lfname.1.name $lfname.1.psm $lfname.1.p4c $lfname.1.ep -side top -anchor nw
		} else {
			pack $lfname.1.name $lfname.1.psm $lfname.1.p4c -side top -anchor nw
		}
	} else {
		pack $lfname.1.name $lfname.1.p4c -side top -anchor nw
	}

	## Public Profile Frame ##
	set lfname [labelframe $frm.lfname2 -text [trans prefprofile] -font splainf]
	pack $frm.lfname2 -anchor n -side top -expand 1 -fill x
	label $lfname.pprofile -image [::skin::loadPixmap prefprofile]
	label $lfname.lprofile -text [trans prefprofile2] -padx 10
	button $lfname.bprofile -text [trans editprofile] -command "::hotmail::hotmail_profile"
	pack $lfname.pprofile $lfname.lprofile -side left
	pack $lfname.bprofile -side right -padx 15


	## Internationalization Frame ##
	set lfname [labelframe $frm.lfname2a -text [trans preflocale] -font splainf]
	pack $frm.lfname2a -anchor n -side top -expand 1 -fill x
	label $lfname.plocale -image [::skin::loadPixmap preflocale]
	label $lfname.llocale -text [trans preflocale2] -padx 10
	combobox::combobox $lfname.clocale -editable true -width 20
	pack $lfname.plocale $lfname.llocale -side left
	pack $lfname.clocale -side right -padx 15


	## Chat Font Frame ##
	set lfname [labelframe $frm.lfname3 -text [trans preffont] -font splainf]
	pack $frm.lfname3 -anchor n -side top -expand 1 -fill x
	label $lfname.pfont -image [::skin::loadPixmap preffont]
	label $lfname.lfontout -text [trans preffont2]
	button $lfname.bfontout -text [trans changefont] -command "change_font cfg mychatfont"
	checkbutton $lfname.disableuserfonts -text "[trans disableuserfonts]" \
		-onvalue 1 -offvalue 0 -variable [::config::getVar disableuserfonts] -command UpdatePreferences
	label $lfname.lfontin -text [trans preffont4]
	button $lfname.bfontin -text [trans changefont] -command "change_font cfg theirchatfont; UpdatePreferences"
	button $lfname.bfontinreset -text [trans resetincomingfont] \
		-command "::config::setKey theirchatfont {}; UpdatePreferences"

	pack $lfname.pfont -side left
	pack $lfname.lfontout $lfname.bfontout $lfname.disableuserfonts \
		$lfname.lfontin $lfname.bfontin $lfname.bfontinreset -anchor w -pady 3 -padx 15 -side top

	## Phone Numbers Frame ##
	set lfname [labelframe $frm.lfname4 -text [trans prefphone] -font splainf]
	pack $frm.lfname4 -anchor n -side top -expand 1 -fill x
	frame $lfname.1
	frame $lfname.2
	label $lfname.1.pphone -image [::skin::loadPixmap prefphone]
	pack $lfname.1.pphone -side left -anchor nw
	label $lfname.1.lphone -text [trans prefphone2] -padx 10
	pack $lfname.1.lphone -fill both -side left
	label $lfname.2.lphone1 -text "[trans countrycode] :" -padx 10 -font sboldf
	entry $lfname.2.ephone1 -font splainf  -width 5
	label $lfname.2.lphone21 -text "[trans areacode]" -pady 3
	label $lfname.2.lphone22 -text "[trans phone]" -pady 3
	label $lfname.2.lphone3 -text "[trans myhomephone] :" -padx 10 -font sboldf
	entry $lfname.2.ephone31 -font splainf  -width 5
	entry $lfname.2.ephone32 -font splainf  -width 20
	label $lfname.2.lphone4 -text "[trans myworkphone] :" -padx 10 -font sboldf
	entry $lfname.2.ephone41 -font splainf  -width 5
	entry $lfname.2.ephone42 -font splainf  -width 20
	label $lfname.2.lphone5 -text "[trans mymobilephone] :" -padx 10 -font sboldf
	entry $lfname.2.ephone51 -font splainf  -width 5
	entry $lfname.2.ephone52 -font splainf  -width 20
	checkbutton $lfname.2.mobphone -text "[trans allow_sms]" -onvalue "Y" -offvalue "N" -variable pager
	button $lfname.2.person -text "[trans change_account_info]" -command "::hotmail::hotmail_changeAccountInfo"
    button $lfname.2.chgmob -text "[trans change_mobile]" -command "::hotmail::hotmail_changeMobile"


	pack $lfname.1 -expand 1 -fill both -side top
	pack $lfname.2 -expand 1 -fill both -side top
	grid $lfname.2.lphone1 -row 1 -column 1 -sticky w -columnspan 2
	grid $lfname.2.ephone1 -row 1 -column 3 -sticky w
	grid $lfname.2.lphone21 -row 2 -column 2 -sticky e
	grid $lfname.2.lphone22 -row 2 -column 3 -sticky e
	grid $lfname.2.lphone3 -row 3 -column 1 -sticky w
	grid $lfname.2.ephone31 -row 3 -column 2 -sticky w
	grid $lfname.2.ephone32 -row 3 -column 3 -sticky w
	grid $lfname.2.lphone4 -row 4 -column 1 -sticky w
	grid $lfname.2.ephone41 -row 4 -column 2 -sticky w
	grid $lfname.2.ephone42 -row 4 -column 3 -sticky w
	grid $lfname.2.lphone5 -row 5 -column 1 -sticky w
	grid $lfname.2.ephone51 -row 5 -column 2 -sticky w
	grid $lfname.2.ephone52 -row 5 -column 3 -sticky w
    grid $lfname.2.mobphone	-row 6 -column 1 -sticky w
	grid $lfname.2.chgmob -row 7 -column 1 -sticky w
	grid $lfname.2.person -row 8 -column 1 -sticky w

	$nb.nn compute_size
	[$nb.nn getframe personal].sw.sf compute_size

	#  .------------.
	# _| Appearance |________________________________________________
	::skin::setPixmap preflook preflook.gif
	::skin::setPixmap prefemotic prefemotic.gif
	::skin::setPixmap prefalerts prefalerts.gif
	#set frm [Rnotebook:frame $nb $Preftabs(appearance)]
	set frm [$nb.nn getframe appearance]
	#Scrollable frame that will contain options
	ScrolledWindow $frm.sw
	ScrollableFrame $frm.sw.sf -constrainedwidth 1
	$frm.sw setwidget $frm.sw.sf
	pack $frm.sw -anchor n -side top -expand true -fill both
	set frm [$frm.sw.sf getframe]

	## General aMSN Look Options (Encoding, BGcolor, General Font, Clock Format)
	set lfname [labelframe $frm.lfname -text [trans preflook]]
	pack $frm.lfname -anchor n -side top -expand 0 -fill x
	label $lfname.plook -image [::skin::loadPixmap preflook]
	frame $lfname.0
	frame $lfname.1
#	frame $lfname.2
	frame $lfname.3
	frame $lfname.4
	frame $lfname.5
	frame $lfname.6
	frame $lfname.7

#	button $lfname.0.skinbutton -text [trans skinselector]  -command ::skinsGUI::SelectSkin
#	pack $lfname.0.skinbutton -side left

	label $lfname.1.llook -text "[trans encoding2]" -padx 10
	button $lfname.1.bencoding -text [trans encoding] -command "show_encodingchoose"
	pack $lfname.plook -anchor nw -side left
	pack $lfname.0 $lfname.1 -side top -padx 0 -pady 0 -expand 1 -fill both
	pack $lfname.1.llook -side left
	pack $lfname.1.bencoding -side right -padx 15
#	label $lfname.2.llook -text "[trans bgcolor]" -padx 10
#	button $lfname.2.bbgcolor -text [trans choosebgcolor] -font sboldf -command "choose_theme"
#	pack $lfname.2 -side top -padx 0 -pady 0 -expand 1 -fill both
#	pack $lfname.2.llook -side left
#	pack $lfname.2.bbgcolor -side right -padx 15
	label $lfname.3.llook -text "[trans preffont3]" -padx 10
	button $lfname.3.bfont -text [trans changefont] -command "choose_basefont"
	pack $lfname.3 -side top -padx 0 -pady 0 -expand 1 -fill both
	pack $lfname.3.llook -side left
	pack $lfname.3.bfont -side right -padx 15
	label $lfname.4.llook -text "[trans dateformat]" -padx 10
	pack $lfname.4 -side top -padx 0 -pady 0 -expand 1 -fill both
	pack $lfname.4.llook -anchor w -side top -padx 10
	radiobutton $lfname.4.mdy -text "[trans month]/[trans day]/[trans year]" -value MDY -variable [::config::getVar dateformat]
	radiobutton $lfname.4.dmy -text "[trans day]/[trans month]/[trans year]" -value DMY -variable [::config::getVar dateformat]
	radiobutton $lfname.4.ymd -text "[trans year]/[trans month]/[trans day]" -value YMD -variable [::config::getVar dateformat]
	pack $lfname.4.mdy $lfname.4.dmy $lfname.4.ymd -side left -padx 10

	checkbutton $lfname.5.dock -text "[trans trayicon]" -onvalue 1 -offvalue 0 -variable [::config::getVar use_tray]
	pack $lfname.5.dock -anchor w -side top -padx 10 -pady 0

	checkbutton $lfname.5.show_contactdps_in_cl -text "[trans show_contactdps_in_cl]" -onvalue 1 -offvalue 0 -variable [::config::getVar show_contactdps_in_cl]
	#checkbutton $lfname.5.show_spaces -text "[trans enablespaces]" -onvalue 1 -offvalue 0 -variable [::config::getVar showspaces]
	pack $lfname.5.show_contactdps_in_cl -anchor w -side top -padx 10 -pady 0

	pack $lfname.5 -side top -padx 0 -pady 10 -expand 1 -fill both

	label $lfname.6.llook -text "[trans psmplace]" -padx 10
	pack $lfname.6 -side top -padx 0 -pady 0 -expand 1 -fill both
	pack $lfname.6.llook -anchor w -side top -padx 10
	radiobutton $lfname.6.dontshow -text "[trans psmdontshow]" -value 0 -variable [::config::getVar psmplace]
	radiobutton $lfname.6.atend -text "[trans psmatend]" -value 1 -variable [::config::getVar psmplace]
	radiobutton $lfname.6.newline -text "[trans psmnewline]" -value 2 -variable [::config::getVar psmplace]
	pack $lfname.6.dontshow $lfname.6.atend $lfname.6.newline -anchor w -side top -padx 10
	checkbutton $lfname.7.cam_in_cw -text "[trans cam_in_cw]" -onvalue 1 -offvalue 0 -variable [::config::getVar cam_in_cw]
	pack $lfname.7 -side top -padx 0 -pady 0 -expand 1 -fill both
	pack $lfname.7.cam_in_cw -anchor w -side top -padx 10


	## Emoticons Frame ##
	set lfname [labelframe $frm.lfname2 -text [trans prefemotic]]
	pack $frm.lfname2 -anchor n -side top -expand 0 -fill x
	label $lfname.pemotic -image [::skin::loadPixmap prefemotic]
	pack $lfname.pemotic -side left -anchor nw
	frame $lfname.1
	pack $lfname.1 -side left -padx 0 -pady 0 -expand 1 -fill x
	checkbutton $lfname.1.chat -text "[trans chatsmileys2]" -onvalue 1 -offvalue 0 -variable [::config::getVar chatsmileys]
	checkbutton $lfname.1.list -text "[trans listsmileys2]" -onvalue 1 -offvalue 0 -variable [::config::getVar listsmileys]
        checkbutton $lfname.1.sound -text "[trans emotisounds]" -onvalue 1 -offvalue 0 -variable [::config::getVar emotisounds]
        checkbutton $lfname.1.animated -text "[trans animatedsmileys]" -onvalue 1 -offvalue 0 -variable [::config::getVar animatedsmileys] -command [list destroy .smile_selector]
	checkbutton $lfname.1.customsmileys -text "[trans customsmileys]" -onvalue 1 -offvalue 0 -variable [::config::getVar customsmileys]
	#checkbutton $lfname.1.log -text "[trans logsmileys]" -onvalue 1 -offvalue 0 -variable [::config::getVar logsmileys] -state disabled
	#pack $lfname.1.chat $lfname.1.list $lfname.1.sound  $lfname.1.animated $lfname.1.log -anchor w -side top -padx 10
	pack $lfname.1.chat $lfname.1.list $lfname.1.sound  $lfname.1.animated $lfname.1.customsmileys -anchor w -side top -padx 10 -pady 0

	## Alerts and Sounds Frame ##
	set lfname [labelframe $frm.lfname3 -text [trans prefalerts]]
	pack $frm.lfname3 -anchor n -side top -expand 0 -fill x
	label $lfname.palerts -image [::skin::loadPixmap prefalerts]
	pack $lfname.palerts -side left -anchor nw
	frame $lfname.1
	checkbutton $lfname.1.alert1 -text "[trans shownotify]" -onvalue 1 -offvalue 0 -variable [::config::getVar shownotify]
	checkbutton $lfname.1.sound -text "[trans sound2]" -onvalue 1 -offvalue 0 -variable [::config::getVar sound]
	pack $lfname.1 -anchor w -side top -padx 0 -pady 5 -expand 1 -fill both
	pack $lfname.1.alert1 $lfname.1.sound -anchor w -side top -padx 10 -pady 0

	#Bounce icon in the dock preference for Mac OS X
	if { [OnMac] } {
		label $lfname.1.bouncedock -text "[trans bouncedock]" -padx 10
		pack $lfname.1.bouncedock -anchor w -side top -padx 10
		radiobutton $lfname.1.unlimited -text "[trans continuously]" -value unlimited -variable [::config::getVar dockbounce]
		radiobutton $lfname.1.once -text "[trans justonce]" -value once -variable [::config::getVar dockbounce]
		radiobutton $lfname.1.never -text "[trans never]" -value never -variable [::config::getVar dockbounce]
		pack $lfname.1.unlimited $lfname.1.once $lfname.1.never -side left -padx 10
	}
	$nb.nn compute_size
	[$nb.nn getframe appearance].sw.sf compute_size


	#  .---------.
	# _| Session |________________________________________________
	::skin::setPixmap prefstatus prefstatus.gif
	::skin::setPixmap prefaway prefaway.gif
	::skin::setPixmap prefmsg prefmsg.gif

	#set frm [Rnotebook:frame $nb $Preftabs(session)]
	set frm [$nb.nn getframe session]
	#Scrollable frame that will contain options
	ScrolledWindow $frm.sw
	ScrollableFrame $frm.sw.sf -constrainedwidth 1
	$frm.sw setwidget $frm.sw.sf
	pack $frm.sw -anchor n -side top -expand true -fill both
	set frm [$frm.sw.sf getframe]

	## Sign In and AutoStatus Options Frame ##
	set lfname [labelframe $frm.lfname -text [trans prefsession]]
	pack $frm.lfname -anchor n -side top -expand 1 -fill x
	label $lfname.psession -image [::skin::loadPixmap prefstatus]
	pack $lfname.psession -anchor nw -side left
	frame $lfname.1
	frame $lfname.2
	frame $lfname.3
	checkbutton $lfname.1.lautonoact -text "[trans autonoact]" -onvalue 1 -offvalue 0 -variable [::config::getVar autoidle] -command UpdatePreferences
	entry $lfname.1.eautonoact -font splainf -width 3 -textvariable [::config::getVar idletime]
	label $lfname.1.lmins -text "[trans mins]" -padx 5
	pack $lfname.1 -side top -padx 0 -expand 1 -fill both
	pack $lfname.1.lautonoact $lfname.1.eautonoact $lfname.1.lmins -side left
	checkbutton $lfname.2.lautoaway -text "[trans autoaway]" -onvalue 1 -offvalue 0 -variable [::config::getVar autoaway] -command UpdatePreferences
	entry $lfname.2.eautoaway -font splainf -width 3 -textvariable [::config::getVar awaytime]
	label $lfname.2.lmins -text "[trans mins]" -padx 5
	pack $lfname.2 -side top -padx 0 -expand 1 -fill both
	pack $lfname.2.lautoaway $lfname.2.eautoaway $lfname.2.lmins -side left
	checkbutton $lfname.3.lreconnect -text "[trans reconnect2]" -onvalue 1 -offvalue 0 -variable [::config::getVar reconnect]
	checkbutton $lfname.3.lonstart -text "[trans autoconnect2]" -onvalue 1 -offvalue 0 -variable [::config::getVar autoconnect]

	if { [OnWin] } {
		set ::start_on_windows_boot [WinDetectBoot]
		checkbutton $lfname.3.startonboot -text "[trans startonboot]" -onvalue 1 -offvalue 0 -variable ::start_on_windows_boot
	}

	pack $lfname.3 -side top -padx 0 -expand 1 -fill both

	if { [OnWin] } {
		pack $lfname.3.lreconnect $lfname.3.lonstart $lfname.3.startonboot  -anchor w -side top
	} else {
		pack $lfname.3.lreconnect $lfname.3.lonstart -anchor w -side top
	}

	## Away Messages Frame ##
	set lfname [labelframe $frm.lfname2 -text [trans prefawaymsg]]
	pack $frm.lfname2 -anchor n -side top -expand 1 -fill x
	label $lfname.psession -image [::skin::loadPixmap prefaway]
	pack $lfname.psession -anchor nw -side left
	frame $lfname.statelist -relief sunken -borderwidth 3
	listbox $lfname.statelist.box -yscrollcommand "$lfname.statelist.ys set" \
		-font splainf -highlightthickness 0 -height 4
	scrollbar $lfname.statelist.ys -command "$lfname.statelist.box yview" -highlightthickness 0 \
         -borderwidth 1 -elementborderwidth 2
	pack $lfname.statelist.ys -side right -fill y
	pack $lfname.statelist.box -side left -expand true -fill both
	frame $lfname.buttons -borderwidth 0
	button $lfname.buttons.add -text [trans addstate] -command "EditNewState 0" -width 20
	button $lfname.buttons.del -text [trans delete]  -command "DeleteStateListBox \[$lfname.statelist.box curselection\] $lfname.statelist.box" -width 20
	button $lfname.buttons.edit -text [trans edit]  -command "EditNewState 2 \[$lfname.statelist.box curselection\]" -width 20
	pack $lfname.buttons.add -side top
	pack $lfname.buttons.del -side top
	pack $lfname.buttons.edit -side top
	pack $lfname.statelist -anchor w -side left -padx 10 -pady 10 -expand 1 -fill both
	pack $lfname.buttons -anchor w -side right -padx 10 -pady 10 -expand 1 -fill both

	## Messaging Interface Frame ##
	set lfname [labelframe $frm.lfname3 -text [trans prefmsging]]
	pack $frm.lfname3 -anchor n -side top -expand 1 -fill x
	label $lfname.pmsging -image [::skin::loadPixmap prefmsg]
	pack $lfname.pmsging -anchor nw -side left
	frame $lfname.1
	frame $lfname.2
	frame $lfname.3
	frame $lfname.4
	frame $lfname.5

	label $lfname.1.lchatmaxmin -text [trans chatmaxmin]
	radiobutton $lfname.1.max -text [trans raised] -value 0 -variable [::config::getVar newchatwinstate] -padx 17
	grid $lfname.1.lchatmaxmin -row 1 -column 1 -sticky w

	#Don't show the minimised option on Mac OS X because that does'nt work in TkAqua
	if { ![OnMac] } {
		radiobutton $lfname.1.min -text [trans minimised] -value 1 -variable [::config::getVar newchatwinstate] -padx 17
	}

	radiobutton $lfname.1.no -text [trans dontshow] -value 2 -variable [::config::getVar newchatwinstate]  -padx 17

	#Don't pack the minimised option on Mac OS X because that does'nt work in TkAqua
	if { [OnMac] } {
		grid $lfname.1.max -row 2 -column 1 -sticky w
		grid $lfname.1.no -row 3 -column 1 -sticky w
	} else {
		grid $lfname.1.max -row 2 -column 1 -sticky w
		grid $lfname.1.min -row 3 -column 1 -sticky w
		grid $lfname.1.no -row 4 -column 1 -sticky w
	}

	#Don't enable this option on Mac OS X because we can't minimized window this way with TkAqua
	if { ![OnMac] } {
		label $lfname.2.lmsgmaxmin -text [trans msgmaxmin]
		radiobutton $lfname.2.max -text [trans raised] -value 0 -variable [::config::getVar newmsgwinstate] -padx 17
		radiobutton $lfname.2.min -text [trans minimised] -value 1 -variable [::config::getVar newmsgwinstate] -padx 17

		grid $lfname.2.lmsgmaxmin -row 1 -column 1 -sticky w
		grid $lfname.2.max -row 2 -column 1 -sticky w
		grid $lfname.2.min -row 3 -column 1 -sticky w
	}

	label $lfname.3.lmsgmode -text [trans msgmode]
	radiobutton $lfname.3.nottabbed -text [trans nottabbed] -value 0 -variable [::config::getVar tabbedchat] -padx 17
	radiobutton $lfname.3.tabbedglobal -text [trans tabbedglobal] -value 1 -variable [::config::getVar tabbedchat] -padx 17
	radiobutton $lfname.3.tabbedgroups -text [trans tabbedgroups] -value 2 -variable [::config::getVar tabbedchat] -padx 17

	label $lfname.4.containermode -text [trans closelabel]
	radiobutton $lfname.4.containerask -text [trans askeachtime] -value 0 -variable [::config::getVar closeChatWindowWithTabs] -padx 17
	radiobutton $lfname.4.containercloseall -text [trans closealltabs] -value 1 -variable [::config::getVar closeChatWindowWithTabs] -padx 17
	radiobutton $lfname.4.containerclosetab -text [trans closeonly] -value 2 -variable [::config::getVar closeChatWindowWithTabs] -padx 17

	label $lfname.5.logoutwinclosemode -text [trans logoutwincloselabel]
	radiobutton $lfname.5.logoutwincloseask -text [trans askeachtime] -value 0 -variable [::config::getVar closeChatWindowsAfterLogout] -padx 17
	radiobutton $lfname.5.logoutwinclosealways -text [trans always] -value 1 -variable [::config::getVar closeChatWindowsAfterLogout] -padx 17
	radiobutton $lfname.5.logoutwinclosenever -text [trans never] -value 2 -variable [::config::getVar closeChatWindowsAfterLogout] -padx 17

	grid $lfname.3.lmsgmode  -row 1 -column 1 -sticky w
	grid $lfname.3.nottabbed -row 2 -column 1 -sticky w
	grid $lfname.3.tabbedglobal -row 3 -column 1 -sticky w
	grid $lfname.3.tabbedgroups -row 4 -column 1 -sticky w

	grid $lfname.4.containermode  -row 1 -column 1 -sticky w
	grid $lfname.4.containerask -row 2 -column 1 -sticky w
	grid $lfname.4.containercloseall -row 3 -column 1 -sticky w
	grid $lfname.4.containerclosetab -row 4 -column 1 -sticky w

	grid $lfname.5.logoutwinclosemode -row 1 -column 1 -sticky w
	grid $lfname.5.logoutwincloseask -row 2 -column 1 -sticky w
	grid $lfname.5.logoutwinclosealways -row 3 -column 1 -sticky w
	grid $lfname.5.logoutwinclosenever -row 4 -column 1 -sticky w

	checkbutton $lfname.winflicker -text "[trans msgflicker]" -onvalue 1 -offvalue 0 -variable [::config::getVar flicker]
	checkbutton $lfname.showdisplaypic -text "[trans showdisplaypic2]" -onvalue 1 -offvalue 0 -variable [::config::getVar showdisplaypic]

	pack $lfname.1 $lfname.2 $lfname.3 $lfname.4 $lfname.5 $lfname.winflicker $lfname.showdisplaypic -anchor w -side top

	$nb.nn compute_size
	[$nb.nn getframe session].sw.sf compute_size


	#  .------------------.
	# _| Group Management |_______________________________________

	::skin::setPixmap prefpersc prefpers.gif
	::skin::setPixmap prefprofilec prefprofile.gif
	::skin::setPixmap prefmobile prefmobile.gif

	set frm [$nb.nn getframe groups]
	ScrolledWindow $frm.sw
	ScrollableFrame $frm.sw.sf -constrainedwidth 1
	$frm.sw setwidget $frm.sw.sf
	pack $frm.sw -anchor n -side top -expand true -fill both
	set frm [$frm.sw.sf getframe]

	## Mobile group ##
	set lfmobile [labelframe $frm.lfmobile -text [trans mobilegrp1]]
	pack $frm.lfmobile -anchor n -side top -expand 1 -fill x
	label $lfmobile.lbmobile -image [::skin::loadPixmap prefmobile]
	pack $lfmobile.lbmobile -side left -padx 5 -pady 5
	checkbutton $lfmobile.btmobile -text "[trans mobilegrp2]" -onvalue 1 -offvalue 0 \
		-variable [::config::getVar showMobileGroup]
	pack $lfmobile.btmobile  -anchor w -side left -padx 0 -pady 5

	#compute_size
	$nb.nn compute_size
	[$nb.nn getframe groups].sw.sf compute_size


	#  .--------.
	# _| Loging |________________________________________________
	::skin::setPixmap prefhist prefhist.gif
	::skin::setPixmap prefhist2 prefhist2.gif
#	::skin::setPixmap prefhist3 prefhist3.gif

	#set frm [Rnotebook:frame $nb $Preftabs(loging)]
	set frm [$nb.nn getframe loging]
	ScrolledWindow $frm.sw
	ScrollableFrame $frm.sw.sf -constrainedwidth 1
	$frm.sw setwidget $frm.sw.sf
	pack $frm.sw -anchor n -side top -expand true -fill both
	set frm [$frm.sw.sf getframe]

	## Loging Options Frame ##
	set lfname [labelframe $frm.lfname -text [trans preflog1]]
	pack $frm.lfname -anchor n -side top -expand 0 -fill x
	label $lfname.plog1 -image [::skin::loadPixmap prefhist]
	pack $lfname.plog1 -anchor nw -side left
	checkbutton $lfname.log -text "[trans keeplog2]" -onvalue 1 -offvalue 0 -variable [::config::getVar keep_logs]
	checkbutton $lfname.date -text "[trans logsbydate]" -onvalue 1 -offvalue 0 -variable [::config::getVar logsbydate]
	checkbutton $lfname.camlog -text "[trans logwebcam]" -onvalue 1 -offvalue 0 -variable [::config::getVar webcamlogs]
	pack $lfname.log -anchor w
	pack $lfname.camlog -anchor w
	pack $lfname.date -anchor w

#/////////TODO Add style log feature
#	frame $lfname.2 -class Degt
#	label $lfname.2.lstyle -text "[trans stylelog]" -padx 10
#	radiobutton $lfname.2.hist -text [trans stylechat] -value 1 -variable [::config::getVar logstyle] -state disabled
#	radiobutton $lfname.2.chat -text [trans stylehist] -value 2 -variable [::config::getVar logstyle] -state disabled
#	pack $lfname.2.lstyle -anchor w -side top -padx 10
#	pack $lfname.2.hist $lfname.2.chat -side left -padx 10
#	pack $lfname.2 -anchor w -side top -expand 1 -fill x

	## Clear All Logs Frame ##
	set lfname [labelframe $frm.lfname2 -text [trans clearlog]]
	pack $frm.lfname2 -anchor n -side top -expand 0 -fill x
	label $lfname.plog1 -image [::skin::loadPixmap prefhist2]
	pack $lfname.plog1 -anchor nw -side left
	frame $lfname.1
	label $lfname.1.lclear -text "[trans clearlog2]" -padx 10
	button $lfname.1.bclear -text [trans clearlog3]  -command "::log::ClearAllLogs"
	button $lfname.1.camclear -text [trans clearwebcamlogs] -command "::log::ClearAllCamLogs"
	pack $lfname.1.lclear -side left
	pack $lfname.1.bclear -side right -padx 15
	pack $lfname.1.camclear -side right -padx 15
	pack $lfname.1 -anchor w -side top -expand 0 -fill x
#////////TODO: Add logs expiry feature
	## Logs Expiry Frame ##
#	set lfname [labelframe $frm.lfname3 -text [trans logfandexp]]
#	pack $frm.lfname3 -anchor n -side top -expand 1 -fill x
#	label $lfname.plog1 -image [::skin::loadPixmap prefhist3]
#	pack $lfname.plog1 -anchor nw -side left
#	frame $lfname.1 -class Degt
#	checkbutton $lfname.1.lolder -text "[trans logolder]" -onvalue 1 -offvalue 0 -variable [::config::getVar logexpiry] -state disabled
#	entry $lfname.1.eolder -bg #FFFFFF -bd 1 -font splainf -highlightthickness 0  -width 3 -state disabled
#	label $lfname.1.ldays -text "[trans days]" -padx 5
#	pack $lfname.1 -side top -padx 0 -expand 1 -fill both
#	pack $lfname.1.lolder $lfname.1.eolder $lfname.1.ldays -side left
#	frame $lfname.2 -class Degt
#	checkbutton $lfname.2.lbigger -text "[trans logbigger]" -onvalue 1 -offvalue 0 -variable [::config::getVar logmaxsize] -state disabled
#	entry $lfname.2.ebigger -bg #FFFFFF -bd 1 -font splainf -highlightthickness 0  -width 3 -state disabled
#	label $lfname.2.lmbs -text "MBs" -padx 5
#	pack $lfname.2 -side top -padx 0 -expand 1 -fill both
#	pack $lfname.2.lbigger $lfname.2.ebigger $lfname.2.lmbs -side left


	## Eventlogging frame ## ***
	set lfname [labelframe $frm.lfname3 -text [trans preflogevent]]
	pack $frm.lfname3 -anchor n -side top -expand 0 -fill x
	label $lfname.plog1
	grid $lfname.plog1 -columnspan 2
	checkbutton $lfname.displayconnect -text "[trans displayeventconnect]" -onvalue 1 -offvalue 0 -variable [::config::getVar display_event_connect]
	checkbutton $lfname.displaydisconnect -text "[trans displayeventdisconnect]" -onvalue 1 -offvalue 0 -variable [::config::getVar display_event_disconnect]
	checkbutton $lfname.displayemail -text "[trans displayeventemail]" -onvalue 1 -offvalue 0 -variable [::config::getVar display_event_email]
	checkbutton $lfname.displaystate -text "[trans displayeventstate]" -onvalue 1 -offvalue 0 -variable [::config::getVar display_event_state]
	checkbutton $lfname.displaynick -text "[trans displayeventnick]" -onvalue 1 -offvalue 0 -variable [::config::getVar display_event_nick]
	checkbutton $lfname.displaypsm -text "[trans displayeventpsm]" -onvalue 1 -offvalue 0 -variable [::config::getVar display_event_psm]
	checkbutton $lfname.logconnect -text "[trans logeventconnect]" -onvalue 1 -offvalue 0 -variable [::config::getVar log_event_connect]
	checkbutton $lfname.logdisconnect -text "[trans logeventdisconnect]" -onvalue 1 -offvalue 0 -variable [::config::getVar log_event_disconnect]
	checkbutton $lfname.logemail -text "[trans logeventemail]" -onvalue 1 -offvalue 0 -variable [::config::getVar log_event_email]
	checkbutton $lfname.logstate -text "[trans logeventstate]" -onvalue 1 -offvalue 0 -variable [::config::getVar log_event_state]
	checkbutton $lfname.lognick -text "[trans logeventnick]" -onvalue 1 -offvalue 0 -variable [::config::getVar log_event_nick]
	checkbutton $lfname.logpsm -text "[trans logeventpsm]" -onvalue 1 -offvalue 0 -variable [::config::getVar log_event_psm]
	grid $lfname.displayconnect -row 0 -column 0 -sticky w
	grid $lfname.displaydisconnect -row 1 -column 0 -sticky w
	grid $lfname.displayemail -row 2 -column 0 -sticky w
	grid $lfname.displaystate -row 3 -column 0 -sticky w
	grid $lfname.displaynick -row 4 -column 0 -sticky w
	grid $lfname.displaypsm -row 5 -column 0 -sticky w
	grid $lfname.logconnect -row 0 -column 1 -sticky w
	grid $lfname.logdisconnect -row 1 -column 1 -sticky w
	grid $lfname.logemail -row 2 -column 1 -sticky w
	grid $lfname.logstate -row 3 -column 1 -sticky w
	grid $lfname.lognick -row 4 -column 1 -sticky w
	grid $lfname.logpsm -row 5 -column 1 -sticky w


	#  .------------.
	# _| Connection |________________________________________________

	::skin::setPixmap prefnat prefnat.gif
	::skin::setPixmap prefproxy prefproxy.gif
	::skin::setPixmap prefremote prefpers.gif

	#set frm [Rnotebook:frame $nb $Preftabs(connection)]
	set frm [$nb.nn getframe connection]
	#Scrollable frame that will contain options
	ScrolledWindow $frm.sw
	ScrollableFrame $frm.sw.sf -constrainedwidth 1
	$frm.sw setwidget $frm.sw.sf
	pack $frm.sw -anchor n -side top -expand true -fill both
	set frm [$frm.sw.sf getframe]

	## Connection Frame ##
	set lfname [labelframe $frm.lfnameconnection -text [trans prefconnection]]
	pack $frm.lfnameconnection -anchor n -side top -expand 1 -fill x
	label $lfname.pshared -image [::skin::loadPixmap prefproxy]
	pack $lfname.pshared -side left -anchor nw

	frame $lfname.1
	frame $lfname.2
	frame $lfname.3
	frame $lfname.4
	frame $lfname.5
	radiobutton $lfname.1.direct -text "[trans directconnection]" -value direct -variable [::config::getVar connectiontype] -command UpdatePreferences
	pack $lfname.1.direct -anchor w -side top -padx 10
	radiobutton $lfname.2.http -text "[trans httpconnection]" -value http -variable [::config::getVar connectiontype] -command UpdatePreferences
	pack $lfname.2.http -anchor w -side top -padx 10
	radiobutton $lfname.3.proxy -text "[trans proxyconnection]" -value proxy -variable [::config::getVar connectiontype] -command UpdatePreferences
	pack $lfname.3.proxy -anchor w -side top -padx 10

	#checkbutton $lfname.1.proxy -text "[trans proxy]" -onvalue 1 -offvalue 0 -variable [::config::getVar withproxy]
	#pack $lfname.1.proxy -anchor w -side top -padx 10

	#radiobutton $lfname.2.http -text "HTTP" -value http -variable [::config::getVar proxytype]
	#radiobutton $lfname.2.socks5 -text "SOCKS5" -value socks -variable [::config::getVar proxytype] -state disabled
	#pack $lfname.2.http $lfname.2.socks5 -anchor w -side left -padx 10

	pack $lfname.1 $lfname.2 $lfname.3 $lfname.4 $lfname.5 -anchor w -side top -padx 0 -pady 0 -expand 1 -fill both

	radiobutton $lfname.4.post -text "HTTP (POST method)" -value http -variable [::config::getVar proxytype] -command UpdatePreferences
	radiobutton $lfname.4.ssl -text "SSL (CONNECT method)" -value ssl -variable [::config::getVar proxytype] -command UpdatePreferences
	radiobutton $lfname.4.socks5 -text "SOCKS5" -value socks5 -variable [::config::getVar proxytype] -command UpdatePreferences

	grid $lfname.4.post -row 1 -column 1 -sticky w -pady 5 -padx 10
	grid $lfname.4.ssl -row 1 -column 2 -sticky w -pady 5 -padx 10
	grid $lfname.4.socks5 -row 1 -column 3 -sticky w -pady 5 -padx 10


	label $lfname.5.lserver -text "[trans server] :" -padx 5 -font sboldf
	entry $lfname.5.server -font splainf  -width 20 -textvariable proxy_server
	label $lfname.5.lport -text "[trans port] :" -padx 5 -font sboldf
	entry $lfname.5.port -font splainf  -width 5 -textvariable proxy_port
	label $lfname.5.luser -text "[trans user] :" -padx 5 -font sboldf
	entry $lfname.5.user -font splainf  -width 20 -textvariable proxy_user
	label $lfname.5.lpass -text "[trans pass] :" -padx 5 -font sboldf
	entry $lfname.5.pass -font splainf  -width 20 -show "*" -textvariable proxy_pass
	grid $lfname.5.lserver -row 2 -column 1 -sticky e
	grid $lfname.5.server -row 2 -column 2 -sticky w -pady 5
	grid $lfname.5.lport -row 2 -column 3 -sticky e
	grid $lfname.5.port -row 2 -column 4 -sticky w -pady 5
	grid $lfname.5.luser -row 3 -column 1 -sticky e
	grid $lfname.5.user -row 3 -column 2 -sticky w
	grid $lfname.5.lpass -row 3 -column 3 -sticky e
	grid $lfname.5.pass -row 3 -column 4 -sticky w

	## NAT (or similar) Frame ##
	set lfname [labelframe $frm.lfname -text [trans prefft]]
	pack $frm.lfname -anchor n -side top -expand 1 -fill x
	label $lfname.pshared -image [::skin::loadPixmap prefnat]
	pack $lfname.pshared -side left -anchor nw
	frame $lfname.1
	pack $lfname.1 -side left -padx 0 -pady 5 -expand 1 -fill both

	label $lfname.1.conntype -padx 5 -font splainf -text "[trans type]: [::abook::getDemographicField conntype]"
	label $lfname.1.listening -padx 5 -font splainf
	if { [::abook::getDemographicField conntype] == "" } {
		$lfname.1.listening configure -text  "[trans connectfirst]" -fg [::skin::getKey extrastderrcolor]
	} else {
		if { [::abook::getDemographicField listening] == "false"} {
			$lfname.1.listening configure -text "[trans firewalled]" -fg [::skin::getKey extrastderrcolor]
		} else {
			$lfname.1.listening configure -text "[trans portswellconfigured]" -fg [::skin::getKey extrastdokcolor]

		}
	}
	pack $lfname.1.conntype $lfname.1.listening -anchor w -side top -padx 10

	frame $lfname.1.ftport
	label $lfname.1.ftport.text -text "[trans ftportpref2] :" -padx 5 -font splainf
	entry $lfname.1.ftport.entry -font splainf  -width 5 -textvariable [::config::getVar initialftport]
	button $lfname.1.ftport.bttest -text "[trans ftporttest]" -padx 5 -font splainf -command [list after 0 connection_check $lfname]
	label $lfname.1.ftport.test -text "" -padx 5 -font splainf
	grid $lfname.1.ftport.text -row 1 -column 1 -sticky w -pady 5 -padx 0 -columnspan 3
	grid $lfname.1.ftport.entry -row 2 -column 1 -sticky w -pady 5 -padx [list 20 3]
	grid $lfname.1.ftport.bttest -row 2 -column 2 -sticky w -pady 5 -padx 3
	grid $lfname.1.ftport.test -row 2 -column 3 -sticky w -pady 5 -padx 3

	checkbutton $lfname.1.autoip -text "[trans autodetectip]" -onvalue 1 -offvalue 0 -variable [::config::getVar autoftip] -command UpdatePreferences
	frame $lfname.1.ipaddr
	label $lfname.1.ipaddr.text -text "[trans ipaddress] :" -padx 5 -font splainf
	entry $lfname.1.ipaddr.entry -font splainf  -width 15 -textvariable [::config::getVar manualip]
	grid $lfname.1.ipaddr.text -row 1 -column 1 -sticky w -pady 5 -padx 0
	grid $lfname.1.ipaddr.entry -row 1 -column 2 -sticky w -pady 5 -padx 3

	checkbutton $lfname.1.autoaccept -text "[trans autoacceptft]" -onvalue 1 -offvalue 0 -variable [::config::getVar ftautoaccept]

	pack $lfname.1.ftport $lfname.1.autoip $lfname.1.ipaddr $lfname.1.autoaccept -anchor w -side top -padx 10


	## Remote Control Frame ##
	set lfname [labelframe $frm.lfname3 -text [trans prefremote]]
	pack $frm.lfname3 -anchor n -side top -expand 1 -fill x
	label $lfname.pshared -image [::skin::loadPixmap prefremote]
	pack $lfname.pshared -side left -anchor nw
	frame $lfname.1
	frame $lfname.2
	pack $lfname.1 -side left -padx 0 -pady 5 -expand 1 -fill both
	checkbutton $lfname.1.eremote -text "[trans enableremote]" -onvalue 1 -offvalue 0 -variable [::config::getVar enableremote] -command UpdatePreferences
	pack $lfname.1.eremote  -anchor w -side top -padx 10
	pack $lfname.1 $lfname.2  -anchor w -side top -padx 0 -pady 0 -expand 1 -fill both
	label $lfname.2.lpass -text "[trans pass] :" -padx 5 -font sboldf
	entry $lfname.2.pass -font splainf  -width 20 -show "*"
	grid $lfname.2.lpass -row 2 -column 3 -sticky e
	grid $lfname.2.pass -row 2 -column 4 -sticky w

	$nb.nn compute_size
	[$nb.nn getframe connection].sw.sf compute_size

	#  .--------.
	# _| Others |________________________________________________
	::skin::setPixmap prefapps prefpers.gif

	#set frm [Rnotebook:frame $nb $Preftabs(others)]
	set frm [$nb.nn getframe others]

	#Scrollable frame that will contain options
	ScrolledWindow $frm.sw
	ScrollableFrame $frm.sw.sf -constrainedwidth 1
	$frm.sw setwidget $frm.sw.sf
	pack $frm.sw -anchor n -side top -expand true -fill both
	set frm [$frm.sw.sf getframe]

	## Delete Profiles Frame ##
	set lfname [labelframe $frm.lfname3 -text [trans prefprofile3]]
	pack $frm.lfname3 -anchor n -side top -expand 1 -fill x
	label $lfname.pprofile -image [::skin::loadPixmap prefapps]
	pack $lfname.pprofile -side left -anchor nw
	frame $lfname.1
	label $lfname.1.ldelprofile -text "[trans delprofile2]" -font sboldf -padx 5
	combobox::combobox $lfname.1.profile -editable true -width 22
	button $lfname.1.bdel -text [trans delprofile] -command "DeleteProfile \[${lfname}.1.profile get\] $lfname.1.profile"
	grid $lfname.1.ldelprofile -row 1 -column 1 -sticky w
	grid $lfname.1.profile -row 1 -column 2 -sticky w
	grid $lfname.1.bdel -row 1 -column 3 -padx 5 -sticky w
	pack $lfname.1 -anchor w -side top -expand 0 -fill none

	## Applications Frame ##
	set lfname [labelframe $frm.lfname -text [trans prefapps]]
	pack $frm.lfname -anchor n -side top -expand 1 -fill x
	label $lfname.pshared -image [::skin::loadPixmap prefapps]
	pack $lfname.pshared -side left -anchor nw
	frame $lfname.1
	pack $lfname.1 -anchor w -side left -padx 0 -pady 5 -expand 0 -fill both

	#Don't change filemanager and open file manager on Mac OS X
	if { ![OnMac] && ![OnWin] } {
		label $lfname.1.lbrowser -text "[trans browser] :" -padx 5 -font sboldf
		entry $lfname.1.browser -width 40 -textvariable [::config::getVar browser]
		label $lfname.1.lbrowserex -text "[trans browserexample]" -font examplef
		#file manager
		label $lfname.1.lfileman -text "[trans fileman] :" -padx 5 -font sboldf
		entry $lfname.1.fileman -width 40 -textvariable [::config::getVar filemanager]
		label $lfname.1.lfilemanex -text "[trans filemanexample]" -font examplef
		#open file command
		label $lfname.1.lopenfile -text "[trans openfilecommand] :" -padx 5 -font sboldf
		entry $lfname.1.openfile -width 40 -textvariable [::config::getVar openfilecommand]
		label $lfname.1.lopenfileex -text "(Gnome: gnome-open \$file) (KDE: kfmclient exec \$file)" -font examplef
	}

	if {![OnWin] } {
		label $lfname.1.lmailer -text "[trans mailer] :" -padx 5 -font sboldf
		entry $lfname.1.mailer -width 40 -textvariable [::config::getVar mailcommand]
		label $lfname.1.lmailerex -text "[trans mailerexample]" -font examplef
	}

	#aMSN for Mac OS X always use "QuickTimeTCL" (except in Alarms) so don't let mac user choose sound player
	if { ![OnMac] } {
		label $lfname.1.lsound -text "[trans soundserver] :" -padx 5 -font sboldf
		frame $lfname.1.sound

		radiobutton $lfname.1.sound.snack -text "[trans usesnack]" -value 1 -variable [::config::getVar usesnack] -command UpdatePreferences
		pack $lfname.1.sound.snack -anchor w -side top -padx 10
		radiobutton $lfname.1.sound.other -text "[trans useother]" -value 0 -variable [::config::getVar usesnack] -command UpdatePreferences
		pack $lfname.1.sound.other -anchor w -side top -padx 10
		entry $lfname.1.sound.sound -width 40 -textvariable [::config::getVar soundcommand]
		pack $lfname.1.sound.sound -anchor w -side top -padx 10
		label $lfname.1.sound.lsoundex -text "[trans soundexample]" -font examplef
		pack $lfname.1.sound.lsoundex -anchor w -side top -padx 10

	}


	#aMSN for Mac OS X always use "QuickTimeTCL" (except in Alarms) so don't let mac user choose sound player
	#because we don't change filemanager and open file manager on Mac OS X
	if { [OnMac] } {
		grid $lfname.1.lmailer -row 7 -column 1 -sticky w
		grid $lfname.1.mailer -row 7 -column 2 -sticky w
		grid $lfname.1.lmailerex -row 8 -column 2 -columnspan 1 -sticky w
	} elseif {![OnWin] } {
		grid $lfname.1.lbrowser -row 1 -column 1 -sticky w
		grid $lfname.1.browser -row 1 -column 2 -sticky w
		grid $lfname.1.lbrowserex -row 2 -column 2 -columnspan 1 -sticky w

		grid $lfname.1.lfileman -row 3 -column 1 -sticky w
		grid $lfname.1.fileman -row 3 -column 2 -sticky w
		grid $lfname.1.lfilemanex -row 4 -column 2 -columnspan 1 -sticky w

		grid $lfname.1.lopenfile -row 5 -column 1 -sticky w
		grid $lfname.1.openfile -row 5 -column 2 -sticky w
		grid $lfname.1.lopenfileex -row 6 -column 2 -columnspan 1 -sticky w

		grid $lfname.1.lmailer -row 7 -column 1 -sticky w
		grid $lfname.1.mailer -row 7 -column 2 -sticky w
		grid $lfname.1.lmailerex -row 8 -column 2 -columnspan 1 -sticky w

	}

	if {![OnMac] } {
		grid $lfname.1.lsound -row 9 -column 1 -sticky nw
		grid $lfname.1.sound -row 9 -column 2 -sticky w
		#grid $lfname.1.lsoundex -row 10 -column 2 -columnspan 1 -sticky w
	}


	## File transfert directory frame ##
	set lfname [labelframe $frm.lfname4 -text [trans receiveddir]]
	pack $frm.lfname4 -anchor n -side top -expand 1 -fill x
	label $lfname.pshared -image [::skin::loadPixmap prefapps]
	pack $lfname.pshared -side left -anchor nw

	frame $lfname.1
	pack $lfname.1 -anchor w -side left -padx 0 -pady 5 -fill none
	label $lfname.1.receivedpath -text [trans receiveddir] -padx 5 -font sboldf
	entry $lfname.1.receiveddir -width 45  -textvariable [::config::getVar receiveddir]
	button $lfname.1.browse -text [trans browse] -command "Browse_Dialog_dir [::config::getVar receiveddir]"

	grid $lfname.1.receivedpath -row 1 -column 1 -sticky w
	grid $lfname.1.receiveddir -row 1 -column 2 -sticky w
	grid $lfname.1.browse -row 1 -column 3 -sticky w

	set lfname [labelframe $frm.lfname5 -text [trans audiovideo]]
	pack $frm.lfname5 -anchor n -side top -expand 1 -fill x
	label $lfname.pshared -image [::skin::loadPixmap webcam]
	pack $lfname.pshared -side left -anchor nw

	frame $lfname.1
	pack $lfname.1 -anchor w -side left -padx 0 -pady 5 -fill none
	button $lfname.1.webcam -text [trans editavsettings] -command [list ::AVAssistant::AVAssistant] -padx 20
	grid $lfname.1.webcam -row 1 -column 3 -sticky w -padx 20

	$nb.nn compute_size
	[$nb.nn getframe others].sw.sf compute_size

	#  .----------.
	# _| Advanced |________________________________________________

	#set frm [Rnotebook:frame $nb $Preftabs(advanced)]
	set frm [$nb.nn getframe advanced]

	set lfname [labelframe $frm.lfname -text [trans advancedprefs]]

	#Scrollable frame that will contain advanced optoins
	ScrolledWindow $lfname.sw
	ScrollableFrame $lfname.sw.sf -constrainedwidth 1
	$lfname.sw setwidget $lfname.sw.sf
	set path [$lfname.sw.sf getframe]

	# search box
	set searchfrm [frame $frm.searchframe]
	label $searchfrm.searchlabel -text "[trans searchadvprefs]" -anchor ne
	entry $searchfrm.searchfield -bg #FFFFFF -width 20 -validate key -vcmd "filter_prefs $path %P %d"

	pack $searchfrm.searchfield -anchor ne -side right
	pack $searchfrm.searchlabel -anchor ne -side right
	pack $searchfrm -anchor n -side top -fill x

	pack $frm.lfname -anchor n -side top -expand true -fill both
	pack $lfname.sw -anchor n -side top -expand true -fill both

	advanced_options_reload $path

	#add bindings to scroll with mousewheel
	#can not use local variables in bind scripts with {}.
	#and with "", can not use %D  :(
	# Mac OS X and Windows
	if { [OnMac] } {
	    bind .cfg <MouseWheel> {
		    set w [.cfg.notebook.nn getframe [.cfg.notebook.nn raise]]
		    if { [winfo exists $w.sw.sf] } {
			    $w.sw.sf yview scroll [expr {- (%D)}] units
		    } elseif { [winfo exists $w.lfname.sw.sf] } {
			    $w.lfname.sw.sf yview scroll [expr {- (%D)}] units
		    }
	    }
	} elseif { [OnWin] } {
	    bind .cfg <MouseWheel> {
		    set w [.cfg.notebook.nn getframe [.cfg.notebook.nn raise]]
		    if { [winfo exists $w.sw.sf] } {
			    $w.sw.sf yview scroll [expr {%D/-120}] units
		    } elseif { [winfo exists $w.lfname.sw.sf] } {
			    $w.lfname.sw.sf yview scroll [expr {%D/-120}] units
		    }
	    }
	} elseif { [OnX11] } {
	    bind .cfg <5> {
		    set w [.cfg.notebook.nn getframe [.cfg.notebook.nn raise]]
		    if { [winfo exists $w.sw.sf] } {
			    $w.sw.sf yview scroll +1 units
		    } elseif { [winfo exists $w.lfname.sw.sf] } {
			    $w.lfname.sw.sf yview scroll +1 units
		    }
	    }
	    bind .cfg <4> {
		    set w [.cfg.notebook.nn getframe [.cfg.notebook.nn raise]]
		    if { [winfo exists $w.sw.sf] } {
			    $w.sw.sf yview scroll -1 units
		    } elseif { [winfo exists $w.lfname.sw.sf] } {
			    $w.lfname.sw.sf yview scroll -1 units
		    }
	    }
	}

	frame $path.2
	label $path.2.delimiters -text "[trans delimiters]" -padx 5
	entry $path.2.ldelimiter -font splainf -width 3 -textvariable [::config::getVar leftdelimiter]
	label $path.2.example -text "HH:MM:SS" -padx 5
	entry $path.2.rdelimiter -font splainf -width 3 -textvariable [::config::getVar rightdelimiter]
	pack $path.2 -side top -padx 0 -fill x
	pack $path.2.delimiters $path.2.ldelimiter $path.2.example $path.2.rdelimiter -side left

	$nb.nn compute_size
	$lfname.sw.sf compute_size


	#  .---------.
	# _| Privacy |________________________________________________
	#set frm [Rnotebook:frame $nb $Preftabs(privacy)]
	set frm [$nb.nn getframe privacy]
	ScrolledWindow $frm.sw
	ScrollableFrame $frm.sw.sf -constrainedwidth 1
	$frm.sw setwidget $frm.sw.sf
	pack $frm.sw -anchor n -side top -expand true -fill both
	set frm [$frm.sw.sf getframe]

         # Allow/Block lists
	set lfname [labelframe $frm.lfname -text [trans prefprivacy]]
	pack $frm.lfname -anchor n -side top -expand 1 -fill both
	label $lfname.pprivacy -image [::skin::loadPixmap prefapps]
	pack $lfname.pprivacy -anchor nw -side left

	frame $lfname.allowlist -relief sunken -borderwidth 3
    label $lfname.allowlist.label -text "[trans allowlist]" \
		-foreground [::skin::getKey extraprivacy_intoal_fg] -font sboldf
	listbox $lfname.allowlist.box -yscrollcommand "$lfname.allowlist.ys set" \
		-relief flat -highlightthickness 0 -height 5
	scrollbar $lfname.allowlist.ys -command "$lfname.allowlist.box yview" -highlightthickness 0 \
        -borderwidth 1 -elementborderwidth 2
	pack $lfname.allowlist.label $lfname.allowlist.box -side top -expand false -fill x
	pack $lfname.allowlist.box -side left -expand true -fill both
	pack $lfname.allowlist.ys -side right -fill y -expand false


	frame $lfname.blocklist -relief sunken -borderwidth 3
	label $lfname.blocklist.label -text "[trans blocklist]" -foreground [::skin::getKey extraprivacy_intobl_fg] -font sboldf
	listbox $lfname.blocklist.box -yscrollcommand "$lfname.blocklist.ys set" \
		-relief flat -highlightthickness 0  -height 5

	scrollbar $lfname.blocklist.ys -command "$lfname.blocklist.box yview" -highlightthickness 0 \
         -borderwidth 1 -elementborderwidth 2
	pack $lfname.blocklist.label $lfname.blocklist.box -side top -expand false -fill x
	pack $lfname.blocklist.box -side left -expand true -fill both
	pack $lfname.blocklist.ys -side right -fill y -expand false


	frame $lfname.buttons -borderwidth 0
	button $lfname.buttons.right -text "[trans move] -->"  -command "Allow_to_Block $lfname" -width 13
	button $lfname.buttons.left -text "<-- [trans move]"  -command "Block_to_Allow $lfname" -width 13
	pack $lfname.buttons.right $lfname.buttons.left  -side top

	label $lfname.status -text ""
	frame $lfname.allowframe
	radiobutton $lfname.allowframe.allowallbutbl -text "[trans allowallbutbl]" -value 1 -variable temp_BLP
	radiobutton $lfname.allowframe.allowonlyinal -text "[trans allowonlyinal]" -value 0 -variable temp_BLP
	grid $lfname.allowframe.allowallbutbl -row 1 -column 1 -sticky w
	grid $lfname.allowframe.allowonlyinal -row 2 -column 1 -sticky w
	pack $lfname.status $lfname.allowframe -side bottom -anchor w -fill x
	pack $lfname.allowlist $lfname.buttons $lfname.blocklist -anchor w -side left -padx 10 -pady 10 -expand 1 -fill both

	bind $lfname.allowlist.box <<Button3>> "create_users_list_popup $lfname \"allow\" %X %Y"
	bind $lfname.blocklist.box <<Button3>> "create_users_list_popup $lfname \"block\" %X %Y"


	# Contact/Reverse lists
	set lfname [labelframe $frm.lfname2 -text [trans prefprivacy2]]
	set framePrivacyReverseList $lfname.reverselist
	pack $frm.lfname2 -anchor n -side top -expand 1 -fill both
	label $lfname.pprivacy -image [::skin::loadPixmap prefapps]
	pack $lfname.pprivacy -anchor nw -side left

	frame $lfname.contactlist -relief sunken -borderwidth 3
	label $lfname.contactlist.label -text "[trans contactlist]" -background [::skin::getKey extraprivacy_notfl_bg] -font sboldf
	listbox $lfname.contactlist.box -yscrollcommand "$lfname.contactlist.ys set" \
		-relief flat -highlightthickness 0 -height 5

	scrollbar $lfname.contactlist.ys -command "$lfname.contactlist.box yview" -highlightthickness 0 \
		-borderwidth 1 -elementborderwidth 2
	pack $lfname.contactlist.label $lfname.contactlist.box -side top -expand false -fill x
	pack $lfname.contactlist.ys -side right -fill y -expand false
	pack $lfname.contactlist.box -side left -expand true -fill both

	frame $lfname.reverselist -relief sunken -borderwidth 3
	label $lfname.reverselist.label -text "[trans reverselist]" -background [::skin::getKey extraprivacy_notrl_bg] -font sboldf
	listbox $lfname.reverselist.box -yscrollcommand "$lfname.reverselist.ys set" \
		-relief flat -highlightthickness 0  -height 5
	scrollbar $lfname.reverselist.ys -command "$lfname.reverselist.box yview" -highlightthickness 0 \
		-borderwidth 1 -elementborderwidth 2
	pack $lfname.reverselist.label $lfname.reverselist.box -side top -expand false -fill x
	pack $lfname.reverselist.ys -side right -fill y -expand false
	pack $lfname.reverselist.box -side left -expand true -fill both

	frame $lfname.adding
	entry $lfname.adding.enter
	button $lfname.adding.addal -text "[trans addtoal]" -command "Add_To_List $lfname AL"
	button $lfname.adding.addbl -text "[trans addtobl]" -command "Add_To_List $lfname BL"
	button $lfname.adding.addfl -text "[trans addtofl]" -command "Add_To_List $lfname FL"
	pack $lfname.adding.addal $lfname.adding.addbl $lfname.adding.addfl -side left
	pack $lfname.adding.enter -side top


	frame $lfname.buttons -borderwidth 0
	button $lfname.buttons.right -text "[trans delete] -->"  -command "Remove_Contact $lfname" -width 13
	button $lfname.buttons.left -text "<-- [trans copy]"  -command "Reverse_to_Contact $lfname" -width 13
	pack $lfname.adding  $lfname.buttons.right $lfname.buttons.left -side top


 #       pack $lfname.addal $lfname.addbl $lfname.addfl -side left

 #    	grid $lfname.enter -row 3 -column 1 -sticky w
 #	grid $lfname.addal -row 4 -column 1 -sticky w
 #	grid $lfname.addbl -row 4 -column 2 -sticky w
 #	grid $lfname.addfl -row 4 -column 3 -sticky w

	label $lfname.status -text ""

	pack $lfname.status -side bottom  -anchor w  -fill x
	pack $lfname.contactlist $lfname.buttons $lfname.reverselist -anchor w -side left -padx 10 -pady 10 -expand 1 -fill both

	bind $lfname.contactlist.box <<Button3>> "create_users_list_popup $lfname \"contact\" %X %Y"
	bind $lfname.reverselist.box <<Button3>> "create_users_list_popup $lfname \"reverse\" %X %Y"


	::Event::registerEvent contactRemoved protocol [list Fill_users_list_event $frm.lfname $frm.lfname2]
	::Event::registerEvent contactListChange all [list Fill_users_list_event $frm.lfname $frm.lfname2]
	::Event::registerEvent contactBlocked all [list Fill_users_list_event $frm.lfname $frm.lfname2]
	::Event::registerEvent contactUnblocked all [list Fill_users_list_event $frm.lfname $frm.lfname2]
	::Event::registerEvent contactMoved all [list Fill_users_list_event $frm.lfname $frm.lfname2]
	::Event::registerEvent contactAdded all [list Fill_users_list_event $frm.lfname $frm.lfname2]
	::Event::registerEvent contactRemoved all [list Fill_users_list_event $frm.lfname $frm.lfname2]
	::Event::registerEvent contactlistLoaded all [list Fill_users_list_event $frm.lfname $frm.lfname2]

	#  .----------.
	# _| Blocking |________________________________________________
	#set frm [Rnotebook:frame $nb $Preftabs(blocking)]

	## Check on disconnect ##
	#set lfname [labelframe $frm.lfname -text [trans prefblock1]]
	#pack $frm.lfname -anchor n -side top -expand 1 -fill x
	#label $lfname.ppref1 -image [::skin::loadPixmap prefapps]
	#pack $lfname.ppref1 -side left -padx 5 -pady 5
	#checkbutton $lfname.enable -text "[trans checkonfln]" -onvalue 1 -offvalue 0 -variable [::config::getVar checkonfln]
	#pack $lfname.enable  -anchor w -side left -padx 0 -pady 5

	## "You have been blocked" group ##
	#set lfname [labelframe $frm.lfname3 -text [trans prefblock3]]
	#pack $frm.lfname3 -anchor n -side top -expand 1 -fill x
	#label $lfname.ppref3 -image [::skin::loadPixmap prefapps]
	#pack $lfname.ppref3 -side left -padx 5 -pady 5
	#checkbutton $lfname.group -text "[trans blockedyougroup]" -onvalue 1 -offvalue 0 -variable [::config::getVar showblockedgroup]
	#pack $lfname.group  -anchor w -side left -padx 0 -pady 5

	## Continuously check ##
	#set lfname [labelframe $frm.lfname2 -text [trans prefblock2]]
	#pack $frm.lfname2 -anchor n -side top -expand 1 -fill x
	#label $lfname.ppref2 -image [::skin::loadPixmap prefapps]
	#pack $lfname.ppref2 -side left -padx 5 -pady 5

	#frame $lfname.enable -class Degt
	#pack $lfname.enable -anchor w -side left
	#checkbutton $lfname.enable.cb -text "[trans checkblocking]" -onvalue 1 -offvalue 0 -variable [::config::getVar checkblocking] -command UpdatePreferences
	#grid $lfname.enable.cb -row 1 -column 1 -sticky w

	#frame $lfname.check -class Degt
	#pack $lfname.check -anchor w -side left -padx 0 -pady 5

        #label $lfname.check.linter1 -text "[trans blockinter1]"
        #label $lfname.check.linter2 -text "[trans blockinter2]"
        #label $lfname.check.linter3 -text "[trans blockinter3]"
        #label $lfname.check.linter4 -text "[trans blockinter4]"
        #label $lfname.check.lusers -text "[trans blockusers]"
        #entry $lfname.check.inter1 -validate all -vcmd "BlockValidateEntry %W %P 1" -invcmd "BlockValidateEntry %W %P 0 15" -width 4 -textvariable [::config::getVar blockinter1]
        #entry $lfname.check.inter2 -validate all -vcmd "BlockValidateEntry %W %P 2" -invcmd "BlockValidateEntry %W %P 0 30"  -width 4 -textvariable [::config::getVar blockinter2]
        #entry $lfname.check.inter3 -validate all -vcmd "BlockValidateEntry %W %P 3" -invcmd "BlockValidateEntry %W %P 0 2" -width 4 -textvariable [::config::getVar blockinter3]
        #entry $lfname.check.users -validate all -vcmd "BlockValidateEntry %W %P 4" -invcmd "BlockValidateEntry %W %P 0 5" -width 4 -textvariable [::config::getVar blockusers]

        #grid $lfname.check.linter1 -row 1 -column 1 -sticky w
        #grid $lfname.check.linter2 -row 1 -column 3 -sticky w
        #grid $lfname.check.linter3 -row 2 -column 3 -sticky w
        #grid $lfname.check.linter4 -row 2 -column 5 -sticky w
        #grid $lfname.check.lusers -row 2 -column 1 -sticky w
        #grid $lfname.check.inter1 -row 1 -column 2 -sticky w
        #grid $lfname.check.inter2 -row 1 -column 4 -sticky w
        #grid $lfname.check.inter3 -row 2 -column 4 -sticky w
        #grid $lfname.check.users -row 2 -column 2 -sticky w

	#pack $lfname.enable $lfname.check -anchor w -side top

	#frame $frm.dummy -class Degt
	#pack $frm.dummy -anchor n -side top -expand 1 -fill both -pady 150

    # Frame for common buttons (all preferences)
    frame .cfg.buttons
    button .cfg.buttons.save -text [trans save] -default active -command "wm withdraw .cfg; SavePreferences; destroy .cfg"
    button .cfg.buttons.cancel -text [trans close] -command "destroy .cfg"
    bind .cfg <<Escape>> "destroy .cfg"
    pack .cfg.buttons.save .cfg.buttons.cancel -side right -padx 10 -pady 5
    pack .cfg.buttons -side bottom -fill x


    #Rnotebook:totalwidth $nb
    $nb.nn raise personal
    $nb.nn compute_size
    pack $nb.nn -expand true -fill both
    #pack $nb -fill both -expand 1 -padx 10 -pady 10

    pack .cfg.notebook -side bottom -fill both -expand true -padx 5 -pady 5


    InitPref 1
    UpdatePreferences

    #wm geometry .cfg [expr [Rnotebook:totalwidth $nb] + 50]x595

    #catch { Rnotebook:raise $nb $Preftabs($settings) }

	# This should raise the settings tab depending on the arg..
	catch {$nb.nn raise $settings}

    bind .cfg <Destroy> "UnregisterPrivacyEvents; RestorePreferences %W"

    wm state .cfg normal


    moveinscreen .cfg 60

    # Show requested page
    # The move in screen could maybe cause the window to get destroyed when it does the 'update' so let's catch this
    catch { $nb.nn raise $settings }
}

proc UnregisterPrivacyEvents {} {
	set nb .cfg.notebook
	if {[winfo exists $nb]} {
		set lfname [$nb.nn getframe privacy]
		set frm [$lfname.sw.sf getframe]
		::Event::unregisterEvent contactRemoved protocol [list Fill_users_list_event $frm.lfname $frm.lfname2]
		::Event::unregisterEvent contactListChange all [list Fill_users_list_event $frm.lfname $frm.lfname2]
		::Event::unregisterEvent contactBlocked all [list Fill_users_list_event $frm.lfname $frm.lfname2]
		::Event::unregisterEvent contactUnblocked all [list Fill_users_list_event $frm.lfname $frm.lfname2]
		::Event::unregisterEvent contactMoved all [list Fill_users_list_event $frm.lfname $frm.lfname2]
		::Event::unregisterEvent contactAdded all [list Fill_users_list_event $frm.lfname $frm.lfname2]
		::Event::unregisterEvent contactRemoved all [list Fill_users_list_event $frm.lfname $frm.lfname2]
		::Event::unregisterEvent contactlistLoaded all [list Fill_users_list_event $frm.lfname $frm.lfname2]
	}
}

proc Fill_users_list_event { path1 path2 args} {
        Fill_users_list $path1 $path2
}


proc getTaskbarHeight {{w .taskBarSize}} {
	global taskbarHeight

	return [list 30 0 0 0]

	catch {destroy $w}
	# the -bg {} is used as a trick, it's some kind of bug with tk, where the background of the window becomes transparent
	toplevel $w
	wm attributes $w -alpha 0 -disabled 1
	wm state $w zoomed
 	update
 	set taskbarBottom [expr {[winfo screenheight $w] - [winfo height $w] - [winfo rooty $w]}]
 	set taskbarRight [expr {[winfo screenwidth $w] - [winfo width $w] - [winfo rootx $w]}]

 	set taskbarTop [expr {[winfo y $w] + 4}]
 	set taskbarLeft [expr {[winfo x $w] + 4}]
 	destroy $w

 	return [list $taskbarTop $taskbarRight $taskbarBottom $taskbarLeft]
}


#check if a window is outside the screen and move it in
proc moveinscreen {window {mindist 0}} {

	update

	#Small check to verify the window really exist
	if { ![winfo exists $window] } {
 		return
 	}

	#set winx [winfo width $window]
	#set winy [winfo height $window]

	set scrx [winfo screenwidth .]
	set scry [winfo screenheight .]

 	if {[OnWin] } {
 		set tb [getTaskbarHeight]
 		set scry [expr {$scry - [lindex $tb 0] - [lindex $tb 2]}]
 		set scrx [expr {$scrx - [lindex $tb 1] - [lindex $tb 3]}]
 	}

	#set wi_geometry [winfo geometry $window]
	#scan $wi_geometry "%dx%d+%d+%d" winx winy winpx winpy

	set winpx [winfo rootx $window]
	set winpy [winfo rooty $window]

	set geom [wm geometry $window]
	scan $geom "%dx%d%c%d%c%d" winx winy sign1 decorationLeft sign2 decorationTop

	# Measure left edge, and assume all edges except top are the
	# same thickness
	if { $sign1 == 45} { ;#'-' character
		#Get size from right decoration
		set decorationThickness [expr {($scrx - $decorationLeft) - ($winpx + $winx)}]
		status_log "Minus: dec=$decorationThickness --> ($scrx + $decorationLeft) - ($winpx + $winx)\n"
	} else {
		set decorationThickness [expr {$winpx - $decorationLeft}]
	}

	# Find titlebar and menubar thickness
	if { $sign2 == 45 } { ;#'-' character
		set menubarThickness [expr {($scry - $decorationLeft) - ($winpy + $winy)}]
	} else {
		set menubarThickness [expr {$winpy - $decorationTop}]
	}


	#status_log "Window information: $window\n" white
	#status_log "Geometry: $geom\n (menuThickness= $menubarThickness, dec=$decorationThickness)\n"
	#status_log "Width, height: [winfo width $window]x[winfo height $window]\n"
	#status_log "winPx, winPy: $winpx,$winpy\n"
	#status_log "decLeft=$decorationLeft / decTop=$decorationTop\n"
	#status_log "-------------------\n" white


    	# Add this decoration size when checking size and limits
	incr winx [expr {2 * $decorationThickness}]
	incr winy $decorationThickness
	incr winy $menubarThickness
	incr winpx [expr {0 - $decorationThickness}]
	incr winpy [expr {0 - $menubarThickness}]

	#check if the window is too large to fit on the screen
	if { [expr {$winx > ($scrx-(2*$mindist))}] } {
		set winx [expr {$scrx-(2*$mindist)}]
	}
	if { [expr {$winy > ($scry-(2*$mindist))}] } {
		set winy [expr {$scry-(2*$mindist)}]
	}

	#check if the window is positioned off the screen
	if { [expr {$winpx + $winx > ($scrx-$mindist)}] } {
		set winpx [expr {$scrx-$mindist-$winx}]
	}
	if { [expr {$winpx < $mindist}] } {
		set winpx $mindist
	}
	if { [expr {$winpy + $winy > ($scry-(2*$mindist))}] } {
		set winpy [expr {$scry-$mindist-$winy}]
	}
	if { [expr {$winpy < $mindist}] } {
		set winpy $mindist
	}

    	# Substract decoration size, as wm geometry needs the window geometry
    	# without decoration
	incr winx [expr {0 - 2 * $decorationThickness}]
	incr winy [expr {0 - $decorationThickness}]
	incr winy [expr {0 - $menubarThickness }]

	catch {wm geometry $window "${winx}x${winy}+${winpx}+${winpy}"}
}

proc advanced_options_reload {path} {
	global advanced_options

	set i 0
	foreach opt $advanced_options {
		incr i
		#For each advanced option, check if it's a title, it's local config, or global configs
		if {[lindex $opt 0] == "title" } {
			if { $i != 1 } {
				label $path.sp$i -font bboldf
				label $path.l$i -font bboldf -text "[trans [lindex $opt 1]]"
				pack $path.sp$i $path.l$i -side top -anchor w -pady 4
			} else {
				label $path.l$i -font bboldf -text "[trans [lindex $opt 1]]"
				pack $path.l$i -side top -anchor w -pady 4
			}
		} else {
			if {[lindex $opt 0] == "local"} {
				set config_var [::config::getVar [lindex $opt 1]]
			} elseif {[lindex $opt 0] == "global"} {
				set config_var [::config::getGlobalVar [lindex $opt 1]]
			} else {
				label $path.l$i -text "ERROR: Unknown advanced option type: \"[lindex $opt 0]\""
				pack $path.l$i -side top -anchor w
				continue
			}

			switch [lindex $opt 2] {
				bool {
					checkbutton $path.cb$i -text [trans [lindex $opt 3]] -font splainf -variable $config_var
					pack $path.cb$i -side top -anchor w
				}
				bool_inv {
					checkbutton $path.cb$i -text [trans [lindex $opt 3]] -font splainf -variable $config_var -onvalue 0 -offvalue 1
					pack $path.cb$i -side top -anchor w
				}
				folder {
					frame $path.fr$i
					button $path.fr$i.browse -text [trans browse] -command "Browse_Dialog_dir [::config::getVar [lindex $opt 1]]"
					LabelEntry $path.fr$i.le "[trans [lindex $opt 3]]:" $config_var 20
					pack $path.fr$i.le -side left -anchor w -expand true -fill x
					pack $path.fr$i.browse -side left
					pack $path.fr$i -side top -anchor w -expand true -fill x
				}
				int {
					LabelEntry $path.le$i "[trans [lindex $opt 3]]:" $config_var 20
					$path.le$i.ent configure -validate focus -validatecommand "check_int %W" -invalidcommand "$path.le$i.ent delete 0 end; $path.le$i.ent insert end [set $config_var]"
					pack $path.le$i -side top -anchor w -expand true -fill x
				}
				default {
					LabelEntry $path.le$i "[trans [lindex $opt 3]]:" $config_var 20
					pack $path.le$i -side top -anchor w -expand true -fill x
				}
			}

			if { [lindex $opt 4] != "" } {
				label $path.exp$i -text "[trans [lindex $opt 4]]\n" -font examplef
				pack $path.exp$i -side top -anchor w -padx 15
			}

		}

	}

}



proc check_int {text} {
	set int_val "0"
	catch { expr {int([$text get])} } int_val
	if { $int_val != [$text get] } {
		status_log "Bad!!\n"
		return false
	}
	status_log "Good!!\n"
	return true
}

# This is where we fill in the Entries of the Preferences
proc InitPref { {fullinit 0} } {
	global Preftabs proxy_user proxy_pass pager locale_codes
	set nb .cfg.notebook

	if { $fullinit } {
		set proxy_user [::config::getKey proxyuser]
		set proxy_pass [::config::getKey proxypass]
	        set pager [::abook::getPersonal MOB]
		# Insert nickname if online, disable if offline
		#set lfname [Rnotebook:frame $nb $Preftabs(personal)]
		set lfname [$nb.nn getframe personal]
		set lfname [$lfname.sw.sf getframe]

		if { [::MSN::myStatusIs] == "FLN" } {
			$lfname.lfname.1.name.entry configure -state disabled
			$lfname.lfname4.2.chgmob configure -state disabled
			$lfname.lfname4.2.person configure -state disabled
		} else {
			set nick [::abook::getPersonal MFN]
			if {[::config::getKey emailVerified 1] == 0} {
				set nick "$nick [trans emailnotverified]"
			}

			$lfname.lfname.1.name.entry delete 0 end
			$lfname.lfname.1.name.entry insert 0 $nick
			if {[::config::getKey emailVerified 1] == 0} {
				#disable nick change (email not yet verified)
				$lfname.lfname.1.name.entry configure -state disabled
			} else {
				$lfname.lfname.1.name.entry configure -state normal
			}


			$lfname.lfname4.2.chgmob configure -state normal
			$lfname.lfname4.2.person configure -state normal
		}

		if {[::config::getKey protocol] >= 11} {
			$lfname.lfname.1.psm.entry delete 0 end
			$lfname.lfname.1.psm.entry insert 0 [::abook::getPersonal PSM]
		}

		$lfname.lfname.1.p4c.entry delete 0 end
		$lfname.lfname.1.p4c.entry insert 0 [::config::getKey p4c_name]

		if {[::config::getKey protocol] >= 18} {
			$lfname.lfname.1.ep.entry delete 0 end
			$lfname.lfname.1.ep.entry insert 0 [::config::getKey epname aMSN]
		}


		# Get My Phone numbers and insert them
		set lfname "$lfname.lfname4"
	    if { [::abook::getPersonal MBE] == "N" } {
		 $lfname.2.mobphone configure -state disabled
	    }
		if { [::MSN::myStatusIs] == "FLN" } {
			$lfname.2.ephone1 configure -state disabled
			$lfname.2.ephone31 configure -state disabled
			$lfname.2.ephone32 configure -state disabled
			$lfname.2.ephone41 configure -state disabled
			$lfname.2.ephone42 configure -state disabled
			$lfname.2.ephone51 configure -state disabled
			$lfname.2.ephone52 configure -state disabled
		        $lfname.2.mobphone configure -state disabled
		} else {
			$lfname.2.ephone1 configure -state normal
			$lfname.2.ephone31 configure -state normal
			$lfname.2.ephone32 configure -state normal
			$lfname.2.ephone41 configure -state normal
			$lfname.2.ephone42 configure -state normal
			$lfname.2.ephone51 configure -state normal
			$lfname.2.ephone52 configure -state normal
			$lfname.2.ephone1 delete 0 end
			$lfname.2.ephone31 delete 0 end
			$lfname.2.ephone32 delete 0 end
			$lfname.2.ephone41 delete 0 end
			$lfname.2.ephone42 delete 0 end
			$lfname.2.ephone51 delete 0 end
			$lfname.2.ephone52 delete 0 end

			$lfname.2.ephone1 insert 0 [lindex [split [::abook::getPersonal PHH] " "] 0]
			$lfname.2.ephone31 insert 0 [lindex [split [::abook::getPersonal PHH] " "] 1]
			$lfname.2.ephone32 insert 0 [join [lrange [split [::abook::getPersonal PHH] " "] 2 end]]
			$lfname.2.ephone41 insert 0 [lindex [split [::abook::getPersonal PHW] " "] 1]
			$lfname.2.ephone42 insert 0 [join [lrange [split [::abook::getPersonal PHW] " "] 2 end]]
			$lfname.2.ephone51 insert 0 [lindex [split [::abook::getPersonal PHM] " "] 1]
			$lfname.2.ephone52 insert 0 [join [lrange [split [::abook::getPersonal PHM] " "] 2 end]]

		    #$lframe.2.mobphone configure -variable [::abook::getPersonal MOB]
		}

		# Init remote preferences
		#set lfname [Rnotebook:frame $nb $Preftabs(connection)]
		set lfname [$nb.nn getframe connection]
		set lfname [$lfname.sw.sf getframe]
		$lfname.lfname3.2.pass delete 0 end
		$lfname.lfname3.2.pass insert 0 "[::config::getKey remotepassword]"

	}

	#fill the locales combobox
	set lfname [$nb.nn getframe personal]
	set lfname "[$lfname.sw.sf getframe].lfname2a"
	$lfname.clocale list delete 0 end
	set loc_item_id 0
	set loc_item_selected 0
	foreach loc_item $locale_codes {
		set loc_name [lindex $loc_item 0]
		set loc_id [lindex $loc_item 1]
		$lfname.clocale list insert end $loc_name
		if {$loc_id == [::config::getKey localecode [::config::getKey localecode_autodetect 1033]]} {
			set loc_item_selected $loc_item_id
		}
		incr loc_item_id
	}
	$lfname.clocale select $loc_item_selected
	$lfname.clocale configure -editable false

	# Lets fill our profile combobox
	#set lfname [Rnotebook:frame $nb $Preftabs(others)]
	set lfname [$nb.nn getframe others]
	set lfname "[$lfname.sw.sf getframe].lfname3"
   	set idx 0
   	set tmp_list ""
	$lfname.1.profile list delete 0 end
   	while { [LoginList get $idx] != 0 } {
		lappend tmp_list [LoginList get $idx]
		incr idx
	}
   	eval $lfname.1.profile list insert end $tmp_list
	$lfname.1.profile insert 0 [lindex $tmp_list 0]
   	unset idx
   	unset tmp_list
	$lfname.1.profile configure -editable false

	# Lets disable loging if on default profile
	if { [LoginList exists 0 [::config::getKey login]] == 0 } {
		#set lfname [Rnotebook:frame $nb $Preftabs(loging)]
		set lfname [$nb.nn getframe loging]
		set lfname [$lfname.sw.sf getframe]
		set lfname "$lfname.lfname"
		$lfname.log configure -state disabled
		$lfname.camlog configure -state disabled
		set lfname [$nb.nn getframe loging]
		set lfname [$lfname.sw.sf getframe]
		set lfname "$lfname.lfname3"
		$lfname.logconnect configure -state disabled
		$lfname.logdisconnect configure -state disabled
		$lfname.logemail configure -state disabled
		$lfname.logstate configure -state disabled
		$lfname.lognick configure -state disabled
		$lfname.logpsm configure -state disabled
	}

	# Let's fill our list of States
	#set lfname [Rnotebook:frame $nb $Preftabs(session)]
	set lfname [$nb.nn getframe session]
	set lfname [$lfname.sw.sf getframe]
	$lfname.lfname2.statelist.box delete 0 end
	for { set idx 0 } { $idx < [StateList size] } {incr idx } {
		$lfname.lfname2.statelist.box insert end [lindex [StateList get $idx] 0]
	}

        # Fill the user's lists
        #set lfname [Rnotebook:frame $nb $Preftabs(privacy)]
	set lfname [$nb.nn getframe privacy]
	set lfname [$lfname.sw.sf getframe]
        Fill_users_list "$lfname.lfname" "$lfname.lfname2"

}


# This is where the preferences entries get enabled disabled
proc UpdatePreferences {} {
	global Preftabs

	set nb .cfg.notebook

	#fonts
	set lfname [$nb.nn getframe personal]
	set lfname [$lfname.sw.sf getframe]
	set lfname "${lfname}.lfname3"
	if { [::config::getKey disableuserfonts] } {
			$lfname.bfontin configure -state disabled
			$lfname.bfontinreset configure -state disabled
	} else {
		$lfname.bfontin configure -state normal
		if { [::config::getKey theirchatfont] == "" } {
			$lfname.bfontinreset configure -state disabled
		} else {
			$lfname.bfontinreset configure -state normal
		}
	}

	# autoaway checkbuttons and entries
	#set lfname [Rnotebook:frame $nb $Preftabs(session)]
	set lfname [$nb.nn getframe session]
	set lfname [$lfname.sw.sf getframe]
	set lfname "${lfname}.lfname"
	if { [::config::getKey autoidle] == 0 } {
		$lfname.1.eautonoact configure -state disabled
	} else {
		$lfname.1.eautonoact configure -state normal
	}
	if { [::config::getKey autoaway] == 0 } {
		$lfname.2.eautoaway configure -state disabled
	} else {
		$lfname.2.eautoaway configure -state normal
	}

	# proxy connection entries and checkbuttons
	#set lfname [Rnotebook:frame $nb $Preftabs(connection)]
	set lfname [$nb.nn getframe connection]
	set lfname [$lfname.sw.sf getframe]
	set lfname "${lfname}.lfnameconnection"
	if { [::config::getKey connectiontype] == "proxy" } {
		$lfname.4.post configure -state normal
		$lfname.4.ssl configure -state disable
		$lfname.4.socks5 configure -state normal
		$lfname.5.server configure -state normal
		$lfname.5.port configure -state normal
		if { [::config::getKey proxytype] == "socks5" || [::config::getKey proxytype] == "http"} {
			$lfname.5.user configure -state normal
			$lfname.5.pass configure -state normal
		} else {
			$lfname.5.user configure -state disabled
			$lfname.5.pass configure -state disabled
		}
	} else {
		$lfname.4.post configure -state disabled
		$lfname.4.ssl configure -state disabled
		$lfname.4.socks5 configure -state disabled
		$lfname.5.server configure -state disabled
		$lfname.5.port configure -state disabled
		$lfname.5.user configure -state disabled
		$lfname.5.pass configure -state disabled
	}
	#set lfname [Rnotebook:frame $nb $Preftabs(connection)]
	set lfname [$nb.nn getframe connection]
	set lfname [$lfname.sw.sf getframe]
	set lfname "${lfname}.lfname"
	if { [::config::getKey autoftip] } {
		$lfname.1.ipaddr.entry configure -textvariable "" -text "Hola"
		$lfname.1.ipaddr.entry delete 0 end
		$lfname.1.ipaddr.entry insert end [::config::getKey myip]
		$lfname.1.ipaddr.entry configure -state disabled
	} else {
		$lfname.1.ipaddr.entry configure -state normal -textvariable [::config::getVar manualip]
	}

	# remote control
	#set lfname [Rnotebook:frame $nb $Preftabs(connection)]
	set lfname [$nb.nn getframe connection]
	set lfname [$lfname.sw.sf getframe]
	set lfname "${lfname}.lfname3"
	if { [::config::getKey enableremote] == 1 } {
		$lfname.2.pass configure -state normal
	} else {
		$lfname.2.pass configure -state disabled
	}

	# sound
	set lfname [$nb.nn getframe others]
	set lfname [$lfname.sw.sf getframe]
	set lfname "${lfname}.lfname"
	#Disabled that if we are on Mac OS X because we can't choose Snack
	if { ![OnMac] } {
		if { [::config::getKey usesnack] == 1 } {
			#load Snack when being used
			if {![catch {require_snack}]} {
				$lfname.1.sound.sound configure -state disabled
				snack::audio playLatency 750
			} else {
				::config::setKey usesnack 0
				$lfname.1.sound.sound configure -state normal
				msg_box [trans snackfailed]
			}
		} else {
			$lfname.1.sound.sound configure -state normal
		}
	}

}


# This function sets all fonts to plain instead of bold,
# excluding the ones that are set to sboldf or examplef
proc setCfgFonts {path value} {
	catch {set res [$path cget -font]}
	if { [info exists res] } {
		if { $res != "sboldf" && $res != "examplef" && $res != "bboldf"} {
		    catch { $path configure -font $value }
		}
	}
        foreach child [winfo children $path] {
            setCfgFonts $child $value
        }
}



proc SavePreferences {} {
	global auto_path HOME2 tlsinstalled
	global myconfig proxy_server proxy_port list_BLP temp_BLP Preftabs libtls proxy_user proxy_pass pager locale_codes

	set nb .cfg.notebook

	# If the default ns server changed, change the start_ns_server too.
	if { [::config::getKey default_ns_server] != [set myconfig(default_ns_server)] } {
		::config::setKey start_ns_server [::config::getKey default_ns_server]
	}

	# I. Data Validation & Metavariable substitution
	# Proxy settings
	set p_server [string trim $proxy_server]
	set p_port [string trim $proxy_port]
	if { ![string is integer -strict $p_port] } {
		set p_port 8080
	}
	set p_user [string trim $proxy_user]
	set p_pass [string trim $proxy_pass]

	::config::setKey proxy [list $p_server $p_port]

	if { ($p_pass != "") && ($p_user != "")} {
		::config::setKey proxypass $p_pass
		::config::setKey proxyuser $p_user
		::config::setKey proxyauthenticate 1
	} else {
		::config::setKey proxypass ""
		::config::setKey proxyuser ""
		::config::setKey proxyauthenticate 0
	}

	if {![string is digit [::config::getKey initialftport]] || [string length [::config::getKey initialftport]] == 0 } {
		::config::setKey initialftport 6891
	}

	# Make sure entries x and y offsets and idle time are digits, if not revert to old values
	if { [string is digit [::config::getKey notifyXoffset]] == 0 } {
		::config::setKey notifyXoffset $myconfig(notifyXoffset)
	}
	if { [string is digit [::config::getKey notifyYoffset]] == 0 } {
		::config::setKey notifyYoffset $myconfig(notifyYoffset)
	}
	if { [string is digit [::config::getKey idletime]] == 0 } {
		::config::setKey idletime $myconfig(idletime)
	}
	if { [string is digit [::config::getKey awaytime]] == 0 } {
		::config::setKey awaytime $myconfig(awaytime)
	}
	if { [::config::getKey idletime] >= [::config::getKey awaytime] } {
		::config::setKey awaytime $myconfig(awaytime)
		::config::setKey idletime $myconfig(idletime)
	}

	# write correct locale code to config
	set lfname [$nb.nn getframe personal]
	set lfname "[$lfname.sw.sf getframe].lfname2a"
	set loc_item_selected [$lfname.clocale curselection]
	status_log "selected item: $loc_item_selected" red
	::config::setKey localecode [lindex [lindex $locale_codes $loc_item_selected] 1]

	# Check and save phone numbers

	if { [::MSN::myStatusIs] != "FLN" && 1 == 0} {
		#set lfname [Rnotebook:frame $nb $Preftabs(personal)]
		set lfname [$nb.nn getframe personal]
		set lfname [$lfname.sw.sf getframe]
		set lfname "$lfname.lfname4"

		set cntrycode [$lfname.2.ephone1 get]
		if { [string is digit $cntrycode] == 0 } {
			set cntrycode [lindex [split [::abook::getPersonal PHH] " "] 0]
		}

		append home [$lfname.2.ephone31 get] " " [$lfname.2.ephone32 get]
		if { [string is digit [$lfname.2.ephone31 get]] == 0 } {
			set home [join [lrange [split [::abook::getPersonal PHH] " "] 1 end]]
		}
		append work [$lfname.2.ephone41 get] " " [$lfname.2.ephone42 get]
		if { [string is digit [$lfname.2.ephone41 get]] == 0 } {
			set work [join [lrange [split [::abook::getPersonal PHW] " "] 1 end]]
		}
		append mobile [$lfname.2.ephone51 get] " " [$lfname.2.ephone52 get]
		if { [string is digit [$lfname.2.ephone51 get]] == 0 } {
			set mobile [join [lrange [split [::abook::getPersonal PHM] " "] 1 end]]
		}

		set home [urlencode [set home "$cntrycode $home"]]
		set work [urlencode [set work "$cntrycode $work"]]
		set mobile [urlencode [set mobile "$cntrycode $mobile"]]
		if { $home != [::abook::getPersonal PHH] } {
			::abook::setPhone home $home
		}
		if { $work != [::abook::getPersonal PHW] } {
			::abook::setPhone work $work
		}
		if { $mobile != [::abook::getPersonal PHM] } {
			::abook::setPhone mobile $mobile
		}
		if {$pager != [::abook::getPersonal MOB] } {
			::abook::setPhone pager $pager
		}

		::abook::getIPConfig
	}

	# Change name
	#set lfname [Rnotebook:frame $nb $Preftabs(personal)]
	set lfname [$nb.nn getframe personal]
	set lfname [$lfname.sw.sf getframe]
	set lfname "$lfname.lfname.1"
	set new_name [$lfname.name.entry get]
	if {$new_name != "" && $new_name != [::abook::getPersonal MFN] && [::MSN::myStatusIs] != "FLN" && [::config::getKey emailVerified 1] == 1} {
		::MSN::changeName $new_name
	}
	if {[::config::getKey protocol] >= 11} {
		set new_psm [$lfname.psm.entry get]
		if {$new_psm != "" && $new_psm != [::abook::getPersonal PSM] && [::MSN::myStatusIs] != "FLN"} {
			::MSN::changePSM $new_psm
		}
	}
	::config::setKey p4c_name [$lfname.p4c.entry get]

	if {[::config::getKey protocol] >= 18} {
		::MSN::changeEndPointName [$lfname.ep.entry get]
	}

	# Get remote controlling preferences
	#set lfname [Rnotebook:frame $nb $Preftabs(connection)]
	set lfname [$nb.nn getframe connection]
	set lfname [$lfname.sw.sf getframe]
	set myconfig(remotepassword) "[$lfname.lfname3.2.pass get]"
	::config::setKey remotepassword $myconfig(remotepassword)

	#Copy to myconfig array, because when the window is closed, these will be restored (RestorePreferences)
	array set myconfig [::config::getAll]

	# Save configuration of the BLP ( Allow all other users to see me online )
	if { $list_BLP != $temp_BLP } {
		AllowAllUsers $temp_BLP
	}


	# Save tls package configuration
	if { [::config::getKey libtls_temp] != $libtls } {
		set libtls [::config::getKey libtls_temp]
		if { $libtls != "" && [lsearch $auto_path $libtls] == -1 } {
			lprepend auto_path $libtls
		}

		if { $tlsinstalled == 0 && [catch {package require tls}] } {
			# Either tls is not installed, or $auto_path does not point to it.
			# Should now never happen; the check for the presence of tls is made
			# before this point.
			status_log "Could not find the package tls on this system.\n"
			set tlsinstalled 0
		} else {
			set tlsinstalled 1
		}

		set fd [open [file join $HOME2 tlsconfig.tcl] w]
		puts $fd "set libtls [list $libtls]"
		close $fd
	}


	# Blocking
	#if { [::config::getKey blockusers] == "" } { ::config::setKey blockusers 1}
	#if { [::config::getKey checkblocking] == 1 } {
		#BeginVerifyBlocked [::config::getKey blockinter1] [::config::getKey blockinter2] [::config::getKey blockusers] [::config::getKey blockinter3]
	#} else {
		#StopVerifyBlocked
	#}

	# Save configuration.
	save_config
	::MSN::contactListChanged
	::config::saveGlobal

	if { [::MSN::myStatusIs] != "FLN" } {
		cmsn_draw_online 0 1
	}

	if { [info exists ::start_on_windows_boot] } {
		WinRegKey $::start_on_windows_boot
        }

	::Event::fireEvent changedPreferences gui

	#Reset the banner incase the option changed
	resetBanner

	#Reload the trayicon in case it got changed
	init_dock


}

proc RestorePreferences { {win ".cfg"} } {

	if { $win != ".cfg" } { return }

	global myconfig proxy_server proxy_port

	::config::setAll [array get myconfig]
	array unset myconfig

	# Save configuration.
	save_config
	::MSN::contactListChanged
	::config::saveGlobal

	if { [::MSN::myStatusIs] != "FLN" } {
		cmsn_draw_online 0 1
	}

	::Event::fireEvent changedPreferences gui

	#::MSN::WriteSB ns "SYN" "0"

	# Save configuration.
	#save_config

}

###################### Other Features     ###########################

# Usage: LabelEntry .mypath.mailer "Label:" config(mailcommand) 20
proc LabelEntry { path lbl variable width } {


    frame $path
	label $path.lbl -text $lbl -justify left \
	    -font splainf
	entry $path.ent -textvariable $variable  \
	    -width $width -font splainf
	pack $path.lbl -side left -anchor e
	pack $path.ent -side left -anchor e -expand 1 -fill x -padx 3
#	pack $path.ent $path.lbl -side right -anchor e -expand 1 -fill x
}

proc LabelEntryGet { path } {
    return [$path.ent get]
}


proc BlockValidateEntry { widget data type {correct 0} } {

    switch  $type  {
	0 {
	    if { [string is integer  $data] } {
		$widget delete 0 end
		$widget insert 0 "$correct"
		after idle "$widget configure -validate all"
	    }
	}
	1 {
	    if { [string is integer  $data] } {
		if { $data < 15 } {
		    return 0
		}
		return 1
	    } else {return 0}
	}
	2 {
	    if { [string is integer $data] } {
		if { $data < 30 } {
		    return 0
		}
		return 1
	    } else {return 0}
	}
	3 {
	    if { [string is integer   $data] } {
		if { $data < 2 } {
		    return 0
		}
		return 1
	    } else {return 0}
	}
	4 {
	    if { [string is integer  $data] } {
		if { $data > 5 } {
		    return 0
		}
		return 1
	    } else {return 0}
	}
    }

}


#proc Browse_Dialog {}
#Browse dialog function (used in TLS directory and convert file), first show the dialog (choose folder or choose file), after check if user choosed something, if yes, set the new variable
proc Browse_Dialog_dir {configitem {initialdir ""}} {

	if { $initialdir == "" } {
		set initialdir [set $configitem]
	}

	if { ![file isdirectory $initialdir]} {
		set initialdir [pwd]
	}

	catch { set parent [focus]}
	if {![info exists parent] || $parent == "" } {
		set parent .
	}
	set browsechoose [tk_chooseDirectory -parent $parent -initialdir $initialdir]
	if { $browsechoose !="" } {
		set $configitem $browsechoose
	}
}

proc Browse_Dialog_file {configitem {initialfile ""}} {

	if { $initialfile == "" } {
		set initialfile [set $configitem]
	}

	if { ![file exists $initialfile] } {
		set initialfile ""
	}

	catch { set parent [focus]}
	if {![info exists parent] || $parent == "" } {
		set parent .
	}
	set browsechoose [tk_getOpenFile -parent $parent -initialfile $initialfile]
	if { $browsechoose !="" } {
		set $configitem $browsechoose
	}
}

#///////////////////////////////////////////////////////////////////////
proc choose_basefont { } {
	if { [winfo exists .basefontsel] } {
		raise .basefontsel
		return
	}


	if { [catch {
			set font [SelectFont .basefontsel -parent .cfg -title [trans choosebasefont] -font [::config::getGlobalKey basefont] -styles [list]]
		}]} {

		set font [SelectFont .basefontsel -parent .cfg -title [trans choosebasefont] -font [list "helvetica" 12 [list]] -styles [list]]

	}

	set family [lindex $font 0]
	set size [lindex $font 1]

	if { $family == "" || $size == ""} {
		return
	}

	set newfont [list $family $size normal]

	if { $newfont != [::config::getGlobalKey basefont]} {
		::config::setGlobalKey basefont $newfont
		focus .cfg
		msg_box [trans mustrestart]
	}

}
#///////////////////////////////////////////////////////////////////////

#///////////////////////////////////////////////////////////////////////
# Since Tk 8.4.14 the Preferences AppleMenu item is hardcoded by TkAqua.
# When the menu item is pressed, it calls ::tk::mac::ShowPreferences.
if {[OnMac] && [version_vcompare [info patchlevel] 8.4.14] >= 0 } {
    proc ::tk::mac::ShowPreferences {} {
        after 0 [list Preferences]
    }
}
#///////////////////////////////////////////////////////////////////////