4 * Copyright (C) 2006-2015 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 = "/brisk/";
28 var mlang_commons = { 'imgload_a' : { 'it' : 'Immagini caricate ',
29 'en' : 'Loaded images ' },
30 'imgload_b' : { 'it' : '%.',
32 'gamleav' : { 'it' : 'Sei sicuro di volere lasciare questa mano?' ,
33 'en' : 'Are you sure to leave this game?' },
34 'brileav' : { 'it' : ' Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)',
35 'en' : ' Are you really sure to leave briscola ?\n(click cancel yo reload it)' },
36 'brireco' : { 'it' : 'Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.',
37 'en' : 'Recovery of briscola failed, to keep the current session reload the page manually.' },
38 'btn_sit' : { 'it' : 'Mi siedo.',
40 'btn_exit' : { 'it' : 'Esco.',
42 'tit_list' : { '0' : { 'it' : '',
44 '1' : { 'it' : '(solo aut.)',
45 'en' : '(only aut.)' },
46 '2' : { 'it' : '(isolam.to)',
47 'en' : '(isolation)' } },
48 'tos_refu' : { 'it' : 'Rifiutando di sottoscrivere i nuovi termini del servizio non ti sarà più possibile accedere come utente registrato al sito, sei proprio sicuro di voler rifiutare le nuove condizioni d\'uso ?',
49 'en' : 'EN Rifiutando di sottoscrivere i nuovi termini del servizio non ti sarà più possibile accedere come utente registrato al sito, sei proprio sicuro di voler rifiutare le nuove condizioni d\'uso ?'
53 function $(id) { return document.getElementById(id); }
55 function dec2hex(d, padding)
57 var hex = Number(d).toString(16);
58 padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
60 while (hex.length < padding) {
67 function getStyle(x,IEstyleProp, MozStyleProp)
70 var y = x.currentStyle[IEstyleProp];
71 } else if (window.getComputedStyle) {
72 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
77 /* replacement of setInterval on IE */
79 /*if not IE, do nothing*/
80 if(!document.uniqueID){return;};
82 /*Copy the default setInterval behavior*/
83 var nativeSetInterval = window.setInterval;
84 window.setInterval = function(fn,ms) {
86 if(arguments.length <= 2) {
87 return nativeSetInterval(fn,ms);
90 for(var i=2;i<arguments.length;i+=1) {
91 param[i-2] = arguments[i];
95 if(typeof(fn)=='function') {
97 return (function (fn,ms,param) {
98 var fo = function () {
99 fn.apply(window,param);
101 return nativeSetInterval(fo,ms);
104 else if(typeof(fn)=='string')
106 return nativeSetInterval(fn,ms);
110 throw Error('setInterval Error\nInvalid function type');
114 /*Copy the default setTimeout behavior*/
115 var nativeSetTimeout = window.setTimeout;
116 window.setTimeout = function(fn,ms) {
118 if(arguments.length <= 2) {
119 return nativeSetTimeout(fn,ms);
122 for(var i=2;i<arguments.length;i+=1) {
123 param[i-2] = arguments[i];
127 if(typeof(fn)=='function') {
129 return (function (fn,ms,param) {
130 var fo = function () {
131 fn.apply(window,param);
133 return nativeSetTimeout(fo,ms);
136 else if(typeof(fn)=='string')
138 return nativeSetTimeout(fn,ms);
142 throw Error('setTimeout Error\nInvalid function type');
148 function addEvent(obj, type, fn)
150 if (obj.addEventListener) {
151 obj.addEventListener( type, fn, false);
153 else if (obj.attachEvent) {
154 obj["e"+type+fn] = fn;
155 obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
156 obj.attachEvent( "on"+type, obj[type+fn] );
159 throw new Error("Event registration not supported");
162 function removeEvent(obj,type,fn)
164 if (obj.removeEventListener) {
165 obj.removeEventListener( type, fn, false );
167 else if (obj.detachEvent) {
168 obj.detachEvent( "on"+type, obj[type+fn] );
170 obj["e"+type+fn] = null;
174 // var card_pos = RANGE 0 <= x < cards_ea_n
176 function show_bigpict(obj, act, x, y)
180 if (arguments.length > 4)
185 big = $(obj.id+"_big"+sfx);
187 big.style.left = obj.offsetLeft + x+"px";
188 big.style.top = obj.offsetTop + y+"px";
189 big.style.visibility = "visible";
192 big.style.visibility = "hidden";
196 function rnd_int(min, max) {
197 return Math.floor(Math.random() * (max - min + 1) + min);
200 function error_images()
202 // alert("GHESEMU!");
203 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
206 function abort_images()
208 // alert("ABORTAIMAGES");
209 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
212 function unload_images()
214 // alert("ABORTAIMAGES");
215 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
218 function reset_images()
220 // alert("ABORTAIMAGES");
221 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
224 function update_images()
226 // MLANG "Immagine caricate" + g_preload_imgsz_arr[g_imgct] + "%."
227 $("imgct").innerHTML = mlang_commons['imgload_a'][g_lang]+g_preload_imgsz_arr[g_imgct]+"%.";
228 if (g_imgct+1 < g_preload_img_arr.length) {
230 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
232 // $("imgct").innerHTML += "U";
235 function preload_images(arr,idx)
239 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
240 im.onload = update_images;
241 im.onerror = error_images;
242 im.onabort = abort_images;
243 im.onunload = unload_images;
244 im.onreset = reset_images;
246 // $("imgct").innerHTML += "P";
249 function safestatus(a)
257 function createXMLHttpRequest() {
258 if (typeof(ActiveXObject) != 'undefined') { // Konqueror complain as unknown object
259 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
260 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
262 try { return new XMLHttpRequest(); } catch(e) {}
263 alert("XMLHttpRequest not supported");
267 function send_mesg(mesg, content)
269 var is_conn = (sess == "not_connected" ? false : true);
271 if (is_conn && xstm && xstm.transp_type.startsWith('websocket')) {
272 if (typeof(content) != 'undefined') {
273 mesg = mesg + content;
275 var target = window.location.href.substring(0,
276 window.location.href.lastIndexOf('/') + 1) + 'index_wr.php';
277 var ws_msg = JSON.stringify({
282 table_idx: readCookie("table_idx"),
283 table_token: readCookie("table_token"),
284 lang: readCookie("lang")
286 // console.log(ws_msg);
287 xstm.transp.ws.send(ws_msg);
290 var xhr_wr = createXMLHttpRequest();
292 if (typeof(content) != 'undefined') {
293 mesg = mesg + encodeURIComponent(content);
295 // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn);
296 xhr_wr.open('GET', 'index_wr.php?&'+(is_conn ? 'sess='+sess : '')+'&stp='+gst.st+'&mesg='+mesg, (is_conn ? true : false));
297 xhr_wr.setRequestHeader("If-Modified-Since", new Date().toUTCString());
298 xhr_wr.onreadystatechange = function() { return; };
299 if (typeof(g_debug) == 'number' && g_debug > 0
300 && typeof(console) == 'object' && typeof(console.log) == 'function') {
301 var ldate = new Date();
302 console.log(ldate.getTime()+':MESG:'+mesg);
307 if (xhr_wr.responseText != null) {
308 eval(xhr_wr.responseText);
315 sync request to server
316 server_request([arg0=arg1[, arg2=arg3[, ...]]])
317 if var name == '__POST__' than all other vars will be managed as POST content
318 and the call will be a POST
320 function server_request()
322 var xhr_wr = createXMLHttpRequest();
323 var i, collect = "", post_collect = null, is_post = false;
325 if (arguments.length > 0) {
326 for (i = 0 ; i < arguments.length ; i+= 2) {
327 if (arguments[i] == "__POST__") {
334 post_collect += (post_collect == "" ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
336 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
339 // alert("Args: "+arguments.length);
341 var is_conn = (sess == "not_connected" ? false : true);
343 // console.log("server_request:preresp: "+xhr_wr.responseText);
346 xhr_wr.open('POST', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
347 xhr_wr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
350 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
352 xhr_wr.onreadystatechange = function() { return; };
353 xhr_wr.send(post_collect);
355 if (xhr_wr.responseText != null) {
356 // console.log("server_request:resp: "+xhr_wr.responseText);
357 return (xhr_wr.responseText);
363 /* Stat: CHAT and TABLE */
365 function chatt_checksend(obj,e)
371 if(window.event) { // IE
374 else if(e.which) { // Netscape/Firefox/Opera
377 // alert("OBJ: "+obj);
378 if (keynum == 13 && obj.value != "") { // Enter
379 act_chatt(obj.value);
383 function act_chatt(value)
385 if (value.substring(0, 6) == "/info ") {
386 info_show(value.substring(6));
389 send_mesg("chatt|", value);
394 obj.disabled = false;
406 function act_sitdown(table)
408 send_mesg("sitdown|"+table);
411 function act_wakeup()
416 function act_splash()
426 function act_passwdhowto()
428 send_mesg("passwdhowto");
431 function act_mesgtoadm()
433 send_mesg("mesgtoadm");
438 act_chatt('/tav '+$('txt_in').value);
439 $('txt_in').value = '';
447 function act_placing()
449 send_mesg("placing");
452 function act_roadmap()
454 send_mesg("roadmap");
457 function act_lascio()
462 function safelascio()
465 // MLANG "Sei sicuro di volere lasciare questa mano?"
466 res = window.confirm(mlang_commons['gamleav'][g_lang]);
471 function act_logout(exitlock)
473 send_mesg("logout|"+exitlock);
476 function act_reloadroom()
478 window.onunload = null;
479 window.onbeforeunload = null;
480 document.location.assign("index.php");
483 function act_shutdown()
487 send_mesg("shutdown");
488 // while (xhr_wr.readyState != 4)
492 function postact_logout()
494 // alert("postact_logout");
499 // eraseCookie("sess");
500 document.location.assign("index.php");
504 type - 'hard' or 'soft'
505 code - if soft: accept (0), refuse (1), download (2), later (3)
506 if hard: accept (0), refuse (1), download (2)
508 function act_tosmgr(type, code, tos_curr, tos_vers)
510 if (type != "soft" && type != "hard") {
516 send_mesg("tosmgr|"+type+"|"+code+"|"+tos_curr+"|"+tos_vers);
527 function tos_confirm(val, url)
533 return (window.confirm(mlang_commons['tos_refu'][g_lang]));
536 dlm = new download_mgr(url);
546 function slowimg(img,x1,y1,deltat,free,action,srcend)
548 x1,y1 - destination coords
549 deltat - time for each frame (in msec)
550 free - when the release the local block for other operations (range: 0 - 1)
551 action - function to run when the image is moved
552 srcend - image to switch when the image is moved
555 function sleep(st, delay)
557 // alert("LOC_NEW PRE: "+st.st_loc_new);
561 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
565 function slowimg(img,x1,y1,deltat,free,action,srcend) {
568 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
569 this.x0 = parseInt(getStyle(this.img,"left", "left"));
570 // alert("img.x0 = "+this.x0);
571 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
572 this.y0 = parseInt(getStyle(this.img,"top", "top"));
575 this.deltat = deltat;
577 this.action = action;
578 this.srcend = srcend;
581 slowimg.prototype = {
600 setstart: function(x0,y0)
606 setaction: function(act)
612 settime: function(time)
614 this.time = (time < this.deltat ? this.deltat : time);
615 this.step_n = parseInt(this.time / this.deltat);
616 this.dx = (this.x1 - this.x0) / this.step_n;
617 this.dy = (this.y1 - this.y0) / this.step_n;
618 if (this.step_n * this.deltat == this.time) {
622 this.step_free = parseInt(this.step_n * this.free);
628 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
630 this.st.st_loc_new++;
632 this.img.style.visibility = "visible";
633 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
638 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
639 if (this.step_cur == 0) {
640 var date = new Date();
641 // $("logz").innerHTML = "Timestart: " + date + "<br>";
643 if (this.step_cur <= this.step_n) {
644 this.img.style.left = this.x0 + this.dx * this.step_cur;
645 this.img.style.top = this.y0 + this.dy * this.step_cur;
647 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
648 if (this.step_cur == this.step_free && this.st != null) {
649 if (this.st.st_loc < this.st.st_loc_new) {
650 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
657 this.img.style.left = this.x1;
658 this.img.style.top = this.y1;
659 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
660 var date = new Date();
661 // $("logz").innerHTML += "Timestop: " + date + "<br>";
663 if (this.action != null) {
667 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
672 if (this.srcend != null) {
673 this.img.src = this.srcend;
679 function div_show(div)
681 div.style.top = parseInt((document.body.clientHeight - parseInt(getStyle(div,"height", "height"))) / 2) + document.body.scrollTop;
682 div.style.visibility = "visible";
688 tout: if < 0 => infinite
696 function notify_document(st, text, tout, butt, confirm_func, confirm_func_args, w, h, is_opa, block_time)
698 var i, clo, clodiv_ctx, clodiv_wai, box;
702 this.ancestor = document.body;
703 this.confirm_func = confirm_func;
704 this.confirm_func_args = confirm_func_args;
705 this.st.st_loc_new++;
707 clodiv_ctx = document.createElement("div");
708 clodiv_ctx.className = "notify_clo";
710 for (i = 0 ; i < butt.length ; i++) {
711 this.input_add(butt[i], i, this.hide, clodiv_ctx);
714 if (block_time > 0) {
715 clodiv_wai = document.createElement("div");
716 clodiv_wai.className = "notify_clo";
718 this.input_add("leggere, prego.", 0, null, clodiv_wai);
719 this.clodiv = clodiv_wai;
720 this.clodiv_pkg = clodiv_ctx;
721 clodiv_ctx.style.display = 'none';
724 this.clodiv = clodiv_ctx;
727 cont = document.createElement("div");
729 cont.style.borderBottomStyle = "solid";
730 cont.style.borderBottomWidth = "1px";
731 cont.style.borderBottomColor = "gray";
732 cont.style.height = (h - 50)+"px";
733 cont.style.overflow = "auto";
734 cont.style.textAlign = "left";
735 cont.style.padding = "8px";
736 cont.style.fontFamily = "monospace";
737 cont.innerHTML = text;
739 box = document.createElement("div");
741 box.className = "notify_opaque";
743 box.className = "notify";
745 box.style.zIndex = 200;
746 box.style.width = w+"px";
747 box.style.marginLeft = -parseInt(w/2)+"px";
748 box.style.height = h+"px";
749 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
750 box.appendChild(cont);
751 box.appendChild(this.clodiv);
752 box.style.visibility = "visible";
756 this.ancestor.appendChild(box);
759 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
762 if (block_time != 0) {
763 this.tblkid = setTimeout(function(obj){ obj.notitag.removeChild(obj.clodiv); obj.clodiv = obj.clodiv_pkg; obj.clodiv.style.display = ''; obj.notitag.appendChild(obj.clodiv); }, block_time, this);
767 notify_document.prototype = {
781 confirm_func_args: [],
788 onclick_cb: name of the onclick callback (with signature f(idx) ) or null
789 anc: parent dom object
791 return new button dom object
793 input_add: function(s, idx, onclick_cb, anc)
797 clo = document.createElement("input");
799 clo.className = "button";
800 clo.style.bottom = "4px";
801 clo.style.margin = "2px";
806 clo.onclick = function () { onclick_cb.call(this.obj, this.obj_idx); };
809 anc.appendChild(clo);
816 // alert("quiz: "+this.rett);
822 if (this.st.st_loc < this.st.st_loc_new) {
829 if (this.confirm_func != null) {
832 args = [ val ].concat(this.confirm_func_args);
834 if (this.confirm_func.apply(null, args) == false) {
839 clearTimeout(this.toutid);
840 this.ancestor.removeChild(this.notitag);
848 function notify_ex(st, text, tout, butt, w, h, is_opa, block_time)
855 this.ancestor = document.body;
857 this.st.st_loc_new++;
859 clo = document.createElement("input");
861 clo.className = "button";
862 clo.style.bottom = "4px";
864 if (block_time > 0) {
865 clo.value = "leggere, prego.";
870 clo.onclick = function () { this.obj.hide() };
873 clodiv = document.createElement("div");
874 clodiv.className = "notify_clo";
876 this.clodiv = clodiv;
878 clodiv.appendChild(clo);
880 cont = document.createElement("div");
882 cont.style.borderBottomStyle = "solid";
883 cont.style.borderBottomWidth = "1px";
884 cont.style.borderBottomColor = "gray";
885 cont.style.height = (h - 30)+"px";
886 cont.style.overflow = "auto";
887 cont.innerHTML = text;
889 box = document.createElement("div");
891 box.className = "notify_opaque";
893 box.className = "notify";
895 box.style.zIndex = 200;
896 box.style.width = w+"px";
897 box.style.marginLeft = -parseInt(w/2)+"px";
898 box.style.height = h+"px";
899 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
900 box.appendChild(cont);
901 box.appendChild(clodiv);
902 box.style.visibility = "visible";
906 this.ancestor.appendChild(box);
908 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
910 if (block_time != 0) {
911 this.tblkid = setTimeout(function(obj){ obj.clo.value = obj.butt; obj.clo.onclick = function () { this.obj.hide() }; formsub_hilite(obj.clo); obj.clo.focus(); }, block_time, this);
921 notify_ex.prototype = {
933 if (this.st.st_loc < this.st.st_loc_new) {
940 clearTimeout(this.toutid);
941 this.ancestor.removeChild(this.notitag);
947 notify.prototype = notify_ex.prototype; // Define sub-class
948 notify.prototype.constructor = notify;
949 notify.baseConstructor = notify_ex;
950 notify.superClass = notify_ex.prototype;
952 function notify(st, text, tout, butt, w, h)
954 notify_ex.call(this, st, text, tout, butt, w, h, false, 0);
960 this.st_loc_new = -1;
961 this.comms = new Array;
971 sleep: function(delay) {
975 this.sleep_hdl = setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; obj.sleep_hdl = null; }},
981 if (this.sleep_hdl != null) {
982 clearTimeout(this.sleep_hdl);
983 this.sleep_hdl = null;
988 function remark_step()
990 var ct = $("remark").l_remct;
996 $("remark").className = "remark"+ct;
997 $("remark").l_remct = ct;
998 setTimeout(remark_step,500);
1001 $("remark").className = "remark0";
1006 function remark_on()
1008 if ($("remark").l_remct == 0) {
1009 $("remark").l_remct = 1;
1010 setTimeout(remark_step,500);
1014 function remark_off()
1016 $("remark").l_remct = 0;
1017 $("remark").className = "remark0";
1021 function italizer(ga)
1025 return "<i>"+ga[1]+"</i>";
1031 function exitlock_show(num, islock)
1035 num = (num < 3 ? num : 3);
1036 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
1037 // alert("EXITLOCK: "+$("exitlock").src);
1038 $("exitlock").style.visibility = "visible";
1043 // exitlock_show(0, true);
1046 var chatt_lines = new Array();
1047 var chatt_lines_n = 0;
1049 var CHATT_MAXLINES = 40;
1051 function user_decorator(user, is_real)
1053 var name, i, sp = "", cl = "";
1054 var flags = user[0] & 0x03 | ((user[0] & 0x0c0000) >> 16);
1056 // console.log(user[1]+" FLAGS: "+flags);
1058 for (i = 0 ; i < 4 ; i++) {
1059 if (flags & (1 << i)) {
1060 cl += sp + "au" + i + (is_real ? "" : "_off");
1066 name = "<span class='" + cl + "'><span class='" +
1067 (is_real && (flags & 0xfffffe && ((flags & 0x01) == 0)) ? "id_usr" : "") +
1068 "'>" + user[1] + "</span></span>";
1077 function user_dec_and_state(el)
1082 content = user_decorator(el, true);
1083 content += state_add(el[0],(typeof(el[2]) != 'undefined' ? el[2] : null));
1090 function chatt_sub(dt,data,str)
1092 var must_scroll = false;
1096 var bolder = [ (data[0] | 1), data[1] ];
1097 name = user_decorator(bolder, false);
1099 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
1102 // alert("ARRIVA NAME: "+ name + " STR:"+str);
1103 if (chatt_lines_n == CHATT_MAXLINES) {
1104 $("txt").innerHTML = "";
1105 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
1106 chatt_lines[i] = chatt_lines[i+1];
1107 $("txt").innerHTML += chatt_lines[i];
1109 chatt_lines[i] = dt+name+": "+str+ "<br>";
1110 $("txt").innerHTML += chatt_lines[i];
1113 chatt_lines[chatt_lines_n] = dt+name+": "+str+ "<br>";
1114 $("txt").innerHTML += chatt_lines[chatt_lines_n];
1117 // $("txt").innerHTML;
1121 $("txt").scrollTop = 10000000;
1123 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
1127 * GESTIONE DEI COOKIES
1129 function createCookie(name,value,hours,path) {
1131 var date = new Date();
1132 date.setTime(date.getTime()+(hours*60*60*1000));
1133 var expires = "; expires="+date.toGMTString();
1135 else var expires = "";
1136 document.cookie = name+"="+value+expires+"; path="+path;
1139 function readCookie(name) {
1140 var nameEQ = name + "=";
1141 var ca = document.cookie.split(';');
1142 for(var i=0;i < ca.length;i++) {
1144 while (c.charAt(0)==' ')
1145 c = c.substring(1,c.length);
1146 if (c.indexOf(nameEQ) == 0)
1147 return c.substring(nameEQ.length,c.length);
1152 function eraseCookie(name) {
1153 createCookie(name,"",-1);
1156 function onbeforeunload_cb () {
1160 function onunload_cb () {
1162 if (typeof(xstm) != "undefined")
1163 xstm.the_end = true;
1170 function room_checkspace(emme,tables,inpe)
1173 for (i = 0 ; i < emme ; i++)
1178 for (i = 0 ; i < 5 ; i++)
1179 alta += nome+"<br>";
1181 for (i = 0 ; i < tables ; i++) {
1182 $("table"+i).innerHTML = alta;
1184 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
1187 stand = "<table class=\"table_standup\"><tbody><tr>";
1188 for (i = 0 ; i < inpe ; i++) {
1189 stand += "<td>"+nome+"</td>";
1190 if ((i+1) % 4 == 0) {
1191 stand += "</tr><tr>";
1195 $("standup").innerHTML = stand;
1197 // VERIFY: what is this button ?
1199 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
1202 function unescapeHTML(cont) {
1203 var div = document.createElement('div');
1207 div.innerHTML = cont;
1208 if (div.childNodes[0]) {
1209 if (div.childNodes.length > 1) {
1210 if (div.childNodes.toArray)
1213 var length = div.childNodes.length, results = new Array(length);
1215 results[length] = div.childNodes[length];
1217 for (i=0 ; i<results.length ; i++)
1218 memo = memo + results[i].nodeValue;
1224 return (div.childNodes[0].nodeValue);
1233 samples = [{'name': <name>, 'file': <file>}, ... ]
1235 function jukebox(samples)
1238 this.enable = false;
1241 var pro_audio_el = document.createElement('audio');
1242 this.enable = !!(pro_audio_el.canPlayType && pro_audio_el.canPlayType('audio/mpeg;').replace(/no/, ''));
1244 for (i in samples) {
1245 sample = samples[i];
1247 this.audio[sample['name']] = a = document.createElement('audio');
1249 source = document.createElement('source');
1250 source.setAttribute('src', sample['file']);
1251 source.setAttribute('type', 'audio/mpeg');
1252 a.appendChild(source);
1258 jukebox.prototype = {
1259 is_enabled: function() {
1263 play: function(name) {
1268 if (!(name in this.audio)) {
1271 a = this.audio[name];
1277 function topbanner_init()
1279 setInterval(topbanner_cb, 666);
1283 function topbanner_cb()
1287 a = $('topbanner').style.backgroundColor;
1288 b = $('topbanner').style.borderLeftColor;
1290 $('topbanner').style.backgroundColor = b;
1291 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
1293 // console.log("A: "+a+" B: "+b);
1296 function sidebanner_init(idx)
1298 setInterval(function () { sidebanner_cb(idx); }, 666);
1301 function sidebanner_cb(idx)
1305 a = $('sidebanner'+idx).style.backgroundColor;
1306 b = $('sidebanner'+idx).style.borderLeftColor;
1308 $('sidebanner'+idx).style.backgroundColor = b;
1309 $('sidebanner'+idx).style.borderColor = a+" "+a+" "+a+" "+a;
1311 // console.log("A: "+a+" B: "+b);
1315 function langtolng(lang)
1323 function formtext_hilite(obj)
1325 obj.className = 'input_text';
1326 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
1327 addEvent(obj, "blur", function () { this.className = 'input_text'; });
1330 function formsub_hilite(obj)
1332 obj.className = 'input_sub';
1333 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1334 addEvent(obj, "blur", function () { this.className = 'input_sub'; });
1337 // return the value of the radio button that is checked
1338 // return an empty string if none are checked, or
1339 // there are no radio buttons
1340 function get_checked_value(radioObj) {
1343 var radioLength = radioObj.length;
1344 if(radioLength == undefined)
1345 if(radioObj.checked)
1346 return radioObj.value;
1349 for(var i = 0; i < radioLength; i++) {
1350 if(radioObj[i].checked) {
1351 return radioObj[i].value;
1357 // set the radio button with the given value as being checked
1358 // do nothing if there are no radio buttons
1359 // if the given value does not exist, all the radio buttons
1360 // are reset to unchecked
1361 function set_checked_value(radioObj, newValue) {
1364 var radioLength = radioObj.length;
1365 if(radioLength == undefined) {
1366 radioObj.checked = (radioObj.value == newValue.toString());
1369 for(var i = 0; i < radioLength; i++) {
1370 radioObj[i].checked = false;
1371 if(radioObj[i].value == newValue.toString()) {
1372 radioObj[i].checked = true;
1377 function url_append_arg(url, name, value)
1379 var pos, sep, pref, rest;
1381 if ((pos = url.indexOf('?'+name+'=')) == -1) {
1382 pos = url.indexOf('&'+name+'=');
1385 if ((pos = url.indexOf('?')) != -1)
1390 return (url+sep+name+"="+encodeURIComponent(value));
1393 pref = url.substring(0, pos+1);
1394 rest = url.substring(pos+1);
1395 // alert("rest: "+rest+" pos: "+pos);
1396 if ((pos = rest.indexOf('&')) != -1) {
1397 rest = rest.substring(pos);
1402 return (pref+name+"="+encodeURIComponent(value)+rest);
1406 function url_append_args(url)
1411 for (i = 1 ; i < arguments.length-1 ; i+= 2) {
1412 ret = url_append_arg(ret, arguments[i], arguments[i+1]);
1418 function url_complete(parent, url)
1421 var host = "", path = "";
1424 p = parent.indexOf("://");
1426 rest = parent.substring(p+3);
1427 p2 = rest.indexOf("/");
1429 host = parent.substring(0, p+3+p2);
1430 rest = parent.substring(p+3+p2);
1442 p = rest.lastIndexOf("/");
1444 path = rest.substring(0, p+1);
1447 // alert("host: ["+host+"] path: ["+path+"]");
1448 if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/' || url.substring(0,4) == 'ws:/' || url.substring(0,5) == 'wss:/') {
1451 else if (url.substring(0,1) == '/') {
1455 return (host+path+url);
1459 function download_mgr(url)
1463 if ((ifra = $('the_downloader')) == null) {
1464 ifra = document.createElement("iframe");
1465 ifra.style.display = "none";
1466 ifra.id = 'the_downloader';
1467 document.body.appendChild(ifra);
1470 ifra.contentWindow.location.href = url;
1475 download_mgr.prototype = {
1479 function submit_click(obj)
1481 obj.form.elements['realsub'].value = obj.id;