first commit
[threegates.git] / raw / root / var / www / onlycrs / commons.js
1 /*
2  *  brisk - commons.js
3  *
4  *  Copyright (C) 2006-2008 Matteo Nastasi
5  *                          mailto: nastasi@alternativeoutput.it 
6  *                                  matteo.nastasi@milug.org
7  *                          web: http://www.alternativeoutput.it
8  *
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.
13  *
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.
21  *
22  */
23
24 var PLAYERS_N = 3;
25 var EXIT_BAN_TIME = 900;
26 var cookiepath = "/trusty";
27
28 function $(id) { return document.getElementById(id); }
29
30 function getStyle(x,IEstyleProp, MozStyleProp) 
31 {
32     if (x.currentStyle) {
33         var y = x.currentStyle[IEstyleProp];
34     } else if (window.getComputedStyle) {
35         var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
36     }
37     return y;
38 }
39
40 /* replacement of setInterval on IE */
41 (function(){
42     /*if not IE, do nothing*/
43     if(!document.uniqueID){return;};
44
45     /*Copy the default setInterval behavior*/
46     var nativeSetInterval = window.setInterval;
47     window.setInterval = function(fn,ms) {              
48         var param = [];
49         if(arguments.length <= 2)       {
50             return nativeSetInterval(fn,ms);
51         }
52         else {
53             for(var i=2;i<arguments.length;i+=1) {
54                 param[i-2] =  arguments[i];
55             }   
56         }
57         
58         if(typeof(fn)=='function') {
59             
60             return (function (fn,ms,param) {
61                 var fo = function () {                                                          
62                     fn.apply(window,param);
63                 };                      
64                 return nativeSetInterval(fo,ms); 
65             })(fn,ms,param);
66         }
67         else if(typeof(fn)=='string')
68         {
69             return  nativeSetInterval(fn,ms);
70         }
71         else
72         {
73             throw Error('setInterval Error\nInvalid function type');
74         };
75     };
76
77     /*Copy the default setTimeout behavior*/
78     var nativeSetTimeout = window.setTimeout;
79     window.setTimeout = function(fn,ms) {               
80         var param = [];
81         if(arguments.length <= 2)       {
82             return nativeSetTimeout(fn,ms);
83         }
84         else {
85             for(var i=2;i<arguments.length;i+=1) {
86                 param[i-2] =  arguments[i];
87             }   
88         }
89         
90         if(typeof(fn)=='function') {
91             
92             return (function (fn,ms,param) {
93                 var fo = function () {                                                          
94                     fn.apply(window,param);
95                 };                      
96                 return nativeSetTimeout(fo,ms); 
97             })(fn,ms,param);
98         }
99         else if(typeof(fn)=='string')
100         {
101             return  nativeSetTimeout(fn,ms);
102         }
103         else
104         {
105             throw Error('setTimeout Error\nInvalid function type');
106         };
107     };
108
109 })()
110
111 function addEvent(obj,type,fn)
112 {
113     if (obj.addEventListener) {
114         obj.addEventListener( type, fn, false);
115     }
116     else if (obj.attachEvent) {
117         obj["e"+type+fn] = fn;
118         obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
119         obj.attachEvent( "on"+type, obj[type+fn] );
120     }
121     else
122         throw new Error("Event registration not supported");
123 }
124
125 function removeEvent(obj,type,fn)
126 {
127     if (obj.removeEventListener) {
128         obj.removeEventListener( type, fn, false );
129     }
130     else if (obj.detachEvent) {
131         obj.detachEvent( "on"+type, obj[type+fn] );
132         obj[type+fn] = null;
133         obj["e"+type+fn] = null;
134     }
135 }
136
137     // var card_pos = RANGE 0 <= x < cards_ea_n
138
139 function show_bigpict(obj, act, x, y)
140 {
141    var big, sfx;
142
143    if (arguments.length > 4)
144        sfx = arguments[4];
145    else
146        sfx = '';
147
148    big = $(obj.id+"_big"+sfx);
149    if (act == "over") {
150        big.style.left = obj.offsetLeft + x+"px";
151        big.style.top  = obj.offsetTop  + y+"px";
152        big.style.visibility = "visible";
153        }
154    else {
155        big.style.visibility = "hidden";
156        }
157 }
158
159 function rnd_int(min, max) {
160   return Math.floor(Math.random() * (max - min + 1) + min);
161 }
162
163 function error_images()
164 {
165     // alert("GHESEMU!");
166     setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
167 }
168
169 function abort_images()
170 {
171     // alert("ABORTAIMAGES");
172     setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
173 }
174
175 function unload_images()
176 {
177     // alert("ABORTAIMAGES");
178     setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
179 }
180
181 function reset_images()
182 {
183     // alert("ABORTAIMAGES");
184     setTimeout(preload_images, 2000, g_preload_img_arr, g_imgct-1);
185 }
186
187 function update_images()
188 {
189     //    if (g_imgct % 10 == 0) alert("g_imgct: "+g_imgct+" xx "+g_preload_img_arr[g_imgct]);
190     $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
191     if (g_imgct+1 < g_preload_img_arr.length) {
192         g_imgct++;
193         setTimeout(preload_images, 100, g_preload_img_arr, g_imgct-1);
194     }
195     // $("imgct").innerHTML += "U";
196 }
197
198 function preload_images(arr,idx)
199 {
200     var im = new Image;
201     
202     // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
203     im.onload =   update_images;
204     im.onerror =  error_images;
205     im.onabort =  abort_images;
206     im.onunload = unload_images;
207     im.onreset =  reset_images;
208     im.src =      arr[idx];
209     // $("imgct").innerHTML += "P";
210 }
211
212 function safestatus(a)
213 {
214     try{
215         return (a.status);
216     } catch(b)
217         { return (-1); }
218 }
219
220 function createXMLHttpRequest() {
221     try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
222     try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
223     try { return new XMLHttpRequest();                   } catch(e) {}
224     alert("XMLHttpRequest not supported");
225     return null;
226 }
227
228 function send_mesg(mesg)
229 {
230     var xhr_wr = createXMLHttpRequest();
231     var is_conn = (sess == "not_connected" ? false : true);
232     
233     // alert("xhr_wr: "+xhr_wr+"  is_conn: "+is_conn);
234     xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, (is_conn ? true : false));
235     xhr_wr.onreadystatechange = function() { return; };
236     xhr_wr.send(null);
237
238     if (!is_conn) {
239         if (xhr_wr.responseText != null) {
240             eval(xhr_wr.responseText);
241         }
242     }
243 }
244
245 function server_request()
246 {
247     var xhr_wr = createXMLHttpRequest();
248     var i, collect = "";
249
250     if (arguments.length > 0) {
251         for (i = 0 ; i < arguments.length ; i+= 2) {
252             collect += (i == 0 ? "" : "&") + arguments[i] + "=" + encodeURIComponent(arguments[i+1]);
253         }
254     }
255     // alert("Args: "+arguments.length);
256
257     var is_conn = (sess == "not_connected" ? false : true);
258     
259     // console.log("server_request:preresp: "+xhr_wr.responseText);
260
261     xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+collect, false);
262     xhr_wr.onreadystatechange = function() { return; };
263     xhr_wr.send(null);
264     
265     if (xhr_wr.responseText != null) {
266         // console.log("server_request:resp: "+xhr_wr.responseText);
267         return (xhr_wr.responseText);
268     } 
269     else
270         return (null);
271 }
272
273 /* Stat: CHAT and TABLE */
274
275 function chatt_checksend(obj,e)
276 {
277     var keynum;
278     var keychar;
279     var numcheck;
280
281     if(window.event) { // IE
282         keynum = e.keyCode;
283     }
284     else if(e.which) { // Netscape/Firefox/Opera
285         keynum = e.which;
286     }
287     // alert("OBJ: "+obj);
288     if (keynum == 13 && obj.value != "") { // Enter
289         act_chatt(obj.value);
290         obj.value = "";
291     }
292 }
293 function act_chatt(value)
294 {
295     send_mesg("chatt|"+encodeURIComponent(value));
296     /*
297     obj.disabled = true;
298     obj.value = "";
299     obj.disabled = false;
300     obj.focus();
301     */
302     return false;
303 }
304
305 /* Stat: ROOM */
306 function act_sitdown(table)
307 {
308     send_mesg("sitdown|"+table);
309 }
310
311 function act_wakeup()
312 {
313     send_mesg("wakeup");
314 }
315
316
317
318 function act_help()
319 {
320     send_mesg("help");
321 }
322
323 function act_tav()
324 {
325     act_chatt('/tav '+$('txt_in').value); 
326     $('txt_in').value = '';
327 }
328
329 function act_about()
330 {
331     send_mesg("about");
332 }
333
334 function act_roadmap()
335 {
336     send_mesg("roadmap");
337 }
338
339 function act_whysupport()
340 {
341     send_mesg("whysupport");
342 }
343
344 function act_lascio()
345 {
346     send_mesg("lascio");
347 }
348
349 function safelascio()
350 {
351     var res;
352
353     res = window.confirm("Sei sicuro di volere lasciare questa mano?");
354     if (res)
355         act_lascio();
356 }
357
358 function act_logout(exitlock)
359 {
360     send_mesg("logout|"+exitlock);
361 }
362
363 function act_reloadroom()
364 {
365     window.onunload = null;
366     window.onbeforeunload = null;
367     document.location.assign("index.php");
368 }
369
370 function act_shutdown()
371 {
372     var c = 0;
373
374     send_mesg("shutdown");
375     // while (xhr_wr.readyState != 4)
376     //  c++;
377 }
378
379 function postact_logout()
380 {
381     // alert("postact_logout");
382     try { 
383         xhr_rd.abort();
384     } catch (e) {}
385
386     // eraseCookie("sess");
387     document.location.assign("index.php");
388 }
389
390 /*
391   function slowimg(img,x1,y1,deltat,free,action,srcend)
392   img    - image to move
393   x1,y1  - destination coords
394   deltat - time for each frame (in msec)
395   free   - when the release the local block for other operations (range: 0 - 1)
396   action - function to run when the image is moved
397   srcend - image to switch when the image is moved
398 */
399
400 function sleep(st, delay)
401 {
402     // alert("LOC_NEW PRE: "+st.st_loc_new);
403
404     st.st_loc_new++;
405
406     setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
407                delay, st);
408 }
409
410 function slowimg(img,x1,y1,deltat,free,action,srcend) {
411     this.img = img;
412
413     // this.x0  = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("left"));
414     this.x0 = parseInt(getStyle(this.img,"left", "left"));
415 // alert("img.x0 = "+this.x0);
416     // this.y0  = parseInt(document.defaultView.getComputedStyle(this.img, "").getPropertyValue("top"));
417     this.y0  = parseInt(getStyle(this.img,"top", "top"));
418     this.x1  = x1;
419     this.y1  = y1;
420     this.deltat = deltat;
421     this.free = free;
422     this.action = action;
423     this.srcend = srcend;
424 }
425
426 slowimg.prototype = {
427     img: null, 
428     st: null,
429     x0: 0,
430     y0: 0,
431     x1: 0,
432     y1: 0,
433     dx: 0,
434     dy: 0,
435     free: 0,
436     step_n:    0,
437     step_cur:  0,
438     step_free: 0,
439     time:      0,
440     deltat:   40,
441     tout: 0,
442     action: null,
443     srcend: null,
444     
445     setstart: function(x0,y0)
446     {
447         this.x0 = x0;
448         this.y0 = y0;
449     },
450     
451     setaction: function(act)
452     {
453         this.action = act;
454     },
455     
456
457     settime: function(time) 
458     {
459         this.time = (time < this.deltat ? this.deltat : time);
460         this.step_n = parseInt(this.time / this.deltat);
461         this.dx = (this.x1 - this.x0) / this.step_n;
462         this.dy = (this.y1 - this.y0) / this.step_n;
463         if (this.step_n * this.deltat == this.time) {
464             this.step_n--;
465         }
466         if (this.free < 1) {
467             this.step_free = parseInt(this.step_n * this.free);
468         }
469     },
470     
471     start: function(st)
472     {
473         // $("logz").innerHTML += "               xxxxxxxxxxxxxxxxxxxxxSTART<br>";
474         this.st = st;
475         this.st.st_loc_new++;
476         
477         this.img.style.visibility = "visible";
478         setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
479     },
480     
481     animate: function()
482     {
483         // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
484         if (this.step_cur == 0) {
485             var date = new Date();
486             // $("logz").innerHTML = "Timestart: " + date + "<br>";
487         }
488         if (this.step_cur <= this.step_n) {
489             this.img.style.left = this.x0 + this.dx * this.step_cur;
490             this.img.style.top  = this.y0 + this.dy * this.step_cur;
491             this.step_cur++;
492             setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
493             if (this.step_cur == this.step_free && this.st != null) {
494                 if (this.st.st_loc < this.st.st_loc_new) {
495                     // alert("QUI1  " + this.step_cur + "  ZZ  "+  this.step_free);
496                     this.st.st_loc++;
497                     this.st = null;
498                 }
499             }
500         }
501         else {
502             this.img.style.left = this.x1;
503             this.img.style.top  = this.y1;
504             // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
505             var date = new Date();
506             // $("logz").innerHTML += "Timestop: " + date + "<br>";
507
508             if (this.action != null) {
509                 eval(this.action);
510             }
511
512             if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
513                 // alert("QUI2");
514                 this.st.st_loc++;
515                 this.st = null;
516             }
517             if (this.srcend != null) {
518                 this.img.src = this.srcend;
519             }
520         }
521     }
522 }
523
524
525 function notify(st, text, tout, butt, w, h)
526 {
527     var clo, box;
528     var t = this;
529     
530     this.st = st;
531
532     this.ancestor = document.body;
533
534     if (this.st)
535         this.st.st_loc_new++;
536
537     clo = document.createElement("input");
538     clo.type = "submit";
539     clo.className = "button";
540     clo.style.bottom = "4px";
541     clo.value = butt;
542     clo.obj = this;
543     clo.onclick = this.input_hide;
544     
545     clodiv = document.createElement("div");
546     clodiv.className = "notify_clo";
547     clodiv.appendChild(clo);
548
549     cont = document.createElement("div");
550
551     cont.style.borderBottomStyle = "solid";
552     cont.style.borderBottomWidth = "1px";
553     cont.style.borderBottomColor = "gray";
554     cont.style.height = (h - 30)+"px";
555     cont.style.overflow = "auto";
556     cont.innerHTML = text;
557
558     box =  document.createElement("div");
559     box.className = "notify";
560     box.style.zIndex = 200;
561     box.style.width  = w+"px";
562     box.style.marginLeft  = -parseInt(w/2)+"px";
563     box.style.height = h+"px";
564     box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
565     box.appendChild(cont);
566     box.appendChild(clodiv);
567     box.style.visibility = "visible";
568
569     this.notitag = box;
570     
571     this.ancestor.appendChild(box);
572     
573     this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
574
575     formsub_hilite(clo);
576     clo.focus();
577
578 }
579
580 notify.prototype = {
581     ancestor: null,
582     st: null,
583     notitag: null,
584     toutid: null,
585     
586     unblock: function()
587     {
588         if (this.st) {
589             if (this.st.st_loc < this.st.st_loc_new) {
590                 this.st.st_loc++;
591             }
592         }
593     },
594     
595     hide: function()
596     {
597         clearTimeout(this.toutid);
598         this.ancestor.removeChild(this.notitag);
599         this.unblock();
600     },
601
602     input_hide: function()
603     {
604         clearTimeout(this.obj.toutid);
605         this.obj.ancestor.removeChild(this.obj.notitag);
606         this.obj.unblock();
607     }
608 }
609         
610
611 function $(id) { 
612     return document.getElementById(id); 
613 }
614
615 function globst() {
616     this.st = -1;
617     this.st_loc = -1;
618     this.st_loc_new = -1;
619     this.comms  = new Array;
620 }
621
622
623
624 function remark_step()
625 {
626     var ct = $("remark").l_remct;
627     
628     if (ct != 0) {
629         ct++;
630         if (ct > 2)
631             ct = 1;
632         $("remark").className = "remark"+ct;
633         $("remark").l_remct = ct;
634         setTimeout(remark_step,500);
635     }
636     else
637         $("remark").className = "remark0";
638     
639     return;
640 }
641
642 function remark_on()
643 {
644     if ($("remark").l_remct == 0) {
645         $("remark").l_remct = 1;
646         setTimeout(remark_step,500);
647     }
648 }
649
650 function remark_off()
651 {
652     $("remark").l_remct = 0;
653     $("remark").className = "remark0";
654 }
655
656
657 function italizer(ga)
658 {
659     var pre, pos;
660     if (ga[0] & 2) 
661         return "<i>"+ga[1]+"</i>";
662     else
663         return ga[1];
664 }
665
666
667 function exitlock_show(num, islock)
668 {
669     g_exitlock = num;
670
671     num = (num < 3 ? num : 3);
672     $("exitlock").src = "img/exitlock"+num+(islock ? "n" : "y")+".png";
673     // alert("EXITLOCK: "+$("exitlock").src);
674     $("exitlock").style.visibility = "visible";
675 }
676
677 var fin = 0;
678
679 //    exitlock_show(0, true);
680
681
682 var chatt_lines = new Array();
683 var chatt_lines_n = 0;
684
685 var CHATT_MAXLINES = 40;
686
687 /* PRO CHATT */
688 function chatt_sub(dt,data,str)
689 {
690     var must_scroll = false;
691     var name;
692     var flags;
693     var isauth;
694
695     flags = data[0];
696     if (flags & 0x02)
697         name = "<i>"+data[1]+"</i>";
698     else
699         name = data[1];
700     // alert ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) -  $("txt").scrollHeight);
701
702   if ($("txt").scrollTop + parseInt(getStyle($("txt"),"height", "height")) -  $("txt").scrollHeight >= 0)
703       must_scroll = true;
704
705   // alert("ARRIVA NAME: "+ name + "  STR:"+str);
706   if (chatt_lines_n == CHATT_MAXLINES) {
707     $("txt").innerHTML = "";
708     for (i = 0 ; i < (CHATT_MAXLINES - 1) ; i++) {
709       chatt_lines[i] = chatt_lines[i+1];
710       $("txt").innerHTML += chatt_lines[i];
711     }
712     chatt_lines[i] = dt+"<b>"+name+"</b> "+str+ "<br>";
713     $("txt").innerHTML += chatt_lines[i];
714   }
715   else {
716     chatt_lines[chatt_lines_n] = dt+"<b>"+name+"</b> "+str+ "<br>";
717     $("txt").innerHTML += chatt_lines[chatt_lines_n];
718     chatt_lines_n++;
719   }
720   // $("txt").innerHTML;
721
722
723   if (must_scroll) {
724       $("txt").scrollTop = 10000000;
725   }
726   // alert("scTOP "+$("txt").scrollTop+"  scHEIGHT: "+$("txt").scrollHeight+" HEIGHT: "+getStyle($("txt"),"height", "height") );
727 }
728
729 /*
730  *  GESTIONE DEI COOKIES
731  */
732 function createCookie(name,value,hours,path) {
733         if (hours) {
734                 var date = new Date();
735                 date.setTime(date.getTime()+(hours*60*60*1000));
736                 var expires = "; expires="+date.toGMTString();
737         }
738         else var expires = "";
739         document.cookie = name+"="+value+expires+"; path="+path;
740 }
741
742 function readCookie(name) {
743         var nameEQ = name + "=";
744         var ca = document.cookie.split(';');
745         for(var i=0;i < ca.length;i++) {
746                 var c = ca[i];
747                 while (c.charAt(0)==' ') c = c.substring(1,c.length);
748                 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
749         }
750         return null;
751 }
752
753 function eraseCookie(name) {
754         createCookie(name,"",-1);
755 }
756
757 var onunload_times = 0;
758
759
760 function onbeforeunload_cb () {
761     return("");
762 }
763
764 function onunload_cb_old () {
765     var u = 0;
766     
767     //    if (nonunload == true)
768     //     return true;
769     
770     if (onunload_times == 0) {
771         var res = window.confirm("    Vuoi veramente abbandonare la briscola ?\n(clicca annulla o cancel se vuoi ricaricare la briscola)");
772         if (res == true) {
773             the_end = true; 
774             act_shutdown();
775             // while (1) 
776             //  u++;
777         }
778         else {
779             try {
780                 document.location.href = self.location; //  = self.location;
781                 // alert ("passiamo di qui"+self.location);
782                 return (false);
783             } catch (e) {
784                 alert("Ripristino della briscola fallito, per non perdere la sessione ricaricare la pagina manualmente.");
785             }
786         }
787         onunload_times++;
788     }
789     
790     return(false);
791 }
792
793 function onunload_cb () {
794     
795     the_end = true; 
796
797     act_shutdown();
798     
799     return(false);
800 }
801
802
803 function room_checkspace(emme,tables,inpe)
804 {
805     nome = "<b>";
806     for (i = 0 ; i < emme ; i++) 
807         nome += "m";
808     nome += "</b>";
809
810     alta = "";
811     for (i = 0 ; i < 5 ; i++) 
812         alta += nome+"<br>";
813
814     for (i = 0 ; i < tables ; i++) {
815         $("table"+i).innerHTML = alta;
816         $("table_act"+i).innerHTML = "<input type=\"button\" class=\"button\" name=\"xhenter"+i+"\"  value=\"Mi siedo.\" onclick=\"act_sitdown(1);\">";
817         }
818
819     stand = "<table class=\"table_standup\"><tbody><tr>";
820     for (i = 0 ; i < inpe ; i++) {
821         stand += "<td>"+nome+"</td>";
822         if ((i+1) % 4 == 0) {
823             stand += "</tr><tr>";
824         }
825     }
826     stand += "</tr>";
827     $("standup").innerHTML = stand;
828
829     // VERIFY: what is this button ?
830     $("esco").innerHTML = "<input class=\"button\" name=\"logout\" type=\"button\" value=\"Esco.\" onclick=\"act_logout();\" type=\"button\">";
831 }
832
833 function  unescapeHTML(cont) {
834     var div = document.createElement('div');
835     var memo = "";
836     var i;
837
838     div.innerHTML = cont;
839     if (div.childNodes[0]) {
840         if (div.childNodes.length > 1) {
841             if (div.childNodes.toArray)
842                 alert("si puo");
843             else {
844                 var length = div.childNodes.length, results = new Array(length);
845             while (length--)
846                 results[length] = div.childNodes[length];
847                 
848             for (i=0 ; i<results.length ; i++)
849                 memo = memo + results[i].nodeValue;
850             }
851
852             return (memo);
853         }
854         else {
855             return (div.childNodes[0].nodeValue);
856         }
857     }
858     else {
859         return ('');
860     }
861 }
862
863 function playsound(tag, sound) {
864    // g_withflash is a global var
865    if (g_withflash) {
866       $(tag).innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
867 'codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="mysound" WIDTH=1 HEIGHT=1>' +
868 '<PARAM NAME="movie" VALUE="../playsound.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="false">' +
869 '<PARAM NAME=FlashVars VALUE="streamUrl='+sound+'">' +
870 '<EMBED swliveconnect="true" name="mysound" src="../playsound.swf" FlashVars="streamUrl='+sound+'" PLAY="true" LOOP="false" '+
871 ' WIDTH=1 HEIGHT=1 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></OBJECT>';
872    }
873 }
874
875 function topbanner_init()
876 {
877     setInterval(topbanner_cb, 666);
878 ;
879 }
880
881 function topbanner_cb()
882 {
883     var a, b;
884
885     a = $('topbanner').style.backgroundColor;
886     b = $('topbanner').style.borderLeftColor;
887
888     $('topbanner').style.backgroundColor = b;
889     $('topbanner').style.borderColor = a+" "+a+" "+a+" "+a;
890
891     // console.log("A: "+a+"  B: "+b);
892 }
893
894 function sidebanner_init()
895 {
896     setInterval(sidebanner_cb, 666);
897 ;
898 }
899
900 function sidebanner_cb()
901 {
902     var a, b;
903
904     a = $('sidebanner').style.backgroundColor;
905     b = $('sidebanner').style.borderLeftColor;
906
907     $('sidebanner').style.backgroundColor = b;
908     $('sidebanner').style.borderColor = a+" "+a+" "+a+" "+a;
909
910     // console.log("A: "+a+"  B: "+b);
911 }
912
913
914 function langtolng(lang)
915 {
916     if (lang == "en")
917         return ("_en");
918     else
919         return ("");
920 }
921
922 function formtext_hilite(obj)
923 {
924     obj.className = 'input_text';
925     addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
926     addEvent(obj, "blur",  function () { this.className = 'input_text'; });
927 }
928
929 function formsub_hilite(obj)
930 {
931     obj.className = 'input_sub';
932     addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
933     addEvent(obj, "blur",  function () { this.className = 'input_sub'; });
934 }
935