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; };
258 if (xhr_wr.responseText != null) {
259 eval(xhr_wr.responseText);
264 function server_request()
266 var xhr_wr = createXMLHttpRequest();
269 if (arguments.length > 0) {
270 for (i = 0 ; i < arguments.length ; i+= 2) {
271 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
274 // alert("Args: "+arguments.length);
276 var is_conn = (sess == "not_connected" ? false : true);
278 // console.log("server_request:preresp: "+xhr_wr.responseText);
280 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
281 xhr_wr.onreadystatechange = function() { return; };
284 if (xhr_wr.responseText != null) {
285 // console.log("server_request:resp: "+xhr_wr.responseText);
286 return (xhr_wr.responseText);
292 /* Stat: CHAT and TABLE */
294 function chatt_checksend(obj,e)
300 if(window.event) { // IE
303 else if(e.which) { // Netscape/Firefox/Opera
306 // alert("OBJ: "+obj);
307 if (keynum == 13 && obj.value != "") { // Enter
308 act_chatt(obj.value);
312 function act_chatt(value)
314 send_mesg("chatt|"+encodeURIComponent(value));
318 obj.disabled = false;
325 function act_sitdown(table)
327 send_mesg("sitdown|"+table);
330 function act_wakeup()
335 function act_splash()
345 function act_passwdhowto()
347 send_mesg("passwdhowto");
350 function act_mesgtoadm()
352 send_mesg("mesgtoadm");
357 act_chatt('/tav '+$('txt_in').value);
358 $('txt_in').value = '';
366 function act_placing()
368 send_mesg("placing");
371 function act_roadmap()
373 send_mesg("roadmap");
376 function act_whysupport()
378 send_mesg("whysupport");
381 function act_lascio()
386 function safelascio()
389 // MLANG "Sei sicuro di volere lasciare questa mano?"
390 res = window.confirm(mlang_commons['gamleav'][g_lang]);
395 function act_logout(exitlock)
397 send_mesg("logout|"+exitlock);
400 function act_reloadroom()
402 window.onunload = null;
403 window.onbeforeunload = null;
404 document.location.assign("index.php");
407 function act_shutdown()
411 send_mesg("shutdown");
412 // while (xhr_wr.readyState != 4)
416 function postact_logout()
418 // alert("postact_logout");
423 // eraseCookie("sess");
424 document.location.assign("index.php");
428 function slowimg(img,x1,y1,deltat,free,action,srcend)
430 x1,y1 - destination coords
431 deltat - time for each frame (in msec)
432 free - when the release the local block for other operations (range: 0 - 1)
433 action - function to run when the image is moved
434 srcend - image to switch when the image is moved
437 function sleep(st, delay)
439 // alert("LOC_NEW PRE: "+st.st_loc_new);
443 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
447 function slowimg(img,x1,y1,deltat,free,action,srcend) {
450 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
451 this.x0 = parseInt(getStyle(this.img,"left", "left"));
452 // alert("img.x0 = "+this.x0);
453 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
454 this.y0 = parseInt(getStyle(this.img,"top", "top"));
457 this.deltat = deltat;
459 this.action = action;
460 this.srcend = srcend;
463 slowimg.prototype = {
482 setstart: function(x0,y0)
488 setaction: function(act)
494 settime: function(time)
496 this.time = (time < this.deltat ? this.deltat : time);
497 this.step_n = parseInt(this.time / this.deltat);
498 this.dx = (this.x1 - this.x0) / this.step_n;
499 this.dy = (this.y1 - this.y0) / this.step_n;
500 if (this.step_n * this.deltat == this.time) {
504 this.step_free = parseInt(this.step_n * this.free);
510 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
512 this.st.st_loc_new++;
514 this.img.style.visibility = "visible";
515 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
520 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
521 if (this.step_cur == 0) {
522 var date = new Date();
523 // $("logz").innerHTML = "Timestart: " + date + "<br>";
525 if (this.step_cur <= this.step_n) {
526 this.img.style.left = this.x0 + this.dx * this.step_cur;
527 this.img.style.top = this.y0 + this.dy * this.step_cur;
529 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
530 if (this.step_cur == this.step_free && this.st != null) {
531 if (this.st.st_loc < this.st.st_loc_new) {
532 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
539 this.img.style.left = this.x1;
540 this.img.style.top = this.y1;
541 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
542 var date = new Date();
543 // $("logz").innerHTML += "Timestop: " + date + "<br>";
545 if (this.action != null) {
549 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
554 if (this.srcend != null) {
555 this.img.src = this.srcend;
562 function notify_ex(st, text, tout, butt, w, h, is_opa, block_time)
569 this.ancestor = document.body;
571 this.st.st_loc_new++;
573 clo = document.createElement("input");
575 clo.className = "button";
576 clo.style.bottom = "4px";
578 if (block_time > 0) {
579 clo.value = "leggere, prego.";
584 clo.onclick = this.input_hide;
587 clodiv = document.createElement("div");
588 clodiv.className = "notify_clo";
590 this.clodiv = clodiv;
592 clodiv.appendChild(clo);
594 cont = document.createElement("div");
596 cont.style.borderBottomStyle = "solid";
597 cont.style.borderBottomWidth = "1px";
598 cont.style.borderBottomColor = "gray";
599 cont.style.height = (h - 30)+"px";
600 cont.style.overflow = "auto";
601 cont.innerHTML = text;
603 box = document.createElement("div");
605 box.className = "notify_opaque";
607 box.className = "notify";
609 box.style.zIndex = 200;
610 box.style.width = w+"px";
611 box.style.marginLeft = -parseInt(w/2)+"px";
612 box.style.height = h+"px";
613 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
614 box.appendChild(cont);
615 box.appendChild(clodiv);
616 box.style.visibility = "visible";
620 this.ancestor.appendChild(box);
622 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
624 if (block_time != 0) {
625 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);
635 notify_ex.prototype = {
647 if (this.st.st_loc < this.st.st_loc_new) {
654 clearTimeout(this.toutid);
655 this.ancestor.removeChild(this.notitag);
659 input_hide: function()
661 clearTimeout(this.obj.toutid);
662 this.obj.ancestor.removeChild(this.obj.notitag);
668 notify.prototype = notify_ex.prototype; // Define sub-class
669 notify.prototype.constructor = notify;
670 notify.baseConstructor = notify_ex;
671 notify.superClass = notify_ex.prototype;
673 function notify(st, text, tout, butt, w, h)
675 notify_ex.call(this, st, text, tout, butt, w, h, false, 0);
680 return document.getElementById(id);
686 this.st_loc_new = -1;
687 this.comms = new Array;
692 function remark_step()
694 var ct = $("remark").l_remct;
700 $("remark").className = "remark"+ct;
701 $("remark").l_remct = ct;
702 setTimeout(remark_step,500);
705 $("remark").className = "remark0";
712 if ($("remark").l_remct == 0) {
713 $("remark").l_remct = 1;
714 setTimeout(remark_step,500);
718 function remark_off()
720 $("remark").l_remct = 0;
721 $("remark").className = "remark0";
725 function italizer(ga)
729 return "<i>"+ga[1]+"</i>";
735 function exitlock_show(num, islock)
739 num = (num < 3 ? num : 3);
740 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
741 // alert("EXITLOCK: "+$("exitlock").src);
742 $("exitlock").style.visibility = "visible";
747 // exitlock_show(0, true);
750 var chatt_lines = new Array();
751 var chatt_lines_n = 0;
753 var CHATT_MAXLINES = 40;
756 function chatt_sub(dt,data,str)
758 var must_scroll = false;
765 name = "<i>"+data[1]+"</i>";
768 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
770 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
773 // alert("ARRIVA NAME: "+ name + " STR:"+str);
774 if (chatt_lines_n == CHATT_MAXLINES) {
775 $("txt").innerHTML = "";
776 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
777 chatt_lines[i] = chatt_lines[i+1];
778 $("txt").innerHTML += chatt_lines[i];
780 chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
781 $("txt").innerHTML += chatt_lines[i];
784 chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
785 $("txt").innerHTML += chatt_lines[chatt_lines_n];
788 // $("txt").innerHTML;
792 $("txt").scrollTop = 10000000;
794 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
798 * GESTIONE DEI COOKIES
800 function createCookie(name,value,hours,path) {
802 var date = new Date();
803 date.setTime(date.getTime()+(hours*60*60*1000));
804 var expires = "; expires="+date.toGMTString();
806 else var expires = "";
807 document.cookie = name+"="+value+expires+"; path="+path;
810 function readCookie(name) {
811 var nameEQ = name + "=";
812 var ca = document.cookie.split(';');
813 for(var i=0;i < ca.length;i++) {
815 while (c.charAt(0)==' ') c = c.substring(1,c.length);
816 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
821 function eraseCookie(name) {
822 createCookie(name,"",-1);
825 var onunload_times = 0;
828 function onbeforeunload_cb () {
832 function onunload_cb_old () {
835 // if (nonunload == true)
838 if (onunload_times == 0) {
839 // MLANG " Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)"
840 var res = window.confirm(mlang_commons['brileav'][g_lang]);
849 document.location.href = self.location; // = self.location;
850 // alert ("passiamo di qui"+self.location);
853 // MLANG "Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente."
854 alert(mlang_commons['brireco'][g_lang]);
863 function onunload_cb () {
873 function room_checkspace(emme,tables,inpe)
876 for (i = 0 ; i < emme ; i++)
881 for (i = 0 ; i < 5 ; i++)
884 for (i = 0 ; i < tables ; i++) {
885 $("table"+i).innerHTML = alta;
887 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
890 stand = "<table class=\"table_standup\"><tbody><tr>";
891 for (i = 0 ; i < inpe ; i++) {
892 stand += "<td>"+nome+"</td>";
893 if ((i+1) % 4 == 0) {
894 stand += "</tr><tr>";
898 $("standup").innerHTML = stand;
900 // VERIFY: what is this button ?
902 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
905 function unescapeHTML(cont) {
906 var div = document.createElement('div');
910 div.innerHTML = cont;
911 if (div.childNodes[0]) {
912 if (div.childNodes.length > 1) {
913 if (div.childNodes.toArray)
916 var length = div.childNodes.length, results = new Array(length);
918 results[length] = div.childNodes[length];
920 for (i=0 ; i<results.length ; i++)
921 memo = memo + results[i].nodeValue;
927 return (div.childNodes[0].nodeValue);
935 function playsound(tag, sound) {
936 // g_withflash is a global var
938 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
939 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
940 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
941 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
942 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
943 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
947 function topbanner_init()
949 setInterval(topbanner_cb, 666);
953 function topbanner_cb()
957 a = $('topbanner').style.backgroundColor;
958 b = $('topbanner').style.borderLeftColor;
960 $('topbanner').style.backgroundColor = b;
961 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
963 // console.log("A: "+a+" B: "+b);
966 function sidebanner_init()
968 setInterval(sidebanner_cb, 666);
971 function sidebanner2_init()
973 setInterval(sidebanner2_cb, 666);
976 function sidebanner_cb()
980 a = $('sidebanner').style.backgroundColor;
981 b = $('sidebanner').style.borderLeftColor;
983 $('sidebanner').style.backgroundColor = b;
984 $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
986 // console.log("A: "+a+" B: "+b);
989 function sidebanner2_cb()
993 a = $('sidebanner2').style.backgroundColor;
994 b = $('sidebanner2').style.borderLeftColor;
996 $('sidebanner2').style.backgroundColor = b;
997 $('sidebanner2').style.borderColor = a+" "+a+" "+a+" "+a;
999 // console.log("A: "+a+" B: "+b);
1003 function langtolng(lang)
1011 function formtext_hilite(obj)
1013 obj.className = 'input_text';
1014 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
1015 addEvent(obj, "blur", function () { this.className = 'input_text'; });
1018 function formsub_hilite(obj)
1020 obj.className = 'input_sub';
1021 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1022 addEvent(obj, "blur", function () { this.className = 'input_sub'; });