function highlightNavSelected(cellId) {
	
	var wndPath = getValidPath(window.location.pathname);
	var childNodes = document.getElementById(cellId).childNodes;

	// Top Nav
	for (var i = 0; i < childNodes.length; i++) {
		var childNode = childNodes[i];
		if (childNode.tagName != "LI")
			continue;
		var hrefNode = childNode.getElementsByTagName('a')[0];
		var hrefNodePath = getValidPath(hrefNode.pathname);
		if (hrefNodePath == wndPath || isRelatedToTab(hrefNodePath, cellId)) {
			childNode.className = getClassName(childNode);
		}

		// Secondary Nav
		var liNodes = childNode.getElementsByTagName('li');
		for (var j = 0; j < liNodes.length; j++) {
			var liNode = liNodes[j];
			var aNode = liNode.getElementsByTagName('a')[0];
			if (getValidPath(aNode.pathname) == wndPath)
				liNode.className = getClassName(liNode);

		}

	}

}

function getClassName(thisNode) {
	var aClass = thisNode.className;
	if (aClass.length > 0) aClass += ' ';
	aClass += ' selected';
	return aClass;
}

function getValidPath(url) {
	var validPath = url.charAt(0) != "/" ?  "/" + url : url;
	return stripSelectors(validPath);
}

function stripSelectors(path) {
	// e.g. /en/shop/3-5_years.qfsearch.age=96-132.html should become /en/shop/3-5_years.html
	var slashsplit = path.split("/");
	var strippedPath = "";
	if (slashsplit.length>1) {
		var strippedEnd  = slashsplit[slashsplit.length-1].replace(/\.(.*)\./, ".");
		for (var i=0;i<slashsplit.length-1;i++)
			strippedPath=strippedPath+slashsplit[i]+"/";
		strippedPath=strippedPath+strippedEnd;
	}
	return strippedPath;
}

function isRelatedToTab(url, cellId) {
	if (cellId != 'headernav')
		return false;
	var tabURL = url.split('/');
	var wndURL = getValidPath(window.location.pathname).split('/');
	if (tabURL.length >= 2 && wndURL.length >= 2) {
		var tabName = tabURL[2].split('.')[0];
		var wndName =  wndURL[2].split('.')[0];
		// Select shop for everything in families
		if (tabName == 'shop' && wndName == 'families')
			return true;
		return tabName == wndName;
	}
	return false;
}
