
var supportedBrowser = "Supported";
var doRedraw = false;
var siteLanguage = 0;

function SetDropDown(value, formObj, arrays, noTitle) {
    if (supportedBrowser == "Supported"){
        var mod = formObj;
        ClearList(mod);
        if(!noTitle)
        {
	        formObj.options[0] = arrays[0].option;
        }
	    FilteredListNoCase(mod, arrays, value, noTitle);
    }
}

function FirstDropDown(value, Obj, Obj1, array, array1) {
	if (value != "g0" && value != "none" && value != "other")
	{
		SetDropDown(value, Obj, array, false);
		SetDropDown("g0", Obj1, array1, true);
	}
	else if (value == "none" || value == "other")
	{
		SetDropDown(value, Obj, array, true);
		SetDropDown(value, Obj1, array1, true);
	}
	else
	{
		SetDropDown(value, Obj, array, true);
		SetDropDown(value, Obj1, array1, true);
	}
}

function SetSelected(value, Obj) {
	for (var j=0; j<Obj.length; j++)
		if (value.toLowerCase() == Obj.options[j].value.toLowerCase())
			Obj.options[j].selected = true;
}

function FilteredListNoCase(list, items, group, noTitle) {
    var j;
    if (noTitle){
    	j = 0;
    }else{
    	j = 1;
    }
    for (var i=0; i < items.length; i++) {
        if (group == 0 || group.toLowerCase() == items[i].group.toLowerCase()) {
            list.options[j++] = items[i].option;
            menuSet = true;
        }
    }
    if (list.options[0]){
	    list.options[0].selected=true;
	}
}

function Loader()
{
	if( chosenCMake  == "" ) { chosenCMake  = "g0"; }
	if( chosenNMake  == "" ) { chosenNMake  = "g0"; }
	if( chosenCYear  == "" ) { chosenCYear  = "g0"; }
	if( chosenNYear  == "" ) { chosenNYear  = "g0"; }
	if( chosenCModel == "" ) { chosenCModel = "g0"; }
	if( chosenNModel == "" ) { chosenNModel = "g0"; }

	if (supportedBrowser == "Supported")
	{
		if(!document.thisForm.CurrentMake.options[0])
		{
			PopulateList(document.thisForm.CurrentMake, CMakeArrays, "", chosenCMake, 0);
			if(chosenCMake != "g0")
			{
				if (chosenCMake == "none" || chosenCMake == "other")
				{
					SetDropDown(chosenCMake, document.thisForm.CurrentYear, CYearArrays, true);
					SetDropDown(chosenCMake, document.thisForm.CurrentModel, CModelArrays, true);
					chosenCYear = chosenCMake;
				}
				else
					SetDropDown(chosenCMake, document.thisForm.CurrentYear, CYearArrays, false);
			}
			else
			{
				SetDropDown(chosenCMake, document.thisForm.CurrentYear, CYearArrays, true);
			}
			if (!document.thisForm.CurrentYear.options[0])
			{
				SetDropDown("g0", document.thisForm.CurrentYear, CYearArrays, true);
				chosenCMake = "g0";
			}
			if(chosenCYear != "g0" && chosenCYear != "none" && chosenCYear != "other")
			{
				SetDropDown(chosenCYear, document.thisForm.CurrentModel, CModelArrays, false);
			}
			else
			{
				SetDropDown(chosenCYear, document.thisForm.CurrentModel, CModelArrays, true);
			 }
			if (!document.thisForm.CurrentModel.options[0])
			{
				SetDropDown("g0", document.thisForm.CurrentModel, CModelArrays, true);
				chosenCYear = "g0";
				chosenCModel = "g0";
			}
			Redraw();
		}
		if (chosenCModel != "g0")
		{
			SetSelected(chosenCMake, document.thisForm.CurrentMake);
			SetSelected(chosenCYear, document.thisForm.CurrentYear);
			SetSelected(chosenCModel, document.thisForm.CurrentModel);
		}

		//For What vehicle are you considering for your next vehicle purchase?
		if(!document.thisForm.NextMake.options[0])
		{
			ser = document.thisForm.NextMake;
			PopulateList(ser, NMakeArrays, "", chosenNMake, 0);
			if(chosenNMake != "g0")
			{
				if (chosenNMake == "none" || chosenNMake == "other")
				{
					SetDropDown(chosenNMake, document.thisForm.NextYear, NYearArrays, true);
					SetDropDown(chosenNMake, document.thisForm.NextModel, NModelArrays, true);
					chosenNYear = chosenNMake;
				}
				else
					SetDropDown(chosenNMake, document.thisForm.NextYear, NYearArrays, false);
			}
			else
			{
				SetDropDown(chosenNMake, document.thisForm.NextYear, NYearArrays, true);
			}
			if (!document.thisForm.NextYear.options[0])
			{
				SetDropDown("g0", document.thisForm.NextYear, NYearArrays, true);
				chosenNMake = "g0";
			}
			if(chosenNYear != "g0" && chosenNYear != "none" && chosenNYear != "other")
			{
				SetDropDown(chosenNYear, document.thisForm.NextModel, NModelArrays, false);
			}
			else
			{
				SetDropDown(chosenNYear, document.thisForm.NextModel, NModelArrays, true);
			 }
			if (!document.thisForm.NextModel.options[0])
			{
				SetDropDown("g0", document.thisForm.NextModel, NModelArrays, true);
				chosenNYear = "g0";
				chosenNModel = "g0";
			}
			Redraw();
		}
		if (chosenNMake != "g0")
		{
			SetSelected(chosenNMake, document.thisForm.NextMake);
			SetSelected(chosenNYear, document.thisForm.NextYear);
			SetSelected(chosenNModel, document.thisForm.NextModel);
		}

	}
}

function pageInit(){
	Loader();
	navIsLoaded=true;
}

function resubmit(){
	if (document.thisForm.ModelYearBox.options[document.thisForm.ModelYearBox.selectedIndex].value!="0")
	{
		document.thisForm.submit();
	}
}

