// Functions for Javascript page processing

// Focus on this input when loaded
function initedit()
{
  document.getElementById( 'first_edit' ).focus();
  return;
}


// Update a given ID with a given value
function update_val( id, v )
{
  ch = document.getElementById( id );
  ch.innerHTML = v;
}


// Set Insert Point
function set_entry( ths )
{
  ths.focus();
}

// Validate Input Provided for an input field and
//    send alert text if not provided
// Caution: Does Not Check correctness of input
function validate_required( field, alerttxt )
{
  with (field)
  {
    if ( value == null || value == "" )
    {
      alert( alerttxt );
      return false;
    }
    else
    {
      return true;
    }
  }
}

// Announce Valid Input Required for two semi-required (one or the other) inputs
function validate_semi_required( field1, field2, alerttxt )
{
  var failed = false;

  with ( field1 )
  {
    if ( value != null && value != "" )
    {
      return true;
    }
  }
  with ( field2 )
  {
    if ( value != null && value != "" )
    {
      return true;
    }
  }
  alert( alerttxt );
  return false;
}


// Validate the AddQuestion form
function validate_question( thisform )
{
  with ( thisform )
  {
    if ( validate_required( quest, "Question Text Required!" ) == false )
    {
      quest.focus();
      return false;
    }
  }
  return true;
}


// Validate the AddReviewer form
function validate_reviewer( thisform )
{
  with ( thisform )
  {
    if ( validate_required( FName, "First Name Required!" ) == false )
    {
      FName.focus();
      return false;
    }
    if ( validate_required( LName, "Last Name Required!" ) == false )
    {
      LName.focus();
      return false;
    }
  }
  return true;
}


// Validate the Login form
function validate_login( thisform, uid, pwd )
{
  with ( thisform )
  {
    if ( validate_required( username, "User Name Required!" ) == false )
    {
      username.focus();
      return false;
    }
    if ( validate_required( password, "Password Required!" ) == false )
    {
      password.focus();
      return false;
    }
    if ( username == uid && password == pwd )
    {
      return true;
    }
    else
    {
      alert( "Invalid User Name/Password Combination" );
      return false;
    }
  }
}

