]> git.wh0rd.org Git - tt-rss.git/blob - functions.js
viewfeed: enable counters reply, but with rate limit (180 sec)
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2 var xmlhttp_rpc = Ajax.getTransport();
3 var notify_silent = false;
4 var last_progress_point = 0;
5
6 /* add method to remove element from array */
7
8 Array.prototype.remove = function(s) {
9         for (var i=0; i < this.length; i++) {
10                 if (s == this[i]) this.splice(i, 1);
11         }
12 }
13
14 function is_msie() {
15         return navigator.userAgent.match("MSIE");
16 }
17
18 function is_opera() {
19         return window.opera;
20 }
21
22 function exception_error(location, e, silent) {
23         var msg;
24
25         if (e.fileName) {
26                 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
27         
28                 msg = "Exception: " + e.name + ", " + e.message + 
29                         "\nFunction: " + location + "()" +
30                         "\nLocation: " + base_fname + ":" + e.lineNumber;
31                 
32         } else {
33                 msg = "Exception: " + e + "\nFunction: " + location + "()";
34         }
35
36         debug("<b>EXCEPTION: " + msg + "</b>");
37
38         if (!silent) {
39                 alert(msg);
40         }
41 }
42
43 function disableHotkeys() {
44         hotkeys_enabled = false;
45 }
46
47 function enableHotkeys() {
48         hotkeys_enabled = true;
49 }
50
51 function xmlhttp_ready(obj) {
52         return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
53 }
54
55 function open_article_callback(transport) {
56         try {
57
58                 if (transport.responseXML) {
59                         
60                         var link = transport.responseXML.getElementsByTagName("link")[0];
61                         var id = transport.responseXML.getElementsByTagName("id")[0];
62
63                         debug("open_article_callback, received link: " + link);
64
65                         if (link && id) {
66
67                                 var wname = "ttrss_article_" + id.firstChild.nodeValue;
68
69                                 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
70
71                                 var w = window.open(link.firstChild.nodeValue, wname);
72
73                                 if (!w) { notify_error("Failed to load article in new window"); }
74
75                                 if (id) {
76                                         id = id.firstChild.nodeValue;
77                                         if (!document.getElementById("headlinesList")) {
78                                                 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
79                                         }
80                                 }
81                         } else {
82                                 notify_error("Can't open article: received invalid article link");
83                         }
84                 } else {
85                         notify_error("Can't open article: received invalid XML");
86                 }
87
88         } catch (e) {
89                 exception_error("open_article_callback", e);
90         }
91 }
92
93 function param_escape(arg) {
94         if (typeof encodeURIComponent != 'undefined')
95                 return encodeURIComponent(arg); 
96         else
97                 return escape(arg);
98 }
99
100 function param_unescape(arg) {
101         if (typeof decodeURIComponent != 'undefined')
102                 return decodeURIComponent(arg); 
103         else
104                 return unescape(arg);
105 }
106
107 function delay(gap) {
108         var then,now; 
109         then=new Date().getTime();
110         now=then;
111         while((now-then)<gap) {
112                 now=new Date().getTime();
113         }
114 }
115
116 var notify_hide_timerid = false;
117
118 function hide_notify() {
119         var n = document.getElementById("notify");
120         if (n) {
121                 n.style.display = "none";
122         }
123
124
125 function notify_silent_next() {
126         notify_silent = true;
127 }
128
129 function notify_real(msg, no_hide, n_type) {
130
131         if (notify_silent) {
132                 notify_silent = false;
133                 return;
134         }
135
136         var n = document.getElementById("notify");
137         var nb = document.getElementById("notify_body");
138
139         if (!n || !nb) return;
140
141         if (notify_hide_timerid) {
142                 window.clearTimeout(notify_hide_timerid);
143         }
144
145         if (msg == "") {
146                 if (n.style.display == "block") {
147                         notify_hide_timerid = window.setTimeout("hide_notify()", 0);
148                 }
149                 return;
150         } else {
151                 n.style.display = "block";
152         }
153
154         /* types:
155
156                 1 - generic
157                 2 - progress
158                 3 - error
159                 4 - info
160
161         */
162
163         if (typeof __ != 'undefined') {
164                 msg = __(msg);
165         }
166
167         if (n_type == 1) {
168                 n.className = "notify";
169         } else if (n_type == 2) {
170                 n.className = "notifyProgress";
171                 msg = "<img src='images/indicator_white.gif'> " + msg;
172         } else if (n_type == 3) {
173                 n.className = "notifyError";
174                 msg = "<img src='images/sign_excl.gif'> " + msg;
175         } else if (n_type == 4) {
176                 n.className = "notifyInfo";
177                 msg = "<img src='images/sign_info.gif'> " + msg;
178         }
179
180 //      msg = "<img src='images/live_com_loading.gif'> " + msg;
181
182         nb.innerHTML = msg;
183
184         if (!no_hide) {
185                 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
186         }
187 }
188
189 function notify(msg, no_hide) {
190         notify_real(msg, no_hide, 1);
191 }
192
193 function notify_progress(msg, no_hide) {
194         notify_real(msg, no_hide, 2);
195 }
196
197 function notify_error(msg, no_hide) {
198         notify_real(msg, no_hide, 3);
199
200 }
201
202 function notify_info(msg, no_hide) {
203         notify_real(msg, no_hide, 4);
204 }
205
206 function printLockingError() {
207         notify_info("Please wait until operation finishes.");
208 }
209
210 function cleanSelectedList(element) {
211         var content = document.getElementById(element);
212
213         if (!document.getElementById("feedCatHolder")) {
214                 for (i = 0; i < content.childNodes.length; i++) {
215                         var child = content.childNodes[i];
216                         try {
217                                 child.className = child.className.replace("Selected", "");
218                         } catch (e) {
219                                 //
220                         }
221                 }
222         } else {
223                 for (i = 0; i < content.childNodes.length; i++) {
224                         var child = content.childNodes[i];
225                         if (child.id == "feedCatHolder") {
226                                 debug(child.id);
227                                 var fcat = child.lastChild;
228                                 for (j = 0; j < fcat.childNodes.length; j++) {
229                                         var feed = fcat.childNodes[j];
230                                         feed.className = feed.className.replace("Selected", "");
231                                 }               
232                         }
233                 } 
234         }
235 }
236
237
238 function cleanSelected(element) {
239         var content = document.getElementById(element);
240
241         for (i = 0; i < content.rows.length; i++) {
242                 content.rows[i].className = content.rows[i].className.replace("Selected", "");
243         }
244 }
245
246 function getVisibleUnreadHeadlines() {
247         var content = document.getElementById("headlinesList");
248
249         var rows = new Array();
250
251         if (!content) return rows;
252
253         for (i = 0; i < content.rows.length; i++) {
254                 var row_id = content.rows[i].id.replace("RROW-", "");
255                 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
256                                 rows.push(row_id);      
257                 }
258         }
259         return rows;
260 }
261
262 function getVisibleHeadlineIds() {
263
264         var content = document.getElementById("headlinesList");
265
266         var rows = new Array();
267
268         if (!content) return rows;
269
270         for (i = 0; i < content.rows.length; i++) {
271                 var row_id = content.rows[i].id.replace("RROW-", "");
272                 if (row_id.length > 0) {
273                                 rows.push(row_id);      
274                 }
275         }
276         return rows;
277 }
278
279 function getFirstVisibleHeadlineId() {
280         if (isCdmMode()) {
281                 var rows = cdmGetVisibleArticles();
282                 return rows[0];
283         } else {
284                 var rows = getVisibleHeadlineIds();
285                 return rows[0];
286         }
287 }
288
289 function getLastVisibleHeadlineId() {
290         if (isCdmMode()) {
291                 var rows = cdmGetVisibleArticles();
292                 return rows[rows.length-1];
293         } else {
294                 var rows = getVisibleHeadlineIds();
295                 return rows[rows.length-1];
296         }
297 }
298
299 function markHeadline(id) {
300         var row = document.getElementById("RROW-" + id);
301         if (row) {
302                 var is_active = false;
303         
304                 if (row.className.match("Active")) {
305                         is_active = true;
306                 }
307                 row.className = row.className.replace("Selected", "");
308                 row.className = row.className.replace("Active", "");
309                 row.className = row.className.replace("Insensitive", "");
310                 
311                 if (is_active) {
312                         row.className = row.className = "Active";
313                 }
314                 
315                 var check = document.getElementById("RCHK-" + id);
316
317                 if (check) {
318                         check.checked = true;
319                 }
320
321                 row.className = row.className + "Selected"; 
322                 
323         }
324 }
325
326 function getFeedIds() {
327         var content = document.getElementById("feedsList");
328
329         var rows = new Array();
330
331         for (i = 0; i < content.rows.length; i++) {
332                 var id = content.rows[i].id.replace("FEEDR-", "");
333                 if (id.length > 0) {
334                         rows.push(id);
335                 }
336         }
337
338         return rows;
339 }
340
341 function setCookie(name, value, lifetime, path, domain, secure) {
342         
343         var d = false;
344         
345         if (lifetime) {
346                 d = new Date();
347                 d.setTime(d.getTime() + (lifetime * 1000));
348         }
349
350         debug("setCookie: " + name + " => " + value + ": " + d);
351         
352         int_setCookie(name, value, d, path, domain, secure);
353
354 }
355
356 function int_setCookie(name, value, expires, path, domain, secure) {
357         document.cookie= name + "=" + escape(value) +
358                 ((expires) ? "; expires=" + expires.toGMTString() : "") +
359                 ((path) ? "; path=" + path : "") +
360                 ((domain) ? "; domain=" + domain : "") +
361                 ((secure) ? "; secure" : "");
362 }
363
364 function delCookie(name, path, domain) {
365         if (getCookie(name)) {
366                 document.cookie = name + "=" +
367                 ((path) ? ";path=" + path : "") +
368                 ((domain) ? ";domain=" + domain : "" ) +
369                 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
370         }
371 }
372                 
373
374 function getCookie(name) {
375
376         var dc = document.cookie;
377         var prefix = name + "=";
378         var begin = dc.indexOf("; " + prefix);
379         if (begin == -1) {
380             begin = dc.indexOf(prefix);
381             if (begin != 0) return null;
382         }
383         else {
384             begin += 2;
385         }
386         var end = document.cookie.indexOf(";", begin);
387         if (end == -1) {
388             end = dc.length;
389         }
390         return unescape(dc.substring(begin + prefix.length, end));
391 }
392
393 function disableContainerChildren(id, disable, doc) {
394
395         if (!doc) doc = document;
396
397         var container = doc.getElementById(id);
398
399         if (!container) {
400                 //alert("disableContainerChildren: element " + id + " not found");
401                 return;
402         }
403
404         for (var i = 0; i < container.childNodes.length; i++) {
405                 var child = container.childNodes[i];
406
407                 try {
408                         child.disabled = disable;
409                 } catch (E) {
410
411                 }
412
413                 if (disable) {
414                         if (child.className && child.className.match("button")) {
415                                 child.className = "disabledButton";
416                         }
417                 } else {
418                         if (child.className && child.className.match("disabledButton")) {
419                                 child.className = "button";
420                         }
421                 } 
422         }
423
424 }
425
426 function gotoPreferences() {
427         document.location.href = "prefs.php";
428 }
429
430 function gotoMain() {
431         document.location.href = "tt-rss.php";
432 }
433
434 function gotoExportOpml() {
435         document.location.href = "opml.php?op=Export";
436 }
437
438 function getActiveFeedId() {
439 //      return getCookie("ttrss_vf_actfeed");
440         try {
441                 debug("gAFID: " + active_feed_id);
442                 return active_feed_id;
443         } catch (e) {
444                 exception_error("getActiveFeedId", e);
445         }
446 }
447
448 function activeFeedIsCat() {
449         return active_feed_is_cat;
450 }
451
452 function setActiveFeedId(id) {
453 //      return setCookie("ttrss_vf_actfeed", id);
454         try {
455                 debug("sAFID(" + id + ")");
456                 active_feed_id = id;
457         } catch (e) {
458                 exception_error("setActiveFeedId", e);
459         }
460 }
461
462 function parse_counters(reply, scheduled_call) {
463         try {
464
465                 var feeds_found = 0;
466
467                 var elems = reply.getElementsByTagName("counter");
468
469                 for (var l = 0; l < elems.length; l++) {
470
471                         var id = elems[l].getAttribute("id");
472                         var t = elems[l].getAttribute("type");
473                         var ctr = elems[l].getAttribute("counter");
474                         var error = elems[l].getAttribute("error");
475                         var has_img = elems[l].getAttribute("hi");
476                         var updated = elems[l].getAttribute("updated");
477                         var title = elems[l].getAttribute("title");
478                         var xmsg = elems[l].getAttribute("xmsg");
479         
480                         if (id == "global-unread") {
481                                 global_unread = ctr;
482                                 updateTitle();
483                                 continue;
484                         }
485
486                         if (id == "subscribed-feeds") {
487                                 feeds_found = ctr;
488                                 continue;
489                         }
490         
491                         if (t == "category") {
492                                 var catctr = document.getElementById("FCATCTR-" + id);
493                                 if (catctr) {
494                                         catctr.innerHTML = "(" + ctr + ")";
495                                         if (ctr > 0) {
496                                                 catctr.className = "catCtrHasUnread";
497                                         } else {
498                                                 catctr.className = "catCtrNoUnread";
499                                         }
500                                 }
501                                 continue;
502                         }
503                 
504                         var feedctr = document.getElementById("FEEDCTR-" + id);
505                         var feedu = document.getElementById("FEEDU-" + id);
506                         var feedr = document.getElementById("FEEDR-" + id);
507                         var feed_img = document.getElementById("FIMG-" + id);
508                         var feedlink = document.getElementById("FEEDL-" + id);
509                         var feedupd = document.getElementById("FLUPD-" + id);
510
511                         if (updated && feedlink) {
512                                 if (error) {
513                                         feedlink.title = "Error: " + error + " (" + updated + ")";
514                                 } else {
515                                         feedlink.title = "Updated: " + updated;
516                                 }
517                         }
518
519                         if (feedupd) {
520                                 if (!updated) updated = "";
521
522                                 if (error) {
523                                         if (xmsg) {
524                                                 feedupd.innerHTML = updated + " " + xmsg + " (Error)";
525                                         } else {
526                                                 feedupd.innerHTML = updated + " (Error)";
527                                         }
528                                 } else {
529                                         if (xmsg) {
530                                                 feedupd.innerHTML = updated + " " + xmsg;
531                                         } else {
532                                                 feedupd.innerHTML = updated;
533                                         }
534                                 }
535                         }
536
537                         if (has_img && feed_img && !is_msie()) {
538                                 if (!feed_img.src.match(id + ".ico")) {
539                                         feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
540                                 }
541                         }
542
543                         if (feedlink && title) {
544                                 feedlink.innerHTML = title;
545                         }
546
547                         if (feedctr && feedu && feedr) {
548
549                                 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
550                                         viewCurrentFeed();
551                                 }
552
553                                 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
554
555                                 feedu.innerHTML = ctr;
556
557                                 if (error) {
558                                         feedr.className = feedr.className.replace("feed", "error");
559                                 } else if (id > 0) {
560                                         feedr.className = feedr.className.replace("error", "feed");
561                                 }
562         
563                                 if (ctr > 0) {                                  
564                                         feedctr.className = "odd";
565                                         if (!feedr.className.match("Unread")) {
566                                                 var is_selected = feedr.className.match("Selected");
567                 
568                                                 feedr.className = feedr.className.replace("Selected", "");
569                                                 feedr.className = feedr.className.replace("Unread", "");
570                 
571                                                 feedr.className = feedr.className + "Unread";
572                 
573                                                 if (is_selected) {
574                                                         feedr.className = feedr.className + "Selected";
575                                                 }       
576                                                 
577                                         }
578
579                                         if (row_needs_hl) { 
580                                                 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
581                                                         queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
582                                         }
583                                 } else {
584                                         feedctr.className = "invisible";
585                                         feedr.className = feedr.className.replace("Unread", "");
586                                 }                       
587                         }
588                 }
589
590                 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
591
592                 var feeds_stored = number_of_feeds;
593
594                 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
595
596                 if (feeds_stored != feeds_found) {
597                         number_of_feeds = feeds_found;
598
599                         if (feeds_stored != 0 && feeds_found != 0) {
600                                 debug("Subscribed feed number changed, refreshing feedlist");
601                                 setTimeout('updateFeedList(false, false)', 50);
602                         }
603                 }
604
605         } catch (e) {
606                 exception_error("parse_counters", e);
607         }
608 }
609
610 function parse_counters_reply(transport, scheduled_call) {
611
612         if (!transport.responseXML) {
613                 notify_error("Backend did not return valid XML", true);
614                 return;
615         }
616
617         var reply = transport.responseXML.firstChild;
618         
619         if (!reply) {
620                 notify_error("Backend did not return expected XML object", true);
621                 updateTitle("");
622                 return;
623         } 
624         
625         var error_code = false;
626         var error_msg = false;
627
628         if (reply.firstChild) {
629                 error_code = reply.firstChild.getAttribute("error-code");
630                 error_msg = reply.firstChild.getAttribute("error-msg");
631         }
632
633         if (!error_code) {      
634                 error_code = reply.getAttribute("error-code");
635                 error_msg = reply.getAttribute("error-msg");
636         }
637         
638         if (error_code && error_code != 0) {
639                 debug("refetch_callback: got error code " + error_code);
640                 return fatalError(error_code, error_msg);
641         }
642
643         var counters = reply.getElementsByTagName("counters")[0];
644         
645         parse_counters(counters, scheduled_call);
646
647         var runtime_info = reply.getElementsByTagName("runtime-info")[0];
648
649         parse_runtime_info(runtime_info);
650
651         if (getInitParam("feeds_sort_by_unread") == 1) {
652                         resort_feedlist();              
653         }       
654
655         hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
656
657 }
658
659 function all_counters_callback2(transport) {
660         try {
661                 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
662                 parse_counters_reply(transport);
663                 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
664
665         } catch (e) {
666                 exception_error("all_counters_callback2", e);
667         }
668 }
669
670 function get_feed_unread(id) {
671         try {
672                 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);      
673         } catch (e) {
674                 exception_error("get_feed_unread", e, true);
675                 return -1;
676         }
677 }
678
679 function get_feed_entry_unread(doc, elem) {
680
681         var id = elem.id.replace("FEEDR-", "");
682
683         if (id <= 0) {
684                 return -1;
685         }
686
687         try {
688                 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);   
689         } catch (e) {
690                 return -1;
691         }
692 }
693
694 function resort_category(doc, node) {
695         debug("resort_category: " + node);
696
697         if (node.hasChildNodes() && node.firstChild.nextSibling != false) {  
698                 for (i = 0; i < node.childNodes.length; i++) {
699                         if (node.childNodes[i].nodeName != "LI") { continue; }
700
701                         if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
702                                 continue;
703                         }
704
705                         for (j = i+1; j < node.childNodes.length; j++) {                        
706                                 if (node.childNodes[j].nodeName != "LI") { continue; }  
707
708                                 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
709                                 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
710
711                                 if (cur_val > tmp_val) {
712                                         tempnode_i = node.childNodes[i].cloneNode(true);
713                                         tempnode_j = node.childNodes[j].cloneNode(true);
714                                         node.replaceChild(tempnode_i, node.childNodes[j]);
715                                         node.replaceChild(tempnode_j, node.childNodes[i]);
716                                 }
717                         }
718
719                 }
720         }
721
722 }
723
724 function resort_feedlist() {
725         debug("resort_feedlist");
726
727         var fd = document;
728
729         if (fd.getElementById("feedCatHolder")) {
730
731                 var feeds = fd.getElementById("feedList");
732                 var child = feeds.firstChild;
733
734                 while (child) {
735
736                         if (child.id == "feedCatHolder") {
737                                 resort_category(fd, child.firstChild);
738                         }
739         
740                         child = child.nextSibling;
741                 }
742
743         } else {
744                 resort_category(fd, fd.getElementById("feedList"));
745         }
746 }
747
748 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
749   * * @author Sundar Dorai-Raj
750   * * Email: sdoraira@vt.edu
751   * * This program is free software; you can redistribute it and/or
752   * * modify it under the terms of the GNU General Public License 
753   * * as published by the Free Software Foundation; either version 2 
754   * * of the License, or (at your option) any later version, 
755   * * provided that any use properly credits the author. 
756   * * This program is distributed in the hope that it will be useful,
757   * * but WITHOUT ANY WARRANTY; without even the implied warranty of
758   * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
759   * * GNU General Public License for more details at http://www.gnu.org * * */
760
761   var numbers=".0123456789";
762   function isNumeric(x) {
763     // is x a String or a character?
764     if(x.length>1) {
765       // remove negative sign
766       x=Math.abs(x)+"";
767       for(j=0;j<x.length;j++) {
768         // call isNumeric recursively for each character
769         number=isNumeric(x.substring(j,j+1));
770         if(!number) return number;
771       }
772       return number;
773     }
774     else {
775       // if x is number return true
776       if(numbers.indexOf(x)>=0) return true;
777       return false;
778     }
779   }
780
781
782 function hideOrShowFeeds(doc, hide) {
783
784         debug("hideOrShowFeeds: " + doc + ", " + hide);
785
786         var fd = document;
787
788         var list = fd.getElementById("feedList");
789
790         if (fd.getElementById("feedCatHolder")) {
791
792                 var feeds = fd.getElementById("feedList");
793                 var child = feeds.firstChild;
794
795                 while (child) {
796
797                         if (child.id == "feedCatHolder") {
798                                 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
799                         }
800         
801                         child = child.nextSibling;
802                 }
803
804         } else {
805                 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
806         }
807 }
808
809 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
810
811 //      debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
812
813         var cat_unread = 0;
814
815         if (!node) {
816                 debug("hideOrShowFeeds: passed node is null, aborting");
817                 return;
818         }
819
820 //      debug("cat: " + node.id);
821
822         if (node.hasChildNodes() && node.firstChild.nextSibling != false) {  
823                 for (i = 0; i < node.childNodes.length; i++) {
824                         if (node.childNodes[i].nodeName != "LI") { continue; }
825
826                         if (node.childNodes[i].style != undefined) {
827
828                                 var has_unread = (node.childNodes[i].className != "feed" &&
829                                         node.childNodes[i].className != "label" && 
830                                         !(!getInitParam("hide_read_shows_special") && 
831                                                 node.childNodes[i].className == "virt") && 
832                                         node.childNodes[i].className != "error" && 
833                                         node.childNodes[i].className != "tag");
834         
835 //                              debug(node.childNodes[i].id + " --> " + has_unread);
836         
837                                 if (hide && !has_unread) {
838                                         //node.childNodes[i].style.display = "none";
839                                         var id = node.childNodes[i].id;
840                                         Effect.Fade(node.childNodes[i], {duration : 0.3, 
841                                                 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
842                                 }
843         
844                                 if (!hide) {
845                                         node.childNodes[i].style.display = "list-item";
846                                         //Effect.Appear(node.childNodes[i], {duration : 0.3});
847                                 }
848         
849                                 if (has_unread) {
850                                         node.childNodes[i].style.display = "list-item";
851                                         cat_unread++;
852                                         //Effect.Appear(node.childNodes[i], {duration : 0.3});
853                                         //Effect.Highlight(node.childNodes[i]);
854                                 }
855                         }
856                 }
857         }       
858
859 //      debug("end cat: " + node.id + " unread " + cat_unread);
860
861         if (cat_unread == 0) {
862                 if (cat_node.style == undefined) {
863                         debug("ERROR: supplied cat_node " + cat_node + 
864                                 " has no styles. WTF?");
865                         return;
866                 }
867                 if (hide) {
868                         //cat_node.style.display = "none";
869                         Effect.Fade(cat_node, {duration : 0.3, 
870                                 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
871                 } else {
872                         cat_node.style.display = "list-item";
873                 }
874         } else {
875                 try {
876                         cat_node.style.display = "list-item";
877                 } catch (e) {
878                         debug(e);
879                 }
880         }
881
882 //      debug("unread for category: " + cat_unread);
883 }
884
885 function selectTableRow(r, do_select) {
886         r.className = r.className.replace("Selected", "");
887         
888         if (do_select) {
889                 r.className = r.className + "Selected";
890         }
891 }
892
893 function selectTableRowById(elem_id, check_id, do_select) {
894
895         try {
896
897                 var row = document.getElementById(elem_id);
898
899                 if (row) {
900                         selectTableRow(row, do_select);
901                 }               
902
903                 var check = document.getElementById(check_id);
904
905                 if (check) {
906                         check.checked = do_select;
907                 }
908         } catch (e) {
909                 exception_error("selectTableRowById", e);
910         }
911 }
912
913 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select, 
914         classcheck, reset_others) {
915
916         var content = document.getElementById(content_id);
917
918         if (!content) {
919                 alert("[selectTableRows] Element " + content_id + " not found.");
920                 return;
921         }
922
923         for (i = 0; i < content.rows.length; i++) {
924                 if (Element.visible(content.rows[i])) {
925                         if (!classcheck || content.rows[i].className.match(classcheck)) {
926                 
927                                 if (content.rows[i].id.match(prefix)) {
928                                         selectTableRow(content.rows[i], do_select);
929                                 
930                                         var row_id = content.rows[i].id.replace(prefix, "");
931                                         var check = document.getElementById(check_prefix + row_id);
932         
933                                         if (check) {
934                                                 check.checked = do_select;
935                                         }
936                                 } else if (reset_others) {
937                                         selectTableRow(content.rows[i], false);
938         
939                                         var row_id = content.rows[i].id.replace(prefix, "");
940                                         var check = document.getElementById(check_prefix + row_id);
941         
942                                         if (check) {
943                                                 check.checked = false;
944                                         }
945         
946                                 }
947                         } else if (reset_others) {
948                                 selectTableRow(content.rows[i], false);
949         
950                                 var row_id = content.rows[i].id.replace(prefix, "");
951                                 var check = document.getElementById(check_prefix + row_id);
952         
953                                 if (check) {
954                                         check.checked = false;
955                                 }
956         
957                         }
958                 }
959         }
960 }
961
962 function getSelectedTableRowIds(content_id, prefix) {
963
964         var content = document.getElementById(content_id);
965
966         if (!content) {
967                 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
968                 return;
969         }
970
971         var sel_rows = new Array();
972
973         for (i = 0; i < content.rows.length; i++) {
974                 if (content.rows[i].id.match(prefix) && 
975                                 content.rows[i].className.match("Selected")) {
976                                 
977                         var row_id = content.rows[i].id.replace(prefix + "-", "");
978                         sel_rows.push(row_id);  
979                 }
980         }
981
982         return sel_rows;
983
984 }
985
986 function toggleSelectRowById(sender, id) {
987         var row = document.getElementById(id);
988
989         if (sender.checked) {
990                 if (!row.className.match("Selected")) {
991                         row.className = row.className + "Selected";
992                 }
993         } else {
994                 if (row.className.match("Selected")) {
995                         row.className = row.className.replace("Selected", "");
996                 }
997         }
998 }
999
1000 function toggleSelectListRow(sender) {
1001         var parent_row = sender.parentNode;
1002
1003         if (sender.checked) {
1004                 if (!parent_row.className.match("Selected")) {
1005                         parent_row.className = parent_row.className + "Selected";
1006                 }
1007         } else {
1008                 if (parent_row.className.match("Selected")) {
1009                         parent_row.className = parent_row.className.replace("Selected", "");
1010                 }
1011         }
1012 }
1013
1014 function tSR(sender) {
1015         return toggleSelectRow(sender);
1016 }
1017
1018 function toggleSelectRow(sender) {
1019         var parent_row = sender.parentNode.parentNode;
1020
1021         if (sender.checked) {
1022                 if (!parent_row.className.match("Selected")) {
1023                         parent_row.className = parent_row.className + "Selected";
1024                 }
1025         } else {
1026                 if (parent_row.className.match("Selected")) {
1027                         parent_row.className = parent_row.className.replace("Selected", "");
1028                 }
1029         }
1030 }
1031
1032 function getRelativeFeedId(list, id, direction, unread_only) {  
1033         var rows = list.getElementsByTagName("LI");
1034         var feeds = new Array();
1035
1036         for (var i = 0; i < rows.length; i++) {
1037                 if (rows[i].id.match("FEEDR-")) {
1038
1039                         if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1040
1041                                 if (!unread_only || 
1042                                                 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1043                                         feeds.push(rows[i].id.replace("FEEDR-", ""));
1044                                 }
1045                         }
1046                 }
1047         }
1048
1049         if (!id) {
1050                 if (direction == "next") {
1051                         return feeds.shift();
1052                 } else {
1053                         return feeds.pop();
1054                 }
1055         } else {
1056                 if (direction == "next") {
1057                         var idx = feeds.indexOf(id);
1058                         if (idx != -1 && idx < feeds.length) {
1059                                 return feeds[idx+1];                                    
1060                         } else {
1061                                 return getRelativeFeedId(list, false, direction, unread_only);
1062                         }
1063                 } else {
1064                         var idx = feeds.indexOf(id);
1065                         if (idx > 0) {
1066                                 return feeds[idx-1];
1067                         } else {
1068                                 return getRelativeFeedId(list, false, direction, unread_only);
1069                         }
1070                 }
1071
1072         }
1073 }
1074
1075 function showBlockElement(id, h_id) {
1076         var elem = document.getElementById(id);
1077
1078         if (elem) {
1079                 elem.style.display = "block";
1080
1081                 if (h_id) {
1082                         elem = document.getElementById(h_id);
1083                         if (elem) {
1084                                 elem.style.display = "none";
1085                         }
1086                 }
1087         } else {
1088                 alert("[showBlockElement] can't find element with id " + id);
1089         } 
1090 }
1091
1092 function appearBlockElement_afh(effect) {
1093
1094 }
1095
1096 function checkboxToggleElement(elem, id) {
1097         if (elem.checked) {
1098                 Effect.SlideDown(id, {duration : 0.5});
1099         } else {
1100                 Effect.SlideUp(id, {duration : 0.5});
1101         }
1102 }
1103
1104 function appearBlockElement(id, h_id) {
1105
1106         try {
1107                 if (h_id) {
1108                         Effect.Fade(h_id);
1109                 }
1110                 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1111         } catch (e) {
1112                 exception_error("appearBlockElement", e);
1113         }
1114
1115 }
1116
1117 function hideParentElement(e) {
1118         e.parentNode.style.display = "none";
1119 }
1120
1121 function dropboxSelect(e, v) {
1122         for (i = 0; i < e.length; i++) {
1123                 if (e[i].value == v) {
1124                         e.selectedIndex = i;
1125                         break;
1126                 }
1127         }
1128 }
1129
1130 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1131 // bugfixed just a little bit :-)
1132 function getURLParam(strParamName){
1133   var strReturn = "";
1134   var strHref = window.location.href;
1135
1136   if (strHref.indexOf("#") == strHref.length-1) {
1137                 strHref = strHref.substring(0, strHref.length-1);
1138   }
1139
1140   if ( strHref.indexOf("?") > -1 ){
1141     var strQueryString = strHref.substr(strHref.indexOf("?"));
1142     var aQueryString = strQueryString.split("&");
1143     for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1144       if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1145         var aParam = aQueryString[iParam].split("=");
1146         strReturn = aParam[1];
1147         break;
1148       }
1149     }
1150   }
1151   return strReturn;
1152
1153
1154 function leading_zero(p) {
1155         var s = String(p);
1156         if (s.length == 1) s = "0" + s;
1157         return s;
1158 }
1159
1160 function closeInfoBox(cleanup) {
1161
1162         if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1163                 var overlay = document.getElementById("dialog_overlay");
1164                 if (overlay) {
1165                         overlay.style.display = "none";
1166                 }
1167         }
1168
1169         var box = document.getElementById('infoBox');
1170         var shadow = document.getElementById('infoBoxShadow');
1171
1172         if (shadow) {
1173                 shadow.style.display = "none";
1174         } else if (box) {
1175                 box.style.display = "none";
1176         }
1177
1178         if (cleanup) box.innerHTML = "&nbsp;";
1179
1180         enableHotkeys();
1181
1182         return false;
1183 }
1184
1185
1186 function displayDlg(id, param) {
1187
1188         notify_progress("Loading, please wait...", true);
1189
1190         disableHotkeys();
1191
1192         var query = "backend.php?op=dlg&id=" +
1193                 param_escape(id) + "&param=" + param_escape(param);
1194
1195         new Ajax.Request(query, {
1196                 onComplete: function (transport) {
1197                         infobox_callback2(transport);
1198                 } });
1199
1200         return false;
1201 }
1202
1203 function infobox_submit_callback2(transport) {
1204         closeInfoBox();
1205
1206         try {
1207                 // called from prefs, reload tab
1208                 if (typeof active_tab != 'undefined' && active_tab) {
1209                         selectTab(active_tab, false);
1210                 }
1211         } catch (e) { }
1212
1213         if (transport.responseText) {
1214                 notify_info(transport.responseText);
1215         }
1216 }
1217
1218 function infobox_callback2(transport) {
1219         try {
1220
1221                 debug("infobox_callback2");
1222
1223                 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1224                         var overlay = document.getElementById("dialog_overlay");
1225                         if (overlay) {
1226                                 overlay.style.display = "block";
1227                         }
1228                 }
1229
1230                 var box = document.getElementById('infoBox');
1231                 var shadow = document.getElementById('infoBoxShadow');
1232                 if (box) {                      
1233
1234                         box.innerHTML=transport.responseText;                   
1235                         if (shadow) {
1236                                 shadow.style.display = "block";
1237                         } else {
1238                                 box.style.display = "block";                            
1239                         }
1240                 }
1241
1242                 /* FIXME this needs to be moved out somewhere */
1243
1244                 if (document.getElementById("tags_choices")) {
1245                         new Ajax.Autocompleter('tags_str', 'tags_choices',
1246                                 "backend.php?op=rpc&subop=completeTags",
1247                                 { tokens: ',', paramName: "search" });
1248                 }
1249
1250                 disableHotkeys();
1251
1252                 notify("");
1253         } catch (e) {
1254                 exception_error("infobox_callback2", e);
1255         }
1256 }
1257
1258 function createFilter() {
1259
1260         try {
1261
1262                 var form = document.forms['filter_add_form'];
1263                 var reg_exp = form.reg_exp.value;
1264         
1265                 if (reg_exp == "") {
1266                         alert(__("Can't add filter: nothing to match on."));
1267                         return false;
1268                 }
1269         
1270                 var query = Form.serialize("filter_add_form");
1271         
1272                 // we can be called from some other tab in Prefs                
1273                 if (typeof active_tab != 'undefined' && active_tab) {
1274                         active_tab = "filterConfig";
1275                 }
1276         
1277                 new Ajax.Request("backend.php?" + query, {
1278                         onComplete: function (transport) {
1279                                 infobox_submit_callback2(transport);
1280                         } });
1281                 
1282                 return true;
1283
1284         } catch (e) {
1285                 exception_error("createFilter", e);
1286         }
1287 }
1288
1289 function toggleSubmitNotEmpty(e, submit_id) {
1290         try {
1291                 document.getElementById(submit_id).disabled = (e.value == "")
1292         } catch (e) {
1293                 exception_error("toggleSubmitNotEmpty", e);
1294         }
1295 }
1296
1297 function isValidURL(s) {
1298         return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1299 }
1300
1301 function subscribeToFeed() {
1302
1303         var form = document.forms['feed_add_form'];
1304         var feed_url = form.feed_url.value;
1305
1306         if (feed_url == "") {
1307                 alert(__("Can't subscribe: no feed URL given."));
1308                 return false;
1309         }
1310
1311         notify_progress(__("Subscribing to feed..."), true);
1312
1313         closeInfoBox();
1314
1315         var feeds_doc = document;
1316
1317 //      feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1318         
1319         var query = Form.serialize("feed_add_form");
1320         
1321         debug("subscribe q: " + query);
1322
1323         new Ajax.Request("backend.php", {
1324                 parameters: query,
1325                 onComplete: function(transport) { 
1326                         dlg_frefresh_callback(transport); 
1327                 } });
1328
1329         return false;
1330 }
1331
1332 function filterCR(e, f)
1333 {
1334      var key;
1335
1336      if(window.event)
1337           key = window.event.keyCode;     //IE
1338      else
1339           key = e.which;     //firefox
1340
1341         if (key == 13) {
1342                 if (typeof f != 'undefined') {
1343                         f();
1344                         return false;
1345                 } else {
1346                         return false;
1347                 }
1348         } else {
1349                 return true;
1350         }
1351 }
1352
1353 function getMainContext() {
1354         return this.window;
1355 }
1356
1357 function getFeedsContext() {
1358         return this.window;
1359 }
1360
1361 function getContentContext() {
1362         return this.window;
1363 }
1364
1365 function getHeadlinesContext() {
1366         return this.window;
1367 }
1368
1369 var debug_last_class = "even";
1370
1371 function debug(msg) {
1372
1373         if (debug_last_class == "even") {
1374                 debug_last_class = "odd";
1375         } else {
1376                 debug_last_class = "even";
1377         }
1378
1379         var c = document.getElementById('debug_output');
1380         if (c && Element.visible(c)) {
1381                 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1382                         c.removeChild(c.lastChild);
1383                 }
1384         
1385                 var d = new Date();
1386                 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1387                         ":" + leading_zero(d.getSeconds());
1388                 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " + 
1389                         msg + "</li>" + c.innerHTML;
1390         }
1391 }
1392
1393 function getInitParam(key) {
1394         return init_params[key];
1395 }
1396
1397 function storeInitParam(key, value) {
1398         debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1399         init_params[key] = value;
1400 }
1401
1402 function fatalError(code, message) {
1403         try {   
1404
1405                 if (code == 6) {
1406                         window.location.href = "tt-rss.php";                    
1407                 } else if (code == 5) {
1408                         window.location.href = "update.php";
1409                 } else {
1410                         var fe = document.getElementById("fatal_error");
1411                         var fc = document.getElementById("fatal_error_msg");
1412         
1413                         if (message == "") message = "Unknown error";
1414
1415                         fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
1416         
1417                         fe.style.display = "block";
1418                 }
1419
1420         } catch (e) {
1421                 exception_error("fatalError", e);
1422         }
1423 }
1424
1425 function getFeedName(id, is_cat) {      
1426         var d = getFeedsContext().document;
1427
1428         var e;
1429
1430         if (is_cat) {
1431                 e = d.getElementById("FCATN-" + id);
1432         } else {
1433                 e = d.getElementById("FEEDN-" + id);
1434         }
1435         if (e) {
1436                 return e.innerHTML.stripTags();
1437         } else {
1438                 return null;
1439         }
1440 }
1441
1442 function viewContentUrl(url) {
1443         getContentContext().location = url;
1444 }
1445
1446 function filterDlgCheckAction(sender) {
1447
1448         try {
1449
1450                 var action = sender[sender.selectedIndex].value;
1451
1452                 var form = document.forms["filter_add_form"];
1453         
1454                 if (!form) {
1455                         form = document.forms["filter_edit_form"];
1456                 }
1457
1458                 if (!form) {
1459                         debug("filterDlgCheckAction: can't find form!");
1460                         return;
1461                 }
1462
1463                 var action_param = form.action_param;
1464
1465                 if (!action_param) {
1466                         debug("filterDlgCheckAction: can't find action param!");
1467                         return;
1468                 }
1469
1470                 // if selected action supports parameters, enable params field
1471                 if (action == 4 || action == 6) {
1472                         action_param.disabled = false;
1473                 } else {
1474                         action_param.disabled = true;
1475                 }
1476
1477         } catch (e) {
1478                 exception_error("filterDlgCheckAction", e);
1479         }
1480
1481 }
1482
1483 function explainError(code) {
1484         return displayDlg("explainError", code);
1485 }
1486
1487 // this only searches loaded headlines list, not in CDM
1488 function getRelativePostIds(id, limit) {
1489
1490         if (!limit) limit = 3;
1491
1492         debug("getRelativePostIds: " + id + " limit=" + limit);
1493
1494         var ids = new Array();
1495         var container = document.getElementById("headlinesList");
1496
1497         if (container) {
1498                 var rows = container.rows;
1499
1500                 for (var i = 0; i < rows.length; i++) {
1501                         var r_id = rows[i].id.replace("RROW-", "");
1502
1503                         if (r_id == id) {
1504                                 for (var k = 1; k <= limit; k++) {
1505                                         var nid = false;
1506
1507                                         if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1508                                         if (nid) ids.push(nid);
1509
1510                                         if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1511                                         if (nid) ids.push(nid);
1512                                 }
1513
1514                                 return ids;
1515                         }
1516                 }
1517         }
1518
1519         return false;
1520 }
1521
1522 function openArticleInNewWindow(id) {
1523         try {
1524                 debug("openArticleInNewWindow: " + id);
1525
1526                 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1527                 var wname = "ttrss_article_" + id;
1528
1529                 debug(query + " " + wname);
1530
1531                 var w = window.open("", wname);
1532
1533                 if (!w) notify_error("Failed to open window for the article");
1534
1535                 new Ajax.Request(query, {
1536                         onComplete: function(transport) { 
1537                                 open_article_callback(transport); 
1538                         } });
1539
1540
1541         } catch (e) {
1542                 exception_error("openArticleInNewWindow", e);
1543         }
1544 }
1545
1546 /* http://textsnippets.com/posts/show/835 */
1547
1548 Position.GetWindowSize = function(w) {
1549         w = w ? w : window;
1550         var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1551         var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1552         return [width, height]
1553 }
1554
1555 /* http://textsnippets.com/posts/show/836 */
1556
1557 Position.Center = function(element, parent) {
1558         var w, h, pw, ph;
1559         var d = Element.getDimensions(element);
1560         w = d.width;
1561         h = d.height;
1562         Position.prepare();
1563         if (!parent) {
1564                 var ws = Position.GetWindowSize();
1565                 pw = ws[0];
1566                 ph = ws[1];
1567         } else {
1568                 pw = parent.offsetWidth;
1569                 ph = parent.offsetHeight;
1570         }
1571         element.style.top = (ph/2) - (h/2) -  Position.deltaY + "px";
1572         element.style.left = (pw/2) - (w/2) -  Position.deltaX + "px";
1573 }
1574
1575
1576 function labeltest_callback(transport) {
1577         try {
1578                 var container = document.getElementById('label_test_result');
1579         
1580                 container.innerHTML = transport.responseText;
1581                 if (!Element.visible(container)) {
1582                         Effect.SlideDown(container, { duration : 0.5 });
1583                 }
1584
1585                 notify("");
1586         } catch (e) {
1587                 exception_error("labeltest_callback", e);
1588         }
1589 }
1590
1591 function labelTest() {
1592
1593         try {
1594                 var container = document.getElementById('label_test_result');
1595         
1596                 var form = document.forms['label_edit_form'];
1597         
1598                 var sql_exp = form.sql_exp.value;
1599                 var description = form.description.value;
1600         
1601                 notify_progress("Loading, please wait...");
1602         
1603                 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1604                         param_escape(sql_exp) + "&descr=" + param_escape(description);
1605         
1606                 new Ajax.Request(query, {
1607                         onComplete: function (transport) {
1608                                 labeltest_callback(transport);
1609                         } });
1610         
1611                 return false;
1612
1613         } catch (e) {
1614                 exception_error("labelTest", e);
1615         }
1616 }
1617
1618 function isCdmMode() {
1619         return !document.getElementById("headlinesList");
1620 }
1621
1622 function getSelectedArticleIds2() {
1623         var rows = new Array();
1624         var cdm_mode = isCdmMode();
1625
1626         if (cdm_mode) {
1627                 rows = cdmGetSelectedArticles();
1628         } else {        
1629                 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1630         }
1631
1632         var ids = new Array();
1633
1634         for (var i = 0; i < rows.length; i++) {
1635                 var chk = document.getElementById("RCHK-" + rows[i]);
1636                 if (chk && chk.checked) {
1637                         ids.push(rows[i]);
1638                 }
1639         }
1640
1641         return ids;
1642 }
1643
1644 function displayHelpInfobox(topic_id) {
1645
1646         var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1647
1648         var w = window.open(url, "ttrss_help", 
1649                 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1650
1651         return false;
1652 }
1653
1654 function focus_element(id) {
1655         try {
1656                 var e = document.getElementById(id);
1657                 if (e) e.focus();
1658         } catch (e) {
1659                 exception_error("focus_element", e);
1660         }
1661         return false;
1662 }
1663
1664 function loading_set_progress(p) {
1665         try {
1666                 if (p < last_progress_point || !Element.visible("overlay")) return;
1667
1668                 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
1669
1670                 var o = document.getElementById("l_progress_i");
1671
1672 //              o.style.width = (p * 2) + "px";
1673
1674                 new Effect.Scale(o, p, { 
1675                         scaleY : false,
1676                         scaleFrom : last_progress_point,
1677                         scaleMode: { originalWidth : 200 },
1678                         queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); 
1679
1680                 last_progress_point = p;
1681
1682         } catch (e) {
1683                 exception_error("loading_set_progress", e);
1684         }
1685 }
1686
1687 function remove_splash() {
1688         if (Element.visible("overlay")) {
1689                 debug("about to remove splash, OMG!");
1690                 Element.hide("overlay");
1691                 debug("removed splash!");
1692         }
1693 }