function hasAddress(strUse, fldLine1, fldLine2, fldLine3, fldCity, fldState, fldPostalCode, fldCountry) {

  if (isWhitespace(fldLine1.value)||isRepeat(fldLine1.value)) {
   alert ('please enter your '+strUse+' Address');
   fldLine1.focus();
   return false;
  }

  var tmp = trim(fldLine1.value).split(' ');
  
  if (tmp.length < 2) {
   alert ('please enter your '+strUse+' Address');
   fldLine1.focus();
   return false;
  }

  if (isWhitespace(fldCity.value)||isRepeat(fldCity.value)) {
   alert ('please enter your '+strUse+' City');
   fldCity.focus();
   return false;
  }
  
  if (!checkSelect(fldState)) {
   alert ('Please select your '+strUse+' state');
   fldState.focus();
   return false;
  }

  if (isWhitespace(fldPostalCode.value)||isRepeat(fldPostalCode.value)) {
   alert ('please enter your '+strUse+' Postal Code');
   fldPostalCode.focus();
   return false;
  }

  if (!checkSelect(fldCountry)) {
   alert ('Please select your '+strUse+' Country');
   fldCountry.focus()
   return false;
  }

  return true;
}
//
//
function hasComm (strUse, fldTelephone,fldTelephoneExtension,fldFax,fldEmail) {
  if (isWhitespace(fldTelephone.value)) {
    alert('Invalid '+strUse+' Telephone Number');
    fldTelephone.focus();
    return false;
  }

 var normalizedPhone = stripCharsInBag(fldTelephone.value, phoneNumberDelimiters);
  if(!isInteger(normalizedPhone) || isRepeat(normalizedPhone) || normalizedPhone.length < 7 ) {
   alert ('Invalid '+strUse+' Telephone Number');
    fldTelephone.focus();
   return false;
  }

  if (fldTelephoneExtension) {
    if (!isWhitespace(fldTelephoneExtension.value)) {
       normalizedPhone = stripCharsInBag(fldTelephoneExtension.value, phoneNumberDelimiters);
       if(!isInteger(normalizedPhone) || isRepeat(normalizedPhone)) {
         alert('Invalid '+strUse+' Telephone Extension Number');
         fldTelephoneExtension.focus();
         return false;
       }
    }
  }

  if (!isWhitespace(fldFax.value)) {
    normalizedPhone = stripCharsInBag(fldFax.value, phoneNumberDelimiters);
    if (!isInteger(normalizedPhone)||isRepeat(normalizedPhone)|| normalizedPhone.length < 7 ) {
      alert('Invalid '+strUse+' Fax Number');
      fldFax.focus();
      return false;
    }
    
  }
  
  if (!checkEmail(fldEmail)) {
   fldEmail.focus();
   return false;	
  }
  
  return true;
}

function hasContactMethod(form, strUse) {

 if (strUse != 'reference') { 
   var fldLine1 = eval('form.'+strUse+'Address1');
   var fldLine2 = eval('form.'+strUse+'Address2');
   var fldLine3 = eval('form.'+strUse+'Address3');
   var fldCity = eval('form.'+strUse+'City');
   var fldState = eval('form.'+strUse+'State');
   var fldPostalCode = eval('form.'+strUse+'PostalCode');
   var fldCountry = eval('form.'+strUse+'Country');

   if (!hasAddress(strUse.toUpperCase(), fldLine1, fldLine2, fldLine3, fldCity, fldState, fldPostalCode, fldCountry))
     return false;
 }  
 
 var fldTelephone = eval('form.'+strUse+'Telephone');
 var fldTelephoneExtension = eval('form.'+strUse+'TelephoneExtension');
 var fldFax = eval('form.'+strUse+'Fax');
 var fldEmail = eval('form.'+strUse+'Email');
 
 if (!hasComm(strUse.toUpperCase(), fldTelephone,fldTelephoneExtension,fldFax,fldEmail))
   return false;
 
  return true;
}

function DoFormValidation(form){

  if (!checkName(form.ApplicantFamilyName.value)) {
     alert('Invalid Family Name');
     form.ApplicantFamilyName.focus();
     return false;
    }

  if (!checkName(form.ApplicantGivenName.value)) {
     alert('Invalid Given Name');
     form.ApplicantGivenName.focus();
     return false;
    }
    
  if (!checkSelect(form.DriverLicenseRegion)) {
    alert("Must select a valid State for the Driver's License");
    form.DriverLicenseRegion.focus();
    return false;
  }
  
  if (getSelect(form.DriverLicenseRegion) != 'N/A') {
    if (isWhitespace(form.DriverLicenseID.value)||isRepeat(form.DriverLicenseID.value)) {
      alert("Must enter valid Driver's License Number");
      form.DriverLicenseRegion.focus();
      return false;
    }
  }
//
//  Taken out 8/8/2002 LD 
//  
//  if (isWhitespace(form.GovernmentID.value) || isRepeat(form.GovernmentID.value)) {
//    alert("Must enter valid Social Security Number or \nN/A");
//    form.GovernmentID.focus();
//    return false;
//  }
//
//  if (trim(form.GovernmentID.value) != 'N/A') {
//    var nSSN = normalizeData(form.GovernmentID.value, '-. ');
//    if (!isInteger(nSSN)) {
//      alert("Must enter valid Social Security Number or \nN/A");
//      form.GovernmentID.focus();
//      return false;
//    }
//  }
  
  var bCompany = !isWhitespace(form.CompanyName.value);
  
  if (bCompany && trim(form.CompanyName.value).length < 2) {
    alert('Invalid Company Name');
    form.CompanyName.focus();
    return false;
  }
  
  if (bCompany) {
    if (!hasContactMethod(form, 'business'))
      return false;
      
    if (!checkFormattedName(form.referenceName.value)) {
      alert('Invalid Company Official Contact Name');
      form.referenceName.focus();
      return false;
    }
      
    if (!hasContactMethod(form, 'reference'))
      return false;
  }
  else {
    if (!hasContactMethod(form, 'home'))
      return false;
  }   

  if (isWhitespace(form.intendedUse.value)) {
    alert('You must specify the intended use of WSSC Records/Information');
    form.intendedUse.focus();
    return false; 	
  }
  if (!(form.chkHardCopy.checked||form.chkInternet.checked||form.chkElectronicData.checked)) {
    alert('You must check at least one type of information');
    form.chkHardCopy.focus();
    return false;
  }
  
  if (form.chkInternet.checked) {
    if (!checkUsername(form.userID.value)) {
      alert('Invalid UserID');
      form.userID.focus();
      return false;
    }
  }
  
  if (form.chkElectronicData.checked) {
    if (!bCompany) {
      alert('You must provide all Company information to get access to Electronic Data');
      form.CompanyName.focus();
      return false;
    }
  
    if (!checkFormattedName(form.authorizedName.value)) {
      alert('Invalid Authorized WSSC Contact Name');
      form.authorizedName.focus();
      return false;
    }
  }	
      
return true;
}


