function trim(s) {
	var res = s.replace(/^\s*(.*)/, "$1");
	res = res.replace(/(.*?)\s*$/, "$1");
	return res;
}

function isNumber(n) {
	var validChars = "0123456789.";
	var c;
	var res = true;
 
	if (n == '') {
		res = false;
	} 
 
	for (i = 0; i < n.length && res; i++) { 
		c = n.charAt(i); 
		if (validChars.indexOf(c) == -1) {
			res = false;
		}
	}
	return res;
}

function validateEmailField(emailElem) {
	var email = emailElem.value;
	var atIndex = email.indexOf("@");
	var afterAt = email.substring((atIndex + 1), email.length);
	// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAt.indexOf(".");
	// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + atIndex + 1;
	// afterAt will be portion of string from ampersand to dot
	afterAt = email.substring((atIndex + 1), dotIndex);
	// afterDot will be portion of string from dot to end of string
	var afterDot = email.substring((dotIndex + 1), email.length);
	var beforeAmp = email.substring(0,(atIndex));
	var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
	// index of -1 means "not found"
	if ((email.indexOf("@") != "-1") && (email.length > 5) && (afterAt.length > 0) && (beforeAmp.length > 1) && (afterDot.length > 1) && (email_regex.test(email)) ) {
		return true;
	} else {
		return false;
	}
}