function lookup(id, inputString, baseUrl) {
    if (id == 'serviceName') {
        if(inputString.length == 0) {
            // Hide the suggestion box.
            $('#suggestions').hide();
        } else {
            $.post(baseUrl+"service/ajaxservicelist", {queryString: ""+inputString+""}, function(data){
                if(data.length >0) {
                    $('#suggestions').show();
                    $('#autoSuggestionsList').html(data);
                }
            });
        }
    } else if (id == 'inputString') {
        if(inputString.length == 0) {
            // Hide the suggestion box.
            $('#suggestions').hide();
        } else {
            $.post(baseUrl+"spot/ajaxspotlist", {queryString: ""+inputString+""}, function(data){
                if(data.length >0) {
                    $('#suggestions').show();
                    $('#autoSuggestionsList').html(data);
                }
            });
        }
    }
} // lookup

function fill(id, thisValue) {
    $('#'+id).val(thisValue);
    if ($('#autocompleterSelection').length) {
        $('#autocompleterSelection').html(thisValue);
    }
    setTimeout("$('#suggestions').hide();", 200);
}

function selectSpot(spotId, isDistrict) {
    $('#useSpotId').val(1);
    $('#spotId').val(spotId);
    $('#isDistrict').val(isDistrict);
    $('#inputString').addClass('mark');
}

function selectService(serviceId) {
    $('#useServiceId').val(1);
    $('#serviceId').val(serviceId);
    $('#serviceName').addClass('mark');
    
    // pobieranie przodkow wybranej uslugi (w drzewie uslug)
    var path = getServiceAncestors(serviceId);
    // ustawienie ciastka z identyfikatorami rozwinietych uslug
    setOpenedNodePathCookie(path);
}

function testUseSpotId() {
    if ($('#dont_test').val() == 1) {
        $('#dont_test').val(0);
    } else {
        var useSpotId = $('#useSpotId').val();
        if(useSpotId != 1) {
            $('#spotId').val(0);
            if ($('#autocompleterSelection').length) {
                $('#autocompleterSelection').html('');
            }
        } else {
            $('#useSpotId').val(0);
            $('#inputString').removeClass('mark');
        }
    }
}

function testUseServiceId() {
    if ($('#dont_test').val() == 1) {
        $('#dont_test').val(0);
    } else {
        var useServiceId = $('#useServiceId').val();
        if(useServiceId != 1) {
            $('#serviceId').val(0);
            if ($('#autocompleterSelection').length) {
                $('#autocompleterSelection').html('');
            }
        } else {
            $('#useServiceId').val(0);
            $('#serviceName').removeClass('mark');
        }
    }
}

function setSuggestionsPosition(className) {
    $('#suggestions').removeClass();
    $('#suggestions').addClass('suggestionsBox');
    $('#suggestions').addClass(className);
}
