var _search  =   {

    criteria:   {
       category:    0,
       mark:        0,
       model:       0,
       energy:      0,
       gearbox:     0,
       body:        0,
       segment:     0,
       site:        0,
       side:        0
    },
    url:        '_front/search_display.php',

    Init:       function()
    {
        for(var n_criterion in this.criteria)
        {
            this.criteria[n_criterion]  =   document.getElementById(n_criterion) ? document.getElementById(n_criterion).value : 0;
        }
        //alert(this.Serialize());
    },
    Serialize:  function()
                {
                    var l_arr   =   new Array();
                    for(var n_criterion in this.criteria)
                    {
                        if (this.criteria[n_criterion] != 0)
                        {
                            l_arr.push(n_criterion + '=' + this.criteria[n_criterion]);
                        }
                    }
                    return l_arr.join('&');
                },
    Update:     function(i_strCriterion, i_idxCriterion)
                {
                    switch(i_strCriterion)
                    {
                        case 'mark':
                            if (i_idxCriterion.toString() != this.criteria[i_strCriterion].toString())
                            {
                                this.criteria['model']  =   0;
                            }
                            break;
                    }
                    this.criteria[i_strCriterion]   =   i_idxCriterion;
                    var l_side  =   document.getElementById('side').value;
//                    $('#' + l_side).load(
//                        this.url + "?" + this.Serialize()
//                    );
                    $('#search_display_' + l_side).load(
                        this.url,
                        this.criteria,
                        function(){_search.Init()}
                    );
                    
                },
    Submit:     function(i_url)
                {
                    delete this.criteria.side;
                    var l_serial    =   this.Serialize();
                    window.parent.location  =   i_url + ((l_serial != "") ? ("?" + l_serial) : "");
                }
};

_search.Init();
