]> git.wh0rd.org - tt-rss.git/blame - functions.js
set scriptWarn to invisible
[tt-rss.git] / functions.js
CommitLineData
760966c1 1var hotkeys_enabled = true;
d96d11f4 2var debug_mode_enabled = false;
a7565293
AD
3var xmlhttp_rpc = Ajax.getTransport();
4
292a8a12 5function browser_has_opacity() {
605f7d46
AD
6 return navigator.userAgent.match("Gecko") != null ||
7 navigator.userAgent.match("Opera") != null;
292a8a12
AD
8}
9
7c620da8
AD
10function is_opera() {
11 return navigator.userAgent.match("Opera");
12}
13
55160955 14function exception_error(location, e, silent) {
83f043bb
AD
15 var msg;
16
17 if (e.fileName) {
18 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
19
20 msg = "Exception: " + e.name + ", " + e.message +
21 "\nFunction: " + location + "()" +
22 "\nLocation: " + base_fname + ":" + e.lineNumber;
ee1f45f4 23
83f043bb
AD
24 } else {
25 msg = "Exception: " + e + "\nFunction: " + location + "()";
26 }
27
ee1f45f4
AD
28 debug("<b>EXCEPTION: " + msg + "</b>");
29
55160955
AD
30 if (!silent) {
31 alert(msg);
32 }
7719618b
AD
33}
34
760966c1
AD
35function disableHotkeys() {
36 hotkeys_enabled = false;
37}
38
39function enableHotkeys() {
40 hotkeys_enabled = true;
41}
42
c0e5a40e
AD
43function xmlhttp_ready(obj) {
44 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
45}
46
9cfc649a
AD
47function notify_callback() {
48 var container = document.getElementById('notify');
49 if (xmlhttp.readyState == 4) {
50 container.innerHTML=xmlhttp.responseText;
51 }
52}
53
54function rpc_notify_callback() {
55 var container = document.getElementById('notify');
56 if (xmlhttp_rpc.readyState == 4) {
57 container.innerHTML=xmlhttp_rpc.responseText;
58 }
59}
60
7726fa02
AD
61function param_escape(arg) {
62 if (typeof encodeURIComponent != 'undefined')
63 return encodeURIComponent(arg);
64 else
65 return escape(arg);
66}
67
68function param_unescape(arg) {
69 if (typeof decodeURIComponent != 'undefined')
70 return decodeURIComponent(arg);
71 else
72 return unescape(arg);
73}
74
508a81e1
AD
75function delay(gap) {
76 var then,now;
77 then=new Date().getTime();
78 now=then;
79 while((now-then)<gap) {
80 now=new Date().getTime();
81 }
82}
7726fa02 83
ce3bf408
AD
84var notify_hide_timerid = false;
85var notify_last_doc = false;
86
d05514a4 87var notify_effect = false;
59a543f0 88
ce3bf408
AD
89function hide_notify() {
90 if (notify_last_doc) {
91 var n = notify_last_doc.getElementById("notify");
d05514a4
AD
92 n.style.display = "none";
93
94/* if (browser_has_opacity()) {
ce3bf408 95 if (notify_opacity >= 0) {
0655a1d5 96 notify_opacity = notify_opacity - 0.1;
ce3bf408 97 n.style.opacity = notify_opacity;
292a8a12 98 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
ce3bf408
AD
99 } else {
100 n.style.display = "none";
292a8a12 101 n.style.opacity = 1;
ce3bf408
AD
102 }
103 } else {
104 n.style.display = "none";
d05514a4 105 } */
8dcfffd0 106 }
d05514a4 107}
c05608c2 108
0530ddd8 109function notify_real(msg, doc, no_hide, is_err) {
7726fa02 110
ce3bf408
AD
111 var n = doc.getElementById("notify");
112 var nb = doc.getElementById("notify_body");
7726fa02 113
c05608c2 114 if (!n || !nb) return;
f0601b87 115
0655a1d5
AD
116 if (notify_hide_timerid) {
117 window.clearTimeout(notify_hide_timerid);
118 }
119
120 notify_last_doc = doc;
121 notify_opacity = 1;
122
8dcfffd0 123 if (msg == "") {
0655a1d5
AD
124 if (n.style.display == "block") {
125 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
126 }
127 return;
7726fa02 128 } else {
0ceded7a 129 n.style.display = "block";
8dcfffd0 130 }
7726fa02 131
0530ddd8 132 if (is_err) {
f407c086
AD
133 n.className = "notifyError";
134// n.style.backgroundColor = "#ffcccc";
135// n.style.color = "black";
136// n.style.borderColor = "#ff0000";
0530ddd8 137 } else {
f407c086
AD
138 n.className = "notify";
139// n.style.backgroundColor = "#fff7d5";
140// n.style.borderColor = "#d7c47a";
141// n.style.color = "black";
0530ddd8
AD
142 }
143
106689b0
AD
144// msg = "<img src='images/live_com_loading.gif'> " + msg;
145
0ceded7a
AD
146 nb.innerHTML = msg;
147
4d4200a8 148 if (!no_hide) {
292a8a12 149 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 150 }
ce3bf408
AD
151}
152
0530ddd8 153function p_notify(msg, no_hide, is_err) {
9cb99906 154 notify_real(msg, document, no_hide, is_err);
ce3bf408
AD
155}
156
0530ddd8
AD
157function notify(msg, no_hide, is_err) {
158 notify_real(msg, document, no_hide, is_err);
7726fa02
AD
159}
160
508a81e1 161function printLockingError() {
f0601b87 162 notify("Please wait until operation finishes");}
508a81e1 163
13ad9102 164function hotkey_handler(e) {
760966c1 165
ee1f45f4 166 try {
2e02b896 167
ee1f45f4 168 var keycode;
d96d11f4
AD
169 var shift_key = false;
170
171 try {
172 shift_key = e.shiftKey;
173 } catch (e) {
174
175 }
ee1f45f4
AD
176
177 if (!hotkeys_enabled) return;
178
179 if (window.event) {
180 keycode = window.event.keyCode;
181 } else if (e) {
182 keycode = e.which;
183 }
d437c8cf 184
ee1f45f4 185 if (keycode == 82) { // r
0feab655 186 return scheduleFeedUpdate(true);
ee1f45f4 187 }
0a383013 188
e3612080 189 if (keycode == 83) { // s
0feab655 190 return displayDlg("search", getActiveFeedId());
0a383013
AD
191 }
192
ee1f45f4
AD
193 if (keycode == 85) { // u
194 if (getActiveFeedId()) {
0feab655 195 return viewfeed(getActiveFeedId(), "ForceUpdate");
ee1f45f4
AD
196 }
197 }
198
199 if (keycode == 65) { // a
0feab655 200 return toggleDispRead();
ee1f45f4
AD
201 }
202
0feab655 203 var feedlist = document.getElementById('feedList');
ee1f45f4
AD
204
205 if (keycode == 74) { // j
206 var feed = getActiveFeedId();
207 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
767e2486 208 if (new_feed) viewfeed(new_feed, '');
ee1f45f4
AD
209 }
210
211 if (keycode == 75) { // k
212 var feed = getActiveFeedId();
213 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
767e2486 214 if (new_feed) viewfeed(new_feed, '');
7b433d8c 215 }
9cfc649a 216
ee1f45f4 217 if (keycode == 78 || keycode == 40) { // n, down
0feab655
AD
218 if (typeof moveToPost != 'undefined') {
219 return moveToPost('next');
e59a2f12 220 }
ee1f45f4
AD
221 }
222
223 if (keycode == 80 || keycode == 38) { // p, up
0feab655
AD
224 if (typeof moveToPost != 'undefined') {
225 return moveToPost('prev');
e59a2f12 226 }
ee1f45f4
AD
227 }
228
d96d11f4
AD
229 if (keycode == 68 && shift_key) { // d
230 if (!debug_mode_enabled) {
231 document.getElementById('debug_output').style.display = 'block';
232 debug('debug mode activated');
233 } else {
234 document.getElementById('debug_output').style.display = 'none';
235 }
236
237 debug_mode_enabled = !debug_mode_enabled;
238 }
239
50a2595d
AD
240 if (keycode == 190 && shift_key) { // >
241 viewFeedGoPage(1);
242 }
243
244 if (keycode == 188 && shift_key) { // <
245 viewFeedGoPage(-1);
246 }
247
248 if (keycode == 191 && shift_key) { // ?
249 viewFeedGoPage(0);
250 }
251
e46cdbb0
AD
252 if (keycode == 69 && shift_key) {
253 return editFeedDlg(getActiveFeedId());
254 }
255
1dc8dba0
AD
256 if (typeof localHotkeyHandler != 'undefined') {
257 try {
258 return localHotkeyHandler(e);
259 } catch (e) {
260 exception_error("hotkey_handler, local:", e);
261 }
262 }
263
d96d11f4 264 debug("KP=" + keycode);
ee1f45f4
AD
265 } catch (e) {
266 exception_error("hotkey_handler", e);
267 }
13ad9102
AD
268}
269
e828e31e 270function cleanSelectedList(element) {
f0601b87
AD
271 var content = document.getElementById(element);
272
703b632e
AD
273 if (!document.getElementById("feedCatHolder")) {
274 for (i = 0; i < content.childNodes.length; i++) {
275 var child = content.childNodes[i];
d0bb308e
AD
276 try {
277 child.className = child.className.replace("Selected", "");
278 } catch (e) {
279 //
280 }
703b632e
AD
281 }
282 } else {
283 for (i = 0; i < content.childNodes.length; i++) {
284 var child = content.childNodes[i];
703b632e 285 if (child.id == "feedCatHolder") {
9cb99906 286 debug(child.id);
c3f348c2 287 var fcat = child.lastChild;
703b632e 288 for (j = 0; j < fcat.childNodes.length; j++) {
befc807f 289 var feed = fcat.childNodes[j];
703b632e
AD
290 feed.className = feed.className.replace("Selected", "");
291 }
292 }
befc807f 293 }
703b632e 294 }
e828e31e
AD
295}
296
297
298function cleanSelected(element) {
299 var content = document.getElementById(element);
f0601b87
AD
300
301 for (i = 0; i < content.rows.length; i++) {
302 content.rows[i].className = content.rows[i].className.replace("Selected", "");
303 }
f0601b87
AD
304}
305
306function getVisibleUnreadHeadlines() {
307 var content = document.getElementById("headlinesList");
308
309 var rows = new Array();
310
311 for (i = 0; i < content.rows.length; i++) {
312 var row_id = content.rows[i].id.replace("RROW-", "");
313 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
314 rows.push(row_id);
315 }
316 }
317 return rows;
318}
319
320function getVisibleHeadlineIds() {
321
322 var content = document.getElementById("headlinesList");
323
324 var rows = new Array();
325
326 for (i = 0; i < content.rows.length; i++) {
327 var row_id = content.rows[i].id.replace("RROW-", "");
328 if (row_id.length > 0) {
329 rows.push(row_id);
330 }
331 }
332 return rows;
333}
334
335function getFirstVisibleHeadlineId() {
336 var rows = getVisibleHeadlineIds();
337 return rows[0];
338}
339
340function getLastVisibleHeadlineId() {
341 var rows = getVisibleHeadlineIds();
342 return rows[rows.length-1];
343}
344
345function markHeadline(id) {
346 var row = document.getElementById("RROW-" + id);
347 if (row) {
35f3c923
AD
348 var is_active = false;
349
350 if (row.className.match("Active")) {
351 is_active = true;
352 }
353 row.className = row.className.replace("Selected", "");
354 row.className = row.className.replace("Active", "");
355 row.className = row.className.replace("Insensitive", "");
356
357 if (is_active) {
358 row.className = row.className = "Active";
359 }
360
72020095
AD
361 var check = document.getElementById("RCHK-" + id);
362
363 if (check) {
364 check.checked = true;
365 }
366
35f3c923
AD
367 row.className = row.className + "Selected";
368
f0601b87
AD
369 }
370}
371
372function getFeedIds() {
373 var content = document.getElementById("feedsList");
374
375 var rows = new Array();
376
377 for (i = 0; i < content.rows.length; i++) {
378 var id = content.rows[i].id.replace("FEEDR-", "");
379 if (id.length > 0) {
380 rows.push(id);
381 }
382 }
383
384 return rows;
385}
13ad9102 386
76b4eae1
AD
387function setCookie(name, value, lifetime, path, domain, secure) {
388
389 var d = false;
390
391 if (lifetime) {
392 d = new Date();
393 d.setTime(lifetime * 1000);
394 }
395
396 int_setCookie(name, value, d, path, domain, secure);
397
398}
399
400function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
401 document.cookie= name + "=" + escape(value) +
402 ((expires) ? "; expires=" + expires.toGMTString() : "") +
403 ((path) ? "; path=" + path : "") +
404 ((domain) ? "; domain=" + domain : "") +
405 ((secure) ? "; secure" : "");
406}
407
76b4eae1
AD
408function delCookie(name, path, domain) {
409 if (getCookie(name)) {
410 document.cookie = name + "=" +
411 ((path) ? ";path=" + path : "") +
412 ((domain) ? ";domain=" + domain : "" ) +
413 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
414 }
415}
416
417
ac43eba1
AD
418function getCookie(name) {
419
420 var dc = document.cookie;
421 var prefix = name + "=";
422 var begin = dc.indexOf("; " + prefix);
423 if (begin == -1) {
424 begin = dc.indexOf(prefix);
425 if (begin != 0) return null;
426 }
427 else {
428 begin += 2;
429 }
430 var end = document.cookie.indexOf(";", begin);
431 if (end == -1) {
432 end = dc.length;
433 }
434 return unescape(dc.substring(begin + prefix.length, end));
435}
436
1a66d16e
AD
437function disableContainerChildren(id, disable, doc) {
438
439 if (!doc) doc = document;
440
441 var container = doc.getElementById(id);
ac43eba1 442
4220b0bd
AD
443 if (!container) {
444 //alert("disableContainerChildren: element " + id + " not found");
445 return;
446 }
447
ac43eba1
AD
448 for (var i = 0; i < container.childNodes.length; i++) {
449 var child = container.childNodes[i];
450
d5224f0d
AD
451 try {
452 child.disabled = disable;
453 } catch (E) {
454
455 }
ac43eba1
AD
456
457 if (disable) {
458 if (child.className && child.className.match("button")) {
459 child.className = "disabledButton";
460 }
461 } else {
462 if (child.className && child.className.match("disabledButton")) {
463 child.className = "button";
464 }
d5224f0d 465 }
ac43eba1
AD
466 }
467
468}
7726fa02 469
e828e31e
AD
470function gotoPreferences() {
471 document.location.href = "prefs.php";
472}
473
474function gotoMain() {
475 document.location.href = "tt-rss.php";
476}
477
8158c57a
AD
478function gotoExportOpml() {
479 document.location.href = "opml.php?op=Export";
480}
86741347
AD
481
482function getActiveFeedId() {
33d13e72
AD
483// return getCookie("ttrss_vf_actfeed");
484 try {
0feab655
AD
485 debug("gAFID: " + active_feed_id);
486 return active_feed_id;
33d13e72
AD
487 } catch (e) {
488 exception_error("getActiveFeedId", e);
489 }
86741347
AD
490}
491
0a6c4846 492function activeFeedIsCat() {
0feab655 493 return active_feed_is_cat;
0a6c4846
AD
494}
495
86741347 496function setActiveFeedId(id) {
33d13e72
AD
497// return setCookie("ttrss_vf_actfeed", id);
498 try {
5c365f60 499 debug("sAFID(" + id + ")");
0feab655 500 active_feed_id = id;
33d13e72
AD
501 } catch (e) {
502 exception_error("setActiveFeedId", e);
503 }
86741347 504}
090e250b 505
ac378ad4 506function parse_counters(reply, scheduled_call) {
1a6a9555 507 try {
ac378ad4 508
9e397d0f
AD
509 var feeds_found = 0;
510
f54f515f
AD
511 if (reply.firstChild && reply.firstChild.firstChild) {
512 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
513 reply = reply.firstChild;
514 }
515
1a6a9555 516 for (var l = 0; l < reply.childNodes.length; l++) {
9cbca41f
AD
517 if (!reply.childNodes[l] ||
518 typeof(reply.childNodes[l].getAttribute) == "undefined") {
6043fb7e
AD
519 // where did this come from?
520 continue;
521 }
522
1a6a9555
AD
523 var id = reply.childNodes[l].getAttribute("id");
524 var t = reply.childNodes[l].getAttribute("type");
525 var ctr = reply.childNodes[l].getAttribute("counter");
023fe037
AD
526 var error = reply.childNodes[l].getAttribute("error");
527 var has_img = reply.childNodes[l].getAttribute("hi");
fb1fb4ab 528 var updated = reply.childNodes[l].getAttribute("updated");
1a6a9555
AD
529
530 if (id == "global-unread") {
0feab655
AD
531 global_unread = ctr;
532 updateTitle();
1a6a9555
AD
533 continue;
534 }
7bf7e4d3
AD
535
536 if (id == "subscribed-feeds") {
537 feeds_found = ctr;
538 continue;
539 }
1a6a9555
AD
540
541 if (t == "category") {
0feab655 542 var catctr = document.getElementById("FCATCTR-" + id);
1a6a9555 543 if (catctr) {
67dabe1a
AD
544 catctr.innerHTML = "(" + ctr + ")";
545 if (ctr > 0) {
546 catctr.className = "catCtrHasUnread";
547 } else {
548 catctr.className = "catCtrNoUnread";
549 }
1a6a9555
AD
550 }
551 continue;
552 }
553
0feab655
AD
554 var feedctr = document.getElementById("FEEDCTR-" + id);
555 var feedu = document.getElementById("FEEDU-" + id);
556 var feedr = document.getElementById("FEEDR-" + id);
557 var feed_img = document.getElementById("FIMG-" + id);
558 var feedlink = document.getElementById("FEEDL-" + id);
559 var feedupd = document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
560
561 if (updated && feedlink) {
562 if (error) {
563 feedlink.title = "Error: " + error + " (" + updated + ")";
564 } else {
565 feedlink.title = "Updated: " + updated;
566 }
567 }
023fe037 568
78d5212c
AD
569 if (updated && feedupd) {
570 if (error) {
571 feedupd.innerHTML = updated + " (Error)";
572 } else {
573 feedupd.innerHTML = updated;
574 }
575 }
576
1a6a9555 577 if (feedctr && feedu && feedr) {
e8ef3b97
AD
578
579 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
5b064721 580 viewCurrentFeed();
e8ef3b97 581 }
1a6a9555
AD
582
583 feedu.innerHTML = ctr;
023fe037 584
426d3c57
AD
585 if (error) {
586 feedr.className = feedr.className.replace("feed", "error");
587 } else if (id > 0) {
588 feedr.className = feedr.className.replace("error", "feed");
023fe037 589 }
1a6a9555
AD
590
591 if (ctr > 0) {
592 feedctr.className = "odd";
593 if (!feedr.className.match("Unread")) {
594 var is_selected = feedr.className.match("Selected");
595
596 feedr.className = feedr.className.replace("Selected", "");
597 feedr.className = feedr.className.replace("Unread", "");
598
599 feedr.className = feedr.className + "Unread";
600
601 if (is_selected) {
602 feedr.className = feedr.className + "Selected";
603 }
604
605 }
606 } else {
607 feedctr.className = "invisible";
608 feedr.className = feedr.className.replace("Unread", "");
609 }
610 }
611 }
9e397d0f 612
0feab655 613 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
7553dd8b 614
0feab655 615 var feeds_stored = number_of_feeds;
9e397d0f
AD
616
617 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
618
619 if (feeds_stored != feeds_found) {
0feab655 620 number_of_feeds = feeds_found;
7bf7e4d3
AD
621
622 if (feeds_stored != 0) {
9e397d0f 623 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 624 setTimeout('updateFeedList(false, false)', 50);
9e397d0f
AD
625 }
626 }
627
1a6a9555 628 } catch (e) {
83f043bb 629 exception_error("parse_counters", e);
1a6a9555
AD
630 }
631}
632
3ac2f3c7 633function parse_counters_reply(xmlhttp, scheduled_call) {
5854573a
AD
634
635 if (!xmlhttp.responseXML) {
636 notify("refetch_callback: backend did not return valid XML", true, true);
637 return;
638 }
639
640 var reply = xmlhttp.responseXML.firstChild;
641
642 if (!reply) {
643 notify("refetch_callback: backend did not return expected XML object", true, true);
644 updateTitle("");
645 return;
646 }
647
648 var error_code = false;
649 var error_msg = false;
650
651 if (reply.firstChild) {
652 error_code = reply.firstChild.getAttribute("error-code");
653 error_msg = reply.firstChild.getAttribute("error-msg");
654 }
655
656 if (!error_code) {
657 error_code = reply.getAttribute("error-code");
658 error_msg = reply.getAttribute("error-msg");
659 }
660
661 if (error_code && error_code != 0) {
662 debug("refetch_callback: got error code " + error_code);
663 return fatalError(error_code, error_msg);
664 }
665
666 var counters = reply.firstChild;
667
3ac2f3c7 668 parse_counters(counters, scheduled_call);
5854573a
AD
669
670 var runtime_info = counters.nextSibling;
671
672 parse_runtime_info(runtime_info);
673
674 if (getInitParam("feeds_sort_by_unread") == 1) {
675 resort_feedlist();
676 }
677
678 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
679
680}
681
4f3a84f4 682function all_counters_callback() {
090e250b 683 if (xmlhttp_rpc.readyState == 4) {
7719618b 684 try {
5854573a 685/* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
b00ed196 686 debug("[all_counters_callback] backend did not return valid XML");
7719618b
AD
687 return;
688 }
894ebcf5 689
6b4163cb 690 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
1cb7492d 691
7719618b 692 var reply = xmlhttp_rpc.responseXML.firstChild;
280ee9a3 693
f54f515f
AD
694 var counters = reply.firstChild;
695
696 parse_counters(counters);
1cb7492d
AD
697
698 var runtime = counters.nextSibling;
699
700 if (runtime) {
0feab655 701 parse_runtime_info(runtime);
1cb7492d 702 }
c9268ed5 703
cea51014 704 if (getInitParam("feeds_sort_by_unread") == 1) {
c9268ed5
AD
705 resort_feedlist();
706 }
293fa942 707
5854573a
AD
708 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
709
710 debug("in all_counters_callback");
711
712 parse_counters_reply(xmlhttp_rpc);
293fa942 713
7719618b
AD
714 } catch (e) {
715 exception_error("all_counters_callback", e);
090e250b
AD
716 }
717 }
718}
719
c9268ed5
AD
720function get_feed_entry_unread(doc, elem) {
721
722 var id = elem.id.replace("FEEDR-", "");
723
724 if (id <= 0) {
725 return -1;
726 }
727
728 try {
729 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
730 } catch (e) {
731 return -1;
732 }
733}
734
735function resort_category(doc, node) {
736 debug("resort_category: " + node);
737
738 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
739 for (i = 0; i < node.childNodes.length; i++) {
740 if (node.childNodes[i].nodeName != "LI") { continue; }
741
742 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
743 continue;
744 }
745
746 for (j = i+1; j < node.childNodes.length; j++) {
747 if (node.childNodes[j].nodeName != "LI") { continue; }
748
749 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
750 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
751
752 if (cur_val > tmp_val) {
753 tempnode_i = node.childNodes[i].cloneNode(true);
754 tempnode_j = node.childNodes[j].cloneNode(true);
755 node.replaceChild(tempnode_i, node.childNodes[j]);
756 node.replaceChild(tempnode_j, node.childNodes[i]);
757 }
758 }
759
760 }
761 }
762
763}
764
765function resort_feedlist() {
766 debug("resort_feedlist");
767
0feab655 768 var fd = document;
c9268ed5
AD
769
770 if (fd.getElementById("feedCatHolder")) {
771
772 var feeds = fd.getElementById("feedList");
773 var child = feeds.firstChild;
774
775 while (child) {
776
777 if (child.id == "feedCatHolder") {
778 resort_category(fd, child.firstChild);
779 }
780
781 child = child.nextSibling;
782 }
783
784 } else {
785 resort_category(fd, fd.getElementById("feedList"));
786 }
787}
788
4f3a84f4 789function update_all_counters(feed) {
090e250b 790 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 791 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
792
793 if (feed > 0) {
794 query = query + "&aid=" + feed;
795 }
796
cf4d339c
AD
797 if (tagsAreDisplayed()) {
798 query = query + "&omode=lt";
3fd7138f
AD
799 } else {
800 query = query + "&omode=flc";
cf4d339c
AD
801 }
802
803 debug("update_all_counters QUERY: " + query);
804
86173d9a
AD
805 var date = new Date();
806 var timestamp = Math.round(date.getTime() / 1000);
807 query = query + "&ts=" + timestamp
808
090e250b 809 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 810 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
811 xmlhttp_rpc.send(null);
812 }
813}
7dc66a61
AD
814
815function popupHelp(tid) {
816 var w = window.open("backend.php?op=help&tid=" + tid,
817 "Popup Help",
818 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
819}
b6644d29
AD
820
821/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
822 * * @author Sundar Dorai-Raj
823 * * Email: sdoraira@vt.edu
824 * * This program is free software; you can redistribute it and/or
825 * * modify it under the terms of the GNU General Public License
826 * * as published by the Free Software Foundation; either version 2
827 * * of the License, or (at your option) any later version,
828 * * provided that any use properly credits the author.
829 * * This program is distributed in the hope that it will be useful,
830 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
831 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
832 * * GNU General Public License for more details at http://www.gnu.org * * */
833
834 var numbers=".0123456789";
835 function isNumeric(x) {
836 // is x a String or a character?
837 if(x.length>1) {
838 // remove negative sign
839 x=Math.abs(x)+"";
840 for(j=0;j<x.length;j++) {
841 // call isNumeric recursively for each character
842 number=isNumeric(x.substring(j,j+1));
843 if(!number) return number;
844 }
845 return number;
846 }
847 else {
848 // if x is number return true
849 if(numbers.indexOf(x)>=0) return true;
850 return false;
851 }
852 }
853
3745788e
AD
854
855function hideOrShowFeeds(doc, hide) {
856
7553dd8b
AD
857 debug("hideOrShowFeeds: " + doc + ", " + hide);
858
0feab655 859 var fd = document;
293fa942
AD
860
861 var list = fd.getElementById("feedList");
862
863 if (fd.getElementById("feedCatHolder")) {
864
865 var feeds = fd.getElementById("feedList");
866 var child = feeds.firstChild;
867
868 while (child) {
869
870 if (child.id == "feedCatHolder") {
871 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
872 }
873
874 child = child.nextSibling;
875 }
876
877 } else {
878 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
879 }
880}
881
882function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
883
884// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 885
293fa942 886 var cat_unread = 0;
3745788e 887
4724a093
AD
888 if (!node) {
889 debug("hideOrShowFeeds: passed node is null, aborting");
890 return;
891 }
892
293fa942
AD
893 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
894 for (i = 0; i < node.childNodes.length; i++) {
895 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 896
b31c2311 897 if (node.childNodes[i].style != undefined) {
293fa942 898
b31c2311
AD
899 var has_unread = (node.childNodes[i].className != "feed");
900
901 // debug(node.childNodes[i].id + " --> " + has_unread);
902
903 if (hide && !has_unread) {
904 node.childNodes[i].style.display = "none";
905 }
906
907 if (!hide) {
908 node.childNodes[i].style.display = "list-item";
909 }
910
911 if (has_unread) {
7553dd8b 912 node.childNodes[i].style.display = "list-item";
b31c2311
AD
913 cat_unread++;
914 }
293fa942 915 }
3745788e 916 }
b31c2311 917 }
3745788e 918
293fa942 919 if (cat_unread == 0) {
b31c2311
AD
920 if (cat_node.style == undefined) {
921 debug("ERROR: supplied cat_node " + cat_node +
922 " has no styles. WTF?");
923 return;
924 }
293fa942
AD
925 if (hide) {
926 cat_node.style.display = "none";
927 } else {
928 cat_node.style.display = "list-item";
929 }
7553dd8b 930 } else {
0ac2faea
AD
931 try {
932 cat_node.style.display = "list-item";
933 } catch (e) {
934 debug(e);
935 }
293fa942 936 }
3745788e 937
293fa942 938// debug("unread for category: " + cat_unread);
3745788e
AD
939}
940
35f3c923
AD
941function selectTableRow(r, do_select) {
942 r.className = r.className.replace("Selected", "");
943
944 if (do_select) {
945 r.className = r.className + "Selected";
946 }
947}
948
6c12c809
AD
949function selectTableRowById(elem_id, check_id, do_select) {
950
951 try {
952
953 var row = document.getElementById(elem_id);
954
955 if (row) {
956 selectTableRow(row, do_select);
957 }
958
959 var check = document.getElementById(check_id);
960
961 if (check) {
962 check.checked = do_select;
963 }
964 } catch (e) {
965 exception_error("selectTableRowById", e);
966 }
967}
968
1572afe5 969function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 970 classcheck, reset_others) {
3745788e 971
35f3c923
AD
972 var content = document.getElementById(content_id);
973
974 if (!content) {
975 alert("[selectTableRows] Element " + content_id + " not found.");
976 return;
977 }
978
979 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
980 if (!classcheck || content.rows[i].className.match(classcheck)) {
981
982 if (content.rows[i].id.match(prefix)) {
983 selectTableRow(content.rows[i], do_select);
649e0af9
AD
984
985 var row_id = content.rows[i].id.replace(prefix, "");
986 var check = document.getElementById(check_prefix + row_id);
3055bc41 987
649e0af9
AD
988 if (check) {
989 check.checked = do_select;
990 }
991 } else if (reset_others) {
992 selectTableRow(content.rows[i], false);
7d8d10c6
AD
993
994 var row_id = content.rows[i].id.replace(prefix, "");
995 var check = document.getElementById(check_prefix + row_id);
996
997 if (check) {
998 check.checked = false;
999 }
1000
1572afe5 1001 }
649e0af9
AD
1002 } else if (reset_others) {
1003 selectTableRow(content.rows[i], false);
7d8d10c6
AD
1004
1005 var row_id = content.rows[i].id.replace(prefix, "");
1006 var check = document.getElementById(check_prefix + row_id);
1007
1008 if (check) {
1009 check.checked = false;
1010 }
1011
3055bc41 1012 }
35f3c923 1013 }
295f9b42 1014}
91ff844a
AD
1015
1016function getSelectedTableRowIds(content_id, prefix) {
1017
1018 var content = document.getElementById(content_id);
1019
1020 if (!content) {
1021 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
1022 return;
1023 }
1024
1025 var sel_rows = new Array();
1026
1027 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
1028 if (content.rows[i].id.match(prefix) &&
1029 content.rows[i].className.match("Selected")) {
1030
91ff844a
AD
1031 var row_id = content.rows[i].id.replace(prefix + "-", "");
1032 sel_rows.push(row_id);
1033 }
1034 }
1035
1036 return sel_rows;
1037
1038}
1039
386cbf27
AD
1040function toggleSelectRowById(sender, id) {
1041 var row = document.getElementById(id);
1042
1043 if (sender.checked) {
1044 if (!row.className.match("Selected")) {
1045 row.className = row.className + "Selected";
1046 }
1047 } else {
1048 if (row.className.match("Selected")) {
1049 row.className = row.className.replace("Selected", "");
1050 }
1051 }
1052}
1053
b92e6209
AD
1054function toggleSelectListRow(sender) {
1055 var parent_row = sender.parentNode;
1056
1057 if (sender.checked) {
1058 if (!parent_row.className.match("Selected")) {
1059 parent_row.className = parent_row.className + "Selected";
1060 }
1061 } else {
1062 if (parent_row.className.match("Selected")) {
1063 parent_row.className = parent_row.className.replace("Selected", "");
1064 }
1065 }
1066}
1067
386cbf27 1068
1572afe5
AD
1069function toggleSelectRow(sender) {
1070 var parent_row = sender.parentNode.parentNode;
1071
1072 if (sender.checked) {
1073 if (!parent_row.className.match("Selected")) {
1074 parent_row.className = parent_row.className + "Selected";
1075 }
1076 } else {
1077 if (parent_row.className.match("Selected")) {
1078 parent_row.className = parent_row.className.replace("Selected", "");
1079 }
1080 }
1081}
1082
3866b046
AD
1083function openExternalUrl(url) {
1084 var w = window.open(url);
1085}
1572afe5 1086
1da76274 1087function getRelativeFeedId(list, id, direction, unread_only) {
7b433d8c
AD
1088 if (!id) {
1089 if (direction == "next") {
1090 for (i = 0; i < list.childNodes.length; i++) {
1091 var child = list.childNodes[i];
1da76274 1092 if (child.id && child.id == "feedCatHolder") {
c3f348c2 1093 if (child.lastChild) {
d05514a4 1094 var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only);
7b433d8c
AD
1095 if (cr) return cr;
1096 }
1da76274 1097 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
1098 return child.id.replace('FEEDR-', '');
1099 }
1100 }
1101 }
1102
1103 // FIXME select last feed doesn't work when only unread feeds are visible
1104
1105 if (direction == "prev") {
1106 for (i = list.childNodes.length-1; i >= 0; i--) {
1107 var child = list.childNodes[i];
1108 if (child.id == "feedCatHolder") {
1109 if (child.firstChild) {
1110 var cr = getRelativeFeedId(child.firstChild, id, direction);
1111 if (cr) return cr;
1112 }
1113 } else if (child.id.match("FEEDR-")) {
1114
e8bd0da9 1115 if (getInitParam("hide_read_feeds") == 1) {
7b433d8c
AD
1116 if (child.className != "feed") {
1117 alert(child.className);
1118 return child.id.replace('FEEDR-', '');
1119 }
1120 } else {
1121 return child.id.replace('FEEDR-', '');
1122 }
1123 }
1124 }
1125 }
1126 } else {
1127
d05514a4 1128 var feed = list.ownerDocument.getElementById("FEEDR-" + id);
7b433d8c 1129
e8bd0da9 1130 if (getInitParam("hide_read_feeds") == 1) {
1da76274
AD
1131 unread_only = true;
1132 }
1133
7b433d8c
AD
1134 if (direction == "next") {
1135
1da76274 1136 var e = feed;
7b433d8c 1137
1da76274 1138 while (e) {
7b433d8c 1139
1da76274
AD
1140 if (e.nextSibling) {
1141
1142 e = e.nextSibling;
1143
1144 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 1145
1da76274 1146 var this_cat = e.parentNode.parentNode;
7b433d8c 1147
1da76274 1148 e = false;
7b433d8c 1149
1da76274
AD
1150 if (this_cat && this_cat.nextSibling) {
1151 while (!e && this_cat.nextSibling) {
1152 this_cat = this_cat.nextSibling;
1153 if (this_cat.id == "feedCatHolder") {
1154 e = this_cat.firstChild.firstChild;
7b433d8c
AD
1155 }
1156 }
7b433d8c 1157 }
1da76274
AD
1158
1159 } else {
1160 e = false;
1161 }
1162
1163 if (e) {
d05514a4 1164 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1165 e.className.match("feed"))) {
1da76274
AD
1166 return e.id.replace("FEEDR-", "");
1167 }
1168 }
7b433d8c 1169 }
1da76274 1170
7b433d8c
AD
1171 } else if (direction == "prev") {
1172
1da76274 1173 var e = feed;
7b433d8c 1174
1da76274 1175 while (e) {
7b433d8c 1176
1da76274
AD
1177 if (e.previousSibling) {
1178
1179 e = e.previousSibling;
1180
1181 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 1182
1da76274 1183 var this_cat = e.parentNode.parentNode;
7b433d8c 1184
1da76274
AD
1185 e = false;
1186
1187 if (this_cat && this_cat.previousSibling) {
1188 while (!e && this_cat.previousSibling) {
1189 this_cat = this_cat.previousSibling;
1190 if (this_cat.id == "feedCatHolder") {
1191 e = this_cat.firstChild.lastChild;
7b433d8c
AD
1192 }
1193 }
7b433d8c 1194 }
1da76274
AD
1195
1196 } else {
1197 e = false;
1198 }
1199
1200 if (e) {
e686782e 1201 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1202 e.className.match("feed"))) {
1da76274
AD
1203 return e.id.replace("FEEDR-", "");
1204 }
1205 }
1206 }
7b433d8c
AD
1207 }
1208 }
1209}
36aab70f
AD
1210
1211function showBlockElement(id) {
1212 var elem = document.getElementById(id);
1213
1214 if (elem) {
1215 elem.style.display = "block";
1216 } else {
1217 alert("[showBlockElement] can't find element with id " + id);
1218 }
1219}
1220
a9b0bfd5
AD
1221function hideParentElement(e) {
1222 e.parentNode.style.display = "none";
1223}
1b0809ae
AD
1224
1225function dropboxSelect(e, v) {
1226 for (i = 0; i < e.length; i++) {
1227 if (e[i].value == v) {
1228 e.selectedIndex = i;
1229 break;
1230 }
1231 }
1232}
0ee1d1a0
AD
1233
1234// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1235// bugfixed just a little bit :-)
1236function getURLParam(strParamName){
1237 var strReturn = "";
1238 var strHref = window.location.href;
1239
1240 if (strHref.indexOf("#") == strHref.length-1) {
1241 strHref = strHref.substring(0, strHref.length-1);
1242 }
1243
1244 if ( strHref.indexOf("?") > -1 ){
1245 var strQueryString = strHref.substr(strHref.indexOf("?"));
1246 var aQueryString = strQueryString.split("&");
1247 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1248 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1249 var aParam = aQueryString[iParam].split("=");
1250 strReturn = aParam[1];
1251 break;
1252 }
1253 }
1254 }
1255 return strReturn;
1256}
1257
cf1bc085
AD
1258function leading_zero(p) {
1259 var s = String(p);
1260 if (s.length == 1) s = "0" + s;
1261 return s;
1262}
c38c2b69 1263
86b682ce 1264function closeInfoBox(cleanup) {
e5d758e3
AD
1265 var box = document.getElementById('infoBox');
1266 var shadow = document.getElementById('infoBoxShadow');
1267
1268 if (shadow) {
1269 shadow.style.display = "none";
1270 } else if (box) {
1271 box.style.display = "none";
1272 }
1273
86b682ce
AD
1274 if (cleanup) box.innerHTML = "&nbsp;";
1275
e5d758e3 1276 enableHotkeys();
c14b5566 1277
90ac84df 1278 return false;
e5d758e3
AD
1279}
1280
1281
7b5c6012
AD
1282function displayDlg(id, param) {
1283
1284 if (!xmlhttp_ready(xmlhttp)) {
1285 printLockingError();
1286 return
1287 }
1288
1289 notify("");
1290
1291 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1292 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 1293 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
1294 xmlhttp.send(null);
1295
1296 disableHotkeys();
2371c520 1297
90ac84df 1298 return false;
7b5c6012
AD
1299}
1300
e5d758e3 1301function infobox_submit_callback() {
7b5c6012 1302 if (xmlhttp.readyState == 4) {
e5d758e3 1303 closeInfoBox();
7b5c6012 1304
6e6504bc
AD
1305 try {
1306 // called from prefs, reload tab
1307 if (active_tab) {
1308 selectTab(active_tab, false);
1309 }
1310 } catch (e) { }
79f3553b
AD
1311
1312 notify(xmlhttp.responseText);
1313
7b5c6012
AD
1314 }
1315}
1316
e5d758e3 1317function infobox_callback() {
7b5c6012 1318 if (xmlhttp.readyState == 4) {
e5d758e3
AD
1319 var box = document.getElementById('infoBox');
1320 var shadow = document.getElementById('infoBoxShadow');
1321 if (box) {
1322 box.innerHTML=xmlhttp.responseText;
1323 if (shadow) {
1324 shadow.style.display = "block";
1325 } else {
1326 box.style.display = "block";
1327 }
1328 }
9c483746 1329 notify("");
e5d758e3 1330 }
7b5c6012
AD
1331}
1332
1333function qaddFilter() {
1334
1335 if (!xmlhttp_ready(xmlhttp)) {
1336 printLockingError();
1337 return
1338 }
1339
c91c2249
AD
1340 var form = document.forms['filter_add_form'];
1341 var reg_exp = form.reg_exp.value;
1342
1343 if (reg_exp == "") {
1344 alert("Can't add filter: nothing to match on.");
1345 return false;
1346 }
1347
79f3553b 1348 var query = Form.serialize("filter_add_form");
7b5c6012 1349
79f3553b
AD
1350 xmlhttp.open("GET", "backend.php?" + query, true);
1351 xmlhttp.onreadystatechange=infobox_submit_callback;
1352 xmlhttp.send(null);
7b5c6012 1353
c14b5566 1354 return true;
7b5c6012
AD
1355}
1356
2371c520
AD
1357function toggleSubmitNotEmpty(e, submit_id) {
1358 try {
1359 document.getElementById(submit_id).disabled = (e.value == "")
1360 } catch (e) {
1361 exception_error("toggleSubmitNotEmpty", e);
1362 }
1363}
1d7bf5a0 1364
605f7d46
AD
1365function isValidURL(s) {
1366 return s.match("http://") != null || s.match("https://") != null;
1367}
07eb9178
AD
1368
1369function qafAdd() {
1370
1371 if (!xmlhttp_ready(xmlhttp)) {
1372 printLockingError();
1373 return
1374 }
1375
c91c2249
AD
1376 var form = document.forms['feed_add_form'];
1377 var feed_url = form.feed_url.value;
1378
1379 if (feed_url == "") {
1380 alert("Can't subscribe: no feed URL given.");
1381 return false;
1382 }
1383
a58d997c 1384 notify("Adding feed...", true);
07eb9178
AD
1385
1386 closeInfoBox();
1387
0feab655 1388 var feeds_doc = document;
07eb9178 1389
80e4dc34 1390// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1391
1392 var query = Form.serialize("feed_add_form");
1393
1394 xmlhttp.open("GET", "backend.php?" + query, true);
1395 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1396 xmlhttp.send(null);
7bc4f251
AD
1397
1398 return false;
07eb9178
AD
1399}
1400
6e6504bc 1401function filterCR(e, f)
86b682ce
AD
1402{
1403 var key;
1404
1405 if(window.event)
1406 key = window.event.keyCode; //IE
1407 else
1408 key = e.which; //firefox
1409
6e6504bc
AD
1410 if (key == 13) {
1411 if (typeof f != 'undefined') {
1412 f();
1413 return false;
1414 } else {
1415 return false;
1416 }
1417 } else {
1418 return true;
1419 }
86b682ce
AD
1420}
1421
ac378ad4 1422function getMainContext() {
6b4163cb 1423 return this.window;
ac378ad4
AD
1424}
1425
33d13e72 1426function getFeedsContext() {
6b4163cb 1427 return this.window;
33d13e72
AD
1428}
1429
0bd411db 1430function getContentContext() {
6b4163cb 1431 return this.window;
0bd411db
AD
1432}
1433
ee1f45f4 1434function getHeadlinesContext() {
6b4163cb 1435 return this.window;
ee1f45f4
AD
1436}
1437
e8614131
AD
1438var debug_last_class = "even";
1439
ac378ad4 1440function debug(msg) {
ac378ad4 1441
0feab655
AD
1442 if (debug_last_class == "even") {
1443 debug_last_class = "odd";
e8614131 1444 } else {
0feab655 1445 debug_last_class = "even";
e8614131
AD
1446 }
1447
0feab655 1448 var c = document.getElementById('debug_output');
ac378ad4 1449 if (c && c.style.display == "block") {
c9268ed5 1450 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1451 c.removeChild(c.lastChild);
1452 }
1453
1454 var d = new Date();
1455 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1456 ":" + leading_zero(d.getSeconds());
0feab655 1457 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1458 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1459 }
1460}
1461
33d13e72
AD
1462function getInitParam(key) {
1463 return getMainContext().init_params[key];
1464}
3ac2b520 1465
e8bd0da9 1466function storeInitParam(key, value, is_client) {
33d13e72 1467 try {
e8bd0da9 1468 if (!is_client) {
1035fcec
AD
1469 if (getMainContext().init_params[key] != value) {
1470 debug("storeInitParam: " + key + " => " + value);
0b7cb301
AD
1471 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1472 // param_escape(key) + "&value=" + param_escape(value));
1473 var f = getMainContext().document.getElementById("backReqBox");
1474 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1475 param_escape(key) + "&value=" + param_escape(value);
1035fcec 1476 }
e8bd0da9 1477 }
1035fcec 1478 getMainContext().init_params[key] = value;
33d13e72
AD
1479 } catch (e) {
1480 exception_error("storeInitParam", e);
1481 }
1482}
a7565293 1483
1035fcec
AD
1484/*
1485function storeInitParams(params, is_client) {
1486 try {
1487 var s = "";
1488
1489 for (k in params) {
1490 if (getMainContext().init_params[k] != params[k]) {
1491 s += k + "=" + params[k] + ";";
1492 getMainContext().init_params[k] = params[k];
1493 }
1494 }
1495
1496 debug("storeInitParams: " + s);
1497
1498 if (!is_client) {
1499 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1500 }
1501 } catch (e) {
1502 exception_error("storeInitParams", e);
1503 }
1504}*/
1505
a7565293
AD
1506function fatalError(code, message) {
1507 try {
a7565293 1508
4724a093 1509 if (code != 6) {
a7565293 1510
4724a093
AD
1511 var fe = document.getElementById("fatal_error");
1512 var fc = document.getElementById("fatal_error_msg");
1513
1514 fc.innerHTML = "Code " + code + ": " + message;
1515
1516 fe.style.display = "block";
1517 } else {
1518 window.location.href = "login.php?rt=none";
1519 }
a7565293
AD
1520
1521 } catch (e) {
1522 exception_error("fatalError", e);
1523 }
1524}
1525
234e467c 1526function getFeedName(id, is_cat) {
64a2875d 1527 var d = getFeedsContext().document;
234e467c
AD
1528
1529 var e;
1530
1531 if (is_cat) {
1532 e = d.getElementById("FCATN-" + id);
1533 } else {
1534 e = d.getElementById("FEEDN-" + id);
1535 }
64a2875d
AD
1536 if (e) {
1537 return e.innerHTML.stripTags();
1538 } else {
1539 return null;
1540 }
1541}
0bd411db
AD
1542
1543function viewContentUrl(url) {
1544 getContentContext().location = url;
1545}
350f0ad1
AD
1546
1547function filterDlgCheckAction(sender) {
1548
1549 try {
1550
1551 var action = sender[sender.selectedIndex].value;
1552
1553 var form = document.forms["filter_add_form"];
1554
1555 if (!form) {
1556 form = document.forms["filter_edit_form"];
1557 }
1558
1559 if (!form) {
1560 debug("filterDlgCheckAction: can't find form!");
1561 return;
1562 }
1563
1564 var action_param = form.action_param;
1565
1566 if (!action_param) {
1567 debug("filterDlgCheckAction: can't find action param!");
1568 return;
1569 }
1570
1571 // if selected action supports parameters, enable params field
1572 if (action == 4) {
1573 action_param.disabled = false;
1574 } else {
1575 action_param.disabled = true;
1576 }
1577
1578 } catch (e) {
1579 exception_error(e, "filterDlgCheckAction");
1580 }
1581
1582}
ef16ae37
AD
1583
1584function explainError(code) {
1585 return displayDlg("explainError", code);
1586}