dc0f4b223e7223de6950f2e8fc0da6a344050f45
[vuplus_dvbapp-plugin] / 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, 10000);
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 = parseNr( $F('updateCurrentInterval') ) * 1000;
347         if( 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 = parseNr( $F('updateBouquetInterval') )  * 1000;
359         if( 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 requestFailed(transport){
441         var notifText = "Request failed for:  " + transport.request.url + "<br>Status: " + transport.status + " " + transport.statusText;
442         notify(notifText, false);
443 }
444
445 function doRequest(url, readyFunction){
446         requestStarted();
447         var request = '';
448         // gears or not that's the question here
449         if (!window.google || !google.gears){ //no gears, how sad
450 //              debug("NO GEARS!!");            
451                 try{
452                         request = new Ajax.Request(url,
453                                         {
454                                                 asynchronous: true,
455                                                 method: 'GET',
456                                                 requestHeaders: ['Cache-Control', 'no-cache,no-store', 'Expires', '-1'],
457                                                 onException: function(o,e){ throw(e); },                                
458                                                 onSuccess: function (transport, json) {                                         
459                                                         if(typeof(readyFunction) != "undefined"){
460                                                                 readyFunction(transport);
461                                                         }
462                                                 },
463                                                 onFailure: function(transport){
464                                                         requestFailed(transport);
465                                                 },
466                                                 onComplete: requestFinished 
467                                         });
468                 } catch(e) {}
469         } else { //we're on gears!
470                 try{
471                         request = google.gears.factory.create('beta.httprequest');
472                         request.open('GET', url);
473
474
475                         request.onreadystatechange = function(){                                
476                                 if(request.readyState == 4){
477                                         if(request.status == 200){
478                                                 if( typeof(readyFunction) != "undefined" ){
479                                                         readyFunction(request);
480                                                 }
481                                         } else {
482                                                 requestFailed(transport);
483                                         }
484                                 }
485                         };
486                         request.send();
487                 } catch(e) {}
488         }
489 }
490
491 //Parental Control
492 function incomingParentControl(request) {
493         if(request.readyState == 4){
494                 parentControlList = new ServiceList(getXML(request)).getArray();
495                 debug("[incomingParentControl] Got "+parentControlList.length + " services");
496         }
497 }
498
499 function getParentControl() {
500         doRequest(URL.parentcontrol, incomingParentControl, false);
501 }
502
503
504 function getParentControlByRef(txt) {
505         debug("[getParentControlByRef] ("+txt+")");
506         for(var i = 0; i < parentControlList.length; i++) {
507                 debug( "[getParentControlByRef] "+parentControlList[i].getClearServiceReference() );
508                 if(String(parentControlList[i].getClearServiceReference()) == String(txt)) {
509                         return parentControlList[i].getClearServiceReference();
510                 } 
511         }
512         return "";
513 }
514
515
516 //Settings
517 function getSettingByName(txt) {
518         debug("[getSettingByName] (" + txt + ")");
519         for(var i = 0; i < settings.length; i++) {
520                 debug("("+settings[i].getSettingName()+") (" +settings[i].getSettingValue()+")");
521                 if(String(settings[i].getSettingName()) == String(txt)) {
522                         return settings[i].getSettingValue().toLowerCase();
523                 } 
524         }
525         return "";
526 }
527
528 function parentPin(servicereference) {
529         debug("[parentPin] parentControlList");
530         servicereference = decodeURIComponent(servicereference);
531         if(parentControlList === null || String(getSettingByName("config.ParentalControl.configured")) != "true") {
532                 return true;
533         }
534         //debug("parentPin " + parentControlList.length);
535         if(getParentControlByRef(servicereference) == servicereference) {
536                 if(String(getSettingByName("config.ParentalControl.type.value")) == "whitelist") {
537                         debug("[parentPin] Channel in whitelist");
538                         return true;
539                 }
540         } else {
541                 debug("[parentPin] sRef differs ");
542                 return true;
543         }
544         debug("[parentPin] Asking for PIN");
545
546         var userInput = prompt('Parental Control is enabled!<br> Please enter the Parental Control PIN','PIN');
547         if (userInput !== '' && userInput !== null) {
548                 if(String(userInput) == String(getSettingByName("config.ParentalControl.servicepin.0")) ) {
549                         return true;
550                 } else {
551                         return parentPin(servicereference);
552                 }
553         } else {
554                 return false;
555         }
556 }
557
558
559 function incomingGetDreamboxSettings(request){
560         if(request.readyState == 4){
561                 settings = new Settings(getXML(request)).getArray();
562
563                 debug("[incomingGetDreamboxSettings] config.ParentalControl.configured="+ getSettingByName("config.ParentalControl.configured"));
564
565                 if(String(getSettingByName("config.ParentalControl.configured")) == "true") {
566                         getParentControl();
567                 }
568         }
569 }
570
571
572 function getDreamboxSettings(){
573         doRequest(URL.settings, incomingGetDreamboxSettings, false);
574 }
575
576
577 //Subservices
578 function incomingSubServiceRequest(request){
579         if(request.readyState == 4){
580                 var services = new ServiceList(getXML(request)).getArray();
581                 debug("[incomingSubServiceRequest] Got " + services.length + " SubServices");
582
583                 if(services.length > 1) {
584
585                         var first = services[0];
586
587                         // we already have the main service in our servicelist so we'll
588                         // start with the second element                        
589                         services.shift();
590                         
591                         var data = { subservices : services };
592                         
593
594                         var id = 'SUB'+first.servicereference;
595                         show('tr' + id);
596                         processTpl('tplSubServices', data, id);
597                 }
598         }
599 }
600
601
602 function getSubServices(bouquet) {
603         doRequest(URL.subservices, incomingSubServiceRequest, false);
604 }
605
606
607 function delayedGetSubservices(){
608         setTimeout(getSubServices, 5000);
609 }
610
611 //zap zap
612 function zap(servicereference){
613         doRequest("/web/zap?sRef=" + servicereference); 
614         setTimeout(updateItemsLazy, 7000); //reload epg and subservices
615         setTimeout(updateItems, 3000);
616 }
617
618 //SignalPanel
619
620 function updateSignalPanel(){   
621         var html = templates.tplSignalPanel.process(signalPanelData);
622
623         if (!signalWin.closed && signalWin.location) {
624                 setWindowContent(signalWin, html);
625         } else {
626                 clearInterval(signalPanelUpdatePoller);
627                 signalPanelUpdatePoller = '';
628         }
629 }
630
631 function incomingSignalPanel(request){
632         var namespace = {};
633
634         if (request.readyState == 4){
635                 var xml = getXML(request).getElementsByTagName("e2frontendstatus").item(0);
636                 namespace = {
637                                 snrdb : xml.getElementsByTagName('e2snrdb').item(0).firstChild.data,
638                                 snr : xml.getElementsByTagName('e2snr').item(0).firstChild.data,
639                                 ber : xml.getElementsByTagName('e2ber').item(0).firstChild.data,
640                                 acg : xml.getElementsByTagName('e2acg').item(0).firstChild.data
641                 };
642         }
643
644         signalPanelData = { signal : namespace };
645         fetchTpl('tplSignalPanel', updateSignalPanel);  
646 }
647
648 function reloadSignalPanel(){
649         doRequest(URL.signal, incomingSignalPanel, false);
650 }
651
652 function openSignalPanel(){
653         if (!(!signalWin.closed && signalWin.location)){
654                 signalWin = openPopup('SignalPanel', '', 220, 120);
655                 if(signalPanelUpdatePoller === ''){
656                         signalPanelUpdatePoller = setInterval(reloadSignalPanel, 5000);
657                 }
658         }
659         reloadSignalPanel();
660 }
661
662 //EPG functions
663
664
665 function showEpgList(){
666         var html = templates.tplEpgList.process(epgListData);
667
668         if (!EPGListWin.closed && EPGListWin.location) {
669                 setWindowContent(EPGListWin, html);
670         } else {
671                 EPGListWin = openPopup("EPG", html, 900, 500);
672         }
673 }
674
675 function incomingEPGrequest(request){
676         debug("[incomingEPGrequest] readyState" +request.readyState);           
677         if (request.readyState == 4){
678                 var EPGItems = new EPGList(getXML(request)).getArray(true);
679                 debug("[incomingEPGrequest] got "+EPGItems.length+" e2events");
680
681                 if( EPGItems.length > 0){
682                         epgListData = {epg : EPGItems};
683                         fetchTpl('tplEpgList', showEpgList);
684                 } else {
685                         messageBox('No Items found!', 'Sorry but I could not find any EPG Content containing your search value');
686                 }
687         }
688 }
689
690 function loadEPGBySearchString(string){
691         doRequest(URL.epgsearch+escape(string),incomingEPGrequest, false);
692 }
693
694 function loadEPGByServiceReference(servicereference){
695         doRequest(URL.epgservice+servicereference,incomingEPGrequest, false);
696 }
697
698 function buildServiceListEPGItem(epgevent, type){
699         var data = { epg : epgevent,
700                                  nownext: type
701                                 };
702         // e.innerHTML = RND(tplServiceListEPGItem, namespace);
703
704         var id = type + epgevent.servicereference;
705
706         show('tr' + id);
707
708         if(typeof(templates.tplServiceListEPGItem) != "undefined"){
709                 renderTpl(templates.tplServiceListEPGItem, data, id, true);
710         } else {
711                 debug("[buildServiceListEPGItem] tplServiceListEPGItem N/A");
712         }
713 }
714
715 function incomingServiceEPGNowNext(request, type){
716         if(request.readyState == 4){
717                 var epgevents = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
718                 for (var c = 0; c < epgevents.length; c++){
719                         try{
720                                 var epgEvt = new EPGEvent(epgevents.item(c), c).toJSON();
721                         } catch (e){
722                                 debug("[incomingServiceEPGNowNext]" + e);
723                         }
724
725                         if (epgEvt.eventid != ''){
726                                 buildServiceListEPGItem(epgEvt, type);
727                         }
728                 }
729         }
730 }
731
732 function incomingServiceEPGNow(request){
733         incomingServiceEPGNowNext(request, 'NOW');
734 }
735
736 function incomingServiceEPGNext(request){
737         incomingServiceEPGNowNext(request, 'NEXT');
738 }
739
740 function loadServiceEPGNowNext(servicereference, next){
741         var url = URL.epgnow+servicereference;
742
743         if(typeof(next) == 'undefined'){
744                 doRequest(url, incomingServiceEPGNow, false);
745         } else {
746                 url = URL.epgnext+servicereference;
747                 doRequest(url, incomingServiceEPGNext, false);
748         }
749 }
750
751
752 function getBouquetEpg(){
753         loadServiceEPGNowNext(currentBouquet);
754         loadServiceEPGNowNext(currentBouquet, true);
755 }
756
757
758 function recordNowPopup(){
759         var result = confirm(   
760                         "OK: Record current event\n" +
761                         "Cancel: Start infinite recording"
762         );
763
764         if( result === true || result === false){
765                 recordNowDecision(result);
766         }
767 }
768
769
770 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
771 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
772 //++++ volume functions ++++
773 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
774 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
775 function handleVolumeRequest(request){
776         if (request.readyState == 4) {
777                 var b = getXML(request).getElementsByTagName("e2volume");
778                 var newvalue = b.item(0).getElementsByTagName('e2current').item(0).firstChild.data;
779                 var mute = b.item(0).getElementsByTagName('e2ismuted').item(0).firstChild.data;
780                 debug("[handleVolumeRequest] Volume " + newvalue + " | Mute: " + mute);
781
782                 for (var i = 1; i <= 10; i++)           {
783                         if ( (newvalue/10)>=i){
784                                 $("volume"+i).src = "/web-data/img/led_on.png";
785                         }else{
786                                 $("volume"+i).src = "/web-data/img/led_off.png";
787                         }
788                 }
789                 if (mute == "False"){
790                         $("speaker").src = "/web-data/img/speak_on.png";
791                 }else{
792                         $("speaker").src = "/web-data/img/speak_off.png";
793                 }
794         }       
795 }
796
797
798 function getVolume(){
799         doRequest(URL.getvolume, handleVolumeRequest, false);
800 }
801
802 function volumeSet(val){
803         doRequest(URL.setvolume+val, handleVolumeRequest, false);
804 }
805
806 function volumeUp(){
807         doRequest(URL.volumeup, handleVolumeRequest, false);
808 }
809
810 function volumeDown(){
811         doRequest(URL.volumedown, handleVolumeRequest, false);
812 }
813
814 function volumeMute(){
815         doRequest(URL.volumemute, handleVolumeRequest, false);
816 }
817
818 function initVolumePanel(){
819         getVolume(); 
820 }
821
822
823
824 //Channels and Bouquets
825
826 function incomingChannellist(request){
827         var serviceList = null;
828         if(typeof(loadedChannellist[currentBouquet]) != "undefined"){
829                 serviceList = loadedChannellist[currentBouquet];
830         } else if(request.readyState == 4) {
831                 serviceList = new ServiceList(getXML(request)).getArray();
832                 debug("[incomingChannellist] got "+serviceList.length+" Services");
833         }
834         if(serviceList !== null) {              
835                 var data = { services : serviceList };
836
837                 processTpl('tplServiceList', data, 'contentServices', getBouquetEpg);
838                 delayedGetSubservices();
839         } else {
840                 debug("[incomingChannellist] services is null");
841         }
842 }
843
844
845 function loadBouquet(servicereference, name){ 
846         debug("[loadBouquet] called");
847
848         currentBouquet = servicereference;
849
850         setContentHd(name);
851         setAjaxLoad('contentServices');
852
853         startUpdateBouquetItemsPoller();
854         doRequest(URL.getservices+servicereference, incomingChannellist, true);
855
856 }
857
858
859 function incomingBouquetListInitial(request){
860         if (request.readyState == 4) {
861                 var bouquetList = new ServiceList(getXML(request)).getArray();
862                 debug("[incomingBouquetListInitial] Got " + bouquetList.length + " TV Bouquets!");      
863         
864                 // loading first entry of TV Favorites as default for ServiceList
865                 incomingBouquetList(
866                                 request, 
867                                 function(){
868                                         loadBouquet(bouquetList[0].servicereference, bouquetList[0].servicename);;
869                                 }
870                         );
871         }
872 }
873
874
875 function incomingBouquetList(request, callback){
876         if (request.readyState == 4) {
877                 var bouquetList = new ServiceList(getXML(request)).getArray();
878                 debug("[incomingBouquetList] got " + bouquetList.length + " TV Bouquets!");     
879                 var data = { bouquets : bouquetList };
880                 
881                 if( $('contentBouquets') != "undefined" && $('contentBouquets') != null ){
882                         processTpl('tplBouquetList', data, 'contentBouquets');
883                         if(typeof(callback) == 'function')
884                                 callback();
885                 } else {
886                         processTpl(                                     
887                                         'tplBouquetsAndServices', 
888                                         null, 
889                                         'contentMain',
890                                         function(){
891                                                 processTpl('tplBouquetList', data, 'contentBouquets');
892                                                 if(typeof(callback) == 'function')
893                                                         callback();
894                                         }
895                         );
896                 }
897         }
898 }
899
900
901 function initChannelList(){
902         var url = URL.getservices+encodeURIComponent(bouquetsTv);
903         currentBouquet = bouquetsTv;
904
905         doRequest(url, incomingBouquetListInitial, true);
906 }
907
908
909
910 //Movies
911 function initMovieList(){
912         // get videodirs, last_videodir, and all tags
913         doRequest(URL.getcurrlocation, incomingMovieListCurrentLocation, false);
914 }
915
916 function incomingMovieListCurrentLocation(request){
917         if(request.readyState == 4){
918                 result  = new SimpleXMLList(getXML(request), "e2location");
919                 currentLocation = result.getList()[0];
920                 debug("[incomingMovieListCurrentLocation].currentLocation" + currentLocation);
921                 doRequest(URL.getlocations, incomingMovieListLocations, false);
922         }
923 }
924
925 function incomingMovieListLocations(request){
926         if(request.readyState == 4){
927                 result  = new SimpleXMLList(getXML(request), "e2location");
928                 locationsList = result.getList();
929
930                 if (locationsList.length === 0) {
931                         locationsList = ["/hdd/movie"];
932                 }
933                 doRequest(URL.gettags, incomingMovieListTags, false);
934         }
935 }
936
937 function incomingMovieListTags(request){
938         if(request.readyState == 4){
939                 result  = new SimpleXMLList(getXML(request), "e2tag");
940                 tagsList = result.getList();
941         }
942 }
943
944 function createOptionListSimple(lst, selected) {
945         var namespace = Array();
946         var i = 0;
947         var found = false;
948
949         for (i = 0; i < lst.length; i++) {
950                 if (lst[i] == selected) {
951                         found = true;
952                 }
953         }
954
955         if (!found) {
956                 lst = [ selected ].concat(lst);
957         }
958
959         for (i = 0; i < lst.length; i++) {
960                 namespace[i] = {
961                                 'value': lst[i],
962                                 'txt': lst[i],
963                                 'selected': (lst[i] == selected ? "selected" : " ")};
964         }
965
966         return namespace;
967 }
968
969 function loadMovieNav(){
970         // fill in menus
971         var data = {
972                         dirname: createOptionListSimple(locationsList, currentLocation),
973                         tags: createOptionListSimple(tagsList, "")
974         };
975
976         processTpl('tplNavMovies', data, 'navContent');
977 }
978
979 function incomingMovieList(request){
980         if(request.readyState == 4){
981
982                 var movieList = new MovieList(getXML(request)).getArray();
983                 debug("[incomingMovieList] Got "+movieList.length+" movies");
984
985                 var data = { movies : movieList };
986                 processTpl('tplMovieList', data, 'contentMain');
987         }               
988 }
989
990 function loadMovieList(loc, tag){
991         if(typeof(loc) == 'undefined'){
992                 loc = currentLocation;
993         }
994         if(typeof(tag) == 'undefined'){
995                 tag = '';
996         }
997         debug("[loadMovieList] Loading movies in location '"+loc+"' with tag '"+tag+"'");
998         doRequest(URL.movielist+"?dirname="+loc+"&tag="+tag, incomingMovieList, false);
999 }
1000
1001
1002 function incomingDelMovieResult(request) {
1003         debug("[incomingDelMovieResult] called");
1004         if(request.readyState == 4){
1005                 var result = new SimpleXMLResult(getXML(request));
1006                 if(result.getState()){                  
1007                         loadMovieList();
1008                 }
1009                 simpleResultHandler(result);
1010         }               
1011 }
1012
1013
1014 function delMovie(sref ,servicename, title, description) {
1015         debug("[delMovie] File(" + unescape(sref) + "), servicename(" + servicename + ")," +
1016                         "title(" + unescape(title) + "), description(" + description + ")");
1017
1018         result = confirm( "Are you sure want to delete the Movie?\n" +
1019                         "Servicename: " + servicename + "\n" +
1020                         "Title: " + unescape(title) + "\n" + 
1021                         "Description: " + description + "\n");
1022
1023         if(result){
1024                 debug("[delMovie] ok confirm panel"); 
1025                 doRequest(URL.moviedelete+"?sRef="+unescape(sref), incomingDelMovieResult, false); 
1026                 return true;
1027         }
1028         else{
1029                 debug("[delMovie] cancel confirm panel");
1030                 return false;
1031         }
1032 }
1033
1034 //Send Messages and Receive the Answer
1035
1036
1037 function incomingMessageResult(request){
1038         if(request.readyState== 4){
1039                 var result = new SimpleXMLResult(getXML(request));
1040                 simpleResultHandler(result);
1041         }
1042 }
1043
1044 function getMessageAnswer() {
1045         doRequest(URL.messageanswer, incomingMessageResult, false);
1046 }
1047
1048 function sendMessage(messagetext, messagetype, messagetimeout){
1049         if(!messagetext){
1050                 messagetext = $('MessageSendFormText').value;
1051         }       
1052         if(!messagetimeout){
1053                 messagetimeout = $('MessageSendFormTimeout').value;
1054         }       
1055         if(!messagetype){
1056                 var index = $('MessageSendFormType').selectedIndex;
1057                 messagetype = $('MessageSendFormType').options[index].value;
1058         }       
1059         if(parseNr(messagetype) === 0){
1060                 doRequest(URL.message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout);
1061                 setTimeout(getMessageAnswer, parseNr(messagetimeout)*1000);
1062         } else {
1063                 doRequest(URL.message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, incomingMessageResult, false);
1064         }
1065 }
1066
1067
1068 //Screenshots
1069 function getScreenShot(what) {
1070         debug("[getScreenShot] called");
1071
1072         var buffer = new Image();
1073         var downloadStart;
1074         var data = {};
1075
1076         buffer.onload = function () { 
1077                 debug("[getScreenShot] image assigned");
1078
1079                 data = { img : { src : buffer.src } };  
1080                 processTpl('tplGrab', data, 'contentMain');
1081
1082                 return true;
1083         };
1084
1085         buffer.onerror = function (meldung) { 
1086                 debug("[getScreenShot] Loading image failed"); 
1087                 return true;
1088         };
1089
1090         switch(what){
1091         case "o":
1092                 what = "&o=&n=";
1093                 break;
1094         case "v":
1095                 what = "&v=";
1096                 break;
1097         default:
1098                 what = "";
1099         break;
1100         }
1101
1102         downloadStart = new Date().getTime();
1103         buffer.src = '/grab?format=jpg&r=720&' + what + '&filename=/tmp/' + downloadStart;
1104 }
1105
1106 function getVideoShot() {
1107         getScreenShot("v");
1108 }
1109
1110 function getOsdShot(){
1111         getScreenShot("o");
1112 }
1113
1114 //RemoteControl Code
1115
1116 function incomingRemoteControlResult(request){
1117 //      if(request.readyState == 4){
1118 //              var b = getXML(request).getElementsByTagName("e2remotecontrol");
1119 //              var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
1120 //              var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
1121 //      }
1122 }
1123
1124 function openWebRemote(){
1125         var template = templates.tplWebRemoteOld;
1126
1127         if(boxtype == "dm8000"){
1128                 template = templates.tplWebRemote;
1129         }
1130
1131
1132         if (!webRemoteWin.closed && webRemoteWin.location) {
1133                 setWindowContent(webRemoteWin, template);
1134         } else {
1135                 webRemoteWin = openPopup('WebRemote', template, 250, 600);
1136         }
1137
1138 }
1139
1140
1141 function loadAndOpenWebRemote(){
1142         if(boxtype == "dm8000"){
1143                 fetchTpl('tplWebRemote', openWebRemote);
1144                 
1145         } else {
1146                 fetchTpl('tplWebRemoteOld', openWebRemote);
1147         }
1148 }
1149
1150
1151 function sendRemoteControlRequest(command){
1152         doRequest(URL.remotecontrol+'?command='+command, incomingRemoteControlResult, false);
1153         if(webRemoteWin.document.getElementById('getScreen').checked) {
1154                 if(webRemoteWin.document.getElementById('getVideo').checked){
1155                         getScreenShot();
1156                 } else {
1157                         getScreenShot("o");
1158                 }
1159         }
1160 }
1161
1162
1163 // Array.insert( index, value ) - Insert value at index, without overwriting existing keys
1164 Array.prototype.insert = function( j, v ) {
1165         if( j>=0 ) {
1166                 var a = this.slice(), b = a.splice( j );
1167                 a[j] = v;
1168                 return a.concat( b );
1169         }
1170 };
1171
1172 //Array.splice() - Remove or replace several elements and return any deleted
1173 //elements
1174 if( typeof Array.prototype.splice==='undefined' ) {
1175         Array.prototype.splice = function( a, c ) {
1176                 var e = arguments, d = this.copy(), f = a, l = this.length;
1177
1178                 if( !c ) { 
1179                         c = l - a; 
1180                 }
1181
1182                 for( var i = 0; i < e.length - 2; i++ ) { 
1183                         this[a + i] = e[i + 2]; 
1184                 }
1185
1186
1187                 for( var j = a; j < l - c; j++ ) { 
1188                         this[j + e.length - 2] = d[j - c]; 
1189                 }
1190                 this.length -= c - e.length + 2;
1191
1192                 return d.slice( f, f + c );
1193         };
1194 }
1195
1196 function ifChecked(rObj) {
1197         if(rObj.checked) {
1198                 return rObj.value;
1199         } else {
1200                 return "";
1201         }
1202 }
1203
1204 //Device Info
1205 /*
1206  * Handles an incoming request for /web/deviceinfo Parses the Data, and calls
1207  * everything needed to render the Template using the parsed data and set the
1208  * result into contentMain @param request - the XHR
1209  */
1210 function incomingDeviceInfo(request) {
1211         if(request.readyState == 4){
1212                 debug("[incomingDeviceInfo] called");
1213                 var deviceInfo = new DeviceInfo(getXML(request));
1214
1215                 processTpl('tplDeviceInfo', deviceInfo, 'contentMain');
1216         }
1217 }
1218
1219
1220 /*
1221  * Show Device Info Information in contentMain
1222  */
1223 function showDeviceInfo() {
1224         doRequest(URL.deviceinfo, incomingDeviceInfo, false);
1225 }
1226
1227 function showGears(){
1228         var enabled = false;
1229         
1230         if (window.google && google.gears){
1231                 enabled = gearsEnabled();
1232         }
1233         
1234         data = { 'useGears' : enabled };
1235         processTpl('tplGears', data, 'contentMain');
1236 }
1237
1238 function showSettings(){
1239         var debug = userprefs.data.debug;
1240         var debugChecked = "";
1241         if(debug){
1242                 debugChecked = 'checked';
1243         }
1244         
1245         var updateCurrentInterval = userprefs.data.updateCurrentInterval / 1000;
1246         var updateBouquetInterval = userprefs.data.updateBouquetInterval / 1000;
1247         
1248
1249         data = {'debug' : debugChecked,
1250                         'updateCurrentInterval' : updateCurrentInterval,
1251                         'updateBouquetInterval' : updateBouquetInterval
1252         };
1253         processTpl('tplSettings', data, 'contentMain');
1254 }
1255
1256  
1257 // Spezial functions, mostly for testing purpose
1258 function openHiddenFunctions(){
1259         openPopup("Extra Hidden Functions",tplExtraHiddenFunctions,300,100,920,0);
1260 }
1261
1262
1263 function startDebugWindow() {
1264         DBG = true;
1265         debugWin = openPopup("DEBUG", "", 300, 300,920,140, "debugWindow");
1266 }
1267
1268
1269 function restartTwisted() {
1270         doRequest( "/web/restarttwisted" );
1271 }
1272
1273
1274 //MediaPlayer
1275 function sendMediaPlayer(command) {
1276         debug("[sendMediaPlayer] called");
1277         doRequest( URL.mediaplayercmd+command );
1278 }
1279
1280
1281 function incomingMediaPlayer(request){
1282         if(request.readyState == 4){
1283                 var files = new FileList(getXML(request)).getArray();
1284
1285                 debug("[loadMediaPlayer] Got "+files.length+" entries in mediaplayer filelist");
1286                 // listerHtml = tplMediaPlayerHeader;
1287
1288                 var namespace = {};
1289
1290                 var root = files[0].getRoot();
1291                 if (root != "playlist") {
1292                         namespace = {'root': root};
1293                         if(root != '/') {
1294                                 var re = new RegExp(/(.*)\/(.*)\/$/);
1295                                 re.exec(root);
1296                                 var newroot = RegExp.$1+'/';
1297                                 if(newroot == '//') {
1298                                         newroot = '/';
1299                                 }
1300                                 namespace = {
1301                                                 'root': root,
1302                                                 'servicereference': newroot,
1303                                                 'exec': 'loadMediaPlayer',
1304                                                 'exec_description': 'Change to directory ../',
1305                                                 'color': '000000',
1306                                                 'newroot': newroot,
1307                                                 'name': '..'
1308                                 };      
1309                         }
1310                 }
1311
1312                 var itemnamespace = Array();
1313                 for ( var i = 0; i <files.length; i++){
1314                         var file = files[i];
1315                         if(file.getNameOnly() == '') {
1316                                 continue;
1317                         }
1318                         var exec = 'loadMediaPlayer';
1319                         var exec_description = 'Change to directory' + file.getServiceReference();
1320                         var color = '000000';                   
1321                         var isdir = 'true';
1322
1323                         if (file.getIsDirectory() == "False") {
1324                                 exec = 'playFile';
1325                                 exec_description = 'play file';
1326                                 color = '00BCBC';
1327                                 isdir = 'false';
1328                         }
1329
1330                         itemnamespace[i] = {
1331                                         'isdir' : isdir,
1332                                         'servicereference': file.getServiceReference(),
1333                                         'exec': exec,
1334                                         'exec_description': exec_description,
1335                                         'color': color,                                                 
1336                                         'root': file.getRoot(),
1337                                         'name': file.getNameOnly()
1338                         };
1339
1340                 }
1341                 /*
1342                 if (root == "playlist") {
1343                         listerHtml += tplMediaPlayerFooterPlaylist;
1344                 }
1345                  */
1346
1347                 var data = { mp : namespace,
1348                                 items: itemnamespace
1349                 };
1350
1351                 processTpl('tplMediaPlayer', data, 'contentMain');
1352                 var sendMediaPlayerTMP = sendMediaPlayer;
1353                 sendMediaPlayer = false;
1354                 // setBodyMainContent('BodyContent');
1355                 sendMediaPlayer = sendMediaPlayerTMP;
1356         }               
1357 }
1358
1359
1360 function loadMediaPlayer(directory){
1361         debug("[loadMediaPlayer] called");
1362         if(typeof(directory) == 'undefined') directory = 'Filesystems';
1363         doRequest(URL.mediaplayerlist+directory, incomingMediaPlayer, false);
1364 }
1365
1366
1367 function playFile(file,root) {
1368         debug("[playFile] called");
1369         mediaPlayerStarted = true;
1370         doRequest( URL.mediaplayerplay+file+"&root="+root );
1371 }
1372
1373
1374 function deleteFile(sref) {
1375         debug("[deleteFile] called");
1376         mediaPlayerStarted = true;
1377         doRequest( URL.mediaplayerremove+sref );
1378 }
1379
1380
1381 function openMediaPlayerPlaylist() {
1382         debug("[openMediaPlayerPlaylist] called");
1383         doRequest(URL.mediaplayerlist+"playlist", incomingMediaPlayer, false);
1384 }
1385
1386
1387 function writePlaylist() {
1388         debug("[writePlaylist] called");
1389         var filename = '';
1390         filename = prompt("Please enter a name for the playlist", "");
1391
1392         if(filename !== "") {
1393                 doRequest( URL.mediaplayerwrite+filename );
1394         }
1395 }
1396
1397 //Powerstate
1398 /*
1399  * Sets the Powerstate @param newState - the new Powerstate Possible Values
1400  * (also see WebComponents/Sources/PowerState.py) #-1: get current state # 0:
1401  * toggle standby # 1: poweroff/deepstandby # 2: rebootdreambox # 3:
1402  * rebootenigma
1403  */
1404 function sendPowerState(newState){
1405         doRequest( URL.powerstate+'?newstate='+newState, incomingPowerState);
1406 }
1407
1408
1409 //Currently Running Service
1410 function incomingCurrent(request){
1411         //      debug("[incomingCurrent called]");
1412         if(request.readyState == 4){
1413                 try{
1414                         var epg = new EPGList(getXML(request)).getArray();
1415                         epg = epg[0];
1416
1417                         var data = { current : epg };
1418
1419                         if(typeof(templates.tplCurrent) != "undefined"){
1420                                 var display = 'none';
1421                                 try{
1422                                         var display = $('trExtCurrent').style.display;
1423                                 } catch(e){}
1424                                 
1425                                 renderTpl(templates.tplCurrent, data, "currentContent");
1426                                 $('trExtCurrent').style.display = display;
1427                         } else {
1428                                 debug("[incomingCurrent] tplCurrent N/A");
1429                         }
1430
1431                 } catch (e){}
1432                 
1433                 isActive.getCurrent = false;
1434         }
1435 }
1436
1437
1438 function getCurrent(){
1439         if(!isActive.getCurrent){
1440                 isActive.getCurrent = true;
1441                 doRequest(URL.getcurrent, incomingCurrent, false);
1442         }
1443 }
1444
1445
1446 //Navigation and Content Helper Functions
1447
1448 /*
1449  * Loads all Bouquets for the given enigma2 servicereference and sets the
1450  * according contentHeader @param sRef - the Servicereference for the bouquet to
1451  * load
1452  */
1453 function getBouquets(sRef){     
1454         var url = URL.getservices+encodeURIComponent(sRef);
1455         
1456         doRequest(url, incomingBouquetList, true);              
1457 }
1458
1459 /*
1460  * Loads another navigation template and sets the navigation header
1461  * @param template - The name of the template
1462  * @param title - The title to set for the navigation
1463  */
1464 function reloadNav(template, title){
1465         setAjaxLoad('navContent');
1466         processTpl(template, null, 'navContent');
1467         setNavHd(title);
1468 }
1469
1470 function reloadNavDynamic(fnc, title){
1471         setAjaxLoad('navContent');
1472         setNavHd(title);
1473         fnc();
1474 }
1475
1476 function getBouquetsTv(){
1477         getBouquets(bouquetsTv);
1478 }
1479
1480 function getProviderTv(){
1481         getBouquets(providerTv);
1482 }
1483
1484 function getSatellitesTv(){
1485         getBouquets(satellitesTv);
1486 }
1487
1488 function getAllTv(){
1489         loadBouquet(allTv, "All (TV)");
1490 }
1491
1492
1493 function getBouquetsRadio(){
1494         getBouquets(bouquetsRadio);
1495 }
1496
1497 function getProviderRadio(){
1498         getBouquets(providerRadio);
1499 }
1500
1501 function getSatellitesRadio(){
1502         getBouquets(satellitesRadio);
1503 }
1504
1505 function getAllRadio(){
1506         loadBouquet(allRadio, "All (Radio)");
1507 }
1508
1509 /*
1510  * Loads dynamic content to $(contentMain) by calling a execution function
1511  * @param fnc - The function used to load the content
1512  * @param title - The Title to set on the contentpanel
1513  */
1514 function loadContentDynamic(fnc, title, domid){
1515         if(typeof(domid) != "undefined" && $(domid) != null){
1516                 setAjaxLoad(domid);
1517         } else {
1518                 setAjaxLoad('contentMain');
1519         }
1520         setContentHd(title);
1521         stopUpdateBouquetItemsPoller();
1522
1523         fnc();
1524 }
1525
1526 /*
1527  * like loadContentDynamic but without the AjaxLoaderAnimation being shown
1528  */
1529 function reloadContentDynamic(fnc, title){
1530         setContentHd(title);
1531         fnc();
1532 }
1533
1534 /*
1535  * Loads a static template to $(contentMain)
1536  * @param template - Name of the Template
1537  * @param title - The Title to set on the Content-Panel
1538  */
1539 function loadContentStatic(template, title){
1540         setAjaxLoad('contentMain');
1541         setContentHd(title);
1542         stopUpdateBouquetItemsPoller();
1543         processTpl(template, null, 'contentMain');
1544 }
1545
1546
1547 /*
1548  * Opens the given Control
1549  * @param control - Control Page as String
1550  * Possible Values: power, extras, message, screenshot, videoshot, osdshot
1551  */
1552 function loadControl(control){
1553         switch(control){
1554         case "power":
1555                 loadContentStatic('tplPower', 'PowerControl');
1556                 break;
1557
1558         case "message":
1559                 loadContentStatic('tplSendMessage', 'Send a Message');
1560                 break;
1561
1562         case "remote":
1563                 loadAndOpenWebRemote();
1564                 break;
1565
1566         case "screenshot":
1567                 loadContentDynamic(getScreenShot, 'Screenshot');
1568                 break;
1569
1570         case "videoshot":
1571                 loadContentDynamic(getVideoShot, 'Videoshot');
1572                 break;
1573
1574         case "osdshot":
1575                 loadContentDynamic(getOsdShot, 'OSDshot');
1576                 break;
1577
1578         default:
1579                 break;
1580         }
1581 }
1582
1583
1584 function loadDeviceInfo(){
1585         loadContentDynamic(showDeviceInfo, 'Device Information');
1586 }
1587
1588 function loadAbout(){
1589         loadContentStatic('tplAbout', 'About');
1590 }
1591
1592 function loadSettings(){
1593         loadContentDynamic(showSettings, 'Settings');
1594 }
1595
1596 function loadGearsInfo(){
1597         loadContentDynamic(showGears, 'Google Gears');
1598 }
1599
1600 function reloadGearsInfo(){
1601         loadContentDynamic(showGears, 'Google Gears');
1602 }
1603
1604
1605 /*
1606  * Switches Navigation Modes
1607  * @param mode - The Navigation Mode you want to switch to
1608  * Possible Values: TV, Radio, Movies, Timer, Extras
1609  */
1610 function switchMode(mode){
1611         switch(mode){
1612         case "TV":
1613                 reloadNav('tplNavTv', 'TeleVision');
1614                 break;
1615
1616         case "Radio":
1617                 reloadNav('tplNavRadio', 'Radio');
1618                 break;
1619
1620         case "Movies":
1621                 //The Navigation
1622                 reloadNavDynamic(loadMovieNav, 'Movies');
1623
1624                 // The Movie list
1625                 loadContentDynamic(loadMovieList, 'Movies');
1626                 break;
1627
1628         case "Timer":
1629                 //The Navigation
1630                 reloadNav('tplNavTimer', 'Timer');
1631
1632                 // The Timerlist
1633                 loadContentDynamic(loadTimerList, 'Timer');
1634                 break;
1635
1636         case "MediaPlayer":
1637                 loadContentDynamic(loadMediaPlayer, 'MediaPlayer');
1638                 break;
1639
1640         case "BoxControl":
1641                 reloadNav('tplNavBoxControl', 'BoxControl');
1642                 break;
1643
1644         case "Extras":
1645                 reloadNav('tplNavExtras', 'Extras');
1646                 break;
1647                 
1648         default:
1649                 break;
1650         }
1651 }
1652
1653 function openWebTV(){
1654         window.open('/web-data/streaminterface.html', 'WebTV', 'scrollbars=no, width=800, height=730');
1655 }
1656
1657
1658
1659 function updateItems(){
1660         getCurrent();
1661         getPowerState();
1662 }
1663
1664 function updateItemsLazy(bouquet){
1665         getSubServices();
1666         getBouquetEpg();
1667 }
1668
1669 /*
1670  * Does the everything required on initial pageload
1671  */
1672
1673 function init(){
1674         var DBG = userprefs.data.debug || false;
1675         
1676         if(DBG){
1677                 openDebug();
1678         }
1679
1680         if( parseNr(userprefs.data.updateCurrentInterval) < 10000){
1681                 userprefs.data.updateCurrentInterval = 120000;
1682                 userprefs.save();
1683         }
1684         
1685         if( parseNr(userprefs.data.updateBouquetInterval) < 60000 ){
1686                 userprefs.data.updateBouquetInterval = 300000;
1687                 userprefs.save();
1688         }
1689         
1690         if (typeof document.body.style.maxHeight == "undefined") {
1691                 alert("Due to the tremendous amount of work needed to get everthing to " +
1692                 "work properly, there is (for now) no support for Internet Explorer Versions below 7");
1693         }
1694         
1695         getBoxtype();
1696
1697         setAjaxLoad('navContent');
1698         setAjaxLoad('contentMain');
1699
1700         fetchTpl('tplServiceListEPGItem');
1701         fetchTpl('tplBouquetsAndServices');
1702         fetchTpl('tplCurrent'); 
1703         reloadNav('tplNavTv', 'TeleVision');
1704
1705         initChannelList();
1706         initVolumePanel();
1707         initMovieList();
1708
1709         updateItems();
1710         startUpdateCurrentPoller();
1711 }