Make updateIntervals configurable (Extras->Settings) on Client-Side.
[enigma2-plugins.git] / webinterface / src / web-data / tools.js
1 //$Header$
2 var templates = {};
3 var loadedChannellist = {};
4
5 var epgListData = {};
6 var signalPanelData = {};
7
8 var mediaPlayerStarted = false; 
9 var popUpBlockerHinted = false;
10
11 var settings = null;
12 var parentControlList = null;
13
14 var requestcounter = 0;
15
16 var debugWin = '';
17 var signalWin = '';
18 var webRemoteWin = '';
19 var EPGListWin = '';
20
21 var currentBouquet = bouquetsTv;
22
23 var updateBouquetItemsPoller = '';
24 var updateCurrentPoller = '';
25 var signalPanelUpdatePoller = '';
26
27 var hideNotifierTimeout = '';
28
29 var isActive = {};
30 isActive.getCurrent = false;
31
32 var currentLocation = "/hdd/movie";
33 var locationsList = [];
34 var tagsList = [];
35
36 var boxtype = "";
37
38 function startUpdateCurrentPoller(){
39         clearInterval(updateCurrentPoller);
40         updateCurrentPoller = setInterval(updateItems, userprefs.data.updateCurrentInterval);
41 }
42
43 function stopUpdateCurrentPoller(){
44         clearInterval(updateCurrentPoller);
45 }
46
47 function getXML(request){
48         var xmlDoc = "";
49
50         if(window.ActiveXObject){ // we're on IE
51                 xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
52                 xmlDoc.async="false";
53                 xmlDoc.loadXML(request.responseText);
54         } else { //we're not on IE
55                 if (!window.google || !google.gears){
56                         xmlDoc = request.responseXML;
57                 } else { //no responseXML on gears
58                         xmlDoc = (new DOMParser()).parseFromString(request.responseText, "text/xml");
59                 }
60         }
61
62         return xmlDoc;
63 }
64 /*
65 * Set boxtype Variable for being able of determining model specific stuff correctly (like WebRemote)
66 */
67 function incomingDeviceInfoBoxtype(request){
68         debug("[incomingAboutBoxtype] returned");
69         boxtype = getXML(request).getElementsByTagName("e2devicename").item(0).firstChild.data;
70
71         debug("[incomingAboutBoxtype] Boxtype: " + boxtype);
72 }
73
74
75 function getBoxtype(){
76         doRequest(URL.deviceinfo, incomingDeviceInfoBoxtype, false);
77 }
78
79 function toggleStandby(){
80         sendPowerState(0);
81 }
82
83 function incomingPowerState(request){
84         var standby = getXML(request).getElementsByTagName("e2instandby").item(0).firstChild.data;
85         
86         var signal = $('openSignalPanel');
87         var signalImg = $('openSignalPanelImg');
88         
89         if(standby.strip() == "false"){
90                 signal.stopObserving('click', openSignalPanel);
91                 signal.observe('click', openSignalPanel);
92                 
93                 signalImg.src = "/web-data/img/signal.png";
94                 signalImg.title = "Show Signal Panel";
95                 
96         } else {
97                 signal.stopObserving('click', openSignalPanel);         
98                 
99                 signalImg.src = "/web-data/img/signal_off.png";
100                 signalImg.title = "Please disable standby first";
101         }
102 }
103
104 function getPowerState(){
105         doRequest(URL.powerstate, incomingPowerState);  
106 }
107
108 function set(element, value){
109         element = parent.$(element);
110         if (element){
111                 element.innerHTML = value;
112         }
113 }
114
115 function hideNotifier(){
116         $('notification').fade({duration : 0.5 });
117 }
118
119 function notify(text, state){
120         notif = $('notification');
121
122         if(notif !== null){
123                 //clear possibly existing hideNotifier timeout of a previous notfication
124                 clearTimeout(hideNotifierTimeout);
125                 if(state === false){
126                         notif.style.background = "#C00";
127                 } else {
128                         notif.style.background = "#85C247";
129                 }                               
130
131                 set('notification', "<div>"+text+"</div>");
132                 notif.appear({duration : 0.5, to: 0.9 });
133                 hideNotifierTimeout = setTimeout(hideNotifier, 7500);
134         }
135 }
136
137
138 function simpleResultHandler(simpleResult){
139         notify(simpleResult.statetext, simpleResult.state);
140 }
141
142
143 function startUpdateBouquetItemsPoller(){
144         debug("[startUpdateBouquetItemsPoller] called");
145         clearInterval(updateBouquetItemsPoller);
146         updateBouquetItemsPoller = setInterval(updateItemsLazy, userprefs.data.updateBouquetInterval);
147 }
148
149
150 function stopUpdateBouquetItemsPoller(){
151         debug("[stopUpdateBouquetItemsPoller] called");
152         clearInterval(updateBouquetItemsPoller);
153 }
154
155
156 //General Helpers
157 function parseNr(num) {
158         if(isNaN(num)){
159                 return 0;
160         } else {
161                 return Number(num);
162         }
163 }
164
165
166 function dec2hex(nr, len){
167
168         var hex = parseInt(nr, 10).toString(16).toUpperCase();
169         if(len > 0){
170                 try{
171                         while(hex.length < len){
172                                 hex = "0"+hex;
173                         }
174                 } 
175                 catch(e){
176                         //something went wrong, return -1
177                         hex = -1;
178                 }
179         } 
180         return hex;
181 }
182
183
184 function quotes2html(txt) {
185         if(typeof(txt) != "undefined"){
186                 return txt.escapeHTML().replace('\n', '<br>');
187         } else {
188                 return "";
189         }
190 }
191
192 function addLeadingZero(nr){
193         if(nr < 10){
194                 return '0' + nr;
195         }
196         return nr;
197 }
198
199 function dateToString(date){
200
201         var dateString = "";
202
203         dateString += date.getFullYear();
204         dateString += "-" + addLeadingZero(date.getMonth()+1);
205         dateString += "-" + addLeadingZero(date.getDate());
206         dateString += " " + addLeadingZero(date.getHours());
207         dateString += ":" + addLeadingZero(date.getMinutes());
208
209         return dateString;
210 }
211
212
213 function showhide(id){
214         var s = $(id).style;
215         s.display = (s.display!="none")? "none":"";
216 }
217
218
219 function show(id){
220         try{
221                 $(id).style.display = "";
222         } catch(e) {
223                 debug("[show] Could not show element with id: " + id);
224         }
225 }
226
227
228 function hide(id){
229         try{
230                 $(id).style.display = "none";
231         } catch(e) {
232                 debug("[hide] Could not hide element with id: " + id);
233         }
234 }
235
236
237 /*
238 * Sets the Loading Notification to the given HTML Element
239 * @param targetElement - The element the Ajax-Loader should be set in
240 */
241 function setAjaxLoad(targetElement){
242         $(targetElement).innerHTML = getAjaxLoad();
243 }
244
245
246 //Ajax Request Helpers
247 //requestindikator
248
249 function requestIndicatorUpdate(){
250         /*debug(requestcounter+" open requests");
251         if(requestcounter>=1){
252                 $('RequestIndicator').style.display = "inline";
253         }else{
254                 $('RequestIndicator').style.display = "none";
255         }*/
256 }
257
258 function requestStarted(){
259         requestcounter +=1;
260         requestIndicatorUpdate();
261 }
262
263 function requestFinished(){
264         requestcounter -= 1;
265         requestIndicatorUpdate();
266 }
267
268 //Popup And Messagebox Helpers
269 function messageBox(m){
270         alert(m);
271 }
272
273
274 function popUpBlockerHint(){
275         if(!popUpBlockerHinted){
276                 popUpBlockerHinted = true;
277                 messageBox("Please disable your Popup-Blocker for enigma2 WebControl to work flawlessly!");
278
279         }
280 }
281
282 function setWindowContent(window, html){
283         window.document.write(html);
284         window.document.close();
285 }
286
287 function openPopup(title, html, width, height, x, y){
288         try {
289                 var popup = window.open('about:blank',title,'scrollbars=yes, width='+width+',height='+height);          
290                 setWindowContent(popup, html);
291                 return popup;
292         } catch(e){
293                 popUpBlockerHint();
294                 return "";
295         }
296 }
297
298 function openPopupPage(title, uri, width, height, x, y){
299         try {
300                 var popup = window.open(uri,title,'scrollbars=yes, width='+width+',height='+height);
301                 return popup;
302         } catch(e){
303                 popUpBlockerHint();
304                 return "";
305         }
306 }
307
308 function debug(text){
309         var DBG = userprefs.data.debug || false;
310         
311         if(DBG){
312                 try{
313                         if(!debugWin.closed && debugWin.location){
314                                 var inner = debugWin.document.getElementById('debugContent').innerHTML;
315                                 debugWin.document.getElementById('debugContent').innerHTML = new Date().toLocaleString() + ": "+text+"<br>" + inner;
316                         } else {                        
317                                 openDebug();
318                                 
319                                 setTimeout(     function(){
320                                                                         var inner = debugWin.document.getElementById('debugContent').innerHTML;
321                                                                         debugWin.document.getElementById('debugContent').innerHTML = new Date().toLocaleString() + ": "+text+"<br>" + inner;
322                                                                 }, 
323                                                                 1000
324                                                         );
325                         }
326                 } catch (Exception) {}
327         }
328 }
329
330 function saveSettings(){
331         userprefs.load();
332         
333         var debug = $('enableDebug').checked;
334         var changed = false;
335         if(typeof(debug) != "undefined"){
336                 if( userprefs.data.debug != debug ){
337                         userprefs.data.debug = debug;
338                         changed = true;
339         
340                         if(debug){
341                                 openDebug();
342                         }
343                 }               
344         }
345         
346         var updateCurrentInterval = $F('updateCurrentInterval');
347         if( isNaN(updateCurrentInterval) || parseNr(updateCurrentInterval) < 10000){
348                 updateCurrentInterval = 120000;
349         }
350         
351         if( userprefs.data.updateCurrentInterval != updateCurrentInterval){
352                 userprefs.data.updateCurrentInterval = updateCurrentInterval;
353                 
354                 changed = true;
355                 startUpdateCurrentPoller();
356         }
357         
358         var updateBouquetInterval = $F('updateBouquetInterval');
359         if( isNaN(updateBouquetInterval) || parseNr(updateBouquetInterval) < 60000){
360                 updateBouquetInterval = 300000;
361         }
362         
363         if( userprefs.data.updateBouquetInterval != updateBouquetInterval){
364                 userprefs.data.updateBouquetInterval = updateBouquetInterval;
365                 
366                 changed = true;
367                 startUpdateBouquetItemsPoller();
368         }
369         
370         if(changed){
371                 userprefs.save();
372         }
373 }
374
375 //Template Helpers
376 function saveTpl(request, tplName){
377         debug("[saveTpl] saving template: " + tplName);
378         templates[tplName] = request.responseText;
379 }
380
381
382 function renderTpl(tpl, data, domElement) {     
383         var result = tpl.process(data);
384
385         try{
386                 $(domElement).innerHTML = result;
387         }catch(ex){
388                 //              debug("[renderTpl] exception: " + ex);
389         }
390 }
391
392
393 function fetchTpl(tplName, callback){
394         if(typeof(templates[tplName]) == "undefined") {
395                 var url = URL.tpl+tplName+".htm";
396
397                 doRequest(
398                                 url, 
399                                 function(transport){
400                                         saveTpl(transport, tplName);
401                                         if(typeof(callback) == 'function'){
402                                                 callback();
403                                         }
404                                 }
405                 );
406         } else {
407                 if(typeof(callback) == 'function'){
408                         callback();
409                 }
410         }
411 }
412
413 function incomingProcessTpl(request, data, domElement, callback){
414         if(request.readyState == 4){
415                 renderTpl(request.responseText, data, domElement);
416                 if(typeof(callback) == 'function') {
417                         callback();
418                 }
419         }
420 }
421
422 function processTpl(tplName, data, domElement, callback){
423         var url = URL.tpl+tplName+".htm";
424
425         doRequest(url, 
426                         function(transport){
427                 incomingProcessTpl(transport, data, domElement, callback);
428         }
429         );
430 }
431
432 //Debugging Window
433
434
435 function openDebug(){
436         var uri = URL.tpl+'tplDebug.htm';
437         debugWin = openPopupPage("Debug", uri, 500, 300);
438 }
439
440 function doRequest(url, readyFunction){
441         requestStarted();
442         var request = '';
443         // gears or not that's the question here
444         if (!window.google || !google.gears){ //no gears, how sad
445 //              debug("NO GEARS!!");            
446                 try{
447                         request = new Ajax.Request(url,
448                                         {
449                                 asynchronous: true,
450                                 method: 'GET',
451                                 requestHeaders: ['Pragma', 'no-cache', 'Cache-Control', 'no-cache', 'Cache-Control', 'no-store', 'Expires', '0'],
452                                 onException: function(o,e){ throw(e); },                                
453                                 onSuccess: function (transport, json) {                                         
454                                         if(typeof(readyFunction) != "undefined"){
455                                                 readyFunction(transport);
456                                         }
457                                 },
458                                 onComplete: requestFinished 
459                                         });
460                 } catch(e) {}
461         } else { //we're on gears!
462                 try{
463                         request = google.gears.factory.create('beta.httprequest');
464                         request.open('GET', url);
465
466                         if( typeof(readyFunction) != "undefined" ){
467                                 request.onreadystatechange = function(){                                
468                                         if(request.readyState == 4){
469                                                 if(request.status == 200){                      
470                                                         readyFunction(request);
471                                                 } else {
472                                                         //we COULD do some error handling here
473                                                 }
474                                         }
475                                 };
476                         }
477                         request.send();
478                 } catch(e) {}
479         }
480 }
481
482 //Parental Control
483 function incomingParentControl(request) {
484         if(request.readyState == 4){
485                 parentControlList = new ServiceList(getXML(request)).getArray();
486                 debug("[incomingParentControl] Got "+parentControlList.length + " services");
487         }
488 }
489
490 function getParentControl() {
491         doRequest(URL.parentcontrol, incomingParentControl, false);
492 }
493
494
495 function getParentControlByRef(txt) {
496         debug("[getParentControlByRef] ("+txt+")");
497         for(var i = 0; i < parentControlList.length; i++) {
498                 debug( "[getParentControlByRef] "+parentControlList[i].getClearServiceReference() );
499                 if(String(parentControlList[i].getClearServiceReference()) == String(txt)) {
500                         return parentControlList[i].getClearServiceReference();
501                 } 
502         }
503         return "";
504 }
505
506
507 //Settings
508 function getSettingByName(txt) {
509         debug("[getSettingByName] (" + txt + ")");
510         for(var i = 0; i < settings.length; i++) {
511                 debug("("+settings[i].getSettingName()+") (" +settings[i].getSettingValue()+")");
512                 if(String(settings[i].getSettingName()) == String(txt)) {
513                         return settings[i].getSettingValue().toLowerCase();
514                 } 
515         }
516         return "";
517 }
518
519 function parentPin(servicereference) {
520         debug("[parentPin] parentControlList");
521         servicereference = decodeURIComponent(servicereference);
522         if(parentControlList === null || String(getSettingByName("config.ParentalControl.configured")) != "true") {
523                 return true;
524         }
525         //debug("parentPin " + parentControlList.length);
526         if(getParentControlByRef(servicereference) == servicereference) {
527                 if(String(getSettingByName("config.ParentalControl.type.value")) == "whitelist") {
528                         debug("[parentPin] Channel in whitelist");
529                         return true;
530                 }
531         } else {
532                 debug("[parentPin] sRef differs ");
533                 return true;
534         }
535         debug("[parentPin] Asking for PIN");
536
537         var userInput = prompt('Parental Control is enabled!<br> Please enter the Parental Control PIN','PIN');
538         if (userInput !== '' && userInput !== null) {
539                 if(String(userInput) == String(getSettingByName("config.ParentalControl.servicepin.0")) ) {
540                         return true;
541                 } else {
542                         return parentPin(servicereference);
543                 }
544         } else {
545                 return false;
546         }
547 }
548
549
550 function incomingGetDreamboxSettings(request){
551         if(request.readyState == 4){
552                 settings = new Settings(getXML(request)).getArray();
553
554                 debug("[incomingGetDreamboxSettings] config.ParentalControl.configured="+ getSettingByName("config.ParentalControl.configured"));
555
556                 if(String(getSettingByName("config.ParentalControl.configured")) == "true") {
557                         getParentControl();
558                 }
559         }
560 }
561
562
563 function getDreamboxSettings(){
564         doRequest(URL.settings, incomingGetDreamboxSettings, false);
565 }
566
567
568 //Subservices
569 function incomingSubServiceRequest(request){
570         if(request.readyState == 4){
571                 var services = new ServiceList(getXML(request)).getArray();
572                 debug("[incomingSubServiceRequest] Got " + services.length + " SubServices");
573
574                 if(services.length > 1) {
575
576                         var first = services[0];
577
578                         // we already have the main service in our servicelist so we'll
579                         // start with the second element                        
580                         services.shift();
581                         
582                         var data = { subservices : services };
583                         
584
585                         var id = 'SUB'+first.servicereference;
586                         show('tr' + id);
587                         processTpl('tplSubServices', data, id);
588                 }
589         }
590 }
591
592
593 function getSubServices(bouquet) {
594         doRequest(URL.subservices, incomingSubServiceRequest, false);
595 }
596
597
598 function delayedGetSubservices(){
599         setTimeout(getSubServices, 5000);
600 }
601
602 //zap zap
603 function zap(servicereference){
604         doRequest("/web/zap?sRef=" + servicereference); 
605         setTimeout(updateItemsLazy, 7000); //reload epg and subservices
606         setTimeout(updateItems, 3000);
607 }
608
609 //SignalPanel
610
611 function updateSignalPanel(){   
612         var html = templates.tplSignalPanel.process(signalPanelData);
613
614         if (!signalWin.closed && signalWin.location) {
615                 setWindowContent(signalWin, html);
616         } else {
617                 clearInterval(signalPanelUpdatePoller);
618                 signalPanelUpdatePoller = '';
619         }
620 }
621
622 function incomingSignalPanel(request){
623         var namespace = {};
624
625         if (request.readyState == 4){
626                 var xml = getXML(request).getElementsByTagName("e2frontendstatus").item(0);
627                 namespace = {
628                                 snrdb : xml.getElementsByTagName('e2snrdb').item(0).firstChild.data,
629                                 snr : xml.getElementsByTagName('e2snr').item(0).firstChild.data,
630                                 ber : xml.getElementsByTagName('e2ber').item(0).firstChild.data,
631                                 acg : xml.getElementsByTagName('e2acg').item(0).firstChild.data
632                 };
633         }
634
635         signalPanelData = { signal : namespace };
636         fetchTpl('tplSignalPanel', updateSignalPanel);  
637 }
638
639 function reloadSignalPanel(){
640         doRequest(URL.signal, incomingSignalPanel, false);
641 }
642
643 function openSignalPanel(){
644         if (!(!signalWin.closed && signalWin.location)){
645                 signalWin = openPopup('SignalPanel', '', 220, 120);
646                 if(signalPanelUpdatePoller === ''){
647                         signalPanelUpdatePoller = setInterval(reloadSignalPanel, 5000);
648                 }
649         }
650         reloadSignalPanel();
651 }
652
653 //EPG functions
654
655
656 function showEpgList(){
657         var html = templates.tplEpgList.process(epgListData);
658
659         if (!EPGListWin.closed && EPGListWin.location) {
660                 setWindowContent(EPGListWin, html);
661         } else {
662                 EPGListWin = openPopup("EPG", html, 900, 500);
663         }
664 }
665
666 function incomingEPGrequest(request){
667         debug("[incomingEPGrequest] readyState" +request.readyState);           
668         if (request.readyState == 4){
669                 var EPGItems = new EPGList(getXML(request)).getArray(true);
670                 debug("[incomingEPGrequest] got "+EPGItems.length+" e2events");
671
672                 if( EPGItems.length > 0){
673                         epgListData = {epg : EPGItems};
674                         fetchTpl('tplEpgList', showEpgList);
675                 } else {
676                         messageBox('No Items found!', 'Sorry but I could not find any EPG Content containing your search value');
677                 }
678         }
679 }
680
681 function loadEPGBySearchString(string){
682         doRequest(URL.epgsearch+escape(string),incomingEPGrequest, false);
683 }
684
685 function loadEPGByServiceReference(servicereference){
686         doRequest(URL.epgservice+servicereference,incomingEPGrequest, false);
687 }
688
689 function buildServiceListEPGItem(epgevent, type){
690         var data = { epg : epgevent,
691                                  nownext: type
692                                 };
693         // e.innerHTML = RND(tplServiceListEPGItem, namespace);
694
695         var id = type + epgevent.servicereference;
696
697         show('tr' + id);
698
699         if(typeof(templates.tplServiceListEPGItem) != "undefined"){
700                 renderTpl(templates.tplServiceListEPGItem, data, id, true);
701         } else {
702                 debug("[buildServiceListEPGItem] tplServiceListEPGItem N/A");
703         }
704 }
705
706 function incomingServiceEPGNowNext(request, type){
707         if(request.readyState == 4){
708                 var epgevents = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
709                 for (var c = 0; c < epgevents.length; c++){
710                         try{
711                                 var epgEvt = new EPGEvent(epgevents.item(c), c).toJSON();
712                         } catch (e){
713                                 debug("[incomingServiceEPGNowNext]" + e);
714                         }
715
716                         if (epgEvt.eventid != ''){
717                                 buildServiceListEPGItem(epgEvt, type);
718                         }
719                 }
720         }
721 }
722
723 function incomingServiceEPGNow(request){
724         incomingServiceEPGNowNext(request, 'NOW');
725 }
726
727 function incomingServiceEPGNext(request){
728         incomingServiceEPGNowNext(request, 'NEXT');
729 }
730
731 function loadServiceEPGNowNext(servicereference, next){
732         var url = URL.epgnow+servicereference;
733
734         if(typeof(next) == 'undefined'){
735                 doRequest(url, incomingServiceEPGNow, false);
736         } else {
737                 url = URL.epgnext+servicereference;
738                 doRequest(url, incomingServiceEPGNext, false);
739         }
740 }
741
742
743 function getBouquetEpg(){
744         loadServiceEPGNowNext(currentBouquet);
745         loadServiceEPGNowNext(currentBouquet, true);
746 }
747
748
749 function recordNowPopup(){
750         var result = confirm(   
751                         "OK: Record current event\n" +
752                         "Cancel: Start infinite recording"
753         );
754
755         if( result === true || result === false){
756                 recordNowDecision(result);
757         }
758 }
759
760
761 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
762 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
763 //++++ volume functions ++++
764 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
765 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
766 function handleVolumeRequest(request){
767         if (request.readyState == 4) {
768                 var b = getXML(request).getElementsByTagName("e2volume");
769                 var newvalue = b.item(0).getElementsByTagName('e2current').item(0).firstChild.data;
770                 var mute = b.item(0).getElementsByTagName('e2ismuted').item(0).firstChild.data;
771                 debug("[handleVolumeRequest] Volume " + newvalue + " | Mute: " + mute);
772
773                 for (var i = 1; i <= 10; i++)           {
774                         if ( (newvalue/10)>=i){
775                                 $("volume"+i).src = "/web-data/img/led_on.png";
776                         }else{
777                                 $("volume"+i).src = "/web-data/img/led_off.png";
778                         }
779                 }
780                 if (mute == "False"){
781                         $("speaker").src = "/web-data/img/speak_on.png";
782                 }else{
783                         $("speaker").src = "/web-data/img/speak_off.png";
784                 }
785         }       
786 }
787
788
789 function getVolume(){
790         doRequest(URL.getvolume, handleVolumeRequest, false);
791 }
792
793 function volumeSet(val){
794         doRequest(URL.setvolume+val, handleVolumeRequest, false);
795 }
796
797 function volumeUp(){
798         doRequest(URL.volumeup, handleVolumeRequest, false);
799 }
800
801 function volumeDown(){
802         doRequest(URL.volumedown, handleVolumeRequest, false);
803 }
804
805 function volumeMute(){
806         doRequest(URL.volumemute, handleVolumeRequest, false);
807 }
808
809 function initVolumePanel(){
810         getVolume(); 
811 }
812
813
814
815 //Channels and Bouquets
816
817 function incomingChannellist(request){
818         var serviceList = null;
819         if(typeof(loadedChannellist[currentBouquet]) != "undefined"){
820                 serviceList = loadedChannellist[currentBouquet];
821         } else if(request.readyState == 4) {
822                 serviceList = new ServiceList(getXML(request)).getArray();
823                 debug("[incomingChannellist] got "+serviceList.length+" Services");
824         }
825         if(serviceList !== null) {              
826                 var data = { services : serviceList };
827
828                 processTpl('tplServiceList', data, 'contentServices', getBouquetEpg);
829                 delayedGetSubservices();
830         } else {
831                 debug("[incomingChannellist] services is null");
832         }
833 }
834
835
836 function loadBouquet(servicereference, name){ 
837         debug("[loadBouquet] called");
838
839         currentBouquet = servicereference;
840
841         setContentHd(name);
842         setAjaxLoad('contentServices');
843
844         startUpdateBouquetItemsPoller();
845         doRequest(URL.getservices+servicereference, incomingChannellist, true);
846
847 }
848
849
850 function incomingBouquetListInitial(request){
851         if (request.readyState == 4) {
852                 var bouquetList = new ServiceList(getXML(request)).getArray();
853                 debug("[incomingBouquetListInitial] Got " + bouquetList.length + " TV Bouquets!");      
854         
855                 // loading first entry of TV Favorites as default for ServiceList
856                 incomingBouquetList(
857                                 request, 
858                                 function(){
859                                         loadBouquet(bouquetList[0].servicereference, bouquetList[0].servicename);;
860                                 }
861                         );
862         }
863 }
864
865
866 function incomingBouquetList(request, callback){
867         if (request.readyState == 4) {
868                 var bouquetList = new ServiceList(getXML(request)).getArray();
869                 debug("[incomingBouquetList] got " + bouquetList.length + " TV Bouquets!");     
870                 var data = { bouquets : bouquetList };
871                 
872                 if( $('contentBouquets') != "undefined" && $('contentBouquets') != null ){
873                         processTpl('tplBouquetList', data, 'contentBouquets');
874                         if(typeof(callback) == 'function')
875                                 callback();
876                 } else {
877                         processTpl(                                     
878                                         'tplBouquetsAndServices', 
879                                         null, 
880                                         'contentMain',
881                                         function(){
882                                                 processTpl('tplBouquetList', data, 'contentBouquets');
883                                                 if(typeof(callback) == 'function')
884                                                         callback();
885                                         }
886                         );
887                 }
888         }
889 }
890
891
892 function initChannelList(){
893         var url = URL.getservices+encodeURIComponent(bouquetsTv);
894         currentBouquet = bouquetsTv;
895
896         doRequest(url, incomingBouquetListInitial, true);
897 }
898
899
900
901 //Movies
902 function initMovieList(){
903         // get videodirs, last_videodir, and all tags
904         doRequest(URL.getcurrlocation, incomingMovieListCurrentLocation, false);
905 }
906
907 function incomingMovieListCurrentLocation(request){
908         if(request.readyState == 4){
909                 result  = new SimpleXMLList(getXML(request), "e2location");
910                 currentLocation = result.getList()[0];
911                 debug("[incomingMovieListCurrentLocation].currentLocation" + currentLocation);
912                 doRequest(URL.getlocations, incomingMovieListLocations, false);
913         }
914 }
915
916 function incomingMovieListLocations(request){
917         if(request.readyState == 4){
918                 result  = new SimpleXMLList(getXML(request), "e2location");
919                 locationsList = result.getList();
920
921                 if (locationsList.length === 0) {
922                         locationsList = ["/hdd/movie"];
923                 }
924                 doRequest(URL.gettags, incomingMovieListTags, false);
925         }
926 }
927
928 function incomingMovieListTags(request){
929         if(request.readyState == 4){
930                 result  = new SimpleXMLList(getXML(request), "e2tag");
931                 tagsList = result.getList();
932         }
933 }
934
935 function createOptionListSimple(lst, selected) {
936         var namespace = Array();
937         var i = 0;
938         var found = false;
939
940         for (i = 0; i < lst.length; i++) {
941                 if (lst[i] == selected) {
942                         found = true;
943                 }
944         }
945
946         if (!found) {
947                 lst = [ selected ].concat(lst);
948         }
949
950         for (i = 0; i < lst.length; i++) {
951                 namespace[i] = {
952                                 'value': lst[i],
953                                 'txt': lst[i],
954                                 'selected': (lst[i] == selected ? "selected" : " ")};
955         }
956
957         return namespace;
958 }
959
960 function loadMovieNav(){
961         // fill in menus
962         var data = {
963                         dirname: createOptionListSimple(locationsList, currentLocation),
964                         tags: createOptionListSimple(tagsList, "")
965         };
966
967         processTpl('tplNavMovies', data, 'navContent');
968 }
969
970 function incomingMovieList(request){
971         if(request.readyState == 4){
972
973                 var movieList = new MovieList(getXML(request)).getArray();
974                 debug("[incomingMovieList] Got "+movieList.length+" movies");
975
976                 var data = { movies : movieList };
977                 processTpl('tplMovieList', data, 'contentMain');
978         }               
979 }
980
981 function loadMovieList(loc, tag){
982         if(typeof(loc) == 'undefined'){
983                 loc = currentLocation;
984         }
985         if(typeof(tag) == 'undefined'){
986                 tag = '';
987         }
988         debug("[loadMovieList] Loading movies in location '"+loc+"' with tag '"+tag+"'");
989         doRequest(URL.movielist+"?dirname="+loc+"&tag="+tag, incomingMovieList, false);
990 }
991
992
993 function incomingDelMovieResult(request) {
994         debug("[incomingDelMovieResult] called");
995         if(request.readyState == 4){
996                 var result = new SimpleXMLResult(getXML(request));
997                 if(result.getState()){                  
998                         loadMovieList();
999                 }
1000                 simpleResultHandler(result);
1001         }               
1002 }
1003
1004
1005 function delMovie(sref ,servicename, title, description) {
1006         debug("[delMovie] File(" + unescape(sref) + "), servicename(" + servicename + ")," +
1007                         "title(" + unescape(title) + "), description(" + description + ")");
1008
1009         result = confirm( "Are you sure want to delete the Movie?\n" +
1010                         "Servicename: " + servicename + "\n" +
1011                         "Title: " + unescape(title) + "\n" + 
1012                         "Description: " + description + "\n");
1013
1014         if(result){
1015                 debug("[delMovie] ok confirm panel"); 
1016                 doRequest(URL.moviedelete+"?sRef="+unescape(sref), incomingDelMovieResult, false); 
1017                 return true;
1018         }
1019         else{
1020                 debug("[delMovie] cancel confirm panel");
1021                 return false;
1022         }
1023 }
1024
1025 //Send Messages and Receive the Answer
1026
1027
1028 function incomingMessageResult(request){
1029         if(request.readyState== 4){
1030                 var result = new SimpleXMLResult(getXML(request));
1031                 simpleResultHandler(result);
1032         }
1033 }
1034
1035 function getMessageAnswer() {
1036         doRequest(URL.messageanswer, incomingMessageResult, false);
1037 }
1038
1039 function sendMessage(messagetext, messagetype, messagetimeout){
1040         if(!messagetext){
1041                 messagetext = $('MessageSendFormText').value;
1042         }       
1043         if(!messagetimeout){
1044                 messagetimeout = $('MessageSendFormTimeout').value;
1045         }       
1046         if(!messagetype){
1047                 var index = $('MessageSendFormType').selectedIndex;
1048                 messagetype = $('MessageSendFormType').options[index].value;
1049         }       
1050         if(parseNr(messagetype) === 0){
1051                 doRequest(URL.message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout);
1052                 setTimeout(getMessageAnswer, parseNr(messagetimeout)*1000);
1053         } else {
1054                 doRequest(URL.message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, incomingMessageResult, false);
1055         }
1056 }
1057
1058
1059 //Screenshots
1060 function getScreenShot(what) {
1061         debug("[getScreenShot] called");
1062
1063         var buffer = new Image();
1064         var downloadStart;
1065         var data = {};
1066
1067         buffer.onload = function () { 
1068                 debug("[getScreenShot] image assigned");
1069
1070                 data = { img : { src : buffer.src } };  
1071                 processTpl('tplGrab', data, 'contentMain');
1072
1073                 return true;
1074         };
1075
1076         buffer.onerror = function (meldung) { 
1077                 debug("[getScreenShot] Loading image failed"); 
1078                 return true;
1079         };
1080
1081         switch(what){
1082         case "o":
1083                 what = "&o=&n=";
1084                 break;
1085         case "v":
1086                 what = "&v=";
1087                 break;
1088         default:
1089                 what = "";
1090         break;
1091         }
1092
1093         downloadStart = new Date().getTime();
1094         buffer.src = '/grab?format=jpg&r=720&' + what + '&filename=/tmp/' + downloadStart;
1095 }
1096
1097 function getVideoShot() {
1098         getScreenShot("v");
1099 }
1100
1101 function getOsdShot(){
1102         getScreenShot("o");
1103 }
1104
1105 //RemoteControl Code
1106
1107 function incomingRemoteControlResult(request){
1108 //      if(request.readyState == 4){
1109 //              var b = getXML(request).getElementsByTagName("e2remotecontrol");
1110 //              var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
1111 //              var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
1112 //      }
1113 }
1114
1115 function openWebRemote(){
1116         var template = templates.tplWebRemoteOld;
1117
1118         if(boxtype == "dm8000"){
1119                 template = templates.tplWebRemote;
1120         }
1121
1122
1123         if (!webRemoteWin.closed && webRemoteWin.location) {
1124                 setWindowContent(webRemoteWin, template);
1125         } else {
1126                 webRemoteWin = openPopup('WebRemote', template, 250, 600);
1127         }
1128
1129 }
1130
1131
1132 function loadAndOpenWebRemote(){
1133         if(boxtype == "dm8000"){
1134                 fetchTpl('tplWebRemote', openWebRemote);
1135                 
1136         } else {
1137                 fetchTpl('tplWebRemoteOld', openWebRemote);
1138         }
1139 }
1140
1141
1142 function sendRemoteControlRequest(command){
1143         doRequest(URL.remotecontrol+'?command='+command, incomingRemoteControlResult, false);
1144         if(webRemoteWin.document.getElementById('getScreen').checked) {
1145                 if(webRemoteWin.document.getElementById('getVideo').checked){
1146                         getScreenShot();
1147                 } else {
1148                         getScreenShot("o");
1149                 }
1150         }
1151 }
1152
1153
1154 // Array.insert( index, value ) - Insert value at index, without overwriting existing keys
1155 Array.prototype.insert = function( j, v ) {
1156         if( j>=0 ) {
1157                 var a = this.slice(), b = a.splice( j );
1158                 a[j] = v;
1159                 return a.concat( b );
1160         }
1161 };
1162
1163 //Array.splice() - Remove or replace several elements and return any deleted
1164 //elements
1165 if( typeof Array.prototype.splice==='undefined' ) {
1166         Array.prototype.splice = function( a, c ) {
1167                 var e = arguments, d = this.copy(), f = a, l = this.length;
1168
1169                 if( !c ) { 
1170                         c = l - a; 
1171                 }
1172
1173                 for( var i = 0; i < e.length - 2; i++ ) { 
1174                         this[a + i] = e[i + 2]; 
1175                 }
1176
1177
1178                 for( var j = a; j < l - c; j++ ) { 
1179                         this[j + e.length - 2] = d[j - c]; 
1180                 }
1181                 this.length -= c - e.length + 2;
1182
1183                 return d.slice( f, f + c );
1184         };
1185 }
1186
1187 function ifChecked(rObj) {
1188         if(rObj.checked) {
1189                 return rObj.value;
1190         } else {
1191                 return "";
1192         }
1193 }
1194
1195 //Device Info
1196 /*
1197  * Handles an incoming request for /web/deviceinfo Parses the Data, and calls
1198  * everything needed to render the Template using the parsed data and set the
1199  * result into contentMain @param request - the XHR
1200  */
1201 function incomingDeviceInfo(request) {
1202         if(request.readyState == 4){
1203                 debug("[incomingDeviceInfo] called");
1204                 var deviceInfo = new DeviceInfo(getXML(request));
1205
1206                 processTpl('tplDeviceInfo', deviceInfo, 'contentMain');
1207         }
1208 }
1209
1210
1211 /*
1212  * Show Device Info Information in contentMain
1213  */
1214 function showDeviceInfo() {
1215         doRequest(URL.deviceinfo, incomingDeviceInfo, false);
1216 }
1217
1218 function showGears(){
1219         var enabled = false;
1220         
1221         if (window.google && google.gears){
1222                 enabled = gearsEnabled();
1223         }
1224         
1225         data = { 'useGears' : enabled };
1226         processTpl('tplGears', data, 'contentMain');
1227 }
1228
1229 function showSettings(){
1230         var debug = userprefs.data.debug;
1231         var debugChecked = "";
1232         if(debug){
1233                 debugChecked = 'checked';
1234         }
1235         
1236         var updateCurrentInterval = userprefs.data.updateCurrentInterval;
1237         var updateBouquetInterval = userprefs.data.updateBouquetInterval;
1238         
1239
1240         data = {'debug' : debugChecked,
1241                         'updateCurrentInterval' : updateCurrentInterval,
1242                         'updateBouquetInterval' : updateBouquetInterval
1243         };
1244         processTpl('tplSettings', data, 'contentMain');
1245 }
1246
1247  
1248 // Spezial functions, mostly for testing purpose
1249 function openHiddenFunctions(){
1250         openPopup("Extra Hidden Functions",tplExtraHiddenFunctions,300,100,920,0);
1251 }
1252
1253
1254 function startDebugWindow() {
1255         DBG = true;
1256         debugWin = openPopup("DEBUG", "", 300, 300,920,140, "debugWindow");
1257 }
1258
1259
1260 function restartTwisted() {
1261         doRequest( "/web/restarttwisted" );
1262 }
1263
1264
1265 //MediaPlayer
1266 function sendMediaPlayer(command) {
1267         debug("[sendMediaPlayer] called");
1268         doRequest( URL.mediaplayercmd+command );
1269 }
1270
1271
1272 function incomingMediaPlayer(request){
1273         if(request.readyState == 4){
1274                 var files = new FileList(getXML(request)).getArray();
1275
1276                 debug("[loadMediaPlayer] Got "+files.length+" entries in mediaplayer filelist");
1277                 // listerHtml = tplMediaPlayerHeader;
1278
1279                 var namespace = {};
1280
1281                 var root = files[0].getRoot();
1282                 if (root != "playlist") {
1283                         namespace = {'root': root};
1284                         if(root != '/') {
1285                                 var re = new RegExp(/(.*)\/(.*)\/$/);
1286                                 re.exec(root);
1287                                 var newroot = RegExp.$1+'/';
1288                                 if(newroot == '//') {
1289                                         newroot = '/';
1290                                 }
1291                                 namespace = {
1292                                                 'root': root,
1293                                                 'servicereference': newroot,
1294                                                 'exec': 'loadMediaPlayer',
1295                                                 'exec_description': 'Change to directory ../',
1296                                                 'color': '000000',
1297                                                 'newroot': newroot,
1298                                                 'name': '..'
1299                                 };      
1300                         }
1301                 }
1302
1303                 var itemnamespace = Array();
1304                 for ( var i = 0; i <files.length; i++){
1305                         var file = files[i];
1306                         if(file.getNameOnly() == '') {
1307                                 continue;
1308                         }
1309                         var exec = 'loadMediaPlayer';
1310                         var exec_description = 'Change to directory' + file.getServiceReference();
1311                         var color = '000000';                   
1312                         var isdir = 'true';
1313
1314                         if (file.getIsDirectory() == "False") {
1315                                 exec = 'playFile';
1316                                 exec_description = 'play file';
1317                                 color = '00BCBC';
1318                                 isdir = 'false';
1319                         }
1320
1321                         itemnamespace[i] = {
1322                                         'isdir' : isdir,
1323                                         'servicereference': file.getServiceReference(),
1324                                         'exec': exec,
1325                                         'exec_description': exec_description,
1326                                         'color': color,                                                 
1327                                         'root': file.getRoot(),
1328                                         'name': file.getNameOnly()
1329                         };
1330
1331                 }
1332                 /*
1333                 if (root == "playlist") {
1334                         listerHtml += tplMediaPlayerFooterPlaylist;
1335                 }
1336                  */
1337
1338                 var data = { mp : namespace,
1339                                 items: itemnamespace
1340                 };
1341
1342                 processTpl('tplMediaPlayer', data, 'contentMain');
1343                 var sendMediaPlayerTMP = sendMediaPlayer;
1344                 sendMediaPlayer = false;
1345                 // setBodyMainContent('BodyContent');
1346                 sendMediaPlayer = sendMediaPlayerTMP;
1347         }               
1348 }
1349
1350
1351 function loadMediaPlayer(directory){
1352         debug("[loadMediaPlayer] called");
1353         if(typeof(directory) == 'undefined') directory = 'Filesystems';
1354         doRequest(URL.mediaplayerlist+directory, incomingMediaPlayer, false);
1355 }
1356
1357
1358 function playFile(file,root) {
1359         debug("[playFile] called");
1360         mediaPlayerStarted = true;
1361         doRequest( URL.mediaplayerplay+file+"&root="+root );
1362 }
1363
1364
1365 function deleteFile(sref) {
1366         debug("[deleteFile] called");
1367         mediaPlayerStarted = true;
1368         doRequest( URL.mediaplayerremove+sref );
1369 }
1370
1371
1372 function openMediaPlayerPlaylist() {
1373         debug("[openMediaPlayerPlaylist] called");
1374         doRequest(URL.mediaplayerlist+"playlist", incomingMediaPlayer, false);
1375 }
1376
1377
1378 function writePlaylist() {
1379         debug("[writePlaylist] called");
1380         var filename = '';
1381         filename = prompt("Please enter a name for the playlist", "");
1382
1383         if(filename !== "") {
1384                 doRequest( URL.mediaplayerwrite+filename );
1385         }
1386 }
1387
1388 //Powerstate
1389 /*
1390  * Sets the Powerstate @param newState - the new Powerstate Possible Values
1391  * (also see WebComponents/Sources/PowerState.py) #-1: get current state # 0:
1392  * toggle standby # 1: poweroff/deepstandby # 2: rebootdreambox # 3:
1393  * rebootenigma
1394  */
1395 function sendPowerState(newState){
1396         doRequest( URL.powerstate+'?newstate='+newState, incomingPowerState);
1397 }
1398
1399
1400 //Currently Running Service
1401 function incomingCurrent(request){
1402         //      debug("[incomingCurrent called]");
1403         if(request.readyState == 4){
1404                 try{
1405                         var epg = new EPGList(getXML(request)).getArray();
1406                         epg = epg[0];
1407
1408                         var data = { current : epg };
1409
1410                         if(typeof(templates.tplCurrent) != "undefined"){
1411                                 var display = 'none';
1412                                 try{
1413                                         var display = $('trExtCurrent').style.display;
1414                                 } catch(e){}
1415                                 
1416                                 renderTpl(templates.tplCurrent, data, "currentContent");
1417                                 $('trExtCurrent').style.display = display;
1418                         } else {
1419                                 debug("[incomingCurrent] tplCurrent N/A");
1420                         }
1421
1422                 } catch (e){}
1423                 
1424                 isActive.getCurrent = false;
1425         }
1426 }
1427
1428
1429 function getCurrent(){
1430         if(!isActive.getCurrent){
1431                 isActive.getCurrent = true;
1432                 doRequest(URL.getcurrent, incomingCurrent, false);
1433         }
1434 }
1435
1436
1437 //Navigation and Content Helper Functions
1438
1439 /*
1440  * Loads all Bouquets for the given enigma2 servicereference and sets the
1441  * according contentHeader @param sRef - the Servicereference for the bouquet to
1442  * load
1443  */
1444 function getBouquets(sRef){     
1445         var url = URL.getservices+encodeURIComponent(sRef);
1446         
1447         doRequest(url, incomingBouquetList, true);              
1448 }
1449
1450 /*
1451  * Loads another navigation template and sets the navigation header
1452  * @param template - The name of the template
1453  * @param title - The title to set for the navigation
1454  */
1455 function reloadNav(template, title){
1456         setAjaxLoad('navContent');
1457         processTpl(template, null, 'navContent');
1458         setNavHd(title);
1459 }
1460
1461 function reloadNavDynamic(fnc, title){
1462         setAjaxLoad('navContent');
1463         setNavHd(title);
1464         fnc();
1465 }
1466
1467 function getBouquetsTv(){
1468         getBouquets(bouquetsTv);
1469 }
1470
1471 function getProviderTv(){
1472         getBouquets(providerTv);
1473 }
1474
1475 function getSatellitesTv(){
1476         getBouquets(satellitesTv);
1477 }
1478
1479 function getAllTv(){
1480         loadBouquet(allTv, "All (TV)");
1481 }
1482
1483
1484 function getBouquetsRadio(){
1485         getBouquets(bouquetsRadio);
1486 }
1487
1488 function getProviderRadio(){
1489         getBouquets(providerRadio);
1490 }
1491
1492 function getSatellitesRadio(){
1493         getBouquets(satellitesRadio);
1494 }
1495
1496 function getAllRadio(){
1497         loadBouquet(allRadio, "All (Radio)");
1498 }
1499
1500 /*
1501  * Loads dynamic content to $(contentMain) by calling a execution function
1502  * @param fnc - The function used to load the content
1503  * @param title - The Title to set on the contentpanel
1504  */
1505 function loadContentDynamic(fnc, title, domid){
1506         if(typeof(domid) != "undefined" && $(domid) != null){
1507                 setAjaxLoad(domid);
1508         } else {
1509                 setAjaxLoad('contentMain');
1510         }
1511         setContentHd(title);
1512         stopUpdateBouquetItemsPoller();
1513
1514         fnc();
1515 }
1516
1517 /*
1518  * like loadContentDynamic but without the AjaxLoaderAnimation being shown
1519  */
1520 function reloadContentDynamic(fnc, title){
1521         setContentHd(title);
1522         fnc();
1523 }
1524
1525 /*
1526  * Loads a static template to $(contentMain)
1527  * @param template - Name of the Template
1528  * @param title - The Title to set on the Content-Panel
1529  */
1530 function loadContentStatic(template, title){
1531         setAjaxLoad('contentMain');
1532         setContentHd(title);
1533         stopUpdateBouquetItemsPoller();
1534         processTpl(template, null, 'contentMain');
1535 }
1536
1537
1538 /*
1539  * Opens the given Control
1540  * @param control - Control Page as String
1541  * Possible Values: power, extras, message, screenshot, videoshot, osdshot
1542  */
1543 function loadControl(control){
1544         switch(control){
1545         case "power":
1546                 loadContentStatic('tplPower', 'PowerControl');
1547                 break;
1548
1549         case "message":
1550                 loadContentStatic('tplSendMessage', 'Send a Message');
1551                 break;
1552
1553         case "remote":
1554                 loadAndOpenWebRemote();
1555                 break;
1556
1557         case "screenshot":
1558                 loadContentDynamic(getScreenShot, 'Screenshot');
1559                 break;
1560
1561         case "videoshot":
1562                 loadContentDynamic(getVideoShot, 'Videoshot');
1563                 break;
1564
1565         case "osdshot":
1566                 loadContentDynamic(getOsdShot, 'OSDshot');
1567                 break;
1568
1569         default:
1570                 break;
1571         }
1572 }
1573
1574
1575 function loadDeviceInfo(){
1576         loadContentDynamic(showDeviceInfo, 'Device Information');
1577 }
1578
1579 function loadAbout(){
1580         loadContentStatic('tplAbout', 'About');
1581 }
1582
1583 function loadSettings(){
1584         loadContentDynamic(showSettings, 'Settings');
1585 }
1586
1587 function loadGearsInfo(){
1588         loadContentDynamic(showGears, 'Google Gears');
1589 }
1590
1591 function reloadGearsInfo(){
1592         loadContentDynamic(showGears, 'Google Gears');
1593 }
1594
1595
1596 /*
1597  * Switches Navigation Modes
1598  * @param mode - The Navigation Mode you want to switch to
1599  * Possible Values: TV, Radio, Movies, Timer, Extras
1600  */
1601 function switchMode(mode){
1602         switch(mode){
1603         case "TV":
1604                 reloadNav('tplNavTv', 'TeleVision');
1605                 break;
1606
1607         case "Radio":
1608                 reloadNav('tplNavRadio', 'Radio');
1609                 break;
1610
1611         case "Movies":
1612                 //The Navigation
1613                 reloadNavDynamic(loadMovieNav, 'Movies');
1614
1615                 // The Movie list
1616                 loadContentDynamic(loadMovieList, 'Movies');
1617                 break;
1618
1619         case "Timer":
1620                 //The Navigation
1621                 reloadNav('tplNavTimer', 'Timer');
1622
1623                 // The Timerlist
1624                 loadContentDynamic(loadTimerList, 'Timer');
1625                 break;
1626
1627         case "MediaPlayer":
1628                 loadContentDynamic(loadMediaPlayer, 'MediaPlayer');
1629                 break;
1630
1631         case "BoxControl":
1632                 reloadNav('tplNavBoxControl', 'BoxControl');
1633                 break;
1634
1635         case "Extras":
1636                 reloadNav('tplNavExtras', 'Extras');
1637                 break;
1638                 
1639         default:
1640                 break;
1641         }
1642 }
1643
1644 function openWebTV(){
1645         window.open('/web-data/streaminterface.html', 'WebTV', 'scrollbars=no, width=800, height=730');
1646 }
1647
1648
1649
1650 function updateItems(){
1651         getCurrent();
1652         getPowerState();
1653 }
1654
1655 function updateItemsLazy(bouquet){
1656         getSubServices();
1657         getBouquetEpg();
1658 }
1659
1660 /*
1661  * Does the everything required on initial pageload
1662  */
1663
1664 function init(){
1665         var DBG = userprefs.data.debug || false;
1666         
1667         if(DBG){
1668                 openDebug();
1669         }
1670
1671         if( parseNr(userprefs.data.updateCurrentInterval) < 10000){
1672                 userprefs.data.updateCurrentInterval = 120000;
1673                 userprefs.save();
1674         }
1675         
1676         if( parseNr(userprefs.data.updateBouquetInterval) < 60000 ){
1677                 userprefs.data.updateBouquetInterval = 300000;
1678                 userprefs.save();
1679         }
1680         
1681         if (typeof document.body.style.maxHeight == "undefined") {
1682                 alert("Due to the tremendous amount of work needed to get everthing to " +
1683                 "work properly, there is (for now) no support for Internet Explorer Versions below 7");
1684         }
1685         
1686         getBoxtype();
1687
1688         setAjaxLoad('navContent');
1689         setAjaxLoad('contentMain');
1690
1691         fetchTpl('tplServiceListEPGItem');
1692         fetchTpl('tplBouquetsAndServices');
1693         fetchTpl('tplCurrent'); 
1694         reloadNav('tplNavTv', 'TeleVision');
1695
1696         initChannelList();
1697         initVolumePanel();
1698         initMovieList();
1699
1700         updateItems();
1701         startUpdateCurrentPoller();
1702 }