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.
25 function $(id) { return document.getElementById(id); }
27 /* replacement of setInterval on IE */
29 /*if not IE, do nothing*/
30 if(!document.uniqueID){return;};
32 /*Copy the default setInterval behavior*/
33 var nativeSetInterval = window.setInterval;
34 window.setInterval = function(fn,ms) {
36 if(arguments.length <= 2) {
37 return nativeSetInterval(fn,ms);
40 for(var i=2;i<arguments.length;i+=1) {
41 param[i-2] = arguments[i];
45 if(typeof(fn)=='function') {
47 return (function (fn,ms,param) {
48 var fo = function () {
49 fn.apply(window,param);
51 return nativeSetInterval(fo,ms);
54 else if(typeof(fn)=='string')
56 return nativeSetInterval(fn,ms);
60 throw Error('setInterval Error\nInvalid function type');
64 /*Copy the default setTimeout behavior*/
65 var nativeSetTimeout = window.setTimeout;
66 window.setTimeout = function(fn,ms) {
68 if(arguments.length <= 2) {
69 return nativeSetTimeout(fn,ms);
72 for(var i=2;i<arguments.length;i+=1) {
73 param[i-2] = arguments[i];
77 if(typeof(fn)=='function') {
79 return (function (fn,ms,param) {
80 var fo = function () {
81 fn.apply(window,param);
83 return nativeSetTimeout(fo,ms);
86 else if(typeof(fn)=='string')
88 return nativeSetTimeout(fn,ms);
92 throw Error('setTimeout Error\nInvalid function type');
98 // var card_pos = RANGE 0 <= x < cards_ea_n
100 function rnd_int(min, max) {
101 return Math.floor(Math.random() * (max - min + 1) + min);
104 function error_images()
109 function abort_images()
111 alert("ABORTAIMAGES");
114 function unload_images()
116 alert("ABORTAIMAGES");
119 function reset_images()
121 alert("ABORTAIMAGES");
124 function update_images()
126 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
127 if (g_imgct < g_preload_img_arr.length)
128 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct);
130 // $("imgct").innerHTML += "U";
133 function preload_images(arr,idx)
137 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
138 im.onload = update_images;
139 im.onerror = error_images;
140 im.onabort = abort_images;
141 im.onunload = unload_images;
142 im.onreset = reset_images;
144 // $("imgct").innerHTML += "P";
147 function safestatus(a)
155 function createXMLHttpRequest() {
156 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
157 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
158 try { return new XMLHttpRequest(); } catch(e) {}
159 alert("XMLHttpRequest not supported");
163 function send_mesg(mesg)
165 var xhr_wr = createXMLHttpRequest();
166 // xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+encodeURIComponent(mesg), true);
167 xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+mesg, true);
168 xhr_wr.onreadystatechange = function() { return; };
173 /* Stat: CHAT and TABLE */
175 function chatt_checksend(obj,e)
181 if(window.event) { // IE
184 else if(e.which) { // Netscape/Firefox/Opera
187 // alert("OBJ: "+obj);
188 if (keynum == 13 && obj.value != "") { // Enter
189 act_chatt(obj.value);
193 function act_chatt(value)
195 send_mesg("chatt|"+encodeURIComponent(value));
199 obj.disabled = false;
206 function act_sitdown(table)
208 send_mesg("sitdown|"+table);
211 function act_wakeup()
216 /* Stat: TABLE Subst: ASTA */
217 function act_asta(card,pnt)
219 send_mesg("asta|"+card+"|"+pnt);
222 function act_choose(card)
225 send_mesg("choose|"+card);
228 /* Stat: TABLE Subst: GAME */
229 function act_play(card,x,y)
232 send_mesg("play|"+card+"|"+x+"|"+y);
235 function act_tableinfo()
237 send_mesg("tableinfo");
250 function safelogout()
254 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
258 function act_logout()
263 function act_reload()
265 window.onunload = null;
266 document.location.reload();
269 function act_shutdown()
273 send_mesg("shutdown");
274 while (xhr_wr.readyState != 4)
278 function act_preout()
283 function postact_logout()
285 // alert("postact_logout");
290 // eraseCookie("sess");
291 document.location.assign("index.php");
295 function slowimg(img,x1,y1,deltat,free,action,srcend)
297 x1,y1 - destination coords
298 deltat - time for each frame (in msec)
299 free - when the release the local block for other operations (range: 0 - 1)
300 action - function to run when the image is moved
301 srcend - image to switch when the image is moved
304 function sleep(st, delay)
306 // alert("LOC_NEW PRE: "+st.st_loc_new);
310 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
314 function slowimg(img,x1,y1,deltat,free,action,srcend) {
317 this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
318 // alert("img.x0 = "+this.x0);
319 this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
322 this.deltat = deltat;
324 this.action = action;
325 this.srcend = srcend;
328 slowimg.prototype = {
347 setstart: function(x0,y0)
353 setaction: function(act)
358 settime: function(time)
361 this.step_n = parseInt(time / this.deltat);
362 this.dx = (this.x1 - this.x0) / this.step_n;
363 this.dy = (this.y1 - this.y0) / this.step_n;
364 if (this.step_n * this.deltat == time) {
367 this.step_free = parseInt(this.step_n * this.free);
372 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
374 this.st.st_loc_new++;
376 this.img.style.visibility = "visible";
377 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
382 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
383 if (this.step_cur == 0) {
384 var date = new Date();
385 // $("logz").innerHTML = "Timestart: " + date + "<br>";
387 if (this.step_cur <= this.step_n) {
388 this.img.style.left = this.x0 + this.dx * this.step_cur;
389 this.img.style.top = this.y0 + this.dy * this.step_cur;
391 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
392 if (this.step_cur == this.step_free && this.st != null) {
393 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
394 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
401 this.img.style.left = this.x1;
402 this.img.style.top = this.y1;
403 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
404 var date = new Date();
405 // $("logz").innerHTML += "Timestop: " + date + "<br>";
406 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
411 if (this.action != null) {
414 if (this.srcend != null) {
415 this.img.src = this.srcend;
421 var asta_xarr = new Array(0,66,133);
423 /* TODO: impostare gli onclick */
424 function dispose_asta(idx, pnt)
429 for (i = 0 ; i < 10 ; i++) {
432 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
436 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
440 btn.style.left = asta_xarr[i % 3];
442 btn.style.left = asta_xarr[(i+1) % 3];
444 btn.style.top = parseInt(i / 3) * 50+1;
445 // btn.style.visibility = "visible";
448 eval("btn.onclick = function () { act_asta("+pass+",61); }");
454 btn = $("astaptdiv");
455 btn.style.left = asta_xarr[i % 3];
456 btn.style.top = parseInt(i / 3) * 50;
457 // btn.style.visibility = "visible";
460 var rpnt = (pnt < 0 ? -pnt : pnt);
461 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
463 btn = $("astaptsub");
464 btn.style.left = asta_xarr[i % 3];
465 btn.style.top = 25 + parseInt(i / 3) * 50;;
466 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
467 // btn.style.visibility = "visible";
469 btn.onclick = function () { act_asta(9,$("astapt").value); };
474 btn = $("astapasso2");
475 btn.style.left = asta_xarr[i % 3];
476 btn.style.top = parseInt(i / 3) * 50;;
477 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
478 // btn.style.visibility = "visible";
480 btn.onclick = function () { act_asta(-1,0); };
483 $("asta").style.visibility = "visible";
488 $("asta").style.visibility = "hidden";
492 function notify(st, text, tout, butt, w, h)
499 this.ancestor = document.body;
501 this.st.st_loc_new++;
503 clo = document.createElement("input");
505 clo.className = "button";
506 clo.style.bottom = "4px";
509 clo.onclick = this.input_hide;
511 clodiv = document.createElement("div");
512 clodiv.className = "notify_clo";
513 clodiv.appendChild(clo);
515 box = document.createElement("div");
516 box.className = "notify";
517 box.innerHTML = text;
518 box.style.zIndex = 200;
519 box.style.width = w+"px";
520 box.style.height = h+"px";
521 box.appendChild(clodiv);
522 box.style.visibility = "visible";
526 this.ancestor.appendChild(box);
528 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
539 if (this.st.st_loc < this.st.st_loc_new) {
546 clearTimeout(this.toutid);
547 this.ancestor.removeChild(this.notitag);
551 input_hide: function()
553 clearTimeout(this.obj.toutid);
554 this.obj.ancestor.removeChild(this.obj.notitag);
561 return document.getElementById(id);
567 this.st_loc_new = -1;
568 this.comms = new Array;
573 function remark_step()
575 var ct = $("remark").l_remct;
581 $("remark").className = "remark"+ct;
582 $("remark").l_remct = ct;
583 setTimeout(remark_step,500);
586 $("remark").className = "remark0";
593 if ($("remark").l_remct == 0) {
594 $("remark").l_remct = 1;
595 setTimeout(remark_step,500);
599 function remark_off()
601 $("remark").l_remct = 0;
602 $("remark").className = "remark0";
606 function choose_seed(card)
610 $("chooseed").style.visibility = "visible";
611 for (i = 0 ; i < 4 ; i++) {
612 $("seed"+i).src = "img/"+i+""+card+".png";
614 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
618 function set_names(so,ea,ne,nw,we)
621 $("name").innerHTML = so;
622 $("name").title = so;
623 $("name_ea").innerHTML = ea;
624 $("name_ea").title = ea;
625 $("name_ne").innerHTML = ne;
626 $("name_ne").title = ne;
627 $("name_nw").innerHTML = nw;
628 $("name_nw").title = nw;
629 $("name_we").innerHTML = we;
630 $("name_we").title = we;
635 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
637 function show_astat(zer,uno,due,tre,qua)
639 var astat = new Array(zer,uno,due,tre,qua);
641 for (i = 0 ; i < PLAYERS_N ; i++) {
642 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
644 if (astat[i] == -2) {
645 $("public"+astat_suffix[idx]).style.visibility = "hidden";
647 else if (astat[i] == -1) {
648 $("public"+astat_suffix[idx]).style.visibility = "visible";
649 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
650 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
651 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
653 else if (astat[i] <= 10) {
654 $("public"+astat_suffix[idx]).style.visibility = "visible";
655 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
656 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
658 else if (astat[i] <= 120) {
659 $("public"+astat_suffix[idx]).style.visibility = "visible";
660 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
661 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
662 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
669 function table_init() {
670 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
674 $("asta").style.visibility = "hidden";
675 $("caller").style.visibility = "hidden";
676 show_astat(-2,-2,-2,-2,-2);
678 for (i=0 ; i < 8 ; i++) {
679 Drag.init($("card" + i), card_mouseup_cb);
680 for (e = 0 ; e < PLAYERS_N ; e++)
681 $("card"+sux[e]+i).style.visibility = "hidden";
683 for (i=0 ; i < PLAYERS_N ; i++) {
684 $("takes"+sux[i]).style.visibility = "hidden";
687 for (i = 0 ; i < 8 ; i++) {
699 var chatt_lines = new Array();
700 var chatt_lines_n = 0;
702 var CHATT_MAXLINES = 40;
705 function chatt_sub(name,str)
707 // alert("ARRIVA NAME: "+ name + " STR:"+str);
708 if (chatt_lines_n == CHATT_MAXLINES) {
709 $("txt").innerHTML = "";
710 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
711 chatt_lines[i] = chatt_lines[i+1];
712 $("txt").innerHTML += chatt_lines[i];
714 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
715 $("txt").innerHTML += chatt_lines[i];
718 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
719 $("txt").innerHTML += chatt_lines[chatt_lines_n];
723 $("txt").scrollTop = 10000000;
727 * GESTIONE DEI COOKIES
729 function createCookie(name,value,hours,path) {
731 var date = new Date();
732 date.setTime(date.getTime()+(hours*60*60*1000));
733 var expires = "; expires="+date.toGMTString();
735 else var expires = "";
736 document.cookie = name+"="+value+expires+"; path="+path;
739 function readCookie(name) {
740 var nameEQ = name + "=";
741 var ca = document.cookie.split(';');
742 for(var i=0;i < ca.length;i++) {
744 while (c.charAt(0)==' ') c = c.substring(1,c.length);
745 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
750 function eraseCookie(name) {
751 createCookie(name,"",-1);
754 var onunload_times = 0;
757 function onunload_cb () {
759 if (onunload_times == 0) {
760 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
769 location = self.location;
771 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
781 function room_checkspace(emme,tables,inpe)
784 for (i = 0 ; i < emme ; i++)
789 for (i = 0 ; i < 5 ; i++)
792 for (i = 0 ; i < tables ; i++) {
793 $("table"+i).innerHTML = alta;
794 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
797 stand = "<table class=\"table_standup\"><tbody><tr>";
798 for (i = 0 ; i < inpe ; i++) {
799 stand += "<td class=\"td_standup\">"+nome+"</td>";
800 if ((i+1) % 4 == 0) {
801 stand += "</tr><tr>";
805 $("standup").innerHTML = stand;
807 $("esco").innerHTML = "<input name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
810 function playsound(tag, sound) {
811 // g_withflash is a global var
813 alert("PLAYSOUND "+sound);
814 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
815 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
816 '<PARAM NAME="movie" VALUE="playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
817 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
818 '<EMBED swliveconnect="true" name="mysound" src="playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
819 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';