/**************************************************************************
 *                                                                        *
 *  JAVASCRIPT MENU HIGHLIGHTER v.1.0 (051123)                            *
 * --------------------------------------------                           *
 * ©2005 Media Division (www.MediaDivision.com)                           *
 *                                                                        *
 * Written by Marius Smarandoiu & Armand Niculescu                        *
 *                                                                        *
 * You are free to use, modify and distribute this file, but please keep  *
 * this header and credits                                                *
 *                                                                        *
 * Usage:                                                                 *
 * - the script will apply the .current class to the <a> and its parent   *
 *   <li> that is contained in the element with id="primarynav" and points*
 *   to the current URL                                                   *
 * - works in IE6, Firefox and Opera                                      *
 **************************************************************************/
function extractLink(hrefString, crtPage)
{
	var arr = /^(http|https):\/\/[a-z-.:0-9]+([\/]{0,1}[^#]+)[#]{0,1}/i.exec(hrefString);
		if(crtPage.charAt(crtPage.length-1) == '/'){
			var arr2 = /^(.*\/)(fi_|se_)(etusivu)\.[shtml]{3,5}$/i.exec(arr[2]);
			if (arr2){
				var palautus = arr2[1];
			} else {
				var palautus = arr[2];
			}
		}else{
			var palautus = arr[2];
		}
	return palautus;
}

function extractUrl(hrefString)
{
	var arr = /^(http|https):\/\/[a-z-.:0-9]+([\/]{0,1}[^#]+)[#]{0,1}/i.exec(hrefString);
	return arr[2];
}

function setActiveMenu(arr, crtPage)
{
	for(var i=0; i < arr.length; i++)
		if(extractLink(arr[i].href, crtPage) == crtPage)
		{
			arr[i].className = "navValittu";
		}
}

function setPage(Taso1url)
{
	if(document.location.href) 
		hrefString = document.location.href;
	else
		hrefString = document.location;

	if (document.getElementById("divNavi")!=null) 
		setActiveMenu(document.getElementById("divNavi").getElementsByTagName("a"), extractUrl(hrefString));

	if (document.getElementById("topNavi")!=null) 
		setActiveMenu(document.getElementById("topNavi").getElementsByTagName("a"), Taso1url);
		
}