// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// I decided to DISABLE the makelink() capability in PE 1.981.
// For this purpose I commented out some things below, making it easy
// to reverse this decision later.

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// When PE comes from molvis.sdsc.edu/protexpl, is this "full_site"? NO.
// Is it "rcsb" -- not in the original sense.
// So currently, server_id == "unknown"!

// see explanation/rationale in linkto.txt (comments here caused js problem)

// The purpose of the functions in linkto.js is to cast certain
// hyperlinks into the appropriate form. There are 3 kinds of hyperlinks
// detailed below. In summary, only links of type 2 need to employ the
// makelink() function below.
// 
// 1. Links to files within the current resource proper (e.g. the Protein
// Explorer). These are always relative since the files are guaranteed to
// be present.
// 
// 2. Links to files within the UMass site ("full site") but external to
// the current resource. The form of these links needs to depend on the
// origin of the current resource.
// 
// 2.A. ORIGIN = UMASS SITE OR A MIRROR OF IT ('FULL SITE'). The links
// need to be relative if the **ENTIRE** UMass site is mirrored on a
// different server, to prevent them from fetching their files from
// UMass.
// 
// 2.B. ORIGIN = A SITE KNOWN TO CONTAIN ONLY THE CURRENT RESOURCE,
// E.G. THE PROTEIN EXPLORER ON THE RCSB PDB SITE. The links need to be
// absolute, so they always go to UMass. No explanatory message is needed.
// In the case of the RCSB PDB site and its mirrors, the url is guaranteed
// always to contain "pdb/pe" (see explorer/0rcsb.txt).
// 
// 2.C. ORIGIN = LOCAL DISK FILES. If the resource is coming from a URL
// beginning file:///, the relative link will work only if the relevant
// external files have also been installed (which they may have been in
// some cases).  It is desirable to have the relative link in case the
// computer is not connected to the Internet, and does happen to have the
// file in question installed.  However, in case the computer is connected
// to the Internet and the files are not installed, it is desirable to have
// an absolute link as well, shown as "[URL]".
// 
// 2.D. ORIGIN = AN UNKNOWN SERVER (base url begins http:// but contains
// neither "umass" nor "pdb/pe"). This case will be treated the same
// as 2.C.
// 
// 2.E. ORIGIN = EBI MMOL SERVER (pdb-browsers.ebi.ac.uk/pe/). Will treat
// same as 2.B (rcsb), all links go to UMass (even tho they have NCBF and
// Morpher).
// 
// 3. Links to files external to the UMass site. These are always absolute links.


// linkto.js is used by index.htm before top_vars.js is loaded into the
//explorer frameset.  Therefore, server_id must be gotten independently from
//home_base.
// PE 1.98: server_id is used many places in PE independently of makelink().

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// VARIABLES AND CALL TO get_server_id()

var umass_base = "www.umass.edu/microbio/"; // also umass server id
var umass2_base = "klaatu.oit.umass.edu/microbio/"; // to avoid 'unknown' server
// var mirror1 = "..." (need to add mirror url id's here if any)

// In January, 2006, RCSB stated that only java-based applications will
// be put on their site. Therefore, PE-Chime will never again be on RCSB.
// DISCONTINUED PE 2.78, January 2006
//var rcsb_server_id = "pdb/pe/"; // see explorer/0rcsb.txt

// ebi pe url can be
//    pqs.ebi.ac.uk/pe
//    pqs.ebi.ac.uk//pdb-doc/pe
//    pdb-browsers.ebi.ac.uk/pe
// ebi mmol file url is
//    pqs.ebi.ac.uk/pqs-bin/macmol-chime.pl?filename=2hhd.mmol
// Therefore the server is ebi if the FIRST instance of ".ebi.ac.uk/"
// is NOT followed by "pqs-bin" (see get_server_id())
var ebi_server_id = ".ebi.ac.uk/";

// ADDITIONS TO SERVER ID LIST MUST BE REFLECTED IN cmd2way2.htm:log_use()
var server_id = ""; // "local_files", "full_site", "rcsb", "ebi", or "unknown"

get_server_id();
//alert("server_id=" + server_id);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
var local_file_url_message = 
"<p><table border=1 cellpadding=10 bgcolor='#80FF80'><tr><td>" +
"<b>Note about hyperlinks:</b> " +
"You are displaying this resource directly from your " +
"local hard disk rather than through the Internet from " +
"the original website. " +
"Links to files on the original website " +
"will be given first as relative links in case the requested " +
"file is on your local hard disk, or in case " +
"you are not connected to the Internet.  If the first " +
"link fails ('unable to find the file ...') " +
"and you are connected to the Internet, " +
"click the immediately following link <b><a href='#'>[URL]</a></b>, " +
"which is an absolute link " +
"to the original website." +
"</td></tr></table>";

var unknown_server_message = 
"<p><table border=1 cellpadding=10 bgcolor='#80FF80'><tr><td>" +
"<b>Note about hyperlinks:</b> " +
"This resource is not being displayed from the original website. " +
"Links to files on the original website " +
"will be given first as relative links in case the requested " +
"file is on the present server.  If the first " +
"link fails ('unable to find the file ...') " +
"click the immediately following link <b><a href='#'>[URL]</a></b>, " +
"which is an absolute link " +
"to the original website." +
"</td></tr></table>";
*/

//For example: <a href='../chime'>Umass Chime Resources Site.</a>\
//[<a href='http://www.umass.edu/microbio/chime'>www.umass.edu/microbio/chime</a>]\

function show_server_id_message()
{
	return; // null function for PE 1.98

/*
	if (server_id == "local_files")
		document.writeln(local_file_url_message);
	else if (server_id == "unknown")
		document.writeln(unknown_server_message);
*/
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function makelink(lklabel, href_rel, href_tail, wintarg)
{
// full_site: relative only
// rcsb (PE only): absolute only
// unknown: both
// local files: both

	with (document)
	{
/*
		// relative link
		if (server_id != "rcsb") // local files, full_site, unknown server
		{
			write("<a href=\"");
			write(href_rel + "\"");
			if (wintarg != "")
				writeln(" target=\"" + wintarg + "\">");
			else
				writeln(">");
			writeln(lklabel + "</a>");
		}

		// absolute link
		if (server_id != "full_site")
		{
*/
			write("<a href=\"http://" + umass_base + href_tail + "\"");
			if (wintarg != "")
				write(" target=\"" + wintarg + "\">");
			else
				writeln(">");
//			if (server_id != "rcsb" && server_id != "ebi")
//				writeln("[URL]</a>");
//			else
				writeln(lklabel + "</a>");
//		}
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Although this function is not called elsewhere in PE, linkto.js
// is loaded many places, calls this function, and the other places
// then use server_id.

function get_server_id(u)
{
	// u is for debugging only

	var the_url = ""; // necessary to make substring be a method of the_url
	the_url += document.location;
//	the_url += u;

	var ebii = the_url.indexOf(ebi_server_id); // see var ebi_server_id
//	alert(the_url.substring(ebii, ebii + ebi_server_id.length + 8));
//	alert(the_url);

	if (the_url.substring(0,4) == "file")
		server_id = "local_files";

	// Look for rcsb first so it will predominate on umass fake pdb test site.
	// DISCONTINUED rcsb option January 2006 PE 2.78 (see above).
//	else if (the_url.indexOf(rcsb_server_id) != -1)
//		server_id = "rcsb";

	else if (ebii != -1 &&
		the_url.substring(ebii, ebii + ebi_server_id.length + 8).indexOf("pqs-bin")
			== -1)
			server_id = "ebi";

	// @@need to add mirror id's here

	else if (the_url.indexOf(umass_base) != -1 ||
		the_url.indexOf(umass2_base) != -1)
			server_id = "full_site";

	else
		server_id = "unknown";
//	alert(server_id);

}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
