home *** CD-ROM | disk | FTP | other *** search
/ Minami 85 / MINAMI85.iso / Extra / vlc-0.8.6b-win32.exe / http / js / vlm.js < prev   
Text File  |  2007-04-24  |  31KB  |  756 lines

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