// CLIENT JS:  favorite_form.js
//
// PURPOSE  :  This file contains client-side JavaScripts that perform 
//             field validations on the "Tell Us About Your Favorite 
//             Book" Form page.
//
///////////////////////////////////////////////////////////////////////////////

// Index to fields (elements) on the identification form to be validated.
var TITLE       =  1;   // Book Title input box
var AUTHOR      =  2;   // Book Author input box
var COMMENTS    =  3;   // Why you Favorite Comment input box
var NAME        =  4;   // Reader's First Name input box
var AGE         =  5;   // Reader's Age input box
var CONTINUEBTN =  6;   // Submit Button

// Initialize minimum field length (element) array
var nFieldLengthArray         = new Array();
nFieldLengthArray[ TITLE ]    = 0;
nFieldLengthArray[ AUTHOR ]   = 0;
nFieldLengthArray[ COMMENTS ] = 0;
nFieldLengthArray[ NAME ]     = 1;
nFieldLengthArray[ AGE ]      = 1;

// Initialize field message array
var strMsgArray         = new Array();
strMsgArray[ TITLE ]     = "";
strMsgArray[ AUTHOR ]    = "";
strMsgArray[ COMMENTS ]  = "";
strMsgArray[ NAME ]      = "We need to know who you are.  Please tell us your first name.";
strMsgArray[ AGE ]       = "We need to know how old you are.  Please tell us your age.";


//********************************************************************
//  function:    isValidName
//  description: 
//  input:
//               nFieldNo  number of field to validate
//               inputVal  value to validate
//  return:  
//               true  - if value checked is valid 
//               false - if value is not valid
//********************************************************************
function isValidName( nFieldNo, inputVal ) {
 
  var valid = false;

  if ( !isValidLength( nFieldNo, inputVal ) ) { return false; }
  if ( isBlank( nFieldNo, inputVal ) ) { return false; }

  return true;
}

//********************************************************************
//  function:    doSubmit
//  description: 
//  input:
//               form  form to validate
//  return:  
//               true  - if value checked is valid 
//               false - if value is not valid
//********************************************************************
function doSubmit( form ) {
  var success = false;

  // success = isValidLength( NAME, form.name ); 

  success = isValidName( NAME, form.name );
  if ( success ) { success = isValidNumber( AGE, form.age ); }
  if ( success ) { success = isValidLength( COMMENTS, form.comments ); }
  return success;
}


