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');
65 // var card_pos = RANGE 0 <= x < cards_ea_n
67 function rnd_int(min, max) {
68 return Math.floor(Math.random() * (max - min + 1) + min);
71 function error_images()
76 function abort_images()
78 alert("ABORTAIMAGES");
81 function unload_images()
83 alert("ABORTAIMAGES");
86 function reset_images()
88 alert("ABORTAIMAGES");
91 function update_images()
93 // $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
94 if (g_imgct < g_preload_img_arr.length)
95 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct);
97 // $("imgct").innerHTML += "U";
100 function preload_images(arr,idx)
104 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
105 im.onload = update_images;
106 im.onerror = error_images;
107 im.onabort = abort_images;
108 im.onunload = unload_images;
109 im.onreset = reset_images;
111 // $("imgct").innerHTML += "P";
114 function safestatus(a)
122 function createXMLHttpRequest() {
123 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
124 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
125 try { return new XMLHttpRequest(); } catch(e) {}
126 alert("XMLHttpRequest not supported");
130 function send_mesg(mesg)
132 var xhr_wr = createXMLHttpRequest();
133 // xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+encodeURIComponent(mesg), true);
134 xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+mesg, true);
135 xhr_wr.onreadystatechange = function() { return; };
140 /* Stat: CHAT and TABLE */
142 function chatt_checksend(obj,e)
148 if(window.event) { // IE
151 else if(e.which) { // Netscape/Firefox/Opera
154 // alert("OBJ: "+obj);
155 if (keynum == 13 && obj.value != "") { // Enter
156 act_chatt(obj.value);
160 function act_chatt(value)
162 send_mesg("chatt|"+encodeURIComponent(value));
166 obj.disabled = false;
173 function act_sitdown(table)
175 send_mesg("sitdown|"+table);
178 function act_wakeup()
183 /* Stat: TABLE Subst: ASTA */
184 function act_asta(card,pnt)
186 send_mesg("asta|"+card+"|"+pnt);
189 function act_choose(card)
192 send_mesg("choose|"+card);
195 /* Stat: TABLE Subst: GAME */
196 function act_play(card,x,y)
199 send_mesg("play|"+card+"|"+x+"|"+y);
202 function act_tableinfo()
204 send_mesg("tableinfo");
207 function safelogout()
211 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
215 function act_logout()
220 function act_reload()
222 window.onunload = null;
223 document.location.reload();
226 function act_shutdown()
230 send_mesg("shutdown");
231 while (xhr_wr.readyState != 4)
235 function act_preout()
240 function postact_logout()
242 // alert("postact_logout");
247 // eraseCookie("sess");
248 document.location.assign("index.php");
252 function slowimg(img,x1,y1,deltat,free,action,srcend)
254 x1,y1 - destination coords
255 deltat - time for each frame (in msec)
256 free - when the release the local block for other operations (range: 0 - 1)
257 action - function to run when the image is moved
258 srcend - image to switch when the image is moved
261 function sleep(st, delay)
263 // alert("LOC_NEW PRE: "+st.st_loc_new);
267 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
271 function slowimg(img,x1,y1,deltat,free,action,srcend) {
274 this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
275 // alert("img.x0 = "+this.x0);
276 this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
279 this.deltat = deltat;
281 this.action = action;
282 this.srcend = srcend;
285 slowimg.prototype = {
304 setstart: function(x0,y0)
310 setaction: function(act)
315 settime: function(time)
318 this.step_n = parseInt(time / this.deltat);
319 this.dx = (this.x1 - this.x0) / this.step_n;
320 this.dy = (this.y1 - this.y0) / this.step_n;
321 if (this.step_n * this.deltat == time) {
324 this.step_free = parseInt(this.step_n * this.free);
329 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
331 this.st.st_loc_new++;
333 this.img.style.visibility = "visible";
334 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
339 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
340 if (this.step_cur == 0) {
341 var date = new Date();
342 // $("logz").innerHTML = "Timestart: " + date + "<br>";
344 if (this.step_cur <= this.step_n) {
345 this.img.style.left = this.x0 + this.dx * this.step_cur;
346 this.img.style.top = this.y0 + this.dy * this.step_cur;
348 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
349 if (this.step_cur == this.step_free && this.st != null) {
350 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
351 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
358 this.img.style.left = this.x1;
359 this.img.style.top = this.y1;
360 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
361 var date = new Date();
362 // $("logz").innerHTML += "Timestop: " + date + "<br>";
363 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
368 if (this.action != null) {
371 if (this.srcend != null) {
372 this.img.src = this.srcend;
378 var asta_xarr = new Array(0,66,133);
380 /* TODO: impostare gli onclick */
381 function dispose_asta(idx, pnt)
386 for (i = 0 ; i < 10 ; i++) {
389 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
393 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
397 btn.style.left = asta_xarr[i % 3];
399 btn.style.left = asta_xarr[(i+1) % 3];
401 btn.style.top = parseInt(i / 3) * 50+1;
402 // btn.style.visibility = "visible";
405 eval("btn.onclick = function () { act_asta("+pass+",61); }");
411 btn = $("astaptdiv");
412 btn.style.left = asta_xarr[i % 3];
413 btn.style.top = parseInt(i / 3) * 50;
414 // btn.style.visibility = "visible";
417 var rpnt = (pnt < 0 ? -pnt : pnt);
418 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
420 btn = $("astaptsub");
421 btn.style.left = asta_xarr[i % 3];
422 btn.style.top = 25 + parseInt(i / 3) * 50;;
423 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
424 // btn.style.visibility = "visible";
426 btn.onclick = function () { act_asta(9,$("astapt").value); };
431 btn = $("astapasso2");
432 btn.style.left = asta_xarr[i % 3];
433 btn.style.top = parseInt(i / 3) * 50;;
434 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
435 // btn.style.visibility = "visible";
437 btn.onclick = function () { act_asta(-1,0); };
440 $("asta").style.visibility = "visible";
445 $("asta").style.visibility = "hidden";
448 function notify(st, ancestor, text, tout, butt)
454 this.ancestor = ancestor;
456 this.st.st_loc_new++;
458 clo = document.createElement("input");
460 clo.className = "button";
463 clo.onclick = this.input_hide;
465 box = document.createElement("div");
466 box.className = "notify";
467 box.innerHTML = text;
468 box.style.zIndex = 200;
469 box.appendChild(clo);
470 box.style.visibility = "visible";
474 this.ancestor.appendChild(box);
476 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
487 if (this.st.st_loc < this.st.st_loc_new) {
494 clearTimeout(this.toutid);
495 this.ancestor.removeChild(this.notitag);
499 input_hide: function()
501 clearTimeout(this.obj.toutid);
502 this.obj.ancestor.removeChild(this.obj.notitag);
509 return document.getElementById(id);
515 this.st_loc_new = -1;
516 this.comms = new Array;
521 function remark_step()
523 var ct = $("remark").l_remct;
529 $("remark").className = "remark"+ct;
530 $("remark").l_remct = ct;
531 setTimeout(remark_step,500);
534 $("remark").className = "remark0";
541 if ($("remark").l_remct == 0) {
542 $("remark").l_remct = 1;
543 setTimeout(remark_step,500);
547 function remark_off()
549 $("remark").l_remct = 0;
550 $("remark").className = "remark0";
554 function choose_seed(card)
558 $("chooseed").style.visibility = "visible";
559 for (i = 0 ; i < 4 ; i++) {
560 $("seed"+i).src = "img/"+i+""+card+".png";
562 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
566 function set_names(so,ea,ne,nw,we)
569 $("name").innerHTML = so;
570 $("name_ea").innerHTML = ea;
571 $("name_ne").innerHTML = ne;
572 $("name_nw").innerHTML = nw;
573 $("name_we").innerHTML = we;
577 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
579 function show_astat(zer,uno,due,tre,qua)
581 var astat = new Array(zer,uno,due,tre,qua);
583 for (i = 0 ; i < PLAYERS_N ; i++) {
584 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
586 if (astat[i] == -2) {
587 $("public"+astat_suffix[idx]).style.visibility = "hidden";
589 else if (astat[i] == -1) {
590 $("public"+astat_suffix[idx]).style.visibility = "visible";
591 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
592 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
593 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
595 else if (astat[i] <= 10) {
596 $("public"+astat_suffix[idx]).style.visibility = "visible";
597 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
598 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
600 else if (astat[i] <= 120) {
601 $("public"+astat_suffix[idx]).style.visibility = "visible";
602 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
603 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
604 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
611 function table_init() {
612 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
616 $("asta").style.visibility = "hidden";
617 $("caller").style.visibility = "hidden";
618 show_astat(-2,-2,-2,-2,-2);
620 for (i=0 ; i < 8 ; i++) {
621 Drag.init($("card" + i), card_mouseup_cb);
622 for (e = 0 ; e < PLAYERS_N ; e++)
623 $("card"+sux[e]+i).style.visibility = "hidden";
625 for (i=0 ; i < PLAYERS_N ; i++) {
626 $("takes"+sux[i]).style.visibility = "hidden";
629 for (i = 0 ; i < 8 ; i++) {
641 var chatt_lines = new Array();
642 var chatt_lines_n = 0;
645 function chatt_sub(name,str)
647 // alert("ARRIVA NAME: "+ name + " STR:"+str);
648 if (chatt_lines_n == 20) {
649 $("txt").innerHTML = "";
650 for (i = 0 ; i < 19 ; i++) {
651 chatt_lines[i] = chatt_lines[i+1];
652 $("txt").innerHTML += chatt_lines[i];
654 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
655 $("txt").innerHTML += chatt_lines[i];
658 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
659 $("txt").innerHTML += chatt_lines[chatt_lines_n];
663 $("txt").scrollTop = 10000000;
667 * GESTIONE DEI COOKIES
669 function createCookie(name,value,hours,path) {
671 var date = new Date();
672 date.setTime(date.getTime()+(hours*60*60*1000));
673 var expires = "; expires="+date.toGMTString();
675 else var expires = "";
676 document.cookie = name+"="+value+expires+"; path="+path;
679 function readCookie(name) {
680 var nameEQ = name + "=";
681 var ca = document.cookie.split(';');
682 for(var i=0;i < ca.length;i++) {
684 while (c.charAt(0)==' ') c = c.substring(1,c.length);
685 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
690 function eraseCookie(name) {
691 createCookie(name,"",-1);
694 var onunload_times = 0;
697 function onunload_cb () {
699 if (onunload_times == 0) {
700 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
709 location = self.location;
711 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
721 function room_checkspace(emme,tables,inpe)
724 for (i = 0 ; i < emme ; i++)
729 for (i = 0 ; i < 5 ; i++)
732 for (i = 0 ; i < tables ; i++) {
733 $("table"+i).innerHTML = alta;
734 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
737 stand = "<table class=\"table_standup\"><tbody><tr>";
738 for (i = 0 ; i < inpe ; i++) {
739 stand += "<td class=\"td_standup\">"+nome+"</td>";
740 if ((i+1) % 4 == 0) {
741 stand += "</tr><tr>";
745 $("standup").innerHTML = stand;
747 $("esco").innerHTML = "<input name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";