summaryrefslogtreecommitdiff
path: root/plugins/WebView/src/webview_opts.cpp
blob: 347ccd2bdbbcd0d0886f7be91176a253526ff109 (plain)
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
/*
* A plugin for Miranda IM which displays web page text in a window Copyright 
* (C) 2005 Vincent Joyce.
* 
* Miranda IM: the free icq client for MS Windows  Copyright (C) 2000-2
* Richard Hughes, Roland Rabien & Tristan Van de Vreede
* 
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free 
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
* 
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
* or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
* for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59 
* Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
*/

#include "stdafx.h"
#include "webview.h"

const TCHAR *szTrackerBarDescr[] = {
	LPGENT("No whitespace removal"),
	LPGENT("Minimal level of whitespace removal"),
	LPGENT("Medium level of whitespace removal"),
	LPGENT("Large level of whitespace removal"),
	LPGENT("Remove all whitespace")
};

static char  *fontSizes[] = {"8", "10", "14", "16", "18", "20", "24", "28"};
static TCHAR *AlertTypes[] = { LPGENT("Popup plugin"), LPGENT("Log to file"), LPGENT("Open data display window"), LPGENT("Use OSD plugin") };
static TCHAR *EventTypes[] = { LPGENT("A string is present"), LPGENT("The web page changes"), LPGENT("A specific part of web page changes") };

#define M_FILLSCRIPTCOMBO    (WM_USER+16)

void strdel(TCHAR *parBuffer, int len )
{
	TCHAR* p;
	for (p = parBuffer+len; *p != 0; p++)
		p[ -len ] = *p;

	p[ -len ] = '\0';
}

TCHAR* FixButtonText(TCHAR *url, size_t len)
{
	TCHAR buttontext[256], stringbefore[256], newbuttontext[256];
	_tcsncpy_s(buttontext, url, _TRUNCATE);
	_tcsncpy_s(newbuttontext, url, _TRUNCATE);

	if ( _tcschr(newbuttontext, '&') != 0) {
		while (true) {
			if ( _tcschr(newbuttontext, '&') == 0)
				break;

			_tcsncpy_s(buttontext, newbuttontext, _TRUNCATE);
			TCHAR *stringafter = _tcschr(buttontext, '&');
			int pos = (stringafter - buttontext);
			int posbefore = (stringafter - buttontext) - 1;
			int posafter = (stringafter - buttontext) + 1;
			strdel(stringafter, 1);
			_tcsncpy_s(stringbefore, pos, buttontext, _TRUNCATE);
			mir_sntprintf(newbuttontext, SIZEOF(buttontext), _T("%s!!%s"), stringbefore, stringafter);

			posafter = 0;
			posbefore = 0;
		}

		while (true) {
			if ( _tcschr(newbuttontext, '!') != 0) {
				TCHAR *stringafter = _tcschr(newbuttontext, '!');
				int pos = (stringafter - newbuttontext);
				newbuttontext[pos] = '&';
			}
			if ( _tcschr(newbuttontext, '!') == 0)
				break;
		}
	}

	_tcsncpy_s(url, len, newbuttontext, _TRUNCATE);
	return url;
}

/*****************************************************************************/
static int CALLBACK EnumFontScriptsProc(ENUMLOGFONTEX * lpelfe, NEWTEXTMETRICEX * lpntme, int FontType, LPARAM lParam)
{
	if (SendMessage((HWND) lParam, CB_FINDSTRINGEXACT, -1, (LPARAM) lpelfe->elfScript) == CB_ERR)
	{
		int i = SendMessage((HWND) lParam, CB_ADDSTRING, 0, (LPARAM) lpelfe->elfScript);

		SendMessage((HWND) lParam, CB_SETITEMDATA, i, lpelfe->elfLogFont.lfCharSet);
	}
	return TRUE;
}

/*****************************************************************************/
// copied and modified from NewStatusNotify
INT_PTR CALLBACK DlgPopUpOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{

	char str[512];
	DWORD  BGColour = 0;
	DWORD  TextColour = 0;
	DWORD  delay = 0;
	static int test = 0;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hdlg);
		{
			delay = db_get_dw(NULL, MODULENAME, POP_DELAY_KEY, 0);

			// setting popup delay option
			_itoa(delay, str, 10);
			SetDlgItemTextA(hdlg, IDC_DELAY, str);

			BGColour = db_get_dw(NULL, MODULENAME, POP_BG_CLR_KEY, Def_color_bg);
			TextColour = db_get_dw(NULL, MODULENAME, POP_TXT_CLR_KEY, Def_color_txt);

			// Colours. First step is configuring the colours.
			SendDlgItemMessage(hdlg, IDC_POP_BGCOLOUR, CPM_SETCOLOUR, 0, BGColour);
			SendDlgItemMessage(hdlg, IDC_POP_TEXTCOLOUR, CPM_SETCOLOUR, 0, TextColour);
			// Second step is disabling them if we want to use default Windows
			// ones.
			CheckDlgButton(hdlg, IDC_POP_USEWINCOLORS, db_get_b(NULL, MODULENAME, POP_USEWINCLRS_KEY, 0));
			CheckDlgButton(hdlg, IDC_POP_USESAMECOLORS, db_get_b(NULL, MODULENAME, POP_USESAMECLRS_KEY, 1));
			CheckDlgButton(hdlg, IDC_POP_USECUSTCOLORS, db_get_b(NULL, MODULENAME, POP_USECUSTCLRS_KEY, 0));

			if (IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS) || IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS)) {
				EnableWindow(GetDlgItem(hdlg, IDC_POP_BGCOLOUR), 0);
				EnableWindow(GetDlgItem(hdlg, IDC_POP_TEXTCOLOUR), 0);
			}

			CheckDlgButton(hdlg, IDC_LCLK_WINDOW, db_get_b(NULL, MODULENAME, LCLK_WINDOW_KEY, 0));
			CheckDlgButton(hdlg, IDC_LCLK_WEB_PGE, db_get_b(NULL, MODULENAME, LCLK_WEB_PGE_KEY, 0));
			CheckDlgButton(hdlg, IDC_LCLK_DISMISS, db_get_b(NULL, MODULENAME, LCLK_DISMISS_KEY, 1));

			CheckDlgButton(hdlg, IDC_RCLK_WINDOW, db_get_b(NULL, MODULENAME, RCLK_WINDOW_KEY, 0));
			CheckDlgButton(hdlg, IDC_RCLK_WEB_PGE, db_get_b(NULL, MODULENAME, RCLK_WEB_PGE_KEY, 1));
			CheckDlgButton(hdlg, IDC_RCLK_DISMISS, db_get_b(NULL, MODULENAME, RCLK_DISMISS_KEY, 0));
		}
		return TRUE;

	case WM_COMMAND:
		// enable the "apply" button 
		if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND) lParam)
			SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
		// These are simple clicks: we don't save, but we tell the Options Page 
		// to enable the "Apply" button.
		switch (LOWORD(wParam)) {
		case IDC_POP_BGCOLOUR: // Fall through
		case IDC_POP_TEXTCOLOUR:
			// select new colors
			if (HIWORD(wParam) == CPN_COLOURCHANGED)
				SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_POP_USESAMECOLORS:
			// use same color as data window - enable/disable color selection
			// controls
			EnableWindow(GetDlgItem(hdlg, IDC_POP_BGCOLOUR), !((BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS)));
			EnableWindow(GetDlgItem(hdlg, IDC_POP_TEXTCOLOUR), !((BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS)));
			SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_POP_USEWINCOLORS:
			// use window color - enable/disable color selection controls
			EnableWindow(GetDlgItem(hdlg, IDC_POP_BGCOLOUR), !((BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS)));
			EnableWindow(GetDlgItem(hdlg, IDC_POP_TEXTCOLOUR), !((BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS)));
			SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_POP_USECUSTCOLORS:
			EnableWindow(GetDlgItem(hdlg, IDC_POP_BGCOLOUR), ((BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USECUSTCOLORS)));
			EnableWindow(GetDlgItem(hdlg, IDC_POP_TEXTCOLOUR), ((BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USECUSTCOLORS)));
			break;

		case IDC_PD1:
			SetDlgItemText(hdlg, IDC_DELAY, _T("0"));
			break;
		case IDC_PD2:
			// Popup delay = permanent
			SetDlgItemText(hdlg, IDC_DELAY, _T("-1"));
			break;

		case IDC_DELAY:
			if (HIWORD(wParam) == EN_CHANGE)
				test++;
			if (test > 1)
			{
				//CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD3);
				SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			}
			break;

		case IDC_PREVIEW:
			{
				TCHAR str3[512];
				POPUPDATAT ppd = { 0 };

				GetDlgItemText(hdlg, IDC_DELAY, str3, SIZEOF(str3));

				if (IsDlgButtonChecked(hdlg, IDC_POP_USECUSTCOLORS)) {
					BGColour = (SendDlgItemMessage(hdlg, IDC_POP_BGCOLOUR, CPM_GETCOLOUR, 0, 0));
					TextColour = (SendDlgItemMessage(hdlg, IDC_POP_TEXTCOLOUR, CPM_GETCOLOUR, 0, 0));
				}
				if (IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS)) {
					BGColour = GetSysColor(COLOR_BTNFACE);
					TextColour = GetSysColor(COLOR_WINDOWTEXT);
				}
				if (IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS)) {
					BGColour = BackgoundClr;
					TextColour = TextClr;
				}
				ppd.lchContact = NULL;
				_tcscpy(ppd.lptzContactName, _T(MODULENAME));
				ppd.lchIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SITE));
				_tcscpy(ppd.lptzText, TranslateT("This is a preview popup."));
				ppd.colorBack = BGColour;
				ppd.colorText = TextColour;
				ppd.PluginWindowProc = NULL;
				ppd.iSeconds = _ttol(str3);
				// display popups
				PUAddPopupT(&ppd);
			}
		}
		break;

	case WM_NOTIFY: // Here we have pressed either the OK or the APPLY button.
		switch (((LPNMHDR) lParam)->code) {
		case PSN_APPLY:
			{
				int popupdelayval = 0;
				TCHAR str2[512];
				GetDlgItemText(hdlg, IDC_DELAY, str2, SIZEOF(str2));

				popupdelayval = _ttol(str2);
				db_set_dw(NULL, MODULENAME, POP_DELAY_KEY, popupdelayval);

				db_set_b(NULL, MODULENAME, LCLK_WINDOW_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_LCLK_WINDOW));
				db_set_b(NULL, MODULENAME, LCLK_WEB_PGE_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_LCLK_WEB_PGE));
				db_set_b(NULL, MODULENAME, LCLK_DISMISS_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_LCLK_DISMISS));

				db_set_b(NULL, MODULENAME, RCLK_WINDOW_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_RCLK_WINDOW));
				db_set_b(NULL, MODULENAME, RCLK_WEB_PGE_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_RCLK_WEB_PGE));
				db_set_b(NULL, MODULENAME, RCLK_DISMISS_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_RCLK_DISMISS));

				db_set_b(NULL, MODULENAME, POP_USECUSTCLRS_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USECUSTCOLORS));
				db_set_b(NULL, MODULENAME, POP_USEWINCLRS_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USEWINCOLORS));
				db_set_b(NULL, MODULENAME, POP_USESAMECLRS_KEY, (BYTE)IsDlgButtonChecked(hdlg, IDC_POP_USESAMECOLORS));

				BGColour = (SendDlgItemMessage(hdlg, IDC_POP_BGCOLOUR, CPM_GETCOLOUR, 0, 0));
				TextColour = (SendDlgItemMessage(hdlg, IDC_POP_TEXTCOLOUR, CPM_GETCOLOUR, 0, 0));

				db_set_dw(NULL, MODULENAME, POP_BG_CLR_KEY, BGColour);
				db_set_dw(NULL, MODULENAME, POP_TXT_CLR_KEY, TextColour);

				test = 0;
				return TRUE;
			}
		}
		break;
	}
	return FALSE;
}

/*****************************************************************************/
INT_PTR CALLBACK DlgProcAlertOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND ParentHwnd;
	DBVARIANT dbv;
	int i;
	int alertIndex = 0;
	int eventIndex = 0;
	static int test;
	MCONTACT hContact;

	ParentHwnd = GetParent(hwndDlg);

	switch (msg) {
	case WM_INITDIALOG:
		test = 0;
		TranslateDialogDefault(hwndDlg);
		hContact = lParam;

		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) hContact);

		SetWindowText(hwndDlg, TranslateT("Alert options"));

		SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(hInst, MAKEINTRESOURCE(IDI_ALERT)));

		EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 0);

		if (!db_get_ts(hContact, MODULENAME, ALERT_STRING_KEY, &dbv)) {
			SetDlgItemText(hwndDlg, IDC_ALERT_STRING, dbv.ptszVal);
			db_free(&dbv);
		}
		if (!db_get_ts(hContact, MODULENAME, ALRT_S_STRING_KEY, &dbv)) {
			SetDlgItemText(hwndDlg, IDC_START2, dbv.ptszVal);
			db_free(&dbv);
		}
		if (!db_get_ts(hContact, MODULENAME, ALRT_E_STRING_KEY, &dbv)) {
			SetDlgItemText(hwndDlg, IDC_END2, dbv.ptszVal);
			db_free(&dbv);
		}
		CheckDlgButton(hwndDlg, IDC_ENABLE_ALERTS, db_get_b(hContact, MODULENAME, ENABLE_ALERTS_KEY, 0));
		CheckDlgButton(hwndDlg, IDC_ADD_DATE_NAME, db_get_b(hContact, MODULENAME, APND_DATE_NAME_KEY, 0));
		CheckDlgButton(hwndDlg, IDC_24_HOUR, db_get_b(hContact, MODULENAME, USE_24_HOUR_KEY, 0));
		CheckDlgButton(hwndDlg, IDC_ALWAYS_LOG, db_get_b(hContact, MODULENAME, ALWAYS_LOG_KEY, 0));

		SetDlgItemText(hwndDlg, IDC_ALERT_TYPE, TranslateTS(AlertTypes[db_get_b(hContact, MODULENAME, ALRT_INDEX_KEY, 0)]));
		SetDlgItemText(hwndDlg, IDC_EVENT_TYPE, TranslateTS(EventTypes[db_get_b(hContact, MODULENAME, EVNT_INDEX_KEY, 0)]));

		for (i = 0; i < SIZEOF(AlertTypes); i++)
			SendDlgItemMessage(hwndDlg, IDC_ALERT_TYPE, CB_ADDSTRING, 0, (LPARAM)TranslateTS(AlertTypes[i]));

		for (i = 0; i < SIZEOF(EventTypes); i++)
			SendDlgItemMessage(hwndDlg, IDC_EVENT_TYPE, CB_ADDSTRING, 0, (LPARAM)TranslateTS(EventTypes[i]));

		if (db_get_b(hContact, MODULENAME, ENABLE_ALERTS_KEY, 0)) {
			CheckDlgButton(hwndDlg, IDC_ENABLE_ALERTS, BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_ADD_DATE_NAME, BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_24_HOUR, BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_PREFIX, BST_UNCHECKED);
		}
		EnableWindow(GetDlgItem(hwndDlg, IDC_EVENT_TYPE), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_DATE_NAME), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));

		if (IsDlgButtonChecked(hwndDlg, IDC_ADD_DATE_NAME)) {
			EnableWindow(GetDlgItem(hwndDlg, IDC_PREFIX), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_SUFFIX), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_24_HOUR), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		}
		else {
			EnableWindow(GetDlgItem(hwndDlg, IDC_PREFIX), 0);
			EnableWindow(GetDlgItem(hwndDlg, IDC_SUFFIX), 0);
			EnableWindow(GetDlgItem(hwndDlg, IDC_24_HOUR), 0);
		}

		EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_TYPE), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_START2), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_END2), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_ALWAYS_LOG), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));

		if (!db_get_s(hContact, MODULENAME, EVNT_INDEX_KEY, &dbv)) {
			eventIndex = db_get_b(hContact, MODULENAME, EVNT_INDEX_KEY, 0);
			db_free(&dbv);
		}
		if (!db_get_s(hContact, MODULENAME, ALRT_INDEX_KEY, &dbv)) {
			alertIndex = db_get_b(hContact, MODULENAME, ALRT_INDEX_KEY, 0);
			db_free(&dbv);
		}

		// alerts
		if (alertIndex == 0) // Popup
		{
			if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);
			}
		}
		else if (alertIndex == 1) // file
		{
			if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 1);
			}
		}
		else if (alertIndex == 2) // datawindow
		{
			if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);
			}
		}
		else if (alertIndex == 3) // osd
		{
			if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);
			}
		}

		// events
		if (eventIndex == 0) // string is present
		{
			if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_START2), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_END2), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 1);
			}
		}
		else if (eventIndex == 1) // webpage changed
		{
			if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_START2), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_END2), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
			}
		}
		else if (eventIndex == 2) // part of page changed
		{
			if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_START2), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_END2), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
			}
		}

		if (!db_get_ts(hContact, MODULENAME, FILE_KEY, &dbv)) {
			SetDlgItemText(hwndDlg, IDC_FILENAME, dbv.ptszVal);
			db_free(&dbv);
		}

		CheckDlgButton(hwndDlg, IDC_APPEND, db_get_b(hContact, MODULENAME, APPEND_KEY, 0));
		CheckDlgButton(hwndDlg, IDC_SAVE_AS_RAW, db_get_b(hContact, MODULENAME, SAVE_AS_RAW_KEY, 0));

		if (db_get_b(hContact, MODULENAME, CONTACT_PREFIX_KEY, 1) == 1)
			CheckRadioButton(hwndDlg, IDC_PREFIX, IDC_SUFFIX, IDC_PREFIX);
		else
			CheckRadioButton(hwndDlg, IDC_PREFIX, IDC_SUFFIX, IDC_SUFFIX);

		if ( db_get_b(hContact, MODULENAME, ALWAYS_LOG_KEY, 0)) {
			if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 1);
			}
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_BROWSE:
			{
				TCHAR szFileName[MAX_PATH];
				GetDlgItemText(hwndDlg, IDC_FILENAME, szFileName, SIZEOF(szFileName));

				OPENFILENAME ofn = { 0 };
				ofn.lStructSize = sizeof(ofn);
				ofn.hwndOwner = hwndDlg;
				ofn.hInstance = NULL;
				ofn.lpstrFilter = _T("TEXT Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0");
				ofn.lpstrFile = szFileName;
				ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
				ofn.nMaxFile = SIZEOF(szFileName);
				ofn.nMaxFileTitle = MAX_PATH;
				ofn.lpstrDefExt = _T("txt");
				if (!GetSaveFileName(&ofn))
					break;

				SetDlgItemText(hwndDlg, IDC_FILENAME, szFileName);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			}
			break;

		case IDC_ADD_DATE_NAME:
			EnableWindow(GetDlgItem(hwndDlg, IDC_PREFIX), (IsDlgButtonChecked(hwndDlg, IDC_ADD_DATE_NAME)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_SUFFIX), (IsDlgButtonChecked(hwndDlg, IDC_ADD_DATE_NAME)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_24_HOUR), (IsDlgButtonChecked(hwndDlg, IDC_ADD_DATE_NAME)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			break;

		case IDC_24_HOUR:
		case IDC_SUFFIX:
		case IDC_PREFIX:
			EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			break;

		case IDC_ALERT_STRING:
			if (HIWORD(wParam) == EN_CHANGE)
				test++;
			if (test > 1)
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			break;

		case IDC_START2:
		case IDC_END2:
			if (HIWORD(wParam) == EN_CHANGE)
				test++;
			if (test > 3)
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			break;

		case IDC_APPEND:
			EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			break;

		case IDC_SAVE_AS_RAW:
			EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			break;

		case IDC_ENABLE_ALERTS:
			hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			EnableWindow(GetDlgItem(hwndDlg, IDC_ADD_DATE_NAME), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));

			if ( IsDlgButtonChecked(hwndDlg, IDC_ADD_DATE_NAME)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_PREFIX), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
				EnableWindow(GetDlgItem(hwndDlg, IDC_SUFFIX), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
				EnableWindow(GetDlgItem(hwndDlg, IDC_24_HOUR), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
			}
			else {
				EnableWindow(GetDlgItem(hwndDlg, IDC_PREFIX), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SUFFIX), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_24_HOUR), 0);
			}

			EnableWindow(GetDlgItem(hwndDlg, IDC_EVENT_TYPE), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_TYPE), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_ALWAYS_LOG), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));

			eventIndex = db_get_b(hContact, MODULENAME, EVNT_INDEX_KEY, 0);
			alertIndex = db_get_b(hContact, MODULENAME, ALRT_INDEX_KEY, 0);

			if (eventIndex == 2) { // part of webpage changed
				EnableWindow(GetDlgItem(hwndDlg, IDC_START2), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
				EnableWindow(GetDlgItem(hwndDlg, IDC_END2), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
			}
			else {
				EnableWindow(GetDlgItem(hwndDlg, IDC_START2), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_END2), 0);
			}

			// //////// 
			if (alertIndex == 0) { // popup
				if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
					EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);

					if (eventIndex == 2) // part of webpage changed
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
					if (eventIndex == 1) // webpage changed
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
					if (eventIndex == 0) // string present
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
				}
			}
			else if (alertIndex == 1) { // log to file
				if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
					EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 1);
					EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 1);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 1);
					EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 1);

					if (eventIndex == 1) // webpage changed
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
					if (eventIndex == 0) // string present
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
				}
				else {
					EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);
				}
			}
			else if (alertIndex == 2) { // display window
				if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
					EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);

					if (eventIndex == 1) // webpage changed
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
					if (eventIndex == 0) // string present
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
				}
			}
			else if (alertIndex == 3) { // osd
				if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
					EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);

					if (eventIndex == 1) // webpage changed
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
					if (eventIndex == 0) // string present
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));
				}
			}

			if (eventIndex == 0) // string present
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)));

			EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);

			if (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)) {
				if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
					EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 1);
					EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 1);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 1);
					EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 1);
				}
				else {
					EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
					EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);
				}
			}
			break;

		case IDC_ALWAYS_LOG:
			EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)));
			break;

		case IDC_ALERT_TYPE:
			if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE) {
				hContact = (MCONTACT) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
				int alertIndex = SendDlgItemMessage(hwndDlg, IDC_ALERT_TYPE, CB_GETCURSEL, 0, 0);

				if (HIWORD(wParam) == CBN_SELCHANGE) {
					db_set_b(hContact, MODULENAME, ALRT_INDEX_KEY, alertIndex);
					if (alertIndex == 0) {
						// PopUp
						EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);
					}
					else if (alertIndex == 1) {
						// log to file
						EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 1);
						EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 1);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 1);
						EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 1);
					}
					else if (alertIndex == 2) {
						// data window
						EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);
					}
					else if (alertIndex == 3) {
						// OSD
						EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), 0);
					}

					if (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)) {
						EnableWindow(GetDlgItem(hwndDlg, IDC_APPEND), (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)));
						EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)));
						EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)));
						EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE_AS_RAW), (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG)));
					}
				}
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			}
			break;

		case IDC_EVENT_TYPE:
			if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE) {
				MCONTACT hContact = (MCONTACT) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
				int eventIndex = SendDlgItemMessage(hwndDlg, IDC_EVENT_TYPE, CB_GETCURSEL, 0, 0);

				if (HIWORD(wParam) == CBN_SELCHANGE) {
					db_set_b(hContact, MODULENAME, EVNT_INDEX_KEY, eventIndex);
					if (eventIndex == 0) {
						// event when string is present
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 1);
						EnableWindow(GetDlgItem(hwndDlg, IDC_START2), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_END2), 0);
					}
					else if (eventIndex == 1) {
						// event when web page changes
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_START2), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_END2), 0);
					}
					else if (eventIndex == 2) {
						// event when part of web page changes
						EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_STRING), 0);
						EnableWindow(GetDlgItem(hwndDlg, IDC_START2), 1);
						EnableWindow(GetDlgItem(hwndDlg, IDC_END2), 1);
					}
				}
				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 1);
			}
			break;

		case IDC_ALERT_APPLY:
		case IDC_OK2:
			{
				hContact = (MCONTACT) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
				TCHAR buf[MAX_PATH];

				eventIndex = db_get_b(hContact, MODULENAME, EVNT_INDEX_KEY, 0);
				alertIndex = db_get_b(hContact, MODULENAME, ALRT_INDEX_KEY, 0);

				db_set_b(hContact, MODULENAME, ENABLE_ALERTS_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS));
				db_set_b(hContact, MODULENAME, APND_DATE_NAME_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ADD_DATE_NAME));
				db_set_b(hContact, MODULENAME, USE_24_HOUR_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_24_HOUR));
				db_set_b(hContact, MODULENAME, ALWAYS_LOG_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG));

				//if alerts is unticked delete the cache
				if (!(IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)))
					SiteDeleted(hContact, 0);

				if (eventIndex == 0) // string present
					if (!(GetWindowTextLength(GetDlgItem(hwndDlg, IDC_ALERT_STRING))))
						if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
							MessageBox(NULL, TranslateT("You need to supply a search string."), _T(MODULENAME), MB_OK);
							break;
						}

				if (eventIndex == 2) // part of web page changed
					if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
						if (!(GetWindowTextLength(GetDlgItem(hwndDlg, IDC_START2)))) {
							MessageBox(NULL, TranslateT("You need to supply a start string."), _T(MODULENAME), MB_OK);
							break;
						}
						if (!(GetWindowTextLength(GetDlgItem(hwndDlg, IDC_END2)))) {
							MessageBox(NULL, TranslateT("You need to supply an end string."), _T(MODULENAME), MB_OK);
							break;
						}
					}

				if (alertIndex == 1) // log to file
					if (!(GetWindowTextLength(GetDlgItem(hwndDlg, IDC_FILENAME))))
						if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
							MessageBox(NULL, TranslateT("You need to supply a file name and path."), _T(MODULENAME), MB_OK);
							break;
						}

				if (IsDlgButtonChecked(hwndDlg, IDC_ALWAYS_LOG))
					if (!(GetWindowTextLength(GetDlgItem(hwndDlg, IDC_FILENAME))))
						if (IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ALERTS)) {
							MessageBox(NULL, TranslateT("You need to supply a file name and path."), _T(MODULENAME), MB_OK);
							break;
						}

				GetDlgItemText(hwndDlg, IDC_FILENAME, buf, SIZEOF(buf));
				db_set_ts(hContact, MODULENAME, FILE_KEY, buf);

				db_set_b(hContact, MODULENAME, APPEND_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_APPEND));
				db_set_b(hContact, MODULENAME, SAVE_AS_RAW_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SAVE_AS_RAW));

				GetDlgItemText(hwndDlg, IDC_ALERT_STRING, buf, SIZEOF(buf));
				db_set_ts(hContact, MODULENAME, ALERT_STRING_KEY, buf);

				GetDlgItemText(hwndDlg, IDC_START2, buf, SIZEOF(buf));
				db_set_ts(hContact, MODULENAME, ALRT_S_STRING_KEY, buf);

				GetDlgItemText(hwndDlg, IDC_END2, buf, SIZEOF(buf));
				db_set_ts(hContact, MODULENAME, ALRT_E_STRING_KEY, buf);

				db_set_b(hContact, MODULENAME, CONTACT_PREFIX_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_PREFIX));

				EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_APPLY), 0);

				if (LOWORD(wParam) == IDC_OK2) {
					EnableWindow(GetDlgItem(ParentHwnd, IDC_ALERT_BUTTON), 1);
					EnableWindow(GetDlgItem(ParentHwnd, IDC_OPTIONS_BUTTON), 1);
					WindowList_Remove(hWindowList, hwndDlg);
					DestroyWindow(hwndDlg);
				}
			}
		}
		break;

	case IDC_ALERT_CANCEL:
		EnableWindow(GetDlgItem(ParentHwnd, IDC_ALERT_BUTTON), 1);
		EnableWindow(GetDlgItem(ParentHwnd, IDC_OPTIONS_BUTTON), 1);
		WindowList_Remove(hWindowList, hwndDlg);
		if (hwndDlg) {
			DestroyWindow(hwndDlg);
			hwndDlg = NULL;
		}
		break;

	case WM_DESTROY:
	case IDC_CANCEL:
		EnableWindow(GetDlgItem(ParentHwnd, IDC_ALERT_BUTTON), 1);
		EnableWindow(GetDlgItem(ParentHwnd, IDC_OPTIONS_BUTTON), 1);
		WindowList_Remove(hWindowList, hwndDlg);
		DestroyWindow(hwndDlg);
	}
	return FALSE;
}

/*****************************************************************************/

INT_PTR CALLBACK DlgProcContactOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DBVARIANT dbv;
	TCHAR url[300];
	HWND ParentHwnd = GetParent(hwndDlg);
	static int test;
	static int test2;
	MCONTACT hContact;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		hContact = (MCONTACT) lParam;

		test = 0;
		test2 = 0;

		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) hContact);
		WindowList_Add(hWindowList, hwndDlg, hContact);

		SetWindowText(hwndDlg, TranslateT("Contact options"));

		SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(hInst, MAKEINTRESOURCE(IDI_OPTIONS)));

		EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 0);

		if (!db_get_ts(hContact, MODULENAME, URL_KEY, &dbv)) {
			SetDlgItemText(hwndDlg, IDC_URL, dbv.ptszVal);
			db_free(&dbv);
		}
		if (!db_get_ts(hContact, MODULENAME, START_STRING_KEY, &dbv)) {
			SetDlgItemText(hwndDlg, IDC_START, dbv.ptszVal);
			db_free(&dbv);
		}
		if (!db_get_ts(hContact, MODULENAME, END_STRING_KEY, &dbv)) {
			SetDlgItemText(hwndDlg, IDC_END, dbv.ptszVal);
			db_free(&dbv);
		}
		if (db_get_ts(hContact, MODULENAME, PRESERVE_NAME_KEY, &dbv)) {
			db_free(&dbv);
			db_get_ts(hContact, "CList", "MyHandle", &dbv);
			db_set_ts(hContact, MODULENAME, PRESERVE_NAME_KEY, dbv.ptszVal);
			db_free(&dbv);
		}
		if (!db_get_ts(hContact, MODULENAME, PRESERVE_NAME_KEY, &dbv)) {
			SetDlgItemText(hwndDlg, IDC_SITE_NAME, dbv.ptszVal);
			db_free(&dbv);
		}

		CheckDlgButton(hwndDlg, IDC_CLEAN, db_get_b(hContact, MODULENAME, CLEAR_DISPLAY_KEY, 0));

		SendDlgItemMessage(hwndDlg, IDC_RWSPACE, TBM_SETRANGE, FALSE, MAKELONG(0, 4));
		SendDlgItemMessage(hwndDlg, IDC_RWSPACE, TBM_SETPOS, TRUE, db_get_b(hContact, MODULENAME, RWSPACE_KEY, 0));
		SetDlgItemText(hwndDlg, IDC_RWSPC_TEXT, TranslateTS(szTrackerBarDescr[SendDlgItemMessage(hwndDlg, IDC_RWSPACE, TBM_GETPOS, 0, 0)]));

		EnableWindow(GetDlgItem(hwndDlg, IDC_RWSPACE), (IsDlgButtonChecked(hwndDlg, IDC_CLEAN)));
		EnableWindow(GetDlgItem(hwndDlg, IDC_RWSPC_TEXT), (IsDlgButtonChecked(hwndDlg, IDC_CLEAN)));

		if (db_get_b(hContact, MODULENAME, DBLE_WIN_KEY, 1) == 1)
			CheckRadioButton(hwndDlg, IDC_DBLE_WEB, IDC_DBLE_WIN, IDC_DBLE_WIN);
		else
			CheckRadioButton(hwndDlg, IDC_DBLE_WEB, IDC_DBLE_WIN, IDC_DBLE_WEB);

		if (db_get_b(hContact, MODULENAME, U_ALLSITE_KEY, 0) == 1) {
			CheckRadioButton(hwndDlg, IDC_U_SE_STRINGS, IDC_U_ALLSITE, IDC_U_ALLSITE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_START), 0);
			EnableWindow(GetDlgItem(hwndDlg, IDC_END), 0);
			EnableWindow(GetDlgItem(hwndDlg, IDC_CPY_STRINGS), 0);
		}
		else {
			CheckRadioButton(hwndDlg, IDC_U_SE_STRINGS, IDC_U_ALLSITE, IDC_U_SE_STRINGS);
			EnableWindow(GetDlgItem(hwndDlg, IDC_START), 1);
			EnableWindow(GetDlgItem(hwndDlg, IDC_END), 1);
			EnableWindow(GetDlgItem(hwndDlg, IDC_CPY_STRINGS), 1);
			//EnableWindow(GetDlgItem(hwndDlg, IDC_CPY_STR_TXT), 1);
		}
		break;

	case WM_HSCROLL:
		SetDlgItemText(hwndDlg, IDC_RWSPC_TEXT, TranslateTS(szTrackerBarDescr[SendDlgItemMessage(hwndDlg, IDC_RWSPACE, TBM_GETPOS, 0, 0)]));
		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 1);
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case WM_CLOSE:
		case IDCANCEL:
			if (hwndDlg) {
				DestroyWindow(hwndDlg);
				hwndDlg = NULL;
			}
			return TRUE;

		case IDC_SITE_NAME:
		case IDC_URL:
			if (HIWORD(wParam) == EN_CHANGE)
				test++;
			if (test > 2)
				EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 1);
			break;

		case IDC_DBLE_WEB:
		case IDC_DBLE_WIN:
			EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 1);
			break;

		case IDC_START:
		case IDC_END:
			if (HIWORD(wParam) == EN_CHANGE)
				test2++;
			if (test2 > 2)
				EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 1);
			break;

		case IDC_CPY_STRINGS:
			{
				TCHAR string[128];
				hContact = (MCONTACT) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

				GetDlgItemText(hwndDlg, IDC_START, string, SIZEOF(string));
				db_set_ts(hContact, MODULENAME, ALRT_S_STRING_KEY, string);

				GetDlgItemText(hwndDlg, IDC_END, string, SIZEOF(string));
				db_set_ts(hContact, MODULENAME, ALRT_E_STRING_KEY, string);

				db_set_w(hContact, MODULENAME, EVNT_INDEX_KEY, 2);
			}
			break;

		case IDC_CLEAN:
			EnableWindow(GetDlgItem(hwndDlg, IDC_RWSPACE), (IsDlgButtonChecked(hwndDlg, IDC_CLEAN)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_RWSPC_TEXT), (IsDlgButtonChecked(hwndDlg, IDC_CLEAN)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 1);
			break;

		case IDC_U_SE_STRINGS:
			EnableWindow(GetDlgItem(hwndDlg, IDC_START), (IsDlgButtonChecked(hwndDlg, IDC_U_SE_STRINGS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_END), (IsDlgButtonChecked(hwndDlg, IDC_U_SE_STRINGS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_CPY_STRINGS), (IsDlgButtonChecked(hwndDlg, IDC_U_SE_STRINGS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 1);
			break;

		case IDC_U_ALLSITE:
			EnableWindow(GetDlgItem(hwndDlg, IDC_START), (IsDlgButtonChecked(hwndDlg, IDC_U_SE_STRINGS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_END), (IsDlgButtonChecked(hwndDlg, IDC_U_SE_STRINGS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_CPY_STRINGS), (IsDlgButtonChecked(hwndDlg, IDC_U_SE_STRINGS)));
			EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 1);
			break;

		case IDC_OPT_APPLY:
		case IDOK:
			{
				TCHAR str[128], contactname[128];
				if (!GetWindowTextLength(GetDlgItem(hwndDlg, IDC_URL))) {
					MessageBox(NULL, TranslateT("You need to supply a URL."), _T(MODULENAME), MB_OK);
					break;
				}
				if (!GetWindowTextLength(GetDlgItem(hwndDlg, IDC_START))) {
					if (IsDlgButtonChecked(hwndDlg, IDC_U_SE_STRINGS)) {
						MessageBox(NULL, TranslateT("You need to supply a start string."), _T(MODULENAME), MB_OK);
						break;
					}
				}
				if (!GetWindowTextLength(GetDlgItem(hwndDlg, IDC_END))) {
					if (IsDlgButtonChecked(hwndDlg, IDC_U_SE_STRINGS)) {
						MessageBox(NULL, TranslateT("You need to supply an end string."), _T(MODULENAME), MB_OK);
						break;
					}
				}
				if (!GetWindowTextLength(GetDlgItem(hwndDlg, IDC_SITE_NAME))) {
					MessageBox(NULL, TranslateT("You need to supply a name for the contact."), _T(MODULENAME), MB_OK);
					break;
				}

				GetDlgItemText(hwndDlg, IDC_SITE_NAME, contactname, SIZEOF(contactname));
				if (_tcschr(contactname, '\\') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}
				if (_tcschr(contactname, '/') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}
				if (_tcschr(contactname, ':') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}
				if (_tcschr(contactname, '*') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}
				if (_tcschr(contactname, '?') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}
				if (_tcschr(contactname, '\"') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}
				if (_tcschr(contactname, '<') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}
				if (_tcschr(contactname, '>') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}
				if (_tcschr(contactname, '|') != NULL) {
					MessageBox(NULL, TranslateT("Invalid symbol present in contact name."), _T(MODULENAME), MB_OK);
					break;
				}

				hContact = (MCONTACT) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

				GetDlgItemText(hwndDlg, IDC_URL, url, SIZEOF(url));
				db_set_ts(hContact, MODULENAME, URL_KEY, url);
				db_set_ts(hContact, MODULENAME, "Homepage", url);

				GetDlgItemText(hwndDlg, IDC_START, str, SIZEOF(str));
				db_set_ts(hContact, MODULENAME, START_STRING_KEY, str);

				GetDlgItemText(hwndDlg, IDC_END, str, SIZEOF(str));
				db_set_ts(hContact, MODULENAME, END_STRING_KEY, str);

				GetDlgItemText(hwndDlg, IDC_SITE_NAME, str, SIZEOF(str));
				db_set_ts(hContact, "CList", "MyHandle", str);

				db_set_b(hContact, MODULENAME, DBLE_WIN_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_DBLE_WIN));
				db_set_b(hContact, MODULENAME, U_ALLSITE_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_U_ALLSITE));

				db_set_b(hContact, MODULENAME, CLEAR_DISPLAY_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_CLEAN));
				db_set_b(hContact, MODULENAME, RWSPACE_KEY, (BYTE)(SendDlgItemMessage(hwndDlg, IDC_RWSPACE, TBM_GETPOS, 0, 0)));

				SetDlgItemText(ParentHwnd, IDC_OPEN_URL, FixButtonText(url, SIZEOF(url)));

				SetWindowText(ParentHwnd, str);
				EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_APPLY), 0);

				if (LOWORD(wParam) == IDOK) {
					EnableWindow(GetDlgItem(ParentHwnd, IDC_OPTIONS_BUTTON), 1);
					EnableWindow(GetDlgItem(ParentHwnd, IDC_ALERT_BUTTON), 1);
					if (hwndDlg) {
						DestroyWindow(hwndDlg);
						hwndDlg = NULL;
					}
				}
			}
			break;

		case IDC_OPT_CANCEL:
			EnableWindow(GetDlgItem(ParentHwnd, IDC_OPTIONS_BUTTON), 1);
			EnableWindow(GetDlgItem(ParentHwnd, IDC_ALERT_BUTTON), 1);
			WindowList_Remove(hWindowList, hwndDlg);
			if (hwndDlg) {
				DestroyWindow(hwndDlg);
				hwndDlg = NULL;
			}
		}
		break;

	case WM_DESTROY:
		EnableWindow(GetDlgItem(ParentHwnd, IDC_OPTIONS_BUTTON), 1);
		EnableWindow(GetDlgItem(ParentHwnd, IDC_ALERT_BUTTON), 1);
		WindowList_Remove(hWindowList, hwndDlg);
		DestroyWindow(hwndDlg);
	}
	return FALSE;
}

/*****************************************************************************/
INT_PTR CALLBACK DlgProcOpt(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	DWORD  timerval, delaytime, oldcolor;
	DBVARIANT       dbv;
	static int test = 0;
	static int test2 = 0;

	switch (uMsg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			test = 0;

			SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(999, 0));
			SendDlgItemMessage(hwndDlg, IDC_SPIN2, UDM_SETRANGE, 0, MAKELONG(120, 0));

			SetDlgItemInt(hwndDlg, IDC_TIME, db_get_dw(NULL, MODULENAME, REFRESH_KEY, TIME), FALSE);
			SetDlgItemInt(hwndDlg, IDC_START_DELAY, db_get_w(NULL, MODULENAME, START_DELAY_KEY, 0), FALSE);

			mir_forkthread(FillFontListThread, hwndDlg);

			CheckDlgButton(hwndDlg, IDC_DISABLEMENU, db_get_b(NULL, MODULENAME, MENU_OFF, 0));
			CheckDlgButton(hwndDlg, IDC_SUPPRESS, db_get_b(NULL, MODULENAME, SUPPRESS_ERR_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_UPDATE_ONSTART, db_get_b(NULL, MODULENAME, UPDATE_ONSTART_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_UPDATE_ON_OPEN, db_get_b(NULL, MODULENAME, UPDATE_ON_OPEN_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_HIDE_STATUS_ICON, db_get_b(NULL, MODULENAME, HIDE_STATUS_ICON_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_FONT_BOLD, db_get_b(NULL, MODULENAME, FONT_BOLD_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_FONT_ITALIC, db_get_b(NULL, MODULENAME, FONT_ITALIC_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_FONT_UNDERLINE, db_get_b(NULL, MODULENAME, FONT_UNDERLINE_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_ERROR_POPUP, db_get_b(NULL, MODULENAME, ERROR_POPUP_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_UPDATE_ONALERT, db_get_b(NULL, MODULENAME, UPDATE_ONALERT_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_SAVE_INDIVID_POS, db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_NO_PROTECT, db_get_b(NULL, MODULENAME, NO_PROTECT_KEY, 0));
			CheckDlgButton(hwndDlg, IDC_DATAPOPUP, db_get_b(NULL, MODULENAME, DATA_POPUP_KEY, 0));

			if (!db_get_ts(NULL, MODULENAME, FONT_FACE_KEY, &dbv)) {
				SetDlgItemText(hwndDlg, IDC_TYPEFACE, dbv.ptszVal);
				db_free(&dbv);
			}
			else SetDlgItemText(hwndDlg, IDC_TYPEFACE, Def_font_face);

			for (int i = 0; i < SIZEOF(fontSizes); i++)
				SendDlgItemMessage(hwndDlg, IDC_FONTSIZE, CB_ADDSTRING, 0, (LPARAM)fontSizes[i]);

			SendMessage(hwndDlg, M_FILLSCRIPTCOMBO, wParam, 0);

			SetDlgItemInt(hwndDlg, IDC_FONTSIZE, db_get_b(NULL, MODULENAME, FONT_SIZE_KEY, 14), FALSE);

			EnableWindow(GetDlgItem(hwndDlg, IDC_FIND_BUTTON), 0);
			EnableWindow(GetDlgItem(hwndDlg, IDC_ALERT_BUTTON), 0);

			SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_SETCOLOUR, 0, (BackgoundClr));
			SendDlgItemMessage(hwndDlg, IDC_TXTCOLOR, CPM_SETCOLOUR, 0, (TextClr));

			/*
			* record bg value for later comparison
			*/
			oldcolor = BackgoundClr;

			if ( db_get_b(NULL, MODULENAME, SUPPRESS_ERR_KEY, 0)) {
				CheckDlgButton(hwndDlg, IDC_SUPPRESS, BST_CHECKED);
				EnableWindow(GetDlgItem(hwndDlg, IDC_ERROR_POPUP), 0);
			}
			else {
				CheckDlgButton(hwndDlg, IDC_SUPPRESS, BST_UNCHECKED);
				if ((ServiceExists(MS_POPUP_ADDPOPUPT) != 0))
					EnableWindow(GetDlgItem(hwndDlg, IDC_ERROR_POPUP), 1);
			}

			if (ServiceExists(MS_POPUP_ADDPOPUPT) == 0)
				EnableWindow(GetDlgItem(hwndDlg, IDC_ERROR_POPUP), 0);

			if ( db_get_b(NULL, MODULENAME, UPDATE_ONSTART_KEY, 0)) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_START_DELAY), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SPIN2), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_STARTDELAYTXT), 1);
				EnableWindow(GetDlgItem(hwndDlg, IDC_STDELAYSECTXT), 1);
			}
			else {
				EnableWindow(GetDlgItem(hwndDlg, IDC_START_DELAY), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_SPIN2), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_STARTDELAYTXT), 0);
				EnableWindow(GetDlgItem(hwndDlg, IDC_STDELAYSECTXT), 0);
			}
		}
		break;

	case M_FILLSCRIPTCOMBO: // fill the script combo box and set the
		// selection to the value for fontid wParam

		{
			LOGFONT         lf = {0};
			int i;
			HDC hdc = GetDC(hwndDlg);

			lf.lfCharSet = DEFAULT_CHARSET;
			GetDlgItemText(hwndDlg, IDC_TYPEFACE, lf.lfFaceName, SIZEOF(lf.lfFaceName));
			lf.lfPitchAndFamily = 0;
			SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_RESETCONTENT, 0, 0);
			EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC) EnumFontScriptsProc, (LPARAM) GetDlgItem(hwndDlg, IDC_SCRIPT), 0);
			ReleaseDC(hwndDlg, hdc);
			for (i = SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_GETCOUNT, 0, 0) - 1; i >= 0; i--)
			{
				if (SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_GETITEMDATA, i, 0) == (BYTE)((db_get_b(NULL, MODULENAME, FONT_SCRIPT_KEY, 0))))
				{
					SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_SETCURSEL, i, 0);
					break;
				}
			}
			if (i < 0)
				SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_SETCURSEL, 0, 0);
		}
		break;

	case WM_COMMAND:
		if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND) lParam)
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);

		switch (LOWORD(wParam)) {
		case IDC_TXTCOLOR:
			TextClr = SendDlgItemMessage(hwndDlg, IDC_TXTCOLOR, CPM_GETCOLOUR, 0, 0);
			db_set_dw(NULL, MODULENAME, TXT_COLOR_KEY, TextClr);
			if (HIWORD(wParam) == CPN_COLOURCHANGED) {
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				TxtclrLoop();
			}
			break;

		case IDC_BGCOLOR:
			BackgoundClr = SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0);
			db_set_dw(NULL, MODULENAME, BG_COLOR_KEY, BackgoundClr);
			if (HIWORD(wParam) == CPN_COLOURCHANGED) {
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				BGclrLoop();
			}
			break;

		case IDC_HIDE_STATUS_ICON:
			ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW);
			break;

		case IDC_SUPPRESS:
			if ((ServiceExists(MS_POPUP_ADDPOPUPT) != 0))
				EnableWindow(GetDlgItem(hwndDlg, IDC_ERROR_POPUP), (!(IsDlgButtonChecked(hwndDlg, IDC_SUPPRESS))));
			break;

		case IDC_UPDATE_ONSTART:
			EnableWindow(GetDlgItem(hwndDlg, IDC_START_DELAY), ((IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART))));
			EnableWindow(GetDlgItem(hwndDlg, IDC_SPIN2), ((IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART))));
			EnableWindow(GetDlgItem(hwndDlg, IDC_STARTDELAYTXT), ((IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART))));
			EnableWindow(GetDlgItem(hwndDlg, IDC_STDELAYSECTXT), ((IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART))));
			break;

		case IDC_DISABLEMENU:
			ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW);
			break;

		case IDC_TYPEFACE:
			SendMessage(hwndDlg, M_FILLSCRIPTCOMBO, wParam, 0);
		case IDC_FONTSIZE:
		case IDC_SCRIPT:
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_START_DELAY:
			if (HIWORD(wParam) == EN_CHANGE)
				test++;
			if (test > 1)
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_TIME:
			if (HIWORD(wParam) == EN_CHANGE)
				test2++;
			if (test2 > 2)
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		} // end WM_COMMAND
		break;

	case WM_DESTROY:
		test = 0;
		test2 = 0;
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR) lParam)->code) {
		case PSN_APPLY:
			db_set_b(NULL, MODULENAME, MENU_OFF, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_DISABLEMENU));
			db_set_b(NULL, MODULENAME, SUPPRESS_ERR_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SUPPRESS));
			db_set_b(NULL, MODULENAME, UPDATE_ONSTART_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONSTART));
			db_set_b(NULL, MODULENAME, UPDATE_ON_OPEN_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ON_OPEN));
			db_set_b(NULL, MODULENAME, HIDE_STATUS_ICON_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_HIDE_STATUS_ICON));
			db_set_b(NULL, MODULENAME, FONT_BOLD_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_FONT_BOLD));
			db_set_b(NULL, MODULENAME, FONT_ITALIC_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_FONT_ITALIC));
			db_set_b(NULL, MODULENAME, FONT_UNDERLINE_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_FONT_UNDERLINE));
			db_set_b(NULL, MODULENAME, UPDATE_ONALERT_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_UPDATE_ONALERT));
			db_set_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SAVE_INDIVID_POS));
			db_set_b(NULL, MODULENAME, NO_PROTECT_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_NO_PROTECT));
			db_set_b(NULL, MODULENAME, DATA_POPUP_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_DATAPOPUP));

			TCHAR str[100];
			GetDlgItemText(hwndDlg, IDC_TYPEFACE, str, SIZEOF(str));
			db_set_ts(NULL, MODULENAME, FONT_FACE_KEY, str);

			db_set_b(NULL, MODULENAME, FONT_SIZE_KEY, (GetDlgItemInt(hwndDlg, IDC_FONTSIZE, NULL, FALSE)));
			db_set_b(NULL, MODULENAME, FONT_SCRIPT_KEY, ((BYTE)SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_SCRIPT, CB_GETCURSEL, 0, 0), 0)));

			db_set_b(NULL, MODULENAME, ERROR_POPUP_KEY, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ERROR_POPUP));

			timerval = GetDlgItemInt(hwndDlg, IDC_TIME, NULL, FALSE);
			db_set_dw(NULL, MODULENAME, REFRESH_KEY, timerval);
			db_set_dw(NULL, MODULENAME, COUNTDOWN_KEY, timerval);


			delaytime = GetDlgItemInt(hwndDlg, IDC_START_DELAY, NULL, FALSE);
			db_set_dw(NULL, MODULENAME, START_DELAY_KEY, delaytime);

			BackgoundClr = (SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0));
			TextClr = (SendDlgItemMessage(hwndDlg, IDC_TXTCOLOR, CPM_GETCOLOUR, 0, 0));

			if ((db_get_dw(NULL, MODULENAME, REFRESH_KEY, 0) != 0))
			{
				KillTimer(NULL, timerId);
				KillTimer(NULL, Countdown);
				timerId = SetTimer(NULL, 0, ((db_get_dw(NULL, MODULENAME, REFRESH_KEY, 0)) * MINUTE), timerfunc);
				Countdown = SetTimer(NULL, 0, MINUTE, Countdownfunc);
			}
			if ((db_get_dw(NULL, MODULENAME, REFRESH_KEY, 0) == 0))
			{
				KillTimer(NULL, timerId);
				KillTimer(NULL, Countdown);
			}
			test = 0;
		}
		break; // end apply
	}

	return 0;
}