/* Javascripts for Diglib information */

/* Writes the <li>-tag for the left hand menu. The url is relative */
function WriteMenuItem(title, url, active)
{
   	var href = String(location.href).toLowerCase();
	var baseUrl = href.substr(0, href.indexOf("information.aspx"));

	completeUrl = 'Information.aspx?id=0&url=' + url;
	var css = "";
	if (active == true)
	    css = " class=\"active\"";
	document.write('<li' + css + '><a href="' + completeUrl + '">' + title + '</a><span></span></li>');
}

/* Builds a full url out of an relative */
/* NOTE! checks only for Information.aspx or index.aspx when determening relative path */
function GetFullUrl(relativeUrl)
{
    var href = String(location.href).toLowerCase();
    var start = href.indexOf("information.aspx");
    if (start == -1)
        start = href.indexOf("index.aspx");
	var baseUrl = href.substr(0, start);
	return baseUrl + relativeUrl;
}

/* Redirects the current page to given relative url */
function Redirect(relativeUrl)
{
    location.href = "Information.aspx?id=0&url=" + escape(GetFullUrl(relativeUrl));
}

/* Build the left hand menu for the contacts pages */
/* activeItem is the number of the item that is active. 0-indexed */
/* Example: BuildMenu_Contact(0) -- first item in list is active */
function BuildMenu_Contact(activeItem)
{
    document.write('<ul class=\"list\">');
    WriteMenuItem('Kontakt oss', 'info/contact.txt', activeItem==0);
    WriteMenuItem('Innhold du savner?', 'info/tips.txt', activeItem==1);
    WriteMenuItem('Er det noe du ville ha endret?', 'info/feedback.txt', activeItem==2);
    document.write('</ul>');
}

/* Build the left hand menu for the about us pages */
/* activeItem is the number of the item that is active. 0-indexed */
/* Example: BuildMenu_About(0) -- first item in list is active */
function BuildMenu_About(activeItem)
{
    document.write('<ul class=\"list\">');
    WriteMenuItem('Om tjenesten', 'info/about.txt', activeItem==0);
    WriteMenuItem('Presseomtaler', 'info/presse.txt', activeItem==1);
    WriteMenuItem('Hvordan bli leverand&oslash;r?', 'info/lms.txt', activeItem==2);
    WriteMenuItem('Diglib versjon 2', 'info/version.txt', activeItem==3);
    WriteMenuItem('Teknisk dokumentasjon', 'info/tech_doc.txt', activeItem==4);
    document.write('</ul>');
}
