$(function() {
	$.getJSON(
		'/cr/php/ls.php',
		{action:'get_manus'},
		function(data) {
			$(data).each(function() {
				$('#mfg').append($('<option value="'+this.mfg+'">'+this.mfg+'</option>'));
			});
		$('div.body').append($('<div class="no-results">Please complete the form to see your results.</div>'));
		});
	if ($('form#loader-search').length && $.browser.msie) {
		$('form#loader-search select#mfg').after(' &nbsp; &nbsp; &nbsp;');
	}
	$('select#mfg').change(function() {
		$.getJSON(
			'/cr/php/ls.php',
			{action:'get_models',mfg:$(this).val()},
			function(data) {
				$('#model').html('<option value="">Select a Model...</option>');
				$(data).each(function() {
					$('#model').append('<option value="'+this.model+'">'+this.model+'</option>');
				});
			});
			//$('div.body div.results,div.body div.no-results').remove();
		});
	$('select#model,select#drive,select#cab').change(function() {
		getLoaders();
		});
	function getLoaders() {
		$('div.body div.results,div.body div.no-results').remove();
		var model = $('select#model').val();
		var drive = $('select#drive').val();
		var cab = $('select#cab').val();
		if (model != '' && drive != '' && drive != 'Select Drive...' && cab != '' && cab != 'Select Cab...') {
			$.getJSON(
				'/cr/php/ls.php',
				{
					action:'get_loaders',
					mfg:$('select#mfg').val(),
					model:$('select#model').val(),
					drive:$('select#drive').val(),
					cab:$('select#cab').val()
				},
				function(data) {
					$('div.body div.results,div.body div.no-results').remove();
					if (data.length) {
						var ids = data[0];
						$('<div class="results"></div>')
							.appendTo('div.body')
							.load('/index.php/loader-info/list/'+ids+' #search-results',function() {
								tb_init('#search-results a.thickbox');
							});
					} else {
						$('div.body').append($('<div class="no-results">There are no matches for this particular search.  Please call us at 800-456-1107 to find the loader you are looking for.  Thank you.</div>'));
					}
				});
		} else {
			 $('div.body').append($('<div class="no-results">Please complete the form to see your results.</div>'));
		}
	}
});