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 dec2hex(d, padding)
59 var hex = Number(d).toString(16);
60 padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
62 while (hex.length < padding) {
69 function ends_with(s, suffix)
71 if (s.indexOf(suffix, s.length - suffix.length) !== -1) {
77 function getStyle(x,IEstyleProp, MozStyleProp)
80 var y = x.currentStyle[IEstyleProp];
81 } else if (window.getComputedStyle) {
82 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
87 /* replacement of setInterval on IE */
89 /*if not IE, do nothing*/
90 if(!document.uniqueID){return;};
92 /*Copy the default setInterval behavior*/
93 var nativeSetInterval = window.setInterval;
94 window.setInterval = function(fn,ms) {
96 if(arguments.length <= 2) {
97 return nativeSetInterval(fn,ms);
100 for(var i=2;i<arguments.length;i+=1) {
101 param[i-2] = arguments[i];
105 if(typeof(fn)=='function') {
107 return (function (fn,ms,param) {
108 var fo = function () {
109 fn.apply(window,param);
111 return nativeSetInterval(fo,ms);
114 else if(typeof(fn)=='string')
116 return nativeSetInterval(fn,ms);
120 throw Error('setInterval Error\nInvalid function type');
124 /*Copy the default setTimeout behavior*/
125 var nativeSetTimeout = window.setTimeout;
126 window.setTimeout = function(fn,ms) {
128 if(arguments.length <= 2) {
129 return nativeSetTimeout(fn,ms);
132 for(var i=2;i<arguments.length;i+=1) {
133 param[i-2] = arguments[i];
137 if(typeof(fn)=='function') {
139 return (function (fn,ms,param) {
140 var fo = function () {
141 fn.apply(window,param);
143 return nativeSetTimeout(fo,ms);
146 else if(typeof(fn)=='string')
148 return nativeSetTimeout(fn,ms);
152 throw Error('setTimeout Error\nInvalid function type');
158 function addEvent(obj, type, fn)
160 if (obj.addEventListener) {
161 obj.addEventListener( type, fn, false);
163 else if (obj.attachEvent) {
164 obj["e"+type+fn] = fn;
165 obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
166 obj.attachEvent( "on"+type, obj[type+fn] );
169 throw new Error("Event registration not supported");
172 function removeEvent(obj,type,fn)
174 if (obj.removeEventListener) {
175 obj.removeEventListener( type, fn, false );
177 else if (obj.detachEvent) {
178 obj.detachEvent( "on"+type, obj[type+fn] );
180 obj["e"+type+fn] = null;
184 // var card_pos = RANGE 0 <= x < cards_ea_n
186 function show_bigpict(obj, act, x, y)
190 if (arguments.length > 4)
195 big = $(obj.id+"_big"+sfx);
197 big.style.left = obj.offsetLeft + x+"px";
198 big.style.top = obj.offsetTop + y+"px";
199 big.style.visibility = "visible";
202 big.style.visibility = "hidden";
206 function rnd_int(min, max) {
207 return Math.floor(Math.random() * (max - min + 1) + min);
210 function error_images()
212 // alert("GHESEMU!");
213 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
216 function abort_images()
218 // alert("ABORTAIMAGES");
219 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
222 function unload_images()
224 // alert("ABORTAIMAGES");
225 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
228 function reset_images()
230 // alert("ABORTAIMAGES");
231 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
234 function update_images()
236 // MLANG "Immagine caricate" + g_preload_imgsz_arr[g_imgct] + "%."
237 $("imgct").innerHTML = mlang_commons['imgload_a'][g_lang]+g_preload_imgsz_arr[g_imgct]+"%.";
238 if (g_imgct+1 < g_preload_img_arr.length) {
240 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
242 // $("imgct").innerHTML += "U";
245 function preload_images(arr,idx)
249 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
250 im.onload = update_images;
251 im.onerror = error_images;
252 im.onabort = abort_images;
253 im.onunload = unload_images;
254 im.onreset = reset_images;
256 // $("imgct").innerHTML += "P";
259 function safestatus(a)
267 function createXMLHttpRequest() {
268 if (typeof(ActiveXObject) != 'undefined') { // Konqueror complain as unknown object
269 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
270 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
272 try { return new XMLHttpRequest(); } catch(e) {}
273 alert("XMLHttpRequest not supported");
277 function send_mesg(mesg)
279 var xhr_wr = createXMLHttpRequest();
280 var is_conn = (sess == "not_connected" ? false : true);
282 // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn);
283 xhr_wr.open('GET', 'index_wr.php?&'+(is_conn ? 'sess='+sess : '')+'&stp='+gst.st+'&mesg='+mesg, (is_conn ? true : false));
284 xhr_wr.setRequestHeader("If-Modified-Since", new Date().toUTCString());
285 xhr_wr.onreadystatechange = function() { return; };
286 if (typeof(g_debug) == 'number' && g_debug > 0
287 && typeof(console) == 'object' && typeof(console.log) == 'function') {
288 var ldate = new Date();
289 console.log(ldate.getTime()+':MESG:'+mesg);
294 if (xhr_wr.responseText != null) {
295 eval(xhr_wr.responseText);
301 sync request to server
302 server_request([arg0=arg1[, arg2=arg3[, ...]]])
303 if var name == '__POST__' than all other vars will be managed as POST content
304 and the call will be a POST
306 function server_request(page, sess)
308 var xhr_wr = createXMLHttpRequest();
310 var i, collect = "", post_collect = null, is_post = false;
312 if (arguments.length > 0) {
313 for (i = 2 ; i < arguments.length ; i+= 2) {
314 if (arguments[i] == "__POST__") {
321 post_collect += (post_collect == "" ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
323 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
326 var uri = page + '?' + (sess != null ? 'sess=' + sess + '&' : '') + collect;
328 xhr_wr.open('POST', uri, false);
329 xhr_wr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
332 xhr_wr.open('GET', uri, false);
335 xhr_wr.timeout = tout;
338 xhr_wr.onreadystatechange = function() {
339 console.log('we are here');
341 xhr_wr.send(post_collect);
343 if (xhr_wr.responseText != null) {
344 // console.log("server_request:resp: "+xhr_wr.responseText);
345 return (xhr_wr.responseText);
352 function server_asyncreq(async_req, page, sess)
354 var xhr_wr = createXMLHttpRequest();
356 var i, collect = "", post_collect = null, is_post = false;
358 if (arguments.length > 0) {
359 for (i = 3 ; i < arguments.length ; i+= 2) {
360 if (arguments[i] == "__POST__") {
366 else if (arguments[i] == "__TOUT__") {
367 tout = arguments[i+1];
371 post_collect += (post_collect == "" ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
373 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
376 var already_quest = (page.indexOf('?') != -1);
377 var uri = page + (already_quest ? '&' : '?') + (sess != null ? 'sess=' + sess + '&' : '') + collect;
379 xhr_wr.open('POST', uri, true);
380 xhr_wr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
383 xhr_wr.open('GET', uri, true);
386 xhr_wr.timeout = tout;
389 xhr_wr.onreadystatechange = async_req;
390 xhr_wr.send(post_collect);
395 /* Stat: CHAT and TABLE */
397 function chatt_checksend(obj,e)
403 if(window.event) { // IE
406 else if(e.which) { // Netscape/Firefox/Opera
409 // alert("OBJ: "+obj);
410 if (keynum == 13 && obj.value != "") { // Enter
411 act_chatt(obj.value);
415 function act_chatt(value)
417 if (value.substring(0, 6) == "/info ") {
418 info_show(value.substring(6));
421 send_mesg("chatt|"+encodeURIComponent(value));
426 obj.disabled = false;
438 function act_sitdown(table)
440 send_mesg("sitdown|"+table);
443 function act_wakeup()
448 function act_splash()
458 function act_passwdhowto()
460 send_mesg("passwdhowto");
463 function act_mesgtoadm()
465 send_mesg("mesgtoadm");
470 act_chatt('/tav '+$('txt_in').value);
471 $('txt_in').value = '';
479 function act_placing()
481 send_mesg("placing");
484 function act_roadmap()
486 send_mesg("roadmap");
489 function act_lascio()
494 function safelascio()
497 // MLANG "Sei sicuro di volere lasciare questa mano?"
498 res = window.confirm(mlang_commons['gamleav'][g_lang]);
503 function act_logout(exitlock)
505 send_mesg("logout|"+exitlock);
508 function act_reloadroom()
510 window.onunload = null;
511 window.onbeforeunload = null;
512 document.location.assign("index.php");
515 function act_shutdown()
519 send_mesg("shutdown");
520 // while (xhr_wr.readyState != 4)
524 function postact_logout()
526 // alert("postact_logout");
531 // eraseCookie("sess");
532 document.location.assign("index.php");
536 type - 'hard' or 'soft'
537 code - if soft: accept (0), refuse (1), download (2), later (3)
538 if hard: accept (0), refuse (1), download (2)
540 function act_tosmgr(type, code, tos_curr, tos_vers)
542 if (type != "soft" && type != "hard") {
548 send_mesg("tosmgr|"+type+"|"+code+"|"+tos_curr+"|"+tos_vers);
559 function tos_confirm(val, url)
565 return (window.confirm(mlang_commons['tos_refu'][g_lang]));
568 dlm = new download_mgr(url);
578 function slowimg(img,x1,y1,deltat,free,action,srcend)
580 x1,y1 - destination coords
581 deltat - time for each frame (in msec)
582 free - when the release the local block for other operations (range: 0 - 1)
583 action - function to run when the image is moved
584 srcend - image to switch when the image is moved
587 function sleep(st, delay)
589 // alert("LOC_NEW PRE: "+st.st_loc_new);
593 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
597 function slowimg(img,x1,y1,deltat,free,action,srcend) {
600 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
601 this.x0 = parseInt(getStyle(this.img,"left", "left"));
602 // alert("img.x0 = "+this.x0);
603 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
604 this.y0 = parseInt(getStyle(this.img,"top", "top"));
607 this.deltat = deltat;
609 this.action = action;
610 this.srcend = srcend;
613 slowimg.prototype = {
632 setstart: function(x0,y0)
638 setaction: function(act)
644 settime: function(time)
646 this.time = (time < this.deltat ? this.deltat : time);
647 this.step_n = parseInt(this.time / this.deltat);
648 this.dx = (this.x1 - this.x0) / this.step_n;
649 this.dy = (this.y1 - this.y0) / this.step_n;
650 if (this.step_n * this.deltat == this.time) {
654 this.step_free = parseInt(this.step_n * this.free);
660 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
662 this.st.st_loc_new++;
664 this.img.style.visibility = "visible";
665 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
670 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
671 if (this.step_cur == 0) {
672 var date = new Date();
673 // $("logz").innerHTML = "Timestart: " + date + "<br>";
675 if (this.step_cur <= this.step_n) {
676 this.img.style.left = this.x0 + this.dx * this.step_cur;
677 this.img.style.top = this.y0 + this.dy * this.step_cur;
679 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
680 if (this.step_cur == this.step_free && this.st != null) {
681 if (this.st.st_loc < this.st.st_loc_new) {
682 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
689 this.img.style.left = this.x1;
690 this.img.style.top = this.y1;
691 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
692 var date = new Date();
693 // $("logz").innerHTML += "Timestop: " + date + "<br>";
695 if (this.action != null) {
699 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
704 if (this.srcend != null) {
705 this.img.src = this.srcend;
711 function div_show(div)
713 div.style.top = parseInt((document.body.clientHeight - parseInt(getStyle(div,"height", "height"))) / 2) + document.body.scrollTop;
714 div.style.visibility = "visible";
720 tout: if < 0 => infinite
728 function notify_document(st, text, tout, butt, confirm_func, confirm_func_args, w, h, is_opa, block_time)
730 var i, clo, clodiv_ctx, clodiv_wai, box;
734 this.ancestor = document.body;
735 this.confirm_func = confirm_func;
736 this.confirm_func_args = confirm_func_args;
737 this.st.st_loc_new++;
739 clodiv_ctx = document.createElement("div");
740 clodiv_ctx.className = "notify_clo";
742 for (i = 0 ; i < butt.length ; i++) {
743 this.input_add(butt[i], i, this.hide, clodiv_ctx);
746 if (block_time > 0) {
747 clodiv_wai = document.createElement("div");
748 clodiv_wai.className = "notify_clo";
750 this.input_add("leggere, prego.", 0, null, clodiv_wai);
751 this.clodiv = clodiv_wai;
752 this.clodiv_pkg = clodiv_ctx;
753 clodiv_ctx.style.display = 'none';
756 this.clodiv = clodiv_ctx;
759 cont = document.createElement("div");
761 cont.style.borderBottomStyle = "solid";
762 cont.style.borderBottomWidth = "1px";
763 cont.style.borderBottomColor = "gray";
764 cont.style.height = (h - 50)+"px";
765 cont.style.overflow = "auto";
766 cont.style.textAlign = "left";
767 cont.style.padding = "8px";
768 cont.style.fontFamily = "monospace";
769 cont.innerHTML = text;
771 box = document.createElement("div");
773 box.className = "notify_opaque";
775 box.className = "notify";
777 box.style.zIndex = 200;
778 box.style.width = w+"px";
779 box.style.marginLeft = -parseInt(w/2)+"px";
780 box.style.height = h+"px";
781 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
782 box.appendChild(cont);
783 box.appendChild(this.clodiv);
784 box.style.visibility = "visible";
788 this.ancestor.appendChild(box);
791 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
794 if (block_time != 0) {
795 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);
799 notify_document.prototype = {
813 confirm_func_args: [],
820 onclick_cb: name of the onclick callback (with signature f(idx) ) or null
821 anc: parent dom object
823 return new button dom object
825 input_add: function(s, idx, onclick_cb, anc)
829 clo = document.createElement("input");
831 clo.className = "button";
832 clo.style.bottom = "4px";
833 clo.style.margin = "2px";
838 clo.onclick = function () { onclick_cb.call(this.obj, this.obj_idx); };
841 anc.appendChild(clo);
848 // alert("quiz: "+this.rett);
854 if (this.st.st_loc < this.st.st_loc_new) {
861 if (this.confirm_func != null) {
864 args = [ val ].concat(this.confirm_func_args);
866 if (this.confirm_func.apply(null, args) == false) {
871 clearTimeout(this.toutid);
872 this.ancestor.removeChild(this.notitag);
880 function notify_ex(st, text, tout, butt, w, h, is_opa, block_time)
887 this.ancestor = document.body;
889 this.st.st_loc_new++;
891 clo = document.createElement("input");
893 clo.className = "button";
894 clo.style.bottom = "4px";
896 if (block_time > 0) {
897 clo.value = "leggere, prego.";
902 clo.onclick = function () { this.obj.hide() };
905 clodiv = document.createElement("div");
906 clodiv.className = "notify_clo";
908 this.clodiv = clodiv;
910 clodiv.appendChild(clo);
912 cont = document.createElement("div");
914 cont.style.borderBottomStyle = "solid";
915 cont.style.borderBottomWidth = "1px";
916 cont.style.borderBottomColor = "gray";
917 cont.style.height = (h - 30)+"px";
918 cont.style.overflow = "auto";
919 cont.innerHTML = text;
921 box = document.createElement("div");
923 box.className = "notify_opaque";
925 box.className = "notify";
927 box.style.zIndex = 200;
928 box.style.width = w+"px";
929 box.style.marginLeft = -parseInt(w/2)+"px";
930 box.style.height = h+"px";
931 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
932 box.appendChild(cont);
933 box.appendChild(clodiv);
934 box.style.visibility = "visible";
938 this.ancestor.appendChild(box);
940 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
942 if (block_time != 0) {
943 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);
953 notify_ex.prototype = {
965 if (this.st.st_loc < this.st.st_loc_new) {
972 clearTimeout(this.toutid);
973 this.ancestor.removeChild(this.notitag);
979 notify.prototype = notify_ex.prototype; // Define sub-class
980 notify.prototype.constructor = notify;
981 notify.baseConstructor = notify_ex;
982 notify.superClass = notify_ex.prototype;
984 function notify(st, text, tout, butt, w, h)
986 notify_ex.call(this, st, text, tout, butt, w, h, false, 0);
992 this.st_loc_new = -1;
993 this.comms = new Array;
1003 sleep: function(delay) {
1006 if (!this.the_end) {
1007 this.sleep_hdl = setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; obj.sleep_hdl = null; }},
1013 if (this.sleep_hdl != null) {
1014 clearTimeout(this.sleep_hdl);
1015 this.sleep_hdl = null;
1020 function remark_step()
1022 var ct = $("remark").l_remct;
1028 $("remark").className = "remark"+ct;
1029 $("remark").l_remct = ct;
1030 setTimeout(remark_step,500);
1033 $("remark").className = "remark0";
1038 function remark_on()
1040 if ($("remark").l_remct == 0) {
1041 $("remark").l_remct = 1;
1042 setTimeout(remark_step,500);
1046 function remark_off()
1048 $("remark").l_remct = 0;
1049 $("remark").className = "remark0";
1053 function italizer(ga)
1057 return "<i>"+ga[1]+"</i>";
1063 function exitlock_show(num, islock)
1067 num = (num < 3 ? num : 3);
1068 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
1069 // alert("EXITLOCK: "+$("exitlock").src);
1070 $("exitlock").style.visibility = "visible";
1075 // exitlock_show(0, true);
1078 var chatt_lines = new Array();
1079 var chatt_lines_n = 0;
1081 var CHATT_MAXLINES = 40;
1083 function user_decorator(user, is_real)
1085 var name, i, sp = "", cl = "";
1086 var flags = user[0] & 0x03 | ((user[0] & 0x0c0000) >> 16);
1088 // console.log(user[1]+" FLAGS: "+flags);
1090 for (i = 0 ; i < 4 ; i++) {
1091 if (flags & (1 << i)) {
1092 cl += sp + "au" + i + (is_real ? "" : "_off");
1098 name = "<span class='" + cl + "'><span class='" +
1099 (is_real && (flags & 0xfffffe && ((flags & 0x01) == 0)) ? "id_usr" : "") +
1100 "'>" + user[1] + "</span></span>";
1109 function user_dec_and_state(el)
1114 content = user_decorator(el, true);
1115 content += state_add(el[0],(typeof(el[2]) != 'undefined' ? el[2] : null));
1122 function chatt_sub(dt,data,str)
1124 var must_scroll = false;
1128 var bolder = [ (data[0] | 1), data[1] ];
1129 name = user_decorator(bolder, false);
1131 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
1134 // alert("ARRIVA NAME: "+ name + " STR:"+str);
1135 if (chatt_lines_n == CHATT_MAXLINES) {
1136 $("txt").innerHTML = "";
1137 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
1138 chatt_lines[i] = chatt_lines[i+1];
1139 $("txt").innerHTML += chatt_lines[i];
1141 chatt_lines[i] = dt+name+": "+str+ "<br>";
1142 $("txt").innerHTML += chatt_lines[i];
1145 chatt_lines[chatt_lines_n] = dt+name+": "+str+ "<br>";
1146 $("txt").innerHTML += chatt_lines[chatt_lines_n];
1149 // $("txt").innerHTML;
1153 $("txt").scrollTop = 10000000;
1155 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
1159 * GESTIONE DEI COOKIES
1161 function createCookie(name,value,hours,path) {
1163 var date = new Date();
1164 date.setTime(date.getTime()+(hours*60*60*1000));
1165 var expires = "; expires="+date.toGMTString();
1167 else var expires = "";
1168 document.cookie = name+"="+value+expires+"; path="+path;
1171 function readCookie(name) {
1172 var nameEQ = name + "=";
1173 var ca = document.cookie.split(';');
1174 for(var i=0;i < ca.length;i++) {
1176 while (c.charAt(0)==' ')
1177 c = c.substring(1,c.length);
1178 if (c.indexOf(nameEQ) == 0)
1179 return c.substring(nameEQ.length,c.length);
1184 function eraseCookie(name) {
1185 createCookie(name,"",-1);
1188 function onbeforeunload_cb () {
1192 function onunload_cb () {
1194 if (typeof(xstm) != "undefined")
1195 xstm.the_end = true;
1202 function room_checkspace(emme,tables,inpe)
1205 for (i = 0 ; i < emme ; i++)
1210 for (i = 0 ; i < 5 ; i++)
1211 alta += nome+"<br>";
1213 for (i = 0 ; i < tables ; i++) {
1214 $("table"+i).innerHTML = alta;
1216 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
1219 stand = "<table class=\"table_standup\"><tbody><tr>";
1220 for (i = 0 ; i < inpe ; i++) {
1221 stand += "<td>"+nome+"</td>";
1222 if ((i+1) % 4 == 0) {
1223 stand += "</tr><tr>";
1227 $("standup").innerHTML = stand;
1229 // VERIFY: what is this button ?
1231 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
1234 function unescapeHTML(cont) {
1235 var div = document.createElement('div');
1239 div.innerHTML = cont;
1240 if (div.childNodes[0]) {
1241 if (div.childNodes.length > 1) {
1242 if (div.childNodes.toArray)
1245 var length = div.childNodes.length, results = new Array(length);
1247 results[length] = div.childNodes[length];
1249 for (i=0 ; i<results.length ; i++)
1250 memo = memo + results[i].nodeValue;
1256 return (div.childNodes[0].nodeValue);
1264 function playsound(tag, sound) {
1265 // g_withflash is a global var
1267 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
1268 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
1269 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
1270 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
1271 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
1272 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
1276 function topbanner_init()
1278 setInterval(topbanner_cb, 666);
1282 function topbanner_cb()
1286 a = $('topbanner').style.backgroundColor;
1287 b = $('topbanner').style.borderLeftColor;
1289 $('topbanner').style.backgroundColor = b;
1290 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
1292 // console.log("A: "+a+" B: "+b);
1295 function sidebanner_init(idx)
1297 setInterval(function () { sidebanner_cb(idx); }, 666);
1300 function sidebanner_cb(idx)
1304 a = $('sidebanner'+idx).style.backgroundColor;
1305 b = $('sidebanner'+idx).style.borderLeftColor;
1307 $('sidebanner'+idx).style.backgroundColor = b;
1308 $('sidebanner'+idx).style.borderColor = a+" "+a+" "+a+" "+a;
1310 // console.log("A: "+a+" B: "+b);
1314 function langtolng(lang)
1322 function formtext_hilite(obj)
1324 obj.className = 'input_text';
1325 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
1326 addEvent(obj, "blur", function () { this.className = 'input_text'; });
1329 function formsub_hilite(obj)
1331 obj.className = 'input_sub';
1332 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1333 addEvent(obj, "blur", function () { this.className = 'input_sub'; });
1336 // return the value of the radio button that is checked
1337 // return an empty string if none are checked, or
1338 // there are no radio buttons
1339 function get_checked_value(radioObj) {
1342 var radioLength = radioObj.length;
1343 if(radioLength == undefined)
1344 if(radioObj.checked)
1345 return radioObj.value;
1348 for(var i = 0; i < radioLength; i++) {
1349 if(radioObj[i].checked) {
1350 return radioObj[i].value;
1356 // set the radio button with the given value as being checked
1357 // do nothing if there are no radio buttons
1358 // if the given value does not exist, all the radio buttons
1359 // are reset to unchecked
1360 function set_checked_value(radioObj, newValue) {
1363 var radioLength = radioObj.length;
1364 if(radioLength == undefined) {
1365 radioObj.checked = (radioObj.value == newValue.toString());
1368 for(var i = 0; i < radioLength; i++) {
1369 radioObj[i].checked = false;
1370 if(radioObj[i].value == newValue.toString()) {
1371 radioObj[i].checked = true;
1376 function url_append_arg(url, name, value)
1378 var pos, sep, pref, rest;
1380 if ((pos = url.indexOf('?'+name+'=')) == -1) {
1381 pos = url.indexOf('&'+name+'=');
1384 if ((pos = url.indexOf('?')) != -1)
1389 return (url+sep+name+"="+encodeURIComponent(value));
1392 pref = url.substring(0, pos+1);
1393 rest = url.substring(pos+1);
1394 // alert("rest: "+rest+" pos: "+pos);
1395 if ((pos = rest.indexOf('&')) != -1) {
1396 rest = rest.substring(pos);
1401 return (pref+name+"="+encodeURIComponent(value)+rest);
1405 function url_append_args(url)
1410 for (i = 1 ; i < arguments.length-1 ; i+= 2) {
1411 ret = url_append_arg(ret, arguments[i], arguments[i+1]);
1417 function url_complete(parent, url)
1420 var host = "", path = "";
1423 p = parent.indexOf("://");
1425 rest = parent.substring(p+3);
1426 p2 = rest.indexOf("/");
1428 host = parent.substring(0, p+3+p2);
1429 rest = parent.substring(p+3+p2);
1441 p = rest.lastIndexOf("/");
1443 path = rest.substring(0, p+1);
1446 // alert("host: ["+host+"] path: ["+path+"]");
1447 if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/' || url.substring(0,4) == 'ws:/') {
1450 else if (url.substring(0,1) == '/') {
1454 return (host+path+url);
1458 function download_mgr(url)
1462 if ((ifra = $('the_downloader')) == null) {
1463 ifra = document.createElement("iframe");
1464 ifra.style.display = "none";
1465 ifra.id = 'the_downloader';
1466 document.body.appendChild(ifra);
1469 ifra.contentWindow.location.href = url;
1474 download_mgr.prototype = {
1478 function submit_click(obj)
1480 obj.form.elements['realsub'].value = obj.id;
1483 function class_check(item, cls_name)
1485 if ((" " + item.className + " ").indexOf(" " + cls_name + " ") == -1)
1491 function class_add(item, cls_name)
1493 for (i = 1 ; i < arguments.length ; i++) {
1494 if (! class_check(item, arguments[i])) {
1495 item.className = item.className + " " + arguments[i];
1500 function class_rem(item, cls_name)
1502 for (i = 1 ; i < arguments.length ; i++) {
1503 var item_spc = " " + item.className + " ";
1504 var cls_spc = " " + arguments[i] + " ";
1507 var pos = item_spc.indexOf(cls_spc);
1509 cls_out = item_spc.substring(0, pos) + item_spc.substring(pos + cls_spc.length - 1);
1510 if (cls_out == " ") {
1511 item.className = "";
1514 item.className = cls_out.substring(1, cls_out.length - 1);
1520 function class_subst(item, cls_out, cls_in)
1522 class_rem(item, cls_out);
1523 class_add(item, cls_in);
1526 function nexst(after)
1528 if (after != undefined) {
1529 this._after = after;
1533 nexst.next = function(st)
1535 if (st === null || st === undefined)
1542 nexst.prev = function(st)
1547 nexst.reprise = function ()
1549 var thiz, args_in, args = [];
1551 if (arguments.length > 1) {
1552 thiz = arguments[0];
1553 args_in = arguments[1];
1557 args_in = arguments[0];
1560 for (var i = 0 ; i < args_in.length ; i++) {
1561 args[i] = args_in[i];
1563 return args_in.callee.apply(thiz, args);
1567 _step: 0, // current step for the async multistep command
1568 _data: null, // data returned at the end of the async command
1569 _subst: null, // substatus for nested async command
1570 _after: null, // callback (as 'arguments' object) to run at the end
1573 step_set: function(step) {
1577 step_get: function() {
1581 data_set: function(data) {
1585 data_get: function() {
1589 subst_set: function(subst) {
1590 this._subst = subst;
1593 subst_get: function() {
1597 after_set: function(after) {
1598 this._after = after;
1601 after_get: function() {
1605 done_set: function() {
1609 done_get: function() {