// core validation function
function validateTravelers(numAdult, numSenior, numYouth, numChild, numInfant, infant_in_seat) {
  var MAX_TRAVELERS = 6;
  var returnVal;
	var totalTravelers = numAdult*1 + numSenior*1 + numYouth*1 + numChild*1 + numInfant*1;
	var totalMinors = numChild*1 + numInfant*1;
	var totalNonMinors = totalTravelers - totalMinors;

  // Assume true to start
  returnVal = true;

  // Check for at least 1 traveler
	if ( totalTravelers == 0 ) { 
	  addTravelerValidationErrors("No travelers selected.");
		returnVal = false;
	}
  // Check for unacompanied minors
	if ( totalMinors > 0 && totalNonMinors == 0 ) { 
	  addTravelerValidationErrors("Infants and children may not travel unaccompanied.");
		returnVal = false;
	}
  // Check for too many infants in seat
	if (infant_in_seat == 1 && numInfant*1 > 0 && totalNonMinors > 0 && numInfant*1 / totalNonMinors > 2 ) { 
	  addTravelerValidationErrors("We are only able to book reserved seats for up to two infants per traveler aged 12+.");
		returnVal = false;
	}
  // Check for infants in laps -- need enough laps 
	if ( numInfant*1 > totalNonMinors && !infant_in_seat ) { 
	  addTravelerValidationErrors("We are only able to book one infant in lap per traveler aged 12+.");
		returnVal = false;
	}
  // Check for too many overall travelers, Expedia only supports a total of 6 
	if ( totalTravelers > MAX_TRAVELERS ) { 
	  addTravelerValidationErrors("Please select no more than " + MAX_TRAVELERS + " travelers.");
		returnVal = false;
	}
	
	return returnVal;
}

// add the error messages to the div
function addTravelerValidationErrors(errorMsg) {
  $('client_validation_message').innerHTML += errorMsg + "<br />";
    
	return true;
}