// quickfind.js v. 1.0, "Bundle Project. Part 1" by Mars Kosatkin


var have_selected = false;
var mode = '';
var req = new Object();  


function loadfields (param){
    $("#loading").show();
    var sid = '';
    var add = '';
    arr_selected = [];
    generated = false;
     
    if (param && mode == 'change'){
       
            $.each(param, function (k, v) {   
                if (v) {
                    add = add + k + '=' + v + '&';
                   // arr_selected[arr_selected.length] = v;
                }
                
            });
         
        }
        //$('#quickcont select').remove();
      
       // console.log('/search.php?'+add+'mode=search');
         $('#quickcont').load('/search.php?'+add+'mode=search',function(){
            $("#loading").hide();   
         });
         
     /* 
        $('#quickfind').find('select').each(function (){
            $(this).find('option').each (function(){
                if ($(this).val()) $(this).remove();
            })
        })
     */
       // console.time("timing foo");   
  //   $.get('/search.php', add+'mode=search', function (obj){
        
            /*
        
                $.each(obj, function(k, v) {
                    sid = v.fieldid;
                    $.each(v.values, function (kk, vv) {
                            if (vv.value != '' && vv.url != '') {
                                  sel = '';
                                  if (vv.is_selected == 'Y') sel ='selected="selected"';
                                  $('#ef'+sid).append ('<option '+sel+' value="' + vv.url + '" >' + vv.value + '</option>');
                            }
                    });                    
                });
       */
    //            generated=true;
    // });
    
   //   tid = setInterval (choose_select, 20);      

}

function changeselect (sel) {
        select = $('#'+sel);
        var name = select.attr("name");
        var v = select.val ();
        eval ('req.' + name + "=" + "'" + v + "'") ;   
        mode = 'change';
        loadfields (req);
}
$(document).ready(function ()
{
    $("#quickform select").removeAttr("disabled");
    
  /*  $("#quickcont select").change(function (){
        
        var name = $(this).attr("name");
        var v = $(this).val ();
        eval ('req.' + name + "=" + "'" + v + "'") ;   
        mode = 'change';
        loadfields (req);
         
       
    });*/
    
    $("#quickform").submit(function (){
        $('#quickcont').find('select').each(function (){
            if ($(this).val()) have_selected = true;
        });
       if (!have_selected)
            return false; 
    });
    
    $("#reset").click(function (){
        req = new Object();
        mode = 'reset';
        loadfields ();
    })
})
