function isEmail(string) {
	var intIndexOfAt = string.indexOf("@");
	if (intIndexOfAt > 0) { // if there is something preceeding the at sign
		// indexOf(searchValue[, fromIndex])
		// fromIndex - The location within the calling string to start the search from. 
		// It can be any integer between 0 and the length of the string. The default value is 0.
		var intIndexOfDot = string.indexOf(".",intIndexOfAt);
		if ((intIndexOfDot > intIndexOfAt + 1) && (string.length > intIndexOfDot + 1)) {
		// if there is something between the @ sign and the . sign and
		// if there is something after the . sign
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function isValidCharacter(character) {
	var validCharacters=" !@#$%^&*()-_=+`~{}[]|:;<>,./?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	if (validCharacters.indexOf(character) != -1) {
		return true;
	} else {
		return false;
	}
}	

function isDigit(character) {
	var validDigits="1234567890";
	// indexOf returns the index within the calling String object of the first 
	// occurrence of the specified value or -1 if the value is not found.
	if (validDigits.indexOf(character) != -1) {
		return true;
	} else {
		return false;
	}
}

function isText(string) {
	for (var i=0; i<string.length; i++) {
		if (!isValidCharacter(string.charAt(i))) {
			return false;
		}
	}
	return true;
}

function isInteger(string) {
	for (var i=0; i<string.length; i++) {
		if (!isDigit(string.charAt(i))) {
			return false; 
		}
	}
	return true;
}

function isNumeric(string) {
	var decimalPoint = false;
	for (var i=0; i<string.length; i++) {
		if (!isDigit(string.charAt(i))) {
			if (string.charAt(i) == ".") {
				if (decimalPoint == true) { 
					return false; 
				} else { 
					decimalPoint = true; 
				}
			} else {
				return false; 
			}
		}
	}
	return true;
}

function isDate(string) { //checks for valid dates
	var dateComponentArray = string.split("/");
	if (dateComponentArray.length == 3) {
		if (!(isInteger(dateComponentArray[0]) && isInteger(dateComponentArray[1]) && isInteger(dateComponentArray[2]))) {
			return false;
		}
		var month = parseInt(dateComponentArray[0]);
		var day = parseInt(dateComponentArray[1]);
		var year = parseInt(dateComponentArray[2]);
		if (dateComponentArray[2].length != 4) {
			return false;
		}
		if (month < 1 || month > 12) {
			return false;
		}
		if (day < 1 || day > 31) {
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			return false
		}
		if (month == 2) {
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				return false;
   			}
		}
		return true;
	}
}

function trim(string) { //removes trailing and leading spaces of a string
	while(string.charAt(0) == " ") {
		string = string.substring(1, string.length);
	}
	while(string.charAt(string.length - 1) == " ") {
		string = string.substring(0, string.length - 1);
	}
	return(string);
}

function len(string) { //returns the length of a string
	return(string.length);
}
