--- loncom/interface/loncommon.pm	2009/11/30 21:29:47	1.920
+++ loncom/interface/loncommon.pm	2010/08/08 02:00:38	1.973
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.920 2009/11/30 21:29:47 raeburn Exp $
+# $Id: loncommon.pm,v 1.973 2010/08/08 02:00:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -483,9 +483,9 @@ ENDAUTHORBRW
 
 sub coursebrowser_javascript {
     my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
-    my $wintitle = &mt('Course Browser');
-    if ($crstype ne '') {
-        $wintitle = &mt($crstype);
+    my $wintitle = 'Course_Browser';
+    if ($crstype eq 'Community') {
+        $wintitle = 'Community_Browser';
     }
     my $id_functions = &javascript_index_functions();
     my $output = '
@@ -900,7 +900,7 @@ sub select_language {
             $langchoices{$code} = &plainlanguagedescription($id);
         }
     }
-    return &select_form($selected,$name,%langchoices);
+    return &select_form($selected,$name,\%langchoices);
 }
 
 =pod
@@ -1072,7 +1072,7 @@ END
 
 =pod
 
-=item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
+=item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
 
 Returns a string corresponding to an HTML link to the given help
 $topic, where $topic corresponds to the name of a .tex file in
@@ -1090,12 +1090,16 @@ a new window using Javascript. (Default
 
 $width and $height are optional numerical parameters that will
 override the width and height of the popped up window, which may
-be useful for certain help topics with big pictures included. 
+be useful for certain help topics with big pictures included.
+
+$imgid is the id of the img tag used for the help icon. This may be
+used in a javascript call to switch the image src.  See 
+lonhtmlcommon::htmlareaselectactive() for an example.
 
 =cut
 
 sub help_open_topic {
-    my ($topic, $text, $stayOnPage, $width, $height) = @_;
+    my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
     $text = "" if (not defined $text);
     $stayOnPage = 0 if (not defined $stayOnPage);
     $width = 350 if (not defined $width);
@@ -1124,10 +1128,13 @@ sub help_open_topic {
     # (Always) Add the graphic
     my $title = &mt('Online Help');
     my $helpicon=&lonhttpdurl("/adm/help/help.png");
+    if ($imgid ne '') {
+        $imgid = ' id="'.$imgid.'"';
+    }
     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
               .'<img src="'.$helpicon.'" border="0"'
               .' alt="'.&mt('Help: [_1]',$topic).'"'
-              .' title="'.$title.'"' 
+              .' title="'.$title.'" style="vertical-align:middle;"'.$imgid 
               .' /></a>';
     if ($text ne "") {	
         $template.='</span>';
@@ -1202,12 +1209,7 @@ ENDOUTPUT
 sub help_open_menu {
     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
 	= @_;    
-    $stayOnPage = 0 if (not defined $stayOnPage);
-    # only use pop-up help (stayOnPage == 0)
-    # if environment.remote is on (using remote control UI)
-    if ($env{'environment.remote'} eq 'off' ) {
-        $stayOnPage=1;
-    }
+    $stayOnPage = 1;
     my $output;
     if ($component_help) {
 	if (!$text) {
@@ -1228,8 +1230,8 @@ sub help_open_menu {
 sub top_nav_help {
     my ($text) = @_;
     $text = &mt($text);
-    my $stay_on_page = 
-	($env{'environment.remote'} eq 'off' );
+    my $stay_on_page = 1;
+
     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
 	                     : "javascript:helpMenu('open')";
     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
@@ -1244,10 +1246,7 @@ END
 
 sub help_menu_js {
     my ($text) = @_;
-
-    my $stayOnPage = 
-	($env{'environment.remote'} eq 'off' );
-
+    my $stayOnPage = 1;
     my $width = 620;
     my $height = 600;
     my $helptopic=&general_help();
@@ -1304,10 +1303,7 @@ sub help_open_bug {
     unless ($env{'user.adv'}) { return ''; }
     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
     $text = "" if (not defined $text);
-    $stayOnPage = 0 if (not defined $stayOnPage);
-    if ($env{'environment.remote'} eq 'off' ) {
 	$stayOnPage=1;
-    }
     $width = 600 if (not defined $width);
     $height = 600 if (not defined $height);
 
@@ -1348,10 +1344,7 @@ sub help_open_faq {
     unless ($env{'user.adv'}) { return ''; }
     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
     $text = "" if (not defined $text);
-    $stayOnPage = 0 if (not defined $stayOnPage);
-    if ($env{'environment.remote'} eq 'off' ) {
 	$stayOnPage=1;
-    }
     $width = 350 if (not defined $width);
     $height = 400 if (not defined $height);
 
@@ -1719,10 +1712,13 @@ sub create_workbook {
     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
     if (! defined($workbook)) {
         $r->log_error("Error creating excel spreadsheet $filename: $!");
-        $r->print('<p>'.&mt("Unable to create new Excel file.  ".
-                            "This error has been logged.  ".
-                            "Please alert your LON-CAPA administrator").
-                  '</p>');
+        $r->print(
+            '<p class="LC_error">'
+           .&mt('Problems occurred in creating the new Excel file.')
+           .' '.&mt('This error has been logged.')
+           .' '.&mt('Please alert your LON-CAPA administrator.')
+           .'</p>'
+        );
         return (undef);
     }
     #
@@ -1762,9 +1758,13 @@ sub create_text_file {
     $fh = Apache::File->new('>/home/httpd'.$filename);
     if (! defined($fh)) {
         $r->log_error("Couldn't open $filename for output $!");
-        $r->print(&mt('Problems occurred in creating the output file. '
-                     .'This error has been logged. '
-                     .'Please alert your LON-CAPA administrator.'));
+        $r->print(
+            '<p class="LC_error">'
+           .&mt('Problems occurred in creating the output file.')
+           .' '.&mt('This error has been logged.')
+           .' '.&mt('Please alert your LON-CAPA administrator.')
+           .'</p>'
+        );
     }
     return ($fh,$filename)
 }
@@ -1793,7 +1793,7 @@ sub domain_select {
 	return &multiple_select_form($name,$value,4,\%domains);
     } else {
 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
-	return &select_form($name,$value,%domains);
+	return &select_form($name,$value,\%domains);
     }
 }
 
@@ -1855,29 +1855,36 @@ sub multiple_select_form {
 
 =pod
 
-=item * &select_form($defdom,$name,%hash)
+=item * &select_form($defdom,$name,$hashref,$onchange)
 
 Returns a string containing a <select name='$name' size='1'> form to 
-allow a user to select options from a hash option_name => displayed text.  
+allow a user to select options from a ref to a hash containing:
+option_name => displayed text. An optional $onchange can include
+a javascript onchange item, e.g., onchange="this.form.submit();"  
+
 See lonrights.pm for an example invocation and use.
 
 =cut
 
 #-------------------------------------------
 sub select_form {
-    my ($def,$name,%hash) = @_;
-    my $selectform = "<select name=\"$name\" size=\"1\">\n";
+    my ($def,$name,$hashref,$onchange) = @_;
+    return unless (ref($hashref) eq 'HASH');
+    if ($onchange) {
+        $onchange = ' onchange="'.$onchange.'"';
+    }
+    my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
     my @keys;
-    if (exists($hash{'select_form_order'})) {
-	@keys=@{$hash{'select_form_order'}};
+    if (exists($hashref->{'select_form_order'})) {
+	@keys=@{$hashref->{'select_form_order'}};
     } else {
-	@keys=sort(keys(%hash));
+	@keys=sort(keys(%{$hashref}));
     }
     foreach my $key (@keys) {
         $selectform.=
 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
             ($key eq $def ? 'selected="selected" ' : '').
-                ">".&mt($hash{$key})."</option>\n";
+                ">".$hashref->{$key}."</option>\n";
     }
     $selectform.="</select>";
     return $selectform;
@@ -1895,9 +1902,9 @@ sub display_filter {
            &mt('Filter [_1]',
 	   &select_form($env{'form.displayfilter'},
 			'displayfilter',
-			('currentfolder' => 'Current folder/page',
+			{'currentfolder' => 'Current folder/page',
 			 'containing' => 'Containing phrase',
-			 'none' => 'None'))).
+			 'none' => 'None'})).
 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
 }
 
@@ -3239,8 +3246,7 @@ sub filemimetype {
 sub filecategoryselect {
     my ($name,$value)=@_;
     return &select_form($value,$name,
-			'' => &mt('Any category'),
-			map { $_,$_ } sort(keys(%category_extensions)));
+                        {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
 }
 
 =pod
@@ -3405,12 +3411,22 @@ sub get_previous_attempt {
       }
       $prevattempts=&start_data_table().&start_data_table_header_row();
       $prevattempts.='<th>'.&mt('History').'</th>';
+      my %typeparts;
+      my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
       foreach my $key (sort(keys(%lasthash))) {
 	my ($ign,@parts) = split(/\./,$key);
 	if ($#parts > 0) {
 	  my $data=$parts[-1];
 	  pop(@parts);
-	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
+          if ($data eq 'type') {
+              unless ($showsurv) {
+                  my $id = join(',',@parts);
+                  $typeparts{$ign.'.'.$id} = $lasthash{$key};
+              }
+              delete($lasthash{$key});
+          } else {
+	      $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
+          }
 	} else {
 	  if ($#parts == 0) {
 	    $prevattempts.='<th>'.$parts[0].'</th>';
@@ -3420,23 +3436,98 @@ sub get_previous_attempt {
 	}
       }
       $prevattempts.=&end_data_table_header_row();
+      my %lasthidden;
       if ($getattempt eq '') {
 	for ($version=1;$version<=$returnhash{'version'};$version++) {
-	  $prevattempts.=&start_data_table_row().
-	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
-	    foreach my $key (sort(keys(%lasthash))) {
-		my $value = &format_previous_attempt_value($key,
-							   $returnhash{$version.':'.$key});
-		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
-	    }
-	  $prevattempts.=&end_data_table_row();
+            my @hidden;
+            if (%typeparts) {
+                foreach my $id (keys(%typeparts)) {
+                    if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
+                        push(@hidden,$id);
+                        $lasthidden{$id} = 1;
+                    } elsif ($lasthidden{$id}) {
+                        if (exists($returnhash{$version.':'.$id.'.award'})) {
+                            delete($lasthidden{$id});
+                        }
+                    }
+                }
+            }
+            $prevattempts.=&start_data_table_row().
+                           '<td>'.&mt('Transaction [_1]',$version).'</td>';
+            if (@hidden) {
+                foreach my $key (sort(keys(%lasthash))) {
+                    my $hide;
+                    foreach my $id (@hidden) {
+                        if ($key =~ /^\Q$id\E/) {
+                            $hide = 1;
+                            last;
+                        }
+                    }
+                    if ($hide) {
+                        my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
+                        if (($data eq 'award') || ($data eq 'awarddetail')) {
+                            my $value = &format_previous_attempt_value($key,
+                                             $returnhash{$version.':'.$key});
+                            $prevattempts.='<td>'.$value.'&nbsp;</td>';
+                        } else {
+                            $prevattempts.='<td>&nbsp;</td>';
+                        }
+                    } else {
+                        if ($key =~ /\./) {
+                            my $value = &format_previous_attempt_value($key,
+                                              $returnhash{$version.':'.$key});
+                            $prevattempts.='<td>'.$value.'&nbsp;</td>';
+                        } else {
+                            $prevattempts.='<td>&nbsp;</td>';
+                        }
+                    }
+                }
+            } else {
+	        foreach my $key (sort(keys(%lasthash))) {
+		    my $value = &format_previous_attempt_value($key,
+			            $returnhash{$version.':'.$key});
+		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
+	        }
+            }
+	    $prevattempts.=&end_data_table_row();
 	 }
       }
+      my @currhidden = keys(%lasthidden);
       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
       foreach my $key (sort(keys(%lasthash))) {
-	my $value = &format_previous_attempt_value($key,$lasthash{$key});
-	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
-	$prevattempts.='<td>'.$value.'&nbsp;</td>';
+          if (%typeparts) {
+              my $hidden;
+              foreach my $id (@currhidden) {
+                  if ($key =~ /^\Q$id\E/) {
+                      $hidden = 1;
+                      last;
+                  }
+              }
+              if ($hidden) {
+                  my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
+                  if (($data eq 'award') || ($data eq 'awarddetail')) {
+                      my $value = &format_previous_attempt_value($key,$lasthash{$key});
+                      if ($key =~/$regexp$/ && (defined &$gradesub)) {
+                          $value = &$gradesub($value);
+                      }
+                      $prevattempts.='<td>'.$value.'&nbsp;</td>';
+                  } else {
+                      $prevattempts.='<td>&nbsp;</td>';
+                  }
+              } else {
+                  my $value = &format_previous_attempt_value($key,$lasthash{$key});
+                  if ($key =~/$regexp$/ && (defined &$gradesub)) {
+                      $value = &$gradesub($value);
+                  }
+                  $prevattempts.='<td>'.$value.'&nbsp;</td>';
+              }
+          } else {
+	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
+	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
+                  $value = &$gradesub($value);
+              }
+	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
+          }
       }
       $prevattempts.= &end_data_table_row().&end_data_table();
     } else {
@@ -3609,10 +3700,13 @@ sub submlink {
     }
     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
     $symb=&escape($symb);
-    if ($target) { $target="target=\"$target\""; }
-    return '<a href="/adm/grades?&command=submission&'.
-	'symb='.$symb.'&student='.$uname.
-	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
+    if ($target) { $target=" target=\"$target\""; }
+    return
+        '<a href="/adm/grades?command=submission'.
+        '&amp;symb='.$symb.
+        '&amp;student='.$uname.
+        '&amp;userdom='.$udom.'"'.
+        $target.'>'.$text.'</a>';
 }
 ##############################################
 
@@ -4139,16 +4233,39 @@ sub get_domainconf {
     if (defined($cached)) { return %{$result}; }
 
     my %domconfig = &Apache::lonnet::get_dom('configuration',
-					     ['login','rolecolors'],$udom);
+					     ['login','rolecolors','autoenroll'],$udom);
     my (%designhash,%legacy);
     if (keys(%domconfig) > 0) {
         if (ref($domconfig{'login'}) eq 'HASH') {
             if (keys(%{$domconfig{'login'}})) {
                 foreach my $key (keys(%{$domconfig{'login'}})) {
                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
-                        foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
-                            $designhash{$udom.'.login.'.$key.'_'.$img} = 
-                                $domconfig{'login'}{$key}{$img};
+                        if ($key eq 'loginvia') {
+                            if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
+                                my @ids = &Apache::lonnet::current_machine_ids();
+                                foreach my $hostname (@ids) {
+                                    if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
+                                        if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
+                                            my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
+                                            $designhash{$udom.'.login.loginvia'} = $server;
+                                            if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
+
+                                                $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
+                                            } else {
+                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
+                                            }
+                                            if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
+                                                $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        } else {
+                            foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
+                                $designhash{$udom.'.login.'.$key.'_'.$img} = 
+                                    $domconfig{'login'}{$key}{$img};
+                            }
                         }
                     } else {
                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
@@ -4175,6 +4292,11 @@ sub get_domainconf {
         } else {
             $legacy{'rolecolors'} = 1;
         }
+        if (ref($domconfig{'autoenroll'}) eq 'HASH') {
+            if ($domconfig{'autoenroll'}{'co-owners'}) {
+                $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
+            }
+        }
         if (keys(%legacy) > 0) {
             my %legacyhash = &get_legacy_domconf($udom);
             foreach my $item (keys(%legacyhash)) {
@@ -4367,18 +4489,30 @@ sub CSTR_pageheader {
     } else {
         $lastitem = $thisdisfn;
     }
-    return
+
+    my $output =
          '<div>'
         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
         .'<b>'.&mt('Construction Space:').'</b> '
         .'<form name="dirs" method="post" action="'.$formaction
-        .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
-        .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
+        .'" target="_top">' #FIXME lonpubdir: target="_parent"
+        .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
+
+    if ($lastitem) {
+        $output .=
+             '<span class="LC_filename">'
+            .$lastitem
+            .'</span>';
+    }
+    $output .=
+         '<br />'
         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
         .'</form>'
         .&Apache::lonmenu::constspaceform()
         .'</div>';
+
+    return $output;
 }
 
 ###############################################
@@ -4418,9 +4552,6 @@ Inputs:
 
 =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
 
-=item * $no_inline_link, if true and in remote mode, don't show the 
-         'Switch To Inline Menu' link
-
 =item * $args, optional argument valid values are
             no_auto_mt_title -> prevents &mt()ing the title arg
             inherit_jsmath -> when creating popup window in a page,
@@ -4438,8 +4569,13 @@ other decorations will be returned.
 
 sub bodytag {
     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
-        $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
+        $no_nav_bar,$bgcolor,$args)=@_;
 
+    my $public;
+    if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
+        || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
+        $public = 1;
+    }
     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
 
     $function = &get_users_function() if (!$function);
@@ -4475,8 +4611,6 @@ sub bodytag {
     }
 
     if (!$realm) { $realm='&nbsp;'; }
-# Set messages
-    my $messages=&domainlogo($domain);
 
     my $extra_body_attr = &make_attr_string($forcereg,\%design);
 
@@ -4489,7 +4623,7 @@ sub bodytag {
     } 
 
     my $name = &plainname($env{'user.name'},$env{'user.domain'});
-    if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
+    if ($public) {
 	undef($role);
     } else {
 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
@@ -4510,8 +4644,6 @@ sub bodytag {
     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
 
-    if ($env{'environment.remote'} eq 'off') {
-        # No Remote
         if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
             return $bodytag; 
         } 
@@ -4533,7 +4665,9 @@ sub bodytag {
             return $bodytag;
         }
 
-        $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
+        unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
+            $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
+        }
 
         $bodytag .= Apache::lonhtmlcommon::scripttag(
             Apache::lonmenu::utilityfunctions(), 'start');
@@ -4546,12 +4680,12 @@ sub bodytag {
         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
 
         #don't show menus for public users
-        if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
+        if (!$public){
             $bodytag .= Apache::lonmenu::secondary_menu();
             $bodytag .= Apache::lonmenu::serverform();
             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
             if ($env{'request.state'} eq 'construct') {
-                $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
+                $bodytag .= &Apache::lonmenu::innerregister($forcereg,
                                 $args->{'bread_crumbs'});
             } elsif ($forcereg) { 
                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);
@@ -4563,43 +4697,7 @@ sub bodytag {
             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
         }
 
-        #SD testing
-        #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
         return $bodytag;
-    }
-
-#
-# Top frame rendering, Remote is up
-#
-
-    my $imgsrc = $img;
-    if ($img =~ /^\/adm/) {
-        $imgsrc = &lonhttpdurl($img);
-    }
-    my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
-
-    # Explicit link to get inline menu
-    my $menu= ($no_inline_link?''
-	       :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
-
-    if ($dc_info) {
-        $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
-    }
-
-    $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
-            <ol class="LC_primary_menu LC_right">
-                <li>$menu</li>
-            </ol><div id="LC_realm"> $realm $dc_info</div>| unless $env{'form.inhibitmenu'};
-    return(<<ENDBODY);
-$bodytag
-<table id="LC_title_bar" class="LC_with_remote">
-<tr><td>$upperleft</td>
-    <td>$messages&nbsp;</td>
-</tr>
-<tr><td>$titleinfo $dc_info $menu</td>
-</tr>
-</table>
-ENDBODY
 }
 
 sub dc_courseid_toggle {
@@ -4631,22 +4729,8 @@ sub make_attr_string {
 		delete($attr_ref->{$key});
 	    }
 	}
-	$attr_ref->{'onload'}  =
-	    &Apache::lonmenu::loadevents().  $on_load;
-	$attr_ref->{'onunload'}=
-	    &Apache::lonmenu::unloadevents().$on_unload;
-    }
-
-# Accessibility font enhance
-    if ($env{'browser.fontenhance'} eq 'on') {
-	my $style;
-	foreach my $key (keys(%{$attr_ref})) {
-	    if (lc($key) eq 'style') {
-		$style.=$attr_ref->{$key}.';';
-		delete($attr_ref->{$key});
-	    }
-	}
-	$attr_ref->{'style'}=$style.'; font-size: x-large;';
+	$attr_ref->{'onload'}  = $on_load;
+	$attr_ref->{'onunload'}= $on_unload;
     }
 
     my $attr_string;
@@ -4720,10 +4804,6 @@ sub standard_css {
     my $vlink  = &designparm($function.'.vlink', $domain);
     my $link   = &designparm($function.'.link',  $domain);
 
-    my $loginbg = &designparm('login.sidebg',$domain);
-    my $bgcol = &designparm('login.bgcol',$domain);
-    my $textcol = &designparm('login.textcol',$domain);
-
     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
     my $mono                 = 'monospace';
     my $data_table_head      = $sidebg;
@@ -4742,6 +4822,7 @@ sub standard_css {
     my $table_header         = '#DDDDDD';
     my $feedback_link_bg     = '#BBBBBB';
     my $lg_border_color      = '#C8C8C8';
+    my $button_hover         = '#BF2317';
 
     my $border = ($env{'browser.type'} eq 'explorer' ||
       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
@@ -4749,6 +4830,14 @@ sub standard_css {
 
 
     return <<END;
+
+/* needed for iframe to allow 100% height in FF */
+body, html { 
+    margin: 0;
+    padding: 0 0.5%;
+    height: 99%; /* to avoid scrollbars */
+}
+
 body {
   font-family: $sans;
   line-height:130%;
@@ -4756,12 +4845,8 @@ body {
   color:$font;
 }
 
-a:link,
-a:visited {
-  font-size:100%;
-}
-
-a:focus {
+a:focus,
+a:focus img {
   color: red;
   background: yellow;
 }
@@ -4778,15 +4863,28 @@ form, .inline {
   vertical-align:middle;
 }
 
-/* just for tests */
 .LC_400Box {
   width:400px;
 }
-/* end */
+
+.LC_iframecontainer {
+    width: 98%;
+    margin: 0;
+    position: fixed;
+    top: 8.5em;
+    bottom: 0;
+}
+
+.LC_iframecontainer iframe{
+    border: none;
+    width: 100%;
+    height: 100%;
+}
 
 .LC_filename {
   font-family: $mono;
   white-space:pre;
+  font-size: 120%;
 }
 
 .LC_fileicon {
@@ -4877,9 +4975,7 @@ table.LC_pastsubmission {
   margin: 2px;
 }
 
-table#LC_top_nav,
-table#LC_menubuttons,
-table#LC_nav_location {
+table#LC_menubuttons {
   width: 100%;
   background: $pgbg;
   border: 2px;
@@ -4897,7 +4993,7 @@ table#LC_title_bar {
 }
 
 table#LC_title_bar,
-table.LC_breadcrumbs,
+table.LC_breadcrumbs, /* obsolete? */
 table#LC_title_bar.LC_with_remote {
   width: 100%;
   border-color: $pgbg;
@@ -4910,46 +5006,26 @@ table#LC_title_bar.LC_with_remote {
   margin: 0;
 }
 
-/* #SD START (work in progress)*/
-
-ul.LC_bct {
+ul.LC_breadcrumb_tools_outerlist {
     margin: 0;
     padding: 0;
+    position: relative;
+    list-style: none;
 }
-ul.LC_bct ol {
+ul.LC_breadcrumb_tools_outerlist li {
     display: inline;
 }
-ul.LC_bct ul {
-    display: inline;
-    padding: 0;
-}
-ul.LC_bct li {
-    list-style-type: none;
-    display: inline;
-}
-
-
-ul.LC_breadcrumb_tools {
-}
 
-li.LC_breadcrumb_tools {
-}
-li.LC_breadcrumb_tools img{
-    vertical-align: middle;
-}
-
-.LC_breadcrumb_tools_A {
-    margin: 0 0 0 1em;
-}
-.LC_breadcrumb_tools_B {
-    float: right;
-    margin-top: 0.4em;
+.LC_breadcrumb_tools_navigation {
+    padding: 0;
+    margin: 0;
+    float: left;
 }
-.LC_breadcrumb_tools_C {
-    margin: 0 1em 0 0;
+.LC_breadcrumb_tools_tools {
+    padding: 0;
+    margin: 0;
     float: right;
 }
-/* #SD END */
 
 table#LC_title_bar td {
   background: $tabbg;
@@ -4959,41 +5035,6 @@ table#LC_menubuttons img {
   border: none;
 }
 
-table#LC_top_nav td {
-  background: $tabbg;
-  border: none;
-  font-size: small;
-  vertical-align:top;
-  padding:2px 5px 2px 5px;
-}
-
-table#LC_top_nav td a,
-div#LC_top_nav a {
-  color: $font;
-}
-
-table#LC_top_nav td.LC_top_nav_logo {
-  background: $tabbg;
-  text-align: left;
-  white-space: nowrap;
-  width: 31px;
-}
-
-table#LC_top_nav td.LC_top_nav_logo img {
-  border: none;
-  vertical-align: bottom;
-}
-
-table#LC_top_nav td.LC_top_nav_exit,
-table#LC_top_nav td.LC_top_nav_help {
-  width: 2.0em;
-}
-
-table#LC_top_nav td.LC_top_nav_login {
-  width: 4.0em;
-  text-align: center;
-}
-
 .LC_breadcrumbs_component {
   float: right;
   margin: 0 1em;
@@ -5006,10 +5047,6 @@ td.LC_table_cell_checkbox {
   text-align: center;
 }
 
-table#LC_mainmenu td.LC_mainmenu_column {
-  vertical-align: top;
-}
-
 .LC_fontsize_small {
   font-size: 70%;
 }
@@ -5019,23 +5056,17 @@ table#LC_mainmenu td.LC_mainmenu_column
   background: $sidebg;
   border-bottom: 1px solid $lg_border_color;
   line-height: 2.5em;
-     /* SD working here 
-     height: 2.5em;
-     overflow: hidden; */
+  overflow: hidden;
   margin: 0;
   padding: 0;
 }
 
-/* Preliminary fix to hide breadcrumbs inside remote control window */
-#LC_remote #LC_breadcrumbs {
-  display:none;
-}
-
 #LC_head_subbox {
   clear:both;
   background: #F8F8F8; /* $sidebg; */
   border: 1px solid $sidebg;
   margin: 0 0 10px 0;      
+  padding: 3px;
 }
 
 .LC_fontsize_medium {
@@ -5052,6 +5083,14 @@ table#LC_mainmenu td.LC_mainmenu_column
   padding-left:3px;
 }
 
+.LC_menubuttons_inline_text img{
+  vertical-align: middle;
+}
+
+li.LC_menubuttons_inline_text img,a {
+  cursor:pointer;
+}
+
 .LC_menubuttons_link {
   text-decoration: none;
 }
@@ -5071,13 +5110,7 @@ td.LC_menubuttons_text {
   background: $tabbg;
 }
 
-.LC_new_mail {
-  background: $tabbg;
-  font-weight: bold;
-}
-
-table.LC_data_table,
-table.LC_mail_list {
+table.LC_data_table {
   border: 1px solid #000000;
   border-collapse: separate;
   border-spacing: 1px;
@@ -5103,9 +5136,16 @@ table.LC_nested {
   width: 100%;
 }
 
+.ui-accordion,
+.ui-accordion table.LC_data_table,
+.ui-accordion table.LC_nested_outer{
+  border: 0px;
+  border-spacing: 0px;
+  margin: 3px;
+}
+
 table.LC_data_table tr th,
 table.LC_calendar tr th,
-table.LC_mail_list tr th,
 table.LC_prior_tries tr th,
 table.LC_innerpickbox tr th {
   font-weight: bold;
@@ -5158,13 +5198,20 @@ table.LC_data_table tr td.LC_leftcol_hea
 
 table.LC_data_table tr.LC_empty_row td,
 table.LC_nested tr.LC_empty_row td {
-  background-color: #FFFFFF;
   font-weight: bold;
   font-style: italic;
   text-align: center;
   padding: 8px;
 }
 
+table.LC_data_table tr.LC_empty_row td {
+  background-color: $sidebg;
+}
+
+table.LC_nested tr.LC_empty_row td {
+  background-color: #FFFFFF;
+}
+
 table.LC_caption {
 }
 
@@ -5212,6 +5259,22 @@ table.LC_nested tr td.LC_right_item {
   text-align: right;
 }
 
+.ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
+.ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
+  text-align: right;
+  width: 40%;
+  padding-right:10px;
+  vertical-align: top;
+  padding: 5px;
+}
+
+.ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
+.ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
+  text-align: left;
+  width: 60%;
+  padding: 2px 4px;
+}
+
 table.LC_nested tr.LC_odd_row td {
   background-color: #EEEEEE;
 }
@@ -5253,43 +5316,43 @@ table.LC_calendar tr td.LC_calendar_day_
   background-color: $data_table_highlight;
 }
 
-table.LC_mail_list tr.LC_mail_new {
+table.LC_data_table tr td.LC_mail_new {
   background-color: $mail_new;
 }
 
-table.LC_mail_list tr.LC_mail_new:hover {
+table.LC_data_table tr.LC_mail_new:hover {
   background-color: $mail_new_hover;
 }
 
-table.LC_mail_list tr.LC_mail_even {
-}
-
-table.LC_mail_list tr.LC_mail_odd {
-}
-
-table.LC_mail_list tr.LC_mail_read {
+table.LC_data_table tr td.LC_mail_read {
   background-color: $mail_read;
 }
 
-table.LC_mail_list tr.LC_mail_read:hover {
+/*
+table.LC_data_table tr.LC_mail_read:hover {
   background-color: $mail_read_hover;
 }
+*/
 
-table.LC_mail_list tr.LC_mail_replied {
+table.LC_data_table tr td.LC_mail_replied {
   background-color: $mail_replied;
 }
 
-table.LC_mail_list tr.LC_mail_replied:hover {
+/*
+table.LC_data_table tr.LC_mail_replied:hover {
   background-color: $mail_replied_hover;
 }
+*/
 
-table.LC_mail_list tr.LC_mail_other {
+table.LC_data_table tr td.LC_mail_other {
   background-color: $mail_other;
 }
 
-table.LC_mail_list tr.LC_mail_other:hover {
+/*
+table.LC_data_table tr.LC_mail_other:hover {
   background-color: $mail_other_hover;
 }
+*/
 
 table.LC_data_table tr > td.LC_browser_file,
 table.LC_data_table tr > td.LC_browser_file_published {
@@ -5319,23 +5382,23 @@ table.LC_data_table tr > td.LC_roles_is
 }
 
 table.LC_data_table tr > td.LC_roles_future {
-  background: #FFFF77;
+  border-right: 8px solid #FFFF77;
 }
 
 table.LC_data_table tr > td.LC_roles_will {
-  background: #FFAA77;
+  border-right: 8px solid #FFAA77;
 }
 
 table.LC_data_table tr > td.LC_roles_expired {
-  background: #FF7777;
+  border-right: 8px solid #FF7777;
 }
 
 table.LC_data_table tr > td.LC_roles_will_not {
-  background: #AAFF77;
+  border-right: 8px solid #AAFF77;
 }
 
 table.LC_data_table tr > td.LC_roles_selected {
-  background: #11CC55;
+  border-right: 8px solid #11CC55;
 }
 
 span.LC_current_location {
@@ -5530,16 +5593,6 @@ table.LC_group_priv td {
   padding: 0;
 }
 
-table.LC_notify_front_page {
-  background: white;
-  border: 1px solid black;
-  padding: 8px;
-}
-
-table.LC_notify_front_page td {
-  padding: 8px;
-}
-
 .LC_navbuttons {
   margin: 2ex 0ex 2ex 0ex;
 }
@@ -5559,10 +5612,6 @@ table.LC_notify_front_page td {
   font-size: 1.2em;
 }
 
-.LC_topic_bar img {
-  vertical-align: bottom;
-}
-
 table.LC_course_group_status {
   margin: 20px;
 }
@@ -5672,12 +5721,12 @@ span.LC_prior_string,
 span.LC_prior_custom,
 span.LC_prior_reaction,
 span.LC_prior_math {
-  font-family: monospace;
+  font-family: $mono;
   white-space: pre;
 }
 
 span.LC_prior_string {
-  font-family: monospace;
+  font-family: $mono;
   white-space: pre;
 }
 
@@ -5710,17 +5759,6 @@ span.LC_cusr_subheading {
   font-size: 85%;
 }
 
-table.LC_docs_documents {
-  background: #BBBBBB;
-  border-width: 0;
-  border-collapse: collapse;
-}
-
-table.LC_docs_documents td.LC_docs_document {
-  border: 2px solid black;
-  padding: 4px;
-}
-
 div.LC_docs_entry_move {
   border: 1px solid #BBBBBB;
   background: #DDDDDD;
@@ -5812,56 +5850,41 @@ div.LC_clear_float_footer {
 }
 
 div.LC_grade_show_user {
-  margin-top: 20px;
-  border: 1px solid black;
+/*  border-left: 5px solid $sidebg; */
+  border-top: 5px solid #000000;
+  margin: 50px 0 0 0;
+  padding: 15px 0 5px 10px;
 }
 
-div.LC_grade_user_name {
-  background: #DDDDEE;
-  border-bottom: 1px solid black;
-  font-weight: bold;
-  font-size: large;
+div.LC_grade_show_user_odd_row {
+/*  border-left: 5px solid #000000; */
 }
 
-div.LC_grade_show_user_odd_row div.LC_grade_user_name {
-  background: #DDEEDD;
+div.LC_grade_show_user div.LC_Box {
+  margin-right: 50px;
 }
 
-div.LC_grade_show_problem,
 div.LC_grade_submissions,
 div.LC_grade_message_center,
-div.LC_grade_info_links,
-div.LC_grade_assign {
+div.LC_grade_info_links {
   margin: 5px;
   width: 99%;
   background: #FFFFFF;
 }
 
-div.LC_grade_show_problem_header,
 div.LC_grade_submissions_header,
-div.LC_grade_message_center_header,
-div.LC_grade_assign_header {
+div.LC_grade_message_center_header {
   font-weight: bold;
   font-size: large;
 }
 
-div.LC_grade_show_problem_problem,
 div.LC_grade_submissions_body,
-div.LC_grade_message_center_body,
-div.LC_grade_assign_body {
+div.LC_grade_message_center_body {
   border: 1px solid black;
   width: 99%;
   background: #FFFFFF;
 }
 
-span.LC_grade_check_note {
-  font-weight: normal;
-  font-size: medium;
-  display: inline;
-  position: absolute;
-  right: 1em;
-}
-
 table.LC_scantron_action {
   width: 100%;
 }
@@ -5895,15 +5918,8 @@ div.LC_edit_problem_header_title {
 }
 
 table.LC_edit_problem_header_title {
-  font-size: larger;
-  font-weight:  bold;
   width: 100%;
-  border-color: $pgbg;
-  border-style: solid;
-  border-width: $border;
   background: $tabbg;
-  border-collapse: collapse;
-  padding: 0;
 }
 
 div.LC_edit_problem_discards {
@@ -5921,21 +5937,8 @@ img.stift {
   vertical-align: middle;
 }
 
-table#LC_mainmenu {
-  margin-top:10px;
-  width:80%;
-}
-
-table#LC_mainmenu td.LC_mainmenu_col_fieldset {
+table td.LC_mainmenu_col_fieldset {
   vertical-align: top;
-  width: 45%;
-}
-
-.LC_mainmenu_fieldset_category {
-  color: $font;
-  background: $pgbg;
-  font-size: small;
-  font-weight: bold;
 }
 
 div.LC_createcourse {
@@ -5949,13 +5952,6 @@ div.LC_createcourse {
   display:none;
 }
 
-/* ---- Remove when done ----
-# The following styles is part of the redesign of LON-CAPA and are
-# subject to change during this project.
-# Don't rely on their current functionality as they might be 
-# changed or removed.
-# --------------------------*/
-
 a:hover,
 ol.LC_primary_menu a:hover,
 ol#LC_MenuBreadcrumbs a:hover,
@@ -5963,7 +5959,7 @@ ol#LC_PathBreadcrumbs a:hover,
 ul#LC_secondary_menu a:hover,
 .LC_FormSectionClearButton input:hover
 ul.LC_TabContent   li:hover a {
-  color:#BF2317;
+  color:$button_hover;
   text-decoration:none;
 }
 
@@ -5998,12 +5994,6 @@ h6 {
   border: 0;
 }
 
-.LC_Right {
-  float: right;
-  margin: 0;
-  padding: 0;
-}
-
 .LC_FormSectionClearButton input {
   background-color:transparent;
   border: none;
@@ -6036,7 +6026,7 @@ fieldset > legend {
 
 #LC_nav_bar {
   float: left;
-  margin: 0.2em 0 0 0;
+  margin: 0 0 2px 0;
 }
 
 #LC_realm {
@@ -6051,9 +6041,14 @@ fieldset > legend {
   font-style: normal;
 }
 
+/* Preliminary fix to hide nav_bar inside bookmarks window */
+#LC_bookmarks #LC_nav_bar {
+  display:none;
+}
+
 ol.LC_primary_menu {
   float: right;
-  margin: 0.2em 0 0 0;
+  margin: 0;
 }
 
 ol#LC_PathBreadcrumbs {
@@ -6068,14 +6063,19 @@ ol.LC_primary_menu li {
 
 ol.LC_primary_menu li img {
   vertical-align: bottom;
+  height: 1.1em;
 }
 
 ol.LC_primary_menu a {
-  font-size: 90%;
   color: RGB(80, 80, 80);
   text-decoration: none;
 }
 
+ol.LC_primary_menu a.LC_new_message {
+  font-weight:bold;
+  color: darkred;
+}
+
 ul#LC_secondary_menu {
   clear: both;
   color: $fontmenu;
@@ -6115,14 +6115,15 @@ ul#LC_secondary_menu li a {
 }
 
 ul.LC_TabContent {
-  min-height:1.5em;
+  min-height:20px;
 }
 
 ul.LC_TabContent li {
   vertical-align:middle;
-  padding: 0 10px 0 10px;
+  padding: 0 16px 0 10px;
   background-color:$tabbg;
   border-bottom:solid 1px $lg_border_color;
+  border-right: solid 1px $font;
 }
 
 ul.LC_TabContent .right {
@@ -6135,16 +6136,33 @@ ul.LC_TabContent li {
   text-decoration:none;
   font-size:95%;
   font-weight:bold;
-  padding-right: 16px;
+  min-height:20px;
+}
+
+ul.LC_TabContent li a:hover,
+ul.LC_TabContent li a:focus {
+  color: $button_hover;
+  background:none;
+  outline:none;
+}
+
+ul.LC_TabContent li:hover {
+  color: $button_hover;
+  cursor:pointer;
 }
 
-ul.LC_TabContent li:hover,
 ul.LC_TabContent li.active {
+  color: $font;
   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
-  border-bottom:solid 2px #FFFFFF;
-  padding-right: 16px;
+  border-bottom:solid 1px #FFFFFF;
+  cursor: default;
 }
 
+ul.LC_TabContent li.active a {
+  color:$font;
+  background:#FFFFFF;
+  outline: none;
+}
 #maincoursedoc {
   clear:both;
 }
@@ -6163,6 +6181,10 @@ ul.LC_TabContentBigger li {
   color: #737373;
 }
 
+ul.LC_TabContentBigger li.active {
+  position: relative;
+  top: 1px;
+}
 
 ul.LC_TabContentBigger li a {
   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
@@ -6171,28 +6193,31 @@ ul.LC_TabContentBigger li a {
   text-align: center;
   display: block;
   text-decoration: none;
+  outline: none;  
 }
 
-ul.LC_TabContentBigger li:hover a,
 ul.LC_TabContentBigger li.active a {
   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
   color:$font;
-  text-decoration: underline;
 }
 
-
 ul.LC_TabContentBigger li b {
   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
   display: block;
   float: left;
   padding: 0 30px;
+  border-bottom: 1px solid $lg_border_color;
+}
+
+ul.LC_TabContentBigger li:hover b {
+  color:$button_hover;
 }
 
-ul.LC_TabContentBigger li:hover b,
 ul.LC_TabContentBigger li.active b {
   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
   color:$font;
-  border-bottom: 1px solid #FFFFFF;
+  border: 0;
+  cursor:default;
 }
 
 
@@ -6209,18 +6234,14 @@ ol#LC_MenuBreadcrumbs,
 ol#LC_PathBreadcrumbs {
   padding-left: 10px;
   margin: 0;
-  list-style-position: inside;
-    /* SD working here 
-    white-space: nowrap; */
+  height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
 }
 
 ol#LC_MenuBreadcrumbs li,
 ol#LC_PathBreadcrumbs li,
 ul.LC_CourseBreadcrumbs li {
   display: inline;
-  white-space: nowrap;
-    /* SD working here  
-    white-space: normal; */ 
+  white-space: normal;  
 }
 
 ol#LC_MenuBreadcrumbs li a,
@@ -6229,6 +6250,14 @@ ul.LC_CourseBreadcrumbs li a {
   font-size:90%;
 }
 
+ol#LC_MenuBreadcrumbs h1 {
+  display: inline;
+  font-size: 90%;
+  line-height: 2.5em;
+  margin: 0;
+  padding: 0;
+}
+
 ol#LC_PathBreadcrumbs li a {
   text-decoration:none;
   font-size:100%;
@@ -6261,7 +6290,6 @@ dl.LC_ListStyleClean dd {
 .LC_ListStyleClean,
 .LC_ListStyleSimple,
 .LC_ListStyleNormal,
-.LC_ListStyle_Border,
 .LC_ListStyleSpecial {
   /* display:block; */
   list-style-position: inside;
@@ -6326,52 +6354,6 @@ div.LC_columnSection>* {
   overflow:hidden;
 }
 
-.LC_loginpage_container {
-  text-align:left;
-  margin : 0 auto;
-  width:90%;
-  padding: 10px;
-  height: auto;
-  background-color:#FFFFFF;
-  border:1px solid #CCCCCC;
-}
-
-
-.LC_loginpage_loginContainer {
-  float:left;
-  width: 182px;
-  padding: 2px;
-  border:1px solid #CCCCCC;
-  background-color:$loginbg;
-}
-
-.LC_loginpage_loginContainer h2 {
-  margin-top: 0;
-  display:block;
-  background:$bgcol;
-  color:$textcol;
-  padding-left:5px;
-}
-
-.LC_loginpage_loginInfo {
-  float:left;
-  width:182px;
-  border:1px solid #CCCCCC;
-  padding:2px;
-}
-
-.LC_loginpage_space {
-  clear: both;
-  margin-bottom: 20px;
-  border-bottom: 1px solid #CCCCCC;
-}
-
-.LC_loginpage_floatLeft {
-  float: left;
-  width: 200px;
-  margin: 0;
-}
-
 table em {
   font-weight: bold;
   font-style: normal;
@@ -6396,11 +6378,6 @@ table.LC_tableOfContent a {
   text-decoration: none;
 }
 
-table.LC_tableBrowseRes tr.LC_trOdd,
-table.LC_tableOfContent tr.LC_trOdd {
-  background-color: #EEEEEE;
-}
-
 table.LC_tableOfContent img {
   border: none;
   height: 1.3em;
@@ -6412,14 +6389,6 @@ a#LC_content_toolbar_firsthomework {
   background-image:url(/res/adm/pages/open-first-problem.gif);
 }
 
-a#LC_content_toolbar_launchnav {
-  background-image:url(/res/adm/pages/start-navigation.gif);
-}
-
-a#LC_content_toolbar_closenav {
-  background-image:url(/res/adm/pages/close-navigation.gif);
-}
-
 a#LC_content_toolbar_everything {
   background-image:url(/res/adm/pages/show-all.gif);
 }
@@ -6479,6 +6448,11 @@ ul.LC_funclist {
     padding: 0.5em 1em 0.5em 0;
 }
 
+ul.LC_funclist > li:first-child {
+    font-weight:bold; 
+    margin-left:0.8em;
+}
+
 ul.LC_funclist + ul.LC_funclist {
     /* 
        left border as a seperator if we have more than
@@ -6499,6 +6473,11 @@ ul.LC_funclist li {
   line-height: 150%;
 }
 
+.ui-accordion .LC_advanced_toggle {
+  float: right;
+  font-size: 90%;
+  padding: 0px 4px
+}
 
 END
 }
@@ -6551,8 +6530,8 @@ sub headtag {
     if (!$args->{'frameset'}) {
 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
     }
-    if ($args->{'force_register'}) {
-	$result .= &Apache::lonmenu::registerurl(1);
+    if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
+        $result .= Apache::lonxml::display_title();
     }
     if (!$args->{'no_nav_bar'} 
 	&& !$args->{'only_body'}
@@ -6578,7 +6557,7 @@ ADDMETA
     $result .= '<title> LON-CAPA '.$title.'</title>'
 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
 	.$head_extra;
-    return $result;
+    return $result.'</head>';
 }
 
 =pod
@@ -6613,10 +6592,6 @@ Inputs: none
 sub xml_begin {
     my $output='';
 
-    if ($env{'internal.start_page'}==1) {
-	&Apache::lonhtmlcommon::init_htmlareafields();
-    }
-
     if ($env{'browser.mathml'}) {
 	$output='<?xml version="1.0"?>'
             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
@@ -6635,43 +6610,6 @@ sub xml_begin {
 
 =pod
 
-=item * &endheadtag()
-
-Returns a uniform </head> for LON-CAPA web pages.
-
-Inputs: none
-
-=cut
-
-sub endheadtag {
-    return '</head>';
-}
-
-=pod
-
-=item * &head()
-
-Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
-
-Inputs:
-
-=over 4
-
-$title - optional title for the page
-
-$head_extra - optional extra HTML to put inside the <head>
-
-=back
-
-=cut
-
-sub head {
-    my ($title,$head_extra,$args) = @_;
-    return &headtag($title,$head_extra,$args).&endheadtag();
-}
-
-=pod
-
 =item * &start_page()
 
 Returns a complete <html> .. <body> section for LON-CAPA web pages.
@@ -6709,8 +6647,6 @@ $args - additional optional args support
              skip_phases    -> hash ref of 
                                     head -> skip the <html><head> generation
                                     body -> skip all <body> generation
-             no_inline_link -> if true and in remote mode, don't show the 
-                                    'Switch To Inline Menu' link
              no_auto_mt_title -> prevent &mt()ing the title arg
              inherit_jsmath -> when creating popup window in a page,
                                     should it have jsmath forced on by the
@@ -6727,6 +6663,14 @@ $args - additional optional args support
 sub start_page {
     my ($title,$head_extra,$args) = @_;
     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
+#SD
+#I don't see why we copy certain elements of %$args to %head_args
+#head args is passed to headtag() and this routine only reads those
+#keys that are needed. There doesn't happen any writes or any processing
+#of other keys.
+#proposal: just pass $args to headtag instead of \%head_args and delete 
+#marked lines
+#<- MARK
     my %head_args;
     foreach my $arg ('redirect','force_register','domain','function',
 		     'bgcolor','frameset','no_nav_bar','only_body',
@@ -6735,13 +6679,16 @@ sub start_page {
 	    $head_args{$arg} = $args->{$arg};
 	}
     }
+#MARK ->
 
     $env{'internal.start_page'}++;
     my $result;
+
     if (! exists($args->{'skip_phases'}{'head'}) ) {
-	$result.=
-	    &xml_begin().
-	    &headtag($title,$head_extra,\%head_args).&endheadtag();
+        $result .= 
+                  &xml_begin() . &headtag($title,$head_extra,\%head_args);
+#replace prev line by
+#                 &xml_begin() . &headtag($title, $head_extra, $args);
     }
     
     if (! exists($args->{'skip_phases'}{'body'}) ) {
@@ -6755,8 +6702,7 @@ sub start_page {
                          $args->{'function'},       $args->{'add_entries'},
                          $args->{'only_body'},      $args->{'domain'},
                          $args->{'force_register'}, $args->{'no_nav_bar'},
-                         $args->{'bgcolor'},        $args->{'no_inline_link'},
-                         $args);
+                         $args->{'bgcolor'},        $args);
         }
     }
 
@@ -6772,14 +6718,10 @@ sub start_page {
     #            $result .= &build_functionlist();
     #}
 
-    # Don't add anything more if only_body wanted
-    return $result if $args->{'only_body'};
+    # Don't add anything more if only_body wanted or in const space
+    return $result if    $args->{'only_body'} 
+                      || $env{'request.state'} eq 'construct';
 
-    #Breadcrumbs for Construction Space provided by &bodytag. 
-    if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
-        return $result;
-    }
- 
     #Breadcrumbs
     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
 		&Apache::lonhtmlcommon::clear_breadcrumbs();
@@ -6800,28 +6742,6 @@ sub start_page {
     return $result;
 }
 
-
-=pod
-
-=item * &head()
-
-Returns a complete </body></html> section for LON-CAPA web pages.
-
-Inputs:         $args - additional optional args supported are:
-                 js_ready     -> return a string ready for being used in 
-                                 a javascript writeln
-                 html_encode  -> return a string ready for being used in 
-                                 a html attribute
-                 frameset     -> if true will start with a <frameset>
-                                 rather than <body>
-                 dicsussion   -> if true will get discussion from
-                                  lonxml::xmlend
-                                 (you can pass the target and parser arguments
-                                  through optional 'target' and 'parser' args
-                                  to this routine)
-
-=cut
-
 sub end_page {
     my ($args) = @_;
     $env{'internal.end_page'}++;
@@ -6911,15 +6831,26 @@ sub simple_error_page {
 
 {
     my @row_count;
+
+    sub start_data_table_count {
+        unshift(@row_count, 0);
+        return;
+    }
+
+    sub end_data_table_count {
+        shift(@row_count);
+        return;
+    }
+
     sub start_data_table {
 	my ($add_class) = @_;
 	my $css_class = (join(' ','LC_data_table',$add_class));
-	unshift(@row_count,0);
+	&start_data_table_count();
 	return '<table class="'.$css_class.'">'."\n";
     }
 
     sub end_data_table {
-	shift(@row_count);
+	&end_data_table_count();
 	return '</table>'."\n";;
     }
 
@@ -8137,6 +8068,10 @@ sub get_institutional_codes {
     return;
 }
 
+sub get_standard_codeitems {
+    return ('Year','Semester','Department','Number','Section');
+}
+
 =pod
 
 =head1 Slot Helpers
@@ -10073,19 +10008,19 @@ sub check_clone {
     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
     my $clonemsg;
     my $can_clone = 0;
-    my $lctype = lc($args->{'type'});
+    my $lctype = lc($args->{'crstype'});
     if ($lctype ne 'community') {
         $lctype = 'course';
     }
     if ($clonehome eq 'no_host') {
-        if ($args->{'type'} eq 'Community') {
+        if ($args->{'crstype'} eq 'Community') {
             $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
         } else {
             $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
         }     
     } else {
 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
-        if ($args->{'type'} eq 'Community') {
+        if ($args->{'crstype'} eq 'Community') {
             if ($clonedesc{'type'} ne 'Community') {
                  $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
@@ -10104,7 +10039,7 @@ sub check_clone {
                 $can_clone = 1;
             } else {
                 my $ccrole = 'cc';
-                if ($args->{'type'} eq 'Community') {
+                if ($args->{'crstype'} eq 'Community') {
                     $ccrole = 'co';
                 }
 	        my %roleshash =
@@ -10113,9 +10048,11 @@ sub check_clone {
                                          'userroles',['active'],[$ccrole],
 					 [$args->{'clonedomain'}]);
 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
-		    $can_clone = 1;
-	        } else {
-                    if ($args->{'type'} eq 'Community') {
+                    $can_clone = 1;
+                } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
+                    $can_clone = 1;
+                } else {
+                    if ($args->{'crstype'} eq 'Community') {
                         $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
                     } else {
                         $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
@@ -10174,11 +10111,19 @@ sub construct_course {
     # if anyone ever decides to not show this, and Utils::Course::new
     # will need to be suitably modified.
     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
+    if ($$courseid =~ /^error:/) {
+        return (0,$outcome);
+    }
+
 #
 # Check if created correctly
 #
     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
+    if ($crsuhome eq 'no_host') {
+        $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
+        return (0,$outcome);
+    }
     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
 
 #
@@ -10197,6 +10142,10 @@ sub construct_course {
 	$cenv{'url'}=$oldcenv{'url'};
 # Restore title
 	$cenv{'description'}=$oldcenv{'description'};
+# Restore creation date, creator and creation context.
+        $cenv{'internal.created'}=$oldcenv{'internal.created'};
+        $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
+        $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
 # Mark as cloned
 	$cenv{'clonedfrom'}=$cloneid;
 # Need to clone grading mode
@@ -10443,7 +10392,7 @@ sub construct_course {
 	    $title=&mt('Syllabus');
             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
         } else {
-            $title=&mt('Navigate Contents');
+            $title=&mt('Table of Contents');
             $url='/adm/navmaps';
         }
 
@@ -10460,6 +10409,8 @@ sub construct_course {
 ############################################################
 ############################################################
 
+#SD
+# only Community and Course, or anything else?
 sub course_type {
     my ($cid) = @_;
     if (!defined($cid)) {
@@ -10625,15 +10576,12 @@ sub init_user_environment {
     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
     my ($tmp) = keys(%userenv);
     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
-	# default remote control to off
-	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
     } else {
 	undef(%userenv);
     }
     if (($userenv{'interface'}) && (!$form->{'interface'})) {
 	$form->{'interface'}=$userenv{'interface'};
     }
-    $env{'environment.remote'}=$userenv{'remote'};
     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
 
 # --------------- Do not trust query string to be put directly into environment
@@ -10665,9 +10613,6 @@ sub init_user_environment {
 	    $initial_env{"browser.localres"}   = $form->{'localres'};
         }
 	
-	if ($public) {
-	    $initial_env{"environment.remote"} = "off";
-	}
 	if ($form->{'interface'}) {
 	    $form->{'interface'}=~s/\W//gs;
 	    $initial_env{"browser.interface"} = $form->{'interface'};