]> git.sesse.net Git - vlc/blob - share/http/js/vlm.js
8a985f87a0013d5e1a4fc7e7ba0ebe0ca013f560
[vlc] / share / http / js / vlm.js
1 /*****************************************************************************
2  * vlm.js: VLC media player web interface
3  *****************************************************************************
4  * Copyright (C) 2005-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /* replace quotes and spaces by underscores */
25 function addunderscores( str ){ return str.replace(/\'|\"| /g, '_'); }
26
27 /**********************************************************************
28  * Input dialog functions
29  *********************************************************************/
30
31 function vlm_input_edit( dest )
32 {
33     document.getElementById( 'input_dest' ).value = dest;
34     show( 'input' );
35 }
36
37 function vlm_input_change()
38 {
39     document.getElementById( value( 'input_dest' ) ).value = value( 'input_mrl' ).replace( /\ :/g, " option " );
40     hide( 'input' );
41     document.getElementById( value( 'input_dest' ) ).focus();
42 }
43
44 function vlm_output_edit( dest )
45 {
46     document.getElementById( 'sout_dest' ).value = dest;
47     show( 'sout' );
48 }
49
50 function vlm_output_change()
51 {
52     document.getElementById( value( 'sout_dest' ) ).value = value( 'sout_mrl' ).substr(6).replace( /\ :/g, " option " ); /* substr <-> remove :sout= */
53     hide( 'sout' );
54     document.getElementById( value( 'sout_dest' ) ).focus();
55 }
56
57 function hide_vlm_add()
58 {
59     document.getElementById( 'vlm_add_broadcast' ).style.display = 'none';
60     document.getElementById( 'vlm_add_vod' ).style.display = 'none';
61     document.getElementById( 'vlm_add_schedule' ).style.display = 'none';
62     document.getElementById( 'vlm_add_other' ).style.display = 'none';
63 }
64
65 function toggle_schedule_date()
66 {
67     if( checked( 'vlm_schedule_now' ) )
68     {
69         disable( 'vlm_schedule_year' );
70         disable( 'vlm_schedule_month' );
71         disable( 'vlm_schedule_day' );
72         disable( 'vlm_schedule_hour' );
73         disable( 'vlm_schedule_minute' );
74         disable( 'vlm_schedule_second' );
75     }
76     else
77     {
78         enable( 'vlm_schedule_year' );
79         enable( 'vlm_schedule_month' );
80         enable( 'vlm_schedule_day' );
81         enable( 'vlm_schedule_hour' );
82         enable( 'vlm_schedule_minute' );
83         enable( 'vlm_schedule_second' );
84     }
85 }
86
87 function toggle_schedule_repeat()
88 {
89     if( checked( 'vlm_schedule_repeat' ) )
90     {
91         enable( 'vlm_schedule_period_year' );
92         enable( 'vlm_schedule_period_month' );
93         enable( 'vlm_schedule_period_day' );
94         enable( 'vlm_schedule_period_hour' );
95         enable( 'vlm_schedule_period_minute' );
96         enable( 'vlm_schedule_period_second' );
97         enable( 'vlm_schedule_repeat_times' );
98     }
99     else
100     {
101         disable( 'vlm_schedule_period_year' );
102         disable( 'vlm_schedule_period_month' );
103         disable( 'vlm_schedule_period_day' );
104         disable( 'vlm_schedule_period_hour' );
105         disable( 'vlm_schedule_period_minute' );
106         disable( 'vlm_schedule_period_second' );
107         disable( 'vlm_schedule_repeat_times' );
108     }
109 }
110
111 function vlm_schedule_type_change( name )
112 {
113     var act = document.getElementById( 'vlm_elt_' + name + '_action' ).value;
114     var itemname = document.getElementById( 'vlm_elt_' + name + '_name' );
115     var opt = document.getElementById( 'vlm_elt_' + name + '_opt' );
116     if( act == "play" || act == "pause" || act == "stop" )
117     {
118         itemname.style.display = "";
119         opt.style.display = "none";
120     }
121     else if( act == "seek" )
122     {
123         itemname.style.display = "";
124         opt.style.display = "";
125     }
126     else
127     {
128         itemname.style.display = "none";
129         opt.style.display = "";
130     }
131 }
132
133 function update_vlm_add_broadcast()
134 {
135     var cmd = document.getElementById( 'vlm_command' );
136
137     if( value( 'vlm_broadcast_name' ) )
138     {
139         cmd.value = "new " + addunderscores( value( 'vlm_broadcast_name' ) )
140                     + " broadcast";
141
142         if( checked( 'vlm_broadcast_enabled' ) )
143         {
144             cmd.value += " enabled";
145         }
146         
147         if( checked( 'vlm_broadcast_loop' ) )
148         {
149             cmd.value += " loop";
150         }
151
152         if( value( 'vlm_broadcast_input' ) )
153         {
154             cmd.value += " input " + value( 'vlm_broadcast_input' );
155         }
156
157         if( value( 'vlm_broadcast_output' ) )
158         {
159             cmd.value += " output " + value( 'vlm_broadcast_output' );
160         }
161     }
162     else
163     {
164         cmd.value = "";
165     }
166 }
167
168 function update_vlm_add_vod()
169 {
170     var cmd = document.getElementById( 'vlm_command' );
171
172     if( value( 'vlm_vod_name' ) )
173     {
174         cmd.value = "new " + addunderscores( value( 'vlm_vod_name' ) )
175                     + " vod";
176
177         if( checked( 'vlm_vod_enabled' ) )
178         {
179             cmd.value += " enabled";
180         }
181         
182         if( value( 'vlm_vod_input' ) )
183         {
184             cmd.value += " input " + value( 'vlm_vod_input' );
185         }
186
187         if( value( 'vlm_vod_output' ) )
188         {
189             cmd.value += " output " + value( 'vlm_vod_output' );
190         }
191     }
192     else
193     {
194         cmd.value = "";
195     }
196 }
197
198 function update_vlm_add_schedule()
199 {
200     var cmd = document.getElementById( 'vlm_command' );
201
202     check_and_replace_int( 'vlm_schedule_year', '0000' );
203     check_and_replace_int( 'vlm_schedule_month', '00' );
204     check_and_replace_int( 'vlm_schedule_day', '00' );
205     check_and_replace_int( 'vlm_schedule_hour', '00' );
206     check_and_replace_int( 'vlm_schedule_minute', '00' );
207     check_and_replace_int( 'vlm_schedule_second', '00' );
208     check_and_replace_int( 'vlm_schedule_period_year', '0000' );
209     check_and_replace_int( 'vlm_schedule_period_month', '00' );
210     check_and_replace_int( 'vlm_schedule_period_day', '00' );
211     check_and_replace_int( 'vlm_schedule_period_hour', '00' );
212     check_and_replace_int( 'vlm_schedule_period_minute', '00' );
213     check_and_replace_int( 'vlm_schedule_period_second', '00' );
214
215     if( value( 'vlm_schedule_name' ) )
216     {
217         cmd.value = "new " + addunderscores( value( 'vlm_schedule_name' ) ) + " schedule";
218
219         if( checked( 'vlm_schedule_enabled' ) )
220         {
221             cmd.value += " enabled";
222         }
223
224         if( checked( 'vlm_schedule_now' ) )
225         {
226             cmd.value += " date now";
227         }
228         else
229         {
230             cmd.value += " date " + value( 'vlm_schedule_year' ) + "/" + value( 'vlm_schedule_month' ) + "/" + value( 'vlm_schedule_day' ) + '-' + value( 'vlm_schedule_hour' ) + ':' + value( 'vlm_schedule_minute' ) + ':' + value( 'vlm_schedule_second' );
231         }
232
233         if( checked( 'vlm_schedule_repeat' ) )
234         {
235             cmd.value += " period " + value( 'vlm_schedule_period_year' ) + "/" + value( 'vlm_schedule_period_month' ) + "/" + value( 'vlm_schedule_period_day' ) + '-' + value( 'vlm_schedule_period_hour' ) + ':' + value( 'vlm_schedule_period_minute' ) + ':' + value( 'vlm_schedule_period_second' );
236
237             if( value( 'vlm_schedule_repeat_times' ) != 0 )
238             {
239                 cmd.value += " repeat " + (value( 'vlm_schedule_repeat_times' ) - 1 );
240             }
241         }
242             
243     }
244     else
245     {
246         cmd.value = "";
247     }
248 }
249
250 function update_vlm_add_other()
251 {
252     var cmd = document.getElementById( 'vlm_command' );
253     cmd.value = "";
254 }
255
256 function clear_vlm_add()
257 {
258     document.getElementById( 'vlm_command' ).value = "";
259     document.getElementById( 'vlm_broadcast_name' ).value = "";
260     document.getElementById( 'vlm_vod_name' ).value = "";
261 }
262
263 function create_button( caption, action )
264 {
265 /*    var link = document.createElement( "input" );
266     link.setAttribute( 'type', 'button' );*/
267     /* link.setAttribute( 'onclick', action ); */
268     /* Above doesn't work on ie. You need to use something like
269      * link.onclick = function() { alert( 'pouet' ); };
270      * instead ... conclusion: IE is crap */
271    /* link.setAttribute( 'value', caption );*/
272
273     var d = document.createElement( 'div' );
274     d.innerHTML = "<input type='button' onclick='"+action+"' value='"+caption+"' />"; /* other IE work around  ... still crap. Use double quotes only in action */
275     var link = d.firstChild;
276     return link;
277 }
278 function create_option( caption, value )
279 {
280     var opt = document.createElement( 'option' );
281     opt.setAttribute( 'value', value );
282     opt.appendChild( document.createTextNode( caption ) );
283     return opt;
284 }
285
286 function parse_vlm_cmd()
287 {
288     if( req.readyState == 4 )
289     {
290         if( req.status == 200 )
291         {
292             var vlm_answer = req.responseXML.documentElement;
293             var error_tag = vlm_answer.getElementsByTagName( 'error' )[0];
294             var vlme = document.getElementById( 'vlm_error' );
295             clear_children( vlme );
296             if( error_tag.hasChildNodes() )
297             {
298                 vlme.appendChild( document.createTextNode( 'Error: ' + error_tag.firstChild.data ) );
299                 vlme.style.color = "#f00";
300             }
301             else
302             {
303                 vlme.appendChild( document.createTextNode( 'Command succesful (' + value( 'vlm_command' ) + ') ' ) );
304                 vlme.style.color = "#0f0";
305                 clear_vlm_add();
306             }
307             vlme.appendChild( create_button( 'clear', 'clear_children( document.getElementById( "vlm_error" ) );' ) );
308
309             vlm_get_elements();
310         }
311     }
312 }
313
314 function parse_vlm_elements()
315 {
316     if( req.readyState == 4 )
317     {
318         if( req.status == 200 )
319         {
320             var vlmb = document.getElementById( 'vlm_broadcast_list' );
321             var vlmv = document.getElementById( 'vlm_vod_list' );
322             var vlms = document.getElementById( 'vlm_schedule_list' );
323
324             clear_children( vlmb );
325             clear_children( vlmv );
326             clear_children( vlms );
327
328             answer = req.responseXML.documentElement;
329
330             var elt = answer.firstChild;
331
332             while( elt )
333             {
334                 if( elt.nodeName == "broadcast" || elt.nodeName == "vod" )
335                 {
336                     var nb = document.createElement( 'div' );
337                     setclass( nb, 'list_element' );
338                     if( elt.nodeName == "broadcast" )
339                     {
340                         vlmb.appendChild( nb );
341                     }
342                     else
343                     {
344                         vlmv.appendChild( nb );
345                     }
346                     var nbname = document.createElement( 'b' );
347                     nbname.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
348                     nb.appendChild( nbname );
349                     
350                     if( elt.getAttribute( 'enabled' ) == 'yes' )
351                     {
352                         nb.appendChild( document.createTextNode( " enabled " ) );
353                         nb.appendChild( create_button( "Disable", 'vlm_disable("'+elt.getAttribute( 'name' ) + '");' ) );
354                     }
355                     else
356                     {
357                         nb.appendChild( document.createTextNode( " disabled " ) );
358                         nb.appendChild( create_button( "Enable", 'vlm_enable("'+elt.getAttribute( 'name' ) + '");' ) );
359                     }
360                     
361                     if( elt.nodeName == "broadcast" )
362                     {
363                         if( elt.getAttribute( 'loop' ) == 'yes' )
364                         {
365                             nb.appendChild( document.createTextNode( " loop " ) );
366
367                             nb.appendChild( create_button( 'Un-loop', 'vlm_unloop("'+elt.getAttribute( 'name' ) + '");' ) );
368                         }
369                         else
370                         {
371                             nb.appendChild( document.createTextNode( " play once " ) );
372                             nb.appendChild( create_button( 'Loop', 'vlm_loop("'+elt.getAttribute( 'name' ) + '");' ) );
373                             
374                         }
375
376                         if( elt.getAttribute( 'enabled' ) == 'yes' )
377                         {
378                             nb.appendChild( document.createTextNode( " " ) );
379                             nb.appendChild( create_button( 'Play', 'vlm_play("'+elt.getAttribute('name')+'");' ) );
380                         }
381
382                         nb.appendChild( document.createTextNode( " " ) );
383                         nb.appendChild( create_button( 'Pause', 'vlm_pause("'+elt.getAttribute('name')+'");' ) );
384
385                         nb.appendChild( document.createTextNode( " " ) );
386                         nb.appendChild( create_button( 'Stop', 'vlm_stop("'+elt.getAttribute('name')+'");' ) );
387                     }
388                     
389                     nb.appendChild( document.createTextNode( " " ) );
390                     nb.appendChild( create_button( 'Delete', 'vlm_delete("'+elt.getAttribute( 'name' ) + '");' ) );
391
392                     var list = document.createElement( "ul" );
393
394                     /* begin input list */
395                     var item = document.createElement( "li" );
396                     list.appendChild( item );
397                     item.appendChild( document.createTextNode( "Inputs: " ) );
398                     var text = document.createElement( "input" );
399                     text.setAttribute( 'type', 'text' );
400                     text.setAttribute( 'size', '40' );
401                     text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_input' );
402                     text.setAttribute( 'onkeypress', 'if( event.keyCode == 13 ) vlm_add_input("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_input").value );' );
403                     item.appendChild( text );
404                     item.appendChild( document.createTextNode( ' ' ) );
405                     item.appendChild( create_button( 'Edit', 'vlm_input_edit("vlm_elt_'+elt.getAttribute('name')+'_input");') );
406                     item.appendChild( document.createTextNode( ' ' ) );
407                     item.appendChild( create_button( 'Add input', 'vlm_add_input("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_input").value );' ) );
408                     
409                     var inputs = elt.getElementsByTagName( 'input' );
410                     if( inputs.length > 0 )
411                     {
412                         var ilist = document.createElement( "ol" );
413                         ilist.setAttribute( 'start', '1' );
414                         item.appendChild( ilist );
415                         for( i = 0; i < inputs.length; i++ )
416                         {
417                             var item = document.createElement( "li" );
418                             item.appendChild( document.createTextNode( inputs[i].firstChild.data + " " ) );
419                             item.appendChild( create_button( "Delete", 'vlm_delete_input("' + elt.getAttribute( 'name' ) + '", '+(i+1)+' );' ) );
420                             ilist.appendChild( item );
421                         }
422                     }
423                     /* end of input list */
424                     
425                     /* output */
426                     var item = document.createElement( "li" );
427                     outputelt = elt.getElementsByTagName( 'output' )[0];
428                     if( outputelt.hasChildNodes() )
429                     {
430                         output = outputelt.firstChild.data;
431                     }
432                     else
433                     {
434                         output = "";
435                     }
436                     item.appendChild( document.createTextNode( 'Output: ' ) );
437                     var text = document.createElement( "input" );
438                     text.setAttribute( 'type', 'text' );
439                     text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_output' );
440                     text.setAttribute( 'value', output );
441                     text.setAttribute( 'onkeypress', 'if( event.keyCode == 13 )  vlm_output("'+elt.getAttribute( 'name' )+ '",document.getElementById("vlm_elt_'+elt.getAttribute( 'name' )+'_output").value);' );
442                     item.appendChild( text );
443
444                     item.appendChild( document.createTextNode( ' ' ) );
445
446                     item.appendChild( create_button( 'Edit', 'vlm_output_edit("vlm_elt_'+elt.getAttribute('name')+'_output");' ) );
447                     item.appendChild( document.createTextNode( ' ' ) );
448                     item.appendChild( create_button( 'Change output', 'vlm_output("'+elt.getAttribute( 'name' )+ '",document.getElementById("vlm_elt_'+elt.getAttribute( 'name' )+'_output").value);' ) );
449                     list.appendChild( item );
450                     /* end of output */
451
452                     /* begin options list */
453                     var item = document.createElement( "li" );
454                     list.appendChild( item );
455                     item.appendChild( document.createTextNode( "Options: " ) );
456                     /* Add option */
457                     var text = document.createElement( "input" );
458                     text.setAttribute( 'type', 'text' );
459                     text.setAttribute( 'size', '40' );
460                     text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_option' );
461                     text.setAttribute( 'onkeypress', 'if( event.keyCode == 13 ) vlm_option("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_option").value );' );
462                     item.appendChild( text );
463                     item.appendChild( document.createTextNode( ' ' ) );
464                     item.appendChild( create_button( 'Add option', 'vlm_option("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_option").value );' ) );
465                     
466                     var options = elt.getElementsByTagName( 'option' );
467                     if( options.length > 0 )
468                     {
469                         var olist = document.createElement( "ul" );
470                         item.appendChild( olist );
471                         for( i = 0; i < options.length; i++ )
472                         {
473                             var item = document.createElement( "li" );
474                             item.appendChild( document.createTextNode( options[i].firstChild.data ) );
475                             olist.appendChild( item );
476                         }
477                     }
478                     /* end of options */
479
480                     /* Instances list */
481                     var instances = elt.getElementsByTagName( 'instance' );
482                     if( instances.length > 0 )
483                     {
484                         var item = document.createElement("li");
485                         var ilist = document.createElement("ul");
486                         list.appendChild( item );
487                         item.appendChild(document.createTextNode("Instances:")); 
488                         item.appendChild( ilist );
489                         for( i = 0; i < instances.length; i++ )
490                         {
491                             var iname = instances[i].getAttribute( 'name' );
492                             var istate = instances[i].getAttribute( 'state' );
493                             var iposition = Number( instances[i].getAttribute( 'position' ) * 100);
494                             var itime = Math.floor( instances[i].getAttribute( 'time' ) / 1000000);
495                             var ilength = Math.floor( instances[i].getAttribute( 'length' ) / 1000000);
496                             var irate = instances[i].getAttribute( 'rate' );
497                             var ititle = instances[i].getAttribute( 'title' );
498                             var ichapter = instances[i].getAttribute( 'chapter' );
499                             var iseekable = instances[i].getAttribute( 'seekable' );
500                             var iplaylistindex = instances[i].getAttribute( 'playlistindex' );
501                             
502                             var item = document.createElement( "li" );
503                             item.appendChild( document.createTextNode( iname + ": " + istate + " (" + iplaylistindex + ") " + (iposition.toFixed(2)) + "%" + " " + format_time( itime ) + "/" + format_time( ilength ) ) );
504                             ilist.appendChild( item );
505                         }
506                     }
507                     /* end of instances list */
508                     
509                     nb.appendChild( list );
510                     
511                 }
512                 else if( elt.nodeName == "schedule" )
513                 {
514                     var nb = document.createElement( 'div' );
515                     setclass( nb, 'list_element' );
516                     vlms.appendChild( nb );
517
518                     var nbname = document.createElement( 'b' );
519                     nbname.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
520                     nb.appendChild( nbname );
521                     
522                     if( elt.getAttribute( 'enabled' ) == 'yes' )
523                     {
524                         nb.appendChild( document.createTextNode( " enabled " ) );
525                         nb.appendChild( create_button( "Disable", 'vlm_disable("'+elt.getAttribute( 'name' ) + '");' ) );
526                     }
527                     else
528                     {
529                         nb.appendChild( document.createTextNode( " disabled " ) );
530                         nb.appendChild( create_button( "Enable", 'vlm_enable("'+elt.getAttribute( 'name' ) + '");' ) );
531                     }
532
533                     nb.appendChild( document.createTextNode( " " ) );
534                     nb.appendChild( create_button( "Delete", 'vlm_delete("'+elt.getAttribute( 'name' ) + '");' ) );
535
536                     var list = document.createElement( 'ul' );
537
538                     var item = document.createElement( 'li' );
539                     item.appendChild( document.createTextNode( "Date: " + elt.getAttribute( 'date' ) ) );
540                     list.appendChild( item );
541
542                     var item = document.createElement( 'li' );
543                     item.appendChild( document.createTextNode( "Period (in seconds): " + elt.getAttribute( 'period' ) ) );
544                     list.appendChild( item );
545                     
546                     var item = document.createElement( 'li' );
547                     if( elt.getAttribute( 'repeat' ) == -1 )
548                     {
549                         item.appendChild( document.createTextNode( "Number of repeats left: for ever" ) );
550                     }
551                     else
552                     {
553                         item.appendChild( document.createTextNode( "Number of repeats left: " + elt.getAttribute( 'repeat' ) ) );
554                     }
555                     list.appendChild( item );
556                     
557                     var commands = elt.getElementsByTagName( 'command' );
558                     for( i = 0; i < commands.length; i++ )
559                     {
560                         var item = document.createElement( "li" );
561                         item.appendChild( document.createTextNode( "Command: " + commands[i].firstChild.data + " " ) );
562                         list.appendChild( item );
563                     }
564                     
565                     var item = document.createElement( 'li' );
566                     var sel = document.createElement( 'select' );
567                     sel.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_action' );
568                     sel.setAttribute( 'onchange', 'vlm_schedule_type_change("'+elt.getAttribute('name')+'");');
569                     sel.appendChild( create_option( 'play', 'play' ) );
570                     sel.appendChild( create_option( 'pause', 'pause' ) );
571                     sel.appendChild( create_option( 'stop', 'stop' ) );
572                     sel.appendChild( create_option( 'seek', 'seek' ) );
573                     sel.appendChild( create_option( '(other)', '' ) );
574                     item.appendChild( sel );
575
576                     item.appendChild( document.createTextNode( " " ) );
577                     var text = document.createElement( 'input' );
578                     text.setAttribute( 'type', 'text' );
579                     text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_name' );
580                     text.setAttribute( 'size', '10' );
581                     text.setAttribute( 'value', '(name)' );
582                     text.setAttribute( 'onfocus', 'if( this.value == "(name)" ) this.value = "";' );
583                     text.setAttribute( 'onblur', 'if( this.value == "" ) this.value = "(name)";' );
584                     item.appendChild( text );
585
586                     item.appendChild( document.createTextNode( " " ) );
587                     text = document.createElement( 'input' );
588                     text.setAttribute( 'type', 'text' );
589                     text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_opt' );
590                     text.setAttribute( 'size', '30' );
591                     text.setAttribute( 'value', '(options)' );
592                     text.setAttribute( 'onfocus', 'if( this.value == "(options)" ) this.value = "";' );
593                     text.setAttribute( 'onblur', 'if( this.value == "" ) this.value = "(options)";' );
594                     item.appendChild( text );
595                     item.appendChild( document.createTextNode( " " ) );
596                     item.appendChild( create_button( "Append command", 'vlm_schedule_append("' + elt.getAttribute( 'name' ) + '");') );
597                     
598                     list.appendChild( item );
599
600                     nb.appendChild( list );
601                     vlm_schedule_type_change( elt.getAttribute('name') );
602                     
603                 }
604                 elt = elt.nextSibling;
605             }
606         }
607     }
608 }
609
610 function vlm_cmd( cmd )
611 {
612     loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_vlm_cmd );
613 }
614
615 function vlm_get_elements( )
616 {
617     loadXMLDoc( 'requests/vlm.xml', parse_vlm_elements );
618 }
619
620 /* helper functions */
621
622 function vlm_disable( name )
623 {
624     document.getElementById( 'vlm_command' ).value = "setup "+name+" disabled";
625     vlm_cmd( value( 'vlm_command' ) );
626 }
627
628 function vlm_enable( name )
629 {
630     document.getElementById( 'vlm_command' ).value = "setup "+name+" enabled";
631     vlm_cmd( value( 'vlm_command' ) );
632 }
633
634 function vlm_loop( name )
635 {
636     document.getElementById( 'vlm_command' ).value = "setup "+name+" loop";
637     vlm_cmd( value( 'vlm_command' ) );
638 }
639
640 function vlm_unloop( name )
641 {
642     document.getElementById( 'vlm_command' ).value = "setup "+name+" unloop";
643     vlm_cmd( value( 'vlm_command' ) );
644 }
645
646 function vlm_play( name )
647 {
648     document.getElementById( 'vlm_command' ).value = "control "+name+" play";
649     vlm_cmd( value( 'vlm_command' ) );
650 }
651
652 function vlm_pause( name )
653 {
654     document.getElementById( 'vlm_command' ).value = "control "+name+" pause";
655     vlm_cmd( value( 'vlm_command' ) );
656 }
657
658 function vlm_stop( name )
659 {
660     document.getElementById( 'vlm_command' ).value = "control "+name+" stop";
661     vlm_cmd( value( 'vlm_command' ) );
662 }
663
664 function vlm_delete( name )
665 {
666     document.getElementById( 'vlm_command' ).value = "del "+name;
667     vlm_cmd( value( 'vlm_command' ) );
668 }
669
670 function vlm_delete_input( name, num )
671 {
672     document.getElementById( 'vlm_command' ).value = "setup "+name+" inputdeln "+num;
673     vlm_cmd( value( 'vlm_command' ) );
674 }
675
676 function vlm_add_input( name, input )
677 {
678     document.getElementById( 'vlm_command' ).value = "setup "+name+" input "+input;
679     vlm_cmd( value( 'vlm_command' ) );
680 }
681
682 function vlm_output( name, output )
683 {
684     document.getElementById( 'vlm_command' ).value = "setup "+name+" output "+output;
685     vlm_cmd( value( 'vlm_command' ) );
686 }
687
688 function vlm_option( name, option )
689 {
690     document.getElementById( 'vlm_command' ).value = "setup "+name+" option "+option;
691     vlm_cmd( value( 'vlm_command' ) );
692 }
693
694 function vlm_batch( batch )
695 {
696     var i;
697     var commands = batch.split( '\n' );
698     for( i = 0; i < commands.length; i++ )
699     {
700         document.getElementById( 'vlm_command' ).value = commands[i];
701         vlm_cmd( value( 'vlm_command' ) );
702     }
703 }
704
705 function vlm_schedule_append( name )
706 {
707     var act = document.getElementById( 'vlm_elt_' + name + '_action' ).value;
708     document.getElementById( 'vlm_command' ).value = "setup " + name + " append ";
709
710     var itemname = document.getElementById( 'vlm_elt_' + name + '_name' ).value;
711     if( itemname == "(name)" ) itemname = "";
712
713     var opt = document.getElementById( 'vlm_elt_' + name + '_opt' ).value;
714     if( opt == "(options)" ) opt = "";
715         
716     if( act == '' )
717     {
718         document.getElementById( 'vlm_command' ).value += opt;
719     }
720     else
721     {
722         document.getElementById( 'vlm_command' ).value += 'control ' + itemname + " " + act + " " + opt;
723     }
724     vlm_cmd( value( 'vlm_command' ) );
725 }
726 function vlm_send( )
727 {
728     vlm_cmd( value( 'vlm_command' ) );
729 }