/*
	Below are the generic settings to populate the search boxes
	with all of the vehicles for a dealer, allowing searches from
	any box, not needing all of them
*/

// Set select defaults
typeChange();
yearChange();
makeChange();
modelChange();

// reload drop downs when a selection is made
$('#type_sel').change(yearChange);
$('#year_sel').change(makeChange);
$('#make_sel').change(modelChange);

function typeChange(){
	$.getJSON('/cfc/generic_dealer.cfc?method=listType&dealerID='+dealerID+'&returnformat=json&queryformat=column',
	function(j){
		var jArray = j.split(",");
		var options = '<option value=""> - Type - </option>';
		for(var i=0; i<jArray.length; i++){
			options += '<option value="'+jArray[i]+'">'+jArray[i]+'</option>';
		}
		$('select#type_sel').html(options);
	});
}

function yearChange(){
	$.getJSON('/cfc/generic_dealer.cfc?method=listYear&returnformat=json&queryformat=column&dealerID='+dealerID+'&vehType='+$("#type_sel").val(),
	function(k){
		var options = '<option value=""> - Year - </option>';
		for(var i=0; i<k.DATA.VEHICLEYEAR.length; i++){
			options += '<option value="'+k.DATA.VEHICLEYEAR[i]+'">'+k.DATA.VEHICLEYEAR[i]+'</option>';
		}
		$('select#year_sel').html(options);
	});
}		

function makeChange(){
	$.getJSON('/cfc/generic_dealer.cfc?method=listMakes&returnformat=json&queryformat=column&dealerID='+dealerID+'&vehType='+$("#type_sel").val()+'&vehYear='+$("#year_sel").val(),
	function(m){
		var options = '<option value=""> - Make - </option>';
		for(var i=0; i<m.DATA.VEHICLEMAKE.length; i++){
			options += '<option value="'+m.DATA.VEHICLEMAKE[i]+'">'+m.DATA.VEHICLEMAKE[i]+'</option>';
		}
		$('select#make_sel').html(options);
	});
}	


function modelChange(){
	$.getJSON('/cfc/generic_dealer.cfc?method=listModels&returnformat=json&queryformat=column&dealerID='+dealerID+'&vehType='+$("#type_sel").val()+'&vehYear='+$("#year_sel").val()+'&vehMake='+$("#make_sel").val(),
	function(n){
		var options = '<option value=""> - Model - </option>';
		for(var i=0; i<n.DATA.VEHICLEMODEL.length; i++){
			options += '<option value="'+n.DATA.VEHICLEMODEL[i]+'">'+n.DATA.VEHICLEMODEL[i]+'</option>';
		}
		$('select#model_sel').html(options);
	});
}
/* End Search boxes */