]> git.wh0rd.org Git - tt-rss.git/blob - prefs.js
remove old-style big feed browser
[tt-rss.git] / prefs.js
1 var xmlhttp = false;
2
3 var active_feed_cat = false;
4 var active_tab = false;
5 var feed_to_expand = false;
6
7 var xmlhttp = Ajax.getTransport();
8
9 var init_params = new Array();
10
11 var caller_subop = false;
12 var sanity_check_done = false;
13 var hotkey_prefix = false;
14
15 function infobox_callback() {
16         if (xmlhttp.readyState == 4) {
17                 infobox_callback2(xmlhttp);
18         }
19 }
20
21 function infobox_submit_callback() {
22         if (xmlhttp.readyState == 4) {
23                 infobox_submit_callback2(xmlhttp);
24         }
25 }
26
27
28 function replace_pubkey_callback() {
29         if (xmlhttp.readyState == 4) {
30                 try {   
31                         var link = document.getElementById("pubGenAddress");
32
33                         if (xmlhttp.responseXML) {
34
35                                 var new_link = xmlhttp.responseXML.getElementsByTagName("link")[0];
36
37                                 if (new_link) {
38                                         link.href = new_link.firstChild.nodeValue;
39                                         //link.innerHTML = new_link.firstChild.nodeValue;
40
41                                         new Effect.Highlight(link);
42
43                                         notify_info("Published feed URL changed.");
44                                 } else {
45                                         notify_error("Could not change feed URL.");
46                                 }
47
48                         } else {
49                                 notify_error("Could not change feed URL.");
50                         }
51                 } catch (e) {
52                         exception_error("replace_pubkey_callback", e);
53                 }
54         }
55 }
56
57 function expand_feed_callback() {
58         if (xmlhttp.readyState == 4) {
59                 try {   
60                         var container = document.getElementById("BRDET-" + feed_to_expand);     
61                         container.innerHTML=xmlhttp.responseText;
62 //                      container.style.display = "block";
63                         Effect.Appear(container, {duration : 0.5});
64                         notify('');
65                 } catch (e) {
66                         exception_error("expand_feed_callback", e);
67                 }
68         }
69 }
70
71 function feedlist_callback() {
72         if (xmlhttp.readyState == 4) {
73                 try {   
74                         var container = document.getElementById('prefContent'); 
75                         container.innerHTML=xmlhttp.responseText;
76                         selectTab("feedConfig", true);
77
78                         if (caller_subop) {
79                                 var tuple = caller_subop.split(":");
80                                 if (tuple[0] == 'editFeed') {
81                                         window.setTimeout('editFeed('+tuple[1]+')', 100);
82                                 }                               
83
84                                 caller_subop = false;
85                         }
86                         if (typeof correctPNG != 'undefined') {
87                                 correctPNG();
88                         }
89                         notify("");
90                         remove_splash();
91
92                 } catch (e) {
93                         exception_error("feedlist_callback", e);
94                 }
95         }
96 }
97
98 /* stub for subscription dialog */
99
100 function dlg_frefresh_callback(transport) {
101
102         try {
103                 var container = document.getElementById('prefContent'); 
104                 container.innerHTML=transport.responseText;
105                 selectTab("feedConfig", true);
106
107                 if (caller_subop) {
108                         var tuple = caller_subop.split(":");
109                         if (tuple[0] == 'editFeed') {
110                                 window.setTimeout('editFeed('+tuple[1]+')', 100);
111                         }                               
112
113                         caller_subop = false;
114                 }
115                 if (typeof correctPNG != 'undefined') {
116                         correctPNG();
117                 }
118                 notify("");
119         } catch (e) {
120                 exception_error("feedlist_callback", e);
121         }
122
123 }
124
125 function filterlist_callback() {
126         var container = document.getElementById('prefContent');
127         if (xmlhttp.readyState == 4) {
128                 container.innerHTML=xmlhttp.responseText;
129                 if (typeof correctPNG != 'undefined') {
130                         correctPNG();
131                 }
132                 notify("");
133                 remove_splash();
134         }
135 }
136
137 function labellist_callback() {
138
139         try {
140
141                 var container = document.getElementById('prefContent');
142                 if (xmlhttp.readyState == 4) {
143                         closeInfoBox();
144                         container.innerHTML=xmlhttp.responseText;
145         
146                         if (document.getElementById("prefLabelList")) {
147                                 var elems = document.getElementById("prefLabelList").getElementsByTagName("SPAN");
148
149                                 for (var i = 0; i < elems.length; i++) {
150                                         if (elems[i].id && elems[i].id.match("LILT-")) {
151
152                                                 var id = elems[i].id.replace("LILT-", "");
153                                                         new Ajax.InPlaceEditor(elems[i],
154                                                         'backend.php?op=pref-labels&subop=save&id=' + id,
155                                                         {cols: 20, rows: 1});
156                                         }
157                                 }
158                         }
159         
160                         if (typeof correctPNG != 'undefined') {
161                                 correctPNG();
162                         }
163                         notify("");
164                         remove_splash();
165                 }
166
167         } catch (e) {
168                 exception_error("labellist_callback", e);
169         }
170 }
171
172 function feed_browser_callback() {
173         var container = document.getElementById('prefContent');
174         if (xmlhttp.readyState == 4) {
175                 container.innerHTML=xmlhttp.responseText;
176                 notify("");
177                 remove_splash();
178         }
179 }
180
181 function userlist_callback() {
182         var container = document.getElementById('prefContent');
183         if (xmlhttp.readyState == 4) {
184                 container.innerHTML=xmlhttp.responseText;
185                 notify("");
186                 remove_splash();
187         }
188 }
189
190 function prefslist_callback() {
191         var container = document.getElementById('prefContent');
192         if (xmlhttp.readyState == 4) {
193                 container.innerHTML=xmlhttp.responseText;
194                 notify("");
195                 remove_splash();
196         }
197 }
198
199 function gethelp_callback() {
200         var container = document.getElementById('prefHelpBox');
201         if (xmlhttp.readyState == 4) {
202
203                 container.innerHTML = xmlhttp.responseText;
204                 container.style.display = "block";
205
206         }
207 }
208
209 function notify_callback() {
210         if (xmlhttp.readyState == 4) {
211                 notify_info(xmlhttp.responseText);
212         } 
213 }
214
215 function prefs_reset_callback() {
216         if (xmlhttp.readyState == 4) {
217                 notify_info(xmlhttp.responseText);
218                 selectTab();
219         } 
220 }
221
222
223 function changepass_callback() {
224         try {
225                 if (xmlhttp.readyState == 4) {
226         
227                         if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
228                                 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
229                         } else {
230                                 notify_info(xmlhttp.responseText);
231                                 var warn = document.getElementById("default_pass_warning");
232                                 if (warn) warn.style.display = "none";
233                         }
234         
235                         document.forms['change_pass_form'].reset();
236
237                 } 
238         } catch (e) {
239                 exception_error("changepass_callback", e);
240         }
241 }
242
243 function init_cat_inline_editor() {
244         try {
245
246                 if (document.getElementById("prefFeedCatList")) {
247                         var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
248
249                         for (var i = 0; i < elems.length; i++) {
250                                 if (elems[i].id && elems[i].id.match("FCATT-")) {
251                                         var cat_id = elems[i].id.replace("FCATT-", "");
252                                                 new Ajax.InPlaceEditor(elems[i],
253                                                 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
254                                 }
255                         }
256                 }
257
258         } catch (e) {
259                 exception_error("init_cat_inline_editor", e);
260         }
261 }
262
263 function infobox_feed_cat_callback() {
264         if (xmlhttp.readyState == 4) {
265                 try {
266
267                         infobox_callback();
268                         init_cat_inline_editor();
269
270                 } catch (e) {
271                         exception_error("infobox_feed_cat_callback", e);
272                 }
273         }
274 }
275
276 function updateFeedList(sort_key) {
277
278         if (!xmlhttp_ready(xmlhttp)) {
279                 printLockingError();
280                 return
281         }
282
283         var feed_search = document.getElementById("feed_search");
284         var search = "";
285         if (feed_search) { search = feed_search.value; }
286
287         var slat = document.getElementById("show_last_article_times");
288
289         var slat_checked = false;
290         if (slat) {
291                 slat_checked = slat.checked;
292         }
293
294         xmlhttp.open("GET", "backend.php?op=pref-feeds" +
295                 "&sort=" + param_escape(sort_key) + 
296                 "&slat=" + param_escape(slat_checked) +
297                 "&search=" + param_escape(search), true);
298         xmlhttp.onreadystatechange=feedlist_callback;
299         xmlhttp.send(null);
300
301 }
302
303 function updateUsersList(sort_key) {
304
305         if (!xmlhttp_ready(xmlhttp)) {
306                 printLockingError();
307                 return
308         }
309
310         var user_search = document.getElementById("user_search");
311         var search = "";
312         if (user_search) { search = user_search.value; }
313
314         xmlhttp.open("GET", "backend.php?op=pref-users&sort="
315                 + param_escape(sort_key) +
316                 "&search=" + param_escape(search), true);
317         xmlhttp.onreadystatechange=userlist_callback;
318         xmlhttp.send(null);
319
320 }
321
322 function addLabel() {
323
324         try {
325
326         if (!xmlhttp_ready(xmlhttp)) {
327                 printLockingError();
328                 return
329         }
330
331         var caption = prompt(__("Please enter label caption:"), "");
332
333         if (caption == null) { 
334                 return false;
335         }
336
337         if (caption == "") {
338                 alert(__("Can't create label: missing caption."));
339                 return false;
340         }
341
342         // we can be called from some other tab
343         active_tab = "labelConfig";
344
345         var query = "caption=" + param_escape(caption);
346
347         xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);                     
348         xmlhttp.onreadystatechange=infobox_submit_callback;
349         xmlhttp.send(null);
350
351         } catch (e) {
352                 exception_error("addLabel", e);
353         }
354 }
355
356 function addFeed() {
357
358         if (!xmlhttp_ready(xmlhttp)) {
359                 printLockingError();
360                 return
361         }
362
363         var link = document.getElementById("fadd_link");
364
365         if (link.value.length == 0) {
366                 alert(__("Error: No feed URL given."));
367         } else if (!isValidURL(link.value)) {
368                 alert(__("Error: Invalid feed URL."));
369         } else {
370                 notify_progress("Adding feed...");
371
372                 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
373                         param_escape(link.value), true);
374                 xmlhttp.onreadystatechange=feedlist_callback;
375                 xmlhttp.send(null);
376
377                 link.value = "";
378
379         }
380
381 }
382
383 function addFeedCat() {
384
385         if (!xmlhttp_ready(xmlhttp)) {
386                 printLockingError();
387                 return
388         }
389
390         var cat = document.getElementById("fadd_cat");
391
392         if (cat.value.length == 0) {
393                 alert(__("Can't add category: no name specified."));
394         } else {
395                 notify_progress("Adding feed category...");
396
397                 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
398                         param_escape(cat.value), true);
399                 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
400                 xmlhttp.send(null);
401
402                 link.value = "";
403
404         }
405
406 }
407 function addUser() {
408
409         if (!xmlhttp_ready(xmlhttp)) {
410                 printLockingError();
411                 return
412         }
413
414         var sqlexp = document.getElementById("uadd_box");
415
416         if (sqlexp.value.length == 0) {
417                 alert(__("Can't add user: no login specified."));
418         } else {
419                 notify_progress("Adding user...");
420
421                 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
422                         param_escape(sqlexp.value), true);                      
423                         
424                 xmlhttp.onreadystatechange=userlist_callback;
425                 xmlhttp.send(null);
426
427                 sqlexp.value = "";
428         }
429
430 }
431
432 function editUser(id) {
433
434         if (!xmlhttp_ready(xmlhttp)) {
435                 printLockingError();
436                 return
437         }
438
439         disableHotkeys();
440
441         notify_progress("Loading, please wait...");
442
443         selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
444         selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
445
446         disableContainerChildren("userOpToolbar", false);
447
448         xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
449                 param_escape(id), true);
450         xmlhttp.onreadystatechange=infobox_callback;
451         xmlhttp.send(null);
452
453 }
454
455 function editFilter(id) {
456
457         if (!xmlhttp_ready(xmlhttp)) {
458                 printLockingError();
459                 return
460         }
461
462         disableHotkeys();
463
464         notify_progress("Loading, please wait...");
465
466 //      document.getElementById("create_filter_btn").disabled = true;
467
468         disableContainerChildren("filterOpToolbar", false);
469
470         selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
471         selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
472
473         xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
474         xmlhttp.onreadystatechange=infobox_callback;
475         xmlhttp.send(null);
476 }
477
478 function editFeed(feed) {
479
480 //      notify("Editing feed...");
481
482         if (!xmlhttp_ready(xmlhttp)) {
483                 printLockingError();
484                 return
485         }
486
487         disableHotkeys();
488
489         notify_progress("Loading, please wait...");
490
491 /*      document.getElementById("subscribe_to_feed_btn").disabled = true;
492
493         try {
494                 document.getElementById("top25_feeds_btn").disabled = true;
495         } catch (e) {
496                 // this button is not always available, no-op if not found
497         } */
498
499         // clean selection from all rows & select row being edited
500         selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
501         selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
502
503         disableContainerChildren("feedOpToolbar", false);
504
505         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
506                 param_escape(feed), true);
507
508         xmlhttp.onreadystatechange=infobox_callback;
509         xmlhttp.send(null);
510
511 }
512
513 function editFeedCat(cat) {
514
515         if (!xmlhttp_ready(xmlhttp)) {
516                 printLockingError();
517                 return
518         }
519
520         disableHotkeys();
521
522         notify_progress("Loading, please wait...");
523
524         active_feed_cat = cat;
525
526         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
527                 param_escape(cat), true);
528         xmlhttp.onreadystatechange=infobox_callback;
529         xmlhttp.send(null);
530
531 }
532
533 function getSelectedLabels() {
534         return getSelectedTableRowIds("prefLabelList", "LILRR");
535 }
536
537 function getSelectedUsers() {
538         return getSelectedTableRowIds("prefUserList", "UMRR");
539 }
540
541 function getSelectedFeeds() {
542         return getSelectedTableRowIds("prefFeedList", "FEEDR");
543 }
544
545 function getSelectedFilters() {
546         return getSelectedTableRowIds("prefFilterList", "FILRR");
547 }
548
549 function getSelectedFeedCats() {
550         return getSelectedTableRowIds("prefFeedCatList", "FCATR");
551 }
552
553
554 function removeSelectedLabels() {
555
556         if (!xmlhttp_ready(xmlhttp)) {
557                 printLockingError();
558                 return
559         }
560
561         var sel_rows = getSelectedLabels();
562
563         if (sel_rows.length > 0) {
564
565                 var ok = confirm(__("Remove selected labels?"));
566
567                 if (ok) {
568                         notify_progress("Removing selected labels...");
569         
570                         xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
571                                 param_escape(sel_rows.toString()), true);
572                         xmlhttp.onreadystatechange=labellist_callback;
573                         xmlhttp.send(null);
574                 }
575         } else {
576                 alert(__("No labels are selected."));
577         }
578
579         return false;
580 }
581
582 function removeSelectedUsers() {
583
584         if (!xmlhttp_ready(xmlhttp)) {
585                 printLockingError();
586                 return
587         }
588
589         var sel_rows = getSelectedUsers();
590
591         if (sel_rows.length > 0) {
592
593                 var ok = confirm(__("Remove selected users?"));
594
595                 if (ok) {
596                         notify_progress("Removing selected users...");
597         
598                         xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
599                                 param_escape(sel_rows.toString()), true);
600                         xmlhttp.onreadystatechange=userlist_callback;
601                         xmlhttp.send(null);
602                 }
603
604         } else {
605                 alert(__("No users are selected."));
606         }
607
608         return false;
609 }
610
611 function removeSelectedFilters() {
612
613         if (!xmlhttp_ready(xmlhttp)) {
614                 printLockingError();
615                 return
616         }
617
618         var sel_rows = getSelectedFilters();
619
620         if (sel_rows.length > 0) {
621
622                 var ok = confirm(__("Remove selected filters?"));
623
624                 if (ok) {
625                         notify_progress("Removing selected filters...");
626         
627                         xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
628                                 param_escape(sel_rows.toString()), true);
629                         xmlhttp.onreadystatechange=filterlist_callback;
630                         xmlhttp.send(null);
631                 }
632         } else {
633                 alert(__("No filters are selected."));
634         }
635
636         return false;
637 }
638
639
640 function removeSelectedFeeds() {
641
642         if (!xmlhttp_ready(xmlhttp)) {
643                 printLockingError();
644                 return
645         }
646
647         var sel_rows = getSelectedFeeds();
648
649         if (sel_rows.length > 0) {
650
651                 var ok = confirm(__("Unsubscribe from selected feeds?"));
652
653                 if (ok) {
654
655                         notify_progress("Unsubscribing from selected feeds...");
656         
657                         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
658                                 param_escape(sel_rows.toString()), true);
659                         xmlhttp.onreadystatechange=feedlist_callback;
660                         xmlhttp.send(null);
661                 }
662
663         } else {
664
665                 alert(__("No feeds are selected."));
666
667         }
668         
669         return false;
670 }
671
672 function clearSelectedFeeds() {
673
674         if (!xmlhttp_ready(xmlhttp)) {
675                 printLockingError();
676                 return
677         }
678
679         var sel_rows = getSelectedFeeds();
680
681         if (sel_rows.length > 1) {
682                 alert(__("Please select only one feed."));
683                 return;
684         }
685
686         if (sel_rows.length > 0) {
687
688                 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
689
690                 if (ok) {
691                         notify_progress("Clearing selected feed...");
692                         clearFeedArticles(sel_rows[0]);
693                 }
694
695         } else {
696
697                 alert(__("No feeds are selected."));
698
699         }
700         
701         return false;
702 }
703
704 function purgeSelectedFeeds() {
705
706         if (!xmlhttp_ready(xmlhttp)) {
707                 printLockingError();
708                 return
709         }
710
711         var sel_rows = getSelectedFeeds();
712
713         if (sel_rows.length > 0) {
714
715                 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
716
717                 if (pr != undefined) {
718                         notify_progress("Purging selected feed...");
719
720                         var query = "backend.php?op=rpc&subop=purge&ids="+
721                                 param_escape(sel_rows.toString()) + "&days=" + pr;
722
723                         debug(query);
724
725                         new Ajax.Request(query, {
726                                 onComplete: function(transport) {
727                                         notify('');
728                                 } });
729                 }
730
731         } else {
732
733                 alert(__("No feeds are selected."));
734
735         }
736         
737         return false;
738 }
739
740 function removeSelectedFeedCats() {
741
742         if (!xmlhttp_ready(xmlhttp)) {
743                 printLockingError();
744                 return
745         }
746
747         var sel_rows = getSelectedFeedCats();
748
749         if (sel_rows.length > 0) {
750
751                 var ok = confirm(__("Remove selected categories?"));
752
753                 if (ok) {
754                         notify_progress("Removing selected categories...");
755         
756                         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
757                                 param_escape(sel_rows.toString()), true);
758                         xmlhttp.onreadystatechange=infobox_feed_cat_callback;
759                         xmlhttp.send(null);
760                 }
761
762         } else {
763
764                 alert(__("No categories are selected."));
765
766         }
767
768         return false;
769 }
770
771 function feedEditCancel() {
772
773         if (!xmlhttp_ready(xmlhttp)) {
774                 printLockingError();
775                 return
776         }
777
778         try {
779                 document.getElementById("subscribe_to_feed_btn").disabled = false;
780                 document.getElementById("top25_feeds_btn").disabled = false;
781         } catch (e) {
782                 // this button is not always available, no-op if not found
783         }
784
785         closeInfoBox();
786
787         selectPrefRows('feed', false); // cleanup feed selection
788
789         return false;
790 }
791
792 function feedCatEditCancel() {
793
794         if (!xmlhttp_ready(xmlhttp)) {
795                 printLockingError();
796                 return
797         }
798
799         active_feed_cat = false;
800
801         try {
802                 document.getElementById("subscribe_to_feed_btn").disabled = false;
803                 document.getElementById("top25_feeds_btn").disabled = false;
804         } catch (e) {
805                 // this button is not always available, no-op if not found
806         }
807
808         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
809         xmlhttp.onreadystatechange=infobox_callback;
810         xmlhttp.send(null);
811
812         return false;
813 }
814
815 function feedEditSave() {
816
817         try {
818         
819                 if (!xmlhttp_ready(xmlhttp)) {
820                         printLockingError();
821                         return
822                 }
823
824                 // FIXME: add parameter validation
825
826                 var query = Form.serialize("edit_feed_form");
827
828                 notify_progress("Saving feed...");
829
830                 xmlhttp.open("POST", "backend.php", true);
831                 xmlhttp.onreadystatechange=feedlist_callback;
832                 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
833                 xmlhttp.send(query);
834
835                 closeInfoBox();
836
837                 return false;
838
839         } catch (e) {
840                 exception_error("feedEditSave", e);
841         } 
842 }
843
844 function userEditCancel() {
845
846         if (!xmlhttp_ready(xmlhttp)) {
847                 printLockingError();
848                 return
849         }
850
851         selectPrefRows('user', false); // cleanup feed selection
852         closeInfoBox();
853
854         return false;
855 }
856
857 function filterEditCancel() {
858
859         if (!xmlhttp_ready(xmlhttp)) {
860                 printLockingError();
861                 return
862         }
863
864         try {
865                 document.getElementById("create_filter_btn").disabled = false;
866                 selectPrefRows('filter', false); // cleanup feed selection
867         } catch (e) { }
868
869         closeInfoBox();
870
871         return false;
872 }
873
874 function userEditSave() {
875
876         if (!xmlhttp_ready(xmlhttp)) {
877                 printLockingError();
878                 return
879         }
880
881         var login = document.forms["user_edit_form"].login.value;
882
883         if (login.length == 0) {
884                 alert(__("Login field cannot be blank."));
885                 return;
886         }
887         
888         notify_progress("Saving user...");
889
890         closeInfoBox();
891
892         var query = Form.serialize("user_edit_form");
893         
894         xmlhttp.open("GET", "backend.php?" + query, true);                      
895         xmlhttp.onreadystatechange=userlist_callback;
896         xmlhttp.send(null);
897
898         return false;
899 }
900
901
902 function filterEditSave() {
903
904         if (!xmlhttp_ready(xmlhttp)) {
905                 printLockingError();
906                 return
907         }
908
909 /*      if (!is_opera()) {
910                 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
911         
912                 if (reg_exp.length == 0) {
913                         alert("Filter expression field cannot be blank.");
914                         return;
915                 }
916         } */
917
918         notify_progress("Saving filter...");
919
920         var query = Form.serialize("filter_edit_form");
921
922         closeInfoBox();
923
924         document.getElementById("create_filter_btn").disabled = false;
925
926         xmlhttp.open("GET", "backend.php?" + query, true);
927         xmlhttp.onreadystatechange=filterlist_callback;
928         xmlhttp.send(null);
929
930         return false;
931 }
932
933
934 function editSelectedUser() {
935         var rows = getSelectedUsers();
936
937         if (rows.length == 0) {
938                 alert(__("No users are selected."));
939                 return;
940         }
941
942         if (rows.length > 1) {
943                 alert(__("Please select only one user."));
944                 return;
945         }
946
947         notify("");
948
949         editUser(rows[0]);
950 }
951
952 function resetSelectedUserPass() {
953         var rows = getSelectedUsers();
954
955         if (rows.length == 0) {
956                 alert(__("No users are selected."));
957                 return;
958         }
959
960         if (rows.length > 1) {
961                 alert(__("Please select only one user."));
962                 return;
963         }
964
965         var ok = confirm(__("Reset password of selected user?"));
966
967         if (ok) {
968                 notify_progress("Resetting password for selected user...");
969         
970                 var id = rows[0];
971         
972                 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
973                         param_escape(id), true);
974                 xmlhttp.onreadystatechange=userlist_callback;
975                 xmlhttp.send(null);
976         }
977 }
978
979 function selectedUserDetails() {
980
981         if (!xmlhttp_ready(xmlhttp)) {
982                 printLockingError();
983                 return
984         }
985
986         var rows = getSelectedUsers();
987
988         if (rows.length == 0) {
989                 alert(__("No users are selected."));
990                 return;
991         }
992
993         if (rows.length > 1) {
994                 alert(__("Please select only one user."));
995                 return;
996         }
997
998         notify_progress("Loading, please wait...");
999
1000         var id = rows[0];
1001
1002         xmlhttp.open("GET", "backend.php?op=pref-users&subop=user-details&id=" + id, true);
1003         xmlhttp.onreadystatechange=infobox_callback;
1004         xmlhttp.send(null);
1005
1006 }
1007
1008 function selectedFeedDetails() {
1009
1010         if (!xmlhttp_ready(xmlhttp)) {
1011                 printLockingError();
1012                 return
1013         }
1014
1015         var rows = getSelectedFeeds();
1016
1017         if (rows.length == 0) {
1018                 alert(__("No feeds are selected."));
1019                 return;
1020         }
1021
1022         if (rows.length > 1) {
1023                 alert(__("Please select only one feed."));
1024                 return;
1025         }
1026
1027 //      var id = rows[0];
1028
1029         notify("");
1030
1031         xmlhttp.open("GET", "backend.php?op=feed-details&id=" + 
1032                 param_escape(rows.toString()), true);
1033         xmlhttp.onreadystatechange=infobox_callback;
1034         xmlhttp.send(null);
1035
1036 }
1037
1038 function editSelectedFilter() {
1039         var rows = getSelectedFilters();
1040
1041         if (rows.length == 0) {
1042                 alert(__("No filters are selected."));
1043                 return;
1044         }
1045
1046         if (rows.length > 1) {
1047                 alert(__("Please select only one filter."));
1048                 return;
1049         }
1050
1051         notify("");
1052
1053         editFilter(rows[0]);
1054
1055 }
1056
1057
1058 function editSelectedFeed() {
1059         var rows = getSelectedFeeds();
1060
1061         if (rows.length == 0) {
1062                 alert(__("No feeds are selected."));
1063                 return;
1064         }
1065
1066         if (rows.length > 1) {
1067                 alert(__("Please select one feed."));
1068                 return;
1069         }
1070
1071         notify("");
1072
1073         editFeed(rows[0]);
1074
1075 }
1076
1077 function editSelectedFeeds() {
1078
1079         if (!xmlhttp_ready(xmlhttp)) {
1080                 printLockingError();
1081                 return
1082         }
1083
1084         var rows = getSelectedFeeds();
1085
1086         if (rows.length == 0) {
1087                 alert(__("No feeds are selected."));
1088                 return;
1089         }
1090
1091         notify("");
1092
1093         disableHotkeys();
1094
1095         notify_progress("Loading, please wait...");
1096
1097         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeeds&ids=" +
1098                 param_escape(rows.toString()), true);
1099
1100         xmlhttp.onreadystatechange=infobox_callback;
1101         xmlhttp.send(null);
1102
1103 }
1104
1105 function editSelectedFeedCat() {
1106         var rows = getSelectedFeedCats();
1107
1108         if (rows.length == 0) {
1109                 alert(__("No categories are selected."));
1110                 return;
1111         }
1112
1113         if (rows.length > 1) {
1114                 alert(__("Please select only one category."));
1115                 return;
1116         }
1117
1118         notify("");
1119
1120         editFeedCat(rows[0]);
1121
1122 }
1123
1124 function piggie(enable) {
1125         if (enable) {
1126                 debug("I LOVEDED IT!");
1127                 var piggie = document.getElementById("piggie");
1128
1129                 Element.show(piggie);
1130                 Position.Center(piggie);
1131                 Effect.Puff(piggie);
1132
1133         }
1134 }
1135
1136 function validateOpmlImport() {
1137         
1138         var opml_file = document.getElementById("opml_file");
1139
1140         if (opml_file.value.length == 0) {
1141                 alert(__("No OPML file to upload."));
1142                 return false;
1143         } else {
1144                 return true;
1145         }
1146 }
1147
1148 function updateFilterList(sort_key) {
1149
1150         if (!xmlhttp_ready(xmlhttp)) {
1151                 printLockingError();
1152                 return
1153         }
1154
1155         var filter_search = document.getElementById("filter_search");
1156         var search = "";
1157         if (filter_search) { search = filter_search.value; }
1158
1159         xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" + 
1160                 param_escape(sort_key) + 
1161                 "&search=" + param_escape(search), true);
1162         xmlhttp.onreadystatechange=filterlist_callback;
1163         xmlhttp.send(null);
1164
1165 }
1166
1167 function updateLabelList(sort_key) {
1168
1169         if (!xmlhttp_ready(xmlhttp)) {
1170                 printLockingError();
1171                 return
1172         }
1173
1174         var label_search = document.getElementById("label_search");
1175         var search = "";
1176         if (label_search) { search = label_search.value; }
1177
1178         xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" + 
1179                 param_escape(sort_key) +
1180                 "&search=" + param_escape(search), true);
1181         xmlhttp.onreadystatechange=labellist_callback;
1182         xmlhttp.send(null);
1183 }
1184
1185 function updatePrefsList() {
1186
1187         if (!xmlhttp_ready(xmlhttp)) {
1188                 printLockingError();
1189                 return
1190         }
1191
1192         xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1193         xmlhttp.onreadystatechange=prefslist_callback;
1194         xmlhttp.send(null);
1195
1196 }
1197
1198 function selectTab(id, noupdate, subop) {
1199
1200 //      alert(id);
1201
1202         if (!id) id = active_tab;
1203
1204         try {
1205
1206                 if (!xmlhttp_ready(xmlhttp)) {
1207                         printLockingError();
1208                         return
1209                 }
1210
1211                 try {
1212                         var c = document.getElementById('prefContent'); 
1213                         c.scrollTop = 0;
1214                 } catch (e) { };
1215
1216                 if (!noupdate) {
1217
1218                         debug("selectTab: " + id + "(NU: " + noupdate + ")");
1219         
1220                         notify_progress("Loading, please wait...");
1221         
1222                         // close active infobox if needed
1223                         closeInfoBox();
1224         
1225                         // clean up all current selections, just in case
1226                         active_feed_cat = false;
1227
1228 //                      Effect.Fade("prefContent", {duration: 1, to: 0.01, 
1229 //                              queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
1230
1231                         if (id == "feedConfig") {
1232                                 updateFeedList();
1233                         } else if (id == "filterConfig") {
1234                                 updateFilterList();
1235                         } else if (id == "labelConfig") {
1236                                 updateLabelList();
1237                         } else if (id == "genConfig") {
1238                                 updatePrefsList();
1239                         } else if (id == "userConfig") {
1240                                 updateUsersList();
1241                         }
1242                 }
1243
1244                 /* clean selection from all tabs */
1245         
1246                 var tabs_holder = document.getElementById("prefTabs");
1247                 var tab = tabs_holder.firstChild;
1248
1249                 while (tab) {
1250                         if (tab.className && tab.className.match("prefsTabSelected")) {
1251                                 tab.className = "prefsTab";
1252                         }
1253                         tab = tab.nextSibling;
1254                 }
1255
1256                 /* mark new tab as selected */
1257
1258                 tab = document.getElementById(id + "Tab");
1259         
1260                 if (tab) {
1261                         if (!tab.className.match("Selected")) {
1262                                 tab.className = tab.className + "Selected";
1263                         }
1264                 }
1265         
1266                 active_tab = id;
1267
1268         } catch (e) {
1269                 exception_error("selectTab", e);
1270         }
1271 }
1272
1273 function backend_sanity_check_callback() {
1274
1275         if (xmlhttp.readyState == 4) {
1276
1277                 try {
1278
1279                         if (sanity_check_done) {
1280                                 fatalError(11, "Sanity check request received twice. This can indicate "+
1281                               "presence of Firebug or some other disrupting extension. "+
1282                                         "Please disable it and try again.");
1283                                 return;
1284                         }
1285
1286                         if (!xmlhttp.responseXML) {
1287                                 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1288                                 return;
1289                         }
1290         
1291                         var reply = xmlhttp.responseXML.firstChild.firstChild;
1292         
1293                         if (!reply) {
1294                                 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1295                                 return;
1296                         }
1297         
1298                         var error_code = reply.getAttribute("error-code");
1299                 
1300                         if (error_code && error_code != 0) {
1301                                 return fatalError(error_code, reply.getAttribute("error-msg"));
1302                         }
1303         
1304                         debug("sanity check ok");
1305
1306                         var params = reply.nextSibling;
1307
1308                         if (params) {
1309                                 debug('reading init-params...');
1310                                 var param = params.firstChild;
1311
1312                                 while (param) {
1313                                         var k = param.getAttribute("key");
1314                                         var v = param.getAttribute("value");
1315                                         debug(k + " => " + v);
1316                                         init_params[k] = v;                                     
1317                                         param = param.nextSibling;
1318                                 }
1319                         }
1320
1321                         sanity_check_done = true;
1322
1323                         init_second_stage();
1324
1325                 } catch (e) {
1326                         exception_error("backend_sanity_check_callback", e);
1327                 }
1328         } 
1329 }
1330
1331 function init_second_stage() {
1332
1333         try {
1334                 active_tab = getInitParam("prefs_active_tab");
1335                 if (!active_tab || active_tab == '0') active_tab = "genConfig";
1336
1337                 document.onkeydown = pref_hotkey_handler;
1338
1339                 var tab = getURLParam('tab');
1340                 
1341                 caller_subop = getURLParam('subop');
1342
1343                 if (getURLParam("subopparam")) {
1344                         caller_subop = caller_subop + ":" + getURLParam("subopparam");
1345                 }
1346
1347                 if (tab) {
1348                         active_tab = tab;
1349                 }
1350
1351                 if (navigator.userAgent.match("Opera")) {       
1352                         setTimeout("selectTab()", 500);
1353                 } else {
1354                         selectTab(active_tab);
1355                 }
1356                 notify("");
1357
1358                 loading_set_progress(60);
1359
1360         } catch (e) {
1361                 exception_error("init_second_stage", e);
1362         }
1363 }
1364
1365 function init() {
1366
1367         try {
1368         
1369                 if (arguments.callee.done) return;
1370                 arguments.callee.done = true;           
1371
1372                 if (getURLParam('debug')) {
1373                         Element.show("debug_output");
1374                         debug('debug mode activated');
1375                 }
1376
1377                 // IE kludge
1378                 if (!xmlhttp) {
1379                         document.getElementById("prefContent").innerHTML = 
1380                                 "<b>Fatal error:</b> This program needs XmlHttpRequest " + 
1381                                 "to function properly. Your browser doesn't seem to support it.";
1382                         return;
1383                 }
1384
1385                 loading_set_progress(30);
1386
1387                 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1388                 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1389                 xmlhttp.send(null);
1390
1391         } catch (e) {
1392                 exception_error("init", e);
1393         }
1394 }
1395
1396 function categorizeSelectedFeeds() {
1397
1398         if (!xmlhttp_ready(xmlhttp)) {
1399                 printLockingError();
1400                 return
1401         }
1402
1403         var sel_rows = getSelectedFeeds();
1404
1405         var cat_sel = document.getElementById("sfeed_set_fcat");
1406         var cat_id = cat_sel[cat_sel.selectedIndex].value;
1407
1408         if (sel_rows.length > 0) {
1409
1410                 notify_progress("Changing category of selected feeds...");
1411
1412                 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1413                         param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1414                 xmlhttp.onreadystatechange=feedlist_callback;
1415                 xmlhttp.send(null);
1416
1417         } else {
1418
1419                 alert(__("No feeds are selected."));
1420
1421         }
1422
1423 }
1424
1425 function validatePrefsReset() {
1426         try {
1427                 var ok = confirm(__("Reset to defaults?"));
1428
1429                 if (ok) {
1430
1431                         var query = Form.serialize("pref_prefs_form");
1432                         query = query + "&subop=reset-config";
1433                         debug(query);
1434
1435                         xmlhttp.open("POST", "backend.php", true);
1436                         xmlhttp.onreadystatechange=prefs_reset_callback;
1437                         xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1438                         xmlhttp.send(query);
1439                 }
1440
1441         } catch (e) {
1442                 exception_error("validatePrefsSave", e);
1443         }
1444
1445         return false;
1446
1447 }
1448
1449 function browseFeeds(limit) {
1450
1451         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1452         xmlhttp.onreadystatechange=infobox_callback;
1453         xmlhttp.send(null);
1454
1455 }
1456
1457 function feedBrowserSubscribe() {
1458         try {
1459
1460                 var selected = getSelectedFeedsFromBrowser();
1461
1462                 if (selected.length > 0) {
1463                         closeInfoBox();
1464                         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1465                                 param_escape(selected.toString()), true);
1466                         xmlhttp.onreadystatechange=feedlist_callback;
1467                         xmlhttp.send(null);
1468                 } else {
1469                         alert(__("No feeds are selected."));
1470                 }
1471
1472         } catch (e) {
1473                 exception_error("feedBrowserSubscribe", e);
1474         }
1475 }
1476
1477 function updateBigFeedBrowserBtn() {
1478         notify_progress("Loading, please wait...");
1479         return updateBigFeedBrowser();
1480 }
1481
1482 function selectPrefRows(kind, select) {
1483
1484         if (kind) {
1485                 var opbarid = false;    
1486                 var nchk = false;
1487                 var nrow = false;
1488                 var lname = false;
1489
1490                 if (kind == "feed") {
1491                         opbarid = "feedOpToolbar";
1492                         nrow = "FEEDR-";
1493                         nchk = "FRCHK-";                        
1494                         lname = "prefFeedList";
1495                 } else if (kind == "fcat") {
1496                         opbarid = "catOpToolbar";
1497                         nrow = "FCATR-";
1498                         nchk = "FCCHK-";
1499                         lname = "prefFeedCatList";
1500                 } else if (kind == "filter") {
1501                         opbarid = "filterOpToolbar";
1502                         nrow = "FILRR-";
1503                         nchk = "FICHK-";
1504                         lname = "prefFilterList";
1505                 } else if (kind == "label") {
1506                         opbarid = "labelOpToolbar";
1507                         nrow = "LILRR-";
1508                         nchk = "LICHK-";
1509                         lname = "prefLabelList";
1510                 } else if (kind == "user") {
1511                         opbarid = "userOpToolbar";
1512                         nrow = "UMRR-";
1513                         nchk = "UMCHK-";
1514                         lname = "prefUserList";
1515                 }
1516
1517                 if (opbarid) {
1518                         selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1519                         disableContainerChildren(opbarid, !select);
1520                 }
1521
1522         } 
1523 }
1524
1525
1526 function toggleSelectPrefRow(sender, kind) {
1527
1528         toggleSelectRow(sender);
1529
1530         if (kind) {
1531                 var opbarid = false;    
1532                 var nsel = -1;
1533                 
1534                 if (kind == "feed") {
1535                         opbarid = "feedOpToolbar";
1536                         nsel = getSelectedFeeds();
1537                 } else if (kind == "fcat") {
1538                         opbarid = "catOpToolbar";
1539                         nsel = getSelectedFeedCats();
1540                 } else if (kind == "filter") {
1541                         opbarid = "filterOpToolbar";
1542                         nsel = getSelectedFilters();
1543                 } else if (kind == "label") {
1544                         opbarid = "labelOpToolbar";
1545                         nsel = getSelectedLabels();
1546                 } else if (kind == "user") {
1547                         opbarid = "userOpToolbar";
1548                         nsel = getSelectedUsers();
1549                 }
1550
1551                 if (opbarid && nsel != -1) {
1552                         disableContainerChildren(opbarid, nsel == false);
1553                 }
1554
1555         } 
1556 }
1557
1558 function toggleSelectFBListRow(sender) {
1559         toggleSelectListRow(sender);
1560         disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1561 }
1562
1563 var seq = "";
1564
1565 function pref_hotkey_handler(e) {
1566         try {
1567
1568                 var keycode;
1569                 var shift_key = false;
1570
1571                 try {
1572                         shift_key = e.shiftKey;
1573                 } catch (e) {
1574
1575                 }
1576
1577                 if (window.event) {
1578                         keycode = window.event.keyCode;
1579                 } else if (e) {
1580                         keycode = e.which;
1581                 }
1582
1583                 var keychar = String.fromCharCode(keycode);
1584
1585                 if (keycode == 27) { // escape
1586                         if (Element.visible("hotkey_help_overlay")) {
1587                                 Element.hide("hotkey_help_overlay");
1588                         }
1589                         hotkey_prefix = false;
1590                         closeInfoBox();
1591                 } 
1592
1593                 if (!hotkeys_enabled) {
1594                         debug("hotkeys disabled");
1595                         return;
1596                 }
1597
1598                 if (keycode == 16) return; // ignore lone shift
1599
1600                 if ((keycode == 67 || keycode == 71) && !hotkey_prefix) {
1601                         hotkey_prefix = keycode;
1602                         debug("KP: PREFIX=" + keycode + " CHAR=" + keychar);
1603                         return;
1604                 }
1605
1606                 if (Element.visible("hotkey_help_overlay")) {
1607                         Element.hide("hotkey_help_overlay");
1608                 }
1609
1610                 if (keycode == 13 || keycode == 27) {
1611                         seq = "";
1612                 } else {
1613                         seq = seq + "" + keycode;
1614                 }
1615
1616                 /* Global hotkeys */
1617
1618                 if (!hotkey_prefix) {
1619
1620                         if (keycode == 68 && shift_key) { // d
1621                                 if (!Element.visible("debug_output")) {
1622                                         Element.show("debug_output");
1623                                         debug('debug mode activated');
1624                                 } else {
1625                                         Element.hide("debug_output");
1626                                 }
1627                                 return;
1628                         }
1629         
1630                         if ((keycode == 191 || keychar == '?') && shift_key) { // ?
1631                                 if (!Element.visible("hotkey_help_overlay")) {
1632                                         //Element.show("hotkey_help_overlay");
1633                                         Effect.Appear("hotkey_help_overlay", {duration : 0.3});
1634                                 } else {
1635                                         Element.hide("hotkey_help_overlay");
1636                                 }
1637                                 return false;
1638                         }
1639
1640                         if (keycode == 191 || keychar == '/') { // /
1641                                 var search_boxes = new Array("label_search", 
1642                                         "feed_search", "filter_search", "user_search", "feed_browser_search");
1643
1644                                 for (var i = 0; i < search_boxes.length; i++) {
1645                                         var elem = document.getElementById(search_boxes[i]);
1646                                         if (elem) {
1647                                                 focus_element(search_boxes[i]);
1648                                                 return false;
1649                                         }
1650                                 }
1651                         }
1652                 }
1653
1654                 /* Prefix c */
1655
1656                 if (hotkey_prefix == 67) { // c
1657                         hotkey_prefix = false;
1658
1659                         if (keycode == 70) { // f
1660                                 displayDlg("quickAddFilter");
1661                                 return false;
1662                         }
1663
1664                         if (keycode == 83) { // s
1665                                 displayDlg("quickAddFeed");
1666                                 return false;
1667                         }
1668
1669 /*                      if (keycode == 76) { // l
1670                                 displayDlg("quickAddLabel");
1671                                 return false;
1672                         } */
1673
1674                         if (keycode == 85) { // u
1675                                 // no-op
1676                         }
1677
1678                         if (keycode == 67) { // c
1679                                 editFeedCats();
1680                                 return false;
1681                         }
1682
1683                         if (keycode == 84 && shift_key) { // T
1684                                 browseFeeds();
1685                                 return false;
1686                         }
1687
1688                 }
1689
1690                 /* Prefix g */
1691
1692                 if (hotkey_prefix == 71) { // g
1693
1694                         hotkey_prefix = false;
1695
1696                         if (keycode == 49 && document.getElementById("genConfigTab")) { // 1
1697                                 selectTab("genConfig");
1698                                 return false;
1699                         }
1700
1701                         if (keycode == 50 && document.getElementById("feedConfigTab")) { // 2
1702                                 selectTab("feedConfig");
1703                                 return false;
1704                         }
1705
1706                         if (keycode == 51 && document.getElementById("filterConfigTab")) { // 4
1707                                 selectTab("filterConfig");
1708                                 return false;
1709                         }
1710
1711                         if (keycode == 52 && document.getElementById("labelConfigTab")) { // 5
1712                                 selectTab("labelConfig");
1713                                 return false;
1714                         }
1715
1716                         if (keycode == 53 && document.getElementById("userConfigTab")) { // 6
1717                                 selectTab("userConfig");
1718                                 return false;
1719                         }
1720
1721                         if (keycode == 88) { // x
1722                                 return gotoMain();
1723                         }
1724
1725                 }
1726
1727                 if (document.getElementById("piggie")) {
1728         
1729                         if (seq.match("807371717369")) {
1730                                 seq = "";
1731                                 piggie(true);
1732                         } else {
1733                                 piggie(false);
1734                         }
1735                 }
1736
1737                 if (hotkey_prefix) {
1738                         debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1739                 } else {
1740                         debug("KP: CODE=" + keycode + " CHAR=" + keychar);
1741                 }
1742
1743         } catch (e) {
1744                 exception_error("pref_hotkey_handler", e);
1745         }
1746 }
1747
1748 function editFeedCats() {
1749         if (!xmlhttp_ready(xmlhttp)) {
1750                 printLockingError();
1751                 return
1752         }
1753
1754         document.getElementById("subscribe_to_feed_btn").disabled = true;
1755
1756         try {
1757                 document.getElementById("top25_feeds_btn").disabled = true;
1758         } catch (e) {
1759                 // this button is not always available, no-op if not found
1760         }
1761
1762         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1763         xmlhttp.onreadystatechange=infobox_feed_cat_callback;
1764         xmlhttp.send(null);
1765 }
1766
1767 function showFeedsWithErrors() {
1768         displayDlg('feedUpdateErrors');
1769 }
1770
1771 function changeUserPassword() {
1772
1773         try {
1774
1775                 if (!xmlhttp_ready(xmlhttp)) {
1776                         printLockingError();
1777                         return false;
1778                 }
1779         
1780                 var f = document.forms["change_pass_form"];
1781
1782                 if (f) {
1783                         if (f.OLD_PASSWORD.value == "") {
1784                                 new Effect.Highlight(f.OLD_PASSWORD);
1785                                 notify_error("Old password cannot be blank.");
1786                                 return false;
1787                         }
1788
1789                         if (f.NEW_PASSWORD.value == "") {
1790                                 new Effect.Highlight(f.NEW_PASSWORD);
1791                                 notify_error("New password cannot be blank.");
1792                                 return false;
1793                         }
1794
1795                         if (f.CONFIRM_PASSWORD.value == "") {
1796                                 new Effect.Highlight(f.CONFIRM_PASSWORD);
1797                                 notify_error("Entered passwords do not match.");
1798                                 return false;
1799                         }
1800
1801                         if (f.CONFIRM_PASSWORD.value != f.NEW_PASSWORD.value) {
1802                                 new Effect.Highlight(f.CONFIRM_PASSWORD);
1803                                 new Effect.Highlight(f.NEW_PASSWORD);
1804                                 notify_error("Entered passwords do not match.");
1805                                 return false;
1806                         }
1807
1808                 }
1809
1810                 var query = Form.serialize("change_pass_form");
1811         
1812                 notify_progress("Trying to change password...");
1813         
1814                 xmlhttp.open("POST", "backend.php", true);
1815                 xmlhttp.onreadystatechange=changepass_callback;
1816                 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1817                 xmlhttp.send(query);
1818
1819         } catch (e) {
1820                 exception_error("changeUserPassword", e);
1821         }
1822         
1823         return false;
1824 }
1825
1826 function changeUserEmail() {
1827
1828         try {
1829
1830                 if (!xmlhttp_ready(xmlhttp)) {
1831                         printLockingError();
1832                         return false;
1833                 }
1834         
1835                 var query = Form.serialize("change_email_form");
1836         
1837                 notify_progress("Trying to change e-mail...");
1838         
1839                 xmlhttp.open("POST", "backend.php", true);
1840                 xmlhttp.onreadystatechange=notify_callback;
1841                 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1842                 xmlhttp.send(query);
1843
1844         } catch (e) {
1845                 exception_error("changeUserPassword", e);
1846         }
1847         
1848         return false;
1849
1850 }
1851
1852 function feedlistToggleSLAT() {
1853         notify_progress("Loading, please wait...");
1854         updateFeedList()
1855 }
1856
1857 function pubRegenKey() {
1858
1859         if (!xmlhttp_ready(xmlhttp)) {
1860                 printLockingError();
1861                 return false;
1862         }
1863
1864         var ok = confirm(__("Replace current publishing address with a new one?"));
1865
1866         if (ok) {
1867
1868                 notify_progress("Trying to change address...");
1869
1870                 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
1871                 xmlhttp.onreadystatechange=replace_pubkey_callback;
1872                 xmlhttp.send(null);
1873         }
1874
1875         return false;
1876 }
1877
1878 function pubToClipboard() {
1879
1880         try {
1881
1882                 if (!xmlhttp_ready(xmlhttp)) {
1883                         printLockingError();
1884                         return false;
1885                 }
1886         
1887                 var link = document.getElementById("pubGenAddress");
1888                 alert(link.href);
1889
1890         } catch (e) {
1891                 exception_error("pubToClipboard", e);
1892         }
1893
1894         return false; 
1895 }
1896
1897 function validatePrefsSave() {
1898         try {
1899
1900                 var ok = confirm(__("Save current configuration?"));
1901
1902                 if (ok) {
1903
1904                         var query = Form.serialize("pref_prefs_form");
1905                         query = query + "&subop=save-config";
1906                         debug(query);
1907
1908                         xmlhttp.open("POST", "backend.php", true);
1909                         xmlhttp.onreadystatechange=notify_callback;
1910                         xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1911                         xmlhttp.send(query);
1912                 }
1913
1914         } catch (e) {
1915                 exception_error("validatePrefsSave", e);
1916         }
1917
1918         return false;
1919 }
1920
1921 function feedActionChange() {
1922         try {
1923                 var chooser = document.getElementById("feedActionChooser");
1924                 var opid = chooser[chooser.selectedIndex].value;
1925
1926                 chooser.selectedIndex = 0;
1927                 feedActionGo(opid);
1928         } catch (e) {
1929                 exception_error("feedActionChange", e);
1930         }
1931 }
1932
1933 function feedActionGo(op) {     
1934         try {
1935                 if (op == "facEdit") {
1936
1937                         var rows = getSelectedFeeds();
1938
1939                         if (rows.length > 1) {
1940                                 editSelectedFeeds();
1941                         } else {
1942                                 editSelectedFeed();
1943                         }
1944                 }
1945
1946                 if (op == "facClear") {
1947                         clearSelectedFeeds();
1948                 }
1949
1950                 if (op == "facPurge") {
1951                         purgeSelectedFeeds();
1952                 }
1953
1954                 if (op == "facEditCats") {
1955                         editFeedCats();
1956                 }
1957
1958                 if (op == "facRescore") {
1959                         rescoreSelectedFeeds();
1960                 }
1961
1962                 if (op == "facUnsubscribe") {
1963                         removeSelectedFeeds();
1964                 }
1965
1966         } catch (e) {
1967                 exception_error("feedActionGo", e);
1968
1969         }
1970 }
1971
1972 function clearFeedArticles(feed_id) {
1973
1974         notify_progress("Clearing feed...");
1975
1976         var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
1977
1978         new Ajax.Request(query, {
1979                 onComplete: function(transport) {
1980                                 notify('');
1981                         } });
1982
1983         return false;
1984 }
1985
1986 function rescoreSelectedFeeds() {
1987
1988         if (!xmlhttp_ready(xmlhttp)) {
1989                 printLockingError();
1990                 return
1991         }
1992
1993         var sel_rows = getSelectedFeeds();
1994
1995         if (sel_rows.length > 0) {
1996
1997                 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
1998                 var ok = confirm(__("Rescore articles in selected feeds?"));
1999
2000                 if (ok) {
2001                         notify_progress("Rescoring selected feeds...", true);
2002         
2003                         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
2004                                 param_escape(sel_rows.toString()), true);
2005                         xmlhttp.onreadystatechange=notify_callback;
2006                         xmlhttp.send(null);
2007                 }
2008         } else {
2009                 alert(__("No feeds are selected."));
2010         }
2011
2012         return false;
2013 }
2014
2015 function rescore_all_feeds() {
2016                 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
2017
2018                 if (ok) {
2019                         notify_progress("Rescoring feeds...", true);
2020
2021                         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescoreAll&quiet=1", true);
2022                         xmlhttp.onreadystatechange=notify_callback;
2023                         xmlhttp.send(null);
2024                 }
2025 }
2026
2027 function removeFilter(id, title) {
2028
2029         if (!xmlhttp_ready(xmlhttp)) {
2030                 printLockingError();
2031                 return
2032         }
2033
2034         var msg = __("Remove filter %s?").replace("%s", title);
2035
2036         var ok = confirm(msg);
2037
2038         if (ok) {
2039                 closeInfoBox();
2040
2041                 notify_progress("Removing filter...");
2042         
2043                 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
2044                         param_escape(id), true);
2045                 xmlhttp.onreadystatechange=filterlist_callback;
2046                 xmlhttp.send(null);
2047         }
2048
2049         return false;
2050 }
2051
2052 function unsubscribeFeed(id, title) {
2053
2054         if (!xmlhttp_ready(xmlhttp)) {
2055                 printLockingError();
2056                 return
2057         }
2058
2059         var msg = __("Unsubscribe from %s?").replace("%s", title);
2060
2061         var ok = confirm(msg);
2062
2063         if (ok) {
2064                 closeInfoBox();
2065
2066                 notify_progress("Removing feed...");
2067         
2068                 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
2069                         param_escape(id), true);
2070                 xmlhttp.onreadystatechange=filterlist_callback;
2071                 xmlhttp.send(null);
2072         }
2073
2074         return false;
2075
2076         return false;
2077
2078 }
2079
2080 function feedsEditSave() {
2081         try {
2082
2083                 if (!xmlhttp_ready(xmlhttp)) {
2084                         printLockingError();
2085                         return
2086                 }
2087
2088                 var ok = confirm(__("Save changes to selected feeds?"));
2089
2090                 if (ok) {
2091
2092                         var f = document.forms["batch_edit_feed_form"];
2093
2094                         var query = Form.serialize("batch_edit_feed_form");
2095
2096                         /* Form.serialize ignores unchecked checkboxes */
2097
2098                         if (!query.match("&hidden=") && 
2099                                         f.hidden.disabled == false) {
2100                                 query = query + "&hidden=false";
2101                         }
2102
2103                         if (!query.match("&rtl_content=") && 
2104                                         f.rtl_content.disabled == false) {
2105                                 query = query + "&rtl_content=false";
2106                         }
2107
2108                         if (!query.match("&private=") && 
2109                                         f.private.disabled == false) {
2110                                 query = query + "&private=false";
2111                         }
2112
2113                         if (!query.match("&cache_images=") && 
2114                                         f.cache_images.disabled == false) {
2115                                 query = query + "&cache_images=false";
2116                         }
2117
2118                         if (!query.match("&include_in_digest=") && 
2119                                         f.include_in_digest.disabled == false) {
2120                                 query = query + "&include_in_digest=false";
2121                         }
2122         
2123                         closeInfoBox();
2124         
2125                         notify_progress("Saving feeds...");
2126         
2127                         xmlhttp.open("POST", "backend.php", true);
2128                         xmlhttp.onreadystatechange=feedlist_callback;
2129                         xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2130                         xmlhttp.send(query);
2131                 }
2132
2133                 return false;
2134         } catch (e) {
2135                 exception_error("feedsEditSave", e);
2136         }
2137 }
2138
2139 function batchFeedsToggleField(cb, elem, label) {
2140         try {
2141                 var f = document.forms["batch_edit_feed_form"];
2142                 var l = document.getElementById(label);
2143
2144                 if (cb.checked) {
2145                         f[elem].disabled = false;
2146
2147                         if (l) {
2148                                 l.className = "";
2149                         };
2150
2151 //                      new Effect.Highlight(f[elem], {duration: 1, startcolor: "#fff7d5",
2152 //                              queue: { position:'end', scope: 'BPEFQ', limit: 1 } } );
2153
2154                 } else {
2155                         f[elem].disabled = true;
2156
2157                         if (l) {
2158                                 l.className = "insensitive";
2159                         };
2160
2161                 }
2162         } catch (e) {
2163                 exception_error("batchFeedsToggleField", e);
2164         }
2165 }
2166
2167