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