if (window.homePage === undefined) {
	var homePage = 0;	
}

var vYearId = "";
var vMakeId = "";
var vTypeId = "";
var vModelId = "";
var vTrimId = "";
var vType = 0;
var focusVal = 0;
var cfStruct = new Object();
var searchResult = "";

/********************************************
	vyId = Vehicle Year element ID
	vmkId = Vehicle Make element ID
	vbsId = Vehicle Body Style element ID
	vtmId = Vehicle Trim element ID
	vmId = Vehicle Model element ID
	dId = Global params Dealer ID
	mkId = Global params Make ID
*********************************************/
function initVehicleSearch(fVal, vyId, vmkId, vbsId, vtmId, vmId, dId, mkId) {
	jQ('#searchRowWrap').hide();
	jQ('#searchProgress').show();
	
	focusVal = fVal;
	vYearId = vyId;
	vMakeId = vmkId;
	vModelId = vmId;
	vTypeId = vbsId;
	vTrimId = vtmId;
	
	cfStruct.DealerID = dId;
	cfStruct.NewUsed = vType;
	cfStruct.Year = $(vYearId).options[$(vYearId).selectedIndex].value;
	if (vType == 1) {
		cfStruct.MakeID = mkId;
		cfStruct.VehicleTypeID = $(vTypeId).options[$(vTypeId).selectedIndex].value;
	}
	else {
		cfStruct.MakeID = $(vMakeId).options[$(vMakeId).selectedIndex].value;
		cfStruct.VehicleTypeID = '';
	}
	
	cfStruct.ModelID = $(vModelId).options[$(vModelId).selectedIndex].value;
	cfStruct.homePage = homePage;
	
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'getData', 'GETVEHICLESEARCHPARAM', cfStruct, getVehicleSearchParamResults);
	
	if ($('hModelSearhRow')) {
		if (vType == 0 && (mkId == 1 || mkId == 14)) {
			$('hModelSearhRow').style.display = 'none';
			$('hTrimSearhRow').style.display = 'none';
			$('vyWrap').style.display = 'none';
		}
		else {
			$('hModelSearhRow').style.display = '';
			$('hTrimSearhRow').style.display = '';	
			$('vyWrap').style.display = '';
		}
	}
}

function getVehicleSearchParamResults(r) {
	searchResult = r;
	
	if (focusVal == 0) { setVehicleYears(); }
		
	if (vType == 0 && (focusVal == 0 || focusVal == 1)) { setVehicleMakes(); }
	if (focusVal == 0 || focusVal == 1 || focusVal == 2) { setVehicleModels(); }
	if (vType == 1 && (focusVal == 0 || focusVal == 1 || focusVal == 2 || focusVal == 4)) { setVehicleTypes(); }
	setVehicleTrims();
	
	jQ('#searchProgress').hide();
	jQ('#searchRowWrap').show();
}


function setVehicleYears() {
	var i = 0;
	var x = 0;
	
	$(vYearId).length = 0;
	
	if (searchResult.years.length > 0) {
		$(vYearId).options[0] = new Option('- All Years -', '', true, true);
		for (i=0; i<searchResult.years.length; i++) {
			x = i + 1;
			$(vYearId).options[x] = new Option(searchResult.years[i].year + " (" + searchResult.years[i].total_vehicles + ")", searchResult.years[i].year, false, false);
		}
	}
	else {
		$(vYearId).options[0] = new Option('- All Years -', '', true, true);
	}	
}

function setVehicleMakes() {
	var i = 0;
	var x = 0;
	
	$(vMakeId).length = 0;
	
	if (searchResult.makes.length > 0) {
		$(vMakeId).options[0] = new Option('- All Makes -', '', true, true);
		for (i=0; i<searchResult.makes.length; i++) {
			x = i + 1;
			$(vMakeId).options[x] = new Option(searchResult.makes[i].makename + " (" + searchResult.makes[i].total_vehicles + ")", searchResult.makes[i].makeid, false, false);
		}
	}
	else {
		$(vMakeId).options[0] = new Option('- No Make(s) -', '', true, true);
	}
}

function setVehicleTypes() {
	var i = 0;
	var x = 0;
	
	$(vTypeId).length = 0;
	
	if (searchResult.types.length > 0) {
		$(vTypeId).options[0] = new Option('- All Body Styles -', '', true, true);
		for (i=0; i<searchResult.types.length; i++) {
			x = i + 1;
			$(vTypeId).options[x] = new Option(searchResult.types[i].vehicle_type + " (" + searchResult.types[i].total_vehicles + ")", searchResult.types[i].vehicletypeid, false, false);
		}
	}
	else {
		$(vTypeId).options[0] = new Option('- No Body Styles -', '', true, true);
	}
}

function setVehicleModels() {
	var i = 0;
	var x = 0;
	
	$(vModelId).length = 0;
	
	if (searchResult.models.length > 0) {
		$(vModelId).options[0] = new Option('- All Models -', '', true, true);
		for (i=0; i<searchResult.models.length; i++) {
			x = i + 1;
			$(vModelId).options[x] = new Option(searchResult.models[i].model_name + " (" + searchResult.models[i].total_vehicles + ")", searchResult.models[i].modelid, false, false);
		}
	}
	else {
		$(vModelId).options[0] = new Option('- No Model(s) -', '', true, true);
	}
}

function setVehicleTrims() {
	var i = 0;
	var x = 0;
	
	$(vTrimId).length = 0;
	
	if (searchResult.trims.length > 0) {
		$(vTrimId).options[0] = new Option('- All Trims -', '', true, true);
		for (i=0; i<searchResult.trims.length; i++) {
			x = i + 1;
			$(vTrimId).options[x] = new Option(searchResult.trims[i].trim + " (" + searchResult.trims[i].total_vehicles + ")", searchResult.trims[i].trim, false, false);
		}
	}
	else {
		$(vTrimId).options[0] = new Option('- No Trim(s) -', '', true, true);
	}
}


function toggleMakeDisplay(vTypeObj,toggle,vyId,vmId,vbId) {
	//$(vyId).style.display = toggle;
	//$(vmId).style.display = toggle;
	
	if (toggle == 'none') {
		//$(vbId).style.display = '';
		jQ("#"+vmId).hide();
		jQ("#"+vbId).show();
	}
	else {
		//$(vbId).style.display = 'none';
		jQ("#"+vmId).show();
		jQ("#"+vbId).hide();
	}
	
	vType = vTypeObj.value;
}

function setSelectToEmpty(id, defaultText) {
	$(id).length = 0;
	$(id).options[0] = new Option(defaultText, '', true, true);
}