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' : '(autenticati)',
45 'en' : '(authenticated)' } },
46 '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 ?',
47 '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 ?'
51 function $(id) { return document.getElementById(id); }
53 function dec2hex(d, padding)
55 var hex = Number(d).toString(16);
56 padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
58 while (hex.length < padding) {
65 function getStyle(x,IEstyleProp, MozStyleProp)
68 var y = x.currentStyle[IEstyleProp];
69 } else if (window.getComputedStyle) {
70 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
75 /* replacement of setInterval on IE */
77 /*if not IE, do nothing*/
78 if(!document.uniqueID){return;};
80 /*Copy the default setInterval behavior*/
81 var nativeSetInterval = window.setInterval;
82 window.setInterval = function(fn,ms) {
84 if(arguments.length <= 2) {
85 return nativeSetInterval(fn,ms);
88 for(var i=2;i<arguments.length;i+=1) {
89 param[i-2] = arguments[i];
93 if(typeof(fn)=='function') {
95 return (function (fn,ms,param) {
96 var fo = function () {
97 fn.apply(window,param);
99 return nativeSetInterval(fo,ms);
102 else if(typeof(fn)=='string')
104 return nativeSetInterval(fn,ms);
108 throw Error('setInterval Error\nInvalid function type');
112 /*Copy the default setTimeout behavior*/
113 var nativeSetTimeout = window.setTimeout;
114 window.setTimeout = function(fn,ms) {
116 if(arguments.length <= 2) {
117 return nativeSetTimeout(fn,ms);
120 for(var i=2;i<arguments.length;i+=1) {
121 param[i-2] = arguments[i];
125 if(typeof(fn)=='function') {
127 return (function (fn,ms,param) {
128 var fo = function () {
129 fn.apply(window,param);
131 return nativeSetTimeout(fo,ms);
134 else if(typeof(fn)=='string')
136 return nativeSetTimeout(fn,ms);
140 throw Error('setTimeout Error\nInvalid function type');
146 function addEvent(obj, type, fn)
148 if (obj.addEventListener) {
149 obj.addEventListener( type, fn, false);
151 else if (obj.attachEvent) {
152 obj["e"+type+fn] = fn;
153 obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
154 obj.attachEvent( "on"+type, obj[type+fn] );
157 throw new Error("Event registration not supported");
160 function removeEvent(obj,type,fn)
162 if (obj.removeEventListener) {
163 obj.removeEventListener( type, fn, false );
165 else if (obj.detachEvent) {
166 obj.detachEvent( "on"+type, obj[type+fn] );
168 obj["e"+type+fn] = null;
172 // var card_pos = RANGE 0 <= x < cards_ea_n
174 function show_bigpict(obj, act, x, y)
178 if (arguments.length > 4)
183 big = $(obj.id+"_big"+sfx);
185 big.style.left = obj.offsetLeft + x+"px";
186 big.style.top = obj.offsetTop + y+"px";
187 big.style.visibility = "visible";
190 big.style.visibility = "hidden";
194 function rnd_int(min, max) {
195 return Math.floor(Math.random() * (max - min + 1) + min);
198 function error_images()
200 // alert("GHESEMU!");
201 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
204 function abort_images()
206 // alert("ABORTAIMAGES");
207 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
210 function unload_images()
212 // alert("ABORTAIMAGES");
213 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
216 function reset_images()
218 // alert("ABORTAIMAGES");
219 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
222 function update_images()
224 // MLANG "Immagine caricate" + g_preload_imgsz_arr[g_imgct] + "%."
225 $("imgct").innerHTML = mlang_commons['imgload_a'][g_lang]+g_preload_imgsz_arr[g_imgct]+"%.";
226 if (g_imgct+1 < g_preload_img_arr.length) {
228 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
230 // $("imgct").innerHTML += "U";
233 function preload_images(arr,idx)
237 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
238 im.onload = update_images;
239 im.onerror = error_images;
240 im.onabort = abort_images;
241 im.onunload = unload_images;
242 im.onreset = reset_images;
244 // $("imgct").innerHTML += "P";
247 function safestatus(a)
255 function createXMLHttpRequest() {
256 if (typeof(ActiveXObject) != 'undefined') { // Konqueror complain as unknown object
257 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
258 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
260 try { return new XMLHttpRequest(); } catch(e) {}
261 alert("XMLHttpRequest not supported");
265 function send_mesg(mesg, content)
267 var is_conn = (sess == "not_connected" ? false : true);
269 if (is_conn && xstm && xstm.transp_type.startsWith('websocket')) {
270 if (typeof(content) != 'undefined') {
271 mesg = mesg + content;
273 var target = window.location.href.substring(0,
274 window.location.href.lastIndexOf('/') + 1) + 'index_wr.php';
275 var ws_msg = JSON.stringify({
280 table_idx: readCookie("table_idx"),
281 table_token: readCookie("table_token"),
282 lang: readCookie("lang")
284 // console.log(ws_msg);
287 if (xstm.transp.ws.readyState == 1) {
288 xstm.transp.ws.send(ws_msg);
291 xstm.transp.out_queue.push(ws_msg);
297 var xhr_wr = createXMLHttpRequest();
299 if (typeof(content) != 'undefined') {
300 mesg = mesg + encodeURIComponent(content);
302 // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn);
303 xhr_wr.open('GET', 'index_wr.php?&'+(is_conn ? 'sess='+sess : '')+'&stp='+gst.st+'&mesg='+mesg, (is_conn ? true : false));
304 xhr_wr.setRequestHeader("If-Modified-Since", new Date().toUTCString());
305 xhr_wr.onreadystatechange = function() { return; };
306 if (typeof(g_debug) == 'number' && g_debug > 0
307 && typeof(console) == 'object' && typeof(console.log) == 'function') {
308 var ldate = new Date();
309 console.log(ldate.getTime()+':MESG:'+mesg);
314 if (xhr_wr.responseText != null) {
315 eval(xhr_wr.responseText);
322 sync request to server
323 server_request([arg0=arg1[, arg2=arg3[, ...]]])
324 if var name == '__POST__' than all other vars will be managed as POST content
325 and the call will be a POST
327 function server_request()
329 var xhr_wr = createXMLHttpRequest();
330 var i, collect = "", post_collect = null, is_post = false;
332 if (arguments.length > 0) {
333 for (i = 0 ; i < arguments.length ; i+= 2) {
334 if (arguments[i] == "__POST__") {
341 post_collect += (post_collect == "" ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
343 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
346 // alert("Args: "+arguments.length);
348 var is_conn = (sess == "not_connected" ? false : true);
350 // console.log("server_request:preresp: "+xhr_wr.responseText);
353 xhr_wr.open('POST', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
354 xhr_wr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
357 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
359 xhr_wr.onreadystatechange = function() { return; };
360 xhr_wr.send(post_collect);
362 if (xhr_wr.responseText != null) {
363 // console.log("server_request:resp: "+xhr_wr.responseText);
364 return (xhr_wr.responseText);
370 /* Stat: CHAT and TABLE */
372 function chatt_checksend(obj,e)
378 if(window.event) { // IE
381 else if(e.which) { // Netscape/Firefox/Opera
384 // alert("OBJ: "+obj);
385 if (keynum == 13 && obj.value != "") { // Enter
386 act_chatt(obj.value);
390 function act_chatt(value)
392 if (value.substring(0, 6) == "/info ") {
393 info_show(value.substring(6));
396 send_mesg("chatt|", value);
401 obj.disabled = false;
413 function act_sitdown(table)
415 send_mesg("sitdown|"+table);
418 function act_wakeup()
423 function act_splash()
433 function act_passwdhowto()
435 send_mesg("passwdhowto");
438 function act_mesgtoadm()
440 send_mesg("mesgtoadm");
445 act_chatt('/tav '+$('txt_in').value);
446 $('txt_in').value = '';
454 function act_placing()
456 send_mesg("placing");
459 function act_roadmap()
461 send_mesg("roadmap");
464 function act_lascio()
469 function safelascio()
472 // MLANG "Sei sicuro di volere lasciare questa mano?"
473 res = window.confirm(mlang_commons['gamleav'][g_lang]);
478 function act_logout(exitlock)
480 send_mesg("logout|"+exitlock);
483 function act_reloadroom()
485 window.onunload = null;
486 window.onbeforeunload = null;
487 document.location.assign("index.php");
490 function act_shutdown()
494 send_mesg("shutdown");
495 // while (xhr_wr.readyState != 4)
499 function postact_logout()
501 // alert("postact_logout");
506 // eraseCookie("sess");
507 document.location.assign("index.php");
511 type - 'hard' or 'soft'
512 code - if soft: accept (0), refuse (1), download (2), later (3)
513 if hard: accept (0), refuse (1), download (2)
515 function act_tosmgr(type, code, tos_curr, tos_vers)
517 if (type != "soft" && type != "hard") {
523 send_mesg("tosmgr|"+type+"|"+code+"|"+tos_curr+"|"+tos_vers);
534 function tos_confirm(val, url)
540 return (window.confirm(mlang_commons['tos_refu'][g_lang]));
543 dlm = new download_mgr(url);
553 function slowimg(img,x1,y1,deltat,free,action,srcend)
555 x1,y1 - destination coords
556 deltat - time for each frame (in msec)
557 free - when the release the local block for other operations (range: 0 - 1)
558 action - function to run when the image is moved
559 srcend - image to switch when the image is moved
562 function sleep(st, delay)
564 // alert("LOC_NEW PRE: "+st.st_loc_new);
568 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
572 function slowimg(img, x1, y1, deltat, free, action, card_id_end) {
575 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
576 this.x0 = parseInt(getStyle(this.img,"left", "left"));
577 // alert("img.x0 = "+this.x0);
578 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
579 this.y0 = parseInt(getStyle(this.img,"top", "top"));
582 this.deltat = deltat;
584 this.action = action;
585 this.card_id_end = card_id_end;
588 slowimg.prototype = {
607 setstart: function(x0,y0)
613 setaction: function(act)
619 settime: function(time)
621 this.time = (time < this.deltat ? this.deltat : time);
622 this.step_n = parseInt(this.time / this.deltat);
623 this.dx = (this.x1 - this.x0) / this.step_n;
624 this.dy = (this.y1 - this.y0) / this.step_n;
625 if (this.step_n * this.deltat == this.time) {
629 this.step_free = parseInt(this.step_n * this.free);
635 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
637 this.st.st_loc_new++;
639 this.img.style.visibility = "visible";
640 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
645 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
646 if (this.step_cur == 0) {
647 var date = new Date();
648 // $("logz").innerHTML = "Timestart: " + date + "<br>";
650 if (this.step_cur <= this.step_n) {
651 this.img.style.left = this.x0 + this.dx * this.step_cur;
652 this.img.style.top = this.y0 + this.dy * this.step_cur;
654 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
655 if (this.step_cur == this.step_free && this.st != null) {
656 if (this.st.st_loc < this.st.st_loc_new) {
657 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
664 this.img.style.left = this.x1;
665 this.img.style.top = this.y1;
666 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
667 var date = new Date();
668 // $("logz").innerHTML += "Timestop: " + date + "<br>";
670 if (this.action != null) {
674 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
679 if (this.card_id_end != null) {
680 this.img.setAttribute('data-card-id', this.card_id_end);
686 function div_show(div)
688 div.style.top = parseInt((document.body.clientHeight - parseInt(getStyle(div,"height", "height"))) / 2) + document.body.scrollTop;
689 div.style.visibility = "visible";
695 tout: if < 0 => infinite
703 function notify_document(st, text, tout, butt, confirm_func, confirm_func_args, w, h, is_opa, block_time)
705 var i, clo, clodiv_ctx, clodiv_wai, box;
709 this.ancestor = document.body;
710 this.confirm_func = confirm_func;
711 this.confirm_func_args = confirm_func_args;
712 this.st.st_loc_new++;
714 clodiv_ctx = document.createElement("div");
715 clodiv_ctx.className = "notify_clo";
717 for (i = 0 ; i < butt.length ; i++) {
718 this.input_add(butt[i], i, this.hide, clodiv_ctx);
721 if (block_time > 0) {
722 clodiv_wai = document.createElement("div");
723 clodiv_wai.className = "notify_clo";
725 this.input_add("leggere, prego.", 0, null, clodiv_wai);
726 this.clodiv = clodiv_wai;
727 this.clodiv_pkg = clodiv_ctx;
728 clodiv_ctx.style.display = 'none';
731 this.clodiv = clodiv_ctx;
734 cont = document.createElement("div");
736 cont.style.borderBottomStyle = "solid";
737 cont.style.borderBottomWidth = "1px";
738 cont.style.borderBottomColor = "gray";
739 cont.style.height = (h - 50)+"px";
740 cont.style.overflow = "auto";
741 cont.style.textAlign = "left";
742 cont.style.padding = "8px";
743 cont.style.fontFamily = "monospace";
744 cont.innerHTML = text;
746 box = document.createElement("div");
748 box.className = "notify_opaque";
750 box.className = "notify";
752 box.style.zIndex = 200;
753 box.style.width = w+"px";
754 box.style.marginLeft = -parseInt(w/2)+"px";
755 box.style.height = h+"px";
756 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
757 box.appendChild(cont);
758 box.appendChild(this.clodiv);
759 box.style.visibility = "visible";
763 this.ancestor.appendChild(box);
766 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
769 if (block_time != 0) {
770 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);
774 notify_document.prototype = {
788 confirm_func_args: [],
795 onclick_cb: name of the onclick callback (with signature f(idx) ) or null
796 anc: parent dom object
798 return new button dom object
800 input_add: function(s, idx, onclick_cb, anc)
804 clo = document.createElement("input");
806 clo.className = "button";
807 clo.style.bottom = "4px";
808 clo.style.margin = "2px";
813 clo.onclick = function () { onclick_cb.call(this.obj, this.obj_idx); };
816 anc.appendChild(clo);
823 // alert("quiz: "+this.rett);
829 if (this.st.st_loc < this.st.st_loc_new) {
836 if (this.confirm_func != null) {
839 args = [ val ].concat(this.confirm_func_args);
841 if (this.confirm_func.apply(null, args) == false) {
846 clearTimeout(this.toutid);
847 this.ancestor.removeChild(this.notitag);
855 function notify_ex(st, text, tout, butt, w, h, is_opa, block_time)
862 this.ancestor = document.body;
864 this.st.st_loc_new++;
866 clo = document.createElement("input");
868 clo.className = "button";
869 clo.style.bottom = "4px";
871 if (block_time > 0) {
872 clo.value = "leggere, prego.";
877 clo.onclick = function () { this.obj.hide() };
880 clodiv = document.createElement("div");
881 clodiv.className = "notify_clo";
883 this.clodiv = clodiv;
885 clodiv.appendChild(clo);
887 cont = document.createElement("div");
889 cont.style.borderBottomStyle = "solid";
890 cont.style.borderBottomWidth = "1px";
891 cont.style.borderBottomColor = "gray";
892 cont.style.height = (h - 30)+"px";
893 cont.style.overflow = "auto";
894 cont.innerHTML = text;
896 box = document.createElement("div");
898 box.className = "notify_opaque";
900 box.className = "notify";
902 box.style.zIndex = 200;
903 box.style.width = w+"px";
904 box.style.marginLeft = -parseInt(w/2)+"px";
905 box.style.height = h+"px";
906 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
907 box.appendChild(cont);
908 box.appendChild(clodiv);
909 box.style.visibility = "visible";
913 this.ancestor.appendChild(box);
915 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
917 if (block_time != 0) {
918 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);
928 notify_ex.prototype = {
940 if (this.st.st_loc < this.st.st_loc_new) {
947 clearTimeout(this.toutid);
948 this.ancestor.removeChild(this.notitag);
954 notify.prototype = notify_ex.prototype; // Define sub-class
955 notify.prototype.constructor = notify;
956 notify.baseConstructor = notify_ex;
957 notify.superClass = notify_ex.prototype;
959 function notify(st, text, tout, butt, w, h)
961 notify_ex.call(this, st, text, tout, butt, w, h, false, 0);
967 this.st_loc_new = -1;
968 this.comms = new Array;
978 sleep: function(delay) {
982 this.sleep_hdl = setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; obj.sleep_hdl = null; }},
988 if (this.sleep_hdl != null) {
989 clearTimeout(this.sleep_hdl);
990 this.sleep_hdl = null;
995 function remark_step()
997 var ct = $("remark").l_remct;
1003 $("remark").className = "remark"+ct;
1004 $("remark").l_remct = ct;
1005 setTimeout(remark_step,500);
1008 $("remark").className = "remark0";
1013 function remark_on()
1015 if ($("remark").l_remct == 0) {
1016 $("remark").l_remct = 1;
1017 setTimeout(remark_step,500);
1021 function remark_off()
1023 $("remark").l_remct = 0;
1024 $("remark").className = "remark0";
1028 function italizer(ga)
1032 return "<i>"+ga[1]+"</i>";
1038 function exitlock_show(num, islock)
1042 num = (num < 3 ? num : 3);
1043 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
1044 // alert("EXITLOCK: "+$("exitlock").src);
1045 $("exitlock").style.visibility = "visible";
1050 // exitlock_show(0, true);
1053 var chatt_lines = new Array();
1054 var chatt_lines_n = 0;
1056 var CHATT_MAXLINES = 40;
1058 function user_decorator(user, is_real)
1060 var name, i, sp = "", cl = "";
1061 var flags = user[0] & 0x03 | ((user[0] & 0x0c0000) >> 16);
1063 // console.log(user[1]+" FLAGS: "+flags);
1065 for (i = 0 ; i < 4 ; i++) {
1066 if (flags & (1 << i)) {
1067 cl += sp + "au" + i + (is_real ? "" : "_off");
1073 name = "<span class='" + cl + "'><span class='" +
1074 (is_real && (flags & 0xfffffe && ((flags & 0x01) == 0)) ? "id_usr" : "") +
1075 "'>" + user[1] + "</span></span>";
1084 function user_dec_and_state(el)
1089 content = user_decorator(el, true);
1090 content += state_add(el[0],(typeof(el[2]) != 'undefined' ? el[2] : null));
1097 function chatt_sub(dt,data,str)
1099 var must_scroll = false;
1103 var bolder = [ (data[0] | 1), data[1] ];
1104 name = user_decorator(bolder, false);
1106 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
1109 // alert("ARRIVA NAME: "+ name + " STR:"+str);
1110 if (chatt_lines_n == CHATT_MAXLINES) {
1111 $("txt").innerHTML = "";
1112 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
1113 chatt_lines[i] = chatt_lines[i+1];
1114 $("txt").innerHTML += chatt_lines[i];
1116 chatt_lines[i] = dt+name+": "+str+ "<br>";
1117 $("txt").innerHTML += chatt_lines[i];
1120 chatt_lines[chatt_lines_n] = dt+name+": "+str+ "<br>";
1121 $("txt").innerHTML += chatt_lines[chatt_lines_n];
1124 // $("txt").innerHTML;
1128 $("txt").scrollTop = 10000000;
1130 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
1134 * GESTIONE DEI COOKIES
1136 function createCookie(name,value,hours,path) {
1138 var date = new Date();
1139 date.setTime(date.getTime()+(hours*60*60*1000));
1140 var expires = "; expires="+date.toGMTString();
1142 else var expires = "";
1143 document.cookie = name+"="+value+expires+"; path="+path;
1146 function readCookie(name) {
1147 var nameEQ = name + "=";
1148 var ca = document.cookie.split(';');
1149 for(var i=0;i < ca.length;i++) {
1151 while (c.charAt(0)==' ')
1152 c = c.substring(1,c.length);
1153 if (c.indexOf(nameEQ) == 0)
1154 return c.substring(nameEQ.length,c.length);
1159 function eraseCookie(name) {
1160 createCookie(name,"",-1);
1163 function onbeforeunload_cb () {
1167 function onunload_cb () {
1169 if (typeof(xstm) != "undefined")
1170 xstm.the_end = true;
1177 function room_checkspace(emme,tables,inpe)
1180 for (i = 0 ; i < emme ; i++)
1185 for (i = 0 ; i < 5 ; i++)
1186 alta += nome+"<br>";
1188 for (i = 0 ; i < tables ; i++) {
1189 $("table"+i).innerHTML = alta;
1191 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
1194 stand = "<table class=\"table_standup\"><tbody><tr>";
1195 for (i = 0 ; i < inpe ; i++) {
1196 stand += "<td>"+nome+"</td>";
1197 if ((i+1) % 4 == 0) {
1198 stand += "</tr><tr>";
1202 $("standup").innerHTML = stand;
1204 // VERIFY: what is this button ?
1206 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
1209 function unescapeHTML(cont) {
1210 var div = document.createElement('div');
1214 div.innerHTML = cont;
1215 if (div.childNodes[0]) {
1216 if (div.childNodes.length > 1) {
1217 if (div.childNodes.toArray)
1220 var length = div.childNodes.length, results = new Array(length);
1222 results[length] = div.childNodes[length];
1224 for (i=0 ; i<results.length ; i++)
1225 memo = memo + results[i].nodeValue;
1231 return (div.childNodes[0].nodeValue);
1240 samples = [{'name': <name>, 'file': <file>}, ... ]
1242 function jukebox(samples)
1245 this.enable = false;
1248 var pro_audio_el = document.createElement('audio');
1249 this.enable = !!(pro_audio_el.canPlayType && pro_audio_el.canPlayType('audio/mpeg;').replace(/no/, ''));
1251 for (i in samples) {
1252 sample = samples[i];
1254 this.audio[sample['name']] = a = document.createElement('audio');
1256 source = document.createElement('source');
1257 source.setAttribute('src', sample['file']);
1258 source.setAttribute('type', 'audio/mpeg');
1259 a.appendChild(source);
1265 jukebox.prototype = {
1266 is_enabled: function() {
1270 play: function(name) {
1275 if (!(name in this.audio)) {
1278 a = this.audio[name];
1284 function topbanner_init()
1286 setInterval(topbanner_cb, 666);
1290 function topbanner_cb()
1294 a = $('topbanner').style.backgroundColor;
1295 b = $('topbanner').style.borderLeftColor;
1297 $('topbanner').style.backgroundColor = b;
1298 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
1300 // console.log("A: "+a+" B: "+b);
1303 function sidebanner_init(idx)
1305 setInterval(function () { sidebanner_cb(idx); }, 666);
1308 function sidebanner_cb(idx)
1312 a = $('sidebanner'+idx).style.backgroundColor;
1313 b = $('sidebanner'+idx).style.borderLeftColor;
1315 $('sidebanner'+idx).style.backgroundColor = b;
1316 $('sidebanner'+idx).style.borderColor = a+" "+a+" "+a+" "+a;
1318 // console.log("A: "+a+" B: "+b);
1322 function langtolng(lang)
1330 function formtext_hilite(obj)
1332 obj.className = 'input_text';
1333 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
1334 addEvent(obj, "blur", function () { this.className = 'input_text'; });
1337 function formsub_hilite(obj)
1339 obj.className = 'input_sub';
1340 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1341 addEvent(obj, "blur", function () { this.className = 'input_sub'; });
1344 // return the value of the radio button that is checked
1345 // return an empty string if none are checked, or
1346 // there are no radio buttons
1347 function get_checked_value(radioObj) {
1350 var radioLength = radioObj.length;
1351 if(radioLength == undefined)
1352 if(radioObj.checked)
1353 return radioObj.value;
1356 for(var i = 0; i < radioLength; i++) {
1357 if(radioObj[i].checked) {
1358 return radioObj[i].value;
1364 // set the radio button with the given value as being checked
1365 // do nothing if there are no radio buttons
1366 // if the given value does not exist, all the radio buttons
1367 // are reset to unchecked
1368 function set_checked_value(radioObj, newValue) {
1371 var radioLength = radioObj.length;
1372 if(radioLength == undefined) {
1373 radioObj.checked = (radioObj.value == newValue.toString());
1376 for(var i = 0; i < radioLength; i++) {
1377 radioObj[i].checked = false;
1378 if(radioObj[i].value == newValue.toString()) {
1379 radioObj[i].checked = true;
1384 function url_append_arg(url, name, value)
1386 var pos, sep, pref, rest;
1388 if ((pos = url.indexOf('?'+name+'=')) == -1) {
1389 pos = url.indexOf('&'+name+'=');
1392 if ((pos = url.indexOf('?')) != -1)
1397 return (url+sep+name+"="+encodeURIComponent(value));
1400 pref = url.substring(0, pos+1);
1401 rest = url.substring(pos+1);
1402 // alert("rest: "+rest+" pos: "+pos);
1403 if ((pos = rest.indexOf('&')) != -1) {
1404 rest = rest.substring(pos);
1409 return (pref+name+"="+encodeURIComponent(value)+rest);
1413 function url_append_args(url)
1418 for (i = 1 ; i < arguments.length-1 ; i+= 2) {
1419 ret = url_append_arg(ret, arguments[i], arguments[i+1]);
1425 function url_complete(parent, url)
1428 var host = "", path = "";
1431 p = parent.indexOf("://");
1433 rest = parent.substring(p+3);
1434 p2 = rest.indexOf("/");
1436 host = parent.substring(0, p+3+p2);
1437 rest = parent.substring(p+3+p2);
1449 p = rest.lastIndexOf("/");
1451 path = rest.substring(0, p+1);
1454 // alert("host: ["+host+"] path: ["+path+"]");
1455 if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/' || url.substring(0,4) == 'ws:/' || url.substring(0,5) == 'wss:/') {
1458 else if (url.substring(0,1) == '/') {
1462 return (host+path+url);
1466 function download_mgr(url)
1470 if ((ifra = $('the_downloader')) == null) {
1471 ifra = document.createElement("iframe");
1472 ifra.style.display = "none";
1473 ifra.id = 'the_downloader';
1474 document.body.appendChild(ifra);
1477 ifra.contentWindow.location.href = url;
1482 download_mgr.prototype = {
1486 function submit_click(obj)
1488 obj.form.elements['realsub'].value = obj.id;