Added functionality to wap-page timerlist aswell as a new page for powerstate
[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                 $('BodyContentChannellist').innerHTML = listerHtml;
79                 setBodyMainContent('BodyContentChannellist');
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();
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         debug("hier" + listeNeu.length);
333         for (i = 1; i < listeNeu.length; i++) {
334                 var element = listeNeu[i];
335                 channelObject[String(dashString+i)] = "---";
336                 channelObject[element.getServiceReference()] = element.getServiceName();
337         }
338         var namespace = {       
339                                 'justplay': addTimerFormCreateOptionList(Action, addTimerEditFormObject["justplay"]),
340                                 'syear': addTimerFormCreateOptions(2007,2010,addTimerEditFormObject["syear"]),
341                                 'smonth': addTimerFormCreateOptions(1,12,addTimerEditFormObject["smonth"]),
342                                 'sday': addTimerFormCreateOptions(1,31,addTimerEditFormObject["sday"]),
343                                 'shour': addTimerFormCreateOptions(0,23,addTimerEditFormObject["shour"]),
344                                 'smin': addTimerFormCreateOptions(0,59,addTimerEditFormObject["smin"]),
345                                 'eyear': addTimerFormCreateOptions(2007,2010,addTimerEditFormObject["eyear"]),
346                                 'emonth': addTimerFormCreateOptions(1,12,addTimerEditFormObject["emonth"]),
347                                 'eday': addTimerFormCreateOptions(1,31,addTimerEditFormObject["eday"]),
348                                 'ehour': addTimerFormCreateOptions(0,23,addTimerEditFormObject["ehour"]),
349                                 'emin': addTimerFormCreateOptions(0,59,addTimerEditFormObject["emin"]),
350                                 'channel': addTimerFormCreateOptionList(channelObject, addTimerEditFormObject["channel"]),
351                                 'name': addTimerEditFormObject["name"],
352                                 'description': addTimerEditFormObject["description"],
353                                 'repeated': addTimerFormCreateOptionListRepeated(Repeated, addTimerEditFormObject["repeated"]),
354                                 'deleteOldOnSave': addTimerEditFormObject["deleteOldOnSave"],
355                                 'channelOld': addTimerEditFormObject["channel"],
356                                 'beginOld': addTimerEditFormObject["beginOld"],
357                                 'endOld': addTimerEditFormObject["endOld"],
358                                 'afterEvent': addTimerFormCreateOptionList(AfterEvent, addTimerEditFormObject["afterEvent"]),
359                                 'eventID': addTimerEditFormObject["eventID"]
360                 };
361         var listerHtml = RND(tplAddTimerForm, namespace);
362         $('BodyContentChannellist').innerHTML = listerHtml;
363
364         // Empty some stuff, but keep others to have the performance
365         var tmp1 = addTimerEditFormObject["RadioList"];
366         var tmp2 = addTimerEditFormObject["TVList"];
367         addTimerEditFormObject = new Object();
368         addTimerEditFormObject["deleteOldOnSave"] = 0;
369         addTimerEditFormObject["RadioList"] = tmp1;
370         addTimerEditFormObject["TVList"] = tmp2;
371         addTimerEditFormObject["TVListFilled"] = 1;
372         addTimerEditFormObject["RadioListFilled"] = 1;
373 }
374
375 function addTimerFormCreateOptions(start,end,number) {
376         var html = '';
377         for(i = start; i <= end; i++) {
378                 var txt = (String(i).length == 1) ? "0" + String(i) : String(i);
379                 var selected =  (i == Number(number)) ? "selected" : " ";
380                 var namespace = {
381                         'value': i,
382                         'txt': txt,
383                         'selected': selected };
384                 html += RND(tplAddTimerFormOptions, namespace);
385         }
386         return html;
387 }
388 function addTimerFormCreateOptionList(object,selected) {
389         html = '';
390         var found = 0;
391         for(var element in object) {
392                 var txt = String(object[element]);
393                 var sel = " ";
394                 if(element == selected) {
395                         found = 1;
396                         sel = "selected";
397                 }
398                 var namespace = {
399                         'value': element,
400                         'txt': txt,
401                         'selected': sel };
402                 if(element != "extend") {
403                         html += RND(tplAddTimerFormOptions, namespace);
404                 }
405         }
406         if(found == 0) {
407                 var namespace = {
408                         'value': element,
409                         'txt': txt,
410                         'selected': sel };
411         }
412         return html;
413 }
414
415 function timerFormExtendChannellist(bouqet) {
416         var listeTV = new ServiceList(getXML(doRequestMemory[url_getServices+encodeURIComponent(bouqet_tv)])).getArray();
417         var listeRadio = new ServiceList(getXML(doRequestMemory[url_getServices+encodeURIComponent(bouqet_radio)])).getArray();
418         found = 0;
419         for(i = 0; i < listeTV.length; i++) {
420                 var element = listeTV[i];
421                 if(String(element.getServiceReference()) == bouqet) {
422                         found = 1;
423                         break;
424                 }
425         }
426         if(found == 0) {
427                 for(i = 0; i < listeRadio.length; i++) {
428                         var element = listeTV[i];
429                         if(String(element.getServiceReference()) == bouqet) {
430                                 found = 1;
431                                 break;
432                         }
433                 }
434         }
435         if(found == 1) {
436                 servicereftoloadepgnow = bouqet;
437                 if(typeof(loadedChannellist[servicereftoloadepgnow]) == "undefined") {  
438                         doRequest(url_getServices+servicereftoloadepgnow, incomingTimerFormExtendChannellist, true);
439                 } else {
440                         incomingTimerFormExtendChannellist();
441                 }
442         }
443 }
444 function incomingTimerFormExtendChannellist(request) {
445         var services = null;
446         if(typeof(loadedChannellist[servicereftoloadepgnow]) != "undefined"){
447                 services = loadedChannellist[servicereftoloadepgnow];
448         } else if(request.readyState == 4) {
449                 services = new ServiceList(getXML(request)).getArray();
450                 loadedChannellist[servicereftoloadepgnow] = services;
451                 debug("got "+services.length+" Services");
452         }
453         var attachLater = new Object();
454         if(services != null) {
455                 debug("incomingTimerFormExtendChannellist " + services.length);
456                 var selected = $('channel').selectedIndex;
457                 for(j = selected; j < $('channel').options.length; j++) {
458                         if($('channel').options[j].value == servicereftoloadepgnow) {
459                                 j++;
460                                 for(var i = 0; i < services.length ; i++) {
461                                         var reference = services[i];
462                                         var newEntry = new Option(reference.getServiceName(), reference.getServiceReference(), false, true);
463                                         if(typeof($('channel').options[j]) != "undefined") {
464                                                 attachLater[String($('channel').options[j].value)] = $('channel').options[j].text;
465                                         }
466                                         $('channel').options[j] = newEntry;
467                                         j++;
468                                 }
469                         }
470                         break;
471                 }
472                 for(x in attachLater) {
473                         var newEntry = new Option(attachLater[x], x, false, true);
474                         if(x != "extend") {
475                                 $('channel').options[$('channel').options.length] = newEntry;
476                         }
477                 }
478                 $('channel').options[selected].selected = true;
479                 
480         }
481 }
482
483 function addTimerFormChangeTime(which) {
484         var start = new Date( $('syear').value, ($('smonth').value -1), $('sday').value, $('shour').value, $('smin').value, 0);
485         var end = new Date($('eyear').value, ($('emonth').value -1), $('eday').value, $('ehour').value, $('emin').value, 0);
486 //      debug("("+start+")(" + end+")");
487
488         if(start.getTime() > end.getTime()) {
489                 opponent = (which.substr(0,1) == 's') ? 'e' +  which.substr(1, which.length -1) : 's' +  which.substr(1, which.length -1) ;
490                 $(opponent).value = $(which).value;
491         }
492         var all = new Array('year','month','day','hour','min');
493         for(i=0; i < all.length; i++) {
494                 if(which.substr(1, which.length -1) == all[i]) {
495                         addTimerFormChangeTime(which.substr(0,1) + all[i+1] );
496                         break;
497                 }
498         }
499 }
500 function addTimerFormChangeType() {
501         var selected = ($('tvradio').checked == true) ? addTimerEditFormObject["TVList"]: addTimerEditFormObject["RadioList"];
502         for (i = $('channel').options.length; i != 0; i--) {
503                 $('channel').options[i - 1] = null;
504         }
505         var i = -1;
506         for(element in selected) {
507                 if(element != "extend") {
508                         i++;
509                         $('channel').options[i] = new Option(selected[element]);
510                         $('channel').options[i].value = element;
511                 }
512         }
513 }
514 function addTimerFormCreateOptionListRepeated(Repeated,repeated) {
515         var num = Number(repeated);
516         var html = "";
517         var html2 = "";
518         var list = new Array(127, 64, 32, 31, 16, 8, 4, 2, 1);
519         for(i = 0; i < list.length; i++) {
520                 var txt = String(Repeated[String(list[i])]);
521                 if( String(Repeated[String(list[i])]) == "mf") {
522                         txt = "Mo-Fr";
523                 } else if( String(Repeated[String(list[i])]) == "ms") {
524                         txt = "Mo-Su";
525                 } else {
526                         txt = txt.substr(0,1).toUpperCase() + txt.substr(1,1);
527                 }
528                 var checked = " ";
529                 if(num >=  list[i]) {
530                         num -= list[i];
531                         checked = "checked";
532                 }
533                 var namespace = {
534                         'id': Repeated[String(list[i])],
535                         'name': Repeated[String(list[i])],
536                         'value': list[i],
537                         'txt': txt,
538                         'checked': checked };
539                 if(String(Repeated[String(list[i])]) == "mf" || String(Repeated[String(list[i])]) == "ms") {
540                         html2 = RND(tplAddTimerFormCheckbox, namespace) + html2;
541                 } else {
542                         html = RND(tplAddTimerFormCheckbox, namespace) + html;
543                 }
544         }
545         return html + html2;
546 }
547 function sendAddTimer() {
548         debug("sendAddTimer" + "parentChannel:" +$('channel').value);
549         
550         if(parentPin($('channel').value)) {
551                 var beginD = new Date(ownLazyNumber($('syear').value), (ownLazyNumber($('smonth').value) - 1), ownLazyNumber($('sday').value), ownLazyNumber($('shour').value), ownLazyNumber($('smin').value));
552                 var begin = beginD.getTime()/1000;
553                 
554                 var endD = new Date(ownLazyNumber($('eyear').value), (ownLazyNumber($('emonth').value) - 1), ownLazyNumber($('eday').value), ownLazyNumber($('ehour').value), ownLazyNumber($('emin').value));
555                 var end = endD.getTime()/1000;
556
557                 var repeated = 0;
558                 if( $('ms').checked ) {
559                         repeated = 127;
560                 } else if($('mf').checked) {
561                         repeated = 31;
562                         if($('sa').checked) {
563                                 repeated += ownLazyNumber($('sa').value);
564                         }
565                         if($('su').checked) {
566                                 repeated += ownLazyNumber($('su').value);
567                         }
568                 } else {
569                         var check = new Array('mo', 'tu', 'we', 'th', 'fr');
570                         for(i = 0; i < check.length; i++) {
571                                 if($(check[i]).checked) {
572                                         repeated += Number($(check[i]).value);
573                                 }
574                         }
575                 }
576         
577                 var descriptionClean = ($('descr').value == " " || $('descr').value == "N/A") ? "" : $('descr').value;
578                 var nameClean = ($('name').value == " " || $('name').value == "N/A") ? "" : $('name').value;
579                 
580                 var neverString = "[0-9a-zA-Z\-_\.\!\(\)&=\+$,;\?/:\\\ ]*";
581                 if(descriptionClean != descriptionClean.match(neverString) ||
582                         nameClean != nameClean.match(neverString)) {
583                         alert("Please only use "+neverString+" in the name and the description field");
584                         return;
585                 }
586
587                 var repeated = 0;
588                 if($('ms').checked) {
589                         repeated = ownLazyNumber($('ms').value);
590                 } else if($('mf').checked) {
591                         repeated = ownLazyNumber($('mf').value);
592                         if($('su').checked) {
593                                 repeated += ownLazyNumber($('su').value);
594                         }
595                         if($('sa').checked) {
596                                 repeated += ownLazyNumber($('sa').value);
597                         }
598                 } else {
599                         for(i = 0; i < days.length; i++){
600                                 if($(days[i]).checked) {
601                                         repeated += ownLazyNumber($(days[i]).value);
602                                 }
603                         }
604                 }
605                 //addTimerByID(\'%(servicereference)\',\'%(eventid)\',\'False\');
606                 doRequest(url_timerchange+"?"+"sRef="+($('channel').value).replace("&quot;", '"')+"&begin="+begin
607                   +"&end="+end+"&name="+escape(nameClean)+"&description="+escape(descriptionClean)
608                   +"&afterevent="+$('after_event').value+"&eit=0&disabled=0"
609                   +"&justplay="+ownLazyNumber($('justplay').value)+"&repeated="+repeated
610                   +"&channelOld="+$('channelOld').value
611                   +"&beginOld="+$('beginOld').value+"&endOld="+$('endOld').value
612                   +"&eventID"+$('eventID').value
613                   +"&deleteOldOnSave="+ownLazyNumber($('deleteOldOnSave').value), incomingTimerAddResult, false);
614         }
615 }
616
617 function cleanTimerListNow(){
618         debug("cleanTimerListNow pushed");
619         doRequest(url_timerlist, incomingCleanTimerListNow, false);     
620 }
621 function incomingCleanTimerListNow(request) {
622         if(request.readyState == 4){
623                 var timers = new TimerList(getXML(request)).getArray();
624                 debug("have "+timers.length+" timer");
625                 for ( var i = 0; i <timers.length; i++){
626                         var timer = timers[i];
627                         debug(timer.getState() + " " + quotes2html(timer.getName()));
628                         if(timer.getState() != 0) {
629                                 delTimer(timer.getServiceReference(),timer.getTimeBegin(),timer.getTimeEnd()
630                                         ,quotes2html(timer.getServiceName()),quotes2html(timer.getName()),quotes2html(timer.getDescription()),incomingJustDoNothing);
631                         }
632                 }
633         }
634 }
635 function incomingJustDoNothing(request){
636         debug("just do nothing");
637 }
638 function sendToggleTimerDisable(justplay,begin,end,repeated,channel,name,description,afterEvent,disabled){
639         disabled = (ownLazyNumber(disabled) == 0) ? 1 : 0;
640         
641         var descriptionClean = (description == " " || description == "N/A") ? "" : description;
642         var nameClean = (name == " " || name == "N/A") ? "" : name;
643
644         doRequest(url_timerchange+"?"+"sRef="+channel.replace("&quot;", '"')+"&begin="+begin
645          +"&end="+end+"&name="+escape(nameClean)+"&description="+escape(descriptionClean)
646          +"&afterevent="+afterEvent+"&eit=0&disabled="+disabled
647          +"&justplay="+justplay+"&repeated="+repeated
648          +"&channelOld="+channel
649          +"&beginOld="+begin+"&endOld="+end
650          +"&deleteOldOnSave=1", incomingTimerAddResult, false);
651 }