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