--- loncom/homework/chemresponse.pm	2003/10/20 16:25:53	1.20
+++ loncom/homework/chemresponse.pm	2004/03/08 17:31:37	1.30
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # chemical equation style response
 #
-# $Id: chemresponse.pm,v 1.20 2003/10/20 16:25:53 albertel Exp $
+# $Id: chemresponse.pm,v 1.30 2004/03/08 17:31:37 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,11 +35,12 @@ BEGIN {
     &Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse'));
 }
 
-sub seperate_jme_window {
+sub separate_jme_window {
     my ($smile_input,$jme_input,$molecule,$options)=@_;
     my $smilesection;
     if (defined($smile_input)) {
 	$smilesection=<<SMILESECTION;
+        smiles = document.applets.JME.smiles();
 	opener.document.lonhomework.$smile_input.value = smiles;
 SMILESECTION
     }
@@ -58,12 +59,12 @@ JMESECTION
 <title>Molecule Editor</title>
 <script language="JavaScript">
 function submitSmiles() {
-    smiles = document.applets.JME.smiles();
-    if (smiles == "") {
+    jmeFile = document.applets.JME.jmeFile();
+    if (jmeFile == "") {
 	alert("Nothing to submit");
     } else {
-        $smilesection
         $jmesection
+        $smilesection
 	window.close();
     }
 }
@@ -74,7 +75,7 @@ function openHelpWindow() {
 </head>
 <body bgcolor="#ffffff">
 <center>
-<applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="97%" height="78%">
+<applet code="JME.class" name="JME" archive="/adm/jme/JME.jar" width="440" height="390">
 You have to enable Java and JavaScript on your machine.
 $molecule
 <param name="options" value="$options" />
@@ -105,6 +106,7 @@ sub start_organicresponse {
     my $partid = $Apache::inputtags::part;
     my $id = &Apache::response::start_response($parstack,$safeeval);
     if ($target eq 'meta') {
+	$result=&Apache::response::meta_package_write('organicresponse');
     } elsif ($target eq 'web') {
 	my $molecule;
 	if (defined($Apache::lonhomework::history{"resource.$partid.$id.molecule"})) {
@@ -115,7 +117,7 @@ sub start_organicresponse {
 	}
 	my $options=&Apache::lonxml::get_param('options',$parstack,
 					       $safeeval);
-	$result=&seperate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,$options);
+	$result=&separate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule,$options);
 	$result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
     } elsif ($target eq 'edit') {
 	$result .=&Apache::edit::tag_start($target,$token);
@@ -127,7 +129,7 @@ sub start_organicresponse {
 				    $token,40);
 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
 						$safeeval);
-	$result .=&seperate_jme_window(undef,
+	$result .=&separate_jme_window(undef,
 		      &Apache::edit::html_element_name('molecule'),
 		      $molecule,$options);
 	$result .='</nobr><br /><nobr>';
@@ -136,13 +138,13 @@ sub start_organicresponse {
 	$result .=&Apache::edit::hidden_arg('jmeanswer',$token);
 	my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
 						 $safeeval);
-	$result .=&seperate_jme_window(
+	$result .=&separate_jme_window(
                       &Apache::edit::html_element_name('answer'),
                       &Apache::edit::html_element_name('jmeanswer'),
 		      $jmeanswer,$options);
 	$result .='</nobr><br />';
 	$result .=&Apache::edit::checked_arg('Options:','options',
-				    [ ['autoez','Auto E,Z sterochemistry'],
+				    [ ['autoez','Auto E,Z stereochemistry'],
 				      ['multipart','Multipart Structures'],
 				      ['nostereo','No stereochemistry'],
 				      ['reaction','Is a reaction'],
@@ -207,7 +209,7 @@ sub start_organicstructure {
 	my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,$safeeval);
 	my $options=&Apache::lonxml::get_param('options',$parstack,$safeeval);
-	my $id=time.'_'.int(rand(1000));
+	my $id=&Apache::loncommon::get_cgi_id();
 	$result="<img src='/cgi-bin/convertjme.pl?$id'";
 	if ($options =~ /border/) { $result.= ' border="1"'; }
 	$result.=' />';
@@ -234,9 +236,8 @@ sub start_organicstructure {
 	if ($options =~ /border/) { $result.= '} '; }
     } elsif ($target eq 'edit') {
 	$result .=&Apache::edit::tag_start($target,$token);
-	$result .=&Apache::edit::text_arg('Width:','width',$token,5);
-	$result .=&Apache::edit::text_arg('Height:','height',$token,5);
-	$result .=&Apache::edit::text_arg('TeXwidth:','texwidth',$token,5);
+	$result .=&Apache::edit::text_arg('Width (pixels):','width',$token,5);
+	$result .=&Apache::edit::text_arg('TeXwidth (mm):','texwidth',$token,5);
 	$result .='<nobr>';
 	$result .=&Apache::edit::text_arg('Molecule:','molecule',$token,40);
 	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
@@ -247,7 +248,7 @@ sub start_organicstructure {
 	    $options.= ',multipart,number';
 	}
 						   
-	$result .=&seperate_jme_window(undef,
+	$result .=&separate_jme_window(undef,
 				 &Apache::edit::html_element_name('molecule'),
 				       $molecule,$options);
 	$result.="</nobr><br />";
@@ -255,12 +256,12 @@ sub start_organicstructure {
 					     [ ['reaction','Is a reaction'],
 					       ['border','Draw a border'] ],
 					     $token);
-	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
+	$result .=&Apache::edit::end_row();
     } elsif ($target eq 'modified') {
 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
 						     $safeeval,'molecule',
-						     'width','height',
-						     'texwidth','options');
+						     'width','texwidth',
+						     'options');
 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
     }
     return $result;
@@ -298,6 +299,7 @@ sub start_reactionresponse {
     my $result;
     my $id = &Apache::response::start_response($parstack,$safeeval);
     if ($target eq 'meta') {
+	$result=&Apache::response::meta_package_write('reactionresponse');
     } elsif ($target eq 'web') {
 	my $partid = $Apache::inputtags::part;
 	my $id = $Apache::inputtags::response['-1'];