Index: /Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
===================================================================
--- /Dev/branches/rest-dojo-ui/client/rft/pages/survey.js	(revision 362)
+++ /Dev/branches/rest-dojo-ui/client/rft/pages/survey.js	(revision 363)
@@ -46,5 +46,5 @@
                 }));
                 store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:1})
-                .forEach(lang.hitch(this,function(value,key){
+                .forPairs(lang.hitch(this,function(value,key){
                     this._createCategoryTab(key[0],value);
                 }));
@@ -68,5 +68,5 @@
                     categoryMap._filled = true;
                     store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]})
-                    .forEach(lang.hitch(this,function(value,key){
+                    .forPairs(lang.hitch(this,function(value,key){
                         this._createTopicSelector(key[1],category,value);
                     }));
@@ -94,5 +94,5 @@
                 if (!topicMap._filled) {
                     store.query('_design/default/_view/questions', {reduce:false,include_docs:true,key:[category,topic]})
-                    .forEach(lang.hitch(this,function(value,key){
+                    .forEach(lang.hitch(this,function(value){
                         topicMap._widget.addItem(value);
                     }));
Index: /Dev/branches/rest-dojo-ui/client/rft/store.js
===================================================================
--- /Dev/branches/rest-dojo-ui/client/rft/store.js	(revision 362)
+++ /Dev/branches/rest-dojo-ui/client/rft/store.js	(revision 363)
@@ -2,5 +2,5 @@
     function(declare,lang,array,Deferred,xhr,JSON,QueryResults){
     
-        var CouchStore = declare("rft.store", null, {
+        var CouchStore = declare(null, {
             /** dojo.Store implementation for CouchDB
              *
@@ -43,4 +43,12 @@
             },
 	        put: function(object, options){
+                 // summary:
+                 //     put an object in CouchDB
+                 // object: Object
+                 //     The object to put
+                 // options: Object
+                 //     Options object as
+                 //         id: String
+                 //
 		        options = options || {};
 
@@ -91,4 +99,42 @@
             },
             query: function(query, options){
+                // summary:
+                //    query a couchdb view
+                // query: String
+                //    name of a couchdb view you want to query, relative to the current database
+                // options: Object
+                //     options object as
+                //        start: Number
+                //            Start results at this item
+                //        count: Number
+                //            Number of items to return
+                //        sort: [{attribute:'key',descending:true|false}]
+                //            CouchDB only support sorting by key, so only 'key'
+                //            is allowed as attribute value. Multiple sort items
+                //            are ignored.
+                //        key: String|Array|Object
+                //            Return only values with this key.
+                //            Excludes start/endkey usage.
+                //        startkey: String|Array|Object
+                //            Return values starting from this key.
+                //        endkey: String|Array|Object
+                //            Return values with key lower than this key.
+                //        include_docs: true|false
+                //            Return the full documents instead of the view
+                //            values.
+                //        reduce: true|false
+                //            Execute reduce on the view or not. Default depends
+                //            on if a reduce function is defined on the view.
+                //        group: true|false
+                //            Should values be grouped per key or not? Default
+                //            is false.
+                //        group_level: Number
+                //            When group = true and the key is an array,
+                //            determines which elements starting from the first
+                //            are used for grouping. Default is 0.
+                //        get_keys: true|false
+                //            Instead of returning the values or documents,
+                //            return the array of keys as the result.
+                //            This does not affect the forPairs function.
 		        options = options || {};
 
@@ -161,9 +207,19 @@
                         dfd.reject(result.reason);
                     } else  {
-                        dfd.resolve(
-                            array.map(result.rows,
-                                      function(result){
-                                          return [result.key, options.include_docs === true ? result.doc : result.value];
-                                      }));
+                        var results;
+                        var values = array.map(result.rows,function(result){
+                            return options.include_docs === true ? result.doc : result.value;
+                        });
+                        var keys = array.map(result.rows,function(result){
+                            return result.key;
+                        });
+                        if (options.get_keys === true) {
+                            results = keys;
+                            results.values = values;
+                        } else {
+                            results = values;
+                            results.keys = keys;
+                        }
+                        dfd.resolve(results);
                     }
                 },function(err){
@@ -175,22 +231,15 @@
 
         function CouchResults(results) {
-            if (!results) {
-                return results;
+            results = QueryResults(results);
+            results.forPairs = function(callback,thisObject) {
+                callback = lang.hitch(thisObject,callback);
+                return Deferred.when(results,function(results) {
+                    var values = results.values || results;
+                    var keys = results.keys || results;
+                    return array.forEach(values, function(value,index) {
+                        callback(value,keys[index],index);
+                    });
+                });
             }
-
-	        if(results.then){
-		        results = lang.delegate(results);
-	        }
-
-            if (!results.forEach) {
-                results.forEach = function(callback) {
-                    return Deferred.when(results, function(results) {
-                        array.forEach(results, function(result) {
-                            callback(result[1],result[0]);
-                        });
-                    });
-                }
-            }
-
             return results;
         }
