var v_empty = new Array(); // fields to be validated on empty values
var v_format = new Array(); // fields to be validated on incorrect format values

// add the variable to be validated on empty value
function valEmpty(field, label) {
	v_empty.push(new Array(field, label));
}

function valFormat(format, field, label) {
	v_format.push(new Array(format, field, label));
}

function checkForm(form) {
	if (null==form) form = 'document.data';

	empty_fields = new Array();
	invalid_fields = new Array();

	for (i=0; i<v_empty.length; i++) {
		if (!eval(form+'.'+v_empty[i][0]+".value")) {
			empty_fields.push(v_empty[i][1]);
		}
	}

	for (i=0; i<v_format.length; i++) {
		value = eval(form+'.'+v_format[i][1]+".value")
		if (value) {
			var regexp = v_format[i][0];
			if (!regexp.test(value)) {
				invalid_fields.push(v_format[i][2]);
			}
		}
	}

	var error_string = msg_errors+'\n\n';
	var err = false;

	if (empty_fields.length) {
		err = true;
		for (i=0; i<empty_fields.length; i++) {
			error_string += msg_invalid_empty.replace(/%FIELD%/,empty_fields[i])+'\n';
		}	
	}

	if (invalid_fields.length) {
		err = true;
		for (i=0; i<invalid_fields.length; i++) {
			error_string += msg_invalid_format.replace(/%FIELD%/,invalid_fields[i])+'\n';
		}
	}

	if (err) { // there was an errors. output error message
		alert(error_string);
		return false;
	}

	return true;
}
