2 * brisk / fieldify - commons.js
4 * Copyright (C) 2006-2016 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.
24 var __mop_commons_vers="0.1.0"
27 var EXIT_BAN_TIME = 3600;
28 var cookiepath = "/brisk/";
30 var mlang_commons = { 'imgload_a' : { 'it' : 'Immagini caricate ',
31 'en' : 'Loaded images ' },
32 'imgload_b' : { 'it' : '%.',
34 'gamleav' : { 'it' : 'Sei sicuro di volere lasciare questa mano?' ,
35 'en' : 'Are you sure to leave this game?' },
36 'brileav' : { 'it' : ' Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)',
37 'en' : ' Are you really sure to leave briscola ?\n(click cancel yo reload it)' },
38 'brireco' : { 'it' : 'Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.',
39 'en' : 'Recovery of briscola failed, to keep the current session reload the page manually.' },
40 'btn_sit' : { 'it' : 'Mi siedo.',
42 'btn_exit' : { 'it' : 'Esco.',
44 'tit_list' : { '0' : { 'it' : '',
46 '1' : { 'it' : '(solo aut.)',
47 'en' : '(only aut.)' },
48 '2' : { 'it' : '(isolam.to)',
49 'en' : '(isolation)' } },
50 '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 ?',
51 '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 ?'
55 function $(id) { return document.getElementById(id); }
57 function $C(cls) { return document.getElementsByClassName(cls); }
59 function dec2hex(d, padding)
61 var hex = Number(d).toString(16);
62 padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
64 while (hex.length < padding) {
71 function ends_with(s, suffix)
73 if (s.indexOf(suffix, s.length - suffix.length) !== -1) {
79 function getStyle(x,IEstyleProp, MozStyleProp)
82 var y = x.currentStyle[IEstyleProp];
83 } else if (window.getComputedStyle) {
84 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
89 /* replacement of setInterval on IE */
91 /*if not IE, do nothing*/
92 if(!document.uniqueID){return;};
94 /*Copy the default setInterval behavior*/
95 var nativeSetInterval = window.setInterval;
96 window.setInterval = function(fn,ms) {
98 if(arguments.length <= 2) {
99 return nativeSetInterval(fn,ms);
102 for(var i=2;i<arguments.length;i+=1) {
103 param[i-2] = arguments[i];
107 if(typeof(fn)=='function') {
109 return (function (fn,ms,param) {
110 var fo = function () {
111 fn.apply(window,param);
113 return nativeSetInterval(fo,ms);
116 else if(typeof(fn)=='string')
118 return nativeSetInterval(fn,ms);
122 throw Error('setInterval Error\nInvalid function type');
126 /*Copy the default setTimeout behavior*/
127 var nativeSetTimeout = window.setTimeout;
128 window.setTimeout = function(fn,ms) {
130 if(arguments.length <= 2) {
131 return nativeSetTimeout(fn,ms);
134 for(var i=2;i<arguments.length;i+=1) {
135 param[i-2] = arguments[i];
139 if(typeof(fn)=='function') {
141 return (function (fn,ms,param) {
142 var fo = function () {
143 fn.apply(window,param);
145 return nativeSetTimeout(fo,ms);
148 else if(typeof(fn)=='string')
150 return nativeSetTimeout(fn,ms);
154 throw Error('setTimeout Error\nInvalid function type');
160 function addEvent(obj, type, fn)
162 if (obj.addEventListener) {
163 obj.addEventListener( type, fn, false);
165 else if (obj.attachEvent) {
166 obj["e"+type+fn] = fn;
167 obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
168 obj.attachEvent( "on"+type, obj[type+fn] );
171 throw new Error("Event registration not supported");
174 function removeEvent(obj,type,fn)
176 if (obj.removeEventListener) {
177 obj.removeEventListener( type, fn, false );
179 else if (obj.detachEvent) {
180 obj.detachEvent( "on"+type, obj[type+fn] );
182 obj["e"+type+fn] = null;
186 // var card_pos = RANGE 0 <= x < cards_ea_n
188 function show_bigpict(obj, act, x, y)
192 if (arguments.length > 4)
197 big = $(obj.id+"_big"+sfx);
199 big.style.left = obj.offsetLeft + x+"px";
200 big.style.top = obj.offsetTop + y+"px";
201 big.style.visibility = "visible";
204 big.style.visibility = "hidden";
208 function rnd_int(min, max) {
209 return Math.floor(Math.random() * (max - min + 1) + min);
212 function error_images()
214 // alert("GHESEMU!");
215 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
218 function abort_images()
220 // alert("ABORTAIMAGES");
221 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
224 function unload_images()
226 // alert("ABORTAIMAGES");
227 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
230 function reset_images()
232 // alert("ABORTAIMAGES");
233 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
236 function update_images()
238 // MLANG "Immagine caricate" + g_preload_imgsz_arr[g_imgct] + "%."
239 $("imgct").innerHTML = mlang_commons['imgload_a'][g_lang]+g_preload_imgsz_arr[g_imgct]+"%.";
240 if (g_imgct+1 < g_preload_img_arr.length) {
242 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
244 // $("imgct").innerHTML += "U";
247 function preload_images(arr,idx)
251 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
252 im.onload = update_images;
253 im.onerror = error_images;
254 im.onabort = abort_images;
255 im.onunload = unload_images;
256 im.onreset = reset_images;
258 // $("imgct").innerHTML += "P";
261 function safestatus(a)
269 function createXMLHttpRequest() {
270 if (typeof(ActiveXObject) != 'undefined') { // Konqueror complain as unknown object
271 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
272 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
274 try { return new XMLHttpRequest(); } catch(e) {}
275 alert("XMLHttpRequest not supported");
279 function send_mesg(mesg)
281 var xhr_wr = createXMLHttpRequest();
282 var is_conn = (sess == "not_connected" ? false : true);
284 // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn);
285 xhr_wr.open('GET', 'index_wr.php?&'+(is_conn ? 'sess='+sess : '')+'&stp='+gst.st+'&mesg='+mesg, (is_conn ? true : false));
286 xhr_wr.setRequestHeader("If-Modified-Since", new Date().toUTCString());
287 xhr_wr.onreadystatechange = function() { return; };
288 if (typeof(g_debug) == 'number' && g_debug > 0
289 && typeof(console) == 'object' && typeof(console.log) == 'function') {
290 var ldate = new Date();
291 console.log(ldate.getTime()+':MESG:'+mesg);
296 if (xhr_wr.responseText != null) {
297 eval(xhr_wr.responseText);
303 sync request to server
304 server_request([arg0=arg1[, arg2=arg3[, ...]]])
305 if var name == '__POST__' than all other vars will be managed as POST content
306 and the call will be a POST
308 function server_request(page, sess)
310 var xhr_wr = createXMLHttpRequest();
312 var i, collect = "", post_collect = null, is_post = false;
314 if (arguments.length > 0) {
315 for (i = 2 ; i < arguments.length ; i+= 2) {
316 if (arguments[i] == "__POST__") {
323 post_collect += (post_collect == "" ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
325 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
328 var uri = page + '?' + (sess != null ? 'sess=' + sess + '&' : '') + collect;
330 xhr_wr.open('POST', uri, false);
331 xhr_wr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
334 xhr_wr.open('GET', uri, false);
337 xhr_wr.timeout = tout;
340 xhr_wr.onreadystatechange = function() {
341 console.log('we are here');
343 xhr_wr.send(post_collect);
345 if (xhr_wr.responseText != null) {
346 // console.log("server_request:resp: "+xhr_wr.responseText);
347 return (xhr_wr.responseText);
354 function server_asyncreq(async_req, page, sess)
356 var xhr_wr = createXMLHttpRequest();
358 var i, collect = "", post_collect = null, is_post = false;
360 if (arguments.length > 0) {
361 for (i = 3 ; i < arguments.length ; i+= 2) {
362 if (arguments[i] == "__POST__") {
368 else if (arguments[i] == "__TOUT__") {
369 tout = arguments[i+1];
373 post_collect += (post_collect == "" ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
375 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
378 var already_quest = (page.indexOf('?') != -1);
379 var uri = page + (already_quest ? '&' : '?') + (sess != null ? 'sess=' + sess + '&' : '') + collect;
381 xhr_wr.open('POST', uri, true);
382 xhr_wr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
385 xhr_wr.open('GET', uri, true);
388 xhr_wr.timeout = tout;
391 xhr_wr.onreadystatechange = async_req;
392 xhr_wr.send(post_collect);
397 /* Stat: CHAT and TABLE */
399 function chatt_checksend(obj,e)
405 if(window.event) { // IE
408 else if(e.which) { // Netscape/Firefox/Opera
411 // alert("OBJ: "+obj);
412 if (keynum == 13 && obj.value != "") { // Enter
413 act_chatt(obj.value);
417 function act_chatt(value)
419 if (value.substring(0, 6) == "/info ") {
420 info_show(value.substring(6));
423 send_mesg("chatt|"+encodeURIComponent(value));
428 obj.disabled = false;
440 function act_sitdown(table)
442 send_mesg("sitdown|"+table);
445 function act_wakeup()
450 function act_splash()
460 function act_passwdhowto()
462 send_mesg("passwdhowto");
465 function act_mesgtoadm()
467 send_mesg("mesgtoadm");
472 act_chatt('/tav '+$('txt_in').value);
473 $('txt_in').value = '';
481 function act_placing()
483 send_mesg("placing");
486 function act_roadmap()
488 send_mesg("roadmap");
491 function act_lascio()
496 function safelascio()
499 // MLANG "Sei sicuro di volere lasciare questa mano?"
500 res = window.confirm(mlang_commons['gamleav'][g_lang]);
505 function act_logout(exitlock)
507 send_mesg("logout|"+exitlock);
510 function act_reloadroom()
512 window.onunload = null;
513 window.onbeforeunload = null;
514 document.location.assign("index.php");
517 function act_shutdown()
521 send_mesg("shutdown");
522 // while (xhr_wr.readyState != 4)
526 function postact_logout()
528 // alert("postact_logout");
533 // eraseCookie("sess");
534 document.location.assign("index.php");
538 type - 'hard' or 'soft'
539 code - if soft: accept (0), refuse (1), download (2), later (3)
540 if hard: accept (0), refuse (1), download (2)
542 function act_tosmgr(type, code, tos_curr, tos_vers)
544 if (type != "soft" && type != "hard") {
550 send_mesg("tosmgr|"+type+"|"+code+"|"+tos_curr+"|"+tos_vers);
561 function tos_confirm(val, url)
567 return (window.confirm(mlang_commons['tos_refu'][g_lang]));
570 dlm = new download_mgr(url);
580 function slowimg(img,x1,y1,deltat,free,action,srcend)
582 x1,y1 - destination coords
583 deltat - time for each frame (in msec)
584 free - when the release the local block for other operations (range: 0 - 1)
585 action - function to run when the image is moved
586 srcend - image to switch when the image is moved
589 function sleep(st, delay)
591 // alert("LOC_NEW PRE: "+st.st_loc_new);
595 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
599 function slowimg(img,x1,y1,deltat,free,action,srcend) {
602 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
603 this.x0 = parseInt(getStyle(this.img,"left", "left"));
604 // alert("img.x0 = "+this.x0);
605 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
606 this.y0 = parseInt(getStyle(this.img,"top", "top"));
609 this.deltat = deltat;
611 this.action = action;
612 this.srcend = srcend;
615 slowimg.prototype = {
634 setstart: function(x0,y0)
640 setaction: function(act)
646 settime: function(time)
648 this.time = (time < this.deltat ? this.deltat : time);
649 this.step_n = parseInt(this.time / this.deltat);
650 this.dx = (this.x1 - this.x0) / this.step_n;
651 this.dy = (this.y1 - this.y0) / this.step_n;
652 if (this.step_n * this.deltat == this.time) {
656 this.step_free = parseInt(this.step_n * this.free);
662 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
664 this.st.st_loc_new++;
666 this.img.style.visibility = "visible";
667 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
672 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
673 if (this.step_cur == 0) {
674 var date = new Date();
675 // $("logz").innerHTML = "Timestart: " + date + "<br>";
677 if (this.step_cur <= this.step_n) {
678 this.img.style.left = this.x0 + this.dx * this.step_cur;
679 this.img.style.top = this.y0 + this.dy * this.step_cur;
681 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
682 if (this.step_cur == this.step_free && this.st != null) {
683 if (this.st.st_loc < this.st.st_loc_new) {
684 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
691 this.img.style.left = this.x1;
692 this.img.style.top = this.y1;
693 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
694 var date = new Date();
695 // $("logz").innerHTML += "Timestop: " + date + "<br>";
697 if (this.action != null) {
701 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
706 if (this.srcend != null) {
707 this.img.src = this.srcend;
713 function div_show(div)
715 div.style.top = parseInt((document.body.clientHeight - parseInt(getStyle(div,"height", "height"))) / 2) + document.body.scrollTop;
716 div.style.visibility = "visible";
722 tout: if < 0 => infinite
730 function notify_document(st, text, tout, butt, confirm_func, confirm_func_args, w, h, is_opa, block_time)
732 var i, clo, clodiv_ctx, clodiv_wai, box;
736 this.ancestor = document.body;
737 this.confirm_func = confirm_func;
738 this.confirm_func_args = confirm_func_args;
739 this.st.st_loc_new++;
741 clodiv_ctx = document.createElement("div");
742 clodiv_ctx.className = "notify_clo";
744 for (i = 0 ; i < butt.length ; i++) {
745 this.input_add(butt[i], i, this.hide, clodiv_ctx);
748 if (block_time > 0) {
749 clodiv_wai = document.createElement("div");
750 clodiv_wai.className = "notify_clo";
752 this.input_add("leggere, prego.", 0, null, clodiv_wai);
753 this.clodiv = clodiv_wai;
754 this.clodiv_pkg = clodiv_ctx;
755 clodiv_ctx.style.display = 'none';
758 this.clodiv = clodiv_ctx;
761 cont = document.createElement("div");
763 cont.style.borderBottomStyle = "solid";
764 cont.style.borderBottomWidth = "1px";
765 cont.style.borderBottomColor = "gray";
766 cont.style.height = (h - 50)+"px";
767 cont.style.overflow = "auto";
768 cont.style.textAlign = "left";
769 cont.style.padding = "8px";
770 cont.style.fontFamily = "monospace";
771 cont.innerHTML = text;
773 box = document.createElement("div");
775 box.className = "notify_opaque";
777 box.className = "notify";
779 box.style.zIndex = 200;
780 box.style.width = w+"px";
781 box.style.marginLeft = -parseInt(w/2)+"px";
782 box.style.height = h+"px";
783 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
784 box.appendChild(cont);
785 box.appendChild(this.clodiv);
786 box.style.visibility = "visible";
790 this.ancestor.appendChild(box);
793 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
796 if (block_time != 0) {
797 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);
801 notify_document.prototype = {
815 confirm_func_args: [],
822 onclick_cb: name of the onclick callback (with signature f(idx) ) or null
823 anc: parent dom object
825 return new button dom object
827 input_add: function(s, idx, onclick_cb, anc)
831 clo = document.createElement("input");
833 clo.className = "button";
834 clo.style.bottom = "4px";
835 clo.style.margin = "2px";
840 clo.onclick = function () { onclick_cb.call(this.obj, this.obj_idx); };
843 anc.appendChild(clo);
850 // alert("quiz: "+this.rett);
856 if (this.st.st_loc < this.st.st_loc_new) {
863 if (this.confirm_func != null) {
866 args = [ val ].concat(this.confirm_func_args);
868 if (this.confirm_func.apply(null, args) == false) {
873 clearTimeout(this.toutid);
874 this.ancestor.removeChild(this.notitag);
882 function notify_ex(st, text, tout, butt, w, h, is_opa, block_time)
889 this.ancestor = document.body;
891 this.st.st_loc_new++;
893 clo = document.createElement("input");
895 clo.className = "button";
896 clo.style.bottom = "4px";
898 if (block_time > 0) {
899 clo.value = "leggere, prego.";
904 clo.onclick = function () { this.obj.hide() };
907 clodiv = document.createElement("div");
908 clodiv.className = "notify_clo";
910 this.clodiv = clodiv;
912 clodiv.appendChild(clo);
914 cont = document.createElement("div");
916 cont.style.borderBottomStyle = "solid";
917 cont.style.borderBottomWidth = "1px";
918 cont.style.borderBottomColor = "gray";
919 cont.style.height = (h - 30)+"px";
920 cont.style.overflow = "auto";
921 cont.innerHTML = text;
923 box = document.createElement("div");
925 box.className = "notify_opaque";
927 box.className = "notify";
929 box.style.zIndex = 200;
930 box.style.width = w+"px";
931 box.style.marginLeft = -parseInt(w/2)+"px";
932 box.style.height = h+"px";
933 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
934 box.appendChild(cont);
935 box.appendChild(clodiv);
936 box.style.visibility = "visible";
940 this.ancestor.appendChild(box);
942 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
944 if (block_time != 0) {
945 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);
955 notify_ex.prototype = {
967 if (this.st.st_loc < this.st.st_loc_new) {
974 clearTimeout(this.toutid);
975 this.ancestor.removeChild(this.notitag);
981 notify.prototype = notify_ex.prototype; // Define sub-class
982 notify.prototype.constructor = notify;
983 notify.baseConstructor = notify_ex;
984 notify.superClass = notify_ex.prototype;
986 function notify(st, text, tout, butt, w, h)
988 notify_ex.call(this, st, text, tout, butt, w, h, false, 0);
994 this.st_loc_new = -1;
995 this.comms = new Array;
1005 sleep: function(delay) {
1008 if (!this.the_end) {
1009 this.sleep_hdl = setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; obj.sleep_hdl = null; }},
1015 if (this.sleep_hdl != null) {
1016 clearTimeout(this.sleep_hdl);
1017 this.sleep_hdl = null;
1022 function remark_step()
1024 var ct = $("remark").l_remct;
1030 $("remark").className = "remark"+ct;
1031 $("remark").l_remct = ct;
1032 setTimeout(remark_step,500);
1035 $("remark").className = "remark0";
1040 function remark_on()
1042 if ($("remark").l_remct == 0) {
1043 $("remark").l_remct = 1;
1044 setTimeout(remark_step,500);
1048 function remark_off()
1050 $("remark").l_remct = 0;
1051 $("remark").className = "remark0";
1055 function italizer(ga)
1059 return "<i>"+ga[1]+"</i>";
1065 function exitlock_show(num, islock)
1069 num = (num < 3 ? num : 3);
1070 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
1071 // alert("EXITLOCK: "+$("exitlock").src);
1072 $("exitlock").style.visibility = "visible";
1077 // exitlock_show(0, true);
1080 var chatt_lines = new Array();
1081 var chatt_lines_n = 0;
1083 var CHATT_MAXLINES = 40;
1085 function user_decorator(user, is_real)
1087 var name, i, sp = "", cl = "";
1088 var flags = user[0] & 0x03 | ((user[0] & 0x0c0000) >> 16);
1090 // console.log(user[1]+" FLAGS: "+flags);
1092 for (i = 0 ; i < 4 ; i++) {
1093 if (flags & (1 << i)) {
1094 cl += sp + "au" + i + (is_real ? "" : "_off");
1100 name = "<span class='" + cl + "'><span class='" +
1101 (is_real && (flags & 0xfffffe && ((flags & 0x01) == 0)) ? "id_usr" : "") +
1102 "'>" + user[1] + "</span></span>";
1111 function user_dec_and_state(el)
1116 content = user_decorator(el, true);
1117 content += state_add(el[0],(typeof(el[2]) != 'undefined' ? el[2] : null));
1124 function chatt_sub(dt,data,str)
1126 var must_scroll = false;
1130 var bolder = [ (data[0] | 1), data[1] ];
1131 name = user_decorator(bolder, false);
1133 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
1136 // alert("ARRIVA NAME: "+ name + " STR:"+str);
1137 if (chatt_lines_n == CHATT_MAXLINES) {
1138 $("txt").innerHTML = "";
1139 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
1140 chatt_lines[i] = chatt_lines[i+1];
1141 $("txt").innerHTML += chatt_lines[i];
1143 chatt_lines[i] = dt+name+": "+str+ "<br>";
1144 $("txt").innerHTML += chatt_lines[i];
1147 chatt_lines[chatt_lines_n] = dt+name+": "+str+ "<br>";
1148 $("txt").innerHTML += chatt_lines[chatt_lines_n];
1151 // $("txt").innerHTML;
1155 $("txt").scrollTop = 10000000;
1157 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
1161 * GESTIONE DEI COOKIES
1163 function createCookie(name,value,hours,path) {
1165 var date = new Date();
1166 date.setTime(date.getTime()+(hours*60*60*1000));
1167 var expires = "; expires="+date.toGMTString();
1169 else var expires = "";
1170 document.cookie = name+"="+value+expires+"; path="+path;
1173 function readCookie(name) {
1174 var nameEQ = name + "=";
1175 var ca = document.cookie.split(';');
1176 for(var i=0;i < ca.length;i++) {
1178 while (c.charAt(0)==' ')
1179 c = c.substring(1,c.length);
1180 if (c.indexOf(nameEQ) == 0)
1181 return c.substring(nameEQ.length,c.length);
1186 function eraseCookie(name) {
1187 createCookie(name,"",-1);
1190 function onbeforeunload_cb () {
1194 function onunload_cb () {
1196 if (typeof(xstm) != "undefined")
1197 xstm.the_end = true;
1204 function room_checkspace(emme,tables,inpe)
1207 for (i = 0 ; i < emme ; i++)
1212 for (i = 0 ; i < 5 ; i++)
1213 alta += nome+"<br>";
1215 for (i = 0 ; i < tables ; i++) {
1216 $("table"+i).innerHTML = alta;
1218 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
1221 stand = "<table class=\"table_standup\"><tbody><tr>";
1222 for (i = 0 ; i < inpe ; i++) {
1223 stand += "<td>"+nome+"</td>";
1224 if ((i+1) % 4 == 0) {
1225 stand += "</tr><tr>";
1229 $("standup").innerHTML = stand;
1231 // VERIFY: what is this button ?
1233 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
1236 function unescapeHTML(cont) {
1237 var div = document.createElement('div');
1241 div.innerHTML = cont;
1242 if (div.childNodes[0]) {
1243 if (div.childNodes.length > 1) {
1244 if (div.childNodes.toArray)
1247 var length = div.childNodes.length, results = new Array(length);
1249 results[length] = div.childNodes[length];
1251 for (i=0 ; i<results.length ; i++)
1252 memo = memo + results[i].nodeValue;
1258 return (div.childNodes[0].nodeValue);
1266 function playsound(tag, sound) {
1267 // g_withflash is a global var
1269 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
1270 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
1271 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
1272 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
1273 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
1274 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
1278 function topbanner_init()
1280 setInterval(topbanner_cb, 666);
1284 function topbanner_cb()
1288 a = $('topbanner').style.backgroundColor;
1289 b = $('topbanner').style.borderLeftColor;
1291 $('topbanner').style.backgroundColor = b;
1292 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
1294 // console.log("A: "+a+" B: "+b);
1297 function sidebanner_init(idx)
1299 setInterval(function () { sidebanner_cb(idx); }, 666);
1302 function sidebanner_cb(idx)
1306 a = $('sidebanner'+idx).style.backgroundColor;
1307 b = $('sidebanner'+idx).style.borderLeftColor;
1309 $('sidebanner'+idx).style.backgroundColor = b;
1310 $('sidebanner'+idx).style.borderColor = a+" "+a+" "+a+" "+a;
1312 // console.log("A: "+a+" B: "+b);
1316 function langtolng(lang)
1324 function formtext_hilite(obj)
1326 obj.className = 'input_text';
1327 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
1328 addEvent(obj, "blur", function () { this.className = 'input_text'; });
1331 function formsub_hilite(obj)
1333 obj.className = 'input_sub';
1334 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1335 addEvent(obj, "blur", function () { this.className = 'input_sub'; });
1338 // return the value of the radio button that is checked
1339 // return an empty string if none are checked, or
1340 // there are no radio buttons
1341 function get_checked_value(radioObj) {
1344 var radioLength = radioObj.length;
1345 if(radioLength == undefined)
1346 if(radioObj.checked)
1347 return radioObj.value;
1350 for(var i = 0; i < radioLength; i++) {
1351 if(radioObj[i].checked) {
1352 return radioObj[i].value;
1358 // set the radio button with the given value as being checked
1359 // do nothing if there are no radio buttons
1360 // if the given value does not exist, all the radio buttons
1361 // are reset to unchecked
1362 function set_checked_value(radioObj, newValue) {
1365 var radioLength = radioObj.length;
1366 if(radioLength == undefined) {
1367 radioObj.checked = (radioObj.value == newValue.toString());
1370 for(var i = 0; i < radioLength; i++) {
1371 radioObj[i].checked = false;
1372 if(radioObj[i].value == newValue.toString()) {
1373 radioObj[i].checked = true;
1378 function url_append_arg(url, name, value)
1380 var pos, sep, pref, rest;
1382 if ((pos = url.indexOf('?'+name+'=')) == -1) {
1383 pos = url.indexOf('&'+name+'=');
1386 if ((pos = url.indexOf('?')) != -1)
1391 return (url+sep+name+"="+encodeURIComponent(value));
1394 pref = url.substring(0, pos+1);
1395 rest = url.substring(pos+1);
1396 // alert("rest: "+rest+" pos: "+pos);
1397 if ((pos = rest.indexOf('&')) != -1) {
1398 rest = rest.substring(pos);
1403 return (pref+name+"="+encodeURIComponent(value)+rest);
1407 function url_append_args(url)
1412 for (i = 1 ; i < arguments.length-1 ; i+= 2) {
1413 ret = url_append_arg(ret, arguments[i], arguments[i+1]);
1419 function url_complete(parent, url)
1422 var host = "", path = "";
1425 p = parent.indexOf("://");
1427 rest = parent.substring(p+3);
1428 p2 = rest.indexOf("/");
1430 host = parent.substring(0, p+3+p2);
1431 rest = parent.substring(p+3+p2);
1443 p = rest.lastIndexOf("/");
1445 path = rest.substring(0, p+1);
1448 // alert("host: ["+host+"] path: ["+path+"]");
1449 if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/' || url.substring(0,4) == 'ws:/') {
1452 else if (url.substring(0,1) == '/') {
1456 return (host+path+url);
1460 function download_mgr(url)
1464 if ((ifra = $('the_downloader')) == null) {
1465 ifra = document.createElement("iframe");
1466 ifra.style.display = "none";
1467 ifra.id = 'the_downloader';
1468 document.body.appendChild(ifra);
1471 ifra.contentWindow.location.href = url;
1476 download_mgr.prototype = {
1480 function submit_click(obj)
1482 obj.form.elements['realsub'].value = obj.id;
1485 function class_check(item, cls_name)
1487 if ((" " + item.className + " ").indexOf(" " + cls_name + " ") == -1)
1493 function class_add(item, cls_name)
1495 for (i = 1 ; i < arguments.length ; i++) {
1496 if (! class_check(item, arguments[i])) {
1497 item.className = item.className + " " + arguments[i];
1502 function class_rem(item, cls_name)
1504 for (i = 1 ; i < arguments.length ; i++) {
1505 var item_spc = " " + item.className + " ";
1506 var cls_spc = " " + arguments[i] + " ";
1509 var pos = item_spc.indexOf(cls_spc);
1511 cls_out = item_spc.substring(0, pos) + item_spc.substring(pos + cls_spc.length - 1);
1512 if (cls_out == " ") {
1513 item.className = "";
1516 item.className = cls_out.substring(1, cls_out.length - 1);
1522 function class_subst(item, cls_out, cls_in)
1524 class_rem(item, cls_out);
1525 class_add(item, cls_in);
1528 function nexst(after)
1530 if (after != undefined) {
1531 this._after = after;
1535 nexst.next = function(st)
1537 if (st === null || st === undefined)
1544 nexst.prev = function(st)
1549 nexst.reprise = function ()
1551 var thiz, args_in, args = [];
1553 if (arguments.length > 1) {
1554 thiz = arguments[0];
1555 args_in = arguments[1];
1559 args_in = arguments[0];
1562 for (var i = 0 ; i < args_in.length ; i++) {
1563 args[i] = args_in[i];
1565 return args_in.callee.apply(thiz, args);
1569 _step: 0, // current step for the async multistep command
1570 _data: null, // data returned at the end of the async command
1571 _subst: null, // substatus for nested async command
1572 _after: null, // callback (as 'arguments' object) to run at the end
1575 step_set: function(step) {
1579 step_get: function() {
1583 data_set: function(data) {
1587 data_get: function() {
1591 subst_set: function(subst) {
1592 this._subst = subst;
1595 subst_get: function() {
1599 after_set: function(after) {
1600 this._after = after;
1603 after_get: function() {
1607 done_set: function() {
1611 done_get: function() {