// JavaScript Document
//Generate  Trail lines.
var sEngTrailTitle= new Array();
var sEngTrailURL= new Array();
var sEngTrail = "";
var nCurLink = 0;
var sHebTrailTitle= new Array();
var sHebTrailURL= new Array();
var sHebTrail = "";
var nCurLink_Heb = 0;
var bFirst = true;

function AddLinkToGeneralList(sTitle, sUrl)
{
	sEngTrailTitle[nCurLink]  = sTitle;
	sEngTrailURL[nCurLink++] = sUrl;
}
function AddLinkToGeneralList_Heb(sTitle, sUrl)
{
	sHebTrailTitle[nCurLink_Heb]  = sTitle;
	sHebTrailURL[nCurLink_Heb++] = sUrl;
}

function getURL()
{
	return document.URL;
}


function AddToTrail(sUrl) { 
// Search through the url array 
var i;
	for (i=0; i <= sEngTrailURL.length; i++){
		if (sUrl == sEngTrailURL[i]){
//			alert(sEngTrailURL[i]);
//			alert(sEngTrail);
			if (bFirst != true){
				sEngTrail = "<a href=\"" + sEngTrailURL[i] + "\">" + sEngTrailTitle[i]+ "</a>"  + "  &gt;&gt; " + sEngTrail;
				return;
			} else {
			sEngTrail = "<a href=\"" + sEngTrailURL[i] + "\">" + sEngTrailTitle[i]+ "</a>"   + sEngTrail;				
			}
			bFirst = false;
		}
	}
}
function AddToTrail_Heb(sUrl) { 
// Search through the url array 
var i;
	for (i=0; i <= sHebTrailURL.length; i++){
		if (sUrl == sHebTrailURL[i] ){
			sHebTrail = "<a href=\"" + sHebTrailURL[i] + "\">" + sHebTrailTitle[i]+ "</a>"  + "  &gt;&gt; " + sHebTrail;
			return;
		}
	}
}

function GenerateTrail(sUrl) { 
	var nLastCh, sUrl_tmp;
	sUrl_tmp = sUrl;
	// For each level in the hierarchy, define the link string and the index (within this array) of its base in the hierarchy 
AddLinkToGeneralList("Tel Aviv University", "http://www.tau.ac.il/");
AddLinkToGeneralList("Life Sciences", "http://www.tau.ac.il/lifesci/");
AddLinkToGeneralList("Department of Biochemistry and Molecular Biology", "http://www.tau.ac.il/lifesci/departments/biochem/");
AddLinkToGeneralList("Department of Molecular Biology and Ecology of Plants", "http://www.tau.ac.il/lifesci/departments/plant_s/");
AddLinkToGeneralList("Members", "http://www.tau.ac.il/lifesci/departments/plant_s/members/");
//AddLinkToGeneralList("BC Members folder", "http://www.tau.ac.il/lifesci/departments/biochem/members/");
AddLinkToGeneralList("Molecular Microbiology and Biotechnology Department", "http://www.tau.ac.il/lifesci/departments/biotech/");
AddLinkToGeneralList("Cell Research and Immunology Department", "http://www.tau.ac.il/lifesci/departments/cell_r/");
//AddLinkToGeneralList("Institute for Nature Conservation Research", "http://www.tau.ac.il/lifesci/incr/");
AddLinkToGeneralList("Cell Research and Immunology Deptartment", "http://www.tau.ac.il/lifesci/cell/");
AddLinkToGeneralList("Department of Zoology", "http://www.tau.ac.il/lifesci/departments/zoology/");
AddLinkToGeneralList("Department of Neurobiochemistry", "http://www.tau.ac.il/lifesci/neurobiochemistry/");
//AddLinkToGeneralList("Temporary Members folder", "http://www.tau.ac.il/lifesci/temp/deapratments/plant_s/members/");
AddLinkToGeneralList("Temporary folder", "http://www.tau.ac.il/lifesci/temp/");
//AddLinkToGeneralList("IT Unit", "http://www.tau.ac.il/lifesci/units/it/");

//	sEngTrail = "<a href=\"" + sUrl + "\">" + document.title + "</a>";    // Current Page...
//	while (sUrl != "http://www.tau.ac.il"  && sUrl.length > 15) {
	while (sUrl_tmp.length > 15) {
		//  Cut the URL 		
		nLastCh = sUrl_tmp.lastIndexOf("/");
		if (-1 == nLastCh) return;
		sUrl_tmp = sUrl_tmp.substring(0,nLastCh+1);
		// Search for it in the list - if exists, add to the trail
		//alert(sUrl_tmp);
		//alert(bFirst);
		AddToTrail(sUrl_tmp);
		//Cut the last "/" so next iteration the next "/" will be detected
		sUrl_tmp = sUrl_tmp.substring(0,nLastCh);
	}
	setTitle(sUrl);
	document.write(sEngTrail);
}

function GenerateHebTrail(sUrl) { 
	var nLastCh;
	// For each level in the hierarchy, define the link string and the index (within this array) of its base in the hierarchy 
AddLinkToGeneralList_Heb("אוני' ת\"א", "http://www.tau.ac.il/");
AddLinkToGeneralList_Heb("מדעי החיים", "http://www.tau.ac.il/lifesci/");
AddLinkToGeneralList_Heb("המחלקה לביוכימיה וביולוגיה מולקולרית", "http://www.tau.ac.il/lifesci/departments/biochem/");
AddLinkToGeneralList_Heb("המחלקה לחקר התא ואימונולוגיה", "http://www.tau.ac.il/lifesci/departments/cell_r/");
//AddLinkToGeneralList_Heb("BC Members folder", "http://www.tau.ac.il/lifesci/departments/biochem/members/");
AddLinkToGeneralList_Heb("Molecular Microbiology and Biotechnology Department", "http://www.tau.ac.il/lifesci/biotechnology/");
//AddLinkToGeneralList_Heb("Institute for Nature Conservation Research", "http://www.tau.ac.il/lifesci/incr/");
AddLinkToGeneralList_Heb("Cell Research and Immunology Deptartment", "http://www.tau.ac.il/lifesci/cell/");
AddLinkToGeneralList_Heb("Department of Zoology", "http://www.tau.ac.il/lifesci/departments/zoology/");
AddLinkToGeneralList_Heb("Department of Neurobiochemistry", "http://www.tau.ac.il/lifesci/neurobiochemistry/");
AddLinkToGeneralList_Heb("Department of Molecular Biology and Ecology of Plants", "http://www.tau.ac.il/lifesci/departments/plant_s/");
//AddLinkToGeneralList_Heb("Temporary Members folder", "http://www.tau.ac.il/lifesci/temp/deapratments/plant_s/members/");
AddLinkToGeneralList_Heb("Temporary folder", "http://www.tau.ac.il/lifesci/temp/");
//AddLinkToGeneralList("IT Unit", "http://www.tau.ac.il/lifesci/units/it/");

	sEngTrail = "<a href=\"" + sUrl + "\">" + document.title + "</a>";    // Current Page...
//	while (sUrl != "http://www.tau.ac.il"  && sUrl.length > 15) {
	while (sUrl.length > 15) {
		//  Cut the URL 		
		nLastCh = sUrl.lastIndexOf("/");
		if (-1 == nLastCh) return;
		sUrl = sUrl.substring(0,nLastCh+1);
		// Search for it in the list - if exists, add to the trail
		AddToTrail_Heb(sUrl);
		//Cut the last "/" so next iteration the next "/" will be detected
		sUrl = sUrl.substring(0,nLastCh);
	}
	document.write(sEngTrail);
}

function setTitle(sUrl)
{
		var nLastCh, sUrl_tmp;
		sUrl_tmp = sUrl; 
 		nLastCh = sUrl.lastIndexOf("/");
		if (-1 == nLastCh) return;
		sUrl_tmp = sUrl_tmp.substring(0,nLastCh+1);
		// Search for it in the list - if exists, set the title

		for (i=0; i <= sEngTrailURL.length; i++){
			if (sUrl_tmp == sEngTrailURL[i]){
				document.title = sEngTrailTitle[i];
				return;
			}
		}
}
