new function FileBrowser
[enigma2-plugins.git] / webinterface / src / web-data / tools.js
1 Version = '$Header$';
2
3 var doRequestMemory = new Object();
4 var doRequestMemorySave = new Object();
5
6 var mediaPlayerStarted = false;
7
8 // Get Settings
9 var settings = null;
10 var parentControlList = null;
11
12 // UpdateStreamReader
13 var UpdateStreamReaderNextReadPos = 0;
14 var UpdateStreamReaderPollTimer;
15 var UpdateStreamReaderPollTimerCounter = 0;
16 var UpdateStreamReaderPollTimerCounterTwisted = 0;
17 UpdateStreamReaderRequest = null;
18 function UpdateStreamReaderStart(){
19         var ua = navigator.userAgent;
20         if(navigator.userAgent.indexOf("MSIE") >=0) {
21                 debug("UpdateStreamReader IE Fix");
22
23                 var namespace = {       
24                                         'url_updates': url_updates
25                 };
26                 $('UpdateStreamReaderIEFixPanel').innerHTML = RND(tplUpdateStreamReaderIE, namespace);
27                 
28         }else {
29                 UpdateStreamReaderNextReadPos = 0;
30                 allMessages = "";
31                 UpdateStreamReaderRequest = new XMLHttpRequest();
32                 UpdateStreamReaderRequest.onload = UpdateStreamReaderOnLoad;
33                 UpdateStreamReaderRequest.onerror = UpdateStreamReaderOnError;
34                 UpdateStreamReaderRequest.open("GET", url_updates, true);
35                 UpdateStreamReaderRequest.send(null);
36                 UpdateStreamReaderPollTimer = setInterval(UpdateStreamReaderLatestResponse, 10000);
37         }
38 }
39   
40 function UpdateStreamReaderLatestResponse() {
41         UpdateStreamReaderPollTimerCounter++;
42         debug(UpdateStreamReaderPollTimerCounter);
43         if(UpdateStreamReaderPollTimerCounter > 6) {
44                 clearInterval(UpdateStreamReaderPollTimer);
45                 UpdateStreamReaderRequest.abort();
46                 UpdateStreamReaderRequest = null;
47                 UpdateStreamReaderPollTimerCounter = 0;
48                 UpdateStreamReaderStart();
49                 
50                 UpdateStreamReaderPollTimerCounterTwisted++;
51                 return;
52         }
53         var allMessages = UpdateStreamReaderRequest.responseText;
54         do {
55                 var unprocessed = allMessages.substring(UpdateStreamReaderNextReadPos);
56                 var messageXMLEndIndex = unprocessed.indexOf("\n");
57                 
58                 if (messageXMLEndIndex!=-1) {
59                         var endOfFirstMessageIndex = messageXMLEndIndex + "\n".length;
60                         var anUpdate = unprocessed.substring(0, endOfFirstMessageIndex);
61         
62                         var re = new RegExp("<script>parent\.(.*)</script>");
63                         anUpdate = re.exec(anUpdate);
64
65                         if(anUpdate != null){
66                                 if (anUpdate.length == 2){
67                                         eval(anUpdate[1]);
68                                 }
69                         }
70                         
71                         UpdateStreamReaderNextReadPos += endOfFirstMessageIndex;
72                 }
73                 if(UpdateStreamReaderNextReadPos > 65000){
74                         UpdateStreamReaderRequest.abort();
75                         UpdateStreamReaderRequest = null;
76                         UpdateStreamReaderPollTimerCounter = 0;
77                         UpdateStreamReaderStart();
78                         messageXMLEndIndex = -1;
79                 }
80         } while (messageXMLEndIndex != -1);
81 }
82
83 function UpdateStreamReaderOnLoad(){
84         window.clearInterval(UpdateStreamReaderPollTimer);
85         debug("UpdateStreamReaderOnLoad");
86         Dialog.confirm(
87                 "Live Update Stream ends!<br><br>You will not receive any Update from Enigma2.<br>Should I reconnect?",
88                  {windowParameters: {width:300, className: windowStyle},
89                         okLabel: "reconnect",
90                         buttonClass: "myButtonClass",
91                         cancel: function(win) {debug("cancel confirm panel")},
92                         ok: function(win) {UpdateStreamReaderStart(); return true;}
93                         }
94                 );
95 }
96 function UpdateStreamReaderOnError(){
97         // TODO: change this, because it will be called on 'PageUnload' while the request is still running
98         debug("UpdateStreamReaderOnError");
99         window.clearInterval(UpdateStreamReaderPollTimer);
100         Dialog.confirm(
101                 "Live Update Stream has an Error!<br><br>You will not receive any Update from Enigma2.<br>Should I try to reconnect?",
102                  {windowParameters: {width:300, className: windowStyle},
103                          okLabel: "reconnect",
104                          buttonClass: "myButtonClass",
105                          cancel: function(win) {debug("cancel confirm panel")},
106                          ok: function(win) {UpdateStreamReaderStart(); return true;}
107                         }
108                 );
109 }
110 //end UpdateStreamReader
111
112 function openWindow(title, inner, width, height, x, y, id){
113                         if(id == null) id = new Date().toUTCString();
114                         if(x == null) x = 460;
115                         if(y == null) y = 400;
116                         var win = new Window(id, {className: windowStyle, title: title, width: width, height: height,wiredDrag: true});
117                         win.getContent().innerHTML = inner;
118                         win.setDestroyOnClose();
119                         win.showCenter();
120                         win.setLocation(y,x);//y=top,x=left
121                         debug("opening Window: "+title);
122                         return win;
123 }
124 function messageBox(t, m){
125         Dialog.alert(m, {windowParameters: {title: t, className: windowStyle, width:200}, okLabel: "Close"});
126 }
127
128 //RND Template Function (http://www.amix.dk)
129 function RND(tmpl, ns) {
130         var fn = function(w, g) {
131                 g = g.split("|");
132                 var cnt = ns[g[0]];
133                 //Support for filter functions
134                 for(var i=1; i < g.length; i++) {
135                         cnt = eval(g[i])(cnt);
136                 }
137                 return cnt || w;
138         };
139         return tmpl.replace(/%\(([A-Za-z0-9_|.]*)\)/g, fn);
140 }
141 function debug(text){
142         if(DBG){
143                 try{
144                         debugWin.getContent().innerHTML += "DEBUG: "+text+"<br>";
145                 } catch (windowNotPresent) {}
146         }
147 }
148 function showhide(id){
149         o = $(id).style;
150         o.display = (o.display!="none")? "none":"";
151 }
152 function set(element, value){
153         //debug(element+"-"+value);
154 //      MP3 File: /media/hdd/13-Placebo_Song_To_Say_Goodbye-Meds.mp3
155         if(element == "CurrentService") {
156                 if(value.search(/^MP3 File:/) != -1) {
157                         value = value.replace(/.*\//, '');
158                 }
159         }
160         element = parent.$(element);
161         if(value.length > 550) {
162                 value = value.substr(0,550) + "[...]";
163         }
164         if (element){
165                 element.innerHTML = value;
166         }
167         if(navigator.userAgent.indexOf("MSIE") >=0) {
168                 try{
169                         elementscript= $('UpdateStreamReaderIEFixIFrame').$('scriptzone');
170                         if(elementscript){
171                                 elementscript.innerHTML = ""; // deleting set() from page, to keep the page short and to save memory                    
172                         }
173                 }
174                 catch(e){}
175         }
176 }
177 function setComplete(element, value){
178         //debug(element+"-"+value);
179         element = parent.$(element);
180         if (element){
181                 element.innerHTML = value;
182         }
183         if(navigator.userAgent.indexOf("MSIE") >=0) {
184                 elementscript= $('UpdateStreamReaderIEFixIFrame').$('scriptzone');
185                 if(elementscript){
186                         elementscript.innerHTML = ""; // deleting set() from page, to keep the page short and to save memory                    
187                 }
188         }
189 }
190 // requestindikator
191 var requestcounter = 0;
192 function requestIndicatorUpdate(){
193         //debug(requestcounter+" open requests");
194         if(requestcounter>=1){
195                 $('RequestIndicator').style.display = "inline";
196         }else{
197                 $('RequestIndicator').style.display = "none";
198         }
199 }
200 function requestStarted(){
201         requestcounter +=1;
202         requestIndicatorUpdate();
203 }
204 function requestFinished(){
205         requestcounter -=1;
206         requestIndicatorUpdate();
207 }
208 // end requestindikator
209 function doRequest(url, readyFunction, save){
210         requestStarted();
211         doRequestMemorySave[url] = save;
212         debug("doRequest: Requesting: "+url);
213         if(save == true && typeof(doRequestMemory[url]) != "undefined") {
214                 readyFunction(doRequestMemory[url]);
215         } else {
216                 debug("doRequest: loading");
217                 new Ajax.Request(url,
218                         {
219                                 asynchronous: true,
220                                 method: 'GET',
221                                 requestHeaders: ['Pragma', 'no-cache', 'Cache-Control', 'must-revalidate', 'If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT'],
222                                 onException: function(o,e){ throw(e); },                                
223                                 onSuccess: function (transport, json) {
224                                                         if(typeof(doRequestMemorySave[url]) != "undefined") {
225                                                                 if(doRequestMemorySave[url]) {
226                                                                         debug("doRequest: saving request"); 
227                                                                         doRequestMemory[url] = transport;
228                                                                 }
229                                                         }
230                                                         readyFunction(transport);
231                                                 },
232                                 onComplete: requestFinished 
233                         });
234         }
235 }
236
237 function getXML(request){
238         if (document.implementation && document.implementation.createDocument){
239                 var xmlDoc = request.responseXML
240         }
241         else if (window.ActiveXObject){
242                 var xmlInsert = document.createElement('xml');
243
244                 xmlInsert.setAttribute('innerHTML',request.responseText);
245                 xmlInsert.setAttribute('id','_MakeAUniqueID');
246                 document.body.appendChild(xmlInsert);
247                 xmlDoc = $('_MakeAUniqueID');
248                 document.body.removeChild($('_MakeAUniqueID'));
249         } else {
250                 debug("Your Browser Sucks!");
251         }
252         return xmlDoc;
253 }
254 function parentPin(servicereference) {
255         servicereference = decodeURIComponent(servicereference);
256         if(parentControlList == null || String(getSettingByName("config.ParentalControl.configured")) != "True") {
257                 return true;
258         }
259         debug("parentPin " + parentControlList.length);
260         if(getParentControlByRef(servicereference) == servicereference) {
261                 if(String(getSettingByName("config.ParentalControl.type.value")) == "whitelist") {
262                         debug("leaving here 1");
263                         return true;
264                 }
265         } else {
266                 debug("leaving here 2");
267                 return true;
268         }
269         debug("going to ask for PIN");
270
271         var userInput = prompt('ParentControll was switch on.<br> Please enter PIN','PIN');
272         if (userInput != '' && userInput != null) {
273                 if(String(userInput) == String(getSettingByName("config.ParentalControl.servicepin.0")) ) {
274                         return true;
275                 } else {
276                         return parentPin(servicereference);
277                 }
278         } else {
279                 return false;
280         }
281 }
282 var SubServicePoller;
283 var SubServicePollerCounter = 0;
284 var SubServicePollerRef = null;
285 function zap(servicereference){
286         if(parentPin(servicereference)) {
287                 new Ajax.Request( "/web/zap?sRef=" + servicereference, 
288                                                         {
289                                                                 asynchronous: true,
290                                                                 method: 'get'
291                                                         }
292                                                 );
293                 if(SubServicePoller != 0){
294                         clearInterval(SubServicePoller);
295                         SubServicePollerCounter = 0;
296                 }
297                 SubServicePollerRef = servicereference;
298                 SubServicePoller = setInterval(getSubServices, 10000);
299                 SubServicePollerCounter = 1;
300         }
301 }
302
303 //++++       SignalPanel                           ++++
304
305 function openSignalDialog(){
306         openWindow("Signal Info",tplSignalPanel, 215, 75,620,40);
307 }
308
309
310 //++++ EPG functions                               ++++
311 function loadEPGBySearchString(string){
312                 doRequest(url_epgsearch+escape(string),incomingEPGrequest, false);
313 }
314 function loadEPGByServiceReference(servicereference){
315                 doRequest(url_epgservice+servicereference,incomingEPGrequest, false);
316 }
317 function incomingEPGrequest(request){
318         debug("incoming request" +request.readyState);          
319         if (request.readyState == 4){
320                 var EPGItems = new EPGList(getXML(request)).getArray(true);
321                 debug("have "+EPGItems.length+" e2events");
322                 if(EPGItems.length > 0){                        
323                         var html = tplEPGListHeader;
324                         for (var i=0; i < EPGItems.length; i++){
325                                 try{
326                                         var item = EPGItems[i];                         
327                                         var namespace = {       
328                                                         'date': item.getTimeDay(),
329                                                         'eventid': item.getEventId(),
330                                                         'servicereference': item.getServiceReference(),
331                                                         'servicename': quotes2html(item.getServiceName()),
332                                                         'title': quotes2html(item.getTitle()),
333                                                         'titleESC': escape(item.getTitle()),
334                                                         'starttime': item.getTimeStartString(), 
335                                                         'duration': Math.ceil(item.getDuration()/60000), 
336                                                         'description': quotes2html(item.getDescription()),
337                                                         'endtime': item.getTimeEndString(), 
338                                                         'extdescription': quotes2html(item.getDescriptionExtended()),
339                                                         'number': String(i),
340                                                         'extdescriptionSmall': extdescriptionSmall(item.getDescriptionExtended(),String(i)),
341                                                         'start': item.getTimeBegin(),
342                                                         'end': item.getTimeEnd()
343                                                 };
344                                         //Fill template with data and add id to our result
345                                         html += RND(tplEPGListItem, namespace);
346                                 } catch (blubb) { debug("Error rendering: "+blubb);     }
347                         }
348                         html += tplEPGListFooter;
349                         openWindow("Electronic Program Guide", html, 900, 500,50,60);
350                 } else {
351                         messageBox('No Items found!', 'Sorry but i could not find any EPG Content containing your search value');
352                 }
353         }
354 }
355 function extdescriptionSmall(txt,num) {
356         if(txt.length > 410) {
357                 var shortTxt = txt.substr(0,410);
358                 txt = txt.replace(/\'\'/g, '&quot;');
359                 txt = txt.replace(/\\/g, '\\\\');
360                 txt = txt.replace(/\'/g, '\\\'');
361                 txt = txt.replace(/\"/g, '&quot;');
362                 var smallNamespace = { 'txt':txt,'number':num, 'shortTxt':shortTxt};
363                 return RND(tplEPGListItemExtend, smallNamespace);
364         } else {
365                 return txt;
366         }
367 }       
368
369 /////////////////////////
370
371 function loadServiceEPGNowNext(servicereference){
372         var url = url_epgnow+servicereference;
373         doRequest(url, incomingServiceEPGNowNext, false);
374 }
375
376 function incomingServiceEPGNowNext(request){
377         if(request.readyState == 4){
378                 var epgevents = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
379                 for (var c =0; c < epgevents.length;c++){
380                         var eventnow = new EPGEvent(epgevents.item(c));
381                         
382                         if (eventnow.getEventId() != 'None'){
383                                 buildServiceListEPGItem(eventnow,"NOW");
384                         }
385                 }
386         }
387 }
388 function buildServiceListEPGItem(epgevent,nownext){
389         var e = $(epgevent.getServiceReference()+'EPG'+nownext);
390                 try{
391                         var namespace = {       
392                                 'starttime': epgevent.getTimeStartString(), 
393                                 'title': epgevent.getTitle(), 
394                                 'length': Math.ceil(epgevent.duration/60) 
395                         };
396                         e.innerHTML = RND(tplServiceListEPGItem, namespace);
397                 } catch (blubb) {
398                         debug("Error rendering: "+blubb);
399                 }       
400 }
401 ///////////////////
402
403
404 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
405 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
406 //++++ GUI functions                               ++++
407 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
408 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
409
410 var currentBodyMainElement = null
411
412 function setBodyMainContent(newelementname){
413 /*      debug("mediaPlayerStarted 1: " + mediaPlayerStarted);
414         if(mediaPlayerStarted) {
415                 mediaPlayerStarted = false;
416                 sendMediaPlayer(5);
417         }
418         debug("mediaPlayerStarted 2: " + mediaPlayerStarted);*/
419         newelement =$(newelementname);
420         if(currentBodyMainElement != null){
421                 currentBodyMainElement.style.display = "none";
422                 
423         }
424         newelement.style.display = "";
425         currentBodyMainElement = newelement;
426 }
427
428 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
429 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
430 //++++ volume functions                            ++++
431 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
432 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
433
434 function initVolumePanel(){
435         $('VolumePanel').innerHTML = tplVolumePanel;
436         getVolume(); 
437 }
438 function getVolume(){
439         doRequest(url_getvolume,handleVolumeRequest, false);
440 }
441 function volumeSet(newvalue){
442         doRequest(url_setvolume+newvalue,handleVolumeRequest, false);
443 }
444 function volumeUp(){
445         doRequest(url_volumeup,handleVolumeRequest, false);
446 }
447 function volumeDown(){
448         doRequest(url_volumedown,handleVolumeRequest, false);
449 }
450 function volumeMute(){
451         doRequest(url_volumemute,handleVolumeRequest, false);
452 }
453 function handleVolumeRequest(request){
454         if (request.readyState == 4) {
455                 var b = getXML(request).getElementsByTagName("e2volume");
456                 var newvalue = b.item(0).getElementsByTagName('e2current').item(0).firstChild.data;
457                 var mute = b.item(0).getElementsByTagName('e2ismuted').item(0).firstChild.data;
458                 debug("volume"+newvalue+";"+mute);
459                 
460                 for (var i = 1; i <= 10; i++)           {
461                         if ( (newvalue/10)>=i){
462                                 $("volume"+i).src = "/webdata/gfx/led_on.png";
463                         }else{
464                                 $("volume"+i).src = "/webdata/gfx/led_off.png";
465                         }
466                 }
467                 if (mute == "False"){
468                         $("speaker").src = "/webdata/gfx/speak_on.png";
469                 }else{
470                         $("speaker").src = "/webdata/gfx/speak_off.png";
471                 }
472         }       
473 }
474
475 var bouqetsMemory = new Object();
476
477 function initChannelList(){
478         //debug("init ChannelList");    
479         var url = url_getServices+encodeURIComponent(bouqet_tv);
480         doRequest(url, incomingTVBouquetList, true);
481
482         var url = url_getServices+encodeURIComponent(bouqet_radio);
483         doRequest(url, incomingRadioBouquetList, true);
484
485         var url = url_getServices+encodeURIComponent(bouqet_provider_tv);
486         doRequest(url, incomingProviderTVBouquetList, true);
487
488         var url = url_getServices+encodeURIComponent(bouqet_provider_radio);
489         doRequest(url, incomingProviderRadioBouquetList, true);
490         
491         getSettings();
492 }
493
494 var servicereftoloadepgnow = "";
495 var loadedChannellist = new Object();
496 function loadBouquet(servicereference){ 
497         debug("loading bouquet with "+servicereference);
498         servicereftoloadepgnow = servicereference;
499         debug("loadBouquet " + typeof(loadedChannellist[servicereftoloadepgnow]));
500         if(typeof(loadedChannellist[servicereftoloadepgnow]) == "undefined") {
501                 doRequest(url_getServices+servicereference, incomingChannellist, true);
502         } else {
503                 incomingChannellist();
504         }
505 }
506
507 function incomingTVBouquetList(request){
508         if (request.readyState == 4) {
509                 var list0 = new ServiceList(getXML(request)).getArray();
510                 debug("have "+list0.length+" TV Bouquet ");     
511                 $('accordionMenueBouquetContentTV').innerHTML = renderBouquetTable(list0,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
512                 //loading first entry of TV Favorites as default for ServiceList
513                 loadBouquet(list0[0].getServiceReference());
514                 bouqetsMemory["bouqet_tv"] = list0;
515         }
516 }
517 function incomingRadioBouquetList(request){
518         if (request.readyState == 4) {
519                 var list1 = new ServiceList(getXML(request)).getArray();
520                 debug("have "+list1.length+" Radio Bouquet ");  
521                 $('accordionMenueBouquetContentRadio').innerHTML = renderBouquetTable(list1,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
522         }       
523 }
524 function incomingProviderTVBouquetList(request){
525         if (request.readyState == 4) {
526                 var list2 = new ServiceList(getXML(request)).getArray();
527                 debug("have "+list2.length+" TV Provider Bouquet ");    
528                 $('accordionMenueBouquetContentProviderTV').innerHTML = renderBouquetTable(list2,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
529         }       
530 }
531 function incomingProviderRadioBouquetList(request){
532         if (request.readyState == 4) {
533                 var list2 = new ServiceList(getXML(request)).getArray();
534                 debug("have "+list2.length+" Radio Provider Bouquet "); 
535                 $('accordionMenueBouquetContentProviderRadio').innerHTML = renderBouquetTable(list2,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
536         }       
537 }
538
539 function renderBouquetTable(bouquet,templateHeader,templateItem,templateFooter){
540         debug("renderBouquetTable with "+bouquet.length+" Bouqet");     
541         var html = templateHeader;
542         for (var i=0; i < bouquet.length; i++){
543                 try{
544                         var namespace = {
545                                 'servicereference': bouquet[i].getServiceReference(), 
546                                 'bouquetname': bouquet[i].getServiceName()
547                         };
548                         html += RND(templateItem, namespace);
549                 } catch (blubb) {}
550         }
551         html += templateFooter;
552         return html;
553 }       
554
555 function incomingChannellist(request){
556         var services = null;
557         if(typeof(loadedChannellist[servicereftoloadepgnow]) != "undefined"){
558                 services = loadedChannellist[servicereftoloadepgnow];
559         } else if(request.readyState == 4) {
560                 services = new ServiceList(getXML(request)).getArray();
561                 loadedChannellist[servicereftoloadepgnow] = services;
562                 debug("got "+services.length+" Services");
563         }
564         if(services != null) {
565                 var smallNamespace = {'mainServiceRef': servicereftoloadepgnow };
566                 listerHtml = RND(tplServiceListHeader, smallNamespace);
567                 for ( var i = 0; i < services.length ; i++){
568                         var reference = services[i];
569                         var namespace = {       
570                                 'servicereference': reference.getServiceReference(),
571                                 'servicename': reference.getServiceName()
572                         };
573                         listerHtml += RND(tplServiceListItem, namespace);
574                 }               
575                 listerHtml += tplServiceListFooter;
576                 $('BodyContent').innerHTML = listerHtml;
577                 setBodyMainContent('BodyContent');
578                 loadServiceEPGNowNext(servicereftoloadepgnow);
579                 debug("incomingChannellist " + typeof(loadedChannellist[servicereftoloadepgnow]));
580         }
581 }
582 // Movies
583 function loadMovieList(tag){
584         debug("loading movies by tag '"+tag+"'");
585         doRequest(url_movielist+tag, incomingMovieList, false);
586 }
587
588 function incomingMovieList(request){
589         if(request.readyState == 4){
590                 var movies = new MovieList(getXML(request)).getArray();
591                 debug("have "+movies.length+" movies");
592                 listerHtml      = tplMovieListHeader;           
593                 for ( var i = 0; i <movies.length; i++){
594                         var movie = movies[i];
595                         var namespace = {       
596                                 'servicereference': movie.getServiceReference(),
597                                 'servicename': movie.getServiceName() ,
598                                 'title': movie.getTitle(), 
599                                 'description': movie.getDescription(), 
600                                 'descriptionextended': movie.getDescriptionExtended(),
601                                 'filelink': String(movie.getFilename()).substr(17,movie.getFilename().length),
602                                 'filename': String(movie.getFilename()),
603                                 'tags': movie.getTags().join(', ') ,
604                                 'length': movie.getLength() ,
605                                 'time': movie.getTimeDay()+"&nbsp;"+ movie.getTimeStartString()
606                         };
607                         listerHtml += RND(tplMovieListItem, namespace);
608                 }
609                 listerHtml += tplMovieListFooter;
610                 $('BodyContent').innerHTML = listerHtml;
611                 setBodyMainContent('BodyContent');
612                 
613         }               
614 }
615 function delMovieFile(file,servicename,title,description) {
616         debug("delMovieFile: file("+file+"),servicename("+servicename+"),title("+title+"),description("+description+")");
617         Dialog.confirm(
618                 "Selected timer:<br>"
619                 +"Servicename: "+servicename+"<br>"
620                 +"Title: "+title+"<br>"
621                 +"Description: "+description+"<br>"
622                 +"Are you sure that you want to delete the Timer?",
623                  {windowParameters: {width:300, className: windowStyle},
624                         okLabel: "delete",
625                         buttonClass: "myButtonClass",
626                         cancel: function(win) {debug("delMovieFile cancel confirm panel")},
627                         ok: function(win) { debug("delMovieFile ok confirm panel"); doRequest(url_moviefiledelete+"?filename="+file, incomingDelMovieFileResult, false); return true; }
628                         }
629         );
630         
631 }
632 function incomingDelMovieFileResult(request) {
633         debug("incomingDelMovieFileResult");
634         if(request.readyState == 4){
635                 var delresult = new SimpleXMLResult(getXML(request));
636                 if(delresult.getState()){
637                         loadMovieList('');
638                 }else{
639                         messageBox("Deletion Error","Reason: "+delresult.getStateText());
640                 }
641         }               
642 }
643
644
645 // send Messages
646 function showMessageSendForm(){
647                 $('BodyContent').innerHTML = tplMessageSendForm;
648 }
649 var MessageAnswerPolling;
650 function sendMessage(messagetext,messagetype,messagetimeout){
651         if(!messagetext){
652                 messagetext = $('MessageSendFormText').value;
653         }       
654         if(!messagetimeout){
655                 messagetimeout = $('MessageSendFormTimeout').value;
656         }       
657         if(!messagetype){
658                 var index = $('MessageSendFormType').selectedIndex;
659                 messagetype = $('MessageSendFormType').options[index].value;
660         }       
661         if(ownLazyNumber(messagetype) == 0){
662                 new Ajax.Request(url_message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, { asynchronous: true, method: 'get' });
663                 MessageAnswerPolling = setInterval(getMessageAnswer, ownLazyNumber(messagetimeout)*1000);
664         } else {
665                 doRequest(url_message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, incomingMessageResult, false);
666         }
667 }
668 function incomingMessageResult(request){
669
670         if(request.readyState== 4){
671                 var b = getXML(request).getElementsByTagName("e2message");
672                 var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
673                 var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
674                 if (result=="True"){
675                         messageBox('message send',resulttext);//'message send successfully! it appears on TV-Screen');
676                 }else{
677                         messageBox('message send failed',resulttext);
678                 }
679         }               
680 }
681 function getMessageAnswer() {
682         doRequest(url_messageanswer, incomingMessageResult, false);
683         clearInterval(MessageAnswerPolling);
684 }
685 // RemoteControl Code
686 function showRemoteControllSendForm(){
687         if(! $('rcWindow')){
688                 openWindow("Remote", tplRemoteControlForm, 220, 642, 920,0, "rcWindow");
689         }
690 }
691 function sendRemoteControlRequest(command){
692         doRequest(url_remotecontrol+'?command='+command, incomingRemoteControlResult, false);
693         if($('getScreen').checked) {
694                 openGrabPicture();
695         }
696 }
697 function openGrabPicture() {
698         if($('BodyContent').innerHTML != tplRCGrab) {
699                 $('BodyContent').innerHTML = tplRCGrab;
700         }
701         debug("openGrabPicture");
702         var buffer = new Image();
703         var downloadStart;
704
705         buffer.onload = function () { debug("image zugewiesen"); $('grabPageIMG').src = buffer.src; return true;};
706         buffer.onerror = function (meldung) { debug("reload grab image failed"); return true;};
707
708         downloadStart = new Date().getTime();
709         buffer.src = '/grab?' + downloadStart;
710         $('grabPageIMG').height(400);
711         tplRCGrab = $('BodyContent').innerHTML;
712 }
713 function incomingRemoteControlResult(request){
714         if(request.readyState == 4){
715                 var b = getXML(request).getElementsByTagName("e2remotecontrol");
716                 var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
717                 var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
718         } else {
719                 $('rcWindow').innerHTML = "<h1>some unknown error</h1>" + tplRemoteControlForm;
720         }
721 }
722
723 function getSettings(){
724         doRequest(url_settings, incomingGetSettings, false);
725 }
726
727 function incomingGetSettings(request){
728         if(request.readyState == 4){
729                 settings = new Settings(getXML(request)).getArray();
730         }
731         if(String(getSettingByName("config.ParentalControl.configured")) == "True") {
732                 getParentControl();
733         }
734 }
735 function getSettingByName(txt) {
736         debug("getSettingByName ("+txt+")");
737         for(i = 0; i < settings.length; i++) {
738                 debug("("+settings[i].getSettingName()+") (" +settings[i].getSettingValue()+")");
739                 if(String(settings[i].getSettingName()) == String(txt)) {
740                         return settings[i].getSettingValue();
741                 } 
742         }
743         return "";
744 }
745 function getParentControl() {
746         doRequest(url_parentcontrol, incomingParentControl, false);
747 }
748 function incomingParentControl(request) {
749         if(request.readyState == 4){
750                 parentControlList = new ServiceList(getXML(request)).getArray();
751                 debug("parentControlList got "+parentControlList.length + " services");
752         }
753 }
754 function getParentControlByRef(txt) {
755         debug("getParentControlByRef ("+txt+")");
756         for(i = 0; i < parentControlList.length; i++) {
757                 debug("("+parentControlList[i].getClearServiceReference()+")");
758                 if(String(parentControlList[i].getClearServiceReference()) == String(txt)) {
759                         return parentControlList[i].getClearServiceReference();
760                 } 
761         }
762         return "";
763 }
764 function ownLazyNumber(num) {
765         if(isNaN(num)){
766                 return 0;
767         } else {
768                 return Number(num);
769         }
770 }
771
772 var subServicesInsertedList = new Object();
773 function getSubServices(servicereference) {
774         clearInterval(SubServicePoller);
775         SubServicePollerCounter = 0;
776         doRequest(url_subservices,incomingSubServiceRequest, false);
777 }
778 function incomingSubServiceRequest(request){
779         if(request.readyState == 4){
780                 var services = new ServiceList(getXML(request)).getArray();
781                 listerHtml      = '';           
782                 debug("got "+services.length+" SubServices");
783                 if(services.length > 1) {
784                         
785                         first = services[0];
786                         var mainChannellist = loadedChannellist[String($('mainServiceRef').value)];
787                         
788                         var oldEntryPosition = -1;
789                         for(i = 0; i < mainChannellist.length; i++) {
790                                 var service = mainChannellist[i];
791                                 if(String(service.getServiceReference()) == String(first.getServiceReference())) {
792                                         oldEntryPosition = i + 1;
793                                         break;
794                                 }
795                         }
796                         if(typeof(subServicesInsertedList[String(first.getServiceReference())]) != "undefined") {
797                                 for ( var i = 1; i < subServicesInsertedList[String(first.getServiceReference())].length ; i++){
798                                         var reference = subServicesInsertedList[String(first.getServiceReference())][i];
799                                         $(reference.getServiceReference()+'extend').innerHTML = "";
800                                 }
801                                 for(i = oldEntryPosition; i < oldEntryPosition + subServicesInsertedList[String(first.getServiceReference())].length; i++) {
802                                         mainChannellist.splice(i);
803                                 }
804                         }
805                         for ( var i = 0; i < services.length ; i++){
806                                 var reference = services[i];
807                                 var namespace = {       
808                                         'servicereference': reference.getServiceReference(),
809                                         'servicename': reference.getServiceName()
810                                 };
811                                 listerHtml += RND(tplServiceListItem, namespace);
812                                 if(oldEntryPosition > -1) {
813                                         mainChannellist = mainChannellist.insert(oldEntryPosition++, reference);
814                                 }
815                         }
816                         $(first.getServiceReference()+'extend').innerHTML = listerHtml;
817                         subServicesInsertedList[String(first.getServiceReference())] = services;
818                         loadedChannellist[$('mainServiceRef').value] = mainChannellist;
819                 }
820         }
821 }
822 // Array.insert( index, value ) - Insert value at index, without overwriting existing keys
823 Array.prototype.insert = function( j, v ) {
824  if( j>=0 ) {
825   var a = this.slice(), b = a.splice( j );
826   a[j] = v;
827   return a.concat( b );
828  }
829 }
830 // Array.splice() - Remove or replace several elements and return any deleted elements
831 if( typeof Array.prototype.splice==='undefined' ) {
832  Array.prototype.splice = function( a, c ) {
833   var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
834   if( !c ) { c = l - a; }
835   for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
836   for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
837   this.length -= c - e.length + 2;
838   return d.slice( f, f + c );
839  };
840 }
841 function writeTimerListNow() {
842         new Ajax.Request( url_timerlistwrite, { asynchronous: true, method: 'get' });
843 }
844 function recordingPushed() {
845         doRequest(url_timerlist, incomingRecordingPushed, false);
846 }
847 function incomingRecordingPushed(request) {
848         if(request.readyState == 4){
849                 var timers = new TimerList(getXML(request)).getArray();
850                 debug("have "+timers.length+" timer");
851                 
852                 var aftereventReadable = new Array ('Nothing', 'Standby', 'Deepstandby/Shutdown');
853                 var justplayReadable = new Array('record', 'zap');
854                 var OnOff = new Array('on', 'off');
855                 
856                 listerHtml = '';
857                 
858                 for ( var i = 0; i <timers.length; i++){
859                         var timer = timers[i];
860
861                         if(ownLazyNumber(timer.getDontSave()) == 1) {
862                                 var beginDate = new Date(Number(timer.getTimeBegin())*1000);
863                                 var endDate = new Date(Number(timer.getTimeEnd())*1000);
864                                 var namespace = {
865                                 'servicereference': timer.getServiceReference(),
866                                 'servicename': timer.getServiceName() ,
867                                 'title': timer.getName(), 
868                                 'description': timer.getDescription(), 
869                                 'descriptionextended': timer.getDescriptionExtended(), 
870                                 'begin': timer.getTimeBegin(),
871                                 'beginDate': beginDate.toLocaleString(),
872                                 'end': timer.getTimeEnd(),
873                                 'endDate': endDate.toLocaleString(),
874                                 'state': timer.getState(),
875                                 'duration': Math.ceil((timer.getDuration()/60)),
876                                 'repeated': timer.getRepeated(),
877                                 'repeatedReadable': repeatedReadable(timer.getRepeated()),
878                                 'justplay': timer.getJustplay(),
879                                 'justplayReadable': justplayReadable[Number(timer.getJustplay())],
880                                 'afterevent': timer.getAfterevent(),
881                                 'aftereventReadable': aftereventReadable[Number(timer.getAfterevent())],
882                                 'disabled': timer.getDisabled(),
883                                 'onOff': OnOff[Number(timer.getDisabled())],
884                                 'color': colorTimerListEntry( timer.getState() )
885                                 };
886                                 listerHtml += RND(tplTimerListItem, namespace);
887                         }
888                 }
889                 openWindow("Record Now", listerHtml+tplRecordingFooter, 900, 500, "Record now window");
890         }
891 }
892 function inserteSizes() {
893 /*      var screenW = 640, screenH = 480;
894         if (parseInt(navigator.appVersion)>3) { 
895                 screenW = screen.width;
896                 screenH = screen.height;
897         } else if (navigator.appName == "Netscape"
898            && parseInt(navigator.appVersion)==3
899            && navigator.javaEnabled() ) {
900                 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
901                 var jScreenSize = jToolkit.getScreenSize();
902                 screenW = jScreenSize.width;
903                 screenH = jScreenSize.height;
904         }
905         debug("screenW:"+screenW+" screenH:"+screenH);
906         /* 640x480
907          * 800x600
908          * 1024x768
909          * 1280x1024
910          * 1600x1280
911         if(screenH == 800) {
912                 debug("size 1");
913                 $("BodyContent").style.height = '20%';
914         } else if(screenH == 1024) {
915                 debug("1024")
916                 $("BodyContent").style.height = '760px';
917                 
918         } else {
919                 alert("unsupported screensize");
920         }*/
921         
922 }
923 function recordingPushedDecision(recordNowNothing,recordNowUndefinitely,recordNowCurrent) {
924         var recordNow = recordNowNothing;
925         recordNow = (recordNow == "") ? recordNowUndefinitely: recordNow;
926         recordNow = (recordNow == "") ? recordNowCurrent: recordNow;
927         if(recordNow != "nothing" && recordNow != "") {
928                 doRequest(url_recordnow+"?recordnow="+recordNow, incomingTimerAddResult, false);
929         }
930 }
931
932 function ifChecked(rObj) {
933         if(rObj.checked) {
934                 return rObj.value;
935         } else {
936                 return "";
937         }
938 }
939 function showAbout() {
940         doRequest(url_about, incomingAbout, false);
941 }
942 function incomingAbout(request) {
943         if(request.readyState == 4){
944                 debug("incomingAbout returned");
945                 var aboutEntries = getXML(request).getElementsByTagName("e2abouts").item(0).getElementsByTagName("e2about");
946                 for (var c =0; c < aboutEntries.length;c++){
947                         var xml = aboutEntries.item(c);
948                         try{
949                                 var fptext = "V"+xml.getElementsByTagName('e2fpversion').item(0).firstChild.data;
950                                 var tunerinfo = "";
951                                 
952                                 var nims = xml.getElementsByTagName('e2tunerinfo').item(0).getElementsByTagName("e2nim");
953                                 debug("nims: "+nims.length);
954                                 for(var i=0;i< nims.length;i++){
955                                         
956                                         name = nims.item(i).getElementsByTagName("name").item(0).firstChild.data;
957                                         type = nims.item(i).getElementsByTagName("type").item(0).firstChild.data;
958                                         debug(name);
959                                         debug(type);
960                                         var ns = { 'name' : name, 'type' : type};
961                                         tunerinfo += RND(tplAboutTuner, ns);
962                                         
963                                 }
964                                 
965                                 var hdddata = xml.getElementsByTagName('e2hddinfo').item(0);
966                                 
967                                 var hddmodel    = hdddata.getElementsByTagName("model").item(0).firstChild.data;
968                                 var hddcapacity = hdddata.getElementsByTagName("capacity").item(0).firstChild.data;
969                                 var hddfree             = hdddata.getElementsByTagName("free").item(0).firstChild.data;
970
971                                 var namespace = {
972                                         'enigmaVersion': xml.getElementsByTagName('e2enigmaversion').item(0).firstChild.data
973 /*
974                                         ,'lanDHCP': xml.getElementsByTagName('e2landhcp').item(0).firstChild.data
975                                         ,'lanIP': xml.getElementsByTagName('e2lanip').item(0).firstChild.data
976                                         ,'lanMask': xml.getElementsByTagName('e2lanmask').item(0).firstChild.data
977                                         ,'lanGW': xml.getElementsByTagName('e2langw').item(0).firstChild.data
978                                         ,'lanDNS': xml.getElementsByTagName('e2landns').item(0).firstChild.data
979 */
980                                         ,'fpVersion': fptext
981                                         ,'webifversion': xml.getElementsByTagName('e2webifversion').item(0).firstChild.data
982                                         ,'tunerInfo': tunerinfo
983                                         ,'hddmodel': hddmodel
984                                         ,'hddcapacity': hddcapacity
985                                         ,'hddfree': hddfree
986                                         ,'serviceName': xml.getElementsByTagName('e2servicename').item(0).firstChild.data
987                                         ,'serviceProvider': xml.getElementsByTagName('e2serviceprovider').item(0).firstChild.data
988                                         ,'serviceAspect': xml.getElementsByTagName('e2serviceaspect').item(0).firstChild.data
989                                         ,'serviceNamespace': xml.getElementsByTagName('e2servicenamespace').item(0).firstChild.data
990                                         ,'vPIDh': '0x'+xml.getElementsByTagName('e2vpid').item(0).firstChild.data
991                                          ,'vPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2vpid').item(0).firstChild.data),16)
992                                         ,'aPIDh': '0x'+xml.getElementsByTagName('e2apid').item(0).firstChild.data
993                                          ,'aPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2apid').item(0).firstChild.data),16)
994                                         ,'pcrIDh': '0x'+xml.getElementsByTagName('e2pcrid').item(0).firstChild.data
995                                          ,'pcrID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2pcrid').item(0).firstChild.data),16)
996                                         ,'pmtPIDh': '0x'+xml.getElementsByTagName('e2pmtpid').item(0).firstChild.data
997                                          ,'pmtPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2pmtpid').item(0).firstChild.data),16)
998                                         ,'txtPIDh': '0x'+xml.getElementsByTagName('e2txtpid').item(0).firstChild.data
999                                          ,'txtPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2txtpid').item(0).firstChild.data),16)
1000                                         ,'tsIDh': '0x'+xml.getElementsByTagName('e2tsid').item(0).firstChild.data
1001                                          ,'tsID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2tsid').item(0).firstChild.data),16)
1002                                         ,'onIDh': '0x'+xml.getElementsByTagName('e2onid').item(0).firstChild.data
1003                                          ,'onID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2onid').item(0).firstChild.data),16)
1004                                         ,'sidh': '0x'+xml.getElementsByTagName('e2sid').item(0).firstChild.data
1005                                          ,'sid': parseInt(ownLazyNumber(xml.getElementsByTagName('e2sid').item(0).firstChild.data),16)
1006                                   };                              
1007                                 $('BodyContent').innerHTML = RND(tplAbout, namespace);
1008                                 setBodyMainContent('BodyContent');
1009                                 
1010                         } catch (e) {
1011                                 debug("About parsing Error" + e);
1012                         }       
1013                 }
1014         }
1015 }
1016 function quotes2html(txt) {
1017         txt = txt.replace(/"/g, '&quot;');
1018         return txt.replace(/'/g, "\\\'");
1019 }
1020
1021 // Spezial functions, mostly for testing purpose
1022 function openHiddenFunctions(){
1023         openWindow("Extra Hidden Functions",tplExtraHiddenFunctions,300,100,920,0);
1024 }
1025 function restartUpdateStream() {
1026         clearInterval(UpdateStreamReaderPollTimer);
1027         UpdateStreamReaderRequest.abort();
1028         UpdateStreamReaderRequest = null;
1029         UpdateStreamReaderPollTimerCounter = 0;
1030         UpdateStreamReaderStart();
1031 }
1032 function startDebugWindow() {
1033         DBG = true;
1034         debugWin = openWindow("DEBUG", "", 300, 300,920,140, "debugWindow");
1035 }
1036 function restartTwisted() {
1037         new Ajax.Request( "/web/restarttwisted", { asynchronous: true, method: "get" })
1038 }
1039 //MediaPlayer
1040 function loadMediaPlayer(directory){
1041         debug("loading loadMediaPlayer");
1042         doRequest(url_mediaplayerlist+directory, incomingMediaPlayer, false);
1043 }
1044 function incomingMediaPlayer(request){
1045         if(request.readyState == 4){
1046                 var files = new FileList(getXML(request)).getArray();
1047                 debug(getXML(request));
1048                 debug("have "+files.length+" entry in filelist");
1049                 listerHtml      = tplMediaPlayerHeader;
1050                 root = files[0].getRoot();
1051                 listerHtml      = RND(tplMediaPlayerHeader, {'root': root});
1052                 if(root != '/') {
1053                         re = new RegExp(/(.*)\/(.*)\/$/);
1054                         re.exec(root);
1055                         newroot = RegExp.$1+'/';
1056                         if(newroot == '//') {
1057                                 newroot = '/';
1058                         }
1059                         listerHtml += RND(tplMediaPlayerItemBody, 
1060                                 {'root': root
1061                                 , 'servicereference': newroot
1062                                 ,'exec': 'loadMediaPlayer'
1063                                 ,'exec_description': 'change to directory ../'
1064                                 ,'color': '000000'
1065                                 ,'root': newroot
1066                                 ,'name': '..'});
1067                 }
1068                 for ( var i = 0; i <files.length; i++){
1069                         var file = files[i];
1070                         if(file.getNameOnly() == 'None') {
1071                                 continue;
1072                         }
1073                         var exec = 'loadMediaPlayer';
1074                         var exec_description = 'change to directory' + file.getServiceReference();
1075                         var color = '000000';
1076                         if (file.getIsDirectory() == "False") {
1077                                 exec = 'playFile';
1078                                 exec_description = 'play file';
1079                                 color = '00BCBC';
1080                         }
1081                         var namespace = {
1082                                 'servicereference': file.getServiceReference()
1083                                 ,'exec': exec
1084                                 ,'exec_description': exec_description
1085                                 ,'color': color
1086                                 ,'root': file.getRoot()
1087                                 ,'name': file.getNameOnly()
1088                         };
1089                         listerHtml += tplMediaPlayerItemHead;
1090                         listerHtml += RND(tplMediaPlayerItemBody, namespace);
1091                         if (file.getIsDirectory() == "False") {
1092                                 listerHtml += RND(tplMediaPlayerItemIMG, namespace);
1093                         }
1094                         listerHtml += tplMediaPlayerItemFooter;
1095                 }
1096                 listerHtml += tplMediaPlayerFooter;
1097                 $('BodyContent').innerHTML = listerHtml;
1098                 var sendMediaPlayerTMP = sendMediaPlayer;
1099                 sendMediaPlayer = false;
1100                 setBodyMainContent('BodyContent');
1101                 sendMediaPlayer = sendMediaPlayerTMP;
1102         }               
1103 }
1104 function playFile(file,root) {
1105         debug("loading playFile");
1106         mediaPlayerStarted = true;
1107         new Ajax.Request( url_mediaplayerplay+file+"&root="+root, { asynchronous: true, method: 'get' });
1108 }
1109 function sendMediaPlayer(command) {
1110         debug("loading sendMediaPlayer");
1111         new Ajax.Request( url_mediaplayercmd+command, { asynchronous: true, method: 'get' });
1112 }
1113 function showPowerStateSendForm(){
1114                 $('BodyContent').innerHTML = tplPowerStateSendForm;
1115 }
1116 function sendPowerState(newState){
1117         new Ajax.Request( url_powerstate+'?newstate='+newState, { asynchronous: true, method: 'get' });
1118 }
1119 function loadFileBrowser(directory,types){
1120         debug("loading loadFileBrowser");
1121         doRequest(url_filelist+directory+"&types="+types, incomingFileBrowser, false);  
1122 }
1123 function incomingFileBrowser(request){
1124         if(request.readyState == 4){
1125                 var files = new FileList(getXML(request)).getArray();
1126                 debug(getXML(request));
1127                 debug("have "+files.length+" entry in filelist");
1128                 listerHtml      = tplFileBrowserHeader;
1129                 root = files[0].getRoot();
1130                 listerHtml      = RND(tplFileBrowserHeader, {'root': root});
1131                 if(root != '/') {
1132                         re = new RegExp(/(.*)\/(.*)\/$/);
1133                         re.exec(root);
1134                         newroot = RegExp.$1+'/';
1135                         if(newroot == '//') {
1136                                 newroot = '/';
1137                         }
1138                         listerHtml += RND(tplFileBrowserItemBody, 
1139                                 {'root': root
1140                                 , 'servicereference': newroot
1141                                 ,'exec': 'loadFileBrowser'
1142                                 ,'exec_description': 'change to directory ../'
1143                                 ,'color': '000000'
1144                                 ,'root': newroot
1145                                 ,'name': '..'});
1146                 }
1147                 for ( var i = 0; i <files.length; i++){
1148                         var file = files[i];
1149                         if(file.getNameOnly() == 'None') {
1150                                 continue;
1151                         }
1152                         var exec = 'loadFileBrowser';
1153                         var exec_description = 'change to directory' + file.getServiceReference();
1154                         var color = '000000';
1155                         if (file.getIsDirectory() == "False") {
1156                                 exec = '';
1157                                 exec_description = 'do Nothing';
1158                                 color = '00BCBC';
1159                         }
1160                         var namespace = {
1161                                 'servicereference': file.getServiceReference()
1162                                 ,'exec': exec
1163                                 ,'exec_description': exec_description
1164                                 ,'color': color
1165                                 ,'root': file.getRoot()
1166                                 ,'name': file.getNameOnly()
1167                         };
1168                         listerHtml += tplFileBrowserItemHead;
1169                         listerHtml += RND(tplFileBrowserItemBody, namespace);
1170                         if (file.getIsDirectory() == "False") {
1171                                 listerHtml += RND(tplFileBrowserItemIMG, namespace);
1172                         }
1173                         listerHtml += tplFileBrowserItemFooter;
1174                 }
1175                 listerHtml += RND(tplFileBrowserFooter, {'root': root});
1176                 alert(listerHtml);
1177                 $('BodyContent').innerHTML = listerHtml;
1178                 setBodyMainContent('BodyContent');
1179         }               
1180 }
1181 function delFile(file,root) {
1182         debug("loading loadMediaPlayer");
1183         doRequest(url_delfile+root+file, incomingDelFileResult, false);
1184 }
1185 function incomingDelFileResult(request) {
1186         debug("incomingDelFileResult");
1187         if(request.readyState == 4){
1188                 var delresult = new SimpleXMLResult(getXML(request));
1189                 if(delresult.getState()){
1190                         loadFileBrowser($('path').value);
1191                 }else{
1192                         messageBox("Deletion Error","Reason: "+delresult.getStateText());
1193                 }
1194         }               
1195 }
1196
1197 // Notes
1198 function showNotes(){
1199         debug("loading notes");
1200         doRequest(url_notelist, incomingNoteList, false);
1201 }
1202
1203 function incomingNoteList(request){
1204         if(request.readyState == 4){
1205                 var notes = new NoteList(getXML(request)).getArray();
1206                 debug("have "+notes.length+" movies");
1207                 listerHtml      = tplNotesListHeader;           
1208                 for ( var i = 0; i <notes.length; i++){
1209                         var note = notes[i];
1210                         var namespace = {       
1211                                 'name': note.filename,
1212                                 'size': note.size,
1213                                 'ctime': note.getCTime(),
1214                                 'mtime': note.getMTime()
1215                         };
1216                         listerHtml += RND(tplNotesListItem, namespace);
1217                 }
1218                 listerHtml += tplNotesListFooter;
1219                 $('BodyContent').innerHTML = listerHtml;
1220                 setBodyMainContent('BodyContent');
1221                 
1222         }               
1223 }
1224 function showNote(name){
1225         debug("loading note "+name);
1226         doRequest(url_note+name, incomingNote, false);
1227 }
1228
1229 function incomingNote(request){
1230         if(request.readyState == 4){
1231                 var note = new Note(getXML(request));
1232                 var namespace = {       
1233                                 'name': note.filename,
1234                                 'size': note.size,
1235                                 'content': note.content,
1236                                 'ctime': note.getCTime(),
1237                                 'mtime': note.getMTime()
1238                         };
1239                 var html = RND(tplNote, namespace);
1240                 openWindow("Note '"+note.filename+"'", html, 400, 300,50,60);
1241         }               
1242 }
1243 function saveNote(formid){
1244         var nameold = $(formid+'_name').value;
1245         var namenew = $(formid+'_namenew').value;
1246         var content = $(formid+'_content').value;
1247         debug("loading notes"+nameold+namenew+content);
1248         doRequest(url_notelist+"?save="+nameold+"&namenew="+namenew+"&content="+content, incomingNoteSavedResult, false);       
1249         Windows.closeAll();
1250         
1251 }
1252 function incomingNoteSavedResult(request){
1253         if(request.readyState == 4){
1254                 var note = new Note(getXML(request));
1255                 if (note.saved == "True"){
1256                         showNote(note.filename);
1257                         showNotes();
1258                 }
1259         }
1260 }
1261 function createNote(){
1262                 doRequest(url_notelist+"?create=new", incomingNoteCreateResult, false);
1263 }
1264
1265 function incomingNoteCreateResult(request){
1266         if(request.readyState == 4){
1267                 showNotes();
1268         }
1269 }