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