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()
167 // alert("GHESEMU!");
168 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
171 function abort_images()
173 // alert("ABORTAIMAGES");
174 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
177 function unload_images()
179 // alert("ABORTAIMAGES");
180 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
183 function reset_images()
185 // alert("ABORTAIMAGES");
186 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
189 function update_images()
191 // if (g_imgct % 10 == 0) alert("g_imgct: "+g_imgct+" xx "+g_preload_img_arr[g_imgct]);
192 $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
193 if (g_imgct+1 < g_preload_img_arr.length) {
195 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
197 // $("imgct").innerHTML += "U";
200 function preload_images(arr,idx)
204 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
205 im.onload = update_images;
206 im.onerror = error_images;
207 im.onabort = abort_images;
208 im.onunload = unload_images;
209 im.onreset = reset_images;
211 // $("imgct").innerHTML += "P";
214 function safestatus(a)
222 function createXMLHttpRequest() {
223 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
224 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
225 try { return new XMLHttpRequest(); } catch(e) {}
226 alert("XMLHttpRequest not supported");
230 function send_mesg(mesg)
232 var xhr_wr = createXMLHttpRequest();
233 var is_conn = (sess == "not_connected" ? false : true);
235 // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn);
236 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, (is_conn ? true : false));
237 xhr_wr.onreadystatechange = function() { return; };
241 if (xhr_wr.responseText != null) {
242 eval(xhr_wr.responseText);
247 function server_request()
249 var xhr_wr = createXMLHttpRequest();
252 if (arguments.length > 0) {
253 for (i = 0 ; i < arguments.length ; i+= 2) {
254 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
257 // alert("Args: "+arguments.length);
259 var is_conn = (sess == "not_connected" ? false : true);
261 // console.log("server_request:preresp: "+xhr_wr.responseText);
263 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
264 xhr_wr.onreadystatechange = function() { return; };
267 if (xhr_wr.responseText != null) {
268 // console.log("server_request:resp: "+xhr_wr.responseText);
269 return (xhr_wr.responseText);
275 /* Stat: CHAT and TABLE */
277 function chatt_checksend(obj,e)
283 if(window.event) { // IE
286 else if(e.which) { // Netscape/Firefox/Opera
289 // alert("OBJ: "+obj);
290 if (keynum == 13 && obj.value != "") { // Enter
291 act_chatt(obj.value);
295 function act_chatt(value)
297 send_mesg("chatt|"+encodeURIComponent(value));
301 obj.disabled = false;
308 function act_sitdown(table)
310 send_mesg("sitdown|"+table);
313 function act_wakeup()
327 act_chatt('/tav '+$('txt_in').value);
328 $('txt_in').value = '';
336 function act_roadmap()
338 send_mesg("roadmap");
341 function act_whysupport()
343 send_mesg("whysupport");
346 function act_lascio()
351 function safelascio()
355 res = window.confirm("Sei sicuro di volere lasciare questa mano?");
360 function act_logout(exitlock)
362 send_mesg("logout|"+exitlock);
365 function act_reloadroom()
367 window.onunload = null;
368 window.onbeforeunload = null;
369 document.location.assign("index.php");
372 function act_shutdown()
376 send_mesg("shutdown");
377 // while (xhr_wr.readyState != 4)
381 function postact_logout()
383 // alert("postact_logout");
388 // eraseCookie("sess");
389 document.location.assign("index.php");
393 function slowimg(img,x1,y1,deltat,free,action,srcend)
395 x1,y1 - destination coords
396 deltat - time for each frame (in msec)
397 free - when the release the local block for other operations (range: 0 - 1)
398 action - function to run when the image is moved
399 srcend - image to switch when the image is moved
402 function sleep(st, delay)
404 // alert("LOC_NEW PRE: "+st.st_loc_new);
408 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
412 function slowimg(img,x1,y1,deltat,free,action,srcend) {
415 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
416 this.x0 = parseInt(getStyle(this.img,"left", "left"));
417 // alert("img.x0 = "+this.x0);
418 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
419 this.y0 = parseInt(getStyle(this.img,"top", "top"));
422 this.deltat = deltat;
424 this.action = action;
425 this.srcend = srcend;
428 slowimg.prototype = {
447 setstart: function(x0,y0)
453 setaction: function(act)
459 settime: function(time)
461 this.time = (time < this.deltat ? this.deltat : time);
462 this.step_n = parseInt(this.time / this.deltat);
463 this.dx = (this.x1 - this.x0) / this.step_n;
464 this.dy = (this.y1 - this.y0) / this.step_n;
465 if (this.step_n * this.deltat == this.time) {
469 this.step_free = parseInt(this.step_n * this.free);
475 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
477 this.st.st_loc_new++;
479 this.img.style.visibility = "visible";
480 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
485 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
486 if (this.step_cur == 0) {
487 var date = new Date();
488 // $("logz").innerHTML = "Timestart: " + date + "<br>";
490 if (this.step_cur <= this.step_n) {
491 this.img.style.left = this.x0 + this.dx * this.step_cur;
492 this.img.style.top = this.y0 + this.dy * this.step_cur;
494 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
495 if (this.step_cur == this.step_free && this.st != null) {
496 if (this.st.st_loc < this.st.st_loc_new) {
497 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
504 this.img.style.left = this.x1;
505 this.img.style.top = this.y1;
506 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
507 var date = new Date();
508 // $("logz").innerHTML += "Timestop: " + date + "<br>";
510 if (this.action != null) {
514 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
519 if (this.srcend != null) {
520 this.img.src = this.srcend;
527 function notify(st, text, tout, butt, w, h)
534 this.ancestor = document.body;
536 this.st.st_loc_new++;
538 clo = document.createElement("input");
540 clo.className = "button";
541 clo.style.bottom = "4px";
544 clo.onclick = this.input_hide;
546 clodiv = document.createElement("div");
547 clodiv.className = "notify_clo";
548 clodiv.appendChild(clo);
550 cont = document.createElement("div");
552 cont.style.borderBottomStyle = "solid";
553 cont.style.borderBottomWidth = "1px";
554 cont.style.borderBottomColor = "gray";
555 cont.style.height = (h - 30)+"px";
556 cont.style.overflow = "auto";
557 cont.innerHTML = text;
559 box = document.createElement("div");
560 box.className = "notify";
561 box.style.zIndex = 200;
562 box.style.width = w+"px";
563 box.style.marginLeft = -parseInt(w/2)+"px";
564 box.style.height = h+"px";
565 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
566 box.appendChild(cont);
567 box.appendChild(clodiv);
568 box.style.visibility = "visible";
572 this.ancestor.appendChild(box);
574 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
589 if (this.st.st_loc < this.st.st_loc_new) {
596 clearTimeout(this.toutid);
597 this.ancestor.removeChild(this.notitag);
601 input_hide: function()
603 clearTimeout(this.obj.toutid);
604 this.obj.ancestor.removeChild(this.obj.notitag);
611 return document.getElementById(id);
617 this.st_loc_new = -1;
618 this.comms = new Array;
623 function remark_step()
625 var ct = $("remark").l_remct;
631 $("remark").className = "remark"+ct;
632 $("remark").l_remct = ct;
633 setTimeout(remark_step,500);
636 $("remark").className = "remark0";
643 if ($("remark").l_remct == 0) {
644 $("remark").l_remct = 1;
645 setTimeout(remark_step,500);
649 function remark_off()
651 $("remark").l_remct = 0;
652 $("remark").className = "remark0";
656 function italizer(ga)
660 return "<i>"+ga[1]+"</i>";
666 function exitlock_show(num, islock)
670 num = (num < 3 ? num : 3);
671 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
672 // alert("EXITLOCK: "+$("exitlock").src);
673 $("exitlock").style.visibility = "visible";
678 // exitlock_show(0, true);
681 var chatt_lines = new Array();
682 var chatt_lines_n = 0;
684 var CHATT_MAXLINES = 40;
687 function chatt_sub(dt,data,str)
689 var must_scroll = false;
696 name = "<i>"+data[1]+"</i>";
699 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
701 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
704 // alert("ARRIVA NAME: "+ name + " STR:"+str);
705 if (chatt_lines_n == CHATT_MAXLINES) {
706 $("txt").innerHTML = "";
707 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
708 chatt_lines[i] = chatt_lines[i+1];
709 $("txt").innerHTML += chatt_lines[i];
711 chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
712 $("txt").innerHTML += chatt_lines[i];
715 chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
716 $("txt").innerHTML += chatt_lines[chatt_lines_n];
719 // $("txt").innerHTML;
723 $("txt").scrollTop = 10000000;
725 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
729 * GESTIONE DEI COOKIES
731 function createCookie(name,value,hours,path) {
733 var date = new Date();
734 date.setTime(date.getTime()+(hours*60*60*1000));
735 var expires = "; expires="+date.toGMTString();
737 else var expires = "";
738 document.cookie = name+"="+value+expires+"; path="+path;
741 function readCookie(name) {
742 var nameEQ = name + "=";
743 var ca = document.cookie.split(';');
744 for(var i=0;i < ca.length;i++) {
746 while (c.charAt(0)==' ') c = c.substring(1,c.length);
747 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
752 function eraseCookie(name) {
753 createCookie(name,"",-1);
756 var onunload_times = 0;
759 function onbeforeunload_cb () {
763 function onunload_cb_old () {
766 // if (nonunload == true)
769 if (onunload_times == 0) {
770 var res = window.confirm(" Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
779 document.location.href = self.location; // = self.location;
780 // alert ("passiamo di qui"+self.location);
783 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
792 function onunload_cb () {
802 function room_checkspace(emme,tables,inpe)
805 for (i = 0 ; i < emme ; i++)
810 for (i = 0 ; i < 5 ; i++)
813 for (i = 0 ; i < tables ; i++) {
814 $("table"+i).innerHTML = alta;
815 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
818 stand = "<table class=\"table_standup\"><tbody><tr>";
819 for (i = 0 ; i < inpe ; i++) {
820 stand += "<td>"+nome+"</td>";
821 if ((i+1) % 4 == 0) {
822 stand += "</tr><tr>";
826 $("standup").innerHTML = stand;
828 // VERIFY: what is this button ?
829 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"act_logout();\" type=\"button\">";
832 function unescapeHTML(cont) {
833 var div = document.createElement('div');
837 div.innerHTML = cont;
838 if (div.childNodes[0]) {
839 if (div.childNodes.length > 1) {
840 if (div.childNodes.toArray)
843 var length = div.childNodes.length, results = new Array(length);
845 results[length] = div.childNodes[length];
847 for (i=0 ; i<results.length ; i++)
848 memo = memo + results[i].nodeValue;
854 return (div.childNodes[0].nodeValue);
862 function playsound(tag, sound) {
863 // g_withflash is a global var
865 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
866 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
867 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
868 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
869 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
870 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
874 function topbanner_init()
876 setInterval(topbanner_cb, 666);
880 function topbanner_cb()
884 a = $('topbanner').style.backgroundColor;
885 b = $('topbanner').style.borderLeftColor;
887 $('topbanner').style.backgroundColor = b;
888 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
890 // console.log("A: "+a+" B: "+b);
893 function sidebanner_init()
895 setInterval(sidebanner_cb, 666);
899 function sidebanner_cb()
903 a = $('sidebanner').style.backgroundColor;
904 b = $('sidebanner').style.borderLeftColor;
906 $('sidebanner').style.backgroundColor = b;
907 $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
909 // console.log("A: "+a+" B: "+b);
913 function langtolng(lang)
921 function formtext_hilite(obj)
923 obj.className = 'input_text';
924 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
925 addEvent(obj, "blur", function () { this.className = 'input_text'; });
928 function formsub_hilite(obj)
930 obj.className = 'input_sub';
931 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
932 addEvent(obj, "blur", function () { this.className = 'input_sub'; });