
function doFocus(el) {
if (el.type == "text" || el.type == "textarea" || el.type == "password")
el.select();
el.focus();
}
var whitespace = " \t\n\r";
var daysInMonth = new Array();
daysInMonth[1] = 31;
daysInMonth[2] = 29;
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
function leftTrim(s) {
var i = 0;
while (i < s.length && whitespace.indexOf(s.charAt(i)) != -1) i++;
return s.substring(i, s.length);
}
function rightTrim(s) {
var i = s.length;
while (i > 0 && whitespace.indexOf(s.charAt(i - 1)) != -1) i--;
return s.substring(0, i);
}
function trim(s) {
return rightTrim(leftTrim(s));
}
function isEmpty(s) {
return trim(s).length == 0;
}
function isNumeric(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return !isNaN(s);
}
function isInteger(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return !isNaN(s) && s.indexOf(".") == -1;
}
function isPositive(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return !isNaN(s) && s > 0;
}
function isNegative(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return !isNaN(s) && s < 0;
}
function isNonNegative(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return !isNaN(s) && s >= 0;
}
function isNonPositive(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return !isNaN(s) && s <= 0;
}
function isInRange(s, min, max, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return !isNaN(s) && s >= min && s <= max;
}
function isYear(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return isInteger(s) && isInRange(s, 1753, 9999);
}
function isMonth(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return isInteger(s) && isInRange(s, 1, 12);
}
function isDay(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
return isInteger(s) && isInRange(s, 1, 31);
}
function isDate(year, month, day) {
if (!isYear(year) || !isMonth(month) || !isDay(day)) return false;
if (day > daysInMonth[month]) return false;
if (month == 2 && day > daysInFebruary(year)) return false;
return true;
}
function isFutureDate(year, month, day) {
if (!isDate(year, month, day)) return false;
var now = new Date();
var then = new Date(year, month - 1, day);
if (then.getTime() < now.getTime()) return false;
return true;
}
function isStringDate(s) {
var datetime = s.split(" ");
var date = datetime[0].split("/");
return isDate(date[2], date[0], date[1]);
}
function isFutureStringDate(s) {
if (isEmpty(s)) return false;
var date = s.split("/");
if (date.length != 3) {
return false;
} else if (isPositive(date[0]) == false) {
return false;
} else if (isPositive(date[1]) == false) {
return false;
} else if (isPositive(date[2]) == false) {
return false;
} else {
return isFutureDate(date[2], date[0], date[1]);
}
}
function daysInFebruary(year) {
return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 29 : 28;
}
function isChecked(el) {
for (var i = 0; i < el.length; i++) {
if (el[i].checked) return true;
}
return false;
}
function isEmail(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
s = trim(s);
var i = 1;
while (i < s.length && s.charAt(i) != "@") i++;
if (i >= s.length || s.charAt(i) != "@") return false;
i += 2;
while (i < s.length && s.charAt(i) != ".") i++;
if (i >= s.length - 1 || s.charAt(i) != ".") return false;
return true;
}
function isURL(s, emptyOK) {
if (isEmpty(s)) return (emptyOK == null) ? false : emptyOK;
s = trim(s);
if (s.length < 8 || s.substring(0, 7) != "http://") return false;
return true;
}
