//-------------------------------------------------------------------
// VehicleSelector()
// Instantiate a new vehicle selector object
//-------------------------------------------------------------------
function VehicleSelector(url, vmake, vmake_obj, vmodel, vmodel_obj, vyear, vyear_obj, vengine, vengine_obj, vproduct, vproduct_obj)
  {
  this.url          = url;

  this.vmake        = getObject(vmake);
  this.vmake_obj    = vmake_obj;
  this.vmodel       = getObject(vmodel);
  this.vmodel_obj   = vmodel_obj;
  this.vyear        = getObject(vyear);
  this.vyear_obj    = vyear_obj;
  this.vengine      = getObject(vengine);
  this.vengine_obj  = vengine_obj;
  this.vproduct     = getObject(vproduct);
  this.vproduct_obj = vproduct_obj;

  this.vmakeVal    = -1;
  this.vmodelVal   = -1;
  this.vyearVal    = -1;
  this.vengineVal  = -1;
  this.vproductVal = -1;
  }

//-------------------------------------------------------------------
// OnXML()
//-------------------------------------------------------------------
VehicleSelector.prototype.OnXML = function(response)
  {
  var result = response.getElementsByTagName("result")[0];

  var data = result.childNodes;
  var type = result.getAttribute("type");
  var opt  = null;

  if (type == "year")
    {
    opt = this.vyear_obj;
    this.vmake_obj.ClearOptions(1);
    this.vmodel_obj.ClearOptions(1);
    this.vyear_obj.ClearOptions(1);
    this.vengine_obj.ClearOptions(1);
    this.vproduct_obj.ClearOptions(1);
    }
  else if (type == "make")
    {
    opt = this.vmake_obj;
    this.vmodel_obj.ClearOptions(1);
    this.vmake_obj.ClearOptions(1);
    this.vengine_obj.ClearOptions(1);
    this.vproduct_obj.ClearOptions(1);
    }
  else if (type == "model")
    {
    opt = this.vmodel_obj;
    this.vmodel_obj.ClearOptions(1);
    this.vengine_obj.ClearOptions(1);
    this.vproduct_obj.ClearOptions(1);
    }
  else if (type == "engine")
    {
    opt = this.vengine_obj;
    this.vengine_obj.ClearOptions(1);
    this.vproduct_obj.ClearOptions(1);
    }
  else if (type == "product")
    {
    opt = this.vproduct_obj;
    this.vproduct_obj.ClearOptions(1);
    }
  else
    {
    this.vmodel_obj.ClearOptions(1);
    this.vyear_obj.ClearOptions(1);
    this.vengine_obj.ClearOptions(1);
    this.vproduct_obj.ClearOptions(1);
    }

  if (!opt)
    return;

  // parse XML data and populate the select box
  for (var i=0, idx=1; i < data.length; i++)
    {
    if (data.item(i).nodeType == 1)  // A Tag node
      {
      opt.AddOption(data.item(i).firstChild.data, data.item(i).getAttribute("id"));
      }
    }

  opt.Select(0);
  }

//-------------------------------------------------------------------
// OnYearChange()
//-------------------------------------------------------------------
VehicleSelector.prototype.OnYearChange = function()
  {
  this.vyearVal       = this.vyear_obj.GetValue();

  this.vmakeVal       = -1;
  this.vmodelVal      = -1;
  this.vengineVal     = -1;
  this.vmake.value    = "";
  this.vmodel.value   = "";
  this.vengine.value  = "";
  this.vproduct.value = "";

  this.Update();
  }

//-------------------------------------------------------------------
// OnMakeChange()
//-------------------------------------------------------------------
VehicleSelector.prototype.OnMakeChange = function()
  {
  this.vyearVal       = this.vyear_obj.GetValue();
  this.vmakeVal       = this.vmake_obj.GetValue();
  this.vmake.value    = this.vmake_obj.GetTitle()

  this.vmodelVal      = -1;
  this.vengineVal     = -1;
  this.vmodel.value   = "";
  this.vengine.value  = "";
  this.vproduct.value = "";

  this.Update();
  }

//-------------------------------------------------------------------
// OnModelChange()
//-------------------------------------------------------------------
VehicleSelector.prototype.OnModelChange = function()
  {
  this.vyearVal       = this.vyear_obj.GetValue();
  this.vmakeVal       = this.vmake_obj.GetValue();
  this.vmake.value    = this.vmake_obj.GetTitle();
  this.vmodelVal      = this.vmodel_obj.GetValue();
  this.vmodel.value   = this.vmodel_obj.GetTitle();

  this.vengineVal     = -1;
  this.vengine.value  = "";
  this.vproduct.value = "";

  this.Update();
  }

//-------------------------------------------------------------------
// OnEngineChange()
//-------------------------------------------------------------------
VehicleSelector.prototype.OnEngineChange = function()
  {
  this.vengineVal     = this.vengine_obj.GetValue();
  this.vengine.value  = this.vengine_obj.GetTitle();

  this.vproduct.value = "";

  this.Update();
  }

//-------------------------------------------------------------------
// OnProductChange()
//-------------------------------------------------------------------
VehicleSelector.prototype.OnProductChange = function()
  {
  this.vproduct.value = this.vproduct_obj.GetTitle();
  }

//-------------------------------------------------------------------
// Update()
//-------------------------------------------------------------------
VehicleSelector.prototype.Update = function()
  {
  url  = this.url + "?mk=" + this.vmakeVal + "&md=" + this.vmodelVal + "&yr=" + this.vyearVal + "&eg=" + this.vengineVal;

  ajaxSendRequest(this, url, null, "get", true, null);
  }