isolation fix
[brisk.git] / web / room.js
1 /*
2  *  brisk - room.js
3  *
4  *  Copyright (C) 2006-2009 Matteo Nastasi
5  *                          mailto: nastasi@alternativeoutput.it 
6  *                                  matteo.nastasi@milug.org
7  *                          web: http://www.alternativeoutput.it
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details. You should have received a
18  * copy of the GNU General Public License along with this program; if
19  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20  * Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23
24
25 /* 
26    data = [ [ flags, name ],  ... ]
27    
28 */
29
30 var l_list_all = 0x00;
31 var l_list_auth = 0x01;
32 var l_list_isol = 0x02;
33
34 function state_add(flags)
35 {
36     var content = "";
37     var st, name = "";
38     var tit = "";
39
40     if ((flags & 0xf00) != 0) {
41         st = flags & 0xf00;
42         // MLANG 4,12,16,20,24,28
43         switch (st) {
44         case 0x100:
45             name = "st_pau.png";
46             tit = (g_lang == 'en' ? "I'm doing a break" : "sono in pausa");
47             break;
48         case 0x200:
49             name = "st_out.png";
50             tit = (g_lang == 'en' ? "I'm away" : "sono fuori");
51             break;
52         case 0x300:
53             name = "st_dog.png";
54             tit = (g_lang == 'en' ? "Dog time" : "sono a spasso col cane");
55             break;
56         case 0x400:
57             name = "st_eat.png";
58             tit = (g_lang == 'en' ? "I'm eating" : "sto mangiando");
59             break;
60         case 0x500:
61             name = "st_wrk.png";
62             tit = (g_lang == 'en' ? "I'm working" : "sono a lavoro");
63             break;
64         case 0x600:
65             name = "st_smk.png";
66             tit = (g_lang == 'en' ? "I'm smoking a sigarett (and keeping a cancer)" : "sto fumando una sigaretta (e facendomi venire il cancro)");
67             break;
68         case 0x700:
69             name = "st_eye.png";
70             tit = (g_lang == 'en' ? "I'm here!" : "sono presente!");
71             break;
72         default:
73             break;
74         }
75         if (name != "") {
76             content += '&nbsp;<img title="'+tit+'" class="unbo" src="img/'+name+'">';
77         }
78     }
79
80     return content;
81 }
82
83 var standup_data_old = null;
84
85 // TODO !!
86 // appendChild , removeChild
87
88 function table_add(curtag, td)
89 {
90     var tbody  = null, tr;
91
92     do {
93         // console.log("wt: "+curtag.tagName);
94
95         if (curtag.tagName.toLowerCase() == "div" || 
96             curtag.tagName.toLowerCase() == "table") {
97             curtag = curtag.firstChild;
98         }
99         else if (curtag.tagName.toLowerCase() == "tbody") {
100             tbody = curtag;
101             break;
102         }
103         else
104             curtag = null;
105     } while (curtag != null);
106     
107     curtag = tbody.firstChild;
108     ct = 0;
109     do {
110         if (curtag.tagName.toLowerCase() == "tr") {
111             if (curtag.firstChild != null) {
112                 curtag = curtag.firstChild;
113                 ct++;
114             }
115             else {
116                 curtag.appendChild(td);
117                 return(true);
118             }
119         }
120         else if (curtag.tagName.toLowerCase() == "td") {
121             if (curtag.nextSibling != null) {
122                 curtag = curtag.nextSibling;
123                 ct++;
124             }
125             else {
126                 if (ct < 4) {
127                     curtag.parentNode.appendChild(td);
128                     return (true);
129                 }
130                 else {
131                     ct = 0;
132                     curtag = curtag.parentNode.nextSibling;
133                 }
134             }
135         }
136         else {
137             curtag = curtag.parentNode;
138         }
139
140     } while (curtag != null);
141
142     tr = document.createElement("tr");
143     tr.appendChild(td);
144     tbody.appendChild(tr);
145
146     return (true);
147 }
148
149 function spcs(c1, c2, n)
150 {
151     var ret = "";
152     var i;
153
154     for (i = 0 ; i < n ; i++) {
155         if ((i % 2) == 0)
156             ret += c1;
157         else
158             ret += c2;
159     }
160
161     return (ret);
162 }
163
164
165 function table_walk(curtag)
166 {
167     do {
168         // console.log("wt: "+curtag.tagName);
169         if (curtag.tagName.toLowerCase() == "div" || 
170             curtag.tagName.toLowerCase() == "table" ||
171             curtag.tagName.toLowerCase() == "tbody") {
172             curtag = curtag.firstChild;
173         }
174         else if (curtag.tagName.toLowerCase() == "tr") {
175             if (curtag.firstChild != null)
176                 curtag = curtag.firstChild;
177             else if (curtag.tagName != '')
178                 curtag = curtag.nextSibling;
179             else
180                 curtag = null;
181         }
182         else if (curtag.tagName.toLowerCase() == "td") {
183             if (curtag.nextSibling != null)
184                 curtag = curtag.nextSibling;
185             else {
186                 if (curtag.parentNode.nextSibling != null && curtag.parentNode.nextSibling.tagName != '')
187                     curtag = curtag.parentNode.nextSibling;
188                 else
189                     curtag = null;
190             }
191         }
192         else
193             curtag = null;
194
195     } while (curtag != null && curtag.tagName.toLowerCase() != "td");
196
197     if (1 == 0) {
198         if (curtag == null)
199             alert("outtag == null"); 
200         else
201             alert("outtag: "+curtag.tagName);
202     }
203     return (curtag);
204 }
205
206 function j_stand_tdcont(el)
207 {
208     var content = "";
209
210     if (el[0] & 0x01)
211         content += '<b>';
212     
213     if (el[0] & 0x02)
214         content += '<i>';
215     
216     content += el[1];
217     
218     if (el[0] & 0x02)
219         content += '</i>';
220     
221     if (el[0] & 0x01)
222         content += '</b>';
223             
224     content += state_add(el[0]);
225     
226     return (content);
227 }
228
229 function j_stand_cont(ddata)
230 {
231     var i, ii;
232     var content;
233     var st = 0, name = "";
234     var curtag, nextag;
235
236     var data;
237
238     if (g_listen & l_list_isol) {
239         data = new Array();
240
241         for (i = 0, ii = 0 ; ii < ddata.length ; ii++) {
242             if ((ddata[ii][0] & 0x02) == 0) {
243                 continue;
244             }
245             data[i++] = ddata[ii];
246         }
247     }
248     else
249         data = ddata;
250
251     if (standup_data_old == null || data.length < 4) {
252     // if (standup_data_old == null) {
253         
254         content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
255         for (i = 0 ; i < data.length ; i++) {
256             if ((i % 4) == 0)
257                 content += '<tr>';
258             content += '<td id="'+i+'" class="room_standup">';
259             content += j_stand_tdcont(data[i]);
260             content += '</td>';
261             
262             if ((i % 4) == 3)
263                 content += '</tr>';
264
265             i++;
266         }
267         if ((i % 4) < 3)
268             content += '</tr>';
269         content += '</table>';
270         
271         $("standup").innerHTML = content;
272
273         // console.log("inizio");
274         // for (i = 0 , curtag = table_walk($("standup")) ; curtag != null ;  curtag = table_walk(curtag), i++ ) {
275         //     console.log("inloop["+i+"]: "+curtag.tagName+"  ID: "+curtag.id);
276         // }
277         // console.log("fine "+i);
278
279         // walktable($("standup"), nextag);
280         // console.log($("standup").firstChild);
281         // console.log($("standup").firstChild.firstChild.firstChild.firstChild);
282
283         // log_walk($("standup"));
284
285         standup_data_old = data;
286     }
287     else {
288         var idx_del, arr_add, idx_mod, arr_mod;
289         var idx_del_n = 0, idx_add_n = 0, idx_mod_n = 0;
290         var i, e;
291         var i_del, i_mod, i_add;
292         var td;
293
294         idx_del = new Array();
295         arr_add = new Array();
296         map_add = new Array();
297         idx_mod = new Array();
298         arr_mod = new Array();
299         map_cur = new Array();
300         
301         // find removed entries
302         for (i = 0 ; i < standup_data_old.length ; i++) {
303             for (e = 0 ; e < data.length ; e++) {
304                 if (standup_data_old[i][1] == data[e][1]) {
305                     break;
306                 }
307             }
308             if (e == data.length) {
309                 idx_del[idx_del_n++] = i;
310                 map_cur[i] = -1;
311             }
312             else {
313                 /* modified entries */
314                 if (standup_data_old[i][0] != data[e][0]) {
315                     arr_mod[idx_mod_n] = data[e];
316                     idx_mod[idx_mod_n++] = i;
317                 }
318                 map_cur[i] = e;
319             }
320         }
321
322         // find new entries
323         for (e = 0 ; e < data.length ; e++) {
324             for (i = 0 ; i < standup_data_old.length ; i++) {
325                 if (data[e][1] == standup_data_old[i][1] ) {
326                     break;
327                 }
328             }
329             if (i == standup_data_old.length) {
330                 // console.log("ADD: "+data[e][1]);
331                 arr_add[idx_add_n]   = data[e];
332                 map_add[idx_add_n++] = e;
333             }
334         }
335         
336         // TODO: qui travaso add in del
337
338         i_del = 0;
339         // alert("del: ["+j_stand_tdcont(standup_data_old[idx_del[i_del]])+"]");
340         for (i = 0 , i_del = 0, i_mod = 0, i_add = 0, curtag = table_walk($("standup")) ; curtag != null ;  curtag = table_walk(curtag), i++ ) {
341             // console.log("cur.id: "+curtag.id);
342
343             // alert("i: "+i+"  tagname: "+curtag.tagName+"  innerHTML: ["+curtag.innerHTML+"]");
344             // console.log("inloop["+i+"]: "+curtag.tagName+"  ID: "+curtag.id);
345             if (curtag.innerHTML == "") {
346                 // console.log("innerHTML == none");
347                 if (i_add < idx_add_n) {
348                     // console.log("  to be new");
349                     // console.log("  add:   CONT:"+j_stand_tdcont(arr_add[i_add]));
350                     curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
351                     curtag.id = map_add[i_add];
352                     i_add++
353                 }
354             }
355
356             // else if (i_del < idx_del_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_del[i_del]])) {
357             else if (i_del < idx_del_n && curtag.id == idx_del[i_del]) {
358                 // console.log("to be cancel["+i+"]:  ID: "+curtag.id);
359                 if (i_add < idx_add_n) {
360                     // console.log("  to be new");
361                     // console.log("  add:   CONT:"+j_stand_tdcont(arr_add[i_add]));
362                     curtag.innerHTML = j_stand_tdcont(arr_add[i_add]);
363                     curtag.id = map_add[i_add];
364                     i_add++
365                 }
366                 else {
367                     // console.log("  to be del");
368                     curtag.innerHTML = "";
369                     curtag.id = -1;
370                 }
371                 i_del++;
372             }
373             // else if (i_mod < idx_mod_n && curtag.innerHTML == j_stand_tdcont(standup_data_old[idx_mod[i_mod]])) {
374             else if (i_mod < idx_mod_n && curtag.id == idx_mod[i_mod]) {
375                 // console.log("  to be mod");
376                 // console.log("mod: "+idx_mod[i_mod]+ "  CONT:"+j_stand_tdcont(arr_mod[i_mod]));
377                 curtag.innerHTML = j_stand_tdcont(arr_mod[i_mod]);
378                 curtag.id = map_cur[curtag.id];
379                 i_mod++;
380             }
381             else
382                 curtag.id = map_cur[curtag.id];
383         }
384         // console.log("fineloop");
385
386         for (i ; i_add < idx_add_n ; i_add++, i++) {
387             // console.log("ADD: "+i+" arr_add: "+ arr_add[i_add][1]);
388             td = document.createElement("td");
389             td.className = "room_standup";
390             td.id = map_add[i_add];
391             td.innerHTML = j_stand_tdcont(arr_add[i_add]);
392
393             table_add($("standup"), td);
394         }
395
396         standup_data_old = data;
397         return;
398     }
399     // $("esco").innerHTML =  '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
400 }
401
402 function esco_cb() {
403     window.onbeforeunload = null; 
404     window.onunload = null; 
405     // nonunload = true; 
406     act_logout();
407  };
408
409
410
411 function j_tab_cont(table_idx, data)
412 {
413     var i;
414     var content = '';
415
416     for (i = 0 ; i < data.length ; i++) {
417         if (data[i][0] & 0x01)
418             content += '<b>';
419
420         if (data[i][0] & 0x02)
421             content += '<i>';
422
423         content += data[i][1];
424         
425         if (data[i][0] & 0x02)
426             content += '</i>';
427
428         if (data[i][0] & 0x01)
429             content += '</b>';
430         content += state_add(data[i][0]);
431
432         content += '<br>';
433     }
434     $("table"+table_idx).innerHTML = content;
435 }
436
437 function j_tab_act_cont(idx, act)
438 {
439     if (act == 'sit') {
440         // MLANG 1
441         $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'"  value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
442     }
443     else if (act == 'sitreser') {
444         // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
445         // MLANG 1
446         $("table_act"+idx).innerHTML = '<input type="button" style="background-repeat: no-repeat; background-position: center; background-image: url(\'img/okauth.png\');" class="button" name="xhenter'+idx+'"  value="'+(g_lang == 'en' ? "Sit down." : "Mi siedo.")+'" onclick="act_sitdown('+idx+');">';
447     }
448     else if (act == 'wake') {
449         // MLANG 1
450         $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup"  value="'+(g_lang == 'en' ? "Wake up." : "Mi alzo.")+'" onclick="act_wakeup();">';
451     }
452     else if (act == 'reserved') {
453         // MLANG 1
454         $("table_act"+idx).innerHTML = '<img class="nobo" title="'+(g_lang == 'en' ? "reserved table for authenticated users only" : "tavolo riservato agli utenti registrati")+'" style="margin-right: 20px;" src="img/onlyauth.png">';
455     }
456     else {
457         $("table_act"+idx).innerHTML = '';
458     }
459 }
460
461 function j_login_manager(form)
462 {
463     var token;
464
465     if (form.elements['passid'].value == '')
466         return (true);
467
468     else {
469         // console.log("richiesta token");
470         /* richiede token */
471         token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
472         tokens = token.split('|');
473         
474         // console.log('XX token: '+token);
475         // console.log(tokens);
476         if (token == null)
477             return (false);
478
479         token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
480         
481         form.elements['passid_private'].value = token;
482         form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
483
484         return (true);
485     }
486     
487     return (false);
488 }
489
490 function login_formtext_hilite()
491 {
492     formtext_hilite($("nameid"));
493     formtext_hilite($("passid"));
494     formsub_hilite($("sub"));
495 }
496
497 function login_init()
498 {
499     menu_init();
500     login_formtext_hilite();
501 }
502
503 function warrant_formtext_hilite(form)
504 {
505     /*
506     formtext_hilite($("nameid"));
507     formtext_hilite($("emailid"));
508     formsub_hilite($("subid"));
509     formsub_hilite($("cloid"));
510     */
511     formtext_hilite(form.elements['name']);
512     formtext_hilite(form.elements['email']);
513     formsub_hilite(form.elements['sub']);
514     formsub_hilite(form.elements['clo']);
515 }
516
517 function mesgtoadm_formtext_hilite(form)
518 {
519     /*
520     formtext_hilite($("subjid"));
521     formtext_hilite($("mesgid"));
522     formsub_hilite($("subid"));
523     formsub_hilite($("cloid"));
524     */
525     formtext_hilite(form.elements['subj']);
526     formtext_hilite(form.elements['mesg']);
527     formsub_hilite(form.elements['sub']);
528     formsub_hilite(form.elements['clo']);
529 }
530
531
532 function j_check_email(email)
533 {
534     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
535         return (true);
536     return (false);
537 }
538
539 function j_authbox(form)
540 {
541     var no; 
542
543     do {
544         if (form.elements['realsub'].value == "chiudi") {
545             $('authbox').style.visibility = "hidden";
546             break;
547         }
548
549         if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false) {
550             // MLANG 2-4
551             no = new notify(gst, 
552                             (g_lang == 'en' ? "<br><b>nickname</b> and/or <b>e-mail</b> fields are invalid;<br>please, fix them." :
553                              "<br>I campi <b>nickname</b> e/o <b>e-mail</b> non sono validi;<br> correggeteli per favore."),
554                             1, (g_lang == 'en' ? "close" : "chiudi"), 280, 100); 
555             break;
556         }
557
558         // submit the request
559         token = server_request('mesg', 'warranty', 
560                                'cli_name', encodeURIComponent(form.elements['name'].value),
561                                'cli_email', encodeURIComponent(form.elements['email'].value) );
562         if (token == "1") {
563             $('authbox').style.visibility = "hidden";
564             form.elements['name'].value = "";
565             form.elements['email'].value = "";
566             break;
567         }
568     } while (0);
569
570     return (false);
571 }
572
573 function authbox(w, h)
574 {
575     var box;
576
577     box = $('authbox');
578
579     box.style.zIndex = 200;
580     box.style.width  = w+"px";
581     box.style.marginLeft  = -parseInt(w/2)+"px";
582     box.style.height = h+"px";
583     box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
584
585     warrant_formtext_hilite($('auth_form'));
586
587     box.style.visibility = "visible";
588     $("nameid").focus();
589 }
590
591 function j_mesgtoadmbox(form)
592 {
593     var no; 
594
595     do {
596         if (form.elements['realsub'].value == "chiudi") {
597             $('mesgtoadmbox').style.visibility = "hidden";
598             break;
599         }
600
601         if (form.elements['mesg'].value == '' || form.elements['subj'].value == '') {
602             // MLANG 1-3
603             no = new notify(gst, (g_lang == 'en' ? "<br><b>subject</b> and the <b>message</b> cannot be void;<br>please, fix them." :
604                                   "<br>Il <b>soggetto</b> e il <b>messaggo</b> non possono essere vuoti;<br>correggeteli per favore."), 1, 
605                                   (g_lang == 'en' ? "close" : "chiudi"), 280, 100); 
606             break;
607         }
608                 
609         // submit the request
610         token = server_request('mesg', 'mesgtoadm', 
611                                'cli_subj', encodeURIComponent(form.elements['subj'].value),
612                                'cli_mesg', encodeURIComponent(form.elements['mesg'].value) );
613         if (token == "1") {
614             $('mesgtoadmbox').style.visibility = "hidden";
615             form.elements['subj'].value = "";
616             form.elements['mesg'].value = "";
617             break;
618         }
619     } while (0);
620
621     return (false);
622 }
623
624 function mesgtoadmbox(w, h)
625 {
626     var box;
627
628     box = $('mesgtoadmbox');
629
630     box.style.zIndex = 200;
631     box.style.width  = w+"px";
632     box.style.marginLeft  = -parseInt(w/2)+"px";
633     box.style.height = h+"px";
634     box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
635
636     mesgtoadm_formtext_hilite($('mesgtoadm_form'));
637
638     box.style.visibility = "visible";
639     $('mesgtoadm_form').elements['subj'].focus();
640 }
641
642 function j_pollbox(form)
643 {
644     var no, i, choose; 
645
646     do {
647         // submit the request
648         
649         for (i = 0 ; i < form.elements.length ; i++) {
650             if (form.elements[i].checked == true)
651                 break;
652         }
653         if (i == form.elements.length) {
654             // MLANG 1-3
655             no = new notify(gst, (g_lang == 'en' ? "<br>You must choose ah item;<br> please, fix it." :
656                                   "<br>Non hai espresso nessuna preferenza;<br> correggi per favore."), 1, 
657                             (g_lang == 'en' ? "close" : "chiudi"), 280, 100); 
658             return false;
659         }
660         else
661             choose = form.elements[i].value;
662
663         token = server_request('mesg', 'poll', 
664                                'cli_choose', encodeURIComponent(choose) );
665
666         if (token == "1") {
667             // TODO: mesg to user
668             // $('mesgtoadmbox').style.visibility = "hidden";
669             break;
670         }
671     } while (0);
672
673     return (false);
674 }
675
676
677
678
679 function list_set(what, is_update, info)
680 {
681     // console.log(what);
682     var i;
683     var relo = false;
684     var old_st = readCookie("CO_list");
685     
686     if (what == 'auth') {
687         $('list_auth').style.color = 'red';
688         $('list_isol').style.color = 'black';
689         $('list_all').style.color = 'black';
690         if (old_st == 'isolation')
691             relo = true;
692         g_listen = l_list_auth;
693     }
694     else if (what == 'isolation') {
695         $('list_auth').style.color = 'black';
696         $('list_isol').style.color = 'red';
697         $('list_all').style.color = 'black';
698         if (old_st != 'isolation')
699             relo = true;
700         g_listen = l_list_isol;
701     }
702     else {
703         $('list_auth').style.color = 'black';
704         $('list_isol').style.color = 'black';
705         $('list_all').style.color = 'red';
706         if (old_st == 'isolation')
707             relo = true;
708         g_listen = l_list_all;
709     }
710     $('list_info').innerHTML = info;
711     if (is_update) {
712         createCookie("CO_list", what, 24*365, cookiepath);
713     }
714
715
716     if (relo || !is_update) {
717         for (i = g_tables_auth_n ; i < g_tables_n ; i++) {
718             
719             if (i % 4 == 0) {
720                 $('tr_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
721             }
722             
723             $('td_noauth'+i).style.display = (what == 'isolation' ? 'none' : '');
724         }
725         // ricalculation of standup area
726         if (standup_data_old != null) {
727             standup_data = standup_data_old;
728             standup_data_old = null;
729             j_stand_cont(standup_data);
730         }
731     }
732 }
733
734 function sideslide(domobj, height, step)
735 {
736     this.st = 'wait';
737     this.twait = 5000;
738
739     this.domobj = domobj;
740     this.height = height;
741     this.step = step;
742
743     this.start();
744 }
745
746 sideslide.prototype = {
747     id: null,
748     st: 'wait',
749     twait: 0,
750     scroll: 0,
751     countdown: 0,
752
753     domobj: null,
754     height: 0,
755     step: 0,
756
757     start: function() {
758         var instant = this;
759         
760         this.st = 'wait';
761         this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
762     },
763
764     sideslide_cb: function() {
765         var instant = this;
766
767         if (this.st == 'wait') {
768             this.st = 'scroll';
769             this.countdown = 10;
770             this.id = setInterval(function () { instant.sideslide_cb(); }, 100);
771         }
772         else if (this.st == 'scroll') {
773             this.scroll += (this.step / 10);
774             if (this.scroll >= this.height - this.step) {
775                 this.scroll = 0;
776             }
777             this.domobj.scrollTop = this.scroll;
778             this.countdown--;
779             if (this.countdown == 0) {
780                 this.stop();
781                 this.st = 'wait';
782                 this.id = setTimeout(function () { instant.sideslide_cb(); }, this.twait);
783             }
784         }
785     },
786
787
788     stop: function() {
789         if (this.id != null) {
790             clearInterval(this.id);
791             this.id = null;
792         }
793     }
794
795 }