function quickSearch(optionArr){
	this.properties = {
		siteUrl: '',
		loadModelsUrl: 'vehicle_properties/ajax_get_models/',		
		useAjaxSearch: false,
		ajaxSearchObject: false,
		countryObject: false,
		
		search_data: {
				id_make: 0,
				id_model: 0,
				id_bodystyle: 0,
				id_make: 0,
				condition: 1,
				year_min: 0,
				year_max: 0,
				id_country: 0,
				id_region: 0,
				id_city: 0
		}
	}

	var _self = this;


	this.Init = function(options){
		_self.properties = $.extend(_self.properties, options);
		if(typeof(qs_country_select) != 'undefined'){
			_self.properties.countryObject = qs_country_select; 
		}
		_self.init_tabs();
		_self.init_reload_model();
	}

	this.init_tabs = function(){
		$('#qs_tab li').bind('click', function(){
			condition = ($(this).attr('id') == 'qs_new')?1:2;
			_self.set_tab(condition);
		});
	}
	
	this.set_tab = function(condition){
		var active_tab = (condition == 1)?'qs_new':'qs_used';
		$('#qs_tab li').removeClass('active');
		$('#'+active_tab).addClass('active');
		if(condition == 2){
			$('#qs_used_form').show();	
			$('#qs_condition_hidden').val(2);
		}else{
			$('#qs_used_form').hide();	
			$('#qs_condition_hidden').val(1);
		}
	}
	
	this.init_reload_model = function(){
		$('#qs_make_select').bind('change', function(){
			_self.reload_model_select($(this).val());
		});	
	}

	this.reload_model_select = function(id_make, id_model){
		$.ajax({
			url: _self.properties.siteUrl + _self.properties.loadModelsUrl + id_make,
			type: 'GET',
			cache: false,
			dataType: 'json',
			success: function(data){
				$('#qs_model_select option[value!=0]').remove();
				for(var id in data ){
					$('#qs_model_select').append('<option value="'+data[id].id+'">'+data[id].name+'</option>');
					if(id_model){
						$('#qs_model_select').val(id_model);
					}
				}
			}
		});
	}
	
	this.set_values = function(data){
		if(data){
		_self.properties.search_data = $.extend(_self.properties.search_data, data);
				
		}
		_self.set_tab(_self.properties.search_data.condition);
		
		if(_self.properties.search_data.id_make){
			$('#qs_make_select').val(_self.properties.search_data.id_make);	
			_self.reload_model_select(_self.properties.search_data.id_make, _self.properties.search_data.id_model);		
		}
		
		if(_self.properties.search_data.year_min){
			$('#qs_year_min').val(_self.properties.search_data.year_min);	
		}
		
		if(_self.properties.search_data.year_max){
			$('#qs_year_max').val(_self.properties.search_data.year_max);	
		}
		
		if(parseInt(_self.properties.search_data.id_city)){
			if(_self.properties.countryObject != false){
				_self.properties.countryObject.set_values_external('city', _self.properties.search_data.id_city);
			}
		}else
		if(parseInt(_self.properties.search_data.id_region)){
			if(_self.properties.countryObject != false){
				_self.properties.countryObject.set_values_external('region', _self.properties.search_data.id_region);
			}
		}else
		if(_self.properties.search_data.id_country){
			if(_self.properties.countryObject != false){
				_self.properties.countryObject.set_values_external('country', _self.properties.search_data.id_country);
			}
		}

	}
	
	this.set_ajax_search = function(ajax_search_object, refine_search){
		_self.properties.useAjaxSearch = true;
		_self.properties.ajaxSearchObject = ajax_search_object;
		
		if(refine_search){
			$('#qs_submit_btn').hide();
			$('#qs_search_form select').bind('change', function(){
				_self.send_ajax_search();
			});
			
			$('#qs_search_form input[type=text]').bind('keyup', function(){
				_self.send_ajax_search();
			});

			$('#qs_search_form input[type=hidden]').bind('change', function(){
				alert($(this).attr('id'));
				_self.send_ajax_search();
			});
			
		}else{
			$('#qs_search_form').bind('submit', function(){
				_self.send_ajax_search();
				return false;	
			});
		}		
	}
	
	this.send_ajax_search = function(){
		if(_self.properties.useAjaxSearch){
			_self.properties.ajaxSearchObject.loading_post_block($('#qs_search_form').serialize());
		}
	}
		
	_self.Init(optionArr);
}
