function updateMakeSelect()
{
  /* doesn't work in IE 6
  new Ajax.Updater('quicksearch-make-select', 'search.fetch-make-options');
  if ($('make-select'))
    new Ajax.Updater('make-select', 'search.fetch-make-options');
  */
  
  new Ajax.Request('search.fetch-make-options', {onSuccess: updateMakeSelectCallback});
}

function updateMakeSelectCallback(xhr, makes)
{
  var qsSelectEl = $('quicksearch-make-select');
  var selectEl = ($('make-select')) ? $('make-select') : false; // this element will only exist on the search page
  
  qsSelectEl.options.length = 0;
  qsSelectEl.options[0] = new Option('[ All Makes ]', 'all');
  if (selectEl) {
    selectEl.options.length = 0;
    selectEl.options[0] = new Option('[ All Makes ]', 'all');
  }
  
  makes.each(function(make) {
    var optionItem=new Option(make, make);
  
    //Is this make set in the last search?
    if(make==searchCriteria['m~make']) {
      optionItem.selected=true;
      updateModelSelectForMake(make);
    }
    
    qsSelectEl.options[qsSelectEl.length] = optionItem;
    if (selectEl)
      selectEl.options[selectEl.length] = optionItem;
  });
  
  
}

function updateModelSelectForMake(make)
{
  $('quicksearch-make-select').value = make;
  if ($('make-select'))
    $('make-select').value = make;
  
  /* doesn't work in IE 6
  new Ajax.Updater('quicksearch-model-select', 'search.fetch-model-options?make=' + make);
  if ($('model-select'))
    new Ajax.Updater('model-select', 'search.fetch-model-options?make=' + make);
  */
  
  new Ajax.Request('search.fetch-model-options?make=' + escape(make), {onSuccess: updateModelSelectCallback});
}

function updateModelSelectCallback(xhr, models)
{
  var qsSelectEl = $('quicksearch-model-select');
  var selectEl = ($('model-select')) ? $('model-select') : false; // this element will only exist on the search page
  
  qsSelectEl.options.length = 0;
  qsSelectEl.options[0] = new Option('[ All Models ]', 'all');
  if (selectEl) {
    selectEl.options.length = 0;
    selectEl.options[0] = new Option('[ All Models ]', 'all');
  }
  
  models.each(function(model) {
     var optionItem = new Option(model, model);
    //Is this make set in the last search?
    if(model==searchCriteria['m~model']) {
      optionItem.selected=true;
    }
  
    qsSelectEl.options[qsSelectEl.length] = optionItem;
    if (selectEl)
      selectEl.options[selectEl.length] = optionItem;
  });
}
