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 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
139 if (g_imgct < g_preload_img_arr.length)
140 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct);
142 // $("imgct").innerHTML += "U";
145 function preload_images(arr,idx)
149 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
150 im.onload = update_images;
151 im.onerror = error_images;
152 im.onabort = abort_images;
153 im.onunload = unload_images;
154 im.onreset = reset_images;
156 // $("imgct").innerHTML += "P";
159 function safestatus(a)
167 function createXMLHttpRequest() {
168 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
169 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
170 try { return new XMLHttpRequest(); } catch(e) {}
171 alert("XMLHttpRequest not supported");
175 function send_mesg(mesg)
177 var xhr_wr = createXMLHttpRequest();
180 xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+encodeURIComponent(mesg), true);
181 xhr_wr.onreadystatechange = function() { return; };
186 /* Stat: CHAT and TABLE */
188 function chatt_checksend(obj,e)
194 if(window.event) { // IE
197 else if(e.which) { // Netscape/Firefox/Opera
200 // alert("OBJ: "+obj);
201 if (keynum == 13 && obj.value != "") { // Enter
202 act_chatt(obj.value);
206 function act_chatt(value)
208 send_mesg("chatt|"+encodeURIComponent(value));
212 obj.disabled = false;
219 function act_sitdown(table)
221 send_mesg("sitdown|"+table);
224 function act_wakeup()
229 /* Stat: TABLE Subst: ASTA */
230 function act_asta(card,pnt)
232 send_mesg("asta|"+card+"|"+pnt);
235 function act_choose(card)
238 send_mesg("choose|"+card);
241 /* Stat: TABLE Subst: GAME */
242 function act_play(card,x,y)
245 send_mesg("play|"+card+"|"+x+"|"+y);
248 function act_tableinfo()
250 send_mesg("tableinfo");
263 function act_exitlock()
265 send_mesg("exitlock");
268 function safelogout()
273 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.");
275 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
277 act_logout(g_exitlock);
280 function act_lascio()
285 function safelascio()
289 res = window.confirm("Sei sicuro di volere lasciare questa mano?");
294 function act_logout(exitlock)
296 send_mesg("logout|"+exitlock);
299 function act_reload()
301 window.onunload = null;
302 document.location.reload();
305 function act_shutdown()
309 send_mesg("shutdown");
310 while (xhr_wr.readyState != 4)
314 function postact_logout()
316 // alert("postact_logout");
321 // eraseCookie("sess");
322 document.location.assign("index.php");
326 function slowimg(img,x1,y1,deltat,free,action,srcend)
328 x1,y1 - destination coords
329 deltat - time for each frame (in msec)
330 free - when the release the local block for other operations (range: 0 - 1)
331 action - function to run when the image is moved
332 srcend - image to switch when the image is moved
335 function sleep(st, delay)
337 // alert("LOC_NEW PRE: "+st.st_loc_new);
341 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
345 function slowimg(img,x1,y1,deltat,free,action,srcend) {
348 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
349 this.x0 = parseInt(getStyle(this.img,"left", "left"));
350 // alert("img.x0 = "+this.x0);
351 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
352 this.y0 = parseInt(getStyle(this.img,"top", "top"));
355 this.deltat = deltat;
357 this.action = action;
358 this.srcend = srcend;
361 slowimg.prototype = {
380 setstart: function(x0,y0)
386 setaction: function(act)
392 settime: function(time)
394 this.time = (time < this.deltat ? this.deltat : time);
395 this.step_n = parseInt(this.time / this.deltat);
396 this.dx = (this.x1 - this.x0) / this.step_n;
397 this.dy = (this.y1 - this.y0) / this.step_n;
398 if (this.step_n * this.deltat == this.time) {
401 this.step_free = parseInt(this.step_n * this.free);
406 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
408 this.st.st_loc_new++;
410 this.img.style.visibility = "visible";
411 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
416 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
417 if (this.step_cur == 0) {
418 var date = new Date();
419 // $("logz").innerHTML = "Timestart: " + date + "<br>";
421 if (this.step_cur <= this.step_n) {
422 this.img.style.left = this.x0 + this.dx * this.step_cur;
423 this.img.style.top = this.y0 + this.dy * this.step_cur;
425 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
426 if (this.step_cur == this.step_free && this.st != null) {
427 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
428 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
435 this.img.style.left = this.x1;
436 this.img.style.top = this.y1;
437 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
438 var date = new Date();
439 // $("logz").innerHTML += "Timestop: " + date + "<br>";
440 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
445 if (this.action != null) {
448 if (this.srcend != null) {
449 this.img.src = this.srcend;
455 var asta_xarr = new Array(0,66,132);
457 /* TODO: impostare gli onclick */
458 function dispose_asta(idx, pnt, nopoint)
463 for (i = 0 ; i < 10 ; i++) {
466 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
467 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
471 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
472 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
476 btn.style.left = asta_xarr[i % 3];
478 btn.style.left = asta_xarr[(i+1) % 3];
480 btn.style.top = parseInt(i / 3) * 50 + (i == 9 ? 0 : 1);
483 eval("btn.onclick = function () { act_asta("+pass+",61); }");
484 btn.style.cursor = "pointer";
488 btn.style.cursor = "default";
493 btn = $("astaptdiv");
494 btn.style.left = asta_xarr[i % 3];
495 btn.style.top = parseInt(i / 3) * 50 - 2;
496 // btn.style.visibility = "visible";
499 var rpnt = (pnt < 0 ? -pnt : pnt);
500 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
502 btn = $("astaptsub");
503 btn.style.left = asta_xarr[i % 3];
504 btn.style.top = 25 + parseInt(i / 3) * 50 - 1;
505 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
506 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
508 btn.onclick = function () { act_asta(9,$("astapt").value); };
509 btn.style.cursor = "pointer";
513 btn.style.cursor = "default";
518 btn = $("astapasso");
519 btn.style.left = asta_xarr[i % 3];
520 btn.style.top = parseInt(i / 3) * 50;
521 btn.src = "img/astapashalf"+(pnt >= 0 ? "" : "_ro")+".png";
522 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
524 btn.onclick = function () { act_asta(-1,0); };
530 btn = $("astalascio");
531 btn.style.left = asta_xarr[i % 3];
532 btn.style.top = parseInt(i / 3) * 50 + 24;
533 btn.src = "img/astalascio.png";
534 btn.style.visibility = "visible";
535 btn.onclick = function () { safelascio(); };
538 btn = $("astapasso");
539 btn.style.left = asta_xarr[i % 3];
540 btn.style.top = parseInt(i / 3) * 50;;
541 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
542 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
544 btn.onclick = function () { act_asta(-1,0); };
550 btn = $("astalascio");
551 btn.style.visibility = "hidden";
554 // btn.style.visibility = "visible";
555 $("asta").style.visibility = "visible";
558 function asta_pnt_set(pnt)
561 var rpnt = (pnt < 0 ? -pnt : pnt);
562 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
567 $("asta").style.visibility = "hidden";
571 function notify(st, text, tout, butt, w, h)
578 this.ancestor = document.body;
580 this.st.st_loc_new++;
582 clo = document.createElement("input");
584 clo.className = "button";
585 clo.style.bottom = "4px";
588 clo.onclick = this.input_hide;
590 clodiv = document.createElement("div");
591 clodiv.className = "notify_clo";
592 clodiv.appendChild(clo);
594 box = document.createElement("div");
595 box.className = "notify";
596 box.innerHTML = text;
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.appendChild(clodiv);
602 box.style.visibility = "visible";
606 this.ancestor.appendChild(box);
608 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
619 if (this.st.st_loc < this.st.st_loc_new) {
626 clearTimeout(this.toutid);
627 this.ancestor.removeChild(this.notitag);
631 input_hide: function()
633 clearTimeout(this.obj.toutid);
634 this.obj.ancestor.removeChild(this.obj.notitag);
641 return document.getElementById(id);
647 this.st_loc_new = -1;
648 this.comms = new Array;
653 function remark_step()
655 var ct = $("remark").l_remct;
661 $("remark").className = "remark"+ct;
662 $("remark").l_remct = ct;
663 setTimeout(remark_step,500);
666 $("remark").className = "remark0";
673 if ($("remark").l_remct == 0) {
674 $("remark").l_remct = 1;
675 setTimeout(remark_step,500);
679 function remark_off()
681 $("remark").l_remct = 0;
682 $("remark").className = "remark0";
686 function choose_seed(card)
690 $("chooseed").style.visibility = "visible";
691 for (i = 0 ; i < 4 ; i++) {
692 $("seed"+i).src = "img/"+i+""+card+".png";
694 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
698 function set_names(so,ea,ne,nw,we)
701 $("name").innerHTML = so;
702 $("name").title = so;
703 $("name_ea").innerHTML = ea;
704 $("name_ea").title = ea;
705 $("name_ne").innerHTML = ne;
706 $("name_ne").title = ne;
707 $("name_nw").innerHTML = nw;
708 $("name_nw").title = nw;
709 $("name_we").innerHTML = we;
710 $("name_we").title = we;
715 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
717 function show_astat(zer,uno,due,tre,qua)
719 var astat = new Array(zer,uno,due,tre,qua);
721 for (i = 0 ; i < PLAYERS_N ; i++) {
722 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
724 if (astat[i] == -2) {
725 $("public"+astat_suffix[idx]).style.visibility = "hidden";
727 else if (astat[i] == -1) {
728 $("public"+astat_suffix[idx]).style.visibility = "visible";
729 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
730 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
731 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
733 else if (astat[i] <= 10) {
734 $("public"+astat_suffix[idx]).style.visibility = "visible";
735 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
736 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
738 else if (astat[i] <= 120) {
739 $("public"+astat_suffix[idx]).style.visibility = "visible";
740 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
741 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
742 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
747 function exitlock_show(num, islock)
751 num = (num < 3 ? num : 3);
752 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
753 // alert("EXITLOCK: "+$("exitlock").src);
754 $("exitlock").style.visibility = "visible";
759 // exitlock_show(0, true);
761 function table_init() {
762 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
765 $("asta").style.visibility = "hidden";
766 $("caller").style.visibility = "hidden";
767 show_astat(-2,-2,-2,-2,-2);
768 for (i=0 ; i < 8 ; i++) {
769 Drag.init($("card" + i), card_mouseup_cb);
770 for (e = 0 ; e < PLAYERS_N ; e++)
771 $("card"+sux[e]+i).style.visibility = "hidden";
773 for (i=0 ; i < PLAYERS_N ; i++) {
774 $("takes"+sux[i]).style.visibility = "hidden";
777 for (i = 0 ; i < 8 ; i++) {
789 var chatt_lines = new Array();
790 var chatt_lines_n = 0;
792 var CHATT_MAXLINES = 40;
795 function chatt_sub(name,str)
797 // alert("ARRIVA NAME: "+ name + " STR:"+str);
798 if (chatt_lines_n == CHATT_MAXLINES) {
799 $("txt").innerHTML = "";
800 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
801 chatt_lines[i] = chatt_lines[i+1];
802 $("txt").innerHTML += chatt_lines[i];
804 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
805 $("txt").innerHTML += chatt_lines[i];
808 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
809 $("txt").innerHTML += chatt_lines[chatt_lines_n];
813 $("txt").scrollTop = 10000000;
817 * GESTIONE DEI COOKIES
819 function createCookie(name,value,hours,path) {
821 var date = new Date();
822 date.setTime(date.getTime()+(hours*60*60*1000));
823 var expires = "; expires="+date.toGMTString();
825 else var expires = "";
826 document.cookie = name+"="+value+expires+"; path="+path;
829 function readCookie(name) {
830 var nameEQ = name + "=";
831 var ca = document.cookie.split(';');
832 for(var i=0;i < ca.length;i++) {
834 while (c.charAt(0)==' ') c = c.substring(1,c.length);
835 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
840 function eraseCookie(name) {
841 createCookie(name,"",-1);
844 var onunload_times = 0;
847 function onunload_cb () {
849 if (onunload_times == 0) {
850 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
859 location = self.location;
861 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
871 function room_checkspace(emme,tables,inpe)
874 for (i = 0 ; i < emme ; i++)
879 for (i = 0 ; i < 5 ; i++)
882 for (i = 0 ; i < tables ; i++) {
883 $("table"+i).innerHTML = alta;
884 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
887 stand = "<table class=\"table_standup\"><tbody><tr>";
888 for (i = 0 ; i < inpe ; i++) {
889 stand += "<td>"+nome+"</td>";
890 if ((i+1) % 4 == 0) {
891 stand += "</tr><tr>";
895 $("standup").innerHTML = stand;
897 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
900 function playsound(tag, sound) {
901 // g_withflash is a global var
903 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
904 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
905 '<PARAM NAME="movie" VALUE="playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
906 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
907 '<EMBED swliveconnect="true" name="mysound" src="playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
908 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';