
function Form(form) {
	
	this.canvas = form;
	
	function throwSubmitException() {
		return false;
	}
	function throwSubmitSuccess() {
		return true;
	}
	
	this.onSubmitException = function (action) {
		throwSubmitException = action;
	};
	
	this.onSubmitSuccess = function (action) {
		throwSubmitSuccess = action;
	};
	
	this.canvas.onsubmit = function () {
		var i;
		var j = this.length;
		var id;
		var tmp;
		for (i=0; i<j; i++) {
			id = this.elements[i].id;
			if (id) {
				tmp = document.getElementById(id);
				if (tmp) {
					if (tmp.getAttribute("required") == "true") {
						switch (tmp.tagName) {
							case "INPUT":
								switch (tmp.getAttribute("type")) {
									case "radio":
										var rg = new RadioGroup(tmp);
										if (!rg.isChecked()) {
											rg.setFocus();
											return throwSubmitException();
										}
									break;
									case "checkbox":
										if (!tmp.checked) {
											tmp.focus();
											return throwSubmitException();
										}
									break;
									default:
										if (tmp.value == "") {
											tmp.focus();
											return throwSubmitException();
										}
									break;
								}
							break;
							case "SELECT":
								var cb = new ComboBox(tmp);
								if (cb.getValue() == "") {
									cb.setFocus();
									return throwSubmitException();
								}
							break;
							default:
								// TEXTAREA
								if (tmp.value == "") {
									tmp.focus();
									return throwSubmitException();
								}
							break;
						}
					}
				}
			}
		}
		return throwSubmitSuccess();
	};
	
	this.onSubmit = function (action) {
		this.canvas.onsubmit = action;
	};
	
}

