
function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (trimSpaces(formField.value) == "")
	{
		alert("Please enter a value for the '" + fieldLabel + "' field.");
		formField.focus();
		result = false;
	}
	
	return result;
}


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;
}// trimSpaces()



/////////////////////////////////////////////////////////////////////////////////////////
// Checks whether a string is a valid email address.
/////////////////////////////////////////////////////////////////////////////////////////
function checkEmail(emailString) {
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) {
		alert("Please enter a valid Email");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid Email");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid Email");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid Email");
		return false;
	}
	return true;
}

