TModelSelector = function(){	var t = this;	this.brandSelect = document.getElementById('auto54_select_brand');
	this.brandPreloaderImg = document.getElementById('auto54_img_brand');
	this.modelSelect = document.getElementById('auto54_select_model');
	this.modelPreloaderImg = document.getElementById('auto54_img_model');
	this.brandSelect.onchange = function(){t.onChangeBrand.call(t, this.value)}
	this.loadBrandList();}

TModelSelector.prototype = {	loadBrandList: function(){		var t = this;		var request = new TXMLHttpRequest();
		request.open('get', 'modelselector.php', true);
		request.completeHandler = this.onLoadBrandList;
		request.handlerOwner = this;
		request.send(null);	},
	onLoadBrandList: function(response){
	//alert(response);
    	var brandList = response.documentElement.childNodes;
   		var opt = document.createElement('option');
   		opt.value = '0';
   		opt.innerHTML = 'Все марки'
   		this.brandSelect.appendChild(opt);
    	for(var i = 0; i < brandList.length; i++){    		var opt = document.createElement('option');
    		opt.value = brandList[i].getAttribute('id');
    		opt.innerHTML = brandList[i].firstChild.data;
    		this.brandSelect.appendChild(opt);    	}
    	this.brandPreloaderImg.style.display = 'none';
    	this.brandSelect.style.display = 'block';	},
	onChangeBrand: function(idBrand){   		if(idBrand != '0'){   			this.modelSelect.style.display = 'none';
   			this.modelPreloaderImg.style.display = 'block';
			var request = new TXMLHttpRequest();
			request.open('get', 'modelselector.php?brand=' + idBrand, true);
			request.completeHandler = this.onLoadModelList;
			request.handlerOwner = this;
			request.send(null);   		}else{			this.modelSelect.innerHTML = '';
	   		var opt = document.createElement('option');
	   		opt.value = '0';
	   		opt.innerHTML = 'Выберете марку автомобиля';
	   		this.modelSelect.appendChild(opt);   		}	},
	onLoadModelList: function(response){		this.modelSelect.innerHTML = '';
    		var opt = document.createElement('option');
    		opt.value = '0';
    		opt.innerHTML = 'Все модели';
    		this.modelSelect.appendChild(opt);    	var modelList = response.documentElement.childNodes;
    	for(var i = 0; i < modelList.length; i++){
    		var opt = document.createElement('option');
    		opt.value = modelList[i].getAttribute('id');
    		opt.innerHTML = modelList[i].firstChild.data;
    		this.modelSelect.appendChild(opt);
    	}
    	this.modelPreloaderImg.style.display = 'none';
    	this.modelSelect.style.display = 'block';	}}
