$(document).ready( 
    function(){
        
        $("select").change(function(){ 
            $.getJSON("getOptions.php?Ch="+$("#Chemistry").val()+"&Ca="+$("#Capacity").val()+"&Vo="+$("#Voltage").val()+"&Ma="+$("#Manufacturer").val(), 
                function(data){
                    if(data.error=='1'){ 
                        alert(data.value);
                    } else {
                    	  jQuery.each(data.value,
                    	  	  function(i, val){
                    	  	  	  $("#"+i).empty();
                        				$("#"+i).append('<option value="">Any '+i+'</option>');
                            		var fillout = function(j,val){
                            						var sel = '';
                            						if(data.selected[i]==val){
                            							  sel = ' selected="selected"';
                            					  }
                                				$("#"+i).append('<option value="'+val+'"'+sel+'>'+val+'</option>');
                                		}
                        				jQuery.each(val,fillout);
                            }
                        );
                    }
                });        
        });

        $("select").bind("ajaxSend", function(){
            $(this).attr("disabled", "disabled");
        }).bind("ajaxComplete", function(){
            $(this).removeAttr("disabled");
        });        
        $("input").bind("ajaxSend", function(){
            $(this).attr("disabled", "disabled");
        }).bind("ajaxComplete", function(){
            $(this).removeAttr("disabled");
        });        
    }
);

