var daysInMonth = new Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var daysOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}

function isWhitespace(s) {
	return /^\s+$/.test(s);
}

function isLetter(c) {
	return /^[A-Za-z]{1}$/.test(c);
}

function isDigit(c) {
	return /^\d{1}$/.test(c);
}

function isLetterOrDigit(c) {
	return /^[A-Za-z\d]{1}$/.test(c);
}

function isInteger(s) {
	return /^\d+$/.test(s);
}

function isSignedInteger(s) {
	return /^[\+|\-]?\d+$/.test(s);
}

function isPositiveInteger(s) {
	return (isSignedInteger(s) && parseInt(s) > 0);
}

function isNonnegativeInteger(s) {
	return (isSignedInteger(s) && parseInt(s) >= 0);
}

function isNegativeInteger(s) {
	return (isSignedInteger(s) && parseInt(s) < 0);
}

function isNonpositiveInteger(s) {
	return (isSignedInteger(s) && parseInt(s) <= 0);
}

function isFloat(s) {
	return /^\d+\.?\d*$/.test(s);
}

function isSignedFloat(s) {
	return /^[\+|\-]?\d+\.?\d*$/.test(s);
}

function isFraction(s) {
	return /(^0$)|(^([1-9]{1}[0-9]*(\-[1-9]{1}[0-9]*\/([2-9]{1}|([1-9]{1}[0-9]+)))?)$)|(^([1-9]{1}[0-9]*\/([2-9]{1}|([1-9]{1}[0-9]+))))$/.test(s);
}

function isPrice(s) {
	if (s == "") return false;
	return /(^\d{0,4}\.\d{0,2}$)|(^\d{0,4}$)/.test(s);
}

function isAlphabetic(s) {
	return /^[A-Za-z]+$/.test(s);
}

function isAlphanumeric(s) {
	return /^[A-Za-z\d]+$/.test(s);
}

function isEmail(s) {
	return /^(([A-Za-z\d]+[A-Za-z\d\_\-\.]*[A-Za-z\d]+)|[A-Za-z\d]+)\@[A-Za-z\d]+[A-Za-z\d\-]?[A-Za-z\d]+(\.[A-Za-z]{2,4}){1,3}$/.test(s);
}

function isYear(s) {
	if (!isNonnegativeInteger(s)) return false;
	return ((s.length == 2) || (s.length == 4));
}

function isIntegerInRange(s, a, b) {
	if (!isInteger(s)) return false;
	var num = parseInt(s);
	return ((num >= a) && (num <= b));
}

function isMonth(s) {
	return isIntegerInRange(s, 1, 12);
}

function isDay(s) {
	return isIntegerInRange(s, 1, 31);
}

function daysInFebruary(year) {
	return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0)))?29:28);
}

function isDate(year, month, day) {
	if (!(isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
	var intYear = parseInt(year);
	var intMonth = parseInt(month);
	var intDay = parseInt(day);
	if (intDay > daysInMonth[intMonth]) return false; 
	if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
	return true;
}

function hasBannedSymbols(s) {
	return /[\#\|\?]/.test(s);
}

function isBadFilename(s) {
	return /[\*\/\@\=\+\:\.\,\$\&\%\'\"\\]/.test(s);
}

function isISBN10(s) {
	if (!(/^\d{9}[\dxX]{1}$/.test(s))) return false;
	s = s.toUpperCase();
	var checkInt = 0;
	for (i = 0; i <= 8; i++) checkInt += ((10 - i) * (s.substr(i, 1) - 0));
	if (s.substr(9, 1) == "X") checkInt += 10;
	else checkInt += (s.substr(i, 9) - 0);
	if (checkInt % 11) return false;
	else return true;
}

function isISBN13(s) {
	if (!/^(978|979)\d{10}$/.test(s)) return false;
	var checkInt = 0;
	for (i = 0; i <= 11; i++) checkInt += ((i % 2?3:1) * (s.substr(i, 1) - 0));
	checkInt = (10 - (checkInt % 10)) % 10;
	if (checkInt != s.substr(12, 1)) return false;
	else return true;
}

function ISBN10_13(s) {
	s = "978" + s.substr(0, 9);
	checkInt = 0;
	for (i = 0; i <= 11; i++) checkInt += ((i % 2?3:1) * (s.substr(i, 1) - 0));
	checkInt = (10 - (checkInt % 10)) % 10;
	return s + checkInt;
}

function ISBN13_10(s) {
	checkInt = 0;
	s = s.substr(3, 9);
	for (i = 0; i <= 8; i++) checkInt += ((10 - i) * (s.substr(i, 1) - 0));
	checkInt = 11 - (checkInt % 11);
	checkInt = (checkInt == 10?"X":(checkInt == 11?"0":checkInt));
	return (s + checkInt);
}

function isISBN12(s) {
	if (!/^(978|979)\d{9}$/.test(s)) return false;
	else return true;
}

function ISBN12_13(s) {
	checkInt = 0;
	for (i = 0; i <= 11; i++) checkInt += ((i % 2?3:1) * (s.substr(i, 1) - 0));
	checkInt = (10 - (checkInt % 10)) % 10;
	return s + checkInt;
}

function ValidateString(s, minLen, maxLen, allowEmpty, allowAlpha, allowNumeric, allowSymbol) {
	s = TrimString(s);
	if (s == "") return allowEmpty;
	if ((s.length < minLen) || (s.length > maxLen)) return false;
	if (/[A-Za-z]+/.test(s) && !allowAlpha) return false;
	if (/\d+/.test(s) && !allowNumeric) return false;
	if (/[^\dA-Za-z\x20]+/.test(s) && !allowSymbol) return false;
	return true;
}

function TrimString(s) {
	return (s.replace(/^[\s]*/, "")).replace(/[\s]*$/, "");
}

function TrimAll(f) {
	for (i = 0; i < f.length; i++) if (f[i].type != "select-multiple" && f[i].type != "file") f[i].value = TrimString(f[i].value);
}

function EnableAll(f) {
	for (i = 0; i < f.length; i++) f[i].disabled = false;
}