/* 
   mailmask.js 
   generates mailtos from encrypted address
   author: David P. Leader 2003
   Use it if you wish, but don't blame me if it doesn't work
*/


// look up the encrypted address from id
function makemail(id, visText)
{
	var crypto = new String("");		
	if(id == "100")
	{
		crypto = "13s>2u:u75Pty:qt16";	// david's q7 address
	}
	else if(id == "101")
	{
		crypto = "=GLA5L@A?76L@9;E76UC^D7=3?753>30"; // jean's q7 address
	}
	else
	{
		crypto = "35u@w8wz=54R?v5t5418";	// nobody
	}
    decode(crypto, visText);
}

// decodes the encrypted address 
function decode(inString, visText)
{
    // get input string
	var coded = new String("");
    coded  = inString;
	var decoded = new String("");
  
    //strip last two chars off and make into a number
    var offset = coded.substring(coded.length-2, coded.length);
    coded = coded.substring(0, coded.length-2);

	for(i = coded.length-1; i>-1; i--)
	{
		var x = coded.charCodeAt(i);
		if((x-offset)<46)
		{
		 	x = (x-offset) -46 + 122;
		}
		else
		{
		    x -= offset;
		}
		decoded += String.fromCharCode(x);
	}
	writeIt(decoded, visText);       
}

// generates the final output, diplaying visText as the linked text
function writeIt(decoded, visText)
{
	var first = '<a href="ma';
	var second = 'ilto:';
	var third = decoded;
	var fourth = '">';
	var fifth = visText;
	var sixth = '</a>';
	
	var outString = first + second + third + fourth + fifth + sixth;	
	document.write(outString);
}