corretto bug
[brisk.git] / web / commons.js
1 /*
2  *  brisk - commons.js
3  *
4  *  Copyright (C) 2006 matteo.nastasi@milug.org
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details. You should have received a
15  * copy of the GNU General Public License along with this program; if
16  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
17  * Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * $Id$
20  *
21  */
22
23 var PLAYERS_N = 3;
24 var EXIT_BAN_TIME = 900;
25
26 function $(id) { return document.getElementById(id); }
27
28 /* replacement of setInterval on IE */
29 (function(){
30     /*if not IE, do nothing*/
31     if(!document.uniqueID){return;};
32
33     /*Copy the default setInterval behavior*/
34     var nativeSetInterval = window.setInterval;
35     window.setInterval = function(fn,ms) {              
36         var param = [];
37         if(arguments.length <= 2)       {
38             return nativeSetInterval(fn,ms);
39         }
40         else {
41             for(var i=2;i<arguments.length;i+=1) {
42                 param[i-2] =  arguments[i];
43             }   
44         }
45         
46         if(typeof(fn)=='function') {
47             
48             return (function (fn,ms,param) {
49                 var fo = function () {                                                          
50                     fn.apply(window,param);
51                 };                      
52                 return nativeSetInterval(fo,ms); 
53             })(fn,ms,param);
54         }
55         else if(typeof(fn)=='string')
56         {
57             return  nativeSetInterval(fn,ms);
58         }
59         else
60         {
61             throw Error('setInterval Error\nInvalid function type');
62         };
63     };
64
65     /*Copy the default setTimeout behavior*/
66     var nativeSetTimeout = window.setTimeout;
67     window.setTimeout = function(fn,ms) {               
68         var param = [];
69         if(arguments.length <= 2)       {
70             return nativeSetTimeout(fn,ms);
71         }
72         else {
73             for(var i=2;i<arguments.length;i+=1) {
74                 param[i-2] =  arguments[i];
75             }   
76         }
77         
78         if(typeof(fn)=='function') {
79             
80             return (function (fn,ms,param) {
81                 var fo = function () {                                                          
82                     fn.apply(window,param);
83                 };                      
84                 return nativeSetTimeout(fo,ms); 
85             })(fn,ms,param);
86         }
87         else if(typeof(fn)=='string')
88         {
89             return  nativeSetTimeout(fn,ms);
90         }
91         else
92         {
93             throw Error('setTimeout Error\nInvalid function type');
94         };
95     };
96
97 })()
98
99     // var card_pos = RANGE 0 <= x < cards_ea_n
100
101 function rnd_int(min, max) {
102   return Math.floor(Math.random() * (max - min + 1) + min);
103 }
104
105 function error_images()
106 {
107     alert("GHESEMU!");
108 }
109
110 function abort_images()
111 {
112     alert("ABORTAIMAGES");
113 }
114
115 function unload_images()
116 {
117     alert("ABORTAIMAGES");
118 }
119
120 function reset_images()
121 {
122     alert("ABORTAIMAGES");
123 }
124
125 function update_images()
126 {
127     $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
128     if (g_imgct < g_preload_img_arr.length)
129         setTimeout(preload_images, 100, g_preload_img_arr, g_imgct);
130     g_imgct++;
131     // $("imgct").innerHTML += "U";
132 }
133
134 function preload_images(arr,idx)
135 {
136     var im = new Image;
137     
138     // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
139     im.onload =   update_images;
140     im.onerror =  error_images;
141     im.onabort =  abort_images;
142     im.onunload = unload_images;
143     im.onreset =  reset_images;
144     im.src =      arr[idx];
145     // $("imgct").innerHTML += "P";
146 }
147
148 function safestatus(a)
149 {
150     try{
151         return (a.status);
152     } catch(b)
153         { return (-1); }
154 }
155
156 function createXMLHttpRequest() {
157     try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
158     try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
159     try { return new XMLHttpRequest();                   } catch(e) {}
160     alert("XMLHttpRequest not supported");
161     return null;
162 }
163
164 function send_mesg(mesg)
165 {
166     var xhr_wr = createXMLHttpRequest();
167     // xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+encodeURIComponent(mesg), true);
168     xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+mesg, true);
169     xhr_wr.onreadystatechange = function() { return; };
170     xhr_wr.send(null);
171
172 }
173
174 /* Stat: CHAT and TABLE */
175
176 function chatt_checksend(obj,e)
177 {
178     var keynum;
179     var keychar;
180     var numcheck;
181
182     if(window.event) { // IE
183         keynum = e.keyCode;
184     }
185     else if(e.which) { // Netscape/Firefox/Opera
186         keynum = e.which;
187     }
188     // alert("OBJ: "+obj);
189     if (keynum == 13 && obj.value != "") { // Enter
190         act_chatt(obj.value);
191         obj.value = "";
192     }
193 }
194 function act_chatt(value)
195 {
196     send_mesg("chatt|"+encodeURIComponent(value));
197     /*
198     obj.disabled = true;
199     obj.value = "";
200     obj.disabled = false;
201     obj.focus();
202     */
203     return false;
204 }
205
206 /* Stat: ROOM */
207 function act_sitdown(table)
208 {
209     send_mesg("sitdown|"+table);
210 }
211
212 function act_wakeup()
213 {
214     send_mesg("wakeup");
215 }
216
217 /* Stat: TABLE  Subst: ASTA */
218 function act_asta(card,pnt)
219 {
220     send_mesg("asta|"+card+"|"+pnt);
221 }
222
223 function act_choose(card)
224 {
225     // alert("sitdown");
226     send_mesg("choose|"+card);
227 }
228
229 /* Stat: TABLE  Subst: GAME */
230 function act_play(card,x,y)
231 {
232     // alert("sitdown");
233     send_mesg("play|"+card+"|"+x+"|"+y);
234 }
235
236 function act_tableinfo()
237 {
238     send_mesg("tableinfo");
239 }
240
241 function act_help()
242 {
243     send_mesg("help");
244 }
245
246 function act_about()
247 {
248     send_mesg("about");
249 }
250
251 function act_exitlock()
252 {
253     send_mesg("exitlock");
254 }
255
256 function safelogout()
257 {
258     var res;
259     
260     if (g_exitlock < 3) 
261         res = window.confirm("Sei sicuro di volere abbandonare la partita?\nATTENZIONE: se esci adesso senza il consenso degli altri giocatori non potrai sederti ai tavoli per "+(Math.floor(EXIT_BAN_TIME/60))+" minuti.");    
262     else 
263         res = window.confirm("Sei sicuro di volere abbandonare la partita?");
264     if (res)
265         act_logout(g_exitlock);
266 }
267
268 function act_lascio()
269 {
270     send_mesg("lascio");
271 }
272
273 function safelascio()
274 {
275     var res;
276
277     res = window.confirm("Sei sicuro di volere lasciare questa mano?");
278     if (res)
279         act_lascio();
280 }
281
282 function act_logout(exitlock)
283 {
284     send_mesg("logout|"+exitlock);
285 }
286
287 function act_reload()
288 {
289     window.onunload = null;
290     document.location.reload();
291 }
292
293 function act_shutdown()
294 {
295     var c = 0;
296
297     send_mesg("shutdown");
298     while (xhr_wr.readyState != 4)
299         c++;
300 }
301
302 function act_preout()
303 {
304     act_logout();
305 }
306
307 function postact_logout()
308 {
309     // alert("postact_logout");
310     try { 
311         xhr_rd.abort();
312     } catch (e) {}
313
314     // eraseCookie("sess");
315     document.location.assign("index.php");
316 }
317
318 /*
319   function slowimg(img,x1,y1,deltat,free,action,srcend)
320   img    - image to move
321   x1,y1  - destination coords
322   deltat - time for each frame (in msec)
323   free   - when the release the local block for other operations (range: 0 - 1)
324   action - function to run when the image is moved
325   srcend - image to switch when the image is moved
326 */
327
328 function sleep(st, delay)
329 {
330     // alert("LOC_NEW PRE: "+st.st_loc_new);
331
332     st.st_loc_new++;
333
334     setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
335                delay, st);
336 }
337
338 function slowimg(img,x1,y1,deltat,free,action,srcend) {
339     this.img = img;
340
341     this.x0  = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
342     // alert("img.x0 = "+this.x0);
343     this.y0  = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
344     this.x1  = x1;
345     this.y1  = y1;
346     this.deltat = deltat;
347     this.free = free;
348     this.action = action;
349     this.srcend = srcend;
350 }
351
352 slowimg.prototype = {
353     img: null, 
354     st: null,
355     x0: 0,
356     y0: 0,
357     x1: 0,
358     y1: 0,
359     dx: 0,
360     dy: 0,
361     free: 0,
362     step_n:    0,
363     step_cur:  0,
364     step_free: 0,
365     time:      0,
366     deltat:   40,
367     tout: 0,
368     action: null,
369     srcend: null,
370     
371     setstart: function(x0,y0)
372     {
373         this.x0 = x0;
374         this.y0 = y0;
375     },
376     
377     setaction: function(act)
378     {
379         this.action = act;
380     },
381     
382     settime: function(time) 
383     {
384         this.time = time;
385         this.step_n = parseInt(time / this.deltat);
386         this.dx = (this.x1 - this.x0) / this.step_n;
387         this.dy = (this.y1 - this.y0) / this.step_n;
388         if (this.step_n * this.deltat == time) {
389             this.step_n--;
390         }
391         this.step_free = parseInt(this.step_n * this.free);
392     },
393     
394     start: function(st)
395     {
396         // $("logz").innerHTML += "               xxxxxxxxxxxxxxxxxxxxxSTART<br>";
397         this.st = st;
398         this.st.st_loc_new++;
399         
400         this.img.style.visibility = "visible";
401         setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
402     },
403     
404     animate: function()
405     {
406         // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
407         if (this.step_cur == 0) {
408             var date = new Date();
409             // $("logz").innerHTML = "Timestart: " + date + "<br>";
410         }
411         if (this.step_cur <= this.step_n) {
412             this.img.style.left = this.x0 + this.dx * this.step_cur;
413             this.img.style.top  = this.y0 + this.dy * this.step_cur;
414             this.step_cur++;
415             setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
416             if (this.step_cur == this.step_free && this.st != null) {
417                 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
418                     // alert("QUI1  " + this.step_cur + "  ZZ  "+  this.step_free);
419                     this.st.st_loc++;
420                     this.st = null;
421                 }
422             }
423         }
424         else {
425             this.img.style.left = this.x1;
426             this.img.style.top  = this.y1;
427             // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
428             var date = new Date();
429             // $("logz").innerHTML += "Timestop: " + date + "<br>";
430             if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
431                 // alert("QUI2");
432                 this.st.st_loc++;
433                 this.st = null;
434             }
435             if (this.action != null) {
436                 eval(this.action);
437             }
438             if (this.srcend != null) {
439                 this.img.src = this.srcend;
440             }
441         }
442     }
443 }
444
445 var asta_xarr = new Array(0,66,132);
446
447 /* TODO: impostare gli onclick */
448 function dispose_asta(idx, pnt, nopoint)
449 {
450     var i, btn, pass;
451     var btn;
452
453     for (i = 0 ; i < 10 ; i++) {
454         btn = $("asta"+i);
455         if (i < idx) {
456             btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
457             pass = -1;
458         }
459         else {
460             btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
461             pass = i;
462         }
463         if (i < 19)
464             btn.style.left = asta_xarr[i % 3];
465         else
466             btn.style.left = asta_xarr[(i+1) % 3];
467         
468         btn.style.top  = parseInt(i / 3) * 50+1;
469
470         if (pnt >= 0) {
471             eval("btn.onclick = function () { act_asta("+pass+",61); }");
472             btn.style.hover_cursor = "pointer";
473         }
474         else {
475             btn.onclick = null;
476             btn.style.hover_cursor = "";
477         }
478     }
479     
480     
481     btn = $("astaptdiv");
482     btn.style.left = asta_xarr[i % 3];
483     btn.style.top = parseInt(i / 3) * 50 - 2;
484     // btn.style.visibility  = "visible";
485     
486     btn = $("astapt");
487     var rpnt = (pnt < 0 ? -pnt : pnt);
488     btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
489     
490     btn = $("astaptsub");
491     btn.style.left = asta_xarr[i % 3];
492     btn.style.top = 25 + parseInt(i / 3) * 50 - 1;
493     btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
494     // btn.style.visibility  = "visible";
495     if (pnt >= 0) {
496         btn.onclick = function () { act_asta(9,$("astapt").value); };
497         // btn.stylehover.cursor = "pointer";
498     }
499     else {
500         btn.onclick = null;
501         // btn.stylehover.cursor = "";
502     }
503     
504     i+=1;
505     if (nopoint) {
506         btn = $("astapasso");
507         btn.style.left = asta_xarr[i % 3];
508         btn.style.top = parseInt(i / 3) * 50;
509         btn.src = "img/astapashalf"+(pnt >= 0 ? "" : "_ro")+".png";
510         if (pnt >= 0) {
511             btn.onclick = function () { act_asta(-1,0); };
512             // btn.stylehover.cursor = "pointer";
513         }
514         else {          
515             btn.onclick = null;
516             // btn.stylehover.cursor = "";
517         }
518
519         btn = $("astalascio");
520         btn.style.left = asta_xarr[i % 3];
521         btn.style.top = parseInt(i / 3) * 50 + 24;
522         btn.src = "img/astalascio.png";
523         btn.style.visibility = "visible";
524         btn.onclick = function () { safelascio(); };
525         }
526     else {
527         btn = $("astapasso");
528         btn.style.left = asta_xarr[i % 3];
529         btn.style.top = parseInt(i / 3) * 50;;
530         btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
531         if (pnt >= 0) {
532             btn.onclick = function () { act_asta(-1,0); };
533             // btn.stylehover.cursor = "pointer";
534         }
535         else {
536             btn.onclick = null;
537             // btn.stylehover.cursor = "";
538         }
539
540         btn = $("astalascio");
541         btn.style.visibility = "hidden";
542         btn.onclick = null;
543     }
544     // btn.style.visibility  = "visible";
545     $("asta").style.visibility = "visible";
546 }
547
548 function hide_asta()
549 {
550     $("asta").style.visibility = "hidden"; 
551 }
552
553
554 function notify(st, text, tout, butt, w, h)
555 {
556     var clo, box;
557     var t = this;
558     
559     this.st = st;
560
561     this.ancestor = document.body;
562     
563     this.st.st_loc_new++;
564
565     clo = document.createElement("input");
566     clo.type = "submit";
567     clo.className = "button";
568     clo.style.bottom = "4px";
569     clo.value = butt;
570     clo.obj = this;
571     clo.onclick = this.input_hide;
572     
573     clodiv = document.createElement("div");
574     clodiv.className = "notify_clo";
575     clodiv.appendChild(clo);
576
577     box = document.createElement("div");
578     box.className = "notify";
579     box.innerHTML = text;
580     box.style.zIndex = 200;
581     box.style.width  = w+"px";
582     box.style.height = h+"px";
583     box.appendChild(clodiv);
584     box.style.visibility = "visible";
585
586     this.notitag = box;
587     
588     this.ancestor.appendChild(box);
589     
590     this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
591 }
592
593 notify.prototype = {
594     ancestor: null,
595     st: null,
596     notitag: null,
597     toutid: null,
598     
599     unblock: function()
600     {
601         if (this.st.st_loc < this.st.st_loc_new) {
602             this.st.st_loc++;
603         }
604     },
605     
606     hide: function()
607     {
608         clearTimeout(this.toutid);
609         this.ancestor.removeChild(this.notitag);
610         this.unblock();
611     },
612
613     input_hide: function()
614     {
615         clearTimeout(this.obj.toutid);
616         this.obj.ancestor.removeChild(this.obj.notitag);
617         this.obj.unblock();
618     }
619 }
620         
621
622 function $(id) { 
623     return document.getElementById(id); 
624 }
625
626 function globst() {
627     this.st = -1;
628     this.st_loc = -1;
629     this.st_loc_new = -1;
630     this.comms  = new Array;
631 }
632
633
634
635 function remark_step()
636 {
637     var ct = $("remark").l_remct;
638     
639     if (ct != 0) {
640         ct++;
641         if (ct > 2)
642             ct = 1;
643         $("remark").className = "remark"+ct;
644         $("remark").l_remct = ct;
645         setTimeout(remark_step,500);
646     }
647     else
648         $("remark").className = "remark0";
649     
650     return;
651 }
652
653 function remark_on()
654 {
655     if ($("remark").l_remct == 0) {
656         $("remark").l_remct = 1;
657         setTimeout(remark_step,500);
658     }
659 }
660
661 function remark_off()
662 {
663     $("remark").l_remct = 0;
664     $("remark").className = "remark0";
665 }
666
667
668 function choose_seed(card)
669 {
670     var i;
671
672     $("chooseed").style.visibility = "visible";
673     for (i = 0 ; i < 4 ; i++) {
674         $("seed"+i).src = "img/"+i+""+card+".png";
675         seed=$("seed"+i);
676         eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
677     }
678 }
679
680 function set_names(so,ea,ne,nw,we)
681 {
682 //    alert("EA: "+ea);
683     $("name").innerHTML = so; 
684     $("name").title = so; 
685     $("name_ea").innerHTML = ea;
686     $("name_ea").title = ea;
687     $("name_ne").innerHTML = ne;
688     $("name_ne").title = ne;
689     $("name_nw").innerHTML = nw;
690     $("name_nw").title = nw;
691     $("name_we").innerHTML = we;
692     $("name_we").title = we;
693
694     return;
695 }
696
697 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
698
699 function show_astat(zer,uno,due,tre,qua)
700 {
701     var astat = new Array(zer,uno,due,tre,qua);
702
703     for (i = 0 ; i < PLAYERS_N ; i++) {
704         idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
705
706         if (astat[i] == -2) {
707             $("public"+astat_suffix[idx]).style.visibility = "hidden";
708         }
709         else if (astat[i] == -1) {
710             $("public"+astat_suffix[idx]).style.visibility = "visible";
711             $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
712             $("pubapnt"+astat_suffix[idx]).innerHTML = "";
713             $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
714         }
715         else if (astat[i] <= 10) {
716             $("public"+astat_suffix[idx]).style.visibility = "visible";
717             $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
718             $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
719         }
720         else if (astat[i] <= 120) {
721             $("public"+astat_suffix[idx]).style.visibility = "visible";
722             $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
723             $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
724             $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
725         }
726     }
727 }
728
729 function exitlock_show(num, islock)
730 {
731     g_exitlock = num;
732
733     num = (num < 3 ? num : 3);
734     $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
735     // alert("EXITLOCK: "+$("exitlock").src);
736     $("exitlock").style.visibility = "visible";
737 }
738
739 var fin = 0;
740
741 //    exitlock_show(0, true);
742
743 function table_init() {
744     var sux = new Array("", "_ea", "_ne", "_nw", "_we");
745
746     remark_off();
747     $("asta").style.visibility = "hidden";
748     $("caller").style.visibility = "hidden";
749     show_astat(-2,-2,-2,-2,-2);
750     for (i=0 ; i < 8 ; i++) {
751         Drag.init($("card" + i), card_mouseup_cb);
752         for (e = 0 ; e < PLAYERS_N ; e++)
753             $("card"+sux[e]+i).style.visibility = "hidden";
754     }
755     for (i=0 ; i < PLAYERS_N ; i++) {
756         $("takes"+sux[i]).style.visibility = "hidden";
757         }
758
759     for (i = 0 ; i < 8 ; i++) {
760         cards_pos[i] = i;
761         cards_ea_pos[i] = i;
762         cards_ne_pos[i] = i;
763         cards_nw_pos[i] = i;
764         cards_we_pos[i] = i;
765     }
766
767 }
768   
769
770
771 var chatt_lines = new Array();
772 var chatt_lines_n = 0;
773
774 var CHATT_MAXLINES = 40;
775
776 /* PRO CHATT */
777 function chatt_sub(name,str)
778 {
779   // alert("ARRIVA NAME: "+ name + "  STR:"+str);
780   if (chatt_lines_n == CHATT_MAXLINES) {
781     $("txt").innerHTML = "";
782     for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
783       chatt_lines[i] = chatt_lines[i+1];
784       $("txt").innerHTML += chatt_lines[i];
785     }
786     chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
787     $("txt").innerHTML += chatt_lines[i];
788   }
789   else {
790     chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
791     $("txt").innerHTML += chatt_lines[chatt_lines_n];
792     chatt_lines_n++;
793   }
794   $("txt").innerHTML;
795   $("txt").scrollTop = 10000000;
796 }
797
798 /*
799  *  GESTIONE DEI COOKIES
800  */
801 function createCookie(name,value,hours,path) {
802         if (hours) {
803                 var date = new Date();
804                 date.setTime(date.getTime()+(hours*60*60*1000));
805                 var expires = "; expires="+date.toGMTString();
806         }
807         else var expires = "";
808         document.cookie = name+"="+value+expires+"; path="+path;
809 }
810
811 function readCookie(name) {
812         var nameEQ = name + "=";
813         var ca = document.cookie.split(';');
814         for(var i=0;i < ca.length;i++) {
815                 var c = ca[i];
816                 while (c.charAt(0)==' ') c = c.substring(1,c.length);
817                 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
818         }
819         return null;
820 }
821
822 function eraseCookie(name) {
823         createCookie(name,"",-1);
824 }
825
826 var onunload_times = 0;
827
828
829 function onunload_cb () {
830     var u = 0;
831     if (onunload_times == 0) {
832         var res = window.confirm("    Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
833         if (res == true) {
834             the_end = true; 
835             act_shutdown();
836             while (1) 
837                 u++;
838         }
839         else {
840             try {
841                 location = self.location;
842             } catch (e) {
843                 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
844             }
845         }
846         onunload_times++;
847     }
848     
849     return(false);
850 }
851
852
853 function room_checkspace(emme,tables,inpe)
854 {
855     nome = "<b>";
856     for (i = 0 ; i < emme ; i++) 
857         nome += "m";
858     nome += "</b>";
859
860     alta = "";
861     for (i = 0 ; i < 5 ; i++) 
862         alta += nome+"<br>";
863
864     for (i = 0 ; i < tables ; i++) {
865         $("table"+i).innerHTML = alta;
866         $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\"  value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
867         }
868
869     stand = "<table class=\"table_standup\"><tbody><tr>";
870     for (i = 0 ; i < inpe ; i++) {
871         stand += "<td class=\"td_standup\">"+nome+"</td>";
872         if ((i+1) % 4 == 0) {
873             stand += "</tr><tr>";
874         }
875     }
876     stand += "</tr>";
877     $("standup").innerHTML = stand;
878
879     $("esco").innerHTML = "<input name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
880 }
881
882 function playsound(tag, sound) {
883    // g_withflash is a global var
884    if (g_withflash) {
885       $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
886 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
887 '<PARAM NAME="movie" VALUE="playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
888 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
889 '<EMBED swliveconnect="true" name="mysound" src="playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
890 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
891    }
892 }