--- loncom/interface/lonmenu.pm	2008/12/13 15:51:51	1.239.4.1
+++ loncom/interface/lonmenu.pm	2009/04/29 16:57:29	1.261
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.239.4.1 2008/12/13 15:51:51 raeburn Exp $
+# $Id: lonmenu.pm,v 1.261 2009/04/29 16:57:29 bisitz Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,6 +36,105 @@
 # browser.interface is 'textual'
 #
 
+=head1 NAME
+
+Apache::lonmenu
+
+=head1 SYNOPSIS
+
+Coordinates the response to clicking an image.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 SUBROUTINES
+
+=over
+
+=item show_course()
+
+Little texts
+
+=item initlittle()
+
+=item menubuttons()
+
+This gets called at the top of the body section
+
+=item show_return_link()
+
+=item registerurl()
+
+This gets called in the header section
+
+=item innerregister()
+
+This gets called in order to register a URL, both with the Remote
+and in the body of the document
+
+=item loadevents()
+
+=item unloadevents()
+
+=item startupremote()
+
+=item setflags()
+
+=item maincall()
+
+=item load_remote_msg()
+
+=item get_menu_name()
+
+=item reopenmenu()
+
+=item open()
+
+Open the menu
+
+=item clear()
+
+=item switch()
+
+Switch a button or create a link
+Switch acts on the javascript that is executed when a button is clicked.  
+The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
+
+=item secondlevel()
+
+=item openmenu()
+
+=item inlinemenu()
+
+=item rawconfig()
+
+=item close()
+
+=item footer()
+
+=item utilityfunctions()
+
+=item serverform()
+
+=item constspaceform()
+
+=item get_nav_status()
+
+=item convert_menu_function()
+
+FIXME this needs to move into mydesktab and the other locations 
+the text is generated
+
+=item hidden_button_check()
+
+=item roles_selector()
+
+=item jump_to_role()
+
+=back
+
+=cut
+
 package Apache::lonmenu;
 
 use strict;
@@ -53,7 +152,6 @@ my @inlineremote;
 
 
 
-# ================================================================ Little texts
 sub show_course {
     my $course = !$env{'user.adv'};
     if (!$env{'user.adv'}) {
@@ -76,7 +174,7 @@ sub initlittle {
                                                     'Courses':'Roles'),
                                        'other' => 'Other Roles',
                                        'docs' => 'Edit Course',
-                                       'exit' => 'Exit',
+                                       'exit' => 'Logout',
                                        'login' => 'Log In',
 				       'launch' => 'Launch Remote Control',
                                        'groups' => 'Groups',
@@ -84,8 +182,6 @@ sub initlittle {
                                        );
 }
 
-# ============================= This gets called at the top of the body section
-
 sub menubuttons {
     my $forcereg=shift;
     my $registration=shift;
@@ -110,8 +206,8 @@ sub menubuttons {
     my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
 
     my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
-    $logo = '<td class="LC_top_nav_logo"><a href="/adm/about.html"><img src="'.
-	$logo.'" alt="LON-CAPA Logo" /></a></td>';
+    $logo = '<a href="/adm/about.html"><img src="'.
+	$logo.'" alt="LON-CAPA Logo" class="LC_noBorder" /></a>';
 
     if ($env{'request.state'} eq 'construct') {
         if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
@@ -196,17 +292,16 @@ ENDMAINMENU
 	    return (<<ENDINLINEMENU);
    <table id="LC_top_nav">
     <tr>
-      $logo
+      <td>$logo</td>
       <td></td>
       <td class="LC_top_nav_login">
         <a href="/adm/roles" target="_top">$lt{'login'}</a>
      </td>
     </tr>
   </table>
-</font>
 ENDINLINEMENU
         }
-        $roles = '<td><a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a></td>';
+        $roles = '<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
 # Do we have a NAV link?
         if ($env{'request.course.id'}) {
 	    my $link='/adm/navmaps?postdata='.$escurl.'&amp;postsymb='.
@@ -215,34 +310,35 @@ ENDINLINEMENU
 		$link="javascript:gonav('".$link."')";
 	    }
 	    $navmaps=(<<ENDNAV);
-<td><a href="$link" target="_top">$lt{'nav'}</a></td>
+<li><a href="$link" target="_top">$lt{'nav'}</a></li>
 ENDNAV
             my $is_group = (&Apache::loncommon::course_type() eq 'Group');
 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
                 my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'};
 		$docs=(<<ENDDOCS);
-<td><a href="/adm/coursedocs" target="_top">$text</a></td>
+<li><a href="/adm/coursedocs" target="_top">$text</a></li>
 ENDDOCS
             }
             if ($showgroups) {
                 $groups =(<<ENDGROUPS);
-<td><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></td>
+<li><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></li>
 ENDGROUPS
             }
 	    if (&show_return_link()) {
                 my $escreload=&escape('return:');
                 $reloadlink=(<<ENDRELOAD);
-<td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
+<li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
 ENDRELOAD
             }
             if ($role_selector) {
-                $roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
+            	#$roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
+				$role_selector = '<li>'.$role_selector.'</li>';
             }
         }
 	if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
 	    my $escreload=&escape('return:');
 	    $reloadlink=(<<ENDCRELOAD);
-<td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
+<li><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></li>
 ENDCRELOAD
         }
         my $reg='';
@@ -252,6 +348,12 @@ ENDCRELOAD
         my $form=&serverform();
 	my $utility=&utilityfunctions();
 
+	my $messagelink = "";
+	if(&Apache::lonmsg::mynewmail()){
+		$messagelink = '<a href="javascript:go(\'/adm/communicate\');">Message(new)</a>'
+	}else{
+		$messagelink = '<a href="javascript:go(\'/adm/communicate\');">Message</a>'
+	}
         my $helplink=&Apache::loncommon::top_nav_help('Help');
 	return (<<ENDINLINEMENU);
 <script type="text/javascript">
@@ -260,23 +362,26 @@ ENDCRELOAD
 $utility
 // ]]>
 </script>
-<table id="LC_top_nav">
-<tr>
-$logo
-<td><a href="/adm/menu" target="_top">$lt{'main'}</a></td>
+<ol class="LC_smallMenu LC_right">
+	<li>$logo</li>
+	<li>$messagelink</li>
+	<li>$roles</li>
+	<li>$helplink</li>
+	<li><a href="/adm/logout" target="_top">$lt{'exit'}</a></li>
+</ol>
+<ol id="LC_TabMainMenuContent">
+<li><a href="/adm/menu" target="_top">$lt{'main'}</a></li>
 $reloadlink
 $navmaps
 $docs
 $groups
-$roles
-<td class="LC_top_nav_help">$helplink</td>
-<td class="LC_top_nav_exit"><a href="/adm/logout" target="_top">$lt{'exit'}</a></td>
-</tr>
-</table>
+$role_selector
+</ol>
 $form
 <script type="text/javascript">
 // END LON-CAPA Internal
 </script>
+<br clear="all" />
 $reg
 ENDINLINEMENU
     } else {
@@ -297,7 +402,6 @@ sub show_return_link {
 	     ));
 }
 
-# ====================================== This gets called in the header section
 
 sub registerurl {
     my ($forcereg) = @_;
@@ -322,9 +426,6 @@ sub registerurl {
     return $result.$force_title;
 }
 
-# =========== This gets called in order to register a URL, both with the Remote
-# =========== and in the body of the document
-
 sub innerregister {
     my ($forcereg, $titletable) = @_;
     my $result = '';
@@ -401,7 +502,7 @@ sub innerregister {
         if ($env{'request.symb'} ne '' &&
 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
-		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
+		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
                        "gocmd('/adm/grades','gradingmenu')",
                        'Modify user grades for this assessment resource');
             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
@@ -422,6 +523,12 @@ sub innerregister {
         ### resource
         ###
         my $editbutton = '';
+        my $noeditbutton = 1;
+        my ($cnum,$cdom);
+        if ($env{'request.course.id'}) {
+            $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+            $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        }
         if ($env{'user.author'}) {
             if ($env{'request.role'}=~/^(aa|ca|au)/) {
                 # Set defaults for authors
@@ -449,6 +556,7 @@ sub innerregister {
 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 		if (!$allowed) {
 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
+                    $noeditbutton = 0;
                 }
             }
             ##
@@ -457,30 +565,53 @@ sub innerregister {
             my $cfile='';
             my $cfuname='';
             my $cfudom='';
+            my $uploaded;
             if ($env{'request.filename'}) {
                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
-                $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
-                # Check that the user has permission to edit this resource
-                ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
-                if (defined($cfudom)) {
-		    my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
-		    my $allowed=0;
-		    my @ids=&Apache::lonnet::current_machine_ids();
-		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
-		    if ($allowed) {
-                        $cfile=$file;
+                if (defined($cnum) && defined($cdom)) {
+                    $uploaded = &is_course_upload($file,$cnum,$cdom);
+                }
+                if (!$uploaded) {
+                    $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
+                    # Check that the user has permission to edit this resource
+                    ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
+                    if (defined($cfudom)) {
+		        my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
+		        my $allowed=0;
+		        my @ids=&Apache::lonnet::current_machine_ids();
+		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+		        if ($allowed) {
+                            $cfile=$file;
+                        }
                     }
                 }
-            }        
+            }
             # Finally, turn the button on or off
             if ($cfile && !$const_space) {
                 $editbutton=&switch
                     ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
                      "go('".$cfile."');","Edit this resource");
+                $noeditbutton = 0;
             } elsif ($editbutton eq '') {
                 $editbutton=&clear(6,1);
             }
         }
+        if (($noeditbutton) && ($env{'request.filename'})) { 
+            if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
+                my $file=&Apache::lonnet::declutter($env{'request.filename'});
+                if (defined($cnum) && defined($cdom)) {
+                    if (&is_course_upload($file,$cnum,$cdom)) {
+                        my $cfile = &edit_course_upload($file,$cnum,$cdom);
+                        if ($cfile) {
+                            $editbutton=&switch
+                                        ('','',6,1,'pcstr.gif','edit[_1]',
+                                         'resource[_2]',"go('".$cfile."');",
+                                         'Edit this resource');
+                        }
+                    }
+                }
+            }
+        }
         ###
         ###
 # Prepare the rest of the buttons
@@ -498,7 +629,7 @@ sub innerregister {
                 $menuitems=(<<ENDMENUITEMS);
 s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
 s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
-s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
+s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
 s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
 s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
 ENDMENUITEMS
@@ -514,13 +645,24 @@ c&8&1
 c&8&2
 s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
 s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
-s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&&1
 ENDMENUITEMS
 
+my $currentURL = &Apache::loncommon::get_symb();
+my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
+my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
+$menuitems.="s&9&3&";
+if(length($annotation) > 0){
+	$menuitems.="anot2.gif";
+}else{
+	$menuitems.="anot.gif";
+}
+$menuitems.="&anno-[_1]&tations[_1]&annotate()&";
+$menuitems.="Make notes and annotations about this resource&&1\n";
+
             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
 		if (!$env{'request.enc'}) {
 		    $menuitems.=(<<ENDREALRES);
-s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
+s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
 ENDREALRES
                 }
 	        $menuitems.=(<<ENDREALRES);
@@ -704,6 +846,42 @@ ENDDONOTREGTHIS
     return $result;
 }
 
+sub is_course_upload {
+    my ($file,$cnum,$cdom) = @_;
+    my $uploadpath = &LONCAPA::propath($cdom,$cnum);
+    $uploadpath =~ s{^\/}{};
+    if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
+        ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
+        return 1;
+    }
+    return;
+}
+
+sub edit_course_upload {
+    my ($file,$cnum,$cdom) = @_;
+    my $cfile;
+    if ($file =~/\.(htm|html|css|js|txt)$/) {
+        my $ext = $1;
+        my $url = &Apache::lonnet::hreflocation('',$file);
+        my $home = &Apache::lonnet::homeserver($cnum,$cdom);
+        my @ids=&Apache::lonnet::current_machine_ids();
+        my $dest;
+        if ($home && grep(/^\Q$home\E$/,@ids)) {
+            $dest = $url.'?forceedit=1';
+        } else {
+            unless (&Apache::lonnet::get_locks()) {
+                $dest = '/adm/switchserver?otherserver='.
+                        $home.'&role='.$env{'request.role'}.
+                        '&url='.$url.'&forceedit=1';
+            }
+        }
+        if ($dest) {
+            $cfile = &HTML::Entities::encode($dest,'"<>&');
+        }
+    }
+    return $cfile;
+}
+
 sub loadevents() {
     if ($env{'request.state'} eq 'construct' ||
 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
@@ -716,7 +894,6 @@ sub unloadevents() {
     return 'LONCAPAstale();';
 }
 
-# ============================================================= Start up remote
 
 sub startupremote {
     my ($lowerurl)=@_;
@@ -812,8 +989,9 @@ sub load_remote_msg {
         ($env{'environment.remote'} eq 'off')) { return ''; }
 
     my $esclowerurl=&escape($lowerurl);
-    my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
-		 "/adm/remote?action=collapse&amp;url=$esclowerurl");
+    my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
+                ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
+                ,'</a>');
     return(<<ENDREMOTEFORM);
 <p>
 <form name="wheel">
@@ -830,7 +1008,6 @@ sub get_menu_name {
     return 'LCmenu'.$hostid;
 }
 
-# ================================================================= Reopen menu
 
 sub reopenmenu {
    if (($env{'browser.interface'} eq 'textual') ||
@@ -840,7 +1017,6 @@ sub reopenmenu {
    return('window.open('.$nothing.',"'.$menuname.'","",false);');
 } 
 
-# =============================================================== Open the menu
 
 sub open {
     my $returnval='';
@@ -928,22 +1104,22 @@ sub switch {
        my $pic=
 	   '<img alt="'.$text.'" src="'.
 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
-	   '" align="'.($nobreak==3?'right':'left').'" />';
+	   '" align="'.($nobreak==3?'right':'left').'" class="LC_noBorder" />';
        if ($env{'browser.interface'} eq 'faketextual') {
 # Accessibility
 	   if ($nobreak==3) {
 	       $inlineremote[$idx]="\n".
 		   '<td class="LC_menubuttons_text" align="right">'.$text.
-		   '</td><td class="LC_menubuttons_img" align="left">'.
+		   '</td><td align="left">'.
 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 	   } elsif ($nobreak) {
 	       $inlineremote[$idx]="\n<tr>".
-		   '<td class="LC_menubuttons_img" align="left">'.
+		   '<td align="left">'.
 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
                     <td class="LC_menubuttons_text" align="left"><a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$text.'</span></a></td>';
 	   } else {
 	       $inlineremote[$idx]="\n<tr>".
-		   '<td class="LC_menubuttons_img" align="left">'.
+		   '<td align="left">'.
 		   '<a href="javascript:'.$act.';">'.$pic.
 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
@@ -990,11 +1166,14 @@ sub inlinemenu {
     &rawconfig(1);
     my $output='<table id="LC_mainmenu"><tr>';
     for (my $col=1; $col<=2; $col++) {
-        $output.='<td class="LC_mainmenu_column">';
+        $output.='<td class="LC_mainmenu_col_fieldset">';
         for (my $row=1; $row<=8; $row++) {
             foreach my $cat (keys(%category_members)) {
                if ($category_positions{$cat} ne "$col,$row") { next; }
-               $output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
+               #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
+               $output.='<div class="LC_ContentBoxSpecial">';
+	       $output.='<h4 class="LC_hcell">'.&mt($category_names{$cat}).'</h4>';
+               $output.='<table>';
                my %active=();
                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
                   if ($inlineremote[$menu_item]) {
@@ -1005,6 +1184,7 @@ sub inlinemenu {
                   $output.=$inlineremote[$item];
                }
                $output.='</table>';
+               $output.='</div>';
             }
          }
          $output.="</td>";
@@ -1121,6 +1301,33 @@ sub rawconfig {
                     }
                 }
             }
+        } elsif ($pro eq 'tools') {
+            my @tools = ('aboutme','blog','portfolio');
+            if (grep(/^\Q$prt\E$/,@tools)) {
+                if (!&Apache::lonnet::usertools_access($env{'user.name'},
+                                                       $env{'user.domain'},
+                                                       $prt,undef,'tools')) {
+                    $output.=&clear($row,$col);
+                    next;
+                }
+            } elsif ($prt eq 'reqcrs') {
+                my $showreqcrs = 0;
+                foreach my $type ('official','unofficial') {
+                    if (&Apache::lonnet::usertools_access($env{'user.name'},
+                                                    $env{'user.domain'},
+                                                    $type,undef,'requestcourses')) {
+                        $showreqcrs = 1;
+                        last;
+                    }
+                }
+                if (!$showreqcrs) {
+                    $output.=&clear($row,$col);
+                    next;
+                }
+            }
+            $prt='any';
+            $output.=&secondlevel(
+          $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
         }
     }
     unless (($env{'browser.interface'} eq 'textual') ||
@@ -1337,16 +1544,16 @@ function set_bookmark() {
    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
    bmquery.document.write(
    '$start_page_bookmark'
-   +"<center><form method='post'"
-   +" name='newlink' action='/adm/bookmarks' target='bmquery' "
-   +">\\n <table width=340 height=150 "
-   +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
-   +"type='text' name='title' size=45 value='"+clienttitle+"' />"
-   +"<br />Address:<br /><input type='text' name='address' size='45' "
-   +"value='"+clienthref+"' /><br /><center><input type='submit' "
-   +"value='Save' /> <input type='button' value='Close (no save)' "
-   +"onclick='javascript:window.close();' /><\\/center><\\/td>"
-   +"<\\/tr><\\/table><\\/form><\\/center>"
+   +'<center><form method="post"'
+   +' name="newlink" action="/adm/bookmarks" target="bmquery" '
+   +'> <table width="340" height="150" '
+   +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
+   +'type="text" name="title" size="45" value="'+clienttitle+'" />'
+   +'<br />Address:<br /><input type="text" name="address" size="45" '
+   +'value="'+clienthref+'" /><br /><center><input type="submit" '
+   +'value="Save" /> <input type="button" value="Close" '
+   +'onclick="javascript:window.close();" /></center></td>'
+   +'</tr></table></form></center>'
    +'$end_page_bookmark' );
    bmquery.document.close();
 }