// core validation function
function validateTLAs(originTLA, destTLA)
{
  var returnVal = true;

  // Check for orign being blank
	if ( originTLA == "" ) { 
	  addTravelerValidationErrors("Please enter what airport to leave from.");
		returnVal = false;
	}

  // Check destination being blank
	if ( destTLA == "" ) { 
	  addTravelerValidationErrors("Please enter what airport to go to.");
		returnVal = false;
	}

  // Check for orign & destination being the same
	if ( originTLA != "" && originTLA == destTLA ) { 
	  addTravelerValidationErrors("Your destination must be different than your origin.");
		returnVal = false;
	}
  
  // Make sure both tlas exist in our arrays of airports
  [originTLA, destTLA].each(function(tla) {
    if ( tla != "" && !validateTLAExists(tla) ) {
	    addTravelerValidationErrors("Cannot find the airport " + tla + ".");
      returnVal = false;
    }
  });
	
	return returnVal;
}

// Validate that a TLA exists, return true if it does
function validateTLAExists(tlaToCheck) {
  var tlaFound = false;
  [METROCODES, AIRPORTS].each(function(tlray) {
    tlray.each(function(pair) {
      if (pair.value.valid != false) {
        if (pair.key.toUpperCase() == tlaToCheck.toUpperCase() ) {        
          tlaFound = true;
        }
      }
    });
  });
  return tlaFound;
}

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