//----------------------------------------------------------------------
// DO NOT DELETE THIS FILE. IT IS CRUCIAL TO YOUR PiPES!

// Every line starting with // is a javacript comment.
// Only the lines that are not comments are crucial.

// This file tells your PiPEs where to get PE.
// If it is incorrect, your PiPE links will report
//   Netscape 7, Mozilla, Firefox:
//     "The file ... cannot be found. Please check the location and try again."
//   Internet Explorer:
//     "The page cannot be displayed."
//   Netscape 4:
//     "Netscape is unable to find the file or directory named ..."

// The value of pe_path below must be a relative URL:
// PE must be on your local computer or your server. You cannot run your
// local PiPE in PE from a server, or PiPE on your server in PE on another
// server. pe_path normally ends in "protexpl/". It must end with "/".

// pe_path is relative to the index.htm files in your PiPEs.
// Typically for Windows, PE will be
// in a folder named "Protein Explorer N.NN" or somesuch, where "N.NN"
// is the version number.
// Typically, your PiPEs will be in a folder named
// "my_molecules/pipes/my_pipe1"
// where my_pipe1 is the name of a folder containing a PiPE.
// If "Protein Explorer N.NN" and "my_molecules" are side by side,
// it follows that to get from my_pipe1 to
// "Protein Explorer N.NN/protexpl/pe.htm"
// pe_path = "../../../Protein Explorer N.NN/protexpl/pe.htm";
// (where "../" means the parent of the current directory).
// "N.NN" must be replaced with the actual version number.

// If your configuration is different, you will have to change
// pe_path below.
// THE NEXT LINE IS THE LINE YOU MAY HAVE TO CHANGE.

var pe_path = "../../../pe/protexpl/";

//----------------------------------------------------------------------
// DO NOT CHANGE ANYTHING BELOW HERE.

// The following functions are in pe_path.js (rather than pstart.js)
// because some HTML files in my_molecules/pipes that don't start PE
// need the following, but nothing from pstart.js.

// Retained only for backwards compatibility.
function linkto_pe_inpipe(doc, targ, rgb, label, tail)
{
	linkto_pe(doc, targ, rgb, label, tail);	
}

// Retained only for backwards compatibility.
function linkto_pe_belowpipes(doc, targ, rgb, label, tail)
{
	linkto_pe(doc, targ, rgb, label, tail);	
}

function linkto_pe(doc, targ, rgb, label, tail)
{
	var fixed_pepath = pe_path;
	var rstepsdown = get_rstepsdown();
	var i;

	// allowable range of rstepsdown is -2 to 3
	if (rstepsdown < -1 || rstepsdown > 4)
	{
		alert("ERROR: this document is not in directory\n" +
			"\"/my_molecules/\" or a subdirectory within\n" +
			"it (up to four levels of subdirectories).\n" +
			"The link to \"" + doc + "\" will fail. See pe_path.js.\n" +
			"Relocating this set of files is recommended.");
	}
	else if (rstepsdown < 0)
	{
		for (i = -1; i >= rstepsdown; i--)
			fixed_pepath = fixed_pepath.substring(3); // trim off leading "../"
	}
	else if (rstepsdown > 0)
	{
		for (i = 1; i <= rstepsdown; i++)
			fixed_pepath = "../" + fixed_pepath;
	}

//	alert(fixed_pepath);
	make_pelink(fixed_pepath, doc, targ, rgb, label, tail);	
}

//----------------------------------------------------------------------
// rstepsdown is, RELATIVE to pe_path defined in template/pe_path.htm,
// the number of steps "down" towards the root directory
// to get to pe/protexpl.

// Examples:
// for /my_molecules/pipes/examples.htm slashes = 0, rstepsdown = -1;
//   (that is, one fewer step down than in pe_path)
// for /my_molecules/pipes/template/index.htm slashes = 1, rstepsdown = 0;
//   (that is, no change to pe_path)
// for /my_molecules/pipes/oberholser/collagen/index.htm slashes = 2, rstepsdown = 1;
//   (that is, one more step down than in pe_path)

function get_rstepsdown()
{
	var anchor = "/my_molecules/";
	var here = "" + document.location.href;
//	alert(here);
	var slashes = 0;

	var i = here.indexOf(anchor);
	if (i == -1)
		return -3; // triggers error message

	i += anchor.length;
	
	// count slashes following anchor, "../" counting negative
	while ((i = here.indexOf("/", i)) != -1)
	{
		if(here.substring(i-2,i+1) == "../")
			slashes--;
		else
			slashes++;

		i++;
	}
	slashes = slashes - 2;
//	alert(slashes);
	return (slashes);
}

//----------------------------------------------------------------------
function make_pelink(pepath, doc, targ, rgb, label, tail)
{
	with (document)
	{
		// href
		// pe_path ends with "/".
		var lks = "<a href='" + pepath + doc + "'";

		// target
		if (targ != "")
			lks += " target='" + targ + "'";

		lks += ">";

		// font color
		if (rgb != "")
			lks += "<font color='#" + rgb + "'>";

		// label = description
		lks += label;

		// close font color
		if (rgb != "")
			lks += "<\/font>";

		// close anchor
		lks += "</a>";

		// add tail
		if (tail != "")
			lks += tail;

		//alert(lks);
		writeln(lks);
	}
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
