// debug alerts used: # 39
// jcontrol.js - control panel support for controlling Jmol.

// Text for translation is in txt06.js

var pollForm = true;
var doNotPollForm = false;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// (frames only)
// The control.htm document and its javascript must complete loading
// before we try to run a script defined there in the jmol frame!
// Therefore we must not load jmol until after control.htm is loaded.

function startJmol()
{
	if (top.usingFrames)
		top.frameRight.document.location.replace("moldoc.htm");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function initFG()
{
	top.initTargetDivs();
// removed to facilitate use of "javascript" sitemeter.
//	showHelp2('makeBePatientHelp()');
	startJmol(); // frames only
//	slideit(); the image to change has not loaded yet, see startup.txt
	//alert("jcontrol.js #38 initFG() completed");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// writeToggleButton() is used to write each toggle button.
// Button numbers are predetermined to minimize confusion when switching
//   consurf <--> fg.
// The button numbers are used to take the correct action in: doToggleButton().
// The up and down command scripts, button state, and labels are
// kept in arrays.

var toggleIndex = 0;
var toggleUpSptName = new Array();
var toggleDownSptName = new Array();
var toggleIsDown = new Array();
var toggleHelpName = new Array();

var ligandIndex = 0;
var waterIndex = 1;
var slabIndex = 2;

var backgroundIndex = 3;
	toggleIsDown[backgroundIndex] = false; // default black background at outset
var spinIndex = 4;
var resetIndex = 5;

var qualityIndex = 6;

var savedButtonStates = new Array();

//var toggleIndexFromName = new Array(
//"ligands+", "water", "slab", "background", "spin");

// start is "up" or "down"

function writeToggleButton(downSptName, upSptName, label, start, helpName,
titleMsg)
{
	document.writeln(
	makeToggleButton(downSptName, upSptName, label, start, helpName, titleMsg));
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeToggleButton(downSptName, upSptName, label, start, helpName,
titleMsg, cptab)
{

	// get pre-determined index
	if (match(label, "water"))
		toggleIndex = waterIndex;
	if (match(label, "ligand"))
		toggleIndex = ligandIndex;
	if (match(label, "slab"))
		toggleIndex = slabIndex;

	if (match(label, "background"))
		toggleIndex = backgroundIndex;
	if (match(label, "spin"))
		toggleIndex = spinIndex;

	if (match(label, "view1"))
		toggleIndex = resetIndex;

	if (match(label, "quality"))
		toggleIndex = qualityIndex;

	// search for "buttonoffset"
	// cptab 2: for tab II, ibutt is 11 and higher.
	// For Molecule tab (cptab 0), ibutt is 101 and higher.
	if (cptab == 2)
		toggleIndex += 10;
	if (cptab == 0)
		toggleIndex += 100;

	// remember up and down scripts
	toggleUpSptName[toggleIndex] = upSptName;
	toggleDownSptName[toggleIndex] = downSptName;
	toggleHelpName[toggleIndex] = helpName;

	var butwas = toggleIsDown[toggleIndex];
	if (typeof(butwas) != "undefined")
	{
		if (butwas)
			start = "down";
		else
			start = "up";
	}
	// else this is the first time the button was created, and so it
	// obeys the default start value.

	if (start == "up")
		toggleIsDown[toggleIndex] = false;
	else
		toggleIsDown[toggleIndex] = true;

	// supercede default with saved state

	if (typeof(titleMsg) == "undefined")
		titleMsg = "";

	var tog = "<a href='javascript: doToggleButton(" + toggleIndex + ")'>" +
"<img src='" + start + ".gif' border='0' name='toggle" + toggleIndex + "'" +
" title='" + titleMsg + "'\/><\/a>&nbsp;" + label;

	return tog;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// could have been named doButton  dtb
function doToggleButton(tognum)
{
		//	alert("jcontrol.js #14 doToggleButton(" + tognum + ")");

// ======== REFUSE TOGGLE ================

	// DON'T USE WATER BUTTON DURING CONTACTS TARGET SELECTION
	if (selectMode != "" && buttonIs(tognum, waterIndex))
		if (confirm(ContactsSelectWater_txt))
			return;

	// REQUIRE RESET FOR WATER/LIGAND WHEN symmetryLoaded (Unit Cell, XtlCon)
	if (symmetryLoaded && (buttonIs(tognum, waterIndex) ||
		buttonIs(tognum, ligandIndex)))
	{
		alertResetFirst();
		return;
	}

	// DON'T SPIN WHEN CAPTURING AN IMAGE OR ANIMATION
	if (match(helpPanel, "capturehelp") &&
			buttonIs(tognum, spinIndex) && !toggleIsDown[spinIndex])
	{
		alert("Spinning is not permitted when saving graphics.");
		return;
	}

// ======== END REFUSE TOGGLE ================
// ======== BEGIN EXECUTE TOGGLE ================

	var sptname = toggleUpSptName[tognum];

	var spt;

	var imgnum = eval("document.toggle" + tognum);
	if (toggleIsDown[tognum]) // going up/off
	{
		setButtonState("up", tognum);
		spt = eval(toggleUpSptName[tognum]);
		toggleIsDown[tognum] = false;
	}
	else // toggle is up, going on/down
	{
			//		alert("jcontrol.js #35: toggleHelpName = " + toggleHelpName[tognum]);
			showHelp2(toggleHelpName[tognum]); // blank for Quality

		setButtonState("down", tognum);
		spt = eval(toggleDownSptName[tognum]);
		toggleIsDown[tognum] = true;
	}

	//	alert("jcontrol.js #14a buttontoggle executed");


// ======== REFRESH HELP IF NEEDED ================

	// For background, refresh the PDB Id echo
// UNNEC?
//	if (tognum == backgroundIndex)
//		spt += makeEchoPdbIdSpt(""); // blank parameter means get color from toggle

	// For background, If help is seqnum, refresh help to toggle White/Black checkbox.
	if (match(helpPanel, "seqnum"))
		showHelp(helpPanel);

	// For background, refresh capture help
	// this is already done for quality button, but have been unable to figure out how, see
	// capture.txt
	//	alert("jcontrol.js #36: backgroundIndex=" + backgroundIndex +
	//		"\n tognum=" + tognum +
	//		"\n helpPanel=" + helpPanel);
	// tognum can be backgroundIndex + 100 so just do it for all buttons or use buttonIs()
	//	if (tognum == backgroundIndex && match(helpPanel, "capturehelp"))
	if (match(helpPanel, "capturehelp"))
		showHelp(helpPanel);

// ======== TURN OFF CENTERING, HIDING, SELECTING AS NEEDED  ================

	// if centering was on, and the button went down (except for bkg, spin),
	// now the centering controls are gone, so turn centering off.
	// Ditto for hiding & selecting.
	if (!buttonIs(tognum, spinIndex) && !buttonIs(tognum, backgroundIndex))
	{
//		alert("jcontrol.js #23 canceling centerMode, hideMode, selectMode!");
		if (toggleIsDown[tognum]) // button went down
		{
			// must be done before scriptToJmol!
			centerMode = false; // scriptToJmol turns off picking center

			// only Water or Ligands+ affect hiding, since Slab is refused above.
			top.hideMode = "";
			if (hiddenRangeStart != "")
			{
				hiddenRangeStart = "";
				spt += makeEchoSpt(""); // to blank "Range Starts at "
			}
			top.selectMode = "";
		}
	}

	// alert("jcontrol.js #3: doToggleButton(" + spt + ")");

	// SKIP doMolViewSpt FOR ALL(?) BUTTONS
	if (buttonIs(tognum, spinIndex)
		|| buttonIs(tognum, backgroundIndex)
		|| buttonIs(tognum, qualityIndex)
			//		|| buttonIs(tognum, ligandIndex) NEEDS HIDE/ISOLATE
			//		|| buttonIs(tognum, waterIndex) NEEDS HIDE/ISOLATE
		|| buttonIs(tognum, slabIndex)
		)
		unchangedScriptToJmol(spt);
	else
		doMolViewSpt(spt); // in doToggleButton()
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function getPDBId()
{
	var pdbid = validPDBId;

	// CONSURF UPLOAD
	if (pdbid.length == 0 && consurfMode)
	{
    if (consurf_pdb_id.length == 4)
			pdbid = consurf_pdb_id;
	}
	// PEPSURF UPLOAD
	if (pdbid.length == 0 && pepsurfMode)
	{
    if (pepsurf_pdb_id.length == 4)
			pdbid = pepsurf_pdb_id;
	}
	// SELECTON UPLOAD
	if (pdbid.length == 0 && selectonMode)
	{
    if (selecton_pdb_id.length == 4)
			pdbid = selecton_pdb_id;
	}
	// EPITOPIA UPLOAD
	if (pdbid.length == 0 && epitopiaMode)
	{
    if (epitopia_pdb_id.length == 4)
			pdbid = epitopia_pdb_id;
	}
	return pdbid;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// Write a pdb code-specific link to RCSB's Structure Explorer.
// NOT IN USE
/*
function makeRCSB(pdbid)
{
	var tmsg = pdbid.toUpperCase() + " " + AtPDB_txt;

	// explore.cgi?pdbId= returns a blank page when the entry is on hold.
	// Feb08: rcsb.org/pdb/explore.do?structureId= no longer works for on hold.
	// Flammang @Nature inquired of RCSB and we were told to use the following
	// by Christine Zardecki, zardecki@rcsb.rutgers.edu
	var rcsb = "<a href='http:\/\/www.rcsb.org\/pdb\/search\/structidSearch.do?structureId=" +
	pdbid + "' target='rcsbwin' \/>" +
	"<img src='pdb.gif' border=1 align='center' \
title='" + tmsg + "'><\/a>";

	return(rcsb);
}
*/
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 // NOT IN USE
 /*
function makeOCA(pdbid)
{
	var oca = "<a href='http:\/\/bip.weizmann.ac.il\/oca-bin\/ocashort?id=" +
	pdbid + "' target='_blank' \/>" +
	"<img src='oca.gif' border=1 align='center' \
title='" + pdbid.toUpperCase() + " " + InfoAtOCATT_txt + "'><\/a>";

	return oca;
}
 */
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// Write a special troubleshooting message, only if the Safari browser
// is being used. In 11/05, this bug in Apple's java had been fixed in
// OSX.4 (tiger) but not in OSX.3.9.

//function makeSafari()
//{
//	if (!isMac)
//		return "";
//	var safariBug =
//"Quit, restart the browser if the above controls don't work. \
//<a href=\"notes.htm#safari\" target=_blank>Why?</a><br>";

//	return (safariBug);
//}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// Write a link that sends a command script to Jmol.
// Each link is numbered in the order in which they are written.
// The link numbers are used to perform the correct action in: doViewLink().
// Actions and link labels are stored in arrays.

var viewLinkSptName = new Array();
var viewLinkHelpName = new Array();

// CONTROLS TAB I
var secondaryStructureIndex = 1;
var cartoonIndex = 2;
var NCRainbowIndex = 3;
var compositionIndex = 4;
var hydrophobicPolarIndex = 5;
var chargeIndex = 6;
var contactsIndex = 7;
var vinesIndex = 8;
var allModelsIndex = 9;
var hideIndex = 10;
var findIndex = 11;
var moreViewsIndex = 12;
var centerIndex = 13;
var troubleshootingIndex = 14;
var resetIndex = 15;
var keyExternalResourcesIndex = 16;

// CONTROLS TAB II
var ssBondsIndex = 17;
var catPiSBIndex = 18;
var uncertaintyIndex = 19;

// MORE ADDED LATER
var solidIndex = 20;
var xtlconIndex = 21;
var unitCellIndex = 22;
var isolateIndex = 23;
var endsIndex = 24;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function getLinkIndex(sptName)
{
	if (match(sptName, "rocket"))
		return secondaryStructureIndex;
	if(match(sptName, "cartoon"))
		return cartoonIndex;
	if(match(sptName, "rainbow"))
		return NCRainbowIndex;
	if(match(sptName, "composition"))
		return compositionIndex;
	if(match(sptName, "polarity"))
		return hydrophobicPolarIndex;
	if(match(sptName, "charge"))
		return chargeIndex;
	if(match(sptName, "contacts"))
		return contactsIndex;
	if(match(sptName, "vine"))
		return vinesIndex;
	if(match(sptName, "allmodels"))
		return allModelsIndex;
	if(match(sptName, "hide"))
		return hideIndex;
	if(match(sptName, "find"))
		return findIndex;
	if(match(sptName, "moreviews"))
		return moreViewsIndex;
	if(match(sptName, "center"))
		return centerIndex;
	if(match(sptName, "trouble"))
		return troubleshootingIndex;
	if(match(sptName, "view1") || match(sptName, "reset"))
		return resetIndex;
	if(match(sptName, "keyexternal"))
		return keyExternalResourcesIndex;

	// CONTROLS TAB II

	if(match(sptName, "ends"))
		return endsIndex;

	if(match(sptName, "ssbonds"))
		return ssBondsIndex;

	if(match(sptName, "catpisb"))
		return catPiSBIndex;

	if(match(sptName, "uncertainty"))
		return uncertaintyIndex;

	// MORE ADDED LATER

	if(match(sptName, "solid"))
		return solidIndex;

	if(match(sptName, "crystal"))
		return xtlconIndex;

	if(match(sptName, "unitcell"))
		return unitCellIndex;

	if(match(sptName, "isolate"))
		return isolateIndex;


	alert("Programmer's error: getLinkIndex() failure (jcontrol.js).\n\
		sptName: " + sptName);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function writeViewLink(sptName, label, helpName, titleMsg)
{
	lk = makeViewLink(sptName, label, helpName, titleMsg);
	document.writeln(lk);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeViewLink(sptName, label, helpName, titleMsg)
{
// This is what jmol.js jmolLink() makes:
//<A name='jmolLink0' id='jmolLink0'
//href='javascript:_jmolClick(1);'
//onMouseover='_jmolMouseOver(1);return true;' onMouseout='_jmolMouseOut()'
//>Cartoon</A>

	linkIndex = getLinkIndex(sptName);

	viewLinkSptName[linkIndex] = sptName;
	viewLinkHelpName[linkIndex] = helpName;
//	linkLabel[linkIndex] = label;

// class='greenlink' 

	var lk =
		"<a href='javascript: doViewLink(" + linkIndex + ")'";
	if (typeof(titleMsg) != "undefined")
	{
		if (titleMsg != "")
			lk += " title='" + titleMsg + "' ";
	}
	lk += ">" + label + "<\/a>"

//	if (match(titleMsg, "rocket"))
//		alert(lk);

	return lk;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function doViewLink(lnum) // dvl
{
	reportElapsed("doViewLink() starting (jcontrol.js)");

	// LOCAL CONVENIENCE FLAGS
	var allModelsNow = match(viewLinkSptName[lnum], "allmodels");
	var chargeNow = match(viewLinkSptName[lnum], "charge");
	var centerNow = match(viewLinkSptName[lnum], "center");
	var compositionNow = match(viewLinkSptName[lnum], "composition");
	var hideNow = match(viewLinkSptName[lnum], "hide");
	var isolateNow = match(viewLinkSptName[lnum], "isolate");
	var keyExternalNow = match(viewLinkSptName[lnum], "keyexternal");
	// Local Uncertainty
	var uncertaintyNow = match(viewLinkSptName[lnum], "uncertainty");
	var moreViewsNow = match(viewLinkSptName[lnum], "moreviews");
	var polarityNow = match(viewLinkSptName[lnum], "polarity");
	var preContacts = match(viewLinkSptName[lnum], "precontacts");
	var preFind = match(viewLinkSptName[lnum], "find");
	var resetNow = match(viewLinkSptName[lnum], "reset"); // formerly view1
	var solidNow = match(viewLinkSptName[lnum], "solid");
	var troubleNow = match(viewLinkSptName[lnum], "troubleshooting");
	// uncertainty, see above
	var unitCellNow = match(viewLinkSptName[lnum], "unitcell");
	var vinesNow = match(viewLinkSptName[lnum], "vine");
	var xtlConNow = match(viewLinkSptName[lnum], "crystal");
	var rocketNow = match(viewLinkSptName[lnum], "rocket");
	var endsNow = match(viewLinkSptName[lnum], "ends");

	if (rocketNow) // recalc secondary structure in case hidden/isolate has changed
		getSecondary();

//	alert("jcontrol.js #24 xtlCon = " + xtlCon);

	if (xtlConLoaded && !(resetNow || preFind || troubleNow ||
		centerNow || xtlConNow || uncertaintyNow))
	{
		alertResetFirst();
		return;
	}

	if (unitCellLoaded && !(resetNow || preFind || troubleNow ||
		centerNow || unitCellNow || uncertaintyNow))
	{
		alertResetFirst();
		return;
	}

	// if entering Hide.. or Find.. from the help prefix links in ConSurf,
	// also change the control panel to FG.
	if (controlPanel == "consurf" && (hideNow || isolateNow || preFind))
		setupControlPanelTabs();

	// CONFIRM NEW CONTACTS
	if (preContacts && contactsShowing)
	{
		if (!confirm(ContactsStartOver_txt))
		{
			showHelp2("makeContactsShownHelp()");
			return;
		}
	}
			
	// contactsShowing goes off prior to an unrelated view, that is,
	// unless the contacts view is to be modified with
	// Find, Hide, Center, More Views, or Troubleshooting.
	// This must happen before showing help!
	if (!hideNow && !isolateNow && !preFind && !centerNow &&
		!moreViewsNow &&
		!troubleNow)
	{
		contactsShowing = false;
		markContactsTargets = false;
	}

	if (preContacts)
		resetContacts(); // must be done before showing help

	// RESET
	if (resetNow)
	{
		if (confirm("Start over, restoring the initial view?"))
			resetPrep();
		else
			return;
	}

	if (vinesNow) // must be done before help
	{
		setButtonState("up", waterIndex);

// In FGiJ 2.2, I want these to be remembered within a session.
//		allWireframe = false;
//		hydrogensVisible = true;
//		sidechainsVisible = true;
	}

	if (preContacts)
		useConsurfColors = false;

	// =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  
	// SHOW HELP
	showHelp2(viewLinkHelpName[lnum]);

//	alert("jcontrol.js #6: help shown in doViewLink():\n" +
//		viewLinkHelpName[lnum]);
	// =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  

	// xtlConNow help explains not possible for NMR
	if ((xtlConNow || unitCellNow) && match(expMethod, "nmr"))
		return;

	// FOCUS FIND SLOT
	if (match(viewLinkHelpName[lnum], "makefindhelp"))
		setTimeout("document.findForm.toFind.focus()", 100);

	// RETURN IF NO SCRIPT
	// More Views, Troubleshooting are special cases with NO SCRIPT
	// No Script: moreViews, troubleshooting, keyExternal
	var noScript = false;
	if (troubleNow || moreViewsNow || keyExternalNow || endsNow)
		noScript = true;

	if (pdbIsSwissModel && uncertaintyNow)
		noScript = true;
	// Local Uncertainty OK for OPM and MakeMultimer

	// pdbNoHeader includes OPM, SwissModel, MakeMultimer
	if (pdbNoHeader &&
		(xtlConNow || unitCellNow))
		noScript = true;

	if (noScript)
	{
		cancelCenteringNoHelp(); // sends script set picking on
		selectMode = ""; // in doViewLink()
		return;
	}

	// SET VARIOUS FLAGS
	// For all remaining views, non-standard residues will be hidden.
//	alert("jcontrol.js #4: turning off showNonStandardResidues");
	top.showNonStandardResidues = false;

	// For all remaining views, hiding mode goes off.
	if (!hideNow && !isolateNow)
		top.hideMode = "";

	// Unless this is Contacts, selectMode goes off.
	if (!preContacts)
		top.selectMode = ""; // in doViewLink()

	//..................................................
	// BUTTONS FORCED UP/DOWN
	//..................................................

	// LIGAND BUTTON GOES ON/DOWN if Composition, Vines, precontacts, reset,
	// solid.
	if (compositionNow || vinesNow || preContacts || resetNow || solidNow)
			setButtonState("down", ligandIndex);

	// LIGAND BUTTON GOES OFF/UP if Polarity, Charge, All Models, xtlConNow
	if (polarityNow || chargeNow ||
		allModelsNow || xtlConNow || unitCellNow)
	{
//			alert("jcontrol.js #17a: setButtonState(up, ligandIndex=" + ligandIndex + ")");
			setButtonState("up", ligandIndex);
	}

	// WATER BUTTON GOES ON/DOWN if Composition, Contacts
	if (match(viewLinkSptName[lnum], "composition") || preContacts)
		setButtonState("down", waterIndex);

	// WATER BUTTON GOES OFF/UP if Polarity, Charge, All Models, reset,
	// xtlConNow, solid.
	// Vines done above.
	// preContacts
	if (polarityNow || chargeNow || allModelsNow || resetNow || preContacts ||
		xtlConNow || unitCellNow || solidNow)
	{
//			alert("jcontrol.js #17b: setButtonState(up, waterIndex=" + waterIndex + ")");
			setButtonState("up", waterIndex);
	}

	// SLAB BUTTON GOES OFF/UP if reset, xtlCon, unitCell
//	if (preContacts || hideNow) // LEAVE SLAB ON
	if (resetNow || xtlConNow || unitCellNow)
		setButtonState("up", slabIndex);

	// BACKGROUND BUTTON GOES BLACK/UP if precontacts, prefind, allmodels, reset
	if (preContacts || preFind || allModelsNow || resetNow)
		setButtonState("up", backgroundIndex); // Background Black

	// BACKGROUND BUTTON GOES DOWN/WHITE if unitCellNow
	if (unitCellNow)
		setButtonState("down", backgroundIndex);

	// SPIN BUTTON GOES DOWN/ON if reset
	if (resetNow)
	{
		if (preferenceSpin)
			setButtonState("down", spinIndex);
		else
			setButtonState("up", spinIndex);
	}

	// QUALITY BUTTON GOES UP if reset
	if (resetNow)
		setButtonState("up", qualityIndex);

	//....................................................
	// END BUTTONS
	//....................................................

	// for xtlConNow, turn off labels
	if ((xtlConNow || unitCellNow) && labelsOn)
		toggleLabelsShow();

	// for unitCellNow, turn off sequence numbers, residue names.
	// (they are permitted for xtlConNow).
	if (unitCellNow)
		resetLabelCheckboxes();

	// SET centerMode IF CENTERING
	if (centerNow)
		top.centerMode = true;

	// SET default view for contacts
	if (preContacts)
		contactsView = "sf";

	// SET hideMode // now set in help
//	alert("jcontrol.js #28 hideMode='" + hideMode + "'");
// NO LONGER NECESSARY now that I stopped blanking hideMode above
//	if (hideNow || isolateNow)
//		hideMode = "c"; // hide has blank script, but needs sendToJmol postscripts!

	// vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
	// GENERATE THE NEW VIEW SCRIPT

	var spt = eval(viewLinkSptName[lnum]);
	//	alert("jcontrol.js #39:\n" + spt);
	
	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

// hover remains on for slab. this is probably unnecessary:	
	if (preContacts || resetNow || hideNow) // SLAB FORCED OFF
		spt += 	hoverSpt; // restore hover report

// This was removed in FGiJ 1.43.
//		spt += "slab off;\n"; // in doViewLink, for Hide

	if (!hideNow && !isolateNow) // includes Reset
	{
		// hiddenRangeStart already blanked by resetPrep() if resetNow
		// but in all other cases,
		hiddenRangeStart = "";
	}

	if (preContacts && telAvivMode)
		spt += makeEchoSpt(TargSelColorsTmp_txt);
	else if (!hideNow && !isolateNow)
		// and in all cases except Hide, blank the echo message.
		spt += makeEchoSpt(""); // to blank "Range Started at "

	if (resetNow)
	{
//		alert("jcontrol.js #25 currentView = " + currentView);
//		if (match(currentView, "makeCrystalConSpt"))
			if (symmetryLoaded)
				spt = 'load "";' + spt;

		symmetryLoaded = false;
		xtlConLoaded = false;
		unitCellLoaded = false;

		spt += clearBoxes(); // axes, unitcell, boundbox
	}

	spt += makeEchoPdbIdSpt(""); // blank parameter means get color from toggle

	// Clicking "Contacts.." always starts with nothing selected.
	if (preContacts)
	{
		clearSelectedArrays();		
		spt += "select none; define ~targ_current selected;\n";
	}

	// if centering was on, now the controls are gone, so turn it off.
	if (!centerNow)
		top.centerMode = false; // DO BEFORE SENDING SCRIPT!

	// RECORD CURRENT VIEW UNLESS ...
	if (!centerNow &&
		!preFind &&
		!resetNow &&
		!hideNow &&
		!isolateNow)
			currentView = viewLinkSptName[lnum];

	// view1Spt has undesired consequences. It starts spinning, and
	// re-zeros ~hidden_jdef?
	if (resetNow)
		currentView = "cartoonSpt";

	//	alert("jcontrol.js #7: doViewLink() viewLinkSptName[]=" + viewLinkSptName[lnum] +
	//		"\n currentView now = " + currentView);

	reportElapsed("doViewLink() handing spt to doMolViewSpt() (jcontrol.js)");

	doMolViewSpt(spt); // in doViewLink()
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// showHelp2() is called by showHelp(), as well as directly in several
// places.

function showHelp2(helpname)
{
		//	alert("jcontrol.js #8: showHelp2 receives " + helpname);

	if (helpname == "")
		return;

	helpPanel = helpname; // added in FGiJ 1.43
	
	// In some cases, the help HTML must be dynamically generated.
	// In other cases, the help HTML text is static.
	// Regardless of whether helpname is a static variable or a function,
	// the code below works.

	var prehtxt = makeHelpPrefix(helpname);

	//alert("jcontrol.js #8b: prehtxt:\n|" + prehtxt + "|");

	var htxt;
	htxt = eval("top." + helpname);

	if (typeof(htxt) == "undefined")
		htxt = top.nohelp;

//	alert("jcontrol.js #8d: htxt:\n" + htxt);

	htxt = prehtxt + htxt;

//	alert("jcontrol.js #5: " + top.helpTarget.document)

	// In most cases, add a footer with a link back to the introHelp.

	if (!match(helpname, "ntrohelp") &&
		!match(helpname, "epatienthelp") &&
		!match(helpname, "makeconsurfhelp") &&
		!match(helpname, "makebadpdbfilehelp"))
			htxt += makeHelpFooter();

 // write to the division helpDiv

	//alert("jcontrol.js #13 to helpDiv:\n" + htxt);

		helpTarget.innerHTML = htxt;

// Probably I could simply use this now:
//		top.document.getElementById('helpDiv').innerHTML = htxt;

}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function alertResetFirst(altmsg)
{
	if (typeof(altmsg) == "undefined")
		msg1 = "Please Reset before doing this operation.\n";
	else
		msg1 = altmsg;

	var msg = msg1 +
			'OK for help locating Reset (will open in new\n' +
			'tab/window). Cancel to skip help.';

	if (confirm(msg))
		window.open("where.htm#r");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function closeFgij()
{
	if (confirm(CloseWin_txt))
		top.window.close();
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function clearHidden()
{
	hiddenChains.length = 0;
	hiddenGroups.length = 0;
	hiddenAtoms.length = 0;
	hiddenRanges.length = 0;

	hiddenRangeStart = "";

	hideProtein = hideDNA = hideRNA = hideCarbohydrate = hideHydrogen = false;
	hideHaloed = false;

	hiddenTot = 0;

	invertHidden = false;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function undoIsolated()
{
	// When something is isolated, isolateMode is false (immediately after isolation).

	clearIsolated();
	var uis =
	    "select none; define ~hidden4isolate_jdef selected;" +
	    "select ~hidden4hide_jdef; define ~hidden_jdef selected;";
	if (!match(currentView, "renderend"))
		uis += centerVisibleSpt;
	reDisplay(makeEchoSpt(IsolateUndone_txt), uis);
	showHelp2("makeIsolateHelp()"); // in undoIsolated()
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function clearIsolated()
{
	isolatedDescription = "";
	isolatedAtomExpression = "";
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function invertHiding(hiddenTot)
{
	if (isolatedDescription != "")
	{
	    alert(CantInvertWhenIsolated_txt);
	    document.hideForm.invert.checked = false;
	    return;
	}

	if (hiddenTot == 0)
	{
	    alert(NothingToInvert_txt);
	    document.hideForm.invert.checked = false;
	    return;
	}

	invertHidden = true;
	hideMode = "";
	var msg = HidingIsInverted_txt;

	var ivt = document.hideForm.invert.checked;
	if (!ivt)
	{
		invertHidden = false;	
		msg = HidingNotInverted_txt;
	}
	reDisplay(makeEchoSpt(msg), "");
	showHelp2("makeHideHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function unHideAll()
{
	clearHidden();
	var uhas =
"select none; define ~hidden4hide_jdef selected;" +
	    "select ~hidden4isolate_jdef; define ~hidden_jdef selected;";
	//	uhas += centerVisibleSpt; // maybe not a good idea?
	reDisplay(makeEchoSpt(NothingRemainsHidden_txt), uhas);
	showHelp2("makeHideHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function unHideLast()
{
	var es;

	if (hideMode == "c")
	{
		es = Chain_txt + " " + hiddenChains[hiddenChains.length - 1] + " " + ReDisplayed_txt;
		hiddenChains.length = hiddenChains.length - 1;
	}
	else if (hideMode == "g")
	{
		es = ResidueGroup_txt + " " + hiddenGroups[hiddenGroups.length - 1] +  " " + ReDisplayed_txt;
		hiddenGroups.length = hiddenGroups.length - 1;
	}
	else if (hideMode == "a")
	{
		es = hiddenAtoms[hiddenAtoms.length - 1];
		es = es.substring(es.indexOf(" ")); // trim off leading serial number
		es += " " + ReDisplayed_txt;
		hiddenAtoms.length = hiddenAtoms.length - 1;
	}
	else if (hideMode == "r")
	{
		es = Range_txt + " " + hiddenRanges[hiddenRanges.length - 1] +  " " + ReDisplayed_txt;
		hiddenRanges.length = hiddenRanges.length - 1;
	}
	else alert("Programmer's error: unhideLast() with hideMode blank");

	//	runSptNow(makeDefineHiddenSpt()); // UNNEC, CALLED in doMolViewSpt()

	reDisplay("", makeEchoSpt(es)); // put echo last so not overwritten
	showHelp2("makeHideHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function reDisplay(echoSpt, trailingSpt)
{
		//		alert("jcontrol.js #32 redisplay, currentView: " + currentView);

	var rds = "# BEGIN reDisplay();\n" + echoSpt;

	rds += "define ~holdvis visible;"; // for use by centerVisible()
//	alert("jcontrol.js #12: reDisplay():\ncurrentView = " + currentView +
//		"\n useConSurfColors = " + useConsurfColors);

	rds += eval(currentView);

	if (telAvivMode) // pepsurf obeys useConsurfColors
	{
		//		alert("jcontrol.js #34: useConsurfColors = " + useConsurfColors);

		// if using ConSurf colors, recolor ConSurf chain(s)
		if (useConsurfColors)
		{
			// don't recolor pepsurf (to retain transparency as needed)
			if (!(pepsurfMode && controlPanel == "consurf"))
			{
				var ccs = makeConsurfColorsSpt(); // works for pepsurf too
//			showSptInWindow(ccs);
				rds += ccs;
			}
		} // end telAvivMode using consurf colors

		// telAvivMode, not using consurf colors
		else if (match(currentView, "consurfview"))
		{
			// color by chain only in consurfview; all other views keep their colors
			rds += 
"select not hetero;\n\
color chain;\n\
color cartoon chain;\n\
color backbone chain;\n\
";
		}

		// scripts in consurf PDB files contain obsolete/invalid command
		rds = deleteLinesContaining("list * delete", rds);

		if (match(helpPanel, "catpisb"))
			showHelp("makeCatPiSBHelp()");

	} // end TelAvivMode

	// don't obey water/ligand buttons when contactsShowing or ends
	if (!contactsShowing && !(controlPanel == "consurf" && pepsurfMode) &&
		!match(currentView, "renderend"))
	{
		// OBEY LIGANDS BUTTON
		if (toggleIsDown[ligandIndex])
		{
			// toggleDownSpt[ligandIndex]; colors cpk unconditionally
			rds += ligandClearSpt + "spacefill;\n"; 

			if (match(currentView, "precontacts"))
				rds += "color [x" + colorLigand + "];\n";
		}
		else // hide ligand
		{
			if (match(currentView, "charge"))
				rds += chargeLigandClearSpt; // leaves (protein and hetero) visible for charge view
			else
				rds += ligandClearSpt; // clears		
		}

		// OBEY WATER BUTTON
		if (toggleIsDown[waterIndex])
		{
			var watrad = "";
			if (waterIsSmall)
				watrad = smallWaterRadius;
			rds += "select water; spacefill " + watrad + ";\n"; // don't change color
		}
		else
			rds += "restrict not water;\n";
	}

	rds += trailingSpt; // e.g. center, echo
	rds += "# END reDisplay();\n";

	//	alert("jcontrol.js #31 reDisplay() returns rds:\n" + rds);

	if (match(rds, "list"))
		alert("jcontrol.js #33 reDisplay rds contains 'list':\n" + rds);

	doMolViewSpt(rds); // in reDisplay()
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function centerVisible()
{
// FGiJ thru 2.1
//	reDisplay(makeEchoSpt(VisibleChainsCentered_txt),
//		"select (" + proteinSpt + ", nucleic) and not ~hidden_jdef;\n" +
//		"center selected;\n");

	var cvs =	"restrict ~holdvis;" + centerVisibleSpt; // ~holdvis is defined in reDisplay()

	reDisplay(makeEchoSpt(VisibleCentered_txt), cvs);

}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function centerContacting()
{
	var ccs = "center ~cont_current;\n";

	ccs += makeEchoSpt(VisibleContactingAtomsCentered_txt);

	doMolViewSpt(ccs);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeIsolateSpt()
{
	var isos = "";

	if (isolatedDescription == "")
	{
		isos += "select none;\n";
		isos += "define ~hidden4isolate_jdef selected;\n";
	}
	else
	{
		isos += "select " + isolatedAtomExpression + ";\n";
		isos += "restrict selected;\n";
		isos += "select not selected;\n";
		isos += "define ~hidden4isolate_jdef selected;\n";

//		isos += "isosurface gm* delete;\n" // otherwise, the stray ones linger
//		isos += "delay 1;\n";
	}

	isos += "select ~hidden4isolate_jdef or ~hidden4hide_jdef;\n";
	isos += "define ~hidden_jdef selected;\n";

//		alert ("jcontrol.js #29 isolateMode=" + isolateMode); // ALWAYS FALSE HERE
	// don't auto-center after initial isolation, e.g. when manual centering is done
	//	alert ("jcontrol.js #30: oldIsolatedDescription=" + oldIsolatedDescription +
	//				 "\n isolatedDescription=" + isolatedDescription +
	//				 "\n centerVisibleSpt=" + (oldIsolatedDescription != isolatedDescription));
	if (oldIsolatedDescription != isolatedDescription && !match(currentView, "renderend"))
	{
	    isos += centerVisibleSpt; // now includes isosurface gm* delete
	    oldIsolatedDescription = isolatedDescription;
	}

	return isos;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeHideSpt()
{
	var hs = makeDefineHiddenSpt(); // makes a script that does the hiding
		// using restrict commands, and
		// defines ~hidden_jdef.

	if (hiddenRangeStart != "") // mark with [
	{
		hs +=
			"select " + hiddenRangeStart + ";\n" +
			"set labeloffset 0 0;\n" +
			"label [;\n" +
			"set fontsize 20;\n";

		if (toggleIsDown[backgroundIndex])
			hs += "color labels black;\n";
		else
			hs += "color labels white;\n";
	}

	if (hs.length > 0)
	hs = "# makeHideSpt();\n" + hs;

	return hs;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeDefineHiddenSpt()
{
	var hs = makeSelectHiddenSpt(); // 'select none' if nothing.

//	alert("jcontrol.js #27 hide spt:\n" + hs);

	// this should make it unnecessary to call getHiddenTot all over the place.
	// but I didn't remove all those calls (FGiJ 2.2).
	// see also anyHidden() re: getHiddenTot() and isolatedDescription,
	// and clearHidden().
	hiddenTot = getHiddenTot();

	if (hiddenTot > 0)
	{
		if (!invertHidden)
		{
			hs += "define ~hidden4hide_jdef selected;\n";
			hs += "restrict not selected;\n"; // makeHideSpt() HIDE
		}
		else // INVERTED
		{
			hs += "restrict selected;\n"; // makeHideSpt() INVERT
			hs += "select not selected;\n";
			hs += "define ~hidden4hide_jdef selected;\n";
		}
	}
	else // CLEAR TO ZERO HIDDEN! NEEDED FOR EMPTY BASKETS / BROKEN ENDS
		hs += "define ~hidden4hide_jdef selected;\n"; // makeHideSpt() NONE HIDDEN

	hs += "select ~hidden4hide_jdef or ~hidden4isolate_jdef;\n";
	hs += "define ~hidden_jdef selected;\n";

	//alert("jcontrol.js #37 makeDefineHiddenSpt() returns:\n" + hs);

	return hs;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeSelectHiddenSpt()
{
	var hs = "# makeSelectHiddenSpt();\n" +
		"select none;\n";

	var ih;
	if (hiddenChains.length > 0)
	{
		// Changing from 'restrict not' to 'select selected or' to enable
		// centerVisible();

		if (hiddenChains[0].length > 1)
		{
			if (hiddenChains[0] == "Protein")
				hs += "select selected or ((" + proteinSpt + ") and not hetero);\n";
			else
				hs += "select selected or (nucleic and not hetero);\n";
		}
		else
		{
			hs += "select selected or ((";
			for (ih = 0; ih < hiddenChains.length; ih++)
			{
				if (ih > 0)
					hs += ",";
				hs += ":" + hiddenChains[ih];
			}
			hs += ") and not hetero);\n";
		}
	}
	if (hiddenGroups.length > 0)
	{
		// This is to workaround a bug in Jmol 10.00.48.
		// Should be fixed in a future Jmol release.
		hs += "set bondmode or;\n";

		hs += "select selected or (";
		for (ih = 0; ih < hiddenGroups.length; ih++)
		{
			if (ih > 0)
				hs += ",";
			hs += hiddenGroups[ih];
		}
		hs += ");\n";
	}
	if (hiddenAtoms.length > 0)
	{
		// This is to workaround a bug in Jmol 10.00.48.
		// Should be fixed in a future Jmol release.
		hs += "set bondmode or;\n";

		for (ih = 0; ih < hiddenAtoms.length; ih++)
		{
//			alert("jcontrol.js #22 hiddenAtoms[" + ih + "]=" + hiddenAtoms[ih]);

			// hide all atoms
			hs += "select selected or " + firstWord(hiddenAtoms[ih]) + ";\n"
		}
	}
	for (ih = 0; ih < hiddenRanges.length; ih++)
	{
		hs += "select selected or " + hiddenRanges[ih] + ";\n";
	}

	if (hideProtein)
		hs += "select selected or (~protein and not hetero);\n";
	if (hideDNA)
		hs += "select selected or (DNA and not hetero);\n";
	if (hideRNA)
		hs += "select selected or (RNA and not hetero);\n";
	if (hideCarbohydrate)
		hs += "select selected or " + carbohydrateSpt + ";\n";
	if (hideHydrogen)
		hs += "select selected or hydrogen;\n";
	if (hideHaloed)
		hs += "select selected or (" + toFindHidden + ");\n";

//	hs += "define ~hidden_jdef selected;\n"; NOW DONE IN makeDefineHiddenSpt()

	return hs;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function showContacts()
{
	if ((selectedChains.length + selectedGroups.length + selectedAtoms.length
		+ selectedFound.length + selectedRanges.length == 0) &&
		!selectedWater)
		{
			alert(BeforeContactsCanBe_txt);
			return;
		}

	if (telAvivMode)
	{
		useConsurfColors = true;
		colorContactsTargetGray = true;
	}

	selectMode = "";

	// flags that affect other views are also set in doViewLink(), namely
	// contactsShowing and markContactsTargets (maybe redundant here)?
	contactsShowing = true;
	markContactsTargets = true;

	// flags that affect only contacts are set here

	targetSF = contactingSF = true;
	targetCPK = contactingCPK = false;

	backboneContacts = true;
	hydrogensContacts = false;
	labelContacts = false;

	var spt = makeGenerateContactsSpt();
	if (telAvivMode)
		spt += makeEchoSpt(serverName + " " + ColorsRestored_txt);

	doMolViewSpt(spt);
	currentView = "makeContactsViewSpt(false, false)";

	showHelp("makeContactsShownHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function toggleAxes()
{
	if (document.setForm.axes.checked)
	{
		runBareSpt("set axes on;\n");
		axesOn = true;
	}
	else
	{
		runBareSpt("set axes off;\n");
		axesOn = false;
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function toggleBoundbox()
{
	if (document.setForm.boundbox.checked)
	{
		runBareSpt("set boundbox on;\n");
		boundboxOn = true;
	}
	else
	{
		runBareSpt("set boundbox off;\n");
		boundboxOn = false;
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
/*
function toggleUnitcell()
{
	var ducs = "";
	if (document.setForm.unitcell.checked)
	{
		ducs += "set unitcell on;\n";
		ducs += "set echo top left; echo;\n";
		unitcellOn = true;
	}
	else
	{
		ducs += "set unitcell off;\n";
		unitcellOn = false; // must be before makeEchoPdbIdSpt()!
		ducs += makeEchoPdbIdSpt("");
	}

//	alert(ducs);
	runBareSpt(ducs); // in toggleUnitcell()
}
*/
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function getHiddenTot()
{
	var hiddenTot =
		hiddenChains.length +
		hiddenGroups.length +
		hiddenAtoms.length +
		hiddenRanges.length;

	if (hideProtein) hiddenTot++;
	if (hideDNA) hiddenTot++;
	if (hideRNA) hiddenTot++;
	if (hideCarbohydrate) hiddenTot++;
	if (hideHydrogen) hiddenTot++;
	if (hideHaloed) hiddenTot++;

	return hiddenTot;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function changeContactsBackbones()
{
	backboneContacts = top.document.contactsForm.contactsBackbones.checked;
	if (backboneContacts)
		doMolViewSpt(showContactsBackbonesSpt);
	else
		doMolViewSpt(hideContactsBackbonesSpt);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function changeContactsTargetsMarks()
{
	var conhal = top.document.contactsForm.markContactsTargets.checked;
	if (conhal)
		markContactsTargets = true;
	else
		markContactsTargets = false;
	doMolViewSpt("");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function hideMonitors()
{
	doMolViewSpt("monitors off;");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function changeSlabThickness()
{
	var thk = getRadioValue(top.document.slabForm.slabThickness);	
	slabThickness = thk;

	slabDepthZero = top.document.slabForm.slabDepthZero.checked;

	doMolViewSpt(makeSlabSpt(false));

}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function changeLabelSize()
{
	var labsiz = getRadioValue(top.document.labelForm.labelSize);	
	labelSize = labsiz;

	labelsWhite = top.document.labelForm.labelsWhite.checked;

  doMolViewSpt(""); //makeLabelAllSpt())
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function doFind() // gets query from form slot. findIt() does a string.
{
//	alert("jcontrol.js #19a entering doFind()");

	// GET QUERY FROM FORM SLOT
	var find = document.findForm.toFind.value;

	findIt(find);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function findNoHelp(query)
{
	// If query contains "occupancy", then hoverSpt will not be reset in doMolViewSpt();

	toFind = toFindShown = query;
	doMolViewSpt("");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function clearFindNoHelp()
{
	findNoHelp("");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function findIt(find)
{

	// DISALLOW DOUBLE QUOTES (SINGLE QUOTES UNDECIDED)
	// makeFindSpt() puts toFind in double quotes. (Is this necessary?)
	if (find.charAt(0) == "\"")
	{
		alert("Sorry but double quotes are not permitted.\n" +
			"Please rephrase your search.");
		return;
	}

	// CHANGE CASE TO UPPER
	if (!useLowerCaseChains)
		find = find.toUpperCase();

	// SINGULARIZE SPACES
	while (find.indexOf("\ \ ") != -1)
		find = find.replace(/\ \ /g, " ");

	// SPACES ARE NECESSARY FOR E.G. BOOLEAN AND/OR

// THIS WOULD DEFEAT " and " / " or "
//	if (!quoted)
//	{
//		// GUARANTEE COMMA BEFORE EVERY SPACE
//		var is;
//		for (is = 0; is < find.length; is++)
//			if (find.charAt(is) == " " && is > 0)
//				if (find.charAt(is - 1) != ",")
//					find = find.substring(0, is) + "," + find.substring(is);
//	}

	// REMOVE SPACES BEFORE AND AFTER EQUAL IN SEQUENCE=
	// spaces were singularized above
	var seqeq = "SEQUENCE=";
	find = find.replace(/SEQUENCE = /gi, seqeq); // i for case insensitive!
	find = find.replace(/SEQUENCE =/gi, seqeq); // i for case insensitive!

	// REMOVE SPACES BEFORE AND AFTER EQUAL IN CHAIN=
	// for 14.1.14 chainbug (chain=a fails but :a works)
	// spaces were singularized above
	var chneq = "CHAIN=";
	find = find.replace(/CHAIN = /gi, chneq); // i for case insensitive!
	find = find.replace(/CHAIN= /gi, chneq); // i for case insensitive!
	find = find.replace(/CHAIN =/gi, chneq); // i for case insensitive!

	// ADD "AND NOT SYMMETRY" FOR XTLCON
	if (xtlConLoaded && !match(find, "symmetry"))
	{
		find = "(" + find + ") AND NOT SYMMETRY";
	}

	// SEPARATE THE DISPLAYED QUERY FROM THE JMOL COMMAND
	
	toFindShown = find;

	// CHANGE CHAIN= TO : IN find BUT NOT IN toFindShown for 14.1.14 chainbug
//	find = find.replace(/CHAIN=/gi, ":");

	// REWRITE QUERY WITHOUT QUOTES INTO SLOT
	// this may be unnecessary as makeFindHelp() rewrites the form
//	document.findForm.toFind.value = toFindShown;

	// PROCESS SEQUENCE= QUERY
	// possible queries: (keit is in 4b14)
	// sequence = keit 
	// sequence = keit and chain = a
	// chain = b and sequence = rgd and *.ca
	// sequence = keit, sequence = rgd

//	alert("jcontrol.js #21b, toFind for jmol:\n" + find);

	var iseqeq;
	var sqcount = 0;
	findSequence = "";
	while((iseqeq = find.indexOf(seqeq)) != -1)
	{
		sqcount++;

		// find end of sequence at space, comma, or close parenthesis.
		var ispace = find.indexOf(" ", iseqeq + 1);
		var icomma = find.indexOf(",", iseqeq + 1);
		var iparen = find.indexOf(")", iseqeq + 1);

		// find end closest to sequence=
		var iseqend = ispace;

		if (iseqend == -1)
			iseqend = icomma;
		else if (icomma != -1 && iseqend > icomma)
			iseqend = icomma;

		if (iseqend == -1)
			iseqend = iparen;		
		else if (iparen != -1 && iseqend > iparen)
			iseqend = iparen;

		if (iseqend == -1)
				// end at end of query
				iseqend = find.length;

//		alert("jcontrol.js #21c, iseqend=" + iseqend);

		var findhead = find.substring(0, iseqeq);
		findSequence = find.substring(iseqeq + seqeq.length, iseqend);
		var findtail = find.substring(iseqend);
		find = findhead + "within('" + findSequence + "', all)" + findtail;

//		alert("jcontrol.js #21, toFind for jmol:\n" + find);
	}
	if (sqcount > 1)
		findSequence = "";

	// SEQUENCES: OFFER TO FIND ONLY ONE ATOM PER RESIDUE
	if (sqcount >= 1)
		if (confirm("Find only one atom per matching amino acid\n" +
			"(alpha carbon) or nucleotide (pentose C5')?\n" +
			"(CANCEL to find ALL matching atoms.)"))
			find = "(" + find + ") and (*.ca, *.c5')";

	// find it
	toFind = find;

	// makeFindSpt() sets background black if (forceBackgroundBlack):
	// Each doFind() forces the background to black.
	// But after the halos are rendered, subsequent refreshes don't force
	// the background, so user has control.
	setButtonState("up", backgroundIndex);
	forceBackgroundBlack = true;

//	alert("jcontrol.js #19 ready to execute find");

	// FGiJ 2.42: now using jmolScriptWait so setting foundAtomCount to -1
	// needs to be done BEFORE the find script is executed.
	//
	// THIS OCCURS BEFORE JMOL HAS COMPLETED THE SCRIPT,
	// SO THE SCRIPT HAS JAVASCRIPT CALLS TO SET THE COUNTS,
	// AND updateFoundReport() WATCHES FOR THOSE TO BE COMPLETED.
	// get found counts
	//	foundAtomCount = jmolEvaluate("{selected}.count");

	foundAtomCount = -1;

	doMolViewSpt("#noscript FINDIT;"); // makeFindSpt() is called automatically when toFind
	// is not blank.

	// This is needed for large molecules to show the new query while finding.
	showHelp2("makeFindHelp()"); // FG 2.75: use updateFoundReport()

	// put cursor in slot and select contents of slot
	setTimeout("document.findForm.toFind.select()", 100);

	updateFoundReport(); // NO LONGER NEEDED FGIJ 2.4

}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function updateFoundReport()
{
//	alert("jcontrol.js #20 foundAtomCount=" + foundAtomCount);

  // Clearing toFind in the Find dialog was causing updateFoundReport(), which recursed
  // waiting for foundAtomCount to be not -1, to go into an infinite loop. Hence
  // instead of the recursive strategy, I tried jmolScriptWait for ALL scripts
	// unchangedScriptToJmol (in top.js).

	if (foundAtomCount < 0)
		setTimeout("updateFoundReport()", 300);
	else
		showHelp2("makeFindHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function setButtonState(state, ibutt)
{
//	alert("jcontrol.js #9 setButtonState(" + state + ", " + ibutt + ")");
//	alert("jcontrol.js #16 controlPanel is " + controlPanel);

	// search for "buttonoffset"
	// cptab 0: for molecule tab, ibutt starts at 100
	// cptab 1: for tab I Views, ibutt starts at 1
	// cptab 2: for tab II Tools, ibutt starts at 10

	var ibutt0; 
	var ibutt1;
	var ibutt2;

	// ibutt can come from any control panel so can be 0 to 100+

	if (ibutt < 10) // from cp1, 1+
	{
		ibutt0 = ibutt + 100;
		ibutt1 = ibutt;
		ibutt2 = ibutt + 10;
	}
	else if (ibutt >= 10 && ibutt < 20) // from cp2, 10+
	{
		ibutt2 = ibutt;
		ibutt1 = ibutt2 - 10;
		ibutt0 = ibutt1 + 100;
	}
	else // from cp0, 100+
	{
		ibutt0 = ibutt;
		ibutt1 = ibutt0 - 100;
		ibutt2 = ibutt1 + 10;
	}

	if (controlPanel == "fg" &&
		ibutt1 != backgroundIndex && ibutt1 != spinIndex && ibutt1 != qualityIndex)
			ibutt0 = -1; // ibutt0 is not on the molecule tab

	// consurf is cp1, 1+ BUT I DON'T THINK THIS CODE COULD EVER BE USED
	// SINCE CONSURF CAN'T INITIATE THE OTHER BUTTONS
	if (controlPanel == "consurf" &&
		ibutt1 != backgroundIndex && ibutt1 != spinIndex && ibutt1 != qualityIndex)
			ibutt1 = -1; // ibutt is not on the consurf panel

//	alert("jcontrol.js #18: ibutt=" + ibutt +
//		" ibutt0=" + ibutt0 +
//		" ibutt1=" + ibutt1 +
//		" ibutt2=" + ibutt2);

	// we always have a cp1
	// consurf uses ibutt1 only (cptab is 1).
	if (ibutt1 != -1)
		set1ButtonState(state, ibutt1);

	if (controlPanel == "fg")
	{
		if (ibutt0 != -1)
			set1ButtonState(state, ibutt0);

		set1ButtonState(state, ibutt2);
	}

	if (controlPanel == "consurf") // added for fgij 2.33
	{
			setAllToggleButtons(ibutt, state);
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function set1ButtonState(state, ibutt)
{
//	alert("jcontrol.js #15: set1ButtonState(state=" + state +
//		" ibutt=" + ibutt + ")");

	var imgnum = eval("document.toggle" + ibutt);

//	alert("jcontrol.js #15a: imgnum=" + imgnum);

	if (state == "up")
	{
		toggleIsDown[ibutt] = false;
		imgnum.src = "up.gif";		
	}
	else
	{
		toggleIsDown[ibutt] = true;
		imgnum.src = "down.gif";		
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// setAllToggleButtons() sets the flags but not the images.
// Designed for use by ConSurf for water, when there is no water button showing.
function setAllToggleButtons(buttindex, setting)
{
	toggleIsDown[buttindex] = setting; // cp1
	toggleIsDown[buttindex + 10] = setting; // cp2
	toggleIsDown[buttindex + 100] = setting; // cp0, not always applicable but harmless
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function changeContactsView()
{
	// this change is initiated from the form, so
	// true1 = read radio buttons
	// true 2 = read checkboxes
	doMolViewSpt(makeContactsViewSpt(true, true));
	showHelp2("makeContactsShownHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// setContactsView(vw) sets one of four preset views from snapshots
// in the contacts shown help.

function setContactsView(vw)
{
	var tailSpt = makeEchoPdbIdSpt("");
	if (vw == 1)
	{
		targetSF = true;
		contactingSF = true;
		targetCPK = false;
		contactingCPK = false;		
	}
	else if (vw == 2)
	{
		targetSF = true;
		contactingSF = false;
		targetCPK = false;
		contactingCPK = false;		
	}
	else if (vw == 3)
	{
		targetSF = true;
		contactingSF = false;
		targetCPK = true;
		contactingCPK = true;
	}
	else if (vw == 4)
	{
		targetSF = false;
		contactingSF = false;
		targetCPK = true;
		contactingCPK = true;
		tailSpt = makeEchoMsgSpt(DoubleClicktoMeasure_txt,
			'tl', '16', '[xff4040]'); // tl = top left
	}

	// preset views force radio buttons, so
	// false = don't read radio buttons
	// true = read checkboxes
	doMolViewSpt(makeContactsViewSpt(false, true) + tailSpt);
	showHelp2("makeContactsShownHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function toggleContactsRadioButtons()
{
	var showrad = top.document.contactsForm.contactsRadioButtons.checked;	
	if (showrad)
		contactsRadioViews = true;
	else
		contactsRadioViews = false;
	showHelp2("makeContactsShownHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function clearFindForm()
{
	document.findForm.toFind.value = "";
	doFind();
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function changePreContactsView()
{
	// SPACEFILL OR CARTOON
	preContactsView = getRadioValue(document.contactsForm.pCView);

	// SELECT FOUND?
	var fc = document.contactsForm.selectFound.checked;

	if (fc && toFind.length == 0)
	{
		firstUseFind();
		document.contactsForm.selectFound.checked = false;
		return;
	}

	if (fc)
		selectedFound = toFind;
	else
		selectedFound = "";

//	alert("jcontrol.js #26 selectedFound:\n" + selectedFound);

	// REGENERATE ~targ_current (selectedFound does not use pickCallback)
	// with makeSelectSpt()

	// REGENERATE VIEW
	doMolViewSpt(makeSelectSpt() + makePreContactsSpt());
	showHelp2("makePreContactsHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function cancelCenteringNoHelp()
{
	if (centerMode)
	{
		centerMode = false;
		doMolViewSpt(setPickingIdentSpt); // cancels set picking center
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function changePreContactsWater(tailSpt)
{
	var pcw = top.document.contactsForm.preContactsWater.checked;
	preContactsWater = pcw;
	var pcws = "";

	if (pcw)
	{
		pcws = "select water and not hydrogen; color [x" + colorSolvent + "]; spacefill;\n";
		setButtonState("down", waterIndex);
	}
	else
	{
		pcws = "select water; spacefill off;\n";
		setButtonState("up", waterIndex);
	}

	doMolViewSpt(pcws + tailSpt);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function cancelSelectedRange()
{
	selectedRangeStart = "";
	doMolViewSpt(makeSelectSpt()); // to reset ~targ_current
	showHelp2("makePreContactsHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function cancelHiddenRange()
{
	if (hiddenRangeStart == "")
		return;
	cancelHiddenRangeNoHelp();
	showHelp2("makeHideHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function cancelHiddenRangeNoHelp()
{
	if (hiddenRangeStart == "")
		return;
	hiddenRangeStart = "";
	doMolViewSpt(makeEchoSpt("")); // to blank "Range Started at "
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function isStdAA(aaq)
{
	aaq = "" + aaq.toUpperCase();
//	alert("jcontrol.js #10: isStdAA receives " + aaq);

	switch (aaq)
	{
		case ("ALA"):
		case ("ARG"):
		case ("ASN"):
		case ("ASP"):
		case ("CYS"):
		case ("GLN"):
		case ("GLU"):
		case ("GLY"):
		case ("HIS"):
		case ("ILE"):
		case ("LYS"):
		case ("LEU"):
		case ("MET"):
		case ("PHE"):
		case ("PRO"):
		case ("SER"):
		case ("THR"):
		case ("TRP"):
		case ("TYR"):
		case ("VAL"):
			return true;
		default:
			return false;
	}	
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// PDB format 3.1: A,C,G,T,U,I, and Dx for all those!
// (See HET in http://www.wwpdb.org/documentation/format3.1-20070719.pdf)

function isStdNucleotide(nq)
{
	nq = "" + nq.toUpperCase();
//	alert("jcontrol.js #11: isStdNucleotide receives " + nq);

	switch (nq)
	{
		case ("A"):
		case ("C"):
		case ("G"):
		case ("I"):
		case ("T"):
		case ("U"):
		case ("DA"):
		case ("DC"):
		case ("DG"):
		case ("DI"):
		case ("DT"):
		case ("DU"):
			return true;
		default:
			return false;
	}	
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function changePreContactsWaterTarget()
{
	selectedWater = document.contactsForm.preContactsWaterTarget.checked;

	if (selectedWater)
		top.document.contactsForm.preContactsWater.checked = true;

	changePreContactsWater(makeSelectSpt());
	showHelp2("makePreContactsHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// The purpose of showCatPiSB() is to be called when the form in the
// CatPiSB help panel is changed.

function showCatPiSB(preSpt)
{
	setButtonState("down", backgroundIndex); // white background initially
	setButtonState("up", ligandIndex); // ligands not shown initially
	setButtonState("up", waterIndex); // water not shown initially

	doMolViewSpt(preSpt + makeCatPiSBSpt(pollForm)); // uses ~cont_catpi etc. etc.
	showHelp("makeCatPiSBHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// The purpose of showSSBonds() is to be called when the form in the
// SSBonds help panel is changed.

function showSSBonds(preSpt)
{
	setButtonState("up", backgroundIndex); // black background initially
	setButtonState("up", ligandIndex); // ligands not shown initially
	setButtonState("up", waterIndex); // water not shown initially

	doMolViewSpt(preSpt + makeSSBondsSpt(pollForm));

	showHelp("makeSSBondsHelp()"); // using current form settings
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// The purpose of showUncertainty() is to be called when the form in the
// uncertainty help panel is changed.

function showUncertainty()
{
	doMolViewSpt(makeUncertaintySpt(pollForm));

	showHelp("makeUncertaintyHelp(obeyRelativeUncertainty)");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function clearBoxes()
{
	var spt = "";
	if (axesOn)
	{
		axesOn = false;
		spt += "set axes off;\n";
	}
	if (unitcellOn)
	{
		unitcellOn = false;
		spt += "set unitcell off;\n";
	}
	if (boundboxOn)
	{
		boundboxOn = false;
		spt += "set boundbox off;\n";
	}
	return spt;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function resetPrep()
{
	toFind = ""; // must be before help!
	toFindShown = "";
	findSequence = "";
	foundAtomCount = -1;
	clearHidden();
	clearIsolated();
	markBrokenEnds = true;
	waterIsSmall = false;
	ligandIsSmall = false;
	rocketMode = "j";

	resetPrepConsurf();

	resetLabelCheckboxes();
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function resetPrepConsurf() // keeps hidden and found=halos
{
	showCatPi = false;
	colorCatPiSBChain = false;
	resetContacts();

	// avoid hiding default FG view on Reset
	processHeaderBeforeMolView = false; // needed only for initial load
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function doAnomalousAtoms()
{
	showAnomalous = document.anomalousForm.showAA.checked;
	var rendAA = getRadioValue(document.anomalousForm.renderAA);
	anomalousDots = (rendAA == "d");

//	doMolViewSpt("");
	reDisplay("", "");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function resetContacts()
{
	markContactsTargets = true;
	targetSF = true;
	preContactsView = "sf"; // must be done before showing help
	preContactsWater = false;
	selectedWater = false;
	labelContacts = false;

	showContactsHBonds = true;
	showContactsMeMi   = true;
	showContactsHphob  = true;
	showContactsSB     = true;
	showContactsCatPi  = true;
	showContactsSticks = true;
	showContactsWater  = true;
	showWaterBridges   = true;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function showFGControls(fromx) // for ConSurf
{
	// alert("huh?"); this is not called when not consurf!

	clearControls();
	setupControlPanelTabs();

	if (fromx == "fromConsurf")
	{
		useConsurfColors = true;
		showHelp("makeFGFromConsurfHelp()");
	}
	else	
		showHelp("makeIntroHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function clearControls() // for showFGControls() <--> showConsurfControls()
{
	// don't clear toggle button arrays; they persist between control panels!

	// don't clear view link arrays because the indices persist!

	cancelCenteringHidingPreContacts();

	contactsShowing = false; // cannot return to contacts controls

	// portions hidden or haloed remain in either transition.
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// leaves the current view intact, hidden hidden,
// and if contacts are showing, leaves those as well.

function cancelCenteringHidingPreContacts()
{
	cancelCenteringNoHelp(); // centerMode false + set picking ident
	
	// don't hide new things clicked but leave hidden things hidden
	hideMode = "";

	// Blanking selectMode means that when something is clicked, all target
	// marks disappear (and clicked is identified) and the pre-contacts
	// help will not be displayed. SEE CANCEL.TXT.
	selectMode = "";

	doMolViewSpt(""); // hides marks on targets
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function returnToContacts()
{
	// can't use clearControls() b/c it clears contactsShowing!
	cancelCenteringNoHelp(); // centerMode false + set picking on
	hideMode = "";

	showHelp("makeContactsShownHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function toggleLabelsShow()
{
	labelsOn = !labelsOn;

	document.moltabForm.cklsho0.checked = labelsOn;
	document.controlsForm.cklsho1.checked = labelsOn;
	document.control2Form.cklsho2.checked = labelsOn;
	document.control3Form.cklsho3.checked = labelsOn;

	var msg = LabelsHidden_txt;

	if (labelsOn)
		msg = LabelsRedisplayed_txt;

	reDisplay(makeEchoSpt(msg), "");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function toggleLabelsFront()
{
	labelsFront = !labelsFront;

	document.moltabForm.cklf0.checked = labelsFront;
	document.controlsForm.cklf1.checked = labelsFront;
	document.control2Form.cklf2.checked = labelsFront;
	document.control3Form.cklf3.checked = labelsFront;

	var msg = SomeLabelsMayBeHidden_txt;

//	var tailspt = "set labelsFront off;\n";
	var tailspt = "select all;\n set labelGroup;\n"; // not labelsGroup!

	if (labelsFront)
	{
		msg = AllLabelsVisibleAtFront_txt;

//		tailspt = "set labelsFront on;\n";
		tailspt = "select all;\n set labelFront;\n"; // not labelsFront!
	}

	//	if (!labelsOn)
	//		msg = checkToShowLabelsMsg;
	if (!labelsOn && !labelSequenceNumbers && !labelResidueNames3 && !labelResidueNames1)
			msg = noLabelsOn_txt;

	reDisplay(makeEchoSpt(msg), tailspt);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function toggleLabelsID()
{
	labelsID = !labelsID;

	// ALERT if Labels are off
	if (!labelsOn)
	{
		alert("Residues marked S-, X or ? cannot\nbe identified until you check Labels: Show.");

		document.moltabForm.cklid0.checked = false;
		document.controlsForm.cklid1.checked = false;
		document.control2Form.cklid2.checked = false;
		document.control3Form.cklid3.checked = false;

		return;
	}

	document.moltabForm.cklid0.checked = labelsID;
	document.controlsForm.cklid1.checked = labelsID;
	document.control2Form.cklid2.checked = labelsID;
	document.control3Form.cklid3.checked = labelsID;

	var msg = IDsOfLabeledAtomsHidden_txt;

	if (labelsID)
		msg = LabeledAtomsIDd_txt;

	if (!labelsOn)
		msg = checkToShowLabelsMsg;

	reDisplay(makeEchoSpt(msg), "");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
var seqNumResNamUnchecked = false;

function toggleLabelSequenceNumbers() // toggleSequenceNumbers
{
	labelSequenceNumbers = !labelSequenceNumbers;

	document.moltabForm.ckseqnum0.checked = labelSequenceNumbers;
	document.controlsForm.ckseqnum1.checked = labelSequenceNumbers;
	document.control2Form.ckseqnum2.checked = labelSequenceNumbers;
	document.control3Form.ckseqnum3.checked = labelSequenceNumbers;

	var msg = SequenceNumbersHidden_txt;

	if (labelSequenceNumbers)
		msg = SequenceNumbersShown_txt;

	reDisplay(makeEchoSpt(msg), "");

	// IF SEQNUMRESNAM HELP IS CURRENTLY SHOWING, CHANGE ITS TITLE
	if (labelSequenceNumbers ||
			((labelResidueNames1 || labelResidueNames3) && match(helpPanel, "seqnumresnam")))
			showHelp2("makeLabelSeqNumResNamHelp()");

	// IF ALL TURNED OFF AND HELP IS SEQNUMRESNAM, RETURN HELP TO INTRO
	// Otherwise, toggling background leaves seqnum help with no title!
	if (!labelSequenceNumbers && !labelResidueNames1 && !labelResidueNames3 &&
		match(helpPanel, "seqnumresnam"))
	{
		seqNumResNamUnchecked = true;
		showHelp('makeIntroHelp()');
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//toggleresiduenames

function toggleLabelResidueNames3()
{
	labelResidueNames3 = !labelResidueNames3;

	document.moltabForm.ckresnam30.checked = labelResidueNames3;
	document.controlsForm.ckresnam31.checked = labelResidueNames3;
	document.control2Form.ckresnam32.checked = labelResidueNames3;
	document.control3Form.ckresnam33.checked = labelResidueNames3;

	var msg = ResidueNamesHidden_txt;

	if (labelResidueNames3)
		msg = ResidueNamesShown3_txt;

	else if (labelResidueNames1)
		msg = ResidueNamesShown1_txt;

	reDisplay(makeEchoSpt(msg), "");

	if (labelResidueNames3 ||
			(labelSequenceNumbers && match(helpPanel, "seqnumresnam")))
		showHelp2("makeLabelSeqNumResNamHelp()");

	// IF ALL TURNED OFF AND HELP IS SEQNUMRESNAM, RETURN HELP TO INTRO
	// Otherwise, toggling background leaves seqnum help with no title!
	if (!labelSequenceNumbers && !labelResidueNames1 && !labelResidueNames3 &&
		match(helpPanel, "seqnumresnam"))
	{
		seqNumResNamUnchecked = true;
		showHelp('makeIntroHelp()');
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function toggleLabelResidueNames1()
{
	labelResidueNames1 = !labelResidueNames1;

	document.moltabForm.ckresnam10.checked = labelResidueNames1;
	document.controlsForm.ckresnam11.checked = labelResidueNames1;
	document.control2Form.ckresnam12.checked = labelResidueNames1;
	document.control3Form.ckresnam13.checked = labelResidueNames1;

	var msg = ResidueNamesHidden_txt;

	if (labelResidueNames1)
		msg = ResidueNamesShown1_txt;

	else if (labelResidueNames3)
		msg = ResidueNamesShown3_txt;

	reDisplay(makeEchoSpt(msg), "");

	if (labelResidueNames1 ||
		(labelSequenceNumbers && match(helpPanel, "seqnumresnam")))
			showHelp2("makeLabelSeqNumResNamHelp()");

	// IF ALL TURNED OFF AND HELP IS SEQNUMRESNAM, RETURN HELP TO INTRO
	// Otherwise, toggling background leaves seqnum help with no title!
	if (!labelSequenceNumbers && !labelResidueNames1 && !labelResidueNames3 &&
		match(helpPanel, "seqnumresnam"))
	{
		seqNumResNamUnchecked = true;
		showHelp('makeIntroHelp()');
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// search for "buttonoffset"

function buttonIs(ibutt, funcIndex)
{
	if (ibutt == funcIndex || ibutt == (funcIndex + 10)
		|| ibutt == (funcIndex + 100))
		return true;
			
	else return false;		
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function anyHidden()
{
	var hiddenTot = getHiddenTot();
	return (hiddenTot || isolatedDescription != "");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function resetLabelCheckboxes()
{
	labelsOn = true;

	document.moltabForm.cklsho0.checked = labelsOn;
	document.controlsForm.cklsho1.checked = labelsOn;
	document.control2Form.cklsho2.checked = labelsOn;
	document.control3Form.cklsho3.checked = labelsOn;

	labelsFront = false;

	document.moltabForm.cklf0.checked = labelsFront;
	document.controlsForm.cklf1.checked = labelsFront;
	document.control2Form.cklf2.checked = labelsFront;
	document.control3Form.cklf3.checked = labelsFront;

	labelsID = false;

	document.moltabForm.cklid0.checked = labelsID;
	document.controlsForm.cklid1.checked = labelsID;
	document.control2Form.cklid2.checked = labelsID;
	document.control3Form.cklid3.checked = labelsID;

	labelSequenceNumbers = false;

	document.moltabForm.ckseqnum0.checked = labelSequenceNumbers;
	document.controlsForm.ckseqnum1.checked = labelSequenceNumbers;
	document.control2Form.ckseqnum2.checked = labelSequenceNumbers;
	document.control3Form.ckseqnum3.checked = labelSequenceNumbers;

	labelResidueNames3 = false;

	document.moltabForm.ckresnam30.checked = labelResidueNames3;
	document.controlsForm.ckresnam31.checked = labelResidueNames3;
	document.control2Form.ckresnam32.checked = labelResidueNames3;
	document.control3Form.ckresnam33.checked = labelResidueNames3;

	labelResidueNames1 = false;

	document.moltabForm.ckresnam10.checked = labelResidueNames1;
	document.controlsForm.ckresnam11.checked = labelResidueNames1;
	document.control2Form.ckresnam12.checked = labelResidueNames1;
	document.control3Form.ckresnam13.checked = labelResidueNames1;

}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
