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