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);
266 server_request([arg0=arg1[, arg2=arg3[, ...]]])
268 function server_request()
270 var xhr_wr = createXMLHttpRequest();
273 if (arguments.length > 0) {
274 for (i = 0 ; i < arguments.length ; i+= 2) {
275 collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
278 // alert("Args: "+arguments.length);
280 var is_conn = (sess == "not_connected" ? false : true);
282 // console.log("server_request:preresp: "+xhr_wr.responseText);
284 xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
285 xhr_wr.onreadystatechange = function() { return; };
288 if (xhr_wr.responseText != null) {
289 // console.log("server_request:resp: "+xhr_wr.responseText);
290 return (xhr_wr.responseText);
296 /* Stat: CHAT and TABLE */
298 function chatt_checksend(obj,e)
304 if(window.event) { // IE
307 else if(e.which) { // Netscape/Firefox/Opera
310 // alert("OBJ: "+obj);
311 if (keynum == 13 && obj.value != "") { // Enter
312 act_chatt(obj.value);
316 function act_chatt(value)
318 send_mesg("chatt|"+encodeURIComponent(value));
322 obj.disabled = false;
329 function act_sitdown(table)
331 send_mesg("sitdown|"+table);
334 function act_wakeup()
339 function act_splash()
349 function act_passwdhowto()
351 send_mesg("passwdhowto");
354 function act_mesgtoadm()
356 send_mesg("mesgtoadm");
361 act_chatt('/tav '+$('txt_in').value);
362 $('txt_in').value = '';
370 function act_placing()
372 send_mesg("placing");
375 function act_roadmap()
377 send_mesg("roadmap");
380 function act_whysupport()
382 send_mesg("whysupport");
385 function act_lascio()
390 function safelascio()
393 // MLANG "Sei sicuro di volere lasciare questa mano?"
394 res = window.confirm(mlang_commons['gamleav'][g_lang]);
399 function act_logout(exitlock)
401 send_mesg("logout|"+exitlock);
404 function act_reloadroom()
406 window.onunload = null;
407 window.onbeforeunload = null;
408 document.location.assign("index.php");
411 function act_shutdown()
415 send_mesg("shutdown");
416 // while (xhr_wr.readyState != 4)
420 function postact_logout()
422 // alert("postact_logout");
427 // eraseCookie("sess");
428 document.location.assign("index.php");
432 function slowimg(img,x1,y1,deltat,free,action,srcend)
434 x1,y1 - destination coords
435 deltat - time for each frame (in msec)
436 free - when the release the local block for other operations (range: 0 - 1)
437 action - function to run when the image is moved
438 srcend - image to switch when the image is moved
441 function sleep(st, delay)
443 // alert("LOC_NEW PRE: "+st.st_loc_new);
447 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
451 function slowimg(img,x1,y1,deltat,free,action,srcend) {
454 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
455 this.x0 = parseInt(getStyle(this.img,"left", "left"));
456 // alert("img.x0 = "+this.x0);
457 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
458 this.y0 = parseInt(getStyle(this.img,"top", "top"));
461 this.deltat = deltat;
463 this.action = action;
464 this.srcend = srcend;
467 slowimg.prototype = {
486 setstart: function(x0,y0)
492 setaction: function(act)
498 settime: function(time)
500 this.time = (time < this.deltat ? this.deltat : time);
501 this.step_n = parseInt(this.time / this.deltat);
502 this.dx = (this.x1 - this.x0) / this.step_n;
503 this.dy = (this.y1 - this.y0) / this.step_n;
504 if (this.step_n * this.deltat == this.time) {
508 this.step_free = parseInt(this.step_n * this.free);
514 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
516 this.st.st_loc_new++;
518 this.img.style.visibility = "visible";
519 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
524 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
525 if (this.step_cur == 0) {
526 var date = new Date();
527 // $("logz").innerHTML = "Timestart: " + date + "<br>";
529 if (this.step_cur <= this.step_n) {
530 this.img.style.left = this.x0 + this.dx * this.step_cur;
531 this.img.style.top = this.y0 + this.dy * this.step_cur;
533 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
534 if (this.step_cur == this.step_free && this.st != null) {
535 if (this.st.st_loc < this.st.st_loc_new) {
536 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
543 this.img.style.left = this.x1;
544 this.img.style.top = this.y1;
545 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
546 var date = new Date();
547 // $("logz").innerHTML += "Timestop: " + date + "<br>";
549 if (this.action != null) {
553 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
558 if (this.srcend != null) {
559 this.img.src = this.srcend;
565 function div_show(div)
567 div.style.top = parseInt((document.body.clientHeight - parseInt(getStyle(div,"height", "height"))) / 2) + document.body.scrollTop;
568 div.style.visibility = "visible";
571 function notify_ex(st, text, tout, butt, w, h, is_opa, block_time)
578 this.ancestor = document.body;
580 this.st.st_loc_new++;
582 clo = document.createElement("input");
584 clo.className = "button";
585 clo.style.bottom = "4px";
587 if (block_time > 0) {
588 clo.value = "leggere, prego.";
593 clo.onclick = this.input_hide;
596 clodiv = document.createElement("div");
597 clodiv.className = "notify_clo";
599 this.clodiv = clodiv;
601 clodiv.appendChild(clo);
603 cont = document.createElement("div");
605 cont.style.borderBottomStyle = "solid";
606 cont.style.borderBottomWidth = "1px";
607 cont.style.borderBottomColor = "gray";
608 cont.style.height = (h - 30)+"px";
609 cont.style.overflow = "auto";
610 cont.innerHTML = text;
612 box = document.createElement("div");
614 box.className = "notify_opaque";
616 box.className = "notify";
618 box.style.zIndex = 200;
619 box.style.width = w+"px";
620 box.style.marginLeft = -parseInt(w/2)+"px";
621 box.style.height = h+"px";
622 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
623 box.appendChild(cont);
624 box.appendChild(clodiv);
625 box.style.visibility = "visible";
629 this.ancestor.appendChild(box);
631 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
633 if (block_time != 0) {
634 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);
644 notify_ex.prototype = {
656 if (this.st.st_loc < this.st.st_loc_new) {
663 clearTimeout(this.toutid);
664 this.ancestor.removeChild(this.notitag);
668 input_hide: function()
670 clearTimeout(this.obj.toutid);
671 this.obj.ancestor.removeChild(this.obj.notitag);
677 notify.prototype = notify_ex.prototype; // Define sub-class
678 notify.prototype.constructor = notify;
679 notify.baseConstructor = notify_ex;
680 notify.superClass = notify_ex.prototype;
682 function notify(st, text, tout, butt, w, h)
684 notify_ex.call(this, st, text, tout, butt, w, h, false, 0);
689 return document.getElementById(id);
695 this.st_loc_new = -1;
696 this.comms = new Array;
701 function remark_step()
703 var ct = $("remark").l_remct;
709 $("remark").className = "remark"+ct;
710 $("remark").l_remct = ct;
711 setTimeout(remark_step,500);
714 $("remark").className = "remark0";
721 if ($("remark").l_remct == 0) {
722 $("remark").l_remct = 1;
723 setTimeout(remark_step,500);
727 function remark_off()
729 $("remark").l_remct = 0;
730 $("remark").className = "remark0";
734 function italizer(ga)
738 return "<i>"+ga[1]+"</i>";
744 function exitlock_show(num, islock)
748 num = (num < 3 ? num : 3);
749 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
750 // alert("EXITLOCK: "+$("exitlock").src);
751 $("exitlock").style.visibility = "visible";
756 // exitlock_show(0, true);
759 var chatt_lines = new Array();
760 var chatt_lines_n = 0;
762 var CHATT_MAXLINES = 40;
765 function chatt_sub(dt,data,str)
767 var must_scroll = false;
774 name = "<i>"+data[1]+"</i>";
777 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
779 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
782 // alert("ARRIVA NAME: "+ name + " STR:"+str);
783 if (chatt_lines_n == CHATT_MAXLINES) {
784 $("txt").innerHTML = "";
785 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
786 chatt_lines[i] = chatt_lines[i+1];
787 $("txt").innerHTML += chatt_lines[i];
789 chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
790 $("txt").innerHTML += chatt_lines[i];
793 chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
794 $("txt").innerHTML += chatt_lines[chatt_lines_n];
797 // $("txt").innerHTML;
801 $("txt").scrollTop = 10000000;
803 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
807 * GESTIONE DEI COOKIES
809 function createCookie(name,value,hours,path) {
811 var date = new Date();
812 date.setTime(date.getTime()+(hours*60*60*1000));
813 var expires = "; expires="+date.toGMTString();
815 else var expires = "";
816 document.cookie = name+"="+value+expires+"; path="+path;
819 function readCookie(name) {
820 var nameEQ = name + "=";
821 var ca = document.cookie.split(';');
822 for(var i=0;i < ca.length;i++) {
824 while (c.charAt(0)==' ') c = c.substring(1,c.length);
825 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
830 function eraseCookie(name) {
831 createCookie(name,"",-1);
834 var onunload_times = 0;
837 function onbeforeunload_cb () {
841 function onunload_cb_old () {
844 // if (nonunload == true)
847 if (onunload_times == 0) {
848 // MLANG " Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)"
849 var res = window.confirm(mlang_commons['brileav'][g_lang]);
858 document.location.href = self.location; // = self.location;
859 // alert ("passiamo di qui"+self.location);
862 // MLANG "Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente."
863 alert(mlang_commons['brireco'][g_lang]);
872 function onunload_cb () {
882 function room_checkspace(emme,tables,inpe)
885 for (i = 0 ; i < emme ; i++)
890 for (i = 0 ; i < 5 ; i++)
893 for (i = 0 ; i < tables ; i++) {
894 $("table"+i).innerHTML = alta;
896 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
899 stand = "<table class=\"table_standup\"><tbody><tr>";
900 for (i = 0 ; i < inpe ; i++) {
901 stand += "<td>"+nome+"</td>";
902 if ((i+1) % 4 == 0) {
903 stand += "</tr><tr>";
907 $("standup").innerHTML = stand;
909 // VERIFY: what is this button ?
911 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
914 function unescapeHTML(cont) {
915 var div = document.createElement('div');
919 div.innerHTML = cont;
920 if (div.childNodes[0]) {
921 if (div.childNodes.length > 1) {
922 if (div.childNodes.toArray)
925 var length = div.childNodes.length, results = new Array(length);
927 results[length] = div.childNodes[length];
929 for (i=0 ; i<results.length ; i++)
930 memo = memo + results[i].nodeValue;
936 return (div.childNodes[0].nodeValue);
944 function playsound(tag, sound) {
945 // g_withflash is a global var
947 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
948 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
949 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
950 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
951 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
952 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
956 function topbanner_init()
958 setInterval(topbanner_cb, 666);
962 function topbanner_cb()
966 a = $('topbanner').style.backgroundColor;
967 b = $('topbanner').style.borderLeftColor;
969 $('topbanner').style.backgroundColor = b;
970 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
972 // console.log("A: "+a+" B: "+b);
975 function sidebanner_init()
977 setInterval(sidebanner_cb, 666);
980 function sidebanner2_init()
982 setInterval(sidebanner2_cb, 666);
985 function sidebanner_cb()
989 a = $('sidebanner').style.backgroundColor;
990 b = $('sidebanner').style.borderLeftColor;
992 $('sidebanner').style.backgroundColor = b;
993 $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
995 // console.log("A: "+a+" B: "+b);
998 function sidebanner2_cb()
1002 a = $('sidebanner2').style.backgroundColor;
1003 b = $('sidebanner2').style.borderLeftColor;
1005 $('sidebanner2').style.backgroundColor = b;
1006 $('sidebanner2').style.borderColor = a+" "+a+" "+a+" "+a;
1008 // console.log("A: "+a+" B: "+b);
1012 function langtolng(lang)
1020 function formtext_hilite(obj)
1022 obj.className = 'input_text';
1023 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
1024 addEvent(obj, "blur", function () { this.className = 'input_text'; });
1027 function formsub_hilite(obj)
1029 obj.className = 'input_sub';
1030 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1031 addEvent(obj, "blur", function () { this.className = 'input_sub'; });
1034 // return the value of the radio button that is checked
1035 // return an empty string if none are checked, or
1036 // there are no radio buttons
1037 function get_checked_value(radioObj) {
1040 var radioLength = radioObj.length;
1041 if(radioLength == undefined)
1042 if(radioObj.checked)
1043 return radioObj.value;
1046 for(var i = 0; i < radioLength; i++) {
1047 if(radioObj[i].checked) {
1048 return radioObj[i].value;
1054 // set the radio button with the given value as being checked
1055 // do nothing if there are no radio buttons
1056 // if the given value does not exist, all the radio buttons
1057 // are reset to unchecked
1058 function set_checked_value(radioObj, newValue) {
1061 var radioLength = radioObj.length;
1062 if(radioLength == undefined) {
1063 radioObj.checked = (radioObj.value == newValue.toString());
1066 for(var i = 0; i < radioLength; i++) {
1067 radioObj[i].checked = false;
1068 if(radioObj[i].value == newValue.toString()) {
1069 radioObj[i].checked = true;