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.
23 function $(id) { return document.getElementById(id); }
25 /* replacement of setInterval on IE */
27 /*if not IE, do nothing*/
28 if(!document.uniqueID){return;};
30 /*Copy the default setInterval behavior*/
31 var nativeSetInterval = window.setInterval;
32 window.setInterval = function(fn,ms) {
34 if(arguments.length <= 2) {
35 return nativeSetInterval(fn,ms);
38 for(var i=2;i<arguments.length;i+=1) {
39 param[i-2] = arguments[i];
43 if(typeof(fn)=='function') {
45 return (function (fn,ms,param) {
46 var fo = function () {
47 fn.apply(window,param);
49 return nativeSetInterval(fo,ms);
52 else if(typeof(fn)=='string')
54 return nativeSetInterval(fn,ms);
58 throw Error('setInterval Error\nInvalid function type');
63 // var card_pos = RANGE 0 <= x < cards_ea_n
65 function rnd_int(min, max) {
66 return Math.floor(Math.random() * (max - min + 1) + min);
69 function error_images()
74 function abort_images()
76 alert("ABORTAIMAGES");
79 function unload_images()
81 alert("ABORTAIMAGES");
84 function reset_images()
86 alert("ABORTAIMAGES");
89 function update_images()
91 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
92 if (g_imgct < g_preload_img_arr.length)
93 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct);
95 // $("imgct").innerHTML += "U";
98 function preload_images(arr,idx)
102 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
103 im.onload = update_images;
104 im.onerror = error_images;
105 im.onabort = abort_images;
106 im.onunload = unload_images;
107 im.onreset = reset_images;
109 // $("imgct").innerHTML += "P";
112 function safestatus(a)
120 function createXMLHttpRequest() {
121 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
122 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
123 try { return new XMLHttpRequest(); } catch(e) {}
124 alert("XMLHttpRequest not supported");
128 function send_mesg(mesg)
130 var xhr_wr = createXMLHttpRequest();
131 // xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+encodeURIComponent(mesg), true);
132 xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+mesg, true);
133 xhr_wr.onreadystatechange = function() { return; };
138 /* Stat: CHAT and TABLE */
140 function chatt_checksend(obj,e)
146 if(window.event) { // IE
149 else if(e.which) { // Netscape/Firefox/Opera
152 // alert("OBJ: "+obj);
153 if (keynum == 13 && obj.value != "") { // Enter
154 act_chatt(obj.value);
158 function act_chatt(value)
160 send_mesg("chatt|"+encodeURIComponent(value));
164 obj.disabled = false;
171 function act_sitdown(table)
173 send_mesg("sitdown|"+table);
176 function act_wakeup()
181 /* Stat: TABLE Subst: ASTA */
182 function act_asta(card,pnt)
184 send_mesg("asta|"+card+"|"+pnt);
187 function act_choose(card)
190 send_mesg("choose|"+card);
193 /* Stat: TABLE Subst: GAME */
194 function act_play(card,x,y)
197 send_mesg("play|"+card+"|"+x+"|"+y);
200 function act_tableinfo()
202 send_mesg("tableinfo");
205 function act_logout()
210 function act_preout()
215 function postact_logout()
217 // alert("postact_logout");
223 document.location.assign("index.php");
227 function slowimg(img,x1,y1,deltat,free,action,srcend)
229 x1,y1 - destination coords
230 deltat - time for each frame (in msec)
231 free - when the release the local block for other operations (range: 0 - 1)
232 action - function to run when the image is moved
233 srcend - image to switch when the image is moved
236 function sleep(st, delay)
238 // alert("LOC_NEW PRE: "+st.st_loc_new);
242 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
246 function slowimg(img,x1,y1,deltat,free,action,srcend) {
249 this.x0 = parseInt(window.getComputedStyle(this.img, "").getPropertyValue("left"));
250 // alert("img.x0 = "+this.x0);
251 this.y0 = parseInt(window.getComputedStyle(this.img, "").getPropertyValue("top"));
254 this.deltat = deltat;
256 this.action = action;
257 this.srcend = srcend;
260 slowimg.prototype = {
279 setstart: function(x0,y0)
285 setaction: function(act)
290 settime: function(time)
293 this.step_n = parseInt(time / this.deltat);
294 this.dx = (this.x1 - this.x0) / this.step_n;
295 this.dy = (this.y1 - this.y0) / this.step_n;
296 if (this.step_n * this.deltat == time) {
299 this.step_free = parseInt(this.step_n * this.free);
304 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
306 this.st.st_loc_new++;
308 this.img.style.visibility = "visible";
309 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
314 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
315 if (this.step_cur == 0) {
316 var date = new Date();
317 // $("logz").innerHTML = "Timestart: " + date + "<br>";
319 if (this.step_cur <= this.step_n) {
320 this.img.style.left = this.x0 + this.dx * this.step_cur;
321 this.img.style.top = this.y0 + this.dy * this.step_cur;
323 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
324 if (this.step_cur == this.step_free && this.st != null) {
325 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
326 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
333 this.img.style.left = this.x1;
334 this.img.style.top = this.y1;
335 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
336 var date = new Date();
337 // $("logz").innerHTML += "Timestop: " + date + "<br>";
338 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
343 if (this.action != null) {
346 if (this.srcend != null) {
347 this.img.src = this.srcend;
353 var asta_xarr = new Array(0,66,133);
355 /* TODO: impostare gli onclick */
356 function dispose_asta(idx, pnt)
361 for (i = 0 ; i < 10 ; i++) {
364 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
368 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
372 btn.style.left = asta_xarr[i % 3];
374 btn.style.left = asta_xarr[(i+1) % 3];
376 btn.style.top = parseInt(i / 3) * 50+1;
377 // btn.style.visibility = "visible";
380 eval("btn.onclick = function () { act_asta("+pass+",61); }");
386 btn = $("astaptdiv");
387 btn.style.left = asta_xarr[i % 3];
388 btn.style.top = parseInt(i / 3) * 50;
389 // btn.style.visibility = "visible";
392 var rpnt = (pnt < 0 ? -pnt : pnt);
393 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
395 btn = $("astaptsub");
396 btn.style.left = asta_xarr[i % 3];
397 btn.style.top = 25 + parseInt(i / 3) * 50;;
398 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
399 // btn.style.visibility = "visible";
401 btn.onclick = function () { act_asta(9,$("astapt").value); };
406 btn = $("astapasso2");
407 btn.style.left = asta_xarr[i % 3];
408 btn.style.top = parseInt(i / 3) * 50;;
409 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
410 // btn.style.visibility = "visible";
412 btn.onclick = function () { act_asta(-1,0); };
415 $("asta").style.visibility = "visible";
420 $("asta").style.visibility = "hidden";
423 function notify(st, ancestor, text, tout, butt)
429 this.ancestor = ancestor;
431 this.st.st_loc_new++;
433 clo = document.createElement("input");
437 clo.onclick = this.input_hide;
439 box = document.createElement("div");
440 box.className = "notify";
441 box.innerHTML = text;
442 box.style.zIndex = 200;
443 box.appendChild(clo);
444 box.style.visibility = "visible";
448 this.ancestor.appendChild(box);
450 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
461 if (this.st.st_loc < this.st.st_loc_new) {
468 clearTimeout(this.toutid);
469 this.ancestor.removeChild(this.notitag);
473 input_hide: function()
475 clearTimeout(this.obj.toutid);
476 this.obj.ancestor.removeChild(this.obj.notitag);
483 return document.getElementById(id);
489 this.st_loc_new = -1;
490 this.comms = new Array;
495 function remark_step()
497 var ct = $("remark").l_remct;
503 $("remark").className = "remark"+ct;
504 $("remark").l_remct = ct;
505 setTimeout(remark_step,500);
508 $("remark").className = "remark0";
515 if ($("remark").l_remct == 0) {
516 $("remark").l_remct = 1;
517 setTimeout(remark_step,500);
521 function remark_off()
523 $("remark").l_remct = 0;
524 $("remark").className = "remark0";
528 function choose_seed(card)
532 $("chooseed").style.visibility = "visible";
533 for (i = 0 ; i < 4 ; i++) {
534 $("seed"+i).src = "img/"+i+""+card+".png";
536 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
540 function set_names(so,ea,ne,nw,we)
543 $("name").innerHTML = so;
544 $("name_ea").innerHTML = ea;
545 $("name_ne").innerHTML = ne;
546 $("name_nw").innerHTML = nw;
547 $("name_we").innerHTML = we;
551 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
553 function show_astat(zer,uno,due,tre,qua)
555 var astat = new Array(zer,uno,due,tre,qua);
557 for (i = 0 ; i < PLAYERS_N ; i++) {
558 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
560 if (astat[i] == -2) {
561 $("public"+astat_suffix[idx]).style.visibility = "hidden";
563 else if (astat[i] == -1) {
564 $("public"+astat_suffix[idx]).style.visibility = "visible";
565 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
566 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
567 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
569 else if (astat[i] <= 10) {
570 $("public"+astat_suffix[idx]).style.visibility = "visible";
571 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
572 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
574 else if (astat[i] <= 120) {
575 $("public"+astat_suffix[idx]).style.visibility = "visible";
576 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
577 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
578 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
585 function table_init() {
586 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
590 $("asta").style.visibility = "hidden";
591 $("caller").style.visibility = "hidden";
592 show_astat(-2,-2,-2,-2,-2);
594 for (i=0 ; i < 8 ; i++) {
595 Drag.init($("card" + i), card_mouseup_cb);
596 for (e = 0 ; e < PLAYERS_N ; e++)
597 $("card"+sux[e]+i).style.visibility = "hidden";
599 for (i=0 ; i < PLAYERS_N ; i++) {
600 $("takes"+sux[i]).style.visibility = "hidden";
603 for (i = 0 ; i < 8 ; i++) {
615 var chatt_lines = new Array();
616 var chatt_lines_n = 0;
619 function chatt_sub(name,str)
621 // alert("ARRIVA NAME: "+ name + " STR:"+str);
622 if (chatt_lines_n == 20) {
623 $("txt").innerHTML = "";
624 for (i = 0 ; i < 19 ; i++) {
625 chatt_lines[i] = chatt_lines[i+1];
626 $("txt").innerHTML += chatt_lines[i];
628 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
629 $("txt").innerHTML += chatt_lines[i];
632 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
633 $("txt").innerHTML += chatt_lines[chatt_lines_n];
637 $("txt").scrollTop = 10000000;
641 * GESTIONE DEI COOKIES
643 function createCookie(name,value,hours,path) {
645 var date = new Date();
646 date.setTime(date.getTime()+(hours*60*60*1000));
647 var expires = "; expires="+date.toGMTString();
649 else var expires = "";
650 document.cookie = name+"="+value+expires+"; path="+path;
653 function readCookie(name) {
654 var nameEQ = name + "=";
655 var ca = document.cookie.split(';');
656 for(var i=0;i < ca.length;i++) {
658 while (c.charAt(0)==' ') c = c.substring(1,c.length);
659 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
664 function eraseCookie(name) {
665 createCookie(name,"",-1);
670 window.onload = function() {
671 $("log").innerHTML += " xxxxxxxxxxxxxxxxxxxxxONLOAD<br>";
673 // $("imm2").style.left = 600;
674 // $("imm2").style.top = 400;
675 var zigu = new slowimg($("imm"),300,100,15,"fin");
678 // setTimeout(function() { alert("FIN:" + fin); }, 5000);