
var uzAjaxFilter = {
    debug: 0,
    debugBox: "uz_debug",
    langData: "ru",
    frontBaseHref: "",
    dataSource: "uz_es_filter_resp.php",

    aMatchPatterns: {
        "process": "Matched <img src='_img/uz_request_indicator.gif'> products",
        "process1": "Matched @@cnt@@ product",
        "process2": "Matched @@cnt@@ products",
        "process5": "Matched @@cnt@@ products"
    },
    matchedBoxClassName: "uz_matched_cnt_box",

    //hideEmpty: true,
    //autoSubmit: false,

    optionsDisableMethod: "erase", //disable|erase

    aFields: [], // Filter fields names
    /*
    {
        name: '',
        type: '',   // select|checkbox|radio|text|interval|val_from|val_to
        multi: '##multiple##'
        val: '',
        defaultVal: 'text',0
        defaultDisabled: false, // true|false
    }
    //*/

    //aDefaultFieldsDisabledStatus: {},

    defaultDisplay: "inline",

    //selectCatSupport: 0,
    //catSelectId: "select_cat_id",
    //scriptLink: "",
    //currentCatId: 0,
    //aCatsSublinks: new Array(),

    filterFormName: "",
    oForm: null,


    // Requests number
    requestId: 0,

    // Requests queue
    aRequests: [],


    // Style for disabled elements
    disabledClass: "uz_es_filter_label_disabled",

    // Class name for hide field values box
    hideValuesClass: "uz_filter_box_vals_hidden",
    // Field values box id postfix
    fieldValuesBoxIdPostfix: "_vals_box",


    intervalObjectIdPostfix: "_interval_slider",



    //
    // Init section
    //

    init: function(hOpt){

        // Detect domain
        this.frontBaseHref = "http://"+document.domain+"/";

        //
        // Set default form name
        //
        if(typeof(_cms_document_form) != 'undefined'){
            this.filterFormName= _cms_document_form;
        }

        // Set options
        if(typeof(hOpt) != 'undefined'){
            this.setOptions(hOpt);
        }

        //alert(uzAjaxFilter.toString(hOpt.aFields));
        //alert(uzAjaxFilter.toString(this.aFields));


        // Enable debug by ip
        if(typeof(DEBUG_BY_IP) != 'undefined'){
            if(DEBUG_BY_IP == 1){
                this.debug = 1;
            }
        }

        //
        // Get form object
        //
        if(typeof(document.forms[this.filterFormName]) != 'undefined'){
            this.oForm = document.forms[this.filterFormName];
        }

        //
        // Init fields current values
        //
        this.initFieldsSate();

        this.onLoadShowFieldsValues();
        //this.getFieldsDefaultDisabled();

        //if(this.selectCatSupport){
        //    this.initCurrentCat();
        //}

        //
        // Set messages handlers
        //
        if(typeof(AMI) != 'undefined'){
            if(typeof(AMI.Message) != 'undefined'){
                AMI.Message.addListener("filter_field_changed", uzAjaxFilter.onMessageFilterFieldChanged);
                AMI.Message.addListener("filter_field_caption_click", uzAjaxFilter.onMessageFilterFieldCaptionClick);
                AMI.Message.addListener("filter_field_caption_desc_click", uzAjaxFilter.onMessageFilterFieldCaptionDescClick);
                AMI.Message.addListener("filter_field_interval_change", uzAjaxFilter.onMessageFilterFieldIntervalChange);
            }
        }        



        //
        // On load - get data and populate fields
        //
        this.onFieldChange(false);

    },

    setOptions: function(opt){
        for(var key in opt){
            this[key] = opt[key];
        }
    },

    initFieldsSate: function(){
        if(this.oForm != null && this.aFields.length){
            var i, val;
            //alert(this.toString(this.aFields));
            for(i = 0; i < this.aFields.length; i++){
                //var name = this.aFields[i].formName;
                //name = name.replace(/\[\]/, '');
                //this.aFields[i].name = name;
                this.aFields[i].defaultVal = this.getFieldValue(this.aFields[i].formName);
            }
        }
        //alert(this.toString(this.aFields));
    },

    //
    // Init section end
    //



    //
    // Request data section
    //

    onMessageFilterFieldChanged: function(isManualChange, p2){
        uzAjaxFilter.onFieldChange(isManualChange);
        return true;
    },

    onFieldChange: function(isManualChange){
        //
        // Prevent request if form is missing or have no fields
        //
        if(this.oForm == null || this.aFields.length == 0){
            return true;
        }

        /*
        if(typeof(isManualChange) != 'undefined'){
            if(isManualChange == 1){
                if(this.autoSubmit){
                    if(typeof(CheckFilterForms) != 'undefined'){
                        CheckFilterForms(this.oForm, 0);
                    }
                    return;
                }
            }
        }
        //*/

        //
        // Prepare request data
        //
        var hRequest = {};

        //
        // Prepare subpath
        //
        var aTmp = active_module_link.split('?');
        var subpath = aTmp[0].substr(this.frontBaseHref.length);
        hRequest["subpath"] = subpath;

        // Prepare search subcats flag
        var searchSubCats = 1;
        if(document.getElementById("flt_search_subcats")){
            if(document.getElementById("flt_search_subcats").checked){
                searchSubCats = 1;
            } else {
                searchSubCats = 0;
            }
        }
        hRequest["search_subcats"] = searchSubCats;

        // Prepare category id
        var catId = 20000;
        if(typeof(this.oForm.catid) != 'undefined'){
            // Apply selected cat
            if(this.selectCatSupport && document.getElementById(this.catSelectId)){
                catId = document.getElementById(this.catSelectId).value;
                this.oForm.catid.value = catId;
            } else {
                catId = this.oForm.catid.value;
            }
        }
        hRequest["catid"] = catId;

        // Set submit url to selected category
        this.setForcedSubmitUrl(catId);

        // Reset other fields when category changed
        var forceEmptyVals = 0;
        /*
        if(this.selectCatSupport && this.currentCatId != catId){
            forceEmptyVals = 1;
            // Store new cat id
            this.currentCatId = catId;
        }
        //*/

        //alert(uzAjaxFilter.toString(this.aFields));

        // Collect actual fields values from form
        if(this.aFields.length){
            for(var i = 0; i < this.aFields.length; i++){
                if(forceEmptyVals){
                    hRequest[this.aFields[i].name] = "";
                } else {
                    //alert(this.toString(this.aFields));
                    hRequest[this.aFields[i].name] = this.getFieldValue(this.aFields[i].formName);

                    /*
                    this.oForm.elements[this.aFields[i].name]
                    switch(this.aFields[i].type){
                        case "select":
                            if(this.aFields[i].multi == ''){
                                urlParams += "&"+this.aFields[i].name+"="+encodeURIComponent(this.oForm.elements[this.aFields[i].name].value);
                            } else {
                                var oSel = this.oForm.elements[this.aFields[i].name];
                                for(var j = 0; j < oSel.options.length; j++){
                                    if(oSel.options[j].selected && oSel.options[j].style.display != "none"){
                                        urlParams += "&"+this.aFields[i].name+"="+encodeURIComponent(oSel.options[j].value);
                                        //alert("multiselect add val "+this.aFields[i].name+"="+oSel.options[j].value);
                                        //alert(urlParams);
                                    }
                                }
                            }
                            break;
                        case "checkbox":
                            if(this.aFields[i].name.indexOf("[]") <= 0){
                                // Single checkbox
                                val = (this.oForm.elements[this.aFields[i].name].checked) ? 1 : 0;
                                urlParams += "&"+this.aFields[i].name+"="+val;
                            } else {
                                var j = 0;
                                var cName = "chk_"+this.aFields[i].name+"_";
                                while(document.getElementById(cName+j)){
                                    if(document.getElementById(cName+j).checked){
                                        urlParams += "&"+this.aFields[i].name+"="+encodeURIComponent(document.getElementById(cName+j).value);
                                    }
                                    j++;
                                }
                            }
                            break;
                        case "radio":
                            var j = 0;
                            var cName = "rd_"+this.aFields[i].name+"_";
                            while(document.getElementById(cName+j)){
                                if(document.getElementById(cName+j).checked){
                                    urlParams += "&"+this.aFields[i].name+"="+encodeURIComponent(document.getElementById(cName+j).value);
                                }
                                j++;
                            }
                            break;
                        case "price_from":
                            urlParams += "&"+this.aFields[i].name+"="+encodeURIComponent(this.oForm.elements[this.aFields[i].name].value);
                            break;
                        case "price_to":
                            urlParams += "&"+this.aFields[i].name+"="+encodeURIComponent(this.oForm.elements[this.aFields[i].name].value);
                            break;
                        case "text":
                            urlParams += "&"+this.aFields[i].name+"="+encodeURIComponent(this.oForm.elements[this.aFields[i].name].value);
                            break;
                        default:
                            break;
                    }
                    //*/
                }
            }
        }

/*        
        var subpath;

        if(aTmp.length > 1){
            filters = aTmp[1];
            // Parse url params
            var hParams = uzAjaxStuff.parseUrlParams(filters);

            // Strip action
            if(typeof(hParams.action) != 'undefined'){
                delete(hParams.action);
            }

            // Prepare url params
            filters = uzAjaxStuff.prepareUrlParams(hParams);

            if(this.debug){
                //alert("filters orig = '"+aTmp[1]+"'\n\nfilters prepared = '"+filters+"'");
                //alert(urlParams);
            }

        }
        var urlParams = "&subpath=" + subpath + filters;

        if(this.debug){
            //alert(subpath+", filters = "+filters);
            //alert(urlParams);
        }
  //*/  

        //var fieldsList = this.getFieldsList();
        hRequest["fields_list"] = this.aFields;

        this.populateMatchedCount();

        this.disableFields();

        this.requestData(hRequest);
    },

    requestData: function(hData) {
        var urlParams = "";

        //urlParams += this.prepareUrlParams(hData);

        //
        // Erase form field names from request
        //
        hDataTmp = this.cloneObject(hData);
        if(hDataTmp["fields_list"].length){
            for(var i =0; i < hDataTmp["fields_list"].length; i++){
                hDataTmp["fields_list"][i].formName = "";
            }
        }
        //alert(this.toString(hDataTmp));

        //alert(urlParams);
        /*
        for(name in hData){
            if(name == "plainUrlParams"){
                urlParams += hData[name];
            } else {
                urlParams += "&" + name + "=" + hData[name];
            }
        }
        //*/

        // Increment id
        this.requestId++;

        // Prepare request data
        var hRequest = {
            id: this.requestId,
            lang_data: this.langData,
            data: this.toJsonString(hDataTmp)
        }
        //alert(hRequest.data);
        //alert(this.frontBaseHref + this.dataSource+"\n\n");

        if(typeof(AMI) != 'undefined'){
            if(typeof(AMI.Message) != 'undefined'){
                AMI.Message.send("uz_on_filter_request", hRequest, false);
            }
        }

        jQuery.ajax({
            type: "GET",
            cache: false,
            async: true,
            url: this.frontBaseHref + this.dataSource,
            data: hRequest,
            dataType: "json",
            success: uzAjaxFilter.requestCbSuccess,
            error: uzAjaxFilter.requestCbError
        });
    },

    requestCbSuccess: function(content) {
        //alert("requestCbSuccess");
        uzAjaxFilter.precessResponse(content);
    },

    requestCbError: function(event, jqXHR, ajaxSettings){
        //this.actionProcess = 0;
        //alert("requestCbError\n\n");
        //alert("event: "+uzAjaxFilter.toString(event)+"\n\n");
        //alert("jqXHR: "+uzAjaxFilter.toString(jqXHR)+"\n\n");
        //alert("ajaxSettings: "+uzAjaxFilter.toString(ajaxSettings)+"\n\n");
    },

    precessResponse: function(hResp){
        //this.actionProcess = 0;
        //var hResp = AMI.String.decodeJSON(content);
        if(this.debug && typeof(hResp.debug) != 'undefined'){
            if(document.getElementById(this.debugBox)){
                document.getElementById(this.debugBox).innerHTML = hResp.debug;
            }
        }
        //alert(this.toString(hResp.data));
        if(typeof(hResp.data.id) != 'undefined'){
            if(hResp.data.id == this.requestId){
                //alert(this.toString(hResp.data));
                this.applyFilterData(hResp.data);
            }
        }
        //alert(this.toString(content));
    },
    
    getFieldValue: function(name){
        var i, val;
        var res = '';

        if(this.oForm != null && this.aFields.length){
            for(i = 0; i < this.aFields.length; i++){
                if(this.aFields[i].formName == name){
                    //alert(this.aFields[i].formName+" == "+name);
                    switch(this.aFields[i].type){
                        //select|checkbox|radio|text|interval|val_from|val_to
                        case "checkbox":
                            //alert(this.aFields[i].formName);
                            if(this.aFields[i].formName.indexOf("[]") < 0){
                                //alert("Single checkbox");
                                // Single checkbox
                                res = (this.oForm.elements[name].checked) ? 1 : 0;
                            } else {
                                // Multi checkboxes
                                //alert("Multi checkboxes name = "+name+", flags cnt = "+this.aFields[i].flagsCnt);
                                var j = 0;
                                var cName = "chk_"+this.aFields[i].name+"_";
                                var res = [];
                                while(j <= this.aFields[i].flagsCnt){
                                    //alert("cName = "+cName);
                                    if(document.getElementById(cName+j)){
                                        if(document.getElementById(cName+j).checked){
                                            res.push(document.getElementById(cName+j).value);
                                        }
                                    }
                                    j++;
                                }
                            }
                            break;
                        case "radio":
                            var j = 0;
                            var cName = "rd_"+this.aFields[i].formName+"_";
                            while(document.getElementById(cName+j)){
                                if(document.getElementById(cName+j).checked){
                                    res = document.getElementById(cName+j).value;
                                }
                                j++;
                            }
                            break;
                        case "select":
                            if(this.aFields[i].multi == ''){
                                res = this.oForm.elements[name].value;
                            } else {
                                var oSel = this.oForm.elements[name];
                                var res = [];
                                for(var j = 0; j < oSel.options.length; j++){
                                    if(oSel.options[j].selected && oSel.options[j].style.display != "none"){
                                        res.push(oSel.options[j].value);
                                    }
                                }
                            }
                            break;
                        case "interval":
                            var res = [$("#"+this.aFields[i].name+"_from").val(), $("#"+this.aFields[i].name+"_to").val()];
                            break;
                        default:
                            res = this.oForm.elements[this.aFields[i].formName].value;
                            break;
                    }
                }
            }
        }
        return res;
    },

    //
    // Request data section end
    //




    getFieldProp: function(name) {
        if(this.aFields.length){
            for(var i = 0; i < this.aFields.length; i++){
                if(name == this.aFields[i].name){
                    return this.aFields[i];
                }
            }
        }
        return {};
    },

    applyFilterData: function(hResp) {
        if(this.debug){
            //alert(content);
            if(typeof(hResp.debug) != 'undefined'){
                if(hResp.debug.length){
                    //alert(hResp.debug);
                }
            }
        }

        //
        // Apply matched items count
        //
        this.populateMatchedCount(hResp.cnt);

        //
        // Apply fields data
        //
        if(typeof(hResp.fields_data) != 'undefined'){
            if(hResp.fields_data.length){
                for(var i = 0; i < hResp.fields_data.length; i++){
                    this.populateField(hResp.fields_data[i]);
                }
            }
        }

        this.enableFields();

    },

    populateMatchedCount: function(cnt) {
        var patternPostfix = '';
        var mod = cnt % 10;
        if(typeof(cnt) != 'undefined'){
            if(cnt == 0) {
                patternPostfix = 5;
            } else if (cnt == 1 || (cnt > 20 && mod == 1)) {
                patternPostfix = 1;
            } else if ((cnt >= 2 && cnt <= 4) ||(cnt > 20 && mod >= 2 && mod <= 4)) {
                patternPostfix = 2;
            } else {
                patternPostfix = 5;
            }
        } else {
            var cnt = -1;
        }
        this.applyMatchedCount("process"+patternPostfix, {cnt: cnt});
    },

    applyMatchedCount: function(patternName, hData) {
        var str = "";
        if(typeof(AMI) != 'undefined'){
            if(typeof(AMI.Template) != 'undefined' && typeof(this.aMatchPatterns[patternName]) != 'undefined'){
                str = AMI.Template.parse(this.aMatchPatterns[patternName], hData);
            }
        }
        $("."+this.matchedBoxClassName).html(str);
    },

    populateField: function(hData) {
        var name = hData.name;
        var hProp = this.getFieldProp(name);
        if(uzAjaxFilter.debug){
            //alert("populateField name="+name+", with prop "+this.toString(hProp)+"\n hData: "+this.toString(hData));
            //alert("populateField "+hProp.name+" - "+hProp.type);
        }
        if(typeof(hProp.type) != 'undefined'){
            switch(hProp.type){
                case "select":
                    if(typeof(hProp.multi) == 'undefined' || hProp.multi == ''){
                        this.populateSelect(hData);
                    } else {
                        this.populateSelectMulti(hData);
                    }
                    break;
                case "checkbox":
                    this.populateCheckbox(hData);
                    break;
                case "radio":
                    this.populateRadio(hData);
                    break;
                case "price_from":
                case "price_to":
                    this.populateText(hData);
                    break;
                case "text":
                    this.populateText(hData);
                    break;
                case "interval":
                    this.populateInterval(hData);
                    break;
                default:
                    break;
            }
        }
    },

    populateSelect: function(hData) {
        var hProp = this.getFieldProp(hData.name);
        var name = hProp.formName;
        var defaultVal = hData.selected_vals;
        var aVals = hData.exist_vals;

        if(this.debug){
            //alert("populate select, aVals = "+this.toString(aVals)+"\n defaultVal = "+defaultVal);
            //alert("populateField "+hProp.name+" - "+hProp.type);
        }

        var el = this.oForm.elements[name];

        var i, n;

        if(this.debug){
            //alert(data);
            //alert(name);
            //alert(aVals.length);
            //alert(aVals)
        }

        if(this.optionsDisableMethod == "erase"){
            // Drop old options
            n = el.length;
            //value = el.value;
            for(i=n-1; i>0; i--) {
                el.options[i] = null;
            }
            //alert("options erased");

            if(aVals.length){
                // Add new options
                for(i=0; i<aVals.length; i++) {
                    el.options[i+1] = new Option(aVals[i], aVals[i]);
                }
                el.value = defaultVal;
            
            } else {
                el.value = "";
            }
            //alert("options added");

        } else {

            for(i=1; i<el.length; i++) {
                
                var isExists = this.inArray(el.options[i].value, aVals) ? 1 : 0;
                /*
                if(aVals.length){
                    for(j=0; j<aVals.length; j++) {
                        //alert("aVals[j] = "+aVals[j]+", el.options[i].value = "+el.options[i].value);
                        if(aVals[j] == el.options[i].value){
                            isOn = true;
                        }
                    }
                }
                //*/

                if(isExists){
                    //alert(el.options[i].value+" is on");
                    //el.options[i].style.display = "";
                    el.options[i].disabled = false;
                } else {
                    //el.options[i].style.display = "none";
                    el.options[i].disabled = true;
                }
            }
        }

        if(aVals.length){
            // Show field
            if(document.getElementById("fld_box_"+name)){
                document.getElementById("fld_box_"+name).style.display = this.defaultDisplay;//"inline";
            }

        
        } else {
            el.value = "";

            // Hide field
            if(this.hideEmpty){
                if(document.getElementById("fld_box_"+name)){
                    document.getElementById("fld_box_"+name).style.display = "none";
                }
            }
        }

    },

    populateSelectMulti: function(hData) {
        var hProp = this.getFieldProp(hData.name);
        var name = hProp.formName;
        var aDefaultVals = hData.selected_vals;
        var aVals = hData.exist_vals;

        var el = this.oForm.elements[name];

        var i, n;

        if(uzAjaxFilter.debug){
            //alert(data);
            //alert(name);
            //alert(aVals.length);
            //alert(aVals)
        }

        /*
        if(this.optionsDisableMethod == "erase"){
            // Drop old options
            n = el.length;
            //value = el.value;
            for(i=n-1; i>0; i--) {
                el.options[i] = null;
            }

            if(aVals.length){
                // Add new options
                for(i=0; i<aVals.length; i++) {
                    el.options[i+1] = new Option(aVals[i], aVals[i]);
                    if(this.inArray(aVals[i], aDefaultVals)){
                        el.options[i+1].selected = true;
                        selectedCnt++;
                    }
                }
            }

        } else {
        //*/
            var selectedCnt = 0;

            for(i=1; i<el.length; i++) {

                isExists = this.inArray(el.options[i].value, aVals) ? 1 : 0;
                /*
                var isOn = false;
                if(aVals.length){
                    for(j=0; j<aVals.length; j++) {
                        if(aVals[j] == el.options[i].value){
                            isOn = true;
                        }
                    }
                }
                //*/
                if(isExists){
                    //el.options[i].style.display = "";
                    el.options[i].disabled = false;

                    if(el.options[i].selected){
                        selectedCnt++;
                    }
                    //el.options[j].disabled = false;
                } else {
                    //alert(el.options[i].value+" is off");
                    //el.options[i].style.display = "none";
                    el.options[i].selected = false;
                    el.options[i].disabled = true;
                }
            }
        //}


        if(aVals.length){
            // Show field
            if(document.getElementById("fld_box_"+name)){
                document.getElementById("fld_box_"+name).style.display = this.defaultDisplay;//"inline";
            }

            if(selectedCnt == 0){
                el.options[0].selected = true;
                el.value = "";
            }
        } else {
            el.options[0].selected = true;
            el.value = "";

            // Hide field
            if(this.hideEmpty){
                if(document.getElementById("fld_box_"+name)){
                    document.getElementById("fld_box_"+name).style.display = "none";
                }
            }
        }
    },

    populateCheckbox: function(hData) {
        if(uzAjaxFilter.debug){
            //alert(data);
        }
        var hProp = this.getFieldProp(hData.name);
        var name = hProp.formName;
        var defaultVal = hData.selected_vals;
        var aVals = hData.exist_vals;

        //alert(typeof(aVals));
        //alert(this.toString(hProp));
        //alert("populateCheckbox, form name = "+name+", aVals = "+this.toString(aVals)+"\n defaultVal = "+defaultVal);

        var i, j, val, oInput, isExists, cName;

        if(name.indexOf("[]") <= 0){
            // Single checkbox
            var oFld = document.getElementById(name);
            if(defaultVal == '0'){
                oFld.checked = false;
            } else {
                oFld.checked = true;
            }

        } else {
            // Walk over checkboxes
            //chk_ext_custom_29[]_0
            i = 0;
            cName = "chk_"+hProp.name+"_"+i;
            if(uzAjaxFilter.debug){
                //alert("check field '"+cName+"'");
            }
            while(i <= hProp.flagsCnt){
                if(document.getElementById(cName)){
                    oInput = document.getElementById(cName);
                    val = oInput.value;
                    var nameForLabel = cName.replace(/\[\]/, '');

                    //
                    // Check is exists value
                    //
                    isExists = this.inArray(val, aVals) ? 1 : 0;

                    if(isExists){
                        // Enable checkbox
                        //alert("Enable checkbox");
                        //oInput.disabled = false;
                        this.enableLabel(nameForLabel);

                    } else {
                        // Disable checkbox
                        //alert("Disable checkbox");
                        if(i > 0){
                            //oInput.checked = false;
                            //oInput.disabled = true;
                            this.disableLabel(nameForLabel);
                        }
                    }
                }
                i++;
                cName = "chk_"+hProp.name+"_"+i;
            }
        }

        /*
        if(!this.isObjEmpty(aVals)){
            if(uzAjaxFilter.debug){
                //alert(aVals.join(","));
                //alert("Show field "+name+" id = '"+"fld_box_"+name+"'");
            }
            // Show field
            if(document.getElementById("fld_box_"+name)){
                document.getElementById("fld_box_"+name).style.display = this.defaultDisplay;//"inline";
            }
           
        } else {
            if(uzAjaxFilter.debug){
                //alert("Hide field "+name+" id = '"+"fld_box_"+name+"'");
            }
            // Hide field
            if(this.hideEmpty){
                if(document.getElementById("fld_box_"+name)){
                    document.getElementById("fld_box_"+name).style.display = "none";
                }
            }
        }
        //*/
    },


    populateRadio: function(hData) {
        if(uzAjaxFilter.debug){
            //alert(this.toString(hData));
        }
        var hProp = this.getFieldProp(hData.name);
        var name = hProp.formName;
        var defaultVal = hData.selected_vals;
        var aVals = hData.exist_vals;

        //alert("populateRadio, form name = "+name+", aVals = "+this.toString(aVals)+"\n defaultVal = "+defaultVal);

        var i, j, val, oInput, isExists, cName;

        //
        // Walk over radio inputs
        //chk_ext_custom_29[]_0
        //
        i = 0;
        cName = "rd_"+name+"_"+i;
        while(document.getElementById(cName)){
            oInput = document.getElementById(cName);
            val = oInput.value;

            isExists = this.inArray(val, aVals) ? 1 : 0;

            if(isExists){
                // Enable radio
                //oInput.disabled = false;
                this.enableLabel(cName);

                //
                // Check default value
                //
            } else {
                // Disable radio
                if(i > 0){
                    //oInput.checked = false;
                    //oInput.disabled = true;
                    this.disableLabel(cName);
                }
            }

            //
            // Selected current value
            //
            if(oInput.value == defaultVal){
                oInput.checked = true;
            }

            i++;
            cName = "rd_"+name+"_"+i;
        }

        /*
        if(!this.isObjEmpty(aVals)){
            // Show field
            if(document.getElementById("fld_box_"+name)){
                document.getElementById("fld_box_"+name).style.display = this.defaultDisplay;//"inline";
            }
           
        } else {
            // Hide field
            if(this.hideEmpty){
                if(document.getElementById("fld_box_"+name)){
                    document.getElementById("fld_box_"+name).style.display = "none";
                }
            }
        }
        //*/
    },


    populateText: function(hData) {
        var hProp = this.getFieldProp(hData.name);
        var name = hProp.formName;

        var defaultVal = hData.selected_vals;

        var hProp = uzAjaxFilter.getFieldProp(name);

        var el = this.oForm.elements[name];

        el.value = defaultVal;
    },

    populateInterval: function(hData) {
        //var step = hData.step;
        var min = hData.super_interval.min * 1;
        var max = hData.super_interval.max * 1;
        if(max < min){
            max = min;
        }
        var selMin = hData.selected_vals[0] * 1;
        var selMax = hData.selected_vals[1] * 1;

        if(selMin < min){
            selMin = min;
        }
        if(selMin > max){
            selMin = max;
        }
        if(selMax < min){
            selMax = min;
        }
        if(selMax > max){
            selMax = max;
        }
        //alert(selMin+", "+selMax);

        hInterval = {
            step: hData.step,
            superInterval: {min: min, max: max},
            selectedVals: {min: selMin, max: selMax},
            existsVals: {min: 0, max: 1}
        };

        //alert("hData:\n"+this.toString(hData)+"\n\nhInterval:\n"+this.toString(hInterval));

        this.initInterval(hData.name, hInterval);

        //$("###details_id##_from").val( $("###details_id##_interval_slider").slider("values", 0) );
        //$("###details_id##_to").val( $("###details_id##_interval_slider").slider("values", 1) );

        //$("#"+hData.name+this.intervalObjectIdPostfix).slider( "option" , "max", max );
        //$("#"+hData.name+this.intervalObjectIdPostfix).slider( "option" , "min", min );
        //$("#"+hData.name+this.intervalObjectIdPostfix).slider( "option" , "step" , step );
        //$("#"+hData.name+this.intervalObjectIdPostfix).slider( "values" , 0, selMin );
        //$("#"+hData.name+this.intervalObjectIdPostfix).slider( "values" , 1, selMax );
    },

    //
    // hData = {
    //    superInterval: {min: 0, max: 1},
    //    selectedVals: {min: 0, max: 1},
    //    existsVals: {min: 0, max: 1}
    //}
    //
    initInterval: function(name, hData) {
        //alert("initInterval "+name+"\n"+this.toString(hData));

        //
        // Prepare values
        //
        var min = hData.superInterval.min * 1;
        var max = hData.superInterval.max * 1;
        var intValFrom = hData.selectedVals.min * 1;
        var intValTo = hData.selectedVals.max * 1;

        var valFrom = (intValFrom <= min) ? "" : intValFrom;
        var valTo = (intValTo >= max) ? "" : intValTo;

        //
        // Destroy slider widget before reinit
        //
        $("#"+name+this.intervalObjectIdPostfix).slider( "destroy" );

        //
        // Init slider widget
        //
        
        $("#"+name+this.intervalObjectIdPostfix).slider({
            range: true,
            step: hData.step * 1,
            min: min,
            max: max,
            values: [intValFrom, intValTo],
            slide: function( event, ui ) {
                var min = $(this).slider("option", "min");
                var max = $(this).slider("option", "max");

                var valFrom = ui.values[0];
                var valTo = ui.values[1];

                if(valFrom <= min){
                    valFrom = "";
                }
                if(valTo >= max){
                    valTo = "";
                }
                //alert("min = "+min+", valFrom = "+valFrom);
                $("#"+name+"_from").val(valFrom);
                $("#"+name+"_to").val(valTo);
            },
            stop: function( event, ui ) {
                AMI.Message.send('filter_field_changed', true);
            }
        });

        
        //
        // Add different classes to left and right slidebars
        //
        $("#"+name+this.intervalObjectIdPostfix).find("a.ui-slider-handle").eq(0).addClass("uz-slide-handler-left");
        $("#"+name+this.intervalObjectIdPostfix).find("a.ui-slider-handle").eq(1).addClass("uz-slide-handler-right");

        //
        // Call custom apply slider functions
        //
        AMI.Message.send("on_slider_init", null, null);

        /* To replace left slider handle style:
        function uzCustomSlidersApply(){
            //$(".ui-slider-handle").addClass('ui-slider-handle-left');
            //$(".ui-slider-handle").css({background: 'url("/_img/arrow_slider_l.png") no-repeat scroll 0 0 transparent'});
            $(".ui-slider").each(function(){
                var aLinks = $(this).find(".ui-slider-handle");
                if(aLinks.length){
                    $(aLinks[0]).css({background: 'url("/_img/arrow_slider_l.png") no-repeat scroll 0 0 transparent'});
                }
            });
        }
        AMI.Message.addListener("on_slider_init", uzCustomSlidersApply);
        */




        //
        // Init inputs values
        //
        $("#"+name+"_from").val(valFrom);
        $("#"+name+"_to").val(valTo);
    },

    onMessageFilterFieldIntervalChange: function(fName, fPostfix){
        uzAjaxFilter.onFilterFieldIntervalChange(fName, fPostfix);
        return true;
    },

    onFilterFieldIntervalChange: function(fName, forcedPostfix){
        var oSlider = $("#"+fName+this.intervalObjectIdPostfix);

        var min = oSlider.slider("option", "min");
        var max = oSlider.slider("option", "max");

        var valFrom = $("#"+fName+"_from").val();
        var valTo = $("#"+fName+"_to").val();

        var intValFrom = this.validateInt(valFrom);
        var intValTo = this.validateInt(valTo);

        if(!valFrom.length){
            intValFrom = min;
            forcedPostfix = '';
        }
        if(intValFrom <= min){
            intValFrom = min;
            valFrom = '';
            forcedPostfix = '';
        }

        if(!valTo.length){
            intValTo = max;
            forcedPostfix = '';
        }
        if(intValTo >= max){
            intValTo = max;
            valTo = '';
            forcedPostfix = '';
        }

        //
        // Validate values
        //
        if(intValTo < intValFrom){
            switch(forcedPostfix){
                case "_from":
                    intValTo = intValFrom;
                    valTo = valFrom;
                    break;
                case "_to":
                    intValFrom = intValTo;
                    valFrom = valTo;
                    break;
                default:
                    // One of fields is empty, do not validate other field by forced
                    break;
            }
        }

        //
        // Set-back
        //
        //alert("set fields vals "+valFrom+", "+valTo);
        $("#"+fName+"_from").val(valFrom);
        $("#"+fName+"_to").val(valTo);

        //alert("set slider vals "+intValFrom+", "+intValTo);
        oSlider.slider("option", "values", [intValFrom, intValTo]);

        AMI.Message.send('filter_field_changed', true);
    
    },
    















    setForcedSubmitUrl: function(catId) {
        var varName = this.oForm.name + "_forceSubmitUrl";
        if(document.getElementById(this.catSelectId)){
            var sublink = $("#"+this.catSelectId+" option:selected").attr("sublink");
            eval(varName + " = '" + this.scriptLink + "/" + sublink + "?'");
        }
    },

    // Return array of fields used names with not empty value.
    getFieldsFilteredBy: function() {
        var aRes = new Array();
        if(typeof(this.aFields) == 'undefined'){
            return aRes;
        }
        if(this.oForm != false && this.aFields.length){
            for(var i = 0; i < this.aFields.length; i++){
                switch(this.aFields[i].type){
                    case "select":
                        if(this.aFields[i].multi == ''){
                            if(this.oForm.elements[this.aFields[i].name].value != ""){
                                aRes.push(this.aFields[i].name);
                            }
                        } else {
                            var oSel = this.oForm.elements[this.aFields[i]]
                            for(var j = 0; j < oSel.options.length; j++){
                                if(oSel.options[j].selected){
                                    aRes.push(this.aFields[i].name);
                                    break;
                                }
                            }
                        }
                        break;
                    case "checkbox":
                        var j = 0;
                        var cName = "chk_"+this.aFields[i].name+"_";
                        while(document.getElementById(cName+j)){
                            if(document.getElementById(cName+j).checked && document.getElementById(cName+j).value != ""){
                                aRes.push(this.aFields[i].name);
                            }
                            j++;
                        }
                        break;
                    case "price_from":
                        if(this.oForm.elements[this.aFields[i].name].value != ""){
                            aRes.push(this.aFields[i].name);
                        }
                        break;
                    case "price_to":
                        if(this.oForm.elements[this.aFields[i].name].value != ""){
                            aRes.push(this.aFields[i].name);
                        }
                        break;
                    case "text":
                        if(this.oForm.elements[this.aFields[i].name].value != ""){
                            aRes.push(this.aFields[i].name);
                        }
                        break;
                    default:
                        break;
                }
            }
        }
        return aRes;
    },

/*
    getFieldsDefaultDisabled: function() {
        if(this.oForm == null || this.aFields.length == 0){
            return;
        }
        for(var i = 0; i < this.aFields.length; i++){
            if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                switch(this.aFields[i].type){
                    case "select":
                        this.aFields[i].defaultDisabled = this.oForm[this.aFields[i].name].disabled;
                        //this.aDefaultFieldsDisabledStatus[this.aFields[i].name] = this.oForm[this.aFields[i].name].disabled;
                        break;
                    case "checkbox":
                        break;
                    case "price_from":
                        this.aFields[i].defaultDisabled = this.oForm[this.aFields[i].name].disabled;
                        this.aDefaultFieldsDisabledStatus[this.aFields[i].name] = this.oForm[this.aFields[i].name].disabled;
                        break;
                    case "price_to":
                        this.aDefaultFieldsDisabledStatus[this.aFields[i].name] = this.oForm[this.aFields[i].name].disabled;
                        break;
                    case "text":
                        this.aDefaultFieldsDisabledStatus[this.aFields[i].name] = this.oForm[this.aFields[i].name].disabled;
                        break;
                    default:
                        break;
                }
            }
        }
    },
//*/

    disableFields: function() {
        if(this.oForm == false || typeof(this.aFields) == 'undefined'){
            return;
        }
        for(var i = 0; i < this.aFields.length; i++){
            switch(this.aFields[i].type){
                case "select":
                    if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                        this.oForm[this.aFields[i].name].disabled = true;
                    }
                    break;
                case "checkbox":
                    /*
                    var j = 0;
                    var cName = "chk_"+this.aFields[i].name+"_";
                    while(document.getElementById(cName+j)){
                        if(document.getElementById(cName+j).checked && document.getElementById(cName+j).value != ""){
                            aRes.push(this.aFields[i].name);
                        }
                        j++;
                    }
                    //*/
                    break;
                case "radio":
                    /*
                    var j = 0;
                    var cName = "chk_"+this.aFields[i].name+"_";
                    while(document.getElementById(cName+j)){
                        if(document.getElementById(cName+j).checked && document.getElementById(cName+j).value != ""){
                            aRes.push(this.aFields[i].name);
                        }
                        j++;
                    }
                    //*/
                    break;
                case "price_from":
                    if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                        this.oForm[this.aFields[i].name].disabled = true;
                    }
                    break;
                case "price_to":
                    if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                        this.oForm[this.aFields[i].name].disabled = true;
                    }
                    break;
                case "text":
                    if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                        this.oForm[this.aFields[i].name].disabled = true;
                    }
                    break;
                case "interval":
                    $("#"+this.aFields[i].name+this.intervalObjectIdPostfix).slider( "option" , "disabled", true );
                    break;
                default:
                    break;
            }
            // Disable subfields
            if(typeof(this.aFields[i].aSubfieldsId) != 'undefined'){
                this.setSubfieldsDisabledStatus(this.aFields[i].aSubfieldsId, true);
            }
        }
    },

    enableFields: function() {
        if(this.oForm == false || typeof(this.aFields) == 'undefined'){
            return;
        }
        for(var i = 0; i < this.aFields.length; i++){
            switch(this.aFields[i].type){
                case "select":
                    //alert(this.toString[this.aFields]);
                    //this.oForm[this.aFields[i].name].disabled = this.aDefaultFieldsDisabledStatus[this.aFields[i].name];
                    if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                        this.oForm[this.aFields[i].name].disabled = false;
                    }
                    break;
                case "checkbox":
                    /*
                    var j = 0;
                    var cName = "chk_"+this.aFields[i].name+"_";
                    while(document.getElementById(cName+j)){
                        if(document.getElementById(cName+j).checked && document.getElementById(cName+j).value != ""){
                            aRes.push(this.aFields[i].name);
                        }
                        j++;
                    }
                    //*/
                    break;
                case "price_from":
                    //this.oForm[this.aFields[i].name].disabled = this.aDefaultFieldsDisabledStatus[this.aFields[i].name];
                    if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                        this.oForm[this.aFields[i].name].disabled = false;
                    }
                    break;
                case "price_to":
                    //this.oForm[this.aFields[i].name].disabled = this.aDefaultFieldsDisabledStatus[this.aFields[i].name];
                    if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                        this.oForm[this.aFields[i].name].disabled = false;
                    }
                    break;
                case "text":
                    //this.oForm[this.aFields[i].name].disabled = this.aDefaultFieldsDisabledStatus[this.aFields[i].name];
                    if(typeof(this.oForm[this.aFields[i].name]) != 'undefined'){
                        this.oForm[this.aFields[i].name].disabled = false;
                    }
                    break;
                case "interval":
                    $("#"+this.aFields[i].name+this.intervalObjectIdPostfix).slider( "option" , "disabled", false );
                    break;
                default:
                    break;
            }

            // Enable subfields
            if(typeof(this.aFields[i].aSubfieldsId) != 'undefined'){
                this.setSubfieldsDisabledStatus(this.aFields[i].aSubfieldsId, false);
            }
        }
    },

    setSubfieldsDisabledStatus: function(aSubfieldsId, status) {
        for(var i = 0; i < aSubfieldsId.length; i++){
            var subfieldId = aSubfieldsId[i];

            if(document.getElementById(subfieldId)){
                document.getElementById(subfieldId).disabled = status;
            }
        }
    },

    disableLabel: function(fieldId) {
        $("#"+fieldId+"_label").addClass(this.disabledClass);
        //alert("disableLabel "+"#"+fieldId+"_label");
    },

    enableLabel: function(fieldId) {
        $("#"+fieldId+"_label").removeClass(this.disabledClass);
        //alert("enableLabel "+"#"+fieldId+"_label");
    },


    //
    // Apply filted data section end
    //








    //
    // Select category section
    //
    /*
    initCurrentCat: function(){
        if(document.getElementById(this.catSelectId) && typeof(this.oForm.elements["catid"]) != 'undefined'){
            this.currentCatId = this.oForm.elements["catid"].value;
            document.getElementById(this.catSelectId).value = this.currentCatId;
        }
    },
    //*/
    //
    // Select category section end

    
    
    
    
    //





    //
    // Form interactive widgets section
    //

    onMessageFilterFieldCaptionClick: function(fldName, p2){
        uzAjaxFilter.onFilterFieldCaptionClick(fldName);
        return true;
    },

    onFilterFieldCaptionClick: function(fldName){
        $("#"+fldName+this.fieldValuesBoxIdPostfix).toggleClass(this.hideValuesClass);
    },

    onLoadShowFieldsValues: function(){
        if(this.oForm != null && this.aFields.length){
            var i, j, val, show;
            //alert(this.toString(this.aFields));
            for(i = 0; i < this.aFields.length; i++){
                val = this.getFieldValue(this.aFields[i].formName);
                show = false;
                switch(this.aFields[i].type){
                    //select|checkbox|radio|text|interval|val_from|val_to
                    case "checkbox":
                        //alert(this.aFields[i].formName+" = "+this.toString(val));
                        //alert(this.aFields[i].formName);
                        if(this.aFields[i].formName.indexOf("[]") < 0){
                            show = true;
                        } else {
                            // Multiple checkboxes
                            //alert("Multiple checkboxes");
                            if(val.length){
                                //for(j in val){
                                for(j = 0;  j < val.length; j++){
                                    if(val[j] != this.aFields[i].emptyValue){
                                        //alert(val[j]+" != "+this.aFields[i].emptyValue+" is true");
                                        show = true;
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    case "radio":
                        if(val != this.aFields[i].emptyValue){
                            show = true;
                        }
                        break;
                    case "select":
                        if(this.aFields[i].multi == ''){
                            show = true;
                        } else {
                            // Multiple checkboxes
                            if(val.length){
                                //for(j in val){
                                for(j = 0;  j < val.length; j++){
                                    if(val[j] != this.aFields[i].emptyValue){
                                        show = true;
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    case "interval":
                        show = true;
                        break;
                    default:
                        if(val != this.aFields[i].emptyValue){
                            show = true;
                        }
                        break;
                }

                if(show){
                    //alert("show field vals "+this.aFields[i].name);
                    $("#"+this.aFields[i].name+this.fieldValuesBoxIdPostfix).removeClass(this.hideValuesClass);
                } else {
                    //alert("leave hidden field vals "+this.aFields[i].name);
                }
            }
        }
    },


    onMessageFilterFieldCaptionDescClick: function(fldName, oObj){
        uzAjaxFilter.onFilterFieldCaptionDescClick(fldName,oObj);
	
        return true;
    },

    onFilterFieldCaptionDescClick: function(fldName,oObj){
       // alert('show dialog');
 
        var dlgheight = $('.dialog').height();
        var left_offset_position = $(oObj).position().left; 
        var top_offset_position = $(oObj).position().top+dlgheight+10;

        $('.dialog').css("top",top_offset_position+'px');
        $('.dialog').css("left",left_offset_position+'px');
        $('.dialog').show();
        $(document).mousedown( function(event){
            if( $(event.target).closest(".dialog").length ){
                return;
            }
            $(".dialog").fadeOut("slow");
            $(document).unbind('mousedown');
            event.stopPropagation();
        });
    },


    //
    // Form interactive section
    //




















    //
    // Stuff functions
    //



    toJsonString: function (mixed_val) {
        var retVal, json = window.JSON;
        try {
            if (typeof json === 'object' && typeof json.stringify === 'function') {
                retVal = json.stringify(mixed_val); // Errors will not be caught here if our own equivalent to resource
                //  (an instance of PHPJS_Resource) is used
                if (retVal === undefined) {
                    throw new SyntaxError('json_encode');
                }
                return retVal;
            }

            var value = mixed_val;

            var quote = function (string) {
                var escapable = /[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
                var meta = { // table of character substitutions
                    '\b': '\\b',
                    '\t': '\\t',
                    '\n': '\\n',
                    '\f': '\\f',
                    '\r': '\\r',
                    '"': '\\"',
                    '\\': '\\\\'
                };

                escapable.lastIndex = 0;
                return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
                    var c = meta[a];
                    return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                }) + '"' : '"' + string + '"';
            };

            var str = function (key, holder) {
                var gap = '';
                var indent = '    ';
                var i = 0; // The loop counter.
                var k = ''; // The member key.
                var v = ''; // The member value.
                var length = 0;
                var mind = gap;
                var partial = [];
                var value = holder[key];

                // If the value has a toJSON method, call it to obtain a replacement value.
                if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
                    value = value.toJSON(key);
                }

                // What happens next depends on the value's type.
                switch (typeof value) {
                case 'string':
                    return quote(value);

                case 'number':
                    // JSON numbers must be finite. Encode non-finite numbers as null.
                    return isFinite(value) ? String(value) : 'null';

                case 'boolean':
                case 'null':
                    // If the value is a boolean or null, convert it to a string. Note:
                    // typeof null does not produce 'null'. The case is included here in
                    // the remote chance that this gets fixed someday.
                    return String(value);

                case 'object':
                    // If the type is 'object', we might be dealing with an object or an array or
                    // null.
                    // Due to a specification blunder in ECMAScript, typeof null is 'object',
                    // so watch out for that case.
                    if (!value) {
                        return 'null';
                    }
                    if ((this.PHPJS_Resource && value instanceof this.PHPJS_Resource) || (window.PHPJS_Resource && value instanceof window.PHPJS_Resource)) {
                        throw new SyntaxError('json_encode');
                    }

                    // Make an array to hold the partial results of stringifying this object value.
                    gap += indent;
                    partial = [];

                    // Is the value an array?
                    if (Object.prototype.toString.apply(value) === '[object Array]') {
                        // The value is an array. Stringify every element. Use null as a placeholder
                        // for non-JSON values.
                        length = value.length;
                        for (i = 0; i < length; i += 1) {
                            partial[i] = str(i, value) || 'null';
                        }

                        // Join all of the elements together, separated with commas, and wrap them in
                        // brackets.
                        v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
                        gap = mind;
                        return v;
                    }

                    // Iterate through all of the keys in the object.
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = str(k, value);
                            if (v) {
                                partial.push(quote(k) + (gap ? ': ' : ':') + v);
                            }
                        }
                    }

                    // Join all of the member texts together, separated with commas,
                    // and wrap them in braces.
                    v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
                    gap = mind;
                    return v;
                case 'undefined':
                    // Fall-through
                case 'function':
                    // Fall-through
                default:
                    throw new SyntaxError('json_encode');
                }
            };

            // Make a fake root object containing our value under the key of ''.
            // Return the result of stringifying the value.
            return str('', {
                '': value
            });

        } catch (err) { // Todo: ensure error handling above throws a SyntaxError in all cases where it could
            // (i.e., when the JSON global is not available and there is an error)
            if (!(err instanceof SyntaxError)) {
                throw new Error('Unexpected error type in json_encode()');
            }
            this.php_js = this.php_js || {};
            this.php_js.last_error_json = 4; // usable by json_last_error()
            return null;
        }
    },


    inArray: function(val, aVals){
        var res = 0;
        var i;
        if(typeof(aVals) == 'object'){
            // Check value in object
            for(i in aVals){
                if(aVals[i] == val){
                    res = 1;
                    break;
                }
            }
        } else {
            // Expects aVals is an array
            if(aVals.length){
                for(var i = 0; i < aVals.length; i++){
                    if(aVals[i] == val){
                        res = 1;
                        break;
                    }
                }
            }
        }
        return res;
    },

    isObjEmpty: function(aVals){
        var res = 0;
        var i, cnt;
        switch(typeof(aVals)){
            case "object":
                // Check values in object
                cnt = 0;
                for(i in aVals){
                    cnt++;
                }
                if(cnt == 0){
                    res = 1;
                }
                break;
            default:
                // For arrays
                if(typeof(aVals.length) != 'undefined'){
                    if(aVals.length == 0){
                        res = 1;
                    }
                }
                break;
        }
        return res;
    },

    // Debug object to string
    toString: function(oData, indent){
        if(typeof(indent) == 'undefined'){
            var indent = "";
        }
        var res = "";
        if(typeof(oData) == 'object'){
            for(var i in oData){
                if(typeof(oData[i]) == 'object'){
                  res += indent + i+": {\n"+this.toString(oData[i], indent + "  ")+indent + "}\n";
                } else {
                  res += indent + i+":"+oData[i]+"\n";
                }
            }
        } else {
            res += indent + oData+"\n";
        }
        return res;
    },

    cloneObject: function (obj){
        if(obj == null || typeof(obj) != 'object')
            return obj;
        var temp = new obj.constructor();
        for(var key in obj)
            temp[key] = this.cloneObject(obj[key]);
        return temp;
    },

    validateFloat: function(val, roundPrecision){
        if(isNaN(val) || val == ""){
            val = 0;
        }
        val = parseFloat(val);
        if(val < 0 ){
            val = 0;
        }

        if(typeof(roundPrecision) == 'undefined'){
            var roundPrecision = this.roundPrec;
        }
        val = this.round(val, roundPrecision);
        return val;
    },

    validateInt: function(val){
        if(isNaN(val) || val == ""){
            val = 0;
        }
        val = parseInt(val);
        if(val < 0 ){
            val = 0;
        }
        return val;
    },


    endvar: 1
}







//
// On page load fill the filter fields
//
//var uzHOpt = {
//  /* define filter options */
//}
//uzAjaxFilter.init(uzHOpt);
//uzAjaxFilter.onFieldChange(0);

