                                           /*         locus.js 
This file required for all the Arjay scripts
location variables 
and a function to relocate files to their proper aframes

version 1.1 2007 02 02                                          
*/

	// variables relating to paths; some sniffers
	
var useRelativeBaseAddress = false	// keep at false if you are not using relative BASE addresses or prefer to put that in the html or don't understand what this is
	// note that in the two urls following the trailing slash is not optional; it must be there
var productionSiteURL = 'http://www.sheaves.org/'	// name of site where the files will reside
var localMachineDirectory = 'file:///Volumes/RSFiles/WebSites/www.sheaves.org/'  // name of the folder on home machine where files are -- for testing purposes 
var localTestURL = 'http://localhost/~rsutc/sheaves/' // use for live server testing on local machine
var baseURL = (location.protocol == 'file:')? localMachineDirectory : productionSiteURL	//top of directory hierarchy
var pathToChainLinkFolder = "scripts/chainlinks/"	// unless you change things, this is "scripts/chainlinks/"
var nameOfDefaultCSSFile = "chainlinksopundo.css"
	// what to do if browser incompatible
var tryAltSiteIfOldBrowser = true	// use the path below if defined to access an older and non dynamic site; else if set to false, all you get is a nagging error alert saying you have to upgrade your browser
var pathToAltNonDynamicSite = "www0/index.htm"	// could be an absolute path or relative to the base set above
var deftargetId = "taxonomy"; // name of default aFrame to direct top level files into
var defAFrameFolder = "taxonomy"; // name of top level folder for local testing
var forceUseProductionSite = false;
var tryDefaultFile = false;
var defaultUrl = "html/defcontents.html"; // global default; can be overridden by passing a parameter
var fileSuffix = ".html";
var test=[];
var printAlerts = false;
var tooOld = "Sorry, your browser is too old to run this Ajax page. Please upgrade your browser.";
var badAFrameFileName = "File names transferring into aFrames must have at least one nondigit before any concluding numbers, and letters as a file extension.";

 // Call this first before trying to do rounded corners
function roundSniff()
{
	if(!document.getElementById || !document.createElement)
		return(false);
	var b=navigator.userAgent.toLowerCase();
	if(b.indexOf("msie 5")>0 && b.indexOf("opera")==-1)
		return(false);
	return(true);
}

 // Call this before using aFrames. The aFrame script requires dvarious methods so will do nothing in ie 5 for instance.
function aFrameSniff()
{
	if(!document.documentElement.innerHTML ||!document.getElementById ||!test.push) {if (printAlerts) window.alert (tooOld); return(false)};
	return(true);
}

/* following function is here because this file is required for everything and is small */
/* 	loc2aFrame munges urls to force browsers going directly to a file intended to be framed back to main where the file is placed into an aFrame
	if the location filename is index, does nothing (safety)
		If a host path (relative to the main url) is given, the transfer is made to it.
	if the file is numbered, like "file23.xxx", transfer to baseURL with query str ?file = num; receiver will treat this as part of a sequence
		where the part "file" is the same as the id of the target, so this really amounts to ?targetId=number
	 	if the file is not numbered, transfer to baseURL with query 
	 			1. ?pHostFrameId=filename if a pHostFrameId is supplied
				2. ?dir=filename; here for file = file.xxx, query is ?dir = file.xxx	 		
			assumption: class of aFrame box is "dir" and it will presumably load the filename
			 if there is no directory in the location, fall back to 1 using ?defAFrameId=filename and the receiving code tries to know what to do.
*/
function loc2aFrame (pHostFile,pHostFrameId)
{	if(!aFrameSniff) return;
	var re, str1, str2, queryString, newURL;
	var hostFile = (pHostFile)? pHostFile : ""
	var path = location.pathname;
		// prepare to slice location into dir and filename
	var loc = path.lastIndexOf ('/');
		// but in order of failure, use the supplied id, then a dir name, then the defaullt dirname
	var pathToDir = (pHostFrameId)? pHostFrameId: ((loc != -1)? path.slice (0,loc) : defAFrameFolder)
	var dirName = pathToDir.slice (pathToDir.lastIndexOf ('/')+1); // won't be a slash if using an id, but...
	if (dirName.length==0) dirName = defAFrameName; // and if still nothing, fall back to defaultId 
	var fileName = path.slice (loc+1);
	if (fileName.length ==0||fileName.indexOf ("index.")!=-1) return // was at top level already
			// slice filename into name and number
	re = /^(.*\D)(\d*)(\.[a-zA-Z]*)$/ ;
	var uArray = re.exec(fileName);
	if (!uArray) {if (printAlerts) window.alert (badAFrameFileName); return}
	if (uArray[1] != "index")
		{	if (uArray[2].length>0) {str1 = uArray[1];str2 = uArray[2]}
			else {str1 = dirName;str2 = fileName}
			queryString = "?"+str1+"="+str2;
			newURL = (location.protocol=="file:" &&(!forceUseProductionSite)? localTestURL : productionSiteURL)+hostFile+queryString
			window.location.replace (newURL);
		}
}
