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 */
142 var obj = $("txt_in");
145 send_mesg("chatt|"+encodeURIComponent(obj.value));
148 obj.disabled = false;
155 function act_sitdown(table)
157 send_mesg("sitdown|"+table);
160 function act_wakeup()
165 /* Stat: TABLE Subst: ASTA */
166 function act_asta(card,pnt)
168 send_mesg("asta|"+card+"|"+pnt);
171 function act_choose(card)
174 send_mesg("choose|"+card);
177 /* Stat: TABLE Subst: GAME */
178 function act_play(card,x,y)
181 send_mesg("play|"+card+"|"+x+"|"+y);
184 function act_tableinfo()
186 send_mesg("tableinfo");
189 function act_logout()
194 function act_preout()
199 function postact_logout()
201 // alert("postact_logout");
207 document.location.assign("index.php");
211 function slowimg(img,x1,y1,deltat,free,action,srcend)
213 x1,y1 - destination coords
214 deltat - time for each frame (in msec)
215 free - when the release the local block for other operations (range: 0 - 1)
216 action - function to run when the image is moved
217 srcend - image to switch when the image is moved
220 function sleep(st, delay)
222 // alert("LOC_NEW PRE: "+st.st_loc_new);
226 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
230 function slowimg(img,x1,y1,deltat,free,action,srcend) {
233 this.x0 = parseInt(window.getComputedStyle(this.img, "").getPropertyValue("left"));
234 // alert("img.x0 = "+this.x0);
235 this.y0 = parseInt(window.getComputedStyle(this.img, "").getPropertyValue("top"));
238 this.deltat = deltat;
240 this.action = action;
241 this.srcend = srcend;
244 slowimg.prototype = {
263 setstart: function(x0,y0)
269 setaction: function(act)
274 settime: function(time)
277 this.step_n = parseInt(time / this.deltat);
278 this.dx = (this.x1 - this.x0) / this.step_n;
279 this.dy = (this.y1 - this.y0) / this.step_n;
280 if (this.step_n * this.deltat == time) {
283 this.step_free = parseInt(this.step_n * this.free);
288 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
290 this.st.st_loc_new++;
292 this.img.style.visibility = "visible";
293 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
298 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
299 if (this.step_cur == 0) {
300 var date = new Date();
301 // $("logz").innerHTML = "Timestart: " + date + "<br>";
303 if (this.step_cur <= this.step_n) {
304 this.img.style.left = this.x0 + this.dx * this.step_cur;
305 this.img.style.top = this.y0 + this.dy * this.step_cur;
307 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
308 if (this.step_cur == this.step_free && this.st != null) {
309 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
310 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
317 this.img.style.left = this.x1;
318 this.img.style.top = this.y1;
319 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
320 var date = new Date();
321 // $("logz").innerHTML += "Timestop: " + date + "<br>";
322 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
327 if (this.action != null) {
330 if (this.srcend != null) {
331 this.img.src = this.srcend;
337 var asta_xarr = new Array(0,66,133);
339 /* TODO: impostare gli onclick */
340 function dispose_asta(idx, pnt)
345 for (i = 0 ; i < 10 ; i++) {
348 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
352 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
356 btn.style.left = asta_xarr[i % 3];
358 btn.style.left = asta_xarr[(i+1) % 3];
360 btn.style.top = parseInt(i / 3) * 50+1;
361 // btn.style.visibility = "visible";
364 eval("btn.onclick = function () { act_asta("+pass+",61); }");
370 btn = $("astaptdiv");
371 btn.style.left = asta_xarr[i % 3];
372 btn.style.top = parseInt(i / 3) * 50;
373 // btn.style.visibility = "visible";
376 var rpnt = (pnt < 0 ? -pnt : pnt);
377 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
379 btn = $("astaptsub");
380 btn.style.left = asta_xarr[i % 3];
381 btn.style.top = 25 + parseInt(i / 3) * 50;;
382 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
383 // btn.style.visibility = "visible";
385 btn.onclick = function () { act_asta(9,$("astapt").value); };
390 btn = $("astapasso2");
391 btn.style.left = asta_xarr[i % 3];
392 btn.style.top = parseInt(i / 3) * 50;;
393 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
394 // btn.style.visibility = "visible";
396 btn.onclick = function () { act_asta(-1,0); };
399 $("asta").style.visibility = "visible";
404 $("asta").style.visibility = "hidden";
407 function notify(st, ancestor, text, tout, butt)
413 this.ancestor = ancestor;
415 this.st.st_loc_new++;
417 clo = document.createElement("input");
421 clo.onclick = this.input_hide;
423 box = document.createElement("div");
424 box.className = "notify";
425 box.innerHTML = text;
426 box.style.zIndex = 200;
427 box.appendChild(clo);
428 box.style.visibility = "visible";
432 this.ancestor.appendChild(box);
434 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
445 if (this.st.st_loc < this.st.st_loc_new) {
452 clearTimeout(this.toutid);
453 this.ancestor.removeChild(this.notitag);
457 input_hide: function()
459 clearTimeout(this.obj.toutid);
460 this.obj.ancestor.removeChild(this.obj.notitag);
467 return document.getElementById(id);
473 this.st_loc_new = -1;
474 this.comms = new Array;
479 function remark_step()
481 var ct = $("remark").l_remct;
487 $("remark").className = "remark"+ct;
488 $("remark").l_remct = ct;
489 setTimeout(remark_step,500);
492 $("remark").className = "remark0";
499 if ($("remark").l_remct == 0) {
500 $("remark").l_remct = 1;
501 setTimeout(remark_step,500);
505 function remark_off()
507 $("remark").l_remct = 0;
508 $("remark").className = "remark0";
512 function choose_seed(card)
516 $("chooseed").style.visibility = "visible";
517 for (i = 0 ; i < 4 ; i++) {
518 $("seed"+i).src = "img/"+i+""+card+".png";
520 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
524 function set_names(so,ea,ne,nw,we)
527 $("name").innerHTML = so;
528 $("name_ea").innerHTML = ea;
529 $("name_ne").innerHTML = ne;
530 $("name_nw").innerHTML = nw;
531 $("name_we").innerHTML = we;
535 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
537 function show_astat(zer,uno,due,tre,qua)
539 var astat = new Array(zer,uno,due,tre,qua);
541 for (i = 0 ; i < PLAYERS_N ; i++) {
542 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
544 if (astat[i] == -2) {
545 $("public"+astat_suffix[idx]).style.visibility = "hidden";
547 else if (astat[i] == -1) {
548 $("public"+astat_suffix[idx]).style.visibility = "visible";
549 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
550 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
551 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
553 else if (astat[i] <= 10) {
554 $("public"+astat_suffix[idx]).style.visibility = "visible";
555 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
556 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
558 else if (astat[i] <= 120) {
559 $("public"+astat_suffix[idx]).style.visibility = "visible";
560 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
561 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
562 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
569 function table_init() {
570 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
574 $("asta").style.visibility = "hidden";
575 $("caller").style.visibility = "hidden";
576 show_astat(-2,-2,-2,-2,-2);
578 for (i=0 ; i < 8 ; i++) {
579 Drag.init($("card" + i), card_mouseup_cb);
580 for (e = 0 ; e < PLAYERS_N ; e++)
581 $("card"+sux[e]+i).style.visibility = "hidden";
583 for (i=0 ; i < PLAYERS_N ; i++) {
584 $("takes"+sux[i]).style.visibility = "hidden";
587 for (i = 0 ; i < 8 ; i++) {
599 var chatt_lines = new Array();
600 var chatt_lines_n = 0;
603 function chatt_sub(name,str)
605 // alert("ARRIVA NAME: "+ name + " STR:"+str);
606 if (chatt_lines_n == 20) {
607 $("txt").innerHTML = "";
608 for (i = 0 ; i < 19 ; i++) {
609 chatt_lines[i] = chatt_lines[i+1];
610 $("txt").innerHTML += chatt_lines[i];
612 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
613 $("txt").innerHTML += chatt_lines[i];
616 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
617 $("txt").innerHTML += chatt_lines[chatt_lines_n];
621 $("txt").scrollTop = 10000000;
625 * GESTIONE DEI COOKIES
627 function createCookie(name,value,hours,path) {
629 var date = new Date();
630 date.setTime(date.getTime()+(hours*60*60*1000));
631 var expires = "; expires="+date.toGMTString();
633 else var expires = "";
634 document.cookie = name+"="+value+expires+"; path="+path;
637 function readCookie(name) {
638 var nameEQ = name + "=";
639 var ca = document.cookie.split(';');
640 for(var i=0;i < ca.length;i++) {
642 while (c.charAt(0)==' ') c = c.substring(1,c.length);
643 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
648 function eraseCookie(name) {
649 createCookie(name,"",-1);
654 window.onload = function() {
655 $("log").innerHTML += " xxxxxxxxxxxxxxxxxxxxxONLOAD<br>";
657 // $("imm2").style.left = 600;
658 // $("imm2").style.top = 400;
659 var zigu = new slowimg($("imm"),300,100,15,"fin");
662 // setTimeout(function() { alert("FIN:" + fin); }, 5000);