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 // alert("offsetTop: "+obj.offsetTop+" offsetLeft: "+obj.offsetLeft+"obj.id: "+obj.id);
146 big = $(obj.id+"_big");
148 big.style.left = obj.offsetLeft + x+"px";
149 big.style.top = obj.offsetTop + y+"px";
150 big.style.visibility = "visible";
153 big.style.visibility = "hidden";
157 function rnd_int(min, max) {
158 return Math.floor(Math.random() * (max - min + 1) + min);
161 function error_images()
166 function abort_images()
168 alert("ABORTAIMAGES");
171 function unload_images()
173 alert("ABORTAIMAGES");
176 function reset_images()
178 alert("ABORTAIMAGES");
181 function update_images()
183 // if (g_imgct % 10 == 0) alert("g_imgct: "+g_imgct+" xx "+g_preload_img_arr[g_imgct]);
184 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
185 if (g_imgct+1 < g_preload_img_arr.length) {
187 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
189 // $("imgct").innerHTML += "U";
192 function preload_images(arr,idx)
196 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
197 im.onload = update_images;
198 im.onerror = error_images;
199 im.onabort = abort_images;
200 im.onunload = unload_images;
201 im.onreset = reset_images;
203 // $("imgct").innerHTML += "P";
206 function safestatus(a)
214 function createXMLHttpRequest() {
215 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
216 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
217 try { return new XMLHttpRequest(); } catch(e) {}
218 alert("XMLHttpRequest not supported");
222 function send_mesg(mesg)
224 var xhr_wr = createXMLHttpRequest();
227 xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+mesg, true);
228 xhr_wr.onreadystatechange = function() { return; };
233 /* Stat: CHAT and TABLE */
235 function chatt_checksend(obj,e)
241 if(window.event) { // IE
244 else if(e.which) { // Netscape/Firefox/Opera
247 // alert("OBJ: "+obj);
248 if (keynum == 13 && obj.value != "") { // Enter
249 act_chatt(obj.value);
253 function act_chatt(value)
255 send_mesg("chatt|"+encodeURIComponent(value));
259 obj.disabled = false;
266 function act_sitdown(table)
268 send_mesg("sitdown|"+table);
271 function act_wakeup()
276 /* Stat: TABLE Subst: ASTA */
277 function act_asta(card,pnt)
279 send_mesg("asta|"+card+"|"+pnt);
282 function act_choose(card)
285 send_mesg("choose|"+card);
288 /* Stat: TABLE Subst: GAME */
289 function act_play(card,x,y)
292 send_mesg("play|"+card+"|"+x+"|"+y);
295 function act_tableinfo()
297 send_mesg("tableinfo");
307 act_chatt('/tav '+$('txt_in').value);
308 $('txt_in').value = '';
316 function act_roadmap()
318 send_mesg("roadmap");
321 function act_whysupport()
323 send_mesg("whysupport");
326 function act_exitlock()
328 send_mesg("exitlock");
331 function safelogout()
336 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.");
338 res = window.confirm("Sei sicuro di volere abbandonare la partita?");
340 act_logout(g_exitlock);
343 function act_lascio()
348 function safelascio()
352 res = window.confirm("Sei sicuro di volere lasciare questa mano?");
357 function act_logout(exitlock)
359 send_mesg("logout|"+exitlock);
362 function act_reload()
364 window.onunload = null;
365 document.location.reload();
368 function act_shutdown()
372 send_mesg("shutdown");
373 while (xhr_wr.readyState != 4)
377 function postact_logout()
379 // alert("postact_logout");
384 // eraseCookie("sess");
385 document.location.assign("index.php");
389 function slowimg(img,x1,y1,deltat,free,action,srcend)
391 x1,y1 - destination coords
392 deltat - time for each frame (in msec)
393 free - when the release the local block for other operations (range: 0 - 1)
394 action - function to run when the image is moved
395 srcend - image to switch when the image is moved
398 function sleep(st, delay)
400 // alert("LOC_NEW PRE: "+st.st_loc_new);
404 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
408 function slowimg(img,x1,y1,deltat,free,action,srcend) {
411 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
412 this.x0 = parseInt(getStyle(this.img,"left", "left"));
413 // alert("img.x0 = "+this.x0);
414 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
415 this.y0 = parseInt(getStyle(this.img,"top", "top"));
418 this.deltat = deltat;
420 this.action = action;
421 this.srcend = srcend;
424 slowimg.prototype = {
443 setstart: function(x0,y0)
449 setaction: function(act)
455 settime: function(time)
457 this.time = (time < this.deltat ? this.deltat : time);
458 this.step_n = parseInt(this.time / this.deltat);
459 this.dx = (this.x1 - this.x0) / this.step_n;
460 this.dy = (this.y1 - this.y0) / this.step_n;
461 if (this.step_n * this.deltat == this.time) {
465 this.step_free = parseInt(this.step_n * this.free);
471 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
473 this.st.st_loc_new++;
475 this.img.style.visibility = "visible";
476 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
481 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
482 if (this.step_cur == 0) {
483 var date = new Date();
484 // $("logz").innerHTML = "Timestart: " + date + "<br>";
486 if (this.step_cur <= this.step_n) {
487 this.img.style.left = this.x0 + this.dx * this.step_cur;
488 this.img.style.top = this.y0 + this.dy * this.step_cur;
490 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
491 if (this.step_cur == this.step_free && this.st != null) {
492 if (this.st.st_loc < this.st.st_loc_new) {
493 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
500 this.img.style.left = this.x1;
501 this.img.style.top = this.y1;
502 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
503 var date = new Date();
504 // $("logz").innerHTML += "Timestop: " + date + "<br>";
506 if (this.action != null) {
510 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
515 if (this.srcend != null) {
516 this.img.src = this.srcend;
522 var asta_xarr = new Array(0,66,132);
524 /* TODO: impostare gli onclick */
525 function dispose_asta(idx, pnt, nopoint)
530 for (i = 0 ; i < 10 ; i++) {
533 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
534 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
538 btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
539 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
543 btn.style.left = asta_xarr[i % 3];
545 btn.style.left = asta_xarr[(i+1) % 3];
547 btn.style.top = parseInt(i / 3) * 50 + (i == 9 ? 0 : 1);
550 eval("btn.onclick = function () { act_asta("+pass+",61); }");
551 btn.style.cursor = "pointer";
555 btn.style.cursor = "default";
560 btn = $("astaptdiv");
561 btn.style.left = asta_xarr[i % 3];
562 btn.style.top = parseInt(i / 3) * 50 - 2;
563 // btn.style.visibility = "visible";
566 var rpnt = (pnt < 0 ? -pnt : pnt);
567 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
569 btn = $("astaptsub");
570 btn.style.left = asta_xarr[i % 3];
571 btn.style.top = 25 + parseInt(i / 3) * 50 - 1;
572 btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
573 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
575 btn.onclick = function () { act_asta(9,$("astapt").value); };
576 btn.style.cursor = "pointer";
580 btn.style.cursor = "default";
585 btn = $("astapasso");
586 btn.style.left = asta_xarr[i % 3];
587 btn.style.top = parseInt(i / 3) * 50;
588 btn.src = "img/astapashalf"+(pnt >= 0 ? "" : "_ro")+".png";
589 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
591 btn.onclick = function () { act_asta(-1,0); };
597 btn = $("astalascio");
598 btn.style.left = asta_xarr[i % 3];
599 btn.style.top = parseInt(i / 3) * 50 + 24;
600 btn.src = "img/astalascio.png";
601 btn.style.visibility = "visible";
602 btn.onclick = function () { safelascio(); };
605 btn = $("astapasso");
606 btn.style.left = asta_xarr[i % 3];
607 btn.style.top = parseInt(i / 3) * 50;;
608 btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
609 btn.style.cursor = (pnt >= 0 ? "pointer" : "default");
611 btn.onclick = function () { act_asta(-1,0); };
617 btn = $("astalascio");
618 btn.style.visibility = "hidden";
621 // btn.style.visibility = "visible";
622 $("asta").style.visibility = "visible";
625 function asta_pnt_set(pnt)
628 var rpnt = (pnt < 0 ? -pnt : pnt);
629 btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
634 $("asta").style.visibility = "hidden";
638 function notify(st, text, tout, butt, w, h)
645 this.ancestor = document.body;
647 this.st.st_loc_new++;
649 clo = document.createElement("input");
651 clo.className = "button";
652 clo.style.bottom = "4px";
655 clo.onclick = this.input_hide;
657 clodiv = document.createElement("div");
658 clodiv.className = "notify_clo";
659 clodiv.appendChild(clo);
661 box = document.createElement("div");
662 box.className = "notify";
663 box.innerHTML = text;
664 box.style.zIndex = 200;
665 box.style.width = w+"px";
666 box.style.marginLeft = -parseInt(w/2)+"px";
667 box.style.height = h+"px";
668 box.appendChild(clodiv);
669 box.style.visibility = "visible";
673 this.ancestor.appendChild(box);
675 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
686 if (this.st.st_loc < this.st.st_loc_new) {
693 clearTimeout(this.toutid);
694 this.ancestor.removeChild(this.notitag);
698 input_hide: function()
700 clearTimeout(this.obj.toutid);
701 this.obj.ancestor.removeChild(this.obj.notitag);
708 return document.getElementById(id);
714 this.st_loc_new = -1;
715 this.comms = new Array;
720 function remark_step()
722 var ct = $("remark").l_remct;
728 $("remark").className = "remark"+ct;
729 $("remark").l_remct = ct;
730 setTimeout(remark_step,500);
733 $("remark").className = "remark0";
740 if ($("remark").l_remct == 0) {
741 $("remark").l_remct = 1;
742 setTimeout(remark_step,500);
746 function remark_off()
748 $("remark").l_remct = 0;
749 $("remark").className = "remark0";
753 function choose_seed(card)
757 $("chooseed").style.visibility = "visible";
758 for (i = 0 ; i < 4 ; i++) {
759 $("seed"+i).src = "img/"+i+""+card+".png";
761 eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
765 function set_names(so,ea,ne,nw,we)
768 $("name").innerHTML = so;
769 $("name").title = unescapeHTML(so);
770 $("name_ea").innerHTML = ea;
771 $("name_ea").title = unescapeHTML(ea);
772 $("name_ne").innerHTML = ne;
773 $("name_ne").title = unescapeHTML(ne);
774 $("name_nw").innerHTML = nw;
775 $("name_nw").title = unescapeHTML(nw);
776 $("name_we").innerHTML = we;
777 $("name_we").title = unescapeHTML(we);
782 var astat_suffix = new Array("","_ea","_ne","_nw","_we");
784 function show_astat(zer,uno,due,tre,qua)
786 var astat = new Array(zer,uno,due,tre,qua);
788 for (i = 0 ; i < PLAYERS_N ; i++) {
789 idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
791 if (astat[i] == -2) {
792 $("public"+astat_suffix[idx]).style.visibility = "hidden";
794 else if (astat[i] == -1) {
795 $("public"+astat_suffix[idx]).style.visibility = "visible";
796 $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
797 $("pubapnt"+astat_suffix[idx]).innerHTML = "";
798 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
800 else if (astat[i] <= 10) {
801 $("public"+astat_suffix[idx]).style.visibility = "visible";
802 $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
803 $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
805 else if (astat[i] <= 120) {
806 $("public"+astat_suffix[idx]).style.visibility = "visible";
807 $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
808 $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
809 $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
814 function exitlock_show(num, islock)
818 num = (num < 3 ? num : 3);
819 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
820 // alert("EXITLOCK: "+$("exitlock").src);
821 $("exitlock").style.visibility = "visible";
826 // exitlock_show(0, true);
828 function table_init() {
829 var sux = new Array("", "_ea", "_ne", "_nw", "_we");
831 // console.log("table_init");
834 $("asta").style.visibility = "hidden";
835 $("caller").style.visibility = "hidden";
836 show_astat(-2,-2,-2,-2,-2);
837 for (i=0 ; i < 8 ; i++) {
838 Drag.init($("card" + i), card_mouseup_cb);
839 for (e = 0 ; e < PLAYERS_N ; e++)
840 $("card"+sux[e]+i).style.visibility = "hidden";
842 for (i=0 ; i < PLAYERS_N ; i++) {
843 // console.log("shut: "+"takes"+sux[i]);
844 $("takes"+sux[i]).style.visibility = "hidden";
847 for (i = 0 ; i < 8 ; i++) {
859 var chatt_lines = new Array();
860 var chatt_lines_n = 0;
862 var CHATT_MAXLINES = 40;
865 function chatt_sub(name,str)
867 var must_scroll = false;
869 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
871 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
874 // alert("ARRIVA NAME: "+ name + " STR:"+str);
875 if (chatt_lines_n == CHATT_MAXLINES) {
876 $("txt").innerHTML = "";
877 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
878 chatt_lines[i] = chatt_lines[i+1];
879 $("txt").innerHTML += chatt_lines[i];
881 chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
882 $("txt").innerHTML += chatt_lines[i];
885 chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
886 $("txt").innerHTML += chatt_lines[chatt_lines_n];
889 // $("txt").innerHTML;
893 $("txt").scrollTop = 10000000;
895 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
899 * GESTIONE DEI COOKIES
901 function createCookie(name,value,hours,path) {
903 var date = new Date();
904 date.setTime(date.getTime()+(hours*60*60*1000));
905 var expires = "; expires="+date.toGMTString();
907 else var expires = "";
908 document.cookie = name+"="+value+expires+"; path="+path;
911 function readCookie(name) {
912 var nameEQ = name + "=";
913 var ca = document.cookie.split(';');
914 for(var i=0;i < ca.length;i++) {
916 while (c.charAt(0)==' ') c = c.substring(1,c.length);
917 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
922 function eraseCookie(name) {
923 createCookie(name,"",-1);
926 var onunload_times = 0;
929 function onunload_cb () {
931 if (onunload_times == 0) {
932 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
941 location = self.location;
943 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
953 function room_checkspace(emme,tables,inpe)
956 for (i = 0 ; i < emme ; i++)
961 for (i = 0 ; i < 5 ; i++)
964 for (i = 0 ; i < tables ; i++) {
965 $("table"+i).innerHTML = alta;
966 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
969 stand = "<table class=\"table_standup\"><tbody><tr>";
970 for (i = 0 ; i < inpe ; i++) {
971 stand += "<td>"+nome+"</td>";
972 if ((i+1) % 4 == 0) {
973 stand += "</tr><tr>";
977 $("standup").innerHTML = stand;
979 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"window.onunload = null; act_logout();\" type=\"button\">";
982 function unescapeHTML(cont) {
983 var div = document.createElement('div');
987 div.innerHTML = cont;
988 if (div.childNodes[0]) {
989 if (div.childNodes.length > 1) {
990 if (div.childNodes.toArray)
993 var length = div.childNodes.length, results = new Array(length);
995 results[length] = div.childNodes[length];
997 for (i=0 ; i<results.length ; i++)
998 memo = memo + results[i].nodeValue;
1004 return (div.childNodes[0].nodeValue);
1012 function playsound(tag, sound) {
1013 // g_withflash is a global var
1015 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
1016 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
1017 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
1018 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
1019 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
1020 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';