    /**************************************************
     *****            Field Routines              *****
     **************************************************/

    // show_token_input - displays the token form for entering a token; this
    // takes the JavaScript event e.
    function show_token_input(e) {
      var token_value = '';
      var token = document.getElementById("token_input");
      if (token) {
        token_value = token.value;
      }

      // Build and display the token form.
      html = '<p>'
           + '  <form id="token_form" action="#">'
           + '    <p>Token: '
           + '    <input id="token_input" type="text" size="19" value="xxxx-xxxx-xxxx-xxxx"'
           + token_value
           + '"/>'
           + '    <span id="token_button" class="button">look up</span></p>'
           + '  </form>'
           + '</p>'
	   + '<p><br><br><b><i>Step 1</b></i><br>'
	   + '   Input the token number<br>'
	   + '<br><b><i>Step 2</b></i><br>'
 	   + '    Activate your token<br>'
	   + '<br><b><i>Step 3</b></i><br>' 
	   +'    Add users (can be done before activation as well)<br>' 
	   + '<br><b><i>Step 4</b></i><br>' 
	   + '   Submit jobs with elevated priority!</p>';
      
	document.getElementById('token_field').innerHTML = html;

      // Set event handlers for token form.
      YAHOO.util.Event.addListener('token_form', 'submit', get_token);
      YAHOO.util.Event.addListener('token_button', 'click', get_token);

}

    function show_user_input(e) {
      html = '<p>'
           + '  <form id="user_form" action="#">'
           + '    <p>'
           + '      Email:<br/>'
           + '      <input id="email" type="text" size="25" value="user@domain.name"/><br/>'
           + '      Identity:<br/>'
           + '      <textarea id="identity" rows="3" cols="25">If TeraGrid user, input your DN</textarea>'
           + '    </p>'
           + '    <p>'
           + '      <span id="user_button" class="button">look up</span>'
           + '    </p>'
           + '  </form>'
           + '</p>'
	   + '<p><br><br><b><i>Step 1</b></i><br>'
           + '   Input your email address and identity<br>'
           + '<br><b><i>Step 2</b></i><br>'
           + '    Display shows all pertaining token times and resources if any<br>'
           + '<br><b><i>Step 3</b></i><br>'
	   + '	If token is active, submit jobs with elevated priority!</p>';
 
      document.getElementById('token_field').innerHTML = html;

      // Set event handlers for user form.
      YAHOO.util.Event.addListener('user_form', 'submit', get_user);
      YAHOO.util.Event.addListener('user_button', 'click', get_user);
    }

    // show_token_string - displays the token string and a hidden field
    // containing the token string; this takes the token string token_value.
    function show_token_string(token_value) {
      // Build and display the token string.
      //var html = '<p id="token_text">Token: ' 
        //       + token_value
          //     + '<input type="hidden" id="token_input" value="'
            //   + token_value
              // + '"/>'
               var html = '<p><br><span class="orange"> Fetching information..</span></p>'

      document.getElementById('error_field').innerHTML = html;
      // Add an event listener to display the token form if this string
      // is clicked.
    //  YAHOO.util.Event.addListener('token_text', "click", show_token_input);
    }

    function show_user_string(email, identity) {
      var html = '<p id="user_text">Information for user with<br/>'
               + '  Email: ' + email + '<br/>'
               + '  Identity: ' + identity + '<br/>'
               + '<br><span class="orange"> Fetching User information..</p>'
               + '<input type="hidden" id="email" value="'
               + email
               + '"/>'
               + '<input type="hidden" id="identity" value="'
               + identity
               + '"/>';
      document.getElementById('token_field').innerHTML = html;

//      YAHOO.util.Event.addListener('user_text', 'click', show_user_input);
    }

    // show_comment_form - displays the comment field when activating a
    // token.
    function show_comment_form() {
      // Build and display the form.
      var html = '<p>'
               + '  <form id="comment_form" action="#">'
               + '    <p>'
               + '      Comment:<br/>'
               + '      <textarea id="comment" rows="3" cols="25"></textarea>'
               + '    </p>'
               + '    <p>'
               + '      <span id="activate_activate_button" class="button">activate</span> '
               + '      <span id="activate_cancel_button" class="button">go back</span> '
               + '    </p>'
               + '  </form>'
               + '</p>';

      document.getElementById('announce_field').innerHTML = html;
      
      // Update event listener for 'activate' button to activate the token
      // (instead of showing this form). We also add a listender to the
      // form, but I'm not sure that this can be ever triggered.
      YAHOO.util.Event.removeListener('activate_button', 'click', 
                                      show_comment_form);
      YAHOO.util.Event.addListener('add_button', 'click', activate_token);
      YAHOO.util.Event.addListener('activate_activate_button', 'click', 
                                   activate_token);
      YAHOO.util.Event.addListener('activate_cancel_button', 'click', 
                                   cancel_activate);
      YAHOO.util.Event.addListener('comment_form', 'submit', activate_token);
    }
    
    // show_user_form - displays the user form in the announce field; this
    // takes the token string token_value.
    function show_user_form(token_value) {
      // Build and display the form.
      var html = '<p>'
           + '  <form id="user_form" action="#">'
           + '    <p>'
           + '    Real name: <br/>'
           + '    <input id="real_name" type="text" size="25" value=""/><br/>'
           + '    E\-mail: <br/>'
           + '    <input id="email" type="text" size="25" value=""/><br/>'
           + '    Identity: <br/>'
           + '    <textarea id="identity" rows="3" cols="25"></textarea><br/>'
           + '    </p>'
           + '    <p>'
           + '    <span id="add_add_button" class="button">add</span> '
           + '    <span id="add_cancel_button" class="button">cancel</span> '
           + '    </p>'
           + '  </form>'
           + '</p>';
      document.getElementById('announce_field').innerHTML = html;

      // Update event listener for 'add user' button to add the user
      // (instead of showing this form). We also add a listender to the
      // form, but I'm not sure that this can be ever triggered.
      //YAHOO.util.Event.removeListener('add_button', 'click', show_user_form);
      //YAHOO.util.Event.addListener('add_button', 'click', add_user);
      YAHOO.util.Event.addListener('add_add_button', 'click', add_user);
      YAHOO.util.Event.addListener('add_cancel_button', 'click', cancel_user);
      YAHOO.util.Event.addListener('user_form', 'submit', add_user);
    }


   //show_reserv_form - displays the user settings area here
     function show_reserv_form(token_value) {
	var html = '<p>'
	 	+ ' <form id="reserv_form" action="#">'
		+ '  <p>'
		+ ' Resource Name:<br/>'
		+ ' <input id="res1" type="text" size="25" value="bluedawg.loni.org"/><br/>'
		+ ' Procs:<br/>'
		+ ' <input id="nodes1" type="text" size="5" value="8"/><br/>'
		+ ' Start time:<br/>'
		+ ' <input id="start" type="text" size="20" value="2007-12-15T13:00"/><br/>'
		+ ' Duration:<br/>'
		+ ' <input id="duration" type="text" size="20" value="1:00"/><br/>'
		+ ' </p>'
		+ ' <p>'
		+ ' <span id="reserv_submit_button" class="button">submit</span> '
		+ ' <span id="reserv_cancel_button" class="button">cancel</span>'
		+ ' </p>'
		+ ' </form>'
		+ '</p>';
	document.getElementById('announce_field').innerHTML = html;

	// Update event listener for 'make reservation' button to make reserv 
        // (instead of showing this form). We also add a listener to the
        // form, but I'm not sure that this can be ever triggered.
	
     // YAHOO.util.Event.removeListener('reservation', 'click', show_reserv_form);
     // YAHOO.util.Event.addListener('reservation', 'click', add_reserv);
      YAHOO.util.Event.addListener('reserv_submit_button', 'click', add_reserv);
      YAHOO.util.Event.addListener('reserv_cancel_button', 'click', cancel_reserv);
      YAHOO.util.Event.addListener('reserv_form', 'submit', add_reserv);
}

	
    // show_user_alert - display a confirmation window; remove the user if
    // they select 'OK'. I'm using a very hackish way to pass the id of the
    // hidden input containing the user id to remove.
    function show_user_alert(e) {
      if (confirm('Are you sure you want to remove the user ?')) {
        remove_user(this.id+'_identity');
      }
    }

    // display_error - sets the error field; takes a JSON spruceFault
    // with code, msg, and desc members.
    // removing the code to display in the error, unnecessary information
    // + '  <span class="error_code">' + fault.code + '</span>: '

    function display_error(fault) {
      var html 
         
          = '<fieldset class="error"> '
          + '  <legend>Error</legend> '
          + '  <span class="error_msg">' + fault.msg + '</span><br/> '
          + '  <p class="error_desc">' + fault.desc + '</p> '
          + '</fieldset>';

      document.getElementById("error_field").innerHTML = html;
      clear('info_field');
    }

    // clear - clears the HTML from an element; takes the element's ID.
    function clear(id) {
      document.getElementById(id).innerHTML = '';
    }

