/* $Id$ */
/* additional scripts for the pages */

function selectTab(str)
{
	var El=document.getElementById(str);
	El.className="tabselect"; //IE
	if (typeof(setAttribute)=="function" )
	El.setAttribute("class", "tabselect");  // opera
	//El.href='NULL'; //kan ikke fjerne en href attribut 
	if (typeof(removeAttribute)=="function" )
	El.removeAttribute("href");
}
// IE 4 kompatibel
if ( document.getElementById == null ) 
{	document.getElementById = function(sId) {return document.all[sId];};		}

function createTabs(select)
{
	document.write(' \
	 <a id="c0" class="tabnorm" href="http://www.kochnielsen.dk/index.htm">Home</a> \
	 <a id="c1" class="tabnorm" href="http://www.kochnielsen.dk/adresser.htm">Adresser</a> \
	 <a id="c2" class="tabnorm" href="http://www.kochnielsen.dk/foto/index.php">Foto</a> \
	 <a id="c3" class="tabnorm" href="http://www.kochnielsen.dk/historie.htm">Historie</a> \
	 <a id="c4" class="tabnorm" href="http://www.kochnielsen.dk/stamtrae.htm">Stamtrę</a> \
	 <a id="c5" class="tabnorm" href="http://www.kochnielsen.dk/sommerhus/index.htm">Sommerhus</a> \
	 <a id="c6" class="tabnorm" href="http://www.kochnielsen.dk/links.htm">Links</a> \
	');
	if (select)
		selectTab(select);
	return true;
}

function writeNavigationLinks()
{
	// Set the varible g_url to nothing
	var g_url = "";
	
	
	// Split the document url by the /
	var split_url=document.URL.split('/');
	
	// Loop thorough the splits starting after http:// 
	// and ending on the parent directory of the current document
	for (var i=2; i<split_url.length-1; i++) 
	{
		// Start rebuilding the url to link each level
		g_url = g_url + split_url[i] +"/";
		document.write("<a href='http://" + g_url +"'>" + split_url[i] + "</a>"); 
		
		// Check to see if the last directory was written to avoid
		// and extra > after the parent directory of the current page
		if (i != split_url.length-2) 
		{ 
			document.write(" -> "); 
		}
	} // end loop
	document.write("<br>");
}

function writeNavigationLinksMinusOne() {
	// Set the varible g_url to nothing
	var g_url = "";
	
	
	// Split the document url by the /
	var split_url=document.URL.split('/');
	
	// Loop thorough the splits starting after http:// 
	// and ending on the parent directory of the current document
	for (var i=2; i<split_url.length-2; i++) 
	{
		// Start rebuilding the url to link each level
		g_url = g_url + split_url[i] +"/";
		document.write("<a href='http://" + g_url +"'>" + split_url[i] + "</a>"); 
		
		// Check to see if the last directory was written to avoid
		// and extra > after the parent directory of the current page
		if (i != split_url.length-3) 
		{ 
			document.write(" -> "); 
		}
	} // end loop
	document.write("<br>");

}


// from http://www.xs4all.nl/~ppk/js/lastmod.html
function lastMod()
{
	var towrite;
	towrite = '<span class="datetime">Page last changed ';
	towrite += calcDate();
	towrite += '</span>';
	return towrite;
}
function calcDate()
{
	var x = new Date (document.lastModified);
	var Modif = new Date(x.toGMTString());
	var Year = takeYear(Modif);
	var Month = Modif.getMonth();
	var Day = Modif.getDate();
	var Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	var today = new Date(x.toGMTString());
	var Year2 = takeYear(today);
	var Month2 = today.getMonth();
	var Day2 = today.getDate();
	var now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	var daysago = now - Mod;
	if (daysago < 0) return '';
	unit = 'days';
	if (daysago > 730)
	{
		daysago = Math.round(daysago/365);
		var unit = 'years';
	}
	else if (daysago > 60)
	{
		daysago = Math.round(daysago/30);
		unit = 'months';
	}
	else if (daysago > 14)
	{
		daysago = Math.round(daysago/7);
		unit = 'weeks'
	}
	var towrite = '';
	if (daysago == 0) towrite += 'today';
	else if (daysago == 1) towrite += 'yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	towrite += '</span>';
	return towrite;
}

// from http://www.xs4all.nl/~ppk/js/lastmod.html
function takeYear(theDate)
{
	var x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

