]> git.wh0rd.org - tt-rss.git/blob - functions.js
getFeedCat respects NULL cat_id
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2
3 function browser_has_opacity() {
4 return navigator.userAgent.match("Gecko") != null ||
5 navigator.userAgent.match("Opera") != null;
6 }
7
8 function exception_error(location, e) {
9 var msg;
10
11 if (e.fileName) {
12 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
13
14 msg = "Exception: " + e.name + ", " + e.message +
15 "\nFunction: " + location + "()" +
16 "\nLocation: " + base_fname + ":" + e.lineNumber;
17 } else {
18 msg = "Exception: " + e + "\nFunction: " + location + "()";
19 }
20
21 alert(msg);
22 }
23
24 function disableHotkeys() {
25 hotkeys_enabled = false;
26 }
27
28 function enableHotkeys() {
29 hotkeys_enabled = true;
30 }
31
32 function xmlhttp_ready(obj) {
33 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
34 }
35
36 function notify_callback() {
37 var container = document.getElementById('notify');
38 if (xmlhttp.readyState == 4) {
39 container.innerHTML=xmlhttp.responseText;
40 }
41 }
42
43 function rpc_notify_callback() {
44 var container = document.getElementById('notify');
45 if (xmlhttp_rpc.readyState == 4) {
46 container.innerHTML=xmlhttp_rpc.responseText;
47 }
48 }
49
50 function rpc_pnotify_callback() {
51 var container = parent.document.getElementById('notify');
52 if (xmlhttp_rpc.readyState == 4) {
53 container.innerHTML=xmlhttp_rpc.responseText;
54 }
55 }
56
57 function param_escape(arg) {
58 if (typeof encodeURIComponent != 'undefined')
59 return encodeURIComponent(arg);
60 else
61 return escape(arg);
62 }
63
64 function param_unescape(arg) {
65 if (typeof decodeURIComponent != 'undefined')
66 return decodeURIComponent(arg);
67 else
68 return unescape(arg);
69 }
70
71 function delay(gap) {
72 var then,now;
73 then=new Date().getTime();
74 now=then;
75 while((now-then)<gap) {
76 now=new Date().getTime();
77 }
78 }
79
80 var notify_hide_timerid = false;
81 var notify_last_doc = false;
82
83 var notify_effect = false;
84
85 function hide_notify() {
86 if (notify_last_doc) {
87 var n = notify_last_doc.getElementById("notify");
88 if (browser_has_opacity()) {
89 if (notify_opacity >= 0) {
90 notify_opacity = notify_opacity - 0.1;
91 n.style.opacity = notify_opacity;
92 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
93 } else {
94 n.style.display = "none";
95 n.style.opacity = 1;
96 }
97 } else {
98 n.style.display = "none";
99 }
100 }
101 }
102
103 function notify_real(msg, doc, no_hide, is_err) {
104
105 var n = doc.getElementById("notify");
106 var nb = doc.getElementById("notify_body");
107
108 if (!n || !nb) return;
109
110 if (notify_hide_timerid) {
111 window.clearTimeout(notify_hide_timerid);
112 }
113
114 notify_last_doc = doc;
115 notify_opacity = 1;
116
117 if (msg == "") {
118 if (n.style.display == "block") {
119 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
120 }
121 return;
122 } else {
123 n.style.display = "block";
124 }
125
126 if (is_err) {
127 n.style.backgroundColor = "#ffcccc";
128 n.style.color = "black";
129 n.style.borderColor = "#ff0000";
130 } else {
131 n.style.backgroundColor = "#fff7d5";
132 n.style.borderColor = "#d7c47a";
133 n.style.color = "black";
134 }
135
136 nb.innerHTML = msg;
137
138 if (!no_hide) {
139 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
140 }
141 }
142
143 function p_notify(msg, no_hide, is_err) {
144 notify_real(msg, parent.document, no_hide, is_err);
145 }
146
147 function notify(msg, no_hide, is_err) {
148 notify_real(msg, document, no_hide, is_err);
149 }
150
151 function printLockingError() {
152 notify("Please wait until operation finishes");}
153
154 var seq = "";
155
156 function hotkey_handler(e) {
157
158 var keycode;
159
160 if (!hotkeys_enabled) return;
161
162 if (window.event) {
163 keycode = window.event.keyCode;
164 } else if (e) {
165 keycode = e.which;
166 }
167
168 if (keycode == 13 || keycode == 27) {
169 seq = "";
170 } else {
171 seq = seq + "" + keycode;
172 }
173
174 if (document.getElementById("piggie")) {
175
176 if (seq.match("807371717369")) {
177 seq = "";
178 localPiggieFunction(true);
179 } else {
180 localPiggieFunction(false);
181 }
182 }
183
184 if (typeof localHotkeyHandler != 'undefined') {
185 try {
186 localHotkeyHandler(keycode);
187 } catch (e) {
188 exception_error("hotkey_handler", e);
189 }
190 }
191
192 }
193
194 function cleanSelectedList(element) {
195 var content = document.getElementById(element);
196
197 if (!document.getElementById("feedCatHolder")) {
198 for (i = 0; i < content.childNodes.length; i++) {
199 var child = content.childNodes[i];
200 try {
201 child.className = child.className.replace("Selected", "");
202 } catch (e) {
203 //
204 }
205 }
206 } else {
207 for (i = 0; i < content.childNodes.length; i++) {
208 var child = content.childNodes[i];
209 if (child.id == "feedCatHolder") {
210 parent.debug(child.id);
211 var fcat = child.lastChild;
212 for (j = 0; j < fcat.childNodes.length; j++) {
213 var feed = fcat.childNodes[j];
214 feed.className = feed.className.replace("Selected", "");
215 }
216 }
217 }
218 }
219 }
220
221
222 function cleanSelected(element) {
223 var content = document.getElementById(element);
224
225 for (i = 0; i < content.rows.length; i++) {
226 content.rows[i].className = content.rows[i].className.replace("Selected", "");
227 }
228 }
229
230 function getVisibleUnreadHeadlines() {
231 var content = document.getElementById("headlinesList");
232
233 var rows = new Array();
234
235 for (i = 0; i < content.rows.length; i++) {
236 var row_id = content.rows[i].id.replace("RROW-", "");
237 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
238 rows.push(row_id);
239 }
240 }
241 return rows;
242 }
243
244 function getVisibleHeadlineIds() {
245
246 var content = document.getElementById("headlinesList");
247
248 var rows = new Array();
249
250 for (i = 0; i < content.rows.length; i++) {
251 var row_id = content.rows[i].id.replace("RROW-", "");
252 if (row_id.length > 0) {
253 rows.push(row_id);
254 }
255 }
256 return rows;
257 }
258
259 function getFirstVisibleHeadlineId() {
260 var rows = getVisibleHeadlineIds();
261 return rows[0];
262 }
263
264 function getLastVisibleHeadlineId() {
265 var rows = getVisibleHeadlineIds();
266 return rows[rows.length-1];
267 }
268
269 function markHeadline(id) {
270 var row = document.getElementById("RROW-" + id);
271 if (row) {
272 var is_active = false;
273
274 if (row.className.match("Active")) {
275 is_active = true;
276 }
277 row.className = row.className.replace("Selected", "");
278 row.className = row.className.replace("Active", "");
279 row.className = row.className.replace("Insensitive", "");
280
281 if (is_active) {
282 row.className = row.className = "Active";
283 }
284
285 var check = document.getElementById("RCHK-" + id);
286
287 if (check) {
288 check.checked = true;
289 }
290
291 row.className = row.className + "Selected";
292
293 }
294 }
295
296 function getFeedIds() {
297 var content = document.getElementById("feedsList");
298
299 var rows = new Array();
300
301 for (i = 0; i < content.rows.length; i++) {
302 var id = content.rows[i].id.replace("FEEDR-", "");
303 if (id.length > 0) {
304 rows.push(id);
305 }
306 }
307
308 return rows;
309 }
310
311 function setCookie(name, value, lifetime, path, domain, secure) {
312
313 var d = false;
314
315 if (lifetime) {
316 d = new Date();
317 d.setTime(lifetime * 1000);
318 }
319
320 int_setCookie(name, value, d, path, domain, secure);
321
322 }
323
324 function int_setCookie(name, value, expires, path, domain, secure) {
325 document.cookie= name + "=" + escape(value) +
326 ((expires) ? "; expires=" + expires.toGMTString() : "") +
327 ((path) ? "; path=" + path : "") +
328 ((domain) ? "; domain=" + domain : "") +
329 ((secure) ? "; secure" : "");
330 }
331
332 function delCookie(name, path, domain) {
333 if (getCookie(name)) {
334 document.cookie = name + "=" +
335 ((path) ? ";path=" + path : "") +
336 ((domain) ? ";domain=" + domain : "" ) +
337 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
338 }
339 }
340
341
342 function getCookie(name) {
343
344 var dc = document.cookie;
345 var prefix = name + "=";
346 var begin = dc.indexOf("; " + prefix);
347 if (begin == -1) {
348 begin = dc.indexOf(prefix);
349 if (begin != 0) return null;
350 }
351 else {
352 begin += 2;
353 }
354 var end = document.cookie.indexOf(";", begin);
355 if (end == -1) {
356 end = dc.length;
357 }
358 return unescape(dc.substring(begin + prefix.length, end));
359 }
360
361 function disableContainerChildren(id, disable, doc) {
362
363 if (!doc) doc = document;
364
365 var container = doc.getElementById(id);
366
367 for (var i = 0; i < container.childNodes.length; i++) {
368 var child = container.childNodes[i];
369
370 try {
371 child.disabled = disable;
372 } catch (E) {
373
374 }
375
376 if (disable) {
377 if (child.className && child.className.match("button")) {
378 child.className = "disabledButton";
379 }
380 } else {
381 if (child.className && child.className.match("disabledButton")) {
382 child.className = "button";
383 }
384 }
385 }
386
387 }
388
389 function gotoPreferences() {
390 document.location.href = "prefs.php";
391 }
392
393 function gotoMain() {
394 document.location.href = "tt-rss.php";
395 }
396
397 function gotoExportOpml() {
398 document.location.href = "opml.php?op=Export";
399 }
400
401 function getActiveFeedId() {
402 return getCookie("ttrss_vf_actfeed");
403 }
404
405 function setActiveFeedId(id) {
406 return setCookie("ttrss_vf_actfeed", id);
407 }
408
409 var xmlhttp_rpc = Ajax.getTransport();
410
411 function parse_counters(reply, f_document, title_obj, scheduled_call) {
412 try {
413 for (var l = 0; l < reply.childNodes.length; l++) {
414 if (!reply.childNodes[l] ||
415 typeof(reply.childNodes[l].getAttribute) == "undefined") {
416 // where did this come from?
417 continue;
418 }
419
420 var id = reply.childNodes[l].getAttribute("id");
421 var t = reply.childNodes[l].getAttribute("type");
422 var ctr = reply.childNodes[l].getAttribute("counter");
423 var error = reply.childNodes[l].getAttribute("error");
424 var has_img = reply.childNodes[l].getAttribute("hi");
425 var updated = reply.childNodes[l].getAttribute("updated");
426
427 if (id == "global-unread") {
428 title_obj.global_unread = ctr;
429 title_obj.updateTitle();
430 continue;
431 }
432
433 if (t == "category") {
434 var catctr = f_document.getElementById("FCATCTR-" + id);
435 if (catctr) {
436 catctr.innerHTML = "(" + ctr + " unread)";
437 }
438 continue;
439 }
440
441 var feedctr = f_document.getElementById("FEEDCTR-" + id);
442 var feedu = f_document.getElementById("FEEDU-" + id);
443 var feedr = f_document.getElementById("FEEDR-" + id);
444 var feed_img = f_document.getElementById("FIMG-" + id);
445 var feedlink = f_document.getElementById("FEEDL-" + id);
446
447 if (updated && feedlink) {
448 if (error) {
449 feedlink.title = "Error: " + error + " (" + updated + ")";
450 } else {
451 feedlink.title = "Updated: " + updated;
452 }
453 }
454
455 if (feedctr && feedu && feedr) {
456
457 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
458 var hf = title_obj.parent.frames["headlines-frame"];
459 hf.location.reload(true);
460 }
461
462 feedu.innerHTML = ctr;
463
464 if (error) {
465 feedr.className = feedr.className.replace("feed", "error");
466 } else if (id > 0) {
467 feedr.className = feedr.className.replace("error", "feed");
468 }
469
470 if (ctr > 0) {
471 feedctr.className = "odd";
472 if (!feedr.className.match("Unread")) {
473 var is_selected = feedr.className.match("Selected");
474
475 feedr.className = feedr.className.replace("Selected", "");
476 feedr.className = feedr.className.replace("Unread", "");
477
478 feedr.className = feedr.className + "Unread";
479
480 if (is_selected) {
481 feedr.className = feedr.className + "Selected";
482 }
483
484 }
485 } else {
486 feedctr.className = "invisible";
487 feedr.className = feedr.className.replace("Unread", "");
488 }
489 }
490 }
491 } catch (e) {
492 exception_error("parse_counters", e);
493 }
494 }
495
496 // this one is called from feedlist context
497 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
498
499 function all_counters_callback() {
500 if (xmlhttp_rpc.readyState == 4) {
501 try {
502 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
503 notify("[all_counters_callback] backend did not return valid XML");
504 return;
505 }
506
507 if (!parent.frames["feeds-frame"]) {
508 notify("[all_counters_callback] no parent feeds-frame");
509 return;
510 }
511
512 var reply = xmlhttp_rpc.responseXML.firstChild;
513 var f_document = parent.frames["feeds-frame"].document;
514
515 parse_counters(reply, f_document, parent);
516
517 } catch (e) {
518 exception_error("all_counters_callback", e);
519 }
520 }
521 }
522
523 function update_all_counters(feed) {
524 if (xmlhttp_ready(xmlhttp_rpc)) {
525 var query = "backend.php?op=rpc&subop=getAllCounters";
526
527 if (feed > 0) {
528 query = query + "&aid=" + feed;
529 }
530
531 xmlhttp_rpc.open("GET", query, true);
532 xmlhttp_rpc.onreadystatechange=all_counters_callback;
533 xmlhttp_rpc.send(null);
534 }
535 }
536
537 function popupHelp(tid) {
538 var w = window.open("backend.php?op=help&tid=" + tid,
539 "Popup Help",
540 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
541 }
542
543 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
544 * * @author Sundar Dorai-Raj
545 * * Email: sdoraira@vt.edu
546 * * This program is free software; you can redistribute it and/or
547 * * modify it under the terms of the GNU General Public License
548 * * as published by the Free Software Foundation; either version 2
549 * * of the License, or (at your option) any later version,
550 * * provided that any use properly credits the author.
551 * * This program is distributed in the hope that it will be useful,
552 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
553 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
554 * * GNU General Public License for more details at http://www.gnu.org * * */
555
556 var numbers=".0123456789";
557 function isNumeric(x) {
558 // is x a String or a character?
559 if(x.length>1) {
560 // remove negative sign
561 x=Math.abs(x)+"";
562 for(j=0;j<x.length;j++) {
563 // call isNumeric recursively for each character
564 number=isNumeric(x.substring(j,j+1));
565 if(!number) return number;
566 }
567 return number;
568 }
569 else {
570 // if x is number return true
571 if(numbers.indexOf(x)>=0) return true;
572 return false;
573 }
574 }
575
576
577 function hideOrShowFeeds(doc, hide) {
578
579 if (!doc.styleSheets) return;
580
581 var css_rules = doc.styleSheets[0].cssRules;
582
583 if (!css_rules || !css_rules.length) return;
584
585 for (i = 0; i < css_rules.length; i++) {
586 var rule = css_rules[i];
587
588 if (rule.selectorText == "ul.feedList li.feed") {
589 if (!hide) {
590 rule.style.display = "block";
591 } else {
592 rule.style.display = "none";
593 }
594 }
595
596 }
597
598 }
599
600 function selectTableRow(r, do_select) {
601 r.className = r.className.replace("Selected", "");
602
603 if (do_select) {
604 r.className = r.className + "Selected";
605 }
606 }
607
608 function selectTableRowById(elem_id, check_id, do_select) {
609
610 try {
611
612 var row = document.getElementById(elem_id);
613
614 if (row) {
615 selectTableRow(row, do_select);
616 }
617
618 var check = document.getElementById(check_id);
619
620 if (check) {
621 check.checked = do_select;
622 }
623 } catch (e) {
624 exception_error("selectTableRowById", e);
625 }
626 }
627
628 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
629 classcheck, reset_others) {
630
631 var content = document.getElementById(content_id);
632
633 if (!content) {
634 alert("[selectTableRows] Element " + content_id + " not found.");
635 return;
636 }
637
638 for (i = 0; i < content.rows.length; i++) {
639 if (!classcheck || content.rows[i].className.match(classcheck)) {
640
641 if (content.rows[i].id.match(prefix)) {
642 selectTableRow(content.rows[i], do_select);
643
644 var row_id = content.rows[i].id.replace(prefix, "");
645 var check = document.getElementById(check_prefix + row_id);
646
647 if (check) {
648 check.checked = do_select;
649 }
650 } else if (reset_others) {
651 selectTableRow(content.rows[i], false);
652
653 var row_id = content.rows[i].id.replace(prefix, "");
654 var check = document.getElementById(check_prefix + row_id);
655
656 if (check) {
657 check.checked = false;
658 }
659
660 }
661 } else if (reset_others) {
662 selectTableRow(content.rows[i], false);
663
664 var row_id = content.rows[i].id.replace(prefix, "");
665 var check = document.getElementById(check_prefix + row_id);
666
667 if (check) {
668 check.checked = false;
669 }
670
671 }
672 }
673 }
674
675 function getSelectedTableRowIds(content_id, prefix) {
676
677 var content = document.getElementById(content_id);
678
679 if (!content) {
680 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
681 return;
682 }
683
684 var sel_rows = new Array();
685
686 for (i = 0; i < content.rows.length; i++) {
687 if (content.rows[i].id.match(prefix) &&
688 content.rows[i].className.match("Selected")) {
689
690 var row_id = content.rows[i].id.replace(prefix + "-", "");
691 sel_rows.push(row_id);
692 }
693 }
694
695 return sel_rows;
696
697 }
698
699 function toggleSelectRowById(sender, id) {
700 var row = document.getElementById(id);
701
702 if (sender.checked) {
703 if (!row.className.match("Selected")) {
704 row.className = row.className + "Selected";
705 }
706 } else {
707 if (row.className.match("Selected")) {
708 row.className = row.className.replace("Selected", "");
709 }
710 }
711 }
712
713 function toggleSelectListRow(sender) {
714 var parent_row = sender.parentNode;
715
716 if (sender.checked) {
717 if (!parent_row.className.match("Selected")) {
718 parent_row.className = parent_row.className + "Selected";
719 }
720 } else {
721 if (parent_row.className.match("Selected")) {
722 parent_row.className = parent_row.className.replace("Selected", "");
723 }
724 }
725 }
726
727
728 function toggleSelectRow(sender) {
729 var parent_row = sender.parentNode.parentNode;
730
731 if (sender.checked) {
732 if (!parent_row.className.match("Selected")) {
733 parent_row.className = parent_row.className + "Selected";
734 }
735 } else {
736 if (parent_row.className.match("Selected")) {
737 parent_row.className = parent_row.className.replace("Selected", "");
738 }
739 }
740 }
741
742 function openExternalUrl(url) {
743 var w = window.open(url);
744 }
745
746 function getRelativeFeedId(list, id, direction, unread_only) {
747 if (!id) {
748 if (direction == "next") {
749 for (i = 0; i < list.childNodes.length; i++) {
750 var child = list.childNodes[i];
751 if (child.id && child.id == "feedCatHolder") {
752 if (child.lastChild) {
753 var cr = getRelativeFeedId(child.firstChild, id, direction);
754 if (cr) return cr;
755 }
756 } else if (child.id && child.id.match("FEEDR-")) {
757 return child.id.replace('FEEDR-', '');
758 }
759 }
760 }
761
762 // FIXME select last feed doesn't work when only unread feeds are visible
763
764 if (direction == "prev") {
765 for (i = list.childNodes.length-1; i >= 0; i--) {
766 var child = list.childNodes[i];
767 if (child.id == "feedCatHolder") {
768 if (child.firstChild) {
769 var cr = getRelativeFeedId(child.firstChild, id, direction);
770 if (cr) return cr;
771 }
772 } else if (child.id.match("FEEDR-")) {
773
774 if (getCookie("ttrss_vf_hreadf") == 1) {
775 if (child.className != "feed") {
776 alert(child.className);
777 return child.id.replace('FEEDR-', '');
778 }
779 } else {
780 return child.id.replace('FEEDR-', '');
781 }
782 }
783 }
784 }
785 } else {
786
787 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
788
789 if (getCookie("ttrss_vf_hreadf") == 1) {
790 unread_only = true;
791 }
792
793 if (direction == "next") {
794
795 var e = feed;
796
797 while (e) {
798
799 if (e.nextSibling) {
800
801 e = e.nextSibling;
802
803 } else if (e.parentNode.parentNode.nextSibling) {
804
805 var this_cat = e.parentNode.parentNode;
806
807 e = false;
808
809 if (this_cat && this_cat.nextSibling) {
810 while (!e && this_cat.nextSibling) {
811 this_cat = this_cat.nextSibling;
812 if (this_cat.id == "feedCatHolder") {
813 e = this_cat.firstChild.firstChild;
814 }
815 }
816 }
817
818 } else {
819 e = false;
820 }
821
822 if (e) {
823 if (!unread_only || (unread_only && e.className != "feed" &&
824 e.className != "error")) {
825 return e.id.replace("FEEDR-", "");
826 }
827 }
828 }
829
830 } else if (direction == "prev") {
831
832 var e = feed;
833
834 while (e) {
835
836 if (e.previousSibling) {
837
838 e = e.previousSibling;
839
840 } else if (e.parentNode.parentNode.previousSibling) {
841
842 var this_cat = e.parentNode.parentNode;
843
844 e = false;
845
846 if (this_cat && this_cat.previousSibling) {
847 while (!e && this_cat.previousSibling) {
848 this_cat = this_cat.previousSibling;
849 if (this_cat.id == "feedCatHolder") {
850 e = this_cat.firstChild.lastChild;
851 }
852 }
853 }
854
855 } else {
856 e = false;
857 }
858
859 if (e) {
860 if (!unread_only || (unread_only && e.className != "feed" &&
861 e.className != "error")) {
862 return e.id.replace("FEEDR-", "");
863 }
864 }
865 }
866 }
867 }
868 }
869
870 function showBlockElement(id) {
871 var elem = document.getElementById(id);
872
873 if (elem) {
874 elem.style.display = "block";
875 } else {
876 alert("[showBlockElement] can't find element with id " + id);
877 }
878 }
879
880 function hideParentElement(e) {
881 e.parentNode.style.display = "none";
882 }
883
884 function dropboxSelect(e, v) {
885 for (i = 0; i < e.length; i++) {
886 if (e[i].value == v) {
887 e.selectedIndex = i;
888 break;
889 }
890 }
891 }
892
893 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
894 // bugfixed just a little bit :-)
895 function getURLParam(strParamName){
896 var strReturn = "";
897 var strHref = window.location.href;
898
899 if (strHref.indexOf("#") == strHref.length-1) {
900 strHref = strHref.substring(0, strHref.length-1);
901 }
902
903 if ( strHref.indexOf("?") > -1 ){
904 var strQueryString = strHref.substr(strHref.indexOf("?"));
905 var aQueryString = strQueryString.split("&");
906 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
907 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
908 var aParam = aQueryString[iParam].split("=");
909 strReturn = aParam[1];
910 break;
911 }
912 }
913 }
914 return strReturn;
915 }
916
917 function leading_zero(p) {
918 var s = String(p);
919 if (s.length == 1) s = "0" + s;
920 return s;
921 }
922
923 function closeInfoBox(cleanup) {
924 var box = document.getElementById('infoBox');
925 var shadow = document.getElementById('infoBoxShadow');
926
927 if (shadow) {
928 shadow.style.display = "none";
929 } else if (box) {
930 box.style.display = "none";
931 }
932
933 if (cleanup) box.innerHTML = "&nbsp;";
934
935 enableHotkeys();
936
937 }
938
939
940 function displayDlg(id, param) {
941
942 if (!xmlhttp_ready(xmlhttp)) {
943 printLockingError();
944 return
945 }
946
947 notify("");
948
949 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
950 param_escape(id) + "&param=" + param_escape(param), true);
951 xmlhttp.onreadystatechange=infobox_callback;
952 xmlhttp.send(null);
953
954 disableHotkeys();
955
956 }
957
958 function infobox_submit_callback() {
959 if (xmlhttp.readyState == 4) {
960 closeInfoBox();
961
962 // called from prefs, reload tab
963 if (active_tab) {
964 selectTab(active_tab, false);
965 }
966
967 notify(xmlhttp.responseText);
968
969 }
970 }
971
972 function infobox_callback() {
973 if (xmlhttp.readyState == 4) {
974 var box = document.getElementById('infoBox');
975 var shadow = document.getElementById('infoBoxShadow');
976 if (box) {
977 box.innerHTML=xmlhttp.responseText;
978 if (shadow) {
979 shadow.style.display = "block";
980 } else {
981 box.style.display = "block";
982 }
983 }
984 }
985 }
986
987 function qaddFilter() {
988
989 if (!xmlhttp_ready(xmlhttp)) {
990 printLockingError();
991 return
992 }
993
994 var query = Form.serialize("filter_add_form");
995
996 xmlhttp.open("GET", "backend.php?" + query, true);
997 xmlhttp.onreadystatechange=infobox_submit_callback;
998 xmlhttp.send(null);
999
1000 return true;
1001 }
1002
1003 function toggleSubmitNotEmpty(e, submit_id) {
1004 try {
1005 document.getElementById(submit_id).disabled = (e.value == "")
1006 } catch (e) {
1007 exception_error("toggleSubmitNotEmpty", e);
1008 }
1009 }
1010
1011 function isValidURL(s) {
1012 return s.match("http://") != null || s.match("https://") != null;
1013 }
1014
1015 function qafAdd() {
1016
1017 if (!xmlhttp_ready(xmlhttp)) {
1018 printLockingError();
1019 return
1020 }
1021
1022 notify("Adding feed...");
1023
1024 closeInfoBox();
1025
1026 var feeds_doc = window.frames["feeds-frame"].document;
1027
1028 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1029
1030 var query = Form.serialize("feed_add_form");
1031
1032 xmlhttp.open("GET", "backend.php?" + query, true);
1033 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1034 xmlhttp.send(null);
1035 }
1036
1037 function filterCR(e)
1038 {
1039 var key;
1040
1041 if(window.event)
1042 key = window.event.keyCode; //IE
1043 else
1044 key = e.which; //firefox
1045
1046 if(key == 13)
1047 return false;
1048 else
1049 return true;
1050 }
1051