//*****************************************************************************
//	Form Validator class definition.
//	(c) 2000-2006 Kappa Solutions Ltd.
//
//	This class has methods to validate a form.
//
//*******************************************************************

function FormValidator (form, cols) {
	this._form = form;
	this._cols = cols;
	
}
FormValidator.prototype.validate = function () {
		var msg = "";
		var f = this._form;
		for (var i=0; i<this._cols.length; i++) {
			var val = this._trim(f[this._cols[i].name].value);
			if (!val) msg += "\n" + this._cols[i].msg;
		}
	
		if (msg) {
			msg = "The form cannot be submitted for the following reason(s):" + msg;
			msg += "\n\nPlease ensure that all data is correctly entered and re-submit.";
			alert(msg);
			return false;
		}
		return true;
}
FormValidator.prototype._trim = function (val) {
	return val.replace(/^\s+/, "").replace(/\s+$/, "");
}