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