//
//	$Source$
//	$Date: 2004-01-12 21:58:01 -0800 (Mon, 12 Jan 2004) $
//	$Revision: 594 $
//
//	Copyright 2003-2004 Repomanager 
//	Mike Carlton <carlton@repomanager.com>
//

// return null string if no errors, else error message string
function validate_nonnull(form, field, desc)
{
	var error = "";

	if (eval('form.' + field)) {		// if field exists
		var val = eval('form.' + field + '.value');
		if (!val) {
			error += "\n- You must supply the " + desc + ".";
		}
	}

	return error;
}

// return null string if no errors, else error message string
function validate_nonnullpair(form, field1, field2, desc, optional)
{
	var error = "";

	// if fields exist
	if (eval('form.' + field1) && eval('form.' + field2)) {
		var val1 = eval('form.' + field1 + '.value');
		var val2 = eval('form.' + field2 + '.value');
		if (val1) {
			if (!val2) {
				error += "\n- You must enter the " + desc +
						 " twice to confirm.";
			} else if (val1 != val2) {
				error += "\n- The " + desc;
				if (desc.charAt(desc.length-1) == 's') {
					error += "e";
				}
				error += "s must match.";
			}
		} else {
			if (!optional) {			// unless field is optional
				error += "\n- You must supply the " + desc + ".";
			}
		}
	}

	return error;
}

// return null string if no errors, else error message string
function validate_nonzero(form, field, desc)
{
	var error = "";

	if (eval('form.' + field)) {		// if field exists
		var val = eval('form.' + field + '.value');
		if (val == 0) {				// don't use !val -- !"0" is true
			error += "\n- You must choose the " + desc + ".";
		} 
	}

	return error;
}

// return null string if no errors, else error message string
function validate_radioset(form, field, desc)
{
	var error = "";

	if (eval('form.' + field)) {		// if field exists
		var len = eval('form.' + field + '.length');
		for (j=0; j<len; j++) {
			if (eval('form.' + field + '[' + j + '].checked')) {
				break;
			}
		}
		if (j == len) {
			error += "\n- You must choose the " + desc + ".";
		}
	}

	return error;
}

function validate_accountid(form, field, desc)
{
	var error = "";

	if (eval('form.' + field)) {
		var val = eval('form.' + field + '.value');
		var n = 32;
		if (val.length >= n) {
			error += "\n- The " + desc + " must be less than " + n + 
					 " characters long.";
		} 
		if (val.match(/^[^a-zA-Z]/)) {
			error += "\n- The " + desc + " must begin with a letter.";
		} 
		if (val.match(/[^a-zA-Z0-9]/)) {
			error += "\n- The " + desc + 
					 " must contain only letters and numbers.";
		}
	}

	return error;
}

