//=======================================================================
// JavaScript FBR ScienceWorks footer section
// Created: January 18, 2001					by: KJH
// Last updated: December 3, 2009			by: KJH
//=======================================================================
// Locate root area by direct URL or relative path from file location.
//    if  URL (http://) the root area is the secton after the ://
//    if FILE the root area is found via relative path from designated base
//            base directory (pre-defined)

// Initialize items
var txt="";                              // global text output
var lastMenu="";                         // global menu usage
var cMenu="";                            // global menu usage
var msg="";                              // text for alert messages (debug)

var path="";                             // root area (default- not determined)
var pathIn="http://web.fbrhome.net/";    // DEFAULT internal website path
var dSpos=-1;                            // Starting position (default- not found)
var tStr="";                             // temporary string container
var isGWI=0;                             // page internal or gwi [default=internal]

var aloc=""+document.location;  // get path/filename [document.URL changes the slashes]
var dloc=aloc.toUpperCase();             // convert to uppercase
var dEpos=dloc.lastIndexOf("/");         // get last position of "/"

// Served from GWI or Internal?
var sStr="HTTP://WWW.FBR.ORG";           // LIVE area
var dpos=dloc.indexOf(sStr);             // last character position
if (dpos>=0) {                           // Found it?
	isGWI=1;                              // served from GWI.
	}

// Where is the root area?
var sStr="HTTP://";                             // search string
var dpos=dloc.indexOf(sStr);                    // last character position
if (dpos>=0) {                                  // HTTP web server mode
	tStr=dloc.substring(dpos+sStr.length,dloc.length);  // remove the http://
	dSpos=tStr.indexOf("/");                     // next / 
	if (dSpos<0) { dSpos=tStr.length };          // only root area passed
	dSpos=dpos+sStr.length+dSpos;                // root end position in aloc
	path=aloc.substring(dpos,dSpos);             // get root area substring
	if (path.substring(path.length,path.length) != "/") {
		path=path + "/";                          // must end in '/'
		}
	//alert ("URL path: " + path);
	} 

if (path == "" ) {                              // FILE mode?
	sStr="FBRORG";                               // Live internal area?
	dpos=dloc.indexOf(sStr);
	if (dpos>0) {
		for (i=dpos; i<dEpos; i++) {              // count directories
			if (dloc.charAt(i)=="/") { path=path+"../" };  // create relative path
			} // end of for
		}
	}

msg="aloc: " + aloc + " \ndloc: " + dloc + "\n\n";
msg=msg + "dpos: " + dpos + "   dSpos: " + dSpos + "   dEpos: " + dEpos + " \n";
msg=msg + "sStr: " + sStr + "\ntStr: " + tStr;
msg=msg + "\n\n path: " + path;
msg=msg + "\n\n pathIn: " + pathIn;
//alert(msg);

//---------------------------------------------------------------------------
//                      ScienceWorks for ME Footer
//---------------------------------------------------------------------------

//.................. Acual header output .....................................
txt="<p id='ScienceWorksFooter'>";
txt=txt + "<a href='"+path+"swksweb/sciworks.html'>";
txt=txt + "<strong><em>ScienceWorks for ME</em></strong></a> ";
txt=txt + " &nbsp; a program of the &nbsp; <a href='"+path+"home.html'><strong>";
txt=txt + "Foundation for Blood Research</strong></a></p>";
document.write(txt);

