window.onload=function(){
	SelectTab();
};

function getPageName(link){
	var firstpos,lastpos,Name;
	firstpos = link.lastIndexOf('/') + 1;
	lastpos = (link.indexOf('?')!=-1) ? link.indexOf('?') : link.length+1;
	Name = link.substring(firstpos,lastpos);
	return Name;
};

function getNumTab(link){
	var ret=-1,firstpos;
        if ( link.lastIndexOf('=') != -1 ) {
		firstpos = link.lastIndexOf('=') + 1;
		ret = link.substring(firstpos,firstpos + 1);
	};
	return ret - 1;
};


function SelectTab() {
	if (location.href.lastIndexOf('/') != -1) {
		var pageName,menu,linksCollection,numTab,linkPageName;

		pageName = getPageName(location.href);
		menu     = document.getElementById("primaryNavigation");
		linksCollection = menu.getElementsByTagName('a');
		numTab = getNumTab(location.href);

		for (var i=0;i < linksCollection.length;i++){
			linkPageName = getPageName(linksCollection[i].href);

			//if numtab is the number from the URL 
			if (linkPageName == pageName || numTab == i){
			 linksCollection[i].className = "sel";
			};
		};
		//if there are items in the breadcrumb to add the parameter tab=num	
		if (numTab >= 0) { SetTabs(numTab); };
	};
};

//set the tabs in the breadcrumb
function SetTabs(numtab){
	var breadbrumb,links,pos1,pos2;
	breadbrumb = document.getElementById("ctl00_cphBody_FolderBreadcrumb1");
	links = breadbrumb.getElementsByTagName('a'); 	
	numtab++;
	for (j=2;j < links.length-1;j++){
		if (links[j].href.lastIndexOf('?') == -1 ){
			links[j].href = links[j].href + '?tab='+ numtab;	  
		} else{ //when the page has other var
			pos1 = links[j].href.lastIndexOf('?');
			pos2 = links[j].href.length;
			links[j].href = links[j].href.substring(0,pos1) + '?tab=' + numtab + '&' + links[j].href.substring(pos1+1,(pos2));     
		};
	};
};