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