var alphaChars = "abcdefghijklmnopqrstuvwxyz";
var digitChars = "0123456789";
var asciiChars = alphaChars + digitChars + "!\"#$%&'()*+,-./:;<=>?@[\]^_`{}~";
function isASCII(str){
	var v_len = str.length;
	var i;
	for (i = 0; i < v_len; i++)	{
		if (asciiChars.indexOf(str.charAt(i)) == -1)
			return false;
	}
	return true;
}
function ValidateEmail(str){
	var ret = false;
	if (typeof(str) != "undefined")	{
		if (/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(str))	{
			ret = str;
		}
	}
	return ret;
}
function ValidateLooseEmail(str){
	var resultStr = str.replace(/ /gi, "");
	var atIndex   = resultStr.indexOf("@");
	var dotIndex  = resultStr.lastIndexOf(".");
	if( resultStr == "" || !isASCII(resultStr) || dotIndex == -1)
		return "";
	if ( resultStr.lastIndexOf("@") != atIndex || resultStr.charAt(atIndex+1) == ".")
		return "";
	if ( atIndex <= 0 || dotIndex < atIndex ||  dotIndex >= resultStr.length-1)
		return "";
	return resultStr;
}
function ValidateDomain(str){
	var resultStr = str.replace(/ /gi, "");
	var atIndex   = resultStr.indexOf("@");
	var dotIndex  = resultStr.lastIndexOf(".");
	if( resultStr=="" || !isASCII(resultStr) || dotIndex == -1)
		return "";
	if ( atIndex > 0 || resultStr.charAt(atIndex+1) == "." || dotIndex >= resultStr.length-1 )
		return "";
	return resultStr.replace(/@/i, "");
}
function isEmail(str) {
	var pass = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) pass = 1;
	}
	if (!pass)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
// Speaking of Java, this particular script is (C) Copyright 2002 Jim Tucek
// If you wish to use my Email Encryption script, these comments must be left
// alone!  That is all.

// Visit www.jracademy.com/~jtucek/ for script information and a bit of help
// setting it up, or www.jracademy.com/~jtucek/email.html for contact
// information.

// A brief history of this script can be found (and it's rather entertaining)
// at www.jracademy.com/~jtucek/eencrypt.html

function goForth(c,n,d) {
c += ' ';
var length = c.length;
var number = 0;
var bar = 0;
var answer = '';
for(var i = 0; i < length; i++) {
number = 0;
bar = 0;
while(c.charCodeAt(i) != 32) {
number = number * 10;
number = number + c.charCodeAt(i)-48;
i++;
}
answer += String.fromCharCode(decrypt(number,n,d));
}
// Updated security feature
parent.location = 'm'+'a'+'i'+'l'+'t'+'o'+':'+answer;
}

function showText(c,n,d) {
c += ' ';
var length = c.length;
var number = 0;
var bar = 0;
var answer = '';
for(var i = 0; i < length; i++) {
number = 0;
bar = 0;
while(c.charCodeAt(i) != 32) {
number = number * 10;
number = number + c.charCodeAt(i)-48;
i++;
}
document.write('&');
document.write('#');
document.write(decrypt(number,n,d));
}
}

function decrypt(c,n,d) {
// Split exponents up
if (d % 2== 0) {
bar = 1;
for(var i = 1; i <= d/2; i++) {
foo = (c*c) % n;
bar = (foo*bar) % n;
}
} else {
bar = c;
for(var i = 1; i <= d/2; i++) {
foo = (c*c) % n;
bar = (foo*bar) % n;
}
}
return bar;
}
