* proper escape xml special chars
[enigma2-plugins.git] / webinterface / src / web-data / timer.js
1 // Versioning
2 Version = '$Header$';
3
4 // TimerEdit variables:
5 var addTimerEditFormObject = new Object();
6 addTimerEditFormObject["TVListFilled"] = 0;
7 addTimerEditFormObject["RadioListFilled"] = 0;
8 addTimerEditFormObject["deleteOldOnSave"] = 0;
9 addTimerEditFormObject["eventID"] = 0;
10 days = [];
11 days[0] = 'mo';
12 days[1] = 'tu';
13 days[2] = 'we';
14 days[3] = 'th';
15 days[4] = 'fr';
16 days[5] = 'sa';
17 days[6] = 'su';
18
19 // Timer
20 function addTimerByID(sRef,eventID,justplay){
21         if(parentPin(sRef)) {
22                 debug("addTimerByID\neventID: "+eventID);
23                 doRequest(url_timeraddbyeventid+"?sRef="+sRef+"&eventid="+eventID+"&justplay="+justplay, incomingTimerAddResult, false);        
24         }
25 }
26 function incomingTimerAddResult(request){
27         debug("onTimerAdded");
28         if(request.readyState == 4){
29                 var addresult = new SimpleXMLResult(getXML(request));
30                 if(addresult.getState()){
31                         //timer was add
32                         loadTimerList();
33                 }else{
34                         messageBox("Timer Error","your Timer could not be added!\nReason: "+addresult.getStateText());
35                 }
36         }               
37 }
38 function loadTimerList(){
39         doRequest(url_timerlist, incomingTimerList, false);     
40 }
41
42 function incomingTimerList(request){
43         if(request.readyState == 4){
44                 var timers = new TimerList(getXML(request)).getArray();
45                 debug("have "+timers.length+" timer");
46                 listerHtml      = tplTimerListHeader;
47                 var aftereventReadable = new Array ('Nothing', 'Standby', 'Deepstandby/Shutdown');
48                 var justplayReadable = new Array('record', 'zap');
49                 var OnOff = new Array('on', 'off');
50                 for ( var i = 0; i <timers.length; i++){
51                         var timer = timers[i];
52                         var beginDate = new Date(Number(timer.getTimeBegin())*1000);
53                         var endDate = new Date(Number(timer.getTimeEnd())*1000);
54                         var namespace = {       
55                                 'servicereference': timer.getServiceReference(),
56                                 'servicename': quotes2html(timer.getServiceName()),
57                                 'title': quotes2html(timer.getName()),
58                                 'description': quotes2html(timer.getDescription()),
59                                 'descriptionextended': quotes2html(timer.getDescriptionExtended()),
60                                 'begin': timer.getTimeBegin(),
61                                 'beginDate': beginDate.toLocaleString(),
62                                 'end': timer.getTimeEnd(),
63                                 'endDate': endDate.toLocaleString(),
64                                 'state': timer.getState(),
65                                 'duration': Math.ceil((timer.getDuration()/60)),
66                                 'repeated': timer.getRepeated(),
67                                 'repeatedReadable': repeatedReadable(timer.getRepeated()),
68                                 'justplay': timer.getJustplay(),
69                                 'justplayReadable': justplayReadable[Number(timer.getJustplay())],
70                                 'afterevent': timer.getAfterevent(),
71                                 'aftereventReadable': aftereventReadable[Number(timer.getAfterevent())],
72                                 'disabled': timer.getDisabled(),
73                                 'onOff': OnOff[Number(timer.getDisabled())],
74                                 'color': colorTimerListEntry( timer.getState() )
75                         };
76                         listerHtml += RND(tplTimerListItem, namespace);
77                 }
78                 listerHtml += tplTimerListFooter;
79                 $('BodyContentChannellist').innerHTML = listerHtml;
80                 setBodyMainContent('BodyContentChannellist');
81         }
82 }
83 function repeatedReadable(num) {
84         num = Number(num);
85         if(num == 0) {
86                 return "One Time";
87         }
88         
89         var html = "";
90         var Repeated = new Object();
91         Repeated["Mo-Su"] =127;
92         Repeated["Su"] =    64;
93         Repeated["Sa"] =    32;
94         Repeated["Mo-Fr"] = 31;
95         Repeated["Fr"] =    16;
96         Repeated["Th"] =     8;
97         Repeated["We"] =     4;
98         Repeated["Tu"] =     2;
99         Repeated["Mo"] =     1;
100         
101         for(rep in Repeated) {
102                 if(rep.toString() != "extend") {
103                         var check = Number(Repeated[rep]);
104                         if(check <= num) {
105                                 num -= check;
106                                 if(html == "") {
107                                         html += rep.toString();
108                                 } else {
109                                         html += "," + rep.toString();
110                                 }
111                         }
112                 }
113         }
114         return html;
115 }
116
117 function colorTimerListEntry (state) {
118         if (state == 0) {
119                 return "000000";
120         } else if(state == 1) {
121                 return "00BCBC";
122         } else if(state == 2) {
123                 return "9F1919";
124         } else {
125                 return "00BCBC";
126         }
127 }
128 function delTimer(sRef,begin,end,servicename,title,description,readyFunction){
129         debug("delTimer: sRef("+sRef+"),begin("+begin+"),end("+end+"),servicename("+servicename+"),title("+title+"),description("+description+")");
130         Dialog.confirm(
131                 "Selected timer:<br>"
132                 +"Channel: "+servicename+"<br>"
133                 +"Title: "+title+"<br>"
134                 +"Description: "+description+"<br>"
135                 +"Are you sure that you want to delete the Timer?",
136                  {windowParameters: {width:300, className: windowStyle},
137                         okLabel: "delete",
138                         buttonClass: "myButtonClass",
139                         cancel: function(win) {debug("delTimer cancel confirm panel")},
140                         ok: function(win) { 
141                                                             debug("delTimer ok confirm panel"); 
142                                                             doRequest(url_timerdelete+"?sRef="+sRef+"&begin="+begin+"&end="+end, readyFunction, false);
143                                                             return true;
144                                                           }
145                         }
146         );
147 }
148
149 function incomingTimerDelResult(request){
150         debug("onTimerDeleted");
151         if(request.readyState == 4){
152                 var delresult = new SimpleXMLResult(getXML(request));
153                 debug("Lade liste");
154                 loadTimerList();
155         }               
156 }
157 function loadTimerFormNow() {
158         var now = new Date();
159         addTimerEditFormObject["syear"] = now.getFullYear();
160         addTimerEditFormObject["smonth"] = now.getMonth() + 1;
161         addTimerEditFormObject["sday"] = now.getDate();
162         addTimerEditFormObject["shour"] = now.getHours();
163         addTimerEditFormObject["smin"] = now.getMinutes();
164
165         var     plusTwoHours = new Date(now.getTime() + ((120 *60)*1000) );
166         addTimerEditFormObject["eyear"] = plusTwoHours.getFullYear();
167         addTimerEditFormObject["emonth"] = plusTwoHours.getMonth() + 1;
168         addTimerEditFormObject["eday"] = plusTwoHours.getDate();
169         addTimerEditFormObject["ehour"] = plusTwoHours.getHours();
170         addTimerEditFormObject["emin"] = plusTwoHours.getMinutes();
171                 
172         addTimerEditFormObject["justplay"] = "record";
173         addTimerEditFormObject["channel"] = "";
174         addTimerEditFormObject["channelName"] = "";
175         addTimerEditFormObject["channelSort"] = "tv";
176         addTimerEditFormObject["name"] = "";
177         addTimerEditFormObject["description"] = "";
178         addTimerEditFormObject["repeated"] = 0;
179         addTimerEditFormObject["afterEvent"] = "0";
180         addTimerEditFormObject["deleteOldOnSave"] = 0;
181         
182         addTimerEditFormObject["beginOld"] = 0;
183         addTimerEditFormObject["endOld"] = 0;
184         
185         
186         debug("loadTimerFormNow 2");
187         loadTimerFormChannels();
188 }
189
190 function loadTimerFormSeconds(justplay,begin,end,repeated,channel,channelName,name,description,afterEvent,deleteOldOnSave,eit) {
191         debug('justplay:'+justplay+' begin:'+begin+' end:'+end+' repeated:'+repeated+' channel:'+channel+' name:'+name+' description:'+description+' afterEvent:'+afterEvent+' deleteOldOnSave:'+deleteOldOnSave);
192         var start = new Date(Number(begin)*1000);
193         addTimerEditFormObject["syear"] = start.getFullYear();
194         addTimerEditFormObject["smonth"] = start.getMonth() + 1;
195         addTimerEditFormObject["sday"] = start.getDate();
196         addTimerEditFormObject["shour"] = start.getHours();
197         addTimerEditFormObject["smin"] = start.getMinutes();
198         
199         var     stopp = new Date(Number(end)*1000);
200         addTimerEditFormObject["eyear"] = stopp.getFullYear();
201         addTimerEditFormObject["emonth"] = stopp.getMonth() + 1;
202         addTimerEditFormObject["eday"] = stopp.getDate();
203         addTimerEditFormObject["ehour"] = stopp.getHours();
204         addTimerEditFormObject["emin"] = stopp.getMinutes();
205         
206         addTimerEditFormObject["justplay"] = String(justplay);
207         addTimerEditFormObject["channel"] = decodeURIComponent(String(channel));
208         addTimerEditFormObject["channelName"] = String(channelName);
209         addTimerEditFormObject["channelSort"] = "";
210         addTimerEditFormObject["name"] = String(name);
211         addTimerEditFormObject["description"] = String(description);
212         addTimerEditFormObject["repeated"] = Number(repeated);
213         addTimerEditFormObject["afterEvent"] = Number(afterEvent);
214         
215         debug(justplay+"|"+begin+"|"+end+"|"+repeated+"|"+channel+"|"+name+"|"+description+"|"+afterEvent);
216
217         addTimerEditFormObject["deleteOldOnSave"] = Number(deleteOldOnSave);
218         addTimerEditFormObject["beginOld"] = Number(begin);
219         addTimerEditFormObject["endOld"] = Number(end);
220         
221         addTimerEditFormObject["eventID"] = Number(eit);
222         
223         loadTimerFormChannels();
224 }
225
226 // startin to load for TV
227 function loadTimerFormChannels() {
228         if(addTimerEditFormObject["TVListFilled"] == 1 && addTimerEditFormObject["RadioListFilled"] == 1) {
229                 loadTimerForm();
230         } else if(addTimerEditFormObject["TVListFilled"] == 1 && addTimerEditFormObject["RadioListFilled"] == 0) {
231                 addTimerListFormatTV();
232         } else {
233                 var favorites = '1%3A7%3A1%3A0%3A0%3A0%3A0%3A0%3A0%3A0%3AFROM%20BOUQUET%20%22userbouquet.favourites.tv%22%20ORDER%20BY%20bouquet'
234                 doRequest(url_getServices+favorites, addTimerListFormatTV, false);
235         }
236 }
237
238 function addTimerListFormatTV(request) {
239         if(addTimerEditFormObject["RadioListFilled"] == 0) {
240                 if(request.readyState == 4){
241                         var services = new ServiceList(getXML(request)).getArray();
242                         var tv = new Object();
243                         for ( var i = 0; i < services.length ; i++){
244                                 var reference = services[i];
245                                 tv[reference.servicereference] = reference.servicename;
246                         }
247                         addTimerEditFormObject["TVListFilled"] = 1;
248                         addTimerEditFormObject["TVList"] = tv;
249                 }
250         }
251         if(addTimerEditFormObject["RadioListFilled"] == 1) {
252                 loadTimerForm()
253         } else {
254                 var favorites = '1%3A7%3A1%3A0%3A0%3A0%3A0%3A0%3A0%3A0%3AFROM%20BOUQUET%20%22userbouquet.favourites.radio%22%20ORDER%20BY%20bouquet';
255                 doRequest(url_getServices+favorites, addTimerListFormatRadio, false);
256         }
257 }
258 function addTimerListFormatRadio(request) {
259         if(request.readyState == 4){
260                 var services = new ServiceList(getXML(request)).getArray();
261                 var radio = new Object();
262                 for ( var i = 0; i < services.length ; i++){
263                         var reference = services[i];
264                         radio[reference.servicereference] = reference.servicename;
265                 }
266                 addTimerEditFormObject["RadioListFilled"] = 1;
267                 addTimerEditFormObject["RadioList"] = radio;
268         }
269         loadTimerForm();
270 }
271
272 function loadTimerForm(){
273
274         var Action = new Object();
275         Action["0"] = "Record";
276         Action["1"] = "Zap";
277         
278         var Repeated = new Object();
279         Repeated["1"] =  "mo";
280         Repeated["2"] = "tu";
281         Repeated["4"] =  "we";
282         Repeated["8"] =  "th";
283         Repeated["16"] = "fr";
284         Repeated["32"] = "sa";
285         Repeated["64"] = "su";
286         Repeated["31"] = "mf";
287         Repeated["127"] ="ms";
288         
289         var AfterEvent = new Object();
290         AfterEvent["0"] = "Nothing";
291         AfterEvent["1"] = "Standby";
292         AfterEvent["2"] = "Deepstandby/Shutdown";
293         
294         addTimerEditFormObject["name"] = (typeof(addTimerEditFormObject["name"]) != "undefined") ? addTimerEditFormObject["name"] : "";
295         addTimerEditFormObject["name"] = (addTimerEditFormObject["name"] == "") ? " " : addTimerEditFormObject["name"];
296
297         addTimerEditFormObject["description"] = (typeof(addTimerEditFormObject["description"]) != "undefined") ? addTimerEditFormObject["description"] : "";
298         addTimerEditFormObject["description"] = (addTimerEditFormObject["description"] == "") ? " " : addTimerEditFormObject["description"];
299
300         var channelObject = addTimerEditFormObject["TVList"];
301         if(     addTimerEditFormObject["channelSort"] == "tv") {
302                 // already set
303         } else if( addTimerEditFormObject["channelSort"] == "radio") {
304                 channelObject = addTimerEditFormObject["RadioList"];
305         } else {
306                 var found = 0;
307                 for( element in addTimerEditFormObject["TVList"]) {
308                         if( element == addTimerEditFormObject["channel"]) {
309                                 found = 1;
310                                 break;
311                         }
312                 }
313                 if(found == 0) {
314                         for( element in addTimerEditFormObject["RadioList"]) {
315                                 if( element == addTimerEditFormObject["channel"]) {
316                                         channelObject = addTimerEditFormObject["RadioList"];
317                                         found = 1;
318                                         break;
319                                 }
320                         }
321                 }
322                 if(found == 0) {
323                         addTimerEditFormObject["TVList"][addTimerEditFormObject["channel"]] = addTimerEditFormObject["channelName"];
324                 }
325         }
326         var dashString = "------";
327         channelObject[dashString] = "- Bouquets -";
328         var listeNeu = new ServiceList(getXML(doRequestMemory[url_getServices+encodeURIComponent(bouqet_tv)])).getArray();
329         if(addTimerEditFormObject["channelSort"] == "radio") {
330                 debug("weiter");
331                 listeNeu = new ServiceList(getXML(doRequestMemory[url_getServices+encodeURIComponent(bouqet_radio)])).getArray();
332         }
333         debug("hier" + listeNeu.length);
334         for (i = 1; i < listeNeu.length; i++) {
335                 var element = listeNeu[i];
336                 channelObject[String(dashString+i)] = "---";
337                 channelObject[element.getServiceReference()] = element.getServiceName();
338         }
339         var namespace = {       
340                                 'justplay': addTimerFormCreateOptionList(Action, addTimerEditFormObject["justplay"]),
341                                 'syear': addTimerFormCreateOptions(2007,2010,addTimerEditFormObject["syear"]),
342                                 'smonth': addTimerFormCreateOptions(1,12,addTimerEditFormObject["smonth"]),
343                                 'sday': addTimerFormCreateOptions(1,31,addTimerEditFormObject["sday"]),
344                                 'shour': addTimerFormCreateOptions(0,23,addTimerEditFormObject["shour"]),
345                                 'smin': addTimerFormCreateOptions(0,59,addTimerEditFormObject["smin"]),
346                                 'eyear': addTimerFormCreateOptions(2007,2010,addTimerEditFormObject["eyear"]),
347                                 'emonth': addTimerFormCreateOptions(1,12,addTimerEditFormObject["emonth"]),
348                                 'eday': addTimerFormCreateOptions(1,31,addTimerEditFormObject["eday"]),
349                                 'ehour': addTimerFormCreateOptions(0,23,addTimerEditFormObject["ehour"]),
350                                 'emin': addTimerFormCreateOptions(0,59,addTimerEditFormObject["emin"]),
351                                 'channel': addTimerFormCreateOptionList(channelObject, addTimerEditFormObject["channel"]),
352                                 'name': addTimerEditFormObject["name"],
353                                 'description': addTimerEditFormObject["description"],
354                                 'repeated': addTimerFormCreateOptionListRepeated(Repeated, addTimerEditFormObject["repeated"]),
355                                 'deleteOldOnSave': addTimerEditFormObject["deleteOldOnSave"],
356                                 'channelOld': addTimerEditFormObject["channel"],
357                                 'beginOld': addTimerEditFormObject["beginOld"],
358                                 'endOld': addTimerEditFormObject["endOld"],
359                                 'afterEvent': addTimerFormCreateOptionList(AfterEvent, addTimerEditFormObject["afterEvent"]),
360                                 'eventID': addTimerEditFormObject["eventID"]
361                 };
362         var listerHtml = RND(tplAddTimerForm, namespace);
363         $('BodyContentChannellist').innerHTML = listerHtml;
364
365         // Empty some stuff, but keep others to have the performance
366         var tmp1 = addTimerEditFormObject["RadioList"];
367         var tmp2 = addTimerEditFormObject["TVList"];
368         addTimerEditFormObject = new Object();
369         addTimerEditFormObject["deleteOldOnSave"] = 0;
370         addTimerEditFormObject["RadioList"] = tmp1;
371         addTimerEditFormObject["TVList"] = tmp2;
372         addTimerEditFormObject["TVListFilled"] = 1;
373         addTimerEditFormObject["RadioListFilled"] = 1;
374 }
375
376 function addTimerFormCreateOptions(start,end,number) {
377         var html = '';
378         for(i = start; i <= end; i++) {
379                 var txt = (String(i).length == 1) ? "0" + String(i) : String(i);
380                 var selected =  (i == Number(number)) ? "selected" : " ";
381                 var namespace = {
382                         'value': i,
383                         'txt': txt,
384                         'selected': selected };
385                 html += RND(tplAddTimerFormOptions, namespace);
386         }
387         return html;
388 }
389 function addTimerFormCreateOptionList(object,selected) {
390         html = '';
391         var found = 0;
392         for(var element in object) {
393                 var txt = String(object[element]);
394                 var sel = " ";
395                 if(element == selected) {
396                         found = 1;
397                         sel = "selected";
398                 }
399                 var namespace = {
400                         'value': element,
401                         'txt': txt,
402                         'selected': sel };
403                 if(element != "extend") {
404                         html += RND(tplAddTimerFormOptions, namespace);
405                 }
406         }
407         if(found == 0) {
408                 var namespace = {
409                         'value': element,
410                         'txt': txt,
411                         'selected': sel };
412         }
413         return html;
414 }
415
416 function timerFormExtendChannellist(bouqet) {
417         var listeTV = new ServiceList(getXML(doRequestMemory[url_getServices+encodeURIComponent(bouqet_tv)])).getArray();
418         var listeRadio = new ServiceList(getXML(doRequestMemory[url_getServices+encodeURIComponent(bouqet_radio)])).getArray();
419         found = 0;
420         for(i = 0; i < listeTV.length; i++) {
421                 var element = listeTV[i];
422                 if(String(element.getServiceReference()) == bouqet) {
423                         found = 1;
424                         break;
425                 }
426         }
427         if(found == 0) {
428                 for(i = 0; i < listeRadio.length; i++) {
429                         var element = listeTV[i];
430                         if(String(element.getServiceReference()) == bouqet) {
431                                 found = 1;
432                                 break;
433                         }
434                 }
435         }
436         if(found == 1) {
437                 servicereftoloadepgnow = bouqet;
438                 if(typeof(loadedChannellist[servicereftoloadepgnow]) == "undefined") {  
439                         doRequest(url_getServices+servicereftoloadepgnow, incomingTimerFormExtendChannellist, true);
440                 } else {
441                         incomingTimerFormExtendChannellist();
442                 }
443         }
444 }
445 function incomingTimerFormExtendChannellist(request) {
446         var services = null;
447         if(typeof(loadedChannellist[servicereftoloadepgnow]) != "undefined"){
448                 services = loadedChannellist[servicereftoloadepgnow];
449         } else if(request.readyState == 4) {
450                 services = new ServiceList(getXML(request)).getArray();
451                 loadedChannellist[servicereftoloadepgnow] = services;
452                 debug("got "+services.length+" Services");
453         }
454         var attachLater = new Object();
455         if(services != null) {
456                 debug("incomingTimerFormExtendChannellist " + services.length);
457                 var selected = $('channel').selectedIndex;
458                 for(j = selected; j < $('channel').options.length; j++) {
459                         if($('channel').options[j].value == servicereftoloadepgnow) {
460                                 j++;
461                                 for(var i = 0; i < services.length ; i++) {
462                                         var reference = services[i];
463                                         var newEntry = new Option(reference.getServiceName(), reference.getServiceReference(), false, true);
464                                         if(typeof($('channel').options[j]) != "undefined") {
465                                                 attachLater[String($('channel').options[j].value)] = $('channel').options[j].text;
466                                         }
467                                         $('channel').options[j] = newEntry;
468                                         j++;
469                                 }
470                         }
471                         break;
472                 }
473                 for(x in attachLater) {
474                         var newEntry = new Option(attachLater[x], x, false, true);
475                         if(x != "extend") {
476                                 $('channel').options[$('channel').options.length] = newEntry;
477                         }
478                 }
479                 $('channel').options[selected].selected = true;
480                 
481         }
482 }
483
484 function addTimerFormChangeTime(which) {
485         var start = new Date( $('syear').value, ($('smonth').value -1), $('sday').value, $('shour').value, $('smin').value, 0);
486         var end = new Date($('eyear').value, ($('emonth').value -1), $('eday').value, $('ehour').value, $('emin').value, 0);
487 //      debug("("+start+")(" + end+")");
488
489         if(start.getTime() > end.getTime()) {
490                 opponent = (which.substr(0,1) == 's') ? 'e' +  which.substr(1, which.length -1) : 's' +  which.substr(1, which.length -1) ;
491                 $(opponent).value = $(which).value;
492         }
493         var all = new Array('year','month','day','hour','min');
494         for(i=0; i < all.length; i++) {
495                 if(which.substr(1, which.length -1) == all[i]) {
496                         addTimerFormChangeTime(which.substr(0,1) + all[i+1] );
497                         break;
498                 }
499         }
500 }
501 function addTimerFormChangeType() {
502         var selected = ($('tvradio').checked == true) ? addTimerEditFormObject["TVList"]: addTimerEditFormObject["RadioList"];
503         for (i = $('channel').options.length; i != 0; i--) {
504                 $('channel').options[i - 1] = null;
505         }
506         var i = -1;
507         for(element in selected) {
508                 if(element != "extend") {
509                         i++;
510                         $('channel').options[i] = new Option(selected[element]);
511                         $('channel').options[i].value = element;
512                 }
513         }
514 }
515 function addTimerFormCreateOptionListRepeated(Repeated,repeated) {
516         var num = Number(repeated);
517         var html = "";
518         var html2 = "";
519         var list = new Array(127, 64, 32, 31, 16, 8, 4, 2, 1);
520         for(i = 0; i < list.length; i++) {
521                 var txt = String(Repeated[String(list[i])]);
522                 if( String(Repeated[String(list[i])]) == "mf") {
523                         txt = "Mo-Fr";
524                 } else if( String(Repeated[String(list[i])]) == "ms") {
525                         txt = "Mo-Su";
526                 } else {
527                         txt = txt.substr(0,1).toUpperCase() + txt.substr(1,1);
528                 }
529                 var checked = " ";
530                 if(num >=  list[i]) {
531                         num -= list[i];
532                         checked = "checked";
533                 }
534                 var namespace = {
535                         'id': Repeated[String(list[i])],
536                         'name': Repeated[String(list[i])],
537                         'value': list[i],
538                         'txt': txt,
539                         'checked': checked };
540                 if(String(Repeated[String(list[i])]) == "mf" || String(Repeated[String(list[i])]) == "ms") {
541                         html2 = RND(tplAddTimerFormCheckbox, namespace) + html2;
542                 } else {
543                         html = RND(tplAddTimerFormCheckbox, namespace) + html;
544                 }
545         }
546         return html + html2;
547 }
548 function sendAddTimer() {
549         debug("sendAddTimer" + "parentChannel:" +$('channel').value);
550         
551         if(parentPin($('channel').value)) {
552                 var beginD = new Date(ownLazyNumber($('syear').value), (ownLazyNumber($('smonth').value) - 1), ownLazyNumber($('sday').value), ownLazyNumber($('shour').value), ownLazyNumber($('smin').value));
553                 var begin = beginD.getTime()/1000;
554                 
555                 var endD = new Date(ownLazyNumber($('eyear').value), (ownLazyNumber($('emonth').value) - 1), ownLazyNumber($('eday').value), ownLazyNumber($('ehour').value), ownLazyNumber($('emin').value));
556                 var end = endD.getTime()/1000;
557
558                 var repeated = 0;
559                 if( $('ms').checked ) {
560                         repeated = 127;
561                 } else if($('mf').checked) {
562                         repeated = 31;
563                         if($('sa').checked) {
564                                 repeated += ownLazyNumber($('sa').value);
565                         }
566                         if($('su').checked) {
567                                 repeated += ownLazyNumber($('su').value);
568                         }
569                 } else {
570                         var check = new Array('mo', 'tu', 'we', 'th', 'fr');
571                         for(i = 0; i < check.length; i++) {
572                                 if($(check[i]).checked) {
573                                         repeated += Number($(check[i]).value);
574                                 }
575                         }
576                 }
577         
578                 var descriptionClean = ($('descr').value == " " || $('descr').value == "N/A") ? "" : $('descr').value;
579                 var nameClean = ($('name').value == " " || $('name').value == "N/A") ? "" : $('name').value;
580         
581                 var repeated = 0;
582                 if($('ms').checked) {
583                         repeated = ownLazyNumber($('ms').value);
584                 } else if($('mf').checked) {
585                         repeated = ownLazyNumber($('mf').value);
586                         if($('su').checked) {
587                                 repeated += ownLazyNumber($('su').value);
588                         }
589                         if($('sa').checked) {
590                                 repeated += ownLazyNumber($('sa').value);
591                         }
592                 } else {
593                         for(i = 0; i < days.length; i++){
594                                 if($(days[i]).checked) {
595                                         repeated += ownLazyNumber($(days[i]).value);
596                                 }
597                         }
598                 }
599                 //addTimerByID(\'%(servicereference)\',\'%(eventid)\',\'False\');
600                 doRequest(url_timerchange+"?"+"sRef="+($('channel').value).replace("&quot;", '"')+"&begin="+begin
601                   +"&end="+end+"&name="+escape(nameClean)+"&description="+escape(descriptionClean)
602                   +"&afterevent="+$('after_event').value+"&eit=0&disabled=0"
603                   +"&justplay="+ownLazyNumber($('justplay').value)+"&repeated="+repeated
604                   +"&channelOld="+$('channelOld').value
605                   +"&beginOld="+$('beginOld').value+"&endOld="+$('endOld').value
606                   +"&eventID"+$('eventID').value
607                   +"&deleteOldOnSave="+ownLazyNumber($('deleteOldOnSave').value), incomingTimerAddResult, false);
608         }
609 }
610
611 function cleanTimerListNow(){
612         debug("cleanTimerListNow pushed");
613         doRequest(url_timerlist, incomingCleanTimerListNow, false);     
614 }
615 function incomingCleanTimerListNow(request) {
616         if(request.readyState == 4){
617                 var timers = new TimerList(getXML(request)).getArray();
618                 debug("have "+timers.length+" timer");
619                 for ( var i = 0; i <timers.length; i++){
620                         var timer = timers[i];
621                         debug(timer.getState() + " " + quotes2html(timer.getName()));
622                         if(timer.getState() != 0) {
623                                 delTimer(timer.getServiceReference(),timer.getTimeBegin(),timer.getTimeEnd()
624                                         ,quotes2html(timer.getServiceName()),quotes2html(timer.getName()),quotes2html(timer.getDescription()),incomingJustDoNothing);
625                         }
626                 }
627         }
628 }
629 function incomingJustDoNothing(request){
630         debug("just do nothing");
631 }