// JavaScript Document
//Programmer : Binu Jose, Corporate Communications, Ext 22467
// Purpose :  to generate  breadcrumbs !!!

var subFolders = new Array();
var currentURL = document.location.toString();
subFolders=currentURL.split("/");

function buildDepth(iterations) // builds the relative path 
{
    var iterations=iterations-3;
    var depthStr="";
    for (i=0;i<iterations;i++)
    {
        depthStr=depthStr + "../";
    }
	
return depthStr;

}

function splitText(text,splitChr1,splitChr2) // splits the text and insert spaces 
{
	//alert("the text is " + text  + " the char is " + splitChr1 + " the sec char is " + splitChr2);
	var strWords = new Array();
	var strFinalWord = "";
	var strLastWord = "";
	strWords = text.split(splitChr1);
	if (strWords.length > 1)
	{
		if (splitChr2) // here it is used to remove the extension part of the last element
		{	
			var index = strWords[strWords.length-1].indexOf(splitChr2);
			 strLastWord = strWords[strWords.length-1].substr(0,index);
			for (var i = 0; i<(strWords.length-1); i++)
			{
				 strFinalWord = strFinalWord + strWords[i] +" " ;
			}
		}
		else
		{
			for (var i = 0; i<(strWords.length); i++)
			{
				 strFinalWord = strFinalWord + strWords[i] +" " ;
			}
		}		
		strFinalWord = strFinalWord + strLastWord;
	}
	else
	{
		if (splitChr2)
		{
			var index = text.indexOf(splitChr2);
			 strLastWord = text.substr(0,index);
			 strFinalWord = strLastWord;
		}
		else
		{
			strFinalWord = text;
		}
		
	}
	return strFinalWord;
}

function buildBCrumb()
{
    var subFolders = new Array();
    var currentURL = document.location.toString();
    subFolders=currentURL.split("/");
    var outputStr="";//<span id ='bcumbs1' title='This is how  you reached here from the Menu'>
    for (count=3;count<(subFolders.length-1);count++)
    {
		var subexists = 1;
		if (count == 3){  // starts at the main sublevel
		var repString = splitText(subFolders[count],"_");
		
		outputStr=outputStr + "<a href='" + buildDepth((subFolders.length-count)+1) + "default.htm' class='aFontBrdcrmbs'>" +  repString + "</a>";
		
		}
		if (count > 3  && count < subFolders.length-1) // if the folders 
		{
			
		outputStr=outputStr + " >> " + splitText(subFolders[count],"_") ;			
		}
		if (count == subFolders.length-1) // the last element in the url
		{
			if (subFolders[count] != "default.htm")// to remove the link if the page is the default page
			{
				// to hyperlink the last element use the next line instead of the line which is used 
				//outputStr=outputStr + " <img src='http://mckeenet/hr/benefits2/images/sidearrowPntRight.gif' valign='baseline'> <a href='../%22%20+%20buildDepth((subFolders.length-count)+1)%20+%20subFolders%5Bcount%5D%20+%20%22'>" + splitText(subFolders[count],"_",".") + "</a>";						
				outputStr=outputStr + " >> "  + splitText(subFolders[count],"_",".") ;						
			}
		}
    }
	if (subexists==1) {
	outputStr=outputStr + " >> "//</span>
	}
    document.write(outputStr);
} 