function search_getManufacturers()
{
	jQuery.post('/veh:load_ma', {}, function($obj) {
		try {
			
			var $o, $options = '<option value="0" selected="selected">Manufacturer</option>';
			eval('$o = ' + $obj);
			
			jQuery.each($o, function() {
				$options += '<option value="' + this.ma_id + '">' + this.ma_name + '</option>';
			});
			
			jQuery('select[name=v_ma]').html($options).attr('disabled', false).focus();
		} catch(__exception) {};
	});
};

function search_getModels(manufacturer)
{
	jQuery.post('/veh:get_mo', { 'ma_id': manufacturer }, function($obj) {
		try {
			var $o, $options = '<option value="0" selected="selected">Model</option>';
			eval('$o = ' + $obj);
			
			jQuery.each($o, function() {
				$options += '<option value="' + this.mo_id + '">' + this.mo_name + '</option>';
			});
			
			jQuery('select[name=v_mo]').html($options).attr('disabled', false).focus();
		} catch(__exception) {};
	});
};

function search_getSubModels(manufacturer, model)
{
	jQuery.post('/veh:get_smo', { 'ma_id': manufacturer, 'mo_id': model }, function($obj) {
		try {
			var $o, $options = '<option value="0" selected="selected">Sub Model</option>';
			eval('$o = ' + $obj);
			
			jQuery.each($o, function() {
				$options += '<option value="' + this.smo_id + '">' + this.smo_name + '</option>';
			});
			
			jQuery('select[name=v_smo]').html($options).attr('disabled', false).focus();
		} catch(__exception) {};
	});
};

function search_getFromYears(manufacturer, model, submodel)
{
	jQuery.post('/veh:get_year_from', { 'ma_id': manufacturer, 'mo_id': model, 'smo_id': submodel }, function($obj) {
		try {
			var $o, $options = '<option value="0" selected="selected">Year From</option>';
			eval('$o = ' + $obj);
			
			jQuery.each($o, function() {
				$options += '<option value="' + this.year_id + '">' + this.year_name + '</option>';
			});
			
			jQuery('select[name=v_yr_from]').html($options).attr('disabled', false).focus();
		} catch(__exception) {};
	});
};

function search_getToYears(manufacturer, model, submodel, yearfrom)
{
	jQuery.post('/veh:get_year_to', { 'ma_id': manufacturer, 'mo_id': model, 'smo_id': submodel, 'year_from': yearfrom }, function($obj) {
		try {
			var $o, $options = '<option value="0" selected="selected">Year To</option>';
			eval('$o = ' + $obj);
			
			jQuery.each($o, function() {
				$options += '<option value="' + this.year_id + '">' + this.year_name + '</option>';
			});
			
			jQuery('select[name=v_yr_to]').html($options).attr('disabled', false).focus();
		} catch(__exception) {};
	});
};

// onLoad with jQuery DOM
jQuery(function() {
	search_getManufacturers();
	
	jQuery('select[name=v_ma]').change(function() {
		search_getModels(jQuery(this).val());
	});
	
	jQuery('select[name=v_mo]').change(function() {
		search_getSubModels(jQuery('select[name=v_ma]').val(), jQuery(this).val());
	});
	
	jQuery('select[name=v_smo]').change(function() {
		search_getFromYears(jQuery('select[name=v_ma]').val(), jQuery('select[name=v_mo]').val(), jQuery(this).val());
	});
	
	jQuery('select[name=v_yr_from]').change(function() {
		search_getToYears(jQuery('select[name=v_ma]').val(), jQuery('select[name=v_mo]').val(), jQuery('select[name=v_smo]').val(), jQuery(this).val());
	});
});
