+/* Jmol 12.0 script library Jmol.js 9:48 PM 1/31/2011 Bob Hanson\r
+\r
+ checkbox heirarchy -- see http://chemapps.stolaf.edu/jmol/docs/examples-11/check.htm\r
+\r
+ based on:\r
+ *\r
+ * Copyright (C) 2004-2005 Miguel, Jmol Development, www.jmol.org\r
+ *\r
+ * Contact: hansonr@stolaf.edu\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Lesser General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
+ * 02111-1307 USA.\r
+ */\r
+\r
+// for documentation see www.jmol.org/jslibrary\r
+\r
+try{if(typeof(_jmol)!="undefined")exit()\r
+\r
+// place "?NOAPPLET" on your command line to check applet control action with a textarea\r
+// place "?JMOLJAR=xxxxx" to use a specific jar file\r
+\r
+// bob hanson -- jmolResize(w,h) -- resizes absolutely or by percent (w or h 0.5 means 50%)\r
+// angel herraez -- update of jmolResize(w,h,targetSuffix) so it is not tied to first applet\r
+// bob hanson -- jmolEvaluate -- evaluates molecular math 8:37 AM 2/23/2007\r
+// bob hanson -- jmolScriptMessage -- returns all "scriptStatus" messages 8:37 AM 2/23/2007\r
+// bob hanson -- jmolScriptEcho -- returns all "scriptEcho" messages 8:37 AM 2/23/2007\r
+// bob hanson -- jmolScriptWait -- 11:31 AM 5/2/2006\r
+// bob hanson -- remove trailing separatorHTML in radio groups -- 12:18 PM 5/6/2006\r
+// bob hanson -- adds support for dynamic DOM script nodes 7:04 AM 5/19/2006\r
+// bob hanson -- adds try/catch for wiki - multiple code passes 7:05 AM 5/19/2006\r
+// bob hanson -- auto-initiates to defaultdir/defaultjar -- change as desired.\r
+// bob hanson -- adding save/restore orientation w/ and w/o delay 11:49 AM 5/25/2006\r
+// bob hanson -- adding AjaxJS service 11:16 AM 6/3/2006\r
+// bob hanson -- fix for iframes not available for finding applet\r
+// bob hanson -- added applet fake ?NOAPPLET URL flag\r
+// bob hanson -- added jmolSetCallback(calbackName, funcName) 3:32 PM 6/13/2006\r
+// used PRIOR to jmolApplet() or jmolAppletInline()\r
+// added 4th array element in jmolRadioGroup -- title\r
+// added <span> and id around link, checkbox, radio, menu\r
+// fixing AJAX loads for MSIE/Opera-Mozilla incompatibility\r
+// -- renamed Jmol-11.js from Jmol-new.js; JmolApplet.jar from JmolAppletProto.jar\r
+// renamed Jmol.js for Jmol 11 distribution\r
+// -- modified jmolRestoreOrientation() to be immediate, no 1-second delay\r
+// bob hanson -- jmolScriptWait always returns a string -- 11:23 AM 9/16/2006\r
+// bh -- jmolCommandInput()\r
+// bh -- jmolSetTranslation(TF) -- forces translation even if there might be message callback issues\r
+// bh -- minor fixes suggested by Angel\r
+// bh -- adds jmolSetSyncId() and jmolGetSyncId()\r
+// bh 3/2008 -- adds jmolAppendInlineScript() and jmolAppendInlineArray()\r
+// bh 3/2008 -- fixes IE7 bug in relation to jmolLoadInlineArray()\r
+// bh 6/2008 -- adds jmolSetAppletWindow()\r
+// Angel H. 6/2008 -- added html <label> tags to checkboxes and radio buttons [in jmolCheckbox() and _jmolRadio() functions]\r
+// bh 7/2008 -- code fix "for(i..." not "for(var i..."\r
+// bh 12/2008 -- jmolLoadInline, jmolLoadInlineArray, jmolLoadInlineScript, jmolAppendInlineScript, jmolAppendInlineArray all return error message or null (Jmol 11.7.16)\r
+// bh 12/2008 -- jmolScriptWaitOutput() -- waits for script to complete and delivers output normally sent to console\r
+\r
+// bh 5/2009 -- Support for XHTML using jmolSetXHTML(id)\r
+// ah & bh 6/2009 -- New jmolResizeApplet() more flexible, similar to jmolApplet() size syntax\r
+// bh 11/2009 -- care in accessing top.document\r
+// bh 12/2009 -- added jmolSetParameter(name, value)\r
+// bh 12/2009 -- added PARAMS=name:value;name:value;name:value... for command line\r
+// bh 12/2009 -- overhaul of target checking\r
+// bh 1/2010 -- all _xxxx() methods ALWAYS have complete argument list\r
+// bh 1/2010 -- adds option to run a JavaScript function from any Jmol control. \r
+// This is accomplished by passing an array rather than a script:\r
+// jmolHref([myfunc,"my param 1", "my param 2"], "testing")\r
+// function myfunc(jmolControlObject, [myfunc,"my param 1", "my param 2"], target){...}\r
+// and allows much more flexibility with responding to controls\r
+// bh 4/2010 -- added jmolSetMemoryMb(nMb)\r
+// ah 1/2011 -- wider detection of browsers; more browsers now use the object tag instead of the applet tag; \r
+// fix of object tag (removed classid) accounts for change of behavior in Chrome\r
+// bh 3/2011 -- added jmolLoadAjax_STOLAF_NIH\r
+\r
+var defaultdir = "."\r
+var defaultjar = "JmolApplet.jar"\r
+\r
+\r
+// Note added 12:41 PM 9/21/2008 by Bob Hanson, hansonr@stolaf.edu:\r
+\r
+// JMOLJAR=xxxxx.jar on the URL for this page will override\r
+// the JAR file specified in the jmolInitialize() call.\r
+\r
+// The idea is that it can be very useful to test a web page with different JAR files\r
+// Or for an expert user to substitute a signed applet for an unsigned one\r
+// so as to use a broader range of models or to create JPEG files, for example.\r
+\r
+// If the JAR file is not in the current directory (has any sort of "/" in its name)\r
+// then the user is presented with a warning and asked whether it is OK to change Jar files.\r
+// The default action, if the user just presses "OK" is to NOT allow the change. \r
+// The user must type the word "yes" in the prompt box for the change to be approved.\r
+\r
+// If you don't want people to be able to switch in their own JAR file on your page,\r
+// simply set this next line to read "var allowJMOLJAR = false".\r
+\r
+\r
+var undefined; // for IE 5 ... wherein undefined is undefined\r
+\r
+////////////////////////////////////////////////////////////////\r
+// Basic Scripting infrastruture\r
+////////////////////////////////////////////////////////////////\r
+\r
+function jmolInitialize(codebaseDirectory, fileNameOrUseSignedApplet) {\r
+ if (_jmol.initialized)\r
+ return;\r
+ _jmol.initialized = true;\r
+ if(_jmol.jmoljar) {\r
+ var f = _jmol.jmoljar;\r
+ if (f.indexOf("/") >= 0) {\r
+ alert ("This web page URL is requesting that the applet used be " + f + ". This is a possible security risk, particularly if the applet is signed, because signed applets can read and write files on your local machine or network.")\r
+ var ok = prompt("Do you want to use applet " + f + "? ","yes or no")\r
+ if (ok == "yes") {\r
+ codebaseDirectory = f.substring(0, f.lastIndexOf("/"));\r
+ fileNameOrUseSignedApplet = f.substring(f.lastIndexOf("/") + 1);\r
+ } else {\r
+ _jmolGetJarFilename(fileNameOrUseSignedApplet);\r
+ alert("The web page URL was ignored. Continuing using " + _jmol.archivePath + ' in directory "' + codebaseDirectory + '"');\r
+ }\r
+ } else {\r
+ fileNameOrUseSignedApplet = f;\r
+ }\r
+ }\r
+ _jmolSetCodebase(codebaseDirectory);\r
+ _jmolGetJarFilename(fileNameOrUseSignedApplet);\r
+ _jmolOnloadResetForms();\r
+}\r
+\r
+function jmolSetTranslation(TF) {\r
+ _jmol.params.doTranslate = ''+TF;\r
+}\r
+\r
+function _jmolGetJarFilename(fileNameOrFlag) {\r
+ _jmol.archivePath =\r
+ (typeof(fileNameOrFlag) == "string" ? fileNameOrFlag : (fileNameOrFlag ? "JmolAppletSigned" : "JmolApplet") + "0.jar");\r
+}\r
+\r
+function jmolSetDocument(doc) {\r
+ _jmol.currentDocument = doc;\r
+}\r
+\r
+function jmolSetAppletColor(boxbgcolor, boxfgcolor, progresscolor) {\r
+ _jmolInitCheck();\r
+ _jmol.params.boxbgcolor = boxbgcolor;\r
+ if (boxfgcolor)\r
+ _jmol.params.boxfgcolor = boxfgcolor\r
+ else if (boxbgcolor == "white" || boxbgcolor == "#FFFFFF")\r
+ _jmol.params.boxfgcolor = "black";\r
+ else\r
+ _jmol.params.boxfgcolor = "white";\r
+ if (progresscolor)\r
+ _jmol.params.progresscolor = progresscolor;\r
+ if (_jmol.debugAlert)\r
+ alert(" boxbgcolor=" + _jmol.params.boxbgcolor +\r
+ " boxfgcolor=" + _jmol.params.boxfgcolor +\r
+ " progresscolor=" + _jmol.params.progresscolor);\r
+}\r
+\r
+function jmolSetAppletWindow(w) {\r
+ _jmol.appletWindow = w;\r
+}\r
+\r
+function jmolApplet(size, script, nameSuffix) {\r
+ _jmolInitCheck();\r
+ return _jmolApplet(size, null, script, nameSuffix);\r
+}\r
+\r
+////////////////////////////////////////////////////////////////\r
+// Basic controls\r
+////////////////////////////////////////////////////////////////\r
+\r
+// undefined means it wasn't there; null means it was explicitly listed as null (so as to skip it)\r
+\r
+function jmolButton(script, label, id, title) {\r
+ _jmolInitCheck();\r
+ id != undefined && id != null || (id = "jmolButton" + _jmol.buttonCount);\r
+ label != undefined && label != null || (label = script.substring(0, 32));\r
+ ++_jmol.buttonCount;\r
+ var scriptIndex = _jmolAddScript(script);\r
+ var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='button' name='" + id + "' id='" + id +\r
+ "' value='" + label +\r
+ "' onclick='_jmolClick(this," + scriptIndex + _jmol.targetText +\r
+ ")' onmouseover='_jmolMouseOver(" + scriptIndex +\r
+ ");return true' onmouseout='_jmolMouseOut()' " +\r
+ _jmol.buttonCssText + " /></span>";\r
+ if (_jmol.debugAlert)\r
+ alert(t);\r
+ return _jmolDocumentWrite(t);\r
+}\r
+\r
+function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked,\r
+ labelHtml, isChecked, id, title) {\r
+ _jmolInitCheck();\r
+ id != undefined && id != null || (id = "jmolCheckbox" + _jmol.checkboxCount);\r
+ ++_jmol.checkboxCount;\r
+ if (scriptWhenChecked == undefined || scriptWhenChecked == null ||\r
+ scriptWhenUnchecked == undefined || scriptWhenUnchecked == null) {\r
+ alert("jmolCheckbox requires two scripts");\r
+ return;\r
+ }\r
+ if (labelHtml == undefined || labelHtml == null) {\r
+ alert("jmolCheckbox requires a label");\r
+ return;\r
+ }\r
+ var indexChecked = _jmolAddScript(scriptWhenChecked);\r
+ var indexUnchecked = _jmolAddScript(scriptWhenUnchecked);\r
+ var eospan = "</span>"\r
+ var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='checkbox' name='" + id + "' id='" + id +\r
+ "' onclick='_jmolCbClick(this," +\r
+ indexChecked + "," + indexUnchecked + _jmol.targetText +\r
+ ")' onmouseover='_jmolCbOver(this," + indexChecked + "," +\r
+ indexUnchecked +\r
+ ");return true' onmouseout='_jmolMouseOut()' " +\r
+ (isChecked ? "checked='true' " : "")+ _jmol.checkboxCssText + " />" \r
+ if (labelHtml.toLowerCase().indexOf("<td>")>=0) {\r
+ t += eospan\r
+ eospan = "";\r
+ }\r
+ t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan;\r
+ if (_jmol.debugAlert)\r
+ alert(t);\r
+ return _jmolDocumentWrite(t);\r
+}\r
+\r
+function jmolStartNewRadioGroup() {\r
+ ++_jmol.radioGroupCount;\r
+}\r
+\r
+function jmolRadioGroup(arrayOfRadioButtons, separatorHtml, groupName, id, title) {\r
+ /*\r
+\r
+ array: [radio1,radio2,radio3...]\r
+ where radioN = ["script","label",isSelected,"id","title"]\r
+\r
+ */\r
+\r
+ _jmolInitCheck();\r
+ var type = typeof arrayOfRadioButtons;\r
+ if (type != "object" || type == null || ! arrayOfRadioButtons.length) {\r
+ alert("invalid arrayOfRadioButtons");\r
+ return;\r
+ }\r
+ separatorHtml != undefined && separatorHtml != null || (separatorHtml = " ");\r
+ var len = arrayOfRadioButtons.length;\r
+ jmolStartNewRadioGroup();\r
+ groupName || (groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1));\r
+ var t = "<span id='"+(id ? id : groupName)+"'>";\r
+ for (var i = 0; i < len; ++i) {\r
+ if (i == len - 1)\r
+ separatorHtml = "";\r
+ var radio = arrayOfRadioButtons[i];\r
+ type = typeof radio;\r
+ if (type == "object") {\r
+ t += _jmolRadio(radio[0], radio[1], radio[2], separatorHtml, groupName, (radio.length > 3 ? radio[3]: (id ? id : groupName)+"_"+i), (radio.length > 4 ? radio[4] : 0), title);\r
+ } else {\r
+ t += _jmolRadio(radio, null, null, separatorHtml, groupName, (id ? id : groupName)+"_"+i, title);\r
+ }\r
+ }\r
+ t+="</span>"\r
+ if (_jmol.debugAlert)\r
+ alert(t);\r
+ return _jmolDocumentWrite(t);\r
+}\r
+\r
+\r
+function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {\r
+ _jmolInitCheck();\r
+ if (_jmol.radioGroupCount == 0)\r
+ ++_jmol.radioGroupCount;\r
+ var t = _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, (id ? id : groupName + "_" + _jmol.radioCount), title ? title : 0);\r
+ if (_jmol.debugAlert)\r
+ alert(t);\r
+ return _jmolDocumentWrite(t);\r
+}\r
+\r
+function jmolLink(script, label, id, title) {\r
+ _jmolInitCheck();\r
+ id != undefined && id != null || (id = "jmolLink" + _jmol.linkCount);\r
+ label != undefined && label != null || (label = script.substring(0, 32));\r
+ ++_jmol.linkCount;\r
+ var scriptIndex = _jmolAddScript(script);\r
+ var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><a name='" + id + "' id='" + id + \r
+ "' href='javascript:_jmolClick(this," + scriptIndex + _jmol.targetText + ");' onmouseover='_jmolMouseOver(" + scriptIndex +\r
+ ");return true;' onmouseout='_jmolMouseOut()' " +\r
+ _jmol.linkCssText + ">" + label + "</a></span>";\r
+ if (_jmol.debugAlert)\r
+ alert(t);\r
+ return _jmolDocumentWrite(t);\r
+}\r
+\r
+function jmolCommandInput(label, size, id, title) {\r
+ _jmolInitCheck();\r
+ id != undefined && id != null || (id = "jmolCmd" + _jmol.cmdCount);\r
+ label != undefined && label != null || (label = "Execute");\r
+ size != undefined && !isNaN(size) || (size = 60);\r
+ ++_jmol.cmdCount;\r
+ var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='" + id + "' id='" + id + \r
+ "' size='"+size+"' onkeypress='_jmolCommandKeyPress(event,\""+id+"\"" + _jmol.targetText + ")'><input type=button value = '"+label+"' onclick='jmolScript(document.getElementById(\""+id+"\").value" + _jmol.targetText + ")' /></span>";\r
+ if (_jmol.debugAlert)\r
+ alert(t);\r
+ return _jmolDocumentWrite(t);\r
+}\r
+\r
+function _jmolCommandKeyPress(e, id, target) {\r
+ var keycode = (window.event ? window.event.keyCode : e ? e.which : 0);\r
+ if (keycode == 13) {\r
+ var inputBox = document.getElementById(id)\r
+ _jmolScriptExecute(inputBox, inputBox.value, target)\r
+ }\r
+}\r
+\r
+function _jmolScriptExecute(element,script,target) {\r
+ if (typeof(script) == "object")\r
+ script[0](element, script, target)\r
+ else\r
+ jmolScript(script, target) \r
+}\r
+\r
+function jmolMenu(arrayOfMenuItems, size, id, title) {\r
+ _jmolInitCheck();\r
+ id != undefined && id != null || (id = "jmolMenu" + _jmol.menuCount);\r
+ ++_jmol.menuCount;\r
+ var type = typeof arrayOfMenuItems;\r
+ if (type != null && type == "object" && arrayOfMenuItems.length) {\r
+ var len = arrayOfMenuItems.length;\r
+ if (typeof size != "number" || size == 1)\r
+ size = null;\r
+ else if (size < 0)\r
+ size = len;\r
+ var sizeText = size ? " size='" + size + "' " : "";\r
+ var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><select name='" + id + "' id='" + id +\r
+ "' onChange='_jmolMenuSelected(this" + _jmol.targetText + ")'" +\r
+ sizeText + _jmol.menuCssText + ">";\r
+ for (var i = 0; i < len; ++i) {\r
+ var menuItem = arrayOfMenuItems[i];\r
+ type = typeof menuItem;\r
+ var script, text;\r
+ var isSelected = undefined;\r
+ if (type == "object" && menuItem != null) {\r
+ script = menuItem[0];\r
+ text = menuItem[1];\r
+ isSelected = menuItem[2];\r
+ } else {\r
+ script = text = menuItem;\r
+ }\r
+ text != undefined && text != null || (text = script); \r
+ if (script=="#optgroup") {\r
+ t += "<optgroup label='" + text + "'>"; \r
+ } else if (script=="#optgroupEnd") {\r
+ t += "</optgroup>"; \r
+ } else { \r
+ var scriptIndex = _jmolAddScript(script);\r
+ var selectedText = isSelected ? "' selected='true'>" : "'>";\r
+ t += "<option value='" + scriptIndex + selectedText + text + "</option>";\r
+ }\r
+ }\r
+ t += "</select></span>";\r
+ if (_jmol.debugAlert)\r
+ alert(t);\r
+ return _jmolDocumentWrite(t);\r
+ }\r
+}\r
+\r
+function jmolHtml(html) {\r
+ return _jmolDocumentWrite(html);\r
+}\r
+\r
+function jmolBr() {\r
+ return _jmolDocumentWrite("<br />");\r
+}\r
+\r
+////////////////////////////////////////////////////////////////\r
+// advanced scripting functions\r
+////////////////////////////////////////////////////////////////\r
+\r
+function jmolDebugAlert(enableAlerts) {\r
+ _jmol.debugAlert = (enableAlerts == undefined || enableAlerts)\r
+}\r
+\r
+function jmolAppletInline(size, inlineModel, script, nameSuffix) {\r
+ _jmolInitCheck();\r
+ return _jmolApplet(size, _jmolSterilizeInline(inlineModel),\r
+ script, nameSuffix);\r
+}\r
+\r
+function jmolSetTarget(targetSuffix) {\r
+ _jmol.targetSuffix = targetSuffix;\r
+ _jmol.targetText = targetSuffix ? ",\"" + targetSuffix + "\"" : ",0";\r
+}\r
+\r
+function jmolScript(script, targetSuffix) {\r
+ if (script) {\r
+ _jmolCheckBrowser();\r
+ if (targetSuffix == "all") {\r
+ with (_jmol) {\r
+ for (var i = 0; i < appletSuffixes.length; ++i) {\r
+ var applet = _jmolGetApplet(appletSuffixes[i]);\r
+ if (applet) applet.script(script);\r
+ }\r
+ }\r
+ } else {\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (applet) applet.script(script);\r
+ }\r
+ }\r
+}\r
+\r
+function jmolLoadInline(model, targetSuffix) {\r
+ if (!model)return "ERROR: NO MODEL"\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (!applet)return "ERROR: NO APPLET"\r
+ if (typeof(model) == "string")\r
+ return applet.loadInlineString(model, "", false);\r
+ else\r
+ return applet.loadInlineArray(model, "", false);\r
+}\r
+\r
+\r
+function jmolLoadInlineScript(model, script, targetSuffix) {\r
+ if (!model)return "ERROR: NO MODEL"\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (!applet)return "ERROR: NO APPLET"\r
+ return applet.loadInlineString(model, script, false);\r
+}\r
+\r
+\r
+function jmolLoadInlineArray(ModelArray, script, targetSuffix) {\r
+ if (!model)return "ERROR: NO MODEL"\r
+ script || (script="")\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (!applet)return "ERROR: NO APPLET"\r
+ try {\r
+ return applet.loadInlineArray(ModelArray, script, false);\r
+ } catch (err) {\r
+ //IE 7 bug\r
+ return applet.loadInlineString(ModelArray.join("\n"), script, false);\r
+ }\r
+}\r
+\r
+function jmolAppendInlineArray(ModelArray, script, targetSuffix) {\r
+ if (!model)return "ERROR: NO MODEL"\r
+ script || (script="")\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (!applet)return "ERROR: NO APPLET"\r
+ try {\r
+ return applet.loadInlineArray(ModelArray, script, true);\r
+ } catch (err) {\r
+ //IE 7 bug\r
+ return applet.loadInlineString(ModelArray.join("\n"), script, true);\r
+ }\r
+}\r
+\r
+function jmolAppendInlineScript(model, script, targetSuffix) {\r
+ if (!model)return "ERROR: NO MODEL"\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (!applet)return "ERROR: NO APPLET"\r
+ return applet.loadInlineString(model, script, true);\r
+}\r
+\r
+function jmolCheckBrowser(action, urlOrMessage, nowOrLater) {\r
+ if (typeof action == "string") {\r
+ action = action.toLowerCase();\r
+ action == "alert" || action == "redirect" || action == "popup" || (action = null);\r
+ }\r
+ if (typeof action != "string")\r
+ alert("jmolCheckBrowser(action, urlOrMessage, nowOrLater)\n\n" +\r
+ "action must be 'alert', 'redirect', or 'popup'");\r
+ else {\r
+ if (typeof urlOrMessage != "string")\r
+ alert("jmolCheckBrowser(action, urlOrMessage, nowOrLater)\n\n" +\r
+ "urlOrMessage must be a string");\r
+ else {\r
+ _jmol.checkBrowserAction = action;\r
+ _jmol.checkBrowserUrlOrMessage = urlOrMessage;\r
+ }\r
+ }\r
+ if (typeof nowOrLater == "string" && nowOrLater.toLowerCase() == "now")\r
+ _jmolCheckBrowser();\r
+}\r
+\r
+////////////////////////////////////////////////////////////////\r
+// Cascading Style Sheet Class support\r
+////////////////////////////////////////////////////////////////\r
+\r
+function jmolSetAppletCssClass(appletCssClass) {\r
+ if (_jmol.hasGetElementById) {\r
+ _jmol.appletCssClass = appletCssClass;\r
+ _jmol.appletCssText = appletCssClass ? "class='" + appletCssClass + "' " : "";\r
+ }\r
+}\r
+\r
+function jmolSetButtonCssClass(buttonCssClass) {\r
+ if (_jmol.hasGetElementById) {\r
+ _jmol.buttonCssClass = buttonCssClass;\r
+ _jmol.buttonCssText = buttonCssClass ? "class='" + buttonCssClass + "' " : "";\r
+ }\r
+}\r
+\r
+function jmolSetCheckboxCssClass(checkboxCssClass) {\r
+ if (_jmol.hasGetElementById) {\r
+ _jmol.checkboxCssClass = checkboxCssClass;\r
+ _jmol.checkboxCssText = checkboxCssClass ? "class='" + checkboxCssClass + "' " : "";\r
+ }\r
+}\r
+\r
+function jmolSetRadioCssClass(radioCssClass) {\r
+ if (_jmol.hasGetElementById) {\r
+ _jmol.radioCssClass = radioCssClass;\r
+ _jmol.radioCssText = radioCssClass ? "class='" + radioCssClass + "' " : "";\r
+ }\r
+}\r
+\r
+function jmolSetLinkCssClass(linkCssClass) {\r
+ if (_jmol.hasGetElementById) {\r
+ _jmol.linkCssClass = linkCssClass;\r
+ _jmol.linkCssText = linkCssClass ? "class='" + linkCssClass + "' " : "";\r
+ }\r
+}\r
+\r
+function jmolSetMenuCssClass(menuCssClass) {\r
+ if (_jmol.hasGetElementById) {\r
+ _jmol.menuCssClass = menuCssClass;\r
+ _jmol.menuCssText = menuCssClass ? "class='" + menuCssClass + "' " : "";\r
+ }\r
+}\r
+\r
+////////////////////////////////////////////////////////////////\r
+// functions for INTERNAL USE ONLY which are subject to change\r
+// use at your own risk ... you have been WARNED!\r
+////////////////////////////////////////////////////////////////\r
+var _jmol = {\r
+ currentDocument: document,\r
+\r
+ debugAlert: false,\r
+ \r
+ codebase: "",\r
+ modelbase: ".",\r
+ \r
+ appletCount: 0,\r
+ appletSuffixes: [],\r
+ appletWindow: null,\r
+ allowedJmolSize: [25, 2048, 300], // min, max, default (pixels)\r
+ /* By setting the _jmol.allowedJmolSize[] variable in the webpage \r
+ before calling jmolApplet(), limits for applet size can be overriden.\r
+ 2048 standard for GeoWall (http://geowall.geo.lsa.umich.edu/home.html)\r
+ */ \r
+ buttonCount: 0,\r
+ checkboxCount: 0,\r
+ linkCount: 0,\r
+ cmdCount: 0,\r
+ menuCount: 0,\r
+ radioCount: 0,\r
+ radioGroupCount: 0,\r
+ \r
+ appletCssClass: null,\r
+ appletCssText: "",\r
+ buttonCssClass: null,\r
+ buttonCssText: "",\r
+ checkboxCssClass: null,\r
+ checkboxCssText: "",\r
+ java_arguments: "-Xmx512m",\r
+ radioCssClass: null,\r
+ radioCssText: "",\r
+ linkCssClass: null,\r
+ linkCssText: "",\r
+ menuCssClass: null,\r
+ menuCssText: "",\r
+ \r
+ targetSuffix: 0,\r
+ targetText: ",0",\r
+ scripts: [""],\r
+ params: {\r
+ syncId: ("" + Math.random()).substring(3),\r
+ progressbar: "true",\r
+ progresscolor: "blue",\r
+ boxbgcolor: "black",\r
+ boxfgcolor: "white",\r
+ boxmessage: "Downloading JmolApplet ..."\r
+ },\r
+ ua: navigator.userAgent.toLowerCase(),\r
+ // uaVersion: parseFloat(navigator.appVersion), // not used\r
+ \r
+ os: "unknown",\r
+ browser: "unknown",\r
+ browserVersion: 0,\r
+ hasGetElementById: !!document.getElementById,\r
+ isJavaEnabled: navigator.javaEnabled(),\r
+ // isNetscape47Win: false, // not used, N4.7 is no longer supported even for detection\r
+ useIEObject: false,\r
+ useHtml4Object: false,\r
+ \r
+ windowsClassId: "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93",\r
+ windowsCabUrl:\r
+ "http://java.sun.com/update/1.6.0/jinstall-6u22-windows-i586.cab",\r
+\r
+ isBrowserCompliant: false,\r
+ isJavaCompliant: false,\r
+ isFullyCompliant: false,\r
+\r
+ initialized: false,\r
+ initChecked: false,\r
+ \r
+ browserChecked: false,\r
+ checkBrowserAction: "alert",\r
+ checkBrowserUrlOrMessage: null,\r
+\r
+ archivePath: null, // JmolApplet0.jar OR JmolAppletSigned0.jar\r
+\r
+ previousOnloadHandler: null,\r
+\r
+ jmoljar: null, \r
+ useNoApplet: false,\r
+\r
+ ready: {}\r
+}\r
+\r
+with (_jmol) {\r
+ function _jmolTestUA(candidate) {\r
+ var ua = _jmol.ua;\r
+ var index = ua.indexOf(candidate);\r
+ if (index < 0)\r
+ return false;\r
+ _jmol.browser = candidate;\r
+ _jmol.browserVersion = parseFloat(ua.substring(index+candidate.length+1));\r
+ return true;\r
+ }\r
+ \r
+ function _jmolTestOS(candidate) {\r
+ if (_jmol.ua.indexOf(candidate) < 0)\r
+ return false;\r
+ _jmol.os = candidate;\r
+ return true;\r
+ }\r
+ \r
+ _jmolTestUA("konqueror") ||\r
+ _jmolTestUA("webkit") ||\r
+ _jmolTestUA("omniweb") ||\r
+ _jmolTestUA("opera") ||\r
+ _jmolTestUA("webtv") ||\r
+ _jmolTestUA("icab") ||\r
+ _jmolTestUA("msie") ||\r
+ (_jmol.ua.indexOf("compatible") < 0 && _jmolTestUA("mozilla")); //Netscape, Mozilla, Seamonkey, Firefox and anything assimilated\r
+ \r
+ _jmolTestOS("linux") ||\r
+ _jmolTestOS("unix") ||\r
+ _jmolTestOS("mac") ||\r
+ _jmolTestOS("win");\r
+\r
+ /* not used:\r
+ isNetscape47Win = (os == "win" && browser == "mozilla" &&\r
+ browserVersion >= 4.78 && browserVersion <= 4.8);\r
+ */\r
+\r
+ if (os == "win") {\r
+ isBrowserCompliant = hasGetElementById;\r
+ } else if (os == "mac") { // mac is the problem child :-(\r
+ if (browser == "mozilla" && browserVersion >= 5) {\r
+ // miguel 2004 11 17\r
+ // checking the plugins array does not work because\r
+ // Netscape 7.2 OS X still has Java 1.3.1 listed even though\r
+ // javaplugin.sf.net is installed to upgrade to 1.4.2\r
+ eval("try {var v = java.lang.System.getProperty('java.version');" +\r
+ " _jmol.isBrowserCompliant = v >= '1.4.2';" +\r
+ " } catch (e) { }");\r
+ } else if (browser == "opera" && browserVersion <= 7.54) {\r
+ isBrowserCompliant = false;\r
+ } else {\r
+ isBrowserCompliant = hasGetElementById &&\r
+ !((browser == "msie") ||\r
+ (browser == "webkit" && browserVersion < 125.12));\r
+ }\r
+ } else if (os == "linux" || os == "unix") {\r
+ if (browser == "konqueror" && browserVersion <= 3.3)\r
+ isBrowserCompliant = false;\r
+ else\r
+ isBrowserCompliant = hasGetElementById;\r
+ } else { // other OS\r
+ isBrowserCompliant = hasGetElementById;\r
+ }\r
+\r
+ // possibly more checks in the future for this\r
+ isJavaCompliant = isJavaEnabled;\r
+\r
+ isFullyCompliant = isBrowserCompliant && isJavaCompliant;\r
+\r
+ useIEObject = (os == "win" && browser == "msie" && browserVersion >= 5.5);\r
+ useHtml4Object =\r
+ (browser == "mozilla" && browserVersion >= 5) ||\r
+ (browser == "opera" && browserVersion >= 8) ||\r
+ (browser == "webkit" && browserVersion >= 412.2);\r
+ try {\r
+ if (top.location.search.indexOf("JMOLJAR=")>=0)\r
+ jmoljar = top.location.search.split("JMOLJAR=")[1].split("&")[0];\r
+ } catch(e) {\r
+ // can't access top.location\r
+ }\r
+ try {\r
+ useNoApplet = (top.location.search.indexOf("NOAPPLET")>=0);\r
+ } catch(e) {\r
+ // can't access top.document\r
+ }\r
+}\r
+\r
+function jmolSetMemoryMb(nMb) {\r
+ _jmol.java_arguments = "-Xmx" + Math.round(nMb) + "m"\r
+}\r
+\r
+function jmolSetParameter(name,value) {\r
+ _jmol.params[name] = value\r
+}\r
+\r
+function jmolSetCallback(callbackName,funcName) {\r
+ _jmol.params[callbackName] = funcName\r
+}\r
+\r
+ try {\r
+// note this is done FIRST, so it cannot override a setting done by the developer\r
+ if (top.location.search.indexOf("PARAMS=")>=0) {\r
+ var pars = unescape(top.location.search.split("PARAMS=")[1].split("&")[0]).split(";");\r
+ for (var i = 0; i < pars.length; i++) {\r
+ var p = pars[i].split(":");\r
+ jmolSetParameter(p[0],p[1]);\r
+ }\r
+ }\r
+ } catch(e) {\r
+ // can't access top.location\r
+ }\r
+\r
+function jmolSetSyncId(n) {\r
+ return _jmol.params["syncId"] = n\r
+}\r
+\r
+function jmolGetSyncId() {\r
+ return _jmol.params["syncId"]\r
+}\r
+\r
+function jmolSetLogLevel(n) {\r
+ _jmol.params.logLevel = ''+n;\r
+}\r
+\r
+ /* AngelH, mar2007:\r
+ By (re)setting these variables in the webpage before calling jmolApplet(), \r
+ a custom message can be provided (e.g. localized for user's language) when no Java is installed.\r
+ */\r
+if (noJavaMsg==undefined) var noJavaMsg = \r
+ "You do not have Java applets enabled in your web browser, or your browser is blocking this applet.<br />\n" +\r
+ "Check the warning message from your browser and/or enable Java applets in<br />\n" +\r
+ "your web browser preferences, or install the Java Runtime Environment from <a href='http://www.java.com'>www.java.com</a><br />";\r
+if (noJavaMsg2==undefined) var noJavaMsg2 = \r
+ "You do not have the<br />\n" +\r
+ "Java Runtime Environment<br />\n" +\r
+ "installed for applet support.<br />\n" +\r
+ "Visit <a href='http://www.java.com'>www.java.com</a>";\r
+function _jmolApplet(size, inlineModel, script, nameSuffix) {\r
+ /* AngelH, mar2007\r
+ Fixed percent / pixel business, to avoid browser errors:\r
+ put "px" where needed, avoid where not.\r
+\r
+ Bob Hanson, 1/2010\r
+ Fixed inline escape changing returns to | \r
+ */\r
+ with (_jmol) {\r
+ nameSuffix == undefined && (nameSuffix = appletCount);\r
+ appletSuffixes.push(nameSuffix);\r
+ ++appletCount;\r
+ script || (script = "select *");\r
+ var sz = _jmolGetAppletSize(size);\r
+ var widthAndHeight = " width='" + sz[0] + "' height='" + sz[1] + "' ";\r
+ var tHeader, tFooter;\r
+ codebase || jmolInitialize(".");\r
+ if (useIEObject || useHtml4Object) {\r
+ params.archive = archivePath;\r
+ params.mayscript = 'true';\r
+ params.codebase = codebase;\r
+ params.code = 'JmolApplet';\r
+ tHeader = \r
+ "<object name='jmolApplet" + nameSuffix +\r
+ "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +\r
+ widthAndHeight + "\n";\r
+ tFooter = "</object>";\r
+ }\r
+ if (java_arguments)\r
+ params.java_arguments = java_arguments;\r
+ if (useIEObject) { // use MSFT IE6 object tag with .cab file reference\r
+ tHeader += " classid='" + windowsClassId + "'\n" +\r
+ (windowsCabUrl ? " codebase='" + windowsCabUrl + "'\n" : "") + ">\n";\r
+ } else if (useHtml4Object) { // use HTML4 object tag\r
+ tHeader += " type='application/x-java-applet'\n>\n";\r
+ /* " classid='java:JmolApplet'\n" + AH removed this\r
+ Chromium Issue 62076: Java Applets using an <object> with a classid paramater don't load.\r
+ http://code.google.com/p/chromium/issues/detail?id=62076\r
+ They say this is the correct behavior according to the spec, and there's no indication at this point \r
+ that WebKit will be changing the handling, so eventually Safari will acquire this behavior too.\r
+ Removing the classid parameter seems to be well tolerated by all browsers (even IE!).\r
+ */\r
+ } else { // use applet tag\r
+ tHeader = \r
+ "<applet name='jmolApplet" + nameSuffix +\r
+ "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +\r
+ widthAndHeight + "\n" +\r
+ " code='JmolApplet'" +\r
+ " archive='" + archivePath + "' codebase='" + codebase + "'\n" +\r
+ " mayscript='true'>\n";\r
+ tFooter = "</applet>";\r
+ }\r
+ var visitJava;\r
+ if (useIEObject || useHtml4Object) {\r
+ var szX = "width:" + sz[0]\r
+ if ( szX.indexOf("%")==-1 ) szX+="px" \r
+ var szY = "height:" + sz[1]\r
+ if ( szY.indexOf("%")==-1 ) szY+="px" \r
+ visitJava =\r
+ "<p style='background-color:yellow; color:black; " +\r
+ szX + ";" + szY + ";" +\r
+ // why doesn't this vertical-align work?\r
+ "text-align:center;vertical-align:middle;'>\n" +\r
+ noJavaMsg +\r
+ "</p>";\r
+ } else {\r
+ visitJava =\r
+ "<table bgcolor='yellow'><tr>" +\r
+ "<td align='center' valign='middle' " + widthAndHeight + "><font color='black'>\n" +\r
+ noJavaMsg2 +\r
+ "</font></td></tr></table>";\r
+ }\r
+ params.loadInline = (inlineModel ? inlineModel : "");\r
+ params.script = (script ? _jmolSterilizeScript(script) : "");\r
+ var t = tHeader + _jmolParams() + visitJava + tFooter;\r
+ jmolSetTarget(nameSuffix);\r
+ ready["jmolApplet" + nameSuffix] = false;\r
+ if (_jmol.debugAlert)\r
+ alert(t);\r
+ return _jmolDocumentWrite(t);\r
+ }\r
+}\r
+\r
+function _jmolParams() {\r
+ var t = "";\r
+ for (var i in _jmol.params)\r
+ if(_jmol.params[i]!="")\r
+ t+=" <param name='"+i+"' value='"+_jmol.params[i]+"' />\n";\r
+ return t\r
+}\r
+\r
+function _jmolInitCheck() {\r
+ if (_jmol.initChecked)\r
+ return;\r
+ _jmol.initChecked = true;\r
+ jmolInitialize(defaultdir, defaultjar)\r
+}\r
+\r
+function _jmolCheckBrowser() {\r
+ with (_jmol) {\r
+ if (browserChecked)\r
+ return;\r
+ browserChecked = true;\r
+ \r
+ if (isFullyCompliant)\r
+ return true;\r
+\r
+ if (checkBrowserAction == "redirect")\r
+ location.href = checkBrowserUrlOrMessage;\r
+ else if (checkBrowserAction == "popup")\r
+ _jmolPopup(checkBrowserUrlOrMessage);\r
+ else {\r
+ var msg = checkBrowserUrlOrMessage;\r
+ if (msg == null)\r
+ msg = "Your web browser is not fully compatible with Jmol\n\n" +\r
+ "browser: " + browser +\r
+ " version: " + browserVersion +\r
+ " os: " + os +\r
+ " isBrowserCompliant: " + isBrowserCompliant +\r
+ " isJavaCompliant: " + isJavaCompliant +\r
+ "\n\n" + ua;\r
+ alert(msg);\r
+ }\r
+ }\r
+ return false;\r
+}\r
+\r
+function jmolSetXHTML(id) {\r
+ _jmol.isXHTML = true\r
+ _jmol.XhtmlElement = null\r
+ _jmol.XhtmlAppendChild = false\r
+ if (id){\r
+ _jmol.XhtmlElement = document.getElementById(id)\r
+ _jmol.XhtmlAppendChild = true\r
+ }\r
+}\r
+\r
+function _jmolDocumentWrite(text) {\r
+ if (_jmol.currentDocument) {\r
+ if (_jmol.isXHTML && !_jmol.XhtmlElement) {\r
+ var s = document.getElementsByTagName("script")\r
+ _jmol.XhtmlElement = s.item(s.length - 1)\r
+ _jmol.XhtmlAppendChild = false\r
+ }\r
+ if (_jmol.XhtmlElement) {\r
+ _jmolDomDocumentWrite(text)\r
+ } else {\r
+ _jmol.currentDocument.write(text);\r
+ }\r
+ }\r
+ return text;\r
+}\r
+\r
+function _jmolDomDocumentWrite(data) {\r
+ var pt = 0\r
+ var Ptr = []\r
+ Ptr[0] = 0\r
+ while (Ptr[0] < data.length) {\r
+ var child = _jmolGetDomElement(data, Ptr)\r
+ if (!child)break\r
+ if (_jmol.XhtmlAppendChild)\r
+ _jmol.XhtmlElement.appendChild(child)\r
+ else\r
+ _jmol.XhtmlElement.parentNode.insertBefore(child, _jmol.XhtmlElement); \r
+ }\r
+}\r
+function _jmolGetDomElement(data, Ptr, closetag, lvel) {\r
+ var e = document.createElement("span")\r
+ e.innerHTML = data\r
+ Ptr[0] = data.length\r
+ return e\r
+\r
+//unnecessary?\r
+\r
+ closetag || (closetag = "")\r
+ lvel || (lvel = 0)\r
+ var pt0 = Ptr[0]\r
+ var pt = pt0\r
+ while (pt < data.length && data.charAt(pt) != "<") pt++\r
+ if (pt != pt0) {\r
+ var text = data.substring(pt0, pt)\r
+ Ptr[0] = pt\r
+ return document.createTextNode(text)\r
+ } \r
+ pt0 = ++pt\r
+ var ch\r
+ while (pt < data.length && "\n\r\t >".indexOf(ch = data.charAt(pt)) < 0) pt++\r
+ var tagname = data.substring(pt0, pt)\r
+ var e = (tagname == closetag || tagname == "/" ? "" \r
+ : document.createElementNS ? document.createElementNS('http://www.w3.org/1999/xhtml', tagname)\r
+ : document.createElement(tagname));\r
+ if (ch == ">") {\r
+ Ptr[0] = ++pt\r
+ return e\r
+ }\r
+ while (pt < data.length && (ch = data.charAt(pt)) != ">") {\r
+ while (pt < data.length && "\n\r\t ".indexOf(ch = data.charAt(pt)) >= 0) pt++\r
+ pt0 = pt\r
+ while (pt < data.length && "\n\r\t =/>".indexOf(ch = data.charAt(pt)) < 0) pt++\r
+ var attrname = data.substring(pt0, pt).toLowerCase()\r
+ if (attrname && ch != "=") \r
+ e.setAttribute(attrname, "true")\r
+ while (pt < data.length && "\n\r\t ".indexOf(ch = data.charAt(pt)) >= 0) pt++\r
+ if (ch == "/") {\r
+ Ptr[0] = pt + 2\r
+ return e\r
+ } else if (ch == "=") {\r
+ var quote = data.charAt(++pt)\r
+ pt0 = ++pt\r
+ while (pt < data.length && (ch = data.charAt(pt)) != quote) pt++\r
+ var attrvalue = data.substring(pt0, pt)\r
+ e.setAttribute(attrname, attrvalue)\r
+ pt++\r
+ }\r
+ }\r
+ Ptr[0] = ++pt\r
+ while (Ptr[0] < data.length) {\r
+ var child = _jmolGetDomElement(data, Ptr, "/" + tagname, lvel+1)\r
+ if (!child)break\r
+ e.appendChild(child)\r
+ }\r
+ return e\r
+}\r
+\r
+function _jmolPopup(url) {\r
+ var popup = window.open(url, "JmolPopup",\r
+ "left=150,top=150,height=400,width=600," +\r
+ "directories=yes,location=yes,menubar=yes," +\r
+ "toolbar=yes," +\r
+ "resizable=yes,scrollbars=yes,status=yes");\r
+ if (popup.focus)\r
+ poup.focus();\r
+}\r
+\r
+function _jmolReadyCallback(name) {\r
+ if (_jmol.debugAlert)\r
+ alert(name + " is ready");\r
+ _jmol.ready["" + name] = true;\r
+}\r
+\r
+function _jmolSterilizeScript(script) {\r
+ script = script.replace(/'/g, "'");\r
+ if (_jmol.debugAlert)\r
+ alert("script:\n" + script);\r
+ return script;\r
+}\r
+\r
+function _jmolSterilizeInline(model) {\r
+ model = model.replace(/\r|\n|\r\n/g, (model.indexOf("|") >= 0 ? "\\/n" : "|")).replace(/'/g, "'");\r
+ if (_jmol.debugAlert)\r
+ alert("inline model:\n" + model);\r
+ return model;\r
+}\r
+\r
+function _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {\r
+ ++_jmol.radioCount;\r
+ groupName != undefined && groupName != null || (groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1));\r
+ if (!script)\r
+ return "";\r
+ labelHtml != undefined && labelHtml != null || (labelHtml = script.substring(0, 32));\r
+ separatorHtml || (separatorHtml = "")\r
+ var scriptIndex = _jmolAddScript(script);\r
+ var eospan = "</span>"\r
+ var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='" \r
+ + groupName + "' id='"+id+"' type='radio' onclick='_jmolClick(this," +\r
+ scriptIndex + _jmol.targetText + ");return true;' onmouseover='_jmolMouseOver(" +\r
+ scriptIndex + ");return true;' onmouseout='_jmolMouseOut()' " +\r
+ (isChecked ? "checked='true' " : "") + _jmol.radioCssText + " />"\r
+ if (labelHtml.toLowerCase().indexOf("<td>")>=0) {\r
+ t += eospan\r
+ eospan = "";\r
+ }\r
+ t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan + separatorHtml;\r
+\r
+ return t;\r
+}\r
+\r
+function _jmolFindApplet(target) {\r
+ // first look for the target in the current window\r
+ var applet = _jmolFindAppletInWindow(_jmol.appletWindow != null ? _jmol.appletWindow : window, target);\r
+ // THEN look for the target in child frames\r
+ if (applet == undefined)\r
+ applet = _jmolSearchFrames(window, target);\r
+ // FINALLY look for the target in sibling frames\r
+ if (applet == undefined)\r
+ applet = _jmolSearchFrames(top, target); // look starting in top frame\r
+ return applet;\r
+}\r
+\r
+function _jmolGetApplet(targetSuffix){\r
+ var target = "jmolApplet" + (targetSuffix ? targetSuffix : "0");\r
+ var applet = _jmolFindApplet(target);\r
+ if (applet) return applet\r
+ _jmol.alerted || alert("could not find applet " + target);\r
+ _jmol.alerted = true;\r
+ return null\r
+}\r
+\r
+function _jmolSearchFrames(win, target) {\r
+ var applet;\r
+ var frames = win.frames;\r
+ if (frames && frames.length) { // look in all the frames below this window\r
+ try{\r
+ for (var i = 0; i < frames.length; ++i) {\r
+ applet = _jmolSearchFrames(frames[i], target);\r
+ if (applet)\r
+ return applet;\r
+ }\r
+ }catch(e) {\r
+ if (_jmol.debugAlert)\r
+ alert("Jmol.js _jmolSearchFrames cannot access " + win.name + ".frame[" + i + "] consider using jmolSetAppletWindow()") \r
+ }\r
+ }\r
+ return applet = _jmolFindAppletInWindow(win, target)\r
+}\r
+\r
+function _jmolFindAppletInWindow(win, target) {\r
+ var doc = win.document;\r
+ if (doc.getElementById(target))\r
+ return doc.getElementById(target);\r
+ else if (doc.applets)\r
+ return doc.applets[target];\r
+ else\r
+ return doc[target]; \r
+}\r
+\r
+function _jmolAddScript(script) {\r
+ if (!script)\r
+ return 0;\r
+ var index = _jmol.scripts.length;\r
+ _jmol.scripts[index] = script;\r
+ return index;\r
+}\r
+\r
+function _jmolClick(elementClicked, scriptIndex, targetSuffix) {\r
+ _jmol.element = elementClicked;\r
+ _jmolScriptExecute(elementClicked, _jmol.scripts[scriptIndex], targetSuffix);\r
+}\r
+\r
+function _jmolMenuSelected(menuObject, targetSuffix) {\r
+ var scriptIndex = menuObject.value;\r
+ if (scriptIndex != undefined) {\r
+ _jmolScriptExecute(menuObject, _jmol.scripts[scriptIndex], targetSuffix);\r
+ return;\r
+ }\r
+ var len = menuObject.length;\r
+ if (typeof len == "number") {\r
+ for (var i = 0; i < len; ++i) {\r
+ if (menuObject[i].selected) {\r
+ _jmolClick(menuObject[i], menuObject[i].value, targetSuffix);\r
+ return;\r
+ }\r
+ }\r
+ }\r
+ alert("?Que? menu selected bug #8734");\r
+}\r
+\r
+\r
+_jmol.checkboxMasters = {};\r
+_jmol.checkboxItems = {};\r
+\r
+function jmolSetCheckboxGroup(chkMaster,chkBox) {\r
+ var id = chkMaster;\r
+ if(typeof(id)=="number")id = "jmolCheckbox" + id;\r
+ chkMaster = document.getElementById(id);\r
+ if (!chkMaster)alert("jmolSetCheckboxGroup: master checkbox not found: " + id);\r
+ var m = _jmol.checkboxMasters[id] = {};\r
+ m.chkMaster = chkMaster;\r
+ m.chkGroup = {};\r
+ for (var i = 1; i < arguments.length; i++){\r
+ var id = arguments[i];\r
+ if(typeof(id)=="number")id = "jmolCheckbox" + id;\r
+ checkboxItem = document.getElementById(id);\r
+ if (!checkboxItem)alert("jmolSetCheckboxGroup: group checkbox not found: " + id);\r
+ m.chkGroup[id] = checkboxItem;\r
+ _jmol.checkboxItems[id] = m;\r
+ }\r
+}\r
+\r
+function _jmolNotifyMaster(m){\r
+ //called when a group item is checked\r
+ var allOn = true;\r
+ var allOff = true;\r
+ for (var chkBox in m.chkGroup){\r
+ if(m.chkGroup[chkBox].checked)\r
+ allOff = false;\r
+ else\r
+ allOn = false;\r
+ }\r
+ if (allOn)m.chkMaster.checked = true; \r
+ if (allOff)m.chkMaster.checked = false;\r
+ if ((allOn || allOff) && _jmol.checkboxItems[m.chkMaster.id])\r
+ _jmolNotifyMaster(_jmol.checkboxItems[m.chkMaster.id])\r
+}\r
+\r
+function _jmolNotifyGroup(m, isOn){\r
+ //called when a master item is checked\r
+ for (var chkBox in m.chkGroup){\r
+ var item = m.chkGroup[chkBox]\r
+ item.checked = isOn;\r
+ if (_jmol.checkboxMasters[item.id])\r
+ _jmolNotifyGroup(_jmol.checkboxMasters[item.id], isOn)\r
+ }\r
+}\r
+\r
+function _jmolCbClick(ckbox, whenChecked, whenUnchecked, targetSuffix) {\r
+ _jmol.control = ckbox\r
+ _jmolClick(ckbox, ckbox.checked ? whenChecked : whenUnchecked, targetSuffix);\r
+ if(_jmol.checkboxMasters[ckbox.id])\r
+ _jmolNotifyGroup(_jmol.checkboxMasters[ckbox.id], ckbox.checked)\r
+ if(_jmol.checkboxItems[ckbox.id])\r
+ _jmolNotifyMaster(_jmol.checkboxItems[ckbox.id])\r
+}\r
+\r
+function _jmolCbOver(ckbox, whenChecked, whenUnchecked) {\r
+ window.status = _jmol.scripts[ckbox.checked ? whenUnchecked : whenChecked];\r
+}\r
+\r
+function _jmolMouseOver(scriptIndex) {\r
+ window.status = _jmol.scripts[scriptIndex];\r
+}\r
+\r
+function _jmolMouseOut() {\r
+ window.status = " ";\r
+ return true;\r
+}\r
+\r
+function _jmolSetCodebase(codebase) {\r
+ _jmol.codebase = codebase ? codebase : ".";\r
+ if (_jmol.debugAlert)\r
+ alert("jmolCodebase=" + _jmol.codebase);\r
+}\r
+\r
+function _jmolOnloadResetForms() {\r
+ // must be evaluated ONLY once\r
+ _jmol.previousOnloadHandler = window.onload;\r
+ window.onload =\r
+ function() {\r
+ with (_jmol) {\r
+ if (buttonCount+checkboxCount+menuCount+radioCount+radioGroupCount > 0) {\r
+ var forms = document.forms;\r
+ for (var i = forms.length; --i >= 0; )\r
+ forms[i].reset();\r
+ }\r
+ if (previousOnloadHandler)\r
+ previousOnloadHandler();\r
+ }\r
+ }\r
+}\r
+\r
+////////////////////////////////////\r
+/////extensions for getProperty/////\r
+////////////////////////////////////\r
+\r
+\r
+function _jmolEvalJSON(s,key){\r
+ s=s+""\r
+ if(!s)return []\r
+ if(s.charAt(0)!="{"){\r
+ if(s.indexOf(" | ")>=0)s=s.replace(/\ \|\ /g, "\n")\r
+ return s\r
+ }\r
+ var A = eval("("+s+")")\r
+ if(!A)return\r
+ if(key && A[key])A=A[key]\r
+ return A\r
+}\r
+\r
+function _jmolEnumerateObject(A,key){\r
+ var sout=""\r
+ if(typeof(A) == "string" && A!="null"){\r
+ sout+="\n"+key+"=\""+A+"\""\r
+ }else if(!isNaN(A)||A==null){\r
+ sout+="\n"+key+"="+(A+""==""?"null":A)\r
+ }else if(A.length){\r
+ sout+=key+"=[]"\r
+ for(var i=0;i<A.length;i++){\r
+ sout+="\n"\r
+ if(typeof(A[i]) == "object"||typeof(A[i]) == "array"){\r
+ sout+=_jmolEnumerateObject(A[i],key+"["+i+"]")\r
+ }else{\r
+ sout+=key+"["+i+"]="+(typeof(A[i]) == "string" && A[i]!="null"?"\""+A[i].replace(/\"/g,"\\\"")+"\"":A[i])\r
+ }\r
+ }\r
+ }else{\r
+ if(key != ""){\r
+ sout+=key+"={}"\r
+ key+="."\r
+ }\r
+ \r
+ for(var i in A){\r
+ sout+="\n"\r
+ if(typeof(A[i]) == "object"||typeof(A[i]) == "array"){\r
+ sout+=_jmolEnumerateObject(A[i],key+i)\r
+ }else{\r
+ sout+=key+i+"="+(typeof(A[i]) == "string" && A[i]!="null"?"\""+A[i].replace(/\"/g,"\\\"")+"\"":A[i])\r
+ }\r
+ }\r
+ } \r
+ return sout\r
+}\r
+\r
+\r
+function _jmolSortKey0(a,b){\r
+ return (a[0]<b[0]?1:a[0]>b[0]?-1:0)\r
+}\r
+\r
+function _jmolSortMessages(A){\r
+ if(!A || typeof(A)!="object")return []\r
+ var B = []\r
+ for(var i=A.length-1;i>=0;i--)for(var j=0;j<A[i].length;j++)B[B.length]=A[i][j]\r
+ if(B.length == 0) return\r
+ B=B.sort(_jmolSortKey0)\r
+ return B\r
+}\r
+\r
+/////////additional extensions //////////\r
+\r
+\r
+function _jmolDomScriptLoad(URL){\r
+ //open(URL) //to debug\r
+ _jmol.servercall=URL\r
+ var node = document.getElementById("_jmolScriptNode")\r
+ if (node && _jmol.browser!="msie"){\r
+ document.getElementsByTagName("HEAD")[0].removeChild(node)\r
+ node=null\r
+ }\r
+ if (node) {\r
+ node.setAttribute("src",URL)\r
+ } else {\r
+ node=document.createElement("script")\r
+ node.setAttribute("id","_jmolScriptNode")\r
+ node.setAttribute("type","text/javascript")\r
+ node.setAttribute("src",URL)\r
+ document.getElementsByTagName("HEAD")[0].appendChild(node)\r
+ }\r
+}\r
+\r
+\r
+function _jmolExtractPostData(url){\r
+ S=url.split("&POST:")\r
+ var s=""\r
+ for(var i=1;i<S.length;i++){\r
+ KV=S[i].split("=")\r
+ s+="&POSTKEY"+i+"="+KV[0]\r
+ s+="&POSTVALUE"+i+"="+KV[1]\r
+ }\r
+ return "&url="+escape(S[0])+s\r
+}\r
+\r
+function _jmolLoadModel(targetSuffix,remoteURL,array,isError,errorMessage){\r
+ //called by server, but in client\r
+ //overload this function to customize return\r
+ _jmol.remoteURL=remoteURL\r
+ isError && alert(errorMessage)\r
+ jmolLoadInlineScript(array.join("\n"),_jmol.optionalscript,targetSuffix)\r
+}\r
+\r
+//////////user property/status functions/////////\r
+\r
+function jmolGetStatus(strStatus,targetSuffix){\r
+ return _jmolSortMessages(jmolGetPropertyAsArray("jmolStatus",strStatus,targetSuffix))\r
+}\r
+\r
+function jmolGetPropertyAsArray(sKey,sValue,targetSuffix) {\r
+ return _jmolEvalJSON(jmolGetPropertyAsJSON(sKey,sValue,targetSuffix),sKey)\r
+}\r
+\r
+function jmolGetPropertyAsString(sKey,sValue,targetSuffix) {\r
+ var applet = _jmolGetApplet(targetSuffix);\r
+ sValue == undefined && (sValue="");\r
+ return (applet ? applet.getPropertyAsString(sKey,sValue) + "" : "")\r
+}\r
+\r
+function jmolGetPropertyAsJSON(sKey,sValue,targetSuffix) {\r
+ sValue == undefined && (sValue = "")\r
+ var applet = _jmolGetApplet(targetSuffix);\r
+ try {\r
+ return (applet ? applet.getPropertyAsJSON(sKey,sValue) + "" : "")\r
+ } catch(e) {\r
+ return ""\r
+ }\r
+}\r
+\r
+function jmolGetPropertyAsJavaObject(sKey,sValue,targetSuffix) {\r
+ sValue == undefined && (sValue = "")\r
+ var applet = _jmolGetApplet(targetSuffix);\r
+ return (applet ? applet.getProperty(sKey,sValue) : null)\r
+}\r
+\r
+\r
+function jmolDecodeJSON(s) {\r
+ return _jmolEnumerateObject(_jmolEvalJSON(s),"")\r
+}\r
+\r
+\r
+///////// synchronous scripting ////////\r
+\r
+function jmolScriptWait(script, targetSuffix) {\r
+ targetSuffix == undefined && (targetSuffix="0")\r
+ var Ret=jmolScriptWaitAsArray(script, targetSuffix)\r
+ var s = ""\r
+ for(var i=Ret.length;--i>=0;)\r
+ for(var j=0;j< Ret[i].length;j++)\r
+ s+=Ret[i][j]+"\n"\r
+ return s\r
+}\r
+\r
+function jmolScriptWaitOutput(script, targetSuffix) {\r
+ targetSuffix == undefined && (targetSuffix="0")\r
+ var ret = ""\r
+ try{\r
+ if (script) {\r
+ _jmolCheckBrowser();\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (applet) ret += applet.scriptWaitOutput(script);\r
+ }\r
+ }catch(e){\r
+ }\r
+ return ret;\r
+}\r
+\r
+function jmolEvaluate(molecularMath, targetSuffix) {\r
+\r
+ //carries out molecular math on a model\r
+\r
+ targetSuffix == undefined && (targetSuffix="0")\r
+ var result = "" + jmolGetPropertyAsJavaObject("evaluate", molecularMath, targetSuffix);\r
+ var s = result.replace(/\-*\d+/,"")\r
+ if (s == "" && !isNaN(parseInt(result)))return parseInt(result);\r
+ var s = result.replace(/\-*\d*\.\d*/,"")\r
+ if (s == "" && !isNaN(parseFloat(result)))return parseFloat(result);\r
+ return result;\r
+}\r
+\r
+function jmolScriptEcho(script, targetSuffix) {\r
+ // returns a newline-separated list of all echos from a script\r
+ targetSuffix == undefined && (targetSuffix="0")\r
+ var Ret=jmolScriptWaitAsArray(script, targetSuffix)\r
+ var s = ""\r
+ for(var i=Ret.length;--i>=0;)\r
+ for(var j=Ret[i].length;--j>=0;)\r
+ if (Ret[i][j][1] == "scriptEcho")s+=Ret[i][j][3]+"\n"\r
+ return s.replace(/ \| /g, "\n")\r
+}\r
+\r
+\r
+function jmolScriptMessage(script, targetSuffix) {\r
+ // returns a newline-separated list of all messages from a script, ending with "script completed\n"\r
+ targetSuffix == undefined && (targetSuffix="0")\r
+ var Ret=jmolScriptWaitAsArray(script, targetSuffix)\r
+ var s = ""\r
+ for(var i=Ret.length;--i>=0;)\r
+ for(var j=Ret[i].length;--j>=0;)\r
+ if (Ret[i][j][1] == "scriptStatus")s+=Ret[i][j][3]+"\n"\r
+ return s.replace(/ \| /g, "\n")\r
+}\r
+\r
+\r
+function jmolScriptWaitAsArray(script, targetSuffix) {\r
+ var ret = ""\r
+ try{\r
+ jmolGetStatus("scriptEcho,scriptMessage,scriptStatus,scriptError",targetSuffix)\r
+ if (script) {\r
+ _jmolCheckBrowser();\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (applet) ret += applet.scriptWait(script);\r
+ ret = _jmolEvalJSON(ret,"jmolStatus")\r
+ if(typeof ret == "object")\r
+ return ret\r
+ }\r
+ }catch(e){\r
+ }\r
+ return [[ret]]\r
+}\r
+\r
+\r
+\r
+//////////// save/restore orientation /////////////\r
+\r
+function jmolSaveOrientation(id, targetSuffix) { \r
+ targetSuffix == undefined && (targetSuffix="0")\r
+ return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo\r
+}\r
+\r
+function jmolRestoreOrientation(id, targetSuffix) {\r
+ targetSuffix == undefined && (targetSuffix="0")\r
+ var s=_jmol["savedOrientation"+id]\r
+ if (!s || s == "")return\r
+ s=s.replace(/1\.0/,"0")\r
+ return jmolScriptWait(s,targetSuffix)\r
+}\r
+\r
+function jmolRestoreOrientationDelayed(id, delay, targetSuffix) {\r
+ arguments.length < 2 && (delay=1)\r
+ targetSuffix == undefined && (targetSuffix="0")\r
+ var s=_jmol["savedOrientation"+id]\r
+ if (!s || s == "")return\r
+ s=s.replace(/1\.0/,delay)\r
+ return jmolScriptWait(s,targetSuffix)\r
+}\r
+\r
+//////////// add parameter /////////////\r
+/*\r
+ * for adding callbacks or other parameters. Use:\r
+\r
+ jmolSetDocument(0)\r
+ var s= jmolApplet(....)\r
+ s = jmolAppletAddParam(s,"messageCallback", "myFunctionName")\r
+ document.write(s)\r
+ jmolSetDocument(document) // if you want to then write buttons and such normally\r
+ \r
+ */\r
+\r
+function jmolAppletAddParam(appletCode,name,value){\r
+ return (value == "" ? appletCode : appletCode.replace(/\<param/,"\n<param name='"+name+"' value='"+value+"' />\n<param"))\r
+}\r
+\r
+///////////////auto load Research Consortium for Structural Biology (RCSB) data ///////////\r
+\r
+function jmolLoadAjax_STOLAF_RCSB(fileformat,pdbid,optionalscript,targetSuffix){\r
+\r
+ _jmol.thismodel || (_jmol.thismodel = "1crn")\r
+ _jmol.serverURL || (_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm")\r
+ _jmol.RCSBserver || (_jmol.RCSBserver="http://www.rcsb.org")\r
+ _jmol.defaultURL_RCSB || (_jmol.defaultURL_RCSB=_jmol.RCSBserver+"/pdb/files/1CRN.CIF")\r
+ fileformat || (fileformat="PDB")\r
+ pdbid || (pdbid=prompt("Enter a 4-digit PDB ID:",_jmol.thismodel))\r
+ if(!pdbid || pdbid.length != 4)return ""\r
+ targetSuffix || (targetSuffix="0")\r
+ optionalscript || (optionalscript="")\r
+ var url=_jmol.defaultURL_RCSB.replace(/1CRN/g,pdbid.toUpperCase())\r
+ fileformat=="CIF" || (url=url.replace(/CIF/,fileformat))\r
+ _jmol.optionalscript=optionalscript\r
+ _jmol.thismodel=pdbid\r
+ _jmol.thistargetsuffix=targetSuffix\r
+ _jmol.thisurl=url\r
+ _jmol.modelArray = []\r
+ url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)\r
+ _jmolDomScriptLoad(url)\r
+ return url\r
+}\r
+\r
+\r
+///////////////auto load NIH CACTVS data -- compound name or SMILES ///////////\r
+\r
+function jmolLoadAjax_STOLAF_NIH(compoundid,optionalscript,targetSuffix){\r
+ _jmol.thismodel || (_jmol.thismodel = "aspirin")\r
+ _jmol.serverURL || (_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm")\r
+ _jmol.defaultURL_NIH || (_jmol.defaultURL_NIH="http://cactus.nci.nih.gov/chemical/structure/FILE/file?format=sdf&get3d=True")\r
+ compoundid || (compoundid=prompt("Enter a compound name or a SMILES string:",_jmol.thismodel))\r
+ if(!compoundid)return ""\r
+ targetSuffix || (targetSuffix="0")\r
+ optionalscript || (optionalscript="")\r
+ var url=_jmol.defaultURL_NIH.replace(/FILE/g,compoundid)\r
+ _jmol.optionalscript=optionalscript\r
+ _jmol.thismodel=compoundid\r
+ _jmol.thistargetsuffix=targetSuffix\r
+ _jmol.thisurl=url\r
+ _jmol.modelArray = []\r
+ url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)\r
+ _jmolDomScriptLoad(url)\r
+ return url\r
+}\r
+\r
+\r
+/////////////// St. Olaf College AJAX server -- ANY URL ///////////\r
+\r
+function jmolLoadAjax_STOLAF_ANY(url, userid, optionalscript,targetSuffix){\r
+ _jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"\r
+ _jmol.thisurlANY || (_jmol.thisurlANY = "http://www.stolaf.edu/depts/chemistry/mo/struc/data/ycp3-1.mol")\r
+ url || (url=prompt("Enter any (uncompressed file) URL:", _jmol.thisurlANY))\r
+ userid || (userid="0")\r
+ targetSuffix || (targetSuffix="0")\r
+ optionalscript || (optionalscript="")\r
+ _jmol.optionalscript=optionalscript\r
+ _jmol.thistargetsuffix=targetSuffix\r
+ _jmol.modelArray = []\r
+ _jmol.thisurl = url\r
+ url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)\r
+ _jmolDomScriptLoad(url)\r
+}\r
+\r
+\r
+/////////////// Mineralogical Society of America (MSA) data /////////\r
+\r
+function jmolLoadAjax_MSA(key,value,optionalscript,targetSuffix){\r
+\r
+ _jmol.thiskeyMSA || (_jmol.thiskeyMSA = "mineral")\r
+ _jmol.thismodelMSA || (_jmol.thismodelMSA = "quartz")\r
+ _jmol.ajaxURL_MSA || (_jmol.ajaxURL_MSA="http://rruff.geo.arizona.edu/AMS/result.php?mineral=quartz&viewing=ajaxjs")\r
+ key || (key=prompt("Enter a field:", _jmol.thiskeyMSA))\r
+ if(!key)return ""\r
+ value || (value=prompt("Enter a "+key+":", _jmol.thismodelMSA))\r
+ if(!value)return ""\r
+ targetSuffix || (targetSuffix="0")\r
+ optionalscript || (optionalscript="")\r
+ optionalscript == 1 && (optionalscript='load "" {1 1 1}')\r
+ var url=_jmol.ajaxURL_MSA.replace(/mineral/g,key).replace(/quartz/g,value)\r
+ _jmol.optionalscript=optionalscript\r
+ _jmol.thiskeyMSA=key\r
+ _jmol.thismodelMSA=value\r
+ _jmol.thistargetsuffix=targetSuffix\r
+ _jmol.thisurl=url\r
+ _jmol.modelArray = []\r
+ loadModel=_jmolLoadModel\r
+ _jmolDomScriptLoad(url)\r
+ return url\r
+}\r
+\r
+\r
+\r
+function jmolLoadAjaxJS(url, userid, optionalscript,targetSuffix){\r
+ userid || (userid="0")\r
+ targetSuffix || (targetSuffix="0")\r
+ optionalscript || (optionalscript="")\r
+ _jmol.optionalscript=optionalscript\r
+ _jmol.thismodel=userid\r
+ _jmol.thistargetsuffix=targetSuffix\r
+ _jmol.modelArray = []\r
+ _jmol.thisurl = url\r
+ url+="&returnFunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix\r
+ _jmolDomScriptLoad(url)\r
+}\r
+\r
+\r
+//// in case Jmol library has already been loaded:\r
+\r
+}catch(e){}\r
+\r
+///////////////moving atoms //////////////\r
+\r
+// HIGHLY experimental!!\r
+\r
+function jmolSetAtomCoord(i,x,y,z,targetSuffix){\r
+ _jmolCheckBrowser();\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (applet) applet.getProperty('jmolViewer').setAtomCoord(i,x,y,z)\r
+}\r
+\r
+function jmolSetAtomCoordRelative(i,x,y,z,targetSuffix){\r
+ _jmolCheckBrowser();\r
+ var applet=_jmolGetApplet(targetSuffix);\r
+ if (applet) applet.getProperty('jmolViewer').setAtomCoordRelative(i,x,y,z)\r
+}\r
+\r
+\r
+///////////////applet fake for testing buttons/////////////\r
+\r
+\r
+if(_jmol.useNoApplet){\r
+ jmolApplet = function(w){\r
+ var s="<table style='background-color:black' width="+w+"><tr height="+w+">"\r
+ +"<td align=center valign=center style='background-color:white'>"\r
+ +"Applet would be here"\r
+ +"<p><textarea id=fakeApplet rows=5 cols=50></textarea>"\r
+ +"</td></tr></table>"\r
+ return _jmolDocumentWrite(s)\r
+ }\r
+\r
+ _jmolFindApplet = function(){return jmolApplet0}\r
+\r
+ jmolApplet0 = {\r
+ script: function(script){document.getElementById("fakeApplet").value="\njmolScript:\n"+script}\r
+ ,scriptWait: function(script){document.getElementById("fakeApplet").value="\njmolScriptWait:\n"+script} \r
+ ,loadInline: function(data,script){document.getElementById("fakeApplet").value="\njmolLoadInline data:\n"+data+"\n\nscript:\n"+script}\r
+ }\r
+}\r
+\r
+\r
+///////////////////////////////////////////\r
+\r
+ // This should no longer be needed, jmolResizeApplet() is better; kept for backwards compatibility\r
+ /*\r
+ Resizes absolutely (pixels) or by percent of window (w or h 0.5 means 50%).\r
+ targetSuffix is optional and defaults to zero (first applet in page).\r
+ Both w and h are optional, but needed if you want to use targetSuffix.\r
+ h defaults to w\r
+ w defaults to 100% of window\r
+ If either w or h is between 0 and 1, then it is taken as percent/100.\r
+ If either w or h is greater than 1, then it is taken as a size (pixels). \r
+ */\r
+function jmolResize(w,h,targetSuffix) {\r
+ _jmol.alerted = true;\r
+ var percentW = (!w ? 100 : w <= 1 && w > 0 ? w * 100 : 0);\r
+ var percentH = (!h ? percentW : h <= 1 && h > 0 ? h * 100 : 0);\r
+ if (_jmol.browser=="msie") {\r
+ var width=document.body.clientWidth;\r
+ var height=document.body.clientHeight;\r
+ } else {\r
+ var netscapeScrollWidth=15;\r
+ var width=window.innerWidth - netscapeScrollWidth;\r
+ var height=window.innerHeight-netscapeScrollWidth;\r
+ }\r
+ var applet = _jmolGetApplet(targetSuffix);\r
+ if(!applet)return;\r
+ applet.style.width = (percentW ? width * percentW/100 : w)+"px";\r
+ applet.style.height = (percentH ? height * percentH/100 : (h ? h : w))+"px";\r
+ //title=width + " " + height + " " + (new Date());\r
+}\r
+\r
+// 13 Jun 09 -- makes jmolResize() obsolete (kept for backwards compatibility)\r
+function jmolResizeApplet(size,targetSuffix) {\r
+ // See _jmolGetAppletSize() for the formats accepted as size [same used by jmolApplet()]\r
+ // Special case: an empty value for width or height is accepted, meaning no change in that dimension.\r
+ _jmol.alerted = true;\r
+ var applet = _jmolGetApplet(targetSuffix);\r
+ if(!applet)return;\r
+ var sz = _jmolGetAppletSize(size, "px");\r
+ sz[0] && (applet.style.width = sz[0]);\r
+ sz[1] && (applet.style.height = sz[1]);\r
+}\r
+\r
+function _jmolGetAppletSize(size, units) {\r
+ /* Accepts single number or 2-value array, each one can be one of:\r
+ percent (text string ending %), decimal 0 to 1 (percent/100), number, or text string (interpreted as nr.)\r
+ [width, height] array of strings is returned, with units added if specified.\r
+ Percent is relative to container div or element (which should have explicitly set size).\r
+ */\r
+ var width, height;\r
+ if ( (typeof size) == "object" && size != null ) {\r
+ width = size[0]; height = size[1];\r
+ } else {\r
+ width = height = size;\r
+ }\r
+ return [_jmolFixDim(width, units), _jmolFixDim(height, units)];\r
+}\r
+\r
+function _jmolFixDim(x, units) {\r
+ var sx = "" + x;\r
+ return (sx.length == 0 ? (units ? "" : _jmol.allowedJmolSize[2])\r
+ : sx.indexOf("%") == sx.length-1 ? sx \r
+ : (x = parseFloat(x)) <= 1 && x > 0 ? x * 100 + "%"\r
+ : (isNaN(x = Math.floor(x)) ? _jmol.allowedJmolSize[2]\r
+ : x < _jmol.allowedJmolSize[0] ? _jmol.allowedJmolSize[0]\r
+ : x > _jmol.allowedJmolSize[1] ? _jmol.allowedJmolSize[1] \r
+ : x) + (units ? units : ""));\r
+}\r
+\r
+\r
+\r
+\r