// debug thru # 1
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
var empty_msg = "(Empty Text-Only Slide)";

var isOnline = (top.document.location.href.indexOf("http:") != -1)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
var pdb_filepath_info = 

"<b>PDB Common Filepath Requirement for MolSlides:</b><br><br> \
When a set of MolSlides uses more than one PDB file, all the PDB files \
for the set are expected to be in the same folder (directory), which \
is also where the MolSlides HTML file should be, or be saved. \
This folder, containing the MolSlides HTML file and all the \
PDB files needed, will be called the <b>MolSlides folder</b>. \
When developing a set of MolSlides, \
<b>Protein Explorer should be displaying one of the PDB files \
from the MolSlides Folder</b>. When a MolSlide needs a PDB file \
different than the one currently displayed in PE, it will be looked \
for in the same folder as the one currently displayed. If the PDB \
file is not there, the MolSlide will have a <b>blank black molecular view</b> \
in the MolSlide Manager, in MolSlide Previews, and when Exported and \
Saved MolSlides are displayed from the MolSlides folder. \
";

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var pfn = new Array();
var pfncount = new Array();
var pfntot = 0;

function get_pdb_list(imtotal, impdb, impdb2)
{
	pfntot = 0;
	get_pdb_list2(imtotal, impdb);
	get_pdb_list2(imtotal, impdb2);
}

function get_pdb_list2(imtotal, impdb)
{
	var ii, jj;
	for (ii = 1; ii <= imtotal; ii++)
	{
		var pp = impdb[ii];
		if (pp == "")
			continue;
		pp = opener.top.just_filename(pp);
		var newpdb = true;
		for (jj = 1; jj <= pfntot; jj++)
		{
			if (pp == pfn[jj])
			{
				newpdb = false;
				break;
			}
		}
		if (newpdb)
		{
			pfntot++;
			pfn[pfntot] = pp;
			pfncount[pfntot] = 1;
		}
		else
			pfncount[jj]++;
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// returns inss escaped, but with newlines following %0A (\n),
// bracketed in |...|. If start is negative, returns segment from
// start to end.

function esclines(inss, start, end)
{
	var emsg;
	if (start >= 0)
		emsg = inss.substring(start, end);
	else
		emsg = inss.substring((inss.length + start), inss.length);

	emsg = emsg.replace(/\r/g, "%0D");
	emsg = emsg.replace(/\n/g, "%0A\n");
	emsg = ("\n---------------\n|" + emsg + "|");
	return emsg;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function jmol_delspin(spt)
{
	var etarg = "#jx spin on";
	var ijs = spt.indexOf("#jx set spin");
	if (ijs == -1)
		return spt;
	var ijse = spt.indexOf(etarg);
	if (ijse == -1)
	{
		alert("protexpl/molview/common.js #1:\nunexpected failure to find etarg");		
		return spt;
	}
	ijse += etarg.length;

	while (spt.charAt(ijse) == ";" || spt.charAt(ijse) == "\r"
		|| spt.charAt(ijse) == "\n" || spt.charAt(ijse) == " ")
		ijse++; // beyond end of string returns ""

	spt = spt.substring(0, ijs) + spt.substring(ijse);
	return spt;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// converts \n\n to \n, \r\n\r\n to \r\n
function remove_blank_lines(ss)
{
	ss = ss.replace(/\n\n/g, "\n");
	ss = ss.replace(/\r\n\r\n/g, "\r\n");
	return ss;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// NOT TESTED
// converts \r to \n leaving \n and \r\n alone.
//function bare_returns_to_newlines(sp)
//{
//	var i = 0;
//	while ((i = sp.indexOf("\r", i)) != -1)
//	{
//		if (sp.charAt(i + 1) != "\n")
//			sp = sp.substring(0, i) + "\n" + sp.substring(i + 1);
//		i++;		
//	}
//	return sp;	
//}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function any_compares()
{
	var anycomp = false;
	for (vv = 1; vv <= top.vvt; vv++)
		if (is_compare(vv))
			anycomp = true;
	return anycomp;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function alert2(msg)
{
	alert(remove_blank_lines(msg));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
