]> git.wh0rd.org - tt-rss.git/blob - functions.js
da5d9514386463f71064acd9fa8efe1abc019989
[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 if (!container) {
368 //alert("disableContainerChildren: element " + id + " not found");
369 return;
370 }
371
372 for (var i = 0; i < container.childNodes.length; i++) {
373 var child = container.childNodes[i];
374
375 try {
376 child.disabled = disable;
377 } catch (E) {
378
379 }
380
381 if (disable) {
382 if (child.className && child.className.match("button")) {
383 child.className = "disabledButton";
384 }
385 } else {
386 if (child.className && child.className.match("disabledButton")) {
387 child.className = "button";
388 }
389 }
390 }
391
392 }
393
394 function gotoPreferences() {
395 document.location.href = "prefs.php";
396 }
397
398 function gotoMain() {
399 document.location.href = "tt-rss.php";
400 }
401
402 function gotoExportOpml() {
403 document.location.href = "opml.php?op=Export";
404 }
405
406 function getActiveFeedId() {
407 // return getCookie("ttrss_vf_actfeed");
408 try {
409 debug("gAFID: " + getMainContext().active_feed_id);
410 return getMainContext().active_feed_id;
411 } catch (e) {
412 exception_error("getActiveFeedId", e);
413 }
414 }
415
416 function setActiveFeedId(id) {
417 // return setCookie("ttrss_vf_actfeed", id);
418 try {
419 getMainContext().active_feed_id = id;
420 } catch (e) {
421 exception_error("setActiveFeedId", e);
422 }
423 }
424
425 var xmlhttp_rpc = Ajax.getTransport();
426
427 function parse_counters(reply, scheduled_call) {
428 try {
429 var f_document = getFeedsContext().document;
430 var title_obj = getMainContext();
431
432 debug("F_DOC: " + f_document + ", T_OBJ: " + title_obj);
433
434 for (var l = 0; l < reply.childNodes.length; l++) {
435 if (!reply.childNodes[l] ||
436 typeof(reply.childNodes[l].getAttribute) == "undefined") {
437 // where did this come from?
438 continue;
439 }
440
441 var id = reply.childNodes[l].getAttribute("id");
442 var t = reply.childNodes[l].getAttribute("type");
443 var ctr = reply.childNodes[l].getAttribute("counter");
444 var error = reply.childNodes[l].getAttribute("error");
445 var has_img = reply.childNodes[l].getAttribute("hi");
446 var updated = reply.childNodes[l].getAttribute("updated");
447
448 if (id == "global-unread") {
449 title_obj.global_unread = ctr;
450 title_obj.updateTitle();
451 continue;
452 }
453
454 if (t == "category") {
455 var catctr = f_document.getElementById("FCATCTR-" + id);
456 if (catctr) {
457 catctr.innerHTML = "(" + ctr + " unread)";
458 }
459 continue;
460 }
461
462 var feedctr = f_document.getElementById("FEEDCTR-" + id);
463 var feedu = f_document.getElementById("FEEDU-" + id);
464 var feedr = f_document.getElementById("FEEDR-" + id);
465 var feed_img = f_document.getElementById("FIMG-" + id);
466 var feedlink = f_document.getElementById("FEEDL-" + id);
467
468 if (updated && feedlink) {
469 if (error) {
470 feedlink.title = "Error: " + error + " (" + updated + ")";
471 } else {
472 feedlink.title = "Updated: " + updated;
473 }
474 }
475
476 if (feedctr && feedu && feedr) {
477
478 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
479 var hf = title_obj.parent.frames["headlines-frame"];
480 hf.location.reload(true);
481 }
482
483 feedu.innerHTML = ctr;
484
485 if (error) {
486 feedr.className = feedr.className.replace("feed", "error");
487 } else if (id > 0) {
488 feedr.className = feedr.className.replace("error", "feed");
489 }
490
491 if (ctr > 0) {
492 feedctr.className = "odd";
493 if (!feedr.className.match("Unread")) {
494 var is_selected = feedr.className.match("Selected");
495
496 feedr.className = feedr.className.replace("Selected", "");
497 feedr.className = feedr.className.replace("Unread", "");
498
499 feedr.className = feedr.className + "Unread";
500
501 if (is_selected) {
502 feedr.className = feedr.className + "Selected";
503 }
504
505 }
506 } else {
507 feedctr.className = "invisible";
508 feedr.className = feedr.className.replace("Unread", "");
509 }
510 }
511 }
512 } catch (e) {
513 exception_error("parse_counters", e);
514 }
515 }
516
517 function all_counters_callback() {
518 if (xmlhttp_rpc.readyState == 4) {
519 try {
520 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
521 notify("[all_counters_callback] backend did not return valid XML");
522 return;
523 }
524
525 var reply = xmlhttp_rpc.responseXML.firstChild;
526
527 parse_counters(reply);
528
529 } catch (e) {
530 exception_error("all_counters_callback", e);
531 }
532 }
533 }
534
535 function update_all_counters(feed) {
536 if (xmlhttp_ready(xmlhttp_rpc)) {
537 var query = "backend.php?op=rpc&subop=getAllCounters";
538
539 if (feed > 0) {
540 query = query + "&aid=" + feed;
541 }
542
543 xmlhttp_rpc.open("GET", query, true);
544 xmlhttp_rpc.onreadystatechange=all_counters_callback;
545 xmlhttp_rpc.send(null);
546 }
547 }
548
549 function popupHelp(tid) {
550 var w = window.open("backend.php?op=help&tid=" + tid,
551 "Popup Help",
552 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
553 }
554
555 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
556 * * @author Sundar Dorai-Raj
557 * * Email: sdoraira@vt.edu
558 * * This program is free software; you can redistribute it and/or
559 * * modify it under the terms of the GNU General Public License
560 * * as published by the Free Software Foundation; either version 2
561 * * of the License, or (at your option) any later version,
562 * * provided that any use properly credits the author.
563 * * This program is distributed in the hope that it will be useful,
564 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
565 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
566 * * GNU General Public License for more details at http://www.gnu.org * * */
567
568 var numbers=".0123456789";
569 function isNumeric(x) {
570 // is x a String or a character?
571 if(x.length>1) {
572 // remove negative sign
573 x=Math.abs(x)+"";
574 for(j=0;j<x.length;j++) {
575 // call isNumeric recursively for each character
576 number=isNumeric(x.substring(j,j+1));
577 if(!number) return number;
578 }
579 return number;
580 }
581 else {
582 // if x is number return true
583 if(numbers.indexOf(x)>=0) return true;
584 return false;
585 }
586 }
587
588
589 function hideOrShowFeeds(doc, hide) {
590
591 if (!doc.styleSheets) return;
592
593 var css_rules = doc.styleSheets[0].cssRules;
594
595 if (!css_rules || !css_rules.length) return;
596
597 for (i = 0; i < css_rules.length; i++) {
598 var rule = css_rules[i];
599
600 if (rule.selectorText == "ul.feedList li.feed") {
601 if (!hide) {
602 rule.style.display = "block";
603 } else {
604 rule.style.display = "none";
605 }
606 }
607
608 }
609
610 }
611
612 function selectTableRow(r, do_select) {
613 r.className = r.className.replace("Selected", "");
614
615 if (do_select) {
616 r.className = r.className + "Selected";
617 }
618 }
619
620 function selectTableRowById(elem_id, check_id, do_select) {
621
622 try {
623
624 var row = document.getElementById(elem_id);
625
626 if (row) {
627 selectTableRow(row, do_select);
628 }
629
630 var check = document.getElementById(check_id);
631
632 if (check) {
633 check.checked = do_select;
634 }
635 } catch (e) {
636 exception_error("selectTableRowById", e);
637 }
638 }
639
640 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
641 classcheck, reset_others) {
642
643 var content = document.getElementById(content_id);
644
645 if (!content) {
646 alert("[selectTableRows] Element " + content_id + " not found.");
647 return;
648 }
649
650 for (i = 0; i < content.rows.length; i++) {
651 if (!classcheck || content.rows[i].className.match(classcheck)) {
652
653 if (content.rows[i].id.match(prefix)) {
654 selectTableRow(content.rows[i], do_select);
655
656 var row_id = content.rows[i].id.replace(prefix, "");
657 var check = document.getElementById(check_prefix + row_id);
658
659 if (check) {
660 check.checked = do_select;
661 }
662 } else if (reset_others) {
663 selectTableRow(content.rows[i], false);
664
665 var row_id = content.rows[i].id.replace(prefix, "");
666 var check = document.getElementById(check_prefix + row_id);
667
668 if (check) {
669 check.checked = false;
670 }
671
672 }
673 } else if (reset_others) {
674 selectTableRow(content.rows[i], false);
675
676 var row_id = content.rows[i].id.replace(prefix, "");
677 var check = document.getElementById(check_prefix + row_id);
678
679 if (check) {
680 check.checked = false;
681 }
682
683 }
684 }
685 }
686
687 function getSelectedTableRowIds(content_id, prefix) {
688
689 var content = document.getElementById(content_id);
690
691 if (!content) {
692 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
693 return;
694 }
695
696 var sel_rows = new Array();
697
698 for (i = 0; i < content.rows.length; i++) {
699 if (content.rows[i].id.match(prefix) &&
700 content.rows[i].className.match("Selected")) {
701
702 var row_id = content.rows[i].id.replace(prefix + "-", "");
703 sel_rows.push(row_id);
704 }
705 }
706
707 return sel_rows;
708
709 }
710
711 function toggleSelectRowById(sender, id) {
712 var row = document.getElementById(id);
713
714 if (sender.checked) {
715 if (!row.className.match("Selected")) {
716 row.className = row.className + "Selected";
717 }
718 } else {
719 if (row.className.match("Selected")) {
720 row.className = row.className.replace("Selected", "");
721 }
722 }
723 }
724
725 function toggleSelectListRow(sender) {
726 var parent_row = sender.parentNode;
727
728 if (sender.checked) {
729 if (!parent_row.className.match("Selected")) {
730 parent_row.className = parent_row.className + "Selected";
731 }
732 } else {
733 if (parent_row.className.match("Selected")) {
734 parent_row.className = parent_row.className.replace("Selected", "");
735 }
736 }
737 }
738
739
740 function toggleSelectRow(sender) {
741 var parent_row = sender.parentNode.parentNode;
742
743 if (sender.checked) {
744 if (!parent_row.className.match("Selected")) {
745 parent_row.className = parent_row.className + "Selected";
746 }
747 } else {
748 if (parent_row.className.match("Selected")) {
749 parent_row.className = parent_row.className.replace("Selected", "");
750 }
751 }
752 }
753
754 function openExternalUrl(url) {
755 var w = window.open(url);
756 }
757
758 function getRelativeFeedId(list, id, direction, unread_only) {
759 if (!id) {
760 if (direction == "next") {
761 for (i = 0; i < list.childNodes.length; i++) {
762 var child = list.childNodes[i];
763 if (child.id && child.id == "feedCatHolder") {
764 if (child.lastChild) {
765 var cr = getRelativeFeedId(child.firstChild, id, direction);
766 if (cr) return cr;
767 }
768 } else if (child.id && child.id.match("FEEDR-")) {
769 return child.id.replace('FEEDR-', '');
770 }
771 }
772 }
773
774 // FIXME select last feed doesn't work when only unread feeds are visible
775
776 if (direction == "prev") {
777 for (i = list.childNodes.length-1; i >= 0; i--) {
778 var child = list.childNodes[i];
779 if (child.id == "feedCatHolder") {
780 if (child.firstChild) {
781 var cr = getRelativeFeedId(child.firstChild, id, direction);
782 if (cr) return cr;
783 }
784 } else if (child.id.match("FEEDR-")) {
785
786 if (getCookie("ttrss_vf_hreadf") == 1) {
787 if (child.className != "feed") {
788 alert(child.className);
789 return child.id.replace('FEEDR-', '');
790 }
791 } else {
792 return child.id.replace('FEEDR-', '');
793 }
794 }
795 }
796 }
797 } else {
798
799 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
800
801 if (getCookie("ttrss_vf_hreadf") == 1) {
802 unread_only = true;
803 }
804
805 if (direction == "next") {
806
807 var e = feed;
808
809 while (e) {
810
811 if (e.nextSibling) {
812
813 e = e.nextSibling;
814
815 } else if (e.parentNode.parentNode.nextSibling) {
816
817 var this_cat = e.parentNode.parentNode;
818
819 e = false;
820
821 if (this_cat && this_cat.nextSibling) {
822 while (!e && this_cat.nextSibling) {
823 this_cat = this_cat.nextSibling;
824 if (this_cat.id == "feedCatHolder") {
825 e = this_cat.firstChild.firstChild;
826 }
827 }
828 }
829
830 } else {
831 e = false;
832 }
833
834 if (e) {
835 if (!unread_only || (unread_only && e.className != "feed" &&
836 e.className != "error")) {
837 return e.id.replace("FEEDR-", "");
838 }
839 }
840 }
841
842 } else if (direction == "prev") {
843
844 var e = feed;
845
846 while (e) {
847
848 if (e.previousSibling) {
849
850 e = e.previousSibling;
851
852 } else if (e.parentNode.parentNode.previousSibling) {
853
854 var this_cat = e.parentNode.parentNode;
855
856 e = false;
857
858 if (this_cat && this_cat.previousSibling) {
859 while (!e && this_cat.previousSibling) {
860 this_cat = this_cat.previousSibling;
861 if (this_cat.id == "feedCatHolder") {
862 e = this_cat.firstChild.lastChild;
863 }
864 }
865 }
866
867 } else {
868 e = false;
869 }
870
871 if (e) {
872 if (!unread_only || (unread_only && e.className != "feed" &&
873 e.className != "error")) {
874 return e.id.replace("FEEDR-", "");
875 }
876 }
877 }
878 }
879 }
880 }
881
882 function showBlockElement(id) {
883 var elem = document.getElementById(id);
884
885 if (elem) {
886 elem.style.display = "block";
887 } else {
888 alert("[showBlockElement] can't find element with id " + id);
889 }
890 }
891
892 function hideParentElement(e) {
893 e.parentNode.style.display = "none";
894 }
895
896 function dropboxSelect(e, v) {
897 for (i = 0; i < e.length; i++) {
898 if (e[i].value == v) {
899 e.selectedIndex = i;
900 break;
901 }
902 }
903 }
904
905 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
906 // bugfixed just a little bit :-)
907 function getURLParam(strParamName){
908 var strReturn = "";
909 var strHref = window.location.href;
910
911 if (strHref.indexOf("#") == strHref.length-1) {
912 strHref = strHref.substring(0, strHref.length-1);
913 }
914
915 if ( strHref.indexOf("?") > -1 ){
916 var strQueryString = strHref.substr(strHref.indexOf("?"));
917 var aQueryString = strQueryString.split("&");
918 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
919 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
920 var aParam = aQueryString[iParam].split("=");
921 strReturn = aParam[1];
922 break;
923 }
924 }
925 }
926 return strReturn;
927 }
928
929 function leading_zero(p) {
930 var s = String(p);
931 if (s.length == 1) s = "0" + s;
932 return s;
933 }
934
935 function closeInfoBox(cleanup) {
936 var box = document.getElementById('infoBox');
937 var shadow = document.getElementById('infoBoxShadow');
938
939 if (shadow) {
940 shadow.style.display = "none";
941 } else if (box) {
942 box.style.display = "none";
943 }
944
945 if (cleanup) box.innerHTML = "&nbsp;";
946
947 enableHotkeys();
948
949 }
950
951
952 function displayDlg(id, param) {
953
954 if (!xmlhttp_ready(xmlhttp)) {
955 printLockingError();
956 return
957 }
958
959 notify("");
960
961 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
962 param_escape(id) + "&param=" + param_escape(param), true);
963 xmlhttp.onreadystatechange=infobox_callback;
964 xmlhttp.send(null);
965
966 disableHotkeys();
967
968 }
969
970 function infobox_submit_callback() {
971 if (xmlhttp.readyState == 4) {
972 closeInfoBox();
973
974 // called from prefs, reload tab
975 if (active_tab) {
976 selectTab(active_tab, false);
977 }
978
979 notify(xmlhttp.responseText);
980
981 }
982 }
983
984 function infobox_callback() {
985 if (xmlhttp.readyState == 4) {
986 var box = document.getElementById('infoBox');
987 var shadow = document.getElementById('infoBoxShadow');
988 if (box) {
989 box.innerHTML=xmlhttp.responseText;
990 if (shadow) {
991 shadow.style.display = "block";
992 } else {
993 box.style.display = "block";
994 }
995 }
996 }
997 }
998
999 function qaddFilter() {
1000
1001 if (!xmlhttp_ready(xmlhttp)) {
1002 printLockingError();
1003 return
1004 }
1005
1006 var query = Form.serialize("filter_add_form");
1007
1008 xmlhttp.open("GET", "backend.php?" + query, true);
1009 xmlhttp.onreadystatechange=infobox_submit_callback;
1010 xmlhttp.send(null);
1011
1012 return true;
1013 }
1014
1015 function toggleSubmitNotEmpty(e, submit_id) {
1016 try {
1017 document.getElementById(submit_id).disabled = (e.value == "")
1018 } catch (e) {
1019 exception_error("toggleSubmitNotEmpty", e);
1020 }
1021 }
1022
1023 function isValidURL(s) {
1024 return s.match("http://") != null || s.match("https://") != null;
1025 }
1026
1027 function qafAdd() {
1028
1029 if (!xmlhttp_ready(xmlhttp)) {
1030 printLockingError();
1031 return
1032 }
1033
1034 notify("Adding feed...");
1035
1036 closeInfoBox();
1037
1038 var feeds_doc = getFeedsContext().document;
1039
1040 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1041
1042 var query = Form.serialize("feed_add_form");
1043
1044 xmlhttp.open("GET", "backend.php?" + query, true);
1045 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1046 xmlhttp.send(null);
1047 }
1048
1049 function filterCR(e)
1050 {
1051 var key;
1052
1053 if(window.event)
1054 key = window.event.keyCode; //IE
1055 else
1056 key = e.which; //firefox
1057
1058 if(key == 13)
1059 return false;
1060 else
1061 return true;
1062 }
1063
1064 function getMainContext() {
1065 if (parent.window != window) {
1066 return parent.window;
1067 } else {
1068 return this.window;
1069 }
1070 }
1071
1072 function getFeedsContext() {
1073 try {
1074 return getMainContext().frames["feeds-frame"];
1075 } catch (e) {
1076 exception_error("getFeedsContext", e);
1077 }
1078 }
1079
1080 function debug(msg) {
1081 var ctx = getMainContext();
1082
1083 var c = ctx.document.getElementById('debug_output');
1084 if (c && c.style.display == "block") {
1085 while (c.lastChild != 'undefined' && c.childNodes.length > 20) {
1086 c.removeChild(c.lastChild);
1087 }
1088
1089 var d = new Date();
1090 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1091 ":" + leading_zero(d.getSeconds());
1092 c.innerHTML = "<li>[" + ts + "] " + msg + "</li>" + c.innerHTML;
1093 }
1094 }
1095
1096 function getInitParam(key) {
1097 return getMainContext().init_params[key];
1098 }
1099
1100 // TODO: batch mode
1101 function storeInitParam(key, value) {
1102 try {
1103 getMainContext().init_params[key] = value;
1104 new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1105 param_escape(key) + "&value=" + param_escape(value));
1106 } catch (e) {
1107 exception_error("storeInitParam", e);
1108 }
1109 }