$(document).ready(function() {
  	$('.autos_brands').change(
  		function(){
			var brId = $(".autos_brands option:selected").val();
			$('.autos_models').val(0);
			if(brId) {
				$.ajax({
					type: "GET",
					url: "/api/models/"+brId,
					dataType: "json",
					beforeSend: function() {},
					success: function(response) {
						//console.debug(response);
						if(response) {
						  	var opts=['<option value="">--Todos--</option>'], i, le = response.length;
						   	for( i=0; i<le;i++){
						   	  if(response[i].description != 'Otro Modelo' && response[i].description != 'No importa')
						   	  opts.push('<option value="'+response[i].model_id+'">'+response[i].description+'</option>');
						   	}
						   	$('.autos_models').html(opts.join());
						   	$('.autos_models').focus();
						}
					}
				});
			}
		}
	);
  	
 	$('.motos_brands').change(
  	  		function(){
  				var brId = $(".motos_brands option:selected").val();
  				$('.motos_models').val(0);
  				if(brId) {
  					$.ajax({
  						type: "GET",
  						url: "/api/models/"+brId,
  						dataType: "json",
  						beforeSend: function() { },
  						success: function(response) {
  							//console.debug(response);
  							if(response) {
  							  	var opts=['<option value="">--Todos--</option>'], i, le = response.length;
  							   	for( i=0; i<le;i++){
  							   		if(response[i].description != 'Otro Modelo' && response[i].description != 'No importa')
  							   		opts.push('<option value="'+response[i].model_id+'">'+response[i].description+'</option>');
  							   	}
  							   	$('.motos_models').html(opts.join());
  							   	$('.motos_models').focus();
  							}
  						}
  					});
  				}
  			}
  		);
 	
});


	
