disable debug
[enigma2-plugins.git] / webinterface / src / web-data / tools.js
1 var url_getvolume = '/web/vol?set=state'; 
2 var url_setvolume = '/web/vol?set=set'; // plus new value eq. set=set15
3 var url_volumeup = '/web/vol?set=up';
4 var url_volumedown = '/web/vol?set=down';
5 var url_volumemute = '/web/vol?set=mute';
6
7 var url_epgservice = "/web/epgservice?ref="; // plus serviceRev
8 var url_epgsearch = "/web/epgsearch?search="; // plus serviceRev
9 var url_epgnow = "/web/epgnow?bref="; // plus bouqetRev
10
11 var url_fetchchannels = "/web/fetchchannels?ServiceListBrowse="; // plus encoded serviceref
12
13 var url_updates= "/web/updates.html";
14
15 var url_movielist= "/web/movielist";
16
17 var url_timerlist= "/web/timerlist";
18 var url_timeradd= "/web/timeradd"; // plus serviceref,begin,end,name,description,eit,disabled,justplay,afterevent
19 var url_timeraddbyeventid= "/web/timeraddbyeventid"; // plus serviceref,eventid
20 var url_timerdelete= "/web/timerdelete"; // plus serviceref,bedin,end
21
22 var url_message = "/web/message"; // plus text,type,timeout
23
24 var url_powerstate = "/web/powerstate"; // plus new powerstate
25 var url_remotecontrol = "/web/remotecontrol"; // plus command
26
27 var bouqet_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25)FROM BOUQUET "bouquets.tv" ORDER BY bouquet';
28 var bouqet_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)FROM BOUQUET "bouquets.radio" ORDER BY bouquet';
29 var bouqet_provider_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25) FROM PROVIDERS ORDER BY name';
30 var bouqet_provider_radio ='1:7:2:0:0:0:0:0:0:0:(type == 2) FROM PROVIDERS ORDER BY name';
31
32 var windowStyle = "alphacube";
33 var DBG = false;
34
35 // UpdateStreamReader
36 var UpdateStreamReaderNextReadPos = 0;
37 var UpdateStreamReaderPollTimer;
38 UpdateStreamReaderRequest = null;
39 function UpdateStreamReaderStart(){
40         var ua = navigator.userAgent;
41         if(navigator.userAgent.indexOf("MSIE") >=0) {
42                 debug("UpdateStreamReader IE Fix");
43
44                 var namespace = {       
45                                         'url_updates': url_updates
46                 };
47                 $('UpdateStreamReaderIEFixPanel').innerHTML = RND(tplUpdateStreamReaderIE, namespace);
48                 
49         }else {
50                 UpdateStreamReaderNextReadPos = 0;
51                 allMessages = "";
52                 UpdateStreamReaderRequest = new XMLHttpRequest();
53                 UpdateStreamReaderRequest.onload = UpdateStreamReaderOnLoad;
54                 UpdateStreamReaderRequest.onerror = UpdateStreamReaderOnError;
55                 UpdateStreamReaderRequest.open("GET", url_updates, true);
56                 UpdateStreamReaderRequest.send(null);
57                 UpdateStreamReaderPollTimer = setInterval(UpdateStreamReaderLatestResponse, 500);
58         }
59 }
60   
61 function UpdateStreamReaderLatestResponse() {
62         var allMessages = UpdateStreamReaderRequest.responseText;
63         do {
64                 var unprocessed = allMessages.substring(UpdateStreamReaderNextReadPos);
65                 var messageXMLEndIndex = unprocessed.indexOf("\n");
66                 
67                 if (messageXMLEndIndex!=-1) {
68                         var endOfFirstMessageIndex = messageXMLEndIndex + "\n".length;
69                         var anUpdate = unprocessed.substring(0, endOfFirstMessageIndex);
70         
71                         var re = new RegExp("<script>parent\.(.*)</script>");
72                         anUpdate = re.exec(anUpdate);
73
74                         if(anUpdate != null){
75                                 if (anUpdate.length == 2){
76                                         eval(anUpdate[1]);
77                                 }
78                         }
79                         
80                         UpdateStreamReaderNextReadPos += endOfFirstMessageIndex;
81                 }
82                 if(UpdateStreamReaderNextReadPos > 65000){
83                         UpdateStreamReaderRequest.abort();
84                         UpdateStreamReaderStart();
85                         messageXMLEndIndex = -1;
86                 }
87         } while (messageXMLEndIndex != -1);
88 }
89
90 function UpdateStreamReaderOnLoad(){
91         window.clearInterval(UpdateStreamReaderPollTimer);
92         debug("UpdateStreamReaderOnLoad");
93         Dialog.confirm(
94                 "Live Update Stream ends!<br><br>You will not receive any Update from Enigma2.<br>Should I reconnect?",
95                  {windowParameters: {width:300, className: windowStyle},
96                         okLabel: "reconnect",
97                         buttonClass: "myButtonClass",
98                         cancel: function(win) {debug("cancel confirm panel")},
99                         ok: function(win) {UpdateStreamReaderStart(); return true;}
100                         }
101                 );
102 }
103 function UpdateStreamReaderOnError(){
104         // TODO: change this, because it will be called on 'PageUnload' while the request is still running
105         debug("UpdateStreamReaderOnError");
106         window.clearInterval(UpdateStreamReaderPollTimer);
107         Dialog.confirm(
108                 "Live Update Stream has an Error!<br><br>You will not receive any Update from Enigma2.<br>Should I try to reconnect?",
109                  {windowParameters: {width:300, className: windowStyle},
110                          okLabel: "reconnect",
111                          buttonClass: "myButtonClass",
112                          cancel: function(win) {debug("cancel confirm panel")},
113                          ok: function(win) {UpdateStreamReaderStart(); return true;}
114                         }
115                 );
116 }
117
118 //end UpdateStreamReader
119
120 function openWindow(title, inner, width, height, id){
121                         if(id == null) id = new Date().toUTCString();
122                         
123                         //debug(id);
124                         var win = new Window(id, {className: windowStyle, title: title, width: width, height: height});
125                         win.getContent().innerHTML = inner;
126                         win.setDestroyOnClose();
127                         win.showCenter();
128                         debug("opening Window: "+title);
129                         return win;
130 }
131
132 function messageBox(t, m){
133         Dialog.alert(m, {windowParameters: {title: t, className: windowStyle, width:200}, okLabel: "Close"});
134 }
135
136 //RND Template Function (http://www.amix.dk)
137
138 function RND(tmpl, ns) {
139         var fn = function(w, g) {
140                 g = g.split("|");
141                 var cnt = ns[g[0]];
142
143                 //Support for filter functions
144                 for(var i=1; i < g.length; i++) {
145                         cnt = eval(g[i])(cnt);
146                 }
147                 return cnt || w;
148         };
149         return tmpl.replace(/%\(([A-Za-z0-9_|.]*)\)/g, fn);
150 }
151
152 function debug(text){
153         if(DBG){
154                 try{
155                         debugWin.getContent().innerHTML += "DEBUG: "+text+"<br>";
156                 } catch (windowNotPresent) {}
157         }
158 }
159
160 function showhide(id){
161         o = document.getElementById(id).style;
162         o.display = (o.display!="none")? "none":"";
163 }
164
165 function set(what, value){
166         //debug(what+"-"+value);
167         element = parent.document.getElementById(what);
168         if (element){
169                 element.innerHTML = value;
170         }
171         if(navigator.userAgent.indexOf("MSIE") >=0) {
172                 elementscript= $('UpdateStreamReaderIEFixIFrame').document.getElementById('scriptzone');
173                 if(elementscript){
174                         elementscript.innerHTML = ""; // deleting set() from page, to keep the page short and to save memory                    
175                 }
176         }
177 }
178 // requestindikator
179 var requestcounter = 0;
180
181 function requestIndicatorUpdate(){
182         //debug(requestcounter+" open requests");
183         if(requestcounter>=1){
184                 $('RequestIndicator').style.display = "inline";
185         }else{
186                 $('RequestIndicator').style.display = "none";
187         }
188 }
189 function requestStarted(){
190         requestcounter +=1;
191         requestIndicatorUpdate();
192 }
193 function requestFinished(){
194         requestcounter -=1;
195         requestIndicatorUpdate();
196 }
197 // end requestindikator
198
199 function doRequest(url, readyFunction){
200         requestStarted();
201         //var password = "";
202         //var username = "";
203         debug(url);
204         new Ajax.Request(url,
205                 {
206                         method: 'get',
207                         requestHeaders: ['Pragma', 'no-cache', 'Cache-Control', 'must-revalidate', 'If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT'],
208                         onSuccess: readyFunction,
209                         onComplete: requestFinished 
210                 });
211 }
212
213 function getXML(request){
214         if (document.implementation && document.implementation.createDocument){
215                 var xmlDoc = request.responseXML
216         }
217         else if (window.ActiveXObject){
218                 var xmlInsert = document.createElement('xml');
219
220                 xmlInsert.setAttribute('innerHTML',request.responseText);
221                 xmlInsert.setAttribute('id','_MakeAUniqueID');
222                 document.body.appendChild(xmlInsert);
223                 xmlDoc = document.getElementById('_MakeAUniqueID');
224                 document.body.removeChild(document.getElementById('_MakeAUniqueID'));
225         } else {
226                 debug("Your Browser Sucks!");
227         }
228         return xmlDoc;
229 }
230
231 function zap(servicereference){
232         var url = "/web/zap?ZapTo=" + servicereference;
233         new Ajax.Request( url,
234                 {
235                         method: 'get'                           
236                 });
237 }
238 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
239 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
240 //++++       SignalPanel                           ++++
241 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
242 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
243
244 function initSignalPanel(){
245         $('SignalPanel').innerHTML = tplSignalPanelButton;
246 }
247 function openSignalDialog(){
248         openWindow("Signal Info",tplSignalPanel, 215, 75);
249 }
250
251 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
252 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
253 //++++ EPG functions                               ++++
254 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
255 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
256 function loadEPGBySearchString(string){
257                 doRequest(url_epgsearch+string,incomingEPGrequest);
258 }
259 function loadEPGByServiceReference(servicereference){
260                 doRequest(url_epgservice+servicereference,incomingEPGrequest);
261 }
262 function incomingEPGrequest(request){
263         debug("incoming request" +request.readyState);          
264         if (request.readyState == 4){
265                 var EPGItems = new EPGList(getXML(request)).getArray(true);
266                 debug("have "+EPGItems.length+" e2events");
267                 if(EPGItems.length > 0){                        
268                         var html = tplEPGListHeader;
269                         for (var i=0; i < EPGItems.length; i++){
270                                 try{
271                                         var item = EPGItems[i];                         
272                                         //Create JSON Object for Template
273                                         var namespace = {       
274                                                         'date': item.getTimeDay(), 
275                                                         'eventid': item.getEventId(), 
276                                                         'servicereference': item.getServiceReference(), 
277                                                         'servicename': item.getServiceName(), 
278                                                         'title': item.getTitle(),
279                                                         'titleESC': escape(item.getTitle()),
280                                                         'starttime': item.getTimeStartString(), 
281                                                         'duration': Math.ceil(item.getDuration()/60000), 
282                                                         'description': item.getDescription(), 
283                                                         'endtime': item.getTimeEndString(), 
284                                                         'extdescription': item.getDescriptionExtended()
285                                                 };
286                                         //Fill template with data and add id to our result
287                                         html += RND(tplEPGListItem, namespace);
288                                 } catch (blubb) { debug("Error rendering: "+blubb);     }
289                         }               
290                         html += tplEPGListFooter;
291                         openWindow("Electronic Program Guide", html, 900, 500);
292                 } else {
293                         messageBox('No Items found!', 'Sorry but i could not find any EPG Content containing your search value');
294                 }
295         }
296 }
297         
298
299 /////////////////////////
300
301 function loadServiceEPGNowNext(servicereference){
302         var url = url_epgnow+servicereference;
303         doRequest(url, incomingServiceEPGNowNext);      
304 }
305
306 function incomingServiceEPGNowNext(request){
307         if(request.readyState == 4){
308                 var epgevents = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");
309                 for (var c =0; c < epgevents.length;c++){
310                         var eventnow = new EPGEvent(epgevents.item(c));
311                         
312                         if (eventnow.getEventId() != 'None'){
313                                 buildServiceListEPGItem(eventnow,"NOW");
314                         }
315                 }
316         }
317 }
318 function buildServiceListEPGItem(epgevent,nownext){
319         var e = $(epgevent.getServiceReference()+'EPG'+nownext);
320                 try{
321                         var namespace = {       
322                                 'starttime': epgevent.getTimeStartString(), 
323                                 'title': epgevent.getTitle(), 
324                                 'length': Math.ceil(epgevent.duration/60) 
325                         };
326                         e.innerHTML = RND(tplServiceListEPGItem, namespace);
327                 } catch (blubb) {
328                         debug("Error rendering: "+blubb);
329                 }       
330 }
331 ///////////////////
332
333
334 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
335 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
336 //++++ GUI functions                               ++++
337 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
338 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
339
340 var currentBodyMainElement = null
341
342 function setBodyMainContent(newelementname){
343         newelement =document.getElementById(newelementname);
344         if(currentBodyMainElement != null){
345                 currentBodyMainElement.style.display = "none";
346                 
347         }
348         newelement.style.display = "";
349         currentBodyMainElement = newelement;
350 }
351
352 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
353 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
354 //++++ volume functions                            ++++
355 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
356 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
357
358 function initVolumePanel(){
359         document.getElementById('VolumePanel').innerHTML = tplVolumePanel;
360         getVolume(); 
361 }
362 function getVolume()
363 {
364         doRequest(url_getvolume,handleVolumeRequest);
365 }
366 function volumeSet(newvalue)
367 {
368         doRequest(url_setvolume+newvalue,handleVolumeRequest);
369 }
370 function volumeUp()
371 {
372         doRequest(url_volumeup,handleVolumeRequest);
373 }
374 function volumeDown()
375 {
376         doRequest(url_volumedown,handleVolumeRequest);  
377 }
378 function volumeMute()
379 {
380         doRequest(url_volumemute,handleVolumeRequest);
381 }
382 function handleVolumeRequest(request){
383         if (request.readyState == 4) {
384                 var b = getXML(request).getElementsByTagName("e2volume");
385                 var newvalue = b.item(0).getElementsByTagName('e2current').item(0).firstChild.data;
386                 var mute = b.item(0).getElementsByTagName('e2ismuted').item(0).firstChild.data;
387                 debug("volume"+newvalue+";"+mute);
388                 
389                 for (var i = 1; i <= 10; i++)
390                 {
391                         if ( (newvalue/10)>=i){
392                                 $("volume"+i).src = "/webdata/gfx/led_on.png";
393                         }else{
394                                 $("volume"+i).src = "/webdata/gfx/led_off.png";
395                         }
396                 }
397                 if (mute == "False"){
398                         $("speaker").src = "/webdata/gfx/speak_on.png";
399                 }else{
400                         $("speaker").src = "/webdata/gfx/speak_off.png";
401                 }
402         }       
403 }
404 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
405 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
406 //++++ bouquet managing functions                  ++++
407 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
408 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
409 function initChannelList(){
410         //debug("init ChannelList");    
411         var url = url_fetchchannels+encodeURIComponent(bouqet_tv);
412         doRequest(url, incomingTVBouquetList);
413
414         var url = url_fetchchannels+encodeURIComponent(bouqet_radio);
415         doRequest(url, incomingRadioBouquetList);
416
417         var url = url_fetchchannels+encodeURIComponent(bouqet_provider_tv);
418         doRequest(url, incomingProviderTVBouquetList);
419
420         var url = url_fetchchannels+encodeURIComponent(bouqet_provider_radio);
421         doRequest(url, incomingProviderRadioBouquetList);
422 }
423 var servicereftoloadepgnow="";
424 function loadBouquet(servicereference){ 
425         debug("loading bouquet with "+servicereference);
426         servicereftoloadepgnow = servicereference;
427         doRequest(url_fetchchannels+servicereference, incomingChannellist);
428 }
429
430 function incomingTVBouquetList(request){
431         if (request.readyState == 4) {
432                 var list0 = new ServiceList(getXML(request)).getArray();
433                 debug("have "+list0.length+" TV Bouquet ");     
434                 $('accordionMenueBouquetContentTV').innerHTML = renderBouquetTable(list0,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
435                 //loading first entry of TV Favorites as default for ServiceList
436                 loadBouquet(list0[0].getServiceReference());
437         }
438 }
439 function incomingRadioBouquetList(request){
440         if (request.readyState == 4) {
441                 var list1 = new ServiceList(getXML(request)).getArray();
442                 debug("have "+list1.length+" Radio Bouquet ");  
443                 $('accordionMenueBouquetContentRadio').innerHTML = renderBouquetTable(list1,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
444         }       
445 }
446 function incomingProviderTVBouquetList(request){
447         if (request.readyState == 4) {
448                 var list2 = new ServiceList(getXML(request)).getArray();
449                 debug("have "+list2.length+" TV Provider Bouquet ");    
450                 $('accordionMenueBouquetContentProviderTV').innerHTML = renderBouquetTable(list2,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
451         }       
452 }
453 function incomingProviderRadioBouquetList(request){
454         if (request.readyState == 4) {
455                 var list2 = new ServiceList(getXML(request)).getArray();
456                 debug("have "+list2.length+" Radio Provider Bouquet "); 
457                 $('accordionMenueBouquetContentProviderRadio').innerHTML = renderBouquetTable(list2,tplBouquetListHeader,tplBouquetListItem,tplBouquetListFooter);
458         }       
459 }
460
461 function renderBouquetTable(bouquet,templateHeader,templateItem,templateFooter){
462         debug("renderBouquetTable with "+bouquet.length+" Bouqet");     
463         var html = templateHeader;
464         for (var i=0; i < bouquet.length; i++){
465                 try{
466                         var namespace = {
467                                 'servicereference': bouquet[i].getServiceReference(), 
468                                 'bouquetname': bouquet[i].getServiceName()
469                         };
470                         html += RND(templateItem, namespace);
471                 } catch (blubb) {}
472         }
473         html += templateFooter;
474         return html;
475 }       
476
477 function incomingChannellist(request){
478         if(request.readyState == 4){
479                 var services = new ServiceList(getXML(request)).getArray();
480                 listerHtml      = tplServiceListHeader;         
481                 debug("got "+services.length+" Services");
482                 for ( var i = 0; i < services.length ; i++){
483                         var reference = services[i];
484                         var namespace = {       
485                                 'servicereference': reference.getServiceReference(),
486                                 'servicename': reference.getServiceName() 
487                         };
488                         listerHtml += RND(tplServiceListItem, namespace);
489                 }               
490                 listerHtml += tplServiceListFooter;
491                 document.getElementById('BodyContentChannellist').innerHTML = listerHtml;
492                 setBodyMainContent('BodyContentChannellist');
493                 loadServiceEPGNowNext(servicereftoloadepgnow);
494         }
495 }
496 // Movies
497 function loadMovieList(){
498         debug("loading movies");
499         doRequest(url_movielist, incomingMovieList);    
500 }
501
502 function incomingMovieList(request){
503         if(request.readyState == 4){
504                 var movies = new MovieList(getXML(request)).getArray();
505                 debug("have "+movies.length+" movies");
506                 listerHtml      = tplMovieListHeader;           
507                 for ( var i = 0; i <movies.length; i++){
508                         var movie = movies[i];
509                         var namespace = {       
510                                 'servicereference': movie.getServiceReference(),
511                                 'servicename': movie.getServiceName() ,
512                                 'title': movie.getTitle(), 
513                                 'description': movie.getDescription(), 
514                                 'descriptionextended': movie.getDescriptionExtended(), 
515                                 'tags': movie.getTags().join(', ') 
516                         };
517                         debug(movie.getServiceReference());
518                         listerHtml += RND(tplMovieListItem, namespace);
519                 }
520                 listerHtml += tplMovieListFooter;
521                 document.getElementById('BodyContentChannellist').innerHTML = listerHtml;
522                 setBodyMainContent('BodyContentChannellist');
523                 
524         }               
525 }
526
527 // Timer
528 function addTimerByID(serviceRef,eventID,justplay){
529         debug("adding timer by eventid="+eventID+" for "+serviceRef);justplay
530         doRequest(url_timeraddbyeventid+"?serviceref="+serviceRef+"&eventid="+eventID+"&justplay="+justplay, incomingTimerAddResult);   
531 }
532 function incomingTimerAddResult(request){
533         debug("onTimerAdded");
534         if(request.readyState == 4){
535                 var addresult = new TimerAddResult(getXML(request));
536                 if(addresult.getState()){
537                         //timer was add
538                         loadTimerList();
539                 }else{
540                         messageBox("Timer Error","your Timer could not be added!\nReason: "+addresult.getStateText());
541                 }
542         }               
543 }
544 function loadTimerList(){
545         debug("loading timers");
546         doRequest(url_timerlist, incomingTimerList);    
547 }
548
549 function incomingTimerList(request){
550         debug(request.readyState);
551         if(request.readyState == 4){
552                 var timers = new TimerList(getXML(request)).getArray();
553                 debug("have "+timers.length+" timer");
554                 listerHtml      = tplTimerListHeader;           
555                 for ( var i = 0; i <timers.length; i++){
556                         var timer = timers[i];
557                         var namespace = {       
558                                 'servicereference': timer.getServiceReference(),
559                                 'servicename': timer.getServiceName() ,
560                                 'title': timer.getName(), 
561                                 'description': timer.getDescription(), 
562                                 'descriptionextended': timer.getDescriptionExtended(), 
563                                 'begin': timer.getTimeBegin(), 
564                                 'end': timer.getTimeEnd(), 
565                                 'state': timer.getState(),
566                                 'duration': Math.ceil((timer.getDuration()/60))
567                         };
568                         listerHtml += RND(tplTimerListItem, namespace);
569                 }
570                 listerHtml += tplTimerListFooter;
571                 document.getElementById('BodyContentChannellist').innerHTML = listerHtml;
572                 setBodyMainContent('BodyContentChannellist');
573                 
574         }
575 }
576 function delTimer(serviceRef,begin,end){
577         debug("deleting timer with serviceRef="+serviceRef+" and start="+begin+"end="+end );
578         debug(url_timerdelete+"?serviceref="+serviceRef+"&begin="+begin+"&end="+end);
579         doRequest(url_timerdelete+"?serviceref="+serviceRef+"&begin="+begin+"&end="+end, incomingTimerDelResult);       
580 }
581
582 function incomingTimerDelResult(request){
583         debug("onTimerDeleted");
584         debug(request.readyState);
585         if(request.readyState == 4){
586                 var delresult = new TimerAddResult(getXML(request));
587                 debug("Lade liste");
588                 loadTimerList();
589         }               
590 }
591 function loadTimerForm() {
592         debug("timers form");
593         debug("there is still work to do here");
594 }
595
596 // send Messages
597 function showMessageSendForm(){
598                 document.getElementById('BodyContentChannellist').innerHTML = tplMessageSendForm;
599 }
600 function sendMessage(messagetext,messagetype,messagetimeout){
601         if(!messagetext){
602                 messagetext = $('MessageSendFormText').value;
603         }       
604         if(!messagetimeout){
605                 messagetimeout = $('MessageSendFormTimeout').value;
606         }       
607         if(!messagetype){
608                 var index = $('MessageSendFormType').selectedIndex;
609                 messagetype = $('MessageSendFormType').options[index].value;
610         }       
611         doRequest(url_message+'?text='+messagetext+'&type='+messagetype+'&timeout='+messagetimeout, incomingMessageResult);
612 }
613 function incomingMessageResult(request){
614
615         if(request.readyState== 4){
616                 var b = getXML(request).getElementsByTagName("e2message");
617                 var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
618                 var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
619                 if (result=="True"){
620                         messageBox('message send','message send successfully! it appears on TV-Screen');
621                 }else{
622                         messageBox('message send failed',resulttext);
623                 }
624         }               
625 }
626
627 // PowerState Code
628 function showPowerStateSendForm(){
629                 document.getElementById('BodyContentChannellist').innerHTML = tplPowerStateSendForm;
630 }
631 function sendPowerState(newState){
632         doRequest(url_powerstate+'?newstate='+newState, incomingPowerStateResult);
633 }
634 function incomingPowerStateResult(request){
635         debug(request.readyState);
636         if(request.readyState == 4){
637                 var b = getXML(request).getElementsByTagName("e2powerstate");
638                 var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
639                 var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
640                 var tplPowerStateSendForm2 = '<h1>PowerState is changing to:'+resulttext+ '</h1>' + tplPowerStateSendForm;
641                 document.getElementById('BodyContentChannellist').innerHTML = tplPowerStateSendForm2;
642         } else {
643                 document.getElementById('BodyContentChannellist').innerHTML = "<h1>some unknown error</h1>" + tplPasswordSendForm;
644         }
645 }
646
647 // RemoteControl Code
648 function showRemoteControllSendForm(){
649                 document.getElementById('BodyContentChannellist').innerHTML = tplRemoteControlForm;
650 }
651 function sendRemoteControlRequest(command){
652         doRequest(url_remotecontrol+'?command='+command, incomingRemoteControlResult);
653 }
654 function incomingRemoteControlResult(request){
655         debug(request.readyState);
656         if(request.readyState == 4){
657                 var b = getXML(request).getElementsByTagName("e2remotecontrol");
658                 var result = b.item(0).getElementsByTagName('e2result').item(0).firstChild.data;
659                 var resulttext = b.item(0).getElementsByTagName('e2resulttext').item(0).firstChild.data;
660                 showRemoteControllSendForm();
661         } else {
662                 document.getElementById('BodyContentChannellist').innerHTML = "<h1>some unknown error</h1>" + tplRemoteControlForm;
663         }
664 }