placing instead of classific
[brisk.git] / web / commons.js
1 /*
2  *  brisk - commons.js
3  *
4  *  Copyright (C) 2006-2008 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  * $Id$
23  *
24  */
25
26 var PLAYERS_N = 3;
27 var EXIT_BAN_TIME = 900;
28 var cookiepath = "/brisk/";
29
30 var mlang_commons = { 'imgload_a' : { 'it' : 'Immagine caricate ', 
31                                       'en' : 'Loaded images ' },
32                       'imgload_b' : { 'it' : '%.', 
33                                       'en' : '%.' },
34                       'gamleav'   : { 'it' : 'Sei sicuro di volere lasciare questa mano?' ,
35                                       'en' : 'Are you sure to leave this game?' },
36                       'brileav'   : { 'it' : '    Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)',
37                                       'en' : '    Are you really sure to leave briscola ?\n(click cancel yo reload it)' },
38                       'brireco'   : { 'it' : 'Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.',
39                                       'en' : 'Recovery of briscola failed, to keep the current session reload the page manually.' },
40                       'btn_sit'   : { 'it' : 'Mi siedo.',
41                                       'en' : 'Sit down.' },
42                       'btn_exit'  : { 'it' : 'Esco.',
43                                       'en' : 'Exit.' }
44                       
45                       };
46
47 function $(id) { return document.getElementById(id); }
48
49 function getStyle(x,IEstyleProp, MozStyleProp) 
50 {
51     if (x.currentStyle) {
52         var y = x.currentStyle[IEstyleProp];
53     } else if (window.getComputedStyle) {
54         var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
55     }
56     return y;
57 }
58
59 /* replacement of setInterval on IE */
60 (function(){
61     /*if not IE, do nothing*/
62     if(!document.uniqueID){return;};
63
64     /*Copy the default setInterval behavior*/
65     var nativeSetInterval = window.setInterval;
66     window.setInterval = function(fn,ms) {              
67         var param = [];
68         if(arguments.length <= 2)       {
69             return nativeSetInterval(fn,ms);
70         }
71         else {
72             for(var i=2;i<arguments.length;i+=1) {
73                 param[i-2] =  arguments[i];
74             }   
75         }
76         
77         if(typeof(fn)=='function') {
78             
79             return (function (fn,ms,param) {
80                 var fo = function () {                                                          
81                     fn.apply(window,param);
82                 };                      
83                 return nativeSetInterval(fo,ms); 
84             })(fn,ms,param);
85         }
86         else if(typeof(fn)=='string')
87         {
88             return  nativeSetInterval(fn,ms);
89         }
90         else
91         {
92             throw Error('setInterval Error\nInvalid function type');
93         };
94     };
95
96     /*Copy the default setTimeout behavior*/
97     var nativeSetTimeout = window.setTimeout;
98     window.setTimeout = function(fn,ms) {               
99         var param = [];
100         if(arguments.length <= 2)       {
101             return nativeSetTimeout(fn,ms);
102         }
103         else {
104             for(var i=2;i<arguments.length;i+=1) {
105                 param[i-2] =  arguments[i];
106             }   
107         }
108         
109         if(typeof(fn)=='function') {
110             
111             return (function (fn,ms,param) {
112                 var fo = function () {                                                          
113                     fn.apply(window,param);
114                 };                      
115                 return nativeSetTimeout(fo,ms); 
116             })(fn,ms,param);
117         }
118         else if(typeof(fn)=='string')
119         {
120             return  nativeSetTimeout(fn,ms);
121         }
122         else
123         {
124             throw Error('setTimeout Error\nInvalid function type');
125         };
126     };
127
128 })()
129
130 function addEvent(obj,type,fn)
131 {
132     if (obj.addEventListener) {
133         obj.addEventListener( type, fn, false);
134     }
135     else if (obj.attachEvent) {
136         obj["e"+type+fn] = fn;
137         obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
138         obj.attachEvent( "on"+type, obj[type+fn] );
139     }
140     else
141         throw new Error("Event registration not supported");
142 }
143
144 function removeEvent(obj,type,fn)
145 {
146     if (obj.removeEventListener) {
147         obj.removeEventListener( type, fn, false );
148     }
149     else if (obj.detachEvent) {
150         obj.detachEvent( "on"+type, obj[type+fn] );
151         obj[type+fn] = null;
152         obj["e"+type+fn] = null;
153     }
154 }
155
156     // var card_pos = RANGE 0 <= x < cards_ea_n
157
158 function show_bigpict(obj, act, x, y)
159 {
160    var big, sfx;
161
162    if (arguments.length > 4)
163        sfx = arguments[4];
164    else
165        sfx = '';
166
167    big = $(obj.id+"_big"+sfx);
168    if (act == "over") {
169        big.style.left = obj.offsetLeft + x+"px";
170        big.style.top  = obj.offsetTop  + y+"px";
171        big.style.visibility = "visible";
172        }
173    else {
174        big.style.visibility = "hidden";
175        }
176 }
177
178 function rnd_int(min, max) {
179   return Math.floor(Math.random() * (max - min + 1) + min);
180 }
181
182 function error_images()
183 {
184     // alert("GHESEMU!");
185     setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
186 }
187
188 function abort_images()
189 {
190     // alert("ABORTAIMAGES");
191     setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
192 }
193
194 function unload_images()
195 {
196     // alert("ABORTAIMAGES");
197     setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
198 }
199
200 function reset_images()
201 {
202     // alert("ABORTAIMAGES");
203     setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
204 }
205
206 function update_images()
207 {
208     // MLANG "Immagine caricate" + g_preload_imgsz_arr[g_imgct] + "%."
209     $("imgct").innerHTML = mlang_commons['imgload_a'][g_lang]+g_preload_imgsz_arr[g_imgct]+"%.";
210     if (g_imgct+1 < g_preload_img_arr.length) {
211         g_imgct++;
212         setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
213     }
214     // $("imgct").innerHTML += "U";
215 }
216
217 function preload_images(arr,idx)
218 {
219     var im = new Image;
220     
221     // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
222     im.onload =   update_images;
223     im.onerror =  error_images;
224     im.onabort =  abort_images;
225     im.onunload = unload_images;
226     im.onreset =  reset_images;
227     im.src =      arr[idx];
228     // $("imgct").innerHTML += "P";
229 }
230
231 function safestatus(a)
232 {
233     try{
234         return (a.status);
235     } catch(b)
236         { return (-1); }
237 }
238
239 function createXMLHttpRequest() {
240     try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
241     try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
242     try { return new XMLHttpRequest();                   } catch(e) {}
243     alert("XMLHttpRequest not supported");
244     return null;
245 }
246
247 function send_mesg(mesg)
248 {
249     var xhr_wr = createXMLHttpRequest();
250     var is_conn = (sess == "not_connected" ? false : true);
251     
252     // alert("xhr_wr: "+xhr_wr+"  is_conn: "+is_conn);
253     xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, (is_conn ? true : false));
254     xhr_wr.onreadystatechange = function() { return; };
255     xhr_wr.send(null);
256
257     if (!is_conn) {
258         if (xhr_wr.responseText != null) {
259             eval(xhr_wr.responseText);
260         }
261     }
262 }
263
264 function server_request()
265 {
266     var xhr_wr = createXMLHttpRequest();
267     var i, collect = "";
268
269     if (arguments.length > 0) {
270         for (i = 0 ; i < arguments.length ; i+= 2) {
271             collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
272         }
273     }
274     // alert("Args: "+arguments.length);
275
276     var is_conn = (sess == "not_connected" ? false : true);
277     
278     // console.log("server_request:preresp: "+xhr_wr.responseText);
279
280     xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
281     xhr_wr.onreadystatechange = function() { return; };
282     xhr_wr.send(null);
283     
284     if (xhr_wr.responseText != null) {
285         // console.log("server_request:resp: "+xhr_wr.responseText);
286         return (xhr_wr.responseText);
287     } 
288     else
289         return (null);
290 }
291
292 /* Stat: CHAT and TABLE */
293
294 function chatt_checksend(obj,e)
295 {
296     var keynum;
297     var keychar;
298     var numcheck;
299
300     if(window.event) { // IE
301         keynum = e.keyCode;
302     }
303     else if(e.which) { // Netscape/Firefox/Opera
304         keynum = e.which;
305     }
306     // alert("OBJ: "+obj);
307     if (keynum == 13 && obj.value != "") { // Enter
308         act_chatt(obj.value);
309         obj.value = "";
310     }
311 }
312 function act_chatt(value)
313 {
314     send_mesg("chatt|"+encodeURIComponent(value));
315     /*
316     obj.disabled = true;
317     obj.value = "";
318     obj.disabled = false;
319     obj.focus();
320     */
321     return false;
322 }
323
324 /* Stat: ROOM */
325 function act_sitdown(table)
326 {
327     send_mesg("sitdown|"+table);
328 }
329
330 function act_wakeup()
331 {
332     send_mesg("wakeup");
333 }
334
335
336
337 function act_help()
338 {
339     send_mesg("help");
340 }
341
342 function act_passwdhowto()
343 {
344     send_mesg("passwdhowto");
345 }
346
347 function act_mesgtoadm()
348 {
349     send_mesg("mesgtoadm");
350 }
351
352 function act_tav()
353 {
354     act_chatt('/tav '+$('txt_in').value); 
355     $('txt_in').value = '';
356 }
357
358 function act_about()
359 {
360     send_mesg("about");
361 }
362
363 function act_placing()
364 {
365     send_mesg("placing");
366 }
367
368 function act_roadmap()
369 {
370     send_mesg("roadmap");
371 }
372
373 function act_whysupport()
374 {
375     send_mesg("whysupport");
376 }
377
378 function act_lascio()
379 {
380     send_mesg("lascio");
381 }
382
383 function safelascio()
384 {
385     var res;
386     // MLANG "Sei sicuro di volere lasciare questa mano?"
387     res = window.confirm(mlang_commons['gamleav'][g_lang]);
388     if (res)
389         act_lascio();
390 }
391
392 function act_logout(exitlock)
393 {
394     send_mesg("logout|"+exitlock);
395 }
396
397 function act_reloadroom()
398 {
399     window.onunload = null;
400     window.onbeforeunload = null;
401     document.location.assign("index.php");
402 }
403
404 function act_shutdown()
405 {
406     var c = 0;
407
408     send_mesg("shutdown");
409     // while (xhr_wr.readyState != 4)
410     //  c++;
411 }
412
413 function postact_logout()
414 {
415     // alert("postact_logout");
416     try { 
417         xhr_rd.abort();
418     } catch (e) {}
419
420     // eraseCookie("sess");
421     document.location.assign("index.php");
422 }
423
424 /*
425   function slowimg(img,x1,y1,deltat,free,action,srcend)
426   img    - image to move
427   x1,y1  - destination coords
428   deltat - time for each frame (in msec)
429   free   - when the release the local block for other operations (range: 0 - 1)
430   action - function to run when the image is moved
431   srcend - image to switch when the image is moved
432 */
433
434 function sleep(st, delay)
435 {
436     // alert("LOC_NEW PRE: "+st.st_loc_new);
437
438     st.st_loc_new++;
439
440     setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
441                delay, st);
442 }
443
444 function slowimg(img,x1,y1,deltat,free,action,srcend) {
445     this.img = img;
446
447     // this.x0  = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
448     this.x0 = parseInt(getStyle(this.img,"left", "left"));
449 // alert("img.x0 = "+this.x0);
450     // this.y0  = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
451     this.y0  = parseInt(getStyle(this.img,"top", "top"));
452     this.x1  = x1;
453     this.y1  = y1;
454     this.deltat = deltat;
455     this.free = free;
456     this.action = action;
457     this.srcend = srcend;
458 }
459
460 slowimg.prototype = {
461     img: null, 
462     st: null,
463     x0: 0,
464     y0: 0,
465     x1: 0,
466     y1: 0,
467     dx: 0,
468     dy: 0,
469     free: 0,
470     step_n:    0,
471     step_cur:  0,
472     step_free: 0,
473     time:      0,
474     deltat:   40,
475     tout: 0,
476     action: null,
477     srcend: null,
478     
479     setstart: function(x0,y0)
480     {
481         this.x0 = x0;
482         this.y0 = y0;
483     },
484     
485     setaction: function(act)
486     {
487         this.action = act;
488     },
489     
490
491     settime: function(time) 
492     {
493         this.time = (time < this.deltat ? this.deltat : time);
494         this.step_n = parseInt(this.time / this.deltat);
495         this.dx = (this.x1 - this.x0) / this.step_n;
496         this.dy = (this.y1 - this.y0) / this.step_n;
497         if (this.step_n * this.deltat == this.time) {
498             this.step_n--;
499         }
500         if (this.free < 1) {
501             this.step_free = parseInt(this.step_n * this.free);
502         }
503     },
504     
505     start: function(st)
506     {
507         // $("logz").innerHTML += "               xxxxxxxxxxxxxxxxxxxxxSTART<br>";
508         this.st = st;
509         this.st.st_loc_new++;
510         
511         this.img.style.visibility = "visible";
512         setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
513     },
514     
515     animate: function()
516     {
517         // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
518         if (this.step_cur == 0) {
519             var date = new Date();
520             // $("logz").innerHTML = "Timestart: " + date + "<br>";
521         }
522         if (this.step_cur <= this.step_n) {
523             this.img.style.left = this.x0 + this.dx * this.step_cur;
524             this.img.style.top  = this.y0 + this.dy * this.step_cur;
525             this.step_cur++;
526             setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
527             if (this.step_cur == this.step_free && this.st != null) {
528                 if (this.st.st_loc < this.st.st_loc_new) {
529                     // alert("QUI1  " + this.step_cur + "  ZZ  "+  this.step_free);
530                     this.st.st_loc++;
531                     this.st = null;
532                 }
533             }
534         }
535         else {
536             this.img.style.left = this.x1;
537             this.img.style.top  = this.y1;
538             // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
539             var date = new Date();
540             // $("logz").innerHTML += "Timestop: " + date + "<br>";
541
542             if (this.action != null) {
543                 eval(this.action);
544             }
545
546             if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
547                 // alert("QUI2");
548                 this.st.st_loc++;
549                 this.st = null;
550             }
551             if (this.srcend != null) {
552                 this.img.src = this.srcend;
553             }
554         }
555     }
556 }
557
558
559 function notify_ex(st, text, tout, butt, w, h, is_opa)
560 {
561     var clo, box;
562     var t = this;
563     
564     this.st = st;
565
566     this.ancestor = document.body;
567     
568     this.st.st_loc_new++;
569
570     clo = document.createElement("input");
571     clo.type = "submit";
572     clo.className = "button";
573     clo.style.bottom = "4px";
574     clo.value = butt;
575     clo.obj = this;
576     clo.onclick = this.input_hide;
577     
578     clodiv = document.createElement("div");
579     clodiv.className = "notify_clo";
580     clodiv.appendChild(clo);
581
582     cont = document.createElement("div");
583
584     cont.style.borderBottomStyle = "solid";
585     cont.style.borderBottomWidth = "1px";
586     cont.style.borderBottomColor = "gray";
587     cont.style.height = (h - 30)+"px";
588     cont.style.overflow = "auto";
589     cont.innerHTML = text;
590
591     box =  document.createElement("div");
592     if (is_opa)
593         box.className = "notify_opaque";
594     else
595         box.className = "notify";
596
597     box.style.zIndex = 200;
598     box.style.width  = w+"px";
599     box.style.marginLeft  = -parseInt(w/2)+"px";
600     box.style.height = h+"px";
601     box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
602     box.appendChild(cont);
603     box.appendChild(clodiv);
604     box.style.visibility = "visible";
605
606     this.notitag = box;
607     
608     this.ancestor.appendChild(box);
609     
610     this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
611
612     formsub_hilite(clo);
613     clo.focus();
614
615 }
616
617
618 notify_ex.prototype = {
619     ancestor: null,
620     st: null,
621     notitag: null,
622     toutid: null,
623     
624     unblock: function()
625     {
626         if (this.st.st_loc < this.st.st_loc_new) {
627             this.st.st_loc++;
628         }
629     },
630     
631     hide: function()
632     {
633         clearTimeout(this.toutid);
634         this.ancestor.removeChild(this.notitag);
635         this.unblock();
636     },
637
638     input_hide: function()
639     {
640         clearTimeout(this.obj.toutid);
641         this.obj.ancestor.removeChild(this.obj.notitag);
642         this.obj.unblock();
643     }
644 }
645
646
647 notify.prototype = notify_ex.prototype;                // Define sub-class
648 notify.prototype.constructor = notify;
649 notify.baseConstructor = notify_ex;
650 notify.superClass = notify_ex.prototype;
651
652 function notify(st, text, tout, butt, w, h)
653 {
654     notify_ex.call(this, st, text, tout, butt, w, h, false);
655 }
656         
657
658 function $(id) { 
659     return document.getElementById(id); 
660 }
661
662 function globst() {
663     this.st = -1;
664     this.st_loc = -1;
665     this.st_loc_new = -1;
666     this.comms  = new Array;
667 }
668
669
670
671 function remark_step()
672 {
673     var ct = $("remark").l_remct;
674     
675     if (ct != 0) {
676         ct++;
677         if (ct > 2)
678             ct = 1;
679         $("remark").className = "remark"+ct;
680         $("remark").l_remct = ct;
681         setTimeout(remark_step,500);
682     }
683     else
684         $("remark").className = "remark0";
685     
686     return;
687 }
688
689 function remark_on()
690 {
691     if ($("remark").l_remct == 0) {
692         $("remark").l_remct = 1;
693         setTimeout(remark_step,500);
694     }
695 }
696
697 function remark_off()
698 {
699     $("remark").l_remct = 0;
700     $("remark").className = "remark0";
701 }
702
703
704 function italizer(ga)
705 {
706     var pre, pos;
707     if (ga[0] & 2) 
708         return "<i>"+ga[1]+"</i>";
709     else
710         return ga[1];
711 }
712
713
714 function exitlock_show(num, islock)
715 {
716     g_exitlock = num;
717
718     num = (num < 3 ? num : 3);
719     $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
720     // alert("EXITLOCK: "+$("exitlock").src);
721     $("exitlock").style.visibility = "visible";
722 }
723
724 var fin = 0;
725
726 //    exitlock_show(0, true);
727
728
729 var chatt_lines = new Array();
730 var chatt_lines_n = 0;
731
732 var CHATT_MAXLINES = 40;
733
734 /* PRO CHATT */
735 function chatt_sub(dt,data,str)
736 {
737     var must_scroll = false;
738     var name;
739     var flags;
740     var isauth;
741
742     flags = data[0];
743     if (flags & 0x02)
744         name = "<i>"+data[1]+"</i>";
745     else
746         name = data[1];
747     // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) -  $("txt").scrollHeight);
748
749   if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) -  $("txt").scrollHeight >= 0)
750       must_scroll = true;
751
752   // alert("ARRIVA NAME: "+ name + "  STR:"+str);
753   if (chatt_lines_n == CHATT_MAXLINES) {
754     $("txt").innerHTML = "";
755     for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
756       chatt_lines[i] = chatt_lines[i+1];
757       $("txt").innerHTML += chatt_lines[i];
758     }
759     chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
760     $("txt").innerHTML += chatt_lines[i];
761   }
762   else {
763     chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
764     $("txt").innerHTML += chatt_lines[chatt_lines_n];
765     chatt_lines_n++;
766   }
767   // $("txt").innerHTML;
768
769
770   if (must_scroll) {
771       $("txt").scrollTop = 10000000;
772   }
773   // alert("scTOP "+$("txt").scrollTop+"  scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
774 }
775
776 /*
777  *  GESTIONE DEI COOKIES
778  */
779 function createCookie(name,value,hours,path) {
780         if (hours) {
781                 var date = new Date();
782                 date.setTime(date.getTime()+(hours*60*60*1000));
783                 var expires = "; expires="+date.toGMTString();
784         }
785         else var expires = "";
786         document.cookie = name+"="+value+expires+"; path="+path;
787 }
788
789 function readCookie(name) {
790         var nameEQ = name + "=";
791         var ca = document.cookie.split(';');
792         for(var i=0;i < ca.length;i++) {
793                 var c = ca[i];
794                 while (c.charAt(0)==' ') c = c.substring(1,c.length);
795                 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
796         }
797         return null;
798 }
799
800 function eraseCookie(name) {
801         createCookie(name,"",-1);
802 }
803
804 var onunload_times = 0;
805
806
807 function onbeforeunload_cb () {
808     return("");
809 }
810
811 function onunload_cb_old () {
812     var u = 0;
813     
814     //    if (nonunload == true)
815     //     return true;
816     
817     if (onunload_times == 0) {
818         // MLANG "    Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)"
819         var res = window.confirm(mlang_commons['brileav'][g_lang]);
820         if (res == true) {
821             the_end = true; 
822             act_shutdown();
823             // while (1) 
824             //  u++;
825         }
826         else {
827             try {
828                 document.location.href = self.location; //  = self.location;
829                 // alert ("passiamo di qui"+self.location);
830                 return (false);
831             } catch (e) {
832                 // MLANG "Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente."
833                 alert(mlang_commons['brireco'][g_lang]);
834             }
835         }
836         onunload_times++;
837     }
838     
839     return(false);
840 }
841
842 function onunload_cb () {
843     
844     the_end = true; 
845
846     act_shutdown();
847     
848     return(false);
849 }
850
851
852 function room_checkspace(emme,tables,inpe)
853 {
854     nome = "<b>";
855     for (i = 0 ; i < emme ; i++) 
856         nome += "m";
857     nome += "</b>";
858
859     alta = "";
860     for (i = 0 ; i < 5 ; i++) 
861         alta += nome+"<br>";
862
863     for (i = 0 ; i < tables ; i++) {
864         $("table"+i).innerHTML = alta;
865         // MLANG Mi siedo.
866         $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\"  value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
867         }
868
869     stand = "<table class=\"table_standup\"><tbody><tr>";
870     for (i = 0 ; i < inpe ; i++) {
871         stand += "<td>"+nome+"</td>";
872         if ((i+1) % 4 == 0) {
873             stand += "</tr><tr>";
874         }
875     }
876     stand += "</tr>";
877     $("standup").innerHTML = stand;
878
879     // VERIFY: what is this button ?
880     // MLANG Esco.
881     $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
882 }
883
884 function  unescapeHTML(cont) {
885     var div = document.createElement('div');
886     var memo = "";
887     var i;
888
889     div.innerHTML = cont;
890     if (div.childNodes[0]) {
891         if (div.childNodes.length > 1) {
892             if (div.childNodes.toArray)
893                 alert("si puo");
894             else {
895                 var length = div.childNodes.length, results = new Array(length);
896             while (length--)
897                 results[length] = div.childNodes[length];
898                 
899             for (i=0 ; i<results.length ; i++)
900                 memo = memo + results[i].nodeValue;
901             }
902
903             return (memo);
904         }
905         else {
906             return (div.childNodes[0].nodeValue);
907         }
908     }
909     else {
910         return ('');
911     }
912 }
913
914 function playsound(tag, sound) {
915    // g_withflash is a global var
916    if (g_withflash) {
917       $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
918 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
919 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
920 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
921 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
922 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
923    }
924 }
925
926 function topbanner_init()
927 {
928     setInterval(topbanner_cb, 666);
929 ;
930 }
931
932 function topbanner_cb()
933 {
934     var a, b;
935
936     a = $('topbanner').style.backgroundColor;
937     b = $('topbanner').style.borderLeftColor;
938
939     $('topbanner').style.backgroundColor = b;
940     $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
941
942     // console.log("A: "+a+"  B: "+b);
943 }
944
945 function sidebanner_init()
946 {
947     setInterval(sidebanner_cb, 666);
948 }
949
950 function sidebanner2_init()
951 {
952     setInterval(sidebanner2_cb, 666);
953 }
954
955 function sidebanner_cb()
956 {
957     var a, b;
958
959     a = $('sidebanner').style.backgroundColor;
960     b = $('sidebanner').style.borderLeftColor;
961
962     $('sidebanner').style.backgroundColor = b;
963     $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
964
965     // console.log("A: "+a+"  B: "+b);
966 }
967
968 function sidebanner2_cb()
969 {
970     var a, b;
971
972     a = $('sidebanner2').style.backgroundColor;
973     b = $('sidebanner2').style.borderLeftColor;
974
975     $('sidebanner2').style.backgroundColor = b;
976     $('sidebanner2').style.borderColor = a+" "+a+" "+a+" "+a;
977
978     // console.log("A: "+a+"  B: "+b);
979 }
980
981
982 function langtolng(lang)
983 {
984     if (lang == "en")
985         return ("-en");
986     else
987         return ("");
988 }
989
990 function formtext_hilite(obj)
991 {
992     obj.className = 'input_text';
993     addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
994     addEvent(obj, "blur",  function () { this.className = 'input_text'; });
995 }
996
997 function formsub_hilite(obj)
998 {
999     obj.className = 'input_sub';
1000     addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1001     addEvent(obj, "blur",  function () { this.className = 'input_sub'; });
1002 }
1003