var pch=false;

function LTTownHandler(prefix)
{
  this.remote=new LTTownToDistance(this);
  this.prefix=prefix;
  this.e_dist=document.getElementById(this.prefix+"distance_kilometres");
  this.e_indicator=document.getElementById(this.prefix+"city_indicator");
}

LTTownHandler.prototype=new LTTownToDistanceListener;

LTTownHandler.prototype.onGet_distance=function(res)
{
  //window.alert("recieved distance of "+res)

  res=parseFloat(res);
  if (isNaN(res)) { this.e_dist.value='error'; }
  else { this.e_dist.value=round_off(1,res); }

  pch=false;
  this.e_indicator.style.display='none';
}

function check_city(e_city,alerts)
{
  // maybe check for valid cities
  return true;
}

function services_city_update(prefix, alerts)
{
  var e_dist=document.getElementById(prefix+"distance_kilometres");
  if (!e_dist) { return true; }

  if (pch) { return false; }

  e_dist.value='';

  var e_city=document.getElementById(prefix+"city");
  var e_company=document.getElementById(prefix+"company_name");

  if (!check_city(e_city,alerts)) { return false; }

  pch=new LTTownHandler(prefix);
  pch.remote.get_distance(e_company.value, e_city.options[e_city.selectedIndex].value);
  pch.e_indicator.style.display='';

  return true;
}

