  
  
  
  function dd_year(){
	var year = $("select#year").val();
	$("select#make").attr({ disabled: "disabled" });
	$("select#model").attr({ disabled: "disabled" });
	if($("select#year").val() == "0")
	{
		return false;
	}
    
    $("#make_loader").show();
	
	$.getJSON(base_url+"/ajax/vehicle_drilldown/year/"+year,{}, function(j){    
		var options = '';
		var count = 0;
		for (var i = 0; i < j.length; i++) {
			count++;
			if($.browser.msie && j.length == 2 && count == 2)
			{
				options += '<option value="' + j[i].optionValue + '" selected="selected">' + j[i].optionDisplay + '</option>';
			}
			else
			{
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
		}
		$("select#make").html(options);
		if(count == 2){
			var selectSecond = function() {
				$('select#make option:second').attr('selected','selected');
			};
			$.browser.msie ? setTimeout(selectSecond,1) : selectSecond();
		}else{                          		
			var selectFirst = function() {
				$('select#make option:first').attr('selected','selected');
			};
			$.browser.msie ? setTimeout(selectFirst,1) : selectFirst();   
			
		}
		$("#make_loader").hide();
		$("select#make").attr({ disabled: "" });
		
		if(count == 2)
		{
			dd_make();
		}
	});
};

function dd_make(){
	var year = $("select#year").val();
	var make = $("select#make").val();
	$("select#model").attr({ disabled: "disabled" });
	if($("select#make").val() == "0")
	{
		return false;
	}
	
	$("#model_loader").show();
		
	$.getJSON(base_url+"/ajax/vehicle_drilldown/year/"+year+"/make/"+make,{}, function(j){    
		var options = '';
		var count = 0;
		for (var i = 0; i < j.length; i++) {
			count++;
			if($.browser.msie && j.length == 2 && count == 2)
			{
				options += '<option value="' + j[i].optionValue + '" selected="selected">' + j[i].optionDisplay + '</option>';
			}
			else
			{
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
		}
		$("select#model").html(options);
		if(count == 2){
			var selectSecond = function() {
				$('select#model option:second').attr('selected','selected');
			};
			$.browser.msie ? setTimeout(selectSecond,1) : selectSecond();
		}else{
			var selectFirst = function() {
				$('select#model option:first').attr('selected','selected');
			};
			$.browser.msie ? setTimeout(selectFirst,1) : selectFirst();
		}
		$("select#model").attr({ disabled: "" });
		$("#model_loader").hide();
		
		if(count == 2)
		{                                             
			dd_model();
		}
	});
};

function dd_model(){
	var year = $("select#year").val();
	var make= $("select#make").val();
	var model= $("select#model").val();
	if($("select#model").val() == "0")
	{
		return false;
	}        
	
	$("#category_loader").show();
		
	$.getJSON(base_url+"/ajax/vehicle_categories/year/"+year+"/make/"+make+"/model/"+model,{}, function(j){    
		var options = '';
		var count = 0;
		for (var i = 0; i < j.length; i++) {
			count++;
			if($.browser.msie && j.length == 2 && count == 2)
			{
				options += '<option value="' + j[i].optionValue + '" selected="selected">' + j[i].optionDisplay + '</option>';
			}
			else
			{
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
		}
		$("select#category").html(options);
		if(count == 2){
			var selectSecond = function() {
				$('select#category option:second').attr('selected','selected');
			};
			$.browser.msie ? setTimeout(selectSecond,1) : selectSecond();
		}else{
			var selectFirst = function() {
				$('select#category option:first').attr('selected','selected');
			};
			$.browser.msie ? setTimeout(selectFirst,1) : selectFirst();
		}
		$("select#category").attr({ disabled: "" });
		$("#category_loader").hide();
		    
	});   
};



function dd_category(){
	var year = $("select#year").val();
	var make= $("select#make").val();
	var model= $("select#model").val();
	var category= $("select#category").val();
	if($("select#category").val() == "0")
	{
		return false;
	}      
	else
	{
		$("form#select_vehicle")[0].submit();
	}      	
};
	
	
	


$(document).ready(function() 
{
	$("select#year option:first").attr("selected","selected");
	$("select#year").change(function(){ dd_year(); });
	$("select#make").change(function(){ dd_make(); });
	$("select#model").change(function(){ dd_model(); });
	$("select#category").change(function(){ dd_category(); });

	// search field label
    $(".labeled").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});	
});