			function Trim(s) {
				return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
			}
			
			function showError(control, msg) {
				alert(msg);
				control.focus();
				if (control.select)
					control.select();				
			}
			
			function numericField(control, name, type) {
				if (!control) {
					alert(name + " field is missing.");
					return false;
				}
				
				control.value = Trim(control.value);
				if (control.value.length > 0) {
					if (type == "int")
						v = parseInt(control.value);
					else if (type == "float")
						v = parseFloat(control.value);
					else
						return false;
					
					if (isNaN(v)) {
						showError(control, name + " field is invalid.");
						return false;						
					}
					
					if (v < 0) {
						showError(control, name + " field is invalid.");
						return false;						
					}
					
					// control.value = v
				}
				
				return true;	
		}
		
			function requiredField(control, name) {
				if (!control) {
					alert(name + " field is missing.");
					return false;
				}
				
				control.value = Trim(control.value);
				if (control.value.length == 0) {
					showError(control, name + " field is required.");
					return false;
				}
				
				return true;
			}
		
		function zipField(control, name) {
			if ( !numericField(control, name, "int") ) {
				return false;
			}

			
			if ( control.value.length != 5 ) {
				showError(control, name + " field is invalid.");
				return false;											
			}
			
			return true;
		}
	
	function validateForm(form) {
		return requiredField(form.zip, "Zip Code") && zipField(form.zip, "Zip Code");
	}
