// general purpose function to restrict numeric input to a certain range
function restrict(t, low, high) {
	var v = parseFloat(t.value);
	t.value =
		isNaN(v) ? '' :
		v < low ? low :
		v > high ? high :
		v;
}

// same thing but restrict to integer values
function restrictint(t, low, high) {
	var v = parseInt(t.value);
	t.value =
		isNaN(v) ? '' :
		v < low ? low :
		v > high ? high :
		v;
}

// restrict but don't change the value unless it's out of bounds (ie don't chop off trailing zeros, etc)
function restrictnochange(t, low, high) {
	var v = parseFloat(t.value);
	v =
		isNaN(v) ? '' :
		v < low ? low :
		v > high ? high :
		v;
	if (v != t.value) t.value = v;
}

// same thing but for integers
function restrictintnochange(t, low, high) {
	var v = parseInt(t.value);
	v =
		isNaN(v) ? '' :
		v < low ? low :
		v > high ? high :
		v;
	if (v != t.value) t.value = v;
}

var validemail = new RegExp();
validemail.compile(/^\w+([\.-]\w+)*@[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\.[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)+$/);
function invalidemail(e) {
	return !validemail.test(e.value);
}

var validdate = new RegExp();
validdate.compile(/^((0)?[1-9]|1[012])[-\/.]((0)?[1-9]|[12][0-9]|3[01])[-\/.](19|20)?\d\d$/);
function invaliddate(d) {
	return !validdate.test(d.value);
}

