// This class implements the PositionChangeListener
// interface, in terms of LocationFix(s) and a FormElementLogger.  
// This class could be seen as a very thin bridge between all of these classes.
// This class implements the positionChange method to satisfy 
// the PositionChangeListener interface.
// @author Robert D. Rice
// vc_id = "$Id: FormElementLocationFixReporter.js 9260 2006-06-09 00:14:53Z robert $"

// Constructor
// @param the form element that will represent this reporter
// @param the field to report, optional, defaults to all,
//  "id" = fix.id
function FormElementLocationFixReporter( formElement, field ) {
  this.logger = new FormElementLogger( formElement );

  // positionChange implementation method
  if ( field ) {
    if ( field == "id" ) {
      this.positionChange = FormElementLocationFixReportChangeID;
    } else if ( field == "address" ) {
      this.positionChange = FormElementLocationFixReportChangeAddress;
    } else {
      this.positionChange = FormElementLocationFixReportChange;
    }
  } else {
    this.positionChange = FormElementLocationFixReportChange;
  }
}

// PositionChangeListener impl method
// Display the nearby location fixes
// @param PositionChangeEvent
function FormElementLocationFixReportChange( positionevent ) {
  var matches = getNearbyLocationFixIDs( positionevent );
  var msg = "";
  var delim = "";
  for ( var i = 0; i < matches.length; i++ ) {
    msg = msg + delim + displayLocationFix( matches[i] );
    delim = "\n";
  }

  this.logger.logMessage( msg );
}

// PositionChangeListener impl method
// Display the nearby location fixes
// @param PositionChangeEvent
function FormElementLocationFixReportChangeID( positionevent ) {
  var matches = getNearbyLocationFixIDs( positionevent );
  var msg = "";
  var delim = "";
  for ( var i = 0; i < matches.length; i++ ) {
    msg = msg + delim + matches[i];
    delim = ", ";
  }

  this.logger.logMessage( msg );
}

// PositionChangeListener impl method
// Display the nearby location fixes
// @param PositionChangeEvent
function FormElementLocationFixReportChangeAddress( positionevent ) {
  var matches = getNearbyLocationFixIDs( positionevent );
  var msg = "";
  var delim = "";
  for ( var i = 0; i < matches.length; i++ ) {
    msg = msg + delim + retrieveLocationFix( matches[i] ).address;
    delim = ", ";
  }

  this.logger.logMessage( msg );
}

