eb2bb727094a703f6665d4220762c707530b873f
angie
  Mon Jul 8 14:04:21 2013 -0700
Fixing some broken HTML and JS in hgVai and hgTables when the position/search term can't be found.  refs 6152 10964
diff --git src/hg/lib/web.c src/hg/lib/web.c
index f56a53f..d707d1e 100644
--- src/hg/lib/web.c
+++ src/hg/lib/web.c
@@ -29,59 +29,61 @@
 #include "geoMirror.h"
 #include <regex.h>
 #include "trackHub.h"
 /* phoneHome business */
 
 
 /* flag that tell if the CGI header has already been outputed */
 boolean webHeadAlreadyOutputed = FALSE;
 /* flag that tell if text CGI header hsa been outputed */
 boolean webInTextMode = FALSE;
 static char *dbCgiName = "db";
 static char *orgCgiName = "org";
 static char *cladeCgiName = "clade";
 static char *extraStyle = NULL;
 
-/* global: a cart for use in error handlers. */
+/* globals: a cart and db for use in error handlers. */
 static struct cart *errCart = NULL;
+static char *errDb = NULL;
 
 void textVaWarn(char *format, va_list args)
 {
 vprintf(format, args);
 puts("\n");
 }
 
 void softAbort()
 {
 exit(0);
 }
 
 void webPushErrHandlers(void)
 /* Push warn and abort handler for errAbort(). */
 {
 if (webInTextMode)
     pushWarnHandler(textVaWarn);
 else
     pushWarnHandler(webVaWarn);
 pushAbortHandler(softAbort);
 hDumpStackPushAbortHandler();
 }
 
-void webPushErrHandlersCart(struct cart *cart)
-/* Push warn and abort handler for errAbort(); save cart for use in handlers. */
+void webPushErrHandlersCartDb(struct cart *cart, char *db)
+/* Push warn and abort handler for errAbort(); save cart and db for use in handlers. */
 {
 errCart = cart;
+errDb = db;
 webPushErrHandlers();
 }
 
 void webPopErrHandlers(void)
 /* Pop warn and abort handler for errAbort(). */
 {
 popWarnHandler();
 hDumpStackPopAbortHandler();
 popAbortHandler();
 }
 
 void webSetStyle(char *style)
 /* set a style to add to the header */
 {
 extraStyle = style;
@@ -419,36 +421,38 @@
 #endif /* GBROWSE */
     puts( "</BODY></HTML>");
     webPopErrHandlers();
     }
 }
 
 static boolean gotWarnings = FALSE;
 
 void webVaWarn(char *format, va_list args)
 /* Warning handler that closes out page and stuff in
  * the fancy form. */
 {
 gotWarnings = TRUE;
 boolean needStart = !webHeadAlreadyOutputed;
 if (needStart)
-    webStart(errCart, NULL, "Error");
+    {
+    // All callers of this (via webPushErrHandlersCartDb) have skipped Content-type
+    // because they want to output text unless we hit this condition:
+    puts("Content-type:text/html\n");
+    cartWebStart(errCart, errDb, "Error");
+    }
 htmlVaWarn(format, args);
-printf("\n<!-- HGERROR -->\n");
-printf("\n\n");
-if (needStart)
-    webEnd();
+printf("\n<!-- HGERROR -->\n\n\n");
 }
 
 
 boolean webGotWarnings()
 /* Return TRUE if webVaWarn has been called. */
 {
 return gotWarnings;
 }
 
 void webAbort(char* title, char* format, ...)
 /* an abort function that outputs a error page */
 {
 va_list args;
 va_start(args, format);