   
/* --- load arrays --- */
function load_arrays()
{
   g_arr_models  = g_ref_models.split('|');
}

function add_options(l_option,l_array)
{
   i=0;
   while (l_array[i])
   {
      l_arr_model = l_array[i].split(',');
      l_model = l_arr_model[0];
      l_model_txt = l_arr_model[1];

     // --- check for duplicates ---
      l_equal = 0;
      l_len = l_option.options.length;
      for(j=0;j<l_len;j++)
      {
         if (l_model == l_option.options[j].value)
         {
            l_equal = 1;
            break;
         }
      }
      if (l_equal)
      {
         i++;
         continue;
      }

     // --- add new option ---
      l_new_option = new Option(l_model_txt, l_model, false, false);
      l_option.options[l_len] = l_new_option;

      i++;
   }
}

/* --- remove all options from select list --- */
function clean_options(l_option)
{
   //l_option.selectedIndex = -1;
   l_len = l_option.options.length;
   for (i=l_len-1;i>=0;i--)
   {
      if (l_option.options[i].value != 0)
         l_option.options[i] = null;
   }

}



function populate_models(l_make)
{

   l_option = l_make.options[l_make.options.selectedIndex].value;

  // --- build appropriate array ---
   l_arr_models = new Array();

   i=0;
   idx=0;
   var l_mmake,l_model,l_model_txt;
   while (g_arr_models[i])
   {
      l_arr_model = g_arr_models[i].split(',');
      l_make      = l_arr_model[0];
      l_model     = l_arr_model[1];
      l_model_txt = l_arr_model[2];

      if (l_make == l_option)
      {
         l_arr_models[idx++] = l_model + "," + l_model_txt;
      }
      i++;
   }

  // --- add array as makes ---
   clean_options(document.forms["adsearch"].elements["model"]);
   add_options(document.forms["adsearch"].elements["model"],l_arr_models);

   set_menu_active('home');
}

function chkflds()
{

   if (document.forms["adsearch"].elements["zipcode"].value.length== 0)
   {
      alert("Zipcode is mandatory!");
      document.forms["adsearch"].elements["zipcode"].focus();
      return false;
   }
   return true;
}
