unix linebreaks
[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, 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 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()", 5000);
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                 setTimeout("getSubServices()", 5000);
578                 loadServiceEPGNowNext(servicereftoloadepgnow);
579                 
580                 debug("incomingChannellist " + typeof(loadedChannellist[servicereftoloadepgnow]));
581         }
582 }
583 // Movies
584 function loadMovieList(tag){
585         debug("loading movies by tag '"+tag+"'");
586         doRequest(url_movielist+tag, incomingMovieList, false);
587 }
588
589 function incomingMovieList(request){
590         if(request.readyState == 4){
591                 var movies = new MovieList(getXML(request)).getArray();
592                 debug("have "+movies.length+" movies");
593                 listerHtml      = tplMovieListHeader;           
594                 for ( var i = 0; i <movies.length; i++){
595                         var movie = movies[i];
596                         var namespace = {       
597                                 'servicereference': movie.getServiceReference(),
598                                 'servicename': movie.getServiceName() ,
599                                 'title': movie.getTitle(), 
600                                 'description': movie.getDescription(), 
601                                 'descriptionextended': movie.getDescriptionExtended(),
602                                 'filelink': String(movie.getFilename()).substr(17,movie.getFilename().length),
603                                 'filename': String(movie.getFilename()),
604                                 'filesize': movie.getFilesizeMB(),
605                                 'tags': movie.getTags().join(', ') ,
606                                 'length': movie.getLength() ,
607                                 'time': movie.getTimeDay()+"&nbsp;"+ movie.getTimeStartString()
608                         };
609                         listerHtml += RND(tplMovieListItem, namespace);
610                 }
611                 listerHtml += tplMovieListFooter;
612                 $('BodyContent').innerHTML = listerHtml;
613                 setBodyMainContent('BodyContent');
614                 
615         }               
616 }
617 function delMovieFile(file,servicename,title,description) {
618         debug("delMovieFile: file("+file+"),servicename("+servicename+"),title("+title+"),description("+description+")");
619         Dialog.confirm(
620                 "Selected timer:<br>"
621                 +"Servicename: "+servicename+"<br>"
622                 +"Title: "+title+"<br>"
623                 +"Description: "+description+"<br>"
624                 +"Are you sure that you want to delete the Timer?",
625                  {windowParameters: {width:300, className: windowStyle},
626                         okLabel: "delete",
627                         buttonClass: "myButtonClass",
628                         cancel: function(win) {debug("delMovieFile cancel confirm panel")},
629                         ok: function(win) { debug("delMovieFile ok confirm panel"); doRequest(url_moviefiledelete+"?filename="+file, incomingDelMovieFileResult, false); return true; }
630                         }
631         );
632         
633 }
634 function incomingDelMovieFileResult(request) {
635         debug("incomingDelMovieFileResult");
636         if(request.readyState == 4){
637                 var delresult = new SimpleXMLResult(getXML(request));
638                 if(delresult.getState()){
639                         loadMovieList('');
640                 }else{
641                         messageBox("Deletion Error","Reason: "+delresult.getStateText());
642                 }
643         }               
644 }
645
646
647 // send Messages
648 function showMessageSendForm(){
649                 $('BodyContent').innerHTML = tplMessageSendForm;
650 }
651 var MessageAnswerPolling;
652 function sendMessage(messagetext,messagetype,messagetimeout){
653         if(!messagetext){
654                 messagetext = $('MessageSendFormText').value;
655         }       
656         if(!messagetimeout){
657                 messagetimeout = $('MessageSendFormTimeout').value;
658         }       
659         if(!messagetype){
660                 var index = $('MessageSendFormType').selectedIndex;
661                 messagetype = $('MessageSendFormType').options[index].value;
662         }       
663         if(ownLazyNumber(messagetype) == 0){
664                 new Ajax.Request(url_message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, { asynchronous: true, method: 'get' });
665                 MessageAnswerPolling = setInterval(getMessageAnswer, ownLazyNumber(messagetimeout)*1000);
666         } else {
667                 doRequest(url_message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, incomingMessageResult, false);
668         }
669 }
670 function incomingMessageResult(request){
671
672         if(request.readyState== 4){
673                 var b = getXML(request).getElementsByTagName("e2message");
674                 var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
675                 var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
676                 if (result=="True"){
677                         messageBox('message send',resulttext);//'message send successfully! it appears on TV-Screen');
678                 }else{
679                         messageBox('message send failed',resulttext);
680                 }
681         }               
682 }
683 function getMessageAnswer() {
684         doRequest(url_messageanswer, incomingMessageResult, false);
685         clearInterval(MessageAnswerPolling);
686 }
687 // RemoteControl Code
688 function showRemoteControllSendForm(){
689         if(! $('rcWindow')){
690                 openWindow("Remote", tplRemoteControlForm, 220, 642, 920,0, "rcWindow");
691         }
692 }
693 function sendRemoteControlRequest(command){
694         doRequest(url_remotecontrol+'?command='+command, incomingRemoteControlResult, false);
695         if($('getScreen').checked) {
696                 openGrabPicture();
697         }
698 }
699 function openGrabPicture() {
700         if($('BodyContent').innerHTML != tplRCGrab) {
701                 $('BodyContent').innerHTML = tplRCGrab;
702         }
703         debug("openGrabPicture");
704         var buffer = new Image();
705         var downloadStart;
706
707         buffer.onload = function () { debug("image zugewiesen"); $('grabPageIMG').src = buffer.src; return true;};
708         buffer.onerror = function (meldung) { debug("reload grab image failed"); return true;};
709
710         downloadStart = new Date().getTime();
711         buffer.src = '/grab?' + downloadStart;
712         $('grabPageIMG').height(400);
713         tplRCGrab = $('BodyContent').innerHTML;
714 }
715 function incomingRemoteControlResult(request){
716         if(request.readyState == 4){
717                 var b = getXML(request).getElementsByTagName("e2remotecontrol");
718                 var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
719                 var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
720         } else {
721                 $('rcWindow').innerHTML = "<h1>some unknown error</h1>" + tplRemoteControlForm;
722         }
723 }
724
725 function getSettings(){
726         doRequest(url_settings, incomingGetSettings, false);
727 }
728
729 function incomingGetSettings(request){
730         if(request.readyState == 4){
731                 settings = new Settings(getXML(request)).getArray();
732         }
733         if(String(getSettingByName("config.ParentalControl.configured")) == "True") {
734                 getParentControl();
735         }
736 }
737 function getSettingByName(txt) {
738         debug("getSettingByName ("+txt+")");
739         for(i = 0; i < settings.length; i++) {
740                 debug("("+settings[i].getSettingName()+") (" +settings[i].getSettingValue()+")");
741                 if(String(settings[i].getSettingName()) == String(txt)) {
742                         return settings[i].getSettingValue();
743                 } 
744         }
745         return "";
746 }
747 function getParentControl() {
748         doRequest(url_parentcontrol, incomingParentControl, false);
749 }
750 function incomingParentControl(request) {
751         if(request.readyState == 4){
752                 parentControlList = new ServiceList(getXML(request)).getArray();
753                 debug("parentControlList got "+parentControlList.length + " services");
754         }
755 }
756 function getParentControlByRef(txt) {
757         debug("getParentControlByRef ("+txt+")");
758         for(i = 0; i < parentControlList.length; i++) {
759                 debug("("+parentControlList[i].getClearServiceReference()+")");
760                 if(String(parentControlList[i].getClearServiceReference()) == String(txt)) {
761                         return parentControlList[i].getClearServiceReference();
762                 } 
763         }
764         return "";
765 }
766 function ownLazyNumber(num) {
767         if(isNaN(num)){
768                 return 0;
769         } else {
770                 return Number(num);
771         }
772 }
773
774 function getSubServices() {
775         doRequest(url_subservices,incomingSubServiceRequest, false);
776 }
777
778 //var SubServicePoller = setInterval(getSubServices, 15000);
779 var subServicesInsertedList = new Object();
780
781 function incomingSubServiceRequest(request){
782         if(request.readyState == 4){
783                 var services = new ServiceList(getXML(request)).getArray();
784                 listerHtml      = '';           
785                 debug("got "+services.length+" SubServices");
786                 if(services.length > 1) {
787                         
788                         first = services[0];
789                         var mainChannellist = loadedChannellist[String($('mainServiceRef').value)];
790
791                         last = false
792                         for ( var i = 0; i < services.length ; i++){
793                                 var reference = services[i];
794                                 var namespace = {       
795                                         'servicereference': reference.getServiceReference(),
796                                         'servicename': reference.getServiceName()
797                                 };
798                                 
799                                 if(i != 0){
800                                         listerHtml += RND(tplSubServiceListItem, namespace);
801                                 }
802                                 
803                                 if(last == false){
804                                         last = reference.getServiceReference();
805                                 }
806                                 
807                                 last = reference.getServiceReference();
808
809                         }
810                         //listerHtml += tplSubServiceListFooter;
811                         $(first.getServiceReference()+'sub').innerHTML = listerHtml;
812                         
813                         subServicesInsertedList[String(first.getServiceReference())] = services;
814                         loadedChannellist[$('mainServiceRef').value] = mainChannellist;
815                 }
816         }
817 }
818 // Array.insert( index, value ) - Insert value at index, without overwriting existing keys
819 Array.prototype.insert = function( j, v ) {
820  if( j>=0 ) {
821   var a = this.slice(), b = a.splice( j );
822   a[j] = v;
823   return a.concat( b );
824  }
825 }
826 // Array.splice() - Remove or replace several elements and return any deleted elements
827 if( typeof Array.prototype.splice==='undefined' ) {
828  Array.prototype.splice = function( a, c ) {
829   var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
830   if( !c ) { c = l - a; }
831   for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
832   for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
833   this.length -= c - e.length + 2;
834   return d.slice( f, f + c );
835  };
836 }
837 function writeTimerListNow() {
838         new Ajax.Request( url_timerlistwrite, { asynchronous: true, method: 'get' });
839 }
840 function recordingPushed() {
841         doRequest(url_timerlist, incomingRecordingPushed, false);
842 }
843 function incomingRecordingPushed(request) {
844         if(request.readyState == 4){
845                 var timers = new TimerList(getXML(request)).getArray();
846                 debug("have "+timers.length+" timer");
847                 
848                 var aftereventReadable = new Array ('Nothing', 'Standby', 'Deepstandby/Shutdown');
849                 var justplayReadable = new Array('record', 'zap');
850                 var OnOff = new Array('on', 'off');
851                 
852                 listerHtml = '';
853                 
854                 for ( var i = 0; i <timers.length; i++){
855                         var timer = timers[i];
856
857                         if(ownLazyNumber(timer.getDontSave()) == 1) {
858                                 var beginDate = new Date(Number(timer.getTimeBegin())*1000);
859                                 var endDate = new Date(Number(timer.getTimeEnd())*1000);
860                                 var namespace = {
861                                 'servicereference': timer.getServiceReference(),
862                                 'servicename': timer.getServiceName() ,
863                                 'title': timer.getName(), 
864                                 'description': timer.getDescription(), 
865                                 'descriptionextended': timer.getDescriptionExtended(), 
866                                 'begin': timer.getTimeBegin(),
867                                 'beginDate': beginDate.toLocaleString(),
868                                 'end': timer.getTimeEnd(),
869                                 'endDate': endDate.toLocaleString(),
870                                 'state': timer.getState(),
871                                 'duration': Math.ceil((timer.getDuration()/60)),
872                                 'repeated': timer.getRepeated(),
873                                 'repeatedReadable': repeatedReadable(timer.getRepeated()),
874                                 'justplay': timer.getJustplay(),
875                                 'justplayReadable': justplayReadable[Number(timer.getJustplay())],
876                                 'afterevent': timer.getAfterevent(),
877                                 'aftereventReadable': aftereventReadable[Number(timer.getAfterevent())],
878                                 'disabled': timer.getDisabled(),
879                                 'onOff': OnOff[Number(timer.getDisabled())],
880                                 'color': colorTimerListEntry( timer.getState() )
881                                 };
882                                 listerHtml += RND(tplTimerListItem, namespace);
883                         }
884                 }
885                 openWindow("Record Now", listerHtml+tplRecordingFooter, 900, 500, "Record now window");
886         }
887 }
888 function inserteSizes() {
889 /*      var screenW = 640, screenH = 480;
890         if (parseInt(navigator.appVersion)>3) { 
891                 screenW = screen.width;
892                 screenH = screen.height;
893         } else if (navigator.appName == "Netscape"
894            && parseInt(navigator.appVersion)==3
895            && navigator.javaEnabled() ) {
896                 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
897                 var jScreenSize = jToolkit.getScreenSize();
898                 screenW = jScreenSize.width;
899                 screenH = jScreenSize.height;
900         }
901         debug("screenW:"+screenW+" screenH:"+screenH);
902         /* 640x480
903          * 800x600
904          * 1024x768
905          * 1280x1024
906          * 1600x1280
907         if(screenH == 800) {
908                 debug("size 1");
909                 $("BodyContent").style.height = '20%';
910         } else if(screenH == 1024) {
911                 debug("1024")
912                 $("BodyContent").style.height = '760px';
913                 
914         } else {
915                 alert("unsupported screensize");
916         }*/
917         
918 }
919 function recordingPushedDecision(recordNowNothing,recordNowUndefinitely,recordNowCurrent) {
920         var recordNow = recordNowNothing;
921         recordNow = (recordNow == "") ? recordNowUndefinitely: recordNow;
922         recordNow = (recordNow == "") ? recordNowCurrent: recordNow;
923         if(recordNow != "nothing" && recordNow != "") {
924                 doRequest(url_recordnow+"?recordnow="+recordNow, incomingTimerAddResult, false);
925         }
926 }
927
928 function ifChecked(rObj) {
929         if(rObj.checked) {
930                 return rObj.value;
931         } else {
932                 return "";
933         }
934 }
935 function showAbout() {
936         doRequest(url_about, incomingAbout, false);
937 }
938 function incomingAbout(request) {
939         if(request.readyState == 4){
940                 debug("incomingAbout returned");
941                 var aboutEntries = getXML(request).getElementsByTagName("e2abouts").item(0).getElementsByTagName("e2about");
942                 for (var c =0; c < aboutEntries.length;c++){
943                         var xml = aboutEntries.item(c);
944                         try{
945                                 var fptext = "V"+xml.getElementsByTagName('e2fpversion').item(0).firstChild.data;
946                                 var tunerinfo = "";
947                                 
948                                 var nims = xml.getElementsByTagName('e2tunerinfo').item(0).getElementsByTagName("e2nim");
949                                 debug("nims: "+nims.length);
950                                 for(var i=0;i< nims.length;i++){
951                                         
952                                         name = nims.item(i).getElementsByTagName("name").item(0).firstChild.data;
953                                         type = nims.item(i).getElementsByTagName("type").item(0).firstChild.data;
954                                         debug(name);
955                                         debug(type);
956                                         var ns = { 'name' : name, 'type' : type};
957                                         tunerinfo += RND(tplAboutTuner, ns);
958                                         
959                                 }
960                                 
961                                 var hdddata = xml.getElementsByTagName('e2hddinfo').item(0);
962                                 
963                                 var hddmodel    = hdddata.getElementsByTagName("model").item(0).firstChild.data;
964                                 var hddcapacity = hdddata.getElementsByTagName("capacity").item(0).firstChild.data;
965                                 var hddfree             = hdddata.getElementsByTagName("free").item(0).firstChild.data;
966
967                                 var namespace = {
968                                         'enigmaVersion': xml.getElementsByTagName('e2enigmaversion').item(0).firstChild.data
969 /*
970                                         ,'lanDHCP': xml.getElementsByTagName('e2landhcp').item(0).firstChild.data
971                                         ,'lanIP': xml.getElementsByTagName('e2lanip').item(0).firstChild.data
972                                         ,'lanMask': xml.getElementsByTagName('e2lanmask').item(0).firstChild.data
973                                         ,'lanGW': xml.getElementsByTagName('e2langw').item(0).firstChild.data
974                                         ,'lanDNS': xml.getElementsByTagName('e2landns').item(0).firstChild.data
975 */
976                                         ,'fpVersion': fptext
977                                         ,'webifversion': xml.getElementsByTagName('e2webifversion').item(0).firstChild.data
978                                         ,'tunerInfo': tunerinfo
979                                         ,'hddmodel': hddmodel
980                                         ,'hddcapacity': hddcapacity
981                                         ,'hddfree': hddfree
982                                         ,'serviceName': xml.getElementsByTagName('e2servicename').item(0).firstChild.data
983                                         ,'serviceProvider': xml.getElementsByTagName('e2serviceprovider').item(0).firstChild.data
984                                         ,'serviceAspect': xml.getElementsByTagName('e2serviceaspect').item(0).firstChild.data
985                                         ,'serviceNamespace': xml.getElementsByTagName('e2servicenamespace').item(0).firstChild.data
986                                         ,'vPIDh': '0x'+xml.getElementsByTagName('e2vpid').item(0).firstChild.data
987                                          ,'vPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2vpid').item(0).firstChild.data),16)
988                                         ,'aPIDh': '0x'+xml.getElementsByTagName('e2apid').item(0).firstChild.data
989                                          ,'aPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2apid').item(0).firstChild.data),16)
990                                         ,'pcrIDh': '0x'+xml.getElementsByTagName('e2pcrid').item(0).firstChild.data
991                                          ,'pcrID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2pcrid').item(0).firstChild.data),16)
992                                         ,'pmtPIDh': '0x'+xml.getElementsByTagName('e2pmtpid').item(0).firstChild.data
993                                          ,'pmtPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2pmtpid').item(0).firstChild.data),16)
994                                         ,'txtPIDh': '0x'+xml.getElementsByTagName('e2txtpid').item(0).firstChild.data
995                                          ,'txtPID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2txtpid').item(0).firstChild.data),16)
996                                         ,'tsIDh': '0x'+xml.getElementsByTagName('e2tsid').item(0).firstChild.data
997                                          ,'tsID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2tsid').item(0).firstChild.data),16)
998                                         ,'onIDh': '0x'+xml.getElementsByTagName('e2onid').item(0).firstChild.data
999                                          ,'onID': parseInt(ownLazyNumber(xml.getElementsByTagName('e2onid').item(0).firstChild.data),16)
1000                                         ,'sidh': '0x'+xml.getElementsByTagName('e2sid').item(0).firstChild.data
1001                                          ,'sid': parseInt(ownLazyNumber(xml.getElementsByTagName('e2sid').item(0).firstChild.data),16)
1002                                   };                              
1003                                 $('BodyContent').innerHTML = RND(tplAbout, namespace);
1004                                 setBodyMainContent('BodyContent');
1005                                 
1006                         } catch (e) {
1007                                 debug("About parsing Error" + e);
1008                         }       
1009                 }
1010         }
1011 }
1012 function quotes2html(txt) {
1013         txt = txt.replace(/"/g, '&quot;');
1014         return txt.replace(/'/g, "\\\'");
1015 }
1016
1017 // Spezial functions, mostly for testing purpose
1018 function openHiddenFunctions(){
1019         openWindow("Extra Hidden Functions",tplExtraHiddenFunctions,300,100,920,0);
1020 }
1021 function restartUpdateStream() {
1022         clearInterval(UpdateStreamReaderPollTimer);
1023         UpdateStreamReaderRequest.abort();
1024         UpdateStreamReaderRequest = null;
1025         UpdateStreamReaderPollTimerCounter = 0;
1026         UpdateStreamReaderStart();
1027 }
1028 function startDebugWindow() {
1029         DBG = true;
1030         debugWin = openWindow("DEBUG", "", 300, 300,920,140, "debugWindow");
1031 }
1032 function restartTwisted() {
1033         new Ajax.Request( "/web/restarttwisted", { asynchronous: true, method: "get" })
1034 }
1035 //MediaPlayer
1036 function loadMediaPlayer(directory){
1037         debug("loading loadMediaPlayer");
1038         doRequest(url_mediaplayerlist+directory, incomingMediaPlayer, false);
1039 }
1040 function incomingMediaPlayer(request){
1041         if(request.readyState == 4){
1042                 var files = new FileList(getXML(request)).getArray();
1043                 debug(getXML(request));
1044                 debug("have "+files.length+" entry in filelist");
1045                 listerHtml      = tplMediaPlayerHeader;
1046                 root = files[0].getRoot();
1047                 listerHtml      = RND(tplMediaPlayerHeader, {'root': root});
1048                 if(root != '/') {
1049                         re = new RegExp(/(.*)\/(.*)\/$/);
1050                         re.exec(root);
1051                         newroot = RegExp.$1+'/';
1052                         if(newroot == '//') {
1053                                 newroot = '/';
1054                         }
1055                         listerHtml += RND(tplMediaPlayerItemBody, 
1056                                 {'root': root
1057                                 , 'servicereference': newroot
1058                                 ,'exec': 'loadMediaPlayer'
1059                                 ,'exec_description': 'change to directory ../'
1060                                 ,'color': '000000'
1061                                 ,'root': newroot
1062                                 ,'name': '..'});
1063                 }
1064                 for ( var i = 0; i <files.length; i++){
1065                         var file = files[i];
1066                         if(file.getNameOnly() == 'None') {
1067                                 continue;
1068                         }
1069                         var exec = 'loadMediaPlayer';
1070                         var exec_description = 'change to directory' + file.getServiceReference();
1071                         var color = '000000';
1072                         if (file.getIsDirectory() == "False") {
1073                                 exec = 'playFile';
1074                                 exec_description = 'play file';
1075                                 color = '00BCBC';
1076                         }
1077                         var namespace = {
1078                                 'servicereference': file.getServiceReference()
1079                                 ,'exec': exec
1080                                 ,'exec_description': exec_description
1081                                 ,'color': color
1082                                 ,'root': file.getRoot()
1083                                 ,'name': file.getNameOnly()
1084                         };
1085                         listerHtml += tplMediaPlayerItemHead;
1086                         listerHtml += RND(tplMediaPlayerItemBody, namespace);
1087                         if (file.getIsDirectory() == "False") {
1088                                 listerHtml += RND(tplMediaPlayerItemIMG, namespace);
1089                         }
1090                         listerHtml += tplMediaPlayerItemFooter;
1091                 }
1092                 listerHtml += tplMediaPlayerFooter;
1093                 $('BodyContent').innerHTML = listerHtml;
1094                 var sendMediaPlayerTMP = sendMediaPlayer;
1095                 sendMediaPlayer = false;
1096                 setBodyMainContent('BodyContent');
1097                 sendMediaPlayer = sendMediaPlayerTMP;
1098         }               
1099 }
1100 function playFile(file,root) {
1101         debug("loading playFile");
1102         mediaPlayerStarted = true;
1103         new Ajax.Request( url_mediaplayerplay+file+"&root="+root, { asynchronous: true, method: 'get' });
1104 }
1105 function sendMediaPlayer(command) {
1106         debug("loading sendMediaPlayer");
1107         new Ajax.Request( url_mediaplayercmd+command, { asynchronous: true, method: 'get' });
1108 }
1109 function showPowerStateSendForm(){
1110                 $('BodyContent').innerHTML = tplPowerStateSendForm;
1111 }
1112 function sendPowerState(newState){
1113         new Ajax.Request( url_powerstate+'?newstate='+newState, { asynchronous: true, method: 'get' });
1114 }
1115 function loadFileBrowser(directory,types){
1116         debug("loading loadFileBrowser");
1117         doRequest(url_filelist+directory+"&types="+types, incomingFileBrowser, false);  
1118 }
1119 function incomingFileBrowser(request){
1120         if(request.readyState == 4){
1121                 var files = new FileList(getXML(request)).getArray();
1122                 debug(getXML(request));
1123                 debug("have "+files.length+" entry in filelist");
1124                 listerHtml      = tplFileBrowserHeader;
1125                 root = files[0].getRoot();
1126                 listerHtml      = RND(tplFileBrowserHeader, {'root': root});
1127                 if(root != '/') {
1128                         re = new RegExp(/(.*)\/(.*)\/$/);
1129                         re.exec(root);
1130                         newroot = RegExp.$1+'/';
1131                         if(newroot == '//') {
1132                                 newroot = '/';
1133                         }
1134                         listerHtml += RND(tplFileBrowserItemBody, 
1135                                 {'root': root
1136                                 , 'servicereference': newroot
1137                                 ,'exec': 'loadFileBrowser'
1138                                 ,'exec_description': 'change to directory ../'
1139                                 ,'color': '000000'
1140                                 ,'root': newroot
1141                                 ,'name': '..'});
1142                 }
1143                 for ( var i = 0; i <files.length; i++){
1144                         var file = files[i];
1145                         if(file.getNameOnly() == 'None') {
1146                                 continue;
1147                         }
1148                         var exec = 'loadFileBrowser';
1149                         var exec_description = 'change to directory' + file.getServiceReference();
1150                         var color = '000000';
1151                         if (file.getIsDirectory() == "False") {
1152                                 exec = '';
1153                                 exec_description = 'do Nothing';
1154                                 color = '00BCBC';
1155                         }
1156                         var namespace = {
1157                                 'servicereference': file.getServiceReference()
1158                                 ,'exec': exec
1159                                 ,'exec_description': exec_description
1160                                 ,'color': color
1161                                 ,'root': file.getRoot()
1162                                 ,'name': file.getNameOnly()
1163                         };
1164                         listerHtml += tplFileBrowserItemHead;
1165                         listerHtml += RND(tplFileBrowserItemBody, namespace);
1166                         if (file.getIsDirectory() == "False") {
1167                                 listerHtml += RND(tplFileBrowserItemIMG, namespace);
1168                         }
1169                         listerHtml += tplFileBrowserItemFooter;
1170                 }
1171                 listerHtml += RND(tplFileBrowserFooter, {'root': root});
1172                 $('BodyContent').innerHTML = listerHtml;
1173                 setBodyMainContent('BodyContent');
1174         }               
1175 }
1176 function delFile(file,root) {
1177         debug("loading loadMediaPlayer");
1178         doRequest(url_delfile+root+file, incomingDelFileResult, false);
1179 }
1180 function incomingDelFileResult(request) {
1181         debug("incomingDelFileResult");
1182         if(request.readyState == 4){
1183                 var delresult = new SimpleXMLResult(getXML(request));
1184                 if(delresult.getState()){
1185                         loadFileBrowser($('path').value);
1186                 }else{
1187                         messageBox("Deletion Error","Reason: "+delresult.getStateText());
1188                 }
1189         }               
1190 }
1191
1192 // Notes
1193 function showNotes(){
1194         debug("loading notes");
1195         doRequest(url_notelist, incomingNoteList, false);
1196 }
1197
1198 function incomingNoteList(request){
1199         if(request.readyState == 4){
1200                 var notes = new NoteList(getXML(request)).getArray();
1201                 debug("have "+notes.length+" movies");
1202                 listerHtml      = tplNotesListHeader;           
1203                 for ( var i = 0; i <notes.length; i++){
1204                         var note = notes[i];
1205                         var namespace = {       
1206                                 'name': note.filename,
1207                                 'size': note.size,
1208                                 'ctime': note.getCTime(),
1209                                 'mtime': note.getMTime()
1210                         };
1211                         listerHtml += RND(tplNotesListItem, namespace);
1212                 }
1213                 listerHtml += tplNotesListFooter;
1214                 $('BodyContent').innerHTML = listerHtml;
1215                 setBodyMainContent('BodyContent');
1216                 
1217         }               
1218 }
1219 function showNote(name){
1220         debug("loading note "+name);
1221         doRequest(url_note+name, incomingNote, false);
1222 }
1223
1224 function incomingNote(request){
1225         if(request.readyState == 4){
1226                 var note = new Note(getXML(request));
1227                 var namespace = {       
1228                                 'name': note.filename,
1229                                 'size': note.size,
1230                                 'content': note.content,
1231                                 'ctime': note.getCTime(),
1232                                 'mtime': note.getMTime()
1233                         };
1234                 var html = RND(tplNote, namespace);
1235                 openWindow("Note '"+note.filename+"'", html, 400, 300,50,60);
1236         }               
1237 }
1238 function saveNote(formid){
1239         var nameold = $(formid+'_name').value;
1240         var namenew = $(formid+'_namenew').value;
1241         var content = $(formid+'_content').value;
1242         debug("loading notes"+nameold+namenew+content);
1243         doRequest(url_notelist+"?save="+nameold+"&namenew="+namenew+"&content="+content, incomingNoteSavedResult, false);       
1244         Windows.closeAll();
1245         
1246 }
1247 function incomingNoteSavedResult(request){
1248         if(request.readyState == 4){
1249                 var note = new Note(getXML(request));
1250                 if (note.saved == "True"){
1251                         showNote(note.filename);
1252                         showNotes();
1253                 }
1254         }
1255 }
1256 function createNote(){
1257                 doRequest(url_notelist+"?create=new", incomingNoteCreateResult, false);
1258 }
1259
1260 function incomingNoteCreateResult(request){
1261         if(request.readyState == 4){
1262                 showNotes();
1263         }
1264 }