--- biblio.pages_orig.inc	2009-05-01 10:50:59.000000000 -0400
+++ biblio.pages.inc	2009-05-06 10:46:17.000000000 -0400
@@ -99,7 +99,9 @@ function biblio_db_search() {
 function biblio_build_query($arg_list) {
   global $user, $db_type;
   static $bcc; //biblio_contributor (bc) count , increase for every invocation
+  static $tcc; //term counter, increase for every invocation
   if ( !isset( $bcc ) ) $bcc = 0;
+  if ( !isset( $tcc ) ) $tcc = 0;
   $inline = $rss_info['feed'] = false;
   $joins = array();
   $selects = array();
@@ -144,7 +146,8 @@ function biblio_build_query($arg_list) {
 
   switch ($sort_attrib['sort']) {
     case 'type':
-      $sortby = "ORDER BY bt.name %s, b.biblio_year DESC ";
+      //$sortby = "ORDER BY bt.name %s, b.biblio_year DESC ";
+      $sortby = "ORDER BY bt.name %s, $sort_title";
       break;
     case 'title':
       //$sortby = "ORDER BY SUBSTRING(n.title,1,3) %s, b.biblio_year DESC ";
@@ -216,15 +219,16 @@ function biblio_build_query($arg_list) {
         case 'term':
         case 'term_id':
           $term = explode("?",array_shift($arg_list));
-          $joins[] = "inner join {term_node} as tn on n.vid = tn.vid";
+          $joins[] = "inner join {term_node} as tn".$tcc." on n.vid = tn".$tcc.".vid";
           if ($type == 'term') {
-            $joins[] = "inner join  {term_data} as td on tn.tid= td.tid";
+            $joins[] = "inner join  {term_data} as td on tn".$tcc.".tid= td.tid";
             $where[] = "td.name = '%s' ";
           }elseif ($type == 'term_id') {
-            $where[] = "tn.tid = '%d' ";
+            $where[] = "tn".$tcc.".tid = '%d' ";
           }
           $terms[] = db_escape_string($term[0]);
           array_push($args, $type, $term[0]);
+          $tcc++;
           break;
         case 'tg':
           $term = explode("?",array_shift($arg_list));
@@ -336,7 +340,8 @@ function biblio_build_query($arg_list) {
           break;
         case 'type':
           $term = db_escape_string(array_shift($arg_list));
-          $limit .= $operator. "b.biblio_type=%d ";
+          $where[] = "b.biblio_type=%d ";
+          //$limit .= $operator. "b.biblio_type=%d ";
           $terms[] = (int)$term;
           array_push($args, $type, (int)$term);
           $operator = NULL;
@@ -406,7 +411,6 @@ function biblio_build_query($arg_list) {
   $terms[] = $sort_attrib['order']; // this is either asc or desc to be inserted into the first term of the ORDER clause
   if($sort_attrib['sort'] == 'year') $terms[] = $sort_attrib['order']; // we need any extra order term when sorting by year since there are to date terms biblio_year and biblio_date
   $_SESSION['last_biblio_query_terms'] = $terms;
-
   return (array('query'      => $query,
                'query_terms' => $terms,
                'count_query' => $count_query,
@@ -479,7 +483,6 @@ function biblio_show_results($result, $a
   }
 
   $count = 0;
-
   while ($node = db_fetch_object($result)) {
     $count++;
     $node->biblio_contributors = biblio_load_contributors($node->vid);
@@ -621,12 +624,12 @@ function _biblio_filter_info_line($args)
       if ($type == 'type') {
         $pub_types = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid>0');
         while ($option = db_fetch_object($pub_types)) {
-          $pub_type["$option->tid"] = $option->name;
+          $pub_type["$option->tid"] = ucwords($option->name);
         }
         $value = $pub_type["$value"];
       }
       array_shift($args);
-      $params = array('%a' =>  $type , '%b' =>  $value );
+      $params = array('%a' =>  ucwords($type) , '%b' =>  $value );
       $filtercontent .= ($i++ ? t('<em> and</em> <strong>%a</strong> is <strong>%b</strong>', $params) : t('<strong>%a</strong> is <strong>%b</strong>', $params)) ;
     }
     if ($search_content) {
@@ -1161,4 +1164,4 @@ function _biblio_format_keyword($keyword
   $format   .= (user_access('administer biblio')) ? $edit_link: '';
 
   return $format;
-}
\ No newline at end of file
+}
