
/******************************************************************************/
/**                                                                          **/
/**                               Search panel                               **/
/**                                                                          **/

(function($) {

//------------------------------------------------------------------------------
// constructor (must be before the public functions) ---------------------------
//------------------------------------------------------------------------------

jQuery.searchPanel = {
    
    parametersAndFields: {
        'default': {
            string: {
                cg: 'categoryGroup',
                ca: 'categories',
                pf: 'priceFrom',
                pt: 'priceTo',
                pro: 'cmbProvinces',
                ci: 'city',
                pc: 'postcode',
                ad: 'address',
//                la: 'latitude',
//                lo: 'longitude',
                at: 'cmbAdTypes',
                ip: 'cmbInsertedPeriods',
                ob: 'cmbOrderBy',
                kw: 'keywords'
            },
            checkbox: {
                op: 'onlyWithPhoto'
            },
//            address: {
//                pro: 'cmbProvinces',
//                ci: 'city',
//                pc: 'postcode'
//            },
            latLng: {
                la: 'latitude',
                lo: 'longitude'
            }
        },
        // 1 -> real state
        1: {
            string: {
                m2: 'cmbM2RealState'
            },
            pri: 'privateRealState',
            an: 'agencyNameRealState'
        },
        // 2 -> housing
        2: {
            string: {
                m2: 'cmbM2Housing',
                be: 'cmbBedrooms',
                ha: 'cmbHousingAge',
                fl: 'cmbFloor',
                ba: 'cmbBathrooms',
                m2p: 'cmbM2Plot',
                co: 'cmbCondition',
                fu: 'cmbFurnished',
                or: 'cmbOrientation',
                br: 'cmbBrightness'
            },
            checkbox: {
                el: 'elevator',
                pa: 'parking',
                lr: 'lumberRoom',
                te: 'terrace',
                ga: 'garden',
                sp: 'swimmingPool',
                ex: 'exterior',
                he: 'heating',
                ac: 'airConditioning',
                cm: 'closeToMetro',
                cb: 'closeToBus',
                ct: 'closeToTrain',
                qz: 'quietZone',
                nb: 'nextToBeach',
                nm: 'nextToMountains',
                pe: 'pets',
                ns: 'nonSmoker'
            },
            pri: 'privateHousing',
            an: 'agencyNameHousing'
        }, // 2 -> housing
        // 3 -> motor
        3: {
            string: {
                ye: 'cmbYears',
                km: 'cmbKms',
                ft: 'cmbFuelTypes',
                po: 'cmbPower',
                bt: 'cmbBodyTypes',
                co: 'cmbColors'
            }
        },
        // 17 -> dating
        17: {
            string: {
                af: 'ageFrom',
                at: 'ageTo'
            },
            ps: [
                'normal', 'pop', 'fiesta', 'techno', 'industrial', 'visual', 'goth',
                'metal', 'rock', 'punk', 'hippie', 'hipHop', 'sport', 'other'
            ]
        }
    }
};

//------------------------------------------------------------------------------
// public functions ------------------------------------------------------------
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------

jQuery.searchPanel.initializeSearchPanel = function() {

    // submit the search if the enter key is pressed on a search field.
    // The event is not set for the selects (drop down lists) or it will
    // not be possible to select a value with the keyboard
    $('.searchPanel input')
        .keypress($.globalFunctions.submitIfEnter);

    $('.searchPanel input:text').attr('maxlength', '50');

    $('.searchPanel .selectedCategories')
        .displayEmptyElementText(
            $.messages.altTitleCaption.noSelectedCategories
        )
        .change( function() {
            var $this = $(this);
//            $.categoryMenu.toggleFeaturesAndAdTypes({
            $.categoryMenu.adjustFormToCategory({
                containerElementClass: 'searchPanel',
                categoryGroupId: $this.attr('categoryGroupId'),
                categoryId: $this.attr('categoryId')
            });
        })
        .change();

    // NOTE: This initialization must be the first one, or the latitude
    //       and longitude fields will be wrongly emptied.
    $.globalFunctions.disablingPair(
        $('.searchPanel #city, .searchPanel #postcode'),
        $('.searchPanel #address'),
        'cityAndPostcodeNotTyped'
    );

    // the "geolocated" attribute is removed from the search panel if the
    // address is changed, so that it can be renognised when the previous
    // searched addressv has not been changed, and thus it is not geolocated
    // again
    $('#address, #city, #postcode, #cmbProvinces').change(function() {
//        $('#latitude').val('');
//        $('#longitude').val('');
//        $('#address').attr('geolocated', 'false');
        $('#address').removeAttr('geolocated');
    });

};

//------------------------------------------------------------------------------
/**
 * Submit the search once the searched address is geolocated.
 */
jQuery.searchPanel.handleSubmitSearch = function() {

//        var $addressSearch = $('#addressSearch');

    // If both latitude and longitude are set, no geolocation is performed,
    // as it means that the previous searched address has not been
    // changed, and it is not geolocated again.
    // If a new address is introduced, it must be geolocated before
    // submitting the search in order to get the items next to it on the
    // server side.
//        if ((( ! $('#latitudeSearch').sanitizedValue())
//                    || ( ! $('#longitudeSearch').sanitizedValue()))
//                && ( ! $addressSearch.is('.disabled'))
//                && $addressSearch.sanitizedValue())
//        {
//            var completeAddress =
//                $addressSearch.sanitizedValue()
//                + ', ' + $('#cmbProvincesSearch :selected').text()
//                + ', ' + $('#cmbProvincesSearch').attr('country');
//
//            $.mapFunctions.getLatLngAndSubmitSearch(completeAddress);
//        }
//        else {
//            $.globalFunctions.submitSearch();
//        }

    var errorMessageKey = $.searchPanel.validate();

    if ( ! errorMessageKey) {

        var $address = $('#address');

        // If both latitude and longitude are set, no geolocation is performed,
        // as it means that the previous searched address has not been
        // changed, and it is not geolocated again.
        // If a new address is introduced, it must be geolocated before
        // submitting the search in order to get the items next to it on the
        // server side.
//        if ((( ! $('#latitude').sanitizedValue())
//                    || ( ! $('#longitude').sanitizedValue()))
//                && ( ! $address.is('.disabled'))
//                && $address.sanitizedValue())
        // Note: if (geolocate -> validation)
//        if ($address.attr('geolocate') && ( ! $address.attr('geolocated'))
//                && ( ! $address.is('.disabled')) && $address.sanitizedValue()
//                && ( ! $address.is('.disabled'))
//                &&( $('#city').sanitizedValue() || $('#postcode').sanitizedValue()))
//                || ($('#cmbProvinces :selected').text()))
//        {

        // the "geolocated" attribute is removed from the search panel if the
        // address is changed, so that it can be renognised when the previous
        // searched addressv has not been changed, and thus it is not geolocated
        // again
        // the geolocation is only performed if there is city or postcode
        // (required if there is address) and it is not already geolocated.
        // If there is only province, no geolocation is performed
        // It may also happen that the location is geolocated but the category
        // was changed to anyone that doesn't have the geolocation feature
        if ($address.attr('geolocate') && ( ! $address.attr('geolocated'))
            && ($('#city').sanitizedValue() || $('#postcode').sanitizedValue()))
        {
            // the first blank space is to be able to remove the first comma
            // if the address is empty
            var completeAddress =
                ' ' + $address.sanitizedValue()
                + ', ' + $('#city').sanitizedValue()
                + ', ' + $('#postcode').sanitizedValue()
                + ', ' + $('#cmbProvinces :selected').text()
                + ', ' + $('#cmbProvinces').attr('country');

            // remove the empty elements, which are represented with a blank
            // space and a comma
            completeAddress = $.trim(completeAddress.replace(/ ,/g, ''));

            $.mapFunctions.getLatLngAndSubmitSearch(completeAddress);
        }
        else {
//            $address.attr('geolocated', 'false');
//            $address.removeAttr('geolocated');
            $.searchPanel.submitSearch();
        }
    }
    else {

        var settings = {
//            dialogBoxId: 'noSearchCategorySelected',
            scrollToTop: false,
            title: $.messages.dialog.titles.searchNoValidated,
            message: $.messages.dialog.messages[errorMessageKey],
            buttons: $.configuration.dialog.buttons.ok,
            width: 350
        };

        $.globalFunctions.dialogOpen(settings);
    }
};

//------------------------------------------------------------------------------
/**
 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 */
jQuery.searchPanel.validate = function() {

    var errorMessageKey = '';

    var categoryMenuId = $.categoryMenu.getCategoryGroupId('.searchPanel');

    if ( ! categoryMenuId || ! $.categoryMenu.getSelectedCategoryIds('.searchPanel')) {
        errorMessageKey = 'noSearchCategorySelected';
    }
    else {

        var value1 = $('#priceFrom').sanitizedValue();
        var value2 = $('#priceTo').sanitizedValue();

        if (isNaN(value1) || isNaN(value2)) {
            errorMessageKey = 'priceNoNumber';
        }
        else if (value1 && value2 && (value1 > value2)) {
            errorMessageKey = 'priceFromGreaterThanPriceTo';
        }
        // 1 -> real state
        // 2 -> housing
        else if ((categoryMenuId == 1) || (categoryMenuId == 2)) {

            // city OR postcode must be indicated to get the complete address
            value1 = $('#city').sanitizedValue() + $('#postcode').sanitizedValue();

//            if ($('#address:not(.disabled)').sanitizedValue()
//                && ( ! $('#cmbProvinces').sanitizedValue() || ! value1))
//            {
//                errorMessageKey = 'addressNotComplete';
//            }
            if (value1 && ! $('#cmbProvinces').sanitizedValue())
            {
                errorMessageKey = 'mapNoValidLocation1';
            }
            else if ($('#address:not(.disabled)').sanitizedValue()
                && ( ! $('#cmbProvinces').sanitizedValue() || ! value1))
            {
                errorMessageKey = 'mapNoValidLocation2';
            }
        }
        // 17 -> dating
        else if (categoryMenuId == 17) {

            value1 = $('#ageFrom').sanitizedValue();
            value2 = $('#ageTo').sanitizedValue();

            if (isNaN(value1) || isNaN(value2)) {
                errorMessageKey = 'ageNoNumber';
            }
            else if (value1 && value2 && (value1 > value2)) {
                errorMessageKey = 'ageFromGreaterThanAgeTo';
            }
        }
    }

    return errorMessageKey;
};

//------------------------------------------------------------------------------
/**
 * Create and call an url with the search values.
 */
jQuery.searchPanel.submitSearch = function() {

    var parameters = '';
//    var sanitizedValue = '';

    parameters = handleCategoryParameters();

    // ad categories of different category groups cannot be displayed together,
    // so if no category is selected, an error message is shown
    if ( ! parameters) {

        var settings = {
            dialogBoxId: 'noSearchCategorySelected',
            scrollToTop: true,
            title: $.messages.dialog.titles.noSearchCategorySelected,
            message: $.messages.dialog.messages.noSearchCategorySelected,
            buttons: $.configuration.dialog.buttons.ok,
            width: 300
        };

        $.globalFunctions.dialogOpen(settings);

    }
    else {

        parameters += getSanitizedParameters(
            $.searchPanel.parametersAndFields['default'].string
        );
        parameters += getCheckboxParameters(
            $.searchPanel.parametersAndFields['default'].checkbox
        );

//        if ($('#address').attr('geolocated') == 'true') {
        if ($('#address').attr('geolocated')) {
//        if ($('#address').attr('geolocate') && $('#address').attr('geolocated')) {
            parameters += getSanitizedParameters(
                $.searchPanel.parametersAndFields['default'].latLng
            );
        }
//        else {
//            parameters += getSanitizedParameters(
//                $.searchPanel.parametersAndFields['default'].address
//            );
//        }
    //    parameters += getSanitizedParameters({
    //        pf: 'priceFrom',
    //        pt: 'priceTo',
    //        pr: 'cmbProvinces',
    //        ci: 'city',
    //        pc: 'postcode',
    //        at: 'cmbAdTypes',
    //        ip: 'cmbInsertedPeriods',
    //        lw: 'keywords'
    //    });
    //
    //    parameters += getCheckboxParameters( { op: 'onlyWithPhoto' } );




    //    sanitizedValue = $('#priceFrom').sanitizedValue();
    //    if (sanitizedValue) {
    //        parameters += "&pf=" + sanitizedValue;
    //    }
    //    sanitizedValue = $('#priceTo').sanitizedValue();
    //    if (sanitizedValue) {
    //        parameters += "&pt=" + sanitizedValue;
    //    }
    //
    //    sanitizedValue = $('#cmbProvincesSearch').sanitizedValue();
    //    if (sanitizedValue) {
    //        parameters += "&pr=" + sanitizedValue;
    //    }
    //    sanitizedValue = $('#citySearch').sanitizedValue();
    //    if (sanitizedValue) {
    //        parameters += "&ct=" + sanitizedValue;
    //    }
    //    sanitizedValue = $('#postcodeSearch').sanitizedValue();
    //    if (sanitizedValue) {
    //        parameters += "&pc=" + sanitizedValue;
    //    }

    //    if ($('#onlyWithPhoto').attr('checked')) {
    //        parameters += "&op=true";
    //        parameters += "&op";
    //    }

    //    parameters += getCheckboxParameters( { op: 'onlyWithPhoto' } );
    //
    //    sanitizedValue = $('#cmbAdTypes').sanitizedValue();
    //    if (sanitizedValue) {
    //        parameters += "&at=" + sanitizedValue;
    //    }
    //
    //    sanitizedValue = $('#cmbInsertedPeriods').sanitizedValue();
    //    if (sanitizedValue) {
    //        parameters += "&ip=" + sanitizedValue;
    //    }

    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    //    sanitizedValue = $('#cmbOrderBy').sanitizedValue();
    //    // 2 is the default value, "date descending"
    //    if (sanitizedValue && sanitizedValue != 2) {
    //        parameters += "&ob=" + sanitizedValue;
    //    }

    //    sanitizedValue = $('#keywords').sanitizedValue();
    //    if (sanitizedValue) {
    //        parameters += "&kw=" + sanitizedValue;
    //    }

        var url = $.configuration.url.domain;

        if (parameters) {
            // remove the initial '&'
            parameters = parameters.substr(1);
            url = $.configuration.url.ads + parameters;
        }
//    console.info(url);
        location.assign(url);
    }
};

//------------------------------------------------------------------------------

jQuery.searchPanel.cleanSearch = function() {
    // the change event is fired to display the text when the element is
    // empty
    $('.searchPanel .selectedCategories')
        .html('')
        .removeAttr('categoryGroupId')
        .change();
    $('.searchPanel input, .searchPanel select').val('');
    // '2' ('insert date desc') is the default value for the order drop
    // down list
    $('.searchPanel select#cmbOrderBy').val('2');
    $('.searchPanel input:checkbox').removeAttr('checked').change();
};

//------------------------------------------------------------------------------
// private functions -----------------------------------------------------------
//------------------------------------------------------------------------------

function handleCategoryParameters() {

    var parameters = '';

    var categoryGroupId = $.categoryMenu.getCategoryGroupId('.searchPanel');

    if (categoryGroupId) {

        parameters += '&cg=' + categoryGroupId;

        var selectedCategoryIds =
            $.categoryMenu.getSelectedCategoryIds('.searchPanel').join(',');

        if (selectedCategoryIds) {
            parameters += '&ca=' + selectedCategoryIds;
        }

//        if ($.searchPanel.parametersAndFields[categoryGroupId]) {
//            parameters += getSanitizedParameters(
//                $.searchPanel.parametersAndFields[categoryGroupId].string
//            );
//            parameters += getCheckboxParameters(
//                $.searchPanel.parametersAndFields[categoryGroupId].checkbox
//            );
//        }

        var sanitizedValue

        if (categoryGroupId == 1) {

            parameters += getSanitizedParameters($.searchPanel.parametersAndFields[1].string);

            // if the ad is from a private advertiser, the agency name is not retrieved
            if ($('#' + $.searchPanel.parametersAndFields[1].pri).is(':checked')) {
                parameters += '&pri';
            }
            else {
                sanitizedValue =
                    $('#' + $.searchPanel.parametersAndFields[1].an).sanitizedValue();
                if (sanitizedValue) {
                    parameters += "&an=" + sanitizedValue;
                }
            }
        }
        else if (categoryGroupId == 2) {
//            parameters += getHousingParameters();

            parameters += getSanitizedParameters($.searchPanel.parametersAndFields[2].string);

            parameters += getCheckboxParameters($.searchPanel.parametersAndFields[2].checkbox);

            // if the ad is from a private advertiser, the agency name is not retrieved
            if ($('#' + $.searchPanel.parametersAndFields[2].pri).is(':checked')) {
                parameters += '&pri';
            }
            else {
                sanitizedValue =
                    $('#' + $.searchPanel.parametersAndFields[2].an).sanitizedValue();
                if (sanitizedValue) {
                    parameters += "&an=" + sanitizedValue;
                }
            }
        }
        else if (categoryGroupId == 3) {

            parameters += getSanitizedParameters($.searchPanel.parametersAndFields[3].string);

        }
        else if (categoryGroupId == 17) {

            parameters += getSanitizedParameters($.searchPanel.parametersAndFields[17].string);
            
            parameters += getChainedParameter('ps', $.searchPanel.parametersAndFields[17].ps);

        }
    }

    return parameters;
};

//------------------------------------------------------------------------------

function getHousingParameters() {

    var parameters = '';
//    var sanitizedValue = '';

//    sanitizedValue = $('#m2Search').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&m2=" + sanitizedValue;
//    }
//    sanitizedValue = $('#bedroomsSearch').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&be=" + sanitizedValue;
//    }
//    sanitizedValue = $('#housingAge').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&ha=" + sanitizedValue;
//    }
//    if ($('#private').attr('checked')) {
//        parameters += "&p=true";
//    }
//    else {
//        sanitizedValue = $('#agencyName').sanitizedValue();
//        if (sanitizedValue) {
//            parameters += "&an=" + sanitizedValue;
//        }
//    }
//    sanitizedValue = $('#floorSearch').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&fl=" + sanitizedValue;
//    }
//    sanitizedValue = $('#bathroomsSearch').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&ba=" + sanitizedValue;
//    }
//    sanitizedValue = $('#m2PlotSearch').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&m2p=" + sanitizedValue;
//    }
//    sanitizedValue = $('#condition').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&co=" + sanitizedValue;
//    }
//    sanitizedValue = $('#furnished').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&fu=" + sanitizedValue;
//    }
//    sanitizedValue = $('#orientation').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&or=" + sanitizedValue;
//    }
//    sanitizedValue = $('#brightness').sanitizedValue();
//    if (sanitizedValue) {
//        parameters += "&br=" + sanitizedValue;
//    }
//
//    parameters = getSanitizedParameters({
////        m2: 'm2HousingSearch',
////        be: 'bedroomsSearch',
////        ha: 'housingAge',
////        an: 'agencyName',
////        fl: 'floorSearch',
////        ba: 'bathroomsSearch',
////        m2p: 'm2PlotSearch',
////        co: 'condition',
////        fu: 'furnished',
////        or: 'orientation',
////        br: 'brightness'
//        m2: 'cmbM2Housing',
//        be: 'cmbBedrooms',
//        ha: 'cmbHousingAge',
//        an: 'agencyName',
//        fl: 'cmbFloor',
//        ba: 'cmbBathrooms',
//        m2p: 'cmbM2Plot',
//        co: 'cmbCondition',
//        fu: 'cmbFurnished',
//        or: 'cmbOrientation',
//        br: 'cmbBrightness'
//    });
//
//    parameters += getCheckboxParameters( {
//        pr: 'private',
//        el: 'elevator',
//        pa: 'parking',
//        lr: 'lumberRoom',
//        te: 'terrace',
//        ga: 'garden',
//        sp: 'swimmingPool',
//        ex: 'exterior',
//        he: 'heating',
//        ac: 'airConditioning',
//        cm: 'closeToMetro',
//        cb: 'closeToBus',
//        ct: 'closeToTrain',
//        qz: 'quietZone',
//        nb: 'nextToBeach',
//        nm: 'nextToMountains',
//        pe: 'pets',
//        ns: 'nonSmoker'
//    } );
    
    
//    if ($('#elevator').attr('checked')) {
//        parameters += "&el=true";
//    }
//    if ($('#parking').attr('checked')) {
//        parameters += "&pa=true";
//    }
//    if ($('#lumberRoom').attr('checked')) {
//        parameters += "&lr=true";
//    }
//    if ($('#terrace').attr('checked')) {
//        parameters += "&te=true";
//    }
//    if ($('#garden').attr('checked')) {
//        parameters += "&ga=true";
//    }
//    if ($('#swimmingPool').attr('checked')) {
//        parameters += "&sp=true";
//    }
//    if ($('#exterior').attr('checked')) {
//        parameters += "&ex=true";
//    }
//    if ($('#heating').attr('checked')) {
//        parameters += "&he=true";
//    }
//    if ($('#airConditioning').attr('checked')) {
//        parameters += "&ac=true";
//    }
//    if ($('#closeToMetro').attr('checked')) {
//        parameters += "&cm=true";
//    }
//    if ($('#closeToBus').attr('checked')) {
//        parameters += "&cb=true";
//    }
//    if ($('#closeToTrain').attr('checked')) {
//        parameters += "&ct=true";
//    }
//    if ($('#quietZone').attr('checked')) {
//        parameters += "&qz=true";
//    }
//    if ($('#nextToBeach').attr('checked')) {
//        parameters += "&nb=true";
//    }
//    if ($('#nextToMountains').attr('checked')) {
//        parameters += "&nm=true";
//    }
//    if ($('#pets').attr('checked')) {
//        parameters += "&pe=true";
//    }
//    if ($('#nonSmoker').attr('checked')) {
//        parameters += "&ns=true";
//    }

//console.info($.configuration.parameters);
//console.info($.configuration.parameters[2]);
//console.info($.configuration.parameters[2].string);

    if ($.searchPanel.parametersAndFields[2]) {
        
        parameters += getSanitizedParameters($.searchPanel.parametersAndFields[2].string);

        parameters += getCheckboxParameters($.searchPanel.parametersAndFields[2].checkbox);

        if ($('#' + $.searchPanel.parametersAndFields[2].pri).is(':checked')) {
            parameters += '&pri';
        }
        else {
            var sanitizedValue =
                $('#' + $.searchPanel.parametersAndFields[2].an).sanitizedValue();
            if (sanitizedValue) {
                parameters += "&an=" + sanitizedValue;
            }
        }
    }
//console.info(parameters);
    return parameters;
};

//------------------------------------------------------------------------------
/**
 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 */
function getSanitizedParameters(parametersAndFields) {

    var parameters = '';
    var sanitizedValue = '';

    for (parameter in parametersAndFields) {
        sanitizedValue = $('#' + parametersAndFields[parameter]).sanitizedValue();
        if (sanitizedValue) {
            parameters += '&' + parameter + '=' + sanitizedValue;
        }
    }

    return parameters;
};

//------------------------------------------------------------------------------
/**
 * XXXXXXXXXXXXXXXXXXXXXXXXX
 */
//function getSanitizedParametersByValue(parameters, values) {
//
//    for (valueId in values) {
//        if (values[valueId]) {
//            parameters[valueId] = $.globalFunctions.sanitize(values[valueId]);
//        }
//    }
//
//    return parameters;
//};

//------------------------------------------------------------------------------
/**
 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 */
function getCheckboxParameters(parameterAndFields) {

    var parameters = '';
    
    for (parameter in parameterAndFields) {
//        if ($('#' + parameterAndFields[parameter] + ':checked').length) {
        if ($('#' + parameterAndFields[parameter]).is(':checked')) {
            parameters += '&' + parameter;
        }
    }

    return parameters;
};

//------------------------------------------------------------------------------
/**
 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 * 1 so that it can be treated as numeric
 */
function getChainedParameter(parameterName, elementIds) {

    var parameter = '';

    var values = [];

    for (elementId in elementIds) {
        if ($('#' + elementIds[elementId] + ':checked').length) {
            values.push($('#' + elementIds[elementId]).sanitizedValue());
        }
    }

    if (values) {
        parameter = '&' + parameterName + '=' + values.join(',');
    }

    return parameter;
};

//------------------------------------------------------------------------------

})(jQuery);

/**                                                                          **/
/**                               Search panel                               **/
/**                                                                          **/
/******************************************************************************/


