4 * Copyright (C) 2006-2008 Matteo Nastasi
5 * mailto: nastasi@alternativeoutput.it
6 * matteo.nastasi@milug.org
7 * web: http://www.alternativeoutput.it
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program; if
19 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20 * Suite 330, Boston, MA 02111-1307, USA.
27 var EXIT_BAN_TIME = 900;
28 var cookiepath = "/brisk/";
30 function $(id) { return document.getElementById(id); }
32 function getStyle(x,IEstyleProp, MozStyleProp)
35 var y = x.currentStyle[IEstyleProp];
36 } else if (window.getComputedStyle) {
37 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
42 /* replacement of setInterval on IE */
44 /*if not IE, do nothing*/
45 if(!document.uniqueID){return;};
47 /*Copy the default setInterval behavior*/
48 var nativeSetInterval = window.setInterval;
49 window.setInterval = function(fn,ms) {
51 if(arguments.length <= 2) {
52 return nativeSetInterval(fn,ms);
55 for(var i=2;i<arguments.length;i+=1) {
56 param[i-2] = arguments[i];
60 if(typeof(fn)=='function') {
62 return (function (fn,ms,param) {
63 var fo = function () {
64 fn.apply(window,param);
66 return nativeSetInterval(fo,ms);
69 else if(typeof(fn)=='string')
71 return nativeSetInterval(fn,ms);
75 throw Error('setInterval Error\nInvalid function type');
79 /*Copy the default setTimeout behavior*/
80 var nativeSetTimeout = window.setTimeout;
81 window.setTimeout = function(fn,ms) {
83 if(arguments.length <= 2) {
84 return nativeSetTimeout(fn,ms);
87 for(var i=2;i<arguments.length;i+=1) {
88 param[i-2] = arguments[i];
92 if(typeof(fn)=='function') {
94 return (function (fn,ms,param) {
95 var fo = function () {
96 fn.apply(window,param);
98 return nativeSetTimeout(fo,ms);
101 else if(typeof(fn)=='string')
103 return nativeSetTimeout(fn,ms);
107 throw Error('setTimeout Error\nInvalid function type');
113 function addEvent(obj,type,fn)
115 if (obj.addEventListener) {
116 obj.addEventListener( type, fn, false);
118 else if (obj.attachEvent) {
119 obj["e"+type+fn] = fn;
120 obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
121 obj.attachEvent( "on"+type, obj[type+fn] );
124 throw new Error("Event registration not supported");
127 function removeEvent(obj,type,fn)
129 if (obj.removeEventListener) {
130 obj.removeEventListener( type, fn, false );
132 else if (obj.detachEvent) {
133 obj.detachEvent( "on"+type, obj[type+fn] );
135 obj["e"+type+fn] = null;
139 // var card_pos = RANGE 0 <= x < cards_ea_n
141 function show_bigpict(obj, act, x, y)
145 if (arguments.length > 4)
150 big = $(obj.id+"_big"+sfx);
152 big.style.left = obj.offsetLeft + x+"px";
153 big.style.top = obj.offsetTop + y+"px";
154 big.style.visibility = "visible";
157 big.style.visibility = "hidden";
161 function rnd_int(min, max) {
162 return Math.floor(Math.random() * (max - min + 1) + min);
165 function error_images()
170 function abort_images()
172 alert("ABORTAIMAGES");
175 function unload_images()
177 alert("ABORTAIMAGES");
180 function reset_images()
182 alert("ABORTAIMAGES");
185 function update_images()
187 // if (g_imgct % 10 == 0) alert("g_imgct: "+g_imgct+" xx "+g_preload_img_arr[g_imgct]);
188 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
189 if (g_imgct+1 < g_preload_img_arr.length) {
191 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
193 // $("imgct").innerHTML += "U";
196 function preload_images(arr,idx)
200 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
201 im.onload = update_images;
202 im.onerror = error_images;
203 im.onabort = abort_images;
204 im.onunload = unload_images;
205 im.onreset = reset_images;
207 // $("imgct").innerHTML += "P";
210 function safestatus(a)
218 function createXMLHttpRequest() {
219 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
220 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
221 try { return new XMLHttpRequest(); } catch(e) {}
222 alert("XMLHttpRequest not supported");
226 function send_mesg(mesg)
228 var xhr_wr = createXMLHttpRequest();
229 var is_conn = (sess == "not_connected" ? false : true);
231 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, (is_conn ? true : false));
232 xhr_wr.onreadystatechange = function() { return; };
236 if (xhr_wr.responseText != null) {
237 eval(xhr_wr.responseText);
242 /* Stat: CHAT and TABLE */
244 function chatt_checksend(obj,e)
250 if(window.event) { // IE
253 else if(e.which) { // Netscape/Firefox/Opera
256 // alert("OBJ: "+obj);
257 if (keynum == 13 && obj.value != "") { // Enter
258 act_chatt(obj.value);
262 function act_chatt(value)
264 send_mesg("chatt|"+encodeURIComponent(value));
268 obj.disabled = false;
275 function act_sitdown(table)
277 send_mesg("sitdown|"+table);
280 function act_wakeup()
285 /* Stat: TABLE Subst: ASTA */
286 function act_asta(card,pnt)
288 send_mesg("asta|"+card+"|"+pnt);
291 function act_choose(card)
294 send_mesg("choose|"+card);
297 /* Stat: TABLE Subst: GAME */
298 function act_play(card,x,y)
301 send_mesg("play|"+card+"|"+x+"|"+y);
304 function act_tableinfo()
306 send_mesg("tableinfo");
316 act_chatt('/tav '+$('txt_in').value);
317 $('txt_in').value = '';
325 function act_roadmap()
327 send_mesg("roadmap");
330 function act_whysupport()
332 send_mesg("whysupport");
335 function act_exitlock()
337 send_mesg("exitlock");
340 function safelogout()
345 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 "+(Math.floor(EXIT_BAN_TIME/60))+" minuti.");
347 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
349 act_logout(g_exitlock);
352 function act_lascio()
357 function safelascio()
361 res = window.confirm("Sei sicuro di volere lasciare questa mano?");
366 function act_logout(exitlock)
368 send_mesg("logout|"+exitlock);
371 function act_reload()
373 window.onunload = null;
374 document.location.reload();
377 function act_shutdown()
381 send_mesg("shutdown");
382 while (xhr_wr.readyState != 4)
386 function postact_logout()
388 // alert("postact_logout");
393 // eraseCookie("sess");
394 document.location.assign("index.php");
398 function slowimg(img,x1,y1,deltat,free,action,srcend)
400 x1,y1 - destination coords
401 deltat - time for each frame (in msec)
402 free - when the release the local block for other operations (range: 0 - 1)
403 action - function to run when the image is moved
404 srcend - image to switch when the image is moved
407 function sleep(st, delay)
409 // alert("LOC_NEW PRE: "+st.st_loc_new);
413 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
417 function slowimg(img,x1,y1,deltat,free,action,srcend) {
420 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
421 this.x0 = parseInt(getStyle(this.img,"left", "left"));
422 // alert("img.x0 = "+this.x0);
423 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
424 this.y0 = parseInt(getStyle(this.img,"top", "top"));
427 this.deltat = deltat;
429 this.action = action;
430 this.srcend = srcend;
433 slowimg.prototype = {
452 setstart: function(x0,y0)
458 setaction: function(act)
464 settime: function(time)
466 this.time = (time < this.deltat ? this.deltat : time);
467 this.step_n = parseInt(this.time / this.deltat);
468 this.dx = (this.x1 - this.x0) / this.step_n;
469 this.dy = (this.y1 - this.y0) / this.step_n;
470 if (this.step_n * this.deltat == this.time) {
474 this.step_free = parseInt(this.step_n * this.free);
480 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
482 this.st.st_loc_new++;
484 this.img.style.visibility = "visible";
485 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
490 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
491 if (this.step_cur == 0) {
492 var date = new Date();
493 // $("logz").innerHTML = "Timestart: " + date + "<br>";
495 if (this.step_cur <= this.step_n) {
496 this.img.style.left = this.x0 + this.dx * this.step_cur;
497 this.img.style.top = this.y0 + this.dy * this.step_cur;
499 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
500 if (this.step_cur == this.step_free && this.st != null) {
501 if (this.st.st_loc < this.st.st_loc_new) {
502 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
509 this.img.style.left = this.x1;
510 this.img.style.top = this.y1;
511 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
512 var date = new Date();
513 // $("logz").innerHTML += "Timestop: " + date + "<br>";
515 if (this.action != null) {
519 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
524 if (this.srcend != null) {
525 this.img.src = this.srcend;
531 var asta_xarr = new Array(0,66,132);
533 /* TODO: impostare gli onclick */
534 function dispose_asta(idx, pnt, nopoint)
539 for (i = 0 ; i < 10 ; i++) {
542 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
543 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
547 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
548 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
552 btn.style.left = asta_xarr[i % 3];
554 btn.style.left = asta_xarr[(i+1) % 3];
556 btn.style.top = parseInt(i / 3) * 50 + (i == 9 ? 0 : 1);
559 eval("btn.onclick = function () { act_asta("+pass+",61); }");
560 btn.style.cursor = "pointer";
564 btn.style.cursor = "default";
569 btn = $("astaptdiv");
570 btn.style.left = asta_xarr[i % 3];
571 btn.style.top = parseInt(i / 3) * 50 - 2;
572 // btn.style.visibility = "visible";
575 var rpnt = (pnt < 0 ? -pnt : pnt);
576 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
578 btn = $("astaptsub");
579 btn.style.left = asta_xarr[i % 3];
580 btn.style.top = 25 + parseInt(i / 3) * 50 - 1;
581 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
582 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
584 btn.onclick = function () { act_asta(9,$("astapt").value); };
585 btn.style.cursor = "pointer";
589 btn.style.cursor = "default";
594 btn = $("astapasso");
595 btn.style.left = asta_xarr[i % 3];
596 btn.style.top = parseInt(i / 3) * 50;
597 btn.src = "img/astapashalf"+(pnt >= 0 ? "" : "_ro")+".png";
598 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
600 btn.onclick = function () { act_asta(-1,0); };
606 btn = $("astalascio");
607 btn.style.left = asta_xarr[i % 3];
608 btn.style.top = parseInt(i / 3) * 50 + 24;
609 btn.src = "img/astalascio.png";
610 btn.style.visibility = "visible";
611 btn.onclick = function () { safelascio(); };
614 btn = $("astapasso");
615 btn.style.left = asta_xarr[i % 3];
616 btn.style.top = parseInt(i / 3) * 50;;
617 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
618 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
620 btn.onclick = function () { act_asta(-1,0); };
626 btn = $("astalascio");
627 btn.style.visibility = "hidden";
630 // btn.style.visibility = "visible";
631 $("asta").style.visibility = "visible";
634 function asta_pnt_set(pnt)
637 var rpnt = (pnt < 0 ? -pnt : pnt);
638 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
643 $("asta").style.visibility = "hidden";
647 function notify(st, text, tout, butt, w, h)
654 this.ancestor = document.body;
656 this.st.st_loc_new++;
658 clo = document.createElement("input");
660 clo.className = "button";
661 clo.style.bottom = "4px";
664 clo.onclick = this.input_hide;
666 clodiv = document.createElement("div");
667 clodiv.className = "notify_clo";
668 clodiv.appendChild(clo);
670 box = document.createElement("div");
671 box.className = "notify";
672 box.innerHTML = text;
673 box.style.zIndex = 200;
674 box.style.width = w+"px";
675 box.style.marginLeft = -parseInt(w/2)+"px";
676 box.style.height = h+"px";
677 box.appendChild(clodiv);
678 box.style.visibility = "visible";
682 this.ancestor.appendChild(box);
684 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
695 if (this.st.st_loc < this.st.st_loc_new) {
702 clearTimeout(this.toutid);
703 this.ancestor.removeChild(this.notitag);
707 input_hide: function()
709 clearTimeout(this.obj.toutid);
710 this.obj.ancestor.removeChild(this.obj.notitag);
717 return document.getElementById(id);
723 this.st_loc_new = -1;
724 this.comms = new Array;
729 function remark_step()
731 var ct = $("remark").l_remct;
737 $("remark").className = "remark"+ct;
738 $("remark").l_remct = ct;
739 setTimeout(remark_step,500);
742 $("remark").className = "remark0";
749 if ($("remark").l_remct == 0) {
750 $("remark").l_remct = 1;
751 setTimeout(remark_step,500);
755 function remark_off()
757 $("remark").l_remct = 0;
758 $("remark").className = "remark0";
762 function choose_seed(card)
766 $("chooseed").style.visibility = "visible";
767 for (i = 0 ; i < 4 ; i++) {
768 $("seed"+i).src = "img/"+i+""+card+".png";
770 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
774 function set_names(so,ea,ne,nw,we)
777 $("name").innerHTML = so;
778 $("name").title = unescapeHTML(so);
779 $("name_ea").innerHTML = ea;
780 $("name_ea").title = unescapeHTML(ea);
781 $("name_ne").innerHTML = ne;
782 $("name_ne").title = unescapeHTML(ne);
783 $("name_nw").innerHTML = nw;
784 $("name_nw").title = unescapeHTML(nw);
785 $("name_we").innerHTML = we;
786 $("name_we").title = unescapeHTML(we);
791 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
793 function show_astat(zer,uno,due,tre,qua)
795 var astat = new Array(zer,uno,due,tre,qua);
797 for (i = 0 ; i < PLAYERS_N ; i++) {
798 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
800 if (astat[i] == -2) {
801 $("public"+astat_suffix[idx]).style.visibility = "hidden";
803 else if (astat[i] == -1) {
804 $("public"+astat_suffix[idx]).style.visibility = "visible";
805 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
806 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
807 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
809 else if (astat[i] <= 10) {
810 $("public"+astat_suffix[idx]).style.visibility = "visible";
811 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
812 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
814 else if (astat[i] <= 120) {
815 $("public"+astat_suffix[idx]).style.visibility = "visible";
816 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
817 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
818 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
823 function exitlock_show(num, islock)
827 num = (num < 3 ? num : 3);
828 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
829 // alert("EXITLOCK: "+$("exitlock").src);
830 $("exitlock").style.visibility = "visible";
835 // exitlock_show(0, true);
837 function table_init() {
838 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
840 // console.log("table_init");
843 $("asta").style.visibility = "hidden";
844 $("caller").style.visibility = "hidden";
845 show_astat(-2,-2,-2,-2,-2);
846 for (i=0 ; i < 8 ; i++) {
847 Drag.init($("card" + i), card_mouseup_cb);
848 for (e = 0 ; e < PLAYERS_N ; e++)
849 $("card"+sux[e]+i).style.visibility = "hidden";
851 for (i=0 ; i < PLAYERS_N ; i++) {
852 // console.log("shut: "+"takes"+sux[i]);
853 $("takes"+sux[i]).style.visibility = "hidden";
856 for (i = 0 ; i < 8 ; i++) {
868 var chatt_lines = new Array();
869 var chatt_lines_n = 0;
871 var CHATT_MAXLINES = 40;
874 function chatt_sub(name,str)
876 var must_scroll = false;
878 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
880 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
883 // alert("ARRIVA NAME: "+ name + " STR:"+str);
884 if (chatt_lines_n == CHATT_MAXLINES) {
885 $("txt").innerHTML = "";
886 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
887 chatt_lines[i] = chatt_lines[i+1];
888 $("txt").innerHTML += chatt_lines[i];
890 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
891 $("txt").innerHTML += chatt_lines[i];
894 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
895 $("txt").innerHTML += chatt_lines[chatt_lines_n];
898 // $("txt").innerHTML;
902 $("txt").scrollTop = 10000000;
904 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
908 * GESTIONE DEI COOKIES
910 function createCookie(name,value,hours,path) {
912 var date = new Date();
913 date.setTime(date.getTime()+(hours*60*60*1000));
914 var expires = "; expires="+date.toGMTString();
916 else var expires = "";
917 document.cookie = name+"="+value+expires+"; path="+path;
920 function readCookie(name) {
921 var nameEQ = name + "=";
922 var ca = document.cookie.split(';');
923 for(var i=0;i < ca.length;i++) {
925 while (c.charAt(0)==' ') c = c.substring(1,c.length);
926 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
931 function eraseCookie(name) {
932 createCookie(name,"",-1);
935 var onunload_times = 0;
938 function onunload_cb () {
940 if (onunload_times == 0) {
941 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
950 location = self.location;
952 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
962 function room_checkspace(emme,tables,inpe)
965 for (i = 0 ; i < emme ; i++)
970 for (i = 0 ; i < 5 ; i++)
973 for (i = 0 ; i < tables ; i++) {
974 $("table"+i).innerHTML = alta;
975 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
978 stand = "<table class=\"table_standup\"><tbody><tr>";
979 for (i = 0 ; i < inpe ; i++) {
980 stand += "<td>"+nome+"</td>";
981 if ((i+1) % 4 == 0) {
982 stand += "</tr><tr>";
986 $("standup").innerHTML = stand;
988 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
991 function unescapeHTML(cont) {
992 var div = document.createElement('div');
996 div.innerHTML = cont;
997 if (div.childNodes[0]) {
998 if (div.childNodes.length > 1) {
999 if (div.childNodes.toArray)
1002 var length = div.childNodes.length, results = new Array(length);
1004 results[length] = div.childNodes[length];
1006 for (i=0 ; i<results.length ; i++)
1007 memo = memo + results[i].nodeValue;
1013 return (div.childNodes[0].nodeValue);
1021 function playsound(tag, sound) {
1022 // g_withflash is a global var
1024 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
1025 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
1026 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
1027 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
1028 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
1029 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
1033 function topbanner_init()
1035 // setInterval(topbanner_cb, 666);
1039 function topbanner_cb()
1043 a = $('topbanner').style.backgroundColor;
1044 b = $('topbanner').style.borderLeftColor;
1046 $('topbanner').style.backgroundColor = b;
1047 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
1049 // console.log("A: "+a+" B: "+b);