// JavaScript Document
/*****************************************************************

  Hummingbird Software, Pasadena, California, USA
  www.hummingbird-software.com

  Validate Client Fields from Entry Form

  March 16, 2007

  Javascript routine to validate fields for potential client.

*****************************************************************/

//
// Is char an uppercase letter?
//
function isLetter( ch )
{
  return( ch >= "A" && ch <= "Z" ) ;
}

function checkInput()
{
   var bGood = true ;

   if ( document.clientform.firstname.value.length == 0 )
   {
      window.alert( "Please enter FIRST NAME" ) ;
      document.clientform.firstname.focus() ;
      bGood = false ;
   }
   else
   if ( document.clientform.lastname.value.length == 0 )
   {
      window.alert( "Please enter LAST NAME" ) ;
      document.clientform.lastname.focus() ;
      bGood = false ;
   }
   else
  if ( document.clientform.homephone.value.length == 0 )
   {
      window.alert( "Please enter HOME PHONE NUMBER" ) ;
      document.clientform.homephone.focus() ;
      bGood = false ;
   }
   else
   if ( document.clientform.workphone.value.length == 0 )
   {
      window.alert( "Please enter WORK PHONE NUMBER" ) ;
      document.clientform.workphone.focus() ;
      bGood = false ;
   }
   else
   if ( document.clientform.cellphone.value.length == 0 )
   {
      window.alert( "Please enter CELL PHONE NUMBER" ) ;
      document.clientform.cellphone.focus() ;
      bGood = false ;
   }
   else
   if ( document.clientform.email.value.length == 0 )
   {
      window.alert( "Please enter EMAIL ADDRESS" ) ;
      document.clientform.email.focus() ;
      bGood = false ;
   }
   else
   if ( document.clientform.hasinvestment.value.length == 0 )
   {
      window.alert( "Please select YES or NO for the INVESTMENT" ) ;
      document.clientform.hasinvestment.focus() ;
      bGood = false ;
   }

//
// At this point, all required fields are non-blank.
// Do more detailed validations.
//

//
// Zip Code (if entered)
//
   if ( bGood == true && document.clientform.zip.value.length > 0 )
   if ( !checkZip( document.clientform.zip.value ) )
   {
      window.alert( "Please enter a VALID ZIP CODE" ) ;
      document.clientform.zip.focus() ;
      bGood = false ;
   }

//
// Home Phone Number
//
   if ( bGood == true )
   {
//
// Is phone number in 1113334444 format?
//
      phone = formatPhone( document.clientform.homephone.value ) ;
      if ( checkPhone( phone ) == true )
         document.clientform.homephone.value = phone ;
      else
//
// If not, then is phone number still valid (has 10 digits)?
//
      if ( checkPhone( document.clientform.homephone.value ) == false )
      {
         window.alert( "Please enter HOME PHONE NUMBER with AREA CODE" ) ;
         document.clientform.homephone.focus() ;
         bGood = false ;
      }
   }

//
// Work Phone Number
//
   if ( bGood == true )
   {
//
// Is phone number in 1113334444 format?
//
      phone = formatPhone( document.clientform.workphone.value ) ;
      if ( checkPhone( phone ) == true )
         document.clientform.workphone.value = phone ;
      else
//
// If not, then is phone number still valid (has 10 digits)?
//
      if ( checkPhone( document.clientform.workphone.value ) == false )
      {
         window.alert( "Please enter WORK PHONE NUMBER with AREA CODE" ) ;
         document.clientform.workphone.focus() ;
         bGood = false ;
      }
   }

//
// Work Fax Phone Number (if entered)
//
   if ( bGood == true && document.clientform.workfax.value.length > 0 )
   {
//
// Is phone number in 1113334444 format?
//
      phone = formatPhone( document.clientform.workfax.value ) ;
      if ( checkPhone( phone ) == true )
         document.clientform.workfax.value = phone ;
      else
//
// If not, then is phone number still valid (has 10 digits)?
//
      if ( checkPhone( document.clientform.workfax.value ) == false )
      {
         window.alert( "Please enter WORK FAX PHONE NUMBER with AREA CODE" ) ;
         document.clientform.workfax.focus() ;
         bGood = false ;
      }
   }

//
// Cell Phone Number
//
   if ( bGood == true )
   {
//
// Is phone number in 1113334444 format?
//
      phone = formatPhone( document.clientform.cellphone.value ) ;
      if ( checkPhone( phone ) == true )
         document.clientform.cellphone.value = phone ;
      else
//
// If not, then is phone number still valid (has 10 digits)?
//
      if ( checkPhone( document.clientform.cellphone.value ) == false )
      {
         window.alert( "Please enter CELL PHONE NUMBER with AREA CODE" ) ;
         document.clientform.cellphone.focus() ;
         bGood = false ;
      }
   }

//
// Email Address 
//
   if ( bGood == true )
	if ( document.clientform.email.value.length > 0 )
   {
      if ( checkEmail( document.clientform.email.value ) == false )
      {
         window.alert( "Please enter a VALID EMAIL ADDRESS" ) ;
         document.clientform.email.focus() ;
         bGood = false ;
      }
   }

   return ( bGood ) ;
}
