Index: Dev/trunk/src/server/config/couchdb-design-docs.js
===================================================================
--- Dev/trunk/src/server/config/couchdb-design-docs.js	(revision 526)
+++ Dev/trunk/src/server/config/couchdb-design-docs.js	(revision 531)
@@ -30,5 +30,5 @@
         _id: "schemaInfo",
         version: "4",
-        viewsVersion: "1"
+        viewsVersion: "2"
     },
 
@@ -49,6 +49,7 @@
             by_type: {
                 map: function(doc){
-                    emit(doc.type, doc);
-                }
+                    emit(doc.type, 1);
+                },
+                reduce: function(keys,values){ return sum(values); }
             },
             typeless: {
@@ -104,5 +105,5 @@
                     emit(doc.topic||"(default)",1);
                 },
-                reduce: function(key, values, rereduce) { return sum(values); }
+                reduce: function(key, values ) { return sum(values); }
             },
             all_variables: {
@@ -137,12 +138,15 @@
                 map: function(doc){
                     if ( doc.type !== 'Question' ) { return; }
-                    emit(doc.code,doc);
-                }
+                    emit(doc.code,1);
+                },
+                reduce: function(key, values) { return sum(values); }
             },
             published_by_code: {
                 map: function(doc){
-                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
-                    emit(doc.code,doc);
-                }
+                    if ( doc.type !== 'Question' ||
+                         !doc.publicationDate ) { return; }
+                    emit(doc.code,1);
+                },
+                reduce: function(key, values) { return sum(values); }
             },
             lib: {
@@ -159,5 +163,6 @@
             drafts: {
                 map: function(doc){
-                    if ( doc.type !== 'Survey' || doc.publicationDate ) { return; }
+                    if ( doc.type !== 'Survey' ||
+                         doc.publicationDate ) { return; }
                     emit(doc._id,doc);
                 }
@@ -165,5 +170,6 @@
             published: {
                 map: function(doc){
-                    if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; }
+                    if ( doc.type !== 'Survey' ||
+                         !doc.publicationDate ) { return; }
                     emit(doc._id,doc);
                 }
@@ -176,11 +182,17 @@
         language: "javascript",
         views: {
-            by_dates: {
+            by_start_date: {
                 map: function(doc){
                     if ( doc.type !== 'SurveyRun' ) { return; }
-                    var startDate = doc.startDate || "";
-                    var endDate = doc.endDate || {};
-                    emit([startDate,endDate,doc.liveName||null],doc);
-                }
+                    emit(doc.startDate||null,1);
+                },
+                reduce: function(keys,values){ return sum(values); }
+            },
+            by_end_date: {
+                map: function(doc){
+                    if ( doc.type !== 'SurveyRun' ) { return; }
+                    emit(doc.endDate||{},1);
+                },
+                reduce: function(keys,values){ return sum(values); }
             }
         }
@@ -194,6 +206,7 @@
                 map: function(doc){
                     if ( doc.type !== 'Response' ) { return; }
-                    emit(doc.surveyRunId, doc);
-                }
+                    emit(doc.surveyRunId, 1);
+                },
+                reduce: function(keys,values){ return sum(values); }
             }
         }
Index: Dev/trunk/src/server/config/couchdb-schema.json
===================================================================
--- Dev/trunk/src/server/config/couchdb-schema.json	(revision 526)
+++ Dev/trunk/src/server/config/couchdb-schema.json	(revision 531)
@@ -10,6 +10,8 @@
   "definitions": {
     "nonEmptyString": { "type": "string", "minLength": 1 },
-    "codeString": { "type": "string", "pattern": "^[A-Za-z0-9]+$" },
-    "subcodeString": { "type": "string", "pattern": "^[A-Za-z0-9]*$" },
+    "code": { "type": "string", "pattern": "^[A-Za-z0-9]+$" },
+    "subcode": { "type": "string", "pattern": "^[A-Za-z0-9]*$" },
+    "datetime": {"type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$"},
+    "html5Email": {"type": "string", "pattern": "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"},
     "schemaInfo": {
       "type": "object",
@@ -40,8 +42,8 @@
           "_rev": { "$ref": "#/definitions/nonEmptyString" },
           "categories": { "type": "array", "items": { "$ref": "#/definitions/nonEmptyString" } },
-          "code": { "$ref": "#/definitions/codeString" },
+          "code": { "$ref": "#/definitions/code" },
           "content": { "type": "array", "items": { "$ref": "#/definitions/content/any" } },
           "description": { "$ref": "#/definitions/nonEmptyString" },
-          "publicationDate": { "type": "string", "format": "datetime" },
+          "publicationDate": { "$ref": "#/definitions/datetime" },
           "title": { "$ref": "#/definitions/nonEmptyString" },
           "topic": { "$ref": "#/definitions/nonEmptyString" }
@@ -57,5 +59,5 @@
           "_rev": { "$ref": "#/definitions/nonEmptyString" },
           "description": { "$ref": "#/definitions/nonEmptyString" },
-          "publicationDate": { "type": "string", "format": "datetime" },
+          "publicationDate": { "$ref": "#/definitions/datetime" },
           "questions": { "type": "array", "items": { "$ref": "#/definitions/docs/Question" } },
           "title": { "$ref": "#/definitions/nonEmptyString" }
@@ -71,10 +73,9 @@
           "_rev": { "$ref": "#/definitions/nonEmptyString" },
           "description": { "$ref": "#/definitions/nonEmptyString" },
-          "endDate": { "type": "string", "format": "datetime" },
-          "liveName": { "$ref": "#/definitions/nonEmptyString" },
+          "endDate": { "$ref": "#/definitions/datetime" },
           "mode": { "type": "string", "enum": [ "open", "closed" ] },
           "respondentCanDeleteOwnResponse": { "type": "boolean" },
           "secret": { "$ref": "#/definitions/nonEmptyString" },
-          "startDate": { "type": "string", "format": "datetime" },
+          "startDate": { "$ref": "#/definitions/datetime" },
           "survey": { "$ref": "#/definitions/docs/Survey" },
           "title": { "$ref": "#/definitions/nonEmptyString" }
@@ -96,6 +97,5 @@
               "additionalProperties": false
           },
-          "email": { "type": "string", "format": "email" },
-          "publicationDate": { "type": "string", "format": "datetime" },
+          "publicationDate": { "$ref": "#/definitions/datetime" },
           "secret": { "$ref": "#/definitions/nonEmptyString" },
           "surveyRunId": { "$ref": "#/definitions/nonEmptyString" }
@@ -149,5 +149,5 @@
         "properties": {
           "type": { "type": "string", "pattern": "^StringInput$" },
-          "subcode": { "$ref": "#/definitions/subcodeString" },
+          "subcode": { "$ref": "#/definitions/subcode" },
           "text": { "$ref": "#/definitions/nonEmptyString" }
         },
@@ -160,5 +160,5 @@
           "type": { "type": "string", "pattern": "^TextInput$" },
           "maxLength": { "type": "integer" },
-          "subcode": { "$ref": "#/definitions/subcodeString" },
+          "subcode": { "$ref": "#/definitions/subcode" },
           "text": { "$ref": "#/definitions/nonEmptyString" }
         },
@@ -173,5 +173,5 @@
           "max": { "type": "integer" },
           "places": { "type": "integer" },
-          "subcode": { "$ref": "#/definitions/subcodeString" },
+          "subcode": { "$ref": "#/definitions/subcode" },
           "text": { "$ref": "#/definitions/nonEmptyString" }
         },
@@ -193,5 +193,5 @@
               "minLabel": { "$ref": "#/definitions/nonEmptyString" },
               "maxLabel": { "$ref": "#/definitions/nonEmptyString" },
-              "subcode": { "$ref": "#/definitions/subcodeString" },
+              "subcode": { "$ref": "#/definitions/subcode" },
               "text": { "$ref": "#/definitions/nonEmptyString" }
             },
@@ -219,10 +219,10 @@
               "type": "object",
               "properties": {
-                  "subcode": { "$ref": "#/definitions/subcodeString" }
+                  "subcode": { "$ref": "#/definitions/subcode" }
               },
               "required": ["subcode"],
               "additionalProperties": false
           },
-          "subcode": { "$ref": "#/definitions/subcodeString" }
+          "subcode": { "$ref": "#/definitions/subcode" }
         },
         "required":["type","items","subcode"],
@@ -236,5 +236,5 @@
               "type": "object",
               "properties": {
-                "subcode": { "$ref": "#/definitions/subcodeString" },
+                "subcode": { "$ref": "#/definitions/subcode" },
                 "text": { "$ref": "#/definitions/nonEmptyString" }
               },
@@ -245,5 +245,5 @@
               "type": "object",
               "properties": {
-                "subcode": { "$ref": "#/definitions/subcodeString" }
+                "subcode": { "$ref": "#/definitions/subcode" }
               },
               "required": ["subcode"],
