function validateLegalChars(CF, fieldname)
{
	// Check for presence of illegal character input
	var valid = /[\W]+/;
	return valid.test(CF.getValue(fieldname));
}

function validatePresence(CF, fieldname)
{	
	// Check for presence of response
	var valid = /[\w]+/;

	if (typeof(fieldname) != 'string' || typeof(CF) != 'object') {
		return false;
	} else {
		var theVal = CF.getValue(fieldname);
		return valid.test(theVal);
	}
}

function validatePresenceChars(CF, fieldname)
{	
	/* Same as validatePresence but disallows non-alphanumeric character input */
	
	// Check for presence of response
	var valid = /[\w]+/;

	if (typeof(fieldname) != 'string' || typeof(CF) != 'object') {
		return false;
	} else {
		var resLegal = validateLegalChars(CF, fieldname);
		if (resLegal === true) {
			return false;
		} else {
			var theVal = CF.getValue(fieldname);
			return valid.test(theVal);
		}
	}
}

function validateEmail(CF, fieldname)
{
	// Check E-mail address format
	var valid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	
	if (typeof(fieldname) != 'string' || typeof(CF) != 'object') {
		return false;
	} else {
		var theVal = CF.getValue(fieldname);
		return valid.test(theVal);
	}
}

function validatePassword(CF, fieldname)
{
	/* 	Notice that this function assumes there is a second password
		field ('password2') to be confirmed, as well */
		
	if (!validatePresenceChars(CF, fieldname)) {
		return 1;
	}
	
	if (!validatePresenceChars(CF, 'password2')) {
		return 2;
	}
	
	var val1 = CF.getValue(fieldname);
	var val2 = CF.getValue('password2');
	
	if (val1 != val2) {
		return 3;
	}

	return true;
		
}

function optionSelected(CF, fieldname)
{
	if (typeof(fieldname) != 'string' || typeof(CF) != 'object') {
		return false;
	} else {
		if (typeof(parseInt(CF.getValue(fieldname))) == 'number' && CF.getValue(fieldname) > 0) {
			return true;
		} else {
			return false;
		}
	}
}
