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