//  <!--

function update_key_manuf() {
  if ( document.search_select.manufacturer_F.value != '-ANY-') {
    document.getElementById("key_manuf").innerHTML = document.search_select.manufacturer_F.value + '&nbsp;';
  }
  if ( document.search_select.model_F.value != '') {
  document.getElementById("key_model").innerHTML = '';
  }
}

function update_key_model() {
  if ( document.search_select.model_F.value != '-Any-') {
    document.getElementById("key_model").innerHTML = document.search_select.model_F.value + '&nbsp;';
  }
}

function load_models (what) {
  var v_man = what.manufacturer_F.options[what.manufacturer_F.selectedIndex].value;
  var i_mdl = what.model_F.selectedIndex;

  if ( v_man != '-Any-' && v_man != '--ANY--') {
    update_manuf(what);
    if (what.model_F.selectedIndex == 0) what.model_F.selectedIndex = i_mdl;
    return;
  }
  
  what.model_F.length = 1;
  what.model_F.options[0].selected = true;
  what.model_F.options[0].text = 'Model e.g. Transit'
  what.model_F.options[0].value = '-Any-';
}

function update_manuf (what) {
  var v_man = what.manufacturer_F.options[what.manufacturer_F.selectedIndex].value;
  if (v_man != '-Any-' && v_man != '--ANY--') { update_model_sel(what); checkModelType(what); return; }
  checkModelType(what);
  what.model_F.length = 1;
  what.model_F.options[0].text = 'Model e.g. Transit'
  what.model_F.options[0].value = '-Any-';
  what.model_F.selectedIndex = 0;
}

function update_model_sel (what, model, is_ford)
{ 
  var v_man = what.manufacturer_F.options[what.manufacturer_F.selectedIndex].value;
  if (!model) {
    var v_mdl = what.model_F.options[what.model_F.selectedIndex].value;
  } else {
    var v_mdl = model; 
  }

  var option_selected = new Array;
  var selected_num = 0;

  checked_val = getCheckedValue(what.new_yn_F);

  if (checked_val == 'N') {
    for (i = 1; i < model_options.length; i++)
    {
      if ( model_options[i][0] == v_man )
      {
        new_yn = 1;
        for (j = 1; j<= selected_num; j++)
        {
          if (option_selected[j] == model_options[i][1])
          {
           new_yn = 0;
           break;
          }
        }
        if (new_yn == 1)
        {
          selected_num++;
          option_selected[selected_num] = model_options[i][1];
        }
      }
    }
  } else {
    for (i = 1; i < model_options_new.length; i++)
    {
      if ( model_options_new[i][0] == v_man )
      {
        new_yn = 1;
        for (j = 1; j<= selected_num; j++)
        {
          if (option_selected[j] == model_options_new[i][1])
          {
           new_yn = 0;
           break;
          }
        }
        if (new_yn == 1)
        {
          selected_num++;
          option_selected[selected_num] = model_options_new[i][1];
        }
      }
    }
  }

  what.model_F.length=0;
  selected = 0;
  j = 0;
  if (model_any == 'Y')
  {
    what.model_F.length++;
  if (is_ford == 'N') {
	what.model_F.options[j].text = 'Model e.g. Transit'
  } else{
	what.model_F.options[j].text = 'Model'
  }
    what.model_F.options[j].value = '-Any-';
    j++;
  }

  for (i = 1; i <= selected_num; i++)
  {
    what.model_F.length++;
    what.model_F.options[j].text = option_selected[i];
    what.model_F.options[j].value = option_selected[i];
    if (v_mdl == option_selected[i])
    { selected = 1;
      what.model_F.selectedIndex = j;
    }
    j++;
  }
  if (selected == 0)
  what.model_F.selectedIndex = 0;
} 

function update_fields (what, manuf, model) {

  var option_selected = new Array;
  var selected_num = 0;
  checked_val = getCheckedValue(what.new_yn_F);
  if (checked_val == 'Y') {
    for (i = 1; i < model_options_new.length; i++)
    {
      new_yn = 1;
      for (j = 1; j <= selected_num; j++)
      {
        if (option_selected[j] == model_options_new[i][0])
        {
         new_yn = 0;
         break;
        }
      }
      if (new_yn == 1)
      {
        selected_num++;
        option_selected[selected_num] = model_options_new[i][0];
      }
    }
  } else {
    for (i = 1; i < model_options.length; i++)
    {
      new_yn = 1;
      for (j = 1; j <= selected_num; j++)
      {
        if (option_selected[j] == model_options[i][0])
        {
         new_yn = 0;
         break;
        }
      }
      if (new_yn == 1)
      {
        selected_num++;
        option_selected[selected_num] = model_options[i][0];
      }
    }
  }
  what.manufacturer_F.length = 1;
  what.manufacturer_F.options[0].text = 'Make e.g. Ford'
  what.manufacturer_F.options[0].value = '-Any-';
  
  for (i = 1; i <= selected_num; i++)
  {
    what.manufacturer_F.length++;
    what.manufacturer_F.options[i].text = option_selected[i];
    what.manufacturer_F.options[i].value = option_selected[i];
    if (option_selected[i] == manuf) {
      what.manufacturer_F.selectedIndex = i;
    }
  }

  checked_val = getCheckedValue(what.new_yn_F);

  if (checked_val == 'D') {
    what.action = "/dealer-results.lml";
    document.getElementById("model").disabled = true;
    document.getElementById("price").disabled = true;
    document.getElementById("pc").disabled = false;
  } else {
    what.action = "/search-results.lml"; 
    document.getElementById("model").disabled = false;
    document.getElementById("price").disabled = false;
    document.getElementById("pc").disabled = false;
  }

  if (checked_val == 'Y') {
    what.action = "/new-search-results.lml"; 
    document.getElementById("pc").disabled = true;
    document.getElementById("price").disabled = false;
  }
  
  var v_man = what.manufacturer_F.options[what.manufacturer_F.selectedIndex].value;
  if (v_man != '-Any-' && v_man != '--ANY--') { update_model_sel(what, model, 'N'); return; }

}

function getCheckedValue(radioObj) {
  if(!radioObj)
    return "";
  var radioLength = radioObj.length;
  if(radioLength == undefined)
    if(radioObj.checked)
      return radioObj.value;
    else
      return "";
    for(var i = 0; i < radioLength; i++) {
    if(radioObj[i].checked) {
      return radioObj[i].value;
    }
  }
return "";
}

var v_price_range={'Price Range':'0-100000',
                   'Any Price':'0-100000',
                   '0 - 5000':'0-5000',
                   '5000 - 6000':'5000-6000',
                   '6000 - 7000':'6000-7000',
                   '7000 - 8000':'7000-8000',
                   '8000 - 9000':'8000-9000',
                   '9000 - 10000':'9000-10000',
                   '10000 - 11000':'10000-11000',
                   '11000 - 12000':'11000-12000',
                   '12000 or more':'12000-100000'
                  };

function checkModelType(what) {
/*
  if ((what.model_F.options[what.model_F.selectedIndex].value == 'Transit') || (what.manufacturer_F.options[what.manufacturer_F.selectedIndex].value =='-Any-')) 
  {
    what.price_F.length=0;
    selected = 0;
    j = 1;
    what.price_F.length++;
    what.price_F.options[0].text = 'Price Range'; what.price_F.options[0].value = '\'0-100000\'';
    what.price_F.length++; what.price_F.options[1].text = 'Any Price'; what.price_F.options[1].value = '\'0-100000\'';
    what.price_F.length++; what.price_F.options[2].text = '0 - 5000'; what.price_F.options[2].value = '\'0-5000\'';
    what.price_F.length++; what.price_F.options[3].text = '5000 - 6000'; what.price_F.options[3].value = '\'5000-6000\'';
    what.price_F.length++; what.price_F.options[4].text = '6000 - 7000'; what.price_F.options[4].value = '\'6000-7000\'';
    what.price_F.length++; what.price_F.options[5].text = '7000 - 8000'; what.price_F.options[5].value = '\'7000-8000\'';
    what.price_F.length++; what.price_F.options[6].text = '8000 - 9000'; what.price_F.options[6].value = '\'8000-9000\'';
    what.price_F.length++; what.price_F.options[7].text = '9000 - 10000'; what.price_F.options[7].value = '\'9000-10000\'';
    what.price_F.length++; what.price_F.options[8].text = '10000 - 11000'; what.price_F.options[8].value = '\'10000-11000\'';
    what.price_F.length++; what.price_F.options[9].text = '11000 - 12000'; what.price_F.options[9].value = '\'11000-12000\'';
    what.price_F.length++; what.price_F.options[10].text = '12000 or more'; what.price_F.options[10].value = '\'11000-100000\'';
  } else*/ { 
    what.price_F.length=0;
    selected = 0;
    j = 1;
    idx = 0;
    for (var vpr_array in v_price_range) {
      what.price_F.length++;
      what.price_F.options[idx].text = vpr_array;
      what.price_F.options[idx].value = v_price_range[vpr_array]; 
      if (what.past_pricer.value == v_price_range[vpr_array]) {
        what.price_F.options[idx].selected = 'selected';
      }
      idx = idx + 1;
    }
  }
}

// -->


