/* Author: Tricia Woodruff (twoodruff@cars.com)
   Date: 4-18-2004
   Copyright: 2005 Classified Ventures
   Descripton: Lead Path Make Model Year Functions
   
   Revision History:   
*/
var arrModels = new Array();

/* populateMicrositeMakes Function
   Populates the make dropdown for microsites that only want to show a select set or makes.
   This script will ensure that we have years and models for a given make before putting 
   it into the dropdown.
   makes = an array of makes to put in the dropdown
   form = the form the select list is in (this allows us to name the form whatever we want)   
*/
function populateMicrositeMakes(makes, form){
   var d = form.make; 
   makes.sort();
   for (i=0;i<makes.length;i++){
      for (j=0;j<mymNewArray.length-1;j++){
         singleMmy = mymNewArray[j].split(',');   
         opt = d.length-1;
         if (singleMmy[0] == makes[i] && singleMmy[0] != d.options[opt].value){
            d.options[d.length] = new Option(singleMmy[0],singleMmy[0]);
         }
      }
   }
   if(d.options.length > 1){
      d.options[1].selected=true;
      populateYears(d.options[1].value, form);
   }
}

/* populateMakes Function
   Populates the make dropdown from the mymNew.js (in the js directory).
   form = the form the select list is in (this allows us to name the form whatever we want)   
*/
function populateMakes(form){
   var singleMmy;
   var d = form.make; 
   var opt;
   for (i=0;i<mymNewArray.length-1;i++){
      singleMmy = mymNewArray[i].split(',');   
      opt = d.length-1;
      if (singleMmy[0] != d.options[opt].value){
         d.options[d.length] = new Option(singleMmy[0],singleMmy[0]);
     }
   }
   if(d.options.length > 1){
      d.options[1].selected=true;
      populateYears(d.options[1].value, form);
   }
}

/* populateYears Function
   Populates the years dropdown from the mymNew.js (in the js directory).
   aMake = the make that the year applies to.
   form = the form the select list is in (this allows us to name the form whatever we want)   
*/
function populateYears(aMake, form){
   var singleMmy;   
   var d = form.year; 
   var opt;
   var modelCount = 0;
   d.length=1;
   //clean out the array
   arrModels.length=1;   
   for (i=0;i<mymNewArray.length;i++){
      singleMmy = mymNewArray[i].split(',');
      opt = d.length-1;      
      if (singleMmy[0] == aMake){
         arrModels[modelCount] = mymNewArray[i];
         modelCount += 1;
         if(singleMmy[1] != d.options[opt].value){
            d.options[d.length] = new Option(singleMmy[1],singleMmy[1]);
         }
      }
   }   
   if(d.options.length > 1){
      d.options[1].selected = true;
      populateModels(d.options[1].value, form);
   }
}

/* populateModels Function
   Populates the models dropdown from the mymNew.js (in the js directory).
   aYear = the year that the model applies to.
   form = the form the select list is in (this allows us to name the form whatever we want)   
*/
function populateModels(aYear, form){
   var singleMmy;   
   var d = form.model;
   var opt;   
   d.length=1;
   for (i=0;i<arrModels.length;i++){  
      singleMmy = arrModels[i].split(',');
      opt = d.length-1;
      if (singleMmy[1] == aYear && singleMmy[2] != d.options[opt].value){
         d.options[d.length] = new Option(singleMmy[2],singleMmy[2]);
      }
   }
   if(d.options.length > 1){
      d.options[1].selected=true;
   }
}





