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.
25 var EXIT_BAN_TIME = 900;
26 var cookiepath = "/trusty";
28 function $(id) { return document.getElementById(id); }
30 function getStyle(x,IEstyleProp, MozStyleProp)
33 var y = x.currentStyle[IEstyleProp];
34 } else if (window.getComputedStyle) {
35 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
40 /* replacement of setInterval on IE */
42 /*if not IE, do nothing*/
43 if(!document.uniqueID){return;};
45 /*Copy the default setInterval behavior*/
46 var nativeSetInterval = window.setInterval;
47 window.setInterval = function(fn,ms) {
49 if(arguments.length <= 2) {
50 return nativeSetInterval(fn,ms);
53 for(var i=2;i<arguments.length;i+=1) {
54 param[i-2] = arguments[i];
58 if(typeof(fn)=='function') {
60 return (function (fn,ms,param) {
61 var fo = function () {
62 fn.apply(window,param);
64 return nativeSetInterval(fo,ms);
67 else if(typeof(fn)=='string')
69 return nativeSetInterval(fn,ms);
73 throw Error('setInterval Error\nInvalid function type');
77 /*Copy the default setTimeout behavior*/
78 var nativeSetTimeout = window.setTimeout;
79 window.setTimeout = function(fn,ms) {
81 if(arguments.length <= 2) {
82 return nativeSetTimeout(fn,ms);
85 for(var i=2;i<arguments.length;i+=1) {
86 param[i-2] = arguments[i];
90 if(typeof(fn)=='function') {
92 return (function (fn,ms,param) {
93 var fo = function () {
94 fn.apply(window,param);
96 return nativeSetTimeout(fo,ms);
99 else if(typeof(fn)=='string')
101 return nativeSetTimeout(fn,ms);
105 throw Error('setTimeout Error\nInvalid function type');
111 function addEvent(obj,type,fn)
113 if (obj.addEventListener) {
114 obj.addEventListener( type, fn, false);
116 else if (obj.attachEvent) {
117 obj["e"+type+fn] = fn;
118 obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
119 obj.attachEvent( "on"+type, obj[type+fn] );
122 throw new Error("Event registration not supported");
125 function removeEvent(obj,type,fn)
127 if (obj.removeEventListener) {
128 obj.removeEventListener( type, fn, false );
130 else if (obj.detachEvent) {
131 obj.detachEvent( "on"+type, obj[type+fn] );
133 obj["e"+type+fn] = null;
137 // var card_pos = RANGE 0 <= x < cards_ea_n
139 function show_bigpict(obj, act, x, y)
143 if (arguments.length > 4)
148 big = $(obj.id+"_big"+sfx);
150 big.style.left = obj.offsetLeft + x+"px";
151 big.style.top = obj.offsetTop + y+"px";
152 big.style.visibility = "visible";
155 big.style.visibility = "hidden";
159 function rnd_int(min, max) {
160 return Math.floor(Math.random() * (max - min + 1) + min);
163 function error_images()
165 // alert("GHESEMU!");
166 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
169 function abort_images()
171 // alert("ABORTAIMAGES");
172 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
175 function unload_images()
177 // alert("ABORTAIMAGES");
178 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
181 function reset_images()
183 // alert("ABORTAIMAGES");
184 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
187 function update_images()
189 // if (g_imgct % 10 == 0) alert("g_imgct: "+g_imgct+" xx "+g_preload_img_arr[g_imgct]);
190 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
191 if (g_imgct+1 < g_preload_img_arr.length) {
193 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
195 // $("imgct").innerHTML += "U";
198 function preload_images(arr,idx)
202 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
203 im.onload = update_images;
204 im.onerror = error_images;
205 im.onabort = abort_images;
206 im.onunload = unload_images;
207 im.onreset = reset_images;
209 // $("imgct").innerHTML += "P";
212 function safestatus(a)
220 function createXMLHttpRequest() {
221 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
222 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
223 try { return new XMLHttpRequest(); } catch(e) {}
224 alert("XMLHttpRequest not supported");
228 function send_mesg(mesg)
230 var xhr_wr = createXMLHttpRequest();
231 var is_conn = (sess == "not_connected" ? false : true);
233 // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn);
234 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, (is_conn ? true : false));
235 xhr_wr.onreadystatechange = function() { return; };
239 if (xhr_wr.responseText != null) {
240 eval(xhr_wr.responseText);
245 function server_request()
247 var xhr_wr = createXMLHttpRequest();
250 if (arguments.length > 0) {
251 for (i = 0 ; i < arguments.length ; i+= 2) {
252 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
255 // alert("Args: "+arguments.length);
257 var is_conn = (sess == "not_connected" ? false : true);
259 // console.log("server_request:preresp: "+xhr_wr.responseText);
261 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
262 xhr_wr.onreadystatechange = function() { return; };
265 if (xhr_wr.responseText != null) {
266 // console.log("server_request:resp: "+xhr_wr.responseText);
267 return (xhr_wr.responseText);
273 /* Stat: CHAT and TABLE */
275 function chatt_checksend(obj,e)
281 if(window.event) { // IE
284 else if(e.which) { // Netscape/Firefox/Opera
287 // alert("OBJ: "+obj);
288 if (keynum == 13 && obj.value != "") { // Enter
289 act_chatt(obj.value);
293 function act_chatt(value)
295 send_mesg("chatt|"+encodeURIComponent(value));
299 obj.disabled = false;
306 function act_sitdown(table)
308 send_mesg("sitdown|"+table);
311 function act_wakeup()
325 act_chatt('/tav '+$('txt_in').value);
326 $('txt_in').value = '';
334 function act_roadmap()
336 send_mesg("roadmap");
339 function act_whysupport()
341 send_mesg("whysupport");
344 function act_lascio()
349 function safelascio()
353 res = window.confirm("Sei sicuro di volere lasciare questa mano?");
358 function act_logout(exitlock)
360 send_mesg("logout|"+exitlock);
363 function act_reloadroom()
365 window.onunload = null;
366 window.onbeforeunload = null;
367 document.location.assign("index.php");
370 function act_shutdown()
374 send_mesg("shutdown");
375 // while (xhr_wr.readyState != 4)
379 function postact_logout()
381 // alert("postact_logout");
386 // eraseCookie("sess");
387 document.location.assign("index.php");
391 function slowimg(img,x1,y1,deltat,free,action,srcend)
393 x1,y1 - destination coords
394 deltat - time for each frame (in msec)
395 free - when the release the local block for other operations (range: 0 - 1)
396 action - function to run when the image is moved
397 srcend - image to switch when the image is moved
400 function sleep(st, delay)
402 // alert("LOC_NEW PRE: "+st.st_loc_new);
406 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
410 function slowimg(img,x1,y1,deltat,free,action,srcend) {
413 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
414 this.x0 = parseInt(getStyle(this.img,"left", "left"));
415 // alert("img.x0 = "+this.x0);
416 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
417 this.y0 = parseInt(getStyle(this.img,"top", "top"));
420 this.deltat = deltat;
422 this.action = action;
423 this.srcend = srcend;
426 slowimg.prototype = {
445 setstart: function(x0,y0)
451 setaction: function(act)
457 settime: function(time)
459 this.time = (time < this.deltat ? this.deltat : time);
460 this.step_n = parseInt(this.time / this.deltat);
461 this.dx = (this.x1 - this.x0) / this.step_n;
462 this.dy = (this.y1 - this.y0) / this.step_n;
463 if (this.step_n * this.deltat == this.time) {
467 this.step_free = parseInt(this.step_n * this.free);
473 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
475 this.st.st_loc_new++;
477 this.img.style.visibility = "visible";
478 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
483 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
484 if (this.step_cur == 0) {
485 var date = new Date();
486 // $("logz").innerHTML = "Timestart: " + date + "<br>";
488 if (this.step_cur <= this.step_n) {
489 this.img.style.left = this.x0 + this.dx * this.step_cur;
490 this.img.style.top = this.y0 + this.dy * this.step_cur;
492 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
493 if (this.step_cur == this.step_free && this.st != null) {
494 if (this.st.st_loc < this.st.st_loc_new) {
495 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
502 this.img.style.left = this.x1;
503 this.img.style.top = this.y1;
504 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
505 var date = new Date();
506 // $("logz").innerHTML += "Timestop: " + date + "<br>";
508 if (this.action != null) {
512 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
517 if (this.srcend != null) {
518 this.img.src = this.srcend;
525 function notify(st, text, tout, butt, w, h)
532 this.ancestor = document.body;
535 this.st.st_loc_new++;
537 clo = document.createElement("input");
539 clo.className = "button";
540 clo.style.bottom = "4px";
543 clo.onclick = this.input_hide;
545 clodiv = document.createElement("div");
546 clodiv.className = "notify_clo";
547 clodiv.appendChild(clo);
549 cont = document.createElement("div");
551 cont.style.borderBottomStyle = "solid";
552 cont.style.borderBottomWidth = "1px";
553 cont.style.borderBottomColor = "gray";
554 cont.style.height = (h - 30)+"px";
555 cont.style.overflow = "auto";
556 cont.innerHTML = text;
558 box = document.createElement("div");
559 box.className = "notify";
560 box.style.zIndex = 200;
561 box.style.width = w+"px";
562 box.style.marginLeft = -parseInt(w/2)+"px";
563 box.style.height = h+"px";
564 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
565 box.appendChild(cont);
566 box.appendChild(clodiv);
567 box.style.visibility = "visible";
571 this.ancestor.appendChild(box);
573 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
589 if (this.st.st_loc < this.st.st_loc_new) {
597 clearTimeout(this.toutid);
598 this.ancestor.removeChild(this.notitag);
602 input_hide: function()
604 clearTimeout(this.obj.toutid);
605 this.obj.ancestor.removeChild(this.obj.notitag);
612 return document.getElementById(id);
618 this.st_loc_new = -1;
619 this.comms = new Array;
624 function remark_step()
626 var ct = $("remark").l_remct;
632 $("remark").className = "remark"+ct;
633 $("remark").l_remct = ct;
634 setTimeout(remark_step,500);
637 $("remark").className = "remark0";
644 if ($("remark").l_remct == 0) {
645 $("remark").l_remct = 1;
646 setTimeout(remark_step,500);
650 function remark_off()
652 $("remark").l_remct = 0;
653 $("remark").className = "remark0";
657 function italizer(ga)
661 return "<i>"+ga[1]+"</i>";
667 function exitlock_show(num, islock)
671 num = (num < 3 ? num : 3);
672 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
673 // alert("EXITLOCK: "+$("exitlock").src);
674 $("exitlock").style.visibility = "visible";
679 // exitlock_show(0, true);
682 var chatt_lines = new Array();
683 var chatt_lines_n = 0;
685 var CHATT_MAXLINES = 40;
688 function chatt_sub(dt,data,str)
690 var must_scroll = false;
697 name = "<i>"+data[1]+"</i>";
700 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
702 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
705 // alert("ARRIVA NAME: "+ name + " STR:"+str);
706 if (chatt_lines_n == CHATT_MAXLINES) {
707 $("txt").innerHTML = "";
708 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
709 chatt_lines[i] = chatt_lines[i+1];
710 $("txt").innerHTML += chatt_lines[i];
712 chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
713 $("txt").innerHTML += chatt_lines[i];
716 chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
717 $("txt").innerHTML += chatt_lines[chatt_lines_n];
720 // $("txt").innerHTML;
724 $("txt").scrollTop = 10000000;
726 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
730 * GESTIONE DEI COOKIES
732 function createCookie(name,value,hours,path) {
734 var date = new Date();
735 date.setTime(date.getTime()+(hours*60*60*1000));
736 var expires = "; expires="+date.toGMTString();
738 else var expires = "";
739 document.cookie = name+"="+value+expires+"; path="+path;
742 function readCookie(name) {
743 var nameEQ = name + "=";
744 var ca = document.cookie.split(';');
745 for(var i=0;i < ca.length;i++) {
747 while (c.charAt(0)==' ') c = c.substring(1,c.length);
748 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
753 function eraseCookie(name) {
754 createCookie(name,"",-1);
757 var onunload_times = 0;
760 function onbeforeunload_cb () {
764 function onunload_cb_old () {
767 // if (nonunload == true)
770 if (onunload_times == 0) {
771 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
780 document.location.href = self.location; // = self.location;
781 // alert ("passiamo di qui"+self.location);
784 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
793 function onunload_cb () {
803 function room_checkspace(emme,tables,inpe)
806 for (i = 0 ; i < emme ; i++)
811 for (i = 0 ; i < 5 ; i++)
814 for (i = 0 ; i < tables ; i++) {
815 $("table"+i).innerHTML = alta;
816 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
819 stand = "<table class=\"table_standup\"><tbody><tr>";
820 for (i = 0 ; i < inpe ; i++) {
821 stand += "<td>"+nome+"</td>";
822 if ((i+1) % 4 == 0) {
823 stand += "</tr><tr>";
827 $("standup").innerHTML = stand;
829 // VERIFY: what is this button ?
830 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"act_logout();\" type=\"button\">";
833 function unescapeHTML(cont) {
834 var div = document.createElement('div');
838 div.innerHTML = cont;
839 if (div.childNodes[0]) {
840 if (div.childNodes.length > 1) {
841 if (div.childNodes.toArray)
844 var length = div.childNodes.length, results = new Array(length);
846 results[length] = div.childNodes[length];
848 for (i=0 ; i<results.length ; i++)
849 memo = memo + results[i].nodeValue;
855 return (div.childNodes[0].nodeValue);
863 function playsound(tag, sound) {
864 // g_withflash is a global var
866 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
867 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
868 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
869 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
870 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
871 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
875 function topbanner_init()
877 setInterval(topbanner_cb, 666);
881 function topbanner_cb()
885 a = $('topbanner').style.backgroundColor;
886 b = $('topbanner').style.borderLeftColor;
888 $('topbanner').style.backgroundColor = b;
889 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
891 // console.log("A: "+a+" B: "+b);
894 function sidebanner_init()
896 setInterval(sidebanner_cb, 666);
900 function sidebanner_cb()
904 a = $('sidebanner').style.backgroundColor;
905 b = $('sidebanner').style.borderLeftColor;
907 $('sidebanner').style.backgroundColor = b;
908 $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
910 // console.log("A: "+a+" B: "+b);
914 function langtolng(lang)
922 function formtext_hilite(obj)
924 obj.className = 'input_text';
925 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
926 addEvent(obj, "blur", function () { this.className = 'input_text'; });
929 function formsub_hilite(obj)
931 obj.className = 'input_sub';
932 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
933 addEvent(obj, "blur", function () { this.className = 'input_sub'; });