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 show_bigpict(obj, act, x, y)
116 // alert("offsetTop: "+obj.offsetTop+" offsetLeft: "+obj.offsetLeft+"obj.id: "+obj.id);
117 big = $(obj.id+"_big");
119 big.style.left = obj.offsetLeft + x+"px";
120 big.style.top = obj.offsetTop + y+"px";
121 big.style.visibility = "visible";
124 big.style.visibility = "hidden";
128 function rnd_int(min, max) {
129 return Math.floor(Math.random() * (max - min + 1) + min);
132 function error_images()
137 function abort_images()
139 alert("ABORTAIMAGES");
142 function unload_images()
144 alert("ABORTAIMAGES");
147 function reset_images()
149 alert("ABORTAIMAGES");
152 function update_images()
154 // if (g_imgct % 10 == 0) alert("g_imgct: "+g_imgct+" xx "+g_preload_img_arr[g_imgct]);
155 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
156 if (g_imgct+1 < g_preload_img_arr.length) {
158 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
160 // $("imgct").innerHTML += "U";
163 function preload_images(arr,idx)
167 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
168 im.onload = update_images;
169 im.onerror = error_images;
170 im.onabort = abort_images;
171 im.onunload = unload_images;
172 im.onreset = reset_images;
174 // $("imgct").innerHTML += "P";
177 function safestatus(a)
185 function createXMLHttpRequest() {
186 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
187 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
188 try { return new XMLHttpRequest(); } catch(e) {}
189 alert("XMLHttpRequest not supported");
193 function send_mesg(mesg)
195 var xhr_wr = createXMLHttpRequest();
198 xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+mesg, true);
199 xhr_wr.onreadystatechange = function() { return; };
204 /* Stat: CHAT and TABLE */
206 function chatt_checksend(obj,e)
212 if(window.event) { // IE
215 else if(e.which) { // Netscape/Firefox/Opera
218 // alert("OBJ: "+obj);
219 if (keynum == 13 && obj.value != "") { // Enter
220 act_chatt(obj.value);
224 function act_chatt(value)
226 send_mesg("chatt|"+encodeURIComponent(value));
230 obj.disabled = false;
237 function act_sitdown(table)
239 send_mesg("sitdown|"+table);
242 function act_wakeup()
247 /* Stat: TABLE Subst: ASTA */
248 function act_asta(card,pnt)
250 send_mesg("asta|"+card+"|"+pnt);
253 function act_choose(card)
256 send_mesg("choose|"+card);
259 /* Stat: TABLE Subst: GAME */
260 function act_play(card,x,y)
263 send_mesg("play|"+card+"|"+x+"|"+y);
266 function act_tableinfo()
268 send_mesg("tableinfo");
281 function act_exitlock()
283 send_mesg("exitlock");
286 function safelogout()
291 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.");
293 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
295 act_logout(g_exitlock);
298 function act_lascio()
303 function safelascio()
307 res = window.confirm("Sei sicuro di volere lasciare questa mano?");
312 function act_logout(exitlock)
314 send_mesg("logout|"+exitlock);
317 function act_reload()
319 window.onunload = null;
320 document.location.reload();
323 function act_shutdown()
327 send_mesg("shutdown");
328 while (xhr_wr.readyState != 4)
332 function postact_logout()
334 // alert("postact_logout");
339 // eraseCookie("sess");
340 document.location.assign("index.php");
344 function slowimg(img,x1,y1,deltat,free,action,srcend)
346 x1,y1 - destination coords
347 deltat - time for each frame (in msec)
348 free - when the release the local block for other operations (range: 0 - 1)
349 action - function to run when the image is moved
350 srcend - image to switch when the image is moved
353 function sleep(st, delay)
355 // alert("LOC_NEW PRE: "+st.st_loc_new);
359 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
363 function slowimg(img,x1,y1,deltat,free,action,srcend) {
366 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
367 this.x0 = parseInt(getStyle(this.img,"left", "left"));
368 // alert("img.x0 = "+this.x0);
369 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
370 this.y0 = parseInt(getStyle(this.img,"top", "top"));
373 this.deltat = deltat;
375 this.action = action;
376 this.srcend = srcend;
379 slowimg.prototype = {
398 setstart: function(x0,y0)
404 setaction: function(act)
410 settime: function(time)
412 this.time = (time < this.deltat ? this.deltat : time);
413 this.step_n = parseInt(this.time / this.deltat);
414 this.dx = (this.x1 - this.x0) / this.step_n;
415 this.dy = (this.y1 - this.y0) / this.step_n;
416 if (this.step_n * this.deltat == this.time) {
419 this.step_free = parseInt(this.step_n * this.free);
424 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
426 this.st.st_loc_new++;
428 this.img.style.visibility = "visible";
429 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
434 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
435 if (this.step_cur == 0) {
436 var date = new Date();
437 // $("logz").innerHTML = "Timestart: " + date + "<br>";
439 if (this.step_cur <= this.step_n) {
440 this.img.style.left = this.x0 + this.dx * this.step_cur;
441 this.img.style.top = this.y0 + this.dy * this.step_cur;
443 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
444 if (this.step_cur == this.step_free && this.st != null) {
445 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
446 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
453 this.img.style.left = this.x1;
454 this.img.style.top = this.y1;
455 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
456 var date = new Date();
457 // $("logz").innerHTML += "Timestop: " + date + "<br>";
458 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
463 if (this.action != null) {
466 if (this.srcend != null) {
467 this.img.src = this.srcend;
473 var asta_xarr = new Array(0,66,132);
475 /* TODO: impostare gli onclick */
476 function dispose_asta(idx, pnt, nopoint)
481 for (i = 0 ; i < 10 ; i++) {
484 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
485 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
489 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
490 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
494 btn.style.left = asta_xarr[i % 3];
496 btn.style.left = asta_xarr[(i+1) % 3];
498 btn.style.top = parseInt(i / 3) * 50 + (i == 9 ? 0 : 1);
501 eval("btn.onclick = function () { act_asta("+pass+",61); }");
502 btn.style.cursor = "pointer";
506 btn.style.cursor = "default";
511 btn = $("astaptdiv");
512 btn.style.left = asta_xarr[i % 3];
513 btn.style.top = parseInt(i / 3) * 50 - 2;
514 // btn.style.visibility = "visible";
517 var rpnt = (pnt < 0 ? -pnt : pnt);
518 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
520 btn = $("astaptsub");
521 btn.style.left = asta_xarr[i % 3];
522 btn.style.top = 25 + parseInt(i / 3) * 50 - 1;
523 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
524 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
526 btn.onclick = function () { act_asta(9,$("astapt").value); };
527 btn.style.cursor = "pointer";
531 btn.style.cursor = "default";
536 btn = $("astapasso");
537 btn.style.left = asta_xarr[i % 3];
538 btn.style.top = parseInt(i / 3) * 50;
539 btn.src = "img/astapashalf"+(pnt >= 0 ? "" : "_ro")+".png";
540 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
542 btn.onclick = function () { act_asta(-1,0); };
548 btn = $("astalascio");
549 btn.style.left = asta_xarr[i % 3];
550 btn.style.top = parseInt(i / 3) * 50 + 24;
551 btn.src = "img/astalascio.png";
552 btn.style.visibility = "visible";
553 btn.onclick = function () { safelascio(); };
556 btn = $("astapasso");
557 btn.style.left = asta_xarr[i % 3];
558 btn.style.top = parseInt(i / 3) * 50;;
559 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
560 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
562 btn.onclick = function () { act_asta(-1,0); };
568 btn = $("astalascio");
569 btn.style.visibility = "hidden";
572 // btn.style.visibility = "visible";
573 $("asta").style.visibility = "visible";
576 function asta_pnt_set(pnt)
579 var rpnt = (pnt < 0 ? -pnt : pnt);
580 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
585 $("asta").style.visibility = "hidden";
589 function notify(st, text, tout, butt, w, h)
596 this.ancestor = document.body;
598 this.st.st_loc_new++;
600 clo = document.createElement("input");
602 clo.className = "button";
603 clo.style.bottom = "4px";
606 clo.onclick = this.input_hide;
608 clodiv = document.createElement("div");
609 clodiv.className = "notify_clo";
610 clodiv.appendChild(clo);
612 box = document.createElement("div");
613 box.className = "notify";
614 box.innerHTML = text;
615 box.style.zIndex = 200;
616 box.style.width = w+"px";
617 box.style.marginLeft = -parseInt(w/2)+"px";
618 box.style.height = h+"px";
619 box.appendChild(clodiv);
620 box.style.visibility = "visible";
624 this.ancestor.appendChild(box);
626 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
637 if (this.st.st_loc < this.st.st_loc_new) {
644 clearTimeout(this.toutid);
645 this.ancestor.removeChild(this.notitag);
649 input_hide: function()
651 clearTimeout(this.obj.toutid);
652 this.obj.ancestor.removeChild(this.obj.notitag);
659 return document.getElementById(id);
665 this.st_loc_new = -1;
666 this.comms = new Array;
671 function remark_step()
673 var ct = $("remark").l_remct;
679 $("remark").className = "remark"+ct;
680 $("remark").l_remct = ct;
681 setTimeout(remark_step,500);
684 $("remark").className = "remark0";
691 if ($("remark").l_remct == 0) {
692 $("remark").l_remct = 1;
693 setTimeout(remark_step,500);
697 function remark_off()
699 $("remark").l_remct = 0;
700 $("remark").className = "remark0";
704 function choose_seed(card)
708 $("chooseed").style.visibility = "visible";
709 for (i = 0 ; i < 4 ; i++) {
710 $("seed"+i).src = "img/"+i+""+card+".png";
712 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
716 function set_names(so,ea,ne,nw,we)
719 $("name").innerHTML = so;
720 $("name").title = unescapeHTML(so);
721 $("name_ea").innerHTML = ea;
722 $("name_ea").title = unescapeHTML(ea);
723 $("name_ne").innerHTML = ne;
724 $("name_ne").title = unescapeHTML(ne);
725 $("name_nw").innerHTML = nw;
726 $("name_nw").title = unescapeHTML(nw);
727 $("name_we").innerHTML = we;
728 $("name_we").title = unescapeHTML(we);
733 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
735 function show_astat(zer,uno,due,tre,qua)
737 var astat = new Array(zer,uno,due,tre,qua);
739 for (i = 0 ; i < PLAYERS_N ; i++) {
740 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
742 if (astat[i] == -2) {
743 $("public"+astat_suffix[idx]).style.visibility = "hidden";
745 else if (astat[i] == -1) {
746 $("public"+astat_suffix[idx]).style.visibility = "visible";
747 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
748 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
749 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
751 else if (astat[i] <= 10) {
752 $("public"+astat_suffix[idx]).style.visibility = "visible";
753 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
754 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
756 else if (astat[i] <= 120) {
757 $("public"+astat_suffix[idx]).style.visibility = "visible";
758 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
759 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
760 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
765 function exitlock_show(num, islock)
769 num = (num < 3 ? num : 3);
770 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
771 // alert("EXITLOCK: "+$("exitlock").src);
772 $("exitlock").style.visibility = "visible";
777 // exitlock_show(0, true);
779 function table_init() {
780 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
783 $("asta").style.visibility = "hidden";
784 $("caller").style.visibility = "hidden";
785 show_astat(-2,-2,-2,-2,-2);
786 for (i=0 ; i < 8 ; i++) {
787 Drag.init($("card" + i), card_mouseup_cb);
788 for (e = 0 ; e < PLAYERS_N ; e++)
789 $("card"+sux[e]+i).style.visibility = "hidden";
791 for (i=0 ; i < PLAYERS_N ; i++) {
792 $("takes"+sux[i]).style.visibility = "hidden";
795 for (i = 0 ; i < 8 ; i++) {
807 var chatt_lines = new Array();
808 var chatt_lines_n = 0;
810 var CHATT_MAXLINES = 40;
813 function chatt_sub(name,str)
815 // alert("ARRIVA NAME: "+ name + " STR:"+str);
816 if (chatt_lines_n == CHATT_MAXLINES) {
817 $("txt").innerHTML = "";
818 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
819 chatt_lines[i] = chatt_lines[i+1];
820 $("txt").innerHTML += chatt_lines[i];
822 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
823 $("txt").innerHTML += chatt_lines[i];
826 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
827 $("txt").innerHTML += chatt_lines[chatt_lines_n];
831 $("txt").scrollTop = 10000000;
835 * GESTIONE DEI COOKIES
837 function createCookie(name,value,hours,path) {
839 var date = new Date();
840 date.setTime(date.getTime()+(hours*60*60*1000));
841 var expires = "; expires="+date.toGMTString();
843 else var expires = "";
844 document.cookie = name+"="+value+expires+"; path="+path;
847 function readCookie(name) {
848 var nameEQ = name + "=";
849 var ca = document.cookie.split(';');
850 for(var i=0;i < ca.length;i++) {
852 while (c.charAt(0)==' ') c = c.substring(1,c.length);
853 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
858 function eraseCookie(name) {
859 createCookie(name,"",-1);
862 var onunload_times = 0;
865 function onunload_cb () {
867 if (onunload_times == 0) {
868 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
877 location = self.location;
879 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
889 function room_checkspace(emme,tables,inpe)
892 for (i = 0 ; i < emme ; i++)
897 for (i = 0 ; i < 5 ; i++)
900 for (i = 0 ; i < tables ; i++) {
901 $("table"+i).innerHTML = alta;
902 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
905 stand = "<table class=\"table_standup\"><tbody><tr>";
906 for (i = 0 ; i < inpe ; i++) {
907 stand += "<td>"+nome+"</td>";
908 if ((i+1) % 4 == 0) {
909 stand += "</tr><tr>";
913 $("standup").innerHTML = stand;
915 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
918 function unescapeHTML(cont) {
919 var div = document.createElement('div');
923 div.innerHTML = cont;
924 if (div.childNodes[0]) {
925 if (div.childNodes.length > 1) {
926 if (div.childNodes.toArray)
929 var length = div.childNodes.length, results = new Array(length);
931 results[length] = div.childNodes[length];
933 for (i=0 ; i<results.length ; i++)
934 memo = memo + results[i].nodeValue;
940 return (div.childNodes[0].nodeValue);
948 function playsound(tag, sound) {
949 // g_withflash is a global var
951 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
952 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
953 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
954 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
955 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
956 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';