// addressScrambler.js version 0.2.2
// copyright 2001, 2002, Josiah Q. Hamilton
// This software is provided under the Artistic license of the Open 
//  Source Initiative, as it exists on 2001-12-19, including the optional
//  provision regarding aggregation with a commercial distribution.
// This notice must be included with any distribution.
var scrambleString = "j4Klo3m5c7 8 Aw8 7 inqwjh R62q";
function _scramble(inText,inverse) {
	var outText = "";
	var scrambleLen = scrambleString.length;
	for (var i = 0; i < inText.length; ++i) {
		var currentCode = inText.charCodeAt(i);
		var offset = scrambleString.charCodeAt(i % scrambleLen);
		if (inverse) {
			offset = 10 * 26 - offset;
		}
		var newCode = currentCode;
		if (currentCode == 46) {
			newCode = 64;  // replace '.' by '@'
		} else if (currentCode == 64) {
			newCode = 46;  // replace '@' by '.'
		} else if (65 <= currentCode && currentCode <= 90) {
			newCode = (currentCode - 65 + offset) % 26 + 65;
		} else if (97 <= currentCode && currentCode <= 122) {
			newCode = (currentCode - 97 + offset) % 26 + 97;
		}
		outText += String.fromCharCode(newCode);
	}
	return outText;
}
function descrambleText(inText) {
	var outText = _scramble(inText,true);
	return outText;
}
function writeMailToWithScrambledDisplayText(scrambledAddress, scrambledText, cssClass) {
	document.open();
	document.write("<a href=\"mailto:" + descrambleText(scrambledAddress) + "\"");
		if (cssClass != null && cssClass != "") {
		  document.write(" class=\"" + cssClass + "\" ");
		}
		document.write(">" + descrambleText(scrambledText) + "</a>");
	document.close();
}
function writeMailTo(scrambledAddress) {
	writeMailToWithScrambledDisplayText(scrambledAddress, scrambledAddress);
}
