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