* Changed Subservice Handling a lot
[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 = 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, 1500);
41         }
42 }
43   
44 function UpdateStreamReaderLatestResponse() {
45         UpdateStreamReaderPollTimerCounter++;
46         
47         if(UpdateStreamReaderPollTimerCounter > 6) {
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 function debug(text){
147         if(DBG){
148                 try{
149                         debugWin.getContent().innerHTML += "DEBUG: "+text+"<br>";
150                 } catch (windowNotPresent) {}
151         }
152 }
153 function showhide(id){
154         o = $(id).style;
155         o.display = (o.display!="none")? "none":"";
156 }
157 function set(element, value){
158         //debug(element+"-"+value);
159 //      MP3 File: /media/hdd/13-Placebo_Song_To_Say_Goodbye-Meds.mp3
160         if(element == "CurrentService") {
161                 if(value.search(/^MP3 File:/) != -1) {
162                         value = value.replace(/.*\//, '');
163                 }
164         }
165         element = parent.$(element);
166         if(value.length > 550) {
167                 value = value.substr(0,550) + "[...]";
168         }
169         if (element){
170                 element.innerHTML = value;
171         }
172         if(navigator.userAgent.indexOf("MSIE") >=0) {
173                 try{
174                         elementscript= $('UpdateStreamReaderIEFixIFrame').$('scriptzone');
175                         if(elementscript){
176                                 elementscript.innerHTML = ""; // deleting set() from page, to keep the page short and to save memory                    
177                         }
178                 }
179                 catch(e){}
180         }
181 }
182 function setComplete(element, value){
183         //debug(element+"-"+value);
184         element = parent.$(element);
185         if (element){
186                 element.innerHTML = value;
187         }
188         if(navigator.userAgent.indexOf("MSIE") >=0) {
189                 elementscript= $('UpdateStreamReaderIEFixIFrame').$('scriptzone');
190                 if(elementscript){
191                         elementscript.innerHTML = ""; // deleting set() from page, to keep the page short and to save memory                    
192                 }
193         }
194 }
195 // requestindikator
196 var requestcounter = 0;
197 function requestIndicatorUpdate(){
198         //debug(requestcounter+" open requests");
199         if(requestcounter>=1){
200                 $('RequestIndicator').style.display = "inline";
201         }else{
202                 $('RequestIndicator').style.display = "none";
203         }
204 }
205 function requestStarted(){
206         requestcounter +=1;
207         requestIndicatorUpdate();
208 }
209 function requestFinished(){
210         requestcounter -=1;
211         requestIndicatorUpdate();
212 }
213 // end requestindikator
214 function doRequest(url, readyFunction, save){
215         requestStarted();
216         doRequestMemorySave[url] = save;
217         debug("doRequest: Requesting: "+url);
218         if(save == true && typeof(doRequestMemory[url]) != "undefined") {
219                 readyFunction(doRequestMemory[url]);
220         } else {
221                 debug("doRequest: loading");
222                 new Ajax.Request(url,
223                         {
224                                 asynchronous: true,
225                                 method: 'GET',
226                                 requestHeaders: ['Pragma', 'no-cache', 'Cache-Control', 'must-revalidate', 'If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT'],
227                                 onException: function(o,e){ throw(e); },                                
228                                 onSuccess: function (transport, json) {
229                                                         if(typeof(doRequestMemorySave[url]) != "undefined") {
230                                                                 if(doRequestMemorySave[url]) {
231                                                                         debug("doRequest: saving request"); 
232                                                                         doRequestMemory[url] = transport;
233                                                                 }
234                                                         }
235                                                         readyFunction(transport);
236                                                 },
237                                 onComplete: requestFinished 
238                         });
239         }
240 }
241
242 function getXML(request){
243         if (document.implementation && document.implementation.createDocument){
244                 var xmlDoc = request.responseXML
245         }
246         else if (window.ActiveXObject){
247                 var xmlInsert = document.createElement('xml');
248
249                 xmlInsert.setAttribute('innerHTML',request.responseText);
250                 xmlInsert.setAttribute('id','_MakeAUniqueID');
251                 document.body.appendChild(xmlInsert);
252                 xmlDoc = $('_MakeAUniqueID');
253                 document.body.removeChild($('_MakeAUniqueID'));
254         } else {
255                 debug("Your Browser Sucks!");
256         }
257         return xmlDoc;
258 }
259 function parentPin(servicereference) {
260         servicereference = decodeURIComponent(servicereference);
261         if(parentControlList == null || String(getSettingByName("config.ParentalControl.configured")) != "True") {
262                 return true;
263         }
264         debug("parentPin " + parentControlList.length);
265         if(getParentControlByRef(servicereference) == servicereference) {
266                 if(String(getSettingByName("config.ParentalControl.type.value")) == "whitelist") {
267                         debug("leaving here 1");
268                         return true;
269                 }
270         } else {
271                 debug("leaving here 2");
272                 return true;
273         }
274         debug("going to ask for PIN");
275
276         var userInput = prompt('ParentControll was switch on.<br> Please enter PIN','PIN');
277         if (userInput != '' && userInput != null) {
278                 if(String(userInput) == String(getSettingByName("config.ParentalControl.servicepin.0")) ) {
279                         return true;
280                 } else {
281                         return parentPin(servicereference);
282                 }
283         } else {
284                 return false;
285         }
286 }
287
288 function zap(servicereference){
289         if(parentPin(servicereference)) {
290                 new Ajax.Request( "/web/zap?sRef=" + servicereference, 
291                                                         {
292                                                                 asynchronous: true,
293                                                                 method: 'get'
294                                                         }
295                                                 );
296                 setTimeout("getSubServices()", 3000);
297         }
298         
299 }
300
301
302 //++++       SignalPanel                           ++++
303
304 function openSignalDialog(){
305         openWindow("Signal Info",tplSignalPanel, 215, 100,620,40);
306 }
307
308
309 //++++ EPG functions                               ++++
310 function loadEPGBySearchString(string){
311                 doRequest(url_epgsearch+escape(string),incomingEPGrequest, false);
312 }
313 function loadEPGByServiceReference(servicereference){
314                 doRequest(url_epgservice+servicereference,incomingEPGrequest, false);
315 }
316 function incomingEPGrequest(request){
317         debug("incoming request" +request.readyState);          
318         if (request.readyState == 4){
319                 var EPGItems = new EPGList(getXML(request)).getArray(true);
320                 debug("have "+EPGItems.length+" e2events");
321                 if(EPGItems.length > 0){                        
322                         var html = tplEPGListHeader;
323                         for (var i=0; i < EPGItems.length; i++){
324                                 try{
325                                         var item = EPGItems[i];                         
326                                         var namespace = {       
327                                                         'date': item.getTimeDay(),
328                                                         'eventid': item.getEventId(),
329                                                         'servicereference': item.getServiceReference(),
330                                                         'servicename': quotes2html(item.getServiceName()),
331                                                         'title': quotes2html(item.getTitle()),
332                                                         'titleESC': escape(item.getTitle()),
333                                                         'starttime': item.getTimeStartString(), 
334                                                         'duration': Math.ceil(item.getDuration()/60000), 
335                                                         'description': quotes2html(item.getDescription()),
336                                                         'endtime': item.getTimeEndString(), 
337                                                         'extdescription': quotes2html(item.getDescriptionExtended()),
338                                                         'number': String(i),
339                                                         'extdescriptionSmall': extdescriptionSmall(item.getDescriptionExtended(),String(i)),
340                                                         'start': item.getTimeBegin(),
341                                                         'end': item.getTimeEnd()
342                                                 };
343                                         //Fill template with data and add id to our result
344                                         html += RND(tplEPGListItem, namespace);
345                                 } catch (blubb) { debug("Error rendering: "+blubb);     }
346                         }
347                         html += tplEPGListFooter;
348                         openWindow("Electronic Program Guide", html, 900, 500,50,60);
349                 } else {
350                         messageBox('No Items found!', 'Sorry but i could not find any EPG Content containing your search value');
351                 }
352         }
353 }
354 function extdescriptionSmall(txt,num) {
355         if(txt.length > 410) {
356                 var shortTxt = txt.substr(0,410);
357                 txt = txt.replace(/\'\'/g, '&quot;');
358                 txt = txt.replace(/\\/g, '\\\\');
359                 txt = txt.replace(/\'/g, '\\\'');
360                 txt = txt.replace(/\"/g, '&quot;');
361                 var smallNamespace = { 'txt':txt,'number':num, 'shortTxt':shortTxt};
362                 return RND(tplEPGListItemExtend, smallNamespace);
363         } else {
364                 return txt;
365         }
366 }       
367
368 /////////////////////////
369
370 function loadServiceEPGNowNext(servicereference){
371         var url = url_epgnow+servicereference;
372         doRequest(url, incomingServiceEPGNowNext, false);
373 }
374
375 function incomingServiceEPGNowNext(request){
376         if(request.readyState == 4){
377                 var epgevents = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
378                 for (var c =0; c < epgevents.length;c++){
379                         var eventnow = new EPGEvent(epgevents.item(c));
380                         
381                         if (eventnow.getEventId() != 'None'){
382                                 buildServiceListEPGItem(eventnow,"NOW");
383                         }
384                 }
385         }
386 }
387 function buildServiceListEPGItem(epgevent,nownext){
388         var e = $(epgevent.getServiceReference()+'EPG'+nownext);
389                 try{
390                         var namespace = {       
391                                 'starttime': epgevent.getTimeStartString(), 
392                                 'title': epgevent.getTitle(), 
393                                 'length': Math.ceil(epgevent.duration/60) 
394                         };
395                         e.innerHTML = RND(tplServiceListEPGItem, namespace);
396                 } catch (blubb) {
397                         debug("Error rendering: "+blubb);
398                 }       
399 }
400 ///////////////////
401
402
403 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
404 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
405 //++++ GUI functions                               ++++
406 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
407 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
408
409 var currentBodyMainElement = null
410
411 function setBodyMainContent(newelementname){
412 /*      debug("mediaPlayerStarted 1: " + mediaPlayerStarted);
413         if(mediaPlayerStarted) {
414                 mediaPlayerStarted = false;
415                 sendMediaPlayer(5);
416         }
417         debug("mediaPlayerStarted 2: " + mediaPlayerStarted);*/
418         newelement =$(newelementname);
419         if(currentBodyMainElement != null){
420                 currentBodyMainElement.style.display = "none";
421                 
422         }
423         newelement.style.display = "";
424         currentBodyMainElement = newelement;
425 }
426
427 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
428 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
429 //++++ volume functions                            ++++
430 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
431 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
432
433 function initVolumePanel(){
434         $('VolumePanel').innerHTML = tplVolumePanel;
435         getVolume(); 
436 }
437 function getVolume(){
438         doRequest(url_getvolume,handleVolumeRequest, false);
439 }
440 function volumeSet(newvalue){
441         doRequest(url_setvolume+newvalue,handleVolumeRequest, false);
442 }
443 function volumeUp(){
444         doRequest(url_volumeup,handleVolumeRequest, false);
445 }
446 function volumeDown(){
447         doRequest(url_volumedown,handleVolumeRequest, false);
448 }
449 function volumeMute(){
450         doRequest(url_volumemute,handleVolumeRequest, false);
451 }
452 function handleVolumeRequest(request){
453         if (request.readyState == 4) {
454                 var b = getXML(request).getElementsByTagName("e2volume");
455                 var newvalue = b.item(0).getElementsByTagName('e2current').item(0).firstChild.data;
456                 var mute = b.item(0).getElementsByTagName('e2ismuted').item(0).firstChild.data;
457                 debug("volume"+newvalue+";"+mute);
458                 
459                 for (var i = 1; i <= 10; i++)           {
460                         if ( (newvalue/10)>=i){
461                                 $("volume"+i).src = "/webdata/gfx/led_on.png";
462                         }else{
463                                 $("volume"+i).src = "/webdata/gfx/led_off.png";
464                         }
465                 }
466                 if (mute == "False"){
467                         $("speaker").src = "/webdata/gfx/speak_on.png";
468                 }else{
469                         $("speaker").src = "/webdata/gfx/speak_off.png";
470                 }
471         }       
472 }
473
474 var bouqetsMemory = new Object();
475
476 function initChannelList(){
477         //debug("init ChannelList");    
478         var url = url_getServices+encodeURIComponent(bouqet_tv);
479         doRequest(url, incomingTVBouquetList, true);
480
481         var url = url_getServices+encodeURIComponent(bouqet_radio);
482         doRequest(url, incomingRadioBouquetList, true);
483
484         var url = url_getServices+encodeURIComponent(bouqet_provider_tv);
485         doRequest(url, incomingProviderTVBouquetList, true);
486
487         var url = url_getServices+encodeURIComponent(bouqet_provider_radio);
488         doRequest(url, incomingProviderRadioBouquetList, true);
489         
490         getSettings();
491 }
492
493 var servicereftoloadepgnow = "";
494 var loadedChannellist = new Object();
495 function loadBouquet(servicereference){ 
496         debug("loading bouquet with "+servicereference);
497         servicereftoloadepgnow = servicereference;
498         debug("loadBouquet " + typeof(loadedChannellist[servicereftoloadepgnow]));
499         if(typeof(loadedChannellist[servicereftoloadepgnow]) == "undefined") {
500                 doRequest(url_getServices+servicereference, incomingChannellist, true);
501         } else {
502                 incomingChannellist();
503         }
504 }
505
506 function incomingTVBouquetList(request){
507         if (request.readyState == 4) {
508                 var list0 = new ServiceList(getXML(request)).getArray();
509                 debug("have "+list0.length+" TV Bouquet ");     
510                 $('accordionMenueBouquetContentTV').innerHTML = renderBouquetTable(list0,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
511                 //loading first entry of TV Favorites as default for ServiceList
512                 loadBouquet(list0[0].getServiceReference());
513                 bouqetsMemory["bouqet_tv"] = list0;
514         }
515 }
516 function incomingRadioBouquetList(request){
517         if (request.readyState == 4) {
518                 var list1 = new ServiceList(getXML(request)).getArray();
519                 debug("have "+list1.length+" Radio Bouquet ");  
520                 $('accordionMenueBouquetContentRadio').innerHTML = renderBouquetTable(list1,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
521         }       
522 }
523 function incomingProviderTVBouquetList(request){
524         if (request.readyState == 4) {
525                 var list2 = new ServiceList(getXML(request)).getArray();
526                 debug("have "+list2.length+" TV Provider Bouquet ");    
527                 $('accordionMenueBouquetContentProviderTV').innerHTML = renderBouquetTable(list2,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
528         }       
529 }
530 function incomingProviderRadioBouquetList(request){
531         if (request.readyState == 4) {
532                 var list2 = new ServiceList(getXML(request)).getArray();
533                 debug("have "+list2.length+" Radio Provider Bouquet "); 
534                 $('accordionMenueBouquetContentProviderRadio').innerHTML = renderBouquetTable(list2,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
535         }       
536 }
537
538 function renderBouquetTable(bouquet,templateHeader,templateItem,templateFooter){
539         debug("renderBouquetTable with "+bouquet.length+" Bouqet");     
540         var html = templateHeader;
541         for (var i=0; i < bouquet.length; i++){
542                 try{
543                         var namespace = {
544                                 'servicereference': bouquet[i].getServiceReference(), 
545                                 'bouquetname': bouquet[i].getServiceName()
546                         };
547                         html += RND(templateItem, namespace);
548                 } catch (blubb) {}
549         }
550         html += templateFooter;
551         return html;
552 }       
553
554 function incomingChannellist(request){
555         var services = null;
556         if(typeof(loadedChannellist[servicereftoloadepgnow]) != "undefined"){
557                 services = loadedChannellist[servicereftoloadepgnow];
558         } else if(request.readyState == 4) {
559                 services = new ServiceList(getXML(request)).getArray();
560                 loadedChannellist[servicereftoloadepgnow] = services;
561                 debug("got "+services.length+" Services");
562         }
563         if(services != null) {
564                 var smallNamespace = {'mainServiceRef': servicereftoloadepgnow };
565                 listerHtml = RND(tplServiceListHeader, smallNamespace);
566                 for ( var i = 0; i < services.length ; i++){
567                         var reference = services[i];
568                         var namespace = {       
569                                 'servicereference': reference.getServiceReference(),
570                                 'servicename': reference.getServiceName()
571                         };
572                         listerHtml += RND(tplServiceListItem, namespace);
573                 }               
574                 listerHtml += tplServiceListFooter;
575                 $('BodyContent').innerHTML = listerHtml;
576                 setBodyMainContent('BodyContent');
577                 loadServiceEPGNowNext(servicereftoloadepgnow);
578                 debug("incomingChannellist " + typeof(loadedChannellist[servicereftoloadepgnow]));
579         }
580 }
581 // Movies
582 function loadMovieList(tag){
583         debug("loading movies by tag '"+tag+"'");
584         doRequest(url_movielist+tag, incomingMovieList, false);
585 }
586
587 function incomingMovieList(request){
588         if(request.readyState == 4){
589                 var movies = new MovieList(getXML(request)).getArray();
590                 debug("have "+movies.length+" movies");
591                 listerHtml      = tplMovieListHeader;           
592                 for ( var i = 0; i <movies.length; i++){
593                         var movie = movies[i];
594                         var namespace = {       
595                                 'servicereference': movie.getServiceReference(),
596                                 'servicename': movie.getServiceName() ,
597                                 'title': movie.getTitle(), 
598                                 'description': movie.getDescription(), 
599                                 'descriptionextended': movie.getDescriptionExtended(),
600                                 'filelink': String(movie.getFilename()).substr(17,movie.getFilename().length),
601                                 'filename': String(movie.getFilename()),
602                                 'filesize': movie.getFilesizeMB(),
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 function getSubServices() {
773         doRequest(url_subservices,incomingSubServiceRequest, false);
774 }
775
776 var SubServicePoller = setInterval(getSubServices, 15000);
777 var subServicesInsertedList = new Object();
778
779 function incomingSubServiceRequest(request){
780         if(request.readyState == 4){
781                 var services = new ServiceList(getXML(request)).getArray();
782                 listerHtml      = '';           
783                 debug("got "+services.length+" SubServices");
784                 if(services.length > 1) {
785                         
786                         first = services[0];
787                         var mainChannellist = loadedChannellist[String($('mainServiceRef').value)];
788
789                         last = false
790                         for ( var i = 0; i < services.length ; i++){
791                                 var reference = services[i];
792                                 var namespace = {       
793                                         'servicereference': reference.getServiceReference(),
794                                         'servicename': reference.getServiceName()
795                                 };
796                                 
797                                 if(i != 0){
798                                         listerHtml += RND(tplSubServiceListItem, namespace);
799                                 }
800                                 
801                                 if(last == false){
802                                         last = reference.getServiceReference();
803                                 }
804                                 
805                                 last = reference.getServiceReference();
806
807                         }
808                         //listerHtml += tplSubServiceListFooter;
809                         $(first.getServiceReference()+'sub').innerHTML = listerHtml;
810                         
811                         subServicesInsertedList[String(first.getServiceReference())] = services;
812                         loadedChannellist[$('mainServiceRef').value] = mainChannellist;
813                 }
814         }
815 }
816 // Array.insert( index, value ) - Insert value at index, without overwriting existing keys
817 Array.prototype.insert = function( j, v ) {
818  if( j>=0 ) {
819   var a = this.slice(), b = a.splice( j );
820   a[j] = v;
821   return a.concat( b );
822  }
823 }
824 // Array.splice() - Remove or replace several elements and return any deleted elements
825 if( typeof Array.prototype.splice==='undefined' ) {
826  Array.prototype.splice = function( a, c ) {
827   var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
828   if( !c ) { c = l - a; }
829   for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
830   for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
831   this.length -= c - e.length + 2;
832   return d.slice( f, f + c );
833  };
834 }
835 function writeTimerListNow() {
836         new Ajax.Request( url_timerlistwrite, { asynchronous: true, method: 'get' });
837 }
838 function recordingPushed() {
839         doRequest(url_timerlist, incomingRecordingPushed, false);
840 }
841 function incomingRecordingPushed(request) {
842         if(request.readyState == 4){
843                 var timers = new TimerList(getXML(request)).getArray();
844                 debug("have "+timers.length+" timer");
845                 
846                 var aftereventReadable = new Array ('Nothing', 'Standby', 'Deepstandby/Shutdown');
847                 var justplayReadable = new Array('record', 'zap');
848                 var OnOff = new Array('on', 'off');
849                 
850                 listerHtml = '';
851                 
852                 for ( var i = 0; i <timers.length; i++){
853                         var timer = timers[i];
854
855                         if(ownLazyNumber(timer.getDontSave()) == 1) {
856                                 var beginDate = new Date(Number(timer.getTimeBegin())*1000);
857                                 var endDate = new Date(Number(timer.getTimeEnd())*1000);
858                                 var namespace = {
859                                 'servicereference': timer.getServiceReference(),
860                                 'servicename': timer.getServiceName() ,
861                                 'title': timer.getName(), 
862                                 'description': timer.getDescription(), 
863                                 'descriptionextended': timer.getDescriptionExtended(), 
864                                 'begin': timer.getTimeBegin(),
865                                 'beginDate': beginDate.toLocaleString(),
866                                 'end': timer.getTimeEnd(),
867                                 'endDate': endDate.toLocaleString(),
868                                 'state': timer.getState(),
869                                 'duration': Math.ceil((timer.getDuration()/60)),
870                                 'repeated': timer.getRepeated(),
871                                 'repeatedReadable': repeatedReadable(timer.getRepeated()),
872                                 'justplay': timer.getJustplay(),
873                                 'justplayReadable': justplayReadable[Number(timer.getJustplay())],
874                                 'afterevent': timer.getAfterevent(),
875                                 'aftereventReadable': aftereventReadable[Number(timer.getAfterevent())],
876                                 'disabled': timer.getDisabled(),
877                                 'onOff': OnOff[Number(timer.getDisabled())],
878                                 'color': colorTimerListEntry( timer.getState() )
879                                 };
880                                 listerHtml += RND(tplTimerListItem, namespace);
881                         }
882                 }
883                 openWindow("Record Now", listerHtml+tplRecordingFooter, 900, 500, "Record now window");
884         }
885 }
886 function inserteSizes() {
887 /*      var screenW = 640, screenH = 480;
888         if (parseInt(navigator.appVersion)>3) { 
889                 screenW = screen.width;
890                 screenH = screen.height;
891         } else if (navigator.appName == "Netscape"
892            && parseInt(navigator.appVersion)==3
893            && navigator.javaEnabled() ) {
894                 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
895                 var jScreenSize = jToolkit.getScreenSize();
896                 screenW = jScreenSize.width;
897                 screenH = jScreenSize.height;
898         }
899         debug("screenW:"+screenW+" screenH:"+screenH);
900         /* 640x480
901          * 800x600
902          * 1024x768
903          * 1280x1024
904          * 1600x1280
905         if(screenH == 800) {
906                 debug("size 1");
907                 $("BodyContent").style.height = '20%';
908         } else if(screenH == 1024) {
909                 debug("1024")
910                 $("BodyContent").style.height = '760px';
911                 
912         } else {
913                 alert("unsupported screensize");
914         }*/
915         
916 }
917 function recordingPushedDecision(recordNowNothing,recordNowUndefinitely,recordNowCurrent) {
918         var recordNow = recordNowNothing;
919         recordNow = (recordNow == "") ? recordNowUndefinitely: recordNow;
920         recordNow = (recordNow == "") ? recordNowCurrent: recordNow;
921         if(recordNow != "nothing" && recordNow != "") {
922                 doRequest(url_recordnow+"?recordnow="+recordNow, incomingTimerAddResult, false);
923         }
924 }
925
926 function ifChecked(rObj) {
927         if(rObj.checked) {
928                 return rObj.value;
929         } else {
930                 return "";
931         }
932 }
933 function showAbout() {
934         doRequest(url_about, incomingAbout, false);
935 }
936 function incomingAbout(request) {
937         if(request.readyState == 4){
938                 debug("incomingAbout returned");
939                 var aboutEntries = getXML(request).getElementsByTagName("e2abouts").item(0).getElementsByTagName("e2about");
940                 for (var c =0; c < aboutEntries.length;c++){
941                         var xml = aboutEntries.item(c);
942                         try{
943                                 var fptext = "V"+xml.getElementsByTagName('e2fpversion').item(0).firstChild.data;
944                                 var tunerinfo = "";
945                                 
946                                 var nims = xml.getElementsByTagName('e2tunerinfo').item(0).getElementsByTagName("e2nim");
947                                 debug("nims: "+nims.length);
948                                 for(var i=0;i< nims.length;i++){
949                                         
950                                         name = nims.item(i).getElementsByTagName("name").item(0).firstChild.data;
951                                         type = nims.item(i).getElementsByTagName("type").item(0).firstChild.data;
952                                         debug(name);
953                                         debug(type);
954                                         var ns = { 'name' : name, 'type' : type};
955                                         tunerinfo += RND(tplAboutTuner, ns);
956                                         
957                                 }
958                                 
959                                 var hdddata = xml.getElementsByTagName('e2hddinfo').item(0);
960                                 
961                                 var hddmodel    = hdddata.getElementsByTagName("model").item(0).firstChild.data;
962                                 var hddcapacity = hdddata.getElementsByTagName("capacity").item(0).firstChild.data;
963                                 var hddfree             = hdddata.getElementsByTagName("free").item(0).firstChild.data;
964
965                                 var namespace = {
966                                         'enigmaVersion': xml.getElementsByTagName('e2enigmaversion').item(0).firstChild.data
967 /*
968                                         ,'lanDHCP': xml.getElementsByTagName('e2landhcp').item(0).firstChild.data
969                                         ,'lanIP': xml.getElementsByTagName('e2lanip').item(0).firstChild.data
970                                         ,'lanMask': xml.getElementsByTagName('e2lanmask').item(0).firstChild.data
971                                         ,'lanGW': xml.getElementsByTagName('e2langw').item(0).firstChild.data
972                                         ,'lanDNS': xml.getElementsByTagName('e2landns').item(0).firstChild.data
973 */
974                                         ,'fpVersion': fptext
975                                         ,'webifversion': xml.getElementsByTagName('e2webifversion').item(0).firstChild.data
976                                         ,'tunerInfo': tunerinfo
977                                         ,'hddmodel': hddmodel
978                                         ,'hddcapacity': hddcapacity
979                                         ,'hddfree': hddfree
980                                         ,'serviceName': xml.getElementsByTagName('e2servicename').item(0).firstChild.data
981                                         ,'serviceProvider': xml.getElementsByTagName('e2serviceprovider').item(0).firstChild.data
982                                         ,'serviceAspect': xml.getElementsByTagName('e2serviceaspect').item(0).firstChild.data
983                                         ,'serviceNamespace': xml.getElementsByTagName('e2servicenamespace').item(0).firstChild.data
984                                         ,'vPIDh': '0x'+xml.getElementsByTagName('e2vpid').item(0).firstChild.data
985                                          ,'vPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2vpid').item(0).firstChild.data),16)
986                                         ,'aPIDh': '0x'+xml.getElementsByTagName('e2apid').item(0).firstChild.data
987                                          ,'aPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2apid').item(0).firstChild.data),16)
988                                         ,'pcrIDh': '0x'+xml.getElementsByTagName('e2pcrid').item(0).firstChild.data
989                                          ,'pcrID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2pcrid').item(0).firstChild.data),16)
990                                         ,'pmtPIDh': '0x'+xml.getElementsByTagName('e2pmtpid').item(0).firstChild.data
991                                          ,'pmtPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2pmtpid').item(0).firstChild.data),16)
992                                         ,'txtPIDh': '0x'+xml.getElementsByTagName('e2txtpid').item(0).firstChild.data
993                                          ,'txtPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2txtpid').item(0).firstChild.data),16)
994                                         ,'tsIDh': '0x'+xml.getElementsByTagName('e2tsid').item(0).firstChild.data
995                                          ,'tsID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2tsid').item(0).firstChild.data),16)
996                                         ,'onIDh': '0x'+xml.getElementsByTagName('e2onid').item(0).firstChild.data
997                                          ,'onID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2onid').item(0).firstChild.data),16)
998                                         ,'sidh': '0x'+xml.getElementsByTagName('e2sid').item(0).firstChild.data
999                                          ,'sid': parseInt(ownLazyNumber(xml.getElementsByTagName('e2sid').item(0).firstChild.data),16)
1000                                   };                              
1001                                 $('BodyContent').innerHTML = RND(tplAbout, namespace);
1002                                 setBodyMainContent('BodyContent');
1003                                 
1004                         } catch (e) {
1005                                 debug("About parsing Error" + e);
1006                         }       
1007                 }
1008         }
1009 }
1010 function quotes2html(txt) {
1011         txt = txt.replace(/"/g, '&quot;');
1012         return txt.replace(/'/g, "\\\'");
1013 }
1014
1015 // Spezial functions, mostly for testing purpose
1016 function openHiddenFunctions(){
1017         openWindow("Extra Hidden Functions",tplExtraHiddenFunctions,300,100,920,0);
1018 }
1019 function restartUpdateStream() {
1020         clearInterval(UpdateStreamReaderPollTimer);
1021         UpdateStreamReaderRequest.abort();
1022         UpdateStreamReaderRequest = null;
1023         UpdateStreamReaderPollTimerCounter = 0;
1024         UpdateStreamReaderStart();
1025 }
1026 function startDebugWindow() {
1027         DBG = true;
1028         debugWin = openWindow("DEBUG", "", 300, 300,920,140, "debugWindow");
1029 }
1030 function restartTwisted() {
1031         new Ajax.Request( "/web/restarttwisted", { asynchronous: true, method: "get" })
1032 }
1033 //MediaPlayer
1034 function loadMediaPlayer(directory){
1035         debug("loading loadMediaPlayer");
1036         doRequest(url_mediaplayerlist+directory, incomingMediaPlayer, false);
1037 }
1038 function incomingMediaPlayer(request){
1039         if(request.readyState == 4){
1040                 var files = new FileList(getXML(request)).getArray();
1041                 debug(getXML(request));
1042                 debug("have "+files.length+" entry in filelist");
1043                 listerHtml      = tplMediaPlayerHeader;
1044                 root = files[0].getRoot();
1045                 listerHtml      = RND(tplMediaPlayerHeader, {'root': root});
1046                 if(root != '/') {
1047                         re = new RegExp(/(.*)\/(.*)\/$/);
1048                         re.exec(root);
1049                         newroot = RegExp.$1+'/';
1050                         if(newroot == '//') {
1051                                 newroot = '/';
1052                         }
1053                         listerHtml += RND(tplMediaPlayerItemBody, 
1054                                 {'root': root
1055                                 , 'servicereference': newroot
1056                                 ,'exec': 'loadMediaPlayer'
1057                                 ,'exec_description': 'change to directory ../'
1058                                 ,'color': '000000'
1059                                 ,'root': newroot
1060                                 ,'name': '..'});
1061                 }
1062                 for ( var i = 0; i <files.length; i++){
1063                         var file = files[i];
1064                         if(file.getNameOnly() == 'None') {
1065                                 continue;
1066                         }
1067                         var exec = 'loadMediaPlayer';
1068                         var exec_description = 'change to directory' + file.getServiceReference();
1069                         var color = '000000';
1070                         if (file.getIsDirectory() == "False") {
1071                                 exec = 'playFile';
1072                                 exec_description = 'play file';
1073                                 color = '00BCBC';
1074                         }
1075                         var namespace = {
1076                                 'servicereference': file.getServiceReference()
1077                                 ,'exec': exec
1078                                 ,'exec_description': exec_description
1079                                 ,'color': color
1080                                 ,'root': file.getRoot()
1081                                 ,'name': file.getNameOnly()
1082                         };
1083                         listerHtml += tplMediaPlayerItemHead;
1084                         listerHtml += RND(tplMediaPlayerItemBody, namespace);
1085                         if (file.getIsDirectory() == "False") {
1086                                 listerHtml += RND(tplMediaPlayerItemIMG, namespace);
1087                         }
1088                         listerHtml += tplMediaPlayerItemFooter;
1089                 }
1090                 listerHtml += tplMediaPlayerFooter;
1091                 $('BodyContent').innerHTML = listerHtml;
1092                 var sendMediaPlayerTMP = sendMediaPlayer;
1093                 sendMediaPlayer = false;
1094                 setBodyMainContent('BodyContent');
1095                 sendMediaPlayer = sendMediaPlayerTMP;
1096         }               
1097 }
1098 function playFile(file,root) {
1099         debug("loading playFile");
1100         mediaPlayerStarted = true;
1101         new Ajax.Request( url_mediaplayerplay+file+"&root="+root, { asynchronous: true, method: 'get' });
1102 }
1103 function sendMediaPlayer(command) {
1104         debug("loading sendMediaPlayer");
1105         new Ajax.Request( url_mediaplayercmd+command, { asynchronous: true, method: 'get' });
1106 }
1107 function showPowerStateSendForm(){
1108                 $('BodyContent').innerHTML = tplPowerStateSendForm;
1109 }
1110 function sendPowerState(newState){
1111         new Ajax.Request( url_powerstate+'?newstate='+newState, { asynchronous: true, method: 'get' });
1112 }
1113 function loadFileBrowser(directory,types){
1114         debug("loading loadFileBrowser");
1115         doRequest(url_filelist+directory+"&types="+types, incomingFileBrowser, false);  
1116 }
1117 function incomingFileBrowser(request){
1118         if(request.readyState == 4){
1119                 var files = new FileList(getXML(request)).getArray();
1120                 debug(getXML(request));
1121                 debug("have "+files.length+" entry in filelist");
1122                 listerHtml      = tplFileBrowserHeader;
1123                 root = files[0].getRoot();
1124                 listerHtml      = RND(tplFileBrowserHeader, {'root': root});
1125                 if(root != '/') {
1126                         re = new RegExp(/(.*)\/(.*)\/$/);
1127                         re.exec(root);
1128                         newroot = RegExp.$1+'/';
1129                         if(newroot == '//') {
1130                                 newroot = '/';
1131                         }
1132                         listerHtml += RND(tplFileBrowserItemBody, 
1133                                 {'root': root
1134                                 , 'servicereference': newroot
1135                                 ,'exec': 'loadFileBrowser'
1136                                 ,'exec_description': 'change to directory ../'
1137                                 ,'color': '000000'
1138                                 ,'root': newroot
1139                                 ,'name': '..'});
1140                 }
1141                 for ( var i = 0; i <files.length; i++){
1142                         var file = files[i];
1143                         if(file.getNameOnly() == 'None') {
1144                                 continue;
1145                         }
1146                         var exec = 'loadFileBrowser';
1147                         var exec_description = 'change to directory' + file.getServiceReference();
1148                         var color = '000000';
1149                         if (file.getIsDirectory() == "False") {
1150                                 exec = '';
1151                                 exec_description = 'do Nothing';
1152                                 color = '00BCBC';
1153                         }
1154                         var namespace = {
1155                                 'servicereference': file.getServiceReference()
1156                                 ,'exec': exec
1157                                 ,'exec_description': exec_description
1158                                 ,'color': color
1159                                 ,'root': file.getRoot()
1160                                 ,'name': file.getNameOnly()
1161                         };
1162                         listerHtml += tplFileBrowserItemHead;
1163                         listerHtml += RND(tplFileBrowserItemBody, namespace);
1164                         if (file.getIsDirectory() == "False") {
1165                                 listerHtml += RND(tplFileBrowserItemIMG, namespace);
1166                         }
1167                         listerHtml += tplFileBrowserItemFooter;
1168                 }
1169                 listerHtml += RND(tplFileBrowserFooter, {'root': root});
1170                 $('BodyContent').innerHTML = listerHtml;
1171                 setBodyMainContent('BodyContent');
1172         }               
1173 }
1174 function delFile(file,root) {
1175         debug("loading loadMediaPlayer");
1176         doRequest(url_delfile+root+file, incomingDelFileResult, false);
1177 }
1178 function incomingDelFileResult(request) {
1179         debug("incomingDelFileResult");
1180         if(request.readyState == 4){
1181                 var delresult = new SimpleXMLResult(getXML(request));
1182                 if(delresult.getState()){
1183                         loadFileBrowser($('path').value);
1184                 }else{
1185                         messageBox("Deletion Error","Reason: "+delresult.getStateText());
1186                 }
1187         }               
1188 }
1189
1190 // Notes
1191 function showNotes(){
1192         debug("loading notes");
1193         doRequest(url_notelist, incomingNoteList, false);
1194 }
1195
1196 function incomingNoteList(request){
1197         if(request.readyState == 4){
1198                 var notes = new NoteList(getXML(request)).getArray();
1199                 debug("have "+notes.length+" movies");
1200                 listerHtml      = tplNotesListHeader;           
1201                 for ( var i = 0; i <notes.length; i++){
1202                         var note = notes[i];
1203                         var namespace = {       
1204                                 'name': note.filename,
1205                                 'size': note.size,
1206                                 'ctime': note.getCTime(),
1207                                 'mtime': note.getMTime()
1208                         };
1209                         listerHtml += RND(tplNotesListItem, namespace);
1210                 }
1211                 listerHtml += tplNotesListFooter;
1212                 $('BodyContent').innerHTML = listerHtml;
1213                 setBodyMainContent('BodyContent');
1214                 
1215         }               
1216 }
1217 function showNote(name){
1218         debug("loading note "+name);
1219         doRequest(url_note+name, incomingNote, false);
1220 }
1221
1222 function incomingNote(request){
1223         if(request.readyState == 4){
1224                 var note = new Note(getXML(request));
1225                 var namespace = {       
1226                                 'name': note.filename,
1227                                 'size': note.size,
1228                                 'content': note.content,
1229                                 'ctime': note.getCTime(),
1230                                 'mtime': note.getMTime()
1231                         };
1232                 var html = RND(tplNote, namespace);
1233                 openWindow("Note '"+note.filename+"'", html, 400, 300,50,60);
1234         }               
1235 }
1236 function saveNote(formid){
1237         var nameold = $(formid+'_name').value;
1238         var namenew = $(formid+'_namenew').value;
1239         var content = $(formid+'_content').value;
1240         debug("loading notes"+nameold+namenew+content);
1241         doRequest(url_notelist+"?save="+nameold+"&namenew="+namenew+"&content="+content, incomingNoteSavedResult, false);       
1242         Windows.closeAll();
1243         
1244 }
1245 function incomingNoteSavedResult(request){
1246         if(request.readyState == 4){
1247                 var note = new Note(getXML(request));
1248                 if (note.saved == "True"){
1249                         showNote(note.filename);
1250                         showNotes();
1251                 }
1252         }
1253 }
1254 function createNote(){
1255                 doRequest(url_notelist+"?create=new", incomingNoteCreateResult, false);
1256 }
1257
1258 function incomingNoteCreateResult(request){
1259         if(request.readyState == 4){
1260                 showNotes();
1261         }
1262 }