4 * Copyright (C) 2006-2008 Matteo Nastasi
5 * mailto: nastasi@alternativeoutput.it
6 * matteo.nastasi@milug.org
7 * web: http://www.alternativeoutput.it
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program; if
19 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20 * Suite 330, Boston, MA 02111-1307, USA.
27 var EXIT_BAN_TIME = 900;
28 var cookiepath = "/brisk/";
30 var mlang_commons = { 'imgload_a' : { 'it' : 'Immagine 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.',
47 function $(id) { return document.getElementById(id); }
49 function getStyle(x,IEstyleProp, MozStyleProp)
52 var y = x.currentStyle[IEstyleProp];
53 } else if (window.getComputedStyle) {
54 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
59 /* replacement of setInterval on IE */
61 /*if not IE, do nothing*/
62 if(!document.uniqueID){return;};
64 /*Copy the default setInterval behavior*/
65 var nativeSetInterval = window.setInterval;
66 window.setInterval = function(fn,ms) {
68 if(arguments.length <= 2) {
69 return nativeSetInterval(fn,ms);
72 for(var i=2;i<arguments.length;i+=1) {
73 param[i-2] = arguments[i];
77 if(typeof(fn)=='function') {
79 return (function (fn,ms,param) {
80 var fo = function () {
81 fn.apply(window,param);
83 return nativeSetInterval(fo,ms);
86 else if(typeof(fn)=='string')
88 return nativeSetInterval(fn,ms);
92 throw Error('setInterval Error\nInvalid function type');
96 /*Copy the default setTimeout behavior*/
97 var nativeSetTimeout = window.setTimeout;
98 window.setTimeout = function(fn,ms) {
100 if(arguments.length <= 2) {
101 return nativeSetTimeout(fn,ms);
104 for(var i=2;i<arguments.length;i+=1) {
105 param[i-2] = arguments[i];
109 if(typeof(fn)=='function') {
111 return (function (fn,ms,param) {
112 var fo = function () {
113 fn.apply(window,param);
115 return nativeSetTimeout(fo,ms);
118 else if(typeof(fn)=='string')
120 return nativeSetTimeout(fn,ms);
124 throw Error('setTimeout Error\nInvalid function type');
130 function addEvent(obj,type,fn)
132 if (obj.addEventListener) {
133 obj.addEventListener( type, fn, false);
135 else if (obj.attachEvent) {
136 obj["e"+type+fn] = fn;
137 obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
138 obj.attachEvent( "on"+type, obj[type+fn] );
141 throw new Error("Event registration not supported");
144 function removeEvent(obj,type,fn)
146 if (obj.removeEventListener) {
147 obj.removeEventListener( type, fn, false );
149 else if (obj.detachEvent) {
150 obj.detachEvent( "on"+type, obj[type+fn] );
152 obj["e"+type+fn] = null;
156 // var card_pos = RANGE 0 <= x < cards_ea_n
158 function show_bigpict(obj, act, x, y)
162 if (arguments.length > 4)
167 big = $(obj.id+"_big"+sfx);
169 big.style.left = obj.offsetLeft + x+"px";
170 big.style.top = obj.offsetTop + y+"px";
171 big.style.visibility = "visible";
174 big.style.visibility = "hidden";
178 function rnd_int(min, max) {
179 return Math.floor(Math.random() * (max - min + 1) + min);
182 function error_images()
184 // alert("GHESEMU!");
185 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
188 function abort_images()
190 // alert("ABORTAIMAGES");
191 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
194 function unload_images()
196 // alert("ABORTAIMAGES");
197 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
200 function reset_images()
202 // alert("ABORTAIMAGES");
203 setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
206 function update_images()
208 // MLANG "Immagine caricate" + g_preload_imgsz_arr[g_imgct] + "%."
209 $("imgct").innerHTML = mlang_commons['imgload_a'][g_lang]+g_preload_imgsz_arr[g_imgct]+"%.";
210 if (g_imgct+1 < g_preload_img_arr.length) {
212 setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
214 // $("imgct").innerHTML += "U";
217 function preload_images(arr,idx)
221 // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
222 im.onload = update_images;
223 im.onerror = error_images;
224 im.onabort = abort_images;
225 im.onunload = unload_images;
226 im.onreset = reset_images;
228 // $("imgct").innerHTML += "P";
231 function safestatus(a)
239 function createXMLHttpRequest() {
240 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
241 try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
242 try { return new XMLHttpRequest(); } catch(e) {}
243 alert("XMLHttpRequest not supported");
247 function send_mesg(mesg)
249 var xhr_wr = createXMLHttpRequest();
250 var is_conn = (sess == "not_connected" ? false : true);
252 // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn);
253 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, (is_conn ? true : false));
254 xhr_wr.onreadystatechange = function() { return; };
255 if (typeof(console) == 'object') {
256 if (typeof(console.log) == 'function') {
257 var ldate = new Date();
258 console.log(ldate.getTime()+':MESG:'+mesg);
264 if (xhr_wr.responseText != null) {
265 eval(xhr_wr.responseText);
272 server_request([arg0=arg1[, arg2=arg3[, ...]]])
274 function server_request()
276 var xhr_wr = createXMLHttpRequest();
279 if (arguments.length > 0) {
280 for (i = 0 ; i < arguments.length ; i+= 2) {
281 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
284 // alert("Args: "+arguments.length);
286 var is_conn = (sess == "not_connected" ? false : true);
288 // console.log("server_request:preresp: "+xhr_wr.responseText);
290 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
291 xhr_wr.onreadystatechange = function() { return; };
294 if (xhr_wr.responseText != null) {
295 // console.log("server_request:resp: "+xhr_wr.responseText);
296 return (xhr_wr.responseText);
302 /* Stat: CHAT and TABLE */
304 function chatt_checksend(obj,e)
310 if(window.event) { // IE
313 else if(e.which) { // Netscape/Firefox/Opera
316 // alert("OBJ: "+obj);
317 if (keynum == 13 && obj.value != "") { // Enter
318 act_chatt(obj.value);
322 function act_chatt(value)
324 send_mesg("chatt|"+encodeURIComponent(value));
328 obj.disabled = false;
335 function act_sitdown(table)
337 send_mesg("sitdown|"+table);
340 function act_wakeup()
345 function act_splash()
355 function act_passwdhowto()
357 send_mesg("passwdhowto");
360 function act_mesgtoadm()
362 send_mesg("mesgtoadm");
367 act_chatt('/tav '+$('txt_in').value);
368 $('txt_in').value = '';
376 function act_placing()
378 send_mesg("placing");
381 function act_roadmap()
383 send_mesg("roadmap");
386 function act_whysupport()
388 send_mesg("whysupport");
391 function act_lascio()
396 function safelascio()
399 // MLANG "Sei sicuro di volere lasciare questa mano?"
400 res = window.confirm(mlang_commons['gamleav'][g_lang]);
405 function act_logout(exitlock)
407 send_mesg("logout|"+exitlock);
410 function act_reloadroom()
412 window.onunload = null;
413 window.onbeforeunload = null;
414 document.location.assign("index.php");
417 function act_shutdown()
421 send_mesg("shutdown");
422 // while (xhr_wr.readyState != 4)
426 function postact_logout()
428 // alert("postact_logout");
433 // eraseCookie("sess");
434 document.location.assign("index.php");
438 function slowimg(img,x1,y1,deltat,free,action,srcend)
440 x1,y1 - destination coords
441 deltat - time for each frame (in msec)
442 free - when the release the local block for other operations (range: 0 - 1)
443 action - function to run when the image is moved
444 srcend - image to switch when the image is moved
447 function sleep(st, delay)
449 // alert("LOC_NEW PRE: "+st.st_loc_new);
453 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
457 function slowimg(img,x1,y1,deltat,free,action,srcend) {
460 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
461 this.x0 = parseInt(getStyle(this.img,"left", "left"));
462 // alert("img.x0 = "+this.x0);
463 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
464 this.y0 = parseInt(getStyle(this.img,"top", "top"));
467 this.deltat = deltat;
469 this.action = action;
470 this.srcend = srcend;
473 slowimg.prototype = {
492 setstart: function(x0,y0)
498 setaction: function(act)
504 settime: function(time)
506 this.time = (time < this.deltat ? this.deltat : time);
507 this.step_n = parseInt(this.time / this.deltat);
508 this.dx = (this.x1 - this.x0) / this.step_n;
509 this.dy = (this.y1 - this.y0) / this.step_n;
510 if (this.step_n * this.deltat == this.time) {
514 this.step_free = parseInt(this.step_n * this.free);
520 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
522 this.st.st_loc_new++;
524 this.img.style.visibility = "visible";
525 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
530 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
531 if (this.step_cur == 0) {
532 var date = new Date();
533 // $("logz").innerHTML = "Timestart: " + date + "<br>";
535 if (this.step_cur <= this.step_n) {
536 this.img.style.left = this.x0 + this.dx * this.step_cur;
537 this.img.style.top = this.y0 + this.dy * this.step_cur;
539 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
540 if (this.step_cur == this.step_free && this.st != null) {
541 if (this.st.st_loc < this.st.st_loc_new) {
542 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
549 this.img.style.left = this.x1;
550 this.img.style.top = this.y1;
551 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
552 var date = new Date();
553 // $("logz").innerHTML += "Timestop: " + date + "<br>";
555 if (this.action != null) {
559 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
564 if (this.srcend != null) {
565 this.img.src = this.srcend;
571 function div_show(div)
573 div.style.top = parseInt((document.body.clientHeight - parseInt(getStyle(div,"height", "height"))) / 2) + document.body.scrollTop;
574 div.style.visibility = "visible";
577 function notify_ex(st, text, tout, butt, w, h, is_opa, block_time)
584 this.ancestor = document.body;
586 this.st.st_loc_new++;
588 clo = document.createElement("input");
590 clo.className = "button";
591 clo.style.bottom = "4px";
593 if (block_time > 0) {
594 clo.value = "leggere, prego.";
599 clo.onclick = this.input_hide;
602 clodiv = document.createElement("div");
603 clodiv.className = "notify_clo";
605 this.clodiv = clodiv;
607 clodiv.appendChild(clo);
609 cont = document.createElement("div");
611 cont.style.borderBottomStyle = "solid";
612 cont.style.borderBottomWidth = "1px";
613 cont.style.borderBottomColor = "gray";
614 cont.style.height = (h - 30)+"px";
615 cont.style.overflow = "auto";
616 cont.innerHTML = text;
618 box = document.createElement("div");
620 box.className = "notify_opaque";
622 box.className = "notify";
624 box.style.zIndex = 200;
625 box.style.width = w+"px";
626 box.style.marginLeft = -parseInt(w/2)+"px";
627 box.style.height = h+"px";
628 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
629 box.appendChild(cont);
630 box.appendChild(clodiv);
631 box.style.visibility = "visible";
635 this.ancestor.appendChild(box);
637 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
639 if (block_time != 0) {
640 this.tblkid = setTimeout(function(obj){ obj.clo.value = obj.butt; obj.clo.onclick = obj.input_hide; formsub_hilite(obj.clo); obj.clo.focus(); }, block_time, this);
650 notify_ex.prototype = {
662 if (this.st.st_loc < this.st.st_loc_new) {
669 clearTimeout(this.toutid);
670 this.ancestor.removeChild(this.notitag);
674 input_hide: function()
676 clearTimeout(this.obj.toutid);
677 this.obj.ancestor.removeChild(this.obj.notitag);
683 notify.prototype = notify_ex.prototype; // Define sub-class
684 notify.prototype.constructor = notify;
685 notify.baseConstructor = notify_ex;
686 notify.superClass = notify_ex.prototype;
688 function notify(st, text, tout, butt, w, h)
690 notify_ex.call(this, st, text, tout, butt, w, h, false, 0);
695 return document.getElementById(id);
701 this.st_loc_new = -1;
702 this.comms = new Array;
707 function remark_step()
709 var ct = $("remark").l_remct;
715 $("remark").className = "remark"+ct;
716 $("remark").l_remct = ct;
717 setTimeout(remark_step,500);
720 $("remark").className = "remark0";
727 if ($("remark").l_remct == 0) {
728 $("remark").l_remct = 1;
729 setTimeout(remark_step,500);
733 function remark_off()
735 $("remark").l_remct = 0;
736 $("remark").className = "remark0";
740 function italizer(ga)
744 return "<i>"+ga[1]+"</i>";
750 function exitlock_show(num, islock)
754 num = (num < 3 ? num : 3);
755 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
756 // alert("EXITLOCK: "+$("exitlock").src);
757 $("exitlock").style.visibility = "visible";
762 // exitlock_show(0, true);
765 var chatt_lines = new Array();
766 var chatt_lines_n = 0;
768 var CHATT_MAXLINES = 40;
771 function chatt_sub(dt,data,str)
773 var must_scroll = false;
780 name = "<i>"+data[1]+"</i>";
783 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
785 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
788 // alert("ARRIVA NAME: "+ name + " STR:"+str);
789 if (chatt_lines_n == CHATT_MAXLINES) {
790 $("txt").innerHTML = "";
791 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
792 chatt_lines[i] = chatt_lines[i+1];
793 $("txt").innerHTML += chatt_lines[i];
795 chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
796 $("txt").innerHTML += chatt_lines[i];
799 chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
800 $("txt").innerHTML += chatt_lines[chatt_lines_n];
803 // $("txt").innerHTML;
807 $("txt").scrollTop = 10000000;
809 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
813 * GESTIONE DEI COOKIES
815 function createCookie(name,value,hours,path) {
817 var date = new Date();
818 date.setTime(date.getTime()+(hours*60*60*1000));
819 var expires = "; expires="+date.toGMTString();
821 else var expires = "";
822 document.cookie = name+"="+value+expires+"; path="+path;
825 function readCookie(name) {
826 var nameEQ = name + "=";
827 var ca = document.cookie.split(';');
828 for(var i=0;i < ca.length;i++) {
830 while (c.charAt(0)==' ') c = c.substring(1,c.length);
831 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
836 function eraseCookie(name) {
837 createCookie(name,"",-1);
840 var onunload_times = 0;
843 function onbeforeunload_cb () {
847 function onunload_cb_old () {
850 // if (nonunload == true)
853 if (onunload_times == 0) {
854 // MLANG " Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)"
855 var res = window.confirm(mlang_commons['brileav'][g_lang]);
864 document.location.href = self.location; // = self.location;
865 // alert ("passiamo di qui"+self.location);
868 // MLANG "Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente."
869 alert(mlang_commons['brireco'][g_lang]);
878 function onunload_cb () {
888 function room_checkspace(emme,tables,inpe)
891 for (i = 0 ; i < emme ; i++)
896 for (i = 0 ; i < 5 ; i++)
899 for (i = 0 ; i < tables ; i++) {
900 $("table"+i).innerHTML = alta;
902 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
905 stand = "<table class=\"table_standup\"><tbody><tr>";
906 for (i = 0 ; i < inpe ; i++) {
907 stand += "<td>"+nome+"</td>";
908 if ((i+1) % 4 == 0) {
909 stand += "</tr><tr>";
913 $("standup").innerHTML = stand;
915 // VERIFY: what is this button ?
917 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
920 function unescapeHTML(cont) {
921 var div = document.createElement('div');
925 div.innerHTML = cont;
926 if (div.childNodes[0]) {
927 if (div.childNodes.length > 1) {
928 if (div.childNodes.toArray)
931 var length = div.childNodes.length, results = new Array(length);
933 results[length] = div.childNodes[length];
935 for (i=0 ; i<results.length ; i++)
936 memo = memo + results[i].nodeValue;
942 return (div.childNodes[0].nodeValue);
950 function playsound(tag, sound) {
951 // g_withflash is a global var
953 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
954 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
955 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
956 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
957 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
958 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
962 function topbanner_init()
964 setInterval(topbanner_cb, 666);
968 function topbanner_cb()
972 a = $('topbanner').style.backgroundColor;
973 b = $('topbanner').style.borderLeftColor;
975 $('topbanner').style.backgroundColor = b;
976 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
978 // console.log("A: "+a+" B: "+b);
981 function sidebanner_init()
983 setInterval(sidebanner_cb, 666);
986 function sidebanner2_init()
988 setInterval(sidebanner2_cb, 666);
991 function sidebanner_cb()
995 a = $('sidebanner').style.backgroundColor;
996 b = $('sidebanner').style.borderLeftColor;
998 $('sidebanner').style.backgroundColor = b;
999 $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
1001 // console.log("A: "+a+" B: "+b);
1004 function sidebanner2_cb()
1008 a = $('sidebanner2').style.backgroundColor;
1009 b = $('sidebanner2').style.borderLeftColor;
1011 $('sidebanner2').style.backgroundColor = b;
1012 $('sidebanner2').style.borderColor = a+" "+a+" "+a+" "+a;
1014 // console.log("A: "+a+" B: "+b);
1018 function langtolng(lang)
1026 function formtext_hilite(obj)
1028 obj.className = 'input_text';
1029 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
1030 addEvent(obj, "blur", function () { this.className = 'input_text'; });
1033 function formsub_hilite(obj)
1035 obj.className = 'input_sub';
1036 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1037 addEvent(obj, "blur", function () { this.className = 'input_sub'; });
1040 // return the value of the radio button that is checked
1041 // return an empty string if none are checked, or
1042 // there are no radio buttons
1043 function get_checked_value(radioObj) {
1046 var radioLength = radioObj.length;
1047 if(radioLength == undefined)
1048 if(radioObj.checked)
1049 return radioObj.value;
1052 for(var i = 0; i < radioLength; i++) {
1053 if(radioObj[i].checked) {
1054 return radioObj[i].value;
1060 // set the radio button with the given value as being checked
1061 // do nothing if there are no radio buttons
1062 // if the given value does not exist, all the radio buttons
1063 // are reset to unchecked
1064 function set_checked_value(radioObj, newValue) {
1067 var radioLength = radioObj.length;
1068 if(radioLength == undefined) {
1069 radioObj.checked = (radioObj.value == newValue.toString());
1072 for(var i = 0; i < radioLength; i++) {
1073 radioObj[i].checked = false;
1074 if(radioObj[i].value == newValue.toString()) {
1075 radioObj[i].checked = true;