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