// build the makes array
// used on the search page
function Build_Makes()
{
  var x = document.search.make;
  for (var i=0;i < makes.length;i++)
  {
    if (makes[i] == "")
    {
      x.options[i] = new Option("< All Makes >","");
    }
    else
    {
      x.options[i] = new Option(makes[i],makes[i]);
    }
  }
}

// build the models array
// used on the search page
function Build_Models()
{
  var i = document.search.make.selectedIndex;
  var x = document.search.model;
  x.options.length = 1;
  if(models[i] && models[i].length)
  {
    for (var j=0;j < models[i].length;j++)
    {
      if (models[i][j] == "#")
      {
        x.options[j] = new Option("< All Models >","");
      }
      else
      {
        x.options[j] = new Option(models[i][j],models[i][j]);
      }
    }
  }
}

function Validate_YearFrom()
{
  var from = parseInt(document.search.yearfrom.value);
  var to = parseInt(document.search.yearto.value);
  if (from > to && document.search.yearfrom.value != "" && document.search.yearto.value != "")
    document.search.yearto.value = from;
}

function Validate_YearTo()
{
  var from = parseInt(document.search.yearfrom.value);
  var to = parseInt(document.search.yearto.value);
  if (from > to && document.search.yearfrom.value != "" && document.search.yearto.value != "")
    document.search.yearfrom.value = to;
}

function Validate_RetailFrom()
{
  var from = parseInt(document.search.retailfrom.value);
  var to = parseInt(document.search.retailto.value);
  if (from > to && document.search.retailfrom.value != "" && document.search.retailto.value != "")
    document.search.retailto.value = from;
}

function Validate_RetailTo()
{
  var from = parseInt(document.search.retailfrom.value);
  var to = parseInt(document.search.retailto.value);
  if (from > to && document.search.retailfrom.value != "" && document.search.retailto.value != "")
    document.search.retailfrom.value = document.search.retailto.value;
}

// initialize the search form
function Initialize_Form ()
{
  if (document.search.make)
  {
    Build_Makes();
    document.search.make.value = default_make;
  }
  if (document.search.model)
  {
    Build_Models();
    document.search.model.value = default_model;
  }
}

// reset the search form
function reset_search_form()
{
  document.search.reset();
  if (document.search.make) Build_Makes();
  if (document.search.model) Build_Models();
}
