	$(document).ready(function(){
	
		//Default settings
		$("#search").attr("disabled","disabled");

		
		//Function for Make change
		$("#makes").change(function() {

			//Get Variables
			var makeText = $(this).children("option:selected").text();
			var selVal =$(this).val();


			//Set the action for the searchForm
		    	$('#searchForm').attr("action","carlist.php?status=active&sort=year&type=" + makeText);


			//Enable or Disable the search button
			if($(this)[0].selectedIndex == 0)
			{
				$("#search").attr("disabled","disabled");

			}
			
			else
			{
				$("#search").removeAttr("disabled","disabled");

			}
			
			

			//Set the url for the ajax call
			var url = "includes/getModelsByMake.php?make=" + makeText;


			//Ajax call to get models
			$.post(url, {make: ""+makeText+""}, function(data){
				if(data.length >0) {
					$('#models').html(data);
				}

				else
				{
					$('#models').html("<option value=\"\">Choose A Model</option>");
				}
			});

	   	});


		//Function for Model change
		$("#models").change(function() {

			//Get Variables
			var makeText = $('#makes').children("option:selected").text();
			var modelText = $('#models').children("option:selected").text();

			//Set the action for the searchForm
		    $('#searchForm').attr("action","carlist.php?status=active&sort=year&type=" + makeText + "&model=" + modelText);

	   	});


	});
