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()
342 function act_passwdhowto()
344 send_mesg("passwdhowto");
347 function act_mesgtoadm()
349 send_mesg("mesgtoadm");
354 act_chatt('/tav '+$('txt_in').value);
355 $('txt_in').value = '';
363 function act_roadmap()
365 send_mesg("roadmap");
368 function act_whysupport()
370 send_mesg("whysupport");
373 function act_lascio()
378 function safelascio()
381 // MLANG "Sei sicuro di volere lasciare questa mano?"
382 res = window.confirm(mlang_commons['gamleav'][g_lang]);
387 function act_logout(exitlock)
389 send_mesg("logout|"+exitlock);
392 function act_reloadroom()
394 window.onunload = null;
395 window.onbeforeunload = null;
396 document.location.assign("index.php");
399 function act_shutdown()
403 send_mesg("shutdown");
404 // while (xhr_wr.readyState != 4)
408 function postact_logout()
410 // alert("postact_logout");
415 // eraseCookie("sess");
416 document.location.assign("index.php");
420 function slowimg(img,x1,y1,deltat,free,action,srcend)
422 x1,y1 - destination coords
423 deltat - time for each frame (in msec)
424 free - when the release the local block for other operations (range: 0 - 1)
425 action - function to run when the image is moved
426 srcend - image to switch when the image is moved
429 function sleep(st, delay)
431 // alert("LOC_NEW PRE: "+st.st_loc_new);
435 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
439 function slowimg(img,x1,y1,deltat,free,action,srcend) {
442 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
443 this.x0 = parseInt(getStyle(this.img,"left", "left"));
444 // alert("img.x0 = "+this.x0);
445 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
446 this.y0 = parseInt(getStyle(this.img,"top", "top"));
449 this.deltat = deltat;
451 this.action = action;
452 this.srcend = srcend;
455 slowimg.prototype = {
474 setstart: function(x0,y0)
480 setaction: function(act)
486 settime: function(time)
488 this.time = (time < this.deltat ? this.deltat : time);
489 this.step_n = parseInt(this.time / this.deltat);
490 this.dx = (this.x1 - this.x0) / this.step_n;
491 this.dy = (this.y1 - this.y0) / this.step_n;
492 if (this.step_n * this.deltat == this.time) {
496 this.step_free = parseInt(this.step_n * this.free);
502 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
504 this.st.st_loc_new++;
506 this.img.style.visibility = "visible";
507 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
512 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
513 if (this.step_cur == 0) {
514 var date = new Date();
515 // $("logz").innerHTML = "Timestart: " + date + "<br>";
517 if (this.step_cur <= this.step_n) {
518 this.img.style.left = this.x0 + this.dx * this.step_cur;
519 this.img.style.top = this.y0 + this.dy * this.step_cur;
521 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
522 if (this.step_cur == this.step_free && this.st != null) {
523 if (this.st.st_loc < this.st.st_loc_new) {
524 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
531 this.img.style.left = this.x1;
532 this.img.style.top = this.y1;
533 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
534 var date = new Date();
535 // $("logz").innerHTML += "Timestop: " + date + "<br>";
537 if (this.action != null) {
541 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
546 if (this.srcend != null) {
547 this.img.src = this.srcend;
554 function notify(st, text, tout, butt, w, h)
561 this.ancestor = document.body;
563 this.st.st_loc_new++;
565 clo = document.createElement("input");
567 clo.className = "button";
568 clo.style.bottom = "4px";
571 clo.onclick = this.input_hide;
573 clodiv = document.createElement("div");
574 clodiv.className = "notify_clo";
575 clodiv.appendChild(clo);
577 cont = document.createElement("div");
579 cont.style.borderBottomStyle = "solid";
580 cont.style.borderBottomWidth = "1px";
581 cont.style.borderBottomColor = "gray";
582 cont.style.height = (h - 30)+"px";
583 cont.style.overflow = "auto";
584 cont.innerHTML = text;
586 box = document.createElement("div");
587 box.className = "notify";
588 box.style.zIndex = 200;
589 box.style.width = w+"px";
590 box.style.marginLeft = -parseInt(w/2)+"px";
591 box.style.height = h+"px";
592 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
593 box.appendChild(cont);
594 box.appendChild(clodiv);
595 box.style.visibility = "visible";
599 this.ancestor.appendChild(box);
601 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
616 if (this.st.st_loc < this.st.st_loc_new) {
623 clearTimeout(this.toutid);
624 this.ancestor.removeChild(this.notitag);
628 input_hide: function()
630 clearTimeout(this.obj.toutid);
631 this.obj.ancestor.removeChild(this.obj.notitag);
638 return document.getElementById(id);
644 this.st_loc_new = -1;
645 this.comms = new Array;
650 function remark_step()
652 var ct = $("remark").l_remct;
658 $("remark").className = "remark"+ct;
659 $("remark").l_remct = ct;
660 setTimeout(remark_step,500);
663 $("remark").className = "remark0";
670 if ($("remark").l_remct == 0) {
671 $("remark").l_remct = 1;
672 setTimeout(remark_step,500);
676 function remark_off()
678 $("remark").l_remct = 0;
679 $("remark").className = "remark0";
683 function italizer(ga)
687 return "<i>"+ga[1]+"</i>";
693 function exitlock_show(num, islock)
697 num = (num < 3 ? num : 3);
698 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
699 // alert("EXITLOCK: "+$("exitlock").src);
700 $("exitlock").style.visibility = "visible";
705 // exitlock_show(0, true);
708 var chatt_lines = new Array();
709 var chatt_lines_n = 0;
711 var CHATT_MAXLINES = 40;
714 function chatt_sub(dt,data,str)
716 var must_scroll = false;
723 name = "<i>"+data[1]+"</i>";
726 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
728 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
731 // alert("ARRIVA NAME: "+ name + " STR:"+str);
732 if (chatt_lines_n == CHATT_MAXLINES) {
733 $("txt").innerHTML = "";
734 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
735 chatt_lines[i] = chatt_lines[i+1];
736 $("txt").innerHTML += chatt_lines[i];
738 chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
739 $("txt").innerHTML += chatt_lines[i];
742 chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
743 $("txt").innerHTML += chatt_lines[chatt_lines_n];
746 // $("txt").innerHTML;
750 $("txt").scrollTop = 10000000;
752 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
756 * GESTIONE DEI COOKIES
758 function createCookie(name,value,hours,path) {
760 var date = new Date();
761 date.setTime(date.getTime()+(hours*60*60*1000));
762 var expires = "; expires="+date.toGMTString();
764 else var expires = "";
765 document.cookie = name+"="+value+expires+"; path="+path;
768 function readCookie(name) {
769 var nameEQ = name + "=";
770 var ca = document.cookie.split(';');
771 for(var i=0;i < ca.length;i++) {
773 while (c.charAt(0)==' ') c = c.substring(1,c.length);
774 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
779 function eraseCookie(name) {
780 createCookie(name,"",-1);
783 var onunload_times = 0;
786 function onbeforeunload_cb () {
790 function onunload_cb_old () {
793 // if (nonunload == true)
796 if (onunload_times == 0) {
797 // MLANG " Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)"
798 var res = window.confirm(mlang_commons['brileav'][g_lang]);
807 document.location.href = self.location; // = self.location;
808 // alert ("passiamo di qui"+self.location);
811 // MLANG "Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente."
812 alert(mlang_commons['brireco'][g_lang]);
821 function onunload_cb () {
831 function room_checkspace(emme,tables,inpe)
834 for (i = 0 ; i < emme ; i++)
839 for (i = 0 ; i < 5 ; i++)
842 for (i = 0 ; i < tables ; i++) {
843 $("table"+i).innerHTML = alta;
845 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
848 stand = "<table class=\"table_standup\"><tbody><tr>";
849 for (i = 0 ; i < inpe ; i++) {
850 stand += "<td>"+nome+"</td>";
851 if ((i+1) % 4 == 0) {
852 stand += "</tr><tr>";
856 $("standup").innerHTML = stand;
858 // VERIFY: what is this button ?
860 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
863 function unescapeHTML(cont) {
864 var div = document.createElement('div');
868 div.innerHTML = cont;
869 if (div.childNodes[0]) {
870 if (div.childNodes.length > 1) {
871 if (div.childNodes.toArray)
874 var length = div.childNodes.length, results = new Array(length);
876 results[length] = div.childNodes[length];
878 for (i=0 ; i<results.length ; i++)
879 memo = memo + results[i].nodeValue;
885 return (div.childNodes[0].nodeValue);
893 function playsound(tag, sound) {
894 // g_withflash is a global var
896 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
897 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
898 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
899 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
900 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
901 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
905 function topbanner_init()
907 setInterval(topbanner_cb, 666);
911 function topbanner_cb()
915 a = $('topbanner').style.backgroundColor;
916 b = $('topbanner').style.borderLeftColor;
918 $('topbanner').style.backgroundColor = b;
919 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
921 // console.log("A: "+a+" B: "+b);
924 function sidebanner_init()
926 setInterval(sidebanner_cb, 666);
929 function sidebanner2_init()
931 setInterval(sidebanner2_cb, 666);
934 function sidebanner_cb()
938 a = $('sidebanner').style.backgroundColor;
939 b = $('sidebanner').style.borderLeftColor;
941 $('sidebanner').style.backgroundColor = b;
942 $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
944 // console.log("A: "+a+" B: "+b);
947 function sidebanner2_cb()
951 a = $('sidebanner2').style.backgroundColor;
952 b = $('sidebanner2').style.borderLeftColor;
954 $('sidebanner2').style.backgroundColor = b;
955 $('sidebanner2').style.borderColor = a+" "+a+" "+a+" "+a;
957 // console.log("A: "+a+" B: "+b);
961 function langtolng(lang)
969 function formtext_hilite(obj)
971 obj.className = 'input_text';
972 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
973 addEvent(obj, "blur", function () { this.className = 'input_text'; });
976 function formsub_hilite(obj)
978 obj.className = 'input_sub';
979 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
980 addEvent(obj, "blur", function () { this.className = 'input_sub'; });