/*
	Macro for internal links (links between parts of the page)
	The links are different on a disc and on a server
*/
function addrOfSubPage(pageName,subPath,level) {
	// level   : how deep we are in the dir. structure (www=0)
	// subPath : if empty, we use index.htm for local version
	var addr;
	if (self.location.href.substring(0,5)=='index.html') {
		// runs on the server -> needs absolut address
		addr = 'http://' + pageName + '.michalkaut.net' + '/' + subPath;
	}
	else {
		// runs locally -> relative links
		addr = 'http://www.iot.ntnu.no/users/';
		for(var i = 1; i <= level; i++)
			addr = '../' + addr;
		addr = addr + pageName + '/' + subPath;
		if (subPath=='')
			addr = addr + 'index.htm';
	}
	return addr;
}
function link2subPage(pageName,subPath,level,linkText) {
	// write the address as a complete tag: <a>linkText</a>
	document.write('<a href="' + addrOfSubPage(pageName,subPath,level) + '">'
	               + linkText + '</a>');
}


var mailCount = 0;
/*
	Use this function in the files
	Possibilities are:
	 : mailAddrTXT() - plain text
	 : mailAddrURL() - working link
	 : mailAddrMOUSE() - working link, after mouse over
*/	 
function mailLink(name,server) {
	mailAddrURL(name,server);
}

// Return the mail address as text (for use in other functions)
function mailAddrFunc(name,server) {
	return name+'@'+server;
}
// Writes the mail address as a plain text
function mailAddrTXT(name,server) {
	document.write(mailAddrFunc(name,server));
}
// Writes the mail address as an URL
function mailAddrURL(name,server) {
	document.write(
		'<a href=\"mailto:' + mailAddrFunc(name,server) +'\">'
		+ mailAddrFunc(name,server)
		+ '</a>'
	);
}
// Writes the mail address after a mouse over
function mailAddrMOUSE(name,server) {
	mailCount = mailCount + 1;
	var spanID = 'mail' + mailCount;
	document.write(
		'<span'
			+	' onmouseover=' + "'" + 'document.getElementById("' + spanID + '").innerHTML="'
				+ mailAddrFunc(name,server) + '";' + "'"
			+ ' onmouseout=' + "'" + 'document.getElementById("' + spanID + '").innerHTML='
				+ '"<a href=\\"mailto:"'
				+ '+ document.getElementById("' + spanID + '").innerHTML + "\\">"'
				+ '+ document.getElementById("' + spanID + '").innerHTML + "</a>"'
				+ "'"
		+ '>'
		+ '&nbsp;'
		+ '</span>'
	);
	document.write(
		'<span id=' + spanID + '>'
		+ '<img src="arrow_left.gif" width="8"> move mouse there'
		+ '</span>'
	);
}

