//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// util.js WAS ADDED BY ERIC MARTZ.
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

var initSpt = "[NOT SET]";

var show_author_info = false;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeControls()
{
	var ctrls = "";

	if ( getNavigation() == 'top' ) 
		ctrls += makeNavigation();

	if (!isContents)
	{
		ctrls += "<div style='margin: 10px;'>" +
			make_script_filename(0) + "</div>";
	}

	var buttonCount = getButtonCount();
		
	for ( var i = 1; i <= buttonCount; i++ ) 
		ctrls += makeButton(i);

	if ( getNavigation() == 'bottom' ) 
		ctrls += makeNavigation();

	ctrls += makeFontSizeHelp();
	ctrls += makeFooter();

	return ctrls;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function writeControls()
{
	document.writeln(makeControls());
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function putWindowTitle()
{
	document.writeln("<title>" + tutorialTitle + "</title>");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function putJmolApplet()
{
	// jmolInitialize() is REQUIRED!
	// It specifies the relative location of the applet.
	//
	// If you are serving this page from a Web server, call jmolInitialize 
	// with the relative path from this html file to the JmolApplet directory.
	
	// defaultjar (defined in Jmol.js) causes use of the single file
	// applet JmolApplet.jar, instead of the many-file applet JmolApplet0*.jar

	jmolInitialize("../..", defaultjar);
	
	// jmolSetCallback() was added by Frieda.
	// It is required for Angel Herraez's spin state button below.
	// It must be betweeen initialize and applet calls.

	jmolSetCallback("messageCallback", "messageProcess");
	
	initSpt = getStart();
	jmolApplet( ["100%","94%"], initSpt);
	
	// messageCallback (messageProcess()) watches for the report from
	// show spin, and when it goes by, toggles spinning.
	jmolBr(); // leaves some space below the applet for the Spin Toggle button.
	jmolButton("exit; show spin;", "toggle spinning");

	// This must be after the above calls, else it suppresses their writes.
	jmolSetDocument(0); // this suppresses direct html writes by jmolButton()
	// see makeControls()
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

var authoring_mode_message_color = "808080";

var script_showing = new Array();

function make_script_filename(bnum)
{
	if (!authoring_mode)
		return "";

	script_showing[bnum] = false;

	var msg = make_show_script_msg(bnum);

	return(msg);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function make_show_script_msg(bnum)
{
	// for buttons in a control panel, bnum 1-N
	// bnum == 0 for the contents page

	if (bnum > 0 && !show_author_info)
		return "";

	var msg = "";

	if (show_author_info || bnum == 0)
		msg += "<div id='show_script" + bnum + "'>" +
			"<font color='#" + authoring_mode_message_color + "'>";

	var ck = "";
	if (show_author_info)
		ck = " checked";

	if (bnum == 0) // initial view
	{
		if (!isContents)
		{
			msg +=
				"<input type='checkbox' name='authinfo' " +
				"onClick='reWriteControls()'" + ck + ">Show Info for Author " +
				"(authoring_mode is true).<br>";
		}

		if (show_author_info || isContents)
			msg += "Initial View:<br>";
	}

	if (show_author_info || isContents)
	{
		msg +=
			"&nbsp; &quot;" + buttons[bnum][iMoleculeFilename] + "&quot;, " +
			"&quot;" + buttons[bnum][iScript] + "&quot;";

		if (script_showing[bnum])
			msg += make_script_listing(bnum);

		else
			msg +=
				"<div align='right'><a href='javascript: show_script(" + bnum + ")'>Show Script</a></div>";
	}

	if (bnum == 0)
		msg +=
			"Change authoring_mode (in _jsutil/config2.js) to false " +
			"in order to hide all messages in this color.";

	if (show_author_info || bnum == 0)
		msg += "</font></div>";

	return msg;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function show_script(bnum)
{
	var divId = "show_script" + bnum;

	script_showing[bnum] = true;
	
	document.getElementById(divId).innerHTML = make_show_script_msg(bnum);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function make_script_listing(bnum)
{
	var spt = _jmol.scripts[bnum + 1];
	if (bnum == 0)
		spt = initSpt;
	spt = spt.replace(/;/g, "<br>\n");
	spt = spt.replace(/script/g, "<big><big>script</big></big>");

	var hidelk =
		"<div align='right'><a href='javascript: hide_script(" +
		bnum + ")'>hide script</a></div>";


	var msg = "<div class='script'>" +
		"<font color='#" + authoring_mode_message_color + "'>" +
		 spt + hidelk + "</font></div>";

	return msg;	
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function hide_script(bnum)
{
	var divId = "show_script" + bnum;

	script_showing[bnum] = false;
	var msg = make_show_script_msg(bnum);

	document.getElementById(divId).innerHTML = msg;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function reWriteControls()
{
	show_author_info = document.baseForm.authinfo.checked;

	document.getElementById("controls").innerHTML =
		makeControls();	
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function script2Jmol(spt)
{
	// This assumes there is only one Jmol, jmolApplet0.

	jmolScript(spt, "0");	
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeFooter()
{
	var msg = "<div class='templateLink'>Would you like\n" +
		"<ul>\n" +
		"<li>A <a href='../../_docs/tutuse.htm#ppt' " +
			"target='_blank'><b>Powerpoint&reg; slide</b></a> " +
			"containing this view?</li>\n" +

		"<br><li>A <a href='../../_docs/tutuse.htm#bkg' " +
			"target='_blank'><b>white background</b></a>?</li>\n" +
		"<li>A <a href='../../_docs/tutuse.htm#colors' " +
			"target='_blank'><b>different color scheme</b></a>?</li>\n" +
		"<li>To <a href='../../_docs/tutuse.htm#colors' " +
			"target='_blank'><b>identify</b></a> an atom?</li>\n" +
		"<li>To <a href='../../_docs/tutuse.htm#colors' " +
			"target='_blank'><b>measure</b></a> distances or angles?</li>\n" +

		"</ul>\n" +

		"Explore the molecule(s) in this Tutorial further, " +
		"using <i>FirstGlance in Jmol</i>, " +


		"<ul>\n" +

		makeMoleculeLinks2FGiJ() +

		"</ul>\n" +

		"<br><big>You " +
		"can make interactive 3D molecular structure tutorials like this one! " +
		"<a href='../../_docs/index.htm' target='_blank'><b>Here`s " +
		"how</b>.</a></big>" +

		"<br><br>" +
		makeLicense() +

		"</div>\n";


	return msg;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeMoleculeLinks2FGiJ()
{
	var msg = "";

	if (totalMolecules == 0)
		msg = 

"<big><b><font color='red'>Author: please list PDB codes and \n\
descriptions of the molecules shown in this tutorial in the file \n\
js4all/molecules.js!\n\
</font></b></big>";

	else
	{
		for (iml = 1; iml <= totalMolecules; iml++)
		{
			var moldis1;
			var moldis2 = "";
			var moldis1 = moleculeDescription[iml];
			var op = moldis1.indexOf("(");
			if (op != -1)
			{
				moldis2 = moldis1.substring(op);
				moldis1 = moldis1.substring(0, op - 1);
			}

			msg += "<li><a href='http://firstglance.jmol.org/fg.htm?mol=" + 
				moleculeCoordinates[iml] + "' target='_blank'><b>" +
				moldis1 + "</b></a> " + moldis2 +
				" [<a href='http://www.pdb.org/pdb/explore/explore.do?structureId=" +
				moleculeCoordinates[iml] + "' target='_blank'><b>" +
				moleculeCoordinates[iml] + "</b></a>]</li>";
		}
	}

	return msg;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
