function redirectToUrl(value){
    if (value && value != 0)
        window.location = value;
}

function set_search_price(price_min, price_max){
    $('#id_price_min').val(price_min)
    $('#id_price_max').val(price_max)
}

var AutoComplete = {
    liFormat_input : function(row, i, num) {
	var result = row[0];
	return result;
    },
    selectItem_input: function(li) {
	if( li == null ) var sValue = '';
	if( !!li.extra ) var sValue = li.extra[0];
	else var sValue = li.selectValue;
	$(AutoComplete.id_input).val(sValue);
    },

    init: function(id_input, url){
	this.id_input = $('#'+id_input);
	$(this.id_input).autocomplete(url, {
	    delay:10,
	    minChars:2,
	    matchSubset:1,
	    autoFill:true,
	    matchContains:1,
	    cacheLength:10,
	    selectFirst:true,
	    formatItem: AutoComplete.liFormat_input,
	    maxItemsToShow:10,
	    onItemSelect:AutoComplete.selectItem_input
	}) ;
    }
}

var SearchForm = {
    change_realestate: function(){
	disabled_obj = SearchForm.area_box;
	enable_obj = SearchForm.room_count_box;
	realestate_type = $(SearchForm.realestate_type).val();
        if (realestate_type == 3 || realestate_type == 5){
	    disabled_obj = SearchForm.room_count_box;
	    enable_obj = SearchForm.area_box;
	}
	$(enable_obj).css('display','block');
	$(enable_obj).find('input').removeAttr('disabled');	
    	$(enable_obj).find('select').removeAttr('disabled');
	$(disabled_obj).css('display','none');	
	$(disabled_obj).find('input').attr('disabled','disabled');
	$(disabled_obj).find('select').attr('disabled','disabled');
    },
    
    init: function(){
	this.realestate_type = $('#id_realestate_type');
	$(this.realestate_type).change(SearchForm.change_realestate);
	this.room_count_box = $('#room_count_search_box');
	this.area_box = $('#area_search_box');
	this.change_realestate();
    }
}


