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;
26 function $(id) { return document.getElementById(id); }
28 /* replacement of setInterval on IE */
30 /*if not IE, do nothing*/
31 if(!document.uniqueID){return;};
33 /*Copy the default setInterval behavior*/
34 var nativeSetInterval = window.setInterval;
35 window.setInterval = function(fn,ms) {
37 if(arguments.length <= 2) {
38 return nativeSetInterval(fn,ms);
41 for(var i=2;i<arguments.length;i+=1) {
42 param[i-2] = arguments[i];
46 if(typeof(fn)=='function') {
48 return (function (fn,ms,param) {
49 var fo = function () {
50 fn.apply(window,param);
52 return nativeSetInterval(fo,ms);
55 else if(typeof(fn)=='string')
57 return nativeSetInterval(fn,ms);
61 throw Error('setInterval Error\nInvalid function type');
65 /*Copy the default setTimeout behavior*/
66 var nativeSetTimeout = window.setTimeout;
67 window.setTimeout = function(fn,ms) {
69 if(arguments.length <= 2) {
70 return nativeSetTimeout(fn,ms);
73 for(var i=2;i<arguments.length;i+=1) {
74 param[i-2] = arguments[i];
78 if(typeof(fn)=='function') {
80 return (function (fn,ms,param) {
81 var fo = function () {
82 fn.apply(window,param);
84 return nativeSetTimeout(fo,ms);
87 else if(typeof(fn)=='string')
89 return nativeSetTimeout(fn,ms);
93 throw Error('setTimeout Error\nInvalid function type');
99 // var card_pos = RANGE 0 <= x < cards_ea_n
101 function rnd_int(min, max) {
102 return Math.floor(Math.random() * (max - min + 1) + min);
105 function error_images()
110 function abort_images()
112 alert("ABORTAIMAGES");
115 function unload_images()
117 alert("ABORTAIMAGES");
120 function reset_images()
122 alert("ABORTAIMAGES");
125 function update_images()
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);
131 // $("imgct").innerHTML += "U";
134 function preload_images(arr,idx)
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;
145 // $("imgct").innerHTML += "P";
148 function safestatus(a)
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");
164 function send_mesg(mesg)
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; };
174 /* Stat: CHAT and TABLE */
176 function chatt_checksend(obj,e)
182 if(window.event) { // IE
185 else if(e.which) { // Netscape/Firefox/Opera
188 // alert("OBJ: "+obj);
189 if (keynum == 13 && obj.value != "") { // Enter
190 act_chatt(obj.value);
194 function act_chatt(value)
196 send_mesg("chatt|"+encodeURIComponent(value));
200 obj.disabled = false;
207 function act_sitdown(table)
209 send_mesg("sitdown|"+table);
212 function act_wakeup()
217 /* Stat: TABLE Subst: ASTA */
218 function act_asta(card,pnt)
220 send_mesg("asta|"+card+"|"+pnt);
223 function act_choose(card)
226 send_mesg("choose|"+card);
229 /* Stat: TABLE Subst: GAME */
230 function act_play(card,x,y)
233 send_mesg("play|"+card+"|"+x+"|"+y);
236 function act_tableinfo()
238 send_mesg("tableinfo");
251 function act_exitlock()
253 send_mesg("exitlock");
256 function safelogout()
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 "+(floor(EXIT_BAN_TIME/60))+" minuti.");
263 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
265 act_logout(g_exitlock);
268 function act_lascio()
273 function safelascio()
277 res = window.confirm("Sei sicuro di volere lasciare questa mano?");
282 function act_logout(exitlock)
284 send_mesg("logout|"+exitlock);
287 function act_reload()
289 window.onunload = null;
290 document.location.reload();
293 function act_shutdown()
297 send_mesg("shutdown");
298 while (xhr_wr.readyState != 4)
302 function act_preout()
307 function postact_logout()
309 // alert("postact_logout");
314 // eraseCookie("sess");
315 document.location.assign("index.php");
319 function slowimg(img,x1,y1,deltat,free,action,srcend)
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
328 function sleep(st, delay)
330 // alert("LOC_NEW PRE: "+st.st_loc_new);
334 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
338 function slowimg(img,x1,y1,deltat,free,action,srcend) {
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"));
346 this.deltat = deltat;
348 this.action = action;
349 this.srcend = srcend;
352 slowimg.prototype = {
371 setstart: function(x0,y0)
377 setaction: function(act)
382 settime: function(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) {
391 this.step_free = parseInt(this.step_n * this.free);
396 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
398 this.st.st_loc_new++;
400 this.img.style.visibility = "visible";
401 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
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>";
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;
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);
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) {
435 if (this.action != null) {
438 if (this.srcend != null) {
439 this.img.src = this.srcend;
445 var asta_xarr = new Array(0,66,132);
447 /* TODO: impostare gli onclick */
448 function dispose_asta(idx, pnt, nopoint)
453 for (i = 0 ; i < 10 ; i++) {
456 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
460 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
464 btn.style.left = asta_xarr[i % 3];
466 btn.style.left = asta_xarr[(i+1) % 3];
468 btn.style.top = parseInt(i / 3) * 50+1;
471 eval("btn.onclick = function () { act_asta("+pass+",61); }");
472 btn.style.hover_cursor = "pointer";
476 btn.style.hover_cursor = "";
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";
487 var rpnt = (pnt < 0 ? -pnt : pnt);
488 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
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";
496 btn.onclick = function () { act_asta(9,$("astapt").value); };
497 // btn.stylehover.cursor = "pointer";
501 // btn.stylehover.cursor = "";
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";
511 btn.onclick = function () { act_asta(-1,0); };
512 // btn.stylehover.cursor = "pointer";
516 // btn.stylehover.cursor = "";
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(); };
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";
532 btn.onclick = function () { act_asta(-1,0); };
533 // btn.stylehover.cursor = "pointer";
537 // btn.stylehover.cursor = "";
540 btn = $("astalascio");
541 btn.style.visibility = "hidden";
544 // btn.style.visibility = "visible";
545 $("asta").style.visibility = "visible";
550 $("asta").style.visibility = "hidden";
554 function notify(st, text, tout, butt, w, h)
561 this.ancestor = document.body;
563 this.st.st_loc_new++;
565 clo = document.createElement("input");
567 clo.className = "button";
568 clo.style.bottom = "4px";
571 clo.onclick = this.input_hide;
573 clodiv = document.createElement("div");
574 clodiv.className = "notify_clo";
575 clodiv.appendChild(clo);
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";
588 this.ancestor.appendChild(box);
590 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
601 if (this.st.st_loc < this.st.st_loc_new) {
608 clearTimeout(this.toutid);
609 this.ancestor.removeChild(this.notitag);
613 input_hide: function()
615 clearTimeout(this.obj.toutid);
616 this.obj.ancestor.removeChild(this.obj.notitag);
623 return document.getElementById(id);
629 this.st_loc_new = -1;
630 this.comms = new Array;
635 function remark_step()
637 var ct = $("remark").l_remct;
643 $("remark").className = "remark"+ct;
644 $("remark").l_remct = ct;
645 setTimeout(remark_step,500);
648 $("remark").className = "remark0";
655 if ($("remark").l_remct == 0) {
656 $("remark").l_remct = 1;
657 setTimeout(remark_step,500);
661 function remark_off()
663 $("remark").l_remct = 0;
664 $("remark").className = "remark0";
668 function choose_seed(card)
672 $("chooseed").style.visibility = "visible";
673 for (i = 0 ; i < 4 ; i++) {
674 $("seed"+i).src = "img/"+i+""+card+".png";
676 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
680 function set_names(so,ea,ne,nw,we)
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;
697 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
699 function show_astat(zer,uno,due,tre,qua)
701 var astat = new Array(zer,uno,due,tre,qua);
703 for (i = 0 ; i < PLAYERS_N ; i++) {
704 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
706 if (astat[i] == -2) {
707 $("public"+astat_suffix[idx]).style.visibility = "hidden";
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";
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";
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];
729 function exitlock_show(num, islock)
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";
741 // exitlock_show(0, true);
743 function table_init() {
744 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
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";
755 for (i=0 ; i < PLAYERS_N ; i++) {
756 $("takes"+sux[i]).style.visibility = "hidden";
759 for (i = 0 ; i < 8 ; i++) {
771 var chatt_lines = new Array();
772 var chatt_lines_n = 0;
774 var CHATT_MAXLINES = 40;
777 function chatt_sub(name,str)
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];
786 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
787 $("txt").innerHTML += chatt_lines[i];
790 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
791 $("txt").innerHTML += chatt_lines[chatt_lines_n];
795 $("txt").scrollTop = 10000000;
799 * GESTIONE DEI COOKIES
801 function createCookie(name,value,hours,path) {
803 var date = new Date();
804 date.setTime(date.getTime()+(hours*60*60*1000));
805 var expires = "; expires="+date.toGMTString();
807 else var expires = "";
808 document.cookie = name+"="+value+expires+"; path="+path;
811 function readCookie(name) {
812 var nameEQ = name + "=";
813 var ca = document.cookie.split(';');
814 for(var i=0;i < ca.length;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);
822 function eraseCookie(name) {
823 createCookie(name,"",-1);
826 var onunload_times = 0;
829 function onunload_cb () {
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)");
841 location = self.location;
843 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
853 function room_checkspace(emme,tables,inpe)
856 for (i = 0 ; i < emme ; i++)
861 for (i = 0 ; i < 5 ; i++)
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);\">";
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>";
877 $("standup").innerHTML = stand;
879 $("esco").innerHTML = "<input name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
882 function playsound(tag, sound) {
883 // g_withflash is a global var
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>';