--- loncom/interface/loncommon.pm	2007/08/11 15:18:24	1.561
+++ loncom/interface/loncommon.pm	2007/08/18 00:01:37	1.565
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.561 2007/08/11 15:18:24 www Exp $
+# $Id: loncommon.pm,v 1.565 2007/08/18 00:01:37 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1084,6 +1084,63 @@ sub changable_area {
 
 =pod
 
+=item * resize_textarea_js
+
+emits the needed javascript to resize a textarea to be as big as possible
+
+creates a function resize_textrea that takes two IDs first should be
+the id of the element to resize, second should be the id of a div that
+surrounds everything that comes after the textarea, this routine needs
+to be attached to the <body> for the onload and onresize events.
+
+
+=cut
+
+sub resize_textarea_js {
+    return <<"RESIZE";
+    <script type="text/javascript">
+var Geometry = {};
+function init_geometry() {
+    if (Geometry.init) { return };
+    Geometry.init=1;
+    if (window.innerHeight) {
+	Geometry.getViewportHeight = function() { return window.innerHeight; };
+    }
+    else if (document.documentElement && document.documentElement.clientHeight) {
+	Geometry.getViewportHeight = 
+	    function() { return document.documentElement.clientHeight; };
+    }
+    else if (document.body.clientHeight) {
+	Geometry.getViewportHeight = 
+	    function() { return document.body.clientHeight; };
+    }
+}
+
+function resize_textarea(textarea_id,bottom_id) {
+    init_geometry();
+    var textarea        = document.getElementById(textarea_id);
+    //alert(textarea);
+
+    var textarea_top    = textarea.offsetTop;
+    var textarea_height = textarea.offsetHeight;
+    var bottom          = document.getElementById(bottom_id);
+    var bottom_top      = bottom.offsetTop;
+    var bottom_height   = bottom.offsetHeight;
+    var window_height   = Geometry.getViewportHeight();
+    var fudge           = 23; 
+    var new_height      = window_height-fudge-textarea_top-bottom_height;
+    if (new_height < 300) {
+	new_height = 300;
+    }
+    textarea.style.height=new_height+'px';
+}
+</script>
+RESIZE
+
+}
+
+=pod
+
 =back
  
 =head1 Excel and CSV file utility routines
@@ -1424,7 +1481,7 @@ sub select_level_form {
 
 =pod
 
-=item * select_dom_form($defdom,$name,$includeempty)
+=item * select_dom_form($defdom,$name,$includeempty,$showdomdesc)
 
 Returns a string containing a <select name='$name' size='1'> form to 
 allow a user to select the domain to preform an operation in.  
@@ -1433,18 +1490,28 @@ See loncreateuser.pm for an example invo
 If the $includeempty flag is set, it also includes an empty choice ("no domain
 selected");
 
+If the $showdomdesc flag is set, the domain name is followed by the domain description. 
+
 =cut
 
 #-------------------------------------------
 sub select_dom_form {
-    my ($defdom,$name,$includeempty) = @_;
+    my ($defdom,$name,$includeempty,$showdomdesc) = @_;
     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
     if ($includeempty) { @domains=('',@domains); }
     my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
     foreach my $dom (@domains) {
         $selectdomain.="<option value=\"$dom\" ".
-            ($dom eq $defdom ? 'selected="selected" ' : '').
-                ">$dom</option>\n";
+            ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
+        if ($showdomdesc) {
+            if ($dom ne '') {
+                my $domdesc = &Apache::lonnet::domain($dom,'description');
+                if ($domdesc ne '') {
+                    $selectdomain .= ' ('.$domdesc.')';
+                }
+            } 
+        }
+        $selectdomain .= "</option>\n";
     }
     $selectdomain.="</select>";
     return $selectdomain;
@@ -3397,6 +3464,9 @@ Inputs:
 
 =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,
+                              should it have jsmath forced on by the
+                              current page
 
 =back
 
@@ -3453,7 +3523,7 @@ sub bodytag {
 
 # construct main body tag
     my $bodytag = "<body $extra_body_attr>".
-	&Apache::lontexconvert::init_math_support();
+	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
 
     if ($bodyonly) {
         return $bodytag;
@@ -4711,6 +4781,10 @@ Inputs: $title - optional title for the
 
                   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
+                                    current page
+
 =cut
 
 sub start_page {
@@ -5558,9 +5632,7 @@ sub user_picker {
         $srchterm = $srch->{'srchterm'};
     }
     my %lt=&Apache::lonlocal::texthash(
-                    'usr'       => 'Search for',
-                    'or'        => 'or',
-                    'doma'      => 'domain',
+                    'doma'      => 'Domain/institution to search',
                     'uname'     => 'username',
                     'lastname'  => 'last name',
                     'lastfirst' => 'last name, first name',
@@ -5571,9 +5643,8 @@ sub user_picker {
                     'exact'     => 'is',
                     'contains'  => 'contains',
                                        );
-    my $domform = &select_dom_form($currdom,'srchdomain',1);
-
-    my $srchin;
+    my $domform = &select_dom_form($currdom,'srchdomain',1,1);
+    my $srchinsel = ' <select name="srchin">';
 
     my @srchins = ('crs','dom','alc','instd');
 
@@ -5583,18 +5654,15 @@ sub user_picker {
         #       has been completed.
         next if ($option eq 'alc');
         next if ($option eq 'crs' && !$env{'request.course.id'});
-        my $checked =($curr_selected{'srchin'} eq $option) ?'checked="checked"'
-	                                                   :'';
-	my $extra = ($option eq 'dom') ? $domform
-	                               : '';
-	$srchin.=<<ROW
- <tr>
-   <td>
-     <label><input type="radio" name="srchin" value="$option" $checked /> $lt{$option}</label> $extra
-   </td>
-</tr>
-ROW
+        if ($curr_selected{'srchin'} eq $option) {
+            $srchinsel .= ' 
+   <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
+        } else {
+            $srchinsel .= '
+   <option value="'.$option.'">'.$lt{$option}.'</option>';
+        }
     }
+    $srchinsel .= "\n  </select>\n";
 
     my $srchbysel =  ' <select name="srchby">';
     foreach my $option ('uname','lastname','lastfirst') {
@@ -5634,8 +5702,8 @@ function setSearch(createnew) {
             }
         }
         for (var i=0; i<document.crtuser.srchin.length; i++) {
-            if ( document.crtuser.srchin[i].value == 'dom') {
-		document.crtuser.srchin[i].checked = 1;
+            if ( document.crtuser.srchin.options[i].value == 'dom') {
+		document.crtuser.srchin.selectedIndex = i;
             }
         }
         for (var i=0; i<document.crtuser.srchtype.length; i++) {
@@ -5670,6 +5738,7 @@ function validateEntry() {
     var srchby = document.crtuser.srchby.options[document.crtuser.srchby.selectedIndex].value;
     var srchdomain = document.crtuser.srchdomain.options[document.crtuser.srchdomain.selectedIndex].value;
     var srchterm =  document.crtuser.srchterm.value;
+    var srchin = document.crtuser.srchin.options[document.crtuser.srchin.selectedIndex].value;
     var msg = "";
 
     if (srchterm == "") {
@@ -5680,7 +5749,7 @@ function validateEntry() {
     if (srchtype== 'contains') {
         if (srchterm.length < 3) {
             checkok = 0;
-            msg += "The text you are searching for must contain at least three characters when using a 'contained in' type search.\\n";
+            msg += "The text you are searching for must contain at least three characters when using a 'contains' type search.\\n";
         }
     }
     if (srchin == 'instd') {
@@ -5722,12 +5791,16 @@ $new_user_create
 
 <table>
  <tr>
-  <td> $srchbysel
-       $srchtypesel 
-       <input type="text" size="15" name="srchterm" value="$srchterm" />
+  <td>$srchbysel
+      $srchtypesel 
+      <input type="text" size="15" name="srchterm" value="$srchterm" />
+      $srchinsel 
+  </td>
+ </tr>
+ <tr>
+  <td>$lt{'doma'}: $domform</td>
   </td>
  </tr>
-$srchin
 </table>
 <br />
 END_BLOCK