var makes = new Array();
var models = new Array();


makes.push(new Array('Tool', 'Vermeer'));
models.push(new Array('Vermeer', '4-1/2" BOX x BOX transmitter housing'));
models.push(new Array('Vermeer', '12" Wing Cutter'));
models.push(new Array('Vermeer', '8" Wing Cutter'));
models.push(new Array('Vermeer', '14" Wing Cutter'));
models.push(new Array('Vermeer', '16" Wing Cutter'));
models.push(new Array('Vermeer', '18" Wing Cutter'));
models.push(new Array('Vermeer', '8-1/2" Compaction Bell'));
models.push(new Array('Vermeer', '12-1/2" Compaction Bell'));
models.push(new Array('Vermeer', '14-1/2" Compaction Bell'));
models.push(new Array('Vermeer', '6-1/2" Compaction Bell'));
models.push(new Array('Vermeer', 'Spiral Compaction'));

makes.push(new Array('Trencher', 'Ditch Witch®'));
models.push(new Array('Ditch Witch®', 'RT115H'));

makes.push(new Array('Trencher', 'Vermeer'));
models.push(new Array('Vermeer', 'RT1250'));

makes.push(new Array('Rig', 'Astec'));
models.push(new Array('Astec', 'DD65'));

makes.push(new Array('Rig', 'Ditch Witch®'));
models.push(new Array('Ditch Witch®', 'JT3020 All Terrain'));
models.push(new Array('Ditch Witch®', 'JT2720 ALL TERRAIN'));
models.push(new Array('Ditch Witch®', 'JT2020M1'));
models.push(new Array('Ditch Witch®', 'JT1220M1'));
models.push(new Array('Ditch Witch®', 'JT4020 All Terrain'));
models.push(new Array('Ditch Witch®', 'JT8020M1'));
models.push(new Array('Ditch Witch®', 'JT4020M1'));
models.push(new Array('Ditch Witch®', 'JT2720'));

makes.push(new Array('Rig', 'Vermeer'));
models.push(new Array('Vermeer', '10x14'));
models.push(new Array('Vermeer', '10x15'));
models.push(new Array('Vermeer', '24x40 Series II'));
models.push(new Array('Vermeer', '24x40a'));
models.push(new Array('Vermeer', '16x20a'));
models.push(new Array('Vermeer', '80x120'));
models.push(new Array('Vermeer', '36x50 Series II'));
models.push(new Array('Vermeer', '50x100a'));

makes.push(new Array('Rig', 'Case'));
models.push(new Array('Case', '6010'));

makes.push(new Array('Rig', 'CMS'));
models.push(new Array('CMS', '180'));

makes.push(new Array('MudStuff', 'StraightLine'));
models.push(new Array('StraightLine', 'SL100HP'));

makes.push(new Array('MudStuff', 'Tulsa Rig Iron'));
models.push(new Array('Tulsa Rig Iron', 'MCS-325'));

makes.push(new Array('MudStuff', 'KemTron'));
models.push(new Array('KemTron', 'Samba'));

makes.push(new Array('MudStuff', 'Ring-O-Matic'));
models.push(new Array('Ring-O-Matic', '500 Jet Vac'));

makes.push(new Array('Trailer', 'Trail King'));
models.push(new Array('Trail King', 'TK70HT'));

$(document).ready(function() {
  //Disable the sub-selects on page load2
  $('#make-select').attr("disabled", "disabled");
  $('#model-select').attr("disabled", "disabled");
  
  // Watch for a change in Category Selection.
  $('#category-select').bind("change", function() {

	 //If it's a tool, nomenclature of the third select changes
	 if ($('#category-select').val() == "Tool") {
		$('#tertiary-search-term').text("Style");
	 } else {
		$('#tertiary-search-term').text("Model");
	 }
	 
	 //Reset our two sub-selects
	 $('#make-select').empty();
	 $('#make-select').append('<option value="Any">Any</option>');
	 $('#model-select').empty();
	 $('#model-select').append('<option value="Any">Any</option>');

	 if ($('#category-select').val() == "None") {
		//Re-disable our Make & Model Fields when "Please Select" is selected
		$('#make-select').attr("disabled", "disabled");
		$('#model-select').attr("disabled", "disabled");
	 } else {
		//Populate The Make sub-select
		for (i = 0; i < makes.length; i++) {
		  if (makes[i][0] == $('#category-select').val()) {
			 $('#make-select').append('<option value="' + makes[i][1] + '">' + makes[i][1] + '</option>');
		  }
		}
		// Re-enable our Make sub-select
		$('#make-select').removeAttr("disabled");
	 }
  });
  
  //Watch For a change in the Make Selection
  $('#make-select').bind("change", function() {
	 $('#model-select').empty();
	 $('#model-select').append('<option value="Any">Any</option>');
	 for (i = 0; i < models.length; i++) {
		if (models[i][0] == $('#make-select').val()) {
		  $('#model-select').append('<option value="' + models[i][1] + '">' + models[i][1] + '</option>');
		}
	 }
	 // Re-enable our Model option
	 $('#model-select').removeAttr("disabled");
  });
});
