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