(function($){
  // очищаем select
  $.fn.clearSelect = function() {
	  return this.each(function(){
		  if(this.tagName=='SELECT') {
		      this.options.length = 0;
		      $(this).attr('disabled','disabled');
		  }
	  });
  }
  // заполняем select
  $.fn.fillSelect = function(dataArray) {
	  return this.clearSelect().each(function(){
		  if(this.tagName=='SELECT') {
			  var currentSelect = this;
			  $.each(dataArray,function(index,data){
				  var option = new Option(data.text,data.value);
				  if($.support.cssFloat) {
					  currentSelect.add(option,null);
				  } else {
					  currentSelect.add(option);
				  }
			  });
		  }
	  });
  }
})(jQuery);

$(document).ready(function(){

  // выбор автомобиля
  function adjustAuto(){
  	var countryValue = $('#country').val();
  	var tmpSelect = $('#city');
  	if(countryValue.length == 0) {
  		tmpSelect.attr('disabled','disabled');
  		tmpSelect.clearSelect();
  		adjustModel();
  	} else {
  		$.getJSON('../registration/cascadeSelectCountry.php',{country:countryValue},function(data) { tmpSelect.fillSelect(data).attr('disabled',''); });

  	}
  };


  $('#country').change(function(){
  	adjustAuto();
  }).change();
});
