
/*
REM JavaScript functions for Make/Model selector ("YMM Lite")
REM Works on both NetScape (4.0+) and IE (4.0+).
REM Look at \source\misc\home.asp for an example of how to use these functions.
*/
function mmInitialize(parent, make, model, make_caption, model_caption, bnew)
{
    mmInitializeEx(parent, make, model, make_caption, model_caption, bnew, false);
}


function mmInitializeEx(parent, make, model, make_caption, model_caption, bnew, buse_short_name)

{
    clearList(parent.mmMakes);
    
    addElement(parent.mmMakes, make_caption, 0);
    
    if (bnew == 'true')
	{
        for (var i = 0; i < mmMkN.length; i++)
        {
            if (mmMkN[i])
			{
                addElement(parent.mmMakes, mmMkN[i], mmMkN[i]);
            }
        }
    }
    else
	{
        for (var i = 0; i < mmMkU.length; i++)
            if (mmMkU[i])
            {
                addElement(parent.mmMakes, mmMkU[i], mmMkU[i]);
			}
    }

    if (make)
    {
        setDefaultByText(parent.mmMakes, make);
        
        if (model_caption != "none")
            mmChangeMakeEx(parent, bnew, model_caption, buse_short_name);
        
        if (model)
            setDefaultByText(parent.mmModels, model);
	}
    else
	{
        parent.mmMakes.selectedIndex = 0;
        mmChangeMakeEx(parent, bnew, model_caption, buse_short_name);
    }
}

function mmChangeMake(parent, bnew, model_caption)
{
    mmChangeMakeEx(parent, bnew, model_caption, false);
}

function InitializeModel(parent, bnew, model_caption, makeID)
{
	var arr = bnew ? mmMdN : mmMdU;
	ModelsPopulate(parent, arr[makeID], model_caption, false);
}

function mmChangeMakeEx(parent, bnew, model_caption, buse_short_name)
{
	if (bnew == 'true')
		var ModelList = mmMdN[parent.mmMakes.options[parent.mmMakes.selectedIndex].value];
	else
		var ModelList = mmMdU[parent.mmMakes.options[parent.mmMakes.selectedIndex].value];
	ModelsPopulate(parent, ModelList, model_caption, buse_short_name);
} 

function ModelsPopulate(parent, ModelList, model_caption, buse_short_name)
{
	clearList(parent.mmModels);
  addElement(parent.mmModels, model_caption, 0);
  if(ModelList)
  {
      var rgModels = ModelList.split(',');
      for (var i = 0; i < rgModels.length; i++)
      {
          var sName, sValue;
          // rgModels[i] may be a singular value of ModelAscii, or a "#" delimited string of ModelID and ModelAscii
					if (rgModels[i].indexOf('#') != -1)
					{
						var rgModel = rgModels[i].split('#');
						sName = rgModel[1];
						sValue = rgModel[0];
					}
					else
						sName = sValue = rgModels[i];
          if (rgModels[i])
          {
              addElement(parent.mmModels, (buse_short_name == true ? MakeShortName(sName) : sName), sValue);
          }
      }
      parent.mmModels.disabled = false;
  }
  else
      parent.mmModels.disabled = true;

  parent.mmModels.selectedIndex = 0;
}

// In order for model names to fit within the 130px-wide LeftNav control we need to modify
// some of the model names so that they fit.  Any name "tweaks" here must go through 
// editorial...
function MakeShortName(sName)
{
//  for all even i: mpNameToContraction[i] is the original name, and mpNameToContraction[i+1] the contraction
	var mpNameToContraction = ["3-Series Sport Wagon",  "3-Series Sprt Wgn",
	                           "3-Series Sports Wagon", "3-Series Sprts Wgn",
	                           "5-Series Sport Wagon", "5-Series Sprt Wgn",
	                           "5-Series Sports Wagon", "5-Series Sprts Wgn",
	                           "Passat Wagon (2001.5)", "Passat Wgn (01.5)",
	                           "Caprice Classic Wagon", "Caprice Clssic Wgn",
	                           "Power Ram 50 Sport Cab", "Pwr Ram 50 Sport",
	                           "Explorer  Sport Trac",  "Explorer Sport Trac",
	                           "LTD Crown Victoria Wagon", "LTD Crown Vic Wgn",
	                           "Grand Marquis Wagon", "Grand Marquis Wgn",
	                           "Cutlass Ciera Wagon", "Cutlass Ciera Wgn",
	                           "A4 Avant (Early 2005)", "A4 Avant (Early 05)",
	                           "S4 Avant (Early 2005)", "S4 Avant (Early 05)",
	                           "Continental Flying Spur", "Conti. Flying Spur",
	                           "Mazda6 Sport Wagon", "Mazda6 Sprt Wgn",
	                           "Aura Green Line Hybrid", "Aura GL Hybrid",
	                           "Vue Green Line Hybrid", "Vue GL Hybrid"]
	for (var i=0; i < mpNameToContraction.length; i += 2)
	{
		if (sName == mpNameToContraction[i]) return mpNameToContraction[i+1];
	}
	return sName;
}

function ModelChange(e, url)
{
	var o = e.target || window.event.srcElement;
	var model = o.options[o.selectedIndex].value;
	document.location = url + escape(model);
}
