// Email obfuscator script 2.1 by Tim Williams, University of Arizona
// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
// This code is freeware provided these four comment lines remain intact
// A wizard to generate this code is at http://www.jottings.com/obfuscator/
// modified to fit this project by die-informatiker.net

function unscrambleEmail(id, coded, key, replaceValue)
{
	var shift = coded.length;
	var link = "";
	var ltr;
	for (i=0; i<coded.length; i++)
	{
		if (key.indexOf(coded.charAt(i))==-1)
		{
			ltr = coded.charAt(i);
			link += (ltr);
		}
		else
		{     
			ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length;
			link += (key.charAt(ltr));
		}
	}

	var node = document.getElementById(id);
	node.style.display = ""; //setAttribute("style", "display: inline");
	if (node.nodeName == "A")
	{
		node.setAttribute("href", "mailto:" + link);
		//node.removeChild(node.firstChild);
	}
	if (replaceValue || node.nodeName != "A")
	{
		while (node.hasChildNodes())
			node.removeChild(node.firstChild);
		node.appendChild(document.createTextNode(link));
	}
}
