--- loncom/interface/lonhtmlcommon.pm	2006/12/05 02:55:53	1.155
+++ loncom/interface/lonhtmlcommon.pm	2007/10/04 01:16:58	1.166
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.155 2006/12/05 02:55:53 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.166 2007/10/04 01:16:58 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -140,6 +140,7 @@ sub select_recent {
     foreach my $value (sort(keys(%recent))) {
 	unless ($value =~/^error\:/) {
 	    my $escaped = &Apache::loncommon::escape_url($value);
+	    &Apache::loncommon::inhibit_menu_check(\$escaped);
 	    $return.="\n<option value='$escaped'>".
 		&unescape((split(/\&/,$recent{$value}))[1]).
 		'</option>';
@@ -480,6 +481,19 @@ ENDJS
     return $result;
 }
 
+
+sub build_url {
+    my ($base, $fields)=@_;
+    my $url;
+    $url = $base.'?';
+    foreach my $key(keys(%$fields)) {
+        $url.=$key.'='.$$fields{$key}.'&amp;';
+    }
+    $url =~ s/&amp;$//;
+    return $url;
+}
+
+
 ##############################################
 ##############################################
 
@@ -681,7 +695,7 @@ Returns: a perl string as described.
 ##############################################
 ##############################################
 sub StatusOptions {
-    my ($status, $formName,$size,$onchange)=@_;
+    my ($status, $formName,$size,$onchange,$mult)=@_;
     $size = 1 if (!defined($size));
     if (! defined($status)) {
         $status = 'Active';
@@ -690,6 +704,9 @@ sub StatusOptions {
 
     my $Str = '';
     $Str .= '<select name="Status"';
+    if (defined($mult)){
+        $Str .= ' multiple="multiple" ';
+    }
     if(defined($formName) && $formName ne '' && ! defined($onchange)) {
         $Str .= ' onchange="document.'.$formName.'.submit()"';
     }
@@ -852,7 +869,7 @@ sub Create_PrgWin {
          popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
         "popwin.document.writeln(\'".$start_page.
               "<h4>$heading<\/h4>".
-              "<form name=\"popremain\" method=\"post\">".
+              "<form action= \"\" name=\"popremain\" method=\"post\">".
               '<input type="text" size="'.$width.'" name="remaining" value="'.
 	      &mt('Starting').'" /><\\/form>'.$end_page.
               "\');".
@@ -864,7 +881,7 @@ sub Create_PrgWin {
 	$prog_state{'window'}='window';
 	if (!$formname) {
 	    $prog_state{'formname'}=&get_uniq_name();
-	    &r_print($r,'<form name="'.$prog_state{'formname'}.'">');
+	    &r_print($r,'<form action="" name="'.$prog_state{'formname'}.'">');
 	} else {
 	    $prog_state{'formname'}=$formname;
 	}
@@ -891,7 +908,7 @@ sub Create_PrgWin {
 # update progress
 sub Update_PrgWin {
     my ($r,$prog_state,$displayString)=@_;
-    &r_print($r,'<script>'.$$prog_state{'window'}.'.document.'.
+    &r_print($r,'<script type="text/javascript">'.$$prog_state{'window'}.'.document.'.
 	     $$prog_state{'formname'}.'.'.
 	     $$prog_state{'inputname'}.'.value="'.
 	     $displayString.'";</script>');
@@ -1002,13 +1019,15 @@ sub crumbs {
 		} 
 	    } else {
 		$path.='/'; 
+	    }	    
+            my $href_path = &HTML::Entities::encode($path,'<>&"');
+	    &Apache::loncommon::inhibit_menu_check(\$href_path);
+	    if ($form) {
+	        my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
+	        $output.=qq{<a href="$href" $target>$dir</a>/};
+	    } else {
+	        $output.=qq{<a href="$href_path" $target>$dir</a>/};
 	    }
-            my $linkpath = &Apache::loncommon::escape_single($path);
-            if ($form) {
-		$linkpath=
-                    qq{javascript:$form.action='$linkpath';$form.submit();};
-            }
-	    $output.=qq{<a href="$linkpath" $target>$dir</a>/};
 	}
     } else {
 	foreach my $dir (split('/',$uri)) {
@@ -1202,7 +1221,8 @@ Pushes a breadcrumb on the stack of crum
 
 input: $breadcrumb, a hash reference.  The keys 'href','title', and 'text'
 are required.  If present the keys 'faq' and 'bug' will be used to provide
-links to the FAQ and bug sites.
+links to the FAQ and bug sites. If the key 'no_mt' is present the 'title' 
+and 'text' values won't be sent through &mt()
 
 returns: nothing    
 
@@ -1252,13 +1272,22 @@ returns: nothing
                      if (defined($_->{'target'}) && $_->{'target'} ne '') {
                          $result .= 'target="'.$_->{'target'}.'" ';
                      }
-                     $result .='title="'.&mt($_->{'title'}).'">'.
-                         &mt($_->{'text'}).'</a>';
+		     if ($_->{'no_mt'}) {
+			 $result .='title="'.$_->{'title'}.'">'.
+			     $_->{'text'}.'</a>';
+		     } else {
+			 $result .='title="'.&mt($_->{'title'}).'">'.
+			     &mt($_->{'text'}).'</a>';
+		     }
                      $result;
                      } @Crumbs
                  );
         $links .= '-&gt;' if ($links ne '');
-        $links .= '<b>'.&mt($last->{'text'}).'</b>';
+	if ($last->{'no_mt'}) {
+	    $links .= '<b>'.$last->{'text'}.'</b>';
+	} else {
+	    $links .= '<b>'.&mt($last->{'text'}).'</b>';
+	}
         #
         my $icons = '';
         $faq = $last->{'faq'} if (exists($last->{'faq'}));
@@ -1321,7 +1350,7 @@ returns: nothing
 # row2
 # row3   ... etc.
 # &submit_row(0
-# &end_pickbox()
+# &end_pick_box()
 #
 # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
 # &status_select_row and &email_default_row
@@ -1559,7 +1588,6 @@ sub status_select_row {
 sub email_default_row {
     my ($authtypes,$title,$descrip,$css_class) = @_;
     my $output = &row_title($title,$css_class);
-    my @rowcols = ('#eeeeee','#dddddd');
     $output .= $descrip.
 	&Apache::loncommon::start_data_table().
 	&Apache::loncommon::start_data_table_header_row().
@@ -1830,6 +1858,43 @@ sub set_form_elements {
     return $output;
 }
 
+##############################################
+##############################################
+
+# javascript_valid_email
+#
+# Generates javascript to validate an e-mail address.
+# Returns a javascript function which accetps a form field as argumnent, and
+# returns false if field.value does not satisfy two regular expression matches
+# for a valid e-mail address.  Backwards compatible with old browsers without
+# support for javascript RegExp (just checks for @ in field.value in this case). 
+
+sub javascript_valid_email {
+    my $scripttag .= <<'END';
+function validmail(field) {
+    var str = field.value;
+    if (window.RegExp) {
+        var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
+        var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
+        var reg1 = new RegExp(reg1str);
+        var reg2 = new RegExp(reg2str);
+        if (!reg1.test(str) && reg2.test(str)) {
+            return true;
+        }
+        return false;
+    }
+    else
+    {
+        if(str.indexOf("@") >= 0) {
+            return true;
+        }
+        return false;
+    }
+}
+END
+    return $scripttag;
+}
+
 1;
 
 __END__