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_classific()
365 send_mesg("classific");
368 function act_roadmap()
370 send_mesg("roadmap");
373 function act_whysupport()
375 send_mesg("whysupport");
378 function act_lascio()
383 function safelascio()
386 // MLANG "Sei sicuro di volere lasciare questa mano?"
387 res = window.confirm(mlang_commons['gamleav'][g_lang]);
392 function act_logout(exitlock)
394 send_mesg("logout|"+exitlock);
397 function act_reloadroom()
399 window.onunload = null;
400 window.onbeforeunload = null;
401 document.location.assign("index.php");
404 function act_shutdown()
408 send_mesg("shutdown");
409 // while (xhr_wr.readyState != 4)
413 function postact_logout()
415 // alert("postact_logout");
420 // eraseCookie("sess");
421 document.location.assign("index.php");
425 function slowimg(img,x1,y1,deltat,free,action,srcend)
427 x1,y1 - destination coords
428 deltat - time for each frame (in msec)
429 free - when the release the local block for other operations (range: 0 - 1)
430 action - function to run when the image is moved
431 srcend - image to switch when the image is moved
434 function sleep(st, delay)
436 // alert("LOC_NEW PRE: "+st.st_loc_new);
440 setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
444 function slowimg(img,x1,y1,deltat,free,action,srcend) {
447 // this.x0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
448 this.x0 = parseInt(getStyle(this.img,"left", "left"));
449 // alert("img.x0 = "+this.x0);
450 // this.y0 = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
451 this.y0 = parseInt(getStyle(this.img,"top", "top"));
454 this.deltat = deltat;
456 this.action = action;
457 this.srcend = srcend;
460 slowimg.prototype = {
479 setstart: function(x0,y0)
485 setaction: function(act)
491 settime: function(time)
493 this.time = (time < this.deltat ? this.deltat : time);
494 this.step_n = parseInt(this.time / this.deltat);
495 this.dx = (this.x1 - this.x0) / this.step_n;
496 this.dy = (this.y1 - this.y0) / this.step_n;
497 if (this.step_n * this.deltat == this.time) {
501 this.step_free = parseInt(this.step_n * this.free);
507 // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
509 this.st.st_loc_new++;
511 this.img.style.visibility = "visible";
512 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
517 // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
518 if (this.step_cur == 0) {
519 var date = new Date();
520 // $("logz").innerHTML = "Timestart: " + date + "<br>";
522 if (this.step_cur <= this.step_n) {
523 this.img.style.left = this.x0 + this.dx * this.step_cur;
524 this.img.style.top = this.y0 + this.dy * this.step_cur;
526 setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
527 if (this.step_cur == this.step_free && this.st != null) {
528 if (this.st.st_loc < this.st.st_loc_new) {
529 // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
536 this.img.style.left = this.x1;
537 this.img.style.top = this.y1;
538 // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
539 var date = new Date();
540 // $("logz").innerHTML += "Timestop: " + date + "<br>";
542 if (this.action != null) {
546 if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
551 if (this.srcend != null) {
552 this.img.src = this.srcend;
559 function notify_ex(st, text, tout, butt, w, h, is_opa)
566 this.ancestor = document.body;
568 this.st.st_loc_new++;
570 clo = document.createElement("input");
572 clo.className = "button";
573 clo.style.bottom = "4px";
576 clo.onclick = this.input_hide;
578 clodiv = document.createElement("div");
579 clodiv.className = "notify_clo";
580 clodiv.appendChild(clo);
582 cont = document.createElement("div");
584 cont.style.borderBottomStyle = "solid";
585 cont.style.borderBottomWidth = "1px";
586 cont.style.borderBottomColor = "gray";
587 cont.style.height = (h - 30)+"px";
588 cont.style.overflow = "auto";
589 cont.innerHTML = text;
591 box = document.createElement("div");
593 box.className = "notify_opaque";
595 box.className = "notify";
597 box.style.zIndex = 200;
598 box.style.width = w+"px";
599 box.style.marginLeft = -parseInt(w/2)+"px";
600 box.style.height = h+"px";
601 box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
602 box.appendChild(cont);
603 box.appendChild(clodiv);
604 box.style.visibility = "visible";
608 this.ancestor.appendChild(box);
610 this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
618 notify_ex.prototype = {
626 if (this.st.st_loc < this.st.st_loc_new) {
633 clearTimeout(this.toutid);
634 this.ancestor.removeChild(this.notitag);
638 input_hide: function()
640 clearTimeout(this.obj.toutid);
641 this.obj.ancestor.removeChild(this.obj.notitag);
647 notify.prototype = notify_ex.prototype; // Define sub-class
648 notify.prototype.constructor = notify;
649 notify.baseConstructor = notify_ex;
650 notify.superClass = notify_ex.prototype;
652 function notify(st, text, tout, butt, w, h)
654 notify_ex.call(this, st, text, tout, butt, w, h, false);
659 return document.getElementById(id);
665 this.st_loc_new = -1;
666 this.comms = new Array;
671 function remark_step()
673 var ct = $("remark").l_remct;
679 $("remark").className = "remark"+ct;
680 $("remark").l_remct = ct;
681 setTimeout(remark_step,500);
684 $("remark").className = "remark0";
691 if ($("remark").l_remct == 0) {
692 $("remark").l_remct = 1;
693 setTimeout(remark_step,500);
697 function remark_off()
699 $("remark").l_remct = 0;
700 $("remark").className = "remark0";
704 function italizer(ga)
708 return "<i>"+ga[1]+"</i>";
714 function exitlock_show(num, islock)
718 num = (num < 3 ? num : 3);
719 $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
720 // alert("EXITLOCK: "+$("exitlock").src);
721 $("exitlock").style.visibility = "visible";
726 // exitlock_show(0, true);
729 var chatt_lines = new Array();
730 var chatt_lines_n = 0;
732 var CHATT_MAXLINES = 40;
735 function chatt_sub(dt,data,str)
737 var must_scroll = false;
744 name = "<i>"+data[1]+"</i>";
747 // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight);
749 if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) - $("txt").scrollHeight >= 0)
752 // alert("ARRIVA NAME: "+ name + " STR:"+str);
753 if (chatt_lines_n == CHATT_MAXLINES) {
754 $("txt").innerHTML = "";
755 for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
756 chatt_lines[i] = chatt_lines[i+1];
757 $("txt").innerHTML += chatt_lines[i];
759 chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
760 $("txt").innerHTML += chatt_lines[i];
763 chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
764 $("txt").innerHTML += chatt_lines[chatt_lines_n];
767 // $("txt").innerHTML;
771 $("txt").scrollTop = 10000000;
773 // alert("scTOP "+$("txt").scrollTop+" scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
777 * GESTIONE DEI COOKIES
779 function createCookie(name,value,hours,path) {
781 var date = new Date();
782 date.setTime(date.getTime()+(hours*60*60*1000));
783 var expires = "; expires="+date.toGMTString();
785 else var expires = "";
786 document.cookie = name+"="+value+expires+"; path="+path;
789 function readCookie(name) {
790 var nameEQ = name + "=";
791 var ca = document.cookie.split(';');
792 for(var i=0;i < ca.length;i++) {
794 while (c.charAt(0)==' ') c = c.substring(1,c.length);
795 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
800 function eraseCookie(name) {
801 createCookie(name,"",-1);
804 var onunload_times = 0;
807 function onbeforeunload_cb () {
811 function onunload_cb_old () {
814 // if (nonunload == true)
817 if (onunload_times == 0) {
818 // MLANG " Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)"
819 var res = window.confirm(mlang_commons['brileav'][g_lang]);
828 document.location.href = self.location; // = self.location;
829 // alert ("passiamo di qui"+self.location);
832 // MLANG "Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente."
833 alert(mlang_commons['brireco'][g_lang]);
842 function onunload_cb () {
852 function room_checkspace(emme,tables,inpe)
855 for (i = 0 ; i < emme ; i++)
860 for (i = 0 ; i < 5 ; i++)
863 for (i = 0 ; i < tables ; i++) {
864 $("table"+i).innerHTML = alta;
866 $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\" value=\""+mlang_commons['btn_sit'][g_lang]+"\" onclick=\"act_sitdown(1);\">";
869 stand = "<table class=\"table_standup\"><tbody><tr>";
870 for (i = 0 ; i < inpe ; i++) {
871 stand += "<td>"+nome+"</td>";
872 if ((i+1) % 4 == 0) {
873 stand += "</tr><tr>";
877 $("standup").innerHTML = stand;
879 // VERIFY: what is this button ?
881 $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\""+mlang_commons['btn_exit'][g_lang]+"\" onclick=\"act_logout();\" type=\"button\">";
884 function unescapeHTML(cont) {
885 var div = document.createElement('div');
889 div.innerHTML = cont;
890 if (div.childNodes[0]) {
891 if (div.childNodes.length > 1) {
892 if (div.childNodes.toArray)
895 var length = div.childNodes.length, results = new Array(length);
897 results[length] = div.childNodes[length];
899 for (i=0 ; i<results.length ; i++)
900 memo = memo + results[i].nodeValue;
906 return (div.childNodes[0].nodeValue);
914 function playsound(tag, sound) {
915 // g_withflash is a global var
917 $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
918 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
919 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
920 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
921 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
922 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
926 function topbanner_init()
928 setInterval(topbanner_cb, 666);
932 function topbanner_cb()
936 a = $('topbanner').style.backgroundColor;
937 b = $('topbanner').style.borderLeftColor;
939 $('topbanner').style.backgroundColor = b;
940 $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
942 // console.log("A: "+a+" B: "+b);
945 function sidebanner_init()
947 setInterval(sidebanner_cb, 666);
950 function sidebanner2_init()
952 setInterval(sidebanner2_cb, 666);
955 function sidebanner_cb()
959 a = $('sidebanner').style.backgroundColor;
960 b = $('sidebanner').style.borderLeftColor;
962 $('sidebanner').style.backgroundColor = b;
963 $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
965 // console.log("A: "+a+" B: "+b);
968 function sidebanner2_cb()
972 a = $('sidebanner2').style.backgroundColor;
973 b = $('sidebanner2').style.borderLeftColor;
975 $('sidebanner2').style.backgroundColor = b;
976 $('sidebanner2').style.borderColor = a+" "+a+" "+a+" "+a;
978 // console.log("A: "+a+" B: "+b);
982 function langtolng(lang)
990 function formtext_hilite(obj)
992 obj.className = 'input_text';
993 addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
994 addEvent(obj, "blur", function () { this.className = 'input_text'; });
997 function formsub_hilite(obj)
999 obj.className = 'input_sub';
1000 addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
1001 addEvent(obj, "blur", function () { this.className = 'input_sub'; });