4 * Copyright (C) 2006 matteo.nastasi@milug.org
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.
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.
24 var EXIT_BAN_TIME = 900;
25 var cookiepath = "/brisk/";
27 function $(id) { return document.getElementById(id); }
29 function getStyle(x,IEstyleProp, MozStyleProp)
32 var y = x.currentStyle[IEstyleProp];
33 } else if (window.getComputedStyle) {
34 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
39 /* replacement of setInterval on IE */
41 /*if not IE, do nothing*/
42 if(!document.uniqueID){return;};
44 /*Copy the default setInterval behavior*/
45 var nativeSetInterval = window.setInterval;
46 window.setInterval = function(fn,ms) {
48 if(arguments.length <= 2) {
49 return nativeSetInterval(fn,ms);
52 for(var i=2;i<arguments.length;i+=1) {
53 param[i-2] = arguments[i];
57 if(typeof(fn)=='function') {
59 return (function (fn,ms,param) {
60 var fo = function () {
61 fn.apply(window,param);
63 return nativeSetInterval(fo,ms);
66 else if(typeof(fn)=='string')
68 return nativeSetInterval(fn,ms);
72 throw Error('setInterval Error\nInvalid function type');
76 /*Copy the default setTimeout behavior*/
77 var nativeSetTimeout = window.setTimeout;
78 window.setTimeout = function(fn,ms) {
80 if(arguments.length <= 2) {
81 return nativeSetTimeout(fn,ms);
84 for(var i=2;i<arguments.length;i+=1) {
85 param[i-2] = arguments[i];
89 if(typeof(fn)=='function') {
91 return (function (fn,ms,param) {
92 var fo = function () {
93 fn.apply(window,param);
95 return nativeSetTimeout(fo,ms);
98 else if(typeof(fn)=='string')
100 return nativeSetTimeout(fn,ms);
104 throw Error('setTimeout Error\nInvalid function type');
110 // var card_pos = RANGE 0 <= x < cards_ea_n
112 function rnd_int(min, max) {
113 return Math.floor(Math.random() * (max - min + 1) + min);
116 function error_images()
121 function abort_images()
123 alert("ABORTAIMAGES");
126 function unload_images()
128 alert("ABORTAIMAGES");
131 function reset_images()
133 alert("ABORTAIMAGES");
136 function update_images()
138 // if (g_imgct % 10 == 0) alert("g_imgct: "+g_imgct+" xx "+g_preload_img_arr[g_imgct]);
139 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
140 if (g_imgct+1 < g_preload_img_arr.length) {
142 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
144 // $("imgct").innerHTML += "U";
147 function preload_images(arr,idx)
151 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
152 im.onload = update_images;
153 im.onerror = error_images;
154 im.onabort = abort_images;
155 im.onunload = unload_images;
156 im.onreset = reset_images;
158 // $("imgct").innerHTML += "P";
161 function safestatus(a)
169 function createXMLHttpRequest() {
170 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
171 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
172 try { return new XMLHttpRequest(); } catch(e) {}
173 alert("XMLHttpRequest not supported");
177 function send_mesg(mesg)
179 var xhr_wr = createXMLHttpRequest();
182 xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+mesg, true);
183 xhr_wr.onreadystatechange = function() { return; };
188 /* Stat: CHAT and TABLE */
190 function chatt_checksend(obj,e)
196 if(window.event) { // IE
199 else if(e.which) { // Netscape/Firefox/Opera
202 // alert("OBJ: "+obj);
203 if (keynum == 13 && obj.value != "") { // Enter
204 act_chatt(obj.value);
208 function act_chatt(value)
210 send_mesg("chatt|"+encodeURIComponent(value));
214 obj.disabled = false;
221 function act_sitdown(table)
223 send_mesg("sitdown|"+table);
226 function act_wakeup()
231 /* Stat: TABLE Subst: ASTA */
232 function act_asta(card,pnt)
234 send_mesg("asta|"+card+"|"+pnt);
237 function act_choose(card)
240 send_mesg("choose|"+card);
243 /* Stat: TABLE Subst: GAME */
244 function act_play(card,x,y)
247 send_mesg("play|"+card+"|"+x+"|"+y);
250 function act_tableinfo()
252 send_mesg("tableinfo");
265 function act_exitlock()
267 send_mesg("exitlock");
270 function safelogout()
275 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.");
277 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
279 act_logout(g_exitlock);
282 function act_lascio()
287 function safelascio()
291 res = window.confirm("Sei sicuro di volere lasciare questa mano?");
296 function act_logout(exitlock)
298 send_mesg("logout|"+exitlock);
301 function act_reload()
303 window.onunload = null;
304 document.location.reload();
307 function act_shutdown()
311 send_mesg("shutdown");
312 while (xhr_wr.readyState != 4)
316 function postact_logout()
318 // alert("postact_logout");
323 // eraseCookie("sess");
324 document.location.assign("index.php");
328 function slowimg(img,x1,y1,deltat,free,action,srcend)
330 x1,y1 - destination coords
331 deltat - time for each frame (in msec)
332 free - when the release the local block for other operations (range: 0 - 1)
333 action - function to run when the image is moved
334 srcend - image to switch when the image is moved
337 function sleep(st, delay)
339 // alert("LOC_NEW PRE: "+st.st_loc_new);
343 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
347 function slowimg(img,x1,y1,deltat,free,action,srcend) {
350 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
351 this.x0 = parseInt(getStyle(this.img,"left", "left"));
352 // alert("img.x0 = "+this.x0);
353 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
354 this.y0 = parseInt(getStyle(this.img,"top", "top"));
357 this.deltat = deltat;
359 this.action = action;
360 this.srcend = srcend;
363 slowimg.prototype = {
382 setstart: function(x0,y0)
388 setaction: function(act)
394 settime: function(time)
396 this.time = (time < this.deltat ? this.deltat : time);
397 this.step_n = parseInt(this.time / this.deltat);
398 this.dx = (this.x1 - this.x0) / this.step_n;
399 this.dy = (this.y1 - this.y0) / this.step_n;
400 if (this.step_n * this.deltat == this.time) {
403 this.step_free = parseInt(this.step_n * this.free);
408 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
410 this.st.st_loc_new++;
412 this.img.style.visibility = "visible";
413 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
418 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
419 if (this.step_cur == 0) {
420 var date = new Date();
421 // $("logz").innerHTML = "Timestart: " + date + "<br>";
423 if (this.step_cur <= this.step_n) {
424 this.img.style.left = this.x0 + this.dx * this.step_cur;
425 this.img.style.top = this.y0 + this.dy * this.step_cur;
427 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
428 if (this.step_cur == this.step_free && this.st != null) {
429 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
430 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
437 this.img.style.left = this.x1;
438 this.img.style.top = this.y1;
439 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
440 var date = new Date();
441 // $("logz").innerHTML += "Timestop: " + date + "<br>";
442 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
447 if (this.action != null) {
450 if (this.srcend != null) {
451 this.img.src = this.srcend;
457 var asta_xarr = new Array(0,66,132);
459 /* TODO: impostare gli onclick */
460 function dispose_asta(idx, pnt, nopoint)
465 for (i = 0 ; i < 10 ; i++) {
468 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
469 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
473 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
474 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
478 btn.style.left = asta_xarr[i % 3];
480 btn.style.left = asta_xarr[(i+1) % 3];
482 btn.style.top = parseInt(i / 3) * 50 + (i == 9 ? 0 : 1);
485 eval("btn.onclick = function () { act_asta("+pass+",61); }");
486 btn.style.cursor = "pointer";
490 btn.style.cursor = "default";
495 btn = $("astaptdiv");
496 btn.style.left = asta_xarr[i % 3];
497 btn.style.top = parseInt(i / 3) * 50 - 2;
498 // btn.style.visibility = "visible";
501 var rpnt = (pnt < 0 ? -pnt : pnt);
502 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
504 btn = $("astaptsub");
505 btn.style.left = asta_xarr[i % 3];
506 btn.style.top = 25 + parseInt(i / 3) * 50 - 1;
507 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
508 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
510 btn.onclick = function () { act_asta(9,$("astapt").value); };
511 btn.style.cursor = "pointer";
515 btn.style.cursor = "default";
520 btn = $("astapasso");
521 btn.style.left = asta_xarr[i % 3];
522 btn.style.top = parseInt(i / 3) * 50;
523 btn.src = "img/astapashalf"+(pnt >= 0 ? "" : "_ro")+".png";
524 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
526 btn.onclick = function () { act_asta(-1,0); };
532 btn = $("astalascio");
533 btn.style.left = asta_xarr[i % 3];
534 btn.style.top = parseInt(i / 3) * 50 + 24;
535 btn.src = "img/astalascio.png";
536 btn.style.visibility = "visible";
537 btn.onclick = function () { safelascio(); };
540 btn = $("astapasso");
541 btn.style.left = asta_xarr[i % 3];
542 btn.style.top = parseInt(i / 3) * 50;;
543 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
544 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
546 btn.onclick = function () { act_asta(-1,0); };
552 btn = $("astalascio");
553 btn.style.visibility = "hidden";
556 // btn.style.visibility = "visible";
557 $("asta").style.visibility = "visible";
560 function asta_pnt_set(pnt)
563 var rpnt = (pnt < 0 ? -pnt : pnt);
564 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
569 $("asta").style.visibility = "hidden";
573 function notify(st, text, tout, butt, w, h)
580 this.ancestor = document.body;
582 this.st.st_loc_new++;
584 clo = document.createElement("input");
586 clo.className = "button";
587 clo.style.bottom = "4px";
590 clo.onclick = this.input_hide;
592 clodiv = document.createElement("div");
593 clodiv.className = "notify_clo";
594 clodiv.appendChild(clo);
596 box = document.createElement("div");
597 box.className = "notify";
598 box.innerHTML = text;
599 box.style.zIndex = 200;
600 box.style.width = w+"px";
601 box.style.marginLeft = -parseInt(w/2)+"px";
602 box.style.height = h+"px";
603 box.appendChild(clodiv);
604 box.style.visibility = "visible";
608 this.ancestor.appendChild(box);
610 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
621 if (this.st.st_loc < this.st.st_loc_new) {
628 clearTimeout(this.toutid);
629 this.ancestor.removeChild(this.notitag);
633 input_hide: function()
635 clearTimeout(this.obj.toutid);
636 this.obj.ancestor.removeChild(this.obj.notitag);
643 return document.getElementById(id);
649 this.st_loc_new = -1;
650 this.comms = new Array;
655 function remark_step()
657 var ct = $("remark").l_remct;
663 $("remark").className = "remark"+ct;
664 $("remark").l_remct = ct;
665 setTimeout(remark_step,500);
668 $("remark").className = "remark0";
675 if ($("remark").l_remct == 0) {
676 $("remark").l_remct = 1;
677 setTimeout(remark_step,500);
681 function remark_off()
683 $("remark").l_remct = 0;
684 $("remark").className = "remark0";
688 function choose_seed(card)
692 $("chooseed").style.visibility = "visible";
693 for (i = 0 ; i < 4 ; i++) {
694 $("seed"+i).src = "img/"+i+""+card+".png";
696 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
700 function set_names(so,ea,ne,nw,we)
703 $("name").innerHTML = so;
704 $("name").title = so;
705 $("name_ea").innerHTML = ea;
706 $("name_ea").title = ea;
707 $("name_ne").innerHTML = ne;
708 $("name_ne").title = ne;
709 $("name_nw").innerHTML = nw;
710 $("name_nw").title = nw;
711 $("name_we").innerHTML = we;
712 $("name_we").title = we;
717 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
719 function show_astat(zer,uno,due,tre,qua)
721 var astat = new Array(zer,uno,due,tre,qua);
723 for (i = 0 ; i < PLAYERS_N ; i++) {
724 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
726 if (astat[i] == -2) {
727 $("public"+astat_suffix[idx]).style.visibility = "hidden";
729 else if (astat[i] == -1) {
730 $("public"+astat_suffix[idx]).style.visibility = "visible";
731 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
732 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
733 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
735 else if (astat[i] <= 10) {
736 $("public"+astat_suffix[idx]).style.visibility = "visible";
737 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
738 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
740 else if (astat[i] <= 120) {
741 $("public"+astat_suffix[idx]).style.visibility = "visible";
742 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
743 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
744 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
749 function exitlock_show(num, islock)
753 num = (num < 3 ? num : 3);
754 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
755 // alert("EXITLOCK: "+$("exitlock").src);
756 $("exitlock").style.visibility = "visible";
761 // exitlock_show(0, true);
763 function table_init() {
764 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
767 $("asta").style.visibility = "hidden";
768 $("caller").style.visibility = "hidden";
769 show_astat(-2,-2,-2,-2,-2);
770 for (i=0 ; i < 8 ; i++) {
771 Drag.init($("card" + i), card_mouseup_cb);
772 for (e = 0 ; e < PLAYERS_N ; e++)
773 $("card"+sux[e]+i).style.visibility = "hidden";
775 for (i=0 ; i < PLAYERS_N ; i++) {
776 $("takes"+sux[i]).style.visibility = "hidden";
779 for (i = 0 ; i < 8 ; i++) {
791 var chatt_lines = new Array();
792 var chatt_lines_n = 0;
794 var CHATT_MAXLINES = 40;
797 function chatt_sub(name,str)
799 // alert("ARRIVA NAME: "+ name + " STR:"+str);
800 if (chatt_lines_n == CHATT_MAXLINES) {
801 $("txt").innerHTML = "";
802 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
803 chatt_lines[i] = chatt_lines[i+1];
804 $("txt").innerHTML += chatt_lines[i];
806 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
807 $("txt").innerHTML += chatt_lines[i];
810 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
811 $("txt").innerHTML += chatt_lines[chatt_lines_n];
815 $("txt").scrollTop = 10000000;
819 * GESTIONE DEI COOKIES
821 function createCookie(name,value,hours,path) {
823 var date = new Date();
824 date.setTime(date.getTime()+(hours*60*60*1000));
825 var expires = "; expires="+date.toGMTString();
827 else var expires = "";
828 document.cookie = name+"="+value+expires+"; path="+path;
831 function readCookie(name) {
832 var nameEQ = name + "=";
833 var ca = document.cookie.split(';');
834 for(var i=0;i < ca.length;i++) {
836 while (c.charAt(0)==' ') c = c.substring(1,c.length);
837 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
842 function eraseCookie(name) {
843 createCookie(name,"",-1);
846 var onunload_times = 0;
849 function onunload_cb () {
851 if (onunload_times == 0) {
852 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
861 location = self.location;
863 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
873 function room_checkspace(emme,tables,inpe)
876 for (i = 0 ; i < emme ; i++)
881 for (i = 0 ; i < 5 ; i++)
884 for (i = 0 ; i < tables ; i++) {
885 $("table"+i).innerHTML = alta;
886 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
889 stand = "<table class=\"table_standup\"><tbody><tr>";
890 for (i = 0 ; i < inpe ; i++) {
891 stand += "<td>"+nome+"</td>";
892 if ((i+1) % 4 == 0) {
893 stand += "</tr><tr>";
897 $("standup").innerHTML = stand;
899 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
902 function playsound(tag, sound) {
903 // g_withflash is a global var
905 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
906 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
907 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
908 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
909 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
910 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';