// possible whitespace characters
var whitespace = " \t\n\r";

function askDelete() {
	return confirm('Do you really want to delete this record?');
}

// checks a given password and confirmation for validity
function checkPass(pass, pass2) {
	var err = "";
	if (pass.length < 5) { 
		err = "Password must be at least 5 characters long.";
	} else if (hasWhitespace(pass)) { 
		err = "Password cannot contain white space.";
	} else if (pass != pass2) { 
		err = "Password does not match the confirmation password.";
	} else {
		err = ""
	}
	return err;
}

// tests to see if the integer value of the string is greater than some value
function isGreater(s, lo) { 
	return (intVal(s) > lo);
}

// tests to see if the integer value of the string falls in the range low to high
function inRange(s, lo, hi) { 
	var x = intVal(s);
	return (x >= lo && x <= hi);
}

// tests to see if a string is all whitespace
function isWhitespace(s) { 
	for (i=0; i<s.length; i++) { 
		if (whitespace.indexOf(s.charAt(i)) == -1) { 
			return false;
		}
	}
	return true;
}

// tests to see if a string contains any whitespace
function hasWhitespace(s) { 
	for (i=0; i<s.length; i++) { 
		if (whitespace.indexOf(s.charAt(i)) != -1) { 
			return true;
		}
	}
	return false;
}

// converts the string to integer
function intVal(s) { 
	return parseInt(parseFloat(s));
}

// tests to see if a string is numeric
function isNumeric (s) {
	for (i = 0; i < s.length; i++) { 
		if (!isNumber (s.charAt(i))) {
			return false;
		}
	}
	return true;
	//return !(isNaN(intVal(s)));
}

function isNumber (c) { 
	return (c >= "0" && c <= "9");
}

// test to see if upper or lowercase letter
function isLetter (c) {   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

// tests to see if a string is made up of only letters
function isAlphabetic (s) {   
	for (i = 0; i < s.length; i++) {   
		if (!isLetter(s.charAt(i))) { 
			return false;
		}
	}
	return true;
}

// tests to see if a string a empty
function isEmpty(s) {   
	return (s == null || s.length == 0 || isWhitespace(s));
}

// tests for validity of an email address
function isEmail(s) {
	if (hasWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")) i++;
    if ((i >= sLength) || (s.charAt(i) != "@")) return false; else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")) i++;
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false; else return true;
}
