function checkEmail(fieldName, fieldToCheck) {
	var emailString = fieldToCheck.value;
	emailString = trimSpaces(emailString);
	fieldToCheck.value = emailString;
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) {
		alert("Please enter a valid " + fieldName);
		fieldToCheck.focus();
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid " + fieldName);
		fieldToCheck.focus();
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid " + fieldName);
		fieldToCheck.focus();
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid " + fieldName);
		fieldToCheck.focus();
		return false;
	}
	return true;
}

function checkAllowedChars(fieldName, fieldToCheck, allowedChars) {
	var strToCheck = fieldToCheck.value;
	strToCheck = trimSpaces(strToCheck);
	fieldToCheck.value = strToCheck;
	var allowedLength = allowedChars.length;
	var strLength = strToCheck.length;
	strToCheck = strToCheck.toLowerCase();
	var i;
	var index;
	var charToCheck;
	for (i=0; i<strLength; i++) {
		charToCheck = strToCheck.charAt(i);
		index = allowedChars.indexOf(charToCheck);
		if (index == -1) {
			alert('Illegal character "' + charToCheck + '" in ' + fieldName);
			fieldToCheck.focus();
			return false;
		}
	}
	return true;
}

function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}