//---------------------------------------------------------------------------
// Deprecated color key functions are in a block at the bottom of this file,
// commented out. If you are upgrading an existing tutorial to this version
// of JTAT, and you used the older function names, uncomment the block at
// the end of this file.
//---------------------------------------------------------------------------
// Element keys defined below:
// alphac (or calpha) will show a darker C with subscript "alpha".
// element_key("[list of elements in any order separated by commas]",
//	"[nothing or comma]", "[nothing, comma, or period]");
//
// Elements can also be separated by spaces.
//
// Examples:
//
//  element_key("c,o,n,s,se");
//  [Since the 2nd and 3rd parameters are missing, there will be no commas
//   between elements, and no final punctuation.]
//
//  element_key("n o c calpha zn", "", ".");
//  [There will be no commas between elements, but a period at the end.]
//
//  element_key("s, c, h, o, n, p");

// Secondary Structure key
// ss_key() Secondary Structure (alpha helix, beta strand, coil)
// sst_key() Secondary Structure with Turns (alpha helix, beta strand, turn, coil)

// Composition keys:
// composition_key() [lists all 5 types]
// protein_key() dna_key() rna_key()
// ligand_key() solvent_key()

// polarity2_key() (hydrophobic, polar)
// aacharge_key()  (positive, negative; remaining protein white)
// polarity4_key() (charge and polarity in 4 colors)
// polarity5_key() (charge and polarity in 5 colors)

// nucbases_dna_key()   (A, T, G, C)
// nucbases_ddna_key()  (dA, dT, dG, dC)
// nucbases_rna_key()   (A, U, G, C)
// nucbases_key()   (A, T, G, C, U)
// dna_backbone_key()
// rna_backbone_key()
// nucbasesbb_key()   (A, T, G, C, U, DNA Backbone, RNA Backbone)

// purpyr_key() (purines vs. pyrimidines)

// Additional keys can be defined very easily, referring to the the examples
// below, and to the style class color definitions in jtat/_drums/drums.css.
// If you add your own, they will need to be copied into the keys.js file
// in any new version of JTAT that you use.

//---------------------------------------------------------------------------
// These specify the default font style, size, and weight for color keys.
// To change these in a single tutorial, define them differently
// in jtat/tutorial_name/js4all/tutorial.js.

var colorKeyPrefix = '<tt><font size="+2"><b>';
var colorKeySuffix = '</b></font></tt>';

//---------------------------------------------------------------------------
function spanClass(mclass, msg, delim)
{
	var endit = "\n";
	if (delim == ".")
		endit = "";

	if (typeof(delim) == "undefined")
		delim = "";
	return (spanClassLast(mclass, msg) + delim + endit);
}

function spanClassLast(mclass, msg)
{
	var spc = '<span class="' + mclass + '">' + msg + '</span>';
	return spc;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function ckey(hexrgb, keytext, punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	return (colorKeyPrefix + '<font color=\"#' + hexrgb + '\">' +
		keytext + '</font>' + punct + colorKeySuffix);
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// elist: element list delimited by commas, spaces, or comma-spaces.
// Elements can be in any order. Double commas or spaces are ok: "c,,  n".
// Acceptable formats are:
// "c,h,o,ca" or "alphac, c, h, o" or "c o n se".

// delim is either blank, or a comma, for the delimiter between elements
// in the color key output.
// endpunct is the punctuation that goes at the end ("," or ".").
// delim and endpunct may be omitted in the function call, in which case
// they default to blanks.

function element_key(elist, delim0, endpunct)
{
	if (typeof(delim0) == "undefined")
		delim0 = "";

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

	var badElement = false;

	// convert elist to lower case
	elist = elist.toLowerCase();

	// trim end spaces
	while (elist.charAt(0) == " ")
		elist = elist.substring(1);

	while (elist.charAt((elist.length) - 1) == " ")
		elist = elist.substring(0, (elist.length) - 1);

	// replace spaces with commas
	elist = elist.replace(/ /g, ",");

	// "comma space" is now "comma comma": reduce double commas to single ones.
	while(elist.indexOf(",,") != -1)
		elist = elist.replace(/,,/g, ",");

	// ela: element array
	var ela = new Array();
	ela = elist.split(/,/);

//	alert("|" + elist + "|\n" + ela.length);

	var mkey = colorKeyPrefix;

	var i;
	var e1;
	var delim;
	for (i = 0; i < ela.length; i++)
	{
		delim = delim0;
		if (i == (ela.length - 1))
			delim = endpunct;

		switch (ela[i])
		{
			case "alphac":
			case "calpha":
				e1 = spanClass("alphac", "C<sub>alpha</sub>", delim);
				break;
			case "c":
				e1 = spanClass("c", "C", delim);
				break;
			case "h":
				e1 = spanClass("h", "H", delim);
				break;
			case "o":
				e1 = spanClass("o", "O", delim);
				break;
			case "n":
				e1 = spanClass("n", "N", delim);
				break;
			case "s":
				e1 = spanClass("s", "S", delim);
				break;
			case "p":
				e1 = spanClass("p", "P", delim);
				break;
			case "na":
				e1 = spanClass("na", "Na", delim);
				break;
			case "k":
				e1 = spanClass("k", "K", delim);
				break;
			case "rb":
				e1 = spanClass("rb", "Rb", delim);
				break;
			case "ca":
				e1 = spanClass("ca", "Ca", delim);
				break;
			case "mg":
				e1 = spanClass("mg", "Mg", delim);
				break;
			case "fe":
				e1 = spanClass("fe", "Fe", delim);
				break;
			case "al":
				e1 = spanClass("al", "Al", delim);
				break;
			case "cr":
				e1 = spanClass("cr", "Cr", delim);
				break;
			case "v":
				e1 = spanClass("v", "V", delim);
				break;
			case "mn":
				e1 = spanClass("mn", "Mn", delim);
				break;
			case "zn":
				e1 = spanClass("zn", "Zn", delim);
				break;
			case "cu":
				e1 = spanClass("cu", "Cu", delim);
				break;
			case "co":
				e1 = spanClass("co", "Co", delim);
				break;
			case "ni":
				e1 = spanClass("ni", "Ni", delim);
				break;
			case "cd":
				e1 = spanClass("cd", "Cd", delim);
				break;
			case "f":
				e1 = spanClass("f", "F", delim);
				break;
			case "cl":
				e1 = spanClass("cl", "Cl", delim);
				break;
			case "i":
				e1 = spanClass("i", "I", delim);
				break;
			case "br":
				e1 = spanClass("br", "Br", delim);
				break;
			case "b":
				e1 = spanClass("b", "B", delim);
				break;
			case "se":
				e1 = spanClass("se", "Se", delim);
				break;
			case "si":
				e1 = spanClass("si", "Si", delim);
				break;
			case "xe":
				e1 = spanClass("xe", "Xe", delim);
				break;
			default:
				alert("Fatal Author's error:\n" +
					"Unrecognized element in element_key():\n" +
					ela[i] +
					"\nIf this element is correct, please add it to\n" +
					"element_key() in jtat/_jsutil/keys.js");
				badElement = true;
		}
		if (badElement)
		{
			mkey += " [Error: Unrecognized Element " + ela[i] + "]";
			break;
		}
		else
			mkey += e1;
	}

	mkey += colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function polarity2_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("nonpolar", "Hydrophobic", ",") +
	spanClassLast("polar", "Polar", ",") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function polarity4_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("basic", "Positive", ",") +
	spanClass("acidic", "Negative", ",") +
	spanClass("polar", "Polar&nbsp;Uncharged", ",") +
	spanClassLast("nonpolar", "Nonpolar", ",") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function polarity5_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("basic", "Positive", ",") +
	spanClass("acidic", "Negative", ",") +
	spanClass("polar", "Polar Uncharged", ",") +
	spanClass("aabackbone", "Backbone", ",") +
	spanClassLast("nonpolar", "Nonpolar", ",") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function aacharge_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("basic", "Positive", ",") +
	spanClassLast("acidic", "Negative") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function ss_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("helix", "Alpha Helix", ",") +
	spanClass("strand", "Beta Strand", ",") +
	spanClassLast("h", "Coil", punct) +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function sst_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("helix", "Alpha Helix", ",") +
	spanClass("strand", "Beta Strand", ",") +
	spanClass("turn", "Turn", ",") +
	spanClassLast("h", "Coil") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function nucbases_dna_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("a", "A", ",") +
	spanClass("t", "T", ",") +
	spanClass("g", "G", ",") +
	spanClassLast("cy", "C") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function nucbases_ddna_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("a", "dA", ",") +
	spanClass("t", "dT", ",") +
	spanClass("g", "dG", ",") +
	spanClassLast("cy", "dC") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function nucbases_rna_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("a", "A", ",") +
	spanClass("u", "U", ",") +
	spanClass("g", "G", ",") +
	spanClassLast("cy", "C") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function nucbases_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("a", "A", ",") +
	spanClass("t", "T", ",") +
	spanClass("g", "G", ",") +
	spanClass("cy", "C", ",") +
	spanClassLast("u", "U") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function nucbasesmnemonic_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("a", "Azure", ",") +
	spanClass("t", "Tweety bird", ",") +
	spanClass("g", "Green", ",") +
	spanClass("cy", "Carmine", ",") +
	spanClassLast("u", "Umber") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function nucbasesbb_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("a", "A", ",") +
	spanClass("t", "T", ",") +
	spanClass("g", "G", ",") +
	spanClass("cy", "C", ",") +
	spanClass("u", "U", ",") +
	spanClass("dnaback", "DNA Backbone", ",") +
	spanClassLast("rnaback", "RNA Backbone") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function dna_backbone_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClassLast("dnaback", "DNA Backbone") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function rna_backbone_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClassLast("rnaback", "RNA Backbone") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function protein_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClassLast("protein", "Protein") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function dna_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClassLast("dna", "DNA") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function rna_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClassLast("rna", "RNA") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function ligand_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClassLast("ligand", "Ligand") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function solvent_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClassLast("solvent", "Solvent") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function composition_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("protein", "Protein", ",") +
	spanClass("dna", "DNA", ",") +
	spanClass("rna", "RNA", ",") +
	spanClass("ligand", "Ligand", ",") +
	spanClassLast("solvent", "Solvent") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function purpyr_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("pu", "Purines", ",") +
	spanClassLast("py", "Pyrimidines") +
	punct +
	colorKeySuffix;

	return mkey;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function n2c_rainbow_key()
{
	var rbk = 
'<center> \n\
<table cellpadding="5" cellspacing="0"> \n\
<tr> \n\
<td bgcolor="#0000ff"><font color="#ffffff" \n\
face="sans-serif"><b>N, 5\'</b></font></td> \n\
<td bgcolor="#0080ff">&nbsp;</td> \n\
<td bgcolor="#00c0ff">&nbsp;</td> \n\
<td bgcolor="#00e0b0">&nbsp;</td> \n\
<td bgcolor="#50e000">&nbsp;</td> \n\
<td bgcolor="#a0e000">&nbsp;</td> \n\
<td bgcolor="#e0e000">&nbsp;</td> \n\
<td bgcolor="#ffa000">&nbsp;</td> \n\
<td bgcolor="#ff0000"><font color="#ffffff" \n\
face="sans-serif"><b>C, 3\'</b></font></td> \n\
</tr></table></center>	 \n\
';

	return rbk;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function consurf_key11()
{
	var ck11 = '<center><img src="';

	// kludge?
	// for jtatdocs.htm vs. contents/chapter
	if (document.location.href.indexOf("_docs/") == -1)
		ck11 += "../";

	ck11 += '../_imgutil/consurf_key_11.gif"></center>';

	return ck11;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//  DEPRECATED FUNCTIONS:
//THESE COLOR KEY FUNCTIONS ARE NO LONGER RECOMMENDED. ALL ARE REPLACED BY
//THE NEW FUNCTION element_key(). IF YOU HAVE AN EXISTING TUTORIAL THAT USES
//SOME OF THESE FUNCTIONS, UNCOMMENT THIS BLOCK FROM HERE TO THE END OF THIS
//FILE.

/* <<< BEGIN COMMENT DEPRECATED FUNCTIONS

function calpha_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClassLast("alphac", "C<sub>alpha</sub>") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function con_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("c", "C") +
	spanClass("o", "O") +
	spanClassLast("n", "N") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function conh_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("c", "C") +
	spanClass("o", "O") +
	spanClass("n", "N") +
	spanClassLast("h", "H") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function cons_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("c", "C") +
	spanClass("o", "O") +
	spanClass("n", "N") +
	spanClassLast("s", "S") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function consh_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("c", "C") +
	spanClass("o", "O") +
	spanClass("n", "N") +
	spanClass("s", "S") +
	spanClassLast("h", "H") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function conps_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("c", "C") +
	spanClass("o", "O") +
	spanClass("n", "N") +
	spanClass("p", "P") +
	spanClassLast("s", "S") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function conpsh_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("c", "C") +
	spanClass("o", "O") +
	spanClass("n", "N") +
	spanClass("p", "P") +
	spanClass("s", "S") +
	spanClassLast("h", "H") +
	punct +
	colorKeySuffix;

	return mkey;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function noh_key(punct)
{
	if (typeof(punct) == "undefined")
		punct = "";

	var mkey = colorKeyPrefix +
	spanClass("n", "N") +
	spanClass("o", "O") +
	spanClassLast("h", "H") +
	punct +
	colorKeySuffix;

	return mkey;
}

END COMMENT DEPRECATED FUNCTIONS >>> */
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
