function getValues() {
    var text = '';
    var result = {};
    var subRealties = '';
    $('input,select,text,textarea').each(function() {
        if (this.type != 'hidden') {
            var str = this.id.replace(/^(.*_)(.*)/, "$2");
            if (str != undefined && this.value != undefined && this.value != -1) {
                if (this.value == 'on') {
                    // normal checkboxes
                    if (this.checked) {
                        result[str] = 1;
                        text += str + " " + result[str] + "\n";
                    }
                }
                else if (this.value == str && this.value != 'RbnListNormal' && this.value != 'RbnListGallery') {
                    // ignore gallery and list radiobuttons
                    // subrealty checkboxes
                    if (this.checked) {
                        subRealties += this.value + "_";
                    }
                }
                else {
                        result[str] = this.value;
                        text += str + " " + result[str] + "\n";
                }

            }
        }
    });
    // add subrealties (cut of trailing '_')
    if (subRealties.length > 0)
        result['subrealties'] = subRealties.substring(0, subRealties.length - 1);

    result = $('input.inputCity').updateResult(result);
    
    //these are hidden values
    return result;
}


function UpdateParameters()
{
    $('input.inputCity').update();    
}

$(function() { $('input.inputCity').xautocomplete(); } );

var callCounter = false;
function UpdateAutoComplete()
{
	$('input.inputCity').xautocomplete();
	$('input.inputCity').update();	
	var result = $.getQueryString({id:"total"});
    var setflag = ($("#search_live_counter").data("flag") != undefined);

    if ((!result) || callCounter)
    {    
      UpdateLiveCounter();    
    }
    else
    {
      callCounter = true;
    }
}

function UpdateLiveCounter() {
    var obj = getValues();
    var invalidParams =  (obj.city == undefined || obj.city == "") && (obj.zip == undefined || obj.zip == undefined) && (obj.radius != undefined && obj.radius != "");
    if (invalidParams)
    {
       obj.radius = undefined;
    }

    $('#search_live_counter').html('<img src="/Resources/sets/is24/Icons/loading.gif" width="15px" height="15px">');    
	$.getJSON("/IS24Web/_V2/Counter.ashx", obj, function(json) {
	   $('#search_live_counter').html("" + json[0] + "");
	   $('#live_counter_count1').html("" + json[0] + "");
	   $('#live_counter_count2').html("" + json[0] + "");                
	});
}

function CallCounter() {
  $('input.inputCity').update();
  UpdateLiveCounter();
}
