--- loncom/homework/radiobuttonresponse.pm	2005/06/21 21:00:55	1.101
+++ loncom/homework/radiobuttonresponse.pm	2005/12/06 10:03:57	1.105
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.101 2005/06/21 21:00:55 albertel Exp $
+# $Id: radiobuttonresponse.pm,v 1.105 2005/12/06 10:03:57 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,12 +60,14 @@ sub start_radiobuttonresponse {
 				    $token,'4').
 	    &Apache::edit::select_arg('Randomize Foil Order','randomize',
 				      ['yes','no'],$token).
+	    &Apache::edit::select_arg('Display Direction','direction',
+				      ['vertical','horizontal'],$token).
 				      &Apache::edit::end_row().
 				      &Apache::edit::start_spanning_row()."\n";
     } elsif ($target eq 'modified') {
 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
 						     $safeeval,'max',
-						     'randomize');
+						     'randomize','direction');
 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
     } elsif ($target eq 'tex') {
 	my $type=&Apache::lonxml::get_param('TeXtype',$parstack,$safeeval,
@@ -289,7 +291,7 @@ sub whichfoils {
     my ($truecnt,$falsecnt) = &getfoilcounts();
     my $count=0;
     # we will add in 1 of the true statements
-    if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
+    if ( $max>0 && ($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; $max=$count; }
     my $answer=int(&Math::Random::random_uniform() * ($count));
     &Apache::lonxml::debug("Count is $count, $answer is $answer");
     my @names;
@@ -520,10 +522,15 @@ sub displayanswers {
     my ($max,$randomize)=@_;
     my ($answer,@whichopt) = &whichfoils($max,$randomize);
     my $result=&Apache::response::answer_header('radiobuttonresponse');
+    if ($Apache::lonhomework::type eq 'exam') {
+	my $correct = ('A'..'Z')[$answer];
+	$result.=&Apache::response::answer_part('radiobuttonresponse',
+						$correct);
+    }
     foreach my $name (@whichopt) {
 	$result.=&Apache::response::answer_part('radiobuttonresponse',
-						$Apache::response::foilgroup{$name.'.value'})
-	}
+						$Apache::response::foilgroup{$name.'.value'});
+    }
     $result.=&Apache::response::answer_footer('radiobuttonresponse');
     return $result;
 }
@@ -607,7 +614,7 @@ sub end_foil {
 	my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
 	if ($value ne 'unused') {
 	    my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
-	    if (!$name) {
+	    if ($name eq "") {
 		&Apache::lonxml::warning("Foils without names exist. This can cause problems to malfunction.");
 		$name=$Apache::lonxml::curdepth;
 	    }