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