MayaChemTools

   1 package HTMLUtil;
   2 #
   3 # $RCSfile: HTMLUtil.pm,v $
   4 # $Date: 2008/04/19 16:11:00 $
   5 # $Revision: 1.28 $
   6 #
   7 # Author: Manish Sud <msud@san.rr.com>
   8 #
   9 # Copyright (C) 2004-2008 Manish Sud. All rights reserved.
  10 #
  11 # This file is part of MayaChemTools.
  12 #
  13 # MayaChemTools is free software; you can redistribute it and/or modify it under
  14 # the terms of the GNU Lesser General Public License as published by the Free
  15 # Software Foundation; either version 3 of the License, or (at your option) any
  16 # later version.
  17 #
  18 # MayaChemTools is distributed in the hope that it will be useful, but without
  19 # any warranty; without even the implied warranty of merchantability of fitness
  20 # for a particular purpose.  See the GNU Lesser General Public License for more
  21 # details.
  22 #
  23 # You should have received a copy of the GNU Lesser General Public License
  24 # along with MayaChemTools; if not, see <http://www.gnu.org/licenses/> or
  25 # write to the Free Software Foundation Inc., 59 Temple Place, Suite 330,
  26 # Boston, MA, 02111-1307, USA.
  27 #
  28 use 5.006;
  29 use strict;
  30 use Exporter;
  31 
  32 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  33 
  34 $VERSION = '1.00';
  35 @ISA = qw(Exporter);
  36 @EXPORT = qw(InsertHTMLTags SetupHTMLAlignmentBegin SetupHTMLAlignmentEnd SetupHTMLButtonRef SetupHTMLDivBegin SetupHTMLDivEnd SetupHTMLEmptyLines SetupHTMLPageHeader SetupHTMLHRef SetupHTMLPageEnd SetupHTMLPageTitle SetupHTMLStyleSheetTags SetupHTMLTableHeader SetupHTMLTableEnd SetupHTMLTableColumnHeader SetupHTMLTableColumnEnd SetupHTMLTableRowHeader SetupHTMLTableRowEnd SetupHTMLTableRowHeaderValue SetupHTMLTableRowDataValue SetupJavaScriptCmds SetupStrViewerJSInitCmd SetupStrViewerJMEApplet SetupStrViewerJmolApplet SetupStrViewerChimePlugIn SetupStrViewerChem3DActiveX SetupStrViewerChemDrawActiveX SetupStrViewerChemDrawPlugIn SetupStrViewerMarvinViewApplet SetupStrViewerAccelrysActiveX);
  37 @EXPORT_OK = qw();
  38 
  39 %EXPORT_TAGS = (all  => [@EXPORT, @EXPORT_OK]);
  40 
  41 # Default window size for various supported structure viewers...
  42 my($StrViewerWidth, $StrViewerHeight) = (250, 170);
  43 
  44 # Insert specfied tags into existing tag string...
  45 sub InsertHTMLTags {
  46   my($Tag, %TagsMap) = @_;
  47   my($NewTag, $TagName, $TagValue, $TagPart1, $TagPart2);
  48 
  49   $NewTag = $Tag; $TagPart1 = ""; $TagPart2 = "";
  50   ($TagPart1) = $Tag =~ /^(.*?)>/;
  51 
  52   if ($TagPart1 && length($TagPart1)) {
  53     $TagPart2 = $Tag;
  54     $TagPart2 =~ s/^(.*?)>//;
  55     if ($TagPart2 && length($TagPart2)) {
  56       for $TagName (keys %TagsMap) {
  57 	$TagValue = $TagsMap{$TagName};
  58 	$TagPart1 .= qq( $TagName="$TagValue" );
  59       }
  60       $NewTag = "${TagPart1}>${TagPart2}";
  61     }
  62   }
  63 
  64   return $NewTag;
  65 }
  66 
  67 sub SetupHTMLAlignmentBegin {
  68   my($AlignmentTag, $Alignment);
  69 
  70   $Alignment = (@_ == 1) ? $_[0] : "left";
  71   $AlignmentTag = qq(<$Alignment>\n);
  72 
  73   return $AlignmentTag;
  74 }
  75 
  76 sub SetupHTMLAlignmentEnd {
  77   my($AlignmentTag, $Alignment);
  78 
  79   $Alignment = (@_ == 1) ? $_[0] : "left";
  80   $AlignmentTag = qq(</$Alignment>\n);
  81 
  82   return $AlignmentTag;
  83 }
  84 
  85 # Setup a button reference...
  86 sub SetupHTMLButtonRef {
  87   my($ButtonLabel, $RefFile, $ButtonTags);
  88 
  89   ($ButtonLabel, $RefFile) = @_;
  90 
  91   $ButtonTags = qq(<input type="button" value="$ButtonLabel" onClick="document.location='$RefFile'">);
  92   return $ButtonTags;
  93 }
  94 
  95 sub SetupHTMLDivBegin {
  96   my($Id) = @_;
  97   my($DivTag);
  98 
  99   $DivTag = qq(<div id="$Id">\n);
 100 
 101   return $DivTag;
 102 }
 103 
 104 sub SetupHTMLDivEnd {
 105   my($DivTag);
 106 
 107   $DivTag = qq(</div>\n);
 108 
 109   return $DivTag;
 110 }
 111 sub SetupHTMLEmptyLines {
 112   my($LineCount, $Index, $EmptyLineTags);
 113 
 114   $LineCount = 1;
 115   $EmptyLineTags = qq(<p>&nbsp</p>);
 116   ($LineCount) = @_;
 117   if ($LineCount > 1) {
 118     for $Index (2 .. $LineCount) {
 119       $EmptyLineTags .= qq(<p>&nbsp</p>);
 120     }
 121   }
 122   return $EmptyLineTags;
 123 }
 124 
 125 # Setup HTML page header...
 126 sub SetupHTMLPageHeader {
 127   my($HeaderTitle, $Stylesheet, $JavaScript, $PageHeader);
 128 
 129   $HeaderTitle = "";  $Stylesheet = ""; $JavaScript = "";
 130   if (@_ == 3) {
 131     ($HeaderTitle, $Stylesheet, $JavaScript) = @_;
 132   }
 133   elsif (@_ == 2) {
 134     ($HeaderTitle, $Stylesheet) = @_;
 135   }
 136   else {
 137     ($HeaderTitle) = @_;
 138   }
 139   $PageHeader = qq(<html>\n);
 140   $PageHeader .= qq(<head>\n);
 141   $PageHeader .= qq(<title>$HeaderTitle</title>\n);
 142   $PageHeader .= qq(<meta http-equiv="content-type" content="text/html;charset=utf-8">\n);
 143   if ($Stylesheet) {
 144     $PageHeader .= qq(<link rel="stylesheet" type="text/css" href="$Stylesheet">\n);
 145   }
 146   if ($JavaScript) {
 147     $PageHeader .= qq(<script src="$JavaScript"></script>\n);
 148   }
 149   $PageHeader .= <<ENDPAGEHEADER;
 150 </head>
 151 <body>
 152 <p>&nbsp</p>
 153 ENDPAGEHEADER
 154 
 155   return $PageHeader;
 156 }
 157 
 158 # Setup page title...
 159 sub SetupHTMLPageTitle {
 160   my($Title, $Alignment, $PageTitle);
 161 
 162   $Alignment = "center";
 163   if (@_ == 2) {
 164     ($Title, $Alignment) = @_;
 165   }
 166   else {
 167     ($Title) = @_;
 168   }
 169 
 170   $PageTitle=<<ENDPAGETITLE;
 171 <$Alignment>
 172 <h3>$Title</h3>
 173 </$Alignment>
 174 ENDPAGETITLE
 175 
 176   return $PageTitle;
 177 }
 178 
 179 # Setup HTML page end...
 180 sub SetupHTMLPageEnd {
 181   my($PageEnd, $Footer);
 182 
 183   $Footer = "";
 184   if (@_ == 1) {
 185     ($Footer) = @_;
 186   }
 187   if ($Footer) {
 188     $Footer = qq(<span class="Footer">$Footer</span>);
 189   }
 190   $PageEnd=<<ENDPAGE;
 191 <center>
 192 <p>&nbsp</p>
 193 $Footer
 194 </center>
 195 </body>
 196 </html>
 197 ENDPAGE
 198 
 199   return $PageEnd;
 200 }
 201 
 202 # Setup HTML link tags...
 203 sub SetupHTMLHRef {
 204   my($Value, $RefFile, $HRef, $Title);
 205 
 206   $Title = "";
 207   if (@_ == 3) {
 208     ($Value, $RefFile, $Title) = @_;
 209   }
 210   else {
 211     ($Value, $RefFile) = @_;
 212   }
 213 
 214   $HRef = qq(<a href="$RefFile");
 215   if ($Title) {
 216     $HRef .= qq( title="$Title");
 217   }
 218   $HRef .= qq(>$Value</a>);
 219   return $HRef;
 220 }
 221 
 222 #
 223 sub SetupHTMLStyleSheetTags {
 224   my($StyleSheetTags);
 225 
 226   $StyleSheetTags=<<ENDSTYLESHEET;
 227 body
 228 {
 229     background-color: #ffffff;
 230     font-family: Verdana, Arial, Helvetica, sans-serif;
 231     font-size: 11px;
 232 }
 233 p
 234 {
 235     font-family: Verdana, Arial, Helvetica, sans-serif;
 236     font-size: 11px;
 237 }
 238 h1
 239 {
 240     font-family: Verdana, Arial, Helvetica, sans-serif;
 241     font-size: 25px;
 242     font-weight: bold;
 243     color: #0054aa;
 244 }
 245 h2
 246 {
 247     font-family: Verdana, Arial, Helvetica, sans-serif;
 248     font-size: 18px;
 249     font-weight: bold;
 250     color: #0054aa;
 251 }
 252 h3
 253 {
 254     font-family: Verdana, Arial, Helvetica, sans-serif;
 255     font-size: 14px;
 256     font-weight: bold;
 257     color: #0054aa;
 258 }
 259 b
 260 {
 261     font-weight: bold;
 262 }
 263 td
 264 {
 265     font-family: Verdana, Arial, Helvetica, sans-serif;
 266     font-size: 11px;
 267 }
 268 th
 269 {
 270     font-family: Verdana, Arial, Helvetica, sans-serif;
 271     font-size: 11px;
 272     color: #0054aa;
 273     font-weight: bold;
 274 }
 275 .box {
 276   border-color: #000000;
 277   border-style: solid;
 278   border-top-width: 1px;
 279   border-bottom-width: 1px;
 280   border-left-width: 1px;
 281   border-right-width: 1px;
 282 }
 283 a
 284 {
 285     color: #0000bb;
 286     text-decoration: none;
 287     font-family: Verdana, Arial, Helvetica, sans-serif;
 288     font-size: 11px;
 289 }
 290 a:hover
 291 {
 292     color: #ff0000;
 293 }
 294 #tablenav {
 295     font-family: Verdana, Arial, Helvetica, sans-serif;
 296     font-size: 11px;
 297 }
 298 #tablenav td
 299 {
 300     font-family: Verdana, Arial, Helvetica, sans-serif;
 301     font-size: 11px;
 302 }
 303 #tablenav th
 304 {
 305     font-family: Verdana, Arial, Helvetica, sans-serif;
 306     font-size: 11px;
 307     font-weight: bold;
 308 }
 309 #tablenav a
 310 {
 311     color: #0000bb;
 312     text-decoration: none;
 313     font-family: Verdana, Arial, Helvetica, sans-serif;
 314     font-size: 11px;
 315 }
 316 #tablenav a:hover
 317 {
 318     color: #ff0000;
 319 }
 320 .footer
 321 {
 322     font-family: Arial, Verdana, Helvetica, sans-serif;
 323     font-size: 9px;
 324     color: #888888;
 325 }
 326 ENDSTYLESHEET
 327 
 328   return $StyleSheetTags;
 329 }
 330 
 331 # Setup HTML table header...
 332 sub SetupHTMLTableHeader {
 333   my($TableHeader, $BorderWidth, $CellPadding, $CellSpacing, $Width, $Height);
 334 
 335   $BorderWidth = 1; $CellPadding = 2; $CellSpacing = 0; $Width = ""; $Height = "";
 336   if (@_ == 5) {
 337     ($BorderWidth, $CellPadding, $CellSpacing, $Width, $Height) = @_;
 338   }
 339   elsif (@_ == 4) {
 340     ($BorderWidth, $CellPadding, $CellSpacing, $Width) = @_;
 341   }
 342   elsif (@_ == 3) {
 343     ($BorderWidth, $CellPadding, $CellSpacing) = @_;
 344   }
 345   elsif (@_ == 2) {
 346     ($BorderWidth, $CellPadding) = @_;
 347   }
 348   elsif (@_ = 1) {
 349     ($BorderWidth) = @_;
 350   }
 351   $TableHeader = qq(<table border=$BorderWidth cellpadding=$CellPadding cellspacing=$CellSpacing);
 352   if ($Width) {
 353     $TableHeader .= qq( width=$Width);
 354   }
 355   if ($Height) {
 356     $TableHeader .= qq( height=$Height);
 357   }
 358   $TableHeader .= qq(>\n);
 359 
 360   return $TableHeader;
 361 }
 362 
 363 # Setup HTML table end...
 364 sub SetupHTMLTableEnd {
 365   my($TableEnd);
 366 
 367   $TableEnd=<<ENDTABLE;
 368 </table>
 369 ENDTABLE
 370 
 371   return $TableEnd;
 372 }
 373 
 374 # Setup HTML table column header...
 375 sub SetupHTMLTableColumnHeader {
 376   my($BgColor, $Width, $ColumnHeader);
 377 
 378   $BgColor = ""; $Width = "";
 379   if (@_ == 1) {
 380     ($BgColor) = @_;
 381   }
 382   elsif (@_ == 2) {
 383     ($BgColor, $Width) = @_;
 384   }
 385   $ColumnHeader = qq(<td);
 386   if ($BgColor) {
 387     $ColumnHeader .= qq( bgcolor="$BgColor")
 388   }
 389   if ($Width) {
 390     $ColumnHeader .= qq( width="$Width")
 391   }
 392   $ColumnHeader .= qq(>);
 393   return $ColumnHeader;
 394 }
 395 
 396 # Setup HTML table column end...
 397 sub SetupHTMLTableColumnEnd {
 398   my($ColumnEnd);
 399 
 400   $ColumnEnd = qq(</td>);
 401   return $ColumnEnd;
 402 }
 403 
 404 # Setup HTML table row header...
 405 sub SetupHTMLTableRowHeader {
 406   my($RowHeader, $HAlignment, $BgColor, $VAlignment);
 407 
 408   $HAlignment = "center"; $BgColor = ""; $VAlignment = "top";
 409   if (@_ == 3) {
 410     ($HAlignment, $BgColor, $VAlignment) = @_;
 411   }
 412   elsif (@_ == 2) {
 413     ($HAlignment, $BgColor) = @_;
 414   }
 415   elsif (@_ == 1) {
 416     ($HAlignment) = @_;
 417   }
 418   if ($BgColor) {
 419     $RowHeader = qq(<tr bgcolor="$BgColor" align="$HAlignment" valign="$VAlignment">);
 420   }
 421   else {
 422     $RowHeader = qq(<tr align="$HAlignment" valign="$VAlignment">);
 423   }
 424 
 425   return $RowHeader;
 426 }
 427 
 428 # Setup HTML table row end...
 429 sub SetupHTMLTableRowEnd {
 430   my($RowEnd);
 431 
 432   $RowEnd = qq(</tr>\n);
 433   return $RowEnd;
 434 }
 435 
 436 # Setup HTML table header values...
 437 sub SetupHTMLTableRowHeaderValue {
 438   my($HeaderValue, $Value);
 439 
 440   $Value = "";
 441   if (@_ >= 1) {
 442     ($Value) = @_;
 443   }
 444   if (defined $Value && length $Value) {
 445     $HeaderValue = qq(<th>$Value</th>);
 446   }
 447   else {
 448     $HeaderValue = qq(<th>&nbsp</th>);
 449   }
 450   return $HeaderValue;
 451 }
 452 
 453 # Setup HTML table row data values...
 454 sub SetupHTMLTableRowDataValue {
 455   my($RowValues, $Value, $BgColor, $FontColor, $FontBold, $FontBoldTag1, $FontBoldTag2);
 456 
 457   $Value = ""; $BgColor = ""; $FontColor = ""; $FontBold = "";
 458   if (@_ == 1) {
 459     ($Value) = @_;
 460   }
 461   elsif (@_ == 2) {
 462     ($Value, $BgColor) = @_;
 463   }
 464   elsif (@_ == 3) {
 465     ($Value, $BgColor, $FontColor) = @_;
 466   }
 467   elsif (@_ == 4) {
 468     ($Value, $BgColor, $FontColor, $FontBold) = @_;
 469   }
 470   if (!(defined $Value && length $Value)) {
 471     $Value = qq(&nbsp);
 472   }
 473   $FontBoldTag1 = ""; $FontBoldTag2 = "";
 474   if ($FontBold) {
 475     $FontBoldTag1 = qq(<b>);
 476     $FontBoldTag2 = qq(</b>);
 477   }
 478   if ($BgColor || $FontColor) {
 479     my ($BgColorTag, $FontTag1, $FontTag2);
 480 
 481     $BgColorTag = "";
 482     if ($BgColor) {
 483       $BgColorTag = qq( bgcolor="$BgColor");
 484     }
 485     $FontTag1 = ""; $FontTag2 = "";
 486     if ($FontColor) {
 487       $FontTag1 = qq(<font color="$FontColor">);
 488       $FontTag2 = qq(</font>);
 489     }
 490     if ($FontBold) {
 491       $RowValues = "<td" . $BgColorTag . ">" . $FontBoldTag1 . $FontTag1 . "$Value" . $FontTag2 . $FontBoldTag2 .  "</td>";
 492     }
 493     else {
 494       $RowValues = "<td" . $BgColorTag . ">" . $FontTag1 . "$Value" . $FontTag2 .  "</td>";
 495     }
 496   }
 497   elsif ($FontBold) {
 498     $RowValues = "<td>" . $FontBoldTag1 . "$Value" . $FontBoldTag2 . "</td>";
 499   }
 500   else {
 501     $RowValues = qq(<td>$Value</td>);
 502   }
 503   return $RowValues;
 504 }
 505 
 506 # Setup Java scripts command...
 507 sub SetupJavaScriptCmds {
 508   my(@JSCmdList) = @_;
 509   my($JSTags, $JSCmd);
 510 
 511   $JSTags = qq(<script>\n);
 512   for $JSCmd (@JSCmdList) {
 513     $JSTags .= qq($JSCmd\n);
 514   }
 515   $JSTags .= qq(</script>\n);
 516 
 517   return $JSTags;
 518 }
 519 
 520 # Setup Java script initialize command...
 521 sub SetupStrViewerJSInitCmd {
 522   my($StrViewerType, $CodeBase) = @_;
 523   my($JSTag);
 524 
 525   $JSTag = "";
 526   if ($StrViewerType eq "Jmol") {
 527     $JSTag = qq(<script>jmolInitialize("$CodeBase");</script>\n);
 528   }
 529   elsif ($StrViewerType eq "ChemDrawPlugIn" || $StrViewerType eq "ChemDrawActiveX") {
 530     $JSTag = qq(<script>cd_includeWrapperFile("$CodeBase/");</script>\n);
 531   }
 532   elsif ($StrViewerType eq "Chem3DActiveX") {
 533   }
 534   return $JSTag;
 535 }
 536 
 537 
 538 # Setup Jmol applet...
 539 sub SetupStrViewerJmolApplet {
 540   my($MolString, $CodeBase, $ParamsMapRef, %ParamsMap, $AppletTags, $JavaScriptTags, $ReturnTags, $Name, $Code, $Archive, $Width, $Height, $ParamName, $ParamValue, $JSFileName, $UseJavaScript);
 541   my($ProgressBar, $ProgressColor, $BoxMessage, $BoxFgColor, $BoxBgColor, $BgColor, $JMolScript);
 542 
 543   $AppletTags = "";  $JavaScriptTags = ""; $ReturnTags = "";
 544   $ParamsMapRef = ""; %ParamsMap = ();
 545   $Name = "Jmol"; $Code = "JmolApplet"; $Archive = "JmolApplet.jar"; $Width = $StrViewerWidth; $Height = $StrViewerHeight;
 546   $ProgressBar = "true"; $ProgressColor = "#0000ff"; $BgColor = "#000000";
 547   $BoxMessage = "Setting up JmolApplet..."; $BoxFgColor = "#000000"; $BoxBgColor = "#ffffff";
 548   $UseJavaScript = 0; $JSFileName = "";
 549   $JMolScript = "select *; set frank off; wireframe on; spacefill off";
 550 
 551  PARAMS: {
 552     if (@_ == 3) { ($MolString, $CodeBase, $ParamsMapRef) = @_; last PARAMS; }
 553     ($MolString, $CodeBase) = @_;
 554   }
 555 
 556   if ($ParamsMapRef) {
 557     %ParamsMap = %$ParamsMapRef;
 558     if (exists $ParamsMap{usejavascript} ) { $JSFileName = $ParamsMap{usejavascript}; $UseJavaScript = 1; $ParamsMap{usejavascript} = ""; }
 559     if (exists $ParamsMap{name} ) { $Name = $ParamsMap{name}; $ParamsMap{name} = ""; }
 560     if (exists $ParamsMap{code} ) { $Code = $ParamsMap{code}; $ParamsMap{code} = ""; }
 561     if (exists $ParamsMap{archive} ) { $Archive = $ParamsMap{archive}; $ParamsMap{archive} = ""; }
 562     if (exists $ParamsMap{height} ) { $Height = $ParamsMap{height}; $ParamsMap{height} = ""; }
 563     if (exists $ParamsMap{width} ) { $Width = $ParamsMap{width}; $ParamsMap{width} = ""; }
 564     if (exists $ParamsMap{progressbar} ) { $ProgressBar = $ParamsMap{progressbar}; $ParamsMap{progressbar} = ""; }
 565     if (exists $ParamsMap{progresscolor} ) { $ProgressColor = $ParamsMap{progresscolor}; $ParamsMap{progresscolor} = ""; }
 566     if (exists $ParamsMap{boxmessage} ) { $BoxMessage = $ParamsMap{boxmessage}; $ParamsMap{boxmessage} = ""; }
 567     if (exists $ParamsMap{script} ) { $JMolScript = $ParamsMap{script}; $ParamsMap{script} = ""; }
 568     if (exists $ParamsMap{bgcolor}) {
 569       $BgColor = $ParamsMap{bgcolor};
 570       if (length($BgColor)) {
 571 	if ($BgColor =~ /black/i || $BgColor =~ /#000000/ ) {
 572 	  $BoxFgColor = "#ffffff";
 573 	  $BoxBgColor = "#000000";
 574 	}
 575       }
 576     }
 577     if (exists $ParamsMap{boxbgcolor} ) { $BoxBgColor = $ParamsMap{boxbgcolor}; $ParamsMap{boxbgcolor} = ""; }
 578     if (exists $ParamsMap{boxfgcolor} ) { $BoxFgColor = $ParamsMap{boxfgcolor}; $ParamsMap{boxfgcolor} = ""; }
 579   }
 580 
 581   $MolString =~ s/(\r\n)|(\r)|(\n)/|/g;
 582   if ($UseJavaScript) {
 583     $JavaScriptTags = qq(\n<script>\n);
 584     my($Size) = ($Width > $Height ) ? $Width : $Height;
 585     $JavaScriptTags .= qq(var $Name = \n);
 586     my(@MolLines) = split /\|/, $MolString;
 587     my($LineIndex);
 588     $JavaScriptTags .= qq("$MolLines[0]\\n");
 589     for $LineIndex (1 .. $#MolLines) {
 590       $JavaScriptTags .= qq( + \n"$MolLines[$LineIndex]\\n");
 591     }
 592     $JavaScriptTags .= qq(;\n);
 593     $JavaScriptTags .= qq(jmolSetAppletColor("$BgColor", "$BoxBgColor", "$BoxFgColor", "$ProgressColor");\n);
 594     # "set frank off turns" off JMol logo. For wireframe display; use wireframe on; spacefill off...
 595     # $JavaScriptTags .= qq(jmolAppletInline($Size, $Name);\n);
 596     $JavaScriptTags .= qq(jmolAppletInline([$Width,$Height], $Name, \"$JMolScript\");\n);
 597     $JavaScriptTags .= qq(</script>\n);
 598     $ReturnTags = $JavaScriptTags;
 599   }
 600   else {
 601     # Setup applet header...
 602     $AppletTags = qq(\n<applet name="$Name" id="$Name" code="$Code" archive="$Archive" codebase="$CodeBase" width="$Width" height="$Height">\n);
 603 
 604     # Setup molecule data...
 605     $AppletTags .= qq(<param name="loadInline" value="$MolString">\n);
 606 
 607     # Setup prograss bar...
 608     $AppletTags .= qq(<param name="progressbar" value="$ProgressBar">\n<param name="progresscolor" value="$ProgressColor">\n<param name="boxmessage" value="$BoxMessage">\n<param name="boxbgcolor" value="$BoxBgColor">\n<param name="boxfgcolor" value="$BoxFgColor">\n);
 609 
 610     # "set frank off turns" off JMol logo. For wireframe display; use wireframe on; spacefill off...
 611     $AppletTags .= qq(<param name="script" value="$JMolScript">);
 612 
 613     #Setup other parameters...
 614     for $ParamName (sort keys %ParamsMap) {
 615       $ParamValue = $ParamsMap{$ParamName};
 616       if (length $ParamValue) {
 617 	$AppletTags .= qq(<param name="$ParamName" value="$ParamValue">\n);
 618       }
 619     }
 620     #Finish it up...
 621     $AppletTags .= qq(</applet>\n);
 622     $ReturnTags = $AppletTags;
 623   }
 624   return $ReturnTags;
 625 }
 626 
 627 # Setup JME applet...
 628 sub SetupStrViewerJMEApplet {
 629   my($MolString, $CodeBase, $ParamsMapRef, %ParamsMap, $AppletTags, $Name, $Code, $Archive, $Width, $Height, $ParamName, $ParamValue);
 630   my($Options);
 631 
 632   $AppletTags = "";  $ParamsMapRef = ""; %ParamsMap = ();
 633   $Name = "JME"; $Code = "JME"; $Archive = "JME.jar"; $Width = $StrViewerWidth; $Height = $StrViewerHeight;
 634   $Options = "depict";
 635 
 636   if (@_ == 3) {
 637     ($MolString, $CodeBase, $ParamsMapRef) = @_;
 638   }
 639   else {
 640     ($MolString, $CodeBase) = @_;
 641   }
 642   $MolString =~ s/(\r\n)|(\r)|(\n)/|/g;
 643 
 644   if ($ParamsMapRef) {
 645     %ParamsMap = %$ParamsMapRef;
 646     if (exists $ParamsMap{name} ) { $Name = $ParamsMap{name}; $ParamsMap{name} = ""; }
 647     if (exists $ParamsMap{code} ) { $Code = $ParamsMap{code}; $ParamsMap{code} = ""; }
 648     if (exists $ParamsMap{archive} ) { $Archive = $ParamsMap{archive}; $ParamsMap{archive} = ""; }
 649     if (exists $ParamsMap{height} ) { $Height = $ParamsMap{height}; $ParamsMap{height} = ""; }
 650     if (exists $ParamsMap{width} ) { $Width = $ParamsMap{width}; $ParamsMap{width} = ""; }
 651     if (exists $ParamsMap{options} ) { $Options = $ParamsMap{options}; $ParamsMap{options} = ""; }
 652   }
 653 
 654   # Setup applet header...
 655   $AppletTags = qq(\n<applet name="$Name" id="$Name" code="$Code" archive="$Archive" codebase="$CodeBase" width="$Width" height="$Height">\n);
 656 
 657   # Setup molecule data...
 658   $AppletTags .= qq(<param name="mol" value="$MolString">\n<param name="options" value="$Options">\n);
 659 
 660   #Setup other parameters...
 661   for $ParamName (sort keys %ParamsMap) {
 662     $ParamValue = $ParamsMap{$ParamName};
 663     if (length $ParamValue) {
 664       $AppletTags .= qq(<param name="$ParamName" value="$ParamValue">\n);
 665     }
 666   }
 667 
 668   #Finish it up...
 669   $AppletTags .= qq(</applet>\n);
 670 
 671   return $AppletTags;
 672 }
 673 
 674 # Setup MarvinView applet...
 675 sub SetupStrViewerMarvinViewApplet {
 676   my($MolString, $CodeBase, $ParamsMapRef, %ParamsMap, $AppletTags, $JavaScriptTags, $ReturnTags, $Name, $Code, $Archive, $Width, $Height, $ParamName, $NavMode, $ParamValue, $JSFileName, $UseJavaScript, $MarvinJVM);
 677 
 678   $AppletTags = "";  $JavaScriptTags = ""; $ReturnTags = "";
 679   $ParamsMapRef = ""; %ParamsMap = ();
 680   $Name = "MView"; $Code = "MView"; $Archive = "marvin.jar"; $Width = $StrViewerWidth; $Height = $StrViewerHeight;
 681   $NavMode = "zoom";
 682   $UseJavaScript = 0; $JSFileName = ""; $MarvinJVM = "";
 683 
 684   if (@_ == 3) {
 685     ($MolString, $CodeBase, $ParamsMapRef) = @_;
 686   }
 687   else {
 688     ($MolString, $CodeBase) = @_;
 689   }
 690 
 691   if ($ParamsMapRef) {
 692     %ParamsMap = %$ParamsMapRef;
 693     if (exists $ParamsMap{usejavascript} ) { $JSFileName = $ParamsMap{usejavascript}; $UseJavaScript = 1; $ParamsMap{usejavascript} = ""; }
 694     if (exists $ParamsMap{marvin_jvm} ) { $MarvinJVM = $ParamsMap{marvin_jvm}; $ParamsMap{marvin_jvm} = ""; }
 695     if (exists $ParamsMap{name} ) { $Name = $ParamsMap{name}; $ParamsMap{name} = ""; }
 696     if (exists $ParamsMap{code} ) { $Code = $ParamsMap{code}; $ParamsMap{code} = ""; }
 697     if (exists $ParamsMap{archive} ) { $Archive = $ParamsMap{archive}; $ParamsMap{archive} = ""; }
 698     if (exists $ParamsMap{height} ) { $Height = $ParamsMap{height}; $ParamsMap{height} = ""; }
 699     if (exists $ParamsMap{width} ) { $Width = $ParamsMap{width}; $ParamsMap{width} = ""; }
 700     if (exists $ParamsMap{bgcolor}) {
 701       $ParamsMap{background} = "$ParamsMap{bgcolor}";
 702       $ParamsMap{molbg} = "$ParamsMap{bgcolor}";
 703       $ParamsMap{bgcolor} = "";
 704     }
 705     if (exists $ParamsMap{navmode}) {
 706       $NavMode = $ParamsMap{navmode};
 707       $ParamsMap{navmode} = "";
 708     }
 709   }
 710   $MolString =~ s/(\r\n)|(\r)|(\n)/\\/g;
 711   if ($UseJavaScript) {
 712     $JavaScriptTags = qq(\n<script>\n);
 713     $JavaScriptTags .= qq(var marvin_name = "$Name";\n);
 714     $JavaScriptTags .= qq(var marvin_jvm = "$MarvinJVM";\n);
 715 
 716     $JavaScriptTags .= qq(mview_begin("$CodeBase", $Width, $Height);\n);
 717 
 718     $JavaScriptTags .= qq(var $Name = \n);
 719     my(@MolLines) = split /\\/, $MolString;
 720     my($LineIndex);
 721     $JavaScriptTags .= qq("$MolLines[0]\\n");
 722     for $LineIndex (1 .. $#MolLines) {
 723       $JavaScriptTags .= qq( + \n"$MolLines[$LineIndex]\\n");
 724     }
 725     $JavaScriptTags .= qq(;\n);
 726     $JavaScriptTags .= qq(mview_param("mol", $Name);\n);
 727 
 728     $JavaScriptTags .= qq(mview_param("navmode", "$NavMode");\n);
 729 
 730     for $ParamName (sort keys %ParamsMap) {
 731       $ParamValue = $ParamsMap{$ParamName};
 732       if (length $ParamValue) {
 733 	$JavaScriptTags .= qq(mview_param("$ParamName", "$ParamValue");\n);
 734       }
 735     }
 736     $JavaScriptTags .= qq(mview_end();\n);
 737     $JavaScriptTags .= qq(</script>\n);
 738     $ReturnTags = $JavaScriptTags;
 739   }
 740   else {
 741     # Setup applet header...
 742     $AppletTags = qq(\n<applet name="$Name" id="$Name" code="$Code" archive="$Archive" codebase="$CodeBase" width="$Width" height="$Height">\n);
 743 
 744     # Setup molecule data...
 745     $AppletTags .= qq(<param name="mol" value="$MolString">\n);
 746 
 747     $AppletTags .= qq(<param name="navmode" value="$NavMode">\n);
 748 
 749     #Setup other parameters...
 750     for $ParamName (sort keys %ParamsMap) {
 751       $ParamValue = $ParamsMap{$ParamName};
 752       if (length $ParamValue) {
 753 	$AppletTags .= qq(<param name="$ParamName" value="$ParamValue">\n);
 754       }
 755     }
 756     $AppletTags .= qq(</applet>\n);
 757     $ReturnTags = $AppletTags;
 758   }
 759   return $ReturnTags;
 760 }
 761 
 762 # Setup MDL chime plug-in...
 763 sub SetupStrViewerChimePlugIn {
 764   my($MolFile, $ParamsMapRef, %ParamsMap, $Width, $Height, $ParamName, $ParamValue, $PlugInTags);
 765   my($Display2D);
 766 
 767   $PlugInTags = ""; $ParamsMapRef = ""; %ParamsMap = ();
 768   $Width = $StrViewerWidth; $Height = $StrViewerHeight;
 769   $Display2D = "true";
 770 
 771   if (@_ == 2) {
 772     ($MolFile, $ParamsMapRef) = @_;
 773   }
 774   else {
 775     ($MolFile) = @_;
 776   }
 777 
 778   if ($ParamsMapRef) {
 779     %ParamsMap = %$ParamsMapRef;
 780     if (exists $ParamsMap{height} ) { $Height = $ParamsMap{height}; $ParamsMap{height} = ""; }
 781     if (exists $ParamsMap{width} ) { $Width = $ParamsMap{width}; $ParamsMap{width} = ""; }
 782     if (exists $ParamsMap{display2d} ) { $Display2D = $ParamsMap{display2d}; $ParamsMap{display2d} = ""; }
 783   }
 784   # Start plug-in tag...
 785   $PlugInTags = qq(<embed src="$MolFile" width="$Width" height="$Height" display2d="$Display2D");
 786 
 787   #Setup other parameters...
 788   for $ParamName (sort keys %ParamsMap) {
 789     $ParamValue = $ParamsMap{$ParamName};
 790     if (length $ParamValue) {
 791       $PlugInTags .= qq(" $ParamName"="$ParamValue");
 792     }
 793   }
 794 
 795   # Finish it off...
 796   $PlugInTags .= qq( >);
 797 
 798   return $PlugInTags;
 799 }
 800 
 801 # Setup Accelrys ViewerActiveX controls...
 802 sub SetupStrViewerAccelrysActiveX {
 803   my($MolFile, $ParamsMapRef, %ParamsMap, $ActiveXTags, $Name, $Width, $Height, $ParamName, $ParamValue);
 804   my($ClassId, $Convert2DTo3D, $Style, $Mouse);
 805 
 806   $ActiveXTags = "";  $ParamsMapRef = ""; %ParamsMap = ();
 807   $Name = "ViewerActiveX"; $Width = $StrViewerWidth; $Height = $StrViewerHeight;
 808   $ClassId = "clsid:90690CB6-BC07-11D4-AEF7-0050DA948176";
 809   $Convert2DTo3D = "0";
 810   $Mouse = 4;
 811 
 812   if (@_ == 2) {
 813     ($MolFile, $ParamsMapRef) = @_;
 814   }
 815   else {
 816     ($MolFile) = @_;
 817   }
 818 
 819   if ($ParamsMapRef) {
 820     %ParamsMap = %$ParamsMapRef;
 821     if (exists $ParamsMap{classid} ) { $ClassId = $ParamsMap{classid}; $ParamsMap{classid} = ""; }
 822     if (exists $ParamsMap{name} ) { $Name = $ParamsMap{name}; $ParamsMap{name} = ""; }
 823     if (exists $ParamsMap{height} ) { $Height = $ParamsMap{height}; $ParamsMap{height} = ""; }
 824     if (exists $ParamsMap{width} ) { $Width = $ParamsMap{width}; $ParamsMap{width} = ""; }
 825     if (exists $ParamsMap{Convert2Dto3D} ) { $Convert2DTo3D = $ParamsMap{Convert2Dto3D}; $ParamsMap{Convert2Dto3D} = ""; }
 826     if (exists $ParamsMap{Mouse} ) { $Mouse = $ParamsMap{Mouse}; $ParamsMap{Mouse} = ""; }
 827     if (exists $ParamsMap{bgcolor} ) {
 828       my($BgColor) = $ParamsMap{bgcolor};
 829       $ParamsMap{bgcolor} = "";
 830       # Get OLE color value: &aabbggrr&
 831       # Set it to white for now...
 832       $BgColor = "16777215";
 833       $ParamsMap{BackColor} = "$BgColor";
 834     }
 835   }
 836   $Style = qq(style="height: ) . $Height . qq(px; width: ) . $Width . qq(px");
 837 
 838   # Setup object header...
 839   $ActiveXTags = qq(\n<object id="$Name" classid="$ClassId" $Style>\n);
 840 
 841   # Setup molecule data...
 842   $ActiveXTags .= qq(<param name="Source" value="$MolFile">\n<param name="Mouse" value="$Mouse">\n<param name="Convert2Dto3D" value="$Convert2DTo3D">\n);
 843 
 844   #Setup other parameters...
 845   for $ParamName (sort keys %ParamsMap) {
 846     $ParamValue = $ParamsMap{$ParamName};
 847     if (length $ParamValue) {
 848       $ActiveXTags .= qq(<param name="$ParamName" value="$ParamValue">\n);
 849     }
 850   }
 851 
 852   # Finish it off...
 853   $ActiveXTags .= qq(</object>\n);
 854 
 855   return $ActiveXTags;
 856 }
 857 
 858 # Setup Chem3D ActiveX 8.0 control...
 859 sub SetupStrViewerChem3DActiveX {
 860   my($MolFile, $ParamsMapRef, %ParamsMap, $ActiveXTags, $JavaScriptTags, $ReturnTags, $Name, $Width, $Height, $ParamName, $ParamValue);
 861   my($ClassId, $Style, $DisplayType, $RotationBars, $MovieController, $JSFileName, $UseJavaScript);
 862 
 863   $ActiveXTags = ""; $JavaScriptTags = ""; $ReturnTags = "";
 864   $ParamsMapRef = ""; %ParamsMap = ();
 865   $Name = "Chem3D"; $Width = $StrViewerWidth; $Height = $StrViewerHeight;
 866   $ClassId = "clsid:B7A6B8E4-3E8B-4D18-8F8F-B4057EFC784B";
 867   $DisplayType = "Ball&Stick";
 868   $RotationBars = "false";
 869   $MovieController = "false";
 870 
 871   if (@_ == 2) {
 872     ($MolFile, $ParamsMapRef) = @_;
 873   }
 874   else {
 875     ($MolFile) = @_;
 876   }
 877 
 878   if ($ParamsMapRef) {
 879     %ParamsMap = %$ParamsMapRef;
 880     if (exists $ParamsMap{usejavascript} ) { $JSFileName = $ParamsMap{usejavascript}; $UseJavaScript = 1; $ParamsMap{usejavascript} = ""; }
 881     if (exists $ParamsMap{classid} ) { $ClassId = $ParamsMap{classid}; $ParamsMap{classid} = ""; }
 882     if (exists $ParamsMap{name} ) { $Name = $ParamsMap{name}; $ParamsMap{name} = ""; }
 883     if (exists $ParamsMap{height} ) { $Height = $ParamsMap{height}; $ParamsMap{height} = ""; }
 884     if (exists $ParamsMap{width} ) { $Width = $ParamsMap{width}; $ParamsMap{width} = ""; }
 885     if (exists $ParamsMap{displaytype} ) { $DisplayType = $ParamsMap{displaytype}; $ParamsMap{displaytype} = ""; }
 886     if (exists $ParamsMap{rotationbars} ) { $RotationBars = $ParamsMap{rotationbars}; $ParamsMap{rotationbars} = ""; }
 887     if (exists $ParamsMap{moviecontroller} ) { $MovieController = $ParamsMap{moviecontroller}; $ParamsMap{moviecontroller} = ""; }
 888   }
 889   $Style = qq(style="height: ) . $Height . qq(px; width: ) . $Width . qq(px");
 890 
 891   if ($UseJavaScript) {
 892     #Setup parameters...
 893     my($Params) = "";
 894     for $ParamName (sort keys %ParamsMap) {
 895       $ParamValue = $ParamsMap{$ParamName};
 896       if (length $ParamValue) {
 897 	$Params .= qq( $ParamName='$ParamValue');
 898       }
 899     }
 900     $JavaScriptTags = qq(\n<script>\n);
 901     $JavaScriptTags .= qq(c3d_insert3dStr("name='$Name' src='$MolFile' width='$Width' height='$Height' displaytype='$DisplayType' rotation_bars_visible='$RotationBars' movie_controller_visible='$MovieController' $Params");\n);
 902     $JavaScriptTags .= qq(</script>\n);
 903     $ReturnTags = $JavaScriptTags;
 904   }
 905   else {
 906     # Setup object header...
 907     $ActiveXTags = qq(\n<object id="$Name" classid="$ClassId" $Style>\n);
 908 
 909     # Setup molecule data...
 910     $ActiveXTags .= qq(<param name="src" value="$MolFile">\n<param name="displaytype" value="$DisplayType">\n<param name="rotationbars" value="$RotationBars">\n<param name="moviecontroller" value="$MovieController">\n);
 911 
 912     #Setup other parameters...
 913     for $ParamName (sort keys %ParamsMap) {
 914       $ParamValue = $ParamsMap{$ParamName};
 915       if (length $ParamValue) {
 916 	$ActiveXTags .= qq(<param name="$ParamName" value="$ParamValue">\n);
 917       }
 918     }
 919     $ActiveXTags .= qq(</object>\n);
 920     $ReturnTags = $ActiveXTags;
 921   }
 922   return $ReturnTags;
 923 }
 924 
 925 # Setup ChemDraw ActiveX 8.0 control...
 926 # Problems: "bgcolor" parameter doesn't work.
 927 sub SetupStrViewerChemDrawActiveX {
 928   my($MolFile, $ParamsMapRef, %ParamsMap, $ActiveXTags, $JavaScriptTags, $ReturnTags, $Name, $Width, $Height, $ParamName, $ParamValue);
 929   my($ClassId, $Style, $ViewOnly, $ShrinkToFit, $ShowToolsWhenVisible, $JSFileName, $UseJavaScript);
 930 
 931   $ActiveXTags = "";  $JavaScriptTags = ""; $ReturnTags = "";
 932   $ParamsMapRef = ""; %ParamsMap = ();
 933   $Name = "ChemDraw"; $Width = $StrViewerWidth; $Height = $StrViewerHeight;
 934   $ClassId = "clsid:51A649C4-3E3D-4557-9BD8-B14C0AD44B0C";
 935   $ViewOnly = "1"; $JavaScriptTags = "";
 936   $ShrinkToFit = "1";
 937   $ShowToolsWhenVisible = "1";
 938 
 939   if (@_ == 2) {
 940     ($MolFile, $ParamsMapRef) = @_;
 941   }
 942   else {
 943     ($MolFile) = @_;
 944   }
 945 
 946   if ($ParamsMapRef) {
 947     %ParamsMap = %$ParamsMapRef;
 948     if (exists $ParamsMap{usejavascript} ) { $JSFileName = $ParamsMap{usejavascript}; $UseJavaScript = 1; $ParamsMap{usejavascript} = ""; }
 949     if (exists $ParamsMap{classid} ) { $ClassId = $ParamsMap{classid}; $ParamsMap{classid} = ""; }
 950     if (exists $ParamsMap{name} ) { $Name = $ParamsMap{name}; $ParamsMap{name} = ""; }
 951     if (exists $ParamsMap{height} ) { $Height = $ParamsMap{height}; $ParamsMap{height} = ""; }
 952     if (exists $ParamsMap{width} ) { $Width = $ParamsMap{width}; $ParamsMap{width} = ""; }
 953     if (exists $ParamsMap{ViewOnly} ) { $ViewOnly = $ParamsMap{ViewOnly}; $ParamsMap{ViewOnly} = ""; }
 954     if (exists $ParamsMap{ShrinkToFit} ) { $ShrinkToFit = $ParamsMap{ShrinkToFit}; $ParamsMap{ShrinkToFit} = ""; }
 955     if (exists $ParamsMap{ShowToolsWhenVisible} ) { $ShowToolsWhenVisible = $ParamsMap{ShowToolsWhenVisible}; $ParamsMap{ShowToolsWhenVisible} = ""; }
 956   }
 957   if ($UseJavaScript) {
 958     #Setup parameter...
 959     my($Params) = "";
 960     for $ParamName (sort keys %ParamsMap) {
 961       $ParamValue = $ParamsMap{$ParamName};
 962       if (length $ParamValue) {
 963 	$Params .= qq( $ParamName='$ParamValue');
 964       }
 965     }
 966     $JavaScriptTags = qq(\n<script>\n);
 967     $JavaScriptTags .= qq(cd_insertObjectStr("name='$Name' src='$MolFile' width='$Width' height='$Height' shrinktofit='$ShrinkToFit' viewonly='$ViewOnly' $Params");\n);
 968     $JavaScriptTags .= qq(</script>\n);
 969     $ReturnTags = $JavaScriptTags;
 970   }
 971   else {
 972     $Style = qq(style="height: ) . $Height . qq(px; width: ) . $Width . qq(px");
 973 
 974     # Setup object header...
 975     $ActiveXTags = qq(\n<object id="$Name" classid="$ClassId" $Style>\n);
 976 
 977     # Setup molecule data...
 978     $ActiveXTags .= qq(<param name="SourceURL" value="$MolFile">\n<param name="ShrinkToFit" value="$ShrinkToFit">\n<param name="ViewOnly" value="$ViewOnly">\n<param name="ShowToolsWhenVisible" value="$ShowToolsWhenVisible">\n);
 979 
 980     #Setup other parameters...
 981     for $ParamName (sort keys %ParamsMap) {
 982       $ParamValue = $ParamsMap{$ParamName};
 983       if (length $ParamValue) {
 984 	$ActiveXTags .= qq(<param name="$ParamName" value="$ParamValue">\n);
 985       }
 986     }
 987     $ActiveXTags .= qq(</object>\n);
 988     $ReturnTags = $ActiveXTags;
 989   }
 990   return $ReturnTags;
 991 }
 992 
 993 # Setup ChemDraw plug-in used for Netscape browsers...
 994 # Problems: "bgcolor" parameter doesn't work.
 995 sub SetupStrViewerChemDrawPlugIn {
 996   my($MolFile, $Name, $ParamsMapRef, %ParamsMap, $Width, $Height, $ParamName, $ParamValue, $PlugInTags, $JavaScriptTags, $ReturnTags,);
 997   my($MimeType, $ViewOnly, $ShrinkToFit, $ShowToolsWhenVisible, $JSFileName, $UseJavaScript);
 998 
 999   $Name = "ChemDraw"; $PlugInTags = ""; $ParamsMapRef = ""; %ParamsMap = ();
1000   $Width = $StrViewerWidth; $Height = $StrViewerHeight;
1001   $MimeType = "chemical/x-mdl-molfile";
1002   $ViewOnly = "1";
1003   $ShrinkToFit = "1";
1004   $ShowToolsWhenVisible = "1"; $JavaScriptTags = "";
1005 
1006   if (@_ == 2) {
1007     ($MolFile, $ParamsMapRef) = @_;
1008   }
1009   else